book-index-ui 0.47.0 → 0.47.1

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.
Files changed (3) hide show
  1. package/dist/index.cjs +75 -73
  2. package/dist/index.js +4250 -4247
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Kd=Object.create;var Kr=Object.defineProperty;var qd=Object.getOwnPropertyDescriptor;var Xd=Object.getOwnPropertyNames;var Zd=Object.getPrototypeOf,Jd=Object.prototype.hasOwnProperty;var Qd=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Xd(n))!Jd.call(e,s)&&s!==o&&Kr(e,s,{get:()=>n[s],enumerable:!(r=qd(n,s))||r.enumerable});return e};var qn=(e,n,o)=>(o=e!=null?Kd(Zd(e)):{},Qd(n||!e||!e.__esModule?Kr(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Se=require("./storage-entry-BDcJjAiW.cjs"),t=require("react/jsx-runtime"),g=require("react"),ep=require("opencc-js/t2cn"),tp=require("react-markdown"),np=require("remark-gfm"),ip=e=>`/book-index?id=${e}`,wa=g.createContext(ip);function op({buildUrl:e,children:n}){const o=g.useMemo(()=>e,[e]);return t.jsx(wa.Provider,{value:o,children:n})}function Je(){return g.useContext(wa)}const Sa="",_a="";function Io(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?_a:Sa,a=r.indexOf(s);if(a===-1){n.push({text:r,marked:o});break}a>0&&n.push({text:r.slice(0,a),marked:o}),r=r.slice(a+1),o=!o}return n}function rt(e,n){return{title:e,tokens:n}}const qr='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',rp=[rt("基础(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"}}),rt("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),rt("提示与警告",{"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)"}}),rt("遮罩与阴影",{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)"}}),rt("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),rt("资源",{"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"}}),rt("整理本(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"}}),rt("版本传承(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"}}),rt("编辑器视图(主要在 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")'}}),rt("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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:"#3b4a58",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}}),rt('版式(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:"14px 18px",note:"区块标题栏内边距。10-01 起疏朗也有淡染底的标题栏(--bim-fr-hd-bg),故疏朗 14px 18px,界栏 12px 18px"},"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:"页签行下沿线颜色(疏朗不画,界栏画)"},"fr-hd-size":{value:"24px",note:"分区标题字号。界栏标题在框顶标题栏里,小一档 19px"},"fr-hd-bg":{value:"color-mix(in srgb, var(--bim-accent) 7%, var(--bim-page-bg))",note:"分区标题栏底色(淡染主色)。疏朗混进页面底,界栏 6% 混进卡面底。主色取 accent(primary 是 VS Code 按钮蓝,不随配色)"},"fr-card-bd":{value:"1px solid transparent",note:"卡片边框。疏朗不画(靠卡面底与淡投影);界栏 1px"},"fr-card-bg":{value:"var(--bim-card-bg)",note:"卡片底"},"fr-row-bd":{value:"1px solid transparent",note:"列表行线、块内小分割线。疏朗不画(靠行距);界栏 1px"},"fr-row-pad":{value:"10px 2px",note:"列表行内边距。界栏收紧 7px 2px"},"fr-chrome-bd":{value:"1px solid transparent",note:"顶栏、分区导航(吸顶锚点条)的线"},"fr-tag-bd":{value:"1px solid transparent",note:"标签、版本签、计数签、工具按钮的边框。疏朗浅底无框;界栏透明底加框"},"fr-tag-bg":{value:"var(--bim-tint-bg)",note:"标签底"},"fr-tbl-cell-bd":{value:"0 solid transparent",note:"表格格线。疏朗不画(靠斑马纹);界栏全格线"},"fr-tbl-zebra":{value:"var(--bim-tint-bg)",note:"表格斑马纹(只在疏朗下有)"},"fr-rail-bd":{value:"1px solid transparent",note:"侧栏里的块、提示块的边框"},"fr-rail-bg":{value:"var(--bim-tint-bg)",note:"侧栏块底。疏朗浅底;界栏卡面底"},"fr-spine-bd":{value:"1px solid transparent",note:"题签、书脊(竖排书名)的边框。界栏是强调色浅线"},"fr-spine-bg":{value:"var(--bim-flag-bg)",note:"题签、书脊底。疏朗浅色实底;界栏卡面底(正史原志两种版式都是强调色实底)"},"fr-plank":{value:"0 solid transparent",note:"书架架板(border 简写)。只在界栏下画 3px"},"fr-axis-bd":{value:"0 solid transparent",note:"时间轴轴线。界栏 1px"},"fr-axis-band":{value:"6px",note:"时间轴底带高度。疏朗用 6px 浅色带代替轴线;界栏 0"},"fr-tick":{value:"0",note:"时间轴刻度短线长度。界栏 5px"},"fr-band-gap":{value:"3px",note:"年代带各段之间的空隙。疏朗 3px;界栏紧贴"},"fr-band-bd":{value:"0 solid transparent",note:"年代带外框与段间分隔。界栏 1px"}}),rt("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"},"warp-bg":{value:"#faf8f5",note:"古籍矫正底本书影画布底色"},"warp-box-shadow":{value:"0 2px 12px rgba(0, 0, 0, 0.08)",note:"古籍底本书影浮雕阴影"},"warp-sel-bg":{value:"rgba(196, 148, 76, 0.45)",note:"古籍对读字框选中高亮底色"},"warp-sel-stroke":{value:"#a06e1c",note:"古籍对读字框选中描边"},"warp-hover-bg":{value:"rgba(217, 185, 106, 0.25)",note:"古籍对读字框悬停高亮底色"},"warp-hover-stroke":{value:"#c4944c",note:"古籍对读字框悬停描边"},"warp-badge-bg":{value:"rgba(184, 134, 54, 0.12)",note:"图文对读徽章背景"},"warp-badge-fg":{value:"#8c6820",note:"图文对读徽章文字颜色"},"warp-badge-bd":{value:"rgba(184, 134, 54, 0.3)",note:"图文对读徽章边框"},"warp-banxin-border":{value:"#8a8070",note:"版心分界线"},"warp-banxin-fold":{value:"rgba(160, 110, 28, 0.65)",note:"版心中缝对折线"},"warp-banxin-outer":{value:"#c9c3b4",note:"版心外边线"}}),rt("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),rt("字体(全站无衬线,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:qr,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:qr,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],sp=Object.assign({},...rp.map(e=>e.tokens)),$a={};for(const[e,n]of Object.entries(sp))$a[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=$a[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Kt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function ap(e,n){return Kt(e).includes(n)}const lp={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const qt=g.createContext(null),Ca=["曹霑"];function cp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function dp(e,n=Ca){const o=[...new Set(n.filter(Boolean))].sort((a,l)=>l.length-a.length);if(!o.length)return e;const r=new RegExp(`(${o.map(cp).join("|")})`,"g"),s=new Set(o);return a=>{if(!a)return e(a);const l=a.split(r);return l.length===1?e(a):l.map((d,c)=>c%2===1&&s.has(d)?d:d&&e(d)).join("")}}let yn=null;function pp(){if(yn)return yn;try{const e=ep.Converter({from:"t",to:"cn"});yn=dp(n=>e(Se.normalizeVariants(n)))}catch{yn=e=>e}return yn}const up={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"},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:"圖片資源"}},mp={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"},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:"图片资源"}};function at(e,n,o){return{"zh-Hant":e,"zh-Hans":n}}const hp=at({toHans:"切换为简体",toHant:"切換為繁體",localeShortHans:"简",localeShortHant:"繁",themeLabel:"主題",theme:{zhusha:"朱砂",indigo:"靛青",ink:"墨"},loading:"加載中",repoSourceLink:"在 GitHub 查看本條目源文件",volumesMissing:"缺{n}",collapseVolumes:"收起分冊",expandVolumes:"展開分冊",collapseArrow:"收起 ▲",expandArrow:"展開 ▼",entitySubtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"集體"},cbdbTitle:"CBDB 中國歷代人物傳記數據庫",entityPlaceholderNote:"人物信息暫缺。該 Entity 僅作為作者佔位,詳細生平資料尚待補充。",otherVersions:"其他版本",switchToEdit:"切換到編輯模式",switchToView:"切換到查看模式",modeEdit:"✏️ 編輯",modeView:"👁 查看",noData:"無數據"},{toHans:"切换为简体",toHant:"切換為繁體",localeShortHans:"简",localeShortHant:"繁",themeLabel:"主题",theme:{zhusha:"朱砂",indigo:"靛青",ink:"墨"},loading:"加载中",repoSourceLink:"在 GitHub 查看本条目源文件",volumesMissing:"缺{n}",collapseVolumes:"收起分册",expandVolumes:"展开分册",collapseArrow:"收起 ▲",expandArrow:"展开 ▼",entitySubtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"集体"},cbdbTitle:"CBDB 中国历代人物传记数据库",entityPlaceholderNote:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。",otherVersions:"其他版本",switchToEdit:"切换到编辑模式",switchToView:"切换到查看模式",modeEdit:"✏️ 编辑",modeView:"👁 查看",noData:"无数据"}),mi=at({relation:{part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"},lossStatus:{extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"},resourceKind:{text:"文本",image:"影印",textImage:"圖文",physical:"館藏"},otherImages:"其他影印",fragmentTag:"殘片",collapseVolumes:"收起分冊",expandVolumes:"展開 {n} 冊",mirror:"鏡像",volumeStats:"{found} / {expected} 冊",volumeStatsMissing:"{found} / {expected} 冊 缺 {missing}",pageNav:"本頁導航",thisPage:"本頁",more:"更多",expandRest:"展開其餘 {n} {unit}",read:"閱讀",showMore:"顯示更多({n})",review:{reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"},dataVersion:"數據版本",todoCount:"待核 {n} 項",lacuna:"闕文",lacunaWith:"闕文:{label}",composedChar:"組字:{label}",bce:"前{n}",roleAll:"全部",loading:"加載中…",noLineageGraph:"暫無版本圖數據",notFound:"找不到該條目,可能已被刪除或 ID 不正確",workInfo:"作品信息"},{relation:{part_of:"所属",has_part:"包含",contains_text_of:"收录",collected_in:"丛编",text_carried_by:"载录",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"后继",derived_from:"衍生",has_adaptation:"改编",related:"相关"},lossStatus:{extant:"今存",fragment:"残存",partial:"残存",lost:"已佚",unknown:"未详"},resourceKind:{text:"文本",image:"影印",textImage:"图文",physical:"馆藏"},otherImages:"其他影印",fragmentTag:"残片",collapseVolumes:"收起分册",expandVolumes:"展开 {n} 册",mirror:"镜像",volumeStats:"{found} / {expected} 册",volumeStatsMissing:"{found} / {expected} 册 缺 {missing}",pageNav:"本页导航",thisPage:"本页",more:"更多",expandRest:"展开其余 {n} {unit}",read:"阅读",showMore:"显示更多({n})",review:{reviewed:"已审核",disputed:"有争议",unreviewed:"未审核",draft:"草稿"},dataVersion:"数据版本",todoCount:"待核 {n} 项",lacuna:"阙文",lacunaWith:"阙文:{label}",composedChar:"组字:{label}",bce:"前{n}",roleAll:"全部",loading:"加载中…",noLineageGraph:"暂无版本图数据",notFound:"找不到该条目,可能已被删除或 ID 不正确",workInfo:"作品信息"}),gp=at({kind:"版本",fact:{editionType:"版本類型",publication:"刊印",era:"刊寫年代",measure:"卷帙",volumes:"冊次",baseEdition:"底本",holdings:"存藏",callNumber:"索書號",seals:"藏印",leafStyle:"行款",binding:"裝幀",dimensions:"尺寸",condition:"品相",aliases:"又名"},inferredFromEdition:"據版本題名推斷",volumesValue:"第 {range} {unit}({n} {unit})",andMorePlaces:" 等 {n} 處",viewImages:"看原書影印",sec:{fulltext:"文本",images:"影印",physical:"館藏",lineage:"版本源流",empty:"影印與文本"},chapterUnit:"章",chapterCount:"{n} {unit}",sourceBy:"據{src}",readFrom:"從{ch}讀起",firstChapter:"第一章",enterReader:"進入閱讀頁",externalText:"站外文本",groupCount:"{n} 組",placeCount:"{n} 處",lineageMeta:"據版本傳承著錄",lineageView:"源流視圖",viewCards:"卡片",viewGraph:"關係圖",totalOf:"全 {n} {unit}",emptyText:"尚未著錄該版本的影印、文本與收藏信息。",editionCount:"{n} 種版本",siblings:"同作品版本",byEra:"按年代",kindCount:"{n} 種",viewAllInWork:"在作品頁看全部 {n} 種 →",volumeRange:"第 {range} {unit}",volumeCount:"{n} {unit}",confidence:{certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"},confidenceNote:"({c})",lineage:{ancestor:"祖本",reconstructed:"擬構祖本",thisEdition:"本版",derivatives:"翻刻 · 衍生",appendix:"附記"}},{kind:"版本",fact:{editionType:"版本类型",publication:"刊印",era:"刊写年代",measure:"卷帙",volumes:"册次",baseEdition:"底本",holdings:"存藏",callNumber:"索书号",seals:"藏印",leafStyle:"行款",binding:"装帧",dimensions:"尺寸",condition:"品相",aliases:"又名"},inferredFromEdition:"据版本题名推断",volumesValue:"第 {range} {unit}({n} {unit})",andMorePlaces:" 等 {n} 处",viewImages:"看原书影印",sec:{fulltext:"文本",images:"影印",physical:"馆藏",lineage:"版本源流",empty:"影印与文本"},chapterUnit:"章",chapterCount:"{n} {unit}",sourceBy:"据{src}",readFrom:"从{ch}读起",firstChapter:"第一章",enterReader:"进入阅读页",externalText:"站外文本",groupCount:"{n} 组",placeCount:"{n} 处",lineageMeta:"据版本传承著录",lineageView:"源流视图",viewCards:"卡片",viewGraph:"关系图",totalOf:"全 {n} {unit}",emptyText:"尚未著录该版本的影印、文本与收藏信息。",editionCount:"{n} 种版本",siblings:"同作品版本",byEra:"按年代",kindCount:"{n} 种",viewAllInWork:"在作品页看全部 {n} 种 →",volumeRange:"第 {range} {unit}",volumeCount:"{n} {unit}",confidence:{certain:"确证",consensus:"通说",probable:"可能",disputed:"有争议"},confidenceNote:"({c})",lineage:{ancestor:"祖本",reconstructed:"拟构祖本",thisEdition:"本版",derivatives:"翻刻 · 衍生",appendix:"附记"}}),fp=at({fact:{written:"成書",measure:"卷帙",loss:"存佚",earliest:"最早存世",emendation:"考證",alias:"又名",attached:"附載",appendix:"附錄"},inferredFromEdition:"據版本題名推斷",loading:"載入中",emendationCount:"{n} 條",stat:{editions:"版本",hasImage:"有影印",catalogs:"家著錄"},classifiedBy:"據《{source}》",sec:{versions:"版本",catalogs:"著錄",collected:"收入叢編",related:"相關書目",resources:"在線資源"},versionsTotal:"共 {n} 種",versionsWithImage:"{n} 種有影印",versionsCurrent:"當前 {n} 種",scanOnly:"只看有影印",sortByYear:"按年代排列",sortByCatalog:"按著錄順序",col:{edition:"版本",era:"年代",holder:"館藏",image:"影印"},noVersionsFiltered:"當前篩選下沒有版本",noVersions:"暫無版本著錄",moreUnit:"種版本",inferredEraNote:"部分年代據版本題名推斷,非著錄原文",empty:"尚未著錄該作品的版本與書目收錄。",relatedCount:"{n} 部",hasImage:"有影印",catalog:{meta:"歷代書目 {n} 家",tablist:"著錄書目",titleOnly:"僅著錄書名,無提要。",prev:"上一家:{name}",next:"下一家:{name}"}},{fact:{written:"成书",measure:"卷帙",loss:"存佚",earliest:"最早存世",emendation:"考证",alias:"又名",attached:"附载",appendix:"附录"},inferredFromEdition:"据版本题名推断",loading:"载入中",emendationCount:"{n} 条",stat:{editions:"版本",hasImage:"有影印",catalogs:"家著录"},classifiedBy:"据《{source}》",sec:{versions:"版本",catalogs:"著录",collected:"收入丛编",related:"相关书目",resources:"在线资源"},versionsTotal:"共 {n} 种",versionsWithImage:"{n} 种有影印",versionsCurrent:"当前 {n} 种",scanOnly:"只看有影印",sortByYear:"按年代排列",sortByCatalog:"按著录顺序",col:{edition:"版本",era:"年代",holder:"馆藏",image:"影印"},noVersionsFiltered:"当前筛选下没有版本",noVersions:"暂无版本著录",moreUnit:"种版本",inferredEraNote:"部分年代据版本题名推断,非著录原文",empty:"尚未著录该作品的版本与书目收录。",relatedCount:"{n} 部",hasImage:"有影印",catalog:{meta:"历代书目 {n} 家",tablist:"著录书目",titleOnly:"仅著录书名,无提要。",prev:"上一家:{name}",next:"下一家:{name}"}}),xp=at({kind:"叢編",workCollection:"作品集",stat:{titles:"子目"},fact:{publication:"刊印",expected:"應收",measure:"卷帙"},member:{Book:"所收版本",Work:"所收作品",other:"成員"},memberNote:"子目與其各版本合計",nZhong:"{n} 種",nHan:"{n} 函",dist:{head:"全帙冊次分佈",segTitle:"{section} 第 {from}–{to} 冊",only:"只看{section}",unclassified:"未分類",hint:"點色段篩選部類"},sec:{titles:"子目",resources:"影印與文本"},totalVolumes:"全帙 {n} {unit}",currentN:"當前 {n} {unit}",loadAllTitle:"將載入全部 {n} {unit}",grouping:"正在按部類分組…",groupBySection:"按部類分組",find:"在本叢編中檢索",col:{volumes:"冊次",title:"書名",versions:"版本"},volumeRange:"第 {range} {unit}",resourcesCount:"{n} 處",text:"文本",empty:"尚未著錄該叢編的子目。",parent:"上級叢編"},{kind:"丛编",workCollection:"作品集",stat:{titles:"子目"},fact:{publication:"刊印",expected:"应收",measure:"卷帙"},member:{Book:"所收版本",Work:"所收作品",other:"成员"},memberNote:"子目与其各版本合计",nZhong:"{n} 种",nHan:"{n} 函",dist:{head:"全帙册次分布",segTitle:"{section} 第 {from}–{to} 册",only:"只看{section}",unclassified:"未分类",hint:"点色段筛选部类"},sec:{titles:"子目",resources:"影印与文本"},totalVolumes:"全帙 {n} {unit}",currentN:"当前 {n} {unit}",loadAllTitle:"将载入全部 {n} {unit}",grouping:"正在按部类分组…",groupBySection:"按部类分组",find:"在本丛编中检索",col:{volumes:"册次",title:"书名",versions:"版本"},volumeRange:"第 {range} {unit}",resourcesCount:"{n} 处",text:"文本",empty:"尚未著录该丛编的子目。",parent:"上级丛编"}),bp=at({subtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"},bce:"前{n}",floruit:"活躍於 {from}—{to}",zi:"字{name}",hao:"號{name}",nativePlace:"{place}人",lifeAria:"{birth}—{death},一生 {years} 年",lifeYears:"一生 {years} 年",fact:{works:"著作"},nZhong:"{n} 種",moreNames:"更多別名({n})",dist:"著作分佈",autoMatch:"自動匹配",sec:{featured:"著作舉要",allWorks:"全部著作",works:"著作",external:"站外資料"},featuredSub:"存世版本最多的三部",versionsUnit:"種版本",hasImage:"有影印",empty:"尚未著錄該人物的關聯作品。",total:"共 {n} 種",current:"當前 {n} 種",sortByVersions:"按版本數排列",sortByCatalog:"按著錄順序",col:{work:"作品",section:"部類",role:"職任",versions:"存世版本",image:"影印"},notRecorded:"未著錄",emptyRole:"該職任下的著作尚未著錄。",moreUnit:"種著作",cbdbAuto:"CBDB 為自動匹配,未經人工核對"},{subtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群体"},bce:"前{n}",floruit:"活跃于 {from}—{to}",zi:"字{name}",hao:"号{name}",nativePlace:"{place}人",lifeAria:"{birth}—{death},一生 {years} 年",lifeYears:"一生 {years} 年",fact:{works:"著作"},nZhong:"{n} 种",moreNames:"更多别名({n})",dist:"著作分布",autoMatch:"自动匹配",sec:{featured:"著作举要",allWorks:"全部著作",works:"著作",external:"站外资料"},featuredSub:"存世版本最多的三部",versionsUnit:"种版本",hasImage:"有影印",empty:"尚未著录该人物的关联作品。",total:"共 {n} 种",current:"当前 {n} 种",sortByVersions:"按版本数排列",sortByCatalog:"按著录顺序",col:{work:"作品",section:"部类",role:"职任",versions:"存世版本",image:"影印"},notRecorded:"未著录",emptyRole:"该职任下的著作尚未著录。",moreUnit:"种著作",cbdbAuto:"CBDB 为自动匹配,未经人工核对"}),yp=at({imagesLoading:"加載書影…",noImages:"暫無書影",noImagesHint:"這一卷還沒有配上影像;接入後在此與正文逐頁對看",imageAlt:"書影 第 {label} 頁",prevImage:"上一頁書影",nextImage:"下一頁書影",back:"閱讀",backAria:"返回{label}首頁",skipToText:"跳到正文",settings:"閱讀設置",version:"版本",versionShort:"版本▾",unitJuan:"卷",pagerGroup:"翻{unit}",prevUnit:"上一{unit}",nextUnit:"下一{unit}",prevUnitTitle:"上一{unit}:{label}",nextUnitTitle:"下一{unit}:{label}",firstUnit:"已是第一{unit}",lastUnit:"已是最後一{unit}",toc:"目錄",images:"書影",fontSmaller:"縮小字號",fontLarger:"放大字號",paragraphTitle:"條目分行 ↔ 自然段",paragraph:"自然段",workLinks:"標出作品鏈接",properNameTitle:"書名加波浪線",properName:"專名線",vertical:"豎排",closeToc:"收起目錄",sourceLabel:"出處",licenseOf:"授權 {license}",revisedAt:"最近校訂 {date}",reportError:"報告錯字",pagerNav:"翻卷",rail:"本卷",bottomBar:"閱讀工具",tocShort:"卷目",fontSize:"字號",close:"關閉",loading:"加載中…",noText:"暫無文本",tocFailed:"無法加載目錄",tocLoading:"加載目錄…",viewEntry:"查看條目",defaultRole:"撰",tocCaption:"目錄 · {n} {unit}",searchChapters:"搜索全部章節",searchChaptersPlaceholder:"搜索全部章節…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"來源",upstream:"上游",chapterFailed:"無法加載章節內容",references:"參考文獻"},{imagesLoading:"加载书影…",noImages:"暂无书影",noImagesHint:"这一卷还没有配上影像;接入后在此与正文逐页对看",imageAlt:"书影 第 {label} 页",prevImage:"上一页书影",nextImage:"下一页书影",back:"阅读",backAria:"返回{label}首页",skipToText:"跳到正文",settings:"阅读设置",version:"版本",versionShort:"版本▾",unitJuan:"卷",pagerGroup:"翻{unit}",prevUnit:"上一{unit}",nextUnit:"下一{unit}",prevUnitTitle:"上一{unit}:{label}",nextUnitTitle:"下一{unit}:{label}",firstUnit:"已是第一{unit}",lastUnit:"已是最后一{unit}",toc:"目录",images:"书影",fontSmaller:"缩小字号",fontLarger:"放大字号",paragraphTitle:"条目分行 ↔ 自然段",paragraph:"自然段",workLinks:"标出作品链接",properNameTitle:"书名加波浪线",properName:"专名线",vertical:"竖排",closeToc:"收起目录",sourceLabel:"出处",licenseOf:"授权 {license}",revisedAt:"最近校订 {date}",reportError:"报告错字",pagerNav:"翻卷",rail:"本卷",bottomBar:"阅读工具",tocShort:"卷目",fontSize:"字号",close:"关闭",loading:"加载中…",noText:"暂无文本",tocFailed:"无法加载目录",tocLoading:"加载目录…",viewEntry:"查看条目",defaultRole:"撰",tocCaption:"目录 · {n} {unit}",searchChapters:"搜索全部章节",searchChaptersPlaceholder:"搜索全部章节…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"来源",upstream:"上游",chapterFailed:"无法加载章节内容",references:"参考文献"}),jp=at({nJuan:"{n}卷",viewWork:"查看作品",viewWorkOf:"查看作品:{title}",workArrow:"作品 →",arrowWork:"→作品",nWorks:"{n}部作品",unlinked:"未關聯",summary:"提要",comment:"按語",additionalComment:"附按",noMatch:"無匹配結果",sectionType:{类:"類",书:"書",序:"序",结语:"結語",注释:"註釋",考证:"考證",诗:"詩"},countTiao:"{n} 條",countTiaoOf:"{m} / {n} 條",countPoems:"{n} 首",countPoemsOf:"{m} / {n} 首",countBooks:"{n} 部書",countBooksOf:"{m} / {n} 部書",kaozhenTarget:"考證對象 {target}",baseText:"底本 {note}",textQuality:"文本質量",qualityLabel:{published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},qualityCriteria:{published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},originalSource:"原文來源",viewsGroup:"看法",viewText:"正文",viewEntries:"條目",rowHeadNo:"序",rowHeadTitle:"書名",rowHeadWork:"作品",railCap:"本卷",railUnitPoems:"首",railUnitBooks:"部書",linkedN:"已關聯 {n}",linkedOf:"已關聯 {n} / {total}",railEntriesNav:"本卷條目"},{nJuan:"{n}卷",viewWork:"查看作品",viewWorkOf:"查看作品:{title}",workArrow:"作品 →",arrowWork:"→作品",nWorks:"{n}部作品",unlinked:"未关联",summary:"提要",comment:"按语",additionalComment:"附按",noMatch:"无匹配结果",sectionType:{类:"类",书:"书",序:"序",结语:"结语",注释:"注释",考证:"考证",诗:"诗"},countTiao:"{n} 条",countTiaoOf:"{m} / {n} 条",countPoems:"{n} 首",countPoemsOf:"{m} / {n} 首",countBooks:"{n} 部书",countBooksOf:"{m} / {n} 部书",kaozhenTarget:"考证对象 {target}",baseText:"底本 {note}",textQuality:"文本质量",qualityLabel:{published:"出版",fine:"精校",rough:"粗校",ocr:"机器识别"},qualityCriteria:{published:"达到出版、学术研究标准,错误率在万分之一以内",fine:"通读无障碍,错误率在百分之一以内",rough:"保证文意基本正确,错误率在百分之三以内",ocr:"保持大意和结构,错误率在百分之十以内"},originalSource:"原文来源",viewsGroup:"看法",viewText:"正文",viewEntries:"条目",rowHeadNo:"序",rowHeadTitle:"书名",rowHeadWork:"作品",railCap:"本卷",railUnitPoems:"首",railUnitBooks:"部书",linkedN:"已关联 {n}",linkedOf:"已关联 {n} / {total}",railEntriesNav:"本卷条目"}),vp=at({typeShort:{work:"作",book:"版",collection:"叢",entity:"人"},typeLabel:{work:"作品",book:"版本",collection:"叢編",entity:"人物"},typeAll:"全部",typeChipsLabel:"按類型檢索",recentTitle:"最近瀏覽",recentClear:"清除",recentItemLabel:"{type} {title}",recentEmpty:"還沒有瀏覽記錄。打開任一條目後會出現在這裏。",status:{done:"已完成",in_progress:"進行中",todo:"計劃中"},siteStatus:{done:"已對接",in_progress:"進行中"},catalogTitle:"書目著錄進度",catalogNote:"每條著錄對到作品條目",colCatalog:"書目",colRecords:"著錄條目",colMatched:"已對上作品",colProgress:"進度",colStatus:"狀態",relatedTitle:"同類書目與考證",relatedNote:"不在書架上的",allNWorks:"全部 {n} 部",nKinds:"{n} 種",allNKinds:"全部 {n} 種",pavilion:"閣",yearBC:"前{n}",missingLife:"生卒年未錄、未上軸:{names}",viewLineage:"看版本譜系 →",plannedSites:"計劃接入:{names}",loss:{extant:"存",partially_extant:"殘",lost:"佚",unknown:"未詳"},lossNote:{extant:"今有傳本",partially_extant:"部分存世",lost:"僅見著錄",unknown:"尚未判定"},lossCount:"{n} 部 · {note}",stat:{works:"作品",books:"版本",collections:"叢編",entities:"人物",has_image:"有影印",has_text:"有文本",article:"單篇文",poem:"單篇詩"},dataScale:"數據規模",byLoss:"按存佚檢索",license:"古籍元數據以 CC0 公有領域發布,可自由複製、改編、再發布。",repo:"數據倉庫:",repoNote:"(GitHub,CC0)",version:"當前數據版本:",download:"引用方式與數據下載 →",navLabel:"元數據首頁分區",nav:{zhi:"歷代史志",sibu:"四部",cong:"叢編",people:"人物",lineage:"版本譜系",sites:"在線資源",data:"數據與授權"},zhiSub:"正史藝文志、經籍志與後人補志,按所志朝代排列;每部志的著錄逐條對到作品",shelfLegendCount:"脊下數字=著錄條目",shelfLegendClick:"點書脊進作品頁",sibuSub:"全部作品按經史子集分類;與「目錄」頁同一棵分類樹",toCatalog:"進入目錄 →",unclassifiedNote:"多為只見於史志著錄、尚未歸類的書",congSub:"大型叢書、影印彙編、出土文獻與館藏,逐種列到版本",allNKindsMore:"全部 {n} 種 →",peopleSub:"歷代目錄學家,按生卒年排在一條時間軸上",allNPeopleMore:"全部 {n} 人 →",lineageSub:"版本多的作品,看各本的源流與異同",sitesSub:"外部數字圖書館與本站條目的對接",dataSub:"規模、存佚、許可與版本"},{typeShort:{work:"作",book:"版",collection:"丛",entity:"人"},typeLabel:{work:"作品",book:"版本",collection:"丛编",entity:"人物"},typeAll:"全部",typeChipsLabel:"按类型检索",recentTitle:"最近浏览",recentClear:"清除",recentItemLabel:"{type} {title}",recentEmpty:"还没有浏览记录。打开任一条目后会出现在这里。",status:{done:"已完成",in_progress:"进行中",todo:"计划中"},siteStatus:{done:"已对接",in_progress:"进行中"},catalogTitle:"书目著录进度",catalogNote:"每条著录对到作品条目",colCatalog:"书目",colRecords:"著录条目",colMatched:"已对上作品",colProgress:"进度",colStatus:"状态",relatedTitle:"同类书目与考证",relatedNote:"不在书架上的",allNWorks:"全部 {n} 部",nKinds:"{n} 种",allNKinds:"全部 {n} 种",pavilion:"阁",yearBC:"前{n}",missingLife:"生卒年未录、未上轴:{names}",viewLineage:"看版本谱系 →",plannedSites:"计划接入:{names}",loss:{extant:"存",partially_extant:"残",lost:"佚",unknown:"未详"},lossNote:{extant:"今有传本",partially_extant:"部分存世",lost:"仅见著录",unknown:"尚未判定"},lossCount:"{n} 部 · {note}",stat:{works:"作品",books:"版本",collections:"丛编",entities:"人物",has_image:"有影印",has_text:"有文本",article:"单篇文",poem:"单篇诗"},dataScale:"数据规模",byLoss:"按存佚检索",license:"古籍元数据以 CC0 公有领域发布,可自由复制、改编、再发布。",repo:"数据仓库:",repoNote:"(GitHub,CC0)",version:"当前数据版本:",download:"引用方式与数据下载 →",navLabel:"元数据首页分区",nav:{zhi:"历代史志",sibu:"四部",cong:"丛编",people:"人物",lineage:"版本谱系",sites:"在线资源",data:"数据与授权"},zhiSub:"正史艺文志、经籍志与后人补志,按所志朝代排列;每部志的著录逐条对到作品",shelfLegendCount:"脊下数字=著录条目",shelfLegendClick:"点书脊进作品页",sibuSub:"全部作品按经史子集分类;与「目录」页同一棵分类树",toCatalog:"进入目录 →",unclassifiedNote:"多为只见于史志著录、尚未归类的书",congSub:"大型丛书、影印汇编、出土文献与馆藏,逐种列到版本",allNKindsMore:"全部 {n} 种 →",peopleSub:"历代目录学家,按生卒年排在一条时间轴上",allNPeopleMore:"全部 {n} 人 →",lineageSub:"版本多的作品,看各本的源流与异同",sitesSub:"外部数字图书馆与本站条目的对接",dataSub:"规模、存佚、许可与版本"}),Ro=at({readable:"部可讀",pieces:"篇單篇詩文",startReading:"開始閱讀 →",nCopies:"{n}本",shelfHint:"按所志朝代排列,一脊一部",shelfLegendCount:"脊下「2本」=站內有幾個本子",shelfOther:"其他",shelfRegion:"{label}書架,可橫向滾動",origZhi:"正史原志",laterZhi:"後人補撰、續補",spineBy:"{name} 撰",spineRecords:"著錄 {n} 條",spineOnSite:"站內 {n}",nWorks:"{n} 部",allNWorks:"全部 {n} 部",nCopiesCard:"{n} 個本子",workPageLink:"作品頁:{title}的源流與全部版本 →",sibuUnclassifiedNote:"書目分類還沒補齊,其中多數是單篇詩文,已單列在下方。",subClasses:"{label}子類",allNClasses:"{label}全部 {n} 類 →",unclassified:"未分類",viewUnclassified:"查看未分類 →",periodItem:"{label},{n} 部",periodUnknown:"另有 {n} 部作者無朝代,在「四部」和搜索裏能找到",hoverHint:"窄段懸停看全名",nPieces:"{n} 篇",authorAll:"{name}全部 {n} 篇 →",period:{xianqin:"先秦",qinhan:"秦漢",weijin:"魏晉南北朝",suitang:"隋唐五代",song:"宋",liaojinyuan:"遼金元",ming:"明",qing:"清",modern:"近現代"},navLabel:"閱讀首頁分區",nav:{picks:"推薦閱讀",topics:"專題",famous:"名著與版本",sibu:"四部",period:"按年代",pieces:"單篇詩文"},picksSub:"編輯挑選,定期輪換",topicsSub:"按作品類型歸組;小說見下方「名著與版本」",famousSub:"一部作品一張卡,卡上列出站內能讀的各個本子",sibuSub:"按古籍總目的分類樹,只計站內可讀的作品",periodSub:"按作者朝代歸段,寬度與部數成比例",piecesSub:"單篇的詩、文、賦、表,按作者歸組",piecesMore:"按作者瀏覽全部 →"},{readable:"部可读",pieces:"篇单篇诗文",startReading:"开始阅读 →",nCopies:"{n}本",shelfHint:"按所志朝代排列,一脊一部",shelfLegendCount:"脊下「2本」=站内有几个本子",shelfOther:"其他",shelfRegion:"{label}书架,可横向滚动",origZhi:"正史原志",laterZhi:"后人补撰、续补",spineBy:"{name} 撰",spineRecords:"著录 {n} 条",spineOnSite:"站内 {n}",nWorks:"{n} 部",allNWorks:"全部 {n} 部",nCopiesCard:"{n} 个本子",workPageLink:"作品页:{title}的源流与全部版本 →",sibuUnclassifiedNote:"书目分类还没补齐,其中多数是单篇诗文,已单列在下方。",subClasses:"{label}子类",allNClasses:"{label}全部 {n} 类 →",unclassified:"未分类",viewUnclassified:"查看未分类 →",periodItem:"{label},{n} 部",periodUnknown:"另有 {n} 部作者无朝代,在「四部」和搜索里能找到",hoverHint:"窄段悬停看全名",nPieces:"{n} 篇",authorAll:"{name}全部 {n} 篇 →",period:{xianqin:"先秦",qinhan:"秦汉",weijin:"魏晋南北朝",suitang:"隋唐五代",song:"宋",liaojinyuan:"辽金元",ming:"明",qing:"清",modern:"近现代"},navLabel:"阅读首页分区",nav:{picks:"推荐阅读",topics:"专题",famous:"名著与版本",sibu:"四部",period:"按年代",pieces:"单篇诗文"},picksSub:"编辑挑选,定期轮换",topicsSub:"按作品类型归组;小说见下方「名著与版本」",famousSub:"一部作品一张卡,卡上列出站内能读的各个本子",sibuSub:"按古籍总目的分类树,只计站内可读的作品",periodSub:"按作者朝代归段,宽度与部数成比例",piecesSub:"单篇的诗、文、赋、表,按作者归组",piecesMore:"按作者浏览全部 →"}),kp=at({sideNav:"分類導航",classification:"分類",drawerLabel:"分類:{path}",all:"全部",allTitle:"全部典籍",stat:"共 {total} 種 · 每頁 {size} 條",statPage:" · 第 {page} / {pages} 頁",viewLabel:"呈現方式",viewCard:"卡片",viewList:"列表",juanN:"{n}卷",pagerLabel:"分頁",prevPage:"上一頁",nextPage:"下一頁",pageN:"第 {n} 頁",emptyWorks:"此類暫無作品",zhulu:"著錄",cunmu:"存目",categoriesN:"{n} 類",divisionStat:"{cats} 類 · {books} 部",categoryJuan:"卷{n}",booksN:"{n} 部",expandAllN:"展開全部 {n} 條"},{sideNav:"分类导航",classification:"分类",drawerLabel:"分类:{path}",all:"全部",allTitle:"全部典籍",stat:"共 {total} 种 · 每页 {size} 条",statPage:" · 第 {page} / {pages} 页",viewLabel:"呈现方式",viewCard:"卡片",viewList:"列表",juanN:"{n}卷",pagerLabel:"分页",prevPage:"上一页",nextPage:"下一页",pageN:"第 {n} 页",emptyWorks:"此类暂无作品",zhulu:"著录",cunmu:"存目",categoriesN:"{n} 类",divisionStat:"{cats} 类 · {books} 部",categoryJuan:"卷{n}",booksN:"{n} 部",expandAllN:"展开全部 {n} 条"}),wp=at({loss:{all:"全部",extant:"存",partially_extant:"殘",lost:"佚"},unclassified:"未分類",statBook:"書",statComma:",",statBookCopies:"本",statArticle:"文章",statArticleUnit:"篇",statPoem:"詩詞",statPoemUnit:"首",statCollection:"叢編",submit:"搜索"},{loss:{all:"全部",extant:"存",partially_extant:"残",lost:"佚"},unclassified:"未分类",statBook:"书",statComma:",",statBookCopies:"本",statArticle:"文章",statArticleUnit:"篇",statPoem:"诗词",statPoemUnit:"首",statCollection:"丛编",submit:"搜索"}),Sp=at({title:"反饋",close:"關閉",submitType:{bug:"反饋錯誤",resource:"添加資源",suggestion:"功能建議",contact:"想參與"},placeholder:{bug:"請描述您發現的錯誤,包括頁面位置和具體內容",resource:"請提供完整資源鏈接和簡要版本說明",suggestion:"您希望網站增加或改進什麼?",contact:"想參與整理、校對或合作?簡單介紹一下您自己,並留下聯繫方式(此類留言不公開)"},chooseTypeFirst:"請先選擇反饋類型",contactPlaceholder:"郵箱(選填,僅站方可見,方便我們回覆您)",contactLabel:"聯繫方式(選填)",submitFailedRetry:"提交失敗,請稍後重試",submitFailed:"提交失敗",thanks:"感謝您的反饋!",viewList:"查看反饋列表 →",continueSubmit:"繼續提交",submitting:"提交中...",submit:"提交",submitFeedback:"提交反饋",listType:{bug:"錯誤反饋",resource:"資源建議",suggestion:"功能建議",other:"其他"},status:{pending:"待處理",in_progress:"處理中",resolved:"已處理",wontfix:"不採納",duplicate:"重複"},empty:"暫無反饋",reply:"回覆"},{title:"反馈",close:"关闭",submitType:{bug:"反馈错误",resource:"添加资源",suggestion:"功能建议",contact:"想参与"},placeholder:{bug:"请描述您发现的错误,包括页面位置和具体内容",resource:"请提供完整资源链接和简要版本说明",suggestion:"您希望网站增加或改进什么?",contact:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"},chooseTypeFirst:"请先选择反馈类型",contactPlaceholder:"邮箱(选填,仅站方可见,方便我们回复您)",contactLabel:"联系方式(选填)",submitFailedRetry:"提交失败,请稍后重试",submitFailed:"提交失败",thanks:"感谢您的反馈!",viewList:"查看反馈列表 →",continueSubmit:"继续提交",submitting:"提交中...",submit:"提交",submitFeedback:"提交反馈",listType:{bug:"错误反馈",resource:"资源建议",suggestion:"功能建议",other:"其他"},status:{pending:"待处理",in_progress:"处理中",resolved:"已处理",wontfix:"不采纳",duplicate:"重复"},empty:"暂无反馈",reply:"回复"}),_p=at({empty:"暫無版本傳承數據",emptyGraph:"暫無版本圖數據",modeList:"列表",modeGraph:"關係圖",collectionLabel:"集合:",collectionAll:"全部",collectionAllDesc:"顯示該作品所有版本(含橋接節點)",graphLoading:"加載圖組件中…",graphMissing:"圖組件未安裝。請安裝 {xyflow} 與 {dagre}。",graphMissingHint:"或使用 {list} 列表視圖。",bridgeTitle:"橋接節點:本身不在核心集,為保持派生鏈完整而顯示",otherGroup:"其他",lost:"已佚",fragment:"殘本",hypothetical:"假想祖本",bridge:"橋接",extant:"現存:{juan}",sources:"來源:",related:"關聯:",confidence:{certain:"確定",consensus:"共識",probable:"推測",disputed:"有爭議"}},{empty:"暂无版本传承数据",emptyGraph:"暂无版本图数据",modeList:"列表",modeGraph:"关系图",collectionLabel:"集合:",collectionAll:"全部",collectionAllDesc:"显示该作品所有版本(含桥接节点)",graphLoading:"加载图组件中…",graphMissing:"图组件未安装。请安装 {xyflow} 与 {dagre}。",graphMissingHint:"或使用 {list} 列表视图。",bridgeTitle:"桥接节点:本身不在核心集,为保持派生链完整而显示",otherGroup:"其他",lost:"已佚",fragment:"残本",hypothetical:"假想祖本",bridge:"桥接",extant:"现存:{juan}",sources:"来源:",related:"关联:",confidence:{certain:"确定",consensus:"共识",probable:"推测",disputed:"有争议"}}),$p={common:hp,detail:mi,bookPage:gp,workPage:fp,collectionPage:xp,entityPage:bp,reader:yp,collated:jp,metaHome:vp,readHome:Ro,catalogPage:kp,searchPage:wp,feedback:Sp,lineage:_p};function Cp(e){const n={};for(const[o,r]of Object.entries($p))n[o]=r[e];return n}function ut(e,n){return e.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}const Xr=new Map;function pn(e){let n=Xr.get(e);return n||(n={...e==="zh-Hans"?mp:up,...Cp(e)},Xr.set(e,n)),n}function Zr(e,n){let o=e;for(const r of n.split(".")){if(o==null||typeof o!="object")return;o=o[r]}return typeof o=="string"?o:void 0}function za(e){return(n,o)=>{const r=Zr(e,n)??Zr(pn("zh-Hant"),n)??n;return o?ut(r,o):r}}const Jr=new Map;function un(e){let n=Jr.get(e);return n||(n=za(pn(e)),Jr.set(e,n)),n}const Ta="bim-locale";function zp(){try{const e=localStorage.getItem(Ta);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Tp(e){try{localStorage.setItem(Ta,e)}catch{}}const Np="zh-Hans",Ep=({locale:e,onLocaleChange:n,converter:o,children:r})=>{const[s,a]=g.useState(e??Np),l=e??s;g.useEffect(()=>{if(e)return;const u=zp();u&&u!==s&&a(u)},[]);const d=g.useMemo(()=>l==="zh-Hans"?o??pp():null,[l,o]),c=g.useCallback(u=>{a(u),Tp(u),n==null||n(u)},[n]),p=g.useMemo(()=>({locale:l,setLocale:c,messages:pn(l),converter:d}),[l,c,d]);return t.jsx(qt.Provider,{value:p,children:r})};function ze(){const e=g.useContext(qt);return(e==null?void 0:e.messages)??pn("zh-Hant")}const Ip=2e3;function Re(){const e=g.useContext(qt),n=(e==null?void 0:e.locale)??"zh-Hant",o=(e==null?void 0:e.converter)??null,r=g.useRef(new Map),s=g.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const a=g.useCallback(l=>{if(!l)return"";if(!o)return l;const d=r.current.get(l);if(d!==void 0)return d;const c=o(l);if(r.current.size>=Ip){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(l,c),c},[o]);return g.useMemo(()=>({convert:a,locale:n,isSimplified:n==="zh-Hans"}),[a,n])}function J(){const e=g.useContext(qt),{convert:n,locale:o,isSimplified:r}=Re(),s=(e==null?void 0:e.messages)??pn("zh-Hant"),a=g.useMemo(()=>e?za(s):un("zh-Hant"),[e,s]);return g.useMemo(()=>({t:a,convert:n,locale:o,isSimplified:r,messages:s}),[a,n,o,r,s])}const Na=["錄說語詞議樣書記類傳國經補藝紀編後與間條號為開總種無數據冊頁選時題爲詩萬證學續關東圖資歷來讀館論見鈔別進師輯陳覽寫現應從","點兩華實對員長註結闕殘檢閱當會單換體將裡訂處過區釋術頭錢譯識個電動顯問這認質還幾遺雖須專擇係網運權務變發機請風聲輸軍導產","話們車難報讓業設帶辦紙氣麼際聽親場買賣謝費漢庫遷馬叢孫於張義晉閣維曆欽則夢慶齋録舊內陽樓紅淵歸載稱隱遼計評觀禮龜黃興節併","餘齊韓簡霑並樂諸滸屬組篩紹緒劉蘇誤職夾廣蓋敘斷歐寬駰極參試雜魯沒順線貞該測鮮統戰檔衛辭聯臺贊刪聖貫啟瀏譜薈寶約嘗諜謂舉詳","異賦軾復諒構級審標劃彙吳楊暫轉項寧硯蕭儀禪韻掃閉倉麗禎錯監鞏轍繫説筆竄縣聞諡賈僅擊羅宮訓談誌葉視戶細許祿繪鍵絕欄鑑講誕馮","趙習樹饋確賜裝擬規繼製薦畫鉛獨誠遠龍門覺訣隸軒諭繕塊爭鏡裏豐碼備掛堯錦駕鶴遊傷猶鄒瑩綴揚詔託僞頗竊虛莊歲禍爾辯獲篤窮盡跡","萊終穎訛瑣鐫繡廟幀佈躍雙預連狀態軸複懸遞灣箋頌訪層鏈敗達鈞鳳亂奮豈陰婁騎純優獻靈牆隨摺疊驗徑橫瀾蔣壞鈕盤範圍責減籤適側","榮聶頃縉讎銓廳軌厲鶚駢醫駝黨鐘諫樞滄軻溫贈鐵徵賴蹟潁閒顗歿駁歟勸諷誼湯詐脫羣尋澤擄顏釀謄鴻離騷傑滯憤執廢懼匱歎毀蠶獄寵闇","陸淺貨輕貧俠賤貴煩競樑鳩採綜謬鳴養堅韋顎呂蘭脈峯鵲兒賞籠階緊綱漁荊嬰慍潛營鎔繞陣塚億負卻塵懷閨擋撐縮領滾輪匯撈貼讚創險團","隊準礙強髒藥鮑顧給緯悅帳巖廬貢亞壇惡諱鎮薊驍愛討彌護揮偉輒擾況較響喪鑰藍"].join(""),Rp=new Set([...Na,...Object.keys(Se.VARIANT_CHARS)]),Ea=[...Ca,"切換為繁體","漢籍リポジトリ"];function Lp(e,n=Ea){let o=e;for(const a of n)a&&(o=o.split(a).join(" "));const r=[],s=Array.from(o);return s.forEach((a,l)=>{Rp.has(a)&&r.push({char:a,context:s.slice(Math.max(0,l-8),l+9).join("")})}),r}function Ap(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 Pp(){return{id:"",name:"",url:"",type:"text",details:""}}const so=({items:e,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const a=ze(),[l,d]=g.useState(null),c=[{value:"text",label:a.resourceTypeShort.text},{value:"image",label:a.resourceTypeShort.image},{value:"text+image",label:a.resourceTypeShort.textImage},{value:"physical",label:a.resourceTypeShort.physical}],p=[{value:"catalog",label:a.rootType.catalog},{value:"search",label:a.rootType.search}],u=b=>{if(!s)return!0;const j=Kt(b);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},m=e.map((b,j)=>({item:b,originalIndex:j})).filter(({item:b})=>u(b)),h=()=>{const b=Pp();s&&(b.type=s),n([...e,b]),d(e.length)},f=b=>{n(e.filter((j,S)=>S!==b)),d(null)},x=(b,j,S)=>{const v=[...e];if(v[b]={...v[b],[j]:S},j==="url"&&!v[b].id){const $=Ap(S);$&&(v[b].id=$)}n(v)},k=(b,j,S)=>{const $={...e[b].metadata||{}};S?$[j]=S:delete $[j],x(b,"metadata",Object.keys($).length>0?$:void 0)},y=(b,j)=>{const S=j.trim()?j.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;x(b,"structure",S)},w=(b,j,S)=>{const $=e[b].coverage||{level:1,ranges:""};j==="level"?$.level=parseInt(S)||1:$.ranges=S,x(b,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.map(({item:b,originalIndex:j})=>{var S,v,$;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>d(l===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Mp(b.type??"text"),color:i("on-color-fg")},children:(()=>{var C,M;const _=Kt(b);return _.length===0?b.type??"text":_.length===1?((C=c.find(T=>T.value===_[0]))==null?void 0:C.label)??_[0]:_.includes("text")&&_.includes("image")?((M=c.find(T=>T.value==="text+image"))==null?void 0:M.label)??"text+image":_.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${a.editor.resourcePlaceholder} ${j+1}`}),b.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:_=>_.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&b.url&&Bp(j,r==null?void 0:r[j],o,a),t.jsx("button",{onClick:_=>{_.stopPropagation(),f(j)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:a.editor.deleteThisResource,children:"✕"})]}),l===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[ap(b,"image")&&b.url&&Wp(b,a),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:jn,children:[t.jsx("span",{style:vn,children:a.label.type}),t.jsx("select",{value:b.type,onChange:_=>x(j,"type",_.target.value),style:{...vt,flex:1},children:c.map(_=>t.jsx("option",{value:_.value,children:_.label},_.value))})]}),t.jsxs("label",{style:jn,children:[t.jsx("span",{style:vn,children:a.label.rootType}),t.jsx("select",{value:b.root_type||"catalog",onChange:_=>x(j,"root_type",_.target.value),style:{...vt,flex:1},children:p.map(_=>t.jsx("option",{value:_.value,children:_.label},_.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:b.id,onChange:_=>x(j,"id",_.target.value),placeholder:a.editor.idAutoExtract,style:{...vt,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:b.name,onChange:_=>x(j,"name",_.target.value),placeholder:a.editor.resourceName,style:{...vt,flex:1}})]}),t.jsx("input",{type:"text",value:b.url,onChange:_=>x(j,"url",_.target.value),placeholder:a.editor.resourceUrl,style:vt}),t.jsx("input",{type:"text",value:((S=b.structure)==null?void 0:S.join("、"))||"",onChange:_=>y(j,_.target.value),placeholder:a.editor.structurePlaceholder,style:vt}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:jn,children:[t.jsx("span",{style:vn,children:a.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=b.coverage)==null?void 0:v.level)??"",onChange:_=>w(j,"level",_.target.value),placeholder:"1",style:{...vt,width:"60px"}})]}),t.jsxs("label",{style:{...jn,flex:1},children:[t.jsx("span",{style:vn,children:a.label.coverageRange}),t.jsx("input",{type:"text",value:(($=b.coverage)==null?void 0:$.ranges)||"",onChange:_=>w(j,"ranges",_.target.value),placeholder:a.editor.coverageRangePlaceholder,style:{...vt,flex:1}})]})]}),t.jsx("textarea",{value:b.details||"",onChange:_=>x(j,"details",_.target.value),placeholder:a.editor.detailsPlaceholder,style:{...vt,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:a.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(a.metadata).map(([_,C])=>{var M;return t.jsxs("label",{style:{...jn,gap:"4px"},children:[t.jsx("span",{style:{...vn,minWidth:"56px"},children:C}),t.jsx("input",{type:"text",value:((M=b.metadata)==null?void 0:M[_])||"",onChange:T=>k(j,_,T.target.value),placeholder:C,style:{...vt,flex:1}})]},_)})})]})]})]})]},j)}),t.jsxs("button",{onClick:h,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:a.action.addResource})]})]})};function Mp(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 Bp(e,n,o,r){const s=(n==null?void 0:n.status)==="downloading",a=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:l=>{l.stopPropagation(),s||o(e,"")},disabled:s,style:{background:"transparent",border:"none",color:i(a?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:a?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:a?"✓":s?"⏳":"⬇"})}function Wp(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 vt={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"},jn={display:"flex",alignItems:"center",gap:"6px"},vn={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},Op={"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 mn(e){try{return Op[new URL(e).hostname]}catch{return}}const Qr={text:0,image:1,physical:2};function Lo(e){return e.length===0?"physical":[...e].sort((n,o)=>(Qr[n]??99)-(Qr[o]??99)).join("+")}function Ao(e){var l;const n=d=>{const c=d.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const p=d.match(/^(.+?)[·(](\d+)[)]?$/);return p?[p[1],parseInt(p[2])]:null},o=new Map;for(let d=0;d<e.length;d++){const c=e[d];if(c.volumes&&c.volumes.length>0)continue;const p=n(c.name);if(!p)continue;const[u,m]=p,h=`${u}|${Lo(Kt(c))}`;o.has(h)||o.set(h,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const f=o.get(h);f.volumes.push({volume:m,url:c.url||void 0,status:"found"}),f.indices.push(d)}const r=[],s=new Set;for(const d of o.values())if(!(d.volumes.length<2)){d.volumes.sort((c,p)=>c.volume-p.volume),d.base.volumes=d.volumes,d.base.expected_volumes=d.volumes.length,d.base.url||(d.base.url=((l=d.volumes.find(c=>c.url))==null?void 0:l.url)??""),r.push(d.base);for(const c of d.indices)s.add(c)}const a=[...r];for(let d=0;d<e.length;d++)s.has(d)||a.push(e[d]);return a}function Ia(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 Ra(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||Ia(n)}))}function hi(e){const n=Ra(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 Po(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 Mo(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 hn(e){if(!e.url)return;const n=Po(e.metadata);return n?Mo(e.url,n):e.url}const es={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function Hp(e){return e.includes("text")&&e.includes("image")?es["text+image"]:es[e[0]||"physical"]}const Bo=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const a=ze(),{convert:l}=Re(),d=g.useMemo(()=>Ao(e||[]),[e]),{mirrorGroups:c,ungroupedItems:p}=g.useMemo(()=>{const y=new Map,w=[];for(const b of d){const j=b.group;j?(y.has(j)||y.set(j,[]),y.get(j).push(b)):w.push(b)}for(const b of y.values())b.sort((j,S)=>{const v=$=>$.group_role==="origin"?0:$.group_role==="mirror"?1:2;return v(j)-v(S)});return{mirrorGroups:y,ungroupedItems:w}},[d]),u={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},m=y=>u[y]?u[y]:y.split("+").map(w=>u[w]||w).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:a.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:d.map((y,w)=>t.jsx(Fi,{item:y},y.id||w))});const h=(y,w)=>{const b=o==null?void 0:o[y],j=(b==null?void 0:b.label)||y,S=b==null?void 0:b.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:l(j)}),S&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:l(S)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.map((v,$)=>t.jsx(Fi,{item:v,onNavigate:r,renderLink:s},v.id||$))})]},`group-${y}`)},f=new Map;for(const y of p){const w=Lo(Kt(y));f.has(w)||f.set(w,[]),f.get(w).push(y)}const x=["text","image","text+image","physical"],k=[...x.filter(y=>f.has(y)),...[...f.keys()].filter(y=>!x.includes(y)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([y,w])=>h(y,w)),k.map(y=>{const w=f.get(y),b=Hp(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:b,whiteSpace:"nowrap",flexShrink:0},children:m(y)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.map((j,S)=>t.jsx(Fi,{item:j,onNavigate:r,renderLink:s},j.id||S))})]},y)})]})},Fp={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},Fi=({item:e})=>{const n=ze(),{convert:o}=Re(),[r,s]=g.useState(!1),a=g.useMemo(()=>(e.url?mn(e.url):void 0)||o(e.name),[e.url,e.name,o]),l=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(x=>({...x,url:x.url||Ia(x)})),[e.volumes]),d=l&&l.length>0,c=d?new Set(l.filter(x=>x.status!=="missing").map(x=>x.volume)).size:0,p=d?new Set(l.filter(x=>x.status==="missing").map(x=>x.volume)).size:0,u=e.expected_volumes??(d?c+p:0),m=e.color_mode?{...Fp[e.color_mode],label:n.colorMode[e.color_mode]}:null,h=e.details&&!d?o(e.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 t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:f,children:[t.jsx("span",{style:{fontWeight:500},children:a}),m&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:m.bg,color:m.fg},children:m.label}),h&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:h}),d&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[c,"/",u,n.unit.volume,p>0&&t.jsx("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:ut(n.common.volumesMissing,{n:p})})]}),e.url&&t.jsx("a",{href:(()=>{const x=Po(e.metadata);return x?Mo(e.url,x):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),d&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),d&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(x=>{const k=x.status==="missing";return x.url&&!k?t.jsx("a",{href:x.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:x.volume},x.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(k?"missing-fg":"desc-fg"),textDecoration:k?"line-through":"none",opacity:k?.6:1},children:x.volume},x.volume)})})]})},La=({indexSource:e,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:a,onSelectFolder:l})=>{const d=ze(),c=e==="local",p=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",m=u?u.split(/[/\\]/).pop()||u:"",h={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:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},x=t.jsxs("div",{onClick:s,title:p?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...h,background:i(p?"warning":"success"),color:i("on-color-fg")},...f,children:[t.jsx("span",{children:p?"📝":"📚"}),t.jsx("span",{children:p?"draft":"official"})]});return o==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[x,t.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:h,...f,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:l,title:u||d.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...f,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:[x,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:d.mode.switchToLocal,style:h,...f,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:a,title:m||d.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...f,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:h,...f,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:l,title:u||d.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...f,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]}),!c&&m&&t.jsxs("div",{style:{...h,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})]})]})},gi="bim-search-history",ts=10,ns=8;function Tn(){try{const e=localStorage.getItem(gi);return e?JSON.parse(e):[]}catch{return[]}}function Aa(e){try{const n=Tn().filter(o=>o!==e);n.unshift(e),n.length>ts&&(n.length=ts),localStorage.setItem(gi,JSON.stringify(n))}catch{}}function Dp(e){try{const n=Tn().filter(o=>o!==e);localStorage.setItem(gi,JSON.stringify(n))}catch{}}function Up(){try{localStorage.removeItem(gi)}catch{}}const Pa=({transport:e,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:a})=>{const l=ze(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,u]=g.useState(!1),[m,h]=g.useState([]),[f,x]=g.useState(-1),[k,y]=g.useState(Tn),w=g.useRef(null),b=g.useRef(null),j=g.useRef(null),S=g.useRef(!1);g.useEffect(()=>{x(-1);const z=n.trim();if(!z){h(k.map(I=>({type:"history",text:I})));return}if(!e.searchAll){h([]);return}let H=!1;const N=setTimeout(()=>{e.searchAll(z,ns).then(I=>{if(H)return;const L=[...I.works,...I.books,...I.collections,...I.entities??[]];h(L.slice(0,ns).map(R=>({type:"entry",text:R.title||R.id,entry:R})))}).catch(()=>{H||h([])})},80);return()=>{H=!0,clearTimeout(N)}},[n,k,e]),g.useEffect(()=>{const z=H=>{j.current&&!j.current.contains(H.target)&&u(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[]),g.useEffect(()=>{const z=H=>{var N,I;if(H.key==="/"&&document.activeElement!==w.current){const L=(N=document.activeElement)==null?void 0:N.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;H.preventDefault(),(I=w.current)==null||I.focus()}};return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[]);const v=g.useCallback(z=>{z.trim()&&(Aa(z.trim()),y(Tn())),r(z),u(!1)},[r]),$=g.useCallback(z=>{z.type==="history"?(o(z.text),v(z.text)):z.entry&&(s?(s(z.entry),u(!1)):(o(z.text),v(z.text)))},[o,v,s]),_=g.useCallback(z=>{if(!p||m.length===0){z.key==="Enter"&&v(n);return}switch(z.key){case"ArrowDown":z.preventDefault(),x(H=>(H+1)%m.length);break;case"ArrowUp":z.preventDefault(),x(H=>(H-1+m.length)%m.length);break;case"Enter":z.preventDefault(),f>=0&&f<m.length?$(m[f]):v(n);break;case"Escape":z.preventDefault(),u(!1);break}},[p,m,f,n,v,$]),C=g.useCallback((z,H)=>{H.stopPropagation(),Dp(z),y(Tn()),h(N=>N.filter(I=>!(I.type==="history"&&I.text===z)))},[]),M=g.useCallback(z=>{z.stopPropagation(),Up(),y([]),h([])},[]);g.useEffect(()=>{if(f>=0&&b.current){const z=b.current.children;z[f]&&z[f].scrollIntoView({block:"nearest"})}},[f]);const T=!n.trim()&&k.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:w,type:"text",placeholder:d,value:n,onChange:z=>{o(z.target.value),u(!0)},onCompositionStart:()=>{S.current=!0},onCompositionEnd:()=>{S.current=!1},onFocus:()=>{u(!0)},onKeyDown:_,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),p&&m.length>0&&t.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:i("desc-fg"),borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:M,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),m.map((z,H)=>t.jsxs("div",{onClick:()=>$(z),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:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:z.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.text}),z.entry&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:[c[z.entry.type],z.entry.edition&&` · ${z.entry.edition}`,z.entry.author&&` · ${z.entry.author}`]}),z.type==="history"&&t.jsx("button",{onClick:N=>C(z.text,N),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${z.type}-${z.text}-${H}`))]})]})},gn=({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"}}),fi={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Ma=new Set(["work","book","entity"]);function Vp(e){return Oa(e)||!!e.sort}function Gp(e,n){return n.sort&&Ma.has(e)?n.sort:void 0}const xi=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],bi=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Ba=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Wa={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function yi(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 Oa(e){return yi(e)>0}function Yp(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 Ha(e,n){const o=Wa[e];return Yp(n).every(r=>o.has(r))}const kn=e=>JSON.stringify(e);function Kp(e,n){if(!Ha(n,e))return null;const o=[];if(e.dynasty.length){const r=Array.from(new Set(e.dynasty.flatMap(s=>{var a;return((a=xi.find(l=>l.key===s))==null?void 0:a.values)??[]})));r.length===1?o.push(`dynasty = ${kn(r[0])}`):r.length>1&&o.push(`dynasty IN [${r.map(kn).join(", ")}]`)}return e.classification.length&&o.push(e.classification.length===1?`classification = ${kn(e.classification[0])}`:`classification IN [${e.classification.map(kn).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 = ${kn(e.loss)}`),o.join(" AND ")}const it={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},Fa="_";function si(e,n=new URLSearchParams){for(const o of Object.values(it))n.delete(o);return e.dynasty.length&&n.set(it.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(it.classification,e.classification.map(o=>o||Fa).join(",")),e.hasImage&&n.set(it.hasImage,"1"),e.hasText&&n.set(it.hasText,"1"),e.hasCollated&&n.set(it.hasCollated,"1"),e.loss&&n.set(it.loss,e.loss),e.sort&&n.set(it.sort,e.sort),n}function qp(e){const n=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),o=new Set(xi.map(a=>a.key)),r=new Set(bi.map(a=>a.value)),s=e.get(it.loss);return{dynasty:Array.from(new Set(n(it.dynasty).filter(a=>o.has(a)))),classification:Array.from(new Set(n(it.classification).map(a=>a===Fa?"":a).filter(a=>r.has(a)))),hasImage:e.get(it.hasImage)==="1",hasText:e.get(it.hasText)==="1"||e.get(it.hasCollated)==="1",hasCollated:!1,loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(a=>a===e.get(it.sort))??""}}function Xp(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 is(e,n){return e.includes(n)?e.filter(o=>o!==n):[...e,n]}const Zp=({filters:e,onChange:n})=>{const o=ze(),r=o.searchV4,{convert:s}=Re(),[a,l]=g.useState(!1),d=g.useId(),c=yi(e),p=u=>n({...e,...u});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":s(r.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":a,"aria-controls":d,onClick:()=>l(u=>!u),children:[t.jsxs("span",{children:[s(r.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:s(ut(r.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[s(a?r.collapse:r.expand)," ",a?"▴":"▾"]})]}),t.jsxs("div",{className:"bim-sr-filters",id:d,"data-open":a?"true":"false",...a?{}:{"data-collapsed":"true"},children:[t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(r.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:xi.map(u=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(u.key),onClick:()=>p({dynasty:is(e.dynasty,u.key)}),children:s(u.key)},u.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(r.classification)}),bi.map(u=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(u.value),onChange:()=>p({classification:is(e.classification,u.value)})}),u.value?s(u.label):o.searchPage.unclassified]},u.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(r.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:u=>p({hasImage:u.target.checked})}),s(r.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:u=>p({hasText:u.target.checked})}),s(r.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:s(r.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:Ba.map(u=>t.jsx("button",{type:"button","aria-pressed":e.loss===u.value,onClick:()=>p({loss:u.value}),children:o.searchPage.loss[u.value||"all"]},u.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...fi,sort:e.sort}),children:s(r.clearAllFilters)})]})]})};function Da({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(),a=[];let l=0,d=0;for(;l<e.length;){const c=r.indexOf(s,l);if(c<0){a.push(e.slice(l));break}c>l&&a.push(e.slice(l,c)),a.push(t.jsx("mark",{className:"bim-sr-hl",children:e.slice(c,c+s.length)},d++)),l=c+s.length}return t.jsx(t.Fragment,{children:a})}const os=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=ze(),a=s.searchV4,{convert:l}=Re(),d=Je();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:l(a.colTitle)}),t.jsx("th",{scope:"col",children:l(a.colType)}),t.jsx("th",{scope:"col",children:l(a.colAuthor)}),t.jsx("th",{scope:"col",children:l(a.colEra)}),t.jsx("th",{scope:"col",children:l(a.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:l(a.colResource)})]})}),t.jsx("tbody",{children:e.map(c=>{const p=l(c.title||c.primary_name||c.id),u=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",m=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${l(c.author)}${c.role&&c.role!=="author"?` ${l(c.role)}`:""}`:"",h=c.type==="book"?c.era??c.dynasty:c.dynasty,f=h?l(h):"",x=c.classification?l(c.classification):"",k=[];c.has_image&&k.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&k.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&k.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const y=[m,f,x].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:d(c.id),onClick:w=>o(c,w),children:t.jsx(Da,{text:p,query:n?l(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(gn,{type:c.type,size:6})," ",r(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:m||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:f||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:x||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:k.map(w=>t.jsx("span",{className:`bim-sr-tag ${w.cls}`,children:l(w.label)},w.label))})]},c.id)})})]})})},Jp=`
1
+ "use strict";var Xd=Object.create;var Xr=Object.defineProperty;var Zd=Object.getOwnPropertyDescriptor;var Jd=Object.getOwnPropertyNames;var Qd=Object.getPrototypeOf,ep=Object.prototype.hasOwnProperty;var tp=(e,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Jd(n))!ep.call(e,s)&&s!==o&&Xr(e,s,{get:()=>n[s],enumerable:!(r=Zd(n,s))||r.enumerable});return e};var Zn=(e,n,o)=>(o=e!=null?Xd(Qd(e)):{},tp(n||!e||!e.__esModule?Xr(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./storage-entry-BDcJjAiW.cjs"),t=require("react/jsx-runtime"),g=require("react"),np=require("opencc-js/t2cn"),ip=require("react-markdown"),op=require("remark-gfm"),rp=e=>`/book-index?id=${e}`,_a=g.createContext(rp);function sp({buildUrl:e,children:n}){const o=g.useMemo(()=>e,[e]);return t.jsx(_a.Provider,{value:o,children:n})}function Ze(){return g.useContext(_a)}const $a="",Ca="";function Lo(e){const n=[];let o=!1,r=e;for(;r.length;){const s=o?Ca:$a,a=r.indexOf(s);if(a===-1){n.push({text:r,marked:o});break}a>0&&n.push({text:r.slice(0,a),marked:o}),r=r.slice(a+1),o=!o}return n}function rt(e,n){return{title:e,tokens:n}}const Zr='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',ap=[rt("基础(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"}}),rt("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),rt("提示与警告",{"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)"}}),rt("遮罩与阴影",{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)"}}),rt("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),rt("资源",{"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"}}),rt("整理本(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"}}),rt("版本传承(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"}}),rt("编辑器视图(主要在 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")'}}),rt("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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:"#3b4a58",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}}),rt('版式(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:"14px 18px",note:"区块标题栏内边距。10-01 起疏朗也有淡染底的标题栏(--bim-fr-hd-bg),故疏朗 14px 18px,界栏 12px 18px"},"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:"页签行下沿线颜色(疏朗不画,界栏画)"},"fr-hd-size":{value:"24px",note:"分区标题字号。界栏标题在框顶标题栏里,小一档 19px"},"fr-hd-bg":{value:"color-mix(in srgb, var(--bim-accent) 7%, var(--bim-page-bg))",note:"分区标题栏底色(淡染主色)。疏朗混进页面底,界栏 6% 混进卡面底。主色取 accent(primary 是 VS Code 按钮蓝,不随配色)"},"fr-card-bd":{value:"1px solid transparent",note:"卡片边框。疏朗不画(靠卡面底与淡投影);界栏 1px"},"fr-card-bg":{value:"var(--bim-card-bg)",note:"卡片底"},"fr-row-bd":{value:"1px solid transparent",note:"列表行线、块内小分割线。疏朗不画(靠行距);界栏 1px"},"fr-row-pad":{value:"10px 2px",note:"列表行内边距。界栏收紧 7px 2px"},"fr-chrome-bd":{value:"1px solid transparent",note:"顶栏、分区导航(吸顶锚点条)的线"},"fr-tag-bd":{value:"1px solid transparent",note:"标签、版本签、计数签、工具按钮的边框。疏朗浅底无框;界栏透明底加框"},"fr-tag-bg":{value:"var(--bim-tint-bg)",note:"标签底"},"fr-tbl-cell-bd":{value:"0 solid transparent",note:"表格格线。疏朗不画(靠斑马纹);界栏全格线"},"fr-tbl-zebra":{value:"var(--bim-tint-bg)",note:"表格斑马纹(只在疏朗下有)"},"fr-rail-bd":{value:"1px solid transparent",note:"侧栏里的块、提示块的边框"},"fr-rail-bg":{value:"var(--bim-tint-bg)",note:"侧栏块底。疏朗浅底;界栏卡面底"},"fr-spine-bd":{value:"1px solid transparent",note:"题签、书脊(竖排书名)的边框。界栏是强调色浅线"},"fr-spine-bg":{value:"var(--bim-flag-bg)",note:"题签、书脊底。疏朗浅色实底;界栏卡面底(正史原志两种版式都是强调色实底)"},"fr-plank":{value:"0 solid transparent",note:"书架架板(border 简写)。只在界栏下画 3px"},"fr-axis-bd":{value:"0 solid transparent",note:"时间轴轴线。界栏 1px"},"fr-axis-band":{value:"6px",note:"时间轴底带高度。疏朗用 6px 浅色带代替轴线;界栏 0"},"fr-tick":{value:"0",note:"时间轴刻度短线长度。界栏 5px"},"fr-band-gap":{value:"3px",note:"年代带各段之间的空隙。疏朗 3px;界栏紧贴"},"fr-band-bd":{value:"0 solid transparent",note:"年代带外框与段间分隔。界栏 1px"}}),rt("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"},"warp-bg":{value:"#faf8f5",note:"古籍矫正底本书影画布底色"},"warp-box-shadow":{value:"0 2px 12px rgba(0, 0, 0, 0.08)",note:"古籍底本书影浮雕阴影"},"warp-sel-bg":{value:"rgba(196, 148, 76, 0.45)",note:"古籍对读字框选中高亮底色"},"warp-sel-stroke":{value:"#a06e1c",note:"古籍对读字框选中描边"},"warp-hover-bg":{value:"rgba(217, 185, 106, 0.25)",note:"古籍对读字框悬停高亮底色"},"warp-hover-stroke":{value:"#c4944c",note:"古籍对读字框悬停描边"},"warp-badge-bg":{value:"rgba(184, 134, 54, 0.12)",note:"图文对读徽章背景"},"warp-badge-fg":{value:"#8c6820",note:"图文对读徽章文字颜色"},"warp-badge-bd":{value:"rgba(184, 134, 54, 0.3)",note:"图文对读徽章边框"},"warp-banxin-border":{value:"#8a8070",note:"版心分界线"},"warp-banxin-fold":{value:"rgba(160, 110, 28, 0.65)",note:"版心中缝对折线"},"warp-banxin-outer":{value:"#c9c3b4",note:"版心外边线"}}),rt("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),rt("字体(全站无衬线,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:Zr,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Zr,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],lp=Object.assign({},...ap.map(e=>e.tokens)),za={};for(const[e,n]of Object.entries(lp))za[e]=`var(--bim-${e}, ${n.value})`;function i(e){const n=za[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function qt(e){return e.types&&e.types.length>0?e.types:e.type?e.type==="text+image"?["text","image"]:[e.type]:[]}function cp(e,n){return qt(e).includes(n)}const dp={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"};i("quality-published"),i("quality-fine"),i("quality-rough"),i("quality-ocr");const Xt=g.createContext(null),Ta=["曹霑"];function pp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function up(e,n=Ta){const o=[...new Set(n.filter(Boolean))].sort((a,l)=>l.length-a.length);if(!o.length)return e;const r=new RegExp(`(${o.map(pp).join("|")})`,"g"),s=new Set(o);return a=>{if(!a)return e(a);const l=a.split(r);return l.length===1?e(a):l.map((d,c)=>c%2===1&&s.has(d)?d:d&&e(d)).join("")}}let vn=null;function mp(){if(vn)return vn;try{const e=np.Converter({from:"t",to:"cn"});vn=up(n=>e(_e.normalizeVariants(n)))}catch{vn=e=>e}return vn}const hp={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"},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:"圖片資源"}},gp={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"},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:"图片资源"}};function at(e,n,o){return{"zh-Hant":e,"zh-Hans":n}}const fp=at({toHans:"切换为简体",toHant:"切換為繁體",localeShortHans:"简",localeShortHant:"繁",themeLabel:"主題",theme:{zhusha:"朱砂",indigo:"靛青",ink:"墨"},loading:"加載中",repoSourceLink:"在 GitHub 查看本條目源文件",volumesMissing:"缺{n}",collapseVolumes:"收起分冊",expandVolumes:"展開分冊",collapseArrow:"收起 ▲",expandArrow:"展開 ▼",entitySubtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"集體"},cbdbTitle:"CBDB 中國歷代人物傳記數據庫",entityPlaceholderNote:"人物信息暫缺。該 Entity 僅作為作者佔位,詳細生平資料尚待補充。",otherVersions:"其他版本",switchToEdit:"切換到編輯模式",switchToView:"切換到查看模式",modeEdit:"✏️ 編輯",modeView:"👁 查看",noData:"無數據"},{toHans:"切换为简体",toHant:"切換為繁體",localeShortHans:"简",localeShortHant:"繁",themeLabel:"主题",theme:{zhusha:"朱砂",indigo:"靛青",ink:"墨"},loading:"加载中",repoSourceLink:"在 GitHub 查看本条目源文件",volumesMissing:"缺{n}",collapseVolumes:"收起分册",expandVolumes:"展开分册",collapseArrow:"收起 ▲",expandArrow:"展开 ▼",entitySubtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"集体"},cbdbTitle:"CBDB 中国历代人物传记数据库",entityPlaceholderNote:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。",otherVersions:"其他版本",switchToEdit:"切换到编辑模式",switchToView:"切换到查看模式",modeEdit:"✏️ 编辑",modeView:"👁 查看",noData:"无数据"}),gi=at({relation:{part_of:"所屬",has_part:"包含",contains_text_of:"收錄",collected_in:"叢編",text_carried_by:"載錄",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"後繼",derived_from:"衍生",has_adaptation:"改編",related:"相關"},lossStatus:{extant:"今存",fragment:"殘存",partial:"殘存",lost:"已佚",unknown:"未詳"},resourceKind:{text:"文本",image:"影印",textImage:"圖文",physical:"館藏"},otherImages:"其他影印",fragmentTag:"殘片",collapseVolumes:"收起分冊",expandVolumes:"展開 {n} 冊",mirror:"鏡像",volumeStats:"{found} / {expected} 冊",volumeStatsMissing:"{found} / {expected} 冊 缺 {missing}",pageNav:"本頁導航",thisPage:"本頁",more:"更多",expandRest:"展開其餘 {n} {unit}",read:"閱讀",showMore:"顯示更多({n})",review:{reviewed:"已審核",disputed:"有爭議",unreviewed:"未審核",draft:"草稿"},dataVersion:"數據版本",todoCount:"待核 {n} 項",lacuna:"闕文",lacunaWith:"闕文:{label}",composedChar:"組字:{label}",bce:"前{n}",roleAll:"全部",loading:"加載中…",noLineageGraph:"暫無版本圖數據",notFound:"找不到該條目,可能已被刪除或 ID 不正確",workInfo:"作品信息"},{relation:{part_of:"所属",has_part:"包含",contains_text_of:"收录",collected_in:"丛编",text_carried_by:"载录",studied_by:"研究",studies:"所考",preceded_by:"前承",followed_by:"后继",derived_from:"衍生",has_adaptation:"改编",related:"相关"},lossStatus:{extant:"今存",fragment:"残存",partial:"残存",lost:"已佚",unknown:"未详"},resourceKind:{text:"文本",image:"影印",textImage:"图文",physical:"馆藏"},otherImages:"其他影印",fragmentTag:"残片",collapseVolumes:"收起分册",expandVolumes:"展开 {n} 册",mirror:"镜像",volumeStats:"{found} / {expected} 册",volumeStatsMissing:"{found} / {expected} 册 缺 {missing}",pageNav:"本页导航",thisPage:"本页",more:"更多",expandRest:"展开其余 {n} {unit}",read:"阅读",showMore:"显示更多({n})",review:{reviewed:"已审核",disputed:"有争议",unreviewed:"未审核",draft:"草稿"},dataVersion:"数据版本",todoCount:"待核 {n} 项",lacuna:"阙文",lacunaWith:"阙文:{label}",composedChar:"组字:{label}",bce:"前{n}",roleAll:"全部",loading:"加载中…",noLineageGraph:"暂无版本图数据",notFound:"找不到该条目,可能已被删除或 ID 不正确",workInfo:"作品信息"}),xp=at({kind:"版本",fact:{editionType:"版本類型",publication:"刊印",era:"刊寫年代",measure:"卷帙",volumes:"冊次",baseEdition:"底本",holdings:"存藏",callNumber:"索書號",seals:"藏印",leafStyle:"行款",binding:"裝幀",dimensions:"尺寸",condition:"品相",aliases:"又名"},inferredFromEdition:"據版本題名推斷",volumesValue:"第 {range} {unit}({n} {unit})",andMorePlaces:" 等 {n} 處",viewImages:"看原書影印",sec:{fulltext:"文本",images:"影印",physical:"館藏",lineage:"版本源流",empty:"影印與文本"},chapterUnit:"章",chapterCount:"{n} {unit}",sourceBy:"據{src}",readFrom:"從{ch}讀起",firstChapter:"第一章",enterReader:"進入閱讀頁",externalText:"站外文本",groupCount:"{n} 組",placeCount:"{n} 處",lineageMeta:"據版本傳承著錄",lineageView:"源流視圖",viewCards:"卡片",viewGraph:"關係圖",totalOf:"全 {n} {unit}",emptyText:"尚未著錄該版本的影印、文本與收藏信息。",editionCount:"{n} 種版本",siblings:"同作品版本",byEra:"按年代",kindCount:"{n} 種",viewAllInWork:"在作品頁看全部 {n} 種 →",volumeRange:"第 {range} {unit}",volumeCount:"{n} {unit}",confidence:{certain:"確證",consensus:"通說",probable:"可能",disputed:"有爭議"},confidenceNote:"({c})",lineage:{ancestor:"祖本",reconstructed:"擬構祖本",thisEdition:"本版",derivatives:"翻刻 · 衍生",appendix:"附記"}},{kind:"版本",fact:{editionType:"版本类型",publication:"刊印",era:"刊写年代",measure:"卷帙",volumes:"册次",baseEdition:"底本",holdings:"存藏",callNumber:"索书号",seals:"藏印",leafStyle:"行款",binding:"装帧",dimensions:"尺寸",condition:"品相",aliases:"又名"},inferredFromEdition:"据版本题名推断",volumesValue:"第 {range} {unit}({n} {unit})",andMorePlaces:" 等 {n} 处",viewImages:"看原书影印",sec:{fulltext:"文本",images:"影印",physical:"馆藏",lineage:"版本源流",empty:"影印与文本"},chapterUnit:"章",chapterCount:"{n} {unit}",sourceBy:"据{src}",readFrom:"从{ch}读起",firstChapter:"第一章",enterReader:"进入阅读页",externalText:"站外文本",groupCount:"{n} 组",placeCount:"{n} 处",lineageMeta:"据版本传承著录",lineageView:"源流视图",viewCards:"卡片",viewGraph:"关系图",totalOf:"全 {n} {unit}",emptyText:"尚未著录该版本的影印、文本与收藏信息。",editionCount:"{n} 种版本",siblings:"同作品版本",byEra:"按年代",kindCount:"{n} 种",viewAllInWork:"在作品页看全部 {n} 种 →",volumeRange:"第 {range} {unit}",volumeCount:"{n} {unit}",confidence:{certain:"确证",consensus:"通说",probable:"可能",disputed:"有争议"},confidenceNote:"({c})",lineage:{ancestor:"祖本",reconstructed:"拟构祖本",thisEdition:"本版",derivatives:"翻刻 · 衍生",appendix:"附记"}}),bp=at({fact:{written:"成書",measure:"卷帙",loss:"存佚",earliest:"最早存世",emendation:"考證",alias:"又名",attached:"附載",appendix:"附錄"},inferredFromEdition:"據版本題名推斷",loading:"載入中",emendationCount:"{n} 條",stat:{editions:"版本",hasImage:"有影印",catalogs:"家著錄"},classifiedBy:"據《{source}》",sec:{versions:"版本",catalogs:"著錄",collected:"收入叢編",related:"相關書目",resources:"在線資源"},versionsTotal:"共 {n} 種",versionsWithImage:"{n} 種有影印",versionsCurrent:"當前 {n} 種",scanOnly:"只看有影印",sortByYear:"按年代排列",sortByCatalog:"按著錄順序",col:{edition:"版本",era:"年代",holder:"館藏",image:"影印"},noVersionsFiltered:"當前篩選下沒有版本",noVersions:"暫無版本著錄",moreUnit:"種版本",inferredEraNote:"部分年代據版本題名推斷,非著錄原文",empty:"尚未著錄該作品的版本與書目收錄。",relatedCount:"{n} 部",hasImage:"有影印",catalog:{meta:"歷代書目 {n} 家",tablist:"著錄書目",titleOnly:"僅著錄書名,無提要。",prev:"上一家:{name}",next:"下一家:{name}"}},{fact:{written:"成书",measure:"卷帙",loss:"存佚",earliest:"最早存世",emendation:"考证",alias:"又名",attached:"附载",appendix:"附录"},inferredFromEdition:"据版本题名推断",loading:"载入中",emendationCount:"{n} 条",stat:{editions:"版本",hasImage:"有影印",catalogs:"家著录"},classifiedBy:"据《{source}》",sec:{versions:"版本",catalogs:"著录",collected:"收入丛编",related:"相关书目",resources:"在线资源"},versionsTotal:"共 {n} 种",versionsWithImage:"{n} 种有影印",versionsCurrent:"当前 {n} 种",scanOnly:"只看有影印",sortByYear:"按年代排列",sortByCatalog:"按著录顺序",col:{edition:"版本",era:"年代",holder:"馆藏",image:"影印"},noVersionsFiltered:"当前筛选下没有版本",noVersions:"暂无版本著录",moreUnit:"种版本",inferredEraNote:"部分年代据版本题名推断,非著录原文",empty:"尚未著录该作品的版本与书目收录。",relatedCount:"{n} 部",hasImage:"有影印",catalog:{meta:"历代书目 {n} 家",tablist:"著录书目",titleOnly:"仅著录书名,无提要。",prev:"上一家:{name}",next:"下一家:{name}"}}),yp=at({kind:"叢編",workCollection:"作品集",stat:{titles:"子目"},fact:{publication:"刊印",expected:"應收",measure:"卷帙"},member:{Book:"所收版本",Work:"所收作品",other:"成員"},memberNote:"子目與其各版本合計",nZhong:"{n} 種",nHan:"{n} 函",dist:{head:"全帙冊次分佈",segTitle:"{section} 第 {from}–{to} 冊",only:"只看{section}",unclassified:"未分類",hint:"點色段篩選部類"},sec:{titles:"子目",resources:"影印與文本"},totalVolumes:"全帙 {n} {unit}",currentN:"當前 {n} {unit}",loadAllTitle:"將載入全部 {n} {unit}",grouping:"正在按部類分組…",groupBySection:"按部類分組",find:"在本叢編中檢索",col:{volumes:"冊次",title:"書名",versions:"版本"},volumeRange:"第 {range} {unit}",resourcesCount:"{n} 處",text:"文本",empty:"尚未著錄該叢編的子目。",parent:"上級叢編"},{kind:"丛编",workCollection:"作品集",stat:{titles:"子目"},fact:{publication:"刊印",expected:"应收",measure:"卷帙"},member:{Book:"所收版本",Work:"所收作品",other:"成员"},memberNote:"子目与其各版本合计",nZhong:"{n} 种",nHan:"{n} 函",dist:{head:"全帙册次分布",segTitle:"{section} 第 {from}–{to} 册",only:"只看{section}",unclassified:"未分类",hint:"点色段筛选部类"},sec:{titles:"子目",resources:"影印与文本"},totalVolumes:"全帙 {n} {unit}",currentN:"当前 {n} {unit}",loadAllTitle:"将载入全部 {n} {unit}",grouping:"正在按部类分组…",groupBySection:"按部类分组",find:"在本丛编中检索",col:{volumes:"册次",title:"书名",versions:"版本"},volumeRange:"第 {range} {unit}",resourcesCount:"{n} 处",text:"文本",empty:"尚未著录该丛编的子目。",parent:"上级丛编"}),jp=at({subtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群體"},bce:"前{n}",floruit:"活躍於 {from}—{to}",zi:"字{name}",hao:"號{name}",nativePlace:"{place}人",lifeAria:"{birth}—{death},一生 {years} 年",lifeYears:"一生 {years} 年",fact:{works:"著作"},nZhong:"{n} 種",moreNames:"更多別名({n})",dist:"著作分佈",autoMatch:"自動匹配",sec:{featured:"著作舉要",allWorks:"全部著作",works:"著作",external:"站外資料"},featuredSub:"存世版本最多的三部",versionsUnit:"種版本",hasImage:"有影印",empty:"尚未著錄該人物的關聯作品。",total:"共 {n} 種",current:"當前 {n} 種",sortByVersions:"按版本數排列",sortByCatalog:"按著錄順序",col:{work:"作品",section:"部類",role:"職任",versions:"存世版本",image:"影印"},notRecorded:"未著錄",emptyRole:"該職任下的著作尚未著錄。",moreUnit:"種著作",cbdbAuto:"CBDB 為自動匹配,未經人工核對"},{subtype:{people:"人物",place:"地名",dynasty:"朝代",anonymous:"佚名",collective:"群体"},bce:"前{n}",floruit:"活跃于 {from}—{to}",zi:"字{name}",hao:"号{name}",nativePlace:"{place}人",lifeAria:"{birth}—{death},一生 {years} 年",lifeYears:"一生 {years} 年",fact:{works:"著作"},nZhong:"{n} 种",moreNames:"更多别名({n})",dist:"著作分布",autoMatch:"自动匹配",sec:{featured:"著作举要",allWorks:"全部著作",works:"著作",external:"站外资料"},featuredSub:"存世版本最多的三部",versionsUnit:"种版本",hasImage:"有影印",empty:"尚未著录该人物的关联作品。",total:"共 {n} 种",current:"当前 {n} 种",sortByVersions:"按版本数排列",sortByCatalog:"按著录顺序",col:{work:"作品",section:"部类",role:"职任",versions:"存世版本",image:"影印"},notRecorded:"未著录",emptyRole:"该职任下的著作尚未著录。",moreUnit:"种著作",cbdbAuto:"CBDB 为自动匹配,未经人工核对"}),vp=at({imagesLoading:"加載書影…",noImages:"暫無書影",noImagesHint:"這一卷還沒有配上影像;接入後在此與正文逐頁對看",imageAlt:"書影 第 {label} 頁",prevImage:"上一頁書影",nextImage:"下一頁書影",back:"閱讀",backAria:"返回{label}首頁",skipToText:"跳到正文",settings:"閱讀設置",version:"版本",versionShort:"版本▾",unitJuan:"卷",pagerGroup:"翻{unit}",prevUnit:"上一{unit}",nextUnit:"下一{unit}",prevUnitTitle:"上一{unit}:{label}",nextUnitTitle:"下一{unit}:{label}",firstUnit:"已是第一{unit}",lastUnit:"已是最後一{unit}",toc:"目錄",images:"書影",fontSmaller:"縮小字號",fontLarger:"放大字號",paragraphTitle:"條目分行 ↔ 自然段",paragraph:"自然段",workLinks:"標出作品鏈接",properNameTitle:"書名加波浪線",properName:"專名線",vertical:"豎排",closeToc:"收起目錄",sourceLabel:"出處",licenseOf:"授權 {license}",revisedAt:"最近校訂 {date}",reportError:"報告錯字",pagerNav:"翻卷",rail:"本卷",bottomBar:"閱讀工具",tocShort:"卷目",fontSize:"字號",close:"關閉",loading:"加載中…",noText:"暫無文本",tocFailed:"無法加載目錄",tocLoading:"加載目錄…",viewEntry:"查看條目",defaultRole:"撰",tocCaption:"目錄 · {n} {unit}",searchChapters:"搜索全部章節",searchChaptersPlaceholder:"搜索全部章節…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"來源",upstream:"上游",chapterFailed:"無法加載章節內容",references:"參考文獻"},{imagesLoading:"加载书影…",noImages:"暂无书影",noImagesHint:"这一卷还没有配上影像;接入后在此与正文逐页对看",imageAlt:"书影 第 {label} 页",prevImage:"上一页书影",nextImage:"下一页书影",back:"阅读",backAria:"返回{label}首页",skipToText:"跳到正文",settings:"阅读设置",version:"版本",versionShort:"版本▾",unitJuan:"卷",pagerGroup:"翻{unit}",prevUnit:"上一{unit}",nextUnit:"下一{unit}",prevUnitTitle:"上一{unit}:{label}",nextUnitTitle:"下一{unit}:{label}",firstUnit:"已是第一{unit}",lastUnit:"已是最后一{unit}",toc:"目录",images:"书影",fontSmaller:"缩小字号",fontLarger:"放大字号",paragraphTitle:"条目分行 ↔ 自然段",paragraph:"自然段",workLinks:"标出作品链接",properNameTitle:"书名加波浪线",properName:"专名线",vertical:"竖排",closeToc:"收起目录",sourceLabel:"出处",licenseOf:"授权 {license}",revisedAt:"最近校订 {date}",reportError:"报告错字",pagerNav:"翻卷",rail:"本卷",bottomBar:"阅读工具",tocShort:"卷目",fontSize:"字号",close:"关闭",loading:"加载中…",noText:"暂无文本",tocFailed:"无法加载目录",tocLoading:"加载目录…",viewEntry:"查看条目",defaultRole:"撰",tocCaption:"目录 · {n} {unit}",searchChapters:"搜索全部章节",searchChaptersPlaceholder:"搜索全部章节…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"来源",upstream:"上游",chapterFailed:"无法加载章节内容",references:"参考文献"}),kp=at({nJuan:"{n}卷",viewWork:"查看作品",viewWorkOf:"查看作品:{title}",workArrow:"作品 →",arrowWork:"→作品",nWorks:"{n}部作品",unlinked:"未關聯",summary:"提要",comment:"按語",additionalComment:"附按",noMatch:"無匹配結果",sectionType:{类:"類",书:"書",序:"序",结语:"結語",注释:"註釋",考证:"考證",诗:"詩"},countTiao:"{n} 條",countTiaoOf:"{m} / {n} 條",countPoems:"{n} 首",countPoemsOf:"{m} / {n} 首",countBooks:"{n} 部書",countBooksOf:"{m} / {n} 部書",kaozhenTarget:"考證對象 {target}",baseText:"底本 {note}",textQuality:"文本質量",qualityLabel:{published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},qualityCriteria:{published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},originalSource:"原文來源",viewsGroup:"看法",viewText:"正文",viewEntries:"條目",rowHeadNo:"序",rowHeadTitle:"書名",rowHeadWork:"作品",railCap:"本卷",railUnitPoems:"首",railUnitBooks:"部書",linkedN:"已關聯 {n}",linkedOf:"已關聯 {n} / {total}",railEntriesNav:"本卷條目"},{nJuan:"{n}卷",viewWork:"查看作品",viewWorkOf:"查看作品:{title}",workArrow:"作品 →",arrowWork:"→作品",nWorks:"{n}部作品",unlinked:"未关联",summary:"提要",comment:"按语",additionalComment:"附按",noMatch:"无匹配结果",sectionType:{类:"类",书:"书",序:"序",结语:"结语",注释:"注释",考证:"考证",诗:"诗"},countTiao:"{n} 条",countTiaoOf:"{m} / {n} 条",countPoems:"{n} 首",countPoemsOf:"{m} / {n} 首",countBooks:"{n} 部书",countBooksOf:"{m} / {n} 部书",kaozhenTarget:"考证对象 {target}",baseText:"底本 {note}",textQuality:"文本质量",qualityLabel:{published:"出版",fine:"精校",rough:"粗校",ocr:"机器识别"},qualityCriteria:{published:"达到出版、学术研究标准,错误率在万分之一以内",fine:"通读无障碍,错误率在百分之一以内",rough:"保证文意基本正确,错误率在百分之三以内",ocr:"保持大意和结构,错误率在百分之十以内"},originalSource:"原文来源",viewsGroup:"看法",viewText:"正文",viewEntries:"条目",rowHeadNo:"序",rowHeadTitle:"书名",rowHeadWork:"作品",railCap:"本卷",railUnitPoems:"首",railUnitBooks:"部书",linkedN:"已关联 {n}",linkedOf:"已关联 {n} / {total}",railEntriesNav:"本卷条目"}),wp=at({typeShort:{work:"作",book:"版",collection:"叢",entity:"人"},typeLabel:{work:"作品",book:"版本",collection:"叢編",entity:"人物"},typeAll:"全部",typeChipsLabel:"按類型檢索",recentTitle:"最近瀏覽",recentClear:"清除",recentItemLabel:"{type} {title}",recentEmpty:"還沒有瀏覽記錄。打開任一條目後會出現在這裏。",status:{done:"已完成",in_progress:"進行中",todo:"計劃中"},siteStatus:{done:"已對接",in_progress:"進行中"},catalogTitle:"書目著錄進度",catalogNote:"每條著錄對到作品條目",colCatalog:"書目",colRecords:"著錄條目",colMatched:"已對上作品",colProgress:"進度",colStatus:"狀態",relatedTitle:"同類書目與考證",relatedNote:"不在書架上的",allNWorks:"全部 {n} 部",nKinds:"{n} 種",allNKinds:"全部 {n} 種",pavilion:"閣",yearBC:"前{n}",missingLife:"生卒年未錄、未上軸:{names}",viewLineage:"看版本譜系 →",plannedSites:"計劃接入:{names}",loss:{extant:"存",partially_extant:"殘",lost:"佚",unknown:"未詳"},lossNote:{extant:"今有傳本",partially_extant:"部分存世",lost:"僅見著錄",unknown:"尚未判定"},lossCount:"{n} 部 · {note}",stat:{works:"作品",books:"版本",collections:"叢編",entities:"人物",has_image:"有影印",has_text:"有文本",article:"單篇文",poem:"單篇詩"},dataScale:"數據規模",byLoss:"按存佚檢索",license:"古籍元數據以 CC0 公有領域發布,可自由複製、改編、再發布。",repo:"數據倉庫:",repoNote:"(GitHub,CC0)",version:"當前數據版本:",download:"引用方式與數據下載 →",navLabel:"元數據首頁分區",nav:{zhi:"歷代史志",sibu:"四部",cong:"叢編",people:"人物",lineage:"版本譜系",sites:"在線資源",data:"數據與授權"},zhiSub:"正史藝文志、經籍志與後人補志,按所志朝代排列;每部志的著錄逐條對到作品",shelfLegendCount:"脊下數字=著錄條目",shelfLegendClick:"點書脊進作品頁",sibuSub:"全部作品按經史子集分類;與「目錄」頁同一棵分類樹",toCatalog:"進入目錄 →",unclassifiedNote:"多為只見於史志著錄、尚未歸類的書",congSub:"大型叢書、影印彙編、出土文獻與館藏,逐種列到版本",allNKindsMore:"全部 {n} 種 →",peopleSub:"歷代目錄學家,按生卒年排在一條時間軸上",allNPeopleMore:"全部 {n} 人 →",lineageSub:"版本多的作品,看各本的源流與異同",sitesSub:"外部數字圖書館與本站條目的對接",dataSub:"規模、存佚、許可與版本"},{typeShort:{work:"作",book:"版",collection:"丛",entity:"人"},typeLabel:{work:"作品",book:"版本",collection:"丛编",entity:"人物"},typeAll:"全部",typeChipsLabel:"按类型检索",recentTitle:"最近浏览",recentClear:"清除",recentItemLabel:"{type} {title}",recentEmpty:"还没有浏览记录。打开任一条目后会出现在这里。",status:{done:"已完成",in_progress:"进行中",todo:"计划中"},siteStatus:{done:"已对接",in_progress:"进行中"},catalogTitle:"书目著录进度",catalogNote:"每条著录对到作品条目",colCatalog:"书目",colRecords:"著录条目",colMatched:"已对上作品",colProgress:"进度",colStatus:"状态",relatedTitle:"同类书目与考证",relatedNote:"不在书架上的",allNWorks:"全部 {n} 部",nKinds:"{n} 种",allNKinds:"全部 {n} 种",pavilion:"阁",yearBC:"前{n}",missingLife:"生卒年未录、未上轴:{names}",viewLineage:"看版本谱系 →",plannedSites:"计划接入:{names}",loss:{extant:"存",partially_extant:"残",lost:"佚",unknown:"未详"},lossNote:{extant:"今有传本",partially_extant:"部分存世",lost:"仅见著录",unknown:"尚未判定"},lossCount:"{n} 部 · {note}",stat:{works:"作品",books:"版本",collections:"丛编",entities:"人物",has_image:"有影印",has_text:"有文本",article:"单篇文",poem:"单篇诗"},dataScale:"数据规模",byLoss:"按存佚检索",license:"古籍元数据以 CC0 公有领域发布,可自由复制、改编、再发布。",repo:"数据仓库:",repoNote:"(GitHub,CC0)",version:"当前数据版本:",download:"引用方式与数据下载 →",navLabel:"元数据首页分区",nav:{zhi:"历代史志",sibu:"四部",cong:"丛编",people:"人物",lineage:"版本谱系",sites:"在线资源",data:"数据与授权"},zhiSub:"正史艺文志、经籍志与后人补志,按所志朝代排列;每部志的著录逐条对到作品",shelfLegendCount:"脊下数字=著录条目",shelfLegendClick:"点书脊进作品页",sibuSub:"全部作品按经史子集分类;与「目录」页同一棵分类树",toCatalog:"进入目录 →",unclassifiedNote:"多为只见于史志著录、尚未归类的书",congSub:"大型丛书、影印汇编、出土文献与馆藏,逐种列到版本",allNKindsMore:"全部 {n} 种 →",peopleSub:"历代目录学家,按生卒年排在一条时间轴上",allNPeopleMore:"全部 {n} 人 →",lineageSub:"版本多的作品,看各本的源流与异同",sitesSub:"外部数字图书馆与本站条目的对接",dataSub:"规模、存佚、许可与版本"}),Ao=at({readable:"部可讀",pieces:"篇單篇詩文",startReading:"開始閱讀 →",nCopies:"{n}本",shelfHint:"按所志朝代排列,一脊一部",shelfLegendCount:"脊下「2本」=站內有幾個本子",shelfOther:"其他",shelfRegion:"{label}書架,可橫向滾動",origZhi:"正史原志",laterZhi:"後人補撰、續補",spineBy:"{name} 撰",spineRecords:"著錄 {n} 條",spineOnSite:"站內 {n}",nWorks:"{n} 部",allNWorks:"全部 {n} 部",nCopiesCard:"{n} 個本子",workPageLink:"作品頁:{title}的源流與全部版本 →",sibuUnclassifiedNote:"書目分類還沒補齊,其中多數是單篇詩文,已單列在下方。",subClasses:"{label}子類",allNClasses:"{label}全部 {n} 類 →",unclassified:"未分類",viewUnclassified:"查看未分類 →",periodItem:"{label},{n} 部",periodUnknown:"另有 {n} 部作者無朝代,在「四部」和搜索裏能找到",hoverHint:"窄段懸停看全名",nPieces:"{n} 篇",authorAll:"{name}全部 {n} 篇 →",period:{xianqin:"先秦",qinhan:"秦漢",weijin:"魏晉南北朝",suitang:"隋唐五代",song:"宋",liaojinyuan:"遼金元",ming:"明",qing:"清",modern:"近現代"},navLabel:"閱讀首頁分區",nav:{picks:"推薦閱讀",topics:"專題",famous:"名著與版本",sibu:"四部",period:"按年代",pieces:"單篇詩文"},picksSub:"編輯挑選,定期輪換",topicsSub:"按作品類型歸組;小說見下方「名著與版本」",famousSub:"一部作品一張卡,卡上列出站內能讀的各個本子",sibuSub:"按古籍總目的分類樹,只計站內可讀的作品",periodSub:"按作者朝代歸段,寬度與部數成比例",piecesSub:"單篇的詩、文、賦、表,按作者歸組",piecesMore:"按作者瀏覽全部 →"},{readable:"部可读",pieces:"篇单篇诗文",startReading:"开始阅读 →",nCopies:"{n}本",shelfHint:"按所志朝代排列,一脊一部",shelfLegendCount:"脊下「2本」=站内有几个本子",shelfOther:"其他",shelfRegion:"{label}书架,可横向滚动",origZhi:"正史原志",laterZhi:"后人补撰、续补",spineBy:"{name} 撰",spineRecords:"著录 {n} 条",spineOnSite:"站内 {n}",nWorks:"{n} 部",allNWorks:"全部 {n} 部",nCopiesCard:"{n} 个本子",workPageLink:"作品页:{title}的源流与全部版本 →",sibuUnclassifiedNote:"书目分类还没补齐,其中多数是单篇诗文,已单列在下方。",subClasses:"{label}子类",allNClasses:"{label}全部 {n} 类 →",unclassified:"未分类",viewUnclassified:"查看未分类 →",periodItem:"{label},{n} 部",periodUnknown:"另有 {n} 部作者无朝代,在「四部」和搜索里能找到",hoverHint:"窄段悬停看全名",nPieces:"{n} 篇",authorAll:"{name}全部 {n} 篇 →",period:{xianqin:"先秦",qinhan:"秦汉",weijin:"魏晋南北朝",suitang:"隋唐五代",song:"宋",liaojinyuan:"辽金元",ming:"明",qing:"清",modern:"近现代"},navLabel:"阅读首页分区",nav:{picks:"推荐阅读",topics:"专题",famous:"名著与版本",sibu:"四部",period:"按年代",pieces:"单篇诗文"},picksSub:"编辑挑选,定期轮换",topicsSub:"按作品类型归组;小说见下方「名著与版本」",famousSub:"一部作品一张卡,卡上列出站内能读的各个本子",sibuSub:"按古籍总目的分类树,只计站内可读的作品",periodSub:"按作者朝代归段,宽度与部数成比例",piecesSub:"单篇的诗、文、赋、表,按作者归组",piecesMore:"按作者浏览全部 →"}),Sp=at({sideNav:"分類導航",classification:"分類",drawerLabel:"分類:{path}",all:"全部",allTitle:"全部典籍",stat:"共 {total} 種 · 每頁 {size} 條",statPage:" · 第 {page} / {pages} 頁",viewLabel:"呈現方式",viewCard:"卡片",viewList:"列表",juanN:"{n}卷",pagerLabel:"分頁",prevPage:"上一頁",nextPage:"下一頁",pageN:"第 {n} 頁",emptyWorks:"此類暫無作品",zhulu:"著錄",cunmu:"存目",categoriesN:"{n} 類",divisionStat:"{cats} 類 · {books} 部",categoryJuan:"卷{n}",booksN:"{n} 部",expandAllN:"展開全部 {n} 條"},{sideNav:"分类导航",classification:"分类",drawerLabel:"分类:{path}",all:"全部",allTitle:"全部典籍",stat:"共 {total} 种 · 每页 {size} 条",statPage:" · 第 {page} / {pages} 页",viewLabel:"呈现方式",viewCard:"卡片",viewList:"列表",juanN:"{n}卷",pagerLabel:"分页",prevPage:"上一页",nextPage:"下一页",pageN:"第 {n} 页",emptyWorks:"此类暂无作品",zhulu:"著录",cunmu:"存目",categoriesN:"{n} 类",divisionStat:"{cats} 类 · {books} 部",categoryJuan:"卷{n}",booksN:"{n} 部",expandAllN:"展开全部 {n} 条"}),_p=at({loss:{all:"全部",extant:"存",partially_extant:"殘",lost:"佚"},unclassified:"未分類",statBook:"書",statComma:",",statBookCopies:"本",statArticle:"文章",statArticleUnit:"篇",statPoem:"詩詞",statPoemUnit:"首",statCollection:"叢編",submit:"搜索"},{loss:{all:"全部",extant:"存",partially_extant:"残",lost:"佚"},unclassified:"未分类",statBook:"书",statComma:",",statBookCopies:"本",statArticle:"文章",statArticleUnit:"篇",statPoem:"诗词",statPoemUnit:"首",statCollection:"丛编",submit:"搜索"}),$p=at({title:"反饋",close:"關閉",submitType:{bug:"反饋錯誤",resource:"添加資源",suggestion:"功能建議",contact:"想參與"},placeholder:{bug:"請描述您發現的錯誤,包括頁面位置和具體內容",resource:"請提供完整資源鏈接和簡要版本說明",suggestion:"您希望網站增加或改進什麼?",contact:"想參與整理、校對或合作?簡單介紹一下您自己,並留下聯繫方式(此類留言不公開)"},chooseTypeFirst:"請先選擇反饋類型",contactPlaceholder:"郵箱(選填,僅站方可見,方便我們回覆您)",contactLabel:"聯繫方式(選填)",submitFailedRetry:"提交失敗,請稍後重試",submitFailed:"提交失敗",thanks:"感謝您的反饋!",viewList:"查看反饋列表 →",continueSubmit:"繼續提交",submitting:"提交中...",submit:"提交",submitFeedback:"提交反饋",listType:{bug:"錯誤反饋",resource:"資源建議",suggestion:"功能建議",other:"其他"},status:{pending:"待處理",in_progress:"處理中",resolved:"已處理",wontfix:"不採納",duplicate:"重複"},empty:"暫無反饋",reply:"回覆"},{title:"反馈",close:"关闭",submitType:{bug:"反馈错误",resource:"添加资源",suggestion:"功能建议",contact:"想参与"},placeholder:{bug:"请描述您发现的错误,包括页面位置和具体内容",resource:"请提供完整资源链接和简要版本说明",suggestion:"您希望网站增加或改进什么?",contact:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"},chooseTypeFirst:"请先选择反馈类型",contactPlaceholder:"邮箱(选填,仅站方可见,方便我们回复您)",contactLabel:"联系方式(选填)",submitFailedRetry:"提交失败,请稍后重试",submitFailed:"提交失败",thanks:"感谢您的反馈!",viewList:"查看反馈列表 →",continueSubmit:"继续提交",submitting:"提交中...",submit:"提交",submitFeedback:"提交反馈",listType:{bug:"错误反馈",resource:"资源建议",suggestion:"功能建议",other:"其他"},status:{pending:"待处理",in_progress:"处理中",resolved:"已处理",wontfix:"不采纳",duplicate:"重复"},empty:"暂无反馈",reply:"回复"}),Cp=at({empty:"暫無版本傳承數據",emptyGraph:"暫無版本圖數據",modeList:"列表",modeGraph:"關係圖",collectionLabel:"集合:",collectionAll:"全部",collectionAllDesc:"顯示該作品所有版本(含橋接節點)",graphLoading:"加載圖組件中…",graphMissing:"圖組件未安裝。請安裝 {xyflow} 與 {dagre}。",graphMissingHint:"或使用 {list} 列表視圖。",bridgeTitle:"橋接節點:本身不在核心集,為保持派生鏈完整而顯示",otherGroup:"其他",lost:"已佚",fragment:"殘本",hypothetical:"假想祖本",bridge:"橋接",extant:"現存:{juan}",sources:"來源:",related:"關聯:",confidence:{certain:"確定",consensus:"共識",probable:"推測",disputed:"有爭議"}},{empty:"暂无版本传承数据",emptyGraph:"暂无版本图数据",modeList:"列表",modeGraph:"关系图",collectionLabel:"集合:",collectionAll:"全部",collectionAllDesc:"显示该作品所有版本(含桥接节点)",graphLoading:"加载图组件中…",graphMissing:"图组件未安装。请安装 {xyflow} 与 {dagre}。",graphMissingHint:"或使用 {list} 列表视图。",bridgeTitle:"桥接节点:本身不在核心集,为保持派生链完整而显示",otherGroup:"其他",lost:"已佚",fragment:"残本",hypothetical:"假想祖本",bridge:"桥接",extant:"现存:{juan}",sources:"来源:",related:"关联:",confidence:{certain:"确定",consensus:"共识",probable:"推测",disputed:"有争议"}}),zp={common:fp,detail:gi,bookPage:xp,workPage:bp,collectionPage:yp,entityPage:jp,reader:vp,collated:kp,metaHome:wp,readHome:Ao,catalogPage:Sp,searchPage:_p,feedback:$p,lineage:Cp};function Tp(e){const n={};for(const[o,r]of Object.entries(zp))n[o]=r[e];return n}function mt(e,n){return e.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}const Jr=new Map;function un(e){let n=Jr.get(e);return n||(n={...e==="zh-Hans"?gp:hp,...Tp(e)},Jr.set(e,n)),n}function Qr(e,n){let o=e;for(const r of n.split(".")){if(o==null||typeof o!="object")return;o=o[r]}return typeof o=="string"?o:void 0}function Na(e){return(n,o)=>{const r=Qr(e,n)??Qr(un("zh-Hant"),n)??n;return o?mt(r,o):r}}const es=new Map;function mn(e){let n=es.get(e);return n||(n=Na(un(e)),es.set(e,n)),n}const Ra="bim-locale";function Np(){try{const e=localStorage.getItem(Ra);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Rp(e){try{localStorage.setItem(Ra,e)}catch{}}const Ep="zh-Hans",Ip=({locale:e,onLocaleChange:n,converter:o,children:r})=>{const[s,a]=g.useState(e??Ep),l=e??s;g.useEffect(()=>{if(e)return;const u=Np();u&&u!==s&&a(u)},[]);const d=g.useMemo(()=>l==="zh-Hans"?o??mp():null,[l,o]),c=g.useCallback(u=>{a(u),Rp(u),n==null||n(u)},[n]),p=g.useMemo(()=>({locale:l,setLocale:c,messages:un(l),converter:d}),[l,c,d]);return t.jsx(Xt.Provider,{value:p,children:r})};function Te(){const e=g.useContext(Xt);return(e==null?void 0:e.messages)??un("zh-Hant")}const Lp=2e3;function Ae(){const e=g.useContext(Xt),n=(e==null?void 0:e.locale)??"zh-Hant",o=(e==null?void 0:e.converter)??null,r=g.useRef(new Map),s=g.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const a=g.useCallback(l=>{if(!l)return"";if(!o)return l;const d=r.current.get(l);if(d!==void 0)return d;const c=o(l);if(r.current.size>=Lp){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(l,c),c},[o]);return g.useMemo(()=>({convert:a,locale:n,isSimplified:n==="zh-Hans"}),[a,n])}function J(){const e=g.useContext(Xt),{convert:n,locale:o,isSimplified:r}=Ae(),s=(e==null?void 0:e.messages)??un("zh-Hant"),a=g.useMemo(()=>e?Na(s):mn("zh-Hant"),[e,s]);return g.useMemo(()=>({t:a,convert:n,locale:o,isSimplified:r,messages:s}),[a,n,o,r,s])}const Ea=["錄說語詞議樣書記類傳國經補藝紀編後與間條號為開總種無數據冊頁選時題爲詩萬證學續關東圖資歷來讀館論見鈔別進師輯陳覽寫現應從","點兩華實對員長註結闕殘檢閱當會單換體將裡訂處過區釋術頭錢譯識個電動顯問這認質還幾遺雖須專擇係網運權務變發機請風聲輸軍導產","話們車難報讓業設帶辦紙氣麼際聽親場買賣謝費漢庫遷馬叢孫於張義晉閣維曆欽則夢慶齋録舊內陽樓紅淵歸載稱隱遼計評觀禮龜黃興節併","餘齊韓簡霑並樂諸滸屬組篩紹緒劉蘇誤職夾廣蓋敘斷歐寬駰極參試雜魯沒順線貞該測鮮統戰檔衛辭聯臺贊刪聖貫啟瀏譜薈寶約嘗諜謂舉詳","異賦軾復諒構級審標劃彙吳楊暫轉項寧硯蕭儀禪韻掃閉倉麗禎錯監鞏轍繫説筆竄縣聞諡賈僅擊羅宮訓談誌葉視戶細許祿繪鍵絕欄鑑講誕馮","趙習樹饋確賜裝擬規繼製薦畫鉛獨誠遠龍門覺訣隸軒諭繕塊爭鏡裏豐碼備掛堯錦駕鶴遊傷猶鄒瑩綴揚詔託僞頗竊虛莊歲禍爾辯獲篤窮盡跡","萊終穎訛瑣鐫繡廟幀佈躍雙預連狀態軸複懸遞灣箋頌訪層鏈敗達鈞鳳亂奮豈陰婁騎純優獻靈牆隨摺疊驗徑橫瀾蔣壞鈕盤範圍責減籤適側","榮聶頃縉讎銓廳軌厲鶚駢醫駝黨鐘諫樞滄軻溫贈鐵徵賴蹟潁閒顗歿駁歟勸諷誼湯詐脫羣尋澤擄顏釀謄鴻離騷傑滯憤執廢懼匱歎毀蠶獄寵闇","陸淺貨輕貧俠賤貴煩競樑鳩採綜謬鳴養堅韋顎呂蘭脈峯鵲兒賞籠階緊綱漁荊嬰慍潛營鎔繞陣塚億負卻塵懷閨擋撐縮領滾輪匯撈貼讚創險團","隊準礙強髒藥鮑顧給緯悅帳巖廬貢亞壇惡諱鎮薊驍愛討彌護揮偉輒擾況較響喪鑰藍"].join(""),Ap=new Set([...Ea,...Object.keys(_e.VARIANT_CHARS)]),Ia=[...Ta,"切換為繁體","漢籍リポジトリ"];function Pp(e,n=Ia){let o=e;for(const a of n)a&&(o=o.split(a).join(" "));const r=[],s=Array.from(o);return s.forEach((a,l)=>{Ap.has(a)&&r.push({char:a,context:s.slice(Math.max(0,l-8),l+9).join("")})}),r}function Mp(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 Bp(){return{id:"",name:"",url:"",type:"text",details:""}}const lo=({items:e,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const a=Te(),[l,d]=g.useState(null),c=[{value:"text",label:a.resourceTypeShort.text},{value:"image",label:a.resourceTypeShort.image},{value:"text+image",label:a.resourceTypeShort.textImage},{value:"physical",label:a.resourceTypeShort.physical}],p=[{value:"catalog",label:a.rootType.catalog},{value:"search",label:a.rootType.search}],u=b=>{if(!s)return!0;const j=qt(b);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},m=e.map((b,j)=>({item:b,originalIndex:j})).filter(({item:b})=>u(b)),h=()=>{const b=Bp();s&&(b.type=s),n([...e,b]),d(e.length)},f=b=>{n(e.filter((j,S)=>S!==b)),d(null)},x=(b,j,S)=>{const v=[...e];if(v[b]={...v[b],[j]:S},j==="url"&&!v[b].id){const $=Mp(S);$&&(v[b].id=$)}n(v)},k=(b,j,S)=>{const $={...e[b].metadata||{}};S?$[j]=S:delete $[j],x(b,"metadata",Object.keys($).length>0?$:void 0)},y=(b,j)=>{const S=j.trim()?j.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;x(b,"structure",S)},w=(b,j,S)=>{const $=e[b].coverage||{level:1,ranges:""};j==="level"?$.level=parseInt(S)||1:$.ranges=S,x(b,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.map(({item:b,originalIndex:j})=>{var S,v,$;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>d(l===j?null:j),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===j?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Wp(b.type??"text"),color:i("on-color-fg")},children:(()=>{var C,M;const _=qt(b);return _.length===0?b.type??"text":_.length===1?((C=c.find(N=>N.value===_[0]))==null?void 0:C.label)??_[0]:_.includes("text")&&_.includes("image")?((M=c.find(N=>N.value==="text+image"))==null?void 0:M.label)??"text+image":_.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${a.editor.resourcePlaceholder} ${j+1}`}),b.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&t.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:_=>_.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&b.url&&Op(j,r==null?void 0:r[j],o,a),t.jsx("button",{onClick:_=>{_.stopPropagation(),f(j)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:a.editor.deleteThisResource,children:"✕"})]}),l===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:[cp(b,"image")&&b.url&&Hp(b,a),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:kn,children:[t.jsx("span",{style:wn,children:a.label.type}),t.jsx("select",{value:b.type,onChange:_=>x(j,"type",_.target.value),style:{...jt,flex:1},children:c.map(_=>t.jsx("option",{value:_.value,children:_.label},_.value))})]}),t.jsxs("label",{style:kn,children:[t.jsx("span",{style:wn,children:a.label.rootType}),t.jsx("select",{value:b.root_type||"catalog",onChange:_=>x(j,"root_type",_.target.value),style:{...jt,flex:1},children:p.map(_=>t.jsx("option",{value:_.value,children:_.label},_.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:b.id,onChange:_=>x(j,"id",_.target.value),placeholder:a.editor.idAutoExtract,style:{...jt,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:b.name,onChange:_=>x(j,"name",_.target.value),placeholder:a.editor.resourceName,style:{...jt,flex:1}})]}),t.jsx("input",{type:"text",value:b.url,onChange:_=>x(j,"url",_.target.value),placeholder:a.editor.resourceUrl,style:jt}),t.jsx("input",{type:"text",value:((S=b.structure)==null?void 0:S.join("、"))||"",onChange:_=>y(j,_.target.value),placeholder:a.editor.structurePlaceholder,style:jt}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:kn,children:[t.jsx("span",{style:wn,children:a.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((v=b.coverage)==null?void 0:v.level)??"",onChange:_=>w(j,"level",_.target.value),placeholder:"1",style:{...jt,width:"60px"}})]}),t.jsxs("label",{style:{...kn,flex:1},children:[t.jsx("span",{style:wn,children:a.label.coverageRange}),t.jsx("input",{type:"text",value:(($=b.coverage)==null?void 0:$.ranges)||"",onChange:_=>w(j,"ranges",_.target.value),placeholder:a.editor.coverageRangePlaceholder,style:{...jt,flex:1}})]})]}),t.jsx("textarea",{value:b.details||"",onChange:_=>x(j,"details",_.target.value),placeholder:a.editor.detailsPlaceholder,style:{...jt,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:a.label.metadata}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(a.metadata).map(([_,C])=>{var M;return t.jsxs("label",{style:{...kn,gap:"4px"},children:[t.jsx("span",{style:{...wn,minWidth:"56px"},children:C}),t.jsx("input",{type:"text",value:((M=b.metadata)==null?void 0:M[_])||"",onChange:N=>k(j,_,N.target.value),placeholder:C,style:{...jt,flex:1}})]},_)})})]})]})]})]},j)}),t.jsxs("button",{onClick:h,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:a.action.addResource})]})]})};function Wp(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 Op(e,n,o,r){const s=(n==null?void 0:n.status)==="downloading",a=(n==null?void 0:n.status)==="completed";return t.jsx("button",{onClick:l=>{l.stopPropagation(),s||o(e,"")},disabled:s,style:{background:"transparent",border:"none",color:i(a?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:a?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:a?"✓":s?"⏳":"⬇"})}function Hp(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 jt={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"},kn={display:"flex",alignItems:"center",gap:"6px"},wn={fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap"},Fp={"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 hn(e){try{return Fp[new URL(e).hostname]}catch{return}}const ts={text:0,image:1,physical:2};function Po(e){return e.length===0?"physical":[...e].sort((n,o)=>(ts[n]??99)-(ts[o]??99)).join("+")}function Mo(e){var l;const n=d=>{const c=d.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const p=d.match(/^(.+?)[·(](\d+)[)]?$/);return p?[p[1],parseInt(p[2])]:null},o=new Map;for(let d=0;d<e.length;d++){const c=e[d];if(c.volumes&&c.volumes.length>0)continue;const p=n(c.name);if(!p)continue;const[u,m]=p,h=`${u}|${Po(qt(c))}`;o.has(h)||o.set(h,{base:{...c,name:u,url:"",volumes:[]},volumes:[],indices:[]});const f=o.get(h);f.volumes.push({volume:m,url:c.url||void 0,status:"found"}),f.indices.push(d)}const r=[],s=new Set;for(const d of o.values())if(!(d.volumes.length<2)){d.volumes.sort((c,p)=>c.volume-p.volume),d.base.volumes=d.volumes,d.base.expected_volumes=d.volumes.length,d.base.url||(d.base.url=((l=d.volumes.find(c=>c.url))==null?void 0:l.url)??""),r.push(d.base);for(const c of d.indices)s.add(c)}const a=[...r];for(let d=0;d<e.length;d++)s.has(d)||a.push(e[d]);return a}function La(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 Aa(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||La(n)}))}function fi(e){const n=Aa(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 Bo(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 Wo(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 gn(e){if(!e.url)return;const n=Bo(e.metadata);return n?Wo(e.url,n):e.url}const ns={text:i("restype-text"),image:i("restype-image"),"text+image":i("restype-text-image"),physical:i("restype-physical")};function Dp(e){return e.includes("text")&&e.includes("image")?ns["text+image"]:ns[e[0]||"physical"]}const Oo=({items:e,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const a=Te(),{convert:l}=Ae(),d=g.useMemo(()=>Mo(e||[]),[e]),{mirrorGroups:c,ungroupedItems:p}=g.useMemo(()=>{const y=new Map,w=[];for(const b of d){const j=b.group;j?(y.has(j)||y.set(j,[]),y.get(j).push(b)):w.push(b)}for(const b of y.values())b.sort((j,S)=>{const v=$=>$.group_role==="origin"?0:$.group_role==="mirror"?1:2;return v(j)-v(S)});return{mirrorGroups:y,ungroupedItems:w}},[d]),u={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},m=y=>u[y]?u[y]:y.split("+").map(w=>u[w]||w).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:i("desc-fg"),fontSize:"13px",textAlign:"center"},children:a.misc.noResources});if(!n)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:d.map((y,w)=>t.jsx(Ui,{item:y},y.id||w))});const h=(y,w)=>{const b=o==null?void 0:o[y],j=(b==null?void 0:b.label)||y,S=b==null?void 0:b.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:i("fg")},children:l(j)}),S&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.5},children:l(S)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.map((v,$)=>t.jsx(Ui,{item:v,onNavigate:r,renderLink:s},v.id||$))})]},`group-${y}`)},f=new Map;for(const y of p){const w=Po(qt(y));f.has(w)||f.set(w,[]),f.get(w).push(y)}const x=["text","image","text+image","physical"],k=[...x.filter(y=>f.has(y)),...[...f.keys()].filter(y=>!x.includes(y)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([y,w])=>h(y,w)),k.map(y=>{const w=f.get(y),b=Dp(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:b,whiteSpace:"nowrap",flexShrink:0},children:m(y)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:w.map((j,S)=>t.jsx(Ui,{item:j,onNavigate:r,renderLink:s},j.id||S))})]},y)})]})},Up={bw:{label:"",bg:i("colormode-bw-bg"),fg:i("colormode-bw-fg")},color:{label:"",bg:i("colormode-color-bg"),fg:i("colormode-color-fg")}},Ui=({item:e})=>{const n=Te(),{convert:o}=Ae(),[r,s]=g.useState(!1),a=g.useMemo(()=>(e.url?hn(e.url):void 0)||o(e.name),[e.url,e.name,o]),l=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(x=>({...x,url:x.url||La(x)})),[e.volumes]),d=l&&l.length>0,c=d?new Set(l.filter(x=>x.status!=="missing").map(x=>x.volume)).size:0,p=d?new Set(l.filter(x=>x.status==="missing").map(x=>x.volume)).size:0,u=e.expected_volumes??(d?c+p:0),m=e.color_mode?{...Up[e.color_mode],label:n.colorMode[e.color_mode]}:null,h=e.details&&!d?o(e.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 t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:f,children:[t.jsx("span",{style:{fontWeight:500},children:a}),m&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:m.bg,color:m.fg},children:m.label}),h&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:h}),d&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[c,"/",u,n.unit.volume,p>0&&t.jsx("span",{style:{color:i("missing-fg"),marginLeft:"3px"},children:mt(n.common.volumesMissing,{n:p})})]}),e.url&&t.jsx("a",{href:(()=>{const x=Bo(e.metadata);return x?Wo(e.url,x):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:i("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),d&&t.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),d&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${i("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(x=>{const k=x.status==="missing";return x.url&&!k?t.jsx("a",{href:x.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:x.volume},x.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:i(k?"missing-fg":"desc-fg"),textDecoration:k?"line-through":"none",opacity:k?.6:1},children:x.volume},x.volume)})})]})},Pa=({indexSource:e,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:a,onSelectFolder:l})=>{const d=Te(),c=e==="local",p=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",m=u?u.split(/[/\\]/).pop()||u:"",h={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:k=>k.currentTarget.style.opacity="0.8",onMouseOut:k=>k.currentTarget.style.opacity="1"},x=t.jsxs("div",{onClick:s,title:p?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...h,background:i(p?"warning":"success"),color:i("on-color-fg")},...f,children:[t.jsx("span",{children:p?"📝":"📚"}),t.jsx("span",{children:p?"draft":"official"})]});return o==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[x,t.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:h,...f,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:l,title:u||d.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...f,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:[x,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:d.mode.switchToLocal,style:h,...f,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:a,title:m||d.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...f,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:h,...f,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:l,title:u||d.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...f,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]}),!c&&m&&t.jsxs("div",{style:{...h,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})]})]})},xi="bim-search-history",is=10,os=8;function Rn(){try{const e=localStorage.getItem(xi);return e?JSON.parse(e):[]}catch{return[]}}function Ma(e){try{const n=Rn().filter(o=>o!==e);n.unshift(e),n.length>is&&(n.length=is),localStorage.setItem(xi,JSON.stringify(n))}catch{}}function Vp(e){try{const n=Rn().filter(o=>o!==e);localStorage.setItem(xi,JSON.stringify(n))}catch{}}function Gp(){try{localStorage.removeItem(xi)}catch{}}const Ba=({transport:e,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:a})=>{const l=Te(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,u]=g.useState(!1),[m,h]=g.useState([]),[f,x]=g.useState(-1),[k,y]=g.useState(Rn),w=g.useRef(null),b=g.useRef(null),j=g.useRef(null),S=g.useRef(!1);g.useEffect(()=>{x(-1);const T=n.trim();if(!T){h(k.map(E=>({type:"history",text:E})));return}if(!e.searchAll){h([]);return}let F=!1;const R=setTimeout(()=>{e.searchAll(T,os).then(E=>{if(F)return;const L=[...E.works,...E.books,...E.collections,...E.entities??[]];h(L.slice(0,os).map(I=>({type:"entry",text:I.title||I.id,entry:I})))}).catch(()=>{F||h([])})},80);return()=>{F=!0,clearTimeout(R)}},[n,k,e]),g.useEffect(()=>{const T=F=>{j.current&&!j.current.contains(F.target)&&u(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),g.useEffect(()=>{const T=F=>{var R,E;if(F.key==="/"&&document.activeElement!==w.current){const L=(R=document.activeElement)==null?void 0:R.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;F.preventDefault(),(E=w.current)==null||E.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const v=g.useCallback(T=>{T.trim()&&(Ma(T.trim()),y(Rn())),r(T),u(!1)},[r]),$=g.useCallback(T=>{T.type==="history"?(o(T.text),v(T.text)):T.entry&&(s?(s(T.entry),u(!1)):(o(T.text),v(T.text)))},[o,v,s]),_=g.useCallback(T=>{if(!p||m.length===0){T.key==="Enter"&&v(n);return}switch(T.key){case"ArrowDown":T.preventDefault(),x(F=>(F+1)%m.length);break;case"ArrowUp":T.preventDefault(),x(F=>(F-1+m.length)%m.length);break;case"Enter":T.preventDefault(),f>=0&&f<m.length?$(m[f]):v(n);break;case"Escape":T.preventDefault(),u(!1);break}},[p,m,f,n,v,$]),C=g.useCallback((T,F)=>{F.stopPropagation(),Vp(T),y(Rn()),h(R=>R.filter(E=>!(E.type==="history"&&E.text===T)))},[]),M=g.useCallback(T=>{T.stopPropagation(),Gp(),y([]),h([])},[]);g.useEffect(()=>{if(f>=0&&b.current){const T=b.current.children;T[f]&&T[f].scrollIntoView({block:"nearest"})}},[f]);const N=!n.trim()&&k.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:w,type:"text",placeholder:d,value:n,onChange:T=>{o(T.target.value),u(!0)},onCompositionStart:()=>{S.current=!0},onCompositionEnd:()=>{S.current=!1},onFocus:()=>{u(!0)},onKeyDown:_,style:{width:"100%",padding:"8px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),p&&m.length>0&&t.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:i("input-bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"6px",boxShadow:i("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[N&&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:l.search.history}),t.jsx("button",{onClick:M,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),m.map((T,F)=>t.jsxs("div",{onClick:()=>$(T),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:i("fg"),background:F===f?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:[c[T.entry.type],T.entry.edition&&` · ${T.entry.edition}`,T.entry.author&&` · ${T.entry.author}`]}),T.type==="history"&&t.jsx("button",{onClick:R=>C(T.text,R),style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${T.type}-${T.text}-${F}`))]})]})},fn=({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"}}),bi={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Wa=new Set(["work","book","entity"]);function Yp(e){return Fa(e)||!!e.sort}function Kp(e,n){return n.sort&&Wa.has(e)?n.sort:void 0}const yi=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],ji=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Oa=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Ha={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function vi(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 Fa(e){return vi(e)>0}function qp(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 Da(e,n){const o=Ha[e];return qp(n).every(r=>o.has(r))}const Sn=e=>JSON.stringify(e);function Xp(e,n){if(!Da(n,e))return null;const o=[];if(e.dynasty.length){const r=Array.from(new Set(e.dynasty.flatMap(s=>{var a;return((a=yi.find(l=>l.key===s))==null?void 0:a.values)??[]})));r.length===1?o.push(`dynasty = ${Sn(r[0])}`):r.length>1&&o.push(`dynasty IN [${r.map(Sn).join(", ")}]`)}return e.classification.length&&o.push(e.classification.length===1?`classification = ${Sn(e.classification[0])}`:`classification IN [${e.classification.map(Sn).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 = ${Sn(e.loss)}`),o.join(" AND ")}const it={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},Ua="_";function li(e,n=new URLSearchParams){for(const o of Object.values(it))n.delete(o);return e.dynasty.length&&n.set(it.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(it.classification,e.classification.map(o=>o||Ua).join(",")),e.hasImage&&n.set(it.hasImage,"1"),e.hasText&&n.set(it.hasText,"1"),e.hasCollated&&n.set(it.hasCollated,"1"),e.loss&&n.set(it.loss,e.loss),e.sort&&n.set(it.sort,e.sort),n}function Zp(e){const n=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),o=new Set(yi.map(a=>a.key)),r=new Set(ji.map(a=>a.value)),s=e.get(it.loss);return{dynasty:Array.from(new Set(n(it.dynasty).filter(a=>o.has(a)))),classification:Array.from(new Set(n(it.classification).map(a=>a===Ua?"":a).filter(a=>r.has(a)))),hasImage:e.get(it.hasImage)==="1",hasText:e.get(it.hasText)==="1"||e.get(it.hasCollated)==="1",hasCollated:!1,loss:s==="extant"||s==="partially_extant"||s==="lost"?s:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(a=>a===e.get(it.sort))??""}}function Jp(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 rs(e,n){return e.includes(n)?e.filter(o=>o!==n):[...e,n]}const Qp=({filters:e,onChange:n})=>{const o=Te(),r=o.searchV4,{convert:s}=Ae(),[a,l]=g.useState(!1),d=g.useId(),c=vi(e),p=u=>n({...e,...u});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":s(r.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":a,"aria-controls":d,onClick:()=>l(u=>!u),children:[t.jsxs("span",{children:[s(r.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:s(mt(r.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[s(a?r.collapse:r.expand)," ",a?"▴":"▾"]})]}),t.jsxs("div",{className:"bim-sr-filters",id:d,"data-open":a?"true":"false",...a?{}:{"data-collapsed":"true"},children:[t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(r.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:yi.map(u=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(u.key),onClick:()=>p({dynasty:rs(e.dynasty,u.key)}),children:s(u.key)},u.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(r.classification)}),ji.map(u=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(u.value),onChange:()=>p({classification:rs(e.classification,u.value)})}),u.value?s(u.label):o.searchPage.unclassified]},u.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(r.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:u=>p({hasImage:u.target.checked})}),s(r.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:u=>p({hasText:u.target.checked})}),s(r.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:s(r.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:Oa.map(u=>t.jsx("button",{type:"button","aria-pressed":e.loss===u.value,onClick:()=>p({loss:u.value}),children:o.searchPage.loss[u.value||"all"]},u.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...bi,sort:e.sort}),children:s(r.clearAllFilters)})]})]})};function Va({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(),a=[];let l=0,d=0;for(;l<e.length;){const c=r.indexOf(s,l);if(c<0){a.push(e.slice(l));break}c>l&&a.push(e.slice(l,c)),a.push(t.jsx("mark",{className:"bim-sr-hl",children:e.slice(c,c+s.length)},d++)),l=c+s.length}return t.jsx(t.Fragment,{children:a})}const ss=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=Te(),a=s.searchV4,{convert:l}=Ae(),d=Ze();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:l(a.colTitle)}),t.jsx("th",{scope:"col",children:l(a.colType)}),t.jsx("th",{scope:"col",children:l(a.colAuthor)}),t.jsx("th",{scope:"col",children:l(a.colEra)}),t.jsx("th",{scope:"col",children:l(a.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:l(a.colResource)})]})}),t.jsx("tbody",{children:e.map(c=>{const p=l(c.title||c.primary_name||c.id),u=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",m=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${l(c.author)}${c.role&&c.role!=="author"?` ${l(c.role)}`:""}`:"",h=c.type==="book"?c.era??c.dynasty:c.dynasty,f=h?l(h):"",x=c.classification?l(c.classification):"",k=[];c.has_image&&k.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&k.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&k.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const y=[m,f,x].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:d(c.id),onClick:w=>o(c,w),children:t.jsx(Va,{text:p,query:n?l(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(fn,{type:c.type,size:6})," ",r(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:m||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:f||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:x||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:k.map(w=>t.jsx("span",{className:`bim-sr-tag ${w.cls}`,children:l(w.label)},w.label))})]},c.id)})})]})})},eu=`
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
- `,rs=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=ze(),a=s.searchV4,{convert:l}=Re(),d=Je();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Jp}),e.map(c=>{const p=l(c.title||c.primary_name||c.id),u=c.measure_info?l(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??"?"}`:"":`${c.dynasty?`〔${l(c.dynasty)}〕`:""}${c.author?l(c.author):""}`,c.type==="book"&&c.edition?l(c.edition):"",u].filter(Boolean).join(" · "),f=[r(c.type),c.classification?l(c.classification):""].filter(Boolean).join(" · "),x=[];return c.has_image&&x.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&x.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&x.push({label:a.tagLost,cls:"bim-sr-tag--lost"}),t.jsxs("a",{className:"bim-sc",href:d(c.id),onClick:k=>o(c,k),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(Da,{text:p,query:n?l(n):void 0})}),h&&t.jsx("span",{className:"bim-sc-m",children:h}),c.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:Io(c.descriptionSnippet).map((k,y)=>k.marked?t.jsx("mark",{children:l(k.text)},y):t.jsx(g.Fragment,{children:l(k.text)},y))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:f}),t.jsx("span",{className:"bim-sc-tags",children:x.map(k=>t.jsx("span",{className:`bim-sr-tag ${k.cls}`,children:l(k.label)},k.label))})]})]},c.id)})]})};function Qp(e,n){const o=new Set([1,n,e-1,e,e+1].filter(a=>a>=1&&a<=n)),r=Array.from(o).sort((a,l)=>a-l),s=[];return r.forEach((a,l)=>{l>0&&a-r[l-1]>1&&s.push("gap"),s.push(a)}),s}function eu(e,n,o){const r=Math.max(1,Math.ceil(n/o));return Math.min(Math.max(1,e),r)}const tu=({page:e,pageSize:n,total:o,totalLabel:r,onPage:s})=>{const a=ze().searchV4,{convert:l}=Re(),d=Math.max(1,Math.ceil(o/n));return o<=0?null:t.jsxs("nav",{className:"bim-sr-pager","aria-label":l(a.pagerLabel),children:[t.jsx("span",{className:"bim-sr-info",children:l(ut(a.pageInfo,{total:r??o.toLocaleString(),size:n,page:e,pages:d}))}),d>1&&t.jsxs("ul",{children:[t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>s(e-1),children:l(a.prevPage)})}),Qp(e,d).map((c,p)=>c==="gap"?t.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${p}`):t.jsx("li",{children:t.jsx("button",{type:"button","aria-current":c===e?"page":void 0,"aria-label":`${c}`,onClick:()=>s(c),children:c})},c)),t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e>=d,onClick:()=>s(e+1),children:l(a.nextPage)})})]})]})},Ua="(max-width: 719px)",nu=`${Ua}, (pointer: coarse)`,iu=`
15
+ `,as=({entries:e,query:n,onEntryLinkClick:o,typeName:r})=>{const s=Te(),a=s.searchV4,{convert:l}=Ae(),d=Ze();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:eu}),e.map(c=>{const p=l(c.title||c.primary_name||c.id),u=c.measure_info?l(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??"?"}`:"":`${c.dynasty?`〔${l(c.dynasty)}〕`:""}${c.author?l(c.author):""}`,c.type==="book"&&c.edition?l(c.edition):"",u].filter(Boolean).join(" · "),f=[r(c.type),c.classification?l(c.classification):""].filter(Boolean).join(" · "),x=[];return c.has_image&&x.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&x.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&x.push({label:a.tagLost,cls:"bim-sr-tag--lost"}),t.jsxs("a",{className:"bim-sc",href:d(c.id),onClick:k=>o(c,k),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(Va,{text:p,query:n?l(n):void 0})}),h&&t.jsx("span",{className:"bim-sc-m",children:h}),c.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:Lo(c.descriptionSnippet).map((k,y)=>k.marked?t.jsx("mark",{children:l(k.text)},y):t.jsx(g.Fragment,{children:l(k.text)},y))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:f}),t.jsx("span",{className:"bim-sc-tags",children:x.map(k=>t.jsx("span",{className:`bim-sr-tag ${k.cls}`,children:l(k.label)},k.label))})]})]},c.id)})]})};function tu(e,n){const o=new Set([1,n,e-1,e,e+1].filter(a=>a>=1&&a<=n)),r=Array.from(o).sort((a,l)=>a-l),s=[];return r.forEach((a,l)=>{l>0&&a-r[l-1]>1&&s.push("gap"),s.push(a)}),s}function nu(e,n,o){const r=Math.max(1,Math.ceil(n/o));return Math.min(Math.max(1,e),r)}const iu=({page:e,pageSize:n,total:o,totalLabel:r,onPage:s})=>{const a=Te().searchV4,{convert:l}=Ae(),d=Math.max(1,Math.ceil(o/n));return o<=0?null:t.jsxs("nav",{className:"bim-sr-pager","aria-label":l(a.pagerLabel),children:[t.jsx("span",{className:"bim-sr-info",children:l(mt(a.pageInfo,{total:r??o.toLocaleString(),size:n,page:e,pages:d}))}),d>1&&t.jsxs("ul",{children:[t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>s(e-1),children:l(a.prevPage)})}),tu(e,d).map((c,p)=>c==="gap"?t.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${p}`):t.jsx("li",{children:t.jsx("button",{type:"button","aria-current":c===e?"page":void 0,"aria-label":`${c}`,onClick:()=>s(c),children:c})},c)),t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e>=d,onClick:()=>s(e+1),children:l(a.nextPage)})})]})]})},Ga="(max-width: 719px)",ou=`${Ga}, (pointer: coarse)`,ru=`
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 ${Ua} {
84
+ @media ${Ga} {
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 ${nu} {
105
+ @media ${ou} {
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,10 +117,10 @@
117
117
  :root[data-layout="boxed"] .bim-sr-table th { background: ${i("fr-bg")}; }
118
118
  /* 墨:主色与正文对比不到 3:1,标题链接另加下划线 */
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
- `,Wo="bim-search-view",Di=50,ss=5,Nn=1e3;function ti(e){return e>=Nn?`${Nn.toLocaleString()}+`:e.toLocaleString()}const ou={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function ru(e){return e&&ou[e.toLowerCase()]||"all"}function su(e){return e==="all"?null:e}const as=["work","collection","book","entity"],au={work:"works",collection:"collections",book:"books",entity:"entities"},lu={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function cu(){try{return window.localStorage.getItem(Wo)==="card"?"card":"table"}catch{return"table"}}function du(e){try{window.localStorage.setItem(Wo,e)}catch{}}const tn=(e,n)=>(e==null?void 0:e[lu[n]])??0,Ui=(e,n)=>(e==null?void 0:e[au[n]])??[],Va=({transport:e,query:n,filters:o,onFiltersChange:r,onEntryLinkClick:s,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:p})=>{const u=ze(),m=u.searchV4,{convert:h}=Re(),f=!!e.supportsSearchFilters,x=g.useMemo(()=>f?o:fi,[f,o]),[k,y]=g.useState("table");g.useEffect(()=>{y(cu())},[]);const w=X=>{y(X),du(X)},[b,j]=g.useState(l??"all"),S=g.useRef(b);S.current=b,g.useEffect(()=>{l!==void 0&&l!==S.current&&(j(l),$(1))},[l]);const[v,$]=g.useState(c&&c>0?c:1),_=g.useRef(v);_.current=v,g.useEffect(()=>{c!==void 0&&c>0&&c!==_.current&&$(c)},[c]);const C=g.useRef(null),M=g.useCallback(X=>{var he;$(X),p==null||p(X);const ie=C.current;ie&&ie.getBoundingClientRect().top<0&&((he=ie.scrollIntoView)==null||he.call(ie,{block:"start",behavior:"instant"}))},[p]),[T,z]=g.useState(null),[H,N]=g.useState(null),[I,L]=g.useState(!1),[R,P]=g.useState(""),U=si(x).toString(),q=yi(x)>0,D=si({...x,sort:""}).toString(),O=g.useRef({query:n,filterOnlyKey:D,sort:x.sort});g.useEffect(()=>{const X=O.current;X.query!==n||X.filterOnlyKey!==D?(j("all"),$(1)):X.sort!==x.sort&&$(1),O.current={query:n,filterOnlyKey:D,sort:x.sort}},[n,D,x.sort]),g.useEffect(()=>{let X=!1;return L(!0),P(""),(async()=>{try{let ie;if(e.searchAll)ie=await e.searchAll(n,ss,x);else{const he=["work","book","collection","entity"],Te=await Promise.all(he.map(K=>e.search(n,K,{page:1,pageSize:ss,filters:x})));ie={works:Te[0].entries,books:Te[1].entries,collections:Te[2].entries,entities:Te[3].entries,totalWorks:Te[0].total,totalBooks:Te[1].total,totalCollections:Te[2].total,totalEntities:Te[3].total}}X||z(ie)}catch(ie){X||(P(ie instanceof Error?ie.message:String(ie)),z(null))}finally{X||L(!1)}})(),()=>{X=!0}},[e,n,U]);const A=b;g.useEffect(()=>{if(b==="all"){N(null);return}let X=!1;return L(!0),(async()=>{try{const ie=await e.search(n,b,{page:v,pageSize:Di,filters:x});X||N({key:A,entries:ie.entries,total:ie.total})}catch(ie){X||(P(ie instanceof Error?ie.message:String(ie)),N(null))}finally{X||L(!1)}})(),()=>{X=!0}},[e,n,U,b,v]);const G=H&&H.key===A?H:null;g.useEffect(()=>{if(b==="all"||!G||I)return;const X=Math.min(G.total,Nn),ie=eu(v,X,Di);G.entries.length===0&&X>0&&ie!==v&&($(ie),p==null||p(ie))},[b,G,I,v]);const le=g.useMemo(()=>as.filter(X=>tn(T,X)>0),[T]),ne=le.reduce((X,ie)=>X+tn(T,ie),0),ve=le.some(X=>tn(T,X)>=Nn)?`${ne.toLocaleString()}+`:ne.toLocaleString(),oe=!I&&!R&&T!==null&&ne===0,pe=g.useCallback(X=>{j(X),$(1),d==null||d(X)},[d]),We=g.useMemo(()=>{const X=[];return x.dynasty.forEach(ie=>X.push({name:ie,remove:()=>r({...x,dynasty:x.dynasty.filter(he=>he!==ie)})})),x.classification.forEach(ie=>{var he;return X.push({name:ie?((he=bi.find(Te=>Te.value===ie))==null?void 0:he.label)??ie:u.searchPage.unclassified,remove:()=>r({...x,classification:x.classification.filter(Te=>Te!==ie)})})}),x.hasImage&&X.push({name:m.hasImage,remove:()=>r({...x,hasImage:!1})}),x.hasText&&X.push({name:m.hasText,remove:()=>r({...x,hasText:!1})}),x.hasCollated&&X.push({name:m.hasCollated,remove:()=>r({...x,hasCollated:!1})}),x.loss&&X.push({name:`${m.extant}:${u.searchPage.loss[x.loss]}`,remove:()=>r({...x,loss:""})}),X},[x,r,m,u]),ee={query:n,onEntryLinkClick:s,typeName:a},Be=X=>k==="table"?t.jsx(os,{entries:X,...ee}):t.jsx(rs,{entries:X,...ee}),Ee=as.flatMap(X=>Ui(T,X));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:iu}),f&&t.jsx(Zp,{filters:x,onChange:r}),t.jsxs("div",{className:"bim-sr-main","aria-busy":I,ref:C,children:[le.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":u.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs(ls,{on:b==="all",onClick:()=>pe("all"),children:[u.search.allTab," ",t.jsx("small",{children:ve})]}),le.map(X=>t.jsxs(ls,{on:b===X,onClick:()=>pe(X),children:[a(X)," ",t.jsx("small",{children:ti(tn(T,X))})]},X))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":h(m.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!x.sort,onClick:()=>r({...x,sort:""}),children:h(m.sortRelevance)}),["era","title"].map(X=>{const ie=x.sort.startsWith(`${X}:`)?x.sort.endsWith("desc")?"desc":"asc":null,he=X==="era"?m.sortEra:m.sortTitle,Te=X==="era"?ie==="desc"?m.sortEraDesc:m.sortEraAsc:ie==="desc"?m.sortTitleDesc:m.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":ie!==null,title:h(Te),onClick:()=>r({...x,sort:`${X}:${ie==="asc"?"desc":"asc"}`}),children:[h(he),ie?t.jsxs("span",{"aria-hidden":"true",children:[" ",ie==="asc"?"↑":"↓"]}):null]},X)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":h(m.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":k==="table",onClick:()=>w("table"),children:h(m.viewTable)}),t.jsx("button",{type:"button","aria-pressed":k==="card",onClick:()=>w("card"),children:h(m.viewCard)})]})]}),q&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:h(ut(m.filteredCount,{n:ve}))}),We.map(X=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":h(ut(m.removeFilter,{name:X.name})),onClick:X.remove,children:[h(X.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},X.name))]}),R&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:R}),oe&&t.jsx("div",{className:"bim-sr-empty",children:h(q?m.emptyFiltered:ut(u.search.noResultsFor,{query:n}))}),!R&&!oe&&b==="all"&&T&&(k==="table"?t.jsxs(t.Fragment,{children:[t.jsx(os,{entries:Ee,...ee}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:h(m.limitedNote)})]}):t.jsx(t.Fragment,{children:le.map(X=>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(gn,{type:X,size:8}),a(X),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[ti(tn(T,X))," ",u.unit.items]})]}),tn(T,X)>Ui(T,X).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>pe(X),children:u.action.viewAll})]}),t.jsx(rs,{entries:Ui(T,X),...ee})]},X))})),!R&&b!=="all"&&!G&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:u.search.loading}),!R&&b!=="all"&&G&&G.entries.length>0&&t.jsxs(t.Fragment,{children:[Be(G.entries),t.jsx(tu,{page:v,pageSize:Di,total:Math.min(G.total,Nn),totalLabel:ti(G.total),onPage:M})]}),!R&&b!=="all"&&G&&G.entries.length===0&&!I&&t.jsxs("div",{className:"bim-sr-empty",children:[h(q?m.emptyFiltered:ut(u.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>pe("all"),children:u.search.allTab})})]})]})]})};function ls({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 an="bim-recent-ids",cs="bim-recent-entries",ds=50;function Pt(){try{const e=localStorage.getItem(an);if(e)return JSON.parse(e);const n=localStorage.getItem(cs);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(an,JSON.stringify(o)),localStorage.removeItem(cs),o}return[]}catch{return[]}}function ao(e){try{const n=Pt().filter(o=>o!==e);n.unshift(e),n.length>ds&&(n.length=ds),localStorage.setItem(an,JSON.stringify(n))}catch{}}function Ga(e){try{const n=Pt().filter(o=>o!==e);localStorage.setItem(an,JSON.stringify(n))}catch{}}function Oo(){try{localStorage.removeItem(an)}catch{}}async function Ho(e,n){var o,r,s;try{if(e.getEntry){const l=await e.getEntry(n);if(l)return l}const a=await e.getItem(n);if(a){const l=a.authors;return{id:n,title:a.title||n,type:a.type||"work",author:(o=l==null?void 0:l[0])==null?void 0:o.name,dynasty:(r=l==null?void 0:l[0])==null?void 0:r.dynasty,role:(s=l==null?void 0:l[0])==null?void 0:s.role,edition:a.edition||void 0}}}catch{}return{id:n,title:n,type:"work",notFound:!0}}const Vi=5,pu=50,uu=200,ps={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},lo=({transport:e,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:p,resultVariant:u="compact",renderEntry:m,initialQuery:h,onQueryChange:f,headerRight:x,reserveViewportHeight:k=!1,filtersEnabled:y=!1,filters:w=fi,onFiltersChange:b,resultTab:j,onResultTabChange:S,resultPage:v,onResultPageChange:$})=>{const _=ze(),C=[{type:"work",name:_.indexType.work,key:"works"},{type:"book",name:_.indexType.book,key:"books"},{type:"collection",name:_.indexType.collection,key:"collections"},{type:"entity",name:_.indexType.entity,key:"entities"}],M=["work","collection","book","entity"],[T,z]=g.useState(h??""),[H,N]=g.useState(null),[I,L]=g.useState(h??""),R=si(w).toString(),[P,U]=g.useState(w);g.useEffect(()=>{U(w)},[R]);const q=E=>{U(E),b==null||b(E)},[D,O]=g.useState(null),[A,G]=g.useState("all"),[le,ne]=g.useState(!1),[ve,oe]=g.useState(null),[pe,We]=g.useState(""),[ee,Be]=g.useState(!(h!=null&&h.trim())),[Ee,X]=g.useState(Pt),[ie,he]=g.useState([]),[Te,K]=g.useState(!1),[_e,se]=g.useState(!1),[$e,Z]=g.useState(null),[Ne,Oe]=g.useState(null),B=g.useRef(void 0),te=g.useRef(!1),be=g.useCallback(async(E,re)=>{if(!E.trim()){Be(!0),N(null),O(null);return}if(Be(!1),y){L(E);return}ne(!0),We("");try{if(e.searchAll){const ae=await e.searchAll(E,re??Vi);N(ae)}else{const ae=["work","book","collection","entity"],je=await Promise.all(ae.map(ke=>e.search(E,ke,{page:1,pageSize:re??Vi})));N({works:je[0].entries,books:je[1].entries,collections:je[2].entries,entities:je[3].entries,totalWorks:je[0].total,totalBooks:je[1].total,totalCollections:je[2].total,totalEntities:je[3].total})}}catch(ae){We(ae instanceof Error?ae.message:String(ae)),N(null)}finally{ne(!1)}},[e,y]);g.useEffect(()=>{let E=!1;const re=()=>{var Le,V;const ae=["work","book","collection","entity"],je=Promise.all(ae.map(xe=>e.loadEntries(xe,{page:1,pageSize:1}).catch(()=>({total:0})))),ke=((Le=e.getResourceCounts)==null?void 0:Le.call(e).catch(()=>null))??Promise.resolve(null),ge=((V=e.getSubtypeStats)==null?void 0:V.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([je,ke,ge]).then(([xe,Ae,Y])=>{E||(Z({works:xe[0].total,books:xe[1].total,collections:xe[2].total,entities:xe[3].total,hasText:Ae==null?void 0:Ae.hasText,hasImage:Ae==null?void 0:Ae.hasImage}),Y&&Oe(Y))})};return e.getCounts?e.getCounts().then(ae=>{var je,ke;E||(Z({works:ae.works,books:ae.books,collections:ae.collections,entities:ae.entities,hasText:(je=ae.resourceCounts)==null?void 0:je.hasText,hasImage:(ke=ae.resourceCounts)==null?void 0:ke.hasImage}),ae.subtypeStats&&Oe(ae.subtypeStats))}).catch(()=>{E||re()}):re(),()=>{E=!0}},[e]),g.useEffect(()=>{te.current||!(h!=null&&h.trim())||(te.current=!0,be(h))},[h,be]);const Ie=g.useCallback(E=>{if(z(E),!E.trim()){f==null||f(E),Be(!0),N(null),O(null),G("all");return}B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{O(null),G("all"),f==null||f(E),be(E)},uu)},[be,f]),F=g.useCallback(E=>{B.current&&clearTimeout(B.current),G("all"),f==null||f(E),be(E)},[be,f]),ue=g.useCallback(E=>{O(E),be(T,pu)},[T,be]);g.useEffect(()=>{if(!Ee.length){he([]);return}let E=!1;return K(!0),Promise.all(Ee.slice(0,10).map(re=>Ho(e,re))).then(re=>{E||(he(re),K(!1))}),()=>{E=!0}},[Ee,e]);const Q=E=>{oe(E.id),ao(E.id),X(Pt()),r==null||r(E)},ye=(E,re)=>{if(r&&hu(re)){re.preventDefault(),Q(E);return}ao(E.id),X(Pt())},Ce=E=>{Ga(E),X(Pt())},Me=()=>{Oo(),X([])},De=E=>C.find(re=>re.type===E),qe=!ee&&!H&&!pe,me=H&&(H.works.length>0||H.books.length>0||H.collections.length>0),Ve=t.jsxs(t.Fragment,{children:[t.jsx(Pa,{transport:e,value:T,onChange:Ie,onSearch:F,onEntrySelect:Q}),y&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const E=T.trim();E&&Aa(E),F(T)},children:_.searchPage.submit}),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:_.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:k?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:gu+(y?fu:"")}),(!y||x||!p)&&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:[y?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:_.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[x,!p&&t.jsx(La,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),y?t.jsxs("div",{className:"bim-ib-bar","data-nofilters":e.supportsSearchFilters?void 0:"true",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("div",{className:"bim-ib-bar-main",children:Ve})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:Ve}),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:$e&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:Ne?t.jsxs(t.Fragment,{children:[(Ne.book??0)>0&&t.jsxs(t.Fragment,{children:[_.searchPage.statBook," ",t.jsx("strong",{style:{color:i("fg")},children:Ne.book.toLocaleString()})," ",_.unit.bu,_.searchPage.statComma,t.jsx("strong",{style:{color:i("fg")},children:$e.books.toLocaleString()})," ",_.searchPage.statBookCopies]}),Ne.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statArticle," ",t.jsx("strong",{style:{color:i("fg")},children:Ne.article.toLocaleString()})," ",_.searchPage.statArticleUnit]}):null,Ne.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statPoem," ",t.jsx("strong",{style:{color:i("fg")},children:Ne.poem.toLocaleString()})," ",_.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statCollection," ",t.jsx("strong",{style:{color:i("fg")},children:$e.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[_.indexType.work," ",t.jsx("strong",{style:{color:i("fg")},children:$e.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.book," ",t.jsx("strong",{style:{color:i("fg")},children:$e.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.collection," ",t.jsx("strong",{style:{color:i("fg")},children:$e.collections.toLocaleString()}),$e.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.entity," ",t.jsx("strong",{style:{color:i("fg")},children:$e.entities.toLocaleString()})]})]})}),$e.hasImage!=null&&$e.hasText!=null&&t.jsxs("span",{children:[_.resourceType.image," ",t.jsx("strong",{style:{color:i("fg")},children:$e.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.resourceType.text," ",t.jsx("strong",{style:{color:i("fg")},children:$e.hasText.toLocaleString()})]})]})}),y&&!ee&&t.jsx(Va,{transport:e,query:I,filters:P,onFiltersChange:q,onEntryLinkClick:ye,typeName:E=>De(E).name,tab:j,onTabChange:S,page:v,onPageChange:$}),!(y&&!ee)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:le||qe?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:mu,boxSizing:"border-box"},children:_.search.searching}):pe?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:i("desc-fg")},children:pe})}):ee?t.jsx("div",{style:{flex:1},children:Te?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:_.search.loading}):ie.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:_.search.recentBrowse}),t.jsx("button",{onClick:Me,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:_.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ie.slice(0,_e?10:3).map(E=>E.notFound?t.jsx(ju,{id:E.id,onRemove:Ce,t:_},E.id):t.jsx(us,{entry:E,selected:ve===E.id,onClick:ye,getConfig:De,onRemove:Ce},E.id))}),!_e&&ie.length>3&&t.jsx("button",{onClick:()=>se(!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:_.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:_.search.searchTitle}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:_.search.searchSubtitle})]})}):me?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:xu}),(()=>{const E=ge=>H[ps[ge]]??0,re=M.map(ge=>C.find(Le=>Le.type===ge)).filter(ge=>E(ge.key)>0);if(re.length<2)return null;const ae=re.reduce((ge,Le)=>ge+E(Le.key),0),je=ge=>{if(G(ge),ge!=="all"&&D!==ge){const Le=C.find(xe=>xe.type===ge),V=(H[Le.key]??[]).length;E(Le.key)>V&&ue(ge)}},ke=ge=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(ge?"fg":"desc-fg"),fontWeight:ge?700:400,boxShadow:ge?`inset 0 -2px 0 ${i("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":_.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":A==="all",style:ke(A==="all"),onClick:()=>je("all"),children:[_.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ae.toLocaleString()})]}),re.map(ge=>t.jsxs("button",{type:"button","aria-pressed":A===ge.type,style:ke(A===ge.type),onClick:()=>je(ge.type),children:[ge.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:E(ge.key).toLocaleString()})]},ge.type))]})})(),C.map(({type:E,name:re,key:ae})=>{const je=H[ae]??[],ke=ps[ae],ge=H[ke]??0;if(je.length===0||A!=="all"&&A!==E)return null;const V=A==="all"&&!(D===E)&&ge>Vi;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(gn,{type:E})," ",re,t.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[ge," ",_.unit.items]})]}),V&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>ue(E),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:_.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:je.map(xe=>{if(m)return t.jsx(g.Fragment,{children:m(xe)},xe.id);const Ae=u==="card"?yu:us;return t.jsx(Ae,{entry:xe,selected:ve===xe.id,onClick:ye,getConfig:De,query:T},xe.id)})})]},E)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:ut(_.search.noResultsFor,{query:T})}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:_.search.tryOther})]})})]})},mu=240;function hu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const gu=`
120
+ `,Ho="bim-search-view",Vi=50,ls=5,En=1e3;function ii(e){return e>=En?`${En.toLocaleString()}+`:e.toLocaleString()}const su={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function au(e){return e&&su[e.toLowerCase()]||"all"}function lu(e){return e==="all"?null:e}const cs=["work","collection","book","entity"],cu={work:"works",collection:"collections",book:"books",entity:"entities"},du={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function pu(){try{return window.localStorage.getItem(Ho)==="card"?"card":"table"}catch{return"table"}}function uu(e){try{window.localStorage.setItem(Ho,e)}catch{}}const nn=(e,n)=>(e==null?void 0:e[du[n]])??0,Gi=(e,n)=>(e==null?void 0:e[cu[n]])??[],Ya=({transport:e,query:n,filters:o,onFiltersChange:r,onEntryLinkClick:s,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:p})=>{const u=Te(),m=u.searchV4,{convert:h}=Ae(),f=!!e.supportsSearchFilters,x=g.useMemo(()=>f?o:bi,[f,o]),[k,y]=g.useState("table");g.useEffect(()=>{y(pu())},[]);const w=Z=>{y(Z),uu(Z)},[b,j]=g.useState(l??"all"),S=g.useRef(b);S.current=b,g.useEffect(()=>{l!==void 0&&l!==S.current&&(j(l),$(1))},[l]);const[v,$]=g.useState(c&&c>0?c:1),_=g.useRef(v);_.current=v,g.useEffect(()=>{c!==void 0&&c>0&&c!==_.current&&$(c)},[c]);const C=g.useRef(null),M=g.useCallback(Z=>{var oe;$(Z),p==null||p(Z);const le=C.current;le&&le.getBoundingClientRect().top<0&&((oe=le.scrollIntoView)==null||oe.call(le,{block:"start",behavior:"instant"}))},[p]),[N,T]=g.useState(null),[F,R]=g.useState(null),[E,L]=g.useState(!1),[I,P]=g.useState(""),V=li(x).toString(),X=vi(x)>0,D=li({...x,sort:""}).toString(),O=g.useRef({query:n,filterOnlyKey:D,sort:x.sort});g.useEffect(()=>{const Z=O.current;Z.query!==n||Z.filterOnlyKey!==D?(j("all"),$(1)):Z.sort!==x.sort&&$(1),O.current={query:n,filterOnlyKey:D,sort:x.sort}},[n,D,x.sort]),g.useEffect(()=>{let Z=!1;return L(!0),P(""),(async()=>{try{let le;if(e.searchAll)le=await e.searchAll(n,ls,x);else{const oe=["work","book","collection","entity"],he=await Promise.all(oe.map(U=>e.search(n,U,{page:1,pageSize:ls,filters:x})));le={works:he[0].entries,books:he[1].entries,collections:he[2].entries,entities:he[3].entries,totalWorks:he[0].total,totalBooks:he[1].total,totalCollections:he[2].total,totalEntities:he[3].total}}Z||T(le)}catch(le){Z||(P(le instanceof Error?le.message:String(le)),T(null))}finally{Z||L(!1)}})(),()=>{Z=!0}},[e,n,V]);const A=b;g.useEffect(()=>{if(b==="all"){R(null);return}let Z=!1;return L(!0),(async()=>{try{const le=await e.search(n,b,{page:v,pageSize:Vi,filters:x});Z||R({key:A,entries:le.entries,total:le.total})}catch(le){Z||(P(le instanceof Error?le.message:String(le)),R(null))}finally{Z||L(!1)}})(),()=>{Z=!0}},[e,n,V,b,v]);const G=F&&F.key===A?F:null;g.useEffect(()=>{if(b==="all"||!G||E)return;const Z=Math.min(G.total,En),le=nu(v,Z,Vi);G.entries.length===0&&Z>0&&le!==v&&($(le),p==null||p(le))},[b,G,E,v]);const se=g.useMemo(()=>cs.filter(Z=>nn(N,Z)>0),[N]),Q=se.reduce((Z,le)=>Z+nn(N,le),0),ve=se.some(Z=>nn(N,Z)>=En)?`${Q.toLocaleString()}+`:Q.toLocaleString(),ne=!E&&!I&&N!==null&&Q===0,ce=g.useCallback(Z=>{j(Z),$(1),d==null||d(Z)},[d]),We=g.useMemo(()=>{const Z=[];return x.dynasty.forEach(le=>Z.push({name:le,remove:()=>r({...x,dynasty:x.dynasty.filter(oe=>oe!==le)})})),x.classification.forEach(le=>{var oe;return Z.push({name:le?((oe=ji.find(he=>he.value===le))==null?void 0:oe.label)??le:u.searchPage.unclassified,remove:()=>r({...x,classification:x.classification.filter(he=>he!==le)})})}),x.hasImage&&Z.push({name:m.hasImage,remove:()=>r({...x,hasImage:!1})}),x.hasText&&Z.push({name:m.hasText,remove:()=>r({...x,hasText:!1})}),x.hasCollated&&Z.push({name:m.hasCollated,remove:()=>r({...x,hasCollated:!1})}),x.loss&&Z.push({name:`${m.extant}:${u.searchPage.loss[x.loss]}`,remove:()=>r({...x,loss:""})}),Z},[x,r,m,u]),ke={query:n,onEntryLinkClick:s,typeName:a},Pe=Z=>k==="table"?t.jsx(ss,{entries:Z,...ke}):t.jsx(as,{entries:Z,...ke}),Ee=cs.flatMap(Z=>Gi(N,Z));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:ru}),f&&t.jsx(Qp,{filters:x,onChange:r}),t.jsxs("div",{className:"bim-sr-main","aria-busy":E,ref:C,children:[se.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":u.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs(ds,{on:b==="all",onClick:()=>ce("all"),children:[u.search.allTab," ",t.jsx("small",{children:ve})]}),se.map(Z=>t.jsxs(ds,{on:b===Z,onClick:()=>ce(Z),children:[a(Z)," ",t.jsx("small",{children:ii(nn(N,Z))})]},Z))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":h(m.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!x.sort,onClick:()=>r({...x,sort:""}),children:h(m.sortRelevance)}),["era","title"].map(Z=>{const le=x.sort.startsWith(`${Z}:`)?x.sort.endsWith("desc")?"desc":"asc":null,oe=Z==="era"?m.sortEra:m.sortTitle,he=Z==="era"?le==="desc"?m.sortEraDesc:m.sortEraAsc:le==="desc"?m.sortTitleDesc:m.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":le!==null,title:h(he),onClick:()=>r({...x,sort:`${Z}:${le==="asc"?"desc":"asc"}`}),children:[h(oe),le?t.jsxs("span",{"aria-hidden":"true",children:[" ",le==="asc"?"↑":"↓"]}):null]},Z)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":h(m.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":k==="table",onClick:()=>w("table"),children:h(m.viewTable)}),t.jsx("button",{type:"button","aria-pressed":k==="card",onClick:()=>w("card"),children:h(m.viewCard)})]})]}),X&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:h(mt(m.filteredCount,{n:ve}))}),We.map(Z=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":h(mt(m.removeFilter,{name:Z.name})),onClick:Z.remove,children:[h(Z.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},Z.name))]}),I&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:I}),ne&&t.jsx("div",{className:"bim-sr-empty",children:h(X?m.emptyFiltered:mt(u.search.noResultsFor,{query:n}))}),!I&&!ne&&b==="all"&&N&&(k==="table"?t.jsxs(t.Fragment,{children:[t.jsx(ss,{entries:Ee,...ke}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:h(m.limitedNote)})]}):t.jsx(t.Fragment,{children:se.map(Z=>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(fn,{type:Z,size:8}),a(Z),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:i("meta-fg")},children:[ii(nn(N,Z))," ",u.unit.items]})]}),nn(N,Z)>Gi(N,Z).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>ce(Z),children:u.action.viewAll})]}),t.jsx(as,{entries:Gi(N,Z),...ke})]},Z))})),!I&&b!=="all"&&!G&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:u.search.loading}),!I&&b!=="all"&&G&&G.entries.length>0&&t.jsxs(t.Fragment,{children:[Pe(G.entries),t.jsx(iu,{page:v,pageSize:Vi,total:Math.min(G.total,En),totalLabel:ii(G.total),onPage:M})]}),!I&&b!=="all"&&G&&G.entries.length===0&&!E&&t.jsxs("div",{className:"bim-sr-empty",children:[h(X?m.emptyFiltered:mt(u.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>ce("all"),children:u.search.allTab})})]})]})]})};function ds({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 ln="bim-recent-ids",ps="bim-recent-entries",us=50;function Mt(){try{const e=localStorage.getItem(ln);if(e)return JSON.parse(e);const n=localStorage.getItem(ps);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(ln,JSON.stringify(o)),localStorage.removeItem(ps),o}return[]}catch{return[]}}function co(e){try{const n=Mt().filter(o=>o!==e);n.unshift(e),n.length>us&&(n.length=us),localStorage.setItem(ln,JSON.stringify(n))}catch{}}function Ka(e){try{const n=Mt().filter(o=>o!==e);localStorage.setItem(ln,JSON.stringify(n))}catch{}}function Fo(){try{localStorage.removeItem(ln)}catch{}}async function Do(e,n){var o,r,s;try{if(e.getEntry){const l=await e.getEntry(n);if(l)return l}const a=await e.getItem(n);if(a){const l=a.authors;return{id:n,title:a.title||n,type:a.type||"work",author:(o=l==null?void 0:l[0])==null?void 0:o.name,dynasty:(r=l==null?void 0:l[0])==null?void 0:r.dynasty,role:(s=l==null?void 0:l[0])==null?void 0:s.role,edition:a.edition||void 0}}}catch{}return{id:n,title:n,type:"work",notFound:!0}}const Yi=5,mu=50,hu=200,ms={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},po=({transport:e,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:p,resultVariant:u="compact",renderEntry:m,initialQuery:h,onQueryChange:f,headerRight:x,reserveViewportHeight:k=!1,filtersEnabled:y=!1,filters:w=bi,onFiltersChange:b,resultTab:j,onResultTabChange:S,resultPage:v,onResultPageChange:$})=>{const _=Te(),C=[{type:"work",name:_.indexType.work,key:"works"},{type:"book",name:_.indexType.book,key:"books"},{type:"collection",name:_.indexType.collection,key:"collections"},{type:"entity",name:_.indexType.entity,key:"entities"}],M=["work","collection","book","entity"],[N,T]=g.useState(h??""),[F,R]=g.useState(null),[E,L]=g.useState(h??""),I=li(w).toString(),[P,V]=g.useState(w);g.useEffect(()=>{V(w)},[I]);const X=z=>{V(z),b==null||b(z)},[D,O]=g.useState(null),[A,G]=g.useState("all"),[se,Q]=g.useState(!1),[ve,ne]=g.useState(null),[ce,We]=g.useState(""),[ke,Pe]=g.useState(!(h!=null&&h.trim())),[Ee,Z]=g.useState(Mt),[le,oe]=g.useState([]),[he,U]=g.useState(!1),[$e,me]=g.useState(!1),[Ce,Y]=g.useState(null),[ze,Me]=g.useState(null),B=g.useRef(void 0),te=g.useRef(!1),xe=g.useCallback(async(z,ie)=>{if(!z.trim()){Pe(!0),R(null),O(null);return}if(Pe(!1),y){L(z);return}Q(!0),We("");try{if(e.searchAll){const ae=await e.searchAll(z,ie??Yi);R(ae)}else{const ae=["work","book","collection","entity"],be=await Promise.all(ae.map(je=>e.search(z,je,{page:1,pageSize:ie??Yi})));R({works:be[0].entries,books:be[1].entries,collections:be[2].entries,entities:be[3].entries,totalWorks:be[0].total,totalBooks:be[1].total,totalCollections:be[2].total,totalEntities:be[3].total})}}catch(ae){We(ae instanceof Error?ae.message:String(ae)),R(null)}finally{Q(!1)}},[e,y]);g.useEffect(()=>{let z=!1;const ie=()=>{var Ie,K;const ae=["work","book","collection","entity"],be=Promise.all(ae.map(fe=>e.loadEntries(fe,{page:1,pageSize:1}).catch(()=>({total:0})))),je=((Ie=e.getResourceCounts)==null?void 0:Ie.call(e).catch(()=>null))??Promise.resolve(null),ge=((K=e.getSubtypeStats)==null?void 0:K.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([be,je,ge]).then(([fe,Ne,q])=>{z||(Y({works:fe[0].total,books:fe[1].total,collections:fe[2].total,entities:fe[3].total,hasText:Ne==null?void 0:Ne.hasText,hasImage:Ne==null?void 0:Ne.hasImage}),q&&Me(q))})};return e.getCounts?e.getCounts().then(ae=>{var be,je;z||(Y({works:ae.works,books:ae.books,collections:ae.collections,entities:ae.entities,hasText:(be=ae.resourceCounts)==null?void 0:be.hasText,hasImage:(je=ae.resourceCounts)==null?void 0:je.hasImage}),ae.subtypeStats&&Me(ae.subtypeStats))}).catch(()=>{z||ie()}):ie(),()=>{z=!0}},[e]),g.useEffect(()=>{te.current||!(h!=null&&h.trim())||(te.current=!0,xe(h))},[h,xe]);const Re=g.useCallback(z=>{if(T(z),!z.trim()){f==null||f(z),Pe(!0),R(null),O(null),G("all");return}B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{O(null),G("all"),f==null||f(z),xe(z)},hu)},[xe,f]),H=g.useCallback(z=>{B.current&&clearTimeout(B.current),G("all"),f==null||f(z),xe(z)},[xe,f]),de=g.useCallback(z=>{O(z),xe(N,mu)},[N,xe]);g.useEffect(()=>{if(!Ee.length){oe([]);return}let z=!1;return U(!0),Promise.all(Ee.slice(0,10).map(ie=>Do(e,ie))).then(ie=>{z||(oe(ie),U(!1))}),()=>{z=!0}},[Ee,e]);const ee=z=>{ne(z.id),co(z.id),Z(Mt()),r==null||r(z)},ye=(z,ie)=>{if(r&&fu(ie)){ie.preventDefault(),ee(z);return}co(z.id),Z(Mt())},Se=z=>{Ka(z),Z(Mt())},Be=()=>{Fo(),Z([])},De=z=>C.find(ie=>ie.type===z),Je=!ke&&!F&&!ce,He=F&&(F.works.length>0||F.books.length>0||F.collections.length>0),Ue=t.jsxs(t.Fragment,{children:[t.jsx(Ba,{transport:e,value:N,onChange:Re,onSearch:H,onEntrySelect:ee}),y&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const z=N.trim();z&&Ma(z),H(N)},children:_.searchPage.submit}),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:_.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:k?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:xu+(y?bu:"")}),(!y||x||!p)&&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:[y?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:i("fg")},children:_.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[x,!p&&t.jsx(Pa,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),y?t.jsxs("div",{className:"bim-ib-bar","data-nofilters":e.supportsSearchFilters?void 0:"true",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("div",{className:"bim-ib-bar-main",children:Ue})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:Ue}),ke&&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:Ce&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:ze?t.jsxs(t.Fragment,{children:[(ze.book??0)>0&&t.jsxs(t.Fragment,{children:[_.searchPage.statBook," ",t.jsx("strong",{style:{color:i("fg")},children:ze.book.toLocaleString()})," ",_.unit.bu,_.searchPage.statComma,t.jsx("strong",{style:{color:i("fg")},children:Ce.books.toLocaleString()})," ",_.searchPage.statBookCopies]}),ze.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statArticle," ",t.jsx("strong",{style:{color:i("fg")},children:ze.article.toLocaleString()})," ",_.searchPage.statArticleUnit]}):null,ze.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statPoem," ",t.jsx("strong",{style:{color:i("fg")},children:ze.poem.toLocaleString()})," ",_.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statCollection," ",t.jsx("strong",{style:{color:i("fg")},children:Ce.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[_.indexType.work," ",t.jsx("strong",{style:{color:i("fg")},children:Ce.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.book," ",t.jsx("strong",{style:{color:i("fg")},children:Ce.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.collection," ",t.jsx("strong",{style:{color:i("fg")},children:Ce.collections.toLocaleString()}),Ce.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.entity," ",t.jsx("strong",{style:{color:i("fg")},children:Ce.entities.toLocaleString()})]})]})}),Ce.hasImage!=null&&Ce.hasText!=null&&t.jsxs("span",{children:[_.resourceType.image," ",t.jsx("strong",{style:{color:i("fg")},children:Ce.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.resourceType.text," ",t.jsx("strong",{style:{color:i("fg")},children:Ce.hasText.toLocaleString()})]})]})}),y&&!ke&&t.jsx(Ya,{transport:e,query:E,filters:P,onFiltersChange:X,onEntryLinkClick:ye,typeName:z=>De(z).name,tab:j,onTabChange:S,page:v,onPageChange:$}),!(y&&!ke)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:se||Je?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg"),minHeight:gu,boxSizing:"border-box"},children:_.search.searching}):ce?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:i("desc-fg")},children:ce})}):ke?t.jsx("div",{style:{flex:1},children:he?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:i("desc-fg")},children:_.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:_.search.recentBrowse}),t.jsx("button",{onClick:Be,style:{border:"none",background:"transparent",color:i("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:_.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:le.slice(0,$e?10:3).map(z=>z.notFound?t.jsx(ku,{id:z.id,onRemove:Se,t:_},z.id):t.jsx(hs,{entry:z,selected:ve===z.id,onClick:ye,getConfig:De,onRemove:Se},z.id))}),!$e&&le.length>3&&t.jsx("button",{onClick:()=>me(!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:_.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:_.search.searchTitle}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:_.search.searchSubtitle})]})}):He?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:yu}),(()=>{const z=ge=>F[ms[ge]]??0,ie=M.map(ge=>C.find(Ie=>Ie.type===ge)).filter(ge=>z(ge.key)>0);if(ie.length<2)return null;const ae=ie.reduce((ge,Ie)=>ge+z(Ie.key),0),be=ge=>{if(G(ge),ge!=="all"&&D!==ge){const Ie=C.find(fe=>fe.type===ge),K=(F[Ie.key]??[]).length;z(Ie.key)>K&&de(ge)}},je=ge=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:i(ge?"fg":"desc-fg"),fontWeight:ge?700:400,boxShadow:ge?`inset 0 -2px 0 ${i("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":_.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":A==="all",style:je(A==="all"),onClick:()=>be("all"),children:[_.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ae.toLocaleString()})]}),ie.map(ge=>t.jsxs("button",{type:"button","aria-pressed":A===ge.type,style:je(A===ge.type),onClick:()=>be(ge.type),children:[ge.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:z(ge.key).toLocaleString()})]},ge.type))]})})(),C.map(({type:z,name:ie,key:ae})=>{const be=F[ae]??[],je=ms[ae],ge=F[je]??0;if(be.length===0||A!=="all"&&A!==z)return null;const K=A==="all"&&!(D===z)&&ge>Yi;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(fn,{type:z})," ",ie,t.jsxs("span",{style:{fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:[ge," ",_.unit.items]})]}),K&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>de(z),style:{border:"none",background:"transparent",color:i("primary"),cursor:"pointer",fontSize:"12px"},children:_.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:be.map(fe=>{if(m)return t.jsx(g.Fragment,{children:m(fe)},fe.id);const Ne=u==="card"?vu:hs;return t.jsx(Ne,{entry:fe,selected:ve===fe.id,onClick:ye,getConfig:De,query:N},fe.id)})})]},z)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:i("fg")},children:mt(_.search.noResultsFor,{query:N})}),t.jsx("p",{style:{color:i("desc-fg"),fontSize:"13px"},children:_.search.tryOther})]})})]})},gu=240;function fu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const xu=`
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
- `,fu=`
123
+ `,bu=`
124
124
  .bim-ib-bar { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; padding: 0 20px 16px; }
125
125
  .bim-ib-bar[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
126
126
  .bim-ib-bar[data-nofilters] > [aria-hidden] { display: none; }
@@ -135,26 +135,26 @@
135
135
  .bim-ib-bar-main { max-width: none; }
136
136
  .bim-ib-submit { min-height: 44px; padding: 0 16px; }
137
137
  }
138
- `,xu=`
138
+ `,yu=`
139
139
  @media (max-width: 719px), (pointer: coarse) {
140
140
  .bim-ib-viewall { position: relative; }
141
141
  .bim-ib-viewall::after {
142
142
  content: ""; position: absolute; left: 50%; top: 50%;
143
143
  width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
144
144
  }
145
- }`,Ya={color:"inherit",textDecoration:"none"},bu=({snippet:e})=>{const{convert:n}=Re();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:Io(e).map((o,r)=>o.marked?t.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(o.text)},r):t.jsx(g.Fragment,{children:n(o.text)},r))})},yu=({entry:e,selected:n,onClick:o,getConfig:r,query:s})=>{const a=ze(),{convert:l}=Re(),d=l(e.title||e.primary_name||e.id),c=e.measure_info?l(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${a.unit.juan}`:"",p=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&p.length?p.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,m=i("cover-accent"),h=Je();return t.jsxs("a",{href:h(e.id),onClick:f=>o(e,f),className:"bim-result-card",style:{...Ya,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(d).map((f,x)=>t.jsx("span",{children:f},x))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",l(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:l(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",l(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",l(e.era),"〕"]}),e.edition&&t.jsx("span",{children:l(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[a.search.alias,":",l(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(bu,{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(gn,{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:a.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:a.misc.imageResource})]})]})]})},us=({entry:e,selected:n,onClick:o,getConfig:r,query:s,onRemove:a})=>{const l=ze(),{convert:d}=Re(),c=[...e.additional_titles||[],...e.attached_texts||[]],p=s&&c.length?c.find(m=>{const h=typeof m=="string"?m:m==null?void 0:m.book_title;return h==null?void 0:h.toLowerCase().includes(s.toLowerCase())}):void 0,u=Je();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${i("primary")}`:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("a",{href:u(e.id),onClick:m=>o(e,m),className:"bim-result-card",style:{...Ya,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:a?"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(gn,{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:d(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:l.misc.textResource}),e.has_image&&t.jsx("span",{children:l.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.juan_count,l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),p&&t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[l.search.alias,":",d(p)]})]}),!a&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),a&&t.jsx("button",{type:"button",onClick:()=>a(e.id),title:l.search.removeFromRecent,"aria-label":l.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:"×"})]})},ju=({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 vu(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 ku({data:e}){const{convert:n}=Re(),{dynasty:o,birth_year:r,death_year:s}=e,a=[];return o&&a.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?a.push(`${r}—${s}`):r!==void 0?a.push(`${r}—?`):s!==void 0&&a.push(`?—${s}`),a.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:a.join(" ")})}function wu({alt_names:e}){const{convert:n}=Re(),o=new Map;for(const a of e){const l=a.type||"別名";o.has(l)||o.set(l,[]),o.get(l).push(a.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((a,l)=>{const d=r.indexOf(a),c=r.indexOf(l);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(a=>{const l=o.get(a);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:n(a)}),t.jsx("span",{children:l.map((d,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},a)})})}function Su({data:e}){const n=ze(),o=e.external_ids;if(!o)return null;const r=[];return o.cbdb_id&&r.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${o.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:n.common.cbdbTitle,children:["CBDB ",o.cbdb_id]},"cbdb")),r.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:r})}function _u({works:e,transport:n,onNavigate:o,renderLink:r}){const s=ze(),{convert:a}=Re(),l=Je(),[d,c]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let h=!1;const f=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(f);let S=!0;for(let v=0;v<f.length;v++){const $=j[v];$!=null&&$.title?k.set(f[v],$.title):$!=null&&$.primary_name?k.set(f[v],$.primary_name):S=!1}if(S)return k}catch{}const y=[...f],w=8,b=new Array(w).fill(0).map(async()=>{for(;y.length;){const j=y.shift();if(!j)break;if(!k.has(j))try{if(n.getEntry){const $=await n.getEntry(j);if($!=null&&$.title){k.set(j,$.title);continue}}const S=await n.getItem(j),v=S&&(S.title||S.primary_name)||j;k.set(j,v)}catch{k.set(j,j)}}});return await Promise.all(b),k})().then(k=>{h||c(k)}),()=>{h=!0}},[e,n]);const p=new Map;for(const h of e){const f=h.role||"";p.has(f)||p.set(f,[]),p.get(f).push(h)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],m=[...p.keys()].sort((h,f)=>{const x=u.indexOf(h),k=u.indexOf(f);return x===-1&&k===-1?h.localeCompare(f):x===-1?1:k===-1?-1:x-k});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),m.map(h=>{const f=p.get(h);return t.jsxs("div",{style:{marginBottom:"8px"},children:[h&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[a(h)," ",t.jsxs("span",{style:{color:i("desc-fg")},children:["(",f.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:f.map((x,k)=>{const y=a(d.get(x.work_id)||x.work_id);return r?t.jsx("li",{children:r(x.work_id,y)},k):o?t.jsx("li",{children:t.jsx("a",{href:l(x.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),o(x.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},k):t.jsx("li",{children:y},k)})})]},h)})]})}const Ka=({data:e,transport:n,onNavigate:o,renderLink:r,headerExtra:s,hideHeader:a})=>{var m;const l=ze(),{convert:d}=Re();let c=!1;try{c=Se.extractStatus(e.id)==="draft"}catch{}const p=vu(e),u=e.subtype&&e.subtype in l.common.entitySubtype?l.common.entitySubtype[e.subtype]:d(e.subtype);return t.jsxs("div",{children:[!a&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:i("fg")},children:[d(e.primary_name),t.jsx(ku,{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:l.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:l.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),p&&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:l.common.entityPlaceholderNote}),e.alt_names&&e.alt_names.length>0&&t.jsx(wu,{alt_names:e.alt_names}),t.jsx(Su,{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:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(_u,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},$u=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function Cu(e){const n=e.search($u);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const qa={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===zu(e))){const[a,l]=Cu(n);l&&(o=encodeURI(a),s=a,r=l)}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 zu(e){try{return decodeURI(e)}catch{return e}}const Tu={...qa,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Nt=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=Re(),a=n?Tu:qa;return t.jsx("div",{className:r,style:o,children:t.jsx(tp,{remarkPlugins:[np],components:a,children:s(e)})})},Nu=["〇","一","二","三","四","五","六","七","八","九"],ms=["","十","百","千"];function Xa(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let a=0;a<o;a++){const l=parseInt(n[a]),d=o-1-a;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&d===1&&a===0?r+=ms[d]:r+=Nu[l]+ms[d])}return r}function Za(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 Eu={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function Iu({type:e}){const n=ze();return t.jsx("span",{style:Za(Eu[e]),children:n.indexType[e]})}function Ru({isDraft:e}){const n=ze(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:Za(o),children:e?n.status.draft:n.status.official})}function Lu({id:e}){const n=ze(),[o,r]=g.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:e}),t.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:a=>a.currentTarget.style.opacity="1",onMouseLeave:a=>a.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function gt({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 wt({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 Ja({authors:e,type:n,onNavigate:o,renderLink:r}){const{convert:s}=Re();return t.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:e.map((a,l)=>{const d=s(a.name),c=a.entity_id?t.jsx(jt,{id:a.entity_id,label:d,onNavigate:o,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[l>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),a.dynasty&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(a.dynasty),"〕"]}),c,a.role&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(a.role)]})]},l)})})}function jt({id:e,label:n,onNavigate:o,renderLink:r}){const s=Je();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Au({id:e,title:n,edition:o,type:r,isDraft:s,authors:a,volumeText:l,meta:d,headerExtra:c,onNavigate:p,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}),l&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:l})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Iu,{type:r}),t.jsx(Ru,{isDraft:s}),t.jsx(Lu,{id:e})]}),((a==null?void 0:a.length)||d.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[a&&a.length>0&&t.jsx(Ja,{authors:a,type:r,onNavigate:p,renderLink:u}),d]})]})}function Qa({items:e,label:n,showMeta:o,onNavigate:r,renderLink:s}){const a=ze(),{convert:l}=Re();if(!e.length)return null;const[d,c]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(gt,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((p,u)=>{const m=d===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:()=>c(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:l(p.source)}),!m&&o&&p.title_info&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(p.title_info)}),p.source_bid&&t.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(jt,{id:p.source_bid,label:a.action.view,onNavigate:r,renderLink:s})})]}),m&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[o&&(p.title_info||p.author_info||p.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[p.title_info&&t.jsx(wt,{label:a.label.titleInfo,children:l(p.title_info)}),p.author_info&&t.jsx(wt,{label:a.label.authorInfo,children:l(p.author_info)}),p.edition&&t.jsx(wt,{label:a.label.edition,children:l(p.edition)})]}),p.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:a.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:l(p.summary)})]}),p.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:a.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.comment)})]}),p.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:a.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.additional_comment)})]})]})]},u)})})]})}function Pu({items:e,onNavigate:n,renderLink:o}){const r=ze();return t.jsx(Qa,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function el({items:e,onNavigate:n,renderLink:o}){const r=ze();return t.jsx(Qa,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function tl({label:e,items:n}){const{convert:o}=Re();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(gt,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const a=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(a)},s)})})]}):null}function Mu({items:e}){const n=ze();return t.jsx(tl,{label:n.section.aliases,items:e})}function Bu({items:e}){const n=ze();return t.jsx(tl,{label:n.section.attachedTexts,items:e})}function Wu({items:e}){const n=ze(),{convert:o}=Re();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(gt,{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 Ou({items:e}){const n=ze(),{convert:o}=Re();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(gt,{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 Hu({items:e}){const n=ze(),{convert:o}=Re();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(gt,{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 hs({title:e,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:a}=Re(),[l,d]=g.useState([]);return g.useEffect(()=>{if(!n.length){d([]);return}if(!o){d(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>o.getItem(p).then(u=>({id:p,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:p})))).then(p=>{c||d(p)}),()=>{c=!0}},[n,o]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(gt,{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:(l.length?l:n.map(c=>({id:c}))).map(c=>{const p=c.edition?`${a(c.title)||c.id}(${a(c.edition)})`:a(c.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:t.jsx(jt,{id:c.id,label:p,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Gi({book:e,onNavigate:n,renderLink:o}){const r=ze(),{convert:s}=Re(),[a,l]=g.useState(!1),d=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:d&&!a?`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(jt,{id:e.id,label:c,onNavigate:n,renderLink:o})}),d&&t.jsx("span",{onClick:()=>l(p=>!p),style:{cursor:"pointer",fontSize:"10px",color:i("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:a?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:a?r.action.expand:r.action.collapse,children:"▼"})]}),d&&!a&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Bo,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Fu({ids:e,workData:n,transport:o,onNavigate:r,renderLink:s,footer:a}){const l=ze(),{convert:d}=Re(),[c,p]=g.useState([]);if(g.useEffect(()=>{if(!e.length){p([]);return}if(!o){p(e.map(k=>({id:k})));return}let x=!1;return Promise.all(e.map(k=>o.getItem(k).then(y=>({id:k,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:k})))).then(k=>{x||p(k)}),()=>{x=!0}},[e,o]),!e.length)return null;const u=c.length?c:e.map(x=>({id:x})),m=new Map(u.map(x=>[x.id,x])),h=n==null?void 0:n.version_graph,f=Du(e,h,l.common.otherVersions);return t.jsxs(t.Fragment,{children:[t.jsxs(gt,{children:[l.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),a,f.useGrouping?t.jsxs(t.Fragment,{children:[f.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:f.coreIds.map(x=>{const k=m.get(x);return k?t.jsx(Gi,{book:k,onNavigate:r,renderLink:s},x):null})}),f.groupedIds.map(x=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[d(x.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",x.ids.length,")"]}),x.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:d(x.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:x.ids.map(k=>{const y=m.get(k);return y?t.jsx(Gi,{book:y,onNavigate:r,renderLink:s},k):null})})]},x.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(x=>t.jsx(Gi,{book:x,onNavigate:r,renderLink:s},x.id))})]})}function Du(e,n,o){var w,b;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const r=(w=n.collections)==null?void 0:w[n.default_collection],s=(r==null?void 0:r.groups)??[],a=(r==null?void 0:r.book_ids)??[],l=s.length>0||a.length>0,d=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&d.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const c=new Set(s),p=new Set([...a,...d]),u=j=>{if(p.has(j))return!0;const S=n.node_groups[j];return S!=null&&c.has(S)},m=[],h=new Map,f=[];for(const j of e)if(!((b=n.excluded_books)!=null&&b.includes(j)))if(u(j))m.push(j);else{const S=n.node_groups[j];S?(h.has(S)||h.set(S,[]),h.get(S).push(j)):f.push(j)}if(f.length+[...h.values()].reduce((j,S)=>j+S.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const k=new Map((n.groups??[]).map(j=>[j.id,j])),y=[...h.entries()].map(([j,S])=>{const v=k.get(j);return{id:j,label:(v==null?void 0:v.label)??j,description:v==null?void 0:v.description,ids:S}});return f.length>0&&y.push({id:"__other__",label:o,description:void 0,ids:f}),{useGrouping:!0,coreIds:m,groupedIds:y}}function Uu({workData:e,onNavigate:n,renderLink:o}){var l,d,c,p;const r=ze(),{convert:s}=Re(),a=!!((l=e.description)!=null&&l.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:a?`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(jt,{id:e.id,label:s(e.title),onNavigate:n,renderLink:o})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:s(e.measure_info)}):((d=e.juan_count)==null?void 0:d.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[Xa(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Ja,{authors:e.authors,type:"work",onNavigate:n,renderLink:o})})]}),a&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(Nt,{text:e.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(p=e.description)!=null&&p.text?"8px":0,fontSize:"13px"},children:t.jsx(wt,{label:r.label.parentWork,children:t.jsx(jt,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Vu({items:e,onNavigate:n,renderLink:o}){const r=ze(),{convert:s}=Re();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(a=>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(jt,{id:a.id,label:s(a.title)||a.id,onNavigate:n,renderLink:o}),a.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:ut(r.catalog.volume,{n:a.volume_index})})]},a.id))}):null}const Fo=({data:e,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:a,relatedBooksFooter:l,className:d,style:c})=>{var H,N,I,L,R,P,U,q;const p=ze(),{convert:u}=Re(),[m,h]=g.useState(null),[f,x]=g.useState(!1),[k,y]=g.useState(null),[w,b]=g.useState(null),[j,S]=g.useState([]),v=e||m;if(g.useEffect(()=>{if(e||!n||!o)return;let D=!1;return x(!0),y(null),o.getItem(n).then(O=>{D||(O?h(O):y(p.misc.notFoundEntry))}).catch(O=>{D||y(O instanceof Error?O.message:p.misc.loadFailed)}).finally(()=>{D||x(!1)}),()=>{D=!0}},[e,n,o]),g.useEffect(()=>{if(!v||!o){b(null),S([]);return}let D=!1;const O=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(O?o.getItem(O).then(A=>{!D&&A&&A.type==="work"&&b(A)}).catch(()=>{}):b(null),v.type==="book"){const A=v;A.contained_in&&A.contained_in.length>0?Promise.all(A.contained_in.map(G=>{const le=typeof G=="string"?G:G.id,ne=typeof G=="string"?void 0:G.volume_index;return o.getItem(le).then(ve=>({id:le,title:ve&&ve.title||le,volume_index:ne})).catch(()=>({id:le,title:le,volume_index:ne}))})).then(G=>{D||S(G)}):S([])}else S([]);return()=>{D=!0}},[v,o]),f)return t.jsx("div",{className:d,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((D,O)=>t.jsx("div",{style:{height:O===1?"32px":"16px",width:`${D}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},O))})});if(k)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:k});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(Ka,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:a})});const $=v.type==="book"?v:null,_=v.type==="collection"?v:null,C=v.type==="work"?v:null;let M=!1;try{M=Se.extractStatus(v.id)==="draft"}catch{}let T="";v.measure_info?T=u(v.measure_info):(H=v.juan_count)!=null&&H.number?T=Xa(v.juan_count.number)+p.unit.juan:(N=v.juan_count)!=null&&N.description&&(T=u(v.juan_count.description));const z=[];return(I=v.publication_info)!=null&&I.year&&z.push(t.jsx(wt,{label:p.label.year,children:v.publication_info.year},"year")),(L=v.current_location)!=null&&L.name&&z.push(t.jsx(wt,{label:p.label.currentLocation,children:u(v.current_location.name)},"loc")),(R=v.page_count)!=null&&R.description&&z.push(t.jsx(wt,{label:p.label.pageCount,children:v.page_count.description},"page")),$!=null&&$.edition&&z.push(t.jsx(wt,{label:p.label.edition,children:u($.edition)},"ver")),C!=null&&C.parent_work&&z.push(t.jsx(wt,{label:p.label.parentWork,children:t.jsx(jt,{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&&z.push(t.jsx(wt,{label:p.label.parentWork,children:C.parent_works.map((D,O)=>t.jsxs("span",{children:[O>0&&"、",t.jsx(jt,{id:D,onNavigate:r,renderLink:s})]},D))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(Au,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:M,authors:v.authors,volumeText:T,meta:z,headerExtra:a,onNavigate:r,renderLink:s}),((P=v.description)==null?void 0:P.text)&&t.jsx(Nt,{text:v.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((D,O)=>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(D.title)}),t.jsx(Nt,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},O))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(gt,{children:p.section.containedIn}),t.jsx(Vu,{items:j,onNavigate:r,renderLink:s})]}),w&&t.jsxs(t.Fragment,{children:[t.jsx(gt,{children:p.section.belongsToWork}),t.jsx(Uu,{workData:w,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(Wu,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Mu,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Bu,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Pu,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(el,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(gt,{children:p.section.resources}),t.jsx(Bo,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),($==null?void 0:$.location_history)&&$.location_history.length>0&&t.jsx(Ou,{items:$.location_history}),(_==null?void 0:_.history)&&_.history.length>0&&t.jsx(Hu,{items:_.history}),($==null?void 0:$.related_books)&&$.related_books.length>0&&t.jsx(hs,{title:p.section.relatedVersions,ids:$.related_books,transport:o,onNavigate:r,renderLink:s}),(_==null?void 0:_.books)&&_.books.length>0&&t.jsx(hs,{title:p.section.containedBooks,ids:_.books,transport:o,onNavigate:r,renderLink:s}),(_==null?void 0:_.contained_works)&&_.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(gt,{children:[p.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",_.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.contained_works.map(D=>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(jt,{id:D.id,label:u(D.title),onNavigate:r,renderLink:s})},D.id))})]}),(((U=C==null?void 0:C.books)==null?void 0:U.length)||0)+(((q=C==null?void 0:C.collections)==null?void 0:q.length)||0)>0&&t.jsx(Fu,{ids:[...(C==null?void 0:C.books)||[],...(C==null?void 0:C.collections)||[]],workData:C??void 0,transport:o,onNavigate:r,renderLink:s,footer:l}),(C==null?void 0:C.related_works)&&C.related_works.length>0&&(()=>{const D=[],O=C.related_works.filter(oe=>oe.relation==="part_of"),A=C.related_works.filter(oe=>oe.relation==="has_part"),G=C.related_works.filter(oe=>oe.relation==="has_adaptation"),le=C.related_works.filter(oe=>oe.relation==="text_carried_by"),ne=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ve=C.related_works.filter(oe=>!oe.relation||!ne.has(oe.relation));return O.length>0&&D.push({label:p.section.belongsToWork,items:O}),A.length>0&&D.push({label:p.section.containedWorks,items:A}),G.length>0&&D.push({label:p.section.adaptations,items:G}),le.length>0&&D.push({label:p.section.derivativeWorks,items:le}),ve.length>0&&D.push({label:p.section.relatedWorks,items:ve}),D.map(oe=>t.jsxs("div",{children:[t.jsxs(gt,{children:[oe.label,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",oe.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:oe.items.map(pe=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg")},children:t.jsx(jt,{id:pe.id,label:u(pe.title),onNavigate:r,renderLink:s})},pe.id))})]},oe.label))})()]})};function Gu({data:e}){const n=ze(),{convert:o}=Re(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,a=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]}),a!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",a,"%)"]}),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 Yu({sections:e,activeSection:n,onSelect:o}){const r=ze();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>o(null),style:gs(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:gs(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 gs(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 Ku({id:e,label:n,onNavigate:o,renderLink:r}){const s=Je();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:n||e})}function qu(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 fs({book:e,onNavigate:n,renderLink:o,showVolumes:r}){const s=ze(),{convert:a}=Re(),l=e.book_id||e.work_id,d=r&&e.volumes.length>0?qu(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[a(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(p=>a(p)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:i(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),l&&t.jsx(Ku,{id:l,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!l&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Do=({data:e,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:a,style:l})=>{const d=ze(),[c,p]=g.useState(null),[u,m]=g.useState(!1),[h,f]=g.useState(null),[x,k]=g.useState(null),[y,w]=g.useState(""),b=e||c;g.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollectionCatalog))return;let _=!1;return m(!0),f(null),o.getCollectionCatalog(n).then(C=>{_||(C?p(C):f(d.catalog.notFound))}).catch(C=>{_||f(C instanceof Error?C.message:d.catalog.loadFailed)}).finally(()=>{_||m(!1)}),()=>{_=!0}},[e,n,o,d]);const j=(b==null?void 0:b.sections)&&b.sections.length>0,S=g.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const _=b.books.map(M=>M.volumes[0]).filter(M=>M!=null);return new Set(_).size<_.length},[b]),v=g.useMemo(()=>{if(!b)return[];let _=b.books;if(x&&(_=_.filter(C=>C.section===x)),y.trim()){const C=y.trim().toLowerCase();_=_.filter(M=>M.title.toLowerCase().includes(C)||M.sub_items&&M.sub_items.some(T=>T.toLowerCase().includes(C))||M.edition&&M.edition.toLowerCase().includes(C))}return _},[b,x,y]),$=g.useMemo(()=>{if(!S)return null;const _=[],C=new Map;for(const T of v){if(!T.volumes||T.volumes.length===0)continue;const z=T.volumes[0];C.has(z)||C.set(z,[]),C.get(z).push(T)}const M=[...C.keys()].sort((T,z)=>T-z);for(const T of M)_.push({volume:T,books:C.get(T)});return _},[v,S]);return u?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):h?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:h}):b?t.jsxs("div",{className:a,style:l,children:[t.jsx(Gu,{data:b}),j&&t.jsx(Yu,{sections:b.sections,activeSection:x,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:y,onChange:_=>w(_.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[v.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[$?$.map((_,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:ut(d.catalog.volume,{n:_.volume})}),_.books.map((M,T)=>t.jsx(fs,{book:M,onNavigate:r,renderLink:s,showVolumes:M.volumes.length>1},`${_.volume}-${T}`))]},`${_.volume}-${C}`)):v.map((_,C)=>t.jsx(fs,{book:_,onNavigate:r,renderLink:s,showVolumes:!0},C)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Xu="guji_markdown";function co(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 Zu=/^□\{guess=([^\s{}]+)\}/;function Ju(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function nl(e,n){let o=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
146
- `)return-1;if(s==="\\"){r++;continue}if(s==="[")o++;else if(s==="]"&&(o--,o===0))return r}return-1}function Qu(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function em(e,n){const o=e[n];if(o==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
147
- `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(o===":"&&e.startsWith(":zi[",n)){const r=nl(e,n+3);return r>n+4?{node:{type:"zi",label:Qu(e.slice(n+4,r))},end:r+1}:null}if(o==="□"&&e[n+1]==="{"){const r=Zu.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function il(e,n,o,r){const s=[];let a="";const l=()=>{if(!a)return;const d=r?a.replace(/\\?\|/g,""):a;d&&s.push({type:"text",text:d}),a=""};for(;n<e.length;){const d=e[n];if(o!==null){if(d===o)return l(),{nodes:s,end:n};if(d===`
148
- `)return null}const c=em(e,n);if(c){l(),s.push(c.node),n=c.end;continue}let p=null;if(d==="⟨"?p="⟩":d==="<"&&Ju(e,n)&&(p=">"),p){const u=il(e,n+1,p,!0);if(u){l(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}a+=d,n++}return o!==null?null:(l(),{nodes:s,end:n})}function ol(e){return il(e,0,null,!1).nodes}function tm(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function rl(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${rl(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const sl="guji-table-v1";function al(e){return!!e&&e.table_notation===sl}const nm=/^:::table(?:\{[^}]*\})?[ \t]*$/,im=/^:::[ \t]*$/;function ll(e){const n=[];let o="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const l=nl(e,r+3);if(l>r+4){o+=e.slice(r,l+1),r=l;continue}}let a=null;if(s==="⟨")a="⟩";else if(s==="<"){const l=e[r+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(a=">")}if(a){const l=e.indexOf(a,r+1);if(l>0){o+=e.slice(r,l+1),r=l;continue}}s==="|"?(n.push(o),o=""):o+=s}return n.push(o),n.map(r=>r.trim())}const om=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function rm(e){if(e==="^")return{cont:!0};const n=om.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,a=o==="_";return{cont:!1,cell:{text:a?"":o,empty:a,colspan:r,rowspan:s}}}function cl(e,n=1){const o=[],r=[],s=[];let a=[];e.forEach((d,c)=>{const p=c+n+1;let u=d.trim();if(!u)return;let m=!1;u.startsWith("!")&&(m=!0,u=u.slice(1));const h=ll(u).map(rm),f=a.map(w=>w>0),x=a.map(w=>w>0?w-1:0),k=[];let y=0;for(const w of h){if(w.cont){f[y]||o.push(`第 ${p} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:b}=w;for(let j=y;j<y+b.colspan;j++)if(f[j]){o.push(`第 ${p} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(b.rowspan>1)for(let j=y;j<y+b.colspan;j++)x[j]=b.rowspan-1;k.push(b),y+=b.colspan}for(let w=y;w<f.length;w++)f[w]&&o.push(`第 ${p} 行第 ${w+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let w=0;w<x.length;w++)x[w]===void 0&&(x[w]=0);a=x,r.push({header:m,cells:k}),s.push({width:y,line:p})});const l=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==l&&o.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${l} 不符`);return a.some(d=>d>0)&&o.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&o.push("空表"),{rows:r,columns:l,warnings:o}}function Uo(e){const n=e.split(`
145
+ }`,qa={color:"inherit",textDecoration:"none"},ju=({snippet:e})=>{const{convert:n}=Ae();return t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),lineHeight:1.6},children:Lo(e).map((o,r)=>o.marked?t.jsx("mark",{style:{background:i("highlight-bg"),color:i("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(o.text)},r):t.jsx(g.Fragment,{children:n(o.text)},r))})},vu=({entry:e,selected:n,onClick:o,getConfig:r,query:s})=>{const a=Te(),{convert:l}=Ae(),d=l(e.title||e.primary_name||e.id),c=e.measure_info?l(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${e.juan_count}${a.unit.juan}`:"",p=[...e.additional_titles||[],...e.attached_texts||[]],u=s&&p.length?p.find(f=>{const x=typeof f=="string"?f:f==null?void 0:f.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,m=i("cover-accent"),h=Ze();return t.jsxs("a",{href:h(e.id),onClick:f=>o(e,f),className:"bim-result-card",style:{...qa,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(d).map((f,x)=>t.jsx("span",{children:f},x))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:i("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",l(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:l(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",l(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",l(e.era),"〕"]}),e.edition&&t.jsx("span",{children:l(e.edition)})]}),u&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg")},children:[a.search.alias,":",l(typeof u=="string"?u:u.book_title||"")]}),e.descriptionSnippet&&t.jsx(ju,{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(fn,{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:a.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:a.misc.imageResource})]})]})]})},hs=({entry:e,selected:n,onClick:o,getConfig:r,query:s,onRemove:a})=>{const l=Te(),{convert:d}=Ae(),c=[...e.additional_titles||[],...e.attached_texts||[]],p=s&&c.length?c.find(m=>{const h=typeof m=="string"?m:m==null?void 0:m.book_title;return h==null?void 0:h.toLowerCase().includes(s.toLowerCase())}):void 0,u=Ze();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:{...qa,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:a?"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(fn,{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:d(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:l.misc.textResource}),e.has_image&&t.jsx("span",{children:l.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[e.juan_count,l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),p&&t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginTop:"2px"},children:[l.search.alias,":",d(p)]})]}),!a&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),a&&t.jsx("button",{type:"button",onClick:()=>a(e.id),title:l.search.removeFromRecent,"aria-label":l.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:"×"})]})},ku=({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 wu(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 Su({data:e}){const{convert:n}=Ae(),{dynasty:o,birth_year:r,death_year:s}=e,a=[];return o&&a.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?a.push(`${r}—${s}`):r!==void 0?a.push(`${r}—?`):s!==void 0&&a.push(`?—${s}`),a.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:i("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:a.join(" ")})}function _u({alt_names:e}){const{convert:n}=Ae(),o=new Map;for(const a of e){const l=a.type||"別名";o.has(l)||o.set(l,[]),o.get(l).push(a.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((a,l)=>{const d=r.indexOf(a),c=r.indexOf(l);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(a=>{const l=o.get(a);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:n(a)}),t.jsx("span",{children:l.map((d,c)=>t.jsxs("span",{children:[c>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},a)})})}function $u({data:e}){const n=Te(),o=e.external_ids;if(!o)return null;const r=[];return o.cbdb_id&&r.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${o.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:n.common.cbdbTitle,children:["CBDB ",o.cbdb_id]},"cbdb")),r.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:r})}function Cu({works:e,transport:n,onNavigate:o,renderLink:r}){const s=Te(),{convert:a}=Ae(),l=Ze(),[d,c]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let h=!1;const f=e.map(k=>k.work_id);return(async()=>{const k=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(f);let S=!0;for(let v=0;v<f.length;v++){const $=j[v];$!=null&&$.title?k.set(f[v],$.title):$!=null&&$.primary_name?k.set(f[v],$.primary_name):S=!1}if(S)return k}catch{}const y=[...f],w=8,b=new Array(w).fill(0).map(async()=>{for(;y.length;){const j=y.shift();if(!j)break;if(!k.has(j))try{if(n.getEntry){const $=await n.getEntry(j);if($!=null&&$.title){k.set(j,$.title);continue}}const S=await n.getItem(j),v=S&&(S.title||S.primary_name)||j;k.set(j,v)}catch{k.set(j,j)}}});return await Promise.all(b),k})().then(k=>{h||c(k)}),()=>{h=!0}},[e,n]);const p=new Map;for(const h of e){const f=h.role||"";p.has(f)||p.set(f,[]),p.get(f).push(h)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],m=[...p.keys()].sort((h,f)=>{const x=u.indexOf(h),k=u.indexOf(f);return x===-1&&k===-1?h.localeCompare(f):x===-1?1:k===-1?-1:x-k});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:i("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:i("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),m.map(h=>{const f=p.get(h);return t.jsxs("div",{style:{marginBottom:"8px"},children:[h&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"2px"},children:[a(h)," ",t.jsxs("span",{style:{color:i("desc-fg")},children:["(",f.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:f.map((x,k)=>{const y=a(d.get(x.work_id)||x.work_id);return r?t.jsx("li",{children:r(x.work_id,y)},k):o?t.jsx("li",{children:t.jsx("a",{href:l(x.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),o(x.work_id))},style:{color:i("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},k):t.jsx("li",{children:y},k)})})]},h)})]})}const Xa=({data:e,transport:n,onNavigate:o,renderLink:r,headerExtra:s,hideHeader:a})=>{var m;const l=Te(),{convert:d}=Ae();let c=!1;try{c=_e.extractStatus(e.id)==="draft"}catch{}const p=wu(e),u=e.subtype&&e.subtype in l.common.entitySubtype?l.common.entitySubtype[e.subtype]:d(e.subtype);return t.jsxs("div",{children:[!a&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[t.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:i("fg")},children:[d(e.primary_name),t.jsx(Su,{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:l.indexType.entity}),u&&e.subtype!=="people"&&t.jsx("span",{children:u}),c&&t.jsx("span",{style:{padding:"1px 6px",background:i("warn-bg"),border:`1px solid ${i("warn-border")}`,borderRadius:"2px",color:i("warn-fg")},children:l.status.draft}),t.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:e.id})]})]}),p&&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:l.common.entityPlaceholderNote}),e.alt_names&&e.alt_names.length>0&&t.jsx(_u,{alt_names:e.alt_names}),t.jsx($u,{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:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(Cu,{works:e.works,transport:n,onNavigate:o,renderLink:r})]})},zu=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function Tu(e){const n=e.search(zu);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const Za={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===Nu(e))){const[a,l]=Tu(n);l&&(o=encodeURI(a),s=a,r=l)}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 Nu(e){try{return decodeURI(e)}catch{return e}}const Ru={...Za,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Tt=({text:e,plainStrong:n,style:o,className:r})=>{const{convert:s}=Ae(),a=n?Ru:Za;return t.jsx("div",{className:r,style:o,children:t.jsx(ip,{remarkPlugins:[op],components:a,children:s(e)})})},Eu=["〇","一","二","三","四","五","六","七","八","九"],gs=["","十","百","千"];function Ja(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let a=0;a<o;a++){const l=parseInt(n[a]),d=o-1-a;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&d===1&&a===0?r+=gs[d]:r+=Eu[l]+gs[d])}return r}function Qa(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 Iu={book:i("type-book"),work:i("type-work"),collection:i("type-collection"),entity:i("type-entity")};function Lu({type:e}){const n=Te();return t.jsx("span",{style:Qa(Iu[e]),children:n.indexType[e]})}function Au({isDraft:e}){const n=Te(),o=i(e?"status-draft":"status-official");return t.jsx("span",{style:Qa(o),children:e?n.status.draft:n.status.official})}function Pu({id:e}){const n=Te(),[o,r]=g.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:i("desc-fg"),background:i("bg-subtle"),border:`1px solid ${i("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:i("fg")},children:e}),t.jsx("span",{onClick:s,title:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:a=>a.currentTarget.style.opacity="1",onMouseLeave:a=>a.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ft({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 kt({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 el({authors:e,type:n,onNavigate:o,renderLink:r}){const{convert:s}=Ae();return t.jsx("span",{style:{fontSize:"14px",color:i("fg"),lineHeight:1.6},children:e.map((a,l)=>{const d=s(a.name),c=a.entity_id?t.jsx(yt,{id:a.entity_id,label:d,onNavigate:o,renderLink:r}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[l>0&&t.jsx("span",{style:{color:i("desc-fg"),margin:"0 4px"},children:"·"}),a.dynasty&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px"},children:["〔",s(a.dynasty),"〕"]}),c,a.role&&t.jsxs("span",{style:{color:i("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(a.role)]})]},l)})})}function yt({id:e,label:n,onNavigate:o,renderLink:r}){const s=Ze();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{children:n||e})}function Mu({id:e,title:n,edition:o,type:r,isDraft:s,authors:a,volumeText:l,meta:d,headerExtra:c,onNavigate:p,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}),l&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:l})]}),c&&t.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[t.jsx(Lu,{type:r}),t.jsx(Au,{isDraft:s}),t.jsx(Pu,{id:e})]}),((a==null?void 0:a.length)||d.length>0)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[a&&a.length>0&&t.jsx(el,{authors:a,type:r,onNavigate:p,renderLink:u}),d]})]})}function tl({items:e,label:n,showMeta:o,onNavigate:r,renderLink:s}){const a=Te(),{convert:l}=Ae();if(!e.length)return null;const[d,c]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(ft,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((p,u)=>{const m=d===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:()=>c(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:l(p.source)}),!m&&o&&p.title_info&&t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(p.title_info)}),p.source_bid&&t.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(yt,{id:p.source_bid,label:a.action.view,onNavigate:r,renderLink:s})})]}),m&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${i("widget-border")}`},children:[o&&(p.title_info||p.author_info||p.edition)&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[p.title_info&&t.jsx(kt,{label:a.label.titleInfo,children:l(p.title_info)}),p.author_info&&t.jsx(kt,{label:a.label.authorInfo,children:l(p.author_info)}),p.edition&&t.jsx(kt,{label:a.label.edition,children:l(p.edition)})]}),p.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:a.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:l(p.summary)})]}),p.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:a.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.comment)})]}),p.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:a.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.additional_comment)})]})]})]},u)})})]})}function Bu({items:e,onNavigate:n,renderLink:o}){const r=Te();return t.jsx(tl,{items:e,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function nl({items:e,onNavigate:n,renderLink:o}){const r=Te();return t.jsx(tl,{items:e,label:r.section.emendated,onNavigate:n,renderLink:o})}function il({label:e,items:n}){const{convert:o}=Ae();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(ft,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const a=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(a)},s)})})]}):null}function Wu({items:e}){const n=Te();return t.jsx(il,{label:n.section.aliases,items:e})}function Ou({items:e}){const n=Te();return t.jsx(il,{label:n.section.attachedTexts,items:e})}function Hu({items:e}){const n=Te(),{convert:o}=Ae();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(ft,{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 Fu({items:e}){const n=Te(),{convert:o}=Ae();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(ft,{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 Du({items:e}){const n=Te(),{convert:o}=Ae();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(ft,{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 fs({title:e,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:a}=Ae(),[l,d]=g.useState([]);return g.useEffect(()=>{if(!n.length){d([]);return}if(!o){d(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>o.getItem(p).then(u=>({id:p,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:p})))).then(p=>{c||d(p)}),()=>{c=!0}},[n,o]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(ft,{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:(l.length?l:n.map(c=>({id:c}))).map(c=>{const p=c.edition?`${a(c.title)||c.id}(${a(c.edition)})`:a(c.title)||void 0;return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),transition:"border-color 0.15s"},children:t.jsx(yt,{id:c.id,label:p,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Ki({book:e,onNavigate:n,renderLink:o}){const r=Te(),{convert:s}=Ae(),[a,l]=g.useState(!1),d=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:i("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:d&&!a?`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(yt,{id:e.id,label:c,onNavigate:n,renderLink:o})}),d&&t.jsx("span",{onClick:()=>l(p=>!p),style:{cursor:"pointer",fontSize:"10px",color:i("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:a?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:a?r.action.expand:r.action.collapse,children:"▼"})]}),d&&!a&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Oo,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Uu({ids:e,workData:n,transport:o,onNavigate:r,renderLink:s,footer:a}){const l=Te(),{convert:d}=Ae(),[c,p]=g.useState([]);if(g.useEffect(()=>{if(!e.length){p([]);return}if(!o){p(e.map(k=>({id:k})));return}let x=!1;return Promise.all(e.map(k=>o.getItem(k).then(y=>({id:k,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:k})))).then(k=>{x||p(k)}),()=>{x=!0}},[e,o]),!e.length)return null;const u=c.length?c:e.map(x=>({id:x})),m=new Map(u.map(x=>[x.id,x])),h=n==null?void 0:n.version_graph,f=Vu(e,h,l.common.otherVersions);return t.jsxs(t.Fragment,{children:[t.jsxs(ft,{children:[l.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),a,f.useGrouping?t.jsxs(t.Fragment,{children:[f.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:f.coreIds.map(x=>{const k=m.get(x);return k?t.jsx(Ki,{book:k,onNavigate:r,renderLink:s},x):null})}),f.groupedIds.map(x=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${i("widget-border")}`,borderRadius:6,background:i("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:i("fg"),userSelect:"none"},children:[d(x.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:i("desc-fg"),fontWeight:400},children:["(",x.ids.length,")"]}),x.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:i("desc-fg"),fontWeight:400},children:d(x.description)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:x.ids.map(k=>{const y=m.get(k);return y?t.jsx(Ki,{book:y,onNavigate:r,renderLink:s},k):null})})]},x.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(x=>t.jsx(Ki,{book:x,onNavigate:r,renderLink:s},x.id))})]})}function Vu(e,n,o){var w,b;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const r=(w=n.collections)==null?void 0:w[n.default_collection],s=(r==null?void 0:r.groups)??[],a=(r==null?void 0:r.book_ids)??[],l=s.length>0||a.length>0,d=!l&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!l&&d.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const c=new Set(s),p=new Set([...a,...d]),u=j=>{if(p.has(j))return!0;const S=n.node_groups[j];return S!=null&&c.has(S)},m=[],h=new Map,f=[];for(const j of e)if(!((b=n.excluded_books)!=null&&b.includes(j)))if(u(j))m.push(j);else{const S=n.node_groups[j];S?(h.has(S)||h.set(S,[]),h.get(S).push(j)):f.push(j)}if(f.length+[...h.values()].reduce((j,S)=>j+S.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const k=new Map((n.groups??[]).map(j=>[j.id,j])),y=[...h.entries()].map(([j,S])=>{const v=k.get(j);return{id:j,label:(v==null?void 0:v.label)??j,description:v==null?void 0:v.description,ids:S}});return f.length>0&&y.push({id:"__other__",label:o,description:void 0,ids:f}),{useGrouping:!0,coreIds:m,groupedIds:y}}function Gu({workData:e,onNavigate:n,renderLink:o}){var l,d,c,p;const r=Te(),{convert:s}=Ae(),a=!!((l=e.description)!=null&&l.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:a?`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(yt,{id:e.id,label:s(e.title),onNavigate:n,renderLink:o})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:s(e.measure_info)}):((d=e.juan_count)==null?void 0:d.number)!=null&&e.juan_count.number>0?t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[Ja(e.juan_count.number),r.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(el,{authors:e.authors,type:"work",onNavigate:n,renderLink:o})})]}),a&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(Tt,{text:e.description.text,style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,textAlign:"justify"}}),e.parent_work&&t.jsx("div",{style:{marginTop:(p=e.description)!=null&&p.text?"8px":0,fontSize:"13px"},children:t.jsx(kt,{label:r.label.parentWork,children:t.jsx(yt,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Yu({items:e,onNavigate:n,renderLink:o}){const r=Te(),{convert:s}=Ae();return e.length?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:e.map(a=>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(yt,{id:a.id,label:s(a.title)||a.id,onNavigate:n,renderLink:o}),a.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"2px"},children:mt(r.catalog.volume,{n:a.volume_index})})]},a.id))}):null}const Uo=({data:e,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:a,relatedBooksFooter:l,className:d,style:c})=>{var F,R,E,L,I,P,V,X;const p=Te(),{convert:u}=Ae(),[m,h]=g.useState(null),[f,x]=g.useState(!1),[k,y]=g.useState(null),[w,b]=g.useState(null),[j,S]=g.useState([]),v=e||m;if(g.useEffect(()=>{if(e||!n||!o)return;let D=!1;return x(!0),y(null),o.getItem(n).then(O=>{D||(O?h(O):y(p.misc.notFoundEntry))}).catch(O=>{D||y(O instanceof Error?O.message:p.misc.loadFailed)}).finally(()=>{D||x(!1)}),()=>{D=!0}},[e,n,o]),g.useEffect(()=>{if(!v||!o){b(null),S([]);return}let D=!1;const O=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(O?o.getItem(O).then(A=>{!D&&A&&A.type==="work"&&b(A)}).catch(()=>{}):b(null),v.type==="book"){const A=v;A.contained_in&&A.contained_in.length>0?Promise.all(A.contained_in.map(G=>{const se=typeof G=="string"?G:G.id,Q=typeof G=="string"?void 0:G.volume_index;return o.getItem(se).then(ve=>({id:se,title:ve&&ve.title||se,volume_index:Q})).catch(()=>({id:se,title:se,volume_index:Q}))})).then(G=>{D||S(G)}):S([])}else S([]);return()=>{D=!0}},[v,o]),f)return t.jsx("div",{className:d,style:{...c,padding:"24px"},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((D,O)=>t.jsx("div",{style:{height:O===1?"32px":"16px",width:`${D}px`,background:i("widget-border"),borderRadius:"4px",opacity:.4}},O))})});if(k)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:k});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(Xa,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:a})});const $=v.type==="book"?v:null,_=v.type==="collection"?v:null,C=v.type==="work"?v:null;let M=!1;try{M=_e.extractStatus(v.id)==="draft"}catch{}let N="";v.measure_info?N=u(v.measure_info):(F=v.juan_count)!=null&&F.number?N=Ja(v.juan_count.number)+p.unit.juan:(R=v.juan_count)!=null&&R.description&&(N=u(v.juan_count.description));const T=[];return(E=v.publication_info)!=null&&E.year&&T.push(t.jsx(kt,{label:p.label.year,children:v.publication_info.year},"year")),(L=v.current_location)!=null&&L.name&&T.push(t.jsx(kt,{label:p.label.currentLocation,children:u(v.current_location.name)},"loc")),(I=v.page_count)!=null&&I.description&&T.push(t.jsx(kt,{label:p.label.pageCount,children:v.page_count.description},"page")),$!=null&&$.edition&&T.push(t.jsx(kt,{label:p.label.edition,children:u($.edition)},"ver")),C!=null&&C.parent_work&&T.push(t.jsx(kt,{label:p.label.parentWork,children:t.jsx(yt,{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(kt,{label:p.label.parentWork,children:C.parent_works.map((D,O)=>t.jsxs("span",{children:[O>0&&"、",t.jsx(yt,{id:D,onNavigate:r,renderLink:s})]},D))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(Mu,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:M,authors:v.authors,volumeText:N,meta:T,headerExtra:a,onNavigate:r,renderLink:s}),((P=v.description)==null?void 0:P.text)&&t.jsx(Tt,{text:v.description.text,style:{fontSize:"14px",color:i("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((D,O)=>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(D.title)}),t.jsx(Tt,{text:D.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:i("fg")}})]},O))}),j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(ft,{children:p.section.containedIn}),t.jsx(Yu,{items:j,onNavigate:r,renderLink:s})]}),w&&t.jsxs(t.Fragment,{children:[t.jsx(ft,{children:p.section.belongsToWork}),t.jsx(Gu,{workData:w,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(Hu,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Wu,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Ou,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Bu,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(nl,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(ft,{children:p.section.resources}),t.jsx(Oo,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),($==null?void 0:$.location_history)&&$.location_history.length>0&&t.jsx(Fu,{items:$.location_history}),(_==null?void 0:_.history)&&_.history.length>0&&t.jsx(Du,{items:_.history}),($==null?void 0:$.related_books)&&$.related_books.length>0&&t.jsx(fs,{title:p.section.relatedVersions,ids:$.related_books,transport:o,onNavigate:r,renderLink:s}),(_==null?void 0:_.books)&&_.books.length>0&&t.jsx(fs,{title:p.section.containedBooks,ids:_.books,transport:o,onNavigate:r,renderLink:s}),(_==null?void 0:_.contained_works)&&_.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(ft,{children:[p.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",_.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.contained_works.map(D=>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(yt,{id:D.id,label:u(D.title),onNavigate:r,renderLink:s})},D.id))})]}),(((V=C==null?void 0:C.books)==null?void 0:V.length)||0)+(((X=C==null?void 0:C.collections)==null?void 0:X.length)||0)>0&&t.jsx(Uu,{ids:[...(C==null?void 0:C.books)||[],...(C==null?void 0:C.collections)||[]],workData:C??void 0,transport:o,onNavigate:r,renderLink:s,footer:l}),(C==null?void 0:C.related_works)&&C.related_works.length>0&&(()=>{const D=[],O=C.related_works.filter(ne=>ne.relation==="part_of"),A=C.related_works.filter(ne=>ne.relation==="has_part"),G=C.related_works.filter(ne=>ne.relation==="has_adaptation"),se=C.related_works.filter(ne=>ne.relation==="text_carried_by"),Q=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ve=C.related_works.filter(ne=>!ne.relation||!Q.has(ne.relation));return O.length>0&&D.push({label:p.section.belongsToWork,items:O}),A.length>0&&D.push({label:p.section.containedWorks,items:A}),G.length>0&&D.push({label:p.section.adaptations,items:G}),se.length>0&&D.push({label:p.section.derivativeWorks,items:se}),ve.length>0&&D.push({label:p.section.relatedWorks,items:ve}),D.map(ne=>t.jsxs("div",{children:[t.jsxs(ft,{children:[ne.label,t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg"),fontWeight:400},children:["(",ne.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ne.items.map(ce=>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(yt,{id:ce.id,label:u(ce.title),onNavigate:r,renderLink:s})},ce.id))})]},ne.label))})()]})};function Ku({data:e}){const n=Te(),{convert:o}=Ae(),{stats:r}=e,s=r.processed_volumes??r.total_found_volumes,a=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]}),a!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:i("fg")},children:s})," ",n.unit.volume," (",a,"%)"]}),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 qu({sections:e,activeSection:n,onSelect:o}){const r=Te();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>o(null),style:xs(n===null),children:r.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>o(s.name),style:xs(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 xs(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 Xu({id:e,label:n,onNavigate:o,renderLink:r}){const s=Ze();return r?t.jsx(t.Fragment,{children:r(e,n)}):o?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o(e))},style:{color:i("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:n||e}):t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg")},children:n||e})}function Zu(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 bs({book:e,onNavigate:n,renderLink:o,showVolumes:r}){const s=Te(),{convert:a}=Ae(),l=e.book_id||e.work_id,d=r&&e.volumes.length>0?Zu(e.volumes,s.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${i("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:i("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:i("fg")},children:[a(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(p=>a(p)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:i(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),l&&t.jsx(Xu,{id:l,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!l&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const Vo=({data:e,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:a,style:l})=>{const d=Te(),[c,p]=g.useState(null),[u,m]=g.useState(!1),[h,f]=g.useState(null),[x,k]=g.useState(null),[y,w]=g.useState(""),b=e||c;g.useEffect(()=>{if(e||!n||!(o!=null&&o.getCollectionCatalog))return;let _=!1;return m(!0),f(null),o.getCollectionCatalog(n).then(C=>{_||(C?p(C):f(d.catalog.notFound))}).catch(C=>{_||f(C instanceof Error?C.message:d.catalog.loadFailed)}).finally(()=>{_||m(!1)}),()=>{_=!0}},[e,n,o,d]);const j=(b==null?void 0:b.sections)&&b.sections.length>0,S=g.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const _=b.books.map(M=>M.volumes[0]).filter(M=>M!=null);return new Set(_).size<_.length},[b]),v=g.useMemo(()=>{if(!b)return[];let _=b.books;if(x&&(_=_.filter(C=>C.section===x)),y.trim()){const C=y.trim().toLowerCase();_=_.filter(M=>M.title.toLowerCase().includes(C)||M.sub_items&&M.sub_items.some(N=>N.toLowerCase().includes(C))||M.edition&&M.edition.toLowerCase().includes(C))}return _},[b,x,y]),$=g.useMemo(()=>{if(!S)return null;const _=[],C=new Map;for(const N of v){if(!N.volumes||N.volumes.length===0)continue;const T=N.volumes[0];C.has(T)||C.set(T,[]),C.get(T).push(N)}const M=[...C.keys()].sort((N,T)=>N-T);for(const N of M)_.push({volume:N,books:C.get(N)});return _},[v,S]);return u?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:i("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):h?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:h}):b?t.jsxs("div",{className:a,style:l,children:[t.jsx(Ku,{data:b}),j&&t.jsx(qu,{sections:b.sections,activeSection:x,onSelect:k}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:y,onChange:_=>w(_.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:i("desc-fg")},children:[v.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[$?$.map((_,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:mt(d.catalog.volume,{n:_.volume})}),_.books.map((M,N)=>t.jsx(bs,{book:M,onNavigate:r,renderLink:s,showVolumes:M.volumes.length>1},`${_.volume}-${N}`))]},`${_.volume}-${C}`)):v.map((_,C)=>t.jsx(bs,{book:_,onNavigate:r,renderLink:s,showVolumes:!0},C)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Ju="guji_markdown";function uo(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 Qu=/^□\{guess=([^\s{}]+)\}/;function em(e,n){const o=e[n+1];return o!==void 0&&!/[A-Za-z/!?>\s]/.test(o)}function ol(e,n){let o=0;for(let r=n;r<e.length;r++){const s=e[r];if(s===`
146
+ `)return-1;if(s==="\\"){r++;continue}if(s==="[")o++;else if(s==="]"&&(o--,o===0))return r}return-1}function tm(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function nm(e,n){const o=e[n];if(o==="["&&e[n+1]==="["){const r=e.indexOf("]]",n+2);return r>=0&&e.slice(n+2,r).indexOf(`
147
+ `)<0?{node:{type:"qw",label:e.slice(n+2,r)},end:r+2}:null}if(o===":"&&e.startsWith(":zi[",n)){const r=ol(e,n+3);return r>n+4?{node:{type:"zi",label:tm(e.slice(n+4,r))},end:r+1}:null}if(o==="□"&&e[n+1]==="{"){const r=Qu.exec(e.slice(n,n+64));if(r)return{node:{type:"qz",guess:r[1]},end:n+r[0].length}}return null}function rl(e,n,o,r){const s=[];let a="";const l=()=>{if(!a)return;const d=r?a.replace(/\\?\|/g,""):a;d&&s.push({type:"text",text:d}),a=""};for(;n<e.length;){const d=e[n];if(o!==null){if(d===o)return l(),{nodes:s,end:n};if(d===`
148
+ `)return null}const c=nm(e,n);if(c){l(),s.push(c.node),n=c.end;continue}let p=null;if(d==="⟨"?p="⟩":d==="<"&&em(e,n)&&(p=">"),p){const u=rl(e,n+1,p,!0);if(u){l(),s.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}a+=d,n++}return o!==null?null:(l(),{nodes:s,end:n})}function sl(e){return rl(e,0,null,!1).nodes}function im(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function al(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${al(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const ll="guji-table-v1";function cl(e){return!!e&&e.table_notation===ll}const om=/^:::table(?:\{[^}]*\})?[ \t]*$/,rm=/^:::[ \t]*$/;function dl(e){const n=[];let o="";for(let r=0;r<e.length;r++){const s=e[r];if(s===":"&&e.startsWith(":zi[",r)){const l=ol(e,r+3);if(l>r+4){o+=e.slice(r,l+1),r=l;continue}}let a=null;if(s==="⟨")a="⟩";else if(s==="<"){const l=e[r+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(a=">")}if(a){const l=e.indexOf(a,r+1);if(l>0){o+=e.slice(r,l+1),r=l;continue}}s==="|"?(n.push(o),o=""):o+=s}return n.push(o),n.map(r=>r.trim())}const sm=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function am(e){if(e==="^")return{cont:!0};const n=sm.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,a=o==="_";return{cont:!1,cell:{text:a?"":o,empty:a,colspan:r,rowspan:s}}}function pl(e,n=1){const o=[],r=[],s=[];let a=[];e.forEach((d,c)=>{const p=c+n+1;let u=d.trim();if(!u)return;let m=!1;u.startsWith("!")&&(m=!0,u=u.slice(1));const h=dl(u).map(am),f=a.map(w=>w>0),x=a.map(w=>w>0?w-1:0),k=[];let y=0;for(const w of h){if(w.cont){f[y]||o.push(`第 ${p} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:b}=w;for(let j=y;j<y+b.colspan;j++)if(f[j]){o.push(`第 ${p} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(b.rowspan>1)for(let j=y;j<y+b.colspan;j++)x[j]=b.rowspan-1;k.push(b),y+=b.colspan}for(let w=y;w<f.length;w++)f[w]&&o.push(`第 ${p} 行第 ${w+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let w=0;w<x.length;w++)x[w]===void 0&&(x[w]=0);a=x,r.push({header:m,cells:k}),s.push({width:y,line:p})});const l=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==l&&o.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${l} 不符`);return a.some(d=>d>0)&&o.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&o.push("空表"),{rows:r,columns:l,warnings:o}}function Go(e){const n=e.split(`
149
149
  `),o=[];let r=[];const s=()=>{if(r.length===0)return;const l=r.join(`
150
- `);r=[],o.push({type:"text",text:l})};let a=0;for(;a<n.length;){if(nm.test(n[a].trim())){let l=a+1;for(;l<n.length&&!im.test(n[l].trim());)l++;if(l<n.length){s();const d=n.slice(a+1,l);o.push({type:"table",table:cl(d,a+1),source:n.slice(a,l+1).join(`
151
- `)}),a=l+1;continue}}r.push(n[a]),a++}return s(),o.map((l,d)=>{var p,u;if(l.type!=="text")return l;let c=l.text;return((p=o[d-1])==null?void 0:p.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=o[d+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(l=>l.type!=="text"||l.text!=="")}const Yi=e=>e?e.catch(()=>null):Promise.resolve(null);function dl(e){const n=new Map;function o(r){var a;let s=n.get(r);return s||(s=Yi((a=e.getTextManifest)==null?void 0:a.call(e,r)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||n.delete(r),d}),n.set(r,s)),s}return{getManifest(r){return Se.isSafeSegment(r)?o(r):Promise.resolve(null)},async getIndex(r,s){return!Se.isSafeSegment(r)||!Se.isSafeSegment(s)||!e.getTextIndex?null:Yi(e.getTextIndex(r,s))},async getChapter(r,s,a,l){return!Se.isSafeSegment(r)||!Se.isSafeSegment(s)||!Se.isSafeSegment(a)||!e.getChapter?null:Yi(e.getChapter(r,s,a,l))}}}const Xt=()=>{const{t:e}=J(),[n,o]=g.useState(1);return g.useEffect(()=>{const r=setInterval(()=>o(s=>s>=3?1:s+1),500);return()=>clearInterval(r)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(n)})},Ki=String.raw`https?:\/\/[^\s()()<>"]+`,sm=new RegExp(String.raw`\[([^\]\n]+)\]\((${Ki})\)`+String.raw`|(《[^》\n]+》)\s?[((](${Ki})[))]`+`|(${Ki})`,"g");function am(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function lm(e){const n=[];let o=0;for(const r of e.matchAll(sm)){const s=r.index??0;s>o&&n.push({text:e.slice(o,s)}),r[1]!==void 0?n.push({text:r[1],url:r[2]}):r[3]!==void 0?n.push({text:r[3],url:r[4]}):n.push({text:am(r[5]),url:r[5]}),o=s+r[0].length}return o<e.length&&n.push({text:e.slice(o)}),n}function pl({text:e,convert:n,className:o="bim-rd-link"}){return t.jsx(t.Fragment,{children:lm(e).map((r,s)=>r.url?t.jsx("a",{className:o,href:r.url,target:"_blank",rel:"noopener noreferrer",children:n(r.text)},s):t.jsx(g.Fragment,{children:n(r.text)},s))})}const ul="(min-width: 1100px)",ml="(max-width: 719px)",hl="(max-width: 859px)",cm=`${ml}, (pointer: coarse)`,Rt=i("reader-top"),dm="48px",gl=`
150
+ `);r=[],o.push({type:"text",text:l})};let a=0;for(;a<n.length;){if(om.test(n[a].trim())){let l=a+1;for(;l<n.length&&!rm.test(n[l].trim());)l++;if(l<n.length){s();const d=n.slice(a+1,l);o.push({type:"table",table:pl(d,a+1),source:n.slice(a,l+1).join(`
151
+ `)}),a=l+1;continue}}r.push(n[a]),a++}return s(),o.map((l,d)=>{var p,u;if(l.type!=="text")return l;let c=l.text;return((p=o[d-1])==null?void 0:p.type)==="table"&&(c=c.replace(/^\n+/,"")),((u=o[d+1])==null?void 0:u.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(l=>l.type!=="text"||l.text!=="")}const qi=e=>e?e.catch(()=>null):Promise.resolve(null);function ul(e){const n=new Map;function o(r){var a;let s=n.get(r);return s||(s=qi((a=e.getTextManifest)==null?void 0:a.call(e,r)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||n.delete(r),d}),n.set(r,s)),s}return{getManifest(r){return _e.isSafeSegment(r)?o(r):Promise.resolve(null)},async getIndex(r,s){return!_e.isSafeSegment(r)||!_e.isSafeSegment(s)||!e.getTextIndex?null:qi(e.getTextIndex(r,s))},async getChapter(r,s,a,l){return!_e.isSafeSegment(r)||!_e.isSafeSegment(s)||!_e.isSafeSegment(a)||!e.getChapter?null:qi(e.getChapter(r,s,a,l))}}}const Zt=()=>{const{t:e}=J(),[n,o]=g.useState(1);return g.useEffect(()=>{const r=setInterval(()=>o(s=>s>=3?1:s+1),500);return()=>clearInterval(r)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:i("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(n)})},Xi=String.raw`https?:\/\/[^\s()()<>"]+`,lm=new RegExp(String.raw`\[([^\]\n]+)\]\((${Xi})\)`+String.raw`|(《[^》\n]+》)\s?[((](${Xi})[))]`+`|(${Xi})`,"g");function cm(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function dm(e){const n=[];let o=0;for(const r of e.matchAll(lm)){const s=r.index??0;s>o&&n.push({text:e.slice(o,s)}),r[1]!==void 0?n.push({text:r[1],url:r[2]}):r[3]!==void 0?n.push({text:r[3],url:r[4]}):n.push({text:cm(r[5]),url:r[5]}),o=s+r[0].length}return o<e.length&&n.push({text:e.slice(o)}),n}function ml({text:e,convert:n,className:o="bim-rd-link"}){return t.jsx(t.Fragment,{children:dm(e).map((r,s)=>r.url?t.jsx("a",{className:o,href:r.url,target:"_blank",rel:"noopener noreferrer",children:n(r.text)},s):t.jsx(g.Fragment,{children:n(r.text)},s))})}const hl="(min-width: 1100px)",gl="(max-width: 719px)",fl="(max-width: 859px)",pm=`${gl}, (pointer: coarse)`,Lt=i("reader-top"),um="48px",xl=`
152
152
  .bim-rd {
153
153
  position: relative;
154
154
  background: ${i("page-bg")};
155
155
  color: ${i("ink")};
156
156
  font-family: ${i("font-ui")};
157
- --bimrd-bar-h: ${dm};
157
+ --bimrd-bar-h: ${um};
158
158
  }
159
159
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
160
160
 
@@ -180,7 +180,7 @@
180
180
 
181
181
  /* ── 工具条:文字 + 图标,不画按钮外框 ── */
182
182
  .bim-rd-bar {
183
- position: sticky; top: ${Rt}; z-index: 30;
183
+ position: sticky; top: ${Lt}; z-index: 30;
184
184
  height: var(--bimrd-bar-h);
185
185
  display: flex; align-items: center; gap: 16px;
186
186
  padding: 0 20px;
@@ -235,14 +235,14 @@
235
235
  display: grid;
236
236
  grid-template-columns: auto auto minmax(0, 1fr);
237
237
  align-items: start;
238
- min-height: calc(100vh - ${Rt} - var(--bimrd-bar-h));
238
+ min-height: calc(100vh - ${Lt} - var(--bimrd-bar-h));
239
239
  }
240
240
 
241
241
  /* 目录:宽屏是侧栏 */
242
242
  .bim-rd-toc {
243
243
  grid-column: 1;
244
- position: sticky; top: calc(${Rt} + var(--bimrd-bar-h));
245
- width: 248px; height: calc(100vh - ${Rt} - var(--bimrd-bar-h));
244
+ position: sticky; top: calc(${Lt} + var(--bimrd-bar-h));
245
+ width: 248px; height: calc(100vh - ${Lt} - var(--bimrd-bar-h));
246
246
  overflow-y: auto; overscroll-behavior: contain;
247
247
  padding: 0 10px 40px;
248
248
  background: ${i("sidebar-bg")};
@@ -279,8 +279,8 @@
279
279
  /* 书影:正文左侧 */
280
280
  .bim-rd-img {
281
281
  grid-column: 2;
282
- position: sticky; top: calc(${Rt} + var(--bimrd-bar-h));
283
- width: clamp(300px, 32vw, 560px); height: calc(100vh - ${Rt} - var(--bimrd-bar-h));
282
+ position: sticky; top: calc(${Lt} + var(--bimrd-bar-h));
283
+ width: clamp(300px, 32vw, 560px); height: calc(100vh - ${Lt} - var(--bimrd-bar-h));
284
284
  padding: 16px 0 16px 20px;
285
285
  display: flex; flex-direction: column; gap: 8px;
286
286
  }
@@ -291,7 +291,7 @@
291
291
  display: flex; align-items: center; justify-content: center; overflow: hidden;
292
292
  }
293
293
  .bim-rd-img-fig { position: relative; margin: 0; max-width: 100%; max-height: 100%; }
294
- .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${Rt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
294
+ .bim-rd-img-fig img { display: block; max-width: 100%; max-height: calc(100vh - ${Lt} - var(--bimrd-bar-h) - 80px); object-fit: contain; }
295
295
  .bim-rd-img-fig svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
296
296
  .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")}; }
297
297
  .bim-rd-img-empty b { font-size: 15px; font-weight: 500; color: ${i("quiet-fg")}; }
@@ -387,7 +387,7 @@
387
387
 
388
388
  /* 竖排(预留):只在宿主打开 allowVertical 时可切换 */
389
389
  .bim-rd-vertical .bim-rd-prose {
390
- writing-mode: vertical-rl; max-height: calc(100vh - ${Rt} - var(--bimrd-bar-h) - 120px);
390
+ writing-mode: vertical-rl; max-height: calc(100vh - ${Lt} - var(--bimrd-bar-h) - 120px);
391
391
  overflow-x: auto; text-align: start;
392
392
  }
393
393
 
@@ -444,7 +444,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
444
444
  .bim-rd-sheet-img .bim-rd-img-fig img { max-height: 60vh; }
445
445
  .bim-rd-sheet-fs { display: flex; align-items: center; justify-content: center; gap: 24px; padding: 8px 0 12px; font-size: 15px; color: ${i("ink")}; }
446
446
  .bim-rd-sheet-fs .bim-rd-t { min-width: 56px; min-height: 44px; justify-content: center; font-size: 17px; border: 1px solid ${i("rule")}; }
447
- @media ${hl} {
447
+ @media ${fl} {
448
448
  .bim-rd[data-bb] .bim-rd-text { padding-bottom: calc(56px + 64px + env(safe-area-inset-bottom, 0px)); }
449
449
  /* 底栏上已有的,工具条上不再重复(目录、字号) */
450
450
  .bim-rd[data-bb] .bim-rd-bb-dup { display: none !important; }
@@ -454,7 +454,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
454
454
 
455
455
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
456
456
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
457
- @media ${cm} {
457
+ @media ${pm} {
458
458
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
459
459
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
460
460
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -467,7 +467,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
467
467
  }
468
468
 
469
469
  /* ── 中屏以下:目录改抽屉 ── */
470
- @media not all and ${ul} {
470
+ @media not all and ${hl} {
471
471
  .bim-rd-toc {
472
472
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
473
473
  width: min(86vw, 320px);
@@ -481,7 +481,7 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
481
481
  }
482
482
 
483
483
  /* ── 窄屏:书影收起,只留正文 ── */
484
- @media ${ml} {
484
+ @media ${gl} {
485
485
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
486
486
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
487
487
  /* 工具条放不下时(版本、自然段、标出作品链接都在)在条内左右滑,不撑宽页面 */
@@ -634,12 +634,12 @@ button.bim-rd-pg:hover { border-color: ${i("accent")}; }
634
634
  letter-spacing: 0.05em;
635
635
  margin-left: 6px;
636
636
  }
637
- `;function Vo(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>Vo(r,n))):!1}const pm=()=>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 um({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=Vo(e,n),[a,l]=g.useState(s||!!e.defaultExpanded);return g.useEffect(()=>{s&&l(!0)},[s]),g.useEffect(()=>{e.defaultExpanded&&l(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":a,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>l(d=>!d),children:[t.jsx(pm,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),a&&t.jsx(fl,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function fl({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(um,{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 xs(e,n){var o;for(const r of e)if(r.key===n||Vo(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function xl({items:e,activeKey:n,onSelect:o,label:r}){const{t:s}=J(),a=r??s("reader.toc"),l=g.useRef(null),[d,c]=g.useState(null);g.useEffect(()=>{c(null)},[n]);const p=g.useMemo(()=>d||(n??xs(e,n)),[d,n,e]);g.useEffect(()=>{const m=l.current;if(!m)return;const h=Array.from(m.querySelectorAll("[data-rd-toc-key]"));if(h.length===0)return;const f=h.find(x=>x.dataset.rdTocKey===p)??h.find(x=>x.dataset.rdTocKey===xs(e,n))??h.find(x=>!x.disabled)??h[0];for(const x of h)x.tabIndex=x===f?0:-1}),g.useEffect(()=>{const m=l.current,h=m==null?void 0:m.closest(".bim-rd-toc");if(!m||!h||!n)return;const f=Array.from(m.querySelectorAll("[data-rd-toc-key]")).find(k=>k.dataset.rdTocKey===n);if(!f)return;const x=f.getBoundingClientRect().top-h.getBoundingClientRect().top+h.scrollTop;(x<h.scrollTop+80||x>h.scrollTop+h.clientHeight-40)&&(h.scrollTop=Math.max(0,x-h.clientHeight/3))},[n]);const u=g.useCallback(m=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(m.key))return;const f=l.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(b=>!b.disabled),k=x.indexOf(document.activeElement);let y=k;if(m.key==="ArrowDown"?y=Math.min(x.length-1,k+1):m.key==="ArrowUp"?y=Math.max(0,k-1):m.key==="Home"?y=0:m.key==="End"&&(y=x.length-1),y<0||y===k)return;m.preventDefault();const w=x[y];for(const b of x)b.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:u,children:t.jsx(fl,{items:e,activeKey:n,onSelect:o,tabKey:p})})}function mm({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 po({pages:e,loading:n,page:o,onPageChange:r,renderOverlay:s}){const{t:a}=J(),[l,d]=g.useState(0),c=o??l,p=f=>{r?r(f):d(f)};if(g.useEffect(()=>{o===void 0&&d(0)},[e,o]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:a("reader.imagesLoading")})});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:a("reader.noImages")}),t.jsx("span",{children:a("reader.noImagesHint")})]})});const u=Math.max(0,Math.min(e.length-1,c)),m=e[u],h=m.label??`${u+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:m.url,alt:m.alt??a("reader.imageAlt",{label:h}),width:m.width,height:m.height,loading:"lazy",decoding:"async"}),t.jsx(mm,{page:m}),s==null?void 0:s(m,u)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":a("reader.prevImage"),disabled:u===0,onClick:()=>p(u-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:m.label??`${u+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":a("reader.nextImage"),disabled:u===e.length-1,onClick:()=>p(u+1),children:"›"})]})]})}const Go={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},Ct=[15,16,17,18,20,22,24],uo=18,bl="bim-reader-prefs",hm="bim-reading-mode";function gm(){const e={...Go};try{const n=localStorage.getItem(bl),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&Ct.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(hm))==="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 fm(e){try{localStorage.setItem(bl,JSON.stringify(e))}catch{}}function Xn(e,n){const o=e??uo,r=Ct;let s=r.indexOf(o);return s<0&&(s=r.indexOf(uo)),r[Math.max(0,Math.min(r.length-1,s+n))]}function yl(){const[e,n]=g.useState(Go);g.useEffect(()=>{n(gm())},[]);const o=g.useCallback(r=>{n(s=>{const a={...s,...r};return fm(a),a})},[]);return[e,o]}function mo(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 jl(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 vl(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 bs=()=>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"})}),xm=()=>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"})}),bm=()=>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"})}),ys=()=>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 js(e,n){if(!n)return;const o=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(o.length===0)return;const r=o[0],s=o[o.length-1],a=document.activeElement;e.shiftKey&&(a===r||!n.contains(a))?(e.preventDefault(),s.focus()):!e.shiftKey&&(a===s||!n.contains(a))&&(e.preventDefault(),r.focus())}function vs(e,n){const[o,r]=g.useState(n);return g.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const a=()=>r(s.matches);return(l=s.addEventListener)==null||l.call(s,"change",a),()=>{var d;return(d=s.removeEventListener)==null?void 0:d.call(s,"change",a)}},[e]),o}function ym(){const e=g.useContext(qt),{t:n}=J();if(!e)return null;const o=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n(o?"common.toHans":"common.toHant"),"aria-label":n(o?"common.toHans":"common.toHant"),onClick:()=>e.setLocale(o?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:o?"bim-rd-on":"bim-rd-off",children:n("common.localeShortHant")}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:o?"bim-rd-off":"bim-rd-on",children:n("common.localeShortHans")})]})}function jm(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 vm(e){var a;if(typeof window>"u"||!e)return;const n=(a=window.getSelection)==null?void 0:a.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const o=e.querySelector(".bim-rd-col"),r=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(o!=null&&o.contains(l))&&!(d!=null&&d.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 kl({title:e,subtitle:n,toc:o,activeKey:r,onSelect:s,tocHeader:a,tocCaption:l,images:d,imagesLoading:c,renderImageOverlay:p,imagePanel:u="auto",prefs:m,onPrefsChange:h,paragraphToggle:f,properNameToggle:x=!0,allowVertical:k,byline:y,current:w,workLinkToggle:b,rail:j,onReportError:S,revisedAt:v,backHref:$,backLabel:_,bottomBar:C=!0,pager:M=!0,pagerUnit:T,versions:z,currentVersionKey:H,onVersionChange:N,versionSource:I=!0,keepChapterOnVersionChange:L=!1,customImagePanel:R,toolbarExtra:P,isWarpMode:U,children:q,className:D,style:O}){const{t:A,convert:G}=J(),le=_??A("reader.back"),ne=G(T??A("reader.unitJuan")),ve=g.useId().replace(/:/g,""),oe=`bim-rd-toc-${ve}`,pe=`bim-rd-text-${ve}`,We=g.useRef(null),ee=g.useRef(null),Be=g.useRef(null),Ee=g.useRef(null),X=vs(ul,!0),ie=vs(hl,!1),he=C&&ie,[Te,K]=g.useState(null),_e=g.useRef(null),se=g.useRef(null),$e=(Y,fe)=>{se.current=fe,K(ce=>ce===Y?null:Y)},Z=g.useCallback(()=>{var Y;K(null),(Y=se.current)==null||Y.focus()},[]);g.useEffect(()=>{he||K(null)},[he]),g.useEffect(()=>{var Y,fe;Te&&((fe=(Y=_e.current)==null?void 0:Y.querySelector("button:not([disabled])"))==null||fe.focus())},[Te]);const[Ne,Oe]=g.useState("auto"),B=Ne==="auto"?X:Ne==="open",te=!X,be=!!R||!!d&&d.length>0,[Ie,F]=g.useState(u);g.useEffect(()=>{F(u)},[u]);const ue=Ie==="auto"?be||!!c:Ie==="open",Q=g.useCallback(Y=>{var fe;Oe("auto"),Y&&((fe=Ee.current)==null||fe.focus())},[]),ye=()=>Oe(B?"closed":"open");g.useEffect(()=>{if(!te||Ne!=="open")return;const Y=Be.current,fe=Y==null?void 0:Y.querySelector('input, [data-rd-toc-key][tabindex="0"]');fe==null||fe.focus()},[te,Ne]);const Ce=g.useCallback(Y=>{s(Y),te&&Q(!1);const fe=ee.current,ce=We.current;if(fe&&ce&&typeof window<"u"){const we=fe.getBoundingClientRect().top-ce.getBoundingClientRect().bottom;we<0&&window.scrollBy({top:we})}},[s,te,Q]),Me=g.useMemo(()=>vl(o),[o]),[De,qe]=g.useState(null),me=jl(z,H!==void 0?H:De),Ve=(me==null?void 0:me.key)??null,E=g.useMemo(()=>Me.map(Y=>Y.key).join(`
638
- `),[Me]),re=g.useRef(null),ae=Y=>{Y!==Ve&&(L||(re.current={key:Y,sig:E,done:!1}),H===void 0&&qe(Y),N==null||N(Y))};g.useEffect(()=>{const Y=re.current;if(!Y||Y.key!==Ve)return;const fe=Me.find(we=>!we.disabled);if(!fe)return;const ce=E!==Y.sig;!ce&&Y.done||(ce?re.current=null:Y.done=!0,fe.key!==r&&Ce(fe.key))},[Ve,E,Me,r,Ce]);const je=Me.find(Y=>Y.key===r),ke=()=>{var Y;S==null||S({chapterKey:r,chapterLabel:typeof(je==null?void 0:je.label)=="string"?je.label:void 0,anchor:jm(ee.current,((Y=We.current)==null?void 0:Y.getBoundingClientRect().bottom)??0),selectedText:vm(ee.current)})},ge=Me.findIndex(Y=>Y.key===r),Le=ge>0?Me.slice(0,ge).reverse().find(Y=>!Y.disabled):void 0,V=ge>=0?Me.slice(ge+1).find(Y=>!Y.disabled):void 0,xe=m.fontSize??uo,Ae={...O,...m.fontSize?{"--bimrd-fs":`${m.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",m.writingMode==="vertical"&&k?"bim-rd-vertical":"",D].filter(Boolean).join(" "),"data-toc":Ne,"data-img":ue?"open":"closed","data-bb":he?"":void 0,"data-warp":U?"true":void 0,style:Ae,children:[t.jsx("style",{children:gl}),t.jsx("a",{className:"bim-rd-skip",href:`#${pe}`,onClick:Y=>{var fe,ce,we;Y.preventDefault(),(fe=ee.current)==null||fe.focus(),(we=(ce=ee.current)==null?void 0:ce.scrollIntoView)==null||we.call(ce,{block:"start"})},children:A("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:We,children:[$&&t.jsxs("a",{className:"bim-rd-back",href:$,"aria-label":A("reader.backAria",{label:le}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:le})]}),(e||n||y||w)&&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}),w&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:w})]}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":A("reader.settings"),children:[z&&z.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:me?G(mo(me)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:A("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:A("reader.versionShort")}),t.jsx("select",{"aria-label":A("reader.version"),value:Ve??"",onChange:Y=>ae(Y.target.value),children:z.map(Y=>t.jsx("option",{value:Y.key,children:G(mo(Y))},Y.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),M&&(Le||V)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":A("reader.pagerGroup",{unit:ne}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.prevUnit",{unit:ne}),title:Le?typeof Le.label=="string"&&Le.label?A("reader.prevUnitTitle",{unit:ne,label:Le.label}):A("reader.prevUnit",{unit:ne}):A("reader.firstUnit",{unit:ne}),disabled:!Le,onClick:()=>Le&&Ce(Le.key),children:t.jsx(xm,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.nextUnit",{unit:ne}),title:V?typeof V.label=="string"&&V.label?A("reader.nextUnitTitle",{unit:ne,label:V.label}):A("reader.nextUnit",{unit:ne}):A("reader.lastUnit",{unit:ne}),disabled:!V,onClick:()=>V&&Ce(V.key),children:t.jsx(bm,{})})]}),M&&(Le||V)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:Ee,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":B,"aria-controls":oe,onClick:ye,children:[t.jsx(bs,{}),t.jsx("span",{className:"bim-rd-tlabel",children:A("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":ue,onClick:()=>F(ue?"closed":"open"),children:[t.jsx(ys,{}),A("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(ym,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":A("reader.fontSmaller"),disabled:xe<=Ct[0],onClick:()=>h({fontSize:Xn(m.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":A("reader.fontLarger"),disabled:xe>=Ct[Ct.length-1],onClick:()=>h({fontSize:Xn(m.fontSize,1)}),children:"A+"}),(f||x||k)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),f&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.readingMode==="paragraph",title:A("reader.paragraphTitle"),onClick:()=>h({readingMode:m.readingMode==="paragraph"?"line":"paragraph"}),children:A("reader.paragraph")}),b&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[t.jsx("input",{type:"checkbox",checked:m.workLinks,onChange:Y=>h({workLinks:Y.target.checked})}),t.jsx("span",{children:A("reader.workLinks")})]}),x&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.properNames,title:A("reader.properNameTitle"),onClick:()=>h({properNames:!m.properNames}),children:A("reader.properName")}),k&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":m.writingMode==="vertical",onClick:()=>h({writingMode:m.writingMode==="vertical"?"horizontal":"vertical"}),children:A("reader.vertical")}),P]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:oe,ref:Be,role:te&&B?"dialog":void 0,"aria-modal":te&&B?!0:void 0,"aria-label":te&&B?A("reader.toc"):void 0,onKeyDown:Y=>{if(!(!te||!B)){if(Y.key==="Escape"){Y.stopPropagation(),Q(!0);return}Y.key==="Tab"&&js(Y,Be.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:l??A("reader.toc")}),te&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.closeToc"),onClick:()=>Q(!0),children:"✕"})]}),a]}),t.jsx(xl,{items:o,activeKey:r,onSelect:Ce})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Q(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":A("reader.images"),children:ue&&(R||t.jsx(po,{pages:d??null,loading:c,renderOverlay:p}))}),t.jsxs("div",{className:"bim-rd-text",id:pe,ref:ee,tabIndex:-1,"data-rail":(j||S)&&!U?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[q,I&&me&&(me.sourceName||me.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":me.key,children:[me.sourceName&&t.jsxs(t.Fragment,{children:[A("reader.sourceLabel")," ",me.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:me.sourceUrl,target:"_blank",rel:"noreferrer",children:G(me.sourceName)}):G(me.sourceName)]}),me.sourceName&&me.license&&t.jsx("span",{className:"bim-rd-dot"}),me.license&&t.jsx(t.Fragment,{children:A("reader.licenseOf",{license:me.license})})]}),v&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:A("reader.revisedAt",{date:v})}),S&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:Y=>Y.preventDefault(),onClick:ke,children:A("reader.reportError")})}),M&&(Le||V)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":A("reader.pagerNav"),children:[Le?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Ce(Le.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),A("reader.prevUnit",{unit:ne})]}),t.jsx("span",{className:"bim-rd-pglabel",children:Le.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",A("reader.firstUnit",{unit:ne})]}),V?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Ce(V.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[A("reader.nextUnit",{unit:ne}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:V.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[A("reader.lastUnit",{unit:ne})," →"]})]})]}),(j||S)&&!U&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":A("reader.rail"),children:[j,S&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:Y=>Y.preventDefault(),onClick:ke,children:A("reader.reportError")})})]})]})]}),he&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":A("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":B,"aria-controls":oe,onClick:()=>{K(null),ye()},children:[t.jsx(bs,{}),t.jsx("span",{children:A("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":Te==="img","aria-haspopup":"dialog",onClick:Y=>$e("img",Y.currentTarget),children:[t.jsx(ys,{}),t.jsx("span",{children:A("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":Te==="fs","aria-haspopup":"dialog",onClick:Y=>$e("fs",Y.currentTarget),children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"A"}),t.jsx("span",{children:A("reader.fontSize")})]}),S&&t.jsxs("button",{type:"button",onMouseDown:Y=>Y.preventDefault(),onClick:()=>{K(null),ke()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:A("reader.reportError")})]})]}),he&&Te&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:Z}),t.jsxs("div",{className:"bim-rd-sheet",ref:_e,role:"dialog","aria-modal":"true","aria-label":A(Te==="img"?"reader.images":"reader.fontSize"),onKeyDown:Y=>{if(Y.key==="Escape"){Y.stopPropagation(),Z();return}Y.key==="Tab"&&js(Y,_e.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:A(Te==="img"?"reader.images":"reader.fontSize")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.close"),onClick:Z,children:"✕"})]}),Te==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(po,{pages:d??null,loading:c,renderOverlay:p})}):t.jsxs("div",{className:"bim-rd-sheet-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.fontSmaller"),disabled:xe<=Ct[0],onClick:()=>h({fontSize:Xn(m.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[xe,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.fontLarger"),disabled:xe>=Ct[Ct.length-1],onClick:()=>h({fontSize:Xn(m.fontSize,1)}),children:"A+"})]})]})]})]})}const wl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],km={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Qe(e){return km[e]??e}const ln=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],cn={熹平: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},Sl={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function ji(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 wm(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 Sm=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,ks={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Yo(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(ks))if(n.startsWith(s))return ks[s];const o=Qe(n);if(Dt[o]!=null)return o;const r=Tt(n);if(r&&n.length<=r.length+1)return Qe(r)}function Ft(e,n){if(n){const o=Sl[`${n}|${e}`];if(o!=null)return o}return cn[e]}const _m=1911;function $m(e){const n=cn[e];if(n==null)return;const o=St[e];let r;for(const[s,a]of Object.entries(cn))St[s]===o&&a>n&&(r==null||a<r)&&(r=a);return r!=null?r-1:void 0}const Cm={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function ai(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,o=0,r=!1;for(const a of e){const l=Cm[a];if(l===void 0)return;r=!0,a==="十"?o=(o||1)*10:a==="廿"||a==="卅"?(n+=l,o=0):o>=10?(n+=o+l,o=0):o=o*10+l}const s=n+o;return r&&s>0?s:void 0}function Tt(e){for(const n of wl)if(e.startsWith(n))return n}const St={};{const e=(n,o)=>{for(const r of o)St[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ut(e,n){const o=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(cn))if(e.includes(r)&&!(o&&St[r]&&St[r]!==o&&Sl[`${o}|${r}`]==null))return r}function An(e){var l,d,c;const n={era:"",reign:"",source:"none"},o=e.dating;if(o!=null&&o.era||o!=null&&o.reign)return{era:o.era??"",reign:o.reign??"",source:o.certainty==="attested"?"catalog":"edition"};const r=(l=e.lineage)==null?void 0:l.year_text;if(r){const p=Tt(r)??"";return{era:Qe(p),reign:Ut(r,p)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const p=ji(s);if(p)return{era:wm(p.from),reign:"",source:"publication"};const u=Tt(s)??Yo(s)??((c=ln.find(f=>f.pattern.test(s)))==null?void 0:c.era)??"",m=Ut(s,u)??"",h=u||(m?St[m]??"":"");if(h||m)return{era:Qe(h),reign:m,source:"publication"}}const a=e.edition||e.title||"";if(a){const p=Tt(a);if(p)return{era:Qe(p),reign:Ut(a,p)??"",source:"edition"};const u=ln.find(m=>m.pattern.test(a));if(u)return{era:Qe(u.era),reign:Ut(a,u.era)??u.reign??"",source:"edition"}}return n}function vi(e){var r,s,a,l,d,c,p,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=(a=e.publication_info)==null?void 0:a.year;if(n){const h=ji(n);if(h)return h.from}const o=[(l=e.lineage)==null?void 0:l.year_text,(d=e.publication_info)==null?void 0:d.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const h of o){const f=((c=e.publication_info)==null?void 0:c.year)||((p=e.lineage)==null?void 0:p.year_text);if(f&&h!==f&&(Tt(f)||Yo(f)))break;const x=h.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??h.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(x){const j=parseInt(x[1],10);if(j>=100&&j<=2100)return j}const k=h.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const j=Tt(h);if(!j||Qe(j)==="民國"){const v=ai(k[1]);if(v!=null&&v>=1&&v<=120)return _m+v}}const y=Tt(h)??((u=ln.find(j=>j.pattern.test(h)))==null?void 0:u.era),w=y?Qe(y):void 0,b=Ut(h,w)??(Tt(h)||(m=ln.find(j=>j.pattern.test(h)))==null?void 0:m.reign);if(b){const j=Ft(b,w);if(j==null)continue;const S=h.indexOf(b),v=S>=0?h.slice(S+b.length):"",$=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),_=$?ai($[1]):void 0;return j+(_?_-1:0)}}}function Ko(e){var l,d,c,p,u,m;const n=(l=e.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const o=(d=e.lineage)==null?void 0:d.year_range;if(o&&o.length===2)return{from:o[0],to:o[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const h=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const f=ho[Qe(h[1])],x=Dt[Qe(h[2])];if(f!=null&&x!=null)return{from:Math.min(f,x)-20,to:Math.max(f,x)+40}}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const h=ji(s);if((h==null?void 0:h.to)!=null)return{from:h.from,to:h.to};const f=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const x=ho[Qe(f[1])],k=Dt[Qe(f[2])];if(x!=null&&k!=null)return{from:Math.min(x,k)-20,to:Math.max(x,k)+40}}}const a=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const h of a){if(!/[間间]/.test(h))continue;const f=Tt(h)??Yo(h)??((m=ln.find(y=>y.pattern.test(h)))==null?void 0:m.era),x=f?Qe(f):void 0,k=[];for(const y of Object.keys(cn))h.includes(y)&&(x&&St[y]&&St[y]!==x||Ft(y,x)!=null&&k.push(y));if(k.length===0){const y=h.match(/([一-鿿])([一-鿿])[間间]/);if(y&&x){for(const w of[y[1],y[2]])for(const b of Object.keys(cn))if(St[b]===x&&!(b[0]!==w&&b[b.length-1]!==w)&&Ft(b,x)!=null){k.push(b);break}}}if(k.length>0){const y=k.map(S=>Ft(S,x)).filter(S=>S!=null),w=Math.min(...y),b=k.reduce((S,v)=>Ft(S,x)>=Ft(v,x)?S:v),j=$m(b)??qi(x??"")??Math.max(...y);return{from:w,to:j>w?j:qi(x??St[b]??"")??w}}if(x&&Dt[x]!=null)return{from:Dt[x],to:qi(x)??Dt[x]}}}const Dt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},zm=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Tm=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ws=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Ss(e,n){for(const o of wl){const r=e.indexOf(o);if(r<0)continue;if(o.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Ut(e.slice(r),Qe(o)))continue}const s=Qe(o);if(s===n)continue;const a=e.slice(r),l=Ut(a,s)??"";let d;if(l){const c=Ft(l,s);if(c!=null){const u=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),m=u?ai(u[1]):void 0;d=c+(m?m-1:0)}}return{era:s,reign:l,year:d}}for(const o of ln)if(o.pattern.test(e))return{era:Qe(o.era),reign:o.reign??""}}function Nm(e){var w,b,j,S,v;const n=An(e),o=((w=e.publication_info)==null?void 0:w.year)??"",r=o?ji(o):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",a=/[間间]/.test(s),l=((b=e.lineage)==null?void 0:b.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),c=n.source==="publication"&&Sm.test(o),p=n.source==="publication"&&/[間间]/.test(o),u=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;a||d||c||p?m=void 0:u?m=parseInt(u[2],10):m=vi(e);const h=m==null?Ko(e):void 0;let f;n.source==="publication"&&(c||ws.test(o))?f="uncertain":n.source==="lineage"||n.source==="publication"?f="attested":ws.test(s)||!n.reign&&m==null?f="uncertain":f="inferred";const x=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.year_text)??((S=e.lineage)==null?void 0:S.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,k={era:n.era,reign:n.reign,year:m,yearRange:h,certainty:f,source:n.source==="edition"?"edition":"catalog",basis:x};if(u){const $=l.match(/[、,,]\s*([宋元明清])/);$&&$[1]!==k.era&&(k.laterRepair={era:$[1]})}if(!k.laterRepair&&Tm.test(s)){const $=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);$&&$[1]!==n.era&&(k.laterRepair={era:$[1]})}const y=zm.find($=>$.re.test(s));if(y){const $=s.search(y.re),_=s.slice($),C=Ss(_,n.era)??Ss(s,n.era);C&&(k.basedOn={era:C.era,reign:C.reign,year:C.year,relation:y.relation})}return k}const ho={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function qi(e){return ho[e]}function li(e){const n=vi(e);if(n!=null)return n;const o=Ko(e);if(o)return o.from;const r=An(e).era;return r?Dt[r]:void 0}const _s=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function go(e){const n=_s.indexOf(e);return n===-1?_s.length:n}function Em(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const a=s.relation;a==="part_of"?n.belongsTo.push(s):a==="collected_in"?n.collected.push(s):a==="has_part"||a==="contains_text_of"?n.contains.push(s):a==="text_carried_by"||a==="studied_by"||a==="derived_from"||a==="followed_by"||a==="has_adaptation"?n.derivative.push(s):a==="studies"||a==="preceded_by"?n.studies.push(s):n.related.push(s)}const o=[],r=(s,a)=>{n[s].length&&o.push({key:s,labelKey:a,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),o}function qo(e,n){const o=Ao(e||[]),r=new Map,s=[];for(const p of o)p.group?(r.has(p.group)||r.set(p.group,[]),r.get(p.group).push(p)):s.push(p);for(const p of r.values())p.sort((u,m)=>{const h=f=>f.group_role==="origin"?0:f.group_role==="mirror"?1:2;return h(u)-h(m)});const a={text:[],image:[],textImage:[],physical:[]};for(const p of s){const u=Kt(p),m=u.includes("text"),h=u.includes("image");m&&h?a.textImage.push(p):m?a.text.push(p):h?a.image.push(p):a.physical.push(p)}const d=["text","image","textImage","physical"].filter(p=>a[p].length>0).map(p=>({key:p,items:a[p]})),c=[...r.entries()].map(([p,u])=>{var m,h;return{key:p,label:((m=n==null?void 0:n[p])==null?void 0:m.label)||p,description:(h=n==null?void 0:n[p])==null?void 0:h.description,items:u}});return{buckets:d,mirrors:c,total:o.length}}function ki(e,n=un("zh-Hant")){const o=[],r=e.metadata||{};r.edition&&o.push(String(r.edition)),e.source_label&&o.push(e.source_label),e.details&&o.push(e.details);const s=hi(e);return s&&s.expected>0&&o.push(s.missing>0?n("detail.volumeStatsMissing",{found:s.found,expected:s.expected,missing:s.missing}):n("detail.volumeStats",{found:s.found,expected:s.expected})),r.version&&o.push(String(r.version)),o.join(" · ")}function _l(e,n){if(ki(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 a=r.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}function $l(e,n){var a,l;const o=e.resources||[],r=[],s=[];for(const d of o){const c=Kt(d);c.includes("image")&&r.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:An(e),year:vi(e),sortYear:li(e),images:r,holders:s,locationName:(a=e.current_location)==null?void 0:a.name,important:Im(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:r.length>0}}function Im(e,n){var d,c;if(!n)return!1;const o=n.default_collection;if(!o)return!1;const r=(d=n.collections)==null?void 0:d[o];if(((r==null?void 0:r.book_ids)??(o==="core"?n.core_books??[]:[])).includes(e))return!0;const a=(r==null?void 0:r.groups)??[],l=(c=n.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function Cl(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>$l(c,n));let a=s;o.era&&(a=a.filter(c=>c.era.era===o.era)),o.scanOnly&&(a=a.filter(c=>c.hasImage)),o.sort==="year"?a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const u=c.r.sortYear,m=p.r.sortYear;return u!=null&&m!=null?u-m||c.i-p.i:u!=null?-1:m!=null?1:c.i-p.i}).map(c=>c.r):a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const u=m=>(m.important?0:1)*2+(m.hasImage?0:1);return u(c.r)-u(p.r)||c.i-p.i}).map(c=>c.r);const d=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,p)=>go(c)-go(p));return{rows:a,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function Rm(e,n){var y,w;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)??[],a=r.length>0||s.length>0,l=!a&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!a&&l.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...l]),p=b=>{if(c.has(b))return!0;const j=n.node_groups[b];return j!=null&&d.has(j)},u=[],m=new Map,h=[];for(const b of e)if(!((w=n.excluded_books)!=null&&w.includes(b)))if(p(b))u.push(b);else{const j=n.node_groups[b];j?(m.has(j)||m.set(j,[]),m.get(j).push(b)):h.push(b)}if(h.length+[...m.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const x=new Map((n.groups??[]).map(b=>[b.id,b])),k=[...m.entries()].map(([b,j])=>{const S=x.get(b);return{id:b,label:(S==null?void 0:S.label)??b,description:S==null?void 0:S.description,ids:j}});return h.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:h}),{useGrouping:!0,coreIds:u,groupedIds:k}}const zl=["撰","編","注","校","譯","繪","其他"],Lm=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Xo(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of Lm)if(r.test(n))return o;return"其他"}function Zo(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Tl(e,n="全部"){const o=new Map;for(const s of e){const a=Xo(s);o.set(a,(o.get(a)??0)+1)}const r=[{cls:"全部",label:n,count:e.length}];for(const s of zl){const a=o.get(s);a&&r.push({cls:s,label:s,count:a})}return r.length>2?r:[]}function Nl(e,n,o){if(n&&n.books&&n.books.length>0){const s=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),a=[...new Set(s.map(l=>l.section).filter(Boolean))];return{rows:s,source:"catalog",sections:a,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(a=>({id:a.id,title:a.title,volumes:En(a.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var a,l;return{id:s,title:((a=o==null?void 0:o.get(s))==null?void 0:a.title)||s,edition:(l=o==null?void 0:o.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function En(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,a)=>o+a)}return e.split(/[,、]/).map(o=>parseInt(o.trim())).filter(o=>!isNaN(o))}return[]}function wi(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=[...e].sort((a,l)=>a-l),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 Am=["〇","一","二","三","四","五","六","七","八","九"],$s=["","十","百","千"];function El(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let a=0;a<o;a++){const l=parseInt(n[a]),d=o-1-a;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&d===1&&a===0?r+=$s[d]:r+=Am[l]+$s[d])}return r}function Pm(e){return e==null?"":typeof e=="string"?e:e.title??""}function Et(e,n="卷"){var r,s;const o=e;return o.measure_info?o.measure_info:(r=o.juan_count)!=null&&r.number?El(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function Il(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,a]of o)if(s.test(n))return a;return""}const Mm=216,Cs="clamp(280px, 23vw, 360px)",Bm=1440,fo="(max-width: 719px)",Wm=`${fo}, (pointer: coarse)`,Om=`
639
- .bim-d-main.bim-d-main-grid { max-width: ${Bm}px; padding: 16px 32px 0; }
637
+ `;function Yo(e,n){var o;return n?e.key===n?!0:!!((o=e.children)!=null&&o.some(r=>Yo(r,n))):!1}const mm=()=>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 hm({item:e,activeKey:n,onSelect:o,tabKey:r}){const s=Yo(e,n),[a,l]=g.useState(s||!!e.defaultExpanded);return g.useEffect(()=>{s&&l(!0)},[s]),g.useEffect(()=>{e.defaultExpanded&&l(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":a,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>l(d=>!d),children:[t.jsx(mm,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),a&&t.jsx(bl,{items:e.children,activeKey:n,onSelect:o,tabKey:r})]})}function bl({items:e,activeKey:n,onSelect:o,tabKey:r}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(hm,{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 ys(e,n){var o;for(const r of e)if(r.key===n||Yo(r,n))return r.key;return((o=e[0])==null?void 0:o.key)??null}function yl({items:e,activeKey:n,onSelect:o,label:r}){const{t:s}=J(),a=r??s("reader.toc"),l=g.useRef(null),[d,c]=g.useState(null);g.useEffect(()=>{c(null)},[n]);const p=g.useMemo(()=>d||(n??ys(e,n)),[d,n,e]);g.useEffect(()=>{const m=l.current;if(!m)return;const h=Array.from(m.querySelectorAll("[data-rd-toc-key]"));if(h.length===0)return;const f=h.find(x=>x.dataset.rdTocKey===p)??h.find(x=>x.dataset.rdTocKey===ys(e,n))??h.find(x=>!x.disabled)??h[0];for(const x of h)x.tabIndex=x===f?0:-1}),g.useEffect(()=>{const m=l.current,h=m==null?void 0:m.closest(".bim-rd-toc");if(!m||!h||!n)return;const f=Array.from(m.querySelectorAll("[data-rd-toc-key]")).find(k=>k.dataset.rdTocKey===n);if(!f)return;const x=f.getBoundingClientRect().top-h.getBoundingClientRect().top+h.scrollTop;(x<h.scrollTop+80||x>h.scrollTop+h.clientHeight-40)&&(h.scrollTop=Math.max(0,x-h.clientHeight/3))},[n]);const u=g.useCallback(m=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(m.key))return;const f=l.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(b=>!b.disabled),k=x.indexOf(document.activeElement);let y=k;if(m.key==="ArrowDown"?y=Math.min(x.length-1,k+1):m.key==="ArrowUp"?y=Math.max(0,k-1):m.key==="Home"?y=0:m.key==="End"&&(y=x.length-1),y<0||y===k)return;m.preventDefault();const w=x[y];for(const b of x)b.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:u,children:t.jsx(bl,{items:e,activeKey:n,onSelect:o,tabKey:p})})}function gm({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 mo({pages:e,loading:n,page:o,onPageChange:r,renderOverlay:s}){const{t:a}=J(),[l,d]=g.useState(0),c=o??l,p=f=>{r?r(f):d(f)};if(g.useEffect(()=>{o===void 0&&d(0)},[e,o]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:a("reader.imagesLoading")})});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:a("reader.noImages")}),t.jsx("span",{children:a("reader.noImagesHint")})]})});const u=Math.max(0,Math.min(e.length-1,c)),m=e[u],h=m.label??`${u+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:m.url,alt:m.alt??a("reader.imageAlt",{label:h}),width:m.width,height:m.height,loading:"lazy",decoding:"async"}),t.jsx(gm,{page:m}),s==null?void 0:s(m,u)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":a("reader.prevImage"),disabled:u===0,onClick:()=>p(u-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:m.label??`${u+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":a("reader.nextImage"),disabled:u===e.length-1,onClick:()=>p(u+1),children:"›"})]})]})}const Ko={fontSize:null,readingMode:"line",properNames:!1,writingMode:"horizontal",workLinks:!0},$t=[15,16,17,18,20,22,24],ho=18,jl="bim-reader-prefs",fm="bim-reading-mode";function xm(){const e={...Ko};try{const n=localStorage.getItem(jl),o=n?JSON.parse(n):{};typeof o.fontSize=="number"&&$t.includes(o.fontSize)&&(e.fontSize=o.fontSize),(o.readingMode??localStorage.getItem(fm))==="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 bm(e){try{localStorage.setItem(jl,JSON.stringify(e))}catch{}}function Jn(e,n){const o=e??ho,r=$t;let s=r.indexOf(o);return s<0&&(s=r.indexOf(ho)),r[Math.max(0,Math.min(r.length-1,s+n))]}function vl(){const[e,n]=g.useState(Ko);g.useEffect(()=>{n(xm())},[]);const o=g.useCallback(r=>{n(s=>{const a={...s,...r};return bm(a),a})},[]);return[e,o]}function go(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 kl(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 wl(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 js=()=>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"})}),ym=()=>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"})}),jm=()=>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"})}),vs=()=>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 ks(e,n){if(!n)return;const o=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(o.length===0)return;const r=o[0],s=o[o.length-1],a=document.activeElement;e.shiftKey&&(a===r||!n.contains(a))?(e.preventDefault(),s.focus()):!e.shiftKey&&(a===s||!n.contains(a))&&(e.preventDefault(),r.focus())}function ws(e,n){const[o,r]=g.useState(n);return g.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);r(s.matches);const a=()=>r(s.matches);return(l=s.addEventListener)==null||l.call(s,"change",a),()=>{var d;return(d=s.removeEventListener)==null?void 0:d.call(s,"change",a)}},[e]),o}function vm(){const e=g.useContext(Xt),{t:n}=J();if(!e)return null;const o=e.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:n(o?"common.toHans":"common.toHant"),"aria-label":n(o?"common.toHans":"common.toHant"),onClick:()=>e.setLocale(o?"zh-Hans":"zh-Hant"),children:[t.jsx("span",{className:o?"bim-rd-on":"bim-rd-off",children:n("common.localeShortHant")}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:o?"bim-rd-off":"bim-rd-on",children:n("common.localeShortHans")})]})}function km(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 wm(e){var a;if(typeof window>"u"||!e)return;const n=(a=window.getSelection)==null?void 0:a.call(window);if(!n||n.isCollapsed||n.rangeCount===0)return;const o=e.querySelector(".bim-rd-col"),r=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(o!=null&&o.contains(l))&&!(d!=null&&d.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 Sl({title:e,subtitle:n,toc:o,activeKey:r,onSelect:s,tocHeader:a,tocCaption:l,images:d,imagesLoading:c,renderImageOverlay:p,imagePanel:u="auto",prefs:m,onPrefsChange:h,paragraphToggle:f,properNameToggle:x=!0,allowVertical:k,byline:y,current:w,workLinkToggle:b,rail:j,onReportError:S,revisedAt:v,backHref:$,backLabel:_,bottomBar:C=!0,pager:M=!0,pagerUnit:N,versions:T,currentVersionKey:F,onVersionChange:R,versionSource:E=!0,keepChapterOnVersionChange:L=!1,customImagePanel:I,toolbarExtra:P,isWarpMode:V,children:X,className:D,style:O}){const{t:A,convert:G}=J(),se=_??A("reader.back"),Q=G(N??A("reader.unitJuan")),ve=g.useId().replace(/:/g,""),ne=`bim-rd-toc-${ve}`,ce=`bim-rd-text-${ve}`,We=g.useRef(null),ke=g.useRef(null),Pe=g.useRef(null),Ee=g.useRef(null),Z=ws(hl,!0),le=ws(fl,!1),oe=C&&le,[he,U]=g.useState(null),$e=g.useRef(null),me=g.useRef(null),Ce=(q,ue)=>{me.current=ue,U(re=>re===q?null:q)},Y=g.useCallback(()=>{var q;U(null),(q=me.current)==null||q.focus()},[]);g.useEffect(()=>{oe||U(null)},[oe]),g.useEffect(()=>{var q,ue;he&&((ue=(q=$e.current)==null?void 0:q.querySelector("button:not([disabled])"))==null||ue.focus())},[he]);const[ze,Me]=g.useState("auto"),B=ze==="auto"?Z:ze==="open",te=!Z,xe=!!I||!!d&&d.length>0,[Re,H]=g.useState(u);g.useEffect(()=>{H(u)},[u]);const de=Re==="auto"?xe||!!c:Re==="open",ee=g.useCallback(q=>{var ue;Me("auto"),q&&((ue=Ee.current)==null||ue.focus())},[]),ye=()=>Me(B?"closed":"open");g.useEffect(()=>{if(!te||ze!=="open")return;const q=Pe.current,ue=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');ue==null||ue.focus()},[te,ze]);const Se=g.useCallback(q=>{s(q),te&&ee(!1);const ue=ke.current,re=We.current;if(ue&&re&&typeof window<"u"){const we=ue.getBoundingClientRect().top-re.getBoundingClientRect().bottom;we<0&&window.scrollBy({top:we})}},[s,te,ee]),Be=g.useMemo(()=>wl(o),[o]),[De,Je]=g.useState(null),He=kl(T,F!==void 0?F:De),Ue=(He==null?void 0:He.key)??null,z=g.useMemo(()=>Be.map(q=>q.key).join(`
638
+ `),[Be]),ie=g.useRef(null),ae=q=>{q!==Ue&&(L||(ie.current={key:q,sig:z,done:!1}),F===void 0&&Je(q),R==null||R(q))};g.useEffect(()=>{const q=ie.current;if(!q||q.key!==Ue)return;const ue=Be.find(we=>!we.disabled);if(!ue)return;const re=z!==q.sig;!re&&q.done||(re?ie.current=null:q.done=!0,ue.key!==r&&Se(ue.key))},[Ue,z,Be,r,Se]);const be=Be.find(q=>q.key===r),je=()=>{var q;S==null||S({chapterKey:r,chapterLabel:typeof(be==null?void 0:be.label)=="string"?be.label:void 0,anchor:km(ke.current,((q=We.current)==null?void 0:q.getBoundingClientRect().bottom)??0),selectedText:wm(ke.current)})},ge=Be.findIndex(q=>q.key===r),Ie=ge>0?Be.slice(0,ge).reverse().find(q=>!q.disabled):void 0,K=ge>=0?Be.slice(ge+1).find(q=>!q.disabled):void 0,fe=m.fontSize??ho,Ne={...O,...m.fontSize?{"--bimrd-fs":`${m.fontSize}px`}:null};return t.jsxs("div",{className:["bim-rd",m.writingMode==="vertical"&&k?"bim-rd-vertical":"",D].filter(Boolean).join(" "),"data-toc":ze,"data-img":de?"open":"closed","data-bb":oe?"":void 0,"data-warp":V?"true":void 0,style:Ne,children:[t.jsx("style",{children:xl}),t.jsx("a",{className:"bim-rd-skip",href:`#${ce}`,onClick:q=>{var ue,re,we;q.preventDefault(),(ue=ke.current)==null||ue.focus(),(we=(re=ke.current)==null?void 0:re.scrollIntoView)==null||we.call(re,{block:"start"})},children:A("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:We,children:[$&&t.jsxs("a",{className:"bim-rd-back",href:$,"aria-label":A("reader.backAria",{label:se}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:se})]}),(e||n||y||w)&&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}),w&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:w})]}),n&&t.jsx("span",{children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":A("reader.settings"),children:[T&&T.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:He?G(go(He)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:A("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:A("reader.versionShort")}),t.jsx("select",{"aria-label":A("reader.version"),value:Ue??"",onChange:q=>ae(q.target.value),children:T.map(q=>t.jsx("option",{value:q.key,children:G(go(q))},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),M&&(Ie||K)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":A("reader.pagerGroup",{unit:Q}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.prevUnit",{unit:Q}),title:Ie?typeof Ie.label=="string"&&Ie.label?A("reader.prevUnitTitle",{unit:Q,label:Ie.label}):A("reader.prevUnit",{unit:Q}):A("reader.firstUnit",{unit:Q}),disabled:!Ie,onClick:()=>Ie&&Se(Ie.key),children:t.jsx(ym,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.nextUnit",{unit:Q}),title:K?typeof K.label=="string"&&K.label?A("reader.nextUnitTitle",{unit:Q,label:K.label}):A("reader.nextUnit",{unit:Q}):A("reader.lastUnit",{unit:Q}),disabled:!K,onClick:()=>K&&Se(K.key),children:t.jsx(jm,{})})]}),M&&(Ie||K)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:Ee,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":B,"aria-controls":ne,onClick:ye,children:[t.jsx(js,{}),t.jsx("span",{className:"bim-rd-tlabel",children:A("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":de,onClick:()=>H(de?"closed":"open"),children:[t.jsx(vs,{}),A("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(vm,{}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":A("reader.fontSmaller"),disabled:fe<=$t[0],onClick:()=>h({fontSize:Jn(m.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":A("reader.fontLarger"),disabled:fe>=$t[$t.length-1],onClick:()=>h({fontSize:Jn(m.fontSize,1)}),children:"A+"}),(f||x||k)&&t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),f&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.readingMode==="paragraph",title:A("reader.paragraphTitle"),onClick:()=>h({readingMode:m.readingMode==="paragraph"?"line":"paragraph"}),children:A("reader.paragraph")}),b&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk",children:[t.jsx("input",{type:"checkbox",checked:m.workLinks,onChange:q=>h({workLinks:q.target.checked})}),t.jsx("span",{children:A("reader.workLinks")})]}),x&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":m.properNames,title:A("reader.properNameTitle"),onClick:()=>h({properNames:!m.properNames}),children:A("reader.properName")}),k&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":m.writingMode==="vertical",onClick:()=>h({writingMode:m.writingMode==="vertical"?"horizontal":"vertical"}),children:A("reader.vertical")}),P]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:ne,ref:Pe,role:te&&B?"dialog":void 0,"aria-modal":te&&B?!0:void 0,"aria-label":te&&B?A("reader.toc"):void 0,onKeyDown:q=>{if(!(!te||!B)){if(q.key==="Escape"){q.stopPropagation(),ee(!0);return}q.key==="Tab"&&ks(q,Pe.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:l??A("reader.toc")}),te&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.closeToc"),onClick:()=>ee(!0),children:"✕"})]}),a]}),t.jsx(yl,{items:o,activeKey:r,onSelect:Se})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>ee(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":A("reader.images"),children:de&&(I||t.jsx(mo,{pages:d??null,loading:c,renderOverlay:p}))}),t.jsxs("div",{className:"bim-rd-text",id:ce,ref:ke,tabIndex:-1,"data-rail":(j||S)&&!V?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[X,E&&He&&(He.sourceName||He.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":He.key,children:[He.sourceName&&t.jsxs(t.Fragment,{children:[A("reader.sourceLabel")," ",He.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:He.sourceUrl,target:"_blank",rel:"noreferrer",children:G(He.sourceName)}):G(He.sourceName)]}),He.sourceName&&He.license&&t.jsx("span",{className:"bim-rd-dot"}),He.license&&t.jsx(t.Fragment,{children:A("reader.licenseOf",{license:He.license})})]}),v&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:A("reader.revisedAt",{date:v})}),S&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:q=>q.preventDefault(),onClick:je,children:A("reader.reportError")})}),M&&(Ie||K)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":A("reader.pagerNav"),children:[Ie?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Se(Ie.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),A("reader.prevUnit",{unit:Q})]}),t.jsx("span",{className:"bim-rd-pglabel",children:Ie.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",A("reader.firstUnit",{unit:Q})]}),K?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Se(K.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[A("reader.nextUnit",{unit:Q}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:K.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[A("reader.lastUnit",{unit:Q})," →"]})]})]}),(j||S)&&!V&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":A("reader.rail"),children:[j,S&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:q=>q.preventDefault(),onClick:je,children:A("reader.reportError")})})]})]})]}),oe&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":A("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":B,"aria-controls":ne,onClick:()=>{U(null),ye()},children:[t.jsx(js,{}),t.jsx("span",{children:A("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":he==="img","aria-haspopup":"dialog",onClick:q=>Ce("img",q.currentTarget),children:[t.jsx(vs,{}),t.jsx("span",{children:A("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":he==="fs","aria-haspopup":"dialog",onClick:q=>Ce("fs",q.currentTarget),children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"A"}),t.jsx("span",{children:A("reader.fontSize")})]}),S&&t.jsxs("button",{type:"button",onMouseDown:q=>q.preventDefault(),onClick:()=>{U(null),je()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:A("reader.reportError")})]})]}),oe&&he&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:Y}),t.jsxs("div",{className:"bim-rd-sheet",ref:$e,role:"dialog","aria-modal":"true","aria-label":A(he==="img"?"reader.images":"reader.fontSize"),onKeyDown:q=>{if(q.key==="Escape"){q.stopPropagation(),Y();return}q.key==="Tab"&&ks(q,$e.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:A(he==="img"?"reader.images":"reader.fontSize")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.close"),onClick:Y,children:"✕"})]}),he==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(mo,{pages:d??null,loading:c,renderOverlay:p})}):t.jsxs("div",{className:"bim-rd-sheet-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.fontSmaller"),disabled:fe<=$t[0],onClick:()=>h({fontSize:Jn(m.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[fe,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":A("reader.fontLarger"),disabled:fe>=$t[$t.length-1],onClick:()=>h({fontSize:Jn(m.fontSize,1)}),children:"A+"})]})]})]})]})}const _l=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Sm={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Qe(e){return Sm[e]??e}const cn=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],dn={熹平: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},$l={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function ki(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 _m(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 $m=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Ss={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function qo(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Ss))if(n.startsWith(s))return Ss[s];const o=Qe(n);if(Ut[o]!=null)return o;const r=zt(n);if(r&&n.length<=r.length+1)return Qe(r)}function Dt(e,n){if(n){const o=$l[`${n}|${e}`];if(o!=null)return o}return dn[e]}const Cm=1911;function zm(e){const n=dn[e];if(n==null)return;const o=wt[e];let r;for(const[s,a]of Object.entries(dn))wt[s]===o&&a>n&&(r==null||a<r)&&(r=a);return r!=null?r-1:void 0}const Tm={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function ci(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,o=0,r=!1;for(const a of e){const l=Tm[a];if(l===void 0)return;r=!0,a==="十"?o=(o||1)*10:a==="廿"||a==="卅"?(n+=l,o=0):o>=10?(n+=o+l,o=0):o=o*10+l}const s=n+o;return r&&s>0?s:void 0}function zt(e){for(const n of _l)if(e.startsWith(n))return n}const wt={};{const e=(n,o)=>{for(const r of o)wt[r]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Vt(e,n){const o=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(dn))if(e.includes(r)&&!(o&&wt[r]&&wt[r]!==o&&$l[`${o}|${r}`]==null))return r}function Mn(e){var l,d,c;const n={era:"",reign:"",source:"none"},o=e.dating;if(o!=null&&o.era||o!=null&&o.reign)return{era:o.era??"",reign:o.reign??"",source:o.certainty==="attested"?"catalog":"edition"};const r=(l=e.lineage)==null?void 0:l.year_text;if(r){const p=zt(r)??"";return{era:Qe(p),reign:Vt(r,p)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const p=ki(s);if(p)return{era:_m(p.from),reign:"",source:"publication"};const u=zt(s)??qo(s)??((c=cn.find(f=>f.pattern.test(s)))==null?void 0:c.era)??"",m=Vt(s,u)??"",h=u||(m?wt[m]??"":"");if(h||m)return{era:Qe(h),reign:m,source:"publication"}}const a=e.edition||e.title||"";if(a){const p=zt(a);if(p)return{era:Qe(p),reign:Vt(a,p)??"",source:"edition"};const u=cn.find(m=>m.pattern.test(a));if(u)return{era:Qe(u.era),reign:Vt(a,u.era)??u.reign??"",source:"edition"}}return n}function wi(e){var r,s,a,l,d,c,p,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=(a=e.publication_info)==null?void 0:a.year;if(n){const h=ki(n);if(h)return h.from}const o=[(l=e.lineage)==null?void 0:l.year_text,(d=e.publication_info)==null?void 0:d.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const h of o){const f=((c=e.publication_info)==null?void 0:c.year)||((p=e.lineage)==null?void 0:p.year_text);if(f&&h!==f&&(zt(f)||qo(f)))break;const x=h.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??h.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(x){const j=parseInt(x[1],10);if(j>=100&&j<=2100)return j}const k=h.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(k){const j=zt(h);if(!j||Qe(j)==="民國"){const v=ci(k[1]);if(v!=null&&v>=1&&v<=120)return Cm+v}}const y=zt(h)??((u=cn.find(j=>j.pattern.test(h)))==null?void 0:u.era),w=y?Qe(y):void 0,b=Vt(h,w)??(zt(h)||(m=cn.find(j=>j.pattern.test(h)))==null?void 0:m.reign);if(b){const j=Dt(b,w);if(j==null)continue;const S=h.indexOf(b),v=S>=0?h.slice(S+b.length):"",$=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),_=$?ci($[1]):void 0;return j+(_?_-1:0)}}}function Xo(e){var l,d,c,p,u,m;const n=(l=e.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const o=(d=e.lineage)==null?void 0:d.year_range;if(o&&o.length===2)return{from:o[0],to:o[1]};const r=(c=e.lineage)==null?void 0:c.year_text;if(r){const h=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const f=fo[Qe(h[1])],x=Ut[Qe(h[2])];if(f!=null&&x!=null)return{from:Math.min(f,x)-20,to:Math.max(f,x)+40}}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const h=ki(s);if((h==null?void 0:h.to)!=null)return{from:h.from,to:h.to};const f=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const x=fo[Qe(f[1])],k=Ut[Qe(f[2])];if(x!=null&&k!=null)return{from:Math.min(x,k)-20,to:Math.max(x,k)+40}}}const a=[(u=e.publication_info)==null?void 0:u.year,e.edition,e.title].filter(Boolean);for(const h of a){if(!/[間间]/.test(h))continue;const f=zt(h)??qo(h)??((m=cn.find(y=>y.pattern.test(h)))==null?void 0:m.era),x=f?Qe(f):void 0,k=[];for(const y of Object.keys(dn))h.includes(y)&&(x&&wt[y]&&wt[y]!==x||Dt(y,x)!=null&&k.push(y));if(k.length===0){const y=h.match(/([一-鿿])([一-鿿])[間间]/);if(y&&x){for(const w of[y[1],y[2]])for(const b of Object.keys(dn))if(wt[b]===x&&!(b[0]!==w&&b[b.length-1]!==w)&&Dt(b,x)!=null){k.push(b);break}}}if(k.length>0){const y=k.map(S=>Dt(S,x)).filter(S=>S!=null),w=Math.min(...y),b=k.reduce((S,v)=>Dt(S,x)>=Dt(v,x)?S:v),j=zm(b)??Zi(x??"")??Math.max(...y);return{from:w,to:j>w?j:Zi(x??wt[b]??"")??w}}if(x&&Ut[x]!=null)return{from:Ut[x],to:Zi(x)??Ut[x]}}}const Ut={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Nm=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Rm=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,_s=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function $s(e,n){for(const o of _l){const r=e.indexOf(o);if(r<0)continue;if(o.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Vt(e.slice(r),Qe(o)))continue}const s=Qe(o);if(s===n)continue;const a=e.slice(r),l=Vt(a,s)??"";let d;if(l){const c=Dt(l,s);if(c!=null){const u=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),m=u?ci(u[1]):void 0;d=c+(m?m-1:0)}}return{era:s,reign:l,year:d}}for(const o of cn)if(o.pattern.test(e))return{era:Qe(o.era),reign:o.reign??""}}function Em(e){var w,b,j,S,v;const n=Mn(e),o=((w=e.publication_info)==null?void 0:w.year)??"",r=o?ki(o):void 0;if(!n.era&&!n.reign&&!r)return;const s=e.edition||e.title||"",a=/[間间]/.test(s),l=((b=e.lineage)==null?void 0:b.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),c=n.source==="publication"&&$m.test(o),p=n.source==="publication"&&/[間间]/.test(o),u=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;a||d||c||p?m=void 0:u?m=parseInt(u[2],10):m=wi(e);const h=m==null?Xo(e):void 0;let f;n.source==="publication"&&(c||_s.test(o))?f="uncertain":n.source==="lineage"||n.source==="publication"?f="attested":_s.test(s)||!n.reign&&m==null?f="uncertain":f="inferred";const x=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=e.lineage)==null?void 0:j.year_text)??((S=e.lineage)==null?void 0:S.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,k={era:n.era,reign:n.reign,year:m,yearRange:h,certainty:f,source:n.source==="edition"?"edition":"catalog",basis:x};if(u){const $=l.match(/[、,,]\s*([宋元明清])/);$&&$[1]!==k.era&&(k.laterRepair={era:$[1]})}if(!k.laterRepair&&Rm.test(s)){const $=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);$&&$[1]!==n.era&&(k.laterRepair={era:$[1]})}const y=Nm.find($=>$.re.test(s));if(y){const $=s.search(y.re),_=s.slice($),C=$s(_,n.era)??$s(s,n.era);C&&(k.basedOn={era:C.era,reign:C.reign,year:C.year,relation:y.relation})}return k}const fo={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Zi(e){return fo[e]}function di(e){const n=wi(e);if(n!=null)return n;const o=Xo(e);if(o)return o.from;const r=Mn(e).era;return r?Ut[r]:void 0}const Cs=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function xo(e){const n=Cs.indexOf(e);return n===-1?Cs.length:n}function Im(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const a=s.relation;a==="part_of"?n.belongsTo.push(s):a==="collected_in"?n.collected.push(s):a==="has_part"||a==="contains_text_of"?n.contains.push(s):a==="text_carried_by"||a==="studied_by"||a==="derived_from"||a==="followed_by"||a==="has_adaptation"?n.derivative.push(s):a==="studies"||a==="preceded_by"?n.studies.push(s):n.related.push(s)}const o=[],r=(s,a)=>{n[s].length&&o.push({key:s,labelKey:a,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),o}function Zo(e,n){const o=Mo(e||[]),r=new Map,s=[];for(const p of o)p.group?(r.has(p.group)||r.set(p.group,[]),r.get(p.group).push(p)):s.push(p);for(const p of r.values())p.sort((u,m)=>{const h=f=>f.group_role==="origin"?0:f.group_role==="mirror"?1:2;return h(u)-h(m)});const a={text:[],image:[],textImage:[],physical:[]};for(const p of s){const u=qt(p),m=u.includes("text"),h=u.includes("image");m&&h?a.textImage.push(p):m?a.text.push(p):h?a.image.push(p):a.physical.push(p)}const d=["text","image","textImage","physical"].filter(p=>a[p].length>0).map(p=>({key:p,items:a[p]})),c=[...r.entries()].map(([p,u])=>{var m,h;return{key:p,label:((m=n==null?void 0:n[p])==null?void 0:m.label)||p,description:(h=n==null?void 0:n[p])==null?void 0:h.description,items:u}});return{buckets:d,mirrors:c,total:o.length}}function Si(e,n=mn("zh-Hant")){const o=[],r=e.metadata||{};r.edition&&o.push(String(r.edition)),e.source_label&&o.push(e.source_label),e.details&&o.push(e.details);const s=fi(e);return s&&s.expected>0&&o.push(s.missing>0?n("detail.volumeStatsMissing",{found:s.found,expected:s.expected,missing:s.missing}):n("detail.volumeStats",{found:s.found,expected:s.expected})),r.version&&o.push(String(r.version)),o.join(" · ")}function Cl(e,n){if(Si(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 a=r.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}function zl(e,n){var a,l;const o=e.resources||[],r=[],s=[];for(const d of o){const c=qt(d);c.includes("image")&&r.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:Mn(e),year:wi(e),sortYear:di(e),images:r,holders:s,locationName:(a=e.current_location)==null?void 0:a.name,important:Lm(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:r.length>0}}function Lm(e,n){var d,c;if(!n)return!1;const o=n.default_collection;if(!o)return!1;const r=(d=n.collections)==null?void 0:d[o];if(((r==null?void 0:r.book_ids)??(o==="core"?n.core_books??[]:[])).includes(e))return!0;const a=(r==null?void 0:r.groups)??[],l=(c=n.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function Tl(e,n,o={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!r.has(c.id)).map(c=>zl(c,n));let a=s;o.era&&(a=a.filter(c=>c.era.era===o.era)),o.scanOnly&&(a=a.filter(c=>c.hasImage)),o.sort==="year"?a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const u=c.r.sortYear,m=p.r.sortYear;return u!=null&&m!=null?u-m||c.i-p.i:u!=null?-1:m!=null?1:c.i-p.i}).map(c=>c.r):a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const u=m=>(m.important?0:1)*2+(m.hasImage?0:1);return u(c.r)-u(p.r)||c.i-p.i}).map(c=>c.r);const d=[...new Set(s.map(c=>c.era.era).filter(Boolean))].sort((c,p)=>xo(c)-xo(p));return{rows:a,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function Am(e,n){var y,w;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)??[],a=r.length>0||s.length>0,l=!a&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!a&&l.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...s,...l]),p=b=>{if(c.has(b))return!0;const j=n.node_groups[b];return j!=null&&d.has(j)},u=[],m=new Map,h=[];for(const b of e)if(!((w=n.excluded_books)!=null&&w.includes(b)))if(p(b))u.push(b);else{const j=n.node_groups[b];j?(m.has(j)||m.set(j,[]),m.get(j).push(b)):h.push(b)}if(h.length+[...m.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const x=new Map((n.groups??[]).map(b=>[b.id,b])),k=[...m.entries()].map(([b,j])=>{const S=x.get(b);return{id:b,label:(S==null?void 0:S.label)??b,description:S==null?void 0:S.description,ids:j}});return h.length>0&&k.push({id:"__other__",label:"其他版本",description:void 0,ids:h}),{useGrouping:!0,coreIds:u,groupedIds:k}}const Nl=["撰","編","注","校","譯","繪","其他"],Pm=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Jo(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:o,re:r}of Pm)if(r.test(n))return o;return"其他"}function Qo(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Rl(e,n="全部"){const o=new Map;for(const s of e){const a=Jo(s);o.set(a,(o.get(a)??0)+1)}const r=[{cls:"全部",label:n,count:e.length}];for(const s of Nl){const a=o.get(s);a&&r.push({cls:s,label:s,count:a})}return r.length>2?r:[]}function El(e,n,o){if(n&&n.books&&n.books.length>0){const s=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),a=[...new Set(s.map(l=>l.section).filter(Boolean))];return{rows:s,source:"catalog",sections:a,totalVolumes:n.total_volumes}}return e.contained_works&&e.contained_works.length>0?{rows:e.contained_works.map(a=>({id:a.id,title:a.title,volumes:In(a.volume_index)})),source:"works",sections:[]}:{rows:(e.books||[]).map(s=>{var a,l;return{id:s,title:((a=o==null?void 0:o.get(s))==null?void 0:a.title)||s,edition:(l=o==null?void 0:o.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function In(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,a)=>o+a)}return e.split(/[,、]/).map(o=>parseInt(o.trim())).filter(o=>!isNaN(o))}return[]}function _i(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const o=[...e].sort((a,l)=>a-l),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 Mm=["〇","一","二","三","四","五","六","七","八","九"],zs=["","十","百","千"];function Il(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),o=n.length;let r="",s=!1;for(let a=0;a<o;a++){const l=parseInt(n[a]),d=o-1-a;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&d===1&&a===0?r+=zs[d]:r+=Mm[l]+zs[d])}return r}function Bm(e){return e==null?"":typeof e=="string"?e:e.title??""}function Nt(e,n="卷"){var r,s;const o=e;return o.measure_info?o.measure_info:(r=o.juan_count)!=null&&r.number?Il(o.juan_count.number)+n:(s=o.juan_count)!=null&&s.description?o.juan_count.description:""}function Ll(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,a]of o)if(s.test(n))return a;return""}const Wm=216,Ts="clamp(280px, 23vw, 360px)",Om=1440,bo="(max-width: 719px)",Hm=`${bo}, (pointer: coarse)`,Fm=`
639
+ .bim-d-main.bim-d-main-grid { max-width: ${Om}px; padding: 16px 32px 0; }
640
640
  .bim-d-grid {
641
641
  display: grid;
642
- grid-template-columns: ${Mm}px minmax(0, 1fr) ${Cs};
642
+ grid-template-columns: ${Wm}px minmax(0, 1fr) ${Ts};
643
643
  grid-template-rows: auto 1fr;
644
644
  grid-template-areas: "rail main card" "rail main side";
645
645
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -977,7 +977,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
977
977
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
978
978
 
979
979
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
980
- @media ${Wm} {
980
+ @media ${Hm} {
981
981
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
982
982
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
983
983
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -1015,7 +1015,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1015
1015
  /* 中等宽度:左栏折到顶部一行 */
1016
1016
  @media (max-width: 1100px) {
1017
1017
  .bim-d-grid {
1018
- grid-template-columns: minmax(0, 1fr) ${Cs};
1018
+ grid-template-columns: minmax(0, 1fr) ${Ts};
1019
1019
  grid-template-rows: auto auto 1fr;
1020
1020
  grid-template-areas: "rail rail" "main card" "main side";
1021
1021
  }
@@ -1029,7 +1029,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1029
1029
  }
1030
1030
 
1031
1031
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
1032
- @media ${fo} {
1032
+ @media ${bo} {
1033
1033
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
1034
1034
  .bim-d-grid {
1035
1035
  grid-template-columns: minmax(0, 1fr);
@@ -1104,7 +1104,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1104
1104
  :root[data-layout="boxed"] .bim-d-g-rail { border: ${i("fr-bd")}; background: ${i("fr-bg")}; padding: 14px 8px; }
1105
1105
  :root[data-layout="boxed"] .bim-d-filters { border-bottom: 1px solid ${i("fr-tab-bd")}; }
1106
1106
  :root[data-layout="boxed"] .bim-d-filters .bim-d-tab { margin-bottom: -1px; }
1107
- @media ${fo} {
1107
+ @media ${bo} {
1108
1108
  :root[data-layout="boxed"] .bim-d-card { padding: 16px; }
1109
1109
  :root[data-layout="boxed"] .bim-d-g-rail { border: 0; background: transparent; padding: 0; }
1110
1110
  }
@@ -1119,7 +1119,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1119
1119
  :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 {
1120
1120
  text-decoration-color: currentColor; text-decoration-thickness: 2px;
1121
1121
  }
1122
- `;function Pn({railTop:e,back:n,up:o,nav:r,railLinks:s,main:a,card:l,side:d}){const{t:c,convert:p}=J(),u=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),o,u.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("detail.pageNav"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("detail.thisPage")}),t.jsx("ul",{className:"bim-d-rail-nav",children:u.map(m=>t.jsx("li",{children:t.jsxs("a",{href:`#${m.id}`,children:[t.jsx("span",{children:p(m.label)}),m.count!=null&&t.jsx("span",{className:"bim-d-meta",children:m.count})]})},m.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("detail.more"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("detail.more")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(m=>t.jsx("li",{children:t.jsxs("a",{href:m.href??"#",onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),m.onClick())},children:[t.jsx("span",{children:p(m.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},m.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:a}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:d})]})}function Rl({caption:e,children:n}){const{convert:o}=J();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:o(e)}),n]})}function tt({id:e,title:n,meta:o,action:r,children:s}){const{convert:a}=J();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:a(n)}),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),t.jsx("div",{className:"bim-d-sec-body",children:s})]})}function et({items:e,className:n,style:o}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:o,children:r.map((s,a)=>t.jsxs(g.Fragment,{children:[a>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},a))}):null}function Si({items:e,value:n,onChange:o}){const{convert:r}=J();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>o(s.key),children:r(s.label)},s.key))})}function Ll({label:e,checked:n,onChange:o}){const{convert:r}=J();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>o(s.target.checked)}),r(e)]})}const Al=6,_i=e=>e>Al+1;function Jo({total:e,shown:n,unit:o,onClick:r}){const{t:s,convert:a}=J(),l=e-n,d=_i(e)?e-Math.min(n,Al):l;return d<=0?null:t.jsxs("button",{type:"button",className:`bim-d-more bim-d-ui${l>0?"":" bim-d-more-ncap"}`,onClick:r,children:[l>0&&t.jsx("span",{className:"bim-d-more-w",children:s("detail.expandRest",{n:l,unit:a(o)})}),t.jsx("span",{className:"bim-d-more-n",children:s("detail.expandRest",{n:d,unit:a(o)})})]})}function Qo({label:e,onClick:n}){const{convert:o}=J();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:o(e)})}function Mn({kind:e,title:n,subtitle:o,byline:r,meta:s,description:a,clampDescription:l,facts:d,stats:c,readAction:p,secondaryAction:u,children:m,foot:h}){const{t:f,convert:x}=J(),k=(d||[]).filter(S=>S.value!=null&&S.value!==""),y=(c||[]).filter(S=>S.value!=null&&S.value!==""&&S.value!==0),[w,b]=g.useState(!1),j=!!l&&!w;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:x(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),o&&t.jsx("div",{className:"bim-d-card-sub",children:o}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),a&&t.jsx("div",{className:j?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:j?{"--detail-clamp":l}:void 0,children:a}),a&&!!l&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":w,onClick:()=>b(S=>!S),children:f(w?"action.collapse":"action.expand")}),y.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:y.map((S,v)=>t.jsxs("div",{children:[t.jsx("b",{children:S.value}),t.jsx("span",{children:x(S.label)})]},v))}),k.length>0&&t.jsx("dl",{className:"bim-d-ui",children:k.map((S,v)=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:x(S.label)}),t.jsx("dd",{title:S.title,children:S.value})]},v))}),m,p,u,h&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:h})]})}function er(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function xo({href:e,onClick:n,label:o}){const{t:r,convert:s}=J(),a=o??r("detail.read");return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n())}:void 0,children:s(a)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:s(a)})}function Gt({id:e,title:n,meta:o,items:r,metas:s,currentIndex:a,cap:l=8,moreLabel:d,foot:c,sub:p,timeline:u}){const{t:m,convert:h}=J(),[f,x]=g.useState(!1);if(!r.length)return null;const k=f?r:r.slice(0,l),y=r.length-k.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[h(n),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o})]}),p&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:p}),t.jsx("ul",{children:k.map((w,b)=>t.jsxs("li",{className:b===a?"bim-d-side-cur":void 0,"aria-current":b===a?"page":void 0,children:[w,s!=null&&s[b]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[b]}):null]},b))}),y>0&&t.jsx(Qo,{label:d?d(y):m("detail.showMore",{n:y}),onClick:()=>x(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const Hm=new Set(["reviewed","disputed","unreviewed","draft"]);function Bn({revision:e,revisedAt:n,review:o,todo:r}){const{t:s,convert:a}=J(),l=o&&Hm.has(o.status)?s(`detail.review.${o.status}`):void 0,d=o&&o.status!=="unreviewed"&&l?[l,o.by,o.date].filter(Boolean).join(" "):"",c=[e!=null&&e!==""?`${s("detail.dataVersion")} ${e}`:"",n??"",a(d)].filter(Boolean),p=(r||[]).filter(u=>u&&u.what);return!c.length&&!p.length?null:t.jsxs(t.Fragment,{children:[c.length>0&&t.jsx(et,{items:c,style:{fontSize:12}}),p.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s("detail.todoCount",{n:p.length})}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:p.map((u,m)=>t.jsxs("li",{children:[a(u.what),(u.by||u.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[u.by&&a(u.by),u.date].filter(Boolean).join(" · "),")"]})]},m))})]})]})}const ni=1e3,zs=208,Fm=1440,Dm="(max-width: 719px)",Pl=`
1122
+ `;function Bn({railTop:e,back:n,up:o,nav:r,railLinks:s,main:a,card:l,side:d}){const{t:c,convert:p}=J(),u=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),o,u.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("detail.pageNav"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("detail.thisPage")}),t.jsx("ul",{className:"bim-d-rail-nav",children:u.map(m=>t.jsx("li",{children:t.jsxs("a",{href:`#${m.id}`,children:[t.jsx("span",{children:p(m.label)}),m.count!=null&&t.jsx("span",{className:"bim-d-meta",children:m.count})]})},m.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("detail.more"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("detail.more")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(m=>t.jsx("li",{children:t.jsxs("a",{href:m.href??"#",onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),m.onClick())},children:[t.jsx("span",{children:p(m.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},m.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:a}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:d})]})}function Al({caption:e,children:n}){const{convert:o}=J();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:o(e)}),n]})}function tt({id:e,title:n,meta:o,action:r,children:s}){const{convert:a}=J();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:a(n)}),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),t.jsx("div",{className:"bim-d-sec-body",children:s})]})}function et({items:e,className:n,style:o}){const r=e.filter(s=>s!=null&&s!==""&&s!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:o,children:r.map((s,a)=>t.jsxs(g.Fragment,{children:[a>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},a))}):null}function $i({items:e,value:n,onChange:o}){const{convert:r}=J();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...r(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>o(s.key),children:r(s.label)},s.key))})}function Pl({label:e,checked:n,onChange:o}){const{convert:r}=J();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>o(s.target.checked)}),r(e)]})}const Ml=6,Ci=e=>e>Ml+1;function er({total:e,shown:n,unit:o,onClick:r}){const{t:s,convert:a}=J(),l=e-n,d=Ci(e)?e-Math.min(n,Ml):l;return d<=0?null:t.jsxs("button",{type:"button",className:`bim-d-more bim-d-ui${l>0?"":" bim-d-more-ncap"}`,onClick:r,children:[l>0&&t.jsx("span",{className:"bim-d-more-w",children:s("detail.expandRest",{n:l,unit:a(o)})}),t.jsx("span",{className:"bim-d-more-n",children:s("detail.expandRest",{n:d,unit:a(o)})})]})}function tr({label:e,onClick:n}){const{convert:o}=J();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:o(e)})}function Wn({kind:e,title:n,subtitle:o,byline:r,meta:s,description:a,clampDescription:l,facts:d,stats:c,readAction:p,secondaryAction:u,children:m,foot:h}){const{t:f,convert:x}=J(),k=(d||[]).filter(S=>S.value!=null&&S.value!==""),y=(c||[]).filter(S=>S.value!=null&&S.value!==""&&S.value!==0),[w,b]=g.useState(!1),j=!!l&&!w;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:x(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),o&&t.jsx("div",{className:"bim-d-card-sub",children:o}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),a&&t.jsx("div",{className:j?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:j?{"--detail-clamp":l}:void 0,children:a}),a&&!!l&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":w,onClick:()=>b(S=>!S),children:f(w?"action.collapse":"action.expand")}),y.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:y.map((S,v)=>t.jsxs("div",{children:[t.jsx("b",{children:S.value}),t.jsx("span",{children:x(S.label)})]},v))}),k.length>0&&t.jsx("dl",{className:"bim-d-ui",children:k.map((S,v)=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:x(S.label)}),t.jsx("dd",{title:S.title,children:S.value})]},v))}),m,p,u,h&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:h})]})}function nr(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function yo({href:e,onClick:n,label:o}){const{t:r,convert:s}=J(),a=o??r("detail.read");return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n())}:void 0,children:s(a)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:s(a)})}function Yt({id:e,title:n,meta:o,items:r,metas:s,currentIndex:a,cap:l=8,moreLabel:d,foot:c,sub:p,timeline:u}){const{t:m,convert:h}=J(),[f,x]=g.useState(!1);if(!r.length)return null;const k=f?r:r.slice(0,l),y=r.length-k.length;return t.jsxs("div",{id:e,className:u?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[h(n),o!=null&&o!==""&&t.jsx("span",{className:"bim-d-meta",children:o})]}),p&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:p}),t.jsx("ul",{children:k.map((w,b)=>t.jsxs("li",{className:b===a?"bim-d-side-cur":void 0,"aria-current":b===a?"page":void 0,children:[w,s!=null&&s[b]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[b]}):null]},b))}),y>0&&t.jsx(tr,{label:d?d(y):m("detail.showMore",{n:y}),onClick:()=>x(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const Dm=new Set(["reviewed","disputed","unreviewed","draft"]);function On({revision:e,revisedAt:n,review:o,todo:r}){const{t:s,convert:a}=J(),l=o&&Dm.has(o.status)?s(`detail.review.${o.status}`):void 0,d=o&&o.status!=="unreviewed"&&l?[l,o.by,o.date].filter(Boolean).join(" "):"",c=[e!=null&&e!==""?`${s("detail.dataVersion")} ${e}`:"",n??"",a(d)].filter(Boolean),p=(r||[]).filter(u=>u&&u.what);return!c.length&&!p.length?null:t.jsxs(t.Fragment,{children:[c.length>0&&t.jsx(et,{items:c,style:{fontSize:12}}),p.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s("detail.todoCount",{n:p.length})}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:p.map((u,m)=>t.jsxs("li",{children:[a(u.what),(u.by||u.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[u.by&&a(u.by),u.date].filter(Boolean).join(" · "),")"]})]},m))})]})]})}const oi=1e3,Ns=208,Um=1440,Vm="(max-width: 719px)",Bl=`
1123
1123
  .bim-d-page {
1124
1124
  background: ${i("page-bg")};
1125
1125
  color: ${i("ink")};
@@ -1128,7 +1128,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1128
1128
  padding-bottom: 64px;
1129
1129
  }
1130
1130
  .bim-d-main {
1131
- max-width: ${ni}px;
1131
+ max-width: ${oi}px;
1132
1132
  margin: 0 auto;
1133
1133
  padding: 24px clamp(16px, 4vw, 28px) 0;
1134
1134
  }
@@ -1139,7 +1139,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1139
1139
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
1140
1140
  */
1141
1141
  .bim-d-main.bim-d-main-wide {
1142
- max-width: ${Fm}px;
1142
+ max-width: ${Um}px;
1143
1143
  }
1144
1144
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
1145
1145
 
@@ -1171,9 +1171,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1171
1171
  */
1172
1172
  .bim-d-reader {
1173
1173
  display: grid;
1174
- grid-template-columns: ${zs}px minmax(0, ${ni}px);
1174
+ grid-template-columns: ${Ns}px minmax(0, ${oi}px);
1175
1175
  gap: 32px;
1176
- max-width: ${zs+ni+32}px;
1176
+ max-width: ${Ns+oi+32}px;
1177
1177
  margin: 0 auto;
1178
1178
  align-items: start;
1179
1179
  }
@@ -1196,7 +1196,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1196
1196
  align-items: start; margin-bottom: 48px; }
1197
1197
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
1198
1198
 
1199
- @media ${Dm} {
1199
+ @media ${Vm} {
1200
1200
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
1201
1201
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
1202
1202
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -1214,16 +1214,16 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
1214
1214
  padding-right: 0; padding-bottom: 12px;
1215
1215
  }
1216
1216
  }
1217
- ${Om}`;function zn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Pl}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":o?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function bo({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:i("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function tr({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:i(n==="accent"?"accent":"ink"),color:i("page-bg")},children:e})}function yo({items:e}){const n=Je();return t.jsx(t.Fragment,{children:e.map((o,r)=>{const s=r===e.length-1,a=r>0&&t.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${r}`),l=o.id?n(o.id):o.href,d=s||!o.onClick&&!l?t.jsx("span",{style:{color:i("ink")},children:o.label},r):t.jsx("a",{href:l??"#",onClick:o.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),o.onClick())}:void 0,style:{color:i("meta-fg")},children:o.label},r);return t.jsxs(g.Fragment,{children:[a,d]},r)})})}function Ml({title:e,subtitle:n,aside:o,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${i("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:i("meta-fg"),letterSpacing:".06em"},children:n})]}),o&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:o})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:r})]})}function Um({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function Vm({items:e,horizontal:n}){const{convert:o}=Re();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${i("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:i("label-fg"),letterSpacing:".08em",flex:"none"},children:o(r.label)}),t.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function Gm({glyph:e,tone:n,title:o,count:r,actions:s,id:a}){const{convert:l}=Re();return t.jsxs("div",{id:a,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(tr,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(o)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Bl({label:e,active:n,onClick:o,dashed:r}){const{convert:s}=Re();return t.jsx("button",{type:"button",onClick:o,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${i(n?"accent":"rule")}`,background:n?i("accent"):"transparent",color:i(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function Ym({label:e,onClick:n}){const{convert:o}=Re();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:o(e)})}function Km({label:e,onClick:n,inline:o}){const{convert:r}=Re();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:o?0:12,width:o?void 0:"100%",padding:o?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:o?void 0:".08em"},children:r(e)})}function Wl({children:e,href:n,onClick:o,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||o?t.jsx("a",{href:n??"#",title:r,onClick:o?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function qm({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Xm({volumes:e,unit:n,max:o=60}){const{t:r}=J(),s=n??r("unit.volume"),[a,l]=g.useState(!1);if(!e.length)return null;const d=a?e:e.slice(0,o);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[d.map(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${i("rule")}`,color:i("meta-fg")},children:c},c)),!a&&e.length>o&&t.jsxs("button",{type:"button",onClick:()=>l(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${i("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:i("meta-fg")},children:["+",e.length-o]}),t.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:s})]})}function Zm({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:e})}function Jm({spec:e}){const{convert:n}=Re();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${i("rule-strong")}`,fontSize:11,color:i("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(o=>o.width).join(" "),gap:12},children:e.columns.map(o=>t.jsx("span",{children:n(o.label)},o.label))})]})}function Qm({no:e,main:n,meta:o,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:o})]})}function eh(e){return String(e+1).padStart(2,"0")}function th(){return t.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function nh({open:e,onToggle:n,main:o,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${i(e?"accent":"rule-dashed")}`,background:e?i("accent"):"transparent",color:i(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:o}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function Ol(e){const n=[];for(let o=0;o<e.length;o++){const r=e[o];let s;if(r==="⟨")s="⟩";else if(r==="<"){const d=e[o+1];if(d===void 0||/[A-Za-z/!?>\s]/.test(d))continue;s=">"}else continue;const a=e.indexOf(s,o+1);if(a<0)continue;const l=e.slice(o+1,a);l.includes(`
1218
- `)||(n.push({start:o,end:a+1,inner:l}),o=a)}return n}function Hl(e,n){if(e.length<=n)return e;let o=n;for(const r of Ol(e)){if(r.start>=o)break;if(r.end>o){o=r.start>0?r.start:r.end;break}}return e.slice(0,o)}const Fl={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},ih={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 Dl(e,n,o,r){return e.map((s,a)=>{switch(s.type){case"text":return t.jsx(g.Fragment,{children:n(s.text)},a);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:o===0?Fl:void 0,children:Dl(s.children,n,o+1,r)},a);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:s.label?r("detail.lacunaWith",{label:s.label}):r("detail.lacuna"),children:"□"},a);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":s.guess,children:"□"},a);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:r("detail.composedChar",{label:s.label}),style:ih,children:s.label},a)}})}function mt(e,n=r=>r,o){if(!e)return"";if(o!=null&&o.gujiMarkdown)return tm(e)?Dl(ol(e),n,0,o.t??un("zh-Hant")):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,a=0;for(const l of Ol(e))l.start>s&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s,l.start))},a++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Fl,children:n(l.inner)},a++)),s=l.end;return s<e.length&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s))},a++)),r}function oh({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:i("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function rh({title:e,tag:n,children:o}){const{convert:r}=Re();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:o})]})}function Ul({name:e,note:n,href:o,extra:r}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:i("hint-fg"),flex:"none"},children:o?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:i("label-fg")},children:n})]}),a={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${i("rule")}`,color:i("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[o?t.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:a,children:s}):t.jsx("div",{style:a,children:s}),r]})}function sh({item:e,siblings:n,showVolumes:o=!0,fallbackNote:r}){const{t:s,convert:a}=J(),[l,d]=g.useState(!1),c=hi(e),p=o&&!!c&&c.expected>0,u=(e.url?mn(e.url):void 0)||a(e.name),m=n?_l(e,n):"",h=m?`${u}(${m})`:u;return t.jsx(Ul,{name:h,note:ki(e,s)||r,href:hn(e),extra:p?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(f=>!f),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:l?s("detail.collapseVolumes"):s("detail.expandVolumes",{n:c.expected})}),l&&t.jsx(nr,{item:e})]}):void 0})}function nr({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,o)=>{const r=n.status==="missing";return n.url&&!r?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:i("zebra-bg")},children:n.volume},o):t.jsx("span",{style:{padding:"1px 5px",color:i(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},o)})})}function Vl({label:e,items:n}){const{convert:o}=Re();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(Wl,{children:o(r)},s))]}):null}function ah({rows:e}){const n=e.filter(o=>o.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(o=>t.jsx(Vl,{label:o.label,items:o.items},o.label))}):null}function jo(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Gl({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:i("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function lh({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:i("aux-fg"),borderBottom:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Ze({id:e,label:n,onNavigate:o,renderLink:r,style:s,dense:a}){const l=Je();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:a})}):t.jsx("a",{href:l(e),onClick:o?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(e))}:void 0,style:s,children:n??e})}function ch({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const dh={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ph={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},uh=`1px solid ${i("table-border")}`,Yl={border:uh,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},mh={...Yl,background:i("table-head-bg"),fontWeight:600};function ir({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:dh,children:t.jsx("table",{className:"bim-guji-table",style:ph,children:t.jsx("tbody",{children:e.rows.map((o,r)=>t.jsx("tr",{children:o.cells.map((s,a)=>{const l=o.header?"th":"td";return t.jsx(l,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:o.header?mh:Yl,children:s.empty?null:mt(s.text,void 0,n)},a)})},r))})})})}function hh(e,n){return e.indexOf("**")<0?mt(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:mt(r.trim().slice(2,-2),void 0,n)},s):t.jsx(g.Fragment,{children:mt(r,void 0,n)},s))}function gh(e,n,o=!1){const r=o?{gujiMarkdown:!0}:void 0;return n?Uo(e).map((s,a)=>s.type==="table"?t.jsx(ir,{table:s.table,opts:r},a):t.jsx(g.Fragment,{children:hh(s.text,r)},a)):mt(e,void 0,r)}const fh=/^(#{1,6})\s+(.*)$/,xh=/^\*\*([^*\n]+)\*\*\s*$/;function or(e){const n=e.match(fh);if(n)return{level:n[1].length,text:n[2].trim()};const o=e.trim().match(xh);return o?{level:3,text:o[1].trim()}:null}const rr=/^<!--.*-->$/;function Kl(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function ql(e){return e.split(`
1219
- `).map(n=>n.trim()).filter(n=>n&&!rr.test(n))}const bh=60;function Xl(e){let n=0,o=0;for(const r of e.split(`
1220
- `)){const s=r.trim();if(!s||rr.test(s)||or(s))continue;const a=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=a,a>bh&&(o+=a)}return n>0&&o*2>=n}function yh(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function $i(e){if(e=yh(e),Xl(e))return"unknown";const n=Kl(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const o=n.map(s=>ql(s).length).filter(s=>s>0);if(o.length===0)return"unknown";const r=o.reduce((s,a)=>s+a,0)/o.length;return r<=4?"record":r>=8?"catalog":"unknown"}function jh(e){const n=e.split(`
1217
+ ${Fm}`;function Nn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Bl}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":o?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function jo({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:i("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function ir({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:i(n==="accent"?"accent":"ink"),color:i("page-bg")},children:e})}function vo({items:e}){const n=Ze();return t.jsx(t.Fragment,{children:e.map((o,r)=>{const s=r===e.length-1,a=r>0&&t.jsx("span",{style:{color:i("hint-fg")},children:"/"},`s${r}`),l=o.id?n(o.id):o.href,d=s||!o.onClick&&!l?t.jsx("span",{style:{color:i("ink")},children:o.label},r):t.jsx("a",{href:l??"#",onClick:o.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),o.onClick())}:void 0,style:{color:i("meta-fg")},children:o.label},r);return t.jsxs(g.Fragment,{children:[a,d]},r)})})}function Wl({title:e,subtitle:n,aside:o,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${i("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:i("meta-fg"),letterSpacing:".06em"},children:n})]}),o&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".06em"},children:o})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:i("quiet-fg")},children:r})]})}function Gm({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${i("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function Ym({items:e,horizontal:n}){const{convert:o}=Ae();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${i("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((r,s)=>t.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:i("label-fg"),letterSpacing:".08em",flex:"none"},children:o(r.label)}),t.jsx("span",{style:{color:i("body-fg"),textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function Km({glyph:e,tone:n,title:o,count:r,actions:s,id:a}){const{convert:l}=Ae();return t.jsxs("div",{id:a,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(ir,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(o)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg")},children:r})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Ol({label:e,active:n,onClick:o,dashed:r}){const{convert:s}=Ae();return t.jsx("button",{type:"button",onClick:o,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${i(n?"accent":"rule")}`,background:n?i("accent"):"transparent",color:i(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function qm({label:e,onClick:n}){const{convert:o}=Ae();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:o(e)})}function Xm({label:e,onClick:n,inline:o}){const{convert:r}=Ae();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:o?0:12,width:o?void 0:"100%",padding:o?"4px 12px":9,background:"none",border:`1px dashed ${i("rule-dashed")}`,cursor:"pointer",fontSize:12,color:i("meta-fg"),letterSpacing:o?void 0:".08em"},children:r(e)})}function Hl({children:e,href:n,onClick:o,title:r}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${i("rule")}`,fontSize:13,color:i("body-fg"),lineHeight:1.5};return n||o?t.jsx("a",{href:n??"#",title:r,onClick:o?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),o())}:void 0,style:s,children:e}):t.jsx("span",{title:r,style:s,children:e})}function Zm({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Jm({volumes:e,unit:n,max:o=60}){const{t:r}=J(),s=n??r("unit.volume"),[a,l]=g.useState(!1);if(!e.length)return null;const d=a?e:e.slice(0,o);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[d.map(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${i("rule")}`,color:i("meta-fg")},children:c},c)),!a&&e.length>o&&t.jsxs("button",{type:"button",onClick:()=>l(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${i("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:i("meta-fg")},children:["+",e.length-o]}),t.jsx("span",{style:{padding:"2px 6px",color:i("hint-fg")},children:s})]})}function Qm({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${i("rule-strong")}`},children:e})}function eh({spec:e}){const{convert:n}=Ae();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${i("rule-strong")}`,fontSize:11,color:i("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(o=>o.width).join(" "),gap:12},children:e.columns.map(o=>t.jsx("span",{children:n(o.label)},o.label))})]})}function th({no:e,main:n,meta:o,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:o})]})}function nh(e){return String(e+1).padStart(2,"0")}function ih(){return t.jsx("span",{style:{color:i("hint-fg")},children:"—"})}function oh({open:e,onToggle:n,main:o,action:r,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${i("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${i(e?"accent":"rule-dashed")}`,background:e?i("accent"):"transparent",color:i(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:o}),r]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${i("rule-accent-soft")}`,marginLeft:12},children:s})]})}function Fl(e){const n=[];for(let o=0;o<e.length;o++){const r=e[o];let s;if(r==="⟨")s="⟩";else if(r==="<"){const d=e[o+1];if(d===void 0||/[A-Za-z/!?>\s]/.test(d))continue;s=">"}else continue;const a=e.indexOf(s,o+1);if(a<0)continue;const l=e.slice(o+1,a);l.includes(`
1218
+ `)||(n.push({start:o,end:a+1,inner:l}),o=a)}return n}function Dl(e,n){if(e.length<=n)return e;let o=n;for(const r of Fl(e)){if(r.start>=o)break;if(r.end>o){o=r.start>0?r.start:r.end;break}}return e.slice(0,o)}const Ul={fontSize:".78em",color:i("meta-fg"),lineHeight:1.55},rh={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 Vl(e,n,o,r){return e.map((s,a)=>{switch(s.type){case"text":return t.jsx(g.Fragment,{children:n(s.text)},a);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:o===0?Ul:void 0,children:Vl(s.children,n,o+1,r)},a);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:s.label?r("detail.lacunaWith",{label:s.label}):r("detail.lacuna"),children:"□"},a);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":s.guess,children:"□"},a);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:r("detail.composedChar",{label:s.label}),style:rh,children:s.label},a)}})}function ht(e,n=r=>r,o){if(!e)return"";if(o!=null&&o.gujiMarkdown)return im(e)?Vl(sl(e),n,0,o.t??mn("zh-Hant")):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const r=[];let s=0,a=0;for(const l of Fl(e))l.start>s&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s,l.start))},a++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Ul,children:n(l.inner)},a++)),s=l.end;return s<e.length&&r.push(t.jsx(g.Fragment,{children:n(e.slice(s))},a++)),r}function sh({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:i("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:i("quiet-fg"),textAlign:"justify"},children:n})]})}function ah({title:e,tag:n,children:o}){const{convert:r}=Ae();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${i("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:i("accent"),letterSpacing:".06em"},children:r(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:o})]})}function Gl({name:e,note:n,href:o,extra:r}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:i("hint-fg"),flex:"none"},children:o?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:i("label-fg")},children:n})]}),a={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${i("rule")}`,color:i("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[o?t.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:a,children:s}):t.jsx("div",{style:a,children:s}),r]})}function lh({item:e,siblings:n,showVolumes:o=!0,fallbackNote:r}){const{t:s,convert:a}=J(),[l,d]=g.useState(!1),c=fi(e),p=o&&!!c&&c.expected>0,u=(e.url?hn(e.url):void 0)||a(e.name),m=n?Cl(e,n):"",h=m?`${u}(${m})`:u;return t.jsx(Gl,{name:h,note:Si(e,s)||r,href:gn(e),extra:p?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(f=>!f),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:i("meta-fg"),borderBottom:`1px solid ${i("rule")}`},children:l?s("detail.collapseVolumes"):s("detail.expandVolumes",{n:c.expected})}),l&&t.jsx(or,{item:e})]}):void 0})}function or({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,o)=>{const r=n.status==="missing";return n.url&&!r?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:i("zebra-bg")},children:n.volume},o):t.jsx("span",{style:{padding:"1px 5px",color:i(r?"missing-fg":"hint-fg"),textDecoration:r?"line-through":void 0},children:n.volume},o)})})}function Yl({label:e,items:n}){const{convert:o}=Ae();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:i("label-fg"),letterSpacing:".08em"},children:e}),n.map((r,s)=>t.jsx(Hl,{children:o(r)},s))]}):null}function ch({rows:e}){const n=e.filter(o=>o.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(o=>t.jsx(Yl,{label:o.label,items:o.items},o.label))}):null}function ko(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Kl({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:i("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function dh({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:i("aux-fg"),borderBottom:`1px solid ${i("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function Xe({id:e,label:n,onNavigate:o,renderLink:r,style:s,dense:a}){const l=Ze();return r?t.jsx(t.Fragment,{children:r(e,typeof n=="string"?n:void 0,{dense:a})}):t.jsx("a",{href:l(e),onClick:o?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(e))}:void 0,style:s,children:n??e})}function ph({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const uh={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},mh={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},hh=`1px solid ${i("table-border")}`,ql={border:hh,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},gh={...ql,background:i("table-head-bg"),fontWeight:600};function rr({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:uh,children:t.jsx("table",{className:"bim-guji-table",style:mh,children:t.jsx("tbody",{children:e.rows.map((o,r)=>t.jsx("tr",{children:o.cells.map((s,a)=>{const l=o.header?"th":"td";return t.jsx(l,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:o.header?gh:ql,children:s.empty?null:ht(s.text,void 0,n)},a)})},r))})})})}function fh(e,n){return e.indexOf("**")<0?ht(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,s)=>s%2===1?t.jsx("strong",{children:ht(r.trim().slice(2,-2),void 0,n)},s):t.jsx(g.Fragment,{children:ht(r,void 0,n)},s))}function xh(e,n,o=!1){const r=o?{gujiMarkdown:!0}:void 0;return n?Go(e).map((s,a)=>s.type==="table"?t.jsx(rr,{table:s.table,opts:r},a):t.jsx(g.Fragment,{children:fh(s.text,r)},a)):ht(e,void 0,r)}const bh=/^(#{1,6})\s+(.*)$/,yh=/^\*\*([^*\n]+)\*\*\s*$/;function sr(e){const n=e.match(bh);if(n)return{level:n[1].length,text:n[2].trim()};const o=e.trim().match(yh);return o?{level:3,text:o[1].trim()}:null}const ar=/^<!--.*-->$/;function Xl(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function Zl(e){return e.split(`
1219
+ `).map(n=>n.trim()).filter(n=>n&&!ar.test(n))}const jh=60;function Jl(e){let n=0,o=0;for(const r of e.split(`
1220
+ `)){const s=r.trim();if(!s||ar.test(s)||sr(s))continue;const a=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=a,a>jh&&(o+=a)}return n>0&&o*2>=n}function vh(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function zi(e){if(e=vh(e),Jl(e))return"unknown";const n=Xl(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const o=n.map(s=>Zl(s).length).filter(s=>s>0);if(o.length===0)return"unknown";const r=o.reduce((s,a)=>s+a,0)/o.length;return r<=4?"record":r>=8?"catalog":"unknown"}function kh(e){const n=e.split(`
1221
1221
  `),o=[];let r=null,s=[];const a=()=>{o.push({heading:r,body:s.join(`
1222
- `)}),s=[]};for(const l of n){const d=or(l);if(d){a(),r={kind:"heading",level:d.level,text:d.text};continue}s.push(l)}return a(),o}function Ts(e){const n=[];for(const o of e.split(`
1223
- `)){const r=or(o);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=o.trim();!s||rr.test(s)||n.push({kind:"body",text:o})}return n}function Zl(e){if(!e)return[];const n=$i(e);if(n==="unknown")return Ts(e);const o=[];for(const{heading:r,body:s}of jh(e)){r&&o.push(r);const a=Kl(s);if(a.length!==0){if(Xl(s)){o.push(...Ts(s));continue}if(n==="record"){const l=a.join(" ");l&&o.push({kind:"body",text:l})}else for(const l of a){const d=ql(l);d.length&&o.push({kind:"body",text:d.join(" ")})}}}return o}const Jl=e=>e;function Ql(e,n=Jl){if(e.indexOf("《")<0)return n(e);const o=[],r=/《([^《》\n]+)》/g;let s=0,a=0,l;for(;l=r.exec(e);)l.index>s&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s,l.index))},a++)),o.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(l[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},a++)),s=l.index+l[0].length;return s===0?n(e):(s<e.length&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s))},a++)),o)}function sr(e,n={}){const o=n.renderText??Jl,r=n.properNames?a=>Ql(a,o):o,s=n.gujiMarkdown?{gujiMarkdown:!0,t:n.t}:void 0;return mt(e,r,s)}function Ns(e,n,o){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,a)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${o}-${a}`):t.jsx(g.Fragment,{children:n(s)},`${o}-${a}`))}const Xi=/^(#{1,6})\s+(.*)$/,vh=/^\s*<!--.*-->\s*$/;function ec(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1224
- `)?"":n)}function kh(e){return e<=1?2:e===2?3:4}function wh(){let e=1;return n=>{const o=kh(n),r=Math.min(o,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${o}`}}}function ci(e){return e?$i(ec(e))!=="unknown":!1}function Sh(e){return/^\u3000{2}/.test(e)}const Es=e=>Sh(e)?"bim-rd-noindent":void 0;function Is({text:e,mode:n,inline:o,dropTitle:r}){const s=ec(e),a=(p,u,m)=>!!r&&m<=1&&p<=2&&u.trim()===r.trim(),l=wh();if(n==="paragraph"&&$i(s)!=="unknown"){const p=Zl(s);return t.jsx(t.Fragment,{children:p.map((u,m)=>{if(u.kind==="heading"){if(a(u.level??1,u.text,m))return null;const{Tag:h,className:f}=l(u.level??1);return t.jsx(h,{className:f,children:o(u.text)},m)}return t.jsx("p",{className:Es(u.text),children:Ns(u.text,o,m)},m)})})}const d=s.split(`
1225
- `);let c=0;return t.jsx(t.Fragment,{children:d.map((p,u)=>{const m=p.match(Xi);if(m){const f=c++;if(a(m[1].length,m[2],f))return null;const{Tag:x,className:k}=l(m[1].length);return t.jsx(x,{className:k,children:o(m[2])},u)}if(!p.trim())return u>=2&&!!d[u-1].trim()&&!!d[u-2].trim()&&!Xi.test(d[u-1])&&!Xi.test(d[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(vh.test(p))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(p.trim())){const{Tag:f,className:x}=l(3);return t.jsx(f,{className:x,children:o(p.trim().slice(2,-2))},u)}return t.jsx("p",{className:Es(p),children:Ns(p,o,u)},u)})})}function _h(e){const{convert:n}=Re();return g.useMemo(()=>e?n(e):"",[e,n])}function ar({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:a,dropTitle:l}){const d=_h(e),{t:c,convert:p}=J(),u=f=>sr(f,{renderText:a,properNames:s,gujiMarkdown:r,t:c}),m=r?{gujiMarkdown:!0,t:c}:void 0,h=l?p(l):void 0;return!o||d.indexOf(":::")<0?t.jsx(Is,{text:d,mode:n,inline:u,dropTitle:h}):t.jsx(t.Fragment,{children:Uo(d).map((f,x)=>f.type==="table"?t.jsx(ir,{table:f.table,opts:m},x):t.jsx(Is,{text:f.text,mode:n,inline:u,dropTitle:x===0?h:void 0},x))})}function $h(e,n,o){const[r,s]=g.useState(null),[a,l]=g.useState(!1),d=g.useRef(0);return g.useEffect(()=>{const c=++d.current;if(!e||!n){s(null),l(!1);return}let p;try{p=e(n,o)}catch{s(null),l(!1);return}if(!p||typeof p.then!="function"){s(p??null),l(!1);return}l(!0),p.then(u=>{c===d.current&&s(u??null)}).catch(()=>{c===d.current&&s(null)}).finally(()=>{c===d.current&&l(!1)})},[e,n,o]),{images:r,loading:a}}const Rs={A:"fine",B:"rough",C:"rough",D:"ocr"};function Ch(e){return typeof e!="string"?null:e in lp?e:e in Rs?Rs[e]:null}const zh={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Th={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"},tc="\0";function Nh(e,n,o){const[r,s=""]=e.split(tc);return t.jsxs(t.Fragment,{children:[r,t.jsx(pl,{text:n,convert:o}),s]})}function ft(e){return typeof e!="string"?"":zh[e]??Th[e]??e}const Eh=["〇","一","二","三","四","五","六","七","八","九"],Ls=["","十","百","千"],Ih=["","萬","億"];function lr(e){if(e===0)return"〇";if(e<0)return`負${lr(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Rh(s,r>0)+Ih[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Rh(e,n){const o=[];let r=e;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let a=0;a<o.length;a++){const l=o[a],d=o.length-1-a;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&d===1&&a===0&&!n?s+=Ls[d]:s+=Eh[l]+Ls[d]}return s.replace(/〇$/,"")}let In=null,Zn=null;const di=new Set;function Lh(){return In?Promise.resolve():Zn||(Zn=import("opencc-js/t2cn").then(e=>{const n=e.Converter({from:"t",to:"cn"});In=o=>n(Se.normalizeVariants(o)),di.forEach(o=>o())}).catch(()=>{In=e=>e,di.forEach(e=>e())}),Zn)}const Ah=e=>e;function Zt(){const[,e]=g.useState(0);return g.useEffect(()=>{if(In)return;const n=()=>e(o=>o+1);return di.add(n),Lh(),()=>{di.delete(n)}},[]),In??Ah}function dn(e,n){return n(e).toLowerCase()}const Ph=i("highlight-bg");function Wn(e,n,o){if(!n)return e;const r=dn(n,o);if(!r)return e;const s=dn(e,o);if(s.length!==e.length)return e;const a=[];let l=0,d=0;for(;l<e.length;){const c=s.indexOf(r,l);if(c===-1){a.push(e.slice(l));break}c>l&&a.push(e.slice(l,c)),a.push(t.jsx("mark",{style:{background:Ph,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},d++)),l=c+r.length}return t.jsx(t.Fragment,{children:a})}function cr(e,n,o,r){if(!n)return!0;const s=dn(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(l=>typeof l=="string"&&dn(l,r).includes(s))}function Mh(e,n,o){return n?dn(e,o).includes(dn(n,o)):!0}const dr={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},Bh={考证:i("section-kaozhen")};function pr(e,n,o){return e.collated.sectionType[n]??o(n)}function nc(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,a)=>s+nc(a),0))||0;return n+o}function Wh(e,n){const o=[],r=l=>{var d;o.push(...l.files),(d=l.children)==null||d.forEach(r)};if(r(e),o.length===0)return;const s=o.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let a=0;for(const l of s)typeof l=="number"&&(a+=l);return a}const Oh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function ur({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...Oh,...r},children:s}):t.jsx("span",{style:r,children:s})}function Hh({type:e}){const{convert:n,messages:o}=J(),r=ft(e),s=dr[r]||i("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:s,border:`1px solid ${s}40`,borderRadius:"2px",background:`${s}08`,flexShrink:0},children:pr(o,r,n)})}function Fh({section:e,onNavigate:n,highlightQuery:o="",no:r,showUnlinked:s=!1,domId:a}){const{t:l,convert:d}=J(),c=Je(),p=Zt(),u=j=>j?mt(d(j),S=>o?Wn(S,o,p):S,{t:l}):"",[m,h]=g.useState(!1),f=!!e.summary,x=!!e.comment,k=!!e.additional_comment,y=!!(e.content&&e.content.length>60),w=f||x||k||y;g.useEffect(()=>{o&&h(!0)},[o]);const b=!m&&y?Hl(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>w&&h(!m),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:w?"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(ur,{enabled:w,expanded:m,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[w&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:m?"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:["《",u(e.book_title),"》"]}):u(e.title),e.n_juan!=null&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d(lr(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:u(e.author_info||e.author)})]}),!m&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:u(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u(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:c(e.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:l("collated.viewWork"),"aria-label":l("collated.viewWorkOf",{title:d(e.book_title||e.title)}),children:l("collated.workArrow")}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),m&&w&&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:u(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:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:u(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:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:u(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:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:u(e.additional_comment)})]}),y&&!f&&!x&&!k&&t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:u(e.content)})]})]})}function Dh({section:e,highlightQuery:n=""}){const{t:o,convert:r}=J(),s=Zt(),a=p=>p?mt(r(p),u=>n?Wn(u,n,s):u,{t:o}):"",[l,d]=g.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(ur,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Hh,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:a(e.title)}),c&&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&&c&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${dr[ft(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:a(e.content)})})]})}const Uh=100;function mr(e){return ft(e.type)!=="page_header"?!1:(e.content||"").length>=Uh}function Vh({section:e,highlightQuery:n=""}){const{t:o,convert:r,messages:s}=J(),a=Zt();if(ft(e.type)==="page_header"&&!mr(e)||!e.content&&!e.title)return null;const l=r((e.content||e.title||"").replace(/\n{2,}/g,`
1226
- `)),d=mt(l,m=>n?Wn(m,n,a):m,{t:o}),c=ft(e.type),p=dr[c]||i("desc-fg"),u=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:u?"10px 12px":"6px 0",margin:u?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:u?`3px solid ${p}40`:void 0,background:u?i("bg"):void 0,borderRadius:u?"0 4px 4px 0":void 0,position:"relative"},children:[u&&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:pr(s,c,r)}),d]})}function Gh(e,n,o){const[r,s]=g.useState({});return g.useEffect(()=>{var p;if(!n||e.length===0)return;let a=!1;const l=e.filter(u=>{var m;return!((m=o==null?void 0:o.current)!=null&&m.has(u))}),d={};for(const u of e)(p=o==null?void 0:o.current)!=null&&p.has(u)&&(d[u]=o.current.get(u));if(Object.keys(d).length>0&&s(d),l.length===0)return;const c=async u=>{var m;try{if(n.getEntry){const y=await n.getEntry(u);if(y)return{title:y.title,author:y.author}}const h=await n.getItem(u);if(!h)return null;const f=h.title||u,x=h.authors,k=(m=x==null?void 0:x[0])==null?void 0:m.name;return{title:f,author:k}}catch{return null}};return Promise.all(l.map(async u=>{var h;const m=await c(u);return(h=o==null?void 0:o.current)==null||h.set(u,m),[u,m]})).then(u=>{a||s(m=>{const h={...m};for(const[f,x]of u)h[f]=x;return h})}),()=>{a=!0}},[e.join(","),n]),r}function Yh({section:e,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{t:a,convert:l,messages:d}=J(),c=Je(),p=Zt(),u=S=>S?mt(l(S),v=>s?Wn(v,s,p):v,{t:a}):"",[m,h]=g.useState(!1);g.useEffect(()=>{s&&h(!0)},[s]);const f=ft(e.type),x=Bh[f]||i("desc-fg"),k=!!e.content,y=e.work_ids||[],w=y.length>1,b=Gh(w?y:[],o,r),j=k&&!m&&e.content.length>80?Hl(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>k&&h(!m),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:k?"pointer":"default",userSelect:"none"},children:[t.jsxs(ur,{enabled:k,expanded:m,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[k&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:m?"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?u(e.header_line):u(e.title)}),!m&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:u(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[y.length===1&&n&&t.jsx("a",{href:c(y[0]),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(y[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),w&&t.jsx("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:y.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:pr(d,f,l)})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:y.map(S=>{const v=b[S],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:S.slice(0,8)+"…";return t.jsxs("a",{href:c(S),onClick:_=>{_.metaKey||_.ctrlKey||(_.preventDefault(),_.stopPropagation(),n(S))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:S,children:["→",$]},S)})}),m&&k&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:u(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:u(e.comment)})]})]})}function Kh({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{t:a}=J(),l=Zt(),d=n.trim(),c=g.useMemo(()=>d?e.sections.filter(p=>cr(p,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:c.map((p,u)=>t.jsx(Yh,{section:p,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:d},u))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function qh(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Xh({sections:e,onNavigate:n,inline:o,workLinks:r=!0}){const s=Je(),{t:a,convert:l}=J(),d=qh();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const u=ft(c.type);if(u==="page_header"&&!mr(c))return null;if(u==="类")return t.jsxs(g.Fragment,{children:[g.createElement(d("类"),null,o(l(c.title))),c.content&&t.jsx("p",{children:o(l(c.content))})]},p);if(u==="书"||u==="诗"||u==="考证"||u==="注释"){const m=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:lr(c.n_juan)}):""}`:c.title,h=o(l(m));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${p}`,children:[g.createElement(d("条目"),{className:"bim-rd-entry-h"},c.work_id&&n&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:a("collated.viewWork"),children:h}),t.jsx("a",{className:"bim-rd-wl",href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(m)}),children:a("collated.workArrow")})]}):h),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:o(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:o(l(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.summary")}),o(l(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.comment")}),o(l(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.additionalComment")}),o(l(c.additional_comment))]})]},p)}return c.content?t.jsx("p",{children:o(l(c.content))},p):null})})}function ic(e){return e.some(n=>{const o=ft(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&mr(n)})}function Zh({juan:e,rawText:n,positionLabel:o,groupLabel:r,index:s,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:p,view:u,onViewChange:m}){var O;const{t:h,convert:f,messages:x}=J(),k=Zt(),[y,w]=g.useState("text"),b=u??y,j=A=>{w(A),m==null||m(A)},S=a.trim(),v=(s==null?void 0:s.type)==="kaozhen",$=g.useCallback(A=>S?Wn(A,S,k):A,[S,k]),_=A=>sr(A,{renderText:$,properNames:p.properNames,t:h}),C=g.useMemo(()=>S?e.sections.filter(A=>cr(A,S,v,k)):e.sections,[e.sections,S,v,k]),M=(A,G)=>G.filter(le=>ft(le.type)===A).length,T=M("书",e.sections),z=M("诗",e.sections),H=M("考证",e.sections);let N="";v?N=S?h("collated.countTiaoOf",{m:M("考证",C),n:H}):h("collated.countTiao",{n:H}):z>0?N=S?h("collated.countPoemsOf",{m:M("诗",C),n:z}):h("collated.countPoems",{n:z}):T>0&&(N=S?h("collated.countBooksOf",{m:M("书",C),n:T}):h("collated.countBooks",{n:T}));const I=s!=null&&s.text_quality?Ch(s.text_quality.grade):null,L=[];N&&L.push(N),v&&(s!=null&&s.target_source)&&L.push(t.jsx(t.Fragment,{children:h("collated.kaozhenTarget",{target:f(s.target_source)})})),I&&L.push(t.jsx("span",{title:x.collated.qualityCriteria[I],children:(O=s==null?void 0:s.text_quality)!=null&&O.source_note?t.jsxs(t.Fragment,{children:[Nh(h("collated.baseText",{note:tc}),s.text_quality.source_note,f),t.jsx("span",{className:"bim-rd-grade",children:x.collated.qualityLabel[I]})]}):t.jsxs(t.Fragment,{children:[h("collated.textQuality"),t.jsx("span",{className:"bim-rd-grade",children:x.collated.qualityLabel[I]})]})})),e.source_url&&L.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:h("collated.originalSource")}));const R=!v&&ic(e.sections),P=!!n&&(!R||p.readingMode==="paragraph"&&ci(n)),U=!v&&(R||!!n),q=v||!U?"entries":b;let D=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)}),L.length>0&&t.jsx("p",{className:"bim-rd-meta",children:L.map((A,G)=>t.jsxs(g.Fragment,{children:[G>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},G))}),U&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":h("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":q==="text",onClick:()=>j("text"),children:h("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":q==="entries",onClick:()=>j("entries"),children:h("collated.viewEntries")})]})]}),q==="text"&&t.jsx("article",{className:"bim-rd-prose",children:P?t.jsx(ar,{text:n,mode:p.readingMode,properNames:p.properNames,renderText:$,dropTitle:e.title}):t.jsx(Xh,{sections:e.sections,onNavigate:l,inline:_,workLinks:p.workLinks})}),q==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?t.jsx(Kh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[C.some(A=>["书","诗","考证"].includes(ft(A.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:h("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:h("collated.rowHeadTitle")}),t.jsx("span",{children:h("collated.rowHeadWork")})]}),C.map((A,G)=>{const le=ft(A.type);return le==="书"||le==="诗"||le==="考证"?(D+=1,t.jsx(Fh,{domId:`rd-e-${e.sections.indexOf(A)}`,section:A,onNavigate:p.workLinks?l:void 0,highlightQuery:S,no:D,showUnlinked:p.workLinks&&!!l},G)):le==="类"?t.jsx(Dh,{section:A,highlightQuery:S},G):t.jsx(Vh,{section:A,highlightQuery:S},G)}),C.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:h("collated.noMatch")})]})})]})}function Jh(e){const{resetKey:n,load:o,files:r,activeFile:s,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,p=Zt(),u=g.useRef(new Map),[m,h]=g.useState({}),[f,x]=g.useState({}),k=g.useCallback((w,b)=>{const j=b==null?void 0:b.title;j&&x(S=>S[w]===j?S:{...S,[w]:j})},[]);g.useEffect(()=>{s&&a&&(u.current.set(s,{juan:a,rawText:l}),k(s,a))},[s,a,l,k]),g.useEffect(()=>{u.current.clear(),h({}),x({})},[n]);const y=g.useCallback((w,b)=>{let j=0;if(w.juan)for(const S of w.juan.sections)cr(S,b,c,p)&&j++;return j===0&&w.rawText&&Mh(w.rawText,b,p)&&(j=1),j},[c,p]);return g.useEffect(()=>{const w=d.trim();if(!w){h({});return}if(!o||r.length===0)return;let b=!1;const j={},S=[];for(const M of r){const T=u.current.get(M);T?j[M]=y(T,w):(j[M]="loading",S.push(M))}h(j);const v=8;let $=0;const _=async()=>{for(;$<S.length;){if(b)return;const M=$++,T=S[M];try{const z=await o(T),H=z.juan;if(u.current.set(T,z),k(T,H),b)return;h(N=>({...N,[T]:y(z,w)}))}catch{if(b)return;h(z=>({...z,[T]:0}))}}},C=Array.from({length:Math.min(v,S.length)},()=>_());return Promise.all(C),()=>{b=!0}},[d,n,o,r.join(","),y,p,k]),{matchStates:m,titles:f}}function Qh({juan:e,view:n,onView:o,textHasEntries:r}){const{t:s,convert:a}=J(),l=e.sections.map((u,m)=>({s:u,i:m,t:ft(u.type)})).filter(u=>u.t==="书"||u.t==="诗");if(l.length===0)return null;const d=l.filter(u=>!!u.s.work_id).length,c=l.every(u=>u.t==="诗")?s("collated.railUnitPoems"):s("collated.railUnitBooks"),p=u=>{const m=()=>{var h,f;return(f=(h=document.getElementById(`rd-e-${u}`))==null?void 0:h.scrollIntoView)==null?void 0:f.call(h,{block:"start",behavior:"smooth"})};n==="text"&&!r&&o("entries"),n==="text"&&!r?setTimeout(m,0):m()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:s("collated.railCap")}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:c}),t.jsx("span",{className:"bim-rd-rail-linked",children:s("collated.linkedN",{n:d})})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":s("collated.linkedOf",{n:d,total:l.length}),children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":s("collated.railEntriesNav"),children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("collated.viewEntries")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:u,i:m})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${m}`,onClick:h=>{h.preventDefault(),p(m)},children:[t.jsx("span",{className:`bim-rd-rail-dot${u.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:a(u.book_title||u.title)})]})},m))})]})]})}const eg=`
1222
+ `)}),s=[]};for(const l of n){const d=sr(l);if(d){a(),r={kind:"heading",level:d.level,text:d.text};continue}s.push(l)}return a(),o}function Rs(e){const n=[];for(const o of e.split(`
1223
+ `)){const r=sr(o);if(r){n.push({kind:"heading",level:r.level,text:r.text});continue}const s=o.trim();!s||ar.test(s)||n.push({kind:"body",text:o})}return n}function Ql(e){if(!e)return[];const n=zi(e);if(n==="unknown")return Rs(e);const o=[];for(const{heading:r,body:s}of kh(e)){r&&o.push(r);const a=Xl(s);if(a.length!==0){if(Jl(s)){o.push(...Rs(s));continue}if(n==="record"){const l=a.join(" ");l&&o.push({kind:"body",text:l})}else for(const l of a){const d=Zl(l);d.length&&o.push({kind:"body",text:d.join(" ")})}}}return o}const ec=e=>e;function tc(e,n=ec){if(e.indexOf("《")<0)return n(e);const o=[],r=/《([^《》\n]+)》/g;let s=0,a=0,l;for(;l=r.exec(e);)l.index>s&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s,l.index))},a++)),o.push(t.jsxs("span",{className:"bim-rd-pn",children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(l[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]},a++)),s=l.index+l[0].length;return s===0?n(e):(s<e.length&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s))},a++)),o)}function lr(e,n={}){const o=n.renderText??ec,r=n.properNames?a=>tc(a,o):o,s=n.gujiMarkdown?{gujiMarkdown:!0,t:n.t}:void 0;return ht(e,r,s)}function Es(e,n,o){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,a)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${o}-${a}`):t.jsx(g.Fragment,{children:n(s)},`${o}-${a}`))}const Ji=/^(#{1,6})\s+(.*)$/,wh=/^\s*<!--.*-->\s*$/;function nc(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1224
+ `)?"":n)}function Sh(e){return e<=1?2:e===2?3:4}function _h(){let e=1;return n=>{const o=Sh(n),r=Math.min(o,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${o}`}}}function pi(e){return e?zi(nc(e))!=="unknown":!1}function $h(e){return/^\u3000{2}/.test(e)}const Is=e=>$h(e)?"bim-rd-noindent":void 0;function Ls({text:e,mode:n,inline:o,dropTitle:r}){const s=nc(e),a=(p,u,m)=>!!r&&m<=1&&p<=2&&u.trim()===r.trim(),l=_h();if(n==="paragraph"&&zi(s)!=="unknown"){const p=Ql(s);return t.jsx(t.Fragment,{children:p.map((u,m)=>{if(u.kind==="heading"){if(a(u.level??1,u.text,m))return null;const{Tag:h,className:f}=l(u.level??1);return t.jsx(h,{className:f,children:o(u.text)},m)}return t.jsx("p",{className:Is(u.text),children:Es(u.text,o,m)},m)})})}const d=s.split(`
1225
+ `);let c=0;return t.jsx(t.Fragment,{children:d.map((p,u)=>{const m=p.match(Ji);if(m){const f=c++;if(a(m[1].length,m[2],f))return null;const{Tag:x,className:k}=l(m[1].length);return t.jsx(x,{className:k,children:o(m[2])},u)}if(!p.trim())return u>=2&&!!d[u-1].trim()&&!!d[u-2].trim()&&!Ji.test(d[u-1])&&!Ji.test(d[u-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},u):null;if(wh.test(p))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(p.trim())){const{Tag:f,className:x}=l(3);return t.jsx(f,{className:x,children:o(p.trim().slice(2,-2))},u)}return t.jsx("p",{className:Is(p),children:Es(p,o,u)},u)})})}function Ch(e){const{convert:n}=Ae();return g.useMemo(()=>e?n(e):"",[e,n])}function cr({text:e,mode:n,tables:o=!1,gujiMarkdown:r=!1,properNames:s=!1,renderText:a,dropTitle:l}){const d=Ch(e),{t:c,convert:p}=J(),u=f=>lr(f,{renderText:a,properNames:s,gujiMarkdown:r,t:c}),m=r?{gujiMarkdown:!0,t:c}:void 0,h=l?p(l):void 0;return!o||d.indexOf(":::")<0?t.jsx(Ls,{text:d,mode:n,inline:u,dropTitle:h}):t.jsx(t.Fragment,{children:Go(d).map((f,x)=>f.type==="table"?t.jsx(rr,{table:f.table,opts:m},x):t.jsx(Ls,{text:f.text,mode:n,inline:u,dropTitle:x===0?h:void 0},x))})}function zh(e,n,o){const[r,s]=g.useState(null),[a,l]=g.useState(!1),d=g.useRef(0);return g.useEffect(()=>{const c=++d.current;if(!e||!n){s(null),l(!1);return}let p;try{p=e(n,o)}catch{s(null),l(!1);return}if(!p||typeof p.then!="function"){s(p??null),l(!1);return}l(!0),p.then(u=>{c===d.current&&s(u??null)}).catch(()=>{c===d.current&&s(null)}).finally(()=>{c===d.current&&l(!1)})},[e,n,o]),{images:r,loading:a}}const As={A:"fine",B:"rough",C:"rough",D:"ocr"};function Th(e){return typeof e!="string"?null:e in dp?e:e in As?As[e]:null}const Nh={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Rh={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"},ic="\0";function Eh(e,n,o){const[r,s=""]=e.split(ic);return t.jsxs(t.Fragment,{children:[r,t.jsx(ml,{text:n,convert:o}),s]})}function xt(e){return typeof e!="string"?"":Nh[e]??Rh[e]??e}const Ih=["〇","一","二","三","四","五","六","七","八","九"],Ps=["","十","百","千"],Lh=["","萬","億"];function dr(e){if(e===0)return"〇";if(e<0)return`負${dr(-e)}`;const n=[];let o=e,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Ah(s,r>0)+Lh[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ah(e,n){const o=[];let r=e;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let a=0;a<o.length;a++){const l=o[a],d=o.length-1-a;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&d===1&&a===0&&!n?s+=Ps[d]:s+=Ih[l]+Ps[d]}return s.replace(/〇$/,"")}let Ln=null,Qn=null;const ui=new Set;function Ph(){return Ln?Promise.resolve():Qn||(Qn=import("opencc-js/t2cn").then(e=>{const n=e.Converter({from:"t",to:"cn"});Ln=o=>n(_e.normalizeVariants(o)),ui.forEach(o=>o())}).catch(()=>{Ln=e=>e,ui.forEach(e=>e())}),Qn)}const Mh=e=>e;function Jt(){const[,e]=g.useState(0);return g.useEffect(()=>{if(Ln)return;const n=()=>e(o=>o+1);return ui.add(n),Ph(),()=>{ui.delete(n)}},[]),Ln??Mh}function pn(e,n){return n(e).toLowerCase()}const Bh=i("highlight-bg");function Hn(e,n,o){if(!n)return e;const r=pn(n,o);if(!r)return e;const s=pn(e,o);if(s.length!==e.length)return e;const a=[];let l=0,d=0;for(;l<e.length;){const c=s.indexOf(r,l);if(c===-1){a.push(e.slice(l));break}c>l&&a.push(e.slice(l,c)),a.push(t.jsx("mark",{style:{background:Bh,padding:0,color:"inherit"},children:e.slice(c,c+r.length)},d++)),l=c+r.length}return t.jsx(t.Fragment,{children:a})}function pr(e,n,o,r){if(!n)return!0;const s=pn(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(l=>typeof l=="string"&&pn(l,r).includes(s))}function Wh(e,n,o){return n?pn(e,o).includes(pn(n,o)):!0}const ur={类:i("section-lei"),书:i("section-shu"),序:i("section-xu"),结语:i("section-jieyu"),注释:i("section-zhushi")},Oh={考证:i("section-kaozhen")};function mr(e,n,o){return e.collated.sectionType[n]??o(n)}function oc(e){var r;const n=e.files.length,o=((r=e.children)==null?void 0:r.reduce((s,a)=>s+oc(a),0))||0;return n+o}function Hh(e,n){const o=[],r=l=>{var d;o.push(...l.files),(d=l.children)==null||d.forEach(r)};if(r(e),o.length===0)return;const s=o.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let a=0;for(const l of s)typeof l=="number"&&(a+=l);return a}const Fh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function hr({enabled:e,expanded:n,onClick:o,style:r,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:o,style:{...Fh,...r},children:s}):t.jsx("span",{style:r,children:s})}function Dh({type:e}){const{convert:n,messages:o}=J(),r=xt(e),s=ur[r]||i("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:s,border:`1px solid ${s}40`,borderRadius:"2px",background:`${s}08`,flexShrink:0},children:mr(o,r,n)})}function Uh({section:e,onNavigate:n,highlightQuery:o="",no:r,showUnlinked:s=!1,domId:a}){const{t:l,convert:d}=J(),c=Ze(),p=Jt(),u=j=>j?ht(d(j),S=>o?Hn(S,o,p):S,{t:l}):"",[m,h]=g.useState(!1),f=!!e.summary,x=!!e.comment,k=!!e.additional_comment,y=!!(e.content&&e.content.length>60),w=f||x||k||y;g.useEffect(()=>{o&&h(!0)},[o]);const b=!m&&y?Dl(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${i("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>w&&h(!m),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:w?"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(hr,{enabled:w,expanded:m,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[w&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),transition:"transform 0.15s",transform:m?"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:["《",u(e.book_title),"》"]}):u(e.title),e.n_juan!=null&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d(dr(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg"),marginLeft:"8px"},children:u(e.author_info||e.author)})]}),!m&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:i("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:u(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u(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:c(e.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:l("collated.viewWork"),"aria-label":l("collated.viewWorkOf",{title:d(e.book_title||e.title)}),children:l("collated.workArrow")}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:i("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),m&&w&&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:u(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:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:u(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:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:u(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:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:u(e.additional_comment)})]}),y&&!f&&!x&&!k&&t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:u(e.content)})]})]})}function Vh({section:e,highlightQuery:n=""}){const{t:o,convert:r}=J(),s=Jt(),a=p=>p?ht(r(p),u=>n?Hn(u,n,s):u,{t:o}):"",[l,d]=g.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(hr,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Dh,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:i("fg")},children:a(e.title)}),c&&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&&c&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${ur[xt(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:a(e.content)})})]})}const Gh=100;function gr(e){return xt(e.type)!=="page_header"?!1:(e.content||"").length>=Gh}function Yh({section:e,highlightQuery:n=""}){const{t:o,convert:r,messages:s}=J(),a=Jt();if(xt(e.type)==="page_header"&&!gr(e)||!e.content&&!e.title)return null;const l=r((e.content||e.title||"").replace(/\n{2,}/g,`
1226
+ `)),d=ht(l,m=>n?Hn(m,n,a):m,{t:o}),c=xt(e.type),p=ur[c]||i("desc-fg"),u=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:u?"10px 12px":"6px 0",margin:u?"8px 0":void 0,fontSize:"13px",color:i("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:u?`3px solid ${p}40`:void 0,background:u?i("bg"):void 0,borderRadius:u?"0 4px 4px 0":void 0,position:"relative"},children:[u&&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:mr(s,c,r)}),d]})}function Kh(e,n,o){const[r,s]=g.useState({});return g.useEffect(()=>{var p;if(!n||e.length===0)return;let a=!1;const l=e.filter(u=>{var m;return!((m=o==null?void 0:o.current)!=null&&m.has(u))}),d={};for(const u of e)(p=o==null?void 0:o.current)!=null&&p.has(u)&&(d[u]=o.current.get(u));if(Object.keys(d).length>0&&s(d),l.length===0)return;const c=async u=>{var m;try{if(n.getEntry){const y=await n.getEntry(u);if(y)return{title:y.title,author:y.author}}const h=await n.getItem(u);if(!h)return null;const f=h.title||u,x=h.authors,k=(m=x==null?void 0:x[0])==null?void 0:m.name;return{title:f,author:k}}catch{return null}};return Promise.all(l.map(async u=>{var h;const m=await c(u);return(h=o==null?void 0:o.current)==null||h.set(u,m),[u,m]})).then(u=>{a||s(m=>{const h={...m};for(const[f,x]of u)h[f]=x;return h})}),()=>{a=!0}},[e.join(","),n]),r}function qh({section:e,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{t:a,convert:l,messages:d}=J(),c=Ze(),p=Jt(),u=S=>S?ht(l(S),v=>s?Hn(v,s,p):v,{t:a}):"",[m,h]=g.useState(!1);g.useEffect(()=>{s&&h(!0)},[s]);const f=xt(e.type),x=Oh[f]||i("desc-fg"),k=!!e.content,y=e.work_ids||[],w=y.length>1,b=Kh(w?y:[],o,r),j=k&&!m&&e.content.length>80?Dl(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${i("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>k&&h(!m),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:k?"pointer":"default",userSelect:"none"},children:[t.jsxs(hr,{enabled:k,expanded:m,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[k&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:i("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:m?"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?u(e.header_line):u(e.title)}),!m&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:i("desc-fg"),lineHeight:1.7},children:u(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[y.length===1&&n&&t.jsx("a",{href:c(y[0]),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),n(y[0]))},style:{fontSize:"11px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),w&&t.jsx("span",{style:{fontSize:"11px",color:i("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:y.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:mr(d,f,l)})]})]}),w&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:y.map(S=>{const v=b[S],$=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:S.slice(0,8)+"…";return t.jsxs("a",{href:c(S),onClick:_=>{_.metaKey||_.ctrlKey||(_.preventDefault(),_.stopPropagation(),n(S))},style:{fontSize:"12px",color:i("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:S,children:["→",$]},S)})}),m&&k&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:i("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:i("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:u(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:u(e.comment)})]})]})}function Xh({juan:e,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{t:a}=J(),l=Jt(),d=n.trim(),c=g.useMemo(()=>d?e.sections.filter(p=>pr(p,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:c.map((p,u)=>t.jsx(qh,{section:p,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:d},u))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function Zh(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Jh({sections:e,onNavigate:n,inline:o,workLinks:r=!0}){const s=Ze(),{t:a,convert:l}=J(),d=Zh();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const u=xt(c.type);if(u==="page_header"&&!gr(c))return null;if(u==="类")return t.jsxs(g.Fragment,{children:[g.createElement(d("类"),null,o(l(c.title))),c.content&&t.jsx("p",{children:o(l(c.content))})]},p);if(u==="书"||u==="诗"||u==="考证"||u==="注释"){const m=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:dr(c.n_juan)}):""}`:c.title,h=o(l(m));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${p}`,children:[g.createElement(d("条目"),{className:"bim-rd-entry-h"},c.work_id&&n&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:a("collated.viewWork"),children:h}),t.jsx("a",{className:"bim-rd-wl",href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(m)}),children:a("collated.workArrow")})]}):h),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:o(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:o(l(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.summary")}),o(l(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.comment")}),o(l(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.additionalComment")}),o(l(c.additional_comment))]})]},p)}return c.content?t.jsx("p",{children:o(l(c.content))},p):null})})}function rc(e){return e.some(n=>{const o=xt(n.type);return o==="书"||o==="诗"||o==="考证"||o==="注释"||o==="类"||(o==="序"||o==="结语")&&!!n.content||o==="page_header"&&gr(n)})}function Qh({juan:e,rawText:n,positionLabel:o,groupLabel:r,index:s,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:p,view:u,onViewChange:m}){var O;const{t:h,convert:f,messages:x}=J(),k=Jt(),[y,w]=g.useState("text"),b=u??y,j=A=>{w(A),m==null||m(A)},S=a.trim(),v=(s==null?void 0:s.type)==="kaozhen",$=g.useCallback(A=>S?Hn(A,S,k):A,[S,k]),_=A=>lr(A,{renderText:$,properNames:p.properNames,t:h}),C=g.useMemo(()=>S?e.sections.filter(A=>pr(A,S,v,k)):e.sections,[e.sections,S,v,k]),M=(A,G)=>G.filter(se=>xt(se.type)===A).length,N=M("书",e.sections),T=M("诗",e.sections),F=M("考证",e.sections);let R="";v?R=S?h("collated.countTiaoOf",{m:M("考证",C),n:F}):h("collated.countTiao",{n:F}):T>0?R=S?h("collated.countPoemsOf",{m:M("诗",C),n:T}):h("collated.countPoems",{n:T}):N>0&&(R=S?h("collated.countBooksOf",{m:M("书",C),n:N}):h("collated.countBooks",{n:N}));const E=s!=null&&s.text_quality?Th(s.text_quality.grade):null,L=[];R&&L.push(R),v&&(s!=null&&s.target_source)&&L.push(t.jsx(t.Fragment,{children:h("collated.kaozhenTarget",{target:f(s.target_source)})})),E&&L.push(t.jsx("span",{title:x.collated.qualityCriteria[E],children:(O=s==null?void 0:s.text_quality)!=null&&O.source_note?t.jsxs(t.Fragment,{children:[Eh(h("collated.baseText",{note:ic}),s.text_quality.source_note,f),t.jsx("span",{className:"bim-rd-grade",children:x.collated.qualityLabel[E]})]}):t.jsxs(t.Fragment,{children:[h("collated.textQuality"),t.jsx("span",{className:"bim-rd-grade",children:x.collated.qualityLabel[E]})]})})),e.source_url&&L.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:h("collated.originalSource")}));const I=!v&&rc(e.sections),P=!!n&&(!I||p.readingMode==="paragraph"&&pi(n)),V=!v&&(I||!!n),X=v||!V?"entries":b;let D=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)}),L.length>0&&t.jsx("p",{className:"bim-rd-meta",children:L.map((A,G)=>t.jsxs(g.Fragment,{children:[G>0&&t.jsx("span",{className:"bim-rd-dot"}),A]},G))}),V&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":h("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":X==="text",onClick:()=>j("text"),children:h("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":X==="entries",onClick:()=>j("entries"),children:h("collated.viewEntries")})]})]}),X==="text"&&t.jsx("article",{className:"bim-rd-prose",children:P?t.jsx(cr,{text:n,mode:p.readingMode,properNames:p.properNames,renderText:$,dropTitle:e.title}):t.jsx(Jh,{sections:e.sections,onNavigate:l,inline:_,workLinks:p.workLinks})}),X==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?t.jsx(Xh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[C.some(A=>["书","诗","考证"].includes(xt(A.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:h("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:h("collated.rowHeadTitle")}),t.jsx("span",{children:h("collated.rowHeadWork")})]}),C.map((A,G)=>{const se=xt(A.type);return se==="书"||se==="诗"||se==="考证"?(D+=1,t.jsx(Uh,{domId:`rd-e-${e.sections.indexOf(A)}`,section:A,onNavigate:p.workLinks?l:void 0,highlightQuery:S,no:D,showUnlinked:p.workLinks&&!!l},G)):se==="类"?t.jsx(Vh,{section:A,highlightQuery:S},G):t.jsx(Yh,{section:A,highlightQuery:S},G)}),C.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:h("collated.noMatch")})]})})]})}function eg(e){const{resetKey:n,load:o,files:r,activeFile:s,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,p=Jt(),u=g.useRef(new Map),[m,h]=g.useState({}),[f,x]=g.useState({}),k=g.useCallback((w,b)=>{const j=b==null?void 0:b.title;j&&x(S=>S[w]===j?S:{...S,[w]:j})},[]);g.useEffect(()=>{s&&a&&(u.current.set(s,{juan:a,rawText:l}),k(s,a))},[s,a,l,k]),g.useEffect(()=>{u.current.clear(),h({}),x({})},[n]);const y=g.useCallback((w,b)=>{let j=0;if(w.juan)for(const S of w.juan.sections)pr(S,b,c,p)&&j++;return j===0&&w.rawText&&Wh(w.rawText,b,p)&&(j=1),j},[c,p]);return g.useEffect(()=>{const w=d.trim();if(!w){h({});return}if(!o||r.length===0)return;let b=!1;const j={},S=[];for(const M of r){const N=u.current.get(M);N?j[M]=y(N,w):(j[M]="loading",S.push(M))}h(j);const v=8;let $=0;const _=async()=>{for(;$<S.length;){if(b)return;const M=$++,N=S[M];try{const T=await o(N),F=T.juan;if(u.current.set(N,T),k(N,F),b)return;h(R=>({...R,[N]:y(T,w)}))}catch{if(b)return;h(T=>({...T,[N]:0}))}}},C=Array.from({length:Math.min(v,S.length)},()=>_());return Promise.all(C),()=>{b=!0}},[d,n,o,r.join(","),y,p,k]),{matchStates:m,titles:f}}function tg({juan:e,view:n,onView:o,textHasEntries:r}){const{t:s,convert:a}=J(),l=e.sections.map((u,m)=>({s:u,i:m,t:xt(u.type)})).filter(u=>u.t==="书"||u.t==="诗");if(l.length===0)return null;const d=l.filter(u=>!!u.s.work_id).length,c=l.every(u=>u.t==="诗")?s("collated.railUnitPoems"):s("collated.railUnitBooks"),p=u=>{const m=()=>{var h,f;return(f=(h=document.getElementById(`rd-e-${u}`))==null?void 0:h.scrollIntoView)==null?void 0:f.call(h,{block:"start",behavior:"smooth"})};n==="text"&&!r&&o("entries"),n==="text"&&!r?setTimeout(m,0):m()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:s("collated.railCap")}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:c}),t.jsx("span",{className:"bim-rd-rail-linked",children:s("collated.linkedN",{n:d})})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":s("collated.linkedOf",{n:d,total:l.length}),children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":s("collated.railEntriesNav"),children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("collated.viewEntries")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:u,i:m})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${m}`,onClick:h=>{h.preventDefault(),p(m)},children:[t.jsx("span",{className:`bim-rd-rail-dot${u.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:a(u.book_title||u.title)})]})},m))})]})]})}const ng=`
1227
1227
  attribute vec2 a_position; // 目标画布像素坐标 [0, canvasWidth] x [0, canvasHeight]
1228
1228
  attribute vec2 a_texCoord; // 原图像素坐标 [0, imgWidth] x [0, imgHeight]
1229
1229
 
@@ -1241,7 +1241,7 @@ ${Om}`;function zn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
1241
1241
  // 纹理坐标归一化 [0, 1]
1242
1242
  v_texCoord = a_texCoord / u_imgResolution;
1243
1243
  }
1244
- `,tg=`
1244
+ `,ig=`
1245
1245
  precision mediump float;
1246
1246
  uniform sampler2D u_image;
1247
1247
  uniform float u_alpha;
@@ -1251,8 +1251,8 @@ ${Om}`;function zn({children:e,style:n,wide:o,grid:r}){return t.jsxs("div",{clas
1251
1251
  vec4 tex = texture2D(u_image, v_texCoord);
1252
1252
  gl_FragColor = vec4(tex.rgb, tex.a * u_alpha);
1253
1253
  }
1254
- `;function As(e,n,o){const r=e.createShader(n);return r?(e.shaderSource(r,o),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error("Shader compile error:",e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}class vo{constructor(n){const o=n.getContext("webgl",{alpha:!0,antialias:!0,preserveDrawingBuffer:!0,premultipliedAlpha:!1});if(!o)throw new Error("WebGL not supported");this.gl=o;const r=As(o,o.VERTEX_SHADER,eg),s=As(o,o.FRAGMENT_SHADER,tg);if(!r||!s)throw new Error("Failed to create shaders");const a=o.createProgram();if(!a)throw new Error("Failed to create program");if(o.attachShader(a,r),o.attachShader(a,s),o.linkProgram(a),!o.getProgramParameter(a,o.LINK_STATUS))throw new Error("Program link error: "+o.getProgramInfoLog(a));this.program=a,this.positionBuffer=o.createBuffer(),this.texCoordBuffer=o.createBuffer(),this.uResolutionLoc=o.getUniformLocation(a,"u_resolution"),this.uImgResolutionLoc=o.getUniformLocation(a,"u_imgResolution"),this.uAlphaLoc=o.getUniformLocation(a,"u_alpha"),this.aPositionLoc=o.getAttribLocation(a,"a_position"),this.aTexCoordLoc=o.getAttribLocation(a,"a_texCoord"),o.enable(o.BLEND),o.blendFunc(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA),this.clear(n.width,n.height)}clear(n,o){const r=this.gl;r.viewport(0,0,n,o),r.clearColor(.98,.97,.95,1),r.clear(r.COLOR_BUFFER_BIT)}createTexture(n){const o=this.gl,r=o.createTexture();return o.bindTexture(o.TEXTURE_2D,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,n),r}renderStripsWithTexture(n,o,r,s,a,l,d=1){if(l.length===0)return;const c=this.gl;c.viewport(0,0,o,r),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,o,r),c.uniform2f(this.uImgResolutionLoc,s,a),c.uniform1f(this.uAlphaLoc,d);const p=[],u=[],m=8;for(const h of l){const f=h.colOffsetX||0,x=h.colOffsetY||0,{srcQuad:k,dstRect:y}=h.strip,[w,b,j,S]=y,v=f+w,$=x+b,[_,C,M,T]=k;for(let z=0;z<m;z++){const H=z/m,N=(z+1)/m,I=$+S*H,L=$+S*N,R=[_[0]+(T[0]-_[0])*H,_[1]+(T[1]-_[1])*H],P=[_[0]+(T[0]-_[0])*N,_[1]+(T[1]-_[1])*N],U=[C[0]+(M[0]-C[0])*H,C[1]+(M[1]-C[1])*H],q=[C[0]+(M[0]-C[0])*N,C[1]+(M[1]-C[1])*N],D=[v,I],O=[v+j,I],A=[v,L],G=[v+j,L];p.push(D[0],D[1],O[0],O[1],A[0],A[1]),u.push(R[0],R[1],U[0],U[1],P[0],P[1]),p.push(O[0],O[1],G[0],G[1],A[0],A[1]),u.push(U[0],U[1],q[0],q[1],P[0],P[1])}}c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(p),c.STATIC_DRAW),c.enableVertexAttribArray(this.aPositionLoc),c.vertexAttribPointer(this.aPositionLoc,2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,this.texCoordBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW),c.enableVertexAttribArray(this.aTexCoordLoc),c.vertexAttribPointer(this.aTexCoordLoc,2,c.FLOAT,!1,0,0),c.bindTexture(c.TEXTURE_2D,n),c.drawArrays(c.TRIANGLES,0,p.length/2)}deleteTexture(n){n&&this.gl.deleteTexture(n)}destroy(){const n=this.gl;n.deleteProgram(this.program),n.deleteBuffer(this.positionBuffer),n.deleteBuffer(this.texCoordBuffer)}}const Lt=new Map,ng=24;function ko(e){let n=Lt.get(e);if(n)return Lt.delete(e),Lt.set(e,n),n;for(n=new Promise(o=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>{(r.decode?r.decode().catch(()=>{}):Promise.resolve()).then(()=>o(r))},r.onerror=()=>{Lt.delete(e),o(null)},r.src=e}),Lt.set(e,n);Lt.size>ng;)Lt.delete(Lt.keys().next().value);return n}const hr=({imageUrl:e,pageData:n,selectedCharIds:o,hoveredCharId:r,preserveMargins:s=!1,onCharClick:a,onCharHover:l})=>{const d=g.useRef(null),c=g.useRef(null),p=g.useRef(null),u=g.useRef(null),m=g.useRef(null),h=g.useRef(null),[f,x]=g.useState(0),[k,y]=g.useState(0),w=g.useRef(""),b=g.useMemo(()=>Math.max(...n.columns.map(N=>N.warped_h),2440),[n]),j=n.total_warped_w,S=n.banxin,v=g.useMemo(()=>{var q;if(!s)return{top:0,bottom:0,left:0,right:0};const[N,I]=n.image_size||[2386,3082];let L=1/0,R=-1/0,P=1/0,U=-1/0;for(const D of n.columns)for(const O of D.strips||[])for(const A of O.srcQuad)A[0]<L&&(L=A[0]),A[0]>R&&(R=A[0]),A[1]<P&&(P=A[1]),A[1]>U&&(U=A[1]);if((q=n.banxin)!=null&&q.current_page_strips)for(const D of n.banxin.current_page_strips)for(const O of D.srcQuad)O[0]<L&&(L=O[0]),O[0]>R&&(R=O[0]),O[1]<P&&(P=O[1]),O[1]>U&&(U=O[1]);return isFinite(L)||(L=0),isFinite(R)||(R=N),isFinite(P)||(P=0),isFinite(U)||(U=I),{top:Math.max(0,Math.round(P)),bottom:Math.max(0,Math.round(I-U)),left:Math.max(0,Math.round(L)),right:Math.max(0,Math.round(N-R)),rawMinX:L,rawMaxX:R,rawMinY:P,rawMaxY:U,imgW:N,imgH:I}},[n,s]),$=j+(S?S.total_w:0),_=$+v.left+v.right,C=b+v.top+v.bottom,M=g.useCallback(()=>{const N=c.current;if(!(!N||!d.current)&&!(e&&w.current!==e)){if(N.clear(_,C),s&&v.rawMinX!==void 0&&m.current&&p.current){const{rawMinX:I,rawMaxX:L,rawMinY:R,rawMaxY:P,imgW:U,imgH:q,top:D,bottom:O,left:A,right:G}=v,le=[];A>0&&le.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[I,0],[I,q],[0,q]],dstRect:[0,0,A,C]}}),D>0&&le.push({colOffsetX:A,colOffsetY:0,strip:{srcQuad:[[I,0],[L,0],[L,R],[I,R]],dstRect:[0,0,$,D]}}),O>0&&le.push({colOffsetX:A,colOffsetY:D+b,strip:{srcQuad:[[I,P],[L,P],[L,q],[I,q]],dstRect:[0,0,$,O]}}),G>0&&le.push({colOffsetX:A+$,colOffsetY:0,strip:{srcQuad:[[L,0],[U,0],[U,q],[L,q]],dstRect:[0,0,G,C]}}),N.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],le,1)}if(m.current&&p.current){const I=n.columns.flatMap(L=>(L.strips||[]).map(R=>({colOffsetX:v.left+L.offset_x,colOffsetY:v.top,strip:R})));if(I.length>0?N.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],I,1):N.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[n.image_size[0],0],[n.image_size[0],n.image_size[1]],[0,n.image_size[1]]],dstRect:[0,0,_,C]}}],1),S&&S.current_page_strips.length>0){const L=S.current_page_strips.map(R=>({colOffsetX:v.left+j,colOffsetY:v.top,strip:R}));N.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],L,1)}}if(S&&h.current&&u.current&&S.mate_page_strips.length>0){const I=S.mate_page_strips.map(L=>({colOffsetX:v.left+j+S.half_w,colOffsetY:v.top,strip:L}));N.renderStripsWithTexture(h.current,_,C,S.mate_img_size[0],S.mate_img_size[1],I,.65)}}},[e,n,S,_,C,j,b,$,v,s]),T=g.useRef(M);T.current=M,g.useEffect(()=>{const N=d.current;if(!N)return;const I=P=>{m.current=p.current?P.createTexture(p.current):null,h.current=u.current?P.createTexture(u.current):null,T.current()};try{const P=new vo(N);c.current=P,I(P)}catch(P){console.error("Failed to init WebGL renderer:",P)}const L=P=>{P.preventDefault(),console.warn("WebGL context lost")},R=()=>{console.info("WebGL context restored, re-initializing..."),d.current&&(c.current=new vo(d.current),I(c.current))};return N.addEventListener("webglcontextlost",L,!1),N.addEventListener("webglcontextrestored",R,!1),()=>{N.removeEventListener("webglcontextlost",L),N.removeEventListener("webglcontextrestored",R),c.current&&(c.current.deleteTexture(m.current),c.current.deleteTexture(h.current),c.current.destroy(),c.current=null)}},[]),g.useEffect(()=>{if(!e)return;let N=!0;return ko(e).then(I=>{if(!N||!I)return;p.current=I,w.current=e;const L=c.current;L&&(L.deleteTexture(m.current),m.current=L.createTexture(I)),x(R=>R+1)}),()=>{N=!1}},[e]);const z=S==null?void 0:S.mate_image_url;g.useEffect(()=>{if(!z)return;let N=!0;return ko(z).then(I=>{if(!N||!I)return;u.current=I;const L=c.current;L&&(L.deleteTexture(h.current),h.current=L.createTexture(I)),y(R=>R+1)}),()=>{N=!1}},[z]),g.useEffect(()=>{M()},[M,f,k]);const H=g.useMemo(()=>{const N=[];for(const I of n.columns)for(const L of I.chars){const[R,P,U,q]=L.bbox_col;N.push({id:L.id,char:L.char,x:v.left+I.offset_x+R,y:v.top+P,w:Math.max(U-R,1),h:Math.max(q-P,1)})}return N},[n,v]);return t.jsxs("div",{className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${_} / ${C}`,backgroundColor:i("warp-bg"),boxShadow:i("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("canvas",{ref:d,width:_,height:C,style:{width:"100%",height:"100%",display:"block",backgroundColor:i("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${_} ${C}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[H.map(N=>{const I=o.has(N.id),L=r===N.id;return t.jsx("rect",{"data-selected":I?"true":void 0,x:N.x,y:N.y,width:N.w,height:N.h,fill:I?i("warp-sel-bg"):L?i("warp-hover-bg"):"transparent",stroke:I?i("warp-sel-stroke"):L?i("warp-hover-stroke"):"transparent",strokeWidth:I?3.5:L?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>a==null?void 0:a(N.id),onMouseEnter:()=>l==null?void 0:l(N.id),onMouseLeave:()=>l==null?void 0:l(null),children:t.jsx("title",{children:N.char})},N.id)}),S&&t.jsxs("g",{children:[t.jsx("line",{x1:v.left+j,y1:v.top,x2:v.left+j,y2:v.top+b,stroke:i("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:v.left+j+S.half_w,y1:v.top,x2:v.left+j+S.half_w,y2:v.top+b,stroke:i("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:v.left+$,y1:v.top,x2:v.left+$,y2:v.top+b,stroke:i("warp-banxin-outer"),strokeWidth:1})]})]})]})},ig={work:"work",book:"work",people:"person",person:"person",place:"place",office:"office",dynasty:"dynasty"};function og(e){return typeof e=="string"&&ig[e]||"other"}function wo(e){if(!e)return null;const n=e.trim(),o=/^book-index:\/\/(?:[A-Za-z]+\/)*([0-9A-Za-z]+)\/?$/.exec(n);if(o)return o[1];const r=/^bid:\\{1,2}([0-9A-Za-z]+)$/.exec(n);return r?r[1]:/^[0-9A-Za-z]+$/.test(n)?n:null}function wn(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function At(e){return typeof e=="string"&&e?e:void 0}function oc(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.entities)?e.entities:[],o=[];return n.forEach((r,s)=>{if(!r||typeof r!="object")return;const a=r,l=a.span??{},d=a.target??{},c=wn(l.start_offset)??wn(a.start_offset),p=wn(l.end_offset)??wn(a.end_offset);if(c===void 0||p===void 0||c<0||p<=c)return;const u=At(d.status),m=u===void 0||u==="matched"?wo(At(d.entity_id))??wo(At(d.href))??void 0:void 0,h=a.anchor??{},f=At(h.start),x=At(h.end);o.push({...f&&x?{anchor:{start:f,end:x}}:{},key:At(a.id)??`e${s}`,kind:og(a.type),start:c,end:p,text:At(a.text),targetId:m,canonicalName:At(d.canonical_name),confidence:wn(a.confidence)})}),o.sort((r,s)=>r.start-s.start||s.end-r.end)}const rg=new Set(Array.from(`《》/<>\r
1255
-  ,。、;:?!「」『』()…—·`));function gr(e){return!rg.has(e)}function rc(e,n,o=0){const r=[],s=Array.from(e);let a=0;for(const d of s)gr(d)&&r.push(a),a+=d.length;const l=[];for(const d of n){const c=d.start-o,p=d.end-o;if(c<0||p>r.length||p<=c)continue;const u=r[p-1],m=e.codePointAt(u)>65535?2:1;l.push({...d,start:r[c],end:u+m})}return l}function sg(e,n){return n.text?Array.from(e.slice(n.start,n.end)).filter(gr).join("")===n.text:!0}function ag(e,n,o){if(!n.text)return null;let r=-1,s=Math.max(0,n.start-o);const a=n.start+o;for(;s<=a;){const l=e.indexOf(n.text,s);if(l<0||l>a)break;(r<0||Math.abs(l-n.start)<Math.abs(r-n.start))&&(r=l),s=l+1}return r<0?null:{...n,start:r,end:r+n.text.length}}function sc(e,n,o=16){const r=[];for(const l of n){let d={...l,start:Math.max(0,l.start),end:Math.min(e.length,l.end)};(d.end<=d.start||!sg(e,d))&&(d=ag(e,l,o)),d&&r.push(d)}r.sort((l,d)=>l.start-d.start||d.end-l.end);const s=[];let a=0;for(const l of r)l.start<a||(l.start>a&&s.push({type:"text",text:e.slice(a,l.start),start:a}),s.push({type:"entity",text:e.slice(l.start,l.end),start:l.start,span:l}),a=l.end);return a<e.length&&s.push({type:"text",text:e.slice(a),start:a}),s}const fr=`
1254
+ `;function Ms(e,n,o){const r=e.createShader(n);return r?(e.shaderSource(r,o),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error("Shader compile error:",e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}class wo{constructor(n){const o=n.getContext("webgl",{alpha:!0,antialias:!0,preserveDrawingBuffer:!0,premultipliedAlpha:!1});if(!o)throw new Error("WebGL not supported");this.gl=o;const r=Ms(o,o.VERTEX_SHADER,ng),s=Ms(o,o.FRAGMENT_SHADER,ig);if(!r||!s)throw new Error("Failed to create shaders");const a=o.createProgram();if(!a)throw new Error("Failed to create program");if(o.attachShader(a,r),o.attachShader(a,s),o.linkProgram(a),!o.getProgramParameter(a,o.LINK_STATUS))throw new Error("Program link error: "+o.getProgramInfoLog(a));this.program=a,this.positionBuffer=o.createBuffer(),this.texCoordBuffer=o.createBuffer(),this.uResolutionLoc=o.getUniformLocation(a,"u_resolution"),this.uImgResolutionLoc=o.getUniformLocation(a,"u_imgResolution"),this.uAlphaLoc=o.getUniformLocation(a,"u_alpha"),this.aPositionLoc=o.getAttribLocation(a,"a_position"),this.aTexCoordLoc=o.getAttribLocation(a,"a_texCoord"),o.enable(o.BLEND),o.blendFunc(o.SRC_ALPHA,o.ONE_MINUS_SRC_ALPHA),this.clear(n.width,n.height)}clear(n,o){const r=this.gl;r.viewport(0,0,n,o),r.clearColor(.98,.97,.95,1),r.clear(r.COLOR_BUFFER_BIT)}createTexture(n){const o=this.gl,r=o.createTexture();return o.bindTexture(o.TEXTURE_2D,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,o.LINEAR),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,n),r}renderStripsWithTexture(n,o,r,s,a,l,d=1){if(l.length===0)return;const c=this.gl;c.viewport(0,0,o,r),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,o,r),c.uniform2f(this.uImgResolutionLoc,s,a),c.uniform1f(this.uAlphaLoc,d);const p=[],u=[],m=8;for(const h of l){const f=h.colOffsetX||0,x=h.colOffsetY||0,{srcQuad:k,dstRect:y}=h.strip,[w,b,j,S]=y,v=f+w,$=x+b,[_,C,M,N]=k;for(let T=0;T<m;T++){const F=T/m,R=(T+1)/m,E=$+S*F,L=$+S*R,I=[_[0]+(N[0]-_[0])*F,_[1]+(N[1]-_[1])*F],P=[_[0]+(N[0]-_[0])*R,_[1]+(N[1]-_[1])*R],V=[C[0]+(M[0]-C[0])*F,C[1]+(M[1]-C[1])*F],X=[C[0]+(M[0]-C[0])*R,C[1]+(M[1]-C[1])*R],D=[v,E],O=[v+j,E],A=[v,L],G=[v+j,L];p.push(D[0],D[1],O[0],O[1],A[0],A[1]),u.push(I[0],I[1],V[0],V[1],P[0],P[1]),p.push(O[0],O[1],G[0],G[1],A[0],A[1]),u.push(V[0],V[1],X[0],X[1],P[0],P[1])}}c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(p),c.STATIC_DRAW),c.enableVertexAttribArray(this.aPositionLoc),c.vertexAttribPointer(this.aPositionLoc,2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,this.texCoordBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(u),c.STATIC_DRAW),c.enableVertexAttribArray(this.aTexCoordLoc),c.vertexAttribPointer(this.aTexCoordLoc,2,c.FLOAT,!1,0,0),c.bindTexture(c.TEXTURE_2D,n),c.drawArrays(c.TRIANGLES,0,p.length/2)}deleteTexture(n){n&&this.gl.deleteTexture(n)}destroy(){const n=this.gl;n.deleteProgram(this.program),n.deleteBuffer(this.positionBuffer),n.deleteBuffer(this.texCoordBuffer)}}const At=new Map,og=24;function So(e){let n=At.get(e);if(n)return At.delete(e),At.set(e,n),n;for(n=new Promise(o=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>{(r.decode?r.decode().catch(()=>{}):Promise.resolve()).then(()=>o(r))},r.onerror=()=>{At.delete(e),o(null)},r.src=e}),At.set(e,n);At.size>og;)At.delete(At.keys().next().value);return n}const fr=({imageUrl:e,pageData:n,selectedCharIds:o,hoveredCharId:r,preserveMargins:s=!1,onCharClick:a,onCharHover:l})=>{const d=g.useRef(null),c=g.useRef(null),p=g.useRef(null),u=g.useRef(null),m=g.useRef(null),h=g.useRef(null),[f,x]=g.useState(0),[k,y]=g.useState(0),w=g.useRef(""),b=g.useMemo(()=>Math.max(...n.columns.map(R=>R.warped_h),2440),[n]),j=n.total_warped_w,S=n.banxin,v=g.useMemo(()=>{var X;if(!s)return{top:0,bottom:0,left:0,right:0};const[R,E]=n.image_size||[2386,3082];let L=1/0,I=-1/0,P=1/0,V=-1/0;for(const D of n.columns)for(const O of D.strips||[])for(const A of O.srcQuad)A[0]<L&&(L=A[0]),A[0]>I&&(I=A[0]),A[1]<P&&(P=A[1]),A[1]>V&&(V=A[1]);if((X=n.banxin)!=null&&X.current_page_strips)for(const D of n.banxin.current_page_strips)for(const O of D.srcQuad)O[0]<L&&(L=O[0]),O[0]>I&&(I=O[0]),O[1]<P&&(P=O[1]),O[1]>V&&(V=O[1]);return isFinite(L)||(L=0),isFinite(I)||(I=R),isFinite(P)||(P=0),isFinite(V)||(V=E),{top:Math.max(0,Math.round(P)),bottom:Math.max(0,Math.round(E-V)),left:Math.max(0,Math.round(L)),right:Math.max(0,Math.round(R-I)),rawMinX:L,rawMaxX:I,rawMinY:P,rawMaxY:V,imgW:R,imgH:E}},[n,s]),$=j+(S?S.total_w:0),_=$+v.left+v.right,C=b+v.top+v.bottom,M=g.useCallback(()=>{const R=c.current;if(!(!R||!d.current)&&!(e&&w.current!==e)){if(R.clear(_,C),s&&v.rawMinX!==void 0&&m.current&&p.current){const{rawMinX:E,rawMaxX:L,rawMinY:I,rawMaxY:P,imgW:V,imgH:X,top:D,bottom:O,left:A,right:G}=v,se=[];A>0&&se.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[E,0],[E,X],[0,X]],dstRect:[0,0,A,C]}}),D>0&&se.push({colOffsetX:A,colOffsetY:0,strip:{srcQuad:[[E,0],[L,0],[L,I],[E,I]],dstRect:[0,0,$,D]}}),O>0&&se.push({colOffsetX:A,colOffsetY:D+b,strip:{srcQuad:[[E,P],[L,P],[L,X],[E,X]],dstRect:[0,0,$,O]}}),G>0&&se.push({colOffsetX:A+$,colOffsetY:0,strip:{srcQuad:[[L,0],[V,0],[V,X],[L,X]],dstRect:[0,0,G,C]}}),R.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],se,1)}if(m.current&&p.current){const E=n.columns.flatMap(L=>(L.strips||[]).map(I=>({colOffsetX:v.left+L.offset_x,colOffsetY:v.top,strip:I})));if(E.length>0?R.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],E,1):R.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[n.image_size[0],0],[n.image_size[0],n.image_size[1]],[0,n.image_size[1]]],dstRect:[0,0,_,C]}}],1),S&&S.current_page_strips.length>0){const L=S.current_page_strips.map(I=>({colOffsetX:v.left+j,colOffsetY:v.top,strip:I}));R.renderStripsWithTexture(m.current,_,C,n.image_size[0],n.image_size[1],L,1)}}if(S&&h.current&&u.current&&S.mate_page_strips.length>0){const E=S.mate_page_strips.map(L=>({colOffsetX:v.left+j+S.half_w,colOffsetY:v.top,strip:L}));R.renderStripsWithTexture(h.current,_,C,S.mate_img_size[0],S.mate_img_size[1],E,.65)}}},[e,n,S,_,C,j,b,$,v,s]),N=g.useRef(M);N.current=M,g.useEffect(()=>{const R=d.current;if(!R)return;const E=P=>{m.current=p.current?P.createTexture(p.current):null,h.current=u.current?P.createTexture(u.current):null,N.current()};try{const P=new wo(R);c.current=P,E(P)}catch(P){console.error("Failed to init WebGL renderer:",P)}const L=P=>{P.preventDefault(),console.warn("WebGL context lost")},I=()=>{console.info("WebGL context restored, re-initializing..."),d.current&&(c.current=new wo(d.current),E(c.current))};return R.addEventListener("webglcontextlost",L,!1),R.addEventListener("webglcontextrestored",I,!1),()=>{R.removeEventListener("webglcontextlost",L),R.removeEventListener("webglcontextrestored",I),c.current&&(c.current.deleteTexture(m.current),c.current.deleteTexture(h.current),c.current.destroy(),c.current=null)}},[]),g.useEffect(()=>{if(!e)return;let R=!0;return So(e).then(E=>{if(!R||!E)return;p.current=E,w.current=e;const L=c.current;L&&(L.deleteTexture(m.current),m.current=L.createTexture(E)),x(I=>I+1)}),()=>{R=!1}},[e]);const T=S==null?void 0:S.mate_image_url;g.useEffect(()=>{if(!T)return;let R=!0;return So(T).then(E=>{if(!R||!E)return;u.current=E;const L=c.current;L&&(L.deleteTexture(h.current),h.current=L.createTexture(E)),y(I=>I+1)}),()=>{R=!1}},[T]),g.useEffect(()=>{M()},[M,f,k]);const F=g.useMemo(()=>{const R=[];for(const E of n.columns)for(const L of E.chars){const[I,P,V,X]=L.bbox_col;R.push({id:L.id,char:L.char,x:v.left+E.offset_x+I,y:v.top+P,w:Math.max(V-I,1),h:Math.max(X-P,1)})}return R},[n,v]);return t.jsxs("div",{className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${_} / ${C}`,backgroundColor:i("warp-bg"),boxShadow:i("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("canvas",{ref:d,width:_,height:C,style:{width:"100%",height:"100%",display:"block",backgroundColor:i("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${_} ${C}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[F.map(R=>{const E=o.has(R.id),L=r===R.id;return t.jsx("rect",{"data-selected":E?"true":void 0,x:R.x,y:R.y,width:R.w,height:R.h,fill:E?i("warp-sel-bg"):L?i("warp-hover-bg"):"transparent",stroke:E?i("warp-sel-stroke"):L?i("warp-hover-stroke"):"transparent",strokeWidth:E?3.5:L?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>a==null?void 0:a(R.id),onMouseEnter:()=>l==null?void 0:l(R.id),onMouseLeave:()=>l==null?void 0:l(null),children:t.jsx("title",{children:R.char})},R.id)}),S&&t.jsxs("g",{children:[t.jsx("line",{x1:v.left+j,y1:v.top,x2:v.left+j,y2:v.top+b,stroke:i("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:v.left+j+S.half_w,y1:v.top,x2:v.left+j+S.half_w,y2:v.top+b,stroke:i("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:v.left+$,y1:v.top,x2:v.left+$,y2:v.top+b,stroke:i("warp-banxin-outer"),strokeWidth:1})]})]})]})},rg={work:"work",book:"work",people:"person",person:"person",place:"place",office:"office",dynasty:"dynasty"};function sg(e){return typeof e=="string"&&rg[e]||"other"}function _o(e){if(!e)return null;const n=e.trim(),o=/^book-index:\/\/(?:[A-Za-z]+\/)*([0-9A-Za-z]+)\/?$/.exec(n);if(o)return o[1];const r=/^bid:\\{1,2}([0-9A-Za-z]+)$/.exec(n);return r?r[1]:/^[0-9A-Za-z]+$/.test(n)?n:null}function _n(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Pt(e){return typeof e=="string"&&e?e:void 0}function sc(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.entities)?e.entities:[],o=[];return n.forEach((r,s)=>{if(!r||typeof r!="object")return;const a=r,l=a.span??{},d=a.target??{},c=_n(l.start_offset)??_n(a.start_offset),p=_n(l.end_offset)??_n(a.end_offset);if(c===void 0||p===void 0||c<0||p<=c)return;const u=Pt(d.status),m=u===void 0||u==="matched"?_o(Pt(d.entity_id))??_o(Pt(d.href))??void 0:void 0,h=a.anchor??{},f=Pt(h.start),x=Pt(h.end);o.push({...f&&x?{anchor:{start:f,end:x}}:{},key:Pt(a.id)??`e${s}`,kind:sg(a.type),start:c,end:p,text:Pt(a.text),targetId:m,canonicalName:Pt(d.canonical_name),confidence:_n(a.confidence)})}),o.sort((r,s)=>r.start-s.start||s.end-r.end)}const ag=new Set(Array.from(`《》/<>\r
1255
+  ,。、;:?!「」『』()…—·`));function xr(e){return!ag.has(e)}function ac(e,n,o=0){const r=[],s=Array.from(e);let a=0;for(const d of s)xr(d)&&r.push(a),a+=d.length;const l=[];for(const d of n){const c=d.start-o,p=d.end-o;if(c<0||p>r.length||p<=c)continue;const u=r[p-1],m=e.codePointAt(u)>65535?2:1;l.push({...d,start:r[c],end:u+m})}return l}function lg(e,n){return n.text?Array.from(e.slice(n.start,n.end)).filter(xr).join("")===n.text:!0}function cg(e,n,o){if(!n.text)return null;let r=-1,s=Math.max(0,n.start-o);const a=n.start+o;for(;s<=a;){const l=e.indexOf(n.text,s);if(l<0||l>a)break;(r<0||Math.abs(l-n.start)<Math.abs(r-n.start))&&(r=l),s=l+1}return r<0?null:{...n,start:r,end:r+n.text.length}}function lc(e,n,o=16){const r=[];for(const l of n){let d={...l,start:Math.max(0,l.start),end:Math.min(e.length,l.end)};(d.end<=d.start||!lg(e,d))&&(d=cg(e,l,o)),d&&r.push(d)}r.sort((l,d)=>l.start-d.start||d.end-l.end);const s=[];let a=0;for(const l of r)l.start<a||(l.start>a&&s.push({type:"text",text:e.slice(a,l.start),start:a}),s.push({type:"entity",text:e.slice(l.start,l.end),start:l.start,span:l}),a=l.end);return a<e.length&&s.push({type:"text",text:e.slice(a),start:a}),s}const br=`
1256
1256
  .bim-et-w { position: relative; display: inline; }
1257
1257
  .bim-et {
1258
1258
  color: inherit; text-decoration-line: underline;
@@ -1292,15 +1292,17 @@ a.bim-et:focus-visible { outline: 2px solid ${i("accent")}; outline-offset: 2px;
1292
1292
  .bim-et-card { animation: bim-et-in 120ms ease-out; }
1293
1293
  @keyframes bim-et-in { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
1294
1294
  }
1295
- `,lg=120;function dt(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function cg(e,n=lg){if(!e)return;const o=e.replace(/\s+/g," ").trim(),r=Array.from(o);return r.length>n?r.slice(0,n).join("")+"…":o}function dg(e){const n=typeof e.birth_year=="number"?e.birth_year:void 0,o=typeof e.death_year=="number"?e.death_year:void 0;if(!(n===void 0&&o===void 0))return`${n??"?"}–${o??"?"}`}function pg(e){if(!Array.isArray(e.authors))return;const n=e.authors.map(o=>{if(!o||typeof o!="object")return"";const r=o,s=dt(r.name);return s?[dt(r.dynasty)&&`〔${dt(r.dynasty)}〕`,s,dt(r.role)].filter(Boolean).join(""):""}).filter(Boolean);return n.length?n.slice(0,3).join("、"):void 0}function ac(e,n){const o=dt(n.type),r=dt(n.primary_name)??dt(n.title)??e,s=o==="entity"?[dt(n.dynasty),dg(n),dt(n.native_place)].filter(Boolean).join(" · "):[pg(n),dt(n.edition),dt(n.measure_info)].filter(Boolean).join(" · "),a=n.description&&typeof n.description=="object"?dt(n.description.text):dt(n.description);return{id:e,type:o,title:r,meta:s||void 0,description:cg(a)}}function lc(e){const n=[e.dynasty,e.author,e.edition].filter(Boolean).join(" · ");return{id:e.id,type:e.type,title:e.title,meta:n||void 0}}function cc(e){return async n=>{const o=await e.getItem(n);if(o)return ac(n,o);if(e.getEntry){const r=await e.getEntry(n);if(r)return lc(r)}return null}}const Ps=new WeakMap;function ug(e,n,o){let r=Ps.get(e);r||(r=new Map,Ps.set(e,r));const s=r.get(o);if(s)return s;const a=n(o);return r.set(o,a),a.catch(()=>r.delete(o)),a}const dc=e=>`/item/${encodeURIComponent(e)}`,mg={work:"書名",person:"人名",place:"地名",office:"官職",dynasty:"朝代",other:"專名"},hg=typeof window>"u"?g.useEffect:g.useLayoutEffect;function xr(e,n){return g.useMemo(()=>n?{owner:n,load:n}:e?{owner:e,load:cc(e)}:null,[n,e])}const gg=e=>e,fg=({text:e,entities:n,offsets:o="text",plainBase:r=0,transport:s,loadSummary:a,buildHref:l=dc,onNavigate:d,renderText:c=gg,hoverDelayMs:p=250,injectStyles:u=!0,className:m})=>{const h=g.useMemo(()=>{const x=o==="plain"?rc(e,n,r):n;return sc(e,x)},[e,n,o,r]),f=xr(s,a);return t.jsxs("span",{className:m?`bim-et-root ${m}`:"bim-et-root",children:[u&&t.jsx("style",{children:fr}),h.map(x=>x.type==="text"?t.jsx(g.Fragment,{children:c(x.text)},`t${x.start}`):t.jsx(br,{span:x.span,label:x.text,hasBrackets:e[x.start-1]==="《"&&e[x.start+x.text.length]==="》",loader:f,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:p},`${x.span.key}@${x.start}`))]})},br=({span:e,label:n,hasBrackets:o,loader:r,buildHref:s,onNavigate:a,renderText:l,hoverDelayMs:d})=>{const c=g.useId(),[p,u]=g.useState(!1),m=g.useRef(null),h=`bim-et bim-et-${e.kind}`,f=e.kind==="work"&&!o,x=t.jsxs(t.Fragment,{children:[f&&t.jsx("span",{className:"bim-et-sr",children:"《"}),l(n),f&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),k=()=>{m.current&&(clearTimeout(m.current),m.current=null)};g.useEffect(()=>k,[]);const y=g.useCallback(j=>{k(),j<=0?u(!0):m.current=setTimeout(()=>u(!0),j)},[]),w=g.useCallback(()=>{k(),u(!1)},[]);if(!e.targetId)return t.jsx("span",{className:h,children:x});const b=e.targetId;return t.jsxs("span",{className:"bim-et-w",onMouseEnter:()=>y(d),onMouseLeave:w,onKeyDown:j=>{j.key==="Escape"&&p&&(j.stopPropagation(),w())},children:[t.jsx("a",{className:h,href:s(b),"data-entity-id":b,"aria-describedby":p?c:void 0,onFocus:()=>y(0),onBlur:w,onClick:a?j=>a(b,j):void 0,children:x}),p&&t.jsx(xg,{id:c,entityId:b,span:e,loader:r})]})},xg=({id:e,entityId:n,span:o,loader:r})=>{const{convert:s}=J(),a=g.useRef(null),[l,d]=g.useState("start"),[c,p]=g.useState(r?{status:"loading"}:{status:"ready",summary:null});g.useEffect(()=>{if(!r)return;let h=!1;return p({status:"loading"}),ug(r.owner,r.load,n).then(f=>{h||p({status:"ready",summary:f})}).catch(()=>{h||p({status:"error"})}),()=>{h=!0}},[r,n]),hg(()=>{const h=a.current;if(!h||typeof window>"u")return;const f=h.getBoundingClientRect(),x=document.documentElement.clientWidth||window.innerWidth;f.right>x-8&&l==="start"&&d("end")},[c,l]);const u=c.status==="ready"?c.summary:null,m=(u==null?void 0:u.title)??o.canonicalName??o.text;return t.jsxs("span",{ref:a,id:e,role:"tooltip",className:"bim-et-card","data-align":l,children:[t.jsx("span",{className:"bim-et-card-k",children:s(mg[o.kind])}),m&&t.jsx("span",{className:"bim-et-card-t",children:s(m)}),(u==null?void 0:u.meta)&&t.jsx("span",{className:"bim-et-card-m",children:s(u.meta)}),(u==null?void 0:u.description)&&t.jsx("span",{className:"bim-et-card-d",children:s(u.description)}),c.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:s("載入中…")}),c.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:s("摘要載入失敗")})]})},bg=e=>`/item/${encodeURIComponent(e)}`;function yg(e){const n=e.filter(o=>o.kind!=="break");return{before:n.filter(o=>o.pos==="before"),after:n.filter(o=>o.pos!=="before")}}function jg(e,n){const o=[];for(const r of e){const s=n.get(r.charData.id)??null,a=o[o.length-1];a&&a.entity===s?a.chars.push(r):o.push({entity:s,chars:[r]})}return o}const yr=({pageData:e,pages:n,punctuations:o=kg,selectedCharIds:r,hoveredCharId:s,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:p=!0,onVisiblePageChange:u,convert:m,scrollToPage:h,entities:f,entityTransport:x,loadEntitySummary:k,buildEntityHref:y,onEntityNavigate:w})=>{const b=g.useRef(null),j=g.useRef(0),S=g.useMemo(()=>{const R=new Map;return p&&o.forEach((P,U)=>{const q=P.id?P:{...P,id:`${P.anchor}#${U}`},D=R.get(q.anchor)||[];D.push(q),R.set(q.anchor,D)}),R},[o,p]),v=g.useMemo(()=>(n&&n.length>0?n:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}]).filter(P=>P.columns.some(U=>U.chars.length>0)).map(P=>{const U=[...P.columns].sort((O,A)=>O.col-A.col),q=[];let D=[];for(const O of U)for(const A of O.chars){const{before:G,after:le}=yg(S.get(A.id)||[]),ne=(S.get(A.id)||[]).some(ve=>ve.kind==="break");D.push({charData:A,col:O.col,beforePuncts:G,afterPuncts:le}),ne&&(q.push({id:`para-p${P.page}-${q.length}`,chars:D}),D=[])}return D.length>0&&q.push({id:`para-p${P.page}-${q.length}`,chars:D}),{page:P.page,paragraphs:q}}),[n,e,S]),$=g.useMemo(()=>{const R=[];for(const P of v)for(const U of P.paragraphs)for(const q of U.chars)R.push(q.charData.id);return R},[v]),_=g.useMemo(()=>{const R=new Map;if(!f||f.length===0)return R;const P=new Map($.map((U,q)=>[U,q]));for(const U of f){if(!U.anchor)continue;const q=P.get(U.anchor.start),D=P.get(U.anchor.end);if(!(q===void 0||D===void 0||D<q))for(let O=q;O<=D;O++)R.has($[O])||R.set($[O],U)}return R},[f,$]),C=xr(x,k),M=_.size>0,T=g.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:u,onEntityNavigate:w});T.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:u,onEntityNavigate:w};const z=g.useMemo(()=>({click:R=>{var P,U;j.current=Date.now()+1200,(U=(P=T.current).onCharClick)==null||U.call(P,R)},enter:R=>{var P,U;return(U=(P=T.current).onCharHover)==null?void 0:U.call(P,R)},leave:()=>{var R,P;return(P=(R=T.current).onCharHover)==null?void 0:P.call(R,null)},navigate:(R,P)=>{var q,D;if(!(P.detail===0||P.ctrlKey||P.metaKey||P.shiftKey)){P.preventDefault();return}(D=(q=T.current).onEntityNavigate)==null||D.call(q,R,P)}}),[]),H=wg(r),N=g.useRef(null);g.useEffect(()=>{var P,U;if((P=N.current)==null||P.classList.remove("is-hovered"),N.current=null,!s)return;const R=(U=b.current)==null?void 0:U.querySelector(`span[data-char-id="${s}"]`);R&&(R.classList.add("is-hovered"),N.current=R)},[s]),g.useEffect(()=>{let R=null;const P=()=>{var ee,Be;R=null;const q=window.getSelection(),D=b.current;if(!q||q.isCollapsed||q.rangeCount===0||!D)return;const O=q.getRangeAt(0),A=O.commonAncestorContainer,G=A.nodeType===3?A.parentElement:A;if(!G||!D.contains(G))return;const le=D.querySelectorAll("span[data-char-id]");let ne=0,ve=le.length;for(;ne<ve;){const Ee=ne+ve>>1;O.comparePoint(le[Ee],0)<0?ne=Ee+1:ve=Ee}const oe=ne;for(ve=le.length;ne<ve;){const Ee=ne+ve>>1;O.comparePoint(le[Ee],0)<=0?ne=Ee+1:ve=Ee}const pe=ne-1;if(pe<oe)return;const We=[];for(let Ee=oe;Ee<=pe;Ee++)We.push(le[Ee].getAttribute("data-char-id"));We.length>0&&(j.current=Date.now()+1200,(Be=(ee=T.current).onSelectionChange)==null||Be.call(ee,We))},U=()=>{R&&clearTimeout(R),R=setTimeout(P,120)};return document.addEventListener("selectionchange",U),()=>{document.removeEventListener("selectionchange",U),R&&clearTimeout(R)}},[]),g.useEffect(()=>{var R;if(r.size===1){const P=Array.from(r)[0],U=(R=b.current)==null?void 0:R.querySelector(`span[data-char-id="${P}"]`);U&&U.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}},[r]);const I=h==null?void 0:h.nonce;g.useEffect(()=>{var P;if(!h)return;const R=(P=b.current)==null?void 0:P.querySelector(`[data-page-section="${h.page}"]`);R&&(j.current=Date.now()+800,R.scrollIntoView({behavior:"auto",block:"start"}))},[I]);const L=!!u;return g.useEffect(()=>{var O;if(!L)return;const R=Array.from(((O=b.current)==null?void 0:O.querySelectorAll("[data-page-section]"))??[]);if(R.length===0)return;const P=120;let U=0;const q=()=>{var ne,ve;if(U=0,Date.now()<j.current)return;let A=0,G=R.length-1;for(;A<G;){const oe=A+G+1>>1;R[oe].getBoundingClientRect().top<=P?A=oe:G=oe-1}const le=parseInt(R[A].getAttribute("data-page-section")||"",10);isNaN(le)||(ve=(ne=T.current).onVisiblePageChange)==null||ve.call(ne,le)},D=()=>{U||(U=requestAnimationFrame(q))};return window.addEventListener("scroll",D,{passive:!0}),q(),()=>{window.removeEventListener("scroll",D),U&&cancelAnimationFrame(U)}},[L,v]),t.jsxs("div",{ref:b,className:"guji-text-pane-content",children:[M&&t.jsx("style",{children:fr}),t.jsx("div",{className:"guji-text-reflow-view",children:v.map((R,P)=>t.jsx(_g,{pGroup:R,first:P===0,selected:H.get(R.page)??vg,entityOfChar:_,entityLoader:C,convert:m,buildHref:y??bg,handlers:z},`page-sec-${R.page}`))})]})},vg=new Set,kg=[];function wg(e){const n=g.useRef(new Map);return g.useMemo(()=>{const o=new Map;e.forEach(s=>{const a=parseInt(s.split(":")[0],10);let l=o.get(a);l||o.set(a,l=new Set),l.add(s)});const r=new Map;return o.forEach((s,a)=>{const l=n.current.get(a),d=l&&l.size===s.size&&Array.from(s).every(c=>l.has(c));r.set(a,d?l:s)}),n.current=r,r},[e])}function Sg(e,n){const o=Array.from(n(e.join("")));return o.length===e.length&&e.every(r=>Array.from(r).length===1)?o:e.map(r=>n(r))}const _g=g.memo(function({pGroup:n,first:o,selected:r,entityOfChar:s,entityLoader:a,convert:l,buildHref:d,handlers:c}){const p=g.useMemo(()=>{const m=new Map;if(!l)return m;for(const h of n.paragraphs){const f=Sg(h.chars.map(x=>x.charData.char),l);h.chars.forEach((x,k)=>m.set(x.charData.id,f[k]))}return m},[n,l]),u=m=>p.get(m.id)??m.char;return t.jsxs("section",{"data-page-section":n.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96},children:[!o&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:i("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:i("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},children:["第 ",n.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:i("rule")}})]}),n.paragraphs.map(m=>t.jsx("p",{className:"guji-reflow-paragraph",children:jg(m.chars,s).map((h,f)=>{const x=h.chars.map(({charData:w,col:b,beforePuncts:j,afterPuncts:S},v)=>{const $=!!h.entity&&v===0,_=!!h.entity&&v===h.chars.length-1,C=$?[]:j,M=_?[]:S;return t.jsxs(g.Fragment,{children:[C.map(T=>t.jsx("span",{className:"guji-text-punct","data-punct-id":T.id,children:T.mark},T.id)),t.jsx("span",{"data-char-id":w.id,onClick:()=>c.click(w.id),onMouseEnter:()=>c.enter(w.id),onMouseLeave:c.leave,className:`guji-text-char${r.has(w.id)?" is-selected":""}${w.sub?" is-sub":""}`,title:`[第${n.page}葉·第${b}列·第${w.slot||w.pos}字] ${u(w)}`,children:u(w)}),M.map(T=>t.jsx("span",{className:"guji-text-punct","data-punct-id":T.id,children:T.mark},T.id))]},w.id)});if(!h.entity)return t.jsx(g.Fragment,{children:x},`r${f}`);const k=h.chars[0].beforePuncts.map(w=>t.jsx("span",{className:"guji-text-punct","data-punct-id":w.id,children:w.mark},w.id)),y=h.chars[h.chars.length-1].afterPuncts.map(w=>t.jsx("span",{className:"guji-text-punct","data-punct-id":w.id,children:w.mark},w.id));return t.jsxs(g.Fragment,{children:[k,t.jsx(br,{span:h.entity,label:h.chars.map(w=>u(w.charData)).join(""),hasBrackets:!0,loader:a,buildHref:d,onNavigate:c.navigate,renderText:()=>x,hoverDelayMs:250}),y]},`${h.entity.key}@${f}`)})},m.id))]})}),pc=1,uc=6,Jn={s:1,x:0,y:0},ii=(e,n,o)=>Math.min(o,Math.max(n,e));function jr(e,n,o){const r=ii(e.s,pc,uc);return{s:r,x:ii(e.x,n*(1-r),0),y:ii(e.y,o*(1-r),0)}}function Zi(e,n,o,r,s,a){const l=ii(e.s*r,pc,uc),d=l/e.s;return jr({s:l,x:n-(n-e.x)*d,y:o-(o-e.y)*d},s,a)}function $g(e,n,o,r,s){return jr({s:e.s,x:e.x+n,y:e.y+o},r,s)}function Cg(e,n,o){const r=n===1?e*16:n===2?e*400:e;return Math.exp(-r*(o?.01:.0015))}const Ms=4,zg=g.forwardRef(function({children:n,onScaleChange:o,resetKey:r,style:s},a){const l=g.useRef(null),[d,c]=g.useState(Jn),p=g.useRef(d),u=g.useRef(o);u.current=o;const m=b=>{var S;const j=p.current;p.current=b,c(b),b.s!==j.s&&((S=u.current)==null||S.call(u,b.s))},h=()=>{var j;const b=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(b==null?void 0:b.width)??0,h:(b==null?void 0:b.height)??0,left:(b==null?void 0:b.left)??0,top:(b==null?void 0:b.top)??0}};g.useImperativeHandle(a,()=>({zoomBy(b){const{w:j,h:S}=h();m(Zi(p.current,j/2,S/2,b,j,S))},reset(){m(Jn)}})),g.useEffect(()=>{m(Jn)},[r]),g.useEffect(()=>{const b=l.current;if(!b||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:S,h:v}=h(),$=jr(p.current,S,v);($.x!==p.current.x||$.y!==p.current.y)&&m($)});return j.observe(b),()=>j.disconnect()},[]),g.useEffect(()=>{const b=l.current;if(!b)return;const j=S=>{const v=Cg(S.deltaY,S.deltaMode,S.ctrlKey);if(p.current.s<=1&&v<1)return;S.preventDefault();const{w:$,h:_,left:C,top:M}=h();m(Zi(p.current,S.clientX-C,S.clientY-M,v,$,_))};return b.addEventListener("wheel",j,{passive:!1}),()=>b.removeEventListener("wheel",j)},[]);const f=g.useRef(new Map),x=g.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),k=b=>{if(b.pointerType==="mouse"&&b.button!==0)return;f.current.set(b.pointerId,{x:b.clientX,y:b.clientY});const j=x.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[S,v]=[...f.current.values()];j.pinchDist=Math.hypot(S.x-v.x,S.y-v.y),j.moved=Ms+1}},y=b=>{var H;const j=f.current.get(b.pointerId);if(!j)return;const S={x:b.clientX,y:b.clientY};f.current.set(b.pointerId,S);const v=x.current,{w:$,h:_,left:C,top:M}=h();if(f.current.size>=2){const[N,I]=[...f.current.values()],L=Math.hypot(N.x-I.x,N.y-I.y);if(v.pinchDist>0&&L>0){const R=(N.x+I.x)/2-C,P=(N.y+I.y)/2-M;m(Zi(p.current,R,P,L/v.pinchDist,$,_))}v.pinchDist=L,v.swallowClick=!0;return}const T=S.x-j.x,z=S.y-j.y;if(v.moved+=Math.abs(T)+Math.abs(z),!(v.moved<=Ms)){if(!v.dragging){v.dragging=!0;try{(H=l.current)==null||H.setPointerCapture(b.pointerId)}catch{}}v.swallowClick=!0,p.current.s>1&&m($g(p.current,T,z,$,_))}},w=b=>{f.current.delete(b.pointerId);const j=x.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:k,onPointerMove:y,onPointerUp:w,onPointerCancel:w,onClickCapture:b=>{x.current.swallowClick&&(x.current.swallowClick=!1,b.stopPropagation(),b.preventDefault())},onDoubleClick:()=>m(Jn),style:{position:"relative",overflow:"hidden",touchAction:"none",cursor:d.s>1?"grab":void 0,...s},children:t.jsx("div",{className:"bim-zp-inner",style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",transformOrigin:"0 0",transform:`translate(${d.x}px, ${d.y}px) scale(${d.s})`,willChange:d.s>1?"transform":void 0},children:n})})});function mc(e,n,o,r,s){const[a,l]=g.useState(n??null),[d,c]=g.useState(!1),p=g.useRef(0);return g.useEffect(()=>{if(n!==void 0){l(n);return}const u=++p.current;if(!o){l(null),c(!1);return}if(e){let m;try{m=e(o,s)}catch{l(null),c(!1);return}if(!m||typeof m.then!="function"){l(m??null),c(!1);return}c(!0),m.then(h=>{u===p.current&&l(h??null)}).catch(()=>{u===p.current&&l(null)}).finally(()=>{u===p.current&&c(!1)});return}if(r!=null&&r.warp_data){if(typeof r.warp_data=="object"){l(r.warp_data);return}if(typeof r.warp_data=="string"){c(!0),fetch(r.warp_data).then(m=>m.ok?m.json():null).then(m=>{u===p.current&&l(m)}).catch(()=>{u===p.current&&l(null)}).finally(()=>{u===p.current&&c(!1)});return}}l(null),c(!1)},[e,n,o,r,s]),{warpData:a,loading:d}}function Tg(e,n,o){const[r,s]=g.useState([]),a=g.useRef(0);return g.useEffect(()=>{const l=++a.current;if(!e||!n){s([]);return}let d;try{d=e(n,o)}catch{s([]);return}Promise.resolve(d).then(c=>{l===a.current&&s(c?oc(c):[])}).catch(()=>{l===a.current&&s([])})},[e,n,o]),r}const Bs={padding:24,color:i("desc-fg"),fontSize:14};function Ws({title:e,label:n,className:o,style:r}){const s=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:i("rule")});return t.jsxs("div",{className:o,style:{...r,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:i("ink"),fontFamily:i("font-ui")},children:e}),t.jsx("div",{style:s("42%",24,28)}),t.jsx("div",{style:s("30%",12,10)}),["96%","100%","92%","98%","64%"].map((a,l)=>t.jsx("div",{style:s(a,16,l===0?30:14)},l)),t.jsx("p",{role:"status",style:{marginTop:24,color:i("desc-fg"),fontSize:14,fontFamily:i("font-ui")},children:n})]})}const Os=/^https?:\/\//i;function Ng(e){if(!e||typeof e!="object")return null;const n=a=>typeof a=="string"&&a.trim()?a.trim():void 0,o=n(e.url),r=n(e.license_url),s={name:n(e.name),url:o&&Os.test(o)?o:void 0,license:n(e.license),license_url:r&&Os.test(r)?r:void 0,note:n(e.note)};return s.name||s.license||s.note?s:null}function Eg(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 Ig(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 hc(e,n,o,r=!1){const s=o(`${n}${e.n}`);if(!e.title)return s;const a=o(e.title);return r&&!/^[卷冊册章篇回第]/.test(e.title)?`${s} ${a}`:a}function Rg(e,n,o,r,s){var p;const a=new Map(e.chapters.map(u=>[u.file,u])),l=u=>u==="loading"?"…":typeof u=="number"&&u>0?u:void 0,d=(u,m)=>{const h=a.get(u);return{key:u,label:m??(h?hc(h,o,r,s):u),hint:l(n[u]),disabled:n[u]===0}},c=(p=e.juan_groups)==null?void 0:p.filter(u=>{var m;return u.files.some(h=>a.has(h))||((m=u.children)==null?void 0:m.length)});if(c&&c.length>0){const u=(m,h)=>{var x;if(m.files.length===1&&!((x=m.children)!=null&&x.length))return d(m.files[0],r(m.label));const f=Wh(m,n);return{key:`group:${h}`,label:r(m.label),hint:f==="loading"?"…":typeof f=="number"&&f>0?`${f}`:nc(m),defaultExpanded:typeof f=="number"&&f>0,children:[...m.files.filter(k=>a.has(k)).map(k=>d(k)),...(m.children??[]).map((k,y)=>u(k,`${h}.${y}`))]}};return c.map((m,h)=>u(m,`${h}`))}return e.chapters.map(u=>d(u.file))}const vr=({id:e,transport:n,versionKey:o,chapter:r,onLocationChange:s,onNavigate:a,title:l,subtitle:d,resolveImages:c,renderImageOverlay:p,imagePanel:u,allowVertical:m,onReportError:h,revisedAt:f,backHref:x,backLabel:k,resolveWarpData:y,warpData:w,resolveEntities:b,onEntityNavigate:j,className:S,style:v})=>{var Hr,Fr,Dr;const{t:$,convert:_}=J(),C=g.useMemo(()=>dl(n),[n]),[M,T]=yl(),z=Je(),H=g.useRef(s);H.current=s;const[N,I]=g.useState(null),[L,R]=g.useState("loading");g.useEffect(()=>{let W=!1;return I(null),R("loading"),C.getManifest(e).then(de=>{W||(de?(I(de),R("ready")):R("missing"))}).catch(()=>{W||R("missing")}),()=>{W=!0}},[C,e]);const P=o!==void 0,U=r!==void 0,[q,D]=g.useState(null),[O,A]=g.useState(null);g.useEffect(()=>{D(null),A(null)},[e]);const G=Se.pickTextVersion(N,P?o:q),le=((Hr=N==null?void 0:N.versions.find(W=>W.key==="default"))==null?void 0:Hr.key)??((Fr=N==null?void 0:N.versions[0])==null?void 0:Fr.key)??"default",ne=(G==null?void 0:G.key)??null,ve=U?r:O,oe=g.useCallback((W,de,Pe)=>{var Fe;(Fe=H.current)==null||Fe.call(H,{key:W,chapter:de,isDefault:W===le},Pe)},[le]);g.useEffect(()=>{!N||!P||o==null||N.versions.some(W=>W.key===o)||oe(le,null,"auto")},[N,P,o,le,oe]);const pe=g.useRef(new Map);g.useEffect(()=>{pe.current.clear()},[C,e]);const We=g.useCallback(async W=>{const de=`${e}
1296
- ${W}`;if(pe.current.has(de))return pe.current.get(de)??null;const Pe=await C.getIndex(e,W).catch(()=>null);return Pe&&pe.current.set(de,Pe),Pe},[C,e]),[ee,Be]=g.useState(null),[Ee,X]=g.useState("loading");g.useEffect(()=>{if(!ne)return;let W=!1;return Be(null),X("loading"),We(ne).then(de=>{W||(de&&de.chapters.length>0?(Be(de),X("ready")):X("failed"))}),()=>{W=!0}},[ne,We]),g.useEffect(()=>{if(!ee||!ne||ve!=null&&ee.chapters.some(Pe=>Pe.file===ve))return;const de=ee.chapters[0].file;U||A(de),oe(ne,de,"auto")},[ee,ne,ve,U,oe]);const ie=ee?ve!=null&&ee.chapters.some(W=>W.file===ve)?ve:ee.chapters[0].file:ve,he=g.useMemo(()=>ee&&ie?ee.chapters.find(W=>W.file===ie)??null:null,[ee,ie]),Te=g.useRef(0),K=g.useCallback(async W=>{if(!N||W===ne||!N.versions.some(ot=>ot.key===W))return;const de=++Te.current,Pe=await We(W);if(de!==Te.current)return;const Fe=he??(ie?{file:ie}:null),Xe=Se.matchChapterAcrossVersions(Fe,Pe);P||D(W),U||A(Xe),oe(W,Xe,"version")},[N,ne,We,he,ie,P,U,oe]),_e=g.useCallback(W=>{ne&&(U||A(W),oe(ne,W,"chapter"))},[ne,U,oe]),[se,$e]=g.useState(null),Z=ne&&he?`${e}
1297
- ${ne}
1298
- ${he.file}`:null,[Ne,Oe]=g.useState(null),B=Z!==null&&Ne!==Z,te=g.useRef(0);g.useEffect(()=>{if(!ne||!he)return;const W=++te.current,de=`${e}
1299
- ${ne}
1300
- ${he.file}`;$e(null),C.getChapter(e,ne,he.file,{json:!!he.has_json}).then(Pe=>{W===te.current&&$e(Pe)}).catch(()=>{W===te.current&&$e(null)}).finally(()=>{W===te.current&&Oe(de)})},[C,e,ne,he]);const be=(G==null?void 0:G.kind)==="collated",[Ie,F]=g.useState("");g.useEffect(()=>{F("")},[e,ne]);const ue=g.useMemo(()=>ne&&be?async W=>{const de=await C.getChapter(e,ne,W,{json:!0});return{juan:(de==null?void 0:de.json)??null,rawText:(de==null?void 0:de.md)??null}}:null,[C,e,ne,be]),Q=(ee==null?void 0:ee.type)==="kaozhen",ye=g.useMemo(()=>(ee==null?void 0:ee.chapters.map(W=>W.file))??[],[ee]),{matchStates:Ce}=Jh({resetKey:`${e}
1301
- ${ne??""}`,load:ue,files:ye,activeFile:ie??null,activeJuan:(se==null?void 0:se.json)??null,activeRawText:(se==null?void 0:se.md)??null,query:Ie,isKaozhen:Q}),Me=g.useRef(new Map);g.useEffect(()=>{Me.current.clear()},[e]);const De=g.useMemo(()=>({versionKey:ne,chapter:he??null}),[ne,he]),qe=$h(c,ie??null,De),{warpData:me,loading:Ve}=mc(y,w,ie??null,he,De),E=Tg(b,ie??null,De),[re,ae]=g.useState(new Set),[je,ke]=g.useState(null),[ge,Le]=g.useState(!0),[V,xe]=g.useState(!0),Ae=g.useRef(null),[Y,fe]=g.useState(1),[ce,we]=g.useState(null),Ge=W=>{var Pe;const de=parseInt(((Pe=W==null?void 0:W.page_id)==null?void 0:Pe.split(":")[1])??"",10);return isNaN(de)?null:de},He=W=>{var Pe,Fe;const de=(W==null?void 0:W.pages)??[];return Ge(W)??((Pe=de.find(Xe=>Xe.columns.some(ot=>ot.chars.length>0)))==null?void 0:Pe.page)??((Fe=de[0])==null?void 0:Fe.page)??1},[Ue,xt]=g.useState(()=>He(me)),Wt=`${e}
1302
- ${ne}
1303
- ${ie??""}`,[Jt,fn]=g.useState({key:Wt,data:me,started:!!me});if(Jt.key!==Wt)fn({key:Wt,data:me,started:!1});else if(me!==Jt.data&&(fn({key:Wt,data:me,started:!!me}),me)){const W=me.pages??[];(!Jt.started||!W.some(de=>de.page===Ue))&&xt(He(me))}g.useEffect(()=>{ae(new Set),ke(null)},[ie,ne]);const Fn=g.useCallback(W=>{if(ae(new Set(W)),W.length>0){const de=W[0],Pe=parseInt(de.split(":")[0],10);isNaN(Pe)||xt(Pe)}},[]),bt=g.useMemo(()=>{const W=new Map;for(const de of(me==null?void 0:me.pages)??[])W.set(de.page,de);return W},[me]),It=Ge(me),Dn=g.useCallback(W=>{var Fe;const de=qe.images;if(!de||de.length===0)return;const Pe=(Fe=bt.get(W))==null?void 0:Fe.seq;return(Pe?de.find(Xe=>Xe.seq===Pe):void 0)??de.find(Xe=>Xe.pageNo===W)??de[W-1]},[qe.images,bt]),Pr=Y>1.5,Un=g.useCallback((W,de=!1)=>{const Pe=Dn(W);return Pe?W===It||de?Pe.hiresUrl??Pe.url:Pe.url:W===It?(me==null?void 0:me.imageUrl)??"":""},[Dn,me,It]),Md=g.useMemo(()=>Un(Ue,Pr),[Un,Ue,Pr]),xn=g.useMemo(()=>[...bt.keys()].sort((W,de)=>W-de),[bt]),Li=g.useRef(Ue);Li.current=Ue;const bn=g.useCallback(W=>{var Xe;const de=Li.current,Pe=xn.indexOf(de),Fe=xn[Pe<0?0:Pe+W];Fe===void 0||Fe===de||(Li.current=Fe,xt(Fe),(Xe=bt.get(Fe))!=null&&Xe.columns.some(ot=>ot.chars.length>0)&&we(ot=>({page:Fe,nonce:((ot==null?void 0:ot.nonce)??0)+1})))},[xn,bt]),Ai=xn.indexOf(Ue),Bd=g.useCallback(W=>{if(W.altKey||W.ctrlKey||W.metaKey)return;const de=W.target.tagName;de==="INPUT"||de==="TEXTAREA"||de==="SELECT"||(W.key==="ArrowLeft"||W.key==="PageUp"?(W.preventDefault(),bn(-1)):(W.key==="ArrowRight"||W.key==="PageDown")&&(W.preventDefault(),bn(1)))},[bn]);g.useEffect(()=>{if(me)for(const W of[1,-1,2,3]){const de=Un(Ue+W);de&&ko(de)}},[me,Ue,Un]);const Mr=g.useMemo(()=>{var Yr;if(!me)return null;if(Ue===It)return me;const W=bt.get(Ue);if(W&&W.width>0&&W.height>0)return{page_id:`p:${Ue}`,title:`第${Ue}葉`,image_size:[W.width,W.height],total_warped_w:W.width,columns:[{col:1,warped_w:W.width,warped_h:W.height,offset_x:0,strips:[],chars:W.columns.flatMap(Ke=>Ke.chars).map(Ke=>({id:Ke.id,char:Ke.char,slot:Ke.slot,pos:Ke.pos,sub:Ke.sub,bbox_col:Ke.bbox??[0,0,0,0]}))}]};const de=(Yr=me.pages)==null?void 0:Yr.find(Ke=>Ke.page===Ue),[Pe,Fe]=me.image_size||[2386,3082],Xe=Dn(Ue),ot=(Xe==null?void 0:Xe.width)??Pe,Oi=(Xe==null?void 0:Xe.height)??Fe,Ur=ot/Pe,Vr=Oi/Fe,Gr=new Map;for(const Ke of me.columns){const ct=(Ke.strips||[]).flatMap(Yn=>Yn.srcQuad.map(Kn=>Kn[0]));if(ct.length===0)continue;const _t=Ke.top_y??0,Hi=Ke.bottom_y??_t+Ke.warped_h;Gr.set(Ke.col,{x0:Math.min(...ct),x1:Math.max(...ct),top:_t,slotH:(Hi-_t)/21})}return{page_id:`p:${Ue}`,title:`第${Ue}葉`,image_size:[ot,Oi],total_warped_w:ot,columns:de?de.columns.map(Ke=>{const ct=Gr.get(Ke.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Ke.col,warped_w:ot,warped_h:Oi,offset_x:0,strips:[],chars:Ke.chars.map(_t=>{const Hi=_t.slot??_t.pos??0,Yn=(ct.top+(Hi-1)*ct.slotH)*Vr,Kn=(ct.x0+ct.x1)/2,[Gd,Yd]=_t.sub==="a"?[Kn,ct.x1]:_t.sub==="b"?[ct.x0,Kn]:[ct.x0,ct.x1];return{..._t,bbox_col:[Gd*Ur,Yn,Yd*Ur,Yn+ct.slotH*Vr]}})}}):[]}},[me,Ue,It,bt,Dn]),{entryTitle:Vn,authors:Br}=Pg(e,n,l===void 0),[Wr,Pi]=g.useState("text");if(g.useEffect(()=>{Pi("text")},[ie,ne]),L==="loading")return t.jsx(Ws,{className:S,style:v,title:l??Vn,label:$("reader.loading")});if(L==="missing"||!N||!G)return t.jsx("div",{className:S,style:{...v,...Bs},children:$("reader.noText")});if(Ee==="failed")return t.jsx("div",{className:S,style:{...v,...Bs},children:$("reader.tocFailed")});if(!ee)return t.jsx(Ws,{className:S,style:v,title:l??Vn,label:$("reader.tocLoading")});const Ot=Ig(G,ee),Wd=Rg(ee,Ce,Ot,_,be),Mi=N.versions.map(W=>({key:W.key,label:Se.textVersionLabel(W),optionLabel:_(Se.textVersionLabel(W)),sourceName:W.source_name?_(W.source_name):void 0,license:W.license??void 0,sourceUrl:W.source_url??void 0,primary:W.key===le})),lt=Ng((Dr=ee.source)==null?void 0:Dr.upstream),Gn=(typeof l=="string"?_(l):l)??(ee.title?_(ee.title):Vn?_(Vn):void 0),Od=Gn?t.jsx("a",{href:z(e),title:$("reader.viewEntry"),onClick:a?W=>{W.metaKey||W.ctrlKey||(W.preventDefault(),a(e))}:void 0,children:Gn}):void 0,Hd=Br.length>0?_(Br.slice(0,2).map(W=>`${W.dynasty?`〔${W.dynasty}〕`:""}${W.name}${` ${W.role||$("reader.defaultRole")}`}`).join("、")):void 0,Bi=he?hc(he,Ot,_,be):void 0,Qt=be&&!!(se!=null&&se.json),Ht=(se==null?void 0:se.json)??null,en=(se==null?void 0:se.md)??null,Or=Qt&&!Q&&ic(Ht.sections),Fd=Or&&!(en&&M.readingMode==="paragraph"&&ci(en)),Dd=Qt&&Or?t.jsx(Qh,{juan:Ht,view:Wr,onView:Pi,textHasEntries:Fd}):void 0,Ud=al(ee)||co(ee),Wi=en?en.replace(/^##\s+[^\n]+\n+/,""):null,Vd=(typeof d=="string"?_(d):d)??(G.source_name?_(G.source_name):_(Se.textVersionLabel(G)));return t.jsxs(kl,{className:S,style:v,title:Od,subtitle:Vd,byline:Hd,current:Bi,pagerUnit:Ot,rail:Dd,revisedAt:f,backHref:x,backLabel:k,onReportError:h?W=>h({...W,bookTitle:typeof Gn=="string"?Gn:void 0,entryId:e}):void 0,workLinkToggle:Qt&&!Q&&!!a&&!!(Ht!=null&&Ht.sections.some(W=>W.work_id)),toc:Wd,tocCaption:$("reader.tocCaption",{n:ee.chapters.length,unit:_(Ot)}),tocHeader:be&&ee.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:Q?$("reader.searchChaptersPlaceholder"):$("reader.searchUnitPlaceholder",{unit:_(Ot)}),"aria-label":Q?$("reader.searchChapters"):$("reader.searchUnit",{unit:_(Ot)}),value:Ie,onChange:W=>F(W.target.value)}):void 0,activeKey:ie??null,onSelect:_e,images:qe.images,imagesLoading:qe.loading||Ve,renderImageOverlay:p,imagePanel:me?"open":u,isWarpMode:!!me,customImagePanel:me&&Mr?t.jsxs("div",{className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Bd,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",outline:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 4px 6px",fontSize:12,color:i("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",disabled:Ai<=0,onClick:()=>bn(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":Ue,style:{fontSize:11,padding:"1px 6px",background:i("rule"),borderRadius:10},children:["第 ",Ue," 葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",disabled:Ai<0||Ai>=xn.length-1,onClick:()=>bn(1),children:"›"})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[re.size>0&&t.jsxs("button",{type:"button",onClick:()=>ae(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${i("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",re.size,")"]}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:2},"data-testid":"facsimile-zoom-tools",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小",title:"缩小",disabled:Y<=1,onClick:()=>{var W;return(W=Ae.current)==null?void 0:W.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(Y*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:Y>=6,onClick:()=>{var W;return(W=Ae.current)==null?void 0:W.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:Y===1,onClick:()=>{var W;return(W=Ae.current)==null?void 0:W.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(zg,{ref:Ae,resetKey:Ue,onScaleChange:fe,style:{flex:1,minHeight:0},children:t.jsx(hr,{imageUrl:Md,pageData:Mr,selectedCharIds:re,hoveredCharId:je,preserveMargins:V,onCharClick:W=>{ae(Pe=>{const Fe=new Set(Pe);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const de=document.querySelector(`[data-char-id="${W}"]`);de&&de.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:ke})}),t.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"8px 0 2px"},children:t.jsxs("div",{style:{display:"inline-flex",border:`1px solid ${i("rule")}`,borderRadius:4,overflow:"hidden"},children:[t.jsx("button",{type:"button",onClick:()=>xe(!1),"aria-pressed":!V,className:`bim-rd-t ${V?"":"bim-rd-on"}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:V?"transparent":i("accent-bg"),color:V?"inherit":i("accent")},title:"去空白:紧凑裁切版心",children:"去空白"}),t.jsx("button",{type:"button",onClick:()=>xe(!0),"aria-pressed":V,className:`bim-rd-t ${V?"bim-rd-on":""}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:V?i("accent-bg"):"transparent",color:V?i("accent"):"inherit"},title:"保留空白:完整呈现古籍天头地脚与白边",children:"保留空白"})]})})]}):void 0,toolbarExtra:me?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-badge-warp",children:"图文对读"}),t.jsx("button",{type:"button",className:`bim-rd-t ${ge?"bim-rd-on":""}`,"aria-pressed":ge,title:"切换外挂现代断句标点",onClick:()=>Le(W=>!W),children:ge?"标点":"无标点"})]}):void 0,prefs:M,onPrefsChange:T,versions:Mi.length>1?Mi:void 0,currentVersionKey:Mi.length>1?G.key:void 0,onVersionChange:K,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:ci(en),allowVertical:m,children:[B&&t.jsx(Xt,{}),!B&&me&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:he!=null&&he.title?_(he.title):Bi}),(G.source_name||G.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[G.source_name&&_(G.source_name),G.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),G.license]})]})]}),t.jsx(yr,{pageData:me,pages:me.pages,punctuations:me.punctuations||[],selectedCharIds:re,hoveredCharId:je,onSelectionChange:Fn,onCharClick:W=>{ae(Pe=>{const Fe=new Set(Pe);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const de=parseInt(W.split(":")[0],10);isNaN(de)||xt(de)},onCharHover:ke,mode:"horizontal",showPunctuation:ge,entities:M.properNames?E:void 0,entityTransport:n,onEntityNavigate:j,onVisiblePageChange:W=>xt(W),convert:_,scrollToPage:ce})]}),!B&&!me&&Qt&&Ht&&t.jsx(Zh,{juan:Ht,rawText:en,positionLabel:Lg(he,ee,Ot,_),groupLabel:Ag(ee,ie??null),index:Eg(e,ee),searchQuery:Ie,onNavigate:a,transport:n,workLabelCache:Me,prefs:M,view:Wr,onViewChange:Pi},`${ne}/${ie}`),!B&&!me&&!Qt&&Wi!=null&&he&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:he.title?_(he.title):Bi}),(G.source_name||G.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[G.source_name&&t.jsxs(t.Fragment,{children:[$("reader.textSource")," ",G.source_url?t.jsx("a",{className:"bim-rd-link",href:G.source_url,target:"_blank",rel:"noreferrer",children:_(G.source_name)}):_(G.source_name)]}),G.source_name&&G.license&&t.jsx("span",{className:"bim-rd-dot"}),G.license]}),lt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[$("reader.upstream")," ",lt.url?t.jsx("a",{className:"bim-rd-link",href:lt.url,target:"_blank",rel:"noreferrer",children:_(lt.name??lt.url)}):_(lt.name??""),lt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),lt.license_url?t.jsx("a",{className:"bim-rd-link",href:lt.license_url,target:"_blank",rel:"noreferrer",children:lt.license}):lt.license]}),lt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(pl,{text:lt.note,convert:_})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(ar,{text:Wi,mode:M.readingMode,tables:Ud,gujiMarkdown:co(ee),properNames:M.properNames})})]}),!B&&!me&&!Qt&&Wi==null&&he&&t.jsx("div",{className:"bim-rd-state",children:$("reader.chapterFailed")}),ee.references&&ee.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:$("reader.references")}),t.jsx("ol",{children:ee.references.map((W,de)=>t.jsxs("li",{children:[W.url?t.jsx("a",{className:"bim-rd-link",href:W.url,target:"_blank",rel:"noopener noreferrer",children:_(W.title)}):t.jsx("span",{children:_(W.title)}),W.author&&t.jsxs("span",{children:[",",_(W.author)]}),W.note&&t.jsxs("span",{children:["。",_(W.note)]})]},de))})]})]})};function Lg(e,n,o,r){var a,l;if(!e)return;const s=(l=(a=n.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(s?`${s}冊`:`${o}${e.n}`)}function Ag(e,n){if(!n)return;const o=r=>{var s;for(const a of r??[]){const l=o(a.children);if(l)return l;if((s=a.files)!=null&&s.includes(n))return a.label}};return o(e.juan_groups)}function Pg(e,n,o){const[r,s]=g.useState({entryTitle:void 0,authors:[]});return g.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let a=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);s({entryTitle:o&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,n,o]),r}const gc={bug:{key:"bug",color:i("danger")},resource:{key:"resource",color:i("primary")},suggestion:{key:"suggestion",color:i("primary")},other:{key:"other",color:i("desc-fg")}},Mg=gc.other,fc={pending:{key:"pending",color:i("warning")},in_progress:{key:"in_progress",color:i("primary")},resolved:{key:"resolved",color:i("success")},wontfix:{key:"wontfix",color:i("desc-fg")},duplicate:{key:"duplicate",color:i("desc-fg")}},Bg=fc.pending;function Wg(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 Og(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 kr=({items:e,loading:n})=>{const o=Je(),{t:r,convert:s}=J();return n?t.jsx(Xt,{}):e.length===0?t.jsx("div",{style:Hg,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=gc[a.type]||Mg,d=fc[a.status]||Bg,c=typeof window<"u"&&Og(a.pageUrl,window.location.href);return t.jsxs("div",{style:Fg,children:[t.jsxs("div",{style:Dg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Hs,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Hs,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Ug,children:Wg(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Vg,children:[a.resourceId&&t.jsx("a",{href:o(a.resourceId),style:Ji,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Ji,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Ji,children:a.pageUrl}))]}),t.jsx("div",{style:Gg,children:s(a.content)}),a.reply&&t.jsxs("div",{style:Yg,children:[t.jsx("div",{style:Kg,children:r("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},Hg={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Fg={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Dg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Hs={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Ug={fontSize:"12px",color:i("desc-fg")},Vg={fontSize:"12px",marginBottom:"6px"},Ji={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Gg={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},Yg={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Kg={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},So=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:a})=>{const l=ze(),[d,c]=g.useState(null),[p,u]=g.useState([]),[m,h]=g.useState("recommend"),[f,x]=g.useState([]),[k,y]=g.useState(!1),w=r??m,b=L=>{h(L),s==null||s(L)},[j,S]=g.useState(!0),[v,$]=g.useState(null),[_,C]=g.useState(null),[M,T]=g.useState(null);g.useEffect(()=>{let L=!1;if(e.getCounts)return e.getCounts().then(R=>{L||c({works:R.works,books:R.books,collections:R.collections})}).catch(()=>{}),()=>{L=!0}},[e]),g.useEffect(()=>{let L=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const P=await e.getRecommended();if(P!=null&&P.groups)return P.groups.flatMap(U=>U.items.map(q=>({...q,group:U.name})))}catch{}return[]})().then(async P=>{if(L)return;const U=P.filter(D=>D.id);if(U.length===0){S(!1);return}const q=await Promise.all(U.map(async D=>{if(D.type)return{id:D.id,title:D.title,type:D.type,author:D.author,dynasty:D.dynasty,role:D.role,edition:D.edition,has_text:D.has_text,has_image:D.has_image,has_collated:D.has_collated,subtype:D.subtype,primary_name:D.primary_name,group:D.group,fallbackDescription:D.description};try{let O=null;if(e.getEntry)O=await e.getEntry(D.id);else{const A=await e.getItem(D.id);A&&(O={id:D.id,title:A.title||D.id,type:A.type||"work"})}if(O)return{...O,group:D.group,fallbackDescription:D.description}}catch{}return{id:D.id,title:D.title,type:Se.extractType(D.id),group:D.group,fallbackDescription:D.description}}));L||(u(q.filter(D=>D!==null)),S(!1))}),()=>{L=!0}},[e,o]);const z=g.useRef(!1),H=g.useRef(!1),N=g.useRef(!1);g.useEffect(()=>{if(w!=="catalog"||z.current)return;const L=e.getCatalogProgress??e.getResourceProgress;if(!L)return;z.current=!0;let R=!1;return L.call(e).then(P=>{R||$(P)}).catch(()=>{z.current=!1}),()=>{R=!0}},[e,w]),g.useEffect(()=>{if(w!=="collection"||H.current||!e.getCollectionProgress)return;H.current=!0;let L=!1;return e.getCollectionProgress().then(R=>{L||C(R)}).catch(()=>{H.current=!1}),()=>{L=!0}},[e,w]),g.useEffect(()=>{if(w!=="site"||N.current||!e.getSiteProgress)return;N.current=!0;let L=!1;return e.getSiteProgress().then(R=>{L||T(R)}).catch(()=>{N.current=!1}),()=>{L=!0}},[e,w]),g.useEffect(()=>{if(!a||w!=="feedback")return;let L=!1;return y(!0),fetch(a).then(R=>R.json()).then(R=>{!L&&R.success&&x(R.items||[])}).catch(()=>{}).finally(()=>{L||y(!1)}),()=>{L=!0}},[a,w]);const I=L=>t.jsx(gn,{type:L,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(Sn,{label:l.home.recommendTab,active:w==="recommend",onClick:()=>b("recommend")}),t.jsx(Sn,{label:l.home.catalogTab,active:w==="catalog",onClick:()=>b("catalog")}),t.jsx(Sn,{label:l.home.collectionTab,active:w==="collection",onClick:()=>b("collection")}),t.jsx(Sn,{label:l.home.siteTab,active:w==="site",onClick:()=>b("site")}),a&&t.jsx(Sn,{label:l.home.feedbackTab,active:w==="feedback",onClick:()=>b("feedback")})]}),w==="recommend"&&t.jsx(qg,{recommended:p,loading:j,onNavigate:n,getIcon:I,t:l}),w==="catalog"&&t.jsx(Fs,{progress:v,t:l,onNavigate:n}),w==="collection"&&t.jsx(Fs,{progress:_,t:l,onNavigate:n}),w==="site"&&t.jsx(Zg,{progress:M,t:l,totalWorks:(d==null?void 0:d.works)??0}),w==="feedback"&&a&&t.jsx(kr,{items:f,loading:k})]})})},Sn=({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}),qg=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const a=Je();if(n)return t.jsx(Xt,{});if(e.length===0)return null;const l=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(l.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(p=>{const u=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return t.jsxs("a",{href:a(p.id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o==null||o(p.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(p.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[p.title,p.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:p.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},p.id)})})]},d))})},Fs=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(Xt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],a={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(p=>p.status===d);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[d]}}),a[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(p=>t.jsx(Xg,{item:p,t:n,statusColor:l[d],onNavigate:o},p.id))})]},d)})})},Xg=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Je(),a=e.total>0?Math.round(e.imported/e.total*100):0,l=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const d=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:p=>p.currentTarget.style.borderBottomStyle="solid",onMouseLeave:p=>p.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:l})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?ut(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${a}%`,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})]})},Zg=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(Xt,{});const r=[...e.resources].sort((c,p)=>c.priority-p.priority),s=r.filter(c=>c.imported>0),a=r.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),d=o>0?Math.round(l/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:l.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Ds,{item:c,t:n,totalWorks:o},c.id))})]}),a.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," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(Ds,{item:c,t:n,totalWorks:o},c.id))})]})]})},Ds=({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})]})},Us="(max-width: 768px)";function Jg(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(Us).matches);return g.useEffect(()=>{const o=window.matchMedia(Us),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const Qg=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var H;const a=ze(),{convert:l}=Re(),d=Jg(),[c,p]=g.useState(null),[u,m]=g.useState(null),[h,f]=g.useState(!1),[x,k]=g.useState("detail"),[y,w]=g.useState([]),[b,j]=g.useState(!1),S=g.useCallback(async N=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){w([]);return}j(!0);try{if(e.getCollectionCatalogs){const I=await e.getCollectionCatalogs(N);w(I||[])}else if(e.getCollectionCatalog){const I=await e.getCollectionCatalog(N);w(I?[{resource_id:"",data:I}]:[])}}catch{w([])}finally{j(!1)}},[e]),v=g.useCallback(async N=>{if(o){o(N);return}p(N),m(null),w([]),k("detail"),f(!0);try{const I=await e.getItem(N.id);I&&(m(I),I.type==="collection"&&S(N.id))}catch(I){console.error("加载详情失败:",I)}finally{f(!1)}},[e,o,S]),$=g.useCallback(async N=>{m(null),w([]),k("detail"),f(!0);try{const I=await e.getItem(N);I&&(m(I),p({id:N,title:I.title||N,type:I.type||"book"}),I.type==="collection"&&S(N))}catch(I){console.error("导航失败:",I)}finally{f(!1)}},[e,S]),_=typeof(u==null?void 0:u.text_count)=="number"&&u.text_count>0,C=(u==null?void 0:u.type)==="collection"&&(y.length>0||b)||(u==null?void 0:u.type)==="work"&&_,M=d&&(h||u),T=g.useCallback(()=>{p(null),m(null),w([]),k("detail")},[]),z=t.jsx(t.Fragment,{children:h?t.jsx(Xt,{}):u?t.jsxs(t.Fragment,{children:[(C||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:d?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[C&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:Qn(x==="detail"),children:a.detailTab.basicInfo}),u.type==="collection"&&b&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:Qn(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(N=>t.jsx("button",{onClick:()=>k(`catalog:${N.resource_id}`),style:Qn(x===`catalog:${N.resource_id}`),children:N.short_name?`${l(N.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},N.resource_id)),u.type==="work"&&_&&t.jsx("button",{onClick:()=>k("collated"),style:Qn(x==="collated"),children:a.detailTab.collatedEdition})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:x==="detail"?t.jsx(Fo,{data:u,transport:e,onNavigate:$}):x.startsWith("catalog:")?t.jsx(Do,{data:(H=y.find(N=>`catalog:${N.resource_id}`===x))==null?void 0:H.data,onNavigate:$}):x==="collated"?t.jsx(vr,{id:u.id,transport:e,onNavigate:$}):null})]}):t.jsx(So,{transport:e,onNavigate:$,recommendedIds:r})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children: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:T,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",a.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:z})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(lo,{transport:e,onEntryClick:v,hideModeIndicator:n}),!u&&t.jsx(So,{transport:e,onNavigate:$,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(lo,{transport:e,onEntryClick:v,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:z})]})};function Qn(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}}const ef=({pageData:e,rawImageUrl:n="",punctuations:o=[],title:r,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=g.useState(new Set),[u,m]=g.useState(null),[h,f]=g.useState("horizontal"),[x,k]=g.useState(!0),y=g.useRef(null),w=g.useCallback(v=>{p(new Set(v))},[]),b=g.useCallback(v=>{if(p($=>{const _=new Set($);return _.has(v)?_.delete(v):(_.clear(),_.add(v)),_}),y.current){const $=y.current.querySelector(`[data-char-id="${v}"]`);$&&$.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var v;p(new Set),window.getSelection&&((v=window.getSelection())==null||v.removeAllRanges())},S=o.length>0?o:e.punctuations||[];return t.jsxs("div",{className:`guji-reader-container ${l}`,style:d,children:[t.jsxs("header",{className:"guji-reader-header",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&t.jsx("button",{type:"button",onClick:a,className:"guji-reader-btn",style:{marginRight:6},children:"‹ 返回"}),t.jsx("span",{className:"guji-reader-title",children:r||e.title}),s&&t.jsx("span",{style:{fontSize:"0.85rem",color:i("meta-fg")},children:s}),t.jsx("span",{className:"guji-reader-tag",children:"WebGL 客户端透视矫正对读"})]}),t.jsxs("div",{className:"guji-reader-actions",children:[t.jsxs("span",{style:{fontSize:"0.85rem",color:i("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:i("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>k(v=>!v),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f(v=>v==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:h==="horizontal"?"切换竖排":"切换横排"})]})]}),t.jsxs("div",{className:"guji-reader-body",children:[t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%",position:"sticky",top:0},children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:"底本书影 (WebGL 分带透视矫正 + 完整版心)"}),t.jsx("span",{className:"guji-pane-hint",children:"点击字框可联动文本定位"})]}),t.jsx("div",{className:"guji-pane-content",children:t.jsx(hr,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:u,onCharClick:b,onCharHover:m})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:y,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:h==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(yr,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:u,onSelectionChange:w,onCharClick:b,onCharHover:m,mode:h,showPunctuation:x})]})]})]})},tf=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function nn(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function nf(e){var r,s,a,l,d,c;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return[];const o=[];for(const p of n){if(!p||typeof p!="object")continue;const u=p,m=nn((r=u.page)==null?void 0:r.index),h=Array.isArray(u.cells)?u.cells:[];if(m===void 0||h.length===0)continue;const f=new Map;for(const x of h){if(!x||typeof x!="object")continue;const k=x,y=tf.exec(String(k.a??""));if(!y||typeof k.c!="string")continue;const w=parseInt(y[2],10),b=parseInt(y[3],10),j=Array.isArray(k.box)&&k.box.length===4&&k.box.every($=>nn($)!==void 0)?k.box:null,S={id:String(k.a),char:k.c,slot:b,pos:b,sub:y[4]||null,bbox:j?[j[0],j[1],j[0]+j[2],j[1]+j[3]]:null};let v=f.get(w);v||f.set(w,v=[]),v.push(S)}o.push({page:m,seq:String(((s=u.canvas)==null?void 0:s.seq)??""),width:nn((a=u.canvas)==null?void 0:a.width)??nn((l=u.image)==null?void 0:l.width)??0,height:nn((d=u.canvas)==null?void 0:d.height)??nn((c=u.image)==null?void 0:c.height)??0,columns:Array.from(f.entries()).sort((x,k)=>x[0]-k[0]).map(([x,k])=>({col:x,chars:k}))})}return o}function of(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.punctuations)?e.punctuations:[],o=[];for(const r of n){if(!r||typeof r!="object")continue;const s=r;typeof s.anchor!="string"||typeof s.mark!="string"||o.push({id:typeof s.id=="string"?s.id:void 0,anchor:s.anchor,mark:s.mark,kind:s.kind,pos:s.pos,pre_char:s.pre_char})}return o}function rf(e){var o;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return null;for(const r of n){const s=/\/iiif\/([^/]+)\/canvas\/([^/]+)\//.exec(String(((o=r==null?void 0:r.canvas)==null?void 0:o.id)??""));if(s)return{bookId:s[1],vol:s[2]}}return null}const sf=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function ht(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Vs(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(o=>!!o&&typeof o=="object"):[]}function af(e,n){var l,d,c,p,u,m,h,f,x,k;const o=new Map,r=new Map;for(const y of Vs(n)){const w=ht(y.page);if(w!==void 0){o.set(w,y);for(const b of Array.isArray(y.cells)?y.cells:[]){const j=b==null?void 0:b.box;typeof(b==null?void 0:b.a)=="string"&&Array.isArray(j)&&j.length===4&&j.every(S=>ht(S)!==void 0)&&r.set(b.a,[j[0],j[1],j[0]+j[2],j[1]+j[3]])}}}const s=[];for(const y of Vs(e)){const w=ht(y.page);if(w===void 0)continue;const b=[];for(const S of Array.isArray(y.columns)?y.columns:[]){const v=ht(S==null?void 0:S.col);if(v===void 0)continue;const $=[];for(const _ of Array.isArray(S.cells)?S.cells:[]){const C=sf.exec(String((_==null?void 0:_.a)??""));if(!C||typeof _.c!="string")continue;const M=parseInt(C[3],10);$.push({id:_.a,char:_.c,slot:M,pos:M,sub:C[4]||null,bbox:r.get(_.a)??null})}$.length>0&&b.push({col:v,chars:$})}if(b.length===0)continue;b.sort((S,v)=>S.col-v.col);const j=o.get(w);s.push({page:w,seq:String(((l=j==null?void 0:j.canvas)==null?void 0:l.seq)??""),width:ht((d=j==null?void 0:j.canvas)==null?void 0:d.width)??ht((c=j==null?void 0:j.image)==null?void 0:c.width)??0,height:ht((p=j==null?void 0:j.canvas)==null?void 0:p.height)??ht((u=j==null?void 0:j.image)==null?void 0:u.height)??0,columns:b})}const a=new Set(s.map(y=>y.page));for(const[y,w]of o){const b=(m=w==null?void 0:w.canvas)==null?void 0:m.seq;a.has(y)||typeof b!="string"&&typeof b!="number"||String(b)===""||s.push({page:y,seq:String(b),width:ht((h=w.canvas)==null?void 0:h.width)??ht((f=w.image)==null?void 0:f.width)??0,height:ht((x=w.canvas)==null?void 0:x.height)??ht((k=w.image)==null?void 0:k.height)??0,columns:[]})}return s.sort((y,w)=>y.page-w.page)}const lf=({data:e,onNavigate:n,className:o,style:r})=>{var u;const{t:s,convert:a}=J(),[l,d]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,p]=g.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:a(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:[s("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",s("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[s("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",s("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:s("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(m=>t.jsx(cf,{division:m,expanded:l===m.name,onToggle:()=>d(l===m.name?null:m.name),expandedCat:c,onCatToggle:h=>p(c===h?null:h),onNavigate:n},m.name))})]})},cf=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=J(),c=e.categories.reduce((p,u)=>{const m=u.stats||{zhulu:0,cunmu:0};return p+(m.zhulu||0)+(m.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(p=>{const u=`${e.name}/${p.name}`;return t.jsx(df,{category:p,expanded:r===u,onToggle:()=>s(u),onNavigate:a},p.name)})})]})},df=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var p,u,m,h;const{t:s,convert:a}=J(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((u=e.books)==null?void 0:u.cunmu)||[],c=(((m=e.stats)==null?void 0:m.zhulu)||l.length)+(((h=e.stats)==null?void 0:h.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:s("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[s("catalogPage.booksN",{n:c})," ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Gs,{label:s("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(Gs,{label:s("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},Gs=({label:e,books:n,onNavigate:o})=>{const{t:r,convert:s}=J(),a=Je(),[l,d]=g.useState(n.length<=20),c=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:c.map((p,u)=>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:p.work_id&&o?t.jsx("a",{href:a(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o(p.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:s(p.title)}):s(p.title)}),p.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.volumes)}),p.author&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.author).slice(0,20)})]},u))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:n.length})})]})},yt=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const a=ze();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:uf,children:"AI"}),n&&t.jsx("button",{onClick:n,style:pf,children:a.action.save})]})]}),s]})},pf={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},uf={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},pt=({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:a=>o(a.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"}})]}),Yt=({value:e,onChange:n,placeholder:o})=>{const r=g.useRef(null);return g.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},pi=({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 mf(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const oi=({value:e,onChange:n,label:o})=>{const[r,s]=g.useState(!1),a=g.useRef(null),l=mf(e||"");return g.useEffect(()=>{r&&a.current&&a.current.focus()},[r]),!r&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ys,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:l.name}),t.jsx(pi,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ys,children:o}),t.jsx("input",{ref:a,type:"text",value:e||"",onChange:d=>n(d.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Ys={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function hf(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function gf(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const xc=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=ze(),[s,a]=g.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=m=>{n(e.filter((h,f)=>f!==m)),s===m&&a(null)},c=(m,h,f)=>{const x=[...e];x[m]={...x[m],[h]:f},n(x)},p=(m,h)=>{const f=[...e];f[m]={...f[m],type:h,id:"",name:""},n(f),h==="bookID"&&o&&o(x=>{const k=[...e];k[m]={...k[m],id:x.id,name:x.title,type:"bookID"},n(k)})},u=m=>{o&&o(h=>{const f=[...e];f[m]={...f[m],id:h.id,name:h.title,type:"bookID"},n(f)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,h)=>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:()=>a(s===h?null:h),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===h?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:m.name||`${r.editor.sourcePlaceholder} ${h+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:hf(m.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:gf(m.type)}),t.jsx("button",{onClick:f=>{f.stopPropagation(),d(h)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===h&&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:$t,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Ks,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:()=>p(h,"url"),style:{...Ks,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:$t,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:qs,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(h),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(h),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:$t,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:qs,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:f=>c(h,"name",f.target.value),placeholder:r.editor.sourceNamePlaceholder,style:on})]}),t.jsxs("div",{children:[t.jsx("label",{style:$t,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:f=>c(h,"id",f.target.value),placeholder:"https://...",style:on})]})]}),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:{...$t,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:$t,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:f=>c(h,"details",f.target.value),placeholder:r.editor.detailsPlaceholder,style:on})]}),t.jsxs("div",{children:[t.jsx("label",{style:$t,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:f=>c(h,"position",f.target.value),placeholder:"如: 卷三, p.52",style:on})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:$t,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:f=>c(h,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:on})]}),t.jsxs("div",{children:[t.jsx("label",{style:$t,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:f=>c(h,"processor_version",f.target.value),placeholder:"如: v0.1",style:on})]})]})]})]})})]},h)),t.jsxs("button",{onClick:l,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})]})]})},$t={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},on={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"},Ks={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"},qs={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function bc(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 yc(e){return!e||e.length===0?"":JSON.stringify(e)}const jc=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:u,onLinkEntity:m,onUnlinkEntity:h,onViewEntity:f,onCreateAndLink:x,onSaveRelations:k})=>{const y=ze();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})]}),k&&t.jsx("button",{onClick:k,style:ff,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(_n,{direction:"up",title:y.relation.belongsToWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("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(_n,{direction:"up",title:y.relation.containedInCollection,entity:l,onView:f,onUnlink:()=>h("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),a&&u&&u.length>0&&t.jsx(rn,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:f,onAdd:()=>x("siblingBook","book",{workId:a.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(_n,{direction:"up",title:y.relation.parentWork,entity:r,onView:f,onUnlink:()=>h("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>x("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),d&&d.length>0&&t.jsx(rn,{direction:"down",title:`${y.relation.childWorks} (${d.length})`,entities:d,onView:f,onAdd:()=>x("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),c&&c.length>0&&t.jsx(rn,{direction:"down",title:`${y.relation.collectionImpl} (${c.length})`,entities:c,onView:f,onAdd:()=>x("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(rn,{direction:"down",title:`${y.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("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(_n,{direction:"up",title:y.relation.correspondingWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("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(_n,{direction:"up",title:y.relation.parentCollection,entity:s,onView:f,onUnlink:()=>h("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>x("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(rn,{direction:"down",title:`${y.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:f,onAdd:()=>x("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(rn,{direction:"down",title:`${y.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},_n=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:u,unlinkLabel:m})=>{const h=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=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:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),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:vc(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(Xs,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(Xs,{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:p}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(_o,{onClick:a,children:d}),t.jsx(_o,{onClick:l,primary:!0,children:c})]})]})},rn=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=g.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",h=c?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(f=>t.jsxs("div",{onClick:()=>r(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:vc(f.type)}),t.jsx("span",{children:f.title})]},f.id)),o.length>5&&!c&&t.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[d," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:l}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(_o,{onClick:s,primary:!0,children:["+ ",a]})})]})},Xs=({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}),_o=({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 vc(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const ff={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},kc=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[u,m]=g.useState(""),h=p?l.filter(y=>y.id!==p):l;g.useEffect(()=>{e&&(m(""),d(""))},[e]);const f=y=>{m(y),d(y)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:xf,children:t.jsxs("div",{style:bf,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:yf,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:y=>f(y.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:jf})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Qi,children:"搜索中..."}):h.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(y=>t.jsxs("div",{onClick:()=>r(y),style:vf,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),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:Qi,children:["未找到匹配的",x]}):t.jsxs("div",{style:Qi,children:["输入关键词搜索",x]})}),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:a,style:kf,children:["创建新",x,"并关联"]})]})]})})},xf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},bf={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")},yf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},jf={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"},vf={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},Qi={padding:"20px",textAlign:"center",color:i("desc-fg")},kf={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Zs={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},wf={work:"📜",book:"📖",collection:"📚",entity:"👤"},wc=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:a})=>{const[l,d]=g.useState(""),c=g.useRef(null);g.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var h,f;(h=c.current)==null||h.focus(),(f=c.current)==null||f.select()},100))},[e,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&l.trim()?u():h.key==="Escape"&&a()},u=()=>{l.trim()&&s(l.trim(),{...r,title:l.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`创建新${Zs[n]}`}};return t.jsx("div",{style:Sf,onClick:h=>{h.target===h.currentTarget&&a()},children:t.jsxs("div",{style:_f,onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:wf[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:c,type:"text",value:l,onChange:h=>d(h.target.value),onKeyDown:p,placeholder:`请输入${Zs[n]}名称...`,style:$f})]}),((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:a,style:Cf,children:"取消"}),t.jsx("button",{onClick:u,disabled:!l.trim(),style:{...zf,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Sf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},_f={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")},$f={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"},Cf={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},zf={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function Tf(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Sc(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Nf(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 _c=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:u})=>{const[m,h]=g.useState(""),[f,x]=g.useState([]),[k,y]=g.useState(!1),[w,b]=g.useState("recent");g.useEffect(()=>{e&&(h(""),x([]),b(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!m.trim()){x([]);return}const C=setTimeout(async()=>{y(!0);try{x(await u(m,o))}catch{x([])}finally{y(!1)}},300);return()=>clearTimeout(C)},[m,o,u]);const j=g.useCallback(C=>{h(C.target.value),C.target.value.trim()&&b("search")},[]),S=g.useCallback(C=>s?C.filter(M=>M.id!==s):C,[s]);if(!e)return null;const v=n||(o==="all"?"选择实体":`选择${Sc(o)}`),$=S(r),_=S(f);return t.jsx("div",{style:If,children:t.jsxs("div",{style:Rf,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Lf,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:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Af}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs(Js,{active:w==="recent",onClick:()=>b("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs(Js,{active:w==="search",onClick:()=>b("search"),children:["搜索结果 ",_.length>0&&`(${_.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:w==="recent"&&$.length>0?t.jsx(Qs,{entities:$,onSelect:d}):m.trim()?k?t.jsx(eo,{message:"搜索中..."}):_.length>0?t.jsx(Qs,{entities:_,onSelect:d}):t.jsx(eo,{message:"未找到匹配的结果"}):t.jsx(eo,{message:"输入关键词开始搜索"})}),a&&p&&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:p,style:Pf,children:l||"创建新实体"})]})]})})},Js=({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}),Qs=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Ef,{entity:o,onClick:()=>n(o)},o.id))}),Ef=({entity:e,onClick:n})=>{const[o,r]=g.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Tf(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:Nf(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Sc(e.type)})]})},eo=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),If={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Rf={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")},Lf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Af={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"},Pf={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Mf={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Bf={work:"📜",collection:"📚",book:"📖",entity:"👤"},$c=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:u,relations:m,onRelationsChange:h})=>{var $e;const f=ze(),[x,k]=g.useState(!1),[y,w]=g.useState("work"),[b,j]=g.useState(""),[S,v]=g.useState(""),[$,_]=g.useState([]),[C,M]=g.useState(!1),[T,z]=g.useState(!1),[H,N]=g.useState("work"),[I,L]=g.useState(""),[R,P]=g.useState(),[U,q]=g.useState(!1),[D,O]=g.useState(null),[A,G]=g.useState([]);g.useRef(null);const le=e.type,ne=le==="work",ve=le==="collection",oe=le==="book",pe=g.useCallback((Z,Ne)=>{n({...e,[Z]:Ne})},[e,n]),We=g.useCallback((Z,Ne)=>{j(Z),w(Ne),v(f.editor.selectToLink+f.indexType[Ne]),_([]),k(!0)},[f]),ee=g.useCallback(Z=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,Z)},[r,e.id]),Be=g.useCallback(Z=>{s==null||s(Z.id,Z.type)},[s]),Ee=g.useCallback((Z,Ne,Oe)=>{const B={...Oe,author:(Oe==null?void 0:Oe.author)||e.author,dynasty:Oe==null?void 0:Oe.dynasty};N(Ne),L(Z),P(B),z(!0)},[e.author]),X=g.useCallback((Z,Ne)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,I,{type:H,title:Z,inheritData:Ne}),z(!1)},[r,e.id,I,H]),ie=g.useCallback(Z=>{if(!Z.trim()){_([]);return}M(!0),r!=null&&r.searchEntities&&r.searchEntities(Z,y).then(Ne=>{_(Ne),M(!1)}).catch(()=>{_([]),M(!1)})},[r,y]),he=g.useCallback(Z=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,b,Z.id),k(!1)},[r,e.id,b]),Te=g.useCallback(()=>{o()},[o]),K=g.useCallback(Z=>{O(()=>Z),q(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(G).catch(()=>{})},[r]),_e=g.useCallback((Z,Ne)=>r!=null&&r.searchEntities?r.searchEntities(Z,Ne==="all"?void 0:Ne):Promise.resolve([]),[r]),se=g.useCallback(Z=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(Z),G(Ne=>[Z,...Ne.filter(Oe=>Oe.id!==Z.id)].slice(0,10)),D==null||D(Z),q(!1),O(null)},[r,D]);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:Bf[le]}),t.jsx("span",{children:e.title||f.editor.untitled}),t.jsx(pi,{children:e.id}),t.jsx(pi,{color:Mf[le],children:f.indexType[le]})]})}),t.jsx(yt,{title:f.section.basicInfo,onSave:o,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(oi,{label:ne?f.editor.workTitle:ve?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:Z=>pe("title",Z)}),oe&&t.jsx(oi,{label:f.editor.belongsToWork,value:e.workName||"",onChange:Z=>pe("workName",Z)}),t.jsx(pt,{label:f.editor.authorLabel,value:e.author||"",onChange:Z=>pe("author",Z)}),t.jsx(pt,{label:f.editor.publicationYearLabel,value:e.publicationYear||"",onChange:Z=>pe("publicationYear",Z)}),(oe||ve)&&t.jsx(oi,{label:f.editor.containedIn,value:e.collection||"",onChange:Z=>pe("collection",Z)}),(oe||ve)&&t.jsx(pt,{label:f.editor.holderLabel,value:e.holder||"",onChange:Z=>pe("holder",Z)}),(oe||ve)&&t.jsx(pt,{label:oe?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:Z=>pe("pages",Z)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(pt,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:Z=>pe("firstImage",Z)})})]})}),t.jsx(yt,{title:f.section.description,onSave:o,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Yt,{value:e.description||"",onChange:Z=>pe("description",Z),placeholder:f.editor.descriptionPlaceholder})}),((($e=e.additional_works)==null?void 0:$e.length)||0)>0&&t.jsx(yt,{title:f.section.additionalWorks,onSave:o,children:t.jsx(Wf,{items:e.additional_works||[],onChange:Z=>pe("additional_works",Z)})}),t.jsx(yt,{title:f.section.indexedBy,onSave:o,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Of,{items:e.indexed_by||[],onChange:Z=>pe("indexed_by",Z)})}),t.jsx(yt,{title:f.section.emendatedBy,onSave:o,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Hf,{items:e.emendated_by||[],onChange:Z=>pe("emendated_by",Z)})}),t.jsx(yt,{title:f.section.textResources,onSave:o,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(so,{items:e.resources||[],onChange:Z=>pe("resources",Z),onDownload:p,downloadStatuses:u,filterType:"text"})}),t.jsx(yt,{title:f.section.imageResources,onSave:o,children:t.jsx(so,{items:e.resources||[],onChange:Z=>pe("resources",Z),onDownload:p,downloadStatuses:u,filterType:"image"})}),t.jsx(yt,{title:f.section.sources,onSave:o,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(xc,{items:bc(e.sources||""),onChange:Z=>pe("sources",yc(Z)),onOpenEntityPicker:K})}),(oe||ve)&&t.jsx(yt,{title:f.section.provenance,onSave:o,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Yt,{value:e.provenance||"",onChange:Z=>pe("provenance",Z),placeholder:f.editor.provenancePlaceholder})}),oe&&t.jsx(yt,{title:f.section.otherEditions,onSave:o,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Yt,{value:e.otherEditions||"",onChange:Z=>pe("otherEditions",Z),placeholder:f.editor.otherEditionsPlaceholder})}),t.jsx(jc,{entityType:le,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:We,onUnlinkEntity:ee,onViewEntity:Be,onCreateAndLink:Ee,onSaveRelations:Te}),a&&l&&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:f.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:f.editor.dangerZoneDesc}),t.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:f.editor.deleteEntity})]}),t.jsx(kc,{isOpen:x,entityType:y,title:S,onSelect:he,onCancel:()=>k(!1),onCreate:()=>{k(!1),Ee(b,y)},searchResults:$,onSearch:ie,isLoading:C,excludeId:e.id}),t.jsx(wc,{isOpen:T,entityType:H,relationField:I,inheritData:R,onConfirm:X,onCancel:()=>z(!1)}),t.jsx(_c,{isOpen:U,title:f.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:e.id,onSelect:se,onCancel:()=>{q(!1),O(null)},onSearch:_e})]})};function Wf({items:e,onChange:n}){const o=ze(),r=(l,d,c)=>{const p=e.map((u,m)=>m===l?{...u,[d]:c}:u);n(p)},s=l=>n(e.filter((d,c)=>c!==l)),a=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((l,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(pt,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(pt,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},d)),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Cc({items:e,onChange:n,showMeta:o,addLabel:r}){const s=ze(),[a,l]=g.useState(null),d=(u,m,h)=>{const f=e.map((x,k)=>k===u?{...x,[m]:h||void 0}:x);n(f)},c=u=>{n(e.filter((m,h)=>h!==u)),a===u&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,m)=>{const h=a===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:h?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(h?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:h?"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:f=>{f.stopPropagation(),c(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!h&&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]}),h&&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(pt,{label:s.label.sourceName,value:u.source,onChange:f=>d(m,"source",f)}),t.jsx(pt,{label:s.label.sourceBid,value:u.source_bid||"",onChange:f=>d(m,"source_bid",f)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(pt,{label:s.label.titleInfo,value:u.title_info||"",onChange:f=>d(m,"title_info",f)}),t.jsx(pt,{label:s.label.authorInfo,value:u.author_info||"",onChange:f=>d(m,"author_info",f)})]}),t.jsx(pt,{label:s.label.edition,value:u.edition||"",onChange:f=>d(m,"edition",f)})]}),t.jsx(Yt,{value:u.summary||"",onChange:f=>d(m,"summary",f),placeholder:s.editor.summaryPlaceholder}),t.jsx(Yt,{value:u.comment||"",onChange:f=>d(m,"comment",f),placeholder:s.editor.commentPlaceholder}),t.jsx(Yt,{value:u.additional_comment||"",onChange:f=>d(m,"additional_comment",f),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),t.jsx("button",{onClick:p,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 Of({items:e,onChange:n}){const o=ze();return t.jsx(Cc,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Hf({items:e,onChange:n}){const o=ze();return t.jsx(Cc,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function zc(e){var d,c,p,u,m,h,f;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",o=((p=e.publication_info)==null?void 0:p.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(m=e.page_count)!=null&&m.number?String(e.page_count.number):((h=e.page_count)==null?void 0:h.description)||"",a=typeof e.description=="object"&&e.description!==null&&e.description.text||"",l={id:e.id,title:e.title,type:e.type,author:n,publicationYear:o,holder:r,pages:s,description:a,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const x=e;if(Array.isArray(x.related_works)){const k=x.related_works.find(y=>y.relation==="part_of");k&&(l.parentWorkId=k.id,l.parentWorkName=k.title)}}if(e.type==="book"){const x=e;l.workId=x.work_id,Array.isArray(x.contained_in)&&x.contained_in.length>0&&(l.collectionId=(f=x.contained_in[0])==null?void 0:f.id)}return l}function Ff(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 Df=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:u,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y,headerExtra:w,className:b,style:j}=e,S=ze(),[v,$]=g.useState(s),_=a?s:v;g.useEffect(()=>{s!==v&&$(s)},[s]);const C=g.useCallback(()=>{const L=_==="view"?"edit":"view";a?a(L):$(L)},[_,a]),[M,T]=g.useState(null);g.useEffect(()=>{o&&r&&r.getItem(o).then(L=>{L&&T(L)})},[o,r]);const z=n||M,H=g.useMemo(()=>z?zc(z):null,[z]),N=a||!n?t.jsx("button",{onClick:C,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"?S.common.switchToEdit:S.common.switchToView,children:_==="view"?S.common.modeEdit:S.common.modeView}):null,I=t.jsxs(t.Fragment,{children:[N,w]});return!z&&!H?t.jsx(Xt,{}):_==="view"?t.jsx(Fo,{data:z,transport:r,onNavigate:p?L=>p(L):void 0,renderLink:u,headerExtra:I,className:b,style:j}):H?t.jsxs("div",{className:b,style:j,children:[I&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:I}),t.jsx($c,{data:H,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:S.common.noData})},Uf=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Tc=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const{t:s}=J(),[a,l]=g.useState(null),[d,c]=g.useState(""),[p,u]=g.useState(""),[m,h]=g.useState("idle"),[f,x]=g.useState(""),k=g.useRef(null);g.useEffect(()=>{e&&(l(null),c(""),u(""),h("idle"),x(""))},[e]),g.useEffect(()=>{a&&setTimeout(()=>{var b;return(b=k.current)==null?void 0:b.focus()},100)},[a]),g.useEffect(()=>{if(m==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[m,n]),g.useEffect(()=>{if(!e)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const y=async()=>{if(!(!a||!d.trim())){h("submitting"),x("");try{await o({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),h("success")}catch(b){h("error"),x(b instanceof Error?b.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&m!=="submitting";return t.jsx("div",{style:Vf,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:Gf,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:Yf,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:Kf,"aria-label":s("feedback.close"),children:"✕"})]}),m==="success"?t.jsxs("div",{style:Qf,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:s("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:s("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Uf.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...qf,...a===b.value?Xf:{}},children:[t.jsx("span",{children:b.icon})," ",s(`feedback.submitType.${b.value}`)]},b.value))}),t.jsx("textarea",{ref:k,value:d,onChange:b=>c(b.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||m==="submitting",style:{...Zf,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:b=>u(b.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||m==="submitting","aria-label":s("feedback.contactLabel"),style:tx}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),m==="error"&&t.jsx("div",{style:ex,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:y,disabled:!w,style:{...Jf,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:s(m==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Vf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Gf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Yf={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Kf={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},qf={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"},Xf={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Zf={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"},Jf={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},Qf={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},ex={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},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"},$o="--bim-feedback-fab-offset",Co=48,nx=16,ix=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const{t:a}=J(),[l,d]=g.useState(!1),c=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty($o,`calc(${c+Co+nx}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty($o)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ox,zIndex:s??i("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":a("feedback.title"),title:a("feedback.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(Tc,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:o})]})},ox={position:"fixed",width:`${Co}px`,height:`${Co}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"},rx=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Nc=({onSubmit:e})=>{const{t:n}=J(),[o,r]=g.useState("bug"),[s,a]=g.useState(""),[l,d]=g.useState(""),[c,p]=g.useState("idle"),[u,m]=g.useState(""),h=g.useRef(null);g.useEffect(()=>{o&&setTimeout(()=>{var k;return(k=h.current)==null?void 0:k.focus()},100)},[o]);const f=async()=>{if(!(!o||!s.trim())){p("submitting"),m("");try{await e({type:o,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),r("bug")}catch(k){p("error"),m(k instanceof Error?k.message:n("feedback.submitFailedRetry"))}}},x=o&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:ea,children:t.jsxs("div",{style:dx,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:px,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:ea,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:rx.map(k=>t.jsxs("button",{onClick:()=>r(k.value),style:{...sx,...o===k.value?ax:{}},children:[t.jsx("span",{children:k.icon})," ",n(`feedback.submitType.${k.value}`)]},k.value))}),t.jsx("textarea",{ref:h,value:s,onChange:k=>a(k.target.value),placeholder:n(o?`feedback.placeholder.${o}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...lx}}),t.jsx("input",{type:"text",value:l,onChange:k=>d(k.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:mx}),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:[s.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!x,style:{...cx,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:ux,children:u})]})},ea={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},sx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ax={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},lx={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"},cx={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},dx={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},px={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ux={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},mx={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 ta(e){return typeof e=="function"?e():e??"/api/feedback"}const Ec=({resourceId:e,apiUrl:n})=>{const{t:o}=J(),[r,s]=g.useState([]),[a,l]=g.useState(!0),d=g.useCallback(async()=>{const p=ta(n);l(!0);try{const m=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();m.success&&s(m.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{d()},[d]);const c=async p=>{const u=ta(n),m=await fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!m.ok){const h=await m.json().catch(()=>null);throw new Error((h==null?void 0:h.error)||o("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(kr,{items:r,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Nc,{onSubmit:c})})]})},hx=mi["zh-Hant"].relation,gx=mi["zh-Hant"].lossStatus,fx=mi["zh-Hant"].resourceKind,Ci=un("zh-Hant"),wr=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function na(e,n=Ci){return e?wr(hx,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function xx(e,n=Ci){return wr(gx,e)?n(`detail.lossStatus.${e}`):e}function bx(e,n=Ci){return wr(fx,e)?n(`detail.resourceKind.${e}`):""}function Sr({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=J(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=Zo(a.role);return t.jsxs(g.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(Ze,{id:a.entity_id,label:r(a.name),onNavigate:n,renderLink:o,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function Ic(e,n,o=Ci){var c,p;const r=qo(e,n),s=r.mirrors.map(u=>({key:u.key,label:u.label,description:u.description,rows:u.items.filter(m=>m.group_role!=="mirror"),mirrors:u.items.filter(m=>m.group_role==="mirror")})),a=r.buckets.filter(u=>u.key==="image"||u.key==="textImage").flatMap(u=>u.items);a.length&&s.push({key:"_images",label:s.length?o("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(u=>u.key==="physical"))==null?void 0:c.items)??[];return l.length&&s.push({key:"_physical",label:o("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((p=r.buckets.find(u=>u.key==="text"))==null?void 0:p.items)??[],groups:s}}function Rc(e,n){const o=(e.url?mn(e.url):void 0)||e.name,r=_l(e,n);return r?`${o}(${r})`:o}function _r({item:e,siblings:n,listedVolumeCounts:o}){const{t:r,convert:s}=J(),[a,l]=g.useState(!1),d=hi(e),c=!!d&&d.expected>0&&!(o!=null&&o.has(d.expected)),p=s(Rc(e,n)),u=hn(e),m=ki(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,x;const h=(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:[((x=e.metadata)==null?void 0:x.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?r("colorMode.color"):r("colorMode.bw")})]}):null;return u?t.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),h]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,h]})})(),m&&t.jsx("span",{className:"bim-d-meta",children:s(m)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(nr,{item:e})})]}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":a,onClick:()=>l(h=>!h),children:a?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Lc({groups:e,listedVolumeCounts:n}){const{t:o,convert:r}=J();return t.jsx(t.Fragment,{children:e.map(s=>t.jsxs("div",{className:"bim-d-rg",children:[s.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(s.label)}),s.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(s.description)}),s.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:s.rows.map((a,l)=>t.jsx(_r,{item:a,siblings:s.rows,listedVolumeCounts:n},`${a.id||a.url||a.name}-${l}`))})}),s.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[s.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:o("detail.mirror")}),s.mirrors.map((a,l)=>{const d=hn(a),c=r(Rc(a,s.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?r(a.details):void 0,children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:c},l)})]})]},s.key))})}const Rn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function zo(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=Rn.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const ia=12,yx=60,Ac=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:a,back:l,railLinks:d})=>{var ie,he,Te;const{t:c,convert:p,messages:u}=J(),m=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[h,f]=g.useState(new Map),[x,k]=g.useState(!1),[y,w]=g.useState(""),[b,j]=g.useState(!1),S=m.length<=yx,v=S||x||!!y||b,$=g.useMemo(()=>v?m:m.slice(0,ia),[m,v]);g.useEffect(()=>{if(!n||$.length===0)return;const K=$.filter(se=>!h.has(se));if(K.length===0)return;let _e=!1;return Promise.all(K.map(se=>n.getItem(se).then($e=>{const Z=$e??{};return[se,{id:se,title:Z.title,edition:Z.edition,resources:Z.resources,publication_info:Z.publication_info,current_location:Z.current_location,lineage:Z.lineage,measure_info:Z.measure_info}]}).catch(()=>[se,{id:se}]))).then(se=>{_e||f($e=>{const Z=new Map($e);for(const[Ne,Oe]of se)Z.set(Ne,Oe);return Z})}),()=>{_e=!0}},[n,$,h]);const _=g.useMemo(()=>m.map(K=>h.get(K)??{id:K}),[m,h]),C=m.length>0&&m.every(K=>h.has(K)),M=!!n&&$.some(K=>!h.has(K)),T=S||v,z=g.useMemo(()=>Cl(_,e.version_graph,{era:y,scanOnly:b,sort:T?"year":"default"}),[_,e.version_graph,y,b,T]),H=x?z.rows:z.rows.slice(0,ia),N=z.allRows.filter(K=>K.hasImage).length,I=e.related_works||[],L=I.filter(K=>K.relation==="collected_in"),R=g.useMemo(()=>{const K=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],_e=se=>{const $e=K.indexOf(se??"");return $e<0?K.length:$e};return I.filter(se=>se.relation!=="collected_in").map((se,$e)=>({r:se,i:$e})).sort((se,$e)=>_e(se.r.relation)-_e($e.r.relation)||se.i-$e.i).map(se=>se.r)},[I]),P=g.useMemo(()=>{const K=qo(e.resources,e.resource_groups);return[...K.mirrors.flatMap(_e=>_e.items.map(se=>({r:se,kind:p(_e.label)}))),...K.buckets.flatMap(_e=>_e.items.map(se=>({r:se,kind:p(bx(_e.key,c))})))]},[e.resources,e.resource_groups,p,c]),U=e.indexed_by||[],q=e.emendated_by||[],D=g.useMemo(()=>{var te,be,Ie;const K=[],_e=(be=(te=e.authors)==null?void 0:te[0])==null?void 0:be.dynasty;_e&&K.push({label:c("workPage.fact.written"),value:p(_e)});const se=Et(e,u.unit.juan);if(se){const F=(Ie=e.juan_count)==null?void 0:Ie.description;K.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(se),F&&F!==se?t.jsxs("span",{className:"bim-d-meta",children:["(",p(F),")"]}):null]})})}e.loss_status&&K.push({label:c("workPage.fact.loss"),value:p(xx(e.loss_status,c))});const $e=z.allRows.filter(F=>F.sortYear!=null),Z=$e.length>0?$e.reduce((F,ue)=>F.sortYear<=ue.sortYear?F:ue):null;Z!=null&&Z.era.era?K.push({label:c("workPage.fact.earliest"),value:p([Z.era.era,Z.era.reign].filter(Boolean).join(" ")),title:Z.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):M&&K.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),q.length&&K.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:q.length})});const Ne=oa(e.additional_titles);Ne.length&&K.push({label:c("workPage.fact.alias"),value:Ne.map(p).join("、")});const Oe=oa(e.attached_texts);Oe.length&&K.push({label:c("workPage.fact.attached"),value:Oe.map(p).join("、")});const B=(e.additional_works||[]).map(F=>p(F.book_title)+(F.n_juan!=null?` ${F.n_juan}${u.unit.juan}`:""));return B.length&&K.push({label:c("workPage.fact.appendix"),value:B.join("、")}),K},[e,p,c,u,M,z.allRows,q.length]),A=[{value:e._edition_count??m.length,label:c("workPage.stat.editions")},{value:C?N:0,label:c("workPage.stat.hasImage")},{value:U.length,label:c("workPage.stat.catalogs")}],G=e.classification,le=G?[G.l1,G.l2,G.l3,G.l4].filter(Boolean).map(K=>p(K)):[],ne=e.subtype?u.workSubtype[e.subtype]??p(e.subtype):"",ve=t.jsx(Mn,{title:p(e.title),byline:t.jsx(Sr,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(et,{items:[...le,G!=null&&G.source?c("workPage.classifiedBy",{source:p(G.source.split("/")[0])}):"",ne]}),description:(ie=e.description)!=null&&ie.text?t.jsxs(t.Fragment,{children:[t.jsx(Nt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(he=e.description.sources)!=null&&he.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(K=>p(Pm(K))).filter(Boolean).join(" · ")}):null]}):void 0,stats:A,facts:D,readAction:s,foot:t.jsx(Bn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Te=e.appendix)==null?void 0:Te.map((K,_e)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(K.title)}),t.jsx(Nt,{text:K.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},_e))}),oe=z.eras.length>=2?[{key:"",label:c("catalog.all")},...z.eras.map(K=>({key:K,label:`${K} ${z.allRows.filter(_e=>_e.era.era===K).length}`}))]:[],pe=[];m.length&&pe.push({id:"versions",label:c("workPage.sec.versions"),count:m.length}),U.length&&pe.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:U.length}),L.length&&pe.push({id:"collected",label:c("workPage.sec.collected"),count:L.length}),R.length&&pe.push({id:"related",label:c("workPage.sec.related"),count:R.length}),P.length&&pe.push({id:"resources",label:c("workPage.sec.resources"),count:P.length});const We=m.length===0&&U.length===0,ee=t.jsxs(t.Fragment,{children:[m.length>0&&t.jsxs(tt,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(et,{items:[c("workPage.versionsTotal",{n:m.length}),C&&N?c("workPage.versionsWithImage",{n:N}):"",z.rows.length!==z.allRows.length?c("workPage.versionsCurrent",{n:z.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":M&&oe.length===0&&m.length>1?"":void 0,children:[oe.length>0&&t.jsx(Si,{items:oe,value:y,onChange:K=>{w(K),k(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Ll,{label:c("workPage.scanOnly"),checked:b,onChange:K=>{j(K),k(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(T?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&_i(z.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:H.map(K=>{var _e;return t.jsx(jx,{row:K,measure:(_e=h.get(K.id))==null?void 0:_e.measure_info,loaded:h.has(K.id),onNavigate:o,renderLink:r},`${K.id}:${h.has(K.id)?"r":"p"}`)})})]}),H.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(y||b?"workPage.noVersionsFiltered":"workPage.noVersions")}),!x&&t.jsx(Jo,{total:z.rows.length,shown:H.length,unit:c("workPage.moreUnit"),onClick:()=>k(!0)}),z.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),U.length>0&&t.jsx(vx,{items:U,transport:n,onNavigate:o,renderLink:r}),We&&t.jsx(tt,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),Be=(K,_e)=>t.jsx(Ze,{id:K,label:p(_e),onNavigate:o,renderLink:r,dense:!0}),Ee=g.useMemo(()=>{const K=new Map;for(const _e of R){const se=na(_e.relation,c);K.set(se,(K.get(se)??0)+1)}return K.size>1?[...K.entries()].sort((_e,se)=>se[1]-_e[1]).slice(0,4).map(([_e,se])=>`${p(_e)} ${se}`).join(" · "):void 0},[R,p,c]),X=t.jsxs(t.Fragment,{children:[t.jsx(Gt,{id:"collected",title:c("workPage.sec.collected"),items:L.map(K=>Be(K.id,K.title))}),t.jsx(Gt,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:R.length}),sub:Ee,items:R.map(K=>t.jsxs(t.Fragment,{children:[Be(K.id,K.title),t.jsx("span",{className:"bim-d-meta",title:K.note?p(K.note):void 0,children:p(na(K.relation,c))})]}))}),t.jsx(Gt,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:P.map(({r:K,kind:_e})=>{const se=p((K.url?mn(K.url):void 0)||K.name),$e=hn(K);return t.jsxs(t.Fragment,{children:[$e?t.jsxs("a",{href:$e,target:"_blank",rel:"noopener noreferrer",children:[se," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:se}),_e&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:_e})]})})})]});return t.jsx(Pn,{railTop:a,back:l,nav:pe,railLinks:d,main:ee,card:ve,side:X})};function oa(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ra(e,n){return n((e.url?mn(e.url):void 0)||e.name)}function jx({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{t:a,convert:l}=J(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],u=p?ra(p,l):e.locationName?l(e.locationName):"",m=e.images[0],h=m?hn(m):void 0,f=e.images.map(x=>ra(x,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ze,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:c?a("workPage.inferredFromEdition"):void 0,children:d?l(d):o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${u?"":" bim-d-zt-blank"}`,children:[u||(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&&(h?t.jsx("a",{className:"bim-d-flag",href:h,target:"_blank",rel:"noopener noreferrer",title:f,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:f,children:a("workPage.hasImage")}))})]})}function vx({items:e,transport:n,onNavigate:o,renderLink:r}){const{t:s,convert:a}=J(),[l,d]=g.useState(0),c=Math.min(l,e.length-1),p=e[c],[u,m]=g.useState(new Map);return g.useEffect(()=>{if(!n)return;const h=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(h.length===0)return;let f=!1;return Promise.all(h.map(x=>n.getItem(x).then(k=>{var y,w;return[x,((w=(y=k==null?void 0:k.authors)==null?void 0:y[0])==null?void 0:w.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{f||m(new Map(x.filter(([,k])=>k)))}),()=>{f=!0}},[n,e]),t.jsx(tt,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(et,{items:[s("workPage.catalog.meta",{n:e.length}),s("workPage.sortByCatalog")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":s("workPage.catalog.tablist"),children:e.map((h,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(h.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(h.source_bid??"")?a(u.get(h.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:[...a(h.source)].slice(0,9).map((x,k)=>t.jsx("span",{children:x},k))})]})},f))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(p.title_info)}),t.jsx(et,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(Ze,{id:p.source_bid,label:a(p.source),onNavigate:o,renderLink:r,dense:!0}):a(p.source),p.section?a(p.section):"",p.author_info?`${s("label.authorInfo")} ${a(p.author_info)}`:"",p.edition?`${s("label.edition")} ${a(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:mt(a(p.summary),void 0,{t:s})}),p.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:mt(a(p.comment),void 0,{t:s})})]}),p.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:mt(a(p.additional_comment),void 0,{t:s})})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("workPage.catalog.titleOnly")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.prev",{name:a(e[c-1].source)}),onClick:()=>d(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.next",{name:a(e[c+1].source)}),onClick:()=>d(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function kx(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function wx(e,n){if(!e.lineage)return null;const o=e.lineage;return{id:e.id,kind:"book",label:e.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[e.id],note:o.note}}function sa(e,n,o){return{id:`derive:${n.ref}->${e}:${o}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Sx(e,n,o){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _x(e,n){var p;if(n==="all")return null;const o=(p=e.collections)==null?void 0:p[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,a=r||s||!!(o!=null&&o.hypothetical_ids);if(!a&&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||!a)return null;const l=r?new Set(o.groups):null,d=new Set(o.book_ids??[]);if(l&&e.node_groups)for(const[u,m]of Object.entries(e.node_groups))l.has(m)&&d.add(u);let c=null;if(o.hypothetical_ids&&(c=new Set(o.hypothetical_ids)),l){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&l.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function ri(e,n,o){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const a=new Set(r.excluded_books??[]),l=r.node_groups??{},d=_x(r,o??r.default_collection??"all"),c=d!==null,p=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,m=new Set,h=new Set;if(c){const S=new Map(n.map(T=>[T.id,T])),v=new Map((r.hypothetical_nodes??[]).map(T=>[T.id,T])),$=T=>{const z=S.get(T);if(z&&z.lineage)return(z.lineage.derived_from??[]).map(N=>N.ref);const H=v.get(T);return H?(H.derived_from??[]).map(N=>N.ref):[]},_=T=>v.has(T)?!u||u.has(T):!p||p.has(T),C=new Set,M=T=>{if(!C.has(T)){C.add(T);for(const z of $(T))a.has(z)||(_(z)||(v.has(z)?h.add(z):S.has(z)&&m.add(z)),M(z))}};for(const T of n)p&&p.has(T.id)&&!a.has(T.id)&&M(T.id);for(const T of r.hypothetical_nodes??[])u&&u.has(T.id)&&M(T.id)}const f=n.filter(S=>!a.has(S.id)).filter(S=>!p||p.has(S.id)||m.has(S.id)).map(S=>{const v=wx(S,l);return v&&m.has(S.id)&&(v.bridge=!0),v}).filter(S=>S!==null),x=(r.hypothetical_nodes??[]).filter(S=>!u||u.has(S.id)||h.has(S.id)).map(S=>{const v=kx(S);return h.has(S.id)&&(v.bridge=!0),v}),k=[...f,...x],y=new Set(k.map(S=>S.id)),w=new Set,b=[],j=S=>{w.has(S.id)||!y.has(S.source)||!y.has(S.target)||(w.add(S.id),b.push(S))};for(const S of n)a.has(S.id)||!S.lineage||p&&!p.has(S.id)&&!m.has(S.id)||((S.lineage.derived_from??[]).forEach((v,$)=>{j(sa(S.id,v,$))}),(S.lineage.related_to??[]).forEach((v,$)=>{j(Sx(S.id,v,$))}));for(const S of r.hypothetical_nodes??[])u&&!u.has(S.id)&&!h.has(S.id)||(S.derived_from??[]).forEach((v,$)=>{j(sa(S.id,v,$))});return{nodes:k,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(a)}}function Pc(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function $x(e,n){const o=[],r=e.version_graph;if(!r)return o;const s=new Set(n.map(c=>c.id)),a=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...a]),d=(c,p)=>{l.has(p.ref)||o.push(`${c}: derived_from.ref "${p.ref}" 未在 books 或 hypothetical_nodes 中找到`),p.ref_type==="book"&&!s.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 book 但不在 books 列表中`),p.ref_type==="hypothetical"&&!a.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const p=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>d(p,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${p}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>d(p,u))}return o}const Mc=({graph:e,renderLink:n,className:o,style:r})=>{const{t:s,convert:a}=J();if(!e.nodes.length)return t.jsx("div",{style:{...Ox,...r},className:o,children:s("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const x=l.get(f.target)??[];x.push(f),l.set(f.target,x)}else for(const x of[f.source,f.target]){const k=d.get(x)??[];k.push(f),d.set(x,k)}const c=new Map(e.nodes.map(f=>[f.id,f])),p=new Map,u=[];for(const f of e.nodes)if(f.group){const x=p.get(f.group)??[];x.push(f),p.set(f.group,x)}else u.push(f);const m=(f,x)=>(f.year??9999)-(x.year??9999);p.forEach(f=>f.sort(m)),u.sort(m);const h=e.groups.filter(f=>p.has(f.id));return t.jsxs("div",{className:o,style:{...zx,...r},children:[e.title&&t.jsx("div",{style:Tx,children:a(e.title)}),e.description&&t.jsx("div",{style:Nx,children:a(e.description)}),h.map(f=>t.jsx(aa,{label:f.label,color:f.color,nodes:p.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},f.id)),u.length>0&&t.jsx(aa,{label:s("lineage.otherGroup"),nodes:u,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},aa=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=J();return t.jsxs("div",{style:Ex,children:[t.jsx("div",{style:{...Ix,borderLeftColor:n??i("widget-border")},children:d(e)}),o.map(c=>t.jsx(Cx,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Cx=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=J();return t.jsxs("div",{style:{...Rx,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?i("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Lx,children:[t.jsx("span",{style:Ax,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Px,children:Pc(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Mx,children:[e.category&&t.jsx($n,{children:c(e.category)}),e.status==="lost"&&t.jsx($n,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx($n,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx($n,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx($n,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Bx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Wx,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:ca,children:[t.jsx("div",{style:da,children:d("lineage.sources")}),n.map(p=>{const u=r.get(p.source);return t.jsxs("div",{style:pa(p.confidence),children:[t.jsx("span",{style:ua,children:c(p.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,c(u.label)):c((u==null?void 0:u.label)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(la,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ma,children:["· ",c(p.evidence)]})]},p.id)})]}),o.length>0&&t.jsxs("div",{style:ca,children:[t.jsx("div",{style:da,children:d("lineage.related")}),o.map(p=>{const u=p.source===e.id?p.target:p.source,m=r.get(u);return t.jsxs("div",{style:pa(p.confidence),children:[t.jsx("span",{style:ua,children:c(p.relation)}),t.jsx("span",{children:(m==null?void 0:m.kind)==="book"&&s?s(m.id,c(m.label)):c((m==null?void 0:m.label)??u)}),t.jsx(la,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ma,children:["· ",c(p.evidence)]})]},p.id)})]})]})},$n=({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})},la=({level:e})=>{const{t:n}=J(),r={certain:{key:"certain",color:i("confidence-certain")},consensus:{key:"consensus",color:i("confidence-consensus")},probable:{key:"probable",color:i("confidence-probable")},disputed:{key:"disputed",color:i("confidence-disputed")}}[e];return r?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:n(`lineage.confidence.${r.key}`)}):null},zx={fontSize:"14px",color:i("fg")},Tx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Nx={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Ex={marginBottom:"16px"},Ix={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Rx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Lx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ax={fontSize:"15px",fontWeight:600},Px={fontSize:"12px",color:i("muted")},Mx={marginBottom:"6px"},Bx={fontSize:"12px",color:i("muted"),margin:"2px 0"},Wx={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},ca={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},da={fontSize:"11px",color:i("muted"),marginBottom:"2px"},pa=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),ua={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},ma={fontSize:"11px",color:i("muted")},Ox={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Bc=({selectedNodeId:e,...n})=>{const{t:o}=J(),[r,s]=g.useState("loading"),[a,l]=g.useState(null);return g.useEffect(()=>{let d=!1;return Hx().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:ga,children:o("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:ga,children:[t.jsx("div",{children:ha(o("lineage.graphMissing"),{xyflow:t.jsx("code",{children:"@xyflow/react"}),dagre:t.jsx("code",{children:"@dagrejs/dagre"})})}),t.jsx("div",{style:{fontSize:"12px",marginTop:"4px"},children:ha(o("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Fx,{modules:a,selectedNodeId:e,...n})};function ha(e,n){return e.split(/(\{\w+\})/).map((o,r)=>{const s=/^\{(\w+)\}$/.exec(o);return t.jsx(g.Fragment,{children:s&&s[1]in n?n[s[1]]:o},r)})}async function Hx(){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 Fx=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:p,Handle:u,Position:m,BaseEdge:h,EdgeLabelRenderer:f,getSmoothStepPath:x,dagre:k}=l,y=g.useMemo(()=>({lineage:$=>{var R,P,U,q;const _=((R=$.data)==null?void 0:R.stepPosition)??.85,[C,M,T]=x({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:_,borderRadius:5}),z=!!((P=$.data)!=null&&P.isSibling),H=z?M:$.targetX-18,N=z?T:$.targetY-12,I=(U=$.data)==null?void 0:U.labelStyle,L=(q=$.data)==null?void 0:q.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(h,{id:$.id,path:C,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${H}px,${N}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...L,...I},children:$.label})})]})}}),[h,f,x]),w=g.useMemo(()=>({version:$=>{const{t:_}=J(),C=$.data,M=C.kind==="hypothetical",T=C.status==="lost",z=C.isSelected,H=C.bridge,N=C.borderColor??i("muted"),I=H||M?"dashed":"solid",L=H?.5:T?.6:1;return t.jsxs("div",{style:{background:i(H?"bg-subtle":"bg"),border:`2px ${I} ${z?i("primary"):N}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:L,boxShadow:z?i("shadow-node-selected"):M||H?"none":i("shadow-node")},title:H?_("lineage.bridgeTitle"):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:M||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Pc(C.yearText,void 0,C.uncertain)}),T&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:_("lineage.lost")}),t.jsx(u,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[u,m]),{convert:b}=J(),{rfNodes:j,rfEdges:S}=g.useMemo(()=>Dx(e,k,n,a,b),[e,k,n,a,b]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(p,{showInteractive:!1})]})})};function Dx(e,n,o,r,s=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const p=new Map(e.groups.map(w=>[w.id,w.color??i("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(u.has(w.relation)||c.setEdge(w.source,w.target));n.layout(c);const m=e.nodes.map(w=>{const b=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:s(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:s(w.year_text??Vx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?p.get(w.group):void 0,renderLink:o,isSelected:j,description:s(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:S,draggable:!1,selected:j}}),h=.78,f=.06,x=new Map;for(const w of e.edges)w.kind==="derive"&&(x.has(w.source)||x.set(w.source,[]),x.get(w.source).push(w));const k=new Map;for(const[w,b]of x){if(b.length<=1)continue;const j=[...b].sort((v,$)=>{var M,T;const _=((M=c.node(v.target))==null?void 0:M.y)??0,C=((T=c.node($.target))==null?void 0:T.y)??0;return _-C}),S=j.length;j.forEach((v,$)=>{const _=($-(S-1)/2)*f;k.set(v.id,h+_)})}const y=e.edges.map(w=>Ux(w,k.get(w.id),s));return{rfNodes:m,rfEdges:y}}function Ux(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=Gx(e.confidence),l={type:"arrowclosed",color:a,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:a,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Vx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Gx(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 ga={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},$r=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:u,style:m})=>{var S;const{t:h,convert:f}=J(),[x,k]=g.useState(n),y=v=>{k(v),a==null||a(v)},w=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:h("lineage.collectionAll"),description:h("lineage.collectionAllDesc")}]]})(),b=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:h("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:u,style:m,children:[t.jsxs("div",{style:Yx,children:[t.jsx("button",{onClick:()=>y("list"),style:to(x==="list"),children:h("lineage.modeList")}),t.jsx("button",{onClick:()=>y("graph"),style:to(x==="graph"),children:h("lineage.modeGraph")}),b&&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:h("lineage.collectionLabel")}),w.map(([v,$])=>{const _=p==null?void 0:p[v];return t.jsxs("button",{onClick:()=>d==null?void 0:d(v),style:to(l===v),title:$.description?f($.description):void 0,children:[f($.label),_!=null?` ${_}`:""]},v)})]})]}),b&&j&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:f(j)}),x==="list"?t.jsx(Mc,{graph:e,renderLink:o}):t.jsx(Bc,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},Yx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},to=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"}),fa=40,xa=2,Kx=9,qx=new Set(["certain","consensus","probable","disputed"]);function no(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Wc=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:u})=>{var Ie,F,ue,Q,ye,Ce,Me,De,qe,me,Ve;const m=ze(),{t:h,convert:f}=J(),[x,k]=g.useState(null),[y,w]=g.useState(new Map),[b,j]=g.useState([]),[S,v]=g.useState(new Map),[$,_]=g.useState(!1),[C,M]=g.useState("flow"),[T,z]=g.useState(null);g.useEffect(()=>{if(!n||!e.work_id){k(null);return}let E=!1;return n.getItem(e.work_id).then(re=>{!E&&re&&re.type==="work"&&k(re)}).catch(()=>{}),()=>{E=!0}},[n,e.work_id]),g.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){z(null);return}let E=!1;return n.getLineageGraph(e.work_id).then(re=>{E||z(re&&re.nodes.length>1?re:null)}).catch(()=>{E||z(null)}),()=>{E=!0}},[n,e.work_id]),g.useEffect(()=>{const E=e.contained_in||[];if(!n||E.length===0){w(new Map);return}let re=!1;return Promise.all(E.map(ae=>{const je=typeof ae=="string"?ae:ae.id;return n.getItem(je).then(ke=>[je,ke]).catch(()=>[je,null])})).then(ae=>{if(re)return;const je=new Map;for(const[ke,ge]of ae)ge&&je.set(ke,ge);w(je)}),()=>{re=!0}},[n,e.contained_in]);const H=g.useMemo(()=>{const E=new Set([...(x==null?void 0:x.books)||[],...e.related_books||[]]);return E.add(e.id),[...E]},[x==null?void 0:x.books,e.related_books,e.id]),N=H.length-1;g.useEffect(()=>{if(!n||N<=0){j([]);return}const E=H.length<=fa,re=E?H:H.slice(0,8);let ae=!1;return Promise.all(re.map(je=>je===e.id?Promise.resolve({id:je,title:e.title,edition:e.edition,year:li(e)}):n.getItem(je).then(ke=>{const ge=ke??{};return{id:je,title:ge.title,edition:ge.edition,year:ke?li(ge):void 0}}).catch(()=>({id:je})))).then(je=>{if(ae)return;const ke=je.filter(ge=>ge.id===e.id||ge.title||ge.edition);E&&ke.sort((ge,Le)=>(ge.year??1/0)-(Le.year??1/0)),j(ke)}),()=>{ae=!0}},[n,H,N,e]);const I=e.lineage,L=g.useMemo(()=>[...((I==null?void 0:I.derived_from)||[]).filter(E=>E.ref_type==="book").map(E=>E.ref),...((I==null?void 0:I.related_to)||[]).map(E=>E.book_id)].filter(Boolean),[I]);g.useEffect(()=>{if(!n||L.length===0){v(new Map);return}let E=!1;return Promise.all(L.map(re=>n.getItem(re).then(ae=>[re,{id:re,title:ae==null?void 0:ae.title,edition:ae==null?void 0:ae.edition}]).catch(()=>[re,{id:re}]))).then(re=>{E||v(new Map(re))}),()=>{E=!0}},[n,L]);const R=g.useMemo(()=>Ic(e.resources,e.resource_groups,h),[e.resources,e.resource_groups,h]),P=R.groups.reduce((E,re)=>E+re.rows.length+re.mirrors.length,0),U=R.groups.length>0&&R.groups.every(E=>E.key==="_physical"),q=An(e),D=Il(e),O=Et(e,m.unit.juan),A=new Set((e.contained_in||[]).map(E=>typeof E=="string"?0:En(E.volume_index).length).filter(E=>E>0)),G=E=>{var je;const re=(je=e.base_edition)==null?void 0:je.find(ke=>ke.book_id===E&&ke.name);if(re!=null&&re.name)return re.name;const ae=S.get(E);return(ae==null?void 0:ae.edition)||(ae==null?void 0:ae.title)||""},le=g.useMemo(()=>{var xe,Ae,Y,fe,ce;const E=[];D&&E.push({label:h("bookPage.fact.editionType"),value:f(D),title:e.edition_type||(xe=e.lineage)!=null&&xe.category?void 0:h("bookPage.inferredFromEdition")}),(Ae=e.publication_info)!=null&&Ae.details?E.push({label:h("bookPage.fact.publication"),value:f(e.publication_info.details)}):(q.era||q.reign)&&E.push({label:h("bookPage.fact.era"),value:f([q.era,q.reign].filter(Boolean).join(" ")),title:q.source==="edition"?h("bookPage.inferredFromEdition"):void 0}),O&&E.push({label:h("bookPage.fact.measure"),value:f(O)});const re=(e.contained_in||[]).flatMap(we=>typeof we=="string"?[]:En(we.volume_index));re.length&&E.push({label:h("bookPage.fact.volumes"),value:h("bookPage.volumesValue",{range:wi(re,m.unit.volume),unit:m.unit.volume,n:re.length})});const ae=(((Y=e.lineage)==null?void 0:Y.derived_from)||[]).find(we=>we.relation==="底本"&&we.ref_type==="book");ae&&G(ae.ref)&&E.push({label:h("bookPage.fact.baseEdition"),value:t.jsx(Ze,{id:ae.ref,label:f(G(ae.ref)),onNavigate:o,renderLink:r,dense:!0})});const je=(e.base_edition||[]).filter(we=>we&&we.name);for(const we of["底本","配補","參校"]){if(we==="底本"&&ae&&G(ae.ref))continue;const Ge=je.filter(He=>He.role===we);Ge.length&&E.push({label:f(we),value:Ge.map((He,Ue)=>t.jsxs(g.Fragment,{children:[Ue>0&&"、",He.book_id?t.jsx(Ze,{id:He.book_id,label:f(He.name),onNavigate:o,renderLink:r,dense:!0}):f(He.name)]},Ue))})}const ke=(e.provenance||[]).filter(we=>we&&we.institution),ge=(e.resources||[]).filter(we=>(we.types||(we.type?[we.type]:[])).includes("physical"));if(ke.length){E.push({label:h("bookPage.fact.holdings"),value:ke.slice(0,2).map(He=>f(He.institution)).join("、")+(ke.length>2?h("bookPage.andMorePlaces",{n:ke.length}):"")});const we=ke.filter(He=>He.call_number).slice(0,2).map(He=>`${f(He.institution)} ${He.call_number}`);we.length&&E.push({label:h("bookPage.fact.callNumber"),value:we.join(";")+(ke.filter(He=>He.call_number).length>2?"…":"")});const Ge=ke.flatMap(He=>He.seals||[]).filter(Boolean);Ge.length&&E.push({label:h("bookPage.fact.seals"),value:f(Ge.join("、"))})}else ge.length?E.push({label:h("bookPage.fact.holdings"),value:ge.slice(0,2).map(we=>f(we.name)).join("、")+(ge.length>2?h("bookPage.andMorePlaces",{n:ge.length}):"")}):(fe=e.current_location)!=null&&fe.name&&E.push({label:h("bookPage.fact.holdings"),value:f(e.current_location.name)});const Le=e.physical_description;if(Le){const we=[[h("bookPage.fact.leafStyle"),Le.leaf_style],[h("bookPage.fact.binding"),Le.binding],[h("bookPage.fact.dimensions"),Le.dimensions],[h("bookPage.fact.condition"),Le.condition]];for(const[Ge,He]of we)He&&He.trim()&&E.push({label:Ge,value:f(He)})}(ce=e.page_count)!=null&&ce.description&&E.push({label:m.label.pageCount,value:f(e.page_count.description)});const V=[...jo(e.additional_titles),...jo(e.attached_texts)];return V.length&&E.push({label:h("bookPage.fact.aliases"),value:V.map(f).join("、")}),E},[e,f,m,h,q,D,O,S,o,r]),ne=f(e.title),ve=e.edition?f(e.edition):void 0,oe=((Ie=e.lineage)==null?void 0:Ie.year_text)||"",pe=t.jsx(Mn,{kind:h("bookPage.kind"),title:ne,subtitle:ve,byline:t.jsx(Sr,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:o,renderLink:r}),meta:(()=>{const E=[D?f(D):"",q.era?f([q.era,q.reign].filter(Boolean).join("")):"",O?f(O):""].filter(Boolean);return E.length?t.jsx("span",{className:"bim-d-tags",children:E.map((re,ae)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ae,2)}`,children:re},ae))}):null})(),description:(F=e.description)!=null&&F.text?t.jsx(Nt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:er((ue=e.description)==null?void 0:ue.text)?6:void 0,facts:le,readAction:s,secondaryAction:s&&P>0&&!U?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:h("bookPage.viewImages")}):void 0,foot:t.jsx(Bn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),We=e.contained_in||[],ee=(a==null?void 0:a.chapters)||[],Be=f(ee[0]&&no(ee[0].title)[0].slice(-1)||"")||h("bookPage.chapterUnit"),Ee=h("bookPage.chapterCount",{n:ee.length,unit:Be}),X=!!((Q=I==null?void 0:I.derived_from)!=null&&Q.length||(ye=I==null?void 0:I.related_to)!=null&&ye.length||(Ce=e.appendix)!=null&&Ce.length),ie=[],he=h(U?"bookPage.sec.physical":"bookPage.sec.images");(ee.length||R.text.length||l)&&ie.push({id:"fulltext",label:h("bookPage.sec.fulltext"),count:ee.length?Ee:void 0}),R.groups.length&&ie.push({id:"images",label:he,count:P}),X&&ie.push({id:"lineage",label:h("bookPage.sec.lineage")}),We.length&&ie.push({id:"collections",label:h("section.containedIn"),count:We.length}),(Me=e.location_history)!=null&&Me.length&&ie.push({id:"provenance",label:h("section.locationHistory")});const Te=E=>(d==null?void 0:d(E))??null,K=ee[0],_e=K?Te(K.file):null,se=$?ee:ee.slice(0,Kx),$e=(E,re,ae)=>E?t.jsx("a",{className:ae,href:E.href??"#",onClick:E.onClick?je=>{je.metaKey||je.ctrlKey||(je.preventDefault(),E.onClick())}:void 0,children:re}):t.jsx("span",{className:ae,children:re}),Z=t.jsxs(t.Fragment,{children:[(ee.length>0||R.text.length>0||l)&&t.jsxs(tt,{id:"fulltext",title:h("bookPage.sec.fulltext"),meta:ee.length>0?t.jsx(et,{items:[Ee,(De=a==null?void 0:a.source)!=null&&De.name?h("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!K&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),K&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:h("bookPage.readFrom",{ch:f(no(K.title)[0])||h("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((K.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),$e(_e,t.jsxs(t.Fragment,{children:[h("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ee.length>1&&t.jsx("ul",{className:"bim-d-chap",children:se.map(E=>{const[re,ae]=no(E.title);return t.jsx("li",{children:$e(Te(E.file),t.jsxs(t.Fragment,{children:[re&&t.jsx("b",{children:f(re)}),f(ae||E.file)]}))},E.file)})}),ee.length>se.length&&t.jsx(Qo,{label:h("detail.expandRest",{n:ee.length-se.length,unit:Be}),onClick:()=>_(!0)}),R.text.length>0&&t.jsxs(t.Fragment,{children:[(ee.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:h("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:R.text.map((E,re)=>t.jsx(_r,{item:E,siblings:R.text,listedVolumeCounts:A},`${E.id||E.url||E.name}-${re}`))})})]})]}),R.groups.length>0&&t.jsx(tt,{id:"images",title:he,meta:t.jsx(et,{items:[R.groups.length>1?h("bookPage.groupCount",{n:R.groups.length}):"",h("bookPage.placeCount",{n:P})]}),children:t.jsx(Lc,{groups:R.groups,listedVolumeCounts:A})}),X&&t.jsx(tt,{id:"lineage",title:h("bookPage.sec.lineage"),meta:(qe=I==null?void 0:I.derived_from)!=null&&qe.length?h("bookPage.lineageMeta"):void 0,action:T?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":h("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":C==="flow",onClick:()=>M("flow"),children:h("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>M("graph"),children:h("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&T?t.jsx($r,{graph:T,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(E,re)=>t.jsx(Ze,{id:E,label:f(re),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(Zx,{data:e,heading:ve||ne,yearText:oe,refName:G,onNavigate:o,renderLink:r})}),We.length>0&&t.jsx(tt,{id:"collections",title:h("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:We.map((E,re)=>{var Le,V;const ae=typeof E=="string"?E:E.id,je=typeof E=="string"?[]:En(E.volume_index),ke=y.get(ae),ge=(ke==null?void 0:ke._member_count)||((Le=ke==null?void 0:ke.books)==null?void 0:Le.length)||((V=ke==null?void 0:ke.contained_works)==null?void 0:V.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ze,{id:ae,label:ke?f(ke.title):ae,onNavigate:o,renderLink:r,dense:!0}),je.length>0&&t.jsx(Xx,{volumes:je,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ge>0&&h("bookPage.totalOf",{n:ge,unit:m.unit.bu})})]},`${ae}-${re}`)})})})}),(me=e.location_history)!=null&&me.length?t.jsx(tt,{id:"provenance",title:h("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((E,re)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(E.name)}),([E.start_date,E.end_date].filter(Boolean).join("—")||E.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(et,{items:[[E.start_date,E.end_date].filter(Boolean).join("—"),E.description?f(E.description):""]})})]},re))})}):null,ie.length===0&&t.jsx(tt,{title:h("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:h("bookPage.emptyText")})})]}),Ne=b.findIndex(E=>E.id===e.id),Oe=H.length<=fa,B=Oe&&Ne>=0?b.slice(Math.max(0,Ne-xa),Ne+xa+1):b.filter(E=>E.id!==e.id),te=t.jsxs(t.Fragment,{children:[x&&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(Ze,{id:x.id,label:f(x.title),onNavigate:o,renderLink:r})}),t.jsx(et,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(E=>`${E.dynasty?`〔${f(E.dynasty)}〕`:""}${f(E.name)}`),f(Et(x,m.unit.juan)),x._edition_count?h("bookPage.editionCount",{n:x._edition_count}):""]}),((Ve=x.description)==null?void 0:Ve.text)&&t.jsx("p",{style:{fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc bim-d-side-desc",children:f(x.description.text.replace(/[#*_>`[\]]/g,""))})]}),N>0&&B.length>0&&t.jsxs("div",{children:[t.jsx(Gt,{id:"siblings",timeline:!0,title:Oe?h("bookPage.siblings"):m.relation.siblingVersions,meta:Oe?h("bookPage.byEra"):h("bookPage.kindCount",{n:N}),cap:B.length,items:B.map(E=>E.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(E.edition||E.title||E.id)}):t.jsx(Ze,{id:E.id,label:f(E.edition||E.title||E.id),onNavigate:o,renderLink:r,dense:!0})),metas:B.map(E=>[E.year!=null?E.year<0?h("detail.bce",{n:-E.year}):String(E.year):"",E.id===e.id?h("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:B.findIndex(E=>E.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Ze,{id:x.id,label:h("bookPage.viewAllInWork",{n:H.length}),onNavigate:o,renderLink:r,dense:!0})})]})]}),be=e.work_id?t.jsx(Rl,{caption:m.section.belongsToWork,children:t.jsx(Ze,{id:e.work_id,label:x?f(x.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(Pn,{railTop:c,back:p,up:be,nav:ie,railLinks:u,main:Z,card:pe,side:te})};function Xx({volumes:e,unit:n}){const{t:o}=J();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o("bookPage.volumeRange",{range:wi(e,n),unit:n}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o("bookPage.volumeCount",{n:e.length,unit:n})]})]})}function Zx({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:a}){var w;const{t:l,convert:d}=J(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],u=p.filter(b=>b.ref_type!=="book"),m=p.filter(b=>b.ref_type==="book"&&b.relation==="底本"),h=p.filter(b=>b.ref_type==="book"&&b.relation!=="底本"),f=(c==null?void 0:c.related_to)||[],x=p.length>0||f.length>0,k=b=>b&&qx.has(b)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${b}`)}):"",y=(b,j)=>t.jsx(Ze,{id:b,label:d(j||b),onNavigate:s,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[x&&t.jsxs("ol",{className:"bim-d-lf-list",children:[u.map((b,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:b.relation?d(b.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),b.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(b.evidence),k(b.confidence)]})]})},`a-${j}`)),m.map((b,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:d(o)})]}),h.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:h.map((b,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.confidence)]})]},j))})]}),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:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((b,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:b.evidence?d(b.evidence):void 0,children:[y(b.book_id,r(b.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(b.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((b,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(b.title)]}),t.jsx(Nt,{text:b.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Cn=16,Jx=200,Qx=16,Oc=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var Z,Ne,Oe,B,te,be,Ie;const{t:p,convert:u,messages:m}=J(),[h,f]=g.useState(""),[x,k]=g.useState(!1),[y,w]=g.useState(null),[b,j]=g.useState(""),[S,v]=g.useState(!1),$=g.useMemo(()=>Nl(e,n),[e,n]),[_,C]=g.useState(new Map),M=!!o&&$.rows.length>0&&$.rows.length<=Jx,T=M&&($.rows.length<=Cn||S),z=T&&$.rows.every(F=>!F.id||_.has(F.id)),H=F=>{var ue;return zo(F?(ue=_.get(F))==null?void 0:ue.l1:void 0)},N=g.useMemo(()=>{const F=h.trim(),ue=F?u(F):"";return $.rows.filter(Q=>{var Ce,Me;if(b&&zo(Q.id?(Ce=_.get(Q.id))==null?void 0:Ce.l1:void 0)!==b)return!1;if(!ue)return!0;const ye=Q.id&&((Me=_.get(Q.id))==null?void 0:Me.title)||Q.title;return u(ye).includes(ue)||(Q.subItems||[]).some(De=>u(De).includes(ue))})},[$.rows,h,b,_,u]),I=x?N:N.slice(0,Cn),L=g.useMemo(()=>(T?$.rows:I).filter(F=>F.id&&!_.has(F.id)).map(F=>F.id),[T,$.rows,I,_]);g.useEffect(()=>{if(!o||L.length===0)return;let F=!1;const ue=L.slice(0,Qx);return Promise.all(ue.map(Q=>o.getItem(Q).then(ye=>{var De,qe;const Ce=ye??{},Me={title:Ce.title,edition:Ce.edition,authors:Ce.authors,measure:ye?Et(ye,m.unit.juan):void 0,versionCount:Ce._edition_count??((De=Ce.books)==null?void 0:De.length),l1:((qe=Ce.classification)==null?void 0:qe.l1)||void 0};return[Q,Me]}).catch(()=>[Q,{}]))).then(Q=>{F||C(ye=>{const Ce=new Map(ye);for(const[Me,De]of Q)Ce.set(Me,De);return Ce})}),()=>{F=!0}},[o,L,m.unit.juan]);const R=(e.contained_in||[])[0];g.useEffect(()=>{if(!R){w(null);return}if(w({id:R}),!o)return;let F=!1;return o.getItem(R).then(ue=>{F||w({id:R,title:ue==null?void 0:ue.title})}).catch(()=>{}),()=>{F=!0}},[o,R]);const P=g.useMemo(()=>Ic(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),U=P.text.length+P.groups.reduce((F,ue)=>F+ue.rows.length+ue.mirrors.length,0),q=e.contained_works||[],D=new Set($.rows.map(F=>F.id).filter(Boolean)),O=q.length>0&&!q.every(F=>D.has(F.id)),A=(()=>{const F=$.rows.map(ue=>ue.edition).filter(Boolean);return F.length>1&&new Set(F).size===1})(),G=$.rows.some(F=>F.volumes.length>0||F.expected!=null),le=e._member_count||((Z=e.books)==null?void 0:Z.length)||q.length,ne=e._members_truncated?le:$.rows.length,ve=Et(e,m.unit.juan),oe=e.count,pe=F=>typeof F=="number"&&Number.isFinite(F)?F:null,We=pe(oe==null?void 0:oe.juan)??pe((Ne=e.juan_count)==null?void 0:Ne.number),ee=pe(oe==null?void 0:oe.ce)??($.totalVolumes||null),Be=[{value:ne,label:p("collectionPage.stat.titles")},{value:We??0,label:m.unit.juan},{value:ee??0,label:m.unit.volume}],Ee=g.useMemo(()=>{var Q,ye;const F=[];if((Q=e.publication_info)!=null&&Q.details&&F.push({label:p("collectionPage.fact.publication"),value:u(e.publication_info.details)}),le&&(le!==$.rows.length||e._members_truncated)){const Ce=e._member_type==="Book"?p("collectionPage.member.Book"):e._member_type==="Work"?p("collectionPage.member.Work"):p("collectionPage.member.other");F.push({label:Ce,value:`${le} ${m.unit.bu}`,title:p("collectionPage.memberNote")})}const ue=[pe(oe==null?void 0:oe.zhong)!=null?p("collectionPage.nZhong",{n:oe.zhong}):"",pe(oe==null?void 0:oe.han)!=null?p("collectionPage.nHan",{n:oe.han}):""].filter(Boolean);return ue.length&&F.push({label:p("collectionPage.fact.expected"),value:ue.join(" ")}),We==null&&ve&&F.push({label:p("collectionPage.fact.measure"),value:u(ve),title:(ye=e.juan_count)!=null&&ye.description?u(e.juan_count.description):void 0}),F},[e,le,$.rows.length,We,ve,oe,u,p,m]),X=g.useMemo(()=>{if(!z)return[];const F=new Map;for(const Q of $.rows){const ye=H(Q.id);ye&&F.set(ye,(F.get(ye)??0)+1)}const ue=Rn.filter(Q=>(F.get(Q.key)??0)>0);return ue.length<2?[]:[{key:"",label:`${m.catalog.all} ${ne}`},...ue.map(Q=>({key:Q.key,label:`${Q.label} ${F.get(Q.key)}`}))]},[z,$.rows,_,m]),ie=g.useMemo(()=>{if(!z||!$.rows.some(ye=>ye.volumes.length>0))return null;const F=[],ue=$.rows.filter(ye=>ye.volumes.length>0).map(ye=>({k:H(ye.id)??"",from:Math.min(...ye.volumes),to:Math.max(...ye.volumes)})).sort((ye,Ce)=>ye.from-Ce.from);for(const ye of ue){const Ce=ye.to-ye.from+1,Me=F[F.length-1];Me&&Me.key===ye.k?(Me.to=Math.max(Me.to,ye.to),Me.n+=Ce):F.push({key:ye.k,from:ye.from,to:ye.to,n:Ce})}const Q=ue.reduce((ye,Ce)=>Math.max(ye,Ce.to),0);return F.length>1&&F.some(ye=>ye.key)?{segs:F,last:Q}:null},[z,$.rows,_]),he=(Oe=e.description)==null?void 0:Oe.text,Te=t.jsx(Mn,{kind:p("collectionPage.kind"),title:u(e.title),byline:t.jsx(Sr,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(et,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(B=e.publication_info)!=null&&B.year?u(e.publication_info.year):""]}),description:he||(te=e.history)!=null&&te.length?t.jsxs(t.Fragment,{children:[he&&t.jsx(Nt,{text:he,style:{fontSize:15,lineHeight:1.85}}),(be=e.history)!=null&&be.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((F,ue)=>t.jsx("li",{children:u(F)},ue))}):null]}):void 0,clampDescription:er(he)||(((Ie=e.history)==null?void 0:Ie.length)??0)>2?6:void 0,stats:Be,facts:Ee,foot:t.jsx(Bn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ie&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:p("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":p("collectionPage.dist.head"),children:ie.segs.map((F,ue)=>{const Q=Rn.find(ye=>ye.key===F.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!Q,title:Q?p("collectionPage.dist.segTitle",{section:u(Q.label),from:F.from,to:F.to}):void 0,"aria-label":Q?p("collectionPage.dist.only",{section:u(Q.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!Q&&b===F.key,style:{flexGrow:F.n,background:i(Q?Q.token:"rule")},onClick:()=>{Q&&(j(b===F.key?"":F.key),k(!1))}},ue)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:p("catalog.volume",{n:1})}),t.jsx("span",{children:p("collectionPage.dist.hint")}),t.jsx("span",{children:p("catalog.volume",{n:ie.last})})]})]})}),K=[];$.rows.length&&K.push({id:"titles",label:p("collectionPage.sec.titles"),count:ne}),U&&K.push({id:"resources",label:p("collectionPage.sec.resources"),count:U}),O&&K.push({id:"works",label:m.section.containedWorks,count:q.length});const _e=t.jsxs(t.Fragment,{children:[$.rows.length>0&&t.jsxs(tt,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(et,{items:[`${ne} ${m.unit.items}`,$.totalVolumes?p("collectionPage.totalVolumes",{n:$.totalVolumes,unit:m.unit.volume}):"",N.length!==ne?p("collectionPage.currentN",{n:N.length,unit:m.unit.items}):""]}),action:a,children:[($.rows.length>Cn||X.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[X.length>0&&t.jsx(Si,{items:X,value:b,onChange:F=>{j(F),k(!1)}}),M&&$.rows.length>Cn&&!z&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>v(!0),title:p("collectionPage.loadAllTitle",{n:$.rows.length,unit:m.unit.items}),children:p(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),$.rows.length>Cn&&t.jsx("input",{type:"search",className:"bim-d-find",value:h,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:F=>{f(F.target.value),k(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&_i(N.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[G&&t.jsx("th",{style:{width:"8.5em"},children:p("collectionPage.col.volumes")}),t.jsx("th",{children:p("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:p("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:I.map((F,ue)=>{var me;const Q=F.id?_.get(F.id):void 0,ye=Q!=null&&Q.title&&F.title===F.id?Q.title:F.title,Ce=((Q==null?void 0:Q.authors)||[]).find(Ve=>Ve&&Ve.name),Me=[Ce?`${Ce.dynasty?`〔${u(Ce.dynasty)}〕`:""}${u(Ce.name)}${Ce.role?` ${u(Ce.role)}`:""}`:"",Q!=null&&Q.measure?u(Q.measure):"",(me=F.subItems)!=null&&me.length?F.subItems.map(Ve=>u(Ve)).join("、"):"",(Q!=null&&Q.edition||F.edition)&&!A?u((Q==null?void 0:Q.edition)||F.edition||""):""].filter(Boolean),De=Rn.find(Ve=>Ve.key===H(F.id)),qe=F.volumes.length>0?p("collectionPage.volumeRange",{range:wi(F.volumes,m.unit.volume),unit:m.unit.volume}):F.expected!=null?`${F.found??0}/${F.expected} ${m.unit.volume}`:"";return t.jsxs("tr",{children:[G&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${qe?"":" bim-d-zt-blank"}`,children:[De&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(De.token)}}),qe||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[F.id?t.jsx(Ze,{id:F.id,label:u(ye),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(ye)}),Me.length>0?t.jsx(et,{items:Me}):F.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?p("collectionPage.nZhong",{n:Q.versionCount}):""})]},`${F.id??F.title}-${ue}`)})})]}),I.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:p("catalog.noMatch")}),!x&&t.jsx(Jo,{total:N.length,shown:I.length,unit:m.unit.items,onClick:()=>k(!0)})]}),U>0&&t.jsxs(tt,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:U}),children:[P.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[P.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:p("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:P.text.map((F,ue)=>t.jsx(_r,{item:F,siblings:P.text},`${F.id||F.url||F.name}-${ue}`))})})]}),t.jsx(Lc,{groups:P.groups})]}),$.rows.length===0&&U===0&&t.jsx(tt,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),se=O?t.jsx(Gt,{id:"works",title:m.section.containedWorks,meta:p("collectionPage.nZhong",{n:q.length}),cap:12,items:q.map(F=>t.jsx(Ze,{id:F.id,label:u(F.title),onNavigate:r,renderLink:s,dense:!0}))}):null,$e=y?t.jsx(Rl,{caption:p("collectionPage.parent"),children:t.jsx(Ze,{id:y.id,label:u(y.title||y.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Pn,{railTop:l,back:d,up:$e,nav:K,railLinks:c,main:_e,card:Te,side:se})},eb=16,io=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function ba(e){if(!e)return io.length;const n=io.indexOf(e);return n===-1?io.length:n}function tb(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const nb={秦:[-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]},Hc=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:a,railLinks:l})=>{var se,$e,Z,Ne,Oe;const{t:d,convert:c,messages:p}=J(),u=B=>tb(B,d),[m,h]=g.useState("全部"),[f,x]=g.useState(!1),[k,y]=g.useState("default"),[w,b]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(B=>{const te=w.get(B.work_id);return{id:B.work_id,title:(te==null?void 0:te.title)??B.title??B.work_id,role:B.role||"",cls:Xo(B.role),versionCount:te==null?void 0:te.versionCount,section:te==null?void 0:te.cls,l1:te==null?void 0:te.l1,measure:te==null?void 0:te.measure,hasImage:te==null?void 0:te.hasImage,loaded:!!(te!=null&&te.loaded)}}),[e.works,w]),S=g.useMemo(()=>Tl((e.works||[]).map(B=>B.role),d("detail.roleAll")),[e.works,d]),v=g.useMemo(()=>{const B=m==="全部"?j:j.filter(te=>te.cls===m);return k==="versions"?[...B].sort((te,be)=>(be.versionCount??-1)-(te.versionCount??-1)):B},[j,m,k]),$=f?v:v.slice(0,eb),_=g.useMemo(()=>$.filter(B=>!w.has(B.id)).map(B=>B.id),[$,w]);g.useEffect(()=>{if(!n||_.length===0)return;let B=!1;return Promise.all(_.map(te=>n.getItem(te).then(be=>{var Q,ye,Ce,Me,De;const Ie=be??{},F=Ie._edition_count??(((Q=Ie.books)==null?void 0:Q.length)??0)+(((ye=Ie.collections)==null?void 0:ye.length)??0),ue=[(Ce=Ie.classification)==null?void 0:Ce.l1,(Me=Ie.classification)==null?void 0:Me.l2].filter(Boolean).join(" ");return[te,{id:te,title:Ie.title,versionCount:F,loaded:!0,cls:ue||void 0,l1:((De=Ie.classification)==null?void 0:De.l1)||void 0,measure:be&&Et(be,p.unit.juan)||void 0,hasImage:!!(Ie.has_image??Ie._has_image)}]}).catch(()=>[te,{id:te,loaded:!0}]))).then(te=>{B||b(be=>{const Ie=new Map(be);for(const[F,ue]of te)Ie.set(F,ue);return Ie})}),()=>{B=!0}},[n,_,p.unit.juan]);const C=g.useMemo(()=>{const B=new Map;for(const te of e.alt_names||[]){const be=te.type||p.section.aliases;B.has(be)||B.set(be,[]),B.get(be).push(te.name)}return[...B.entries()].sort((te,be)=>ba(te[0])-ba(be[0])).map(([te,be])=>({label:te,names:be}))},[e.alt_names,p]),M=e.birth_year??((se=e.dates)==null?void 0:se.birth)??void 0,T=e.death_year??(($e=e.dates)==null?void 0:$e.death)??void 0,z=(Z=e.dates)==null?void 0:Z.floruit,H=M!=null||T!=null?`${u(M)||"?"}—${u(T)||"?"}`:Array.isArray(z)&&z.length===2&&z.every(B=>Number.isFinite(B))?d("entityPage.floruit",{from:u(z[0]),to:u(z[1])}):"",N=new Set(["本名","字","號","号"]),I=C.filter(B=>N.has(B.label)),L=C.filter(B=>!N.has(B.label)),R=L.reduce((B,te)=>B+te.names.length,0),P=g.useMemo(()=>{const B=[];for(const be of I)B.push({label:be.label,value:be.names.map(Ie=>c(Ie)).join("、")});const te=(e.works||[]).length;return te&&B.push({label:d("entityPage.fact.works"),value:d("entityPage.nZhong",{n:te})}),B},[e.works,I,c,d]),U=B=>{var te;return(te=C.find(be=>B.includes(be.label)))==null?void 0:te.names[0]},q=U(["字"]),D=U(["號","号"]),O=[q?d("entityPage.zi",{name:c(q)}):"",D?d("entityPage.hao",{name:c(D)}):""].filter(Boolean).join(","),A=e.native_place,G=e.dynasty?nb[e.dynasty]:void 0,le=(()=>{if(!G||M==null||T==null||T<M)return null;const[B,te]=G,be=Math.max(M,B),Ie=Math.min(T,te);if(Ie<=be)return null;const F=te-B;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":d("entityPage.lifeAria",{birth:u(M),death:u(T),years:T-M+1}),children:t.jsx("i",{style:{left:`${(be-B)/F*100}%`,width:`${(Ie-be)/F*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${u(B)} ${c(e.dynasty)}`}),t.jsx("span",{children:d("entityPage.lifeYears",{years:T-M+1})}),t.jsx("span",{children:u(te)})]})]})})(),ne=g.useMemo(()=>{if(!n||j.length===0||j.some(be=>!be.loaded))return null;const B=new Map;for(const be of j){const Ie=zo(be.l1);Ie&&B.set(Ie,(B.get(Ie)??0)+1)}const te=Rn.map(be=>({...be,n:B.get(be.key)??0})).filter(be=>be.n>0);return te.length?te:null},[j,n]),ve=t.jsxs(Mn,{kind:p.entityPage.subtype[e.subtype]??d("entityPage.subtype.people"),title:c(e.primary_name||e.title),subtitle:O||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(et,{items:[e.dynasty?c(e.dynasty):"",H,A?d("entityPage.nativePlace",{place:c(A)}):""]}),le]}),description:(Ne=e.description)!=null&&Ne.text?t.jsx(Nt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:er((Oe=e.description)==null?void 0:Oe.text)?6:void 0,facts:P,foot:t.jsx(Bn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[R>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:d("entityPage.moreNames",{n:R})}),t.jsx("dl",{children:L.map(B=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:c(B.label)}),t.jsx("dd",{children:B.names.map(te=>c(te)).join("、")})]},B.label))})]}),ne&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:d("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ne.map(B=>t.jsx("i",{style:{flexGrow:B.n,background:i(B.token)}},B.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ne.map(B=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(B.token)}}),c(B.label)," ",B.n]},B.key))})]})]}),oe=g.useMemo(()=>j.filter(B=>B.loaded&&(B.versionCount??0)>0).sort((B,te)=>(te.versionCount??0)-(B.versionCount??0)).slice(0,3),[j]),pe=!!n&&j.length>=3&&$.some(B=>!B.loaded),We=m==="全部"&&(pe||oe.length>=2),ee=e.external_ids||{},Be=[];ee.cbdb_id!=null&&Be.push({label:"CBDB",id:String(ee.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ee.cbdb_id}`,note:ee.cbdb_match==="auto"?d("entityPage.autoMatch"):void 0});const Ee=ee.wikidata_id;Ee&&Be.push({label:"Wikidata",id:Ee,href:`https://www.wikidata.org/wiki/${Ee}`});const X=ee.viaf_id;X&&Be.push({label:"VIAF",id:X,href:`https://viaf.org/viaf/${X}`});const ie=S.map(B=>({key:B.cls,label:`${B.label} ${B.count}`})),he=[...We&&!pe?[{id:"featured",label:d("entityPage.sec.featured"),count:oe.length}]:[],...j.length?[{id:"works",label:d("entityPage.sec.allWorks"),count:j.length}]:[],...Be.length?[{id:"external",label:d("entityPage.sec.external"),count:Be.length}]:[]],Te=We?t.jsxs(tt,{id:"featured",title:d("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:d("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":pe||void 0,children:[pe&&[0,1,2].map(B=>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:" "})]},B)),!pe&&oe.map(B=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Ze,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(et,{items:[B.section?c(B.section):"",B.measure?c(B.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:B.versionCount}),t.jsx("span",{children:d("entityPage.versionsUnit")}),B.hasImage&&t.jsx("span",{className:"bim-d-flag",children:d("entityPage.hasImage")})]})]},B.id))]})]}):null,K=j.length===0?t.jsx(tt,{title:d("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("entityPage.empty")})}):t.jsxs(t.Fragment,{children:[Te,t.jsxs(tt,{id:"works",title:d("entityPage.sec.works"),meta:t.jsx(et,{items:[d("entityPage.total",{n:j.length}),v.length!==j.length?d("entityPage.current",{n:v.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ie.length>1&&t.jsx(Si,{items:ie,value:m,onChange:B=>{h(B),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":k==="versions",onClick:()=>{k==="default"&&x(!0),y(B=>B==="default"?"versions":"default")},children:d(k==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!f&&_i(v.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("entityPage.col.work")}),t.jsx("th",{children:d("entityPage.col.section")}),t.jsx("th",{children:d("entityPage.col.role")}),t.jsx("th",{children:d("entityPage.col.versions")}),t.jsx("th",{"aria-label":d("entityPage.col.image")})]})}),t.jsx("tbody",{children:$.map(B=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Ze,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0}),B.measure?t.jsx(et,{items:[c(B.measure)]}):!B.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${B.section||B.loaded?"":" bim-d-zt-blank"}`,children:B.section?c(B.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.role?"":" bim-d-zt-blank"}`,children:B.role?c(B.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.loaded?"":" bim-d-zt-blank"}`,children:B.loaded?B.versionCount?d("entityPage.nZhong",{n:B.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:d("entityPage.notRecorded")}):""}),t.jsx("td",{className:B.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:B.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:d("entityPage.hasImage")})})]},B.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d("entityPage.emptyRole")}),!f&&t.jsx(Jo,{total:v.length,shown:$.length,unit:d("entityPage.moreUnit"),onClick:()=>x(!0)})]})]}),_e=Be.length>0?t.jsx(Gt,{id:"external",title:d("entityPage.sec.external"),items:Be.map(B=>t.jsxs("a",{href:B.href,target:"_blank",rel:"noopener noreferrer",children:[B.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Be.map(B=>B.id),foot:ee.cbdb_id!=null&&ee.cbdb_match==="auto"?d("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Pn,{railTop:s,back:a,nav:he,railLinks:l,main:K,card:ve,side:_e})},Cr="(max-width: 719px)",ib=`${Cr}, (pointer: coarse)`,Fc=`
1295
+ `,dg=120;function pt(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function pg(e,n=dg){if(!e)return;const o=e.replace(/\s+/g," ").trim(),r=Array.from(o);return r.length>n?r.slice(0,n).join("")+"…":o}function ug(e){const n=typeof e.birth_year=="number"?e.birth_year:void 0,o=typeof e.death_year=="number"?e.death_year:void 0;if(!(n===void 0&&o===void 0))return`${n??"?"}–${o??"?"}`}function mg(e){if(!Array.isArray(e.authors))return;const n=e.authors.map(o=>{if(!o||typeof o!="object")return"";const r=o,s=pt(r.name);return s?[pt(r.dynasty)&&`〔${pt(r.dynasty)}〕`,s,pt(r.role)].filter(Boolean).join(""):""}).filter(Boolean);return n.length?n.slice(0,3).join("、"):void 0}function cc(e,n){const o=pt(n.type),r=pt(n.primary_name)??pt(n.title)??e,s=o==="entity"?[pt(n.dynasty),ug(n),pt(n.native_place)].filter(Boolean).join(" · "):[mg(n),pt(n.edition),pt(n.measure_info)].filter(Boolean).join(" · "),a=n.description&&typeof n.description=="object"?pt(n.description.text):pt(n.description);return{id:e,type:o,title:r,meta:s||void 0,description:pg(a)}}function dc(e){const n=[e.dynasty,e.author,e.edition].filter(Boolean).join(" · ");return{id:e.id,type:e.type,title:e.title,meta:n||void 0}}function pc(e){return async n=>{const o=await e.getItem(n);if(o)return cc(n,o);if(e.getEntry){const r=await e.getEntry(n);if(r)return dc(r)}return null}}const Bs=new WeakMap;function hg(e,n,o){let r=Bs.get(e);r||(r=new Map,Bs.set(e,r));const s=r.get(o);if(s)return s;const a=n(o);return r.set(o,a),a.catch(()=>r.delete(o)),a}const uc=e=>`/item/${encodeURIComponent(e)}`,gg={work:"書名",person:"人名",place:"地名",office:"官職",dynasty:"朝代",other:"專名"},fg=typeof window>"u"?g.useEffect:g.useLayoutEffect;function yr(e,n){return g.useMemo(()=>n?{owner:n,load:n}:e?{owner:e,load:pc(e)}:null,[n,e])}const xg=e=>e,bg=({text:e,entities:n,offsets:o="text",plainBase:r=0,transport:s,loadSummary:a,buildHref:l=uc,onNavigate:d,renderText:c=xg,hoverDelayMs:p=250,injectStyles:u=!0,className:m})=>{const h=g.useMemo(()=>{const x=o==="plain"?ac(e,n,r):n;return lc(e,x)},[e,n,o,r]),f=yr(s,a);return t.jsxs("span",{className:m?`bim-et-root ${m}`:"bim-et-root",children:[u&&t.jsx("style",{children:br}),h.map(x=>x.type==="text"?t.jsx(g.Fragment,{children:c(x.text)},`t${x.start}`):t.jsx(jr,{span:x.span,label:x.text,hasBrackets:e[x.start-1]==="《"&&e[x.start+x.text.length]==="》",loader:f,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:p},`${x.span.key}@${x.start}`))]})},jr=({span:e,label:n,hasBrackets:o,loader:r,buildHref:s,onNavigate:a,renderText:l,hoverDelayMs:d})=>{const c=g.useId(),[p,u]=g.useState(!1),m=g.useRef(null),h=`bim-et bim-et-${e.kind}`,f=e.kind==="work"&&!o,x=t.jsxs(t.Fragment,{children:[f&&t.jsx("span",{className:"bim-et-sr",children:"《"}),l(n),f&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),k=()=>{m.current&&(clearTimeout(m.current),m.current=null)};g.useEffect(()=>k,[]);const y=g.useCallback(j=>{k(),j<=0?u(!0):m.current=setTimeout(()=>u(!0),j)},[]),w=g.useCallback(()=>{k(),u(!1)},[]);if(!e.targetId)return t.jsx("span",{className:h,children:x});const b=e.targetId;return t.jsxs("span",{className:"bim-et-w",onMouseEnter:()=>y(d),onMouseLeave:w,onKeyDown:j=>{j.key==="Escape"&&p&&(j.stopPropagation(),w())},children:[t.jsx("a",{className:h,href:s(b),"data-entity-id":b,"aria-describedby":p?c:void 0,onFocus:()=>y(0),onBlur:w,onClick:a?j=>a(b,j):void 0,children:x}),p&&t.jsx(yg,{id:c,entityId:b,span:e,loader:r})]})},yg=({id:e,entityId:n,span:o,loader:r})=>{const{convert:s}=J(),a=g.useRef(null),[l,d]=g.useState("start"),[c,p]=g.useState(r?{status:"loading"}:{status:"ready",summary:null});g.useEffect(()=>{if(!r)return;let h=!1;return p({status:"loading"}),hg(r.owner,r.load,n).then(f=>{h||p({status:"ready",summary:f})}).catch(()=>{h||p({status:"error"})}),()=>{h=!0}},[r,n]),fg(()=>{const h=a.current;if(!h||typeof window>"u")return;const f=h.getBoundingClientRect(),x=document.documentElement.clientWidth||window.innerWidth;f.right>x-8&&l==="start"&&d("end")},[c,l]);const u=c.status==="ready"?c.summary:null,m=(u==null?void 0:u.title)??o.canonicalName??o.text;return t.jsxs("span",{ref:a,id:e,role:"tooltip",className:"bim-et-card","data-align":l,children:[t.jsx("span",{className:"bim-et-card-k",children:s(gg[o.kind])}),m&&t.jsx("span",{className:"bim-et-card-t",children:s(m)}),(u==null?void 0:u.meta)&&t.jsx("span",{className:"bim-et-card-m",children:s(u.meta)}),(u==null?void 0:u.description)&&t.jsx("span",{className:"bim-et-card-d",children:s(u.description)}),c.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:s("載入中…")}),c.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:s("摘要載入失敗")})]})},jg=e=>`/item/${encodeURIComponent(e)}`;function vg(e){const n=e.filter(o=>o.kind!=="break");return{before:n.filter(o=>o.pos==="before"),after:n.filter(o=>o.pos!=="before")}}function kg(e,n){const o=[];for(const r of e){const s=n.get(r.charData.id)??null,a=o[o.length-1];a&&a.entity===s?a.chars.push(r):o.push({entity:s,chars:[r]})}return o}const vr=({pageData:e,pages:n,punctuations:o=Sg,selectedCharIds:r,hoveredCharId:s,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:p=!0,onVisiblePageChange:u,convert:m,scrollToPage:h,entities:f,entityTransport:x,loadEntitySummary:k,buildEntityHref:y,onEntityNavigate:w})=>{const b=g.useRef(null),j=g.useRef(0),S=g.useMemo(()=>{const I=new Map;return p&&o.forEach((P,V)=>{const X=P.id?P:{...P,id:`${P.anchor}#${V}`},D=I.get(X.anchor)||[];D.push(X),I.set(X.anchor,D)}),I},[o,p]),v=g.useMemo(()=>(n&&n.length>0?n:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}]).filter(P=>P.columns.some(V=>V.chars.length>0)).map(P=>{const V=[...P.columns].sort((O,A)=>O.col-A.col),X=[];let D=[];for(const O of V)for(const A of O.chars){const{before:G,after:se}=vg(S.get(A.id)||[]),Q=(S.get(A.id)||[]).some(ve=>ve.kind==="break");D.push({charData:A,col:O.col,beforePuncts:G,afterPuncts:se}),Q&&(X.push({id:`para-p${P.page}-${X.length}`,chars:D}),D=[])}return D.length>0&&X.push({id:`para-p${P.page}-${X.length}`,chars:D}),{page:P.page,paragraphs:X}}),[n,e,S]),$=g.useMemo(()=>{const I=[];for(const P of v)for(const V of P.paragraphs)for(const X of V.chars)I.push(X.charData.id);return I},[v]),_=g.useMemo(()=>{const I=new Map;if(!f||f.length===0)return I;const P=new Map($.map((V,X)=>[V,X]));for(const V of f){if(!V.anchor)continue;const X=P.get(V.anchor.start),D=P.get(V.anchor.end);if(!(X===void 0||D===void 0||D<X))for(let O=X;O<=D;O++)I.has($[O])||I.set($[O],V)}return I},[f,$]),C=yr(x,k),M=_.size>0,N=g.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:u,onEntityNavigate:w});N.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:u,onEntityNavigate:w};const T=g.useMemo(()=>({click:I=>{var P,V;j.current=Date.now()+1200,(V=(P=N.current).onCharClick)==null||V.call(P,I)},enter:I=>{var P,V;return(V=(P=N.current).onCharHover)==null?void 0:V.call(P,I)},leave:()=>{var I,P;return(P=(I=N.current).onCharHover)==null?void 0:P.call(I,null)},navigate:(I,P)=>{var X,D;if(!(P.detail===0||P.ctrlKey||P.metaKey||P.shiftKey)){P.preventDefault();return}(D=(X=N.current).onEntityNavigate)==null||D.call(X,I,P)}}),[]),F=_g(r),R=g.useRef(null);g.useEffect(()=>{var P,V;if((P=R.current)==null||P.classList.remove("is-hovered"),R.current=null,!s)return;const I=(V=b.current)==null?void 0:V.querySelector(`span[data-char-id="${s}"]`);I&&(I.classList.add("is-hovered"),R.current=I)},[s]),g.useEffect(()=>{let I=null;const P=()=>{var ke,Pe;I=null;const X=window.getSelection(),D=b.current;if(!X||X.isCollapsed||X.rangeCount===0||!D)return;const O=X.getRangeAt(0),A=O.commonAncestorContainer,G=A.nodeType===3?A.parentElement:A;if(!G||!D.contains(G))return;const se=D.querySelectorAll("span[data-char-id]");let Q=0,ve=se.length;for(;Q<ve;){const Ee=Q+ve>>1;O.comparePoint(se[Ee],0)<0?Q=Ee+1:ve=Ee}const ne=Q;for(ve=se.length;Q<ve;){const Ee=Q+ve>>1;O.comparePoint(se[Ee],0)<=0?Q=Ee+1:ve=Ee}const ce=Q-1;if(ce<ne)return;const We=[];for(let Ee=ne;Ee<=ce;Ee++)We.push(se[Ee].getAttribute("data-char-id"));We.length>0&&(j.current=Date.now()+1200,(Pe=(ke=N.current).onSelectionChange)==null||Pe.call(ke,We))},V=()=>{I&&clearTimeout(I),I=setTimeout(P,120)};return document.addEventListener("selectionchange",V),()=>{document.removeEventListener("selectionchange",V),I&&clearTimeout(I)}},[]),g.useEffect(()=>{var I;if(r.size===1){const P=Array.from(r)[0],V=(I=b.current)==null?void 0:I.querySelector(`span[data-char-id="${P}"]`);V&&V.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}},[r]);const E=h==null?void 0:h.nonce;g.useEffect(()=>{var P;if(!h)return;const I=(P=b.current)==null?void 0:P.querySelector(`[data-page-section="${h.page}"]`);I&&(j.current=Date.now()+800,I.scrollIntoView({behavior:"auto",block:"start"}))},[E]);const L=!!u;return g.useEffect(()=>{var O;if(!L)return;const I=Array.from(((O=b.current)==null?void 0:O.querySelectorAll("[data-page-section]"))??[]);if(I.length===0)return;const P=120;let V=0;const X=()=>{var Q,ve;if(V=0,Date.now()<j.current)return;let A=0,G=I.length-1;for(;A<G;){const ne=A+G+1>>1;I[ne].getBoundingClientRect().top<=P?A=ne:G=ne-1}const se=parseInt(I[A].getAttribute("data-page-section")||"",10);isNaN(se)||(ve=(Q=N.current).onVisiblePageChange)==null||ve.call(Q,se)},D=()=>{V||(V=requestAnimationFrame(X))};return window.addEventListener("scroll",D,{passive:!0}),X(),()=>{window.removeEventListener("scroll",D),V&&cancelAnimationFrame(V)}},[L,v]),t.jsxs("div",{ref:b,className:"guji-text-pane-content",children:[M&&t.jsx("style",{children:br}),t.jsx("div",{className:"guji-text-reflow-view",children:v.map((I,P)=>t.jsx(Cg,{pGroup:I,first:P===0,selected:F.get(I.page)??wg,entityOfChar:_,entityLoader:C,convert:m,buildHref:y??jg,handlers:T},`page-sec-${I.page}`))})]})},wg=new Set,Sg=[];function _g(e){const n=g.useRef(new Map);return g.useMemo(()=>{const o=new Map;e.forEach(s=>{const a=parseInt(s.split(":")[0],10);let l=o.get(a);l||o.set(a,l=new Set),l.add(s)});const r=new Map;return o.forEach((s,a)=>{const l=n.current.get(a),d=l&&l.size===s.size&&Array.from(s).every(c=>l.has(c));r.set(a,d?l:s)}),n.current=r,r},[e])}function $g(e,n){const o=Array.from(n(e.join("")));return o.length===e.length&&e.every(r=>Array.from(r).length===1)?o:e.map(r=>n(r))}const Cg=g.memo(function({pGroup:n,first:o,selected:r,entityOfChar:s,entityLoader:a,convert:l,buildHref:d,handlers:c}){const p=g.useMemo(()=>{const m=new Map;if(!l)return m;for(const h of n.paragraphs){const f=$g(h.chars.map(x=>x.charData.char),l);h.chars.forEach((x,k)=>m.set(x.charData.id,f[k]))}return m},[n,l]),u=m=>p.get(m.id)??m.char;return t.jsxs("section",{"data-page-section":n.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96},children:[!o&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:i("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:i("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},children:["第 ",n.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:i("rule")}})]}),n.paragraphs.map(m=>t.jsx("p",{className:"guji-reflow-paragraph",children:kg(m.chars,s).map((h,f)=>{const x=h.chars.map(({charData:w,col:b,beforePuncts:j,afterPuncts:S},v)=>{const $=!!h.entity&&v===0,_=!!h.entity&&v===h.chars.length-1,C=$?[]:j,M=_?[]:S;return t.jsxs(g.Fragment,{children:[C.map(N=>t.jsx("span",{className:"guji-text-punct","data-punct-id":N.id,children:N.mark},N.id)),t.jsx("span",{"data-char-id":w.id,onClick:()=>c.click(w.id),onMouseEnter:()=>c.enter(w.id),onMouseLeave:c.leave,className:`guji-text-char${r.has(w.id)?" is-selected":""}${w.sub?" is-sub":""}`,title:`[第${n.page}葉·第${b}列·第${w.slot||w.pos}字] ${u(w)}`,children:u(w)}),M.map(N=>t.jsx("span",{className:"guji-text-punct","data-punct-id":N.id,children:N.mark},N.id))]},w.id)});if(!h.entity)return t.jsx(g.Fragment,{children:x},`r${f}`);const k=h.chars[0].beforePuncts.map(w=>t.jsx("span",{className:"guji-text-punct","data-punct-id":w.id,children:w.mark},w.id)),y=h.chars[h.chars.length-1].afterPuncts.map(w=>t.jsx("span",{className:"guji-text-punct","data-punct-id":w.id,children:w.mark},w.id));return t.jsxs(g.Fragment,{children:[k,t.jsx(jr,{span:h.entity,label:h.chars.map(w=>u(w.charData)).join(""),hasBrackets:!0,loader:a,buildHref:d,onNavigate:c.navigate,renderText:()=>x,hoverDelayMs:250}),y]},`${h.entity.key}@${f}`)})},m.id))]})}),mc=1,hc=6,ei={s:1,x:0,y:0},ri=(e,n,o)=>Math.min(o,Math.max(n,e));function kr(e,n,o){const r=ri(e.s,mc,hc);return{s:r,x:ri(e.x,n*(1-r),0),y:ri(e.y,o*(1-r),0)}}function Qi(e,n,o,r,s,a){const l=ri(e.s*r,mc,hc),d=l/e.s;return kr({s:l,x:n-(n-e.x)*d,y:o-(o-e.y)*d},s,a)}function zg(e,n,o,r,s){return kr({s:e.s,x:e.x+n,y:e.y+o},r,s)}function Tg(e,n,o){const r=n===1?e*16:n===2?e*400:e;return Math.exp(-r*(o?.01:.0015))}const Ws=4,Ng=g.forwardRef(function({children:n,onScaleChange:o,resetKey:r,style:s},a){const l=g.useRef(null),[d,c]=g.useState(ei),p=g.useRef(d),u=g.useRef(o);u.current=o;const m=b=>{var S;const j=p.current;p.current=b,c(b),b.s!==j.s&&((S=u.current)==null||S.call(u,b.s))},h=()=>{var j;const b=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(b==null?void 0:b.width)??0,h:(b==null?void 0:b.height)??0,left:(b==null?void 0:b.left)??0,top:(b==null?void 0:b.top)??0}};g.useImperativeHandle(a,()=>({zoomBy(b){const{w:j,h:S}=h();m(Qi(p.current,j/2,S/2,b,j,S))},reset(){m(ei)}})),g.useEffect(()=>{m(ei)},[r]),g.useEffect(()=>{const b=l.current;if(!b||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:S,h:v}=h(),$=kr(p.current,S,v);($.x!==p.current.x||$.y!==p.current.y)&&m($)});return j.observe(b),()=>j.disconnect()},[]),g.useEffect(()=>{const b=l.current;if(!b)return;const j=S=>{const v=Tg(S.deltaY,S.deltaMode,S.ctrlKey);if(p.current.s<=1&&v<1)return;S.preventDefault();const{w:$,h:_,left:C,top:M}=h();m(Qi(p.current,S.clientX-C,S.clientY-M,v,$,_))};return b.addEventListener("wheel",j,{passive:!1}),()=>b.removeEventListener("wheel",j)},[]);const f=g.useRef(new Map),x=g.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),k=b=>{if(b.pointerType==="mouse"&&b.button!==0)return;f.current.set(b.pointerId,{x:b.clientX,y:b.clientY});const j=x.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[S,v]=[...f.current.values()];j.pinchDist=Math.hypot(S.x-v.x,S.y-v.y),j.moved=Ws+1}},y=b=>{var F;const j=f.current.get(b.pointerId);if(!j)return;const S={x:b.clientX,y:b.clientY};f.current.set(b.pointerId,S);const v=x.current,{w:$,h:_,left:C,top:M}=h();if(f.current.size>=2){const[R,E]=[...f.current.values()],L=Math.hypot(R.x-E.x,R.y-E.y);if(v.pinchDist>0&&L>0){const I=(R.x+E.x)/2-C,P=(R.y+E.y)/2-M;m(Qi(p.current,I,P,L/v.pinchDist,$,_))}v.pinchDist=L,v.swallowClick=!0;return}const N=S.x-j.x,T=S.y-j.y;if(v.moved+=Math.abs(N)+Math.abs(T),!(v.moved<=Ws)){if(!v.dragging){v.dragging=!0;try{(F=l.current)==null||F.setPointerCapture(b.pointerId)}catch{}}v.swallowClick=!0,p.current.s>1&&m(zg(p.current,N,T,$,_))}},w=b=>{f.current.delete(b.pointerId);const j=x.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:k,onPointerMove:y,onPointerUp:w,onPointerCancel:w,onClickCapture:b=>{x.current.swallowClick&&(x.current.swallowClick=!1,b.stopPropagation(),b.preventDefault())},onDoubleClick:()=>m(ei),style:{position:"relative",overflow:"hidden",touchAction:"none",cursor:d.s>1?"grab":void 0,...s},children:t.jsx("div",{className:"bim-zp-inner",style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",transformOrigin:"0 0",transform:`translate(${d.x}px, ${d.y}px) scale(${d.s})`,willChange:d.s>1?"transform":void 0},children:n})})});function gc(e,n,o,r,s){const[a,l]=g.useState(n??null),[d,c]=g.useState(!1),p=g.useRef(0);return g.useEffect(()=>{if(n!==void 0){l(n);return}const u=++p.current;if(!o){l(null),c(!1);return}if(e){let m;try{m=e(o,s)}catch{l(null),c(!1);return}if(!m||typeof m.then!="function"){l(m??null),c(!1);return}c(!0),m.then(h=>{u===p.current&&l(h??null)}).catch(()=>{u===p.current&&l(null)}).finally(()=>{u===p.current&&c(!1)});return}if(r!=null&&r.warp_data){if(typeof r.warp_data=="object"){l(r.warp_data);return}if(typeof r.warp_data=="string"){c(!0),fetch(r.warp_data).then(m=>m.ok?m.json():null).then(m=>{u===p.current&&l(m)}).catch(()=>{u===p.current&&l(null)}).finally(()=>{u===p.current&&c(!1)});return}}l(null),c(!1)},[e,n,o,r,s]),{warpData:a,loading:d}}function Rg(e,n,o){const[r,s]=g.useState([]),a=g.useRef(0);return g.useEffect(()=>{const l=++a.current;if(!e||!n){s([]);return}let d;try{d=e(n,o)}catch{s([]);return}Promise.resolve(d).then(c=>{l===a.current&&s(c?sc(c):[])}).catch(()=>{l===a.current&&s([])})},[e,n,o]),r}const Os={padding:24,color:i("desc-fg"),fontSize:14};function Hs({title:e,label:n,className:o,style:r}){const s=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:i("rule")});return t.jsxs("div",{className:o,style:{...r,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:i("ink"),fontFamily:i("font-ui")},children:e}),t.jsx("div",{style:s("42%",24,28)}),t.jsx("div",{style:s("30%",12,10)}),["96%","100%","92%","98%","64%"].map((a,l)=>t.jsx("div",{style:s(a,16,l===0?30:14)},l)),t.jsx("p",{role:"status",style:{marginTop:24,color:i("desc-fg"),fontSize:14,fontFamily:i("font-ui")},children:n})]})}const Fs=/^https?:\/\//i;function Eg(e){if(!e||typeof e!="object")return null;const n=a=>typeof a=="string"&&a.trim()?a.trim():void 0,o=n(e.url),r=n(e.license_url),s={name:n(e.name),url:o&&Fs.test(o)?o:void 0,license:n(e.license),license_url:r&&Fs.test(r)?r:void 0,note:n(e.note)};return s.name||s.license||s.note?s:null}function Ig(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 Lg(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 fc(e,n,o,r=!1){const s=o(`${n}${e.n}`);if(!e.title)return s;const a=o(e.title);return r&&!/^[卷冊册章篇回第]/.test(e.title)?`${s} ${a}`:a}function Ag(e,n,o,r,s){var p;const a=new Map(e.chapters.map(u=>[u.file,u])),l=u=>u==="loading"?"…":typeof u=="number"&&u>0?u:void 0,d=(u,m)=>{const h=a.get(u);return{key:u,label:m??(h?fc(h,o,r,s):u),hint:l(n[u]),disabled:n[u]===0}},c=(p=e.juan_groups)==null?void 0:p.filter(u=>{var m;return u.files.some(h=>a.has(h))||((m=u.children)==null?void 0:m.length)});if(c&&c.length>0){const u=(m,h)=>{var x;if(m.files.length===1&&!((x=m.children)!=null&&x.length))return d(m.files[0],r(m.label));const f=Hh(m,n);return{key:`group:${h}`,label:r(m.label),hint:f==="loading"?"…":typeof f=="number"&&f>0?`${f}`:oc(m),defaultExpanded:typeof f=="number"&&f>0,children:[...m.files.filter(k=>a.has(k)).map(k=>d(k)),...(m.children??[]).map((k,y)=>u(k,`${h}.${y}`))]}};return c.map((m,h)=>u(m,`${h}`))}return e.chapters.map(u=>d(u.file))}const wr=({id:e,transport:n,versionKey:o,chapter:r,onLocationChange:s,onNavigate:a,title:l,subtitle:d,resolveImages:c,renderImageOverlay:p,imagePanel:u,allowVertical:m,onReportError:h,revisedAt:f,backHref:x,backLabel:k,resolveWarpData:y,warpData:w,resolveEntities:b,onEntityNavigate:j,className:S,style:v})=>{var Dr,Ur,Vr;const{t:$,convert:_}=J(),C=g.useMemo(()=>ul(n),[n]),[M,N]=vl(),T=Ze(),F=g.useRef(s);F.current=s;const[R,E]=g.useState(null),[L,I]=g.useState("loading");g.useEffect(()=>{let W=!1;return E(null),I("loading"),C.getManifest(e).then(pe=>{W||(pe?(E(pe),I("ready")):I("missing"))}).catch(()=>{W||I("missing")}),()=>{W=!0}},[C,e]);const P=o!==void 0,V=r!==void 0,[X,D]=g.useState(null),[O,A]=g.useState(null);g.useEffect(()=>{D(null),A(null)},[e]);const G=_e.pickTextVersion(R,P?o:X),se=((Dr=R==null?void 0:R.versions.find(W=>W.key==="default"))==null?void 0:Dr.key)??((Ur=R==null?void 0:R.versions[0])==null?void 0:Ur.key)??"default",Q=(G==null?void 0:G.key)??null,ve=V?r:O,ne=g.useCallback((W,pe,Le)=>{var Fe;(Fe=F.current)==null||Fe.call(F,{key:W,chapter:pe,isDefault:W===se},Le)},[se]);g.useEffect(()=>{!R||!P||o==null||R.versions.some(W=>W.key===o)||ne(se,null,"auto")},[R,P,o,se,ne]);const ce=g.useRef(new Map);g.useEffect(()=>{ce.current.clear()},[C,e]);const We=g.useCallback(async W=>{const pe=`${e}
1296
+ ${W}`;if(ce.current.has(pe))return ce.current.get(pe)??null;const Le=await C.getIndex(e,W).catch(()=>null);return Le&&ce.current.set(pe,Le),Le},[C,e]),[ke,Pe]=g.useState(null),[Ee,Z]=g.useState("loading"),le=Q?`${e}
1297
+ ${Q}`:null,oe=ke&&ke.owner===le?ke.idx:null;g.useEffect(()=>{if(!Q)return;let W=!1;const pe=`${e}
1298
+ ${Q}`;return Pe(null),Z("loading"),We(Q).then(Le=>{W||(Le&&Le.chapters.length>0?(Pe({owner:pe,idx:Le}),Z("ready")):Z("failed"))}),()=>{W=!0}},[e,Q,We]),g.useEffect(()=>{if(!oe||!Q||ve!=null&&oe.chapters.some(Le=>Le.file===ve))return;const pe=oe.chapters[0].file;V||A(pe),ne(Q,pe,"auto")},[oe,Q,ve,V,ne]);const he=oe?ve!=null&&oe.chapters.some(W=>W.file===ve)?ve:oe.chapters[0].file:ve,U=g.useMemo(()=>oe&&he?oe.chapters.find(W=>W.file===he)??null:null,[oe,he]),$e=g.useRef(0),me=g.useCallback(async W=>{if(!R||W===Q||!R.versions.some(ot=>ot.key===W))return;const pe=++$e.current,Le=await We(W);if(pe!==$e.current)return;const Fe=U??(he?{file:he}:null),qe=_e.matchChapterAcrossVersions(Fe,Le);P||D(W),V||A(qe),ne(W,qe,"version")},[R,Q,We,U,he,P,V,ne]),Ce=g.useCallback(W=>{Q&&(V||A(W),ne(Q,W,"chapter"))},[Q,V,ne]),[Y,ze]=g.useState(null),Me=Q&&U?`${e}
1299
+ ${Q}
1300
+ ${U.file}`:null,[B,te]=g.useState(null),xe=Me!==null&&B!==Me,Re=g.useRef(0);g.useEffect(()=>{if(!Q||!U)return;const W=++Re.current,pe=`${e}
1301
+ ${Q}
1302
+ ${U.file}`;ze(null),C.getChapter(e,Q,U.file,{json:!!U.has_json}).then(Le=>{W===Re.current&&ze(Le)}).catch(()=>{W===Re.current&&ze(null)}).finally(()=>{W===Re.current&&te(pe)})},[C,e,Q,U]);const H=(G==null?void 0:G.kind)==="collated",[de,ee]=g.useState("");g.useEffect(()=>{ee("")},[e,Q]);const ye=g.useMemo(()=>Q&&H?async W=>{const pe=await C.getChapter(e,Q,W,{json:!0});return{juan:(pe==null?void 0:pe.json)??null,rawText:(pe==null?void 0:pe.md)??null}}:null,[C,e,Q,H]),Se=(oe==null?void 0:oe.type)==="kaozhen",Be=g.useMemo(()=>(oe==null?void 0:oe.chapters.map(W=>W.file))??[],[oe]),{matchStates:De}=eg({resetKey:`${e}
1303
+ ${Q??""}`,load:ye,files:Be,activeFile:he??null,activeJuan:(Y==null?void 0:Y.json)??null,activeRawText:(Y==null?void 0:Y.md)??null,query:de,isKaozhen:Se}),Je=g.useRef(new Map);g.useEffect(()=>{Je.current.clear()},[e]);const He=g.useMemo(()=>({versionKey:Q,chapter:U??null}),[Q,U]),Ue=zh(c,he??null,He),{warpData:z,loading:ie}=gc(y,w,he??null,U,He),ae=Rg(b,he??null,He),[be,je]=g.useState(new Set),[ge,Ie]=g.useState(null),[K,fe]=g.useState(!0),[Ne,q]=g.useState(!0),ue=g.useRef(null),[re,we]=g.useState(1),[Ve,Oe]=g.useState(null),lt=W=>{var Le;const pe=parseInt(((Le=W==null?void 0:W.page_id)==null?void 0:Le.split(":")[1])??"",10);return isNaN(pe)?null:pe},Rt=W=>{var Le,Fe;const pe=(W==null?void 0:W.pages)??[];return lt(W)??((Le=pe.find(qe=>qe.columns.some(ot=>ot.chars.length>0)))==null?void 0:Le.page)??((Fe=pe[0])==null?void 0:Fe.page)??1},[Ge,Et]=g.useState(()=>Rt(z)),Ot=`${e}
1304
+ ${Q}
1305
+ ${he??""}`,[Qt,xn]=g.useState({key:Ot,data:z,started:!!z});if(Qt.key!==Ot)xn({key:Ot,data:z,started:!1});else if(z!==Qt.data&&(xn({key:Ot,data:z,started:!!z}),z)){const W=z.pages??[];(!Qt.started||!W.some(pe=>pe.page===Ge))&&Et(Rt(z))}g.useEffect(()=>{je(new Set),Ie(null)},[he,Q]);const Un=g.useCallback(W=>{if(je(new Set(W)),W.length>0){const pe=W[0],Le=parseInt(pe.split(":")[0],10);isNaN(Le)||Et(Le)}},[]),It=g.useMemo(()=>{const W=new Map;for(const pe of(z==null?void 0:z.pages)??[])W.set(pe.page,pe);return W},[z]),bn=lt(z),Vn=g.useCallback(W=>{var Fe;const pe=Ue.images;if(!pe||pe.length===0)return;const Le=(Fe=It.get(W))==null?void 0:Fe.seq;return(Le?pe.find(qe=>qe.seq===Le):void 0)??pe.find(qe=>qe.pageNo===W)??pe[W-1]},[Ue.images,It]),Br=re>1.5,Gn=g.useCallback((W,pe=!1)=>{const Le=Vn(W);return Le?W===bn||pe?Le.hiresUrl??Le.url:Le.url:W===bn?(z==null?void 0:z.imageUrl)??"":""},[Vn,z,bn]),Wd=g.useMemo(()=>Gn(Ge,Br),[Gn,Ge,Br]),yn=g.useMemo(()=>[...It.keys()].sort((W,pe)=>W-pe),[It]),Pi=g.useRef(Ge);Pi.current=Ge;const jn=g.useCallback(W=>{var qe;const pe=Pi.current,Le=yn.indexOf(pe),Fe=yn[Le<0?0:Le+W];Fe===void 0||Fe===pe||(Pi.current=Fe,Et(Fe),(qe=It.get(Fe))!=null&&qe.columns.some(ot=>ot.chars.length>0)&&Oe(ot=>({page:Fe,nonce:((ot==null?void 0:ot.nonce)??0)+1})))},[yn,It]),Mi=yn.indexOf(Ge),Od=g.useCallback(W=>{if(W.altKey||W.ctrlKey||W.metaKey)return;const pe=W.target.tagName;pe==="INPUT"||pe==="TEXTAREA"||pe==="SELECT"||(W.key==="ArrowLeft"||W.key==="PageUp"?(W.preventDefault(),jn(-1)):(W.key==="ArrowRight"||W.key==="PageDown")&&(W.preventDefault(),jn(1)))},[jn]);g.useEffect(()=>{if(z)for(const W of[1,-1,2,3]){const pe=Gn(Ge+W);pe&&So(pe)}},[z,Ge,Gn]);const Wr=g.useMemo(()=>{var qr;if(!z)return null;if(Ge===bn)return z;const W=It.get(Ge);if(W&&W.width>0&&W.height>0)return{page_id:`p:${Ge}`,title:`第${Ge}葉`,image_size:[W.width,W.height],total_warped_w:W.width,columns:[{col:1,warped_w:W.width,warped_h:W.height,offset_x:0,strips:[],chars:W.columns.flatMap(Ke=>Ke.chars).map(Ke=>({id:Ke.id,char:Ke.char,slot:Ke.slot,pos:Ke.pos,sub:Ke.sub,bbox_col:Ke.bbox??[0,0,0,0]}))}]};const pe=(qr=z.pages)==null?void 0:qr.find(Ke=>Ke.page===Ge),[Le,Fe]=z.image_size||[2386,3082],qe=Vn(Ge),ot=(qe==null?void 0:qe.width)??Le,Fi=(qe==null?void 0:qe.height)??Fe,Gr=ot/Le,Yr=Fi/Fe,Kr=new Map;for(const Ke of z.columns){const dt=(Ke.strips||[]).flatMap(qn=>qn.srcQuad.map(Xn=>Xn[0]));if(dt.length===0)continue;const St=Ke.top_y??0,Di=Ke.bottom_y??St+Ke.warped_h;Kr.set(Ke.col,{x0:Math.min(...dt),x1:Math.max(...dt),top:St,slotH:(Di-St)/21})}return{page_id:`p:${Ge}`,title:`第${Ge}葉`,image_size:[ot,Fi],total_warped_w:ot,columns:pe?pe.columns.map(Ke=>{const dt=Kr.get(Ke.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Ke.col,warped_w:ot,warped_h:Fi,offset_x:0,strips:[],chars:Ke.chars.map(St=>{const Di=St.slot??St.pos??0,qn=(dt.top+(Di-1)*dt.slotH)*Yr,Xn=(dt.x0+dt.x1)/2,[Kd,qd]=St.sub==="a"?[Xn,dt.x1]:St.sub==="b"?[dt.x0,Xn]:[dt.x0,dt.x1];return{...St,bbox_col:[Kd*Gr,qn,qd*Gr,qn+dt.slotH*Yr]}})}}):[]}},[z,Ge,bn,It,Vn]),{entryTitle:Yn,authors:Or}=Bg(e,n,l===void 0),[Hr,Bi]=g.useState("text");if(g.useEffect(()=>{Bi("text")},[he,Q]),L==="loading")return t.jsx(Hs,{className:S,style:v,title:l??Yn,label:$("reader.loading")});if(L==="missing"||!R||!G)return t.jsx("div",{className:S,style:{...v,...Os},children:$("reader.noText")});if(Ee==="failed")return t.jsx("div",{className:S,style:{...v,...Os},children:$("reader.tocFailed")});if(!oe)return t.jsx(Hs,{className:S,style:v,title:l??Yn,label:$("reader.tocLoading")});const Ht=Lg(G,oe),Hd=Ag(oe,De,Ht,_,H),Wi=R.versions.map(W=>({key:W.key,label:_e.textVersionLabel(W),optionLabel:_(_e.textVersionLabel(W)),sourceName:W.source_name?_(W.source_name):void 0,license:W.license??void 0,sourceUrl:W.source_url??void 0,primary:W.key===se})),ct=Eg((Vr=oe.source)==null?void 0:Vr.upstream),Kn=(typeof l=="string"?_(l):l)??(oe.title?_(oe.title):Yn?_(Yn):void 0),Fd=Kn?t.jsx("a",{href:T(e),title:$("reader.viewEntry"),onClick:a?W=>{W.metaKey||W.ctrlKey||(W.preventDefault(),a(e))}:void 0,children:Kn}):void 0,Dd=Or.length>0?_(Or.slice(0,2).map(W=>`${W.dynasty?`〔${W.dynasty}〕`:""}${W.name}${` ${W.role||$("reader.defaultRole")}`}`).join("、")):void 0,Oi=U?fc(U,Ht,_,H):void 0,en=H&&!!(Y!=null&&Y.json),Ft=(Y==null?void 0:Y.json)??null,tn=(Y==null?void 0:Y.md)??null,Fr=en&&!Se&&rc(Ft.sections),Ud=Fr&&!(tn&&M.readingMode==="paragraph"&&pi(tn)),Vd=en&&Fr?t.jsx(tg,{juan:Ft,view:Hr,onView:Bi,textHasEntries:Ud}):void 0,Gd=cl(oe)||uo(oe),Hi=tn?tn.replace(/^##\s+[^\n]+\n+/,""):null,Yd=(typeof d=="string"?_(d):d)??(G.source_name?_(G.source_name):_(_e.textVersionLabel(G)));return t.jsxs(Sl,{className:S,style:v,title:Fd,subtitle:Yd,byline:Dd,current:Oi,pagerUnit:Ht,rail:Vd,revisedAt:f,backHref:x,backLabel:k,onReportError:h?W=>h({...W,bookTitle:typeof Kn=="string"?Kn:void 0,entryId:e}):void 0,workLinkToggle:en&&!Se&&!!a&&!!(Ft!=null&&Ft.sections.some(W=>W.work_id)),toc:Hd,tocCaption:$("reader.tocCaption",{n:oe.chapters.length,unit:_(Ht)}),tocHeader:H&&oe.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:Se?$("reader.searchChaptersPlaceholder"):$("reader.searchUnitPlaceholder",{unit:_(Ht)}),"aria-label":Se?$("reader.searchChapters"):$("reader.searchUnit",{unit:_(Ht)}),value:de,onChange:W=>ee(W.target.value)}):void 0,activeKey:he??null,onSelect:Ce,images:Ue.images,imagesLoading:Ue.loading||ie,renderImageOverlay:p,imagePanel:z?"open":u,isWarpMode:!!z,customImagePanel:z&&Wr?t.jsxs("div",{className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Od,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",outline:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 4px 6px",fontSize:12,color:i("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",disabled:Mi<=0,onClick:()=>jn(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":Ge,style:{fontSize:11,padding:"1px 6px",background:i("rule"),borderRadius:10},children:["第 ",Ge," 葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",disabled:Mi<0||Mi>=yn.length-1,onClick:()=>jn(1),children:"›"})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[be.size>0&&t.jsxs("button",{type:"button",onClick:()=>je(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${i("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",be.size,")"]}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:2},"data-testid":"facsimile-zoom-tools",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小",title:"缩小",disabled:re<=1,onClick:()=>{var W;return(W=ue.current)==null?void 0:W.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(re*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:re>=6,onClick:()=>{var W;return(W=ue.current)==null?void 0:W.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:re===1,onClick:()=>{var W;return(W=ue.current)==null?void 0:W.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(Ng,{ref:ue,resetKey:Ge,onScaleChange:we,style:{flex:1,minHeight:0},children:t.jsx(fr,{imageUrl:Wd,pageData:Wr,selectedCharIds:be,hoveredCharId:ge,preserveMargins:Ne,onCharClick:W=>{je(Le=>{const Fe=new Set(Le);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const pe=document.querySelector(`[data-char-id="${W}"]`);pe&&pe.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Ie})}),t.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"8px 0 2px"},children:t.jsxs("div",{style:{display:"inline-flex",border:`1px solid ${i("rule")}`,borderRadius:4,overflow:"hidden"},children:[t.jsx("button",{type:"button",onClick:()=>q(!1),"aria-pressed":!Ne,className:`bim-rd-t ${Ne?"":"bim-rd-on"}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:Ne?"transparent":i("accent-bg"),color:Ne?"inherit":i("accent")},title:"去空白:紧凑裁切版心",children:"去空白"}),t.jsx("button",{type:"button",onClick:()=>q(!0),"aria-pressed":Ne,className:`bim-rd-t ${Ne?"bim-rd-on":""}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:Ne?i("accent-bg"):"transparent",color:Ne?i("accent"):"inherit"},title:"保留空白:完整呈现古籍天头地脚与白边",children:"保留空白"})]})})]}):void 0,toolbarExtra:z?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-badge-warp",children:"图文对读"}),t.jsx("button",{type:"button",className:`bim-rd-t ${K?"bim-rd-on":""}`,"aria-pressed":K,title:"切换外挂现代断句标点",onClick:()=>fe(W=>!W),children:K?"标点":"无标点"})]}):void 0,prefs:M,onPrefsChange:N,versions:Wi.length>1?Wi:void 0,currentVersionKey:Wi.length>1?G.key:void 0,onVersionChange:me,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:pi(tn),allowVertical:m,children:[xe&&t.jsx(Zt,{}),!xe&&z&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:U!=null&&U.title?_(U.title):Oi}),(G.source_name||G.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[G.source_name&&_(G.source_name),G.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),G.license]})]})]}),t.jsx(vr,{pageData:z,pages:z.pages,punctuations:z.punctuations||[],selectedCharIds:be,hoveredCharId:ge,onSelectionChange:Un,onCharClick:W=>{je(Le=>{const Fe=new Set(Le);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const pe=parseInt(W.split(":")[0],10);isNaN(pe)||Et(pe)},onCharHover:Ie,mode:"horizontal",showPunctuation:K,entities:M.properNames?ae:void 0,entityTransport:n,onEntityNavigate:j,onVisiblePageChange:W=>Et(W),convert:_,scrollToPage:Ve})]}),!xe&&!z&&en&&Ft&&t.jsx(Qh,{juan:Ft,rawText:tn,positionLabel:Pg(U,oe,Ht,_),groupLabel:Mg(oe,he??null),index:Ig(e,oe),searchQuery:de,onNavigate:a,transport:n,workLabelCache:Je,prefs:M,view:Hr,onViewChange:Bi},`${Q}/${he}`),!xe&&!z&&!en&&Hi!=null&&U&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:U.title?_(U.title):Oi}),(G.source_name||G.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[G.source_name&&t.jsxs(t.Fragment,{children:[$("reader.textSource")," ",G.source_url?t.jsx("a",{className:"bim-rd-link",href:G.source_url,target:"_blank",rel:"noreferrer",children:_(G.source_name)}):_(G.source_name)]}),G.source_name&&G.license&&t.jsx("span",{className:"bim-rd-dot"}),G.license]}),ct&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[$("reader.upstream")," ",ct.url?t.jsx("a",{className:"bim-rd-link",href:ct.url,target:"_blank",rel:"noreferrer",children:_(ct.name??ct.url)}):_(ct.name??""),ct.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),ct.license_url?t.jsx("a",{className:"bim-rd-link",href:ct.license_url,target:"_blank",rel:"noreferrer",children:ct.license}):ct.license]}),ct.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(ml,{text:ct.note,convert:_})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(cr,{text:Hi,mode:M.readingMode,tables:Gd,gujiMarkdown:uo(oe),properNames:M.properNames})})]}),!xe&&!z&&!en&&Hi==null&&U&&t.jsx("div",{className:"bim-rd-state",children:$("reader.chapterFailed")}),oe.references&&oe.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:$("reader.references")}),t.jsx("ol",{children:oe.references.map((W,pe)=>t.jsxs("li",{children:[W.url?t.jsx("a",{className:"bim-rd-link",href:W.url,target:"_blank",rel:"noopener noreferrer",children:_(W.title)}):t.jsx("span",{children:_(W.title)}),W.author&&t.jsxs("span",{children:[",",_(W.author)]}),W.note&&t.jsxs("span",{children:["。",_(W.note)]})]},pe))})]})]})};function Pg(e,n,o,r){var a,l;if(!e)return;const s=(l=(a=n.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(s?`${s}冊`:`${o}${e.n}`)}function Mg(e,n){if(!n)return;const o=r=>{var s;for(const a of r??[]){const l=o(a.children);if(l)return l;if((s=a.files)!=null&&s.includes(n))return a.label}};return o(e.juan_groups)}function Bg(e,n,o){const[r,s]=g.useState({entryTitle:void 0,authors:[]});return g.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let a=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);s({entryTitle:o&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,n,o]),r}const xc={bug:{key:"bug",color:i("danger")},resource:{key:"resource",color:i("primary")},suggestion:{key:"suggestion",color:i("primary")},other:{key:"other",color:i("desc-fg")}},Wg=xc.other,bc={pending:{key:"pending",color:i("warning")},in_progress:{key:"in_progress",color:i("primary")},resolved:{key:"resolved",color:i("success")},wontfix:{key:"wontfix",color:i("desc-fg")},duplicate:{key:"duplicate",color:i("desc-fg")}},Og=bc.pending;function Hg(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 Fg(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 Sr=({items:e,loading:n})=>{const o=Ze(),{t:r,convert:s}=J();return n?t.jsx(Zt,{}):e.length===0?t.jsx("div",{style:Dg,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=xc[a.type]||Wg,d=bc[a.status]||Og,c=typeof window<"u"&&Fg(a.pageUrl,window.location.href);return t.jsxs("div",{style:Ug,children:[t.jsxs("div",{style:Vg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ds,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Ds,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Gg,children:Hg(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Yg,children:[a.resourceId&&t.jsx("a",{href:o(a.resourceId),style:eo,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:eo,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:eo,children:a.pageUrl}))]}),t.jsx("div",{style:Kg,children:s(a.content)}),a.reply&&t.jsxs("div",{style:qg,children:[t.jsx("div",{style:Xg,children:r("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},Dg={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Ug={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Vg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ds={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Gg={fontSize:"12px",color:i("desc-fg")},Yg={fontSize:"12px",marginBottom:"6px"},eo={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Kg={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},qg={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Xg={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},$o=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:a})=>{const l=Te(),[d,c]=g.useState(null),[p,u]=g.useState([]),[m,h]=g.useState("recommend"),[f,x]=g.useState([]),[k,y]=g.useState(!1),w=r??m,b=L=>{h(L),s==null||s(L)},[j,S]=g.useState(!0),[v,$]=g.useState(null),[_,C]=g.useState(null),[M,N]=g.useState(null);g.useEffect(()=>{let L=!1;if(e.getCounts)return e.getCounts().then(I=>{L||c({works:I.works,books:I.books,collections:I.collections})}).catch(()=>{}),()=>{L=!0}},[e]),g.useEffect(()=>{let L=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const P=await e.getRecommended();if(P!=null&&P.groups)return P.groups.flatMap(V=>V.items.map(X=>({...X,group:V.name})))}catch{}return[]})().then(async P=>{if(L)return;const V=P.filter(D=>D.id);if(V.length===0){S(!1);return}const X=await Promise.all(V.map(async D=>{if(D.type)return{id:D.id,title:D.title,type:D.type,author:D.author,dynasty:D.dynasty,role:D.role,edition:D.edition,has_text:D.has_text,has_image:D.has_image,has_collated:D.has_collated,subtype:D.subtype,primary_name:D.primary_name,group:D.group,fallbackDescription:D.description};try{let O=null;if(e.getEntry)O=await e.getEntry(D.id);else{const A=await e.getItem(D.id);A&&(O={id:D.id,title:A.title||D.id,type:A.type||"work"})}if(O)return{...O,group:D.group,fallbackDescription:D.description}}catch{}return{id:D.id,title:D.title,type:_e.extractType(D.id),group:D.group,fallbackDescription:D.description}}));L||(u(X.filter(D=>D!==null)),S(!1))}),()=>{L=!0}},[e,o]);const T=g.useRef(!1),F=g.useRef(!1),R=g.useRef(!1);g.useEffect(()=>{if(w!=="catalog"||T.current)return;const L=e.getCatalogProgress??e.getResourceProgress;if(!L)return;T.current=!0;let I=!1;return L.call(e).then(P=>{I||$(P)}).catch(()=>{T.current=!1}),()=>{I=!0}},[e,w]),g.useEffect(()=>{if(w!=="collection"||F.current||!e.getCollectionProgress)return;F.current=!0;let L=!1;return e.getCollectionProgress().then(I=>{L||C(I)}).catch(()=>{F.current=!1}),()=>{L=!0}},[e,w]),g.useEffect(()=>{if(w!=="site"||R.current||!e.getSiteProgress)return;R.current=!0;let L=!1;return e.getSiteProgress().then(I=>{L||N(I)}).catch(()=>{R.current=!1}),()=>{L=!0}},[e,w]),g.useEffect(()=>{if(!a||w!=="feedback")return;let L=!1;return y(!0),fetch(a).then(I=>I.json()).then(I=>{!L&&I.success&&x(I.items||[])}).catch(()=>{}).finally(()=>{L||y(!1)}),()=>{L=!0}},[a,w]);const E=L=>t.jsx(fn,{type:L,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($n,{label:l.home.recommendTab,active:w==="recommend",onClick:()=>b("recommend")}),t.jsx($n,{label:l.home.catalogTab,active:w==="catalog",onClick:()=>b("catalog")}),t.jsx($n,{label:l.home.collectionTab,active:w==="collection",onClick:()=>b("collection")}),t.jsx($n,{label:l.home.siteTab,active:w==="site",onClick:()=>b("site")}),a&&t.jsx($n,{label:l.home.feedbackTab,active:w==="feedback",onClick:()=>b("feedback")})]}),w==="recommend"&&t.jsx(Zg,{recommended:p,loading:j,onNavigate:n,getIcon:E,t:l}),w==="catalog"&&t.jsx(Us,{progress:v,t:l,onNavigate:n}),w==="collection"&&t.jsx(Us,{progress:_,t:l,onNavigate:n}),w==="site"&&t.jsx(Qg,{progress:M,t:l,totalWorks:(d==null?void 0:d.works)??0}),w==="feedback"&&a&&t.jsx(Sr,{items:f,loading:k})]})})},$n=({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}),Zg=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const a=Ze();if(n)return t.jsx(Zt,{});if(e.length===0)return null;const l=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(l.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(p=>{const u=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return t.jsxs("a",{href:a(p.id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o==null||o(p.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(p.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[p.title,p.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:p.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},p.id)})})]},d))})},Us=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(Zt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],a={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(p=>p.status===d);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[d]}}),a[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(p=>t.jsx(Jg,{item:p,t:n,statusColor:l[d],onNavigate:o},p.id))})]},d)})})},Jg=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Ze(),a=e.total>0?Math.round(e.imported/e.total*100):0,l=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const d=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:p=>p.currentTarget.style.borderBottomStyle="solid",onMouseLeave:p=>p.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:l})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?mt(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:`${a}%`,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})]})},Qg=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(Zt,{});const r=[...e.resources].sort((c,p)=>c.priority-p.priority),s=r.filter(c=>c.imported>0),a=r.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),d=o>0?Math.round(l/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:l.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Vs,{item:c,t:n,totalWorks:o},c.id))})]}),a.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," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(Vs,{item:c,t:n,totalWorks:o},c.id))})]})]})},Vs=({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})]})},Gs="(max-width: 768px)";function ef(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(Gs).matches);return g.useEffect(()=>{const o=window.matchMedia(Gs),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const tf=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var F;const a=Te(),{convert:l}=Ae(),d=ef(),[c,p]=g.useState(null),[u,m]=g.useState(null),[h,f]=g.useState(!1),[x,k]=g.useState("detail"),[y,w]=g.useState([]),[b,j]=g.useState(!1),S=g.useCallback(async R=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){w([]);return}j(!0);try{if(e.getCollectionCatalogs){const E=await e.getCollectionCatalogs(R);w(E||[])}else if(e.getCollectionCatalog){const E=await e.getCollectionCatalog(R);w(E?[{resource_id:"",data:E}]:[])}}catch{w([])}finally{j(!1)}},[e]),v=g.useCallback(async R=>{if(o){o(R);return}p(R),m(null),w([]),k("detail"),f(!0);try{const E=await e.getItem(R.id);E&&(m(E),E.type==="collection"&&S(R.id))}catch(E){console.error("加载详情失败:",E)}finally{f(!1)}},[e,o,S]),$=g.useCallback(async R=>{m(null),w([]),k("detail"),f(!0);try{const E=await e.getItem(R);E&&(m(E),p({id:R,title:E.title||R,type:E.type||"book"}),E.type==="collection"&&S(R))}catch(E){console.error("导航失败:",E)}finally{f(!1)}},[e,S]),_=typeof(u==null?void 0:u.text_count)=="number"&&u.text_count>0,C=(u==null?void 0:u.type)==="collection"&&(y.length>0||b)||(u==null?void 0:u.type)==="work"&&_,M=d&&(h||u),N=g.useCallback(()=>{p(null),m(null),w([]),k("detail")},[]),T=t.jsx(t.Fragment,{children:h?t.jsx(Zt,{}):u?t.jsxs(t.Fragment,{children:[(C||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:d?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[C&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:ti(x==="detail"),children:a.detailTab.basicInfo}),u.type==="collection"&&b&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:ti(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(R=>t.jsx("button",{onClick:()=>k(`catalog:${R.resource_id}`),style:ti(x===`catalog:${R.resource_id}`),children:R.short_name?`${l(R.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},R.resource_id)),u.type==="work"&&_&&t.jsx("button",{onClick:()=>k("collated"),style:ti(x==="collated"),children:a.detailTab.collatedEdition})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:x==="detail"?t.jsx(Uo,{data:u,transport:e,onNavigate:$}):x.startsWith("catalog:")?t.jsx(Vo,{data:(F=y.find(R=>`catalog:${R.resource_id}`===x))==null?void 0:F.data,onNavigate:$}):x==="collated"?t.jsx(wr,{id:u.id,transport:e,onNavigate:$}):null})]}):t.jsx($o,{transport:e,onNavigate:$,recommendedIds:r})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children: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:N,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",a.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:T})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(po,{transport:e,onEntryClick:v,hideModeIndicator:n}),!u&&t.jsx($o,{transport:e,onNavigate:$,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(po,{transport:e,onEntryClick:v,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:T})]})};function ti(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}}const nf=({pageData:e,rawImageUrl:n="",punctuations:o=[],title:r,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=g.useState(new Set),[u,m]=g.useState(null),[h,f]=g.useState("horizontal"),[x,k]=g.useState(!0),y=g.useRef(null),w=g.useCallback(v=>{p(new Set(v))},[]),b=g.useCallback(v=>{if(p($=>{const _=new Set($);return _.has(v)?_.delete(v):(_.clear(),_.add(v)),_}),y.current){const $=y.current.querySelector(`[data-char-id="${v}"]`);$&&$.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var v;p(new Set),window.getSelection&&((v=window.getSelection())==null||v.removeAllRanges())},S=o.length>0?o:e.punctuations||[];return t.jsxs("div",{className:`guji-reader-container ${l}`,style:d,children:[t.jsxs("header",{className:"guji-reader-header",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&t.jsx("button",{type:"button",onClick:a,className:"guji-reader-btn",style:{marginRight:6},children:"‹ 返回"}),t.jsx("span",{className:"guji-reader-title",children:r||e.title}),s&&t.jsx("span",{style:{fontSize:"0.85rem",color:i("meta-fg")},children:s}),t.jsx("span",{className:"guji-reader-tag",children:"WebGL 客户端透视矫正对读"})]}),t.jsxs("div",{className:"guji-reader-actions",children:[t.jsxs("span",{style:{fontSize:"0.85rem",color:i("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:i("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>k(v=>!v),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f(v=>v==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:h==="horizontal"?"切换竖排":"切换横排"})]})]}),t.jsxs("div",{className:"guji-reader-body",children:[t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%",position:"sticky",top:0},children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:"底本书影 (WebGL 分带透视矫正 + 完整版心)"}),t.jsx("span",{className:"guji-pane-hint",children:"点击字框可联动文本定位"})]}),t.jsx("div",{className:"guji-pane-content",children:t.jsx(fr,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:u,onCharClick:b,onCharHover:m})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:y,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:h==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(vr,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:u,onSelectionChange:w,onCharClick:b,onCharHover:m,mode:h,showPunctuation:x})]})]})]})},of=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function on(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function rf(e){var r,s,a,l,d,c;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return[];const o=[];for(const p of n){if(!p||typeof p!="object")continue;const u=p,m=on((r=u.page)==null?void 0:r.index),h=Array.isArray(u.cells)?u.cells:[];if(m===void 0||h.length===0)continue;const f=new Map;for(const x of h){if(!x||typeof x!="object")continue;const k=x,y=of.exec(String(k.a??""));if(!y||typeof k.c!="string")continue;const w=parseInt(y[2],10),b=parseInt(y[3],10),j=Array.isArray(k.box)&&k.box.length===4&&k.box.every($=>on($)!==void 0)?k.box:null,S={id:String(k.a),char:k.c,slot:b,pos:b,sub:y[4]||null,bbox:j?[j[0],j[1],j[0]+j[2],j[1]+j[3]]:null};let v=f.get(w);v||f.set(w,v=[]),v.push(S)}o.push({page:m,seq:String(((s=u.canvas)==null?void 0:s.seq)??""),width:on((a=u.canvas)==null?void 0:a.width)??on((l=u.image)==null?void 0:l.width)??0,height:on((d=u.canvas)==null?void 0:d.height)??on((c=u.image)==null?void 0:c.height)??0,columns:Array.from(f.entries()).sort((x,k)=>x[0]-k[0]).map(([x,k])=>({col:x,chars:k}))})}return o}function sf(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.punctuations)?e.punctuations:[],o=[];for(const r of n){if(!r||typeof r!="object")continue;const s=r;typeof s.anchor!="string"||typeof s.mark!="string"||o.push({id:typeof s.id=="string"?s.id:void 0,anchor:s.anchor,mark:s.mark,kind:s.kind,pos:s.pos,pre_char:s.pre_char})}return o}function af(e){var o;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return null;for(const r of n){const s=/\/iiif\/([^/]+)\/canvas\/([^/]+)\//.exec(String(((o=r==null?void 0:r.canvas)==null?void 0:o.id)??""));if(s)return{bookId:s[1],vol:s[2]}}return null}const lf=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function gt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Ys(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(o=>!!o&&typeof o=="object"):[]}function cf(e,n){var l,d,c,p,u,m,h,f,x,k;const o=new Map,r=new Map;for(const y of Ys(n)){const w=gt(y.page);if(w!==void 0){o.set(w,y);for(const b of Array.isArray(y.cells)?y.cells:[]){const j=b==null?void 0:b.box;typeof(b==null?void 0:b.a)=="string"&&Array.isArray(j)&&j.length===4&&j.every(S=>gt(S)!==void 0)&&r.set(b.a,[j[0],j[1],j[0]+j[2],j[1]+j[3]])}}}const s=[];for(const y of Ys(e)){const w=gt(y.page);if(w===void 0)continue;const b=[];for(const S of Array.isArray(y.columns)?y.columns:[]){const v=gt(S==null?void 0:S.col);if(v===void 0)continue;const $=[];for(const _ of Array.isArray(S.cells)?S.cells:[]){const C=lf.exec(String((_==null?void 0:_.a)??""));if(!C||typeof _.c!="string")continue;const M=parseInt(C[3],10);$.push({id:_.a,char:_.c,slot:M,pos:M,sub:C[4]||null,bbox:r.get(_.a)??null})}$.length>0&&b.push({col:v,chars:$})}if(b.length===0)continue;b.sort((S,v)=>S.col-v.col);const j=o.get(w);s.push({page:w,seq:String(((l=j==null?void 0:j.canvas)==null?void 0:l.seq)??""),width:gt((d=j==null?void 0:j.canvas)==null?void 0:d.width)??gt((c=j==null?void 0:j.image)==null?void 0:c.width)??0,height:gt((p=j==null?void 0:j.canvas)==null?void 0:p.height)??gt((u=j==null?void 0:j.image)==null?void 0:u.height)??0,columns:b})}const a=new Set(s.map(y=>y.page));for(const[y,w]of o){const b=(m=w==null?void 0:w.canvas)==null?void 0:m.seq;a.has(y)||typeof b!="string"&&typeof b!="number"||String(b)===""||s.push({page:y,seq:String(b),width:gt((h=w.canvas)==null?void 0:h.width)??gt((f=w.image)==null?void 0:f.width)??0,height:gt((x=w.canvas)==null?void 0:x.height)??gt((k=w.image)==null?void 0:k.height)??0,columns:[]})}return s.sort((y,w)=>y.page-w.page)}const df=({data:e,onNavigate:n,className:o,style:r})=>{var u;const{t:s,convert:a}=J(),[l,d]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,p]=g.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:a(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:[s("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",s("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[s("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",s("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:s("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(m=>t.jsx(pf,{division:m,expanded:l===m.name,onToggle:()=>d(l===m.name?null:m.name),expandedCat:c,onCatToggle:h=>p(c===h?null:h),onNavigate:n},m.name))})]})},pf=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=J(),c=e.categories.reduce((p,u)=>{const m=u.stats||{zhulu:0,cunmu:0};return p+(m.zhulu||0)+(m.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(p=>{const u=`${e.name}/${p.name}`;return t.jsx(uf,{category:p,expanded:r===u,onToggle:()=>s(u),onNavigate:a},p.name)})})]})},uf=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var p,u,m,h;const{t:s,convert:a}=J(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((u=e.books)==null?void 0:u.cunmu)||[],c=(((m=e.stats)==null?void 0:m.zhulu)||l.length)+(((h=e.stats)==null?void 0:h.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:s("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[s("catalogPage.booksN",{n:c})," ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Ks,{label:s("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(Ks,{label:s("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},Ks=({label:e,books:n,onNavigate:o})=>{const{t:r,convert:s}=J(),a=Ze(),[l,d]=g.useState(n.length<=20),c=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:c.map((p,u)=>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:p.work_id&&o?t.jsx("a",{href:a(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o(p.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:s(p.title)}):s(p.title)}),p.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.volumes)}),p.author&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.author).slice(0,20)})]},u))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:n.length})})]})},bt=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const a=Te();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&t.jsx("button",{onClick:o,style:hf,children:"AI"}),n&&t.jsx("button",{onClick:n,style:mf,children:a.action.save})]})]}),s]})},mf={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},hf={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},ut=({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:a=>o(a.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"}})]}),Kt=({value:e,onChange:n,placeholder:o})=>{const r=g.useRef(null);return g.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},mi=({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 gf(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const si=({value:e,onChange:n,label:o})=>{const[r,s]=g.useState(!1),a=g.useRef(null),l=gf(e||"");return g.useEffect(()=>{r&&a.current&&a.current.focus()},[r]),!r&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:qs,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:l.name}),t.jsx(mi,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:qs,children:o}),t.jsx("input",{ref:a,type:"text",value:e||"",onChange:d=>n(d.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},qs={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function ff(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function xf(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const yc=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=Te(),[s,a]=g.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=m=>{n(e.filter((h,f)=>f!==m)),s===m&&a(null)},c=(m,h,f)=>{const x=[...e];x[m]={...x[m],[h]:f},n(x)},p=(m,h)=>{const f=[...e];f[m]={...f[m],type:h,id:"",name:""},n(f),h==="bookID"&&o&&o(x=>{const k=[...e];k[m]={...k[m],id:x.id,name:x.title,type:"bookID"},n(k)})},u=m=>{o&&o(h=>{const f=[...e];f[m]={...f[m],id:h.id,name:h.title,type:"bookID"},n(f)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,h)=>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:()=>a(s===h?null:h),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===h?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:m.name||`${r.editor.sourcePlaceholder} ${h+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:ff(m.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:xf(m.type)}),t.jsx("button",{onClick:f=>{f.stopPropagation(),d(h)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===h&&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:_t,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Xs,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:()=>p(h,"url"),style:{...Xs,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:_t,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:Zs,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(h),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(h),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:_t,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:Zs,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:f=>c(h,"name",f.target.value),placeholder:r.editor.sourceNamePlaceholder,style:rn})]}),t.jsxs("div",{children:[t.jsx("label",{style:_t,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:f=>c(h,"id",f.target.value),placeholder:"https://...",style:rn})]})]}),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:{..._t,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:_t,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:f=>c(h,"details",f.target.value),placeholder:r.editor.detailsPlaceholder,style:rn})]}),t.jsxs("div",{children:[t.jsx("label",{style:_t,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:f=>c(h,"position",f.target.value),placeholder:"如: 卷三, p.52",style:rn})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:_t,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:f=>c(h,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:rn})]}),t.jsxs("div",{children:[t.jsx("label",{style:_t,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:f=>c(h,"processor_version",f.target.value),placeholder:"如: v0.1",style:rn})]})]})]})]})})]},h)),t.jsxs("button",{onClick:l,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})]})]})},_t={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},rn={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"},Xs={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"},Zs={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function jc(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 vc(e){return!e||e.length===0?"":JSON.stringify(e)}const kc=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:u,onLinkEntity:m,onUnlinkEntity:h,onViewEntity:f,onCreateAndLink:x,onSaveRelations:k})=>{const y=Te();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:y.section.relations})]}),k&&t.jsx("button",{onClick:k,style:bf,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Cn,{direction:"up",title:y.relation.belongsToWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("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(Cn,{direction:"up",title:y.relation.containedInCollection,entity:l,onView:f,onUnlink:()=>h("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),a&&u&&u.length>0&&t.jsx(sn,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:f,onAdd:()=>x("siblingBook","book",{workId:a.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Cn,{direction:"up",title:y.relation.parentWork,entity:r,onView:f,onUnlink:()=>h("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>x("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),d&&d.length>0&&t.jsx(sn,{direction:"down",title:`${y.relation.childWorks} (${d.length})`,entities:d,onView:f,onAdd:()=>x("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),c&&c.length>0&&t.jsx(sn,{direction:"down",title:`${y.relation.collectionImpl} (${c.length})`,entities:c,onView:f,onAdd:()=>x("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(sn,{direction:"down",title:`${y.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("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(Cn,{direction:"up",title:y.relation.correspondingWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("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(Cn,{direction:"up",title:y.relation.parentCollection,entity:s,onView:f,onUnlink:()=>h("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>x("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(sn,{direction:"down",title:`${y.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:f,onAdd:()=>x("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(sn,{direction:"down",title:`${y.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},Cn=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:u,unlinkLabel:m})=>{const h=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=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:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),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:wc(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(Js,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(Js,{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:p}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Co,{onClick:a,children:d}),t.jsx(Co,{onClick:l,primary:!0,children:c})]})]})},sn=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=g.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",h=c?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(f=>t.jsxs("div",{onClick:()=>r(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:wc(f.type)}),t.jsx("span",{children:f.title})]},f.id)),o.length>5&&!c&&t.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[d," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:l}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Co,{onClick:s,primary:!0,children:["+ ",a]})})]})},Js=({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}),Co=({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 wc(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const bf={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Sc=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[u,m]=g.useState(""),h=p?l.filter(y=>y.id!==p):l;g.useEffect(()=>{e&&(m(""),d(""))},[e]);const f=y=>{m(y),d(y)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:yf,children:t.jsxs("div",{style:jf,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:vf,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:y=>f(y.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:kf})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:to,children:"搜索中..."}):h.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(y=>t.jsxs("div",{onClick:()=>r(y),style:wf,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),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:to,children:["未找到匹配的",x]}):t.jsxs("div",{style:to,children:["输入关键词搜索",x]})}),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:a,style:Sf,children:["创建新",x,"并关联"]})]})]})})},yf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},jf={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")},vf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},kf={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"},wf={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},to={padding:"20px",textAlign:"center",color:i("desc-fg")},Sf={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Qs={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},_f={work:"📜",book:"📖",collection:"📚",entity:"👤"},_c=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:a})=>{const[l,d]=g.useState(""),c=g.useRef(null);g.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var h,f;(h=c.current)==null||h.focus(),(f=c.current)==null||f.select()},100))},[e,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&l.trim()?u():h.key==="Escape"&&a()},u=()=>{l.trim()&&s(l.trim(),{...r,title:l.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`创建新${Qs[n]}`}};return t.jsx("div",{style:$f,onClick:h=>{h.target===h.currentTarget&&a()},children:t.jsxs("div",{style:Cf,onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:_f[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:c,type:"text",value:l,onChange:h=>d(h.target.value),onKeyDown:p,placeholder:`请输入${Qs[n]}名称...`,style:zf})]}),((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:a,style:Tf,children:"取消"}),t.jsx("button",{onClick:u,disabled:!l.trim(),style:{...Nf,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},$f={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Cf={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")},zf={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"},Tf={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Nf={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function Rf(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function $c(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ef(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 Cc=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:u})=>{const[m,h]=g.useState(""),[f,x]=g.useState([]),[k,y]=g.useState(!1),[w,b]=g.useState("recent");g.useEffect(()=>{e&&(h(""),x([]),b(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!m.trim()){x([]);return}const C=setTimeout(async()=>{y(!0);try{x(await u(m,o))}catch{x([])}finally{y(!1)}},300);return()=>clearTimeout(C)},[m,o,u]);const j=g.useCallback(C=>{h(C.target.value),C.target.value.trim()&&b("search")},[]),S=g.useCallback(C=>s?C.filter(M=>M.id!==s):C,[s]);if(!e)return null;const v=n||(o==="all"?"选择实体":`选择${$c(o)}`),$=S(r),_=S(f);return t.jsx("div",{style:Lf,children:t.jsxs("div",{style:Af,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Pf,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:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Mf}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs(ea,{active:w==="recent",onClick:()=>b("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs(ea,{active:w==="search",onClick:()=>b("search"),children:["搜索结果 ",_.length>0&&`(${_.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:w==="recent"&&$.length>0?t.jsx(ta,{entities:$,onSelect:d}):m.trim()?k?t.jsx(no,{message:"搜索中..."}):_.length>0?t.jsx(ta,{entities:_,onSelect:d}):t.jsx(no,{message:"未找到匹配的结果"}):t.jsx(no,{message:"输入关键词开始搜索"})}),a&&p&&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:p,style:Bf,children:l||"创建新实体"})]})]})})},ea=({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}),ta=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(If,{entity:o,onClick:()=>n(o)},o.id))}),If=({entity:e,onClick:n})=>{const[o,r]=g.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Rf(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:Ef(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:$c(e.type)})]})},no=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),Lf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Af={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")},Pf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Mf={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"},Bf={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Wf={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Of={work:"📜",collection:"📚",book:"📖",entity:"👤"},zc=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:u,relations:m,onRelationsChange:h})=>{var Ce;const f=Te(),[x,k]=g.useState(!1),[y,w]=g.useState("work"),[b,j]=g.useState(""),[S,v]=g.useState(""),[$,_]=g.useState([]),[C,M]=g.useState(!1),[N,T]=g.useState(!1),[F,R]=g.useState("work"),[E,L]=g.useState(""),[I,P]=g.useState(),[V,X]=g.useState(!1),[D,O]=g.useState(null),[A,G]=g.useState([]);g.useRef(null);const se=e.type,Q=se==="work",ve=se==="collection",ne=se==="book",ce=g.useCallback((Y,ze)=>{n({...e,[Y]:ze})},[e,n]),We=g.useCallback((Y,ze)=>{j(Y),w(ze),v(f.editor.selectToLink+f.indexType[ze]),_([]),k(!0)},[f]),ke=g.useCallback(Y=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,Y)},[r,e.id]),Pe=g.useCallback(Y=>{s==null||s(Y.id,Y.type)},[s]),Ee=g.useCallback((Y,ze,Me)=>{const B={...Me,author:(Me==null?void 0:Me.author)||e.author,dynasty:Me==null?void 0:Me.dynasty};R(ze),L(Y),P(B),T(!0)},[e.author]),Z=g.useCallback((Y,ze)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,E,{type:F,title:Y,inheritData:ze}),T(!1)},[r,e.id,E,F]),le=g.useCallback(Y=>{if(!Y.trim()){_([]);return}M(!0),r!=null&&r.searchEntities&&r.searchEntities(Y,y).then(ze=>{_(ze),M(!1)}).catch(()=>{_([]),M(!1)})},[r,y]),oe=g.useCallback(Y=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,b,Y.id),k(!1)},[r,e.id,b]),he=g.useCallback(()=>{o()},[o]),U=g.useCallback(Y=>{O(()=>Y),X(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(G).catch(()=>{})},[r]),$e=g.useCallback((Y,ze)=>r!=null&&r.searchEntities?r.searchEntities(Y,ze==="all"?void 0:ze):Promise.resolve([]),[r]),me=g.useCallback(Y=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(Y),G(ze=>[Y,...ze.filter(Me=>Me.id!==Y.id)].slice(0,10)),D==null||D(Y),X(!1),O(null)},[r,D]);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:Of[se]}),t.jsx("span",{children:e.title||f.editor.untitled}),t.jsx(mi,{children:e.id}),t.jsx(mi,{color:Wf[se],children:f.indexType[se]})]})}),t.jsx(bt,{title:f.section.basicInfo,onSave:o,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(si,{label:Q?f.editor.workTitle:ve?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:Y=>ce("title",Y)}),ne&&t.jsx(si,{label:f.editor.belongsToWork,value:e.workName||"",onChange:Y=>ce("workName",Y)}),t.jsx(ut,{label:f.editor.authorLabel,value:e.author||"",onChange:Y=>ce("author",Y)}),t.jsx(ut,{label:f.editor.publicationYearLabel,value:e.publicationYear||"",onChange:Y=>ce("publicationYear",Y)}),(ne||ve)&&t.jsx(si,{label:f.editor.containedIn,value:e.collection||"",onChange:Y=>ce("collection",Y)}),(ne||ve)&&t.jsx(ut,{label:f.editor.holderLabel,value:e.holder||"",onChange:Y=>ce("holder",Y)}),(ne||ve)&&t.jsx(ut,{label:ne?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:Y=>ce("pages",Y)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(ut,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:Y=>ce("firstImage",Y)})})]})}),t.jsx(bt,{title:f.section.description,onSave:o,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Kt,{value:e.description||"",onChange:Y=>ce("description",Y),placeholder:f.editor.descriptionPlaceholder})}),(((Ce=e.additional_works)==null?void 0:Ce.length)||0)>0&&t.jsx(bt,{title:f.section.additionalWorks,onSave:o,children:t.jsx(Hf,{items:e.additional_works||[],onChange:Y=>ce("additional_works",Y)})}),t.jsx(bt,{title:f.section.indexedBy,onSave:o,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Ff,{items:e.indexed_by||[],onChange:Y=>ce("indexed_by",Y)})}),t.jsx(bt,{title:f.section.emendatedBy,onSave:o,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Df,{items:e.emendated_by||[],onChange:Y=>ce("emendated_by",Y)})}),t.jsx(bt,{title:f.section.textResources,onSave:o,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(lo,{items:e.resources||[],onChange:Y=>ce("resources",Y),onDownload:p,downloadStatuses:u,filterType:"text"})}),t.jsx(bt,{title:f.section.imageResources,onSave:o,children:t.jsx(lo,{items:e.resources||[],onChange:Y=>ce("resources",Y),onDownload:p,downloadStatuses:u,filterType:"image"})}),t.jsx(bt,{title:f.section.sources,onSave:o,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(yc,{items:jc(e.sources||""),onChange:Y=>ce("sources",vc(Y)),onOpenEntityPicker:U})}),(ne||ve)&&t.jsx(bt,{title:f.section.provenance,onSave:o,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Kt,{value:e.provenance||"",onChange:Y=>ce("provenance",Y),placeholder:f.editor.provenancePlaceholder})}),ne&&t.jsx(bt,{title:f.section.otherEditions,onSave:o,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Kt,{value:e.otherEditions||"",onChange:Y=>ce("otherEditions",Y),placeholder:f.editor.otherEditionsPlaceholder})}),t.jsx(kc,{entityType:se,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:We,onUnlinkEntity:ke,onViewEntity:Pe,onCreateAndLink:Ee,onSaveRelations:he}),a&&l&&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:f.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:f.editor.dangerZoneDesc}),t.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:f.editor.deleteEntity})]}),t.jsx(Sc,{isOpen:x,entityType:y,title:S,onSelect:oe,onCancel:()=>k(!1),onCreate:()=>{k(!1),Ee(b,y)},searchResults:$,onSearch:le,isLoading:C,excludeId:e.id}),t.jsx(_c,{isOpen:N,entityType:F,relationField:E,inheritData:I,onConfirm:Z,onCancel:()=>T(!1)}),t.jsx(Cc,{isOpen:V,title:f.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:e.id,onSelect:me,onCancel:()=>{X(!1),O(null)},onSearch:$e})]})};function Hf({items:e,onChange:n}){const o=Te(),r=(l,d,c)=>{const p=e.map((u,m)=>m===l?{...u,[d]:c}:u);n(p)},s=l=>n(e.filter((d,c)=>c!==l)),a=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((l,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(ut,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(ut,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},d)),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Tc({items:e,onChange:n,showMeta:o,addLabel:r}){const s=Te(),[a,l]=g.useState(null),d=(u,m,h)=>{const f=e.map((x,k)=>k===u?{...x,[m]:h||void 0}:x);n(f)},c=u=>{n(e.filter((m,h)=>h!==u)),a===u&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,m)=>{const h=a===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:h?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(h?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:h?"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:f=>{f.stopPropagation(),c(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!h&&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]}),h&&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(ut,{label:s.label.sourceName,value:u.source,onChange:f=>d(m,"source",f)}),t.jsx(ut,{label:s.label.sourceBid,value:u.source_bid||"",onChange:f=>d(m,"source_bid",f)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ut,{label:s.label.titleInfo,value:u.title_info||"",onChange:f=>d(m,"title_info",f)}),t.jsx(ut,{label:s.label.authorInfo,value:u.author_info||"",onChange:f=>d(m,"author_info",f)})]}),t.jsx(ut,{label:s.label.edition,value:u.edition||"",onChange:f=>d(m,"edition",f)})]}),t.jsx(Kt,{value:u.summary||"",onChange:f=>d(m,"summary",f),placeholder:s.editor.summaryPlaceholder}),t.jsx(Kt,{value:u.comment||"",onChange:f=>d(m,"comment",f),placeholder:s.editor.commentPlaceholder}),t.jsx(Kt,{value:u.additional_comment||"",onChange:f=>d(m,"additional_comment",f),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),t.jsx("button",{onClick:p,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 Ff({items:e,onChange:n}){const o=Te();return t.jsx(Tc,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Df({items:e,onChange:n}){const o=Te();return t.jsx(Tc,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function Nc(e){var d,c,p,u,m,h,f;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",o=((p=e.publication_info)==null?void 0:p.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(m=e.page_count)!=null&&m.number?String(e.page_count.number):((h=e.page_count)==null?void 0:h.description)||"",a=typeof e.description=="object"&&e.description!==null&&e.description.text||"",l={id:e.id,title:e.title,type:e.type,author:n,publicationYear:o,holder:r,pages:s,description:a,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const x=e;if(Array.isArray(x.related_works)){const k=x.related_works.find(y=>y.relation==="part_of");k&&(l.parentWorkId=k.id,l.parentWorkName=k.title)}}if(e.type==="book"){const x=e;l.workId=x.work_id,Array.isArray(x.contained_in)&&x.contained_in.length>0&&(l.collectionId=(f=x.contained_in[0])==null?void 0:f.id)}return l}function Uf(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 Vf=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:u,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y,headerExtra:w,className:b,style:j}=e,S=Te(),[v,$]=g.useState(s),_=a?s:v;g.useEffect(()=>{s!==v&&$(s)},[s]);const C=g.useCallback(()=>{const L=_==="view"?"edit":"view";a?a(L):$(L)},[_,a]),[M,N]=g.useState(null);g.useEffect(()=>{o&&r&&r.getItem(o).then(L=>{L&&N(L)})},[o,r]);const T=n||M,F=g.useMemo(()=>T?Nc(T):null,[T]),R=a||!n?t.jsx("button",{onClick:C,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"?S.common.switchToEdit:S.common.switchToView,children:_==="view"?S.common.modeEdit:S.common.modeView}):null,E=t.jsxs(t.Fragment,{children:[R,w]});return!T&&!F?t.jsx(Zt,{}):_==="view"?t.jsx(Uo,{data:T,transport:r,onNavigate:p?L=>p(L):void 0,renderLink:u,headerExtra:E,className:b,style:j}):F?t.jsxs("div",{className:b,style:j,children:[E&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:E}),t.jsx(zc,{data:F,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:S.common.noData})},Gf=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Rc=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const{t:s}=J(),[a,l]=g.useState(null),[d,c]=g.useState(""),[p,u]=g.useState(""),[m,h]=g.useState("idle"),[f,x]=g.useState(""),k=g.useRef(null);g.useEffect(()=>{e&&(l(null),c(""),u(""),h("idle"),x(""))},[e]),g.useEffect(()=>{a&&setTimeout(()=>{var b;return(b=k.current)==null?void 0:b.focus()},100)},[a]),g.useEffect(()=>{if(m==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[m,n]),g.useEffect(()=>{if(!e)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const y=async()=>{if(!(!a||!d.trim())){h("submitting"),x("");try{await o({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),h("success")}catch(b){h("error"),x(b instanceof Error?b.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&m!=="submitting";return t.jsx("div",{style:Yf,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:Kf,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:qf,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:Xf,"aria-label":s("feedback.close"),children:"✕"})]}),m==="success"?t.jsxs("div",{style:tx,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:s("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:s("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Gf.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...Zf,...a===b.value?Jf:{}},children:[t.jsx("span",{children:b.icon})," ",s(`feedback.submitType.${b.value}`)]},b.value))}),t.jsx("textarea",{ref:k,value:d,onChange:b=>c(b.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||m==="submitting",style:{...Qf,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:b=>u(b.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||m==="submitting","aria-label":s("feedback.contactLabel"),style:ix}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),m==="error"&&t.jsx("div",{style:nx,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:y,disabled:!w,style:{...ex,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:s(m==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Yf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Kf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},qf={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Xf={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Zf={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"},Jf={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Qf={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ex={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},tx={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},nx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},ix={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},zo="--bim-feedback-fab-offset",To=48,ox=16,rx=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const{t:a}=J(),[l,d]=g.useState(!1),c=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(zo,`calc(${c+To+ox}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(zo)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...sx,zIndex:s??i("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":a("feedback.title"),title:a("feedback.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(Rc,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:o})]})},sx={position:"fixed",width:`${To}px`,height:`${To}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"},ax=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Ec=({onSubmit:e})=>{const{t:n}=J(),[o,r]=g.useState("bug"),[s,a]=g.useState(""),[l,d]=g.useState(""),[c,p]=g.useState("idle"),[u,m]=g.useState(""),h=g.useRef(null);g.useEffect(()=>{o&&setTimeout(()=>{var k;return(k=h.current)==null?void 0:k.focus()},100)},[o]);const f=async()=>{if(!(!o||!s.trim())){p("submitting"),m("");try{await e({type:o,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),r("bug")}catch(k){p("error"),m(k instanceof Error?k.message:n("feedback.submitFailedRetry"))}}},x=o&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:na,children:t.jsxs("div",{style:ux,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:mx,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:na,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:ax.map(k=>t.jsxs("button",{onClick:()=>r(k.value),style:{...lx,...o===k.value?cx:{}},children:[t.jsx("span",{children:k.icon})," ",n(`feedback.submitType.${k.value}`)]},k.value))}),t.jsx("textarea",{ref:h,value:s,onChange:k=>a(k.target.value),placeholder:n(o?`feedback.placeholder.${o}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...dx}}),t.jsx("input",{type:"text",value:l,onChange:k=>d(k.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:gx}),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:[s.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!x,style:{...px,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:hx,children:u})]})},na={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},lx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},cx={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},dx={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"},px={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},ux={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},mx={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},hx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},gx={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 ia(e){return typeof e=="function"?e():e??"/api/feedback"}const Ic=({resourceId:e,apiUrl:n})=>{const{t:o}=J(),[r,s]=g.useState([]),[a,l]=g.useState(!0),d=g.useCallback(async()=>{const p=ia(n);l(!0);try{const m=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();m.success&&s(m.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{d()},[d]);const c=async p=>{const u=ia(n),m=await fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!m.ok){const h=await m.json().catch(()=>null);throw new Error((h==null?void 0:h.error)||o("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Sr,{items:r,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Ec,{onSubmit:c})})]})},fx=gi["zh-Hant"].relation,xx=gi["zh-Hant"].lossStatus,bx=gi["zh-Hant"].resourceKind,Ti=mn("zh-Hant"),_r=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function oa(e,n=Ti){return e?_r(fx,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function yx(e,n=Ti){return _r(xx,e)?n(`detail.lossStatus.${e}`):e}function jx(e,n=Ti){return _r(bx,e)?n(`detail.resourceKind.${e}`):""}function $r({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=J(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=Qo(a.role);return t.jsxs(g.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(Xe,{id:a.entity_id,label:r(a.name),onNavigate:n,renderLink:o,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function Lc(e,n,o=Ti){var c,p;const r=Zo(e,n),s=r.mirrors.map(u=>({key:u.key,label:u.label,description:u.description,rows:u.items.filter(m=>m.group_role!=="mirror"),mirrors:u.items.filter(m=>m.group_role==="mirror")})),a=r.buckets.filter(u=>u.key==="image"||u.key==="textImage").flatMap(u=>u.items);a.length&&s.push({key:"_images",label:s.length?o("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(u=>u.key==="physical"))==null?void 0:c.items)??[];return l.length&&s.push({key:"_physical",label:o("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((p=r.buckets.find(u=>u.key==="text"))==null?void 0:p.items)??[],groups:s}}function Ac(e,n){const o=(e.url?hn(e.url):void 0)||e.name,r=Cl(e,n);return r?`${o}(${r})`:o}function Cr({item:e,siblings:n,listedVolumeCounts:o}){const{t:r,convert:s}=J(),[a,l]=g.useState(!1),d=fi(e),c=!!d&&d.expected>0&&!(o!=null&&o.has(d.expected)),p=s(Ac(e,n)),u=gn(e),m=Si(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,x;const h=(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:[((x=e.metadata)==null?void 0:x.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?r("colorMode.color"):r("colorMode.bw")})]}):null;return u?t.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),h]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,h]})})(),m&&t.jsx("span",{className:"bim-d-meta",children:s(m)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(or,{item:e})})]}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":a,onClick:()=>l(h=>!h),children:a?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Pc({groups:e,listedVolumeCounts:n}){const{t:o,convert:r}=J();return t.jsx(t.Fragment,{children:e.map(s=>t.jsxs("div",{className:"bim-d-rg",children:[s.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(s.label)}),s.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(s.description)}),s.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:s.rows.map((a,l)=>t.jsx(Cr,{item:a,siblings:s.rows,listedVolumeCounts:n},`${a.id||a.url||a.name}-${l}`))})}),s.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[s.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:o("detail.mirror")}),s.mirrors.map((a,l)=>{const d=gn(a),c=r(Ac(a,s.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?r(a.details):void 0,children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:c},l)})]})]},s.key))})}const An=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function No(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=An.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const ra=12,vx=60,Mc=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:a,back:l,railLinks:d})=>{var le,oe,he;const{t:c,convert:p,messages:u}=J(),m=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[h,f]=g.useState(new Map),[x,k]=g.useState(!1),[y,w]=g.useState(""),[b,j]=g.useState(!1),S=m.length<=vx,v=S||x||!!y||b,$=g.useMemo(()=>v?m:m.slice(0,ra),[m,v]);g.useEffect(()=>{if(!n||$.length===0)return;const U=$.filter(me=>!h.has(me));if(U.length===0)return;let $e=!1;return Promise.all(U.map(me=>n.getItem(me).then(Ce=>{const Y=Ce??{};return[me,{id:me,title:Y.title,edition:Y.edition,resources:Y.resources,publication_info:Y.publication_info,current_location:Y.current_location,lineage:Y.lineage,measure_info:Y.measure_info}]}).catch(()=>[me,{id:me}]))).then(me=>{$e||f(Ce=>{const Y=new Map(Ce);for(const[ze,Me]of me)Y.set(ze,Me);return Y})}),()=>{$e=!0}},[n,$,h]);const _=g.useMemo(()=>m.map(U=>h.get(U)??{id:U}),[m,h]),C=m.length>0&&m.every(U=>h.has(U)),M=!!n&&$.some(U=>!h.has(U)),N=S||v,T=g.useMemo(()=>Tl(_,e.version_graph,{era:y,scanOnly:b,sort:N?"year":"default"}),[_,e.version_graph,y,b,N]),F=x?T.rows:T.rows.slice(0,ra),R=T.allRows.filter(U=>U.hasImage).length,E=e.related_works||[],L=E.filter(U=>U.relation==="collected_in"),I=g.useMemo(()=>{const U=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],$e=me=>{const Ce=U.indexOf(me??"");return Ce<0?U.length:Ce};return E.filter(me=>me.relation!=="collected_in").map((me,Ce)=>({r:me,i:Ce})).sort((me,Ce)=>$e(me.r.relation)-$e(Ce.r.relation)||me.i-Ce.i).map(me=>me.r)},[E]),P=g.useMemo(()=>{const U=Zo(e.resources,e.resource_groups);return[...U.mirrors.flatMap($e=>$e.items.map(me=>({r:me,kind:p($e.label)}))),...U.buckets.flatMap($e=>$e.items.map(me=>({r:me,kind:p(jx($e.key,c))})))]},[e.resources,e.resource_groups,p,c]),V=e.indexed_by||[],X=e.emendated_by||[],D=g.useMemo(()=>{var te,xe,Re;const U=[],$e=(xe=(te=e.authors)==null?void 0:te[0])==null?void 0:xe.dynasty;$e&&U.push({label:c("workPage.fact.written"),value:p($e)});const me=Nt(e,u.unit.juan);if(me){const H=(Re=e.juan_count)==null?void 0:Re.description;U.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(me),H&&H!==me?t.jsxs("span",{className:"bim-d-meta",children:["(",p(H),")"]}):null]})})}e.loss_status&&U.push({label:c("workPage.fact.loss"),value:p(yx(e.loss_status,c))});const Ce=T.allRows.filter(H=>H.sortYear!=null),Y=Ce.length>0?Ce.reduce((H,de)=>H.sortYear<=de.sortYear?H:de):null;Y!=null&&Y.era.era?U.push({label:c("workPage.fact.earliest"),value:p([Y.era.era,Y.era.reign].filter(Boolean).join(" ")),title:Y.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):M&&U.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),X.length&&U.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:X.length})});const ze=sa(e.additional_titles);ze.length&&U.push({label:c("workPage.fact.alias"),value:ze.map(p).join("、")});const Me=sa(e.attached_texts);Me.length&&U.push({label:c("workPage.fact.attached"),value:Me.map(p).join("、")});const B=(e.additional_works||[]).map(H=>p(H.book_title)+(H.n_juan!=null?` ${H.n_juan}${u.unit.juan}`:""));return B.length&&U.push({label:c("workPage.fact.appendix"),value:B.join("、")}),U},[e,p,c,u,M,T.allRows,X.length]),A=[{value:e._edition_count??m.length,label:c("workPage.stat.editions")},{value:C?R:0,label:c("workPage.stat.hasImage")},{value:V.length,label:c("workPage.stat.catalogs")}],G=e.classification,se=G?[G.l1,G.l2,G.l3,G.l4].filter(Boolean).map(U=>p(U)):[],Q=e.subtype?u.workSubtype[e.subtype]??p(e.subtype):"",ve=t.jsx(Wn,{title:p(e.title),byline:t.jsx($r,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(et,{items:[...se,G!=null&&G.source?c("workPage.classifiedBy",{source:p(G.source.split("/")[0])}):"",Q]}),description:(le=e.description)!=null&&le.text?t.jsxs(t.Fragment,{children:[t.jsx(Tt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(oe=e.description.sources)!=null&&oe.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(U=>p(Bm(U))).filter(Boolean).join(" · ")}):null]}):void 0,stats:A,facts:D,readAction:s,foot:t.jsx(On,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(he=e.appendix)==null?void 0:he.map((U,$e)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(U.title)}),t.jsx(Tt,{text:U.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},$e))}),ne=T.eras.length>=2?[{key:"",label:c("catalog.all")},...T.eras.map(U=>({key:U,label:`${U} ${T.allRows.filter($e=>$e.era.era===U).length}`}))]:[],ce=[];m.length&&ce.push({id:"versions",label:c("workPage.sec.versions"),count:m.length}),V.length&&ce.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:V.length}),L.length&&ce.push({id:"collected",label:c("workPage.sec.collected"),count:L.length}),I.length&&ce.push({id:"related",label:c("workPage.sec.related"),count:I.length}),P.length&&ce.push({id:"resources",label:c("workPage.sec.resources"),count:P.length});const We=m.length===0&&V.length===0,ke=t.jsxs(t.Fragment,{children:[m.length>0&&t.jsxs(tt,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(et,{items:[c("workPage.versionsTotal",{n:m.length}),C&&R?c("workPage.versionsWithImage",{n:R}):"",T.rows.length!==T.allRows.length?c("workPage.versionsCurrent",{n:T.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":M&&ne.length===0&&m.length>1?"":void 0,children:[ne.length>0&&t.jsx($i,{items:ne,value:y,onChange:U=>{w(U),k(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Pl,{label:c("workPage.scanOnly"),checked:b,onChange:U=>{j(U),k(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(N?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&Ci(T.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:F.map(U=>{var $e;return t.jsx(kx,{row:U,measure:($e=h.get(U.id))==null?void 0:$e.measure_info,loaded:h.has(U.id),onNavigate:o,renderLink:r},`${U.id}:${h.has(U.id)?"r":"p"}`)})})]}),F.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(y||b?"workPage.noVersionsFiltered":"workPage.noVersions")}),!x&&t.jsx(er,{total:T.rows.length,shown:F.length,unit:c("workPage.moreUnit"),onClick:()=>k(!0)}),T.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),V.length>0&&t.jsx(wx,{items:V,transport:n,onNavigate:o,renderLink:r}),We&&t.jsx(tt,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),Pe=(U,$e)=>t.jsx(Xe,{id:U,label:p($e),onNavigate:o,renderLink:r,dense:!0}),Ee=g.useMemo(()=>{const U=new Map;for(const $e of I){const me=oa($e.relation,c);U.set(me,(U.get(me)??0)+1)}return U.size>1?[...U.entries()].sort(($e,me)=>me[1]-$e[1]).slice(0,4).map(([$e,me])=>`${p($e)} ${me}`).join(" · "):void 0},[I,p,c]),Z=t.jsxs(t.Fragment,{children:[t.jsx(Yt,{id:"collected",title:c("workPage.sec.collected"),items:L.map(U=>Pe(U.id,U.title))}),t.jsx(Yt,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:I.length}),sub:Ee,items:I.map(U=>t.jsxs(t.Fragment,{children:[Pe(U.id,U.title),t.jsx("span",{className:"bim-d-meta",title:U.note?p(U.note):void 0,children:p(oa(U.relation,c))})]}))}),t.jsx(Yt,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:P.map(({r:U,kind:$e})=>{const me=p((U.url?hn(U.url):void 0)||U.name),Ce=gn(U);return t.jsxs(t.Fragment,{children:[Ce?t.jsxs("a",{href:Ce,target:"_blank",rel:"noopener noreferrer",children:[me," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:me}),$e&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:$e})]})})})]});return t.jsx(Bn,{railTop:a,back:l,nav:ce,railLinks:d,main:ke,card:ve,side:Z})};function sa(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function aa(e,n){return n((e.url?hn(e.url):void 0)||e.name)}function kx({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{t:a,convert:l}=J(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],u=p?aa(p,l):e.locationName?l(e.locationName):"",m=e.images[0],h=m?gn(m):void 0,f=e.images.map(x=>aa(x,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Xe,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:c?a("workPage.inferredFromEdition"):void 0,children:d?l(d):o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${u?"":" bim-d-zt-blank"}`,children:[u||(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&&(h?t.jsx("a",{className:"bim-d-flag",href:h,target:"_blank",rel:"noopener noreferrer",title:f,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:f,children:a("workPage.hasImage")}))})]})}function wx({items:e,transport:n,onNavigate:o,renderLink:r}){const{t:s,convert:a}=J(),[l,d]=g.useState(0),c=Math.min(l,e.length-1),p=e[c],[u,m]=g.useState(new Map);return g.useEffect(()=>{if(!n)return;const h=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(h.length===0)return;let f=!1;return Promise.all(h.map(x=>n.getItem(x).then(k=>{var y,w;return[x,((w=(y=k==null?void 0:k.authors)==null?void 0:y[0])==null?void 0:w.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{f||m(new Map(x.filter(([,k])=>k)))}),()=>{f=!0}},[n,e]),t.jsx(tt,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(et,{items:[s("workPage.catalog.meta",{n:e.length}),s("workPage.sortByCatalog")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":s("workPage.catalog.tablist"),children:e.map((h,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(h.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(h.source_bid??"")?a(u.get(h.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:[...a(h.source)].slice(0,9).map((x,k)=>t.jsx("span",{children:x},k))})]})},f))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(p.title_info)}),t.jsx(et,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(Xe,{id:p.source_bid,label:a(p.source),onNavigate:o,renderLink:r,dense:!0}):a(p.source),p.section?a(p.section):"",p.author_info?`${s("label.authorInfo")} ${a(p.author_info)}`:"",p.edition?`${s("label.edition")} ${a(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:ht(a(p.summary),void 0,{t:s})}),p.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:ht(a(p.comment),void 0,{t:s})})]}),p.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:ht(a(p.additional_comment),void 0,{t:s})})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("workPage.catalog.titleOnly")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.prev",{name:a(e[c-1].source)}),onClick:()=>d(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.next",{name:a(e[c+1].source)}),onClick:()=>d(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Sx(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 _x(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 la(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 $x(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 Cx(e,n){var p;if(n==="all")return null;const o=(p=e.collections)==null?void 0:p[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,a=r||s||!!(o!=null&&o.hypothetical_ids);if(!a&&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||!a)return null;const l=r?new Set(o.groups):null,d=new Set(o.book_ids??[]);if(l&&e.node_groups)for(const[u,m]of Object.entries(e.node_groups))l.has(m)&&d.add(u);let c=null;if(o.hypothetical_ids&&(c=new Set(o.hypothetical_ids)),l){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&l.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function ai(e,n,o){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const a=new Set(r.excluded_books??[]),l=r.node_groups??{},d=Cx(r,o??r.default_collection??"all"),c=d!==null,p=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,m=new Set,h=new Set;if(c){const S=new Map(n.map(N=>[N.id,N])),v=new Map((r.hypothetical_nodes??[]).map(N=>[N.id,N])),$=N=>{const T=S.get(N);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(R=>R.ref);const F=v.get(N);return F?(F.derived_from??[]).map(R=>R.ref):[]},_=N=>v.has(N)?!u||u.has(N):!p||p.has(N),C=new Set,M=N=>{if(!C.has(N)){C.add(N);for(const T of $(N))a.has(T)||(_(T)||(v.has(T)?h.add(T):S.has(T)&&m.add(T)),M(T))}};for(const N of n)p&&p.has(N.id)&&!a.has(N.id)&&M(N.id);for(const N of r.hypothetical_nodes??[])u&&u.has(N.id)&&M(N.id)}const f=n.filter(S=>!a.has(S.id)).filter(S=>!p||p.has(S.id)||m.has(S.id)).map(S=>{const v=_x(S,l);return v&&m.has(S.id)&&(v.bridge=!0),v}).filter(S=>S!==null),x=(r.hypothetical_nodes??[]).filter(S=>!u||u.has(S.id)||h.has(S.id)).map(S=>{const v=Sx(S);return h.has(S.id)&&(v.bridge=!0),v}),k=[...f,...x],y=new Set(k.map(S=>S.id)),w=new Set,b=[],j=S=>{w.has(S.id)||!y.has(S.source)||!y.has(S.target)||(w.add(S.id),b.push(S))};for(const S of n)a.has(S.id)||!S.lineage||p&&!p.has(S.id)&&!m.has(S.id)||((S.lineage.derived_from??[]).forEach((v,$)=>{j(la(S.id,v,$))}),(S.lineage.related_to??[]).forEach((v,$)=>{j($x(S.id,v,$))}));for(const S of r.hypothetical_nodes??[])u&&!u.has(S.id)&&!h.has(S.id)||(S.derived_from??[]).forEach((v,$)=>{j(la(S.id,v,$))});return{nodes:k,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(a)}}function Bc(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function zx(e,n){const o=[],r=e.version_graph;if(!r)return o;const s=new Set(n.map(c=>c.id)),a=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...a]),d=(c,p)=>{l.has(p.ref)||o.push(`${c}: derived_from.ref "${p.ref}" 未在 books 或 hypothetical_nodes 中找到`),p.ref_type==="book"&&!s.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 book 但不在 books 列表中`),p.ref_type==="hypothetical"&&!a.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const p=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>d(p,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${p}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>d(p,u))}return o}const Wc=({graph:e,renderLink:n,className:o,style:r})=>{const{t:s,convert:a}=J();if(!e.nodes.length)return t.jsx("div",{style:{...Fx,...r},className:o,children:s("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const x=l.get(f.target)??[];x.push(f),l.set(f.target,x)}else for(const x of[f.source,f.target]){const k=d.get(x)??[];k.push(f),d.set(x,k)}const c=new Map(e.nodes.map(f=>[f.id,f])),p=new Map,u=[];for(const f of e.nodes)if(f.group){const x=p.get(f.group)??[];x.push(f),p.set(f.group,x)}else u.push(f);const m=(f,x)=>(f.year??9999)-(x.year??9999);p.forEach(f=>f.sort(m)),u.sort(m);const h=e.groups.filter(f=>p.has(f.id));return t.jsxs("div",{className:o,style:{...Nx,...r},children:[e.title&&t.jsx("div",{style:Rx,children:a(e.title)}),e.description&&t.jsx("div",{style:Ex,children:a(e.description)}),h.map(f=>t.jsx(ca,{label:f.label,color:f.color,nodes:p.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},f.id)),u.length>0&&t.jsx(ca,{label:s("lineage.otherGroup"),nodes:u,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},ca=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=J();return t.jsxs("div",{style:Ix,children:[t.jsx("div",{style:{...Lx,borderLeftColor:n??i("widget-border")},children:d(e)}),o.map(c=>t.jsx(Tx,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Tx=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=J();return t.jsxs("div",{style:{...Ax,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?i("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Px,children:[t.jsx("span",{style:Mx,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Bx,children:Bc(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Wx,children:[e.category&&t.jsx(zn,{children:c(e.category)}),e.status==="lost"&&t.jsx(zn,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(zn,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(zn,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(zn,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Ox,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Hx,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:pa,children:[t.jsx("div",{style:ua,children:d("lineage.sources")}),n.map(p=>{const u=r.get(p.source);return t.jsxs("div",{style:ma(p.confidence),children:[t.jsx("span",{style:ha,children:c(p.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,c(u.label)):c((u==null?void 0:u.label)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(da,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ga,children:["· ",c(p.evidence)]})]},p.id)})]}),o.length>0&&t.jsxs("div",{style:pa,children:[t.jsx("div",{style:ua,children:d("lineage.related")}),o.map(p=>{const u=p.source===e.id?p.target:p.source,m=r.get(u);return t.jsxs("div",{style:ma(p.confidence),children:[t.jsx("span",{style:ha,children:c(p.relation)}),t.jsx("span",{children:(m==null?void 0:m.kind)==="book"&&s?s(m.id,c(m.label)):c((m==null?void 0:m.label)??u)}),t.jsx(da,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ga,children:["· ",c(p.evidence)]})]},p.id)})]})]})},zn=({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})},da=({level:e})=>{const{t:n}=J(),r={certain:{key:"certain",color:i("confidence-certain")},consensus:{key:"consensus",color:i("confidence-consensus")},probable:{key:"probable",color:i("confidence-probable")},disputed:{key:"disputed",color:i("confidence-disputed")}}[e];return r?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:n(`lineage.confidence.${r.key}`)}):null},Nx={fontSize:"14px",color:i("fg")},Rx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ex={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Ix={marginBottom:"16px"},Lx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Ax={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Px={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Mx={fontSize:"15px",fontWeight:600},Bx={fontSize:"12px",color:i("muted")},Wx={marginBottom:"6px"},Ox={fontSize:"12px",color:i("muted"),margin:"2px 0"},Hx={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},pa={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},ua={fontSize:"11px",color:i("muted"),marginBottom:"2px"},ma=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),ha={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},ga={fontSize:"11px",color:i("muted")},Fx={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Oc=({selectedNodeId:e,...n})=>{const{t:o}=J(),[r,s]=g.useState("loading"),[a,l]=g.useState(null);return g.useEffect(()=>{let d=!1;return Dx().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:xa,children:o("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:xa,children:[t.jsx("div",{children:fa(o("lineage.graphMissing"),{xyflow:t.jsx("code",{children:"@xyflow/react"}),dagre:t.jsx("code",{children:"@dagrejs/dagre"})})}),t.jsx("div",{style:{fontSize:"12px",marginTop:"4px"},children:fa(o("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Ux,{modules:a,selectedNodeId:e,...n})};function fa(e,n){return e.split(/(\{\w+\})/).map((o,r)=>{const s=/^\{(\w+)\}$/.exec(o);return t.jsx(g.Fragment,{children:s&&s[1]in n?n[s[1]]:o},r)})}async function Dx(){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 Ux=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:p,Handle:u,Position:m,BaseEdge:h,EdgeLabelRenderer:f,getSmoothStepPath:x,dagre:k}=l,y=g.useMemo(()=>({lineage:$=>{var I,P,V,X;const _=((I=$.data)==null?void 0:I.stepPosition)??.85,[C,M,N]=x({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:_,borderRadius:5}),T=!!((P=$.data)!=null&&P.isSibling),F=T?M:$.targetX-18,R=T?N:$.targetY-12,E=(V=$.data)==null?void 0:V.labelStyle,L=(X=$.data)==null?void 0:X.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(h,{id:$.id,path:C,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...L,...E},children:$.label})})]})}}),[h,f,x]),w=g.useMemo(()=>({version:$=>{const{t:_}=J(),C=$.data,M=C.kind==="hypothetical",N=C.status==="lost",T=C.isSelected,F=C.bridge,R=C.borderColor??i("muted"),E=F||M?"dashed":"solid",L=F?.5:N?.6:1;return t.jsxs("div",{style:{background:i(F?"bg-subtle":"bg"),border:`2px ${E} ${T?i("primary"):R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:L,boxShadow:T?i("shadow-node-selected"):M||F?"none":i("shadow-node")},title:F?_("lineage.bridgeTitle"):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:M||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Bc(C.yearText,void 0,C.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:_("lineage.lost")}),t.jsx(u,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[u,m]),{convert:b}=J(),{rfNodes:j,rfEdges:S}=g.useMemo(()=>Vx(e,k,n,a,b),[e,k,n,a,b]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(p,{showInteractive:!1})]})})};function Vx(e,n,o,r,s=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const p=new Map(e.groups.map(w=>[w.id,w.color??i("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(u.has(w.relation)||c.setEdge(w.source,w.target));n.layout(c);const m=e.nodes.map(w=>{const b=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:s(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:s(w.year_text??Yx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?p.get(w.group):void 0,renderLink:o,isSelected:j,description:s(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:S,draggable:!1,selected:j}}),h=.78,f=.06,x=new Map;for(const w of e.edges)w.kind==="derive"&&(x.has(w.source)||x.set(w.source,[]),x.get(w.source).push(w));const k=new Map;for(const[w,b]of x){if(b.length<=1)continue;const j=[...b].sort((v,$)=>{var M,N;const _=((M=c.node(v.target))==null?void 0:M.y)??0,C=((N=c.node($.target))==null?void 0:N.y)??0;return _-C}),S=j.length;j.forEach((v,$)=>{const _=($-(S-1)/2)*f;k.set(v.id,h+_)})}const y=e.edges.map(w=>Gx(w,k.get(w.id),s));return{rfNodes:m,rfEdges:y}}function Gx(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=Kx(e.confidence),l={type:"arrowclosed",color:a,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:a,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Yx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Kx(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 xa={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},zr=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:u,style:m})=>{var S;const{t:h,convert:f}=J(),[x,k]=g.useState(n),y=v=>{k(v),a==null||a(v)},w=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:h("lineage.collectionAll"),description:h("lineage.collectionAllDesc")}]]})(),b=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:h("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:u,style:m,children:[t.jsxs("div",{style:qx,children:[t.jsx("button",{onClick:()=>y("list"),style:io(x==="list"),children:h("lineage.modeList")}),t.jsx("button",{onClick:()=>y("graph"),style:io(x==="graph"),children:h("lineage.modeGraph")}),b&&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:h("lineage.collectionLabel")}),w.map(([v,$])=>{const _=p==null?void 0:p[v];return t.jsxs("button",{onClick:()=>d==null?void 0:d(v),style:io(l===v),title:$.description?f($.description):void 0,children:[f($.label),_!=null?` ${_}`:""]},v)})]})]}),b&&j&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:f(j)}),x==="list"?t.jsx(Wc,{graph:e,renderLink:o}):t.jsx(Oc,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},qx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},io=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"}),ba=40,ya=2,Xx=9,Zx=new Set(["certain","consensus","probable","disputed"]);function oo(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Hc=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:u})=>{var Re,H,de,ee,ye,Se,Be,De,Je,He,Ue;const m=Te(),{t:h,convert:f}=J(),[x,k]=g.useState(null),[y,w]=g.useState(new Map),[b,j]=g.useState([]),[S,v]=g.useState(new Map),[$,_]=g.useState(!1),[C,M]=g.useState("flow"),[N,T]=g.useState(null);g.useEffect(()=>{if(!n||!e.work_id){k(null);return}let z=!1;return n.getItem(e.work_id).then(ie=>{!z&&ie&&ie.type==="work"&&k(ie)}).catch(()=>{}),()=>{z=!0}},[n,e.work_id]),g.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let z=!1;return n.getLineageGraph(e.work_id).then(ie=>{z||T(ie&&ie.nodes.length>1?ie:null)}).catch(()=>{z||T(null)}),()=>{z=!0}},[n,e.work_id]),g.useEffect(()=>{const z=e.contained_in||[];if(!n||z.length===0){w(new Map);return}let ie=!1;return Promise.all(z.map(ae=>{const be=typeof ae=="string"?ae:ae.id;return n.getItem(be).then(je=>[be,je]).catch(()=>[be,null])})).then(ae=>{if(ie)return;const be=new Map;for(const[je,ge]of ae)ge&&be.set(je,ge);w(be)}),()=>{ie=!0}},[n,e.contained_in]);const F=g.useMemo(()=>{const z=new Set([...(x==null?void 0:x.books)||[],...e.related_books||[]]);return z.add(e.id),[...z]},[x==null?void 0:x.books,e.related_books,e.id]),R=F.length-1;g.useEffect(()=>{if(!n||R<=0){j([]);return}const z=F.length<=ba,ie=z?F:F.slice(0,8);let ae=!1;return Promise.all(ie.map(be=>be===e.id?Promise.resolve({id:be,title:e.title,edition:e.edition,year:di(e)}):n.getItem(be).then(je=>{const ge=je??{};return{id:be,title:ge.title,edition:ge.edition,year:je?di(ge):void 0}}).catch(()=>({id:be})))).then(be=>{if(ae)return;const je=be.filter(ge=>ge.id===e.id||ge.title||ge.edition);z&&je.sort((ge,Ie)=>(ge.year??1/0)-(Ie.year??1/0)),j(je)}),()=>{ae=!0}},[n,F,R,e]);const E=e.lineage,L=g.useMemo(()=>[...((E==null?void 0:E.derived_from)||[]).filter(z=>z.ref_type==="book").map(z=>z.ref),...((E==null?void 0:E.related_to)||[]).map(z=>z.book_id)].filter(Boolean),[E]);g.useEffect(()=>{if(!n||L.length===0){v(new Map);return}let z=!1;return Promise.all(L.map(ie=>n.getItem(ie).then(ae=>[ie,{id:ie,title:ae==null?void 0:ae.title,edition:ae==null?void 0:ae.edition}]).catch(()=>[ie,{id:ie}]))).then(ie=>{z||v(new Map(ie))}),()=>{z=!0}},[n,L]);const I=g.useMemo(()=>Lc(e.resources,e.resource_groups,h),[e.resources,e.resource_groups,h]),P=I.groups.reduce((z,ie)=>z+ie.rows.length+ie.mirrors.length,0),V=I.groups.length>0&&I.groups.every(z=>z.key==="_physical"),X=Mn(e),D=Ll(e),O=Nt(e,m.unit.juan),A=new Set((e.contained_in||[]).map(z=>typeof z=="string"?0:In(z.volume_index).length).filter(z=>z>0)),G=z=>{var be;const ie=(be=e.base_edition)==null?void 0:be.find(je=>je.book_id===z&&je.name);if(ie!=null&&ie.name)return ie.name;const ae=S.get(z);return(ae==null?void 0:ae.edition)||(ae==null?void 0:ae.title)||""},se=g.useMemo(()=>{var fe,Ne,q,ue,re;const z=[];D&&z.push({label:h("bookPage.fact.editionType"),value:f(D),title:e.edition_type||(fe=e.lineage)!=null&&fe.category?void 0:h("bookPage.inferredFromEdition")}),(Ne=e.publication_info)!=null&&Ne.details?z.push({label:h("bookPage.fact.publication"),value:f(e.publication_info.details)}):(X.era||X.reign)&&z.push({label:h("bookPage.fact.era"),value:f([X.era,X.reign].filter(Boolean).join(" ")),title:X.source==="edition"?h("bookPage.inferredFromEdition"):void 0}),O&&z.push({label:h("bookPage.fact.measure"),value:f(O)});const ie=(e.contained_in||[]).flatMap(we=>typeof we=="string"?[]:In(we.volume_index));ie.length&&z.push({label:h("bookPage.fact.volumes"),value:h("bookPage.volumesValue",{range:_i(ie,m.unit.volume),unit:m.unit.volume,n:ie.length})});const ae=(((q=e.lineage)==null?void 0:q.derived_from)||[]).find(we=>we.relation==="底本"&&we.ref_type==="book");ae&&G(ae.ref)&&z.push({label:h("bookPage.fact.baseEdition"),value:t.jsx(Xe,{id:ae.ref,label:f(G(ae.ref)),onNavigate:o,renderLink:r,dense:!0})});const be=(e.base_edition||[]).filter(we=>we&&we.name);for(const we of["底本","配補","參校"]){if(we==="底本"&&ae&&G(ae.ref))continue;const Ve=be.filter(Oe=>Oe.role===we);Ve.length&&z.push({label:f(we),value:Ve.map((Oe,lt)=>t.jsxs(g.Fragment,{children:[lt>0&&"、",Oe.book_id?t.jsx(Xe,{id:Oe.book_id,label:f(Oe.name),onNavigate:o,renderLink:r,dense:!0}):f(Oe.name)]},lt))})}const je=(e.provenance||[]).filter(we=>we&&we.institution),ge=(e.resources||[]).filter(we=>(we.types||(we.type?[we.type]:[])).includes("physical"));if(je.length){z.push({label:h("bookPage.fact.holdings"),value:je.slice(0,2).map(Oe=>f(Oe.institution)).join("、")+(je.length>2?h("bookPage.andMorePlaces",{n:je.length}):"")});const we=je.filter(Oe=>Oe.call_number).slice(0,2).map(Oe=>`${f(Oe.institution)} ${Oe.call_number}`);we.length&&z.push({label:h("bookPage.fact.callNumber"),value:we.join(";")+(je.filter(Oe=>Oe.call_number).length>2?"…":"")});const Ve=je.flatMap(Oe=>Oe.seals||[]).filter(Boolean);Ve.length&&z.push({label:h("bookPage.fact.seals"),value:f(Ve.join("、"))})}else ge.length?z.push({label:h("bookPage.fact.holdings"),value:ge.slice(0,2).map(we=>f(we.name)).join("、")+(ge.length>2?h("bookPage.andMorePlaces",{n:ge.length}):"")}):(ue=e.current_location)!=null&&ue.name&&z.push({label:h("bookPage.fact.holdings"),value:f(e.current_location.name)});const Ie=e.physical_description;if(Ie){const we=[[h("bookPage.fact.leafStyle"),Ie.leaf_style],[h("bookPage.fact.binding"),Ie.binding],[h("bookPage.fact.dimensions"),Ie.dimensions],[h("bookPage.fact.condition"),Ie.condition]];for(const[Ve,Oe]of we)Oe&&Oe.trim()&&z.push({label:Ve,value:f(Oe)})}(re=e.page_count)!=null&&re.description&&z.push({label:m.label.pageCount,value:f(e.page_count.description)});const K=[...ko(e.additional_titles),...ko(e.attached_texts)];return K.length&&z.push({label:h("bookPage.fact.aliases"),value:K.map(f).join("、")}),z},[e,f,m,h,X,D,O,S,o,r]),Q=f(e.title),ve=e.edition?f(e.edition):void 0,ne=((Re=e.lineage)==null?void 0:Re.year_text)||"",ce=t.jsx(Wn,{kind:h("bookPage.kind"),title:Q,subtitle:ve,byline:t.jsx($r,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:o,renderLink:r}),meta:(()=>{const z=[D?f(D):"",X.era?f([X.era,X.reign].filter(Boolean).join("")):"",O?f(O):""].filter(Boolean);return z.length?t.jsx("span",{className:"bim-d-tags",children:z.map((ie,ae)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ae,2)}`,children:ie},ae))}):null})(),description:(H=e.description)!=null&&H.text?t.jsx(Tt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:nr((de=e.description)==null?void 0:de.text)?6:void 0,facts:se,readAction:s,secondaryAction:s&&P>0&&!V?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:h("bookPage.viewImages")}):void 0,foot:t.jsx(On,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),We=e.contained_in||[],ke=(a==null?void 0:a.chapters)||[],Pe=f(ke[0]&&oo(ke[0].title)[0].slice(-1)||"")||h("bookPage.chapterUnit"),Ee=h("bookPage.chapterCount",{n:ke.length,unit:Pe}),Z=!!((ee=E==null?void 0:E.derived_from)!=null&&ee.length||(ye=E==null?void 0:E.related_to)!=null&&ye.length||(Se=e.appendix)!=null&&Se.length),le=[],oe=h(V?"bookPage.sec.physical":"bookPage.sec.images");(ke.length||I.text.length||l)&&le.push({id:"fulltext",label:h("bookPage.sec.fulltext"),count:ke.length?Ee:void 0}),I.groups.length&&le.push({id:"images",label:oe,count:P}),Z&&le.push({id:"lineage",label:h("bookPage.sec.lineage")}),We.length&&le.push({id:"collections",label:h("section.containedIn"),count:We.length}),(Be=e.location_history)!=null&&Be.length&&le.push({id:"provenance",label:h("section.locationHistory")});const he=z=>(d==null?void 0:d(z))??null,U=ke[0],$e=U?he(U.file):null,me=$?ke:ke.slice(0,Xx),Ce=(z,ie,ae)=>z?t.jsx("a",{className:ae,href:z.href??"#",onClick:z.onClick?be=>{be.metaKey||be.ctrlKey||(be.preventDefault(),z.onClick())}:void 0,children:ie}):t.jsx("span",{className:ae,children:ie}),Y=t.jsxs(t.Fragment,{children:[(ke.length>0||I.text.length>0||l)&&t.jsxs(tt,{id:"fulltext",title:h("bookPage.sec.fulltext"),meta:ke.length>0?t.jsx(et,{items:[Ee,(De=a==null?void 0:a.source)!=null&&De.name?h("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!U&&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"})]}),U&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:h("bookPage.readFrom",{ch:f(oo(U.title)[0])||h("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((U.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),Ce($e,t.jsxs(t.Fragment,{children:[h("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ke.length>1&&t.jsx("ul",{className:"bim-d-chap",children:me.map(z=>{const[ie,ae]=oo(z.title);return t.jsx("li",{children:Ce(he(z.file),t.jsxs(t.Fragment,{children:[ie&&t.jsx("b",{children:f(ie)}),f(ae||z.file)]}))},z.file)})}),ke.length>me.length&&t.jsx(tr,{label:h("detail.expandRest",{n:ke.length-me.length,unit:Pe}),onClick:()=>_(!0)}),I.text.length>0&&t.jsxs(t.Fragment,{children:[(ke.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:h("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:I.text.map((z,ie)=>t.jsx(Cr,{item:z,siblings:I.text,listedVolumeCounts:A},`${z.id||z.url||z.name}-${ie}`))})})]})]}),I.groups.length>0&&t.jsx(tt,{id:"images",title:oe,meta:t.jsx(et,{items:[I.groups.length>1?h("bookPage.groupCount",{n:I.groups.length}):"",h("bookPage.placeCount",{n:P})]}),children:t.jsx(Pc,{groups:I.groups,listedVolumeCounts:A})}),Z&&t.jsx(tt,{id:"lineage",title:h("bookPage.sec.lineage"),meta:(Je=E==null?void 0:E.derived_from)!=null&&Je.length?h("bookPage.lineageMeta"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":h("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":C==="flow",onClick:()=>M("flow"),children:h("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>M("graph"),children:h("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&N?t.jsx(zr,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(z,ie)=>t.jsx(Xe,{id:z,label:f(ie),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(Qx,{data:e,heading:ve||Q,yearText:ne,refName:G,onNavigate:o,renderLink:r})}),We.length>0&&t.jsx(tt,{id:"collections",title:h("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:We.map((z,ie)=>{var Ie,K;const ae=typeof z=="string"?z:z.id,be=typeof z=="string"?[]:In(z.volume_index),je=y.get(ae),ge=(je==null?void 0:je._member_count)||((Ie=je==null?void 0:je.books)==null?void 0:Ie.length)||((K=je==null?void 0:je.contained_works)==null?void 0:K.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Xe,{id:ae,label:je?f(je.title):ae,onNavigate:o,renderLink:r,dense:!0}),be.length>0&&t.jsx(Jx,{volumes:be,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ge?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ge>0&&h("bookPage.totalOf",{n:ge,unit:m.unit.bu})})]},`${ae}-${ie}`)})})})}),(He=e.location_history)!=null&&He.length?t.jsx(tt,{id:"provenance",title:h("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((z,ie)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(z.name)}),([z.start_date,z.end_date].filter(Boolean).join("—")||z.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(et,{items:[[z.start_date,z.end_date].filter(Boolean).join("—"),z.description?f(z.description):""]})})]},ie))})}):null,le.length===0&&t.jsx(tt,{title:h("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:h("bookPage.emptyText")})})]}),ze=b.findIndex(z=>z.id===e.id),Me=F.length<=ba,B=Me&&ze>=0?b.slice(Math.max(0,ze-ya),ze+ya+1):b.filter(z=>z.id!==e.id),te=t.jsxs(t.Fragment,{children:[x&&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(Xe,{id:x.id,label:f(x.title),onNavigate:o,renderLink:r})}),t.jsx(et,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(z=>`${z.dynasty?`〔${f(z.dynasty)}〕`:""}${f(z.name)}`),f(Nt(x,m.unit.juan)),x._edition_count?h("bookPage.editionCount",{n:x._edition_count}):""]}),((Ue=x.description)==null?void 0:Ue.text)&&t.jsx("p",{style:{fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc bim-d-side-desc",children:f(x.description.text.replace(/[#*_>`[\]]/g,""))})]}),R>0&&B.length>0&&t.jsxs("div",{children:[t.jsx(Yt,{id:"siblings",timeline:!0,title:Me?h("bookPage.siblings"):m.relation.siblingVersions,meta:Me?h("bookPage.byEra"):h("bookPage.kindCount",{n:R}),cap:B.length,items:B.map(z=>z.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(z.edition||z.title||z.id)}):t.jsx(Xe,{id:z.id,label:f(z.edition||z.title||z.id),onNavigate:o,renderLink:r,dense:!0})),metas:B.map(z=>[z.year!=null?z.year<0?h("detail.bce",{n:-z.year}):String(z.year):"",z.id===e.id?h("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:B.findIndex(z=>z.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(Xe,{id:x.id,label:h("bookPage.viewAllInWork",{n:F.length}),onNavigate:o,renderLink:r,dense:!0})})]})]}),xe=e.work_id?t.jsx(Al,{caption:m.section.belongsToWork,children:t.jsx(Xe,{id:e.work_id,label:x?f(x.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(Bn,{railTop:c,back:p,up:xe,nav:le,railLinks:u,main:Y,card:ce,side:te})};function Jx({volumes:e,unit:n}){const{t:o}=J();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o("bookPage.volumeRange",{range:_i(e,n),unit:n}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o("bookPage.volumeCount",{n:e.length,unit:n})]})]})}function Qx({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:a}){var w;const{t:l,convert:d}=J(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],u=p.filter(b=>b.ref_type!=="book"),m=p.filter(b=>b.ref_type==="book"&&b.relation==="底本"),h=p.filter(b=>b.ref_type==="book"&&b.relation!=="底本"),f=(c==null?void 0:c.related_to)||[],x=p.length>0||f.length>0,k=b=>b&&Zx.has(b)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${b}`)}):"",y=(b,j)=>t.jsx(Xe,{id:b,label:d(j||b),onNavigate:s,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[x&&t.jsxs("ol",{className:"bim-d-lf-list",children:[u.map((b,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:b.relation?d(b.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),b.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(b.evidence),k(b.confidence)]})]})},`a-${j}`)),m.map((b,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:d(o)})]}),h.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:h.map((b,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.confidence)]})]},j))})]}),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:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((b,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:b.evidence?d(b.evidence):void 0,children:[y(b.book_id,r(b.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(b.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((b,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(b.title)]}),t.jsx(Tt,{text:b.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Tn=16,eb=200,tb=16,Fc=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var Y,ze,Me,B,te,xe,Re;const{t:p,convert:u,messages:m}=J(),[h,f]=g.useState(""),[x,k]=g.useState(!1),[y,w]=g.useState(null),[b,j]=g.useState(""),[S,v]=g.useState(!1),$=g.useMemo(()=>El(e,n),[e,n]),[_,C]=g.useState(new Map),M=!!o&&$.rows.length>0&&$.rows.length<=eb,N=M&&($.rows.length<=Tn||S),T=N&&$.rows.every(H=>!H.id||_.has(H.id)),F=H=>{var de;return No(H?(de=_.get(H))==null?void 0:de.l1:void 0)},R=g.useMemo(()=>{const H=h.trim(),de=H?u(H):"";return $.rows.filter(ee=>{var Se,Be;if(b&&No(ee.id?(Se=_.get(ee.id))==null?void 0:Se.l1:void 0)!==b)return!1;if(!de)return!0;const ye=ee.id&&((Be=_.get(ee.id))==null?void 0:Be.title)||ee.title;return u(ye).includes(de)||(ee.subItems||[]).some(De=>u(De).includes(de))})},[$.rows,h,b,_,u]),E=x?R:R.slice(0,Tn),L=g.useMemo(()=>(N?$.rows:E).filter(H=>H.id&&!_.has(H.id)).map(H=>H.id),[N,$.rows,E,_]);g.useEffect(()=>{if(!o||L.length===0)return;let H=!1;const de=L.slice(0,tb);return Promise.all(de.map(ee=>o.getItem(ee).then(ye=>{var De,Je;const Se=ye??{},Be={title:Se.title,edition:Se.edition,authors:Se.authors,measure:ye?Nt(ye,m.unit.juan):void 0,versionCount:Se._edition_count??((De=Se.books)==null?void 0:De.length),l1:((Je=Se.classification)==null?void 0:Je.l1)||void 0};return[ee,Be]}).catch(()=>[ee,{}]))).then(ee=>{H||C(ye=>{const Se=new Map(ye);for(const[Be,De]of ee)Se.set(Be,De);return Se})}),()=>{H=!0}},[o,L,m.unit.juan]);const I=(e.contained_in||[])[0];g.useEffect(()=>{if(!I){w(null);return}if(w({id:I}),!o)return;let H=!1;return o.getItem(I).then(de=>{H||w({id:I,title:de==null?void 0:de.title})}).catch(()=>{}),()=>{H=!0}},[o,I]);const P=g.useMemo(()=>Lc(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),V=P.text.length+P.groups.reduce((H,de)=>H+de.rows.length+de.mirrors.length,0),X=e.contained_works||[],D=new Set($.rows.map(H=>H.id).filter(Boolean)),O=X.length>0&&!X.every(H=>D.has(H.id)),A=(()=>{const H=$.rows.map(de=>de.edition).filter(Boolean);return H.length>1&&new Set(H).size===1})(),G=$.rows.some(H=>H.volumes.length>0||H.expected!=null),se=e._member_count||((Y=e.books)==null?void 0:Y.length)||X.length,Q=e._members_truncated?se:$.rows.length,ve=Nt(e,m.unit.juan),ne=e.count,ce=H=>typeof H=="number"&&Number.isFinite(H)?H:null,We=ce(ne==null?void 0:ne.juan)??ce((ze=e.juan_count)==null?void 0:ze.number),ke=ce(ne==null?void 0:ne.ce)??($.totalVolumes||null),Pe=[{value:Q,label:p("collectionPage.stat.titles")},{value:We??0,label:m.unit.juan},{value:ke??0,label:m.unit.volume}],Ee=g.useMemo(()=>{var ee,ye;const H=[];if((ee=e.publication_info)!=null&&ee.details&&H.push({label:p("collectionPage.fact.publication"),value:u(e.publication_info.details)}),se&&(se!==$.rows.length||e._members_truncated)){const Se=e._member_type==="Book"?p("collectionPage.member.Book"):e._member_type==="Work"?p("collectionPage.member.Work"):p("collectionPage.member.other");H.push({label:Se,value:`${se} ${m.unit.bu}`,title:p("collectionPage.memberNote")})}const de=[ce(ne==null?void 0:ne.zhong)!=null?p("collectionPage.nZhong",{n:ne.zhong}):"",ce(ne==null?void 0:ne.han)!=null?p("collectionPage.nHan",{n:ne.han}):""].filter(Boolean);return de.length&&H.push({label:p("collectionPage.fact.expected"),value:de.join(" ")}),We==null&&ve&&H.push({label:p("collectionPage.fact.measure"),value:u(ve),title:(ye=e.juan_count)!=null&&ye.description?u(e.juan_count.description):void 0}),H},[e,se,$.rows.length,We,ve,ne,u,p,m]),Z=g.useMemo(()=>{if(!T)return[];const H=new Map;for(const ee of $.rows){const ye=F(ee.id);ye&&H.set(ye,(H.get(ye)??0)+1)}const de=An.filter(ee=>(H.get(ee.key)??0)>0);return de.length<2?[]:[{key:"",label:`${m.catalog.all} ${Q}`},...de.map(ee=>({key:ee.key,label:`${ee.label} ${H.get(ee.key)}`}))]},[T,$.rows,_,m]),le=g.useMemo(()=>{if(!T||!$.rows.some(ye=>ye.volumes.length>0))return null;const H=[],de=$.rows.filter(ye=>ye.volumes.length>0).map(ye=>({k:F(ye.id)??"",from:Math.min(...ye.volumes),to:Math.max(...ye.volumes)})).sort((ye,Se)=>ye.from-Se.from);for(const ye of de){const Se=ye.to-ye.from+1,Be=H[H.length-1];Be&&Be.key===ye.k?(Be.to=Math.max(Be.to,ye.to),Be.n+=Se):H.push({key:ye.k,from:ye.from,to:ye.to,n:Se})}const ee=de.reduce((ye,Se)=>Math.max(ye,Se.to),0);return H.length>1&&H.some(ye=>ye.key)?{segs:H,last:ee}:null},[T,$.rows,_]),oe=(Me=e.description)==null?void 0:Me.text,he=t.jsx(Wn,{kind:p("collectionPage.kind"),title:u(e.title),byline:t.jsx($r,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(et,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(B=e.publication_info)!=null&&B.year?u(e.publication_info.year):""]}),description:oe||(te=e.history)!=null&&te.length?t.jsxs(t.Fragment,{children:[oe&&t.jsx(Tt,{text:oe,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((H,de)=>t.jsx("li",{children:u(H)},de))}):null]}):void 0,clampDescription:nr(oe)||(((Re=e.history)==null?void 0:Re.length)??0)>2?6:void 0,stats:Pe,facts:Ee,foot:t.jsx(On,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:le&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:p("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":p("collectionPage.dist.head"),children:le.segs.map((H,de)=>{const ee=An.find(ye=>ye.key===H.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!ee,title:ee?p("collectionPage.dist.segTitle",{section:u(ee.label),from:H.from,to:H.to}):void 0,"aria-label":ee?p("collectionPage.dist.only",{section:u(ee.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!ee&&b===H.key,style:{flexGrow:H.n,background:i(ee?ee.token:"rule")},onClick:()=>{ee&&(j(b===H.key?"":H.key),k(!1))}},de)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:p("catalog.volume",{n:1})}),t.jsx("span",{children:p("collectionPage.dist.hint")}),t.jsx("span",{children:p("catalog.volume",{n:le.last})})]})]})}),U=[];$.rows.length&&U.push({id:"titles",label:p("collectionPage.sec.titles"),count:Q}),V&&U.push({id:"resources",label:p("collectionPage.sec.resources"),count:V}),O&&U.push({id:"works",label:m.section.containedWorks,count:X.length});const $e=t.jsxs(t.Fragment,{children:[$.rows.length>0&&t.jsxs(tt,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(et,{items:[`${Q} ${m.unit.items}`,$.totalVolumes?p("collectionPage.totalVolumes",{n:$.totalVolumes,unit:m.unit.volume}):"",R.length!==Q?p("collectionPage.currentN",{n:R.length,unit:m.unit.items}):""]}),action:a,children:[($.rows.length>Tn||Z.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Z.length>0&&t.jsx($i,{items:Z,value:b,onChange:H=>{j(H),k(!1)}}),M&&$.rows.length>Tn&&!T&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>v(!0),title:p("collectionPage.loadAllTitle",{n:$.rows.length,unit:m.unit.items}),children:p(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),$.rows.length>Tn&&t.jsx("input",{type:"search",className:"bim-d-find",value:h,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:H=>{f(H.target.value),k(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Ci(R.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[G&&t.jsx("th",{style:{width:"8.5em"},children:p("collectionPage.col.volumes")}),t.jsx("th",{children:p("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:p("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:E.map((H,de)=>{var He;const ee=H.id?_.get(H.id):void 0,ye=ee!=null&&ee.title&&H.title===H.id?ee.title:H.title,Se=((ee==null?void 0:ee.authors)||[]).find(Ue=>Ue&&Ue.name),Be=[Se?`${Se.dynasty?`〔${u(Se.dynasty)}〕`:""}${u(Se.name)}${Se.role?` ${u(Se.role)}`:""}`:"",ee!=null&&ee.measure?u(ee.measure):"",(He=H.subItems)!=null&&He.length?H.subItems.map(Ue=>u(Ue)).join("、"):"",(ee!=null&&ee.edition||H.edition)&&!A?u((ee==null?void 0:ee.edition)||H.edition||""):""].filter(Boolean),De=An.find(Ue=>Ue.key===F(H.id)),Je=H.volumes.length>0?p("collectionPage.volumeRange",{range:_i(H.volumes,m.unit.volume),unit:m.unit.volume}):H.expected!=null?`${H.found??0}/${H.expected} ${m.unit.volume}`:"";return t.jsxs("tr",{children:[G&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Je?"":" bim-d-zt-blank"}`,children:[De&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(De.token)}}),Je||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[H.id?t.jsx(Xe,{id:H.id,label:u(ye),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(ye)}),Be.length>0?t.jsx(et,{items:Be}):H.id&&!ee&&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${ee!=null&&ee.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ee!=null&&ee.versionCount?p("collectionPage.nZhong",{n:ee.versionCount}):""})]},`${H.id??H.title}-${de}`)})})]}),E.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:p("catalog.noMatch")}),!x&&t.jsx(er,{total:R.length,shown:E.length,unit:m.unit.items,onClick:()=>k(!0)})]}),V>0&&t.jsxs(tt,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:V}),children:[P.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[P.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:p("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:P.text.map((H,de)=>t.jsx(Cr,{item:H,siblings:P.text},`${H.id||H.url||H.name}-${de}`))})})]}),t.jsx(Pc,{groups:P.groups})]}),$.rows.length===0&&V===0&&t.jsx(tt,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),me=O?t.jsx(Yt,{id:"works",title:m.section.containedWorks,meta:p("collectionPage.nZhong",{n:X.length}),cap:12,items:X.map(H=>t.jsx(Xe,{id:H.id,label:u(H.title),onNavigate:r,renderLink:s,dense:!0}))}):null,Ce=y?t.jsx(Al,{caption:p("collectionPage.parent"),children:t.jsx(Xe,{id:y.id,label:u(y.title||y.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Bn,{railTop:l,back:d,up:Ce,nav:U,railLinks:c,main:$e,card:he,side:me})},nb=16,ro=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function ja(e){if(!e)return ro.length;const n=ro.indexOf(e);return n===-1?ro.length:n}function ib(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const ob={秦:[-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]},Dc=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:a,railLinks:l})=>{var me,Ce,Y,ze,Me;const{t:d,convert:c,messages:p}=J(),u=B=>ib(B,d),[m,h]=g.useState("全部"),[f,x]=g.useState(!1),[k,y]=g.useState("default"),[w,b]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(B=>{const te=w.get(B.work_id);return{id:B.work_id,title:(te==null?void 0:te.title)??B.title??B.work_id,role:B.role||"",cls:Jo(B.role),versionCount:te==null?void 0:te.versionCount,section:te==null?void 0:te.cls,l1:te==null?void 0:te.l1,measure:te==null?void 0:te.measure,hasImage:te==null?void 0:te.hasImage,loaded:!!(te!=null&&te.loaded)}}),[e.works,w]),S=g.useMemo(()=>Rl((e.works||[]).map(B=>B.role),d("detail.roleAll")),[e.works,d]),v=g.useMemo(()=>{const B=m==="全部"?j:j.filter(te=>te.cls===m);return k==="versions"?[...B].sort((te,xe)=>(xe.versionCount??-1)-(te.versionCount??-1)):B},[j,m,k]),$=f?v:v.slice(0,nb),_=g.useMemo(()=>$.filter(B=>!w.has(B.id)).map(B=>B.id),[$,w]);g.useEffect(()=>{if(!n||_.length===0)return;let B=!1;return Promise.all(_.map(te=>n.getItem(te).then(xe=>{var ee,ye,Se,Be,De;const Re=xe??{},H=Re._edition_count??(((ee=Re.books)==null?void 0:ee.length)??0)+(((ye=Re.collections)==null?void 0:ye.length)??0),de=[(Se=Re.classification)==null?void 0:Se.l1,(Be=Re.classification)==null?void 0:Be.l2].filter(Boolean).join(" ");return[te,{id:te,title:Re.title,versionCount:H,loaded:!0,cls:de||void 0,l1:((De=Re.classification)==null?void 0:De.l1)||void 0,measure:xe&&Nt(xe,p.unit.juan)||void 0,hasImage:!!(Re.has_image??Re._has_image)}]}).catch(()=>[te,{id:te,loaded:!0}]))).then(te=>{B||b(xe=>{const Re=new Map(xe);for(const[H,de]of te)Re.set(H,de);return Re})}),()=>{B=!0}},[n,_,p.unit.juan]);const C=g.useMemo(()=>{const B=new Map;for(const te of e.alt_names||[]){const xe=te.type||p.section.aliases;B.has(xe)||B.set(xe,[]),B.get(xe).push(te.name)}return[...B.entries()].sort((te,xe)=>ja(te[0])-ja(xe[0])).map(([te,xe])=>({label:te,names:xe}))},[e.alt_names,p]),M=e.birth_year??((me=e.dates)==null?void 0:me.birth)??void 0,N=e.death_year??((Ce=e.dates)==null?void 0:Ce.death)??void 0,T=(Y=e.dates)==null?void 0:Y.floruit,F=M!=null||N!=null?`${u(M)||"?"}—${u(N)||"?"}`:Array.isArray(T)&&T.length===2&&T.every(B=>Number.isFinite(B))?d("entityPage.floruit",{from:u(T[0]),to:u(T[1])}):"",R=new Set(["本名","字","號","号"]),E=C.filter(B=>R.has(B.label)),L=C.filter(B=>!R.has(B.label)),I=L.reduce((B,te)=>B+te.names.length,0),P=g.useMemo(()=>{const B=[];for(const xe of E)B.push({label:xe.label,value:xe.names.map(Re=>c(Re)).join("、")});const te=(e.works||[]).length;return te&&B.push({label:d("entityPage.fact.works"),value:d("entityPage.nZhong",{n:te})}),B},[e.works,E,c,d]),V=B=>{var te;return(te=C.find(xe=>B.includes(xe.label)))==null?void 0:te.names[0]},X=V(["字"]),D=V(["號","号"]),O=[X?d("entityPage.zi",{name:c(X)}):"",D?d("entityPage.hao",{name:c(D)}):""].filter(Boolean).join(","),A=e.native_place,G=e.dynasty?ob[e.dynasty]:void 0,se=(()=>{if(!G||M==null||N==null||N<M)return null;const[B,te]=G,xe=Math.max(M,B),Re=Math.min(N,te);if(Re<=xe)return null;const H=te-B;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":d("entityPage.lifeAria",{birth:u(M),death:u(N),years:N-M+1}),children:t.jsx("i",{style:{left:`${(xe-B)/H*100}%`,width:`${(Re-xe)/H*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${u(B)} ${c(e.dynasty)}`}),t.jsx("span",{children:d("entityPage.lifeYears",{years:N-M+1})}),t.jsx("span",{children:u(te)})]})]})})(),Q=g.useMemo(()=>{if(!n||j.length===0||j.some(xe=>!xe.loaded))return null;const B=new Map;for(const xe of j){const Re=No(xe.l1);Re&&B.set(Re,(B.get(Re)??0)+1)}const te=An.map(xe=>({...xe,n:B.get(xe.key)??0})).filter(xe=>xe.n>0);return te.length?te:null},[j,n]),ve=t.jsxs(Wn,{kind:p.entityPage.subtype[e.subtype]??d("entityPage.subtype.people"),title:c(e.primary_name||e.title),subtitle:O||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(et,{items:[e.dynasty?c(e.dynasty):"",F,A?d("entityPage.nativePlace",{place:c(A)}):""]}),se]}),description:(ze=e.description)!=null&&ze.text?t.jsx(Tt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:nr((Me=e.description)==null?void 0:Me.text)?6:void 0,facts:P,foot:t.jsx(On,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[I>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:d("entityPage.moreNames",{n:I})}),t.jsx("dl",{children:L.map(B=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:c(B.label)}),t.jsx("dd",{children:B.names.map(te=>c(te)).join("、")})]},B.label))})]}),Q&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:d("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:Q.map(B=>t.jsx("i",{style:{flexGrow:B.n,background:i(B.token)}},B.key))}),t.jsx("div",{className:"bim-d-dist-key",children:Q.map(B=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(B.token)}}),c(B.label)," ",B.n]},B.key))})]})]}),ne=g.useMemo(()=>j.filter(B=>B.loaded&&(B.versionCount??0)>0).sort((B,te)=>(te.versionCount??0)-(B.versionCount??0)).slice(0,3),[j]),ce=!!n&&j.length>=3&&$.some(B=>!B.loaded),We=m==="全部"&&(ce||ne.length>=2),ke=e.external_ids||{},Pe=[];ke.cbdb_id!=null&&Pe.push({label:"CBDB",id:String(ke.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ke.cbdb_id}`,note:ke.cbdb_match==="auto"?d("entityPage.autoMatch"):void 0});const Ee=ke.wikidata_id;Ee&&Pe.push({label:"Wikidata",id:Ee,href:`https://www.wikidata.org/wiki/${Ee}`});const Z=ke.viaf_id;Z&&Pe.push({label:"VIAF",id:Z,href:`https://viaf.org/viaf/${Z}`});const le=S.map(B=>({key:B.cls,label:`${B.label} ${B.count}`})),oe=[...We&&!ce?[{id:"featured",label:d("entityPage.sec.featured"),count:ne.length}]:[],...j.length?[{id:"works",label:d("entityPage.sec.allWorks"),count:j.length}]:[],...Pe.length?[{id:"external",label:d("entityPage.sec.external"),count:Pe.length}]:[]],he=We?t.jsxs(tt,{id:"featured",title:d("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:d("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":ce||void 0,children:[ce&&[0,1,2].map(B=>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:" "})]},B)),!ce&&ne.map(B=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(Xe,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(et,{items:[B.section?c(B.section):"",B.measure?c(B.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:B.versionCount}),t.jsx("span",{children:d("entityPage.versionsUnit")}),B.hasImage&&t.jsx("span",{className:"bim-d-flag",children:d("entityPage.hasImage")})]})]},B.id))]})]}):null,U=j.length===0?t.jsx(tt,{title:d("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("entityPage.empty")})}):t.jsxs(t.Fragment,{children:[he,t.jsxs(tt,{id:"works",title:d("entityPage.sec.works"),meta:t.jsx(et,{items:[d("entityPage.total",{n:j.length}),v.length!==j.length?d("entityPage.current",{n:v.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[le.length>1&&t.jsx($i,{items:le,value:m,onChange:B=>{h(B),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":k==="versions",onClick:()=>{k==="default"&&x(!0),y(B=>B==="default"?"versions":"default")},children:d(k==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!f&&Ci(v.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("entityPage.col.work")}),t.jsx("th",{children:d("entityPage.col.section")}),t.jsx("th",{children:d("entityPage.col.role")}),t.jsx("th",{children:d("entityPage.col.versions")}),t.jsx("th",{"aria-label":d("entityPage.col.image")})]})}),t.jsx("tbody",{children:$.map(B=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(Xe,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0}),B.measure?t.jsx(et,{items:[c(B.measure)]}):!B.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${B.section||B.loaded?"":" bim-d-zt-blank"}`,children:B.section?c(B.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.role?"":" bim-d-zt-blank"}`,children:B.role?c(B.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.loaded?"":" bim-d-zt-blank"}`,children:B.loaded?B.versionCount?d("entityPage.nZhong",{n:B.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:d("entityPage.notRecorded")}):""}),t.jsx("td",{className:B.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:B.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:d("entityPage.hasImage")})})]},B.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d("entityPage.emptyRole")}),!f&&t.jsx(er,{total:v.length,shown:$.length,unit:d("entityPage.moreUnit"),onClick:()=>x(!0)})]})]}),$e=Pe.length>0?t.jsx(Yt,{id:"external",title:d("entityPage.sec.external"),items:Pe.map(B=>t.jsxs("a",{href:B.href,target:"_blank",rel:"noopener noreferrer",children:[B.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Pe.map(B=>B.id),foot:ke.cbdb_id!=null&&ke.cbdb_match==="auto"?d("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Bn,{railTop:s,back:a,nav:oe,railLinks:l,main:U,card:ve,side:$e})},Tr="(max-width: 719px)",rb=`${Tr}, (pointer: coarse)`,Uc=`
1304
1306
  .bim-ct {
1305
1307
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
1306
1308
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -1408,7 +1410,7 @@ ${ie??""}`,[Jt,fn]=g.useState({key:Wt,data:me,started:!!me});if(Jt.key!==Wt)fn({
1408
1410
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1409
1411
  }
1410
1412
 
1411
- @media ${Cr} {
1413
+ @media ${Tr} {
1412
1414
  .bim-ct { display: block; padding: 12px 16px 40px; }
1413
1415
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
1414
1416
  .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
@@ -1433,7 +1435,7 @@ ${ie??""}`,[Jt,fn]=g.useState({key:Wt,data:me,started:!!me});if(Jt.key!==Wt)fn({
1433
1435
  }
1434
1436
 
1435
1437
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
1436
- @media ${ib} {
1438
+ @media ${rb} {
1437
1439
  .bim-ct-row { min-height: 44px; }
1438
1440
  .bim-ct-tw { width: 44px; }
1439
1441
  .bim-ct-pg { min-width: 44px; height: 44px; }
@@ -1459,7 +1461,7 @@ ${ie??""}`,[Jt,fn]=g.useState({key:Wt,data:me,started:!!me});if(Jt.key!==Wt)fn({
1459
1461
  /* 窄屏分类抽屉:界栏下按钮和面板都有框 */
1460
1462
  :root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${i("fr-bd")}; background: ${i("fr-bg")}; }
1461
1463
  :root[data-layout="boxed"] .bim-ct-drawer { border: ${i("fr-bd")}; }
1462
- `,Vt="未分類",zt="all",zr=20;function On(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 ob(e){const n=On(e);return n.length?n.join("/"):Vt}function rb(e){const n=On(e);return n.length?n.map((o,r)=>n.slice(0,r+1).join("/")):[Vt]}function sb(e,n=[]){const o=new Map;n.forEach((d,c)=>{const p=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(u=>!!u);p.forEach((u,m)=>{const h=p.slice(0,m+1).join("/");o.has(h)||o.set(h,c)})});const r=new Map;let s=0;for(const d of e){const c=On(d.classification);if(!c.length){s++;continue}let p=r;c.forEach((u,m)=>{const h=c.slice(0,m+1).join("/");let f=p.get(u);f||(f={id:h,label:u,count:0,children:new Map},p.set(u,f)),f.count++,p=f.children})}const a=d=>[...d.values()].sort((c,p)=>{const u=c.label===Vt?1:0,m=p.label===Vt?1:0;if(u!==m)return u-m;const h=o.get(c.id)??1/0,f=o.get(p.id)??1/0;return h!==f?h-f:c.label.localeCompare(p.label,"zh")}).map(c=>{const p={id:c.id,label:c.label,count:c.count};return c.children.size&&(p.children=a(c.children)),p}),l=a(r);return s>0&&l.push({id:Vt,label:Vt,count:s}),l}function sn(e,n){if(!n)return[];for(const o of e){if(o.id===n)return[o];if(o.children){const r=sn(o.children,n);if(r.length)return[o,...r]}}return[]}function Tr(e){return e.reduce((n,o)=>n+o.count,0)}function ab(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function lb(e){var d;const n={id:e.id,title:e.title||e.id},o=e.juan_count,r=typeof o=="number"?o:o==null?void 0:o.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const p=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return p?{name:c.name,dynasty:p}:{name:c.name}});s.length&&(n.authors=s);const a=ab(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);a&&(n.summary=a);const l=On(e.classification);return l.length&&(n.classification=l),n}function cb(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 db(e,n=zr){return Math.max(1,Math.ceil(e/n))}function Dc(e,n,o=2){if(n<=1)return[1];const r=new Set([1,n]);for(let l=e-o;l<=e+o;l++)l>=1&&l<=n&&r.add(l);const s=[...r].sort((l,d)=>l-d),a=[];return s.forEach((l,d)=>{if(d>0){const c=l-s[d-1];c===2?a.push(l-1):c>2&&a.push(null)}a.push(l)}),a}const pb=()=>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 ub(e,n,o){const r=[];o&&r.push({id:zt,parentId:null,hasChildren:!1,firstChildId:null});const s=(a,l)=>{var d;for(const c of a){const p=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:l,hasChildren:!!p,firstChildId:p?p[0].id:null}),p&&n.has(c.id)&&s(p,c.id)}};return s(e,null),r}function Uc({tree:e,selectedId:n,onSelect:o,allLabel:r,label:s}){const{t:a,convert:l}=J(),d=r===void 0?a("catalogPage.all"):r,c=s??a("catalogPage.classification"),p=g.useRef(null),u=n&&n!==zt?n:null,m=d!==null,[h,f]=g.useState(()=>{const C=new Set;for(const M of sn(e,u))C.add(M.id);return C});g.useEffect(()=>{const C=sn(e,u);C.length&&f(M=>{if(C.every(z=>M.has(z.id)))return M;const T=new Set(M);for(const z of C)T.add(z.id);return T})},[e,u]);const x=g.useMemo(()=>ub(e,h,m),[e,h,m]),[k,y]=g.useState(null);g.useEffect(()=>{y(null)},[n]);const w=u??(m?zt:null),b=g.useMemo(()=>{var T;const C=new Set(x.map(z=>z.id));if(k&&C.has(k))return k;if(w&&C.has(w))return w;const M=sn(e,u).map(z=>z.id).filter(z=>C.has(z));return M.length?M[M.length-1]:((T=x[0])==null?void 0:T.id)??null},[x,k,w,e,u]),j=g.useCallback((C,M)=>{f(T=>{const z=T.has(C),H=M??!z;if(H===z)return T;const N=new Set(T);return H?N.add(C):N.delete(C),N})},[]),S=g.useCallback(C=>{y(C),requestAnimationFrame(()=>{var T;const M=Array.from(((T=p.current)==null?void 0:T.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===C);M==null||M.focus()})},[]),v=g.useCallback((C,M)=>{M&&j(C,!0),o(C)},[o,j]),$=g.useCallback(C=>{const M=C.target.closest("[data-ct-id]");if(!M)return;const T=M.dataset.ctId,z=x.findIndex(I=>I.id===T);if(z<0)return;const H=x[z];let N=null;switch(C.key){case"ArrowDown":N=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":N=x[Math.max(0,z-1)].id;break;case"Home":N=x[0].id;break;case"End":N=x[x.length-1].id;break;case"ArrowRight":if(!H.hasChildren)break;h.has(T)?N=H.firstChildId:j(T,!0);break;case"ArrowLeft":H.hasChildren&&h.has(T)?j(T,!1):N=H.parentId;break;case"Enter":case" ":C.preventDefault(),v(T,H.hasChildren);return;default:return}C.preventDefault(),N&&N!==T&&S(N)},[x,h,j,S,v]),_=(C,M)=>C.map((T,z)=>{var R;const H=(R=T.children)!=null&&R.length?T.children:null,N=!!H&&h.has(T.id),I=T.id===u,L=M===1&&C.length>1&&z===C.length-1;return t.jsxs("li",{role:"treeitem","aria-level":M,"aria-expanded":H?N:void 0,"aria-selected":I,tabIndex:b===T.id?0:-1,"data-ct-id":T.id,className:L?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":M-1},onClick:()=>{y(T.id),v(T.id,!!H)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:H?P=>{P.stopPropagation(),y(T.id),j(T.id)}:void 0,children:H?t.jsx(pb,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(T.label)}),t.jsx("span",{className:"bim-ct-n",children:T.count.toLocaleString("en-US")})]}),N&&t.jsx("ul",{role:"group",children:_(H,M+1)})]},T.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:$,children:[m&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!u,tabIndex:b===zt?0:-1,"data-ct-id":zt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{y(zt),o(zt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(d)}),t.jsx("span",{className:"bim-ct-n",children:Tr(e).toLocaleString("en-US")})]})}),_(e,1)]})}const Vc=e=>`/item/${encodeURIComponent(e)}`;function mb(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Gc(e,n){return e==null||e===""?null:typeof e=="number"?n("catalogPage.juanN",{n:e}):e}function Yc({work:e,href:n}){var d,c;const{t:o,convert:r}=J(),s=Gc(e.juan,o),a=((d=e.authors)==null?void 0:d.filter(p=>p.name))??[],l=((c=e.classification)==null?void 0:c.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:r(e.title)}),s&&t.jsx("span",{className:"bim-ct-juan",children:r(s)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((p,u)=>t.jsxs(g.Fragment,{children:[u>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(p.dynasty),"〕"]}),r(p.name)]},u))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:r(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>r(p)).join(" · ")})]})})}function Kc({work:e,href:n}){var d,c;const{t:o,convert:r}=J(),s=Gc(e.juan,o),a=((d=e.authors)==null?void 0:d.filter(p=>p.name))??[],l=((c=e.classification)==null?void 0:c.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:[r(e.title),s&&t.jsx("span",{className:"bim-ct-juan",children:r(s)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((p,u)=>t.jsxs(g.Fragment,{children:[u>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(p.dynasty),"〕"]}),r(p.name)]},u))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>r(p)).join(" · ")})]})})}function qc({page:e,pageCount:n,onPage:o,pageHref:r,label:s}){const{t:a,convert:l}=J();if(n<=1)return null;const d=p=>u=>{o&&(r&&!mb(u)||(u.preventDefault(),o(p)))},c=(p,u,m)=>{if(m.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:u});const h={className:"bim-ct-pg","aria-current":m.current?"page":void 0,"aria-label":m.aria};return r?t.jsx("a",{...h,href:r(p),onClick:d(p),children:u}):t.jsx("button",{type:"button",...h,onClick:m.current?void 0:d(p),children:u})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":s?l(s):a("catalogPage.pagerLabel"),children:[c(e-1,a("catalogPage.prevPage"),{disabled:e<=1}),t.jsx("ol",{children:Dc(e,n).map((p,u)=>t.jsx("li",{style:{display:"contents"},children:p===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):c(p,p,{current:p===e,aria:a("catalogPage.pageN",{n:p})})},p??`gap${u}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=n})]})}function Xc({works:e,workLink:n=Vc,emptyText:o,view:r="card",...s}){const{t:a,convert:l}=J();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:o===void 0?a("catalogPage.emptyWorks"):typeof o=="string"?l(o):o}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Kc,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Yc,{work:d,href:n(d.id)},d.id))}),t.jsx(qc,{...s})]})}const hb=()=>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 gb({tree:e,selectedId:n,page:o,pageCount:r,works:s,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:p,allLabel:u,allTitle:m,pageSize:h=zr,className:f,view:x,onViewChange:k}){const{t:y,convert:w}=J(),b=u===void 0?y("catalogPage.all"):u,j=m??y("catalogPage.allTitle"),v=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[$,_]=g.useState(!1),[C,M]=g.useState("card"),T=x??C,z=P=>{M(P),k==null||k(P)},H=sn(e,n&&n!==zt?n:null),N=H.length?H[H.length-1]:null,I=N?N.label:j,L=N?N.count:Tr(e),R=g.useCallback(P=>{_(!1),a(P)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":$?"open":"closed",children:[t.jsx("style",{children:Fc}),t.jsxs("aside",{className:"bim-ct-side","aria-label":y("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":$,"aria-controls":v,onClick:()=>_(P=>!P),children:[t.jsx("span",{children:y("catalogPage.drawerLabel",{path:w(H.length?H.map(P=>P.label).join(" › "):b??j)})}),t.jsx(hb,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:v,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("catalogPage.classification")}),t.jsx(Uc,{tree:e,selectedId:n,onSelect:R,allLabel:b})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:w(I)}),H.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:w(H.slice(0,-1).map(P=>P.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y("catalogPage.stat",{total:L.toLocaleString("en-US"),size:h}),r>1&&y("catalogPage.statPage",{page:o,pages:r})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":T==="card",onClick:()=>z("card"),children:y("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":T==="list",onClick:()=>z("list"),children:y("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Xc,{works:s,view:T,workLink:c,page:o,pageCount:r,onPage:l,pageHref:p})]})]})}const Hn="(max-width: 719px)",fb="(max-width: 1079px)",xb=`${Hn}, (pointer: coarse)`,bb=[8,18,30,42,88],Nr=`
1464
+ `,Gt="未分類",Ct="all",Nr=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 sb(e){const n=Fn(e);return n.length?n.join("/"):Gt}function ab(e){const n=Fn(e);return n.length?n.map((o,r)=>n.slice(0,r+1).join("/")):[Gt]}function lb(e,n=[]){const o=new Map;n.forEach((d,c)=>{const p=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(u=>!!u);p.forEach((u,m)=>{const h=p.slice(0,m+1).join("/");o.has(h)||o.set(h,c)})});const r=new Map;let s=0;for(const d of e){const c=Fn(d.classification);if(!c.length){s++;continue}let p=r;c.forEach((u,m)=>{const h=c.slice(0,m+1).join("/");let f=p.get(u);f||(f={id:h,label:u,count:0,children:new Map},p.set(u,f)),f.count++,p=f.children})}const a=d=>[...d.values()].sort((c,p)=>{const u=c.label===Gt?1:0,m=p.label===Gt?1:0;if(u!==m)return u-m;const h=o.get(c.id)??1/0,f=o.get(p.id)??1/0;return h!==f?h-f:c.label.localeCompare(p.label,"zh")}).map(c=>{const p={id:c.id,label:c.label,count:c.count};return c.children.size&&(p.children=a(c.children)),p}),l=a(r);return s>0&&l.push({id:Gt,label:Gt,count:s}),l}function an(e,n){if(!n)return[];for(const o of e){if(o.id===n)return[o];if(o.children){const r=an(o.children,n);if(r.length)return[o,...r]}}return[]}function Rr(e){return e.reduce((n,o)=>n+o.count,0)}function cb(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function db(e){var d;const n={id:e.id,title:e.title||e.id},o=e.juan_count,r=typeof o=="number"?o:o==null?void 0:o.number;typeof r=="number"&&r>0?n.juan=r:e.measure_info&&(n.juan=e.measure_info);const s=(e.authors??[]).filter(c=>c==null?void 0:c.name).map(c=>{const p=c.dynasty||(e.authors.length===1?e.dynasty:void 0);return p?{name:c.name,dynasty:p}:{name:c.name}});s.length&&(n.authors=s);const a=cb(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);a&&(n.summary=a);const l=Fn(e.classification);return l.length&&(n.classification=l),n}function pb(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 ub(e,n=Nr){return Math.max(1,Math.ceil(e/n))}function Vc(e,n,o=2){if(n<=1)return[1];const r=new Set([1,n]);for(let l=e-o;l<=e+o;l++)l>=1&&l<=n&&r.add(l);const s=[...r].sort((l,d)=>l-d),a=[];return s.forEach((l,d)=>{if(d>0){const c=l-s[d-1];c===2?a.push(l-1):c>2&&a.push(null)}a.push(l)}),a}const mb=()=>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 hb(e,n,o){const r=[];o&&r.push({id:Ct,parentId:null,hasChildren:!1,firstChildId:null});const s=(a,l)=>{var d;for(const c of a){const p=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:l,hasChildren:!!p,firstChildId:p?p[0].id:null}),p&&n.has(c.id)&&s(p,c.id)}};return s(e,null),r}function Gc({tree:e,selectedId:n,onSelect:o,allLabel:r,label:s}){const{t:a,convert:l}=J(),d=r===void 0?a("catalogPage.all"):r,c=s??a("catalogPage.classification"),p=g.useRef(null),u=n&&n!==Ct?n:null,m=d!==null,[h,f]=g.useState(()=>{const C=new Set;for(const M of an(e,u))C.add(M.id);return C});g.useEffect(()=>{const C=an(e,u);C.length&&f(M=>{if(C.every(T=>M.has(T.id)))return M;const N=new Set(M);for(const T of C)N.add(T.id);return N})},[e,u]);const x=g.useMemo(()=>hb(e,h,m),[e,h,m]),[k,y]=g.useState(null);g.useEffect(()=>{y(null)},[n]);const w=u??(m?Ct:null),b=g.useMemo(()=>{var N;const C=new Set(x.map(T=>T.id));if(k&&C.has(k))return k;if(w&&C.has(w))return w;const M=an(e,u).map(T=>T.id).filter(T=>C.has(T));return M.length?M[M.length-1]:((N=x[0])==null?void 0:N.id)??null},[x,k,w,e,u]),j=g.useCallback((C,M)=>{f(N=>{const T=N.has(C),F=M??!T;if(F===T)return N;const R=new Set(N);return F?R.add(C):R.delete(C),R})},[]),S=g.useCallback(C=>{y(C),requestAnimationFrame(()=>{var N;const M=Array.from(((N=p.current)==null?void 0:N.querySelectorAll("[data-ct-id]"))??[]).find(T=>T.dataset.ctId===C);M==null||M.focus()})},[]),v=g.useCallback((C,M)=>{M&&j(C,!0),o(C)},[o,j]),$=g.useCallback(C=>{const M=C.target.closest("[data-ct-id]");if(!M)return;const N=M.dataset.ctId,T=x.findIndex(E=>E.id===N);if(T<0)return;const F=x[T];let R=null;switch(C.key){case"ArrowDown":R=x[Math.min(x.length-1,T+1)].id;break;case"ArrowUp":R=x[Math.max(0,T-1)].id;break;case"Home":R=x[0].id;break;case"End":R=x[x.length-1].id;break;case"ArrowRight":if(!F.hasChildren)break;h.has(N)?R=F.firstChildId:j(N,!0);break;case"ArrowLeft":F.hasChildren&&h.has(N)?j(N,!1):R=F.parentId;break;case"Enter":case" ":C.preventDefault(),v(N,F.hasChildren);return;default:return}C.preventDefault(),R&&R!==N&&S(R)},[x,h,j,S,v]),_=(C,M)=>C.map((N,T)=>{var I;const F=(I=N.children)!=null&&I.length?N.children:null,R=!!F&&h.has(N.id),E=N.id===u,L=M===1&&C.length>1&&T===C.length-1;return t.jsxs("li",{role:"treeitem","aria-level":M,"aria-expanded":F?R:void 0,"aria-selected":E,tabIndex:b===N.id?0:-1,"data-ct-id":N.id,className:L?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":M-1},onClick:()=>{y(N.id),v(N.id,!!F)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:F?P=>{P.stopPropagation(),y(N.id),j(N.id)}:void 0,children:F?t.jsx(mb,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(N.label)}),t.jsx("span",{className:"bim-ct-n",children:N.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:_(F,M+1)})]},N.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:$,children:[m&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!u,tabIndex:b===Ct?0:-1,"data-ct-id":Ct,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{y(Ct),o(Ct)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(d)}),t.jsx("span",{className:"bim-ct-n",children:Rr(e).toLocaleString("en-US")})]})}),_(e,1)]})}const Yc=e=>`/item/${encodeURIComponent(e)}`;function gb(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Kc(e,n){return e==null||e===""?null:typeof e=="number"?n("catalogPage.juanN",{n:e}):e}function qc({work:e,href:n}){var d,c;const{t:o,convert:r}=J(),s=Kc(e.juan,o),a=((d=e.authors)==null?void 0:d.filter(p=>p.name))??[],l=((c=e.classification)==null?void 0:c.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:r(e.title)}),s&&t.jsx("span",{className:"bim-ct-juan",children:r(s)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((p,u)=>t.jsxs(g.Fragment,{children:[u>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(p.dynasty),"〕"]}),r(p.name)]},u))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:r(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>r(p)).join(" · ")})]})})}function Xc({work:e,href:n}){var d,c;const{t:o,convert:r}=J(),s=Kc(e.juan,o),a=((d=e.authors)==null?void 0:d.filter(p=>p.name))??[],l=((c=e.classification)==null?void 0:c.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:[r(e.title),s&&t.jsx("span",{className:"bim-ct-juan",children:r(s)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((p,u)=>t.jsxs(g.Fragment,{children:[u>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(p.dynasty),"〕"]}),r(p.name)]},u))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>r(p)).join(" · ")})]})})}function Zc({page:e,pageCount:n,onPage:o,pageHref:r,label:s}){const{t:a,convert:l}=J();if(n<=1)return null;const d=p=>u=>{o&&(r&&!gb(u)||(u.preventDefault(),o(p)))},c=(p,u,m)=>{if(m.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:u});const h={className:"bim-ct-pg","aria-current":m.current?"page":void 0,"aria-label":m.aria};return r?t.jsx("a",{...h,href:r(p),onClick:d(p),children:u}):t.jsx("button",{type:"button",...h,onClick:m.current?void 0:d(p),children:u})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":s?l(s):a("catalogPage.pagerLabel"),children:[c(e-1,a("catalogPage.prevPage"),{disabled:e<=1}),t.jsx("ol",{children:Vc(e,n).map((p,u)=>t.jsx("li",{style:{display:"contents"},children:p===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):c(p,p,{current:p===e,aria:a("catalogPage.pageN",{n:p})})},p??`gap${u}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=n})]})}function Jc({works:e,workLink:n=Yc,emptyText:o,view:r="card",...s}){const{t:a,convert:l}=J();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:o===void 0?a("catalogPage.emptyWorks"):typeof o=="string"?l(o):o}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Xc,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(qc,{work:d,href:n(d.id)},d.id))}),t.jsx(Zc,{...s})]})}const fb=()=>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 xb({tree:e,selectedId:n,page:o,pageCount:r,works:s,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:p,allLabel:u,allTitle:m,pageSize:h=Nr,className:f,view:x,onViewChange:k}){const{t:y,convert:w}=J(),b=u===void 0?y("catalogPage.all"):u,j=m??y("catalogPage.allTitle"),v=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[$,_]=g.useState(!1),[C,M]=g.useState("card"),N=x??C,T=P=>{M(P),k==null||k(P)},F=an(e,n&&n!==Ct?n:null),R=F.length?F[F.length-1]:null,E=R?R.label:j,L=R?R.count:Rr(e),I=g.useCallback(P=>{_(!1),a(P)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":$?"open":"closed",children:[t.jsx("style",{children:Uc}),t.jsxs("aside",{className:"bim-ct-side","aria-label":y("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":$,"aria-controls":v,onClick:()=>_(P=>!P),children:[t.jsx("span",{children:y("catalogPage.drawerLabel",{path:w(F.length?F.map(P=>P.label).join(" › "):b??j)})}),t.jsx(fb,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:v,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("catalogPage.classification")}),t.jsx(Gc,{tree:e,selectedId:n,onSelect:I,allLabel:b})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:w(E)}),F.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:w(F.slice(0,-1).map(P=>P.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y("catalogPage.stat",{total:L.toLocaleString("en-US"),size:h}),r>1&&y("catalogPage.statPage",{page:o,pages:r})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":N==="card",onClick:()=>T("card"),children:y("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":N==="list",onClick:()=>T("list"),children:y("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Jc,{works:s,view:N,workLink:c,page:o,pageCount:r,onPage:l,pageHref:p})]})]})}const Dn="(max-width: 719px)",bb="(max-width: 1079px)",yb=`${Dn}, (pointer: coarse)`,jb=[8,18,30,42,88],Er=`
1463
1465
  .bim-rh { color: ${i("ink")}; font-family: ${i("font-ui")}; font-size: 14px; line-height: 1.6; }
1464
1466
  .bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
1465
1467
  .bim-rh a { color: ${i("accent")}; text-decoration: none; }
@@ -1607,7 +1609,7 @@ ${ie??""}`,[Jt,fn]=g.useState({key:Wt,data:me,started:!!me});if(Jt.key!==Wt)fn({
1607
1609
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
1608
1610
  color: ${i("ink")} !important; font-size: 13px;
1609
1611
  }
1610
- ${bb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb, ${i("accent")} ${e}%, ${i("card-bg")}); }`).join(`
1612
+ ${jb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb, ${i("accent")} ${e}%, ${i("card-bg")}); }`).join(`
1611
1613
  `)}
1612
1614
  .bim-rh-band a[data-k="4"] { color: ${i("page-bg")} !important; }
1613
1615
  .bim-rh-band a:hover { outline: 2px solid ${i("ink")}; outline-offset: -2px; }
@@ -1635,13 +1637,13 @@ ${bb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1635
1637
  }
1636
1638
 
1637
1639
  /* ── 中屏 ── */
1638
- @media ${fb} {
1640
+ @media ${bb} {
1639
1641
  .bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1640
1642
  .bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
1641
1643
  }
1642
1644
 
1643
1645
  /* ── 手机 ── */
1644
- @media ${Hn} {
1646
+ @media ${Dn} {
1645
1647
  .bim-rh-main { padding-top: 24px; }
1646
1648
  .bim-rh-stats { gap: 4px 18px; }
1647
1649
  .bim-rh-stats b { font-size: 16px; }
@@ -1678,7 +1680,7 @@ ${bb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1678
1680
  }
1679
1681
 
1680
1682
  /* 触屏或窄屏:点击目标放大到 44px */
1681
- @media ${xb} {
1683
+ @media ${yb} {
1682
1684
  .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; }
1683
1685
  .bim-rh-chip { display: inline-flex; }
1684
1686
  }
@@ -1689,7 +1691,7 @@ ${bb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1689
1691
  }
1690
1692
 
1691
1693
  @media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
1692
- `,yb=Ro["zh-Hant"].period,Zc={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function Mt(e){return{...Zc,...e??{}}}function Er(e){var o;const n=(o=e.authors)==null?void 0:o.find(r=>r==null?void 0:r.name);return n?n.dynasty?`${n.dynasty} ${n.name}`:n.name:""}function zi(e){return(e.authors??[]).filter(o=>o==null?void 0:o.name).map(o=>o.dynasty?`〔${o.dynasty}〕${o.name}`:o.name).join(" ")}function Jc(e,n=Ro["zh-Hant"].shelfOther){var s;const o=[],r=new Map;for(const a of e){const l=((s=a.period_of)==null?void 0:s.trim())||n;let d=r.get(l);d||(d={label:l,items:[]},r.set(l,d),o.push(d)),d.items.push(a)}return o}function Qc(e){return Math.max(150,Array.from(e).length*18+44)}function ed(e,n){if(n<=0||e<=0)return 0;const o=e/n;return o<.15?0:o<.35?1:o<.6?2:o<.85?3:4}const td=.04;function Ye(e){return e.toLocaleString("en-US")}function nd({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((n,o)=>t.jsx("span",{children:n},o))})}function st({id:e,title:n,sub:o,more:r,children:s}){const{convert:a}=J(),l=`${e}-h`;return t.jsxs("section",{className:"bim-rh-sec",id:e,"aria-labelledby":l,children:[t.jsxs("div",{className:"bim-rh-hd",children:[t.jsx("h2",{id:l,children:a(n)}),o&&t.jsx("span",{className:"bim-rh-sub",children:o}),r]}),t.jsx("div",{className:"bim-rh-bd",children:s})]})}function id({counts:e}){const{t:n}=J();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:Ye(e.readable)}),n("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:Ye(e.pieces)}),n("readHome.pieces")]})]})}function od({picks:e,links:n}){const{t:o,convert:r}=J(),s=Mt(n);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=zi(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:s.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(nd,{text:r(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:r(d)}),t.jsx("h3",{children:r(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:r(l)}),a.blurb&&t.jsx("p",{children:r(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:o("readHome.startReading")})]})]})},a.id)})}):null}function rd(e,n){return e&&e>1?n("readHome.nCopies",{n:e}):null}function Ir({topic:e,links:n,hint:o,legendCount:r,showTitle:s=!0,legendExtra:a}){const{t:l,convert:d}=J(),c=Mt(n);if(!e.items.length)return null;const p=r===void 0?l("readHome.shelfLegendCount"):r,u=Jc(e.items,l("readHome.shelfOther")),m=h=>{const f=h.records?Ye(h.records):rd(h.text_count,l),x=Er(h),k=[d(h.title),h.orig?l("readHome.origZhi"):"",x?l("readHome.spineBy",{name:d(x)}):"",h.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(h.id),"data-orig":h.orig?"":void 0,"aria-label":k,title:k,style:{height:Qc(h.title)},children:[t.jsx(nd,{text:d(h.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":h.records?"":void 0,children:f})]})},h.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[s&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:o?d(o):l("readHome.shelfHint")})]}),t.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":l("readHome.shelfRegion",{label:d(e.label)}),children:t.jsx("ul",{className:"bim-rh-shelf",children:u.map(h=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(h.label),children:h.items.map(m)}),t.jsx("span",{"aria-hidden":"true",children:d(h.label)})]},h.label))})}),t.jsxs("p",{className:"bim-rh-legend",children:[t.jsxs("span",{children:[t.jsx("i",{"data-orig":"","aria-hidden":"true"}),l("readHome.origZhi")]}),t.jsxs("span",{children:[t.jsx("i",{"aria-hidden":"true"}),l("readHome.laterZhi")]}),p&&t.jsx("span",{children:d(p)}),a==null?void 0:a.map(h=>t.jsx("span",{children:d(h)},h))]})]})}const jb=4,Ln=e=>e>jb+1;function sd({topic:e,links:n}){const{t:o,convert:r}=J(),s=Mt(n),[a,l]=g.useState(!1);if(!e.items.length)return null;const d=`bim-rh-g-${e.key}`;return t.jsxs("div",{className:"bim-rh-grp","data-cap":Ln(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:o("readHome.nWorks",{n:Ye(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const p=rd(c.text_count,o),u=Er(c);return t.jsx("li",{children:t.jsxs("a",{href:s.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(c.title)}),p&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:p}),u&&t.jsx("small",{children:r(u)})]})},c.id)})}),Ln(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?o("action.collapse"):o("readHome.allNWorks",{n:e.items.length})})]})}function ad({topics:e,links:n}){const o=e.filter(s=>s.shelf&&s.items.length),r=e.filter(s=>!s.shelf&&s.items.length);return!o.length&&!r.length?null:t.jsxs(t.Fragment,{children:[o.map(s=>t.jsx(Ir,{topic:s,links:n},s.key)),r.length>0&&t.jsx("div",{className:"bim-rh-groups",children:r.map(s=>t.jsx(sd,{topic:s,links:n},s.key))})]})}function ld({famous:e,links:n}){const{t:o,convert:r}=J(),s=Mt(n);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:r(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:r(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:o("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:s.read(c.id),title:r([c.title,c.edition].filter(Boolean).join(" · ")),children:r(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:s.work(a.work_id),children:o("readHome.workPageLink",{title:r(a.title)})})})]})},a.work_id??a.title))}):null}function Rr({bu:e,unclassified:n,links:o,unclassifiedNote:r}){const{t:s,convert:a}=J(),l=Mt(o);return!e.length&&!n?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var p;const c=((p=d.top[0])==null?void 0:p.count)||1;return t.jsxs("li",{className:"bim-rh-bu-c",children:[t.jsxs("a",{className:"bim-rh-bu-h",href:l.node(d.id),children:[t.jsx("b",{children:a(d.label)}),t.jsx("span",{className:"bim-rh-num",children:s("readHome.nWorks",{n:Ye(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":s("readHome.subClasses",{label:a(d.label)}),children:d.top.map(u=>t.jsx("li",{children:t.jsxs("a",{href:l.node(u.id),children:[t.jsx("span",{children:a(u.label)}),t.jsx("small",{className:"bim-rh-num",children:Ye(u.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(u.count/c*100)}%`}})]})},u.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:s("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!n&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:s("readHome.unclassified")}),t.jsx("span",{children:s("readHome.nWorks",{n:Ye(n)})}),t.jsx("span",{children:r?a(r):s("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:s("readHome.viewUnclassified")})]})]})}function cd({periods:e,unknown:n,links:o}){const{t:r,convert:s,messages:a}=J(),l=a.readHome.period,d=Mt(o),c=e.filter(m=>m.count>0);if(!c.length)return null;const p=c.reduce((m,h)=>m+h.count,0),u=Math.max(...c.map(m=>m.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(m=>{const h=m.label?s(m.label):l[m.key]??s(m.key),f=m.count/p,x=r("readHome.periodItem",{label:h,n:Ye(m.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(m.key),"data-k":ed(m.count,u),"data-narrow":f<td?"":void 0,"aria-label":x,title:x,children:[t.jsx("span",{className:"bim-rh-pl",children:h}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(h)[0]}),t.jsx("small",{className:"bim-rh-num",children:Ye(m.count)})]})},m.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&t.jsx("span",{children:r("readHome.periodUnknown",{n:Ye(n)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:r("readHome.hoverHint")})]})]})}function dd({authors:e,links:n}){const{t:o,convert:r}=J(),s=Mt(n);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[r(a.name),a.dynasty&&t.jsx("span",{children:r(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:o("readHome.nPieces",{n:Ye(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:s.read(l.id),children:r(l.title)})},l.id))}),s.author&&t.jsx("a",{className:"bim-rh-more",href:s.author(a.name),children:o("readHome.authorAll",{name:r(a.name),n:a.count})})]},a.name))}):null}const pd={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function vb({sections:e,links:n,head:o,piecesMoreHref:r,className:s}){const{t:a}=J(),l=e,d=pd,c=l.topics.filter(h=>!h.shelf),p={picks:l.picks.length>0,topics:c.some(h=>h.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(h=>h.count>0),pieces:l.pieces.authors.length>0},u=Object.keys(d).filter(h=>p[h]),m=h=>a(`readHome.nav.${h}`);return t.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[t.jsx("style",{children:Nr}),t.jsxs("div",{className:"bim-rh-head",children:[o,t.jsx(id,{counts:l.counts})]}),u.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:u.map(h=>t.jsx("li",{children:t.jsx("a",{href:`#${d[h]}`,children:m(h)})},h))})}),t.jsxs("div",{className:"bim-rh-main",children:[p.picks&&t.jsx(st,{id:d.picks,title:m("picks"),sub:a("readHome.picksSub"),children:t.jsx(od,{picks:l.picks,links:n})}),p.topics&&t.jsx(st,{id:d.topics,title:m("topics"),sub:a("readHome.topicsSub"),children:t.jsx(ad,{topics:c,links:n})}),p.famous&&t.jsx(st,{id:d.famous,title:m("famous"),sub:a("readHome.famousSub"),children:t.jsx(ld,{famous:l.famous,links:n})}),p.sibu&&t.jsx(st,{id:d.sibu,title:m("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(Rr,{bu:l.bu,unclassified:l.unclassified,links:n})}),p.period&&t.jsx(st,{id:d.period,title:m("period"),sub:a("readHome.periodSub"),children:t.jsx(cd,{periods:l.periods,unknown:l.period_unknown,links:n})}),p.pieces&&t.jsx(st,{id:d.pieces,title:m("pieces"),sub:a("readHome.piecesSub"),more:r?t.jsx("a",{className:"bim-rh-more",href:r,children:a("readHome.piecesMore")}):void 0,children:t.jsx(dd,{authors:l.pieces.authors,links:n})})]})]})}const kb="(max-width: 1079px)",wb=`${Hn}, (pointer: coarse)`,ud=`
1694
+ `,vb=Ao["zh-Hant"].period,Qc={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function Bt(e){return{...Qc,...e??{}}}function Ir(e){var o;const n=(o=e.authors)==null?void 0:o.find(r=>r==null?void 0:r.name);return n?n.dynasty?`${n.dynasty} ${n.name}`:n.name:""}function Ni(e){return(e.authors??[]).filter(o=>o==null?void 0:o.name).map(o=>o.dynasty?`〔${o.dynasty}〕${o.name}`:o.name).join(" ")}function ed(e,n=Ao["zh-Hant"].shelfOther){var s;const o=[],r=new Map;for(const a of e){const l=((s=a.period_of)==null?void 0:s.trim())||n;let d=r.get(l);d||(d={label:l,items:[]},r.set(l,d),o.push(d)),d.items.push(a)}return o}function td(e){return Math.max(150,Array.from(e).length*18+44)}function nd(e,n){if(n<=0||e<=0)return 0;const o=e/n;return o<.15?0:o<.35?1:o<.6?2:o<.85?3:4}const id=.04;function Ye(e){return e.toLocaleString("en-US")}function od({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((n,o)=>t.jsx("span",{children:n},o))})}function st({id:e,title:n,sub:o,more:r,children:s}){const{convert:a}=J(),l=`${e}-h`;return t.jsxs("section",{className:"bim-rh-sec",id:e,"aria-labelledby":l,children:[t.jsxs("div",{className:"bim-rh-hd",children:[t.jsx("h2",{id:l,children:a(n)}),o&&t.jsx("span",{className:"bim-rh-sub",children:o}),r]}),t.jsx("div",{className:"bim-rh-bd",children:s})]})}function rd({counts:e}){const{t:n}=J();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:Ye(e.readable)}),n("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:Ye(e.pieces)}),n("readHome.pieces")]})]})}function sd({picks:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=Ni(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:s.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(od,{text:r(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:r(d)}),t.jsx("h3",{children:r(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:r(l)}),a.blurb&&t.jsx("p",{children:r(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:o("readHome.startReading")})]})]})},a.id)})}):null}function ad(e,n){return e&&e>1?n("readHome.nCopies",{n:e}):null}function Lr({topic:e,links:n,hint:o,legendCount:r,showTitle:s=!0,legendExtra:a}){const{t:l,convert:d}=J(),c=Bt(n);if(!e.items.length)return null;const p=r===void 0?l("readHome.shelfLegendCount"):r,u=ed(e.items,l("readHome.shelfOther")),m=h=>{const f=h.records?Ye(h.records):ad(h.text_count,l),x=Ir(h),k=[d(h.title),h.orig?l("readHome.origZhi"):"",x?l("readHome.spineBy",{name:d(x)}):"",h.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(h.id),"data-orig":h.orig?"":void 0,"aria-label":k,title:k,style:{height:td(h.title)},children:[t.jsx(od,{text:d(h.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":h.records?"":void 0,children:f})]})},h.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[s&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:o?d(o):l("readHome.shelfHint")})]}),t.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":l("readHome.shelfRegion",{label:d(e.label)}),children:t.jsx("ul",{className:"bim-rh-shelf",children:u.map(h=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(h.label),children:h.items.map(m)}),t.jsx("span",{"aria-hidden":"true",children:d(h.label)})]},h.label))})}),t.jsxs("p",{className:"bim-rh-legend",children:[t.jsxs("span",{children:[t.jsx("i",{"data-orig":"","aria-hidden":"true"}),l("readHome.origZhi")]}),t.jsxs("span",{children:[t.jsx("i",{"aria-hidden":"true"}),l("readHome.laterZhi")]}),p&&t.jsx("span",{children:d(p)}),a==null?void 0:a.map(h=>t.jsx("span",{children:d(h)},h))]})]})}const kb=4,Pn=e=>e>kb+1;function ld({topic:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n),[a,l]=g.useState(!1);if(!e.items.length)return null;const d=`bim-rh-g-${e.key}`;return t.jsxs("div",{className:"bim-rh-grp","data-cap":Pn(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:o("readHome.nWorks",{n:Ye(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const p=ad(c.text_count,o),u=Ir(c);return t.jsx("li",{children:t.jsxs("a",{href:s.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(c.title)}),p&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:p}),u&&t.jsx("small",{children:r(u)})]})},c.id)})}),Pn(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?o("action.collapse"):o("readHome.allNWorks",{n:e.items.length})})]})}function cd({topics:e,links:n}){const o=e.filter(s=>s.shelf&&s.items.length),r=e.filter(s=>!s.shelf&&s.items.length);return!o.length&&!r.length?null:t.jsxs(t.Fragment,{children:[o.map(s=>t.jsx(Lr,{topic:s,links:n},s.key)),r.length>0&&t.jsx("div",{className:"bim-rh-groups",children:r.map(s=>t.jsx(ld,{topic:s,links:n},s.key))})]})}function dd({famous:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:r(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:r(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:o("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:s.read(c.id),title:r([c.title,c.edition].filter(Boolean).join(" · ")),children:r(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:s.work(a.work_id),children:o("readHome.workPageLink",{title:r(a.title)})})})]})},a.work_id??a.title))}):null}function Ar({bu:e,unclassified:n,links:o,unclassifiedNote:r}){const{t:s,convert:a}=J(),l=Bt(o);return!e.length&&!n?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var p;const c=((p=d.top[0])==null?void 0:p.count)||1;return t.jsxs("li",{className:"bim-rh-bu-c",children:[t.jsxs("a",{className:"bim-rh-bu-h",href:l.node(d.id),children:[t.jsx("b",{children:a(d.label)}),t.jsx("span",{className:"bim-rh-num",children:s("readHome.nWorks",{n:Ye(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":s("readHome.subClasses",{label:a(d.label)}),children:d.top.map(u=>t.jsx("li",{children:t.jsxs("a",{href:l.node(u.id),children:[t.jsx("span",{children:a(u.label)}),t.jsx("small",{className:"bim-rh-num",children:Ye(u.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(u.count/c*100)}%`}})]})},u.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:s("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!n&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:s("readHome.unclassified")}),t.jsx("span",{children:s("readHome.nWorks",{n:Ye(n)})}),t.jsx("span",{children:r?a(r):s("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:s("readHome.viewUnclassified")})]})]})}function pd({periods:e,unknown:n,links:o}){const{t:r,convert:s,messages:a}=J(),l=a.readHome.period,d=Bt(o),c=e.filter(m=>m.count>0);if(!c.length)return null;const p=c.reduce((m,h)=>m+h.count,0),u=Math.max(...c.map(m=>m.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(m=>{const h=m.label?s(m.label):l[m.key]??s(m.key),f=m.count/p,x=r("readHome.periodItem",{label:h,n:Ye(m.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(m.key),"data-k":nd(m.count,u),"data-narrow":f<id?"":void 0,"aria-label":x,title:x,children:[t.jsx("span",{className:"bim-rh-pl",children:h}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(h)[0]}),t.jsx("small",{className:"bim-rh-num",children:Ye(m.count)})]})},m.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&t.jsx("span",{children:r("readHome.periodUnknown",{n:Ye(n)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:r("readHome.hoverHint")})]})]})}function ud({authors:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[r(a.name),a.dynasty&&t.jsx("span",{children:r(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:o("readHome.nPieces",{n:Ye(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:s.read(l.id),children:r(l.title)})},l.id))}),s.author&&t.jsx("a",{className:"bim-rh-more",href:s.author(a.name),children:o("readHome.authorAll",{name:r(a.name),n:a.count})})]},a.name))}):null}const md={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function wb({sections:e,links:n,head:o,piecesMoreHref:r,className:s}){const{t:a}=J(),l=e,d=md,c=l.topics.filter(h=>!h.shelf),p={picks:l.picks.length>0,topics:c.some(h=>h.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(h=>h.count>0),pieces:l.pieces.authors.length>0},u=Object.keys(d).filter(h=>p[h]),m=h=>a(`readHome.nav.${h}`);return t.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[t.jsx("style",{children:Er}),t.jsxs("div",{className:"bim-rh-head",children:[o,t.jsx(rd,{counts:l.counts})]}),u.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:u.map(h=>t.jsx("li",{children:t.jsx("a",{href:`#${d[h]}`,children:m(h)})},h))})}),t.jsxs("div",{className:"bim-rh-main",children:[p.picks&&t.jsx(st,{id:d.picks,title:m("picks"),sub:a("readHome.picksSub"),children:t.jsx(sd,{picks:l.picks,links:n})}),p.topics&&t.jsx(st,{id:d.topics,title:m("topics"),sub:a("readHome.topicsSub"),children:t.jsx(cd,{topics:c,links:n})}),p.famous&&t.jsx(st,{id:d.famous,title:m("famous"),sub:a("readHome.famousSub"),children:t.jsx(dd,{famous:l.famous,links:n})}),p.sibu&&t.jsx(st,{id:d.sibu,title:m("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(Ar,{bu:l.bu,unclassified:l.unclassified,links:n})}),p.period&&t.jsx(st,{id:d.period,title:m("period"),sub:a("readHome.periodSub"),children:t.jsx(pd,{periods:l.periods,unknown:l.period_unknown,links:n})}),p.pieces&&t.jsx(st,{id:d.pieces,title:m("pieces"),sub:a("readHome.piecesSub"),more:r?t.jsx("a",{className:"bim-rh-more",href:r,children:a("readHome.piecesMore")}):void 0,children:t.jsx(ud,{authors:l.pieces.authors,links:n})})]})]})}const Sb="(max-width: 1079px)",_b=`${Dn}, (pointer: coarse)`,hd=`
1693
1695
  /* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
1694
1696
  .bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
1695
1697
  .bim-mh-q { min-width: 0; }
@@ -1829,7 +1831,7 @@ ${bb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1829
1831
  .bim-mh-cc0 { display: inline-block; margin-right: 8px; padding: 1px 7px; font-size: 11.5px; letter-spacing: 0.08em; background: ${i("check-fine-bg")}; color: ${i("check-fine-fg")}; }
1830
1832
 
1831
1833
  /* ── 中屏 ── */
1832
- @media ${kb} {
1834
+ @media ${Sb} {
1833
1835
  .bim-mh-head, .bim-mh-zhi { grid-template-columns: minmax(0, 1fr); }
1834
1836
  .bim-mh-cg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1835
1837
  .bim-mh-lin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@@ -1839,7 +1841,7 @@ ${bb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1839
1841
  }
1840
1842
 
1841
1843
  /* ── 手机 ── */
1842
- @media ${Hn} {
1844
+ @media ${Dn} {
1843
1845
  .bim-mh-cg, .bim-mh-data { grid-template-columns: minmax(0, 1fr); }
1844
1846
  .bim-mh-ge { grid-template-columns: repeat(4, minmax(0, 1fr)); }
1845
1847
  .bim-mh-lin { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@@ -1856,8 +1858,8 @@ ${bb.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1856
1858
  .bim-mh-tbl tr > :nth-child(2), .bim-mh-tbl tr > :nth-child(3) { display: none; }
1857
1859
  }
1858
1860
 
1859
- @media ${wb} {
1861
+ @media ${_b} {
1860
1862
  .bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
1861
1863
  .bim-mh-recent-h button { min-height: 44px; }
1862
1864
  }
1863
- `,md={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function Bt(e){return{...md,...e??{}}}function hd(e,n){if(e.lineage)return e.lineage(n);const o=e.item(n),r=o.indexOf("#"),[s,a]=r<0?[o,""]:[o.slice(0,r),o.slice(r)];return`${s}${s.includes("?")?"&":"?"}tab=lineage${a}`}function Lr(e,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(e/n*100)))}function gd(e){const n=e.filter(p=>Number.isFinite(p.birth_year)||Number.isFinite(p.death_year)),o=e.filter(p=>!n.includes(p));if(!n.length)return{min:0,max:0,placed:[],missing:o};const r=p=>{const u=Number.isFinite(p.birth_year)?p.birth_year:p.death_year-50,m=Number.isFinite(p.death_year)?p.death_year:p.birth_year+50;return[Math.min(u,m),Math.max(u,m)]},s=n.map(r),a=Math.min(...s.map(p=>p[0])),l=Math.max(...s.map(p=>p[1])),d=Math.max(1,l-a),c=n.map((p,u)=>({p,from:s[u][0],to:s[u][1]})).sort((p,u)=>p.from-u.from).map(p=>({...p,left:(p.from-a)/d*100,width:Math.max(.8,(p.to-p.from)/d*100)}));return{min:a,max:l,placed:c,missing:o}}function ui(e,n=un("zh-Hant")){return e<0?n("metaHome.yearBC",{n:-e}):String(e)}function Sb(e){return{read:e.item,work:e.item,node:e.node}}function fd({counts:e,links:n}){const{t:o}=J(),r=n==null?void 0:n.type;if(!r)return null;const s=[["all",o("metaHome.typeAll"),null],["work",o("metaHome.typeLabel.work"),e.works],["book",o("metaHome.typeLabel.book"),e.books],["collection",o("metaHome.typeLabel.collection"),e.collections],["entity",o("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":o("metaHome.typeChipsLabel"),children:s.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:r(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:Ye(d)})]})},a))})}function xd(e,n=5){const[o,r]=g.useState(null);g.useEffect(()=>{let a=!1;const l=Pt().slice(0,n);if(!l.length||!e){r([]);return}return Promise.all(l.map(d=>Ho(e,d))).then(d=>{a||r(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,n]);const s=g.useCallback(()=>{Oo(),r([])},[]);return{entries:o,clear:s}}function _b(e,n,o){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?o(r):bd(e.type,n)}function bd(e,n){return n(`metaHome.typeLabel.${e}`)}function yd({entries:e,onClear:n,links:o}){const{t:r,convert:s}=J(),a=Bt(o);return t.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[t.jsxs("div",{className:"bim-mh-recent-h",children:[t.jsx("h2",{id:"bim-mh-recent-h",children:r("metaHome.recentTitle")}),e&&e.length>0&&n&&t.jsx("button",{type:"button",onClick:n,children:r("metaHome.recentClear")})]}),e&&e.length>0&&t.jsx("ol",{children:e.map(l=>t.jsx("li",{children:t.jsxs("a",{href:a.item(l.id),"aria-label":r("metaHome.recentItemLabel",{type:l.type?bd(l.type,r):"",title:s(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?r(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:s(l.title)}),t.jsx("small",{"aria-hidden":"true",children:_b(l,r,s)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function jd(e,n,o,r=!1){return r&&(e==="done"||e==="in_progress")?n(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?n(`metaHome.status.${e}`):o(e)}function vd({rows:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":o("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[o("metaHome.catalogTitle"),t.jsx("small",{children:o("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:o("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:o("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:o("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:o("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:o("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=Lr(a.imported,a.total),d=a.work_id??a.collection_id,c=r(a.edition?`${a.name}·${a.edition}`:a.name);return t.jsxs("tr",{children:[t.jsx("th",{scope:"row",children:d?t.jsx("a",{href:s.item(d),children:c}):c}),t.jsx("td",{className:"bim-mh-r",children:Ye(a.total)}),t.jsx("td",{className:"bim-mh-r",children:Ye(a.imported)}),t.jsx("td",{children:t.jsxs("span",{className:"bim-mh-meter",children:[t.jsx("i",{"aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[l,"%"]})]})}),t.jsx("td",{children:a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:jd(a.status,o,r)})})]},a.id||a.name)})})]})}):null}function kd({items:e,links:n,label:o}){const{convert:r}=J();return t.jsx("ul",{className:"bim-rh-rows","aria-label":o?r(o):void 0,children:e.map(s=>t.jsx("li",{children:t.jsxs("a",{href:n.item(s.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(s.title)}),s.sub&&t.jsx("small",{children:r(s.sub)})]})},s.id))})}function wd({works:e,links:n}){const{t:o}=J(),[r,s]=g.useState(!1);if(!e.length)return null;const a=Ln(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":r?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[o("metaHome.relatedTitle"),t.jsx("small",{children:o("metaHome.relatedNote")})]}),t.jsx(kd,{items:e.map(l=>({id:l.id,title:l.title,sub:zi(l)||void 0})),links:Bt(n)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":r,onClick:()=>s(l=>!l),children:r?o("action.collapse"):o("metaHome.allNWorks",{n:e.length})})]})}const Sd="siku_qige";function $b({group:e,links:n}){const{t:o,convert:r}=J(),[s,a]=g.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Ln(e.items.length)?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:o("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(kd,{items:e.items,links:n,label:e.label}),Ln(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>a(l=>!l),children:s?o("action.collapse"):o("metaHome.allNKinds",{n:e.items.length})})]})}function _d({groups:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n);if(!e.length)return null;const a=e.find(c=>c.key===Sd),l=e.filter(c=>c!==a),d=c=>{var p;return((p=c.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:p[1])??c};return t.jsxs(t.Fragment,{children:[a&&t.jsxs(t.Fragment,{children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(a.label),t.jsx("small",{children:r(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":r(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:s.item(c.id),"aria-label":r(c.title),title:r(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:r(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:o("metaHome.pavilion")})]})},c.id))})]}),l.length>0&&t.jsx("div",{className:"bim-mh-cg",style:a?void 0:{marginTop:0},children:l.map(c=>t.jsx($b,{group:c,links:s},c.key))})]})}const ya=34,ja=13;function va(e,n){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?ui(e.birth_year,n):"?"}–${e.death_year!=null?ui(e.death_year,n):"?"}`}function Cb(e,n){const o=n-e,r=o>1200?300:o>400?100:50,s=[];for(let a=Math.ceil(e/r)*r;a<=n;a+=r)s.push(a);return s}function $d({people:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=gd(e),p=[],u=d.map(h=>{const f=h.left>70,x=f?Math.min(h.left,h.left+h.width-ja):h.left;let k=0;for(;p[k]!=null&&p[k]>x;)k++;return p[k]=f?h.left+h.width:h.left+Math.max(h.width,ja),{...h,lane:k,end:f}}),m=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:p.length*ya+10},children:u.map(h=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":h.end?"":void 0,style:{left:`${h.left}%`,top:h.lane*ya+4,width:`${Math.max(h.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:s.item(h.p.id),children:[r(h.p.name),t.jsx("small",{className:"bim-rh-num",children:va(h.p,o)})]})]},h.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:Cb(a,l).map(h=>t.jsx("span",{style:{left:`${(h-a)/m*100}%`},children:ui(h,o)},h))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":u.length?void 0:"",children:(u.length?e:c).map(h=>t.jsx("li",{children:t.jsxs("a",{href:s.item(h.id),children:[t.jsx("span",{children:r(h.name)}),t.jsx("small",{className:"bim-rh-num",children:[h.dynasty?r(h.dynasty):"",va(h,o)].filter(Boolean).join(" ")})]})},h.id))}),c.length>0&&u.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:o("metaHome.missingLife",{names:r(c.map(h=>h.name).join("、"))})})]})}const zb=t.jsxs("svg",{width:"54",height:"34",viewBox:"0 0 54 34",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",children:[t.jsx("circle",{cx:"27",cy:"5",r:"3.5"}),t.jsx("circle",{cx:"10",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"27",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"44",cy:"29",r:"3.5"}),t.jsx("path",{d:"M27 8.5v17M27 15H10v10.5M27 15h17v10.5"})]});function Cd({works:e,links:n}){const{t:o,convert:r}=J(),s=Bt(n);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=zi(a);return t.jsx("li",{children:t.jsxs("a",{href:hd(s,a.id),children:[zb,t.jsx("b",{children:r(a.title)}),l&&t.jsx("small",{children:r(l)}),t.jsx("span",{children:o("metaHome.viewLineage")})]})},a.id)})}):null}function zd({sites:e}){const{t:n,convert:o}=J(),r=e.filter(a=>a.status!=="todo"&&a.total>0),s=e.filter(a=>!r.includes(a));return e.length?t.jsxs(t.Fragment,{children:[r.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:r.map(a=>{const l=Lr(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:o(a.name)}):t.jsx("span",{children:o(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${Ye(a.imported)} / ${Ye(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:jd(a.status,n,o,!0)})]})]},a.id||a.name)})}),s.length>0&&t.jsx("p",{className:"bim-mh-todo",children:n("metaHome.plannedSites",{names:o(s.map(a=>a.name).join("、"))})})]}):null}const ka=["extant","partially_extant","lost","unknown"];function Td({stats:e,links:n,version:o,repoUrl:r,downloadHref:s}){const{t:a}=J(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(p=>[e[p],a(`metaHome.stat.${p}`)]).filter(([p])=>p>0),d=n==null?void 0:n.loss,c=ka.some(p=>{var u;return(((u=e.loss)==null?void 0:u[p])??0)>0});return t.jsxs("div",{className:"bim-mh-data",children:[l.length>0&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.dataScale")}),t.jsx("ul",{className:"bim-mh-nums",children:l.map(([p,u])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:Ye(p)}),t.jsx("span",{children:u})]},u))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:ka.map(p=>{var h;const u=((h=e.loss)==null?void 0:h[p])??0,m=a(`metaHome.lossNote.${p}`);return t.jsx("li",{children:t.jsxs("a",{href:d(p),children:[a(`metaHome.loss.${p}`),t.jsx("small",{className:"bim-rh-num",children:c&&u>0?a("metaHome.lossCount",{n:Ye(u),note:m}):m})]})},p)})})]}),t.jsxs("div",{className:"bim-mh-lic",children:[t.jsxs("p",{children:[t.jsx("span",{className:"bim-mh-cc0",children:"CC0"}),a("metaHome.license")]}),t.jsxs("p",{children:[a("metaHome.repo"),r?t.jsx("a",{href:r,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),o&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:o})]}),s&&t.jsx("p",{children:t.jsx("a",{href:s,children:a("metaHome.download")})})]})]})}const Nd={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function Tb({sections:e,links:n,head:o,transport:r,catalogHref:s,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:p,className:u}){var v,$;const{t:m}=J(),h=e,f=Bt(n),x=Sb(f),k=Nd,y=xd(r),w={zhi:!!((v=h.shelf)!=null&&v.items.length)||h.catalog_progress.length>0||h.related_catalogs.length>0,sibu:h.bu.length>0||h.unclassified>0,cong:h.collection_groups.length>0,people:h.bibliographers.length>0,lineage:h.lineage.length>0,sites:h.sites.length>0,data:!0},b=Object.keys(k).filter(_=>w[_]),j=_=>m(`metaHome.nav.${_}`),S=(_,C)=>_?t.jsx("a",{className:"bim-rh-more",href:_,children:C}):void 0;return t.jsxs("div",{className:u?`bim-rh bim-mh ${u}`:"bim-rh bim-mh",children:[t.jsx("style",{children:Nr+ud}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[o,t.jsx(fd,{counts:h.counts,links:n})]}),r&&t.jsx(yd,{entries:y.entries,onClear:y.clear,links:n})]}),b.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":m("metaHome.navLabel"),children:t.jsx("ul",{children:b.map(_=>t.jsx("li",{children:t.jsx("a",{href:`#${k[_]}`,children:j(_)})},_))})}),t.jsxs("div",{className:"bim-rh-main",children:[w.zhi&&t.jsxs(st,{id:k.zhi,title:j("zhi"),sub:m("metaHome.zhiSub"),children:[h.shelf&&h.shelf.items.length>0&&t.jsx(Ir,{topic:{key:"shelf",label:h.shelf.label,shelf:!0,items:h.shelf.items},links:x,showTitle:!1,legendCount:h.shelf.items.some(_=>_.records)?m("metaHome.shelfLegendCount"):null,legendExtra:[m("metaHome.shelfLegendClick")]}),(h.catalog_progress.length>0||h.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:($=h.shelf)!=null&&$.items.length?void 0:{marginTop:0},children:[t.jsx(vd,{rows:h.catalog_progress,links:n}),t.jsx(wd,{works:h.related_catalogs,links:n})]})]}),w.sibu&&t.jsx(st,{id:k.sibu,title:j("sibu"),sub:m("metaHome.sibuSub"),more:S(s,m("metaHome.toCatalog")),children:t.jsx(Rr,{bu:h.bu,unclassified:h.unclassified,links:x,unclassifiedNote:m("metaHome.unclassifiedNote")})}),w.cong&&t.jsx(st,{id:k.cong,title:j("cong"),sub:m("metaHome.congSub"),more:S(a,m("metaHome.allNKindsMore",{n:Ye(h.counts.collections)})),children:t.jsx(_d,{groups:h.collection_groups,links:n})}),w.people&&t.jsx(st,{id:k.people,title:j("people"),sub:m("metaHome.peopleSub"),more:S(l,m("metaHome.allNPeopleMore",{n:Ye(h.counts.entities)})),children:t.jsx($d,{people:h.bibliographers,links:n})}),w.lineage&&t.jsx(st,{id:k.lineage,title:j("lineage"),sub:m("metaHome.lineageSub"),children:t.jsx(Cd,{works:h.lineage,links:n})}),w.sites&&t.jsx(st,{id:k.sites,title:j("sites"),sub:m("metaHome.sitesSub"),children:t.jsx(zd,{sites:h.sites})}),t.jsx(st,{id:k.data,title:j("data"),sub:m("metaHome.dataSub"),children:t.jsx(Td,{stats:h.stats,links:n,version:d,repoUrl:c,downloadHref:p})})]})]})}const kt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),nt=e=>Array.isArray(e),Nb=e=>kt(e)&&!!e.h;function Eb(e){if(!e)return!1;for(const n of["_related","_catalogs","_collections","_works","_members","_children"]){const o=e[n];if(nt(o)&&o.some(Nb))return!0}return!1}function ei(e,n){var r;if(typeof e.title=="string"&&e.title)return e.title;const o=e.id??e.bid;return e.h&&o&&((r=n==null?void 0:n[o])!=null&&r.title)?n[o].title:""}function Ib(e){const n=e.filter(kt);return n.find(o=>o.scheme==="zongmu")??n[0]??null}const Rb=e=>typeof e=="number"?e:nt(e)&&typeof e[0]=="number"?e[0]:void 0;function To(e,n){if(!kt(e))return e;const o={...e},r=e.type;if(r==="work"){if(!nt(e.books)&&nt(e._books)&&(o.books=e._books.filter(kt).map(s=>s.id).filter(s=>typeof s=="string")),!kt(e.classification)&&nt(e._classifications)){const s=Ib(e._classifications);s&&(o.classification={l1:s.l1??"",l2:s.l2??"",l3:s.l3??"",l4:s.l4??"",...s.source?{source:s.source}:{}})}nt(e._related)&&(o.related_works=e._related.filter(kt).map(s=>{const a=s;return{id:a.id,title:ei(a,n),...a.relation?{relation:a.relation}:{},...a.note?{note:a.note}:{}}})),!nt(e.indexed_by)&&nt(e._catalogs)&&e._catalogs.length&&(o.indexed_by=e._catalogs.filter(kt).map(s=>{const a=s;return{source:ei(a,n)||String(a.bid??""),...a.bid?{source_bid:a.bid}:{},...a.section?{section:a.section}:{}}}))}if((r==="work"||r==="book")&&!nt(e.contained_in)&&nt(e._collections)&&e._collections.length&&(o.contained_in=e._collections.filter(kt).map(s=>{const a=s;return{id:a.id,...a.vol!=null?{volume_index:a.vol}:{},...a.sub!=null?{sub_items:a.sub}:{}}})),r==="collection"&&nt(e._members)){const s=e._members.filter(kt),a=typeof e._member_count=="number"?e._member_count:s.length,l=d=>d.t==="work";if(!nt(e.books)){const d=s.filter(c=>!l(c)).map(c=>c.id).filter(c=>typeof c=="string");d.length&&(o.books=d)}if(!nt(e.contained_works)){const d=s.filter(l).map(c=>{const p=Rb(c.vol);return{id:c.id,title:ei(c,n),...p!=null?{volume_index:p}:{}}});d.length&&(o.contained_works=d)}a>s.length&&(o._members_truncated=!0)}return r==="entity"&&!nt(e.works)&&nt(e._works)&&(o.works=e._works.filter(kt).map(s=>{const a=s,l=ei({...a,id:a.work_id},n);return{...a,work_id:a.work_id,...l?{title:l}:{}}})),o}function Lb(e){let n=null;const o=()=>e.getHubs?(n??(n=e.getHubs().catch(()=>null)),n):Promise.resolve(null),r=async s=>s&&To(s,Eb(s)?await o():null);return new Proxy(e,{get(s,a,l){if(a==="getItem")return async c=>r(await s.getItem(c));const d=Reflect.get(s,a,s);return typeof d=="function"?d.bind(s):d}})}const No=({style:e})=>{const n=g.useContext(qt),{t:o}=J();if(!n)return null;const{locale:r,setLocale:s}=n,a=r==="zh-Hant",l=()=>s(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:o(a?"common.toHans":"common.toHant"),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:a?i("primary"):void 0,fontWeight:a?700:400},children:o("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:i("primary"),fontWeight:a?400:700},children:o("common.localeShortHans")})]})},Eo=({href:e,label:n,size:o=16,className:r,style:s})=>{const{t:a}=J(),l=n??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,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:d=>{d.currentTarget.style.color=i("fg")},onMouseLeave:d=>{d.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 oo(e){const n=e.text_count;return typeof n=="number"&&n>0}function ro(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function Ab(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const Pb=({id:e,transport:n,initialDetail:o,initialEntry:r,activeTab:s,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:p,lineageCollection:u,onLineageCollectionChange:m,initialPage:h=1,selectedLineageNodeId:f,onNavigate:x,onBack:k,backLabel:y,renderLink:w,enrichDetail:b,getSourceLink:j,readLink:S,railTop:v,extraTabs:$=[],showFeedbackTab:_=!0,feedbackApiUrl:C,height:M,footerExtra:T,hideHeaderControls:z=!1,className:H,style:N})=>{const I=g.useMemo(()=>Lb(n),[n]),L=ze(),{t:R,convert:P}=J(),[U]=g.useState(()=>{if(!Ab(e,o))return null;const V=To({...o}),xe=r??ro(e,V);return b&&b(xe,V),{id:e,entry:xe,detail:V}}),[q,D]=g.useState((U==null?void 0:U.entry)??null),[O,A]=g.useState((U==null?void 0:U.detail)??null),[G,le]=g.useState(!U),[ne,ve]=g.useState(!1),[oe,pe]=g.useState([]),[We,ee]=g.useState(!1),[Be,Ee]=g.useState(null),[X,ie]=g.useState(null),[he,Te]=g.useState(null),[K,_e]=g.useState(!1),se=g.useRef(null),$e=g.useRef(0),[Z,Ne]=g.useState(null),Oe=l!==void 0?l:Z,B=g.useCallback(V=>{d?d(V):Ne(V)},[d]),te=g.useCallback(async V=>{if(!I.getCollectionCatalogs&&!I.getCollectionCatalog){pe([]);return}ee(!0);try{if(I.getCollectionCatalogs)pe(await I.getCollectionCatalogs(V)||[]);else if(I.getCollectionCatalog){const xe=await I.getCollectionCatalog(V);pe(xe?[{resource_id:"",data:xe}]:[])}}catch{pe([])}finally{ee(!1)}},[I]),be=g.useCallback(async V=>{var xe,Ae;if(!I.getTextManifest||!I.getTextIndex){Ee(null),ie(V);return}try{const Y=Se.pickTextVersion(await I.getTextManifest(V)),fe=Y?await I.getTextIndex(V,Y.key):null;Ee(fe&&fe.chapters.length>0?{chapters:fe.chapters.map(ce=>({n:ce.n,title:ce.title,file:ce.file})),source:{name:((xe=fe.source)==null?void 0:xe.name)??(Y==null?void 0:Y.source_name),license:((Ae=fe.source)==null?void 0:Ae.license)??(Y==null?void 0:Y.license)??void 0}}:null)}catch{Ee(null)}finally{ie(V)}},[I]),Ie=g.useCallback(async(V,xe)=>{const Ae=++$e.current,Y=()=>Ae!==$e.current;_e(!0);try{if(I.getLineageGraph){const Ue=await I.getLineageGraph(V);if(Y())return;Ue&&Te(Ue)}const fe=xe.version_graph;if(!fe||!fe.enabled){he||Te(null),se.current=null;return}const ce=xe.books??[],we=[];for(const Ue of ce)try{const xt=await I.getItem(Ue);xt&&we.push(xt)}catch{}if(Y())return;se.current={work:xe,books:we};const Ge=u??fe.default_collection??(fe.core_books&&fe.core_books.length>0?"core":"all"),He=Ge==="core"&&Array.isArray(fe.core_books)&&fe.core_books.length>0?"core":Ge??"all";Te(ri(xe,we,He))}catch{if(Y())return;Te(null),se.current=null}finally{Y()||_e(!1)}},[I]),F=g.useRef({initialDetail:o,initialEntry:r});F.current={initialDetail:o,initialEntry:r},g.useEffect(()=>{let V=!1;$e.current++,_e(!1);const xe=ce=>{ce.type==="collection"?te(e):ce.type==="work"?(ce.version_graph||I.getLineageGraph)&&Ie(e,ce):ce.type==="book"&&oo(ce)&&be(e)},Ae=F.current;let Y=null;if(U&&U.id===e)Y=U;else if(Ae.initialDetail&&Ae.initialDetail.id===e){const ce=To({...Ae.initialDetail}),we=Ae.initialEntry??ro(e,ce);b&&b(we,ce),Y={entry:we,detail:ce}}return Y?(ve(!1),pe(ce=>ce.length?[]:ce),Ee(null),Te(null),se.current=null,D(Y.entry),A(Y.detail),le(!1),xe(Y.detail),()=>{V=!0}):((async()=>{le(!0),ve(!1),D(null),A(null),pe([]),Ee(null),Te(null),se.current=null;try{const ce=await I.getItem(e);if(V)return;if(!ce){ve(!0);return}const we=ce;let Ge=null;if(I.getEntry&&(Ge=await I.getEntry(e),V))return;Ge||(Ge=ro(e,we)),b&&b(Ge,we),D(Ge),A(we),xe(we)}catch{V||ve(!0)}finally{V||le(!1)}})(),()=>{V=!0})},[e,I,U,b,te,Ie,be]),g.useEffect(()=>{const V=se.current;!V||!u||Te(ri(V.work,V.books,u))},[u]);const ue=[];if(O){if(ue.push({key:"basic",label:L.detailTab.basicInfo}),O.type==="collection"){We&&oe.length===0&&ue.push({key:"catalog:loading",label:`${L.detailTab.catalog}…`});for(const V of oe)ue.push({key:`catalog:${V.resource_id}`,label:V.short_name?`${P(V.short_name)}${L.detailTab.catalogSuffix}`:L.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&ue.push({key:s,label:L.detailTab.fullText}),O.type==="work"&&(he||K)&&ue.push({key:"lineage",label:K?`${L.detailTab.lineage}…`:L.detailTab.lineage});for(const V of $)(V.position??"before-feedback")==="before-feedback"&&V.shouldShow(O)&&ue.push({key:V.key,label:V.label});_&&s==="feedback"&&ue.push({key:"feedback",label:L.detailTab.feedback});for(const V of $)V.position==="after-feedback"&&V.shouldShow(O)&&ue.push({key:V.key,label:V.label})}g.useEffect(()=>{if(s!=="emendated"||!O)return;a("basic");const V=setTimeout(()=>{var xe;(xe=document.getElementById("studies"))==null||xe.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(V)},[s,O,a]);const Q=q&&O&&j?j({activeTab:s,activeJuan:Oe,entry:q,detail:O}):null,ye=g.useMemo(()=>{var fe;if(!O)return null;const xe=(O.authors??[]).map(ce=>{const we=Zo(ce.role);return`${ce.dynasty?`〔${P(ce.dynasty)}〕`:""}${P(ce.name)}${we?` ${P(we)}`:""}`}).join(" · ");let Ae=!1;try{Ae=Se.extractStatus(O.id)==="draft"}catch{}if(O.type==="book"){const ce=O;return{title:P(ce.title),subtitle:ce.edition?P(ce.edition):xe||void 0,aside:[Ae?L.status.draft:"",xe&&ce.edition?xe:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(O.type==="collection"){const ce=O;return{title:P(ce.title),subtitle:P(Et(ce,L.unit.juan))||void 0,aside:[(fe=ce.publication_info)==null?void 0:fe.year,Ae?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:xe||void 0}}if(O.type==="entity"){const ce=O,we=He=>He==null?"":He<0?R("detail.bce",{n:-He}):String(He),Ge=ce.birth_year!=null||ce.death_year!=null?`${we(ce.birth_year)||"?"}—${we(ce.death_year)||"?"}`:"";return{title:P(ce.primary_name||ce.title),subtitle:[ce.dynasty?`〔${P(ce.dynasty)}〕`:"",Ge].filter(Boolean).join(" ")||void 0,aside:Ae?L.status.draft:void 0,secondLine:void 0}}const Y=P(Et(O,L.unit.juan));return{title:P(O.title),subtitle:[Y,xe].filter(Boolean).join(" · ")||void 0,aside:[Bb(L,O.subtype),Ae?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[O,P,L,R]),Ce=O&&oo(O)?"text":null,Me=()=>{B(null),a("fulltext")};let De=null;if(O&&S){const V=S({detail:O,kind:Ce});V&&(De=t.jsx(xo,{href:V}))}else Ce&&(De=t.jsx(xo,{onClick:Me}));const qe=V=>{if(!O)return null;const xe=V.replace(/\.[^.]+$/,"");if(S){const Ae=S({detail:O,kind:Ce,juan:xe});return Ae?{href:Ae}:null}return{onClick:()=>{B(xe),a("fulltext")}}},me=new Set($.map(V=>V.key)),Ve=ue.filter(V=>V.key.startsWith("catalog:")&&V.key!=="catalog:loading"||V.key==="lineage"&&!!he&&!K||me.has(V.key)).map(V=>({key:V.key,label:V.label,onClick:()=>a(V.key)})),E=()=>{var V;return O?O.type==="work"?t.jsx(Ac,{data:O,transport:I,onNavigate:x,renderLink:w,readAction:De,railTop:v,railLinks:Ve}):O.type==="book"?t.jsx(Wc,{data:O,transport:I,onNavigate:x,renderLink:w,readAction:De,fullText:Be,fullTextPending:oo(O)&&!!I.getTextManifest&&X!==O.id,chapterLink:qe,railTop:v,railLinks:Ve}):O.type==="collection"?t.jsx(Oc,{data:O,catalog:(V=oe[0])==null?void 0:V.data,transport:I,onNavigate:x,renderLink:w,readAction:De,railTop:v,railLinks:Ve,catalogAction:oe.length>0?t.jsxs("a",{href:"#catalog",onClick:xe=>{xe.preventDefault(),a(`catalog:${oe[0].resource_id}`)},children:[P(L.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Hc,{data:O,transport:I,onNavigate:x,renderLink:w,railTop:v,railLinks:Ve}):null},re=()=>{var xe,Ae,Y;if(!q||!O)return null;if(s==="basic"||s==="emendated")return E();if(typeof s=="string"&&s.startsWith("catalog:")){const fe=(xe=oe.find(ce=>`catalog:${ce.resource_id}`===s))==null?void 0:xe.data;return t.jsx(Do,{data:fe,onNavigate:x,renderLink:w})}if(s==="collated"||s==="fulltext")return t.jsx(vr,{id:e,transport:I,chapter:Oe,onLocationChange:fe=>B(fe.chapter),onNavigate:x});if(s==="lineage"){if(!he)return t.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:R(K?"detail.loading":"detail.noLineageGraph")});const fe=O.type==="work"?O:null;return t.jsx($r,{graph:he,renderLink:w,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:p,selectedNodeId:f,collection:u??((Ae=fe==null?void 0:fe.version_graph)==null?void 0:Ae.default_collection),onCollectionChange:m,collectionsAvailable:(Y=fe==null?void 0:fe.version_graph)==null?void 0:Y.collections,collectionCounts:(()=>{var He,Ue,xt,Wt,Jt,fn,Fn;if(!fe)return;const ce={},we=((He=se.current)==null?void 0:He.books)??[];ce.all=(((Ue=fe.books)==null?void 0:Ue.length)??0)-(((Wt=(xt=fe.version_graph)==null?void 0:xt.excluded_books)==null?void 0:Wt.length)??0);const Ge=(Jt=fe.version_graph)==null?void 0:Jt.collections;if(Ge)for(const bt of Object.keys(Ge))ce[bt]=ri(fe,we,bt).nodes.filter(It=>It.kind==="book"&&!It.bridge).length;return ce.core==null&&((Fn=(fn=fe.version_graph)==null?void 0:fn.core_books)!=null&&Fn.length)&&(ce.core=fe.version_graph.core_books.length),ce})()})}if(s==="feedback"&&_)return t.jsx(Ec,{resourceId:e,apiUrl:C});const V=$.find(fe=>fe.key===s);return V?V.render({detail:O,entry:q,transport:I,onNavigate:x}):null};if(G)return t.jsx(zn,{style:{minHeight:M,...N},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((V,xe)=>t.jsx("div",{style:{height:xe===1?40:16,width:V,opacity:.35,background:i("rule")}},xe))})});if(ne||!O||!q||!ye)return t.jsx(zn,{style:{minHeight:M,...N},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:R("detail.notFound")})});const ae=s==="basic"||s==="emendated",je=[{label:y??L.detailTab.backToIndex,onClick:k}];if(O.type==="book"&&O.work_id){const V=O.work_id;je.push({label:L.indexType.work,id:V,onClick:()=>x==null?void 0:x(V)})}je.push({label:L.indexType[O.type]});const ke=s==="collated"||s==="fulltext",ge=typeof T=="string"?L.status[T.trim()]??T:T,Le=t.jsx(Gl,{left:t.jsxs(t.Fragment,{children:[ge,ge?" · ":"",t.jsx(Mb,{id:O.id,label:L.label.id,copied:L.action.copied,copyLabel:L.action.copy})]}),right:t.jsxs(t.Fragment,{children:[_&&!ae&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:L.detailTab.submitVersion}),Q&&t.jsx("a",{href:Q.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:L.detailTab.dataLicense})]})});return ae?t.jsx("div",{className:H,children:t.jsxs(zn,{grid:!0,style:{minHeight:M,...N},children:[t.jsx(bo,{breadcrumb:t.jsx(yo,{items:je}),actions:t.jsxs(t.Fragment,{children:[!z&&t.jsx(No,{style:{border:"none",background:"transparent"}}),!z&&Q&&t.jsx(Eo,{...Q})]})}),E(),Le]})}):t.jsx("div",{className:H,children:t.jsxs(zn,{wide:ke,style:{minHeight:M,...N},children:[t.jsx(bo,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(tr,{char:"籍"}),t.jsx(yo,{items:je})]}),actions:t.jsxs(t.Fragment,{children:[!z&&t.jsx(No,{}),_&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:L.detailTab.feedback}),!z&&Q&&t.jsx(Eo,{...Q})]})}),t.jsx(Ml,{...ye,aside:ke?t.jsxs("button",{type:"button",onClick:()=>a("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:[R("detail.workInfo")," →"]}):ye.aside}),!ke&&ue.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:ue.map(V=>t.jsx(Bl,{label:V.label,active:V.key===s||ae&&V.key==="basic",onClick:()=>a(V.key)},V.key))}),t.jsx("div",{style:{marginTop:!ke&&ue.length>1?8:0},children:re()}),Le]})})};function Mb({id:e,label:n,copied:o,copyLabel:r}){const[s,a]=g.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var l;(l=navigator.clipboard)==null||l.writeText(e).then(()=>{a(!0),setTimeout(()=>a(!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 Bb(e,n){return n?e.workSubtype[n]??n:""}const Ed=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Ti="zhusha",Ni="bim-theme";function Id(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Ei(e){return Id(e)?e:Ti}function Wb(){try{return Ei(window.localStorage.getItem(Ni))}catch{return Ti}}function Rd(e){try{window.localStorage.setItem(Ni,e)}catch{}}function Ld(e){const n=Ei(e);return document.documentElement.setAttribute("data-theme",n),n}function Ad(){return Ei(document.documentElement.getAttribute("data-theme"))}const Ob=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],Ar="airy",Ii="bim-layout";function Pd(e){return e==="airy"||e==="boxed"}function Ri(e){return Pd(e)?e:Ar}function Hb(){try{return Ri(window.localStorage.getItem(Ii))}catch{return Ar}}function Fb(e){try{window.localStorage.setItem(Ii,e)}catch{}}function Db(e){const n=Ri(e);return document.documentElement.setAttribute("data-layout",n),n}function Ub(){return Ri(document.documentElement.getAttribute("data-layout"))}const Vb=`try{var t=localStorage.getItem(${JSON.stringify(Ni)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Ii)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,Gb={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},Yb=({onChange:e,style:n})=>{const{t:o}=J(),[r,s]=g.useState(Ti);g.useEffect(()=>{s(Ad())},[]);const a=l=>{s(Ld(l)),Rd(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":o("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...n},children:Ed.map(l=>{const d=r===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":o(`common.theme.${l.name}`),title:o(`common.theme.${l.name}`),onClick:()=>a(l.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(Gb[l.name]),boxShadow:d?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=Se.BidLink;exports.BookIndexError=Se.BookIndexError;exports.BookIndexManager=Se.BookIndexManager;exports.BookIndexStorage=Se.BookIndexStorage;exports.BundleStorage=Se.BundleStorage;exports.ConfigError=Se.ConfigError;exports.GithubStorage=Se.GithubStorage;exports.IdGenerationError=Se.IdGenerationError;exports.IdGenerator=Se.IdGenerator;exports.LocalStorage=Se.LocalStorage;exports.MigrationError=Se.MigrationError;exports.StorageError=Se.StorageError;exports.VARIANT_CHARS=Se.VARIANT_CHARS;exports.base36Decode=Se.base36Decode;exports.base36Encode=Se.base36Encode;exports.base58Decode=Se.base58Decode;exports.buildId=Se.buildId;exports.buildPromotionMap=Se.buildPromotionMap;exports.cleanName=Se.cleanName;exports.decodeId=Se.decodeId;exports.decodeIdString=Se.decodeIdString;exports.encodeId=Se.encodeId;exports.extractIdFromUrl=Se.extractIdFromUrl;exports.extractStatus=Se.extractStatus;exports.extractType=Se.extractType;exports.isChapterSegment=Se.isChapterSegment;exports.isTextKey=Se.isTextKey;exports.matchChapterAcrossVersions=Se.matchChapterAcrossVersions;exports.normalizeCatalog=Se.normalizeCatalog;exports.normalizeVariants=Se.normalizeVariants;exports.parseId=Se.parseId;exports.pickTextVersion=Se.pickTextVersion;exports.shardOf=Se.shardOf;exports.smartDecode=Se.smartDecode;exports.textVersionLabel=Se.textVersionLabel;exports.validateResource=Se.validateResource;exports.Badge=pi;exports.BidUrlProvider=op;exports.BookDetailLayout=Pb;exports.BookPage=Wc;exports.Breadcrumb=yo;exports.CATALOG_ALL_ID=zt;exports.CATALOG_CSS=Fc;exports.CATALOG_NARROW_QUERY=Cr;exports.CATALOG_PAGE_SIZE=zr;exports.CATALOG_UNCLASSIFIED_ID=Vt;exports.CLASSIFICATIONS=bi;exports.COMMON_TRADITIONAL_CHARS=Na;exports.CardFoot=Bn;exports.CatalogPage=gb;exports.CatalogPager=qc;exports.CatalogTree=Uc;exports.CheckFilter=Ll;exports.Chip=Wl;exports.ChipWall=qm;exports.CollectionCatalog=Do;exports.CollectionPage=Oc;exports.CreateEntityDialog=wc;exports.DEFAULT_LAYOUT=Ar;exports.DEFAULT_META_HOME_LINKS=md;exports.DEFAULT_READER_PREFS=Go;exports.DEFAULT_READ_HOME_LINKS=Zc;exports.DEFAULT_THEME=Ti;exports.DETAIL_CSS=Pl;exports.DYNASTY_GROUPS=xi;exports.Dash=th;exports.DataTable=Zm;exports.DetailFooter=Gl;exports.DetailGrid=Pn;exports.DetailHeader=Ml;exports.EMPTY_FILTERS=fi;exports.ENTITY_TEXT_CSS=fr;exports.EmendatedBySection=el;exports.EmptyNote=lh;exports.EntityDetail=Ka;exports.EntityMark=br;exports.EntityPage=Hc;exports.EntityPickerDialog=_c;exports.EntitySelector=kc;exports.EntityText=fg;exports.ExpandRow=nh;exports.ExtLink=ch;exports.FEEDBACK_FAB_OFFSET_VAR=$o;exports.FILTER_SUPPORT=Wa;exports.FONT_SIZE_STEPS=Ct;exports.FactList=Vm;exports.FeedbackButton=ix;exports.FeedbackDialog=Tc;exports.FeedbackForm=Nc;exports.FeedbackList=kr;exports.FeedbackTab=Ec;exports.FilterChip=Bl;exports.FormInput=pt;exports.FormTextArea=Yt;exports.GUJI_MARKDOWN_FIELD=Xu;exports.GUJI_TABLE_NOTATION=sl;exports.GlyphBadge=tr;exports.GujiInteractiveReader=ef;exports.GujiTable=ir;exports.GujiTextViewer=yr;exports.GujiWarpCanvas=hr;exports.HomePage=So;exports.ImagePanel=po;exports.IndexApp=Qg;exports.IndexBrowser=lo;exports.IndexDetail=Fo;exports.IndexEditor=$c;exports.IndexView=Df;exports.IntroGrid=Um;exports.LAYOUTS=Ob;exports.LAYOUT_STORAGE_KEY=Ii;exports.LOSS_OPTIONS=Ba;exports.LocaleContext=qt;exports.LocaleProvider=Ep;exports.LocaleToggle=No;exports.META_HOME_CSS=ud;exports.META_HOME_SECTION_IDS=Nd;exports.MetaCatalogTable=vd;exports.MetaCollectionGroups=_d;exports.MetaDataLicense=Td;exports.MetaHomeView=Tb;exports.MetaLine=et;exports.MetaLineageCards=Cd;exports.MetaOnlineSites=zd;exports.MetaPeopleTimeline=$d;exports.MetaRecentPanel=yd;exports.MetaRelatedCatalogs=wd;exports.MetaTypeChips=fd;exports.ModeIndicator=La;exports.MoreButton=Km;exports.MoreLink=Qo;exports.PAGE_MAX_WIDTH=ni;exports.PERIOD_NARROW_SHARE=td;exports.PageFrame=zn;exports.Quote=oh;exports.READER_CSS=gl;exports.READ_HOME_CSS=Nr;exports.READ_HOME_NARROW_QUERY=Hn;exports.READ_HOME_SECTION_IDS=pd;exports.READ_PERIOD_LABELS=yb;exports.RECENT_IDS_STORAGE_KEY=an;exports.ROLE_CLASS_ORDER=zl;exports.ReadButton=xo;exports.ReadFamousWorks=ld;exports.ReadHomeView=vb;exports.ReadPeriodBand=cd;exports.ReadPicks=od;exports.ReadPieces=dd;exports.ReadSection=st;exports.ReadShelf=Ir;exports.ReadSibu=Rr;exports.ReadStats=id;exports.ReadTopicGroup=sd;exports.ReadTopics=ad;exports.ReaderMdText=ar;exports.ReaderShell=kl;exports.ReaderToc=xl;exports.RelationPanel=jc;exports.RepoSourceLink=Eo;exports.ResourceEditor=so;exports.ResourceGroup=rh;exports.ResourceLine=sh;exports.ResourceList=Bo;exports.ResourceRow=Ul;exports.SEARCH_VIEW_STORAGE_KEY=Wo;exports.SEVEN_PAVILIONS_KEY=Sd;exports.SNIPPET_MARK_END=_a;exports.SNIPPET_MARK_START=Sa;exports.SORTABLE_TYPES=Ma;exports.SearchInput=Pa;exports.SearchResults=Va;exports.Sec=tt;exports.Section=yt;exports.SectionHead=Gm;exports.SideList=Gt;exports.SmartBidInput=oi;exports.SourceEditor=xc;exports.StripWarpRenderer=vo;exports.SummaryCard=Mn;exports.THEMES=Ed;exports.THEME_INIT_SCRIPT=Vb;exports.THEME_STORAGE_KEY=Ni;exports.TRADITIONAL_ALLOWLIST=Ea;exports.TabFilter=Si;exports.TableHead=Jm;exports.TableRow=Qm;exports.TagRow=Vl;exports.TagRows=ah;exports.TextButton=Ym;exports.TextReader=vr;exports.ThemeToggle=Yb;exports.TopStrip=bo;exports.VersionLineageGraph=Bc;exports.VersionLineageList=Mc;exports.VersionLineageView=$r;exports.VolumeChips=Xm;exports.VolumeLinks=nr;exports.WorkCard=Yc;exports.WorkCardGrid=Xc;exports.WorkCatalog=lf;exports.WorkPage=Ac;exports.WorkRow=Kc;exports.adaptCharCord=af;exports.adaptEntityJson=oc;exports.adaptGujiPages=nf;exports.adaptPunctJson=of;exports.applyLayout=Db;exports.applyTheme=Ld;exports.authorsLine=zi;exports.bookIndexUriToId=wo;exports.bucketResources=qo;exports.buildCatalogTree=sb;exports.buildCollectionTable=Nl;exports.buildLineageGraph=ri;exports.buildMeiliFilter=Kp;exports.buildPageUrl=Mo;exports.buildParagraphBlocks=Zl;exports.buildVersionRow=$l;exports.buildVersionTable=Cl;exports.canParagraphize=ci;exports.catalogNodeIdOf=ob;exports.catalogNodeIdsOf=rb;exports.catalogPageCount=db;exports.catalogTotal=Tr;exports.classificationPath=On;exports.clearAllRecentIds=Oo;exports.compareCatalogCards=cb;exports.computeVersionPartition=Rm;exports.countActiveFilters=yi;exports.createTextApi=dl;exports.currentLayout=Ub;exports.currentTheme=Ad;exports.defaultEntityHref=dc;exports.defaultWorkLink=Vc;exports.deriveDating=Nm;exports.deriveEditionType=Il;exports.deriveEra=An;exports.deriveYear=vi;exports.deriveYearRange=Ko;exports.detailToEditor=zc;exports.detectGenre=$i;exports.displayAuthorRole=Zo;exports.editorToDetail=Ff;exports.eraRank=go;exports.filtersFromParams=qp;exports.filtersToParams=si;exports.findCatalogPath=sn;exports.findTraditionalChars=Lp;exports.firstAuthorText=Er;exports.flattenTitles=jo;exports.flattenToc=vl;exports.fmtCount=Ye;exports.formatHitCount=ti;exports.formatTemplate=ut;exports.formatVolumeRange=wi;exports.getDisplayNameFromUrl=mn;exports.getMessages=pn;exports.getStartPage=Po;exports.getT=un;exports.getTypeGroupKey=Lo;exports.groupRelatedWorks=Em;exports.gujiInlineToPlain=rl;exports.hasActiveFilters=Oa;exports.hasGujiMarkdownV02=co;exports.hasGujiTableNotation=al;exports.hasSearchOptions=Vp;exports.iiifVolumeOf=rf;exports.isCountedChar=gr;exports.isLayoutName=Pd;exports.isThemeName=Id;exports.lineageHref=hd;exports.loadRecentIds=Pt;exports.measureText=Et;exports.mergeVolumeResources=Ao;exports.normalizeEra=Qe;exports.normalizeLayout=Ri;exports.normalizeRole=Xo;exports.normalizeTheme=Ei;exports.normalizeVolumeIndex=En;exports.normalizeVolumes=Ra;exports.numberToChinese=El;exports.paginationItems=Dc;exports.parseChineseNumber=ai;exports.parseGujiInline=ol;exports.parseGujiTable=cl;exports.parseSourceString=bc;exports.pct=Lr;exports.periodLevel=ed;exports.pickReaderVersion=jl;exports.readStoredLayout=Hb;exports.readStoredTheme=Wb;exports.readerVersionOptionLabel=mo;exports.remapPlainOffsets=rc;exports.removeRecentId=Ga;exports.renderFullTextBody=gh;exports.renderProperNames=Ql;exports.renderReaderInline=sr;exports.resolveRecentEntry=Ho;exports.resourceHref=hn;exports.resourceNote=ki;exports.resultTabFromParam=ru;exports.resultTabToParam=su;exports.roleFacets=Tl;exports.rowNo=eh;exports.sameFilters=Xp;exports.saveRecentId=ao;exports.segmentEntities=sc;exports.shelfColumns=Jc;exports.sortFor=Gp;exports.sortYear=li;exports.spineHeight=Qc;exports.splitFullTextTables=Uo;exports.splitHighlightSnippet=Io;exports.splitTableRow=ll;exports.storeLayout=Fb;exports.storeTheme=Rd;exports.stringifySources=yc;exports.summaryFromEntry=lc;exports.summaryFromItem=ac;exports.timelineLayout=gd;exports.toCatalogWorkCard=lb;exports.transportSummaryLoader=cc;exports.typeSupportsFilters=Ha;exports.useBidUrl=Je;exports.useChapterWarpData=mc;exports.useConvert=Re;exports.useEntitySummaryLoader=xr;exports.useI18n=J;exports.useReaderPrefs=yl;exports.useRecentEntries=xd;exports.useT=ze;exports.validateLineageGraph=$x;exports.volumeStats=hi;exports.withDefaultLinks=Mt;exports.withMetaLinks=Bt;exports.yearText=ui;
1865
+ `,gd={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function Wt(e){return{...gd,...e??{}}}function fd(e,n){if(e.lineage)return e.lineage(n);const o=e.item(n),r=o.indexOf("#"),[s,a]=r<0?[o,""]:[o.slice(0,r),o.slice(r)];return`${s}${s.includes("?")?"&":"?"}tab=lineage${a}`}function Pr(e,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(e/n*100)))}function xd(e){const n=e.filter(p=>Number.isFinite(p.birth_year)||Number.isFinite(p.death_year)),o=e.filter(p=>!n.includes(p));if(!n.length)return{min:0,max:0,placed:[],missing:o};const r=p=>{const u=Number.isFinite(p.birth_year)?p.birth_year:p.death_year-50,m=Number.isFinite(p.death_year)?p.death_year:p.birth_year+50;return[Math.min(u,m),Math.max(u,m)]},s=n.map(r),a=Math.min(...s.map(p=>p[0])),l=Math.max(...s.map(p=>p[1])),d=Math.max(1,l-a),c=n.map((p,u)=>({p,from:s[u][0],to:s[u][1]})).sort((p,u)=>p.from-u.from).map(p=>({...p,left:(p.from-a)/d*100,width:Math.max(.8,(p.to-p.from)/d*100)}));return{min:a,max:l,placed:c,missing:o}}function hi(e,n=mn("zh-Hant")){return e<0?n("metaHome.yearBC",{n:-e}):String(e)}function $b(e){return{read:e.item,work:e.item,node:e.node}}function bd({counts:e,links:n}){const{t:o}=J(),r=n==null?void 0:n.type;if(!r)return null;const s=[["all",o("metaHome.typeAll"),null],["work",o("metaHome.typeLabel.work"),e.works],["book",o("metaHome.typeLabel.book"),e.books],["collection",o("metaHome.typeLabel.collection"),e.collections],["entity",o("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":o("metaHome.typeChipsLabel"),children:s.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:r(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:Ye(d)})]})},a))})}function yd(e,n=5){const[o,r]=g.useState(null);g.useEffect(()=>{let a=!1;const l=Mt().slice(0,n);if(!l.length||!e){r([]);return}return Promise.all(l.map(d=>Do(e,d))).then(d=>{a||r(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,n]);const s=g.useCallback(()=>{Fo(),r([])},[]);return{entries:o,clear:s}}function Cb(e,n,o){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?o(r):jd(e.type,n)}function jd(e,n){return n(`metaHome.typeLabel.${e}`)}function vd({entries:e,onClear:n,links:o}){const{t:r,convert:s}=J(),a=Wt(o);return t.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[t.jsxs("div",{className:"bim-mh-recent-h",children:[t.jsx("h2",{id:"bim-mh-recent-h",children:r("metaHome.recentTitle")}),e&&e.length>0&&n&&t.jsx("button",{type:"button",onClick:n,children:r("metaHome.recentClear")})]}),e&&e.length>0&&t.jsx("ol",{children:e.map(l=>t.jsx("li",{children:t.jsxs("a",{href:a.item(l.id),"aria-label":r("metaHome.recentItemLabel",{type:l.type?jd(l.type,r):"",title:s(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?r(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:s(l.title)}),t.jsx("small",{"aria-hidden":"true",children:Cb(l,r,s)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function kd(e,n,o,r=!1){return r&&(e==="done"||e==="in_progress")?n(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?n(`metaHome.status.${e}`):o(e)}function wd({rows:e,links:n}){const{t:o,convert:r}=J(),s=Wt(n);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":o("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[o("metaHome.catalogTitle"),t.jsx("small",{children:o("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:o("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:o("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:o("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:o("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:o("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=Pr(a.imported,a.total),d=a.work_id??a.collection_id,c=r(a.edition?`${a.name}·${a.edition}`:a.name);return t.jsxs("tr",{children:[t.jsx("th",{scope:"row",children:d?t.jsx("a",{href:s.item(d),children:c}):c}),t.jsx("td",{className:"bim-mh-r",children:Ye(a.total)}),t.jsx("td",{className:"bim-mh-r",children:Ye(a.imported)}),t.jsx("td",{children:t.jsxs("span",{className:"bim-mh-meter",children:[t.jsx("i",{"aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[l,"%"]})]})}),t.jsx("td",{children:a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:kd(a.status,o,r)})})]},a.id||a.name)})})]})}):null}function Sd({items:e,links:n,label:o}){const{convert:r}=J();return t.jsx("ul",{className:"bim-rh-rows","aria-label":o?r(o):void 0,children:e.map(s=>t.jsx("li",{children:t.jsxs("a",{href:n.item(s.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(s.title)}),s.sub&&t.jsx("small",{children:r(s.sub)})]})},s.id))})}function _d({works:e,links:n}){const{t:o}=J(),[r,s]=g.useState(!1);if(!e.length)return null;const a=Pn(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":r?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[o("metaHome.relatedTitle"),t.jsx("small",{children:o("metaHome.relatedNote")})]}),t.jsx(Sd,{items:e.map(l=>({id:l.id,title:l.title,sub:Ni(l)||void 0})),links:Wt(n)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":r,onClick:()=>s(l=>!l),children:r?o("action.collapse"):o("metaHome.allNWorks",{n:e.length})})]})}const $d="siku_qige";function zb({group:e,links:n}){const{t:o,convert:r}=J(),[s,a]=g.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Pn(e.items.length)?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:o("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(Sd,{items:e.items,links:n,label:e.label}),Pn(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>a(l=>!l),children:s?o("action.collapse"):o("metaHome.allNKinds",{n:e.items.length})})]})}function Cd({groups:e,links:n}){const{t:o,convert:r}=J(),s=Wt(n);if(!e.length)return null;const a=e.find(c=>c.key===$d),l=e.filter(c=>c!==a),d=c=>{var p;return((p=c.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:p[1])??c};return t.jsxs(t.Fragment,{children:[a&&t.jsxs(t.Fragment,{children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(a.label),t.jsx("small",{children:r(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":r(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:s.item(c.id),"aria-label":r(c.title),title:r(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:r(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:o("metaHome.pavilion")})]})},c.id))})]}),l.length>0&&t.jsx("div",{className:"bim-mh-cg",style:a?void 0:{marginTop:0},children:l.map(c=>t.jsx(zb,{group:c,links:s},c.key))})]})}const va=34,ka=13;function wa(e,n){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?hi(e.birth_year,n):"?"}–${e.death_year!=null?hi(e.death_year,n):"?"}`}function Tb(e,n){const o=n-e,r=o>1200?300:o>400?100:50,s=[];for(let a=Math.ceil(e/r)*r;a<=n;a+=r)s.push(a);return s}function zd({people:e,links:n}){const{t:o,convert:r}=J(),s=Wt(n);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=xd(e),p=[],u=d.map(h=>{const f=h.left>70,x=f?Math.min(h.left,h.left+h.width-ka):h.left;let k=0;for(;p[k]!=null&&p[k]>x;)k++;return p[k]=f?h.left+h.width:h.left+Math.max(h.width,ka),{...h,lane:k,end:f}}),m=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:p.length*va+10},children:u.map(h=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":h.end?"":void 0,style:{left:`${h.left}%`,top:h.lane*va+4,width:`${Math.max(h.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:s.item(h.p.id),children:[r(h.p.name),t.jsx("small",{className:"bim-rh-num",children:wa(h.p,o)})]})]},h.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:Tb(a,l).map(h=>t.jsx("span",{style:{left:`${(h-a)/m*100}%`},children:hi(h,o)},h))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":u.length?void 0:"",children:(u.length?e:c).map(h=>t.jsx("li",{children:t.jsxs("a",{href:s.item(h.id),children:[t.jsx("span",{children:r(h.name)}),t.jsx("small",{className:"bim-rh-num",children:[h.dynasty?r(h.dynasty):"",wa(h,o)].filter(Boolean).join(" ")})]})},h.id))}),c.length>0&&u.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:o("metaHome.missingLife",{names:r(c.map(h=>h.name).join("、"))})})]})}const Nb=t.jsxs("svg",{width:"54",height:"34",viewBox:"0 0 54 34",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",children:[t.jsx("circle",{cx:"27",cy:"5",r:"3.5"}),t.jsx("circle",{cx:"10",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"27",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"44",cy:"29",r:"3.5"}),t.jsx("path",{d:"M27 8.5v17M27 15H10v10.5M27 15h17v10.5"})]});function Td({works:e,links:n}){const{t:o,convert:r}=J(),s=Wt(n);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=Ni(a);return t.jsx("li",{children:t.jsxs("a",{href:fd(s,a.id),children:[Nb,t.jsx("b",{children:r(a.title)}),l&&t.jsx("small",{children:r(l)}),t.jsx("span",{children:o("metaHome.viewLineage")})]})},a.id)})}):null}function Nd({sites:e}){const{t:n,convert:o}=J(),r=e.filter(a=>a.status!=="todo"&&a.total>0),s=e.filter(a=>!r.includes(a));return e.length?t.jsxs(t.Fragment,{children:[r.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:r.map(a=>{const l=Pr(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:o(a.name)}):t.jsx("span",{children:o(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${Ye(a.imported)} / ${Ye(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:kd(a.status,n,o,!0)})]})]},a.id||a.name)})}),s.length>0&&t.jsx("p",{className:"bim-mh-todo",children:n("metaHome.plannedSites",{names:o(s.map(a=>a.name).join("、"))})})]}):null}const Sa=["extant","partially_extant","lost","unknown"];function Rd({stats:e,links:n,version:o,repoUrl:r,downloadHref:s}){const{t:a}=J(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(p=>[e[p],a(`metaHome.stat.${p}`)]).filter(([p])=>p>0),d=n==null?void 0:n.loss,c=Sa.some(p=>{var u;return(((u=e.loss)==null?void 0:u[p])??0)>0});return t.jsxs("div",{className:"bim-mh-data",children:[l.length>0&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.dataScale")}),t.jsx("ul",{className:"bim-mh-nums",children:l.map(([p,u])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:Ye(p)}),t.jsx("span",{children:u})]},u))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:Sa.map(p=>{var h;const u=((h=e.loss)==null?void 0:h[p])??0,m=a(`metaHome.lossNote.${p}`);return t.jsx("li",{children:t.jsxs("a",{href:d(p),children:[a(`metaHome.loss.${p}`),t.jsx("small",{className:"bim-rh-num",children:c&&u>0?a("metaHome.lossCount",{n:Ye(u),note:m}):m})]})},p)})})]}),t.jsxs("div",{className:"bim-mh-lic",children:[t.jsxs("p",{children:[t.jsx("span",{className:"bim-mh-cc0",children:"CC0"}),a("metaHome.license")]}),t.jsxs("p",{children:[a("metaHome.repo"),r?t.jsx("a",{href:r,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),o&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:o})]}),s&&t.jsx("p",{children:t.jsx("a",{href:s,children:a("metaHome.download")})})]})]})}const Ed={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function Rb({sections:e,links:n,head:o,transport:r,catalogHref:s,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:p,className:u}){var v,$;const{t:m}=J(),h=e,f=Wt(n),x=$b(f),k=Ed,y=yd(r),w={zhi:!!((v=h.shelf)!=null&&v.items.length)||h.catalog_progress.length>0||h.related_catalogs.length>0,sibu:h.bu.length>0||h.unclassified>0,cong:h.collection_groups.length>0,people:h.bibliographers.length>0,lineage:h.lineage.length>0,sites:h.sites.length>0,data:!0},b=Object.keys(k).filter(_=>w[_]),j=_=>m(`metaHome.nav.${_}`),S=(_,C)=>_?t.jsx("a",{className:"bim-rh-more",href:_,children:C}):void 0;return t.jsxs("div",{className:u?`bim-rh bim-mh ${u}`:"bim-rh bim-mh",children:[t.jsx("style",{children:Er+hd}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[o,t.jsx(bd,{counts:h.counts,links:n})]}),r&&t.jsx(vd,{entries:y.entries,onClear:y.clear,links:n})]}),b.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":m("metaHome.navLabel"),children:t.jsx("ul",{children:b.map(_=>t.jsx("li",{children:t.jsx("a",{href:`#${k[_]}`,children:j(_)})},_))})}),t.jsxs("div",{className:"bim-rh-main",children:[w.zhi&&t.jsxs(st,{id:k.zhi,title:j("zhi"),sub:m("metaHome.zhiSub"),children:[h.shelf&&h.shelf.items.length>0&&t.jsx(Lr,{topic:{key:"shelf",label:h.shelf.label,shelf:!0,items:h.shelf.items},links:x,showTitle:!1,legendCount:h.shelf.items.some(_=>_.records)?m("metaHome.shelfLegendCount"):null,legendExtra:[m("metaHome.shelfLegendClick")]}),(h.catalog_progress.length>0||h.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:($=h.shelf)!=null&&$.items.length?void 0:{marginTop:0},children:[t.jsx(wd,{rows:h.catalog_progress,links:n}),t.jsx(_d,{works:h.related_catalogs,links:n})]})]}),w.sibu&&t.jsx(st,{id:k.sibu,title:j("sibu"),sub:m("metaHome.sibuSub"),more:S(s,m("metaHome.toCatalog")),children:t.jsx(Ar,{bu:h.bu,unclassified:h.unclassified,links:x,unclassifiedNote:m("metaHome.unclassifiedNote")})}),w.cong&&t.jsx(st,{id:k.cong,title:j("cong"),sub:m("metaHome.congSub"),more:S(a,m("metaHome.allNKindsMore",{n:Ye(h.counts.collections)})),children:t.jsx(Cd,{groups:h.collection_groups,links:n})}),w.people&&t.jsx(st,{id:k.people,title:j("people"),sub:m("metaHome.peopleSub"),more:S(l,m("metaHome.allNPeopleMore",{n:Ye(h.counts.entities)})),children:t.jsx(zd,{people:h.bibliographers,links:n})}),w.lineage&&t.jsx(st,{id:k.lineage,title:j("lineage"),sub:m("metaHome.lineageSub"),children:t.jsx(Td,{works:h.lineage,links:n})}),w.sites&&t.jsx(st,{id:k.sites,title:j("sites"),sub:m("metaHome.sitesSub"),children:t.jsx(Nd,{sites:h.sites})}),t.jsx(st,{id:k.data,title:j("data"),sub:m("metaHome.dataSub"),children:t.jsx(Rd,{stats:h.stats,links:n,version:d,repoUrl:c,downloadHref:p})})]})]})}const vt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),nt=e=>Array.isArray(e),Eb=e=>vt(e)&&!!e.h;function Ib(e){if(!e)return!1;for(const n of["_related","_catalogs","_collections","_works","_members","_children"]){const o=e[n];if(nt(o)&&o.some(Eb))return!0}return!1}function ni(e,n){var r;if(typeof e.title=="string"&&e.title)return e.title;const o=e.id??e.bid;return e.h&&o&&((r=n==null?void 0:n[o])!=null&&r.title)?n[o].title:""}function Lb(e){const n=e.filter(vt);return n.find(o=>o.scheme==="zongmu")??n[0]??null}const Ab=e=>typeof e=="number"?e:nt(e)&&typeof e[0]=="number"?e[0]:void 0;function Ro(e,n){if(!vt(e))return e;const o={...e},r=e.type;if(r==="work"){if(!nt(e.books)&&nt(e._books)&&(o.books=e._books.filter(vt).map(s=>s.id).filter(s=>typeof s=="string")),!vt(e.classification)&&nt(e._classifications)){const s=Lb(e._classifications);s&&(o.classification={l1:s.l1??"",l2:s.l2??"",l3:s.l3??"",l4:s.l4??"",...s.source?{source:s.source}:{}})}nt(e._related)&&(o.related_works=e._related.filter(vt).map(s=>{const a=s;return{id:a.id,title:ni(a,n),...a.relation?{relation:a.relation}:{},...a.note?{note:a.note}:{}}})),!nt(e.indexed_by)&&nt(e._catalogs)&&e._catalogs.length&&(o.indexed_by=e._catalogs.filter(vt).map(s=>{const a=s;return{source:ni(a,n)||String(a.bid??""),...a.bid?{source_bid:a.bid}:{},...a.section?{section:a.section}:{}}}))}if((r==="work"||r==="book")&&!nt(e.contained_in)&&nt(e._collections)&&e._collections.length&&(o.contained_in=e._collections.filter(vt).map(s=>{const a=s;return{id:a.id,...a.vol!=null?{volume_index:a.vol}:{},...a.sub!=null?{sub_items:a.sub}:{}}})),r==="collection"&&nt(e._members)){const s=e._members.filter(vt),a=typeof e._member_count=="number"?e._member_count:s.length,l=d=>d.t==="work";if(!nt(e.books)){const d=s.filter(c=>!l(c)).map(c=>c.id).filter(c=>typeof c=="string");d.length&&(o.books=d)}if(!nt(e.contained_works)){const d=s.filter(l).map(c=>{const p=Ab(c.vol);return{id:c.id,title:ni(c,n),...p!=null?{volume_index:p}:{}}});d.length&&(o.contained_works=d)}a>s.length&&(o._members_truncated=!0)}return r==="entity"&&!nt(e.works)&&nt(e._works)&&(o.works=e._works.filter(vt).map(s=>{const a=s,l=ni({...a,id:a.work_id},n);return{...a,work_id:a.work_id,...l?{title:l}:{}}})),o}function Pb(e){let n=null;const o=()=>e.getHubs?(n??(n=e.getHubs().catch(()=>null)),n):Promise.resolve(null),r=async s=>s&&Ro(s,Ib(s)?await o():null);return new Proxy(e,{get(s,a,l){if(a==="getItem")return async c=>r(await s.getItem(c));const d=Reflect.get(s,a,s);return typeof d=="function"?d.bind(s):d}})}const Eo=({style:e})=>{const n=g.useContext(Xt),{t:o}=J();if(!n)return null;const{locale:r,setLocale:s}=n,a=r==="zh-Hant",l=()=>s(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:o(a?"common.toHans":"common.toHant"),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:a?i("primary"):void 0,fontWeight:a?700:400},children:o("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:i("primary"),fontWeight:a?400:700},children:o("common.localeShortHans")})]})},Io=({href:e,label:n,size:o=16,className:r,style:s})=>{const{t:a}=J(),l=n??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,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:d=>{d.currentTarget.style.color=i("fg")},onMouseLeave:d=>{d.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 so(e){const n=e.text_count;return typeof n=="number"&&n>0}function ao(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function Mb(e,n){if(!n)return!1;const o=n.id;return o===void 0||o===e}const Bb=({id:e,transport:n,initialDetail:o,initialEntry:r,activeTab:s,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:p,lineageCollection:u,onLineageCollectionChange:m,initialPage:h=1,selectedLineageNodeId:f,onNavigate:x,onBack:k,backLabel:y,renderLink:w,enrichDetail:b,getSourceLink:j,readLink:S,railTop:v,extraTabs:$=[],showFeedbackTab:_=!0,feedbackApiUrl:C,height:M,footerExtra:N,hideHeaderControls:T=!1,className:F,style:R})=>{const E=g.useMemo(()=>Pb(n),[n]),L=Te(),{t:I,convert:P}=J(),[V]=g.useState(()=>{if(!Mb(e,o))return null;const K=Ro({...o}),fe=r??ao(e,K);return b&&b(fe,K),{id:e,entry:fe,detail:K}}),[X,D]=g.useState((V==null?void 0:V.entry)??null),[O,A]=g.useState((V==null?void 0:V.detail)??null),[G,se]=g.useState(!V),[Q,ve]=g.useState(!1),[ne,ce]=g.useState([]),[We,ke]=g.useState(!1),[Pe,Ee]=g.useState(null),[Z,le]=g.useState(null),[oe,he]=g.useState(null),[U,$e]=g.useState(!1),me=g.useRef(null),Ce=g.useRef(0),[Y,ze]=g.useState(null),Me=l!==void 0?l:Y,B=g.useCallback(K=>{d?d(K):ze(K)},[d]),te=g.useCallback(async K=>{if(!E.getCollectionCatalogs&&!E.getCollectionCatalog){ce([]);return}ke(!0);try{if(E.getCollectionCatalogs)ce(await E.getCollectionCatalogs(K)||[]);else if(E.getCollectionCatalog){const fe=await E.getCollectionCatalog(K);ce(fe?[{resource_id:"",data:fe}]:[])}}catch{ce([])}finally{ke(!1)}},[E]),xe=g.useCallback(async K=>{var fe,Ne;if(!E.getTextManifest||!E.getTextIndex){Ee(null),le(K);return}try{const q=_e.pickTextVersion(await E.getTextManifest(K)),ue=q?await E.getTextIndex(K,q.key):null;Ee(ue&&ue.chapters.length>0?{chapters:ue.chapters.map(re=>({n:re.n,title:re.title,file:re.file})),source:{name:((fe=ue.source)==null?void 0:fe.name)??(q==null?void 0:q.source_name),license:((Ne=ue.source)==null?void 0:Ne.license)??(q==null?void 0:q.license)??void 0}}:null)}catch{Ee(null)}finally{le(K)}},[E]),Re=g.useCallback(async(K,fe)=>{const Ne=++Ce.current,q=()=>Ne!==Ce.current;$e(!0);try{if(E.getLineageGraph){const lt=await E.getLineageGraph(K);if(q())return;lt&&he(lt)}const ue=fe.version_graph;if(!ue||!ue.enabled){oe||he(null),me.current=null;return}const re=fe.books??[],we=[];for(const lt of re)try{const Rt=await E.getItem(lt);Rt&&we.push(Rt)}catch{}if(q())return;me.current={work:fe,books:we};const Ve=u??ue.default_collection??(ue.core_books&&ue.core_books.length>0?"core":"all"),Oe=Ve==="core"&&Array.isArray(ue.core_books)&&ue.core_books.length>0?"core":Ve??"all";he(ai(fe,we,Oe))}catch{if(q())return;he(null),me.current=null}finally{q()||$e(!1)}},[E]),H=g.useRef({initialDetail:o,initialEntry:r});H.current={initialDetail:o,initialEntry:r},g.useEffect(()=>{let K=!1;Ce.current++,$e(!1);const fe=re=>{re.type==="collection"?te(e):re.type==="work"?(re.version_graph||E.getLineageGraph)&&Re(e,re):re.type==="book"&&so(re)&&xe(e)},Ne=H.current;let q=null;if(V&&V.id===e)q=V;else if(Ne.initialDetail&&Ne.initialDetail.id===e){const re=Ro({...Ne.initialDetail}),we=Ne.initialEntry??ao(e,re);b&&b(we,re),q={entry:we,detail:re}}return q?(ve(!1),ce(re=>re.length?[]:re),Ee(null),he(null),me.current=null,D(q.entry),A(q.detail),se(!1),fe(q.detail),()=>{K=!0}):((async()=>{se(!0),ve(!1),D(null),A(null),ce([]),Ee(null),he(null),me.current=null;try{const re=await E.getItem(e);if(K)return;if(!re){ve(!0);return}const we=re;let Ve=null;if(E.getEntry&&(Ve=await E.getEntry(e),K))return;Ve||(Ve=ao(e,we)),b&&b(Ve,we),D(Ve),A(we),fe(we)}catch{K||ve(!0)}finally{K||se(!1)}})(),()=>{K=!0})},[e,E,V,b,te,Re,xe]),g.useEffect(()=>{const K=me.current;!K||!u||he(ai(K.work,K.books,u))},[u]);const de=[];if(O){if(de.push({key:"basic",label:L.detailTab.basicInfo}),O.type==="collection"){We&&ne.length===0&&de.push({key:"catalog:loading",label:`${L.detailTab.catalog}…`});for(const K of ne)de.push({key:`catalog:${K.resource_id}`,label:K.short_name?`${P(K.short_name)}${L.detailTab.catalogSuffix}`:L.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&de.push({key:s,label:L.detailTab.fullText}),O.type==="work"&&(oe||U)&&de.push({key:"lineage",label:U?`${L.detailTab.lineage}…`:L.detailTab.lineage});for(const K of $)(K.position??"before-feedback")==="before-feedback"&&K.shouldShow(O)&&de.push({key:K.key,label:K.label});_&&s==="feedback"&&de.push({key:"feedback",label:L.detailTab.feedback});for(const K of $)K.position==="after-feedback"&&K.shouldShow(O)&&de.push({key:K.key,label:K.label})}g.useEffect(()=>{if(s!=="emendated"||!O)return;a("basic");const K=setTimeout(()=>{var fe;(fe=document.getElementById("studies"))==null||fe.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(K)},[s,O,a]);const ee=X&&O&&j?j({activeTab:s,activeJuan:Me,entry:X,detail:O}):null,ye=g.useMemo(()=>{var ue;if(!O)return null;const fe=(O.authors??[]).map(re=>{const we=Qo(re.role);return`${re.dynasty?`〔${P(re.dynasty)}〕`:""}${P(re.name)}${we?` ${P(we)}`:""}`}).join(" · ");let Ne=!1;try{Ne=_e.extractStatus(O.id)==="draft"}catch{}if(O.type==="book"){const re=O;return{title:P(re.title),subtitle:re.edition?P(re.edition):fe||void 0,aside:[Ne?L.status.draft:"",fe&&re.edition?fe:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(O.type==="collection"){const re=O;return{title:P(re.title),subtitle:P(Nt(re,L.unit.juan))||void 0,aside:[(ue=re.publication_info)==null?void 0:ue.year,Ne?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:fe||void 0}}if(O.type==="entity"){const re=O,we=Oe=>Oe==null?"":Oe<0?I("detail.bce",{n:-Oe}):String(Oe),Ve=re.birth_year!=null||re.death_year!=null?`${we(re.birth_year)||"?"}—${we(re.death_year)||"?"}`:"";return{title:P(re.primary_name||re.title),subtitle:[re.dynasty?`〔${P(re.dynasty)}〕`:"",Ve].filter(Boolean).join(" ")||void 0,aside:Ne?L.status.draft:void 0,secondLine:void 0}}const q=P(Nt(O,L.unit.juan));return{title:P(O.title),subtitle:[q,fe].filter(Boolean).join(" · ")||void 0,aside:[Ob(L,O.subtype),Ne?L.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[O,P,L,I]),Se=O&&so(O)?"text":null,Be=()=>{B(null),a("fulltext")};let De=null;if(O&&S){const K=S({detail:O,kind:Se});K&&(De=t.jsx(yo,{href:K}))}else Se&&(De=t.jsx(yo,{onClick:Be}));const Je=K=>{if(!O)return null;const fe=K.replace(/\.[^.]+$/,"");if(S){const Ne=S({detail:O,kind:Se,juan:fe});return Ne?{href:Ne}:null}return{onClick:()=>{B(fe),a("fulltext")}}},He=new Set($.map(K=>K.key)),Ue=de.filter(K=>K.key.startsWith("catalog:")&&K.key!=="catalog:loading"||K.key==="lineage"&&!!oe&&!U||He.has(K.key)).map(K=>({key:K.key,label:K.label,onClick:()=>a(K.key)})),z=()=>{var K;return O?O.type==="work"?t.jsx(Mc,{data:O,transport:E,onNavigate:x,renderLink:w,readAction:De,railTop:v,railLinks:Ue}):O.type==="book"?t.jsx(Hc,{data:O,transport:E,onNavigate:x,renderLink:w,readAction:De,fullText:Pe,fullTextPending:so(O)&&!!E.getTextManifest&&Z!==O.id,chapterLink:Je,railTop:v,railLinks:Ue}):O.type==="collection"?t.jsx(Fc,{data:O,catalog:(K=ne[0])==null?void 0:K.data,transport:E,onNavigate:x,renderLink:w,readAction:De,railTop:v,railLinks:Ue,catalogAction:ne.length>0?t.jsxs("a",{href:"#catalog",onClick:fe=>{fe.preventDefault(),a(`catalog:${ne[0].resource_id}`)},children:[P(L.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Dc,{data:O,transport:E,onNavigate:x,renderLink:w,railTop:v,railLinks:Ue}):null},ie=()=>{var fe,Ne,q;if(!X||!O)return null;if(s==="basic"||s==="emendated")return z();if(typeof s=="string"&&s.startsWith("catalog:")){const ue=(fe=ne.find(re=>`catalog:${re.resource_id}`===s))==null?void 0:fe.data;return t.jsx(Vo,{data:ue,onNavigate:x,renderLink:w})}if(s==="collated"||s==="fulltext")return t.jsx(wr,{id:e,transport:E,chapter:Me,onLocationChange:ue=>B(ue.chapter),onNavigate:x});if(s==="lineage"){if(!oe)return t.jsx("div",{style:{color:i("label-fg"),padding:"24px 0"},children:I(U?"detail.loading":"detail.noLineageGraph")});const ue=O.type==="work"?O:null;return t.jsx(zr,{graph:oe,renderLink:w,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:p,selectedNodeId:f,collection:u??((Ne=ue==null?void 0:ue.version_graph)==null?void 0:Ne.default_collection),onCollectionChange:m,collectionsAvailable:(q=ue==null?void 0:ue.version_graph)==null?void 0:q.collections,collectionCounts:(()=>{var Oe,lt,Rt,Ge,Et,Ot,Qt;if(!ue)return;const re={},we=((Oe=me.current)==null?void 0:Oe.books)??[];re.all=(((lt=ue.books)==null?void 0:lt.length)??0)-(((Ge=(Rt=ue.version_graph)==null?void 0:Rt.excluded_books)==null?void 0:Ge.length)??0);const Ve=(Et=ue.version_graph)==null?void 0:Et.collections;if(Ve)for(const xn of Object.keys(Ve))re[xn]=ai(ue,we,xn).nodes.filter(Un=>Un.kind==="book"&&!Un.bridge).length;return re.core==null&&((Qt=(Ot=ue.version_graph)==null?void 0:Ot.core_books)!=null&&Qt.length)&&(re.core=ue.version_graph.core_books.length),re})()})}if(s==="feedback"&&_)return t.jsx(Ic,{resourceId:e,apiUrl:C});const K=$.find(ue=>ue.key===s);return K?K.render({detail:O,entry:X,transport:E,onNavigate:x}):null};if(G)return t.jsx(Nn,{style:{minHeight:M,...R},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((K,fe)=>t.jsx("div",{style:{height:fe===1?40:16,width:K,opacity:.35,background:i("rule")}},fe))})});if(Q||!O||!X||!ye)return t.jsx(Nn,{style:{minHeight:M,...R},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:i("label-fg"),fontSize:14},children:I("detail.notFound")})});const ae=s==="basic"||s==="emendated",be=[{label:y??L.detailTab.backToIndex,onClick:k}];if(O.type==="book"&&O.work_id){const K=O.work_id;be.push({label:L.indexType.work,id:K,onClick:()=>x==null?void 0:x(K)})}be.push({label:L.indexType[O.type]});const je=s==="collated"||s==="fulltext",ge=typeof N=="string"?L.status[N.trim()]??N:N,Ie=t.jsx(Kl,{left:t.jsxs(t.Fragment,{children:[ge,ge?" · ":"",t.jsx(Wb,{id:O.id,label:L.label.id,copied:L.action.copied,copyLabel:L.action.copy})]}),right:t.jsxs(t.Fragment,{children:[_&&!ae&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:L.detailTab.submitVersion}),ee&&t.jsx("a",{href:ee.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:i("meta-fg")},children:L.detailTab.dataLicense})]})});return ae?t.jsx("div",{className:F,children:t.jsxs(Nn,{grid:!0,style:{minHeight:M,...R},children:[t.jsx(jo,{breadcrumb:t.jsx(vo,{items:be}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Eo,{style:{border:"none",background:"transparent"}}),!T&&ee&&t.jsx(Io,{...ee})]})}),z(),Ie]})}):t.jsx("div",{className:F,children:t.jsxs(Nn,{wide:je,style:{minHeight:M,...R},children:[t.jsx(jo,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(ir,{char:"籍"}),t.jsx(vo,{items:be})]}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Eo,{}),_&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("meta-fg")},children:L.detailTab.feedback}),!T&&ee&&t.jsx(Io,{...ee})]})}),t.jsx(Wl,{...ye,aside:je?t.jsxs("button",{type:"button",onClick:()=>a("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:i("accent"),borderBottom:`1px solid ${i("rule")}`},children:[I("detail.workInfo")," →"]}):ye.aside}),!je&&de.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:de.map(K=>t.jsx(Ol,{label:K.label,active:K.key===s||ae&&K.key==="basic",onClick:()=>a(K.key)},K.key))}),t.jsx("div",{style:{marginTop:!je&&de.length>1?8:0},children:ie()}),Ie]})})};function Wb({id:e,label:n,copied:o,copyLabel:r}){const[s,a]=g.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var l;(l=navigator.clipboard)==null||l.writeText(e).then(()=>{a(!0),setTimeout(()=>a(!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 Ob(e,n){return n?e.workSubtype[n]??n:""}const Id=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Ri="zhusha",Ei="bim-theme";function Ld(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Ii(e){return Ld(e)?e:Ri}function Hb(){try{return Ii(window.localStorage.getItem(Ei))}catch{return Ri}}function Ad(e){try{window.localStorage.setItem(Ei,e)}catch{}}function Pd(e){const n=Ii(e);return document.documentElement.setAttribute("data-theme",n),n}function Md(){return Ii(document.documentElement.getAttribute("data-theme"))}const Fb=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],Mr="airy",Li="bim-layout";function Bd(e){return e==="airy"||e==="boxed"}function Ai(e){return Bd(e)?e:Mr}function Db(){try{return Ai(window.localStorage.getItem(Li))}catch{return Mr}}function Ub(e){try{window.localStorage.setItem(Li,e)}catch{}}function Vb(e){const n=Ai(e);return document.documentElement.setAttribute("data-layout",n),n}function Gb(){return Ai(document.documentElement.getAttribute("data-layout"))}const Yb=`try{var t=localStorage.getItem(${JSON.stringify(Ei)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Li)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,Kb={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},qb=({onChange:e,style:n})=>{const{t:o}=J(),[r,s]=g.useState(Ri);g.useEffect(()=>{s(Md())},[]);const a=l=>{s(Pd(l)),Ad(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":o("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...n},children:Id.map(l=>{const d=r===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":o(`common.theme.${l.name}`),title:o(`common.theme.${l.name}`),onClick:()=>a(l.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(Kb[l.name]),boxShadow:d?`0 0 0 2px ${i("page-bg")}, 0 0 0 3.5px ${i("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=_e.BidLink;exports.BookIndexError=_e.BookIndexError;exports.BookIndexManager=_e.BookIndexManager;exports.BookIndexStorage=_e.BookIndexStorage;exports.BundleStorage=_e.BundleStorage;exports.ConfigError=_e.ConfigError;exports.GithubStorage=_e.GithubStorage;exports.IdGenerationError=_e.IdGenerationError;exports.IdGenerator=_e.IdGenerator;exports.LocalStorage=_e.LocalStorage;exports.MigrationError=_e.MigrationError;exports.StorageError=_e.StorageError;exports.VARIANT_CHARS=_e.VARIANT_CHARS;exports.base36Decode=_e.base36Decode;exports.base36Encode=_e.base36Encode;exports.base58Decode=_e.base58Decode;exports.buildId=_e.buildId;exports.buildPromotionMap=_e.buildPromotionMap;exports.cleanName=_e.cleanName;exports.decodeId=_e.decodeId;exports.decodeIdString=_e.decodeIdString;exports.encodeId=_e.encodeId;exports.extractIdFromUrl=_e.extractIdFromUrl;exports.extractStatus=_e.extractStatus;exports.extractType=_e.extractType;exports.isChapterSegment=_e.isChapterSegment;exports.isTextKey=_e.isTextKey;exports.matchChapterAcrossVersions=_e.matchChapterAcrossVersions;exports.normalizeCatalog=_e.normalizeCatalog;exports.normalizeVariants=_e.normalizeVariants;exports.parseId=_e.parseId;exports.pickTextVersion=_e.pickTextVersion;exports.shardOf=_e.shardOf;exports.smartDecode=_e.smartDecode;exports.textVersionLabel=_e.textVersionLabel;exports.validateResource=_e.validateResource;exports.Badge=mi;exports.BidUrlProvider=sp;exports.BookDetailLayout=Bb;exports.BookPage=Hc;exports.Breadcrumb=vo;exports.CATALOG_ALL_ID=Ct;exports.CATALOG_CSS=Uc;exports.CATALOG_NARROW_QUERY=Tr;exports.CATALOG_PAGE_SIZE=Nr;exports.CATALOG_UNCLASSIFIED_ID=Gt;exports.CLASSIFICATIONS=ji;exports.COMMON_TRADITIONAL_CHARS=Ea;exports.CardFoot=On;exports.CatalogPage=xb;exports.CatalogPager=Zc;exports.CatalogTree=Gc;exports.CheckFilter=Pl;exports.Chip=Hl;exports.ChipWall=Zm;exports.CollectionCatalog=Vo;exports.CollectionPage=Fc;exports.CreateEntityDialog=_c;exports.DEFAULT_LAYOUT=Mr;exports.DEFAULT_META_HOME_LINKS=gd;exports.DEFAULT_READER_PREFS=Ko;exports.DEFAULT_READ_HOME_LINKS=Qc;exports.DEFAULT_THEME=Ri;exports.DETAIL_CSS=Bl;exports.DYNASTY_GROUPS=yi;exports.Dash=ih;exports.DataTable=Qm;exports.DetailFooter=Kl;exports.DetailGrid=Bn;exports.DetailHeader=Wl;exports.EMPTY_FILTERS=bi;exports.ENTITY_TEXT_CSS=br;exports.EmendatedBySection=nl;exports.EmptyNote=dh;exports.EntityDetail=Xa;exports.EntityMark=jr;exports.EntityPage=Dc;exports.EntityPickerDialog=Cc;exports.EntitySelector=Sc;exports.EntityText=bg;exports.ExpandRow=oh;exports.ExtLink=ph;exports.FEEDBACK_FAB_OFFSET_VAR=zo;exports.FILTER_SUPPORT=Ha;exports.FONT_SIZE_STEPS=$t;exports.FactList=Ym;exports.FeedbackButton=rx;exports.FeedbackDialog=Rc;exports.FeedbackForm=Ec;exports.FeedbackList=Sr;exports.FeedbackTab=Ic;exports.FilterChip=Ol;exports.FormInput=ut;exports.FormTextArea=Kt;exports.GUJI_MARKDOWN_FIELD=Ju;exports.GUJI_TABLE_NOTATION=ll;exports.GlyphBadge=ir;exports.GujiInteractiveReader=nf;exports.GujiTable=rr;exports.GujiTextViewer=vr;exports.GujiWarpCanvas=fr;exports.HomePage=$o;exports.ImagePanel=mo;exports.IndexApp=tf;exports.IndexBrowser=po;exports.IndexDetail=Uo;exports.IndexEditor=zc;exports.IndexView=Vf;exports.IntroGrid=Gm;exports.LAYOUTS=Fb;exports.LAYOUT_STORAGE_KEY=Li;exports.LOSS_OPTIONS=Oa;exports.LocaleContext=Xt;exports.LocaleProvider=Ip;exports.LocaleToggle=Eo;exports.META_HOME_CSS=hd;exports.META_HOME_SECTION_IDS=Ed;exports.MetaCatalogTable=wd;exports.MetaCollectionGroups=Cd;exports.MetaDataLicense=Rd;exports.MetaHomeView=Rb;exports.MetaLine=et;exports.MetaLineageCards=Td;exports.MetaOnlineSites=Nd;exports.MetaPeopleTimeline=zd;exports.MetaRecentPanel=vd;exports.MetaRelatedCatalogs=_d;exports.MetaTypeChips=bd;exports.ModeIndicator=Pa;exports.MoreButton=Xm;exports.MoreLink=tr;exports.PAGE_MAX_WIDTH=oi;exports.PERIOD_NARROW_SHARE=id;exports.PageFrame=Nn;exports.Quote=sh;exports.READER_CSS=xl;exports.READ_HOME_CSS=Er;exports.READ_HOME_NARROW_QUERY=Dn;exports.READ_HOME_SECTION_IDS=md;exports.READ_PERIOD_LABELS=vb;exports.RECENT_IDS_STORAGE_KEY=ln;exports.ROLE_CLASS_ORDER=Nl;exports.ReadButton=yo;exports.ReadFamousWorks=dd;exports.ReadHomeView=wb;exports.ReadPeriodBand=pd;exports.ReadPicks=sd;exports.ReadPieces=ud;exports.ReadSection=st;exports.ReadShelf=Lr;exports.ReadSibu=Ar;exports.ReadStats=rd;exports.ReadTopicGroup=ld;exports.ReadTopics=cd;exports.ReaderMdText=cr;exports.ReaderShell=Sl;exports.ReaderToc=yl;exports.RelationPanel=kc;exports.RepoSourceLink=Io;exports.ResourceEditor=lo;exports.ResourceGroup=ah;exports.ResourceLine=lh;exports.ResourceList=Oo;exports.ResourceRow=Gl;exports.SEARCH_VIEW_STORAGE_KEY=Ho;exports.SEVEN_PAVILIONS_KEY=$d;exports.SNIPPET_MARK_END=Ca;exports.SNIPPET_MARK_START=$a;exports.SORTABLE_TYPES=Wa;exports.SearchInput=Ba;exports.SearchResults=Ya;exports.Sec=tt;exports.Section=bt;exports.SectionHead=Km;exports.SideList=Yt;exports.SmartBidInput=si;exports.SourceEditor=yc;exports.StripWarpRenderer=wo;exports.SummaryCard=Wn;exports.THEMES=Id;exports.THEME_INIT_SCRIPT=Yb;exports.THEME_STORAGE_KEY=Ei;exports.TRADITIONAL_ALLOWLIST=Ia;exports.TabFilter=$i;exports.TableHead=eh;exports.TableRow=th;exports.TagRow=Yl;exports.TagRows=ch;exports.TextButton=qm;exports.TextReader=wr;exports.ThemeToggle=qb;exports.TopStrip=jo;exports.VersionLineageGraph=Oc;exports.VersionLineageList=Wc;exports.VersionLineageView=zr;exports.VolumeChips=Jm;exports.VolumeLinks=or;exports.WorkCard=qc;exports.WorkCardGrid=Jc;exports.WorkCatalog=df;exports.WorkPage=Mc;exports.WorkRow=Xc;exports.adaptCharCord=cf;exports.adaptEntityJson=sc;exports.adaptGujiPages=rf;exports.adaptPunctJson=sf;exports.applyLayout=Vb;exports.applyTheme=Pd;exports.authorsLine=Ni;exports.bookIndexUriToId=_o;exports.bucketResources=Zo;exports.buildCatalogTree=lb;exports.buildCollectionTable=El;exports.buildLineageGraph=ai;exports.buildMeiliFilter=Xp;exports.buildPageUrl=Wo;exports.buildParagraphBlocks=Ql;exports.buildVersionRow=zl;exports.buildVersionTable=Tl;exports.canParagraphize=pi;exports.catalogNodeIdOf=sb;exports.catalogNodeIdsOf=ab;exports.catalogPageCount=ub;exports.catalogTotal=Rr;exports.classificationPath=Fn;exports.clearAllRecentIds=Fo;exports.compareCatalogCards=pb;exports.computeVersionPartition=Am;exports.countActiveFilters=vi;exports.createTextApi=ul;exports.currentLayout=Gb;exports.currentTheme=Md;exports.defaultEntityHref=uc;exports.defaultWorkLink=Yc;exports.deriveDating=Em;exports.deriveEditionType=Ll;exports.deriveEra=Mn;exports.deriveYear=wi;exports.deriveYearRange=Xo;exports.detailToEditor=Nc;exports.detectGenre=zi;exports.displayAuthorRole=Qo;exports.editorToDetail=Uf;exports.eraRank=xo;exports.filtersFromParams=Zp;exports.filtersToParams=li;exports.findCatalogPath=an;exports.findTraditionalChars=Pp;exports.firstAuthorText=Ir;exports.flattenTitles=ko;exports.flattenToc=wl;exports.fmtCount=Ye;exports.formatHitCount=ii;exports.formatTemplate=mt;exports.formatVolumeRange=_i;exports.getDisplayNameFromUrl=hn;exports.getMessages=un;exports.getStartPage=Bo;exports.getT=mn;exports.getTypeGroupKey=Po;exports.groupRelatedWorks=Im;exports.gujiInlineToPlain=al;exports.hasActiveFilters=Fa;exports.hasGujiMarkdownV02=uo;exports.hasGujiTableNotation=cl;exports.hasSearchOptions=Yp;exports.iiifVolumeOf=af;exports.isCountedChar=xr;exports.isLayoutName=Bd;exports.isThemeName=Ld;exports.lineageHref=fd;exports.loadRecentIds=Mt;exports.measureText=Nt;exports.mergeVolumeResources=Mo;exports.normalizeEra=Qe;exports.normalizeLayout=Ai;exports.normalizeRole=Jo;exports.normalizeTheme=Ii;exports.normalizeVolumeIndex=In;exports.normalizeVolumes=Aa;exports.numberToChinese=Il;exports.paginationItems=Vc;exports.parseChineseNumber=ci;exports.parseGujiInline=sl;exports.parseGujiTable=pl;exports.parseSourceString=jc;exports.pct=Pr;exports.periodLevel=nd;exports.pickReaderVersion=kl;exports.readStoredLayout=Db;exports.readStoredTheme=Hb;exports.readerVersionOptionLabel=go;exports.remapPlainOffsets=ac;exports.removeRecentId=Ka;exports.renderFullTextBody=xh;exports.renderProperNames=tc;exports.renderReaderInline=lr;exports.resolveRecentEntry=Do;exports.resourceHref=gn;exports.resourceNote=Si;exports.resultTabFromParam=au;exports.resultTabToParam=lu;exports.roleFacets=Rl;exports.rowNo=nh;exports.sameFilters=Jp;exports.saveRecentId=co;exports.segmentEntities=lc;exports.shelfColumns=ed;exports.sortFor=Kp;exports.sortYear=di;exports.spineHeight=td;exports.splitFullTextTables=Go;exports.splitHighlightSnippet=Lo;exports.splitTableRow=dl;exports.storeLayout=Ub;exports.storeTheme=Ad;exports.stringifySources=vc;exports.summaryFromEntry=dc;exports.summaryFromItem=cc;exports.timelineLayout=xd;exports.toCatalogWorkCard=db;exports.transportSummaryLoader=pc;exports.typeSupportsFilters=Da;exports.useBidUrl=Ze;exports.useChapterWarpData=gc;exports.useConvert=Ae;exports.useEntitySummaryLoader=yr;exports.useI18n=J;exports.useReaderPrefs=vl;exports.useRecentEntries=yd;exports.useT=Te;exports.validateLineageGraph=zx;exports.volumeStats=fi;exports.withDefaultLinks=Bt;exports.withMetaLinks=Wt;exports.yearText=hi;