book-index-ui 0.52.0 → 0.52.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.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Np=Object.create;var fs=Object.defineProperty;var Ip=Object.getOwnPropertyDescriptor;var Rp=Object.getOwnPropertyNames;var Ep=Object.getPrototypeOf,Lp=Object.prototype.hasOwnProperty;var Ap=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Rp(n))!Lp.call(e,s)&&s!==i&&fs(e,s,{get:()=>n[s],enumerable:!(o=Ip(n,s))||o.enumerable});return e};var ri=(e,n,i)=>(i=e!=null?Np(Ep(e)):{},Ap(n||!e||!e.__esModule?fs(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./storage-entry-4WXkdkaK.cjs"),t=require("react/jsx-runtime"),h=require("react"),Mp=require("opencc-js/t2cn"),Ja=require("./variant-supplement.cjs"),Pp=require("react-markdown"),Bp=require("remark-gfm"),Wp=e=>`/book-index?id=${e}`,Qa=h.createContext(Wp);function Op({buildUrl:e,children:n}){const i=h.useMemo(()=>e,[e]);return t.jsx(Qa.Provider,{value:i,children:n})}function tt(){return h.useContext(Qa)}const el="",tl="";function Gr(e){const n=[];let i=!1,o=e;for(;o.length;){const s=i?tl:el,a=o.indexOf(s);if(a===-1){n.push({text:o,marked:i});break}a>0&&n.push({text:o.slice(0,a),marked:i}),o=o.slice(a+1),i=!i}return n}function ct(e,n){return{title:e,tokens:n}}const xs='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Fp=[ct("基础(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"}}),ct("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),ct("提示与警告",{"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)"}}),ct("遮罩与阴影",{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)"}}),ct("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),ct("资源",{"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"}}),ct("整理本(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-source":{value:"#1b5e20",note:"文本质量等级(底本 / OCR / 粗校 / 精校 / 暂无正文 / 占位)"},"quality-ocr":{value:"#e65100"},"quality-rough":{value:"#1565c0"},"quality-fine":{value:"#2e7d32"},"quality-none":{value:"#5f6368",note:"中性灰:暂无正文"},"quality-placeholder":{value:"#757575",note:"中性灰:占位"}}),ct("版本传承(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"}}),ct("编辑器视图(主要在 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")'}}),ct("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),ct('版式(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"}}),ct("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"},"reader-warm":{value:"#c9a24a",note:"阅读设置侧栏的暖黄:只做底色(8%)与选中态(24%),与朱/靛/墨三套主色都不冲"},"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:"版心外边线"}}),ct("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),ct("字体(全站无衬线,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:xs,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:xs,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Hp=Object.assign({},...Fp.map(e=>e.tokens)),nl={};for(const[e,n]of Object.entries(Hp))nl[e]=`var(--bim-${e}, ${n.value})`;function r(e){const n=nl[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Pt(e){return e.types&&e.types.length>0?e.types:[]}function Dp(e,n){return Pt(e).includes(n)}const Up={source:"底本",ocr:"OCR",rough:"粗校",fine:"精校",none:"暫無正文",placeholder:"占位"};r("quality-source"),r("quality-ocr"),r("quality-rough"),r("quality-fine"),r("quality-none"),r("quality-placeholder");const Vp={"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 fn(e){try{return Vp[new URL(e).hostname]}catch{return}}const bs={text:0,image:1,physical:2};function Yr(e){return e.length===0?"physical":[...e].sort((n,i)=>(bs[n]??99)-(bs[i]??99)).join("+")}function Gp(e){return e.includes("text")&&e.includes("image")?"text+image":e[0]||"physical"}function qr(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},i=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[m,u]=p,g=`${m}|${Yr(Pt(c))}`;i.has(g)||i.set(g,{base:{...c,name:m,url:"",volumes:[]},volumes:[],indices:[]});const f=i.get(g);f.volumes.push({volume:u,url:c.url||void 0,status:"found"}),f.indices.push(d)}const o=[],s=new Set;for(const d of i.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)??""),o.push(d.base);for(const c of d.indices)s.add(c)}const a=[...o];for(let d=0;d<e.length;d++)s.has(d)||a.push(e[d]);return a}function il(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function rl(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||il(n)}))}function wi(e){const n=rl(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:o,expected:e.expected_volumes??i+o}}function Kr(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function Xr(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const o=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function xn(e){if(!e.url)return;const n=Kr(e.metadata);return n?Xr(e.url,n):e.url}const Tt=h.createContext(null),ol=["曹霑"];function Yp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qp(e,n=ol){const i=[...new Set(n.filter(Boolean))].sort((a,l)=>l.length-a.length);if(!i.length)return e;const o=new RegExp(`(${i.map(Yp).join("|")})`,"g"),s=new Set(i);return a=>{if(!a)return e(a);const l=a.split(o);return l.length===1?e(a):l.map((d,c)=>c%2===1&&s.has(d)?d:d&&e(d)).join("")}}let wn=null;function sl(){if(wn)return wn;try{const e=Mp.Converter({from:"t",to:"cn"});wn=qp(n=>e(_e.normalizeVariants(n)))}catch{wn=e=>e}return wn}const Kp={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:r("check-fine-bg"),fg:r("check-fine-fg")},粗校:{label:"粗校",bg:r("check-rough-bg"),fg:r("check-rough-fg")},AI整理:{label:"AI整理",bg:r("check-ai-bg"),fg:r("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:"圖片資源"}},Xp={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:r("check-fine-bg"),fg:r("check-fine-fg")},粗校:{label:"粗校",bg:r("check-rough-bg"),fg:r("check-rough-fg")},AI整理:{label:"AI整理",bg:r("check-ai-bg"),fg:r("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 pt(e,n,i){return{"zh-Hant":e,"zh-Hans":n}}const Zp=pt({toHans:"切换为简体",toHant:"切換為繁體",localeShortHans:"简",localeShortHant:"繁",themeLabel:"主題",theme:{zhusha:"朱砂",indigo:"靛青",ink:"墨"},loading:"加載中",repoSourceLink:"在 GitHub 查看本條目源文件",volumesMissing:"缺{n}",collapseVolumes:"收起分冊",expandVolumes:"展開分冊",collapseArrow:"收起 ▲",expandArrow:"展開 ▼",entitySubtype:{people:"人物",place:"地名",dynasty:"朝代",reign:"年號",office:"官職",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:"朝代",reign:"年号",office:"官职",anonymous:"佚名",collective:"集体"},cbdbTitle:"CBDB 中国历代人物传记数据库",entityPlaceholderNote:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。",otherVersions:"其他版本",switchToEdit:"切换到编辑模式",switchToView:"切换到查看模式",modeEdit:"✏️ 编辑",modeView:"👁 查看",noData:"无数据"}),Si=pt({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:"作品信息"}),Jp=pt({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:"附记"}}),Qp=pt({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}"}}),eu=pt({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:"上级丛编"}),tu=pt({subtype:{people:"人物",place:"地名",dynasty:"朝代",reign:"年號",office:"官職",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:"朝代",reign:"年号",office:"官职",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 为自动匹配,未经人工核对"}),nu=pt({imagesLoading:"加載書影…",noImages:"暫無書影",noImagesHint:"這一卷還沒有配上影像;接入後在此與正文逐頁對看",imageAlt:"書影 第 {label} 頁",prevImage:"上一頁書影",nextImage:"下一頁書影",back:"閱讀",backAria:"返回{label}首頁",skipToText:"跳到正文",settings:"閱讀設置",settingsShort:"設置",closeSettings:"收起設置",groupText:"文字",groupMark:"標註",groupLayout:"版面",font:"字體",fontSong:"宋體",fontKai:"楷體",fontSystem:"系統默認",script:"繁簡",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:"專名線",properNameOff:"不顯示",properNameLite:"精簡",properNameFull:"完整",properNameLiteTitle:"只標人名、地名、朝代",showWorks:"標註書名",bookTitleStyle:"書名樣式",bookTitleWavy:"波浪線",bookTitleBracket:"書名號",scriptOrig:"原字",scriptHant:"通行繁體",scriptHans:"簡體",quoteStyle:"引號",quoteModern:"“”‘’",quoteClassic:"「」『』",quoteOriginal:"原樣",pageBreaks:"顯示分葉分割線",pageIndicator:"頁指示頭(上下鍵調整位置)",preserveMargins:"書影保留空白",facsimilePager:"書影翻頁",facsimilePageInput:"書影葉碼(輸入數字後按 Enter 或離開輸入框跳轉)",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:"來源",originalSource:"本站獨立整理",charGuess:"殘字(推測)",upstream:"上游",chapterFailed:"無法加載章節內容",references:"參考文獻",entityDetail:"查看詳情 →"},{imagesLoading:"加载书影…",noImages:"暂无书影",noImagesHint:"这一卷还没有配上影像;接入后在此与正文逐页对看",imageAlt:"书影 第 {label} 页",prevImage:"上一页书影",nextImage:"下一页书影",back:"阅读",backAria:"返回{label}首页",skipToText:"跳到正文",settings:"阅读设置",settingsShort:"设置",closeSettings:"收起设置",groupText:"文字",groupMark:"标注",groupLayout:"版面",font:"字体",fontSong:"宋体",fontKai:"楷体",fontSystem:"系统默认",script:"繁简",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:"专名线",properNameOff:"不显示",properNameLite:"精简",properNameFull:"完整",properNameLiteTitle:"只标人名、地名、朝代",showWorks:"标注书名",bookTitleStyle:"书名样式",bookTitleWavy:"波浪线",bookTitleBracket:"书名号",scriptOrig:"原字",scriptHant:"通行繁体",scriptHans:"简体",quoteStyle:"引号",quoteModern:"“”‘’",quoteClassic:"「」『』",quoteOriginal:"原样",pageBreaks:"显示分叶分割线",pageIndicator:"页指示头(上下键调整位置)",preserveMargins:"书影保留空白",facsimilePager:"书影翻页",facsimilePageInput:"书影叶码(输入数字后按 Enter 或离开输入框跳转)",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:"来源",originalSource:"本站独立整理",charGuess:"残字(推测)",upstream:"上游",chapterFailed:"无法加载章节内容",references:"参考文献",entityDetail:"查看详情 →"}),iu=pt({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:{source:"底本",ocr:"OCR",rough:"粗校",fine:"精校",none:"暫無正文",placeholder:"占位"},qualityCriteria:{source:"照錄來源原文,本站未另行校對",ocr:"保持大意和結構,錯誤率在百分之十以內",rough:"保證文意基本正確,錯誤率在百分之三以內",fine:"通讀無障礙,錯誤率在百分之一以內",none:"質量未評定",placeholder:"占位條目,正文尚未錄入"},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:{source:"底本",ocr:"OCR",rough:"粗校",fine:"精校",none:"暂无正文",placeholder:"占位"},qualityCriteria:{source:"照录来源原文,本站未另行校对",ocr:"保持大意和结构,错误率在百分之十以内",rough:"保证文意基本正确,错误率在百分之三以内",fine:"通读无障碍,错误率在百分之一以内",none:"质量未评定",placeholder:"占位条目,正文尚未录入"},originalSource:"原文来源",viewsGroup:"看法",viewText:"正文",viewEntries:"条目",rowHeadNo:"序",rowHeadTitle:"书名",rowHeadWork:"作品",railCap:"本卷",railUnitPoems:"首",railUnitBooks:"部书",linkedN:"已关联 {n}",linkedOf:"已关联 {n} / {total}",railEntriesNav:"本卷条目"}),ru=pt({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:"规模、存佚、许可与版本"}),Zr=pt({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:"按作者浏览全部 →"}),ou=pt({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} 条"}),su=pt({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:"搜索"}),au=pt({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:"回复"}),lu=pt({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:"有争议"}}),cu={common:Zp,detail:Si,bookPage:Jp,workPage:Qp,collectionPage:eu,entityPage:tu,reader:nu,collated:iu,metaHome:ru,readHome:Zr,catalogPage:ou,searchPage:su,feedback:au,lineage:lu};function du(e){const n={};for(const[i,o]of Object.entries(cu))n[i]=o[e];return n}function ft(e,n){return e.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}const ys=new Map;function bn(e){let n=ys.get(e);return n||(n={...e==="zh-Hans"?Xp:Kp,...du(e)},ys.set(e,n)),n}function js(e,n){let i=e;for(const o of n.split(".")){if(i==null||typeof i!="object")return;i=i[o]}return typeof i=="string"?i:void 0}function al(e){return(n,i)=>{const o=js(e,n)??js(bn("zh-Hant"),n)??n;return i?ft(o,i):o}}const vs=new Map;function yn(e){let n=vs.get(e);return n||(n=al(bn(e)),vs.set(e,n)),n}const ll="bim-locale";function pu(){try{const e=localStorage.getItem(ll);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function uu(e){try{localStorage.setItem(ll,e)}catch{}}const mu="zh-Hans",gu=({locale:e,onLocaleChange:n,converter:i,children:o})=>{const[s,a]=h.useState(e??mu),l=e??s;h.useEffect(()=>{if(e)return;const m=pu();m&&m!==s&&a(m)},[]);const d=h.useMemo(()=>l==="zh-Hans"?i??sl():null,[l,i]),c=h.useCallback(m=>{a(m),uu(m),n==null||n(m)},[n]),p=h.useMemo(()=>({locale:l,setLocale:c,messages:bn(l),converter:d}),[l,c,d]);return t.jsx(Tt.Provider,{value:p,children:o})};function Ie(){const e=h.useContext(Tt);return(e==null?void 0:e.messages)??bn("zh-Hant")}const hu=2e3;function Me(){const e=h.useContext(Tt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,o=h.useRef(new Map),s=h.useRef(n),a=h.useRef(i);(s.current!==n||a.current!==i)&&(o.current.clear(),s.current=n,a.current=i);const l=h.useCallback(d=>{if(!d)return"";if(!i)return d;const c=o.current.get(d);if(c!==void 0)return c;const p=i(d);if(o.current.size>=hu){const m=o.current.keys().next().value;m!==void 0&&o.current.delete(m)}return o.current.set(d,p),p},[i]);return h.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function te(){const e=h.useContext(Tt),{convert:n,locale:i,isSimplified:o}=Me(),s=(e==null?void 0:e.messages)??bn("zh-Hant"),a=h.useMemo(()=>e?al(s):yn("zh-Hant"),[e,s]);return h.useMemo(()=>({t:a,convert:n,locale:i,isSimplified:o,messages:s}),[a,n,i,o,s])}const cl=["錄說語詞議樣書記類傳國經補藝紀編後與間條號為開總種無數據冊頁選時題爲詩萬證學續關東圖資歷來讀館論見鈔別進師輯陳覽寫現應從","點兩華實對員長註結闕殘檢閱當會單換體將裡訂處過區釋術頭錢譯識個電動顯問這認質還幾遺雖須專擇係網運權務變發機請風聲輸軍導產","話們車難報讓業設帶辦紙氣麼際聽親場買賣謝費漢庫遷馬叢孫於張義晉閣維曆欽則夢慶齋録舊內陽樓紅淵歸載稱隱遼計評觀禮龜黃興節併","餘齊韓簡霑並樂諸滸屬組篩紹緒劉蘇誤職夾廣蓋敘斷歐寬駰極參試雜魯沒順線貞該測鮮統戰檔衛辭聯臺贊刪聖貫啟瀏譜薈寶約嘗諜謂舉詳","異賦軾復諒構級審標劃彙吳楊暫轉項寧硯蕭儀禪韻掃閉倉麗禎錯監鞏轍繫説筆竄縣聞諡賈僅擊羅宮訓談誌葉視戶細許祿繪鍵絕欄鑑講誕馮","趙習樹饋確賜裝擬規繼製薦畫鉛獨誠遠龍門覺訣隸軒諭繕塊爭鏡裏豐碼備掛堯錦駕鶴遊傷猶鄒瑩綴揚詔託僞頗竊虛莊歲禍爾辯獲篤窮盡跡","萊終穎訛瑣鐫繡廟幀佈躍雙預連狀態軸複懸遞灣箋頌訪層鏈敗達鈞鳳亂奮豈陰婁騎純優獻靈牆隨摺疊驗徑橫瀾蔣壞鈕盤範圍責減籤適側","榮聶頃縉讎銓廳軌厲鶚駢醫駝黨鐘諫樞滄軻溫贈鐵徵賴蹟潁閒顗歿駁歟勸諷誼湯詐脫羣尋澤擄顏釀謄鴻離騷傑滯憤執廢懼匱歎毀蠶獄寵闇","陸淺貨輕貧俠賤貴煩競樑鳩採綜謬鳴養堅韋顎呂蘭脈峯鵲兒賞籠階緊綱漁荊嬰慍潛營鎔繞陣塚億負卻塵懷閨擋撐縮領滾輪匯撈貼讚創險團","隊準礙強髒藥鮑顧給緯悅帳巖廬貢亞壇惡諱鎮薊驍愛討彌護揮偉輒擾況較響喪鑰藍"].join(""),fu=new Set([...cl,...Object.keys(_e.VARIANT_CHARS),...Object.keys(Ja.VARIANT_SUPPLEMENT)]),dl=[...ol,"切換為繁體","漢籍リポジトリ"];function xu(e,n=dl){let i=e;for(const a of n)a&&(i=i.split(a).join(" "));const o=[],s=Array.from(i);return s.forEach((a,l)=>{fu.has(a)&&o.push({char:a,context:s.slice(Math.max(0,l-8),l+9).join("")})}),o}function bu(e,n,i){return e?e==="orig"?null:n==="zh-Hans"?i??sl():e==="hant"?_e.normalizeVariants:i:i}const yu=({mode:e,children:n})=>{const i=h.useContext(Tt),o=h.useMemo(()=>!i||!e?i:{...i,converter:bu(e,i.locale,i.converter)},[i,e]);return t.jsx(Tt.Provider,{value:o,children:n})};function ju(e){if(!e)return"";try{const n=new URL(e).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function ks(e){return e==="text+image"?["text","image"]:[e]}function ws(e){const n=Pt(e);return n.length===0?"text":Gp(n)}function vu(){return{id:"",name:"",url:"",types:["text"],details:""}}const vr=({items:e,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const a=Ie(),[l,d]=h.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}],m=w=>{if(!s)return!0;const j=Pt(w);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},u=e.map((w,j)=>({item:w,originalIndex:j})).filter(({item:w})=>m(w)),g=()=>{const w=vu();s&&(w.types=ks(s)),n([...e,w]),d(e.length)},f=w=>{n(e.filter((j,k)=>k!==w)),d(null)},x=(w,j,k)=>{const C=[...e];if(C[w]={...C[w],[j]:k},j==="url"&&!C[w].id){const $=ju(k);$&&(C[w].id=$)}n(C)},v=(w,j)=>{const k=[...e],{type:C,...$}=k[w];k[w]={...$,types:ks(j)},n(k)},y=(w,j,k)=>{const $={...e[w].metadata||{}};k?$[j]=k:delete $[j],x(w,"metadata",Object.keys($).length>0?$:void 0)},_=(w,j)=>{const k=j.trim()?j.split(/[,,、]/).map(C=>C.trim()).filter(Boolean):void 0;x(w,"structure",k)},b=(w,j,k)=>{const $=e[w].coverage||{level:1,ranges:""};j==="level"?$.level=parseInt(k)||1:$.ranges=k,x(w,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[u.map(({item:w,originalIndex:j})=>{var k,C,$;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("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:ku(ws(w)),color:r("on-color-fg")},children:(()=>{var M,z;const S=Pt(w);return S.length===0?"text":S.length===1?((M=c.find(T=>T.value===S[0]))==null?void 0:M.label)??S[0]:S.includes("text")&&S.includes("image")?((z=c.find(T=>T.value==="text+image"))==null?void 0:z.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:w.name||`${a.editor.resourcePlaceholder} ${j+1}`}),w.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:w.id}),w.url&&t.jsx("a",{href:w.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&w.url&&wu(j,o==null?void 0:o[j],i,a),t.jsx("button",{onClick:S=>{S.stopPropagation(),f(j)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:a.editor.deleteThisResource,children:"✕"})]}),l===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:[Dp(w,"image")&&w.url&&Su(w,a),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Sn,children:[t.jsx("span",{style:_n,children:a.label.type}),t.jsx("select",{value:ws(w),onChange:S=>v(j,S.target.value),style:{...St,flex:1},children:c.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Sn,children:[t.jsx("span",{style:_n,children:a.label.rootType}),t.jsx("select",{value:w.root_type||"catalog",onChange:S=>x(j,"root_type",S.target.value),style:{...St,flex:1},children:p.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:w.id,onChange:S=>x(j,"id",S.target.value),placeholder:a.editor.idAutoExtract,style:{...St,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:w.name,onChange:S=>x(j,"name",S.target.value),placeholder:a.editor.resourceName,style:{...St,flex:1}})]}),t.jsx("input",{type:"text",value:w.url,onChange:S=>x(j,"url",S.target.value),placeholder:a.editor.resourceUrl,style:St}),t.jsx("input",{type:"text",value:((k=w.structure)==null?void 0:k.join("、"))||"",onChange:S=>_(j,S.target.value),placeholder:a.editor.structurePlaceholder,style:St}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Sn,children:[t.jsx("span",{style:_n,children:a.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((C=w.coverage)==null?void 0:C.level)??"",onChange:S=>b(j,"level",S.target.value),placeholder:"1",style:{...St,width:"60px"}})]}),t.jsxs("label",{style:{...Sn,flex:1},children:[t.jsx("span",{style:_n,children:a.label.coverageRange}),t.jsx("input",{type:"text",value:(($=w.coverage)==null?void 0:$.ranges)||"",onChange:S=>b(j,"ranges",S.target.value),placeholder:a.editor.coverageRangePlaceholder,style:{...St,flex:1}})]})]}),t.jsx("textarea",{value:w.details||"",onChange:S=>x(j,"details",S.target.value),placeholder:a.editor.detailsPlaceholder,style:{...St,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${r("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:r("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(([S,M])=>{var z;return t.jsxs("label",{style:{...Sn,gap:"4px"},children:[t.jsx("span",{style:{..._n,minWidth:"56px"},children:M}),t.jsx("input",{type:"text",value:((z=w.metadata)==null?void 0:z[S])||"",onChange:T=>y(j,S,T.target.value),placeholder:M,style:{...St,flex:1}})]},S)})})]})]})]})]},j)}),t.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:a.action.addResource})]})]})};function ku(e){switch(e){case"text":return r("restype-text");case"image":return r("restype-image");case"text+image":return r("restype-text-image");case"physical":return r("restype-physical")}}function wu(e,n,i,o){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||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:r(a?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:a?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:a?"✓":s?"⏳":"⬇"})}function Su(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:r("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:r("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:r("desc-fg")},children:n.editor.imageResourceLink})})}const St={width:"100%",padding:"6px 8px",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Sn={display:"flex",alignItems:"center",gap:"6px"},_n={fontSize:"12px",color:r("desc-fg"),whiteSpace:"nowrap"},Ss={text:r("restype-text"),image:r("restype-image"),"text+image":r("restype-text-image"),physical:r("restype-physical")};function _u(e){return e.includes("text")&&e.includes("image")?Ss["text+image"]:Ss[e[0]||"physical"]}const Jr=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const a=Ie(),{convert:l}=Me(),d=h.useMemo(()=>qr(e||[]),[e]),{mirrorGroups:c,ungroupedItems:p}=h.useMemo(()=>{const y=new Map,_=[];for(const b of d){const w=b.group;w?(y.has(w)||y.set(w,[]),y.get(w).push(b)):_.push(b)}for(const b of y.values())b.sort((w,j)=>{const k=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return k(w)-k(j)});return{mirrorGroups:y,ungroupedItems:_}},[d]),m={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=y=>m[y]?m[y]:y.split("+").map(_=>m[_]||_).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:r("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,_)=>t.jsx(nr,{item:y},y.id||_))});const g=(y,_)=>{const b=i==null?void 0:i[y],w=(b==null?void 0:b.label)||y,j=b==null?void 0:b.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${r("widget-border")}`,borderRadius:"6px",background:r("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:l(w)}),j&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.5},children:l(j)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((k,C)=>t.jsx(nr,{item:k,onNavigate:o,renderLink:s},k.id||C))})]},`group-${y}`)},f=new Map;for(const y of p){const _=Yr(Pt(y));f.has(_)||f.set(_,[]),f.get(_).push(y)}const x=["text","image","text+image","physical"],v=[...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,_])=>g(y,_)),v.map(y=>{const _=f.get(y),b=_u(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:u(y)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((w,j)=>t.jsx(nr,{item:w,onNavigate:o,renderLink:s},w.id||j))})]},y)})]})},$u={bw:{label:"",bg:r("colormode-bw-bg"),fg:r("colormode-bw-fg")},color:{label:"",bg:r("colormode-color-bg"),fg:r("colormode-color-fg")}},nr=({item:e})=>{const n=Ie(),{convert:i}=Me(),[o,s]=h.useState(!1),a=h.useMemo(()=>(e.url?fn(e.url):void 0)||i(e.name),[e.url,e.name,i]),l=h.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(x=>({...x,url:x.url||il(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,m=e.expected_volumes??(d?c+p:0),u=e.color_mode?{...$u[e.color_mode],label:n.colorMode[e.color_mode]}:null,g=e.details&&!d?i(e.details):null,f={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${r("widget-border")}`,borderRadius:"5px",background:r("input-bg"),fontSize:"12px",color:r("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}),u&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:u.bg,color:u.fg},children:u.label}),g&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:g}),d&&t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg")},children:[c,"/",m,n.unit.volume,p>0&&t.jsx("span",{style:{color:r("missing-fg"),marginLeft:"3px"},children:ft(n.common.volumesMissing,{n:p})})]}),e.url&&t.jsx("a",{href:(()=>{const x=Kr(e.metadata);return x?Xr(e.url,x):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:r("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),d&&t.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),d&&o&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${r("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(x=>{const v=x.status==="missing";return x.url&&!v?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 ${r("widget-border")}`,color:r("link-fg"),textDecoration:"none"},children:x.volume},x.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:r(v?"missing-fg":"desc-fg"),textDecoration:v?"line-through":"none",opacity:v?.6:1},children:x.volume},x.volume)})})]})},pl=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:a,onSelectFolder:l})=>{const d=Ie(),c=e==="local",p=(n==null?void 0:n.isDraft)??!0,m=(n==null?void 0:n.repoPath)||"",u=m?m.split(/[/\\]/).pop()||m:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:r("primary-soft"),color:r("primary")},f={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},x=t.jsxs("div",{onClick:s,title:p?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...g,background:r(p?"warning":"success"),color:r("on-color-fg")},...f,children:[t.jsx("span",{children:p?"📝":"📚"}),t.jsx("span",{children:p?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[x,t.jsxs("div",{onClick:o,title:d.mode.switchToSync,style:g,...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:m||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...f,children:[t.jsx("span",{children:"📂"}),u&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]})]}):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:o,title:d.mode.switchToLocal,style:g,...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:u||d.mode.configurePath,style:{...g,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:o,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:g,...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:m||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:m?"100px":"auto",justifyContent:"space-between"},...f,children:[t.jsx("span",{children:"📂"}),u&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]}),!c&&u&&t.jsxs("div",{style:{...g,background:r("mode-active-bg"),color:r("on-color-fg"),cursor:"default"},title:m,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:u})]})]})},_i="bim-search-history",_s=10,$s=8;function Rn(){try{const e=localStorage.getItem(_i);return e?JSON.parse(e):[]}catch{return[]}}function ul(e){try{const n=Rn().filter(i=>i!==e);n.unshift(e),n.length>_s&&(n.length=_s),localStorage.setItem(_i,JSON.stringify(n))}catch{}}function Cu(e){try{const n=Rn().filter(i=>i!==e);localStorage.setItem(_i,JSON.stringify(n))}catch{}}function Tu(){try{localStorage.removeItem(_i)}catch{}}const ml=({transport:e,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:a})=>{const l=Ie(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,m]=h.useState(!1),[u,g]=h.useState([]),[f,x]=h.useState(-1),[v,y]=h.useState(Rn),_=h.useRef(null),b=h.useRef(null),w=h.useRef(null),j=h.useRef(!1);h.useEffect(()=>{x(-1);const T=n.trim();if(!T){g(v.map(N=>({type:"history",text:N})));return}if(!e.searchAll){g([]);return}let P=!1;const R=setTimeout(()=>{e.searchAll(T,$s).then(N=>{if(P)return;const A=[...N.works,...N.books,...N.collections,...N.entities??[]];g(A.slice(0,$s).map(H=>({type:"entry",text:H.title||H.id,entry:H})))}).catch(()=>{P||g([])})},80);return()=>{P=!0,clearTimeout(R)}},[n,v,e]),h.useEffect(()=>{const T=P=>{w.current&&!w.current.contains(P.target)&&m(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),h.useEffect(()=>{const T=P=>{var R,N;if(P.key==="/"&&document.activeElement!==_.current){const A=(R=document.activeElement)==null?void 0:R.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return;P.preventDefault(),(N=_.current)==null||N.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const k=h.useCallback(T=>{T.trim()&&(ul(T.trim()),y(Rn())),o(T),m(!1)},[o]),C=h.useCallback(T=>{T.type==="history"?(i(T.text),k(T.text)):T.entry&&(s?(s(T.entry),m(!1)):(i(T.text),k(T.text)))},[i,k,s]),$=h.useCallback(T=>{if(!p||u.length===0){T.key==="Enter"&&k(n);return}switch(T.key){case"ArrowDown":T.preventDefault(),x(P=>(P+1)%u.length);break;case"ArrowUp":T.preventDefault(),x(P=>(P-1+u.length)%u.length);break;case"Enter":T.preventDefault(),f>=0&&f<u.length?C(u[f]):k(n);break;case"Escape":T.preventDefault(),m(!1);break}},[p,u,f,n,k,C]),S=h.useCallback((T,P)=>{P.stopPropagation(),Cu(T),y(Rn()),g(R=>R.filter(N=>!(N.type==="history"&&N.text===T)))},[]),M=h.useCallback(T=>{T.stopPropagation(),Tu(),y([]),g([])},[]);h.useEffect(()=>{if(f>=0&&b.current){const T=b.current.children;T[f]&&T[f].scrollIntoView({block:"nearest"})}},[f]);const z=!n.trim()&&v.length>0;return t.jsxs("div",{ref:w,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:_,type:"text",placeholder:d,value:n,onChange:T=>{i(T.target.value),m(!0)},onCompositionStart:()=>{j.current=!0},onCompositionEnd:()=>{j.current=!1},onFocus:()=>{m(!0)},onKeyDown:$,style:{width:"100%",padding:"8px 12px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),p&&u.length>0&&t.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:r("input-bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"6px",boxShadow:r("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[z&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:r("desc-fg"),borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:M,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),u.map((T,P)=>t.jsxs("div",{onClick:()=>C(T),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r("fg"),background:P===f?r("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:r("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=>S(T.text,R),style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${T.type}-${T.text}-${P}`))]})]})},jn=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:r(`type-${e}`),verticalAlign:"middle"}}),$i={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},gl=new Set(["work","book","entity"]);function zu(e){return xl(e)||!!e.sort}function Nu(e,n){return n.sort&&gl.has(e)?n.sort:void 0}const Ci=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Ti=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],hl=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],fl={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function zi(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 xl(e){return zi(e)>0}function Iu(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 bl(e,n){const i=fl[e];return Iu(n).every(o=>i.has(o))}const $n=e=>JSON.stringify(e);function Ru(e,n){if(!bl(n,e))return null;const i=[];if(e.dynasty.length){const o=Array.from(new Set(e.dynasty.flatMap(s=>{var a;return((a=Ci.find(l=>l.key===s))==null?void 0:a.values)??[]})));o.length===1?i.push(`dynasty = ${$n(o[0])}`):o.length>1&&i.push(`dynasty IN [${o.map($n).join(", ")}]`)}return e.classification.length&&i.push(e.classification.length===1?`classification = ${$n(e.classification[0])}`:`classification IN [${e.classification.map($n).join(", ")}]`),e.hasImage&&i.push("has_image = true"),e.hasText&&i.push("has_text = true"),e.hasCollated&&i.push("has_collated = true"),e.loss&&i.push(`loss_status = ${$n(e.loss)}`),i.join(" AND ")}const lt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},yl="_";function fi(e,n=new URLSearchParams){for(const i of Object.values(lt))n.delete(i);return e.dynasty.length&&n.set(lt.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(lt.classification,e.classification.map(i=>i||yl).join(",")),e.hasImage&&n.set(lt.hasImage,"1"),e.hasText&&n.set(lt.hasText,"1"),e.hasCollated&&n.set(lt.hasCollated,"1"),e.loss&&n.set(lt.loss,e.loss),e.sort&&n.set(lt.sort,e.sort),n}function Eu(e){const n=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),i=new Set(Ci.map(a=>a.key)),o=new Set(Ti.map(a=>a.value)),s=e.get(lt.loss);return{dynasty:Array.from(new Set(n(lt.dynasty).filter(a=>i.has(a)))),classification:Array.from(new Set(n(lt.classification).map(a=>a===yl?"":a).filter(a=>o.has(a)))),hasImage:e.get(lt.hasImage)==="1",hasText:e.get(lt.hasText)==="1"||e.get(lt.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(lt.sort))??""}}function Lu(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 Cs(e,n){return e.includes(n)?e.filter(i=>i!==n):[...e,n]}const Au=({filters:e,onChange:n})=>{const i=Ie(),o=i.searchV4,{convert:s}=Me(),[a,l]=h.useState(!1),d=h.useId(),c=zi(e),p=m=>n({...e,...m});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":s(o.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":a,"aria-controls":d,onClick:()=>l(m=>!m),children:[t.jsxs("span",{children:[s(o.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:s(ft(o.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[s(a?o.collapse:o.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(o.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:Ci.map(m=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(m.key),onClick:()=>p({dynasty:Cs(e.dynasty,m.key)}),children:s(m.key)},m.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(o.classification)}),Ti.map(m=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(m.value),onChange:()=>p({classification:Cs(e.classification,m.value)})}),m.value?s(m.label):i.searchPage.unclassified]},m.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(o.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:m=>p({hasImage:m.target.checked})}),s(o.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:m=>p({hasText:m.target.checked})}),s(o.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:s(o.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:hl.map(m=>t.jsx("button",{type:"button","aria-pressed":e.loss===m.value,onClick:()=>p({loss:m.value}),children:i.searchPage.loss[m.value||"all"]},m.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...$i,sort:e.sort}),children:s(o.clearAllFilters)})]})]})};function jl({text:e,query:n}){const i=(n??"").trim();if(!i||!e)return t.jsx(t.Fragment,{children:e});const o=e.toLowerCase(),s=i.toLowerCase(),a=[];let l=0,d=0;for(;l<e.length;){const c=o.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 Ts=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Ie(),a=s.searchV4,{convert:l}=Me(),d=tt();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),m=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",u=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)}`:""}`:"",g=c.type==="book"?c.era??c.dynasty:c.dynasty,f=g?l(g):"",x=c.classification?l(c.classification):"",v=[];c.has_image&&v.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&v.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&v.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const y=[u,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:_=>i(c,_),children:t.jsx(jl,{text:p,query:n?l(n):void 0})}),m&&t.jsx("span",{className:"bim-sr-measure",children:m})]}),y&&t.jsx("span",{className:"bim-sr-sub",children:y})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(jn,{type:c.type,size:6})," ",o(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:u||"—"}),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:v.map(_=>t.jsx("span",{className:`bim-sr-tag ${_.cls}`,children:l(_.label)},_.label))})]},c.id)})})]})})},Mu=`
1
+ "use strict";var Np=Object.create;var fs=Object.defineProperty;var Ip=Object.getOwnPropertyDescriptor;var Rp=Object.getOwnPropertyNames;var Ep=Object.getPrototypeOf,Lp=Object.prototype.hasOwnProperty;var Ap=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Rp(n))!Lp.call(e,s)&&s!==i&&fs(e,s,{get:()=>n[s],enumerable:!(o=Ip(n,s))||o.enumerable});return e};var ri=(e,n,i)=>(i=e!=null?Np(Ep(e)):{},Ap(n||!e||!e.__esModule?fs(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./storage-entry-4WXkdkaK.cjs"),t=require("react/jsx-runtime"),h=require("react"),Mp=require("opencc-js/t2cn"),Ja=require("./variant-supplement.cjs"),Pp=require("react-markdown"),Bp=require("remark-gfm"),Wp=e=>`/book-index?id=${e}`,Qa=h.createContext(Wp);function Op({buildUrl:e,children:n}){const i=h.useMemo(()=>e,[e]);return t.jsx(Qa.Provider,{value:i,children:n})}function tt(){return h.useContext(Qa)}const el="",tl="";function Gr(e){const n=[];let i=!1,o=e;for(;o.length;){const s=i?tl:el,a=o.indexOf(s);if(a===-1){n.push({text:o,marked:i});break}a>0&&n.push({text:o.slice(0,a),marked:i}),o=o.slice(a+1),i=!i}return n}function ct(e,n){return{title:e,tokens:n}}const xs='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Fp=[ct("基础(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"}}),ct("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),ct("提示与警告",{"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)"}}),ct("遮罩与阴影",{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)"}}),ct("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),ct("资源",{"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"}}),ct("整理本(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-source":{value:"#1b5e20",note:"文本质量等级(底本 / OCR / 粗校 / 精校 / 暂无正文 / 占位)"},"quality-ocr":{value:"#e65100"},"quality-rough":{value:"#1565c0"},"quality-fine":{value:"#2e7d32"},"quality-none":{value:"#5f6368",note:"中性灰:暂无正文"},"quality-placeholder":{value:"#757575",note:"中性灰:占位"}}),ct("版本传承(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"}}),ct("编辑器视图(主要在 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")'}}),ct("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),ct('版式(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"}}),ct("阅读器(整理本 / 全文)",{"reader-top":{value:"0px",note:"宿主吸顶导航的高度:阅读器工具条、目录与书影侧栏在它下面吸顶(如 60px)"},"reader-warm":{value:"#c9a24a",note:"阅读设置侧栏的暖黄:只做底色(8%)与选中态(24%),与朱/靛/墨三套主色都不冲"},"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:"版心外边线"}}),ct("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),ct("字体(全站无衬线,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:xs,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:xs,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Hp=Object.assign({},...Fp.map(e=>e.tokens)),nl={};for(const[e,n]of Object.entries(Hp))nl[e]=`var(--bim-${e}, ${n.value})`;function r(e){const n=nl[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Mt(e){return e.types&&e.types.length>0?e.types:[]}function Dp(e,n){return Mt(e).includes(n)}const Up={source:"底本",ocr:"OCR",rough:"粗校",fine:"精校",none:"暫無正文",placeholder:"占位"};r("quality-source"),r("quality-ocr"),r("quality-rough"),r("quality-fine"),r("quality-none"),r("quality-placeholder");const Vp={"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 fn(e){try{return Vp[new URL(e).hostname]}catch{return}}const bs={text:0,image:1,physical:2};function Yr(e){return e.length===0?"physical":[...e].sort((n,i)=>(bs[n]??99)-(bs[i]??99)).join("+")}function Gp(e){return e.includes("text")&&e.includes("image")?"text+image":e[0]||"physical"}function qr(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},i=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[m,u]=p,g=`${m}|${Yr(Mt(c))}`;i.has(g)||i.set(g,{base:{...c,name:m,url:"",volumes:[]},volumes:[],indices:[]});const f=i.get(g);f.volumes.push({volume:u,url:c.url||void 0,status:"found"}),f.indices.push(d)}const o=[],s=new Set;for(const d of i.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)??""),o.push(d.base);for(const c of d.indices)s.add(c)}const a=[...o];for(let d=0;d<e.length;d++)s.has(d)||a.push(e[d]);return a}function il(e){if(e.url)return e.url;for(const[n,i]of Object.entries(e))if(n.endsWith("_url")&&typeof i=="string")return i}function rl(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||il(n)}))}function wi(e){const n=rl(e);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:o,expected:e.expected_volumes??i+o}}function Kr(e){if(!e)return;const n=e.file_page_range||e.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function Xr(e,n){try{if(new URL(e).hostname.includes("wikimedia.org")){const o=e.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(e);return s.searchParams.set("page",String(n)),s.toString()}return e}catch{return e}}function xn(e){if(!e.url)return;const n=Kr(e.metadata);return n?Xr(e.url,n):e.url}const Tt=h.createContext(null),ol=["曹霑"];function Yp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qp(e,n=ol){const i=[...new Set(n.filter(Boolean))].sort((a,l)=>l.length-a.length);if(!i.length)return e;const o=new RegExp(`(${i.map(Yp).join("|")})`,"g"),s=new Set(i);return a=>{if(!a)return e(a);const l=a.split(o);return l.length===1?e(a):l.map((d,c)=>c%2===1&&s.has(d)?d:d&&e(d)).join("")}}let wn=null;function sl(){if(wn)return wn;try{const e=Mp.Converter({from:"t",to:"cn"});wn=qp(n=>e(_e.normalizeVariants(n)))}catch{wn=e=>e}return wn}const Kp={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:r("check-fine-bg"),fg:r("check-fine-fg")},粗校:{label:"粗校",bg:r("check-rough-bg"),fg:r("check-rough-fg")},AI整理:{label:"AI整理",bg:r("check-ai-bg"),fg:r("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:"圖片資源"}},Xp={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:r("check-fine-bg"),fg:r("check-fine-fg")},粗校:{label:"粗校",bg:r("check-rough-bg"),fg:r("check-rough-fg")},AI整理:{label:"AI整理",bg:r("check-ai-bg"),fg:r("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 pt(e,n,i){return{"zh-Hant":e,"zh-Hans":n}}const Zp=pt({toHans:"切换为简体",toHant:"切換為繁體",localeShortHans:"简",localeShortHant:"繁",themeLabel:"主題",theme:{zhusha:"朱砂",indigo:"靛青",ink:"墨"},loading:"加載中",repoSourceLink:"在 GitHub 查看本條目源文件",volumesMissing:"缺{n}",collapseVolumes:"收起分冊",expandVolumes:"展開分冊",collapseArrow:"收起 ▲",expandArrow:"展開 ▼",entitySubtype:{people:"人物",place:"地名",dynasty:"朝代",reign:"年號",office:"官職",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:"朝代",reign:"年号",office:"官职",anonymous:"佚名",collective:"集体"},cbdbTitle:"CBDB 中国历代人物传记数据库",entityPlaceholderNote:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。",otherVersions:"其他版本",switchToEdit:"切换到编辑模式",switchToView:"切换到查看模式",modeEdit:"✏️ 编辑",modeView:"👁 查看",noData:"无数据"}),Si=pt({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:"作品信息"}),Jp=pt({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:"附记"}}),Qp=pt({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}"}}),eu=pt({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:"上级丛编"}),tu=pt({subtype:{people:"人物",place:"地名",dynasty:"朝代",reign:"年號",office:"官職",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:"朝代",reign:"年号",office:"官职",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 为自动匹配,未经人工核对"}),nu=pt({imagesLoading:"加載書影…",noImages:"暫無書影",noImagesHint:"這一卷還沒有配上影像;接入後在此與正文逐頁對看",imageAlt:"書影 第 {label} 頁",prevImage:"上一頁書影",nextImage:"下一頁書影",back:"閱讀",backAria:"返回{label}首頁",skipToText:"跳到正文",settings:"閱讀設置",settingsShort:"設置",closeSettings:"收起設置",groupText:"文字",groupMark:"標註",groupLayout:"版面",font:"字體",fontSong:"宋體",fontKai:"楷體",fontSystem:"系統默認",script:"繁簡",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:"專名線",properNameOff:"不顯示",properNameLite:"精簡",properNameFull:"完整",properNameLiteTitle:"只標人名、地名、朝代",showWorks:"標註書名",bookTitleStyle:"書名樣式",bookTitleWavy:"波浪線",bookTitleBracket:"書名號",scriptOrig:"原字",scriptOrigShort:"原",scriptQuick:"字形",scriptHant:"通行繁體",scriptHans:"簡體",quoteStyle:"引號",quoteModern:"“”‘’",quoteClassic:"「」『』",quoteOriginal:"原樣",pageBreaks:"顯示分葉分割線",pageIndicator:"頁指示頭(上下鍵調整位置)",preserveMargins:"書影保留空白",facsimilePager:"書影翻頁",facsimilePageInput:"書影葉碼(輸入數字後按 Enter 或離開輸入框跳轉)",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:"來源",originalSource:"本站獨立整理",charGuess:"殘字(推測)",upstream:"上游",chapterFailed:"無法加載章節內容",references:"參考文獻",entityDetail:"查看詳情 →"},{imagesLoading:"加载书影…",noImages:"暂无书影",noImagesHint:"这一卷还没有配上影像;接入后在此与正文逐页对看",imageAlt:"书影 第 {label} 页",prevImage:"上一页书影",nextImage:"下一页书影",back:"阅读",backAria:"返回{label}首页",skipToText:"跳到正文",settings:"阅读设置",settingsShort:"设置",closeSettings:"收起设置",groupText:"文字",groupMark:"标注",groupLayout:"版面",font:"字体",fontSong:"宋体",fontKai:"楷体",fontSystem:"系统默认",script:"繁简",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:"专名线",properNameOff:"不显示",properNameLite:"精简",properNameFull:"完整",properNameLiteTitle:"只标人名、地名、朝代",showWorks:"标注书名",bookTitleStyle:"书名样式",bookTitleWavy:"波浪线",bookTitleBracket:"书名号",scriptOrig:"原字",scriptOrigShort:"原",scriptQuick:"字形",scriptHant:"通行繁体",scriptHans:"简体",quoteStyle:"引号",quoteModern:"“”‘’",quoteClassic:"「」『』",quoteOriginal:"原样",pageBreaks:"显示分叶分割线",pageIndicator:"页指示头(上下键调整位置)",preserveMargins:"书影保留空白",facsimilePager:"书影翻页",facsimilePageInput:"书影叶码(输入数字后按 Enter 或离开输入框跳转)",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:"来源",originalSource:"本站独立整理",charGuess:"残字(推测)",upstream:"上游",chapterFailed:"无法加载章节内容",references:"参考文献",entityDetail:"查看详情 →"}),iu=pt({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:{source:"底本",ocr:"OCR",rough:"粗校",fine:"精校",none:"暫無正文",placeholder:"占位"},qualityCriteria:{source:"照錄來源原文,本站未另行校對",ocr:"保持大意和結構,錯誤率在百分之十以內",rough:"保證文意基本正確,錯誤率在百分之三以內",fine:"通讀無障礙,錯誤率在百分之一以內",none:"質量未評定",placeholder:"占位條目,正文尚未錄入"},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:{source:"底本",ocr:"OCR",rough:"粗校",fine:"精校",none:"暂无正文",placeholder:"占位"},qualityCriteria:{source:"照录来源原文,本站未另行校对",ocr:"保持大意和结构,错误率在百分之十以内",rough:"保证文意基本正确,错误率在百分之三以内",fine:"通读无障碍,错误率在百分之一以内",none:"质量未评定",placeholder:"占位条目,正文尚未录入"},originalSource:"原文来源",viewsGroup:"看法",viewText:"正文",viewEntries:"条目",rowHeadNo:"序",rowHeadTitle:"书名",rowHeadWork:"作品",railCap:"本卷",railUnitPoems:"首",railUnitBooks:"部书",linkedN:"已关联 {n}",linkedOf:"已关联 {n} / {total}",railEntriesNav:"本卷条目"}),ru=pt({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:"规模、存佚、许可与版本"}),Zr=pt({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:"按作者浏览全部 →"}),ou=pt({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} 条"}),su=pt({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:"搜索"}),au=pt({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:"回复"}),lu=pt({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:"有争议"}}),cu={common:Zp,detail:Si,bookPage:Jp,workPage:Qp,collectionPage:eu,entityPage:tu,reader:nu,collated:iu,metaHome:ru,readHome:Zr,catalogPage:ou,searchPage:su,feedback:au,lineage:lu};function du(e){const n={};for(const[i,o]of Object.entries(cu))n[i]=o[e];return n}function ft(e,n){return e.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}const ys=new Map;function bn(e){let n=ys.get(e);return n||(n={...e==="zh-Hans"?Xp:Kp,...du(e)},ys.set(e,n)),n}function js(e,n){let i=e;for(const o of n.split(".")){if(i==null||typeof i!="object")return;i=i[o]}return typeof i=="string"?i:void 0}function al(e){return(n,i)=>{const o=js(e,n)??js(bn("zh-Hant"),n)??n;return i?ft(o,i):o}}const vs=new Map;function yn(e){let n=vs.get(e);return n||(n=al(bn(e)),vs.set(e,n)),n}const ll="bim-locale";function pu(){try{const e=localStorage.getItem(ll);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function uu(e){try{localStorage.setItem(ll,e)}catch{}}const mu="zh-Hans",gu=({locale:e,onLocaleChange:n,converter:i,children:o})=>{const[s,a]=h.useState(e??mu),l=e??s;h.useEffect(()=>{if(e)return;const m=pu();m&&m!==s&&a(m)},[]);const d=h.useMemo(()=>l==="zh-Hans"?i??sl():null,[l,i]),c=h.useCallback(m=>{a(m),uu(m),n==null||n(m)},[n]),p=h.useMemo(()=>({locale:l,setLocale:c,messages:bn(l),converter:d}),[l,c,d]);return t.jsx(Tt.Provider,{value:p,children:o})};function Ie(){const e=h.useContext(Tt);return(e==null?void 0:e.messages)??bn("zh-Hant")}const hu=2e3;function Me(){const e=h.useContext(Tt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,o=h.useRef(new Map),s=h.useRef(n),a=h.useRef(i);(s.current!==n||a.current!==i)&&(o.current.clear(),s.current=n,a.current=i);const l=h.useCallback(d=>{if(!d)return"";if(!i)return d;const c=o.current.get(d);if(c!==void 0)return c;const p=i(d);if(o.current.size>=hu){const m=o.current.keys().next().value;m!==void 0&&o.current.delete(m)}return o.current.set(d,p),p},[i]);return h.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function te(){const e=h.useContext(Tt),{convert:n,locale:i,isSimplified:o}=Me(),s=(e==null?void 0:e.messages)??bn("zh-Hant"),a=h.useMemo(()=>e?al(s):yn("zh-Hant"),[e,s]);return h.useMemo(()=>({t:a,convert:n,locale:i,isSimplified:o,messages:s}),[a,n,i,o,s])}const cl=["錄說語詞議樣書記類傳國經補藝紀編後與間條號為開總種無數據冊頁選時題爲詩萬證學續關東圖資歷來讀館論見鈔別進師輯陳覽寫現應從","點兩華實對員長註結闕殘檢閱當會單換體將裡訂處過區釋術頭錢譯識個電動顯問這認質還幾遺雖須專擇係網運權務變發機請風聲輸軍導產","話們車難報讓業設帶辦紙氣麼際聽親場買賣謝費漢庫遷馬叢孫於張義晉閣維曆欽則夢慶齋録舊內陽樓紅淵歸載稱隱遼計評觀禮龜黃興節併","餘齊韓簡霑並樂諸滸屬組篩紹緒劉蘇誤職夾廣蓋敘斷歐寬駰極參試雜魯沒順線貞該測鮮統戰檔衛辭聯臺贊刪聖貫啟瀏譜薈寶約嘗諜謂舉詳","異賦軾復諒構級審標劃彙吳楊暫轉項寧硯蕭儀禪韻掃閉倉麗禎錯監鞏轍繫説筆竄縣聞諡賈僅擊羅宮訓談誌葉視戶細許祿繪鍵絕欄鑑講誕馮","趙習樹饋確賜裝擬規繼製薦畫鉛獨誠遠龍門覺訣隸軒諭繕塊爭鏡裏豐碼備掛堯錦駕鶴遊傷猶鄒瑩綴揚詔託僞頗竊虛莊歲禍爾辯獲篤窮盡跡","萊終穎訛瑣鐫繡廟幀佈躍雙預連狀態軸複懸遞灣箋頌訪層鏈敗達鈞鳳亂奮豈陰婁騎純優獻靈牆隨摺疊驗徑橫瀾蔣壞鈕盤範圍責減籤適側","榮聶頃縉讎銓廳軌厲鶚駢醫駝黨鐘諫樞滄軻溫贈鐵徵賴蹟潁閒顗歿駁歟勸諷誼湯詐脫羣尋澤擄顏釀謄鴻離騷傑滯憤執廢懼匱歎毀蠶獄寵闇","陸淺貨輕貧俠賤貴煩競樑鳩採綜謬鳴養堅韋顎呂蘭脈峯鵲兒賞籠階緊綱漁荊嬰慍潛營鎔繞陣塚億負卻塵懷閨擋撐縮領滾輪匯撈貼讚創險團","隊準礙強髒藥鮑顧給緯悅帳巖廬貢亞壇惡諱鎮薊驍愛討彌護揮偉輒擾況較響喪鑰藍"].join(""),fu=new Set([...cl,...Object.keys(_e.VARIANT_CHARS),...Object.keys(Ja.VARIANT_SUPPLEMENT)]),dl=[...ol,"切換為繁體","漢籍リポジトリ"];function xu(e,n=dl){let i=e;for(const a of n)a&&(i=i.split(a).join(" "));const o=[],s=Array.from(i);return s.forEach((a,l)=>{fu.has(a)&&o.push({char:a,context:s.slice(Math.max(0,l-8),l+9).join("")})}),o}function bu(e,n,i){return e?e==="orig"?null:n==="zh-Hans"?i??sl():e==="hant"?_e.normalizeVariants:i:i}const yu=({mode:e,children:n})=>{const i=h.useContext(Tt),o=h.useMemo(()=>!i||!e?i:{...i,converter:bu(e,i.locale,i.converter)},[i,e]);return t.jsx(Tt.Provider,{value:o,children:n})};function ju(e){if(!e)return"";try{const n=new URL(e).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function ks(e){return e==="text+image"?["text","image"]:[e]}function ws(e){const n=Mt(e);return n.length===0?"text":Gp(n)}function vu(){return{id:"",name:"",url:"",types:["text"],details:""}}const vr=({items:e,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const a=Ie(),[l,d]=h.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}],m=w=>{if(!s)return!0;const j=Mt(w);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},u=e.map((w,j)=>({item:w,originalIndex:j})).filter(({item:w})=>m(w)),g=()=>{const w=vu();s&&(w.types=ks(s)),n([...e,w]),d(e.length)},f=w=>{n(e.filter((j,k)=>k!==w)),d(null)},x=(w,j,k)=>{const C=[...e];if(C[w]={...C[w],[j]:k},j==="url"&&!C[w].id){const $=ju(k);$&&(C[w].id=$)}n(C)},v=(w,j)=>{const k=[...e],{type:C,...$}=k[w];k[w]={...$,types:ks(j)},n(k)},y=(w,j,k)=>{const $={...e[w].metadata||{}};k?$[j]=k:delete $[j],x(w,"metadata",Object.keys($).length>0?$:void 0)},_=(w,j)=>{const k=j.trim()?j.split(/[,,、]/).map(C=>C.trim()).filter(Boolean):void 0;x(w,"structure",k)},b=(w,j,k)=>{const $=e[w].coverage||{level:1,ranges:""};j==="level"?$.level=parseInt(k)||1:$.ranges=k,x(w,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[u.map(({item:w,originalIndex:j})=>{var k,C,$;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("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:ku(ws(w)),color:r("on-color-fg")},children:(()=>{var M,z;const S=Mt(w);return S.length===0?"text":S.length===1?((M=c.find(T=>T.value===S[0]))==null?void 0:M.label)??S[0]:S.includes("text")&&S.includes("image")?((z=c.find(T=>T.value==="text+image"))==null?void 0:z.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:w.name||`${a.editor.resourcePlaceholder} ${j+1}`}),w.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:w.id}),w.url&&t.jsx("a",{href:w.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&w.url&&wu(j,o==null?void 0:o[j],i,a),t.jsx("button",{onClick:S=>{S.stopPropagation(),f(j)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:a.editor.deleteThisResource,children:"✕"})]}),l===j&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:[Dp(w,"image")&&w.url&&Su(w,a),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Sn,children:[t.jsx("span",{style:_n,children:a.label.type}),t.jsx("select",{value:ws(w),onChange:S=>v(j,S.target.value),style:{...St,flex:1},children:c.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Sn,children:[t.jsx("span",{style:_n,children:a.label.rootType}),t.jsx("select",{value:w.root_type||"catalog",onChange:S=>x(j,"root_type",S.target.value),style:{...St,flex:1},children:p.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:w.id,onChange:S=>x(j,"id",S.target.value),placeholder:a.editor.idAutoExtract,style:{...St,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:w.name,onChange:S=>x(j,"name",S.target.value),placeholder:a.editor.resourceName,style:{...St,flex:1}})]}),t.jsx("input",{type:"text",value:w.url,onChange:S=>x(j,"url",S.target.value),placeholder:a.editor.resourceUrl,style:St}),t.jsx("input",{type:"text",value:((k=w.structure)==null?void 0:k.join("、"))||"",onChange:S=>_(j,S.target.value),placeholder:a.editor.structurePlaceholder,style:St}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Sn,children:[t.jsx("span",{style:_n,children:a.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((C=w.coverage)==null?void 0:C.level)??"",onChange:S=>b(j,"level",S.target.value),placeholder:"1",style:{...St,width:"60px"}})]}),t.jsxs("label",{style:{...Sn,flex:1},children:[t.jsx("span",{style:_n,children:a.label.coverageRange}),t.jsx("input",{type:"text",value:(($=w.coverage)==null?void 0:$.ranges)||"",onChange:S=>b(j,"ranges",S.target.value),placeholder:a.editor.coverageRangePlaceholder,style:{...St,flex:1}})]})]}),t.jsx("textarea",{value:w.details||"",onChange:S=>x(j,"details",S.target.value),placeholder:a.editor.detailsPlaceholder,style:{...St,minHeight:"60px",resize:"vertical"}}),t.jsxs("div",{style:{borderTop:`1px solid ${r("widget-border")}`,paddingTop:"8px",marginTop:"4px"},children:[t.jsx("div",{style:{fontSize:"12px",color:r("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(([S,M])=>{var z;return t.jsxs("label",{style:{...Sn,gap:"4px"},children:[t.jsx("span",{style:{..._n,minWidth:"56px"},children:M}),t.jsx("input",{type:"text",value:((z=w.metadata)==null?void 0:z[S])||"",onChange:T=>y(j,S,T.target.value),placeholder:M,style:{...St,flex:1}})]},S)})})]})]})]})]},j)}),t.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:a.action.addResource})]})]})};function ku(e){switch(e){case"text":return r("restype-text");case"image":return r("restype-image");case"text+image":return r("restype-text-image");case"physical":return r("restype-physical")}}function wu(e,n,i,o){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||i(e,"")},disabled:s,style:{background:"transparent",border:"none",color:r(a?"success":s?"desc-fg":"link-fg"),cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:a?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:a?"✓":s?"⏳":"⬇"})}function Su(e,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.url)||e.url.includes("iiif")||e.url.includes("image");return t.jsx("div",{style:{marginBottom:"12px"},children:i?t.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:r("overlay-bg")},children:t.jsx("img",{src:e.url,alt:e.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):t.jsx("div",{style:{padding:"12px",background:r("overlay-bg"),borderRadius:"4px",fontSize:"12px",color:r("desc-fg")},children:n.editor.imageResourceLink})})}const St={width:"100%",padding:"6px 8px",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Sn={display:"flex",alignItems:"center",gap:"6px"},_n={fontSize:"12px",color:r("desc-fg"),whiteSpace:"nowrap"},Ss={text:r("restype-text"),image:r("restype-image"),"text+image":r("restype-text-image"),physical:r("restype-physical")};function _u(e){return e.includes("text")&&e.includes("image")?Ss["text+image"]:Ss[e[0]||"physical"]}const Jr=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const a=Ie(),{convert:l}=Me(),d=h.useMemo(()=>qr(e||[]),[e]),{mirrorGroups:c,ungroupedItems:p}=h.useMemo(()=>{const y=new Map,_=[];for(const b of d){const w=b.group;w?(y.has(w)||y.set(w,[]),y.get(w).push(b)):_.push(b)}for(const b of y.values())b.sort((w,j)=>{const k=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return k(w)-k(j)});return{mirrorGroups:y,ungroupedItems:_}},[d]),m={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=y=>m[y]?m[y]:y.split("+").map(_=>m[_]||_).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:r("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,_)=>t.jsx(nr,{item:y},y.id||_))});const g=(y,_)=>{const b=i==null?void 0:i[y],w=(b==null?void 0:b.label)||y,j=b==null?void 0:b.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${r("widget-border")}`,borderRadius:"6px",background:r("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:l(w)}),j&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.5},children:l(j)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((k,C)=>t.jsx(nr,{item:k,onNavigate:o,renderLink:s},k.id||C))})]},`group-${y}`)},f=new Map;for(const y of p){const _=Yr(Mt(y));f.has(_)||f.set(_,[]),f.get(_).push(y)}const x=["text","image","text+image","physical"],v=[...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,_])=>g(y,_)),v.map(y=>{const _=f.get(y),b=_u(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:u(y)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((w,j)=>t.jsx(nr,{item:w,onNavigate:o,renderLink:s},w.id||j))})]},y)})]})},$u={bw:{label:"",bg:r("colormode-bw-bg"),fg:r("colormode-bw-fg")},color:{label:"",bg:r("colormode-color-bg"),fg:r("colormode-color-fg")}},nr=({item:e})=>{const n=Ie(),{convert:i}=Me(),[o,s]=h.useState(!1),a=h.useMemo(()=>(e.url?fn(e.url):void 0)||i(e.name),[e.url,e.name,i]),l=h.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(x=>({...x,url:x.url||il(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,m=e.expected_volumes??(d?c+p:0),u=e.color_mode?{...$u[e.color_mode],label:n.colorMode[e.color_mode]}:null,g=e.details&&!d?i(e.details):null,f={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${r("widget-border")}`,borderRadius:"5px",background:r("input-bg"),fontSize:"12px",color:r("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}),u&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:u.bg,color:u.fg},children:u.label}),g&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:g}),d&&t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg")},children:[c,"/",m,n.unit.volume,p>0&&t.jsx("span",{style:{color:r("missing-fg"),marginLeft:"3px"},children:ft(n.common.volumesMissing,{n:p})})]}),e.url&&t.jsx("a",{href:(()=>{const x=Kr(e.metadata);return x?Xr(e.url,x):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:r("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),d&&t.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),d&&o&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${r("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(x=>{const v=x.status==="missing";return x.url&&!v?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 ${r("widget-border")}`,color:r("link-fg"),textDecoration:"none"},children:x.volume},x.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:r(v?"missing-fg":"desc-fg"),textDecoration:v?"line-through":"none",opacity:v?.6:1},children:x.volume},x.volume)})})]})},pl=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:a,onSelectFolder:l})=>{const d=Ie(),c=e==="local",p=(n==null?void 0:n.isDraft)??!0,m=(n==null?void 0:n.repoPath)||"",u=m?m.split(/[/\\]/).pop()||m:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:r("primary-soft"),color:r("primary")},f={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},x=t.jsxs("div",{onClick:s,title:p?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...g,background:r(p?"warning":"success"),color:r("on-color-fg")},...f,children:[t.jsx("span",{children:p?"📝":"📚"}),t.jsx("span",{children:p?"draft":"official"})]});return i==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[x,t.jsxs("div",{onClick:o,title:d.mode.switchToSync,style:g,...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:m||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...f,children:[t.jsx("span",{children:"📂"}),u&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]})]}):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:o,title:d.mode.switchToLocal,style:g,...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:u||d.mode.configurePath,style:{...g,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:o,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:g,...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:m||d.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:m?"100px":"auto",justifyContent:"space-between"},...f,children:[t.jsx("span",{children:"📂"}),u&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:u})]}),!c&&u&&t.jsxs("div",{style:{...g,background:r("mode-active-bg"),color:r("on-color-fg"),cursor:"default"},title:m,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:u})]})]})},_i="bim-search-history",_s=10,$s=8;function Rn(){try{const e=localStorage.getItem(_i);return e?JSON.parse(e):[]}catch{return[]}}function ul(e){try{const n=Rn().filter(i=>i!==e);n.unshift(e),n.length>_s&&(n.length=_s),localStorage.setItem(_i,JSON.stringify(n))}catch{}}function Cu(e){try{const n=Rn().filter(i=>i!==e);localStorage.setItem(_i,JSON.stringify(n))}catch{}}function Tu(){try{localStorage.removeItem(_i)}catch{}}const ml=({transport:e,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:a})=>{const l=Ie(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,m]=h.useState(!1),[u,g]=h.useState([]),[f,x]=h.useState(-1),[v,y]=h.useState(Rn),_=h.useRef(null),b=h.useRef(null),w=h.useRef(null),j=h.useRef(!1);h.useEffect(()=>{x(-1);const T=n.trim();if(!T){g(v.map(N=>({type:"history",text:N})));return}if(!e.searchAll){g([]);return}let P=!1;const R=setTimeout(()=>{e.searchAll(T,$s).then(N=>{if(P)return;const A=[...N.works,...N.books,...N.collections,...N.entities??[]];g(A.slice(0,$s).map(H=>({type:"entry",text:H.title||H.id,entry:H})))}).catch(()=>{P||g([])})},80);return()=>{P=!0,clearTimeout(R)}},[n,v,e]),h.useEffect(()=>{const T=P=>{w.current&&!w.current.contains(P.target)&&m(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),h.useEffect(()=>{const T=P=>{var R,N;if(P.key==="/"&&document.activeElement!==_.current){const A=(R=document.activeElement)==null?void 0:R.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return;P.preventDefault(),(N=_.current)==null||N.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const k=h.useCallback(T=>{T.trim()&&(ul(T.trim()),y(Rn())),o(T),m(!1)},[o]),C=h.useCallback(T=>{T.type==="history"?(i(T.text),k(T.text)):T.entry&&(s?(s(T.entry),m(!1)):(i(T.text),k(T.text)))},[i,k,s]),$=h.useCallback(T=>{if(!p||u.length===0){T.key==="Enter"&&k(n);return}switch(T.key){case"ArrowDown":T.preventDefault(),x(P=>(P+1)%u.length);break;case"ArrowUp":T.preventDefault(),x(P=>(P-1+u.length)%u.length);break;case"Enter":T.preventDefault(),f>=0&&f<u.length?C(u[f]):k(n);break;case"Escape":T.preventDefault(),m(!1);break}},[p,u,f,n,k,C]),S=h.useCallback((T,P)=>{P.stopPropagation(),Cu(T),y(Rn()),g(R=>R.filter(N=>!(N.type==="history"&&N.text===T)))},[]),M=h.useCallback(T=>{T.stopPropagation(),Tu(),y([]),g([])},[]);h.useEffect(()=>{if(f>=0&&b.current){const T=b.current.children;T[f]&&T[f].scrollIntoView({block:"nearest"})}},[f]);const z=!n.trim()&&v.length>0;return t.jsxs("div",{ref:w,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:_,type:"text",placeholder:d,value:n,onChange:T=>{i(T.target.value),m(!0)},onCompositionStart:()=>{j.current=!0},onCompositionEnd:()=>{j.current=!1},onFocus:()=>{m(!0)},onKeyDown:$,style:{width:"100%",padding:"8px 12px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),p&&u.length>0&&t.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:r("input-bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"6px",boxShadow:r("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[z&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:r("desc-fg"),borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:M,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),u.map((T,P)=>t.jsxs("div",{onClick:()=>C(T),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r("fg"),background:P===f?r("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:r("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=>S(T.text,R),style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${T.type}-${T.text}-${P}`))]})]})},jn=({type:e,size:n=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:n,height:n,borderRadius:1,flex:"none",background:r(`type-${e}`),verticalAlign:"middle"}}),$i={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},gl=new Set(["work","book","entity"]);function zu(e){return xl(e)||!!e.sort}function Nu(e,n){return n.sort&&gl.has(e)?n.sort:void 0}const Ci=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Ti=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],hl=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],fl={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function zi(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 xl(e){return zi(e)>0}function Iu(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 bl(e,n){const i=fl[e];return Iu(n).every(o=>i.has(o))}const $n=e=>JSON.stringify(e);function Ru(e,n){if(!bl(n,e))return null;const i=[];if(e.dynasty.length){const o=Array.from(new Set(e.dynasty.flatMap(s=>{var a;return((a=Ci.find(l=>l.key===s))==null?void 0:a.values)??[]})));o.length===1?i.push(`dynasty = ${$n(o[0])}`):o.length>1&&i.push(`dynasty IN [${o.map($n).join(", ")}]`)}return e.classification.length&&i.push(e.classification.length===1?`classification = ${$n(e.classification[0])}`:`classification IN [${e.classification.map($n).join(", ")}]`),e.hasImage&&i.push("has_image = true"),e.hasText&&i.push("has_text = true"),e.hasCollated&&i.push("has_collated = true"),e.loss&&i.push(`loss_status = ${$n(e.loss)}`),i.join(" AND ")}const lt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},yl="_";function fi(e,n=new URLSearchParams){for(const i of Object.values(lt))n.delete(i);return e.dynasty.length&&n.set(lt.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(lt.classification,e.classification.map(i=>i||yl).join(",")),e.hasImage&&n.set(lt.hasImage,"1"),e.hasText&&n.set(lt.hasText,"1"),e.hasCollated&&n.set(lt.hasCollated,"1"),e.loss&&n.set(lt.loss,e.loss),e.sort&&n.set(lt.sort,e.sort),n}function Eu(e){const n=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),i=new Set(Ci.map(a=>a.key)),o=new Set(Ti.map(a=>a.value)),s=e.get(lt.loss);return{dynasty:Array.from(new Set(n(lt.dynasty).filter(a=>i.has(a)))),classification:Array.from(new Set(n(lt.classification).map(a=>a===yl?"":a).filter(a=>o.has(a)))),hasImage:e.get(lt.hasImage)==="1",hasText:e.get(lt.hasText)==="1"||e.get(lt.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(lt.sort))??""}}function Lu(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 Cs(e,n){return e.includes(n)?e.filter(i=>i!==n):[...e,n]}const Au=({filters:e,onChange:n})=>{const i=Ie(),o=i.searchV4,{convert:s}=Me(),[a,l]=h.useState(!1),d=h.useId(),c=zi(e),p=m=>n({...e,...m});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":s(o.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":a,"aria-controls":d,onClick:()=>l(m=>!m),children:[t.jsxs("span",{children:[s(o.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:s(ft(o.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[s(a?o.collapse:o.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(o.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:Ci.map(m=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(m.key),onClick:()=>p({dynasty:Cs(e.dynasty,m.key)}),children:s(m.key)},m.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(o.classification)}),Ti.map(m=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(m.value),onChange:()=>p({classification:Cs(e.classification,m.value)})}),m.value?s(m.label):i.searchPage.unclassified]},m.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(o.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:m=>p({hasImage:m.target.checked})}),s(o.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:m=>p({hasText:m.target.checked})}),s(o.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:s(o.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:hl.map(m=>t.jsx("button",{type:"button","aria-pressed":e.loss===m.value,onClick:()=>p({loss:m.value}),children:i.searchPage.loss[m.value||"all"]},m.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...$i,sort:e.sort}),children:s(o.clearAllFilters)})]})]})};function jl({text:e,query:n}){const i=(n??"").trim();if(!i||!e)return t.jsx(t.Fragment,{children:e});const o=e.toLowerCase(),s=i.toLowerCase(),a=[];let l=0,d=0;for(;l<e.length;){const c=o.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 Ts=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Ie(),a=s.searchV4,{convert:l}=Me(),d=tt();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),m=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",u=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)}`:""}`:"",g=c.type==="book"?c.era??c.dynasty:c.dynasty,f=g?l(g):"",x=c.classification?l(c.classification):"",v=[];c.has_image&&v.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&v.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&v.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const y=[u,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:_=>i(c,_),children:t.jsx(jl,{text:p,query:n?l(n):void 0})}),m&&t.jsx("span",{className:"bim-sr-measure",children:m})]}),y&&t.jsx("span",{className:"bim-sr-sub",children:y})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(jn,{type:c.type,size:6})," ",o(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:u||"—"}),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:v.map(_=>t.jsx("span",{className:`bim-sr-tag ${_.cls}`,children:l(_.label)},_.label))})]},c.id)})})]})})},Mu=`
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 ${r("rule")}; background: ${r("card-bg")}; color: inherit; text-decoration: none; }
4
4
  .bim-sc:hover { border-color: ${r("rule-dashed")}; box-shadow: ${r("fr-shadow")}; }
@@ -142,7 +142,7 @@
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
- }`,Sl={color:"inherit",textDecoration:"none"},nm=({snippet:e})=>{const{convert:n}=Me();return t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.6},children:Gr(e).map((i,o)=>i.marked?t.jsx("mark",{style:{background:r("highlight-bg"),color:r("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},o):t.jsx(h.Fragment,{children:n(i.text)},o))})},im=({entry:e,selected:n,onClick:i,getConfig:o,query:s})=>{const a=Ie(),{convert:l}=Me(),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||[]],m=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,u=r("cover-accent"),g=tt();return t.jsxs("a",{href:g(e.id),onClick:f=>i(e,f),className:"bim-result-card",style:{...Sl,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:r("bg"),border:n?`1px solid ${r("primary")}`:`1px solid ${r("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, ${u} 50%, ${r("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${u} 14%, ${r("bg")}), color-mix(in srgb, ${u} 7%, ${r("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, ${u} 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:u},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:r("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:r("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:r("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:r("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",l(e.era),"〕"]}),e.edition&&t.jsx("span",{children:l(e.edition)})]}),m&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg")},children:[a.search.alias,":",l(typeof m=="string"?m:m.book_title||"")]}),e.descriptionSnippet&&t.jsx(nm,{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:r("desc-fg"),border:`1px solid ${r("widget-border")}`},children:[t.jsx(jn,{type:e.type,size:8})," ",o(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r("desc-fg"),border:`1px solid ${r("widget-border")}`},children:a.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r("desc-fg"),border:`1px solid ${r("widget-border")}`},children:a.misc.imageResource})]})]})]})},Ms=({entry:e,selected:n,onClick:i,getConfig:o,query:s,onRemove:a})=>{const l=Ie(),{convert:d}=Me(),c=[...e.additional_titles||[],...e.attached_texts||[]],p=s&&c.length?c.find(u=>{const g=typeof u=="string"?u:u==null?void 0:u.book_title;return g==null?void 0:g.toLowerCase().includes(s.toLowerCase())}):void 0,m=tt();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${r("primary")}`:`1px solid ${r("widget-border")}`,background:r("input-bg")},children:[t.jsxs("a",{href:m(e.id),onClick:u=>i(e,u),className:"bim-result-card",style:{...Sl,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(jn,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:r("desc-fg"),lineHeight:1},children:o(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:r("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:r("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:r("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg")},children:[e.juan_count,l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:r("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:r("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:r("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},rm=({id:e,onRemove:n,t:i})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${r("widget-border")}`,background:r("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:r("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:r("desc-fg"),marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function om(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 sm({data:e}){const{convert:n}=Me(),{dynasty:i,birth_year:o,death_year:s}=e,a=[];return i&&a.push(`〔${n(i)}〕`),o!==void 0&&s!==void 0?a.push(`${o}—${s}`):o!==void 0?a.push(`${o}—?`):s!==void 0&&a.push(`?—${s}`),a.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:r("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:a.join(" ")})}function am({alt_names:e}){const{convert:n}=Me(),i=new Map;for(const a of e){const l=a.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(a.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((a,l)=>{const d=o.indexOf(a),c=o.indexOf(l);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(a=>{const l=i.get(a);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:r("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:r("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},a)})})}function lm({data:e}){const n=Ie(),i=e.external_ids;if(!i)return null;const o=[];return i.cbdb_id&&o.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${i.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:r("link-fg"),border:`1px solid ${r("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${r("link-fg")}08`},title:n.common.cbdbTitle,children:["CBDB ",i.cbdb_id]},"cbdb")),o.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function cm({works:e,transport:n,onNavigate:i,renderLink:o}){const s=Ie(),{convert:a}=Me(),l=tt(),[d,c]=h.useState(new Map);h.useEffect(()=>{if(!n)return;let g=!1;const f=e.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const w=await n.getEntriesByIds(f);let j=!0;for(let k=0;k<f.length;k++){const C=w[k];C!=null&&C.title?v.set(f[k],C.title):C!=null&&C.primary_name?v.set(f[k],C.primary_name):j=!1}if(j)return v}catch{}const y=[...f],_=8,b=new Array(_).fill(0).map(async()=>{for(;y.length;){const w=y.shift();if(!w)break;if(!v.has(w))try{if(n.getEntry){const C=await n.getEntry(w);if(C!=null&&C.title){v.set(w,C.title);continue}}const j=await n.getItem(w),k=j&&(j.title||j.primary_name)||w;v.set(w,k)}catch{v.set(w,w)}}});return await Promise.all(b),v})().then(v=>{g||c(v)}),()=>{g=!0}},[e,n]);const p=new Map;for(const g of e){const f=g.role||"";p.has(f)||p.set(f,[]),p.get(f).push(g)}const m=["撰","編","注","輯","集","校","評","譯","述","作",""],u=[...p.keys()].sort((g,f)=>{const x=m.indexOf(g),v=m.indexOf(f);return x===-1&&v===-1?g.localeCompare(f):x===-1?1:v===-1?-1:x-v});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:r("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${r("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:r("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),u.map(g=>{const f=p.get(g);return t.jsxs("div",{style:{marginBottom:"8px"},children:[g&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"2px"},children:[a(g)," ",t.jsxs("span",{style:{color:r("desc-fg")},children:["(",f.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:f.map((x,v)=>{const y=a(d.get(x.work_id)||x.work_id);return o?t.jsx("li",{children:o(x.work_id,y)},v):i?t.jsx("li",{children:t.jsx("a",{href:l(x.work_id),onClick:_=>{_.metaKey||_.ctrlKey||(_.preventDefault(),i(x.work_id))},style:{color:r("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},v):t.jsx("li",{children:y},v)})})]},g)})]})}const _l=({data:e,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:a})=>{var u;const l=Ie(),{convert:d}=Me();let c=!1;try{c=_e.extractStatus(e.id)==="draft"}catch{}const p=om(e),m=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:r("fg")},children:[d(e.primary_name),t.jsx(sm,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:r("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:r("type-entity"),border:`1px solid color-mix(in srgb, ${r("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${r("type-entity")} 3%, transparent)`},children:l.indexType.entity}),m&&e.subtype!=="people"&&t.jsx("span",{children:m}),c&&t.jsx("span",{style:{padding:"1px 6px",background:r("warn-bg"),border:`1px solid ${r("warn-border")}`,borderRadius:"2px",color:r("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:r("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:r("widget-bg"),border:`1px dashed ${r("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:l.common.entityPlaceholderNote}),e.alt_names&&e.alt_names.length>0&&t.jsx(am,{alt_names:e.alt_names}),t.jsx(lm,{data:e}),((u=e.description)==null?void 0:u.text)&&t.jsx("p",{style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(cm,{works:e.works,transport:n,onNavigate:i,renderLink:o})]})},dm=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function pm(e){const n=e.search(dm);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const $l={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,o="",s=n;if(e&&typeof n=="string"&&(n===e||n===um(e))){const[a,l]=pm(n);l&&(i=encodeURI(a),s=a,o=l)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:r("link")},children:s}),o]})},code:({children:e})=>t.jsx("code",{style:{background:r("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function um(e){try{return decodeURI(e)}catch{return e}}const mm={...$l,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Bt=({text:e,plainStrong:n,style:i,className:o})=>{const{convert:s}=Me(),a=n?mm:$l;return t.jsx("div",{className:o,style:i,children:t.jsx(Pp,{remarkPlugins:[Bp],components:a,children:s(e)})})},gm=["〇","一","二","三","四","五","六","七","八","九"],Ps=["","十","百","千"];function Cl(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let o="",s=!1;for(let a=0;a<i;a++){const l=parseInt(n[a]),d=i-1-a;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&d===1&&a===0?o+=Ps[d]:o+=gm[l]+Ps[d])}return o}function Tl(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 hm={book:r("type-book"),work:r("type-work"),collection:r("type-collection"),entity:r("type-entity")};function fm({type:e}){const n=Ie();return t.jsx("span",{style:Tl(hm[e]),children:n.indexType[e]})}function xm({isDraft:e}){const n=Ie(),i=r(e?"status-draft":"status-official");return t.jsx("span",{style:Tl(i),children:e?n.status.draft:n.status.official})}function bm({id:e}){const n=Ie(),[i,o]=h.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:r("desc-fg"),background:r("bg-subtle"),border:`1px solid ${r("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:r("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:a=>a.currentTarget.style.opacity="1",onMouseLeave:a=>a.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function bt({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:r("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function $t({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:r("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:r("fg")},children:n})]})}function zl({authors:e,type:n,onNavigate:i,renderLink:o}){const{convert:s}=Me();return t.jsx("span",{style:{fontSize:"14px",color:r("fg"),lineHeight:1.6},children:e.map((a,l)=>{const d=s(a.name),c=a.entity_id?t.jsx(wt,{id:a.entity_id,label:d,onNavigate:i,renderLink:o}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[l>0&&t.jsx("span",{style:{color:r("desc-fg"),margin:"0 4px"},children:"·"}),a.dynasty&&t.jsxs("span",{style:{color:r("desc-fg"),fontSize:"12px"},children:["〔",s(a.dynasty),"〕"]}),c,a.role&&t.jsxs("span",{style:{color:r("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(a.role)]})]},l)})})}function wt({id:e,label:n,onNavigate:i,renderLink:o}){const s=tt();return o?t.jsx(t.Fragment,{children:o(e,n)}):i?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i(e))},style:{color:r("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${r("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 ym({id:e,title:n,edition:i,type:o,isDraft:s,authors:a,volumeText:l,meta:d,headerExtra:c,onNavigate:p,renderLink:m}){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:r("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:i}),l&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:r("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(fm,{type:o}),t.jsx(xm,{isDraft:s}),t.jsx(bm,{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(zl,{authors:a,type:o,onNavigate:p,renderLink:m}),d]})]})}function Nl({items:e,label:n,showMeta:i,onNavigate:o,renderLink:s}){const a=Ie(),{convert:l}=Me();if(!e.length)return null;const[d,c]=h.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((p,m)=>{const u=d===m;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:r("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(u?null:m),style:{padding:"8px 12px",background:r("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:r("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:l(p.source)}),!u&&i&&p.title_info&&t.jsx("span",{style:{fontSize:"12px",color:r("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(p.title_info)}),p.source_bid&&t.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(wt,{id:p.source_bid,label:a.action.view,onNavigate:o,renderLink:s})})]}),u&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${r("widget-border")}`},children:[i&&(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($t,{label:a.label.titleInfo,children:l(p.title_info)}),p.author_info&&t.jsx($t,{label:a.label.authorInfo,children:l(p.author_info)}),p.edition&&t.jsx($t,{label:a.label.edition,children:l(p.edition)})]}),p.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${r("primary")}`,background:`color-mix(in srgb, ${r("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:a.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:r("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 ${r("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:a.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:r("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 ${r("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:a.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.additional_comment)})]})]})]},m)})})]})}function jm({items:e,onNavigate:n,renderLink:i}){const o=Ie();return t.jsx(Nl,{items:e,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Il({items:e,onNavigate:n,renderLink:i}){const o=Ie();return t.jsx(Nl,{items:e,label:o.section.emendated,onNavigate:n,renderLink:i})}function Rl({label:e,items:n}){const{convert:i}=Me();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const a=typeof o=="string"?o:o.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:r("fg"),border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:i(a)},s)})})]}):null}function vm({items:e}){const n=Ie();return t.jsx(Rl,{label:n.section.aliases,items:e})}function km({items:e}){const n=Ie();return t.jsx(Rl,{label:n.section.attachedTexts,items:e})}function wm({items:e}){const n=Ie(),{convert:i}=Me();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((o,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:r("fg"),border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:["《",i(o.book_title),"》",o.n_juan!=null&&t.jsxs("span",{style:{color:r("desc-fg"),fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function Sm({items:e}){const n=Ie(),{convert:i}=Me();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{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:r("widget-border")}}),e.map((o,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:r("primary"),border:`1.5px solid ${r("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:r("fg")},children:i(o.name)}),o.description&&t.jsx("span",{style:{fontSize:"12px",color:r("desc-fg"),marginLeft:"8px"},children:i(o.description)})]},s))]})]}):null}function _m({items:e}){const n=Ie(),{convert:i}=Me();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((o,s)=>t.jsxs("div",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:r("desc-fg")},children:"·"}),i(o)]},s))})]}):null}function Bs({title:e,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:a}=Me(),[l,d]=h.useState([]);return h.useEffect(()=>{if(!n.length){d([]);return}if(!i){d(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>i.getItem(p).then(m=>({id:p,title:m?m.title:void 0,edition:m?m.edition:void 0,type:m?m.type:void 0})).catch(()=>({id:p})))).then(p=>{c||d(p)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(bt,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:r("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 ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg"),transition:"border-color 0.15s"},children:t.jsx(wt,{id:c.id,label:p,onNavigate:o,renderLink:s})},c.id)})})]}):null}function sr({book:e,onNavigate:n,renderLink:i}){const o=Ie(),{convert:s}=Me(),[a,l]=h.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 ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:r("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:d&&!a?`1px solid ${r("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(wt,{id:e.id,label:c,onNavigate:n,renderLink:i})}),d&&t.jsx("span",{onClick:()=>l(p=>!p),style:{cursor:"pointer",fontSize:"10px",color:r("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:a?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:a?o.action.expand:o.action.collapse,children:"▼"})]}),d&&!a&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Jr,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function $m({ids:e,workData:n,transport:i,onNavigate:o,renderLink:s,footer:a}){const l=Ie(),{convert:d}=Me(),[c,p]=h.useState([]);if(h.useEffect(()=>{if(!e.length){p([]);return}if(!i){p(e.map(v=>({id:v})));return}let x=!1;return Promise.all(e.map(v=>i.getItem(v).then(y=>({id:v,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:v})))).then(v=>{x||p(v)}),()=>{x=!0}},[e,i]),!e.length)return null;const m=c.length?c:e.map(x=>({id:x})),u=new Map(m.map(x=>[x.id,x])),g=n==null?void 0:n.version_graph,f=Cm(e,g,l.common.otherVersions);return t.jsxs(t.Fragment,{children:[t.jsxs(bt,{children:[l.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:r("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 v=u.get(x);return v?t.jsx(sr,{book:v,onNavigate:o,renderLink:s},x):null})}),f.groupedIds.map(x=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${r("widget-border")}`,borderRadius:6,background:r("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:r("fg"),userSelect:"none"},children:[d(x.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:r("desc-fg"),fontWeight:400},children:["(",x.ids.length,")"]}),x.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:r("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(v=>{const y=u.get(v);return y?t.jsx(sr,{book:y,onNavigate:o,renderLink:s},v):null})})]},x.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.map(x=>t.jsx(sr,{book:x,onNavigate:o,renderLink:s},x.id))})]})}function Cm(e,n,i){var _,b;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(_=n.collections)==null?void 0:_[n.default_collection],s=(o==null?void 0:o.groups)??[],a=(o==null?void 0:o.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]),m=w=>{if(p.has(w))return!0;const j=n.node_groups[w];return j!=null&&c.has(j)},u=[],g=new Map,f=[];for(const w of e)if(!((b=n.excluded_books)!=null&&b.includes(w)))if(m(w))u.push(w);else{const j=n.node_groups[w];j?(g.has(j)||g.set(j,[]),g.get(j).push(w)):f.push(w)}if(f.length+[...g.values()].reduce((w,j)=>w+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const v=new Map((n.groups??[]).map(w=>[w.id,w])),y=[...g.entries()].map(([w,j])=>{const k=v.get(w);return{id:w,label:(k==null?void 0:k.label)??w,description:k==null?void 0:k.description,ids:j}});return f.length>0&&y.push({id:"__other__",label:i,description:void 0,ids:f}),{useGrouping:!0,coreIds:u,groupedIds:y}}function Tm({workData:e,onNavigate:n,renderLink:i}){var l,d,c,p;const o=Ie(),{convert:s}=Me(),a=!!((l=e.description)!=null&&l.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:r("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:a?`1px solid ${r("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${r("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:r("fg")},children:t.jsx(wt,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:r("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:r("desc-fg")},children:[Cl(e.juan_count.number),o.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(zl,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),a&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(Bt,{text:e.description.text,style:{fontSize:"13px",color:r("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($t,{label:o.label.parentWork,children:t.jsx(wt,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function zm({items:e,onNavigate:n,renderLink:i}){const o=Ie(),{convert:s}=Me();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, ${r("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${r("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:r("type-collection")},children:o.indexType.collection}),t.jsx(wt,{id:a.id,label:s(a.title)||a.id,onNavigate:n,renderLink:i}),a.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),marginLeft:"2px"},children:ft(o.catalog.volume,{n:a.volume_index})})]},a.id))}):null}const no=({data:e,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:a,relatedBooksFooter:l,className:d,style:c})=>{var P,R,N,A,H,G,ie,le;const p=Ie(),{convert:m}=Me(),[u,g]=h.useState(null),[f,x]=h.useState(!1),[v,y]=h.useState(null),[_,b]=h.useState(null),[w,j]=h.useState([]),k=e||u;if(h.useEffect(()=>{if(e||!n||!i)return;let V=!1;return x(!0),y(null),i.getItem(n).then(F=>{V||(F?g(F):y(p.misc.notFoundEntry))}).catch(F=>{V||y(F instanceof Error?F.message:p.misc.loadFailed)}).finally(()=>{V||x(!1)}),()=>{V=!0}},[e,n,i]),h.useEffect(()=>{if(!k||!i){b(null),j([]);return}let V=!1;const F=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(F?i.getItem(F).then(xe=>{!V&&xe&&xe.type==="work"&&b(xe)}).catch(()=>{}):b(null),k.type==="book"){const xe=k;xe.contained_in&&xe.contained_in.length>0?Promise.all(xe.contained_in.map(ee=>{const L=typeof ee=="string"?ee:ee.id,Re=typeof ee=="string"?void 0:ee.volume_index;return i.getItem(L).then(ce=>({id:L,title:ce&&ce.title||L,volume_index:Re})).catch(()=>({id:L,title:L,volume_index:Re}))})).then(ee=>{V||j(ee)}):j([])}else j([]);return()=>{V=!0}},[k,i]),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((V,F)=>t.jsx("div",{style:{height:F===1?"32px":"16px",width:`${V}px`,background:r("widget-border"),borderRadius:"4px",opacity:.4}},F))})});if(v)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:v});if(!k)return null;if(k.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(_l,{data:k,transport:i,onNavigate:o,renderLink:s,headerExtra:a})});const C=k.type==="book"?k:null,$=k.type==="collection"?k:null,S=k.type==="work"?k:null;let M=!1;try{M=_e.extractStatus(k.id)==="draft"}catch{}let z="";k.measure_info?z=m(k.measure_info):(P=k.juan_count)!=null&&P.number?z=Cl(k.juan_count.number)+p.unit.juan:(R=k.juan_count)!=null&&R.description&&(z=m(k.juan_count.description));const T=[];return(N=k.publication_info)!=null&&N.year&&T.push(t.jsx($t,{label:p.label.year,children:k.publication_info.year},"year")),(A=k.current_location)!=null&&A.name&&T.push(t.jsx($t,{label:p.label.currentLocation,children:m(k.current_location.name)},"loc")),(H=k.page_count)!=null&&H.description&&T.push(t.jsx($t,{label:p.label.pageCount,children:k.page_count.description},"page")),C!=null&&C.edition&&T.push(t.jsx($t,{label:p.label.edition,children:m(C.edition)},"ver")),S!=null&&S.parent_work&&T.push(t.jsx($t,{label:p.label.parentWork,children:t.jsx(wt,{id:S.parent_work.id,label:m(S.parent_work.title),onNavigate:o,renderLink:s})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&T.push(t.jsx($t,{label:p.label.parentWork,children:S.parent_works.map((V,F)=>t.jsxs("span",{children:[F>0&&"、",t.jsx(wt,{id:V,onNavigate:o,renderLink:s})]},V))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(ym,{id:k.id,title:m(k.title),edition:k.edition?m(k.edition):void 0,type:k.type,isDraft:M,authors:k.authors,volumeText:z,meta:T,headerExtra:a,onNavigate:o,renderLink:s}),((G=k.description)==null?void 0:G.text)&&t.jsx(Bt,{text:k.description.text,style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((V,F)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:r("bg-subtle"),borderRadius:4,border:`1px solid ${r("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:r("muted")},children:m(V.title)}),t.jsx(Bt,{text:V.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:r("fg")}})]},F))}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:p.section.containedIn}),t.jsx(zm,{items:w,onNavigate:o,renderLink:s})]}),_&&t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:p.section.belongsToWork}),t.jsx(Tm,{workData:_,onNavigate:o,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&t.jsx(wm,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&t.jsx(vm,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&t.jsx(km,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&t.jsx(jm,{items:k.indexed_by,onNavigate:o,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&t.jsx(Il,{items:k.emendated_by,onNavigate:o,renderLink:s}),k.resources&&k.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:p.section.resources}),t.jsx(Jr,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&t.jsx(Sm,{items:C.location_history}),($==null?void 0:$.history)&&$.history.length>0&&t.jsx(_m,{items:$.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&t.jsx(Bs,{title:p.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:o,renderLink:s}),($==null?void 0:$.books)&&$.books.length>0&&t.jsx(Bs,{title:p.section.containedBooks,ids:$.books,transport:i,onNavigate:o,renderLink:s}),($==null?void 0:$.contained_works)&&$.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(bt,{children:[p.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",$.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:$.contained_works.map(V=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:t.jsx(wt,{id:V.id,label:m(V.title),onNavigate:o,renderLink:s})},V.id))})]}),(((ie=S==null?void 0:S.books)==null?void 0:ie.length)||0)+(((le=S==null?void 0:S.collections)==null?void 0:le.length)||0)>0&&t.jsx($m,{ids:[...(S==null?void 0:S.books)||[],...(S==null?void 0:S.collections)||[]],workData:S??void 0,transport:i,onNavigate:o,renderLink:s,footer:l}),(S==null?void 0:S.related_works)&&S.related_works.length>0&&(()=>{const V=[],F=S.related_works.filter(me=>me.relation==="part_of"),xe=S.related_works.filter(me=>me.relation==="has_part"),ee=S.related_works.filter(me=>me.relation==="has_adaptation"),L=S.related_works.filter(me=>me.relation==="text_carried_by"),Re=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ce=S.related_works.filter(me=>!me.relation||!Re.has(me.relation));return F.length>0&&V.push({label:p.section.belongsToWork,items:F}),xe.length>0&&V.push({label:p.section.containedWorks,items:xe}),ee.length>0&&V.push({label:p.section.adaptations,items:ee}),L.length>0&&V.push({label:p.section.derivativeWorks,items:L}),ce.length>0&&V.push({label:p.section.relatedWorks,items:ce}),V.map(me=>t.jsxs("div",{children:[t.jsxs(bt,{children:[me.label,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",me.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:me.items.map(se=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:t.jsx(wt,{id:se.id,label:m(se.title),onNavigate:o,renderLink:s})},se.id))})]},me.label))})()]})};function Nm({data:e}){const n=Ie(),{convert:i}=Me(),{stats:o}=e,s=o.processed_volumes??o.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:r("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:r("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:r("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:r("fg")},children:e.total_volumes})," ",n.unit.volume]}),a!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:r("fg")},children:s})," ",n.unit.volume," (",a,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:r("fg")},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:r("fg")},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:r("missing-fg")},children:o.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:r("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Im({sections:e,activeSection:n,onSelect:i}){const o=Ie();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:Ws(n===null),children:o.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:Ws(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 Ws(e){return{padding:"4px 12px",border:e?`1px solid ${r("primary")}`:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${r("primary")} 8%, transparent)`:"transparent",color:r(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Rm({id:e,label:n,onNavigate:i,renderLink:o}){const s=tt();return o?t.jsx(t.Fragment,{children:o(e,n)}):i?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i(e))},style:{color:r("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${r("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:r("desc-fg")},children:n||e})}function Em(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],o=e[e.length-1];return o-i+1===e.length?`${i}–${o}`:e.length<=3?e.join(", "):`${i}–${o} (${e.length}${n})`}function Os({book:e,onNavigate:n,renderLink:i,showVolumes:o}){const s=Ie(),{convert:a}=Me(),l=e.book_id||e.work_id,d=o&&e.volumes.length>0?Em(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 ${r("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[o&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:r("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:r("fg")},children:[a(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(p=>a(p)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:r(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),l&&t.jsx(Rm,{id:l,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!l&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const io=({data:e,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:a,style:l})=>{const d=Ie(),[c,p]=h.useState(null),[m,u]=h.useState(!1),[g,f]=h.useState(null),[x,v]=h.useState(null),[y,_]=h.useState(""),b=e||c;h.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let $=!1;return u(!0),f(null),i.getCollectionCatalog(n).then(S=>{$||(S?p(S):f(d.catalog.notFound))}).catch(S=>{$||f(S instanceof Error?S.message:d.catalog.loadFailed)}).finally(()=>{$||u(!1)}),()=>{$=!0}},[e,n,i,d]);const w=(b==null?void 0:b.sections)&&b.sections.length>0,j=h.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]),k=h.useMemo(()=>{if(!b)return[];let $=b.books;if(x&&($=$.filter(S=>S.section===x)),y.trim()){const S=y.trim().toLowerCase();$=$.filter(M=>M.title.toLowerCase().includes(S)||M.sub_items&&M.sub_items.some(z=>z.toLowerCase().includes(S))||M.edition&&M.edition.toLowerCase().includes(S))}return $},[b,x,y]),C=h.useMemo(()=>{if(!j)return null;const $=[],S=new Map;for(const z of k){if(!z.volumes||z.volumes.length===0)continue;const T=z.volumes[0];S.has(T)||S.set(T,[]),S.get(T).push(z)}const M=[...S.keys()].sort((z,T)=>z-T);for(const z of M)$.push({volume:z,books:S.get(z)});return $},[k,j]);return m?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:r("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):g?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:g}):b?t.jsxs("div",{className:a,style:l,children:[t.jsx(Nm,{data:b}),w&&t.jsx(Im,{sections:b.sections,activeSection:x,onSelect:v}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:y,onChange:$=>_($.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${r("input-border")}`,borderRadius:"4px",background:r("input-bg"),color:r("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:r("desc-fg")},children:[k.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[C?C.map(($,S)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:r("bg"),borderBottom:`1px solid ${r("widget-border")}`,fontSize:"12px",fontWeight:600,color:r("desc-fg"),position:"sticky",top:0,zIndex:1},children:ft(d.catalog.volume,{n:$.volume})}),$.books.map((M,z)=>t.jsx(Os,{book:M,onNavigate:o,renderLink:s,showVolumes:M.volumes.length>1},`${$.volume}-${z}`))]},`${$.volume}-${S}`)):k.map(($,S)=>t.jsx(Os,{book:$,onNavigate:o,renderLink:s,showVolumes:!0},S)),k.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},ar=e=>e?e.catch(()=>null):Promise.resolve(null);function El(e){const n=new Map;function i(o){var a;let s=n.get(o);return s||(s=ar((a=e.getTextManifest)==null?void 0:a.call(e,o)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||n.delete(o),d}),n.set(o,s)),s}return{getManifest(o){return _e.isSafeSegment(o)?i(o):Promise.resolve(null)},async getIndex(o,s){return!_e.isSafeSegment(o)||!_e.isSafeSegment(s)||!e.getTextIndex?null:ar(e.getTextIndex(o,s))},async getChapter(o,s,a,l){return!_e.isSafeSegment(o)||!_e.isSafeSegment(s)||!_e.isSafeSegment(a)||!e.getChapter?null:ar(e.getChapter(o,s,a,l))}}}const nn=()=>{const{t:e}=te(),[n,i]=h.useState(1);return h.useEffect(()=>{const o=setInterval(()=>i(s=>s>=3?1:s+1),500);return()=>clearInterval(o)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:r("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(n)})},lr=String.raw`https?:\/\/[^\s()()<>"]+`,Lm=new RegExp(String.raw`\[([^\]\n]+)\]\((${lr})\)`+String.raw`|(《[^》\n]+》)\s?[((](${lr})[))]`+`|(${lr})`,"g");function Am(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Mm(e){const n=[];let i=0;for(const o of e.matchAll(Lm)){const s=o.index??0;s>i&&n.push({text:e.slice(i,s)}),o[1]!==void 0?n.push({text:o[1],url:o[2]}):o[3]!==void 0?n.push({text:o[3],url:o[4]}):n.push({text:Am(o[5]),url:o[5]}),i=s+o[0].length}return i<e.length&&n.push({text:e.slice(i)}),n}function Ll({text:e,convert:n,className:i="bim-rd-link"}){return t.jsx(t.Fragment,{children:Mm(e).map((o,s)=>o.url?t.jsx("a",{className:i,href:o.url,target:"_blank",rel:"noopener noreferrer",children:n(o.text)},s):t.jsx(h.Fragment,{children:n(o.text)},s))})}const Al="(min-width: 1100px)",Ml="(max-width: 719px)",Pl="(max-width: 859px)",Pm=`${Ml}, (pointer: coarse)`,_t=r("reader-top"),Bm="48px",Bl=`
145
+ }`,Sl={color:"inherit",textDecoration:"none"},nm=({snippet:e})=>{const{convert:n}=Me();return t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.6},children:Gr(e).map((i,o)=>i.marked?t.jsx("mark",{style:{background:r("highlight-bg"),color:r("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:n(i.text)},o):t.jsx(h.Fragment,{children:n(i.text)},o))})},im=({entry:e,selected:n,onClick:i,getConfig:o,query:s})=>{const a=Ie(),{convert:l}=Me(),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||[]],m=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,u=r("cover-accent"),g=tt();return t.jsxs("a",{href:g(e.id),onClick:f=>i(e,f),className:"bim-result-card",style:{...Sl,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:r("bg"),border:n?`1px solid ${r("primary")}`:`1px solid ${r("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, ${u} 50%, ${r("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${u} 14%, ${r("bg")}), color-mix(in srgb, ${u} 7%, ${r("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, ${u} 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:u},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:r("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:r("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:r("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:r("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",l(e.era),"〕"]}),e.edition&&t.jsx("span",{children:l(e.edition)})]}),m&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg")},children:[a.search.alias,":",l(typeof m=="string"?m:m.book_title||"")]}),e.descriptionSnippet&&t.jsx(nm,{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:r("desc-fg"),border:`1px solid ${r("widget-border")}`},children:[t.jsx(jn,{type:e.type,size:8})," ",o(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r("desc-fg"),border:`1px solid ${r("widget-border")}`},children:a.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r("desc-fg"),border:`1px solid ${r("widget-border")}`},children:a.misc.imageResource})]})]})]})},Ms=({entry:e,selected:n,onClick:i,getConfig:o,query:s,onRemove:a})=>{const l=Ie(),{convert:d}=Me(),c=[...e.additional_titles||[],...e.attached_texts||[]],p=s&&c.length?c.find(u=>{const g=typeof u=="string"?u:u==null?void 0:u.book_title;return g==null?void 0:g.toLowerCase().includes(s.toLowerCase())}):void 0,m=tt();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:n?`1px solid ${r("primary")}`:`1px solid ${r("widget-border")}`,background:r("input-bg")},children:[t.jsxs("a",{href:m(e.id),onClick:u=>i(e,u),className:"bim-result-card",style:{...Sl,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(jn,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:r("desc-fg"),lineHeight:1},children:o(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:r("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:r("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:r("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg")},children:[e.juan_count,l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:r("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:r("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:r("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},rm=({id:e,onRemove:n,t:i})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${r("widget-border")}`,background:r("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:r("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:r("desc-fg"),marginTop:"2px"},children:i.search.itemNotFound})]}),t.jsx("button",{onClick:()=>n(e),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function om(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 sm({data:e}){const{convert:n}=Me(),{dynasty:i,birth_year:o,death_year:s}=e,a=[];return i&&a.push(`〔${n(i)}〕`),o!==void 0&&s!==void 0?a.push(`${o}—${s}`):o!==void 0?a.push(`${o}—?`):s!==void 0&&a.push(`?—${s}`),a.length===0?null:t.jsx("span",{style:{fontSize:"14px",color:r("desc-fg"),marginLeft:"8px",fontWeight:"normal"},children:a.join(" ")})}function am({alt_names:e}){const{convert:n}=Me(),i=new Map;for(const a of e){const l=a.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(a.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((a,l)=>{const d=o.indexOf(a),c=o.indexOf(l);return d===-1&&c===-1?0:d===-1?1:c===-1?-1:d-c});return t.jsx("div",{style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"8px 0 4px"},children:s.map(a=>{const l=i.get(a);return t.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[t.jsx("span",{style:{color:r("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:r("desc-fg"),margin:"0 4px"},children:"·"}),n(d)]},c))})]},a)})})}function lm({data:e}){const n=Ie(),i=e.external_ids;if(!i)return null;const o=[];return i.cbdb_id&&o.push(t.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${i.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:r("link-fg"),border:`1px solid ${r("link-fg")}40`,borderRadius:"3px",textDecoration:"none",background:`${r("link-fg")}08`},title:n.common.cbdbTitle,children:["CBDB ",i.cbdb_id]},"cbdb")),o.length===0?null:t.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function cm({works:e,transport:n,onNavigate:i,renderLink:o}){const s=Ie(),{convert:a}=Me(),l=tt(),[d,c]=h.useState(new Map);h.useEffect(()=>{if(!n)return;let g=!1;const f=e.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const w=await n.getEntriesByIds(f);let j=!0;for(let k=0;k<f.length;k++){const C=w[k];C!=null&&C.title?v.set(f[k],C.title):C!=null&&C.primary_name?v.set(f[k],C.primary_name):j=!1}if(j)return v}catch{}const y=[...f],_=8,b=new Array(_).fill(0).map(async()=>{for(;y.length;){const w=y.shift();if(!w)break;if(!v.has(w))try{if(n.getEntry){const C=await n.getEntry(w);if(C!=null&&C.title){v.set(w,C.title);continue}}const j=await n.getItem(w),k=j&&(j.title||j.primary_name)||w;v.set(w,k)}catch{v.set(w,w)}}});return await Promise.all(b),v})().then(v=>{g||c(v)}),()=>{g=!0}},[e,n]);const p=new Map;for(const g of e){const f=g.role||"";p.has(f)||p.set(f,[]),p.get(f).push(g)}const m=["撰","編","注","輯","集","校","評","譯","述","作",""],u=[...p.keys()].sort((g,f)=>{const x=m.indexOf(g),v=m.indexOf(f);return x===-1&&v===-1?g.localeCompare(f):x===-1?1:v===-1?-1:x-v});return t.jsxs("div",{style:{marginTop:"12px"},children:[t.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:r("fg"),margin:"0 0 8px",paddingBottom:"4px",borderBottom:`1px solid ${r("widget-border")}`},children:[s.label.relatedWorks," ",t.jsxs("span",{style:{color:r("desc-fg"),fontWeight:"normal",fontSize:"12px"},children:["(",e.length,")"]})]}),u.map(g=>{const f=p.get(g);return t.jsxs("div",{style:{marginBottom:"8px"},children:[g&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"2px"},children:[a(g)," ",t.jsxs("span",{style:{color:r("desc-fg")},children:["(",f.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:f.map((x,v)=>{const y=a(d.get(x.work_id)||x.work_id);return o?t.jsx("li",{children:o(x.work_id,y)},v):i?t.jsx("li",{children:t.jsx("a",{href:l(x.work_id),onClick:_=>{_.metaKey||_.ctrlKey||(_.preventDefault(),i(x.work_id))},style:{color:r("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},v):t.jsx("li",{children:y},v)})})]},g)})]})}const _l=({data:e,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:a})=>{var u;const l=Ie(),{convert:d}=Me();let c=!1;try{c=_e.extractStatus(e.id)==="draft"}catch{}const p=om(e),m=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:r("fg")},children:[d(e.primary_name),t.jsx(sm,{data:e})]}),s]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:r("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:r("type-entity"),border:`1px solid color-mix(in srgb, ${r("type-entity")} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${r("type-entity")} 3%, transparent)`},children:l.indexType.entity}),m&&e.subtype!=="people"&&t.jsx("span",{children:m}),c&&t.jsx("span",{style:{padding:"1px 6px",background:r("warn-bg"),border:`1px solid ${r("warn-border")}`,borderRadius:"2px",color:r("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:r("desc-fg"),fontStyle:"italic",padding:"8px 12px",background:r("widget-bg"),border:`1px dashed ${r("widget-border")}`,borderRadius:"4px",margin:"8px 0"},children:l.common.entityPlaceholderNote}),e.alt_names&&e.alt_names.length>0&&t.jsx(am,{alt_names:e.alt_names}),t.jsx(lm,{data:e}),((u=e.description)==null?void 0:u.text)&&t.jsx("p",{style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:d(e.description.text)}),e.works&&e.works.length>0&&t.jsx(cm,{works:e.works,transport:n,onNavigate:i,renderLink:o})]})},dm=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function pm(e){const n=e.search(dm);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const $l={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:n})=>{let i=e,o="",s=n;if(e&&typeof n=="string"&&(n===e||n===um(e))){const[a,l]=pm(n);l&&(i=encodeURI(a),s=a,o=l)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:i,target:i!=null&&i.startsWith("http")?"_blank":void 0,rel:i!=null&&i.startsWith("http")?"noopener noreferrer":void 0,style:{color:r("link")},children:s}),o]})},code:({children:e})=>t.jsx("code",{style:{background:r("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function um(e){try{return decodeURI(e)}catch{return e}}const mm={...$l,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Pt=({text:e,plainStrong:n,style:i,className:o})=>{const{convert:s}=Me(),a=n?mm:$l;return t.jsx("div",{className:o,style:i,children:t.jsx(Pp,{remarkPlugins:[Bp],components:a,children:s(e)})})},gm=["〇","一","二","三","四","五","六","七","八","九"],Ps=["","十","百","千"];function Cl(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let o="",s=!1;for(let a=0;a<i;a++){const l=parseInt(n[a]),d=i-1-a;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&d===1&&a===0?o+=Ps[d]:o+=gm[l]+Ps[d])}return o}function Tl(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 hm={book:r("type-book"),work:r("type-work"),collection:r("type-collection"),entity:r("type-entity")};function fm({type:e}){const n=Ie();return t.jsx("span",{style:Tl(hm[e]),children:n.indexType[e]})}function xm({isDraft:e}){const n=Ie(),i=r(e?"status-draft":"status-official");return t.jsx("span",{style:Tl(i),children:e?n.status.draft:n.status.official})}function bm({id:e}){const n=Ie(),[i,o]=h.useState(!1),s=()=>{navigator.clipboard.writeText(e).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:r("desc-fg"),background:r("bg-subtle"),border:`1px solid ${r("widget-border")}`,borderRadius:"2px"},children:[t.jsx("span",{children:n.label.id}),t.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:r("fg")},children:e}),t.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:a=>a.currentTarget.style.opacity="1",onMouseLeave:a=>a.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function bt({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:r("desc-fg"),letterSpacing:"1px"},children:e}),t.jsx("span",{style:{flex:1}}),n]})}function $t({label:e,children:n}){return t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[t.jsx("span",{style:{color:r("desc-fg"),fontSize:"12px"},children:e}),t.jsx("span",{style:{color:r("fg")},children:n})]})}function zl({authors:e,type:n,onNavigate:i,renderLink:o}){const{convert:s}=Me();return t.jsx("span",{style:{fontSize:"14px",color:r("fg"),lineHeight:1.6},children:e.map((a,l)=>{const d=s(a.name),c=a.entity_id?t.jsx(wt,{id:a.entity_id,label:d,onNavigate:i,renderLink:o}):t.jsx("span",{style:{fontWeight:500},children:d});return t.jsxs("span",{children:[l>0&&t.jsx("span",{style:{color:r("desc-fg"),margin:"0 4px"},children:"·"}),a.dynasty&&t.jsxs("span",{style:{color:r("desc-fg"),fontSize:"12px"},children:["〔",s(a.dynasty),"〕"]}),c,a.role&&t.jsxs("span",{style:{color:r("desc-fg"),fontSize:"12px",marginLeft:"2px"},children:[" ",s(a.role)]})]},l)})})}function wt({id:e,label:n,onNavigate:i,renderLink:o}){const s=tt();return o?t.jsx(t.Fragment,{children:o(e,n)}):i?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i(e))},style:{color:r("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${r("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 ym({id:e,title:n,edition:i,type:o,isDraft:s,authors:a,volumeText:l,meta:d,headerExtra:c,onNavigate:p,renderLink:m}){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:r("fg"),margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&t.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:i}),l&&t.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:r("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(fm,{type:o}),t.jsx(xm,{isDraft:s}),t.jsx(bm,{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(zl,{authors:a,type:o,onNavigate:p,renderLink:m}),d]})]})}function Nl({items:e,label:n,showMeta:i,onNavigate:o,renderLink:s}){const a=Ie(),{convert:l}=Me();if(!e.length)return null;const[d,c]=h.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((p,m)=>{const u=d===m;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...u?{boxShadow:r("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(u?null:m),style:{padding:"8px 12px",background:r("input-bg"),cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[t.jsx("span",{style:{fontSize:"10px",color:r("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:l(p.source)}),!u&&i&&p.title_info&&t.jsx("span",{style:{fontSize:"12px",color:r("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(p.title_info)}),p.source_bid&&t.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(wt,{id:p.source_bid,label:a.action.view,onNavigate:o,renderLink:s})})]}),u&&t.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:`1px solid ${r("widget-border")}`},children:[i&&(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($t,{label:a.label.titleInfo,children:l(p.title_info)}),p.author_info&&t.jsx($t,{label:a.label.authorInfo,children:l(p.author_info)}),p.edition&&t.jsx($t,{label:a.label.edition,children:l(p.edition)})]}),p.summary&&t.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:`3px solid ${r("primary")}`,background:`color-mix(in srgb, ${r("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:a.section.summary}),t.jsx("p",{style:{fontSize:"13px",color:r("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 ${r("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:a.section.comment}),t.jsx("p",{style:{fontSize:"13px",color:r("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 ${r("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:a.section.additionalComment}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(p.additional_comment)})]})]})]},m)})})]})}function jm({items:e,onNavigate:n,renderLink:i}){const o=Ie();return t.jsx(Nl,{items:e,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Il({items:e,onNavigate:n,renderLink:i}){const o=Ie();return t.jsx(Nl,{items:e,label:o.section.emendated,onNavigate:n,renderLink:i})}function Rl({label:e,items:n}){const{convert:i}=Me();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const a=typeof o=="string"?o:o.book_title;return t.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:r("fg"),border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:i(a)},s)})})]}):null}function vm({items:e}){const n=Ie();return t.jsx(Rl,{label:n.section.aliases,items:e})}function km({items:e}){const n=Ie();return t.jsx(Rl,{label:n.section.attachedTexts,items:e})}function wm({items:e}){const n=Ie(),{convert:i}=Me();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:n.section.appendix}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:e.map((o,s)=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:r("fg"),border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:["《",i(o.book_title),"》",o.n_juan!=null&&t.jsxs("span",{style:{color:r("desc-fg"),fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function Sm({items:e}){const n=Ie(),{convert:i}=Me();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{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:r("widget-border")}}),e.map((o,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:r("primary"),border:`1.5px solid ${r("input-bg")}`}}),t.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:r("fg")},children:i(o.name)}),o.description&&t.jsx("span",{style:{fontSize:"12px",color:r("desc-fg"),marginLeft:"8px"},children:i(o.description)})]},s))]})]}):null}function _m({items:e}){const n=Ie(),{convert:i}=Me();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:n.section.historyOverview}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map((o,s)=>t.jsxs("div",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[t.jsx("span",{style:{position:"absolute",left:0,top:0,color:r("desc-fg")},children:"·"}),i(o)]},s))})]}):null}function Bs({title:e,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:a}=Me(),[l,d]=h.useState([]);return h.useEffect(()=>{if(!n.length){d([]);return}if(!i){d(n.map(p=>({id:p})));return}let c=!1;return Promise.all(n.map(p=>i.getItem(p).then(m=>({id:p,title:m?m.title:void 0,edition:m?m.edition:void 0,type:m?m.type:void 0})).catch(()=>({id:p})))).then(p=>{c||d(p)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(bt,{children:[e,t.jsxs("span",{style:{fontSize:"12px",color:r("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 ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg"),transition:"border-color 0.15s"},children:t.jsx(wt,{id:c.id,label:p,onNavigate:o,renderLink:s})},c.id)})})]}):null}function sr({book:e,onNavigate:n,renderLink:i}){const o=Ie(),{convert:s}=Me(),[a,l]=h.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 ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden",background:r("input-bg")},children:[t.jsxs("div",{style:{padding:"6px 12px",borderBottom:d&&!a?`1px solid ${r("widget-border")}`:"none",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:t.jsx(wt,{id:e.id,label:c,onNavigate:n,renderLink:i})}),d&&t.jsx("span",{onClick:()=>l(p=>!p),style:{cursor:"pointer",fontSize:"10px",color:r("desc-fg"),userSelect:"none",transition:"transform 0.15s",transform:a?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:a?o.action.expand:o.action.collapse,children:"▼"})]}),d&&!a&&t.jsx("div",{style:{padding:"10px 14px"},children:t.jsx(Jr,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function $m({ids:e,workData:n,transport:i,onNavigate:o,renderLink:s,footer:a}){const l=Ie(),{convert:d}=Me(),[c,p]=h.useState([]);if(h.useEffect(()=>{if(!e.length){p([]);return}if(!i){p(e.map(v=>({id:v})));return}let x=!1;return Promise.all(e.map(v=>i.getItem(v).then(y=>({id:v,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:v})))).then(v=>{x||p(v)}),()=>{x=!0}},[e,i]),!e.length)return null;const m=c.length?c:e.map(x=>({id:x})),u=new Map(m.map(x=>[x.id,x])),g=n==null?void 0:n.version_graph,f=Cm(e,g,l.common.otherVersions);return t.jsxs(t.Fragment,{children:[t.jsxs(bt,{children:[l.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:r("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 v=u.get(x);return v?t.jsx(sr,{book:v,onNavigate:o,renderLink:s},x):null})}),f.groupedIds.map(x=>t.jsxs("details",{style:{marginTop:12,border:`1px solid ${r("widget-border")}`,borderRadius:6,background:r("bg-subtle")},children:[t.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:r("fg"),userSelect:"none"},children:[d(x.label),t.jsxs("span",{style:{marginLeft:6,fontSize:12,color:r("desc-fg"),fontWeight:400},children:["(",x.ids.length,")"]}),x.description&&t.jsx("span",{style:{marginLeft:8,fontSize:12,color:r("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(v=>{const y=u.get(v);return y?t.jsx(sr,{book:y,onNavigate:o,renderLink:s},v):null})})]},x.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:m.map(x=>t.jsx(sr,{book:x,onNavigate:o,renderLink:s},x.id))})]})}function Cm(e,n,i){var _,b;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(_=n.collections)==null?void 0:_[n.default_collection],s=(o==null?void 0:o.groups)??[],a=(o==null?void 0:o.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]),m=w=>{if(p.has(w))return!0;const j=n.node_groups[w];return j!=null&&c.has(j)},u=[],g=new Map,f=[];for(const w of e)if(!((b=n.excluded_books)!=null&&b.includes(w)))if(m(w))u.push(w);else{const j=n.node_groups[w];j?(g.has(j)||g.set(j,[]),g.get(j).push(w)):f.push(w)}if(f.length+[...g.values()].reduce((w,j)=>w+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const v=new Map((n.groups??[]).map(w=>[w.id,w])),y=[...g.entries()].map(([w,j])=>{const k=v.get(w);return{id:w,label:(k==null?void 0:k.label)??w,description:k==null?void 0:k.description,ids:j}});return f.length>0&&y.push({id:"__other__",label:i,description:void 0,ids:f}),{useGrouping:!0,coreIds:u,groupedIds:y}}function Tm({workData:e,onNavigate:n,renderLink:i}){var l,d,c,p;const o=Ie(),{convert:s}=Me(),a=!!((l=e.description)!=null&&l.text)||!!e.parent_work;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"8px",overflow:"hidden",background:r("input-bg"),marginTop:"4px"},children:[t.jsxs("div",{style:{padding:"6px 14px",borderBottom:a?`1px solid ${r("widget-border")}`:"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:`color-mix(in srgb, ${r("primary")} 4%, transparent)`},children:[t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:r("fg")},children:t.jsx(wt,{id:e.id,label:s(e.title),onNavigate:n,renderLink:i})}),e.measure_info?t.jsx("span",{style:{fontSize:"12px",color:r("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:r("desc-fg")},children:[Cl(e.juan_count.number),o.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(zl,{authors:e.authors,type:"work",onNavigate:n,renderLink:i})})]}),a&&t.jsxs("div",{style:{padding:"8px 14px"},children:[((c=e.description)==null?void 0:c.text)&&t.jsx(Pt,{text:e.description.text,style:{fontSize:"13px",color:r("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($t,{label:o.label.parentWork,children:t.jsx(wt,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function zm({items:e,onNavigate:n,renderLink:i}){const o=Ie(),{convert:s}=Me();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, ${r("type-collection")} 25%, transparent)`,borderRadius:"4px",background:`color-mix(in srgb, ${r("type-collection")} 3%, transparent)`},children:[t.jsx("span",{style:{fontSize:"11px",color:r("type-collection")},children:o.indexType.collection}),t.jsx(wt,{id:a.id,label:s(a.title)||a.id,onNavigate:n,renderLink:i}),a.volume_index!=null&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),marginLeft:"2px"},children:ft(o.catalog.volume,{n:a.volume_index})})]},a.id))}):null}const no=({data:e,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:a,relatedBooksFooter:l,className:d,style:c})=>{var P,R,N,A,H,G,ie,le;const p=Ie(),{convert:m}=Me(),[u,g]=h.useState(null),[f,x]=h.useState(!1),[v,y]=h.useState(null),[_,b]=h.useState(null),[w,j]=h.useState([]),k=e||u;if(h.useEffect(()=>{if(e||!n||!i)return;let V=!1;return x(!0),y(null),i.getItem(n).then(F=>{V||(F?g(F):y(p.misc.notFoundEntry))}).catch(F=>{V||y(F instanceof Error?F.message:p.misc.loadFailed)}).finally(()=>{V||x(!1)}),()=>{V=!0}},[e,n,i]),h.useEffect(()=>{if(!k||!i){b(null),j([]);return}let V=!1;const F=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(F?i.getItem(F).then(xe=>{!V&&xe&&xe.type==="work"&&b(xe)}).catch(()=>{}):b(null),k.type==="book"){const xe=k;xe.contained_in&&xe.contained_in.length>0?Promise.all(xe.contained_in.map(ee=>{const L=typeof ee=="string"?ee:ee.id,Re=typeof ee=="string"?void 0:ee.volume_index;return i.getItem(L).then(ce=>({id:L,title:ce&&ce.title||L,volume_index:Re})).catch(()=>({id:L,title:L,volume_index:Re}))})).then(ee=>{V||j(ee)}):j([])}else j([]);return()=>{V=!0}},[k,i]),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((V,F)=>t.jsx("div",{style:{height:F===1?"32px":"16px",width:`${V}px`,background:r("widget-border"),borderRadius:"4px",opacity:.4}},F))})});if(v)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:v});if(!k)return null;if(k.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(_l,{data:k,transport:i,onNavigate:o,renderLink:s,headerExtra:a})});const C=k.type==="book"?k:null,$=k.type==="collection"?k:null,S=k.type==="work"?k:null;let M=!1;try{M=_e.extractStatus(k.id)==="draft"}catch{}let z="";k.measure_info?z=m(k.measure_info):(P=k.juan_count)!=null&&P.number?z=Cl(k.juan_count.number)+p.unit.juan:(R=k.juan_count)!=null&&R.description&&(z=m(k.juan_count.description));const T=[];return(N=k.publication_info)!=null&&N.year&&T.push(t.jsx($t,{label:p.label.year,children:k.publication_info.year},"year")),(A=k.current_location)!=null&&A.name&&T.push(t.jsx($t,{label:p.label.currentLocation,children:m(k.current_location.name)},"loc")),(H=k.page_count)!=null&&H.description&&T.push(t.jsx($t,{label:p.label.pageCount,children:k.page_count.description},"page")),C!=null&&C.edition&&T.push(t.jsx($t,{label:p.label.edition,children:m(C.edition)},"ver")),S!=null&&S.parent_work&&T.push(t.jsx($t,{label:p.label.parentWork,children:t.jsx(wt,{id:S.parent_work.id,label:m(S.parent_work.title),onNavigate:o,renderLink:s})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&T.push(t.jsx($t,{label:p.label.parentWork,children:S.parent_works.map((V,F)=>t.jsxs("span",{children:[F>0&&"、",t.jsx(wt,{id:V,onNavigate:o,renderLink:s})]},V))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(ym,{id:k.id,title:m(k.title),edition:k.edition?m(k.edition):void 0,type:k.type,isDraft:M,authors:k.authors,volumeText:z,meta:T,headerExtra:a,onNavigate:o,renderLink:s}),((G=k.description)==null?void 0:G.text)&&t.jsx(Pt,{text:k.description.text,style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((V,F)=>t.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:r("bg-subtle"),borderRadius:4,border:`1px solid ${r("widget-border")}`},children:[t.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:r("muted")},children:m(V.title)}),t.jsx(Pt,{text:V.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:r("fg")}})]},F))}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:p.section.containedIn}),t.jsx(zm,{items:w,onNavigate:o,renderLink:s})]}),_&&t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:p.section.belongsToWork}),t.jsx(Tm,{workData:_,onNavigate:o,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&t.jsx(wm,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&t.jsx(vm,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&t.jsx(km,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&t.jsx(jm,{items:k.indexed_by,onNavigate:o,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&t.jsx(Il,{items:k.emendated_by,onNavigate:o,renderLink:s}),k.resources&&k.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(bt,{children:p.section.resources}),t.jsx(Jr,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&t.jsx(Sm,{items:C.location_history}),($==null?void 0:$.history)&&$.history.length>0&&t.jsx(_m,{items:$.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&t.jsx(Bs,{title:p.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:o,renderLink:s}),($==null?void 0:$.books)&&$.books.length>0&&t.jsx(Bs,{title:p.section.containedBooks,ids:$.books,transport:i,onNavigate:o,renderLink:s}),($==null?void 0:$.contained_works)&&$.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(bt,{children:[p.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",$.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:$.contained_works.map(V=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:t.jsx(wt,{id:V.id,label:m(V.title),onNavigate:o,renderLink:s})},V.id))})]}),(((ie=S==null?void 0:S.books)==null?void 0:ie.length)||0)+(((le=S==null?void 0:S.collections)==null?void 0:le.length)||0)>0&&t.jsx($m,{ids:[...(S==null?void 0:S.books)||[],...(S==null?void 0:S.collections)||[]],workData:S??void 0,transport:i,onNavigate:o,renderLink:s,footer:l}),(S==null?void 0:S.related_works)&&S.related_works.length>0&&(()=>{const V=[],F=S.related_works.filter(me=>me.relation==="part_of"),xe=S.related_works.filter(me=>me.relation==="has_part"),ee=S.related_works.filter(me=>me.relation==="has_adaptation"),L=S.related_works.filter(me=>me.relation==="text_carried_by"),Re=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ce=S.related_works.filter(me=>!me.relation||!Re.has(me.relation));return F.length>0&&V.push({label:p.section.belongsToWork,items:F}),xe.length>0&&V.push({label:p.section.containedWorks,items:xe}),ee.length>0&&V.push({label:p.section.adaptations,items:ee}),L.length>0&&V.push({label:p.section.derivativeWorks,items:L}),ce.length>0&&V.push({label:p.section.relatedWorks,items:ce}),V.map(me=>t.jsxs("div",{children:[t.jsxs(bt,{children:[me.label,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",me.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:me.items.map(se=>t.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg")},children:t.jsx(wt,{id:se.id,label:m(se.title),onNavigate:o,renderLink:s})},se.id))})]},me.label))})()]})};function Nm({data:e}){const n=Ie(),{convert:i}=Me(),{stats:o}=e,s=o.processed_volumes??o.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:r("fg"),margin:"0 0 8px"},children:i(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:r("desc-fg"),marginBottom:"6px"},children:i(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:r("desc-fg")},children:[t.jsxs("span",{children:[n.catalog.totalVolumes," ",t.jsx("strong",{style:{color:r("fg")},children:e.total_volumes})," ",n.unit.volume]}),a!=null&&t.jsxs("span",{children:[n.catalog.processed," ",t.jsx("strong",{style:{color:r("fg")},children:s})," ",n.unit.volume," (",a,"%)"]}),t.jsxs("span",{children:[n.catalog.contains," ",t.jsx("strong",{style:{color:r("fg")},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&t.jsxs("span",{children:[n.catalog.matched," ",t.jsx("strong",{style:{color:r("fg")},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&t.jsxs("span",{children:[n.catalog.unmatched," ",t.jsx("strong",{style:{color:r("missing-fg")},children:o.unmatched_works})," ",n.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:r("desc-fg")},children:[n.catalog.source," ",e.source]})]})}function Im({sections:e,activeSection:n,onSelect:i}){const o=Ie();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:Ws(n===null),children:o.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:Ws(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 Ws(e){return{padding:"4px 12px",border:e?`1px solid ${r("primary")}`:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${r("primary")} 8%, transparent)`:"transparent",color:r(e?"primary":"fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Rm({id:e,label:n,onNavigate:i,renderLink:o}){const s=tt();return o?t.jsx(t.Fragment,{children:o(e,n)}):i?t.jsx("a",{href:s(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i(e))},style:{color:r("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${r("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:r("desc-fg")},children:n||e})}function Em(e,n){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=e[0],o=e[e.length-1];return o-i+1===e.length?`${i}–${o}`:e.length<=3?e.join(", "):`${i}–${o} (${e.length}${n})`}function Os({book:e,onNavigate:n,renderLink:i,showVolumes:o}){const s=Ie(),{convert:a}=Me(),l=e.book_id||e.work_id,d=o&&e.volumes.length>0?Em(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 ${r("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[o&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:r("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:r("fg")},children:[a(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(p=>a(p)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:r(c?"missing-fg":"desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,s.unit.volume]}),l&&t.jsx(Rm,{id:l,label:e.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!l&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),flexShrink:0},children:s.catalog.unmatched_label})]})}const io=({data:e,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:a,style:l})=>{const d=Ie(),[c,p]=h.useState(null),[m,u]=h.useState(!1),[g,f]=h.useState(null),[x,v]=h.useState(null),[y,_]=h.useState(""),b=e||c;h.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let $=!1;return u(!0),f(null),i.getCollectionCatalog(n).then(S=>{$||(S?p(S):f(d.catalog.notFound))}).catch(S=>{$||f(S instanceof Error?S.message:d.catalog.loadFailed)}).finally(()=>{$||u(!1)}),()=>{$=!0}},[e,n,i,d]);const w=(b==null?void 0:b.sections)&&b.sections.length>0,j=h.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]),k=h.useMemo(()=>{if(!b)return[];let $=b.books;if(x&&($=$.filter(S=>S.section===x)),y.trim()){const S=y.trim().toLowerCase();$=$.filter(M=>M.title.toLowerCase().includes(S)||M.sub_items&&M.sub_items.some(z=>z.toLowerCase().includes(S))||M.edition&&M.edition.toLowerCase().includes(S))}return $},[b,x,y]),C=h.useMemo(()=>{if(!j)return null;const $=[],S=new Map;for(const z of k){if(!z.volumes||z.volumes.length===0)continue;const T=z.volumes[0];S.has(T)||S.set(T,[]),S.get(T).push(z)}const M=[...S.keys()].sort((z,T)=>z-T);for(const z of M)$.push({volume:z,books:S.get(z)});return $},[k,j]);return m?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:r("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):g?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:g}):b?t.jsxs("div",{className:a,style:l,children:[t.jsx(Nm,{data:b}),w&&t.jsx(Im,{sections:b.sections,activeSection:x,onSelect:v}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:y,onChange:$=>_($.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${r("input-border")}`,borderRadius:"4px",background:r("input-bg"),color:r("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:r("desc-fg")},children:[k.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[C?C.map(($,S)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:r("bg"),borderBottom:`1px solid ${r("widget-border")}`,fontSize:"12px",fontWeight:600,color:r("desc-fg"),position:"sticky",top:0,zIndex:1},children:ft(d.catalog.volume,{n:$.volume})}),$.books.map((M,z)=>t.jsx(Os,{book:M,onNavigate:o,renderLink:s,showVolumes:M.volumes.length>1},`${$.volume}-${z}`))]},`${$.volume}-${S}`)):k.map(($,S)=>t.jsx(Os,{book:$,onNavigate:o,renderLink:s,showVolumes:!0},S)),k.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},ar=e=>e?e.catch(()=>null):Promise.resolve(null);function El(e){const n=new Map;function i(o){var a;let s=n.get(o);return s||(s=ar((a=e.getTextManifest)==null?void 0:a.call(e,o)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||n.delete(o),d}),n.set(o,s)),s}return{getManifest(o){return _e.isSafeSegment(o)?i(o):Promise.resolve(null)},async getIndex(o,s){return!_e.isSafeSegment(o)||!_e.isSafeSegment(s)||!e.getTextIndex?null:ar(e.getTextIndex(o,s))},async getChapter(o,s,a,l){return!_e.isSafeSegment(o)||!_e.isSafeSegment(s)||!_e.isSafeSegment(a)||!e.getChapter?null:ar(e.getChapter(o,s,a,l))}}}const nn=()=>{const{t:e}=te(),[n,i]=h.useState(1);return h.useEffect(()=>{const o=setInterval(()=>i(s=>s>=3?1:s+1),500);return()=>clearInterval(o)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:r("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(n)})},lr=String.raw`https?:\/\/[^\s()()<>"]+`,Lm=new RegExp(String.raw`\[([^\]\n]+)\]\((${lr})\)`+String.raw`|(《[^》\n]+》)\s?[((](${lr})[))]`+`|(${lr})`,"g");function Am(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Mm(e){const n=[];let i=0;for(const o of e.matchAll(Lm)){const s=o.index??0;s>i&&n.push({text:e.slice(i,s)}),o[1]!==void 0?n.push({text:o[1],url:o[2]}):o[3]!==void 0?n.push({text:o[3],url:o[4]}):n.push({text:Am(o[5]),url:o[5]}),i=s+o[0].length}return i<e.length&&n.push({text:e.slice(i)}),n}function Ll({text:e,convert:n,className:i="bim-rd-link"}){return t.jsx(t.Fragment,{children:Mm(e).map((o,s)=>o.url?t.jsx("a",{className:i,href:o.url,target:"_blank",rel:"noopener noreferrer",children:n(o.text)},s):t.jsx(h.Fragment,{children:n(o.text)},s))})}const Al="(min-width: 1100px)",Ml="(max-width: 719px)",Pl="(max-width: 859px)",Pm=`${Ml}, (pointer: coarse)`,_t=r("reader-top"),Bm="48px",Bl=`
146
146
  .bim-rd {
147
147
  position: relative;
148
148
  background: ${r("page-bg")};
@@ -659,7 +659,6 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
659
659
  .guji-text-char.is-guess { color: ${r("meta-fg")}; text-decoration: underline dotted; text-underline-offset: 0.2em; } /* 残字:灰字加点线 */
660
660
  .guji-text-char.is-zi { border: 1px solid color-mix(in srgb, currentColor 40%, transparent); border-radius: 2px; padding: 0 0.12em; margin: 0 0.05em; } /* 组字:细框,同 .bim-zi */
661
661
  .guji-text-char.is-raised { display: inline-block; transform: translateY(-0.2em); } /* 抬头:本列首字高出一格 */
662
- .guji-text-lead-blank { display: inline-block; height: 1px; } /* 行首空格:n 个字宽的空位(宽度在 style) */
663
662
  .guji-text-blank-col { display: inline-block; width: 1em; height: 1px; } /* 空列:一格宽的空位 */
664
663
  .bim-rd-badge-warp {
665
664
  display: inline-flex;
@@ -674,8 +673,8 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
674
673
  letter-spacing: 0.05em;
675
674
  margin-left: 6px;
676
675
  }
677
- `;function ro(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(o=>ro(o,n))):!1}const Wm=()=>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 Om({item:e,activeKey:n,onSelect:i,tabKey:o}){const s=ro(e,n),[a,l]=h.useState(s||!!e.defaultExpanded);return h.useEffect(()=>{s&&l(!0)},[s]),h.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:o===e.key?0:-1,onClick:()=>l(d=>!d),children:[t.jsx(Wm,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),a&&t.jsx(Wl,{items:e.children,activeKey:n,onSelect:i,tabKey:o})]})}function Wl({items:e,activeKey:n,onSelect:i,tabKey:o}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Om,{item:s,activeKey:n,onSelect:i,tabKey:o},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:o===s.key?0:-1,onClick:()=>i(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Fs(e,n){var i;for(const o of e)if(o.key===n||ro(o,n))return o.key;return((i=e[0])==null?void 0:i.key)??null}function Ol({items:e,activeKey:n,onSelect:i,label:o}){const{t:s}=te(),a=o??s("reader.toc"),l=h.useRef(null),[d,c]=h.useState(null);h.useEffect(()=>{c(null)},[n]);const p=h.useMemo(()=>d||(n??Fs(e,n)),[d,n,e]);h.useEffect(()=>{const u=l.current;if(!u)return;const g=Array.from(u.querySelectorAll("[data-rd-toc-key]"));if(g.length===0)return;const f=g.find(x=>x.dataset.rdTocKey===p)??g.find(x=>x.dataset.rdTocKey===Fs(e,n))??g.find(x=>!x.disabled)??g[0];for(const x of g)x.tabIndex=x===f?0:-1}),h.useEffect(()=>{const u=l.current,g=u==null?void 0:u.closest(".bim-rd-toc");if(!u||!g||!n)return;const f=Array.from(u.querySelectorAll("[data-rd-toc-key]")).find(v=>v.dataset.rdTocKey===n);if(!f)return;const x=f.getBoundingClientRect().top-g.getBoundingClientRect().top+g.scrollTop;(x<g.scrollTop+80||x>g.scrollTop+g.clientHeight-40)&&(g.scrollTop=Math.max(0,x-g.clientHeight/3))},[n]);const m=h.useCallback(u=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(u.key))return;const f=l.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(b=>!b.disabled),v=x.indexOf(document.activeElement);let y=v;if(u.key==="ArrowDown"?y=Math.min(x.length-1,v+1):u.key==="ArrowUp"?y=Math.max(0,v-1):u.key==="Home"?y=0:u.key==="End"&&(y=x.length-1),y<0||y===v)return;u.preventDefault();const _=x[y];for(const b of x)b.tabIndex=-1;_.tabIndex=0,_.focus(),c(_.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:m,children:t.jsx(Wl,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Hs({page:e,crop:n}){var i;return!((i=e.boxes)!=null&&i.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:n?`${n.x} ${n.y} ${n.w} ${n.h}`:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((o,s)=>t.jsx("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:"none",stroke:r("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},s))})}function Fm(e){const{boxes:n,width:i,height:o}=e;if(!(n!=null&&n.length)||!i||!o||e.boxFormat&&e.boxFormat!=="bim-charbox-v0")return null;let s=1/0,a=1/0,l=-1/0,d=-1/0;for(const f of n)[f.x,f.y,f.w,f.h].every(Number.isFinite)&&(s=Math.min(s,f.x),a=Math.min(a,f.y),l=Math.max(l,f.x+f.w),d=Math.max(d,f.y+f.h));if(!(l>s)||!(d>a))return null;const c=Math.min(i,o)*.03,p=Math.min(i,Math.max(0,s-c)),m=Math.min(o,Math.max(0,a-c)),u=Math.min(i,Math.max(0,l+c))-p,g=Math.min(o,Math.max(0,d+c))-m;return!(u>0)||!(g>0)||u>=i*.98&&g>=o*.98?null:{x:p,y:m,w:u,h:g}}function Sr({pages:e,loading:n,page:i,onPageChange:o,renderOverlay:s,preserveMargins:a=!0}){const{t:l}=te(),[d,c]=h.useState(0),p=i??d,m=v=>{o?o(v):c(v)};if(h.useEffect(()=>{i===void 0&&c(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:l("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:l("reader.noImages")}),t.jsx("span",{children:l("reader.noImagesHint")})]})});const u=Math.max(0,Math.min(e.length-1,p)),g=e[u],f=g.label??`${u+1}`,x=!a&&!s?Fm(g):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:x?t.jsxs("figure",{className:"bim-rd-img-fig bim-rd-img-trimmed","data-trim":`${Math.round(x.x)},${Math.round(x.y)},${Math.round(x.w)},${Math.round(x.h)}`,style:{aspectRatio:`${x.w} / ${x.h}`,overflow:"hidden",width:"100%",maxWidth:`calc((100vh - 200px) * ${x.w/x.h})`},children:[t.jsx("img",{src:g.url,alt:g.alt??l("reader.imageAlt",{label:f}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${g.width/x.w*100}%`,left:`${-x.x/x.w*100}%`,top:`${-x.y/x.h*100}%`}}),t.jsx(Hs,{page:g,crop:x})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:g.url,alt:g.alt??l("reader.imageAlt",{label:f}),width:g.width,height:g.height,loading:"lazy",decoding:"async"}),t.jsx(Hs,{page:g}),s==null?void 0:s(g,u)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.prevImage"),disabled:u===0,onClick:()=>m(u-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:g.label??`${u+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:u===e.length-1,onClick:()=>m(u+1),children:"›"})]})]})}function Hm(e){return e==="lite"||e==="full"}const Pn=[.1,.9],Fl=[{key:"song",stack:null},{key:"kai",stack:'"Kaiti SC", "Kaiti TC", STKaiti, "KaiTi", "AR PL UKai CN", "Noto Serif CJK SC", serif'},{key:"system",stack:"var(--bim-font-ui)"}];function Dm(e){var n;return((n=Fl.find(i=>i.key===e))==null?void 0:n.stack)??null}const oo={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!0,pageIndicatorY:.33,bookTitleStyle:"wavy",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!0},Lt=[15,16,17,18,20,22,24],_r=18,Hl="bim-reader-prefs",Um="bim-reading-mode";function Vm(){const e={...oo};try{const n=localStorage.getItem(Hl),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&Lt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Um))==="paragraph"&&(e.readingMode="paragraph"),i.properNameMode==="off"||i.properNameMode==="lite"||i.properNameMode==="full"?e.properNameMode=i.properNameMode:i.properNames===!0?e.properNameMode="full":i.properNames===!1&&(e.properNameMode="off"),i.writingMode==="vertical"&&(e.writingMode="vertical"),i.workLinks===!1&&(e.workLinks=!1),(i.fontFamily==="kai"||i.fontFamily==="system")&&(e.fontFamily=i.fontFamily),i.pageBreaks===!1&&(e.pageBreaks=!1),typeof i.pageIndicatorY=="number"&&Number.isFinite(i.pageIndicatorY)&&i.pageIndicatorY>=Pn[0]&&i.pageIndicatorY<=Pn[1]&&(e.pageIndicatorY=i.pageIndicatorY),i.bookTitleStyle==="bracket"&&(e.bookTitleStyle="bracket"),i.showWorks===!1&&(e.showWorks=!1),(i.quoteStyle==="modern"||i.quoteStyle==="classic")&&(e.quoteStyle=i.quoteStyle),(i.scriptMode==="orig"||i.scriptMode==="hant"||i.scriptMode==="hans")&&(e.scriptMode=i.scriptMode),i.preserveMargins===!1&&(e.preserveMargins=!1)}catch{}return e}function Gm(e){try{localStorage.setItem(Hl,JSON.stringify(e))}catch{}}function oi(e,n){const i=e??_r,o=Lt;let s=o.indexOf(i);return s<0&&(s=o.indexOf(_r)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Dl(){const[e,n]=h.useState(oo);h.useEffect(()=>{n(Vm())},[]);const i=h.useCallback(o=>{n(s=>{const a={...s,...o};return Gm(a),a})},[]);return[e,i]}function $r(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 Ul(e,n){if(!(!e||e.length===0))return(n!=null?e.find(i=>i.key===n):void 0)??e.find(i=>i.primary)??e[0]}function Vl(e){const n=[],i=o=>{for(const s of o)s.children&&s.children.length>0?i(s.children):n.push(s)};return i(e),n}const Ds=()=>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"})}),qm=()=>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"})}),Us=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M4 7h10M18 7h2M4 17h2M10 17h10"}),t.jsx("circle",{cx:"16",cy:"7",r:"2"}),t.jsx("circle",{cx:"8",cy:"17",r:"2"})]}),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 Gs(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(i.length===0)return;const o=i[0],s=i[i.length-1],a=document.activeElement;e.shiftKey&&(a===o||!n.contains(a))?(e.preventDefault(),s.focus()):!e.shiftKey&&(a===s||!n.contains(a))&&(e.preventDefault(),o.focus())}function Ys(e,n){const[i,o]=h.useState(n);return h.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);o(s.matches);const a=()=>o(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]),i}function Km({onSwitch:e}){const n=h.useContext(Tt),{t:i}=te();if(!n)return null;const o=n.locale==="zh-Hant";return t.jsxs("button",{type:"button",className:"bim-rd-t",title:i(o?"common.toHans":"common.toHant"),"aria-label":i(o?"common.toHans":"common.toHant"),onClick:()=>{const s=o?"zh-Hans":"zh-Hant";n.setLocale(s),e==null||e(s)},children:[t.jsx("span",{className:o?"bim-rd-on":"bim-rd-off",children:i("common.localeShortHant")}),t.jsx("span",{className:"bim-rd-off",children:"|"}),t.jsx("span",{className:o?"bim-rd-off":"bim-rd-on",children:i("common.localeShortHans")})]})}function pi({label:e,value:n,options:i,onPick:o,title:s}){return t.jsxs("div",{className:"bim-rd-sp-row",role:"group","aria-label":e,title:s,children:[t.jsx("span",{className:"bim-rd-sp-l",children:e}),t.jsx("span",{className:"bim-rd-sp-fs",children:i.map(a=>t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":n===a.key,title:a.title,onClick:()=>o(a.key),children:a.label},a.key))})]})}function Xm({prefs:e,onPrefsChange:n}){const i=h.useContext(Tt),{t:o}=te(),s=(i==null?void 0:i.locale)==="zh-Hans"?"hans":"hant",a=e.scriptMode==="orig"?"orig":s;return t.jsx(pi,{label:o("reader.script"),value:a,options:[{key:"orig",label:o("reader.scriptOrig")},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:l=>{n({scriptMode:l}),l==="hant"?i==null||i.setLocale("zh-Hant"):l==="hans"&&(i==null||i.setLocale("zh-Hans"))}})}function Zm(e,n){if(!e)return;let i;for(const o of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(o.getBoundingClientRect().top<=n+8)i=o.id;else break;return i}function Jm(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 i=e.querySelector(".bim-rd-col"),o=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(i!=null&&i.contains(l))&&!(d!=null&&d.closest(".bim-rd-src, .bim-rd-pager"))};if(!o(n.anchorNode)||!o(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function Gl({title:e,subtitle:n,toc:i,activeKey:o,onSelect:s,tocHeader:a,tocCaption:l,images:d,imagesLoading:c,renderImageOverlay:p,imagePanel:m="auto",prefs:u,onPrefsChange:g,paragraphToggle:f,properNameToggle:x=!0,allowVertical:v,byline:y,current:_,workLinkToggle:b,rail:w,onReportError:j,revisedAt:k,backHref:C,backLabel:$,bottomBar:S=!0,pager:M=!0,pagerUnit:z,versions:T,currentVersionKey:P,onVersionChange:R,versionSource:N=!0,keepChapterOnVersionChange:A=!1,customImagePanel:H,toolbarExtra:G,settingsAnnotate:ie,settingsLayout:le,isWarpMode:V,children:F,className:xe,style:ee}){const{t:L,convert:Re}=te(),ce=$??L("reader.back"),me=Re(z??L("reader.unitJuan")),se=h.useId().replace(/:/g,""),Pe=`bim-rd-toc-${se}`,X=`bim-rd-text-${se}`,re=h.useRef(null),de=h.useRef(null),D=h.useRef(null),K=h.useRef(null),we=Ys(Al,!0),ne=Ys(Pl,!1),B=S&&ne,[Z,ae]=h.useState(null),[je,Y]=h.useState(!1),be=h.useRef(null),Ee=`bim-rd-set-${se}`,Fe=h.useRef(null),W=h.useRef(null),J=(q,Ve)=>{W.current=Ve,ae(Oe=>Oe===q?null:q)},$e=h.useCallback(()=>{var q;ae(null),(q=W.current)==null||q.focus()},[]);h.useEffect(()=>{B||ae(null)},[B]),h.useEffect(()=>{var q,Ve;Z&&((Ve=(q=Fe.current)==null?void 0:q.querySelector("button:not([disabled])"))==null||Ve.focus())},[Z]);const[Te,O]=h.useState("auto"),fe=Te==="auto"?we:Te==="open",oe=!we,Se=!!H||!!d&&d.length>0,[Le,He]=h.useState(m);h.useEffect(()=>{He(m)},[m]);const Ye=Le==="auto"?Se||!!c:Le==="open",qe=h.useCallback(q=>{var Ve;O("auto"),q&&((Ve=K.current)==null||Ve.focus())},[]),Xe=()=>O(fe?"closed":"open");h.useEffect(()=>{if(!oe||Te!=="open")return;const q=D.current,Ve=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');Ve==null||Ve.focus()},[oe,Te]);const I=h.useCallback(q=>{s(q),oe&&qe(!1);const Ve=de.current,Oe=re.current;if(Ve&&Oe&&typeof window<"u"){const rt=Ve.getBoundingClientRect().top-Oe.getBoundingClientRect().bottom;rt<0&&window.scrollBy({top:rt})}},[s,oe,qe]),U=h.useMemo(()=>Vl(i),[i]),[ue,Ce]=h.useState(null),ye=Ul(T,P!==void 0?P:ue),ge=(ye==null?void 0:ye.key)??null,Ge=h.useMemo(()=>U.map(q=>q.key).join(`
678
- `),[U]),Q=h.useRef(null),ke=q=>{q!==ge&&(A||(Q.current={key:q,sig:Ge,done:!1}),P===void 0&&Ce(q),R==null||R(q))};h.useEffect(()=>{const q=Q.current;if(!q||q.key!==ge)return;const Ve=U.find(rt=>!rt.disabled);if(!Ve)return;const Oe=Ge!==q.sig;!Oe&&q.done||(Oe?Q.current=null:q.done=!0,Ve.key!==o&&I(Ve.key))},[ge,Ge,U,o,I]);const Ae=U.find(q=>q.key===o),Be=()=>{var q;j==null||j({chapterKey:o,chapterLabel:typeof(Ae==null?void 0:Ae.label)=="string"?Ae.label:void 0,anchor:Zm(de.current,((q=re.current)==null?void 0:q.getBoundingClientRect().bottom)??0),selectedText:Jm(de.current)})},Ne=U.findIndex(q=>q.key===o),he=Ne>0?U.slice(0,Ne).reverse().find(q=>!q.disabled):void 0,ve=Ne>=0?U.slice(Ne+1).find(q=>!q.disabled):void 0,Ue=u.fontSize??_r,We=Dm(u.fontFamily),st={...ee,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...We?{"--bimrd-ff":We}:null},jt={song:L("reader.fontSong"),kai:L("reader.fontKai"),system:L("reader.fontSystem")},on=x||!!ie,Gt=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ee}-g1`,children:[t.jsx("h3",{id:`${Ee}-g1`,className:"bim-rd-sp-h",children:L("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":L("reader.font"),value:u.fontFamily,onChange:q=>g({fontFamily:q.target.value}),children:Fl.map(q=>t.jsx("option",{value:q.key,children:jt[q.key]},q.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontSmaller"),disabled:Ue<=Lt[0],onClick:()=>g({fontSize:oi(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[Ue,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontLarger"),disabled:Ue>=Lt[Lt.length-1],onClick:()=>g({fontSize:oi(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Xm,{prefs:u,onPrefsChange:g}),t.jsx(pi,{label:L("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:L("reader.quoteModern")},{key:"classic",label:L("reader.quoteClassic")},{key:"original",label:L("reader.quoteOriginal")}],onPick:q=>g({quoteStyle:q})})]}),on&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ee}-g2`,children:[t.jsx("h3",{id:`${Ee}-g2`,className:"bim-rd-sp-h",children:L("reader.groupMark")}),x&&t.jsxs(t.Fragment,{children:[t.jsx(pi,{label:L("reader.properName"),value:u.properNameMode,title:L("reader.properNameTitle"),options:[{key:"off",label:L("reader.properNameOff")},{key:"lite",label:L("reader.properNameLite"),title:L("reader.properNameLiteTitle")},{key:"full",label:L("reader.properNameFull")}],onPick:q=>g({properNameMode:q})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:q=>g({showWorks:q.target.checked})}),t.jsx("span",{children:L("reader.showWorks")})]}),t.jsx(pi,{label:L("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:L("reader.bookTitleWavy")},{key:"bracket",label:L("reader.bookTitleBracket")}],onPick:q=>g({bookTitleStyle:q})})]}),ie]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ee}-g3`,children:[t.jsx("h3",{id:`${Ee}-g3`,className:"bim-rd-sp-h",children:L("reader.groupLayout")}),f&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:L("reader.paragraphTitle"),onClick:()=>g({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:L("reader.paragraph")}),b&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.workLinks,onChange:q=>g({workLinks:q.target.checked})}),t.jsx("span",{children:L("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>g({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:L("reader.vertical")}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.pageBreaks,onChange:q=>g({pageBreaks:q.target.checked})}),t.jsx("span",{children:L("reader.pageBreaks")})]}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:q=>g({preserveMargins:q.target.checked})}),t.jsx("span",{children:L("reader.preserveMargins")})]}),le]})]});return t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",xe].filter(Boolean).join(" "),"data-toc":Te,"data-img":Ye?"open":"closed","data-bb":B?"":void 0,"data-set":!B&&je?"open":void 0,"data-warp":V?"true":void 0,style:st,children:[t.jsx("style",{children:Bl}),t.jsx("a",{className:"bim-rd-skip",href:`#${X}`,onClick:q=>{var Ve,Oe,rt;q.preventDefault(),(Ve=de.current)==null||Ve.focus(),(rt=(Oe=de.current)==null?void 0:Oe.scrollIntoView)==null||rt.call(Oe,{block:"start"})},children:L("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:re,children:[C&&t.jsxs("a",{className:"bim-rd-back",href:C,"aria-label":L("reader.backAria",{label:ce}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:ce})]}),(e||n||y||_)&&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}),_&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:_})]}),n&&t.jsx("span",{className:"bim-rd-ttl-src",children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":L("reader.settings"),children:[T&&T.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ye?Re($r(ye)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:L("reader.versionShort")}),t.jsx("select",{"aria-label":L("reader.version"),value:ge??"",onChange:q=>ke(q.target.value),children:T.map(q=>t.jsx("option",{value:q.key,children:Re($r(q))},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),M&&(he||ve)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":L("reader.pagerGroup",{unit:me}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.prevUnit",{unit:me}),title:he?typeof he.label=="string"&&he.label?L("reader.prevUnitTitle",{unit:me,label:he.label}):L("reader.prevUnit",{unit:me}):L("reader.firstUnit",{unit:me}),disabled:!he,onClick:()=>he&&I(he.key),children:t.jsx(Ym,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.nextUnit",{unit:me}),title:ve?typeof ve.label=="string"&&ve.label?L("reader.nextUnitTitle",{unit:me,label:ve.label}):L("reader.nextUnit",{unit:me}):L("reader.lastUnit",{unit:me}),disabled:!ve,onClick:()=>ve&&I(ve.key),children:t.jsx(qm,{})})]}),M&&(he||ve)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:K,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":fe,"aria-controls":Pe,onClick:Xe,children:[t.jsx(Ds,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":Ye,onClick:()=>He(Ye?"closed":"open"),children:[t.jsx(Vs,{}),L("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Km,{onSwitch:q=>g({scriptMode:q==="zh-Hans"?"hans":"hant"})}),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":L("reader.fontSmaller"),disabled:Ue<=Lt[0],onClick:()=>g({fontSize:oi(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":L("reader.fontLarger"),disabled:Ue>=Lt[Lt.length-1],onClick:()=>g({fontSize:oi(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:be,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":je,"aria-controls":Ee,onClick:()=>Y(q=>!q),children:[t.jsx(Us,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.settings")})]}),G]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:Pe,ref:D,role:oe&&fe?"dialog":void 0,"aria-modal":oe&&fe?!0:void 0,"aria-label":oe&&fe?L("reader.toc"):void 0,onKeyDown:q=>{if(!(!oe||!fe)){if(q.key==="Escape"){q.stopPropagation(),qe(!0);return}q.key==="Tab"&&Gs(q,D.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??L("reader.toc")}),oe&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeToc"),onClick:()=>qe(!0),children:"✕"})]}),a]}),t.jsx(Ol,{items:i,activeKey:o,onSelect:I})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>qe(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":L("reader.images"),children:Ye&&(H||t.jsx(Sr,{pages:d??null,loading:c,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!B&&je&&t.jsxs("aside",{className:"bim-rd-set",id:Ee,"aria-label":L("reader.settings"),onKeyDown:q=>{var Ve;q.key==="Escape"&&(q.stopPropagation(),Y(!1),(Ve=be.current)==null||Ve.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:L("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeSettings"),onClick:()=>{var q;Y(!1),(q=be.current)==null||q.focus()},children:"✕"})]}),Gt]}),t.jsxs("div",{className:"bim-rd-text",id:X,ref:de,tabIndex:-1,"data-rail":(w||j)&&!V?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[F,N&&ye&&(ye.sourceName||ye.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ye.key,children:[ye.sourceName&&t.jsxs(t.Fragment,{children:[L("reader.sourceLabel")," ",ye.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ye.sourceUrl,target:"_blank",rel:"noreferrer",children:Re(ye.sourceName)}):Re(ye.sourceName)]}),ye.sourceName&&ye.license&&t.jsx("span",{className:"bim-rd-dot"}),ye.license&&t.jsx(t.Fragment,{children:L("reader.licenseOf",{license:ye.license})})]}),k&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:L("reader.revisedAt",{date:k})}),j&&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:Be,children:L("reader.reportError")})}),M&&(he||ve)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":L("reader.pagerNav"),children:[he?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>I(he.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),L("reader.prevUnit",{unit:me})]}),t.jsx("span",{className:"bim-rd-pglabel",children:he.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",L("reader.firstUnit",{unit:me})]}),ve?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>I(ve.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[L("reader.nextUnit",{unit:me}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:ve.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[L("reader.lastUnit",{unit:me})," →"]})]})]}),(w||j)&&!V&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":L("reader.rail"),children:[w,j&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:q=>q.preventDefault(),onClick:Be,children:L("reader.reportError")})})]})]})]}),B&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":L("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":fe,"aria-controls":Pe,onClick:()=>{ae(null),Xe()},children:[t.jsx(Ds,{}),t.jsx("span",{children:L("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":Z==="img","aria-haspopup":"dialog",onClick:q=>J("img",q.currentTarget),children:[t.jsx(Vs,{}),t.jsx("span",{children:L("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":Z==="set","aria-haspopup":"dialog",onClick:q=>J("set",q.currentTarget),children:[t.jsx(Us,{}),t.jsx("span",{children:L("reader.settingsShort")})]}),j&&t.jsxs("button",{type:"button",onMouseDown:q=>q.preventDefault(),onClick:()=>{ae(null),Be()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:L("reader.reportError")})]})]}),B&&Z&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:$e}),t.jsxs("div",{className:"bim-rd-sheet",ref:Fe,role:"dialog","aria-modal":"true","aria-label":L(Z==="img"?"reader.images":"reader.settings"),onKeyDown:q=>{if(q.key==="Escape"){q.stopPropagation(),$e();return}q.key==="Tab"&&Gs(q,Fe.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:L(Z==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.close"),onClick:$e,children:"✕"})]}),Z==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Sr,{pages:d??null,loading:c,renderOverlay:p,preserveMargins:u.preserveMargins})}):Gt]})]})]})}const Yl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Qm={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function nt(e){return Qm[e]??e}const mn=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],gn={熹平: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},ql={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Ni(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const o=n[2]?parseInt(n[2],10):void 0;return{from:i,to:o!=null&&o>=i&&o<=2100?o:void 0}}function eg(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 tg=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,qs={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function so(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(qs))if(n.startsWith(s))return qs[s];const i=nt(n);if(Zt[i]!=null)return i;const o=Mt(n);if(o&&n.length<=o.length+1)return nt(o)}function Xt(e,n){if(n){const i=ql[`${n}|${e}`];if(i!=null)return i}return gn[e]}const ng=1911;function ig(e){const n=gn[e];if(n==null)return;const i=Ct[e];let o;for(const[s,a]of Object.entries(gn))Ct[s]===i&&a>n&&(o==null||a<o)&&(o=a);return o!=null?o-1:void 0}const rg={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function xi(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,o=!1;for(const a of e){const l=rg[a];if(l===void 0)return;o=!0,a==="十"?i=(i||1)*10:a==="廿"||a==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return o&&s>0?s:void 0}function Mt(e){for(const n of Yl)if(e.startsWith(n))return n}const Ct={};{const e=(n,i)=>{for(const o of i)Ct[o]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Jt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(gn))if(e.includes(o)&&!(i&&Ct[o]&&Ct[o]!==i&&ql[`${i}|${o}`]==null))return o}function Wn(e){var l,d,c;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const o=(l=e.lineage)==null?void 0:l.year_text;if(o){const p=Mt(o)??"";return{era:nt(p),reign:Jt(o,p)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const p=Ni(s);if(p)return{era:eg(p.from),reign:"",source:"publication"};const m=Mt(s)??so(s)??((c=mn.find(f=>f.pattern.test(s)))==null?void 0:c.era)??"",u=Jt(s,m)??"",g=m||(u?Ct[u]??"":"");if(g||u)return{era:nt(g),reign:u,source:"publication"}}const a=e.edition||e.title||"";if(a){const p=Mt(a);if(p)return{era:nt(p),reign:Jt(a,p)??"",source:"edition"};const m=mn.find(u=>u.pattern.test(a));if(m)return{era:nt(m.era),reign:Jt(a,m.era)??m.reign??"",source:"edition"}}return n}function Ii(e){var o,s,a,l,d,c,p,m,u;if(((o=e.dating)==null?void 0:o.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 g=Ni(n);if(g)return g.from}const i=[(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 g of i){const f=((c=e.publication_info)==null?void 0:c.year)||((p=e.lineage)==null?void 0:p.year_text);if(f&&g!==f&&(Mt(f)||so(f)))break;const x=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(x){const w=parseInt(x[1],10);if(w>=100&&w<=2100)return w}const v=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(v){const w=Mt(g);if(!w||nt(w)==="民國"){const k=xi(v[1]);if(k!=null&&k>=1&&k<=120)return ng+k}}const y=Mt(g)??((m=mn.find(w=>w.pattern.test(g)))==null?void 0:m.era),_=y?nt(y):void 0,b=Jt(g,_)??(Mt(g)||(u=mn.find(w=>w.pattern.test(g)))==null?void 0:u.reign);if(b){const w=Xt(b,_);if(w==null)continue;const j=g.indexOf(b),k=j>=0?g.slice(j+b.length):"",C=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),$=C?xi(C[1]):void 0;return w+($?$-1:0)}}}function ao(e){var l,d,c,p,m,u;const n=(l=e.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(d=e.lineage)==null?void 0:d.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const o=(c=e.lineage)==null?void 0:c.year_text;if(o){const g=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const f=Cr[nt(g[1])],x=Zt[nt(g[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 g=Ni(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const f=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const x=Cr[nt(f[1])],v=Zt[nt(f[2])];if(x!=null&&v!=null)return{from:Math.min(x,v)-20,to:Math.max(x,v)+40}}}const a=[(m=e.publication_info)==null?void 0:m.year,e.edition,e.title].filter(Boolean);for(const g of a){if(!/[間间]/.test(g))continue;const f=Mt(g)??so(g)??((u=mn.find(y=>y.pattern.test(g)))==null?void 0:u.era),x=f?nt(f):void 0,v=[];for(const y of Object.keys(gn))g.includes(y)&&(x&&Ct[y]&&Ct[y]!==x||Xt(y,x)!=null&&v.push(y));if(v.length===0){const y=g.match(/([一-鿿])([一-鿿])[間间]/);if(y&&x){for(const _ of[y[1],y[2]])for(const b of Object.keys(gn))if(Ct[b]===x&&!(b[0]!==_&&b[b.length-1]!==_)&&Xt(b,x)!=null){v.push(b);break}}}if(v.length>0){const y=v.map(j=>Xt(j,x)).filter(j=>j!=null),_=Math.min(...y),b=v.reduce((j,k)=>Xt(j,x)>=Xt(k,x)?j:k),w=ig(b)??cr(x??"")??Math.max(...y);return{from:_,to:w>_?w:cr(x??Ct[b]??"")??_}}if(x&&Zt[x]!=null)return{from:Zt[x],to:cr(x)??Zt[x]}}}const Zt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},og=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],sg=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Ks=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Xs(e,n){for(const i of Yl){const o=e.indexOf(i);if(o<0)continue;if(i.length===1){const c=e[o+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Jt(e.slice(o),nt(i)))continue}const s=nt(i);if(s===n)continue;const a=e.slice(o),l=Jt(a,s)??"";let d;if(l){const c=Xt(l,s);if(c!=null){const m=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),u=m?xi(m[1]):void 0;d=c+(u?u-1:0)}}return{era:s,reign:l,year:d}}for(const i of mn)if(i.pattern.test(e))return{era:nt(i.era),reign:i.reign??""}}function ag(e){var _,b,w,j,k;const n=Wn(e),i=((_=e.publication_info)==null?void 0:_.year)??"",o=i?Ni(i):void 0;if(!n.era&&!n.reign&&!o)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"&&tg.test(i),p=n.source==="publication"&&/[間间]/.test(i),m=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let u;a||d||c||p?u=void 0:m?u=parseInt(m[2],10):u=Ii(e);const g=u==null?ao(e):void 0;let f;n.source==="publication"&&(c||Ks.test(i))?f="uncertain":n.source==="lineage"||n.source==="publication"?f="attested":Ks.test(s)||!n.reign&&u==null?f="uncertain":f="inferred";const x=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((w=e.lineage)==null?void 0:w.year_text)??((j=e.lineage)==null?void 0:j.year)??""}」`:`出版著錄「${((k=e.publication_info)==null?void 0:k.year)??""}」`,v={era:n.era,reign:n.reign,year:u,yearRange:g,certainty:f,source:n.source==="edition"?"edition":"catalog",basis:x};if(m){const C=l.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==v.era&&(v.laterRepair={era:C[1]})}if(!v.laterRepair&&sg.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(v.laterRepair={era:C[1]})}const y=og.find(C=>C.re.test(s));if(y){const C=s.search(y.re),$=s.slice(C),S=Xs($,n.era)??Xs(s,n.era);S&&(v.basedOn={era:S.era,reign:S.reign,year:S.year,relation:y.relation})}return v}const Cr={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function cr(e){return Cr[e]}function bi(e){const n=Ii(e);if(n!=null)return n;const i=ao(e);if(i)return i.from;const o=Wn(e).era;return o?Zt[o]:void 0}const Zs=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Tr(e){const n=Zs.indexOf(e);return n===-1?Zs.length:n}function lg(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 i=[],o=(s,a)=>{n[s].length&&i.push({key:s,labelKey:a,items:n[s]})};return o("belongsTo","belongsToWork"),o("collected","collectedIn"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),i}function lo(e,n){const i=qr(e||[]),o=new Map,s=[];for(const p of i)p.group?(o.has(p.group)||o.set(p.group,[]),o.get(p.group).push(p)):s.push(p);for(const p of o.values())p.sort((m,u)=>{const g=f=>f.group_role==="origin"?0:f.group_role==="mirror"?1:2;return g(m)-g(u)});const a={text:[],image:[],textImage:[],physical:[]};for(const p of s){const m=Pt(p),u=m.includes("text"),g=m.includes("image");u&&g?a.textImage.push(p):u?a.text.push(p):g?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=[...o.entries()].map(([p,m])=>{var u,g;return{key:p,label:((u=n==null?void 0:n[p])==null?void 0:u.label)||p,description:(g=n==null?void 0:n[p])==null?void 0:g.description,items:m}});return{buckets:d,mirrors:c,total:i.length}}function Ri(e,n=yn("zh-Hant")){const i=[],o=e.metadata||{};o.edition&&i.push(String(o.edition)),e.source_label&&i.push(e.source_label),e.details&&i.push(e.details);const s=wi(e);return s&&s.expected>0&&i.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})),o.version&&i.push(String(o.version)),i.join(" · ")}function Kl(e,n){if(Ri(e)||n.filter(o=>o.name===e.name).length<2)return"";try{const o=new URL(e.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const a=o.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}function Xl(e,n){var a,l;const i=e.resources||[],o=[],s=[];for(const d of i){const c=Pt(d);c.includes("image")&&o.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:Wn(e),year:Ii(e),sortYear:bi(e),images:o,holders:s,locationName:(a=e.current_location)==null?void 0:a.name,important:cg(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:o.length>0}}function cg(e,n){var d,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const o=(d=n.collections)==null?void 0:d[i];if(((o==null?void 0:o.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const a=(o==null?void 0:o.groups)??[],l=(c=n.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function Zl(e,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!o.has(c.id)).map(c=>Xl(c,n));let a=s;i.era&&(a=a.filter(c=>c.era.era===i.era)),i.scanOnly&&(a=a.filter(c=>c.hasImage)),i.sort==="year"?a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const m=c.r.sortYear,u=p.r.sortYear;return m!=null&&u!=null?m-u||c.i-p.i:m!=null?-1:u!=null?1:c.i-p.i}).map(c=>c.r):a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const m=u=>(u.important?0:1)*2+(u.hasImage?0:1);return m(c.r)-m(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)=>Tr(c)-Tr(p));return{rows:a,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function dg(e,n){var y,_;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(y=n.collections)==null?void 0:y[n.default_collection],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],a=o.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(o),c=new Set([...s,...l]),p=b=>{if(c.has(b))return!0;const w=n.node_groups[b];return w!=null&&d.has(w)},m=[],u=new Map,g=[];for(const b of e)if(!((_=n.excluded_books)!=null&&_.includes(b)))if(p(b))m.push(b);else{const w=n.node_groups[b];w?(u.has(w)||u.set(w,[]),u.get(w).push(b)):g.push(b)}if(g.length+[...u.values()].reduce((b,w)=>b+w.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const x=new Map((n.groups??[]).map(b=>[b.id,b])),v=[...u.entries()].map(([b,w])=>{const j=x.get(b);return{id:b,label:(j==null?void 0:j.label)??b,description:j==null?void 0:j.description,ids:w}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:m,groupedIds:v}}const Jl=["撰","編","注","校","譯","繪","其他"],pg=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function co(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n)return"撰";for(const{cls:i,re:o}of pg)if(o.test(n))return i;return"其他"}function po(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Ql(e,n="全部"){const i=new Map;for(const s of e){const a=co(s);i.set(a,(i.get(a)??0)+1)}const o=[{cls:"全部",label:n,count:e.length}];for(const s of Jl){const a=i.get(s);a&&o.push({cls:s,label:s,count:a})}return o.length>2?o:[]}function uo(e){return(e._books??[]).map(n=>n.id).filter(n=>typeof n=="string")}function mo(e){const n=e._classifications??[],i=n.find(o=>o.scheme==="zongmu")??n[0];if(i)return{l1:i.l1??"",l2:i.l2??"",l3:i.l3??"",l4:i.l4??"",...i.source?{source:i.source}:{}}}function ec(e){const n=e._members??[],i=typeof e._member_count=="number"?e._member_count:n.length;return{works:n.filter(o=>o.t==="work").map(o=>({id:o.id,title:o.title??"",volumes:Ln(o.vol)})),bookIds:n.filter(o=>o.t!=="work").map(o=>o.id).filter(o=>typeof o=="string"),total:i,truncated:i>n.length}}function ug(e){var n;return(e==null?void 0:e._member_count)||((n=e==null?void 0:e._members)==null?void 0:n.length)||0}function tc(e,n,i){if(n&&n.books&&n.books.length>0){const l=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),d=[...new Set(l.map(c=>c.section).filter(Boolean))];return{rows:l,source:"catalog",sections:d,totalVolumes:n.total_volumes}}const{works:o,bookIds:s}=ec(e);return o.length>0?{rows:o.map(d=>({id:d.id,title:d.title,volumes:d.volumes})),source:"works",sections:[]}:{rows:s.map(l=>{var d,c;return{id:l,title:((d=i==null?void 0:i.get(l))==null?void 0:d.title)||l,edition:(c=i==null?void 0:i.get(l))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Ln(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-i+1)},(s,a)=>i+a)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function Ei(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((a,l)=>a-l),o=i[0],s=i[i.length-1];return s-o+1===i.length?`${o}–${s}`:i.length<=3?i.join(", "):`${o}–${s} (${i.length}${n})`}const mg=["〇","一","二","三","四","五","六","七","八","九"],Js=["","十","百","千"];function nc(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let o="",s=!1;for(let a=0;a<i;a++){const l=parseInt(n[a]),d=i-1-a;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&d===1&&a===0?o+=Js[d]:o+=mg[l]+Js[d])}return o}function gg(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function hg(e){if(e==null||typeof e=="string")return;const n="url"in e&&e.url?e.url:"type"in e&&e.type==="url"?e.details:void 0;return n&&/^https?:\/\//i.test(n)?n:void 0}function Wt(e,n="卷"){var o,s;const i=e;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?nc(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function ic(e){var o;if(e.edition_type)return e.edition_type;if((o=e.lineage)!=null&&o.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,a]of i)if(s.test(n))return a;return""}const fg=65536,xg="guji_markdown";function bg(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const o=parseInt(i[1],10),s=parseInt(i[2],10);return o>0||s>=2}const yg=/^□\{guess=([^\s{}]+)\}/;function jg(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function rc(e,n){let i=0;for(let o=n;o<e.length;o++){const s=e[o];if(s===`
676
+ `;function ro(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(o=>ro(o,n))):!1}const Wm=()=>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 Om({item:e,activeKey:n,onSelect:i,tabKey:o}){const s=ro(e,n),[a,l]=h.useState(s||!!e.defaultExpanded);return h.useEffect(()=>{s&&l(!0)},[s]),h.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:o===e.key?0:-1,onClick:()=>l(d=>!d),children:[t.jsx(Wm,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),a&&t.jsx(Wl,{items:e.children,activeKey:n,onSelect:i,tabKey:o})]})}function Wl({items:e,activeKey:n,onSelect:i,tabKey:o}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Om,{item:s,activeKey:n,onSelect:i,tabKey:o},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:o===s.key?0:-1,onClick:()=>i(s.key),children:[t.jsx("span",{children:s.label}),s.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:s.hint})]})},s.key))})}function Fs(e,n){var i;for(const o of e)if(o.key===n||ro(o,n))return o.key;return((i=e[0])==null?void 0:i.key)??null}function Ol({items:e,activeKey:n,onSelect:i,label:o}){const{t:s}=te(),a=o??s("reader.toc"),l=h.useRef(null),[d,c]=h.useState(null);h.useEffect(()=>{c(null)},[n]);const p=h.useMemo(()=>d||(n??Fs(e,n)),[d,n,e]);h.useEffect(()=>{const u=l.current;if(!u)return;const g=Array.from(u.querySelectorAll("[data-rd-toc-key]"));if(g.length===0)return;const f=g.find(x=>x.dataset.rdTocKey===p)??g.find(x=>x.dataset.rdTocKey===Fs(e,n))??g.find(x=>!x.disabled)??g[0];for(const x of g)x.tabIndex=x===f?0:-1}),h.useEffect(()=>{const u=l.current,g=u==null?void 0:u.closest(".bim-rd-toc");if(!u||!g||!n)return;const f=Array.from(u.querySelectorAll("[data-rd-toc-key]")).find(v=>v.dataset.rdTocKey===n);if(!f)return;const x=f.getBoundingClientRect().top-g.getBoundingClientRect().top+g.scrollTop;(x<g.scrollTop+80||x>g.scrollTop+g.clientHeight-40)&&(g.scrollTop=Math.max(0,x-g.clientHeight/3))},[n]);const m=h.useCallback(u=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(u.key))return;const f=l.current;if(!f)return;const x=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(b=>!b.disabled),v=x.indexOf(document.activeElement);let y=v;if(u.key==="ArrowDown"?y=Math.min(x.length-1,v+1):u.key==="ArrowUp"?y=Math.max(0,v-1):u.key==="Home"?y=0:u.key==="End"&&(y=x.length-1),y<0||y===v)return;u.preventDefault();const _=x[y];for(const b of x)b.tabIndex=-1;_.tabIndex=0,_.focus(),c(_.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:m,children:t.jsx(Wl,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Hs({page:e,crop:n}){var i;return!((i=e.boxes)!=null&&i.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:n?`${n.x} ${n.y} ${n.w} ${n.h}`:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((o,s)=>t.jsx("rect",{x:o.x,y:o.y,width:o.w,height:o.h,fill:"none",stroke:r("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},s))})}function Fm(e){const{boxes:n,width:i,height:o}=e;if(!(n!=null&&n.length)||!i||!o||e.boxFormat&&e.boxFormat!=="bim-charbox-v0")return null;let s=1/0,a=1/0,l=-1/0,d=-1/0;for(const f of n)[f.x,f.y,f.w,f.h].every(Number.isFinite)&&(s=Math.min(s,f.x),a=Math.min(a,f.y),l=Math.max(l,f.x+f.w),d=Math.max(d,f.y+f.h));if(!(l>s)||!(d>a))return null;const c=Math.min(i,o)*.03,p=Math.min(i,Math.max(0,s-c)),m=Math.min(o,Math.max(0,a-c)),u=Math.min(i,Math.max(0,l+c))-p,g=Math.min(o,Math.max(0,d+c))-m;return!(u>0)||!(g>0)||u>=i*.98&&g>=o*.98?null:{x:p,y:m,w:u,h:g}}function Sr({pages:e,loading:n,page:i,onPageChange:o,renderOverlay:s,preserveMargins:a=!0}){const{t:l}=te(),[d,c]=h.useState(0),p=i??d,m=v=>{o?o(v):c(v)};if(h.useEffect(()=>{i===void 0&&c(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:l("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:l("reader.noImages")}),t.jsx("span",{children:l("reader.noImagesHint")})]})});const u=Math.max(0,Math.min(e.length-1,p)),g=e[u],f=g.label??`${u+1}`,x=!a&&!s?Fm(g):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:x?t.jsxs("figure",{className:"bim-rd-img-fig bim-rd-img-trimmed","data-trim":`${Math.round(x.x)},${Math.round(x.y)},${Math.round(x.w)},${Math.round(x.h)}`,style:{aspectRatio:`${x.w} / ${x.h}`,overflow:"hidden",width:"100%",maxWidth:`calc((100vh - 200px) * ${x.w/x.h})`},children:[t.jsx("img",{src:g.url,alt:g.alt??l("reader.imageAlt",{label:f}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${g.width/x.w*100}%`,left:`${-x.x/x.w*100}%`,top:`${-x.y/x.h*100}%`}}),t.jsx(Hs,{page:g,crop:x})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:g.url,alt:g.alt??l("reader.imageAlt",{label:f}),width:g.width,height:g.height,loading:"lazy",decoding:"async"}),t.jsx(Hs,{page:g}),s==null?void 0:s(g,u)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.prevImage"),disabled:u===0,onClick:()=>m(u-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:g.label??`${u+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:u===e.length-1,onClick:()=>m(u+1),children:"›"})]})]})}function Hm(e){return e==="lite"||e==="full"}const Pn=[.1,.9],Fl=[{key:"song",stack:null},{key:"kai",stack:'"Kaiti SC", "Kaiti TC", STKaiti, "KaiTi", "AR PL UKai CN", "Noto Serif CJK SC", serif'},{key:"system",stack:"var(--bim-font-ui)"}];function Dm(e){var n;return((n=Fl.find(i=>i.key===e))==null?void 0:n.stack)??null}const oo={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!0,pageIndicatorY:.33,bookTitleStyle:"wavy",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!0},Et=[15,16,17,18,20,22,24],_r=18,Hl="bim-reader-prefs",Um="bim-reading-mode";function Vm(){const e={...oo};try{const n=localStorage.getItem(Hl),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&Et.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Um))==="paragraph"&&(e.readingMode="paragraph"),i.properNameMode==="off"||i.properNameMode==="lite"||i.properNameMode==="full"?e.properNameMode=i.properNameMode:i.properNames===!0?e.properNameMode="full":i.properNames===!1&&(e.properNameMode="off"),i.writingMode==="vertical"&&(e.writingMode="vertical"),i.workLinks===!1&&(e.workLinks=!1),(i.fontFamily==="kai"||i.fontFamily==="system")&&(e.fontFamily=i.fontFamily),i.pageBreaks===!1&&(e.pageBreaks=!1),typeof i.pageIndicatorY=="number"&&Number.isFinite(i.pageIndicatorY)&&i.pageIndicatorY>=Pn[0]&&i.pageIndicatorY<=Pn[1]&&(e.pageIndicatorY=i.pageIndicatorY),i.bookTitleStyle==="bracket"&&(e.bookTitleStyle="bracket"),i.showWorks===!1&&(e.showWorks=!1),(i.quoteStyle==="modern"||i.quoteStyle==="classic")&&(e.quoteStyle=i.quoteStyle),(i.scriptMode==="orig"||i.scriptMode==="hant"||i.scriptMode==="hans")&&(e.scriptMode=i.scriptMode),i.preserveMargins===!1&&(e.preserveMargins=!1)}catch{}return e}function Gm(e){try{localStorage.setItem(Hl,JSON.stringify(e))}catch{}}function oi(e,n){const i=e??_r,o=Et;let s=o.indexOf(i);return s<0&&(s=o.indexOf(_r)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Dl(){const[e,n]=h.useState(oo);h.useEffect(()=>{n(Vm())},[]);const i=h.useCallback(o=>{n(s=>{const a={...s,...o};return Gm(a),a})},[]);return[e,i]}function $r(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 Ul(e,n){if(!(!e||e.length===0))return(n!=null?e.find(i=>i.key===n):void 0)??e.find(i=>i.primary)??e[0]}function Vl(e){const n=[],i=o=>{for(const s of o)s.children&&s.children.length>0?i(s.children):n.push(s)};return i(e),n}const Ds=()=>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"})}),qm=()=>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"})}),Us=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M4 7h10M18 7h2M4 17h2M10 17h10"}),t.jsx("circle",{cx:"16",cy:"7",r:"2"}),t.jsx("circle",{cx:"8",cy:"17",r:"2"})]}),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 Gs(e,n){if(!n)return;const i=Array.from(n.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(i.length===0)return;const o=i[0],s=i[i.length-1],a=document.activeElement;e.shiftKey&&(a===o||!n.contains(a))?(e.preventDefault(),s.focus()):!e.shiftKey&&(a===s||!n.contains(a))&&(e.preventDefault(),o.focus())}function Ys(e,n){const[i,o]=h.useState(n);return h.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(e);o(s.matches);const a=()=>o(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]),i}function Km({prefs:e,onPrefsChange:n}){const i=h.useContext(Tt),{t:o}=te();if(!i)return null;const s=i.locale==="zh-Hans"?"hans":"hant",a=e.scriptMode==="orig"?"orig":s,l=[{key:"orig",short:o("reader.scriptOrigShort"),title:o("reader.scriptOrig")},{key:"hant",short:o("common.localeShortHant"),title:o("reader.scriptHant")},{key:"hans",short:o("common.localeShortHans"),title:o("reader.scriptHans")}];return t.jsx("span",{className:"bim-rd-script-sw",role:"group","aria-label":o("reader.scriptQuick"),children:l.map((d,c)=>t.jsxs(h.Fragment,{children:[c>0&&t.jsx("span",{className:"bim-rd-off","aria-hidden":"true",children:"|"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":a===d.key,title:d.title,"aria-label":d.title,onClick:()=>{n({scriptMode:d.key}),d.key==="hant"?i.setLocale("zh-Hant"):d.key==="hans"&&i.setLocale("zh-Hans")},children:d.short})]},d.key))})}function pi({label:e,value:n,options:i,onPick:o,title:s}){return t.jsxs("div",{className:"bim-rd-sp-row",role:"group","aria-label":e,title:s,children:[t.jsx("span",{className:"bim-rd-sp-l",children:e}),t.jsx("span",{className:"bim-rd-sp-fs",children:i.map(a=>t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":n===a.key,title:a.title,onClick:()=>o(a.key),children:a.label},a.key))})]})}function Xm({prefs:e,onPrefsChange:n}){const i=h.useContext(Tt),{t:o}=te(),s=(i==null?void 0:i.locale)==="zh-Hans"?"hans":"hant",a=e.scriptMode==="orig"?"orig":s;return t.jsx(pi,{label:o("reader.script"),value:a,options:[{key:"orig",label:o("reader.scriptOrig")},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:l=>{n({scriptMode:l}),l==="hant"?i==null||i.setLocale("zh-Hant"):l==="hans"&&(i==null||i.setLocale("zh-Hans"))}})}function Zm(e,n){if(!e)return;let i;for(const o of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(o.getBoundingClientRect().top<=n+8)i=o.id;else break;return i}function Jm(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 i=e.querySelector(".bim-rd-col"),o=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(i!=null&&i.contains(l))&&!(d!=null&&d.closest(".bim-rd-src, .bim-rd-pager"))};if(!o(n.anchorNode)||!o(n.focusNode))return;const s=n.toString().replace(/\s+/g," ").trim();return s?s.slice(0,500):void 0}function Gl({title:e,subtitle:n,toc:i,activeKey:o,onSelect:s,tocHeader:a,tocCaption:l,images:d,imagesLoading:c,renderImageOverlay:p,imagePanel:m="auto",prefs:u,onPrefsChange:g,paragraphToggle:f,properNameToggle:x=!0,allowVertical:v,byline:y,current:_,workLinkToggle:b,rail:w,onReportError:j,revisedAt:k,backHref:C,backLabel:$,bottomBar:S=!0,pager:M=!0,pagerUnit:z,versions:T,currentVersionKey:P,onVersionChange:R,versionSource:N=!0,keepChapterOnVersionChange:A=!1,customImagePanel:H,toolbarExtra:G,settingsAnnotate:ie,settingsLayout:le,isWarpMode:V,children:F,className:xe,style:ee}){const{t:L,convert:Re}=te(),ce=$??L("reader.back"),me=Re(z??L("reader.unitJuan")),se=h.useId().replace(/:/g,""),Pe=`bim-rd-toc-${se}`,X=`bim-rd-text-${se}`,re=h.useRef(null),de=h.useRef(null),D=h.useRef(null),K=h.useRef(null),we=Ys(Al,!0),ne=Ys(Pl,!1),B=S&&ne,[Z,ae]=h.useState(null),[je,Y]=h.useState(!1),be=h.useRef(null),Ee=`bim-rd-set-${se}`,Fe=h.useRef(null),W=h.useRef(null),J=(q,Ve)=>{W.current=Ve,ae(Oe=>Oe===q?null:q)},$e=h.useCallback(()=>{var q;ae(null),(q=W.current)==null||q.focus()},[]);h.useEffect(()=>{B||ae(null)},[B]),h.useEffect(()=>{var q,Ve;Z&&((Ve=(q=Fe.current)==null?void 0:q.querySelector("button:not([disabled])"))==null||Ve.focus())},[Z]);const[Te,O]=h.useState("auto"),fe=Te==="auto"?we:Te==="open",oe=!we,Se=!!H||!!d&&d.length>0,[Le,He]=h.useState(m);h.useEffect(()=>{He(m)},[m]);const Ye=Le==="auto"?Se||!!c:Le==="open",qe=h.useCallback(q=>{var Ve;O("auto"),q&&((Ve=K.current)==null||Ve.focus())},[]),Xe=()=>O(fe?"closed":"open");h.useEffect(()=>{if(!oe||Te!=="open")return;const q=D.current,Ve=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');Ve==null||Ve.focus()},[oe,Te]);const I=h.useCallback(q=>{s(q),oe&&qe(!1);const Ve=de.current,Oe=re.current;if(Ve&&Oe&&typeof window<"u"){const rt=Ve.getBoundingClientRect().top-Oe.getBoundingClientRect().bottom;rt<0&&window.scrollBy({top:rt})}},[s,oe,qe]),U=h.useMemo(()=>Vl(i),[i]),[ue,Ce]=h.useState(null),ye=Ul(T,P!==void 0?P:ue),ge=(ye==null?void 0:ye.key)??null,Ge=h.useMemo(()=>U.map(q=>q.key).join(`
677
+ `),[U]),Q=h.useRef(null),ke=q=>{q!==ge&&(A||(Q.current={key:q,sig:Ge,done:!1}),P===void 0&&Ce(q),R==null||R(q))};h.useEffect(()=>{const q=Q.current;if(!q||q.key!==ge)return;const Ve=U.find(rt=>!rt.disabled);if(!Ve)return;const Oe=Ge!==q.sig;!Oe&&q.done||(Oe?Q.current=null:q.done=!0,Ve.key!==o&&I(Ve.key))},[ge,Ge,U,o,I]);const Ae=U.find(q=>q.key===o),Be=()=>{var q;j==null||j({chapterKey:o,chapterLabel:typeof(Ae==null?void 0:Ae.label)=="string"?Ae.label:void 0,anchor:Zm(de.current,((q=re.current)==null?void 0:q.getBoundingClientRect().bottom)??0),selectedText:Jm(de.current)})},Ne=U.findIndex(q=>q.key===o),he=Ne>0?U.slice(0,Ne).reverse().find(q=>!q.disabled):void 0,ve=Ne>=0?U.slice(Ne+1).find(q=>!q.disabled):void 0,Ue=u.fontSize??_r,We=Dm(u.fontFamily),st={...ee,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...We?{"--bimrd-ff":We}:null},jt={song:L("reader.fontSong"),kai:L("reader.fontKai"),system:L("reader.fontSystem")},on=x||!!ie,Gt=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ee}-g1`,children:[t.jsx("h3",{id:`${Ee}-g1`,className:"bim-rd-sp-h",children:L("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":L("reader.font"),value:u.fontFamily,onChange:q=>g({fontFamily:q.target.value}),children:Fl.map(q=>t.jsx("option",{value:q.key,children:jt[q.key]},q.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontSmaller"),disabled:Ue<=Et[0],onClick:()=>g({fontSize:oi(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[Ue,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontLarger"),disabled:Ue>=Et[Et.length-1],onClick:()=>g({fontSize:oi(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Xm,{prefs:u,onPrefsChange:g}),t.jsx(pi,{label:L("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:L("reader.quoteModern")},{key:"classic",label:L("reader.quoteClassic")},{key:"original",label:L("reader.quoteOriginal")}],onPick:q=>g({quoteStyle:q})})]}),on&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ee}-g2`,children:[t.jsx("h3",{id:`${Ee}-g2`,className:"bim-rd-sp-h",children:L("reader.groupMark")}),x&&t.jsxs(t.Fragment,{children:[t.jsx(pi,{label:L("reader.properName"),value:u.properNameMode,title:L("reader.properNameTitle"),options:[{key:"off",label:L("reader.properNameOff")},{key:"lite",label:L("reader.properNameLite"),title:L("reader.properNameLiteTitle")},{key:"full",label:L("reader.properNameFull")}],onPick:q=>g({properNameMode:q})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:q=>g({showWorks:q.target.checked})}),t.jsx("span",{children:L("reader.showWorks")})]}),t.jsx(pi,{label:L("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:L("reader.bookTitleWavy")},{key:"bracket",label:L("reader.bookTitleBracket")}],onPick:q=>g({bookTitleStyle:q})})]}),ie]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ee}-g3`,children:[t.jsx("h3",{id:`${Ee}-g3`,className:"bim-rd-sp-h",children:L("reader.groupLayout")}),f&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:L("reader.paragraphTitle"),onClick:()=>g({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:L("reader.paragraph")}),b&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.workLinks,onChange:q=>g({workLinks:q.target.checked})}),t.jsx("span",{children:L("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>g({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:L("reader.vertical")}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.pageBreaks,onChange:q=>g({pageBreaks:q.target.checked})}),t.jsx("span",{children:L("reader.pageBreaks")})]}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:q=>g({preserveMargins:q.target.checked})}),t.jsx("span",{children:L("reader.preserveMargins")})]}),le]})]});return t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",xe].filter(Boolean).join(" "),"data-toc":Te,"data-img":Ye?"open":"closed","data-bb":B?"":void 0,"data-set":!B&&je?"open":void 0,"data-warp":V?"true":void 0,style:st,children:[t.jsx("style",{children:Bl}),t.jsx("a",{className:"bim-rd-skip",href:`#${X}`,onClick:q=>{var Ve,Oe,rt;q.preventDefault(),(Ve=de.current)==null||Ve.focus(),(rt=(Oe=de.current)==null?void 0:Oe.scrollIntoView)==null||rt.call(Oe,{block:"start"})},children:L("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:re,children:[C&&t.jsxs("a",{className:"bim-rd-back",href:C,"aria-label":L("reader.backAria",{label:ce}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:ce})]}),(e||n||y||_)&&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}),_&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:_})]}),n&&t.jsx("span",{className:"bim-rd-ttl-src",children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":L("reader.settings"),children:[T&&T.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ye?Re($r(ye)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:L("reader.versionShort")}),t.jsx("select",{"aria-label":L("reader.version"),value:ge??"",onChange:q=>ke(q.target.value),children:T.map(q=>t.jsx("option",{value:q.key,children:Re($r(q))},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),M&&(he||ve)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":L("reader.pagerGroup",{unit:me}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.prevUnit",{unit:me}),title:he?typeof he.label=="string"&&he.label?L("reader.prevUnitTitle",{unit:me,label:he.label}):L("reader.prevUnit",{unit:me}):L("reader.firstUnit",{unit:me}),disabled:!he,onClick:()=>he&&I(he.key),children:t.jsx(Ym,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.nextUnit",{unit:me}),title:ve?typeof ve.label=="string"&&ve.label?L("reader.nextUnitTitle",{unit:me,label:ve.label}):L("reader.nextUnit",{unit:me}):L("reader.lastUnit",{unit:me}),disabled:!ve,onClick:()=>ve&&I(ve.key),children:t.jsx(qm,{})})]}),M&&(he||ve)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:K,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":fe,"aria-controls":Pe,onClick:Xe,children:[t.jsx(Ds,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":Ye,onClick:()=>He(Ye?"closed":"open"),children:[t.jsx(Vs,{}),L("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Km,{prefs:u,onPrefsChange:g}),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":L("reader.fontSmaller"),disabled:Ue<=Et[0],onClick:()=>g({fontSize:oi(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":L("reader.fontLarger"),disabled:Ue>=Et[Et.length-1],onClick:()=>g({fontSize:oi(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:be,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":je,"aria-controls":Ee,onClick:()=>Y(q=>!q),children:[t.jsx(Us,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.settings")})]}),G]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:Pe,ref:D,role:oe&&fe?"dialog":void 0,"aria-modal":oe&&fe?!0:void 0,"aria-label":oe&&fe?L("reader.toc"):void 0,onKeyDown:q=>{if(!(!oe||!fe)){if(q.key==="Escape"){q.stopPropagation(),qe(!0);return}q.key==="Tab"&&Gs(q,D.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??L("reader.toc")}),oe&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeToc"),onClick:()=>qe(!0),children:"✕"})]}),a]}),t.jsx(Ol,{items:i,activeKey:o,onSelect:I})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>qe(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":L("reader.images"),children:Ye&&(H||t.jsx(Sr,{pages:d??null,loading:c,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!B&&je&&t.jsxs("aside",{className:"bim-rd-set",id:Ee,"aria-label":L("reader.settings"),onKeyDown:q=>{var Ve;q.key==="Escape"&&(q.stopPropagation(),Y(!1),(Ve=be.current)==null||Ve.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:L("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeSettings"),onClick:()=>{var q;Y(!1),(q=be.current)==null||q.focus()},children:"✕"})]}),Gt]}),t.jsxs("div",{className:"bim-rd-text",id:X,ref:de,tabIndex:-1,"data-rail":(w||j)&&!V?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[F,N&&ye&&(ye.sourceName||ye.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ye.key,children:[ye.sourceName&&t.jsxs(t.Fragment,{children:[L("reader.sourceLabel")," ",ye.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ye.sourceUrl,target:"_blank",rel:"noreferrer",children:Re(ye.sourceName)}):Re(ye.sourceName)]}),ye.sourceName&&ye.license&&t.jsx("span",{className:"bim-rd-dot"}),ye.license&&t.jsx(t.Fragment,{children:L("reader.licenseOf",{license:ye.license})})]}),k&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:L("reader.revisedAt",{date:k})}),j&&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:Be,children:L("reader.reportError")})}),M&&(he||ve)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":L("reader.pagerNav"),children:[he?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>I(he.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),L("reader.prevUnit",{unit:me})]}),t.jsx("span",{className:"bim-rd-pglabel",children:he.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",L("reader.firstUnit",{unit:me})]}),ve?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>I(ve.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[L("reader.nextUnit",{unit:me}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:ve.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[L("reader.lastUnit",{unit:me})," →"]})]})]}),(w||j)&&!V&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":L("reader.rail"),children:[w,j&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:q=>q.preventDefault(),onClick:Be,children:L("reader.reportError")})})]})]})]}),B&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":L("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":fe,"aria-controls":Pe,onClick:()=>{ae(null),Xe()},children:[t.jsx(Ds,{}),t.jsx("span",{children:L("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":Z==="img","aria-haspopup":"dialog",onClick:q=>J("img",q.currentTarget),children:[t.jsx(Vs,{}),t.jsx("span",{children:L("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":Z==="set","aria-haspopup":"dialog",onClick:q=>J("set",q.currentTarget),children:[t.jsx(Us,{}),t.jsx("span",{children:L("reader.settingsShort")})]}),j&&t.jsxs("button",{type:"button",onMouseDown:q=>q.preventDefault(),onClick:()=>{ae(null),Be()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:L("reader.reportError")})]})]}),B&&Z&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:$e}),t.jsxs("div",{className:"bim-rd-sheet",ref:Fe,role:"dialog","aria-modal":"true","aria-label":L(Z==="img"?"reader.images":"reader.settings"),onKeyDown:q=>{if(q.key==="Escape"){q.stopPropagation(),$e();return}q.key==="Tab"&&Gs(q,Fe.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:L(Z==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.close"),onClick:$e,children:"✕"})]}),Z==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Sr,{pages:d??null,loading:c,renderOverlay:p,preserveMargins:u.preserveMargins})}):Gt]})]})]})}const Yl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Qm={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function nt(e){return Qm[e]??e}const mn=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],gn={熹平: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},ql={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Ni(e){const n=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const o=n[2]?parseInt(n[2],10):void 0;return{from:i,to:o!=null&&o>=i&&o<=2100?o:void 0}}function eg(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 tg=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,qs={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function so(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(qs))if(n.startsWith(s))return qs[s];const i=nt(n);if(Zt[i]!=null)return i;const o=At(n);if(o&&n.length<=o.length+1)return nt(o)}function Xt(e,n){if(n){const i=ql[`${n}|${e}`];if(i!=null)return i}return gn[e]}const ng=1911;function ig(e){const n=gn[e];if(n==null)return;const i=Ct[e];let o;for(const[s,a]of Object.entries(gn))Ct[s]===i&&a>n&&(o==null||a<o)&&(o=a);return o!=null?o-1:void 0}const rg={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function xi(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,o=!1;for(const a of e){const l=rg[a];if(l===void 0)return;o=!0,a==="十"?i=(i||1)*10:a==="廿"||a==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return o&&s>0?s:void 0}function At(e){for(const n of Yl)if(e.startsWith(n))return n}const Ct={};{const e=(n,i)=>{for(const o of i)Ct[o]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Jt(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(gn))if(e.includes(o)&&!(i&&Ct[o]&&Ct[o]!==i&&ql[`${i}|${o}`]==null))return o}function Wn(e){var l,d,c;const n={era:"",reign:"",source:"none"},i=e.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const o=(l=e.lineage)==null?void 0:l.year_text;if(o){const p=At(o)??"";return{era:nt(p),reign:Jt(o,p)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const p=Ni(s);if(p)return{era:eg(p.from),reign:"",source:"publication"};const m=At(s)??so(s)??((c=mn.find(f=>f.pattern.test(s)))==null?void 0:c.era)??"",u=Jt(s,m)??"",g=m||(u?Ct[u]??"":"");if(g||u)return{era:nt(g),reign:u,source:"publication"}}const a=e.edition||e.title||"";if(a){const p=At(a);if(p)return{era:nt(p),reign:Jt(a,p)??"",source:"edition"};const m=mn.find(u=>u.pattern.test(a));if(m)return{era:nt(m.era),reign:Jt(a,m.era)??m.reign??"",source:"edition"}}return n}function Ii(e){var o,s,a,l,d,c,p,m,u;if(((o=e.dating)==null?void 0:o.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 g=Ni(n);if(g)return g.from}const i=[(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 g of i){const f=((c=e.publication_info)==null?void 0:c.year)||((p=e.lineage)==null?void 0:p.year_text);if(f&&g!==f&&(At(f)||so(f)))break;const x=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(x){const w=parseInt(x[1],10);if(w>=100&&w<=2100)return w}const v=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(v){const w=At(g);if(!w||nt(w)==="民國"){const k=xi(v[1]);if(k!=null&&k>=1&&k<=120)return ng+k}}const y=At(g)??((m=mn.find(w=>w.pattern.test(g)))==null?void 0:m.era),_=y?nt(y):void 0,b=Jt(g,_)??(At(g)||(u=mn.find(w=>w.pattern.test(g)))==null?void 0:u.reign);if(b){const w=Xt(b,_);if(w==null)continue;const j=g.indexOf(b),k=j>=0?g.slice(j+b.length):"",C=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),$=C?xi(C[1]):void 0;return w+($?$-1:0)}}}function ao(e){var l,d,c,p,m,u;const n=(l=e.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(d=e.lineage)==null?void 0:d.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const o=(c=e.lineage)==null?void 0:c.year_text;if(o){const g=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const f=Cr[nt(g[1])],x=Zt[nt(g[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 g=Ni(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const f=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const x=Cr[nt(f[1])],v=Zt[nt(f[2])];if(x!=null&&v!=null)return{from:Math.min(x,v)-20,to:Math.max(x,v)+40}}}const a=[(m=e.publication_info)==null?void 0:m.year,e.edition,e.title].filter(Boolean);for(const g of a){if(!/[間间]/.test(g))continue;const f=At(g)??so(g)??((u=mn.find(y=>y.pattern.test(g)))==null?void 0:u.era),x=f?nt(f):void 0,v=[];for(const y of Object.keys(gn))g.includes(y)&&(x&&Ct[y]&&Ct[y]!==x||Xt(y,x)!=null&&v.push(y));if(v.length===0){const y=g.match(/([一-鿿])([一-鿿])[間间]/);if(y&&x){for(const _ of[y[1],y[2]])for(const b of Object.keys(gn))if(Ct[b]===x&&!(b[0]!==_&&b[b.length-1]!==_)&&Xt(b,x)!=null){v.push(b);break}}}if(v.length>0){const y=v.map(j=>Xt(j,x)).filter(j=>j!=null),_=Math.min(...y),b=v.reduce((j,k)=>Xt(j,x)>=Xt(k,x)?j:k),w=ig(b)??cr(x??"")??Math.max(...y);return{from:_,to:w>_?w:cr(x??Ct[b]??"")??_}}if(x&&Zt[x]!=null)return{from:Zt[x],to:cr(x)??Zt[x]}}}const Zt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},og=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],sg=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Ks=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Xs(e,n){for(const i of Yl){const o=e.indexOf(i);if(o<0)continue;if(i.length===1){const c=e[o+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!Jt(e.slice(o),nt(i)))continue}const s=nt(i);if(s===n)continue;const a=e.slice(o),l=Jt(a,s)??"";let d;if(l){const c=Xt(l,s);if(c!=null){const m=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),u=m?xi(m[1]):void 0;d=c+(u?u-1:0)}}return{era:s,reign:l,year:d}}for(const i of mn)if(i.pattern.test(e))return{era:nt(i.era),reign:i.reign??""}}function ag(e){var _,b,w,j,k;const n=Wn(e),i=((_=e.publication_info)==null?void 0:_.year)??"",o=i?Ni(i):void 0;if(!n.era&&!n.reign&&!o)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"&&tg.test(i),p=n.source==="publication"&&/[間间]/.test(i),m=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let u;a||d||c||p?u=void 0:m?u=parseInt(m[2],10):u=Ii(e);const g=u==null?ao(e):void 0;let f;n.source==="publication"&&(c||Ks.test(i))?f="uncertain":n.source==="lineage"||n.source==="publication"?f="attested":Ks.test(s)||!n.reign&&u==null?f="uncertain":f="inferred";const x=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((w=e.lineage)==null?void 0:w.year_text)??((j=e.lineage)==null?void 0:j.year)??""}」`:`出版著錄「${((k=e.publication_info)==null?void 0:k.year)??""}」`,v={era:n.era,reign:n.reign,year:u,yearRange:g,certainty:f,source:n.source==="edition"?"edition":"catalog",basis:x};if(m){const C=l.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==v.era&&(v.laterRepair={era:C[1]})}if(!v.laterRepair&&sg.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(v.laterRepair={era:C[1]})}const y=og.find(C=>C.re.test(s));if(y){const C=s.search(y.re),$=s.slice(C),S=Xs($,n.era)??Xs(s,n.era);S&&(v.basedOn={era:S.era,reign:S.reign,year:S.year,relation:y.relation})}return v}const Cr={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function cr(e){return Cr[e]}function bi(e){const n=Ii(e);if(n!=null)return n;const i=ao(e);if(i)return i.from;const o=Wn(e).era;return o?Zt[o]:void 0}const Zs=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Tr(e){const n=Zs.indexOf(e);return n===-1?Zs.length:n}function lg(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 i=[],o=(s,a)=>{n[s].length&&i.push({key:s,labelKey:a,items:n[s]})};return o("belongsTo","belongsToWork"),o("collected","collectedIn"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),i}function lo(e,n){const i=qr(e||[]),o=new Map,s=[];for(const p of i)p.group?(o.has(p.group)||o.set(p.group,[]),o.get(p.group).push(p)):s.push(p);for(const p of o.values())p.sort((m,u)=>{const g=f=>f.group_role==="origin"?0:f.group_role==="mirror"?1:2;return g(m)-g(u)});const a={text:[],image:[],textImage:[],physical:[]};for(const p of s){const m=Mt(p),u=m.includes("text"),g=m.includes("image");u&&g?a.textImage.push(p):u?a.text.push(p):g?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=[...o.entries()].map(([p,m])=>{var u,g;return{key:p,label:((u=n==null?void 0:n[p])==null?void 0:u.label)||p,description:(g=n==null?void 0:n[p])==null?void 0:g.description,items:m}});return{buckets:d,mirrors:c,total:i.length}}function Ri(e,n=yn("zh-Hant")){const i=[],o=e.metadata||{};o.edition&&i.push(String(o.edition)),e.source_label&&i.push(e.source_label),e.details&&i.push(e.details);const s=wi(e);return s&&s.expected>0&&i.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})),o.version&&i.push(String(o.version)),i.join(" · ")}function Kl(e,n){if(Ri(e)||n.filter(o=>o.name===e.name).length<2)return"";try{const o=new URL(e.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const a=o.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}function Xl(e,n){var a,l;const i=e.resources||[],o=[],s=[];for(const d of i){const c=Mt(d);c.includes("image")&&o.push(d),c.includes("physical")&&s.push(d)}return{id:e.id,name:e.edition||e.title||e.id,era:Wn(e),year:Ii(e),sortYear:bi(e),images:o,holders:s,locationName:(a=e.current_location)==null?void 0:a.name,important:cg(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:o.length>0}}function cg(e,n){var d,c;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const o=(d=n.collections)==null?void 0:d[i];if(((o==null?void 0:o.book_ids)??(i==="core"?n.core_books??[]:[])).includes(e))return!0;const a=(o==null?void 0:o.groups)??[],l=(c=n.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function Zl(e,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!o.has(c.id)).map(c=>Xl(c,n));let a=s;i.era&&(a=a.filter(c=>c.era.era===i.era)),i.scanOnly&&(a=a.filter(c=>c.hasImage)),i.sort==="year"?a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const m=c.r.sortYear,u=p.r.sortYear;return m!=null&&u!=null?m-u||c.i-p.i:m!=null?-1:u!=null?1:c.i-p.i}).map(c=>c.r):a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const m=u=>(u.important?0:1)*2+(u.hasImage?0:1);return m(c.r)-m(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)=>Tr(c)-Tr(p));return{rows:a,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function dg(e,n){var y,_;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(y=n.collections)==null?void 0:y[n.default_collection],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],a=o.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(o),c=new Set([...s,...l]),p=b=>{if(c.has(b))return!0;const w=n.node_groups[b];return w!=null&&d.has(w)},m=[],u=new Map,g=[];for(const b of e)if(!((_=n.excluded_books)!=null&&_.includes(b)))if(p(b))m.push(b);else{const w=n.node_groups[b];w?(u.has(w)||u.set(w,[]),u.get(w).push(b)):g.push(b)}if(g.length+[...u.values()].reduce((b,w)=>b+w.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const x=new Map((n.groups??[]).map(b=>[b.id,b])),v=[...u.entries()].map(([b,w])=>{const j=x.get(b);return{id:b,label:(j==null?void 0:j.label)??b,description:j==null?void 0:j.description,ids:w}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:m,groupedIds:v}}const Jl=["撰","編","注","校","譯","繪","其他"],pg=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function co(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n)return"撰";for(const{cls:i,re:o}of pg)if(o.test(n))return i;return"其他"}function po(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Ql(e,n="全部"){const i=new Map;for(const s of e){const a=co(s);i.set(a,(i.get(a)??0)+1)}const o=[{cls:"全部",label:n,count:e.length}];for(const s of Jl){const a=i.get(s);a&&o.push({cls:s,label:s,count:a})}return o.length>2?o:[]}function uo(e){return(e._books??[]).map(n=>n.id).filter(n=>typeof n=="string")}function mo(e){const n=e._classifications??[],i=n.find(o=>o.scheme==="zongmu")??n[0];if(i)return{l1:i.l1??"",l2:i.l2??"",l3:i.l3??"",l4:i.l4??"",...i.source?{source:i.source}:{}}}function ec(e){const n=e._members??[],i=typeof e._member_count=="number"?e._member_count:n.length;return{works:n.filter(o=>o.t==="work").map(o=>({id:o.id,title:o.title??"",volumes:Ln(o.vol)})),bookIds:n.filter(o=>o.t!=="work").map(o=>o.id).filter(o=>typeof o=="string"),total:i,truncated:i>n.length}}function ug(e){var n;return(e==null?void 0:e._member_count)||((n=e==null?void 0:e._members)==null?void 0:n.length)||0}function tc(e,n,i){if(n&&n.books&&n.books.length>0){const l=n.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),d=[...new Set(l.map(c=>c.section).filter(Boolean))];return{rows:l,source:"catalog",sections:d,totalVolumes:n.total_volumes}}const{works:o,bookIds:s}=ec(e);return o.length>0?{rows:o.map(d=>({id:d.id,title:d.title,volumes:d.volumes})),source:"works",sections:[]}:{rows:s.map(l=>{var d,c;return{id:l,title:((d=i==null?void 0:i.get(l))==null?void 0:d.title)||l,edition:(c=i==null?void 0:i.get(l))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Ln(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(n=>typeof n=="number");if(typeof e=="string"){const n=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-i+1)},(s,a)=>i+a)}return e.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function Ei(e,n="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const i=[...e].sort((a,l)=>a-l),o=i[0],s=i[i.length-1];return s-o+1===i.length?`${o}–${s}`:i.length<=3?i.join(", "):`${o}–${s} (${i.length}${n})`}const mg=["〇","一","二","三","四","五","六","七","八","九"],Js=["","十","百","千"];function nc(e){if(e<=0)return"";if(e>=1e4)return String(e);const n=String(e),i=n.length;let o="",s=!1;for(let a=0;a<i;a++){const l=parseInt(n[a]),d=i-1-a;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&d===1&&a===0?o+=Js[d]:o+=mg[l]+Js[d])}return o}function gg(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function hg(e){if(e==null||typeof e=="string")return;const n="url"in e&&e.url?e.url:"type"in e&&e.type==="url"?e.details:void 0;return n&&/^https?:\/\//i.test(n)?n:void 0}function Bt(e,n="卷"){var o,s;const i=e;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?nc(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function ic(e){var o;if(e.edition_type)return e.edition_type;if((o=e.lineage)!=null&&o.category)return e.lineage.category;const n=e.edition||e.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,a]of i)if(s.test(n))return a;return""}const fg=65536,xg="guji_markdown";function bg(e){const n=e==null?void 0:e.guji_markdown;if(typeof n!="string")return!1;const i=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(n.trim());if(!i)return!1;const o=parseInt(i[1],10),s=parseInt(i[2],10);return o>0||s>=2}const yg=/^□\{guess=([^\s{}]+)\}/;function jg(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function rc(e,n){let i=0;for(let o=n;o<e.length;o++){const s=e[o];if(s===`
679
678
  `)return-1;if(s==="\\"){o++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return o}return-1}function vg(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function kg(e,n){const i=e[n];if(i==="["&&e[n+1]==="["){const o=e.indexOf("]]",n+2);return o>=0&&e.slice(n+2,o).indexOf(`
680
679
  `)<0?{node:{type:"qw",label:e.slice(n+2,o)},end:o+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const o=rc(e,n+3);return o>n+4?{node:{type:"zi",label:vg(e.slice(n+4,o))},end:o+1}:null}if(i==="□"&&e[n+1]==="{"){const o=yg.exec(e.slice(n,n+64));if(o)return{node:{type:"qz",guess:o[1]},end:n+o[0].length}}return null}function oc(e,n,i,o,s){const a=[];let l="",d=!1;const c=()=>{if(!l)return;let p=l;o&&(p=l.replace(/\\?\|/g,m=>d?"|":(d=!0,""))),p&&a.push({type:"text",text:p}),l=""};for(;n<e.length;){const p=e[n];if(p==="\\"&&(e[n+1]==="<"||e[n+1]===">")){l+=e[n+1],n+=2;continue}if(i!==null){if(p===i)return c(),{nodes:a,end:n};if(p===`
681
680
  `)return null}const m=kg(e,n);if(m){c(),a.push(m.node),n=m.end;continue}let u=null;if(p==="⟨"?u="⟩":p==="<"&&jg(e,n)&&(u=">"),u){const g=oc(e,n+1,u,!0,s);if(g&&!(p==="<"&&g.end-(n+1)>s)){c(),a.push({type:"jz",children:g.nodes}),n=g.end+1;continue}}l+=p,n++}return i!==null?null:(c(),{nodes:a,end:n})}function sc(e,n){return oc(e,0,null,!1,(n==null?void 0:n.jzMaxLength)??fg).nodes}function wg(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function ac(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${ac(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Sg=216,Qs="clamp(280px, 23vw, 360px)",_g=1440,zr="(max-width: 719px)",$g=`${zr}, (pointer: coarse)`,Cg=`
@@ -1341,7 +1340,7 @@ a.bim-et:focus-visible { outline: 2px solid ${r("accent")}; outline-offset: 2px;
1341
1340
  .bim-et-card { animation: bim-et-in 120ms ease-out; }
1342
1341
  @keyframes bim-et-in { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
1343
1342
  }
1344
- `,sf=120;function gt(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function af(e,n=sf){if(!e)return;const i=e.replace(/\s+/g," ").trim(),o=Array.from(i);return o.length>n?o.slice(0,n).join("")+"…":i}function lf(e){const n=typeof e.birth_year=="number"?e.birth_year:void 0,i=typeof e.death_year=="number"?e.death_year:void 0;if(!(n===void 0&&i===void 0))return`${n??"?"}–${i??"?"}`}function cf(e){if(!Array.isArray(e.authors))return;const n=e.authors.map(i=>{if(!i||typeof i!="object")return"";const o=i,s=gt(o.name);return s?[gt(o.dynasty)&&`〔${gt(o.dynasty)}〕`,s,gt(o.role)].filter(Boolean).join(""):""}).filter(Boolean);return n.length?n.slice(0,3).join("、"):void 0}function Oc(e,n){const i=gt(n.type),o=gt(n.primary_name)??gt(n.title)??e,s=i==="entity"?[gt(n.dynasty),lf(n),gt(n.native_place)].filter(Boolean).join(" · "):[cf(n),gt(n.edition),gt(n.measure_info)].filter(Boolean).join(" · "),a=n.description&&typeof n.description=="object"?gt(n.description.text):gt(n.description);return{id:e,type:i,title:o,meta:s||void 0,description:af(a)}}function Fc(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 Hc(e){return async n=>{const i=await e.getItem(n);if(i)return Oc(n,i);if(e.getEntry){const o=await e.getEntry(n);if(o)return Fc(o)}return null}}const la=new WeakMap;function df(e,n,i){let o=la.get(e);o||(o=new Map,la.set(e,o));const s=o.get(i);if(s)return s;const a=n(i);return o.set(i,a),a.catch(()=>o.delete(i)),a}const Dc=e=>`/item/${encodeURIComponent(e)}`,ca={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},pf=typeof window>"u"?h.useEffect:h.useLayoutEffect;function Ao(e,n){return h.useMemo(()=>n?{owner:n,load:n}:e?{owner:e,load:Hc(e)}:null,[n,e])}const uf=e=>e,mf=({text:e,entities:n,offsets:i="text",plainBase:o=0,transport:s,loadSummary:a,buildHref:l=Dc,onNavigate:d,renderText:c=uf,hoverDelayMs:p=250,closeDelayMs:m,injectStyles:u=!0,className:g})=>{const f=h.useMemo(()=>{const v=i==="plain"?Ac(e,n,o):n;return Mc(e,v)},[e,n,i,o]),x=Ao(s,a);return t.jsxs("span",{className:g?`bim-et-root ${g}`:"bim-et-root",children:[u&&t.jsx("style",{children:Lo}),f.map(v=>v.type==="text"?t.jsx(h.Fragment,{children:c(v.text)},`t${v.start}`):t.jsx(Mo,{span:v.span,label:v.text,hasBrackets:e[v.start-1]==="《"&&e[v.start+v.text.length]==="》",loader:x,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:p,closeDelayMs:m},`${v.span.key}@${v.start}`))]})};let Ft=null;const Mo=({span:e,label:n,hasBrackets:i,plain:o,loader:s,buildHref:a,onNavigate:l,renderText:d,hoverDelayMs:c,closeDelayMs:p=280})=>{const m=h.useId(),[u,g]=h.useState(!1),[f,x]=h.useState(!1),v=h.useRef(null),y=h.useRef(null),_=`bim-et bim-et-${e.kind}${o?" bim-et-nu":""}`,b=e.kind==="work"&&!i,w=t.jsxs(t.Fragment,{children:[b&&t.jsx("span",{className:"bim-et-sr",children:"《"}),d(n),b&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),j=()=>{v.current&&(clearTimeout(v.current),v.current=null)},k=()=>{y.current&&(clearTimeout(y.current),y.current=null)},C=h.useCallback(()=>{j(),k(),g(!1),x(!1),Ft===C&&(Ft=null)},[]);h.useEffect(()=>()=>{j(),k(),Ft===C&&(Ft=null)},[C]);const $=h.useCallback(()=>{Ft&&Ft!==C&&Ft(),Ft=C,g(!0)},[C]),S=h.useCallback(R=>{k(),x(!0),!u&&(j(),R<=0?$():v.current=setTimeout($,R))},[u,$]),M=h.useCallback(()=>{j(),k(),y.current=setTimeout(C,p)},[C,p]),z=!!e.targetId,T=e.targetId,P={className:"bim-et-w","data-active":f?"":void 0,onMouseEnter:()=>S(c),onMouseLeave:M,onBlur:R=>{R.currentTarget.contains(R.relatedTarget)||C()},onKeyDown:R=>{R.key==="Escape"&&u&&(R.stopPropagation(),C())}};return!z||!T?t.jsxs("span",{...P,children:[t.jsx("span",{className:_,children:w}),u&&t.jsx(da,{id:m,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...P,children:[t.jsx("a",{className:_,href:a(T),"data-entity-id":T,"aria-describedby":u?m:void 0,onFocus:()=>S(0),onClick:l?R=>l(T,R):void 0,children:w}),u&&t.jsx(da,{id:m,entityId:T,span:e,loader:s,buildHref:a,onNavigate:l})]})},da=({id:e,entityId:n,span:i,loader:o,buildHref:s,onNavigate:a})=>{const{convert:l,t:d}=te(),c=h.useRef(null),[p,m]=h.useState("start"),[u,g]=h.useState(o&&n?{status:"loading"}:{status:"ready",summary:null});h.useEffect(()=>{if(!o||!n)return;let v=!1;return g({status:"loading"}),df(o.owner,o.load,n).then(y=>{v||g({status:"ready",summary:y})}).catch(()=>{v||g({status:"error"})}),()=>{v=!0}},[o,n]),pf(()=>{const v=c.current;if(!v||typeof window>"u")return;const y=v.getBoundingClientRect(),_=document.documentElement.clientWidth||window.innerWidth;y.right>_-8&&p==="start"&&m("end")},[u,p]);const f=u.status==="ready"?u.summary:null,x=(f==null?void 0:f.title)??i.canonicalName??i.text;return n?t.jsxs("span",{ref:c,id:e,role:"tooltip",className:"bim-et-card","data-align":p,children:[t.jsx("span",{className:"bim-et-card-k",children:l(ca[i.kind])}),x&&t.jsx("span",{className:"bim-et-card-t",children:l(x)}),(f==null?void 0:f.meta)&&t.jsx("span",{className:"bim-et-card-m",children:l(f.meta)}),(f==null?void 0:f.description)&&t.jsx("span",{className:"bim-et-card-d",children:l(f.description)}),u.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:l("載入中…")}),u.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:l("摘要載入失敗")}),t.jsx("a",{className:"bim-et-card-a",href:s(n),onClick:a?v=>a(n,v):void 0,children:d("reader.entityDetail")})]}):t.jsx("span",{ref:c,id:e,role:"tooltip",className:"bim-et-card","data-align":p,children:t.jsx("span",{className:"bim-et-card-k",children:l(ca[i.kind])})})},gf=e=>`/item/${encodeURIComponent(e)}`;function hf(e){const n=e.filter(i=>i.kind!=="break");return{before:n.filter(i=>i.pos==="before"),after:n.filter(i=>i.pos!=="before")}}function ff(e,n){const i=[];for(const o of e){const s=n.get(o.charData.id)??null,a=i[i.length-1];a&&a.entity===s?a.chars.push(o):i.push({entity:s,chars:[o]})}return i}const Po=({pageData:e,pages:n,punctuations:i=bf,selectedCharIds:o,hoveredCharId:s,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:p=!0,onVisiblePageChange:m,convert:u,scrollToPage:g,entities:f,entityTransport:x,loadEntitySummary:v,buildEntityHref:y,onEntityNavigate:_,pageBreaks:b=!0,pageIndicatorY:w,onPageIndicatorYChange:j,quoteStyle:k,bookTitleStyle:C,showWorks:$})=>{const S=h.useRef(null),M=h.useRef(0),z=h.useMemo(()=>{const X=new Map;return p&&i.forEach((re,de)=>{const D=re.id?re:{...re,id:`${re.anchor}#${de}`},K=X.get(D.anchor)||[];K.push(D),X.set(D.anchor,K)}),X},[i,p]),T=h.useMemo(()=>k===void 0&&C===void 0&&$===void 0?null:{quoteStyle:k??"original",hideBookBrackets:C==="wavy"||$===!1},[k,C,$]),P=C==="bracket",R=h.useMemo(()=>(n&&n.length>0?n:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}]).filter(re=>re.columns.some(de=>de.chars.length>0)).map(re=>{const de=[...re.columns].sort((ne,B)=>ne.col-B.col),D=[];let K=[],we=0;for(const ne of de){if(ne.chars.length===0){ne.kind==="blank"&&we++;continue}const B=ne.raised||ne.lead_blank||we?{raised:ne.raised,leadBlank:ne.lead_blank,blankBefore:we}:void 0;we=0;let Z=!0;for(const ae of ne.chars){const{before:je,after:Y}=hf(z.get(ae.id)||[]),be=(z.get(ae.id)||[]).some(Ee=>Ee.kind==="break");K.push({charData:ae,col:ne.col,beforePuncts:je,afterPuncts:Y,...Z&&B?{start:B}:{}}),Z=!1,be&&(D.push({id:`para-p${re.page}-${D.length}`,chars:K}),K=[])}}return K.length>0&&D.push({id:`para-p${re.page}-${D.length}`,chars:K}),{page:re.page,paragraphs:D,...re.label?{label:re.label}:{},...we>0?{trailingBlank:we}:{}}}),[n,e,z]),N=h.useMemo(()=>{const X=[];for(const re of R)for(const de of re.paragraphs)for(const D of de.chars)X.push(D.charData.id);return X},[R]),A=h.useMemo(()=>{const X=new Map;if(!f||f.length===0)return X;const re=new Map(N.map((de,D)=>[de,D]));for(const de of f){if(!de.anchor)continue;const D=re.get(de.anchor.start),K=re.get(de.anchor.end);if(!(D===void 0||K===void 0||K<D))for(let we=D;we<=K;we++)X.has(N[we])||X.set(N[we],de)}return X},[f,N]),H=Ao(x,v),G=A.size>0,ie=h.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:m,onEntityNavigate:_});ie.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:m,onEntityNavigate:_};const le=h.useMemo(()=>({click:X=>{var re,de;M.current=Date.now()+1200,(de=(re=ie.current).onCharClick)==null||de.call(re,X)},enter:X=>{var re,de;return(de=(re=ie.current).onCharHover)==null?void 0:de.call(re,X)},leave:()=>{var X,re;return(re=(X=ie.current).onCharHover)==null?void 0:re.call(X,null)},navigate:(X,re)=>{var D,K;if(!(re.detail===0||re.ctrlKey||re.metaKey||re.shiftKey)){re.preventDefault();return}(K=(D=ie.current).onEntityNavigate)==null||K.call(D,X,re)}}),[]),V=yf(o),F=h.useRef(null);h.useEffect(()=>{var re,de;if((re=F.current)==null||re.classList.remove("is-hovered"),F.current=null,!s)return;const X=(de=S.current)==null?void 0:de.querySelector(`span[data-char-id="${s}"]`);X&&(X.classList.add("is-hovered"),F.current=X)},[s]),h.useEffect(()=>{let X=null;const re=()=>{var Fe,W;X=null;const D=window.getSelection(),K=S.current;if(!D||D.isCollapsed||D.rangeCount===0||!K)return;const we=D.getRangeAt(0),ne=we.commonAncestorContainer,B=ne.nodeType===3?ne.parentElement:ne;if(!B||!K.contains(B))return;const Z=K.querySelectorAll("span[data-char-id]");let ae=0,je=Z.length;for(;ae<je;){const J=ae+je>>1;we.comparePoint(Z[J],0)<0?ae=J+1:je=J}const Y=ae;for(je=Z.length;ae<je;){const J=ae+je>>1;we.comparePoint(Z[J],0)<=0?ae=J+1:je=J}const be=ae-1;if(be<Y)return;const Ee=[];for(let J=Y;J<=be;J++)Ee.push(Z[J].getAttribute("data-char-id"));Ee.length>0&&(M.current=Date.now()+1200,(W=(Fe=ie.current).onSelectionChange)==null||W.call(Fe,Ee))},de=()=>{X&&clearTimeout(X),X=setTimeout(re,120)};return document.addEventListener("selectionchange",de),()=>{document.removeEventListener("selectionchange",de),X&&clearTimeout(X)}},[]),h.useEffect(()=>{var X;if(o.size===1){const re=Array.from(o)[0],de=(X=S.current)==null?void 0:X.querySelector(`span[data-char-id="${re}"]`);de&&de.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}},[o]);const xe=g==null?void 0:g.nonce;h.useEffect(()=>{var re;if(!g)return;const X=(re=S.current)==null?void 0:re.querySelector(`[data-page-section="${g.page}"]`);X&&(M.current=Date.now()+800,X.scrollIntoView({behavior:"auto",block:"start"}))},[xe]);const ee=!!m,L=ee&&typeof w=="number",[Re,ce]=h.useState(null),me=Pr(Re??w??0),se=h.useRef(null);se.current=L?me:null;const Pe=h.useRef(()=>{});return h.useEffect(()=>{var K;if(!ee)return;const X=Array.from(((K=S.current)==null?void 0:K.querySelectorAll("[data-page-section]"))??[]);if(X.length===0)return;let re=0;const de=()=>{var ae,je;if(re=0,Date.now()<M.current)return;const we=se.current===null?120:se.current*window.innerHeight;let ne=0,B=X.length-1;for(;ne<B;){const Y=ne+B+1>>1;X[Y].getBoundingClientRect().top<=we?ne=Y:B=Y-1}const Z=parseInt(X[ne].getAttribute("data-page-section")||"",10);isNaN(Z)||(je=(ae=ie.current).onVisiblePageChange)==null||je.call(ae,Z)},D=()=>{re||(re=requestAnimationFrame(de))};return Pe.current=()=>{re||(re=requestAnimationFrame(de))},window.addEventListener("scroll",D,{passive:!0}),de(),()=>{window.removeEventListener("scroll",D),re&&cancelAnimationFrame(re),Pe.current=()=>{}}},[ee,R]),h.useEffect(()=>{L&&Pe.current()},[L,me]),t.jsxs("div",{ref:S,className:"guji-text-pane-content",children:[G&&t.jsx("style",{children:Lo}),L&&t.jsx(wf,{y:me,containerRef:S,onDrag:ce,onCommit:X=>{ce(null),j==null||j(X)}}),t.jsx("div",{className:"guji-text-reflow-view",children:R.map((X,re)=>t.jsx(vf,{pGroup:X,first:re===0,pageBreaks:b,markOpts:T,plainBooks:P,selected:V.get(X.page)??xf,entityOfChar:A,entityLoader:H,convert:u,buildHref:y??gf,handlers:le},`page-sec-${X.page}`))})]})},xf=new Set,bf=[];function yf(e){const n=h.useRef(new Map);return h.useMemo(()=>{const i=new Map;e.forEach(s=>{const a=parseInt(s.split(":")[0],10);let l=i.get(a);l||i.set(a,l=new Set),l.add(s)});const o=new Map;return i.forEach((s,a)=>{const l=n.current.get(a),d=l&&l.size===s.size&&Array.from(s).every(c=>l.has(c));o.set(a,d?l:s)}),n.current=o,o},[e])}function pa({n:e}){return t.jsx(t.Fragment,{children:Array.from({length:e},(n,i)=>t.jsx("span",{className:"guji-text-blank-col","aria-hidden":"true","data-blank-col":""},i))})}function jf(e,n){const i=Array.from(n(e.join("")));return i.length===e.length&&e.every(o=>Array.from(o).length===1)?i:e.map(o=>n(o))}const vf=h.memo(function({pGroup:n,first:i,pageBreaks:o,markOpts:s,plainBooks:a,selected:l,entityOfChar:d,entityLoader:c,convert:p,buildHref:m,handlers:u}){const g=h.useMemo(()=>{const y=new Map;if(!p)return y;for(const _ of n.paragraphs){const b=jf(_.chars.map(w=>w.charData.char),p);_.chars.forEach((w,j)=>y.set(w.charData.id,b[j]))}return y},[n,p]),f=y=>g.get(y.id)??y.char,{t:x}=te(),v=y=>{const _=s?Nc(y.mark,s):y.mark;return _?t.jsx("span",{className:"guji-text-punct","data-punct-id":y.id,children:_},y.id):null};return t.jsxs("section",{"data-page-section":n.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96},children:[!i&&o&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:r("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:r("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},"data-page-label":n.label,title:n.label?`${n.page}`:void 0,children:["第 ",n.label??n.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:r("rule")}})]}),n.paragraphs.map((y,_)=>t.jsxs("p",{className:"guji-reflow-paragraph",children:[ff(y.chars,d).map((b,w)=>{const j=b.chars.map(({charData:$,beforePuncts:S,afterPuncts:M,start:z},T)=>{const P=!!b.entity&&T===0,R=!!b.entity&&T===b.chars.length-1,N=P?[]:S,A=R?[]:M;return t.jsxs(h.Fragment,{children:[z&&z.blankBefore>0&&t.jsx(pa,{n:z.blankBefore}),z!=null&&z.leadBlank?t.jsx("span",{className:"guji-text-lead-blank","aria-hidden":"true","data-lead-blank":z.leadBlank,style:{width:`${z.leadBlank}em`}}):null,N.map(v),t.jsx("span",{"data-char-id":$.id,onClick:()=>u.click($.id),onMouseEnter:()=>u.enter($.id),onMouseLeave:u.leave,className:`guji-text-char${l.has($.id)?" is-selected":""}${$.sub?" is-sub":""}${$.lane==="solo"?" is-solo":""}${$.lacuna?" is-lacuna":""}${$.guess?" is-guess":""}${$.zi?" is-zi":""}${z!=null&&z.raised?" is-raised":""}`,"data-raised":(z==null?void 0:z.raised)||void 0,title:$.lacuna?x("detail.lacuna"):$.zi?x("detail.composedChar",{label:$.zi}):$.guess?x("reader.charGuess"):void 0,children:f($)}),A.map(v)]},$.id)});if(!b.entity)return t.jsx(h.Fragment,{children:j},`r${w}`);const k=b.chars[0].beforePuncts.map(v),C=b.chars[b.chars.length-1].afterPuncts.map(v);return t.jsxs(h.Fragment,{children:[k,t.jsx(Mo,{span:b.entity,label:b.chars.map($=>f($.charData)).join(""),hasBrackets:!0,plain:a&&b.entity.kind==="work",loader:c,buildHref:m,onNavigate:u.navigate,renderText:()=>j,hoverDelayMs:250}),C]},`${b.entity.key}@${w}`)}),_===n.paragraphs.length-1&&n.trailingBlank?t.jsx(pa,{n:n.trailingBlank}):null]},y.id))]})});function Pr(e){const[n,i]=Pn,o=Number.isFinite(e)?e:.33;return Math.round(Math.min(i,Math.max(n,o))*1e3)/1e3}const kf=.02,ai=16;function wf({y:e,containerRef:n,onDrag:i,onCommit:o}){const{t:s}=te(),[a,l]=h.useState(0),d=h.useRef(!1),c=h.useRef(e);c.current=e;const p=h.useCallback(()=>{var f,x;const g=(x=((f=n.current)==null?void 0:f.querySelector(".guji-text-reflow-view"))??n.current)==null?void 0:x.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-ai-2))},[n]);h.useLayoutEffect(()=>(p(),window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)),[p]);const m=u=>Pr(u/Math.max(1,window.innerHeight));return t.jsx("div",{role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":s("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Pn[0]*100),"aria-valuemax":Math.round(Pn[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${ai/2}px)`,width:ai,height:ai,zIndex:20,cursor:"ns-resize",touchAction:"none",background:r("accent"),clipPath:"polygon(0 0, 100% 50%, 0 100%)",outline:"none"},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const g=m(u.clientY);c.current=g,i(g)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}o(m(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,o(c.current))},onKeyDown:u=>{const g=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;g&&(u.preventDefault(),o(Pr(e+g*(u.shiftKey?5:1)*kf)))}})}const Uc=1,Vc=6,li={s:1,x:0,y:0},mi=(e,n,i)=>Math.min(i,Math.max(n,e));function Bo(e,n,i){const o=mi(e.s,Uc,Vc);return{s:o,x:mi(e.x,n*(1-o),0),y:mi(e.y,i*(1-o),0)}}function pr(e,n,i,o,s,a){const l=mi(e.s*o,Uc,Vc),d=l/e.s;return Bo({s:l,x:n-(n-e.x)*d,y:i-(i-e.y)*d},s,a)}function Sf(e,n,i,o,s){return Bo({s:e.s,x:e.x+n,y:e.y+i},o,s)}function _f(e,n,i){const o=n===1?e*16:n===2?e*400:e;return Math.exp(-o*(i?.01:.0015))}const ua=4,$f=h.forwardRef(function({children:n,onScaleChange:i,resetKey:o,style:s},a){const l=h.useRef(null),[d,c]=h.useState(li),p=h.useRef(d),m=h.useRef(i);m.current=i;const u=b=>{var j;const w=p.current;p.current=b,c(b),b.s!==w.s&&((j=m.current)==null||j.call(m,b.s))},g=()=>{var w;const b=(w=l.current)==null?void 0:w.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}};h.useImperativeHandle(a,()=>({zoomBy(b){const{w,h:j}=g();u(pr(p.current,w/2,j/2,b,w,j))},reset(){u(li)}})),h.useEffect(()=>{u(li)},[o]),h.useEffect(()=>{const b=l.current;if(!b||typeof ResizeObserver>"u")return;const w=new ResizeObserver(()=>{const{w:j,h:k}=g(),C=Bo(p.current,j,k);(C.x!==p.current.x||C.y!==p.current.y)&&u(C)});return w.observe(b),()=>w.disconnect()},[]),h.useEffect(()=>{const b=l.current;if(!b)return;const w=j=>{const k=_f(j.deltaY,j.deltaMode,j.ctrlKey);if(p.current.s<=1&&k<1)return;j.preventDefault();const{w:C,h:$,left:S,top:M}=g();u(pr(p.current,j.clientX-S,j.clientY-M,k,C,$))};return b.addEventListener("wheel",w,{passive:!1}),()=>b.removeEventListener("wheel",w)},[]);const f=h.useRef(new Map),x=h.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),v=b=>{if(b.pointerType==="mouse"&&b.button!==0)return;f.current.set(b.pointerId,{x:b.clientX,y:b.clientY});const w=x.current;if(w.swallowClick=!1,f.current.size===1&&(w.moved=0,w.dragging=!1),f.current.size===2){const[j,k]=[...f.current.values()];w.pinchDist=Math.hypot(j.x-k.x,j.y-k.y),w.moved=ua+1}},y=b=>{var P;const w=f.current.get(b.pointerId);if(!w)return;const j={x:b.clientX,y:b.clientY};f.current.set(b.pointerId,j);const k=x.current,{w:C,h:$,left:S,top:M}=g();if(f.current.size>=2){const[R,N]=[...f.current.values()],A=Math.hypot(R.x-N.x,R.y-N.y);if(k.pinchDist>0&&A>0){const H=(R.x+N.x)/2-S,G=(R.y+N.y)/2-M;u(pr(p.current,H,G,A/k.pinchDist,C,$))}k.pinchDist=A,k.swallowClick=!0;return}const z=j.x-w.x,T=j.y-w.y;if(k.moved+=Math.abs(z)+Math.abs(T),!(k.moved<=ua)){if(!k.dragging){k.dragging=!0;try{(P=l.current)==null||P.setPointerCapture(b.pointerId)}catch{}}k.swallowClick=!0,p.current.s>1&&u(Sf(p.current,z,T,C,$))}},_=b=>{f.current.delete(b.pointerId);const w=x.current;w.pinchDist=0,f.current.size===0&&(w.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:v,onPointerMove:y,onPointerUp:_,onPointerCancel:_,onClickCapture:b=>{x.current.swallowClick&&(x.current.swallowClick=!1,b.stopPropagation(),b.preventDefault())},onDoubleClick:()=>u(li),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,i,o){const[s,a]=h.useState(n??null),[l,d]=h.useState(!1),c=h.useRef(0);return h.useEffect(()=>{if(n!==void 0){a(n);return}const p=++c.current;if(!i){a(null),d(!1);return}if(e){let m;try{m=e(i,o)}catch{a(null),d(!1);return}if(!m||typeof m.then!="function"){a(m??null),d(!1);return}d(!0),m.then(u=>{p===c.current&&a(u??null)}).catch(()=>{p===c.current&&a(null)}).finally(()=>{p===c.current&&d(!1)});return}a(null),d(!1)},[e,n,i,o]),{warpData:s,loading:l}}function Cf(e,n,i){const[o,s]=h.useState([]),a=h.useRef(0);return h.useEffect(()=>{const l=++a.current;if(!e||!n){s([]);return}let d;try{d=e(n,i)}catch{s([]);return}Promise.resolve(d).then(c=>{l===a.current&&s(c?Lc(c):[])}).catch(()=>{l===a.current&&s([])})},[e,n,i]),o}const ma={padding:24,color:r("desc-fg"),fontSize:14};function ga({title:e,label:n,className:i,style:o}){const s=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:r("rule")});return t.jsxs("div",{className:i,style:{...o,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:r("ink"),fontFamily:r("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:r("desc-fg"),fontSize:14,fontFamily:r("font-ui")},children:n})]})}const ha=/^https?:\/\//i;function Tf(e){if(!e||typeof e!="object")return null;const n=a=>typeof a=="string"&&a.trim()?a.trim():void 0,i=n(e.url),o=n(e.license_url),s={name:n(e.name),url:i&&ha.test(i)?i:void 0,license:n(e.license),license_url:o&&ha.test(o)?o:void 0,note:n(e.note)};return s.name||s.license||s.note?s:null}function zf(e,n){return{work_id:n.work_id??e,title:n.title,type:n.type,juan_files:n.chapters.map(i=>i.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 Nf(e,n){return(n==null?void 0:n.type)==="kaozhen"?"章":n!=null&&n.juan_metadata&&Object.values(n.juan_metadata).some(i=>i.vol_label)?"冊":_e.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function Yc(e,n,i,o=!1){const s=i(`${n}${e.n}`);if(!e.title)return s;const a=i(e.title);return o&&!/^[卷冊册章篇回第]/.test(e.title)?`${s} ${a}`:a}function If(e,n,i,o,s){var p;const a=new Map(e.chapters.map(m=>[m.file,m])),l=m=>m==="loading"?"…":typeof m=="number"&&m>0?m:void 0,d=(m,u)=>{const g=a.get(m);return{key:m,label:u??(g?Yc(g,i,o,s):m),hint:l(n[m]),disabled:n[m]===0}},c=(p=e.juan_groups)==null?void 0:p.filter(m=>{var u;return m.files.some(g=>a.has(g))||((u=m.children)==null?void 0:u.length)});if(c&&c.length>0){const m=(u,g)=>{var x;if(u.files.length===1&&!((x=u.children)!=null&&x.length))return d(u.files[0],o(u.label));const f=Fh(u,n);return{key:`group:${g}`,label:o(u.label),hint:f==="loading"?"…":typeof f=="number"&&f>0?`${f}`:Bc(u),defaultExpanded:typeof f=="number"&&f>0,children:[...u.files.filter(v=>a.has(v)).map(v=>d(v)),...(u.children??[]).map((v,y)=>m(v,`${g}.${y}`))]}};return c.map((u,g)=>m(u,`${g}`))}return e.chapters.map(m=>d(m.file))}const Wo=e=>{const n=Dl();return t.jsx(yu,{mode:n[0].scriptMode,children:t.jsx(Rf,{...e,prefsState:n})})},Rf=({prefsState:e,id:n,transport:i,versionKey:o,chapter:s,onLocationChange:a,onNavigate:l,title:d,subtitle:c,resolveImages:p,renderImageOverlay:m,imagePanel:u,allowVertical:g,onReportError:f,revisedAt:x,backHref:v,backLabel:y,resolveWarpData:_,warpData:b,resolveEntities:w,onEntityNavigate:j,className:k,style:C})=>{var cs,ds,ps;const{t:$,convert:S}=te(),M=h.useMemo(()=>El(i),[i]),[z,T]=e,P=tt(),R=h.useRef(a);R.current=a;const[N,A]=h.useState(null),[H,G]=h.useState("loading");h.useEffect(()=>{let E=!1;return A(null),G("loading"),M.getManifest(n).then(pe=>{E||(pe?(A(pe),G("ready")):G("missing"))}).catch(()=>{E||G("missing")}),()=>{E=!0}},[M,n]);const ie=o!==void 0,le=s!==void 0,[V,F]=h.useState(null),[xe,ee]=h.useState(null);h.useEffect(()=>{F(null),ee(null)},[n]);const L=_e.pickTextVersion(N,ie?o:V),Re=((cs=N==null?void 0:N.versions.find(E=>E.key==="default"))==null?void 0:cs.key)??((ds=N==null?void 0:N.versions[0])==null?void 0:ds.key)??"default",ce=(L==null?void 0:L.key)??null,me=le?s:xe,se=h.useCallback((E,pe,ze)=>{var De;(De=R.current)==null||De.call(R,{key:E,chapter:pe,isDefault:E===Re},ze)},[Re]);h.useEffect(()=>{!N||!ie||o==null||N.versions.some(E=>E.key===o)||se(Re,null,"auto")},[N,ie,o,Re,se]);const Pe=h.useRef(new Map);h.useEffect(()=>{Pe.current.clear()},[M,n]);const X=h.useCallback(async E=>{const pe=`${n}
1343
+ `,sf=120;function gt(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function af(e,n=sf){if(!e)return;const i=e.replace(/\s+/g," ").trim(),o=Array.from(i);return o.length>n?o.slice(0,n).join("")+"…":i}function lf(e){const n=typeof e.birth_year=="number"?e.birth_year:void 0,i=typeof e.death_year=="number"?e.death_year:void 0;if(!(n===void 0&&i===void 0))return`${n??"?"}–${i??"?"}`}function cf(e){if(!Array.isArray(e.authors))return;const n=e.authors.map(i=>{if(!i||typeof i!="object")return"";const o=i,s=gt(o.name);return s?[gt(o.dynasty)&&`〔${gt(o.dynasty)}〕`,s,gt(o.role)].filter(Boolean).join(""):""}).filter(Boolean);return n.length?n.slice(0,3).join("、"):void 0}function Oc(e,n){const i=gt(n.type),o=gt(n.primary_name)??gt(n.title)??e,s=i==="entity"?[gt(n.dynasty),lf(n),gt(n.native_place)].filter(Boolean).join(" · "):[cf(n),gt(n.edition),gt(n.measure_info)].filter(Boolean).join(" · "),a=n.description&&typeof n.description=="object"?gt(n.description.text):gt(n.description);return{id:e,type:i,title:o,meta:s||void 0,description:af(a)}}function Fc(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 Hc(e){return async n=>{const i=await e.getItem(n);if(i)return Oc(n,i);if(e.getEntry){const o=await e.getEntry(n);if(o)return Fc(o)}return null}}const la=new WeakMap;function df(e,n,i){let o=la.get(e);o||(o=new Map,la.set(e,o));const s=o.get(i);if(s)return s;const a=n(i);return o.set(i,a),a.catch(()=>o.delete(i)),a}const Dc=e=>`/item/${encodeURIComponent(e)}`,ca={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},pf=typeof window>"u"?h.useEffect:h.useLayoutEffect;function Ao(e,n){return h.useMemo(()=>n?{owner:n,load:n}:e?{owner:e,load:Hc(e)}:null,[n,e])}const uf=e=>e,mf=({text:e,entities:n,offsets:i="text",plainBase:o=0,transport:s,loadSummary:a,buildHref:l=Dc,onNavigate:d,renderText:c=uf,hoverDelayMs:p=250,closeDelayMs:m,injectStyles:u=!0,className:g})=>{const f=h.useMemo(()=>{const v=i==="plain"?Ac(e,n,o):n;return Mc(e,v)},[e,n,i,o]),x=Ao(s,a);return t.jsxs("span",{className:g?`bim-et-root ${g}`:"bim-et-root",children:[u&&t.jsx("style",{children:Lo}),f.map(v=>v.type==="text"?t.jsx(h.Fragment,{children:c(v.text)},`t${v.start}`):t.jsx(Mo,{span:v.span,label:v.text,hasBrackets:e[v.start-1]==="《"&&e[v.start+v.text.length]==="》",loader:x,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:p,closeDelayMs:m},`${v.span.key}@${v.start}`))]})};let Ft=null;const Mo=({span:e,label:n,hasBrackets:i,plain:o,loader:s,buildHref:a,onNavigate:l,renderText:d,hoverDelayMs:c,closeDelayMs:p=280})=>{const m=h.useId(),[u,g]=h.useState(!1),[f,x]=h.useState(!1),v=h.useRef(null),y=h.useRef(null),_=`bim-et bim-et-${e.kind}${o?" bim-et-nu":""}`,b=e.kind==="work"&&!i,w=t.jsxs(t.Fragment,{children:[b&&t.jsx("span",{className:"bim-et-sr",children:"《"}),d(n),b&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),j=()=>{v.current&&(clearTimeout(v.current),v.current=null)},k=()=>{y.current&&(clearTimeout(y.current),y.current=null)},C=h.useCallback(()=>{j(),k(),g(!1),x(!1),Ft===C&&(Ft=null)},[]);h.useEffect(()=>()=>{j(),k(),Ft===C&&(Ft=null)},[C]);const $=h.useCallback(()=>{Ft&&Ft!==C&&Ft(),Ft=C,g(!0)},[C]),S=h.useCallback(R=>{k(),x(!0),!u&&(j(),R<=0?$():v.current=setTimeout($,R))},[u,$]),M=h.useCallback(()=>{j(),k(),y.current=setTimeout(C,p)},[C,p]),z=!!e.targetId,T=e.targetId,P={className:"bim-et-w","data-active":f?"":void 0,onMouseEnter:()=>S(c),onMouseLeave:M,onBlur:R=>{R.currentTarget.contains(R.relatedTarget)||C()},onKeyDown:R=>{R.key==="Escape"&&u&&(R.stopPropagation(),C())}};return!z||!T?t.jsxs("span",{...P,children:[t.jsx("span",{className:_,children:w}),u&&t.jsx(da,{id:m,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...P,children:[t.jsx("a",{className:_,href:a(T),"data-entity-id":T,"aria-describedby":u?m:void 0,onFocus:()=>S(0),onClick:l?R=>l(T,R):void 0,children:w}),u&&t.jsx(da,{id:m,entityId:T,span:e,loader:s,buildHref:a,onNavigate:l})]})},da=({id:e,entityId:n,span:i,loader:o,buildHref:s,onNavigate:a})=>{const{convert:l,t:d}=te(),c=h.useRef(null),[p,m]=h.useState("start"),[u,g]=h.useState(o&&n?{status:"loading"}:{status:"ready",summary:null});h.useEffect(()=>{if(!o||!n)return;let v=!1;return g({status:"loading"}),df(o.owner,o.load,n).then(y=>{v||g({status:"ready",summary:y})}).catch(()=>{v||g({status:"error"})}),()=>{v=!0}},[o,n]),pf(()=>{const v=c.current;if(!v||typeof window>"u")return;const y=v.getBoundingClientRect(),_=document.documentElement.clientWidth||window.innerWidth;y.right>_-8&&p==="start"&&m("end")},[u,p]);const f=u.status==="ready"?u.summary:null,x=(f==null?void 0:f.title)??i.canonicalName??i.text;return n?t.jsxs("span",{ref:c,id:e,role:"tooltip",className:"bim-et-card","data-align":p,children:[t.jsx("span",{className:"bim-et-card-k",children:l(ca[i.kind])}),x&&t.jsx("span",{className:"bim-et-card-t",children:l(x)}),(f==null?void 0:f.meta)&&t.jsx("span",{className:"bim-et-card-m",children:l(f.meta)}),(f==null?void 0:f.description)&&t.jsx("span",{className:"bim-et-card-d",children:l(f.description)}),u.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:l("載入中…")}),u.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:l("摘要載入失敗")}),t.jsx("a",{className:"bim-et-card-a",href:s(n),onClick:a?v=>a(n,v):void 0,children:d("reader.entityDetail")})]}):t.jsx("span",{ref:c,id:e,role:"tooltip",className:"bim-et-card","data-align":p,children:t.jsx("span",{className:"bim-et-card-k",children:l(ca[i.kind])})})},gf=e=>`/item/${encodeURIComponent(e)}`;function hf(e){const n=e.filter(i=>i.kind!=="break");return{before:n.filter(i=>i.pos==="before"),after:n.filter(i=>i.pos!=="before")}}function ff(e,n){const i=[];for(const o of e){const s=n.get(o.charData.id)??null,a=i[i.length-1];a&&a.entity===s?a.chars.push(o):i.push({entity:s,chars:[o]})}return i}const Po=({pageData:e,pages:n,punctuations:i=bf,selectedCharIds:o,hoveredCharId:s,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:p=!0,onVisiblePageChange:m,convert:u,scrollToPage:g,entities:f,entityTransport:x,loadEntitySummary:v,buildEntityHref:y,onEntityNavigate:_,pageBreaks:b=!0,pageIndicatorY:w,onPageIndicatorYChange:j,quoteStyle:k,bookTitleStyle:C,showWorks:$})=>{const S=h.useRef(null),M=h.useRef(0),z=h.useMemo(()=>{const X=new Map;return p&&i.forEach((re,de)=>{const D=re.id?re:{...re,id:`${re.anchor}#${de}`},K=X.get(D.anchor)||[];K.push(D),X.set(D.anchor,K)}),X},[i,p]),T=h.useMemo(()=>k===void 0&&C===void 0&&$===void 0?null:{quoteStyle:k??"original",hideBookBrackets:C==="wavy"||$===!1},[k,C,$]),P=C==="bracket",R=h.useMemo(()=>(n&&n.length>0?n:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}]).filter(re=>re.columns.some(de=>de.chars.length>0)).map(re=>{const de=[...re.columns].sort((ne,B)=>ne.col-B.col),D=[];let K=[],we=0;for(const ne of de){if(ne.chars.length===0){ne.kind==="blank"&&we++;continue}const B=ne.raised||ne.lead_blank||we?{raised:ne.raised,leadBlank:ne.lead_blank,blankBefore:we}:void 0;we=0;let Z=!0;for(const ae of ne.chars){const{before:je,after:Y}=hf(z.get(ae.id)||[]),be=(z.get(ae.id)||[]).some(Ee=>Ee.kind==="break");K.push({charData:ae,col:ne.col,beforePuncts:je,afterPuncts:Y,...Z&&B?{start:B}:{}}),Z=!1,be&&(D.push({id:`para-p${re.page}-${D.length}`,chars:K}),K=[])}}return K.length>0&&D.push({id:`para-p${re.page}-${D.length}`,chars:K}),{page:re.page,paragraphs:D,...re.label?{label:re.label}:{},...we>0?{trailingBlank:we}:{}}}),[n,e,z]),N=h.useMemo(()=>{const X=[];for(const re of R)for(const de of re.paragraphs)for(const D of de.chars)X.push(D.charData.id);return X},[R]),A=h.useMemo(()=>{const X=new Map;if(!f||f.length===0)return X;const re=new Map(N.map((de,D)=>[de,D]));for(const de of f){if(!de.anchor)continue;const D=re.get(de.anchor.start),K=re.get(de.anchor.end);if(!(D===void 0||K===void 0||K<D))for(let we=D;we<=K;we++)X.has(N[we])||X.set(N[we],de)}return X},[f,N]),H=Ao(x,v),G=A.size>0,ie=h.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:m,onEntityNavigate:_});ie.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:m,onEntityNavigate:_};const le=h.useMemo(()=>({click:X=>{var re,de;M.current=Date.now()+1200,(de=(re=ie.current).onCharClick)==null||de.call(re,X)},enter:X=>{var re,de;return(de=(re=ie.current).onCharHover)==null?void 0:de.call(re,X)},leave:()=>{var X,re;return(re=(X=ie.current).onCharHover)==null?void 0:re.call(X,null)},navigate:(X,re)=>{var D,K;if(!(re.detail===0||re.ctrlKey||re.metaKey||re.shiftKey)){re.preventDefault();return}(K=(D=ie.current).onEntityNavigate)==null||K.call(D,X,re)}}),[]),V=yf(o),F=h.useRef(null);h.useEffect(()=>{var re,de;if((re=F.current)==null||re.classList.remove("is-hovered"),F.current=null,!s)return;const X=(de=S.current)==null?void 0:de.querySelector(`span[data-char-id="${s}"]`);X&&(X.classList.add("is-hovered"),F.current=X)},[s]),h.useEffect(()=>{let X=null;const re=()=>{var Fe,W;X=null;const D=window.getSelection(),K=S.current;if(!D||D.isCollapsed||D.rangeCount===0||!K)return;const we=D.getRangeAt(0),ne=we.commonAncestorContainer,B=ne.nodeType===3?ne.parentElement:ne;if(!B||!K.contains(B))return;const Z=K.querySelectorAll("span[data-char-id]");let ae=0,je=Z.length;for(;ae<je;){const J=ae+je>>1;we.comparePoint(Z[J],0)<0?ae=J+1:je=J}const Y=ae;for(je=Z.length;ae<je;){const J=ae+je>>1;we.comparePoint(Z[J],0)<=0?ae=J+1:je=J}const be=ae-1;if(be<Y)return;const Ee=[];for(let J=Y;J<=be;J++)Ee.push(Z[J].getAttribute("data-char-id"));Ee.length>0&&(M.current=Date.now()+1200,(W=(Fe=ie.current).onSelectionChange)==null||W.call(Fe,Ee))},de=()=>{X&&clearTimeout(X),X=setTimeout(re,120)};return document.addEventListener("selectionchange",de),()=>{document.removeEventListener("selectionchange",de),X&&clearTimeout(X)}},[]),h.useEffect(()=>{var X;if(o.size===1){const re=Array.from(o)[0],de=(X=S.current)==null?void 0:X.querySelector(`span[data-char-id="${re}"]`);de&&de.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}},[o]);const xe=g==null?void 0:g.nonce;h.useEffect(()=>{var re;if(!g)return;const X=(re=S.current)==null?void 0:re.querySelector(`[data-page-section="${g.page}"]`);X&&(M.current=Date.now()+800,X.scrollIntoView({behavior:"auto",block:"start"}))},[xe]);const ee=!!m,L=ee&&typeof w=="number",[Re,ce]=h.useState(null),me=Pr(Re??w??0),se=h.useRef(null);se.current=L?me:null;const Pe=h.useRef(()=>{});return h.useEffect(()=>{var K;if(!ee)return;const X=Array.from(((K=S.current)==null?void 0:K.querySelectorAll("[data-page-section]"))??[]);if(X.length===0)return;let re=0;const de=()=>{var ae,je;if(re=0,Date.now()<M.current)return;const we=se.current===null?120:se.current*window.innerHeight;let ne=0,B=X.length-1;for(;ne<B;){const Y=ne+B+1>>1;X[Y].getBoundingClientRect().top<=we?ne=Y:B=Y-1}const Z=parseInt(X[ne].getAttribute("data-page-section")||"",10);isNaN(Z)||(je=(ae=ie.current).onVisiblePageChange)==null||je.call(ae,Z)},D=()=>{re||(re=requestAnimationFrame(de))};return Pe.current=()=>{re||(re=requestAnimationFrame(de))},window.addEventListener("scroll",D,{passive:!0}),de(),()=>{window.removeEventListener("scroll",D),re&&cancelAnimationFrame(re),Pe.current=()=>{}}},[ee,R]),h.useEffect(()=>{L&&Pe.current()},[L,me]),t.jsxs("div",{ref:S,className:"guji-text-pane-content",children:[G&&t.jsx("style",{children:Lo}),L&&t.jsx(wf,{y:me,containerRef:S,onDrag:ce,onCommit:X=>{ce(null),j==null||j(X)}}),t.jsx("div",{className:"guji-text-reflow-view",children:R.map((X,re)=>t.jsx(vf,{pGroup:X,first:re===0,pageBreaks:b,markOpts:T,plainBooks:P,selected:V.get(X.page)??xf,entityOfChar:A,entityLoader:H,convert:u,buildHref:y??gf,handlers:le},`page-sec-${X.page}`))})]})},xf=new Set,bf=[];function yf(e){const n=h.useRef(new Map);return h.useMemo(()=>{const i=new Map;e.forEach(s=>{const a=parseInt(s.split(":")[0],10);let l=i.get(a);l||i.set(a,l=new Set),l.add(s)});const o=new Map;return i.forEach((s,a)=>{const l=n.current.get(a),d=l&&l.size===s.size&&Array.from(s).every(c=>l.has(c));o.set(a,d?l:s)}),n.current=o,o},[e])}function pa({n:e}){return t.jsx(t.Fragment,{children:Array.from({length:e},(n,i)=>t.jsx("span",{className:"guji-text-blank-col","aria-hidden":"true","data-blank-col":""},i))})}function jf(e,n){const i=Array.from(n(e.join("")));return i.length===e.length&&e.every(o=>Array.from(o).length===1)?i:e.map(o=>n(o))}const vf=h.memo(function({pGroup:n,first:i,pageBreaks:o,markOpts:s,plainBooks:a,selected:l,entityOfChar:d,entityLoader:c,convert:p,buildHref:m,handlers:u}){const g=h.useMemo(()=>{const y=new Map;if(!p)return y;for(const _ of n.paragraphs){const b=jf(_.chars.map(w=>w.charData.char),p);_.chars.forEach((w,j)=>y.set(w.charData.id,b[j]))}return y},[n,p]),f=y=>g.get(y.id)??y.char,{t:x}=te(),v=y=>{const _=s?Nc(y.mark,s):y.mark;return _?t.jsx("span",{className:"guji-text-punct","data-punct-id":y.id,children:_},y.id):null};return t.jsxs("section",{"data-page-section":n.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96},children:[!i&&o&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:r("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:r("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},"data-page-label":n.label,title:n.label?`${n.page}`:void 0,children:["第 ",n.label??n.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:r("rule")}})]}),n.paragraphs.map((y,_)=>t.jsxs("p",{className:"guji-reflow-paragraph",children:[ff(y.chars,d).map((b,w)=>{const j=b.chars.map(({charData:$,beforePuncts:S,afterPuncts:M,start:z},T)=>{const P=!!b.entity&&T===0,R=!!b.entity&&T===b.chars.length-1,N=P?[]:S,A=R?[]:M;return t.jsxs(h.Fragment,{children:[z&&z.blankBefore>0&&t.jsx(pa,{n:z.blankBefore}),N.map(v),t.jsx("span",{"data-char-id":$.id,onClick:()=>u.click($.id),onMouseEnter:()=>u.enter($.id),onMouseLeave:u.leave,className:`guji-text-char${l.has($.id)?" is-selected":""}${$.sub?" is-sub":""}${$.lane==="solo"?" is-solo":""}${$.lacuna?" is-lacuna":""}${$.guess?" is-guess":""}${$.zi?" is-zi":""}${z!=null&&z.raised?" is-raised":""}`,"data-raised":(z==null?void 0:z.raised)||void 0,title:$.lacuna?x("detail.lacuna"):$.zi?x("detail.composedChar",{label:$.zi}):$.guess?x("reader.charGuess"):void 0,children:f($)}),A.map(v)]},$.id)});if(!b.entity)return t.jsx(h.Fragment,{children:j},`r${w}`);const k=b.chars[0].beforePuncts.map(v),C=b.chars[b.chars.length-1].afterPuncts.map(v);return t.jsxs(h.Fragment,{children:[k,t.jsx(Mo,{span:b.entity,label:b.chars.map($=>f($.charData)).join(""),hasBrackets:!0,plain:a&&b.entity.kind==="work",loader:c,buildHref:m,onNavigate:u.navigate,renderText:()=>j,hoverDelayMs:250}),C]},`${b.entity.key}@${w}`)}),_===n.paragraphs.length-1&&n.trailingBlank?t.jsx(pa,{n:n.trailingBlank}):null]},y.id))]})});function Pr(e){const[n,i]=Pn,o=Number.isFinite(e)?e:.33;return Math.round(Math.min(i,Math.max(n,o))*1e3)/1e3}const kf=.02,ai=16;function wf({y:e,containerRef:n,onDrag:i,onCommit:o}){const{t:s}=te(),[a,l]=h.useState(0),d=h.useRef(!1),c=h.useRef(e);c.current=e;const p=h.useCallback(()=>{var f,x;const g=(x=((f=n.current)==null?void 0:f.querySelector(".guji-text-reflow-view"))??n.current)==null?void 0:x.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-ai-2))},[n]);h.useLayoutEffect(()=>(p(),window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)),[p]);const m=u=>Pr(u/Math.max(1,window.innerHeight));return t.jsx("div",{role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":s("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Pn[0]*100),"aria-valuemax":Math.round(Pn[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${ai/2}px)`,width:ai,height:ai,zIndex:20,cursor:"ns-resize",touchAction:"none",background:r("accent"),clipPath:"polygon(0 0, 100% 50%, 0 100%)",outline:"none"},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const g=m(u.clientY);c.current=g,i(g)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}o(m(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,o(c.current))},onKeyDown:u=>{const g=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;g&&(u.preventDefault(),o(Pr(e+g*(u.shiftKey?5:1)*kf)))}})}const Uc=1,Vc=6,li={s:1,x:0,y:0},mi=(e,n,i)=>Math.min(i,Math.max(n,e));function Bo(e,n,i){const o=mi(e.s,Uc,Vc);return{s:o,x:mi(e.x,n*(1-o),0),y:mi(e.y,i*(1-o),0)}}function pr(e,n,i,o,s,a){const l=mi(e.s*o,Uc,Vc),d=l/e.s;return Bo({s:l,x:n-(n-e.x)*d,y:i-(i-e.y)*d},s,a)}function Sf(e,n,i,o,s){return Bo({s:e.s,x:e.x+n,y:e.y+i},o,s)}function _f(e,n,i){const o=n===1?e*16:n===2?e*400:e;return Math.exp(-o*(i?.01:.0015))}const ua=4,$f=h.forwardRef(function({children:n,onScaleChange:i,resetKey:o,style:s},a){const l=h.useRef(null),[d,c]=h.useState(li),p=h.useRef(d),m=h.useRef(i);m.current=i;const u=b=>{var j;const w=p.current;p.current=b,c(b),b.s!==w.s&&((j=m.current)==null||j.call(m,b.s))},g=()=>{var w;const b=(w=l.current)==null?void 0:w.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}};h.useImperativeHandle(a,()=>({zoomBy(b){const{w,h:j}=g();u(pr(p.current,w/2,j/2,b,w,j))},reset(){u(li)}})),h.useEffect(()=>{u(li)},[o]),h.useEffect(()=>{const b=l.current;if(!b||typeof ResizeObserver>"u")return;const w=new ResizeObserver(()=>{const{w:j,h:k}=g(),C=Bo(p.current,j,k);(C.x!==p.current.x||C.y!==p.current.y)&&u(C)});return w.observe(b),()=>w.disconnect()},[]),h.useEffect(()=>{const b=l.current;if(!b)return;const w=j=>{const k=_f(j.deltaY,j.deltaMode,j.ctrlKey);if(p.current.s<=1&&k<1)return;j.preventDefault();const{w:C,h:$,left:S,top:M}=g();u(pr(p.current,j.clientX-S,j.clientY-M,k,C,$))};return b.addEventListener("wheel",w,{passive:!1}),()=>b.removeEventListener("wheel",w)},[]);const f=h.useRef(new Map),x=h.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),v=b=>{if(b.pointerType==="mouse"&&b.button!==0)return;f.current.set(b.pointerId,{x:b.clientX,y:b.clientY});const w=x.current;if(w.swallowClick=!1,f.current.size===1&&(w.moved=0,w.dragging=!1),f.current.size===2){const[j,k]=[...f.current.values()];w.pinchDist=Math.hypot(j.x-k.x,j.y-k.y),w.moved=ua+1}},y=b=>{var P;const w=f.current.get(b.pointerId);if(!w)return;const j={x:b.clientX,y:b.clientY};f.current.set(b.pointerId,j);const k=x.current,{w:C,h:$,left:S,top:M}=g();if(f.current.size>=2){const[R,N]=[...f.current.values()],A=Math.hypot(R.x-N.x,R.y-N.y);if(k.pinchDist>0&&A>0){const H=(R.x+N.x)/2-S,G=(R.y+N.y)/2-M;u(pr(p.current,H,G,A/k.pinchDist,C,$))}k.pinchDist=A,k.swallowClick=!0;return}const z=j.x-w.x,T=j.y-w.y;if(k.moved+=Math.abs(z)+Math.abs(T),!(k.moved<=ua)){if(!k.dragging){k.dragging=!0;try{(P=l.current)==null||P.setPointerCapture(b.pointerId)}catch{}}k.swallowClick=!0,p.current.s>1&&u(Sf(p.current,z,T,C,$))}},_=b=>{f.current.delete(b.pointerId);const w=x.current;w.pinchDist=0,f.current.size===0&&(w.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:v,onPointerMove:y,onPointerUp:_,onPointerCancel:_,onClickCapture:b=>{x.current.swallowClick&&(x.current.swallowClick=!1,b.stopPropagation(),b.preventDefault())},onDoubleClick:()=>u(li),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,i,o){const[s,a]=h.useState(n??null),[l,d]=h.useState(!1),c=h.useRef(0);return h.useEffect(()=>{if(n!==void 0){a(n);return}const p=++c.current;if(!i){a(null),d(!1);return}if(e){let m;try{m=e(i,o)}catch{a(null),d(!1);return}if(!m||typeof m.then!="function"){a(m??null),d(!1);return}d(!0),m.then(u=>{p===c.current&&a(u??null)}).catch(()=>{p===c.current&&a(null)}).finally(()=>{p===c.current&&d(!1)});return}a(null),d(!1)},[e,n,i,o]),{warpData:s,loading:l}}function Cf(e,n,i){const[o,s]=h.useState([]),a=h.useRef(0);return h.useEffect(()=>{const l=++a.current;if(!e||!n){s([]);return}let d;try{d=e(n,i)}catch{s([]);return}Promise.resolve(d).then(c=>{l===a.current&&s(c?Lc(c):[])}).catch(()=>{l===a.current&&s([])})},[e,n,i]),o}const ma={padding:24,color:r("desc-fg"),fontSize:14};function ga({title:e,label:n,className:i,style:o}){const s=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:r("rule")});return t.jsxs("div",{className:i,style:{...o,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:r("ink"),fontFamily:r("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:r("desc-fg"),fontSize:14,fontFamily:r("font-ui")},children:n})]})}const ha=/^https?:\/\//i;function Tf(e){if(!e||typeof e!="object")return null;const n=a=>typeof a=="string"&&a.trim()?a.trim():void 0,i=n(e.url),o=n(e.license_url),s={name:n(e.name),url:i&&ha.test(i)?i:void 0,license:n(e.license),license_url:o&&ha.test(o)?o:void 0,note:n(e.note)};return s.name||s.license||s.note?s:null}function zf(e,n){return{work_id:n.work_id??e,title:n.title,type:n.type,juan_files:n.chapters.map(i=>i.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 Nf(e,n){return(n==null?void 0:n.type)==="kaozhen"?"章":n!=null&&n.juan_metadata&&Object.values(n.juan_metadata).some(i=>i.vol_label)?"冊":_e.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function Yc(e,n,i,o=!1){const s=i(`${n}${e.n}`);if(!e.title)return s;const a=i(e.title);return o&&!/^[卷冊册章篇回第]/.test(e.title)?`${s} ${a}`:a}function If(e,n,i,o,s){var p;const a=new Map(e.chapters.map(m=>[m.file,m])),l=m=>m==="loading"?"…":typeof m=="number"&&m>0?m:void 0,d=(m,u)=>{const g=a.get(m);return{key:m,label:u??(g?Yc(g,i,o,s):m),hint:l(n[m]),disabled:n[m]===0}},c=(p=e.juan_groups)==null?void 0:p.filter(m=>{var u;return m.files.some(g=>a.has(g))||((u=m.children)==null?void 0:u.length)});if(c&&c.length>0){const m=(u,g)=>{var x;if(u.files.length===1&&!((x=u.children)!=null&&x.length))return d(u.files[0],o(u.label));const f=Fh(u,n);return{key:`group:${g}`,label:o(u.label),hint:f==="loading"?"…":typeof f=="number"&&f>0?`${f}`:Bc(u),defaultExpanded:typeof f=="number"&&f>0,children:[...u.files.filter(v=>a.has(v)).map(v=>d(v)),...(u.children??[]).map((v,y)=>m(v,`${g}.${y}`))]}};return c.map((u,g)=>m(u,`${g}`))}return e.chapters.map(m=>d(m.file))}const Wo=e=>{const n=Dl();return t.jsx(yu,{mode:n[0].scriptMode,children:t.jsx(Rf,{...e,prefsState:n})})},Rf=({prefsState:e,id:n,transport:i,versionKey:o,chapter:s,onLocationChange:a,onNavigate:l,title:d,subtitle:c,resolveImages:p,renderImageOverlay:m,imagePanel:u,allowVertical:g,onReportError:f,revisedAt:x,backHref:v,backLabel:y,resolveWarpData:_,warpData:b,resolveEntities:w,onEntityNavigate:j,className:k,style:C})=>{var cs,ds,ps;const{t:$,convert:S}=te(),M=h.useMemo(()=>El(i),[i]),[z,T]=e,P=tt(),R=h.useRef(a);R.current=a;const[N,A]=h.useState(null),[H,G]=h.useState("loading");h.useEffect(()=>{let E=!1;return A(null),G("loading"),M.getManifest(n).then(pe=>{E||(pe?(A(pe),G("ready")):G("missing"))}).catch(()=>{E||G("missing")}),()=>{E=!0}},[M,n]);const ie=o!==void 0,le=s!==void 0,[V,F]=h.useState(null),[xe,ee]=h.useState(null);h.useEffect(()=>{F(null),ee(null)},[n]);const L=_e.pickTextVersion(N,ie?o:V),Re=((cs=N==null?void 0:N.versions.find(E=>E.key==="default"))==null?void 0:cs.key)??((ds=N==null?void 0:N.versions[0])==null?void 0:ds.key)??"default",ce=(L==null?void 0:L.key)??null,me=le?s:xe,se=h.useCallback((E,pe,ze)=>{var De;(De=R.current)==null||De.call(R,{key:E,chapter:pe,isDefault:E===Re},ze)},[Re]);h.useEffect(()=>{!N||!ie||o==null||N.versions.some(E=>E.key===o)||se(Re,null,"auto")},[N,ie,o,Re,se]);const Pe=h.useRef(new Map);h.useEffect(()=>{Pe.current.clear()},[M,n]);const X=h.useCallback(async E=>{const pe=`${n}
1345
1344
  ${E}`;if(Pe.current.has(pe))return Pe.current.get(pe)??null;const ze=await M.getIndex(n,E).catch(()=>null);return ze&&Pe.current.set(pe,ze),ze},[M,n]),[re,de]=h.useState(null),[D,K]=h.useState("loading"),we=ce?`${n}
1346
1345
  ${ce}`:null,ne=re&&re.owner===we?re.idx:null;h.useEffect(()=>{if(!ce)return;let E=!1;const pe=`${n}
1347
1346
  ${ce}`;return de(null),K("loading"),X(ce).then(ze=>{E||(ze&&ze.chapters.length>0?(de({owner:pe,idx:ze}),K("ready")):K("failed"))}),()=>{E=!0}},[n,ce,X]),h.useEffect(()=>{if(!ne||!ce||me!=null&&ne.chapters.some(ze=>ze.file===me))return;const pe=ne.chapters[0].file;le||ee(pe),se(ce,pe,"auto")},[ne,ce,me,le,se]);const B=ne?me!=null&&ne.chapters.some(E=>E.file===me)?me:ne.chapters[0].file:me,Z=h.useMemo(()=>ne&&B?ne.chapters.find(E=>E.file===B)??null:null,[ne,B]),ae=h.useRef(0),je=h.useCallback(async E=>{if(!N||E===ce||!N.versions.some(vt=>vt.key===E))return;const pe=++ae.current,ze=await X(E);if(pe!==ae.current)return;const De=Z??(B?{file:B}:null),Je=_e.matchChapterAcrossVersions(De,ze);ie||F(E),le||ee(Je),se(E,Je,"version")},[N,ce,X,Z,B,ie,le,se]),Y=h.useCallback(E=>{ce&&(le||ee(E),se(ce,E,"chapter"))},[ce,le,se]),[be,Ee]=h.useState(null),Fe=ce&&Z?`${n}
@@ -1351,7 +1350,7 @@ ${ce}
1351
1350
  ${Z.file}`;Ee(null),M.getChapter(n,ce,Z.file,{json:!!Z.has_json}).then(ze=>{E===Te.current&&Ee(ze)}).catch(()=>{E===Te.current&&Ee(null)}).finally(()=>{E===Te.current&&J(pe)})},[M,n,ce,Z]);const O=_e.isCollatedKind(L==null?void 0:L.kind),[fe,oe]=h.useState("");h.useEffect(()=>{oe("")},[n,ce]);const Se=h.useMemo(()=>ce&&O?async E=>{const pe=await M.getChapter(n,ce,E,{json:!0});return{juan:(pe==null?void 0:pe.json)??null,rawText:(pe==null?void 0:pe.md)??null}}:null,[M,n,ce,O]),Le=(ne==null?void 0:ne.type)==="kaozhen",He=h.useMemo(()=>(ne==null?void 0:ne.chapters.map(E=>E.file))??[],[ne]),{matchStates:Ye}=ef({resetKey:`${n}
1352
1351
  ${ce??""}`,load:Se,files:He,activeFile:B??null,activeJuan:(be==null?void 0:be.json)??null,activeRawText:(be==null?void 0:be.md)??null,query:fe,isKaozhen:Le}),qe=h.useRef(new Map);h.useEffect(()=>{qe.current.clear()},[n]);const Xe=h.useMemo(()=>({versionKey:ce,chapter:Z??null}),[ce,Z]),I=Th(p,B??null,Xe),{warpData:U,loading:ue}=Gc(_,b,B??null,Xe),Ce=Cf(w,B??null,Xe),ye=z.properNameMode??(Ce.length>0?"full":"off"),ge=h.useMemo(()=>({...z,properNameMode:ye}),[z,ye]),Ge=h.useMemo(()=>Ch(Ce,ye,{showWorks:ge.showWorks}),[Ce,ye,ge.showWorks]),[Q,ke]=h.useState(new Set),[Ae,Be]=h.useState(null),[Ne,he]=h.useState(!0),ve=z.preserveMargins,Ue=h.useCallback(E=>T({preserveMargins:E}),[T]),We=h.useRef(null),[st,jt]=h.useState(1),[on,Gt]=h.useState(null),q=E=>{var ze;const pe=parseInt(((ze=E==null?void 0:E.page_id)==null?void 0:ze.split(":")[1])??"",10);return isNaN(pe)?null:pe},Ve=E=>{var ze,De;const pe=(E==null?void 0:E.pages)??[];return q(E)??((ze=pe.find(Je=>Je.columns.some(vt=>vt.chars.length>0)))==null?void 0:ze.page)??((De=pe[0])==null?void 0:De.page)??1},[Oe,rt]=h.useState(()=>Ve(U)),Gn=`${n}
1353
1352
  ${ce}
1354
- ${B??""}`,[Gi,es]=h.useState({key:Gn,data:U,started:!!U});if(Gi.key!==Gn)es({key:Gn,data:U,started:!1});else if(U!==Gi.data&&(es({key:Gn,data:U,started:!!U}),U)){const E=U.pages??[];(!Gi.started||!E.some(pe=>pe.page===Oe))&&rt(Ve(U))}h.useEffect(()=>{ke(new Set),Be(null)},[B,ce]);const xp=h.useCallback(E=>{if(ke(new Set(E)),E.length>0){const pe=E[0],ze=parseInt(pe.split(":")[0],10);isNaN(ze)||rt(ze)}},[]),zt=h.useMemo(()=>{const E=new Map;for(const pe of(U==null?void 0:U.pages)??[])E.set(pe.page,pe);return E},[U]),vn=q(U),Yn=h.useCallback(E=>{var De;const pe=I.images;if(!pe||pe.length===0)return;const ze=(De=zt.get(E))==null?void 0:De.seq;return(ze?pe.find(Je=>Je.seq===ze):void 0)??pe.find(Je=>Je.pageNo===E)??pe[E-1]},[I.images,zt]),ts=st>1.5,qn=h.useCallback((E,pe=!1)=>{const ze=Yn(E);return ze?E===vn||pe?ze.hiresUrl??ze.url:ze.url:E===vn?(U==null?void 0:U.imageUrl)??"":""},[Yn,U,vn]),bp=h.useMemo(()=>qn(Oe,ts),[qn,Oe,ts]),Nt=h.useMemo(()=>[...zt.keys()].sort((E,pe)=>E-pe),[zt]),Kn=h.useRef(Oe);Kn.current=Oe;const Xn=h.useCallback(E=>{var pe;Kn.current===E||!zt.has(E)||(Kn.current=E,rt(E),(pe=zt.get(E))!=null&&pe.columns.some(ze=>ze.chars.length>0)&&Gt(ze=>({page:E,nonce:((ze==null?void 0:ze.nonce)??0)+1})))},[zt]),kn=h.useCallback(E=>{const pe=Kn.current,ze=Nt.indexOf(pe),De=Nt[ze<0?0:ze+E];De===void 0||De===pe||Xn(De)},[Nt,Xn]),ns=h.useCallback(E=>{if(!E.trim().match(/^\d+$/)||Nt.length===0)return null;const ze=parseInt(E.trim(),10),De=Number.isFinite(ze)?ze:Number.MAX_SAFE_INTEGER;return Nt.reduce((Je,vt)=>Math.abs(vt-De)<Math.abs(Je-De)?vt:Je,Nt[0])},[Nt]),[Yi,qi]=h.useState(null),Zn=h.useRef(null),yp=h.useCallback(E=>{Zn.current=E,qi(E)},[]),is=h.useCallback(()=>{const E=Zn.current;if(Zn.current=null,qi(null),E===null)return;const pe=ns(E);pe!==null&&Xn(pe)},[ns,Xn]),Ki=Nt.indexOf(Oe),jp=h.useCallback(E=>{if(E.altKey||E.ctrlKey||E.metaKey)return;const pe=E.target.tagName;pe==="INPUT"||pe==="TEXTAREA"||pe==="SELECT"||(E.key==="ArrowLeft"||E.key==="PageUp"?(E.preventDefault(),kn(-1)):(E.key==="ArrowRight"||E.key==="PageDown")&&(E.preventDefault(),kn(1)))},[kn]);h.useEffect(()=>{if(U)for(const E of[1,-1,2,3]){const pe=qn(Oe+E);pe&&Mr(pe)}},[U,Oe,qn]);const rs=h.useMemo(()=>{var hs;if(!U)return null;if(Oe===vn)return U;const E=zt.get(Oe);if(E&&E.width>0&&E.height>0)return{page_id:`p:${Oe}`,title:`第${Oe}葉`,image_size:[E.width,E.height],total_warped_w:E.width,columns:[{col:1,warped_w:E.width,warped_h:E.height,offset_x:0,strips:[],chars:E.columns.flatMap(Ze=>Ze.chars).map(Ze=>({id:Ze.id,char:Ze.char,slot:Ze.slot,pos:Ze.pos,sub:Ze.sub,bbox_col:Ze.bbox??[0,0,0,0]}))}]};const pe=(hs=U.pages)==null?void 0:hs.find(Ze=>Ze.page===Oe),[ze,De]=U.image_size||[2386,3082],Je=Yn(Oe),vt=(Je==null?void 0:Je.width)??ze,er=(Je==null?void 0:Je.height)??De,us=vt/ze,ms=er/De,gs=new Map;for(const Ze of U.columns){const mt=(Ze.strips||[]).flatMap(ni=>ni.srcQuad.map(ii=>ii[0]));if(mt.length===0)continue;const Rt=Ze.top_y??0,tr=Ze.bottom_y??Rt+Ze.warped_h;gs.set(Ze.col,{x0:Math.min(...mt),x1:Math.max(...mt),top:Rt,slotH:(tr-Rt)/21})}return{page_id:`p:${Oe}`,title:`第${Oe}葉`,image_size:[vt,er],total_warped_w:vt,columns:pe?pe.columns.map(Ze=>{const mt=gs.get(Ze.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Ze.col,warped_w:vt,warped_h:er,offset_x:0,strips:[],chars:Ze.chars.map(Rt=>{const tr=Rt.slot??Rt.pos??0,ni=(mt.top+(tr-1)*mt.slotH)*ms,ii=(mt.x0+mt.x1)/2,[Tp,zp]=Rt.sub==="a"?[ii,mt.x1]:Rt.sub==="b"?[mt.x0,ii]:[mt.x0,mt.x1];return{...Rt,bbox_col:[Tp*us,ni,zp*us,ni+mt.slotH*ms]}})}}):[]}},[U,Oe,vn,zt,Yn]),{entryTitle:Jn,authors:os}=Af(n,i,d===void 0),[ss,Xi]=h.useState("text");if(h.useEffect(()=>{Xi("text")},[B,ce]),H==="loading")return t.jsx(ga,{className:k,style:C,title:d??Jn,label:$("reader.loading")});if(H==="missing"||!N||!L)return t.jsx("div",{className:k,style:{...C,...ma},children:$("reader.noText")});if(D==="failed")return t.jsx("div",{className:k,style:{...C,...ma},children:$("reader.tocFailed")});if(!ne)return t.jsx(ga,{className:k,style:C,title:d??Jn,label:$("reader.tocLoading")});const Yt=Nf(L,ne),vp=If(ne,Ye,Yt,S,O),Zi=N.versions.map(E=>({key:E.key,label:_e.textVersionLabel(E),optionLabel:S(_e.textVersionLabel(E)),sourceName:fa(E)?$("reader.originalSource"):E.source_name?S(E.source_name):void 0,license:E.license??void 0,sourceUrl:E.source_url??void 0,primary:E.key===Re})),ut=Tf((ps=ne.source)==null?void 0:ps.upstream),Qn=(typeof d=="string"?S(d):d)??(ne.title?S(ne.title):Jn?S(Jn):void 0),as=L.edition_label?S(L.edition_label):void 0,Ji=Qn?t.jsx("a",{href:P(n),title:$("reader.viewEntry"),onClick:l?E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),l(n))}:void 0,children:Qn}):void 0,kp=Ji&&as?t.jsxs(t.Fragment,{children:[Ji,t.jsxs("span",{className:"bim-rd-ed",children:["·",as]})]}):Ji,wp=os.length>0?S(os.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${` ${E.role||$("reader.defaultRole")}`}`).join("、")):void 0,Qi=Z?Yc(Z,Yt,S,O):void 0,qt=O&&!!(be!=null&&be.json),Kt=(be==null?void 0:be.json)??null,sn=(be==null?void 0:be.md)??null,ls=qt&&!Le&&Wc(Kt.sections),Sp=ls&&!(sn&&ge.readingMode==="paragraph"&&yi(sn)),_p=qt&&ls?t.jsx(tf,{juan:Kt,view:ss,onView:Xi,textHasEntries:Sp}):void 0,$p=!0,ei=sn?sn.replace(/^##\s+[^\n]+\n+/,""):null,ti=fa(L),It=ti?$("reader.originalSource"):L.source_name?S(L.source_name):void 0,Cp=(typeof c=="string"?S(c):c)??(ti?[It,L.license].filter(Boolean).join(" · "):It??S(_e.textVersionLabel(L)));return t.jsxs(Gl,{className:k,style:C,title:kp,subtitle:Cp,byline:wp,current:Qi,pagerUnit:Yt,rail:_p,revisedAt:x,backHref:v,backLabel:y,onReportError:f?E=>f({...E,bookTitle:typeof Qn=="string"?Qn:void 0,entryId:n}):void 0,workLinkToggle:qt&&!Le&&!!l&&!!(Kt!=null&&Kt.sections.some(E=>E.work_id)),toc:vp,tocCaption:$("reader.tocCaption",{n:ne.chapters.length,unit:S(Yt)}),tocHeader:O&&ne.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:Le?$("reader.searchChaptersPlaceholder"):$("reader.searchUnitPlaceholder",{unit:S(Yt)}),"aria-label":Le?$("reader.searchChapters"):$("reader.searchUnit",{unit:S(Yt)}),value:fe,onChange:E=>oe(E.target.value)}):void 0,activeKey:B??null,onSelect:Y,images:I.images,imagesLoading:I.loading||ue,renderImageOverlay:m,imagePanel:U?"open":u,isWarpMode:!!U,customImagePanel:U&&rs?t.jsxs("div",{className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:jp,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:r("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:4},children:t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[Q.size>0&&t.jsxs("button",{type:"button",onClick:()=>ke(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",Q.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:st<=1,onClick:()=>{var E;return(E=We.current)==null?void 0:E.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(st*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:st>=6,onClick:()=>{var E;return(E=We.current)==null?void 0:E.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:st===1,onClick:()=>{var E;return(E=We.current)==null?void 0:E.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx($f,{ref:We,resetKey:Oe,onScaleChange:jt,style:{flex:1,minHeight:0},children:t.jsx(Eo,{imageUrl:bp,pageData:rs,selectedCharIds:Q,hoveredCharId:Ae,preserveMargins:ve,onCharClick:E=>{ke(ze=>{const De=new Set(ze);return De.has(E)?De.delete(E):(De.clear(),De.add(E)),De});const pe=document.querySelector(`[data-char-id="${E}"]`);pe&&pe.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Be})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":$("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:r("meta-fg")},children:[t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:Ki<=0,onClick:()=>kn(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":Oe,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:r("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":$("reader.facsimilePageInput"),size:Math.max(2,String(Yi??Oe).length),value:Yi??String(Oe),onFocus:E=>E.currentTarget.select(),onChange:E=>yp(E.target.value),onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),is()):E.key==="Escape"&&(Zn.current=null,qi(null)),E.stopPropagation()},onBlur:is,style:{width:`${Math.max(2,String(Yi??Oe).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${r("rule")}`,borderRadius:4,background:"transparent",color:"inherit"}}),"葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:Ki<0||Ki>=Nt.length-1,onClick:()=>kn(1),children:"›"})]})]}):void 0,settingsAnnotate:U?t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ne?"bim-rd-on":""}`,"aria-pressed":Ne,title:"切换外挂现代断句标点",onClick:()=>he(E=>!E),children:Ne?"标点":"无标点"}):void 0,settingsLayout:U?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-badge-warp",children:"图文对读"}),t.jsxs("div",{role:"group","aria-label":"书影留白",style:{display:"inline-flex",border:`1px solid ${r("rule")}`,borderRadius:4,overflow:"hidden"},children:[t.jsx("button",{type:"button",onClick:()=>Ue(!1),"aria-pressed":!ve,className:`bim-rd-t ${ve?"":"bim-rd-on"}`,style:{padding:"6px 12px",border:"none",borderRadius:0,background:ve?"transparent":"var(--bimrd-on-bg)",color:ve?"inherit":r("ink")},title:"去空白:紧凑裁切版心",children:"去空白"}),t.jsx("button",{type:"button",onClick:()=>Ue(!0),"aria-pressed":ve,className:`bim-rd-t ${ve?"bim-rd-on":""}`,style:{padding:"6px 12px",border:"none",borderRadius:0,background:ve?"var(--bimrd-on-bg)":"transparent",color:ve?r("ink"):"inherit"},title:"保留空白:完整呈现古籍天头地脚与白边",children:"保留空白"})]})]}):void 0,prefs:ge,onPrefsChange:T,versions:Zi.length>1?Zi:void 0,currentVersionKey:Zi.length>1?L.key:void 0,onVersionChange:je,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:yi(sn),allowVertical:g,children:[($e||ue&&!U&&!qt&&ei==null)&&t.jsx(nn,{}),!$e&&U&&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:Z!=null&&Z.title?S(Z.title):Qi}),(It||L.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[It,L.license&&t.jsxs(t.Fragment,{children:[It&&t.jsx("span",{className:"bim-rd-dot"}),L.license]})]})]}),t.jsx(Po,{pageData:U,pages:U.pages,punctuations:U.punctuations||[],selectedCharIds:Q,hoveredCharId:Ae,onSelectionChange:xp,onCharClick:E=>{ke(ze=>{const De=new Set(ze);return De.has(E)?De.delete(E):(De.clear(),De.add(E)),De});const pe=parseInt(E.split(":")[0],10);isNaN(pe)||rt(pe)},onCharHover:Be,mode:"horizontal",showPunctuation:Ne,entities:Ge,entityTransport:i,onEntityNavigate:j,onVisiblePageChange:E=>rt(E),convert:S,scrollToPage:on,pageBreaks:ge.pageBreaks,pageIndicatorY:ge.pageIndicatorY,onPageIndicatorYChange:E=>T({pageIndicatorY:E}),quoteStyle:ge.quoteStyle,bookTitleStyle:ge.bookTitleStyle,showWorks:ge.showWorks})]}),!$e&&!U&&qt&&Kt&&t.jsx(Qh,{juan:Kt,rawText:sn,positionLabel:Ef(Z,ne,Yt,S),groupLabel:Lf(ne,B??null),index:zf(n,ne),searchQuery:fe,onNavigate:l,transport:i,workLabelCache:qe,prefs:ge,view:ss,onViewChange:Xi},`${ce}/${B}`),!$e&&!U&&!qt&&ei!=null&&Z&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:Z.title?S(Z.title):Qi}),(It||L.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[ti&&It&&t.jsx(t.Fragment,{children:It}),!ti&&L.source_name&&t.jsxs(t.Fragment,{children:[$("reader.textSource")," ",L.source_url?t.jsx("a",{className:"bim-rd-link",href:L.source_url,target:"_blank",rel:"noreferrer",children:S(L.source_name)}):S(L.source_name)]}),It&&L.license&&t.jsx("span",{className:"bim-rd-dot"}),L.license]}),ut&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[$("reader.upstream")," ",ut.url?t.jsx("a",{className:"bim-rd-link",href:ut.url,target:"_blank",rel:"noreferrer",children:S(ut.name??ut.url)}):S(ut.name??""),ut.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),ut.license_url?t.jsx("a",{className:"bim-rd-link",href:ut.license_url,target:"_blank",rel:"noreferrer",children:ut.license}):ut.license]}),ut.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(Ll,{text:ut.note,convert:S})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(_o,{text:ei,mode:ge.readingMode,tables:$p,gujiMarkdown:!0,bookMarking:wo(ge),quoteStyle:ge.quoteStyle})})]}),!$e&&!ue&&!U&&!qt&&ei==null&&Z&&t.jsx("div",{className:"bim-rd-state",children:$("reader.chapterFailed")}),ne.references&&ne.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:$("reader.references")}),t.jsx("ol",{children:ne.references.map((E,pe)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:S(E.title)}):t.jsx("span",{children:S(E.title)}),E.author&&t.jsxs("span",{children:[",",S(E.author)]}),E.note&&t.jsxs("span",{children:["。",S(E.note)]})]},pe))})]})]})};function fa(e){return e.is_original===!0||e.source==="original"}function Ef(e,n,i,o){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 o(s?`${s}冊`:`${i}${e.n}`)}function Lf(e,n){if(!n)return;const i=o=>{var s;for(const a of o??[]){const l=i(a.children);if(l)return l;if((s=a.files)!=null&&s.includes(n))return a.label}};return i(e.juan_groups)}function Af(e,n,i){const[o,s]=h.useState({entryTitle:void 0,authors:[]});return h.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:i&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,n,i]),o}const qc={bug:{key:"bug",color:r("danger")},resource:{key:"resource",color:r("primary")},suggestion:{key:"suggestion",color:r("primary")},other:{key:"other",color:r("desc-fg")}},Mf=qc.other,Kc={pending:{key:"pending",color:r("warning")},in_progress:{key:"in_progress",color:r("primary")},resolved:{key:"resolved",color:r("success")},wontfix:{key:"wontfix",color:r("desc-fg")},duplicate:{key:"duplicate",color:r("desc-fg")}},Pf=Kc.pending;function Bf(e){try{const n=new Date(e),i=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function Wf(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const o=new URL(n);return i.hostname===o.hostname}catch{return!1}}const Oo=({items:e,loading:n})=>{const i=tt(),{t:o,convert:s}=te();return n?t.jsx(nn,{}):e.length===0?t.jsx("div",{style:Of,children:o("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=qc[a.type]||Mf,d=Kc[a.status]||Pf,c=typeof window<"u"&&Wf(a.pageUrl,window.location.href);return t.jsxs("div",{style:Ff,children:[t.jsxs("div",{style:Hf,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...xa,background:l.color},children:o(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...xa,background:d.color},children:o(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Df,children:Bf(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Uf,children:[a.resourceId&&t.jsx("a",{href:i(a.resourceId),style:ur,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:ur,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:ur,children:a.pageUrl}))]}),t.jsx("div",{style:Vf,children:s(a.content)}),a.reply&&t.jsxs("div",{style:Gf,children:[t.jsx("div",{style:Yf,children:o("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},Of={textAlign:"center",padding:"40px 0",color:r("desc-fg"),fontSize:"14px"},Ff={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"16px"},Hf={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xa={fontSize:"12px",color:r("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Df={fontSize:"12px",color:r("desc-fg")},Uf={fontSize:"12px",marginBottom:"6px"},ur={color:r("primary"),textDecoration:"none",borderBottom:`1px dashed ${r("primary")}`},Vf={fontSize:"14px",lineHeight:"1.6",color:r("fg"),whiteSpace:"pre-wrap"},Gf={marginTop:"12px",padding:"10px 12px",background:r("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r("fg")},Yf={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r("primary")},Br=({transport:e,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:a})=>{const l=Ie(),[d,c]=h.useState(null),[p,m]=h.useState([]),[u,g]=h.useState("recommend"),[f,x]=h.useState([]),[v,y]=h.useState(!1),_=o??u,b=A=>{g(A),s==null||s(A)},[w,j]=h.useState(!0),[k,C]=h.useState(null),[$,S]=h.useState(null),[M,z]=h.useState(null);h.useEffect(()=>{let A=!1;if(e.getCounts)return e.getCounts().then(H=>{A||c({works:H.works,books:H.books,collections:H.collections})}).catch(()=>{}),()=>{A=!0}},[e]),h.useEffect(()=>{let A=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const G=await e.getRecommended();if(G!=null&&G.groups)return G.groups.flatMap(ie=>ie.items.map(le=>({...le,group:ie.name})))}catch{}return[]})().then(async G=>{if(A)return;const ie=G.filter(V=>V.id);if(ie.length===0){j(!1);return}const le=await Promise.all(ie.map(async V=>{if(V.type)return{id:V.id,title:V.title,type:V.type,author:V.author,dynasty:V.dynasty,role:V.role,edition:V.edition,has_text:V.has_text,has_image:V.has_image,has_collated:V.has_collated,subtype:V.subtype,primary_name:V.primary_name,group:V.group,fallbackDescription:V.description};try{let F=null;if(e.getEntry)F=await e.getEntry(V.id);else{const xe=await e.getItem(V.id);xe&&(F={id:V.id,title:xe.title||V.id,type:xe.type||"work"})}if(F)return{...F,group:V.group,fallbackDescription:V.description}}catch{}return{id:V.id,title:V.title,type:_e.extractType(V.id),group:V.group,fallbackDescription:V.description}}));A||(m(le.filter(V=>V!==null)),j(!1))}),()=>{A=!0}},[e,i]);const T=h.useRef(!1),P=h.useRef(!1),R=h.useRef(!1);h.useEffect(()=>{if(_!=="catalog"||T.current)return;const A=e.getCatalogProgress??e.getResourceProgress;if(!A)return;T.current=!0;let H=!1;return A.call(e).then(G=>{H||C(G)}).catch(()=>{T.current=!1}),()=>{H=!0}},[e,_]),h.useEffect(()=>{if(_!=="collection"||P.current||!e.getCollectionProgress)return;P.current=!0;let A=!1;return e.getCollectionProgress().then(H=>{A||S(H)}).catch(()=>{P.current=!1}),()=>{A=!0}},[e,_]),h.useEffect(()=>{if(_!=="site"||R.current||!e.getSiteProgress)return;R.current=!0;let A=!1;return e.getSiteProgress().then(H=>{A||z(H)}).catch(()=>{R.current=!1}),()=>{A=!0}},[e,_]),h.useEffect(()=>{if(!a||_!=="feedback")return;let A=!1;return y(!0),fetch(a).then(H=>H.json()).then(H=>{!A&&H.success&&x(H.items||[])}).catch(()=>{}).finally(()=>{A||y(!1)}),()=>{A=!0}},[a,_]);const N=A=>t.jsx(jn,{type:A,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:r("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${r("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Cn,{label:l.home.recommendTab,active:_==="recommend",onClick:()=>b("recommend")}),t.jsx(Cn,{label:l.home.catalogTab,active:_==="catalog",onClick:()=>b("catalog")}),t.jsx(Cn,{label:l.home.collectionTab,active:_==="collection",onClick:()=>b("collection")}),t.jsx(Cn,{label:l.home.siteTab,active:_==="site",onClick:()=>b("site")}),a&&t.jsx(Cn,{label:l.home.feedbackTab,active:_==="feedback",onClick:()=>b("feedback")})]}),_==="recommend"&&t.jsx(qf,{recommended:p,loading:w,onNavigate:n,getIcon:N,t:l}),_==="catalog"&&t.jsx(ba,{progress:k,t:l,onNavigate:n}),_==="collection"&&t.jsx(ba,{progress:$,t:l,onNavigate:n}),_==="site"&&t.jsx(Xf,{progress:M,t:l,totalWorks:(d==null?void 0:d.works)??0}),_==="feedback"&&a&&t.jsx(Oo,{items:f,loading:v})]})})},Cn=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:r(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${r("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),qf=({recommended:e,loading:n,onNavigate:i,getIcon:o,t:s})=>{const a=tt();if(n)return t.jsx(nn,{});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:r("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 m=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return t.jsxs("a",{href:a(p.id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i==null||i(p.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${r("widget-border")}`,cursor:"pointer",background:r("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:o(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:r("desc-fg"),marginLeft:"4px"},children:p.edition})]}),m&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m})]})]},p.id)})})]},d))})},ba=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(nn,{});const o=[...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:r("progress-active"),done:r("progress-done"),todo:r("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=o.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:r("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(Kf,{item:p,t:n,statusColor:l[d],onNavigate:i},p.id))})]},d)})})},Kf=({item:e,t:n,statusColor:i,onNavigate:o})=>{const s=tt(),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 ${r("widget-border")}`,background:r("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&&o?t.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${r("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:r("widget-border"),color:r("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:r("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?ft(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:r("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${a}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"4px"},children:e.description})]})},Xf=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(nn,{});const o=[...e.resources].sort((c,p)=>c.priority-p.priority),s=o.filter(c=>c.imported>0),a=o.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),d=i>0?Math.round(l/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${r("primary")} 6%, transparent)`,fontSize:"13px",color:r("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:r("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:r("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(ya,{item:c,t:n,totalWorks:i},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:r("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:r("progress-todo")}}),n.home.statusTodo," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(ya,{item:c,t:n,totalWorks:i},c.id))})]})]})},ya=({item:e,t:n,totalWorks:i})=>{const o=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${r("widget-border")}`,background:r("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:r("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:r("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:r("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"4px"},children:e.description})]})},ja="(max-width: 768px)";function Zf(){const[e,n]=h.useState(()=>typeof window>"u"?!1:window.matchMedia(ja).matches);return h.useEffect(()=>{const i=window.matchMedia(ja),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),e}const Jf=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var P;const a=Ie(),{convert:l}=Me(),d=Zf(),[c,p]=h.useState(null),[m,u]=h.useState(null),[g,f]=h.useState(!1),[x,v]=h.useState("detail"),[y,_]=h.useState([]),[b,w]=h.useState(!1),j=h.useCallback(async R=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){_([]);return}w(!0);try{if(e.getCollectionCatalogs){const N=await e.getCollectionCatalogs(R);_(N||[])}else if(e.getCollectionCatalog){const N=await e.getCollectionCatalog(R);_(N?[{resource_id:"",data:N}]:[])}}catch{_([])}finally{w(!1)}},[e]),k=h.useCallback(async R=>{if(i){i(R);return}p(R),u(null),_([]),v("detail"),f(!0);try{const N=await e.getItem(R.id);N&&(u(N),N.type==="collection"&&j(R.id))}catch(N){console.error("加载详情失败:",N)}finally{f(!1)}},[e,i,j]),C=h.useCallback(async R=>{u(null),_([]),v("detail"),f(!0);try{const N=await e.getItem(R);N&&(u(N),p({id:R,title:N.title||R,type:N.type||"book"}),N.type==="collection"&&j(R))}catch(N){console.error("导航失败:",N)}finally{f(!1)}},[e,j]),$=typeof(m==null?void 0:m.text_count)=="number"&&m.text_count>0,S=(m==null?void 0:m.type)==="collection"&&(y.length>0||b)||(m==null?void 0:m.type)==="work"&&$,M=d&&(g||m),z=h.useCallback(()=>{p(null),u(null),_([]),v("detail")},[]),T=t.jsx(t.Fragment,{children:g?t.jsx(nn,{}):m?t.jsxs(t.Fragment,{children:[(S||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${r("widget-border")}`,padding:d?"0 12px":"0 48px",background:r("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[S&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>v("detail"),style:ci(x==="detail"),children:a.detailTab.basicInfo}),m.type==="collection"&&b&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:ci(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),m.type==="collection"&&y.map(R=>t.jsx("button",{onClick:()=>v(`catalog:${R.resource_id}`),style:ci(x===`catalog:${R.resource_id}`),children:R.short_name?`${l(R.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},R.resource_id)),m.type==="work"&&$&&t.jsx("button",{onClick:()=>v("collated"),style:ci(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(no,{data:m,transport:e,onNavigate:C}):x.startsWith("catalog:")?t.jsx(io,{data:(P=y.find(R=>`catalog:${R.resource_id}`===x))==null?void 0:P.data,onNavigate:C}):x==="collated"?t.jsx(Wo,{id:m.id,transport:e,onNavigate:C}):null})]}):t.jsx(Br,{transport:e,onNavigate:C,recommendedIds:o})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:r("bg"),color:r("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${r("widget-border")}`,background:r("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:z,style:{padding:"4px 12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("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(wr,{transport:e,onEntryClick:k,hideModeIndicator:n}),!m&&t.jsx(Br,{transport:e,onNavigate:C,recommendedIds:o})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:r("bg"),color:r("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${r("widget-border")}`,display:"flex",flexDirection:"column",background:r("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(wr,{transport:e,onEntryClick:k,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:r("bg"),display:"flex",flexDirection:"column"},children:T})]})};function ci(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${r("primary")}`:"2px solid transparent",background:"transparent",color:r(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}const Qf=({pageData:e,rawImageUrl:n="",punctuations:i=[],title:o,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=h.useState(new Set),[m,u]=h.useState(null),[g,f]=h.useState("horizontal"),[x,v]=h.useState(!0),y=h.useRef(null),_=h.useCallback(k=>{p(new Set(k))},[]),b=h.useCallback(k=>{if(p(C=>{const $=new Set(C);return $.has(k)?$.delete(k):($.clear(),$.add(k)),$}),y.current){const C=y.current.querySelector(`[data-char-id="${k}"]`);C&&C.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),w=()=>{var k;p(new Set),window.getSelection&&((k=window.getSelection())==null||k.removeAllRanges())},j=i.length>0?i: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:o||e.title}),s&&t.jsx("span",{style:{fontSize:"0.85rem",color:r("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:r("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:r("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:w,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>v(k=>!k),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f(k=>k==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:g==="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(Eo,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:m,onCharClick:b,onCharHover:u})})]}),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:g==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(Po,{pageData:e,punctuations:j,selectedCharIds:c,hoveredCharId:m,onSelectionChange:_,onCharClick:b,onCharHover:u,mode:g,showPunctuation:x})]})]})]})},ex=e=>typeof e=="string"&&Array.from(e).length===1;function tx(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.punctuations)?e.punctuations:[],i=[];for(const o of n){if(!o||typeof o!="object")continue;const s=o;typeof s.anchor!="string"||typeof s.mark!="string"||s.pre_char!=null&&!ex(s.pre_char)||i.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??void 0})}return i}function nx(e){var i;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return null;for(const o of n){const s=/\/iiif\/([^/]+)\/canvas\/([^/]+)\//.exec(String(((i=o==null?void 0:o.canvas)==null?void 0:i.id)??""));if(s)return{bookId:s[1],vol:s[2]}}return null}const ix=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function at(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}const rx=new Set(["main","solo","jz_r","jz_l"]),ox=new Set(["body","banxin","blank"]);function sx(e){const n={};return typeof e.lane=="string"&&rx.has(e.lane)&&e.lane!=="main"&&(n.lane=e.lane),e.lacuna===!0&&(n.lacuna=!0),e.guess===!0&&(n.guess=!0),typeof e.zi=="string"&&e.zi&&(n.zi=e.zi),n}function ax(e){const n={};typeof e.kind=="string"&&ox.has(e.kind)&&e.kind!=="body"&&(n.kind=e.kind);const i=at(e.raised);i!==void 0&&Number.isInteger(i)&&i>0&&(n.raised=i);const o=at(e.lead_blank);return o!==void 0&&Number.isInteger(o)&&o>0&&(n.lead_blank=o),n}function mr(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(i=>!!i&&typeof i=="object"):[]}function lx(e,n){var c,p,m,u,g,f,x,v,y,_;const i=new Map,o=new Map;for(const b of mr(n)){const w=at(b.page);if(w!==void 0){i.set(w,b);for(const j of Array.isArray(b.cells)?b.cells:[]){const k=j==null?void 0:j.box;typeof(j==null?void 0:j.a)=="string"&&Array.isArray(k)&&k.length===4&&k.every(C=>at(C)!==void 0)&&o.set(j.a,[k[0],k[1],k[0]+k[2],k[1]+k[3]])}}}const s=[],a=new Map,l=new Map;for(const b of mr(e)){const w=at(b.page);w!==void 0&&typeof b.label=="string"&&b.label&&a.set(w,b.label)}for(const b of mr(e)){const w=at(b.page);if(w===void 0)continue;const j=[];for(const C of Array.isArray(b.columns)?b.columns:[]){const $=at(C==null?void 0:C.col);if($===void 0)continue;const S=[];for(const z of Array.isArray(C.cells)?C.cells:[]){const T=ix.exec(String((z==null?void 0:z.a)??""));if(!T||typeof z.c!="string")continue;const P=parseInt(T[3],10);S.push({id:z.a,char:z.c,slot:P,pos:P,sub:T[4]||null,bbox:o.get(z.a)??null,...sx(z)})}const M=ax(C);(S.length>0||M.kind==="blank")&&j.push({col:$,chars:S,...M})}if(!j.some(C=>C.chars.length>0)){j.length>0&&l.set(w,j);continue}j.sort((C,$)=>C.col-$.col);const k=i.get(w);s.push({page:w,seq:String(((c=k==null?void 0:k.canvas)==null?void 0:c.seq)??""),width:at((p=k==null?void 0:k.canvas)==null?void 0:p.width)??at((m=k==null?void 0:k.image)==null?void 0:m.width)??0,height:at((u=k==null?void 0:k.canvas)==null?void 0:u.height)??at((g=k==null?void 0:k.image)==null?void 0:g.height)??0,...typeof b.label=="string"&&b.label?{label:b.label}:{},columns:j})}const d=new Set(s.map(b=>b.page));for(const[b,w]of i){const j=(f=w==null?void 0:w.canvas)==null?void 0:f.seq;d.has(b)||typeof j!="string"&&typeof j!="number"||String(j)===""||s.push({page:b,seq:String(j),width:at((x=w.canvas)==null?void 0:x.width)??at((v=w.image)==null?void 0:v.width)??0,height:at((y=w.canvas)==null?void 0:y.height)??at((_=w.image)==null?void 0:_.height)??0,...a.has(b)?{label:a.get(b)}:{},columns:l.get(b)??[]})}return s.sort((b,w)=>b.page-w.page)}const cx=({data:e,onNavigate:n,className:i,style:o})=>{var m;const{t:s,convert:a}=te(),[l,d]=h.useState(((m=e.divisions[0])==null?void 0:m.name)??null),[c,p]=h.useState(null);return t.jsxs("div",{className:i,style:o,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:r("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:r("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(u=>t.jsx(dx,{division:u,expanded:l===u.name,onToggle:()=>d(l===u.name?null:u.name),expandedCat:c,onCatToggle:g=>p(c===g?null:g),onNavigate:n},u.name))})]})},dx=({division:e,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=te(),c=e.categories.reduce((p,m)=>{const u=m.stats||{zhulu:0,cunmu:0};return p+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${r("primary")} 6%, transparent)`:r("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:r("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:r("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 m=`${e.name}/${p.name}`;return t.jsx(px,{category:p,expanded:o===m,onToggle:()=>s(m),onNavigate:a},p.name)})})]})},px=({category:e,expanded:n,onToggle:i,onNavigate:o})=>{var p,m,u,g;const{t:s,convert:a}=te(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((m=e.books)==null?void 0:m.cunmu)||[],c=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?r("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:r("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),marginLeft:"8px",fontWeight:400},children:s("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:r("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(va,{label:s("catalogPage.zhulu"),books:l,onNavigate:o}),d.length>0&&t.jsx(va,{label:s("catalogPage.cunmu"),books:d,onNavigate:o})]})]})},va=({label:e,books:n,onNavigate:i})=>{const{t:o,convert:s}=te(),a=tt(),[l,d]=h.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:r("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((p,m)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:r("fg")},children:p.work_id&&i?t.jsx("a",{href:a(p.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(p.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${r("link-fg")}`},children:s(p.title)}):s(p.title)}),p.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:s(p.volumes)}),p.author&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:s(p.author).slice(0,20)})]},m))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:r("primary"),background:"transparent",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:o("catalogPage.expandAllN",{n:n.length})})]})},kt=({title:e,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const a=Ie();return t.jsxs("div",{style:{background:r("bg"),border:`1px solid ${r("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 ${r("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:r("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,i&&t.jsx("button",{onClick:i,style:mx,children:"AI"}),n&&t.jsx("button",{onClick:n,style:ux,children:a.action.save})]})]}),s]})},ux={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},mx={padding:"4px 12px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},ht=({label:e,value:n,onChange:i,placeholder:o,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:a=>i(a.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),tn=({value:e,onChange:n,placeholder:i})=>{const o=h.useRef(null);return h.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:o,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},vi=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||r("primary-soft"),color:r(n?"on-color-fg":"fg"),...i},children:e});function gx(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const gi=({value:e,onChange:n,label:i})=>{const[o,s]=h.useState(!1),a=h.useRef(null),l=gx(e||"");return h.useEffect(()=>{o&&a.current&&a.current.focus()},[o]),!o&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:ka,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${r("input-border")}`,borderRadius:"2px",background:r("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:r("fg")},children:l.name}),t.jsx(vi,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:ka,children:i}),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:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},ka={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500};function hx(e){switch(e){case"url":return r("source-url");case"bookID":return r("source-bookid");default:return r("desc-fg")}}function fx(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Xc=({items:e,onChange:n,onOpenEntityPicker:i})=>{const o=Ie(),[s,a]=h.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=u=>{n(e.filter((g,f)=>f!==u)),s===u&&a(null)},c=(u,g,f)=>{const x=[...e];x[u]={...x[u],[g]:f},n(x)},p=(u,g)=>{const f=[...e];f[u]={...f[u],type:g,id:"",name:""},n(f),g==="bookID"&&i&&i(x=>{const v=[...e];v[u]={...v[u],id:x.id,name:x.title,type:"bookID"},n(v)})},m=u=>{i&&i(g=>{const f=[...e];f[u]={...f[u],id:g.id,name:g.title,type:"bookID"},n(f)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(s===g?null:g),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:r("fg")},children:u.name||`${o.editor.sourcePlaceholder} ${g+1}`}),u.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:hx(u.type),color:r("on-color-fg"),borderRadius:"3px",fontWeight:500},children:fx(u.type)}),t.jsx("button",{onClick:f=>{f.stopPropagation(),d(g)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===g&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!u.type&&t.jsxs("div",{children:[t.jsx("label",{style:Et,children:o.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(g,"bookID"),style:{...wa,borderColor:r("source-bookid"),color:r("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:o.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>p(g,"url"),style:{...wa,borderColor:r("source-url"),color:r("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),u.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:Et,children:o.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const f=[...e];f[g]={...f[g],type:"",id:"",name:""},n(f)},style:Sa,children:o.action.changeType})]}),u.id&&u.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:r("bg"),border:`1px solid ${r("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:r("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:u.name}),t.jsx("code",{style:{fontSize:"11px",background:r("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:u.id})]}),t.jsx("button",{onClick:()=>m(g),style:{background:"transparent",border:`1px solid ${r("widget-border")}`,color:r("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):t.jsxs("button",{onClick:()=>m(g),style:{width:"100%",padding:"14px",border:`2px dashed ${r("widget-border")}`,borderRadius:"6px",background:"transparent",color:r("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),u.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:Et,children:o.label.sourceName}),t.jsx("button",{onClick:()=>{const f=[...e];f[g]={...f[g],type:"",id:"",name:""},n(f)},style:Sa,children:o.action.changeType})]}),t.jsx("input",{type:"text",value:u.name,onChange:f=>c(g,"name",f.target.value),placeholder:o.editor.sourceNamePlaceholder,style:ln})]}),t.jsxs("div",{children:[t.jsx("label",{style:Et,children:o.label.urlAddress}),t.jsx("input",{type:"text",value:u.id,onChange:f=>c(g,"id",f.target.value),placeholder:"https://...",style:ln})]})]}),u.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${r("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...Et,opacity:.7},children:o.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Et,children:o.label.detailsOptional}),t.jsx("input",{type:"text",value:u.details,onChange:f=>c(g,"details",f.target.value),placeholder:o.editor.detailsPlaceholder,style:ln})]}),t.jsxs("div",{children:[t.jsx("label",{style:Et,children:o.label.positionOptional}),t.jsx("input",{type:"text",value:u.position,onChange:f=>c(g,"position",f.target.value),placeholder:"如: 卷三, p.52",style:ln})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Et,children:o.label.dataVersionOptional}),t.jsx("input",{type:"text",value:u.version,onChange:f=>c(g,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:ln})]}),t.jsxs("div",{children:[t.jsx("label",{style:Et,children:o.label.processorVersionOptional}),t.jsx("input",{type:"text",value:u.processor_version,onChange:f=>c(g,"processor_version",f.target.value),placeholder:"如: v0.1",style:ln})]})]})]})]})})]},g)),t.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:o.action.addSource})]})]})},Et={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500},ln={width:"100%",padding:"6px 8px",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},wa={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:r("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Sa={background:"transparent",border:"none",color:r("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Zc(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Jc(e){return!e||e.length===0?"":JSON.stringify(e)}const Qc=({entityType:e,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:m,onLinkEntity:u,onUnlinkEntity:g,onViewEntity:f,onCreateAndLink:x,onSaveRelations:v})=>{const y=Ie();return t.jsxs("div",{style:{background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${r("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})]}),v&&t.jsx("button",{onClick:v,style:xx,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Tn,{direction:"up",title:y.relation.belongsToWork,entity:a,onView:f,onUnlink:()=>g("workId"),onLink:()=>u("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Tn,{direction:"up",title:y.relation.containedInCollection,entity:l,onView:f,onUnlink:()=>g("collectionId"),onLink:()=>u("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:i}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),a&&m&&m.length>0&&t.jsx(cn,{direction:"horizontal",title:`${y.relation.siblingVersions} (${m.length})`,entities:m,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(Tn,{direction:"up",title:y.relation.parentWork,entity:o,onView:f,onUnlink:()=>g("parentWorkId"),onLink:()=>u("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(cn,{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(cn,{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(cn,{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(Tn,{direction:"up",title:y.relation.correspondingWork,entity:a,onView:f,onUnlink:()=>g("workId"),onLink:()=>u("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Tn,{direction:"up",title:y.relation.parentCollection,entity:s,onView:f,onUnlink:()=>g("parentCollectionId"),onLink:()=>u("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(cn,{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(cn,{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})]})]})]})},Tn=({direction:e,title:n,entity:i,onView:o,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:m,unlinkLabel:u})=>{const g=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",padding:"10px",background:r("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:r("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:ed(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(_a,{onClick:()=>o(i),title:m,children:"👁️"}),t.jsx(_a,{onClick:s,title:u,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:r("bg"),borderRadius:"4px",color:r("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Wr,{onClick:a,children:d}),t.jsx(Wr,{onClick:l,primary:!0,children:c})]})]})},cn=({direction:e,title:n,entities:i,onView:o,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=h.useState(!1),m=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),u=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",g=c?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",padding:"10px",background:r("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:m,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:u}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(f=>t.jsxs("div",{onClick:()=>o(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:r("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:ed(f.type)}),t.jsx("span",{children:f.title})]},f.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:r("link-fg"),cursor:"pointer"},children:[d," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:r("bg"),borderRadius:"4px",color:r("desc-fg"),fontSize:"12px",textAlign:"center"},children:l}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Wr,{onClick:s,primary:!0,children:["+ ",a]})})]})},_a=({onClick:e,title:n,danger:i,children:o})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?r("danger"):"inherit",opacity:.7},children:o}),Wr=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${r("widget-border")}`,borderRadius:"4px",background:n?r("primary"):"transparent",color:n?r("primary-fg"):"inherit",cursor:"pointer"},children:i});function ed(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const xx={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},td=({isOpen:e,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[m,u]=h.useState(""),g=p?l.filter(y=>y.id!==p):l;h.useEffect(()=>{e&&(u(""),d(""))},[e]);const f=y=>{u(y),d(y)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:bx,children:t.jsxs("div",{style:yx,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:jx,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:m,onChange:y=>f(y.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:vx})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:gr,children:"搜索中..."}):g.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(y=>t.jsxs("div",{onClick:()=>o(y),style:kx,children:[t.jsx("span",{style:{fontSize:"16px"},children:v}),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))}):m?t.jsxs("div",{style:gr,children:["未找到匹配的",x]}):t.jsxs("div",{style:gr,children:["输入关键词搜索",x]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${r("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:a,style:wx,children:["创建新",x,"并关联"]})]})]})})},bx={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},yx={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:r("shadow-dialog")},jx={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},vx={width:"100%",padding:"10px 12px",border:`1px solid ${r("input-border")}`,borderRadius:"4px",background:r("input-bg"),color:r("input-fg"),fontSize:"13px",boxSizing:"border-box"},kx={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:r("primary-soft")},gr={padding:"20px",textAlign:"center",color:r("desc-fg")},wx={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},$a={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Sx={work:"📜",book:"📖",collection:"📚",entity:"👤"},nd=({isOpen:e,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:a})=>{const[l,d]=h.useState(""),c=h.useRef(null);h.useEffect(()=>{e&&(d((o==null?void 0:o.title)||""),setTimeout(()=>{var g,f;(g=c.current)==null||g.focus(),(f=c.current)==null||f.select()},100))},[e,o==null?void 0:o.title]);const p=g=>{g.key==="Enter"&&l.trim()?m():g.key==="Escape"&&a()},m=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!e)return null;const u=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${$a[n]}`}};return t.jsx("div",{style:_x,onClick:g=>{g.target===g.currentTarget&&a()},children:t.jsxs("div",{style:$x,onClick:g=>g.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Sx[n]}),t.jsx("span",{children:u()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:r("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:r("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:l,onChange:g=>d(g.target.value),onKeyDown:p,placeholder:`请输入${$a[n]}名称...`,style:Cx})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),background:r("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&t.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:a,style:Tx,children:"取消"}),t.jsx("button",{onClick:m,disabled:!l.trim(),style:{...zx,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},_x={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},$x={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:r("shadow-dialog")},Cx={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${r("input-border")}`,borderRadius:"4px",background:r("input-bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box"},Tx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},zx={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg")};function Nx(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function id(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ix(e){switch(e){case"work":return r("editor-type-work");case"collection":return r("editor-type-collection");case"book":return r("editor-type-book");default:return r("desc-fg")}}const rd=({isOpen:e,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:m})=>{const[u,g]=h.useState(""),[f,x]=h.useState([]),[v,y]=h.useState(!1),[_,b]=h.useState("recent");h.useEffect(()=>{e&&(g(""),x([]),b(o.length>0?"recent":"search"))},[e,o.length]),h.useEffect(()=>{if(!u.trim()){x([]);return}const S=setTimeout(async()=>{y(!0);try{x(await m(u,i))}catch{x([])}finally{y(!1)}},300);return()=>clearTimeout(S)},[u,i,m]);const w=h.useCallback(S=>{g(S.target.value),S.target.value.trim()&&b("search")},[]),j=h.useCallback(S=>s?S.filter(M=>M.id!==s):S,[s]);if(!e)return null;const k=n||(i==="all"?"选择实体":`选择${id(i)}`),C=j(o),$=j(f);return t.jsx("div",{style:Ex,children:t.jsxs("div",{style:Lx,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),t.jsx("button",{onClick:c,style:Ax,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:u,onChange:w,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Mx}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),C.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsxs(Ca,{active:_==="recent",onClick:()=>b("recent"),children:["最近使用 (",C.length,")"]}),t.jsxs(Ca,{active:_==="search",onClick:()=>b("search"),children:["搜索结果 ",$.length>0&&`(${$.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:_==="recent"&&C.length>0?t.jsx(Ta,{entities:C,onSelect:d}):u.trim()?v?t.jsx(hr,{message:"搜索中..."}):$.length>0?t.jsx(Ta,{entities:$,onSelect:d}):t.jsx(hr,{message:"未找到匹配的结果"}):t.jsx(hr,{message:"输入关键词开始搜索"})}),a&&p&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${r("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:p,style:Px,children:l||"创建新实体"})]})]})})},Ca=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${r("primary")}`:"2px solid transparent",background:"transparent",color:r(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),Ta=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Rx,{entity:i,onClick:()=>n(i)},i.id))}),Rx=({entity:e,onClick:n})=>{const[i,o]=h.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:r("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Nx(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:r("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:r("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:Ix(e.type),color:r("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:id(e.type)})]})},hr=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:e}),Ex={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lx={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:r("shadow-dialog")},Ax={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Mx={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("input-fg"),fontSize:"13px",boxSizing:"border-box"},Px={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},Bx={work:r("editor-type-work"),collection:r("editor-type-collection"),book:r("editor-type-book"),entity:r("editor-type-entity")},Wx={work:"📜",collection:"📚",book:"📖",entity:"👤"},od=({data:e,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:m,relations:u,onRelationsChange:g})=>{var je;const f=Ie(),[x,v]=h.useState(!1),[y,_]=h.useState("work"),[b,w]=h.useState(""),[j,k]=h.useState(""),[C,$]=h.useState([]),[S,M]=h.useState(!1),[z,T]=h.useState(!1),[P,R]=h.useState("work"),[N,A]=h.useState(""),[H,G]=h.useState(),[ie,le]=h.useState(!1),[V,F]=h.useState(null),[xe,ee]=h.useState([]);h.useRef(null);const L=e.type,Re=L==="work",ce=L==="collection",me=L==="book",se=h.useCallback((Y,be)=>{n({...e,[Y]:be})},[e,n]),Pe=h.useCallback((Y,be)=>{w(Y),_(be),k(f.editor.selectToLink+f.indexType[be]),$([]),v(!0)},[f]),X=h.useCallback(Y=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(e.id,Y)},[o,e.id]),re=h.useCallback(Y=>{s==null||s(Y.id,Y.type)},[s]),de=h.useCallback((Y,be,Ee)=>{const Fe={...Ee,author:(Ee==null?void 0:Ee.author)||e.author,dynasty:Ee==null?void 0:Ee.dynasty};R(be),A(Y),G(Fe),T(!0)},[e.author]),D=h.useCallback((Y,be)=>{o!=null&&o.createAndLink&&o.createAndLink(e.id,N,{type:P,title:Y,inheritData:be}),T(!1)},[o,e.id,N,P]),K=h.useCallback(Y=>{if(!Y.trim()){$([]);return}M(!0),o!=null&&o.searchEntities&&o.searchEntities(Y,y).then(be=>{$(be),M(!1)}).catch(()=>{$([]),M(!1)})},[o,y]),we=h.useCallback(Y=>{o!=null&&o.linkEntity&&o.linkEntity(e.id,b,Y.id),v(!1)},[o,e.id,b]),ne=h.useCallback(()=>{i()},[i]),B=h.useCallback(Y=>{F(()=>Y),le(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(ee).catch(()=>{})},[o]),Z=h.useCallback((Y,be)=>o!=null&&o.searchEntities?o.searchEntities(Y,be==="all"?void 0:be):Promise.resolve([]),[o]),ae=h.useCallback(Y=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(Y),ee(be=>[Y,...be.filter(Ee=>Ee.id!==Y.id)].slice(0,10)),V==null||V(Y),le(!1),F(null)},[o,V]);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 ${r("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:Wx[L]}),t.jsx("span",{children:e.title||f.editor.untitled}),t.jsx(vi,{children:e.id}),t.jsx(vi,{color:Bx[L],children:f.indexType[L]})]})}),t.jsx(kt,{title:f.section.basicInfo,onSave:i,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(gi,{label:Re?f.editor.workTitle:ce?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:Y=>se("title",Y)}),me&&t.jsx(gi,{label:f.editor.belongsToWork,value:e.workName||"",onChange:Y=>se("workName",Y)}),t.jsx(ht,{label:f.editor.authorLabel,value:e.author||"",onChange:Y=>se("author",Y)}),t.jsx(ht,{label:f.editor.publicationYearLabel,value:e.publicationYear||"",onChange:Y=>se("publicationYear",Y)}),(me||ce)&&t.jsx(gi,{label:f.editor.containedIn,value:e.collection||"",onChange:Y=>se("collection",Y)}),(me||ce)&&t.jsx(ht,{label:f.editor.holderLabel,value:e.holder||"",onChange:Y=>se("holder",Y)}),(me||ce)&&t.jsx(ht,{label:me?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:Y=>se("pages",Y)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(ht,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:Y=>se("firstImage",Y)})})]})}),t.jsx(kt,{title:f.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(tn,{value:e.description||"",onChange:Y=>se("description",Y),placeholder:f.editor.descriptionPlaceholder})}),(((je=e.additional_works)==null?void 0:je.length)||0)>0&&t.jsx(kt,{title:f.section.additionalWorks,onSave:i,children:t.jsx(Ox,{items:e.additional_works||[],onChange:Y=>se("additional_works",Y)})}),t.jsx(kt,{title:f.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Fx,{items:e.indexed_by||[],onChange:Y=>se("indexed_by",Y)})}),t.jsx(kt,{title:f.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Hx,{items:e.emendated_by||[],onChange:Y=>se("emendated_by",Y)})}),t.jsx(kt,{title:f.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(vr,{items:e.resources||[],onChange:Y=>se("resources",Y),onDownload:p,downloadStatuses:m,filterType:"text"})}),t.jsx(kt,{title:f.section.imageResources,onSave:i,children:t.jsx(vr,{items:e.resources||[],onChange:Y=>se("resources",Y),onDownload:p,downloadStatuses:m,filterType:"image"})}),t.jsx(kt,{title:f.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(Xc,{items:Zc(e.sources||""),onChange:Y=>se("sources",Jc(Y)),onOpenEntityPicker:B})}),(me||ce)&&t.jsx(kt,{title:f.section.provenance,onSave:i,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(tn,{value:e.provenance||"",onChange:Y=>se("provenance",Y),placeholder:f.editor.provenancePlaceholder})}),me&&t.jsx(kt,{title:f.section.otherEditions,onSave:i,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(tn,{value:e.otherEditions||"",onChange:Y=>se("otherEditions",Y),placeholder:f.editor.otherEditionsPlaceholder})}),t.jsx(Qc,{entityType:L,entityId:e.id,entityTitle:e.title,parentWork:u==null?void 0:u.parentWork,parentCollection:u==null?void 0:u.parentCollection,belongsToWork:u==null?void 0:u.belongsToWork,belongsToCollection:u==null?void 0:u.belongsToCollection,childWorks:u==null?void 0:u.childWorks,childCollections:u==null?void 0:u.childCollections,containedBooks:u==null?void 0:u.containedBooks,siblingBooks:u==null?void 0:u.siblingBooks,onLinkEntity:Pe,onUnlinkEntity:X,onViewEntity:re,onCreateAndLink:de,onSaveRelations:ne}),a&&l&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${r("danger-soft-border")}`,background:r("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:r("danger"),fontWeight:600,marginBottom:"8px"},children:f.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"12px"},children:f.editor.dangerZoneDesc}),t.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("danger")}`,borderRadius:"4px",background:"transparent",color:r("danger"),cursor:"pointer"},children:f.editor.deleteEntity})]}),t.jsx(td,{isOpen:x,entityType:y,title:j,onSelect:we,onCancel:()=>v(!1),onCreate:()=>{v(!1),de(b,y)},searchResults:C,onSearch:K,isLoading:S,excludeId:e.id}),t.jsx(nd,{isOpen:z,entityType:P,relationField:N,inheritData:H,onConfirm:D,onCancel:()=>T(!1)}),t.jsx(rd,{isOpen:ie,title:f.action.selectBookOrWork,filterType:"all",recentEntities:xe,excludeId:e.id,onSelect:ae,onCancel:()=>{le(!1),F(null)},onSearch:Z})]})};function Ox({items:e,onChange:n}){const i=Ie(),o=(l,d,c)=>{const p=e.map((m,u)=>u===l?{...m,[d]:c}:m);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(ht,{label:i.editor.bookNameLabel,value:l.book_title,onChange:c=>o(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(ht,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>o(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:r("muted"),marginTop:"18px"},children:"✕"})]},d)),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${r("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:r("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function sd({items:e,onChange:n,showMeta:i,addLabel:o}){const s=Ie(),[a,l]=h.useState(null),d=(m,u,g)=>{const f=e.map((x,v)=>v===m?{...x,[u]:g||void 0}:x);n(f)},c=m=>{n(e.filter((u,g)=>g!==m)),a===m&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,u)=>{const g=a===u;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?`color-mix(in srgb, ${r("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(g?null:u),children:[t.jsx("span",{style:{fontSize:"10px",color:r("desc-fg"),transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.source||s.editor.unnamedSource}),m.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:m.source_bid}),t.jsx("button",{onClick:f=>{f.stopPropagation(),c(u)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${r("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:r("muted")},children:"✕"})]}),!g&&i&&(m.title_info||m.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:r("desc-fg")},children:[m.title_info,m.title_info&&m.author_info&&" — ",m.author_info]}),g&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ht,{label:s.label.sourceName,value:m.source,onChange:f=>d(u,"source",f)}),t.jsx(ht,{label:s.label.sourceBid,value:m.source_bid||"",onChange:f=>d(u,"source_bid",f)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ht,{label:s.label.titleInfo,value:m.title_info||"",onChange:f=>d(u,"title_info",f)}),t.jsx(ht,{label:s.label.authorInfo,value:m.author_info||"",onChange:f=>d(u,"author_info",f)})]}),t.jsx(ht,{label:s.label.edition,value:m.edition||"",onChange:f=>d(u,"edition",f)})]}),t.jsx(tn,{value:m.summary||"",onChange:f=>d(u,"summary",f),placeholder:s.editor.summaryPlaceholder}),t.jsx(tn,{value:m.comment||"",onChange:f=>d(u,"comment",f),placeholder:s.editor.commentPlaceholder}),t.jsx(tn,{value:m.additional_comment||"",onChange:f=>d(u,"additional_comment",f),placeholder:s.editor.additionalCommentPlaceholder})]})]},u)}),t.jsx("button",{onClick:p,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${r("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:r("desc-fg"),alignSelf:"flex-start"},children:o})]})}function Fx({items:e,onChange:n}){const i=Ie();return t.jsx(sd,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Hx({items:e,onChange:n}){const i=Ie();return t.jsx(sd,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function ad(e){var d,c,p,m,u,g,f;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",i=((p=e.publication_info)==null?void 0:p.year)||"",o=((m=e.current_location)==null?void 0:m.name)||"",s=(u=e.page_count)!=null&&u.number?String(e.page_count.number):((g=e.page_count)==null?void 0:g.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:i,holder:o,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 v=x.related_works.find(y=>y.relation==="part_of");v&&(l.parentWorkId=v.id,l.parentWorkName=v.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 Dx(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 Ux=e=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:m,onAskAI:u,renderSectionActions:g,onDownloadResource:f,downloadStatuses:x,relations:v,onRelationsChange:y,headerExtra:_,className:b,style:w}=e,j=Ie(),[k,C]=h.useState(s),$=a?s:k;h.useEffect(()=>{s!==k&&C(s)},[s]);const S=h.useCallback(()=>{const A=$==="view"?"edit":"view";a?a(A):C(A)},[$,a]),[M,z]=h.useState(null);h.useEffect(()=>{i&&o&&o.getItem(i).then(A=>{A&&z(A)})},[i,o]);const T=n||M,P=h.useMemo(()=>T?ad(T):null,[T]),R=a||!n?t.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:$==="edit"?r("accent-bg"):"transparent",color:r($==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:$==="view"?j.common.switchToEdit:j.common.switchToView,children:$==="view"?j.common.modeEdit:j.common.modeView}):null,N=t.jsxs(t.Fragment,{children:[R,_]});return!T&&!P?t.jsx(nn,{}):$==="view"?t.jsx(no,{data:T,transport:o,onNavigate:p?A=>p(A):void 0,renderLink:m,headerExtra:N,className:b,style:w}):P?t.jsxs("div",{className:b,style:w,children:[N&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:N}),t.jsx(od,{data:P,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:u,renderSectionActions:g,onDownloadResource:f,downloadStatuses:x,relations:v,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:r("muted")},children:j.common.noData})},Vx=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],ld=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const{t:s}=te(),[a,l]=h.useState(null),[d,c]=h.useState(""),[p,m]=h.useState(""),[u,g]=h.useState("idle"),[f,x]=h.useState(""),v=h.useRef(null);h.useEffect(()=>{e&&(l(null),c(""),m(""),g("idle"),x(""))},[e]),h.useEffect(()=>{a&&setTimeout(()=>{var b;return(b=v.current)==null?void 0:b.focus()},100)},[a]),h.useEffect(()=>{if(u==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[u,n]),h.useEffect(()=>{if(!e)return;const b=w=>{w.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const y=async()=>{if(!(!a||!d.trim())){g("submitting"),x("");try{await i({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),g("success")}catch(b){g("error"),x(b instanceof Error?b.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const _=a&&d.trim()&&u!=="submitting";return t.jsx("div",{style:Gx,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:Yx,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:qx,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:Kx,"aria-label":s("feedback.close"),children:"✕"})]}),u==="success"?t.jsxs("div",{style:eb,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:s("feedback.thanks")}),o&&t.jsx("a",{href:o,style:{fontSize:"13px",color:r("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:Vx.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...Xx,...a===b.value?Zx:{}},children:[t.jsx("span",{children:b.icon})," ",s(`feedback.submitType.${b.value}`)]},b.value))}),t.jsx("textarea",{ref:v,value:d,onChange:b=>c(b.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||u==="submitting",style:{...Jx,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:b=>m(b.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||u==="submitting","aria-label":s("feedback.contactLabel"),style:nb}),t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),u==="error"&&t.jsx("div",{style:tb,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:y,disabled:!_,style:{...Qx,opacity:_?1:.6,cursor:_?"pointer":"not-allowed"},children:s(u==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Gx={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Yx={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r("shadow-dialog")},qx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Kx={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Xx={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Zx={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},Jx={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Qx={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},eb={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r("success")},tb={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginBottom:"12px"},nb={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},Or="--bim-feedback-fab-offset",Fr=48,ib=16,rb=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:o=!1,zIndex:s})=>{const{t:a}=te(),[l,d]=h.useState(!1),c=n.bottom??24;return h.useEffect(()=>{if(o||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(Or,`calc(${c+Fr+ib}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(Or)}},[o,c]),t.jsxs(t.Fragment,{children:[!o&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ob,zIndex:s??r("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(ld,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},ob={position:"fixed",width:`${Fr}px`,height:`${Fr}px`,borderRadius:"50%",border:"none",background:r("primary"),color:r("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:r("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},sb=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],cd=({onSubmit:e})=>{const{t:n}=te(),[i,o]=h.useState("bug"),[s,a]=h.useState(""),[l,d]=h.useState(""),[c,p]=h.useState("idle"),[m,u]=h.useState(""),g=h.useRef(null);h.useEffect(()=>{i&&setTimeout(()=>{var v;return(v=g.current)==null?void 0:v.focus()},100)},[i]);const f=async()=>{if(!(!i||!s.trim())){p("submitting"),u("");try{await e({type:i,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),o("bug")}catch(v){p("error"),u(v instanceof Error?v.message:n("feedback.submitFailedRetry"))}}},x=i&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:za,children:t.jsxs("div",{style:pb,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:ub,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:za,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:sb.map(v=>t.jsxs("button",{onClick:()=>o(v.value),style:{...ab,...i===v.value?lb:{}},children:[t.jsx("span",{children:v.icon})," ",n(`feedback.submitType.${v.value}`)]},v.value))}),t.jsx("textarea",{ref:g,value:s,onChange:v=>a(v.target.value),placeholder:n(i?`feedback.placeholder.${i}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...cb}}),t.jsx("input",{type:"text",value:l,onChange:v=>d(v.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:gb}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg")},children:[s.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!x,style:{...db,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:mb,children:m})]})},za={padding:"16px",border:`1px solid ${r("widget-border")}`,borderRadius:"8px",background:r("input-bg")},ab={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"6px",background:"transparent",color:r("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},lb={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},cb={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},db={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},pb={display:"flex",alignItems:"center",gap:"12px",color:r("success"),fontSize:"14px"},ub={background:"none",border:"none",color:r("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},mb={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginTop:"8px"},gb={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Na(e){return typeof e=="function"?e():e??"/api/feedback"}const dd=({resourceId:e,apiUrl:n})=>{const{t:i}=te(),[o,s]=h.useState([]),[a,l]=h.useState(!0),d=h.useCallback(async()=>{const p=Na(n);l(!0);try{const u=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&s(u.items)}catch{}finally{l(!1)}},[e,n]);h.useEffect(()=>{d()},[d]);const c=async p=>{const m=Na(n),u=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||i("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Oo,{items:o,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(cd,{onSubmit:c})})]})},Pi=8;async function Bi(e,n,i,o){const s=Number.isFinite(n)?Math.max(1,Math.floor(n)):1,a=new Array(e.length);let l=0;const d=Array.from({length:Math.min(s,Math.max(1,e.length))},async()=>{for(;l<e.length&&!(o!=null&&o());){const c=l++;a[c]=await i(e[c],c)}});return await Promise.all(d),a}const hb=Si["zh-Hant"].relation,fb=Si["zh-Hant"].lossStatus,xb=Si["zh-Hant"].resourceKind,Wi=yn("zh-Hant"),Fo=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function Ia(e,n=Wi){return e?Fo(hb,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function bb(e,n=Wi){return Fo(fb,e)?n(`detail.lossStatus.${e}`):e}function yb(e,n=Wi){return Fo(xb,e)?n(`detail.resourceKind.${e}`):""}function Ho({authors:e,onNavigate:n,renderLink:i}){const{convert:o}=te(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=po(a.role);return t.jsxs(h.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",o(a.dynasty),"〕"]}),a.entity_id?t.jsx(et,{id:a.entity_id,label:o(a.name),onNavigate:n,renderLink:i,dense:!0}):o(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:o(d)})]},l)})}):null}function pd(e,n,i=Wi){var c,p;const o=lo(e,n),s=o.mirrors.map(m=>({key:m.key,label:m.label,description:m.description,rows:m.items.filter(u=>u.group_role!=="mirror"),mirrors:m.items.filter(u=>u.group_role==="mirror")})),a=o.buckets.filter(m=>m.key==="image"||m.key==="textImage").flatMap(m=>m.items);a.length&&s.push({key:"_images",label:s.length?i("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=o.buckets.find(m=>m.key==="physical"))==null?void 0:c.items)??[];return l.length&&s.push({key:"_physical",label:i("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((p=o.buckets.find(m=>m.key==="text"))==null?void 0:p.items)??[],groups:s}}function ud(e,n){const i=(e.url?fn(e.url):void 0)||e.name,o=Kl(e,n);return o?`${i}(${o})`:i}function Do({item:e,siblings:n,listedVolumeCounts:i}){const{t:o,convert:s}=te(),[a,l]=h.useState(!1),d=wi(e),c=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),p=s(ud(e,n)),m=xn(e),u=Ri(e,o)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,x;const g=(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:o("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?o("colorMode.color"):o("colorMode.bw")})]}):null;return m?t.jsxs("a",{href:m,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),g]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,g]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:s(u)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(bo,{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(g=>!g),children:a?o("detail.collapseVolumes"):o("detail.expandVolumes",{n:d.expected})})})]})}function md({groups:e,listedVolumeCounts:n}){const{t:i,convert:o}=te();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:o(s.label)}),s.description&&t.jsx("p",{className:"bim-d-rg-d",children:o(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(Do,{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:i("detail.mirror")}),s.mirrors.map((a,l)=>{const d=xn(a),c=o(ud(a,s.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?o(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 Mn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function Hr(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Mn.find(o=>n.startsWith(o.key[0])))==null?void 0:i.key}const Ra=12,jb=60,gd=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,railTop:a,back:l,railLinks:d})=>{var K,we,ne;const{t:c,convert:p,messages:m}=te(),u=h.useMemo(()=>uo({_books:e._books}),[e._books]),[g,f]=h.useState(new Map),[x,v]=h.useState(!1),[y,_]=h.useState(""),[b,w]=h.useState(!1),j=u.length<=jb,k=j||x||!!y||b,C=h.useMemo(()=>k?u:u.slice(0,Ra),[u,k]);h.useEffect(()=>{if(!n||C.length===0)return;const B=C.filter(ae=>!g.has(ae));if(B.length===0)return;let Z=!1;return Bi(B,Pi,ae=>n.getItem(ae).then(je=>{const Y=je??{};return[ae,{id:ae,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(()=>[ae,{id:ae}]),()=>Z).then(ae=>{Z||f(je=>{const Y=new Map(je);for(const[be,Ee]of ae)Y.set(be,Ee);return Y})}),()=>{Z=!0}},[n,C,g]);const $=h.useMemo(()=>u.map(B=>g.get(B)??{id:B}),[u,g]),S=u.length>0&&u.every(B=>g.has(B)),M=!!n&&C.some(B=>!g.has(B)),z=j||k,T=h.useMemo(()=>Zl($,e.version_graph,{era:y,scanOnly:b,sort:z?"year":"default"}),[$,e.version_graph,y,b,z]),P=x?T.rows:T.rows.slice(0,Ra),R=T.allRows.filter(B=>B.hasImage).length,N=h.useMemo(()=>(e._related||[]).map(B=>({...B,title:B.title??""})),[e._related]),A=N.filter(B=>B.relation==="collected_in"),H=h.useMemo(()=>{const B=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],Z=ae=>{const je=B.indexOf(ae??"");return je<0?B.length:je};return N.filter(ae=>ae.relation!=="collected_in").map((ae,je)=>({r:ae,i:je})).sort((ae,je)=>Z(ae.r.relation)-Z(je.r.relation)||ae.i-je.i).map(ae=>ae.r)},[N]),G=h.useMemo(()=>{const B=lo(e.resources,e.resource_groups);return[...B.mirrors.flatMap(Z=>Z.items.map(ae=>({r:ae,kind:p(Z.label)}))),...B.buckets.flatMap(Z=>Z.items.map(ae=>({r:ae,kind:p(yb(Z.key,c))})))]},[e.resources,e.resource_groups,p,c]),ie=e.indexed_by||[],le=e.emendated_by||[],V=h.useMemo(()=>{var W,J,$e;const B=[],Z=(J=(W=e.authors)==null?void 0:W[0])==null?void 0:J.dynasty;Z&&B.push({label:c("workPage.fact.written"),value:p(Z)});const ae=Wt(e,m.unit.juan);if(ae){const Te=($e=e.juan_count)==null?void 0:$e.description;B.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(ae),Te&&Te!==ae?t.jsxs("span",{className:"bim-d-meta",children:["(",p(Te),")"]}):null]})})}e.loss_status&&B.push({label:c("workPage.fact.loss"),value:p(bb(e.loss_status,c))});const je=T.allRows.filter(Te=>Te.sortYear!=null),Y=je.length>0?je.reduce((Te,O)=>Te.sortYear<=O.sortYear?Te:O):null;Y!=null&&Y.era.era?B.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&&B.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),le.length&&B.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:le.length})});const be=Ea(e.additional_titles);be.length&&B.push({label:c("workPage.fact.alias"),value:be.map(p).join("、")});const Ee=Ea(e.attached_texts);Ee.length&&B.push({label:c("workPage.fact.attached"),value:Ee.map(p).join("、")});const Fe=(e.additional_works||[]).map(Te=>p(Te.book_title)+(Te.n_juan!=null?` ${Te.n_juan}${m.unit.juan}`:""));return Fe.length&&B.push({label:c("workPage.fact.appendix"),value:Fe.join("、")}),B},[e,p,c,m,M,T.allRows,le.length]),xe=[{value:e._edition_count??u.length,label:c("workPage.stat.editions")},{value:S?R:0,label:c("workPage.stat.hasImage")},{value:ie.length,label:c("workPage.stat.catalogs")}],ee=mo(e),L=ee?[ee.l1,ee.l2,ee.l3,ee.l4].filter(Boolean).map(B=>p(B)):[],Re=e.subtype?m.workSubtype[e.subtype]??p(e.subtype):"",ce=t.jsx(Fn,{title:p(e.title),byline:t.jsx(Ho,{authors:e.authors,onNavigate:i,renderLink:o}),meta:t.jsx(it,{items:[...L,ee!=null&&ee.source?c("workPage.classifiedBy",{source:p(ee.source.split("/")[0])}):"",Re]}),description:(K=e.description)!=null&&K.text?t.jsxs(t.Fragment,{children:[t.jsx(Bt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(we=e.description.sources)!=null&&we.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(B=>({text:p(gg(B)),href:hg(B)})).filter(B=>B.text).map((B,Z)=>t.jsxs(h.Fragment,{children:[Z>0?" · ":null,B.href?t.jsx("a",{href:B.href,target:"_blank",rel:"noopener noreferrer",children:B.text}):B.text]},Z))}):null]}):void 0,stats:xe,facts:V,readAction:s,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(ne=e.appendix)==null?void 0:ne.map((B,Z)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(B.title)}),t.jsx(Bt,{text:B.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},Z))}),me=T.eras.length>=2?[{key:"",label:c("catalog.all")},...T.eras.map(B=>({key:B,label:`${B} ${T.allRows.filter(Z=>Z.era.era===B).length}`}))]:[],se=[];u.length&&se.push({id:"versions",label:c("workPage.sec.versions"),count:u.length}),ie.length&&se.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:ie.length}),A.length&&se.push({id:"collected",label:c("workPage.sec.collected"),count:A.length}),H.length&&se.push({id:"related",label:c("workPage.sec.related"),count:H.length}),G.length&&se.push({id:"resources",label:c("workPage.sec.resources"),count:G.length});const Pe=u.length===0&&ie.length===0,X=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(ot,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(it,{items:[c("workPage.versionsTotal",{n:u.length}),S&&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&&me.length===0&&u.length>1?"":void 0,children:[me.length>0&&t.jsx(Li,{items:me,value:y,onChange:B=>{_(B),v(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(cc,{label:c("workPage.scanOnly"),checked:b,onChange:B=>{w(B),v(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(z?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&Ai(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:P.map(B=>{var Z;return t.jsx(vb,{row:B,measure:(Z=g.get(B.id))==null?void 0:Z.measure_info,loaded:g.has(B.id),onNavigate:i,renderLink:o},`${B.id}:${g.has(B.id)?"r":"p"}`)})})]}),P.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(go,{total:T.rows.length,shown:P.length,unit:c("workPage.moreUnit"),onClick:()=>v(!0)}),T.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),ie.length>0&&t.jsx(kb,{items:ie,transport:n,onNavigate:i,renderLink:o}),Pe&&t.jsx(ot,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),re=(B,Z)=>t.jsx(et,{id:B,label:p(Z),onNavigate:i,renderLink:o,dense:!0}),de=h.useMemo(()=>{const B=new Map;for(const Z of H){const ae=Ia(Z.relation,c);B.set(ae,(B.get(ae)??0)+1)}return B.size>1?[...B.entries()].sort((Z,ae)=>ae[1]-Z[1]).slice(0,4).map(([Z,ae])=>`${p(Z)} ${ae}`).join(" · "):void 0},[H,p,c]),D=t.jsxs(t.Fragment,{children:[t.jsx(en,{id:"collected",title:c("workPage.sec.collected"),items:A.map(B=>re(B.id,B.title))}),t.jsx(en,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:H.length}),sub:de,items:H.map(B=>t.jsxs(t.Fragment,{children:[re(B.id,B.title),t.jsx("span",{className:"bim-d-meta",title:B.note?p(B.note):void 0,children:p(Ia(B.relation,c))})]}))}),t.jsx(en,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:G.map(({r:B,kind:Z})=>{const ae=p((B.url?fn(B.url):void 0)||B.name),je=xn(B);return t.jsxs(t.Fragment,{children:[je?t.jsxs("a",{href:je,target:"_blank",rel:"noopener noreferrer",children:[ae," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ae}),Z&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:Z})]})})})]});return t.jsx(On,{railTop:a,back:l,nav:se,railLinks:d,main:X,card:ce,side:D})};function Ea(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function La(e,n){return n((e.url?fn(e.url):void 0)||e.name)}function vb({row:e,measure:n,loaded:i,onNavigate:o,renderLink:s}){const{t:a,convert:l}=te(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],m=p?La(p,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?xn(u):void 0,f=e.images.map(x=>La(x,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(et,{id:e.id,label:l(e.name),onNavigate:o,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):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${m?"":" bim-d-zt-blank"}`,children:[m||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,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 kb({items:e,transport:n,onNavigate:i,renderLink:o}){const{t:s,convert:a}=te(),[l,d]=h.useState(0),c=Math.min(l,e.length-1),p=e[c],[m,u]=h.useState(new Map);return h.useEffect(()=>{if(!n)return;const g=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(g.length===0)return;let f=!1;return Promise.all(g.map(x=>n.getItem(x).then(v=>{var y,_;return[x,((_=(y=v==null?void 0:v.authors)==null?void 0:y[0])==null?void 0:_.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{f||u(new Map(x.filter(([,v])=>v)))}),()=>{f=!0}},[n,e]),t.jsx(ot,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(it,{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((g,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(g.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:m.get(g.source_bid??"")?a(m.get(g.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(g.source)].slice(0,9).map((x,v)=>t.jsx("span",{children:x},v))})]})},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(it,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(et,{id:p.source_bid,label:a(p.source),onNavigate:i,renderLink:o,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:xt(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:xt(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:xt(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 wb(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 Sb(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[e.id],note:i.note}}function Aa(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _b(e,n,i){const[o,s]=[e,n.book_id].sort();return{id:`sibling:${o}-${s}:${i}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $b(e,n){var p;if(n==="all")return null;const i=(p=e.collections)==null?void 0:p[n],o=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,a=o||s||!!(i!=null&&i.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(!i||!a)return null;const l=o?new Set(i.groups):null,d=new Set(i.book_ids??[]);if(l&&e.node_groups)for(const[m,u]of Object.entries(e.node_groups))l.has(u)&&d.add(m);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),l){c||(c=new Set);for(const m of e.hypothetical_nodes??[])m.group&&l.has(m.group)&&c.add(m.id)}return{books:d,hypos:c}}function hi(e,n,i){const o=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const a=new Set(o.excluded_books??[]),l=o.node_groups??{},d=$b(o,i??o.default_collection??"all"),c=d!==null,p=(d==null?void 0:d.books)??null,m=(d==null?void 0:d.hypos)??null,u=new Set,g=new Set;if(c){const j=new Map(n.map(z=>[z.id,z])),k=new Map((o.hypothetical_nodes??[]).map(z=>[z.id,z])),C=z=>{const T=j.get(z);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(R=>R.ref);const P=k.get(z);return P?(P.derived_from??[]).map(R=>R.ref):[]},$=z=>k.has(z)?!m||m.has(z):!p||p.has(z),S=new Set,M=z=>{if(!S.has(z)){S.add(z);for(const T of C(z))a.has(T)||($(T)||(k.has(T)?g.add(T):j.has(T)&&u.add(T)),M(T))}};for(const z of n)p&&p.has(z.id)&&!a.has(z.id)&&M(z.id);for(const z of o.hypothetical_nodes??[])m&&m.has(z.id)&&M(z.id)}const f=n.filter(j=>!a.has(j.id)).filter(j=>!p||p.has(j.id)||u.has(j.id)).map(j=>{const k=Sb(j,l);return k&&u.has(j.id)&&(k.bridge=!0),k}).filter(j=>j!==null),x=(o.hypothetical_nodes??[]).filter(j=>!m||m.has(j.id)||g.has(j.id)).map(j=>{const k=wb(j);return g.has(j.id)&&(k.bridge=!0),k}),v=[...f,...x],y=new Set(v.map(j=>j.id)),_=new Set,b=[],w=j=>{_.has(j.id)||!y.has(j.source)||!y.has(j.target)||(_.add(j.id),b.push(j))};for(const j of n)a.has(j.id)||!j.lineage||p&&!p.has(j.id)&&!u.has(j.id)||((j.lineage.derived_from??[]).forEach((k,C)=>{w(Aa(j.id,k,C))}),(j.lineage.related_to??[]).forEach((k,C)=>{w(_b(j.id,k,C))}));for(const j of o.hypothetical_nodes??[])m&&!m.has(j.id)&&!g.has(j.id)||(j.derived_from??[]).forEach((k,C)=>{w(Aa(j.id,k,C))});return{nodes:v,edges:b,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(a)}}function hd(e,n,i){const o=(e??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function Cb(e,n){const i=[],o=e.version_graph;if(!o)return i;const s=new Set(n.map(c=>c.id)),a=new Set((o.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...a]),d=(c,p)=>{l.has(p.ref)||i.push(`${c}: derived_from.ref "${p.ref}" 未在 books 或 hypothetical_nodes 中找到`),p.ref_type==="book"&&!s.has(p.ref)&&i.push(`${c}: derived_from.ref "${p.ref}" 标记为 book 但不在 books 列表中`),p.ref_type==="hypothetical"&&!a.has(p.ref)&&i.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(m=>d(p,m)),(c.lineage.related_to??[]).forEach(m=>{s.has(m.book_id)||i.push(`${p}: related_to.book_id "${m.book_id}" 不在 books 列表中`)})}for(const c of o.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(m=>d(p,m))}return i}const fd=({graph:e,renderLink:n,className:i,style:o})=>{const{t:s,convert:a}=te();if(!e.nodes.length)return t.jsx("div",{style:{...Fb,...o},className:i,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 v=d.get(x)??[];v.push(f),d.set(x,v)}const c=new Map(e.nodes.map(f=>[f.id,f])),p=new Map,m=[];for(const f of e.nodes)if(f.group){const x=p.get(f.group)??[];x.push(f),p.set(f.group,x)}else m.push(f);const u=(f,x)=>(f.year??9999)-(x.year??9999);p.forEach(f=>f.sort(u)),m.sort(u);const g=e.groups.filter(f=>p.has(f.id));return t.jsxs("div",{className:i,style:{...zb,...o},children:[e.title&&t.jsx("div",{style:Nb,children:a(e.title)}),e.description&&t.jsx("div",{style:Ib,children:a(e.description)}),g.map(f=>t.jsx(Ma,{label:f.label,color:f.color,nodes:p.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},f.id)),m.length>0&&t.jsx(Ma,{label:s("lineage.otherGroup"),nodes:m,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},Ma=({label:e,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=te();return t.jsxs("div",{style:Rb,children:[t.jsx("div",{style:{...Eb,borderLeftColor:n??r("widget-border")},children:d(e)}),i.map(c=>t.jsx(Tb,{node:c,incoming:o.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Tb=({node:e,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=te();return t.jsxs("div",{style:{...Lb,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?r("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Ab,children:[t.jsx("span",{style:Mb,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Pb,children:hd(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Bb,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:Wb,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ob,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:Ba,children:[t.jsx("div",{style:Wa,children:d("lineage.sources")}),n.map(p=>{const m=o.get(p.source);return t.jsxs("div",{style:Oa(p.confidence),children:[t.jsx("span",{style:Fa,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)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(Pa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:Ha,children:["· ",c(p.evidence)]})]},p.id)})]}),i.length>0&&t.jsxs("div",{style:Ba,children:[t.jsx("div",{style:Wa,children:d("lineage.related")}),i.map(p=>{const m=p.source===e.id?p.target:p.source,u=o.get(m);return t.jsxs("div",{style:Oa(p.confidence),children:[t.jsx("span",{style:Fa,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)??m)}),t.jsx(Pa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:Ha,children:["· ",c(p.evidence)]})]},p.id)})]})]})},zn=({children:e,tone:n="default"})=>{const o={default:{bg:r("tag-bg"),fg:r("fg")},warn:{bg:r("warn-bg"),fg:r("warn-fg")},info:{bg:r("info-bg"),fg:r("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:o.bg,color:o.fg,marginRight:"4px"},children:e})},Pa=({level:e})=>{const{t:n}=te(),o={certain:{key:"certain",color:r("confidence-certain")},consensus:{key:"consensus",color:r("confidence-consensus")},probable:{key:"probable",color:r("confidence-probable")},disputed:{key:"disputed",color:r("confidence-disputed")}}[e];return o?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:n(`lineage.confidence.${o.key}`)}):null},zb={fontSize:"14px",color:r("fg")},Nb={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ib={fontSize:"13px",color:r("muted"),marginBottom:"16px",lineHeight:1.6},Rb={marginBottom:"16px"},Eb={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r("fg")},Lb={border:`1px solid ${r("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r("bg")},Ab={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Mb={fontSize:"15px",fontWeight:600},Pb={fontSize:"12px",color:r("muted")},Bb={marginBottom:"6px"},Wb={fontSize:"12px",color:r("muted"),margin:"2px 0"},Ob={fontSize:"12px",color:r("muted"),fontStyle:"italic",margin:"4px 0"},Ba={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r("widget-border")}`},Wa={fontSize:"11px",color:r("muted"),marginBottom:"2px"},Oa=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Fa={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r("tag-bg"),color:r("fg"),borderRadius:"3px",marginRight:"6px"},Ha={fontSize:"11px",color:r("muted")},Fb={padding:"20px",textAlign:"center",color:r("muted"),fontSize:"13px"},xd=({selectedNodeId:e,...n})=>{const{t:i}=te(),[o,s]=h.useState("loading"),[a,l]=h.useState(null);return h.useEffect(()=>{let d=!1;return Hb().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),o==="loading"?t.jsx("div",{style:Ua,children:i("lineage.graphLoading")}):o==="missing"||!a?t.jsxs("div",{style:Ua,children:[t.jsx("div",{children:Da(i("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:Da(i("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Db,{modules:a,selectedNodeId:e,...n})};function Da(e,n){return e.split(/(\{\w+\})/).map((i,o)=>{const s=/^\{(\w+)\}$/.exec(i);return t.jsx(h.Fragment,{children:s&&s[1]in n?n[s[1]]:i},o)})}async function Hb(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Db=({graph:e,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:p,Handle:m,Position:u,BaseEdge:g,EdgeLabelRenderer:f,getSmoothStepPath:x,dagre:v}=l,y=h.useMemo(()=>({lineage:C=>{var H,G,ie,le;const $=((H=C.data)==null?void 0:H.stepPosition)??.85,[S,M,z]=x({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:$,borderRadius:5}),T=!!((G=C.data)!=null&&G.isSibling),P=T?M:C.targetX-18,R=T?z:C.targetY-12,N=(ie=C.data)==null?void 0:ie.labelStyle,A=(le=C.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(g,{id:C.id,path:S,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${P}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:r("bg"),border:`0.5px solid ${r("widget-border")}`,...A,...N},children:C.label})})]})}}),[g,f,x]),_=h.useMemo(()=>({version:C=>{const{t:$}=te(),S=C.data,M=S.kind==="hypothetical",z=S.status==="lost",T=S.isSelected,P=S.bridge,R=S.borderColor??r("muted"),N=P||M?"dashed":"solid",A=P?.5:z?.6:1;return t.jsxs("div",{style:{background:r(P?"bg-subtle":"bg"),border:`2px ${N} ${T?r("primary"):R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:T?r("shadow-node-selected"):M||P?"none":r("shadow-node")},title:P?$("lineage.bridgeTitle"):void 0,children:[t.jsx(m,{type:"target",position:u.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:M||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:r("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:r("aux-fg"),lineHeight:1.2},children:hd(S.yearText,void 0,S.uncertain)}),z&&t.jsx("div",{style:{fontSize:9,color:r("lost-fg"),marginTop:1},children:$("lineage.lost")}),t.jsx(m,{type:"source",position:u.Right,style:{visibility:"hidden"}})]})}}),[m,u]),{convert:b}=te(),{rfNodes:w,rfEdges:j}=h.useMemo(()=>Ub(e,v,n,a,b),[e,v,n,a,b]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:o,children:t.jsxs(d,{nodes:w,edges:j,nodeTypes:_,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 Ub(e,n,i,o,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(_=>[_.id,_.color??r("muted")]));for(const _ of e.nodes)c.setNode(_.id,{width:160,height:90});const m=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const _ of e.edges)_.kind==="derive"&&(m.has(_.relation)||c.setEdge(_.source,_.target));n.layout(c);const u=e.nodes.map(_=>{const b=c.node(_.id),w=o?_.id===o:void 0,j={kind:_.kind,label:s(_.label),bookId:_.kind==="book"?_.id:void 0,yearText:s(_.year_text??Gb(_)),uncertain:_.year_uncertain,category:_.category,status:_.status,borderColor:_.group?p.get(_.group):void 0,renderLink:i,isSelected:w,description:s(_.description),bridge:_.bridge};return{id:_.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:j,draggable:!1,selected:w}}),g=.78,f=.06,x=new Map;for(const _ of e.edges)_.kind==="derive"&&(x.has(_.source)||x.set(_.source,[]),x.get(_.source).push(_));const v=new Map;for(const[_,b]of x){if(b.length<=1)continue;const w=[...b].sort((k,C)=>{var M,z;const $=((M=c.node(k.target))==null?void 0:M.y)??0,S=((z=c.node(C.target))==null?void 0:z.y)??0;return $-S}),j=w.length;w.forEach((k,C)=>{const $=(C-(j-1)/2)*f;v.set(k.id,g+$)})}const y=e.edges.map(_=>Vb(_,v.get(_.id),s));return{rfNodes:u,rfEdges:y}}function Vb(e,n,i=o=>o??""){const o=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=Yb(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:r("fg")},isSibling:s,stepPosition:n},style:{stroke:a,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Gb(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Yb(e){switch(e){case"certain":return r("confidence-certain");case"consensus":return r("lineage-edge-consensus");case"probable":return r("confidence-probable");case"disputed":return r("confidence-disputed");default:return r("muted")}}const Ua={padding:"40px 20px",textAlign:"center",color:r("muted"),fontSize:"13px",border:`1px dashed ${r("widget-border")}`,borderRadius:8,background:r("bg")},Uo=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:m,style:u})=>{var j;const{t:g,convert:f}=te(),[x,v]=h.useState(n),y=k=>{v(k),a==null||a(k)},_=(()=>{if(!c)return[];const k=Object.entries(c);return k.length===0||c.all?k:[...k,["all",{label:g("lineage.collectionAll"),description:g("lineage.collectionAllDesc")}]]})(),b=!!(d&&_.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r("muted"),textAlign:"center"},children:g("lineage.empty")});const w=l?(j=c==null?void 0:c[l])==null?void 0:j.description:void 0;return t.jsxs("div",{className:m,style:u,children:[t.jsxs("div",{style:qb,children:[t.jsx("button",{onClick:()=>y("list"),style:fr(x==="list"),children:g("lineage.modeList")}),t.jsx("button",{onClick:()=>y("graph"),style:fr(x==="graph"),children:g("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:r("muted"),marginRight:4},children:g("lineage.collectionLabel")}),_.map(([k,C])=>{const $=p==null?void 0:p[k];return t.jsxs("button",{onClick:()=>d==null?void 0:d(k),style:fr(l===k),title:C.description?f(C.description):void 0,children:[f(C.label),$!=null?` ${$}`:""]},k)})]})]}),b&&w&&t.jsx("div",{style:{fontSize:12,color:r("muted"),marginBottom:8,padding:"4px 8px",background:r("bg-subtle"),borderRadius:4},children:f(w)}),x==="list"?t.jsx(fd,{graph:e,renderLink:i}):t.jsx(xd,{graph:e,renderLink:i,height:o,selectedNodeId:s})]})},qb={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},fr=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${r("widget-border")}`,borderRadius:4,background:e?r("primary"):"transparent",color:r(e?"primary-fg":"fg"),cursor:"pointer"}),Va=40,Ga=2,Kb=9,Xb=new Set(["certain","consensus","probable","disputed"]);function xr(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const bd=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:m})=>{var $e,Te,O,fe,oe,Se,Le,He,Ye,qe,Xe;const u=Ie(),{t:g,convert:f}=te(),[x,v]=h.useState(null),[y,_]=h.useState(new Map),[b,w]=h.useState([]),[j,k]=h.useState(new Map),[C,$]=h.useState(!1),[S,M]=h.useState("flow"),[z,T]=h.useState(null);h.useEffect(()=>{if(!n||!e.work_id){v(null);return}let I=!1;return n.getItem(e.work_id).then(U=>{!I&&U&&U.type==="work"&&v(U)}).catch(()=>{}),()=>{I=!0}},[n,e.work_id]),h.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let I=!1;return n.getLineageGraph(e.work_id).then(U=>{I||T(U&&U.nodes.length>1?U:null)}).catch(()=>{I||T(null)}),()=>{I=!0}},[n,e.work_id]),h.useEffect(()=>{const I=e._collections||[];if(!n||I.length===0){_(new Map);return}let U=!1;return Promise.all(I.map(ue=>{const Ce=ue.id;return n.getItem(Ce).then(ye=>[Ce,ye]).catch(()=>[Ce,null])})).then(ue=>{if(U)return;const Ce=new Map;for(const[ye,ge]of ue)ge&&Ce.set(ye,ge);_(Ce)}),()=>{U=!0}},[n,e._collections]);const P=h.useMemo(()=>{const I=new Set([...x?uo(x):[],...e.related_books||[]]);return I.add(e.id),[...I]},[x,e.related_books,e.id]),R=P.length-1;h.useEffect(()=>{if(!n||R<=0){w([]);return}const I=P.length<=Va,U=I?P:P.slice(0,8);let ue=!1;return Promise.all(U.map(Ce=>Ce===e.id?Promise.resolve({id:Ce,title:e.title,edition:e.edition,year:bi(e)}):n.getItem(Ce).then(ye=>{const ge=ye??{};return{id:Ce,title:ge.title,edition:ge.edition,year:ye?bi(ge):void 0}}).catch(()=>({id:Ce})))).then(Ce=>{if(ue)return;const ye=Ce.filter(ge=>ge.id===e.id||ge.title||ge.edition);I&&ye.sort((ge,Ge)=>(ge.year??1/0)-(Ge.year??1/0)),w(ye)}),()=>{ue=!0}},[n,P,R,e]);const N=e.lineage,A=h.useMemo(()=>[...((N==null?void 0:N.derived_from)||[]).filter(I=>I.ref_type==="book").map(I=>I.ref),...((N==null?void 0:N.related_to)||[]).map(I=>I.book_id)].filter(Boolean),[N]);h.useEffect(()=>{if(!n||A.length===0){k(new Map);return}let I=!1;return Promise.all(A.map(U=>n.getItem(U).then(ue=>[U,{id:U,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[U,{id:U}]))).then(U=>{I||k(new Map(U))}),()=>{I=!0}},[n,A]);const H=h.useMemo(()=>pd(e.resources,e.resource_groups,g),[e.resources,e.resource_groups,g]),G=H.groups.reduce((I,U)=>I+U.rows.length+U.mirrors.length,0),ie=H.groups.length>0&&H.groups.every(I=>I.key==="_physical"),le=Wn(e),V=ic(e),F=Wt(e,u.unit.juan),xe=new Set((e._collections||[]).map(I=>Ln(I.vol).length).filter(I=>I>0)),ee=I=>{var Ce;const U=(Ce=e.base_edition)==null?void 0:Ce.find(ye=>ye.book_id===I&&ye.name);if(U!=null&&U.name)return U.name;const ue=j.get(I);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},L=h.useMemo(()=>{var ke,Ae,Be,Ne,he;const I=[];V&&I.push({label:g("bookPage.fact.editionType"),value:f(V),title:e.edition_type||(ke=e.lineage)!=null&&ke.category?void 0:g("bookPage.inferredFromEdition")}),(Ae=e.publication_info)!=null&&Ae.details?I.push({label:g("bookPage.fact.publication"),value:f(e.publication_info.details)}):(le.era||le.reign)&&I.push({label:g("bookPage.fact.era"),value:f([le.era,le.reign].filter(Boolean).join(" ")),title:le.source==="edition"?g("bookPage.inferredFromEdition"):void 0}),F&&I.push({label:g("bookPage.fact.measure"),value:f(F)});const U=(e._collections||[]).flatMap(ve=>Ln(ve.vol));U.length&&I.push({label:g("bookPage.fact.volumes"),value:g("bookPage.volumesValue",{range:Ei(U,u.unit.volume),unit:u.unit.volume,n:U.length})});const ue=(((Be=e.lineage)==null?void 0:Be.derived_from)||[]).find(ve=>ve.relation==="底本"&&ve.ref_type==="book");ue&&ee(ue.ref)&&I.push({label:g("bookPage.fact.baseEdition"),value:t.jsx(et,{id:ue.ref,label:f(ee(ue.ref)),onNavigate:i,renderLink:o,dense:!0})});const Ce=(e.base_edition||[]).filter(ve=>ve&&ve.name);for(const ve of["底本","配補","參校"]){if(ve==="底本"&&ue&&ee(ue.ref))continue;const Ue=Ce.filter(We=>We.role===ve);Ue.length&&I.push({label:f(ve),value:Ue.map((We,st)=>t.jsxs(h.Fragment,{children:[st>0&&"、",We.book_id?t.jsx(et,{id:We.book_id,label:f(We.name),onNavigate:i,renderLink:o,dense:!0}):f(We.name)]},st))})}const ye=(e.provenance||[]).filter(ve=>ve&&ve.institution),ge=(e.resources||[]).filter(ve=>Pt(ve).includes("physical"));if(ye.length){I.push({label:g("bookPage.fact.holdings"),value:ye.slice(0,2).map(We=>f(We.institution)).join("、")+(ye.length>2?g("bookPage.andMorePlaces",{n:ye.length}):"")});const ve=ye.filter(We=>We.call_number).slice(0,2).map(We=>`${f(We.institution)} ${We.call_number}`);ve.length&&I.push({label:g("bookPage.fact.callNumber"),value:ve.join(";")+(ye.filter(We=>We.call_number).length>2?"…":"")});const Ue=ye.flatMap(We=>We.seals||[]).filter(Boolean);Ue.length&&I.push({label:g("bookPage.fact.seals"),value:f(Ue.join("、"))})}else ge.length?I.push({label:g("bookPage.fact.holdings"),value:ge.slice(0,2).map(ve=>f(ve.name)).join("、")+(ge.length>2?g("bookPage.andMorePlaces",{n:ge.length}):"")}):(Ne=e.current_location)!=null&&Ne.name&&I.push({label:g("bookPage.fact.holdings"),value:f(e.current_location.name)});const Ge=e.physical_description;if(Ge){const ve=[[g("bookPage.fact.leafStyle"),Ge.leaf_style],[g("bookPage.fact.binding"),Ge.binding],[g("bookPage.fact.dimensions"),Ge.dimensions],[g("bookPage.fact.condition"),Ge.condition]];for(const[Ue,We]of ve)We&&We.trim()&&I.push({label:Ue,value:f(We)})}(he=e.page_count)!=null&&he.description&&I.push({label:u.label.pageCount,value:f(e.page_count.description)});const Q=[...Er(e.additional_titles),...Er(e.attached_texts)];return Q.length&&I.push({label:g("bookPage.fact.aliases"),value:Q.map(f).join("、")}),I},[e,f,u,g,le,V,F,j,i,o]),Re=f(e.title),ce=e.edition?f(e.edition):void 0,me=(($e=e.lineage)==null?void 0:$e.year_text)||"",se=t.jsx(Fn,{kind:g("bookPage.kind"),title:Re,subtitle:ce,byline:t.jsx(Ho,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:i,renderLink:o}),meta:(()=>{const I=[V?f(V):"",le.era?f([le.era,le.reign].filter(Boolean).join("")):"",F?f(F):""].filter(Boolean);return I.length?t.jsx("span",{className:"bim-d-tags",children:I.map((U,ue)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ue,2)}`,children:U},ue))}):null})(),description:(Te=e.description)!=null&&Te.text?t.jsx(Bt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:fo((O=e.description)==null?void 0:O.text)?6:void 0,facts:L,readAction:s,secondaryAction:s&&G>0&&!ie?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:g("bookPage.viewImages")}):void 0,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),Pe=e._collections||[],X=(a==null?void 0:a.chapters)||[],re=f(X[0]&&xr(X[0].title)[0].slice(-1)||"")||g("bookPage.chapterUnit"),de=g("bookPage.chapterCount",{n:X.length,unit:re}),D=!!((fe=N==null?void 0:N.derived_from)!=null&&fe.length||(oe=N==null?void 0:N.related_to)!=null&&oe.length||(Se=e.appendix)!=null&&Se.length),K=[],we=g(ie?"bookPage.sec.physical":"bookPage.sec.images");(X.length||H.text.length||l)&&K.push({id:"fulltext",label:g("bookPage.sec.fulltext"),count:X.length?de:void 0}),H.groups.length&&K.push({id:"images",label:we,count:G}),D&&K.push({id:"lineage",label:g("bookPage.sec.lineage")}),Pe.length&&K.push({id:"collections",label:g("section.containedIn"),count:Pe.length}),(Le=e.location_history)!=null&&Le.length&&K.push({id:"provenance",label:g("section.locationHistory")});const ne=I=>(d==null?void 0:d(I))??null,B=X[0],Z=B?ne(B.file):null,ae=C?X:X.slice(0,Kb),je=(I,U,ue)=>I?t.jsx("a",{className:ue,href:I.href??"#",onClick:I.onClick?Ce=>{Ce.metaKey||Ce.ctrlKey||(Ce.preventDefault(),I.onClick())}:void 0,children:U}):t.jsx("span",{className:ue,children:U}),Y=t.jsxs(t.Fragment,{children:[(X.length>0||H.text.length>0||l)&&t.jsxs(ot,{id:"fulltext",title:g("bookPage.sec.fulltext"),meta:X.length>0?t.jsx(it,{items:[de,(He=a==null?void 0:a.source)!=null&&He.name?g("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!B&&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"})]}),B&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:g("bookPage.readFrom",{ch:f(xr(B.title)[0])||g("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((B.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),je(Z,t.jsxs(t.Fragment,{children:[g("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),X.length>1&&t.jsx("ul",{className:"bim-d-chap",children:ae.map(I=>{const[U,ue]=xr(I.title);return t.jsx("li",{children:je(ne(I.file),t.jsxs(t.Fragment,{children:[U&&t.jsx("b",{children:f(U)}),f(ue||I.file)]}))},I.file)})}),X.length>ae.length&&t.jsx(ho,{label:g("detail.expandRest",{n:X.length-ae.length,unit:re}),onClick:()=>$(!0)}),H.text.length>0&&t.jsxs(t.Fragment,{children:[(X.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:g("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:H.text.map((I,U)=>t.jsx(Do,{item:I,siblings:H.text,listedVolumeCounts:xe},`${I.id||I.url||I.name}-${U}`))})})]})]}),H.groups.length>0&&t.jsx(ot,{id:"images",title:we,meta:t.jsx(it,{items:[H.groups.length>1?g("bookPage.groupCount",{n:H.groups.length}):"",g("bookPage.placeCount",{n:G})]}),children:t.jsx(md,{groups:H.groups,listedVolumeCounts:xe})}),D&&t.jsx(ot,{id:"lineage",title:g("bookPage.sec.lineage"),meta:(Ye=N==null?void 0:N.derived_from)!=null&&Ye.length?g("bookPage.lineageMeta"):void 0,action:z?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":g("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>M("flow"),children:g("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>M("graph"),children:g("bookPage.viewGraph")})]}):void 0,children:S==="graph"&&z?t.jsx(Uo,{graph:z,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(I,U)=>t.jsx(et,{id:I,label:f(U),onNavigate:i,renderLink:o,dense:!0})}):t.jsx(Jb,{data:e,heading:ce||Re,yearText:me,refName:ee,onNavigate:i,renderLink:o})}),Pe.length>0&&t.jsx(ot,{id:"collections",title:g("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Pe.map((I,U)=>{const ue=I.id,Ce=Ln(I.vol),ye=y.get(ue),ge=ug(ye);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(et,{id:ue,label:ye?f(ye.title):ue,onNavigate:i,renderLink:o,dense:!0}),Ce.length>0&&t.jsx(Zb,{volumes:Ce,unit:u.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&&g("bookPage.totalOf",{n:ge,unit:u.unit.bu})})]},`${ue}-${U}`)})})})}),(qe=e.location_history)!=null&&qe.length?t.jsx(ot,{id:"provenance",title:g("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((I,U)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(I.name)}),([I.start_date,I.end_date].filter(Boolean).join("—")||I.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(it,{items:[[I.start_date,I.end_date].filter(Boolean).join("—"),I.description?f(I.description):""]})})]},U))})}):null,K.length===0&&t.jsx(ot,{title:g("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:g("bookPage.emptyText")})})]}),be=b.findIndex(I=>I.id===e.id),Ee=P.length<=Va,Fe=Ee&&be>=0?b.slice(Math.max(0,be-Ga),be+Ga+1):b.filter(I=>I.id!==e.id),W=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(u.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(et,{id:x.id,label:f(x.title),onNavigate:i,renderLink:o})}),t.jsx(it,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(I=>`${I.dynasty?`〔${f(I.dynasty)}〕`:""}${f(I.name)}`),f(Wt(x,u.unit.juan)),x._edition_count?g("bookPage.editionCount",{n:x._edition_count}):""]}),((Xe=x.description)==null?void 0:Xe.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&&Fe.length>0&&t.jsxs("div",{children:[t.jsx(en,{id:"siblings",timeline:!0,title:Ee?g("bookPage.siblings"):u.relation.siblingVersions,meta:Ee?g("bookPage.byEra"):g("bookPage.kindCount",{n:R}),cap:Fe.length,items:Fe.map(I=>I.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(I.edition||I.title||I.id)}):t.jsx(et,{id:I.id,label:f(I.edition||I.title||I.id),onNavigate:i,renderLink:o,dense:!0})),metas:Fe.map(I=>[I.year!=null?I.year<0?g("detail.bce",{n:-I.year}):String(I.year):"",I.id===e.id?g("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:Fe.findIndex(I=>I.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(et,{id:x.id,label:g("bookPage.viewAllInWork",{n:P.length}),onNavigate:i,renderLink:o,dense:!0})})]})]}),J=e.work_id?t.jsx(lc,{caption:u.section.belongsToWork,children:t.jsx(et,{id:e.work_id,label:x?f(x.title):" ",onNavigate:i,renderLink:o,dense:!0})}):void 0;return t.jsx(On,{railTop:c,back:p,up:J,nav:K,railLinks:m,main:Y,card:se,side:W})};function Zb({volumes:e,unit:n}){const{t:i}=te();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i("bookPage.volumeRange",{range:Ei(e,n),unit:n}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i("bookPage.volumeCount",{n:e.length,unit:n})]})]})}function Jb({data:e,heading:n,yearText:i,refName:o,onNavigate:s,renderLink:a}){var _;const{t:l,convert:d}=te(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],m=p.filter(b=>b.ref_type!=="book"),u=p.filter(b=>b.ref_type==="book"&&b.relation==="底本"),g=p.filter(b=>b.ref_type==="book"&&b.relation!=="底本"),f=(c==null?void 0:c.related_to)||[],x=p.length>0||f.length>0,v=b=>b&&Xb.has(b)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${b}`)}):"",y=(b,w)=>t.jsx(et,{id:b,label:d(w||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:[m.map((b,w)=>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),v(b.confidence)]})]})},`a-${w}`)),u.map((b,w)=>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,o(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),v(b.confidence)]})]})},`b-${w}`)),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}),i&&t.jsx("span",{className:"bim-d-lf-yr",children:d(i)})]}),g.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:g.map((b,w)=>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,o(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),v(b.confidence)]})]},w))})]}),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,w)=>t.jsxs("span",{className:"bim-d-lf-chip",title:b.evidence?d(b.evidence):void 0,children:[y(b.book_id,o(b.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(b.relation)})]},w))})]})]}),(_=e.appendix)==null?void 0:_.map((b,w)=>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(Bt,{text:b.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${w}`)),(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 Nn=16,Qb=200,ey=16,yd=({data:e,catalog:n,transport:i,onNavigate:o,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var be,Ee,Fe,W,J,$e,Te;const{t:p,convert:m,messages:u}=te(),[g,f]=h.useState(""),[x,v]=h.useState(!1),[y,_]=h.useState(null),[b,w]=h.useState(""),[j,k]=h.useState(!1),C=h.useMemo(()=>tc(e,n),[e,n]),$=h.useMemo(()=>ec(e),[e]),[S,M]=h.useState(new Map),z=!!i&&C.rows.length>0&&C.rows.length<=Qb,T=z&&(C.rows.length<=Nn||j),P=T&&C.rows.every(O=>!O.id||S.has(O.id)),R=O=>{var fe;return Hr(O?(fe=S.get(O))==null?void 0:fe.l1:void 0)},N=h.useMemo(()=>{const O=g.trim(),fe=O?m(O):"";return C.rows.filter(oe=>{var Le,He;if(b&&Hr(oe.id?(Le=S.get(oe.id))==null?void 0:Le.l1:void 0)!==b)return!1;if(!fe)return!0;const Se=oe.id&&((He=S.get(oe.id))==null?void 0:He.title)||oe.title;return m(Se).includes(fe)||(oe.subItems||[]).some(Ye=>m(Ye).includes(fe))})},[C.rows,g,b,S,m]),A=x?N:N.slice(0,Nn),H=h.useMemo(()=>(T?C.rows:A).filter(O=>O.id&&!S.has(O.id)).map(O=>O.id),[T,C.rows,A,S]);h.useEffect(()=>{if(!i||H.length===0)return;let O=!1;const fe=H.slice(0,ey);return Bi(fe,Pi,oe=>i.getItem(oe).then(Se=>{var Ye,qe;const Le=Se??{},He={title:Le.title,edition:Le.edition,authors:Le.authors,measure:Se?Wt(Se,u.unit.juan):void 0,versionCount:Le._edition_count??((Ye=Le._books)==null?void 0:Ye.length),l1:((qe=mo(Le))==null?void 0:qe.l1)||void 0};return[oe,He]}).catch(()=>[oe,{}]),()=>O).then(oe=>{O||M(Se=>{const Le=new Map(Se);for(const[He,Ye]of oe)Le.set(He,Ye);return Le})}),()=>{O=!0}},[i,H,u.unit.juan]);const G=(be=(e.contained_in||[])[0])==null?void 0:be.id;h.useEffect(()=>{if(!G){_(null);return}if(_({id:G}),!i)return;let O=!1;return i.getItem(G).then(fe=>{O||_({id:G,title:fe==null?void 0:fe.title})}).catch(()=>{}),()=>{O=!0}},[i,G]);const ie=h.useMemo(()=>pd(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),le=ie.text.length+ie.groups.reduce((O,fe)=>O+fe.rows.length+fe.mirrors.length,0),V=$.works,F=new Set(C.rows.map(O=>O.id).filter(Boolean)),xe=V.length>0&&!V.every(O=>F.has(O.id)),ee=(()=>{const O=C.rows.map(fe=>fe.edition).filter(Boolean);return O.length>1&&new Set(O).size===1})(),L=C.rows.some(O=>O.volumes.length>0||O.expected!=null),Re=$.total,ce=$.truncated?Re:C.rows.length,me=Wt(e,u.unit.juan),se=e.count,Pe=O=>typeof O=="number"&&Number.isFinite(O)?O:null,X=Pe(se==null?void 0:se.juan)??Pe((Ee=e.juan_count)==null?void 0:Ee.number),re=Pe(se==null?void 0:se.ce)??(C.totalVolumes||null),de=[{value:ce,label:p("collectionPage.stat.titles")},{value:X??0,label:u.unit.juan},{value:re??0,label:u.unit.volume}],D=h.useMemo(()=>{var oe,Se;const O=[];if((oe=e.publication_info)!=null&&oe.details&&O.push({label:p("collectionPage.fact.publication"),value:m(e.publication_info.details)}),Re&&(Re!==C.rows.length||$.truncated)){const Le=e._member_type==="Book"?p("collectionPage.member.Book"):e._member_type==="Work"?p("collectionPage.member.Work"):p("collectionPage.member.other");O.push({label:Le,value:`${Re} ${u.unit.bu}`,title:p("collectionPage.memberNote")})}const fe=[Pe(se==null?void 0:se.zhong)!=null?p("collectionPage.nZhong",{n:se.zhong}):"",Pe(se==null?void 0:se.han)!=null?p("collectionPage.nHan",{n:se.han}):""].filter(Boolean);return fe.length&&O.push({label:p("collectionPage.fact.expected"),value:fe.join(" ")}),X==null&&me&&O.push({label:p("collectionPage.fact.measure"),value:m(me),title:(Se=e.juan_count)!=null&&Se.description?m(e.juan_count.description):void 0}),O},[e,Re,$.truncated,C.rows.length,X,me,se,m,p,u]),K=h.useMemo(()=>{if(!P)return[];const O=new Map;for(const oe of C.rows){const Se=R(oe.id);Se&&O.set(Se,(O.get(Se)??0)+1)}const fe=Mn.filter(oe=>(O.get(oe.key)??0)>0);return fe.length<2?[]:[{key:"",label:`${u.catalog.all} ${ce}`},...fe.map(oe=>({key:oe.key,label:`${oe.label} ${O.get(oe.key)}`}))]},[P,C.rows,S,u]),we=h.useMemo(()=>{if(!P||!C.rows.some(Se=>Se.volumes.length>0))return null;const O=[],fe=C.rows.filter(Se=>Se.volumes.length>0).map(Se=>({k:R(Se.id)??"",from:Math.min(...Se.volumes),to:Math.max(...Se.volumes)})).sort((Se,Le)=>Se.from-Le.from);for(const Se of fe){const Le=Se.to-Se.from+1,He=O[O.length-1];He&&He.key===Se.k?(He.to=Math.max(He.to,Se.to),He.n+=Le):O.push({key:Se.k,from:Se.from,to:Se.to,n:Le})}const oe=fe.reduce((Se,Le)=>Math.max(Se,Le.to),0);return O.length>1&&O.some(Se=>Se.key)?{segs:O,last:oe}:null},[P,C.rows,S]),ne=(Fe=e.description)==null?void 0:Fe.text,B=t.jsx(Fn,{kind:p("collectionPage.kind"),title:m(e.title),byline:t.jsx(Ho,{authors:e.authors,onNavigate:o,renderLink:s}),meta:t.jsx(it,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(W=e.publication_info)!=null&&W.year?m(e.publication_info.year):""]}),description:ne||(J=e.history)!=null&&J.length?t.jsxs(t.Fragment,{children:[ne&&t.jsx(Bt,{text:ne,style:{fontSize:15,lineHeight:1.85}}),($e=e.history)!=null&&$e.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((O,fe)=>t.jsx("li",{children:m(O)},fe))}):null]}):void 0,clampDescription:fo(ne)||(((Te=e.history)==null?void 0:Te.length)??0)>2?6:void 0,stats:de,facts:D,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:we&&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:we.segs.map((O,fe)=>{const oe=Mn.find(Se=>Se.key===O.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!oe,title:oe?p("collectionPage.dist.segTitle",{section:m(oe.label),from:O.from,to:O.to}):void 0,"aria-label":oe?p("collectionPage.dist.only",{section:m(oe.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!oe&&b===O.key,style:{flexGrow:O.n,background:r(oe?oe.token:"rule")},onClick:()=>{oe&&(w(b===O.key?"":O.key),v(!1))}},fe)})}),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:we.last})})]})]})}),Z=[];C.rows.length&&Z.push({id:"titles",label:p("collectionPage.sec.titles"),count:ce}),le&&Z.push({id:"resources",label:p("collectionPage.sec.resources"),count:le}),xe&&Z.push({id:"works",label:u.section.containedWorks,count:V.length});const ae=t.jsxs(t.Fragment,{children:[C.rows.length>0&&t.jsxs(ot,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(it,{items:[`${ce} ${u.unit.items}`,C.totalVolumes?p("collectionPage.totalVolumes",{n:C.totalVolumes,unit:u.unit.volume}):"",N.length!==ce?p("collectionPage.currentN",{n:N.length,unit:u.unit.items}):""]}),action:a,children:[(C.rows.length>Nn||K.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[K.length>0&&t.jsx(Li,{items:K,value:b,onChange:O=>{w(O),v(!1)}}),z&&C.rows.length>Nn&&!P&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:j,onClick:()=>k(!0),title:p("collectionPage.loadAllTitle",{n:C.rows.length,unit:u.unit.items}),children:p(j?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),C.rows.length>Nn&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:O=>{f(O.target.value),v(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Ai(N.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[L&&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:A.map((O,fe)=>{var Xe;const oe=O.id?S.get(O.id):void 0,Se=oe!=null&&oe.title&&O.title===O.id?oe.title:O.title,Le=((oe==null?void 0:oe.authors)||[]).find(I=>I&&I.name),He=[Le?`${Le.dynasty?`〔${m(Le.dynasty)}〕`:""}${m(Le.name)}${Le.role?` ${m(Le.role)}`:""}`:"",oe!=null&&oe.measure?m(oe.measure):"",(Xe=O.subItems)!=null&&Xe.length?O.subItems.map(I=>m(I)).join("、"):"",(oe!=null&&oe.edition||O.edition)&&!ee?m((oe==null?void 0:oe.edition)||O.edition||""):""].filter(Boolean),Ye=Mn.find(I=>I.key===R(O.id)),qe=O.volumes.length>0?p("collectionPage.volumeRange",{range:Ei(O.volumes,u.unit.volume),unit:u.unit.volume}):O.expected!=null?`${O.found??0}/${O.expected} ${u.unit.volume}`:"";return t.jsxs("tr",{children:[L&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${qe?"":" bim-d-zt-blank"}`,children:[Ye&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r(Ye.token)}}),qe||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[O.id?t.jsx(et,{id:O.id,label:m(Se),onNavigate:o,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:m(Se)}),He.length>0?t.jsx(it,{items:He}):O.id&&!oe&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${oe!=null&&oe.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:oe!=null&&oe.versionCount?p("collectionPage.nZhong",{n:oe.versionCount}):""})]},`${O.id??O.title}-${fe}`)})})]}),A.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:p("catalog.noMatch")}),!x&&t.jsx(go,{total:N.length,shown:A.length,unit:u.unit.items,onClick:()=>v(!0)})]}),le>0&&t.jsxs(ot,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:le}),children:[ie.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[ie.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:ie.text.map((O,fe)=>t.jsx(Do,{item:O,siblings:ie.text},`${O.id||O.url||O.name}-${fe}`))})})]}),t.jsx(md,{groups:ie.groups})]}),C.rows.length===0&&le===0&&t.jsx(ot,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),je=xe?t.jsx(en,{id:"works",title:u.section.containedWorks,meta:p("collectionPage.nZhong",{n:V.length}),cap:12,items:V.map(O=>t.jsx(et,{id:O.id,label:m(O.title),onNavigate:o,renderLink:s,dense:!0}))}):null,Y=y?t.jsx(lc,{caption:p("collectionPage.parent"),children:t.jsx(et,{id:y.id,label:m(y.title||y.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return t.jsx(On,{railTop:l,back:d,up:Y,nav:Z,railLinks:c,main:ae,card:B,side:je})},ty=16,br=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Ya(e){if(!e)return br.length;const n=br.indexOf(e);return n===-1?br.length:n}function ny(e,n,i){if(n)return e[n]??i(n)}function iy(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const ry={秦:[-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]},jd=({data:e,transport:n,onNavigate:i,renderLink:o,railTop:s,back:a,railLinks:l})=>{var je,Y,be,Ee,Fe;const{t:d,convert:c,messages:p}=te(),m=W=>iy(W,d),[u,g]=h.useState("全部"),[f,x]=h.useState(!1),[v,y]=h.useState("default"),[_,b]=h.useState(new Map),w=h.useMemo(()=>e._works||[],[e._works]),j=h.useMemo(()=>w.map(W=>{const J=_.get(W.work_id);return{id:W.work_id,title:(J==null?void 0:J.title)??W.title??W.work_id,role:W.role||"",cls:co(W.role),versionCount:J==null?void 0:J.versionCount,section:J==null?void 0:J.cls,l1:J==null?void 0:J.l1,measure:J==null?void 0:J.measure,hasImage:J==null?void 0:J.hasImage,loaded:!!(J!=null&&J.loaded)}}),[w,_]),k=h.useMemo(()=>Ql(w.map(W=>W.role),d("detail.roleAll")),[w,d]),C=h.useMemo(()=>{const W=u==="全部"?j:j.filter(J=>J.cls===u);return v==="versions"?[...W].sort((J,$e)=>($e.versionCount??-1)-(J.versionCount??-1)):W},[j,u,v]),$=f?C:C.slice(0,ty),S=h.useMemo(()=>$.filter(W=>!_.has(W.id)).map(W=>W.id),[$,_]);h.useEffect(()=>{if(!n||S.length===0)return;let W=!1;return Bi(S,Pi,J=>n.getItem(J).then($e=>{var Se;const Te=$e??{},O=Te._edition_count??((Se=Te._books)==null?void 0:Se.length)??0,fe=mo(Te),oe=[fe==null?void 0:fe.l1,fe==null?void 0:fe.l2].filter(Boolean).join(" ");return[J,{id:J,title:Te.title,versionCount:O,loaded:!0,cls:oe||void 0,l1:(fe==null?void 0:fe.l1)||void 0,measure:$e&&Wt($e,p.unit.juan)||void 0,hasImage:!!Te._has_image}]}).catch(()=>[J,{id:J,loaded:!0}]),()=>W).then(J=>{W||b($e=>{const Te=new Map($e);for(const[O,fe]of J)Te.set(O,fe);return Te})}),()=>{W=!0}},[n,S,p.unit.juan]);const M=h.useMemo(()=>{const W=new Map;for(const J of e.alt_names||[]){const $e=J.type||p.section.aliases;W.has($e)||W.set($e,[]),W.get($e).push(J.name)}return[...W.entries()].sort((J,$e)=>Ya(J[0])-Ya($e[0])).map(([J,$e])=>({label:J,names:$e}))},[e.alt_names,p]),z=e.birth_year??((je=e.dates)==null?void 0:je.birth)??void 0,T=e.death_year??((Y=e.dates)==null?void 0:Y.death)??void 0,P=(be=e.dates)==null?void 0:be.floruit,R=z!=null||T!=null?`${m(z)||"?"}—${m(T)||"?"}`:Array.isArray(P)&&P.length===2&&P.every(W=>Number.isFinite(W))?d("entityPage.floruit",{from:m(P[0]),to:m(P[1])}):"",N=new Set(["本名","字","號","号"]),A=M.filter(W=>N.has(W.label)),H=M.filter(W=>!N.has(W.label)),G=H.reduce((W,J)=>W+J.names.length,0),ie=h.useMemo(()=>{const W=[];for(const $e of A)W.push({label:$e.label,value:$e.names.map(Te=>c(Te)).join("、")});const J=w.length;return J&&W.push({label:d("entityPage.fact.works"),value:d("entityPage.nZhong",{n:J})}),W},[w,A,c,d]),le=W=>{var J;return(J=M.find($e=>W.includes($e.label)))==null?void 0:J.names[0]},V=le(["字"]),F=le(["號","号"]),xe=[V?d("entityPage.zi",{name:c(V)}):"",F?d("entityPage.hao",{name:c(F)}):""].filter(Boolean).join(","),ee=e.native_place,L=e.dynasty?ry[e.dynasty]:void 0,Re=(()=>{if(!L||z==null||T==null||T<z)return null;const[W,J]=L,$e=Math.max(z,W),Te=Math.min(T,J);if(Te<=$e)return null;const O=J-W;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:m(z),death:m(T),years:T-z+1}),children:t.jsx("i",{style:{left:`${($e-W)/O*100}%`,width:`${(Te-$e)/O*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${m(W)} ${c(e.dynasty)}`}),t.jsx("span",{children:d("entityPage.lifeYears",{years:T-z+1})}),t.jsx("span",{children:m(J)})]})]})})(),ce=h.useMemo(()=>{if(!n||j.length===0||j.some($e=>!$e.loaded))return null;const W=new Map;for(const $e of j){const Te=Hr($e.l1);Te&&W.set(Te,(W.get(Te)??0)+1)}const J=Mn.map($e=>({...$e,n:W.get($e.key)??0})).filter($e=>$e.n>0);return J.length?J:null},[j,n]),me=t.jsxs(Fn,{kind:ny(p.entityPage.subtype,e.subtype,c),title:c(e.primary_name||e.title),subtitle:xe||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(it,{items:[e.dynasty?c(e.dynasty):"",R,ee?d("entityPage.nativePlace",{place:c(ee)}):""]}),Re]}),description:(Ee=e.description)!=null&&Ee.text?t.jsx(Bt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:fo((Fe=e.description)==null?void 0:Fe.text)?6:void 0,facts:ie,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[G>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:d("entityPage.moreNames",{n:G})}),t.jsx("dl",{children:H.map(W=>t.jsxs(h.Fragment,{children:[t.jsx("dt",{children:c(W.label)}),t.jsx("dd",{children:W.names.map(J=>c(J)).join("、")})]},W.label))})]}),ce&&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:ce.map(W=>t.jsx("i",{style:{flexGrow:W.n,background:r(W.token)}},W.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ce.map(W=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r(W.token)}}),c(W.label)," ",W.n]},W.key))})]})]}),se=h.useMemo(()=>j.filter(W=>W.loaded&&(W.versionCount??0)>0).sort((W,J)=>(J.versionCount??0)-(W.versionCount??0)).slice(0,3),[j]),Pe=!!n&&j.length>=3&&$.some(W=>!W.loaded),X=u==="全部"&&(Pe||se.length>=2),re=e.external_ids||{},de=[];re.cbdb_id!=null&&de.push({label:"CBDB",id:String(re.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${re.cbdb_id}`,note:re.cbdb_match==="auto"?d("entityPage.autoMatch"):void 0});const D=re.wikidata_id;D&&de.push({label:"Wikidata",id:D,href:`https://www.wikidata.org/wiki/${D}`});const K=re.viaf_id;K&&de.push({label:"VIAF",id:K,href:`https://viaf.org/viaf/${K}`});const we=k.map(W=>({key:W.cls,label:`${W.label} ${W.count}`})),ne=[...X&&!Pe?[{id:"featured",label:d("entityPage.sec.featured"),count:se.length}]:[],...j.length?[{id:"works",label:d("entityPage.sec.allWorks"),count:j.length}]:[],...de.length?[{id:"external",label:d("entityPage.sec.external"),count:de.length}]:[]],B=X?t.jsxs(ot,{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(W=>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:" "})]},W)),!Pe&&se.map(W=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(et,{id:W.id,label:c(W.title),onNavigate:i,renderLink:o,dense:!0})}),t.jsx(it,{items:[W.section?c(W.section):"",W.measure?c(W.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:W.versionCount}),t.jsx("span",{children:d("entityPage.versionsUnit")}),W.hasImage&&t.jsx("span",{className:"bim-d-flag",children:d("entityPage.hasImage")})]})]},W.id))]})]}):null,Z=j.length===0?t.jsx(ot,{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:[B,t.jsxs(ot,{id:"works",title:d("entityPage.sec.works"),meta:t.jsx(it,{items:[d("entityPage.total",{n:j.length}),C.length!==j.length?d("entityPage.current",{n:C.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[we.length>1&&t.jsx(Li,{items:we,value:u,onChange:W=>{g(W),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":v==="versions",onClick:()=>{v==="default"&&x(!0),y(W=>W==="default"?"versions":"default")},children:d(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!f&&Ai(C.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(W=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(et,{id:W.id,label:c(W.title),onNavigate:i,renderLink:o,dense:!0}),W.measure?t.jsx(it,{items:[c(W.measure)]}):!W.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${W.section||W.loaded?"":" bim-d-zt-blank"}`,children:W.section?c(W.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${W.role?"":" bim-d-zt-blank"}`,children:W.role?c(W.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${W.loaded?"":" bim-d-zt-blank"}`,children:W.loaded?W.versionCount?d("entityPage.nZhong",{n:W.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:d("entityPage.notRecorded")}):""}),t.jsx("td",{className:W.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:W.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:d("entityPage.hasImage")})})]},W.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(go,{total:C.length,shown:$.length,unit:d("entityPage.moreUnit"),onClick:()=>x(!0)})]})]}),ae=de.length>0?t.jsx(en,{id:"external",title:d("entityPage.sec.external"),items:de.map(W=>t.jsxs("a",{href:W.href,target:"_blank",rel:"noopener noreferrer",children:[W.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:de.map(W=>W.id),foot:re.cbdb_id!=null&&re.cbdb_match==="auto"?d("entityPage.cbdbAuto"):void 0}):null;return t.jsx(On,{railTop:s,back:a,nav:ne,railLinks:l,main:Z,card:me,side:ae})},Vo="(max-width: 719px)",oy=`${Vo}, (pointer: coarse)`,vd=`
1353
+ ${B??""}`,[Gi,es]=h.useState({key:Gn,data:U,started:!!U});if(Gi.key!==Gn)es({key:Gn,data:U,started:!1});else if(U!==Gi.data&&(es({key:Gn,data:U,started:!!U}),U)){const E=U.pages??[];(!Gi.started||!E.some(pe=>pe.page===Oe))&&rt(Ve(U))}h.useEffect(()=>{ke(new Set),Be(null)},[B,ce]);const xp=h.useCallback(E=>{if(ke(new Set(E)),E.length>0){const pe=E[0],ze=parseInt(pe.split(":")[0],10);isNaN(ze)||rt(ze)}},[]),zt=h.useMemo(()=>{const E=new Map;for(const pe of(U==null?void 0:U.pages)??[])E.set(pe.page,pe);return E},[U]),vn=q(U),Yn=h.useCallback(E=>{var De;const pe=I.images;if(!pe||pe.length===0)return;const ze=(De=zt.get(E))==null?void 0:De.seq;return(ze?pe.find(Je=>Je.seq===ze):void 0)??pe.find(Je=>Je.pageNo===E)??pe[E-1]},[I.images,zt]),ts=st>1.5,qn=h.useCallback((E,pe=!1)=>{const ze=Yn(E);return ze?E===vn||pe?ze.hiresUrl??ze.url:ze.url:E===vn?(U==null?void 0:U.imageUrl)??"":""},[Yn,U,vn]),bp=h.useMemo(()=>qn(Oe,ts),[qn,Oe,ts]),Nt=h.useMemo(()=>[...zt.keys()].sort((E,pe)=>E-pe),[zt]),Kn=h.useRef(Oe);Kn.current=Oe;const Xn=h.useCallback(E=>{var pe;Kn.current===E||!zt.has(E)||(Kn.current=E,rt(E),(pe=zt.get(E))!=null&&pe.columns.some(ze=>ze.chars.length>0)&&Gt(ze=>({page:E,nonce:((ze==null?void 0:ze.nonce)??0)+1})))},[zt]),kn=h.useCallback(E=>{const pe=Kn.current,ze=Nt.indexOf(pe),De=Nt[ze<0?0:ze+E];De===void 0||De===pe||Xn(De)},[Nt,Xn]),ns=h.useCallback(E=>{if(!E.trim().match(/^\d+$/)||Nt.length===0)return null;const ze=parseInt(E.trim(),10),De=Number.isFinite(ze)?ze:Number.MAX_SAFE_INTEGER;return Nt.reduce((Je,vt)=>Math.abs(vt-De)<Math.abs(Je-De)?vt:Je,Nt[0])},[Nt]),[Yi,qi]=h.useState(null),Zn=h.useRef(null),yp=h.useCallback(E=>{Zn.current=E,qi(E)},[]),is=h.useCallback(()=>{const E=Zn.current;if(Zn.current=null,qi(null),E===null)return;const pe=ns(E);pe!==null&&Xn(pe)},[ns,Xn]),Ki=Nt.indexOf(Oe),jp=h.useCallback(E=>{if(E.altKey||E.ctrlKey||E.metaKey)return;const pe=E.target.tagName;pe==="INPUT"||pe==="TEXTAREA"||pe==="SELECT"||(E.key==="ArrowLeft"||E.key==="PageUp"?(E.preventDefault(),kn(-1)):(E.key==="ArrowRight"||E.key==="PageDown")&&(E.preventDefault(),kn(1)))},[kn]);h.useEffect(()=>{if(U)for(const E of[1,-1,2,3]){const pe=qn(Oe+E);pe&&Mr(pe)}},[U,Oe,qn]);const rs=h.useMemo(()=>{var hs;if(!U)return null;if(Oe===vn)return U;const E=zt.get(Oe);if(E&&E.width>0&&E.height>0)return{page_id:`p:${Oe}`,title:`第${Oe}葉`,image_size:[E.width,E.height],total_warped_w:E.width,columns:[{col:1,warped_w:E.width,warped_h:E.height,offset_x:0,strips:[],chars:E.columns.flatMap(Ze=>Ze.chars).map(Ze=>({id:Ze.id,char:Ze.char,slot:Ze.slot,pos:Ze.pos,sub:Ze.sub,bbox_col:Ze.bbox??[0,0,0,0]}))}]};const pe=(hs=U.pages)==null?void 0:hs.find(Ze=>Ze.page===Oe),[ze,De]=U.image_size||[2386,3082],Je=Yn(Oe),vt=(Je==null?void 0:Je.width)??ze,er=(Je==null?void 0:Je.height)??De,us=vt/ze,ms=er/De,gs=new Map;for(const Ze of U.columns){const mt=(Ze.strips||[]).flatMap(ni=>ni.srcQuad.map(ii=>ii[0]));if(mt.length===0)continue;const It=Ze.top_y??0,tr=Ze.bottom_y??It+Ze.warped_h;gs.set(Ze.col,{x0:Math.min(...mt),x1:Math.max(...mt),top:It,slotH:(tr-It)/21})}return{page_id:`p:${Oe}`,title:`第${Oe}葉`,image_size:[vt,er],total_warped_w:vt,columns:pe?pe.columns.map(Ze=>{const mt=gs.get(Ze.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Ze.col,warped_w:vt,warped_h:er,offset_x:0,strips:[],chars:Ze.chars.map(It=>{const tr=It.slot??It.pos??0,ni=(mt.top+(tr-1)*mt.slotH)*ms,ii=(mt.x0+mt.x1)/2,[Tp,zp]=It.sub==="a"?[ii,mt.x1]:It.sub==="b"?[mt.x0,ii]:[mt.x0,mt.x1];return{...It,bbox_col:[Tp*us,ni,zp*us,ni+mt.slotH*ms]}})}}):[]}},[U,Oe,vn,zt,Yn]),{entryTitle:Jn,authors:os}=Af(n,i,d===void 0),[ss,Xi]=h.useState("text");if(h.useEffect(()=>{Xi("text")},[B,ce]),H==="loading")return t.jsx(ga,{className:k,style:C,title:d??Jn,label:$("reader.loading")});if(H==="missing"||!N||!L)return t.jsx("div",{className:k,style:{...C,...ma},children:$("reader.noText")});if(D==="failed")return t.jsx("div",{className:k,style:{...C,...ma},children:$("reader.tocFailed")});if(!ne)return t.jsx(ga,{className:k,style:C,title:d??Jn,label:$("reader.tocLoading")});const Yt=Nf(L,ne),vp=If(ne,Ye,Yt,S,O),Zi=N.versions.map(E=>({key:E.key,label:_e.textVersionLabel(E),optionLabel:S(_e.textVersionLabel(E)),sourceName:fa(E)?$("reader.originalSource"):E.source_name?S(E.source_name):void 0,license:E.license??void 0,sourceUrl:E.source_url??void 0,primary:E.key===Re})),ut=Tf((ps=ne.source)==null?void 0:ps.upstream),Qn=(typeof d=="string"?S(d):d)??(ne.title?S(ne.title):Jn?S(Jn):void 0),as=L.edition_label?S(L.edition_label):void 0,Ji=Qn?t.jsx("a",{href:P(n),title:$("reader.viewEntry"),onClick:l?E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),l(n))}:void 0,children:Qn}):void 0,kp=Ji&&as?t.jsxs(t.Fragment,{children:[Ji,t.jsxs("span",{className:"bim-rd-ed",children:["·",as]})]}):Ji,wp=os.length>0?S(os.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${` ${E.role||$("reader.defaultRole")}`}`).join("、")):void 0,Qi=Z?Yc(Z,Yt,S,O):void 0,qt=O&&!!(be!=null&&be.json),Kt=(be==null?void 0:be.json)??null,sn=(be==null?void 0:be.md)??null,ls=qt&&!Le&&Wc(Kt.sections),Sp=ls&&!(sn&&ge.readingMode==="paragraph"&&yi(sn)),_p=qt&&ls?t.jsx(tf,{juan:Kt,view:ss,onView:Xi,textHasEntries:Sp}):void 0,$p=!0,ei=sn?sn.replace(/^##\s+[^\n]+\n+/,""):null,ti=fa(L),Wt=ti?$("reader.originalSource"):L.source_name?S(L.source_name):void 0,Cp=(typeof c=="string"?S(c):c)??(ti?void 0:Wt??S(_e.textVersionLabel(L)));return t.jsxs(Gl,{className:k,style:C,title:kp,subtitle:Cp,byline:wp,current:Qi,pagerUnit:Yt,rail:_p,revisedAt:x,backHref:v,backLabel:y,onReportError:f?E=>f({...E,bookTitle:typeof Qn=="string"?Qn:void 0,entryId:n}):void 0,workLinkToggle:qt&&!Le&&!!l&&!!(Kt!=null&&Kt.sections.some(E=>E.work_id)),toc:vp,tocCaption:$("reader.tocCaption",{n:ne.chapters.length,unit:S(Yt)}),tocHeader:O&&ne.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:Le?$("reader.searchChaptersPlaceholder"):$("reader.searchUnitPlaceholder",{unit:S(Yt)}),"aria-label":Le?$("reader.searchChapters"):$("reader.searchUnit",{unit:S(Yt)}),value:fe,onChange:E=>oe(E.target.value)}):void 0,activeKey:B??null,onSelect:Y,images:I.images,imagesLoading:I.loading||ue,renderImageOverlay:m,imagePanel:U?"open":u,isWarpMode:!!U,customImagePanel:U&&rs?t.jsxs("div",{className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:jp,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:r("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:4},children:t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[Q.size>0&&t.jsxs("button",{type:"button",onClick:()=>ke(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",Q.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:st<=1,onClick:()=>{var E;return(E=We.current)==null?void 0:E.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(st*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:st>=6,onClick:()=>{var E;return(E=We.current)==null?void 0:E.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:st===1,onClick:()=>{var E;return(E=We.current)==null?void 0:E.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx($f,{ref:We,resetKey:Oe,onScaleChange:jt,style:{flex:1,minHeight:0},children:t.jsx(Eo,{imageUrl:bp,pageData:rs,selectedCharIds:Q,hoveredCharId:Ae,preserveMargins:ve,onCharClick:E=>{ke(ze=>{const De=new Set(ze);return De.has(E)?De.delete(E):(De.clear(),De.add(E)),De});const pe=document.querySelector(`[data-char-id="${E}"]`);pe&&pe.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Be})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":$("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:r("meta-fg")},children:[t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:Ki<=0,onClick:()=>kn(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":Oe,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:r("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":$("reader.facsimilePageInput"),size:Math.max(2,String(Yi??Oe).length),value:Yi??String(Oe),onFocus:E=>E.currentTarget.select(),onChange:E=>yp(E.target.value),onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),is()):E.key==="Escape"&&(Zn.current=null,qi(null)),E.stopPropagation()},onBlur:is,style:{width:`${Math.max(2,String(Yi??Oe).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${r("rule")}`,borderRadius:4,background:"transparent",color:"inherit"}}),"葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:Ki<0||Ki>=Nt.length-1,onClick:()=>kn(1),children:"›"})]})]}):void 0,settingsAnnotate:U?t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ne?"bim-rd-on":""}`,"aria-pressed":Ne,title:"切换外挂现代断句标点",onClick:()=>he(E=>!E),children:Ne?"标点":"无标点"}):void 0,settingsLayout:U?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-badge-warp",children:"图文对读"}),t.jsxs("div",{role:"group","aria-label":"书影留白",style:{display:"inline-flex",border:`1px solid ${r("rule")}`,borderRadius:4,overflow:"hidden"},children:[t.jsx("button",{type:"button",onClick:()=>Ue(!1),"aria-pressed":!ve,className:`bim-rd-t ${ve?"":"bim-rd-on"}`,style:{padding:"6px 12px",border:"none",borderRadius:0,background:ve?"transparent":"var(--bimrd-on-bg)",color:ve?"inherit":r("ink")},title:"去空白:紧凑裁切版心",children:"去空白"}),t.jsx("button",{type:"button",onClick:()=>Ue(!0),"aria-pressed":ve,className:`bim-rd-t ${ve?"bim-rd-on":""}`,style:{padding:"6px 12px",border:"none",borderRadius:0,background:ve?"var(--bimrd-on-bg)":"transparent",color:ve?r("ink"):"inherit"},title:"保留空白:完整呈现古籍天头地脚与白边",children:"保留空白"})]})]}):void 0,prefs:ge,onPrefsChange:T,versions:Zi.length>1?Zi:void 0,currentVersionKey:Zi.length>1?L.key:void 0,onVersionChange:je,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:yi(sn),allowVertical:g,children:[($e||ue&&!U&&!qt&&ei==null)&&t.jsx(nn,{}),!$e&&U&&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:Z!=null&&Z.title?S(Z.title):Qi}),(Wt||L.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Wt,L.license&&t.jsxs(t.Fragment,{children:[Wt&&t.jsx("span",{className:"bim-rd-dot"}),L.license]})]})]}),t.jsx(Po,{pageData:U,pages:U.pages,punctuations:U.punctuations||[],selectedCharIds:Q,hoveredCharId:Ae,onSelectionChange:xp,onCharClick:E=>{ke(ze=>{const De=new Set(ze);return De.has(E)?De.delete(E):(De.clear(),De.add(E)),De});const pe=parseInt(E.split(":")[0],10);isNaN(pe)||rt(pe)},onCharHover:Be,mode:"horizontal",showPunctuation:Ne,entities:Ge,entityTransport:i,onEntityNavigate:j,onVisiblePageChange:E=>rt(E),convert:S,scrollToPage:on,pageBreaks:ge.pageBreaks,pageIndicatorY:ge.pageIndicatorY,onPageIndicatorYChange:E=>T({pageIndicatorY:E}),quoteStyle:ge.quoteStyle,bookTitleStyle:ge.bookTitleStyle,showWorks:ge.showWorks})]}),!$e&&!U&&qt&&Kt&&t.jsx(Qh,{juan:Kt,rawText:sn,positionLabel:Ef(Z,ne,Yt,S),groupLabel:Lf(ne,B??null),index:zf(n,ne),searchQuery:fe,onNavigate:l,transport:i,workLabelCache:qe,prefs:ge,view:ss,onViewChange:Xi},`${ce}/${B}`),!$e&&!U&&!qt&&ei!=null&&Z&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:Z.title?S(Z.title):Qi}),(Wt||L.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[ti&&Wt&&t.jsx(t.Fragment,{children:Wt}),!ti&&L.source_name&&t.jsxs(t.Fragment,{children:[$("reader.textSource")," ",L.source_url?t.jsx("a",{className:"bim-rd-link",href:L.source_url,target:"_blank",rel:"noreferrer",children:S(L.source_name)}):S(L.source_name)]}),Wt&&L.license&&t.jsx("span",{className:"bim-rd-dot"}),L.license]}),ut&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[$("reader.upstream")," ",ut.url?t.jsx("a",{className:"bim-rd-link",href:ut.url,target:"_blank",rel:"noreferrer",children:S(ut.name??ut.url)}):S(ut.name??""),ut.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),ut.license_url?t.jsx("a",{className:"bim-rd-link",href:ut.license_url,target:"_blank",rel:"noreferrer",children:ut.license}):ut.license]}),ut.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(Ll,{text:ut.note,convert:S})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(_o,{text:ei,mode:ge.readingMode,tables:$p,gujiMarkdown:!0,bookMarking:wo(ge),quoteStyle:ge.quoteStyle})})]}),!$e&&!ue&&!U&&!qt&&ei==null&&Z&&t.jsx("div",{className:"bim-rd-state",children:$("reader.chapterFailed")}),ne.references&&ne.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:$("reader.references")}),t.jsx("ol",{children:ne.references.map((E,pe)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:S(E.title)}):t.jsx("span",{children:S(E.title)}),E.author&&t.jsxs("span",{children:[",",S(E.author)]}),E.note&&t.jsxs("span",{children:["。",S(E.note)]})]},pe))})]})]})};function fa(e){return e.is_original===!0||e.source==="original"}function Ef(e,n,i,o){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 o(s?`${s}冊`:`${i}${e.n}`)}function Lf(e,n){if(!n)return;const i=o=>{var s;for(const a of o??[]){const l=i(a.children);if(l)return l;if((s=a.files)!=null&&s.includes(n))return a.label}};return i(e.juan_groups)}function Af(e,n,i){const[o,s]=h.useState({entryTitle:void 0,authors:[]});return h.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:i&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,n,i]),o}const qc={bug:{key:"bug",color:r("danger")},resource:{key:"resource",color:r("primary")},suggestion:{key:"suggestion",color:r("primary")},other:{key:"other",color:r("desc-fg")}},Mf=qc.other,Kc={pending:{key:"pending",color:r("warning")},in_progress:{key:"in_progress",color:r("primary")},resolved:{key:"resolved",color:r("success")},wontfix:{key:"wontfix",color:r("desc-fg")},duplicate:{key:"duplicate",color:r("desc-fg")}},Pf=Kc.pending;function Bf(e){try{const n=new Date(e),i=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return e}}function Wf(e,n){if(!e)return!1;try{const i=new URL(e,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const o=new URL(n);return i.hostname===o.hostname}catch{return!1}}const Oo=({items:e,loading:n})=>{const i=tt(),{t:o,convert:s}=te();return n?t.jsx(nn,{}):e.length===0?t.jsx("div",{style:Of,children:o("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=qc[a.type]||Mf,d=Kc[a.status]||Pf,c=typeof window<"u"&&Wf(a.pageUrl,window.location.href);return t.jsxs("div",{style:Ff,children:[t.jsxs("div",{style:Hf,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...xa,background:l.color},children:o(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...xa,background:d.color},children:o(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Df,children:Bf(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Uf,children:[a.resourceId&&t.jsx("a",{href:i(a.resourceId),style:ur,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:ur,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:ur,children:a.pageUrl}))]}),t.jsx("div",{style:Vf,children:s(a.content)}),a.reply&&t.jsxs("div",{style:Gf,children:[t.jsx("div",{style:Yf,children:o("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},Of={textAlign:"center",padding:"40px 0",color:r("desc-fg"),fontSize:"14px"},Ff={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"16px"},Hf={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xa={fontSize:"12px",color:r("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Df={fontSize:"12px",color:r("desc-fg")},Uf={fontSize:"12px",marginBottom:"6px"},ur={color:r("primary"),textDecoration:"none",borderBottom:`1px dashed ${r("primary")}`},Vf={fontSize:"14px",lineHeight:"1.6",color:r("fg"),whiteSpace:"pre-wrap"},Gf={marginTop:"12px",padding:"10px 12px",background:r("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r("fg")},Yf={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r("primary")},Br=({transport:e,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:a})=>{const l=Ie(),[d,c]=h.useState(null),[p,m]=h.useState([]),[u,g]=h.useState("recommend"),[f,x]=h.useState([]),[v,y]=h.useState(!1),_=o??u,b=A=>{g(A),s==null||s(A)},[w,j]=h.useState(!0),[k,C]=h.useState(null),[$,S]=h.useState(null),[M,z]=h.useState(null);h.useEffect(()=>{let A=!1;if(e.getCounts)return e.getCounts().then(H=>{A||c({works:H.works,books:H.books,collections:H.collections})}).catch(()=>{}),()=>{A=!0}},[e]),h.useEffect(()=>{let A=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const G=await e.getRecommended();if(G!=null&&G.groups)return G.groups.flatMap(ie=>ie.items.map(le=>({...le,group:ie.name})))}catch{}return[]})().then(async G=>{if(A)return;const ie=G.filter(V=>V.id);if(ie.length===0){j(!1);return}const le=await Promise.all(ie.map(async V=>{if(V.type)return{id:V.id,title:V.title,type:V.type,author:V.author,dynasty:V.dynasty,role:V.role,edition:V.edition,has_text:V.has_text,has_image:V.has_image,has_collated:V.has_collated,subtype:V.subtype,primary_name:V.primary_name,group:V.group,fallbackDescription:V.description};try{let F=null;if(e.getEntry)F=await e.getEntry(V.id);else{const xe=await e.getItem(V.id);xe&&(F={id:V.id,title:xe.title||V.id,type:xe.type||"work"})}if(F)return{...F,group:V.group,fallbackDescription:V.description}}catch{}return{id:V.id,title:V.title,type:_e.extractType(V.id),group:V.group,fallbackDescription:V.description}}));A||(m(le.filter(V=>V!==null)),j(!1))}),()=>{A=!0}},[e,i]);const T=h.useRef(!1),P=h.useRef(!1),R=h.useRef(!1);h.useEffect(()=>{if(_!=="catalog"||T.current)return;const A=e.getCatalogProgress??e.getResourceProgress;if(!A)return;T.current=!0;let H=!1;return A.call(e).then(G=>{H||C(G)}).catch(()=>{T.current=!1}),()=>{H=!0}},[e,_]),h.useEffect(()=>{if(_!=="collection"||P.current||!e.getCollectionProgress)return;P.current=!0;let A=!1;return e.getCollectionProgress().then(H=>{A||S(H)}).catch(()=>{P.current=!1}),()=>{A=!0}},[e,_]),h.useEffect(()=>{if(_!=="site"||R.current||!e.getSiteProgress)return;R.current=!0;let A=!1;return e.getSiteProgress().then(H=>{A||z(H)}).catch(()=>{R.current=!1}),()=>{A=!0}},[e,_]),h.useEffect(()=>{if(!a||_!=="feedback")return;let A=!1;return y(!0),fetch(a).then(H=>H.json()).then(H=>{!A&&H.success&&x(H.items||[])}).catch(()=>{}).finally(()=>{A||y(!1)}),()=>{A=!0}},[a,_]);const N=A=>t.jsx(jn,{type:A,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:r("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${r("widget-border")}`,marginBottom:"16px"},children:[t.jsx(Cn,{label:l.home.recommendTab,active:_==="recommend",onClick:()=>b("recommend")}),t.jsx(Cn,{label:l.home.catalogTab,active:_==="catalog",onClick:()=>b("catalog")}),t.jsx(Cn,{label:l.home.collectionTab,active:_==="collection",onClick:()=>b("collection")}),t.jsx(Cn,{label:l.home.siteTab,active:_==="site",onClick:()=>b("site")}),a&&t.jsx(Cn,{label:l.home.feedbackTab,active:_==="feedback",onClick:()=>b("feedback")})]}),_==="recommend"&&t.jsx(qf,{recommended:p,loading:w,onNavigate:n,getIcon:N,t:l}),_==="catalog"&&t.jsx(ba,{progress:k,t:l,onNavigate:n}),_==="collection"&&t.jsx(ba,{progress:$,t:l,onNavigate:n}),_==="site"&&t.jsx(Xf,{progress:M,t:l,totalWorks:(d==null?void 0:d.works)??0}),_==="feedback"&&a&&t.jsx(Oo,{items:f,loading:v})]})})},Cn=({label:e,active:n,onClick:i})=>t.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:r(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${r("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),qf=({recommended:e,loading:n,onNavigate:i,getIcon:o,t:s})=>{const a=tt();if(n)return t.jsx(nn,{});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:r("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 m=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return t.jsxs("a",{href:a(p.id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i==null||i(p.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${r("widget-border")}`,cursor:"pointer",background:r("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:o(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:r("desc-fg"),marginLeft:"4px"},children:p.edition})]}),m&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m})]})]},p.id)})})]},d))})},ba=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(nn,{});const o=[...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:r("progress-active"),done:r("progress-done"),todo:r("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=o.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:r("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(Kf,{item:p,t:n,statusColor:l[d],onNavigate:i},p.id))})]},d)})})},Kf=({item:e,t:n,statusColor:i,onNavigate:o})=>{const s=tt(),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 ${r("widget-border")}`,background:r("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&&o?t.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${r("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:r("widget-border"),color:r("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:r("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?ft(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:r("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${a}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"4px"},children:e.description})]})},Xf=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(nn,{});const o=[...e.resources].sort((c,p)=>c.priority-p.priority),s=o.filter(c=>c.imported>0),a=o.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),d=i>0?Math.round(l/i*100):0;return t.jsxs("div",{children:[i>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${r("primary")} 6%, transparent)`,fontSize:"13px",color:r("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:r("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:r("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(ya,{item:c,t:n,totalWorks:i},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:r("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:r("progress-todo")}}),n.home.statusTodo," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(ya,{item:c,t:n,totalWorks:i},c.id))})]})]})},ya=({item:e,t:n,totalWorks:i})=>{const o=i>0?Math.round(e.imported/i*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${r("widget-border")}`,background:r("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:r("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),e.imported>0&&i>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:r("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:r("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"4px"},children:e.description})]})},ja="(max-width: 768px)";function Zf(){const[e,n]=h.useState(()=>typeof window>"u"?!1:window.matchMedia(ja).matches);return h.useEffect(()=>{const i=window.matchMedia(ja),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),e}const Jf=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var P;const a=Ie(),{convert:l}=Me(),d=Zf(),[c,p]=h.useState(null),[m,u]=h.useState(null),[g,f]=h.useState(!1),[x,v]=h.useState("detail"),[y,_]=h.useState([]),[b,w]=h.useState(!1),j=h.useCallback(async R=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){_([]);return}w(!0);try{if(e.getCollectionCatalogs){const N=await e.getCollectionCatalogs(R);_(N||[])}else if(e.getCollectionCatalog){const N=await e.getCollectionCatalog(R);_(N?[{resource_id:"",data:N}]:[])}}catch{_([])}finally{w(!1)}},[e]),k=h.useCallback(async R=>{if(i){i(R);return}p(R),u(null),_([]),v("detail"),f(!0);try{const N=await e.getItem(R.id);N&&(u(N),N.type==="collection"&&j(R.id))}catch(N){console.error("加载详情失败:",N)}finally{f(!1)}},[e,i,j]),C=h.useCallback(async R=>{u(null),_([]),v("detail"),f(!0);try{const N=await e.getItem(R);N&&(u(N),p({id:R,title:N.title||R,type:N.type||"book"}),N.type==="collection"&&j(R))}catch(N){console.error("导航失败:",N)}finally{f(!1)}},[e,j]),$=typeof(m==null?void 0:m.text_count)=="number"&&m.text_count>0,S=(m==null?void 0:m.type)==="collection"&&(y.length>0||b)||(m==null?void 0:m.type)==="work"&&$,M=d&&(g||m),z=h.useCallback(()=>{p(null),u(null),_([]),v("detail")},[]),T=t.jsx(t.Fragment,{children:g?t.jsx(nn,{}):m?t.jsxs(t.Fragment,{children:[(S||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${r("widget-border")}`,padding:d?"0 12px":"0 48px",background:r("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[S&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>v("detail"),style:ci(x==="detail"),children:a.detailTab.basicInfo}),m.type==="collection"&&b&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:ci(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),m.type==="collection"&&y.map(R=>t.jsx("button",{onClick:()=>v(`catalog:${R.resource_id}`),style:ci(x===`catalog:${R.resource_id}`),children:R.short_name?`${l(R.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},R.resource_id)),m.type==="work"&&$&&t.jsx("button",{onClick:()=>v("collated"),style:ci(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(no,{data:m,transport:e,onNavigate:C}):x.startsWith("catalog:")?t.jsx(io,{data:(P=y.find(R=>`catalog:${R.resource_id}`===x))==null?void 0:P.data,onNavigate:C}):x==="collated"?t.jsx(Wo,{id:m.id,transport:e,onNavigate:C}):null})]}):t.jsx(Br,{transport:e,onNavigate:C,recommendedIds:o})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:r("bg"),color:r("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${r("widget-border")}`,background:r("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:z,style:{padding:"4px 12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("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(wr,{transport:e,onEntryClick:k,hideModeIndicator:n}),!m&&t.jsx(Br,{transport:e,onNavigate:C,recommendedIds:o})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:r("bg"),color:r("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${r("widget-border")}`,display:"flex",flexDirection:"column",background:r("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(wr,{transport:e,onEntryClick:k,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:r("bg"),display:"flex",flexDirection:"column"},children:T})]})};function ci(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${r("primary")}`:"2px solid transparent",background:"transparent",color:r(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}const Qf=({pageData:e,rawImageUrl:n="",punctuations:i=[],title:o,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=h.useState(new Set),[m,u]=h.useState(null),[g,f]=h.useState("horizontal"),[x,v]=h.useState(!0),y=h.useRef(null),_=h.useCallback(k=>{p(new Set(k))},[]),b=h.useCallback(k=>{if(p(C=>{const $=new Set(C);return $.has(k)?$.delete(k):($.clear(),$.add(k)),$}),y.current){const C=y.current.querySelector(`[data-char-id="${k}"]`);C&&C.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),w=()=>{var k;p(new Set),window.getSelection&&((k=window.getSelection())==null||k.removeAllRanges())},j=i.length>0?i: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:o||e.title}),s&&t.jsx("span",{style:{fontSize:"0.85rem",color:r("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:r("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:r("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:w,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>v(k=>!k),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f(k=>k==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:g==="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(Eo,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:m,onCharClick:b,onCharHover:u})})]}),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:g==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(Po,{pageData:e,punctuations:j,selectedCharIds:c,hoveredCharId:m,onSelectionChange:_,onCharClick:b,onCharHover:u,mode:g,showPunctuation:x})]})]})]})},ex=e=>typeof e=="string"&&Array.from(e).length===1;function tx(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.punctuations)?e.punctuations:[],i=[];for(const o of n){if(!o||typeof o!="object")continue;const s=o;typeof s.anchor!="string"||typeof s.mark!="string"||s.pre_char!=null&&!ex(s.pre_char)||i.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??void 0})}return i}function nx(e){var i;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return null;for(const o of n){const s=/\/iiif\/([^/]+)\/canvas\/([^/]+)\//.exec(String(((i=o==null?void 0:o.canvas)==null?void 0:i.id)??""));if(s)return{bookId:s[1],vol:s[2]}}return null}const ix=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function at(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}const rx=new Set(["main","solo","jz_r","jz_l"]),ox=new Set(["body","banxin","blank"]);function sx(e){const n={};return typeof e.lane=="string"&&rx.has(e.lane)&&e.lane!=="main"&&(n.lane=e.lane),e.lacuna===!0&&(n.lacuna=!0),e.guess===!0&&(n.guess=!0),typeof e.zi=="string"&&e.zi&&(n.zi=e.zi),n}function ax(e){const n={};typeof e.kind=="string"&&ox.has(e.kind)&&e.kind!=="body"&&(n.kind=e.kind);const i=at(e.raised);i!==void 0&&Number.isInteger(i)&&i>0&&(n.raised=i);const o=at(e.lead_blank);return o!==void 0&&Number.isInteger(o)&&o>0&&(n.lead_blank=o),n}function mr(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(i=>!!i&&typeof i=="object"):[]}function lx(e,n){var c,p,m,u,g,f,x,v,y,_;const i=new Map,o=new Map;for(const b of mr(n)){const w=at(b.page);if(w!==void 0){i.set(w,b);for(const j of Array.isArray(b.cells)?b.cells:[]){const k=j==null?void 0:j.box;typeof(j==null?void 0:j.a)=="string"&&Array.isArray(k)&&k.length===4&&k.every(C=>at(C)!==void 0)&&o.set(j.a,[k[0],k[1],k[0]+k[2],k[1]+k[3]])}}}const s=[],a=new Map,l=new Map;for(const b of mr(e)){const w=at(b.page);w!==void 0&&typeof b.label=="string"&&b.label&&a.set(w,b.label)}for(const b of mr(e)){const w=at(b.page);if(w===void 0)continue;const j=[];for(const C of Array.isArray(b.columns)?b.columns:[]){const $=at(C==null?void 0:C.col);if($===void 0)continue;const S=[];for(const z of Array.isArray(C.cells)?C.cells:[]){const T=ix.exec(String((z==null?void 0:z.a)??""));if(!T||typeof z.c!="string")continue;const P=parseInt(T[3],10);S.push({id:z.a,char:z.c,slot:P,pos:P,sub:T[4]||null,bbox:o.get(z.a)??null,...sx(z)})}const M=ax(C);(S.length>0||M.kind==="blank")&&j.push({col:$,chars:S,...M})}if(!j.some(C=>C.chars.length>0)){j.length>0&&l.set(w,j);continue}j.sort((C,$)=>C.col-$.col);const k=i.get(w);s.push({page:w,seq:String(((c=k==null?void 0:k.canvas)==null?void 0:c.seq)??""),width:at((p=k==null?void 0:k.canvas)==null?void 0:p.width)??at((m=k==null?void 0:k.image)==null?void 0:m.width)??0,height:at((u=k==null?void 0:k.canvas)==null?void 0:u.height)??at((g=k==null?void 0:k.image)==null?void 0:g.height)??0,...typeof b.label=="string"&&b.label?{label:b.label}:{},columns:j})}const d=new Set(s.map(b=>b.page));for(const[b,w]of i){const j=(f=w==null?void 0:w.canvas)==null?void 0:f.seq;d.has(b)||typeof j!="string"&&typeof j!="number"||String(j)===""||s.push({page:b,seq:String(j),width:at((x=w.canvas)==null?void 0:x.width)??at((v=w.image)==null?void 0:v.width)??0,height:at((y=w.canvas)==null?void 0:y.height)??at((_=w.image)==null?void 0:_.height)??0,...a.has(b)?{label:a.get(b)}:{},columns:l.get(b)??[]})}return s.sort((b,w)=>b.page-w.page)}const cx=({data:e,onNavigate:n,className:i,style:o})=>{var m;const{t:s,convert:a}=te(),[l,d]=h.useState(((m=e.divisions[0])==null?void 0:m.name)??null),[c,p]=h.useState(null);return t.jsxs("div",{className:i,style:o,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:r("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:r("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(u=>t.jsx(dx,{division:u,expanded:l===u.name,onToggle:()=>d(l===u.name?null:u.name),expandedCat:c,onCatToggle:g=>p(c===g?null:g),onNavigate:n},u.name))})]})},dx=({division:e,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=te(),c=e.categories.reduce((p,m)=>{const u=m.stats||{zhulu:0,cunmu:0};return p+(u.zhulu||0)+(u.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${r("primary")} 6%, transparent)`:r("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:r("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:r("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 m=`${e.name}/${p.name}`;return t.jsx(px,{category:p,expanded:o===m,onToggle:()=>s(m),onNavigate:a},p.name)})})]})},px=({category:e,expanded:n,onToggle:i,onNavigate:o})=>{var p,m,u,g;const{t:s,convert:a}=te(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((m=e.books)==null?void 0:m.cunmu)||[],c=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((g=e.stats)==null?void 0:g.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?r("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:r("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg"),marginLeft:"8px",fontWeight:400},children:s("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:r("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(va,{label:s("catalogPage.zhulu"),books:l,onNavigate:o}),d.length>0&&t.jsx(va,{label:s("catalogPage.cunmu"),books:d,onNavigate:o})]})]})},va=({label:e,books:n,onNavigate:i})=>{const{t:o,convert:s}=te(),a=tt(),[l,d]=h.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:r("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((p,m)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:r("fg")},children:p.work_id&&i?t.jsx("a",{href:a(p.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),i(p.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${r("link-fg")}`},children:s(p.title)}):s(p.title)}),p.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:s(p.volumes)}),p.author&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:s(p.author).slice(0,20)})]},m))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:r("primary"),background:"transparent",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:o("catalogPage.expandAllN",{n:n.length})})]})},kt=({title:e,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const a=Ie();return t.jsxs("div",{style:{background:r("bg"),border:`1px solid ${r("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 ${r("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:r("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,i&&t.jsx("button",{onClick:i,style:mx,children:"AI"}),n&&t.jsx("button",{onClick:n,style:ux,children:a.action.save})]})]}),s]})},ux={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},mx={padding:"4px 12px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},ht=({label:e,value:n,onChange:i,placeholder:o,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:a=>i(a.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),tn=({value:e,onChange:n,placeholder:i})=>{const o=h.useRef(null);return h.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:o,value:e||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},vi=({children:e,color:n,style:i})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||r("primary-soft"),color:r(n?"on-color-fg":"fg"),...i},children:e});function gx(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const gi=({value:e,onChange:n,label:i})=>{const[o,s]=h.useState(!1),a=h.useRef(null),l=gx(e||"");return h.useEffect(()=>{o&&a.current&&a.current.focus()},[o]),!o&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:ka,children:i}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${r("input-border")}`,borderRadius:"2px",background:r("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:r("fg")},children:l.name}),t.jsx(vi,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:ka,children:i}),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:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},ka={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500};function hx(e){switch(e){case"url":return r("source-url");case"bookID":return r("source-bookid");default:return r("desc-fg")}}function fx(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Xc=({items:e,onChange:n,onOpenEntityPicker:i})=>{const o=Ie(),[s,a]=h.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=u=>{n(e.filter((g,f)=>f!==u)),s===u&&a(null)},c=(u,g,f)=>{const x=[...e];x[u]={...x[u],[g]:f},n(x)},p=(u,g)=>{const f=[...e];f[u]={...f[u],type:g,id:"",name:""},n(f),g==="bookID"&&i&&i(x=>{const v=[...e];v[u]={...v[u],id:x.id,name:x.title,type:"bookID"},n(v)})},m=u=>{i&&i(g=>{const f=[...e];f[u]={...f[u],id:g.id,name:g.title,type:"bookID"},n(f)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,g)=>t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:r("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(s===g?null:g),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:r("fg")},children:u.name||`${o.editor.sourcePlaceholder} ${g+1}`}),u.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:hx(u.type),color:r("on-color-fg"),borderRadius:"3px",fontWeight:500},children:fx(u.type)}),t.jsx("button",{onClick:f=>{f.stopPropagation(),d(g)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===g&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!u.type&&t.jsxs("div",{children:[t.jsx("label",{style:Rt,children:o.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(g,"bookID"),style:{...wa,borderColor:r("source-bookid"),color:r("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:o.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>p(g,"url"),style:{...wa,borderColor:r("source-url"),color:r("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),u.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:Rt,children:o.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const f=[...e];f[g]={...f[g],type:"",id:"",name:""},n(f)},style:Sa,children:o.action.changeType})]}),u.id&&u.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:r("bg"),border:`1px solid ${r("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:r("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:u.name}),t.jsx("code",{style:{fontSize:"11px",background:r("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:u.id})]}),t.jsx("button",{onClick:()=>m(g),style:{background:"transparent",border:`1px solid ${r("widget-border")}`,color:r("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):t.jsxs("button",{onClick:()=>m(g),style:{width:"100%",padding:"14px",border:`2px dashed ${r("widget-border")}`,borderRadius:"6px",background:"transparent",color:r("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),u.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:Rt,children:o.label.sourceName}),t.jsx("button",{onClick:()=>{const f=[...e];f[g]={...f[g],type:"",id:"",name:""},n(f)},style:Sa,children:o.action.changeType})]}),t.jsx("input",{type:"text",value:u.name,onChange:f=>c(g,"name",f.target.value),placeholder:o.editor.sourceNamePlaceholder,style:ln})]}),t.jsxs("div",{children:[t.jsx("label",{style:Rt,children:o.label.urlAddress}),t.jsx("input",{type:"text",value:u.id,onChange:f=>c(g,"id",f.target.value),placeholder:"https://...",style:ln})]})]}),u.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${r("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...Rt,opacity:.7},children:o.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Rt,children:o.label.detailsOptional}),t.jsx("input",{type:"text",value:u.details,onChange:f=>c(g,"details",f.target.value),placeholder:o.editor.detailsPlaceholder,style:ln})]}),t.jsxs("div",{children:[t.jsx("label",{style:Rt,children:o.label.positionOptional}),t.jsx("input",{type:"text",value:u.position,onChange:f=>c(g,"position",f.target.value),placeholder:"如: 卷三, p.52",style:ln})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Rt,children:o.label.dataVersionOptional}),t.jsx("input",{type:"text",value:u.version,onChange:f=>c(g,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:ln})]}),t.jsxs("div",{children:[t.jsx("label",{style:Rt,children:o.label.processorVersionOptional}),t.jsx("input",{type:"text",value:u.processor_version,onChange:f=>c(g,"processor_version",f.target.value),placeholder:"如: v0.1",style:ln})]})]})]})]})})]},g)),t.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:o.action.addSource})]})]})},Rt={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500},ln={width:"100%",padding:"6px 8px",background:r("input-bg"),color:r("input-fg"),border:`1px solid ${r("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},wa={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:r("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Sa={background:"transparent",border:"none",color:r("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Zc(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Jc(e){return!e||e.length===0?"":JSON.stringify(e)}const Qc=({entityType:e,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:m,onLinkEntity:u,onUnlinkEntity:g,onViewEntity:f,onCreateAndLink:x,onSaveRelations:v})=>{const y=Ie();return t.jsxs("div",{style:{background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${r("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})]}),v&&t.jsx("button",{onClick:v,style:xx,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Tn,{direction:"up",title:y.relation.belongsToWork,entity:a,onView:f,onUnlink:()=>g("workId"),onLink:()=>u("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Tn,{direction:"up",title:y.relation.containedInCollection,entity:l,onView:f,onUnlink:()=>g("collectionId"),onLink:()=>u("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:i}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),a&&m&&m.length>0&&t.jsx(cn,{direction:"horizontal",title:`${y.relation.siblingVersions} (${m.length})`,entities:m,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(Tn,{direction:"up",title:y.relation.parentWork,entity:o,onView:f,onUnlink:()=>g("parentWorkId"),onLink:()=>u("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(cn,{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(cn,{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(cn,{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(Tn,{direction:"up",title:y.relation.correspondingWork,entity:a,onView:f,onUnlink:()=>g("workId"),onLink:()=>u("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(Tn,{direction:"up",title:y.relation.parentCollection,entity:s,onView:f,onUnlink:()=>g("parentCollectionId"),onLink:()=>u("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(cn,{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(cn,{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})]})]})]})},Tn=({direction:e,title:n,entity:i,onView:o,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:m,unlinkLabel:u})=>{const g=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",padding:"10px",background:r("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),i?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:r("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:ed(i.type)}),t.jsx("span",{style:{fontWeight:500},children:i.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(_a,{onClick:()=>o(i),title:m,children:"👁️"}),t.jsx(_a,{onClick:s,title:u,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:r("bg"),borderRadius:"4px",color:r("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(Wr,{onClick:a,children:d}),t.jsx(Wr,{onClick:l,primary:!0,children:c})]})]})},cn=({direction:e,title:n,entities:i,onView:o,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=h.useState(!1),m=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),u=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",g=c?i:i.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"4px",padding:"10px",background:r("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:m,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:u}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(f=>t.jsxs("div",{onClick:()=>o(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:r("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:ed(f.type)}),t.jsx("span",{children:f.title})]},f.id)),i.length>5&&!c&&t.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:r("link-fg"),cursor:"pointer"},children:[d," (",i.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:r("bg"),borderRadius:"4px",color:r("desc-fg"),fontSize:"12px",textAlign:"center"},children:l}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(Wr,{onClick:s,primary:!0,children:["+ ",a]})})]})},_a=({onClick:e,title:n,danger:i,children:o})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?r("danger"):"inherit",opacity:.7},children:o}),Wr=({onClick:e,primary:n,children:i})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${r("widget-border")}`,borderRadius:"4px",background:n?r("primary"):"transparent",color:n?r("primary-fg"):"inherit",cursor:"pointer"},children:i});function ed(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const xx={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},td=({isOpen:e,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[m,u]=h.useState(""),g=p?l.filter(y=>y.id!==p):l;h.useEffect(()=>{e&&(u(""),d(""))},[e]);const f=y=>{u(y),d(y)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:bx,children:t.jsxs("div",{style:yx,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),t.jsx("button",{onClick:s,style:jx,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:m,onChange:y=>f(y.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:vx})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:gr,children:"搜索中..."}):g.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(y=>t.jsxs("div",{onClick:()=>o(y),style:kx,children:[t.jsx("span",{style:{fontSize:"16px"},children:v}),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))}):m?t.jsxs("div",{style:gr,children:["未找到匹配的",x]}):t.jsxs("div",{style:gr,children:["输入关键词搜索",x]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${r("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:a,style:wx,children:["创建新",x,"并关联"]})]})]})})},bx={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},yx={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:r("shadow-dialog")},jx={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},vx={width:"100%",padding:"10px 12px",border:`1px solid ${r("input-border")}`,borderRadius:"4px",background:r("input-bg"),color:r("input-fg"),fontSize:"13px",boxSizing:"border-box"},kx={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:r("primary-soft")},gr={padding:"20px",textAlign:"center",color:r("desc-fg")},wx={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},$a={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Sx={work:"📜",book:"📖",collection:"📚",entity:"👤"},nd=({isOpen:e,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:a})=>{const[l,d]=h.useState(""),c=h.useRef(null);h.useEffect(()=>{e&&(d((o==null?void 0:o.title)||""),setTimeout(()=>{var g,f;(g=c.current)==null||g.focus(),(f=c.current)==null||f.select()},100))},[e,o==null?void 0:o.title]);const p=g=>{g.key==="Enter"&&l.trim()?m():g.key==="Escape"&&a()},m=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!e)return null;const u=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${$a[n]}`}};return t.jsx("div",{style:_x,onClick:g=>{g.target===g.currentTarget&&a()},children:t.jsxs("div",{style:$x,onClick:g=>g.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Sx[n]}),t.jsx("span",{children:u()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:r("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:r("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:l,onChange:g=>d(g.target.value),onKeyDown:p,placeholder:`请输入${$a[n]}名称...`,style:Cx})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),background:r("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&t.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:a,style:Tx,children:"取消"}),t.jsx("button",{onClick:m,disabled:!l.trim(),style:{...zx,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},_x={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},$x={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:r("shadow-dialog")},Cx={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${r("input-border")}`,borderRadius:"4px",background:r("input-bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box"},Tx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},zx={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg")};function Nx(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function id(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ix(e){switch(e){case"work":return r("editor-type-work");case"collection":return r("editor-type-collection");case"book":return r("editor-type-book");default:return r("desc-fg")}}const rd=({isOpen:e,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:m})=>{const[u,g]=h.useState(""),[f,x]=h.useState([]),[v,y]=h.useState(!1),[_,b]=h.useState("recent");h.useEffect(()=>{e&&(g(""),x([]),b(o.length>0?"recent":"search"))},[e,o.length]),h.useEffect(()=>{if(!u.trim()){x([]);return}const S=setTimeout(async()=>{y(!0);try{x(await m(u,i))}catch{x([])}finally{y(!1)}},300);return()=>clearTimeout(S)},[u,i,m]);const w=h.useCallback(S=>{g(S.target.value),S.target.value.trim()&&b("search")},[]),j=h.useCallback(S=>s?S.filter(M=>M.id!==s):S,[s]);if(!e)return null;const k=n||(i==="all"?"选择实体":`选择${id(i)}`),C=j(o),$=j(f);return t.jsx("div",{style:Ex,children:t.jsxs("div",{style:Lx,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),t.jsx("button",{onClick:c,style:Ax,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:u,onChange:w,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Mx}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),C.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsxs(Ca,{active:_==="recent",onClick:()=>b("recent"),children:["最近使用 (",C.length,")"]}),t.jsxs(Ca,{active:_==="search",onClick:()=>b("search"),children:["搜索结果 ",$.length>0&&`(${$.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:_==="recent"&&C.length>0?t.jsx(Ta,{entities:C,onSelect:d}):u.trim()?v?t.jsx(hr,{message:"搜索中..."}):$.length>0?t.jsx(Ta,{entities:$,onSelect:d}):t.jsx(hr,{message:"未找到匹配的结果"}):t.jsx(hr,{message:"输入关键词开始搜索"})}),a&&p&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${r("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:p,style:Px,children:l||"创建新实体"})]})]})})},Ca=({active:e,onClick:n,children:i})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${r("primary")}`:"2px solid transparent",background:"transparent",color:r(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:i}),Ta=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(Rx,{entity:i,onClick:()=>n(i)},i.id))}),Rx=({entity:e,onClick:n})=>{const[i,o]=h.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:r("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:Nx(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:r("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:r("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:Ix(e.type),color:r("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:id(e.type)})]})},hr=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:e}),Ex={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lx={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:r("shadow-dialog")},Ax={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Mx={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("input-fg"),fontSize:"13px",boxSizing:"border-box"},Px={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},Bx={work:r("editor-type-work"),collection:r("editor-type-collection"),book:r("editor-type-book"),entity:r("editor-type-entity")},Wx={work:"📜",collection:"📚",book:"📖",entity:"👤"},od=({data:e,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:m,relations:u,onRelationsChange:g})=>{var je;const f=Ie(),[x,v]=h.useState(!1),[y,_]=h.useState("work"),[b,w]=h.useState(""),[j,k]=h.useState(""),[C,$]=h.useState([]),[S,M]=h.useState(!1),[z,T]=h.useState(!1),[P,R]=h.useState("work"),[N,A]=h.useState(""),[H,G]=h.useState(),[ie,le]=h.useState(!1),[V,F]=h.useState(null),[xe,ee]=h.useState([]);h.useRef(null);const L=e.type,Re=L==="work",ce=L==="collection",me=L==="book",se=h.useCallback((Y,be)=>{n({...e,[Y]:be})},[e,n]),Pe=h.useCallback((Y,be)=>{w(Y),_(be),k(f.editor.selectToLink+f.indexType[be]),$([]),v(!0)},[f]),X=h.useCallback(Y=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(e.id,Y)},[o,e.id]),re=h.useCallback(Y=>{s==null||s(Y.id,Y.type)},[s]),de=h.useCallback((Y,be,Ee)=>{const Fe={...Ee,author:(Ee==null?void 0:Ee.author)||e.author,dynasty:Ee==null?void 0:Ee.dynasty};R(be),A(Y),G(Fe),T(!0)},[e.author]),D=h.useCallback((Y,be)=>{o!=null&&o.createAndLink&&o.createAndLink(e.id,N,{type:P,title:Y,inheritData:be}),T(!1)},[o,e.id,N,P]),K=h.useCallback(Y=>{if(!Y.trim()){$([]);return}M(!0),o!=null&&o.searchEntities&&o.searchEntities(Y,y).then(be=>{$(be),M(!1)}).catch(()=>{$([]),M(!1)})},[o,y]),we=h.useCallback(Y=>{o!=null&&o.linkEntity&&o.linkEntity(e.id,b,Y.id),v(!1)},[o,e.id,b]),ne=h.useCallback(()=>{i()},[i]),B=h.useCallback(Y=>{F(()=>Y),le(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(ee).catch(()=>{})},[o]),Z=h.useCallback((Y,be)=>o!=null&&o.searchEntities?o.searchEntities(Y,be==="all"?void 0:be):Promise.resolve([]),[o]),ae=h.useCallback(Y=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(Y),ee(be=>[Y,...be.filter(Ee=>Ee.id!==Y.id)].slice(0,10)),V==null||V(Y),le(!1),F(null)},[o,V]);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 ${r("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:Wx[L]}),t.jsx("span",{children:e.title||f.editor.untitled}),t.jsx(vi,{children:e.id}),t.jsx(vi,{color:Bx[L],children:f.indexType[L]})]})}),t.jsx(kt,{title:f.section.basicInfo,onSave:i,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(gi,{label:Re?f.editor.workTitle:ce?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:Y=>se("title",Y)}),me&&t.jsx(gi,{label:f.editor.belongsToWork,value:e.workName||"",onChange:Y=>se("workName",Y)}),t.jsx(ht,{label:f.editor.authorLabel,value:e.author||"",onChange:Y=>se("author",Y)}),t.jsx(ht,{label:f.editor.publicationYearLabel,value:e.publicationYear||"",onChange:Y=>se("publicationYear",Y)}),(me||ce)&&t.jsx(gi,{label:f.editor.containedIn,value:e.collection||"",onChange:Y=>se("collection",Y)}),(me||ce)&&t.jsx(ht,{label:f.editor.holderLabel,value:e.holder||"",onChange:Y=>se("holder",Y)}),(me||ce)&&t.jsx(ht,{label:me?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:Y=>se("pages",Y)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(ht,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:Y=>se("firstImage",Y)})})]})}),t.jsx(kt,{title:f.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(tn,{value:e.description||"",onChange:Y=>se("description",Y),placeholder:f.editor.descriptionPlaceholder})}),(((je=e.additional_works)==null?void 0:je.length)||0)>0&&t.jsx(kt,{title:f.section.additionalWorks,onSave:i,children:t.jsx(Ox,{items:e.additional_works||[],onChange:Y=>se("additional_works",Y)})}),t.jsx(kt,{title:f.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Fx,{items:e.indexed_by||[],onChange:Y=>se("indexed_by",Y)})}),t.jsx(kt,{title:f.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Hx,{items:e.emendated_by||[],onChange:Y=>se("emendated_by",Y)})}),t.jsx(kt,{title:f.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(vr,{items:e.resources||[],onChange:Y=>se("resources",Y),onDownload:p,downloadStatuses:m,filterType:"text"})}),t.jsx(kt,{title:f.section.imageResources,onSave:i,children:t.jsx(vr,{items:e.resources||[],onChange:Y=>se("resources",Y),onDownload:p,downloadStatuses:m,filterType:"image"})}),t.jsx(kt,{title:f.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(Xc,{items:Zc(e.sources||""),onChange:Y=>se("sources",Jc(Y)),onOpenEntityPicker:B})}),(me||ce)&&t.jsx(kt,{title:f.section.provenance,onSave:i,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(tn,{value:e.provenance||"",onChange:Y=>se("provenance",Y),placeholder:f.editor.provenancePlaceholder})}),me&&t.jsx(kt,{title:f.section.otherEditions,onSave:i,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(tn,{value:e.otherEditions||"",onChange:Y=>se("otherEditions",Y),placeholder:f.editor.otherEditionsPlaceholder})}),t.jsx(Qc,{entityType:L,entityId:e.id,entityTitle:e.title,parentWork:u==null?void 0:u.parentWork,parentCollection:u==null?void 0:u.parentCollection,belongsToWork:u==null?void 0:u.belongsToWork,belongsToCollection:u==null?void 0:u.belongsToCollection,childWorks:u==null?void 0:u.childWorks,childCollections:u==null?void 0:u.childCollections,containedBooks:u==null?void 0:u.containedBooks,siblingBooks:u==null?void 0:u.siblingBooks,onLinkEntity:Pe,onUnlinkEntity:X,onViewEntity:re,onCreateAndLink:de,onSaveRelations:ne}),a&&l&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${r("danger-soft-border")}`,background:r("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:r("danger"),fontWeight:600,marginBottom:"8px"},children:f.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"12px"},children:f.editor.dangerZoneDesc}),t.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("danger")}`,borderRadius:"4px",background:"transparent",color:r("danger"),cursor:"pointer"},children:f.editor.deleteEntity})]}),t.jsx(td,{isOpen:x,entityType:y,title:j,onSelect:we,onCancel:()=>v(!1),onCreate:()=>{v(!1),de(b,y)},searchResults:C,onSearch:K,isLoading:S,excludeId:e.id}),t.jsx(nd,{isOpen:z,entityType:P,relationField:N,inheritData:H,onConfirm:D,onCancel:()=>T(!1)}),t.jsx(rd,{isOpen:ie,title:f.action.selectBookOrWork,filterType:"all",recentEntities:xe,excludeId:e.id,onSelect:ae,onCancel:()=>{le(!1),F(null)},onSearch:Z})]})};function Ox({items:e,onChange:n}){const i=Ie(),o=(l,d,c)=>{const p=e.map((m,u)=>u===l?{...m,[d]:c}:m);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(ht,{label:i.editor.bookNameLabel,value:l.book_title,onChange:c=>o(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(ht,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>o(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:r("muted"),marginTop:"18px"},children:"✕"})]},d)),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${r("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:r("desc-fg"),alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function sd({items:e,onChange:n,showMeta:i,addLabel:o}){const s=Ie(),[a,l]=h.useState(null),d=(m,u,g)=>{const f=e.map((x,v)=>v===m?{...x,[u]:g||void 0}:x);n(f)},c=m=>{n(e.filter((u,g)=>g!==m)),a===m&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,u)=>{const g=a===u;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?`color-mix(in srgb, ${r("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(g?null:u),children:[t.jsx("span",{style:{fontSize:"10px",color:r("desc-fg"),transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.source||s.editor.unnamedSource}),m.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:m.source_bid}),t.jsx("button",{onClick:f=>{f.stopPropagation(),c(u)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${r("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:r("muted")},children:"✕"})]}),!g&&i&&(m.title_info||m.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:r("desc-fg")},children:[m.title_info,m.title_info&&m.author_info&&" — ",m.author_info]}),g&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ht,{label:s.label.sourceName,value:m.source,onChange:f=>d(u,"source",f)}),t.jsx(ht,{label:s.label.sourceBid,value:m.source_bid||"",onChange:f=>d(u,"source_bid",f)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(ht,{label:s.label.titleInfo,value:m.title_info||"",onChange:f=>d(u,"title_info",f)}),t.jsx(ht,{label:s.label.authorInfo,value:m.author_info||"",onChange:f=>d(u,"author_info",f)})]}),t.jsx(ht,{label:s.label.edition,value:m.edition||"",onChange:f=>d(u,"edition",f)})]}),t.jsx(tn,{value:m.summary||"",onChange:f=>d(u,"summary",f),placeholder:s.editor.summaryPlaceholder}),t.jsx(tn,{value:m.comment||"",onChange:f=>d(u,"comment",f),placeholder:s.editor.commentPlaceholder}),t.jsx(tn,{value:m.additional_comment||"",onChange:f=>d(u,"additional_comment",f),placeholder:s.editor.additionalCommentPlaceholder})]})]},u)}),t.jsx("button",{onClick:p,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${r("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:r("desc-fg"),alignSelf:"flex-start"},children:o})]})}function Fx({items:e,onChange:n}){const i=Ie();return t.jsx(sd,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Hx({items:e,onChange:n}){const i=Ie();return t.jsx(sd,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function ad(e){var d,c,p,m,u,g,f;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",i=((p=e.publication_info)==null?void 0:p.year)||"",o=((m=e.current_location)==null?void 0:m.name)||"",s=(u=e.page_count)!=null&&u.number?String(e.page_count.number):((g=e.page_count)==null?void 0:g.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:i,holder:o,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 v=x.related_works.find(y=>y.relation==="part_of");v&&(l.parentWorkId=v.id,l.parentWorkName=v.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 Dx(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 Ux=e=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:m,onAskAI:u,renderSectionActions:g,onDownloadResource:f,downloadStatuses:x,relations:v,onRelationsChange:y,headerExtra:_,className:b,style:w}=e,j=Ie(),[k,C]=h.useState(s),$=a?s:k;h.useEffect(()=>{s!==k&&C(s)},[s]);const S=h.useCallback(()=>{const A=$==="view"?"edit":"view";a?a(A):C(A)},[$,a]),[M,z]=h.useState(null);h.useEffect(()=>{i&&o&&o.getItem(i).then(A=>{A&&z(A)})},[i,o]);const T=n||M,P=h.useMemo(()=>T?ad(T):null,[T]),R=a||!n?t.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:$==="edit"?r("accent-bg"):"transparent",color:r($==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:$==="view"?j.common.switchToEdit:j.common.switchToView,children:$==="view"?j.common.modeEdit:j.common.modeView}):null,N=t.jsxs(t.Fragment,{children:[R,_]});return!T&&!P?t.jsx(nn,{}):$==="view"?t.jsx(no,{data:T,transport:o,onNavigate:p?A=>p(A):void 0,renderLink:m,headerExtra:N,className:b,style:w}):P?t.jsxs("div",{className:b,style:w,children:[N&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:N}),t.jsx(od,{data:P,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:u,renderSectionActions:g,onDownloadResource:f,downloadStatuses:x,relations:v,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:r("muted")},children:j.common.noData})},Vx=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],ld=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const{t:s}=te(),[a,l]=h.useState(null),[d,c]=h.useState(""),[p,m]=h.useState(""),[u,g]=h.useState("idle"),[f,x]=h.useState(""),v=h.useRef(null);h.useEffect(()=>{e&&(l(null),c(""),m(""),g("idle"),x(""))},[e]),h.useEffect(()=>{a&&setTimeout(()=>{var b;return(b=v.current)==null?void 0:b.focus()},100)},[a]),h.useEffect(()=>{if(u==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[u,n]),h.useEffect(()=>{if(!e)return;const b=w=>{w.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const y=async()=>{if(!(!a||!d.trim())){g("submitting"),x("");try{await i({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),g("success")}catch(b){g("error"),x(b instanceof Error?b.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const _=a&&d.trim()&&u!=="submitting";return t.jsx("div",{style:Gx,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:Yx,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:qx,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:Kx,"aria-label":s("feedback.close"),children:"✕"})]}),u==="success"?t.jsxs("div",{style:eb,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:s("feedback.thanks")}),o&&t.jsx("a",{href:o,style:{fontSize:"13px",color:r("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:Vx.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...Xx,...a===b.value?Zx:{}},children:[t.jsx("span",{children:b.icon})," ",s(`feedback.submitType.${b.value}`)]},b.value))}),t.jsx("textarea",{ref:v,value:d,onChange:b=>c(b.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||u==="submitting",style:{...Jx,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:b=>m(b.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||u==="submitting","aria-label":s("feedback.contactLabel"),style:nb}),t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),u==="error"&&t.jsx("div",{style:tb,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:y,disabled:!_,style:{...Qx,opacity:_?1:.6,cursor:_?"pointer":"not-allowed"},children:s(u==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Gx={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Yx={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r("shadow-dialog")},qx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Kx={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Xx={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Zx={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},Jx={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("input-bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Qx={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},eb={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r("success")},tb={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginBottom:"12px"},nb={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},Or="--bim-feedback-fab-offset",Fr=48,ib=16,rb=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:o=!1,zIndex:s})=>{const{t:a}=te(),[l,d]=h.useState(!1),c=n.bottom??24;return h.useEffect(()=>{if(o||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(Or,`calc(${c+Fr+ib}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(Or)}},[o,c]),t.jsxs(t.Fragment,{children:[!o&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ob,zIndex:s??r("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(ld,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},ob={position:"fixed",width:`${Fr}px`,height:`${Fr}px`,borderRadius:"50%",border:"none",background:r("primary"),color:r("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:r("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},sb=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],cd=({onSubmit:e})=>{const{t:n}=te(),[i,o]=h.useState("bug"),[s,a]=h.useState(""),[l,d]=h.useState(""),[c,p]=h.useState("idle"),[m,u]=h.useState(""),g=h.useRef(null);h.useEffect(()=>{i&&setTimeout(()=>{var v;return(v=g.current)==null?void 0:v.focus()},100)},[i]);const f=async()=>{if(!(!i||!s.trim())){p("submitting"),u("");try{await e({type:i,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),o("bug")}catch(v){p("error"),u(v instanceof Error?v.message:n("feedback.submitFailedRetry"))}}},x=i&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:za,children:t.jsxs("div",{style:pb,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:ub,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:za,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:sb.map(v=>t.jsxs("button",{onClick:()=>o(v.value),style:{...ab,...i===v.value?lb:{}},children:[t.jsx("span",{children:v.icon})," ",n(`feedback.submitType.${v.value}`)]},v.value))}),t.jsx("textarea",{ref:g,value:s,onChange:v=>a(v.target.value),placeholder:n(i?`feedback.placeholder.${i}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...cb}}),t.jsx("input",{type:"text",value:l,onChange:v=>d(v.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:gb}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg")},children:[s.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!x,style:{...db,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:mb,children:m})]})},za={padding:"16px",border:`1px solid ${r("widget-border")}`,borderRadius:"8px",background:r("input-bg")},ab={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"6px",background:"transparent",color:r("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},lb={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},cb={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},db={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},pb={display:"flex",alignItems:"center",gap:"12px",color:r("success"),fontSize:"14px"},ub={background:"none",border:"none",color:r("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},mb={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginTop:"8px"},gb={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r("input-border")}`,borderRadius:"6px",background:r("bg"),color:r("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Na(e){return typeof e=="function"?e():e??"/api/feedback"}const dd=({resourceId:e,apiUrl:n})=>{const{t:i}=te(),[o,s]=h.useState([]),[a,l]=h.useState(!0),d=h.useCallback(async()=>{const p=Na(n);l(!0);try{const u=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();u.success&&s(u.items)}catch{}finally{l(!1)}},[e,n]);h.useEffect(()=>{d()},[d]);const c=async p=>{const m=Na(n),u=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const g=await u.json().catch(()=>null);throw new Error((g==null?void 0:g.error)||i("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Oo,{items:o,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(cd,{onSubmit:c})})]})},Pi=8;async function Bi(e,n,i,o){const s=Number.isFinite(n)?Math.max(1,Math.floor(n)):1,a=new Array(e.length);let l=0;const d=Array.from({length:Math.min(s,Math.max(1,e.length))},async()=>{for(;l<e.length&&!(o!=null&&o());){const c=l++;a[c]=await i(e[c],c)}});return await Promise.all(d),a}const hb=Si["zh-Hant"].relation,fb=Si["zh-Hant"].lossStatus,xb=Si["zh-Hant"].resourceKind,Wi=yn("zh-Hant"),Fo=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function Ia(e,n=Wi){return e?Fo(hb,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function bb(e,n=Wi){return Fo(fb,e)?n(`detail.lossStatus.${e}`):e}function yb(e,n=Wi){return Fo(xb,e)?n(`detail.resourceKind.${e}`):""}function Ho({authors:e,onNavigate:n,renderLink:i}){const{convert:o}=te(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=po(a.role);return t.jsxs(h.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",o(a.dynasty),"〕"]}),a.entity_id?t.jsx(et,{id:a.entity_id,label:o(a.name),onNavigate:n,renderLink:i,dense:!0}):o(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:o(d)})]},l)})}):null}function pd(e,n,i=Wi){var c,p;const o=lo(e,n),s=o.mirrors.map(m=>({key:m.key,label:m.label,description:m.description,rows:m.items.filter(u=>u.group_role!=="mirror"),mirrors:m.items.filter(u=>u.group_role==="mirror")})),a=o.buckets.filter(m=>m.key==="image"||m.key==="textImage").flatMap(m=>m.items);a.length&&s.push({key:"_images",label:s.length?i("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=o.buckets.find(m=>m.key==="physical"))==null?void 0:c.items)??[];return l.length&&s.push({key:"_physical",label:i("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((p=o.buckets.find(m=>m.key==="text"))==null?void 0:p.items)??[],groups:s}}function ud(e,n){const i=(e.url?fn(e.url):void 0)||e.name,o=Kl(e,n);return o?`${i}(${o})`:i}function Do({item:e,siblings:n,listedVolumeCounts:i}){const{t:o,convert:s}=te(),[a,l]=h.useState(!1),d=wi(e),c=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),p=s(ud(e,n)),m=xn(e),u=Ri(e,o)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,x;const g=(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:o("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?o("colorMode.color"):o("colorMode.bw")})]}):null;return m?t.jsxs("a",{href:m,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),g]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,g]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:s(u)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(bo,{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(g=>!g),children:a?o("detail.collapseVolumes"):o("detail.expandVolumes",{n:d.expected})})})]})}function md({groups:e,listedVolumeCounts:n}){const{t:i,convert:o}=te();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:o(s.label)}),s.description&&t.jsx("p",{className:"bim-d-rg-d",children:o(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(Do,{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:i("detail.mirror")}),s.mirrors.map((a,l)=>{const d=xn(a),c=o(ud(a,s.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?o(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 Mn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function Hr(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Mn.find(o=>n.startsWith(o.key[0])))==null?void 0:i.key}const Ra=12,jb=60,gd=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,railTop:a,back:l,railLinks:d})=>{var K,we,ne;const{t:c,convert:p,messages:m}=te(),u=h.useMemo(()=>uo({_books:e._books}),[e._books]),[g,f]=h.useState(new Map),[x,v]=h.useState(!1),[y,_]=h.useState(""),[b,w]=h.useState(!1),j=u.length<=jb,k=j||x||!!y||b,C=h.useMemo(()=>k?u:u.slice(0,Ra),[u,k]);h.useEffect(()=>{if(!n||C.length===0)return;const B=C.filter(ae=>!g.has(ae));if(B.length===0)return;let Z=!1;return Bi(B,Pi,ae=>n.getItem(ae).then(je=>{const Y=je??{};return[ae,{id:ae,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(()=>[ae,{id:ae}]),()=>Z).then(ae=>{Z||f(je=>{const Y=new Map(je);for(const[be,Ee]of ae)Y.set(be,Ee);return Y})}),()=>{Z=!0}},[n,C,g]);const $=h.useMemo(()=>u.map(B=>g.get(B)??{id:B}),[u,g]),S=u.length>0&&u.every(B=>g.has(B)),M=!!n&&C.some(B=>!g.has(B)),z=j||k,T=h.useMemo(()=>Zl($,e.version_graph,{era:y,scanOnly:b,sort:z?"year":"default"}),[$,e.version_graph,y,b,z]),P=x?T.rows:T.rows.slice(0,Ra),R=T.allRows.filter(B=>B.hasImage).length,N=h.useMemo(()=>(e._related||[]).map(B=>({...B,title:B.title??""})),[e._related]),A=N.filter(B=>B.relation==="collected_in"),H=h.useMemo(()=>{const B=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],Z=ae=>{const je=B.indexOf(ae??"");return je<0?B.length:je};return N.filter(ae=>ae.relation!=="collected_in").map((ae,je)=>({r:ae,i:je})).sort((ae,je)=>Z(ae.r.relation)-Z(je.r.relation)||ae.i-je.i).map(ae=>ae.r)},[N]),G=h.useMemo(()=>{const B=lo(e.resources,e.resource_groups);return[...B.mirrors.flatMap(Z=>Z.items.map(ae=>({r:ae,kind:p(Z.label)}))),...B.buckets.flatMap(Z=>Z.items.map(ae=>({r:ae,kind:p(yb(Z.key,c))})))]},[e.resources,e.resource_groups,p,c]),ie=e.indexed_by||[],le=e.emendated_by||[],V=h.useMemo(()=>{var W,J,$e;const B=[],Z=(J=(W=e.authors)==null?void 0:W[0])==null?void 0:J.dynasty;Z&&B.push({label:c("workPage.fact.written"),value:p(Z)});const ae=Bt(e,m.unit.juan);if(ae){const Te=($e=e.juan_count)==null?void 0:$e.description;B.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(ae),Te&&Te!==ae?t.jsxs("span",{className:"bim-d-meta",children:["(",p(Te),")"]}):null]})})}e.loss_status&&B.push({label:c("workPage.fact.loss"),value:p(bb(e.loss_status,c))});const je=T.allRows.filter(Te=>Te.sortYear!=null),Y=je.length>0?je.reduce((Te,O)=>Te.sortYear<=O.sortYear?Te:O):null;Y!=null&&Y.era.era?B.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&&B.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),le.length&&B.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:le.length})});const be=Ea(e.additional_titles);be.length&&B.push({label:c("workPage.fact.alias"),value:be.map(p).join("、")});const Ee=Ea(e.attached_texts);Ee.length&&B.push({label:c("workPage.fact.attached"),value:Ee.map(p).join("、")});const Fe=(e.additional_works||[]).map(Te=>p(Te.book_title)+(Te.n_juan!=null?` ${Te.n_juan}${m.unit.juan}`:""));return Fe.length&&B.push({label:c("workPage.fact.appendix"),value:Fe.join("、")}),B},[e,p,c,m,M,T.allRows,le.length]),xe=[{value:e._edition_count??u.length,label:c("workPage.stat.editions")},{value:S?R:0,label:c("workPage.stat.hasImage")},{value:ie.length,label:c("workPage.stat.catalogs")}],ee=mo(e),L=ee?[ee.l1,ee.l2,ee.l3,ee.l4].filter(Boolean).map(B=>p(B)):[],Re=e.subtype?m.workSubtype[e.subtype]??p(e.subtype):"",ce=t.jsx(Fn,{title:p(e.title),byline:t.jsx(Ho,{authors:e.authors,onNavigate:i,renderLink:o}),meta:t.jsx(it,{items:[...L,ee!=null&&ee.source?c("workPage.classifiedBy",{source:p(ee.source.split("/")[0])}):"",Re]}),description:(K=e.description)!=null&&K.text?t.jsxs(t.Fragment,{children:[t.jsx(Pt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(we=e.description.sources)!=null&&we.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(B=>({text:p(gg(B)),href:hg(B)})).filter(B=>B.text).map((B,Z)=>t.jsxs(h.Fragment,{children:[Z>0?" · ":null,B.href?t.jsx("a",{href:B.href,target:"_blank",rel:"noopener noreferrer",children:B.text}):B.text]},Z))}):null]}):void 0,stats:xe,facts:V,readAction:s,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(ne=e.appendix)==null?void 0:ne.map((B,Z)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(B.title)}),t.jsx(Pt,{text:B.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},Z))}),me=T.eras.length>=2?[{key:"",label:c("catalog.all")},...T.eras.map(B=>({key:B,label:`${B} ${T.allRows.filter(Z=>Z.era.era===B).length}`}))]:[],se=[];u.length&&se.push({id:"versions",label:c("workPage.sec.versions"),count:u.length}),ie.length&&se.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:ie.length}),A.length&&se.push({id:"collected",label:c("workPage.sec.collected"),count:A.length}),H.length&&se.push({id:"related",label:c("workPage.sec.related"),count:H.length}),G.length&&se.push({id:"resources",label:c("workPage.sec.resources"),count:G.length});const Pe=u.length===0&&ie.length===0,X=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(ot,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(it,{items:[c("workPage.versionsTotal",{n:u.length}),S&&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&&me.length===0&&u.length>1?"":void 0,children:[me.length>0&&t.jsx(Li,{items:me,value:y,onChange:B=>{_(B),v(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(cc,{label:c("workPage.scanOnly"),checked:b,onChange:B=>{w(B),v(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(z?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&Ai(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:P.map(B=>{var Z;return t.jsx(vb,{row:B,measure:(Z=g.get(B.id))==null?void 0:Z.measure_info,loaded:g.has(B.id),onNavigate:i,renderLink:o},`${B.id}:${g.has(B.id)?"r":"p"}`)})})]}),P.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(go,{total:T.rows.length,shown:P.length,unit:c("workPage.moreUnit"),onClick:()=>v(!0)}),T.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),ie.length>0&&t.jsx(kb,{items:ie,transport:n,onNavigate:i,renderLink:o}),Pe&&t.jsx(ot,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),re=(B,Z)=>t.jsx(et,{id:B,label:p(Z),onNavigate:i,renderLink:o,dense:!0}),de=h.useMemo(()=>{const B=new Map;for(const Z of H){const ae=Ia(Z.relation,c);B.set(ae,(B.get(ae)??0)+1)}return B.size>1?[...B.entries()].sort((Z,ae)=>ae[1]-Z[1]).slice(0,4).map(([Z,ae])=>`${p(Z)} ${ae}`).join(" · "):void 0},[H,p,c]),D=t.jsxs(t.Fragment,{children:[t.jsx(en,{id:"collected",title:c("workPage.sec.collected"),items:A.map(B=>re(B.id,B.title))}),t.jsx(en,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:H.length}),sub:de,items:H.map(B=>t.jsxs(t.Fragment,{children:[re(B.id,B.title),t.jsx("span",{className:"bim-d-meta",title:B.note?p(B.note):void 0,children:p(Ia(B.relation,c))})]}))}),t.jsx(en,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:G.map(({r:B,kind:Z})=>{const ae=p((B.url?fn(B.url):void 0)||B.name),je=xn(B);return t.jsxs(t.Fragment,{children:[je?t.jsxs("a",{href:je,target:"_blank",rel:"noopener noreferrer",children:[ae," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ae}),Z&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:Z})]})})})]});return t.jsx(On,{railTop:a,back:l,nav:se,railLinks:d,main:X,card:ce,side:D})};function Ea(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function La(e,n){return n((e.url?fn(e.url):void 0)||e.name)}function vb({row:e,measure:n,loaded:i,onNavigate:o,renderLink:s}){const{t:a,convert:l}=te(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],m=p?La(p,l):e.locationName?l(e.locationName):"",u=e.images[0],g=u?xn(u):void 0,f=e.images.map(x=>La(x,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(et,{id:e.id,label:l(e.name),onNavigate:o,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):i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${m?"":" bim-d-zt-blank"}`,children:[m||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,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 kb({items:e,transport:n,onNavigate:i,renderLink:o}){const{t:s,convert:a}=te(),[l,d]=h.useState(0),c=Math.min(l,e.length-1),p=e[c],[m,u]=h.useState(new Map);return h.useEffect(()=>{if(!n)return;const g=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(g.length===0)return;let f=!1;return Promise.all(g.map(x=>n.getItem(x).then(v=>{var y,_;return[x,((_=(y=v==null?void 0:v.authors)==null?void 0:y[0])==null?void 0:_.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{f||u(new Map(x.filter(([,v])=>v)))}),()=>{f=!0}},[n,e]),t.jsx(ot,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(it,{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((g,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(g.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:m.get(g.source_bid??"")?a(m.get(g.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(g.source)].slice(0,9).map((x,v)=>t.jsx("span",{children:x},v))})]})},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(it,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(et,{id:p.source_bid,label:a(p.source),onNavigate:i,renderLink:o,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:xt(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:xt(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:xt(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 wb(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 Sb(e,n){if(!e.lineage)return null;const i=e.lineage;return{id:e.id,kind:"book",label:e.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[e.id],note:i.note}}function Aa(e,n,i){return{id:`derive:${n.ref}->${e}:${i}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function _b(e,n,i){const[o,s]=[e,n.book_id].sort();return{id:`sibling:${o}-${s}:${i}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $b(e,n){var p;if(n==="all")return null;const i=(p=e.collections)==null?void 0:p[n],o=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,a=o||s||!!(i!=null&&i.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(!i||!a)return null;const l=o?new Set(i.groups):null,d=new Set(i.book_ids??[]);if(l&&e.node_groups)for(const[m,u]of Object.entries(e.node_groups))l.has(u)&&d.add(m);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),l){c||(c=new Set);for(const m of e.hypothetical_nodes??[])m.group&&l.has(m.group)&&c.add(m.id)}return{books:d,hypos:c}}function hi(e,n,i){const o=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const a=new Set(o.excluded_books??[]),l=o.node_groups??{},d=$b(o,i??o.default_collection??"all"),c=d!==null,p=(d==null?void 0:d.books)??null,m=(d==null?void 0:d.hypos)??null,u=new Set,g=new Set;if(c){const j=new Map(n.map(z=>[z.id,z])),k=new Map((o.hypothetical_nodes??[]).map(z=>[z.id,z])),C=z=>{const T=j.get(z);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(R=>R.ref);const P=k.get(z);return P?(P.derived_from??[]).map(R=>R.ref):[]},$=z=>k.has(z)?!m||m.has(z):!p||p.has(z),S=new Set,M=z=>{if(!S.has(z)){S.add(z);for(const T of C(z))a.has(T)||($(T)||(k.has(T)?g.add(T):j.has(T)&&u.add(T)),M(T))}};for(const z of n)p&&p.has(z.id)&&!a.has(z.id)&&M(z.id);for(const z of o.hypothetical_nodes??[])m&&m.has(z.id)&&M(z.id)}const f=n.filter(j=>!a.has(j.id)).filter(j=>!p||p.has(j.id)||u.has(j.id)).map(j=>{const k=Sb(j,l);return k&&u.has(j.id)&&(k.bridge=!0),k}).filter(j=>j!==null),x=(o.hypothetical_nodes??[]).filter(j=>!m||m.has(j.id)||g.has(j.id)).map(j=>{const k=wb(j);return g.has(j.id)&&(k.bridge=!0),k}),v=[...f,...x],y=new Set(v.map(j=>j.id)),_=new Set,b=[],w=j=>{_.has(j.id)||!y.has(j.source)||!y.has(j.target)||(_.add(j.id),b.push(j))};for(const j of n)a.has(j.id)||!j.lineage||p&&!p.has(j.id)&&!u.has(j.id)||((j.lineage.derived_from??[]).forEach((k,C)=>{w(Aa(j.id,k,C))}),(j.lineage.related_to??[]).forEach((k,C)=>{w(_b(j.id,k,C))}));for(const j of o.hypothetical_nodes??[])m&&!m.has(j.id)&&!g.has(j.id)||(j.derived_from??[]).forEach((k,C)=>{w(Aa(j.id,k,C))});return{nodes:v,edges:b,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(a)}}function hd(e,n,i){const o=(e??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function Cb(e,n){const i=[],o=e.version_graph;if(!o)return i;const s=new Set(n.map(c=>c.id)),a=new Set((o.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...a]),d=(c,p)=>{l.has(p.ref)||i.push(`${c}: derived_from.ref "${p.ref}" 未在 books 或 hypothetical_nodes 中找到`),p.ref_type==="book"&&!s.has(p.ref)&&i.push(`${c}: derived_from.ref "${p.ref}" 标记为 book 但不在 books 列表中`),p.ref_type==="hypothetical"&&!a.has(p.ref)&&i.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(m=>d(p,m)),(c.lineage.related_to??[]).forEach(m=>{s.has(m.book_id)||i.push(`${p}: related_to.book_id "${m.book_id}" 不在 books 列表中`)})}for(const c of o.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(m=>d(p,m))}return i}const fd=({graph:e,renderLink:n,className:i,style:o})=>{const{t:s,convert:a}=te();if(!e.nodes.length)return t.jsx("div",{style:{...Fb,...o},className:i,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 v=d.get(x)??[];v.push(f),d.set(x,v)}const c=new Map(e.nodes.map(f=>[f.id,f])),p=new Map,m=[];for(const f of e.nodes)if(f.group){const x=p.get(f.group)??[];x.push(f),p.set(f.group,x)}else m.push(f);const u=(f,x)=>(f.year??9999)-(x.year??9999);p.forEach(f=>f.sort(u)),m.sort(u);const g=e.groups.filter(f=>p.has(f.id));return t.jsxs("div",{className:i,style:{...zb,...o},children:[e.title&&t.jsx("div",{style:Nb,children:a(e.title)}),e.description&&t.jsx("div",{style:Ib,children:a(e.description)}),g.map(f=>t.jsx(Ma,{label:f.label,color:f.color,nodes:p.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},f.id)),m.length>0&&t.jsx(Ma,{label:s("lineage.otherGroup"),nodes:m,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},Ma=({label:e,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=te();return t.jsxs("div",{style:Rb,children:[t.jsx("div",{style:{...Eb,borderLeftColor:n??r("widget-border")},children:d(e)}),i.map(c=>t.jsx(Tb,{node:c,incoming:o.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Tb=({node:e,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=te();return t.jsxs("div",{style:{...Lb,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?r("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Ab,children:[t.jsx("span",{style:Mb,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Pb,children:hd(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Bb,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:Wb,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ob,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:Ba,children:[t.jsx("div",{style:Wa,children:d("lineage.sources")}),n.map(p=>{const m=o.get(p.source);return t.jsxs("div",{style:Oa(p.confidence),children:[t.jsx("span",{style:Fa,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)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(Pa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:Ha,children:["· ",c(p.evidence)]})]},p.id)})]}),i.length>0&&t.jsxs("div",{style:Ba,children:[t.jsx("div",{style:Wa,children:d("lineage.related")}),i.map(p=>{const m=p.source===e.id?p.target:p.source,u=o.get(m);return t.jsxs("div",{style:Oa(p.confidence),children:[t.jsx("span",{style:Fa,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)??m)}),t.jsx(Pa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:Ha,children:["· ",c(p.evidence)]})]},p.id)})]})]})},zn=({children:e,tone:n="default"})=>{const o={default:{bg:r("tag-bg"),fg:r("fg")},warn:{bg:r("warn-bg"),fg:r("warn-fg")},info:{bg:r("info-bg"),fg:r("info-fg")}}[n];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:o.bg,color:o.fg,marginRight:"4px"},children:e})},Pa=({level:e})=>{const{t:n}=te(),o={certain:{key:"certain",color:r("confidence-certain")},consensus:{key:"consensus",color:r("confidence-consensus")},probable:{key:"probable",color:r("confidence-probable")},disputed:{key:"disputed",color:r("confidence-disputed")}}[e];return o?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:n(`lineage.confidence.${o.key}`)}):null},zb={fontSize:"14px",color:r("fg")},Nb={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ib={fontSize:"13px",color:r("muted"),marginBottom:"16px",lineHeight:1.6},Rb={marginBottom:"16px"},Eb={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r("fg")},Lb={border:`1px solid ${r("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r("bg")},Ab={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Mb={fontSize:"15px",fontWeight:600},Pb={fontSize:"12px",color:r("muted")},Bb={marginBottom:"6px"},Wb={fontSize:"12px",color:r("muted"),margin:"2px 0"},Ob={fontSize:"12px",color:r("muted"),fontStyle:"italic",margin:"4px 0"},Ba={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r("widget-border")}`},Wa={fontSize:"11px",color:r("muted"),marginBottom:"2px"},Oa=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Fa={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r("tag-bg"),color:r("fg"),borderRadius:"3px",marginRight:"6px"},Ha={fontSize:"11px",color:r("muted")},Fb={padding:"20px",textAlign:"center",color:r("muted"),fontSize:"13px"},xd=({selectedNodeId:e,...n})=>{const{t:i}=te(),[o,s]=h.useState("loading"),[a,l]=h.useState(null);return h.useEffect(()=>{let d=!1;return Hb().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),o==="loading"?t.jsx("div",{style:Ua,children:i("lineage.graphLoading")}):o==="missing"||!a?t.jsxs("div",{style:Ua,children:[t.jsx("div",{children:Da(i("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:Da(i("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Db,{modules:a,selectedNodeId:e,...n})};function Da(e,n){return e.split(/(\{\w+\})/).map((i,o)=>{const s=/^\{(\w+)\}$/.exec(i);return t.jsx(h.Fragment,{children:s&&s[1]in n?n[s[1]]:i},o)})}async function Hb(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Db=({graph:e,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:p,Handle:m,Position:u,BaseEdge:g,EdgeLabelRenderer:f,getSmoothStepPath:x,dagre:v}=l,y=h.useMemo(()=>({lineage:C=>{var H,G,ie,le;const $=((H=C.data)==null?void 0:H.stepPosition)??.85,[S,M,z]=x({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:$,borderRadius:5}),T=!!((G=C.data)!=null&&G.isSibling),P=T?M:C.targetX-18,R=T?z:C.targetY-12,N=(ie=C.data)==null?void 0:ie.labelStyle,A=(le=C.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(g,{id:C.id,path:S,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${P}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:r("bg"),border:`0.5px solid ${r("widget-border")}`,...A,...N},children:C.label})})]})}}),[g,f,x]),_=h.useMemo(()=>({version:C=>{const{t:$}=te(),S=C.data,M=S.kind==="hypothetical",z=S.status==="lost",T=S.isSelected,P=S.bridge,R=S.borderColor??r("muted"),N=P||M?"dashed":"solid",A=P?.5:z?.6:1;return t.jsxs("div",{style:{background:r(P?"bg-subtle":"bg"),border:`2px ${N} ${T?r("primary"):R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:T?r("shadow-node-selected"):M||P?"none":r("shadow-node")},title:P?$("lineage.bridgeTitle"):void 0,children:[t.jsx(m,{type:"target",position:u.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:M||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&t.jsx("div",{style:{fontSize:10,color:r("aux-fg"),lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&t.jsx("div",{style:{fontSize:10,color:r("aux-fg"),lineHeight:1.2},children:hd(S.yearText,void 0,S.uncertain)}),z&&t.jsx("div",{style:{fontSize:9,color:r("lost-fg"),marginTop:1},children:$("lineage.lost")}),t.jsx(m,{type:"source",position:u.Right,style:{visibility:"hidden"}})]})}}),[m,u]),{convert:b}=te(),{rfNodes:w,rfEdges:j}=h.useMemo(()=>Ub(e,v,n,a,b),[e,v,n,a,b]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:o,children:t.jsxs(d,{nodes:w,edges:j,nodeTypes:_,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 Ub(e,n,i,o,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(_=>[_.id,_.color??r("muted")]));for(const _ of e.nodes)c.setNode(_.id,{width:160,height:90});const m=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const _ of e.edges)_.kind==="derive"&&(m.has(_.relation)||c.setEdge(_.source,_.target));n.layout(c);const u=e.nodes.map(_=>{const b=c.node(_.id),w=o?_.id===o:void 0,j={kind:_.kind,label:s(_.label),bookId:_.kind==="book"?_.id:void 0,yearText:s(_.year_text??Gb(_)),uncertain:_.year_uncertain,category:_.category,status:_.status,borderColor:_.group?p.get(_.group):void 0,renderLink:i,isSelected:w,description:s(_.description),bridge:_.bridge};return{id:_.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:j,draggable:!1,selected:w}}),g=.78,f=.06,x=new Map;for(const _ of e.edges)_.kind==="derive"&&(x.has(_.source)||x.set(_.source,[]),x.get(_.source).push(_));const v=new Map;for(const[_,b]of x){if(b.length<=1)continue;const w=[...b].sort((k,C)=>{var M,z;const $=((M=c.node(k.target))==null?void 0:M.y)??0,S=((z=c.node(C.target))==null?void 0:z.y)??0;return $-S}),j=w.length;w.forEach((k,C)=>{const $=(C-(j-1)/2)*f;v.set(k.id,g+$)})}const y=e.edges.map(_=>Vb(_,v.get(_.id),s));return{rfNodes:u,rfEdges:y}}function Vb(e,n,i=o=>o??""){const o=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=Yb(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:i(e.relation),data:{labelStyle:{color:r("fg")},isSibling:s,stepPosition:n},style:{stroke:a,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Gb(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Yb(e){switch(e){case"certain":return r("confidence-certain");case"consensus":return r("lineage-edge-consensus");case"probable":return r("confidence-probable");case"disputed":return r("confidence-disputed");default:return r("muted")}}const Ua={padding:"40px 20px",textAlign:"center",color:r("muted"),fontSize:"13px",border:`1px dashed ${r("widget-border")}`,borderRadius:8,background:r("bg")},Uo=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:m,style:u})=>{var j;const{t:g,convert:f}=te(),[x,v]=h.useState(n),y=k=>{v(k),a==null||a(k)},_=(()=>{if(!c)return[];const k=Object.entries(c);return k.length===0||c.all?k:[...k,["all",{label:g("lineage.collectionAll"),description:g("lineage.collectionAllDesc")}]]})(),b=!!(d&&_.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r("muted"),textAlign:"center"},children:g("lineage.empty")});const w=l?(j=c==null?void 0:c[l])==null?void 0:j.description:void 0;return t.jsxs("div",{className:m,style:u,children:[t.jsxs("div",{style:qb,children:[t.jsx("button",{onClick:()=>y("list"),style:fr(x==="list"),children:g("lineage.modeList")}),t.jsx("button",{onClick:()=>y("graph"),style:fr(x==="graph"),children:g("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:r("muted"),marginRight:4},children:g("lineage.collectionLabel")}),_.map(([k,C])=>{const $=p==null?void 0:p[k];return t.jsxs("button",{onClick:()=>d==null?void 0:d(k),style:fr(l===k),title:C.description?f(C.description):void 0,children:[f(C.label),$!=null?` ${$}`:""]},k)})]})]}),b&&w&&t.jsx("div",{style:{fontSize:12,color:r("muted"),marginBottom:8,padding:"4px 8px",background:r("bg-subtle"),borderRadius:4},children:f(w)}),x==="list"?t.jsx(fd,{graph:e,renderLink:i}):t.jsx(xd,{graph:e,renderLink:i,height:o,selectedNodeId:s})]})},qb={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},fr=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${r("widget-border")}`,borderRadius:4,background:e?r("primary"):"transparent",color:r(e?"primary-fg":"fg"),cursor:"pointer"}),Va=40,Ga=2,Kb=9,Xb=new Set(["certain","consensus","probable","disputed"]);function xr(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const bd=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:m})=>{var $e,Te,O,fe,oe,Se,Le,He,Ye,qe,Xe;const u=Ie(),{t:g,convert:f}=te(),[x,v]=h.useState(null),[y,_]=h.useState(new Map),[b,w]=h.useState([]),[j,k]=h.useState(new Map),[C,$]=h.useState(!1),[S,M]=h.useState("flow"),[z,T]=h.useState(null);h.useEffect(()=>{if(!n||!e.work_id){v(null);return}let I=!1;return n.getItem(e.work_id).then(U=>{!I&&U&&U.type==="work"&&v(U)}).catch(()=>{}),()=>{I=!0}},[n,e.work_id]),h.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let I=!1;return n.getLineageGraph(e.work_id).then(U=>{I||T(U&&U.nodes.length>1?U:null)}).catch(()=>{I||T(null)}),()=>{I=!0}},[n,e.work_id]),h.useEffect(()=>{const I=e._collections||[];if(!n||I.length===0){_(new Map);return}let U=!1;return Promise.all(I.map(ue=>{const Ce=ue.id;return n.getItem(Ce).then(ye=>[Ce,ye]).catch(()=>[Ce,null])})).then(ue=>{if(U)return;const Ce=new Map;for(const[ye,ge]of ue)ge&&Ce.set(ye,ge);_(Ce)}),()=>{U=!0}},[n,e._collections]);const P=h.useMemo(()=>{const I=new Set([...x?uo(x):[],...e.related_books||[]]);return I.add(e.id),[...I]},[x,e.related_books,e.id]),R=P.length-1;h.useEffect(()=>{if(!n||R<=0){w([]);return}const I=P.length<=Va,U=I?P:P.slice(0,8);let ue=!1;return Promise.all(U.map(Ce=>Ce===e.id?Promise.resolve({id:Ce,title:e.title,edition:e.edition,year:bi(e)}):n.getItem(Ce).then(ye=>{const ge=ye??{};return{id:Ce,title:ge.title,edition:ge.edition,year:ye?bi(ge):void 0}}).catch(()=>({id:Ce})))).then(Ce=>{if(ue)return;const ye=Ce.filter(ge=>ge.id===e.id||ge.title||ge.edition);I&&ye.sort((ge,Ge)=>(ge.year??1/0)-(Ge.year??1/0)),w(ye)}),()=>{ue=!0}},[n,P,R,e]);const N=e.lineage,A=h.useMemo(()=>[...((N==null?void 0:N.derived_from)||[]).filter(I=>I.ref_type==="book").map(I=>I.ref),...((N==null?void 0:N.related_to)||[]).map(I=>I.book_id)].filter(Boolean),[N]);h.useEffect(()=>{if(!n||A.length===0){k(new Map);return}let I=!1;return Promise.all(A.map(U=>n.getItem(U).then(ue=>[U,{id:U,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[U,{id:U}]))).then(U=>{I||k(new Map(U))}),()=>{I=!0}},[n,A]);const H=h.useMemo(()=>pd(e.resources,e.resource_groups,g),[e.resources,e.resource_groups,g]),G=H.groups.reduce((I,U)=>I+U.rows.length+U.mirrors.length,0),ie=H.groups.length>0&&H.groups.every(I=>I.key==="_physical"),le=Wn(e),V=ic(e),F=Bt(e,u.unit.juan),xe=new Set((e._collections||[]).map(I=>Ln(I.vol).length).filter(I=>I>0)),ee=I=>{var Ce;const U=(Ce=e.base_edition)==null?void 0:Ce.find(ye=>ye.book_id===I&&ye.name);if(U!=null&&U.name)return U.name;const ue=j.get(I);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},L=h.useMemo(()=>{var ke,Ae,Be,Ne,he;const I=[];V&&I.push({label:g("bookPage.fact.editionType"),value:f(V),title:e.edition_type||(ke=e.lineage)!=null&&ke.category?void 0:g("bookPage.inferredFromEdition")}),(Ae=e.publication_info)!=null&&Ae.details?I.push({label:g("bookPage.fact.publication"),value:f(e.publication_info.details)}):(le.era||le.reign)&&I.push({label:g("bookPage.fact.era"),value:f([le.era,le.reign].filter(Boolean).join(" ")),title:le.source==="edition"?g("bookPage.inferredFromEdition"):void 0}),F&&I.push({label:g("bookPage.fact.measure"),value:f(F)});const U=(e._collections||[]).flatMap(ve=>Ln(ve.vol));U.length&&I.push({label:g("bookPage.fact.volumes"),value:g("bookPage.volumesValue",{range:Ei(U,u.unit.volume),unit:u.unit.volume,n:U.length})});const ue=(((Be=e.lineage)==null?void 0:Be.derived_from)||[]).find(ve=>ve.relation==="底本"&&ve.ref_type==="book");ue&&ee(ue.ref)&&I.push({label:g("bookPage.fact.baseEdition"),value:t.jsx(et,{id:ue.ref,label:f(ee(ue.ref)),onNavigate:i,renderLink:o,dense:!0})});const Ce=(e.base_edition||[]).filter(ve=>ve&&ve.name);for(const ve of["底本","配補","參校"]){if(ve==="底本"&&ue&&ee(ue.ref))continue;const Ue=Ce.filter(We=>We.role===ve);Ue.length&&I.push({label:f(ve),value:Ue.map((We,st)=>t.jsxs(h.Fragment,{children:[st>0&&"、",We.book_id?t.jsx(et,{id:We.book_id,label:f(We.name),onNavigate:i,renderLink:o,dense:!0}):f(We.name)]},st))})}const ye=(e.provenance||[]).filter(ve=>ve&&ve.institution),ge=(e.resources||[]).filter(ve=>Mt(ve).includes("physical"));if(ye.length){I.push({label:g("bookPage.fact.holdings"),value:ye.slice(0,2).map(We=>f(We.institution)).join("、")+(ye.length>2?g("bookPage.andMorePlaces",{n:ye.length}):"")});const ve=ye.filter(We=>We.call_number).slice(0,2).map(We=>`${f(We.institution)} ${We.call_number}`);ve.length&&I.push({label:g("bookPage.fact.callNumber"),value:ve.join(";")+(ye.filter(We=>We.call_number).length>2?"…":"")});const Ue=ye.flatMap(We=>We.seals||[]).filter(Boolean);Ue.length&&I.push({label:g("bookPage.fact.seals"),value:f(Ue.join("、"))})}else ge.length?I.push({label:g("bookPage.fact.holdings"),value:ge.slice(0,2).map(ve=>f(ve.name)).join("、")+(ge.length>2?g("bookPage.andMorePlaces",{n:ge.length}):"")}):(Ne=e.current_location)!=null&&Ne.name&&I.push({label:g("bookPage.fact.holdings"),value:f(e.current_location.name)});const Ge=e.physical_description;if(Ge){const ve=[[g("bookPage.fact.leafStyle"),Ge.leaf_style],[g("bookPage.fact.binding"),Ge.binding],[g("bookPage.fact.dimensions"),Ge.dimensions],[g("bookPage.fact.condition"),Ge.condition]];for(const[Ue,We]of ve)We&&We.trim()&&I.push({label:Ue,value:f(We)})}(he=e.page_count)!=null&&he.description&&I.push({label:u.label.pageCount,value:f(e.page_count.description)});const Q=[...Er(e.additional_titles),...Er(e.attached_texts)];return Q.length&&I.push({label:g("bookPage.fact.aliases"),value:Q.map(f).join("、")}),I},[e,f,u,g,le,V,F,j,i,o]),Re=f(e.title),ce=e.edition?f(e.edition):void 0,me=(($e=e.lineage)==null?void 0:$e.year_text)||"",se=t.jsx(Fn,{kind:g("bookPage.kind"),title:Re,subtitle:ce,byline:t.jsx(Ho,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:i,renderLink:o}),meta:(()=>{const I=[V?f(V):"",le.era?f([le.era,le.reign].filter(Boolean).join("")):"",F?f(F):""].filter(Boolean);return I.length?t.jsx("span",{className:"bim-d-tags",children:I.map((U,ue)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ue,2)}`,children:U},ue))}):null})(),description:(Te=e.description)!=null&&Te.text?t.jsx(Pt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:fo((O=e.description)==null?void 0:O.text)?6:void 0,facts:L,readAction:s,secondaryAction:s&&G>0&&!ie?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:g("bookPage.viewImages")}):void 0,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),Pe=e._collections||[],X=(a==null?void 0:a.chapters)||[],re=f(X[0]&&xr(X[0].title)[0].slice(-1)||"")||g("bookPage.chapterUnit"),de=g("bookPage.chapterCount",{n:X.length,unit:re}),D=!!((fe=N==null?void 0:N.derived_from)!=null&&fe.length||(oe=N==null?void 0:N.related_to)!=null&&oe.length||(Se=e.appendix)!=null&&Se.length),K=[],we=g(ie?"bookPage.sec.physical":"bookPage.sec.images");(X.length||H.text.length||l)&&K.push({id:"fulltext",label:g("bookPage.sec.fulltext"),count:X.length?de:void 0}),H.groups.length&&K.push({id:"images",label:we,count:G}),D&&K.push({id:"lineage",label:g("bookPage.sec.lineage")}),Pe.length&&K.push({id:"collections",label:g("section.containedIn"),count:Pe.length}),(Le=e.location_history)!=null&&Le.length&&K.push({id:"provenance",label:g("section.locationHistory")});const ne=I=>(d==null?void 0:d(I))??null,B=X[0],Z=B?ne(B.file):null,ae=C?X:X.slice(0,Kb),je=(I,U,ue)=>I?t.jsx("a",{className:ue,href:I.href??"#",onClick:I.onClick?Ce=>{Ce.metaKey||Ce.ctrlKey||(Ce.preventDefault(),I.onClick())}:void 0,children:U}):t.jsx("span",{className:ue,children:U}),Y=t.jsxs(t.Fragment,{children:[(X.length>0||H.text.length>0||l)&&t.jsxs(ot,{id:"fulltext",title:g("bookPage.sec.fulltext"),meta:X.length>0?t.jsx(it,{items:[de,(He=a==null?void 0:a.source)!=null&&He.name?g("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!B&&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"})]}),B&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:g("bookPage.readFrom",{ch:f(xr(B.title)[0])||g("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((B.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),je(Z,t.jsxs(t.Fragment,{children:[g("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),X.length>1&&t.jsx("ul",{className:"bim-d-chap",children:ae.map(I=>{const[U,ue]=xr(I.title);return t.jsx("li",{children:je(ne(I.file),t.jsxs(t.Fragment,{children:[U&&t.jsx("b",{children:f(U)}),f(ue||I.file)]}))},I.file)})}),X.length>ae.length&&t.jsx(ho,{label:g("detail.expandRest",{n:X.length-ae.length,unit:re}),onClick:()=>$(!0)}),H.text.length>0&&t.jsxs(t.Fragment,{children:[(X.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:g("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:H.text.map((I,U)=>t.jsx(Do,{item:I,siblings:H.text,listedVolumeCounts:xe},`${I.id||I.url||I.name}-${U}`))})})]})]}),H.groups.length>0&&t.jsx(ot,{id:"images",title:we,meta:t.jsx(it,{items:[H.groups.length>1?g("bookPage.groupCount",{n:H.groups.length}):"",g("bookPage.placeCount",{n:G})]}),children:t.jsx(md,{groups:H.groups,listedVolumeCounts:xe})}),D&&t.jsx(ot,{id:"lineage",title:g("bookPage.sec.lineage"),meta:(Ye=N==null?void 0:N.derived_from)!=null&&Ye.length?g("bookPage.lineageMeta"):void 0,action:z?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":g("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>M("flow"),children:g("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>M("graph"),children:g("bookPage.viewGraph")})]}):void 0,children:S==="graph"&&z?t.jsx(Uo,{graph:z,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(I,U)=>t.jsx(et,{id:I,label:f(U),onNavigate:i,renderLink:o,dense:!0})}):t.jsx(Jb,{data:e,heading:ce||Re,yearText:me,refName:ee,onNavigate:i,renderLink:o})}),Pe.length>0&&t.jsx(ot,{id:"collections",title:g("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Pe.map((I,U)=>{const ue=I.id,Ce=Ln(I.vol),ye=y.get(ue),ge=ug(ye);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(et,{id:ue,label:ye?f(ye.title):ue,onNavigate:i,renderLink:o,dense:!0}),Ce.length>0&&t.jsx(Zb,{volumes:Ce,unit:u.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&&g("bookPage.totalOf",{n:ge,unit:u.unit.bu})})]},`${ue}-${U}`)})})})}),(qe=e.location_history)!=null&&qe.length?t.jsx(ot,{id:"provenance",title:g("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((I,U)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(I.name)}),([I.start_date,I.end_date].filter(Boolean).join("—")||I.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(it,{items:[[I.start_date,I.end_date].filter(Boolean).join("—"),I.description?f(I.description):""]})})]},U))})}):null,K.length===0&&t.jsx(ot,{title:g("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:g("bookPage.emptyText")})})]}),be=b.findIndex(I=>I.id===e.id),Ee=P.length<=Va,Fe=Ee&&be>=0?b.slice(Math.max(0,be-Ga),be+Ga+1):b.filter(I=>I.id!==e.id),W=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(u.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(et,{id:x.id,label:f(x.title),onNavigate:i,renderLink:o})}),t.jsx(it,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(I=>`${I.dynasty?`〔${f(I.dynasty)}〕`:""}${f(I.name)}`),f(Bt(x,u.unit.juan)),x._edition_count?g("bookPage.editionCount",{n:x._edition_count}):""]}),((Xe=x.description)==null?void 0:Xe.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&&Fe.length>0&&t.jsxs("div",{children:[t.jsx(en,{id:"siblings",timeline:!0,title:Ee?g("bookPage.siblings"):u.relation.siblingVersions,meta:Ee?g("bookPage.byEra"):g("bookPage.kindCount",{n:R}),cap:Fe.length,items:Fe.map(I=>I.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(I.edition||I.title||I.id)}):t.jsx(et,{id:I.id,label:f(I.edition||I.title||I.id),onNavigate:i,renderLink:o,dense:!0})),metas:Fe.map(I=>[I.year!=null?I.year<0?g("detail.bce",{n:-I.year}):String(I.year):"",I.id===e.id?g("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:Fe.findIndex(I=>I.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(et,{id:x.id,label:g("bookPage.viewAllInWork",{n:P.length}),onNavigate:i,renderLink:o,dense:!0})})]})]}),J=e.work_id?t.jsx(lc,{caption:u.section.belongsToWork,children:t.jsx(et,{id:e.work_id,label:x?f(x.title):" ",onNavigate:i,renderLink:o,dense:!0})}):void 0;return t.jsx(On,{railTop:c,back:p,up:J,nav:K,railLinks:m,main:Y,card:se,side:W})};function Zb({volumes:e,unit:n}){const{t:i}=te();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i("bookPage.volumeRange",{range:Ei(e,n),unit:n}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),i("bookPage.volumeCount",{n:e.length,unit:n})]})]})}function Jb({data:e,heading:n,yearText:i,refName:o,onNavigate:s,renderLink:a}){var _;const{t:l,convert:d}=te(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],m=p.filter(b=>b.ref_type!=="book"),u=p.filter(b=>b.ref_type==="book"&&b.relation==="底本"),g=p.filter(b=>b.ref_type==="book"&&b.relation!=="底本"),f=(c==null?void 0:c.related_to)||[],x=p.length>0||f.length>0,v=b=>b&&Xb.has(b)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${b}`)}):"",y=(b,w)=>t.jsx(et,{id:b,label:d(w||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:[m.map((b,w)=>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),v(b.confidence)]})]})},`a-${w}`)),u.map((b,w)=>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,o(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),v(b.confidence)]})]})},`b-${w}`)),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}),i&&t.jsx("span",{className:"bim-d-lf-yr",children:d(i)})]}),g.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:g.map((b,w)=>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,o(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),v(b.confidence)]})]},w))})]}),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,w)=>t.jsxs("span",{className:"bim-d-lf-chip",title:b.evidence?d(b.evidence):void 0,children:[y(b.book_id,o(b.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(b.relation)})]},w))})]})]}),(_=e.appendix)==null?void 0:_.map((b,w)=>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(Pt,{text:b.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${w}`)),(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 Nn=16,Qb=200,ey=16,yd=({data:e,catalog:n,transport:i,onNavigate:o,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var be,Ee,Fe,W,J,$e,Te;const{t:p,convert:m,messages:u}=te(),[g,f]=h.useState(""),[x,v]=h.useState(!1),[y,_]=h.useState(null),[b,w]=h.useState(""),[j,k]=h.useState(!1),C=h.useMemo(()=>tc(e,n),[e,n]),$=h.useMemo(()=>ec(e),[e]),[S,M]=h.useState(new Map),z=!!i&&C.rows.length>0&&C.rows.length<=Qb,T=z&&(C.rows.length<=Nn||j),P=T&&C.rows.every(O=>!O.id||S.has(O.id)),R=O=>{var fe;return Hr(O?(fe=S.get(O))==null?void 0:fe.l1:void 0)},N=h.useMemo(()=>{const O=g.trim(),fe=O?m(O):"";return C.rows.filter(oe=>{var Le,He;if(b&&Hr(oe.id?(Le=S.get(oe.id))==null?void 0:Le.l1:void 0)!==b)return!1;if(!fe)return!0;const Se=oe.id&&((He=S.get(oe.id))==null?void 0:He.title)||oe.title;return m(Se).includes(fe)||(oe.subItems||[]).some(Ye=>m(Ye).includes(fe))})},[C.rows,g,b,S,m]),A=x?N:N.slice(0,Nn),H=h.useMemo(()=>(T?C.rows:A).filter(O=>O.id&&!S.has(O.id)).map(O=>O.id),[T,C.rows,A,S]);h.useEffect(()=>{if(!i||H.length===0)return;let O=!1;const fe=H.slice(0,ey);return Bi(fe,Pi,oe=>i.getItem(oe).then(Se=>{var Ye,qe;const Le=Se??{},He={title:Le.title,edition:Le.edition,authors:Le.authors,measure:Se?Bt(Se,u.unit.juan):void 0,versionCount:Le._edition_count??((Ye=Le._books)==null?void 0:Ye.length),l1:((qe=mo(Le))==null?void 0:qe.l1)||void 0};return[oe,He]}).catch(()=>[oe,{}]),()=>O).then(oe=>{O||M(Se=>{const Le=new Map(Se);for(const[He,Ye]of oe)Le.set(He,Ye);return Le})}),()=>{O=!0}},[i,H,u.unit.juan]);const G=(be=(e.contained_in||[])[0])==null?void 0:be.id;h.useEffect(()=>{if(!G){_(null);return}if(_({id:G}),!i)return;let O=!1;return i.getItem(G).then(fe=>{O||_({id:G,title:fe==null?void 0:fe.title})}).catch(()=>{}),()=>{O=!0}},[i,G]);const ie=h.useMemo(()=>pd(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),le=ie.text.length+ie.groups.reduce((O,fe)=>O+fe.rows.length+fe.mirrors.length,0),V=$.works,F=new Set(C.rows.map(O=>O.id).filter(Boolean)),xe=V.length>0&&!V.every(O=>F.has(O.id)),ee=(()=>{const O=C.rows.map(fe=>fe.edition).filter(Boolean);return O.length>1&&new Set(O).size===1})(),L=C.rows.some(O=>O.volumes.length>0||O.expected!=null),Re=$.total,ce=$.truncated?Re:C.rows.length,me=Bt(e,u.unit.juan),se=e.count,Pe=O=>typeof O=="number"&&Number.isFinite(O)?O:null,X=Pe(se==null?void 0:se.juan)??Pe((Ee=e.juan_count)==null?void 0:Ee.number),re=Pe(se==null?void 0:se.ce)??(C.totalVolumes||null),de=[{value:ce,label:p("collectionPage.stat.titles")},{value:X??0,label:u.unit.juan},{value:re??0,label:u.unit.volume}],D=h.useMemo(()=>{var oe,Se;const O=[];if((oe=e.publication_info)!=null&&oe.details&&O.push({label:p("collectionPage.fact.publication"),value:m(e.publication_info.details)}),Re&&(Re!==C.rows.length||$.truncated)){const Le=e._member_type==="Book"?p("collectionPage.member.Book"):e._member_type==="Work"?p("collectionPage.member.Work"):p("collectionPage.member.other");O.push({label:Le,value:`${Re} ${u.unit.bu}`,title:p("collectionPage.memberNote")})}const fe=[Pe(se==null?void 0:se.zhong)!=null?p("collectionPage.nZhong",{n:se.zhong}):"",Pe(se==null?void 0:se.han)!=null?p("collectionPage.nHan",{n:se.han}):""].filter(Boolean);return fe.length&&O.push({label:p("collectionPage.fact.expected"),value:fe.join(" ")}),X==null&&me&&O.push({label:p("collectionPage.fact.measure"),value:m(me),title:(Se=e.juan_count)!=null&&Se.description?m(e.juan_count.description):void 0}),O},[e,Re,$.truncated,C.rows.length,X,me,se,m,p,u]),K=h.useMemo(()=>{if(!P)return[];const O=new Map;for(const oe of C.rows){const Se=R(oe.id);Se&&O.set(Se,(O.get(Se)??0)+1)}const fe=Mn.filter(oe=>(O.get(oe.key)??0)>0);return fe.length<2?[]:[{key:"",label:`${u.catalog.all} ${ce}`},...fe.map(oe=>({key:oe.key,label:`${oe.label} ${O.get(oe.key)}`}))]},[P,C.rows,S,u]),we=h.useMemo(()=>{if(!P||!C.rows.some(Se=>Se.volumes.length>0))return null;const O=[],fe=C.rows.filter(Se=>Se.volumes.length>0).map(Se=>({k:R(Se.id)??"",from:Math.min(...Se.volumes),to:Math.max(...Se.volumes)})).sort((Se,Le)=>Se.from-Le.from);for(const Se of fe){const Le=Se.to-Se.from+1,He=O[O.length-1];He&&He.key===Se.k?(He.to=Math.max(He.to,Se.to),He.n+=Le):O.push({key:Se.k,from:Se.from,to:Se.to,n:Le})}const oe=fe.reduce((Se,Le)=>Math.max(Se,Le.to),0);return O.length>1&&O.some(Se=>Se.key)?{segs:O,last:oe}:null},[P,C.rows,S]),ne=(Fe=e.description)==null?void 0:Fe.text,B=t.jsx(Fn,{kind:p("collectionPage.kind"),title:m(e.title),byline:t.jsx(Ho,{authors:e.authors,onNavigate:o,renderLink:s}),meta:t.jsx(it,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(W=e.publication_info)!=null&&W.year?m(e.publication_info.year):""]}),description:ne||(J=e.history)!=null&&J.length?t.jsxs(t.Fragment,{children:[ne&&t.jsx(Pt,{text:ne,style:{fontSize:15,lineHeight:1.85}}),($e=e.history)!=null&&$e.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((O,fe)=>t.jsx("li",{children:m(O)},fe))}):null]}):void 0,clampDescription:fo(ne)||(((Te=e.history)==null?void 0:Te.length)??0)>2?6:void 0,stats:de,facts:D,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:we&&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:we.segs.map((O,fe)=>{const oe=Mn.find(Se=>Se.key===O.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!oe,title:oe?p("collectionPage.dist.segTitle",{section:m(oe.label),from:O.from,to:O.to}):void 0,"aria-label":oe?p("collectionPage.dist.only",{section:m(oe.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!oe&&b===O.key,style:{flexGrow:O.n,background:r(oe?oe.token:"rule")},onClick:()=>{oe&&(w(b===O.key?"":O.key),v(!1))}},fe)})}),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:we.last})})]})]})}),Z=[];C.rows.length&&Z.push({id:"titles",label:p("collectionPage.sec.titles"),count:ce}),le&&Z.push({id:"resources",label:p("collectionPage.sec.resources"),count:le}),xe&&Z.push({id:"works",label:u.section.containedWorks,count:V.length});const ae=t.jsxs(t.Fragment,{children:[C.rows.length>0&&t.jsxs(ot,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(it,{items:[`${ce} ${u.unit.items}`,C.totalVolumes?p("collectionPage.totalVolumes",{n:C.totalVolumes,unit:u.unit.volume}):"",N.length!==ce?p("collectionPage.currentN",{n:N.length,unit:u.unit.items}):""]}),action:a,children:[(C.rows.length>Nn||K.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[K.length>0&&t.jsx(Li,{items:K,value:b,onChange:O=>{w(O),v(!1)}}),z&&C.rows.length>Nn&&!P&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:j,onClick:()=>k(!0),title:p("collectionPage.loadAllTitle",{n:C.rows.length,unit:u.unit.items}),children:p(j?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),C.rows.length>Nn&&t.jsx("input",{type:"search",className:"bim-d-find",value:g,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:O=>{f(O.target.value),v(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Ai(N.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[L&&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:A.map((O,fe)=>{var Xe;const oe=O.id?S.get(O.id):void 0,Se=oe!=null&&oe.title&&O.title===O.id?oe.title:O.title,Le=((oe==null?void 0:oe.authors)||[]).find(I=>I&&I.name),He=[Le?`${Le.dynasty?`〔${m(Le.dynasty)}〕`:""}${m(Le.name)}${Le.role?` ${m(Le.role)}`:""}`:"",oe!=null&&oe.measure?m(oe.measure):"",(Xe=O.subItems)!=null&&Xe.length?O.subItems.map(I=>m(I)).join("、"):"",(oe!=null&&oe.edition||O.edition)&&!ee?m((oe==null?void 0:oe.edition)||O.edition||""):""].filter(Boolean),Ye=Mn.find(I=>I.key===R(O.id)),qe=O.volumes.length>0?p("collectionPage.volumeRange",{range:Ei(O.volumes,u.unit.volume),unit:u.unit.volume}):O.expected!=null?`${O.found??0}/${O.expected} ${u.unit.volume}`:"";return t.jsxs("tr",{children:[L&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${qe?"":" bim-d-zt-blank"}`,children:[Ye&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r(Ye.token)}}),qe||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[O.id?t.jsx(et,{id:O.id,label:m(Se),onNavigate:o,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:m(Se)}),He.length>0?t.jsx(it,{items:He}):O.id&&!oe&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${oe!=null&&oe.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:oe!=null&&oe.versionCount?p("collectionPage.nZhong",{n:oe.versionCount}):""})]},`${O.id??O.title}-${fe}`)})})]}),A.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:p("catalog.noMatch")}),!x&&t.jsx(go,{total:N.length,shown:A.length,unit:u.unit.items,onClick:()=>v(!0)})]}),le>0&&t.jsxs(ot,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:le}),children:[ie.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[ie.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:ie.text.map((O,fe)=>t.jsx(Do,{item:O,siblings:ie.text},`${O.id||O.url||O.name}-${fe}`))})})]}),t.jsx(md,{groups:ie.groups})]}),C.rows.length===0&&le===0&&t.jsx(ot,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),je=xe?t.jsx(en,{id:"works",title:u.section.containedWorks,meta:p("collectionPage.nZhong",{n:V.length}),cap:12,items:V.map(O=>t.jsx(et,{id:O.id,label:m(O.title),onNavigate:o,renderLink:s,dense:!0}))}):null,Y=y?t.jsx(lc,{caption:p("collectionPage.parent"),children:t.jsx(et,{id:y.id,label:m(y.title||y.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return t.jsx(On,{railTop:l,back:d,up:Y,nav:Z,railLinks:c,main:ae,card:B,side:je})},ty=16,br=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Ya(e){if(!e)return br.length;const n=br.indexOf(e);return n===-1?br.length:n}function ny(e,n,i){if(n)return e[n]??i(n)}function iy(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const ry={秦:[-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]},jd=({data:e,transport:n,onNavigate:i,renderLink:o,railTop:s,back:a,railLinks:l})=>{var je,Y,be,Ee,Fe;const{t:d,convert:c,messages:p}=te(),m=W=>iy(W,d),[u,g]=h.useState("全部"),[f,x]=h.useState(!1),[v,y]=h.useState("default"),[_,b]=h.useState(new Map),w=h.useMemo(()=>e._works||[],[e._works]),j=h.useMemo(()=>w.map(W=>{const J=_.get(W.work_id);return{id:W.work_id,title:(J==null?void 0:J.title)??W.title??W.work_id,role:W.role||"",cls:co(W.role),versionCount:J==null?void 0:J.versionCount,section:J==null?void 0:J.cls,l1:J==null?void 0:J.l1,measure:J==null?void 0:J.measure,hasImage:J==null?void 0:J.hasImage,loaded:!!(J!=null&&J.loaded)}}),[w,_]),k=h.useMemo(()=>Ql(w.map(W=>W.role),d("detail.roleAll")),[w,d]),C=h.useMemo(()=>{const W=u==="全部"?j:j.filter(J=>J.cls===u);return v==="versions"?[...W].sort((J,$e)=>($e.versionCount??-1)-(J.versionCount??-1)):W},[j,u,v]),$=f?C:C.slice(0,ty),S=h.useMemo(()=>$.filter(W=>!_.has(W.id)).map(W=>W.id),[$,_]);h.useEffect(()=>{if(!n||S.length===0)return;let W=!1;return Bi(S,Pi,J=>n.getItem(J).then($e=>{var Se;const Te=$e??{},O=Te._edition_count??((Se=Te._books)==null?void 0:Se.length)??0,fe=mo(Te),oe=[fe==null?void 0:fe.l1,fe==null?void 0:fe.l2].filter(Boolean).join(" ");return[J,{id:J,title:Te.title,versionCount:O,loaded:!0,cls:oe||void 0,l1:(fe==null?void 0:fe.l1)||void 0,measure:$e&&Bt($e,p.unit.juan)||void 0,hasImage:!!Te._has_image}]}).catch(()=>[J,{id:J,loaded:!0}]),()=>W).then(J=>{W||b($e=>{const Te=new Map($e);for(const[O,fe]of J)Te.set(O,fe);return Te})}),()=>{W=!0}},[n,S,p.unit.juan]);const M=h.useMemo(()=>{const W=new Map;for(const J of e.alt_names||[]){const $e=J.type||p.section.aliases;W.has($e)||W.set($e,[]),W.get($e).push(J.name)}return[...W.entries()].sort((J,$e)=>Ya(J[0])-Ya($e[0])).map(([J,$e])=>({label:J,names:$e}))},[e.alt_names,p]),z=e.birth_year??((je=e.dates)==null?void 0:je.birth)??void 0,T=e.death_year??((Y=e.dates)==null?void 0:Y.death)??void 0,P=(be=e.dates)==null?void 0:be.floruit,R=z!=null||T!=null?`${m(z)||"?"}—${m(T)||"?"}`:Array.isArray(P)&&P.length===2&&P.every(W=>Number.isFinite(W))?d("entityPage.floruit",{from:m(P[0]),to:m(P[1])}):"",N=new Set(["本名","字","號","号"]),A=M.filter(W=>N.has(W.label)),H=M.filter(W=>!N.has(W.label)),G=H.reduce((W,J)=>W+J.names.length,0),ie=h.useMemo(()=>{const W=[];for(const $e of A)W.push({label:$e.label,value:$e.names.map(Te=>c(Te)).join("、")});const J=w.length;return J&&W.push({label:d("entityPage.fact.works"),value:d("entityPage.nZhong",{n:J})}),W},[w,A,c,d]),le=W=>{var J;return(J=M.find($e=>W.includes($e.label)))==null?void 0:J.names[0]},V=le(["字"]),F=le(["號","号"]),xe=[V?d("entityPage.zi",{name:c(V)}):"",F?d("entityPage.hao",{name:c(F)}):""].filter(Boolean).join(","),ee=e.native_place,L=e.dynasty?ry[e.dynasty]:void 0,Re=(()=>{if(!L||z==null||T==null||T<z)return null;const[W,J]=L,$e=Math.max(z,W),Te=Math.min(T,J);if(Te<=$e)return null;const O=J-W;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:m(z),death:m(T),years:T-z+1}),children:t.jsx("i",{style:{left:`${($e-W)/O*100}%`,width:`${(Te-$e)/O*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${m(W)} ${c(e.dynasty)}`}),t.jsx("span",{children:d("entityPage.lifeYears",{years:T-z+1})}),t.jsx("span",{children:m(J)})]})]})})(),ce=h.useMemo(()=>{if(!n||j.length===0||j.some($e=>!$e.loaded))return null;const W=new Map;for(const $e of j){const Te=Hr($e.l1);Te&&W.set(Te,(W.get(Te)??0)+1)}const J=Mn.map($e=>({...$e,n:W.get($e.key)??0})).filter($e=>$e.n>0);return J.length?J:null},[j,n]),me=t.jsxs(Fn,{kind:ny(p.entityPage.subtype,e.subtype,c),title:c(e.primary_name||e.title),subtitle:xe||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(it,{items:[e.dynasty?c(e.dynasty):"",R,ee?d("entityPage.nativePlace",{place:c(ee)}):""]}),Re]}),description:(Ee=e.description)!=null&&Ee.text?t.jsx(Pt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:fo((Fe=e.description)==null?void 0:Fe.text)?6:void 0,facts:ie,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[G>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:d("entityPage.moreNames",{n:G})}),t.jsx("dl",{children:H.map(W=>t.jsxs(h.Fragment,{children:[t.jsx("dt",{children:c(W.label)}),t.jsx("dd",{children:W.names.map(J=>c(J)).join("、")})]},W.label))})]}),ce&&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:ce.map(W=>t.jsx("i",{style:{flexGrow:W.n,background:r(W.token)}},W.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ce.map(W=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r(W.token)}}),c(W.label)," ",W.n]},W.key))})]})]}),se=h.useMemo(()=>j.filter(W=>W.loaded&&(W.versionCount??0)>0).sort((W,J)=>(J.versionCount??0)-(W.versionCount??0)).slice(0,3),[j]),Pe=!!n&&j.length>=3&&$.some(W=>!W.loaded),X=u==="全部"&&(Pe||se.length>=2),re=e.external_ids||{},de=[];re.cbdb_id!=null&&de.push({label:"CBDB",id:String(re.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${re.cbdb_id}`,note:re.cbdb_match==="auto"?d("entityPage.autoMatch"):void 0});const D=re.wikidata_id;D&&de.push({label:"Wikidata",id:D,href:`https://www.wikidata.org/wiki/${D}`});const K=re.viaf_id;K&&de.push({label:"VIAF",id:K,href:`https://viaf.org/viaf/${K}`});const we=k.map(W=>({key:W.cls,label:`${W.label} ${W.count}`})),ne=[...X&&!Pe?[{id:"featured",label:d("entityPage.sec.featured"),count:se.length}]:[],...j.length?[{id:"works",label:d("entityPage.sec.allWorks"),count:j.length}]:[],...de.length?[{id:"external",label:d("entityPage.sec.external"),count:de.length}]:[]],B=X?t.jsxs(ot,{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(W=>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:" "})]},W)),!Pe&&se.map(W=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(et,{id:W.id,label:c(W.title),onNavigate:i,renderLink:o,dense:!0})}),t.jsx(it,{items:[W.section?c(W.section):"",W.measure?c(W.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:W.versionCount}),t.jsx("span",{children:d("entityPage.versionsUnit")}),W.hasImage&&t.jsx("span",{className:"bim-d-flag",children:d("entityPage.hasImage")})]})]},W.id))]})]}):null,Z=j.length===0?t.jsx(ot,{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:[B,t.jsxs(ot,{id:"works",title:d("entityPage.sec.works"),meta:t.jsx(it,{items:[d("entityPage.total",{n:j.length}),C.length!==j.length?d("entityPage.current",{n:C.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[we.length>1&&t.jsx(Li,{items:we,value:u,onChange:W=>{g(W),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":v==="versions",onClick:()=>{v==="default"&&x(!0),y(W=>W==="default"?"versions":"default")},children:d(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!f&&Ai(C.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(W=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(et,{id:W.id,label:c(W.title),onNavigate:i,renderLink:o,dense:!0}),W.measure?t.jsx(it,{items:[c(W.measure)]}):!W.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${W.section||W.loaded?"":" bim-d-zt-blank"}`,children:W.section?c(W.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${W.role?"":" bim-d-zt-blank"}`,children:W.role?c(W.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${W.loaded?"":" bim-d-zt-blank"}`,children:W.loaded?W.versionCount?d("entityPage.nZhong",{n:W.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:d("entityPage.notRecorded")}):""}),t.jsx("td",{className:W.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:W.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:d("entityPage.hasImage")})})]},W.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(go,{total:C.length,shown:$.length,unit:d("entityPage.moreUnit"),onClick:()=>x(!0)})]})]}),ae=de.length>0?t.jsx(en,{id:"external",title:d("entityPage.sec.external"),items:de.map(W=>t.jsxs("a",{href:W.href,target:"_blank",rel:"noopener noreferrer",children:[W.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:de.map(W=>W.id),foot:re.cbdb_id!=null&&re.cbdb_match==="auto"?d("entityPage.cbdbAuto"):void 0}):null;return t.jsx(On,{railTop:s,back:a,nav:ne,railLinks:l,main:Z,card:me,side:ae})},Vo="(max-width: 719px)",oy=`${Vo}, (pointer: coarse)`,vd=`
1355
1354
  .bim-ct {
1356
1355
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
1357
1356
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -1510,7 +1509,7 @@ ${B??""}`,[Gi,es]=h.useState({key:Gn,data:U,started:!!U});if(Gi.key!==Gn)es({key
1510
1509
  /* 窄屏分类抽屉:界栏下按钮和面板都有框 */
1511
1510
  :root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${r("fr-bd")}; background: ${r("fr-bg")}; }
1512
1511
  :root[data-layout="boxed"] .bim-ct-drawer { border: ${r("fr-bd")}; }
1513
- `,Qt="未分類",At="all",Go=20;function Un(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const o=(i??"").trim();if(!o)break;n.push(o)}return n}function sy(e){const n=Un(e);return n.length?n.join("/"):Qt}function ay(e){const n=Un(e);return n.length?n.map((i,o)=>n.slice(0,o+1).join("/")):[Qt]}function ly(e,n=[]){const i=new Map;n.forEach((d,c)=>{const p=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(m=>!!m);p.forEach((m,u)=>{const g=p.slice(0,u+1).join("/");i.has(g)||i.set(g,c)})});const o=new Map;let s=0;for(const d of e){const c=Un(d.classification);if(!c.length){s++;continue}let p=o;c.forEach((m,u)=>{const g=c.slice(0,u+1).join("/");let f=p.get(m);f||(f={id:g,label:m,count:0,children:new Map},p.set(m,f)),f.count++,p=f.children})}const a=d=>[...d.values()].sort((c,p)=>{const m=c.label===Qt?1:0,u=p.label===Qt?1:0;if(m!==u)return m-u;const g=i.get(c.id)??1/0,f=i.get(p.id)??1/0;return g!==f?g-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(o);return s>0&&l.push({id:Qt,label:Qt,count:s}),l}function pn(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const o=pn(i.children,n);if(o.length)return[i,...o]}}return[]}function Yo(e){return e.reduce((n,i)=>n+i.count,0)}function cy(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function dy(e){var d;const n={id:e.id,title:e.title||e.id},i=e.juan_count,o=typeof i=="number"?i:i==null?void 0:i.number;typeof o=="number"&&o>0?n.juan=o: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=cy(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);a&&(n.summary=a);const l=Un(e.classification);return l.length&&(n.classification=l),n}function py(e,n){const i=e.summary?0:1,o=n.summary?0:1;return i!==o?i-o:e.title.localeCompare(n.title,"zh")}function uy(e,n=Go){return Math.max(1,Math.ceil(e/n))}function kd(e,n,i=2){if(n<=1)return[1];const o=new Set([1,n]);for(let l=e-i;l<=e+i;l++)l>=1&&l<=n&&o.add(l);const s=[...o].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 my=()=>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 gy(e,n,i){const o=[];i&&o.push({id:At,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;o.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),o}function wd({tree:e,selectedId:n,onSelect:i,allLabel:o,label:s}){const{t:a,convert:l}=te(),d=o===void 0?a("catalogPage.all"):o,c=s??a("catalogPage.classification"),p=h.useRef(null),m=n&&n!==At?n:null,u=d!==null,[g,f]=h.useState(()=>{const S=new Set;for(const M of pn(e,m))S.add(M.id);return S});h.useEffect(()=>{const S=pn(e,m);S.length&&f(M=>{if(S.every(T=>M.has(T.id)))return M;const z=new Set(M);for(const T of S)z.add(T.id);return z})},[e,m]);const x=h.useMemo(()=>gy(e,g,u),[e,g,u]),[v,y]=h.useState(null);h.useEffect(()=>{y(null)},[n]);const _=m??(u?At:null),b=h.useMemo(()=>{var z;const S=new Set(x.map(T=>T.id));if(v&&S.has(v))return v;if(_&&S.has(_))return _;const M=pn(e,m).map(T=>T.id).filter(T=>S.has(T));return M.length?M[M.length-1]:((z=x[0])==null?void 0:z.id)??null},[x,v,_,e,m]),w=h.useCallback((S,M)=>{f(z=>{const T=z.has(S),P=M??!T;if(P===T)return z;const R=new Set(z);return P?R.add(S):R.delete(S),R})},[]),j=h.useCallback(S=>{y(S),requestAnimationFrame(()=>{var z;const M=Array.from(((z=p.current)==null?void 0:z.querySelectorAll("[data-ct-id]"))??[]).find(T=>T.dataset.ctId===S);M==null||M.focus()})},[]),k=h.useCallback((S,M)=>{M&&w(S,!0),i(S)},[i,w]),C=h.useCallback(S=>{const M=S.target.closest("[data-ct-id]");if(!M)return;const z=M.dataset.ctId,T=x.findIndex(N=>N.id===z);if(T<0)return;const P=x[T];let R=null;switch(S.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(!P.hasChildren)break;g.has(z)?R=P.firstChildId:w(z,!0);break;case"ArrowLeft":P.hasChildren&&g.has(z)?w(z,!1):R=P.parentId;break;case"Enter":case" ":S.preventDefault(),k(z,P.hasChildren);return;default:return}S.preventDefault(),R&&R!==z&&j(R)},[x,g,w,j,k]),$=(S,M)=>S.map((z,T)=>{var H;const P=(H=z.children)!=null&&H.length?z.children:null,R=!!P&&g.has(z.id),N=z.id===m,A=M===1&&S.length>1&&T===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":M,"aria-expanded":P?R:void 0,"aria-selected":N,tabIndex:b===z.id?0:-1,"data-ct-id":z.id,className:A?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":M-1},onClick:()=>{y(z.id),k(z.id,!!P)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:P?G=>{G.stopPropagation(),y(z.id),w(z.id)}:void 0,children:P?t.jsx(my,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(z.label)}),t.jsx("span",{className:"bim-ct-n",children:z.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:$(P,M+1)})]},z.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:C,children:[u&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!m,tabIndex:b===At?0:-1,"data-ct-id":At,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{y(At),i(At)},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:Yo(e).toLocaleString("en-US")})]})}),$(e,1)]})}const Sd=e=>`/item/${encodeURIComponent(e)}`;function hy(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function _d(e,n){return e==null||e===""?null:typeof e=="number"?n("catalogPage.juanN",{n:e}):e}function $d({work:e,href:n}){var d,c;const{t:i,convert:o}=te(),s=_d(e.juan,i),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:o(e.title)}),s&&t.jsx("span",{className:"bim-ct-juan",children:o(s)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((p,m)=>t.jsxs(h.Fragment,{children:[m>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},m))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:o(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>o(p)).join(" · ")})]})})}function Cd({work:e,href:n}){var d,c;const{t:i,convert:o}=te(),s=_d(e.juan,i),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:[o(e.title),s&&t.jsx("span",{className:"bim-ct-juan",children:o(s)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((p,m)=>t.jsxs(h.Fragment,{children:[m>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},m))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>o(p)).join(" · ")})]})})}function Td({page:e,pageCount:n,onPage:i,pageHref:o,label:s}){const{t:a,convert:l}=te();if(n<=1)return null;const d=p=>m=>{i&&(o&&!hy(m)||(m.preventDefault(),i(p)))},c=(p,m,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:m});const g={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return o?t.jsx("a",{...g,href:o(p),onClick:d(p),children:m}):t.jsx("button",{type:"button",...g,onClick:u.current?void 0:d(p),children:m})};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:kd(e,n).map((p,m)=>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${m}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=n})]})}function zd({works:e,workLink:n=Sd,emptyText:i,view:o="card",...s}){const{t:a,convert:l}=te();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:i===void 0?a("catalogPage.emptyWorks"):typeof i=="string"?l(i):i}):o==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Cd,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx($d,{work:d,href:n(d.id)},d.id))}),t.jsx(Td,{...s})]})}const fy=()=>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 xy({tree:e,selectedId:n,page:i,pageCount:o,works:s,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:p,allLabel:m,allTitle:u,pageSize:g=Go,className:f,view:x,onViewChange:v}){const{t:y,convert:_}=te(),b=m===void 0?y("catalogPage.all"):m,w=u??y("catalogPage.allTitle"),k=`bim-ct-drawer-${h.useId().replace(/:/g,"")}`,[C,$]=h.useState(!1),[S,M]=h.useState("card"),z=x??S,T=G=>{M(G),v==null||v(G)},P=pn(e,n&&n!==At?n:null),R=P.length?P[P.length-1]:null,N=R?R.label:w,A=R?R.count:Yo(e),H=h.useCallback(G=>{$(!1),a(G)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":C?"open":"closed",children:[t.jsx("style",{children:vd}),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":C,"aria-controls":k,onClick:()=>$(G=>!G),children:[t.jsx("span",{children:y("catalogPage.drawerLabel",{path:_(P.length?P.map(G=>G.label).join(" › "):b??w)})}),t.jsx(fy,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:k,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("catalogPage.classification")}),t.jsx(wd,{tree:e,selectedId:n,onSelect:H,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:_(N)}),P.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:_(P.slice(0,-1).map(G=>G.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y("catalogPage.stat",{total:A.toLocaleString("en-US"),size:g}),o>1&&y("catalogPage.statPage",{page:i,pages:o})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":z==="card",onClick:()=>T("card"),children:y("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":z==="list",onClick:()=>T("list"),children:y("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(zd,{works:s,view:z,workLink:c,page:i,pageCount:o,onPage:l,pageHref:p})]})]})}const Vn="(max-width: 719px)",by="(max-width: 1079px)",yy=`${Vn}, (pointer: coarse)`,jy=[8,18,30,42,88],qo=`
1512
+ `,Qt="未分類",Lt="all",Go=20;function Un(e){if(!e)return[];const n=[];for(const i of[e.l1,e.l2,e.l3,e.l4]){const o=(i??"").trim();if(!o)break;n.push(o)}return n}function sy(e){const n=Un(e);return n.length?n.join("/"):Qt}function ay(e){const n=Un(e);return n.length?n.map((i,o)=>n.slice(0,o+1).join("/")):[Qt]}function ly(e,n=[]){const i=new Map;n.forEach((d,c)=>{const p=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(m=>!!m);p.forEach((m,u)=>{const g=p.slice(0,u+1).join("/");i.has(g)||i.set(g,c)})});const o=new Map;let s=0;for(const d of e){const c=Un(d.classification);if(!c.length){s++;continue}let p=o;c.forEach((m,u)=>{const g=c.slice(0,u+1).join("/");let f=p.get(m);f||(f={id:g,label:m,count:0,children:new Map},p.set(m,f)),f.count++,p=f.children})}const a=d=>[...d.values()].sort((c,p)=>{const m=c.label===Qt?1:0,u=p.label===Qt?1:0;if(m!==u)return m-u;const g=i.get(c.id)??1/0,f=i.get(p.id)??1/0;return g!==f?g-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(o);return s>0&&l.push({id:Qt,label:Qt,count:s}),l}function pn(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const o=pn(i.children,n);if(o.length)return[i,...o]}}return[]}function Yo(e){return e.reduce((n,i)=>n+i.count,0)}function cy(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function dy(e){var d;const n={id:e.id,title:e.title||e.id},i=e.juan_count,o=typeof i=="number"?i:i==null?void 0:i.number;typeof o=="number"&&o>0?n.juan=o: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=cy(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);a&&(n.summary=a);const l=Un(e.classification);return l.length&&(n.classification=l),n}function py(e,n){const i=e.summary?0:1,o=n.summary?0:1;return i!==o?i-o:e.title.localeCompare(n.title,"zh")}function uy(e,n=Go){return Math.max(1,Math.ceil(e/n))}function kd(e,n,i=2){if(n<=1)return[1];const o=new Set([1,n]);for(let l=e-i;l<=e+i;l++)l>=1&&l<=n&&o.add(l);const s=[...o].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 my=()=>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 gy(e,n,i){const o=[];i&&o.push({id:Lt,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;o.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),o}function wd({tree:e,selectedId:n,onSelect:i,allLabel:o,label:s}){const{t:a,convert:l}=te(),d=o===void 0?a("catalogPage.all"):o,c=s??a("catalogPage.classification"),p=h.useRef(null),m=n&&n!==Lt?n:null,u=d!==null,[g,f]=h.useState(()=>{const S=new Set;for(const M of pn(e,m))S.add(M.id);return S});h.useEffect(()=>{const S=pn(e,m);S.length&&f(M=>{if(S.every(T=>M.has(T.id)))return M;const z=new Set(M);for(const T of S)z.add(T.id);return z})},[e,m]);const x=h.useMemo(()=>gy(e,g,u),[e,g,u]),[v,y]=h.useState(null);h.useEffect(()=>{y(null)},[n]);const _=m??(u?Lt:null),b=h.useMemo(()=>{var z;const S=new Set(x.map(T=>T.id));if(v&&S.has(v))return v;if(_&&S.has(_))return _;const M=pn(e,m).map(T=>T.id).filter(T=>S.has(T));return M.length?M[M.length-1]:((z=x[0])==null?void 0:z.id)??null},[x,v,_,e,m]),w=h.useCallback((S,M)=>{f(z=>{const T=z.has(S),P=M??!T;if(P===T)return z;const R=new Set(z);return P?R.add(S):R.delete(S),R})},[]),j=h.useCallback(S=>{y(S),requestAnimationFrame(()=>{var z;const M=Array.from(((z=p.current)==null?void 0:z.querySelectorAll("[data-ct-id]"))??[]).find(T=>T.dataset.ctId===S);M==null||M.focus()})},[]),k=h.useCallback((S,M)=>{M&&w(S,!0),i(S)},[i,w]),C=h.useCallback(S=>{const M=S.target.closest("[data-ct-id]");if(!M)return;const z=M.dataset.ctId,T=x.findIndex(N=>N.id===z);if(T<0)return;const P=x[T];let R=null;switch(S.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(!P.hasChildren)break;g.has(z)?R=P.firstChildId:w(z,!0);break;case"ArrowLeft":P.hasChildren&&g.has(z)?w(z,!1):R=P.parentId;break;case"Enter":case" ":S.preventDefault(),k(z,P.hasChildren);return;default:return}S.preventDefault(),R&&R!==z&&j(R)},[x,g,w,j,k]),$=(S,M)=>S.map((z,T)=>{var H;const P=(H=z.children)!=null&&H.length?z.children:null,R=!!P&&g.has(z.id),N=z.id===m,A=M===1&&S.length>1&&T===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":M,"aria-expanded":P?R:void 0,"aria-selected":N,tabIndex:b===z.id?0:-1,"data-ct-id":z.id,className:A?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":M-1},onClick:()=>{y(z.id),k(z.id,!!P)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:P?G=>{G.stopPropagation(),y(z.id),w(z.id)}:void 0,children:P?t.jsx(my,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(z.label)}),t.jsx("span",{className:"bim-ct-n",children:z.count.toLocaleString("en-US")})]}),R&&t.jsx("ul",{role:"group",children:$(P,M+1)})]},z.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:C,children:[u&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!m,tabIndex:b===Lt?0:-1,"data-ct-id":Lt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{y(Lt),i(Lt)},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:Yo(e).toLocaleString("en-US")})]})}),$(e,1)]})}const Sd=e=>`/item/${encodeURIComponent(e)}`;function hy(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function _d(e,n){return e==null||e===""?null:typeof e=="number"?n("catalogPage.juanN",{n:e}):e}function $d({work:e,href:n}){var d,c;const{t:i,convert:o}=te(),s=_d(e.juan,i),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:o(e.title)}),s&&t.jsx("span",{className:"bim-ct-juan",children:o(s)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((p,m)=>t.jsxs(h.Fragment,{children:[m>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},m))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:o(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>o(p)).join(" · ")})]})})}function Cd({work:e,href:n}){var d,c;const{t:i,convert:o}=te(),s=_d(e.juan,i),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:[o(e.title),s&&t.jsx("span",{className:"bim-ct-juan",children:o(s)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((p,m)=>t.jsxs(h.Fragment,{children:[m>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},m))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>o(p)).join(" · ")})]})})}function Td({page:e,pageCount:n,onPage:i,pageHref:o,label:s}){const{t:a,convert:l}=te();if(n<=1)return null;const d=p=>m=>{i&&(o&&!hy(m)||(m.preventDefault(),i(p)))},c=(p,m,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:m});const g={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return o?t.jsx("a",{...g,href:o(p),onClick:d(p),children:m}):t.jsx("button",{type:"button",...g,onClick:u.current?void 0:d(p),children:m})};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:kd(e,n).map((p,m)=>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${m}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=n})]})}function zd({works:e,workLink:n=Sd,emptyText:i,view:o="card",...s}){const{t:a,convert:l}=te();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:i===void 0?a("catalogPage.emptyWorks"):typeof i=="string"?l(i):i}):o==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Cd,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx($d,{work:d,href:n(d.id)},d.id))}),t.jsx(Td,{...s})]})}const fy=()=>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 xy({tree:e,selectedId:n,page:i,pageCount:o,works:s,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:p,allLabel:m,allTitle:u,pageSize:g=Go,className:f,view:x,onViewChange:v}){const{t:y,convert:_}=te(),b=m===void 0?y("catalogPage.all"):m,w=u??y("catalogPage.allTitle"),k=`bim-ct-drawer-${h.useId().replace(/:/g,"")}`,[C,$]=h.useState(!1),[S,M]=h.useState("card"),z=x??S,T=G=>{M(G),v==null||v(G)},P=pn(e,n&&n!==Lt?n:null),R=P.length?P[P.length-1]:null,N=R?R.label:w,A=R?R.count:Yo(e),H=h.useCallback(G=>{$(!1),a(G)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":C?"open":"closed",children:[t.jsx("style",{children:vd}),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":C,"aria-controls":k,onClick:()=>$(G=>!G),children:[t.jsx("span",{children:y("catalogPage.drawerLabel",{path:_(P.length?P.map(G=>G.label).join(" › "):b??w)})}),t.jsx(fy,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:k,children:[t.jsx("h2",{className:"bim-ct-side-h",children:y("catalogPage.classification")}),t.jsx(wd,{tree:e,selectedId:n,onSelect:H,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:_(N)}),P.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:_(P.slice(0,-1).map(G=>G.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[y("catalogPage.stat",{total:A.toLocaleString("en-US"),size:g}),o>1&&y("catalogPage.statPage",{page:i,pages:o})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":y("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":z==="card",onClick:()=>T("card"),children:y("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":z==="list",onClick:()=>T("list"),children:y("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(zd,{works:s,view:z,workLink:c,page:i,pageCount:o,onPage:l,pageHref:p})]})]})}const Vn="(max-width: 719px)",by="(max-width: 1079px)",yy=`${Vn}, (pointer: coarse)`,jy=[8,18,30,42,88],qo=`
1514
1513
  .bim-rh { color: ${r("ink")}; font-family: ${r("font-ui")}; font-size: 14px; line-height: 1.6; }
1515
1514
  .bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
1516
1515
  .bim-rh a { color: ${r("accent")}; text-decoration: none; }
@@ -1911,4 +1910,4 @@ ${jy.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1911
1910
  .bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
1912
1911
  .bim-mh-recent-h button { min-height: 44px; }
1913
1912
  }
1914
- `,Gd={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function Vt(e){return{...Gd,...e??{}}}function Yd(e,n){if(e.lineage)return e.lineage(n);const i=e.item(n),o=i.indexOf("#"),[s,a]=o<0?[i,""]:[i.slice(0,o),i.slice(o)];return`${s}${s.includes("?")?"&":"?"}tab=lineage${a}`}function Jo(e,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(e/n*100)))}function qd(e){const n=e.filter(p=>Number.isFinite(p.birth_year)||Number.isFinite(p.death_year)),i=e.filter(p=>!n.includes(p));if(!n.length)return{min:0,max:0,placed:[],missing:i};const o=p=>{const m=Number.isFinite(p.birth_year)?p.birth_year:p.death_year-50,u=Number.isFinite(p.death_year)?p.death_year:p.birth_year+50;return[Math.min(m,u),Math.max(m,u)]},s=n.map(o),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,m)=>({p,from:s[m][0],to:s[m][1]})).sort((p,m)=>p.from-m.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:i}}function ki(e,n=yn("zh-Hant")){return e<0?n("metaHome.yearBC",{n:-e}):String(e)}function $y(e){return{read:e.item,work:e.item,node:e.node}}function Kd({counts:e,links:n}){const{t:i}=te(),o=n==null?void 0:n.type;if(!o)return null;const s=[["all",i("metaHome.typeAll"),null],["work",i("metaHome.typeLabel.work"),e.works],["book",i("metaHome.typeLabel.book"),e.books],["collection",i("metaHome.typeLabel.collection"),e.collections],["entity",i("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":i("metaHome.typeChipsLabel"),children:s.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:o(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:Ke(d)})]})},a))})}function Xd(e,n=5){const[i,o]=h.useState(null);h.useEffect(()=>{let a=!1;const l=Dt().slice(0,n);if(!l.length||!e){o([]);return}return Promise.all(l.map(d=>to(e,d))).then(d=>{a||o(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,n]);const s=h.useCallback(()=>{eo(),o([])},[]);return{entries:i,clear:s}}function Cy(e,n,i){const o=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return o?i(o):Zd(e.type,n)}function Zd(e,n){return n(`metaHome.typeLabel.${e}`)}function Jd({entries:e,onClear:n,links:i}){const{t:o,convert:s}=te(),a=Vt(i);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:o("metaHome.recentTitle")}),e&&e.length>0&&n&&t.jsx("button",{type:"button",onClick:n,children:o("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":o("metaHome.recentItemLabel",{type:l.type?Zd(l.type,o):"",title:s(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?o(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:s(l.title)}),t.jsx("small",{"aria-hidden":"true",children:Cy(l,o,s)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:o("metaHome.recentEmpty")})]})}function Qd(e,n,i,o=!1){return o&&(e==="done"||e==="in_progress")?n(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?n(`metaHome.status.${e}`):i(e)}function ep({rows:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":i("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[i("metaHome.catalogTitle"),t.jsx("small",{children:i("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:i("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:i("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:i("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:i("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:i("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=Jo(a.imported,a.total),d=a.work_id??a.collection_id,c=o(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:Ke(a.total)}),t.jsx("td",{className:"bim-mh-r",children:Ke(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:Qd(a.status,i,o)})})]},a.id||a.name)})})]})}):null}function tp({items:e,links:n,label:i}){const{convert:o}=te();return t.jsx("ul",{className:"bim-rh-rows","aria-label":i?o(i):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:o(s.title)}),s.sub&&t.jsx("small",{children:o(s.sub)})]})},s.id))})}function np({works:e,links:n}){const{t:i}=te(),[o,s]=h.useState(!1);if(!e.length)return null;const a=Bn(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[i("metaHome.relatedTitle"),t.jsx("small",{children:i("metaHome.relatedNote")})]}),t.jsx(tp,{items:e.map(l=>({id:l.id,title:l.title,sub:Oi(l)||void 0})),links:Vt(n)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>s(l=>!l),children:o?i("action.collapse"):i("metaHome.allNWorks",{n:e.length})})]})}const ip="siku_qige";function Ty({group:e,links:n}){const{t:i,convert:o}=te(),[s,a]=h.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Bn(e.items.length)?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[o(e.label),t.jsx("small",{className:"bim-rh-num",children:i("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(tp,{items:e.items,links:n,label:e.label}),Bn(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>a(l=>!l),children:s?i("action.collapse"):i("metaHome.allNKinds",{n:e.items.length})})]})}function rp({groups:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);if(!e.length)return null;const a=e.find(c=>c.key===ip),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:[o(a.label),t.jsx("small",{children:o(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":o(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:s.item(c.id),"aria-label":o(c.title),title:o(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:o(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:i("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(Ty,{group:c,links:s},c.key))})]})}const qa=34,Ka=13;function Xa(e,n){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?ki(e.birth_year,n):"?"}–${e.death_year!=null?ki(e.death_year,n):"?"}`}function zy(e,n){const i=n-e,o=i>1200?300:i>400?100:50,s=[];for(let a=Math.ceil(e/o)*o;a<=n;a+=o)s.push(a);return s}function op({people:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=qd(e),p=[],m=d.map(g=>{const f=g.left>70,x=f?Math.min(g.left,g.left+g.width-Ka):g.left;let v=0;for(;p[v]!=null&&p[v]>x;)v++;return p[v]=f?g.left+g.width:g.left+Math.max(g.width,Ka),{...g,lane:v,end:f}}),u=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[m.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:p.length*qa+10},children:m.map(g=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":g.end?"":void 0,style:{left:`${g.left}%`,top:g.lane*qa+4,width:`${Math.max(g.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:s.item(g.p.id),children:[o(g.p.name),t.jsx("small",{className:"bim-rh-num",children:Xa(g.p,i)})]})]},g.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:zy(a,l).map(g=>t.jsx("span",{style:{left:`${(g-a)/u*100}%`},children:ki(g,i)},g))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":m.length?void 0:"",children:(m.length?e:c).map(g=>t.jsx("li",{children:t.jsxs("a",{href:s.item(g.id),children:[t.jsx("span",{children:o(g.name)}),t.jsx("small",{className:"bim-rh-num",children:[g.dynasty?o(g.dynasty):"",Xa(g,i)].filter(Boolean).join(" ")})]})},g.id))}),c.length>0&&m.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:i("metaHome.missingLife",{names:o(c.map(g=>g.name).join("、"))})})]})}const Ny=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 sp({works:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=Oi(a);return t.jsx("li",{children:t.jsxs("a",{href:Yd(s,a.id),children:[Ny,t.jsx("b",{children:o(a.title)}),l&&t.jsx("small",{children:o(l)}),t.jsx("span",{children:i("metaHome.viewLineage")})]})},a.id)})}):null}function ap({sites:e}){const{t:n,convert:i}=te(),o=e.filter(a=>a.status!=="todo"&&a.total>0),s=e.filter(a=>!o.includes(a));return e.length?t.jsxs(t.Fragment,{children:[o.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:o.map(a=>{const l=Jo(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:i(a.name)}):t.jsx("span",{children:i(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${Ke(a.imported)} / ${Ke(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:Qd(a.status,n,i,!0)})]})]},a.id||a.name)})}),s.length>0&&t.jsx("p",{className:"bim-mh-todo",children:n("metaHome.plannedSites",{names:i(s.map(a=>a.name).join("、"))})})]}):null}const Za=["extant","partially_extant","lost","unknown"];function lp({stats:e,links:n,version:i,repoUrl:o,downloadHref:s}){const{t:a}=te(),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=Za.some(p=>{var m;return(((m=e.loss)==null?void 0:m[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,m])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:Ke(p)}),t.jsx("span",{children:m})]},m))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:Za.map(p=>{var g;const m=((g=e.loss)==null?void 0:g[p])??0,u=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&&m>0?a("metaHome.lossCount",{n:Ke(m),note:u}):u})]})},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"),o?t.jsx("a",{href:o,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),i&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:i})]}),s&&t.jsx("p",{children:t.jsx("a",{href:s,children:a("metaHome.download")})})]})]})}const cp={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function Iy({sections:e,links:n,head:i,transport:o,catalogHref:s,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:p,className:m}){var k,C;const{t:u}=te(),g=e,f=Vt(n),x=$y(f),v=cp,y=Xd(o),_={zhi:!!((k=g.shelf)!=null&&k.items.length)||g.catalog_progress.length>0||g.related_catalogs.length>0,sibu:g.bu.length>0||g.unclassified>0,cong:g.collection_groups.length>0,people:g.bibliographers.length>0,lineage:g.lineage.length>0,sites:g.sites.length>0,data:!0},b=Object.keys(v).filter($=>_[$]),w=$=>u(`metaHome.nav.${$}`),j=($,S)=>$?t.jsx("a",{className:"bim-rh-more",href:$,children:S}):void 0;return t.jsxs("div",{className:m?`bim-rh bim-mh ${m}`:"bim-rh bim-mh",children:[t.jsx("style",{children:qo+Vd}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[i,t.jsx(Kd,{counts:g.counts,links:n})]}),o&&t.jsx(Jd,{entries:y.entries,onClear:y.clear,links:n})]}),b.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":u("metaHome.navLabel"),children:t.jsx("ul",{children:b.map($=>t.jsx("li",{children:t.jsx("a",{href:`#${v[$]}`,children:w($)})},$))})}),t.jsxs("div",{className:"bim-rh-main",children:[_.zhi&&t.jsxs(dt,{id:v.zhi,title:w("zhi"),sub:u("metaHome.zhiSub"),children:[g.shelf&&g.shelf.items.length>0&&t.jsx(Xo,{topic:{key:"shelf",label:g.shelf.label,shelf:!0,items:g.shelf.items},links:x,showTitle:!1,legendCount:g.shelf.items.some($=>$.records)?u("metaHome.shelfLegendCount"):null,legendExtra:[u("metaHome.shelfLegendClick")]}),(g.catalog_progress.length>0||g.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(C=g.shelf)!=null&&C.items.length?void 0:{marginTop:0},children:[t.jsx(ep,{rows:g.catalog_progress,links:n}),t.jsx(np,{works:g.related_catalogs,links:n})]})]}),_.sibu&&t.jsx(dt,{id:v.sibu,title:w("sibu"),sub:u("metaHome.sibuSub"),more:j(s,u("metaHome.toCatalog")),children:t.jsx(Zo,{bu:g.bu,unclassified:g.unclassified,links:x,unclassifiedNote:u("metaHome.unclassifiedNote")})}),_.cong&&t.jsx(dt,{id:v.cong,title:w("cong"),sub:u("metaHome.congSub"),more:j(a,u("metaHome.allNKindsMore",{n:Ke(g.counts.collections)})),children:t.jsx(rp,{groups:g.collection_groups,links:n})}),_.people&&t.jsx(dt,{id:v.people,title:w("people"),sub:u("metaHome.peopleSub"),more:j(l,u("metaHome.allNPeopleMore",{n:Ke(g.counts.entities)})),children:t.jsx(op,{people:g.bibliographers,links:n})}),_.lineage&&t.jsx(dt,{id:v.lineage,title:w("lineage"),sub:u("metaHome.lineageSub"),children:t.jsx(sp,{works:g.lineage,links:n})}),_.sites&&t.jsx(dt,{id:v.sites,title:w("sites"),sub:u("metaHome.sitesSub"),children:t.jsx(ap,{sites:g.sites})}),t.jsx(dt,{id:v.data,title:w("data"),sub:u("metaHome.dataSub"),children:t.jsx(lp,{stats:g.stats,links:n,version:d,repoUrl:c,downloadHref:p})})]})]})}const dp=["_related","_catalogs","_collections","_members","_children"],Ry=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Dr=e=>Ry(e)&&!!e.h;function Ey(e){return e?dp.some(n=>{const i=e[n];return Array.isArray(i)&&i.some(Dr)}):!1}function Ly(e,n){const i={...e};if(!n)return i;for(const o of dp){const s=e[o];!Array.isArray(s)||!s.some(Dr)||(i[o]=s.map(a=>{var c;if(!Dr(a)||typeof a.title=="string"&&a.title)return a;const l=a.id??a.bid,d=l?(c=n[l])==null?void 0:c.title:void 0;return d?{...a,title:d}:a}))}return i}function Ay(e){let n=null;const i=()=>e.getHubs?(n??(n=e.getHubs().catch(()=>null)),n):Promise.resolve(null);return new Proxy(e,{get(o,s){if(s==="getItem")return async l=>{const d=await o.getItem(l);return d&&Ly(d,Ey(d)?await i():null)};const a=Reflect.get(o,s,o);return typeof a=="function"?a.bind(o):a}})}const Ur=({style:e})=>{const n=h.useContext(Tt),{t:i}=te();if(!n)return null;const{locale:o,setLocale:s}=n,a=o==="zh-Hant",l=()=>s(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:i(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 ${r("border")}`,borderRadius:"4px",background:r("bg"),color:r("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?r("primary"):void 0,fontWeight:a?700:400},children:i("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:r("primary"),fontWeight:a?400:700},children:i("common.localeShortHans")})]})},Vr=({href:e,label:n,size:i=16,className:o,style:s})=>{const{t:a}=te(),l=n??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:r("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:d=>{d.currentTarget.style.color=r("fg")},onMouseLeave:d=>{d.currentTarget.style.color=r("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})})};function yr(e){const n=e.text_count;return typeof n=="number"&&n>0}function jr(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function My(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const Py=({id:e,transport:n,initialDetail:i,initialEntry:o,activeTab:s,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:p,lineageCollection:m,onLineageCollectionChange:u,initialPage:g=1,selectedLineageNodeId:f,onNavigate:x,onBack:v,backLabel:y,renderLink:_,enrichDetail:b,getSourceLink:w,readLink:j,railTop:k,extraTabs:C=[],showFeedbackTab:$=!0,feedbackApiUrl:S,height:M,footerExtra:z,hideHeaderControls:T=!1,className:P,style:R})=>{const N=h.useMemo(()=>Ay(n),[n]),A=Ie(),{t:H,convert:G}=te(),[ie]=h.useState(()=>{if(!My(e,i))return null;const Q={...i},ke=o??jr(e,Q);return b&&b(ke,Q),{id:e,entry:ke,detail:Q}}),[le,V]=h.useState((ie==null?void 0:ie.entry)??null),[F,xe]=h.useState((ie==null?void 0:ie.detail)??null),[ee,L]=h.useState(!ie),[Re,ce]=h.useState(!1),[me,se]=h.useState([]),[Pe,X]=h.useState(!1),[re,de]=h.useState(null),[D,K]=h.useState(null),[we,ne]=h.useState(null),[B,Z]=h.useState(!1),ae=h.useRef(null),je=h.useRef(0),[Y,be]=h.useState(null),Ee=l!==void 0?l:Y,Fe=h.useCallback(Q=>{d?d(Q):be(Q)},[d]),W=h.useCallback(async Q=>{if(!N.getCollectionCatalogs&&!N.getCollectionCatalog){se([]);return}X(!0);try{if(N.getCollectionCatalogs)se(await N.getCollectionCatalogs(Q)||[]);else if(N.getCollectionCatalog){const ke=await N.getCollectionCatalog(Q);se(ke?[{resource_id:"",data:ke}]:[])}}catch{se([])}finally{X(!1)}},[N]),J=h.useCallback(async Q=>{var ke,Ae;if(!N.getTextManifest||!N.getTextIndex){de(null),K(Q);return}try{const Be=_e.pickTextVersion(await N.getTextManifest(Q)),Ne=Be?await N.getTextIndex(Q,Be.key):null;de(Ne&&Ne.chapters.length>0?{chapters:Ne.chapters.map(he=>({n:he.n,title:he.title,file:he.file})),source:{name:((ke=Ne.source)==null?void 0:ke.name)??(Be==null?void 0:Be.source_name),license:((Ae=Ne.source)==null?void 0:Ae.license)??(Be==null?void 0:Be.license)??void 0}}:null)}catch{de(null)}finally{K(Q)}},[N]),$e=h.useCallback(async(Q,ke)=>{const Ae=++je.current,Be=()=>Ae!==je.current;Z(!0);try{if(N.getLineageGraph){const jt=await N.getLineageGraph(Q);if(Be())return;jt&&ne(jt)}const Ne=ke.version_graph;if(!Ne||!Ne.enabled){we||ne(null),ae.current=null;return}const he=uo(ke),Ue=(await Bi(he,Pi,async jt=>{try{return await N.getItem(jt)}catch{return null}},Be)).filter(Boolean);if(Be())return;ae.current={work:ke,books:Ue};const We=m??Ne.default_collection??(Ne.core_books&&Ne.core_books.length>0?"core":"all"),st=We==="core"&&Array.isArray(Ne.core_books)&&Ne.core_books.length>0?"core":We??"all";ne(hi(ke,Ue,st))}catch{if(Be())return;ne(null),ae.current=null}finally{Be()||Z(!1)}},[N]),Te=h.useRef({initialDetail:i,initialEntry:o});Te.current={initialDetail:i,initialEntry:o},h.useEffect(()=>{let Q=!1;je.current++,Z(!1);const ke=he=>{he.type==="collection"?W(e):he.type==="work"?(he.version_graph||N.getLineageGraph)&&$e(e,he):he.type==="book"&&yr(he)&&J(e)},Ae=Te.current;let Be=null;if(ie&&ie.id===e)Be=ie;else if(Ae.initialDetail&&Ae.initialDetail.id===e){const he={...Ae.initialDetail},ve=Ae.initialEntry??jr(e,he);b&&b(ve,he),Be={entry:ve,detail:he}}return Be?(ce(!1),se(he=>he.length?[]:he),de(null),ne(null),ae.current=null,V(Be.entry),xe(Be.detail),L(!1),ke(Be.detail),()=>{Q=!0}):((async()=>{L(!0),ce(!1),V(null),xe(null),se([]),de(null),ne(null),ae.current=null;try{const he=await N.getItem(e);if(Q)return;if(!he){ce(!0);return}const ve=he;let Ue=null;if(N.getEntry&&(Ue=await N.getEntry(e),Q))return;Ue||(Ue=jr(e,ve)),b&&b(Ue,ve),V(Ue),xe(ve),ke(ve)}catch{Q||ce(!0)}finally{Q||L(!1)}})(),()=>{Q=!0})},[e,N,ie,b,W,$e,J]),h.useEffect(()=>{const Q=ae.current;!Q||!m||ne(hi(Q.work,Q.books,m))},[m]);const O=[];if(F){if(O.push({key:"basic",label:A.detailTab.basicInfo}),F.type==="collection"){Pe&&me.length===0&&O.push({key:"catalog:loading",label:`${A.detailTab.catalog}…`});for(const Q of me)O.push({key:`catalog:${Q.resource_id}`,label:Q.short_name?`${G(Q.short_name)}${A.detailTab.catalogSuffix}`:A.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&O.push({key:s,label:A.detailTab.fullText}),F.type==="work"&&(we||B)&&O.push({key:"lineage",label:B?`${A.detailTab.lineage}…`:A.detailTab.lineage});for(const Q of C)(Q.position??"before-feedback")==="before-feedback"&&Q.shouldShow(F)&&O.push({key:Q.key,label:Q.label});$&&s==="feedback"&&O.push({key:"feedback",label:A.detailTab.feedback});for(const Q of C)Q.position==="after-feedback"&&Q.shouldShow(F)&&O.push({key:Q.key,label:Q.label})}h.useEffect(()=>{if(s!=="emendated"||!F)return;a("basic");const Q=setTimeout(()=>{var ke;(ke=document.getElementById("studies"))==null||ke.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(Q)},[s,F,a]);const fe=le&&F&&w?w({activeTab:s,activeJuan:Ee,entry:le,detail:F}):null,oe=h.useMemo(()=>{var Ne;if(!F)return null;const ke=(F.authors??[]).map(he=>{const ve=po(he.role);return`${he.dynasty?`〔${G(he.dynasty)}〕`:""}${G(he.name)}${ve?` ${G(ve)}`:""}`}).join(" · ");let Ae=!1;try{Ae=_e.extractStatus(F.id)==="draft"}catch{}if(F.type==="book"){const he=F;return{title:G(he.title),subtitle:he.edition?G(he.edition):ke||void 0,aside:[Ae?A.status.draft:"",ke&&he.edition?ke:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(F.type==="collection"){const he=F;return{title:G(he.title),subtitle:G(Wt(he,A.unit.juan))||void 0,aside:[(Ne=he.publication_info)==null?void 0:Ne.year,Ae?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ke||void 0}}if(F.type==="entity"){const he=F,ve=We=>We==null?"":We<0?H("detail.bce",{n:-We}):String(We),Ue=he.birth_year!=null||he.death_year!=null?`${ve(he.birth_year)||"?"}—${ve(he.death_year)||"?"}`:"";return{title:G(he.primary_name||he.title),subtitle:[he.dynasty?`〔${G(he.dynasty)}〕`:"",Ue].filter(Boolean).join(" ")||void 0,aside:Ae?A.status.draft:void 0,secondLine:void 0}}const Be=G(Wt(F,A.unit.juan));return{title:G(F.title),subtitle:[Be,ke].filter(Boolean).join(" · ")||void 0,aside:[Wy(A,F.subtype),Ae?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[F,G,A,H]),Se=F&&yr(F)?"text":null,Le=()=>{Fe(null),a("fulltext")};let He=null;if(F&&j){const Q=j({detail:F,kind:Se});Q&&(He=t.jsx(Nr,{href:Q}))}else Se&&(He=t.jsx(Nr,{onClick:Le}));const Ye=Q=>{if(!F)return null;const ke=Q.replace(/\.[^.]+$/,"");if(j){const Ae=j({detail:F,kind:Se,juan:ke});return Ae?{href:Ae}:null}return{onClick:()=>{Fe(ke),a("fulltext")}}},qe=new Set(C.map(Q=>Q.key)),Xe=O.filter(Q=>Q.key.startsWith("catalog:")&&Q.key!=="catalog:loading"||Q.key==="lineage"&&!!we&&!B||qe.has(Q.key)).map(Q=>({key:Q.key,label:Q.label,onClick:()=>a(Q.key)})),I=()=>{var Q;return F?F.type==="work"?t.jsx(gd,{data:F,transport:N,onNavigate:x,renderLink:_,readAction:He,railTop:k,railLinks:Xe}):F.type==="book"?t.jsx(bd,{data:F,transport:N,onNavigate:x,renderLink:_,readAction:He,fullText:re,fullTextPending:yr(F)&&!!N.getTextManifest&&D!==F.id,chapterLink:Ye,railTop:k,railLinks:Xe}):F.type==="collection"?t.jsx(yd,{data:F,catalog:(Q=me[0])==null?void 0:Q.data,transport:N,onNavigate:x,renderLink:_,readAction:He,railTop:k,railLinks:Xe,catalogAction:me.length>0?t.jsxs("a",{href:"#catalog",onClick:ke=>{ke.preventDefault(),a(`catalog:${me[0].resource_id}`)},children:[G(A.detailTab.collectionCatalog)," →"]}):null}):t.jsx(jd,{data:F,transport:N,onNavigate:x,renderLink:_,railTop:k,railLinks:Xe}):null},U=()=>{var ke,Ae,Be;if(!le||!F)return null;if(s==="basic"||s==="emendated")return I();if(typeof s=="string"&&s.startsWith("catalog:")){const Ne=(ke=me.find(he=>`catalog:${he.resource_id}`===s))==null?void 0:ke.data;return t.jsx(io,{data:Ne,onNavigate:x,renderLink:_})}if(s==="collated"||s==="fulltext")return t.jsx(Wo,{id:e,transport:N,chapter:Ee,onLocationChange:Ne=>Fe(Ne.chapter),onNavigate:x});if(s==="lineage"){if(!we)return t.jsx("div",{style:{color:r("label-fg"),padding:"24px 0"},children:H(B?"detail.loading":"detail.noLineageGraph")});const Ne=F.type==="work"?F:null;return t.jsx(Uo,{graph:we,renderLink:_,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:p,selectedNodeId:f,collection:m??((Ae=Ne==null?void 0:Ne.version_graph)==null?void 0:Ae.default_collection),onCollectionChange:u,collectionsAvailable:(Be=Ne==null?void 0:Ne.version_graph)==null?void 0:Be.collections,collectionCounts:(()=>{var We,st,jt,on,Gt,q,Ve;if(!Ne)return;const he={},ve=((We=ae.current)==null?void 0:We.books)??[];he.all=(((st=Ne._books)==null?void 0:st.length)??0)-(((on=(jt=Ne.version_graph)==null?void 0:jt.excluded_books)==null?void 0:on.length)??0);const Ue=(Gt=Ne.version_graph)==null?void 0:Gt.collections;if(Ue)for(const Oe of Object.keys(Ue))he[Oe]=hi(Ne,ve,Oe).nodes.filter(rt=>rt.kind==="book"&&!rt.bridge).length;return he.core==null&&((Ve=(q=Ne.version_graph)==null?void 0:q.core_books)!=null&&Ve.length)&&(he.core=Ne.version_graph.core_books.length),he})()})}if(s==="feedback"&&$)return t.jsx(dd,{resourceId:e,apiUrl:S});const Q=C.find(Ne=>Ne.key===s);return Q?Q.render({detail:F,entry:le,transport:N,onNavigate:x}):null};if(ee)return t.jsx(In,{style:{minHeight:M,...R},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((Q,ke)=>t.jsx("div",{style:{height:ke===1?40:16,width:Q,opacity:.35,background:r("rule")}},ke))})});if(Re||!F||!le||!oe)return t.jsx(In,{style:{minHeight:M,...R},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r("label-fg"),fontSize:14},children:H("detail.notFound")})});const ue=s==="basic"||s==="emendated",Ce=[{label:y??A.detailTab.backToIndex,onClick:v}];if(F.type==="book"&&F.work_id){const Q=F.work_id;Ce.push({label:A.indexType.work,id:Q,onClick:()=>x==null?void 0:x(Q)})}Ce.push({label:A.indexType[F.type]});const ye=s==="collated"||s==="fulltext",ge=typeof z=="string"?A.status[z.trim()]??z:z,Ge=t.jsx(vc,{left:t.jsxs(t.Fragment,{children:[ge,ge?" · ":"",t.jsx(By,{id:F.id,label:A.label.id,copied:A.action.copied,copyLabel:A.action.copy})]}),right:t.jsxs(t.Fragment,{children:[$&&!ue&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r("meta-fg")},children:A.detailTab.submitVersion}),fe&&t.jsx("a",{href:fe.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r("meta-fg")},children:A.detailTab.dataLicense})]})});return ue?t.jsx("div",{className:P,children:t.jsxs(In,{grid:!0,style:{minHeight:M,...R},children:[t.jsx(Ir,{breadcrumb:t.jsx(Rr,{items:Ce}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Ur,{style:{border:"none",background:"transparent"}}),!T&&fe&&t.jsx(Vr,{...fe})]})}),I(),Ge]})}):t.jsx("div",{className:P,children:t.jsxs(In,{wide:ye,style:{minHeight:M,...R},children:[t.jsx(Ir,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(xo,{char:"籍"}),t.jsx(Rr,{items:Ce})]}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Ur,{}),$&&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:r("meta-fg")},children:A.detailTab.feedback}),!T&&fe&&t.jsx(Vr,{...fe})]})}),t.jsx(uc,{...oe,aside:ye?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:r("accent"),borderBottom:`1px solid ${r("rule")}`},children:[H("detail.workInfo")," →"]}):oe.aside}),!ye&&O.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:O.map(Q=>t.jsx(mc,{label:Q.label,active:Q.key===s||ue&&Q.key==="basic",onClick:()=>a(Q.key)},Q.key))}),t.jsx("div",{style:{marginTop:!ye&&O.length>1?8:0},children:U()}),Ge]})})};function By({id:e,label:n,copied:i,copyLabel:o}){const[s,a]=h.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?i:o,"aria-label":s?i:o,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:r("aux-fg")},children:s?"✓":"⧉"})]})}function Wy(e,n){return n?e.workSubtype[n]??n:""}const pp=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Fi="zhusha",Hi="bim-theme";function up(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Di(e){return up(e)?e:Fi}function Oy(){try{return Di(window.localStorage.getItem(Hi))}catch{return Fi}}function mp(e){try{window.localStorage.setItem(Hi,e)}catch{}}function gp(e){const n=Di(e);return document.documentElement.setAttribute("data-theme",n),n}function hp(){return Di(document.documentElement.getAttribute("data-theme"))}const Fy=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],Qo="airy",Ui="bim-layout";function fp(e){return e==="airy"||e==="boxed"}function Vi(e){return fp(e)?e:Qo}function Hy(){try{return Vi(window.localStorage.getItem(Ui))}catch{return Qo}}function Dy(e){try{window.localStorage.setItem(Ui,e)}catch{}}function Uy(e){const n=Vi(e);return document.documentElement.setAttribute("data-layout",n),n}function Vy(){return Vi(document.documentElement.getAttribute("data-layout"))}const Gy=`try{var t=localStorage.getItem(${JSON.stringify(Hi)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Ui)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,Yy={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},qy=({onChange:e,style:n})=>{const{t:i}=te(),[o,s]=h.useState(Fi);h.useEffect(()=>{s(hp())},[]);const a=l=>{s(gp(l)),mp(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":i("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...n},children:pp.map(l=>{const d=o===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":i(`common.theme.${l.name}`),title:i(`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:r(Yy[l.name]),boxShadow:d?`0 0 0 2px ${r("page-bg")}, 0 0 0 3.5px ${r("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.VARIANT_SUPPLEMENT=Ja.VARIANT_SUPPLEMENT;exports.Badge=vi;exports.BidUrlProvider=Op;exports.BookDetailLayout=Py;exports.BookPage=bd;exports.Breadcrumb=Rr;exports.CATALOG_ALL_ID=At;exports.CATALOG_CSS=vd;exports.CATALOG_NARROW_QUERY=Vo;exports.CATALOG_PAGE_SIZE=Go;exports.CATALOG_UNCLASSIFIED_ID=Qt;exports.CLASSIFICATIONS=Ti;exports.COMMON_TRADITIONAL_CHARS=cl;exports.CardFoot=Hn;exports.CatalogPage=xy;exports.CatalogPager=Td;exports.CatalogTree=wd;exports.CheckFilter=cc;exports.Chip=gc;exports.ChipWall=Mg;exports.CollectionCatalog=io;exports.CollectionPage=yd;exports.CreateEntityDialog=nd;exports.DEFAULT_LAYOUT=Qo;exports.DEFAULT_META_HOME_LINKS=Gd;exports.DEFAULT_READER_PREFS=oo;exports.DEFAULT_READ_HOME_LINKS=Nd;exports.DEFAULT_THEME=Fi;exports.DETAIL_CSS=pc;exports.DYNASTY_GROUPS=Ci;exports.Dash=Hg;exports.DataTable=Bg;exports.DetailFooter=vc;exports.DetailGrid=On;exports.DetailHeader=uc;exports.EMPTY_FILTERS=$i;exports.ENTITY_TEXT_CSS=Lo;exports.EmendatedBySection=Il;exports.EmptyNote=Kg;exports.EntityDetail=_l;exports.EntityMark=Mo;exports.EntityPage=jd;exports.EntityPickerDialog=rd;exports.EntitySelector=td;exports.EntityText=mf;exports.ExpandRow=Dg;exports.ExtLink=Xg;exports.FEEDBACK_FAB_OFFSET_VAR=Or;exports.FILTER_SUPPORT=fl;exports.FONT_SIZE_STEPS=Lt;exports.FactList=Rg;exports.FeedbackButton=rb;exports.FeedbackDialog=ld;exports.FeedbackForm=cd;exports.FeedbackList=Oo;exports.FeedbackTab=dd;exports.FilterChip=mc;exports.FormInput=ht;exports.FormTextArea=tn;exports.GUJI_MARKDOWN_FIELD=xg;exports.GUJI_TABLE_NOTATION=kc;exports.GlyphBadge=xo;exports.GujiInteractiveReader=Qf;exports.GujiTable=jo;exports.GujiTextViewer=Po;exports.GujiWarpCanvas=Eo;exports.HomePage=Br;exports.ImagePanel=Sr;exports.IndexApp=Jf;exports.IndexBrowser=wr;exports.IndexDetail=no;exports.IndexEditor=od;exports.IndexView=Ux;exports.IntroGrid=Ig;exports.LAYOUTS=Fy;exports.LAYOUT_STORAGE_KEY=Ui;exports.LOSS_OPTIONS=hl;exports.LocaleContext=Tt;exports.LocaleProvider=gu;exports.LocaleToggle=Ur;exports.META_HOME_CSS=Vd;exports.META_HOME_SECTION_IDS=cp;exports.MetaCatalogTable=ep;exports.MetaCollectionGroups=rp;exports.MetaDataLicense=lp;exports.MetaHomeView=Iy;exports.MetaLine=it;exports.MetaLineageCards=sp;exports.MetaOnlineSites=ap;exports.MetaPeopleTimeline=op;exports.MetaRecentPanel=Jd;exports.MetaRelatedCatalogs=np;exports.MetaTypeChips=Kd;exports.ModeIndicator=pl;exports.MoreButton=Ag;exports.MoreLink=ho;exports.PAGE_MAX_WIDTH=ui;exports.PERIOD_NARROW_SHARE=Ld;exports.PageFrame=In;exports.Quote=Vg;exports.READER_CSS=Bl;exports.READ_HOME_CSS=qo;exports.READ_HOME_NARROW_QUERY=Vn;exports.READ_HOME_SECTION_IDS=Ud;exports.READ_PERIOD_LABELS=vy;exports.RECENT_IDS_STORAGE_KEY=un;exports.ROLE_CLASS_ORDER=Jl;exports.ReadButton=Nr;exports.ReadFamousWorks=Fd;exports.ReadHomeView=wy;exports.ReadPeriodBand=Hd;exports.ReadPicks=Pd;exports.ReadPieces=Dd;exports.ReadSection=dt;exports.ReadShelf=Xo;exports.ReadSibu=Zo;exports.ReadStats=Md;exports.ReadTopicGroup=Wd;exports.ReadTopics=Od;exports.ReaderMdText=_o;exports.ReaderShell=Gl;exports.ReaderToc=Ol;exports.RelationPanel=Qc;exports.RepoSourceLink=Vr;exports.ResourceEditor=vr;exports.ResourceGroup=Gg;exports.ResourceLine=Yg;exports.ResourceList=Jr;exports.ResourceRow=yc;exports.SEARCH_VIEW_STORAGE_KEY=Qr;exports.SEVEN_PAVILIONS_KEY=ip;exports.SNIPPET_MARK_END=tl;exports.SNIPPET_MARK_START=el;exports.SORTABLE_TYPES=gl;exports.SearchInput=ml;exports.SearchResults=kl;exports.Sec=ot;exports.Section=kt;exports.SectionHead=Eg;exports.SideList=en;exports.SmartBidInput=gi;exports.SourceEditor=Xc;exports.StripWarpRenderer=Ar;exports.SummaryCard=Fn;exports.THEMES=pp;exports.THEME_INIT_SCRIPT=Gy;exports.THEME_STORAGE_KEY=Hi;exports.TRADITIONAL_ALLOWLIST=dl;exports.TabFilter=Li;exports.TableHead=Wg;exports.TableRow=Og;exports.TagRow=jc;exports.TagRows=qg;exports.TextButton=Lg;exports.TextReader=Wo;exports.ThemeToggle=qy;exports.TopStrip=Ir;exports.VersionLineageGraph=xd;exports.VersionLineageList=fd;exports.VersionLineageView=Uo;exports.VolumeChips=Pg;exports.VolumeLinks=bo;exports.WorkCard=$d;exports.WorkCardGrid=zd;exports.WorkCatalog=cx;exports.WorkPage=gd;exports.WorkRow=Cd;exports.adaptCharCord=lx;exports.adaptEntityJson=Lc;exports.adaptPunctJson=tx;exports.applyLayout=Uy;exports.applyTheme=gp;exports.authorsLine=Oi;exports.bookIndexUriToId=Lr;exports.bookMarkingOf=wo;exports.bucketResources=lo;exports.buildCatalogTree=ly;exports.buildCollectionTable=tc;exports.buildLineageGraph=hi;exports.buildMeiliFilter=Ru;exports.buildPageUrl=Xr;exports.buildParagraphBlocks=zc;exports.buildVersionRow=Xl;exports.buildVersionTable=Zl;exports.canParagraphize=yi;exports.catalogNodeIdOf=sy;exports.catalogNodeIdsOf=ay;exports.catalogPageCount=uy;exports.catalogTotal=Yo;exports.classificationPath=Un;exports.clearAllRecentIds=eo;exports.compareCatalogCards=py;exports.computeVersionPartition=dg;exports.countActiveFilters=zi;exports.createTextApi=El;exports.currentLayout=Vy;exports.currentTheme=hp;exports.defaultEntityHref=Dc;exports.defaultWorkLink=Sd;exports.deriveDating=ag;exports.deriveEditionType=ic;exports.deriveEra=Wn;exports.deriveYear=Ii;exports.deriveYearRange=ao;exports.detailToEditor=ad;exports.detectGenre=Mi;exports.displayAuthorRole=po;exports.editorToDetail=Dx;exports.eraRank=Tr;exports.filtersFromParams=Eu;exports.filtersToParams=fi;exports.findCatalogPath=pn;exports.findTraditionalChars=xu;exports.firstAuthorText=Ko;exports.flattenTitles=Er;exports.flattenToc=Vl;exports.fmtCount=Ke;exports.formatHitCount=di;exports.formatTemplate=ft;exports.formatVolumeRange=Ei;exports.getDisplayNameFromUrl=fn;exports.getMessages=bn;exports.getStartPage=Kr;exports.getT=yn;exports.getTypeGroupKey=Yr;exports.groupRelatedWorks=lg;exports.gujiInlineToPlain=ac;exports.hasActiveFilters=xl;exports.hasGujiMarkdownV02=bg;exports.hasGujiTableNotation=Zg;exports.hasSearchOptions=zu;exports.iiifVolumeOf=nx;exports.isCountedChar=$o;exports.isLayoutName=fp;exports.isThemeName=up;exports.lineageHref=Yd;exports.loadRecentIds=Dt;exports.measureText=Wt;exports.mergeVolumeResources=qr;exports.normalizeEra=nt;exports.normalizeLayout=Vi;exports.normalizeRole=co;exports.normalizeTheme=Di;exports.normalizeVolumeIndex=Ln;exports.normalizeVolumes=rl;exports.numberToChinese=nc;exports.paginationItems=kd;exports.parseChineseNumber=xi;exports.parseGujiInline=sc;exports.parseGujiTable=Sc;exports.parseSourceString=Zc;exports.pct=Jo;exports.periodLevel=Ed;exports.pickReaderVersion=Ul;exports.readStoredLayout=Hy;exports.readStoredTheme=Oy;exports.readerVersionOptionLabel=$r;exports.remapPlainOffsets=Ac;exports.removeRecentId=wl;exports.renderFullTextBody=ah;exports.renderProperNames=Rc;exports.renderReaderInline=So;exports.resolveRecentEntry=to;exports.resourceHref=xn;exports.resourceNote=Ri;exports.resultTabFromParam=Du;exports.resultTabToParam=Uu;exports.roleFacets=Ql;exports.rowNo=Fg;exports.sameFilters=Lu;exports.saveRecentId=kr;exports.segmentEntities=Mc;exports.shelfColumns=Id;exports.sortFor=Nu;exports.sortYear=bi;exports.spineHeight=Rd;exports.splitFullTextTables=yo;exports.splitHighlightSnippet=Gr;exports.splitTableRow=wc;exports.storeLayout=Dy;exports.storeTheme=mp;exports.stringifySources=Jc;exports.summaryFromEntry=Fc;exports.summaryFromItem=Oc;exports.timelineLayout=qd;exports.toCatalogWorkCard=dy;exports.transportSummaryLoader=Hc;exports.typeSupportsFilters=bl;exports.useBidUrl=tt;exports.useChapterWarpData=Gc;exports.useConvert=Me;exports.useEntitySummaryLoader=Ao;exports.useI18n=te;exports.useReaderPrefs=Dl;exports.useRecentEntries=Xd;exports.useT=Ie;exports.validateLineageGraph=Cb;exports.volumeStats=wi;exports.withDefaultLinks=Ut;exports.withMetaLinks=Vt;exports.yearText=ki;
1913
+ `,Gd={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function Vt(e){return{...Gd,...e??{}}}function Yd(e,n){if(e.lineage)return e.lineage(n);const i=e.item(n),o=i.indexOf("#"),[s,a]=o<0?[i,""]:[i.slice(0,o),i.slice(o)];return`${s}${s.includes("?")?"&":"?"}tab=lineage${a}`}function Jo(e,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(e/n*100)))}function qd(e){const n=e.filter(p=>Number.isFinite(p.birth_year)||Number.isFinite(p.death_year)),i=e.filter(p=>!n.includes(p));if(!n.length)return{min:0,max:0,placed:[],missing:i};const o=p=>{const m=Number.isFinite(p.birth_year)?p.birth_year:p.death_year-50,u=Number.isFinite(p.death_year)?p.death_year:p.birth_year+50;return[Math.min(m,u),Math.max(m,u)]},s=n.map(o),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,m)=>({p,from:s[m][0],to:s[m][1]})).sort((p,m)=>p.from-m.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:i}}function ki(e,n=yn("zh-Hant")){return e<0?n("metaHome.yearBC",{n:-e}):String(e)}function $y(e){return{read:e.item,work:e.item,node:e.node}}function Kd({counts:e,links:n}){const{t:i}=te(),o=n==null?void 0:n.type;if(!o)return null;const s=[["all",i("metaHome.typeAll"),null],["work",i("metaHome.typeLabel.work"),e.works],["book",i("metaHome.typeLabel.book"),e.books],["collection",i("metaHome.typeLabel.collection"),e.collections],["entity",i("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":i("metaHome.typeChipsLabel"),children:s.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:o(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:Ke(d)})]})},a))})}function Xd(e,n=5){const[i,o]=h.useState(null);h.useEffect(()=>{let a=!1;const l=Dt().slice(0,n);if(!l.length||!e){o([]);return}return Promise.all(l.map(d=>to(e,d))).then(d=>{a||o(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,n]);const s=h.useCallback(()=>{eo(),o([])},[]);return{entries:i,clear:s}}function Cy(e,n,i){const o=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return o?i(o):Zd(e.type,n)}function Zd(e,n){return n(`metaHome.typeLabel.${e}`)}function Jd({entries:e,onClear:n,links:i}){const{t:o,convert:s}=te(),a=Vt(i);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:o("metaHome.recentTitle")}),e&&e.length>0&&n&&t.jsx("button",{type:"button",onClick:n,children:o("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":o("metaHome.recentItemLabel",{type:l.type?Zd(l.type,o):"",title:s(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?o(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:s(l.title)}),t.jsx("small",{"aria-hidden":"true",children:Cy(l,o,s)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:o("metaHome.recentEmpty")})]})}function Qd(e,n,i,o=!1){return o&&(e==="done"||e==="in_progress")?n(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?n(`metaHome.status.${e}`):i(e)}function ep({rows:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":i("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[i("metaHome.catalogTitle"),t.jsx("small",{children:i("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:i("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:i("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:i("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:i("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:i("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=Jo(a.imported,a.total),d=a.work_id??a.collection_id,c=o(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:Ke(a.total)}),t.jsx("td",{className:"bim-mh-r",children:Ke(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:Qd(a.status,i,o)})})]},a.id||a.name)})})]})}):null}function tp({items:e,links:n,label:i}){const{convert:o}=te();return t.jsx("ul",{className:"bim-rh-rows","aria-label":i?o(i):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:o(s.title)}),s.sub&&t.jsx("small",{children:o(s.sub)})]})},s.id))})}function np({works:e,links:n}){const{t:i}=te(),[o,s]=h.useState(!1);if(!e.length)return null;const a=Bn(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[i("metaHome.relatedTitle"),t.jsx("small",{children:i("metaHome.relatedNote")})]}),t.jsx(tp,{items:e.map(l=>({id:l.id,title:l.title,sub:Oi(l)||void 0})),links:Vt(n)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>s(l=>!l),children:o?i("action.collapse"):i("metaHome.allNWorks",{n:e.length})})]})}const ip="siku_qige";function Ty({group:e,links:n}){const{t:i,convert:o}=te(),[s,a]=h.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Bn(e.items.length)?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[o(e.label),t.jsx("small",{className:"bim-rh-num",children:i("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(tp,{items:e.items,links:n,label:e.label}),Bn(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>a(l=>!l),children:s?i("action.collapse"):i("metaHome.allNKinds",{n:e.items.length})})]})}function rp({groups:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);if(!e.length)return null;const a=e.find(c=>c.key===ip),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:[o(a.label),t.jsx("small",{children:o(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":o(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:s.item(c.id),"aria-label":o(c.title),title:o(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:o(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:i("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(Ty,{group:c,links:s},c.key))})]})}const qa=34,Ka=13;function Xa(e,n){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?ki(e.birth_year,n):"?"}–${e.death_year!=null?ki(e.death_year,n):"?"}`}function zy(e,n){const i=n-e,o=i>1200?300:i>400?100:50,s=[];for(let a=Math.ceil(e/o)*o;a<=n;a+=o)s.push(a);return s}function op({people:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=qd(e),p=[],m=d.map(g=>{const f=g.left>70,x=f?Math.min(g.left,g.left+g.width-Ka):g.left;let v=0;for(;p[v]!=null&&p[v]>x;)v++;return p[v]=f?g.left+g.width:g.left+Math.max(g.width,Ka),{...g,lane:v,end:f}}),u=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[m.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:p.length*qa+10},children:m.map(g=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":g.end?"":void 0,style:{left:`${g.left}%`,top:g.lane*qa+4,width:`${Math.max(g.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:s.item(g.p.id),children:[o(g.p.name),t.jsx("small",{className:"bim-rh-num",children:Xa(g.p,i)})]})]},g.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:zy(a,l).map(g=>t.jsx("span",{style:{left:`${(g-a)/u*100}%`},children:ki(g,i)},g))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":m.length?void 0:"",children:(m.length?e:c).map(g=>t.jsx("li",{children:t.jsxs("a",{href:s.item(g.id),children:[t.jsx("span",{children:o(g.name)}),t.jsx("small",{className:"bim-rh-num",children:[g.dynasty?o(g.dynasty):"",Xa(g,i)].filter(Boolean).join(" ")})]})},g.id))}),c.length>0&&m.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:i("metaHome.missingLife",{names:o(c.map(g=>g.name).join("、"))})})]})}const Ny=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 sp({works:e,links:n}){const{t:i,convert:o}=te(),s=Vt(n);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=Oi(a);return t.jsx("li",{children:t.jsxs("a",{href:Yd(s,a.id),children:[Ny,t.jsx("b",{children:o(a.title)}),l&&t.jsx("small",{children:o(l)}),t.jsx("span",{children:i("metaHome.viewLineage")})]})},a.id)})}):null}function ap({sites:e}){const{t:n,convert:i}=te(),o=e.filter(a=>a.status!=="todo"&&a.total>0),s=e.filter(a=>!o.includes(a));return e.length?t.jsxs(t.Fragment,{children:[o.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:o.map(a=>{const l=Jo(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:i(a.name)}):t.jsx("span",{children:i(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${Ke(a.imported)} / ${Ke(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:Qd(a.status,n,i,!0)})]})]},a.id||a.name)})}),s.length>0&&t.jsx("p",{className:"bim-mh-todo",children:n("metaHome.plannedSites",{names:i(s.map(a=>a.name).join("、"))})})]}):null}const Za=["extant","partially_extant","lost","unknown"];function lp({stats:e,links:n,version:i,repoUrl:o,downloadHref:s}){const{t:a}=te(),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=Za.some(p=>{var m;return(((m=e.loss)==null?void 0:m[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,m])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:Ke(p)}),t.jsx("span",{children:m})]},m))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:Za.map(p=>{var g;const m=((g=e.loss)==null?void 0:g[p])??0,u=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&&m>0?a("metaHome.lossCount",{n:Ke(m),note:u}):u})]})},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"),o?t.jsx("a",{href:o,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),i&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:i})]}),s&&t.jsx("p",{children:t.jsx("a",{href:s,children:a("metaHome.download")})})]})]})}const cp={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function Iy({sections:e,links:n,head:i,transport:o,catalogHref:s,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:p,className:m}){var k,C;const{t:u}=te(),g=e,f=Vt(n),x=$y(f),v=cp,y=Xd(o),_={zhi:!!((k=g.shelf)!=null&&k.items.length)||g.catalog_progress.length>0||g.related_catalogs.length>0,sibu:g.bu.length>0||g.unclassified>0,cong:g.collection_groups.length>0,people:g.bibliographers.length>0,lineage:g.lineage.length>0,sites:g.sites.length>0,data:!0},b=Object.keys(v).filter($=>_[$]),w=$=>u(`metaHome.nav.${$}`),j=($,S)=>$?t.jsx("a",{className:"bim-rh-more",href:$,children:S}):void 0;return t.jsxs("div",{className:m?`bim-rh bim-mh ${m}`:"bim-rh bim-mh",children:[t.jsx("style",{children:qo+Vd}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[i,t.jsx(Kd,{counts:g.counts,links:n})]}),o&&t.jsx(Jd,{entries:y.entries,onClear:y.clear,links:n})]}),b.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":u("metaHome.navLabel"),children:t.jsx("ul",{children:b.map($=>t.jsx("li",{children:t.jsx("a",{href:`#${v[$]}`,children:w($)})},$))})}),t.jsxs("div",{className:"bim-rh-main",children:[_.zhi&&t.jsxs(dt,{id:v.zhi,title:w("zhi"),sub:u("metaHome.zhiSub"),children:[g.shelf&&g.shelf.items.length>0&&t.jsx(Xo,{topic:{key:"shelf",label:g.shelf.label,shelf:!0,items:g.shelf.items},links:x,showTitle:!1,legendCount:g.shelf.items.some($=>$.records)?u("metaHome.shelfLegendCount"):null,legendExtra:[u("metaHome.shelfLegendClick")]}),(g.catalog_progress.length>0||g.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(C=g.shelf)!=null&&C.items.length?void 0:{marginTop:0},children:[t.jsx(ep,{rows:g.catalog_progress,links:n}),t.jsx(np,{works:g.related_catalogs,links:n})]})]}),_.sibu&&t.jsx(dt,{id:v.sibu,title:w("sibu"),sub:u("metaHome.sibuSub"),more:j(s,u("metaHome.toCatalog")),children:t.jsx(Zo,{bu:g.bu,unclassified:g.unclassified,links:x,unclassifiedNote:u("metaHome.unclassifiedNote")})}),_.cong&&t.jsx(dt,{id:v.cong,title:w("cong"),sub:u("metaHome.congSub"),more:j(a,u("metaHome.allNKindsMore",{n:Ke(g.counts.collections)})),children:t.jsx(rp,{groups:g.collection_groups,links:n})}),_.people&&t.jsx(dt,{id:v.people,title:w("people"),sub:u("metaHome.peopleSub"),more:j(l,u("metaHome.allNPeopleMore",{n:Ke(g.counts.entities)})),children:t.jsx(op,{people:g.bibliographers,links:n})}),_.lineage&&t.jsx(dt,{id:v.lineage,title:w("lineage"),sub:u("metaHome.lineageSub"),children:t.jsx(sp,{works:g.lineage,links:n})}),_.sites&&t.jsx(dt,{id:v.sites,title:w("sites"),sub:u("metaHome.sitesSub"),children:t.jsx(ap,{sites:g.sites})}),t.jsx(dt,{id:v.data,title:w("data"),sub:u("metaHome.dataSub"),children:t.jsx(lp,{stats:g.stats,links:n,version:d,repoUrl:c,downloadHref:p})})]})]})}const dp=["_related","_catalogs","_collections","_members","_children"],Ry=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Dr=e=>Ry(e)&&!!e.h;function Ey(e){return e?dp.some(n=>{const i=e[n];return Array.isArray(i)&&i.some(Dr)}):!1}function Ly(e,n){const i={...e};if(!n)return i;for(const o of dp){const s=e[o];!Array.isArray(s)||!s.some(Dr)||(i[o]=s.map(a=>{var c;if(!Dr(a)||typeof a.title=="string"&&a.title)return a;const l=a.id??a.bid,d=l?(c=n[l])==null?void 0:c.title:void 0;return d?{...a,title:d}:a}))}return i}function Ay(e){let n=null;const i=()=>e.getHubs?(n??(n=e.getHubs().catch(()=>null)),n):Promise.resolve(null);return new Proxy(e,{get(o,s){if(s==="getItem")return async l=>{const d=await o.getItem(l);return d&&Ly(d,Ey(d)?await i():null)};const a=Reflect.get(o,s,o);return typeof a=="function"?a.bind(o):a}})}const Ur=({style:e})=>{const n=h.useContext(Tt),{t:i}=te();if(!n)return null;const{locale:o,setLocale:s}=n,a=o==="zh-Hant",l=()=>s(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:i(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 ${r("border")}`,borderRadius:"4px",background:r("bg"),color:r("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?r("primary"):void 0,fontWeight:a?700:400},children:i("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:r("primary"),fontWeight:a?400:700},children:i("common.localeShortHans")})]})},Vr=({href:e,label:n,size:i=16,className:o,style:s})=>{const{t:a}=te(),l=n??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:r("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:d=>{d.currentTarget.style.color=r("fg")},onMouseLeave:d=>{d.currentTarget.style.color=r("desc-fg")},children:t.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})})};function yr(e){const n=e.text_count;return typeof n=="number"&&n>0}function jr(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function My(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const Py=({id:e,transport:n,initialDetail:i,initialEntry:o,activeTab:s,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:p,lineageCollection:m,onLineageCollectionChange:u,initialPage:g=1,selectedLineageNodeId:f,onNavigate:x,onBack:v,backLabel:y,renderLink:_,enrichDetail:b,getSourceLink:w,readLink:j,railTop:k,extraTabs:C=[],showFeedbackTab:$=!0,feedbackApiUrl:S,height:M,footerExtra:z,hideHeaderControls:T=!1,className:P,style:R})=>{const N=h.useMemo(()=>Ay(n),[n]),A=Ie(),{t:H,convert:G}=te(),[ie]=h.useState(()=>{if(!My(e,i))return null;const Q={...i},ke=o??jr(e,Q);return b&&b(ke,Q),{id:e,entry:ke,detail:Q}}),[le,V]=h.useState((ie==null?void 0:ie.entry)??null),[F,xe]=h.useState((ie==null?void 0:ie.detail)??null),[ee,L]=h.useState(!ie),[Re,ce]=h.useState(!1),[me,se]=h.useState([]),[Pe,X]=h.useState(!1),[re,de]=h.useState(null),[D,K]=h.useState(null),[we,ne]=h.useState(null),[B,Z]=h.useState(!1),ae=h.useRef(null),je=h.useRef(0),[Y,be]=h.useState(null),Ee=l!==void 0?l:Y,Fe=h.useCallback(Q=>{d?d(Q):be(Q)},[d]),W=h.useCallback(async Q=>{if(!N.getCollectionCatalogs&&!N.getCollectionCatalog){se([]);return}X(!0);try{if(N.getCollectionCatalogs)se(await N.getCollectionCatalogs(Q)||[]);else if(N.getCollectionCatalog){const ke=await N.getCollectionCatalog(Q);se(ke?[{resource_id:"",data:ke}]:[])}}catch{se([])}finally{X(!1)}},[N]),J=h.useCallback(async Q=>{var ke,Ae;if(!N.getTextManifest||!N.getTextIndex){de(null),K(Q);return}try{const Be=_e.pickTextVersion(await N.getTextManifest(Q)),Ne=Be?await N.getTextIndex(Q,Be.key):null;de(Ne&&Ne.chapters.length>0?{chapters:Ne.chapters.map(he=>({n:he.n,title:he.title,file:he.file})),source:{name:((ke=Ne.source)==null?void 0:ke.name)??(Be==null?void 0:Be.source_name),license:((Ae=Ne.source)==null?void 0:Ae.license)??(Be==null?void 0:Be.license)??void 0}}:null)}catch{de(null)}finally{K(Q)}},[N]),$e=h.useCallback(async(Q,ke)=>{const Ae=++je.current,Be=()=>Ae!==je.current;Z(!0);try{if(N.getLineageGraph){const jt=await N.getLineageGraph(Q);if(Be())return;jt&&ne(jt)}const Ne=ke.version_graph;if(!Ne||!Ne.enabled){we||ne(null),ae.current=null;return}const he=uo(ke),Ue=(await Bi(he,Pi,async jt=>{try{return await N.getItem(jt)}catch{return null}},Be)).filter(Boolean);if(Be())return;ae.current={work:ke,books:Ue};const We=m??Ne.default_collection??(Ne.core_books&&Ne.core_books.length>0?"core":"all"),st=We==="core"&&Array.isArray(Ne.core_books)&&Ne.core_books.length>0?"core":We??"all";ne(hi(ke,Ue,st))}catch{if(Be())return;ne(null),ae.current=null}finally{Be()||Z(!1)}},[N]),Te=h.useRef({initialDetail:i,initialEntry:o});Te.current={initialDetail:i,initialEntry:o},h.useEffect(()=>{let Q=!1;je.current++,Z(!1);const ke=he=>{he.type==="collection"?W(e):he.type==="work"?(he.version_graph||N.getLineageGraph)&&$e(e,he):he.type==="book"&&yr(he)&&J(e)},Ae=Te.current;let Be=null;if(ie&&ie.id===e)Be=ie;else if(Ae.initialDetail&&Ae.initialDetail.id===e){const he={...Ae.initialDetail},ve=Ae.initialEntry??jr(e,he);b&&b(ve,he),Be={entry:ve,detail:he}}return Be?(ce(!1),se(he=>he.length?[]:he),de(null),ne(null),ae.current=null,V(Be.entry),xe(Be.detail),L(!1),ke(Be.detail),()=>{Q=!0}):((async()=>{L(!0),ce(!1),V(null),xe(null),se([]),de(null),ne(null),ae.current=null;try{const he=await N.getItem(e);if(Q)return;if(!he){ce(!0);return}const ve=he;let Ue=null;if(N.getEntry&&(Ue=await N.getEntry(e),Q))return;Ue||(Ue=jr(e,ve)),b&&b(Ue,ve),V(Ue),xe(ve),ke(ve)}catch{Q||ce(!0)}finally{Q||L(!1)}})(),()=>{Q=!0})},[e,N,ie,b,W,$e,J]),h.useEffect(()=>{const Q=ae.current;!Q||!m||ne(hi(Q.work,Q.books,m))},[m]);const O=[];if(F){if(O.push({key:"basic",label:A.detailTab.basicInfo}),F.type==="collection"){Pe&&me.length===0&&O.push({key:"catalog:loading",label:`${A.detailTab.catalog}…`});for(const Q of me)O.push({key:`catalog:${Q.resource_id}`,label:Q.short_name?`${G(Q.short_name)}${A.detailTab.catalogSuffix}`:A.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&O.push({key:s,label:A.detailTab.fullText}),F.type==="work"&&(we||B)&&O.push({key:"lineage",label:B?`${A.detailTab.lineage}…`:A.detailTab.lineage});for(const Q of C)(Q.position??"before-feedback")==="before-feedback"&&Q.shouldShow(F)&&O.push({key:Q.key,label:Q.label});$&&s==="feedback"&&O.push({key:"feedback",label:A.detailTab.feedback});for(const Q of C)Q.position==="after-feedback"&&Q.shouldShow(F)&&O.push({key:Q.key,label:Q.label})}h.useEffect(()=>{if(s!=="emendated"||!F)return;a("basic");const Q=setTimeout(()=>{var ke;(ke=document.getElementById("studies"))==null||ke.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(Q)},[s,F,a]);const fe=le&&F&&w?w({activeTab:s,activeJuan:Ee,entry:le,detail:F}):null,oe=h.useMemo(()=>{var Ne;if(!F)return null;const ke=(F.authors??[]).map(he=>{const ve=po(he.role);return`${he.dynasty?`〔${G(he.dynasty)}〕`:""}${G(he.name)}${ve?` ${G(ve)}`:""}`}).join(" · ");let Ae=!1;try{Ae=_e.extractStatus(F.id)==="draft"}catch{}if(F.type==="book"){const he=F;return{title:G(he.title),subtitle:he.edition?G(he.edition):ke||void 0,aside:[Ae?A.status.draft:"",ke&&he.edition?ke:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(F.type==="collection"){const he=F;return{title:G(he.title),subtitle:G(Bt(he,A.unit.juan))||void 0,aside:[(Ne=he.publication_info)==null?void 0:Ne.year,Ae?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ke||void 0}}if(F.type==="entity"){const he=F,ve=We=>We==null?"":We<0?H("detail.bce",{n:-We}):String(We),Ue=he.birth_year!=null||he.death_year!=null?`${ve(he.birth_year)||"?"}—${ve(he.death_year)||"?"}`:"";return{title:G(he.primary_name||he.title),subtitle:[he.dynasty?`〔${G(he.dynasty)}〕`:"",Ue].filter(Boolean).join(" ")||void 0,aside:Ae?A.status.draft:void 0,secondLine:void 0}}const Be=G(Bt(F,A.unit.juan));return{title:G(F.title),subtitle:[Be,ke].filter(Boolean).join(" · ")||void 0,aside:[Wy(A,F.subtype),Ae?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[F,G,A,H]),Se=F&&yr(F)?"text":null,Le=()=>{Fe(null),a("fulltext")};let He=null;if(F&&j){const Q=j({detail:F,kind:Se});Q&&(He=t.jsx(Nr,{href:Q}))}else Se&&(He=t.jsx(Nr,{onClick:Le}));const Ye=Q=>{if(!F)return null;const ke=Q.replace(/\.[^.]+$/,"");if(j){const Ae=j({detail:F,kind:Se,juan:ke});return Ae?{href:Ae}:null}return{onClick:()=>{Fe(ke),a("fulltext")}}},qe=new Set(C.map(Q=>Q.key)),Xe=O.filter(Q=>Q.key.startsWith("catalog:")&&Q.key!=="catalog:loading"||Q.key==="lineage"&&!!we&&!B||qe.has(Q.key)).map(Q=>({key:Q.key,label:Q.label,onClick:()=>a(Q.key)})),I=()=>{var Q;return F?F.type==="work"?t.jsx(gd,{data:F,transport:N,onNavigate:x,renderLink:_,readAction:He,railTop:k,railLinks:Xe}):F.type==="book"?t.jsx(bd,{data:F,transport:N,onNavigate:x,renderLink:_,readAction:He,fullText:re,fullTextPending:yr(F)&&!!N.getTextManifest&&D!==F.id,chapterLink:Ye,railTop:k,railLinks:Xe}):F.type==="collection"?t.jsx(yd,{data:F,catalog:(Q=me[0])==null?void 0:Q.data,transport:N,onNavigate:x,renderLink:_,readAction:He,railTop:k,railLinks:Xe,catalogAction:me.length>0?t.jsxs("a",{href:"#catalog",onClick:ke=>{ke.preventDefault(),a(`catalog:${me[0].resource_id}`)},children:[G(A.detailTab.collectionCatalog)," →"]}):null}):t.jsx(jd,{data:F,transport:N,onNavigate:x,renderLink:_,railTop:k,railLinks:Xe}):null},U=()=>{var ke,Ae,Be;if(!le||!F)return null;if(s==="basic"||s==="emendated")return I();if(typeof s=="string"&&s.startsWith("catalog:")){const Ne=(ke=me.find(he=>`catalog:${he.resource_id}`===s))==null?void 0:ke.data;return t.jsx(io,{data:Ne,onNavigate:x,renderLink:_})}if(s==="collated"||s==="fulltext")return t.jsx(Wo,{id:e,transport:N,chapter:Ee,onLocationChange:Ne=>Fe(Ne.chapter),onNavigate:x});if(s==="lineage"){if(!we)return t.jsx("div",{style:{color:r("label-fg"),padding:"24px 0"},children:H(B?"detail.loading":"detail.noLineageGraph")});const Ne=F.type==="work"?F:null;return t.jsx(Uo,{graph:we,renderLink:_,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:p,selectedNodeId:f,collection:m??((Ae=Ne==null?void 0:Ne.version_graph)==null?void 0:Ae.default_collection),onCollectionChange:u,collectionsAvailable:(Be=Ne==null?void 0:Ne.version_graph)==null?void 0:Be.collections,collectionCounts:(()=>{var We,st,jt,on,Gt,q,Ve;if(!Ne)return;const he={},ve=((We=ae.current)==null?void 0:We.books)??[];he.all=(((st=Ne._books)==null?void 0:st.length)??0)-(((on=(jt=Ne.version_graph)==null?void 0:jt.excluded_books)==null?void 0:on.length)??0);const Ue=(Gt=Ne.version_graph)==null?void 0:Gt.collections;if(Ue)for(const Oe of Object.keys(Ue))he[Oe]=hi(Ne,ve,Oe).nodes.filter(rt=>rt.kind==="book"&&!rt.bridge).length;return he.core==null&&((Ve=(q=Ne.version_graph)==null?void 0:q.core_books)!=null&&Ve.length)&&(he.core=Ne.version_graph.core_books.length),he})()})}if(s==="feedback"&&$)return t.jsx(dd,{resourceId:e,apiUrl:S});const Q=C.find(Ne=>Ne.key===s);return Q?Q.render({detail:F,entry:le,transport:N,onNavigate:x}):null};if(ee)return t.jsx(In,{style:{minHeight:M,...R},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((Q,ke)=>t.jsx("div",{style:{height:ke===1?40:16,width:Q,opacity:.35,background:r("rule")}},ke))})});if(Re||!F||!le||!oe)return t.jsx(In,{style:{minHeight:M,...R},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r("label-fg"),fontSize:14},children:H("detail.notFound")})});const ue=s==="basic"||s==="emendated",Ce=[{label:y??A.detailTab.backToIndex,onClick:v}];if(F.type==="book"&&F.work_id){const Q=F.work_id;Ce.push({label:A.indexType.work,id:Q,onClick:()=>x==null?void 0:x(Q)})}Ce.push({label:A.indexType[F.type]});const ye=s==="collated"||s==="fulltext",ge=typeof z=="string"?A.status[z.trim()]??z:z,Ge=t.jsx(vc,{left:t.jsxs(t.Fragment,{children:[ge,ge?" · ":"",t.jsx(By,{id:F.id,label:A.label.id,copied:A.action.copied,copyLabel:A.action.copy})]}),right:t.jsxs(t.Fragment,{children:[$&&!ue&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r("meta-fg")},children:A.detailTab.submitVersion}),fe&&t.jsx("a",{href:fe.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r("meta-fg")},children:A.detailTab.dataLicense})]})});return ue?t.jsx("div",{className:P,children:t.jsxs(In,{grid:!0,style:{minHeight:M,...R},children:[t.jsx(Ir,{breadcrumb:t.jsx(Rr,{items:Ce}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Ur,{style:{border:"none",background:"transparent"}}),!T&&fe&&t.jsx(Vr,{...fe})]})}),I(),Ge]})}):t.jsx("div",{className:P,children:t.jsxs(In,{wide:ye,style:{minHeight:M,...R},children:[t.jsx(Ir,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(xo,{char:"籍"}),t.jsx(Rr,{items:Ce})]}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Ur,{}),$&&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:r("meta-fg")},children:A.detailTab.feedback}),!T&&fe&&t.jsx(Vr,{...fe})]})}),t.jsx(uc,{...oe,aside:ye?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:r("accent"),borderBottom:`1px solid ${r("rule")}`},children:[H("detail.workInfo")," →"]}):oe.aside}),!ye&&O.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:O.map(Q=>t.jsx(mc,{label:Q.label,active:Q.key===s||ue&&Q.key==="basic",onClick:()=>a(Q.key)},Q.key))}),t.jsx("div",{style:{marginTop:!ye&&O.length>1?8:0},children:U()}),Ge]})})};function By({id:e,label:n,copied:i,copyLabel:o}){const[s,a]=h.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?i:o,"aria-label":s?i:o,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:r("aux-fg")},children:s?"✓":"⧉"})]})}function Wy(e,n){return n?e.workSubtype[n]??n:""}const pp=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Fi="zhusha",Hi="bim-theme";function up(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Di(e){return up(e)?e:Fi}function Oy(){try{return Di(window.localStorage.getItem(Hi))}catch{return Fi}}function mp(e){try{window.localStorage.setItem(Hi,e)}catch{}}function gp(e){const n=Di(e);return document.documentElement.setAttribute("data-theme",n),n}function hp(){return Di(document.documentElement.getAttribute("data-theme"))}const Fy=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],Qo="airy",Ui="bim-layout";function fp(e){return e==="airy"||e==="boxed"}function Vi(e){return fp(e)?e:Qo}function Hy(){try{return Vi(window.localStorage.getItem(Ui))}catch{return Qo}}function Dy(e){try{window.localStorage.setItem(Ui,e)}catch{}}function Uy(e){const n=Vi(e);return document.documentElement.setAttribute("data-layout",n),n}function Vy(){return Vi(document.documentElement.getAttribute("data-layout"))}const Gy=`try{var t=localStorage.getItem(${JSON.stringify(Hi)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Ui)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,Yy={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},qy=({onChange:e,style:n})=>{const{t:i}=te(),[o,s]=h.useState(Fi);h.useEffect(()=>{s(hp())},[]);const a=l=>{s(gp(l)),mp(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":i("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...n},children:pp.map(l=>{const d=o===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":i(`common.theme.${l.name}`),title:i(`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:r(Yy[l.name]),boxShadow:d?`0 0 0 2px ${r("page-bg")}, 0 0 0 3.5px ${r("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.VARIANT_SUPPLEMENT=Ja.VARIANT_SUPPLEMENT;exports.Badge=vi;exports.BidUrlProvider=Op;exports.BookDetailLayout=Py;exports.BookPage=bd;exports.Breadcrumb=Rr;exports.CATALOG_ALL_ID=Lt;exports.CATALOG_CSS=vd;exports.CATALOG_NARROW_QUERY=Vo;exports.CATALOG_PAGE_SIZE=Go;exports.CATALOG_UNCLASSIFIED_ID=Qt;exports.CLASSIFICATIONS=Ti;exports.COMMON_TRADITIONAL_CHARS=cl;exports.CardFoot=Hn;exports.CatalogPage=xy;exports.CatalogPager=Td;exports.CatalogTree=wd;exports.CheckFilter=cc;exports.Chip=gc;exports.ChipWall=Mg;exports.CollectionCatalog=io;exports.CollectionPage=yd;exports.CreateEntityDialog=nd;exports.DEFAULT_LAYOUT=Qo;exports.DEFAULT_META_HOME_LINKS=Gd;exports.DEFAULT_READER_PREFS=oo;exports.DEFAULT_READ_HOME_LINKS=Nd;exports.DEFAULT_THEME=Fi;exports.DETAIL_CSS=pc;exports.DYNASTY_GROUPS=Ci;exports.Dash=Hg;exports.DataTable=Bg;exports.DetailFooter=vc;exports.DetailGrid=On;exports.DetailHeader=uc;exports.EMPTY_FILTERS=$i;exports.ENTITY_TEXT_CSS=Lo;exports.EmendatedBySection=Il;exports.EmptyNote=Kg;exports.EntityDetail=_l;exports.EntityMark=Mo;exports.EntityPage=jd;exports.EntityPickerDialog=rd;exports.EntitySelector=td;exports.EntityText=mf;exports.ExpandRow=Dg;exports.ExtLink=Xg;exports.FEEDBACK_FAB_OFFSET_VAR=Or;exports.FILTER_SUPPORT=fl;exports.FONT_SIZE_STEPS=Et;exports.FactList=Rg;exports.FeedbackButton=rb;exports.FeedbackDialog=ld;exports.FeedbackForm=cd;exports.FeedbackList=Oo;exports.FeedbackTab=dd;exports.FilterChip=mc;exports.FormInput=ht;exports.FormTextArea=tn;exports.GUJI_MARKDOWN_FIELD=xg;exports.GUJI_TABLE_NOTATION=kc;exports.GlyphBadge=xo;exports.GujiInteractiveReader=Qf;exports.GujiTable=jo;exports.GujiTextViewer=Po;exports.GujiWarpCanvas=Eo;exports.HomePage=Br;exports.ImagePanel=Sr;exports.IndexApp=Jf;exports.IndexBrowser=wr;exports.IndexDetail=no;exports.IndexEditor=od;exports.IndexView=Ux;exports.IntroGrid=Ig;exports.LAYOUTS=Fy;exports.LAYOUT_STORAGE_KEY=Ui;exports.LOSS_OPTIONS=hl;exports.LocaleContext=Tt;exports.LocaleProvider=gu;exports.LocaleToggle=Ur;exports.META_HOME_CSS=Vd;exports.META_HOME_SECTION_IDS=cp;exports.MetaCatalogTable=ep;exports.MetaCollectionGroups=rp;exports.MetaDataLicense=lp;exports.MetaHomeView=Iy;exports.MetaLine=it;exports.MetaLineageCards=sp;exports.MetaOnlineSites=ap;exports.MetaPeopleTimeline=op;exports.MetaRecentPanel=Jd;exports.MetaRelatedCatalogs=np;exports.MetaTypeChips=Kd;exports.ModeIndicator=pl;exports.MoreButton=Ag;exports.MoreLink=ho;exports.PAGE_MAX_WIDTH=ui;exports.PERIOD_NARROW_SHARE=Ld;exports.PageFrame=In;exports.Quote=Vg;exports.READER_CSS=Bl;exports.READ_HOME_CSS=qo;exports.READ_HOME_NARROW_QUERY=Vn;exports.READ_HOME_SECTION_IDS=Ud;exports.READ_PERIOD_LABELS=vy;exports.RECENT_IDS_STORAGE_KEY=un;exports.ROLE_CLASS_ORDER=Jl;exports.ReadButton=Nr;exports.ReadFamousWorks=Fd;exports.ReadHomeView=wy;exports.ReadPeriodBand=Hd;exports.ReadPicks=Pd;exports.ReadPieces=Dd;exports.ReadSection=dt;exports.ReadShelf=Xo;exports.ReadSibu=Zo;exports.ReadStats=Md;exports.ReadTopicGroup=Wd;exports.ReadTopics=Od;exports.ReaderMdText=_o;exports.ReaderShell=Gl;exports.ReaderToc=Ol;exports.RelationPanel=Qc;exports.RepoSourceLink=Vr;exports.ResourceEditor=vr;exports.ResourceGroup=Gg;exports.ResourceLine=Yg;exports.ResourceList=Jr;exports.ResourceRow=yc;exports.SEARCH_VIEW_STORAGE_KEY=Qr;exports.SEVEN_PAVILIONS_KEY=ip;exports.SNIPPET_MARK_END=tl;exports.SNIPPET_MARK_START=el;exports.SORTABLE_TYPES=gl;exports.SearchInput=ml;exports.SearchResults=kl;exports.Sec=ot;exports.Section=kt;exports.SectionHead=Eg;exports.SideList=en;exports.SmartBidInput=gi;exports.SourceEditor=Xc;exports.StripWarpRenderer=Ar;exports.SummaryCard=Fn;exports.THEMES=pp;exports.THEME_INIT_SCRIPT=Gy;exports.THEME_STORAGE_KEY=Hi;exports.TRADITIONAL_ALLOWLIST=dl;exports.TabFilter=Li;exports.TableHead=Wg;exports.TableRow=Og;exports.TagRow=jc;exports.TagRows=qg;exports.TextButton=Lg;exports.TextReader=Wo;exports.ThemeToggle=qy;exports.TopStrip=Ir;exports.VersionLineageGraph=xd;exports.VersionLineageList=fd;exports.VersionLineageView=Uo;exports.VolumeChips=Pg;exports.VolumeLinks=bo;exports.WorkCard=$d;exports.WorkCardGrid=zd;exports.WorkCatalog=cx;exports.WorkPage=gd;exports.WorkRow=Cd;exports.adaptCharCord=lx;exports.adaptEntityJson=Lc;exports.adaptPunctJson=tx;exports.applyLayout=Uy;exports.applyTheme=gp;exports.authorsLine=Oi;exports.bookIndexUriToId=Lr;exports.bookMarkingOf=wo;exports.bucketResources=lo;exports.buildCatalogTree=ly;exports.buildCollectionTable=tc;exports.buildLineageGraph=hi;exports.buildMeiliFilter=Ru;exports.buildPageUrl=Xr;exports.buildParagraphBlocks=zc;exports.buildVersionRow=Xl;exports.buildVersionTable=Zl;exports.canParagraphize=yi;exports.catalogNodeIdOf=sy;exports.catalogNodeIdsOf=ay;exports.catalogPageCount=uy;exports.catalogTotal=Yo;exports.classificationPath=Un;exports.clearAllRecentIds=eo;exports.compareCatalogCards=py;exports.computeVersionPartition=dg;exports.countActiveFilters=zi;exports.createTextApi=El;exports.currentLayout=Vy;exports.currentTheme=hp;exports.defaultEntityHref=Dc;exports.defaultWorkLink=Sd;exports.deriveDating=ag;exports.deriveEditionType=ic;exports.deriveEra=Wn;exports.deriveYear=Ii;exports.deriveYearRange=ao;exports.detailToEditor=ad;exports.detectGenre=Mi;exports.displayAuthorRole=po;exports.editorToDetail=Dx;exports.eraRank=Tr;exports.filtersFromParams=Eu;exports.filtersToParams=fi;exports.findCatalogPath=pn;exports.findTraditionalChars=xu;exports.firstAuthorText=Ko;exports.flattenTitles=Er;exports.flattenToc=Vl;exports.fmtCount=Ke;exports.formatHitCount=di;exports.formatTemplate=ft;exports.formatVolumeRange=Ei;exports.getDisplayNameFromUrl=fn;exports.getMessages=bn;exports.getStartPage=Kr;exports.getT=yn;exports.getTypeGroupKey=Yr;exports.groupRelatedWorks=lg;exports.gujiInlineToPlain=ac;exports.hasActiveFilters=xl;exports.hasGujiMarkdownV02=bg;exports.hasGujiTableNotation=Zg;exports.hasSearchOptions=zu;exports.iiifVolumeOf=nx;exports.isCountedChar=$o;exports.isLayoutName=fp;exports.isThemeName=up;exports.lineageHref=Yd;exports.loadRecentIds=Dt;exports.measureText=Bt;exports.mergeVolumeResources=qr;exports.normalizeEra=nt;exports.normalizeLayout=Vi;exports.normalizeRole=co;exports.normalizeTheme=Di;exports.normalizeVolumeIndex=Ln;exports.normalizeVolumes=rl;exports.numberToChinese=nc;exports.paginationItems=kd;exports.parseChineseNumber=xi;exports.parseGujiInline=sc;exports.parseGujiTable=Sc;exports.parseSourceString=Zc;exports.pct=Jo;exports.periodLevel=Ed;exports.pickReaderVersion=Ul;exports.readStoredLayout=Hy;exports.readStoredTheme=Oy;exports.readerVersionOptionLabel=$r;exports.remapPlainOffsets=Ac;exports.removeRecentId=wl;exports.renderFullTextBody=ah;exports.renderProperNames=Rc;exports.renderReaderInline=So;exports.resolveRecentEntry=to;exports.resourceHref=xn;exports.resourceNote=Ri;exports.resultTabFromParam=Du;exports.resultTabToParam=Uu;exports.roleFacets=Ql;exports.rowNo=Fg;exports.sameFilters=Lu;exports.saveRecentId=kr;exports.segmentEntities=Mc;exports.shelfColumns=Id;exports.sortFor=Nu;exports.sortYear=bi;exports.spineHeight=Rd;exports.splitFullTextTables=yo;exports.splitHighlightSnippet=Gr;exports.splitTableRow=wc;exports.storeLayout=Dy;exports.storeTheme=mp;exports.stringifySources=Jc;exports.summaryFromEntry=Fc;exports.summaryFromItem=Oc;exports.timelineLayout=qd;exports.toCatalogWorkCard=dy;exports.transportSummaryLoader=Hc;exports.typeSupportsFilters=bl;exports.useBidUrl=tt;exports.useChapterWarpData=Gc;exports.useConvert=Me;exports.useEntitySummaryLoader=Ao;exports.useI18n=te;exports.useReaderPrefs=Dl;exports.useRecentEntries=Xd;exports.useT=Ie;exports.validateLineageGraph=Cb;exports.volumeStats=wi;exports.withDefaultLinks=Ut;exports.withMetaLinks=Vt;exports.yearText=ki;