book-index-ui 0.52.1 → 0.52.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.cjs +57 -57
  2. package/dist/index.js +6606 -6612
  3. package/package.json +1 -1
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 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=`
1
+ "use strict";var zp=Object.create;var gs=Object.defineProperty;var Np=Object.getOwnPropertyDescriptor;var Ip=Object.getOwnPropertyNames;var Rp=Object.getPrototypeOf,Ep=Object.prototype.hasOwnProperty;var Lp=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Ip(n))!Ep.call(e,s)&&s!==i&&gs(e,s,{get:()=>n[s],enumerable:!(o=Np(n,s))||o.enumerable});return e};var ii=(e,n,i)=>(i=e!=null?zp(Rp(e)):{},Lp(n||!e||!e.__esModule?gs(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Se=require("./storage-entry-4WXkdkaK.cjs"),t=require("react/jsx-runtime"),g=require("react"),Ap=require("opencc-js/t2cn"),Za=require("./variant-supplement.cjs"),Mp=require("react-markdown"),Pp=require("remark-gfm"),Bp=e=>`/book-index?id=${e}`,Ja=g.createContext(Bp);function Wp({buildUrl:e,children:n}){const i=g.useMemo(()=>e,[e]);return t.jsx(Ja.Provider,{value:i,children:n})}function tt(){return g.useContext(Ja)}const Qa="",el="";function Vr(e){const n=[];let i=!1,o=e;for(;o.length;){const s=i?el:Qa,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 lt(e,n){return{title:e,tokens:n}}const fs='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Op=[lt("基础(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"}}),lt("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),lt("提示与警告",{"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)"}}),lt("遮罩与阴影",{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)"}}),lt("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),lt("资源",{"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"}}),lt("整理本(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:"中性灰:占位"}}),lt("版本传承(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"}}),lt("编辑器视图(主要在 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")'}}),lt("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),lt('版式(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"}}),lt("阅读器(整理本 / 全文)",{"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:"版心外边线"}}),lt("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),lt("字体(全站无衬线,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:fs,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:fs,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Fp=Object.assign({},...Op.map(e=>e.tokens)),tl={};for(const[e,n]of Object.entries(Fp))tl[e]=`var(--bim-${e}, ${n.value})`;function r(e){const n=tl[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 Hp(e,n){return Mt(e).includes(n)}const Dp={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 Up={"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 Up[new URL(e).hostname]}catch{return}}const xs={text:0,image:1,physical:2};function Gr(e){return e.length===0?"physical":[...e].sort((n,i)=>(xs[n]??99)-(xs[i]??99)).join("+")}function Vp(e){return e.includes("text")&&e.includes("image")?"text+image":e[0]||"physical"}function Yr(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[h,u]=p,m=`${h}|${Gr(Mt(c))}`;i.has(m)||i.set(m,{base:{...c,name:h,url:"",volumes:[]},volumes:[],indices:[]});const f=i.get(m);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 nl(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 il(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||nl(n)}))}function ki(e){const n=il(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 qr(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 Kr(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=qr(e.metadata);return n?Kr(e.url,n):e.url}const Tt=g.createContext(null),rl=["曹霑"];function Gp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Yp(e,n=rl){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(Gp).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 ol(){if(wn)return wn;try{const e=Ap.Converter({from:"t",to:"cn"});wn=Yp(n=>e(Se.normalizeVariants(n)))}catch{wn=e=>e}return wn}const qp={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:"圖片資源"}},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:"图片资源"}};function dt(e,n,i){return{"zh-Hant":e,"zh-Hans":n}}const Xp=dt({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:"无数据"}),wi=dt({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:"作品信息"}),Zp=dt({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:"附记"}}),Jp=dt({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}"}}),Qp=dt({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:"上级丛编"}),eu=dt({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 为自动匹配,未经人工核对"}),tu=dt({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:"查看详情 →"}),nu=dt({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:"本卷条目"}),iu=dt({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:"规模、存佚、许可与版本"}),Xr=dt({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:"按作者浏览全部 →"}),ru=dt({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} 条"}),ou=dt({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:"搜索"}),su=dt({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:"回复"}),au=dt({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:"有争议"}}),lu={common:Xp,detail:wi,bookPage:Zp,workPage:Jp,collectionPage:Qp,entityPage:eu,reader:tu,collated:nu,metaHome:iu,readHome:Xr,catalogPage:ru,searchPage:ou,feedback:su,lineage:au};function cu(e){const n={};for(const[i,o]of Object.entries(lu))n[i]=o[e];return n}function gt(e,n){return e.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}const bs=new Map;function bn(e){let n=bs.get(e);return n||(n={...e==="zh-Hans"?Kp:qp,...cu(e)},bs.set(e,n)),n}function ys(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 sl(e){return(n,i)=>{const o=ys(e,n)??ys(bn("zh-Hant"),n)??n;return i?gt(o,i):o}}const js=new Map;function yn(e){let n=js.get(e);return n||(n=sl(bn(e)),js.set(e,n)),n}const al="bim-locale";function du(){try{const e=localStorage.getItem(al);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function pu(e){try{localStorage.setItem(al,e)}catch{}}const uu="zh-Hans",mu=({locale:e,onLocaleChange:n,converter:i,children:o})=>{const[s,a]=g.useState(e??uu),l=e??s;g.useEffect(()=>{if(e)return;const h=du();h&&h!==s&&a(h)},[]);const d=g.useMemo(()=>l==="zh-Hans"?i??ol():null,[l,i]),c=g.useCallback(h=>{a(h),pu(h),n==null||n(h)},[n]),p=g.useMemo(()=>({locale:l,setLocale:c,messages:bn(l),converter:d}),[l,c,d]);return t.jsx(Tt.Provider,{value:p,children:o})};function Ee(){const e=g.useContext(Tt);return(e==null?void 0:e.messages)??bn("zh-Hant")}const hu=2e3;function Be(){const e=g.useContext(Tt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,o=g.useRef(new Map),s=g.useRef(n),a=g.useRef(i);(s.current!==n||a.current!==i)&&(o.current.clear(),s.current=n,a.current=i);const l=g.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 h=o.current.keys().next().value;h!==void 0&&o.current.delete(h)}return o.current.set(d,p),p},[i]);return g.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function ne(){const e=g.useContext(Tt),{convert:n,locale:i,isSimplified:o}=Be(),s=(e==null?void 0:e.messages)??bn("zh-Hant"),a=g.useMemo(()=>e?sl(s):yn("zh-Hant"),[e,s]);return g.useMemo(()=>({t:a,convert:n,locale:i,isSimplified:o,messages:s}),[a,n,i,o,s])}const ll=["錄說語詞議樣書記類傳國經補藝紀編後與間條號為開總種無數據冊頁選時題爲詩萬證學續關東圖資歷來讀館論見鈔別進師輯陳覽寫現應從","點兩華實對員長註結闕殘檢閱當會單換體將裡訂處過區釋術頭錢譯識個電動顯問這認質還幾遺雖須專擇係網運權務變發機請風聲輸軍導產","話們車難報讓業設帶辦紙氣麼際聽親場買賣謝費漢庫遷馬叢孫於張義晉閣維曆欽則夢慶齋録舊內陽樓紅淵歸載稱隱遼計評觀禮龜黃興節併","餘齊韓簡霑並樂諸滸屬組篩紹緒劉蘇誤職夾廣蓋敘斷歐寬駰極參試雜魯沒順線貞該測鮮統戰檔衛辭聯臺贊刪聖貫啟瀏譜薈寶約嘗諜謂舉詳","異賦軾復諒構級審標劃彙吳楊暫轉項寧硯蕭儀禪韻掃閉倉麗禎錯監鞏轍繫説筆竄縣聞諡賈僅擊羅宮訓談誌葉視戶細許祿繪鍵絕欄鑑講誕馮","趙習樹饋確賜裝擬規繼製薦畫鉛獨誠遠龍門覺訣隸軒諭繕塊爭鏡裏豐碼備掛堯錦駕鶴遊傷猶鄒瑩綴揚詔託僞頗竊虛莊歲禍爾辯獲篤窮盡跡","萊終穎訛瑣鐫繡廟幀佈躍雙預連狀態軸複懸遞灣箋頌訪層鏈敗達鈞鳳亂奮豈陰婁騎純優獻靈牆隨摺疊驗徑橫瀾蔣壞鈕盤範圍責減籤適側","榮聶頃縉讎銓廳軌厲鶚駢醫駝黨鐘諫樞滄軻溫贈鐵徵賴蹟潁閒顗歿駁歟勸諷誼湯詐脫羣尋澤擄顏釀謄鴻離騷傑滯憤執廢懼匱歎毀蠶獄寵闇","陸淺貨輕貧俠賤貴煩競樑鳩採綜謬鳴養堅韋顎呂蘭脈峯鵲兒賞籠階緊綱漁荊嬰慍潛營鎔繞陣塚億負卻塵懷閨擋撐縮領滾輪匯撈貼讚創險團","隊準礙強髒藥鮑顧給緯悅帳巖廬貢亞壇惡諱鎮薊驍愛討彌護揮偉輒擾況較響喪鑰藍"].join(""),gu=new Set([...ll,...Object.keys(Se.VARIANT_CHARS),...Object.keys(Za.VARIANT_SUPPLEMENT)]),cl=[...rl,"切換為繁體","漢籍リポジトリ"];function fu(e,n=cl){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)=>{gu.has(a)&&o.push({char:a,context:s.slice(Math.max(0,l-8),l+9).join("")})}),o}function xu(e,n,i){return e?e==="orig"?null:n==="zh-Hans"?i??ol():e==="hant"?Se.normalizeVariants:i:i}const bu=({mode:e,children:n})=>{const i=g.useContext(Tt),o=g.useMemo(()=>!i||!e?i:{...i,converter:xu(e,i.locale,i.converter)},[i,e]);return t.jsx(Tt.Provider,{value:o,children:n})};function yu(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 vs(e){return e==="text+image"?["text","image"]:[e]}function ks(e){const n=Mt(e);return n.length===0?"text":Vp(n)}function ju(){return{id:"",name:"",url:"",types:["text"],details:""}}const jr=({items:e,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const a=Ee(),[l,d]=g.useState(null),c=[{value:"text",label:a.resourceTypeShort.text},{value:"image",label:a.resourceTypeShort.image},{value:"text+image",label:a.resourceTypeShort.textImage},{value:"physical",label:a.resourceTypeShort.physical}],p=[{value:"catalog",label:a.rootType.catalog},{value:"search",label:a.rootType.search}],h=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})=>h(w)),m=()=>{const w=ju();s&&(w.types=vs(s)),n([...e,w]),d(e.length)},f=w=>{n(e.filter((j,k)=>k!==w)),d(null)},x=(w,j,k)=>{const $=[...e];if($[w]={...$[w],[j]:k},j==="url"&&!$[w].id){const C=yu(k);C&&($[w].id=C)}n($)},v=(w,j)=>{const k=[...e],{type:$,...C}=k[w];k[w]={...C,types:vs(j)},n(k)},y=(w,j,k)=>{const C={...e[w].metadata||{}};k?C[j]=k:delete C[j],x(w,"metadata",Object.keys(C).length>0?C:void 0)},S=(w,j)=>{const k=j.trim()?j.split(/[,,、]/).map($=>$.trim()).filter(Boolean):void 0;x(w,"structure",k)},b=(w,j,k)=>{const C=e[w].coverage||{level:1,ranges:""};j==="level"?C.level=parseInt(k)||1:C.ranges=k,x(w,"coverage",C.ranges?C: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:vu(ks(w)),color:r("on-color-fg")},children:(()=>{var L,z;const _=Mt(w);return _.length===0?"text":_.length===1?((L=c.find(T=>T.value===_[0]))==null?void 0:L.label)??_[0]:_.includes("text")&&_.includes("image")?((z=c.find(T=>T.value==="text+image"))==null?void 0:z.label)??"text+image":_.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:_=>_.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&w.url&&ku(j,o==null?void 0:o[j],i,a),t.jsx("button",{onClick:_=>{_.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:[Hp(w,"image")&&w.url&&wu(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:ks(w),onChange:_=>v(j,_.target.value),style:{...St,flex:1},children:c.map(_=>t.jsx("option",{value:_.value,children:_.label},_.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:_=>x(j,"root_type",_.target.value),style:{...St,flex:1},children:p.map(_=>t.jsx("option",{value:_.value,children:_.label},_.value))})]})]}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsx("input",{type:"text",value:w.id,onChange:_=>x(j,"id",_.target.value),placeholder:a.editor.idAutoExtract,style:{...St,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:w.name,onChange:_=>x(j,"name",_.target.value),placeholder:a.editor.resourceName,style:{...St,flex:1}})]}),t.jsx("input",{type:"text",value:w.url,onChange:_=>x(j,"url",_.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,_.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:(($=w.coverage)==null?void 0:$.level)??"",onChange:_=>b(j,"level",_.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:((C=w.coverage)==null?void 0:C.ranges)||"",onChange:_=>b(j,"ranges",_.target.value),placeholder:a.editor.coverageRangePlaceholder,style:{...St,flex:1}})]})]}),t.jsx("textarea",{value:w.details||"",onChange:_=>x(j,"details",_.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(([_,L])=>{var z;return t.jsxs("label",{style:{...Sn,gap:"4px"},children:[t.jsx("span",{style:{..._n,minWidth:"56px"},children:L}),t.jsx("input",{type:"text",value:((z=w.metadata)==null?void 0:z[_])||"",onChange:T=>y(j,_,T.target.value),placeholder:L,style:{...St,flex:1}})]},_)})})]})]})]})]},j)}),t.jsxs("button",{onClick:m,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 vu(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 ku(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 wu(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"},ws={text:r("restype-text"),image:r("restype-image"),"text+image":r("restype-text-image"),physical:r("restype-physical")};function Su(e){return e.includes("text")&&e.includes("image")?ws["text+image"]:ws[e[0]||"physical"]}const Zr=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const a=Ee(),{convert:l}=Be(),d=g.useMemo(()=>Yr(e||[]),[e]),{mirrorGroups:c,ungroupedItems:p}=g.useMemo(()=>{const y=new Map,S=[];for(const b of d){const w=b.group;w?(y.has(w)||y.set(w,[]),y.get(w).push(b)):S.push(b)}for(const b of y.values())b.sort((w,j)=>{const k=$=>$.group_role==="origin"?0:$.group_role==="mirror"?1:2;return k(w)-k(j)});return{mirrorGroups:y,ungroupedItems:S}},[d]),h={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=y=>h[y]?h[y]:y.split("+").map(S=>h[S]||S).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,S)=>t.jsx(tr,{item:y},y.id||S))});const m=(y,S)=>{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:S.map((k,$)=>t.jsx(tr,{item:k,onNavigate:o,renderLink:s},k.id||$))})]},`group-${y}`)},f=new Map;for(const y of p){const S=Gr(Mt(y));f.has(S)||f.set(S,[]),f.get(S).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,S])=>m(y,S)),v.map(y=>{const S=f.get(y),b=Su(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:S.map((w,j)=>t.jsx(tr,{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")}},tr=({item:e})=>{const n=Ee(),{convert:i}=Be(),[o,s]=g.useState(!1),a=g.useMemo(()=>(e.url?fn(e.url):void 0)||i(e.name),[e.url,e.name,i]),l=g.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(x=>({...x,url:x.url||nl(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,h=e.expected_volumes??(d?c+p:0),u=e.color_mode?{..._u[e.color_mode],label:n.colorMode[e.color_mode]}:null,m=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}),m&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:m}),d&&t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg")},children:[c,"/",h,n.unit.volume,p>0&&t.jsx("span",{style:{color:r("missing-fg"),marginLeft:"3px"},children:gt(n.common.volumesMissing,{n:p})})]}),e.url&&t.jsx("a",{href:(()=>{const x=qr(e.metadata);return x?Kr(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)})})]})},dl=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:a,onSelectFolder:l})=>{const d=Ee(),c=e==="local",p=(n==null?void 0:n.isDraft)??!0,h=(n==null?void 0:n.repoPath)||"",u=h?h.split(/[/\\]/).pop()||h:"",m={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:{...m,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:m,...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:h||d.mode.selectFolder,style:{...m,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:m,...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:{...m,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:m,...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:h||d.mode.selectFolder,style:{...m,paddingLeft:"8px",paddingRight:"8px",minWidth:h?"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:{...m,background:r("mode-active-bg"),color:r("on-color-fg"),cursor:"default"},title:h,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:u})]})]})},Si="bim-search-history",Ss=10,_s=8;function Rn(){try{const e=localStorage.getItem(Si);return e?JSON.parse(e):[]}catch{return[]}}function pl(e){try{const n=Rn().filter(i=>i!==e);n.unshift(e),n.length>Ss&&(n.length=Ss),localStorage.setItem(Si,JSON.stringify(n))}catch{}}function $u(e){try{const n=Rn().filter(i=>i!==e);localStorage.setItem(Si,JSON.stringify(n))}catch{}}function Cu(){try{localStorage.removeItem(Si)}catch{}}const ul=({transport:e,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:a})=>{const l=Ee(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,h]=g.useState(!1),[u,m]=g.useState([]),[f,x]=g.useState(-1),[v,y]=g.useState(Rn),S=g.useRef(null),b=g.useRef(null),w=g.useRef(null),j=g.useRef(!1);g.useEffect(()=>{x(-1);const T=n.trim();if(!T){m(v.map(N=>({type:"history",text:N})));return}if(!e.searchAll){m([]);return}let M=!1;const P=setTimeout(()=>{e.searchAll(T,_s).then(N=>{if(M)return;const A=[...N.works,...N.books,...N.collections,...N.entities??[]];m(A.slice(0,_s).map(W=>({type:"entry",text:W.title||W.id,entry:W})))}).catch(()=>{M||m([])})},80);return()=>{M=!0,clearTimeout(P)}},[n,v,e]),g.useEffect(()=>{const T=M=>{w.current&&!w.current.contains(M.target)&&h(!1)};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[]),g.useEffect(()=>{const T=M=>{var P,N;if(M.key==="/"&&document.activeElement!==S.current){const A=(P=document.activeElement)==null?void 0:P.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return;M.preventDefault(),(N=S.current)==null||N.focus()}};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[]);const k=g.useCallback(T=>{T.trim()&&(pl(T.trim()),y(Rn())),o(T),h(!1)},[o]),$=g.useCallback(T=>{T.type==="history"?(i(T.text),k(T.text)):T.entry&&(s?(s(T.entry),h(!1)):(i(T.text),k(T.text)))},[i,k,s]),C=g.useCallback(T=>{if(!p||u.length===0){T.key==="Enter"&&k(n);return}switch(T.key){case"ArrowDown":T.preventDefault(),x(M=>(M+1)%u.length);break;case"ArrowUp":T.preventDefault(),x(M=>(M-1+u.length)%u.length);break;case"Enter":T.preventDefault(),f>=0&&f<u.length?$(u[f]):k(n);break;case"Escape":T.preventDefault(),h(!1);break}},[p,u,f,n,k,$]),_=g.useCallback((T,M)=>{M.stopPropagation(),$u(T),y(Rn()),m(P=>P.filter(N=>!(N.type==="history"&&N.text===T)))},[]),L=g.useCallback(T=>{T.stopPropagation(),Cu(),y([]),m([])},[]);g.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:S,type:"text",placeholder:d,value:n,onChange:T=>{i(T.target.value),h(!0)},onCompositionStart:()=>{j.current=!0},onCompositionEnd:()=>{j.current=!1},onFocus:()=>{h(!0)},onKeyDown:C,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:L,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),u.map((T,M)=>t.jsxs("div",{onClick:()=>$(T),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r("fg"),background:M===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:P=>_(T.text,P),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}-${M}`))]})]})},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:""},ml=new Set(["work","book","entity"]);function Tu(e){return fl(e)||!!e.sort}function zu(e,n){return n.sort&&ml.has(e)?n.sort:void 0}const $i=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Ci=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],hl=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],gl={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Ti(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 fl(e){return Ti(e)>0}function Nu(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 xl(e,n){const i=gl[e];return Nu(n).every(o=>i.has(o))}const $n=e=>JSON.stringify(e);function Iu(e,n){if(!xl(n,e))return null;const i=[];if(e.dynasty.length){const o=Array.from(new Set(e.dynasty.flatMap(s=>{var a;return((a=$i.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 at={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},bl="_";function gi(e,n=new URLSearchParams){for(const i of Object.values(at))n.delete(i);return e.dynasty.length&&n.set(at.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(at.classification,e.classification.map(i=>i||bl).join(",")),e.hasImage&&n.set(at.hasImage,"1"),e.hasText&&n.set(at.hasText,"1"),e.hasCollated&&n.set(at.hasCollated,"1"),e.loss&&n.set(at.loss,e.loss),e.sort&&n.set(at.sort,e.sort),n}function Ru(e){const n=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),i=new Set($i.map(a=>a.key)),o=new Set(Ci.map(a=>a.value)),s=e.get(at.loss);return{dynasty:Array.from(new Set(n(at.dynasty).filter(a=>i.has(a)))),classification:Array.from(new Set(n(at.classification).map(a=>a===bl?"":a).filter(a=>o.has(a)))),hasImage:e.get(at.hasImage)==="1",hasText:e.get(at.hasText)==="1"||e.get(at.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(at.sort))??""}}function Eu(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 $s(e,n){return e.includes(n)?e.filter(i=>i!==n):[...e,n]}const Lu=({filters:e,onChange:n})=>{const i=Ee(),o=i.searchV4,{convert:s}=Be(),[a,l]=g.useState(!1),d=g.useId(),c=Ti(e),p=h=>n({...e,...h});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(h=>!h),children:[t.jsxs("span",{children:[s(o.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:s(gt(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:$i.map(h=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(h.key),onClick:()=>p({dynasty:$s(e.dynasty,h.key)}),children:s(h.key)},h.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(o.classification)}),Ci.map(h=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(h.value),onChange:()=>p({classification:$s(e.classification,h.value)})}),h.value?s(h.label):i.searchPage.unclassified]},h.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:h=>p({hasImage:h.target.checked})}),s(o.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:h=>p({hasText:h.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(h=>t.jsx("button",{type:"button","aria-pressed":e.loss===h.value,onClick:()=>p({loss:h.value}),children:i.searchPage.loss[h.value||"all"]},h.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({..._i,sort:e.sort}),children:s(o.clearAllFilters)})]})]})};function yl({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 Cs=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Ee(),a=s.searchV4,{convert:l}=Be(),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),h=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)}`:""}`:"",m=c.type==="book"?c.era??c.dynasty:c.dynasty,f=m?l(m):"",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:S=>i(c,S),children:t.jsx(yl,{text:p,query:n?l(n):void 0})}),h&&t.jsx("span",{className:"bim-sr-measure",children:h})]}),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(S=>t.jsx("span",{className:`bim-sr-tag ${S.cls}`,children:l(S.label)},S.label))})]},c.id)})})]})})},Au=`
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")}; }
@@ -12,7 +12,7 @@
12
12
  .bim-sc-fl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: ${r("aux-fg")}; }
13
13
  .bim-sc-tags { display: flex; gap: 4px; flex: none; }
14
14
  :root[data-layout="boxed"] .bim-sc { box-shadow: none; }
15
- `,zs=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Ie(),a=s.searchV4,{convert:l}=Me(),d=tt();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Mu}),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}`:"",g=[c.type==="entity"?c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:"":`${c.dynasty?`〔${l(c.dynasty)}〕`:""}${c.author?l(c.author):""}`,c.type==="book"&&c.edition?l(c.edition):"",m].filter(Boolean).join(" · "),f=[o(c.type),c.classification?l(c.classification):""].filter(Boolean).join(" · "),x=[];return c.has_image&&x.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&x.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&x.push({label:a.tagLost,cls:"bim-sr-tag--lost"}),t.jsxs("a",{className:"bim-sc",href:d(c.id),onClick:v=>i(c,v),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(jl,{text:p,query:n?l(n):void 0})}),g&&t.jsx("span",{className:"bim-sc-m",children:g}),c.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:Gr(c.descriptionSnippet).map((v,y)=>v.marked?t.jsx("mark",{children:l(v.text)},y):t.jsx(h.Fragment,{children:l(v.text)},y))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:f}),t.jsx("span",{className:"bim-sc-tags",children:x.map(v=>t.jsx("span",{className:`bim-sr-tag ${v.cls}`,children:l(v.label)},v.label))})]})]},c.id)})]})};function Pu(e,n){const i=new Set([1,n,e-1,e,e+1].filter(a=>a>=1&&a<=n)),o=Array.from(i).sort((a,l)=>a-l),s=[];return o.forEach((a,l)=>{l>0&&a-o[l-1]>1&&s.push("gap"),s.push(a)}),s}function Bu(e,n,i){const o=Math.max(1,Math.ceil(n/i));return Math.min(Math.max(1,e),o)}const Wu=({page:e,pageSize:n,total:i,totalLabel:o,onPage:s})=>{const a=Ie().searchV4,{convert:l}=Me(),d=Math.max(1,Math.ceil(i/n));return i<=0?null:t.jsxs("nav",{className:"bim-sr-pager","aria-label":l(a.pagerLabel),children:[t.jsx("span",{className:"bim-sr-info",children:l(ft(a.pageInfo,{total:o??i.toLocaleString(),size:n,page:e,pages:d}))}),d>1&&t.jsxs("ul",{children:[t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>s(e-1),children:l(a.prevPage)})}),Pu(e,d).map((c,p)=>c==="gap"?t.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${p}`):t.jsx("li",{children:t.jsx("button",{type:"button","aria-current":c===e?"page":void 0,"aria-label":`${c}`,onClick:()=>s(c),children:c})},c)),t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e>=d,onClick:()=>s(e+1),children:l(a.nextPage)})})]})]})},vl="(max-width: 719px)",Ou=`${vl}, (pointer: coarse)`,Fu=`
15
+ `,Ts=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Ee(),a=s.searchV4,{convert:l}=Be(),d=tt();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Au}),e.map(c=>{const p=l(c.title||c.primary_name||c.id),h=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",m=[c.type==="entity"?c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:"":`${c.dynasty?`〔${l(c.dynasty)}〕`:""}${c.author?l(c.author):""}`,c.type==="book"&&c.edition?l(c.edition):"",h].filter(Boolean).join(" · "),f=[o(c.type),c.classification?l(c.classification):""].filter(Boolean).join(" · "),x=[];return c.has_image&&x.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&x.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&x.push({label:a.tagLost,cls:"bim-sr-tag--lost"}),t.jsxs("a",{className:"bim-sc",href:d(c.id),onClick:v=>i(c,v),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(yl,{text:p,query:n?l(n):void 0})}),m&&t.jsx("span",{className:"bim-sc-m",children:m}),c.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:Vr(c.descriptionSnippet).map((v,y)=>v.marked?t.jsx("mark",{children:l(v.text)},y):t.jsx(g.Fragment,{children:l(v.text)},y))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:f}),t.jsx("span",{className:"bim-sc-tags",children:x.map(v=>t.jsx("span",{className:`bim-sr-tag ${v.cls}`,children:l(v.label)},v.label))})]})]},c.id)})]})};function Mu(e,n){const i=new Set([1,n,e-1,e,e+1].filter(a=>a>=1&&a<=n)),o=Array.from(i).sort((a,l)=>a-l),s=[];return o.forEach((a,l)=>{l>0&&a-o[l-1]>1&&s.push("gap"),s.push(a)}),s}function Pu(e,n,i){const o=Math.max(1,Math.ceil(n/i));return Math.min(Math.max(1,e),o)}const Bu=({page:e,pageSize:n,total:i,totalLabel:o,onPage:s})=>{const a=Ee().searchV4,{convert:l}=Be(),d=Math.max(1,Math.ceil(i/n));return i<=0?null:t.jsxs("nav",{className:"bim-sr-pager","aria-label":l(a.pagerLabel),children:[t.jsx("span",{className:"bim-sr-info",children:l(gt(a.pageInfo,{total:o??i.toLocaleString(),size:n,page:e,pages:d}))}),d>1&&t.jsxs("ul",{children:[t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>s(e-1),children:l(a.prevPage)})}),Mu(e,d).map((c,p)=>c==="gap"?t.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${p}`):t.jsx("li",{children:t.jsx("button",{type:"button","aria-current":c===e?"page":void 0,"aria-label":`${c}`,onClick:()=>s(c),children:c})},c)),t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e>=d,onClick:()=>s(e+1),children:l(a.nextPage)})})]})]})},jl="(max-width: 719px)",Wu=`${jl}, (pointer: coarse)`,Ou=`
16
16
  .bim-sr-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; align-items: start; padding: 0 20px; }
17
17
  .bim-sr-layout[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
18
18
  .bim-sr-aside { position: sticky; top: calc(${r("reader-top")} + 16px); padding-top: 2px; }
@@ -81,7 +81,7 @@
81
81
  .bim-sr-pager .bim-sr-gap { color: ${r("aux-fg")}; padding: 0 2px; }
82
82
  .bim-sr-empty { padding: 60px 0; text-align: center; font-size: 14px; color: ${r("meta-fg")}; }
83
83
 
84
- @media ${vl} {
84
+ @media ${jl} {
85
85
  .bim-sr-layout { grid-template-columns: minmax(0, 1fr); row-gap: 16px; padding: 0 16px; }
86
86
  .bim-sr-aside { position: static; }
87
87
  .bim-sr-fbtn {
@@ -102,7 +102,7 @@
102
102
  .bim-sr-table td.bim-sr-c-res { text-align: left; padding-bottom: 2px; }
103
103
  .bim-sr-table td.bim-sr-c-res:empty { display: none; }
104
104
  }
105
- @media ${Ou} {
105
+ @media ${Wu} {
106
106
  .bim-sr-chip { min-height: 36px; }
107
107
  .bim-sr-opt { min-height: 44px; }
108
108
  .bim-sr-seg button { min-height: 44px; }
@@ -117,10 +117,10 @@
117
117
  :root[data-layout="boxed"] .bim-sr-table th { background: ${r("fr-bg")}; }
118
118
  /* 墨:主色与正文对比不到 3:1,标题链接另加下划线 */
119
119
  :root[data-theme="ink"] .bim-sr-table td.bim-sr-c-title a { text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 3px; }
120
- `,Qr="bim-search-view",ir=50,Ns=5,En=1e3;function di(e){return e>=En?`${En.toLocaleString()}+`:e.toLocaleString()}const Hu={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function Du(e){return e&&Hu[e.toLowerCase()]||"all"}function Uu(e){return e==="all"?null:e}const Is=["work","collection","book","entity"],Vu={work:"works",collection:"collections",book:"books",entity:"entities"},Gu={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Yu(){try{return window.localStorage.getItem(Qr)==="card"?"card":"table"}catch{return"table"}}function qu(e){try{window.localStorage.setItem(Qr,e)}catch{}}const an=(e,n)=>(e==null?void 0:e[Gu[n]])??0,rr=(e,n)=>(e==null?void 0:e[Vu[n]])??[],kl=({transport:e,query:n,filters:i,onFiltersChange:o,onEntryLinkClick:s,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:p})=>{const m=Ie(),u=m.searchV4,{convert:g}=Me(),f=!!e.supportsSearchFilters,x=h.useMemo(()=>f?i:$i,[f,i]),[v,y]=h.useState("table");h.useEffect(()=>{y(Yu())},[]);const _=D=>{y(D),qu(D)},[b,w]=h.useState(l??"all"),j=h.useRef(b);j.current=b,h.useEffect(()=>{l!==void 0&&l!==j.current&&(w(l),C(1))},[l]);const[k,C]=h.useState(c&&c>0?c:1),$=h.useRef(k);$.current=k,h.useEffect(()=>{c!==void 0&&c>0&&c!==$.current&&C(c)},[c]);const S=h.useRef(null),M=h.useCallback(D=>{var we;C(D),p==null||p(D);const K=S.current;K&&K.getBoundingClientRect().top<0&&((we=K.scrollIntoView)==null||we.call(K,{block:"start",behavior:"instant"}))},[p]),[z,T]=h.useState(null),[P,R]=h.useState(null),[N,A]=h.useState(!1),[H,G]=h.useState(""),ie=fi(x).toString(),le=zi(x)>0,V=fi({...x,sort:""}).toString(),F=h.useRef({query:n,filterOnlyKey:V,sort:x.sort});h.useEffect(()=>{const D=F.current;D.query!==n||D.filterOnlyKey!==V?(w("all"),C(1)):D.sort!==x.sort&&C(1),F.current={query:n,filterOnlyKey:V,sort:x.sort}},[n,V,x.sort]),h.useEffect(()=>{let D=!1;return A(!0),G(""),(async()=>{try{let K;if(e.searchAll)K=await e.searchAll(n,Ns,x);else{const we=["work","book","collection","entity"],ne=await Promise.all(we.map(B=>e.search(n,B,{page:1,pageSize:Ns,filters:x})));K={works:ne[0].entries,books:ne[1].entries,collections:ne[2].entries,entities:ne[3].entries,totalWorks:ne[0].total,totalBooks:ne[1].total,totalCollections:ne[2].total,totalEntities:ne[3].total}}D||T(K)}catch(K){D||(G(K instanceof Error?K.message:String(K)),T(null))}finally{D||A(!1)}})(),()=>{D=!0}},[e,n,ie]);const xe=b;h.useEffect(()=>{if(b==="all"){R(null);return}let D=!1;return A(!0),(async()=>{try{const K=await e.search(n,b,{page:k,pageSize:ir,filters:x});D||R({key:xe,entries:K.entries,total:K.total})}catch(K){D||(G(K instanceof Error?K.message:String(K)),R(null))}finally{D||A(!1)}})(),()=>{D=!0}},[e,n,ie,b,k]);const ee=P&&P.key===xe?P:null;h.useEffect(()=>{if(b==="all"||!ee||N)return;const D=Math.min(ee.total,En),K=Bu(k,D,ir);ee.entries.length===0&&D>0&&K!==k&&(C(K),p==null||p(K))},[b,ee,N,k]);const L=h.useMemo(()=>Is.filter(D=>an(z,D)>0),[z]),Re=L.reduce((D,K)=>D+an(z,K),0),ce=L.some(D=>an(z,D)>=En)?`${Re.toLocaleString()}+`:Re.toLocaleString(),me=!N&&!H&&z!==null&&Re===0,se=h.useCallback(D=>{w(D),C(1),d==null||d(D)},[d]),Pe=h.useMemo(()=>{const D=[];return x.dynasty.forEach(K=>D.push({name:K,remove:()=>o({...x,dynasty:x.dynasty.filter(we=>we!==K)})})),x.classification.forEach(K=>{var we;return D.push({name:K?((we=Ti.find(ne=>ne.value===K))==null?void 0:we.label)??K:m.searchPage.unclassified,remove:()=>o({...x,classification:x.classification.filter(ne=>ne!==K)})})}),x.hasImage&&D.push({name:u.hasImage,remove:()=>o({...x,hasImage:!1})}),x.hasText&&D.push({name:u.hasText,remove:()=>o({...x,hasText:!1})}),x.hasCollated&&D.push({name:u.hasCollated,remove:()=>o({...x,hasCollated:!1})}),x.loss&&D.push({name:`${u.extant}:${m.searchPage.loss[x.loss]}`,remove:()=>o({...x,loss:""})}),D},[x,o,u,m]),X={query:n,onEntryLinkClick:s,typeName:a},re=D=>v==="table"?t.jsx(Ts,{entries:D,...X}):t.jsx(zs,{entries:D,...X}),de=Is.flatMap(D=>rr(z,D));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:Fu}),f&&t.jsx(Au,{filters:x,onChange:o}),t.jsxs("div",{className:"bim-sr-main","aria-busy":N,ref:S,children:[L.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":m.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${r("rule")}`},children:[t.jsxs(Rs,{on:b==="all",onClick:()=>se("all"),children:[m.search.allTab," ",t.jsx("small",{children:ce})]}),L.map(D=>t.jsxs(Rs,{on:b===D,onClick:()=>se(D),children:[a(D)," ",t.jsx("small",{children:di(an(z,D))})]},D))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":g(u.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!x.sort,onClick:()=>o({...x,sort:""}),children:g(u.sortRelevance)}),["era","title"].map(D=>{const K=x.sort.startsWith(`${D}:`)?x.sort.endsWith("desc")?"desc":"asc":null,we=D==="era"?u.sortEra:u.sortTitle,ne=D==="era"?K==="desc"?u.sortEraDesc:u.sortEraAsc:K==="desc"?u.sortTitleDesc:u.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":K!==null,title:g(ne),onClick:()=>o({...x,sort:`${D}:${K==="asc"?"desc":"asc"}`}),children:[g(we),K?t.jsxs("span",{"aria-hidden":"true",children:[" ",K==="asc"?"↑":"↓"]}):null]},D)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":g(u.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":v==="table",onClick:()=>_("table"),children:g(u.viewTable)}),t.jsx("button",{type:"button","aria-pressed":v==="card",onClick:()=>_("card"),children:g(u.viewCard)})]})]}),le&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:g(ft(u.filteredCount,{n:ce}))}),Pe.map(D=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":g(ft(u.removeFilter,{name:D.name})),onClick:D.remove,children:[g(D.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},D.name))]}),H&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:H}),me&&t.jsx("div",{className:"bim-sr-empty",children:g(le?u.emptyFiltered:ft(m.search.noResultsFor,{query:n}))}),!H&&!me&&b==="all"&&z&&(v==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Ts,{entries:de,...X}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:g(u.limitedNote)})]}):t.jsx(t.Fragment,{children:L.map(D=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(jn,{type:D,size:8}),a(D),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r("meta-fg")},children:[di(an(z,D))," ",m.unit.items]})]}),an(z,D)>rr(z,D).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>se(D),children:m.action.viewAll})]}),t.jsx(zs,{entries:rr(z,D),...X})]},D))})),!H&&b!=="all"&&!ee&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:m.search.loading}),!H&&b!=="all"&&ee&&ee.entries.length>0&&t.jsxs(t.Fragment,{children:[re(ee.entries),t.jsx(Wu,{page:k,pageSize:ir,total:Math.min(ee.total,En),totalLabel:di(ee.total),onPage:M})]}),!H&&b!=="all"&&ee&&ee.entries.length===0&&!N&&t.jsxs("div",{className:"bim-sr-empty",children:[g(le?u.emptyFiltered:ft(m.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>se("all"),children:m.search.allTab})})]})]})]})};function Rs({on:e,onClick:n,children:i}){return t.jsx("button",{type:"button","aria-pressed":e,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:r(e?"ink":"meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${r("accent")}`:"none"},children:i})}const un="bim-recent-ids",Es="bim-recent-entries",Ls=50;function Dt(){try{const e=localStorage.getItem(un);if(e)return JSON.parse(e);const n=localStorage.getItem(Es);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(un,JSON.stringify(i)),localStorage.removeItem(Es),i}return[]}catch{return[]}}function kr(e){try{const n=Dt().filter(i=>i!==e);n.unshift(e),n.length>Ls&&(n.length=Ls),localStorage.setItem(un,JSON.stringify(n))}catch{}}function wl(e){try{const n=Dt().filter(i=>i!==e);localStorage.setItem(un,JSON.stringify(n))}catch{}}function eo(){try{localStorage.removeItem(un)}catch{}}async function to(e,n){var i,o,s;try{if(e.getEntry){const l=await e.getEntry(n);if(l)return l}const a=await e.getItem(n);if(a){const l=a.authors;return{id:n,title:a.title||n,type:a.type||"work",author:(i=l==null?void 0:l[0])==null?void 0:i.name,dynasty:(o=l==null?void 0:l[0])==null?void 0:o.dynasty,role:(s=l==null?void 0:l[0])==null?void 0:s.role,edition:a.edition||void 0}}}catch{}return{id:n,title:n,type:"work",notFound:!0}}const or=5,Ku=50,Xu=200,As={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},wr=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:p,resultVariant:m="compact",renderEntry:u,initialQuery:g,onQueryChange:f,headerRight:x,reserveViewportHeight:v=!1,filtersEnabled:y=!1,filters:_=$i,onFiltersChange:b,resultTab:w,onResultTabChange:j,resultPage:k,onResultPageChange:C})=>{const $=Ie(),S=[{type:"work",name:$.indexType.work,key:"works"},{type:"book",name:$.indexType.book,key:"books"},{type:"collection",name:$.indexType.collection,key:"collections"},{type:"entity",name:$.indexType.entity,key:"entities"}],M=["work","collection","book","entity"],[z,T]=h.useState(g??""),[P,R]=h.useState(null),[N,A]=h.useState(g??""),H=fi(_).toString(),[G,ie]=h.useState(_);h.useEffect(()=>{ie(_)},[H]);const le=I=>{ie(I),b==null||b(I)},[V,F]=h.useState(null),[xe,ee]=h.useState("all"),[L,Re]=h.useState(!1),[ce,me]=h.useState(null),[se,Pe]=h.useState(""),[X,re]=h.useState(!(g!=null&&g.trim())),[de,D]=h.useState(Dt),[K,we]=h.useState([]),[ne,B]=h.useState(!1),[Z,ae]=h.useState(!1),[je,Y]=h.useState(null),[be,Ee]=h.useState(null),Fe=h.useRef(void 0),W=h.useRef(!1),J=h.useCallback(async(I,U)=>{if(!I.trim()){re(!0),R(null),F(null);return}if(re(!1),y){A(I);return}Re(!0),Pe("");try{if(e.searchAll){const ue=await e.searchAll(I,U??or);R(ue)}else{const ue=["work","book","collection","entity"],Ce=await Promise.all(ue.map(ye=>e.search(I,ye,{page:1,pageSize:U??or})));R({works:Ce[0].entries,books:Ce[1].entries,collections:Ce[2].entries,entities:Ce[3].entries,totalWorks:Ce[0].total,totalBooks:Ce[1].total,totalCollections:Ce[2].total,totalEntities:Ce[3].total})}}catch(ue){Pe(ue instanceof Error?ue.message:String(ue)),R(null)}finally{Re(!1)}},[e,y]);h.useEffect(()=>{let I=!1;const U=()=>{var Ge,Q;const ue=["work","book","collection","entity"],Ce=Promise.all(ue.map(ke=>e.loadEntries(ke,{page:1,pageSize:1}).catch(()=>({total:0})))),ye=((Ge=e.getResourceCounts)==null?void 0:Ge.call(e).catch(()=>null))??Promise.resolve(null),ge=((Q=e.getSubtypeStats)==null?void 0:Q.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Ce,ye,ge]).then(([ke,Ae,Be])=>{I||(Y({works:ke[0].total,books:ke[1].total,collections:ke[2].total,entities:ke[3].total,hasText:Ae==null?void 0:Ae.hasText,hasImage:Ae==null?void 0:Ae.hasImage}),Be&&Ee(Be))})};return e.getCounts?e.getCounts().then(ue=>{var Ce,ye;I||(Y({works:ue.works,books:ue.books,collections:ue.collections,entities:ue.entities,hasText:(Ce=ue.resourceCounts)==null?void 0:Ce.hasText,hasImage:(ye=ue.resourceCounts)==null?void 0:ye.hasImage}),ue.subtypeStats&&Ee(ue.subtypeStats))}).catch(()=>{I||U()}):U(),()=>{I=!0}},[e]),h.useEffect(()=>{W.current||!(g!=null&&g.trim())||(W.current=!0,J(g))},[g,J]);const $e=h.useCallback(I=>{if(T(I),!I.trim()){f==null||f(I),re(!0),R(null),F(null),ee("all");return}Fe.current&&clearTimeout(Fe.current),Fe.current=setTimeout(()=>{F(null),ee("all"),f==null||f(I),J(I)},Xu)},[J,f]),Te=h.useCallback(I=>{Fe.current&&clearTimeout(Fe.current),ee("all"),f==null||f(I),J(I)},[J,f]),O=h.useCallback(I=>{F(I),J(z,Ku)},[z,J]);h.useEffect(()=>{if(!de.length){we([]);return}let I=!1;return B(!0),Promise.all(de.slice(0,10).map(U=>to(e,U))).then(U=>{I||(we(U),B(!1))}),()=>{I=!0}},[de,e]);const fe=I=>{me(I.id),kr(I.id),D(Dt()),o==null||o(I)},oe=(I,U)=>{if(o&&Ju(U)){U.preventDefault(),fe(I);return}kr(I.id),D(Dt())},Se=I=>{wl(I),D(Dt())},Le=()=>{eo(),D([])},He=I=>S.find(U=>U.type===I),Ye=!X&&!P&&!se,qe=P&&(P.works.length>0||P.books.length>0||P.collections.length>0),Xe=t.jsxs(t.Fragment,{children:[t.jsx(ml,{transport:e,value:z,onChange:$e,onSearch:Te,onEntrySelect:fe}),y&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const I=z.trim();I&&ul(I),Te(z)},children:$.searchPage.submit}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${r("primary")}`,borderRadius:"6px",background:"transparent",color:r("primary"),cursor:"pointer",fontSize:"13px"},children:$.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:v?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:Qu+(y?em:"")}),(!y||x||!p)&&t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${r("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[y?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:r("fg")},children:$.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[x,!p&&t.jsx(pl,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),y?t.jsxs("div",{className:"bim-ib-bar","data-nofilters":e.supportsSearchFilters?void 0:"true",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("div",{className:"bim-ib-bar-main",children:Xe})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:Xe}),X&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:r("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:je&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:be?t.jsxs(t.Fragment,{children:[(be.book??0)>0&&t.jsxs(t.Fragment,{children:[$.searchPage.statBook," ",t.jsx("strong",{style:{color:r("fg")},children:be.book.toLocaleString()})," ",$.unit.bu,$.searchPage.statComma,t.jsx("strong",{style:{color:r("fg")},children:je.books.toLocaleString()})," ",$.searchPage.statBookCopies]}),be.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statArticle," ",t.jsx("strong",{style:{color:r("fg")},children:be.article.toLocaleString()})," ",$.searchPage.statArticleUnit]}):null,be.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statPoem," ",t.jsx("strong",{style:{color:r("fg")},children:be.poem.toLocaleString()})," ",$.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statCollection," ",t.jsx("strong",{style:{color:r("fg")},children:je.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[$.indexType.work," ",t.jsx("strong",{style:{color:r("fg")},children:je.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.indexType.book," ",t.jsx("strong",{style:{color:r("fg")},children:je.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.indexType.collection," ",t.jsx("strong",{style:{color:r("fg")},children:je.collections.toLocaleString()}),je.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.indexType.entity," ",t.jsx("strong",{style:{color:r("fg")},children:je.entities.toLocaleString()})]})]})}),je.hasImage!=null&&je.hasText!=null&&t.jsxs("span",{children:[$.resourceType.image," ",t.jsx("strong",{style:{color:r("fg")},children:je.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.resourceType.text," ",t.jsx("strong",{style:{color:r("fg")},children:je.hasText.toLocaleString()})]})]})}),y&&!X&&t.jsx(kl,{transport:e,query:N,filters:G,onFiltersChange:le,onEntryLinkClick:oe,typeName:I=>He(I).name,tab:w,onTabChange:j,page:k,onPageChange:C}),!(y&&!X)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:L||Ye?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg"),minHeight:Zu,boxSizing:"border-box"},children:$.search.searching}):se?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r("desc-fg")},children:se})}):X?t.jsx("div",{style:{flex:1},children:ne?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg")},children:$.search.loading}):K.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:r("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:$.search.recentBrowse}),t.jsx("button",{onClick:Le,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:$.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:K.slice(0,Z?10:3).map(I=>I.notFound?t.jsx(rm,{id:I.id,onRemove:Se,t:$},I.id):t.jsx(Ms,{entry:I,selected:ce===I.id,onClick:oe,getConfig:He,onRemove:Se},I.id))}),!Z&&K.length>3&&t.jsx("button",{onClick:()=>ae(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:r("primary"),background:"transparent",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:$.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r("fg")},children:$.search.searchTitle}),t.jsx("p",{style:{color:r("desc-fg"),fontSize:"13px"},children:$.search.searchSubtitle})]})}):qe?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:tm}),(()=>{const I=ge=>P[As[ge]]??0,U=M.map(ge=>S.find(Ge=>Ge.type===ge)).filter(ge=>I(ge.key)>0);if(U.length<2)return null;const ue=U.reduce((ge,Ge)=>ge+I(Ge.key),0),Ce=ge=>{if(ee(ge),ge!=="all"&&V!==ge){const Ge=S.find(ke=>ke.type===ge),Q=(P[Ge.key]??[]).length;I(Ge.key)>Q&&O(ge)}},ye=ge=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:r(ge?"fg":"desc-fg"),fontWeight:ge?700:400,boxShadow:ge?`inset 0 -2px 0 ${r("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":$.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":xe==="all",style:ye(xe==="all"),onClick:()=>Ce("all"),children:[$.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ue.toLocaleString()})]}),U.map(ge=>t.jsxs("button",{type:"button","aria-pressed":xe===ge.type,style:ye(xe===ge.type),onClick:()=>Ce(ge.type),children:[ge.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:I(ge.key).toLocaleString()})]},ge.type))]})})(),S.map(({type:I,name:U,key:ue})=>{const Ce=P[ue]??[],ye=As[ue],ge=P[ye]??0;if(Ce.length===0||xe!=="all"&&xe!==I)return null;const Q=xe==="all"&&!(V===I)&&ge>or;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${r("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:[t.jsx(jn,{type:I})," ",U,t.jsxs("span",{style:{fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:[ge," ",$.unit.items]})]}),Q&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>O(I),style:{border:"none",background:"transparent",color:r("primary"),cursor:"pointer",fontSize:"12px"},children:$.action.viewAll})]}),t.jsx("div",{style:m==="list"?{display:"flex",flexDirection:"column",gap:0}:m==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Ce.map(ke=>{if(u)return t.jsx(h.Fragment,{children:u(ke)},ke.id);const Ae=m==="card"?im:Ms;return t.jsx(Ae,{entry:ke,selected:ce===ke.id,onClick:oe,getConfig:He,query:z},ke.id)})})]},I)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r("fg")},children:ft($.search.noResultsFor,{query:z})}),t.jsx("p",{style:{color:r("desc-fg"),fontSize:"13px"},children:$.search.tryOther})]})})]})},Zu=240;function Ju(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Qu=`
120
+ `,Jr="bim-search-view",nr=50,zs=5,En=1e3;function ci(e){return e>=En?`${En.toLocaleString()}+`:e.toLocaleString()}const Fu={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function Hu(e){return e&&Fu[e.toLowerCase()]||"all"}function Du(e){return e==="all"?null:e}const Ns=["work","collection","book","entity"],Uu={work:"works",collection:"collections",book:"books",entity:"entities"},Vu={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Gu(){try{return window.localStorage.getItem(Jr)==="card"?"card":"table"}catch{return"table"}}function Yu(e){try{window.localStorage.setItem(Jr,e)}catch{}}const an=(e,n)=>(e==null?void 0:e[Vu[n]])??0,ir=(e,n)=>(e==null?void 0:e[Uu[n]])??[],vl=({transport:e,query:n,filters:i,onFiltersChange:o,onEntryLinkClick:s,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:p})=>{const h=Ee(),u=h.searchV4,{convert:m}=Be(),f=!!e.supportsSearchFilters,x=g.useMemo(()=>f?i:_i,[f,i]),[v,y]=g.useState("table");g.useEffect(()=>{y(Gu())},[]);const S=H=>{y(H),Yu(H)},[b,w]=g.useState(l??"all"),j=g.useRef(b);j.current=b,g.useEffect(()=>{l!==void 0&&l!==j.current&&(w(l),$(1))},[l]);const[k,$]=g.useState(c&&c>0?c:1),C=g.useRef(k);C.current=k,g.useEffect(()=>{c!==void 0&&c>0&&c!==C.current&&$(c)},[c]);const _=g.useRef(null),L=g.useCallback(H=>{var ke;$(H),p==null||p(H);const Z=_.current;Z&&Z.getBoundingClientRect().top<0&&((ke=Z.scrollIntoView)==null||ke.call(Z,{block:"start",behavior:"instant"}))},[p]),[z,T]=g.useState(null),[M,P]=g.useState(null),[N,A]=g.useState(!1),[W,G]=g.useState(""),X=gi(x).toString(),le=Ti(x)>0,U=gi({...x,sort:""}).toString(),D=g.useRef({query:n,filterOnlyKey:U,sort:x.sort});g.useEffect(()=>{const H=D.current;H.query!==n||H.filterOnlyKey!==U?(w("all"),$(1)):H.sort!==x.sort&&$(1),D.current={query:n,filterOnlyKey:U,sort:x.sort}},[n,U,x.sort]),g.useEffect(()=>{let H=!1;return A(!0),G(""),(async()=>{try{let Z;if(e.searchAll)Z=await e.searchAll(n,zs,x);else{const ke=["work","book","collection","entity"],ie=await Promise.all(ke.map(B=>e.search(n,B,{page:1,pageSize:zs,filters:x})));Z={works:ie[0].entries,books:ie[1].entries,collections:ie[2].entries,entities:ie[3].entries,totalWorks:ie[0].total,totalBooks:ie[1].total,totalCollections:ie[2].total,totalEntities:ie[3].total}}H||T(Z)}catch(Z){H||(G(Z instanceof Error?Z.message:String(Z)),T(null))}finally{H||A(!1)}})(),()=>{H=!0}},[e,n,X]);const xe=b;g.useEffect(()=>{if(b==="all"){P(null);return}let H=!1;return A(!0),(async()=>{try{const Z=await e.search(n,b,{page:k,pageSize:nr,filters:x});H||P({key:xe,entries:Z.entries,total:Z.total})}catch(Z){H||(G(Z instanceof Error?Z.message:String(Z)),P(null))}finally{H||A(!1)}})(),()=>{H=!0}},[e,n,X,b,k]);const Y=M&&M.key===xe?M:null;g.useEffect(()=>{if(b==="all"||!Y||N)return;const H=Math.min(Y.total,En),Z=Pu(k,H,nr);Y.entries.length===0&&H>0&&Z!==k&&($(Z),p==null||p(Z))},[b,Y,N,k]);const E=g.useMemo(()=>Ns.filter(H=>an(z,H)>0),[z]),Te=E.reduce((H,Z)=>H+an(z,Z),0),ce=E.some(H=>an(z,H)>=En)?`${Te.toLocaleString()}+`:Te.toLocaleString(),me=!N&&!W&&z!==null&&Te===0,se=g.useCallback(H=>{w(H),$(1),d==null||d(H)},[d]),We=g.useMemo(()=>{const H=[];return x.dynasty.forEach(Z=>H.push({name:Z,remove:()=>o({...x,dynasty:x.dynasty.filter(ke=>ke!==Z)})})),x.classification.forEach(Z=>{var ke;return H.push({name:Z?((ke=Ci.find(ie=>ie.value===Z))==null?void 0:ke.label)??Z:h.searchPage.unclassified,remove:()=>o({...x,classification:x.classification.filter(ie=>ie!==Z)})})}),x.hasImage&&H.push({name:u.hasImage,remove:()=>o({...x,hasImage:!1})}),x.hasText&&H.push({name:u.hasText,remove:()=>o({...x,hasText:!1})}),x.hasCollated&&H.push({name:u.hasCollated,remove:()=>o({...x,hasCollated:!1})}),x.loss&&H.push({name:`${u.extant}:${h.searchPage.loss[x.loss]}`,remove:()=>o({...x,loss:""})}),H},[x,o,u,h]),J={query:n,onEntryLinkClick:s,typeName:a},re=H=>v==="table"?t.jsx(Cs,{entries:H,...J}):t.jsx(Ts,{entries:H,...J}),de=Ns.flatMap(H=>ir(z,H));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:Ou}),f&&t.jsx(Lu,{filters:x,onChange:o}),t.jsxs("div",{className:"bim-sr-main","aria-busy":N,ref:_,children:[E.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":h.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${r("rule")}`},children:[t.jsxs(Is,{on:b==="all",onClick:()=>se("all"),children:[h.search.allTab," ",t.jsx("small",{children:ce})]}),E.map(H=>t.jsxs(Is,{on:b===H,onClick:()=>se(H),children:[a(H)," ",t.jsx("small",{children:ci(an(z,H))})]},H))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":m(u.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!x.sort,onClick:()=>o({...x,sort:""}),children:m(u.sortRelevance)}),["era","title"].map(H=>{const Z=x.sort.startsWith(`${H}:`)?x.sort.endsWith("desc")?"desc":"asc":null,ke=H==="era"?u.sortEra:u.sortTitle,ie=H==="era"?Z==="desc"?u.sortEraDesc:u.sortEraAsc:Z==="desc"?u.sortTitleDesc:u.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":Z!==null,title:m(ie),onClick:()=>o({...x,sort:`${H}:${Z==="asc"?"desc":"asc"}`}),children:[m(ke),Z?t.jsxs("span",{"aria-hidden":"true",children:[" ",Z==="asc"?"↑":"↓"]}):null]},H)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":m(u.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":v==="table",onClick:()=>S("table"),children:m(u.viewTable)}),t.jsx("button",{type:"button","aria-pressed":v==="card",onClick:()=>S("card"),children:m(u.viewCard)})]})]}),le&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:m(gt(u.filteredCount,{n:ce}))}),We.map(H=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":m(gt(u.removeFilter,{name:H.name})),onClick:H.remove,children:[m(H.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},H.name))]}),W&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:W}),me&&t.jsx("div",{className:"bim-sr-empty",children:m(le?u.emptyFiltered:gt(h.search.noResultsFor,{query:n}))}),!W&&!me&&b==="all"&&z&&(v==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Cs,{entries:de,...J}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:m(u.limitedNote)})]}):t.jsx(t.Fragment,{children:E.map(H=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(jn,{type:H,size:8}),a(H),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r("meta-fg")},children:[ci(an(z,H))," ",h.unit.items]})]}),an(z,H)>ir(z,H).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>se(H),children:h.action.viewAll})]}),t.jsx(Ts,{entries:ir(z,H),...J})]},H))})),!W&&b!=="all"&&!Y&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:h.search.loading}),!W&&b!=="all"&&Y&&Y.entries.length>0&&t.jsxs(t.Fragment,{children:[re(Y.entries),t.jsx(Bu,{page:k,pageSize:nr,total:Math.min(Y.total,En),totalLabel:ci(Y.total),onPage:L})]}),!W&&b!=="all"&&Y&&Y.entries.length===0&&!N&&t.jsxs("div",{className:"bim-sr-empty",children:[m(le?u.emptyFiltered:gt(h.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>se("all"),children:h.search.allTab})})]})]})]})};function Is({on:e,onClick:n,children:i}){return t.jsx("button",{type:"button","aria-pressed":e,onClick:n,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:r(e?"ink":"meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${r("accent")}`:"none"},children:i})}const un="bim-recent-ids",Rs="bim-recent-entries",Es=50;function Ut(){try{const e=localStorage.getItem(un);if(e)return JSON.parse(e);const n=localStorage.getItem(Rs);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(un,JSON.stringify(i)),localStorage.removeItem(Rs),i}return[]}catch{return[]}}function vr(e){try{const n=Ut().filter(i=>i!==e);n.unshift(e),n.length>Es&&(n.length=Es),localStorage.setItem(un,JSON.stringify(n))}catch{}}function kl(e){try{const n=Ut().filter(i=>i!==e);localStorage.setItem(un,JSON.stringify(n))}catch{}}function Qr(){try{localStorage.removeItem(un)}catch{}}async function eo(e,n){var i,o,s;try{if(e.getEntry){const l=await e.getEntry(n);if(l)return l}const a=await e.getItem(n);if(a){const l=a.authors;return{id:n,title:a.title||n,type:a.type||"work",author:(i=l==null?void 0:l[0])==null?void 0:i.name,dynasty:(o=l==null?void 0:l[0])==null?void 0:o.dynasty,role:(s=l==null?void 0:l[0])==null?void 0:s.role,edition:a.edition||void 0}}}catch{}return{id:n,title:n,type:"work",notFound:!0}}const rr=5,qu=50,Ku=200,Ls={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},kr=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:p,resultVariant:h="compact",renderEntry:u,initialQuery:m,onQueryChange:f,headerRight:x,reserveViewportHeight:v=!1,filtersEnabled:y=!1,filters:S=_i,onFiltersChange:b,resultTab:w,onResultTabChange:j,resultPage:k,onResultPageChange:$})=>{const C=Ee(),_=[{type:"work",name:C.indexType.work,key:"works"},{type:"book",name:C.indexType.book,key:"books"},{type:"collection",name:C.indexType.collection,key:"collections"},{type:"entity",name:C.indexType.entity,key:"entities"}],L=["work","collection","book","entity"],[z,T]=g.useState(m??""),[M,P]=g.useState(null),[N,A]=g.useState(m??""),W=gi(S).toString(),[G,X]=g.useState(S);g.useEffect(()=>{X(S)},[W]);const le=I=>{X(I),b==null||b(I)},[U,D]=g.useState(null),[xe,Y]=g.useState("all"),[E,Te]=g.useState(!1),[ce,me]=g.useState(null),[se,We]=g.useState(""),[J,re]=g.useState(!(m!=null&&m.trim())),[de,H]=g.useState(Ut),[Z,ke]=g.useState([]),[ie,B]=g.useState(!1),[Q,ae]=g.useState(!1),[je,q]=g.useState(null),[be,Le]=g.useState(null),Fe=g.useRef(void 0),O=g.useRef(!1),ee=g.useCallback(async(I,V)=>{if(!I.trim()){re(!0),P(null),D(null);return}if(re(!1),y){A(I);return}Te(!0),We("");try{if(e.searchAll){const ue=await e.searchAll(I,V??rr);P(ue)}else{const ue=["work","book","collection","entity"],$e=await Promise.all(ue.map(ye=>e.search(I,ye,{page:1,pageSize:V??rr})));P({works:$e[0].entries,books:$e[1].entries,collections:$e[2].entries,entities:$e[3].entries,totalWorks:$e[0].total,totalBooks:$e[1].total,totalCollections:$e[2].total,totalEntities:$e[3].total})}}catch(ue){We(ue instanceof Error?ue.message:String(ue)),P(null)}finally{Te(!1)}},[e,y]);g.useEffect(()=>{let I=!1;const V=()=>{var Ve,te;const ue=["work","book","collection","entity"],$e=Promise.all(ue.map(ve=>e.loadEntries(ve,{page:1,pageSize:1}).catch(()=>({total:0})))),ye=((Ve=e.getResourceCounts)==null?void 0:Ve.call(e).catch(()=>null))??Promise.resolve(null),he=((te=e.getSubtypeStats)==null?void 0:te.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([$e,ye,he]).then(([ve,Me,Oe])=>{I||(q({works:ve[0].total,books:ve[1].total,collections:ve[2].total,entities:ve[3].total,hasText:Me==null?void 0:Me.hasText,hasImage:Me==null?void 0:Me.hasImage}),Oe&&Le(Oe))})};return e.getCounts?e.getCounts().then(ue=>{var $e,ye;I||(q({works:ue.works,books:ue.books,collections:ue.collections,entities:ue.entities,hasText:($e=ue.resourceCounts)==null?void 0:$e.hasText,hasImage:(ye=ue.resourceCounts)==null?void 0:ye.hasImage}),ue.subtypeStats&&Le(ue.subtypeStats))}).catch(()=>{I||V()}):V(),()=>{I=!0}},[e]),g.useEffect(()=>{O.current||!(m!=null&&m.trim())||(O.current=!0,ee(m))},[m,ee]);const _e=g.useCallback(I=>{if(T(I),!I.trim()){f==null||f(I),re(!0),P(null),D(null),Y("all");return}Fe.current&&clearTimeout(Fe.current),Fe.current=setTimeout(()=>{D(null),Y("all"),f==null||f(I),ee(I)},Ku)},[ee,f]),ze=g.useCallback(I=>{Fe.current&&clearTimeout(Fe.current),Y("all"),f==null||f(I),ee(I)},[ee,f]),F=g.useCallback(I=>{D(I),ee(z,qu)},[z,ee]);g.useEffect(()=>{if(!de.length){ke([]);return}let I=!1;return B(!0),Promise.all(de.slice(0,10).map(V=>eo(e,V))).then(V=>{I||(ke(V),B(!1))}),()=>{I=!0}},[de,e]);const fe=I=>{me(I.id),vr(I.id),H(Ut()),o==null||o(I)},oe=(I,V)=>{if(o&&Zu(V)){V.preventDefault(),fe(I);return}vr(I.id),H(Ut())},we=I=>{kl(I),H(Ut())},Ae=()=>{Qr(),H([])},He=I=>_.find(V=>V.type===I),Ge=!J&&!M&&!se,Ye=M&&(M.works.length>0||M.books.length>0||M.collections.length>0),Xe=t.jsxs(t.Fragment,{children:[t.jsx(ul,{transport:e,value:z,onChange:_e,onSearch:ze,onEntrySelect:fe}),y&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const I=z.trim();I&&pl(I),ze(z)},children:C.searchPage.submit}),s&&t.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:`1px solid ${r("primary")}`,borderRadius:"6px",background:"transparent",color:r("primary"),cursor:"pointer",fontSize:"13px"},children:C.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:v?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:Ju+(y?Qu:"")}),(!y||x||!p)&&t.jsx("header",{style:{padding:"12px 20px",borderBottom:`1px solid ${r("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[y?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:r("fg")},children:C.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[x,!p&&t.jsx(dl,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),y?t.jsxs("div",{className:"bim-ib-bar","data-nofilters":e.supportsSearchFilters?void 0:"true",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("div",{className:"bim-ib-bar-main",children:Xe})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:Xe}),J&&t.jsx("div",{className:"bim-ib-stats",style:{padding:"0 20px 8px",fontSize:"12px",color:r("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:je&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:be?t.jsxs(t.Fragment,{children:[(be.book??0)>0&&t.jsxs(t.Fragment,{children:[C.searchPage.statBook," ",t.jsx("strong",{style:{color:r("fg")},children:be.book.toLocaleString()})," ",C.unit.bu,C.searchPage.statComma,t.jsx("strong",{style:{color:r("fg")},children:je.books.toLocaleString()})," ",C.searchPage.statBookCopies]}),be.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),C.searchPage.statArticle," ",t.jsx("strong",{style:{color:r("fg")},children:be.article.toLocaleString()})," ",C.searchPage.statArticleUnit]}):null,be.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),C.searchPage.statPoem," ",t.jsx("strong",{style:{color:r("fg")},children:be.poem.toLocaleString()})," ",C.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),C.searchPage.statCollection," ",t.jsx("strong",{style:{color:r("fg")},children:je.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[C.indexType.work," ",t.jsx("strong",{style:{color:r("fg")},children:je.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),C.indexType.book," ",t.jsx("strong",{style:{color:r("fg")},children:je.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),C.indexType.collection," ",t.jsx("strong",{style:{color:r("fg")},children:je.collections.toLocaleString()}),je.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),C.indexType.entity," ",t.jsx("strong",{style:{color:r("fg")},children:je.entities.toLocaleString()})]})]})}),je.hasImage!=null&&je.hasText!=null&&t.jsxs("span",{children:[C.resourceType.image," ",t.jsx("strong",{style:{color:r("fg")},children:je.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),C.resourceType.text," ",t.jsx("strong",{style:{color:r("fg")},children:je.hasText.toLocaleString()})]})]})}),y&&!J&&t.jsx(vl,{transport:e,query:N,filters:G,onFiltersChange:le,onEntryLinkClick:oe,typeName:I=>He(I).name,tab:w,onTabChange:j,page:k,onPageChange:$}),!(y&&!J)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:E||Ge?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg"),minHeight:Xu,boxSizing:"border-box"},children:C.search.searching}):se?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r("desc-fg")},children:se})}):J?t.jsx("div",{style:{flex:1},children:ie?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg")},children:C.search.loading}):Z.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:r("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:C.search.recentBrowse}),t.jsx("button",{onClick:Ae,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:C.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Z.slice(0,Q?10:3).map(I=>I.notFound?t.jsx(im,{id:I.id,onRemove:we,t:C},I.id):t.jsx(As,{entry:I,selected:ce===I.id,onClick:oe,getConfig:He,onRemove:we},I.id))}),!Q&&Z.length>3&&t.jsx("button",{onClick:()=>ae(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:r("primary"),background:"transparent",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:C.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r("fg")},children:C.search.searchTitle}),t.jsx("p",{style:{color:r("desc-fg"),fontSize:"13px"},children:C.search.searchSubtitle})]})}):Ye?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:em}),(()=>{const I=he=>M[Ls[he]]??0,V=L.map(he=>_.find(Ve=>Ve.type===he)).filter(he=>I(he.key)>0);if(V.length<2)return null;const ue=V.reduce((he,Ve)=>he+I(Ve.key),0),$e=he=>{if(Y(he),he!=="all"&&U!==he){const Ve=_.find(ve=>ve.type===he),te=(M[Ve.key]??[]).length;I(Ve.key)>te&&F(he)}},ye=he=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:r(he?"fg":"desc-fg"),fontWeight:he?700:400,boxShadow:he?`inset 0 -2px 0 ${r("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":C.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":xe==="all",style:ye(xe==="all"),onClick:()=>$e("all"),children:[C.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ue.toLocaleString()})]}),V.map(he=>t.jsxs("button",{type:"button","aria-pressed":xe===he.type,style:ye(xe===he.type),onClick:()=>$e(he.type),children:[he.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:I(he.key).toLocaleString()})]},he.type))]})})(),_.map(({type:I,name:V,key:ue})=>{const $e=M[ue]??[],ye=Ls[ue],he=M[ye]??0;if($e.length===0||xe!=="all"&&xe!==I)return null;const te=xe==="all"&&!(U===I)&&he>rr;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${r("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:[t.jsx(jn,{type:I})," ",V,t.jsxs("span",{style:{fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:[he," ",C.unit.items]})]}),te&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>F(I),style:{border:"none",background:"transparent",color:r("primary"),cursor:"pointer",fontSize:"12px"},children:C.action.viewAll})]}),t.jsx("div",{style:h==="list"?{display:"flex",flexDirection:"column",gap:0}:h==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:$e.map(ve=>{if(u)return t.jsx(g.Fragment,{children:u(ve)},ve.id);const Me=h==="card"?nm:As;return t.jsx(Me,{entry:ve,selected:ce===ve.id,onClick:oe,getConfig:He,query:z},ve.id)})})]},I)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r("fg")},children:gt(C.search.noResultsFor,{query:z})}),t.jsx("p",{style:{color:r("desc-fg"),fontSize:"13px"},children:C.search.tryOther})]})})]})},Xu=240;function Zu(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Ju=`
121
121
  .bim-ib-stats { min-height: 25px; box-sizing: content-box; }
122
122
  @media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
123
- `,em=`
123
+ `,Qu=`
124
124
  .bim-ib-bar { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; padding: 0 20px 16px; }
125
125
  .bim-ib-bar[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
126
126
  .bim-ib-bar[data-nofilters] > [aria-hidden] { display: none; }
@@ -135,20 +135,20 @@
135
135
  .bim-ib-bar-main { max-width: none; }
136
136
  .bim-ib-submit { min-height: 44px; padding: 0 16px; }
137
137
  }
138
- `,tm=`
138
+ `,em=`
139
139
  @media (max-width: 719px), (pointer: coarse) {
140
140
  .bim-ib-viewall { position: relative; }
141
141
  .bim-ib-viewall::after {
142
142
  content: ""; position: absolute; left: 50%; top: 50%;
143
143
  width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
144
144
  }
145
- }`,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=`
145
+ }`,wl={color:"inherit",textDecoration:"none"},tm=({snippet:e})=>{const{convert:n}=Be();return t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.6},children:Vr(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(g.Fragment,{children:n(i.text)},o))})},nm=({entry:e,selected:n,onClick:i,getConfig:o,query:s})=>{const a=Ee(),{convert:l}=Be(),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||[]],h=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"),m=tt();return t.jsxs("a",{href:m(e.id),onClick:f=>i(e,f),className:"bim-result-card",style:{...wl,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)})]}),h&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg")},children:[a.search.alias,":",l(typeof h=="string"?h:h.book_title||"")]}),e.descriptionSnippet&&t.jsx(tm,{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})]})]})]})},As=({entry:e,selected:n,onClick:i,getConfig:o,query:s,onRemove:a})=>{const l=Ee(),{convert:d}=Be(),c=[...e.additional_titles||[],...e.attached_texts||[]],p=s&&c.length?c.find(u=>{const m=typeof u=="string"?u:u==null?void 0:u.book_title;return m==null?void 0:m.toLowerCase().includes(s.toLowerCase())}):void 0,h=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:h(e.id),onClick:u=>i(e,u),className:"bim-result-card",style:{...wl,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:"×"})]})},im=({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 rm(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 om({data:e}){const{convert:n}=Be(),{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 sm({alt_names:e}){const{convert:n}=Be(),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 am({data:e}){const n=Ee(),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 lm({works:e,transport:n,onNavigate:i,renderLink:o}){const s=Ee(),{convert:a}=Be(),l=tt(),[d,c]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let m=!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 $=w[k];$!=null&&$.title?v.set(f[k],$.title):$!=null&&$.primary_name?v.set(f[k],$.primary_name):j=!1}if(j)return v}catch{}const y=[...f],S=8,b=new Array(S).fill(0).map(async()=>{for(;y.length;){const w=y.shift();if(!w)break;if(!v.has(w))try{if(n.getEntry){const $=await n.getEntry(w);if($!=null&&$.title){v.set(w,$.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=>{m||c(v)}),()=>{m=!0}},[e,n]);const p=new Map;for(const m of e){const f=m.role||"";p.has(f)||p.set(f,[]),p.get(f).push(m)}const h=["撰","編","注","輯","集","校","評","譯","述","作",""],u=[...p.keys()].sort((m,f)=>{const x=h.indexOf(m),v=h.indexOf(f);return x===-1&&v===-1?m.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(m=>{const f=p.get(m);return t.jsxs("div",{style:{marginBottom:"8px"},children:[m&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"2px"},children:[a(m)," ",t.jsxs("span",{style:{color:r("desc-fg")},children:["(",f.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:m?"16px":"0",listStyle:m?"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:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),i(x.work_id))},style:{color:r("link-fg"),textDecoration:"underline",cursor:"pointer"},children:y})},v):t.jsx("li",{children:y},v)})})]},m)})]})}const Sl=({data:e,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:a})=>{var u;const l=Ee(),{convert:d}=Be();let c=!1;try{c=Se.extractStatus(e.id)==="draft"}catch{}const p=rm(e),h=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(om,{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}),h&&e.subtype!=="people"&&t.jsx("span",{children:h}),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(sm,{alt_names:e.alt_names}),t.jsx(am,{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(lm,{works:e.works,transport:n,onNavigate:i,renderLink:o})]})},cm=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function dm(e){const n=e.search(cm);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===pm(e))){const[a,l]=dm(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 pm(e){try{return decodeURI(e)}catch{return e}}const um={..._l,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},Pt=({text:e,plainStrong:n,style:i,className:o})=>{const{convert:s}=Be(),a=n?um:_l;return t.jsx("div",{className:o,style:i,children:t.jsx(Mp,{remarkPlugins:[Pp],components:a,children:s(e)})})},mm=["〇","一","二","三","四","五","六","七","八","九"],Ms=["","十","百","千"];function $l(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+=Ms[d]:o+=mm[l]+Ms[d])}return o}function Cl(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 gm({type:e}){const n=Ee();return t.jsx("span",{style:Cl(hm[e]),children:n.indexType[e]})}function fm({isDraft:e}){const n=Ee(),i=r(e?"status-draft":"status-official");return t.jsx("span",{style:Cl(i),children:e?n.status.draft:n.status.official})}function xm({id:e}){const n=Ee(),[i,o]=g.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 xt({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 Tl({authors:e,type:n,onNavigate:i,renderLink:o}){const{convert:s}=Be();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 bm({id:e,title:n,edition:i,type:o,isDraft:s,authors:a,volumeText:l,meta:d,headerExtra:c,onNavigate:p,renderLink:h}){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(gm,{type:o}),t.jsx(fm,{isDraft:s}),t.jsx(xm,{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(Tl,{authors:a,type:o,onNavigate:p,renderLink:h}),d]})]})}function zl({items:e,label:n,showMeta:i,onNavigate:o,renderLink:s}){const a=Ee(),{convert:l}=Be();if(!e.length)return null;const[d,c]=g.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((p,h)=>{const u=d===h;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:h),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:m=>m.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)})]})]})]},h)})})]})}function ym({items:e,onNavigate:n,renderLink:i}){const o=Ee();return t.jsx(zl,{items:e,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Nl({items:e,onNavigate:n,renderLink:i}){const o=Ee();return t.jsx(zl,{items:e,label:o.section.emendated,onNavigate:n,renderLink:i})}function Il({label:e,items:n}){const{convert:i}=Be();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(xt,{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 jm({items:e}){const n=Ee();return t.jsx(Il,{label:n.section.aliases,items:e})}function vm({items:e}){const n=Ee();return t.jsx(Il,{label:n.section.attachedTexts,items:e})}function km({items:e}){const n=Ee(),{convert:i}=Be();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(xt,{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 wm({items:e}){const n=Ee(),{convert:i}=Be();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(xt,{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 Sm({items:e}){const n=Ee(),{convert:i}=Be();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(xt,{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 Ps({title:e,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:a}=Be(),[l,d]=g.useState([]);return g.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(h=>({id:p,title:h?h.title:void 0,edition:h?h.edition:void 0,type:h?h.type:void 0})).catch(()=>({id:p})))).then(p=>{c||d(p)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(xt,{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 or({book:e,onNavigate:n,renderLink:i}){const o=Ee(),{convert:s}=Be(),[a,l]=g.useState(!1),d=e.resources&&e.resources.length>0,c=e.edition?s(e.edition):s(e.title)||void 0;return t.jsxs("div",{style:{border:`1px solid ${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(Zr,{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=Ee(),{convert:d}=Be(),[c,p]=g.useState([]);if(g.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 h=c.length?c:e.map(x=>({id:x})),u=new Map(h.map(x=>[x.id,x])),m=n==null?void 0:n.version_graph,f=$m(e,m,l.common.otherVersions);return t.jsxs(t.Fragment,{children:[t.jsxs(xt,{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(or,{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(or,{book:y,onNavigate:o,renderLink:s},v):null})})]},x.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:h.map(x=>t.jsx(or,{book:x,onNavigate:o,renderLink:s},x.id))})]})}function $m(e,n,i){var S,b;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const o=(S=n.collections)==null?void 0:S[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]),h=w=>{if(p.has(w))return!0;const j=n.node_groups[w];return j!=null&&c.has(j)},u=[],m=new Map,f=[];for(const w of e)if(!((b=n.excluded_books)!=null&&b.includes(w)))if(h(w))u.push(w);else{const j=n.node_groups[w];j?(m.has(j)||m.set(j,[]),m.get(j).push(w)):f.push(w)}if(f.length+[...m.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=[...m.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 Cm({workData:e,onNavigate:n,renderLink:i}){var l,d,c,p;const o=Ee(),{convert:s}=Be(),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:[$l(e.juan_count.number),o.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(Tl,{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 Tm({items:e,onNavigate:n,renderLink:i}){const o=Ee(),{convert:s}=Be();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:gt(o.catalog.volume,{n:a.volume_index})})]},a.id))}):null}const to=({data:e,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:a,relatedBooksFooter:l,className:d,style:c})=>{var M,P,N,A,W,G,X,le;const p=Ee(),{convert:h}=Be(),[u,m]=g.useState(null),[f,x]=g.useState(!1),[v,y]=g.useState(null),[S,b]=g.useState(null),[w,j]=g.useState([]),k=e||u;if(g.useEffect(()=>{if(e||!n||!i)return;let U=!1;return x(!0),y(null),i.getItem(n).then(D=>{U||(D?m(D):y(p.misc.notFoundEntry))}).catch(D=>{U||y(D instanceof Error?D.message:p.misc.loadFailed)}).finally(()=>{U||x(!1)}),()=>{U=!0}},[e,n,i]),g.useEffect(()=>{if(!k||!i){b(null),j([]);return}let U=!1;const D=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(D?i.getItem(D).then(xe=>{!U&&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(Y=>{const E=typeof Y=="string"?Y:Y.id,Te=typeof Y=="string"?void 0:Y.volume_index;return i.getItem(E).then(ce=>({id:E,title:ce&&ce.title||E,volume_index:Te})).catch(()=>({id:E,title:E,volume_index:Te}))})).then(Y=>{U||j(Y)}):j([])}else j([]);return()=>{U=!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((U,D)=>t.jsx("div",{style:{height:D===1?"32px":"16px",width:`${U}px`,background:r("widget-border"),borderRadius:"4px",opacity:.4}},D))})});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(Sl,{data:k,transport:i,onNavigate:o,renderLink:s,headerExtra:a})});const $=k.type==="book"?k:null,C=k.type==="collection"?k:null,_=k.type==="work"?k:null;let L=!1;try{L=Se.extractStatus(k.id)==="draft"}catch{}let z="";k.measure_info?z=h(k.measure_info):(M=k.juan_count)!=null&&M.number?z=$l(k.juan_count.number)+p.unit.juan:(P=k.juan_count)!=null&&P.description&&(z=h(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:h(k.current_location.name)},"loc")),(W=k.page_count)!=null&&W.description&&T.push(t.jsx($t,{label:p.label.pageCount,children:k.page_count.description},"page")),$!=null&&$.edition&&T.push(t.jsx($t,{label:p.label.edition,children:h($.edition)},"ver")),_!=null&&_.parent_work&&T.push(t.jsx($t,{label:p.label.parentWork,children:t.jsx(wt,{id:_.parent_work.id,label:h(_.parent_work.title),onNavigate:o,renderLink:s})},"pw")),_!=null&&_.parent_works&&_.parent_works.length>0&&!_.parent_work&&T.push(t.jsx($t,{label:p.label.parentWork,children:_.parent_works.map((U,D)=>t.jsxs("span",{children:[D>0&&"、",t.jsx(wt,{id:U,onNavigate:o,renderLink:s})]},U))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(bm,{id:k.id,title:h(k.title),edition:k.edition?h(k.edition):void 0,type:k.type,isDraft:L,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((U,D)=>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:h(U.title)}),t.jsx(Pt,{text:U.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:r("fg")}})]},D))}),w.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:p.section.containedIn}),t.jsx(Tm,{items:w,onNavigate:o,renderLink:s})]}),S&&t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:p.section.belongsToWork}),t.jsx(Cm,{workData:S,onNavigate:o,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&t.jsx(km,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&t.jsx(jm,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&t.jsx(vm,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&t.jsx(ym,{items:k.indexed_by,onNavigate:o,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&t.jsx(Nl,{items:k.emendated_by,onNavigate:o,renderLink:s}),k.resources&&k.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(xt,{children:p.section.resources}),t.jsx(Zr,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),($==null?void 0:$.location_history)&&$.location_history.length>0&&t.jsx(wm,{items:$.location_history}),(C==null?void 0:C.history)&&C.history.length>0&&t.jsx(Sm,{items:C.history}),($==null?void 0:$.related_books)&&$.related_books.length>0&&t.jsx(Ps,{title:p.section.relatedVersions,ids:$.related_books,transport:i,onNavigate:o,renderLink:s}),(C==null?void 0:C.books)&&C.books.length>0&&t.jsx(Ps,{title:p.section.containedBooks,ids:C.books,transport:i,onNavigate:o,renderLink:s}),(C==null?void 0:C.contained_works)&&C.contained_works.length>0&&t.jsxs("div",{children:[t.jsxs(xt,{children:[p.section.containedWorks,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",C.contained_works.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:C.contained_works.map(U=>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:U.id,label:h(U.title),onNavigate:o,renderLink:s})},U.id))})]}),(((X=_==null?void 0:_.books)==null?void 0:X.length)||0)+(((le=_==null?void 0:_.collections)==null?void 0:le.length)||0)>0&&t.jsx(_m,{ids:[...(_==null?void 0:_.books)||[],...(_==null?void 0:_.collections)||[]],workData:_??void 0,transport:i,onNavigate:o,renderLink:s,footer:l}),(_==null?void 0:_.related_works)&&_.related_works.length>0&&(()=>{const U=[],D=_.related_works.filter(me=>me.relation==="part_of"),xe=_.related_works.filter(me=>me.relation==="has_part"),Y=_.related_works.filter(me=>me.relation==="has_adaptation"),E=_.related_works.filter(me=>me.relation==="text_carried_by"),Te=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ce=_.related_works.filter(me=>!me.relation||!Te.has(me.relation));return D.length>0&&U.push({label:p.section.belongsToWork,items:D}),xe.length>0&&U.push({label:p.section.containedWorks,items:xe}),Y.length>0&&U.push({label:p.section.adaptations,items:Y}),E.length>0&&U.push({label:p.section.derivativeWorks,items:E}),ce.length>0&&U.push({label:p.section.relatedWorks,items:ce}),U.map(me=>t.jsxs("div",{children:[t.jsxs(xt,{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:h(se.title),onNavigate:o,renderLink:s})},se.id))})]},me.label))})()]})};function zm({data:e}){const n=Ee(),{convert:i}=Be(),{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 Nm({sections:e,activeSection:n,onSelect:i}){const o=Ee();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:Bs(n===null),children:o.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:Bs(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 Bs(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 Im({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 Rm(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 Ws({book:e,onNavigate:n,renderLink:i,showVolumes:o}){const s=Ee(),{convert:a}=Be(),l=e.book_id||e.work_id,d=o&&e.volumes.length>0?Rm(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(Im,{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 no=({data:e,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:a,style:l})=>{const d=Ee(),[c,p]=g.useState(null),[h,u]=g.useState(!1),[m,f]=g.useState(null),[x,v]=g.useState(null),[y,S]=g.useState(""),b=e||c;g.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let C=!1;return u(!0),f(null),i.getCollectionCatalog(n).then(_=>{C||(_?p(_):f(d.catalog.notFound))}).catch(_=>{C||f(_ instanceof Error?_.message:d.catalog.loadFailed)}).finally(()=>{C||u(!1)}),()=>{C=!0}},[e,n,i,d]);const w=(b==null?void 0:b.sections)&&b.sections.length>0,j=g.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const C=b.books.map(L=>L.volumes[0]).filter(L=>L!=null);return new Set(C).size<C.length},[b]),k=g.useMemo(()=>{if(!b)return[];let C=b.books;if(x&&(C=C.filter(_=>_.section===x)),y.trim()){const _=y.trim().toLowerCase();C=C.filter(L=>L.title.toLowerCase().includes(_)||L.sub_items&&L.sub_items.some(z=>z.toLowerCase().includes(_))||L.edition&&L.edition.toLowerCase().includes(_))}return C},[b,x,y]),$=g.useMemo(()=>{if(!j)return null;const C=[],_=new Map;for(const z of k){if(!z.volumes||z.volumes.length===0)continue;const T=z.volumes[0];_.has(T)||_.set(T,[]),_.get(T).push(z)}const L=[..._.keys()].sort((z,T)=>z-T);for(const z of L)C.push({volume:z,books:_.get(z)});return C},[k,j]);return h?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:r("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):m?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:m}):b?t.jsxs("div",{className:a,style:l,children:[t.jsx(zm,{data:b}),w&&t.jsx(Nm,{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:C=>S(C.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:[$?$.map((C,_)=>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:gt(d.catalog.volume,{n:C.volume})}),C.books.map((L,z)=>t.jsx(Ws,{book:L,onNavigate:o,renderLink:s,showVolumes:L.volumes.length>1},`${C.volume}-${z}`))]},`${C.volume}-${_}`)):k.map((C,_)=>t.jsx(Ws,{book:C,onNavigate:o,renderLink:s,showVolumes:!0},_)),k.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},sr=e=>e?e.catch(()=>null):Promise.resolve(null);function Rl(e){const n=new Map;function i(o){var a;let s=n.get(o);return s||(s=sr((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 Se.isSafeSegment(o)?i(o):Promise.resolve(null)},async getIndex(o,s){return!Se.isSafeSegment(o)||!Se.isSafeSegment(s)||!e.getTextIndex?null:sr(e.getTextIndex(o,s))},async getChapter(o,s,a,l){return!Se.isSafeSegment(o)||!Se.isSafeSegment(s)||!Se.isSafeSegment(a)||!e.getChapter?null:sr(e.getChapter(o,s,a,l))}}}const nn=()=>{const{t:e}=ne(),[n,i]=g.useState(1);return g.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)})},ar=String.raw`https?:\/\/[^\s()()<>"]+`,Em=new RegExp(String.raw`\[([^\]\n]+)\]\((${ar})\)`+String.raw`|(《[^》\n]+》)\s?[((](${ar})[))]`+`|(${ar})`,"g");function Lm(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Am(e){const n=[];let i=0;for(const o of e.matchAll(Em)){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:Lm(o[5]),url:o[5]}),i=s+o[0].length}return i<e.length&&n.push({text:e.slice(i)}),n}function El({text:e,convert:n,className:i="bim-rd-link"}){return t.jsx(t.Fragment,{children:Am(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(g.Fragment,{children:n(o.text)},s))})}const Ll="(min-width: 1100px)",Al="(max-width: 719px)",Ml="(max-width: 859px)",Mm=`${Al}, (pointer: coarse)`,_t=r("reader-top"),Pm="48px",Pl=`
146
146
  .bim-rd {
147
147
  position: relative;
148
148
  background: ${r("page-bg")};
149
149
  color: ${r("ink")};
150
150
  font-family: ${r("font-ui")};
151
- --bimrd-bar-h: ${Bm};
151
+ --bimrd-bar-h: ${Pm};
152
152
  /* 设置侧栏的暖黄:与朱/靛/墨三套主色都不冲,只做底色与选中态 */
153
153
  --bimrd-warm: ${r("reader-warm")};
154
154
  --bimrd-warm-bg: color-mix(in srgb, var(--bimrd-warm) 8%, ${r("page-bg")});
@@ -441,7 +441,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
441
441
  .bim-rd-sheet-head .bim-rd-t { margin-left: auto; min-width: 44px; min-height: 44px; justify-content: center; letter-spacing: 0; }
442
442
  .bim-rd-sheet-img { display: flex; flex-direction: column; gap: 8px; min-height: 40vh; }
443
443
  .bim-rd-sheet-img .bim-rd-img-fig img { max-height: 60vh; }
444
- @media ${Pl} {
444
+ @media ${Ml} {
445
445
  .bim-rd[data-bb] .bim-rd-text { padding-bottom: calc(56px + 64px + env(safe-area-inset-bottom, 0px)); }
446
446
  /* 底栏上已有的,工具条上不再重复(目录、字号) */
447
447
  .bim-rd[data-bb] .bim-rd-bb-dup { display: none !important; }
@@ -486,7 +486,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
486
486
 
487
487
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
488
488
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
489
- @media ${Pm} {
489
+ @media ${Mm} {
490
490
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
491
491
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
492
492
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -499,7 +499,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
499
499
  }
500
500
 
501
501
  /* ── 中屏以下:目录改抽屉 ── */
502
- @media not all and ${Al} {
502
+ @media not all and ${Ll} {
503
503
  .bim-rd-toc {
504
504
  position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
505
505
  width: min(86vw, 320px);
@@ -513,7 +513,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
513
513
  }
514
514
 
515
515
  /* ── 窄屏:书影收起,只留正文 ── */
516
- @media ${Ml} {
516
+ @media ${Al} {
517
517
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
518
518
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
519
519
  /* 工具条放不下时(版本、自然段、标出作品链接都在)在条内左右滑,不撑宽页面 */
@@ -658,7 +658,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
658
658
  .guji-text-char.is-lacuna { color: ${r("meta-fg")}; border: 1px dashed currentColor; border-radius: 2px; padding: 0 0.08em; } /* 阙文:虚线框□ */
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
- .guji-text-char.is-raised { display: inline-block; transform: translateY(-0.2em); } /* 抬头:本列首字高出一格 */
661
+ /* 抬头(is-raised/data-raised):横排重排里不做位移——原件的“高一格”在重排后只会显成首字偏高;类名和属性保留给结构识别 */
662
662
  .guji-text-blank-col { display: inline-block; width: 1em; height: 1px; } /* 空列:一格宽的空位 */
663
663
  .bim-rd-badge-warp {
664
664
  display: inline-flex;
@@ -673,15 +673,15 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
673
673
  letter-spacing: 0.05em;
674
674
  margin-left: 6px;
675
675
  }
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===`
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(`
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===`
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=`
681
- .bim-d-main.bim-d-main-grid { max-width: ${_g}px; padding: 16px 32px 0; }
676
+ `;function io(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(o=>io(o,n))):!1}const Bm=()=>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 Wm({item:e,activeKey:n,onSelect:i,tabKey:o}){const s=io(e,n),[a,l]=g.useState(s||!!e.defaultExpanded);return g.useEffect(()=>{s&&l(!0)},[s]),g.useEffect(()=>{e.defaultExpanded&&l(!0)},[e.defaultExpanded]),t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":a,"data-rd-toc-key":e.key,tabIndex:o===e.key?0:-1,onClick:()=>l(d=>!d),children:[t.jsx(Bm,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),a&&t.jsx(Bl,{items:e.children,activeKey:n,onSelect:i,tabKey:o})]})}function Bl({items:e,activeKey:n,onSelect:i,tabKey:o}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Wm,{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 Os(e,n){var i;for(const o of e)if(o.key===n||io(o,n))return o.key;return((i=e[0])==null?void 0:i.key)??null}function Wl({items:e,activeKey:n,onSelect:i,label:o}){const{t:s}=ne(),a=o??s("reader.toc"),l=g.useRef(null),[d,c]=g.useState(null);g.useEffect(()=>{c(null)},[n]);const p=g.useMemo(()=>d||(n??Os(e,n)),[d,n,e]);g.useEffect(()=>{const u=l.current;if(!u)return;const m=Array.from(u.querySelectorAll("[data-rd-toc-key]"));if(m.length===0)return;const f=m.find(x=>x.dataset.rdTocKey===p)??m.find(x=>x.dataset.rdTocKey===Os(e,n))??m.find(x=>!x.disabled)??m[0];for(const x of m)x.tabIndex=x===f?0:-1}),g.useEffect(()=>{const u=l.current,m=u==null?void 0:u.closest(".bim-rd-toc");if(!u||!m||!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-m.getBoundingClientRect().top+m.scrollTop;(x<m.scrollTop+80||x>m.scrollTop+m.clientHeight-40)&&(m.scrollTop=Math.max(0,x-m.clientHeight/3))},[n]);const h=g.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 S=x[y];for(const b of x)b.tabIndex=-1;S.tabIndex=0,S.focus(),c(S.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:h,children:t.jsx(Bl,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function Fs({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 Om(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)),h=Math.min(o,Math.max(0,a-c)),u=Math.min(i,Math.max(0,l+c))-p,m=Math.min(o,Math.max(0,d+c))-h;return!(u>0)||!(m>0)||u>=i*.98&&m>=o*.98?null:{x:p,y:h,w:u,h:m}}function wr({pages:e,loading:n,page:i,onPageChange:o,renderOverlay:s,preserveMargins:a=!0}){const{t:l}=ne(),[d,c]=g.useState(0),p=i??d,h=v=>{o?o(v):c(v)};if(g.useEffect(()=>{i===void 0&&c(0)},[e,i]),n)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children: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)),m=e[u],f=m.label??`${u+1}`,x=!a&&!s?Om(m):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:m.url,alt:m.alt??l("reader.imageAlt",{label:f}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${m.width/x.w*100}%`,left:`${-x.x/x.w*100}%`,top:`${-x.y/x.h*100}%`}}),t.jsx(Fs,{page:m,crop:x})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:m.url,alt:m.alt??l("reader.imageAlt",{label:f}),width:m.width,height:m.height,loading:"lazy",decoding:"async"}),t.jsx(Fs,{page:m}),s==null?void 0:s(m,u)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.prevImage"),disabled:u===0,onClick:()=>h(u-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:m.label??`${u+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:u===e.length-1,onClick:()=>h(u+1),children:"›"})]})]})}function Fm(e){return e==="lite"||e==="full"}const Pn=[.1,.9],Ol=[{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 Hm(e){var n;return((n=Ol.find(i=>i.key===e))==null?void 0:n.stack)??null}const ro={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],Sr=18,Fl="bim-reader-prefs",Dm="bim-reading-mode";function Um(){const e={...ro};try{const n=localStorage.getItem(Fl),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&Et.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(Dm))==="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 Vm(e){try{localStorage.setItem(Fl,JSON.stringify(e))}catch{}}function ri(e,n){const i=e??Sr,o=Et;let s=o.indexOf(i);return s<0&&(s=o.indexOf(Sr)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Hl(){const[e,n]=g.useState(ro);g.useEffect(()=>{n(Um())},[]);const i=g.useCallback(o=>{n(s=>{const a={...s,...o};return Vm(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 Dl(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 Ul(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 Hs=()=>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"})}),Gm=()=>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"})}),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:"M9 5l7 7-7 7"})}),Ds=()=>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"})]}),Us=()=>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 Vs(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 Gs(e,n){const[i,o]=g.useState(n);return g.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 qm({prefs:e,onPrefsChange:n}){const i=g.useContext(Tt),{t:o}=ne();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(g.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 di({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 Km({prefs:e,onPrefsChange:n}){const i=g.useContext(Tt),{t:o}=ne(),s=(i==null?void 0:i.locale)==="zh-Hans"?"hans":"hant",a=e.scriptMode==="orig"?"orig":s;return t.jsx(di,{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 Xm(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 Zm(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 Vl({title:e,subtitle:n,toc:i,activeKey:o,onSelect:s,tocHeader:a,tocCaption:l,images:d,imagesLoading:c,renderImageOverlay:p,imagePanel:h="auto",prefs:u,onPrefsChange:m,paragraphToggle:f,properNameToggle:x=!0,allowVertical:v,byline:y,current:S,workLinkToggle:b,rail:w,onReportError:j,revisedAt:k,backHref:$,backLabel:C,bottomBar:_=!0,pager:L=!0,pagerUnit:z,versions:T,currentVersionKey:M,onVersionChange:P,versionSource:N=!0,keepChapterOnVersionChange:A=!1,customImagePanel:W,toolbarExtra:G,settingsAnnotate:X,settingsLayout:le,isWarpMode:U,children:D,className:xe,style:Y}){const{t:E,convert:Te}=ne(),ce=C??E("reader.back"),me=Te(z??E("reader.unitJuan")),se=g.useId().replace(/:/g,""),We=`bim-rd-toc-${se}`,J=`bim-rd-text-${se}`,re=g.useRef(null),de=g.useRef(null),H=g.useRef(null),Z=g.useRef(null),ke=Gs(Ll,!0),ie=Gs(Ml,!1),B=_&&ie,[Q,ae]=g.useState(null),[je,q]=g.useState(!1),be=g.useRef(null),Le=`bim-rd-set-${se}`,Fe=g.useRef(null),O=g.useRef(null),ee=(K,Re)=>{O.current=Re,ae(qe=>qe===K?null:K)},_e=g.useCallback(()=>{var K;ae(null),(K=O.current)==null||K.focus()},[]);g.useEffect(()=>{B||ae(null)},[B]),g.useEffect(()=>{var K,Re;Q&&((Re=(K=Fe.current)==null?void 0:K.querySelector("button:not([disabled])"))==null||Re.focus())},[Q]);const[ze,F]=g.useState("auto"),fe=ze==="auto"?ke:ze==="open",oe=!ke,we=!!W||!!d&&d.length>0,[Ae,He]=g.useState(h);g.useEffect(()=>{He(h)},[h]);const Ge=Ae==="auto"?we||!!c:Ae==="open",Ye=g.useCallback(K=>{var Re;F("auto"),K&&((Re=Z.current)==null||Re.focus())},[]),Xe=()=>F(fe?"closed":"open");g.useEffect(()=>{if(!oe||ze!=="open")return;const K=H.current,Re=K==null?void 0:K.querySelector('input, [data-rd-toc-key][tabindex="0"]');Re==null||Re.focus()},[oe,ze]);const I=g.useCallback(K=>{s(K),oe&&Ye(!1);const Re=de.current,qe=re.current;if(Re&&qe&&typeof window<"u"){const ot=Re.getBoundingClientRect().top-qe.getBoundingClientRect().bottom;ot<0&&window.scrollBy({top:ot})}},[s,oe,Ye]),V=g.useMemo(()=>Ul(i),[i]),[ue,$e]=g.useState(null),ye=Dl(T,M!==void 0?M:ue),he=(ye==null?void 0:ye.key)??null,Ve=g.useMemo(()=>V.map(K=>K.key).join(`
677
+ `),[V]),te=g.useRef(null),ve=K=>{K!==he&&(A||(te.current={key:K,sig:Ve,done:!1}),M===void 0&&$e(K),P==null||P(K))};g.useEffect(()=>{const K=te.current;if(!K||K.key!==he)return;const Re=V.find(ot=>!ot.disabled);if(!Re)return;const qe=Ve!==K.sig;!qe&&K.done||(qe?te.current=null:K.done=!0,Re.key!==o&&I(Re.key))},[he,Ve,V,o,I]);const Me=V.find(K=>K.key===o),Oe=()=>{var K;j==null||j({chapterKey:o,chapterLabel:typeof(Me==null?void 0:Me.label)=="string"?Me.label:void 0,anchor:Xm(de.current,((K=re.current)==null?void 0:K.getBoundingClientRect().bottom)??0),selectedText:Zm(de.current)})},Ie=V.findIndex(K=>K.key===o),ge=Ie>0?V.slice(0,Ie).reverse().find(K=>!K.disabled):void 0,Ce=Ie>=0?V.slice(Ie+1).find(K=>!K.disabled):void 0,De=u.fontSize??Sr,Pe=Hm(u.fontFamily),yt={...Y,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...Pe?{"--bimrd-ff":Pe}:null},jt={song:E("reader.fontSong"),kai:E("reader.fontKai"),system:E("reader.fontSystem")},on=x||!!X,Wt=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Le}-g1`,children:[t.jsx("h3",{id:`${Le}-g1`,className:"bim-rd-sp-h",children:E("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:E("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":E("reader.font"),value:u.fontFamily,onChange:K=>m({fontFamily:K.target.value}),children:Ol.map(K=>t.jsx("option",{value:K.key,children:jt[K.key]},K.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:E("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":E("reader.fontSmaller"),disabled:De<=Et[0],onClick:()=>m({fontSize:ri(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[De,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":E("reader.fontLarger"),disabled:De>=Et[Et.length-1],onClick:()=>m({fontSize:ri(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Km,{prefs:u,onPrefsChange:m}),t.jsx(di,{label:E("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:E("reader.quoteModern")},{key:"classic",label:E("reader.quoteClassic")},{key:"original",label:E("reader.quoteOriginal")}],onPick:K=>m({quoteStyle:K})})]}),on&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Le}-g2`,children:[t.jsx("h3",{id:`${Le}-g2`,className:"bim-rd-sp-h",children:E("reader.groupMark")}),x&&t.jsxs(t.Fragment,{children:[t.jsx(di,{label:E("reader.properName"),value:u.properNameMode,title:E("reader.properNameTitle"),options:[{key:"off",label:E("reader.properNameOff")},{key:"lite",label:E("reader.properNameLite"),title:E("reader.properNameLiteTitle")},{key:"full",label:E("reader.properNameFull")}],onPick:K=>m({properNameMode:K})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:K=>m({showWorks:K.target.checked})}),t.jsx("span",{children:E("reader.showWorks")})]}),t.jsx(di,{label:E("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:E("reader.bookTitleWavy")},{key:"bracket",label:E("reader.bookTitleBracket")}],onPick:K=>m({bookTitleStyle:K})})]}),X]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Le}-g3`,children:[t.jsx("h3",{id:`${Le}-g3`,className:"bim-rd-sp-h",children:E("reader.groupLayout")}),f&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:E("reader.paragraphTitle"),onClick:()=>m({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:E("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:K=>m({workLinks:K.target.checked})}),t.jsx("span",{children:E("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>m({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:E("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:K=>m({pageBreaks:K.target.checked})}),t.jsx("span",{children:E("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:K=>m({preserveMargins:K.target.checked})}),t.jsx("span",{children:E("reader.preserveMargins")})]}),le]})]});return t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",xe].filter(Boolean).join(" "),"data-toc":ze,"data-img":Ge?"open":"closed","data-bb":B?"":void 0,"data-set":!B&&je?"open":void 0,"data-warp":U?"true":void 0,style:yt,children:[t.jsx("style",{children:Pl}),t.jsx("a",{className:"bim-rd-skip",href:`#${J}`,onClick:K=>{var Re,qe,ot;K.preventDefault(),(Re=de.current)==null||Re.focus(),(ot=(qe=de.current)==null?void 0:qe.scrollIntoView)==null||ot.call(qe,{block:"start"})},children:E("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:re,children:[$&&t.jsxs("a",{className:"bim-rd-back",href:$,"aria-label":E("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||S)&&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}),S&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:S})]}),n&&t.jsx("span",{className:"bim-rd-ttl-src",children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":E("reader.settings"),children:[T&&T.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ye?Te(_r(ye)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:E("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:E("reader.versionShort")}),t.jsx("select",{"aria-label":E("reader.version"),value:he??"",onChange:K=>ve(K.target.value),children:T.map(K=>t.jsx("option",{value:K.key,children:Te(_r(K))},K.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),L&&(ge||Ce)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":E("reader.pagerGroup",{unit:me}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":E("reader.prevUnit",{unit:me}),title:ge?typeof ge.label=="string"&&ge.label?E("reader.prevUnitTitle",{unit:me,label:ge.label}):E("reader.prevUnit",{unit:me}):E("reader.firstUnit",{unit:me}),disabled:!ge,onClick:()=>ge&&I(ge.key),children:t.jsx(Gm,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":E("reader.nextUnit",{unit:me}),title:Ce?typeof Ce.label=="string"&&Ce.label?E("reader.nextUnitTitle",{unit:me,label:Ce.label}):E("reader.nextUnit",{unit:me}):E("reader.lastUnit",{unit:me}),disabled:!Ce,onClick:()=>Ce&&I(Ce.key),children:t.jsx(Ym,{})})]}),L&&(ge||Ce)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:Z,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":fe,"aria-controls":We,onClick:Xe,children:[t.jsx(Hs,{}),t.jsx("span",{className:"bim-rd-tlabel",children:E("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":Ge,onClick:()=>He(Ge?"closed":"open"),children:[t.jsx(Us,{}),E("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(qm,{prefs:u,onPrefsChange:m}),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":E("reader.fontSmaller"),disabled:De<=Et[0],onClick:()=>m({fontSize:ri(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":E("reader.fontLarger"),disabled:De>=Et[Et.length-1],onClick:()=>m({fontSize:ri(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":Le,onClick:()=>q(K=>!K),children:[t.jsx(Ds,{}),t.jsx("span",{className:"bim-rd-tlabel",children:E("reader.settings")})]}),G]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:We,ref:H,role:oe&&fe?"dialog":void 0,"aria-modal":oe&&fe?!0:void 0,"aria-label":oe&&fe?E("reader.toc"):void 0,onKeyDown:K=>{if(!(!oe||!fe)){if(K.key==="Escape"){K.stopPropagation(),Ye(!0);return}K.key==="Tab"&&Vs(K,H.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??E("reader.toc")}),oe&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":E("reader.closeToc"),onClick:()=>Ye(!0),children:"✕"})]}),a]}),t.jsx(Wl,{items:i,activeKey:o,onSelect:I})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Ye(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":E("reader.images"),children:Ge&&(W||t.jsx(wr,{pages:d??null,loading:c,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!B&&je&&t.jsxs("aside",{className:"bim-rd-set",id:Le,"aria-label":E("reader.settings"),onKeyDown:K=>{var Re;K.key==="Escape"&&(K.stopPropagation(),q(!1),(Re=be.current)==null||Re.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:E("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":E("reader.closeSettings"),onClick:()=>{var K;q(!1),(K=be.current)==null||K.focus()},children:"✕"})]}),Wt]}),t.jsxs("div",{className:"bim-rd-text",id:J,ref:de,tabIndex:-1,"data-rail":(w||j)&&!U?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[D,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:[E("reader.sourceLabel")," ",ye.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ye.sourceUrl,target:"_blank",rel:"noreferrer",children:Te(ye.sourceName)}):Te(ye.sourceName)]}),ye.sourceName&&ye.license&&t.jsx("span",{className:"bim-rd-dot"}),ye.license&&t.jsx(t.Fragment,{children:E("reader.licenseOf",{license:ye.license})})]}),k&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:E("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:K=>K.preventDefault(),onClick:Oe,children:E("reader.reportError")})}),L&&(ge||Ce)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":E("reader.pagerNav"),children:[ge?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>I(ge.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),E("reader.prevUnit",{unit:me})]}),t.jsx("span",{className:"bim-rd-pglabel",children:ge.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",E("reader.firstUnit",{unit:me})]}),Ce?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>I(Ce.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[E("reader.nextUnit",{unit:me}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:Ce.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[E("reader.lastUnit",{unit:me})," →"]})]})]}),(w||j)&&!U&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":E("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:K=>K.preventDefault(),onClick:Oe,children:E("reader.reportError")})})]})]})]}),B&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":E("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":fe,"aria-controls":We,onClick:()=>{ae(null),Xe()},children:[t.jsx(Hs,{}),t.jsx("span",{children:E("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":Q==="img","aria-haspopup":"dialog",onClick:K=>ee("img",K.currentTarget),children:[t.jsx(Us,{}),t.jsx("span",{children:E("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":Q==="set","aria-haspopup":"dialog",onClick:K=>ee("set",K.currentTarget),children:[t.jsx(Ds,{}),t.jsx("span",{children:E("reader.settingsShort")})]}),j&&t.jsxs("button",{type:"button",onMouseDown:K=>K.preventDefault(),onClick:()=>{ae(null),Oe()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:E("reader.reportError")})]})]}),B&&Q&&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":E(Q==="img"?"reader.images":"reader.settings"),onKeyDown:K=>{if(K.key==="Escape"){K.stopPropagation(),_e();return}K.key==="Tab"&&Vs(K,Fe.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:E(Q==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":E("reader.close"),onClick:_e,children:"✕"})]}),Q==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(wr,{pages:d??null,loading:c,renderOverlay:p,preserveMargins:u.preserveMargins})}):Wt]})]})]})}const Gl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Jm={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function nt(e){return Jm[e]??e}const mn=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],hn={熹平: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},Yl={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function zi(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 Qm(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 eh=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Ys={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function oo(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(Ys))if(n.startsWith(s))return Ys[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=Yl[`${n}|${e}`];if(i!=null)return i}return hn[e]}const th=1911;function nh(e){const n=hn[e];if(n==null)return;const i=Ct[e];let o;for(const[s,a]of Object.entries(hn))Ct[s]===i&&a>n&&(o==null||a<o)&&(o=a);return o!=null?o-1:void 0}const ih={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function fi(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=ih[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 Gl)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(hn))if(e.includes(o)&&!(i&&Ct[o]&&Ct[o]!==i&&Yl[`${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=zi(s);if(p)return{era:Qm(p.from),reign:"",source:"publication"};const h=At(s)??oo(s)??((c=mn.find(f=>f.pattern.test(s)))==null?void 0:c.era)??"",u=Jt(s,h)??"",m=h||(u?Ct[u]??"":"");if(m||u)return{era:nt(m),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 h=mn.find(u=>u.pattern.test(a));if(h)return{era:nt(h.era),reign:Jt(a,h.era)??h.reign??"",source:"edition"}}return n}function Ni(e){var o,s,a,l,d,c,p,h,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 m=zi(n);if(m)return m.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 m of i){const f=((c=e.publication_info)==null?void 0:c.year)||((p=e.lineage)==null?void 0:p.year_text);if(f&&m!==f&&(At(f)||oo(f)))break;const x=m.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??m.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=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(v){const w=At(m);if(!w||nt(w)==="民國"){const k=fi(v[1]);if(k!=null&&k>=1&&k<=120)return th+k}}const y=At(m)??((h=mn.find(w=>w.pattern.test(m)))==null?void 0:h.era),S=y?nt(y):void 0,b=Jt(m,S)??(At(m)||(u=mn.find(w=>w.pattern.test(m)))==null?void 0:u.reign);if(b){const w=Xt(b,S);if(w==null)continue;const j=m.indexOf(b),k=j>=0?m.slice(j+b.length):"",$=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),C=$?fi($[1]):void 0;return w+(C?C-1:0)}}}function so(e){var l,d,c,p,h,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 m=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const f=$r[nt(m[1])],x=Zt[nt(m[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 m=zi(s);if((m==null?void 0:m.to)!=null)return{from:m.from,to:m.to};const f=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const x=$r[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=[(h=e.publication_info)==null?void 0:h.year,e.edition,e.title].filter(Boolean);for(const m of a){if(!/[間间]/.test(m))continue;const f=At(m)??oo(m)??((u=mn.find(y=>y.pattern.test(m)))==null?void 0:u.era),x=f?nt(f):void 0,v=[];for(const y of Object.keys(hn))m.includes(y)&&(x&&Ct[y]&&Ct[y]!==x||Xt(y,x)!=null&&v.push(y));if(v.length===0){const y=m.match(/([一-鿿])([一-鿿])[間间]/);if(y&&x){for(const S of[y[1],y[2]])for(const b of Object.keys(hn))if(Ct[b]===x&&!(b[0]!==S&&b[b.length-1]!==S)&&Xt(b,x)!=null){v.push(b);break}}}if(v.length>0){const y=v.map(j=>Xt(j,x)).filter(j=>j!=null),S=Math.min(...y),b=v.reduce((j,k)=>Xt(j,x)>=Xt(k,x)?j:k),w=nh(b)??lr(x??"")??Math.max(...y);return{from:S,to:w>S?w:lr(x??Ct[b]??"")??S}}if(x&&Zt[x]!=null)return{from:Zt[x],to:lr(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},rh=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],oh=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,qs=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Ks(e,n){for(const i of Gl){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 h=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),u=h?fi(h[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 sh(e){var S,b,w,j,k;const n=Wn(e),i=((S=e.publication_info)==null?void 0:S.year)??"",o=i?zi(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"&&eh.test(i),p=n.source==="publication"&&/[間间]/.test(i),h=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let u;a||d||c||p?u=void 0:h?u=parseInt(h[2],10):u=Ni(e);const m=u==null?so(e):void 0;let f;n.source==="publication"&&(c||qs.test(i))?f="uncertain":n.source==="lineage"||n.source==="publication"?f="attested":qs.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:m,certainty:f,source:n.source==="edition"?"edition":"catalog",basis:x};if(h){const $=l.match(/[、,,]\s*([宋元明清])/);$&&$[1]!==v.era&&(v.laterRepair={era:$[1]})}if(!v.laterRepair&&oh.test(s)){const $=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);$&&$[1]!==n.era&&(v.laterRepair={era:$[1]})}const y=rh.find($=>$.re.test(s));if(y){const $=s.search(y.re),C=s.slice($),_=Ks(C,n.era)??Ks(s,n.era);_&&(v.basedOn={era:_.era,reign:_.reign,year:_.year,relation:y.relation})}return v}const $r={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function lr(e){return $r[e]}function xi(e){const n=Ni(e);if(n!=null)return n;const i=so(e);if(i)return i.from;const o=Wn(e).era;return o?Zt[o]:void 0}const Xs=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Cr(e){const n=Xs.indexOf(e);return n===-1?Xs.length:n}function ah(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 ao(e,n){const i=Yr(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((h,u)=>{const m=f=>f.group_role==="origin"?0:f.group_role==="mirror"?1:2;return m(h)-m(u)});const a={text:[],image:[],textImage:[],physical:[]};for(const p of s){const h=Mt(p),u=h.includes("text"),m=h.includes("image");u&&m?a.textImage.push(p):u?a.text.push(p):m?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,h])=>{var u,m;return{key:p,label:((u=n==null?void 0:n[p])==null?void 0:u.label)||p,description:(m=n==null?void 0:n[p])==null?void 0:m.description,items:h}});return{buckets:d,mirrors:c,total:i.length}}function Ii(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=ki(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 ql(e,n){if(Ii(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 Kl(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:Ni(e),sortYear:xi(e),images:o,holders:s,locationName:(a=e.current_location)==null?void 0:a.name,important:lh(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:o.length>0}}function lh(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 Xl(e,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=e.filter(c=>!o.has(c.id)).map(c=>Kl(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 h=c.r.sortYear,u=p.r.sortYear;return h!=null&&u!=null?h-u||c.i-p.i:h!=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 h=u=>(u.important?0:1)*2+(u.hasImage?0:1);return h(c.r)-h(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)=>Cr(c)-Cr(p));return{rows:a,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function ch(e,n){var y,S;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)},h=[],u=new Map,m=[];for(const b of e)if(!((S=n.excluded_books)!=null&&S.includes(b)))if(p(b))h.push(b);else{const w=n.node_groups[b];w?(u.has(w)||u.set(w,[]),u.get(w).push(b)):m.push(b)}if(m.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 m.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:m}),{useGrouping:!0,coreIds:h,groupedIds:v}}const Zl=["撰","編","注","校","譯","繪","其他"],dh=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function lo(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n)return"撰";for(const{cls:i,re:o}of dh)if(o.test(n))return i;return"其他"}function co(e){if(!e)return"";const n=e.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Jl(e,n="全部"){const i=new Map;for(const s of e){const a=lo(s);i.set(a,(i.get(a)??0)+1)}const o=[{cls:"全部",label:n,count:e.length}];for(const s of Zl){const a=i.get(s);a&&o.push({cls:s,label:s,count:a})}return o.length>2?o:[]}function po(e){return(e._books??[]).map(n=>n.id).filter(n=>typeof n=="string")}function uo(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 Ql(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 ph(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 ec(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}=Ql(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 Ri(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 uh=["〇","一","二","三","四","五","六","七","八","九"],Zs=["","十","百","千"];function tc(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+=Zs[d]:o+=uh[l]+Zs[d])}return o}function mh(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function hh(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?tc(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function nc(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 gh=65536,fh="guji_markdown";function xh(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 bh=/^□\{guess=([^\s{}]+)\}/;function yh(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function ic(e,n){let i=0;for(let o=n;o<e.length;o++){const s=e[o];if(s===`
678
+ `)return-1;if(s==="\\"){o++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return o}return-1}function jh(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function vh(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(`
679
+ `)<0?{node:{type:"qw",label:e.slice(n+2,o)},end:o+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const o=ic(e,n+3);return o>n+4?{node:{type:"zi",label:jh(e.slice(n+4,o))},end:o+1}:null}if(i==="□"&&e[n+1]==="{"){const o=bh.exec(e.slice(n,n+64));if(o)return{node:{type:"qz",guess:o[1]},end:n+o[0].length}}return null}function rc(e,n,i,o,s){const a=[];let l="",d=!1;const c=()=>{if(!l)return;let p=l;o&&(p=l.replace(/\\?\|/g,h=>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===`
680
+ `)return null}const h=vh(e,n);if(h){c(),a.push(h.node),n=h.end;continue}let u=null;if(p==="⟨"?u="⟩":p==="<"&&yh(e,n)&&(u=">"),u){const m=rc(e,n+1,u,!0,s);if(m&&!(p==="<"&&m.end-(n+1)>s)){c(),a.push({type:"jz",children:m.nodes}),n=m.end+1;continue}}l+=p,n++}return i!==null?null:(c(),{nodes:a,end:n})}function oc(e,n){return rc(e,0,null,!1,(n==null?void 0:n.jzMaxLength)??gh).nodes}function kh(e){return/[<⟨□]|\[\[|:zi\[/.test(e)}function sc(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${sc(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const wh=216,Js="clamp(280px, 23vw, 360px)",Sh=1440,Tr="(max-width: 719px)",_h=`${Tr}, (pointer: coarse)`,$h=`
681
+ .bim-d-main.bim-d-main-grid { max-width: ${Sh}px; padding: 16px 32px 0; }
682
682
  .bim-d-grid {
683
683
  display: grid;
684
- grid-template-columns: ${Sg}px minmax(0, 1fr) ${Qs};
684
+ grid-template-columns: ${wh}px minmax(0, 1fr) ${Js};
685
685
  grid-template-rows: auto 1fr;
686
686
  grid-template-areas: "rail main card" "rail main side";
687
687
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -1019,7 +1019,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1019
1019
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
1020
1020
 
1021
1021
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
1022
- @media ${$g} {
1022
+ @media ${_h} {
1023
1023
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
1024
1024
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
1025
1025
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -1057,7 +1057,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1057
1057
  /* 中等宽度:左栏折到顶部一行 */
1058
1058
  @media (max-width: 1100px) {
1059
1059
  .bim-d-grid {
1060
- grid-template-columns: minmax(0, 1fr) ${Qs};
1060
+ grid-template-columns: minmax(0, 1fr) ${Js};
1061
1061
  grid-template-rows: auto auto 1fr;
1062
1062
  grid-template-areas: "rail rail" "main card" "main side";
1063
1063
  }
@@ -1071,7 +1071,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1071
1071
  }
1072
1072
 
1073
1073
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
1074
- @media ${zr} {
1074
+ @media ${Tr} {
1075
1075
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
1076
1076
  .bim-d-grid {
1077
1077
  grid-template-columns: minmax(0, 1fr);
@@ -1146,7 +1146,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1146
1146
  :root[data-layout="boxed"] .bim-d-g-rail { border: ${r("fr-bd")}; background: ${r("fr-bg")}; padding: 14px 8px; }
1147
1147
  :root[data-layout="boxed"] .bim-d-filters { border-bottom: 1px solid ${r("fr-tab-bd")}; }
1148
1148
  :root[data-layout="boxed"] .bim-d-filters .bim-d-tab { margin-bottom: -1px; }
1149
- @media ${zr} {
1149
+ @media ${Tr} {
1150
1150
  :root[data-layout="boxed"] .bim-d-card { padding: 16px; }
1151
1151
  :root[data-layout="boxed"] .bim-d-g-rail { border: 0; background: transparent; padding: 0; }
1152
1152
  }
@@ -1161,7 +1161,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1161
1161
  :root[data-theme="ink"] :is(.bim-d-zt, .bim-d-side li, .bim-d-card-desc, .bim-d-desc, .bim-d-lf-card) a:hover {
1162
1162
  text-decoration-color: currentColor; text-decoration-thickness: 2px;
1163
1163
  }
1164
- `;function On({railTop:e,back:n,up:i,nav:o,railLinks:s,main:a,card:l,side:d}){const{t:c,convert:p}=te(),m=(o||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,m.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("detail.pageNav"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("detail.thisPage")}),t.jsx("ul",{className:"bim-d-rail-nav",children:m.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:p(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("detail.more"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("detail.more")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:g=>{g.metaKey||g.ctrlKey||(g.preventDefault(),u.onClick())},children:[t.jsx("span",{children:p(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:a}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:d})]})}function lc({caption:e,children:n}){const{convert:i}=te();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function ot({id:e,title:n,meta:i,action:o,children:s}){const{convert:a}=te();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:a(n)}),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i}),o&&t.jsx("span",{className:"bim-d-sec-act",children:o})]}),t.jsx("div",{className:"bim-d-sec-body",children:s})]})}function it({items:e,className:n,style:i}){const o=e.filter(s=>s!=null&&s!==""&&s!==!1);return o.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:i,children:o.map((s,a)=>t.jsxs(h.Fragment,{children:[a>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},a))}):null}function Li({items:e,value:n,onChange:i}){const{convert:o}=te();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...o(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:o(s.label)},s.key))})}function cc({label:e,checked:n,onChange:i}){const{convert:o}=te();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>i(s.target.checked)}),o(e)]})}const dc=6,Ai=e=>e>dc+1;function go({total:e,shown:n,unit:i,onClick:o}){const{t:s,convert:a}=te(),l=e-n,d=Ai(e)?e-Math.min(n,dc):l;return d<=0?null:t.jsxs("button",{type:"button",className:`bim-d-more bim-d-ui${l>0?"":" bim-d-more-ncap"}`,onClick:o,children:[l>0&&t.jsx("span",{className:"bim-d-more-w",children:s("detail.expandRest",{n:l,unit:a(i)})}),t.jsx("span",{className:"bim-d-more-n",children:s("detail.expandRest",{n:d,unit:a(i)})})]})}function ho({label:e,onClick:n}){const{convert:i}=te();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Fn({kind:e,title:n,subtitle:i,byline:o,meta:s,description:a,clampDescription:l,facts:d,stats:c,readAction:p,secondaryAction:m,children:u,foot:g}){const{t:f,convert:x}=te(),v=(d||[]).filter(j=>j.value!=null&&j.value!==""),y=(c||[]).filter(j=>j.value!=null&&j.value!==""&&j.value!==0),[_,b]=h.useState(!1),w=!!l&&!_;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:x(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),o&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:o}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),a&&t.jsx("div",{className:w?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:w?{"--detail-clamp":l}:void 0,children:a}),a&&!!l&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":_,onClick:()=>b(j=>!j),children:f(_?"action.collapse":"action.expand")}),y.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:y.map((j,k)=>t.jsxs("div",{children:[t.jsx("b",{children:j.value}),t.jsx("span",{children:x(j.label)})]},k))}),v.length>0&&t.jsx("dl",{className:"bim-d-ui",children:v.map((j,k)=>t.jsxs(h.Fragment,{children:[t.jsx("dt",{children:x(j.label)}),t.jsx("dd",{title:j.title,children:j.value})]},k))}),u,p,m,g&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:g})]})}function fo(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Nr({href:e,onClick:n,label:i}){const{t:o,convert:s}=te(),a=i??o("detail.read");return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n())}:void 0,children:s(a)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:s(a)})}function en({id:e,title:n,meta:i,items:o,metas:s,currentIndex:a,cap:l=8,moreLabel:d,foot:c,sub:p,timeline:m}){const{t:u,convert:g}=te(),[f,x]=h.useState(!1);if(!o.length)return null;const v=f?o:o.slice(0,l),y=o.length-v.length;return t.jsxs("div",{id:e,className:m?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[g(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),p&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:p}),t.jsx("ul",{children:v.map((_,b)=>t.jsxs("li",{className:b===a?"bim-d-side-cur":void 0,"aria-current":b===a?"page":void 0,children:[_,s!=null&&s[b]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[b]}):null]},b))}),y>0&&t.jsx(ho,{label:d?d(y):u("detail.showMore",{n:y}),onClick:()=>x(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const Tg=new Set(["reviewed","disputed","unreviewed","draft"]);function Hn({revision:e,revisedAt:n,review:i,todo:o}){const{t:s,convert:a}=te(),l=i&&Tg.has(i.status)?s(`detail.review.${i.status}`):void 0,d=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",c=[e!=null&&e!==""?`${s("detail.dataVersion")} ${e}`:"",n??"",a(d)].filter(Boolean),p=(o||[]).filter(m=>m&&m.what);return!c.length&&!p.length?null:t.jsxs(t.Fragment,{children:[c.length>0&&t.jsx(it,{items:c,style:{fontSize:12}}),p.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s("detail.todoCount",{n:p.length})}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:p.map((m,u)=>t.jsxs("li",{children:[a(m.what),(m.by||m.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[m.by&&a(m.by),m.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const ui=1e3,ea=208,zg=1440,Ng="(max-width: 719px)",pc=`
1164
+ `;function On({railTop:e,back:n,up:i,nav:o,railLinks:s,main:a,card:l,side:d}){const{t:c,convert:p}=ne(),h=(o||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,n&&t.jsx("div",{style:{marginTop:e?12:0},children:n}),i,h.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("detail.pageNav"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("detail.thisPage")}),t.jsx("ul",{className:"bim-d-rail-nav",children:h.map(u=>t.jsx("li",{children:t.jsxs("a",{href:`#${u.id}`,children:[t.jsx("span",{children:p(u.label)}),u.count!=null&&t.jsx("span",{className:"bim-d-meta",children:u.count})]})},u.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("detail.more"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("detail.more")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(u=>t.jsx("li",{children:t.jsxs("a",{href:u.href??"#",onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),u.onClick())},children:[t.jsx("span",{children:p(u.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},u.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:a}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:d})]})}function ac({caption:e,children:n}){const{convert:i}=ne();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:i(e)}),n]})}function rt({id:e,title:n,meta:i,action:o,children:s}){const{convert:a}=ne();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:a(n)}),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i}),o&&t.jsx("span",{className:"bim-d-sec-act",children:o})]}),t.jsx("div",{className:"bim-d-sec-body",children:s})]})}function it({items:e,className:n,style:i}){const o=e.filter(s=>s!=null&&s!==""&&s!==!1);return o.length?t.jsx("span",{className:`bim-d-meta${n?` ${n}`:""}`,style:i,children:o.map((s,a)=>t.jsxs(g.Fragment,{children:[a>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},a))}):null}function Ei({items:e,value:n,onChange:i}){const{convert:o}=ne();return t.jsx(t.Fragment,{children:e.map(s=>t.jsx("button",{type:"button",className:[...o(s.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":s.key===n,onClick:()=>i(s.key),children:o(s.label)},s.key))})}function lc({label:e,checked:n,onChange:i}){const{convert:o}=ne();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:s=>i(s.target.checked)}),o(e)]})}const cc=6,Li=e=>e>cc+1;function mo({total:e,shown:n,unit:i,onClick:o}){const{t:s,convert:a}=ne(),l=e-n,d=Li(e)?e-Math.min(n,cc):l;return d<=0?null:t.jsxs("button",{type:"button",className:`bim-d-more bim-d-ui${l>0?"":" bim-d-more-ncap"}`,onClick:o,children:[l>0&&t.jsx("span",{className:"bim-d-more-w",children:s("detail.expandRest",{n:l,unit:a(i)})}),t.jsx("span",{className:"bim-d-more-n",children:s("detail.expandRest",{n:d,unit:a(i)})})]})}function ho({label:e,onClick:n}){const{convert:i}=ne();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function Fn({kind:e,title:n,subtitle:i,byline:o,meta:s,description:a,clampDescription:l,facts:d,stats:c,readAction:p,secondaryAction:h,children:u,foot:m}){const{t:f,convert:x}=ne(),v=(d||[]).filter(j=>j.value!=null&&j.value!==""),y=(c||[]).filter(j=>j.value!=null&&j.value!==""&&j.value!==0),[S,b]=g.useState(!1),w=!!l&&!S;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:x(e)}),t.jsx("h1",{className:typeof n=="string"&&[...n].length>7?"bim-d-card-long":void 0,children:n}),i&&t.jsx("div",{className:"bim-d-card-sub",children:i}),o&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:o}),s&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:s}),a&&t.jsx("div",{className:w?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:w?{"--detail-clamp":l}:void 0,children:a}),a&&!!l&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":S,onClick:()=>b(j=>!j),children:f(S?"action.collapse":"action.expand")}),y.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:y.map((j,k)=>t.jsxs("div",{children:[t.jsx("b",{children:j.value}),t.jsx("span",{children:x(j.label)})]},k))}),v.length>0&&t.jsx("dl",{className:"bim-d-ui",children:v.map((j,k)=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:x(j.label)}),t.jsx("dd",{title:j.title,children:j.value})]},k))}),u,p,h,m&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:m})]})}function go(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function zr({href:e,onClick:n,label:i}){const{t:o,convert:s}=ne(),a=i??o("detail.read");return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:n?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n())}:void 0,children:s(a)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:n,children:s(a)})}function en({id:e,title:n,meta:i,items:o,metas:s,currentIndex:a,cap:l=8,moreLabel:d,foot:c,sub:p,timeline:h}){const{t:u,convert:m}=ne(),[f,x]=g.useState(!1);if(!o.length)return null;const v=f?o:o.slice(0,l),y=o.length-v.length;return t.jsxs("div",{id:e,className:h?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[m(n),i!=null&&i!==""&&t.jsx("span",{className:"bim-d-meta",children:i})]}),p&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:p}),t.jsx("ul",{children:v.map((S,b)=>t.jsxs("li",{className:b===a?"bim-d-side-cur":void 0,"aria-current":b===a?"page":void 0,children:[S,s!=null&&s[b]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[b]}):null]},b))}),y>0&&t.jsx(ho,{label:d?d(y):u("detail.showMore",{n:y}),onClick:()=>x(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const Ch=new Set(["reviewed","disputed","unreviewed","draft"]);function Hn({revision:e,revisedAt:n,review:i,todo:o}){const{t:s,convert:a}=ne(),l=i&&Ch.has(i.status)?s(`detail.review.${i.status}`):void 0,d=i&&i.status!=="unreviewed"&&l?[l,i.by,i.date].filter(Boolean).join(" "):"",c=[e!=null&&e!==""?`${s("detail.dataVersion")} ${e}`:"",n??"",a(d)].filter(Boolean),p=(o||[]).filter(h=>h&&h.what);return!c.length&&!p.length?null:t.jsxs(t.Fragment,{children:[c.length>0&&t.jsx(it,{items:c,style:{fontSize:12}}),p.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:s("detail.todoCount",{n:p.length})}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:p.map((h,u)=>t.jsxs("li",{children:[a(h.what),(h.by||h.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[h.by&&a(h.by),h.date].filter(Boolean).join(" · "),")"]})]},u))})]})]})}const pi=1e3,Qs=208,Th=1440,zh="(max-width: 719px)",dc=`
1165
1165
  .bim-d-page {
1166
1166
  background: ${r("page-bg")};
1167
1167
  color: ${r("ink")};
@@ -1170,7 +1170,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1170
1170
  padding-bottom: 64px;
1171
1171
  }
1172
1172
  .bim-d-main {
1173
- max-width: ${ui}px;
1173
+ max-width: ${pi}px;
1174
1174
  margin: 0 auto;
1175
1175
  padding: 24px clamp(16px, 4vw, 28px) 0;
1176
1176
  }
@@ -1181,7 +1181,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1181
1181
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
1182
1182
  */
1183
1183
  .bim-d-main.bim-d-main-wide {
1184
- max-width: ${zg}px;
1184
+ max-width: ${Th}px;
1185
1185
  }
1186
1186
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
1187
1187
 
@@ -1213,9 +1213,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1213
1213
  */
1214
1214
  .bim-d-reader {
1215
1215
  display: grid;
1216
- grid-template-columns: ${ea}px minmax(0, ${ui}px);
1216
+ grid-template-columns: ${Qs}px minmax(0, ${pi}px);
1217
1217
  gap: 32px;
1218
- max-width: ${ea+ui+32}px;
1218
+ max-width: ${Qs+pi+32}px;
1219
1219
  margin: 0 auto;
1220
1220
  align-items: start;
1221
1221
  }
@@ -1238,7 +1238,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1238
1238
  align-items: start; margin-bottom: 48px; }
1239
1239
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
1240
1240
 
1241
- @media ${Ng} {
1241
+ @media ${zh} {
1242
1242
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
1243
1243
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
1244
1244
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -1256,20 +1256,20 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1256
1256
  padding-right: 0; padding-bottom: 12px;
1257
1257
  }
1258
1258
  }
1259
- ${Cg}`;function In({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:pc}),t.jsx("div",{className:o?"bim-d-main bim-d-main-grid":i?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Ir({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:r("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function xo({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:r(n==="accent"?"accent":"ink"),color:r("page-bg")},children:e})}function Rr({items:e}){const n=tt();return t.jsx(t.Fragment,{children:e.map((i,o)=>{const s=o===e.length-1,a=o>0&&t.jsx("span",{style:{color:r("hint-fg")},children:"/"},`s${o}`),l=i.id?n(i.id):i.href,d=s||!i.onClick&&!l?t.jsx("span",{style:{color:r("ink")},children:i.label},o):t.jsx("a",{href:l??"#",onClick:i.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i.onClick())}:void 0,style:{color:r("meta-fg")},children:i.label},o);return t.jsxs(h.Fragment,{children:[a,d]},o)})})}function uc({title:e,subtitle:n,aside:i,secondLine:o}){return t.jsxs("header",{style:{borderBottom:`2px solid ${r("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:r("meta-fg"),letterSpacing:".06em"},children:n})]}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r("label-fg"),letterSpacing:".06em"},children:i})]}),o&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:r("quiet-fg")},children:o})]})}function Ig({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${r("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function Rg({items:e,horizontal:n}){const{convert:i}=Me();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${r("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((o,s)=>t.jsxs("div",{title:o.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:r("label-fg"),letterSpacing:".08em",flex:"none"},children:i(o.label)}),t.jsx("span",{style:{color:r("body-fg"),textAlign:n?"left":"right",minWidth:0},children:o.value})]},s))}):null}function Eg({glyph:e,tone:n,title:i,count:o,actions:s,id:a}){const{convert:l}=Me();return t.jsxs("div",{id:a,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(xo,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(i)}),o!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r("label-fg")},children:o})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function mc({label:e,active:n,onClick:i,dashed:o}){const{convert:s}=Me();return t.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!n?"dashed":"solid"} ${r(n?"accent":"rule")}`,background:n?r("accent"):"transparent",color:r(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function Lg({label:e,onClick:n}){const{convert:i}=Me();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r("meta-fg"),borderBottom:`1px solid ${r("rule")}`},children:i(e)})}function Ag({label:e,onClick:n,inline:i}){const{convert:o}=Me();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:`1px dashed ${r("rule-dashed")}`,cursor:"pointer",fontSize:12,color:r("meta-fg"),letterSpacing:i?void 0:".08em"},children:o(e)})}function gc({children:e,href:n,onClick:i,title:o}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${r("rule")}`,fontSize:13,color:r("body-fg"),lineHeight:1.5};return n||i?t.jsx("a",{href:n??"#",title:o,onClick:i?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i())}:void 0,style:s,children:e}):t.jsx("span",{title:o,style:s,children:e})}function Mg({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Pg({volumes:e,unit:n,max:i=60}){const{t:o}=te(),s=n??o("unit.volume"),[a,l]=h.useState(!1);if(!e.length)return null;const d=a?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[d.map(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${r("rule")}`,color:r("meta-fg")},children:c},c)),!a&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>l(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${r("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:r("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:r("hint-fg")},children:s})]})}function Bg({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${r("rule-strong")}`},children:e})}function Wg({spec:e}){const{convert:n}=Me();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${r("rule-strong")}`,fontSize:11,color:r("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Og({no:e,main:n,meta:i,spec:o}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o.leadWidth}px 1fr ${o.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:r("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:o.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Fg(e){return String(e+1).padStart(2,"0")}function Hg(){return t.jsx("span",{style:{color:r("hint-fg")},children:"—"})}function Dg({open:e,onToggle:n,main:i,action:o,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${r("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${r(e?"accent":"rule-dashed")}`,background:e?r("accent"):"transparent",color:r(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),o]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${r("rule-accent-soft")}`,marginLeft:12},children:s})]})}function hc(e){const n=[];for(let i=0;i<e.length;i++){const o=e[i];let s;if(o==="⟨")s="⟩";else if(o==="<"){const d=e[i+1];if(d===void 0||/[A-Za-z/!?>\s]/.test(d))continue;s=">"}else continue;const a=e.indexOf(s,i+1);if(a<0)continue;const l=e.slice(i+1,a);l.includes(`
1260
- `)||(n.push({start:i,end:a+1,inner:l}),i=a)}return n}function fc(e,n){if(e.length<=n)return e;let i=n;for(const o of hc(e)){if(o.start>=i)break;if(o.end>i){i=o.start>0?o.start:o.end;break}}return e.slice(0,i)}const xc={fontSize:".78em",color:r("meta-fg"),lineHeight:1.55},Ug={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function bc(e,n,i,o){return e.map((s,a)=>{switch(s.type){case"text":return t.jsx(h.Fragment,{children:n(s.text)},a);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?xc:void 0,children:bc(s.children,n,i+1,o)},a);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:s.label?o("detail.lacunaWith",{label:s.label}):o("detail.lacuna"),children:"□"},a);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":s.guess,children:"□"},a);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:o("detail.composedChar",{label:s.label}),style:Ug,children:s.label},a)}})}function xt(e,n=o=>o,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return wg(e)?bc(sc(e,{jzMaxLength:i.jzMaxLength}),n,0,i.t??yn("zh-Hant")):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const o=[];let s=0,a=0;for(const l of hc(e))l.start>s&&o.push(t.jsx(h.Fragment,{children:n(e.slice(s,l.start))},a++)),o.push(t.jsx("span",{className:"bim-jiazhu",style:xc,children:n(l.inner)},a++)),s=l.end;return s<e.length&&o.push(t.jsx(h.Fragment,{children:n(e.slice(s))},a++)),o}function Vg({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:r("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:r("quiet-fg"),textAlign:"justify"},children:n})]})}function Gg({title:e,tag:n,children:i}){const{convert:o}=Me();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${r("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:o(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:r("accent"),letterSpacing:".06em"},children:o(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function yc({name:e,note:n,href:i,extra:o}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:r("hint-fg"),flex:"none"},children:i?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:r("label-fg")},children:n})]}),a={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${r("rule")}`,color:r("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:a,children:s}):t.jsx("div",{style:a,children:s}),o]})}function Yg({item:e,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{t:s,convert:a}=te(),[l,d]=h.useState(!1),c=wi(e),p=i&&!!c&&c.expected>0,m=(e.url?fn(e.url):void 0)||a(e.name),u=n?Kl(e,n):"",g=u?`${m}(${u})`:m;return t.jsx(yc,{name:g,note:Ri(e,s)||o,href:xn(e),extra:p?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(f=>!f),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:r("meta-fg"),borderBottom:`1px solid ${r("rule")}`},children:l?s("detail.collapseVolumes"):s("detail.expandVolumes",{n:c.expected})}),l&&t.jsx(bo,{item:e})]}):void 0})}function bo({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,i)=>{const o=n.status==="missing";return n.url&&!o?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:r("zebra-bg")},children:n.volume},i):t.jsx("span",{style:{padding:"1px 5px",color:r(o?"missing-fg":"hint-fg"),textDecoration:o?"line-through":void 0},children:n.volume},i)})})}function jc({label:e,items:n}){const{convert:i}=Me();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r("label-fg"),letterSpacing:".08em"},children:e}),n.map((o,s)=>t.jsx(gc,{children:i(o)},s))]}):null}function qg({rows:e}){const n=e.filter(i=>i.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>t.jsx(jc,{label:i.label,items:i.items},i.label))}):null}function Er(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function vc({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${r("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:r("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Kg({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:r("aux-fg"),borderBottom:`1px solid ${r("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function et({id:e,label:n,onNavigate:i,renderLink:o,style:s,dense:a}){const l=tt();return o?t.jsx(t.Fragment,{children:o(e,typeof n=="string"?n:void 0,{dense:a})}):t.jsx("a",{href:l(e),onClick:i?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Xg({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const kc="guji-table-v1";function Zg(e){return!!e&&e.table_notation===kc}const Jg=/^:::table(?:\{[^}]*\})?[ \t]*$/,Qg=/^:::[ \t]*$/;function wc(e){const n=[];let i="";for(let o=0;o<e.length;o++){const s=e[o];if(s===":"&&e.startsWith(":zi[",o)){const l=rc(e,o+3);if(l>o+4){i+=e.slice(o,l+1),o=l;continue}}let a=null;if(s==="⟨")a="⟩";else if(s==="<"){const l=e[o+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(a=">")}if(a){const l=e.indexOf(a,o+1);if(l>0){i+=e.slice(o,l+1),o=l;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(o=>o.trim())}const eh=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function th(e){if(e==="^")return{cont:!0};const n=eh.exec(e),i=n[1].trim(),o=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,a=i==="_";return{cont:!1,cell:{text:a?"":i,empty:a,colspan:o,rowspan:s}}}function Sc(e,n=1){const i=[],o=[],s=[];let a=[];e.forEach((d,c)=>{const p=c+n+1;let m=d.trim();if(!m)return;let u=!1;m.startsWith("!")&&(u=!0,m=m.slice(1));const g=wc(m).map(th),f=a.map(_=>_>0),x=a.map(_=>_>0?_-1:0),v=[];let y=0;for(const _ of g){if(_.cont){f[y]||i.push(`第 ${p} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:b}=_;for(let w=y;w<y+b.colspan;w++)if(f[w]){i.push(`第 ${p} 行第 ${w+1} 列:此处被上方跨行格占住,应写 ^`);break}if(b.rowspan>1)for(let w=y;w<y+b.colspan;w++)x[w]=b.rowspan-1;v.push(b),y+=b.colspan}for(let _=y;_<f.length;_++)f[_]&&i.push(`第 ${p} 行第 ${_+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let _=0;_<x.length;_++)x[_]===void 0&&(x[_]=0);a=x,o.push({header:u,cells:v}),s.push({width:y,line:p})});const l=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==l&&i.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${l} 不符`);return a.some(d=>d>0)&&i.push("表尾:有跨行格超出了表的最后一行"),o.length===0&&i.push("空表"),{rows:o,columns:l,warnings:i}}function yo(e){const n=e.split(`
1259
+ ${$h}`;function In({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:dc}),t.jsx("div",{className:o?"bim-d-main bim-d-main-grid":i?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Nr({breadcrumb:e,actions:n}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:r("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),n&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function fo({char:e,tone:n="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:r(n==="accent"?"accent":"ink"),color:r("page-bg")},children:e})}function Ir({items:e}){const n=tt();return t.jsx(t.Fragment,{children:e.map((i,o)=>{const s=o===e.length-1,a=o>0&&t.jsx("span",{style:{color:r("hint-fg")},children:"/"},`s${o}`),l=i.id?n(i.id):i.href,d=s||!i.onClick&&!l?t.jsx("span",{style:{color:r("ink")},children:i.label},o):t.jsx("a",{href:l??"#",onClick:i.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i.onClick())}:void 0,style:{color:r("meta-fg")},children:i.label},o);return t.jsxs(g.Fragment,{children:[a,d]},o)})})}function pc({title:e,subtitle:n,aside:i,secondLine:o}){return t.jsxs("header",{style:{borderBottom:`2px solid ${r("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),n&&t.jsx("span",{style:{fontSize:15,color:r("meta-fg"),letterSpacing:".06em"},children:n})]}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r("label-fg"),letterSpacing:".06em"},children:i})]}),o&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:r("quiet-fg")},children:o})]})}function Nh({children:e,facts:n}){return!e&&n?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${r("rule")}`,marginBottom:40},children:n}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),n]})}function Ih({items:e,horizontal:n}){const{convert:i}=Be();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${r("accent")}`,paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:e.map((o,s)=>t.jsxs("div",{title:o.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:r("label-fg"),letterSpacing:".08em",flex:"none"},children:i(o.label)}),t.jsx("span",{style:{color:r("body-fg"),textAlign:n?"left":"right",minWidth:0},children:o.value})]},s))}):null}function Rh({glyph:e,tone:n,title:i,count:o,actions:s,id:a}){const{convert:l}=Be();return t.jsxs("div",{id:a,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(fo,{char:e,tone:n}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(i)}),o!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r("label-fg")},children:o})]}),s&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function uc({label:e,active:n,onClick:i,dashed:o}){const{convert:s}=Be();return t.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!n?"dashed":"solid"} ${r(n?"accent":"rule")}`,background:n?r("accent"):"transparent",color:r(n?"page-bg":"meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(e)})}function Eh({label:e,onClick:n}){const{convert:i}=Be();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r("meta-fg"),borderBottom:`1px solid ${r("rule")}`},children:i(e)})}function Lh({label:e,onClick:n,inline:i}){const{convert:o}=Be();return t.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:`1px dashed ${r("rule-dashed")}`,cursor:"pointer",fontSize:12,color:r("meta-fg"),letterSpacing:i?void 0:".08em"},children:o(e)})}function mc({children:e,href:n,onClick:i,title:o}){const s={display:"inline-block",padding:"4px 10px",border:`1px solid ${r("rule")}`,fontSize:13,color:r("body-fg"),lineHeight:1.5};return n||i?t.jsx("a",{href:n??"#",title:o,onClick:i?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i())}:void 0,style:s,children:e}):t.jsx("span",{title:o,style:s,children:e})}function Ah({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Mh({volumes:e,unit:n,max:i=60}){const{t:o}=ne(),s=n??o("unit.volume"),[a,l]=g.useState(!1);if(!e.length)return null;const d=a?e:e.slice(0,i);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[d.map(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${r("rule")}`,color:r("meta-fg")},children:c},c)),!a&&e.length>i&&t.jsxs("button",{type:"button",onClick:()=>l(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${r("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:r("meta-fg")},children:["+",e.length-i]}),t.jsx("span",{style:{padding:"2px 6px",color:r("hint-fg")},children:s})]})}function Ph({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${r("rule-strong")}`},children:e})}function Bh({spec:e}){const{convert:n}=Be();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${r("rule-strong")}`,fontSize:11,color:r("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:n(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(i=>i.width).join(" "),gap:12},children:e.columns.map(i=>t.jsx("span",{children:n(i.label)},i.label))})]})}function Wh({no:e,main:n,meta:i,spec:o}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o.leadWidth}px 1fr ${o.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:r("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:n}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:o.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Oh(e){return String(e+1).padStart(2,"0")}function Fh(){return t.jsx("span",{style:{color:r("hint-fg")},children:"—"})}function Hh({open:e,onToggle:n,main:i,action:o,children:s}){return t.jsxs("div",{style:{borderBottom:`1px solid ${r("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:n,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${r(e?"accent":"rule-dashed")}`,background:e?r("accent"):"transparent",color:r(e?"page-bg":"accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),o]}),e&&s&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${r("rule-accent-soft")}`,marginLeft:12},children:s})]})}function hc(e){const n=[];for(let i=0;i<e.length;i++){const o=e[i];let s;if(o==="⟨")s="⟩";else if(o==="<"){const d=e[i+1];if(d===void 0||/[A-Za-z/!?>\s]/.test(d))continue;s=">"}else continue;const a=e.indexOf(s,i+1);if(a<0)continue;const l=e.slice(i+1,a);l.includes(`
1260
+ `)||(n.push({start:i,end:a+1,inner:l}),i=a)}return n}function gc(e,n){if(e.length<=n)return e;let i=n;for(const o of hc(e)){if(o.start>=i)break;if(o.end>i){i=o.start>0?o.start:o.end;break}}return e.slice(0,i)}const fc={fontSize:".78em",color:r("meta-fg"),lineHeight:1.55},Dh={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function xc(e,n,i,o){return e.map((s,a)=>{switch(s.type){case"text":return t.jsx(g.Fragment,{children:n(s.text)},a);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?fc:void 0,children:xc(s.children,n,i+1,o)},a);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:s.label?o("detail.lacunaWith",{label:s.label}):o("detail.lacuna"),children:"□"},a);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":s.guess,children:"□"},a);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:o("detail.composedChar",{label:s.label}),style:Dh,children:s.label},a)}})}function ft(e,n=o=>o,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return kh(e)?xc(oc(e,{jzMaxLength:i.jzMaxLength}),n,0,i.t??yn("zh-Hant")):n(e);if(e.indexOf("⟨")<0&&e.indexOf("<")<0)return n(e);const o=[];let s=0,a=0;for(const l of hc(e))l.start>s&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s,l.start))},a++)),o.push(t.jsx("span",{className:"bim-jiazhu",style:fc,children:n(l.inner)},a++)),s=l.end;return s<e.length&&o.push(t.jsx(g.Fragment,{children:n(e.slice(s))},a++)),o}function Uh({label:e,children:n}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:r("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:r("quiet-fg"),textAlign:"justify"},children:n})]})}function Vh({title:e,tag:n,children:i}){const{convert:o}=Be();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${r("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:o(e)}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:r("accent"),letterSpacing:".06em"},children:o(n)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function bc({name:e,note:n,href:i,extra:o}){const s=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:r("hint-fg"),flex:"none"},children:i?"↗":""}),n&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:r("label-fg")},children:n})]}),a={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${r("rule")}`,color:r("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[i?t.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:a,children:s}):t.jsx("div",{style:a,children:s}),o]})}function Gh({item:e,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{t:s,convert:a}=ne(),[l,d]=g.useState(!1),c=ki(e),p=i&&!!c&&c.expected>0,h=(e.url?fn(e.url):void 0)||a(e.name),u=n?ql(e,n):"",m=u?`${h}(${u})`:h;return t.jsx(bc,{name:m,note:Ii(e,s)||o,href:xn(e),extra:p?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(f=>!f),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:r("meta-fg"),borderBottom:`1px solid ${r("rule")}`},children:l?s("detail.collapseVolumes"):s("detail.expandVolumes",{n:c.expected})}),l&&t.jsx(xo,{item:e})]}):void 0})}function xo({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((n,i)=>{const o=n.status==="missing";return n.url&&!o?t.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:r("zebra-bg")},children:n.volume},i):t.jsx("span",{style:{padding:"1px 5px",color:r(o?"missing-fg":"hint-fg"),textDecoration:o?"line-through":void 0},children:n.volume},i)})})}function yc({label:e,items:n}){const{convert:i}=Be();return n.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r("label-fg"),letterSpacing:".08em"},children:e}),n.map((o,s)=>t.jsx(mc,{children:i(o)},s))]}):null}function Yh({rows:e}){const n=e.filter(i=>i.items.length>0);return n.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>t.jsx(yc,{label:i.label,items:i.items},i.label))}):null}function Rr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function jc({left:e,right:n}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${r("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:r("aux-fg")},children:[t.jsx("span",{children:e}),n&&t.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function qh({children:e,action:n}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:r("aux-fg"),borderBottom:`1px solid ${r("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),n]})}function et({id:e,label:n,onNavigate:i,renderLink:o,style:s,dense:a}){const l=tt();return o?t.jsx(t.Fragment,{children:o(e,typeof n=="string"?n:void 0,{dense:a})}):t.jsx("a",{href:l(e),onClick:i?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),i(e))}:void 0,style:s,children:n??e})}function Kh({href:e,children:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[n," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const vc="guji-table-v1";function Xh(e){return!!e&&e.table_notation===vc}const Zh=/^:::table(?:\{[^}]*\})?[ \t]*$/,Jh=/^:::[ \t]*$/;function kc(e){const n=[];let i="";for(let o=0;o<e.length;o++){const s=e[o];if(s===":"&&e.startsWith(":zi[",o)){const l=ic(e,o+3);if(l>o+4){i+=e.slice(o,l+1),o=l;continue}}let a=null;if(s==="⟨")a="⟩";else if(s==="<"){const l=e[o+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(a=">")}if(a){const l=e.indexOf(a,o+1);if(l>0){i+=e.slice(o,l+1),o=l;continue}}s==="|"?(n.push(i),i=""):i+=s}return n.push(i),n.map(o=>o.trim())}const Qh=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function eg(e){if(e==="^")return{cont:!0};const n=Qh.exec(e),i=n[1].trim(),o=n[2]?Math.max(1,parseInt(n[2],10)):1,s=n[3]?Math.max(1,parseInt(n[3],10)):1,a=i==="_";return{cont:!1,cell:{text:a?"":i,empty:a,colspan:o,rowspan:s}}}function wc(e,n=1){const i=[],o=[],s=[];let a=[];e.forEach((d,c)=>{const p=c+n+1;let h=d.trim();if(!h)return;let u=!1;h.startsWith("!")&&(u=!0,h=h.slice(1));const m=kc(h).map(eg),f=a.map(S=>S>0),x=a.map(S=>S>0?S-1:0),v=[];let y=0;for(const S of m){if(S.cont){f[y]||i.push(`第 ${p} 行第 ${y+1} 列:续格 ^ 上方没有跨行格`),y+=1;continue}const{cell:b}=S;for(let w=y;w<y+b.colspan;w++)if(f[w]){i.push(`第 ${p} 行第 ${w+1} 列:此处被上方跨行格占住,应写 ^`);break}if(b.rowspan>1)for(let w=y;w<y+b.colspan;w++)x[w]=b.rowspan-1;v.push(b),y+=b.colspan}for(let S=y;S<f.length;S++)f[S]&&i.push(`第 ${p} 行第 ${S+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let S=0;S<x.length;S++)x[S]===void 0&&(x[S]=0);a=x,o.push({header:u,cells:v}),s.push({width:y,line:p})});const l=s.reduce((d,c)=>Math.max(d,c.width),0);for(const d of s)d.width!==l&&i.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${l} 不符`);return a.some(d=>d>0)&&i.push("表尾:有跨行格超出了表的最后一行"),o.length===0&&i.push("空表"),{rows:o,columns:l,warnings:i}}function bo(e){const n=e.split(`
1261
1261
  `),i=[];let o=[];const s=()=>{if(o.length===0)return;const l=o.join(`
1262
- `);o=[],i.push({type:"text",text:l})};let a=0;for(;a<n.length;){if(Jg.test(n[a].trim())){let l=a+1;for(;l<n.length&&!Qg.test(n[l].trim());)l++;if(l<n.length){s();const d=n.slice(a+1,l);i.push({type:"table",table:Sc(d,a+1),source:n.slice(a,l+1).join(`
1263
- `)}),a=l+1;continue}}o.push(n[a]),a++}return s(),i.map((l,d)=>{var p,m;if(l.type!=="text")return l;let c=l.text;return((p=i[d-1])==null?void 0:p.type)==="table"&&(c=c.replace(/^\n+/,"")),((m=i[d+1])==null?void 0:m.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(l=>l.type!=="text"||l.text!=="")}const nh={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ih={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},rh=`1px solid ${r("table-border")}`,_c={border:rh,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},oh={..._c,background:r("table-head-bg"),fontWeight:600};function jo({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:nh,children:t.jsx("table",{className:"bim-guji-table",style:ih,children:t.jsx("tbody",{children:e.rows.map((i,o)=>t.jsx("tr",{children:i.cells.map((s,a)=>{const l=i.header?"th":"td";return t.jsx(l,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?oh:_c,children:s.empty?null:xt(s.text,void 0,n)},a)})},o))})})})}function sh(e,n){return e.indexOf("**")<0?xt(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((o,s)=>s%2===1?t.jsx("strong",{children:xt(o.trim().slice(2,-2),void 0,n)},s):t.jsx(h.Fragment,{children:xt(o,void 0,n)},s))}function ah(e,n,i=!1){const o=i?{gujiMarkdown:!0}:void 0;return n?yo(e).map((s,a)=>s.type==="table"?t.jsx(jo,{table:s.table,opts:o},a):t.jsx(h.Fragment,{children:sh(s.text,o)},a)):xt(e,void 0,o)}const lh=/^(#{1,6})\s+(.*)$/,ch=/^\*\*([^*\n]+)\*\*\s*$/;function vo(e){const n=e.match(lh);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(ch);return i?{level:3,text:i[1].trim()}:null}const ko=/^<!--.*-->$/;function $c(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function Cc(e){return e.split(`
1264
- `).map(n=>n.trim()).filter(n=>n&&!ko.test(n))}const dh=60;function Tc(e){let n=0,i=0;for(const o of e.split(`
1265
- `)){const s=o.trim();if(!s||ko.test(s)||vo(s))continue;const a=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=a,a>dh&&(i+=a)}return n>0&&i*2>=n}function ph(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Mi(e){if(e=ph(e),Tc(e))return"unknown";const n=$c(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>Cc(s).length).filter(s=>s>0);if(i.length===0)return"unknown";const o=i.reduce((s,a)=>s+a,0)/i.length;return o<=4?"record":o>=8?"catalog":"unknown"}function uh(e){const n=e.split(`
1262
+ `);o=[],i.push({type:"text",text:l})};let a=0;for(;a<n.length;){if(Zh.test(n[a].trim())){let l=a+1;for(;l<n.length&&!Jh.test(n[l].trim());)l++;if(l<n.length){s();const d=n.slice(a+1,l);i.push({type:"table",table:wc(d,a+1),source:n.slice(a,l+1).join(`
1263
+ `)}),a=l+1;continue}}o.push(n[a]),a++}return s(),i.map((l,d)=>{var p,h;if(l.type!=="text")return l;let c=l.text;return((p=i[d-1])==null?void 0:p.type)==="table"&&(c=c.replace(/^\n+/,"")),((h=i[d+1])==null?void 0:h.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(l=>l.type!=="text"||l.text!=="")}const tg={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},ng={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},ig=`1px solid ${r("table-border")}`,Sc={border:ig,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},rg={...Sc,background:r("table-head-bg"),fontWeight:600};function yo({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:tg,children:t.jsx("table",{className:"bim-guji-table",style:ng,children:t.jsx("tbody",{children:e.rows.map((i,o)=>t.jsx("tr",{children:i.cells.map((s,a)=>{const l=i.header?"th":"td";return t.jsx(l,{colSpan:s.colspan>1?s.colspan:void 0,rowSpan:s.rowspan>1?s.rowspan:void 0,style:i.header?rg:Sc,children:s.empty?null:ft(s.text,void 0,n)},a)})},o))})})})}function og(e,n){return e.indexOf("**")<0?ft(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((o,s)=>s%2===1?t.jsx("strong",{children:ft(o.trim().slice(2,-2),void 0,n)},s):t.jsx(g.Fragment,{children:ft(o,void 0,n)},s))}function sg(e,n,i=!1){const o=i?{gujiMarkdown:!0}:void 0;return n?bo(e).map((s,a)=>s.type==="table"?t.jsx(yo,{table:s.table,opts:o},a):t.jsx(g.Fragment,{children:og(s.text,o)},a)):ft(e,void 0,o)}const ag=/^(#{1,6})\s+(.*)$/,lg=/^\*\*([^*\n]+)\*\*\s*$/;function jo(e){const n=e.match(ag);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(lg);return i?{level:3,text:i[1].trim()}:null}const vo=/^<!--.*-->$/;function _c(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function $c(e){return e.split(`
1264
+ `).map(n=>n.trim()).filter(n=>n&&!vo.test(n))}const cg=60;function Cc(e){let n=0,i=0;for(const o of e.split(`
1265
+ `)){const s=o.trim();if(!s||vo.test(s)||jo(s))continue;const a=s.replace(/<[^<>\n]*>|\u27e8[^\u27e9\n]*\u27e9/g,"").replace(/\s/g,"").length;n+=a,a>cg&&(i+=a)}return n>0&&i*2>=n}function dg(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Ai(e){if(e=dg(e),Cc(e))return"unknown";const n=_c(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>$c(s).length).filter(s=>s>0);if(i.length===0)return"unknown";const o=i.reduce((s,a)=>s+a,0)/i.length;return o<=4?"record":o>=8?"catalog":"unknown"}function pg(e){const n=e.split(`
1266
1266
  `),i=[];let o=null,s=[];const a=()=>{i.push({heading:o,body:s.join(`
1267
- `)}),s=[]};for(const l of n){const d=vo(l);if(d){a(),o={kind:"heading",level:d.level,text:d.text};continue}s.push(l)}return a(),i}function ta(e){const n=[];for(const i of e.split(`
1268
- `)){const o=vo(i);if(o){n.push({kind:"heading",level:o.level,text:o.text});continue}const s=i.trim();!s||ko.test(s)||n.push({kind:"body",text:i})}return n}function zc(e){if(!e)return[];const n=Mi(e);if(n==="unknown")return ta(e);const i=[];for(const{heading:o,body:s}of uh(e)){o&&i.push(o);const a=$c(s);if(a.length!==0){if(Tc(s)){i.push(...ta(s));continue}if(n==="record"){const l=a.join(" ");l&&i.push({kind:"body",text:l})}else for(const l of a){const d=Cc(l);d.length&&i.push({kind:"body",text:d.join(" ")})}}}return i}const mh={"「":"“","」":"”","『":"‘","』":"’"},gh={"“":"「","”":"」","‘":"『","’":"』"},hh=new Set(["《","》","〈","〉"]);function Nc(e,n){const i=n.quoteStyle==="modern"?mh:n.quoteStyle==="classic"?gh:null;let o="";for(const s of e)n.hideBookBrackets&&hh.has(s)||(o+=(i==null?void 0:i[s])??s);return o}const Ic=e=>e;function wo(e){return e.showWorks?e.bookTitleStyle==="bracket"?"bracket":Hm(e.properNameMode)?"wavy":"bracket":"none"}function Rc(e,n=Ic,i="wavy"){if(e.indexOf("《")<0)return n(e);const o=[],s=/《([^《》\n]+)》/g;let a=0,l=0,d;for(;d=s.exec(e);){d.index>a&&o.push(t.jsx(h.Fragment,{children:n(e.slice(a,d.index))},l++));const c=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(d[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]});o.push(i==="wavy"?t.jsx("span",{className:"bim-rd-pn",children:c},l++):t.jsx(h.Fragment,{children:c},l++)),a=d.index+d[0].length}return a===0?n(e):(a<e.length&&o.push(t.jsx(h.Fragment,{children:n(e.slice(a))},l++)),o)}function So(e,n={}){let i=n.renderText??Ic;const o=n.quoteStyle;if(o&&o!=="original"){const d=i;i=c=>d(Nc(c,{quoteStyle:o}))}const s=n.bookMarking??(n.properNames?"wavy":"bracket"),a=s==="bracket"?i:d=>Rc(d,i,s),l=n.gujiMarkdown?{gujiMarkdown:!0,t:n.t}:void 0;return xt(e,a,l)}function na(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,a)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${a}`):t.jsx(h.Fragment,{children:n(s)},`${i}-${a}`))}const dr=/^(#{1,6})\s+(.*)$/,fh=/^\s*<!--.*-->\s*$/;function Ec(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1269
- `)?"":n)}function xh(e){return e<=1?2:e===2?3:4}function bh(){let e=1;return n=>{const i=xh(n),o=Math.min(i,e+1);return e=o,{Tag:`h${o}`,className:`bim-rd-hl${i}`}}}function yi(e){return e?Mi(Ec(e))!=="unknown":!1}function yh(e){return/^\u3000{2}/.test(e)}const ia=e=>yh(e)?"bim-rd-noindent":void 0;function ra({text:e,mode:n,inline:i,dropTitle:o}){const s=Ec(e),a=(p,m,u)=>!!o&&u<=1&&p<=2&&m.trim()===o.trim(),l=bh();if(n==="paragraph"&&Mi(s)!=="unknown"){const p=zc(s);return t.jsx(t.Fragment,{children:p.map((m,u)=>{if(m.kind==="heading"){if(a(m.level??1,m.text,u))return null;const{Tag:g,className:f}=l(m.level??1);return t.jsx(g,{className:f,children:i(m.text)},u)}return t.jsx("p",{className:ia(m.text),children:na(m.text,i,u)},u)})})}const d=s.split(`
1270
- `);let c=0;return t.jsx(t.Fragment,{children:d.map((p,m)=>{const u=p.match(dr);if(u){const f=c++;if(a(u[1].length,u[2],f))return null;const{Tag:x,className:v}=l(u[1].length);return t.jsx(x,{className:v,children:i(u[2])},m)}if(!p.trim())return m>=2&&!!d[m-1].trim()&&!!d[m-2].trim()&&!dr.test(d[m-1])&&!dr.test(d[m-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},m):null;if(fh.test(p))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(p.trim())){const{Tag:f,className:x}=l(3);return t.jsx(f,{className:x,children:i(p.trim().slice(2,-2))},m)}return t.jsx("p",{className:ia(p),children:na(p,i,m)},m)})})}function jh(e){const{convert:n}=Me();return h.useMemo(()=>e?n(e):"",[e,n])}function _o({text:e,mode:n,tables:i=!1,gujiMarkdown:o=!1,properNames:s=!1,bookMarking:a,quoteStyle:l,renderText:d,dropTitle:c}){const p=jh(e),{t:m,convert:u}=te(),g=v=>So(v,{renderText:d,properNames:s,bookMarking:a,quoteStyle:l,gujiMarkdown:o,t:m}),f=o?{gujiMarkdown:!0,t:m}:void 0,x=c?u(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(ra,{text:p,mode:n,inline:g,dropTitle:x}):t.jsx(t.Fragment,{children:yo(p).map((v,y)=>v.type==="table"?t.jsx(jo,{table:v.table,opts:f},y):t.jsx(ra,{text:v.text,mode:n,inline:g,dropTitle:y===0?x:void 0},y))})}const oa={work:"work",book:"work",people:"people",person:"people",place:"place",office:"office",dynasty:"dynasty",reign:"reign"};function vh(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(oa,e)&&oa[e]||"other"}function Lr(e){if(!e)return null;const n=e.trim(),i=/^book-index:\/\/(?:[A-Za-z]+\/)*([0-9A-Za-z]+)\/?$/.exec(n);if(i)return i[1];const o=/^bid:\\{1,2}([0-9A-Za-z]+)$/.exec(n);return o?o[1]:/^[0-9A-Za-z]+$/.test(n)?n:null}function Ht(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Qe(e){return typeof e=="string"&&e?e:void 0}function kh(e){const n=e&&typeof e=="object"?e.candidates:void 0;if(!Array.isArray(n))return;const i=[];for(const o of n){if(!o||typeof o!="object"||Array.isArray(o))continue;const s=o,a={};Qe(s.entity_id)!==void 0&&(a.entity_id=Qe(s.entity_id)),Qe(s.canonical_name)!==void 0&&(a.canonical_name=Qe(s.canonical_name)),Ht(s.confidence)!==void 0&&(a.confidence=Ht(s.confidence)),i.push(a)}return i}const dn=e=>e.start!==void 0&&e.end!==void 0;function Lc(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.entities)?e.entities:[],i=[];return n.forEach((o,s)=>{if(!o||typeof o!="object")return;const a=o,l=a.span??{},d=a.target??{},c=Ht(l.start_offset)??Ht(a.start_offset),p=Ht(l.end_offset)??Ht(a.end_offset),m=c!==void 0&&p!==void 0&&c>=0&&p>c,u=a.anchor??{},g=Qe(u.start),f=Qe(u.end);if(!m&&!!!(g&&f))return;const v=Qe(d.status),y=v===void 0||v==="matched"?Lr(Qe(d.entity_id))??Lr(Qe(d.href))??void 0:void 0,_=Ht(d.confidence),b=kh(a.ambiguous);i.push({...g&&f?{anchor:{start:g,end:f}}:{},key:Qe(a.id)??`e${s}`,kind:vh(a.type),...m?{start:c,end:p}:{},text:Qe(a.text),targetId:y,canonicalName:Qe(d.canonical_name),confidence:Ht(a.confidence)??_,..._!==void 0?{targetConfidence:_}:{},...Qe(d.level)!==void 0?{targetLevel:Qe(d.level)}:{},...Qe(d.note)!==void 0?{targetNote:Qe(d.note)}:{},...Qe(a.group)!==void 0?{group:Qe(a.group)}:{},...b!==void 0?{candidates:b}:{}})}),i.sort((o,s)=>!dn(o)||!dn(s)?+!dn(o)-+!dn(s):o.start-s.start||s.end-o.end)}const wh=new Set(Array.from(`《》/<>\r
1271
-  ,。、;:?!「」『』()…—·`));function $o(e){return!wh.has(e)}function Ac(e,n,i=0){const o=[],s=Array.from(e);let a=0;for(const d of s)$o(d)&&o.push(a),a+=d.length;const l=[];for(const d of n){if(!dn(d))continue;const c=d.start-i,p=d.end-i;if(c<0||p>o.length||p<=c)continue;const m=o[p-1],u=e.codePointAt(m)>65535?2:1;l.push({...d,start:o[c],end:m+u})}return l}function Sh(e,n){return n.text?Array.from(e.slice(n.start,n.end)).filter($o).join("")===n.text:!0}function _h(e,n,i){if(!n.text)return null;let o=-1,s=Math.max(0,n.start-i);const a=n.start+i;for(;s<=a;){const l=e.indexOf(n.text,s);if(l<0||l>a)break;(o<0||Math.abs(l-n.start)<Math.abs(o-n.start))&&(o=l),s=l+1}return o<0?null:{...n,start:o,end:o+n.text.length}}function Mc(e,n,i=16){const o=[];for(const l of n){if(!dn(l))continue;let d={...l,start:Math.max(0,l.start),end:Math.min(e.length,l.end)};(d.end<=d.start||!Sh(e,d))&&(d=_h(e,l,i)),d&&o.push(d)}o.sort((l,d)=>l.start-d.start||d.end-l.end);const s=[];let a=0;for(const l of o)l.start<a||(l.start>a&&s.push({type:"text",text:e.slice(a,l.start),start:a}),s.push({type:"entity",text:e.slice(l.start,l.end),start:l.start,span:l}),a=l.end);return a<e.length&&s.push({type:"text",text:e.slice(a),start:a}),s}const $h={off:[],lite:["people","place","dynasty"],full:["people","place","dynasty","office","reign","other"]};function Ch(e,n,i){const o=(i==null?void 0:i.showWorks)!==!1,s=new Set($h[n]);return e.filter(a=>a.kind==="work"?o:s.has(a.kind))}function Th(e,n,i){const[o,s]=h.useState(null),[a,l]=h.useState(!1),d=h.useRef(0);return h.useEffect(()=>{const c=++d.current;if(!e||!n){s(null),l(!1);return}let p;try{p=e(n,i)}catch{s(null),l(!1);return}if(!p||typeof p.then!="function"){s(p??null),l(!1);return}l(!0),p.then(m=>{c===d.current&&s(m??null)}).catch(()=>{c===d.current&&s(null)}).finally(()=>{c===d.current&&l(!1)})},[e,n,i]),{images:o,loading:a}}function zh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(Up,e)?e:null}function Nh(e){if(e==="none")return{color:r("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r("quality-placeholder"),fontWeight:400}}const Ih={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Pc="\0";function Rh(e,n,i){const[o,s=""]=e.split(Pc);return t.jsxs(t.Fragment,{children:[o,t.jsx(Ll,{text:n,convert:i}),s]})}function yt(e){return typeof e!="string"?"":Ih[e]??e}const Eh=["〇","一","二","三","四","五","六","七","八","九"],sa=["","十","百","千"],Lh=["","萬","億"];function Co(e){if(e===0)return"〇";if(e<0)return`負${Co(-e)}`;const n=[];let i=e,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Ah(s,o>0)+Lh[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ah(e,n){const i=[];let o=e;for(;o>0;)i.unshift(o%10),o=Math.floor(o/10);let s="";for(let a=0;a<i.length;a++){const l=i[a],d=i.length-1-a;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&d===1&&a===0&&!n?s+=sa[d]:s+=Eh[l]+sa[d]}return s.replace(/〇$/,"")}let An=null,si=null;const ji=new Set;function Mh(){return An?Promise.resolve():si||(si=import("opencc-js/t2cn").then(e=>{const n=e.Converter({from:"t",to:"cn"});An=i=>n(_e.normalizeVariants(i)),ji.forEach(i=>i())}).catch(()=>{An=e=>e,ji.forEach(e=>e())}),si)}const Ph=e=>e;function rn(){const[,e]=h.useState(0);return h.useEffect(()=>{if(An)return;const n=()=>e(i=>i+1);return ji.add(n),Mh(),()=>{ji.delete(n)}},[]),An??Ph}function hn(e,n){return n(e).toLowerCase()}const Bh=r("highlight-bg");function Dn(e,n,i){if(!n)return e;const o=hn(n,i);if(!o)return e;const s=hn(e,i),a=Array.from(e),l=Array.from(s);if(l.length!==a.length)return e;const d=new Map;let c=0;l.forEach((x,v)=>{d.set(c,v),c+=x.length});const p=Array.from(o).length,m=[];let u=0,g=0,f=0;for(;u<a.length;){const x=s.indexOf(o,g),v=x===-1?void 0:d.get(x);if(x===-1){m.push(a.slice(u).join(""));break}if(v===void 0){g=x+1;continue}v>u&&m.push(a.slice(u,v).join("")),m.push(t.jsx("mark",{style:{background:Bh,padding:0,color:"inherit"},children:a.slice(v,v+p).join("")},f++)),u=v+p,g=x+o.length}return t.jsx(t.Fragment,{children:m})}function To(e,n,i,o){if(!n)return!0;const s=hn(n,o);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(l=>typeof l=="string"&&hn(l,o).includes(s))}function Wh(e,n,i){return n?hn(e,i).includes(hn(n,i)):!0}const zo={类:r("section-lei"),书:r("section-shu"),序:r("section-xu"),结语:r("section-jieyu"),注释:r("section-zhushi")},Oh={考证:r("section-kaozhen")};function No(e,n,i){return e.collated.sectionType[n]??i(n)}function Bc(e){var o;const n=e.files.length,i=((o=e.children)==null?void 0:o.reduce((s,a)=>s+Bc(a),0))||0;return n+i}function Fh(e,n){const i=[],o=l=>{var d;i.push(...l.files),(d=l.children)==null||d.forEach(o)};if(o(e),i.length===0)return;const s=i.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let a=0;for(const l of s)typeof l=="number"&&(a+=l);return a}const Hh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Io({enabled:e,expanded:n,onClick:i,style:o,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Hh,...o},children:s}):t.jsx("span",{style:o,children:s})}function Dh({type:e}){const{convert:n,messages:i}=te(),o=yt(e),s=zo[o]||r("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:s,border:`1px solid ${s}40`,borderRadius:"2px",background:`${s}08`,flexShrink:0},children:No(i,o,n)})}function Uh({section:e,onNavigate:n,highlightQuery:i="",no:o,showUnlinked:s=!1,domId:a}){const{t:l,convert:d}=te(),c=tt(),p=rn(),m=w=>w?xt(d(w),j=>i?Dn(j,i,p):j,{t:l}):"",[u,g]=h.useState(!1),f=!!e.summary,x=!!e.comment,v=!!e.additional_comment,y=!!(e.content&&e.content.length>60),_=f||x||v||y;h.useEffect(()=>{i&&g(!0)},[i]);const b=!u&&y?fc(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${r("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>_&&g(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:_?"pointer":"default",userSelect:"none"},children:[o!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:r("label-fg")},children:o}),t.jsxs(Io,{enabled:_,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[_&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:r("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",m(e.book_title),"》"]}):m(e.title),e.n_juan!=null&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d(Co(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:r("desc-fg"),marginLeft:"8px"},children:m(e.author_info||e.author)})]}),!u&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:r("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:m(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:m(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:r("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:c(e.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:l("collated.viewWork"),"aria-label":l("collated.viewWorkOf",{title:d(e.book_title||e.title)}),children:l("collated.workArrow")}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:r("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),u&&_&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${r("widget-border")}`,background:r("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:r("desc-fg"),marginBottom:"8px"},children:m(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",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:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:m(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"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:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:m(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{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:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:m(e.additional_comment)})]}),y&&!f&&!x&&!v&&t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:m(e.content)})]})]})}function Vh({section:e,highlightQuery:n=""}){const{t:i,convert:o}=te(),s=rn(),a=p=>p?xt(o(p),m=>n?Dn(m,n,s):m,{t:i}):"",[l,d]=h.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Io,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Dh,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:r("fg")},children:a(e.title)}),c&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&c&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${zo[yt(e.type)]||r("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:r("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})})]})}const Gh=100;function Ro(e){return yt(e.type)!=="page_header"?!1:(e.content||"").length>=Gh}function Yh({section:e,highlightQuery:n=""}){const{t:i,convert:o,messages:s}=te(),a=rn();if(yt(e.type)==="page_header"&&!Ro(e)||!e.content&&!e.title)return null;const l=o((e.content||e.title||"").replace(/\n{2,}/g,`
1272
- `)),d=xt(l,u=>n?Dn(u,n,a):u,{t:i}),c=yt(e.type),p=zo[c]||r("desc-fg"),m=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:m?"10px 12px":"6px 0",margin:m?"8px 0":void 0,fontSize:"13px",color:r("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:m?`3px solid ${p}40`:void 0,background:m?r("bg"):void 0,borderRadius:m?"0 4px 4px 0":void 0,position:"relative"},children:[m&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:No(s,c,o)}),d]})}function qh(e,n,i){const[o,s]=h.useState({});return h.useEffect(()=>{var p;if(!n||e.length===0)return;let a=!1;const l=e.filter(m=>{var u;return!((u=i==null?void 0:i.current)!=null&&u.has(m))}),d={};for(const m of e)(p=i==null?void 0:i.current)!=null&&p.has(m)&&(d[m]=i.current.get(m));if(Object.keys(d).length>0&&s(d),l.length===0)return;const c=async m=>{var u;try{if(n.getEntry){const y=await n.getEntry(m);if(y)return{title:y.title,author:y.author}}const g=await n.getItem(m);if(!g)return null;const f=g.title||m,x=g.authors,v=(u=x==null?void 0:x[0])==null?void 0:u.name;return{title:f,author:v}}catch{return null}};return Promise.all(l.map(async m=>{var g;const u=await c(m);return(g=i==null?void 0:i.current)==null||g.set(m,u),[m,u]})).then(m=>{a||s(u=>{const g={...u};for(const[f,x]of m)g[f]=x;return g})}),()=>{a=!0}},[e.join(","),n]),o}function Kh({section:e,onNavigate:n,transport:i,workLabelCache:o,highlightQuery:s=""}){const{t:a,convert:l,messages:d}=te(),c=tt(),p=rn(),m=j=>j?xt(l(j),k=>s?Dn(k,s,p):k,{t:a}):"",[u,g]=h.useState(!1);h.useEffect(()=>{s&&g(!0)},[s]);const f=yt(e.type),x=Oh[f]||r("desc-fg"),v=!!e.content,y=e.work_ids||[],_=y.length>1,b=qh(_?y:[],i,o),w=v&&!u&&e.content.length>80?fc(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${r("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>v&&g(!u),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:v?"pointer":"default",userSelect:"none"},children:[t.jsxs(Io,{enabled:v,expanded:u,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[v&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:r("fg"),lineHeight:1.6},children:e.header_line?m(e.header_line):m(e.title)}),!u&&w&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r("desc-fg"),lineHeight:1.7},children:m(w)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[y.length===1&&n&&t.jsx("a",{href:c(y[0]),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(y[0]))},style:{fontSize:"11px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),_&&t.jsx("span",{style:{fontSize:"11px",color:r("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:y.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:No(d,f,l)})]})]}),_&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:y.map(j=>{const k=b[j],C=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:j.slice(0,8)+"…";return t.jsxs("a",{href:c(j),onClick:$=>{$.metaKey||$.ctrlKey||($.preventDefault(),$.stopPropagation(),n(j))},style:{fontSize:"12px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:j,children:["→",C]},j)})}),u&&v&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:r("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:m(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${r("widget-border")}`,fontSize:"12px",color:r("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:m(e.comment)})]})]})}function Xh({juan:e,searchQuery:n,onNavigate:i,transport:o,workLabelCache:s}){const{t:a}=te(),l=rn(),d=n.trim(),c=h.useMemo(()=>d?e.sections.filter(p=>To(p,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:c.map((p,m)=>t.jsx(Kh,{section:p,onNavigate:i,transport:o,workLabelCache:s,highlightQuery:d},m))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function Zh(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Jh({sections:e,onNavigate:n,inline:i,workLinks:o=!0}){const s=tt(),{t:a,convert:l}=te(),d=Zh();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const m=yt(c.type);if(m==="page_header"&&!Ro(c))return null;if(m==="类")return t.jsxs(h.Fragment,{children:[h.createElement(d("类"),null,i(l(c.title))),c.content&&t.jsx("p",{children:i(l(c.content))})]},p);if(m==="书"||m==="诗"||m==="考证"||m==="注释"){const u=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:Co(c.n_juan)}):""}`:c.title,g=i(l(u));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${p}`,children:[h.createElement(d("条目"),{className:"bim-rd-entry-h"},c.work_id&&n&&o?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:a("collated.viewWork"),children:g}),t.jsx("a",{className:"bim-rd-wl",href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(u)}),children:a("collated.workArrow")})]}):g),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:i(l(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.summary")}),i(l(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.comment")}),i(l(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.additionalComment")}),i(l(c.additional_comment))]})]},p)}return m==="小计"&&c.title?t.jsx("p",{children:i(l(c.title))},p):c.content?t.jsx("p",{children:i(l(c.content))},p):null})})}function Wc(e){return e.some(n=>{const i=yt(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Ro(n)})}function Qh({juan:e,rawText:n,positionLabel:i,groupLabel:o,index:s,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:p,view:m,onViewChange:u}){var xe;const{t:g,convert:f,messages:x}=te(),v=rn(),[y,_]=h.useState("text"),b=m??y,w=ee=>{_(ee),u==null||u(ee)},j=a.trim(),k=(s==null?void 0:s.type)==="kaozhen",C=h.useCallback(ee=>j?Dn(ee,j,v):ee,[j,v]),$=wo(p),S=ee=>So(ee,{renderText:C,bookMarking:$,quoteStyle:p.quoteStyle,t:g}),M=h.useMemo(()=>j?e.sections.filter(ee=>To(ee,j,k,v)):e.sections,[e.sections,j,k,v]),z=(ee,L)=>L.filter(Re=>yt(Re.type)===ee).length,T=z("书",e.sections),P=z("诗",e.sections),R=z("考证",e.sections);let N="";k?N=j?g("collated.countTiaoOf",{m:z("考证",M),n:R}):g("collated.countTiao",{n:R}):P>0?N=j?g("collated.countPoemsOf",{m:z("诗",M),n:P}):g("collated.countPoems",{n:P}):T>0&&(N=j?g("collated.countBooksOf",{m:z("书",M),n:T}):g("collated.countBooks",{n:T}));const A=s!=null&&s.text_quality?zh(s.text_quality.grade):null,H=[];if(N&&H.push(N),k&&(s!=null&&s.target_source)&&H.push(t.jsx(t.Fragment,{children:g("collated.kaozhenTarget",{target:f(s.target_source)})})),A){const ee=t.jsx("span",{className:"bim-rd-grade",style:Nh(A),children:x.collated.qualityLabel[A]});H.push(t.jsx("span",{title:x.collated.qualityCriteria[A],children:(xe=s==null?void 0:s.text_quality)!=null&&xe.source_note?t.jsxs(t.Fragment,{children:[Rh(g("collated.baseText",{note:Pc}),s.text_quality.source_note,f),ee]}):t.jsxs(t.Fragment,{children:[g("collated.textQuality"),ee]})}))}e.source_url&&H.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:g("collated.originalSource")}));const G=!k&&Wc(e.sections),ie=!!n&&(!G||p.readingMode==="paragraph"&&yi(n)),le=!k&&(G||!!n),V=k||!le?"entries":b;let F=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(i||o)&&t.jsxs("p",{className:"bim-rd-kicker",children:[i,i&&o&&t.jsx("span",{className:"bim-rd-dot"}),o&&f(o)]}),t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),H.length>0&&t.jsx("p",{className:"bim-rd-meta",children:H.map((ee,L)=>t.jsxs(h.Fragment,{children:[L>0&&t.jsx("span",{className:"bim-rd-dot"}),ee]},L))}),le&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":g("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":V==="text",onClick:()=>w("text"),children:g("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":V==="entries",onClick:()=>w("entries"),children:g("collated.viewEntries")})]})]}),V==="text"&&t.jsx("article",{className:"bim-rd-prose",children:ie?t.jsx(_o,{text:n,mode:p.readingMode,bookMarking:$,quoteStyle:p.quoteStyle,renderText:C,dropTitle:e.title}):t.jsx(Jh,{sections:e.sections,onNavigate:l,inline:S,workLinks:p.workLinks})}),V==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:k?t.jsx(Xh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[M.some(ee=>["书","诗","考证"].includes(yt(ee.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:g("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:g("collated.rowHeadTitle")}),t.jsx("span",{children:g("collated.rowHeadWork")})]}),M.map((ee,L)=>{const Re=yt(ee.type);return Re==="书"||Re==="诗"||Re==="考证"?(F+=1,t.jsx(Uh,{domId:`rd-e-${e.sections.indexOf(ee)}`,section:ee,onNavigate:p.workLinks?l:void 0,highlightQuery:j,no:F,showUnlinked:p.workLinks&&!!l},L)):Re==="类"?t.jsx(Vh,{section:ee,highlightQuery:j},L):t.jsx(Yh,{section:ee,highlightQuery:j},L)}),M.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:g("collated.noMatch")})]})})]})}function ef(e){const{resetKey:n,load:i,files:o,activeFile:s,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,p=rn(),m=h.useRef(new Map),[u,g]=h.useState({}),[f,x]=h.useState({}),v=h.useCallback((_,b)=>{const w=b==null?void 0:b.title;w&&x(j=>j[_]===w?j:{...j,[_]:w})},[]);h.useEffect(()=>{s&&a&&(m.current.set(s,{juan:a,rawText:l}),v(s,a))},[s,a,l,v]),h.useEffect(()=>{m.current.clear(),g({}),x({})},[n]);const y=h.useCallback((_,b)=>{let w=0;if(_.juan)for(const j of _.juan.sections)To(j,b,c,p)&&w++;return w===0&&_.rawText&&Wh(_.rawText,b,p)&&(w=1),w},[c,p]);return h.useEffect(()=>{const _=d.trim();if(!_){g({});return}if(!i||o.length===0)return;let b=!1;const w={},j=[];for(const M of o){const z=m.current.get(M);z?w[M]=y(z,_):(w[M]="loading",j.push(M))}g(w);const k=8;let C=0;const $=async()=>{for(;C<j.length;){if(b)return;const M=C++,z=j[M];try{const T=await i(z),P=T.juan;if(m.current.set(z,T),v(z,P),b)return;g(R=>({...R,[z]:y(T,_)}))}catch{if(b)return;g(T=>({...T,[z]:0}))}}},S=Array.from({length:Math.min(k,j.length)},()=>$());return Promise.all(S),()=>{b=!0}},[d,n,i,o.join(","),y,p,v]),{matchStates:u,titles:f}}function tf({juan:e,view:n,onView:i,textHasEntries:o}){const{t:s,convert:a}=te(),l=e.sections.map((m,u)=>({s:m,i:u,t:yt(m.type)})).filter(m=>m.t==="书"||m.t==="诗");if(l.length===0)return null;const d=l.filter(m=>!!m.s.work_id).length,c=l.every(m=>m.t==="诗")?s("collated.railUnitPoems"):s("collated.railUnitBooks"),p=m=>{const u=()=>{var g,f;return(f=(g=document.getElementById(`rd-e-${m}`))==null?void 0:g.scrollIntoView)==null?void 0:f.call(g,{block:"start",behavior:"smooth"})};n==="text"&&!o&&i("entries"),n==="text"&&!o?setTimeout(u,0):u()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:s("collated.railCap")}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:c}),t.jsx("span",{className:"bim-rd-rail-linked",children:s("collated.linkedN",{n:d})})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":s("collated.linkedOf",{n:d,total:l.length}),children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":s("collated.railEntriesNav"),children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("collated.viewEntries")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:m,i:u})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${u}`,onClick:g=>{g.preventDefault(),p(u)},children:[t.jsx("span",{className:`bim-rd-rail-dot${m.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:a(m.book_title||m.title)})]})},u))})]})]})}const nf=`
1267
+ `)}),s=[]};for(const l of n){const d=jo(l);if(d){a(),o={kind:"heading",level:d.level,text:d.text};continue}s.push(l)}return a(),i}function ea(e){const n=[];for(const i of e.split(`
1268
+ `)){const o=jo(i);if(o){n.push({kind:"heading",level:o.level,text:o.text});continue}const s=i.trim();!s||vo.test(s)||n.push({kind:"body",text:i})}return n}function Tc(e){if(!e)return[];const n=Ai(e);if(n==="unknown")return ea(e);const i=[];for(const{heading:o,body:s}of pg(e)){o&&i.push(o);const a=_c(s);if(a.length!==0){if(Cc(s)){i.push(...ea(s));continue}if(n==="record"){const l=a.join(" ");l&&i.push({kind:"body",text:l})}else for(const l of a){const d=$c(l);d.length&&i.push({kind:"body",text:d.join(" ")})}}}return i}const ug={"「":"“","」":"”","『":"‘","』":"’"},mg={"“":"「","”":"」","‘":"『","’":"』"},hg=new Set(["《","》","〈","〉"]);function zc(e,n){const i=n.quoteStyle==="modern"?ug:n.quoteStyle==="classic"?mg:null;let o="";for(const s of e)n.hideBookBrackets&&hg.has(s)||(o+=(i==null?void 0:i[s])??s);return o}const Nc=e=>e;function ko(e){return e.showWorks?e.bookTitleStyle==="bracket"?"bracket":Fm(e.properNameMode)?"wavy":"bracket":"none"}function Ic(e,n=Nc,i="wavy"){if(e.indexOf("《")<0)return n(e);const o=[],s=/《([^《》\n]+)》/g;let a=0,l=0,d;for(;d=s.exec(e);){d.index>a&&o.push(t.jsx(g.Fragment,{children:n(e.slice(a,d.index))},l++));const c=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),n(d[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]});o.push(i==="wavy"?t.jsx("span",{className:"bim-rd-pn",children:c},l++):t.jsx(g.Fragment,{children:c},l++)),a=d.index+d[0].length}return a===0?n(e):(a<e.length&&o.push(t.jsx(g.Fragment,{children:n(e.slice(a))},l++)),o)}function wo(e,n={}){let i=n.renderText??Nc;const o=n.quoteStyle;if(o&&o!=="original"){const d=i;i=c=>d(zc(c,{quoteStyle:o}))}const s=n.bookMarking??(n.properNames?"wavy":"bracket"),a=s==="bracket"?i:d=>Ic(d,i,s),l=n.gujiMarkdown?{gujiMarkdown:!0,t:n.t}:void 0;return ft(e,a,l)}function ta(e,n,i){return e.indexOf("**")<0?n(e):e.split(/(\*\*[^*]+\*\*)/g).map((s,a)=>s.startsWith("**")&&s.endsWith("**")&&s.length>4?t.jsx("strong",{children:n(s.slice(2,-2))},`${i}-${a}`):t.jsx(g.Fragment,{children:n(s)},`${i}-${a}`))}const cr=/^(#{1,6})\s+(.*)$/,gg=/^\s*<!--.*-->\s*$/;function Rc(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1269
+ `)?"":n)}function fg(e){return e<=1?2:e===2?3:4}function xg(){let e=1;return n=>{const i=fg(n),o=Math.min(i,e+1);return e=o,{Tag:`h${o}`,className:`bim-rd-hl${i}`}}}function bi(e){return e?Ai(Rc(e))!=="unknown":!1}function bg(e){return/^\u3000{2}/.test(e)}const na=e=>bg(e)?"bim-rd-noindent":void 0;function ia({text:e,mode:n,inline:i,dropTitle:o}){const s=Rc(e),a=(p,h,u)=>!!o&&u<=1&&p<=2&&h.trim()===o.trim(),l=xg();if(n==="paragraph"&&Ai(s)!=="unknown"){const p=Tc(s);return t.jsx(t.Fragment,{children:p.map((h,u)=>{if(h.kind==="heading"){if(a(h.level??1,h.text,u))return null;const{Tag:m,className:f}=l(h.level??1);return t.jsx(m,{className:f,children:i(h.text)},u)}return t.jsx("p",{className:na(h.text),children:ta(h.text,i,u)},u)})})}const d=s.split(`
1270
+ `);let c=0;return t.jsx(t.Fragment,{children:d.map((p,h)=>{const u=p.match(cr);if(u){const f=c++;if(a(u[1].length,u[2],f))return null;const{Tag:x,className:v}=l(u[1].length);return t.jsx(x,{className:v,children:i(u[2])},h)}if(!p.trim())return h>=2&&!!d[h-1].trim()&&!!d[h-2].trim()&&!cr.test(d[h-1])&&!cr.test(d[h-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},h):null;if(gg.test(p))return null;if(c++,/^\*\*[^*]+\*\*\s*$/.test(p.trim())){const{Tag:f,className:x}=l(3);return t.jsx(f,{className:x,children:i(p.trim().slice(2,-2))},h)}return t.jsx("p",{className:na(p),children:ta(p,i,h)},h)})})}function yg(e){const{convert:n}=Be();return g.useMemo(()=>e?n(e):"",[e,n])}function So({text:e,mode:n,tables:i=!1,gujiMarkdown:o=!1,properNames:s=!1,bookMarking:a,quoteStyle:l,renderText:d,dropTitle:c}){const p=yg(e),{t:h,convert:u}=ne(),m=v=>wo(v,{renderText:d,properNames:s,bookMarking:a,quoteStyle:l,gujiMarkdown:o,t:h}),f=o?{gujiMarkdown:!0,t:h}:void 0,x=c?u(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(ia,{text:p,mode:n,inline:m,dropTitle:x}):t.jsx(t.Fragment,{children:bo(p).map((v,y)=>v.type==="table"?t.jsx(yo,{table:v.table,opts:f},y):t.jsx(ia,{text:v.text,mode:n,inline:m,dropTitle:y===0?x:void 0},y))})}const ra={work:"work",book:"work",people:"people",person:"people",place:"place",office:"office",dynasty:"dynasty",reign:"reign"};function jg(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(ra,e)&&ra[e]||"other"}function Er(e){if(!e)return null;const n=e.trim(),i=/^book-index:\/\/(?:[A-Za-z]+\/)*([0-9A-Za-z]+)\/?$/.exec(n);if(i)return i[1];const o=/^bid:\\{1,2}([0-9A-Za-z]+)$/.exec(n);return o?o[1]:/^[0-9A-Za-z]+$/.test(n)?n:null}function Dt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Qe(e){return typeof e=="string"&&e?e:void 0}function vg(e){const n=e&&typeof e=="object"?e.candidates:void 0;if(!Array.isArray(n))return;const i=[];for(const o of n){if(!o||typeof o!="object"||Array.isArray(o))continue;const s=o,a={};Qe(s.entity_id)!==void 0&&(a.entity_id=Qe(s.entity_id)),Qe(s.canonical_name)!==void 0&&(a.canonical_name=Qe(s.canonical_name)),Dt(s.confidence)!==void 0&&(a.confidence=Dt(s.confidence)),i.push(a)}return i}const dn=e=>e.start!==void 0&&e.end!==void 0;function Ec(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.entities)?e.entities:[],i=[];return n.forEach((o,s)=>{if(!o||typeof o!="object")return;const a=o,l=a.span??{},d=a.target??{},c=Dt(l.start_offset)??Dt(a.start_offset),p=Dt(l.end_offset)??Dt(a.end_offset),h=c!==void 0&&p!==void 0&&c>=0&&p>c,u=a.anchor??{},m=Qe(u.start),f=Qe(u.end);if(!h&&!!!(m&&f))return;const v=Qe(d.status),y=v===void 0||v==="matched"?Er(Qe(d.entity_id))??Er(Qe(d.href))??void 0:void 0,S=Dt(d.confidence),b=vg(a.ambiguous);i.push({...m&&f?{anchor:{start:m,end:f}}:{},key:Qe(a.id)??`e${s}`,kind:jg(a.type),...h?{start:c,end:p}:{},text:Qe(a.text),targetId:y,canonicalName:Qe(d.canonical_name),confidence:Dt(a.confidence)??S,...S!==void 0?{targetConfidence:S}:{},...Qe(d.level)!==void 0?{targetLevel:Qe(d.level)}:{},...Qe(d.note)!==void 0?{targetNote:Qe(d.note)}:{},...Qe(a.group)!==void 0?{group:Qe(a.group)}:{},...b!==void 0?{candidates:b}:{}})}),i.sort((o,s)=>!dn(o)||!dn(s)?+!dn(o)-+!dn(s):o.start-s.start||s.end-o.end)}const kg=new Set(Array.from(`《》/<>\r
1271
+  ,。、;:?!「」『』()…—·`));function _o(e){return!kg.has(e)}function Lc(e,n,i=0){const o=[],s=Array.from(e);let a=0;for(const d of s)_o(d)&&o.push(a),a+=d.length;const l=[];for(const d of n){if(!dn(d))continue;const c=d.start-i,p=d.end-i;if(c<0||p>o.length||p<=c)continue;const h=o[p-1],u=e.codePointAt(h)>65535?2:1;l.push({...d,start:o[c],end:h+u})}return l}function wg(e,n){return n.text?Array.from(e.slice(n.start,n.end)).filter(_o).join("")===n.text:!0}function Sg(e,n,i){if(!n.text)return null;let o=-1,s=Math.max(0,n.start-i);const a=n.start+i;for(;s<=a;){const l=e.indexOf(n.text,s);if(l<0||l>a)break;(o<0||Math.abs(l-n.start)<Math.abs(o-n.start))&&(o=l),s=l+1}return o<0?null:{...n,start:o,end:o+n.text.length}}function Ac(e,n,i=16){const o=[];for(const l of n){if(!dn(l))continue;let d={...l,start:Math.max(0,l.start),end:Math.min(e.length,l.end)};(d.end<=d.start||!wg(e,d))&&(d=Sg(e,l,i)),d&&o.push(d)}o.sort((l,d)=>l.start-d.start||d.end-l.end);const s=[];let a=0;for(const l of o)l.start<a||(l.start>a&&s.push({type:"text",text:e.slice(a,l.start),start:a}),s.push({type:"entity",text:e.slice(l.start,l.end),start:l.start,span:l}),a=l.end);return a<e.length&&s.push({type:"text",text:e.slice(a),start:a}),s}const _g={off:[],lite:["people","place","dynasty"],full:["people","place","dynasty","office","reign","other"]};function $g(e,n,i){const o=(i==null?void 0:i.showWorks)!==!1,s=new Set(_g[n]);return e.filter(a=>a.kind==="work"?o:s.has(a.kind))}function Cg(e,n,i){const[o,s]=g.useState(null),[a,l]=g.useState(!1),d=g.useRef(0);return g.useEffect(()=>{const c=++d.current;if(!e||!n){s(null),l(!1);return}let p;try{p=e(n,i)}catch{s(null),l(!1);return}if(!p||typeof p.then!="function"){s(p??null),l(!1);return}l(!0),p.then(h=>{c===d.current&&s(h??null)}).catch(()=>{c===d.current&&s(null)}).finally(()=>{c===d.current&&l(!1)})},[e,n,i]),{images:o,loading:a}}function Tg(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(Dp,e)?e:null}function zg(e){if(e==="none")return{color:r("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r("quality-placeholder"),fontWeight:400}}const Ng={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Mc="\0";function Ig(e,n,i){const[o,s=""]=e.split(Mc);return t.jsxs(t.Fragment,{children:[o,t.jsx(El,{text:n,convert:i}),s]})}function bt(e){return typeof e!="string"?"":Ng[e]??e}const Rg=["〇","一","二","三","四","五","六","七","八","九"],oa=["","十","百","千"],Eg=["","萬","億"];function $o(e){if(e===0)return"〇";if(e<0)return`負${$o(-e)}`;const n=[];let i=e,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Lg(s,o>0)+Eg[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Lg(e,n){const i=[];let o=e;for(;o>0;)i.unshift(o%10),o=Math.floor(o/10);let s="";for(let a=0;a<i.length;a++){const l=i[a],d=i.length-1-a;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&d===1&&a===0&&!n?s+=oa[d]:s+=Rg[l]+oa[d]}return s.replace(/〇$/,"")}let An=null,oi=null;const yi=new Set;function Ag(){return An?Promise.resolve():oi||(oi=import("opencc-js/t2cn").then(e=>{const n=e.Converter({from:"t",to:"cn"});An=i=>n(Se.normalizeVariants(i)),yi.forEach(i=>i())}).catch(()=>{An=e=>e,yi.forEach(e=>e())}),oi)}const Mg=e=>e;function rn(){const[,e]=g.useState(0);return g.useEffect(()=>{if(An)return;const n=()=>e(i=>i+1);return yi.add(n),Ag(),()=>{yi.delete(n)}},[]),An??Mg}function gn(e,n){return n(e).toLowerCase()}const Pg=r("highlight-bg");function Dn(e,n,i){if(!n)return e;const o=gn(n,i);if(!o)return e;const s=gn(e,i),a=Array.from(e),l=Array.from(s);if(l.length!==a.length)return e;const d=new Map;let c=0;l.forEach((x,v)=>{d.set(c,v),c+=x.length});const p=Array.from(o).length,h=[];let u=0,m=0,f=0;for(;u<a.length;){const x=s.indexOf(o,m),v=x===-1?void 0:d.get(x);if(x===-1){h.push(a.slice(u).join(""));break}if(v===void 0){m=x+1;continue}v>u&&h.push(a.slice(u,v).join("")),h.push(t.jsx("mark",{style:{background:Pg,padding:0,color:"inherit"},children:a.slice(v,v+p).join("")},f++)),u=v+p,m=x+o.length}return t.jsx(t.Fragment,{children:h})}function Co(e,n,i,o){if(!n)return!0;const s=gn(n,o);return(i?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(l=>typeof l=="string"&&gn(l,o).includes(s))}function Bg(e,n,i){return n?gn(e,i).includes(gn(n,i)):!0}const To={类:r("section-lei"),书:r("section-shu"),序:r("section-xu"),结语:r("section-jieyu"),注释:r("section-zhushi")},Wg={考证:r("section-kaozhen")};function zo(e,n,i){return e.collated.sectionType[n]??i(n)}function Pc(e){var o;const n=e.files.length,i=((o=e.children)==null?void 0:o.reduce((s,a)=>s+Pc(a),0))||0;return n+i}function Og(e,n){const i=[],o=l=>{var d;i.push(...l.files),(d=l.children)==null||d.forEach(o)};if(o(e),i.length===0)return;const s=i.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let a=0;for(const l of s)typeof l=="number"&&(a+=l);return a}const Fg={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function No({enabled:e,expanded:n,onClick:i,style:o,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Fg,...o},children:s}):t.jsx("span",{style:o,children:s})}function Hg({type:e}){const{convert:n,messages:i}=ne(),o=bt(e),s=To[o]||r("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:s,border:`1px solid ${s}40`,borderRadius:"2px",background:`${s}08`,flexShrink:0},children:zo(i,o,n)})}function Dg({section:e,onNavigate:n,highlightQuery:i="",no:o,showUnlinked:s=!1,domId:a}){const{t:l,convert:d}=ne(),c=tt(),p=rn(),h=w=>w?ft(d(w),j=>i?Dn(j,i,p):j,{t:l}):"",[u,m]=g.useState(!1),f=!!e.summary,x=!!e.comment,v=!!e.additional_comment,y=!!(e.content&&e.content.length>60),S=f||x||v||y;g.useEffect(()=>{i&&m(!0)},[i]);const b=!u&&y?gc(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${r("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>S&&m(!u),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:S?"pointer":"default",userSelect:"none"},children:[o!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:r("label-fg")},children:o}),t.jsxs(No,{enabled:S,expanded:u,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[S&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:r("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",h(e.book_title),"》"]}):h(e.title),e.n_juan!=null&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d($o(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:r("desc-fg"),marginLeft:"8px"},children:h(e.author_info||e.author)})]}),!u&&b&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:r("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:h(b)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:h(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:r("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&n&&t.jsx("a",{href:c(e.work_id),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(e.work_id))},style:{fontSize:"11px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:l("collated.viewWork"),"aria-label":l("collated.viewWorkOf",{title:d(e.book_title||e.title)}),children:l("collated.workArrow")}),s&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:r("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),u&&S&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${r("widget-border")}`,background:r("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:r("desc-fg"),marginBottom:"8px"},children:h(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",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:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:h(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"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:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:h(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{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:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:h(e.additional_comment)})]}),y&&!f&&!x&&!v&&t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:h(e.content)})]})]})}function Ug({section:e,highlightQuery:n=""}){const{t:i,convert:o}=ne(),s=rn(),a=p=>p?ft(o(p),h=>n?Dn(h,n,s):h,{t:i}):"",[l,d]=g.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(No,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Hg,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:r("fg")},children:a(e.title)}),c&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&c&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${To[bt(e.type)]||r("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:r("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})})]})}const Vg=100;function Io(e){return bt(e.type)!=="page_header"?!1:(e.content||"").length>=Vg}function Gg({section:e,highlightQuery:n=""}){const{t:i,convert:o,messages:s}=ne(),a=rn();if(bt(e.type)==="page_header"&&!Io(e)||!e.content&&!e.title)return null;const l=o((e.content||e.title||"").replace(/\n{2,}/g,`
1272
+ `)),d=ft(l,u=>n?Dn(u,n,a):u,{t:i}),c=bt(e.type),p=To[c]||r("desc-fg"),h=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:h?"10px 12px":"6px 0",margin:h?"8px 0":void 0,fontSize:"13px",color:r("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:h?`3px solid ${p}40`:void 0,background:h?r("bg"):void 0,borderRadius:h?"0 4px 4px 0":void 0,position:"relative"},children:[h&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:p,marginRight:"8px",padding:"1px 5px",border:`1px solid ${p}40`,borderRadius:"2px",background:`${p}08`,verticalAlign:"middle"},children:zo(s,c,o)}),d]})}function Yg(e,n,i){const[o,s]=g.useState({});return g.useEffect(()=>{var p;if(!n||e.length===0)return;let a=!1;const l=e.filter(h=>{var u;return!((u=i==null?void 0:i.current)!=null&&u.has(h))}),d={};for(const h of e)(p=i==null?void 0:i.current)!=null&&p.has(h)&&(d[h]=i.current.get(h));if(Object.keys(d).length>0&&s(d),l.length===0)return;const c=async h=>{var u;try{if(n.getEntry){const y=await n.getEntry(h);if(y)return{title:y.title,author:y.author}}const m=await n.getItem(h);if(!m)return null;const f=m.title||h,x=m.authors,v=(u=x==null?void 0:x[0])==null?void 0:u.name;return{title:f,author:v}}catch{return null}};return Promise.all(l.map(async h=>{var m;const u=await c(h);return(m=i==null?void 0:i.current)==null||m.set(h,u),[h,u]})).then(h=>{a||s(u=>{const m={...u};for(const[f,x]of h)m[f]=x;return m})}),()=>{a=!0}},[e.join(","),n]),o}function qg({section:e,onNavigate:n,transport:i,workLabelCache:o,highlightQuery:s=""}){const{t:a,convert:l,messages:d}=ne(),c=tt(),p=rn(),h=j=>j?ft(l(j),k=>s?Dn(k,s,p):k,{t:a}):"",[u,m]=g.useState(!1);g.useEffect(()=>{s&&m(!0)},[s]);const f=bt(e.type),x=Wg[f]||r("desc-fg"),v=!!e.content,y=e.work_ids||[],S=y.length>1,b=Yg(S?y:[],i,o),w=v&&!u&&e.content.length>80?gc(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${r("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>v&&m(!u),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:v?"pointer":"default",userSelect:"none"},children:[t.jsxs(No,{enabled:v,expanded:u,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[v&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:r("fg"),lineHeight:1.6},children:e.header_line?h(e.header_line):h(e.title)}),!u&&w&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r("desc-fg"),lineHeight:1.7},children:h(w)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[y.length===1&&n&&t.jsx("a",{href:c(y[0]),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(y[0]))},style:{fontSize:"11px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),S&&t.jsx("span",{style:{fontSize:"11px",color:r("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:y.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:zo(d,f,l)})]})]}),S&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:y.map(j=>{const k=b[j],$=k?`${l(k.title)}${k.author?`(${l(k.author)})`:""}`:j.slice(0,8)+"…";return t.jsxs("a",{href:c(j),onClick:C=>{C.metaKey||C.ctrlKey||(C.preventDefault(),C.stopPropagation(),n(j))},style:{fontSize:"12px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:j,children:["→",$]},j)})}),u&&v&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${x}40`,borderRadius:"0 4px 4px 0",background:r("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:h(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${r("widget-border")}`,fontSize:"12px",color:r("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:h(e.comment)})]})]})}function Kg({juan:e,searchQuery:n,onNavigate:i,transport:o,workLabelCache:s}){const{t:a}=ne(),l=rn(),d=n.trim(),c=g.useMemo(()=>d?e.sections.filter(p=>Co(p,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:c.map((p,h)=>t.jsx(qg,{section:p,onNavigate:i,transport:o,workLabelCache:s,highlightQuery:d},h))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function Xg(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function Zg({sections:e,onNavigate:n,inline:i,workLinks:o=!0}){const s=tt(),{t:a,convert:l}=ne(),d=Xg();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const h=bt(c.type);if(h==="page_header"&&!Io(c))return null;if(h==="类")return t.jsxs(g.Fragment,{children:[g.createElement(d("类"),null,i(l(c.title))),c.content&&t.jsx("p",{children:i(l(c.content))})]},p);if(h==="书"||h==="诗"||h==="考证"||h==="注释"){const u=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:$o(c.n_juan)}):""}`:c.title,m=i(l(u));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${p}`,children:[g.createElement(d("条目"),{className:"bim-rd-entry-h"},c.work_id&&n&&o?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},title:a("collated.viewWork"),children:m}),t.jsx("a",{className:"bim-rd-wl",href:s(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),n(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(u)}),children:a("collated.workArrow")})]}):m),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,x)=>t.jsx("p",{children:i(l(f))},x)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.summary")}),i(l(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.comment")}),i(l(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.additionalComment")}),i(l(c.additional_comment))]})]},p)}return h==="小计"&&c.title?t.jsx("p",{children:i(l(c.title))},p):c.content?t.jsx("p",{children:i(l(c.content))},p):null})})}function Bc(e){return e.some(n=>{const i=bt(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Io(n)})}function Jg({juan:e,rawText:n,positionLabel:i,groupLabel:o,index:s,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:p,view:h,onViewChange:u}){var xe;const{t:m,convert:f,messages:x}=ne(),v=rn(),[y,S]=g.useState("text"),b=h??y,w=Y=>{S(Y),u==null||u(Y)},j=a.trim(),k=(s==null?void 0:s.type)==="kaozhen",$=g.useCallback(Y=>j?Dn(Y,j,v):Y,[j,v]),C=ko(p),_=Y=>wo(Y,{renderText:$,bookMarking:C,quoteStyle:p.quoteStyle,t:m}),L=g.useMemo(()=>j?e.sections.filter(Y=>Co(Y,j,k,v)):e.sections,[e.sections,j,k,v]),z=(Y,E)=>E.filter(Te=>bt(Te.type)===Y).length,T=z("书",e.sections),M=z("诗",e.sections),P=z("考证",e.sections);let N="";k?N=j?m("collated.countTiaoOf",{m:z("考证",L),n:P}):m("collated.countTiao",{n:P}):M>0?N=j?m("collated.countPoemsOf",{m:z("诗",L),n:M}):m("collated.countPoems",{n:M}):T>0&&(N=j?m("collated.countBooksOf",{m:z("书",L),n:T}):m("collated.countBooks",{n:T}));const A=s!=null&&s.text_quality?Tg(s.text_quality.grade):null,W=[];if(N&&W.push(N),k&&(s!=null&&s.target_source)&&W.push(t.jsx(t.Fragment,{children:m("collated.kaozhenTarget",{target:f(s.target_source)})})),A){const Y=t.jsx("span",{className:"bim-rd-grade",style:zg(A),children:x.collated.qualityLabel[A]});W.push(t.jsx("span",{title:x.collated.qualityCriteria[A],children:(xe=s==null?void 0:s.text_quality)!=null&&xe.source_note?t.jsxs(t.Fragment,{children:[Ig(m("collated.baseText",{note:Mc}),s.text_quality.source_note,f),Y]}):t.jsxs(t.Fragment,{children:[m("collated.textQuality"),Y]})}))}e.source_url&&W.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:m("collated.originalSource")}));const G=!k&&Bc(e.sections),X=!!n&&(!G||p.readingMode==="paragraph"&&bi(n)),le=!k&&(G||!!n),U=k||!le?"entries":b;let D=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(i||o)&&t.jsxs("p",{className:"bim-rd-kicker",children:[i,i&&o&&t.jsx("span",{className:"bim-rd-dot"}),o&&f(o)]}),t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),W.length>0&&t.jsx("p",{className:"bim-rd-meta",children:W.map((Y,E)=>t.jsxs(g.Fragment,{children:[E>0&&t.jsx("span",{className:"bim-rd-dot"}),Y]},E))}),le&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":m("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":U==="text",onClick:()=>w("text"),children:m("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":U==="entries",onClick:()=>w("entries"),children:m("collated.viewEntries")})]})]}),U==="text"&&t.jsx("article",{className:"bim-rd-prose",children:X?t.jsx(So,{text:n,mode:p.readingMode,bookMarking:C,quoteStyle:p.quoteStyle,renderText:$,dropTitle:e.title}):t.jsx(Zg,{sections:e.sections,onNavigate:l,inline:_,workLinks:p.workLinks})}),U==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:k?t.jsx(Kg,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[L.some(Y=>["书","诗","考证"].includes(bt(Y.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:m("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:m("collated.rowHeadTitle")}),t.jsx("span",{children:m("collated.rowHeadWork")})]}),L.map((Y,E)=>{const Te=bt(Y.type);return Te==="书"||Te==="诗"||Te==="考证"?(D+=1,t.jsx(Dg,{domId:`rd-e-${e.sections.indexOf(Y)}`,section:Y,onNavigate:p.workLinks?l:void 0,highlightQuery:j,no:D,showUnlinked:p.workLinks&&!!l},E)):Te==="类"?t.jsx(Ug,{section:Y,highlightQuery:j},E):t.jsx(Gg,{section:Y,highlightQuery:j},E)}),L.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:m("collated.noMatch")})]})})]})}function Qg(e){const{resetKey:n,load:i,files:o,activeFile:s,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,p=rn(),h=g.useRef(new Map),[u,m]=g.useState({}),[f,x]=g.useState({}),v=g.useCallback((S,b)=>{const w=b==null?void 0:b.title;w&&x(j=>j[S]===w?j:{...j,[S]:w})},[]);g.useEffect(()=>{s&&a&&(h.current.set(s,{juan:a,rawText:l}),v(s,a))},[s,a,l,v]),g.useEffect(()=>{h.current.clear(),m({}),x({})},[n]);const y=g.useCallback((S,b)=>{let w=0;if(S.juan)for(const j of S.juan.sections)Co(j,b,c,p)&&w++;return w===0&&S.rawText&&Bg(S.rawText,b,p)&&(w=1),w},[c,p]);return g.useEffect(()=>{const S=d.trim();if(!S){m({});return}if(!i||o.length===0)return;let b=!1;const w={},j=[];for(const L of o){const z=h.current.get(L);z?w[L]=y(z,S):(w[L]="loading",j.push(L))}m(w);const k=8;let $=0;const C=async()=>{for(;$<j.length;){if(b)return;const L=$++,z=j[L];try{const T=await i(z),M=T.juan;if(h.current.set(z,T),v(z,M),b)return;m(P=>({...P,[z]:y(T,S)}))}catch{if(b)return;m(T=>({...T,[z]:0}))}}},_=Array.from({length:Math.min(k,j.length)},()=>C());return Promise.all(_),()=>{b=!0}},[d,n,i,o.join(","),y,p,v]),{matchStates:u,titles:f}}function ef({juan:e,view:n,onView:i,textHasEntries:o}){const{t:s,convert:a}=ne(),l=e.sections.map((h,u)=>({s:h,i:u,t:bt(h.type)})).filter(h=>h.t==="书"||h.t==="诗");if(l.length===0)return null;const d=l.filter(h=>!!h.s.work_id).length,c=l.every(h=>h.t==="诗")?s("collated.railUnitPoems"):s("collated.railUnitBooks"),p=h=>{const u=()=>{var m,f;return(f=(m=document.getElementById(`rd-e-${h}`))==null?void 0:m.scrollIntoView)==null?void 0:f.call(m,{block:"start",behavior:"smooth"})};n==="text"&&!o&&i("entries"),n==="text"&&!o?setTimeout(u,0):u()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:s("collated.railCap")}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:c}),t.jsx("span",{className:"bim-rd-rail-linked",children:s("collated.linkedN",{n:d})})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":s("collated.linkedOf",{n:d,total:l.length}),children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":s("collated.railEntriesNav"),children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("collated.viewEntries")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:h,i:u})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${u}`,onClick:m=>{m.preventDefault(),p(u)},children:[t.jsx("span",{className:`bim-rd-rail-dot${h.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:a(h.book_title||h.title)})]})},u))})]})]})}const tf=`
1273
1273
  attribute vec2 a_position; // 目标画布像素坐标 [0, canvasWidth] x [0, canvasHeight]
1274
1274
  attribute vec2 a_texCoord; // 原图像素坐标 [0, imgWidth] x [0, imgHeight]
1275
1275
 
@@ -1287,7 +1287,7 @@ ${Cg}`;function In({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{clas
1287
1287
  // 纹理坐标归一化 [0, 1]
1288
1288
  v_texCoord = a_texCoord / u_imgResolution;
1289
1289
  }
1290
- `,rf=`
1290
+ `,nf=`
1291
1291
  precision mediump float;
1292
1292
  uniform sampler2D u_image;
1293
1293
  uniform float u_alpha;
@@ -1297,7 +1297,7 @@ ${Cg}`;function In({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{clas
1297
1297
  vec4 tex = texture2D(u_image, v_texCoord);
1298
1298
  gl_FragColor = vec4(tex.rgb, tex.a * u_alpha);
1299
1299
  }
1300
- `;function aa(e,n,i){const o=e.createShader(n);return o?(e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)?o:(console.error("Shader compile error:",e.getShaderInfoLog(o)),e.deleteShader(o),null)):null}class Ar{constructor(n){const i=n.getContext("webgl",{alpha:!0,antialias:!0,preserveDrawingBuffer:!0,premultipliedAlpha:!1});if(!i)throw new Error("WebGL not supported");this.gl=i;const o=aa(i,i.VERTEX_SHADER,nf),s=aa(i,i.FRAGMENT_SHADER,rf);if(!o||!s)throw new Error("Failed to create shaders");const a=i.createProgram();if(!a)throw new Error("Failed to create program");if(i.attachShader(a,o),i.attachShader(a,s),i.linkProgram(a),!i.getProgramParameter(a,i.LINK_STATUS))throw new Error("Program link error: "+i.getProgramInfoLog(a));this.program=a,this.positionBuffer=i.createBuffer(),this.texCoordBuffer=i.createBuffer(),this.uResolutionLoc=i.getUniformLocation(a,"u_resolution"),this.uImgResolutionLoc=i.getUniformLocation(a,"u_imgResolution"),this.uAlphaLoc=i.getUniformLocation(a,"u_alpha"),this.aPositionLoc=i.getAttribLocation(a,"a_position"),this.aTexCoordLoc=i.getAttribLocation(a,"a_texCoord"),i.enable(i.BLEND),i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),this.clear(n.width,n.height)}clear(n,i){const o=this.gl;o.viewport(0,0,n,i),o.clearColor(.98,.97,.95,1),o.clear(o.COLOR_BUFFER_BIT)}createTexture(n){const i=this.gl,o=i.createTexture();return i.bindTexture(i.TEXTURE_2D,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,n),o}renderStripsWithTexture(n,i,o,s,a,l,d=1){if(l.length===0)return;const c=this.gl;c.viewport(0,0,i,o),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,i,o),c.uniform2f(this.uImgResolutionLoc,s,a),c.uniform1f(this.uAlphaLoc,d);const p=[],m=[],u=8;for(const g of l){const f=g.colOffsetX||0,x=g.colOffsetY||0,{srcQuad:v,dstRect:y}=g.strip,[_,b,w,j]=y,k=f+_,C=x+b,[$,S,M,z]=v;for(let T=0;T<u;T++){const P=T/u,R=(T+1)/u,N=C+j*P,A=C+j*R,H=[$[0]+(z[0]-$[0])*P,$[1]+(z[1]-$[1])*P],G=[$[0]+(z[0]-$[0])*R,$[1]+(z[1]-$[1])*R],ie=[S[0]+(M[0]-S[0])*P,S[1]+(M[1]-S[1])*P],le=[S[0]+(M[0]-S[0])*R,S[1]+(M[1]-S[1])*R],V=[k,N],F=[k+w,N],xe=[k,A],ee=[k+w,A];p.push(V[0],V[1],F[0],F[1],xe[0],xe[1]),m.push(H[0],H[1],ie[0],ie[1],G[0],G[1]),p.push(F[0],F[1],ee[0],ee[1],xe[0],xe[1]),m.push(ie[0],ie[1],le[0],le[1],G[0],G[1])}}c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(p),c.STATIC_DRAW),c.enableVertexAttribArray(this.aPositionLoc),c.vertexAttribPointer(this.aPositionLoc,2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,this.texCoordBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(m),c.STATIC_DRAW),c.enableVertexAttribArray(this.aTexCoordLoc),c.vertexAttribPointer(this.aTexCoordLoc,2,c.FLOAT,!1,0,0),c.bindTexture(c.TEXTURE_2D,n),c.drawArrays(c.TRIANGLES,0,p.length/2)}deleteTexture(n){n&&this.gl.deleteTexture(n)}destroy(){const n=this.gl;n.deleteProgram(this.program),n.deleteBuffer(this.positionBuffer),n.deleteBuffer(this.texCoordBuffer)}}const Ot=new Map,of=24;function Mr(e){let n=Ot.get(e);if(n)return Ot.delete(e),Ot.set(e,n),n;for(n=new Promise(i=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{(o.decode?o.decode().catch(()=>{}):Promise.resolve()).then(()=>i(o))},o.onerror=()=>{Ot.delete(e),i(null)},o.src=e}),Ot.set(e,n);Ot.size>of;)Ot.delete(Ot.keys().next().value);return n}const Eo=({imageUrl:e,pageData:n,selectedCharIds:i,hoveredCharId:o,preserveMargins:s=!1,onCharClick:a,onCharHover:l})=>{const d=h.useRef(null),c=h.useRef(null),p=h.useRef(null),m=h.useRef(null),u=h.useRef(null),g=h.useRef(null),[f,x]=h.useState(0),[v,y]=h.useState(0),_=h.useRef(""),b=h.useMemo(()=>Math.max(...n.columns.map(R=>R.warped_h),2440),[n]),w=n.total_warped_w,j=n.banxin,k=h.useMemo(()=>{var le;if(!s)return{top:0,bottom:0,left:0,right:0};const[R,N]=n.image_size||[2386,3082];let A=1/0,H=-1/0,G=1/0,ie=-1/0;for(const V of n.columns)for(const F of V.strips||[])for(const xe of F.srcQuad)xe[0]<A&&(A=xe[0]),xe[0]>H&&(H=xe[0]),xe[1]<G&&(G=xe[1]),xe[1]>ie&&(ie=xe[1]);if((le=n.banxin)!=null&&le.current_page_strips)for(const V of n.banxin.current_page_strips)for(const F of V.srcQuad)F[0]<A&&(A=F[0]),F[0]>H&&(H=F[0]),F[1]<G&&(G=F[1]),F[1]>ie&&(ie=F[1]);return isFinite(A)||(A=0),isFinite(H)||(H=R),isFinite(G)||(G=0),isFinite(ie)||(ie=N),{top:Math.max(0,Math.round(G)),bottom:Math.max(0,Math.round(N-ie)),left:Math.max(0,Math.round(A)),right:Math.max(0,Math.round(R-H)),rawMinX:A,rawMaxX:H,rawMinY:G,rawMaxY:ie,imgW:R,imgH:N}},[n,s]),C=w+(j?j.total_w:0),$=C+k.left+k.right,S=b+k.top+k.bottom,M=h.useCallback(()=>{const R=c.current;if(!(!R||!d.current)&&!(e&&_.current!==e)){if(R.clear($,S),s&&k.rawMinX!==void 0&&u.current&&p.current){const{rawMinX:N,rawMaxX:A,rawMinY:H,rawMaxY:G,imgW:ie,imgH:le,top:V,bottom:F,left:xe,right:ee}=k,L=[];xe>0&&L.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[N,0],[N,le],[0,le]],dstRect:[0,0,xe,S]}}),V>0&&L.push({colOffsetX:xe,colOffsetY:0,strip:{srcQuad:[[N,0],[A,0],[A,H],[N,H]],dstRect:[0,0,C,V]}}),F>0&&L.push({colOffsetX:xe,colOffsetY:V+b,strip:{srcQuad:[[N,G],[A,G],[A,le],[N,le]],dstRect:[0,0,C,F]}}),ee>0&&L.push({colOffsetX:xe+C,colOffsetY:0,strip:{srcQuad:[[A,0],[ie,0],[ie,le],[A,le]],dstRect:[0,0,ee,S]}}),R.renderStripsWithTexture(u.current,$,S,n.image_size[0],n.image_size[1],L,1)}if(u.current&&p.current){const N=n.columns.flatMap(A=>(A.strips||[]).map(H=>({colOffsetX:k.left+A.offset_x,colOffsetY:k.top,strip:H})));if(N.length>0?R.renderStripsWithTexture(u.current,$,S,n.image_size[0],n.image_size[1],N,1):R.renderStripsWithTexture(u.current,$,S,n.image_size[0],n.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[n.image_size[0],0],[n.image_size[0],n.image_size[1]],[0,n.image_size[1]]],dstRect:[0,0,$,S]}}],1),j&&j.current_page_strips.length>0){const A=j.current_page_strips.map(H=>({colOffsetX:k.left+w,colOffsetY:k.top,strip:H}));R.renderStripsWithTexture(u.current,$,S,n.image_size[0],n.image_size[1],A,1)}}if(j&&g.current&&m.current&&j.mate_page_strips.length>0){const N=j.mate_page_strips.map(A=>({colOffsetX:k.left+w+j.half_w,colOffsetY:k.top,strip:A}));R.renderStripsWithTexture(g.current,$,S,j.mate_img_size[0],j.mate_img_size[1],N,.65)}}},[e,n,j,$,S,w,b,C,k,s]),z=h.useRef(M);z.current=M,h.useEffect(()=>{const R=d.current;if(!R)return;const N=G=>{u.current=p.current?G.createTexture(p.current):null,g.current=m.current?G.createTexture(m.current):null,z.current()};try{const G=new Ar(R);c.current=G,N(G)}catch(G){console.error("Failed to init WebGL renderer:",G)}const A=G=>{G.preventDefault(),console.warn("WebGL context lost")},H=()=>{console.info("WebGL context restored, re-initializing..."),d.current&&(c.current=new Ar(d.current),N(c.current))};return R.addEventListener("webglcontextlost",A,!1),R.addEventListener("webglcontextrestored",H,!1),()=>{R.removeEventListener("webglcontextlost",A),R.removeEventListener("webglcontextrestored",H),c.current&&(c.current.deleteTexture(u.current),c.current.deleteTexture(g.current),c.current.destroy(),c.current=null)}},[]),h.useEffect(()=>{if(!e)return;let R=!0;return Mr(e).then(N=>{if(!R||!N)return;p.current=N,_.current=e;const A=c.current;A&&(A.deleteTexture(u.current),u.current=A.createTexture(N)),x(H=>H+1)}),()=>{R=!1}},[e]);const T=j==null?void 0:j.mate_image_url;h.useEffect(()=>{if(!T)return;let R=!0;return Mr(T).then(N=>{if(!R||!N)return;m.current=N;const A=c.current;A&&(A.deleteTexture(g.current),g.current=A.createTexture(N)),y(H=>H+1)}),()=>{R=!1}},[T]),h.useEffect(()=>{M()},[M,f,v]);const P=h.useMemo(()=>{const R=[];for(const N of n.columns)for(const A of N.chars){const[H,G,ie,le]=A.bbox_col;R.push({id:A.id,char:A.char,x:k.left+N.offset_x+H,y:k.top+G,w:Math.max(ie-H,1),h:Math.max(le-G,1)})}return R},[n,k]);return t.jsxs("div",{className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${$} / ${S}`,backgroundColor:r("warp-bg"),boxShadow:r("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("canvas",{ref:d,width:$,height:S,style:{width:"100%",height:"100%",display:"block",backgroundColor:r("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${$} ${S}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[P.map(R=>{const N=i.has(R.id),A=o===R.id;return t.jsx("rect",{"data-selected":N?"true":void 0,x:R.x,y:R.y,width:R.w,height:R.h,fill:N?r("warp-sel-bg"):A?r("warp-hover-bg"):"transparent",stroke:N?r("warp-sel-stroke"):A?r("warp-hover-stroke"):"transparent",strokeWidth:N?3.5:A?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>a==null?void 0:a(R.id),onMouseEnter:()=>l==null?void 0:l(R.id),onMouseLeave:()=>l==null?void 0:l(null),children:t.jsx("title",{children:R.char})},R.id)}),j&&t.jsxs("g",{children:[t.jsx("line",{x1:k.left+w,y1:k.top,x2:k.left+w,y2:k.top+b,stroke:r("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:k.left+w+j.half_w,y1:k.top,x2:k.left+w+j.half_w,y2:k.top+b,stroke:r("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:k.left+C,y1:k.top,x2:k.left+C,y2:k.top+b,stroke:r("warp-banxin-outer"),strokeWidth:1})]})]})]})},Lo=`
1300
+ `;function sa(e,n,i){const o=e.createShader(n);return o?(e.shaderSource(o,i),e.compileShader(o),e.getShaderParameter(o,e.COMPILE_STATUS)?o:(console.error("Shader compile error:",e.getShaderInfoLog(o)),e.deleteShader(o),null)):null}class Lr{constructor(n){const i=n.getContext("webgl",{alpha:!0,antialias:!0,preserveDrawingBuffer:!0,premultipliedAlpha:!1});if(!i)throw new Error("WebGL not supported");this.gl=i;const o=sa(i,i.VERTEX_SHADER,tf),s=sa(i,i.FRAGMENT_SHADER,nf);if(!o||!s)throw new Error("Failed to create shaders");const a=i.createProgram();if(!a)throw new Error("Failed to create program");if(i.attachShader(a,o),i.attachShader(a,s),i.linkProgram(a),!i.getProgramParameter(a,i.LINK_STATUS))throw new Error("Program link error: "+i.getProgramInfoLog(a));this.program=a,this.positionBuffer=i.createBuffer(),this.texCoordBuffer=i.createBuffer(),this.uResolutionLoc=i.getUniformLocation(a,"u_resolution"),this.uImgResolutionLoc=i.getUniformLocation(a,"u_imgResolution"),this.uAlphaLoc=i.getUniformLocation(a,"u_alpha"),this.aPositionLoc=i.getAttribLocation(a,"a_position"),this.aTexCoordLoc=i.getAttribLocation(a,"a_texCoord"),i.enable(i.BLEND),i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),this.clear(n.width,n.height)}clear(n,i){const o=this.gl;o.viewport(0,0,n,i),o.clearColor(.98,.97,.95,1),o.clear(o.COLOR_BUFFER_BIT)}createTexture(n){const i=this.gl,o=i.createTexture();return i.bindTexture(i.TEXTURE_2D,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,n),o}renderStripsWithTexture(n,i,o,s,a,l,d=1){if(l.length===0)return;const c=this.gl;c.viewport(0,0,i,o),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,i,o),c.uniform2f(this.uImgResolutionLoc,s,a),c.uniform1f(this.uAlphaLoc,d);const p=[],h=[],u=8;for(const m of l){const f=m.colOffsetX||0,x=m.colOffsetY||0,{srcQuad:v,dstRect:y}=m.strip,[S,b,w,j]=y,k=f+S,$=x+b,[C,_,L,z]=v;for(let T=0;T<u;T++){const M=T/u,P=(T+1)/u,N=$+j*M,A=$+j*P,W=[C[0]+(z[0]-C[0])*M,C[1]+(z[1]-C[1])*M],G=[C[0]+(z[0]-C[0])*P,C[1]+(z[1]-C[1])*P],X=[_[0]+(L[0]-_[0])*M,_[1]+(L[1]-_[1])*M],le=[_[0]+(L[0]-_[0])*P,_[1]+(L[1]-_[1])*P],U=[k,N],D=[k+w,N],xe=[k,A],Y=[k+w,A];p.push(U[0],U[1],D[0],D[1],xe[0],xe[1]),h.push(W[0],W[1],X[0],X[1],G[0],G[1]),p.push(D[0],D[1],Y[0],Y[1],xe[0],xe[1]),h.push(X[0],X[1],le[0],le[1],G[0],G[1])}}c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(p),c.STATIC_DRAW),c.enableVertexAttribArray(this.aPositionLoc),c.vertexAttribPointer(this.aPositionLoc,2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,this.texCoordBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(h),c.STATIC_DRAW),c.enableVertexAttribArray(this.aTexCoordLoc),c.vertexAttribPointer(this.aTexCoordLoc,2,c.FLOAT,!1,0,0),c.bindTexture(c.TEXTURE_2D,n),c.drawArrays(c.TRIANGLES,0,p.length/2)}deleteTexture(n){n&&this.gl.deleteTexture(n)}destroy(){const n=this.gl;n.deleteProgram(this.program),n.deleteBuffer(this.positionBuffer),n.deleteBuffer(this.texCoordBuffer)}}function rf(e){const[n,i]=e.image_size||[0,0];if(!(n>0)||!(i>0)||e.columns.some(m=>{var f;return(((f=m.strips)==null?void 0:f.length)??0)>0}))return null;let o=1/0,s=1/0,a=-1/0,l=-1/0;for(const m of e.columns)for(const f of m.chars){const[x,v,y,S]=f.bbox_col;![x,v,y,S].every(Number.isFinite)||!(y>x)||!(S>v)||(o=Math.min(o,m.offset_x+x),s=Math.min(s,v),a=Math.max(a,m.offset_x+y),l=Math.max(l,S))}if(!(a>o)||!(l>s))return null;const d=Math.min(n,i)*.03,c=Math.min(n,Math.max(0,o-d)),p=Math.min(i,Math.max(0,s-d)),h=Math.min(n,Math.max(0,a+d))-c,u=Math.min(i,Math.max(0,l+d))-p;return!(h>0)||!(u>0)||h>=n*.98&&u>=i*.98?null:{x:c,y:p,w:h,h:u}}const Ft=new Map,of=24;function Ar(e){let n=Ft.get(e);if(n)return Ft.delete(e),Ft.set(e,n),n;for(n=new Promise(i=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{(o.decode?o.decode().catch(()=>{}):Promise.resolve()).then(()=>i(o))},o.onerror=()=>{Ft.delete(e),i(null)},o.src=e}),Ft.set(e,n);Ft.size>of;)Ft.delete(Ft.keys().next().value);return n}const Ro=({imageUrl:e,pageData:n,selectedCharIds:i,hoveredCharId:o,preserveMargins:s=!1,onCharClick:a,onCharHover:l})=>{const d=g.useRef(null),c=g.useRef(null),p=g.useRef(null),h=g.useRef(null),u=g.useRef(null),m=g.useRef(null),[f,x]=g.useState(0),[v,y]=g.useState(0),S=g.useRef(""),b=g.useMemo(()=>Math.max(...n.columns.map(N=>N.warped_h),2440),[n]),w=n.total_warped_w,j=n.banxin,k=g.useMemo(()=>{var U;if(!s)return{top:0,bottom:0,left:0,right:0};const[N,A]=n.image_size||[2386,3082];let W=1/0,G=-1/0,X=1/0,le=-1/0;for(const D of n.columns)for(const xe of D.strips||[])for(const Y of xe.srcQuad)Y[0]<W&&(W=Y[0]),Y[0]>G&&(G=Y[0]),Y[1]<X&&(X=Y[1]),Y[1]>le&&(le=Y[1]);if((U=n.banxin)!=null&&U.current_page_strips)for(const D of n.banxin.current_page_strips)for(const xe of D.srcQuad)xe[0]<W&&(W=xe[0]),xe[0]>G&&(G=xe[0]),xe[1]<X&&(X=xe[1]),xe[1]>le&&(le=xe[1]);return isFinite(W)||(W=0),isFinite(G)||(G=N),isFinite(X)||(X=0),isFinite(le)||(le=A),{top:Math.max(0,Math.round(X)),bottom:Math.max(0,Math.round(A-le)),left:Math.max(0,Math.round(W)),right:Math.max(0,Math.round(N-G)),rawMinX:W,rawMaxX:G,rawMinY:X,rawMaxY:le,imgW:N,imgH:A}},[n,s]),$=g.useMemo(()=>s?null:rf(n),[n,s]),C=w+(j?j.total_w:0),_=$?$.w:C+k.left+k.right,L=$?$.h:b+k.top+k.bottom,z=g.useCallback(()=>{const N=c.current;if(!(!N||!d.current)&&!(e&&S.current!==e)){if(N.clear(_,L),s&&k.rawMinX!==void 0&&u.current&&p.current){const{rawMinX:A,rawMaxX:W,rawMinY:G,rawMaxY:X,imgW:le,imgH:U,top:D,bottom:xe,left:Y,right:E}=k,Te=[];Y>0&&Te.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[A,0],[A,U],[0,U]],dstRect:[0,0,Y,L]}}),D>0&&Te.push({colOffsetX:Y,colOffsetY:0,strip:{srcQuad:[[A,0],[W,0],[W,G],[A,G]],dstRect:[0,0,C,D]}}),xe>0&&Te.push({colOffsetX:Y,colOffsetY:D+b,strip:{srcQuad:[[A,X],[W,X],[W,U],[A,U]],dstRect:[0,0,C,xe]}}),E>0&&Te.push({colOffsetX:Y+C,colOffsetY:0,strip:{srcQuad:[[W,0],[le,0],[le,U],[W,U]],dstRect:[0,0,E,L]}}),N.renderStripsWithTexture(u.current,_,L,n.image_size[0],n.image_size[1],Te,1)}if(u.current&&p.current){const A=n.columns.flatMap(W=>(W.strips||[]).map(G=>({colOffsetX:k.left+W.offset_x,colOffsetY:k.top,strip:G})));if(A.length>0?N.renderStripsWithTexture(u.current,_,L,n.image_size[0],n.image_size[1],A,1):N.renderStripsWithTexture(u.current,_,L,n.image_size[0],n.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:$?[[$.x,$.y],[$.x+$.w,$.y],[$.x+$.w,$.y+$.h],[$.x,$.y+$.h]]:[[0,0],[n.image_size[0],0],[n.image_size[0],n.image_size[1]],[0,n.image_size[1]]],dstRect:[0,0,_,L]}}],1),j&&j.current_page_strips.length>0){const W=j.current_page_strips.map(G=>({colOffsetX:k.left+w,colOffsetY:k.top,strip:G}));N.renderStripsWithTexture(u.current,_,L,n.image_size[0],n.image_size[1],W,1)}}if(j&&m.current&&h.current&&j.mate_page_strips.length>0){const A=j.mate_page_strips.map(W=>({colOffsetX:k.left+w+j.half_w,colOffsetY:k.top,strip:W}));N.renderStripsWithTexture(m.current,_,L,j.mate_img_size[0],j.mate_img_size[1],A,.65)}}},[e,n,j,_,L,w,b,C,k,s,$]),T=g.useRef(z);T.current=z,g.useEffect(()=>{const N=d.current;if(!N)return;const A=X=>{u.current=p.current?X.createTexture(p.current):null,m.current=h.current?X.createTexture(h.current):null,T.current()};try{const X=new Lr(N);c.current=X,A(X)}catch(X){console.error("Failed to init WebGL renderer:",X)}const W=X=>{X.preventDefault(),console.warn("WebGL context lost")},G=()=>{console.info("WebGL context restored, re-initializing..."),d.current&&(c.current=new Lr(d.current),A(c.current))};return N.addEventListener("webglcontextlost",W,!1),N.addEventListener("webglcontextrestored",G,!1),()=>{N.removeEventListener("webglcontextlost",W),N.removeEventListener("webglcontextrestored",G),c.current&&(c.current.deleteTexture(u.current),c.current.deleteTexture(m.current),c.current.destroy(),c.current=null)}},[]),g.useEffect(()=>{if(!e)return;let N=!0;return Ar(e).then(A=>{if(!N||!A)return;p.current=A,S.current=e;const W=c.current;W&&(W.deleteTexture(u.current),u.current=W.createTexture(A)),x(G=>G+1)}),()=>{N=!1}},[e]);const M=j==null?void 0:j.mate_image_url;g.useEffect(()=>{if(!M)return;let N=!0;return Ar(M).then(A=>{if(!N||!A)return;h.current=A;const W=c.current;W&&(W.deleteTexture(m.current),m.current=W.createTexture(A)),y(G=>G+1)}),()=>{N=!1}},[M]),g.useEffect(()=>{z()},[z,f,v]);const P=g.useMemo(()=>{const N=[];for(const A of n.columns)for(const W of A.chars){const[G,X,le,U]=W.bbox_col;N.push({id:W.id,char:W.char,x:k.left+A.offset_x+G-(($==null?void 0:$.x)??0),y:k.top+X-(($==null?void 0:$.y)??0),w:Math.max(le-G,1),h:Math.max(U-X,1)})}return N},[n,k,$]);return t.jsxs("div",{className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${_} / ${L}`,backgroundColor:r("warp-bg"),boxShadow:r("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("canvas",{ref:d,width:_,height:L,style:{width:"100%",height:"100%",display:"block",backgroundColor:r("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${_} ${L}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[P.map(N=>{const A=i.has(N.id),W=o===N.id;return t.jsx("rect",{"data-selected":A?"true":void 0,x:N.x,y:N.y,width:N.w,height:N.h,fill:A?r("warp-sel-bg"):W?r("warp-hover-bg"):"transparent",stroke:A?r("warp-sel-stroke"):W?r("warp-hover-stroke"):"transparent",strokeWidth:A?3.5:W?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>a==null?void 0:a(N.id),onMouseEnter:()=>l==null?void 0:l(N.id),onMouseLeave:()=>l==null?void 0:l(null),children:t.jsx("title",{children:N.char})},N.id)}),j&&t.jsxs("g",{children:[t.jsx("line",{x1:k.left+w,y1:k.top,x2:k.left+w,y2:k.top+b,stroke:r("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:k.left+w+j.half_w,y1:k.top,x2:k.left+w+j.half_w,y2:k.top+b,stroke:r("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:k.left+C,y1:k.top,x2:k.left+C,y2:k.top+b,stroke:r("warp-banxin-outer"),strokeWidth:1})]})]})]})},Eo=`
1301
1301
  .bim-et-w { position: relative; display: inline; }
1302
1302
  .bim-et {
1303
1303
  color: inherit; text-decoration-line: underline;
@@ -1340,17 +1340,17 @@ a.bim-et:focus-visible { outline: 2px solid ${r("accent")}; outline-offset: 2px;
1340
1340
  .bim-et-card { animation: bim-et-in 120ms ease-out; }
1341
1341
  @keyframes bim-et-in { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
1342
1342
  }
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}
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}
1345
- ${ce}`:null,ne=re&&re.owner===we?re.idx:null;h.useEffect(()=>{if(!ce)return;let E=!1;const pe=`${n}
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}
1343
+ `,sf=120;function mt(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=mt(o.name);return s?[mt(o.dynasty)&&`〔${mt(o.dynasty)}〕`,s,mt(o.role)].filter(Boolean).join(""):""}).filter(Boolean);return n.length?n.slice(0,3).join("、"):void 0}function Wc(e,n){const i=mt(n.type),o=mt(n.primary_name)??mt(n.title)??e,s=i==="entity"?[mt(n.dynasty),lf(n),mt(n.native_place)].filter(Boolean).join(" · "):[cf(n),mt(n.edition),mt(n.measure_info)].filter(Boolean).join(" · "),a=n.description&&typeof n.description=="object"?mt(n.description.text):mt(n.description);return{id:e,type:i,title:o,meta:s||void 0,description:af(a)}}function Oc(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 Fc(e){return async n=>{const i=await e.getItem(n);if(i)return Wc(n,i);if(e.getEntry){const o=await e.getEntry(n);if(o)return Oc(o)}return null}}const aa=new WeakMap;function df(e,n,i){let o=aa.get(e);o||(o=new Map,aa.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 Hc=e=>`/item/${encodeURIComponent(e)}`,la={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},pf=typeof window>"u"?g.useEffect:g.useLayoutEffect;function Lo(e,n){return g.useMemo(()=>n?{owner:n,load:n}:e?{owner:e,load:Fc(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=Hc,onNavigate:d,renderText:c=uf,hoverDelayMs:p=250,closeDelayMs:h,injectStyles:u=!0,className:m})=>{const f=g.useMemo(()=>{const v=i==="plain"?Lc(e,n,o):n;return Ac(e,v)},[e,n,i,o]),x=Lo(s,a);return t.jsxs("span",{className:m?`bim-et-root ${m}`:"bim-et-root",children:[u&&t.jsx("style",{children:Eo}),f.map(v=>v.type==="text"?t.jsx(g.Fragment,{children:c(v.text)},`t${v.start}`):t.jsx(Ao,{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:h},`${v.span.key}@${v.start}`))]})};let Ht=null;const Ao=({span:e,label:n,hasBrackets:i,plain:o,loader:s,buildHref:a,onNavigate:l,renderText:d,hoverDelayMs:c,closeDelayMs:p=280})=>{const h=g.useId(),[u,m]=g.useState(!1),[f,x]=g.useState(!1),v=g.useRef(null),y=g.useRef(null),S=`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)},$=g.useCallback(()=>{j(),k(),m(!1),x(!1),Ht===$&&(Ht=null)},[]);g.useEffect(()=>()=>{j(),k(),Ht===$&&(Ht=null)},[$]);const C=g.useCallback(()=>{Ht&&Ht!==$&&Ht(),Ht=$,m(!0)},[$]),_=g.useCallback(P=>{k(),x(!0),!u&&(j(),P<=0?C():v.current=setTimeout(C,P))},[u,C]),L=g.useCallback(()=>{j(),k(),y.current=setTimeout($,p)},[$,p]),z=!!e.targetId,T=e.targetId,M={className:"bim-et-w","data-active":f?"":void 0,onMouseEnter:()=>_(c),onMouseLeave:L,onBlur:P=>{P.currentTarget.contains(P.relatedTarget)||$()},onKeyDown:P=>{P.key==="Escape"&&u&&(P.stopPropagation(),$())}};return!z||!T?t.jsxs("span",{...M,children:[t.jsx("span",{className:S,children:w}),u&&t.jsx(ca,{id:h,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...M,children:[t.jsx("a",{className:S,href:a(T),"data-entity-id":T,"aria-describedby":u?h:void 0,onFocus:()=>_(0),onClick:l?P=>l(T,P):void 0,children:w}),u&&t.jsx(ca,{id:h,entityId:T,span:e,loader:s,buildHref:a,onNavigate:l})]})},ca=({id:e,entityId:n,span:i,loader:o,buildHref:s,onNavigate:a})=>{const{convert:l,t:d}=ne(),c=g.useRef(null),[p,h]=g.useState("start"),[u,m]=g.useState(o&&n?{status:"loading"}:{status:"ready",summary:null});g.useEffect(()=>{if(!o||!n)return;let v=!1;return m({status:"loading"}),df(o.owner,o.load,n).then(y=>{v||m({status:"ready",summary:y})}).catch(()=>{v||m({status:"error"})}),()=>{v=!0}},[o,n]),pf(()=>{const v=c.current;if(!v||typeof window>"u")return;const y=v.getBoundingClientRect(),S=document.documentElement.clientWidth||window.innerWidth;y.right>S-8&&p==="start"&&h("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(la[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(la[i.kind])})})},hf=e=>`/item/${encodeURIComponent(e)}`;function gf(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 Mo=({pageData:e,pages:n,punctuations:i=bf,selectedCharIds:o,hoveredCharId:s,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:p=!0,onVisiblePageChange:h,convert:u,scrollToPage:m,entities:f,entityTransport:x,loadEntitySummary:v,buildEntityHref:y,onEntityNavigate:S,pageBreaks:b=!0,pageIndicatorY:w,onPageIndicatorYChange:j,quoteStyle:k,bookTitleStyle:$,showWorks:C})=>{const _=g.useRef(null),L=g.useRef(0),z=g.useMemo(()=>{const J=new Map;return p&&i.forEach((re,de)=>{const H=re.id?re:{...re,id:`${re.anchor}#${de}`},Z=J.get(H.anchor)||[];Z.push(H),J.set(H.anchor,Z)}),J},[i,p]),T=g.useMemo(()=>k===void 0&&$===void 0&&C===void 0?null:{quoteStyle:k??"original",hideBookBrackets:$==="wavy"||C===!1},[k,$,C]),M=$==="bracket",P=g.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((ie,B)=>ie.col-B.col),H=[];let Z=[],ke=0;for(const ie of de){if(ie.chars.length===0){ie.kind==="blank"&&ke++;continue}const B=ie.raised||ie.lead_blank||ke?{raised:ie.raised,leadBlank:ie.lead_blank,blankBefore:ke}:void 0;ke=0;let Q=!0;for(const ae of ie.chars){const{before:je,after:q}=gf(z.get(ae.id)||[]),be=(z.get(ae.id)||[]).some(Le=>Le.kind==="break");Z.push({charData:ae,col:ie.col,beforePuncts:je,afterPuncts:q,...Q&&B?{start:B}:{}}),Q=!1,be&&(H.push({id:`para-p${re.page}-${H.length}`,chars:Z}),Z=[])}}return Z.length>0&&H.push({id:`para-p${re.page}-${H.length}`,chars:Z}),{page:re.page,paragraphs:H,...re.label?{label:re.label}:{},...ke>0?{trailingBlank:ke}:{}}}),[n,e,z]),N=g.useMemo(()=>{const J=[];for(const re of P)for(const de of re.paragraphs)for(const H of de.chars)J.push(H.charData.id);return J},[P]),A=g.useMemo(()=>{const J=new Map;if(!f||f.length===0)return J;const re=new Map(N.map((de,H)=>[de,H]));for(const de of f){if(!de.anchor)continue;const H=re.get(de.anchor.start),Z=re.get(de.anchor.end);if(!(H===void 0||Z===void 0||Z<H))for(let ke=H;ke<=Z;ke++)J.has(N[ke])||J.set(N[ke],de)}return J},[f,N]),W=Lo(x,v),G=A.size>0,X=g.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:h,onEntityNavigate:S});X.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:h,onEntityNavigate:S};const le=g.useMemo(()=>({click:J=>{var re,de;L.current=Date.now()+1200,(de=(re=X.current).onCharClick)==null||de.call(re,J)},enter:J=>{var re,de;return(de=(re=X.current).onCharHover)==null?void 0:de.call(re,J)},leave:()=>{var J,re;return(re=(J=X.current).onCharHover)==null?void 0:re.call(J,null)},navigate:(J,re)=>{var H,Z;if(!(re.detail===0||re.ctrlKey||re.metaKey||re.shiftKey)){re.preventDefault();return}(Z=(H=X.current).onEntityNavigate)==null||Z.call(H,J,re)}}),[]),U=yf(o),D=g.useRef(null);g.useEffect(()=>{var re,de;if((re=D.current)==null||re.classList.remove("is-hovered"),D.current=null,!s)return;const J=(de=_.current)==null?void 0:de.querySelector(`span[data-char-id="${s}"]`);J&&(J.classList.add("is-hovered"),D.current=J)},[s]),g.useEffect(()=>{let J=null;const re=()=>{var Fe,O;J=null;const H=window.getSelection(),Z=_.current;if(!H||H.isCollapsed||H.rangeCount===0||!Z)return;const ke=H.getRangeAt(0),ie=ke.commonAncestorContainer,B=ie.nodeType===3?ie.parentElement:ie;if(!B||!Z.contains(B))return;const Q=Z.querySelectorAll("span[data-char-id]");let ae=0,je=Q.length;for(;ae<je;){const ee=ae+je>>1;ke.comparePoint(Q[ee],0)<0?ae=ee+1:je=ee}const q=ae;for(je=Q.length;ae<je;){const ee=ae+je>>1;ke.comparePoint(Q[ee],0)<=0?ae=ee+1:je=ee}const be=ae-1;if(be<q)return;const Le=[];for(let ee=q;ee<=be;ee++)Le.push(Q[ee].getAttribute("data-char-id"));Le.length>0&&(L.current=Date.now()+1200,(O=(Fe=X.current).onSelectionChange)==null||O.call(Fe,Le))},de=()=>{J&&clearTimeout(J),J=setTimeout(re,120)};return document.addEventListener("selectionchange",de),()=>{document.removeEventListener("selectionchange",de),J&&clearTimeout(J)}},[]),g.useEffect(()=>{var J;if(o.size===1){const re=Array.from(o)[0],de=(J=_.current)==null?void 0:J.querySelector(`span[data-char-id="${re}"]`);de&&de.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}},[o]);const xe=m==null?void 0:m.nonce;g.useEffect(()=>{var re;if(!m)return;const J=(re=_.current)==null?void 0:re.querySelector(`[data-page-section="${m.page}"]`);J&&(L.current=Date.now()+800,J.scrollIntoView({behavior:"auto",block:"start"}))},[xe]);const Y=!!h,E=Y&&typeof w=="number",[Te,ce]=g.useState(null),me=Mr(Te??w??0),se=g.useRef(null);se.current=E?me:null;const We=g.useRef(()=>{});return g.useEffect(()=>{var Z;if(!Y)return;const J=Array.from(((Z=_.current)==null?void 0:Z.querySelectorAll("[data-page-section]"))??[]);if(J.length===0)return;let re=0;const de=()=>{var ae,je;if(re=0,Date.now()<L.current)return;const ke=se.current===null?120:se.current*window.innerHeight;let ie=0,B=J.length-1;for(;ie<B;){const q=ie+B+1>>1;J[q].getBoundingClientRect().top<=ke?ie=q:B=q-1}const Q=parseInt(J[ie].getAttribute("data-page-section")||"",10);isNaN(Q)||(je=(ae=X.current).onVisiblePageChange)==null||je.call(ae,Q)},H=()=>{re||(re=requestAnimationFrame(de))};return We.current=()=>{re||(re=requestAnimationFrame(de))},window.addEventListener("scroll",H,{passive:!0}),de(),()=>{window.removeEventListener("scroll",H),re&&cancelAnimationFrame(re),We.current=()=>{}}},[Y,P]),g.useEffect(()=>{E&&We.current()},[E,me]),t.jsxs("div",{ref:_,className:"guji-text-pane-content",children:[G&&t.jsx("style",{children:Eo}),E&&t.jsx(wf,{y:me,containerRef:_,onDrag:ce,onCommit:J=>{ce(null),j==null||j(J)}}),t.jsx("div",{className:"guji-text-reflow-view",children:P.map((J,re)=>t.jsx(vf,{pGroup:J,first:re===0,pageBreaks:b,markOpts:T,plainBooks:M,selected:U.get(J.page)??xf,entityOfChar:A,entityLoader:W,convert:u,buildHref:y??hf,handlers:le},`page-sec-${J.page}`))})]})},xf=new Set,bf=[];function yf(e){const n=g.useRef(new Map);return g.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 da({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=g.memo(function({pGroup:n,first:i,pageBreaks:o,markOpts:s,plainBooks:a,selected:l,entityOfChar:d,entityLoader:c,convert:p,buildHref:h,handlers:u}){const m=g.useMemo(()=>{const y=new Map;if(!p)return y;for(const S of n.paragraphs){const b=jf(S.chars.map(w=>w.charData.char),p);S.chars.forEach((w,j)=>y.set(w.charData.id,b[j]))}return y},[n,p]),f=y=>m.get(y.id)??y.char,{t:x}=ne(),v=y=>{const S=s?zc(y.mark,s):y.mark;return S?t.jsx("span",{className:"guji-text-punct","data-punct-id":y.id,children:S},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,S)=>t.jsxs("p",{className:"guji-reflow-paragraph",children:[ff(y.chars,d).map((b,w)=>{const j=b.chars.map(({charData:C,beforePuncts:_,afterPuncts:L,start:z},T)=>{const M=!!b.entity&&T===0,P=!!b.entity&&T===b.chars.length-1,N=M?[]:_,A=P?[]:L;return t.jsxs(g.Fragment,{children:[z&&z.blankBefore>0&&t.jsx(da,{n:z.blankBefore}),N.map(v),t.jsx("span",{"data-char-id":C.id,onClick:()=>u.click(C.id),onMouseEnter:()=>u.enter(C.id),onMouseLeave:u.leave,className:`guji-text-char${l.has(C.id)?" is-selected":""}${C.sub?" is-sub":""}${C.lane==="solo"?" is-solo":""}${C.lacuna?" is-lacuna":""}${C.guess?" is-guess":""}${C.zi?" is-zi":""}${z!=null&&z.raised?" is-raised":""}`,"data-raised":(z==null?void 0:z.raised)||void 0,title:C.lacuna?x("detail.lacuna"):C.zi?x("detail.composedChar",{label:C.zi}):C.guess?x("reader.charGuess"):void 0,children:f(C)}),A.map(v)]},C.id)});if(!b.entity)return t.jsx(g.Fragment,{children:j},`r${w}`);const k=b.chars[0].beforePuncts.map(v),$=b.chars[b.chars.length-1].afterPuncts.map(v);return t.jsxs(g.Fragment,{children:[k,t.jsx(Ao,{span:b.entity,label:b.chars.map(C=>f(C.charData)).join(""),hasBrackets:!0,plain:a&&b.entity.kind==="work",loader:c,buildHref:h,onNavigate:u.navigate,renderText:()=>j,hoverDelayMs:250}),$]},`${b.entity.key}@${w}`)}),S===n.paragraphs.length-1&&n.trailingBlank?t.jsx(da,{n:n.trailingBlank}):null]},y.id))]})});function Mr(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,si=16;function wf({y:e,containerRef:n,onDrag:i,onCommit:o}){const{t:s}=ne(),[a,l]=g.useState(0),d=g.useRef(!1),c=g.useRef(e);c.current=e;const p=g.useCallback(()=>{var f,x;const m=(x=((f=n.current)==null?void 0:f.querySelector(".guji-text-reflow-view"))??n.current)==null?void 0:x.getBoundingClientRect();l(Math.max(0,((m==null?void 0:m.left)??0)-si-2))},[n]);g.useLayoutEffect(()=>(p(),window.addEventListener("resize",p),()=>window.removeEventListener("resize",p)),[p]);const h=u=>Mr(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 - ${si/2}px)`,width:si,height:si,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 m=h(u.clientY);c.current=m,i(m)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}o(h(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,o(c.current))},onKeyDown:u=>{const m=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;m&&(u.preventDefault(),o(Mr(e+m*(u.shiftKey?5:1)*kf)))}})}const Dc=1,Uc=6,ai={s:1,x:0,y:0},ui=(e,n,i)=>Math.min(i,Math.max(n,e));function Po(e,n,i){const o=ui(e.s,Dc,Uc);return{s:o,x:ui(e.x,n*(1-o),0),y:ui(e.y,i*(1-o),0)}}function dr(e,n,i,o,s,a){const l=ui(e.s*o,Dc,Uc),d=l/e.s;return Po({s:l,x:n-(n-e.x)*d,y:i-(i-e.y)*d},s,a)}function Sf(e,n,i,o,s){return Po({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 pa=4,$f=g.forwardRef(function({children:n,onScaleChange:i,resetKey:o,style:s},a){const l=g.useRef(null),[d,c]=g.useState(ai),p=g.useRef(d),h=g.useRef(i);h.current=i;const u=b=>{var j;const w=p.current;p.current=b,c(b),b.s!==w.s&&((j=h.current)==null||j.call(h,b.s))},m=()=>{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}};g.useImperativeHandle(a,()=>({zoomBy(b){const{w,h:j}=m();u(dr(p.current,w/2,j/2,b,w,j))},reset(){u(ai)}})),g.useEffect(()=>{u(ai)},[o]),g.useEffect(()=>{const b=l.current;if(!b||typeof ResizeObserver>"u")return;const w=new ResizeObserver(()=>{const{w:j,h:k}=m(),$=Po(p.current,j,k);($.x!==p.current.x||$.y!==p.current.y)&&u($)});return w.observe(b),()=>w.disconnect()},[]),g.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:$,h:C,left:_,top:L}=m();u(dr(p.current,j.clientX-_,j.clientY-L,k,$,C))};return b.addEventListener("wheel",w,{passive:!1}),()=>b.removeEventListener("wheel",w)},[]);const f=g.useRef(new Map),x=g.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=pa+1}},y=b=>{var M;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:$,h:C,left:_,top:L}=m();if(f.current.size>=2){const[P,N]=[...f.current.values()],A=Math.hypot(P.x-N.x,P.y-N.y);if(k.pinchDist>0&&A>0){const W=(P.x+N.x)/2-_,G=(P.y+N.y)/2-L;u(dr(p.current,W,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<=pa)){if(!k.dragging){k.dragging=!0;try{(M=l.current)==null||M.setPointerCapture(b.pointerId)}catch{}}k.swallowClick=!0,p.current.s>1&&u(Sf(p.current,z,T,$,C))}},S=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:S,onPointerCancel:S,onClickCapture:b=>{x.current.swallowClick&&(x.current.swallowClick=!1,b.stopPropagation(),b.preventDefault())},onDoubleClick:()=>u(ai),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 Vc(e,n,i,o){const[s,a]=g.useState(n??null),[l,d]=g.useState(!1),c=g.useRef(0);return g.useEffect(()=>{if(n!==void 0){a(n);return}const p=++c.current;if(!i){a(null),d(!1);return}if(e){let h;try{h=e(i,o)}catch{a(null),d(!1);return}if(!h||typeof h.then!="function"){a(h??null),d(!1);return}d(!0),h.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]=g.useState([]),a=g.useRef(0);return g.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?Ec(c):[])}).catch(()=>{l===a.current&&s([])})},[e,n,i]),o}const ua={padding:24,color:r("desc-fg"),fontSize:14};function ma({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)?"冊":Se.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function Gc(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(h=>[h.file,h])),l=h=>h==="loading"?"…":typeof h=="number"&&h>0?h:void 0,d=(h,u)=>{const m=a.get(h);return{key:h,label:u??(m?Gc(m,i,o,s):h),hint:l(n[h]),disabled:n[h]===0}},c=(p=e.juan_groups)==null?void 0:p.filter(h=>{var u;return h.files.some(m=>a.has(m))||((u=h.children)==null?void 0:u.length)});if(c&&c.length>0){const h=(u,m)=>{var x;if(u.files.length===1&&!((x=u.children)!=null&&x.length))return d(u.files[0],o(u.label));const f=Og(u,n);return{key:`group:${m}`,label:o(u.label),hint:f==="loading"?"…":typeof f=="number"&&f>0?`${f}`:Pc(u),defaultExpanded:typeof f=="number"&&f>0,children:[...u.files.filter(v=>a.has(v)).map(v=>d(v)),...(u.children??[]).map((v,y)=>h(v,`${m}.${y}`))]}};return c.map((u,m)=>h(u,`${m}`))}return e.chapters.map(h=>d(h.file))}const Bo=e=>{const n=Hl();return t.jsx(bu,{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:h,imagePanel:u,allowVertical:m,onReportError:f,revisedAt:x,backHref:v,backLabel:y,resolveWarpData:S,warpData:b,resolveEntities:w,onEntityNavigate:j,className:k,style:$})=>{var ls,cs,ds;const{t:C,convert:_}=ne(),L=g.useMemo(()=>Rl(i),[i]),[z,T]=e,M=tt(),P=g.useRef(a);P.current=a;const[N,A]=g.useState(null),[W,G]=g.useState("loading");g.useEffect(()=>{let R=!1;return A(null),G("loading"),L.getManifest(n).then(pe=>{R||(pe?(A(pe),G("ready")):G("missing"))}).catch(()=>{R||G("missing")}),()=>{R=!0}},[L,n]);const X=o!==void 0,le=s!==void 0,[U,D]=g.useState(null),[xe,Y]=g.useState(null);g.useEffect(()=>{D(null),Y(null)},[n]);const E=Se.pickTextVersion(N,X?o:U),Te=((ls=N==null?void 0:N.versions.find(R=>R.key==="default"))==null?void 0:ls.key)??((cs=N==null?void 0:N.versions[0])==null?void 0:cs.key)??"default",ce=(E==null?void 0:E.key)??null,me=le?s:xe,se=g.useCallback((R,pe,Ne)=>{var Ue;(Ue=P.current)==null||Ue.call(P,{key:R,chapter:pe,isDefault:R===Te},Ne)},[Te]);g.useEffect(()=>{!N||!X||o==null||N.versions.some(R=>R.key===o)||se(Te,null,"auto")},[N,X,o,Te,se]);const We=g.useRef(new Map);g.useEffect(()=>{We.current.clear()},[L,n]);const J=g.useCallback(async R=>{const pe=`${n}
1344
+ ${R}`;if(We.current.has(pe))return We.current.get(pe)??null;const Ne=await L.getIndex(n,R).catch(()=>null);return Ne&&We.current.set(pe,Ne),Ne},[L,n]),[re,de]=g.useState(null),[H,Z]=g.useState("loading"),ke=ce?`${n}
1345
+ ${ce}`:null,ie=re&&re.owner===ke?re.idx:null;g.useEffect(()=>{if(!ce)return;let R=!1;const pe=`${n}
1346
+ ${ce}`;return de(null),Z("loading"),J(ce).then(Ne=>{R||(Ne&&Ne.chapters.length>0?(de({owner:pe,idx:Ne}),Z("ready")):Z("failed"))}),()=>{R=!0}},[n,ce,J]),g.useEffect(()=>{if(!ie||!ce||me!=null&&ie.chapters.some(Ne=>Ne.file===me))return;const pe=ie.chapters[0].file;le||Y(pe),se(ce,pe,"auto")},[ie,ce,me,le,se]);const B=ie?me!=null&&ie.chapters.some(R=>R.file===me)?me:ie.chapters[0].file:me,Q=g.useMemo(()=>ie&&B?ie.chapters.find(R=>R.file===B)??null:null,[ie,B]),ae=g.useRef(0),je=g.useCallback(async R=>{if(!N||R===ce||!N.versions.some(vt=>vt.key===R))return;const pe=++ae.current,Ne=await J(R);if(pe!==ae.current)return;const Ue=Q??(B?{file:B}:null),Je=Se.matchChapterAcrossVersions(Ue,Ne);X||D(R),le||Y(Je),se(R,Je,"version")},[N,ce,J,Q,B,X,le,se]),q=g.useCallback(R=>{ce&&(le||Y(R),se(ce,R,"chapter"))},[ce,le,se]),[be,Le]=g.useState(null),Fe=ce&&Q?`${n}
1347
1347
  ${ce}
1348
- ${Z.file}`:null,[W,J]=h.useState(null),$e=Fe!==null&&W!==Fe,Te=h.useRef(0);h.useEffect(()=>{if(!ce||!Z)return;const E=++Te.current,pe=`${n}
1348
+ ${Q.file}`:null,[O,ee]=g.useState(null),_e=Fe!==null&&O!==Fe,ze=g.useRef(0);g.useEffect(()=>{if(!ce||!Q)return;const R=++ze.current,pe=`${n}
1349
1349
  ${ce}
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}
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}
1350
+ ${Q.file}`;Le(null),L.getChapter(n,ce,Q.file,{json:!!Q.has_json}).then(Ne=>{R===ze.current&&Le(Ne)}).catch(()=>{R===ze.current&&Le(null)}).finally(()=>{R===ze.current&&ee(pe)})},[L,n,ce,Q]);const F=Se.isCollatedKind(E==null?void 0:E.kind),[fe,oe]=g.useState("");g.useEffect(()=>{oe("")},[n,ce]);const we=g.useMemo(()=>ce&&F?async R=>{const pe=await L.getChapter(n,ce,R,{json:!0});return{juan:(pe==null?void 0:pe.json)??null,rawText:(pe==null?void 0:pe.md)??null}}:null,[L,n,ce,F]),Ae=(ie==null?void 0:ie.type)==="kaozhen",He=g.useMemo(()=>(ie==null?void 0:ie.chapters.map(R=>R.file))??[],[ie]),{matchStates:Ge}=Qg({resetKey:`${n}
1351
+ ${ce??""}`,load:we,files:He,activeFile:B??null,activeJuan:(be==null?void 0:be.json)??null,activeRawText:(be==null?void 0:be.md)??null,query:fe,isKaozhen:Ae}),Ye=g.useRef(new Map);g.useEffect(()=>{Ye.current.clear()},[n]);const Xe=g.useMemo(()=>({versionKey:ce,chapter:Q??null}),[ce,Q]),I=Cg(p,B??null,Xe),{warpData:V,loading:ue}=Vc(S,b,B??null,Xe),$e=Cf(w,B??null,Xe),ye=z.properNameMode??($e.length>0?"full":"off"),he=g.useMemo(()=>({...z,properNameMode:ye}),[z,ye]),Ve=g.useMemo(()=>$g($e,ye,{showWorks:he.showWorks}),[$e,ye,he.showWorks]),[te,ve]=g.useState(new Set),[Me,Oe]=g.useState(null),[Ie,ge]=g.useState(!0),Ce=z.preserveMargins;g.useCallback(R=>T({preserveMargins:R}),[T]);const De=g.useRef(null),[Pe,yt]=g.useState(1),[jt,on]=g.useState(null),Wt=R=>{var Ne;const pe=parseInt(((Ne=R==null?void 0:R.page_id)==null?void 0:Ne.split(":")[1])??"",10);return isNaN(pe)?null:pe},K=R=>{var Ne,Ue;const pe=(R==null?void 0:R.pages)??[];return Wt(R)??((Ne=pe.find(Je=>Je.columns.some(vt=>vt.chars.length>0)))==null?void 0:Ne.page)??((Ue=pe[0])==null?void 0:Ue.page)??1},[Re,qe]=g.useState(()=>K(V)),ot=`${n}
1352
1352
  ${ce}
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=`
1353
+ ${B??""}`,[Vi,Qo]=g.useState({key:ot,data:V,started:!!V});if(Vi.key!==ot)Qo({key:ot,data:V,started:!1});else if(V!==Vi.data&&(Qo({key:ot,data:V,started:!!V}),V)){const R=V.pages??[];(!Vi.started||!R.some(pe=>pe.page===Re))&&qe(K(V))}g.useEffect(()=>{ve(new Set),Oe(null)},[B,ce]);const fp=g.useCallback(R=>{if(ve(new Set(R)),R.length>0){const pe=R[0],Ne=parseInt(pe.split(":")[0],10);isNaN(Ne)||qe(Ne)}},[]),zt=g.useMemo(()=>{const R=new Map;for(const pe of(V==null?void 0:V.pages)??[])R.set(pe.page,pe);return R},[V]),vn=Wt(V),Gn=g.useCallback(R=>{var Ue;const pe=I.images;if(!pe||pe.length===0)return;const Ne=(Ue=zt.get(R))==null?void 0:Ue.seq;return(Ne?pe.find(Je=>Je.seq===Ne):void 0)??pe.find(Je=>Je.pageNo===R)??pe[R-1]},[I.images,zt]),es=Pe>1.5,Yn=g.useCallback((R,pe=!1)=>{const Ne=Gn(R);return Ne?R===vn||pe?Ne.hiresUrl??Ne.url:Ne.url:R===vn?(V==null?void 0:V.imageUrl)??"":""},[Gn,V,vn]),xp=g.useMemo(()=>Yn(Re,es),[Yn,Re,es]),Nt=g.useMemo(()=>[...zt.keys()].sort((R,pe)=>R-pe),[zt]),qn=g.useRef(Re);qn.current=Re;const Kn=g.useCallback(R=>{var pe;qn.current===R||!zt.has(R)||(qn.current=R,qe(R),(pe=zt.get(R))!=null&&pe.columns.some(Ne=>Ne.chars.length>0)&&on(Ne=>({page:R,nonce:((Ne==null?void 0:Ne.nonce)??0)+1})))},[zt]),kn=g.useCallback(R=>{const pe=qn.current,Ne=Nt.indexOf(pe),Ue=Nt[Ne<0?0:Ne+R];Ue===void 0||Ue===pe||Kn(Ue)},[Nt,Kn]),ts=g.useCallback(R=>{if(!R.trim().match(/^\d+$/)||Nt.length===0)return null;const Ne=parseInt(R.trim(),10),Ue=Number.isFinite(Ne)?Ne:Number.MAX_SAFE_INTEGER;return Nt.reduce((Je,vt)=>Math.abs(vt-Ue)<Math.abs(Je-Ue)?vt:Je,Nt[0])},[Nt]),[Gi,Yi]=g.useState(null),Xn=g.useRef(null),bp=g.useCallback(R=>{Xn.current=R,Yi(R)},[]),ns=g.useCallback(()=>{const R=Xn.current;if(Xn.current=null,Yi(null),R===null)return;const pe=ts(R);pe!==null&&Kn(pe)},[ts,Kn]),qi=Nt.indexOf(Re),yp=g.useCallback(R=>{if(R.altKey||R.ctrlKey||R.metaKey)return;const pe=R.target.tagName;pe==="INPUT"||pe==="TEXTAREA"||pe==="SELECT"||(R.key==="ArrowLeft"||R.key==="PageUp"?(R.preventDefault(),kn(-1)):(R.key==="ArrowRight"||R.key==="PageDown")&&(R.preventDefault(),kn(1)))},[kn]);g.useEffect(()=>{if(V)for(const R of[1,-1,2,3]){const pe=Yn(Re+R);pe&&Ar(pe)}},[V,Re,Yn]);const is=g.useMemo(()=>{var hs;if(!V)return null;if(Re===vn)return V;const R=zt.get(Re);if(R&&R.width>0&&R.height>0)return{page_id:`p:${Re}`,title:`第${Re}葉`,image_size:[R.width,R.height],total_warped_w:R.width,columns:[{col:1,warped_w:R.width,warped_h:R.height,offset_x:0,strips:[],chars:R.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=V.pages)==null?void 0:hs.find(Ze=>Ze.page===Re),[Ne,Ue]=V.image_size||[2386,3082],Je=Gn(Re),vt=(Je==null?void 0:Je.width)??Ne,Qi=(Je==null?void 0:Je.height)??Ue,ps=vt/Ne,us=Qi/Ue,ms=new Map;for(const Ze of V.columns){const ut=(Ze.strips||[]).flatMap(ti=>ti.srcQuad.map(ni=>ni[0]));if(ut.length===0)continue;const It=Ze.top_y??0,er=Ze.bottom_y??It+Ze.warped_h;ms.set(Ze.col,{x0:Math.min(...ut),x1:Math.max(...ut),top:It,slotH:(er-It)/21})}return{page_id:`p:${Re}`,title:`第${Re}葉`,image_size:[vt,Qi],total_warped_w:vt,columns:pe?pe.columns.map(Ze=>{const ut=ms.get(Ze.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Ze.col,warped_w:vt,warped_h:Qi,offset_x:0,strips:[],chars:Ze.chars.map(It=>{const er=It.slot??It.pos??0,ti=(ut.top+(er-1)*ut.slotH)*us,ni=(ut.x0+ut.x1)/2,[Cp,Tp]=It.sub==="a"?[ni,ut.x1]:It.sub==="b"?[ut.x0,ni]:[ut.x0,ut.x1];return{...It,bbox_col:[Cp*ps,ti,Tp*ps,ti+ut.slotH*us]}})}}):[]}},[V,Re,vn,zt,Gn]),{entryTitle:Zn,authors:rs}=Af(n,i,d===void 0),[os,Ki]=g.useState("text");if(g.useEffect(()=>{Ki("text")},[B,ce]),W==="loading")return t.jsx(ma,{className:k,style:$,title:d??Zn,label:C("reader.loading")});if(W==="missing"||!N||!E)return t.jsx("div",{className:k,style:{...$,...ua},children:C("reader.noText")});if(H==="failed")return t.jsx("div",{className:k,style:{...$,...ua},children:C("reader.tocFailed")});if(!ie)return t.jsx(ma,{className:k,style:$,title:d??Zn,label:C("reader.tocLoading")});const Yt=Nf(E,ie),jp=If(ie,Ge,Yt,_,F),Xi=N.versions.map(R=>({key:R.key,label:Se.textVersionLabel(R),optionLabel:_(Se.textVersionLabel(R)),sourceName:ga(R)?C("reader.originalSource"):R.source_name?_(R.source_name):void 0,license:R.license??void 0,sourceUrl:R.source_url??void 0,primary:R.key===Te})),pt=Tf((ds=ie.source)==null?void 0:ds.upstream),Jn=(typeof d=="string"?_(d):d)??(ie.title?_(ie.title):Zn?_(Zn):void 0),ss=E.edition_label?_(E.edition_label):void 0,Zi=Jn?t.jsx("a",{href:M(n),title:C("reader.viewEntry"),onClick:l?R=>{R.metaKey||R.ctrlKey||(R.preventDefault(),l(n))}:void 0,children:Jn}):void 0,vp=Zi&&ss?t.jsxs(t.Fragment,{children:[Zi,t.jsxs("span",{className:"bim-rd-ed",children:["·",ss]})]}):Zi,kp=rs.length>0?_(rs.slice(0,2).map(R=>`${R.dynasty?`〔${R.dynasty}〕`:""}${R.name}${` ${R.role||C("reader.defaultRole")}`}`).join("、")):void 0,Ji=Q?Gc(Q,Yt,_,F):void 0,qt=F&&!!(be!=null&&be.json),Kt=(be==null?void 0:be.json)??null,sn=(be==null?void 0:be.md)??null,as=qt&&!Ae&&Bc(Kt.sections),wp=as&&!(sn&&he.readingMode==="paragraph"&&bi(sn)),Sp=qt&&as?t.jsx(ef,{juan:Kt,view:os,onView:Ki,textHasEntries:wp}):void 0,_p=!0,Qn=sn?sn.replace(/^##\s+[^\n]+\n+/,""):null,ei=ga(E),Ot=ei?C("reader.originalSource"):E.source_name?_(E.source_name):void 0,$p=(typeof c=="string"?_(c):c)??(ei?void 0:Ot??_(Se.textVersionLabel(E)));return t.jsxs(Vl,{className:k,style:$,title:vp,subtitle:$p,byline:kp,current:Ji,pagerUnit:Yt,rail:Sp,revisedAt:x,backHref:v,backLabel:y,onReportError:f?R=>f({...R,bookTitle:typeof Jn=="string"?Jn:void 0,entryId:n}):void 0,workLinkToggle:qt&&!Ae&&!!l&&!!(Kt!=null&&Kt.sections.some(R=>R.work_id)),toc:jp,tocCaption:C("reader.tocCaption",{n:ie.chapters.length,unit:_(Yt)}),tocHeader:F&&ie.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:Ae?C("reader.searchChaptersPlaceholder"):C("reader.searchUnitPlaceholder",{unit:_(Yt)}),"aria-label":Ae?C("reader.searchChapters"):C("reader.searchUnit",{unit:_(Yt)}),value:fe,onChange:R=>oe(R.target.value)}):void 0,activeKey:B??null,onSelect:q,images:I.images,imagesLoading:I.loading||ue,renderImageOverlay:h,imagePanel:V?"open":u,isWarpMode:!!V,customImagePanel:V&&is?t.jsxs("div",{className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:yp,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:[te.size>0&&t.jsxs("button",{type:"button",onClick:()=>ve(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",te.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:Pe<=1,onClick:()=>{var R;return(R=De.current)==null?void 0:R.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(Pe*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:Pe>=6,onClick:()=>{var R;return(R=De.current)==null?void 0:R.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:Pe===1,onClick:()=>{var R;return(R=De.current)==null?void 0:R.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx($f,{ref:De,resetKey:Re,onScaleChange:yt,style:{flex:1,minHeight:0},children:t.jsx(Ro,{imageUrl:xp,pageData:is,selectedCharIds:te,hoveredCharId:Me,preserveMargins:Ce,onCharClick:R=>{ve(Ne=>{const Ue=new Set(Ne);return Ue.has(R)?Ue.delete(R):(Ue.clear(),Ue.add(R)),Ue});const pe=document.querySelector(`[data-char-id="${R}"]`);pe&&pe.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Oe})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":C("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:qi<=0,onClick:()=>kn(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":Re,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":C("reader.facsimilePageInput"),size:Math.max(2,String(Gi??Re).length),value:Gi??String(Re),onFocus:R=>R.currentTarget.select(),onChange:R=>bp(R.target.value),onKeyDown:R=>{R.key==="Enter"?(R.preventDefault(),ns()):R.key==="Escape"&&(Xn.current=null,Yi(null)),R.stopPropagation()},onBlur:ns,style:{width:`${Math.max(2,String(Gi??Re).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:qi<0||qi>=Nt.length-1,onClick:()=>kn(1),children:"›"})]})]}):void 0,settingsAnnotate:V?t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ie?"bim-rd-on":""}`,"aria-pressed":Ie,title:"切换外挂现代断句标点",onClick:()=>ge(R=>!R),children:Ie?"标点":"无标点"}):void 0,prefs:he,onPrefsChange:T,versions:Xi.length>1?Xi:void 0,currentVersionKey:Xi.length>1?E.key:void 0,onVersionChange:je,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:bi(sn),allowVertical:m,children:[(_e||ue&&!V&&!qt&&Qn==null)&&t.jsx(nn,{}),!_e&&V&&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:Q!=null&&Q.title?_(Q.title):Ji}),(Ot||E.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Ot,E.license&&t.jsxs(t.Fragment,{children:[Ot&&t.jsx("span",{className:"bim-rd-dot"}),E.license]})]})]}),t.jsx(Mo,{pageData:V,pages:V.pages,punctuations:V.punctuations||[],selectedCharIds:te,hoveredCharId:Me,onSelectionChange:fp,onCharClick:R=>{ve(Ne=>{const Ue=new Set(Ne);return Ue.has(R)?Ue.delete(R):(Ue.clear(),Ue.add(R)),Ue});const pe=parseInt(R.split(":")[0],10);isNaN(pe)||qe(pe)},onCharHover:Oe,mode:"horizontal",showPunctuation:Ie,entities:Ve,entityTransport:i,onEntityNavigate:j,onVisiblePageChange:R=>qe(R),convert:_,scrollToPage:jt,pageBreaks:he.pageBreaks,pageIndicatorY:he.pageIndicatorY,onPageIndicatorYChange:R=>T({pageIndicatorY:R}),quoteStyle:he.quoteStyle,bookTitleStyle:he.bookTitleStyle,showWorks:he.showWorks})]}),!_e&&!V&&qt&&Kt&&t.jsx(Jg,{juan:Kt,rawText:sn,positionLabel:Ef(Q,ie,Yt,_),groupLabel:Lf(ie,B??null),index:zf(n,ie),searchQuery:fe,onNavigate:l,transport:i,workLabelCache:Ye,prefs:he,view:os,onViewChange:Ki},`${ce}/${B}`),!_e&&!V&&!qt&&Qn!=null&&Q&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:Q.title?_(Q.title):Ji}),(Ot||E.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[ei&&Ot&&t.jsx(t.Fragment,{children:Ot}),!ei&&E.source_name&&t.jsxs(t.Fragment,{children:[C("reader.textSource")," ",E.source_url?t.jsx("a",{className:"bim-rd-link",href:E.source_url,target:"_blank",rel:"noreferrer",children:_(E.source_name)}):_(E.source_name)]}),Ot&&E.license&&t.jsx("span",{className:"bim-rd-dot"}),E.license]}),pt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[C("reader.upstream")," ",pt.url?t.jsx("a",{className:"bim-rd-link",href:pt.url,target:"_blank",rel:"noreferrer",children:_(pt.name??pt.url)}):_(pt.name??""),pt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),pt.license_url?t.jsx("a",{className:"bim-rd-link",href:pt.license_url,target:"_blank",rel:"noreferrer",children:pt.license}):pt.license]}),pt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(El,{text:pt.note,convert:_})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(So,{text:Qn,mode:he.readingMode,tables:_p,gujiMarkdown:!0,bookMarking:ko(he),quoteStyle:he.quoteStyle})})]}),!_e&&!ue&&!V&&!qt&&Qn==null&&Q&&t.jsx("div",{className:"bim-rd-state",children:C("reader.chapterFailed")}),ie.references&&ie.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:C("reader.references")}),t.jsx("ol",{children:ie.references.map((R,pe)=>t.jsxs("li",{children:[R.url?t.jsx("a",{className:"bim-rd-link",href:R.url,target:"_blank",rel:"noopener noreferrer",children:_(R.title)}):t.jsx("span",{children:_(R.title)}),R.author&&t.jsxs("span",{children:[",",_(R.author)]}),R.note&&t.jsxs("span",{children:["。",_(R.note)]})]},pe))})]})]})};function ga(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]=g.useState({entryTitle:void 0,authors:[]});return g.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let a=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);s({entryTitle:i&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,n,i]),o}const Yc={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=Yc.other,qc={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=qc.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 Wo=({items:e,loading:n})=>{const i=tt(),{t:o,convert:s}=ne();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=Yc[a.type]||Mf,d=qc[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:{...fa,background:l.color},children:o(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...fa,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:pr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:pr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:pr,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"},fa={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"},pr={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")},Pr=({transport:e,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:a})=>{const l=Ee(),[d,c]=g.useState(null),[p,h]=g.useState([]),[u,m]=g.useState("recommend"),[f,x]=g.useState([]),[v,y]=g.useState(!1),S=o??u,b=A=>{m(A),s==null||s(A)},[w,j]=g.useState(!0),[k,$]=g.useState(null),[C,_]=g.useState(null),[L,z]=g.useState(null);g.useEffect(()=>{let A=!1;if(e.getCounts)return e.getCounts().then(W=>{A||c({works:W.works,books:W.books,collections:W.collections})}).catch(()=>{}),()=>{A=!0}},[e]),g.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(X=>X.items.map(le=>({...le,group:X.name})))}catch{}return[]})().then(async G=>{if(A)return;const X=G.filter(U=>U.id);if(X.length===0){j(!1);return}const le=await Promise.all(X.map(async U=>{if(U.type)return{id:U.id,title:U.title,type:U.type,author:U.author,dynasty:U.dynasty,role:U.role,edition:U.edition,has_text:U.has_text,has_image:U.has_image,has_collated:U.has_collated,subtype:U.subtype,primary_name:U.primary_name,group:U.group,fallbackDescription:U.description};try{let D=null;if(e.getEntry)D=await e.getEntry(U.id);else{const xe=await e.getItem(U.id);xe&&(D={id:U.id,title:xe.title||U.id,type:xe.type||"work"})}if(D)return{...D,group:U.group,fallbackDescription:U.description}}catch{}return{id:U.id,title:U.title,type:Se.extractType(U.id),group:U.group,fallbackDescription:U.description}}));A||(h(le.filter(U=>U!==null)),j(!1))}),()=>{A=!0}},[e,i]);const T=g.useRef(!1),M=g.useRef(!1),P=g.useRef(!1);g.useEffect(()=>{if(S!=="catalog"||T.current)return;const A=e.getCatalogProgress??e.getResourceProgress;if(!A)return;T.current=!0;let W=!1;return A.call(e).then(G=>{W||$(G)}).catch(()=>{T.current=!1}),()=>{W=!0}},[e,S]),g.useEffect(()=>{if(S!=="collection"||M.current||!e.getCollectionProgress)return;M.current=!0;let A=!1;return e.getCollectionProgress().then(W=>{A||_(W)}).catch(()=>{M.current=!1}),()=>{A=!0}},[e,S]),g.useEffect(()=>{if(S!=="site"||P.current||!e.getSiteProgress)return;P.current=!0;let A=!1;return e.getSiteProgress().then(W=>{A||z(W)}).catch(()=>{P.current=!1}),()=>{A=!0}},[e,S]),g.useEffect(()=>{if(!a||S!=="feedback")return;let A=!1;return y(!0),fetch(a).then(W=>W.json()).then(W=>{!A&&W.success&&x(W.items||[])}).catch(()=>{}).finally(()=>{A||y(!1)}),()=>{A=!0}},[a,S]);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:S==="recommend",onClick:()=>b("recommend")}),t.jsx(Cn,{label:l.home.catalogTab,active:S==="catalog",onClick:()=>b("catalog")}),t.jsx(Cn,{label:l.home.collectionTab,active:S==="collection",onClick:()=>b("collection")}),t.jsx(Cn,{label:l.home.siteTab,active:S==="site",onClick:()=>b("site")}),a&&t.jsx(Cn,{label:l.home.feedbackTab,active:S==="feedback",onClick:()=>b("feedback")})]}),S==="recommend"&&t.jsx(qf,{recommended:p,loading:w,onNavigate:n,getIcon:N,t:l}),S==="catalog"&&t.jsx(xa,{progress:k,t:l,onNavigate:n}),S==="collection"&&t.jsx(xa,{progress:C,t:l,onNavigate:n}),S==="site"&&t.jsx(Xf,{progress:L,t:l,totalWorks:(d==null?void 0:d.works)??0}),S==="feedback"&&a&&t.jsx(Wo,{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 h=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})]}),h&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h})]})]},p.id)})})]},d))})},xa=({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?gt(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(ba,{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(ba,{item:c,t:n,totalWorks:i},c.id))})]})]})},ba=({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})]})},ya="(max-width: 768px)";function Zf(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(ya).matches);return g.useEffect(()=>{const i=window.matchMedia(ya),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 M;const a=Ee(),{convert:l}=Be(),d=Zf(),[c,p]=g.useState(null),[h,u]=g.useState(null),[m,f]=g.useState(!1),[x,v]=g.useState("detail"),[y,S]=g.useState([]),[b,w]=g.useState(!1),j=g.useCallback(async P=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){S([]);return}w(!0);try{if(e.getCollectionCatalogs){const N=await e.getCollectionCatalogs(P);S(N||[])}else if(e.getCollectionCatalog){const N=await e.getCollectionCatalog(P);S(N?[{resource_id:"",data:N}]:[])}}catch{S([])}finally{w(!1)}},[e]),k=g.useCallback(async P=>{if(i){i(P);return}p(P),u(null),S([]),v("detail"),f(!0);try{const N=await e.getItem(P.id);N&&(u(N),N.type==="collection"&&j(P.id))}catch(N){console.error("加载详情失败:",N)}finally{f(!1)}},[e,i,j]),$=g.useCallback(async P=>{u(null),S([]),v("detail"),f(!0);try{const N=await e.getItem(P);N&&(u(N),p({id:P,title:N.title||P,type:N.type||"book"}),N.type==="collection"&&j(P))}catch(N){console.error("导航失败:",N)}finally{f(!1)}},[e,j]),C=typeof(h==null?void 0:h.text_count)=="number"&&h.text_count>0,_=(h==null?void 0:h.type)==="collection"&&(y.length>0||b)||(h==null?void 0:h.type)==="work"&&C,L=d&&(m||h),z=g.useCallback(()=>{p(null),u(null),S([]),v("detail")},[]),T=t.jsx(t.Fragment,{children:m?t.jsx(nn,{}):h?t.jsxs(t.Fragment,{children:[(_||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:[_&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>v("detail"),style:li(x==="detail"),children:a.detailTab.basicInfo}),h.type==="collection"&&b&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:li(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),h.type==="collection"&&y.map(P=>t.jsx("button",{onClick:()=>v(`catalog:${P.resource_id}`),style:li(x===`catalog:${P.resource_id}`),children:P.short_name?`${l(P.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},P.resource_id)),h.type==="work"&&C&&t.jsx("button",{onClick:()=>v("collated"),style:li(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(to,{data:h,transport:e,onNavigate:$}):x.startsWith("catalog:")?t.jsx(no,{data:(M=y.find(P=>`catalog:${P.resource_id}`===x))==null?void 0:M.data,onNavigate:$}):x==="collated"?t.jsx(Bo,{id:h.id,transport:e,onNavigate:$}):null})]}):t.jsx(Pr,{transport:e,onNavigate:$,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:L?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(kr,{transport:e,onEntryClick:k,hideModeIndicator:n}),!h&&t.jsx(Pr,{transport:e,onNavigate:$,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(kr,{transport:e,onEntryClick:k,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:r("bg"),display:"flex",flexDirection:"column"},children:T})]})};function li(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]=g.useState(new Set),[h,u]=g.useState(null),[m,f]=g.useState("horizontal"),[x,v]=g.useState(!0),y=g.useRef(null),S=g.useCallback(k=>{p(new Set(k))},[]),b=g.useCallback(k=>{if(p($=>{const C=new Set($);return C.has(k)?C.delete(k):(C.clear(),C.add(k)),C}),y.current){const $=y.current.querySelector(`[data-char-id="${k}"]`);$&&$.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:m==="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(Ro,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:h,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:m==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(Mo,{pageData:e,punctuations:j,selectedCharIds:c,hoveredCharId:h,onSelectionChange:S,onCharClick:b,onCharHover:u,mode:m,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 st(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=st(e.raised);i!==void 0&&Number.isInteger(i)&&i>0&&(n.raised=i);const o=st(e.lead_blank);return o!==void 0&&Number.isInteger(o)&&o>0&&(n.lead_blank=o),n}function ur(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,h,u,m,f,x,v,y,S;const i=new Map,o=new Map;for(const b of ur(n)){const w=st(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($=>st($)!==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 ur(e)){const w=st(b.page);w!==void 0&&typeof b.label=="string"&&b.label&&a.set(w,b.label)}for(const b of ur(e)){const w=st(b.page);if(w===void 0)continue;const j=[];for(const $ of Array.isArray(b.columns)?b.columns:[]){const C=st($==null?void 0:$.col);if(C===void 0)continue;const _=[];for(const z of Array.isArray($.cells)?$.cells:[]){const T=ix.exec(String((z==null?void 0:z.a)??""));if(!T||typeof z.c!="string")continue;const M=parseInt(T[3],10);_.push({id:z.a,char:z.c,slot:M,pos:M,sub:T[4]||null,bbox:o.get(z.a)??null,...sx(z)})}const L=ax($);(_.length>0||L.kind==="blank")&&j.push({col:C,chars:_,...L})}if(!j.some($=>$.chars.length>0)){j.length>0&&l.set(w,j);continue}j.sort(($,C)=>$.col-C.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:st((p=k==null?void 0:k.canvas)==null?void 0:p.width)??st((h=k==null?void 0:k.image)==null?void 0:h.width)??0,height:st((u=k==null?void 0:k.canvas)==null?void 0:u.height)??st((m=k==null?void 0:k.image)==null?void 0:m.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:st((x=w.canvas)==null?void 0:x.width)??st((v=w.image)==null?void 0:v.width)??0,height:st((y=w.canvas)==null?void 0:y.height)??st((S=w.image)==null?void 0:S.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 h;const{t:s,convert:a}=ne(),[l,d]=g.useState(((h=e.divisions[0])==null?void 0:h.name)??null),[c,p]=g.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:m=>p(c===m?null:m),onNavigate:n},u.name))})]})},dx=({division:e,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=ne(),c=e.categories.reduce((p,h)=>{const u=h.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 h=`${e.name}/${p.name}`;return t.jsx(px,{category:p,expanded:o===h,onToggle:()=>s(h),onNavigate:a},p.name)})})]})},px=({category:e,expanded:n,onToggle:i,onNavigate:o})=>{var p,h,u,m;const{t:s,convert:a}=ne(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((h=e.books)==null?void 0:h.cunmu)||[],c=(((u=e.stats)==null?void 0:u.zhulu)||l.length)+(((m=e.stats)==null?void 0:m.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(ja,{label:s("catalogPage.zhulu"),books:l,onNavigate:o}),d.length>0&&t.jsx(ja,{label:s("catalogPage.cunmu"),books:d,onNavigate:o})]})]})},ja=({label:e,books:n,onNavigate:i})=>{const{t:o,convert:s}=ne(),a=tt(),[l,d]=g.useState(n.length<=20),c=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color: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,h)=>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)})]},h))}),!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=Ee();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=g.useRef(null);return g.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"}})},ji=({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 hx(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const mi=({value:e,onChange:n,label:i})=>{const[o,s]=g.useState(!1),a=g.useRef(null),l=hx(e||"");return g.useEffect(()=>{o&&a.current&&a.current.focus()},[o]),!o&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:va,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(ji,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:va,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"}})]})},va={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500};function gx(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 Kc=({items:e,onChange:n,onOpenEntityPicker:i})=>{const o=Ee(),[s,a]=g.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=u=>{n(e.filter((m,f)=>f!==u)),s===u&&a(null)},c=(u,m,f)=>{const x=[...e];x[u]={...x[u],[m]:f},n(x)},p=(u,m)=>{const f=[...e];f[u]={...f[u],type:m,id:"",name:""},n(f),m==="bookID"&&i&&i(x=>{const v=[...e];v[u]={...v[u],id:x.id,name:x.title,type:"bookID"},n(v)})},h=u=>{i&&i(m=>{const f=[...e];f[u]={...f[u],id:m.id,name:m.title,type:"bookID"},n(f)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,m)=>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===m?null:m),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===m?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:r("fg")},children:u.name||`${o.editor.sourcePlaceholder} ${m+1}`}),u.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:gx(u.type),color:r("on-color-fg"),borderRadius:"3px",fontWeight:500},children:fx(u.type)}),t.jsx("button",{onClick:f=>{f.stopPropagation(),d(m)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===m&&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(m,"bookID"),style:{...ka,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(m,"url"),style:{...ka,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[m]={...f[m],type:"",id:"",name:""},n(f)},style:wa,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:()=>h(m),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:()=>h(m),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[m]={...f[m],type:"",id:"",name:""},n(f)},style:wa,children:o.action.changeType})]}),t.jsx("input",{type:"text",value:u.name,onChange:f=>c(m,"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(m,"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(m,"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(m,"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(m,"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(m,"processor_version",f.target.value),placeholder:"如: v0.1",style:ln})]})]})]})]})})]},m)),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"},ka={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"},wa={background:"transparent",border:"none",color:r("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Xc(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 Zc(e){return!e||e.length===0?"":JSON.stringify(e)}const Jc=({entityType:e,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:h,onLinkEntity:u,onUnlinkEntity:m,onViewEntity:f,onCreateAndLink:x,onSaveRelations:v})=>{const y=Ee();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:()=>m("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:()=>m("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&&h&&h.length>0&&t.jsx(cn,{direction:"horizontal",title:`${y.relation.siblingVersions} (${h.length})`,entities:h,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:()=>m("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:()=>m("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:()=>m("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:h,unlinkLabel:u})=>{const m=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:m,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:Qc(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(Sa,{onClick:()=>o(i),title:h,children:"👁️"}),t.jsx(Sa,{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(Br,{onClick:a,children:d}),t.jsx(Br,{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]=g.useState(!1),h=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),u=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",m=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:h,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:[m.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:Qc(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(Br,{onClick:s,primary:!0,children:["+ ",a]})})]})},Sa=({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}),Br=({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 Qc(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"},ed=({isOpen:e,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[h,u]=g.useState(""),m=p?l.filter(y=>y.id!==p):l;g.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:h,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:mr,children:"搜索中..."}):m.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:m.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))}):h?t.jsxs("div",{style:mr,children:["未找到匹配的",x]}):t.jsxs("div",{style:mr,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")},mr={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:"👤"},td=({isOpen:e,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:a})=>{const[l,d]=g.useState(""),c=g.useRef(null);g.useEffect(()=>{e&&(d((o==null?void 0:o.title)||""),setTimeout(()=>{var m,f;(m=c.current)==null||m.focus(),(f=c.current)==null||f.select()},100))},[e,o==null?void 0:o.title]);const p=m=>{m.key==="Enter"&&l.trim()?h():m.key==="Escape"&&a()},h=()=>{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:m=>{m.target===m.currentTarget&&a()},children:t.jsxs("div",{style:$x,onClick:m=>m.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:m=>d(m.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:h,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 nd(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 id=({isOpen:e,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:h})=>{const[u,m]=g.useState(""),[f,x]=g.useState([]),[v,y]=g.useState(!1),[S,b]=g.useState("recent");g.useEffect(()=>{e&&(m(""),x([]),b(o.length>0?"recent":"search"))},[e,o.length]),g.useEffect(()=>{if(!u.trim()){x([]);return}const _=setTimeout(async()=>{y(!0);try{x(await h(u,i))}catch{x([])}finally{y(!1)}},300);return()=>clearTimeout(_)},[u,i,h]);const w=g.useCallback(_=>{m(_.target.value),_.target.value.trim()&&b("search")},[]),j=g.useCallback(_=>s?_.filter(L=>L.id!==s):_,[s]);if(!e)return null;const k=n||(i==="all"?"选择实体":`选择${nd(i)}`),$=j(o),C=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:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${r("widget-border")}`},children:[t.jsxs($a,{active:S==="recent",onClick:()=>b("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs($a,{active:S==="search",onClick:()=>b("search"),children:["搜索结果 ",C.length>0&&`(${C.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&$.length>0?t.jsx(Ca,{entities:$,onSelect:d}):u.trim()?v?t.jsx(hr,{message:"搜索中..."}):C.length>0?t.jsx(Ca,{entities:C,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||"创建新实体"})]})]})})},$a=({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}),Ca=({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]=g.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:nd(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:"👤"},rd=({data:e,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:h,relations:u,onRelationsChange:m})=>{var je;const f=Ee(),[x,v]=g.useState(!1),[y,S]=g.useState("work"),[b,w]=g.useState(""),[j,k]=g.useState(""),[$,C]=g.useState([]),[_,L]=g.useState(!1),[z,T]=g.useState(!1),[M,P]=g.useState("work"),[N,A]=g.useState(""),[W,G]=g.useState(),[X,le]=g.useState(!1),[U,D]=g.useState(null),[xe,Y]=g.useState([]);g.useRef(null);const E=e.type,Te=E==="work",ce=E==="collection",me=E==="book",se=g.useCallback((q,be)=>{n({...e,[q]:be})},[e,n]),We=g.useCallback((q,be)=>{w(q),S(be),k(f.editor.selectToLink+f.indexType[be]),C([]),v(!0)},[f]),J=g.useCallback(q=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(e.id,q)},[o,e.id]),re=g.useCallback(q=>{s==null||s(q.id,q.type)},[s]),de=g.useCallback((q,be,Le)=>{const Fe={...Le,author:(Le==null?void 0:Le.author)||e.author,dynasty:Le==null?void 0:Le.dynasty};P(be),A(q),G(Fe),T(!0)},[e.author]),H=g.useCallback((q,be)=>{o!=null&&o.createAndLink&&o.createAndLink(e.id,N,{type:M,title:q,inheritData:be}),T(!1)},[o,e.id,N,M]),Z=g.useCallback(q=>{if(!q.trim()){C([]);return}L(!0),o!=null&&o.searchEntities&&o.searchEntities(q,y).then(be=>{C(be),L(!1)}).catch(()=>{C([]),L(!1)})},[o,y]),ke=g.useCallback(q=>{o!=null&&o.linkEntity&&o.linkEntity(e.id,b,q.id),v(!1)},[o,e.id,b]),ie=g.useCallback(()=>{i()},[i]),B=g.useCallback(q=>{D(()=>q),le(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(Y).catch(()=>{})},[o]),Q=g.useCallback((q,be)=>o!=null&&o.searchEntities?o.searchEntities(q,be==="all"?void 0:be):Promise.resolve([]),[o]),ae=g.useCallback(q=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(q),Y(be=>[q,...be.filter(Le=>Le.id!==q.id)].slice(0,10)),U==null||U(q),le(!1),D(null)},[o,U]);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[E]}),t.jsx("span",{children:e.title||f.editor.untitled}),t.jsx(ji,{children:e.id}),t.jsx(ji,{color:Bx[E],children:f.indexType[E]})]})}),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(mi,{label:Te?f.editor.workTitle:ce?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:q=>se("title",q)}),me&&t.jsx(mi,{label:f.editor.belongsToWork,value:e.workName||"",onChange:q=>se("workName",q)}),t.jsx(ht,{label:f.editor.authorLabel,value:e.author||"",onChange:q=>se("author",q)}),t.jsx(ht,{label:f.editor.publicationYearLabel,value:e.publicationYear||"",onChange:q=>se("publicationYear",q)}),(me||ce)&&t.jsx(mi,{label:f.editor.containedIn,value:e.collection||"",onChange:q=>se("collection",q)}),(me||ce)&&t.jsx(ht,{label:f.editor.holderLabel,value:e.holder||"",onChange:q=>se("holder",q)}),(me||ce)&&t.jsx(ht,{label:me?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:q=>se("pages",q)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(ht,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:q=>se("firstImage",q)})})]})}),t.jsx(kt,{title:f.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(tn,{value:e.description||"",onChange:q=>se("description",q),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:q=>se("additional_works",q)})}),t.jsx(kt,{title:f.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Fx,{items:e.indexed_by||[],onChange:q=>se("indexed_by",q)})}),t.jsx(kt,{title:f.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Hx,{items:e.emendated_by||[],onChange:q=>se("emendated_by",q)})}),t.jsx(kt,{title:f.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(jr,{items:e.resources||[],onChange:q=>se("resources",q),onDownload:p,downloadStatuses:h,filterType:"text"})}),t.jsx(kt,{title:f.section.imageResources,onSave:i,children:t.jsx(jr,{items:e.resources||[],onChange:q=>se("resources",q),onDownload:p,downloadStatuses:h,filterType:"image"})}),t.jsx(kt,{title:f.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(Kc,{items:Xc(e.sources||""),onChange:q=>se("sources",Zc(q)),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:q=>se("provenance",q),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:q=>se("otherEditions",q),placeholder:f.editor.otherEditionsPlaceholder})}),t.jsx(Jc,{entityType:E,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:We,onUnlinkEntity:J,onViewEntity:re,onCreateAndLink:de,onSaveRelations:ie}),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(ed,{isOpen:x,entityType:y,title:j,onSelect:ke,onCancel:()=>v(!1),onCreate:()=>{v(!1),de(b,y)},searchResults:$,onSearch:Z,isLoading:_,excludeId:e.id}),t.jsx(td,{isOpen:z,entityType:M,relationField:N,inheritData:W,onConfirm:H,onCancel:()=>T(!1)}),t.jsx(id,{isOpen:X,title:f.action.selectBookOrWork,filterType:"all",recentEntities:xe,excludeId:e.id,onSelect:ae,onCancel:()=>{le(!1),D(null)},onSearch:Q})]})};function Ox({items:e,onChange:n}){const i=Ee(),o=(l,d,c)=>{const p=e.map((h,u)=>u===l?{...h,[d]:c}:h);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 od({items:e,onChange:n,showMeta:i,addLabel:o}){const s=Ee(),[a,l]=g.useState(null),d=(h,u,m)=>{const f=e.map((x,v)=>v===h?{...x,[u]:m||void 0}:x);n(f)},c=h=>{n(e.filter((u,m)=>m!==h)),a===h&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((h,u)=>{const m=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:m?`color-mix(in srgb, ${r("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(m?null:u),children:[t.jsx("span",{style:{fontSize:"10px",color:r("desc-fg"),transition:"transform 0.2s",transform:m?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:h.source||s.editor.unnamedSource}),h.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:h.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:"✕"})]}),!m&&i&&(h.title_info||h.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:r("desc-fg")},children:[h.title_info,h.title_info&&h.author_info&&" — ",h.author_info]}),m&&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:h.source,onChange:f=>d(u,"source",f)}),t.jsx(ht,{label:s.label.sourceBid,value:h.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:h.title_info||"",onChange:f=>d(u,"title_info",f)}),t.jsx(ht,{label:s.label.authorInfo,value:h.author_info||"",onChange:f=>d(u,"author_info",f)})]}),t.jsx(ht,{label:s.label.edition,value:h.edition||"",onChange:f=>d(u,"edition",f)})]}),t.jsx(tn,{value:h.summary||"",onChange:f=>d(u,"summary",f),placeholder:s.editor.summaryPlaceholder}),t.jsx(tn,{value:h.comment||"",onChange:f=>d(u,"comment",f),placeholder:s.editor.commentPlaceholder}),t.jsx(tn,{value:h.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=Ee();return t.jsx(od,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Hx({items:e,onChange:n}){const i=Ee();return t.jsx(od,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function sd(e){var d,c,p,h,u,m,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=((h=e.current_location)==null?void 0:h.name)||"",s=(u=e.page_count)!=null&&u.number?String(e.page_count.number):((m=e.page_count)==null?void 0:m.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:h,onAskAI:u,renderSectionActions:m,onDownloadResource:f,downloadStatuses:x,relations:v,onRelationsChange:y,headerExtra:S,className:b,style:w}=e,j=Ee(),[k,$]=g.useState(s),C=a?s:k;g.useEffect(()=>{s!==k&&$(s)},[s]);const _=g.useCallback(()=>{const A=C==="view"?"edit":"view";a?a(A):$(A)},[C,a]),[L,z]=g.useState(null);g.useEffect(()=>{i&&o&&o.getItem(i).then(A=>{A&&z(A)})},[i,o]);const T=n||L,M=g.useMemo(()=>T?sd(T):null,[T]),P=a||!n?t.jsx("button",{onClick:_,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:C==="edit"?r("accent-bg"):"transparent",color:r(C==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:C==="view"?j.common.switchToEdit:j.common.switchToView,children:C==="view"?j.common.modeEdit:j.common.modeView}):null,N=t.jsxs(t.Fragment,{children:[P,S]});return!T&&!M?t.jsx(nn,{}):C==="view"?t.jsx(to,{data:T,transport:o,onNavigate:p?A=>p(A):void 0,renderLink:h,headerExtra:N,className:b,style:w}):M?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(rd,{data:M,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:u,renderSectionActions:m,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:"🤝"}],ad=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const{t:s}=ne(),[a,l]=g.useState(null),[d,c]=g.useState(""),[p,h]=g.useState(""),[u,m]=g.useState("idle"),[f,x]=g.useState(""),v=g.useRef(null);g.useEffect(()=>{e&&(l(null),c(""),h(""),m("idle"),x(""))},[e]),g.useEffect(()=>{a&&setTimeout(()=>{var b;return(b=v.current)==null?void 0:b.focus()},100)},[a]),g.useEffect(()=>{if(u==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[u,n]),g.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())){m("submitting"),x("");try{await i({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),m("success")}catch(b){m("error"),x(b instanceof Error?b.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const S=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=>h(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:!S,style:{...Qx,opacity:S?1:.6,cursor:S?"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"},Wr="--bim-feedback-fab-offset",Or=48,ib=16,rb=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:o=!1,zIndex:s})=>{const{t:a}=ne(),[l,d]=g.useState(!1),c=n.bottom??24;return g.useEffect(()=>{if(o||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(Wr,`calc(${c+Or+ib}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(Wr)}},[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(ad,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},ob={position:"fixed",width:`${Or}px`,height:`${Or}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:"🤝"}],ld=({onSubmit:e})=>{const{t:n}=ne(),[i,o]=g.useState("bug"),[s,a]=g.useState(""),[l,d]=g.useState(""),[c,p]=g.useState("idle"),[h,u]=g.useState(""),m=g.useRef(null);g.useEffect(()=>{i&&setTimeout(()=>{var v;return(v=m.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:Ta,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:Ta,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:m,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:hb}),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:h})]})},Ta={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"},hb={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 za(e){return typeof e=="function"?e():e??"/api/feedback"}const cd=({resourceId:e,apiUrl:n})=>{const{t:i}=ne(),[o,s]=g.useState([]),[a,l]=g.useState(!0),d=g.useCallback(async()=>{const p=za(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]);g.useEffect(()=>{d()},[d]);const c=async p=>{const h=za(n),u=await fetch(h,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!u.ok){const m=await u.json().catch(()=>null);throw new Error((m==null?void 0:m.error)||i("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(Wo,{items:o,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(ld,{onSubmit:c})})]})},Mi=8;async function Pi(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 gb=wi["zh-Hant"].relation,fb=wi["zh-Hant"].lossStatus,xb=wi["zh-Hant"].resourceKind,Bi=yn("zh-Hant"),Oo=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function Na(e,n=Bi){return e?Oo(gb,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function bb(e,n=Bi){return Oo(fb,e)?n(`detail.lossStatus.${e}`):e}function yb(e,n=Bi){return Oo(xb,e)?n(`detail.resourceKind.${e}`):""}function Fo({authors:e,onNavigate:n,renderLink:i}){const{convert:o}=ne(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=co(a.role);return t.jsxs(g.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",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 dd(e,n,i=Bi){var c,p;const o=ao(e,n),s=o.mirrors.map(h=>({key:h.key,label:h.label,description:h.description,rows:h.items.filter(u=>u.group_role!=="mirror"),mirrors:h.items.filter(u=>u.group_role==="mirror")})),a=o.buckets.filter(h=>h.key==="image"||h.key==="textImage").flatMap(h=>h.items);a.length&&s.push({key:"_images",label:s.length?i("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=o.buckets.find(h=>h.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(h=>h.key==="text"))==null?void 0:p.items)??[],groups:s}}function pd(e,n){const i=(e.url?fn(e.url):void 0)||e.name,o=ql(e,n);return o?`${i}(${o})`:i}function Ho({item:e,siblings:n,listedVolumeCounts:i}){const{t:o,convert:s}=ne(),[a,l]=g.useState(!1),d=ki(e),c=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),p=s(pd(e,n)),h=xn(e),u=Ii(e,o)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,x;const m=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((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 h?t.jsxs("a",{href:h,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),m]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,m]})})(),u&&t.jsx("span",{className:"bim-d-meta",children:s(u)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(xo,{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(m=>!m),children:a?o("detail.collapseVolumes"):o("detail.expandVolumes",{n:d.expected})})})]})}function ud({groups:e,listedVolumeCounts:n}){const{t:i,convert:o}=ne();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(Ho,{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(pd(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 Fr(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 Ia=12,jb=60,md=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,railTop:a,back:l,railLinks:d})=>{var Z,ke,ie;const{t:c,convert:p,messages:h}=ne(),u=g.useMemo(()=>po({_books:e._books}),[e._books]),[m,f]=g.useState(new Map),[x,v]=g.useState(!1),[y,S]=g.useState(""),[b,w]=g.useState(!1),j=u.length<=jb,k=j||x||!!y||b,$=g.useMemo(()=>k?u:u.slice(0,Ia),[u,k]);g.useEffect(()=>{if(!n||$.length===0)return;const B=$.filter(ae=>!m.has(ae));if(B.length===0)return;let Q=!1;return Pi(B,Mi,ae=>n.getItem(ae).then(je=>{const q=je??{};return[ae,{id:ae,title:q.title,edition:q.edition,resources:q.resources,publication_info:q.publication_info,current_location:q.current_location,lineage:q.lineage,measure_info:q.measure_info}]}).catch(()=>[ae,{id:ae}]),()=>Q).then(ae=>{Q||f(je=>{const q=new Map(je);for(const[be,Le]of ae)q.set(be,Le);return q})}),()=>{Q=!0}},[n,$,m]);const C=g.useMemo(()=>u.map(B=>m.get(B)??{id:B}),[u,m]),_=u.length>0&&u.every(B=>m.has(B)),L=!!n&&$.some(B=>!m.has(B)),z=j||k,T=g.useMemo(()=>Xl(C,e.version_graph,{era:y,scanOnly:b,sort:z?"year":"default"}),[C,e.version_graph,y,b,z]),M=x?T.rows:T.rows.slice(0,Ia),P=T.allRows.filter(B=>B.hasImage).length,N=g.useMemo(()=>(e._related||[]).map(B=>({...B,title:B.title??""})),[e._related]),A=N.filter(B=>B.relation==="collected_in"),W=g.useMemo(()=>{const B=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],Q=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)=>Q(ae.r.relation)-Q(je.r.relation)||ae.i-je.i).map(ae=>ae.r)},[N]),G=g.useMemo(()=>{const B=ao(e.resources,e.resource_groups);return[...B.mirrors.flatMap(Q=>Q.items.map(ae=>({r:ae,kind:p(Q.label)}))),...B.buckets.flatMap(Q=>Q.items.map(ae=>({r:ae,kind:p(yb(Q.key,c))})))]},[e.resources,e.resource_groups,p,c]),X=e.indexed_by||[],le=e.emendated_by||[],U=g.useMemo(()=>{var O,ee,_e;const B=[],Q=(ee=(O=e.authors)==null?void 0:O[0])==null?void 0:ee.dynasty;Q&&B.push({label:c("workPage.fact.written"),value:p(Q)});const ae=Bt(e,h.unit.juan);if(ae){const ze=(_e=e.juan_count)==null?void 0:_e.description;B.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(ae),ze&&ze!==ae?t.jsxs("span",{className:"bim-d-meta",children:["(",p(ze),")"]}):null]})})}e.loss_status&&B.push({label:c("workPage.fact.loss"),value:p(bb(e.loss_status,c))});const je=T.allRows.filter(ze=>ze.sortYear!=null),q=je.length>0?je.reduce((ze,F)=>ze.sortYear<=F.sortYear?ze:F):null;q!=null&&q.era.era?B.push({label:c("workPage.fact.earliest"),value:p([q.era.era,q.era.reign].filter(Boolean).join(" ")),title:q.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):L&&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=Ra(e.additional_titles);be.length&&B.push({label:c("workPage.fact.alias"),value:be.map(p).join("、")});const Le=Ra(e.attached_texts);Le.length&&B.push({label:c("workPage.fact.attached"),value:Le.map(p).join("、")});const Fe=(e.additional_works||[]).map(ze=>p(ze.book_title)+(ze.n_juan!=null?` ${ze.n_juan}${h.unit.juan}`:""));return Fe.length&&B.push({label:c("workPage.fact.appendix"),value:Fe.join("、")}),B},[e,p,c,h,L,T.allRows,le.length]),xe=[{value:e._edition_count??u.length,label:c("workPage.stat.editions")},{value:_?P:0,label:c("workPage.stat.hasImage")},{value:X.length,label:c("workPage.stat.catalogs")}],Y=uo(e),E=Y?[Y.l1,Y.l2,Y.l3,Y.l4].filter(Boolean).map(B=>p(B)):[],Te=e.subtype?h.workSubtype[e.subtype]??p(e.subtype):"",ce=t.jsx(Fn,{title:p(e.title),byline:t.jsx(Fo,{authors:e.authors,onNavigate:i,renderLink:o}),meta:t.jsx(it,{items:[...E,Y!=null&&Y.source?c("workPage.classifiedBy",{source:p(Y.source.split("/")[0])}):"",Te]}),description:(Z=e.description)!=null&&Z.text?t.jsxs(t.Fragment,{children:[t.jsx(Pt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ke=e.description.sources)!=null&&ke.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(B=>({text:p(mh(B)),href:hh(B)})).filter(B=>B.text).map((B,Q)=>t.jsxs(g.Fragment,{children:[Q>0?" · ":null,B.href?t.jsx("a",{href:B.href,target:"_blank",rel:"noopener noreferrer",children:B.text}):B.text]},Q))}):null]}):void 0,stats:xe,facts:U,readAction:s,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(ie=e.appendix)==null?void 0:ie.map((B,Q)=>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}})]},Q))}),me=T.eras.length>=2?[{key:"",label:c("catalog.all")},...T.eras.map(B=>({key:B,label:`${B} ${T.allRows.filter(Q=>Q.era.era===B).length}`}))]:[],se=[];u.length&&se.push({id:"versions",label:c("workPage.sec.versions"),count:u.length}),X.length&&se.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:X.length}),A.length&&se.push({id:"collected",label:c("workPage.sec.collected"),count:A.length}),W.length&&se.push({id:"related",label:c("workPage.sec.related"),count:W.length}),G.length&&se.push({id:"resources",label:c("workPage.sec.resources"),count:G.length});const We=u.length===0&&X.length===0,J=t.jsxs(t.Fragment,{children:[u.length>0&&t.jsxs(rt,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(it,{items:[c("workPage.versionsTotal",{n:u.length}),_&&P?c("workPage.versionsWithImage",{n:P}):"",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":L&&me.length===0&&u.length>1?"":void 0,children:[me.length>0&&t.jsx(Ei,{items:me,value:y,onChange:B=>{S(B),v(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(lc,{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&&Li(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:M.map(B=>{var Q;return t.jsx(vb,{row:B,measure:(Q=m.get(B.id))==null?void 0:Q.measure_info,loaded:m.has(B.id),onNavigate:i,renderLink:o},`${B.id}:${m.has(B.id)?"r":"p"}`)})})]}),M.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(mo,{total:T.rows.length,shown:M.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")})]}),X.length>0&&t.jsx(kb,{items:X,transport:n,onNavigate:i,renderLink:o}),We&&t.jsx(rt,{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,Q)=>t.jsx(et,{id:B,label:p(Q),onNavigate:i,renderLink:o,dense:!0}),de=g.useMemo(()=>{const B=new Map;for(const Q of W){const ae=Na(Q.relation,c);B.set(ae,(B.get(ae)??0)+1)}return B.size>1?[...B.entries()].sort((Q,ae)=>ae[1]-Q[1]).slice(0,4).map(([Q,ae])=>`${p(Q)} ${ae}`).join(" · "):void 0},[W,p,c]),H=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:W.length}),sub:de,items:W.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(Na(B.relation,c))})]}))}),t.jsx(en,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:G.map(({r:B,kind:Q})=>{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}),Q&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:Q})]})})})]});return t.jsx(On,{railTop:a,back:l,nav:se,railLinks:d,main:J,card:ce,side:H})};function Ra(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ea(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}=ne(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],h=p?Ea(p,l):e.locationName?l(e.locationName):"",u=e.images[0],m=u?xn(u):void 0,f=e.images.map(x=>Ea(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${h?"":" bim-d-zt-blank"}`,children:[h||(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&&(m?t.jsx("a",{className:"bim-d-flag",href:m,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}=ne(),[l,d]=g.useState(0),c=Math.min(l,e.length-1),p=e[c],[h,u]=g.useState(new Map);return g.useEffect(()=>{if(!n)return;const m=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(m.length===0)return;let f=!1;return Promise.all(m.map(x=>n.getItem(x).then(v=>{var y,S;return[x,((S=(y=v==null?void 0:v.authors)==null?void 0:y[0])==null?void 0:S.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{f||u(new Map(x.filter(([,v])=>v)))}),()=>{f=!0}},[n,e]),t.jsx(rt,{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((m,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(m.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:h.get(m.source_bid??"")?a(h.get(m.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(m.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:ft(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:ft(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:ft(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 La(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[h,u]of Object.entries(e.node_groups))l.has(u)&&d.add(h);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),l){c||(c=new Set);for(const h of e.hypothetical_nodes??[])h.group&&l.has(h.group)&&c.add(h.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,h=(d==null?void 0:d.hypos)??null,u=new Set,m=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])),$=z=>{const T=j.get(z);if(T&&T.lineage)return(T.lineage.derived_from??[]).map(P=>P.ref);const M=k.get(z);return M?(M.derived_from??[]).map(P=>P.ref):[]},C=z=>k.has(z)?!h||h.has(z):!p||p.has(z),_=new Set,L=z=>{if(!_.has(z)){_.add(z);for(const T of $(z))a.has(T)||(C(T)||(k.has(T)?m.add(T):j.has(T)&&u.add(T)),L(T))}};for(const z of n)p&&p.has(z.id)&&!a.has(z.id)&&L(z.id);for(const z of o.hypothetical_nodes??[])h&&h.has(z.id)&&L(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=>!h||h.has(j.id)||m.has(j.id)).map(j=>{const k=wb(j);return m.has(j.id)&&(k.bridge=!0),k}),v=[...f,...x],y=new Set(v.map(j=>j.id)),S=new Set,b=[],w=j=>{S.has(j.id)||!y.has(j.source)||!y.has(j.target)||(S.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,$)=>{w(La(j.id,k,$))}),(j.lineage.related_to??[]).forEach((k,$)=>{w(_b(j.id,k,$))}));for(const j of o.hypothetical_nodes??[])h&&!h.has(j.id)&&!m.has(j.id)||(j.derived_from??[]).forEach((k,$)=>{w(La(j.id,k,$))});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(h=>d(p,h)),(c.lineage.related_to??[]).forEach(h=>{s.has(h.book_id)||i.push(`${p}: related_to.book_id "${h.book_id}" 不在 books 列表中`)})}for(const c of o.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(h=>d(p,h))}return i}const gd=({graph:e,renderLink:n,className:i,style:o})=>{const{t:s,convert:a}=ne();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,h=[];for(const f of e.nodes)if(f.group){const x=p.get(f.group)??[];x.push(f),p.set(f.group,x)}else h.push(f);const u=(f,x)=>(f.year??9999)-(x.year??9999);p.forEach(f=>f.sort(u)),h.sort(u);const m=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)}),m.map(f=>t.jsx(Aa,{label:f.label,color:f.color,nodes:p.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},f.id)),h.length>0&&t.jsx(Aa,{label:s("lineage.otherGroup"),nodes:h,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},Aa=({label:e,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=ne();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}=ne();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:Pa,children:[t.jsx("div",{style:Ba,children:d("lineage.sources")}),n.map(p=>{const h=o.get(p.source);return t.jsxs("div",{style:Wa(p.confidence),children:[t.jsx("span",{style:Oa,children:c(p.relation)}),t.jsx("span",{children:(h==null?void 0:h.kind)==="book"&&s?s(h.id,c(h.label)):c((h==null?void 0:h.label)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(Ma,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:Fa,children:["· ",c(p.evidence)]})]},p.id)})]}),i.length>0&&t.jsxs("div",{style:Pa,children:[t.jsx("div",{style:Ba,children:d("lineage.related")}),i.map(p=>{const h=p.source===e.id?p.target:p.source,u=o.get(h);return t.jsxs("div",{style:Wa(p.confidence),children:[t.jsx("span",{style:Oa,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)??h)}),t.jsx(Ma,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:Fa,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})},Ma=({level:e})=>{const{t:n}=ne(),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"},Pa={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r("widget-border")}`},Ba={fontSize:"11px",color:r("muted"),marginBottom:"2px"},Wa=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Oa={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r("tag-bg"),color:r("fg"),borderRadius:"3px",marginRight:"6px"},Fa={fontSize:"11px",color:r("muted")},Fb={padding:"20px",textAlign:"center",color:r("muted"),fontSize:"13px"},fd=({selectedNodeId:e,...n})=>{const{t:i}=ne(),[o,s]=g.useState("loading"),[a,l]=g.useState(null);return g.useEffect(()=>{let d=!1;return Hb().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),o==="loading"?t.jsx("div",{style:Da,children:i("lineage.graphLoading")}):o==="missing"||!a?t.jsxs("div",{style:Da,children:[t.jsx("div",{children:Ha(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:Ha(i("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Db,{modules:a,selectedNodeId:e,...n})};function Ha(e,n){return e.split(/(\{\w+\})/).map((i,o)=>{const s=/^\{(\w+)\}$/.exec(i);return t.jsx(g.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:h,Position:u,BaseEdge:m,EdgeLabelRenderer:f,getSmoothStepPath:x,dagre:v}=l,y=g.useMemo(()=>({lineage:$=>{var W,G,X,le;const C=((W=$.data)==null?void 0:W.stepPosition)??.85,[_,L,z]=x({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:C,borderRadius:5}),T=!!((G=$.data)!=null&&G.isSibling),M=T?L:$.targetX-18,P=T?z:$.targetY-12,N=(X=$.data)==null?void 0:X.labelStyle,A=(le=$.data)==null?void 0:le.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(m,{id:$.id,path:_,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${M}px,${P}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:$.label})})]})}}),[m,f,x]),S=g.useMemo(()=>({version:$=>{const{t:C}=ne(),_=$.data,L=_.kind==="hypothetical",z=_.status==="lost",T=_.isSelected,M=_.bridge,P=_.borderColor??r("muted"),N=M||L?"dashed":"solid",A=M?.5:z?.6:1;return t.jsxs("div",{style:{background:r(M?"bg-subtle":"bg"),border:`2px ${N} ${T?r("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:T?r("shadow-node-selected"):L||M?"none":r("shadow-node")},title:M?C("lineage.bridgeTitle"):void 0,children:[t.jsx(h,{type:"target",position:u.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:L||!_.renderLink?_.label:_.renderLink(_.bookId,_.label)}),_.description&&t.jsx("div",{style:{fontSize:10,color:r("aux-fg"),lineHeight:1.25,marginTop:1},children:_.description}),_.yearText&&t.jsx("div",{style:{fontSize:10,color:r("aux-fg"),lineHeight:1.2},children:hd(_.yearText,void 0,_.uncertain)}),z&&t.jsx("div",{style:{fontSize:9,color:r("lost-fg"),marginTop:1},children:C("lineage.lost")}),t.jsx(h,{type:"source",position:u.Right,style:{visibility:"hidden"}})]})}}),[h,u]),{convert:b}=ne(),{rfNodes:w,rfEdges:j}=g.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:S,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(S=>[S.id,S.color??r("muted")]));for(const S of e.nodes)c.setNode(S.id,{width:160,height:90});const h=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const S of e.edges)S.kind==="derive"&&(h.has(S.relation)||c.setEdge(S.source,S.target));n.layout(c);const u=e.nodes.map(S=>{const b=c.node(S.id),w=o?S.id===o:void 0,j={kind:S.kind,label:s(S.label),bookId:S.kind==="book"?S.id:void 0,yearText:s(S.year_text??Gb(S)),uncertain:S.year_uncertain,category:S.category,status:S.status,borderColor:S.group?p.get(S.group):void 0,renderLink:i,isSelected:w,description:s(S.description),bridge:S.bridge};return{id:S.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:j,draggable:!1,selected:w}}),m=.78,f=.06,x=new Map;for(const S of e.edges)S.kind==="derive"&&(x.has(S.source)||x.set(S.source,[]),x.get(S.source).push(S));const v=new Map;for(const[S,b]of x){if(b.length<=1)continue;const w=[...b].sort((k,$)=>{var L,z;const C=((L=c.node(k.target))==null?void 0:L.y)??0,_=((z=c.node($.target))==null?void 0:z.y)??0;return C-_}),j=w.length;w.forEach((k,$)=>{const C=($-(j-1)/2)*f;v.set(k.id,m+C)})}const y=e.edges.map(S=>Vb(S,v.get(S.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 Da={padding:"40px 20px",textAlign:"center",color:r("muted"),fontSize:"13px",border:`1px dashed ${r("widget-border")}`,borderRadius:8,background:r("bg")},Do=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:h,style:u})=>{var j;const{t:m,convert:f}=ne(),[x,v]=g.useState(n),y=k=>{v(k),a==null||a(k)},S=(()=>{if(!c)return[];const k=Object.entries(c);return k.length===0||c.all?k:[...k,["all",{label:m("lineage.collectionAll"),description:m("lineage.collectionAllDesc")}]]})(),b=!!(d&&S.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r("muted"),textAlign:"center"},children:m("lineage.empty")});const w=l?(j=c==null?void 0:c[l])==null?void 0:j.description:void 0;return t.jsxs("div",{className:h,style:u,children:[t.jsxs("div",{style:qb,children:[t.jsx("button",{onClick:()=>y("list"),style:gr(x==="list"),children:m("lineage.modeList")}),t.jsx("button",{onClick:()=>y("graph"),style:gr(x==="graph"),children:m("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:m("lineage.collectionLabel")}),S.map(([k,$])=>{const C=p==null?void 0:p[k];return t.jsxs("button",{onClick:()=>d==null?void 0:d(k),style:gr(l===k),title:$.description?f($.description):void 0,children:[f($.label),C!=null?` ${C}`:""]},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(gd,{graph:e,renderLink:i}):t.jsx(fd,{graph:e,renderLink:i,height:o,selectedNodeId:s})]})},qb={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},gr=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"}),Ua=40,Va=2,Kb=9,Xb=new Set(["certain","consensus","probable","disputed"]);function fr(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const xd=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:h})=>{var _e,ze,F,fe,oe,we,Ae,He,Ge,Ye,Xe;const u=Ee(),{t:m,convert:f}=ne(),[x,v]=g.useState(null),[y,S]=g.useState(new Map),[b,w]=g.useState([]),[j,k]=g.useState(new Map),[$,C]=g.useState(!1),[_,L]=g.useState("flow"),[z,T]=g.useState(null);g.useEffect(()=>{if(!n||!e.work_id){v(null);return}let I=!1;return n.getItem(e.work_id).then(V=>{!I&&V&&V.type==="work"&&v(V)}).catch(()=>{}),()=>{I=!0}},[n,e.work_id]),g.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){T(null);return}let I=!1;return n.getLineageGraph(e.work_id).then(V=>{I||T(V&&V.nodes.length>1?V:null)}).catch(()=>{I||T(null)}),()=>{I=!0}},[n,e.work_id]),g.useEffect(()=>{const I=e._collections||[];if(!n||I.length===0){S(new Map);return}let V=!1;return Promise.all(I.map(ue=>{const $e=ue.id;return n.getItem($e).then(ye=>[$e,ye]).catch(()=>[$e,null])})).then(ue=>{if(V)return;const $e=new Map;for(const[ye,he]of ue)he&&$e.set(ye,he);S($e)}),()=>{V=!0}},[n,e._collections]);const M=g.useMemo(()=>{const I=new Set([...x?po(x):[],...e.related_books||[]]);return I.add(e.id),[...I]},[x,e.related_books,e.id]),P=M.length-1;g.useEffect(()=>{if(!n||P<=0){w([]);return}const I=M.length<=Ua,V=I?M:M.slice(0,8);let ue=!1;return Promise.all(V.map($e=>$e===e.id?Promise.resolve({id:$e,title:e.title,edition:e.edition,year:xi(e)}):n.getItem($e).then(ye=>{const he=ye??{};return{id:$e,title:he.title,edition:he.edition,year:ye?xi(he):void 0}}).catch(()=>({id:$e})))).then($e=>{if(ue)return;const ye=$e.filter(he=>he.id===e.id||he.title||he.edition);I&&ye.sort((he,Ve)=>(he.year??1/0)-(Ve.year??1/0)),w(ye)}),()=>{ue=!0}},[n,M,P,e]);const N=e.lineage,A=g.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]);g.useEffect(()=>{if(!n||A.length===0){k(new Map);return}let I=!1;return Promise.all(A.map(V=>n.getItem(V).then(ue=>[V,{id:V,title:ue==null?void 0:ue.title,edition:ue==null?void 0:ue.edition}]).catch(()=>[V,{id:V}]))).then(V=>{I||k(new Map(V))}),()=>{I=!0}},[n,A]);const W=g.useMemo(()=>dd(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),G=W.groups.reduce((I,V)=>I+V.rows.length+V.mirrors.length,0),X=W.groups.length>0&&W.groups.every(I=>I.key==="_physical"),le=Wn(e),U=nc(e),D=Bt(e,u.unit.juan),xe=new Set((e._collections||[]).map(I=>Ln(I.vol).length).filter(I=>I>0)),Y=I=>{var $e;const V=($e=e.base_edition)==null?void 0:$e.find(ye=>ye.book_id===I&&ye.name);if(V!=null&&V.name)return V.name;const ue=j.get(I);return(ue==null?void 0:ue.edition)||(ue==null?void 0:ue.title)||""},E=g.useMemo(()=>{var ve,Me,Oe,Ie,ge;const I=[];U&&I.push({label:m("bookPage.fact.editionType"),value:f(U),title:e.edition_type||(ve=e.lineage)!=null&&ve.category?void 0:m("bookPage.inferredFromEdition")}),(Me=e.publication_info)!=null&&Me.details?I.push({label:m("bookPage.fact.publication"),value:f(e.publication_info.details)}):(le.era||le.reign)&&I.push({label:m("bookPage.fact.era"),value:f([le.era,le.reign].filter(Boolean).join(" ")),title:le.source==="edition"?m("bookPage.inferredFromEdition"):void 0}),D&&I.push({label:m("bookPage.fact.measure"),value:f(D)});const V=(e._collections||[]).flatMap(Ce=>Ln(Ce.vol));V.length&&I.push({label:m("bookPage.fact.volumes"),value:m("bookPage.volumesValue",{range:Ri(V,u.unit.volume),unit:u.unit.volume,n:V.length})});const ue=(((Oe=e.lineage)==null?void 0:Oe.derived_from)||[]).find(Ce=>Ce.relation==="底本"&&Ce.ref_type==="book");ue&&Y(ue.ref)&&I.push({label:m("bookPage.fact.baseEdition"),value:t.jsx(et,{id:ue.ref,label:f(Y(ue.ref)),onNavigate:i,renderLink:o,dense:!0})});const $e=(e.base_edition||[]).filter(Ce=>Ce&&Ce.name);for(const Ce of["底本","配補","參校"]){if(Ce==="底本"&&ue&&Y(ue.ref))continue;const De=$e.filter(Pe=>Pe.role===Ce);De.length&&I.push({label:f(Ce),value:De.map((Pe,yt)=>t.jsxs(g.Fragment,{children:[yt>0&&"、",Pe.book_id?t.jsx(et,{id:Pe.book_id,label:f(Pe.name),onNavigate:i,renderLink:o,dense:!0}):f(Pe.name)]},yt))})}const ye=(e.provenance||[]).filter(Ce=>Ce&&Ce.institution),he=(e.resources||[]).filter(Ce=>Mt(Ce).includes("physical"));if(ye.length){I.push({label:m("bookPage.fact.holdings"),value:ye.slice(0,2).map(Pe=>f(Pe.institution)).join("、")+(ye.length>2?m("bookPage.andMorePlaces",{n:ye.length}):"")});const Ce=ye.filter(Pe=>Pe.call_number).slice(0,2).map(Pe=>`${f(Pe.institution)} ${Pe.call_number}`);Ce.length&&I.push({label:m("bookPage.fact.callNumber"),value:Ce.join(";")+(ye.filter(Pe=>Pe.call_number).length>2?"…":"")});const De=ye.flatMap(Pe=>Pe.seals||[]).filter(Boolean);De.length&&I.push({label:m("bookPage.fact.seals"),value:f(De.join("、"))})}else he.length?I.push({label:m("bookPage.fact.holdings"),value:he.slice(0,2).map(Ce=>f(Ce.name)).join("、")+(he.length>2?m("bookPage.andMorePlaces",{n:he.length}):"")}):(Ie=e.current_location)!=null&&Ie.name&&I.push({label:m("bookPage.fact.holdings"),value:f(e.current_location.name)});const Ve=e.physical_description;if(Ve){const Ce=[[m("bookPage.fact.leafStyle"),Ve.leaf_style],[m("bookPage.fact.binding"),Ve.binding],[m("bookPage.fact.dimensions"),Ve.dimensions],[m("bookPage.fact.condition"),Ve.condition]];for(const[De,Pe]of Ce)Pe&&Pe.trim()&&I.push({label:De,value:f(Pe)})}(ge=e.page_count)!=null&&ge.description&&I.push({label:u.label.pageCount,value:f(e.page_count.description)});const te=[...Rr(e.additional_titles),...Rr(e.attached_texts)];return te.length&&I.push({label:m("bookPage.fact.aliases"),value:te.map(f).join("、")}),I},[e,f,u,m,le,U,D,j,i,o]),Te=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:m("bookPage.kind"),title:Te,subtitle:ce,byline:t.jsx(Fo,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:i,renderLink:o}),meta:(()=>{const I=[U?f(U):"",le.era?f([le.era,le.reign].filter(Boolean).join("")):"",D?f(D):""].filter(Boolean);return I.length?t.jsx("span",{className:"bim-d-tags",children:I.map((V,ue)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ue,2)}`,children:V},ue))}):null})(),description:(ze=e.description)!=null&&ze.text?t.jsx(Pt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:go((F=e.description)==null?void 0:F.text)?6:void 0,facts:E,readAction:s,secondaryAction:s&&G>0&&!X?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:m("bookPage.viewImages")}):void 0,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),We=e._collections||[],J=(a==null?void 0:a.chapters)||[],re=f(J[0]&&fr(J[0].title)[0].slice(-1)||"")||m("bookPage.chapterUnit"),de=m("bookPage.chapterCount",{n:J.length,unit:re}),H=!!((fe=N==null?void 0:N.derived_from)!=null&&fe.length||(oe=N==null?void 0:N.related_to)!=null&&oe.length||(we=e.appendix)!=null&&we.length),Z=[],ke=m(X?"bookPage.sec.physical":"bookPage.sec.images");(J.length||W.text.length||l)&&Z.push({id:"fulltext",label:m("bookPage.sec.fulltext"),count:J.length?de:void 0}),W.groups.length&&Z.push({id:"images",label:ke,count:G}),H&&Z.push({id:"lineage",label:m("bookPage.sec.lineage")}),We.length&&Z.push({id:"collections",label:m("section.containedIn"),count:We.length}),(Ae=e.location_history)!=null&&Ae.length&&Z.push({id:"provenance",label:m("section.locationHistory")});const ie=I=>(d==null?void 0:d(I))??null,B=J[0],Q=B?ie(B.file):null,ae=$?J:J.slice(0,Kb),je=(I,V,ue)=>I?t.jsx("a",{className:ue,href:I.href??"#",onClick:I.onClick?$e=>{$e.metaKey||$e.ctrlKey||($e.preventDefault(),I.onClick())}:void 0,children:V}):t.jsx("span",{className:ue,children:V}),q=t.jsxs(t.Fragment,{children:[(J.length>0||W.text.length>0||l)&&t.jsxs(rt,{id:"fulltext",title:m("bookPage.sec.fulltext"),meta:J.length>0?t.jsx(it,{items:[de,(He=a==null?void 0:a.source)!=null&&He.name?m("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:m("bookPage.readFrom",{ch:f(fr(B.title)[0])||m("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((B.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),je(Q,t.jsxs(t.Fragment,{children:[m("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),J.length>1&&t.jsx("ul",{className:"bim-d-chap",children:ae.map(I=>{const[V,ue]=fr(I.title);return t.jsx("li",{children:je(ie(I.file),t.jsxs(t.Fragment,{children:[V&&t.jsx("b",{children:f(V)}),f(ue||I.file)]}))},I.file)})}),J.length>ae.length&&t.jsx(ho,{label:m("detail.expandRest",{n:J.length-ae.length,unit:re}),onClick:()=>C(!0)}),W.text.length>0&&t.jsxs(t.Fragment,{children:[(J.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:m("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:W.text.map((I,V)=>t.jsx(Ho,{item:I,siblings:W.text,listedVolumeCounts:xe},`${I.id||I.url||I.name}-${V}`))})})]})]}),W.groups.length>0&&t.jsx(rt,{id:"images",title:ke,meta:t.jsx(it,{items:[W.groups.length>1?m("bookPage.groupCount",{n:W.groups.length}):"",m("bookPage.placeCount",{n:G})]}),children:t.jsx(ud,{groups:W.groups,listedVolumeCounts:xe})}),H&&t.jsx(rt,{id:"lineage",title:m("bookPage.sec.lineage"),meta:(Ge=N==null?void 0:N.derived_from)!=null&&Ge.length?m("bookPage.lineageMeta"):void 0,action:z?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":m("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":_==="flow",onClick:()=>L("flow"),children:m("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":_==="graph",onClick:()=>L("graph"),children:m("bookPage.viewGraph")})]}):void 0,children:_==="graph"&&z?t.jsx(Do,{graph:z,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(I,V)=>t.jsx(et,{id:I,label:f(V),onNavigate:i,renderLink:o,dense:!0})}):t.jsx(Jb,{data:e,heading:ce||Te,yearText:me,refName:Y,onNavigate:i,renderLink:o})}),We.length>0&&t.jsx(rt,{id:"collections",title:m("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:We.map((I,V)=>{const ue=I.id,$e=Ln(I.vol),ye=y.get(ue),he=ph(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}),$e.length>0&&t.jsx(Zb,{volumes:$e,unit:u.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${he?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:he>0&&m("bookPage.totalOf",{n:he,unit:u.unit.bu})})]},`${ue}-${V}`)})})})}),(Ye=e.location_history)!=null&&Ye.length?t.jsx(rt,{id:"provenance",title:m("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((I,V)=>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):""]})})]},V))})}):null,Z.length===0&&t.jsx(rt,{title:m("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("bookPage.emptyText")})})]}),be=b.findIndex(I=>I.id===e.id),Le=M.length<=Ua,Fe=Le&&be>=0?b.slice(Math.max(0,be-Va),be+Va+1):b.filter(I=>I.id!==e.id),O=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?m("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,""))})]}),P>0&&Fe.length>0&&t.jsxs("div",{children:[t.jsx(en,{id:"siblings",timeline:!0,title:Le?m("bookPage.siblings"):u.relation.siblingVersions,meta:Le?m("bookPage.byEra"):m("bookPage.kindCount",{n:P}),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?m("detail.bce",{n:-I.year}):String(I.year):"",I.id===e.id?m("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:m("bookPage.viewAllInWork",{n:M.length}),onNavigate:i,renderLink:o,dense:!0})})]})]}),ee=e.work_id?t.jsx(ac,{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:ee,nav:Z,railLinks:h,main:q,card:se,side:O})};function Zb({volumes:e,unit:n}){const{t:i}=ne();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i("bookPage.volumeRange",{range:Ri(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 S;const{t:l,convert:d}=ne(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],h=p.filter(b=>b.ref_type!=="book"),u=p.filter(b=>b.ref_type==="book"&&b.relation==="底本"),m=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:[h.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)})]}),m.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:m.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))})]})]}),(S=e.appendix)==null?void 0:S.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,bd=({data:e,catalog:n,transport:i,onNavigate:o,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var be,Le,Fe,O,ee,_e,ze;const{t:p,convert:h,messages:u}=ne(),[m,f]=g.useState(""),[x,v]=g.useState(!1),[y,S]=g.useState(null),[b,w]=g.useState(""),[j,k]=g.useState(!1),$=g.useMemo(()=>ec(e,n),[e,n]),C=g.useMemo(()=>Ql(e),[e]),[_,L]=g.useState(new Map),z=!!i&&$.rows.length>0&&$.rows.length<=Qb,T=z&&($.rows.length<=Nn||j),M=T&&$.rows.every(F=>!F.id||_.has(F.id)),P=F=>{var fe;return Fr(F?(fe=_.get(F))==null?void 0:fe.l1:void 0)},N=g.useMemo(()=>{const F=m.trim(),fe=F?h(F):"";return $.rows.filter(oe=>{var Ae,He;if(b&&Fr(oe.id?(Ae=_.get(oe.id))==null?void 0:Ae.l1:void 0)!==b)return!1;if(!fe)return!0;const we=oe.id&&((He=_.get(oe.id))==null?void 0:He.title)||oe.title;return h(we).includes(fe)||(oe.subItems||[]).some(Ge=>h(Ge).includes(fe))})},[$.rows,m,b,_,h]),A=x?N:N.slice(0,Nn),W=g.useMemo(()=>(T?$.rows:A).filter(F=>F.id&&!_.has(F.id)).map(F=>F.id),[T,$.rows,A,_]);g.useEffect(()=>{if(!i||W.length===0)return;let F=!1;const fe=W.slice(0,ey);return Pi(fe,Mi,oe=>i.getItem(oe).then(we=>{var Ge,Ye;const Ae=we??{},He={title:Ae.title,edition:Ae.edition,authors:Ae.authors,measure:we?Bt(we,u.unit.juan):void 0,versionCount:Ae._edition_count??((Ge=Ae._books)==null?void 0:Ge.length),l1:((Ye=uo(Ae))==null?void 0:Ye.l1)||void 0};return[oe,He]}).catch(()=>[oe,{}]),()=>F).then(oe=>{F||L(we=>{const Ae=new Map(we);for(const[He,Ge]of oe)Ae.set(He,Ge);return Ae})}),()=>{F=!0}},[i,W,u.unit.juan]);const G=(be=(e.contained_in||[])[0])==null?void 0:be.id;g.useEffect(()=>{if(!G){S(null);return}if(S({id:G}),!i)return;let F=!1;return i.getItem(G).then(fe=>{F||S({id:G,title:fe==null?void 0:fe.title})}).catch(()=>{}),()=>{F=!0}},[i,G]);const X=g.useMemo(()=>dd(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),le=X.text.length+X.groups.reduce((F,fe)=>F+fe.rows.length+fe.mirrors.length,0),U=C.works,D=new Set($.rows.map(F=>F.id).filter(Boolean)),xe=U.length>0&&!U.every(F=>D.has(F.id)),Y=(()=>{const F=$.rows.map(fe=>fe.edition).filter(Boolean);return F.length>1&&new Set(F).size===1})(),E=$.rows.some(F=>F.volumes.length>0||F.expected!=null),Te=C.total,ce=C.truncated?Te:$.rows.length,me=Bt(e,u.unit.juan),se=e.count,We=F=>typeof F=="number"&&Number.isFinite(F)?F:null,J=We(se==null?void 0:se.juan)??We((Le=e.juan_count)==null?void 0:Le.number),re=We(se==null?void 0:se.ce)??($.totalVolumes||null),de=[{value:ce,label:p("collectionPage.stat.titles")},{value:J??0,label:u.unit.juan},{value:re??0,label:u.unit.volume}],H=g.useMemo(()=>{var oe,we;const F=[];if((oe=e.publication_info)!=null&&oe.details&&F.push({label:p("collectionPage.fact.publication"),value:h(e.publication_info.details)}),Te&&(Te!==$.rows.length||C.truncated)){const Ae=e._member_type==="Book"?p("collectionPage.member.Book"):e._member_type==="Work"?p("collectionPage.member.Work"):p("collectionPage.member.other");F.push({label:Ae,value:`${Te} ${u.unit.bu}`,title:p("collectionPage.memberNote")})}const fe=[We(se==null?void 0:se.zhong)!=null?p("collectionPage.nZhong",{n:se.zhong}):"",We(se==null?void 0:se.han)!=null?p("collectionPage.nHan",{n:se.han}):""].filter(Boolean);return fe.length&&F.push({label:p("collectionPage.fact.expected"),value:fe.join(" ")}),J==null&&me&&F.push({label:p("collectionPage.fact.measure"),value:h(me),title:(we=e.juan_count)!=null&&we.description?h(e.juan_count.description):void 0}),F},[e,Te,C.truncated,$.rows.length,J,me,se,h,p,u]),Z=g.useMemo(()=>{if(!M)return[];const F=new Map;for(const oe of $.rows){const we=P(oe.id);we&&F.set(we,(F.get(we)??0)+1)}const fe=Mn.filter(oe=>(F.get(oe.key)??0)>0);return fe.length<2?[]:[{key:"",label:`${u.catalog.all} ${ce}`},...fe.map(oe=>({key:oe.key,label:`${oe.label} ${F.get(oe.key)}`}))]},[M,$.rows,_,u]),ke=g.useMemo(()=>{if(!M||!$.rows.some(we=>we.volumes.length>0))return null;const F=[],fe=$.rows.filter(we=>we.volumes.length>0).map(we=>({k:P(we.id)??"",from:Math.min(...we.volumes),to:Math.max(...we.volumes)})).sort((we,Ae)=>we.from-Ae.from);for(const we of fe){const Ae=we.to-we.from+1,He=F[F.length-1];He&&He.key===we.k?(He.to=Math.max(He.to,we.to),He.n+=Ae):F.push({key:we.k,from:we.from,to:we.to,n:Ae})}const oe=fe.reduce((we,Ae)=>Math.max(we,Ae.to),0);return F.length>1&&F.some(we=>we.key)?{segs:F,last:oe}:null},[M,$.rows,_]),ie=(Fe=e.description)==null?void 0:Fe.text,B=t.jsx(Fn,{kind:p("collectionPage.kind"),title:h(e.title),byline:t.jsx(Fo,{authors:e.authors,onNavigate:o,renderLink:s}),meta:t.jsx(it,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(O=e.publication_info)!=null&&O.year?h(e.publication_info.year):""]}),description:ie||(ee=e.history)!=null&&ee.length?t.jsxs(t.Fragment,{children:[ie&&t.jsx(Pt,{text:ie,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((F,fe)=>t.jsx("li",{children:h(F)},fe))}):null]}):void 0,clampDescription:go(ie)||(((ze=e.history)==null?void 0:ze.length)??0)>2?6:void 0,stats:de,facts:H,foot:t.jsx(Hn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ke&&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:ke.segs.map((F,fe)=>{const oe=Mn.find(we=>we.key===F.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!oe,title:oe?p("collectionPage.dist.segTitle",{section:h(oe.label),from:F.from,to:F.to}):void 0,"aria-label":oe?p("collectionPage.dist.only",{section:h(oe.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!oe&&b===F.key,style:{flexGrow:F.n,background:r(oe?oe.token:"rule")},onClick:()=>{oe&&(w(b===F.key?"":F.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:ke.last})})]})]})}),Q=[];$.rows.length&&Q.push({id:"titles",label:p("collectionPage.sec.titles"),count:ce}),le&&Q.push({id:"resources",label:p("collectionPage.sec.resources"),count:le}),xe&&Q.push({id:"works",label:u.section.containedWorks,count:U.length});const ae=t.jsxs(t.Fragment,{children:[$.rows.length>0&&t.jsxs(rt,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(it,{items:[`${ce} ${u.unit.items}`,$.totalVolumes?p("collectionPage.totalVolumes",{n:$.totalVolumes,unit:u.unit.volume}):"",N.length!==ce?p("collectionPage.currentN",{n:N.length,unit:u.unit.items}):""]}),action:a,children:[($.rows.length>Nn||Z.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Z.length>0&&t.jsx(Ei,{items:Z,value:b,onChange:F=>{w(F),v(!1)}}),z&&$.rows.length>Nn&&!M&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:j,onClick:()=>k(!0),title:p("collectionPage.loadAllTitle",{n:$.rows.length,unit:u.unit.items}),children:p(j?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),$.rows.length>Nn&&t.jsx("input",{type:"search",className:"bim-d-find",value:m,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:F=>{f(F.target.value),v(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Li(N.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[E&&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((F,fe)=>{var Xe;const oe=F.id?_.get(F.id):void 0,we=oe!=null&&oe.title&&F.title===F.id?oe.title:F.title,Ae=((oe==null?void 0:oe.authors)||[]).find(I=>I&&I.name),He=[Ae?`${Ae.dynasty?`〔${h(Ae.dynasty)}〕`:""}${h(Ae.name)}${Ae.role?` ${h(Ae.role)}`:""}`:"",oe!=null&&oe.measure?h(oe.measure):"",(Xe=F.subItems)!=null&&Xe.length?F.subItems.map(I=>h(I)).join("、"):"",(oe!=null&&oe.edition||F.edition)&&!Y?h((oe==null?void 0:oe.edition)||F.edition||""):""].filter(Boolean),Ge=Mn.find(I=>I.key===P(F.id)),Ye=F.volumes.length>0?p("collectionPage.volumeRange",{range:Ri(F.volumes,u.unit.volume),unit:u.unit.volume}):F.expected!=null?`${F.found??0}/${F.expected} ${u.unit.volume}`:"";return t.jsxs("tr",{children:[E&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ye?"":" bim-d-zt-blank"}`,children:[Ge&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r(Ge.token)}}),Ye||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[F.id?t.jsx(et,{id:F.id,label:h(we),onNavigate:o,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:h(we)}),He.length>0?t.jsx(it,{items:He}):F.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}):""})]},`${F.id??F.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(mo,{total:N.length,shown:A.length,unit:u.unit.items,onClick:()=>v(!0)})]}),le>0&&t.jsxs(rt,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:le}),children:[X.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[X.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:p("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:X.text.map((F,fe)=>t.jsx(Ho,{item:F,siblings:X.text},`${F.id||F.url||F.name}-${fe}`))})})]}),t.jsx(ud,{groups:X.groups})]}),$.rows.length===0&&le===0&&t.jsx(rt,{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:U.length}),cap:12,items:U.map(F=>t.jsx(et,{id:F.id,label:h(F.title),onNavigate:o,renderLink:s,dense:!0}))}):null,q=y?t.jsx(ac,{caption:p("collectionPage.parent"),children:t.jsx(et,{id:y.id,label:h(y.title||y.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return t.jsx(On,{railTop:l,back:d,up:q,nav:Q,railLinks:c,main:ae,card:B,side:je})},ty=16,xr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Ga(e){if(!e)return xr.length;const n=xr.indexOf(e);return n===-1?xr.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]},yd=({data:e,transport:n,onNavigate:i,renderLink:o,railTop:s,back:a,railLinks:l})=>{var je,q,be,Le,Fe;const{t:d,convert:c,messages:p}=ne(),h=O=>iy(O,d),[u,m]=g.useState("全部"),[f,x]=g.useState(!1),[v,y]=g.useState("default"),[S,b]=g.useState(new Map),w=g.useMemo(()=>e._works||[],[e._works]),j=g.useMemo(()=>w.map(O=>{const ee=S.get(O.work_id);return{id:O.work_id,title:(ee==null?void 0:ee.title)??O.title??O.work_id,role:O.role||"",cls:lo(O.role),versionCount:ee==null?void 0:ee.versionCount,section:ee==null?void 0:ee.cls,l1:ee==null?void 0:ee.l1,measure:ee==null?void 0:ee.measure,hasImage:ee==null?void 0:ee.hasImage,loaded:!!(ee!=null&&ee.loaded)}}),[w,S]),k=g.useMemo(()=>Jl(w.map(O=>O.role),d("detail.roleAll")),[w,d]),$=g.useMemo(()=>{const O=u==="全部"?j:j.filter(ee=>ee.cls===u);return v==="versions"?[...O].sort((ee,_e)=>(_e.versionCount??-1)-(ee.versionCount??-1)):O},[j,u,v]),C=f?$:$.slice(0,ty),_=g.useMemo(()=>C.filter(O=>!S.has(O.id)).map(O=>O.id),[C,S]);g.useEffect(()=>{if(!n||_.length===0)return;let O=!1;return Pi(_,Mi,ee=>n.getItem(ee).then(_e=>{var we;const ze=_e??{},F=ze._edition_count??((we=ze._books)==null?void 0:we.length)??0,fe=uo(ze),oe=[fe==null?void 0:fe.l1,fe==null?void 0:fe.l2].filter(Boolean).join(" ");return[ee,{id:ee,title:ze.title,versionCount:F,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:!!ze._has_image}]}).catch(()=>[ee,{id:ee,loaded:!0}]),()=>O).then(ee=>{O||b(_e=>{const ze=new Map(_e);for(const[F,fe]of ee)ze.set(F,fe);return ze})}),()=>{O=!0}},[n,_,p.unit.juan]);const L=g.useMemo(()=>{const O=new Map;for(const ee of e.alt_names||[]){const _e=ee.type||p.section.aliases;O.has(_e)||O.set(_e,[]),O.get(_e).push(ee.name)}return[...O.entries()].sort((ee,_e)=>Ga(ee[0])-Ga(_e[0])).map(([ee,_e])=>({label:ee,names:_e}))},[e.alt_names,p]),z=e.birth_year??((je=e.dates)==null?void 0:je.birth)??void 0,T=e.death_year??((q=e.dates)==null?void 0:q.death)??void 0,M=(be=e.dates)==null?void 0:be.floruit,P=z!=null||T!=null?`${h(z)||"?"}—${h(T)||"?"}`:Array.isArray(M)&&M.length===2&&M.every(O=>Number.isFinite(O))?d("entityPage.floruit",{from:h(M[0]),to:h(M[1])}):"",N=new Set(["本名","字","號","号"]),A=L.filter(O=>N.has(O.label)),W=L.filter(O=>!N.has(O.label)),G=W.reduce((O,ee)=>O+ee.names.length,0),X=g.useMemo(()=>{const O=[];for(const _e of A)O.push({label:_e.label,value:_e.names.map(ze=>c(ze)).join("、")});const ee=w.length;return ee&&O.push({label:d("entityPage.fact.works"),value:d("entityPage.nZhong",{n:ee})}),O},[w,A,c,d]),le=O=>{var ee;return(ee=L.find(_e=>O.includes(_e.label)))==null?void 0:ee.names[0]},U=le(["字"]),D=le(["號","号"]),xe=[U?d("entityPage.zi",{name:c(U)}):"",D?d("entityPage.hao",{name:c(D)}):""].filter(Boolean).join(","),Y=e.native_place,E=e.dynasty?ry[e.dynasty]:void 0,Te=(()=>{if(!E||z==null||T==null||T<z)return null;const[O,ee]=E,_e=Math.max(z,O),ze=Math.min(T,ee);if(ze<=_e)return null;const F=ee-O;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:h(z),death:h(T),years:T-z+1}),children:t.jsx("i",{style:{left:`${(_e-O)/F*100}%`,width:`${(ze-_e)/F*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${h(O)} ${c(e.dynasty)}`}),t.jsx("span",{children:d("entityPage.lifeYears",{years:T-z+1})}),t.jsx("span",{children:h(ee)})]})]})})(),ce=g.useMemo(()=>{if(!n||j.length===0||j.some(_e=>!_e.loaded))return null;const O=new Map;for(const _e of j){const ze=Fr(_e.l1);ze&&O.set(ze,(O.get(ze)??0)+1)}const ee=Mn.map(_e=>({..._e,n:O.get(_e.key)??0})).filter(_e=>_e.n>0);return ee.length?ee: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):"",P,Y?d("entityPage.nativePlace",{place:c(Y)}):""]}),Te]}),description:(Le=e.description)!=null&&Le.text?t.jsx(Pt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:go((Fe=e.description)==null?void 0:Fe.text)?6:void 0,facts:X,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:W.map(O=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:c(O.label)}),t.jsx("dd",{children:O.names.map(ee=>c(ee)).join("、")})]},O.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(O=>t.jsx("i",{style:{flexGrow:O.n,background:r(O.token)}},O.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ce.map(O=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r(O.token)}}),c(O.label)," ",O.n]},O.key))})]})]}),se=g.useMemo(()=>j.filter(O=>O.loaded&&(O.versionCount??0)>0).sort((O,ee)=>(ee.versionCount??0)-(O.versionCount??0)).slice(0,3),[j]),We=!!n&&j.length>=3&&C.some(O=>!O.loaded),J=u==="全部"&&(We||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 H=re.wikidata_id;H&&de.push({label:"Wikidata",id:H,href:`https://www.wikidata.org/wiki/${H}`});const Z=re.viaf_id;Z&&de.push({label:"VIAF",id:Z,href:`https://viaf.org/viaf/${Z}`});const ke=k.map(O=>({key:O.cls,label:`${O.label} ${O.count}`})),ie=[...J&&!We?[{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=J?t.jsxs(rt,{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":We||void 0,children:[We&&[0,1,2].map(O=>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:" "})]},O)),!We&&se.map(O=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(et,{id:O.id,label:c(O.title),onNavigate:i,renderLink:o,dense:!0})}),t.jsx(it,{items:[O.section?c(O.section):"",O.measure?c(O.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:O.versionCount}),t.jsx("span",{children:d("entityPage.versionsUnit")}),O.hasImage&&t.jsx("span",{className:"bim-d-flag",children:d("entityPage.hasImage")})]})]},O.id))]})]}):null,Q=j.length===0?t.jsx(rt,{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(rt,{id:"works",title:d("entityPage.sec.works"),meta:t.jsx(it,{items:[d("entityPage.total",{n:j.length}),$.length!==j.length?d("entityPage.current",{n:$.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[ke.length>1&&t.jsx(Ei,{items:ke,value:u,onChange:O=>{m(O),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(O=>O==="default"?"versions":"default")},children:d(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!f&&Li($.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:C.map(O=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(et,{id:O.id,label:c(O.title),onNavigate:i,renderLink:o,dense:!0}),O.measure?t.jsx(it,{items:[c(O.measure)]}):!O.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${O.section||O.loaded?"":" bim-d-zt-blank"}`,children:O.section?c(O.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${O.role?"":" bim-d-zt-blank"}`,children:O.role?c(O.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${O.loaded?"":" bim-d-zt-blank"}`,children:O.loaded?O.versionCount?d("entityPage.nZhong",{n:O.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:d("entityPage.notRecorded")}):""}),t.jsx("td",{className:O.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:O.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:d("entityPage.hasImage")})})]},O.id))})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d("entityPage.emptyRole")}),!f&&t.jsx(mo,{total:$.length,shown:C.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(O=>t.jsxs("a",{href:O.href,target:"_blank",rel:"noopener noreferrer",children:[O.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:de.map(O=>O.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:ie,railLinks:l,main:Q,card:me,side:ae})},Uo="(max-width: 719px)",oy=`${Uo}, (pointer: coarse)`,jd=`
1354
1354
  .bim-ct {
1355
1355
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
1356
1356
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -1458,7 +1458,7 @@ ${B??""}`,[Gi,es]=h.useState({key:Gn,data:U,started:!!U});if(Gi.key!==Gn)es({key
1458
1458
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1459
1459
  }
1460
1460
 
1461
- @media ${Vo} {
1461
+ @media ${Uo} {
1462
1462
  .bim-ct { display: block; padding: 12px 16px 40px; }
1463
1463
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
1464
1464
  .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
@@ -1509,7 +1509,7 @@ ${B??""}`,[Gi,es]=h.useState({key:Gn,data:U,started:!!U});if(Gi.key!==Gn)es({key
1509
1509
  /* 窄屏分类抽屉:界栏下按钮和面板都有框 */
1510
1510
  :root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${r("fr-bd")}; background: ${r("fr-bg")}; }
1511
1511
  :root[data-layout="boxed"] .bim-ct-drawer { border: ${r("fr-bd")}; }
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=`
1512
+ `,Qt="未分類",Lt="all",Vo=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(h=>!!h);p.forEach((h,u)=>{const m=p.slice(0,u+1).join("/");i.has(m)||i.set(m,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((h,u)=>{const m=c.slice(0,u+1).join("/");let f=p.get(h);f||(f={id:m,label:h,count:0,children:new Map},p.set(h,f)),f.count++,p=f.children})}const a=d=>[...d.values()].sort((c,p)=>{const h=c.label===Qt?1:0,u=p.label===Qt?1:0;if(h!==u)return h-u;const m=i.get(c.id)??1/0,f=i.get(p.id)??1/0;return m!==f?m-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 Go(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=Vo){return Math.max(1,Math.ceil(e/n))}function vd(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 hy(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 kd({tree:e,selectedId:n,onSelect:i,allLabel:o,label:s}){const{t:a,convert:l}=ne(),d=o===void 0?a("catalogPage.all"):o,c=s??a("catalogPage.classification"),p=g.useRef(null),h=n&&n!==Lt?n:null,u=d!==null,[m,f]=g.useState(()=>{const _=new Set;for(const L of pn(e,h))_.add(L.id);return _});g.useEffect(()=>{const _=pn(e,h);_.length&&f(L=>{if(_.every(T=>L.has(T.id)))return L;const z=new Set(L);for(const T of _)z.add(T.id);return z})},[e,h]);const x=g.useMemo(()=>hy(e,m,u),[e,m,u]),[v,y]=g.useState(null);g.useEffect(()=>{y(null)},[n]);const S=h??(u?Lt:null),b=g.useMemo(()=>{var z;const _=new Set(x.map(T=>T.id));if(v&&_.has(v))return v;if(S&&_.has(S))return S;const L=pn(e,h).map(T=>T.id).filter(T=>_.has(T));return L.length?L[L.length-1]:((z=x[0])==null?void 0:z.id)??null},[x,v,S,e,h]),w=g.useCallback((_,L)=>{f(z=>{const T=z.has(_),M=L??!T;if(M===T)return z;const P=new Set(z);return M?P.add(_):P.delete(_),P})},[]),j=g.useCallback(_=>{y(_),requestAnimationFrame(()=>{var z;const L=Array.from(((z=p.current)==null?void 0:z.querySelectorAll("[data-ct-id]"))??[]).find(T=>T.dataset.ctId===_);L==null||L.focus()})},[]),k=g.useCallback((_,L)=>{L&&w(_,!0),i(_)},[i,w]),$=g.useCallback(_=>{const L=_.target.closest("[data-ct-id]");if(!L)return;const z=L.dataset.ctId,T=x.findIndex(N=>N.id===z);if(T<0)return;const M=x[T];let P=null;switch(_.key){case"ArrowDown":P=x[Math.min(x.length-1,T+1)].id;break;case"ArrowUp":P=x[Math.max(0,T-1)].id;break;case"Home":P=x[0].id;break;case"End":P=x[x.length-1].id;break;case"ArrowRight":if(!M.hasChildren)break;m.has(z)?P=M.firstChildId:w(z,!0);break;case"ArrowLeft":M.hasChildren&&m.has(z)?w(z,!1):P=M.parentId;break;case"Enter":case" ":_.preventDefault(),k(z,M.hasChildren);return;default:return}_.preventDefault(),P&&P!==z&&j(P)},[x,m,w,j,k]),C=(_,L)=>_.map((z,T)=>{var W;const M=(W=z.children)!=null&&W.length?z.children:null,P=!!M&&m.has(z.id),N=z.id===h,A=L===1&&_.length>1&&T===_.length-1;return t.jsxs("li",{role:"treeitem","aria-level":L,"aria-expanded":M?P: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":L-1},onClick:()=>{y(z.id),k(z.id,!!M)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:M?G=>{G.stopPropagation(),y(z.id),w(z.id)}:void 0,children:M?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")})]}),P&&t.jsx("ul",{role:"group",children:C(M,L+1)})]},z.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:$,children:[u&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!h,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:Go(e).toLocaleString("en-US")})]})}),C(e,1)]})}const wd=e=>`/item/${encodeURIComponent(e)}`;function gy(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Sd(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}=ne(),s=Sd(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,h)=>t.jsxs(g.Fragment,{children:[h>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},h))}),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 $d({work:e,href:n}){var d,c;const{t:i,convert:o}=ne(),s=Sd(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,h)=>t.jsxs(g.Fragment,{children:[h>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},h))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>o(p)).join(" · ")})]})})}function Cd({page:e,pageCount:n,onPage:i,pageHref:o,label:s}){const{t:a,convert:l}=ne();if(n<=1)return null;const d=p=>h=>{i&&(o&&!gy(h)||(h.preventDefault(),i(p)))},c=(p,h,u)=>{if(u.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:h});const m={className:"bim-ct-pg","aria-current":u.current?"page":void 0,"aria-label":u.aria};return o?t.jsx("a",{...m,href:o(p),onClick:d(p),children:h}):t.jsx("button",{type:"button",...m,onClick:u.current?void 0:d(p),children:h})};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:vd(e,n).map((p,h)=>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${h}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=n})]})}function Td({works:e,workLink:n=wd,emptyText:i,view:o="card",...s}){const{t:a,convert:l}=ne();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($d,{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(Cd,{...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:h,allTitle:u,pageSize:m=Vo,className:f,view:x,onViewChange:v}){const{t:y,convert:S}=ne(),b=h===void 0?y("catalogPage.all"):h,w=u??y("catalogPage.allTitle"),k=`bim-ct-drawer-${g.useId().replace(/:/g,"")}`,[$,C]=g.useState(!1),[_,L]=g.useState("card"),z=x??_,T=G=>{L(G),v==null||v(G)},M=pn(e,n&&n!==Lt?n:null),P=M.length?M[M.length-1]:null,N=P?P.label:w,A=P?P.count:Go(e),W=g.useCallback(G=>{C(!1),a(G)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":$?"open":"closed",children:[t.jsx("style",{children:jd}),t.jsxs("aside",{className:"bim-ct-side","aria-label":y("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":$,"aria-controls":k,onClick:()=>C(G=>!G),children:[t.jsx("span",{children:y("catalogPage.drawerLabel",{path:S(M.length?M.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(kd,{tree:e,selectedId:n,onSelect:W,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:S(N)}),M.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:S(M.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:m}),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(Td,{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],Yo=`
1513
1513
  .bim-rh { color: ${r("ink")}; font-family: ${r("font-ui")}; font-size: 14px; line-height: 1.6; }
1514
1514
  .bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
1515
1515
  .bim-rh a { color: ${r("accent")}; text-decoration: none; }
@@ -1739,7 +1739,7 @@ ${jy.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1739
1739
  }
1740
1740
 
1741
1741
  @media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
1742
- `,vy=Zr["zh-Hant"].period,Nd={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function Ut(e){return{...Nd,...e??{}}}function Ko(e){var i;const n=(i=e.authors)==null?void 0:i.find(o=>o==null?void 0:o.name);return n?n.dynasty?`${n.dynasty} ${n.name}`:n.name:""}function Oi(e){return(e.authors??[]).filter(i=>i==null?void 0:i.name).map(i=>i.dynasty?`〔${i.dynasty}〕${i.name}`:i.name).join(" ")}function Id(e,n=Zr["zh-Hant"].shelfOther){var s;const i=[],o=new Map;for(const a of e){const l=((s=a.period_of)==null?void 0:s.trim())||n;let d=o.get(l);d||(d={label:l,items:[]},o.set(l,d),i.push(d)),d.items.push(a)}return i}function Rd(e){return Math.max(150,Array.from(e).length*18+44)}function Ed(e,n){if(n<=0||e<=0)return 0;const i=e/n;return i<.15?0:i<.35?1:i<.6?2:i<.85?3:4}const Ld=.04;function Ke(e){return e.toLocaleString("en-US")}function Ad({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((n,i)=>t.jsx("span",{children:n},i))})}function dt({id:e,title:n,sub:i,more:o,children:s}){const{convert:a}=te(),l=`${e}-h`;return t.jsxs("section",{className:"bim-rh-sec",id:e,"aria-labelledby":l,children:[t.jsxs("div",{className:"bim-rh-hd",children:[t.jsx("h2",{id:l,children:a(n)}),i&&t.jsx("span",{className:"bim-rh-sub",children:i}),o]}),t.jsx("div",{className:"bim-rh-bd",children:s})]})}function Md({counts:e}){const{t:n}=te();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:Ke(e.readable)}),n("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:Ke(e.pieces)}),n("readHome.pieces")]})]})}function Pd({picks:e,links:n}){const{t:i,convert:o}=te(),s=Ut(n);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=Oi(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:s.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(Ad,{text:o(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:o(d)}),t.jsx("h3",{children:o(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:o(l)}),a.blurb&&t.jsx("p",{children:o(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:i("readHome.startReading")})]})]})},a.id)})}):null}function Bd(e,n){return e&&e>1?n("readHome.nCopies",{n:e}):null}function Xo({topic:e,links:n,hint:i,legendCount:o,showTitle:s=!0,legendExtra:a}){const{t:l,convert:d}=te(),c=Ut(n);if(!e.items.length)return null;const p=o===void 0?l("readHome.shelfLegendCount"):o,m=Id(e.items,l("readHome.shelfOther")),u=g=>{const f=g.records?Ke(g.records):Bd(g.text_count,l),x=Ko(g),v=[d(g.title),g.orig?l("readHome.origZhi"):"",x?l("readHome.spineBy",{name:d(x)}):"",g.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(g.id),"data-orig":g.orig?"":void 0,"aria-label":v,title:v,style:{height:Rd(g.title)},children:[t.jsx(Ad,{text:d(g.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":g.records?"":void 0,children:f})]})},g.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[s&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:i?d(i):l("readHome.shelfHint")})]}),t.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":l("readHome.shelfRegion",{label:d(e.label)}),children:t.jsx("ul",{className:"bim-rh-shelf",children:m.map(g=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(g.label),children:g.items.map(u)}),t.jsx("span",{"aria-hidden":"true",children:d(g.label)})]},g.label))})}),t.jsxs("p",{className:"bim-rh-legend",children:[t.jsxs("span",{children:[t.jsx("i",{"data-orig":"","aria-hidden":"true"}),l("readHome.origZhi")]}),t.jsxs("span",{children:[t.jsx("i",{"aria-hidden":"true"}),l("readHome.laterZhi")]}),p&&t.jsx("span",{children:d(p)}),a==null?void 0:a.map(g=>t.jsx("span",{children:d(g)},g))]})]})}const ky=4,Bn=e=>e>ky+1;function Wd({topic:e,links:n}){const{t:i,convert:o}=te(),s=Ut(n),[a,l]=h.useState(!1);if(!e.items.length)return null;const d=`bim-rh-g-${e.key}`;return t.jsxs("div",{className:"bim-rh-grp","data-cap":Bn(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[o(e.label),t.jsx("small",{className:"bim-rh-num",children:i("readHome.nWorks",{n:Ke(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const p=Bd(c.text_count,i),m=Ko(c);return t.jsx("li",{children:t.jsxs("a",{href:s.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:o(c.title)}),p&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:p}),m&&t.jsx("small",{children:o(m)})]})},c.id)})}),Bn(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?i("action.collapse"):i("readHome.allNWorks",{n:e.items.length})})]})}function Od({topics:e,links:n}){const i=e.filter(s=>s.shelf&&s.items.length),o=e.filter(s=>!s.shelf&&s.items.length);return!i.length&&!o.length?null:t.jsxs(t.Fragment,{children:[i.map(s=>t.jsx(Xo,{topic:s,links:n},s.key)),o.length>0&&t.jsx("div",{className:"bim-rh-groups",children:o.map(s=>t.jsx(Wd,{topic:s,links:n},s.key))})]})}function Fd({famous:e,links:n}){const{t:i,convert:o}=te(),s=Ut(n);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:o(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:o(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:i("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?o(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:o(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:s.read(c.id),title:o([c.title,c.edition].filter(Boolean).join(" · ")),children:o(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:s.work(a.work_id),children:i("readHome.workPageLink",{title:o(a.title)})})})]})},a.work_id??a.title))}):null}function Zo({bu:e,unclassified:n,links:i,unclassifiedNote:o}){const{t:s,convert:a}=te(),l=Ut(i);return!e.length&&!n?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var p;const c=((p=d.top[0])==null?void 0:p.count)||1;return t.jsxs("li",{className:"bim-rh-bu-c",children:[t.jsxs("a",{className:"bim-rh-bu-h",href:l.node(d.id),children:[t.jsx("b",{children:a(d.label)}),t.jsx("span",{className:"bim-rh-num",children:s("readHome.nWorks",{n:Ke(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":s("readHome.subClasses",{label:a(d.label)}),children:d.top.map(m=>t.jsx("li",{children:t.jsxs("a",{href:l.node(m.id),children:[t.jsx("span",{children:a(m.label)}),t.jsx("small",{className:"bim-rh-num",children:Ke(m.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(m.count/c*100)}%`}})]})},m.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:s("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!n&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:s("readHome.unclassified")}),t.jsx("span",{children:s("readHome.nWorks",{n:Ke(n)})}),t.jsx("span",{children:o?a(o):s("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:s("readHome.viewUnclassified")})]})]})}function Hd({periods:e,unknown:n,links:i}){const{t:o,convert:s,messages:a}=te(),l=a.readHome.period,d=Ut(i),c=e.filter(u=>u.count>0);if(!c.length)return null;const p=c.reduce((u,g)=>u+g.count,0),m=Math.max(...c.map(u=>u.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(u=>{const g=u.label?s(u.label):l[u.key]??s(u.key),f=u.count/p,x=o("readHome.periodItem",{label:g,n:Ke(u.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(u.key),"data-k":Ed(u.count,m),"data-narrow":f<Ld?"":void 0,"aria-label":x,title:x,children:[t.jsx("span",{className:"bim-rh-pl",children:g}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(g)[0]}),t.jsx("small",{className:"bim-rh-num",children:Ke(u.count)})]})},u.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&t.jsx("span",{children:o("readHome.periodUnknown",{n:Ke(n)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:o("readHome.hoverHint")})]})]})}function Dd({authors:e,links:n}){const{t:i,convert:o}=te(),s=Ut(n);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[o(a.name),a.dynasty&&t.jsx("span",{children:o(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:i("readHome.nPieces",{n:Ke(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:s.read(l.id),children:o(l.title)})},l.id))}),s.author&&t.jsx("a",{className:"bim-rh-more",href:s.author(a.name),children:i("readHome.authorAll",{name:o(a.name),n:a.count})})]},a.name))}):null}const Ud={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function wy({sections:e,links:n,head:i,piecesMoreHref:o,className:s}){const{t:a}=te(),l=e,d=Ud,c=l.topics.filter(g=>!g.shelf),p={picks:l.picks.length>0,topics:c.some(g=>g.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(g=>g.count>0),pieces:l.pieces.authors.length>0},m=Object.keys(d).filter(g=>p[g]),u=g=>a(`readHome.nav.${g}`);return t.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[t.jsx("style",{children:qo}),t.jsxs("div",{className:"bim-rh-head",children:[i,t.jsx(Md,{counts:l.counts})]}),m.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:m.map(g=>t.jsx("li",{children:t.jsx("a",{href:`#${d[g]}`,children:u(g)})},g))})}),t.jsxs("div",{className:"bim-rh-main",children:[p.picks&&t.jsx(dt,{id:d.picks,title:u("picks"),sub:a("readHome.picksSub"),children:t.jsx(Pd,{picks:l.picks,links:n})}),p.topics&&t.jsx(dt,{id:d.topics,title:u("topics"),sub:a("readHome.topicsSub"),children:t.jsx(Od,{topics:c,links:n})}),p.famous&&t.jsx(dt,{id:d.famous,title:u("famous"),sub:a("readHome.famousSub"),children:t.jsx(Fd,{famous:l.famous,links:n})}),p.sibu&&t.jsx(dt,{id:d.sibu,title:u("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(Zo,{bu:l.bu,unclassified:l.unclassified,links:n})}),p.period&&t.jsx(dt,{id:d.period,title:u("period"),sub:a("readHome.periodSub"),children:t.jsx(Hd,{periods:l.periods,unknown:l.period_unknown,links:n})}),p.pieces&&t.jsx(dt,{id:d.pieces,title:u("pieces"),sub:a("readHome.piecesSub"),more:o?t.jsx("a",{className:"bim-rh-more",href:o,children:a("readHome.piecesMore")}):void 0,children:t.jsx(Dd,{authors:l.pieces.authors,links:n})})]})]})}const Sy="(max-width: 1079px)",_y=`${Vn}, (pointer: coarse)`,Vd=`
1742
+ `,vy=Xr["zh-Hant"].period,zd={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function Vt(e){return{...zd,...e??{}}}function qo(e){var i;const n=(i=e.authors)==null?void 0:i.find(o=>o==null?void 0:o.name);return n?n.dynasty?`${n.dynasty} ${n.name}`:n.name:""}function Wi(e){return(e.authors??[]).filter(i=>i==null?void 0:i.name).map(i=>i.dynasty?`〔${i.dynasty}〕${i.name}`:i.name).join(" ")}function Nd(e,n=Xr["zh-Hant"].shelfOther){var s;const i=[],o=new Map;for(const a of e){const l=((s=a.period_of)==null?void 0:s.trim())||n;let d=o.get(l);d||(d={label:l,items:[]},o.set(l,d),i.push(d)),d.items.push(a)}return i}function Id(e){return Math.max(150,Array.from(e).length*18+44)}function Rd(e,n){if(n<=0||e<=0)return 0;const i=e/n;return i<.15?0:i<.35?1:i<.6?2:i<.85?3:4}const Ed=.04;function Ke(e){return e.toLocaleString("en-US")}function Ld({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((n,i)=>t.jsx("span",{children:n},i))})}function ct({id:e,title:n,sub:i,more:o,children:s}){const{convert:a}=ne(),l=`${e}-h`;return t.jsxs("section",{className:"bim-rh-sec",id:e,"aria-labelledby":l,children:[t.jsxs("div",{className:"bim-rh-hd",children:[t.jsx("h2",{id:l,children:a(n)}),i&&t.jsx("span",{className:"bim-rh-sub",children:i}),o]}),t.jsx("div",{className:"bim-rh-bd",children:s})]})}function Ad({counts:e}){const{t:n}=ne();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:Ke(e.readable)}),n("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:Ke(e.pieces)}),n("readHome.pieces")]})]})}function Md({picks:e,links:n}){const{t:i,convert:o}=ne(),s=Vt(n);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=Wi(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:s.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(Ld,{text:o(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:o(d)}),t.jsx("h3",{children:o(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:o(l)}),a.blurb&&t.jsx("p",{children:o(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:i("readHome.startReading")})]})]})},a.id)})}):null}function Pd(e,n){return e&&e>1?n("readHome.nCopies",{n:e}):null}function Ko({topic:e,links:n,hint:i,legendCount:o,showTitle:s=!0,legendExtra:a}){const{t:l,convert:d}=ne(),c=Vt(n);if(!e.items.length)return null;const p=o===void 0?l("readHome.shelfLegendCount"):o,h=Nd(e.items,l("readHome.shelfOther")),u=m=>{const f=m.records?Ke(m.records):Pd(m.text_count,l),x=qo(m),v=[d(m.title),m.orig?l("readHome.origZhi"):"",x?l("readHome.spineBy",{name:d(x)}):"",m.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(m.id),"data-orig":m.orig?"":void 0,"aria-label":v,title:v,style:{height:Id(m.title)},children:[t.jsx(Ld,{text:d(m.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":m.records?"":void 0,children:f})]})},m.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[s&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:i?d(i):l("readHome.shelfHint")})]}),t.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":l("readHome.shelfRegion",{label:d(e.label)}),children:t.jsx("ul",{className:"bim-rh-shelf",children:h.map(m=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(m.label),children:m.items.map(u)}),t.jsx("span",{"aria-hidden":"true",children:d(m.label)})]},m.label))})}),t.jsxs("p",{className:"bim-rh-legend",children:[t.jsxs("span",{children:[t.jsx("i",{"data-orig":"","aria-hidden":"true"}),l("readHome.origZhi")]}),t.jsxs("span",{children:[t.jsx("i",{"aria-hidden":"true"}),l("readHome.laterZhi")]}),p&&t.jsx("span",{children:d(p)}),a==null?void 0:a.map(m=>t.jsx("span",{children:d(m)},m))]})]})}const ky=4,Bn=e=>e>ky+1;function Bd({topic:e,links:n}){const{t:i,convert:o}=ne(),s=Vt(n),[a,l]=g.useState(!1);if(!e.items.length)return null;const d=`bim-rh-g-${e.key}`;return t.jsxs("div",{className:"bim-rh-grp","data-cap":Bn(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[o(e.label),t.jsx("small",{className:"bim-rh-num",children:i("readHome.nWorks",{n:Ke(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const p=Pd(c.text_count,i),h=qo(c);return t.jsx("li",{children:t.jsxs("a",{href:s.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:o(c.title)}),p&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:p}),h&&t.jsx("small",{children:o(h)})]})},c.id)})}),Bn(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?i("action.collapse"):i("readHome.allNWorks",{n:e.items.length})})]})}function Wd({topics:e,links:n}){const i=e.filter(s=>s.shelf&&s.items.length),o=e.filter(s=>!s.shelf&&s.items.length);return!i.length&&!o.length?null:t.jsxs(t.Fragment,{children:[i.map(s=>t.jsx(Ko,{topic:s,links:n},s.key)),o.length>0&&t.jsx("div",{className:"bim-rh-groups",children:o.map(s=>t.jsx(Bd,{topic:s,links:n},s.key))})]})}function Od({famous:e,links:n}){const{t:i,convert:o}=ne(),s=Vt(n);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:o(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:o(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:i("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?o(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:o(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:s.read(c.id),title:o([c.title,c.edition].filter(Boolean).join(" · ")),children:o(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:s.work(a.work_id),children:i("readHome.workPageLink",{title:o(a.title)})})})]})},a.work_id??a.title))}):null}function Xo({bu:e,unclassified:n,links:i,unclassifiedNote:o}){const{t:s,convert:a}=ne(),l=Vt(i);return!e.length&&!n?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var p;const c=((p=d.top[0])==null?void 0:p.count)||1;return t.jsxs("li",{className:"bim-rh-bu-c",children:[t.jsxs("a",{className:"bim-rh-bu-h",href:l.node(d.id),children:[t.jsx("b",{children:a(d.label)}),t.jsx("span",{className:"bim-rh-num",children:s("readHome.nWorks",{n:Ke(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":s("readHome.subClasses",{label:a(d.label)}),children:d.top.map(h=>t.jsx("li",{children:t.jsxs("a",{href:l.node(h.id),children:[t.jsx("span",{children:a(h.label)}),t.jsx("small",{className:"bim-rh-num",children:Ke(h.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(h.count/c*100)}%`}})]})},h.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:s("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!n&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:s("readHome.unclassified")}),t.jsx("span",{children:s("readHome.nWorks",{n:Ke(n)})}),t.jsx("span",{children:o?a(o):s("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:s("readHome.viewUnclassified")})]})]})}function Fd({periods:e,unknown:n,links:i}){const{t:o,convert:s,messages:a}=ne(),l=a.readHome.period,d=Vt(i),c=e.filter(u=>u.count>0);if(!c.length)return null;const p=c.reduce((u,m)=>u+m.count,0),h=Math.max(...c.map(u=>u.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(u=>{const m=u.label?s(u.label):l[u.key]??s(u.key),f=u.count/p,x=o("readHome.periodItem",{label:m,n:Ke(u.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(u.key),"data-k":Rd(u.count,h),"data-narrow":f<Ed?"":void 0,"aria-label":x,title:x,children:[t.jsx("span",{className:"bim-rh-pl",children:m}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(m)[0]}),t.jsx("small",{className:"bim-rh-num",children:Ke(u.count)})]})},u.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&t.jsx("span",{children:o("readHome.periodUnknown",{n:Ke(n)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:o("readHome.hoverHint")})]})]})}function Hd({authors:e,links:n}){const{t:i,convert:o}=ne(),s=Vt(n);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[o(a.name),a.dynasty&&t.jsx("span",{children:o(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:i("readHome.nPieces",{n:Ke(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:s.read(l.id),children:o(l.title)})},l.id))}),s.author&&t.jsx("a",{className:"bim-rh-more",href:s.author(a.name),children:i("readHome.authorAll",{name:o(a.name),n:a.count})})]},a.name))}):null}const Dd={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function wy({sections:e,links:n,head:i,piecesMoreHref:o,className:s}){const{t:a}=ne(),l=e,d=Dd,c=l.topics.filter(m=>!m.shelf),p={picks:l.picks.length>0,topics:c.some(m=>m.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(m=>m.count>0),pieces:l.pieces.authors.length>0},h=Object.keys(d).filter(m=>p[m]),u=m=>a(`readHome.nav.${m}`);return t.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[t.jsx("style",{children:Yo}),t.jsxs("div",{className:"bim-rh-head",children:[i,t.jsx(Ad,{counts:l.counts})]}),h.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:h.map(m=>t.jsx("li",{children:t.jsx("a",{href:`#${d[m]}`,children:u(m)})},m))})}),t.jsxs("div",{className:"bim-rh-main",children:[p.picks&&t.jsx(ct,{id:d.picks,title:u("picks"),sub:a("readHome.picksSub"),children:t.jsx(Md,{picks:l.picks,links:n})}),p.topics&&t.jsx(ct,{id:d.topics,title:u("topics"),sub:a("readHome.topicsSub"),children:t.jsx(Wd,{topics:c,links:n})}),p.famous&&t.jsx(ct,{id:d.famous,title:u("famous"),sub:a("readHome.famousSub"),children:t.jsx(Od,{famous:l.famous,links:n})}),p.sibu&&t.jsx(ct,{id:d.sibu,title:u("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(Xo,{bu:l.bu,unclassified:l.unclassified,links:n})}),p.period&&t.jsx(ct,{id:d.period,title:u("period"),sub:a("readHome.periodSub"),children:t.jsx(Fd,{periods:l.periods,unknown:l.period_unknown,links:n})}),p.pieces&&t.jsx(ct,{id:d.pieces,title:u("pieces"),sub:a("readHome.piecesSub"),more:o?t.jsx("a",{className:"bim-rh-more",href:o,children:a("readHome.piecesMore")}):void 0,children:t.jsx(Hd,{authors:l.pieces.authors,links:n})})]})]})}const Sy="(max-width: 1079px)",_y=`${Vn}, (pointer: coarse)`,Ud=`
1743
1743
  /* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
1744
1744
  .bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
1745
1745
  .bim-mh-q { min-width: 0; }
@@ -1910,4 +1910,4 @@ ${jy.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1910
1910
  .bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
1911
1911
  .bim-mh-recent-h button { min-height: 44px; }
1912
1912
  }
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;
1913
+ `,Vd={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function Gt(e){return{...Vd,...e??{}}}function Gd(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 Zo(e,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(e/n*100)))}function Yd(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 h=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(h,u),Math.max(h,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,h)=>({p,from:s[h][0],to:s[h][1]})).sort((p,h)=>p.from-h.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 vi(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 qd({counts:e,links:n}){const{t:i}=ne(),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 Kd(e,n=5){const[i,o]=g.useState(null);g.useEffect(()=>{let a=!1;const l=Ut().slice(0,n);if(!l.length||!e){o([]);return}return Promise.all(l.map(d=>eo(e,d))).then(d=>{a||o(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,n]);const s=g.useCallback(()=>{Qr(),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):Xd(e.type,n)}function Xd(e,n){return n(`metaHome.typeLabel.${e}`)}function Zd({entries:e,onClear:n,links:i}){const{t:o,convert:s}=ne(),a=Gt(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?Xd(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 Jd(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 Qd({rows:e,links:n}){const{t:i,convert:o}=ne(),s=Gt(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=Zo(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:Jd(a.status,i,o)})})]},a.id||a.name)})})]})}):null}function ep({items:e,links:n,label:i}){const{convert:o}=ne();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 tp({works:e,links:n}){const{t:i}=ne(),[o,s]=g.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(ep,{items:e.map(l=>({id:l.id,title:l.title,sub:Wi(l)||void 0})),links:Gt(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 np="siku_qige";function Ty({group:e,links:n}){const{t:i,convert:o}=ne(),[s,a]=g.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(ep,{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 ip({groups:e,links:n}){const{t:i,convert:o}=ne(),s=Gt(n);if(!e.length)return null;const a=e.find(c=>c.key===np),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 Ya=34,qa=13;function Ka(e,n){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?vi(e.birth_year,n):"?"}–${e.death_year!=null?vi(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 rp({people:e,links:n}){const{t:i,convert:o}=ne(),s=Gt(n);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=Yd(e),p=[],h=d.map(m=>{const f=m.left>70,x=f?Math.min(m.left,m.left+m.width-qa):m.left;let v=0;for(;p[v]!=null&&p[v]>x;)v++;return p[v]=f?m.left+m.width:m.left+Math.max(m.width,qa),{...m,lane:v,end:f}}),u=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[h.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:p.length*Ya+10},children:h.map(m=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":m.end?"":void 0,style:{left:`${m.left}%`,top:m.lane*Ya+4,width:`${Math.max(m.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:s.item(m.p.id),children:[o(m.p.name),t.jsx("small",{className:"bim-rh-num",children:Ka(m.p,i)})]})]},m.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:zy(a,l).map(m=>t.jsx("span",{style:{left:`${(m-a)/u*100}%`},children:vi(m,i)},m))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":h.length?void 0:"",children:(h.length?e:c).map(m=>t.jsx("li",{children:t.jsxs("a",{href:s.item(m.id),children:[t.jsx("span",{children:o(m.name)}),t.jsx("small",{className:"bim-rh-num",children:[m.dynasty?o(m.dynasty):"",Ka(m,i)].filter(Boolean).join(" ")})]})},m.id))}),c.length>0&&h.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:i("metaHome.missingLife",{names:o(c.map(m=>m.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 op({works:e,links:n}){const{t:i,convert:o}=ne(),s=Gt(n);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=Wi(a);return t.jsx("li",{children:t.jsxs("a",{href:Gd(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 sp({sites:e}){const{t:n,convert:i}=ne(),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=Zo(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:Jd(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 Xa=["extant","partially_extant","lost","unknown"];function ap({stats:e,links:n,version:i,repoUrl:o,downloadHref:s}){const{t:a}=ne(),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=Xa.some(p=>{var h;return(((h=e.loss)==null?void 0:h[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,h])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:Ke(p)}),t.jsx("span",{children:h})]},h))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:Xa.map(p=>{var m;const h=((m=e.loss)==null?void 0:m[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&&h>0?a("metaHome.lossCount",{n:Ke(h),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 lp={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:h}){var k,$;const{t:u}=ne(),m=e,f=Gt(n),x=$y(f),v=lp,y=Kd(o),S={zhi:!!((k=m.shelf)!=null&&k.items.length)||m.catalog_progress.length>0||m.related_catalogs.length>0,sibu:m.bu.length>0||m.unclassified>0,cong:m.collection_groups.length>0,people:m.bibliographers.length>0,lineage:m.lineage.length>0,sites:m.sites.length>0,data:!0},b=Object.keys(v).filter(C=>S[C]),w=C=>u(`metaHome.nav.${C}`),j=(C,_)=>C?t.jsx("a",{className:"bim-rh-more",href:C,children:_}):void 0;return t.jsxs("div",{className:h?`bim-rh bim-mh ${h}`:"bim-rh bim-mh",children:[t.jsx("style",{children:Yo+Ud}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[i,t.jsx(qd,{counts:m.counts,links:n})]}),o&&t.jsx(Zd,{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(C=>t.jsx("li",{children:t.jsx("a",{href:`#${v[C]}`,children:w(C)})},C))})}),t.jsxs("div",{className:"bim-rh-main",children:[S.zhi&&t.jsxs(ct,{id:v.zhi,title:w("zhi"),sub:u("metaHome.zhiSub"),children:[m.shelf&&m.shelf.items.length>0&&t.jsx(Ko,{topic:{key:"shelf",label:m.shelf.label,shelf:!0,items:m.shelf.items},links:x,showTitle:!1,legendCount:m.shelf.items.some(C=>C.records)?u("metaHome.shelfLegendCount"):null,legendExtra:[u("metaHome.shelfLegendClick")]}),(m.catalog_progress.length>0||m.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:($=m.shelf)!=null&&$.items.length?void 0:{marginTop:0},children:[t.jsx(Qd,{rows:m.catalog_progress,links:n}),t.jsx(tp,{works:m.related_catalogs,links:n})]})]}),S.sibu&&t.jsx(ct,{id:v.sibu,title:w("sibu"),sub:u("metaHome.sibuSub"),more:j(s,u("metaHome.toCatalog")),children:t.jsx(Xo,{bu:m.bu,unclassified:m.unclassified,links:x,unclassifiedNote:u("metaHome.unclassifiedNote")})}),S.cong&&t.jsx(ct,{id:v.cong,title:w("cong"),sub:u("metaHome.congSub"),more:j(a,u("metaHome.allNKindsMore",{n:Ke(m.counts.collections)})),children:t.jsx(ip,{groups:m.collection_groups,links:n})}),S.people&&t.jsx(ct,{id:v.people,title:w("people"),sub:u("metaHome.peopleSub"),more:j(l,u("metaHome.allNPeopleMore",{n:Ke(m.counts.entities)})),children:t.jsx(rp,{people:m.bibliographers,links:n})}),S.lineage&&t.jsx(ct,{id:v.lineage,title:w("lineage"),sub:u("metaHome.lineageSub"),children:t.jsx(op,{works:m.lineage,links:n})}),S.sites&&t.jsx(ct,{id:v.sites,title:w("sites"),sub:u("metaHome.sitesSub"),children:t.jsx(sp,{sites:m.sites})}),t.jsx(ct,{id:v.data,title:w("data"),sub:u("metaHome.dataSub"),children:t.jsx(ap,{stats:m.stats,links:n,version:d,repoUrl:c,downloadHref:p})})]})]})}const cp=["_related","_catalogs","_collections","_members","_children"],Ry=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Hr=e=>Ry(e)&&!!e.h;function Ey(e){return e?cp.some(n=>{const i=e[n];return Array.isArray(i)&&i.some(Hr)}):!1}function Ly(e,n){const i={...e};if(!n)return i;for(const o of cp){const s=e[o];!Array.isArray(s)||!s.some(Hr)||(i[o]=s.map(a=>{var c;if(!Hr(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 Dr=({style:e})=>{const n=g.useContext(Tt),{t:i}=ne();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")})]})},Ur=({href:e,label:n,size:i=16,className:o,style:s})=>{const{t:a}=ne(),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 br(e){const n=e.text_count;return typeof n=="number"&&n>0}function yr(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:h,onLineageCollectionChange:u,initialPage:m=1,selectedLineageNodeId:f,onNavigate:x,onBack:v,backLabel:y,renderLink:S,enrichDetail:b,getSourceLink:w,readLink:j,railTop:k,extraTabs:$=[],showFeedbackTab:C=!0,feedbackApiUrl:_,height:L,footerExtra:z,hideHeaderControls:T=!1,className:M,style:P})=>{const N=g.useMemo(()=>Ay(n),[n]),A=Ee(),{t:W,convert:G}=ne(),[X]=g.useState(()=>{if(!My(e,i))return null;const te={...i},ve=o??yr(e,te);return b&&b(ve,te),{id:e,entry:ve,detail:te}}),[le,U]=g.useState((X==null?void 0:X.entry)??null),[D,xe]=g.useState((X==null?void 0:X.detail)??null),[Y,E]=g.useState(!X),[Te,ce]=g.useState(!1),[me,se]=g.useState([]),[We,J]=g.useState(!1),[re,de]=g.useState(null),[H,Z]=g.useState(null),[ke,ie]=g.useState(null),[B,Q]=g.useState(!1),ae=g.useRef(null),je=g.useRef(0),[q,be]=g.useState(null),Le=l!==void 0?l:q,Fe=g.useCallback(te=>{d?d(te):be(te)},[d]),O=g.useCallback(async te=>{if(!N.getCollectionCatalogs&&!N.getCollectionCatalog){se([]);return}J(!0);try{if(N.getCollectionCatalogs)se(await N.getCollectionCatalogs(te)||[]);else if(N.getCollectionCatalog){const ve=await N.getCollectionCatalog(te);se(ve?[{resource_id:"",data:ve}]:[])}}catch{se([])}finally{J(!1)}},[N]),ee=g.useCallback(async te=>{var ve,Me;if(!N.getTextManifest||!N.getTextIndex){de(null),Z(te);return}try{const Oe=Se.pickTextVersion(await N.getTextManifest(te)),Ie=Oe?await N.getTextIndex(te,Oe.key):null;de(Ie&&Ie.chapters.length>0?{chapters:Ie.chapters.map(ge=>({n:ge.n,title:ge.title,file:ge.file})),source:{name:((ve=Ie.source)==null?void 0:ve.name)??(Oe==null?void 0:Oe.source_name),license:((Me=Ie.source)==null?void 0:Me.license)??(Oe==null?void 0:Oe.license)??void 0}}:null)}catch{de(null)}finally{Z(te)}},[N]),_e=g.useCallback(async(te,ve)=>{const Me=++je.current,Oe=()=>Me!==je.current;Q(!0);try{if(N.getLineageGraph){const jt=await N.getLineageGraph(te);if(Oe())return;jt&&ie(jt)}const Ie=ve.version_graph;if(!Ie||!Ie.enabled){ke||ie(null),ae.current=null;return}const ge=po(ve),De=(await Pi(ge,Mi,async jt=>{try{return await N.getItem(jt)}catch{return null}},Oe)).filter(Boolean);if(Oe())return;ae.current={work:ve,books:De};const Pe=h??Ie.default_collection??(Ie.core_books&&Ie.core_books.length>0?"core":"all"),yt=Pe==="core"&&Array.isArray(Ie.core_books)&&Ie.core_books.length>0?"core":Pe??"all";ie(hi(ve,De,yt))}catch{if(Oe())return;ie(null),ae.current=null}finally{Oe()||Q(!1)}},[N]),ze=g.useRef({initialDetail:i,initialEntry:o});ze.current={initialDetail:i,initialEntry:o},g.useEffect(()=>{let te=!1;je.current++,Q(!1);const ve=ge=>{ge.type==="collection"?O(e):ge.type==="work"?(ge.version_graph||N.getLineageGraph)&&_e(e,ge):ge.type==="book"&&br(ge)&&ee(e)},Me=ze.current;let Oe=null;if(X&&X.id===e)Oe=X;else if(Me.initialDetail&&Me.initialDetail.id===e){const ge={...Me.initialDetail},Ce=Me.initialEntry??yr(e,ge);b&&b(Ce,ge),Oe={entry:Ce,detail:ge}}return Oe?(ce(!1),se(ge=>ge.length?[]:ge),de(null),ie(null),ae.current=null,U(Oe.entry),xe(Oe.detail),E(!1),ve(Oe.detail),()=>{te=!0}):((async()=>{E(!0),ce(!1),U(null),xe(null),se([]),de(null),ie(null),ae.current=null;try{const ge=await N.getItem(e);if(te)return;if(!ge){ce(!0);return}const Ce=ge;let De=null;if(N.getEntry&&(De=await N.getEntry(e),te))return;De||(De=yr(e,Ce)),b&&b(De,Ce),U(De),xe(Ce),ve(Ce)}catch{te||ce(!0)}finally{te||E(!1)}})(),()=>{te=!0})},[e,N,X,b,O,_e,ee]),g.useEffect(()=>{const te=ae.current;!te||!h||ie(hi(te.work,te.books,h))},[h]);const F=[];if(D){if(F.push({key:"basic",label:A.detailTab.basicInfo}),D.type==="collection"){We&&me.length===0&&F.push({key:"catalog:loading",label:`${A.detailTab.catalog}…`});for(const te of me)F.push({key:`catalog:${te.resource_id}`,label:te.short_name?`${G(te.short_name)}${A.detailTab.catalogSuffix}`:A.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&F.push({key:s,label:A.detailTab.fullText}),D.type==="work"&&(ke||B)&&F.push({key:"lineage",label:B?`${A.detailTab.lineage}…`:A.detailTab.lineage});for(const te of $)(te.position??"before-feedback")==="before-feedback"&&te.shouldShow(D)&&F.push({key:te.key,label:te.label});C&&s==="feedback"&&F.push({key:"feedback",label:A.detailTab.feedback});for(const te of $)te.position==="after-feedback"&&te.shouldShow(D)&&F.push({key:te.key,label:te.label})}g.useEffect(()=>{if(s!=="emendated"||!D)return;a("basic");const te=setTimeout(()=>{var ve;(ve=document.getElementById("studies"))==null||ve.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(te)},[s,D,a]);const fe=le&&D&&w?w({activeTab:s,activeJuan:Le,entry:le,detail:D}):null,oe=g.useMemo(()=>{var Ie;if(!D)return null;const ve=(D.authors??[]).map(ge=>{const Ce=co(ge.role);return`${ge.dynasty?`〔${G(ge.dynasty)}〕`:""}${G(ge.name)}${Ce?` ${G(Ce)}`:""}`}).join(" · ");let Me=!1;try{Me=Se.extractStatus(D.id)==="draft"}catch{}if(D.type==="book"){const ge=D;return{title:G(ge.title),subtitle:ge.edition?G(ge.edition):ve||void 0,aside:[Me?A.status.draft:"",ve&&ge.edition?ve:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(D.type==="collection"){const ge=D;return{title:G(ge.title),subtitle:G(Bt(ge,A.unit.juan))||void 0,aside:[(Ie=ge.publication_info)==null?void 0:Ie.year,Me?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ve||void 0}}if(D.type==="entity"){const ge=D,Ce=Pe=>Pe==null?"":Pe<0?W("detail.bce",{n:-Pe}):String(Pe),De=ge.birth_year!=null||ge.death_year!=null?`${Ce(ge.birth_year)||"?"}—${Ce(ge.death_year)||"?"}`:"";return{title:G(ge.primary_name||ge.title),subtitle:[ge.dynasty?`〔${G(ge.dynasty)}〕`:"",De].filter(Boolean).join(" ")||void 0,aside:Me?A.status.draft:void 0,secondLine:void 0}}const Oe=G(Bt(D,A.unit.juan));return{title:G(D.title),subtitle:[Oe,ve].filter(Boolean).join(" · ")||void 0,aside:[Wy(A,D.subtype),Me?A.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[D,G,A,W]),we=D&&br(D)?"text":null,Ae=()=>{Fe(null),a("fulltext")};let He=null;if(D&&j){const te=j({detail:D,kind:we});te&&(He=t.jsx(zr,{href:te}))}else we&&(He=t.jsx(zr,{onClick:Ae}));const Ge=te=>{if(!D)return null;const ve=te.replace(/\.[^.]+$/,"");if(j){const Me=j({detail:D,kind:we,juan:ve});return Me?{href:Me}:null}return{onClick:()=>{Fe(ve),a("fulltext")}}},Ye=new Set($.map(te=>te.key)),Xe=F.filter(te=>te.key.startsWith("catalog:")&&te.key!=="catalog:loading"||te.key==="lineage"&&!!ke&&!B||Ye.has(te.key)).map(te=>({key:te.key,label:te.label,onClick:()=>a(te.key)})),I=()=>{var te;return D?D.type==="work"?t.jsx(md,{data:D,transport:N,onNavigate:x,renderLink:S,readAction:He,railTop:k,railLinks:Xe}):D.type==="book"?t.jsx(xd,{data:D,transport:N,onNavigate:x,renderLink:S,readAction:He,fullText:re,fullTextPending:br(D)&&!!N.getTextManifest&&H!==D.id,chapterLink:Ge,railTop:k,railLinks:Xe}):D.type==="collection"?t.jsx(bd,{data:D,catalog:(te=me[0])==null?void 0:te.data,transport:N,onNavigate:x,renderLink:S,readAction:He,railTop:k,railLinks:Xe,catalogAction:me.length>0?t.jsxs("a",{href:"#catalog",onClick:ve=>{ve.preventDefault(),a(`catalog:${me[0].resource_id}`)},children:[G(A.detailTab.collectionCatalog)," →"]}):null}):t.jsx(yd,{data:D,transport:N,onNavigate:x,renderLink:S,railTop:k,railLinks:Xe}):null},V=()=>{var ve,Me,Oe;if(!le||!D)return null;if(s==="basic"||s==="emendated")return I();if(typeof s=="string"&&s.startsWith("catalog:")){const Ie=(ve=me.find(ge=>`catalog:${ge.resource_id}`===s))==null?void 0:ve.data;return t.jsx(no,{data:Ie,onNavigate:x,renderLink:S})}if(s==="collated"||s==="fulltext")return t.jsx(Bo,{id:e,transport:N,chapter:Le,onLocationChange:Ie=>Fe(Ie.chapter),onNavigate:x});if(s==="lineage"){if(!ke)return t.jsx("div",{style:{color:r("label-fg"),padding:"24px 0"},children:W(B?"detail.loading":"detail.noLineageGraph")});const Ie=D.type==="work"?D:null;return t.jsx(Do,{graph:ke,renderLink:S,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:p,selectedNodeId:f,collection:h??((Me=Ie==null?void 0:Ie.version_graph)==null?void 0:Me.default_collection),onCollectionChange:u,collectionsAvailable:(Oe=Ie==null?void 0:Ie.version_graph)==null?void 0:Oe.collections,collectionCounts:(()=>{var Pe,yt,jt,on,Wt,K,Re;if(!Ie)return;const ge={},Ce=((Pe=ae.current)==null?void 0:Pe.books)??[];ge.all=(((yt=Ie._books)==null?void 0:yt.length)??0)-(((on=(jt=Ie.version_graph)==null?void 0:jt.excluded_books)==null?void 0:on.length)??0);const De=(Wt=Ie.version_graph)==null?void 0:Wt.collections;if(De)for(const qe of Object.keys(De))ge[qe]=hi(Ie,Ce,qe).nodes.filter(ot=>ot.kind==="book"&&!ot.bridge).length;return ge.core==null&&((Re=(K=Ie.version_graph)==null?void 0:K.core_books)!=null&&Re.length)&&(ge.core=Ie.version_graph.core_books.length),ge})()})}if(s==="feedback"&&C)return t.jsx(cd,{resourceId:e,apiUrl:_});const te=$.find(Ie=>Ie.key===s);return te?te.render({detail:D,entry:le,transport:N,onNavigate:x}):null};if(Y)return t.jsx(In,{style:{minHeight:L,...P},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((te,ve)=>t.jsx("div",{style:{height:ve===1?40:16,width:te,opacity:.35,background:r("rule")}},ve))})});if(Te||!D||!le||!oe)return t.jsx(In,{style:{minHeight:L,...P},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r("label-fg"),fontSize:14},children:W("detail.notFound")})});const ue=s==="basic"||s==="emendated",$e=[{label:y??A.detailTab.backToIndex,onClick:v}];if(D.type==="book"&&D.work_id){const te=D.work_id;$e.push({label:A.indexType.work,id:te,onClick:()=>x==null?void 0:x(te)})}$e.push({label:A.indexType[D.type]});const ye=s==="collated"||s==="fulltext",he=typeof z=="string"?A.status[z.trim()]??z:z,Ve=t.jsx(jc,{left:t.jsxs(t.Fragment,{children:[he,he?" · ":"",t.jsx(By,{id:D.id,label:A.label.id,copied:A.action.copied,copyLabel:A.action.copy})]}),right:t.jsxs(t.Fragment,{children:[C&&!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:M,children:t.jsxs(In,{grid:!0,style:{minHeight:L,...P},children:[t.jsx(Nr,{breadcrumb:t.jsx(Ir,{items:$e}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Dr,{style:{border:"none",background:"transparent"}}),!T&&fe&&t.jsx(Ur,{...fe})]})}),I(),Ve]})}):t.jsx("div",{className:M,children:t.jsxs(In,{wide:ye,style:{minHeight:L,...P},children:[t.jsx(Nr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(fo,{char:"籍"}),t.jsx(Ir,{items:$e})]}),actions:t.jsxs(t.Fragment,{children:[!T&&t.jsx(Dr,{}),C&&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(Ur,{...fe})]})}),t.jsx(pc,{...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:[W("detail.workInfo")," →"]}):oe.aside}),!ye&&F.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:F.map(te=>t.jsx(uc,{label:te.label,active:te.key===s||ue&&te.key==="basic",onClick:()=>a(te.key)},te.key))}),t.jsx("div",{style:{marginTop:!ye&&F.length>1?8:0},children:V()}),Ve]})})};function By({id:e,label:n,copied:i,copyLabel:o}){const[s,a]=g.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var l;(l=navigator.clipboard)==null||l.writeText(e).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},title:s?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 dp=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Oi="zhusha",Fi="bim-theme";function pp(e){return e==="zhusha"||e==="indigo"||e==="ink"}function Hi(e){return pp(e)?e:Oi}function Oy(){try{return Hi(window.localStorage.getItem(Fi))}catch{return Oi}}function up(e){try{window.localStorage.setItem(Fi,e)}catch{}}function mp(e){const n=Hi(e);return document.documentElement.setAttribute("data-theme",n),n}function hp(){return Hi(document.documentElement.getAttribute("data-theme"))}const Fy=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],Jo="airy",Di="bim-layout";function gp(e){return e==="airy"||e==="boxed"}function Ui(e){return gp(e)?e:Jo}function Hy(){try{return Ui(window.localStorage.getItem(Di))}catch{return Jo}}function Dy(e){try{window.localStorage.setItem(Di,e)}catch{}}function Uy(e){const n=Ui(e);return document.documentElement.setAttribute("data-layout",n),n}function Vy(){return Ui(document.documentElement.getAttribute("data-layout"))}const Gy=`try{var t=localStorage.getItem(${JSON.stringify(Fi)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(Di)})==='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}=ne(),[o,s]=g.useState(Oi);g.useEffect(()=>{s(hp())},[]);const a=l=>{s(mp(l)),up(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":i("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...n},children:dp.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=Se.BidLink;exports.BookIndexError=Se.BookIndexError;exports.BookIndexManager=Se.BookIndexManager;exports.BookIndexStorage=Se.BookIndexStorage;exports.BundleStorage=Se.BundleStorage;exports.ConfigError=Se.ConfigError;exports.GithubStorage=Se.GithubStorage;exports.IdGenerationError=Se.IdGenerationError;exports.IdGenerator=Se.IdGenerator;exports.LocalStorage=Se.LocalStorage;exports.MigrationError=Se.MigrationError;exports.StorageError=Se.StorageError;exports.VARIANT_CHARS=Se.VARIANT_CHARS;exports.base36Decode=Se.base36Decode;exports.base36Encode=Se.base36Encode;exports.base58Decode=Se.base58Decode;exports.buildId=Se.buildId;exports.buildPromotionMap=Se.buildPromotionMap;exports.cleanName=Se.cleanName;exports.decodeId=Se.decodeId;exports.decodeIdString=Se.decodeIdString;exports.encodeId=Se.encodeId;exports.extractIdFromUrl=Se.extractIdFromUrl;exports.extractStatus=Se.extractStatus;exports.extractType=Se.extractType;exports.isChapterSegment=Se.isChapterSegment;exports.isTextKey=Se.isTextKey;exports.matchChapterAcrossVersions=Se.matchChapterAcrossVersions;exports.normalizeCatalog=Se.normalizeCatalog;exports.normalizeVariants=Se.normalizeVariants;exports.parseId=Se.parseId;exports.pickTextVersion=Se.pickTextVersion;exports.shardOf=Se.shardOf;exports.smartDecode=Se.smartDecode;exports.textVersionLabel=Se.textVersionLabel;exports.validateResource=Se.validateResource;exports.VARIANT_SUPPLEMENT=Za.VARIANT_SUPPLEMENT;exports.Badge=ji;exports.BidUrlProvider=Wp;exports.BookDetailLayout=Py;exports.BookPage=xd;exports.Breadcrumb=Ir;exports.CATALOG_ALL_ID=Lt;exports.CATALOG_CSS=jd;exports.CATALOG_NARROW_QUERY=Uo;exports.CATALOG_PAGE_SIZE=Vo;exports.CATALOG_UNCLASSIFIED_ID=Qt;exports.CLASSIFICATIONS=Ci;exports.COMMON_TRADITIONAL_CHARS=ll;exports.CardFoot=Hn;exports.CatalogPage=xy;exports.CatalogPager=Cd;exports.CatalogTree=kd;exports.CheckFilter=lc;exports.Chip=mc;exports.ChipWall=Ah;exports.CollectionCatalog=no;exports.CollectionPage=bd;exports.CreateEntityDialog=td;exports.DEFAULT_LAYOUT=Jo;exports.DEFAULT_META_HOME_LINKS=Vd;exports.DEFAULT_READER_PREFS=ro;exports.DEFAULT_READ_HOME_LINKS=zd;exports.DEFAULT_THEME=Oi;exports.DETAIL_CSS=dc;exports.DYNASTY_GROUPS=$i;exports.Dash=Fh;exports.DataTable=Ph;exports.DetailFooter=jc;exports.DetailGrid=On;exports.DetailHeader=pc;exports.EMPTY_FILTERS=_i;exports.ENTITY_TEXT_CSS=Eo;exports.EmendatedBySection=Nl;exports.EmptyNote=qh;exports.EntityDetail=Sl;exports.EntityMark=Ao;exports.EntityPage=yd;exports.EntityPickerDialog=id;exports.EntitySelector=ed;exports.EntityText=mf;exports.ExpandRow=Hh;exports.ExtLink=Kh;exports.FEEDBACK_FAB_OFFSET_VAR=Wr;exports.FILTER_SUPPORT=gl;exports.FONT_SIZE_STEPS=Et;exports.FactList=Ih;exports.FeedbackButton=rb;exports.FeedbackDialog=ad;exports.FeedbackForm=ld;exports.FeedbackList=Wo;exports.FeedbackTab=cd;exports.FilterChip=uc;exports.FormInput=ht;exports.FormTextArea=tn;exports.GUJI_MARKDOWN_FIELD=fh;exports.GUJI_TABLE_NOTATION=vc;exports.GlyphBadge=fo;exports.GujiInteractiveReader=Qf;exports.GujiTable=yo;exports.GujiTextViewer=Mo;exports.GujiWarpCanvas=Ro;exports.HomePage=Pr;exports.ImagePanel=wr;exports.IndexApp=Jf;exports.IndexBrowser=kr;exports.IndexDetail=to;exports.IndexEditor=rd;exports.IndexView=Ux;exports.IntroGrid=Nh;exports.LAYOUTS=Fy;exports.LAYOUT_STORAGE_KEY=Di;exports.LOSS_OPTIONS=hl;exports.LocaleContext=Tt;exports.LocaleProvider=mu;exports.LocaleToggle=Dr;exports.META_HOME_CSS=Ud;exports.META_HOME_SECTION_IDS=lp;exports.MetaCatalogTable=Qd;exports.MetaCollectionGroups=ip;exports.MetaDataLicense=ap;exports.MetaHomeView=Iy;exports.MetaLine=it;exports.MetaLineageCards=op;exports.MetaOnlineSites=sp;exports.MetaPeopleTimeline=rp;exports.MetaRecentPanel=Zd;exports.MetaRelatedCatalogs=tp;exports.MetaTypeChips=qd;exports.ModeIndicator=dl;exports.MoreButton=Lh;exports.MoreLink=ho;exports.PAGE_MAX_WIDTH=pi;exports.PERIOD_NARROW_SHARE=Ed;exports.PageFrame=In;exports.Quote=Uh;exports.READER_CSS=Pl;exports.READ_HOME_CSS=Yo;exports.READ_HOME_NARROW_QUERY=Vn;exports.READ_HOME_SECTION_IDS=Dd;exports.READ_PERIOD_LABELS=vy;exports.RECENT_IDS_STORAGE_KEY=un;exports.ROLE_CLASS_ORDER=Zl;exports.ReadButton=zr;exports.ReadFamousWorks=Od;exports.ReadHomeView=wy;exports.ReadPeriodBand=Fd;exports.ReadPicks=Md;exports.ReadPieces=Hd;exports.ReadSection=ct;exports.ReadShelf=Ko;exports.ReadSibu=Xo;exports.ReadStats=Ad;exports.ReadTopicGroup=Bd;exports.ReadTopics=Wd;exports.ReaderMdText=So;exports.ReaderShell=Vl;exports.ReaderToc=Wl;exports.RelationPanel=Jc;exports.RepoSourceLink=Ur;exports.ResourceEditor=jr;exports.ResourceGroup=Vh;exports.ResourceLine=Gh;exports.ResourceList=Zr;exports.ResourceRow=bc;exports.SEARCH_VIEW_STORAGE_KEY=Jr;exports.SEVEN_PAVILIONS_KEY=np;exports.SNIPPET_MARK_END=el;exports.SNIPPET_MARK_START=Qa;exports.SORTABLE_TYPES=ml;exports.SearchInput=ul;exports.SearchResults=vl;exports.Sec=rt;exports.Section=kt;exports.SectionHead=Rh;exports.SideList=en;exports.SmartBidInput=mi;exports.SourceEditor=Kc;exports.StripWarpRenderer=Lr;exports.SummaryCard=Fn;exports.THEMES=dp;exports.THEME_INIT_SCRIPT=Gy;exports.THEME_STORAGE_KEY=Fi;exports.TRADITIONAL_ALLOWLIST=cl;exports.TabFilter=Ei;exports.TableHead=Bh;exports.TableRow=Wh;exports.TagRow=yc;exports.TagRows=Yh;exports.TextButton=Eh;exports.TextReader=Bo;exports.ThemeToggle=qy;exports.TopStrip=Nr;exports.VersionLineageGraph=fd;exports.VersionLineageList=gd;exports.VersionLineageView=Do;exports.VolumeChips=Mh;exports.VolumeLinks=xo;exports.WorkCard=_d;exports.WorkCardGrid=Td;exports.WorkCatalog=cx;exports.WorkPage=md;exports.WorkRow=$d;exports.adaptCharCord=lx;exports.adaptEntityJson=Ec;exports.adaptPunctJson=tx;exports.applyLayout=Uy;exports.applyTheme=mp;exports.authorsLine=Wi;exports.bookIndexUriToId=Er;exports.bookMarkingOf=ko;exports.bucketResources=ao;exports.buildCatalogTree=ly;exports.buildCollectionTable=ec;exports.buildLineageGraph=hi;exports.buildMeiliFilter=Iu;exports.buildPageUrl=Kr;exports.buildParagraphBlocks=Tc;exports.buildVersionRow=Kl;exports.buildVersionTable=Xl;exports.canParagraphize=bi;exports.catalogNodeIdOf=sy;exports.catalogNodeIdsOf=ay;exports.catalogPageCount=uy;exports.catalogTotal=Go;exports.classificationPath=Un;exports.clearAllRecentIds=Qr;exports.compareCatalogCards=py;exports.computeVersionPartition=ch;exports.countActiveFilters=Ti;exports.createTextApi=Rl;exports.currentLayout=Vy;exports.currentTheme=hp;exports.defaultEntityHref=Hc;exports.defaultWorkLink=wd;exports.deriveDating=sh;exports.deriveEditionType=nc;exports.deriveEra=Wn;exports.deriveYear=Ni;exports.deriveYearRange=so;exports.detailToEditor=sd;exports.detectGenre=Ai;exports.displayAuthorRole=co;exports.editorToDetail=Dx;exports.eraRank=Cr;exports.filtersFromParams=Ru;exports.filtersToParams=gi;exports.findCatalogPath=pn;exports.findTraditionalChars=fu;exports.firstAuthorText=qo;exports.flattenTitles=Rr;exports.flattenToc=Ul;exports.fmtCount=Ke;exports.formatHitCount=ci;exports.formatTemplate=gt;exports.formatVolumeRange=Ri;exports.getDisplayNameFromUrl=fn;exports.getMessages=bn;exports.getStartPage=qr;exports.getT=yn;exports.getTypeGroupKey=Gr;exports.groupRelatedWorks=ah;exports.gujiInlineToPlain=sc;exports.hasActiveFilters=fl;exports.hasGujiMarkdownV02=xh;exports.hasGujiTableNotation=Xh;exports.hasSearchOptions=Tu;exports.iiifVolumeOf=nx;exports.isCountedChar=_o;exports.isLayoutName=gp;exports.isThemeName=pp;exports.lineageHref=Gd;exports.loadRecentIds=Ut;exports.measureText=Bt;exports.mergeVolumeResources=Yr;exports.normalizeEra=nt;exports.normalizeLayout=Ui;exports.normalizeRole=lo;exports.normalizeTheme=Hi;exports.normalizeVolumeIndex=Ln;exports.normalizeVolumes=il;exports.numberToChinese=tc;exports.paginationItems=vd;exports.parseChineseNumber=fi;exports.parseGujiInline=oc;exports.parseGujiTable=wc;exports.parseSourceString=Xc;exports.pct=Zo;exports.periodLevel=Rd;exports.pickReaderVersion=Dl;exports.readStoredLayout=Hy;exports.readStoredTheme=Oy;exports.readerVersionOptionLabel=_r;exports.remapPlainOffsets=Lc;exports.removeRecentId=kl;exports.renderFullTextBody=sg;exports.renderProperNames=Ic;exports.renderReaderInline=wo;exports.resolveRecentEntry=eo;exports.resourceHref=xn;exports.resourceNote=Ii;exports.resultTabFromParam=Hu;exports.resultTabToParam=Du;exports.roleFacets=Jl;exports.rowNo=Oh;exports.sameFilters=Eu;exports.saveRecentId=vr;exports.segmentEntities=Ac;exports.shelfColumns=Nd;exports.sortFor=zu;exports.sortYear=xi;exports.spineHeight=Id;exports.splitFullTextTables=bo;exports.splitHighlightSnippet=Vr;exports.splitTableRow=kc;exports.storeLayout=Dy;exports.storeTheme=up;exports.stringifySources=Zc;exports.summaryFromEntry=Oc;exports.summaryFromItem=Wc;exports.timelineLayout=Yd;exports.toCatalogWorkCard=dy;exports.transportSummaryLoader=Fc;exports.typeSupportsFilters=xl;exports.useBidUrl=tt;exports.useChapterWarpData=Vc;exports.useConvert=Be;exports.useEntitySummaryLoader=Lo;exports.useI18n=ne;exports.useReaderPrefs=Hl;exports.useRecentEntries=Kd;exports.useT=Ee;exports.validateLineageGraph=Cb;exports.volumeStats=ki;exports.withDefaultLinks=Vt;exports.withMetaLinks=Gt;exports.yearText=vi;