book-index-ui 0.63.0 → 0.63.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var wu=Object.create;var Us=Object.defineProperty;var Su=Object.getOwnPropertyDescriptor;var _u=Object.getOwnPropertyNames;var $u=Object.getPrototypeOf,Cu=Object.prototype.hasOwnProperty;var zu=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of _u(n))!Cu.call(e,s)&&s!==i&&Us(e,s,{get:()=>n[s],enumerable:!(o=Su(n,s))||o.enumerable});return e};var fi=(e,n,i)=>(i=e!=null?wu($u(e)):{},zu(n||!e||!e.__esModule?Us(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ie=require("./storage-entry-Cx6j1zcJ.cjs"),t=require("react/jsx-runtime"),f=require("react"),Nu=require("opencc-js/t2cn"),Il=require("./variant-supplement.cjs"),Tu=require("react-markdown"),Iu=require("remark-gfm"),Eu=e=>`/item/${e}`,El=f.createContext(Eu);function Ru({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(El.Provider,{value:i,children:n})}function mt(){return f.useContext(El)}const Rl="",Ll="";function fo(e){const n=[];let i=!1,o=e;for(;o.length;){const s=i?Ll:Rl,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 yt(e,n){return{title:e,tokens:n}}const Vs='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Lu=[yt("基础(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"}}),yt("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),yt("提示与警告",{"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)"}}),yt("遮罩与阴影",{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)"}}),yt("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),yt("资源",{"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"}}),yt("整理本(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:"中性灰:占位"}}),yt("版本传承(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"}}),yt("编辑器视图(主要在 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")'}}),yt("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),yt('版式(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"}}),yt("阅读器(整理本 / 全文)",{"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:"版心外边线"}}),yt("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),yt("字体(全站无衬线,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:Vs,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Vs,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Au=Object.assign({},...Lu.map(e=>e.tokens)),Al={};for(const[e,n]of Object.entries(Au))Al[e]=`var(--bim-${e}, ${n.value})`;function r(e){const n=Al[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Gt(e){return e.types&&e.types.length>0?e.types:[]}function Mu(e,n){return Gt(e).includes(n)}const Pu={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 Bu={"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 $n(e){try{return Bu[new URL(e).hostname]}catch{return}}const Gs={text:0,image:1,physical:2};function ho(e){return e.length===0?"physical":[...e].sort((n,i)=>(Gs[n]??99)-(Gs[i]??99)).join("+")}function Ou(e){return e.includes("text")&&e.includes("image")?"text+image":e[0]||"physical"}function xo(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[g,m]=p,u=`${g}|${ho(Gt(c))}`;i.has(u)||i.set(u,{base:{...c,name:g,url:"",volumes:[]},volumes:[],indices:[]});const h=i.get(u);h.volumes.push({volume:m,url:c.url||void 0,status:"found"}),h.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 Ml(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 Pl(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||Ml(n)}))}function Li(e){const n=Pl(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 bo(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 yo(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 Cn(e){if(!e.url)return;const n=bo(e.metadata);return n?yo(e.url,n):e.url}const Bt=f.createContext(null),Bl=["曹霑"];function Wu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Fu(e,n=Bl){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(Wu).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 Mn=null;function Ol(){if(Mn)return Mn;try{const e=Nu.Converter({from:"t",to:"cn"});Mn=Fu(n=>e(Ie.normalizeVariants(n)))}catch{Mn=e=>e}return Mn}const Hu={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:"圖片資源"}},Du={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 kt(e,n,i){return{"zh-Hant":e,"zh-Hans":n}}const Uu=kt({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:"无数据"}),Ai=kt({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:"作品信息"}),Vu=kt({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:"附记"}}),Gu=kt({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:"種版本",sameEditionCopies:"同版另藏 {n} 部:",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:"种版本",sameEditionCopies:"同版另藏 {n} 部:",inferredEraNote:"部分年代据版本题名推断,非著录原文",empty:"尚未著录该作品的版本与书目收录。",relatedCount:"{n} 部",hasImage:"有影印",catalog:{meta:"历代书目 {n} 家",tablist:"著录书目",titleOnly:"仅著录书名,无提要。",prev:"上一家:{name}",next:"下一家:{name}"}}),Yu=kt({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:"上级丛编"}),qu=kt({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 為自動匹配,未經人工核對",sealAlt:"{name}印影",imgCredit:"圖像:{credit}",imgLicense:"授權:{license}",imgSource:"來源"},{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 为自动匹配,未经人工核对",sealAlt:"{name}印影",imgCredit:"图像:{credit}",imgLicense:"授权:{license}",imgSource:"来源"}),Ku=kt({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:"原字",scriptOrigUnavailable:"此文本沒有規範層,無「原字」可選",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}",tocExpand:"展開",tocCollapse:"收起",searchChapters:"搜索全部章節",searchChaptersPlaceholder:"搜索全部章節…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"來源",originalSource:"本站獨立整理",charGuess:"殘字(推測)",figLabel:"圖形符號:{alt}",figPlain:"圖形符號",lacunaGuess:"闕文,推測為「{guess}」",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:"原字",scriptOrigUnavailable:"此文本没有规范层,无「原字」可选",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}",tocExpand:"展开",tocCollapse:"收起",searchChapters:"搜索全部章节",searchChaptersPlaceholder:"搜索全部章节…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"来源",originalSource:"本站独立整理",charGuess:"残字(推测)",figLabel:"图形符号:{alt}",figPlain:"图形符号",lacunaGuess:"阙文,推测为「{guess}」",upstream:"上游",chapterFailed:"无法加载章节内容",references:"参考文献",entityDetail:"查看详情 →"}),Xu=kt({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:"本卷条目"}),Zu=kt({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:"古籍元數據以 CC BY-SA 4.0 發布,可自由複製、改編、再發布,但須註明出處,並以相同方式共享。",repo:"數據倉庫:",repoNote:"(GitHub,CC BY-SA 4.0)",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:"古籍元数据以 CC BY-SA 4.0 发布,可自由复制、改编、再发布,但须注明出处,并以相同方式共享。",repo:"数据仓库:",repoNote:"(GitHub,CC BY-SA 4.0)",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:"规模、存佚、许可与版本"}),jo=kt({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:"按作者浏览全部 →"}),Ju=kt({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} 条"}),Qu=kt({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:"搜索"}),em=kt({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:"回复"}),tm=kt({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:"有争议"}}),nm={common:Uu,detail:Ai,bookPage:Vu,workPage:Gu,collectionPage:Yu,entityPage:qu,reader:Ku,collated:Xu,metaHome:Zu,readHome:jo,catalogPage:Ju,searchPage:Qu,feedback:em,lineage:tm};function im(e){const n={};for(const[i,o]of Object.entries(nm))n[i]=o[e];return n}function $t(e,n){return e.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}const Ys=new Map;function zn(e){let n=Ys.get(e);return n||(n={...e==="zh-Hans"?Du:Hu,...im(e)},Ys.set(e,n)),n}function qs(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 Wl(e){return(n,i)=>{const o=qs(e,n)??qs(zn("zh-Hant"),n)??n;return i?$t(o,i):o}}const Ks=new Map;function Nn(e){let n=Ks.get(e);return n||(n=Wl(zn(e)),Ks.set(e,n)),n}const Fl="bim-locale";function rm(){try{const e=localStorage.getItem(Fl);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function om(e){try{localStorage.setItem(Fl,e)}catch{}}const sm="zh-Hans",am=({locale:e,onLocaleChange:n,converter:i,children:o})=>{const[s,a]=f.useState(e??sm),l=e??s;f.useEffect(()=>{if(e)return;const g=rm();g&&g!==s&&a(g)},[]);const d=f.useMemo(()=>l==="zh-Hans"?i??Ol():null,[l,i]),c=f.useCallback(g=>{a(g),om(g),n==null||n(g)},[n]),p=f.useMemo(()=>({locale:l,setLocale:c,messages:zn(l),converter:d}),[l,c,d]);return t.jsx(Bt.Provider,{value:p,children:o})};function Pe(){const e=f.useContext(Bt);return(e==null?void 0:e.messages)??zn("zh-Hant")}const lm=2e3;function De(){const e=f.useContext(Bt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,o=f.useRef(new Map),s=f.useRef(n),a=f.useRef(i);(s.current!==n||a.current!==i)&&(o.current.clear(),s.current=n,a.current=i);const l=f.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>=lm){const g=o.current.keys().next().value;g!==void 0&&o.current.delete(g)}return o.current.set(d,p),p},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function re(){const e=f.useContext(Bt),{convert:n,locale:i,isSimplified:o}=De(),s=(e==null?void 0:e.messages)??zn("zh-Hant"),a=f.useMemo(()=>e?Wl(s):Nn("zh-Hant"),[e,s]);return f.useMemo(()=>({t:a,convert:n,locale:i,isSimplified:o,messages:s}),[a,n,i,o,s])}const Hl=["錄說語詞議樣書記類傳國經補藝紀編後與間條號為開總種無數據冊頁選時題爲詩萬證學續關東圖資歷來讀館論見鈔別進師輯陳覽寫現應從","點兩華實對員長註結闕殘檢閱當會單換體將裡訂處過區釋術頭錢譯識個電動顯問這認質還幾遺雖須專擇係網運權務變發機請風聲輸軍導產","話們車難報讓業設帶辦紙氣麼際聽親場買賣謝費漢庫遷馬叢孫於張義晉閣維曆欽則夢慶齋録舊內陽樓紅淵歸載稱隱遼計評觀禮龜黃興節併","餘齊韓簡霑並樂諸滸屬組篩紹緒劉蘇誤職夾廣蓋敘斷歐寬駰極參試雜魯沒順線貞該測鮮統戰檔衛辭聯臺贊刪聖貫啟瀏譜薈寶約嘗諜謂舉詳","異賦軾復諒構級審標劃彙吳楊暫轉項寧硯蕭儀禪韻掃閉倉麗禎錯監鞏轍繫説筆竄縣聞諡賈僅擊羅宮訓談誌葉視戶細許祿繪鍵絕欄鑑講誕馮","趙習樹饋確賜裝擬規繼製薦畫鉛獨誠遠龍門覺訣隸軒諭繕塊爭鏡裏豐碼備掛堯錦駕鶴遊傷猶鄒瑩綴揚詔託僞頗竊虛莊歲禍爾辯獲篤窮盡跡","萊終穎訛瑣鐫繡廟幀佈躍雙預連狀態軸複懸遞灣箋頌訪層鏈敗達鈞鳳亂奮豈陰婁騎純優獻靈牆隨摺疊驗徑橫瀾蔣壞鈕盤範圍責減籤適側","榮聶頃縉讎銓廳軌厲鶚駢醫駝黨鐘諫樞滄軻溫贈鐵徵賴蹟潁閒顗歿駁歟勸諷誼湯詐脫羣尋澤擄顏釀謄鴻離騷傑滯憤執廢懼匱歎毀蠶獄寵闇","陸淺貨輕貧俠賤貴煩競樑鳩採綜謬鳴養堅韋顎呂蘭脈峯鵲兒賞籠階緊綱漁荊嬰慍潛營鎔繞陣塚億負卻塵懷閨擋撐縮領滾輪匯撈貼讚創險團","隊準礙強髒藥鮑顧給緯悅帳巖廬貢亞壇惡諱鎮薊驍愛討彌護揮偉輒擾況較響喪鑰藍"].join(""),cm=new Set([...Hl,...Object.keys(Ie.VARIANT_CHARS),...Object.keys(Il.VARIANT_SUPPLEMENT)]),Dl=[...Bl,"切換為繁體","漢籍リポジトリ"];function dm(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)=>{cm.has(a)&&o.push({char:a,context:s.slice(Math.max(0,l-8),l+9).join("")})}),o}function pm(e,n,i){return e?e==="orig"?null:n==="zh-Hans"?i??Ol():e==="hant"?Ie.normalizeVariants:i:n==="zh-Hans"?i:Ie.normalizeVariants}const um=({mode:e,children:n})=>{const i=f.useContext(Bt),o=f.useMemo(()=>i&&{...i,converter:pm(e,i.locale,i.converter)},[i,e]);return t.jsx(Bt.Provider,{value:o,children:n})};function mm(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 Xs(e){return e==="text+image"?["text","image"]:[e]}function Zs(e){const n=Gt(e);return n.length===0?"text":Ou(n)}function gm(){return{id:"",name:"",url:"",types:["text"],details:""}}const Br=({items:e,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const a=Pe(),[l,d]=f.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}],g=k=>{if(!s)return!0;const w=Gt(k);return s==="text"?w.includes("text"):s==="image"?w.includes("image")||w.includes("physical"):s==="physical"?w.includes("physical"):w.includes(s)},m=e.map((k,w)=>({item:k,originalIndex:w})).filter(({item:k})=>g(k)),u=()=>{const k=gm();s&&(k.types=Xs(s)),n([...e,k]),d(e.length)},h=k=>{n(e.filter((w,v)=>v!==k)),d(null)},x=(k,w,v)=>{const C=[...e];if(C[k]={...C[k],[w]:v},w==="url"&&!C[k].id){const $=mm(v);$&&(C[k].id=$)}n(C)},j=(k,w)=>{const v=[...e],{type:C,...$}=v[k];v[k]={...$,types:Xs(w)},n(v)},b=(k,w,v)=>{const $={...e[k].metadata||{}};v?$[w]=v:delete $[w],x(k,"metadata",Object.keys($).length>0?$:void 0)},_=(k,w)=>{const v=w.trim()?w.split(/[,,、]/).map(C=>C.trim()).filter(Boolean):void 0;x(k,"structure",v)},y=(k,w,v)=>{const $=e[k].coverage||{level:1,ranges:""};w==="level"?$.level=parseInt(v)||1:$.ranges=v,x(k,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[m.map(({item:k,originalIndex:w})=>{var v,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===w?null:w),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===w?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:fm(Zs(k)),color:r("on-color-fg")},children:(()=>{var R,N;const S=Gt(k);return S.length===0?"text":S.length===1?((R=c.find(z=>z.value===S[0]))==null?void 0:R.label)??S[0]:S.includes("text")&&S.includes("image")?((N=c.find(z=>z.value==="text+image"))==null?void 0:N.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:k.name||`${a.editor.resourcePlaceholder} ${w+1}`}),k.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:k.id}),k.url&&t.jsx("a",{href:k.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&k.url&&hm(w,o==null?void 0:o[w],i,a),t.jsx("button",{onClick:S=>{S.stopPropagation(),h(w)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:a.editor.deleteThisResource,children:"✕"})]}),l===w&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:[Mu(k,"image")&&k.url&&xm(k,a),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pn,children:[t.jsx("span",{style:Bn,children:a.label.type}),t.jsx("select",{value:Zs(k),onChange:S=>j(w,S.target.value),style:{...Lt,flex:1},children:c.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Pn,children:[t.jsx("span",{style:Bn,children:a.label.rootType}),t.jsx("select",{value:k.root_type||"catalog",onChange:S=>x(w,"root_type",S.target.value),style:{...Lt,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:k.id,onChange:S=>x(w,"id",S.target.value),placeholder:a.editor.idAutoExtract,style:{...Lt,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:k.name,onChange:S=>x(w,"name",S.target.value),placeholder:a.editor.resourceName,style:{...Lt,flex:1}})]}),t.jsx("input",{type:"text",value:k.url,onChange:S=>x(w,"url",S.target.value),placeholder:a.editor.resourceUrl,style:Lt}),t.jsx("input",{type:"text",value:((v=k.structure)==null?void 0:v.join("、"))||"",onChange:S=>_(w,S.target.value),placeholder:a.editor.structurePlaceholder,style:Lt}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pn,children:[t.jsx("span",{style:Bn,children:a.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((C=k.coverage)==null?void 0:C.level)??"",onChange:S=>y(w,"level",S.target.value),placeholder:"1",style:{...Lt,width:"60px"}})]}),t.jsxs("label",{style:{...Pn,flex:1},children:[t.jsx("span",{style:Bn,children:a.label.coverageRange}),t.jsx("input",{type:"text",value:(($=k.coverage)==null?void 0:$.ranges)||"",onChange:S=>y(w,"ranges",S.target.value),placeholder:a.editor.coverageRangePlaceholder,style:{...Lt,flex:1}})]})]}),t.jsx("textarea",{value:k.details||"",onChange:S=>x(w,"details",S.target.value),placeholder:a.editor.detailsPlaceholder,style:{...Lt,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,R])=>{var N;return t.jsxs("label",{style:{...Pn,gap:"4px"},children:[t.jsx("span",{style:{...Bn,minWidth:"56px"},children:R}),t.jsx("input",{type:"text",value:((N=k.metadata)==null?void 0:N[S])||"",onChange:z=>b(w,S,z.target.value),placeholder:R,style:{...Lt,flex:1}})]},S)})})]})]})]})]},w)}),t.jsxs("button",{onClick:u,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 fm(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 hm(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 xm(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 Lt={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"},Pn={display:"flex",alignItems:"center",gap:"6px"},Bn={fontSize:"12px",color:r("desc-fg"),whiteSpace:"nowrap"},Js={text:r("restype-text"),image:r("restype-image"),"text+image":r("restype-text-image"),physical:r("restype-physical")};function bm(e){return e.includes("text")&&e.includes("image")?Js["text+image"]:Js[e[0]||"physical"]}const vo=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const a=Pe(),{convert:l}=De(),d=f.useMemo(()=>xo(e||[]),[e]),{mirrorGroups:c,ungroupedItems:p}=f.useMemo(()=>{const b=new Map,_=[];for(const y of d){const k=y.group;k?(b.has(k)||b.set(k,[]),b.get(k).push(y)):_.push(y)}for(const y of b.values())y.sort((k,w)=>{const v=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return v(k)-v(w)});return{mirrorGroups:b,ungroupedItems:_}},[d]),g={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},m=b=>g[b]?g[b]:b.split("+").map(_=>g[_]||_).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((b,_)=>t.jsx(xr,{item:b},b.id||_))});const u=(b,_)=>{const y=i==null?void 0:i[b],k=(y==null?void 0:y.label)||b,w=y==null?void 0:y.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(k)}),w&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.5},children:l(w)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((v,C)=>t.jsx(xr,{item:v,onNavigate:o,renderLink:s},v.id||C))})]},`group-${b}`)},h=new Map;for(const b of p){const _=ho(Gt(b));h.has(_)||h.set(_,[]),h.get(_).push(b)}const x=["text","image","text+image","physical"],j=[...x.filter(b=>h.has(b)),...[...h.keys()].filter(b=>!x.includes(b)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([b,_])=>u(b,_)),j.map(b=>{const _=h.get(b),y=bm(b.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:y,whiteSpace:"nowrap",flexShrink:0},children:m(b)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((k,w)=>t.jsx(xr,{item:k,onNavigate:o,renderLink:s},k.id||w))})]},b)})]})},ym={bw:{label:"",bg:r("colormode-bw-bg"),fg:r("colormode-bw-fg")},color:{label:"",bg:r("colormode-color-bg"),fg:r("colormode-color-fg")}},xr=({item:e})=>{const n=Pe(),{convert:i}=De(),[o,s]=f.useState(!1),a=f.useMemo(()=>(e.url?$n(e.url):void 0)||i(e.name),[e.url,e.name,i]),l=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(x=>({...x,url:x.url||Ml(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,g=e.expected_volumes??(d?c+p:0),m=e.color_mode?{...ym[e.color_mode],label:n.colorMode[e.color_mode]}:null,u=e.details&&!d?i(e.details):null,h={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:h,children:[t.jsx("span",{style:{fontWeight:500},children:a}),m&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:m.bg,color:m.fg},children:m.label}),u&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:u}),d&&t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg")},children:[c,"/",g,n.unit.volume,p>0&&t.jsx("span",{style:{color:r("missing-fg"),marginLeft:"3px"},children:$t(n.common.volumesMissing,{n:p})})]}),e.url&&t.jsx("a",{href:(()=>{const x=bo(e.metadata);return x?yo(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 j=x.status==="missing";return x.url&&!j?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(j?"missing-fg":"desc-fg"),textDecoration:j?"line-through":"none",opacity:j?.6:1},children:x.volume},x.volume)})})]})},Ul=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:a,onSelectFolder:l})=>{const d=Pe(),c=e==="local",p=(n==null?void 0:n.isDraft)??!0,g=(n==null?void 0:n.repoPath)||"",m=g?g.split(/[/\\]/).pop()||g:"",u={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")},h={onMouseOver:j=>j.currentTarget.style.opacity="0.8",onMouseOut:j=>j.currentTarget.style.opacity="1"},x=t.jsxs("div",{onClick:s,title:p?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...u,background:r(p?"warning":"success"),color:r("on-color-fg")},...h,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:u,...h,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:g||d.mode.selectFolder,style:{...u,paddingLeft:"8px",paddingRight:"8px"},...h,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[x,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:o,title:d.mode.switchToLocal,style:u,...h,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:a,title:m||d.mode.configurePath,style:{...u,background:"transparent",padding:"6px",fontSize:"12px"},...h,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:u,...h,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:g||d.mode.selectFolder,style:{...u,paddingLeft:"8px",paddingRight:"8px",minWidth:g?"100px":"auto",justifyContent:"space-between"},...h,children:[t.jsx("span",{children:"📂"}),m&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:m})]}),!c&&m&&t.jsxs("div",{style:{...u,background:r("mode-active-bg"),color:r("on-color-fg"),cursor:"default"},title:g,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:m})]})]})},Mi="bim-search-history",Qs=10,ea=8;function Vn(){try{const e=localStorage.getItem(Mi);return e?JSON.parse(e):[]}catch{return[]}}function Vl(e){try{const n=Vn().filter(i=>i!==e);n.unshift(e),n.length>Qs&&(n.length=Qs),localStorage.setItem(Mi,JSON.stringify(n))}catch{}}function jm(e){try{const n=Vn().filter(i=>i!==e);localStorage.setItem(Mi,JSON.stringify(n))}catch{}}function vm(){try{localStorage.removeItem(Mi)}catch{}}const Gl=({transport:e,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:a})=>{const l=Pe(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,g]=f.useState(!1),[m,u]=f.useState([]),[h,x]=f.useState(-1),[j,b]=f.useState(Vn),_=f.useRef(null),y=f.useRef(null),k=f.useRef(null),w=f.useRef(!1);f.useEffect(()=>{x(-1);const z=n.trim();if(!z){u(j.map(A=>({type:"history",text:A})));return}if(!e.searchAll){u([]);return}let I=!1;const P=setTimeout(()=>{e.searchAll(z,ea).then(A=>{if(I)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];u(M.slice(0,ea).map(F=>({type:"entry",text:F.title||F.id,entry:F})))}).catch(()=>{I||u([])})},80);return()=>{I=!0,clearTimeout(P)}},[n,j,e]),f.useEffect(()=>{const z=I=>{k.current&&!k.current.contains(I.target)&&g(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[]),f.useEffect(()=>{const z=I=>{var P,A;if(I.key==="/"&&document.activeElement!==_.current){const M=(P=document.activeElement)==null?void 0:P.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;I.preventDefault(),(A=_.current)==null||A.focus()}};return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[]);const v=f.useCallback(z=>{z.trim()&&(Vl(z.trim()),b(Vn())),o(z),g(!1)},[o]),C=f.useCallback(z=>{z.type==="history"?(i(z.text),v(z.text)):z.entry&&(s?(s(z.entry),g(!1)):(i(z.text),v(z.text)))},[i,v,s]),$=f.useCallback(z=>{if(!p||m.length===0){z.key==="Enter"&&v(n);return}switch(z.key){case"ArrowDown":z.preventDefault(),x(I=>(I+1)%m.length);break;case"ArrowUp":z.preventDefault(),x(I=>(I-1+m.length)%m.length);break;case"Enter":z.preventDefault(),h>=0&&h<m.length?C(m[h]):v(n);break;case"Escape":z.preventDefault(),g(!1);break}},[p,m,h,n,v,C]),S=f.useCallback((z,I)=>{I.stopPropagation(),jm(z),b(Vn()),u(P=>P.filter(A=>!(A.type==="history"&&A.text===z)))},[]),R=f.useCallback(z=>{z.stopPropagation(),vm(),b([]),u([])},[]);f.useEffect(()=>{if(h>=0&&y.current){const z=y.current.children;z[h]&&z[h].scrollIntoView({block:"nearest"})}},[h]);const N=!n.trim()&&j.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:_,type:"text",placeholder:d,value:n,onChange:z=>{i(z.target.value),g(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{g(!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&&m.length>0&&t.jsxs("div",{ref:y,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:[N&&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:R,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),m.map((z,I)=>t.jsxs("div",{onClick:()=>C(z),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r("fg"),background:I===h?r("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:z.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.text}),z.entry&&t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg"),flexShrink:0},children:[c[z.entry.type],z.entry.edition&&` · ${z.entry.edition}`,z.entry.author&&` · ${z.entry.author}`]}),z.type==="history"&&t.jsx("button",{onClick:P=>S(z.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:"×"})]},`${z.type}-${z.text}-${I}`))]})]})},Tn=({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"}}),Yl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],km={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function gt(e){return km[e]??e}const kn=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],wn={熹平: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 Pi(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 wm(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Sm=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,ta={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function ko(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(ta))if(n.startsWith(s))return ta[s];const i=gt(n);if(an[i]!=null)return i;const o=Vt(n);if(o&&n.length<=o.length+1)return gt(o)}function sn(e,n){if(n){const i=ql[`${n}|${e}`];if(i!=null)return i}return wn[e]}const _m=1911;function $m(e){const n=wn[e];if(n==null)return;const i=Pt[e];let o;for(const[s,a]of Object.entries(wn))Pt[s]===i&&a>n&&(o==null||a<o)&&(o=a);return o!=null?o-1:void 0}const Cm={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Ci(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let n=0,i=0,o=!1;for(const a of e){const l=Cm[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 Vt(e){for(const n of Yl)if(e.startsWith(n))return n}const Pt={};{const e=(n,i)=>{for(const o of i)Pt[o]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function ln(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(wn))if(e.includes(o)&&!(i&&Pt[o]&&Pt[o]!==i&&ql[`${i}|${o}`]==null))return o}function Jn(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=Vt(o)??"";return{era:gt(p),reign:ln(o,p)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const p=Pi(s);if(p)return{era:wm(p.from),reign:"",source:"publication"};const g=Vt(s)??ko(s)??((c=kn.find(h=>h.pattern.test(s)))==null?void 0:c.era)??"",m=ln(s,g)??"",u=g||(m?Pt[m]??"":"");if(u||m)return{era:gt(u),reign:m,source:"publication"}}const a=e.edition||e.title||"";if(a){const p=Vt(a);if(p)return{era:gt(p),reign:ln(a,p)??"",source:"edition"};const g=kn.find(m=>m.pattern.test(a));if(g)return{era:gt(g.era),reign:ln(a,g.era)??g.reign??"",source:"edition"}}return n}function Bi(e){var o,s,a,l,d,c,p,g,m;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 u=Pi(n);if(u)return u.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 u of i){const h=((c=e.publication_info)==null?void 0:c.year)||((p=e.lineage)==null?void 0:p.year_text);if(h&&u!==h&&(Vt(h)||ko(h)))break;const x=u.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??u.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(x){const k=parseInt(x[1],10);if(k>=100&&k<=2100)return k}const j=u.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(j){const k=Vt(u);if(!k||gt(k)==="民國"){const v=Ci(j[1]);if(v!=null&&v>=1&&v<=120)return _m+v}}const b=Vt(u)??((g=kn.find(k=>k.pattern.test(u)))==null?void 0:g.era),_=b?gt(b):void 0,y=ln(u,_)??(Vt(u)||(m=kn.find(k=>k.pattern.test(u)))==null?void 0:m.reign);if(y){const k=sn(y,_);if(k==null)continue;const w=u.indexOf(y),v=w>=0?u.slice(w+y.length):"",C=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),$=C?Ci(C[1]):void 0;return k+($?$-1:0)}}}function wo(e){var l,d,c,p,g,m;const n=(l=e.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const 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 u=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(u){const h=Or[gt(u[1])],x=an[gt(u[2])];if(h!=null&&x!=null)return{from:Math.min(h,x)-20,to:Math.max(h,x)+40}}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const u=Pi(s);if((u==null?void 0:u.to)!=null)return{from:u.from,to:u.to};const h=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const x=Or[gt(h[1])],j=an[gt(h[2])];if(x!=null&&j!=null)return{from:Math.min(x,j)-20,to:Math.max(x,j)+40}}}const a=[(g=e.publication_info)==null?void 0:g.year,e.edition,e.title].filter(Boolean);for(const u of a){if(!/[間间]/.test(u))continue;const h=Vt(u)??ko(u)??((m=kn.find(b=>b.pattern.test(u)))==null?void 0:m.era),x=h?gt(h):void 0,j=[];for(const b of Object.keys(wn))u.includes(b)&&(x&&Pt[b]&&Pt[b]!==x||sn(b,x)!=null&&j.push(b));if(j.length===0){const b=u.match(/([一-鿿])([一-鿿])[間间]/);if(b&&x){for(const _ of[b[1],b[2]])for(const y of Object.keys(wn))if(Pt[y]===x&&!(y[0]!==_&&y[y.length-1]!==_)&&sn(y,x)!=null){j.push(y);break}}}if(j.length>0){const b=j.map(w=>sn(w,x)).filter(w=>w!=null),_=Math.min(...b),y=j.reduce((w,v)=>sn(w,x)>=sn(v,x)?w:v),k=$m(y)??br(x??"")??Math.max(...b);return{from:_,to:k>_?k:br(x??Pt[y]??"")??_}}if(x&&an[x]!=null)return{from:an[x],to:br(x)??an[x]}}}const an={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},zm=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Nm=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,na=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function ia(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)&&!ln(e.slice(o),gt(i)))continue}const s=gt(i);if(s===n)continue;const a=e.slice(o),l=ln(a,s)??"";let d;if(l){const c=sn(l,s);if(c!=null){const g=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),m=g?Ci(g[1]):void 0;d=c+(m?m-1:0)}}return{era:s,reign:l,year:d}}for(const i of kn)if(i.pattern.test(e))return{era:gt(i.era),reign:i.reign??""}}function Tm(e){var _,y,k,w,v;const n=Jn(e),i=((_=e.publication_info)==null?void 0:_.year)??"",o=i?Pi(i):void 0;if(!n.era&&!n.reign&&!o)return;const s=e.edition||e.title||"",a=/[間间]/.test(s),l=((y=e.lineage)==null?void 0:y.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),c=n.source==="publication"&&Sm.test(i),p=n.source==="publication"&&/[間间]/.test(i),g=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;a||d||c||p?m=void 0:g?m=parseInt(g[2],10):m=Bi(e);const u=m==null?wo(e):void 0;let h;n.source==="publication"&&(c||na.test(i))?h="uncertain":n.source==="lineage"||n.source==="publication"?h="attested":na.test(s)||!n.reign&&m==null?h="uncertain":h="inferred";const x=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??((w=e.lineage)==null?void 0:w.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,j={era:n.era,reign:n.reign,year:m,yearRange:u,certainty:h,source:n.source==="edition"?"edition":"catalog",basis:x};if(g){const C=l.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==j.era&&(j.laterRepair={era:C[1]})}if(!j.laterRepair&&Nm.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(j.laterRepair={era:C[1]})}const b=zm.find(C=>C.re.test(s));if(b){const C=s.search(b.re),$=s.slice(C),S=ia($,n.era)??ia(s,n.era);S&&(j.basedOn={era:S.era,reign:S.reign,year:S.year,relation:b.relation})}return j}const Or={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function br(e){return Or[e]}function zi(e){const n=Bi(e);if(n!=null)return n;const i=wo(e);if(i)return i.from;const o=Jn(e).era;return o?an[o]:void 0}const ra=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Wr(e){const n=ra.indexOf(e);return n===-1?ra.length:n}function Im(e){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of e){const a=s.relation;a==="part_of"?n.belongsTo.push(s):a==="collected_in"?n.collected.push(s):a==="has_part"||a==="contains_text_of"?n.contains.push(s):a==="text_carried_by"||a==="studied_by"||a==="derived_from"||a==="followed_by"||a==="has_adaptation"?n.derivative.push(s):a==="studies"||a==="preceded_by"?n.studies.push(s):n.related.push(s)}const 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 So(e,n){const i=xo(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((g,m)=>{const u=h=>h.group_role==="origin"?0:h.group_role==="mirror"?1:2;return u(g)-u(m)});const a={text:[],image:[],textImage:[],physical:[]};for(const p of s){const g=Gt(p),m=g.includes("text"),u=g.includes("image");m&&u?a.textImage.push(p):m?a.text.push(p):u?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,g])=>{var m,u;return{key:p,label:((m=n==null?void 0:n[p])==null?void 0:m.label)||p,description:(u=n==null?void 0:n[p])==null?void 0:u.description,items:g}});return{buckets:d,mirrors:c,total:i.length}}function Oi(e,n=Nn("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=Li(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(Oi(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""}const Em="同版";function Rm(e){const n=e==null?void 0:e.metadata;return((n==null?void 0:n.item_id)||(n==null?void 0:n.call_number)||"").trim()||void 0}function Lm(e){var n;for(const i of((n=e.lineage)==null?void 0:n.related_to)??[]){const o=i.ref??i.book_id;if(i.relation===Em&&o&&o!==e.id)return o}}function Am(e){const n=new Map(e.map(a=>[a.id,a])),i=a=>{const l=n.get(a);return!!l&&!l.copyOf},o=new Map;for(const a of e)if(a.copyOf&&i(a.copyOf)){const l=o.get(a.copyOf)??[];l.push(a),o.set(a.copyOf,l)}if(o.size===0)return e;const s=[];for(const a of e){if(a.copyOf&&i(a.copyOf))continue;const l=o.get(a.id);if(!l){s.push(a);continue}const d=[...l].sort((c,p)=>(c.callNumber??c.id).localeCompare(p.callNumber??p.id));s.push({...a,copies:d,hasImage:a.hasImage||d.some(c=>c.hasImage)})}return s}function Xl(e,n){var a,l;const i=e.resources||[],o=[],s=[];for(const d of i){const c=Gt(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:Jn(e),year:Bi(e),sortYear:zi(e),images:o,holders:s,locationName:(a=e.current_location)==null?void 0:a.name,callNumber:Rm(s[0]),copyOf:Lm(e),summary:e.summary,important:Mm(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:o.length>0}}function Mm(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=Am(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 g=c.r.sortYear,m=p.r.sortYear;return g!=null&&m!=null?g-m||c.i-p.i:g!=null?-1:m!=null?1:c.i-p.i}).map(c=>c.r):a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const g=m=>(m.important?0:1)*2+(m.hasImage?0:1);return g(c.r)-g(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)=>Wr(c)-Wr(p));return{rows:a,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function Pm(e,n){var b,_;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(b=n.collections)==null?void 0:b[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=y=>{if(c.has(y))return!0;const k=n.node_groups[y];return k!=null&&d.has(k)},g=[],m=new Map,u=[];for(const y of e)if(!((_=n.excluded_books)!=null&&_.includes(y)))if(p(y))g.push(y);else{const k=n.node_groups[y];k?(m.has(k)||m.set(k,[]),m.get(k).push(y)):u.push(y)}if(u.length+[...m.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const x=new Map((n.groups??[]).map(y=>[y.id,y])),j=[...m.entries()].map(([y,k])=>{const w=x.get(y);return{id:y,label:(w==null?void 0:w.label)??y,description:w==null?void 0:w.description,ids:k}});return u.length>0&&j.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:g,groupedIds:j}}const Jl=["撰","編","注","校","譯","繪","其他"],Bm=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function _o(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n)return"撰";for(const{cls:i,re:o}of Bm)if(o.test(n))return i;return"其他"}function $o(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=_o(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 Co(e){return(e._books??[]).map(n=>n.id).filter(n=>typeof n=="string")}function zo(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:Gn(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 Om(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 Gn(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 Wi(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 Wm=["〇","一","二","三","四","五","六","七","八","九"],oa=["","十","百","千"];function In(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return yr(e,!0);const n=Math.floor(e/1e4),i=e%1e4;let o=yr(n,!0)+"萬";return i>0&&(o+=(i<1e3?"〇":"")+yr(i,!1)),o}function yr(e,n){const i=String(e),o=i.length;let s="",a=!1;for(let l=0;l<o;l++){const d=parseInt(i[l]),c=o-1-l;d===0?a=!0:(a&&s&&(s+="〇"),a=!1,n&&d===1&&c===1&&l===0?s+=oa[c]:s+=Wm[d]+oa[c])}return s}function Fm(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function Hm(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 Yt(e,n="卷"){var o,s;const i=e;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?In(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 Fi={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},ic=new Set(["work","book","entity"]);function Dm(e){return sc(e)||!!e.sort}function Um(e,n){return n.sort&&ic.has(e)?n.sort:void 0}const Hi=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Di=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],rc=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],oc={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Ui(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 sc(e){return Ui(e)>0}function Vm(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 ac(e,n){const i=oc[e];return Vm(n).every(o=>i.has(o))}const On=e=>JSON.stringify(e);function Gm(e,n){if(!ac(n,e))return null;const i=[];if(e.dynasty.length){const o=Array.from(new Set(e.dynasty.flatMap(s=>{var a;return((a=Hi.find(l=>l.key===s))==null?void 0:a.values)??[]})));o.length===1?i.push(`dynasty = ${On(o[0])}`):o.length>1&&i.push(`dynasty IN [${o.map(On).join(", ")}]`)}return e.classification.length&&i.push(e.classification.length===1?`classification = ${On(e.classification[0])}`:`classification IN [${e.classification.map(On).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 = ${On(e.loss)}`),i.join(" AND ")}const bt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},lc="_";function Ni(e,n=new URLSearchParams){for(const i of Object.values(bt))n.delete(i);return e.dynasty.length&&n.set(bt.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(bt.classification,e.classification.map(i=>i||lc).join(",")),e.hasImage&&n.set(bt.hasImage,"1"),e.hasText&&n.set(bt.hasText,"1"),e.hasCollated&&n.set(bt.hasCollated,"1"),e.loss&&n.set(bt.loss,e.loss),e.sort&&n.set(bt.sort,e.sort),n}function Ym(e){const n=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),i=new Set(Hi.map(a=>a.key)),o=new Set(Di.map(a=>a.value)),s=e.get(bt.loss);return{dynasty:Array.from(new Set(n(bt.dynasty).filter(a=>i.has(a)))),classification:Array.from(new Set(n(bt.classification).map(a=>a===lc?"":a).filter(a=>o.has(a)))),hasImage:e.get(bt.hasImage)==="1",hasText:e.get(bt.hasText)==="1"||e.get(bt.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(bt.sort))??""}}function qm(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 sa(e,n){return e.includes(n)?e.filter(i=>i!==n):[...e,n]}const Km=({filters:e,onChange:n})=>{const i=Pe(),o=i.searchV4,{convert:s}=De(),[a,l]=f.useState(!1),d=f.useId(),c=Ui(e),p=g=>n({...e,...g});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(g=>!g),children:[t.jsxs("span",{children:[s(o.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:s($t(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:Hi.map(g=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(g.key),onClick:()=>p({dynasty:sa(e.dynasty,g.key)}),children:s(g.key)},g.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:s(o.classification)}),Di.map(g=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(g.value),onChange:()=>p({classification:sa(e.classification,g.value)})}),g.value?s(g.label):i.searchPage.unclassified]},g.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:g=>p({hasImage:g.target.checked})}),s(o.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:g=>p({hasText:g.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:rc.map(g=>t.jsx("button",{type:"button","aria-pressed":e.loss===g.value,onClick:()=>p({loss:g.value}),children:i.searchPage.loss[g.value||"all"]},g.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>n({...Fi,sort:e.sort}),children:s(o.clearAllFilters)})]})]})};function cc({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 aa=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Pe(),a=s.searchV4,{convert:l}=De(),d=mt();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),g=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${s.unit.juan}`:"",m=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${l(c.author)}${c.role&&c.role!=="author"?` ${l(c.role)}`:""}`:"",u=c.type==="book"?c.era??c.dynasty:c.dynasty,h=u?l(u):"",x=c.classification?l(c.classification):"",j=[];c.has_image&&j.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&j.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&j.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const b=[m,h,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(cc,{text:p,query:n?l(n):void 0})}),g&&t.jsx("span",{className:"bim-sr-measure",children:g})]}),b&&t.jsx("span",{className:"bim-sr-sub",children:b})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Tn,{type:c.type,size:6})," ",o(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:m||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:h||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:x||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:j.map(_=>t.jsx("span",{className:`bim-sr-tag ${_.cls}`,children:l(_.label)},_.label))})]},c.id)})})]})})},Xm=`
1
+ "use strict";var _u=Object.create;var Vs=Object.defineProperty;var $u=Object.getOwnPropertyDescriptor;var Cu=Object.getOwnPropertyNames;var zu=Object.getPrototypeOf,Nu=Object.prototype.hasOwnProperty;var Tu=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Cu(n))!Nu.call(e,s)&&s!==i&&Vs(e,s,{get:()=>n[s],enumerable:!(o=$u(n,s))||o.enumerable});return e};var hi=(e,n,i)=>(i=e!=null?_u(zu(e)):{},Tu(n||!e||!e.__esModule?Vs(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ee=require("./storage-entry-Cx6j1zcJ.cjs"),t=require("react/jsx-runtime"),f=require("react"),Eu=require("opencc-js/t2cn"),El=require("./variant-supplement.cjs"),Iu=require("react-markdown"),Ru=require("remark-gfm"),Lu=e=>`/item/${e}`,Il=f.createContext(Lu);function Au({buildUrl:e,children:n}){const i=f.useMemo(()=>e,[e]);return t.jsx(Il.Provider,{value:i,children:n})}function mt(){return f.useContext(Il)}const Rl="",Ll="";function ho(e){const n=[];let i=!1,o=e;for(;o.length;){const s=i?Ll:Rl,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 yt(e,n){return{title:e,tokens:n}}const Gs='"Songti SC", "Songti TC", STSong, "Noto Serif CJK SC", "Source Han Serif SC", SimSun, serif',Mu=[yt("基础(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"}}),yt("底色层次 / 文字与描边 / 链接",{"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:"彩色底(徽章、选中态按钮)上的文字"}}),yt("提示与警告",{"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)"}}),yt("遮罩与阴影",{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)"}}),yt("条目类型 / 状态徽章",{"type-book":{value:"#c0392b"},"type-work":{value:"#8e6f3e"},"type-collection":{value:"#2471a3"},"type-entity":{value:"#5b3e8e"},"status-draft":{value:"#e67e22"},"status-official":{value:"#27ae60"}}),yt("资源",{"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"}}),yt("整理本(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:"中性灰:占位"}}),yt("版本传承(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"}}),yt("编辑器视图(主要在 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")'}}),yt("详情页(作品 / 版本 / 丛编):宣纸 + 朱砂一套独立暖色,不继承 --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}}),yt('版式(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"}}),yt("阅读器(整理本 / 全文)",{"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:"版心外边线"}}),yt("反馈浮钮(2026-09-28 Q5)",{"feedback-fab-z":{value:"40",note:"层级:低于页面抽屉、弹层(本包对话框为 1000)"},"feedback-fab-offset":{value:"0px",root:!1}}),yt("字体(全站无衬线,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:Gs,note:"著录原文(提要、按语)用宋体"},"font-reading":{value:Gs,css:"var(--bim-font-serif)",note:"阅读器正文(整理本 / 全文);默认接 font-serif,只需覆盖那一个就同时换掉"}})],Pu=Object.assign({},...Mu.map(e=>e.tokens)),Al={};for(const[e,n]of Object.entries(Pu))Al[e]=`var(--bim-${e}, ${n.value})`;function r(e){const n=Al[e];if(n===void 0)throw new Error(`book-index-ui: 未定义的设计变量 --bim-${e}`);return n}function Gt(e){return e.types&&e.types.length>0?e.types:[]}function Bu(e,n){return Gt(e).includes(n)}const Ou={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 Wu={"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 $n(e){try{return Wu[new URL(e).hostname]}catch{return}}const Ys={text:0,image:1,physical:2};function xo(e){return e.length===0?"physical":[...e].sort((n,i)=>(Ys[n]??99)-(Ys[i]??99)).join("+")}function Fu(e){return e.includes("text")&&e.includes("image")?"text+image":e[0]||"physical"}function bo(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,g]=p,u=`${m}|${xo(Gt(c))}`;i.has(u)||i.set(u,{base:{...c,name:m,url:"",volumes:[]},volumes:[],indices:[]});const h=i.get(u);h.volumes.push({volume:g,url:c.url||void 0,status:"found"}),h.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 Ml(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 Pl(e){return!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(n=>({...n,url:n.url||Ml(n)}))}function Ai(e){const n=Pl(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 yo(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 jo(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 Cn(e){if(!e.url)return;const n=yo(e.metadata);return n?jo(e.url,n):e.url}const Bt=f.createContext(null),Bl=["曹霑"];function Hu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Du(e,n=Bl){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(Hu).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 Mn=null;function Ol(){if(Mn)return Mn;try{const e=Eu.Converter({from:"t",to:"cn"});Mn=Du(n=>e(Ee.normalizeVariants(n)))}catch{Mn=e=>e}return Mn}const Uu={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:"圖片資源"}},Vu={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 kt(e,n,i){return{"zh-Hant":e,"zh-Hans":n}}const Gu=kt({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:"无数据"}),Mi=kt({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:"作品信息"}),Yu=kt({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:"附记"}}),qu=kt({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:"種版本",sameEditionCopies:"同版另藏 {n} 部:",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:"种版本",sameEditionCopies:"同版另藏 {n} 部:",inferredEraNote:"部分年代据版本题名推断,非著录原文",empty:"尚未著录该作品的版本与书目收录。",relatedCount:"{n} 部",hasImage:"有影印",catalog:{meta:"历代书目 {n} 家",tablist:"著录书目",titleOnly:"仅著录书名,无提要。",prev:"上一家:{name}",next:"下一家:{name}"}}),Ku=kt({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:"上级丛编"}),Xu=kt({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 為自動匹配,未經人工核對",sealAlt:"{name}印影",imgCredit:"圖像:{credit}",imgLicense:"授權:{license}",imgSource:"來源"},{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 为自动匹配,未经人工核对",sealAlt:"{name}印影",imgCredit:"图像:{credit}",imgLicense:"授权:{license}",imgSource:"来源"}),Zu=kt({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:"原字",scriptOrigUnavailable:"此文本沒有規範層,無「原字」可選",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}",tocExpand:"展開",tocCollapse:"收起",searchChapters:"搜索全部章節",searchChaptersPlaceholder:"搜索全部章節…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"來源",originalSource:"本站獨立整理",charGuess:"殘字(推測)",figLabel:"圖形符號:{alt}",figPlain:"圖形符號",lacunaGuess:"闕文,推測為「{guess}」",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:"原字",scriptOrigUnavailable:"此文本没有规范层,无「原字」可选",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}",tocExpand:"展开",tocCollapse:"收起",searchChapters:"搜索全部章节",searchChaptersPlaceholder:"搜索全部章节…",searchUnit:"搜索全部{unit}",searchUnitPlaceholder:"搜索全部{unit}…",textSource:"来源",originalSource:"本站独立整理",charGuess:"残字(推测)",figLabel:"图形符号:{alt}",figPlain:"图形符号",lacunaGuess:"阙文,推测为「{guess}」",upstream:"上游",chapterFailed:"无法加载章节内容",references:"参考文献",entityDetail:"查看详情 →"}),Ju=kt({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:"本卷条目"}),Qu=kt({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:"古籍元數據以 CC BY-SA 4.0 發布,可自由複製、改編、再發布,但須註明出處,並以相同方式共享。",repo:"數據倉庫:",repoNote:"(GitHub,CC BY-SA 4.0)",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:"古籍元数据以 CC BY-SA 4.0 发布,可自由复制、改编、再发布,但须注明出处,并以相同方式共享。",repo:"数据仓库:",repoNote:"(GitHub,CC BY-SA 4.0)",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:"规模、存佚、许可与版本"}),vo=kt({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:"按作者浏览全部 →"}),em=kt({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} 条"}),tm=kt({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:"搜索"}),nm=kt({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:"回复"}),im=kt({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:"有争议"}}),rm={common:Gu,detail:Mi,bookPage:Yu,workPage:qu,collectionPage:Ku,entityPage:Xu,reader:Zu,collated:Ju,metaHome:Qu,readHome:vo,catalogPage:em,searchPage:tm,feedback:nm,lineage:im};function om(e){const n={};for(const[i,o]of Object.entries(rm))n[i]=o[e];return n}function $t(e,n){return e.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}const qs=new Map;function zn(e){let n=qs.get(e);return n||(n={...e==="zh-Hans"?Vu:Uu,...om(e)},qs.set(e,n)),n}function Ks(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 Wl(e){return(n,i)=>{const o=Ks(e,n)??Ks(zn("zh-Hant"),n)??n;return i?$t(o,i):o}}const Xs=new Map;function Nn(e){let n=Xs.get(e);return n||(n=Wl(zn(e)),Xs.set(e,n)),n}const Fl="bim-locale";function sm(){try{const e=localStorage.getItem(Fl);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function am(e){try{localStorage.setItem(Fl,e)}catch{}}const lm="zh-Hans",cm=({locale:e,onLocaleChange:n,converter:i,children:o})=>{const[s,a]=f.useState(e??lm),l=e??s;f.useEffect(()=>{if(e)return;const m=sm();m&&m!==s&&a(m)},[]);const d=f.useMemo(()=>l==="zh-Hans"?i??Ol():null,[l,i]),c=f.useCallback(m=>{a(m),am(m),n==null||n(m)},[n]),p=f.useMemo(()=>({locale:l,setLocale:c,messages:zn(l),converter:d}),[l,c,d]);return t.jsx(Bt.Provider,{value:p,children:o})};function Pe(){const e=f.useContext(Bt);return(e==null?void 0:e.messages)??zn("zh-Hant")}const dm=2e3;function De(){const e=f.useContext(Bt),n=(e==null?void 0:e.locale)??"zh-Hant",i=(e==null?void 0:e.converter)??null,o=f.useRef(new Map),s=f.useRef(n),a=f.useRef(i);(s.current!==n||a.current!==i)&&(o.current.clear(),s.current=n,a.current=i);const l=f.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>=dm){const m=o.current.keys().next().value;m!==void 0&&o.current.delete(m)}return o.current.set(d,p),p},[i]);return f.useMemo(()=>({convert:l,locale:n,isSimplified:n==="zh-Hans"}),[l,n])}function ie(){const e=f.useContext(Bt),{convert:n,locale:i,isSimplified:o}=De(),s=(e==null?void 0:e.messages)??zn("zh-Hant"),a=f.useMemo(()=>e?Wl(s):Nn("zh-Hant"),[e,s]);return f.useMemo(()=>({t:a,convert:n,locale:i,isSimplified:o,messages:s}),[a,n,i,o,s])}const Hl=["錄說語詞議樣書記類傳國經補藝紀編後與間條號為開總種無數據冊頁選時題爲詩萬證學續關東圖資歷來讀館論見鈔別進師輯陳覽寫現應從","點兩華實對員長註結闕殘檢閱當會單換體將裡訂處過區釋術頭錢譯識個電動顯問這認質還幾遺雖須專擇係網運權務變發機請風聲輸軍導產","話們車難報讓業設帶辦紙氣麼際聽親場買賣謝費漢庫遷馬叢孫於張義晉閣維曆欽則夢慶齋録舊內陽樓紅淵歸載稱隱遼計評觀禮龜黃興節併","餘齊韓簡霑並樂諸滸屬組篩紹緒劉蘇誤職夾廣蓋敘斷歐寬駰極參試雜魯沒順線貞該測鮮統戰檔衛辭聯臺贊刪聖貫啟瀏譜薈寶約嘗諜謂舉詳","異賦軾復諒構級審標劃彙吳楊暫轉項寧硯蕭儀禪韻掃閉倉麗禎錯監鞏轍繫説筆竄縣聞諡賈僅擊羅宮訓談誌葉視戶細許祿繪鍵絕欄鑑講誕馮","趙習樹饋確賜裝擬規繼製薦畫鉛獨誠遠龍門覺訣隸軒諭繕塊爭鏡裏豐碼備掛堯錦駕鶴遊傷猶鄒瑩綴揚詔託僞頗竊虛莊歲禍爾辯獲篤窮盡跡","萊終穎訛瑣鐫繡廟幀佈躍雙預連狀態軸複懸遞灣箋頌訪層鏈敗達鈞鳳亂奮豈陰婁騎純優獻靈牆隨摺疊驗徑橫瀾蔣壞鈕盤範圍責減籤適側","榮聶頃縉讎銓廳軌厲鶚駢醫駝黨鐘諫樞滄軻溫贈鐵徵賴蹟潁閒顗歿駁歟勸諷誼湯詐脫羣尋澤擄顏釀謄鴻離騷傑滯憤執廢懼匱歎毀蠶獄寵闇","陸淺貨輕貧俠賤貴煩競樑鳩採綜謬鳴養堅韋顎呂蘭脈峯鵲兒賞籠階緊綱漁荊嬰慍潛營鎔繞陣塚億負卻塵懷閨擋撐縮領滾輪匯撈貼讚創險團","隊準礙強髒藥鮑顧給緯悅帳巖廬貢亞壇惡諱鎮薊驍愛討彌護揮偉輒擾況較響喪鑰藍"].join(""),pm=new Set([...Hl,...Object.keys(Ee.VARIANT_CHARS),...Object.keys(El.VARIANT_SUPPLEMENT)]),Dl=[...Bl,"切換為繁體","漢籍リポジトリ"];function um(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)=>{pm.has(a)&&o.push({char:a,context:s.slice(Math.max(0,l-8),l+9).join("")})}),o}function mm(e,n,i){return e?e==="orig"?null:n==="zh-Hans"?i??Ol():e==="hant"?Ee.normalizeVariants:i:n==="zh-Hans"?i:Ee.normalizeVariants}const gm=({mode:e,children:n})=>{const i=f.useContext(Bt),o=f.useMemo(()=>i&&{...i,converter:mm(e,i.locale,i.converter)},[i,e]);return t.jsx(Bt.Provider,{value:o,children:n})};function fm(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 Zs(e){return e==="text+image"?["text","image"]:[e]}function Js(e){const n=Gt(e);return n.length===0?"text":Fu(n)}function hm(){return{id:"",name:"",url:"",types:["text"],details:""}}const Or=({items:e,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const a=Pe(),[l,d]=f.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=k=>{if(!s)return!0;const w=Gt(k);return s==="text"?w.includes("text"):s==="image"?w.includes("image")||w.includes("physical"):s==="physical"?w.includes("physical"):w.includes(s)},g=e.map((k,w)=>({item:k,originalIndex:w})).filter(({item:k})=>m(k)),u=()=>{const k=hm();s&&(k.types=Zs(s)),n([...e,k]),d(e.length)},h=k=>{n(e.filter((w,v)=>v!==k)),d(null)},x=(k,w,v)=>{const C=[...e];if(C[k]={...C[k],[w]:v},w==="url"&&!C[k].id){const $=fm(v);$&&(C[k].id=$)}n(C)},j=(k,w)=>{const v=[...e],{type:C,...$}=v[k];v[k]={...$,types:Zs(w)},n(v)},b=(k,w,v)=>{const $={...e[k].metadata||{}};v?$[w]=v:delete $[w],x(k,"metadata",Object.keys($).length>0?$:void 0)},_=(k,w)=>{const v=w.trim()?w.split(/[,,、]/).map(C=>C.trim()).filter(Boolean):void 0;x(k,"structure",v)},y=(k,w,v)=>{const $=e[k].coverage||{level:1,ranges:""};w==="level"?$.level=parseInt(v)||1:$.ranges=v,x(k,"coverage",$.ranges?$:void 0)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[g.map(({item:k,originalIndex:w})=>{var v,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===w?null:w),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===w?"▼":"▶"}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:xm(Js(k)),color:r("on-color-fg")},children:(()=>{var I,N;const S=Gt(k);return S.length===0?"text":S.length===1?((I=c.find(z=>z.value===S[0]))==null?void 0:I.label)??S[0]:S.includes("text")&&S.includes("image")?((N=c.find(z=>z.value==="text+image"))==null?void 0:N.label)??"text+image":S.join("+")})()}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:k.name||`${a.editor.resourcePlaceholder} ${w+1}`}),k.id&&t.jsx("span",{style:{fontSize:"11px",opacity:.5},children:k.id}),k.url&&t.jsx("a",{href:k.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&k.url&&bm(w,o==null?void 0:o[w],i,a),t.jsx("button",{onClick:S=>{S.stopPropagation(),h(w)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:a.editor.deleteThisResource,children:"✕"})]}),l===w&&t.jsxs("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:[Bu(k,"image")&&k.url&&ym(k,a),t.jsxs("div",{style:{display:"grid",gap:"8px"},children:[t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pn,children:[t.jsx("span",{style:Bn,children:a.label.type}),t.jsx("select",{value:Js(k),onChange:S=>j(w,S.target.value),style:{...Lt,flex:1},children:c.map(S=>t.jsx("option",{value:S.value,children:S.label},S.value))})]}),t.jsxs("label",{style:Pn,children:[t.jsx("span",{style:Bn,children:a.label.rootType}),t.jsx("select",{value:k.root_type||"catalog",onChange:S=>x(w,"root_type",S.target.value),style:{...Lt,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:k.id,onChange:S=>x(w,"id",S.target.value),placeholder:a.editor.idAutoExtract,style:{...Lt,width:"140px",flexShrink:0}}),t.jsx("input",{type:"text",value:k.name,onChange:S=>x(w,"name",S.target.value),placeholder:a.editor.resourceName,style:{...Lt,flex:1}})]}),t.jsx("input",{type:"text",value:k.url,onChange:S=>x(w,"url",S.target.value),placeholder:a.editor.resourceUrl,style:Lt}),t.jsx("input",{type:"text",value:((v=k.structure)==null?void 0:v.join("、"))||"",onChange:S=>_(w,S.target.value),placeholder:a.editor.structurePlaceholder,style:Lt}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[t.jsxs("label",{style:Pn,children:[t.jsx("span",{style:Bn,children:a.label.coverageLevel}),t.jsx("input",{type:"number",min:1,value:((C=k.coverage)==null?void 0:C.level)??"",onChange:S=>y(w,"level",S.target.value),placeholder:"1",style:{...Lt,width:"60px"}})]}),t.jsxs("label",{style:{...Pn,flex:1},children:[t.jsx("span",{style:Bn,children:a.label.coverageRange}),t.jsx("input",{type:"text",value:(($=k.coverage)==null?void 0:$.ranges)||"",onChange:S=>y(w,"ranges",S.target.value),placeholder:a.editor.coverageRangePlaceholder,style:{...Lt,flex:1}})]})]}),t.jsx("textarea",{value:k.details||"",onChange:S=>x(w,"details",S.target.value),placeholder:a.editor.detailsPlaceholder,style:{...Lt,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,I])=>{var N;return t.jsxs("label",{style:{...Pn,gap:"4px"},children:[t.jsx("span",{style:{...Bn,minWidth:"56px"},children:I}),t.jsx("input",{type:"text",value:((N=k.metadata)==null?void 0:N[S])||"",onChange:z=>b(w,S,z.target.value),placeholder:I,style:{...Lt,flex:1}})]},S)})})]})]})]})]},w)}),t.jsxs("button",{onClick:u,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 xm(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 bm(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 ym(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 Lt={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"},Pn={display:"flex",alignItems:"center",gap:"6px"},Bn={fontSize:"12px",color:r("desc-fg"),whiteSpace:"nowrap"},Qs={text:r("restype-text"),image:r("restype-image"),"text+image":r("restype-text-image"),physical:r("restype-physical")};function jm(e){return e.includes("text")&&e.includes("image")?Qs["text+image"]:Qs[e[0]||"physical"]}const ko=({items:e,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const a=Pe(),{convert:l}=De(),d=f.useMemo(()=>bo(e||[]),[e]),{mirrorGroups:c,ungroupedItems:p}=f.useMemo(()=>{const b=new Map,_=[];for(const y of d){const k=y.group;k?(b.has(k)||b.set(k,[]),b.get(k).push(y)):_.push(y)}for(const y of b.values())y.sort((k,w)=>{const v=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return v(k)-v(w)});return{mirrorGroups:b,ungroupedItems:_}},[d]),m={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},g=b=>m[b]?m[b]:b.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((b,_)=>t.jsx(br,{item:b},b.id||_))});const u=(b,_)=>{const y=i==null?void 0:i[b],k=(y==null?void 0:y.label)||b,w=y==null?void 0:y.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(k)}),w&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.5},children:l(w)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((v,C)=>t.jsx(br,{item:v,onNavigate:o,renderLink:s},v.id||C))})]},`group-${b}`)},h=new Map;for(const b of p){const _=xo(Gt(b));h.has(_)||h.set(_,[]),h.get(_).push(b)}const x=["text","image","text+image","physical"],j=[...x.filter(b=>h.has(b)),...[...h.keys()].filter(b=>!x.includes(b)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([b,_])=>u(b,_)),j.map(b=>{const _=h.get(b),y=jm(b.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:y,whiteSpace:"nowrap",flexShrink:0},children:g(b)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:_.map((k,w)=>t.jsx(br,{item:k,onNavigate:o,renderLink:s},k.id||w))})]},b)})]})},vm={bw:{label:"",bg:r("colormode-bw-bg"),fg:r("colormode-bw-fg")},color:{label:"",bg:r("colormode-color-bg"),fg:r("colormode-color-fg")}},br=({item:e})=>{const n=Pe(),{convert:i}=De(),[o,s]=f.useState(!1),a=f.useMemo(()=>(e.url?$n(e.url):void 0)||i(e.name),[e.url,e.name,i]),l=f.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(x=>({...x,url:x.url||Ml(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),g=e.color_mode?{...vm[e.color_mode],label:n.colorMode[e.color_mode]}:null,u=e.details&&!d?i(e.details):null,h={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:h,children:[t.jsx("span",{style:{fontWeight:500},children:a}),g&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:g.bg,color:g.fg},children:g.label}),u&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:u}),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:$t(n.common.volumesMissing,{n:p})})]}),e.url&&t.jsx("a",{href:(()=>{const x=yo(e.metadata);return x?jo(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 j=x.status==="missing";return x.url&&!j?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(j?"missing-fg":"desc-fg"),textDecoration:j?"line-through":"none",opacity:j?.6:1},children:x.volume},x.volume)})})]})},Ul=({indexSource:e,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:a,onSelectFolder:l})=>{const d=Pe(),c=e==="local",p=(n==null?void 0:n.isDraft)??!0,m=(n==null?void 0:n.repoPath)||"",g=m?m.split(/[/\\]/).pop()||m:"",u={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")},h={onMouseOver:j=>j.currentTarget.style.opacity="0.8",onMouseOut:j=>j.currentTarget.style.opacity="1"},x=t.jsxs("div",{onClick:s,title:p?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...u,background:r(p?"warning":"success"),color:r("on-color-fg")},...h,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:u,...h,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:{...u,paddingLeft:"8px",paddingRight:"8px"},...h,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]})]}):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:u,...h,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:g||d.mode.configurePath,style:{...u,background:"transparent",padding:"6px",fontSize:"12px"},...h,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:u,...h,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:{...u,paddingLeft:"8px",paddingRight:"8px",minWidth:m?"100px":"auto",justifyContent:"space-between"},...h,children:[t.jsx("span",{children:"📂"}),g&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:g})]}),!c&&g&&t.jsxs("div",{style:{...u,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:g})]})]})},Pi="bim-search-history",ea=10,ta=8;function Vn(){try{const e=localStorage.getItem(Pi);return e?JSON.parse(e):[]}catch{return[]}}function Vl(e){try{const n=Vn().filter(i=>i!==e);n.unshift(e),n.length>ea&&(n.length=ea),localStorage.setItem(Pi,JSON.stringify(n))}catch{}}function km(e){try{const n=Vn().filter(i=>i!==e);localStorage.setItem(Pi,JSON.stringify(n))}catch{}}function wm(){try{localStorage.removeItem(Pi)}catch{}}const Gl=({transport:e,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:a})=>{const l=Pe(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[p,m]=f.useState(!1),[g,u]=f.useState([]),[h,x]=f.useState(-1),[j,b]=f.useState(Vn),_=f.useRef(null),y=f.useRef(null),k=f.useRef(null),w=f.useRef(!1);f.useEffect(()=>{x(-1);const z=n.trim();if(!z){u(j.map(A=>({type:"history",text:A})));return}if(!e.searchAll){u([]);return}let E=!1;const P=setTimeout(()=>{e.searchAll(z,ta).then(A=>{if(E)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];u(M.slice(0,ta).map(F=>({type:"entry",text:F.title||F.id,entry:F})))}).catch(()=>{E||u([])})},80);return()=>{E=!0,clearTimeout(P)}},[n,j,e]),f.useEffect(()=>{const z=E=>{k.current&&!k.current.contains(E.target)&&m(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[]),f.useEffect(()=>{const z=E=>{var P,A;if(E.key==="/"&&document.activeElement!==_.current){const M=(P=document.activeElement)==null?void 0:P.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;E.preventDefault(),(A=_.current)==null||A.focus()}};return document.addEventListener("keydown",z),()=>document.removeEventListener("keydown",z)},[]);const v=f.useCallback(z=>{z.trim()&&(Vl(z.trim()),b(Vn())),o(z),m(!1)},[o]),C=f.useCallback(z=>{z.type==="history"?(i(z.text),v(z.text)):z.entry&&(s?(s(z.entry),m(!1)):(i(z.text),v(z.text)))},[i,v,s]),$=f.useCallback(z=>{if(!p||g.length===0){z.key==="Enter"&&v(n);return}switch(z.key){case"ArrowDown":z.preventDefault(),x(E=>(E+1)%g.length);break;case"ArrowUp":z.preventDefault(),x(E=>(E-1+g.length)%g.length);break;case"Enter":z.preventDefault(),h>=0&&h<g.length?C(g[h]):v(n);break;case"Escape":z.preventDefault(),m(!1);break}},[p,g,h,n,v,C]),S=f.useCallback((z,E)=>{E.stopPropagation(),km(z),b(Vn()),u(P=>P.filter(A=>!(A.type==="history"&&A.text===z)))},[]),I=f.useCallback(z=>{z.stopPropagation(),wm(),b([]),u([])},[]);f.useEffect(()=>{if(h>=0&&y.current){const z=y.current.children;z[h]&&z[h].scrollIntoView({block:"nearest"})}},[h]);const N=!n.trim()&&j.length>0;return t.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:_,type:"text",placeholder:d,value:n,onChange:z=>{i(z.target.value),m(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.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&&g.length>0&&t.jsxs("div",{ref:y,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:[N&&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:I,style:{border:"none",background:"transparent",color:r("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),g.map((z,E)=>t.jsxs("div",{onClick:()=>C(z),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r("fg"),background:E===h?r("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:z.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:z.text}),z.entry&&t.jsxs("span",{style:{fontSize:"11px",color:r("desc-fg"),flexShrink:0},children:[c[z.entry.type],z.entry.edition&&` · ${z.entry.edition}`,z.entry.author&&` · ${z.entry.author}`]}),z.type==="history"&&t.jsx("button",{onClick:P=>S(z.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:"×"})]},`${z.type}-${z.text}-${E}`))]})]})},Tn=({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"}}),Yl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Sm={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function gt(e){return Sm[e]??e}const kn=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],wn={熹平: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 Bi(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 _m(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const $m=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,na={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function wo(e){const n=e.trim().replace(/[代朝]$/,"");for(const s of Object.keys(na))if(n.startsWith(s))return na[s];const i=gt(n);if(an[i]!=null)return i;const o=Vt(n);if(o&&n.length<=o.length+1)return gt(o)}function sn(e,n){if(n){const i=ql[`${n}|${e}`];if(i!=null)return i}return wn[e]}const Cm=1911;function zm(e){const n=wn[e];if(n==null)return;const i=Pt[e];let o;for(const[s,a]of Object.entries(wn))Pt[s]===i&&a>n&&(o==null||a<o)&&(o=a);return o!=null?o-1:void 0}const Nm={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function zi(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=Nm[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 Vt(e){for(const n of Yl)if(e.startsWith(n))return n}const Pt={};{const e=(n,i)=>{for(const o of i)Pt[o]=n};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function ln(e,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(wn))if(e.includes(o)&&!(i&&Pt[o]&&Pt[o]!==i&&ql[`${i}|${o}`]==null))return o}function Qn(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=Vt(o)??"";return{era:gt(p),reign:ln(o,p)??"",source:"lineage"}}const s=(d=e.publication_info)==null?void 0:d.year;if(s){const p=Bi(s);if(p)return{era:_m(p.from),reign:"",source:"publication"};const m=Vt(s)??wo(s)??((c=kn.find(h=>h.pattern.test(s)))==null?void 0:c.era)??"",g=ln(s,m)??"",u=m||(g?Pt[g]??"":"");if(u||g)return{era:gt(u),reign:g,source:"publication"}}const a=e.edition||e.title||"";if(a){const p=Vt(a);if(p)return{era:gt(p),reign:ln(a,p)??"",source:"edition"};const m=kn.find(g=>g.pattern.test(a));if(m)return{era:gt(m.era),reign:ln(a,m.era)??m.reign??"",source:"edition"}}return n}function Oi(e){var o,s,a,l,d,c,p,m,g;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 u=Bi(n);if(u)return u.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 u of i){const h=((c=e.publication_info)==null?void 0:c.year)||((p=e.lineage)==null?void 0:p.year_text);if(h&&u!==h&&(Vt(h)||wo(h)))break;const x=u.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??u.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(x){const k=parseInt(x[1],10);if(k>=100&&k<=2100)return k}const j=u.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(j){const k=Vt(u);if(!k||gt(k)==="民國"){const v=zi(j[1]);if(v!=null&&v>=1&&v<=120)return Cm+v}}const b=Vt(u)??((m=kn.find(k=>k.pattern.test(u)))==null?void 0:m.era),_=b?gt(b):void 0,y=ln(u,_)??(Vt(u)||(g=kn.find(k=>k.pattern.test(u)))==null?void 0:g.reign);if(y){const k=sn(y,_);if(k==null)continue;const w=u.indexOf(y),v=w>=0?u.slice(w+y.length):"",C=v.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??v.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),$=C?zi(C[1]):void 0;return k+($?$-1:0)}}}function So(e){var l,d,c,p,m,g;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 u=o.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(u){const h=Wr[gt(u[1])],x=an[gt(u[2])];if(h!=null&&x!=null)return{from:Math.min(h,x)-20,to:Math.max(h,x)+40}}}const s=(p=e.publication_info)==null?void 0:p.year;if(s){const u=Bi(s);if((u==null?void 0:u.to)!=null)return{from:u.from,to:u.to};const h=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(h){const x=Wr[gt(h[1])],j=an[gt(h[2])];if(x!=null&&j!=null)return{from:Math.min(x,j)-20,to:Math.max(x,j)+40}}}const a=[(m=e.publication_info)==null?void 0:m.year,e.edition,e.title].filter(Boolean);for(const u of a){if(!/[間间]/.test(u))continue;const h=Vt(u)??wo(u)??((g=kn.find(b=>b.pattern.test(u)))==null?void 0:g.era),x=h?gt(h):void 0,j=[];for(const b of Object.keys(wn))u.includes(b)&&(x&&Pt[b]&&Pt[b]!==x||sn(b,x)!=null&&j.push(b));if(j.length===0){const b=u.match(/([一-鿿])([一-鿿])[間间]/);if(b&&x){for(const _ of[b[1],b[2]])for(const y of Object.keys(wn))if(Pt[y]===x&&!(y[0]!==_&&y[y.length-1]!==_)&&sn(y,x)!=null){j.push(y);break}}}if(j.length>0){const b=j.map(w=>sn(w,x)).filter(w=>w!=null),_=Math.min(...b),y=j.reduce((w,v)=>sn(w,x)>=sn(v,x)?w:v),k=zm(y)??yr(x??"")??Math.max(...b);return{from:_,to:k>_?k:yr(x??Pt[y]??"")??_}}if(x&&an[x]!=null)return{from:an[x],to:yr(x)??an[x]}}}const an={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Tm=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Em=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ia=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function ra(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)&&!ln(e.slice(o),gt(i)))continue}const s=gt(i);if(s===n)continue;const a=e.slice(o),l=ln(a,s)??"";let d;if(l){const c=sn(l,s);if(c!=null){const m=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=m?zi(m[1]):void 0;d=c+(g?g-1:0)}}return{era:s,reign:l,year:d}}for(const i of kn)if(i.pattern.test(e))return{era:gt(i.era),reign:i.reign??""}}function Im(e){var _,y,k,w,v;const n=Qn(e),i=((_=e.publication_info)==null?void 0:_.year)??"",o=i?Bi(i):void 0;if(!n.era&&!n.reign&&!o)return;const s=e.edition||e.title||"",a=/[間间]/.test(s),l=((y=e.lineage)==null?void 0:y.year_text)??"",d=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),c=n.source==="publication"&&$m.test(i),p=n.source==="publication"&&/[間间]/.test(i),m=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let g;a||d||c||p?g=void 0:m?g=parseInt(m[2],10):g=Oi(e);const u=g==null?So(e):void 0;let h;n.source==="publication"&&(c||ia.test(i))?h="uncertain":n.source==="lineage"||n.source==="publication"?h="attested":ia.test(s)||!n.reign&&g==null?h="uncertain":h="inferred";const x=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=e.lineage)==null?void 0:k.year_text)??((w=e.lineage)==null?void 0:w.year)??""}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,j={era:n.era,reign:n.reign,year:g,yearRange:u,certainty:h,source:n.source==="edition"?"edition":"catalog",basis:x};if(m){const C=l.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==j.era&&(j.laterRepair={era:C[1]})}if(!j.laterRepair&&Em.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(j.laterRepair={era:C[1]})}const b=Tm.find(C=>C.re.test(s));if(b){const C=s.search(b.re),$=s.slice(C),S=ra($,n.era)??ra(s,n.era);S&&(j.basedOn={era:S.era,reign:S.reign,year:S.year,relation:b.relation})}return j}const Wr={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function yr(e){return Wr[e]}function Ni(e){const n=Oi(e);if(n!=null)return n;const i=So(e);if(i)return i.from;const o=Qn(e).era;return o?an[o]:void 0}const oa=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Fr(e){const n=oa.indexOf(e);return n===-1?oa.length:n}function Rm(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 _o(e,n){const i=bo(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,g)=>{const u=h=>h.group_role==="origin"?0:h.group_role==="mirror"?1:2;return u(m)-u(g)});const a={text:[],image:[],textImage:[],physical:[]};for(const p of s){const m=Gt(p),g=m.includes("text"),u=m.includes("image");g&&u?a.textImage.push(p):g?a.text.push(p):u?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 g,u;return{key:p,label:((g=n==null?void 0:n[p])==null?void 0:g.label)||p,description:(u=n==null?void 0:n[p])==null?void 0:u.description,items:m}});return{buckets:d,mirrors:c,total:i.length}}function Wi(e,n=Nn("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=Ai(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(Wi(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""}const Lm="同版";function Am(e){const n=e==null?void 0:e.metadata;return((n==null?void 0:n.item_id)||(n==null?void 0:n.call_number)||"").trim()||void 0}function Mm(e){var n;for(const i of((n=e.lineage)==null?void 0:n.related_to)??[]){const o=i.ref??i.book_id;if(i.relation===Lm&&o&&o!==e.id)return o}}function Pm(e){const n=new Map(e.map(a=>[a.id,a])),i=a=>{const l=n.get(a);return!!l&&!l.copyOf},o=new Map;for(const a of e)if(a.copyOf&&i(a.copyOf)){const l=o.get(a.copyOf)??[];l.push(a),o.set(a.copyOf,l)}if(o.size===0)return e;const s=[];for(const a of e){if(a.copyOf&&i(a.copyOf))continue;const l=o.get(a.id);if(!l){s.push(a);continue}const d=[...l].sort((c,p)=>(c.callNumber??c.id).localeCompare(p.callNumber??p.id));s.push({...a,copies:d,hasImage:a.hasImage||d.some(c=>c.hasImage)})}return s}function Xl(e,n){var a,l;const i=e.resources||[],o=[],s=[];for(const d of i){const c=Gt(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:Qn(e),year:Oi(e),sortYear:Ni(e),images:o,holders:s,locationName:(a=e.current_location)==null?void 0:a.name,callNumber:Am(s[0]),copyOf:Mm(e),summary:e.summary,important:Bm(e.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[e.id],hasImage:o.length>0}}function Bm(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=Pm(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,g=p.r.sortYear;return m!=null&&g!=null?m-g||c.i-p.i:m!=null?-1:g!=null?1:c.i-p.i}).map(c=>c.r):a=a.map((c,p)=>({r:c,i:p})).sort((c,p)=>{const m=g=>(g.important?0:1)*2+(g.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)=>Fr(c)-Fr(p));return{rows:a,allRows:s,eras:d,hasInferredEra:s.some(c=>c.era.source==="edition")}}function Om(e,n){var b,_;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const i=(b=n.collections)==null?void 0:b[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=y=>{if(c.has(y))return!0;const k=n.node_groups[y];return k!=null&&d.has(k)},m=[],g=new Map,u=[];for(const y of e)if(!((_=n.excluded_books)!=null&&_.includes(y)))if(p(y))m.push(y);else{const k=n.node_groups[y];k?(g.has(k)||g.set(k,[]),g.get(k).push(y)):u.push(y)}if(u.length+[...g.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const x=new Map((n.groups??[]).map(y=>[y.id,y])),j=[...g.entries()].map(([y,k])=>{const w=x.get(y);return{id:y,label:(w==null?void 0:w.label)??y,description:w==null?void 0:w.description,ids:k}});return u.length>0&&j.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:m,groupedIds:j}}const Jl=["撰","編","注","校","譯","繪","其他"],Wm=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function $o(e){if(!e||!e.trim())return"撰";const n=e.replace(/[\s-]/g,"");if(!n)return"撰";for(const{cls:i,re:o}of Wm)if(o.test(n))return i;return"其他"}function Co(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=$o(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 zo(e){return(e._books??[]).map(n=>n.id).filter(n=>typeof n=="string")}function No(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:Gn(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 Fm(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 Gn(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 Fi(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 Hm=["〇","一","二","三","四","五","六","七","八","九"],sa=["","十","百","千"];function En(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return jr(e,!0);const n=Math.floor(e/1e4),i=e%1e4;let o=jr(n,!0)+"萬";return i>0&&(o+=(i<1e3?"〇":"")+jr(i,!1)),o}function jr(e,n){const i=String(e),o=i.length;let s="",a=!1;for(let l=0;l<o;l++){const d=parseInt(i[l]),c=o-1-l;d===0?a=!0:(a&&s&&(s+="〇"),a=!1,n&&d===1&&c===1&&l===0?s+=sa[c]:s+=Hm[d]+sa[c])}return s}function Dm(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function Um(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 Yt(e,n="卷"){var o,s;const i=e;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?En(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 Hi={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},ic=new Set(["work","book","entity"]);function Vm(e){return sc(e)||!!e.sort}function Gm(e,n){return n.sort&&ic.has(e)?n.sort:void 0}const Di=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Ui=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],rc=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],oc={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Vi(e){return e.dynasty.length+e.classification.length+(e.hasImage?1:0)+(e.hasText?1:0)+(e.hasCollated?1:0)+(e.loss?1:0)}function sc(e){return Vi(e)>0}function Ym(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 ac(e,n){const i=oc[e];return Ym(n).every(o=>i.has(o))}const On=e=>JSON.stringify(e);function qm(e,n){if(!ac(n,e))return null;const i=[];if(e.dynasty.length){const o=Array.from(new Set(e.dynasty.flatMap(s=>{var a;return((a=Di.find(l=>l.key===s))==null?void 0:a.values)??[]})));o.length===1?i.push(`dynasty = ${On(o[0])}`):o.length>1&&i.push(`dynasty IN [${o.map(On).join(", ")}]`)}return e.classification.length&&i.push(e.classification.length===1?`classification = ${On(e.classification[0])}`:`classification IN [${e.classification.map(On).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 = ${On(e.loss)}`),i.join(" AND ")}const bt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},lc="_";function Ti(e,n=new URLSearchParams){for(const i of Object.values(bt))n.delete(i);return e.dynasty.length&&n.set(bt.dynasty,e.dynasty.join(",")),e.classification.length&&n.set(bt.classification,e.classification.map(i=>i||lc).join(",")),e.hasImage&&n.set(bt.hasImage,"1"),e.hasText&&n.set(bt.hasText,"1"),e.hasCollated&&n.set(bt.hasCollated,"1"),e.loss&&n.set(bt.loss,e.loss),e.sort&&n.set(bt.sort,e.sort),n}function Km(e){const n=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),i=new Set(Di.map(a=>a.key)),o=new Set(Ui.map(a=>a.value)),s=e.get(bt.loss);return{dynasty:Array.from(new Set(n(bt.dynasty).filter(a=>i.has(a)))),classification:Array.from(new Set(n(bt.classification).map(a=>a===lc?"":a).filter(a=>o.has(a)))),hasImage:e.get(bt.hasImage)==="1",hasText:e.get(bt.hasText)==="1"||e.get(bt.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(bt.sort))??""}}function Xm(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 aa(e,n){return e.includes(n)?e.filter(i=>i!==n):[...e,n]}const Zm=({filters:e,onChange:n})=>{const i=Pe(),o=i.searchV4,{convert:s}=De(),[a,l]=f.useState(!1),d=f.useId(),c=Vi(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($t(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:Di.map(m=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(m.key),onClick:()=>p({dynasty:aa(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)}),Ui.map(m=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(m.value),onChange:()=>p({classification:aa(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:rc.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({...Hi,sort:e.sort}),children:s(o.clearAllFilters)})]})]})};function cc({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 la=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Pe(),a=s.searchV4,{convert:l}=De(),d=mt();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}`:"",g=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)}`:""}`:"",u=c.type==="book"?c.era??c.dynasty:c.dynasty,h=u?l(u):"",x=c.classification?l(c.classification):"",j=[];c.has_image&&j.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&j.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&j.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const b=[g,h,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(cc,{text:p,query:n?l(n):void 0})}),m&&t.jsx("span",{className:"bim-sr-measure",children:m})]}),b&&t.jsx("span",{className:"bim-sr-sub",children:b})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Tn,{type:c.type,size:6})," ",o(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:g||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:h||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:x||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:j.map(_=>t.jsx("span",{className:`bim-sr-tag ${_.cls}`,children:l(_.label)},_.label))})]},c.id)})})]})})},Jm=`
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
- `,la=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Pe(),a=s.searchV4,{convert:l}=De(),d=mt();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Xm}),e.map(c=>{const p=l(c.title||c.primary_name||c.id),g=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??"?"}`:"":`${c.dynasty?`〔${l(c.dynasty)}〕`:""}${c.author?l(c.author):""}`,c.type==="book"&&c.edition?l(c.edition):"",g].filter(Boolean).join(" · "),h=[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:j=>i(c,j),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(cc,{text:p,query:n?l(n):void 0})}),u&&t.jsx("span",{className:"bim-sc-m",children:u}),c.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:fo(c.descriptionSnippet).map((j,b)=>j.marked?t.jsx("mark",{children:l(j.text)},b):t.jsx(f.Fragment,{children:l(j.text)},b))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:h}),t.jsx("span",{className:"bim-sc-tags",children:x.map(j=>t.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:l(j.label)},j.label))})]})]},c.id)})]})};function Zm(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 Jm(e,n,i){const o=Math.max(1,Math.ceil(n/i));return Math.min(Math.max(1,e),o)}const Qm=({page:e,pageSize:n,total:i,totalLabel:o,onPage:s})=>{const a=Pe().searchV4,{convert:l}=De(),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($t(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)})}),Zm(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)})})]})]})},dc="(max-width: 719px)",eg=`${dc}, (pointer: coarse)`,tg=`
15
+ `,ca=({entries:e,query:n,onEntryLinkClick:i,typeName:o})=>{const s=Pe(),a=s.searchV4,{convert:l}=De(),d=mt();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Jm}),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??"?"}`:"":`${c.dynasty?`〔${l(c.dynasty)}〕`:""}${c.author?l(c.author):""}`,c.type==="book"&&c.edition?l(c.edition):"",m].filter(Boolean).join(" · "),h=[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:j=>i(c,j),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(cc,{text:p,query:n?l(n):void 0})}),u&&t.jsx("span",{className:"bim-sc-m",children:u}),c.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:ho(c.descriptionSnippet).map((j,b)=>j.marked?t.jsx("mark",{children:l(j.text)},b):t.jsx(f.Fragment,{children:l(j.text)},b))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:h}),t.jsx("span",{className:"bim-sc-tags",children:x.map(j=>t.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:l(j.label)},j.label))})]})]},c.id)})]})};function Qm(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 eg(e,n,i){const o=Math.max(1,Math.ceil(n/i));return Math.min(Math.max(1,e),o)}const tg=({page:e,pageSize:n,total:i,totalLabel:o,onPage:s})=>{const a=Pe().searchV4,{convert:l}=De(),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($t(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)})}),Qm(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)})})]})]})},dc="(max-width: 719px)",ng=`${dc}, (pointer: coarse)`,ig=`
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; }
@@ -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 ${eg} {
105
+ @media ${ng} {
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
- `,No="bim-search-view",jr=50,ca=5,Yn=1e3;function ji(e){return e>=Yn?`${Yn.toLocaleString()}+`:e.toLocaleString()}const ng={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function ig(e){return e&&ng[e.toLowerCase()]||"all"}function rg(e){return e==="all"?null:e}const da=["work","collection","book","entity"],og={work:"works",collection:"collections",book:"books",entity:"entities"},sg={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function ag(){try{return window.localStorage.getItem(No)==="card"?"card":"table"}catch{return"table"}}function lg(e){try{window.localStorage.setItem(No,e)}catch{}}const hn=(e,n)=>(e==null?void 0:e[sg[n]])??0,vr=(e,n)=>(e==null?void 0:e[og[n]])??[],pc=({transport:e,query:n,filters:i,onFiltersChange:o,onEntryLinkClick:s,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:p})=>{const g=Pe(),m=g.searchV4,{convert:u}=De(),h=!!e.supportsSearchFilters,x=f.useMemo(()=>h?i:Fi,[h,i]),[j,b]=f.useState("table");f.useEffect(()=>{b(ag())},[]);const _=X=>{b(X),lg(X)},[y,k]=f.useState(l??"all"),w=f.useRef(y);w.current=y,f.useEffect(()=>{l!==void 0&&l!==w.current&&(k(l),C(1))},[l]);const[v,C]=f.useState(c&&c>0?c:1),$=f.useRef(v);$.current=v,f.useEffect(()=>{c!==void 0&&c>0&&c!==$.current&&C(c)},[c]);const S=f.useRef(null),R=f.useCallback(X=>{var ze;C(X),p==null||p(X);const oe=S.current;oe&&oe.getBoundingClientRect().top<0&&((ze=oe.scrollIntoView)==null||ze.call(oe,{block:"start",behavior:"instant"}))},[p]),[N,z]=f.useState(null),[I,P]=f.useState(null),[A,M]=f.useState(!1),[F,ne]=f.useState(""),je=Ni(x).toString(),ae=Ui(x)>0,Y=Ni({...x,sort:""}).toString(),xe=f.useRef({query:n,filterOnlyKey:Y,sort:x.sort});f.useEffect(()=>{const X=xe.current;X.query!==n||X.filterOnlyKey!==Y?(k("all"),C(1)):X.sort!==x.sort&&C(1),xe.current={query:n,filterOnlyKey:Y,sort:x.sort}},[n,Y,x.sort]),f.useEffect(()=>{let X=!1;return M(!0),ne(""),(async()=>{try{let oe;if(e.searchAll)oe=await e.searchAll(n,ca,x);else{const ze=["work","book","collection","entity"],We=await Promise.all(ze.map(be=>e.search(n,be,{page:1,pageSize:ca,filters:x})));oe={works:We[0].entries,books:We[1].entries,collections:We[2].entries,entities:We[3].entries,totalWorks:We[0].total,totalBooks:We[1].total,totalCollections:We[2].total,totalEntities:We[3].total}}X||z(oe)}catch(oe){X||(ne(oe instanceof Error?oe.message:String(oe)),z(null))}finally{X||M(!1)}})(),()=>{X=!0}},[e,n,je]);const J=y;f.useEffect(()=>{if(y==="all"){P(null);return}let X=!1;return M(!0),(async()=>{try{const oe=await e.search(n,y,{page:v,pageSize:jr,filters:x});X||P({key:J,entries:oe.entries,total:oe.total})}catch(oe){X||(ne(oe instanceof Error?oe.message:String(oe)),P(null))}finally{X||M(!1)}})(),()=>{X=!0}},[e,n,je,y,v]);const le=I&&I.key===J?I:null;f.useEffect(()=>{if(y==="all"||!le||A)return;const X=Math.min(le.total,Yn),oe=Jm(v,X,jr);le.entries.length===0&&X>0&&oe!==v&&(C(oe),p==null||p(oe))},[y,le,A,v]);const we=f.useMemo(()=>da.filter(X=>hn(N,X)>0),[N]),ye=we.reduce((X,oe)=>X+hn(N,oe),0),Q=we.some(X=>hn(N,X)>=Yn)?`${ye.toLocaleString()}+`:ye.toLocaleString(),T=!A&&!F&&N!==null&&ye===0,G=f.useCallback(X=>{k(X),C(1),d==null||d(X)},[d]),fe=f.useMemo(()=>{const X=[];return x.dynasty.forEach(oe=>X.push({name:oe,remove:()=>o({...x,dynasty:x.dynasty.filter(ze=>ze!==oe)})})),x.classification.forEach(oe=>{var ze;return X.push({name:oe?((ze=Di.find(We=>We.value===oe))==null?void 0:ze.label)??oe:g.searchPage.unclassified,remove:()=>o({...x,classification:x.classification.filter(We=>We!==oe)})})}),x.hasImage&&X.push({name:m.hasImage,remove:()=>o({...x,hasImage:!1})}),x.hasText&&X.push({name:m.hasText,remove:()=>o({...x,hasText:!1})}),x.hasCollated&&X.push({name:m.hasCollated,remove:()=>o({...x,hasCollated:!1})}),x.loss&&X.push({name:`${m.extant}:${g.searchPage.loss[x.loss]}`,remove:()=>o({...x,loss:""})}),X},[x,o,m,g]),se={query:n,onEntryLinkClick:s,typeName:a},Be=X=>j==="table"?t.jsx(aa,{entries:X,...se}):t.jsx(la,{entries:X,...se}),Oe=da.flatMap(X=>vr(N,X));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":h?void 0:"true",children:[t.jsx("style",{children:tg}),h&&t.jsx(Km,{filters:x,onChange:o}),t.jsxs("div",{className:"bim-sr-main","aria-busy":A,ref:S,children:[we.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":g.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${r("rule")}`},children:[t.jsxs(pa,{on:y==="all",onClick:()=>G("all"),children:[g.search.allTab," ",t.jsx("small",{children:Q})]}),we.map(X=>t.jsxs(pa,{on:y===X,onClick:()=>G(X),children:[a(X)," ",t.jsx("small",{children:ji(hn(N,X))})]},X))]}),t.jsxs("div",{className:"bim-sr-tools",children:[h&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":u(m.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!x.sort,onClick:()=>o({...x,sort:""}),children:u(m.sortRelevance)}),["era","title"].map(X=>{const oe=x.sort.startsWith(`${X}:`)?x.sort.endsWith("desc")?"desc":"asc":null,ze=X==="era"?m.sortEra:m.sortTitle,We=X==="era"?oe==="desc"?m.sortEraDesc:m.sortEraAsc:oe==="desc"?m.sortTitleDesc:m.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":oe!==null,title:u(We),onClick:()=>o({...x,sort:`${X}:${oe==="asc"?"desc":"asc"}`}),children:[u(ze),oe?t.jsxs("span",{"aria-hidden":"true",children:[" ",oe==="asc"?"↑":"↓"]}):null]},X)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":u(m.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":j==="table",onClick:()=>_("table"),children:u(m.viewTable)}),t.jsx("button",{type:"button","aria-pressed":j==="card",onClick:()=>_("card"),children:u(m.viewCard)})]})]}),ae&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:u($t(m.filteredCount,{n:Q}))}),fe.map(X=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u($t(m.removeFilter,{name:X.name})),onClick:X.remove,children:[u(X.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},X.name))]}),F&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:F}),T&&t.jsx("div",{className:"bim-sr-empty",children:u(ae?m.emptyFiltered:$t(g.search.noResultsFor,{query:n}))}),!F&&!T&&y==="all"&&N&&(j==="table"?t.jsxs(t.Fragment,{children:[t.jsx(aa,{entries:Oe,...se}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(m.limitedNote)})]}):t.jsx(t.Fragment,{children:we.map(X=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Tn,{type:X,size:8}),a(X),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r("meta-fg")},children:[ji(hn(N,X))," ",g.unit.items]})]}),hn(N,X)>vr(N,X).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>G(X),children:g.action.viewAll})]}),t.jsx(la,{entries:vr(N,X),...se})]},X))})),!F&&y!=="all"&&!le&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:g.search.loading}),!F&&y!=="all"&&le&&le.entries.length>0&&t.jsxs(t.Fragment,{children:[Be(le.entries),t.jsx(Qm,{page:v,pageSize:jr,total:Math.min(le.total,Yn),totalLabel:ji(le.total),onPage:R})]}),!F&&y!=="all"&&le&&le.entries.length===0&&!A&&t.jsxs("div",{className:"bim-sr-empty",children:[u(ae?m.emptyFiltered:$t(g.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>G("all"),children:g.search.allTab})})]})]})]})};function pa({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 Sn="bim-recent-ids",ua="bim-recent-entries",ma=50;function Qt(){try{const e=localStorage.getItem(Sn);if(e)return JSON.parse(e);const n=localStorage.getItem(ua);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Sn,JSON.stringify(i)),localStorage.removeItem(ua),i}return[]}catch{return[]}}function Fr(e){try{const n=Qt().filter(i=>i!==e);n.unshift(e),n.length>ma&&(n.length=ma),localStorage.setItem(Sn,JSON.stringify(n))}catch{}}function uc(e){try{const n=Qt().filter(i=>i!==e);localStorage.setItem(Sn,JSON.stringify(n))}catch{}}function To(){try{localStorage.removeItem(Sn)}catch{}}async function Io(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 kr=5,cg=50,dg=200,ga={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Hr=({transport:e,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:p,resultVariant:g="compact",renderEntry:m,initialQuery:u,onQueryChange:h,headerRight:x,reserveViewportHeight:j=!1,filtersEnabled:b=!1,filters:_=Fi,onFiltersChange:y,resultTab:k,onResultTabChange:w,resultPage:v,onResultPageChange:C})=>{const $=Pe(),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"}],R=["work","collection","book","entity"],[N,z]=f.useState(u??""),[I,P]=f.useState(null),[A,M]=f.useState(u??""),F=Ni(_).toString(),[ne,je]=f.useState(_);f.useEffect(()=>{je(_)},[F]);const ae=E=>{je(E),y==null||y(E)},[Y,xe]=f.useState(null),[J,le]=f.useState("all"),[we,ye]=f.useState(!1),[Q,T]=f.useState(null),[G,fe]=f.useState(""),[se,Be]=f.useState(!(u!=null&&u.trim())),[Oe,X]=f.useState(Qt),[oe,ze]=f.useState([]),[We,be]=f.useState(!1),[H,ce]=f.useState(!1),[de,ee]=f.useState(null),[Ce,Ue]=f.useState(null),Ge=f.useRef(void 0),nt=f.useRef(!1),O=f.useCallback(async(E,ge)=>{if(!E.trim()){Be(!0),P(null),xe(null);return}if(Be(!1),b){M(E);return}ye(!0),fe("");try{if(e.searchAll){const ve=await e.searchAll(E,ge??kr);P(ve)}else{const ve=["work","book","collection","entity"],$e=await Promise.all(ve.map(D=>e.search(E,D,{page:1,pageSize:ge??kr})));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(ve){fe(ve instanceof Error?ve.message:String(ve)),P(null)}finally{ye(!1)}},[e,b]);f.useEffect(()=>{let E=!1;const ge=()=>{var Z,me;const ve=["work","book","collection","entity"],$e=Promise.all(ve.map(V=>e.loadEntries(V,{page:1,pageSize:1}).catch(()=>({total:0})))),D=((Z=e.getResourceCounts)==null?void 0:Z.call(e).catch(()=>null))??Promise.resolve(null),B=((me=e.getSubtypeStats)==null?void 0:me.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([$e,D,B]).then(([V,U,Me])=>{E||(ee({works:V[0].total,books:V[1].total,collections:V[2].total,entities:V[3].total,hasText:U==null?void 0:U.hasText,hasImage:U==null?void 0:U.hasImage}),Me&&Ue(Me))})};return e.getCounts?e.getCounts().then(ve=>{var $e,D;E||(ee({works:ve.works,books:ve.books,collections:ve.collections,entities:ve.entities,hasText:($e=ve.resourceCounts)==null?void 0:$e.hasText,hasImage:(D=ve.resourceCounts)==null?void 0:D.hasImage}),ve.subtypeStats&&Ue(ve.subtypeStats))}).catch(()=>{E||ge()}):ge(),()=>{E=!0}},[e]),f.useEffect(()=>{nt.current||!(u!=null&&u.trim())||(nt.current=!0,O(u))},[u,O]);const ue=f.useCallback(E=>{if(z(E),!E.trim()){h==null||h(E),Be(!0),P(null),xe(null),le("all");return}Ge.current&&clearTimeout(Ge.current),Ge.current=setTimeout(()=>{xe(null),le("all"),h==null||h(E),O(E)},dg)},[O,h]),Re=f.useCallback(E=>{Ge.current&&clearTimeout(Ge.current),le("all"),h==null||h(E),O(E)},[O,h]),W=f.useCallback(E=>{xe(E),O(N,cg)},[N,O]);f.useEffect(()=>{if(!Oe.length){ze([]);return}let E=!1;return be(!0),Promise.all(Oe.slice(0,10).map(ge=>Io(e,ge))).then(ge=>{E||(ze(ge),be(!1))}),()=>{E=!0}},[Oe,e]);const pe=E=>{T(E.id),Fr(E.id),X(Qt()),o==null||o(E)},ie=(E,ge)=>{if(o&&ug(ge)){ge.preventDefault(),pe(E);return}Fr(E.id),X(Qt())},Ne=E=>{uc(E),X(Qt())},Le=()=>{To(),X([])},Ve=E=>S.find(ge=>ge.type===E),Xe=!se&&!I&&!G,ot=I&&(I.works.length>0||I.books.length>0||I.collections.length>0),it=t.jsxs(t.Fragment,{children:[t.jsx(Gl,{transport:e,value:N,onChange:ue,onSearch:Re,onEntrySelect:pe}),b&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const E=N.trim();E&&Vl(E),Re(N)},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:j?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:mg+(b?gg:"")}),(!b||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:[b?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(Ul,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),b?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:it})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:it}),se&&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:de&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:Ce?t.jsxs(t.Fragment,{children:[(Ce.book??0)>0&&t.jsxs(t.Fragment,{children:[$.searchPage.statBook," ",t.jsx("strong",{style:{color:r("fg")},children:Ce.book.toLocaleString()})," ",$.unit.bu,$.searchPage.statComma,t.jsx("strong",{style:{color:r("fg")},children:de.books.toLocaleString()})," ",$.searchPage.statBookCopies]}),Ce.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statArticle," ",t.jsx("strong",{style:{color:r("fg")},children:Ce.article.toLocaleString()})," ",$.searchPage.statArticleUnit]}):null,Ce.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statPoem," ",t.jsx("strong",{style:{color:r("fg")},children:Ce.poem.toLocaleString()})," ",$.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statCollection," ",t.jsx("strong",{style:{color:r("fg")},children:de.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[$.indexType.work," ",t.jsx("strong",{style:{color:r("fg")},children:de.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.indexType.book," ",t.jsx("strong",{style:{color:r("fg")},children:de.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.indexType.collection," ",t.jsx("strong",{style:{color:r("fg")},children:de.collections.toLocaleString()}),de.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:de.entities.toLocaleString()})]})]})}),de.hasImage!=null&&de.hasText!=null&&t.jsxs("span",{children:[$.resourceType.image," ",t.jsx("strong",{style:{color:r("fg")},children:de.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.resourceType.text," ",t.jsx("strong",{style:{color:r("fg")},children:de.hasText.toLocaleString()})]})]})}),b&&!se&&t.jsx(pc,{transport:e,query:A,filters:ne,onFiltersChange:ae,onEntryLinkClick:ie,typeName:E=>Ve(E).name,tab:k,onTabChange:w,page:v,onPageChange:C}),!(b&&!se)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:we||Xe?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg"),minHeight:pg,boxSizing:"border-box"},children:$.search.searching}):G?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r("desc-fg")},children:G})}):se?t.jsx("div",{style:{flex:1},children:We?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg")},children:$.search.loading}):oe.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:oe.slice(0,H?10:3).map(E=>E.notFound?t.jsx(bg,{id:E.id,onRemove:Ne,t:$},E.id):t.jsx(fa,{entry:E,selected:Q===E.id,onClick:ie,getConfig:Ve,onRemove:Ne},E.id))}),!H&&oe.length>3&&t.jsx("button",{onClick:()=>ce(!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})]})}):ot?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:fg}),(()=>{const E=B=>I[ga[B]]??0,ge=R.map(B=>S.find(Z=>Z.type===B)).filter(B=>E(B.key)>0);if(ge.length<2)return null;const ve=ge.reduce((B,Z)=>B+E(Z.key),0),$e=B=>{if(le(B),B!=="all"&&Y!==B){const Z=S.find(V=>V.type===B),me=(I[Z.key]??[]).length;E(Z.key)>me&&W(B)}},D=B=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:r(B?"fg":"desc-fg"),fontWeight:B?700:400,boxShadow:B?`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":J==="all",style:D(J==="all"),onClick:()=>$e("all"),children:[$.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ve.toLocaleString()})]}),ge.map(B=>t.jsxs("button",{type:"button","aria-pressed":J===B.type,style:D(J===B.type),onClick:()=>$e(B.type),children:[B.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:E(B.key).toLocaleString()})]},B.type))]})})(),S.map(({type:E,name:ge,key:ve})=>{const $e=I[ve]??[],D=ga[ve],B=I[D]??0;if($e.length===0||J!=="all"&&J!==E)return null;const me=J==="all"&&!(Y===E)&&B>kr;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(Tn,{type:E})," ",ge,t.jsxs("span",{style:{fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:[B," ",$.unit.items]})]}),me&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>W(E),style:{border:"none",background:"transparent",color:r("primary"),cursor:"pointer",fontSize:"12px"},children:$.action.viewAll})]}),t.jsx("div",{style:g==="list"?{display:"flex",flexDirection:"column",gap:0}:g==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:$e.map(V=>{if(m)return t.jsx(f.Fragment,{children:m(V)},V.id);const U=g==="card"?xg:fa;return t.jsx(U,{entry:V,selected:Q===V.id,onClick:ie,getConfig:Ve,query:N},V.id)})})]},E)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r("fg")},children:$t($.search.noResultsFor,{query:N})}),t.jsx("p",{style:{color:r("desc-fg"),fontSize:"13px"},children:$.search.tryOther})]})})]})},pg=240;function ug(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const mg=`
120
+ `,To="bim-search-view",vr=50,da=5,Yn=1e3;function vi(e){return e>=Yn?`${Yn.toLocaleString()}+`:e.toLocaleString()}const rg={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function og(e){return e&&rg[e.toLowerCase()]||"all"}function sg(e){return e==="all"?null:e}const pa=["work","collection","book","entity"],ag={work:"works",collection:"collections",book:"books",entity:"entities"},lg={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function cg(){try{return window.localStorage.getItem(To)==="card"?"card":"table"}catch{return"table"}}function dg(e){try{window.localStorage.setItem(To,e)}catch{}}const hn=(e,n)=>(e==null?void 0:e[lg[n]])??0,kr=(e,n)=>(e==null?void 0:e[ag[n]])??[],pc=({transport:e,query:n,filters:i,onFiltersChange:o,onEntryLinkClick:s,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:p})=>{const m=Pe(),g=m.searchV4,{convert:u}=De(),h=!!e.supportsSearchFilters,x=f.useMemo(()=>h?i:Hi,[h,i]),[j,b]=f.useState("table");f.useEffect(()=>{b(cg())},[]);const _=Z=>{b(Z),dg(Z)},[y,k]=f.useState(l??"all"),w=f.useRef(y);w.current=y,f.useEffect(()=>{l!==void 0&&l!==w.current&&(k(l),C(1))},[l]);const[v,C]=f.useState(c&&c>0?c:1),$=f.useRef(v);$.current=v,f.useEffect(()=>{c!==void 0&&c>0&&c!==$.current&&C(c)},[c]);const S=f.useRef(null),I=f.useCallback(Z=>{var ze;C(Z),p==null||p(Z);const oe=S.current;oe&&oe.getBoundingClientRect().top<0&&((ze=oe.scrollIntoView)==null||ze.call(oe,{block:"start",behavior:"instant"}))},[p]),[N,z]=f.useState(null),[E,P]=f.useState(null),[A,M]=f.useState(!1),[F,q]=f.useState(""),be=Ti(x).toString(),se=Vi(x)>0,Y=Ti({...x,sort:""}).toString(),xe=f.useRef({query:n,filterOnlyKey:Y,sort:x.sort});f.useEffect(()=>{const Z=xe.current;Z.query!==n||Z.filterOnlyKey!==Y?(k("all"),C(1)):Z.sort!==x.sort&&C(1),xe.current={query:n,filterOnlyKey:Y,sort:x.sort}},[n,Y,x.sort]),f.useEffect(()=>{let Z=!1;return M(!0),q(""),(async()=>{try{let oe;if(e.searchAll)oe=await e.searchAll(n,da,x);else{const ze=["work","book","collection","entity"],We=await Promise.all(ze.map(ye=>e.search(n,ye,{page:1,pageSize:da,filters:x})));oe={works:We[0].entries,books:We[1].entries,collections:We[2].entries,entities:We[3].entries,totalWorks:We[0].total,totalBooks:We[1].total,totalCollections:We[2].total,totalEntities:We[3].total}}Z||z(oe)}catch(oe){Z||(q(oe instanceof Error?oe.message:String(oe)),z(null))}finally{Z||M(!1)}})(),()=>{Z=!0}},[e,n,be]);const Q=y;f.useEffect(()=>{if(y==="all"){P(null);return}let Z=!1;return M(!0),(async()=>{try{const oe=await e.search(n,y,{page:v,pageSize:vr,filters:x});Z||P({key:Q,entries:oe.entries,total:oe.total})}catch(oe){Z||(q(oe instanceof Error?oe.message:String(oe)),P(null))}finally{Z||M(!1)}})(),()=>{Z=!0}},[e,n,be,y,v]);const le=E&&E.key===Q?E:null;f.useEffect(()=>{if(y==="all"||!le||A)return;const Z=Math.min(le.total,Yn),oe=eg(v,Z,vr);le.entries.length===0&&Z>0&&oe!==v&&(C(oe),p==null||p(oe))},[y,le,A,v]);const we=f.useMemo(()=>pa.filter(Z=>hn(N,Z)>0),[N]),je=we.reduce((Z,oe)=>Z+hn(N,oe),0),ee=we.some(Z=>hn(N,Z)>=Yn)?`${je.toLocaleString()}+`:je.toLocaleString(),T=!A&&!F&&N!==null&&je===0,G=f.useCallback(Z=>{k(Z),C(1),d==null||d(Z)},[d]),fe=f.useMemo(()=>{const Z=[];return x.dynasty.forEach(oe=>Z.push({name:oe,remove:()=>o({...x,dynasty:x.dynasty.filter(ze=>ze!==oe)})})),x.classification.forEach(oe=>{var ze;return Z.push({name:oe?((ze=Ui.find(We=>We.value===oe))==null?void 0:ze.label)??oe:m.searchPage.unclassified,remove:()=>o({...x,classification:x.classification.filter(We=>We!==oe)})})}),x.hasImage&&Z.push({name:g.hasImage,remove:()=>o({...x,hasImage:!1})}),x.hasText&&Z.push({name:g.hasText,remove:()=>o({...x,hasText:!1})}),x.hasCollated&&Z.push({name:g.hasCollated,remove:()=>o({...x,hasCollated:!1})}),x.loss&&Z.push({name:`${g.extant}:${m.searchPage.loss[x.loss]}`,remove:()=>o({...x,loss:""})}),Z},[x,o,g,m]),ae={query:n,onEntryLinkClick:s,typeName:a},Be=Z=>j==="table"?t.jsx(la,{entries:Z,...ae}):t.jsx(ca,{entries:Z,...ae}),Oe=pa.flatMap(Z=>kr(N,Z));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":h?void 0:"true",children:[t.jsx("style",{children:ig}),h&&t.jsx(Zm,{filters:x,onChange:o}),t.jsxs("div",{className:"bim-sr-main","aria-busy":A,ref:S,children:[we.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(ua,{on:y==="all",onClick:()=>G("all"),children:[m.search.allTab," ",t.jsx("small",{children:ee})]}),we.map(Z=>t.jsxs(ua,{on:y===Z,onClick:()=>G(Z),children:[a(Z)," ",t.jsx("small",{children:vi(hn(N,Z))})]},Z))]}),t.jsxs("div",{className:"bim-sr-tools",children:[h&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":u(g.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!x.sort,onClick:()=>o({...x,sort:""}),children:u(g.sortRelevance)}),["era","title"].map(Z=>{const oe=x.sort.startsWith(`${Z}:`)?x.sort.endsWith("desc")?"desc":"asc":null,ze=Z==="era"?g.sortEra:g.sortTitle,We=Z==="era"?oe==="desc"?g.sortEraDesc:g.sortEraAsc:oe==="desc"?g.sortTitleDesc:g.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":oe!==null,title:u(We),onClick:()=>o({...x,sort:`${Z}:${oe==="asc"?"desc":"asc"}`}),children:[u(ze),oe?t.jsxs("span",{"aria-hidden":"true",children:[" ",oe==="asc"?"↑":"↓"]}):null]},Z)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":u(g.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":j==="table",onClick:()=>_("table"),children:u(g.viewTable)}),t.jsx("button",{type:"button","aria-pressed":j==="card",onClick:()=>_("card"),children:u(g.viewCard)})]})]}),se&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:u($t(g.filteredCount,{n:ee}))}),fe.map(Z=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u($t(g.removeFilter,{name:Z.name})),onClick:Z.remove,children:[u(Z.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},Z.name))]}),F&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:F}),T&&t.jsx("div",{className:"bim-sr-empty",children:u(se?g.emptyFiltered:$t(m.search.noResultsFor,{query:n}))}),!F&&!T&&y==="all"&&N&&(j==="table"?t.jsxs(t.Fragment,{children:[t.jsx(la,{entries:Oe,...ae}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(g.limitedNote)})]}):t.jsx(t.Fragment,{children:we.map(Z=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Tn,{type:Z,size:8}),a(Z),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r("meta-fg")},children:[vi(hn(N,Z))," ",m.unit.items]})]}),hn(N,Z)>kr(N,Z).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>G(Z),children:m.action.viewAll})]}),t.jsx(ca,{entries:kr(N,Z),...ae})]},Z))})),!F&&y!=="all"&&!le&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:m.search.loading}),!F&&y!=="all"&&le&&le.entries.length>0&&t.jsxs(t.Fragment,{children:[Be(le.entries),t.jsx(tg,{page:v,pageSize:vr,total:Math.min(le.total,Yn),totalLabel:vi(le.total),onPage:I})]}),!F&&y!=="all"&&le&&le.entries.length===0&&!A&&t.jsxs("div",{className:"bim-sr-empty",children:[u(se?g.emptyFiltered:$t(m.search.noResultsFor,{query:n})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>G("all"),children:m.search.allTab})})]})]})]})};function ua({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 Sn="bim-recent-ids",ma="bim-recent-entries",ga=50;function Qt(){try{const e=localStorage.getItem(Sn);if(e)return JSON.parse(e);const n=localStorage.getItem(ma);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(Sn,JSON.stringify(i)),localStorage.removeItem(ma),i}return[]}catch{return[]}}function Hr(e){try{const n=Qt().filter(i=>i!==e);n.unshift(e),n.length>ga&&(n.length=ga),localStorage.setItem(Sn,JSON.stringify(n))}catch{}}function uc(e){try{const n=Qt().filter(i=>i!==e);localStorage.setItem(Sn,JSON.stringify(n))}catch{}}function Eo(){try{localStorage.removeItem(Sn)}catch{}}async function Io(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 wr=5,pg=50,ug=200,fa={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Dr=({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:g,initialQuery:u,onQueryChange:h,headerRight:x,reserveViewportHeight:j=!1,filtersEnabled:b=!1,filters:_=Hi,onFiltersChange:y,resultTab:k,onResultTabChange:w,resultPage:v,onResultPageChange:C})=>{const $=Pe(),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"}],I=["work","collection","book","entity"],[N,z]=f.useState(u??""),[E,P]=f.useState(null),[A,M]=f.useState(u??""),F=Ti(_).toString(),[q,be]=f.useState(_);f.useEffect(()=>{be(_)},[F]);const se=R=>{be(R),y==null||y(R)},[Y,xe]=f.useState(null),[Q,le]=f.useState("all"),[we,je]=f.useState(!1),[ee,T]=f.useState(null),[G,fe]=f.useState(""),[ae,Be]=f.useState(!(u!=null&&u.trim())),[Oe,Z]=f.useState(Qt),[oe,ze]=f.useState([]),[We,ye]=f.useState(!1),[H,ce]=f.useState(!1),[de,te]=f.useState(null),[Ce,Ue]=f.useState(null),Ge=f.useRef(void 0),nt=f.useRef(!1),O=f.useCallback(async(R,ge)=>{if(!R.trim()){Be(!0),P(null),xe(null);return}if(Be(!1),b){M(R);return}je(!0),fe("");try{if(e.searchAll){const ve=await e.searchAll(R,ge??wr);P(ve)}else{const ve=["work","book","collection","entity"],$e=await Promise.all(ve.map(D=>e.search(R,D,{page:1,pageSize:ge??wr})));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(ve){fe(ve instanceof Error?ve.message:String(ve)),P(null)}finally{je(!1)}},[e,b]);f.useEffect(()=>{let R=!1;const ge=()=>{var J,me;const ve=["work","book","collection","entity"],$e=Promise.all(ve.map(V=>e.loadEntries(V,{page:1,pageSize:1}).catch(()=>({total:0})))),D=((J=e.getResourceCounts)==null?void 0:J.call(e).catch(()=>null))??Promise.resolve(null),B=((me=e.getSubtypeStats)==null?void 0:me.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([$e,D,B]).then(([V,U,Me])=>{R||(te({works:V[0].total,books:V[1].total,collections:V[2].total,entities:V[3].total,hasText:U==null?void 0:U.hasText,hasImage:U==null?void 0:U.hasImage}),Me&&Ue(Me))})};return e.getCounts?e.getCounts().then(ve=>{var $e,D;R||(te({works:ve.works,books:ve.books,collections:ve.collections,entities:ve.entities,hasText:($e=ve.resourceCounts)==null?void 0:$e.hasText,hasImage:(D=ve.resourceCounts)==null?void 0:D.hasImage}),ve.subtypeStats&&Ue(ve.subtypeStats))}).catch(()=>{R||ge()}):ge(),()=>{R=!0}},[e]),f.useEffect(()=>{nt.current||!(u!=null&&u.trim())||(nt.current=!0,O(u))},[u,O]);const ue=f.useCallback(R=>{if(z(R),!R.trim()){h==null||h(R),Be(!0),P(null),xe(null),le("all");return}Ge.current&&clearTimeout(Ge.current),Ge.current=setTimeout(()=>{xe(null),le("all"),h==null||h(R),O(R)},ug)},[O,h]),Re=f.useCallback(R=>{Ge.current&&clearTimeout(Ge.current),le("all"),h==null||h(R),O(R)},[O,h]),W=f.useCallback(R=>{xe(R),O(N,pg)},[N,O]);f.useEffect(()=>{if(!Oe.length){ze([]);return}let R=!1;return ye(!0),Promise.all(Oe.slice(0,10).map(ge=>Io(e,ge))).then(ge=>{R||(ze(ge),ye(!1))}),()=>{R=!0}},[Oe,e]);const pe=R=>{T(R.id),Hr(R.id),Z(Qt()),o==null||o(R)},re=(R,ge)=>{if(o&&gg(ge)){ge.preventDefault(),pe(R);return}Hr(R.id),Z(Qt())},Ne=R=>{uc(R),Z(Qt())},Le=()=>{Eo(),Z([])},Ve=R=>S.find(ge=>ge.type===R),Xe=!ae&&!E&&!G,ot=E&&(E.works.length>0||E.books.length>0||E.collections.length>0),it=t.jsxs(t.Fragment,{children:[t.jsx(Gl,{transport:e,value:N,onChange:ue,onSearch:Re,onEntrySelect:pe}),b&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const R=N.trim();R&&Vl(R),Re(N)},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:j?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:fg+(b?hg:"")}),(!b||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:[b?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(Ul,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),b?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:it})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:it}),ae&&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:de&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:Ce?t.jsxs(t.Fragment,{children:[(Ce.book??0)>0&&t.jsxs(t.Fragment,{children:[$.searchPage.statBook," ",t.jsx("strong",{style:{color:r("fg")},children:Ce.book.toLocaleString()})," ",$.unit.bu,$.searchPage.statComma,t.jsx("strong",{style:{color:r("fg")},children:de.books.toLocaleString()})," ",$.searchPage.statBookCopies]}),Ce.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statArticle," ",t.jsx("strong",{style:{color:r("fg")},children:Ce.article.toLocaleString()})," ",$.searchPage.statArticleUnit]}):null,Ce.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statPoem," ",t.jsx("strong",{style:{color:r("fg")},children:Ce.poem.toLocaleString()})," ",$.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.searchPage.statCollection," ",t.jsx("strong",{style:{color:r("fg")},children:de.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[$.indexType.work," ",t.jsx("strong",{style:{color:r("fg")},children:de.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.indexType.book," ",t.jsx("strong",{style:{color:r("fg")},children:de.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.indexType.collection," ",t.jsx("strong",{style:{color:r("fg")},children:de.collections.toLocaleString()}),de.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:de.entities.toLocaleString()})]})]})}),de.hasImage!=null&&de.hasText!=null&&t.jsxs("span",{children:[$.resourceType.image," ",t.jsx("strong",{style:{color:r("fg")},children:de.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),$.resourceType.text," ",t.jsx("strong",{style:{color:r("fg")},children:de.hasText.toLocaleString()})]})]})}),b&&!ae&&t.jsx(pc,{transport:e,query:A,filters:q,onFiltersChange:se,onEntryLinkClick:re,typeName:R=>Ve(R).name,tab:k,onTabChange:w,page:v,onPageChange:C}),!(b&&!ae)&&t.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:we||Xe?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg"),minHeight:mg,boxSizing:"border-box"},children:$.search.searching}):G?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r("desc-fg")},children:G})}):ae?t.jsx("div",{style:{flex:1},children:We?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r("desc-fg")},children:$.search.loading}):oe.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:oe.slice(0,H?10:3).map(R=>R.notFound?t.jsx(jg,{id:R.id,onRemove:Ne,t:$},R.id):t.jsx(ha,{entry:R,selected:ee===R.id,onClick:re,getConfig:Ve,onRemove:Ne},R.id))}),!H&&oe.length>3&&t.jsx("button",{onClick:()=>ce(!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})]})}):ot?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:xg}),(()=>{const R=B=>E[fa[B]]??0,ge=I.map(B=>S.find(J=>J.type===B)).filter(B=>R(B.key)>0);if(ge.length<2)return null;const ve=ge.reduce((B,J)=>B+R(J.key),0),$e=B=>{if(le(B),B!=="all"&&Y!==B){const J=S.find(V=>V.type===B),me=(E[J.key]??[]).length;R(J.key)>me&&W(B)}},D=B=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:r(B?"fg":"desc-fg"),fontWeight:B?700:400,boxShadow:B?`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":Q==="all",style:D(Q==="all"),onClick:()=>$e("all"),children:[$.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ve.toLocaleString()})]}),ge.map(B=>t.jsxs("button",{type:"button","aria-pressed":Q===B.type,style:D(Q===B.type),onClick:()=>$e(B.type),children:[B.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:R(B.key).toLocaleString()})]},B.type))]})})(),S.map(({type:R,name:ge,key:ve})=>{const $e=E[ve]??[],D=fa[ve],B=E[D]??0;if($e.length===0||Q!=="all"&&Q!==R)return null;const me=Q==="all"&&!(Y===R)&&B>wr;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(Tn,{type:R})," ",ge,t.jsxs("span",{style:{fontWeight:400,color:r("desc-fg"),marginLeft:"6px"},children:[B," ",$.unit.items]})]}),me&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>W(R),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:$e.map(V=>{if(g)return t.jsx(f.Fragment,{children:g(V)},V.id);const U=m==="card"?yg:ha;return t.jsx(U,{entry:V,selected:ee===V.id,onClick:re,getConfig:Ve,query:N},V.id)})})]},R)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r("fg")},children:$t($.search.noResultsFor,{query:N})}),t.jsx("p",{style:{color:r("desc-fg"),fontSize:"13px"},children:$.search.tryOther})]})})]})},mg=240;function gg(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const fg=`
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
- `,gg=`
123
+ `,hg=`
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
- `,fg=`
138
+ `,xg=`
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
- }`,mc={color:"inherit",textDecoration:"none"},hg=({snippet:e})=>{const{convert:n}=De();return t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.6},children:fo(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(f.Fragment,{children:n(i.text)},o))})},xg=({entry:e,selected:n,onClick:i,getConfig:o,query:s})=>{const a=Pe(),{convert:l}=De(),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?`${In(e.juan_count)}${a.unit.juan}`:"",p=[...e.additional_titles||[],...e.attached_texts||[]],g=s&&p.length?p.find(h=>{const x=typeof h=="string"?h:h==null?void 0:h.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,m=r("cover-accent"),u=mt();return t.jsxs("a",{href:u(e.id),onClick:h=>i(e,h),className:"bim-result-card",style:{...mc,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, ${m} 50%, ${r("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${m} 14%, ${r("bg")}), color-mix(in srgb, ${m} 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, ${m} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:m},children:Array.from(d).map((h,x)=>t.jsx("span",{children:h},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)})]}),g&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg")},children:[a.search.alias,":",l(typeof g=="string"?g:g.book_title||"")]}),e.descriptionSnippet&&t.jsx(hg,{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(Tn,{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})]})]})]})},fa=({entry:e,selected:n,onClick:i,getConfig:o,query:s,onRemove:a})=>{const l=Pe(),{convert:d}=De(),c=[...e.additional_titles||[],...e.attached_texts||[]],p=s&&c.length?c.find(m=>{const u=typeof m=="string"?m:m==null?void 0:m.book_title;return u==null?void 0:u.toLowerCase().includes(s.toLowerCase())}):void 0,g=mt();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:g(e.id),onClick:m=>i(e,m),className:"bim-result-card",style:{...mc,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(Tn,{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:[In(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:"×"})]})},bg=({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 yg(e){var n,i,o;return!e.dynasty&&((n=e.dates)==null?void 0:n.birth)==null&&((i=e.dates)==null?void 0:i.death)==null&&(!e.alt_names||e.alt_names.length===0)&&!((o=e.description)!=null&&o.text)}function jg({data:e}){var l,d;const{convert:n}=De(),{dynasty:i}=e,o=((l=e.dates)==null?void 0:l.birth)??void 0,s=((d=e.dates)==null?void 0:d.death)??void 0,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 vg({alt_names:e}){const{convert:n}=De(),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 kg({data:e}){const n=Pe(),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 wg({works:e,transport:n,onNavigate:i,renderLink:o}){const s=Pe(),{convert:a}=De(),l=mt(),[d,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let u=!1;const h=e.map(j=>j.work_id);return(async()=>{const j=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(h);let w=!0;for(let v=0;v<h.length;v++){const C=k[v];C!=null&&C.title?j.set(h[v],C.title):C!=null&&C.primary_name?j.set(h[v],C.primary_name):w=!1}if(w)return j}catch{}const b=[...h],_=8,y=new Array(_).fill(0).map(async()=>{for(;b.length;){const k=b.shift();if(!k)break;if(!j.has(k))try{if(n.getEntry){const C=await n.getEntry(k);if(C!=null&&C.title){j.set(k,C.title);continue}}const w=await n.getItem(k),v=w&&(w.title||w.primary_name)||k;j.set(k,v)}catch{j.set(k,k)}}});return await Promise.all(y),j})().then(j=>{u||c(j)}),()=>{u=!0}},[e,n]);const p=new Map;for(const u of e){const h=u.role||"";p.has(h)||p.set(h,[]),p.get(h).push(u)}const g=["撰","編","注","輯","集","校","評","譯","述","作",""],m=[...p.keys()].sort((u,h)=>{const x=g.indexOf(u),j=g.indexOf(h);return x===-1&&j===-1?u.localeCompare(h):x===-1?1:j===-1?-1:x-j});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,")"]})]}),m.map(u=>{const h=p.get(u);return t.jsxs("div",{style:{marginBottom:"8px"},children:[u&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"2px"},children:[a(u)," ",t.jsxs("span",{style:{color:r("desc-fg")},children:["(",h.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:u?"16px":"0",listStyle:u?"disc":"none",fontSize:"14px",lineHeight:1.8},children:h.map((x,j)=>{const b=a(d.get(x.work_id)||x.work_id);return o?t.jsx("li",{children:o(x.work_id,b)},j):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:b})},j):t.jsx("li",{children:b},j)})})]},u)})]})}const gc=({data:e,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:a})=>{var m;const l=Pe(),{convert:d}=De();let c=!1;try{c=Ie.extractStatus(e.id)==="draft"}catch{}const p=yg(e),g=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(jg,{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}),g&&e.subtype!=="people"&&t.jsx("span",{children:g}),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(vg,{alt_names:e.alt_names}),t.jsx(kg,{data:e}),((m=e.description)==null?void 0:m.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(wg,{works:e.works,transport:n,onNavigate:i,renderLink:o})]})},Sg=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function _g(e){const n=e.search(Sg);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const fc={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===$g(e))){const[a,l]=_g(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 $g(e){try{return decodeURI(e)}catch{return e}}const Cg={...fc,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},qt=({text:e,plainStrong:n,style:i,className:o})=>{const{convert:s}=De(),a=n?Cg:fc;return t.jsx("div",{className:o,style:i,children:t.jsx(Tu,{remarkPlugins:[Iu],components:a,children:s(e)})})};function hc(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 zg={book:r("type-book"),work:r("type-work"),collection:r("type-collection"),entity:r("type-entity")};function Ng({type:e}){const n=Pe();return t.jsx("span",{style:hc(zg[e]),children:n.indexType[e]})}function Tg({isDraft:e}){const n=Pe(),i=r(e?"status-draft":"status-official");return t.jsx("span",{style:hc(i),children:e?n.status.draft:n.status.official})}function Ig({id:e}){const n=Pe(),[i,o]=f.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 zt({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 Mt({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 xc({authors:e,type:n,onNavigate:i,renderLink:o}){const{convert:s}=De();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(Rt,{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 Rt({id:e,label:n,onNavigate:i,renderLink:o}){const s=mt();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 Eg({id:e,title:n,edition:i,type:o,isDraft:s,authors:a,volumeText:l,meta:d,headerExtra:c,onNavigate:p,renderLink:g}){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(Ng,{type:o}),t.jsx(Tg,{isDraft:s}),t.jsx(Ig,{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(xc,{authors:a,type:o,onNavigate:p,renderLink:g}),d]})]})}function bc({items:e,label:n,showMeta:i,onNavigate:o,renderLink:s}){const a=Pe(),{convert:l}=De();if(!e.length)return null;const[d,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((p,g)=>{const m=d===g;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...m?{boxShadow:r("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(m?null:g),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:m?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:l(p.source)}),!m&&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:u=>u.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Rt,{id:p.source_bid,label:a.action.view,onNavigate:o,renderLink:s})})]}),m&&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(Mt,{label:a.label.titleInfo,children:l(p.title_info)}),p.author_info&&t.jsx(Mt,{label:a.label.authorInfo,children:l(p.author_info)}),p.edition&&t.jsx(Mt,{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)})]})]})]},g)})})]})}function Rg({items:e,onNavigate:n,renderLink:i}){const o=Pe();return t.jsx(bc,{items:e,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function yc({items:e,onNavigate:n,renderLink:i}){const o=Pe();return t.jsx(bc,{items:e,label:o.section.emendated,onNavigate:n,renderLink:i})}function jc({label:e,items:n}){const{convert:i}=De();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 Lg({items:e}){const n=Pe();return t.jsx(jc,{label:n.section.aliases,items:e})}function Ag({items:e}){const n=Pe();return t.jsx(jc,{label:n.section.attachedTexts,items:e})}function Mg({items:e}){const n=Pe(),{convert:i}=De();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 Pg({items:e}){const n=Pe(),{convert:i}=De();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 Bg({items:e}){const n=Pe(),{convert:i}=De();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 ha({title:e,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:a}=De(),[l,d]=f.useState([]);return f.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(g=>({id:p,title:g?g.title:void 0,edition:g?g.edition:void 0,type:g?g.type:void 0})).catch(()=>({id:p})))).then(p=>{c||d(p)}),()=>{c=!0}},[n,i]),n.length?t.jsxs(t.Fragment,{children:[t.jsxs(zt,{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(Rt,{id:c.id,label:p,onNavigate:o,renderLink:s})},c.id)})})]}):null}function wr({book:e,onNavigate:n,renderLink:i}){const o=Pe(),{convert:s}=De(),[a,l]=f.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(Rt,{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(vo,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Og({ids:e,workData:n,transport:i,onNavigate:o,renderLink:s,footer:a}){const l=Pe(),{convert:d}=De(),[c,p]=f.useState([]);if(f.useEffect(()=>{if(!e.length){p([]);return}if(!i){p(e.map(j=>({id:j})));return}let x=!1;return Promise.all(e.map(j=>i.getItem(j).then(b=>({id:j,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0,resource_groups:b?b.resource_groups:void 0})).catch(()=>({id:j})))).then(j=>{x||p(j)}),()=>{x=!0}},[e,i]),!e.length)return null;const g=c.length?c:e.map(x=>({id:x})),m=new Map(g.map(x=>[x.id,x])),u=n==null?void 0:n.version_graph,h=Wg(e,u,l.common.otherVersions);return t.jsxs(t.Fragment,{children:[t.jsxs(zt,{children:[l.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),a,h.useGrouping?t.jsxs(t.Fragment,{children:[h.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:h.coreIds.map(x=>{const j=m.get(x);return j?t.jsx(wr,{book:j,onNavigate:o,renderLink:s},x):null})}),h.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(j=>{const b=m.get(j);return b?t.jsx(wr,{book:b,onNavigate:o,renderLink:s},j):null})})]},x.id))]}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:g.map(x=>t.jsx(wr,{book:x,onNavigate:o,renderLink:s},x.id))})]})}function Wg(e,n,i){var _,y;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]),g=k=>{if(p.has(k))return!0;const w=n.node_groups[k];return w!=null&&c.has(w)},m=[],u=new Map,h=[];for(const k of e)if(!((y=n.excluded_books)!=null&&y.includes(k)))if(g(k))m.push(k);else{const w=n.node_groups[k];w?(u.has(w)||u.set(w,[]),u.get(w).push(k)):h.push(k)}if(h.length+[...u.values()].reduce((k,w)=>k+w.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const j=new Map((n.groups??[]).map(k=>[k.id,k])),b=[...u.entries()].map(([k,w])=>{const v=j.get(k);return{id:k,label:(v==null?void 0:v.label)??k,description:v==null?void 0:v.description,ids:w}});return h.length>0&&b.push({id:"__other__",label:i,description:void 0,ids:h}),{useGrouping:!0,coreIds:m,groupedIds:b}}function Fg({workData:e,onNavigate:n,renderLink:i}){var l,d,c,p;const o=Pe(),{convert:s}=De(),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(Rt,{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:[In(e.juan_count.number),o.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(xc,{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(qt,{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(Mt,{label:o.label.parentWork,children:t.jsx(Rt,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Hg({items:e,onNavigate:n,renderLink:i}){const o=Pe(),{convert:s}=De();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(Rt,{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:$t(o.catalog.volume,{n:a.volume_index})})]},a.id))}):null}const Eo=({data:e,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:a,relatedBooksFooter:l,className:d,style:c})=>{var I,P,A,M,F,ne,je,ae;const p=Pe(),{convert:g}=De(),[m,u]=f.useState(null),[h,x]=f.useState(!1),[j,b]=f.useState(null),[_,y]=f.useState(null),[k,w]=f.useState([]),v=e||m;if(f.useEffect(()=>{if(e||!n||!i)return;let Y=!1;return x(!0),b(null),i.getItem(n).then(xe=>{Y||(xe?u(xe):b(p.misc.notFoundEntry))}).catch(xe=>{Y||b(xe instanceof Error?xe.message:p.misc.loadFailed)}).finally(()=>{Y||x(!1)}),()=>{Y=!0}},[e,n,i]),f.useEffect(()=>{if(!v||!i){y(null),w([]);return}let Y=!1;const xe=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(xe?i.getItem(xe).then(J=>{!Y&&J&&J.type==="work"&&y(J)}).catch(()=>{}):y(null),v.type==="book"){const J=v;J.contained_in&&J.contained_in.length>0?Promise.all(J.contained_in.map(le=>{const we=typeof le=="string"?le:le.id,ye=typeof le=="string"?void 0:le.volume_index;return i.getItem(we).then(Q=>({id:we,title:Q&&Q.title||we,volume_index:ye})).catch(()=>({id:we,title:we,volume_index:ye}))})).then(le=>{Y||w(le)}):w([])}else w([]);return()=>{Y=!0}},[v,i]),h)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((Y,xe)=>t.jsx("div",{style:{height:xe===1?"32px":"16px",width:`${Y}px`,background:r("widget-border"),borderRadius:"4px",opacity:.4}},xe))})});if(j)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:j});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(gc,{data:v,transport:i,onNavigate:o,renderLink:s,headerExtra:a})});const C=v.type==="book"?v:null,$=v.type==="collection"?v:null,S=v.type==="work"?v:null;let R=!1;try{R=Ie.extractStatus(v.id)==="draft"}catch{}let N="";v.measure_info?N=g(v.measure_info):(I=v.juan_count)!=null&&I.number?N=In(v.juan_count.number)+p.unit.juan:(P=v.juan_count)!=null&&P.description&&(N=g(v.juan_count.description));const z=[];return(A=v.publication_info)!=null&&A.year&&z.push(t.jsx(Mt,{label:p.label.year,children:v.publication_info.year},"year")),(M=v.current_location)!=null&&M.name&&z.push(t.jsx(Mt,{label:p.label.currentLocation,children:g(v.current_location.name)},"loc")),(F=v.page_count)!=null&&F.description&&z.push(t.jsx(Mt,{label:p.label.pageCount,children:v.page_count.description},"page")),C!=null&&C.edition&&z.push(t.jsx(Mt,{label:p.label.edition,children:g(C.edition)},"ver")),S!=null&&S.parent_work&&z.push(t.jsx(Mt,{label:p.label.parentWork,children:t.jsx(Rt,{id:S.parent_work.id,label:g(S.parent_work.title),onNavigate:o,renderLink:s})},"pw")),S!=null&&S.parent_works&&S.parent_works.length>0&&!S.parent_work&&z.push(t.jsx(Mt,{label:p.label.parentWork,children:S.parent_works.map((Y,xe)=>t.jsxs("span",{children:[xe>0&&"、",t.jsx(Rt,{id:Y,onNavigate:o,renderLink:s})]},Y))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(Eg,{id:v.id,title:g(v.title),edition:v.edition?g(v.edition):void 0,type:v.type,isDraft:R,authors:v.authors,volumeText:N,meta:z,headerExtra:a,onNavigate:o,renderLink:s}),((ne=v.description)==null?void 0:ne.text)&&t.jsx(qt,{text:v.description.text,style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((Y,xe)=>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:g(Y.title)}),t.jsx(qt,{text:Y.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:r("fg")}})]},xe))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:p.section.containedIn}),t.jsx(Hg,{items:k,onNavigate:o,renderLink:s})]}),_&&t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:p.section.belongsToWork}),t.jsx(Fg,{workData:_,onNavigate:o,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(Mg,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Lg,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Ag,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Rg,{items:v.indexed_by,onNavigate:o,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(yc,{items:v.emendated_by,onNavigate:o,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:p.section.resources}),t.jsx(vo,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&t.jsx(Pg,{items:C.location_history}),($==null?void 0:$.history)&&$.history.length>0&&t.jsx(Bg,{items:$.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&t.jsx(ha,{title:p.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:o,renderLink:s}),($==null?void 0:$.books)&&$.books.length>0&&t.jsx(ha,{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(zt,{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(Y=>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(Rt,{id:Y.id,label:g(Y.title),onNavigate:o,renderLink:s})},Y.id))})]}),(((je=S==null?void 0:S.books)==null?void 0:je.length)||0)+(((ae=S==null?void 0:S.collections)==null?void 0:ae.length)||0)>0&&t.jsx(Og,{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 Y=[],xe=S.related_works.filter(T=>T.relation==="part_of"),J=S.related_works.filter(T=>T.relation==="has_part"),le=S.related_works.filter(T=>T.relation==="has_adaptation"),we=S.related_works.filter(T=>T.relation==="text_carried_by"),ye=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),Q=S.related_works.filter(T=>!T.relation||!ye.has(T.relation));return xe.length>0&&Y.push({label:p.section.belongsToWork,items:xe}),J.length>0&&Y.push({label:p.section.containedWorks,items:J}),le.length>0&&Y.push({label:p.section.adaptations,items:le}),we.length>0&&Y.push({label:p.section.derivativeWorks,items:we}),Q.length>0&&Y.push({label:p.section.relatedWorks,items:Q}),Y.map(T=>t.jsxs("div",{children:[t.jsxs(zt,{children:[T.label,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",T.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:T.items.map(G=>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(Rt,{id:G.id,label:g(G.title),onNavigate:o,renderLink:s})},G.id))})]},T.label))})()]})};function Dg({data:e}){const n=Pe(),{convert:i}=De(),{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 Ug({sections:e,activeSection:n,onSelect:i}){const o=Pe();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:xa(n===null),children:o.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:xa(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 xa(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 Vg({id:e,label:n,onNavigate:i,renderLink:o}){const s=mt();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 Gg(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 ba({book:e,onNavigate:n,renderLink:i,showVolumes:o}){const s=Pe(),{convert:a}=De(),l=e.book_id||e.work_id,d=o&&e.volumes.length>0?Gg(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(Vg,{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 Ro=({data:e,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:a,style:l})=>{const d=Pe(),[c,p]=f.useState(null),[g,m]=f.useState(!1),[u,h]=f.useState(null),[x,j]=f.useState(null),[b,_]=f.useState(""),y=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let $=!1;return m(!0),h(null),i.getCollectionCatalog(n).then(S=>{$||(S?p(S):h(d.catalog.notFound))}).catch(S=>{$||h(S instanceof Error?S.message:d.catalog.loadFailed)}).finally(()=>{$||m(!1)}),()=>{$=!0}},[e,n,i,d]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,w=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const $=y.books.map(R=>R.volumes[0]).filter(R=>R!=null);return new Set($).size<$.length},[y]),v=f.useMemo(()=>{if(!y)return[];let $=y.books;if(x&&($=$.filter(S=>S.section===x)),b.trim()){const S=b.trim().toLowerCase();$=$.filter(R=>R.title.toLowerCase().includes(S)||R.sub_items&&R.sub_items.some(N=>N.toLowerCase().includes(S))||R.edition&&R.edition.toLowerCase().includes(S))}return $},[y,x,b]),C=f.useMemo(()=>{if(!w)return null;const $=[],S=new Map;for(const N of v){if(!N.volumes||N.volumes.length===0)continue;const z=N.volumes[0];S.has(z)||S.set(z,[]),S.get(z).push(N)}const R=[...S.keys()].sort((N,z)=>N-z);for(const N of R)$.push({volume:N,books:S.get(N)});return $},[v,w]);return g?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:r("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):u?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:u}):y?t.jsxs("div",{className:a,style:l,children:[t.jsx(Dg,{data:y}),k&&t.jsx(Ug,{sections:y.sections,activeSection:x,onSelect:j}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:b,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:[v.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:$t(d.catalog.volume,{n:$.volume})}),$.books.map((R,N)=>t.jsx(ba,{book:R,onNavigate:o,renderLink:s,showVolumes:R.volumes.length>1},`${$.volume}-${N}`))]},`${$.volume}-${S}`)):v.map(($,S)=>t.jsx(ba,{book:$,onNavigate:o,renderLink:s,showVolumes:!0},S)),v.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 vc(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 Ie.isSafeSegment(o)?i(o):Promise.resolve(null)},async getIndex(o,s){return!Ie.isSafeSegment(o)||!Ie.isSafeSegment(s)||!e.getTextIndex?null:Sr(e.getTextIndex(o,s))},async getChapter(o,s,a,l){return!Ie.isSafeSegment(o)||!Ie.isSafeSegment(s)||!Ie.isSafeSegment(a)||!e.getChapter?null:Sr(e.getChapter(o,s,a,l))}}}const un=()=>{const{t:e}=re(),[n,i]=f.useState(1);return f.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)})},_r=String.raw`https?:\/\/[^\s()()<>"]+`,Yg=new RegExp(String.raw`\[([^\]\n]+)\]\((${_r})\)`+String.raw`|(《[^》\n]+》)\s?[((](${_r})[))]`+`|(${_r})`,"g");function qg(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Kg(e){const n=[];let i=0;for(const o of e.matchAll(Yg)){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:qg(o[5]),url:o[5]}),i=s+o[0].length}return i<e.length&&n.push({text:e.slice(i)}),n}function kc({text:e,convert:n,className:i="bim-rd-link"}){return t.jsx(t.Fragment,{children:Kg(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(f.Fragment,{children:n(o.text)},s))})}const wc="(min-width: 1100px)",vi="(max-width: 719px)",Sc="(max-width: 859px)",Xg=`${vi}, (pointer: coarse)`,At=r("reader-top"),Zg="48px",_c=`
145
+ }`,mc={color:"inherit",textDecoration:"none"},bg=({snippet:e})=>{const{convert:n}=De();return t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),lineHeight:1.6},children:ho(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(f.Fragment,{children:n(i.text)},o))})},yg=({entry:e,selected:n,onClick:i,getConfig:o,query:s})=>{const a=Pe(),{convert:l}=De(),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?`${En(e.juan_count)}${a.unit.juan}`:"",p=[...e.additional_titles||[],...e.attached_texts||[]],m=s&&p.length?p.find(h=>{const x=typeof h=="string"?h:h==null?void 0:h.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,g=r("cover-accent"),u=mt();return t.jsxs("a",{href:u(e.id),onClick:h=>i(e,h),className:"bim-result-card",style:{...mc,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, ${g} 50%, ${r("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${g} 14%, ${r("bg")}), color-mix(in srgb, ${g} 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, ${g} 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:g},children:Array.from(d).map((h,x)=>t.jsx("span",{children:h},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(bg,{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(Tn,{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})]})]})]})},ha=({entry:e,selected:n,onClick:i,getConfig:o,query:s,onRemove:a})=>{const l=Pe(),{convert:d}=De(),c=[...e.additional_titles||[],...e.attached_texts||[]],p=s&&c.length?c.find(g=>{const u=typeof g=="string"?g:g==null?void 0:g.book_title;return u==null?void 0:u.toLowerCase().includes(s.toLowerCase())}):void 0,m=mt();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:g=>i(e,g),className:"bim-result-card",style:{...mc,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(Tn,{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:[En(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:"×"})]})},jg=({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 vg(e){var n,i,o;return!e.dynasty&&((n=e.dates)==null?void 0:n.birth)==null&&((i=e.dates)==null?void 0:i.death)==null&&(!e.alt_names||e.alt_names.length===0)&&!((o=e.description)!=null&&o.text)}function kg({data:e}){var l,d;const{convert:n}=De(),{dynasty:i}=e,o=((l=e.dates)==null?void 0:l.birth)??void 0,s=((d=e.dates)==null?void 0:d.death)??void 0,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 wg({alt_names:e}){const{convert:n}=De(),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 Sg({data:e}){const n=Pe(),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 _g({works:e,transport:n,onNavigate:i,renderLink:o}){const s=Pe(),{convert:a}=De(),l=mt(),[d,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let u=!1;const h=e.map(j=>j.work_id);return(async()=>{const j=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(h);let w=!0;for(let v=0;v<h.length;v++){const C=k[v];C!=null&&C.title?j.set(h[v],C.title):C!=null&&C.primary_name?j.set(h[v],C.primary_name):w=!1}if(w)return j}catch{}const b=[...h],_=8,y=new Array(_).fill(0).map(async()=>{for(;b.length;){const k=b.shift();if(!k)break;if(!j.has(k))try{if(n.getEntry){const C=await n.getEntry(k);if(C!=null&&C.title){j.set(k,C.title);continue}}const w=await n.getItem(k),v=w&&(w.title||w.primary_name)||k;j.set(k,v)}catch{j.set(k,k)}}});return await Promise.all(y),j})().then(j=>{u||c(j)}),()=>{u=!0}},[e,n]);const p=new Map;for(const u of e){const h=u.role||"";p.has(h)||p.set(h,[]),p.get(h).push(u)}const m=["撰","編","注","輯","集","校","評","譯","述","作",""],g=[...p.keys()].sort((u,h)=>{const x=m.indexOf(u),j=m.indexOf(h);return x===-1&&j===-1?u.localeCompare(h):x===-1?1:j===-1?-1:x-j});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,")"]})]}),g.map(u=>{const h=p.get(u);return t.jsxs("div",{style:{marginBottom:"8px"},children:[u&&t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"2px"},children:[a(u)," ",t.jsxs("span",{style:{color:r("desc-fg")},children:["(",h.length,")"]})]}),t.jsx("ul",{style:{margin:0,paddingLeft:u?"16px":"0",listStyle:u?"disc":"none",fontSize:"14px",lineHeight:1.8},children:h.map((x,j)=>{const b=a(d.get(x.work_id)||x.work_id);return o?t.jsx("li",{children:o(x.work_id,b)},j):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:b})},j):t.jsx("li",{children:b},j)})})]},u)})]})}const gc=({data:e,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:a})=>{var g;const l=Pe(),{convert:d}=De();let c=!1;try{c=Ee.extractStatus(e.id)==="draft"}catch{}const p=vg(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(kg,{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(wg,{alt_names:e.alt_names}),t.jsx(Sg,{data:e}),((g=e.description)==null?void 0:g.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(_g,{works:e.works,transport:n,onNavigate:i,renderLink:o})]})},$g=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function Cg(e){const n=e.search($g);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}const fc={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===zg(e))){const[a,l]=Cg(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 zg(e){try{return decodeURI(e)}catch{return e}}const Ng={...fc,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},qt=({text:e,plainStrong:n,style:i,className:o})=>{const{convert:s}=De(),a=n?Ng:fc;return t.jsx("div",{className:o,style:i,children:t.jsx(Iu,{remarkPlugins:[Ru],components:a,children:s(e)})})};function hc(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 Tg={book:r("type-book"),work:r("type-work"),collection:r("type-collection"),entity:r("type-entity")};function Eg({type:e}){const n=Pe();return t.jsx("span",{style:hc(Tg[e]),children:n.indexType[e]})}function Ig({isDraft:e}){const n=Pe(),i=r(e?"status-draft":"status-official");return t.jsx("span",{style:hc(i),children:e?n.status.draft:n.status.official})}function Rg({id:e}){const n=Pe(),[i,o]=f.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 zt({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 Mt({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 xc({authors:e,type:n,onNavigate:i,renderLink:o}){const{convert:s}=De();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(Rt,{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 Rt({id:e,label:n,onNavigate:i,renderLink:o}){const s=mt();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 Lg({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(Eg,{type:o}),t.jsx(Ig,{isDraft:s}),t.jsx(Rg,{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(xc,{authors:a,type:o,onNavigate:p,renderLink:m}),d]})]})}function bc({items:e,label:n,showMeta:i,onNavigate:o,renderLink:s}){const a=Pe(),{convert:l}=De();if(!e.length)return null;const[d,c]=f.useState(null);return t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:n}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.map((p,m)=>{const g=d===m;return t.jsxs("div",{style:{border:`1px solid ${r("widget-border")}`,borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...g?{boxShadow:r("shadow-card")}:{}},children:[t.jsxs("div",{onClick:()=>c(g?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:g?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:r("fg")},children:l(p.source)}),!g&&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:u=>u.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:t.jsx(Rt,{id:p.source_bid,label:a.action.view,onNavigate:o,renderLink:s})})]}),g&&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(Mt,{label:a.label.titleInfo,children:l(p.title_info)}),p.author_info&&t.jsx(Mt,{label:a.label.authorInfo,children:l(p.author_info)}),p.edition&&t.jsx(Mt,{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 Ag({items:e,onNavigate:n,renderLink:i}){const o=Pe();return t.jsx(bc,{items:e,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function yc({items:e,onNavigate:n,renderLink:i}){const o=Pe();return t.jsx(bc,{items:e,label:o.section.emendated,onNavigate:n,renderLink:i})}function jc({label:e,items:n}){const{convert:i}=De();return n.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 Mg({items:e}){const n=Pe();return t.jsx(jc,{label:n.section.aliases,items:e})}function Pg({items:e}){const n=Pe();return t.jsx(jc,{label:n.section.attachedTexts,items:e})}function Bg({items:e}){const n=Pe(),{convert:i}=De();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 Og({items:e}){const n=Pe(),{convert:i}=De();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 Wg({items:e}){const n=Pe(),{convert:i}=De();return e.length?t.jsxs(t.Fragment,{children:[t.jsx(zt,{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 xa({title:e,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:a}=De(),[l,d]=f.useState([]);return f.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(zt,{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(Rt,{id:c.id,label:p,onNavigate:o,renderLink:s})},c.id)})})]}):null}function Sr({book:e,onNavigate:n,renderLink:i}){const o=Pe(),{convert:s}=De(),[a,l]=f.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(Rt,{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(ko,{items:e.resources,resourceGroups:e.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Fg({ids:e,workData:n,transport:i,onNavigate:o,renderLink:s,footer:a}){const l=Pe(),{convert:d}=De(),[c,p]=f.useState([]);if(f.useEffect(()=>{if(!e.length){p([]);return}if(!i){p(e.map(j=>({id:j})));return}let x=!1;return Promise.all(e.map(j=>i.getItem(j).then(b=>({id:j,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0,resource_groups:b?b.resource_groups:void 0})).catch(()=>({id:j})))).then(j=>{x||p(j)}),()=>{x=!0}},[e,i]),!e.length)return null;const m=c.length?c:e.map(x=>({id:x})),g=new Map(m.map(x=>[x.id,x])),u=n==null?void 0:n.version_graph,h=Hg(e,u,l.common.otherVersions);return t.jsxs(t.Fragment,{children:[t.jsxs(zt,{children:[l.section.relatedVersions,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",e.length,")"]})]}),a,h.useGrouping?t.jsxs(t.Fragment,{children:[h.coreIds.length>0&&t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:h.coreIds.map(x=>{const j=g.get(x);return j?t.jsx(Sr,{book:j,onNavigate:o,renderLink:s},x):null})}),h.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(j=>{const b=g.get(j);return b?t.jsx(Sr,{book:b,onNavigate:o,renderLink:s},j):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 Hg(e,n,i){var _,y;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=k=>{if(p.has(k))return!0;const w=n.node_groups[k];return w!=null&&c.has(w)},g=[],u=new Map,h=[];for(const k of e)if(!((y=n.excluded_books)!=null&&y.includes(k)))if(m(k))g.push(k);else{const w=n.node_groups[k];w?(u.has(w)||u.set(w,[]),u.get(w).push(k)):h.push(k)}if(h.length+[...u.values()].reduce((k,w)=>k+w.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const j=new Map((n.groups??[]).map(k=>[k.id,k])),b=[...u.entries()].map(([k,w])=>{const v=j.get(k);return{id:k,label:(v==null?void 0:v.label)??k,description:v==null?void 0:v.description,ids:w}});return h.length>0&&b.push({id:"__other__",label:i,description:void 0,ids:h}),{useGrouping:!0,coreIds:g,groupedIds:b}}function Dg({workData:e,onNavigate:n,renderLink:i}){var l,d,c,p;const o=Pe(),{convert:s}=De(),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(Rt,{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:[En(e.juan_count.number),o.unit.juan]}):null,e.authors&&e.authors.length>0&&t.jsx("span",{style:{fontSize:"13px"},children:t.jsx(xc,{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(qt,{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(Mt,{label:o.label.parentWork,children:t.jsx(Rt,{id:e.parent_work.id,label:s(e.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Ug({items:e,onNavigate:n,renderLink:i}){const o=Pe(),{convert:s}=De();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(Rt,{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:$t(o.catalog.volume,{n:a.volume_index})})]},a.id))}):null}const Ro=({data:e,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:a,relatedBooksFooter:l,className:d,style:c})=>{var E,P,A,M,F,q,be,se;const p=Pe(),{convert:m}=De(),[g,u]=f.useState(null),[h,x]=f.useState(!1),[j,b]=f.useState(null),[_,y]=f.useState(null),[k,w]=f.useState([]),v=e||g;if(f.useEffect(()=>{if(e||!n||!i)return;let Y=!1;return x(!0),b(null),i.getItem(n).then(xe=>{Y||(xe?u(xe):b(p.misc.notFoundEntry))}).catch(xe=>{Y||b(xe instanceof Error?xe.message:p.misc.loadFailed)}).finally(()=>{Y||x(!1)}),()=>{Y=!0}},[e,n,i]),f.useEffect(()=>{if(!v||!i){y(null),w([]);return}let Y=!1;const xe=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(xe?i.getItem(xe).then(Q=>{!Y&&Q&&Q.type==="work"&&y(Q)}).catch(()=>{}):y(null),v.type==="book"){const Q=v;Q.contained_in&&Q.contained_in.length>0?Promise.all(Q.contained_in.map(le=>{const we=typeof le=="string"?le:le.id,je=typeof le=="string"?void 0:le.volume_index;return i.getItem(we).then(ee=>({id:we,title:ee&&ee.title||we,volume_index:je})).catch(()=>({id:we,title:we,volume_index:je}))})).then(le=>{Y||w(le)}):w([])}else w([]);return()=>{Y=!0}},[v,i]),h)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((Y,xe)=>t.jsx("div",{style:{height:xe===1?"32px":"16px",width:`${Y}px`,background:r("widget-border"),borderRadius:"4px",opacity:.4}},xe))})});if(j)return t.jsx("div",{className:d,style:{...c,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:j});if(!v)return null;if(v.type==="entity")return t.jsx("div",{className:d,style:c,children:t.jsx(gc,{data:v,transport:i,onNavigate:o,renderLink:s,headerExtra:a})});const C=v.type==="book"?v:null,$=v.type==="collection"?v:null,S=v.type==="work"?v:null;let I=!1;try{I=Ee.extractStatus(v.id)==="draft"}catch{}let N="";v.measure_info?N=m(v.measure_info):(E=v.juan_count)!=null&&E.number?N=En(v.juan_count.number)+p.unit.juan:(P=v.juan_count)!=null&&P.description&&(N=m(v.juan_count.description));const z=[];return(A=v.publication_info)!=null&&A.year&&z.push(t.jsx(Mt,{label:p.label.year,children:v.publication_info.year},"year")),(M=v.current_location)!=null&&M.name&&z.push(t.jsx(Mt,{label:p.label.currentLocation,children:m(v.current_location.name)},"loc")),(F=v.page_count)!=null&&F.description&&z.push(t.jsx(Mt,{label:p.label.pageCount,children:v.page_count.description},"page")),C!=null&&C.edition&&z.push(t.jsx(Mt,{label:p.label.edition,children:m(C.edition)},"ver")),S!=null&&S.parent_work&&z.push(t.jsx(Mt,{label:p.label.parentWork,children:t.jsx(Rt,{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&&z.push(t.jsx(Mt,{label:p.label.parentWork,children:S.parent_works.map((Y,xe)=>t.jsxs("span",{children:[xe>0&&"、",t.jsx(Rt,{id:Y,onNavigate:o,renderLink:s})]},Y))},"pws")),t.jsxs("div",{className:d,style:c,children:[t.jsx(Lg,{id:v.id,title:m(v.title),edition:v.edition?m(v.edition):void 0,type:v.type,isDraft:I,authors:v.authors,volumeText:N,meta:z,headerExtra:a,onNavigate:o,renderLink:s}),((q=v.description)==null?void 0:q.text)&&t.jsx(qt,{text:v.description.text,style:{fontSize:"14px",color:r("fg"),lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&t.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((Y,xe)=>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(Y.title)}),t.jsx(qt,{text:Y.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:r("fg")}})]},xe))}),k.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:p.section.containedIn}),t.jsx(Ug,{items:k,onNavigate:o,renderLink:s})]}),_&&t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:p.section.belongsToWork}),t.jsx(Dg,{workData:_,onNavigate:o,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&t.jsx(Bg,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&t.jsx(Mg,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&t.jsx(Pg,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&t.jsx(Ag,{items:v.indexed_by,onNavigate:o,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&t.jsx(yc,{items:v.emendated_by,onNavigate:o,renderLink:s}),v.resources&&v.resources.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(zt,{children:p.section.resources}),t.jsx(ko,{items:v.resources,resourceGroups:v.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&t.jsx(Og,{items:C.location_history}),($==null?void 0:$.history)&&$.history.length>0&&t.jsx(Wg,{items:$.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&t.jsx(xa,{title:p.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:o,renderLink:s}),($==null?void 0:$.books)&&$.books.length>0&&t.jsx(xa,{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(zt,{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(Y=>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(Rt,{id:Y.id,label:m(Y.title),onNavigate:o,renderLink:s})},Y.id))})]}),(((be=S==null?void 0:S.books)==null?void 0:be.length)||0)+(((se=S==null?void 0:S.collections)==null?void 0:se.length)||0)>0&&t.jsx(Fg,{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 Y=[],xe=S.related_works.filter(T=>T.relation==="part_of"),Q=S.related_works.filter(T=>T.relation==="has_part"),le=S.related_works.filter(T=>T.relation==="has_adaptation"),we=S.related_works.filter(T=>T.relation==="text_carried_by"),je=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ee=S.related_works.filter(T=>!T.relation||!je.has(T.relation));return xe.length>0&&Y.push({label:p.section.belongsToWork,items:xe}),Q.length>0&&Y.push({label:p.section.containedWorks,items:Q}),le.length>0&&Y.push({label:p.section.adaptations,items:le}),we.length>0&&Y.push({label:p.section.derivativeWorks,items:we}),ee.length>0&&Y.push({label:p.section.relatedWorks,items:ee}),Y.map(T=>t.jsxs("div",{children:[t.jsxs(zt,{children:[T.label,t.jsxs("span",{style:{fontSize:"12px",color:r("desc-fg"),fontWeight:400},children:["(",T.items.length,")"]})]}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:T.items.map(G=>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(Rt,{id:G.id,label:m(G.title),onNavigate:o,renderLink:s})},G.id))})]},T.label))})()]})};function Vg({data:e}){const n=Pe(),{convert:i}=De(),{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 Gg({sections:e,activeSection:n,onSelect:i}){const o=Pe();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>i(null),style:ba(n===null),children:o.catalog.all}),e.map(s=>t.jsxs("button",{onClick:()=>i(s.name),style:ba(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 ba(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 Yg({id:e,label:n,onNavigate:i,renderLink:o}){const s=mt();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 qg(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 ya({book:e,onNavigate:n,renderLink:i,showVolumes:o}){const s=Pe(),{convert:a}=De(),l=e.book_id||e.work_id,d=o&&e.volumes.length>0?qg(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(Yg,{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 Lo=({data:e,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:a,style:l})=>{const d=Pe(),[c,p]=f.useState(null),[m,g]=f.useState(!1),[u,h]=f.useState(null),[x,j]=f.useState(null),[b,_]=f.useState(""),y=e||c;f.useEffect(()=>{if(e||!n||!(i!=null&&i.getCollectionCatalog))return;let $=!1;return g(!0),h(null),i.getCollectionCatalog(n).then(S=>{$||(S?p(S):h(d.catalog.notFound))}).catch(S=>{$||h(S instanceof Error?S.message:d.catalog.loadFailed)}).finally(()=>{$||g(!1)}),()=>{$=!0}},[e,n,i,d]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,w=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const $=y.books.map(I=>I.volumes[0]).filter(I=>I!=null);return new Set($).size<$.length},[y]),v=f.useMemo(()=>{if(!y)return[];let $=y.books;if(x&&($=$.filter(S=>S.section===x)),b.trim()){const S=b.trim().toLowerCase();$=$.filter(I=>I.title.toLowerCase().includes(S)||I.sub_items&&I.sub_items.some(N=>N.toLowerCase().includes(S))||I.edition&&I.edition.toLowerCase().includes(S))}return $},[y,x,b]),C=f.useMemo(()=>{if(!w)return null;const $=[],S=new Map;for(const N of v){if(!N.volumes||N.volumes.length===0)continue;const z=N.volumes[0];S.has(z)||S.set(z,[]),S.get(z).push(N)}const I=[...S.keys()].sort((N,z)=>N-z);for(const N of I)$.push({volume:N,books:S.get(N)});return $},[v,w]);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})}):u?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:u}):y?t.jsxs("div",{className:a,style:l,children:[t.jsx(Vg,{data:y}),k&&t.jsx(Gg,{sections:y.sections,activeSection:x,onSelect:j}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:b,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:[v.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:$t(d.catalog.volume,{n:$.volume})}),$.books.map((I,N)=>t.jsx(ya,{book:I,onNavigate:o,renderLink:s,showVolumes:I.volumes.length>1},`${$.volume}-${N}`))]},`${$.volume}-${S}`)):v.map(($,S)=>t.jsx(ya,{book:$,onNavigate:o,renderLink:s,showVolumes:!0},S)),v.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},_r=e=>e?e.catch(()=>null):Promise.resolve(null);function vc(e){const n=new Map;function i(o){var a;let s=n.get(o);return s||(s=_r((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 Ee.isSafeSegment(o)?i(o):Promise.resolve(null)},async getIndex(o,s){return!Ee.isSafeSegment(o)||!Ee.isSafeSegment(s)||!e.getTextIndex?null:_r(e.getTextIndex(o,s))},async getChapter(o,s,a,l){return!Ee.isSafeSegment(o)||!Ee.isSafeSegment(s)||!Ee.isSafeSegment(a)||!e.getChapter?null:_r(e.getChapter(o,s,a,l))}}}const un=()=>{const{t:e}=ie(),[n,i]=f.useState(1);return f.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)})},$r=String.raw`https?:\/\/[^\s()()<>"]+`,Kg=new RegExp(String.raw`\[([^\]\n]+)\]\((${$r})\)`+String.raw`|(《[^》\n]+》)\s?[((](${$r})[))]`+`|(${$r})`,"g");function Xg(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Zg(e){const n=[];let i=0;for(const o of e.matchAll(Kg)){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:Xg(o[5]),url:o[5]}),i=s+o[0].length}return i<e.length&&n.push({text:e.slice(i)}),n}function kc({text:e,convert:n,className:i="bim-rd-link"}){return t.jsx(t.Fragment,{children:Zg(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(f.Fragment,{children:n(o.text)},s))})}const wc="(min-width: 1100px)",ki="(max-width: 719px)",Sc="(max-width: 859px)",Jg=`${ki}, (pointer: coarse)`,At=r("reader-top"),Qg="48px",_c=`
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: ${Zg};
151
+ --bimrd-bar-h: ${Qg};
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")});
@@ -156,6 +156,10 @@
156
156
  }
157
157
  .bim-rd *, .bim-rd *::before, .bim-rd *::after { box-sizing: border-box; }
158
158
 
159
+ /* 页框用 content-visibility: auto(含 paint 包含)跳过屏外排版,副作用是页框把溢出的内容裁掉、后一页再盖上来:
160
+ 悬停卡(专名/书名)开在页尾时下半截被截断。页内有卡开着时这页恢复正常渲染(它正在屏内,本来就要画)。 */
161
+ .guji-page-section:has(.bim-et-card) { content-visibility: visible !important; }
162
+
159
163
  /* 跳到正文:平时按标准 visually-hidden 收成 1px 并裁掉(任何宽度都不外露),
160
164
  获得焦点时才还原成左上角的按钮 */
161
165
  .bim-rd-skip {
@@ -496,7 +500,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
496
500
 
497
501
  /* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
498
502
  A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
499
- @media ${Xg} {
503
+ @media ${Jg} {
500
504
  .bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
501
505
  .bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
502
506
  content: ""; position: absolute; left: 50%; top: 50%;
@@ -523,7 +527,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
523
527
  }
524
528
 
525
529
  /* ── 窄屏:书影收起,只留正文 ── */
526
- @media ${vi} {
530
+ @media ${ki} {
527
531
  .bim-rd-bar { padding: 0 12px; gap: 10px; }
528
532
  .bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
529
533
  /* 工具条放不下时(版本、自然段、标出作品链接都在)在条内左右滑,不撑宽页面 */
@@ -718,7 +722,7 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
718
722
  }
719
723
 
720
724
  /* ── 手机:正文两侧不留白(放在对读、界栏规则之后才压得过它们) ── */
721
- @media ${vi} {
725
+ @media ${ki} {
722
726
  .bim-rd-text, .bim-rd[data-warp="true"] .bim-rd-text { padding-left: 0; padding-right: 0; }
723
727
  .bim-rd-col, :root[data-layout="boxed"] .bim-rd-col { padding-left: 14px; padding-right: 14px; }
724
728
  :root[data-layout="boxed"] .bim-rd-col { border-left: 0; border-right: 0; }
@@ -729,17 +733,17 @@ button.bim-rd-pg:hover { border-color: ${r("accent")}; }
729
733
  .guji-page-indicator { opacity: 0.55; transition: opacity 0.15s; outline: none; }
730
734
  .guji-page-indicator:hover, .guji-page-indicator:focus-visible { opacity: 1; }
731
735
  .guji-page-indicator:focus-visible { outline: 2px solid ${r("accent")}; outline-offset: 1px; border-radius: 3px; }
732
- @media ${vi} { .guji-page-indicator { display: none; } }
733
- `;function Lo(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(o=>Lo(o,n))):!1}const ya=()=>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 Jg({item:e,activeKey:n,onSelect:i,tabKey:o}){const{t:s}=re(),a=Lo(e,n),[l,d]=f.useState(a||!!e.defaultExpanded);return f.useEffect(()=>{a&&d(!0)},[a]),f.useEffect(()=>{e.defaultExpanded&&d(!0)},[e.defaultExpanded]),e.selectable?t.jsxs("li",{children:[t.jsxs("div",{className:"bim-rd-ti-row",children:[t.jsx("button",{type:"button",className:"bim-rd-ti-tw","aria-expanded":l,"aria-label":s(l?"reader.tocCollapse":"reader.tocExpand"),tabIndex:-1,onClick:()=>d(c=>!c),children:t.jsx(ya,{})}),t.jsxs("button",{type:"button",className:`bim-rd-ti${e.inChapter?"":" bim-rd-ti-group"}`,"aria-current":e.key===n?"true":void 0,disabled:e.disabled,"data-rd-toc-key":e.key,tabIndex:o===e.key?0:-1,onClick:()=>{d(!0),i(e.key)},onKeyDown:c=>{c.key==="ArrowRight"&&!l?(c.preventDefault(),d(!0)):c.key==="ArrowLeft"&&l&&(c.preventDefault(),d(!1))},children:[t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]})]}),l&&t.jsx(Dr,{items:e.children,activeKey:n,onSelect:i,tabKey:o})]}):t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:o===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(ya,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Dr,{items:e.children,activeKey:n,onSelect:i,tabKey:o})]})}function Dr({items:e,activeKey:n,onSelect:i,tabKey:o}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(Jg,{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 ja(e,n){var i;for(const o of e)if(o.key===n||Lo(o,n))return o.key;return((i=e[0])==null?void 0:i.key)??null}function $c({items:e,activeKey:n,onSelect:i,label:o}){const{t:s}=re(),a=o??s("reader.toc"),l=f.useRef(null),[d,c]=f.useState(null);f.useEffect(()=>{c(null)},[n]);const p=f.useMemo(()=>d||(n??ja(e,n)),[d,n,e]);f.useEffect(()=>{const m=l.current;if(!m)return;const u=Array.from(m.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const h=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===ja(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===h?0:-1}),f.useEffect(()=>{const m=l.current,u=m==null?void 0:m.closest(".bim-rd-toc");if(!m||!u||!n)return;const h=Array.from(m.querySelectorAll("[data-rd-toc-key]")).find(j=>j.dataset.rdTocKey===n);if(!h)return;const x=h.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const g=f.useCallback(m=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(m.key))return;const h=l.current;if(!h)return;const x=Array.from(h.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),j=x.indexOf(document.activeElement);let b=j;if(m.key==="ArrowDown"?b=Math.min(x.length-1,j+1):m.key==="ArrowUp"?b=Math.max(0,j-1):m.key==="Home"?b=0:m.key==="End"&&(b=x.length-1),b<0||b===j)return;m.preventDefault();const _=x[b];for(const y of x)y.tabIndex=-1;_.tabIndex=0,_.focus(),c(_.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:g,children:t.jsx(Dr,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function va({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 Qg(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 h of n)[h.x,h.y,h.w,h.h].every(Number.isFinite)&&(s=Math.min(s,h.x),a=Math.min(a,h.y),l=Math.max(l,h.x+h.w),d=Math.max(d,h.y+h.h));if(!(l>s)||!(d>a))return null;const c=Math.min(i,o)*.03,p=Math.min(i,Math.max(0,s-c)),g=Math.min(o,Math.max(0,a-c)),m=Math.min(i,Math.max(0,l+c))-p,u=Math.min(o,Math.max(0,d+c))-g;return!(m>0)||!(u>0)||m>=i*.98&&u>=o*.98?null:{x:p,y:g,w:m,h:u}}function Ur({pages:e,loading:n,page:i,onPageChange:o,renderOverlay:s,preserveMargins:a=!0}){const{t:l}=re(),[d,c]=f.useState(0),p=i??d,g=j=>{o?o(j):c(j)};if(f.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 m=Math.max(0,Math.min(e.length-1,p)),u=e[m],h=u.label??`${m+1}`,x=!a&&!s?Qg(u):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:u.url,alt:u.alt??l("reader.imageAlt",{label:h}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${u.width/x.w*100}%`,left:`${-x.x/x.w*100}%`,top:`${-x.y/x.h*100}%`}}),t.jsx(va,{page:u,crop:x})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:h}),width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(va,{page:u}),s==null?void 0:s(u,m)]})}),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:m===0,onClick:()=>g(m-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${m+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:m===e.length-1,onClick:()=>g(m+1),children:"›"})]})]})}function ef(e){return e==="lite"||e==="full"}const Xn=[.1,.9],Cc=[{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 tf(e){var n;return((n=Cc.find(i=>i.key===e))==null?void 0:n.stack)??null}const Ao={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!0},Dt=[15,16,17,18,20,22,24],Vr=18,zc="bim-reader-prefs",Nc=2,nf="bim-reading-mode";function rf(){const e={...Ao};try{const n=localStorage.getItem(zc),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&Dt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(nf))==="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);const s=i.v===Nc;s&&typeof i.pageBreaks=="boolean"&&(e.pageBreaks=i.pageBreaks),typeof i.pageIndicatorY=="number"&&Number.isFinite(i.pageIndicatorY)&&i.pageIndicatorY>=Xn[0]&&i.pageIndicatorY<=Xn[1]&&(e.pageIndicatorY=i.pageIndicatorY),s&&(i.bookTitleStyle==="wavy"||i.bookTitleStyle==="bracket")&&(e.bookTitleStyle=i.bookTitleStyle),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 of(e){try{localStorage.setItem(zc,JSON.stringify({...e,v:Nc}))}catch{}}function hi(e,n){const i=e??Vr,o=Dt;let s=o.indexOf(i);return s<0&&(s=o.indexOf(Vr)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Tc(){const[e,n]=f.useState(Ao);f.useEffect(()=>{n(rf())},[]);const i=f.useCallback(o=>{n(s=>{const a={...s,...o};return of(a),a})},[]);return[e,i]}function Gr(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 Ic(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 Ec(e){const n=[],i=o=>{for(const s of o){if(s.inChapter)continue;const a=!!s.children&&s.children.length>0;(!a||s.selectable)&&n.push(s),a&&i(s.children)}};return i(e),n}const ka=()=>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"})}),sf=()=>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"})}),af=()=>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"})}),wa=()=>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"})]}),Sa=()=>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 _a(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 $a(e,n){const[i,o]=f.useState(n);return f.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 lf({prefs:e,onPrefsChange:n,origAvailable:i}){const o=f.useContext(Bt),{t:s}=re();if(!o)return null;const a=o.locale==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a,d=[{key:"orig",short:s("reader.scriptOrigShort"),title:s(i?"reader.scriptOrig":"reader.scriptOrigUnavailable"),disabled:!i},{key:"hant",short:s("common.localeShortHant"),title:s("reader.scriptHant")},{key:"hans",short:s("common.localeShortHans"),title:s("reader.scriptHans")}];return t.jsx("span",{className:"bim-rd-script-sw",role:"group","aria-label":s("reader.scriptQuick"),children:d.map((c,p)=>t.jsxs(f.Fragment,{children:[p>0&&t.jsx("span",{className:"bim-rd-off","aria-hidden":"true",children:"|"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":l===c.key,title:c.title,"aria-label":c.title,disabled:c.disabled,onClick:()=>{c.disabled||(n({scriptMode:c.key}),c.key==="hant"?o.setLocale("zh-Hant"):c.key==="hans"&&o.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function ki({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,disabled:a.disabled,onClick:()=>{a.disabled||o(a.key)},children:a.label},a.key))})]})}function cf({prefs:e,onPrefsChange:n,origAvailable:i}){const o=f.useContext(Bt),{t:s}=re(),a=(o==null?void 0:o.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(ki,{label:s("reader.script"),value:l,options:[{key:"orig",label:s("reader.scriptOrig"),title:i?void 0:s("reader.scriptOrigUnavailable"),disabled:!i},{key:"hant",label:s("reader.scriptHant")},{key:"hans",label:s("reader.scriptHans")}],onPick:d=>{n({scriptMode:d}),d==="hant"?o==null||o.setLocale("zh-Hant"):d==="hans"&&(o==null||o.setLocale("zh-Hans"))}})}function df(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 pf(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 Rc({title:e,subtitle:n,toc:i,activeKey:o,tocActiveKey:s,onSelect:a,tocHeader:l,tocCaption:d,images:c,imagesLoading:p,renderImageOverlay:g,imagePanel:m="auto",prefs:u,onPrefsChange:h,paragraphToggle:x,properNameToggle:j=!0,allowVertical:b,origScriptAvailable:_=!0,byline:y,current:k,workLinkToggle:w,rail:v,onReportError:C,revisedAt:$,backHref:S,backLabel:R,bottomBar:N=!0,pager:z=!0,contentLoading:I=!1,pagerUnit:P,versions:A,currentVersionKey:M,onVersionChange:F,versionSource:ne=!0,keepChapterOnVersionChange:je=!1,customImagePanel:ae,toolbarExtra:Y,settingsAnnotate:xe,settingsLayout:J,isWarpMode:le,children:we,className:ye,style:Q}){const{t:T,convert:G}=re(),fe=R??T("reader.back"),se=G(P??T("reader.unitJuan")),Be=f.useId().replace(/:/g,""),Oe=`bim-rd-toc-${Be}`,X=`bim-rd-text-${Be}`,oe=f.useRef(null),ze=f.useRef(null),We=f.useRef(null),be=f.useRef(null),H=$a(wc,!0),ce=$a(Sc,!1),de=N&&ce,[ee,Ce]=f.useState(null),[Ue,Ge]=f.useState(!1),nt=f.useRef(null),O=`bim-rd-set-${Be}`,ue=f.useRef(null),Re=f.useRef(null),W=(q,Ae)=>{Re.current=Ae,Ce(Qe=>Qe===q?null:q)},pe=f.useCallback(()=>{var q;Ce(null),(q=Re.current)==null||q.focus()},[]);f.useEffect(()=>{de||Ce(null)},[de]),f.useEffect(()=>{var q,Ae;ee&&((Ae=(q=ue.current)==null?void 0:q.querySelector("button:not([disabled])"))==null||Ae.focus())},[ee]);const[ie,Ne]=f.useState("auto"),Le=ie==="auto"?H:ie==="open",Ve=!H,Xe=!!ae||!!c&&c.length>0,[ot,it]=f.useState(m);f.useEffect(()=>{it(m)},[m]);const E=ot==="auto"?Xe||!!p:ot==="open",ge=f.useCallback(q=>{var Ae;Ne("auto"),q&&((Ae=be.current)==null||Ae.focus())},[]),ve=()=>Ne(Le?"closed":"open");f.useEffect(()=>{if(!Ve||ie!=="open")return;const q=We.current,Ae=q==null?void 0:q.querySelector('input, [data-rd-toc-key][tabindex="0"]');Ae==null||Ae.focus()},[Ve,ie]);const $e=f.useCallback(q=>{a(q),Ve&&ge(!1);const Ae=ze.current,Qe=oe.current;if(Ae&&Qe&&typeof window<"u"){const st=Ae.getBoundingClientRect().top-Qe.getBoundingClientRect().bottom;st<0&&window.scrollBy({top:st})}},[a,Ve,ge]),D=f.useMemo(()=>Ec(i),[i]),[B,Z]=f.useState(null),me=Ic(A,M!==void 0?M:B),V=(me==null?void 0:me.key)??null,U=f.useMemo(()=>D.map(q=>q.key).join(`
734
- `),[D]),Me=f.useRef(null),He=q=>{q!==V&&(je||(Me.current={key:q,sig:U,done:!1}),M===void 0&&Z(q),F==null||F(q))};f.useEffect(()=>{const q=Me.current;if(!q||q.key!==V)return;const Ae=D.find(st=>!st.disabled);if(!Ae)return;const Qe=U!==q.sig;!Qe&&q.done||(Qe?Me.current=null:q.done=!0,Ae.key!==o&&$e(Ae.key))},[V,U,D,o,$e]);const _e=D.find(q=>q.key===o),K=()=>{var q;C==null||C({chapterKey:o,chapterLabel:typeof(_e==null?void 0:_e.label)=="string"?_e.label:void 0,anchor:df(ze.current,((q=oe.current)==null?void 0:q.getBoundingClientRect().bottom)??0),selectedText:pf(ze.current)})},ke=D.findIndex(q=>q.key===o),he=ke>0?D.slice(0,ke).reverse().find(q=>!q.disabled):void 0,Ee=ke>=0?D.slice(ke+1).find(q=>!q.disabled):void 0,Se=u.fontSize??Vr,Fe=tf(u.fontFamily),Ye={...Q,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...Fe?{"--bimrd-ff":Fe}:null},et={song:T("reader.fontSong"),kai:T("reader.fontKai"),system:T("reader.fontSystem")},Ke=j||!!xe,ct=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${O}-g1`,children:[t.jsx("h3",{id:`${O}-g1`,className:"bim-rd-sp-h",children:T("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:T("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":T("reader.font"),value:u.fontFamily,onChange:q=>h({fontFamily:q.target.value}),children:Cc.map(q=>t.jsx("option",{value:q.key,children:et[q.key]},q.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:T("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.fontSmaller"),disabled:Se<=Dt[0],onClick:()=>h({fontSize:hi(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[Se,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.fontLarger"),disabled:Se>=Dt[Dt.length-1],onClick:()=>h({fontSize:hi(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(cf,{prefs:u,onPrefsChange:h,origAvailable:_}),t.jsx(ki,{label:T("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:T("reader.quoteModern")},{key:"classic",label:T("reader.quoteClassic")},{key:"original",label:T("reader.quoteOriginal")}],onPick:q=>h({quoteStyle:q})})]}),Ke&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${O}-g2`,children:[t.jsx("h3",{id:`${O}-g2`,className:"bim-rd-sp-h",children:T("reader.groupMark")}),j&&t.jsxs(t.Fragment,{children:[t.jsx(ki,{label:T("reader.properName"),value:u.properNameMode,title:T("reader.properNameTitle"),options:[{key:"off",label:T("reader.properNameOff")},{key:"lite",label:T("reader.properNameLite"),title:T("reader.properNameLiteTitle")},{key:"full",label:T("reader.properNameFull")}],onPick:q=>h({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=>h({showWorks:q.target.checked})}),t.jsx("span",{children:T("reader.showWorks")})]}),t.jsx(ki,{label:T("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:T("reader.bookTitleWavy")},{key:"bracket",label:T("reader.bookTitleBracket")}],onPick:q=>h({bookTitleStyle:q})})]}),xe]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${O}-g3`,children:[t.jsx("h3",{id:`${O}-g3`,className:"bim-rd-sp-h",children:T("reader.groupLayout")}),x&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:T("reader.paragraphTitle"),onClick:()=>h({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:T("reader.paragraph")}),w&&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=>h({workLinks:q.target.checked})}),t.jsx("span",{children:T("reader.workLinks")})]}),b&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>h({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:T("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=>h({pageBreaks:q.target.checked})}),t.jsx("span",{children:T("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=>h({preserveMargins:q.target.checked})}),t.jsx("span",{children:T("reader.preserveMargins")})]}),J]})]}),qe=f.useRef(null);return f.useEffect(()=>{const q=qe.current;if(!q||!E)return;let Ae=0,Qe=-1;const st=()=>{Ae=0;const tt=parseFloat(getComputedStyle(q).top);if(!Number.isFinite(tt))return;const xt=Math.max(0,Math.round(q.getBoundingClientRect().top-tt));xt!==Qe&&(Qe=xt,q.style.setProperty("--bimrd-img-lead",`${xt}px`))},at=()=>{Ae||(Ae=requestAnimationFrame(st))};at(),window.addEventListener("scroll",at,{passive:!0}),window.addEventListener("resize",at);const Tt=typeof ResizeObserver<"u"?new ResizeObserver(at):null;return Tt==null||Tt.observe(document.body),()=>{window.removeEventListener("scroll",at),window.removeEventListener("resize",at),Tt==null||Tt.disconnect(),Ae&&cancelAnimationFrame(Ae),q.style.removeProperty("--bimrd-img-lead")}},[E]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&b?"bim-rd-vertical":"",ye].filter(Boolean).join(" "),"data-toc":ie,"data-img":E?"open":"closed","data-bb":de?"":void 0,"data-set":!de&&Ue?"open":void 0,"data-warp":le?"true":void 0,style:Ye,children:[t.jsx("style",{children:_c}),t.jsx("a",{className:"bim-rd-skip",href:`#${X}`,onClick:q=>{var Ae,Qe,st;q.preventDefault(),(Ae=ze.current)==null||Ae.focus(),(st=(Qe=ze.current)==null?void 0:Qe.scrollIntoView)==null||st.call(Qe,{block:"start"})},children:T("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:oe,children:[S&&t.jsxs("a",{className:"bim-rd-back",href:S,"aria-label":T("reader.backAria",{label:fe}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:fe})]}),(e||n||y||k)&&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}),k&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:k})]}),n&&t.jsx("span",{className:"bim-rd-ttl-src",children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":T("reader.settings"),children:[A&&A.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:me?G(Gr(me)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:T("reader.versionShort")}),t.jsx("select",{"aria-label":T("reader.version"),value:V??"",onChange:q=>He(q.target.value),children:A.map(q=>t.jsx("option",{value:q.key,children:G(Gr(q))},q.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),z&&(he||Ee)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":T("reader.pagerGroup",{unit:se}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.prevUnit",{unit:se}),title:he?typeof he.label=="string"&&he.label?T("reader.prevUnitTitle",{unit:se,label:he.label}):T("reader.prevUnit",{unit:se}):T("reader.firstUnit",{unit:se}),disabled:!he,onClick:()=>he&&$e(he.key),children:t.jsx(sf,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.nextUnit",{unit:se}),title:Ee?typeof Ee.label=="string"&&Ee.label?T("reader.nextUnitTitle",{unit:se,label:Ee.label}):T("reader.nextUnit",{unit:se}):T("reader.lastUnit",{unit:se}),disabled:!Ee,onClick:()=>Ee&&$e(Ee.key),children:t.jsx(af,{})})]}),z&&(he||Ee)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:be,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Le,"aria-controls":Oe,onClick:ve,children:[t.jsx(ka,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":E,onClick:()=>it(E?"closed":"open"),children:[t.jsx(Sa,{}),T("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(lf,{prefs:u,onPrefsChange:h,origAvailable:_}),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":T("reader.fontSmaller"),disabled:Se<=Dt[0],onClick:()=>h({fontSize:hi(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":T("reader.fontLarger"),disabled:Se>=Dt[Dt.length-1],onClick:()=>h({fontSize:hi(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:nt,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Ue,"aria-controls":O,onClick:()=>Ge(q=>!q),children:[t.jsx(wa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.settings")})]}),Y]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:Oe,ref:We,role:Ve&&Le?"dialog":void 0,"aria-modal":Ve&&Le?!0:void 0,"aria-label":Ve&&Le?T("reader.toc"):void 0,onKeyDown:q=>{if(!(!Ve||!Le)){if(q.key==="Escape"){q.stopPropagation(),ge(!0);return}q.key==="Tab"&&_a(q,We.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??T("reader.toc")}),Ve&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeToc"),onClick:()=>ge(!0),children:"✕"})]}),l]}),t.jsx($c,{items:i,activeKey:s!==void 0?s:o,onSelect:$e})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>ge(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":T("reader.images"),ref:qe,children:E&&(ae||t.jsx(Ur,{pages:c??null,loading:p,renderOverlay:g,preserveMargins:u.preserveMargins}))}),!de&&Ue&&t.jsxs("aside",{className:"bim-rd-set",id:O,"aria-label":T("reader.settings"),onKeyDown:q=>{var Ae;q.key==="Escape"&&(q.stopPropagation(),Ge(!1),(Ae=nt.current)==null||Ae.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:T("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeSettings"),onClick:()=>{var q;Ge(!1),(q=nt.current)==null||q.focus()},children:"✕"})]}),ct]}),t.jsxs("div",{className:"bim-rd-text",id:X,ref:ze,tabIndex:-1,"data-rail":(v||C)&&!le?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[we,ne&&me&&(me.sourceName||me.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":me.key,children:[me.sourceName&&t.jsxs(t.Fragment,{children:[T("reader.sourceLabel")," ",me.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:me.sourceUrl,target:"_blank",rel:"noreferrer",children:G(me.sourceName)}):G(me.sourceName)]}),me.sourceName&&me.license&&t.jsx("span",{className:"bim-rd-dot"}),me.license&&t.jsx(t.Fragment,{children:T("reader.licenseOf",{license:me.license})})]}),$&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:T("reader.revisedAt",{date:$})}),C&&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:K,children:T("reader.reportError")})}),z&&!I&&(he||Ee)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":T("reader.pagerNav"),children:[he?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>$e(he.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),T("reader.prevUnit",{unit:se})]}),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:["← ",T("reader.firstUnit",{unit:se})]}),Ee?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>$e(Ee.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[T("reader.nextUnit",{unit:se}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:Ee.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[T("reader.lastUnit",{unit:se})," →"]})]})]}),(v||C)&&!le&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":T("reader.rail"),children:[v,C&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:q=>q.preventDefault(),onClick:K,children:T("reader.reportError")})})]})]})]}),de&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":T("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":Le,"aria-controls":Oe,onClick:()=>{Ce(null),ve()},children:[t.jsx(ka,{}),t.jsx("span",{children:T("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":ee==="img","aria-haspopup":"dialog",onClick:q=>W("img",q.currentTarget),children:[t.jsx(Sa,{}),t.jsx("span",{children:T("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":ee==="set","aria-haspopup":"dialog",onClick:q=>W("set",q.currentTarget),children:[t.jsx(wa,{}),t.jsx("span",{children:T("reader.settingsShort")})]}),C&&t.jsxs("button",{type:"button",onMouseDown:q=>q.preventDefault(),onClick:()=>{Ce(null),K()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:T("reader.reportError")})]})]}),de&&ee&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:pe}),t.jsxs("div",{className:"bim-rd-sheet",ref:ue,role:"dialog","aria-modal":"true","aria-label":T(ee==="img"?"reader.images":"reader.settings"),onKeyDown:q=>{if(q.key==="Escape"){q.stopPropagation(),pe();return}q.key==="Tab"&&_a(q,ue.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:T(ee==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.close"),onClick:pe,children:"✕"})]}),ee==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Ur,{pages:c??null,loading:p,renderOverlay:g,preserveMargins:u.preserveMargins})}):ct]})]})]})}function uf(e,n,i){return i?Lc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(n).length?"convert-length":n.includes(":::")?"tables":null:"quoteStyle"}function Lc(e){return e.replace(/\r\n/g,`
735
- `)}const Ca=2,mf=400,gf=6,Ac=e=>e==="*"||e==="#"||e==="<"||e===">"||/\s/.test(e);function Mc(e,n){if(e[n]!=="<"||e[n+1]!=="!"||e[n+2]!=="-"||e[n+3]!=="-")return-1;for(let i=n+4;i+2<e.length;i++)if(e[i]==="-"&&e[i+1]==="-"&&e[i+2]===">")return i+2;return-1}function ff(e,n,i){let o=n;for(let s=0;s<i.length;){if(o>=e.length)return-1;if(i[s]===e[o]){s++,o++;continue}const a=Mc(e,o);if(a>=0){o=a+1;continue}if(Ac(e[o])){o++;continue}if(i[s]===" "){s++;continue}return-1}return o}function hf(e){const n=Array.from(Lc(e));let i=0;return{align(o){if(!o)return;const s=Array.from(o);if(s.every(d=>d===" "||/\s/.test(d)))return;const a=s.length>=gf;let l=0;for(let d=i;d<n.length&&d-i<=(a?mf:Ca+64);d++){const c=Mc(n,d);if(c>=0){d=c;continue}if(!Ac(n[d])){const g=ff(n,d,s);if(g>=0)return i=g,d;if(l++,!a&&l>Ca)return}}}}}const xf=65536,bf="guji_markdown";function yf(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 jf=/^□\{guess=([^\s{}]+)\}/;function vf(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Pc(e,n){let i=0;for(let o=n;o<e.length;o++){const s=e[o];if(s===`
736
- `)return-1;if(s==="\\"){o++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return o}return-1}function kf(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function wf(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(`
737
- `)<0?{node:{type:"qw",label:e.slice(n+2,o)},end:o+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const o=Pc(e,n+3);return o>n+4?{node:{type:"zi",label:kf(e.slice(n+4,o))},end:o+1}:null}if(i==="□"&&e[n+1]==="{"){const o=jf.exec(e.slice(n,n+64));if(o)return{node:{type:"qz",guess:o[1]},end:n+o[0].length}}return null}function Bc(e,n,i,o,s){const a=[];let l="",d=!1;const c=()=>{if(!l)return;let p=l;o&&(p=l.replace(/\\?\|/g,g=>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===`
738
- `)return null}const g=wf(e,n);if(g){c(),a.push(g.node),n=g.end;continue}let m=null;if(p==="<"&&vf(e,n)&&(m=">"),m){const u=Bc(e,n+1,m,!0,s);if(u&&!(u.end-(n+1)>s)){c(),a.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(c(),{nodes:a,end:n})}function Oc(e,n){return Bc(e,0,null,!1,(n==null?void 0:n.jzMaxLength)??xf).nodes}function Sf(e){return/[<□]|\[\[|:zi\[/.test(e)}function Wc(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Wc(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const _f=216,za="clamp(280px, 23vw, 360px)",$f=1440,Yr="(max-width: 719px)",Cf=`${Yr}, (pointer: coarse)`,zf=`
739
- .bim-d-main.bim-d-main-grid { max-width: ${$f}px; padding: 16px 32px 0; }
736
+ @media ${ki} { .guji-page-indicator { display: none; } }
737
+ `;function Ao(e,n){var i;return n?e.key===n?!0:!!((i=e.children)!=null&&i.some(o=>Ao(o,n))):!1}const ja=()=>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 ef({item:e,activeKey:n,onSelect:i,tabKey:o}){const{t:s}=ie(),a=Ao(e,n),[l,d]=f.useState(a||!!e.defaultExpanded);return f.useEffect(()=>{a&&d(!0)},[a]),f.useEffect(()=>{e.defaultExpanded&&d(!0)},[e.defaultExpanded]),e.selectable?t.jsxs("li",{children:[t.jsxs("div",{className:"bim-rd-ti-row",children:[t.jsx("button",{type:"button",className:"bim-rd-ti-tw","aria-expanded":l,"aria-label":s(l?"reader.tocCollapse":"reader.tocExpand"),tabIndex:-1,onClick:()=>d(c=>!c),children:t.jsx(ja,{})}),t.jsxs("button",{type:"button",className:`bim-rd-ti${e.inChapter?"":" bim-rd-ti-group"}`,"aria-current":e.key===n?"true":void 0,disabled:e.disabled,"data-rd-toc-key":e.key,tabIndex:o===e.key?0:-1,onClick:()=>{d(!0),i(e.key)},onKeyDown:c=>{c.key==="ArrowRight"&&!l?(c.preventDefault(),d(!0)):c.key==="ArrowLeft"&&l&&(c.preventDefault(),d(!1))},children:[t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]})]}),l&&t.jsx(Ur,{items:e.children,activeKey:n,onSelect:i,tabKey:o})]}):t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:o===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(ja,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Ur,{items:e.children,activeKey:n,onSelect:i,tabKey:o})]})}function Ur({items:e,activeKey:n,onSelect:i,tabKey:o}){return t.jsx("ul",{children:e.map(s=>s.children&&s.children.length>0?t.jsx(ef,{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 va(e,n){var i;for(const o of e)if(o.key===n||Ao(o,n))return o.key;return((i=e[0])==null?void 0:i.key)??null}function $c({items:e,activeKey:n,onSelect:i,label:o}){const{t:s}=ie(),a=o??s("reader.toc"),l=f.useRef(null),[d,c]=f.useState(null);f.useEffect(()=>{c(null)},[n]);const p=f.useMemo(()=>d||(n??va(e,n)),[d,n,e]);f.useEffect(()=>{const g=l.current;if(!g)return;const u=Array.from(g.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const h=u.find(x=>x.dataset.rdTocKey===p)??u.find(x=>x.dataset.rdTocKey===va(e,n))??u.find(x=>!x.disabled)??u[0];for(const x of u)x.tabIndex=x===h?0:-1}),f.useEffect(()=>{const g=l.current,u=g==null?void 0:g.closest(".bim-rd-toc");if(!g||!u||!n)return;const h=Array.from(g.querySelectorAll("[data-rd-toc-key]")).find(j=>j.dataset.rdTocKey===n);if(!h)return;const x=h.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(x<u.scrollTop+80||x>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,x-u.clientHeight/3))},[n]);const m=f.useCallback(g=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(g.key))return;const h=l.current;if(!h)return;const x=Array.from(h.querySelectorAll("[data-rd-toc-key]")).filter(y=>!y.disabled),j=x.indexOf(document.activeElement);let b=j;if(g.key==="ArrowDown"?b=Math.min(x.length-1,j+1):g.key==="ArrowUp"?b=Math.max(0,j-1):g.key==="Home"?b=0:g.key==="End"&&(b=x.length-1),b<0||b===j)return;g.preventDefault();const _=x[b];for(const y of x)y.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(Ur,{items:e,activeKey:n,onSelect:i,tabKey:p})})}function ka({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 tf(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 h of n)[h.x,h.y,h.w,h.h].every(Number.isFinite)&&(s=Math.min(s,h.x),a=Math.min(a,h.y),l=Math.max(l,h.x+h.w),d=Math.max(d,h.y+h.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)),g=Math.min(i,Math.max(0,l+c))-p,u=Math.min(o,Math.max(0,d+c))-m;return!(g>0)||!(u>0)||g>=i*.98&&u>=o*.98?null:{x:p,y:m,w:g,h:u}}function Vr({pages:e,loading:n,page:i,onPageChange:o,renderOverlay:s,preserveMargins:a=!0}){const{t:l}=ie(),[d,c]=f.useState(0),p=i??d,m=j=>{o?o(j):c(j)};if(f.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 g=Math.max(0,Math.min(e.length-1,p)),u=e[g],h=u.label??`${g+1}`,x=!a&&!s?tf(u):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:u.url,alt:u.alt??l("reader.imageAlt",{label:h}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${u.width/x.w*100}%`,left:`${-x.x/x.w*100}%`,top:`${-x.y/x.h*100}%`}}),t.jsx(ka,{page:u,crop:x})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:h}),width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(ka,{page:u}),s==null?void 0:s(u,g)]})}),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:g===0,onClick:()=>m(g-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${g+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:g===e.length-1,onClick:()=>m(g+1),children:"›"})]})]})}function nf(e){return e==="lite"||e==="full"}const Xn=[.1,.9],Cc=[{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 rf(e){var n;return((n=Cc.find(i=>i.key===e))==null?void 0:n.stack)??null}const Mo={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!0},Dt=[15,16,17,18,20,22,24],Gr=18,zc="bim-reader-prefs",Nc=2,of="bim-reading-mode";function sf(){const e={...Mo};try{const n=localStorage.getItem(zc),i=n?JSON.parse(n):{};typeof i.fontSize=="number"&&Dt.includes(i.fontSize)&&(e.fontSize=i.fontSize),(i.readingMode??localStorage.getItem(of))==="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);const s=i.v===Nc;s&&typeof i.pageBreaks=="boolean"&&(e.pageBreaks=i.pageBreaks),typeof i.pageIndicatorY=="number"&&Number.isFinite(i.pageIndicatorY)&&i.pageIndicatorY>=Xn[0]&&i.pageIndicatorY<=Xn[1]&&(e.pageIndicatorY=i.pageIndicatorY),s&&(i.bookTitleStyle==="wavy"||i.bookTitleStyle==="bracket")&&(e.bookTitleStyle=i.bookTitleStyle),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 af(e){try{localStorage.setItem(zc,JSON.stringify({...e,v:Nc}))}catch{}}function xi(e,n){const i=e??Gr,o=Dt;let s=o.indexOf(i);return s<0&&(s=o.indexOf(Gr)),o[Math.max(0,Math.min(o.length-1,s+n))]}function Tc(){const[e,n]=f.useState(Mo);f.useEffect(()=>{n(sf())},[]);const i=f.useCallback(o=>{n(s=>{const a={...s,...o};return af(a),a})},[]);return[e,i]}function Yr(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 Ec(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 Ic(e){const n=[],i=o=>{for(const s of o){if(s.inChapter)continue;const a=!!s.children&&s.children.length>0;(!a||s.selectable)&&n.push(s),a&&i(s.children)}};return i(e),n}const wa=()=>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"})}),lf=()=>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"})}),cf=()=>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"})}),Sa=()=>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"})]}),_a=()=>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 $a(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 Ca(e,n){const[i,o]=f.useState(n);return f.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 df({prefs:e,onPrefsChange:n,origAvailable:i}){const o=f.useContext(Bt),{t:s}=ie();if(!o)return null;const a=o.locale==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a,d=[{key:"orig",short:s("reader.scriptOrigShort"),title:s(i?"reader.scriptOrig":"reader.scriptOrigUnavailable"),disabled:!i},{key:"hant",short:s("common.localeShortHant"),title:s("reader.scriptHant")},{key:"hans",short:s("common.localeShortHans"),title:s("reader.scriptHans")}];return t.jsx("span",{className:"bim-rd-script-sw",role:"group","aria-label":s("reader.scriptQuick"),children:d.map((c,p)=>t.jsxs(f.Fragment,{children:[p>0&&t.jsx("span",{className:"bim-rd-off","aria-hidden":"true",children:"|"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":l===c.key,title:c.title,"aria-label":c.title,disabled:c.disabled,onClick:()=>{c.disabled||(n({scriptMode:c.key}),c.key==="hant"?o.setLocale("zh-Hant"):c.key==="hans"&&o.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function wi({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,disabled:a.disabled,onClick:()=>{a.disabled||o(a.key)},children:a.label},a.key))})]})}function pf({prefs:e,onPrefsChange:n,origAvailable:i}){const o=f.useContext(Bt),{t:s}=ie(),a=(o==null?void 0:o.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(wi,{label:s("reader.script"),value:l,options:[{key:"orig",label:s("reader.scriptOrig"),title:i?void 0:s("reader.scriptOrigUnavailable"),disabled:!i},{key:"hant",label:s("reader.scriptHant")},{key:"hans",label:s("reader.scriptHans")}],onPick:d=>{n({scriptMode:d}),d==="hant"?o==null||o.setLocale("zh-Hant"):d==="hans"&&(o==null||o.setLocale("zh-Hans"))}})}function uf(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 mf(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 Rc({title:e,subtitle:n,toc:i,activeKey:o,tocActiveKey:s,onSelect:a,tocHeader:l,tocCaption:d,images:c,imagesLoading:p,renderImageOverlay:m,imagePanel:g="auto",prefs:u,onPrefsChange:h,paragraphToggle:x,properNameToggle:j=!0,allowVertical:b,origScriptAvailable:_=!0,byline:y,current:k,workLinkToggle:w,rail:v,onReportError:C,revisedAt:$,backHref:S,backLabel:I,bottomBar:N=!0,pager:z=!0,contentLoading:E=!1,pagerUnit:P,versions:A,currentVersionKey:M,onVersionChange:F,versionSource:q=!0,keepChapterOnVersionChange:be=!1,customImagePanel:se,toolbarExtra:Y,settingsAnnotate:xe,settingsLayout:Q,isWarpMode:le,children:we,className:je,style:ee}){const{t:T,convert:G}=ie(),fe=I??T("reader.back"),ae=G(P??T("reader.unitJuan")),Be=f.useId().replace(/:/g,""),Oe=`bim-rd-toc-${Be}`,Z=`bim-rd-text-${Be}`,oe=f.useRef(null),ze=f.useRef(null),We=f.useRef(null),ye=f.useRef(null),H=Ca(wc,!0),ce=Ca(Sc,!1),de=N&&ce,[te,Ce]=f.useState(null),[Ue,Ge]=f.useState(!1),nt=f.useRef(null),O=`bim-rd-set-${Be}`,ue=f.useRef(null),Re=f.useRef(null),W=(K,Ae)=>{Re.current=Ae,Ce(Qe=>Qe===K?null:K)},pe=f.useCallback(()=>{var K;Ce(null),(K=Re.current)==null||K.focus()},[]);f.useEffect(()=>{de||Ce(null)},[de]),f.useEffect(()=>{var K,Ae;te&&((Ae=(K=ue.current)==null?void 0:K.querySelector("button:not([disabled])"))==null||Ae.focus())},[te]);const[re,Ne]=f.useState("auto"),Le=re==="auto"?H:re==="open",Ve=!H,Xe=!!se||!!c&&c.length>0,[ot,it]=f.useState(g);f.useEffect(()=>{it(g)},[g]);const R=ot==="auto"?Xe||!!p:ot==="open",ge=f.useCallback(K=>{var Ae;Ne("auto"),K&&((Ae=ye.current)==null||Ae.focus())},[]),ve=()=>Ne(Le?"closed":"open");f.useEffect(()=>{if(!Ve||re!=="open")return;const K=We.current,Ae=K==null?void 0:K.querySelector('input, [data-rd-toc-key][tabindex="0"]');Ae==null||Ae.focus()},[Ve,re]);const $e=f.useCallback(K=>{a(K),Ve&&ge(!1);const Ae=ze.current,Qe=oe.current;if(Ae&&Qe&&typeof window<"u"){const at=Ae.getBoundingClientRect().top-Qe.getBoundingClientRect().bottom;at<0&&window.scrollBy({top:at})}},[a,Ve,ge]),D=f.useMemo(()=>Ic(i),[i]),[B,J]=f.useState(null),me=Ec(A,M!==void 0?M:B),V=(me==null?void 0:me.key)??null,U=f.useMemo(()=>D.map(K=>K.key).join(`
738
+ `),[D]),Me=f.useRef(null),He=K=>{K!==V&&(be||(Me.current={key:K,sig:U,done:!1}),M===void 0&&J(K),F==null||F(K))};f.useEffect(()=>{const K=Me.current;if(!K||K.key!==V)return;const Ae=D.find(at=>!at.disabled);if(!Ae)return;const Qe=U!==K.sig;!Qe&&K.done||(Qe?Me.current=null:K.done=!0,Ae.key!==o&&$e(Ae.key))},[V,U,D,o,$e]);const _e=D.find(K=>K.key===o),X=()=>{var K;C==null||C({chapterKey:o,chapterLabel:typeof(_e==null?void 0:_e.label)=="string"?_e.label:void 0,anchor:uf(ze.current,((K=oe.current)==null?void 0:K.getBoundingClientRect().bottom)??0),selectedText:mf(ze.current)})},ke=D.findIndex(K=>K.key===o),he=ke>0?D.slice(0,ke).reverse().find(K=>!K.disabled):void 0,Ie=ke>=0?D.slice(ke+1).find(K=>!K.disabled):void 0,Se=u.fontSize??Gr,Fe=rf(u.fontFamily),Ye={...ee,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...Fe?{"--bimrd-ff":Fe}:null},et={song:T("reader.fontSong"),kai:T("reader.fontKai"),system:T("reader.fontSystem")},Ke=j||!!xe,dt=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${O}-g1`,children:[t.jsx("h3",{id:`${O}-g1`,className:"bim-rd-sp-h",children:T("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:T("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":T("reader.font"),value:u.fontFamily,onChange:K=>h({fontFamily:K.target.value}),children:Cc.map(K=>t.jsx("option",{value:K.key,children:et[K.key]},K.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:T("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.fontSmaller"),disabled:Se<=Dt[0],onClick:()=>h({fontSize:xi(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[Se,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.fontLarger"),disabled:Se>=Dt[Dt.length-1],onClick:()=>h({fontSize:xi(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(pf,{prefs:u,onPrefsChange:h,origAvailable:_}),t.jsx(wi,{label:T("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:T("reader.quoteModern")},{key:"classic",label:T("reader.quoteClassic")},{key:"original",label:T("reader.quoteOriginal")}],onPick:K=>h({quoteStyle:K})})]}),Ke&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${O}-g2`,children:[t.jsx("h3",{id:`${O}-g2`,className:"bim-rd-sp-h",children:T("reader.groupMark")}),j&&t.jsxs(t.Fragment,{children:[t.jsx(wi,{label:T("reader.properName"),value:u.properNameMode,title:T("reader.properNameTitle"),options:[{key:"off",label:T("reader.properNameOff")},{key:"lite",label:T("reader.properNameLite"),title:T("reader.properNameLiteTitle")},{key:"full",label:T("reader.properNameFull")}],onPick:K=>h({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=>h({showWorks:K.target.checked})}),t.jsx("span",{children:T("reader.showWorks")})]}),t.jsx(wi,{label:T("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:T("reader.bookTitleWavy")},{key:"bracket",label:T("reader.bookTitleBracket")}],onPick:K=>h({bookTitleStyle:K})})]}),xe]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${O}-g3`,children:[t.jsx("h3",{id:`${O}-g3`,className:"bim-rd-sp-h",children:T("reader.groupLayout")}),x&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:T("reader.paragraphTitle"),onClick:()=>h({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:T("reader.paragraph")}),w&&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=>h({workLinks:K.target.checked})}),t.jsx("span",{children:T("reader.workLinks")})]}),b&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>h({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:T("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=>h({pageBreaks:K.target.checked})}),t.jsx("span",{children:T("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=>h({preserveMargins:K.target.checked})}),t.jsx("span",{children:T("reader.preserveMargins")})]}),Q]})]}),qe=f.useRef(null);return f.useEffect(()=>{const K=qe.current;if(!K||!R)return;let Ae=0,Qe=-1;const at=()=>{Ae=0;const tt=parseFloat(getComputedStyle(K).top);if(!Number.isFinite(tt))return;const xt=Math.max(0,Math.round(K.getBoundingClientRect().top-tt));xt!==Qe&&(Qe=xt,K.style.setProperty("--bimrd-img-lead",`${xt}px`))},lt=()=>{Ae||(Ae=requestAnimationFrame(at))};lt(),window.addEventListener("scroll",lt,{passive:!0}),window.addEventListener("resize",lt);const Tt=typeof ResizeObserver<"u"?new ResizeObserver(lt):null;return Tt==null||Tt.observe(document.body),()=>{window.removeEventListener("scroll",lt),window.removeEventListener("resize",lt),Tt==null||Tt.disconnect(),Ae&&cancelAnimationFrame(Ae),K.style.removeProperty("--bimrd-img-lead")}},[R]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&b?"bim-rd-vertical":"",je].filter(Boolean).join(" "),"data-toc":re,"data-img":R?"open":"closed","data-bb":de?"":void 0,"data-set":!de&&Ue?"open":void 0,"data-warp":le?"true":void 0,style:Ye,children:[t.jsx("style",{children:_c}),t.jsx("a",{className:"bim-rd-skip",href:`#${Z}`,onClick:K=>{var Ae,Qe,at;K.preventDefault(),(Ae=ze.current)==null||Ae.focus(),(at=(Qe=ze.current)==null?void 0:Qe.scrollIntoView)==null||at.call(Qe,{block:"start"})},children:T("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:oe,children:[S&&t.jsxs("a",{className:"bim-rd-back",href:S,"aria-label":T("reader.backAria",{label:fe}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:fe})]}),(e||n||y||k)&&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}),k&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:k})]}),n&&t.jsx("span",{className:"bim-rd-ttl-src",children:n})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":T("reader.settings"),children:[A&&A.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:me?G(Yr(me)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:T("reader.versionShort")}),t.jsx("select",{"aria-label":T("reader.version"),value:V??"",onChange:K=>He(K.target.value),children:A.map(K=>t.jsx("option",{value:K.key,children:G(Yr(K))},K.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),z&&(he||Ie)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":T("reader.pagerGroup",{unit:ae}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.prevUnit",{unit:ae}),title:he?typeof he.label=="string"&&he.label?T("reader.prevUnitTitle",{unit:ae,label:he.label}):T("reader.prevUnit",{unit:ae}):T("reader.firstUnit",{unit:ae}),disabled:!he,onClick:()=>he&&$e(he.key),children:t.jsx(lf,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.nextUnit",{unit:ae}),title:Ie?typeof Ie.label=="string"&&Ie.label?T("reader.nextUnitTitle",{unit:ae,label:Ie.label}):T("reader.nextUnit",{unit:ae}):T("reader.lastUnit",{unit:ae}),disabled:!Ie,onClick:()=>Ie&&$e(Ie.key),children:t.jsx(cf,{})})]}),z&&(he||Ie)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:ye,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Le,"aria-controls":Oe,onClick:ve,children:[t.jsx(wa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":R,onClick:()=>it(R?"closed":"open"),children:[t.jsx(_a,{}),T("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(df,{prefs:u,onPrefsChange:h,origAvailable:_}),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":T("reader.fontSmaller"),disabled:Se<=Dt[0],onClick:()=>h({fontSize:xi(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":T("reader.fontLarger"),disabled:Se>=Dt[Dt.length-1],onClick:()=>h({fontSize:xi(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:nt,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Ue,"aria-controls":O,onClick:()=>Ge(K=>!K),children:[t.jsx(Sa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.settings")})]}),Y]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:Oe,ref:We,role:Ve&&Le?"dialog":void 0,"aria-modal":Ve&&Le?!0:void 0,"aria-label":Ve&&Le?T("reader.toc"):void 0,onKeyDown:K=>{if(!(!Ve||!Le)){if(K.key==="Escape"){K.stopPropagation(),ge(!0);return}K.key==="Tab"&&$a(K,We.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??T("reader.toc")}),Ve&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeToc"),onClick:()=>ge(!0),children:"✕"})]}),l]}),t.jsx($c,{items:i,activeKey:s!==void 0?s:o,onSelect:$e})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>ge(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":T("reader.images"),ref:qe,children:R&&(se||t.jsx(Vr,{pages:c??null,loading:p,renderOverlay:m,preserveMargins:u.preserveMargins}))}),!de&&Ue&&t.jsxs("aside",{className:"bim-rd-set",id:O,"aria-label":T("reader.settings"),onKeyDown:K=>{var Ae;K.key==="Escape"&&(K.stopPropagation(),Ge(!1),(Ae=nt.current)==null||Ae.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:T("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeSettings"),onClick:()=>{var K;Ge(!1),(K=nt.current)==null||K.focus()},children:"✕"})]}),dt]}),t.jsxs("div",{className:"bim-rd-text",id:Z,ref:ze,tabIndex:-1,"data-rail":(v||C)&&!le?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[we,q&&me&&(me.sourceName||me.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":me.key,children:[me.sourceName&&t.jsxs(t.Fragment,{children:[T("reader.sourceLabel")," ",me.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:me.sourceUrl,target:"_blank",rel:"noreferrer",children:G(me.sourceName)}):G(me.sourceName)]}),me.sourceName&&me.license&&t.jsx("span",{className:"bim-rd-dot"}),me.license&&t.jsx(t.Fragment,{children:T("reader.licenseOf",{license:me.license})})]}),$&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:T("reader.revisedAt",{date:$})}),C&&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:X,children:T("reader.reportError")})}),z&&!E&&(he||Ie)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":T("reader.pagerNav"),children:[he?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>$e(he.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),T("reader.prevUnit",{unit:ae})]}),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:["← ",T("reader.firstUnit",{unit:ae})]}),Ie?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>$e(Ie.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[T("reader.nextUnit",{unit:ae}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:Ie.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[T("reader.lastUnit",{unit:ae})," →"]})]})]}),(v||C)&&!le&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":T("reader.rail"),children:[v,C&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:K=>K.preventDefault(),onClick:X,children:T("reader.reportError")})})]})]})]}),de&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":T("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":Le,"aria-controls":Oe,onClick:()=>{Ce(null),ve()},children:[t.jsx(wa,{}),t.jsx("span",{children:T("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":te==="img","aria-haspopup":"dialog",onClick:K=>W("img",K.currentTarget),children:[t.jsx(_a,{}),t.jsx("span",{children:T("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":te==="set","aria-haspopup":"dialog",onClick:K=>W("set",K.currentTarget),children:[t.jsx(Sa,{}),t.jsx("span",{children:T("reader.settingsShort")})]}),C&&t.jsxs("button",{type:"button",onMouseDown:K=>K.preventDefault(),onClick:()=>{Ce(null),X()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:T("reader.reportError")})]})]}),de&&te&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:pe}),t.jsxs("div",{className:"bim-rd-sheet",ref:ue,role:"dialog","aria-modal":"true","aria-label":T(te==="img"?"reader.images":"reader.settings"),onKeyDown:K=>{if(K.key==="Escape"){K.stopPropagation(),pe();return}K.key==="Tab"&&$a(K,ue.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:T(te==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.close"),onClick:pe,children:"✕"})]}),te==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Vr,{pages:c??null,loading:p,renderOverlay:m,preserveMargins:u.preserveMargins})}):dt]})]})]})}function gf(e,n,i){return i?Lc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(n).length?"convert-length":n.includes(":::")?"tables":null:"quoteStyle"}function Lc(e){return e.replace(/\r\n/g,`
739
+ `)}const za=2,ff=400,hf=6,Ac=e=>e==="*"||e==="#"||e==="<"||e===">"||/\s/.test(e);function Mc(e,n){if(e[n]!=="<"||e[n+1]!=="!"||e[n+2]!=="-"||e[n+3]!=="-")return-1;for(let i=n+4;i+2<e.length;i++)if(e[i]==="-"&&e[i+1]==="-"&&e[i+2]===">")return i+2;return-1}function xf(e,n,i){let o=n;for(let s=0;s<i.length;){if(o>=e.length)return-1;if(i[s]===e[o]){s++,o++;continue}const a=Mc(e,o);if(a>=0){o=a+1;continue}if(Ac(e[o])){o++;continue}if(i[s]===" "){s++;continue}return-1}return o}function bf(e){const n=Array.from(Lc(e));let i=0;return{align(o){if(!o)return;const s=Array.from(o);if(s.every(d=>d===" "||/\s/.test(d)))return;const a=s.length>=hf;let l=0;for(let d=i;d<n.length&&d-i<=(a?ff:za+64);d++){const c=Mc(n,d);if(c>=0){d=c;continue}if(!Ac(n[d])){const m=xf(n,d,s);if(m>=0)return i=m,d;if(l++,!a&&l>za)return}}}}}const yf=65536,jf="guji_markdown";function vf(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 kf=/^□\{guess=([^\s{}]+)\}/;function wf(e,n){const i=e[n+1];return i!==void 0&&!/[A-Za-z/!?>\s]/.test(i)}function Pc(e,n){let i=0;for(let o=n;o<e.length;o++){const s=e[o];if(s===`
740
+ `)return-1;if(s==="\\"){o++;continue}if(s==="[")i++;else if(s==="]"&&(i--,i===0))return o}return-1}function Sf(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function _f(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(`
741
+ `)<0?{node:{type:"qw",label:e.slice(n+2,o)},end:o+2}:null}if(i===":"&&e.startsWith(":zi[",n)){const o=Pc(e,n+3);return o>n+4?{node:{type:"zi",label:Sf(e.slice(n+4,o))},end:o+1}:null}if(i==="□"&&e[n+1]==="{"){const o=kf.exec(e.slice(n,n+64));if(o)return{node:{type:"qz",guess:o[1]},end:n+o[0].length}}return null}function Bc(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===`
742
+ `)return null}const m=_f(e,n);if(m){c(),a.push(m.node),n=m.end;continue}let g=null;if(p==="<"&&wf(e,n)&&(g=">"),g){const u=Bc(e,n+1,g,!0,s);if(u&&!(u.end-(n+1)>s)){c(),a.push({type:"jz",children:u.nodes}),n=u.end+1;continue}}l+=p,n++}return i!==null?null:(c(),{nodes:a,end:n})}function Oc(e,n){return Bc(e,0,null,!1,(n==null?void 0:n.jzMaxLength)??yf).nodes}function $f(e){return/[<□]|\[\[|:zi\[/.test(e)}function Wc(e){return e.map(n=>{switch(n.type){case"text":return n.text;case"jz":return`(${Wc(n.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return n.label}}).join("")}const Cf=216,Na="clamp(280px, 23vw, 360px)",zf=1440,qr="(max-width: 719px)",Nf=`${qr}, (pointer: coarse)`,Tf=`
743
+ .bim-d-main.bim-d-main-grid { max-width: ${zf}px; padding: 16px 32px 0; }
740
744
  .bim-d-grid {
741
745
  display: grid;
742
- grid-template-columns: ${_f}px minmax(0, 1fr) ${za};
746
+ grid-template-columns: ${Cf}px minmax(0, 1fr) ${Na};
743
747
  grid-template-rows: auto 1fr;
744
748
  grid-template-areas: "rail main card" "rail main side";
745
749
  column-gap: 32px; row-gap: 28px; align-items: start;
@@ -1092,7 +1096,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1092
1096
  .bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
1093
1097
 
1094
1098
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
1095
- @media ${Cf} {
1099
+ @media ${Nf} {
1096
1100
  .bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
1097
1101
  .bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
1098
1102
  .bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
@@ -1130,7 +1134,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1130
1134
  /* 中等宽度:左栏折到顶部一行 */
1131
1135
  @media (max-width: 1100px) {
1132
1136
  .bim-d-grid {
1133
- grid-template-columns: minmax(0, 1fr) ${za};
1137
+ grid-template-columns: minmax(0, 1fr) ${Na};
1134
1138
  grid-template-rows: auto auto 1fr;
1135
1139
  grid-template-areas: "rail rail" "main card" "main side";
1136
1140
  }
@@ -1144,7 +1148,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1144
1148
  }
1145
1149
 
1146
1150
  /* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
1147
- @media ${Yr} {
1151
+ @media ${qr} {
1148
1152
  .bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
1149
1153
  .bim-d-grid {
1150
1154
  grid-template-columns: minmax(0, 1fr);
@@ -1219,7 +1223,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1219
1223
  :root[data-layout="boxed"] .bim-d-g-rail { border: ${r("fr-bd")}; background: ${r("fr-bg")}; padding: 14px 8px; }
1220
1224
  :root[data-layout="boxed"] .bim-d-filters { border-bottom: 1px solid ${r("fr-tab-bd")}; }
1221
1225
  :root[data-layout="boxed"] .bim-d-filters .bim-d-tab { margin-bottom: -1px; }
1222
- @media ${Yr} {
1226
+ @media ${qr} {
1223
1227
  :root[data-layout="boxed"] .bim-d-card { padding: 16px; }
1224
1228
  :root[data-layout="boxed"] .bim-d-g-rail { border: 0; background: transparent; padding: 0; }
1225
1229
  }
@@ -1234,7 +1238,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1234
1238
  :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 {
1235
1239
  text-decoration-color: currentColor; text-decoration-thickness: 2px;
1236
1240
  }
1237
- `;function Qn({railTop:e,back:n,up:i,nav:o,railLinks:s,main:a,card:l,side:d}){const{t:c,convert:p}=re(),g=(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,g.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:g.map(m=>t.jsx("li",{children:t.jsxs("a",{href:`#${m.id}`,children:[t.jsx("span",{children:p(m.label)}),m.count!=null&&t.jsx("span",{className:"bim-d-meta",children:m.count})]})},m.id))})]}),s&&s.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("detail.more"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("detail.more")}),t.jsx("ul",{className:"bim-d-rail-nav",children:s.map(m=>t.jsx("li",{children:t.jsxs("a",{href:m.href??"#",onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),m.onClick())},children:[t.jsx("span",{children:p(m.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},m.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:a}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:d})]})}function Fc({caption:e,children:n}){const{convert:i}=re();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 ht({id:e,title:n,meta:i,action:o,children:s}){const{convert:a}=re();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 ft({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(f.Fragment,{children:[a>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},a))}):null}function Vi({items:e,value:n,onChange:i}){const{convert:o}=re();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 Hc({label:e,checked:n,onChange:i}){const{convert:o}=re();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,Gi=e=>e>Dc+1;function Mo({total:e,shown:n,unit:i,onClick:o}){const{t:s,convert:a}=re(),l=e-n,d=Gi(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 Po({label:e,onClick:n}){const{convert:i}=re();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function ei({kind:e,title:n,subtitle:i,byline:o,meta:s,description:a,clampDescription:l,facts:d,stats:c,readAction:p,secondaryAction:g,children:m,foot:u}){const{t:h,convert:x}=re(),j=(d||[]).filter(w=>w.value!=null&&w.value!==""),b=(c||[]).filter(w=>w.value!=null&&w.value!==""&&w.value!==0),[_,y]=f.useState(!1),k=!!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:k?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:k?{"--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:()=>y(w=>!w),children:h(_?"action.collapse":"action.expand")}),b.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:b.map((w,v)=>t.jsxs("div",{children:[t.jsx("b",{children:w.value}),t.jsx("span",{children:x(w.label)})]},v))}),j.length>0&&t.jsx("dl",{className:"bim-d-ui",children:j.map((w,v)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:x(w.label)}),t.jsx("dd",{title:w.title,children:w.value})]},v))}),m,p,g,u&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:u})]})}function Bo(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function qr({href:e,onClick:n,label:i}){const{t:o,convert:s}=re(),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 dn({id:e,title:n,meta:i,items:o,metas:s,currentIndex:a,cap:l=8,moreLabel:d,foot:c,sub:p,timeline:g}){const{t:m,convert:u}=re(),[h,x]=f.useState(!1);if(!o.length)return null;const j=h?o:o.slice(0,l),b=o.length-j.length;return t.jsxs("div",{id:e,className:g?"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:[u(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:j.map((_,y)=>t.jsxs("li",{className:y===a?"bim-d-side-cur":void 0,"aria-current":y===a?"page":void 0,children:[_,s!=null&&s[y]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[y]}):null]},y))}),b>0&&t.jsx(Po,{label:d?d(b):m("detail.showMore",{n:b}),onClick:()=>x(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const Nf=new Set(["reviewed","disputed","unreviewed","draft"]);function ti({revision:e,revisedAt:n,review:i,todo:o}){const{t:s,convert:a}=re(),l=i&&Nf.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(g=>g&&g.what);return!c.length&&!p.length?null:t.jsxs(t.Fragment,{children:[c.length>0&&t.jsx(ft,{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((g,m)=>t.jsxs("li",{children:[a(g.what),(g.by||g.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[g.by&&a(g.by),g.date].filter(Boolean).join(" · "),")"]})]},m))})]})]})}const wi=1e3,Na=208,Tf=1440,If="(max-width: 719px)",Uc=`
1241
+ `;function ei({railTop:e,back:n,up:i,nav:o,railLinks:s,main:a,card:l,side:d}){const{t:c,convert:p}=ie(),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(g=>t.jsx("li",{children:t.jsxs("a",{href:`#${g.id}`,children:[t.jsx("span",{children:p(g.label)}),g.count!=null&&t.jsx("span",{className:"bim-d-meta",children:g.count})]})},g.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(g=>t.jsx("li",{children:t.jsxs("a",{href:g.href??"#",onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),g.onClick())},children:[t.jsx("span",{children:p(g.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},g.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 Fc({caption:e,children:n}){const{convert:i}=ie();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 ht({id:e,title:n,meta:i,action:o,children:s}){const{convert:a}=ie();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 ft({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(f.Fragment,{children:[a>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:s})]},a))}):null}function Gi({items:e,value:n,onChange:i}){const{convert:o}=ie();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 Hc({label:e,checked:n,onChange:i}){const{convert:o}=ie();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,Yi=e=>e>Dc+1;function Po({total:e,shown:n,unit:i,onClick:o}){const{t:s,convert:a}=ie(),l=e-n,d=Yi(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 Bo({label:e,onClick:n}){const{convert:i}=ie();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:n,children:i(e)})}function ti({kind:e,title:n,subtitle:i,byline:o,meta:s,description:a,clampDescription:l,facts:d,stats:c,readAction:p,secondaryAction:m,children:g,foot:u}){const{t:h,convert:x}=ie(),j=(d||[]).filter(w=>w.value!=null&&w.value!==""),b=(c||[]).filter(w=>w.value!=null&&w.value!==""&&w.value!==0),[_,y]=f.useState(!1),k=!!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:k?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:k?{"--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:()=>y(w=>!w),children:h(_?"action.collapse":"action.expand")}),b.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:b.map((w,v)=>t.jsxs("div",{children:[t.jsx("b",{children:w.value}),t.jsx("span",{children:x(w.label)})]},v))}),j.length>0&&t.jsx("dl",{className:"bim-d-ui",children:j.map((w,v)=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:x(w.label)}),t.jsx("dd",{title:w.title,children:w.value})]},v))}),g,p,m,u&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:u})]})}function Oo(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Kr({href:e,onClick:n,label:i}){const{t:o,convert:s}=ie(),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 dn({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:g,convert:u}=ie(),[h,x]=f.useState(!1);if(!o.length)return null;const j=h?o:o.slice(0,l),b=o.length-j.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:[u(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:j.map((_,y)=>t.jsxs("li",{className:y===a?"bim-d-side-cur":void 0,"aria-current":y===a?"page":void 0,children:[_,s!=null&&s[y]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:s[y]}):null]},y))}),b>0&&t.jsx(Bo,{label:d?d(b):g("detail.showMore",{n:b}),onClick:()=>x(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const Ef=new Set(["reviewed","disputed","unreviewed","draft"]);function ni({revision:e,revisedAt:n,review:i,todo:o}){const{t:s,convert:a}=ie(),l=i&&Ef.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(ft,{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,g)=>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(" · "),")"]})]},g))})]})]})}const Si=1e3,Ta=208,If=1440,Rf="(max-width: 719px)",Uc=`
1238
1242
  .bim-d-page {
1239
1243
  background: ${r("page-bg")};
1240
1244
  color: ${r("ink")};
@@ -1243,7 +1247,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1243
1247
  padding-bottom: 64px;
1244
1248
  }
1245
1249
  .bim-d-main {
1246
- max-width: ${wi}px;
1250
+ max-width: ${Si}px;
1247
1251
  margin: 0 auto;
1248
1252
  padding: 24px clamp(16px, 4vw, 28px) 0;
1249
1253
  }
@@ -1254,7 +1258,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1254
1258
  * PAGE_MAX_WIDTH,读者的行宽体验不变。
1255
1259
  */
1256
1260
  .bim-d-main.bim-d-main-wide {
1257
- max-width: ${Tf}px;
1261
+ max-width: ${If}px;
1258
1262
  }
1259
1263
  .bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
1260
1264
 
@@ -1286,9 +1290,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1286
1290
  */
1287
1291
  .bim-d-reader {
1288
1292
  display: grid;
1289
- grid-template-columns: ${Na}px minmax(0, ${wi}px);
1293
+ grid-template-columns: ${Ta}px minmax(0, ${Si}px);
1290
1294
  gap: 32px;
1291
- max-width: ${Na+wi+32}px;
1295
+ max-width: ${Ta+Si+32}px;
1292
1296
  margin: 0 auto;
1293
1297
  align-items: start;
1294
1298
  }
@@ -1311,7 +1315,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1311
1315
  align-items: start; margin-bottom: 48px; }
1312
1316
  .bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
1313
1317
 
1314
- @media ${If} {
1318
+ @media ${Rf} {
1315
1319
  .bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
1316
1320
  .bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
1317
1321
  /* 表格:meta 列折到第二行,表头隐藏 */
@@ -1329,20 +1333,20 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r("tint-bg"
1329
1333
  padding-right: 0; padding-bottom: 12px;
1330
1334
  }
1331
1335
  }
1332
- ${zf}`;function Un({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Uc}),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 Kr({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 Oo({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 Xr({items:e}){const n=mt();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(f.Fragment,{children:[a,d]},o)})})}function Vc({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 Ef({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 Rf({items:e,horizontal:n}){const{convert:i}=De();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 Lf({glyph:e,tone:n,title:i,count:o,actions:s,id:a}){const{convert:l}=De();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(Oo,{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 Gc({label:e,active:n,onClick:i,dashed:o}){const{convert:s}=De();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 Af({label:e,onClick:n}){const{convert:i}=De();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 Mf({label:e,onClick:n,inline:i}){const{convert:o}=De();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 Yc({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 Pf({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Bf({volumes:e,unit:n,max:i=60}){const{t:o}=re(),s=n??o("unit.volume"),[a,l]=f.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 Of({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${r("rule-strong")}`},children:e})}function Wf({spec:e}){const{convert:n}=De();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 Ff({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 Hf(e){return String(e+1).padStart(2,"0")}function Df(){return t.jsx("span",{style:{color:r("hint-fg")},children:"—"})}function Uf({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 qc(e){const n=[];for(let i=0;i<e.length;i++){if(e[i]!=="<")continue;const s=e[i+1];if(s===void 0||/[A-Za-z/!?>\s]/.test(s))continue;const l=e.indexOf(">",i+1);if(l<0)continue;const d=e.slice(i+1,l);d.includes(`
1333
- `)||(n.push({start:i,end:l+1,inner:d}),i=l)}return n}function Kc(e,n){if(e.length<=n)return e;let i=n;for(const o of qc(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},Vf={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 Zc(e,n,i,o){return e.map((s,a)=>{switch(s.type){case"text":return t.jsx(f.Fragment,{children:n(s.text)},a);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?Xc:void 0,children:Zc(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:Vf,children:s.label},a)}})}function Ct(e,n=o=>o,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return Sf(e)?Zc(Oc(e,{jzMaxLength:i.jzMaxLength}),n,0,i.t??Nn("zh-Hant")):n(e);if(e.indexOf("<")<0)return n(e);const o=[];let s=0,a=0;for(const l of qc(e))l.start>s&&o.push(t.jsx(f.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(f.Fragment,{children:n(e.slice(s))},a++)),o}function Gf({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 Yf({title:e,tag:n,children:i}){const{convert:o}=De();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 Jc({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 qf({item:e,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{t:s,convert:a}=re(),[l,d]=f.useState(!1),c=Li(e),p=i&&!!c&&c.expected>0,g=(e.url?$n(e.url):void 0)||a(e.name),m=n?Kl(e,n):"",u=m?`${g}(${m})`:g;return t.jsx(Jc,{name:u,note:Oi(e,s)||o,href:Cn(e),extra:p?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(h=>!h),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(Wo,{item:e})]}):void 0})}function Wo({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 Qc({label:e,items:n}){const{convert:i}=De();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(Yc,{children:i(o)},s))]}):null}function Kf({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(Qc,{label:i.label,items:i.items},i.label))}):null}function Zr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ed({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 Xf({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 pt({id:e,label:n,onNavigate:i,renderLink:o,style:s,dense:a}){const l=mt();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 Zf({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 td="guji-table-v1";function Jf(e){return!!e&&e.table_notation===td}const Qf=/^:::table(?:\{[^}]*\})?[ \t]*$/,eh=/^:::[ \t]*$/;function nd(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=Pc(e,o+3);if(l>o+4){i+=e.slice(o,l+1),o=l;continue}}let a=null;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 th=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function nh(e){if(e==="^")return{cont:!0};const n=th.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 id(e,n=1){const i=[],o=[],s=[];let a=[];e.forEach((d,c)=>{const p=c+n+1;let g=d.trim();if(!g)return;let m=!1;g.startsWith("!")&&(m=!0,g=g.slice(1));const u=nd(g).map(nh),h=a.map(_=>_>0),x=a.map(_=>_>0?_-1:0),j=[];let b=0;for(const _ of u){if(_.cont){h[b]||i.push(`第 ${p} 行第 ${b+1} 列:续格 ^ 上方没有跨行格`),b+=1;continue}const{cell:y}=_;for(let k=b;k<b+y.colspan;k++)if(h[k]){i.push(`第 ${p} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let k=b;k<b+y.colspan;k++)x[k]=y.rowspan-1;j.push(y),b+=y.colspan}for(let _=b;_<h.length;_++)h[_]&&i.push(`第 ${p} 行第 ${_+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let _=0;_<x.length;_++)x[_]===void 0&&(x[_]=0);a=x,o.push({header:m,cells:j}),s.push({width:b,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 Fo(e){const n=e.split(`
1336
+ ${Tf}`;function Un({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{className:"bim-d-page",style:n,children:[t.jsx("style",{children:Uc}),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 Xr({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 Wo({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 Zr({items:e}){const n=mt();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(f.Fragment,{children:[a,d]},o)})})}function Vc({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 Lf({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 Af({items:e,horizontal:n}){const{convert:i}=De();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 Mf({glyph:e,tone:n,title:i,count:o,actions:s,id:a}){const{convert:l}=De();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(Wo,{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 Gc({label:e,active:n,onClick:i,dashed:o}){const{convert:s}=De();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 Pf({label:e,onClick:n}){const{convert:i}=De();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 Bf({label:e,onClick:n,inline:i}){const{convert:o}=De();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 Yc({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 Of({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function Wf({volumes:e,unit:n,max:i=60}){const{t:o}=ie(),s=n??o("unit.volume"),[a,l]=f.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 Ff({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${r("rule-strong")}`},children:e})}function Hf({spec:e}){const{convert:n}=De();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 Df({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 Uf(e){return String(e+1).padStart(2,"0")}function Vf(){return t.jsx("span",{style:{color:r("hint-fg")},children:"—"})}function Gf({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 qc(e){const n=[];for(let i=0;i<e.length;i++){if(e[i]!=="<")continue;const s=e[i+1];if(s===void 0||/[A-Za-z/!?>\s]/.test(s))continue;const l=e.indexOf(">",i+1);if(l<0)continue;const d=e.slice(i+1,l);d.includes(`
1337
+ `)||(n.push({start:i,end:l+1,inner:d}),i=l)}return n}function Kc(e,n){if(e.length<=n)return e;let i=n;for(const o of qc(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},Yf={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 Zc(e,n,i,o){return e.map((s,a)=>{switch(s.type){case"text":return t.jsx(f.Fragment,{children:n(s.text)},a);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:i===0?Xc:void 0,children:Zc(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:Yf,children:s.label},a)}})}function Ct(e,n=o=>o,i){if(!e)return"";if(i!=null&&i.gujiMarkdown)return $f(e)?Zc(Oc(e,{jzMaxLength:i.jzMaxLength}),n,0,i.t??Nn("zh-Hant")):n(e);if(e.indexOf("<")<0)return n(e);const o=[];let s=0,a=0;for(const l of qc(e))l.start>s&&o.push(t.jsx(f.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(f.Fragment,{children:n(e.slice(s))},a++)),o}function qf({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 Kf({title:e,tag:n,children:i}){const{convert:o}=De();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 Jc({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 Xf({item:e,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{t:s,convert:a}=ie(),[l,d]=f.useState(!1),c=Ai(e),p=i&&!!c&&c.expected>0,m=(e.url?$n(e.url):void 0)||a(e.name),g=n?Kl(e,n):"",u=g?`${m}(${g})`:m;return t.jsx(Jc,{name:u,note:Wi(e,s)||o,href:Cn(e),extra:p?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(h=>!h),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(Fo,{item:e})]}):void 0})}function Fo({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 Qc({label:e,items:n}){const{convert:i}=De();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(Yc,{children:i(o)},s))]}):null}function Zf({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(Qc,{label:i.label,items:i.items},i.label))}):null}function Jr(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ed({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 Jf({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 ut({id:e,label:n,onNavigate:i,renderLink:o,style:s,dense:a}){const l=mt();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 Qf({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 td="guji-table-v1";function eh(e){return!!e&&e.table_notation===td}const th=/^:::table(?:\{[^}]*\})?[ \t]*$/,nh=/^:::[ \t]*$/;function nd(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=Pc(e,o+3);if(l>o+4){i+=e.slice(o,l+1),o=l;continue}}let a=null;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 ih=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function rh(e){if(e==="^")return{cont:!0};const n=ih.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 id(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 g=!1;m.startsWith("!")&&(g=!0,m=m.slice(1));const u=nd(m).map(rh),h=a.map(_=>_>0),x=a.map(_=>_>0?_-1:0),j=[];let b=0;for(const _ of u){if(_.cont){h[b]||i.push(`第 ${p} 行第 ${b+1} 列:续格 ^ 上方没有跨行格`),b+=1;continue}const{cell:y}=_;for(let k=b;k<b+y.colspan;k++)if(h[k]){i.push(`第 ${p} 行第 ${k+1} 列:此处被上方跨行格占住,应写 ^`);break}if(y.rowspan>1)for(let k=b;k<b+y.colspan;k++)x[k]=y.rowspan-1;j.push(y),b+=y.colspan}for(let _=b;_<h.length;_++)h[_]&&i.push(`第 ${p} 行第 ${_+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let _=0;_<x.length;_++)x[_]===void 0&&(x[_]=0);a=x,o.push({header:g,cells:j}),s.push({width:b,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 Ho(e){const n=e.split(`
1334
1338
  `),i=[];let o=[];const s=()=>{if(o.length===0)return;const l=o.join(`
1335
- `);o=[],i.push({type:"text",text:l})};let a=0;for(;a<n.length;){if(Qf.test(n[a].trim())){let l=a+1;for(;l<n.length&&!eh.test(n[l].trim());)l++;if(l<n.length){s();const d=n.slice(a+1,l);i.push({type:"table",table:id(d,a+1),source:n.slice(a,l+1).join(`
1336
- `)}),a=l+1;continue}}o.push(n[a]),a++}return s(),i.map((l,d)=>{var p,g;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+/,"")),((g=i[d+1])==null?void 0:g.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(l=>l.type!=="text"||l.text!=="")}const ih={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},rh={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},oh=`1px solid ${r("table-border")}`,rd={border:oh,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},sh={...rd,background:r("table-head-bg"),fontWeight:600};function Ho({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:ih,children:t.jsx("table",{className:"bim-guji-table",style:rh,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?sh:rd,children:s.empty?null:Ct(s.text,void 0,n)},a)})},o))})})})}function ah(e,n){return e.indexOf("**")<0?Ct(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((o,s)=>s%2===1?t.jsx("strong",{children:Ct(o.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ct(o,void 0,n)},s))}function lh(e,n,i=!1){const o=i?{gujiMarkdown:!0}:void 0;return n?Fo(e).map((s,a)=>s.type==="table"?t.jsx(Ho,{table:s.table,opts:o},a):t.jsx(f.Fragment,{children:ah(s.text,o)},a)):Ct(e,void 0,o)}const ch=/^(#{1,6})\s+(.*)$/,dh=/^\*\*([^*\n]+)\*\*\s*$/;function Do(e){const n=e.match(ch);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(dh);return i?{level:3,text:i[1].trim()}:null}const Uo=/^<!--.*-->$/;function od(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function sd(e){return e.split(`
1337
- `).map(n=>n.trim()).filter(n=>n&&!Uo.test(n))}const ph=60;function ad(e){let n=0,i=0;for(const o of e.split(`
1338
- `)){const s=o.trim();if(!s||Uo.test(s)||Do(s))continue;const a=s.replace(/<[^<>\n]*>/g,"").replace(/\s/g,"").length;n+=a,a>ph&&(i+=a)}return n>0&&i*2>=n}function uh(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Yi(e){if(e=uh(e),ad(e))return"unknown";const n=od(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>sd(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 mh(e){const n=e.split(`
1339
+ `);o=[],i.push({type:"text",text:l})};let a=0;for(;a<n.length;){if(th.test(n[a].trim())){let l=a+1;for(;l<n.length&&!nh.test(n[l].trim());)l++;if(l<n.length){s();const d=n.slice(a+1,l);i.push({type:"table",table:id(d,a+1),source:n.slice(a,l+1).join(`
1340
+ `)}),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 oh={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},sh={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},ah=`1px solid ${r("table-border")}`,rd={border:ah,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},lh={...rd,background:r("table-head-bg"),fontWeight:600};function Do({table:e,opts:n}){return t.jsx("div",{className:"bim-guji-table-wrap",style:oh,children:t.jsx("table",{className:"bim-guji-table",style:sh,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?lh:rd,children:s.empty?null:Ct(s.text,void 0,n)},a)})},o))})})})}function ch(e,n){return e.indexOf("**")<0?Ct(e,void 0,n):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((o,s)=>s%2===1?t.jsx("strong",{children:Ct(o.trim().slice(2,-2),void 0,n)},s):t.jsx(f.Fragment,{children:Ct(o,void 0,n)},s))}function dh(e,n,i=!1){const o=i?{gujiMarkdown:!0}:void 0;return n?Ho(e).map((s,a)=>s.type==="table"?t.jsx(Do,{table:s.table,opts:o},a):t.jsx(f.Fragment,{children:ch(s.text,o)},a)):Ct(e,void 0,o)}const ph=/^(#{1,6})\s+(.*)$/,uh=/^\*\*([^*\n]+)\*\*\s*$/;function Uo(e){const n=e.match(ph);if(n)return{level:n[1].length,text:n[2].trim()};const i=e.trim().match(uh);return i?{level:3,text:i[1].trim()}:null}const Vo=/^<!--.*-->$/;function od(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean)}function sd(e){return e.split(`
1341
+ `).map(n=>n.trim()).filter(n=>n&&!Vo.test(n))}const mh=60;function ad(e){let n=0,i=0;for(const o of e.split(`
1342
+ `)){const s=o.trim();if(!s||Vo.test(s)||Uo(s))continue;const a=s.replace(/<[^<>\n]*>/g,"").replace(/\s/g,"").length;n+=a,a>mh&&(i+=a)}return n>0&&i*2>=n}function gh(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function qi(e){if(e=gh(e),ad(e))return"unknown";const n=od(e);if(n.length===0)return"unknown";if(n.length===1)return"catalog";const i=n.map(s=>sd(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 fh(e){const n=e.split(`
1339
1343
  `),i=[];let o=null,s=[];const a=()=>{i.push({heading:o,body:s.join(`
1340
- `)}),s=[]};for(const l of n){const d=Do(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(`
1341
- `)){const o=Do(i);if(o){n.push({kind:"heading",level:o.level,text:o.text});continue}const s=i.trim();!s||Uo.test(s)||n.push({kind:"body",text:i})}return n}function ld(e){if(!e)return[];const n=Yi(e);if(n==="unknown")return Ta(e);const i=[];for(const{heading:o,body:s}of mh(e)){o&&i.push(o);const a=od(s);if(a.length!==0){if(ad(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=sd(l);d.length&&i.push({kind:"body",text:d.join(" ")})}}}return i}const gh={"「":"“","」":"”","『":"‘","』":"’"},fh={"“":"「","”":"」","‘":"『","’":"』"},hh=new Set(["《","》","〈","〉"]);function cd(e,n){const i=n.quoteStyle==="modern"?gh:n.quoteStyle==="classic"?fh:null;let o="";for(const s of e)n.hideBookBrackets&&hh.has(s)||(o+=(i==null?void 0:i[s])??s);return o}const dd=e=>e;function Vo(e){return e.showWorks?e.bookTitleStyle==="bracket"?"bracket":ef(e.properNameMode)?"wavy":"bracket":"none"}function pd(e,n=dd,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(f.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(f.Fragment,{children:c},l++)),a=d.index+d[0].length}return a===0?n(e):(a<e.length&&o.push(t.jsx(f.Fragment,{children:n(e.slice(a))},l++)),o)}function qi(e,n={}){let i=n.renderText??dd;const o=n.quoteStyle;if(o&&o!=="original"){const d=i;i=c=>d(cd(c,{quoteStyle:o}))}const s=n.bookMarking??(n.properNames?"wavy":"bracket"),a=s==="bracket"?i:d=>pd(d,i,s),l=n.gujiMarkdown?{gujiMarkdown:!0,t:n.t}:void 0;return Ct(e,a,l)}function Ia(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(f.Fragment,{children:n(s)},`${i}-${a}`))}const $r=/^(#{1,6})\s+(.*)$/,xh=/^\s*<!--.*-->\s*$/;function ud(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1342
- `)?"":n)}function bh(e){return e<=1?2:e===2?3:4}function yh(){let e=1;return n=>{const i=bh(n),o=Math.min(i,e+1);return e=o,{Tag:`h${o}`,className:`bim-rd-hl${i}`}}}function Ti(e){return e?Yi(ud(e))!=="unknown":!1}function jh(e){return/^\u3000{2}/.test(e)}const Ea=e=>jh(e)?"bim-rd-noindent":void 0;function Ra({text:e,mode:n,inline:i,dropTitle:o,onStart:s}){s==null||s();const a=ud(e),l=(g,m,u)=>!!o&&u<=1&&g<=2&&m.trim()===o.trim(),d=yh();if(n==="paragraph"&&Yi(a)!=="unknown"){const g=ld(a);return t.jsx(t.Fragment,{children:g.map((m,u)=>{if(m.kind==="heading"){if(l(m.level??1,m.text,u))return null;const{Tag:h,className:x}=d(m.level??1);return t.jsx(h,{className:x,children:i(m.text)},u)}return t.jsx("p",{className:Ea(m.text),children:Ia(m.text,i,u)},u)})})}const c=a.split(`
1343
- `);let p=0;return t.jsx(t.Fragment,{children:c.map((g,m)=>{const u=g.match($r);if(u){const x=p++;if(l(u[1].length,u[2],x))return null;const{Tag:j,className:b}=d(u[1].length);return t.jsx(j,{className:b,children:i(u[2])},m)}if(!g.trim())return m>=2&&!!c[m-1].trim()&&!!c[m-2].trim()&&!$r.test(c[m-1])&&!$r.test(c[m-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},m):null;if(xh.test(g))return null;if(p++,/^\*\*[^*]+\*\*\s*$/.test(g.trim())){const{Tag:x,className:j}=d(3);return t.jsx(x,{className:j,children:i(g.trim().slice(2,-2))},m)}return t.jsx("p",{className:Ea(g),children:Ia(g,i,m)},m)})})}function vh(e){const{convert:n}=De();return f.useMemo(()=>e?n(e):"",[e,n])}function Go({text:e,mode:n,tables:i=!1,gujiMarkdown:o=!1,properNames:s=!1,bookMarking:a,quoteStyle:l,renderText:d,dropTitle:c}){const p=vh(e),{t:g,convert:m}=re();let u=null;const h=!!d&&!uf(e,p,!l||l==="original"),x=d&&h?k=>d(k,{mdStart:u==null?void 0:u.align(k)}):d,j=h?()=>{u=hf(e)}:void 0,b=k=>qi(k,{renderText:x,properNames:s,bookMarking:a,quoteStyle:l,gujiMarkdown:o,t:g}),_=o?{gujiMarkdown:!0,t:g}:void 0,y=c?m(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(Ra,{text:p,mode:n,inline:b,dropTitle:y,onStart:j}):t.jsx(t.Fragment,{children:Fo(p).map((k,w)=>k.type==="table"?t.jsx(Ho,{table:k.table,opts:_},w):t.jsx(Ra,{text:k.text,mode:n,inline:b,dropTitle:w===0?y:void 0},w))})}const La={work:"work",book:"work",people:"people",person:"people",place:"place",office:"office",dynasty:"dynasty",reign:"reign"};function kh(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(La,e)&&La[e]||"other"}function Jr(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 Jt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function ut(e){return typeof e=="string"&&e?e:void 0}function wh(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={};ut(s.entity_id)!==void 0&&(a.entity_id=ut(s.entity_id)),ut(s.canonical_name)!==void 0&&(a.canonical_name=ut(s.canonical_name)),Jt(s.confidence)!==void 0&&(a.confidence=Jt(s.confidence)),i.push(a)}return i}const jn=e=>e.start!==void 0&&e.end!==void 0;function md(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=Jt(l.start_offset)??Jt(a.start_offset),p=Jt(l.end_offset)??Jt(a.end_offset),g=c!==void 0&&p!==void 0&&c>=0&&p>c,m=a.anchor??{},u=ut(m.start),h=ut(m.end);if(!g&&!!!(u&&h))return;const j=ut(d.status),b=j===void 0||j==="matched"?Jr(ut(d.entity_id))??Jr(ut(d.href))??void 0:void 0,_=Jt(d.confidence),y=wh(a.ambiguous);i.push({...u&&h?{anchor:{start:u,end:h}}:{},key:ut(a.id)??`e${s}`,kind:kh(a.type),...g?{start:c,end:p}:{},text:ut(a.text),targetId:b,canonicalName:ut(d.canonical_name),confidence:Jt(a.confidence)??_,..._!==void 0?{targetConfidence:_}:{},...ut(d.level)!==void 0?{targetLevel:ut(d.level)}:{},...ut(d.note)!==void 0?{targetNote:ut(d.note)}:{},...ut(a.group)!==void 0?{group:ut(a.group)}:{},...y!==void 0?{candidates:y}:{}})}),i.sort((o,s)=>!jn(o)||!jn(s)?+!jn(o)-+!jn(s):o.start-s.start||s.end-o.end)}const Sh=new Set(Array.from(`《》/<>\r
1344
-  ,。、;:?!「」『』()…—·`));function Yo(e){return!Sh.has(e)}function gd(e,n,i=0){const o=[],s=Array.from(e);let a=0;for(const d of s)Yo(d)&&o.push(a),a+=d.length;const l=[];for(const d of n){if(!jn(d))continue;const c=d.start-i,p=d.end-i;if(c<0||p>o.length||p<=c)continue;const g=o[p-1],m=e.codePointAt(g)>65535?2:1;l.push({...d,start:o[c],end:g+m})}return l}function _h(e,n){return n.text?Array.from(e.slice(n.start,n.end)).filter(Yo).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 fd(e,n,i=16){const o=[];for(const l of n){if(!jn(l))continue;let d={...l,start:Math.max(0,l.start),end:Math.min(e.length,l.end)};(d.end<=d.start||!_h(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 Ch={off:[],lite:["people","place","dynasty"],full:["people","place","dynasty","office","reign","other"]};function zh(e,n,i){const o=(i==null?void 0:i.showWorks)!==!1,s=new Set(Ch[n]);return e.filter(a=>a.kind==="work"?o:s.has(a.kind))}function Nh(e,n,i){const[o,s]=f.useState(null),[a,l]=f.useState(!1),d=f.useRef(0);return f.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(g=>{c===d.current&&s(g??null)}).catch(()=>{c===d.current&&s(null)}).finally(()=>{c===d.current&&l(!1)})},[e,n,i]),{images:o,loading:a}}function Th(){let e=null;const n=new Set;return{get:()=>e,set:i=>{i!==e&&(e=i,n.forEach(o=>o()))},subscribe:i=>(n.add(i),()=>{n.delete(i)})}}function Ih(e){return f.useSyncExternalStore(e.subscribe,e.get,e.get)}function Aa({store:e,children:n}){const i=Ih(e);return f.createElement(f.Fragment,null,n(i))}function Eh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(Pu,e)?e:null}function Rh(e){if(e==="none")return{color:r("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r("quality-placeholder"),fontWeight:400}}const Lh={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},hd="\0";function Ah(e,n,i){const[o,s=""]=e.split(hd);return t.jsxs(t.Fragment,{children:[o,t.jsx(kc,{text:n,convert:i}),s]})}function Nt(e){return typeof e!="string"?"":Lh[e]??e}const Mh=["〇","一","二","三","四","五","六","七","八","九"],Ma=["","十","百","千"],Ph=["","萬","億"];function qo(e){if(e===0)return"〇";if(e<0)return`負${qo(-e)}`;const n=[];let i=e,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Bh(s,o>0)+Ph[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Bh(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+=Ma[d]:s+=Mh[l]+Ma[d]}return s.replace(/〇$/,"")}let qn=null,xi=null;const Ii=new Set;function Oh(){return qn?Promise.resolve():xi||(xi=import("opencc-js/t2cn").then(e=>{const n=e.Converter({from:"t",to:"cn"});qn=i=>n(Ie.normalizeVariants(i)),Ii.forEach(i=>i())}).catch(()=>{qn=e=>e,Ii.forEach(e=>e())}),xi)}const Wh=e=>e;function mn(){const[,e]=f.useState(0);return f.useEffect(()=>{if(qn)return;const n=()=>e(i=>i+1);return Ii.add(n),Oh(),()=>{Ii.delete(n)}},[]),qn??Wh}function _n(e,n){return n(e).toLowerCase()}const Fh=r("highlight-bg");function ni(e,n,i){if(!n)return e;const o=_n(n,i);if(!o)return e;const s=_n(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,j)=>{d.set(c,j),c+=x.length});const p=Array.from(o).length,g=[];let m=0,u=0,h=0;for(;m<a.length;){const x=s.indexOf(o,u),j=x===-1?void 0:d.get(x);if(x===-1){g.push(a.slice(m).join(""));break}if(j===void 0){u=x+1;continue}j>m&&g.push(a.slice(m,j).join("")),g.push(t.jsx("mark",{style:{background:Fh,padding:0,color:"inherit"},children:a.slice(j,j+p).join("")},h++)),m=j+p,u=x+o.length}return t.jsx(t.Fragment,{children:g})}function Ko(e,n,i,o){if(!n)return!0;const s=_n(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"&&_n(l,o).includes(s))}function Hh(e,n,i){return n?_n(e,i).includes(_n(n,i)):!0}const Xo={类:r("section-lei"),书:r("section-shu"),序:r("section-xu"),结语:r("section-jieyu"),注释:r("section-zhushi")},Dh={考证:r("section-kaozhen")};function Zo(e,n,i){return e.collated.sectionType[n]??i(n)}function xd(e){var o;const n=e.files.length,i=((o=e.children)==null?void 0:o.reduce((s,a)=>s+xd(a),0))||0;return n+i}function Uh(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 Vh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Jo({enabled:e,expanded:n,onClick:i,style:o,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...Vh,...o},children:s}):t.jsx("span",{style:o,children:s})}function Gh({type:e}){const{convert:n,messages:i}=re(),o=Nt(e),s=Xo[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 Yh({section:e,onNavigate:n,highlightQuery:i="",no:o,showUnlinked:s=!1,domId:a}){const{t:l,convert:d}=re(),c=mt(),p=mn(),g=k=>k?Ct(d(k),w=>i?ni(w,i,p):w,{t:l}):"",[m,u]=f.useState(!1),h=!!e.summary,x=!!e.comment,j=!!e.additional_comment,b=!!(e.content&&e.content.length>60),_=h||x||j||b;f.useEffect(()=>{i&&u(!0)},[i]);const y=!m&&b?Kc(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:()=>_&&u(!m),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(Jo,{enabled:_,expanded:m,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:m?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:r("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",g(e.book_title),"》"]}):g(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(qo(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:r("desc-fg"),marginLeft:"8px"},children:g(e.author_info||e.author)})]}),!m&&y&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:r("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:g(y)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:g(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:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.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")})]}),m&&_&&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:g(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:g(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:g(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:g(e.additional_comment)})]}),b&&!h&&!x&&!j&&t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:g(e.content)})]})]})}function qh({section:e,highlightQuery:n=""}){const{t:i,convert:o}=re(),s=mn(),a=p=>p?Ct(o(p),g=>n?ni(g,n,s):g,{t:i}):"",[l,d]=f.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Jo,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Gh,{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, ${Xo[Nt(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 Kh=100;function Qo(e){return Nt(e.type)!=="page_header"?!1:(e.content||"").length>=Kh}function Xh({section:e,highlightQuery:n=""}){const{t:i,convert:o,messages:s}=re(),a=mn();if(Nt(e.type)==="page_header"&&!Qo(e)||!e.content&&!e.title)return null;const l=o((e.content||e.title||"").replace(/\n{2,}/g,`
1345
- `)),d=Ct(l,m=>n?ni(m,n,a):m,{t:i}),c=Nt(e.type),p=Xo[c]||r("desc-fg"),g=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:g?"10px 12px":"6px 0",margin:g?"8px 0":void 0,fontSize:"13px",color:r("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:g?`3px solid ${p}40`:void 0,background:g?r("bg"):void 0,borderRadius:g?"0 4px 4px 0":void 0,position:"relative"},children:[g&&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 Zh(e,n,i){const[o,s]=f.useState({});return f.useEffect(()=>{var p;if(!n||e.length===0)return;let a=!1;const l=e.filter(g=>{var m;return!((m=i==null?void 0:i.current)!=null&&m.has(g))}),d={};for(const g of e)(p=i==null?void 0:i.current)!=null&&p.has(g)&&(d[g]=i.current.get(g));if(Object.keys(d).length>0&&s(d),l.length===0)return;const c=async g=>{var m;try{if(n.getEntry){const b=await n.getEntry(g);if(b)return{title:b.title,author:b.author}}const u=await n.getItem(g);if(!u)return null;const h=u.title||g,x=u.authors,j=(m=x==null?void 0:x[0])==null?void 0:m.name;return{title:h,author:j}}catch{return null}};return Promise.all(l.map(async g=>{var u;const m=await c(g);return(u=i==null?void 0:i.current)==null||u.set(g,m),[g,m]})).then(g=>{a||s(m=>{const u={...m};for(const[h,x]of g)u[h]=x;return u})}),()=>{a=!0}},[e.join(","),n]),o}function Jh({section:e,onNavigate:n,transport:i,workLabelCache:o,highlightQuery:s=""}){const{t:a,convert:l,messages:d}=re(),c=mt(),p=mn(),g=w=>w?Ct(l(w),v=>s?ni(v,s,p):v,{t:a}):"",[m,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const h=Nt(e.type),x=Dh[h]||r("desc-fg"),j=!!e.content,b=e.work_ids||[],_=b.length>1,y=Zh(_?b:[],i,o),k=j&&!m&&e.content.length>80?Kc(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${r("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>j&&u(!m),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:j?"pointer":"default",userSelect:"none"},children:[t.jsxs(Jo,{enabled:j,expanded:m,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[j&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:m?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:r("fg"),lineHeight:1.6},children:e.header_line?g(e.header_line):g(e.title)}),!m&&k&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r("desc-fg"),lineHeight:1.7},children:g(k)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:c(b[0]),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(b[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:b.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:Zo(d,h,l)})]})]}),_&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(w=>{const v=y[w],C=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:w.slice(0,8)+"…";return t.jsxs("a",{href:c(w),onClick:$=>{$.metaKey||$.ctrlKey||($.preventDefault(),$.stopPropagation(),n(w))},style:{fontSize:"12px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:w,children:["→",C]},w)})}),m&&j&&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:g(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:g(e.comment)})]})]})}function Qh({juan:e,searchQuery:n,onNavigate:i,transport:o,workLabelCache:s}){const{t:a}=re(),l=mn(),d=n.trim(),c=f.useMemo(()=>d?e.sections.filter(p=>Ko(p,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:c.map((p,g)=>t.jsx(Jh,{section:p,onNavigate:i,transport:o,workLabelCache:s,highlightQuery:d},g))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function ex(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function tx({sections:e,onNavigate:n,inline:i,workLinks:o=!0}){const s=mt(),{t:a,convert:l}=re(),d=ex();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const g=Nt(c.type);if(g==="page_header"&&!Qo(c))return null;if(g==="类")return t.jsxs(f.Fragment,{children:[f.createElement(d("类"),null,i(l(c.title))),c.content&&t.jsx("p",{children:i(l(c.content))})]},p);if(g==="书"||g==="诗"||g==="考证"||g==="注释"){const m=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:qo(c.n_juan)}):""}`:c.title,u=i(l(m));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${p}`,children:[f.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:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(c.work_id))},title:a("collated.viewWork"),children:u}),t.jsx("a",{className:"bim-rd-wl",href:s(c.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(m)}),children:a("collated.workArrow")})]}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((h,x)=>t.jsx("p",{children:i(l(h))},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 g==="小计"&&c.title?t.jsx("p",{children:i(l(c.title))},p):c.content?t.jsx("p",{children:i(l(c.content))},p):null})})}function bd(e){return e.some(n=>{const i=Nt(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&Qo(n)})}function nx({juan:e,rawText:n,positionLabel:i,groupLabel:o,index:s,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:p,view:g,onViewChange:m}){var J;const{t:u,convert:h,messages:x}=re(),j=mn(),[b,_]=f.useState("text"),y=g??b,k=le=>{_(le),m==null||m(le)},w=a.trim(),v=(s==null?void 0:s.type)==="kaozhen",C=f.useCallback(le=>w?ni(le,w,j):le,[w,j]),$=Vo(p),S=le=>qi(le,{renderText:C,bookMarking:$,quoteStyle:p.quoteStyle,t:u}),R=f.useMemo(()=>w?e.sections.filter(le=>Ko(le,w,v,j)):e.sections,[e.sections,w,v,j]),N=(le,we)=>we.filter(ye=>Nt(ye.type)===le).length,z=N("书",e.sections),I=N("诗",e.sections),P=N("考证",e.sections);let A="";v?A=w?u("collated.countTiaoOf",{m:N("考证",R),n:P}):u("collated.countTiao",{n:P}):I>0?A=w?u("collated.countPoemsOf",{m:N("诗",R),n:I}):u("collated.countPoems",{n:I}):z>0&&(A=w?u("collated.countBooksOf",{m:N("书",R),n:z}):u("collated.countBooks",{n:z}));const M=s!=null&&s.text_quality?Eh(s.text_quality.grade):null,F=[];if(A&&F.push(A),v&&(s!=null&&s.target_source)&&F.push(t.jsx(t.Fragment,{children:u("collated.kaozhenTarget",{target:h(s.target_source)})})),M){const le=t.jsx("span",{className:"bim-rd-grade",style:Rh(M),children:x.collated.qualityLabel[M]});F.push(t.jsx("span",{title:x.collated.qualityCriteria[M],children:(J=s==null?void 0:s.text_quality)!=null&&J.source_note?t.jsxs(t.Fragment,{children:[Ah(u("collated.baseText",{note:hd}),s.text_quality.source_note,h),le]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),le]})}))}e.source_url&&F.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:u("collated.originalSource")}));const ne=!v&&bd(e.sections),je=!!n&&(!ne||p.readingMode==="paragraph"&&Ti(n)),ae=!v&&(ne||!!n),Y=v||!ae?"entries":y;let xe=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&&h(o)]}),t.jsx("h1",{className:"bim-rd-h1",children:h(e.title)}),F.length>0&&t.jsx("p",{className:"bim-rd-meta",children:F.map((le,we)=>t.jsxs(f.Fragment,{children:[we>0&&t.jsx("span",{className:"bim-rd-dot"}),le]},we))}),ae&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":u("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":Y==="text",onClick:()=>k("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":Y==="entries",onClick:()=>k("entries"),children:u("collated.viewEntries")})]})]}),Y==="text"&&t.jsx("article",{className:"bim-rd-prose",children:je?t.jsx(Go,{text:n,mode:p.readingMode,bookMarking:$,quoteStyle:p.quoteStyle,renderText:C,dropTitle:e.title}):t.jsx(tx,{sections:e.sections,onNavigate:l,inline:S,workLinks:p.workLinks})}),Y==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?t.jsx(Qh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[R.some(le=>["书","诗","考证"].includes(Nt(le.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:u("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:u("collated.rowHeadTitle")}),t.jsx("span",{children:u("collated.rowHeadWork")})]}),R.map((le,we)=>{const ye=Nt(le.type);return ye==="书"||ye==="诗"||ye==="考证"?(xe+=1,t.jsx(Yh,{domId:`rd-e-${e.sections.indexOf(le)}`,section:le,onNavigate:p.workLinks?l:void 0,highlightQuery:w,no:xe,showUnlinked:p.workLinks&&!!l},we)):ye==="类"?t.jsx(qh,{section:le,highlightQuery:w},we):t.jsx(Xh,{section:le,highlightQuery:w},we)}),R.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function ix(e){const{resetKey:n,load:i,files:o,activeFile:s,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,p=mn(),g=f.useRef(new Map),[m,u]=f.useState({}),[h,x]=f.useState({}),j=f.useCallback((_,y)=>{const k=y==null?void 0:y.title;k&&x(w=>w[_]===k?w:{...w,[_]:k})},[]);f.useEffect(()=>{s&&a&&(g.current.set(s,{juan:a,rawText:l}),j(s,a))},[s,a,l,j]),f.useEffect(()=>{g.current.clear(),u({}),x({})},[n]);const b=f.useCallback((_,y)=>{let k=0;if(_.juan)for(const w of _.juan.sections)Ko(w,y,c,p)&&k++;return k===0&&_.rawText&&Hh(_.rawText,y,p)&&(k=1),k},[c,p]);return f.useEffect(()=>{const _=d.trim();if(!_){u({});return}if(!i||o.length===0)return;let y=!1;const k={},w=[];for(const R of o){const N=g.current.get(R);N?k[R]=b(N,_):(k[R]="loading",w.push(R))}u(k);const v=8;let C=0;const $=async()=>{for(;C<w.length;){if(y)return;const R=C++,N=w[R];try{const z=await i(N),I=z.juan;if(g.current.set(N,z),j(N,I),y)return;u(P=>({...P,[N]:b(z,_)}))}catch{if(y)return;u(z=>({...z,[N]:0}))}}},S=Array.from({length:Math.min(v,w.length)},()=>$());return Promise.all(S),()=>{y=!0}},[d,n,i,o.join(","),b,p,j]),{matchStates:m,titles:h}}function rx({juan:e,view:n,onView:i,textHasEntries:o}){const{t:s,convert:a}=re(),l=e.sections.map((g,m)=>({s:g,i:m,t:Nt(g.type)})).filter(g=>g.t==="书"||g.t==="诗");if(l.length===0)return null;const d=l.filter(g=>!!g.s.work_id).length,c=l.every(g=>g.t==="诗")?s("collated.railUnitPoems"):s("collated.railUnitBooks"),p=g=>{const m=()=>{var u,h;return(h=(u=document.getElementById(`rd-e-${g}`))==null?void 0:u.scrollIntoView)==null?void 0:h.call(u,{block:"start",behavior:"smooth"})};n==="text"&&!o&&i("entries"),n==="text"&&!o?setTimeout(m,0):m()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:s("collated.railCap")}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:c}),t.jsx("span",{className:"bim-rd-rail-linked",children:s("collated.linkedN",{n:d})})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":s("collated.linkedOf",{n:d,total:l.length}),children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":s("collated.railEntriesNav"),children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:s("collated.viewEntries")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:g,i:m})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${m}`,onClick:u=>{u.preventDefault(),p(m)},children:[t.jsx("span",{className:`bim-rd-rail-dot${g.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:qi(a(g.book_title||g.title),{t:s})})]})},m))})]})]})}const ox=`
1344
+ `)}),s=[]};for(const l of n){const d=Uo(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(`
1345
+ `)){const o=Uo(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 ld(e){if(!e)return[];const n=qi(e);if(n==="unknown")return Ea(e);const i=[];for(const{heading:o,body:s}of fh(e)){o&&i.push(o);const a=od(s);if(a.length!==0){if(ad(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=sd(l);d.length&&i.push({kind:"body",text:d.join(" ")})}}}return i}const hh={"「":"“","」":"”","『":"‘","』":"’"},xh={"“":"「","”":"」","‘":"『","’":"』"},bh=new Set(["《","》","〈","〉"]);function cd(e,n){const i=n.quoteStyle==="modern"?hh:n.quoteStyle==="classic"?xh:null;let o="";for(const s of e)n.hideBookBrackets&&bh.has(s)||(o+=(i==null?void 0:i[s])??s);return o}const dd=e=>e;function Go(e){return e.showWorks?e.bookTitleStyle==="bracket"?"bracket":nf(e.properNameMode)?"wavy":"bracket":"none"}function pd(e,n=dd,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(f.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(f.Fragment,{children:c},l++)),a=d.index+d[0].length}return a===0?n(e):(a<e.length&&o.push(t.jsx(f.Fragment,{children:n(e.slice(a))},l++)),o)}function Ki(e,n={}){let i=n.renderText??dd;const o=n.quoteStyle;if(o&&o!=="original"){const d=i;i=c=>d(cd(c,{quoteStyle:o}))}const s=n.bookMarking??(n.properNames?"wavy":"bracket"),a=s==="bracket"?i:d=>pd(d,i,s),l=n.gujiMarkdown?{gujiMarkdown:!0,t:n.t}:void 0;return Ct(e,a,l)}function Ia(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(f.Fragment,{children:n(s)},`${i}-${a}`))}const Cr=/^(#{1,6})\s+(.*)$/,yh=/^\s*<!--.*-->\s*$/;function ud(e){return e.replace(/<!--[\s\S]*?-->/g,n=>n.includes(`
1346
+ `)?"":n)}function jh(e){return e<=1?2:e===2?3:4}function vh(){let e=1;return n=>{const i=jh(n),o=Math.min(i,e+1);return e=o,{Tag:`h${o}`,className:`bim-rd-hl${i}`}}}function Ei(e){return e?qi(ud(e))!=="unknown":!1}function kh(e){return/^\u3000{2}/.test(e)}const Ra=e=>kh(e)?"bim-rd-noindent":void 0;function La({text:e,mode:n,inline:i,dropTitle:o,onStart:s}){s==null||s();const a=ud(e),l=(m,g,u)=>!!o&&u<=1&&m<=2&&g.trim()===o.trim(),d=vh();if(n==="paragraph"&&qi(a)!=="unknown"){const m=ld(a);return t.jsx(t.Fragment,{children:m.map((g,u)=>{if(g.kind==="heading"){if(l(g.level??1,g.text,u))return null;const{Tag:h,className:x}=d(g.level??1);return t.jsx(h,{className:x,children:i(g.text)},u)}return t.jsx("p",{className:Ra(g.text),children:Ia(g.text,i,u)},u)})})}const c=a.split(`
1347
+ `);let p=0;return t.jsx(t.Fragment,{children:c.map((m,g)=>{const u=m.match(Cr);if(u){const x=p++;if(l(u[1].length,u[2],x))return null;const{Tag:j,className:b}=d(u[1].length);return t.jsx(j,{className:b,children:i(u[2])},g)}if(!m.trim())return g>=2&&!!c[g-1].trim()&&!!c[g-2].trim()&&!Cr.test(c[g-1])&&!Cr.test(c[g-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},g):null;if(yh.test(m))return null;if(p++,/^\*\*[^*]+\*\*\s*$/.test(m.trim())){const{Tag:x,className:j}=d(3);return t.jsx(x,{className:j,children:i(m.trim().slice(2,-2))},g)}return t.jsx("p",{className:Ra(m),children:Ia(m,i,g)},g)})})}function wh(e){const{convert:n}=De();return f.useMemo(()=>e?n(e):"",[e,n])}function Yo({text:e,mode:n,tables:i=!1,gujiMarkdown:o=!1,properNames:s=!1,bookMarking:a,quoteStyle:l,renderText:d,dropTitle:c}){const p=wh(e),{t:m,convert:g}=ie();let u=null;const h=!!d&&!gf(e,p,!l||l==="original"),x=d&&h?k=>d(k,{mdStart:u==null?void 0:u.align(k)}):d,j=h?()=>{u=bf(e)}:void 0,b=k=>Ki(k,{renderText:x,properNames:s,bookMarking:a,quoteStyle:l,gujiMarkdown:o,t:m}),_=o?{gujiMarkdown:!0,t:m}:void 0,y=c?g(c):void 0;return!i||p.indexOf(":::")<0?t.jsx(La,{text:p,mode:n,inline:b,dropTitle:y,onStart:j}):t.jsx(t.Fragment,{children:Ho(p).map((k,w)=>k.type==="table"?t.jsx(Do,{table:k.table,opts:_},w):t.jsx(La,{text:k.text,mode:n,inline:b,dropTitle:w===0?y:void 0},w))})}const Aa={work:"work",book:"work",people:"people",person:"people",place:"place",office:"office",dynasty:"dynasty",reign:"reign"};function Sh(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(Aa,e)&&Aa[e]||"other"}function Zn(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 Jt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function st(e){return typeof e=="string"&&e?e:void 0}function _h(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={};st(s.entity_id)!==void 0&&(a.entity_id=st(s.entity_id)),st(s.canonical_name)!==void 0&&(a.canonical_name=st(s.canonical_name)),Jt(s.confidence)!==void 0&&(a.confidence=Jt(s.confidence)),i.push(a)}return i}function $h(e){if(!Array.isArray(e.targets))return;const n=[];for(const i of e.targets){if(!i||typeof i!="object"||Array.isArray(i))continue;const o=i,s=Zn(st(o.entity_id))??Zn(st(o.href));s&&n.push({id:s,...st(o.canonical_name)?{canonicalName:st(o.canonical_name)}:{},...st(o.part)?{part:st(o.part)}:{}})}return n.length>=2?n:void 0}const jn=e=>e.start!==void 0&&e.end!==void 0;function md(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=Jt(l.start_offset)??Jt(a.start_offset),p=Jt(l.end_offset)??Jt(a.end_offset),m=c!==void 0&&p!==void 0&&c>=0&&p>c,g=a.anchor??{},u=st(g.start),h=st(g.end);if(!m&&!!!(u&&h))return;const j=st(d.status),b=j===void 0||j==="matched"?Zn(st(d.entity_id))??Zn(st(d.href))??void 0:void 0,_=Jt(d.confidence),y=j==="matched_multi"?$h(d):void 0,k=_h(a.ambiguous);i.push({...u&&h?{anchor:{start:u,end:h}}:{},key:st(a.id)??`e${s}`,kind:Sh(a.type),...m?{start:c,end:p}:{},text:st(a.text),targetId:b,canonicalName:st(d.canonical_name),...y?{targets:y}:{},confidence:Jt(a.confidence)??_,..._!==void 0?{targetConfidence:_}:{},...st(d.level)!==void 0?{targetLevel:st(d.level)}:{},...st(d.note)!==void 0?{targetNote:st(d.note)}:{},...st(a.group)!==void 0?{group:st(a.group)}:{},...k!==void 0?{candidates:k}:{}})}),i.sort((o,s)=>!jn(o)||!jn(s)?+!jn(o)-+!jn(s):o.start-s.start||s.end-o.end)}const Ch=new Set(Array.from(`《》/<>\r
1348
+  ,。、;:?!「」『』()…—·`));function qo(e){return!Ch.has(e)}function gd(e,n,i=0){const o=[],s=Array.from(e);let a=0;for(const d of s)qo(d)&&o.push(a),a+=d.length;const l=[];for(const d of n){if(!jn(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],g=e.codePointAt(m)>65535?2:1;l.push({...d,start:o[c],end:m+g})}return l}function zh(e,n){return n.text?Array.from(e.slice(n.start,n.end)).filter(qo).join("")===n.text:!0}function Nh(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 fd(e,n,i=16){const o=[];for(const l of n){if(!jn(l))continue;let d={...l,start:Math.max(0,l.start),end:Math.min(e.length,l.end)};(d.end<=d.start||!zh(e,d))&&(d=Nh(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 Th={off:[],lite:["people","place","dynasty"],full:["people","place","dynasty","office","reign","other"]};function Eh(e,n,i){const o=(i==null?void 0:i.showWorks)!==!1,s=new Set(Th[n]);return e.filter(a=>a.kind==="work"?o:s.has(a.kind))}function Ih(e,n,i){const[o,s]=f.useState(null),[a,l]=f.useState(!1),d=f.useRef(0);return f.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 Rh(){let e=null;const n=new Set;return{get:()=>e,set:i=>{i!==e&&(e=i,n.forEach(o=>o()))},subscribe:i=>(n.add(i),()=>{n.delete(i)})}}function Lh(e){return f.useSyncExternalStore(e.subscribe,e.get,e.get)}function Ma({store:e,children:n}){const i=Lh(e);return f.createElement(f.Fragment,null,n(i))}function Ah(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(Ou,e)?e:null}function Mh(e){if(e==="none")return{color:r("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r("quality-placeholder"),fontWeight:400}}const Ph={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},hd="\0";function Bh(e,n,i){const[o,s=""]=e.split(hd);return t.jsxs(t.Fragment,{children:[o,t.jsx(kc,{text:n,convert:i}),s]})}function Nt(e){return typeof e!="string"?"":Ph[e]??e}const Oh=["〇","一","二","三","四","五","六","七","八","九"],Pa=["","十","百","千"],Wh=["","萬","億"];function Ko(e){if(e===0)return"〇";if(e<0)return`負${Ko(-e)}`;const n=[];let i=e,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Fh(s,o>0)+Wh[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Fh(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+=Pa[d]:s+=Oh[l]+Pa[d]}return s.replace(/〇$/,"")}let qn=null,bi=null;const Ii=new Set;function Hh(){return qn?Promise.resolve():bi||(bi=import("opencc-js/t2cn").then(e=>{const n=e.Converter({from:"t",to:"cn"});qn=i=>n(Ee.normalizeVariants(i)),Ii.forEach(i=>i())}).catch(()=>{qn=e=>e,Ii.forEach(e=>e())}),bi)}const Dh=e=>e;function mn(){const[,e]=f.useState(0);return f.useEffect(()=>{if(qn)return;const n=()=>e(i=>i+1);return Ii.add(n),Hh(),()=>{Ii.delete(n)}},[]),qn??Dh}function _n(e,n){return n(e).toLowerCase()}const Uh=r("highlight-bg");function ii(e,n,i){if(!n)return e;const o=_n(n,i);if(!o)return e;const s=_n(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,j)=>{d.set(c,j),c+=x.length});const p=Array.from(o).length,m=[];let g=0,u=0,h=0;for(;g<a.length;){const x=s.indexOf(o,u),j=x===-1?void 0:d.get(x);if(x===-1){m.push(a.slice(g).join(""));break}if(j===void 0){u=x+1;continue}j>g&&m.push(a.slice(g,j).join("")),m.push(t.jsx("mark",{style:{background:Uh,padding:0,color:"inherit"},children:a.slice(j,j+p).join("")},h++)),g=j+p,u=x+o.length}return t.jsx(t.Fragment,{children:m})}function Xo(e,n,i,o){if(!n)return!0;const s=_n(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"&&_n(l,o).includes(s))}function Vh(e,n,i){return n?_n(e,i).includes(_n(n,i)):!0}const Zo={类:r("section-lei"),书:r("section-shu"),序:r("section-xu"),结语:r("section-jieyu"),注释:r("section-zhushi")},Gh={考证:r("section-kaozhen")};function Jo(e,n,i){return e.collated.sectionType[n]??i(n)}function xd(e){var o;const n=e.files.length,i=((o=e.children)==null?void 0:o.reduce((s,a)=>s+xd(a),0))||0;return n+i}function Yh(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 qh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Qo({enabled:e,expanded:n,onClick:i,style:o,children:s}){return e?t.jsx("button",{type:"button","aria-expanded":n,onClick:i,style:{...qh,...o},children:s}):t.jsx("span",{style:o,children:s})}function Kh({type:e}){const{convert:n,messages:i}=ie(),o=Nt(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:Jo(i,o,n)})}function Xh({section:e,onNavigate:n,highlightQuery:i="",no:o,showUnlinked:s=!1,domId:a}){const{t:l,convert:d}=ie(),c=mt(),p=mn(),m=k=>k?Ct(d(k),w=>i?ii(w,i,p):w,{t:l}):"",[g,u]=f.useState(!1),h=!!e.summary,x=!!e.comment,j=!!e.additional_comment,b=!!(e.content&&e.content.length>60),_=h||x||j||b;f.useEffect(()=>{i&&u(!0)},[i]);const y=!g&&b?Kc(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:()=>_&&u(!g),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(Qo,{enabled:_,expanded:g,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:g?"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(Ko(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)})]}),!g&&y&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:r("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:m(y)})]})]}),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:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.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")})]}),g&&_&&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)})]}),b&&!h&&!x&&!j&&t.jsx("p",{style:{fontSize:"13px",color:r("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:m(e.content)})]})]})}function Zh({section:e,highlightQuery:n=""}){const{t:i,convert:o}=ie(),s=mn(),a=p=>p?Ct(o(p),m=>n?ii(m,n,s):m,{t:i}):"",[l,d]=f.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Qo,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Kh,{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[Nt(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 Jh=100;function es(e){return Nt(e.type)!=="page_header"?!1:(e.content||"").length>=Jh}function Qh({section:e,highlightQuery:n=""}){const{t:i,convert:o,messages:s}=ie(),a=mn();if(Nt(e.type)==="page_header"&&!es(e)||!e.content&&!e.title)return null;const l=o((e.content||e.title||"").replace(/\n{2,}/g,`
1349
+ `)),d=Ct(l,g=>n?ii(g,n,a):g,{t:i}),c=Nt(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:Jo(s,c,o)}),d]})}function ex(e,n,i){const[o,s]=f.useState({});return f.useEffect(()=>{var p;if(!n||e.length===0)return;let a=!1;const l=e.filter(m=>{var g;return!((g=i==null?void 0:i.current)!=null&&g.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 g;try{if(n.getEntry){const b=await n.getEntry(m);if(b)return{title:b.title,author:b.author}}const u=await n.getItem(m);if(!u)return null;const h=u.title||m,x=u.authors,j=(g=x==null?void 0:x[0])==null?void 0:g.name;return{title:h,author:j}}catch{return null}};return Promise.all(l.map(async m=>{var u;const g=await c(m);return(u=i==null?void 0:i.current)==null||u.set(m,g),[m,g]})).then(m=>{a||s(g=>{const u={...g};for(const[h,x]of m)u[h]=x;return u})}),()=>{a=!0}},[e.join(","),n]),o}function tx({section:e,onNavigate:n,transport:i,workLabelCache:o,highlightQuery:s=""}){const{t:a,convert:l,messages:d}=ie(),c=mt(),p=mn(),m=w=>w?Ct(l(w),v=>s?ii(v,s,p):v,{t:a}):"",[g,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const h=Nt(e.type),x=Gh[h]||r("desc-fg"),j=!!e.content,b=e.work_ids||[],_=b.length>1,y=ex(_?b:[],i,o),k=j&&!g&&e.content.length>80?Kc(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${r("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>j&&u(!g),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:j?"pointer":"default",userSelect:"none"},children:[t.jsxs(Qo,{enabled:j,expanded:g,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[j&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:g?"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)}),!g&&k&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r("desc-fg"),lineHeight:1.7},children:m(k)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&t.jsx("a",{href:c(b[0]),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(b[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:b.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:x,border:`1px solid ${x}40`,borderRadius:"2px",background:`${x}08`},children:Jo(d,h,l)})]})]}),_&&n&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(w=>{const v=y[w],C=v?`${l(v.title)}${v.author?`(${l(v.author)})`:""}`:w.slice(0,8)+"…";return t.jsxs("a",{href:c(w),onClick:$=>{$.metaKey||$.ctrlKey||($.preventDefault(),$.stopPropagation(),n(w))},style:{fontSize:"12px",color:r("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:w,children:["→",C]},w)})}),g&&j&&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 nx({juan:e,searchQuery:n,onNavigate:i,transport:o,workLabelCache:s}){const{t:a}=ie(),l=mn(),d=n.trim(),c=f.useMemo(()=>d?e.sections.filter(p=>Xo(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(tx,{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 ix(){let e=!1;return n=>n==="类"?(e=!0,"h2"):e?"h3":"h2"}function rx({sections:e,onNavigate:n,inline:i,workLinks:o=!0}){const s=mt(),{t:a,convert:l}=ie(),d=ix();return t.jsx(t.Fragment,{children:e.map((c,p)=>{const m=Nt(c.type);if(m==="page_header"&&!es(c))return null;if(m==="类")return t.jsxs(f.Fragment,{children:[f.createElement(d("类"),null,i(l(c.title))),c.content&&t.jsx("p",{children:i(l(c.content))})]},p);if(m==="书"||m==="诗"||m==="考证"||m==="注释"){const g=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:Ko(c.n_juan)}):""}`:c.title,u=i(l(g));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${p}`,children:[f.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:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(c.work_id))},title:a("collated.viewWork"),children:u}),t.jsx("a",{className:"bim-rd-wl",href:s(c.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(g)}),children:a("collated.workArrow")})]}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:i(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((h,x)=>t.jsx("p",{children:i(l(h))},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 bd(e){return e.some(n=>{const i=Nt(n.type);return i==="书"||i==="诗"||i==="考证"||i==="注释"||i==="类"||(i==="序"||i==="结语")&&!!n.content||i==="page_header"&&es(n)})}function ox({juan:e,rawText:n,positionLabel:i,groupLabel:o,index:s,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:p,view:m,onViewChange:g}){var Q;const{t:u,convert:h,messages:x}=ie(),j=mn(),[b,_]=f.useState("text"),y=m??b,k=le=>{_(le),g==null||g(le)},w=a.trim(),v=(s==null?void 0:s.type)==="kaozhen",C=f.useCallback(le=>w?ii(le,w,j):le,[w,j]),$=Go(p),S=le=>Ki(le,{renderText:C,bookMarking:$,quoteStyle:p.quoteStyle,t:u}),I=f.useMemo(()=>w?e.sections.filter(le=>Xo(le,w,v,j)):e.sections,[e.sections,w,v,j]),N=(le,we)=>we.filter(je=>Nt(je.type)===le).length,z=N("书",e.sections),E=N("诗",e.sections),P=N("考证",e.sections);let A="";v?A=w?u("collated.countTiaoOf",{m:N("考证",I),n:P}):u("collated.countTiao",{n:P}):E>0?A=w?u("collated.countPoemsOf",{m:N("诗",I),n:E}):u("collated.countPoems",{n:E}):z>0&&(A=w?u("collated.countBooksOf",{m:N("书",I),n:z}):u("collated.countBooks",{n:z}));const M=s!=null&&s.text_quality?Ah(s.text_quality.grade):null,F=[];if(A&&F.push(A),v&&(s!=null&&s.target_source)&&F.push(t.jsx(t.Fragment,{children:u("collated.kaozhenTarget",{target:h(s.target_source)})})),M){const le=t.jsx("span",{className:"bim-rd-grade",style:Mh(M),children:x.collated.qualityLabel[M]});F.push(t.jsx("span",{title:x.collated.qualityCriteria[M],children:(Q=s==null?void 0:s.text_quality)!=null&&Q.source_note?t.jsxs(t.Fragment,{children:[Bh(u("collated.baseText",{note:hd}),s.text_quality.source_note,h),le]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),le]})}))}e.source_url&&F.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:u("collated.originalSource")}));const q=!v&&bd(e.sections),be=!!n&&(!q||p.readingMode==="paragraph"&&Ei(n)),se=!v&&(q||!!n),Y=v||!se?"entries":y;let xe=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&&h(o)]}),t.jsx("h1",{className:"bim-rd-h1",children:h(e.title)}),F.length>0&&t.jsx("p",{className:"bim-rd-meta",children:F.map((le,we)=>t.jsxs(f.Fragment,{children:[we>0&&t.jsx("span",{className:"bim-rd-dot"}),le]},we))}),se&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":u("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":Y==="text",onClick:()=>k("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":Y==="entries",onClick:()=>k("entries"),children:u("collated.viewEntries")})]})]}),Y==="text"&&t.jsx("article",{className:"bim-rd-prose",children:be?t.jsx(Yo,{text:n,mode:p.readingMode,bookMarking:$,quoteStyle:p.quoteStyle,renderText:C,dropTitle:e.title}):t.jsx(rx,{sections:e.sections,onNavigate:l,inline:S,workLinks:p.workLinks})}),Y==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:v?t.jsx(nx,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[I.some(le=>["书","诗","考证"].includes(Nt(le.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:u("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:u("collated.rowHeadTitle")}),t.jsx("span",{children:u("collated.rowHeadWork")})]}),I.map((le,we)=>{const je=Nt(le.type);return je==="书"||je==="诗"||je==="考证"?(xe+=1,t.jsx(Xh,{domId:`rd-e-${e.sections.indexOf(le)}`,section:le,onNavigate:p.workLinks?l:void 0,highlightQuery:w,no:xe,showUnlinked:p.workLinks&&!!l},we)):je==="类"?t.jsx(Zh,{section:le,highlightQuery:w},we):t.jsx(Qh,{section:le,highlightQuery:w},we)}),I.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function sx(e){const{resetKey:n,load:i,files:o,activeFile:s,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,p=mn(),m=f.useRef(new Map),[g,u]=f.useState({}),[h,x]=f.useState({}),j=f.useCallback((_,y)=>{const k=y==null?void 0:y.title;k&&x(w=>w[_]===k?w:{...w,[_]:k})},[]);f.useEffect(()=>{s&&a&&(m.current.set(s,{juan:a,rawText:l}),j(s,a))},[s,a,l,j]),f.useEffect(()=>{m.current.clear(),u({}),x({})},[n]);const b=f.useCallback((_,y)=>{let k=0;if(_.juan)for(const w of _.juan.sections)Xo(w,y,c,p)&&k++;return k===0&&_.rawText&&Vh(_.rawText,y,p)&&(k=1),k},[c,p]);return f.useEffect(()=>{const _=d.trim();if(!_){u({});return}if(!i||o.length===0)return;let y=!1;const k={},w=[];for(const I of o){const N=m.current.get(I);N?k[I]=b(N,_):(k[I]="loading",w.push(I))}u(k);const v=8;let C=0;const $=async()=>{for(;C<w.length;){if(y)return;const I=C++,N=w[I];try{const z=await i(N),E=z.juan;if(m.current.set(N,z),j(N,E),y)return;u(P=>({...P,[N]:b(z,_)}))}catch{if(y)return;u(z=>({...z,[N]:0}))}}},S=Array.from({length:Math.min(v,w.length)},()=>$());return Promise.all(S),()=>{y=!0}},[d,n,i,o.join(","),b,p,j]),{matchStates:g,titles:h}}function ax({juan:e,view:n,onView:i,textHasEntries:o}){const{t:s,convert:a}=ie(),l=e.sections.map((m,g)=>({s:m,i:g,t:Nt(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 g=()=>{var u,h;return(h=(u=document.getElementById(`rd-e-${m}`))==null?void 0:u.scrollIntoView)==null?void 0:h.call(u,{block:"start",behavior:"smooth"})};n==="text"&&!o&&i("entries"),n==="text"&&!o?setTimeout(g,0):g()};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:g})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${g}`,onClick:u=>{u.preventDefault(),p(g)},children:[t.jsx("span",{className:`bim-rd-rail-dot${m.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:Ki(a(m.book_title||m.title),{t:s})})]})},g))})]})]})}const lx=`
1346
1350
  attribute vec2 a_position; // 目标画布像素坐标 [0, canvasWidth] x [0, canvasHeight]
1347
1351
  attribute vec2 a_texCoord; // 原图像素坐标 [0, imgWidth] x [0, imgHeight]
1348
1352
 
@@ -1360,7 +1364,7 @@ ${zf}`;function Un({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{clas
1360
1364
  // 纹理坐标归一化 [0, 1]
1361
1365
  v_texCoord = a_texCoord / u_imgResolution;
1362
1366
  }
1363
- `,sx=`
1367
+ `,cx=`
1364
1368
  precision mediump float;
1365
1369
  uniform sampler2D u_image;
1366
1370
  uniform float u_alpha;
@@ -1370,7 +1374,7 @@ ${zf}`;function Un({children:e,style:n,wide:i,grid:o}){return t.jsxs("div",{clas
1370
1374
  vec4 tex = texture2D(u_image, v_texCoord);
1371
1375
  gl_FragColor = vec4(tex.rgb, tex.a * u_alpha);
1372
1376
  }
1373
- `;function Pa(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 Qr{constructor(n){const i=n.getContext("webgl",{alpha:!0,antialias:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1});if(!i)throw new Error("WebGL not supported");this.gl=i;const o=Pa(i,i.VERTEX_SHADER,ox),s=Pa(i,i.FRAGMENT_SHADER,sx);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,o.drawingBufferWidth,o.drawingBufferHeight),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,c.drawingBufferWidth,c.drawingBufferHeight),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,i,o),c.uniform2f(this.uImgResolutionLoc,s,a),c.uniform1f(this.uAlphaLoc,d);const p=[],g=[],m=8;for(const u of l){const h=u.colOffsetX||0,x=u.colOffsetY||0,{srcQuad:j,dstRect:b}=u.strip,[_,y,k,w]=b,v=h+_,C=x+y,[$,S,R,N]=j;for(let z=0;z<m;z++){const I=z/m,P=(z+1)/m,A=C+w*I,M=C+w*P,F=[$[0]+(N[0]-$[0])*I,$[1]+(N[1]-$[1])*I],ne=[$[0]+(N[0]-$[0])*P,$[1]+(N[1]-$[1])*P],je=[S[0]+(R[0]-S[0])*I,S[1]+(R[1]-S[1])*I],ae=[S[0]+(R[0]-S[0])*P,S[1]+(R[1]-S[1])*P],Y=[v,A],xe=[v+k,A],J=[v,M],le=[v+k,M];p.push(Y[0],Y[1],xe[0],xe[1],J[0],J[1]),g.push(F[0],F[1],je[0],je[1],ne[0],ne[1]),p.push(xe[0],xe[1],le[0],le[1],J[0],J[1]),g.push(je[0],je[1],ae[0],ae[1],ne[0],ne[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(g),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 ax(e){const[n,i]=e.image_size||[0,0];if(!(n>0)||!(i>0)||e.columns.some(u=>{var h;return(((h=u.strips)==null?void 0:h.length)??0)>0}))return null;let o=1/0,s=1/0,a=-1/0,l=-1/0;for(const u of e.columns)for(const h of u.chars){const[x,j,b,_]=h.bbox_col;![x,j,b,_].every(Number.isFinite)||!(b>x)||!(_>j)||(o=Math.min(o,u.offset_x+x),s=Math.min(s,j),a=Math.max(a,u.offset_x+b),l=Math.max(l,_))}for(const u of e.figBlocks??[]){const[h,x,j,b]=u.box;![h,x,j,b].every(Number.isFinite)||!(j>h)||!(b>x)||(o=Math.min(o,h),s=Math.min(s,x),a=Math.max(a,j),l=Math.max(l,b))}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)),g=Math.min(n,Math.max(0,a+d))-c,m=Math.min(i,Math.max(0,l+d))-p;return!(g>0)||!(m>0)||g>=n*.98&&m>=i*.98?null:{x:c,y:p,w:g,h:m}}const Ba=typeof window>"u"?f.useEffect:f.useLayoutEffect;function lx(e,n){const i=Math.max(1,Math.round(e)),o=Math.max(1,Math.round(n));return`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${o}"/>`)}`}const Cr=[1,1.5,2,3,4,6];function cx(e){for(const n of Cr)if(e<=n)return n;return Cr[Cr.length-1]}function dx(e,n,i,o,s=1){if(!(e>0)||!(n>0))return[1,1];if(i===null||!(i>0))return[1,1];const a=Math.ceil(i*Math.min(Math.max(o,1),2)*cx(s)/64)*64,l=Math.max(1,Math.min(Math.round(e),a)),d=Math.max(1,Math.round(l*n/e));return[l,d]}const Xt=new Map,px=8;function eo(e){let n=Xt.get(e);if(n)return Xt.delete(e),Xt.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=()=>{Xt.delete(e),i(null)},o.src=e}),Xt.set(e,n);Xt.size>px;)Xt.delete(Xt.keys().next().value);return n}const es=({imageUrl:e,pageData:n,selectedCharIds:i,hoveredCharId:o,preserveMargins:s=!1,onCharClick:a,onCharHover:l,selectedFigBlock:d,onFigBlockClick:c,renderScale:p=1})=>{const g=f.useRef(null),m=f.useRef(null),u=typeof ResizeObserver<"u",[h,x]=f.useState(null);Ba(()=>{const Q=m.current;if(!Q||typeof ResizeObserver>"u")return;const T=new ResizeObserver(G=>{var se;const fe=((se=G[G.length-1])==null?void 0:se.contentRect.width)??0;x(Be=>Be===fe?Be:fe)});return T.observe(Q),()=>T.disconnect()},[]);const j=!u||h!==null&&h>0,b=f.useRef(null),_=f.useRef(null),y=f.useRef(null),k=f.useRef(null),w=f.useRef(null),[v,C]=f.useState(0),[$,S]=f.useState(0),R=f.useRef(""),N=f.useMemo(()=>Math.max(...n.columns.map(Q=>Q.warped_h),2440),[n]),z=n.total_warped_w,I=n.banxin,P=f.useMemo(()=>{var Oe;if(!s)return{top:0,bottom:0,left:0,right:0};const[Q,T]=n.image_size||[2386,3082];let G=1/0,fe=-1/0,se=1/0,Be=-1/0;for(const X of n.columns)for(const oe of X.strips||[])for(const ze of oe.srcQuad)ze[0]<G&&(G=ze[0]),ze[0]>fe&&(fe=ze[0]),ze[1]<se&&(se=ze[1]),ze[1]>Be&&(Be=ze[1]);if((Oe=n.banxin)!=null&&Oe.current_page_strips)for(const X of n.banxin.current_page_strips)for(const oe of X.srcQuad)oe[0]<G&&(G=oe[0]),oe[0]>fe&&(fe=oe[0]),oe[1]<se&&(se=oe[1]),oe[1]>Be&&(Be=oe[1]);return isFinite(G)||(G=0),isFinite(fe)||(fe=Q),isFinite(se)||(se=0),isFinite(Be)||(Be=T),{top:Math.max(0,Math.round(se)),bottom:Math.max(0,Math.round(T-Be)),left:Math.max(0,Math.round(G)),right:Math.max(0,Math.round(Q-fe)),rawMinX:G,rawMaxX:fe,rawMinY:se,rawMaxY:Be,imgW:Q,imgH:T}},[n,s]),A=f.useMemo(()=>s?null:ax(n),[n,s]),M=z+(I?I.total_w:0),F=A?A.w:M+P.left+P.right,ne=A?A.h:N+P.top+P.bottom,je=typeof window<"u"&&window.devicePixelRatio||1,[ae,Y]=u?dx(F,ne,h,je,p):[Math.round(F),Math.round(ne)],xe=f.useCallback(()=>{const Q=b.current;if(!(!Q||!g.current)&&!(e&&R.current!==e)){if(Q.clear(F,ne),s&&P.rawMinX!==void 0&&k.current&&_.current){const{rawMinX:T,rawMaxX:G,rawMinY:fe,rawMaxY:se,imgW:Be,imgH:Oe,top:X,bottom:oe,left:ze,right:We}=P,be=[];ze>0&&be.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[T,0],[T,Oe],[0,Oe]],dstRect:[0,0,ze,ne]}}),X>0&&be.push({colOffsetX:ze,colOffsetY:0,strip:{srcQuad:[[T,0],[G,0],[G,fe],[T,fe]],dstRect:[0,0,M,X]}}),oe>0&&be.push({colOffsetX:ze,colOffsetY:X+N,strip:{srcQuad:[[T,se],[G,se],[G,Oe],[T,Oe]],dstRect:[0,0,M,oe]}}),We>0&&be.push({colOffsetX:ze+M,colOffsetY:0,strip:{srcQuad:[[G,0],[Be,0],[Be,Oe],[G,Oe]],dstRect:[0,0,We,ne]}}),Q.renderStripsWithTexture(k.current,F,ne,n.image_size[0],n.image_size[1],be,1)}if(k.current&&_.current){const T=n.columns.flatMap(G=>(G.strips||[]).map(fe=>({colOffsetX:P.left+G.offset_x,colOffsetY:P.top,strip:fe})));if(T.length>0?Q.renderStripsWithTexture(k.current,F,ne,n.image_size[0],n.image_size[1],T,1):Q.renderStripsWithTexture(k.current,F,ne,n.image_size[0],n.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:A?[[A.x,A.y],[A.x+A.w,A.y],[A.x+A.w,A.y+A.h],[A.x,A.y+A.h]]:[[0,0],[n.image_size[0],0],[n.image_size[0],n.image_size[1]],[0,n.image_size[1]]],dstRect:[0,0,F,ne]}}],1),I&&I.current_page_strips.length>0){const G=I.current_page_strips.map(fe=>({colOffsetX:P.left+z,colOffsetY:P.top,strip:fe}));Q.renderStripsWithTexture(k.current,F,ne,n.image_size[0],n.image_size[1],G,1)}}if(I&&w.current&&y.current&&I.mate_page_strips.length>0){const T=I.mate_page_strips.map(G=>({colOffsetX:P.left+z+I.half_w,colOffsetY:P.top,strip:G}));Q.renderStripsWithTexture(w.current,F,ne,I.mate_img_size[0],I.mate_img_size[1],T,.65)}}},[e,n,I,F,ne,z,N,M,P,s,A]),J=f.useRef(xe);J.current=xe,f.useEffect(()=>{const Q=g.current;if(!Q)return;const T=se=>{k.current=_.current?se.createTexture(_.current):null,w.current=y.current?se.createTexture(y.current):null,J.current()};try{const se=new Qr(Q);b.current=se,T(se)}catch(se){console.error("Failed to init WebGL renderer:",se)}const G=se=>{se.preventDefault(),console.warn("WebGL context lost")},fe=()=>{console.info("WebGL context restored, re-initializing..."),g.current&&(b.current=new Qr(g.current),T(b.current))};return Q.addEventListener("webglcontextlost",G,!1),Q.addEventListener("webglcontextrestored",fe,!1),()=>{Q.removeEventListener("webglcontextlost",G),Q.removeEventListener("webglcontextrestored",fe),b.current&&(b.current.deleteTexture(k.current),b.current.deleteTexture(w.current),b.current.destroy(),b.current=null)}},[]),f.useEffect(()=>{if(!e||!j)return;let Q=!0;return eo(e).then(T=>{if(!Q||!T)return;_.current=T,R.current=e;const G=b.current;G&&(G.deleteTexture(k.current),k.current=G.createTexture(T)),C(fe=>fe+1)}),()=>{Q=!1}},[e,j]);const le=I==null?void 0:I.mate_image_url;f.useEffect(()=>{if(!le||!j)return;let Q=!0;return eo(le).then(T=>{if(!Q||!T)return;y.current=T;const G=b.current;G&&(G.deleteTexture(w.current),w.current=G.createTexture(T)),S(fe=>fe+1)}),()=>{Q=!1}},[le,j]),Ba(()=>{j&&xe()},[xe,v,$,ae,Y,j]);const we=f.useMemo(()=>(n.figBlocks??[]).map(Q=>{const[T,G,fe,se]=Q.box;return{id:Q.id,x:P.left+T-((A==null?void 0:A.x)??0),y:P.top+G-((A==null?void 0:A.y)??0),w:Math.max(fe-T,1),h:Math.max(se-G,1)}}),[n,P,A]),ye=f.useMemo(()=>{const Q=[];for(const T of n.columns)for(const G of T.chars){const[fe,se,Be,Oe]=G.bbox_col;Q.push({id:G.id,char:G.char,x:P.left+T.offset_x+fe-((A==null?void 0:A.x)??0),y:P.top+se-((A==null?void 0:A.y)??0),w:Math.max(Be-fe,1),h:Math.max(Oe-se,1)})}return Q},[n,P,A]);return t.jsxs("div",{ref:m,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${F} / ${ne}`,backgroundColor:r("warp-bg"),boxShadow:r("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("img",{alt:"","aria-hidden":"true","data-warp-sizer":"",src:lx(F,ne),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:g,width:ae,height:Y,"data-logical-size":`${Math.floor(F)}x${Math.floor(ne)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:r("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${F} ${ne}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[ye.map(Q=>{const T=i.has(Q.id),G=o===Q.id;return t.jsx("rect",{"data-selected":T?"true":void 0,x:Q.x,y:Q.y,width:Q.w,height:Q.h,fill:T?r("warp-sel-bg"):G?r("warp-hover-bg"):"transparent",stroke:T?r("warp-sel-stroke"):G?r("warp-hover-stroke"):"transparent",strokeWidth:T?3.5:G?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>a==null?void 0:a(Q.id),onMouseEnter:()=>l==null?void 0:l(Q.id),onMouseLeave:()=>l==null?void 0:l(null),children:t.jsx("title",{children:Q.char})},Q.id)}),we.map(Q=>{const T=d===Q.id;return t.jsx("rect",{"data-fig-block":Q.id,"data-selected":T?"true":void 0,x:Q.x,y:Q.y,width:Q.w,height:Q.h,fill:T?r("warp-sel-bg"):"transparent",stroke:r(T?"warp-sel-stroke":"warp-hover-stroke"),strokeWidth:T?3.5:2,strokeDasharray:T?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>c==null?void 0:c(Q.id),children:t.jsx("title",{children:Q.id})},`fig-${Q.id}`)}),I&&t.jsxs("g",{children:[t.jsx("line",{x1:P.left+z,y1:P.top,x2:P.left+z,y2:P.top+N,stroke:r("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:P.left+z+I.half_w,y1:P.top,x2:P.left+z+I.half_w,y2:P.top+N,stroke:r("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:P.left+M,y1:P.top,x2:P.left+M,y2:P.top+N,stroke:r("warp-banxin-outer"),strokeWidth:1})]})]})]})},ts=`
1377
+ `;function Ba(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 Qr{constructor(n){const i=n.getContext("webgl",{alpha:!0,antialias:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1});if(!i)throw new Error("WebGL not supported");this.gl=i;const o=Ba(i,i.VERTEX_SHADER,lx),s=Ba(i,i.FRAGMENT_SHADER,cx);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,o.drawingBufferWidth,o.drawingBufferHeight),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,c.drawingBufferWidth,c.drawingBufferHeight),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,i,o),c.uniform2f(this.uImgResolutionLoc,s,a),c.uniform1f(this.uAlphaLoc,d);const p=[],m=[],g=8;for(const u of l){const h=u.colOffsetX||0,x=u.colOffsetY||0,{srcQuad:j,dstRect:b}=u.strip,[_,y,k,w]=b,v=h+_,C=x+y,[$,S,I,N]=j;for(let z=0;z<g;z++){const E=z/g,P=(z+1)/g,A=C+w*E,M=C+w*P,F=[$[0]+(N[0]-$[0])*E,$[1]+(N[1]-$[1])*E],q=[$[0]+(N[0]-$[0])*P,$[1]+(N[1]-$[1])*P],be=[S[0]+(I[0]-S[0])*E,S[1]+(I[1]-S[1])*E],se=[S[0]+(I[0]-S[0])*P,S[1]+(I[1]-S[1])*P],Y=[v,A],xe=[v+k,A],Q=[v,M],le=[v+k,M];p.push(Y[0],Y[1],xe[0],xe[1],Q[0],Q[1]),m.push(F[0],F[1],be[0],be[1],q[0],q[1]),p.push(xe[0],xe[1],le[0],le[1],Q[0],Q[1]),m.push(be[0],be[1],se[0],se[1],q[0],q[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)}}function dx(e){const[n,i]=e.image_size||[0,0];if(!(n>0)||!(i>0)||e.columns.some(u=>{var h;return(((h=u.strips)==null?void 0:h.length)??0)>0}))return null;let o=1/0,s=1/0,a=-1/0,l=-1/0;for(const u of e.columns)for(const h of u.chars){const[x,j,b,_]=h.bbox_col;![x,j,b,_].every(Number.isFinite)||!(b>x)||!(_>j)||(o=Math.min(o,u.offset_x+x),s=Math.min(s,j),a=Math.max(a,u.offset_x+b),l=Math.max(l,_))}for(const u of e.figBlocks??[]){const[h,x,j,b]=u.box;![h,x,j,b].every(Number.isFinite)||!(j>h)||!(b>x)||(o=Math.min(o,h),s=Math.min(s,x),a=Math.max(a,j),l=Math.max(l,b))}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)),m=Math.min(n,Math.max(0,a+d))-c,g=Math.min(i,Math.max(0,l+d))-p;return!(m>0)||!(g>0)||m>=n*.98&&g>=i*.98?null:{x:c,y:p,w:m,h:g}}const Oa=typeof window>"u"?f.useEffect:f.useLayoutEffect;function px(e,n){const i=Math.max(1,Math.round(e)),o=Math.max(1,Math.round(n));return`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${o}"/>`)}`}const zr=[1,1.5,2,3,4,6];function ux(e){for(const n of zr)if(e<=n)return n;return zr[zr.length-1]}function mx(e,n,i,o,s=1){if(!(e>0)||!(n>0))return[1,1];if(i===null||!(i>0))return[1,1];const a=Math.ceil(i*Math.min(Math.max(o,1),2)*ux(s)/64)*64,l=Math.max(1,Math.min(Math.round(e),a)),d=Math.max(1,Math.round(l*n/e));return[l,d]}const Xt=new Map,gx=8;function eo(e){let n=Xt.get(e);if(n)return Xt.delete(e),Xt.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=()=>{Xt.delete(e),i(null)},o.src=e}),Xt.set(e,n);Xt.size>gx;)Xt.delete(Xt.keys().next().value);return n}const ts=({imageUrl:e,pageData:n,selectedCharIds:i,hoveredCharId:o,preserveMargins:s=!1,onCharClick:a,onCharHover:l,selectedFigBlock:d,onFigBlockClick:c,renderScale:p=1})=>{const m=f.useRef(null),g=f.useRef(null),u=typeof ResizeObserver<"u",[h,x]=f.useState(null);Oa(()=>{const ee=g.current;if(!ee||typeof ResizeObserver>"u")return;const T=new ResizeObserver(G=>{var ae;const fe=((ae=G[G.length-1])==null?void 0:ae.contentRect.width)??0;x(Be=>Be===fe?Be:fe)});return T.observe(ee),()=>T.disconnect()},[]);const j=!u||h!==null&&h>0,b=f.useRef(null),_=f.useRef(null),y=f.useRef(null),k=f.useRef(null),w=f.useRef(null),[v,C]=f.useState(0),[$,S]=f.useState(0),I=f.useRef(""),N=f.useMemo(()=>Math.max(...n.columns.map(ee=>ee.warped_h),2440),[n]),z=n.total_warped_w,E=n.banxin,P=f.useMemo(()=>{var Oe;if(!s)return{top:0,bottom:0,left:0,right:0};const[ee,T]=n.image_size||[2386,3082];let G=1/0,fe=-1/0,ae=1/0,Be=-1/0;for(const Z of n.columns)for(const oe of Z.strips||[])for(const ze of oe.srcQuad)ze[0]<G&&(G=ze[0]),ze[0]>fe&&(fe=ze[0]),ze[1]<ae&&(ae=ze[1]),ze[1]>Be&&(Be=ze[1]);if((Oe=n.banxin)!=null&&Oe.current_page_strips)for(const Z of n.banxin.current_page_strips)for(const oe of Z.srcQuad)oe[0]<G&&(G=oe[0]),oe[0]>fe&&(fe=oe[0]),oe[1]<ae&&(ae=oe[1]),oe[1]>Be&&(Be=oe[1]);return isFinite(G)||(G=0),isFinite(fe)||(fe=ee),isFinite(ae)||(ae=0),isFinite(Be)||(Be=T),{top:Math.max(0,Math.round(ae)),bottom:Math.max(0,Math.round(T-Be)),left:Math.max(0,Math.round(G)),right:Math.max(0,Math.round(ee-fe)),rawMinX:G,rawMaxX:fe,rawMinY:ae,rawMaxY:Be,imgW:ee,imgH:T}},[n,s]),A=f.useMemo(()=>s?null:dx(n),[n,s]),M=z+(E?E.total_w:0),F=A?A.w:M+P.left+P.right,q=A?A.h:N+P.top+P.bottom,be=typeof window<"u"&&window.devicePixelRatio||1,[se,Y]=u?mx(F,q,h,be,p):[Math.round(F),Math.round(q)],xe=f.useCallback(()=>{const ee=b.current;if(!(!ee||!m.current)&&!(e&&I.current!==e)){if(ee.clear(F,q),s&&P.rawMinX!==void 0&&k.current&&_.current){const{rawMinX:T,rawMaxX:G,rawMinY:fe,rawMaxY:ae,imgW:Be,imgH:Oe,top:Z,bottom:oe,left:ze,right:We}=P,ye=[];ze>0&&ye.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[T,0],[T,Oe],[0,Oe]],dstRect:[0,0,ze,q]}}),Z>0&&ye.push({colOffsetX:ze,colOffsetY:0,strip:{srcQuad:[[T,0],[G,0],[G,fe],[T,fe]],dstRect:[0,0,M,Z]}}),oe>0&&ye.push({colOffsetX:ze,colOffsetY:Z+N,strip:{srcQuad:[[T,ae],[G,ae],[G,Oe],[T,Oe]],dstRect:[0,0,M,oe]}}),We>0&&ye.push({colOffsetX:ze+M,colOffsetY:0,strip:{srcQuad:[[G,0],[Be,0],[Be,Oe],[G,Oe]],dstRect:[0,0,We,q]}}),ee.renderStripsWithTexture(k.current,F,q,n.image_size[0],n.image_size[1],ye,1)}if(k.current&&_.current){const T=n.columns.flatMap(G=>(G.strips||[]).map(fe=>({colOffsetX:P.left+G.offset_x,colOffsetY:P.top,strip:fe})));if(T.length>0?ee.renderStripsWithTexture(k.current,F,q,n.image_size[0],n.image_size[1],T,1):ee.renderStripsWithTexture(k.current,F,q,n.image_size[0],n.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:A?[[A.x,A.y],[A.x+A.w,A.y],[A.x+A.w,A.y+A.h],[A.x,A.y+A.h]]:[[0,0],[n.image_size[0],0],[n.image_size[0],n.image_size[1]],[0,n.image_size[1]]],dstRect:[0,0,F,q]}}],1),E&&E.current_page_strips.length>0){const G=E.current_page_strips.map(fe=>({colOffsetX:P.left+z,colOffsetY:P.top,strip:fe}));ee.renderStripsWithTexture(k.current,F,q,n.image_size[0],n.image_size[1],G,1)}}if(E&&w.current&&y.current&&E.mate_page_strips.length>0){const T=E.mate_page_strips.map(G=>({colOffsetX:P.left+z+E.half_w,colOffsetY:P.top,strip:G}));ee.renderStripsWithTexture(w.current,F,q,E.mate_img_size[0],E.mate_img_size[1],T,.65)}}},[e,n,E,F,q,z,N,M,P,s,A]),Q=f.useRef(xe);Q.current=xe,f.useEffect(()=>{const ee=m.current;if(!ee)return;const T=ae=>{k.current=_.current?ae.createTexture(_.current):null,w.current=y.current?ae.createTexture(y.current):null,Q.current()};try{const ae=new Qr(ee);b.current=ae,T(ae)}catch(ae){console.error("Failed to init WebGL renderer:",ae)}const G=ae=>{ae.preventDefault(),console.warn("WebGL context lost")},fe=()=>{console.info("WebGL context restored, re-initializing..."),m.current&&(b.current=new Qr(m.current),T(b.current))};return ee.addEventListener("webglcontextlost",G,!1),ee.addEventListener("webglcontextrestored",fe,!1),()=>{ee.removeEventListener("webglcontextlost",G),ee.removeEventListener("webglcontextrestored",fe),b.current&&(b.current.deleteTexture(k.current),b.current.deleteTexture(w.current),b.current.destroy(),b.current=null)}},[]),f.useEffect(()=>{if(!e||!j)return;let ee=!0;return eo(e).then(T=>{if(!ee||!T)return;_.current=T,I.current=e;const G=b.current;G&&(G.deleteTexture(k.current),k.current=G.createTexture(T)),C(fe=>fe+1)}),()=>{ee=!1}},[e,j]);const le=E==null?void 0:E.mate_image_url;f.useEffect(()=>{if(!le||!j)return;let ee=!0;return eo(le).then(T=>{if(!ee||!T)return;y.current=T;const G=b.current;G&&(G.deleteTexture(w.current),w.current=G.createTexture(T)),S(fe=>fe+1)}),()=>{ee=!1}},[le,j]),Oa(()=>{j&&xe()},[xe,v,$,se,Y,j]);const we=f.useMemo(()=>(n.figBlocks??[]).map(ee=>{const[T,G,fe,ae]=ee.box;return{id:ee.id,x:P.left+T-((A==null?void 0:A.x)??0),y:P.top+G-((A==null?void 0:A.y)??0),w:Math.max(fe-T,1),h:Math.max(ae-G,1)}}),[n,P,A]),je=f.useMemo(()=>{const ee=[];for(const T of n.columns)for(const G of T.chars){const[fe,ae,Be,Oe]=G.bbox_col;ee.push({id:G.id,char:G.char,x:P.left+T.offset_x+fe-((A==null?void 0:A.x)??0),y:P.top+ae-((A==null?void 0:A.y)??0),w:Math.max(Be-fe,1),h:Math.max(Oe-ae,1)})}return ee},[n,P,A]);return t.jsxs("div",{ref:g,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${F} / ${q}`,backgroundColor:r("warp-bg"),boxShadow:r("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("img",{alt:"","aria-hidden":"true","data-warp-sizer":"",src:px(F,q),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:m,width:se,height:Y,"data-logical-size":`${Math.floor(F)}x${Math.floor(q)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:r("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${F} ${q}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[je.map(ee=>{const T=i.has(ee.id),G=o===ee.id;return t.jsx("rect",{"data-selected":T?"true":void 0,x:ee.x,y:ee.y,width:ee.w,height:ee.h,fill:T?r("warp-sel-bg"):G?r("warp-hover-bg"):"transparent",stroke:T?r("warp-sel-stroke"):G?r("warp-hover-stroke"):"transparent",strokeWidth:T?3.5:G?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>a==null?void 0:a(ee.id),onMouseEnter:()=>l==null?void 0:l(ee.id),onMouseLeave:()=>l==null?void 0:l(null),children:t.jsx("title",{children:ee.char})},ee.id)}),we.map(ee=>{const T=d===ee.id;return t.jsx("rect",{"data-fig-block":ee.id,"data-selected":T?"true":void 0,x:ee.x,y:ee.y,width:ee.w,height:ee.h,fill:T?r("warp-sel-bg"):"transparent",stroke:r(T?"warp-sel-stroke":"warp-hover-stroke"),strokeWidth:T?3.5:2,strokeDasharray:T?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>c==null?void 0:c(ee.id),children:t.jsx("title",{children:ee.id})},`fig-${ee.id}`)}),E&&t.jsxs("g",{children:[t.jsx("line",{x1:P.left+z,y1:P.top,x2:P.left+z,y2:P.top+N,stroke:r("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:P.left+z+E.half_w,y1:P.top,x2:P.left+z+E.half_w,y2:P.top+N,stroke:r("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:P.left+M,y1:P.top,x2:P.left+M,y2:P.top+N,stroke:r("warp-banxin-outer"),strokeWidth:1})]})]})]})},ns=`
1374
1378
  .bim-et-w { position: relative; display: inline; }
1375
1379
  .bim-et {
1376
1380
  color: inherit; text-decoration-line: underline;
@@ -1405,6 +1409,20 @@ a.bim-et:focus-visible { outline: 2px solid ${r("accent")}; outline-offset: 2px;
1405
1409
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
1406
1410
  margin-top: 4px; color: ${r("body-fg")};
1407
1411
  }
1412
+ .bim-et-multi { cursor: pointer; outline: none; }
1413
+ .bim-et-multi:focus-visible { outline: 2px solid ${r("accent")}; outline-offset: 2px; border-radius: 2px; }
1414
+ .bim-et-multi:hover, .bim-et-multi:focus-visible { color: ${r("accent")}; text-decoration-color: ${r("accent")}; }
1415
+ .bim-et-card-multi { width: min(340px, 86vw); max-width: none; max-height: min(60vh, 420px); overflow-y: auto; padding: 8px 12px 4px; }
1416
+ .bim-et-row { display: block; padding: 8px 0 6px; border-top: 1px solid ${r("rule")}; }
1417
+ .bim-et-card-k + .bim-et-row { margin-top: 4px; }
1418
+ .bim-et-row-t { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
1419
+ .bim-et-row-p { font-family: ${r("font-serif")}; color: ${r("accent")}; font-size: 13px; }
1420
+ .bim-et-row-k { font-size: 11px; letter-spacing: 0.1em; color: ${r("label-fg")}; }
1421
+ .bim-et-dense .bim-et-row { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 8px; padding: 6px 0; }
1422
+ .bim-et-dense .bim-et-row-t { flex: 0 0 auto; }
1423
+ .bim-et-dense .bim-et-card-d { display: none; }
1424
+ .bim-et-dense .bim-et-card-a { margin: 0 0 0 auto; }
1425
+ .bim-et-card-d2 { -webkit-line-clamp: 2; }
1408
1426
  .bim-et-card-s { display: block; color: ${r("hint-fg")}; }
1409
1427
  .bim-et-card-a { display: block; margin-top: 6px; color: ${r("accent")}; text-decoration: none; }
1410
1428
  .bim-et-card-a:hover, .bim-et-card-a:focus-visible { text-decoration: underline; }
@@ -1412,19 +1430,19 @@ a.bim-et:focus-visible { outline: 2px solid ${r("accent")}; outline-offset: 2px;
1412
1430
  .bim-et-card { animation: bim-et-in 120ms ease-out; }
1413
1431
  @keyframes bim-et-in { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }
1414
1432
  }
1415
- `,ux=120;function jt(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function mx(e,n=ux){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 gx(e){const n=e.dates&&typeof e.dates=="object"?e.dates:{},i=typeof n.birth=="number"?n.birth:void 0,o=typeof n.death=="number"?n.death:void 0;if(!(i===void 0&&o===void 0))return`${i??"?"}–${o??"?"}`}function fx(e){if(!Array.isArray(e.authors))return;const n=e.authors.map(i=>{if(!i||typeof i!="object")return"";const o=i,s=jt(o.name);return s?[jt(o.dynasty)&&`〔${jt(o.dynasty)}〕`,s,jt(o.role)].filter(Boolean).join(""):""}).filter(Boolean);return n.length?n.slice(0,3).join("、"):void 0}function yd(e,n){const i=jt(n.type),o=jt(n.primary_name)??jt(n.title)??e,s=i==="entity"?[jt(n.dynasty),gx(n),jt(n.native_place)].filter(Boolean).join(" · "):[fx(n),jt(n.edition),jt(n.measure_info)].filter(Boolean).join(" · "),a=n.description&&typeof n.description=="object"?jt(n.description.text):jt(n.description);return{id:jt(n.id)??e,type:i,title:o,meta:s||void 0,description:mx(a)}}function jd(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 vd(e){return async n=>{const i=await e.getItem(n);if(i)return yd(n,i);if(e.getEntry){const o=await e.getEntry(n);if(o)return jd(o)}return null}}const Oa=new WeakMap;function hx(e,n,i){let o=Oa.get(e);o||(o=new Map,Oa.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 kd=e=>`/item/${encodeURIComponent(e)}`,Wa={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},xx=typeof window>"u"?f.useEffect:f.useLayoutEffect;function ns(e,n){return f.useMemo(()=>n?{owner:n,load:n}:e?{owner:e,load:vd(e)}:null,[n,e])}const bx=e=>e,yx=({text:e,entities:n,offsets:i="text",plainBase:o=0,transport:s,loadSummary:a,buildHref:l=kd,onNavigate:d,renderText:c=bx,hoverDelayMs:p=250,closeDelayMs:g,injectStyles:m=!0,className:u})=>{const h=f.useMemo(()=>{const j=i==="plain"?gd(e,n,o):n;return fd(e,j)},[e,n,i,o]),x=ns(s,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[m&&t.jsx("style",{children:ts}),h.map(j=>j.type==="text"?t.jsx(f.Fragment,{children:c(j.text)},`t${j.start}`):t.jsx(is,{span:j.span,label:j.text,hasBrackets:e[j.start-1]==="《"&&e[j.start+j.text.length]==="》",loader:x,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:p,closeDelayMs:g},`${j.span.key}@${j.start}`))]})};let Zt=null;const is=({span:e,label:n,hasBrackets:i,plain:o,loader:s,buildHref:a,onNavigate:l,onCardNavigate:d=l,cardNewTab:c,renderText:p,hoverDelayMs:g,closeDelayMs:m=280})=>{const u=f.useId(),[h,x]=f.useState(!1),[j,b]=f.useState(!1),_=f.useRef(null),y=f.useRef(null),k=`bim-et bim-et-${e.kind}${o?" bim-et-nu":""}`,w=e.kind==="work"&&!i,v=t.jsxs(t.Fragment,{children:[w&&t.jsx("span",{className:"bim-et-sr",children:"《"}),p(n),w&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),C=()=>{_.current&&(clearTimeout(_.current),_.current=null)},$=()=>{y.current&&(clearTimeout(y.current),y.current=null)},S=f.useCallback(()=>{C(),$(),x(!1),b(!1),Zt===S&&(Zt=null)},[]);f.useEffect(()=>()=>{C(),$(),Zt===S&&(Zt=null)},[S]);const R=f.useCallback(()=>{Zt&&Zt!==S&&Zt(),Zt=S,x(!0)},[S]),N=f.useCallback(M=>{$(),b(!0),!h&&(C(),M<=0?R():_.current=setTimeout(R,M))},[h,R]),z=f.useCallback(()=>{C(),$(),y.current=setTimeout(S,m)},[S,m]),I=!!e.targetId,P=e.targetId,A={className:"bim-et-w","data-active":j?"":void 0,onMouseEnter:()=>N(g),onMouseLeave:z,onBlur:M=>{M.currentTarget.contains(M.relatedTarget)||S()},onKeyDown:M=>{M.key==="Escape"&&h&&(M.stopPropagation(),S())}};return!I||!P?t.jsxs("span",{...A,children:[t.jsx("span",{className:k,children:v}),h&&t.jsx(Fa,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...A,children:[t.jsx("a",{className:k,href:a(P),"data-entity-id":P,"aria-describedby":h?u:void 0,onFocus:()=>N(0),onClick:l?M=>l(P,M):void 0,children:v}),h&&t.jsx(Fa,{id:u,entityId:P,span:e,loader:s,buildHref:a,onNavigate:c?void 0:d,newTab:c})]})},Fa=({id:e,entityId:n,span:i,loader:o,buildHref:s,onNavigate:a,newTab:l})=>{const{convert:d,t:c}=re(),p=f.useRef(null),[g,m]=f.useState("start"),[u,h]=f.useState(o&&n?{status:"loading"}:{status:"ready",summary:null});f.useEffect(()=>{if(!o||!n)return;let b=!1;return h({status:"loading"}),hx(o.owner,o.load,n).then(_=>{b||h({status:"ready",summary:_})}).catch(()=>{b||h({status:"error"})}),()=>{b=!0}},[o,n]),xx(()=>{const b=p.current;if(!b||typeof window>"u")return;const _=b.getBoundingClientRect(),y=document.documentElement.clientWidth||window.innerWidth;_.right>y-8&&g==="start"&&m("end")},[u,g]);const x=u.status==="ready"?u.summary:null,j=(x==null?void 0:x.title)??i.canonicalName??i.text;return n?t.jsxs("span",{ref:p,id:e,role:"tooltip",className:"bim-et-card","data-align":g,children:[t.jsx("span",{className:"bim-et-card-k",children:d(Wa[i.kind])}),j&&t.jsx("span",{className:"bim-et-card-t",children:d(j)}),(x==null?void 0:x.meta)&&t.jsx("span",{className:"bim-et-card-m",children:d(x.meta)}),(x==null?void 0:x.description)&&t.jsx("span",{className:"bim-et-card-d",children:d(x.description)}),u.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:d("載入中…")}),u.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:d("摘要載入失敗")}),x&&t.jsx("a",{className:"bim-et-card-a",href:s(x.id||n),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?b=>a(x.id||n,b):void 0,children:c("reader.entityDetail")})]}):t.jsx("span",{ref:p,id:e,role:"tooltip",className:"bim-et-card","data-align":g,children:t.jsx("span",{className:"bim-et-card-k",children:d(Wa[i.kind])})})},rs=e=>`〔图:${e}〕`,wd=(e,n)=>e&&n?n(e.file):null;function Sd({fig:e,info:n,figUrl:i,block:o,failed:s,onFail:a}){const l=(n==null?void 0:n.alt)??"图形符号",d=wd(n,i);if(!d||s)return t.jsx("span",{className:"guji-fig-missing","data-fig-missing":e,children:rs(l)});const c=n.width>0&&n.height>0?`${n.width} / ${n.height}`:void 0;return n.mime==="image/svg+xml"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"guji-fig-img is-svg",role:"img","aria-label":l,"data-fig":e,style:{"--guji-fig-src":`url("${d}")`,aspectRatio:c}}),t.jsx("img",{src:d,alt:"",hidden:!0,onError:a})]}):t.jsx("img",{className:`guji-fig-img${o?" is-block":""}`,src:d,alt:o?l:"","data-fig":e,"data-raster":"1",loading:o?"lazy":void 0,decoding:"async",draggable:!1,style:c?{aspectRatio:c}:void 0,onError:a})}function jx({id:e,fig:n,info:i,figUrl:o,cells:s,cont:a,className:l,pageStart:d,children:c}){const{t:p}=re(),g=(i==null?void 0:i.alt)??"",m=g&&g!==p("reader.figPlain")?p("reader.figLabel",{alt:g}):p("reader.figPlain"),[u,h]=f.useState(!1),x=u||!wd(i,o);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":rs((i==null?void 0:i.alt)??"图形符号"),className:`${l} is-fig${a?" is-fig-cont":""}${x&&!a?" is-fig-missing":""}`,style:a?void 0:{"--guji-fig-n":s},title:m,"aria-label":m,role:"img",children:[t.jsx("span",{className:"guji-fig-glyph",children:c}),!a&&t.jsx(Sd,{fig:n,info:i,figUrl:o,failed:u,onFail:()=>h(!0)})]})}function vx({fig:e,info:n,figUrl:i,onClick:o}){const{t:s}=re(),a=(n==null?void 0:n.alt)??"图形符号",l=a!==s("reader.figPlain")?s("reader.figLabel",{alt:a}):s("reader.figPlain"),[d,c]=f.useState(!1);return t.jsxs("figure",{className:"guji-fig-block","data-fig-block":e,"data-fig-copy":rs(a),title:l,onClick:o,style:o?{cursor:"pointer"}:void 0,children:[t.jsx(Sd,{fig:e,info:n,figUrl:i,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const kx=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function wx(e){const n=e.cloneContents();if(!n.querySelector("[data-fig-copy]"))return null;let i="";const o=()=>{i&&!i.endsWith(`
1433
+ `,fx=120;function jt(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function hx(e,n=fx){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 xx(e){const n=e.dates&&typeof e.dates=="object"?e.dates:{},i=typeof n.birth=="number"?n.birth:void 0,o=typeof n.death=="number"?n.death:void 0;if(!(i===void 0&&o===void 0))return`${i??"?"}–${o??"?"}`}function bx(e){if(!Array.isArray(e.authors))return;const n=e.authors.map(i=>{if(!i||typeof i!="object")return"";const o=i,s=jt(o.name);return s?[jt(o.dynasty)&&`〔${jt(o.dynasty)}〕`,s,jt(o.role)].filter(Boolean).join(""):""}).filter(Boolean);return n.length?n.slice(0,3).join("、"):void 0}function yd(e,n){const i=jt(n.type),o=jt(n.primary_name)??jt(n.title)??e,s=i==="entity"?[jt(n.dynasty),xx(n),jt(n.native_place)].filter(Boolean).join(" · "):[bx(n),jt(n.edition),jt(n.measure_info)].filter(Boolean).join(" · "),a=n.description&&typeof n.description=="object"?jt(n.description.text):jt(n.description);return{id:jt(n.id)??e,type:i,title:o,meta:s||void 0,description:hx(a)}}function jd(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 vd(e){return async n=>{const i=await e.getItem(n);if(i)return yd(n,i);if(e.getEntry){const o=await e.getEntry(n);if(o)return jd(o)}return null}}const Wa=new WeakMap;function kd(e,n,i){let o=Wa.get(e);o||(o=new Map,Wa.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 wd=e=>`/item/${encodeURIComponent(e)}`,to={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Sd=typeof window>"u"?f.useEffect:f.useLayoutEffect;function is(e,n){return f.useMemo(()=>n?{owner:n,load:n}:e?{owner:e,load:vd(e)}:null,[n,e])}const yx=e=>e,jx=({text:e,entities:n,offsets:i="text",plainBase:o=0,transport:s,loadSummary:a,buildHref:l=wd,onNavigate:d,renderText:c=yx,hoverDelayMs:p=250,closeDelayMs:m,injectStyles:g=!0,className:u})=>{const h=f.useMemo(()=>{const j=i==="plain"?gd(e,n,o):n;return fd(e,j)},[e,n,i,o]),x=is(s,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[g&&t.jsx("style",{children:ns}),h.map(j=>j.type==="text"?t.jsx(f.Fragment,{children:c(j.text)},`t${j.start}`):t.jsx(rs,{span:j.span,label:j.text,hasBrackets:e[j.start-1]==="《"&&e[j.start+j.text.length]==="》",loader:x,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:p,closeDelayMs:m},`${j.span.key}@${j.start}`))]})};let Zt=null;const rs=({span:e,label:n,hasBrackets:i,plain:o,loader:s,buildHref:a,onNavigate:l,onCardNavigate:d=l,cardNewTab:c,renderText:p,hoverDelayMs:m,closeDelayMs:g=280})=>{const u=f.useId(),[h,x]=f.useState(!1),[j,b]=f.useState(!1),_=f.useRef(null),y=f.useRef(null),k=`bim-et bim-et-${e.kind}${o?" bim-et-nu":""}`,w=e.kind==="work"&&!i,v=t.jsxs(t.Fragment,{children:[w&&t.jsx("span",{className:"bim-et-sr",children:"《"}),p(n),w&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),C=()=>{_.current&&(clearTimeout(_.current),_.current=null)},$=()=>{y.current&&(clearTimeout(y.current),y.current=null)},S=f.useRef(!1),I=f.useCallback(()=>{S.current=!1,C(),$(),x(!1),b(!1),Zt===I&&(Zt=null)},[]);f.useEffect(()=>()=>{C(),$(),Zt===I&&(Zt=null)},[I]);const N=f.useCallback(()=>{Zt&&Zt!==I&&Zt(),Zt=I,x(!0)},[I]),z=f.useCallback(q=>{$(),b(!0),!h&&(C(),q<=0?N():_.current=setTimeout(N,q))},[h,N]),E=f.useCallback(()=>{C(),$(),!S.current&&(y.current=setTimeout(I,g))},[I,g]),P=f.useRef(null);f.useEffect(()=>{if(!h||!e.targets)return;const q=be=>{var se;(se=P.current)!=null&&se.contains(be.target)||I()};return document.addEventListener("pointerdown",q),()=>document.removeEventListener("pointerdown",q)},[h,e.targets,I]);const A=!!e.targetId,M=e.targetId,F={className:"bim-et-w","data-active":j?"":void 0,onMouseEnter:()=>z(m),onMouseLeave:E,onBlur:q=>{q.currentTarget.contains(q.relatedTarget)||I()},onKeyDown:q=>{q.key==="Escape"&&h&&(q.stopPropagation(),I())}};return e.targets?t.jsxs("span",{...F,ref:P,children:[t.jsx("span",{className:`${k} bim-et-multi`,role:"button",tabIndex:0,"aria-haspopup":"true","aria-expanded":h,"aria-controls":h?u:void 0,onFocus:()=>z(0),onClick:()=>{$(),S.current=!0,b(!0),N()},onKeyDown:q=>{(q.key==="Enter"||q.key===" ")&&(q.preventDefault(),h?I():(S.current=!0,b(!0),N()))},children:v}),h&&t.jsx(vx,{id:u,span:e,loader:s,buildHref:a,onNavigate:c?void 0:d,newTab:c})]}):!A||!M?t.jsxs("span",{...F,children:[t.jsx("span",{className:k,children:v}),h&&t.jsx(Fa,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...F,children:[t.jsx("a",{className:k,href:a(M),"data-entity-id":M,"aria-describedby":h?u:void 0,onFocus:()=>z(0),onClick:l?q=>l(M,q):void 0,children:v}),h&&t.jsx(Fa,{id:u,entityId:M,span:e,loader:s,buildHref:a,onNavigate:c?void 0:d,newTab:c})]})},Fa=({id:e,entityId:n,span:i,loader:o,buildHref:s,onNavigate:a,newTab:l})=>{const{convert:d,t:c}=ie(),p=f.useRef(null),[m,g]=f.useState("start"),[u,h]=f.useState(o&&n?{status:"loading"}:{status:"ready",summary:null});f.useEffect(()=>{if(!o||!n)return;let b=!1;return h({status:"loading"}),kd(o.owner,o.load,n).then(_=>{b||h({status:"ready",summary:_})}).catch(()=>{b||h({status:"error"})}),()=>{b=!0}},[o,n]),Sd(()=>{const b=p.current;if(!b||typeof window>"u")return;const _=b.getBoundingClientRect(),y=document.documentElement.clientWidth||window.innerWidth;_.right>y-8&&m==="start"&&g("end")},[u,m]);const x=u.status==="ready"?u.summary:null,j=(x==null?void 0:x.title)??i.canonicalName??i.text;return n?t.jsxs("span",{ref:p,id:e,role:"tooltip",className:"bim-et-card","data-align":m,children:[t.jsx("span",{className:"bim-et-card-k",children:d(to[i.kind])}),j&&t.jsx("span",{className:"bim-et-card-t",children:d(j)}),(x==null?void 0:x.meta)&&t.jsx("span",{className:"bim-et-card-m",children:d(x.meta)}),(x==null?void 0:x.description)&&t.jsx("span",{className:"bim-et-card-d",children:d(x.description)}),u.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:d("載入中…")}),u.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:d("摘要載入失敗")}),x&&t.jsx("a",{className:"bim-et-card-a",href:s(x.id||n),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?b=>a(x.id||n,b):void 0,children:c("reader.entityDetail")})]}):t.jsx("span",{ref:p,id:e,role:"tooltip",className:"bim-et-card","data-align":m,children:t.jsx("span",{className:"bim-et-card-k",children:d(to[i.kind])})})},vx=({id:e,span:n,loader:i,buildHref:o,onNavigate:s,newTab:a})=>{const{convert:l}=ie(),d=f.useRef(null),[c,p]=f.useState(0);Sd(()=>{const g=d.current;if(!g||typeof window>"u")return;const u=g.getBoundingClientRect();if(!u.width)return;const h=document.documentElement.clientWidth||window.innerWidth;p(Math.max(8-u.left,Math.min(0,h-8-u.right)))},[]);const m=n.targets??[];return t.jsxs("span",{ref:d,id:e,role:"group","aria-label":l(`合稱,${m.length} 條`),className:`bim-et-card bim-et-card-multi${m.length>3?" bim-et-dense":""}`,style:c?{left:c}:void 0,children:[t.jsxs("span",{className:"bim-et-card-k",children:[l("合稱")," · ",l(`${m.length} 條`)]}),m.map(g=>t.jsx(kx,{target:g,kind:n.kind,loader:i,buildHref:o,onNavigate:s,newTab:a},g.id))]})},kx=({target:e,kind:n,loader:i,buildHref:o,onNavigate:s,newTab:a})=>{const{convert:l,t:d}=ie(),[c,p]=f.useState(i?{status:"loading"}:{status:"ready",summary:null});f.useEffect(()=>{if(!i)return;let u=!1;return p({status:"loading"}),kd(i.owner,i.load,e.id).then(h=>{u||p({status:"ready",summary:h})}).catch(()=>{u||p({status:"error"})}),()=>{u=!0}},[i,e.id]);const m=c.status==="ready"?c.summary:null,g=(m==null?void 0:m.title)??e.canonicalName??e.id;return t.jsxs("span",{className:"bim-et-row","data-entity-id":e.id,children:[t.jsxs("span",{className:"bim-et-row-t",children:[e.part&&t.jsx("span",{className:"bim-et-row-p",children:wx(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(g)}),t.jsx("span",{className:"bim-et-row-k",children:l(to[n])})]}),(m==null?void 0:m.meta)&&t.jsx("span",{className:"bim-et-card-m",children:l(m.meta)}),(m==null?void 0:m.description)&&t.jsx("span",{className:"bim-et-card-d bim-et-card-d2",children:l(m.description)}),c.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:l("載入中…")}),c.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:l("摘要載入失敗")}),m&&t.jsx("a",{className:"bim-et-card-a",href:o(m.id||e.id),...a?{target:"_blank",rel:"noopener"}:{},onClick:s?u=>s(m.id||e.id,u):void 0,children:d("reader.entityDetail")})]})},wx=(e,n)=>`${n(e)} →`,os=e=>`〔图:${e}〕`,_d=(e,n)=>e&&n?n(e.file):null;function $d({fig:e,info:n,figUrl:i,block:o,failed:s,onFail:a}){const l=(n==null?void 0:n.alt)??"图形符号",d=_d(n,i);if(!d||s)return t.jsx("span",{className:"guji-fig-missing","data-fig-missing":e,children:os(l)});const c=n.width>0&&n.height>0?`${n.width} / ${n.height}`:void 0;return n.mime==="image/svg+xml"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"guji-fig-img is-svg",role:"img","aria-label":l,"data-fig":e,style:{"--guji-fig-src":`url("${d}")`,aspectRatio:c}}),t.jsx("img",{src:d,alt:"",hidden:!0,onError:a})]}):t.jsx("img",{className:`guji-fig-img${o?" is-block":""}`,src:d,alt:o?l:"","data-fig":e,"data-raster":"1",loading:o?"lazy":void 0,decoding:"async",draggable:!1,style:c?{aspectRatio:c}:void 0,onError:a})}function Sx({id:e,fig:n,info:i,figUrl:o,cells:s,cont:a,className:l,pageStart:d,children:c}){const{t:p}=ie(),m=(i==null?void 0:i.alt)??"",g=m&&m!==p("reader.figPlain")?p("reader.figLabel",{alt:m}):p("reader.figPlain"),[u,h]=f.useState(!1),x=u||!_d(i,o);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":os((i==null?void 0:i.alt)??"图形符号"),className:`${l} is-fig${a?" is-fig-cont":""}${x&&!a?" is-fig-missing":""}`,style:a?void 0:{"--guji-fig-n":s},title:g,"aria-label":g,role:"img",children:[t.jsx("span",{className:"guji-fig-glyph",children:c}),!a&&t.jsx($d,{fig:n,info:i,figUrl:o,failed:u,onFail:()=>h(!0)})]})}function _x({fig:e,info:n,figUrl:i,onClick:o}){const{t:s}=ie(),a=(n==null?void 0:n.alt)??"图形符号",l=a!==s("reader.figPlain")?s("reader.figLabel",{alt:a}):s("reader.figPlain"),[d,c]=f.useState(!1);return t.jsxs("figure",{className:"guji-fig-block","data-fig-block":e,"data-fig-copy":os(a),title:l,onClick:o,style:o?{cursor:"pointer"}:void 0,children:[t.jsx($d,{fig:e,info:n,figUrl:i,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const $x=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function Cx(e){const n=e.cloneContents();if(!n.querySelector("[data-fig-copy]"))return null;let i="";const o=()=>{i&&!i.endsWith(`
1416
1434
  `)&&(i+=`
1417
- `)},s=a=>{if(a.nodeType===3){i+=a.nodeValue??"";return}if(!(a.nodeType!==1&&a.nodeType!==11)){if(a.nodeType===1){const l=a;if(l.classList.contains("guji-page-divider")||l.style.userSelect==="none")return;const d=l.getAttribute("data-fig-copy");if(d!==null){l.tagName==="FIGURE"?(o(),i+=d,o()):i+=d;return}const c=kx.has(l.tagName);c&&o(),l.childNodes.forEach(s),c&&o();return}a.childNodes.forEach(s)}};return s(n),i.replace(/\n+$/,"")}const Sx=e=>`/item/${encodeURIComponent(e)}`;function _x(e){const n=e.filter(i=>i.kind==null||i.kind==="point");return{before:n.filter(i=>i.pos==="before"),after:n.filter(i=>i.pos!=="before")}}function $x(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 os=({pageData:e,pages:n,punctuations:i=to,selectedCharIds:o,hoveredCharId:s,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:p=!0,onVisiblePageChange:g,convert:m,scrollToPage:u,scrollToAnchor:h,onVisibleHeadingChange:x,entities:j,entityTransport:b,loadEntitySummary:_,buildEntityHref:y,onEntityNavigate:k,pageBreaks:w=!0,pageIndicatorY:v,onPageIndicatorYChange:C,quoteStyle:$,bookTitleStyle:S,showWorks:R,figures:N,figUrl:z,onFigureBlockClick:I})=>{var ge,ve,$e;const P=f.useRef(null),A=f.useRef(0),M=f.useMemo(()=>{const D=new Map;return p&&i.forEach((B,Z)=>{const me=B.id?B:{...B,id:`${B.anchor}#${Z}`},V=D.get(me.anchor)||[];V.push(me),D.set(me.anchor,V)}),D},[i,p]),F=f.useMemo(()=>$===void 0&&S===void 0&&R===void 0?null:{quoteStyle:$??"original",hideBookBrackets:S==="wavy"||R===!1},[$,S,R]),ne=S==="bracket",je=f.useMemo(()=>{var _e;const D=n&&n.length>0?n:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],B=new Map;for(const K of D)for(const ke of K.columns)ke.chars.length>0&&!ke.raised&&B.set(ke.lead_blank||0,(B.get(ke.lead_blank||0)||0)+1);let Z=0,me=-1;for(const[K,ke]of B)(ke>me||ke===me&&K<Z)&&(Z=K,me=ke);const V=K=>!!K.raised||(K.lead_blank||0)<Z,U=D.filter(K=>K.columns.some(ke=>ke.chars.length>0||ke.kind==="figure")).map(K=>{const ke=[...K.columns].sort((qe,q)=>qe.col-q.col),he=[];let Ee=[];const Se=()=>{const qe=Ex(M.get(Ee[0].charData.id));he.push({id:`para-p${K.page}-${he.length}`,chars:Ee,...qe?{heading:{level:qe.mark.length,anchor:Ee[0].charData.id,...qe.toc===!1?{toc:!1}:{}}}:{}}),Ee=[]};let Fe=!1,Ye=0,et;const Ke=[];for(const qe of ke){if(qe.kind==="figure"&&qe.fig){Ee.length>0?Se():he.length===0&&(Fe=!0),Ke.push({before:he.length,fig:qe.fig,...qe.figBox?{box:qe.figBox}:{}}),Ye=0;continue}if(qe.chars.length===0){qe.kind==="blank"&&Ye++;continue}const q=qe.raised||qe.lead_blank||Ye?{raised:qe.raised,leadBlank:qe.lead_blank,blankBefore:Ye}:void 0;Ye=0,V(qe)||(et=qe.lead_blank||0);let Ae=!0;for(const Qe of qe.chars){const st=M.get(Qe.id),{before:at,after:Tt}=st?_x(st):Tx,tt=!!st&&st.some(xt=>xt.kind==="break"&&xt.pos!=="before");st&&st.some(xt=>xt.kind==="heading")&&(Ee.length>0?Se():he.length===0&&(Fe=!0)),Ee.push({charData:Qe,col:qe.col,beforePuncts:at,afterPuncts:Tt,...Ae&&q?{start:q}:{}}),Ae=!1,tt&&Se()}}const ct=Ee.length>0;return ct&&Se(),{page:K.page,paragraphs:he,endsOpen:ct,...et!==void 0?{tailLead:et}:{},...Fe?{leadStarts:Fe}:{},...K.label?{label:K.label}:{},...Ye>0?{trailingBlank:Ye}:{},...Ke.length>0?{blocks:Ke}:{}}}),Me=new Map;if(!w){let K=null;for(const ke of U){const he=ke.paragraphs[0],Ee=(_e=he==null?void 0:he.chars[0])==null?void 0:_e.start,Se=(Ee==null?void 0:Ee.leadBlank)||0,Fe=!!Ee&&!Ee.raised&&Se>=Z&&Se>((K==null?void 0:K.tailLead)??Z),Ye=!!ke.leadStarts||!!(Ee!=null&&Ee.blankBefore)||Fe,et=ke.paragraphs.length===1&&!!ke.trailingBlank;if(K&&he&&!Ye&&!et){for(const Ke of he.chars)Me.set(Ke.charData.id,K.owner);K.para.chars=K.para.chars.concat(he.chars),ke.leadFirstId=he.chars[0].charData.id,ke.paragraphs=ke.paragraphs.slice(1),ke.blocks&&(ke.blocks=ke.blocks.map(Ke=>({...Ke,before:Ke.before-1})))}if(ke.endsOpen&&!ke.trailingBlank){const Ke=ke.paragraphs[ke.paragraphs.length-1];Ke?K={para:Ke,owner:ke.page,tailLead:ke.tailLead??(K==null?void 0:K.tailLead)??Z}:K&&ke.tailLead!==void 0&&(K.tailLead=ke.tailLead)}else K=null}}const He=new Map;for(const K of U)K.leadFirstId&&He.set(K.leadFirstId,K.page);return{pages:U,mergedOwner:Me,pageStarts:He}},[n,e,M,w]),ae=je.pages,Y=f.useRef(ae);Y.current=ae;const xe=f.useMemo(()=>ae.map(D=>D.paragraphs.reduce((B,Z)=>B+Z.chars.length,0)),[ae]),J=f.useCallback((D,B)=>{let Z=D,me=0;for(;Z<xe.length&&(Z===D||me+xe[Z]<=B);)me+=xe[Z++];return Z},[xe]),le=`${ae.length}:${(($e=(ve=(ge=ae[0])==null?void 0:ge.paragraphs[0])==null?void 0:ve.chars[0])==null?void 0:$e.charData.id)??""}`,[we,ye]=f.useState(()=>({sig:le,n:J(0,Ha)}));let Q=we.n;we.sig!==le&&(Q=J(0,Ha),ye({sig:le,n:Q})),Q=Math.min(Q,ae.length);const T=Q>=ae.length;f.useEffect(()=>T?void 0:(B=>{const Z=window;if(Z.requestIdleCallback){const V=Z.requestIdleCallback(B,{timeout:300});return()=>{var U;return(U=Z.cancelIdleCallback)==null?void 0:U.call(Z,V)}}const me=setTimeout(B,16);return()=>clearTimeout(me)})(()=>ye(B=>B.sig===le?{sig:B.sig,n:Math.max(B.n,J(B.n,Cx))}:B)),[T,Q,le,J]);const G=f.useCallback(D=>{const B=Y.current.findIndex(me=>me.page>=D),Z=(B<0?Y.current.length:B)+2;ye(me=>me.n>=Z?me:{...me,n:Z})},[]),fe=T?ae:ae.slice(0,Q);f.useEffect(()=>{let D;const B=requestAnimationFrame(()=>{D=setTimeout(()=>{const Z=P.current,me=Z==null?void 0:Z.querySelector(".guji-reflow-paragraph");if(!Z||!me)return;const V=getComputedStyle(me),U=parseFloat(V.fontSize),Me=me.clientWidth;if(!(U>0)||!(Me>0))return;const He=parseFloat(V.lineHeight);Z.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(Me/U)))),Z.style.setProperty("--gtv-lh",`${Math.round(He>0?He:U*2)}px`)},0)});return()=>{cancelAnimationFrame(B),D&&clearTimeout(D)}},[le]);const se=f.useMemo(()=>{const D=[];for(const B of ae)for(const Z of B.paragraphs)for(const me of Z.chars)D.push(me.charData.id);return D},[ae]),Be=f.useMemo(()=>{const D=new Map;if(!j||j.length===0)return D;const B=new Map(se.map((Z,me)=>[Z,me]));for(const Z of j){if(!Z.anchor)continue;const me=B.get(Z.anchor.start),V=B.get(Z.anchor.end);if(!(me===void 0||V===void 0||V<me))for(let U=me;U<=V;U++)D.has(se[U])||D.set(se[U],Z)}return D},[j,se]),Oe=ns(b,_),X=Be.size>0,oe=f.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:g,onEntityNavigate:k,onVisibleHeadingChange:x,onFigureBlockClick:I});oe.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:g,onEntityNavigate:k,onVisibleHeadingChange:x,onFigureBlockClick:I};const ze=f.useMemo(()=>({click:D=>{var B,Z;A.current=Date.now()+1200,(Z=(B=oe.current).onCharClick)==null||Z.call(B,D)},enter:D=>{var B,Z;return(Z=(B=oe.current).onCharHover)==null?void 0:Z.call(B,D)},leave:()=>{var D,B;return(B=(D=oe.current).onCharHover)==null?void 0:B.call(D,null)},figBlock:D=>{var B,Z;return(Z=(B=oe.current).onFigureBlockClick)==null?void 0:Z.call(B,D)},navigate:(D,B)=>{B.ctrlKey||B.metaKey||B.shiftKey||(B.preventDefault(),B.detail===0&&window.open(B.currentTarget.href,"_blank","noopener"))}}),[]),We=Ix(o,je.mergedOwner),be=f.useRef(Q);be.current=Q;const H=f.useRef(null),ce=f.useCallback(D=>{const B=H.current,Z=B==null?void 0:B.map.get(D);if(Z&&Z.isConnected)return Z;if(B&&B.for===Y.current&&B.n===be.current&&!Z)return null;const me=P.current;if(!me)return null;const V=new Map;return me.querySelectorAll("span[data-char-id]").forEach(U=>{V.set(U.getAttribute("data-char-id"),U)}),H.current={for:Y.current,n:be.current,map:V},V.get(D)??null},[]),de=f.useRef(null);f.useEffect(()=>{var B;if((B=de.current)==null||B.classList.remove("is-hovered"),de.current=null,!s)return;const D=ce(s);D&&(D.classList.add("is-hovered"),de.current=D)},[s,ce]);const ee=f.useRef(null),Ce=D=>{var Z;const B=D instanceof Element?D.closest("span[data-char-id]"):null;return B&&((Z=P.current)!=null&&Z.contains(B))?B.getAttribute("data-char-id"):null},Ue=D=>{const B=Ce(D.target);B&&ze.click(B)},Ge=D=>{const B=Ce(D.target);B!==ee.current&&(ee.current=B,B?ze.enter(B):ze.leave())},nt=D=>{const B=typeof window<"u"?window.getSelection():null;if(!B||B.isCollapsed||B.rangeCount===0)return;const Z=wx(B.getRangeAt(0));Z!==null&&(D.clipboardData.setData("text/plain",Z),D.preventDefault())},O=()=>{ee.current!==null&&(ee.current=null,ze.leave())};f.useEffect(()=>{let D=null;const B=()=>{var Ye,et;D=null;const me=window.getSelection(),V=P.current;if(!me||me.isCollapsed||me.rangeCount===0||!V)return;const U=me.getRangeAt(0),Me=U.commonAncestorContainer,He=Me.nodeType===3?Me.parentElement:Me;if(!He||!V.contains(He))return;const _e=V.querySelectorAll("span[data-char-id]"),K=Ke=>{let ct=Ke;for(;ct.nodeType!==3&&ct.firstChild;)ct=ct.firstChild;return ct};let ke=0,he=_e.length;for(;ke<he;){const Ke=ke+he>>1;U.comparePoint(K(_e[Ke]),0)<0?ke=Ke+1:he=Ke}const Ee=ke;for(he=_e.length;ke<he;){const Ke=ke+he>>1;U.comparePoint(K(_e[Ke]),0)<=0?ke=Ke+1:he=Ke}let Se=ke-1;if(Se>=Ee&&U.endOffset===0&&U.endContainer===K(_e[Se])&&Se--,Se<Ee)return;const Fe=[];for(let Ke=Ee;Ke<=Se;Ke++)Fe.push(_e[Ke].getAttribute("data-char-id"));Fe.length>0&&(A.current=Date.now()+1200,(et=(Ye=oe.current).onSelectionChange)==null||et.call(Ye,Fe))},Z=()=>{D&&clearTimeout(D),D=setTimeout(B,120)};return document.addEventListener("selectionchange",Z),()=>{document.removeEventListener("selectionchange",Z),D&&clearTimeout(D)}},[]);const ue=f.useRef(null);f.useEffect(()=>{if(o.size!==1||ue.current===o)return;const D=Array.from(o)[0],B=ce(D);if(B)ue.current=o,B.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const Z=parseInt(D.split(":")[0],10);isNaN(Z)||G(Z)}},[o,Q,ce,G]);const Re=D=>{var me;const B=P.current;if(!B)return null;const Z=(me=ae.find(V=>V.page===D))==null?void 0:me.leadFirstId;return Z?B.querySelector(`span[data-char-id="${Z}"]`):B.querySelector(`[data-page-section="${D}"]`)},W=u==null?void 0:u.nonce,pe=f.useRef(null);f.useEffect(()=>{if(!u||pe.current===u.nonce)return;const D=Re(u.page);if(!D){!T&&ae.some(B=>B.page>=u.page)&&G(u.page);return}pe.current=u.nonce,A.current=Date.now()+800,D.scrollIntoView({behavior:"auto",block:"start"})},[W,Q]);const ie=f.useRef(null);f.useEffect(()=>{var V,U;if(!h||ie.current===h.nonce)return;const D=P.current,B=D==null?void 0:D.querySelector(`span[data-char-id="${Lx(h.anchor)}"]`);if(!B){const Me=parseInt(h.anchor.split(":")[0],10);!T&&!isNaN(Me)&&G(Me);return}ie.current=h.nonce;const Z=B.closest(".guji-reflow-paragraph")??B;A.current=Date.now()+800,Z.scrollIntoView({behavior:"auto",block:"start"});const me=parseInt(h.anchor.split(":")[0],10);isNaN(me)||(U=(V=oe.current).onVisiblePageChange)==null||U.call(V,me)},[h,ae,Q,T,G]);const Ne=!!g||!!x,Le=!!g&&typeof v=="number",[Ve,Xe]=f.useState(null),ot=no(Ve??v??0),it=f.useRef(null);it.current=Le?ot:null;const E=f.useRef(()=>{});return f.useEffect(()=>{var he,Ee;if(!Ne)return;const D=new Map,B=new Map;(he=P.current)==null||he.querySelectorAll("[data-page-section],[data-page-start]").forEach(Se=>{const Fe=Se.getAttribute("data-page-section");Fe!==null?D.set(Fe,Se):B.set(Se.getAttribute("data-page-start"),Se)});const Z=[],me=[];for(const Se of fe){const Fe=D.get(String(Se.page));Fe&&(Z.push(Fe),me.push(Se.page))}if(Z.length===0)return;const V=new Map(Z.map((Se,Fe)=>[Se,Fe])),U=Z.map(()=>[]);let Me=0;(Ee=P.current)==null||Ee.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Se=>{const Fe=V.get(Se.closest("[data-page-section]"));Fe!==void 0&&(U[Fe].push(Se),Me++)});let He,_e=0;const K=()=>{var qe,q;if(_e=0,Date.now()<A.current)return;const Se=Ae=>Ae.getBoundingClientRect().top;if(Z.length>1&&Se(Z[0])===Se(Z[Z.length-1]))return;const Fe=it.current===null?120:it.current*window.innerHeight;let Ye=0,et=Z.length-1;for(;Ye<et;){const Ae=Ye+et+1>>1;Se(Z[Ae])<=Fe?Ye=Ae:et=Ae-1}const Ke=Se(Z[0])>Fe;let ct=me[Ye];for(let Ae=Ye+1;Ae<Z.length;Ae++){const Qe=B.get(String(me[Ae]));if(!Qe||!Z[Ye].contains(Qe)||Se(Qe)>Fe)break;ct=me[Ae]}if(Me>0&&oe.current.onVisibleHeadingChange){let Ae=null;if(!Ke){const st=U[Ye];for(let at=st.length-1;at>=0&&!Ae;at--)Se(st[at])<=Fe&&(Ae=st[at]);for(let at=Ye-1;at>=0&&!Ae;at--)U[at].length>0&&(Ae=U[at][U[at].length-1])}const Qe=Ae?Rx(Ae):null;Qe!==He&&(He=Qe,oe.current.onVisibleHeadingChange(Qe))}(q=(qe=oe.current).onVisiblePageChange)==null||q.call(qe,ct)},ke=()=>{_e||(_e=requestAnimationFrame(K))};return E.current=()=>{_e||(_e=requestAnimationFrame(K))},window.addEventListener("scroll",ke,{passive:!0}),ke(),()=>{window.removeEventListener("scroll",ke),_e&&cancelAnimationFrame(_e),E.current=()=>{}}},[Ne,ae,Q]),f.useEffect(()=>{Le&&E.current()},[Le,ot]),t.jsxs("div",{ref:P,className:"guji-text-pane-content",onClick:Ue,onMouseOver:Ge,onMouseLeave:O,onCopy:nt,children:[X&&t.jsx("style",{children:ts}),Le&&t.jsx(Wx,{y:ot,containerRef:P,onDrag:Xe,onCommit:D=>{Xe(null),C==null||C(D)}}),t.jsx("div",{className:"guji-text-reflow-view",children:fe.map((D,B)=>t.jsx(Px,{pGroup:D,first:B===0,pageBreaks:w,markOpts:F,plainBooks:ne,selected:We.get(D.page)??Nx,entityOfChar:Be,entityLoader:Oe,convert:m,buildHref:y??Sx,handlers:ze,charCount:xe[B]??0,pageStarts:je.pageStarts,figures:N,figUrl:z},`page-sec-${D.page}`))})]})},Ha=1800,Cx=800,zx="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",Nx=new Set,to=[],Tx={before:to,after:to};function Ix(e,n){const i=f.useRef(new Map);return f.useMemo(()=>{const o=new Map;e.forEach(a=>{const l=n.get(a)??parseInt(a.split(":")[0],10);let d=o.get(l);d||o.set(l,d=new Set),d.add(a)});const s=new Map;return o.forEach((a,l)=>{const d=i.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(p=>d.has(p));s.set(l,c?d:a)}),i.current=s,s},[e,n])}function Ex(e){return e==null?void 0:e.find(n=>n.kind==="heading"&&/^#{1,6}$/.test(n.mark))}function Rx(e){return e.getAttribute("data-heading-anchor")}function Lx(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}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 Ax(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))}function Mx({heading:e,children:n}){if(!e)return t.jsx("p",{className:"guji-reflow-paragraph",children:n});const i=`h${Math.min(6,e.level+1)}`;return t.jsx(i,{className:`guji-reflow-paragraph guji-reflow-heading guji-reflow-h${e.level}`,"data-heading-anchor":e.anchor,"data-heading-level":e.level,"data-heading-toc":e.toc===!1?"0":void 0,children:n})}const Px=f.memo(function({pGroup:n,first:i,pageBreaks:o,markOpts:s,plainBooks:a,selected:l,entityOfChar:d,entityLoader:c,convert:p,buildHref:g,handlers:m,charCount:u,pageStarts:h,figures:x,figUrl:j}){const b=f.useMemo(()=>{const v=new Map;if(!p)return v;for(const C of n.paragraphs){const $=Ax(C.chars.map(S=>S.charData.fig?S.charData.char:S.charData.norm??S.charData.char),p);C.chars.forEach((S,R)=>v.set(S.charData.id,S.charData.fig?S.charData.char:$[R]))}return v},[n,p]),_=v=>b.get(v.id)??v.char,{t:y}=re(),k=v=>{const C=s?cd(v.mark,s):v.mark;return C?t.jsx("span",{className:"guji-text-punct","data-punct-id":v.id,children:C},v.id):null},w=v=>{var C;return(C=n.blocks)==null?void 0:C.map(($,S)=>$.before===v&&t.jsx(vx,{fig:$.fig,info:x==null?void 0:x.get($.fig),figUrl:j,onClick:()=>m.figBlock({page:n.page,fig:$.fig,...$.box?{box:$.box}:{}})},`fig-${$.fig}-${S}`))};return t.jsxs("section",{"data-page-section":n.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:zx,"--gtv-pc":u,"--gtv-pp":n.paragraphs.length},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((v,C)=>t.jsxs(f.Fragment,{children:[w(C),t.jsxs(Mx,{heading:v.heading,children:[$x(v.chars,d).map(($,S)=>{const R=$.chars.map(({charData:I,beforePuncts:P,afterPuncts:A,start:M},F)=>{var we;const ne=!!$.entity&&F===0,je=!!$.entity&&F===$.chars.length-1,ae=ne?[]:P,Y=je?[]:A,xe=!!I.fig&&F>0&&$.chars[F-1].charData.fig===I.fig;let J=1;if(I.fig&&!xe)for(;((we=$.chars[F+J])==null?void 0:we.charData.fig)===I.fig;)J++;const le=`guji-text-char${l.has(I.id)?" is-selected":""}${I.sub?" is-sub":""}${I.lane==="solo"?" is-solo":""}${M!=null&&M.raised?" is-raised":""}`;return t.jsxs(f.Fragment,{children:[M&&M.blankBefore>0&&t.jsx(Da,{n:M.blankBefore}),ae.map(k),I.fig?t.jsx(jx,{id:I.id,fig:I.fig,info:x==null?void 0:x.get(I.fig),figUrl:j,cells:J,cont:xe,className:le,pageStart:h.get(I.id),children:_(I)}):t.jsx("span",{"data-char-id":I.id,"data-page-start":h.get(I.id),className:`guji-text-char${l.has(I.id)?" is-selected":""}${I.sub?" is-sub":""}${I.lane==="solo"?" is-solo":""}${I.lacuna?" is-lacuna":""}${I.lacuna&&I.guess_c?" has-guess":""}${I.guess?" is-guess":""}${I.zi?" is-zi":""}${M!=null&&M.raised?" is-raised":""}`,"data-raised":(M==null?void 0:M.raised)||void 0,"data-guji-guess":I.lacuna&&I.guess_c?I.guess_c:void 0,title:I.lacuna?I.guess_c?y("reader.lacunaGuess",{guess:p?p(I.guess_c):I.guess_c}):y("detail.lacuna"):I.zi?y("detail.composedChar",{label:I.zi}):I.guess?y("reader.charGuess"):void 0,children:_(I)}),Y.map(k)]},I.id)});if(!$.entity)return t.jsx(f.Fragment,{children:R},`r${S}`);const N=$.chars[0].beforePuncts.map(k),z=$.chars[$.chars.length-1].afterPuncts.map(k);return t.jsxs(f.Fragment,{children:[N,t.jsx(is,{span:$.entity,label:$.chars.map(I=>_(I.charData)).join(""),hasBrackets:!0,plain:a&&$.entity.kind==="work",loader:c,buildHref:g,onNavigate:m.navigate,cardNewTab:!0,renderText:()=>R,hoverDelayMs:250}),z]},`${$.entity.key}@${S}`)}),C===n.paragraphs.length-1&&n.trailingBlank?t.jsx(Da,{n:n.trailingBlank}):null]})]},v.id)),w(n.paragraphs.length)]})});function no(e){const[n,i]=Xn,o=Number.isFinite(e)?e:.33;return Math.round(Math.min(i,Math.max(n,o))*1e3)/1e3}const Bx=.02,xn=16,Ox=4;function Wx({y:e,containerRef:n,onDrag:i,onCommit:o}){const{t:s}=re(),[a,l]=f.useState(0),d=f.useRef(!1),c=f.useRef(null),p=f.useRef(e);p.current=e;const g=f.useCallback(()=>{var j;const u=((j=c.current)==null?void 0:j.parentElement)??n.current,h=(u==null?void 0:u.closest(".bim-rd-col"))??u,x=h==null?void 0:h.getBoundingClientRect();l(Math.max(0,((x==null?void 0:x.left)??0)-xn-Ox))},[n]);f.useLayoutEffect(()=>{var j;window.addEventListener("resize",g);const u=((j=c.current)==null?void 0:j.parentElement)??n.current,h=(u==null?void 0:u.closest(".bim-rd-col"))??u,x=typeof ResizeObserver<"u"?new ResizeObserver(()=>g()):null;for(const b of[h,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])b&&(x==null||x.observe(b));return x||g(),()=>{window.removeEventListener("resize",g),x==null||x.disconnect()}},[g,n]);const m=u=>no(u/Math.max(1,window.innerHeight));return t.jsx("div",{ref:c,role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":s("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Xn[0]*100),"aria-valuemax":Math.round(Xn[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${xn/2}px)`,width:xn,height:xn,zIndex:20,cursor:"ns-resize",touchAction:"none",display:"flex",alignItems:"center",justifyContent:"center",color:r("meta-fg")},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const h=m(u.clientY);p.current=h,i(h)},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(p.current))},onKeyDown:u=>{const h=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;h&&(u.preventDefault(),o(no(e+h*(u.shiftKey?5:1)*Bx)))},children:t.jsx("svg",{width:xn,height:xn,viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2 8h11M9 4l4 4-4 4"})})})}const _d=1,$d=6,bi={s:1,x:0,y:0},Si=(e,n,i)=>Math.min(i,Math.max(n,e));function ss(e,n,i){const o=Si(e.s,_d,$d);return{s:o,x:Si(e.x,n*(1-o),0),y:Si(e.y,i*(1-o),0)}}function zr(e,n,i,o,s,a){const l=Si(e.s*o,_d,$d),d=l/e.s;return ss({s:l,x:n-(n-e.x)*d,y:i-(i-e.y)*d},s,a)}function Fx(e,n,i,o,s){return ss({s:e.s,x:e.x+n,y:e.y+i},o,s)}function Hx(e,n,i){const o=n===1?e*16:n===2?e*400:e;return Math.exp(-o*(i?.01:.0015))}const Ua=4,Dx=f.forwardRef(function({children:n,onScaleChange:i,resetKey:o,style:s},a){const l=f.useRef(null),[d,c]=f.useState(bi),p=f.useRef(d),g=f.useRef(i);g.current=i;const m=y=>{var w;const k=p.current;p.current=y,c(y),y.s!==k.s&&((w=g.current)==null||w.call(g,y.s))},u=()=>{var k;const y=(k=l.current)==null?void 0:k.getBoundingClientRect();return{w:(y==null?void 0:y.width)??0,h:(y==null?void 0:y.height)??0,left:(y==null?void 0:y.left)??0,top:(y==null?void 0:y.top)??0}};f.useImperativeHandle(a,()=>({zoomBy(y){const{w:k,h:w}=u();m(zr(p.current,k/2,w/2,y,k,w))},reset(){m(bi)}})),f.useEffect(()=>{m(bi)},[o]),f.useEffect(()=>{const y=l.current;if(!y||typeof ResizeObserver>"u")return;const k=new ResizeObserver(()=>{const{w,h:v}=u(),C=ss(p.current,w,v);(C.x!==p.current.x||C.y!==p.current.y)&&m(C)});return k.observe(y),()=>k.disconnect()},[]),f.useEffect(()=>{const y=l.current;if(!y)return;const k=w=>{const v=Hx(w.deltaY,w.deltaMode,w.ctrlKey);if(p.current.s<=1&&v<1)return;w.preventDefault();const{w:C,h:$,left:S,top:R}=u();m(zr(p.current,w.clientX-S,w.clientY-R,v,C,$))};return y.addEventListener("wheel",k,{passive:!1}),()=>y.removeEventListener("wheel",k)},[]);const h=f.useRef(new Map),x=f.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),j=y=>{if(y.pointerType==="mouse"&&y.button!==0)return;h.current.set(y.pointerId,{x:y.clientX,y:y.clientY});const k=x.current;if(k.swallowClick=!1,h.current.size===1&&(k.moved=0,k.dragging=!1),h.current.size===2){const[w,v]=[...h.current.values()];k.pinchDist=Math.hypot(w.x-v.x,w.y-v.y),k.moved=Ua+1}},b=y=>{var I;const k=h.current.get(y.pointerId);if(!k)return;const w={x:y.clientX,y:y.clientY};h.current.set(y.pointerId,w);const v=x.current,{w:C,h:$,left:S,top:R}=u();if(h.current.size>=2){const[P,A]=[...h.current.values()],M=Math.hypot(P.x-A.x,P.y-A.y);if(v.pinchDist>0&&M>0){const F=(P.x+A.x)/2-S,ne=(P.y+A.y)/2-R;m(zr(p.current,F,ne,M/v.pinchDist,C,$))}v.pinchDist=M,v.swallowClick=!0;return}const N=w.x-k.x,z=w.y-k.y;if(v.moved+=Math.abs(N)+Math.abs(z),!(v.moved<=Ua)){if(!v.dragging){v.dragging=!0;try{(I=l.current)==null||I.setPointerCapture(y.pointerId)}catch{}}v.swallowClick=!0,p.current.s>1&&m(Fx(p.current,N,z,C,$))}},_=y=>{h.current.delete(y.pointerId);const k=x.current;k.pinchDist=0,h.current.size===0&&(k.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:j,onPointerMove:b,onPointerUp:_,onPointerCancel:_,onClickCapture:y=>{x.current.swallowClick&&(x.current.swallowClick=!1,y.stopPropagation(),y.preventDefault())},onDoubleClick:()=>m(bi),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 Cd(e,n,i,o){const[s,a]=f.useState(n??null),[l,d]=f.useState(!1),c=f.useRef(0);return f.useEffect(()=>{if(n!==void 0){a(n);return}const p=++c.current;if(!i){a(null),d(!1);return}if(e){let g;try{g=e(i,o)}catch{a(null),d(!1);return}if(!g||typeof g.then!="function"){a(g??null),d(!1);return}d(!0),g.then(m=>{p===c.current&&a(m??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 Ux(e,n,i){const[o,s]=f.useState([]),a=f.useRef(0);return f.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?md(c):[])}).catch(()=>{l===a.current&&s([])})},[e,n,i]),o}const Vx=/^#{1,6}$/,Gx=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function Yx(e){let n=e.trim();const i=Gx.exec(n);return i&&(n=i[1]+i[2]),n.replace(/[《》〈〉]/g,"").trim()}const Va=e=>e.kind==null||e.kind==="point";function zd(e,n){var d;if(!e||!n||n.length===0)return[];const i=new Map;let o=!1;for(const c of n){c.kind==="heading"&&(o=!0);const p=i.get(c.anchor);p?p.push(c):i.set(c.anchor,[c])}if(!o)return[];const s=[];let a=null;const l=()=>{a&&(a.fixed||(a.h.label=Yx(a.text)),a.h.label&&s.push(a.h)),a=null};for(const c of e){const p=[...c.columns].sort((g,m)=>g.col-m.col);for(const g of p)for(const m of g.chars){const u=i.get(m.id)??[],h=u.find(x=>x.kind==="heading"&&x.pos==="before"&&Vx.test(x.mark));if(h&&l(),h&&h.toc!==!1){const x=(d=h.label)==null?void 0:d.trim();a={h:{level:h.mark.length,label:x??"",anchor:m.id},text:"",fixed:!!x}}if(a&&!a.fixed){for(const x of u)Va(x)&&x.pos==="before"&&(a.text+=x.mark);a.text+=m.char;for(const x of u)Va(x)&&x.pos!=="before"&&(a.text+=x.mark)}u.some(x=>x.kind==="break"&&x.pos!=="before")&&l()}}return l(),s}function io(e){if(!Array.isArray(e))return[];const n=[];for(const i of e){if(!i||typeof i!="object")continue;const{level:o,label:s,anchor:a}=i;typeof o!="number"||!Number.isInteger(o)||o<1||o>6||typeof s!="string"||!s.trim()||typeof a!="string"||!a||n.push({level:o,label:s.trim(),anchor:a})}return n}function as(e,n){return`${e}#${n}`}function Nd(e){const n=e.indexOf("#");return n<=0||n===e.length-1?null:{chapter:e.slice(0,n),anchor:e.slice(n+1)}}function Td(e){const n=[],i=[];for(const o of e){const s={...o,children:[]};for(;i.length>0&&i[i.length-1].level>=o.level;)i.pop();i.length===0?n.push(s):i[i.length-1].children.push(s),i.push(s)}return n}function ro(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const qx=150,Ga={padding:24,color:r("desc-fg"),fontSize:14};function Ya({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 qa=/^https?:\/\//i,Kx=[];function Xx(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&&qa.test(i)?i:void 0,license:n(e.license),license_url:o&&qa.test(o)?o:void 0,note:n(e.note)};return s.name||s.license||s.note?s:null}function Zx(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 Ka(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)||Array.isArray(n==null?void 0:n.heading_levels)&&n.heading_levels.length>0?"冊":Ie.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function Id(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 Ed(e,n,i){return n.map(o=>({key:as(e,o.anchor),label:i(o.label),inChapter:!0,...o.children.length>0?{selectable:!0,children:Ed(e,o.children,i)}:{}}))}function Jx(e,n,i,o,s,a=()=>[]){var g;const l=new Map(e.chapters.map(m=>[m.file,m])),d=m=>m==="loading"?"…":typeof m=="number"&&m>0?m:void 0,c=(m,u)=>{const h=l.get(m),x=h?a(h):[];return{key:m,label:u??(h?Id(h,i,o,s):m),hint:d(n[m]),disabled:n[m]===0,...x.length>0?{selectable:!0,children:Ed(m,Td(x),o)}:{}}},p=(g=e.juan_groups)==null?void 0:g.filter(m=>{var u;return m.files.some(h=>l.has(h))||((u=m.children)==null?void 0:u.length)});if(p&&p.length>0){const m=(u,h)=>{var j;if(u.files.length===1&&!((j=u.children)!=null&&j.length))return c(u.files[0],o(u.label));const x=Uh(u,n);return{key:`group:${h}`,label:o(u.label),hint:x==="loading"?"…":typeof x=="number"&&x>0?`${x}`:xd(u),defaultExpanded:typeof x=="number"&&x>0,children:[...u.files.filter(b=>l.has(b)).map(b=>c(b)),...(u.children??[]).map((b,_)=>m(b,`${h}.${_}`))]}};return p.map((u,h)=>m(u,`${h}`))}return e.chapters.map(m=>c(m.file))}const ls=e=>{const n=Tc();return t.jsx(um,{mode:n[0].scriptMode,children:t.jsx(Qx,{...e,prefsState:n})})},Qx=({prefsState:e,id:n,transport:i,versionKey:o,chapter:s,onLocationChange:a,onNavigate:l,anchor:d,title:c,subtitle:p,resolveImages:g,renderImageOverlay:m,imagePanel:u,allowVertical:h,onReportError:x,revisedAt:j,backHref:b,backLabel:_,resolveWarpData:y,warpData:k,resolveEntities:w,onEntityNavigate:v,className:C,style:$})=>{var Ps,Bs,Os;const{t:S,convert:R}=re(),N=f.useMemo(()=>vc(i),[i]),[z,I]=e,P=mt(),A=f.useRef(a);A.current=a;const[M,F]=f.useState(null),[ne,je]=f.useState("loading");f.useEffect(()=>{let L=!1;return F(null),je("loading"),N.getManifest(n).then(te=>{L||(te?(F(te),je("ready")):je("missing"))}).catch(()=>{L||je("missing")}),()=>{L=!0}},[N,n]);const ae=o!==void 0,Y=s!==void 0,[xe,J]=f.useState(null),[le,we]=f.useState(null);f.useEffect(()=>{J(null),we(null)},[n]);const ye=Ie.pickTextVersion(M,ae?o:xe),Q=((Ps=M==null?void 0:M.versions.find(L=>L.key==="default"))==null?void 0:Ps.key)??((Bs=M==null?void 0:M.versions[0])==null?void 0:Bs.key)??"default",T=(ye==null?void 0:ye.key)??null,G=Y?s:le,fe=f.useCallback((L,te,Te,rt)=>{var Ze;(Ze=A.current)==null||Ze.call(A,{key:L,chapter:te,isDefault:L===Q,...rt?{anchor:rt}:{}},Te)},[Q]);f.useEffect(()=>{!M||!ae||o==null||M.versions.some(L=>L.key===o)||fe(Q,null,"auto")},[M,ae,o,Q,fe]);const se=f.useRef(new Map);f.useEffect(()=>{se.current.clear()},[N,n]);const Be=f.useCallback(async L=>{const te=`${n}
1418
- ${L}`;if(se.current.has(te))return se.current.get(te)??null;const Te=await N.getIndex(n,L).catch(()=>null);return Te&&se.current.set(te,Te),Te},[N,n]),[Oe,X]=f.useState(null),[oe,ze]=f.useState("loading"),We=T?`${n}
1419
- ${T}`:null,be=Oe&&Oe.owner===We?Oe.idx:null;f.useEffect(()=>{if(!T)return;let L=!1;const te=`${n}
1420
- ${T}`;return X(null),ze("loading"),Be(T).then(Te=>{L||(Te&&Te.chapters.length>0?(X({owner:te,idx:Te}),ze("ready")):ze("failed"))}),()=>{L=!0}},[n,T,Be]),f.useEffect(()=>{if(!be||!T||G!=null&&be.chapters.some(Te=>Te.file===G))return;const te=be.chapters[0].file;Y||we(te),fe(T,te,"auto")},[be,T,G,Y,fe]);const H=be?G!=null&&be.chapters.some(L=>L.file===G)?G:be.chapters[0].file:G,ce=f.useMemo(()=>be&&H?be.chapters.find(L=>L.file===H)??null:null,[be,H]),de=f.useRef(0),ee=f.useCallback(async L=>{if(!M||L===T||!M.versions.some(It=>It.key===L))return;const te=++de.current,Te=await Be(L);if(te!==de.current)return;const rt=ce??(H?{file:H}:null),Ze=Ie.matchChapterAcrossVersions(rt,Te);ae||J(L),Y||we(Ze),fe(L,Ze,"version")},[M,T,Be,ce,H,ae,Y,fe]),[Ce,Ue]=f.useState(null),[Ge,nt]=f.useState(null),O=f.useRef(0),ue=f.useCallback((L,te)=>{Ue({chapter:L,anchor:te,nonce:++O.current}),nt({chapter:L,anchor:te})},[]),Re=f.useCallback(L=>{if(!T)return;const te=Nd(L);if(te){ue(te.chapter,te.anchor),Y||we(te.chapter),fe(T,te.chapter,"chapter",te.anchor);return}Y||we(L),fe(T,L,"chapter")},[T,Y,fe,ue]),W=f.useRef(null);f.useEffect(()=>{!d||!H||d===W.current||(W.current=d,ue(H,d))},[d,H,ue]),f.useEffect(()=>{d||(W.current=null)},[d]);const[pe,ie]=f.useState(null),Ne=T&&ce?`${n}
1435
+ `)},s=a=>{if(a.nodeType===3){i+=a.nodeValue??"";return}if(!(a.nodeType!==1&&a.nodeType!==11)){if(a.nodeType===1){const l=a;if(l.classList.contains("guji-page-divider")||l.style.userSelect==="none")return;const d=l.getAttribute("data-fig-copy");if(d!==null){l.tagName==="FIGURE"?(o(),i+=d,o()):i+=d;return}const c=$x.has(l.tagName);c&&o(),l.childNodes.forEach(s),c&&o();return}a.childNodes.forEach(s)}};return s(n),i.replace(/\n+$/,"")}const zx=e=>`/item/${encodeURIComponent(e)}`;function Nx(e){const n=e.filter(i=>i.kind==null||i.kind==="point");return{before:n.filter(i=>i.pos==="before"),after:n.filter(i=>i.pos!=="before")}}function Tx(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 ss=({pageData:e,pages:n,punctuations:i=no,selectedCharIds:o,hoveredCharId:s,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:p=!0,onVisiblePageChange:m,convert:g,scrollToPage:u,scrollToAnchor:h,onVisibleHeadingChange:x,entities:j,entityTransport:b,loadEntitySummary:_,buildEntityHref:y,onEntityNavigate:k,pageBreaks:w=!0,pageIndicatorY:v,onPageIndicatorYChange:C,quoteStyle:$,bookTitleStyle:S,showWorks:I,figures:N,figUrl:z,onFigureBlockClick:E})=>{var ge,ve,$e;const P=f.useRef(null),A=f.useRef(0),M=f.useMemo(()=>{const D=new Map;return p&&i.forEach((B,J)=>{const me=B.id?B:{...B,id:`${B.anchor}#${J}`},V=D.get(me.anchor)||[];V.push(me),D.set(me.anchor,V)}),D},[i,p]),F=f.useMemo(()=>$===void 0&&S===void 0&&I===void 0?null:{quoteStyle:$??"original",hideBookBrackets:S==="wavy"||I===!1},[$,S,I]),q=S==="bracket",be=f.useMemo(()=>{var _e;const D=n&&n.length>0?n:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],B=new Map;for(const X of D)for(const ke of X.columns)ke.chars.length>0&&!ke.raised&&B.set(ke.lead_blank||0,(B.get(ke.lead_blank||0)||0)+1);let J=0,me=-1;for(const[X,ke]of B)(ke>me||ke===me&&X<J)&&(J=X,me=ke);const V=X=>!!X.raised||(X.lead_blank||0)<J,U=D.filter(X=>X.columns.some(ke=>ke.chars.length>0||ke.kind==="figure")).map(X=>{const ke=[...X.columns].sort((qe,K)=>qe.col-K.col),he=[];let Ie=[];const Se=()=>{const qe=Mx(M.get(Ie[0].charData.id));he.push({id:`para-p${X.page}-${he.length}`,chars:Ie,...qe?{heading:{level:qe.mark.length,anchor:Ie[0].charData.id,...qe.toc===!1?{toc:!1}:{}}}:{}}),Ie=[]};let Fe=!1,Ye=0,et;const Ke=[];for(const qe of ke){if(qe.kind==="figure"&&qe.fig){Ie.length>0?Se():he.length===0&&(Fe=!0),Ke.push({before:he.length,fig:qe.fig,...qe.figBox?{box:qe.figBox}:{}}),Ye=0;continue}if(qe.chars.length===0){qe.kind==="blank"&&Ye++;continue}const K=qe.raised||qe.lead_blank||Ye?{raised:qe.raised,leadBlank:qe.lead_blank,blankBefore:Ye}:void 0;Ye=0,V(qe)||(et=qe.lead_blank||0);let Ae=!0;for(const Qe of qe.chars){const at=M.get(Qe.id),{before:lt,after:Tt}=at?Nx(at):Lx,tt=!!at&&at.some(xt=>xt.kind==="break"&&xt.pos!=="before");at&&at.some(xt=>xt.kind==="heading")&&(Ie.length>0?Se():he.length===0&&(Fe=!0)),Ie.push({charData:Qe,col:qe.col,beforePuncts:lt,afterPuncts:Tt,...Ae&&K?{start:K}:{}}),Ae=!1,tt&&Se()}}const dt=Ie.length>0;return dt&&Se(),{page:X.page,paragraphs:he,endsOpen:dt,...et!==void 0?{tailLead:et}:{},...Fe?{leadStarts:Fe}:{},...X.label?{label:X.label}:{},...Ye>0?{trailingBlank:Ye}:{},...Ke.length>0?{blocks:Ke}:{}}}),Me=new Map;if(!w){let X=null;for(const ke of U){const he=ke.paragraphs[0],Ie=(_e=he==null?void 0:he.chars[0])==null?void 0:_e.start,Se=(Ie==null?void 0:Ie.leadBlank)||0,Fe=!!Ie&&!Ie.raised&&Se>=J&&Se>((X==null?void 0:X.tailLead)??J),Ye=!!ke.leadStarts||!!(Ie!=null&&Ie.blankBefore)||Fe,et=ke.paragraphs.length===1&&!!ke.trailingBlank;if(X&&he&&!Ye&&!et){for(const Ke of he.chars)Me.set(Ke.charData.id,X.owner);X.para.chars=X.para.chars.concat(he.chars),ke.leadFirstId=he.chars[0].charData.id,ke.paragraphs=ke.paragraphs.slice(1),ke.blocks&&(ke.blocks=ke.blocks.map(Ke=>({...Ke,before:Ke.before-1})))}if(ke.endsOpen&&!ke.trailingBlank){const Ke=ke.paragraphs[ke.paragraphs.length-1];Ke?X={para:Ke,owner:ke.page,tailLead:ke.tailLead??(X==null?void 0:X.tailLead)??J}:X&&ke.tailLead!==void 0&&(X.tailLead=ke.tailLead)}else X=null}}const He=new Map;for(const X of U)X.leadFirstId&&He.set(X.leadFirstId,X.page);return{pages:U,mergedOwner:Me,pageStarts:He}},[n,e,M,w]),se=be.pages,Y=f.useRef(se);Y.current=se;const xe=f.useMemo(()=>se.map(D=>D.paragraphs.reduce((B,J)=>B+J.chars.length,0)),[se]),Q=f.useCallback((D,B)=>{let J=D,me=0;for(;J<xe.length&&(J===D||me+xe[J]<=B);)me+=xe[J++];return J},[xe]),le=`${se.length}:${(($e=(ve=(ge=se[0])==null?void 0:ge.paragraphs[0])==null?void 0:ve.chars[0])==null?void 0:$e.charData.id)??""}`,[we,je]=f.useState(()=>({sig:le,n:Q(0,Ha)}));let ee=we.n;we.sig!==le&&(ee=Q(0,Ha),je({sig:le,n:ee})),ee=Math.min(ee,se.length);const T=ee>=se.length;f.useEffect(()=>T?void 0:(B=>{const J=window;if(J.requestIdleCallback){const V=J.requestIdleCallback(B,{timeout:300});return()=>{var U;return(U=J.cancelIdleCallback)==null?void 0:U.call(J,V)}}const me=setTimeout(B,16);return()=>clearTimeout(me)})(()=>je(B=>B.sig===le?{sig:B.sig,n:Math.max(B.n,Q(B.n,Ex))}:B)),[T,ee,le,Q]);const G=f.useCallback(D=>{const B=Y.current.findIndex(me=>me.page>=D),J=(B<0?Y.current.length:B)+2;je(me=>me.n>=J?me:{...me,n:J})},[]),fe=T?se:se.slice(0,ee);f.useEffect(()=>{let D;const B=requestAnimationFrame(()=>{D=setTimeout(()=>{const J=P.current,me=J==null?void 0:J.querySelector(".guji-reflow-paragraph");if(!J||!me)return;const V=getComputedStyle(me),U=parseFloat(V.fontSize),Me=me.clientWidth;if(!(U>0)||!(Me>0))return;const He=parseFloat(V.lineHeight);J.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(Me/U)))),J.style.setProperty("--gtv-lh",`${Math.round(He>0?He:U*2)}px`)},0)});return()=>{cancelAnimationFrame(B),D&&clearTimeout(D)}},[le]);const ae=f.useMemo(()=>{const D=[];for(const B of se)for(const J of B.paragraphs)for(const me of J.chars)D.push(me.charData.id);return D},[se]),Be=f.useMemo(()=>{const D=new Map;if(!j||j.length===0)return D;const B=new Map(ae.map((J,me)=>[J,me]));for(const J of j){if(!J.anchor)continue;const me=B.get(J.anchor.start),V=B.get(J.anchor.end);if(!(me===void 0||V===void 0||V<me))for(let U=me;U<=V;U++)D.has(ae[U])||D.set(ae[U],J)}return D},[j,ae]),Oe=is(b,_),Z=Be.size>0,oe=f.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:m,onEntityNavigate:k,onVisibleHeadingChange:x,onFigureBlockClick:E});oe.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:m,onEntityNavigate:k,onVisibleHeadingChange:x,onFigureBlockClick:E};const ze=f.useMemo(()=>({click:D=>{var B,J;A.current=Date.now()+1200,(J=(B=oe.current).onCharClick)==null||J.call(B,D)},enter:D=>{var B,J;return(J=(B=oe.current).onCharHover)==null?void 0:J.call(B,D)},leave:()=>{var D,B;return(B=(D=oe.current).onCharHover)==null?void 0:B.call(D,null)},figBlock:D=>{var B,J;return(J=(B=oe.current).onFigureBlockClick)==null?void 0:J.call(B,D)},navigate:(D,B)=>{B.ctrlKey||B.metaKey||B.shiftKey||(B.preventDefault(),B.detail===0&&window.open(B.currentTarget.href,"_blank","noopener"))}}),[]),We=Ax(o,be.mergedOwner),ye=f.useRef(ee);ye.current=ee;const H=f.useRef(null),ce=f.useCallback(D=>{const B=H.current,J=B==null?void 0:B.map.get(D);if(J&&J.isConnected)return J;if(B&&B.for===Y.current&&B.n===ye.current&&!J)return null;const me=P.current;if(!me)return null;const V=new Map;return me.querySelectorAll("span[data-char-id]").forEach(U=>{V.set(U.getAttribute("data-char-id"),U)}),H.current={for:Y.current,n:ye.current,map:V},V.get(D)??null},[]),de=f.useRef(null);f.useEffect(()=>{var B;if((B=de.current)==null||B.classList.remove("is-hovered"),de.current=null,!s)return;const D=ce(s);D&&(D.classList.add("is-hovered"),de.current=D)},[s,ce]);const te=f.useRef(null),Ce=D=>{var J;const B=D instanceof Element?D.closest("span[data-char-id]"):null;return B&&((J=P.current)!=null&&J.contains(B))?B.getAttribute("data-char-id"):null},Ue=D=>{const B=Ce(D.target);B&&ze.click(B)},Ge=D=>{const B=Ce(D.target);B!==te.current&&(te.current=B,B?ze.enter(B):ze.leave())},nt=D=>{const B=typeof window<"u"?window.getSelection():null;if(!B||B.isCollapsed||B.rangeCount===0)return;const J=Cx(B.getRangeAt(0));J!==null&&(D.clipboardData.setData("text/plain",J),D.preventDefault())},O=()=>{te.current!==null&&(te.current=null,ze.leave())};f.useEffect(()=>{let D=null;const B=()=>{var Ye,et;D=null;const me=window.getSelection(),V=P.current;if(!me||me.isCollapsed||me.rangeCount===0||!V)return;const U=me.getRangeAt(0),Me=U.commonAncestorContainer,He=Me.nodeType===3?Me.parentElement:Me;if(!He||!V.contains(He))return;const _e=V.querySelectorAll("span[data-char-id]"),X=Ke=>{let dt=Ke;for(;dt.nodeType!==3&&dt.firstChild;)dt=dt.firstChild;return dt};let ke=0,he=_e.length;for(;ke<he;){const Ke=ke+he>>1;U.comparePoint(X(_e[Ke]),0)<0?ke=Ke+1:he=Ke}const Ie=ke;for(he=_e.length;ke<he;){const Ke=ke+he>>1;U.comparePoint(X(_e[Ke]),0)<=0?ke=Ke+1:he=Ke}let Se=ke-1;if(Se>=Ie&&U.endOffset===0&&U.endContainer===X(_e[Se])&&Se--,Se<Ie)return;const Fe=[];for(let Ke=Ie;Ke<=Se;Ke++)Fe.push(_e[Ke].getAttribute("data-char-id"));Fe.length>0&&(A.current=Date.now()+1200,(et=(Ye=oe.current).onSelectionChange)==null||et.call(Ye,Fe))},J=()=>{D&&clearTimeout(D),D=setTimeout(B,120)};return document.addEventListener("selectionchange",J),()=>{document.removeEventListener("selectionchange",J),D&&clearTimeout(D)}},[]);const ue=f.useRef(null);f.useEffect(()=>{if(o.size!==1||ue.current===o)return;const D=Array.from(o)[0],B=ce(D);if(B)ue.current=o,B.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const J=parseInt(D.split(":")[0],10);isNaN(J)||G(J)}},[o,ee,ce,G]);const Re=D=>{var me;const B=P.current;if(!B)return null;const J=(me=se.find(V=>V.page===D))==null?void 0:me.leadFirstId;return J?B.querySelector(`span[data-char-id="${J}"]`):B.querySelector(`[data-page-section="${D}"]`)},W=u==null?void 0:u.nonce,pe=f.useRef(null);f.useEffect(()=>{if(!u||pe.current===u.nonce)return;const D=Re(u.page);if(!D){!T&&se.some(B=>B.page>=u.page)&&G(u.page);return}pe.current=u.nonce,A.current=Date.now()+800,D.scrollIntoView({behavior:"auto",block:"start"})},[W,ee]);const re=f.useRef(null);f.useEffect(()=>{var V,U;if(!h||re.current===h.nonce)return;const D=P.current,B=D==null?void 0:D.querySelector(`span[data-char-id="${Bx(h.anchor)}"]`);if(!B){const Me=parseInt(h.anchor.split(":")[0],10);!T&&!isNaN(Me)&&G(Me);return}re.current=h.nonce;const J=B.closest(".guji-reflow-paragraph")??B;A.current=Date.now()+800,J.scrollIntoView({behavior:"auto",block:"start"});const me=parseInt(h.anchor.split(":")[0],10);isNaN(me)||(U=(V=oe.current).onVisiblePageChange)==null||U.call(V,me)},[h,se,ee,T,G]);const Ne=!!m||!!x,Le=!!m&&typeof v=="number",[Ve,Xe]=f.useState(null),ot=io(Ve??v??0),it=f.useRef(null);it.current=Le?ot:null;const R=f.useRef(()=>{});return f.useEffect(()=>{var he,Ie;if(!Ne)return;const D=new Map,B=new Map;(he=P.current)==null||he.querySelectorAll("[data-page-section],[data-page-start]").forEach(Se=>{const Fe=Se.getAttribute("data-page-section");Fe!==null?D.set(Fe,Se):B.set(Se.getAttribute("data-page-start"),Se)});const J=[],me=[];for(const Se of fe){const Fe=D.get(String(Se.page));Fe&&(J.push(Fe),me.push(Se.page))}if(J.length===0)return;const V=new Map(J.map((Se,Fe)=>[Se,Fe])),U=J.map(()=>[]);let Me=0;(Ie=P.current)==null||Ie.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Se=>{const Fe=V.get(Se.closest("[data-page-section]"));Fe!==void 0&&(U[Fe].push(Se),Me++)});let He,_e=0;const X=()=>{var qe,K;if(_e=0,Date.now()<A.current)return;const Se=Ae=>Ae.getBoundingClientRect().top;if(J.length>1&&Se(J[0])===Se(J[J.length-1]))return;const Fe=it.current===null?120:it.current*window.innerHeight;let Ye=0,et=J.length-1;for(;Ye<et;){const Ae=Ye+et+1>>1;Se(J[Ae])<=Fe?Ye=Ae:et=Ae-1}const Ke=Se(J[0])>Fe;let dt=me[Ye];for(let Ae=Ye+1;Ae<J.length;Ae++){const Qe=B.get(String(me[Ae]));if(!Qe||!J[Ye].contains(Qe)||Se(Qe)>Fe)break;dt=me[Ae]}if(Me>0&&oe.current.onVisibleHeadingChange){let Ae=null;if(!Ke){const at=U[Ye];for(let lt=at.length-1;lt>=0&&!Ae;lt--)Se(at[lt])<=Fe&&(Ae=at[lt]);for(let lt=Ye-1;lt>=0&&!Ae;lt--)U[lt].length>0&&(Ae=U[lt][U[lt].length-1])}const Qe=Ae?Px(Ae):null;Qe!==He&&(He=Qe,oe.current.onVisibleHeadingChange(Qe))}(K=(qe=oe.current).onVisiblePageChange)==null||K.call(qe,dt)},ke=()=>{_e||(_e=requestAnimationFrame(X))};return R.current=()=>{_e||(_e=requestAnimationFrame(X))},window.addEventListener("scroll",ke,{passive:!0}),ke(),()=>{window.removeEventListener("scroll",ke),_e&&cancelAnimationFrame(_e),R.current=()=>{}}},[Ne,se,ee]),f.useEffect(()=>{Le&&R.current()},[Le,ot]),t.jsxs("div",{ref:P,className:"guji-text-pane-content",onClick:Ue,onMouseOver:Ge,onMouseLeave:O,onCopy:nt,children:[Z&&t.jsx("style",{children:ns}),Le&&t.jsx(Ux,{y:ot,containerRef:P,onDrag:Xe,onCommit:D=>{Xe(null),C==null||C(D)}}),t.jsx("div",{className:"guji-text-reflow-view",children:fe.map((D,B)=>t.jsx(Fx,{pGroup:D,first:B===0,pageBreaks:w,markOpts:F,plainBooks:q,selected:We.get(D.page)??Rx,entityOfChar:Be,entityLoader:Oe,convert:g,buildHref:y??zx,handlers:ze,charCount:xe[B]??0,pageStarts:be.pageStarts,figures:N,figUrl:z},`page-sec-${D.page}`))})]})},Ha=1800,Ex=800,Ix="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",Rx=new Set,no=[],Lx={before:no,after:no};function Ax(e,n){const i=f.useRef(new Map);return f.useMemo(()=>{const o=new Map;e.forEach(a=>{const l=n.get(a)??parseInt(a.split(":")[0],10);let d=o.get(l);d||o.set(l,d=new Set),d.add(a)});const s=new Map;return o.forEach((a,l)=>{const d=i.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(p=>d.has(p));s.set(l,c?d:a)}),i.current=s,s},[e,n])}function Mx(e){return e==null?void 0:e.find(n=>n.kind==="heading"&&/^#{1,6}$/.test(n.mark))}function Px(e){return e.getAttribute("data-heading-anchor")}function Bx(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}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 Ox(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))}function Wx({heading:e,children:n}){if(!e)return t.jsx("p",{className:"guji-reflow-paragraph",children:n});const i=`h${Math.min(6,e.level+1)}`;return t.jsx(i,{className:`guji-reflow-paragraph guji-reflow-heading guji-reflow-h${e.level}`,"data-heading-anchor":e.anchor,"data-heading-level":e.level,"data-heading-toc":e.toc===!1?"0":void 0,children:n})}const Fx=f.memo(function({pGroup:n,first:i,pageBreaks:o,markOpts:s,plainBooks:a,selected:l,entityOfChar:d,entityLoader:c,convert:p,buildHref:m,handlers:g,charCount:u,pageStarts:h,figures:x,figUrl:j}){const b=f.useMemo(()=>{const v=new Map;if(!p)return v;for(const C of n.paragraphs){const $=Ox(C.chars.map(S=>S.charData.fig?S.charData.char:S.charData.norm??S.charData.char),p);C.chars.forEach((S,I)=>v.set(S.charData.id,S.charData.fig?S.charData.char:$[I]))}return v},[n,p]),_=v=>b.get(v.id)??v.char,{t:y}=ie(),k=v=>{const C=s?cd(v.mark,s):v.mark;return C?t.jsx("span",{className:"guji-text-punct","data-punct-id":v.id,children:C},v.id):null},w=v=>{var C;return(C=n.blocks)==null?void 0:C.map(($,S)=>$.before===v&&t.jsx(_x,{fig:$.fig,info:x==null?void 0:x.get($.fig),figUrl:j,onClick:()=>g.figBlock({page:n.page,fig:$.fig,...$.box?{box:$.box}:{}})},`fig-${$.fig}-${S}`))};return t.jsxs("section",{"data-page-section":n.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:Ix,"--gtv-pc":u,"--gtv-pp":n.paragraphs.length},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((v,C)=>t.jsxs(f.Fragment,{children:[w(C),t.jsxs(Wx,{heading:v.heading,children:[Tx(v.chars,d).map(($,S)=>{const I=$.chars.map(({charData:E,beforePuncts:P,afterPuncts:A,start:M},F)=>{var we;const q=!!$.entity&&F===0,be=!!$.entity&&F===$.chars.length-1,se=q?[]:P,Y=be?[]:A,xe=!!E.fig&&F>0&&$.chars[F-1].charData.fig===E.fig;let Q=1;if(E.fig&&!xe)for(;((we=$.chars[F+Q])==null?void 0:we.charData.fig)===E.fig;)Q++;const le=`guji-text-char${l.has(E.id)?" is-selected":""}${E.sub?" is-sub":""}${E.lane==="solo"?" is-solo":""}${M!=null&&M.raised?" is-raised":""}`;return t.jsxs(f.Fragment,{children:[M&&M.blankBefore>0&&t.jsx(Da,{n:M.blankBefore}),se.map(k),E.fig?t.jsx(Sx,{id:E.id,fig:E.fig,info:x==null?void 0:x.get(E.fig),figUrl:j,cells:Q,cont:xe,className:le,pageStart:h.get(E.id),children:_(E)}):t.jsx("span",{"data-char-id":E.id,"data-page-start":h.get(E.id),className:`guji-text-char${l.has(E.id)?" is-selected":""}${E.sub?" is-sub":""}${E.lane==="solo"?" is-solo":""}${E.lacuna?" is-lacuna":""}${E.lacuna&&E.guess_c?" has-guess":""}${E.guess?" is-guess":""}${E.zi?" is-zi":""}${M!=null&&M.raised?" is-raised":""}`,"data-raised":(M==null?void 0:M.raised)||void 0,"data-guji-guess":E.lacuna&&E.guess_c?E.guess_c:void 0,title:E.lacuna?E.guess_c?y("reader.lacunaGuess",{guess:p?p(E.guess_c):E.guess_c}):y("detail.lacuna"):E.zi?y("detail.composedChar",{label:E.zi}):E.guess?y("reader.charGuess"):void 0,children:_(E)}),Y.map(k)]},E.id)});if(!$.entity)return t.jsx(f.Fragment,{children:I},`r${S}`);const N=$.chars[0].beforePuncts.map(k),z=$.chars[$.chars.length-1].afterPuncts.map(k);return t.jsxs(f.Fragment,{children:[N,t.jsx(rs,{span:$.entity,label:$.chars.map(E=>_(E.charData)).join(""),hasBrackets:!0,plain:a&&$.entity.kind==="work",loader:c,buildHref:m,onNavigate:g.navigate,cardNewTab:!0,renderText:()=>I,hoverDelayMs:250}),z]},`${$.entity.key}@${S}`)}),C===n.paragraphs.length-1&&n.trailingBlank?t.jsx(Da,{n:n.trailingBlank}):null]})]},v.id)),w(n.paragraphs.length)]})});function io(e){const[n,i]=Xn,o=Number.isFinite(e)?e:.33;return Math.round(Math.min(i,Math.max(n,o))*1e3)/1e3}const Hx=.02,xn=16,Dx=4;function Ux({y:e,containerRef:n,onDrag:i,onCommit:o}){const{t:s}=ie(),[a,l]=f.useState(0),d=f.useRef(!1),c=f.useRef(null),p=f.useRef(e);p.current=e;const m=f.useCallback(()=>{var j;const u=((j=c.current)==null?void 0:j.parentElement)??n.current,h=(u==null?void 0:u.closest(".bim-rd-col"))??u,x=h==null?void 0:h.getBoundingClientRect();l(Math.max(0,((x==null?void 0:x.left)??0)-xn-Dx))},[n]);f.useLayoutEffect(()=>{var j;window.addEventListener("resize",m);const u=((j=c.current)==null?void 0:j.parentElement)??n.current,h=(u==null?void 0:u.closest(".bim-rd-col"))??u,x=typeof ResizeObserver<"u"?new ResizeObserver(()=>m()):null;for(const b of[h,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])b&&(x==null||x.observe(b));return x||m(),()=>{window.removeEventListener("resize",m),x==null||x.disconnect()}},[m,n]);const g=u=>io(u/Math.max(1,window.innerHeight));return t.jsx("div",{ref:c,role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":s("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Xn[0]*100),"aria-valuemax":Math.round(Xn[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${xn/2}px)`,width:xn,height:xn,zIndex:20,cursor:"ns-resize",touchAction:"none",display:"flex",alignItems:"center",justifyContent:"center",color:r("meta-fg")},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const h=g(u.clientY);p.current=h,i(h)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}o(g(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,o(p.current))},onKeyDown:u=>{const h=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;h&&(u.preventDefault(),o(io(e+h*(u.shiftKey?5:1)*Hx)))},children:t.jsx("svg",{width:xn,height:xn,viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2 8h11M9 4l4 4-4 4"})})})}const Cd=1,zd=6,yi={s:1,x:0,y:0},_i=(e,n,i)=>Math.min(i,Math.max(n,e));function as(e,n,i){const o=_i(e.s,Cd,zd);return{s:o,x:_i(e.x,n*(1-o),0),y:_i(e.y,i*(1-o),0)}}function Nr(e,n,i,o,s,a){const l=_i(e.s*o,Cd,zd),d=l/e.s;return as({s:l,x:n-(n-e.x)*d,y:i-(i-e.y)*d},s,a)}function Vx(e,n,i,o,s){return as({s:e.s,x:e.x+n,y:e.y+i},o,s)}function Gx(e,n,i){const o=n===1?e*16:n===2?e*400:e;return Math.exp(-o*(i?.01:.0015))}const Ua=4,Yx=f.forwardRef(function({children:n,onScaleChange:i,resetKey:o,style:s},a){const l=f.useRef(null),[d,c]=f.useState(yi),p=f.useRef(d),m=f.useRef(i);m.current=i;const g=y=>{var w;const k=p.current;p.current=y,c(y),y.s!==k.s&&((w=m.current)==null||w.call(m,y.s))},u=()=>{var k;const y=(k=l.current)==null?void 0:k.getBoundingClientRect();return{w:(y==null?void 0:y.width)??0,h:(y==null?void 0:y.height)??0,left:(y==null?void 0:y.left)??0,top:(y==null?void 0:y.top)??0}};f.useImperativeHandle(a,()=>({zoomBy(y){const{w:k,h:w}=u();g(Nr(p.current,k/2,w/2,y,k,w))},reset(){g(yi)}})),f.useEffect(()=>{g(yi)},[o]),f.useEffect(()=>{const y=l.current;if(!y||typeof ResizeObserver>"u")return;const k=new ResizeObserver(()=>{const{w,h:v}=u(),C=as(p.current,w,v);(C.x!==p.current.x||C.y!==p.current.y)&&g(C)});return k.observe(y),()=>k.disconnect()},[]),f.useEffect(()=>{const y=l.current;if(!y)return;const k=w=>{const v=Gx(w.deltaY,w.deltaMode,w.ctrlKey);if(p.current.s<=1&&v<1)return;w.preventDefault();const{w:C,h:$,left:S,top:I}=u();g(Nr(p.current,w.clientX-S,w.clientY-I,v,C,$))};return y.addEventListener("wheel",k,{passive:!1}),()=>y.removeEventListener("wheel",k)},[]);const h=f.useRef(new Map),x=f.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),j=y=>{if(y.pointerType==="mouse"&&y.button!==0)return;h.current.set(y.pointerId,{x:y.clientX,y:y.clientY});const k=x.current;if(k.swallowClick=!1,h.current.size===1&&(k.moved=0,k.dragging=!1),h.current.size===2){const[w,v]=[...h.current.values()];k.pinchDist=Math.hypot(w.x-v.x,w.y-v.y),k.moved=Ua+1}},b=y=>{var E;const k=h.current.get(y.pointerId);if(!k)return;const w={x:y.clientX,y:y.clientY};h.current.set(y.pointerId,w);const v=x.current,{w:C,h:$,left:S,top:I}=u();if(h.current.size>=2){const[P,A]=[...h.current.values()],M=Math.hypot(P.x-A.x,P.y-A.y);if(v.pinchDist>0&&M>0){const F=(P.x+A.x)/2-S,q=(P.y+A.y)/2-I;g(Nr(p.current,F,q,M/v.pinchDist,C,$))}v.pinchDist=M,v.swallowClick=!0;return}const N=w.x-k.x,z=w.y-k.y;if(v.moved+=Math.abs(N)+Math.abs(z),!(v.moved<=Ua)){if(!v.dragging){v.dragging=!0;try{(E=l.current)==null||E.setPointerCapture(y.pointerId)}catch{}}v.swallowClick=!0,p.current.s>1&&g(Vx(p.current,N,z,C,$))}},_=y=>{h.current.delete(y.pointerId);const k=x.current;k.pinchDist=0,h.current.size===0&&(k.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:j,onPointerMove:b,onPointerUp:_,onPointerCancel:_,onClickCapture:y=>{x.current.swallowClick&&(x.current.swallowClick=!1,y.stopPropagation(),y.preventDefault())},onDoubleClick:()=>g(yi),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 Nd(e,n,i,o){const[s,a]=f.useState(n??null),[l,d]=f.useState(!1),c=f.useRef(0);return f.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(g=>{p===c.current&&a(g??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 qx(e,n,i){const[o,s]=f.useState([]),a=f.useRef(0);return f.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?md(c):[])}).catch(()=>{l===a.current&&s([])})},[e,n,i]),o}const Kx=/^#{1,6}$/,Xx=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function Zx(e){let n=e.trim();const i=Xx.exec(n);return i&&(n=i[1]+i[2]),n.replace(/[《》〈〉]/g,"").trim()}const Va=e=>e.kind==null||e.kind==="point";function Td(e,n){var d;if(!e||!n||n.length===0)return[];const i=new Map;let o=!1;for(const c of n){c.kind==="heading"&&(o=!0);const p=i.get(c.anchor);p?p.push(c):i.set(c.anchor,[c])}if(!o)return[];const s=[];let a=null;const l=()=>{a&&(a.fixed||(a.h.label=Zx(a.text)),a.h.label&&s.push(a.h)),a=null};for(const c of e){const p=[...c.columns].sort((m,g)=>m.col-g.col);for(const m of p)for(const g of m.chars){const u=i.get(g.id)??[],h=u.find(x=>x.kind==="heading"&&x.pos==="before"&&Kx.test(x.mark));if(h&&l(),h&&h.toc!==!1){const x=(d=h.label)==null?void 0:d.trim();a={h:{level:h.mark.length,label:x??"",anchor:g.id},text:"",fixed:!!x}}if(a&&!a.fixed){for(const x of u)Va(x)&&x.pos==="before"&&(a.text+=x.mark);a.text+=g.char;for(const x of u)Va(x)&&x.pos!=="before"&&(a.text+=x.mark)}u.some(x=>x.kind==="break"&&x.pos!=="before")&&l()}}return l(),s}function ro(e){if(!Array.isArray(e))return[];const n=[];for(const i of e){if(!i||typeof i!="object")continue;const{level:o,label:s,anchor:a}=i;typeof o!="number"||!Number.isInteger(o)||o<1||o>6||typeof s!="string"||!s.trim()||typeof a!="string"||!a||n.push({level:o,label:s.trim(),anchor:a})}return n}function ls(e,n){return`${e}#${n}`}function Ed(e){const n=e.indexOf("#");return n<=0||n===e.length-1?null:{chapter:e.slice(0,n),anchor:e.slice(n+1)}}function Id(e){const n=[],i=[];for(const o of e){const s={...o,children:[]};for(;i.length>0&&i[i.length-1].level>=o.level;)i.pop();i.length===0?n.push(s):i[i.length-1].children.push(s),i.push(s)}return n}function oo(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const Jx=150,Ga={padding:24,color:r("desc-fg"),fontSize:14};function Ya({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 qa=/^https?:\/\//i,Qx=[];function eb(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&&qa.test(i)?i:void 0,license:n(e.license),license_url:o&&qa.test(o)?o:void 0,note:n(e.note)};return s.name||s.license||s.note?s:null}function tb(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 Ka(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)||Array.isArray(n==null?void 0:n.heading_levels)&&n.heading_levels.length>0?"冊":Ee.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function Rd(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 Ld(e,n,i){return n.map(o=>({key:ls(e,o.anchor),label:i(o.label),inChapter:!0,...o.children.length>0?{selectable:!0,children:Ld(e,o.children,i)}:{}}))}function nb(e,n,i,o,s,a=()=>[]){var m;const l=new Map(e.chapters.map(g=>[g.file,g])),d=g=>g==="loading"?"…":typeof g=="number"&&g>0?g:void 0,c=(g,u)=>{const h=l.get(g),x=h?a(h):[];return{key:g,label:u??(h?Rd(h,i,o,s):g),hint:d(n[g]),disabled:n[g]===0,...x.length>0?{selectable:!0,children:Ld(g,Id(x),o)}:{}}},p=(m=e.juan_groups)==null?void 0:m.filter(g=>{var u;return g.files.some(h=>l.has(h))||((u=g.children)==null?void 0:u.length)});if(p&&p.length>0){const g=(u,h)=>{var j;if(u.files.length===1&&!((j=u.children)!=null&&j.length))return c(u.files[0],o(u.label));const x=Yh(u,n);return{key:`group:${h}`,label:o(u.label),hint:x==="loading"?"…":typeof x=="number"&&x>0?`${x}`:xd(u),defaultExpanded:typeof x=="number"&&x>0,children:[...u.files.filter(b=>l.has(b)).map(b=>c(b)),...(u.children??[]).map((b,_)=>g(b,`${h}.${_}`))]}};return p.map((u,h)=>g(u,`${h}`))}return e.chapters.map(g=>c(g.file))}const cs=e=>{const n=Tc();return t.jsx(gm,{mode:n[0].scriptMode,children:t.jsx(ib,{...e,prefsState:n})})},ib=({prefsState:e,id:n,transport:i,versionKey:o,chapter:s,onLocationChange:a,onNavigate:l,anchor:d,title:c,subtitle:p,resolveImages:m,renderImageOverlay:g,imagePanel:u,allowVertical:h,onReportError:x,revisedAt:j,backHref:b,backLabel:_,resolveWarpData:y,warpData:k,resolveEntities:w,onEntityNavigate:v,className:C,style:$})=>{var Bs,Os,Ws;const{t:S,convert:I}=ie(),N=f.useMemo(()=>vc(i),[i]),[z,E]=e,P=mt(),A=f.useRef(a);A.current=a;const[M,F]=f.useState(null),[q,be]=f.useState("loading");f.useEffect(()=>{let L=!1;return F(null),be("loading"),N.getManifest(n).then(ne=>{L||(ne?(F(ne),be("ready")):be("missing"))}).catch(()=>{L||be("missing")}),()=>{L=!0}},[N,n]);const se=o!==void 0,Y=s!==void 0,[xe,Q]=f.useState(null),[le,we]=f.useState(null);f.useEffect(()=>{Q(null),we(null)},[n]);const je=Ee.pickTextVersion(M,se?o:xe),ee=((Bs=M==null?void 0:M.versions.find(L=>L.key==="default"))==null?void 0:Bs.key)??((Os=M==null?void 0:M.versions[0])==null?void 0:Os.key)??"default",T=(je==null?void 0:je.key)??null,G=Y?s:le,fe=f.useCallback((L,ne,Te,rt)=>{var Ze;(Ze=A.current)==null||Ze.call(A,{key:L,chapter:ne,isDefault:L===ee,...rt?{anchor:rt}:{}},Te)},[ee]);f.useEffect(()=>{!M||!se||o==null||M.versions.some(L=>L.key===o)||fe(ee,null,"auto")},[M,se,o,ee,fe]);const ae=f.useRef(new Map);f.useEffect(()=>{ae.current.clear()},[N,n]);const Be=f.useCallback(async L=>{const ne=`${n}
1436
+ ${L}`;if(ae.current.has(ne))return ae.current.get(ne)??null;const Te=await N.getIndex(n,L).catch(()=>null);return Te&&ae.current.set(ne,Te),Te},[N,n]),[Oe,Z]=f.useState(null),[oe,ze]=f.useState("loading"),We=T?`${n}
1437
+ ${T}`:null,ye=Oe&&Oe.owner===We?Oe.idx:null;f.useEffect(()=>{if(!T)return;let L=!1;const ne=`${n}
1438
+ ${T}`;return Z(null),ze("loading"),Be(T).then(Te=>{L||(Te&&Te.chapters.length>0?(Z({owner:ne,idx:Te}),ze("ready")):ze("failed"))}),()=>{L=!0}},[n,T,Be]),f.useEffect(()=>{if(!ye||!T||G!=null&&ye.chapters.some(Te=>Te.file===G))return;const ne=ye.chapters[0].file;Y||we(ne),fe(T,ne,"auto")},[ye,T,G,Y,fe]);const H=ye?G!=null&&ye.chapters.some(L=>L.file===G)?G:ye.chapters[0].file:G,ce=f.useMemo(()=>ye&&H?ye.chapters.find(L=>L.file===H)??null:null,[ye,H]),de=f.useRef(0),te=f.useCallback(async L=>{if(!M||L===T||!M.versions.some(Et=>Et.key===L))return;const ne=++de.current,Te=await Be(L);if(ne!==de.current)return;const rt=ce??(H?{file:H}:null),Ze=Ee.matchChapterAcrossVersions(rt,Te);se||Q(L),Y||we(Ze),fe(L,Ze,"version")},[M,T,Be,ce,H,se,Y,fe]),[Ce,Ue]=f.useState(null),[Ge,nt]=f.useState(null),O=f.useRef(0),ue=f.useCallback((L,ne)=>{Ue({chapter:L,anchor:ne,nonce:++O.current}),nt({chapter:L,anchor:ne})},[]),Re=f.useCallback(L=>{if(!T)return;const ne=Ed(L);if(ne){ue(ne.chapter,ne.anchor),Y||we(ne.chapter),fe(T,ne.chapter,"chapter",ne.anchor);return}Y||we(L),fe(T,L,"chapter")},[T,Y,fe,ue]),W=f.useRef(null);f.useEffect(()=>{!d||!H||d===W.current||(W.current=d,ue(H,d))},[d,H,ue]),f.useEffect(()=>{d||(W.current=null)},[d]);const[pe,re]=f.useState(null),Ne=T&&ce?`${n}
1421
1439
  ${T}
1422
- ${ce.file}`:null,[Le,Ve]=f.useState(null),Xe=Ne!==null&&Le!==Ne,ot=f.useRef(0);f.useEffect(()=>{if(!T||!ce)return;const L=++ot.current,te=`${n}
1440
+ ${ce.file}`:null,[Le,Ve]=f.useState(null),Xe=Ne!==null&&Le!==Ne,ot=f.useRef(0);f.useEffect(()=>{if(!T||!ce)return;const L=++ot.current,ne=`${n}
1423
1441
  ${T}
1424
- ${ce.file}`;if(ie(null),ro(ce)){Ve(te);return}N.getChapter(n,T,ce.file,{json:!!ce.has_json}).then(Te=>{L===ot.current&&ie(Te)}).catch(()=>{L===ot.current&&ie(null)}).finally(()=>{L===ot.current&&Ve(te)})},[N,n,T,ce]);const it=Ie.isCollatedKind(ye==null?void 0:ye.kind),[E,ge]=f.useState("");f.useEffect(()=>{ge("")},[n,T]);const ve=f.useMemo(()=>T&&it?async L=>{const te=await N.getChapter(n,T,L,{json:!0});return{juan:(te==null?void 0:te.json)??null,rawText:(te==null?void 0:te.md)??null}}:null,[N,n,T,it]),$e=(be==null?void 0:be.type)==="kaozhen",D=f.useMemo(()=>(be==null?void 0:be.chapters.map(L=>L.file))??[],[be]),{matchStates:B}=ix({resetKey:`${n}
1425
- ${T??""}`,load:ve,files:D,activeFile:H??null,activeJuan:(pe==null?void 0:pe.json)??null,activeRawText:(pe==null?void 0:pe.md)??null,query:E,isKaozhen:$e}),Z=f.useRef(new Map);f.useEffect(()=>{Z.current.clear()},[n]);const me=f.useMemo(()=>({versionKey:T,chapter:ce??null}),[T,ce]),V=Nh(g,H??null,me),{warpData:U,loading:Me}=Cd(y,k,H??null,me),He=Ux(w,H??null,me),_e=z.properNameMode??(He.length>0?"full":"off"),K=f.useMemo(()=>({...z,properNameMode:_e}),[z,_e]),ke=f.useMemo(()=>zh(He,_e,{showWorks:K.showWorks}),[He,_e,K.showWorks]),[he,Ee]=f.useState(new Set),[Se,Fe]=f.useState(null),[Ye]=f.useState(Th),[et,Ke]=f.useState(!0),ct=z.preserveMargins;f.useCallback(L=>I({preserveMargins:L}),[I]);const qe=f.useRef(null),[q,Ae]=f.useState(1),[Qe,st]=f.useState(null),at=L=>{var Te;const te=parseInt(((Te=L==null?void 0:L.page_id)==null?void 0:Te.split(":")[1])??"",10);return isNaN(te)?null:te},Tt=L=>{var Te,rt;const te=(L==null?void 0:L.pages)??[];return((Te=te.find(Ze=>Ze.columns.some(It=>It.chars.length>0)))==null?void 0:Te.page)??at(L)??((rt=te[0])==null?void 0:rt.page)??1},[tt,xt]=f.useState(()=>Tt(U)),En=`${n}
1442
+ ${ce.file}`;if(re(null),oo(ce)){Ve(ne);return}N.getChapter(n,T,ce.file,{json:!!ce.has_json}).then(Te=>{L===ot.current&&re(Te)}).catch(()=>{L===ot.current&&re(null)}).finally(()=>{L===ot.current&&Ve(ne)})},[N,n,T,ce]);const it=Ee.isCollatedKind(je==null?void 0:je.kind),[R,ge]=f.useState("");f.useEffect(()=>{ge("")},[n,T]);const ve=f.useMemo(()=>T&&it?async L=>{const ne=await N.getChapter(n,T,L,{json:!0});return{juan:(ne==null?void 0:ne.json)??null,rawText:(ne==null?void 0:ne.md)??null}}:null,[N,n,T,it]),$e=(ye==null?void 0:ye.type)==="kaozhen",D=f.useMemo(()=>(ye==null?void 0:ye.chapters.map(L=>L.file))??[],[ye]),{matchStates:B}=sx({resetKey:`${n}
1443
+ ${T??""}`,load:ve,files:D,activeFile:H??null,activeJuan:(pe==null?void 0:pe.json)??null,activeRawText:(pe==null?void 0:pe.md)??null,query:R,isKaozhen:$e}),J=f.useRef(new Map);f.useEffect(()=>{J.current.clear()},[n]);const me=f.useMemo(()=>({versionKey:T,chapter:ce??null}),[T,ce]),V=Ih(m,H??null,me),{warpData:U,loading:Me}=Nd(y,k,H??null,me),He=qx(w,H??null,me),_e=z.properNameMode??(He.length>0?"full":"off"),X=f.useMemo(()=>({...z,properNameMode:_e}),[z,_e]),ke=f.useMemo(()=>Eh(He,_e,{showWorks:X.showWorks}),[He,_e,X.showWorks]),[he,Ie]=f.useState(new Set),[Se,Fe]=f.useState(null),[Ye]=f.useState(Rh),[et,Ke]=f.useState(!0),dt=z.preserveMargins;f.useCallback(L=>E({preserveMargins:L}),[E]);const qe=f.useRef(null),[K,Ae]=f.useState(1),[Qe,at]=f.useState(null),lt=L=>{var Te;const ne=parseInt(((Te=L==null?void 0:L.page_id)==null?void 0:Te.split(":")[1])??"",10);return isNaN(ne)?null:ne},Tt=L=>{var Te,rt;const ne=(L==null?void 0:L.pages)??[];return((Te=ne.find(Ze=>Ze.columns.some(Et=>Et.chars.length>0)))==null?void 0:Te.page)??lt(L)??((rt=ne[0])==null?void 0:rt.page)??1},[tt,xt]=f.useState(()=>Tt(U)),In=`${n}
1426
1444
  ${T}
1427
- ${H??""}`,[Rn,Ss]=f.useState({key:En,data:U,started:!!U});if(Rn.key!==En)Ss({key:En,data:U,started:!1});else if(U!==Rn.data&&(Ss({key:En,data:U,started:!!U}),U)){const L=U.pages??[];(!Rn.started||!L.some(te=>te.page===tt))&&xt(Tt(U))}f.useEffect(()=>{Ee(new Set),Ye.set(null)},[H,T,Ye]);const rr=Rn.key===En&&Rn.started,_s=!!ce&&io(ce.headings).length===0,$s=f.useMemo(()=>_s&&rr&&U?zd(U.pages,U.punctuations):[],[_s,rr,U]),or=f.useCallback(L=>{const te=io(L.headings);return te.length>0?te:L.file===H?$s:[]},[H,$s]),su=f.useCallback(L=>{if(Ee(new Set(L)),L.length>0){const te=L[0],Te=parseInt(te.split(":")[0],10);isNaN(Te)||xt(Te)}},[]),Ot=f.useMemo(()=>{const L=new Map;for(const te of(U==null?void 0:U.pages)??[])L.set(te.page,te);return L},[U]),Ln=at(U),oi=f.useCallback(L=>{var rt;const te=V.images;if(!te||te.length===0)return;const Te=(rt=Ot.get(L))==null?void 0:rt.seq;return(Te?te.find(Ze=>Ze.seq===Te):void 0)??te.find(Ze=>Ze.pageNo===L)??te[L-1]},[V.images,Ot]),Cs=q>1.5,si=f.useCallback((L,te=!1)=>{const Te=oi(L);return Te?L===Ln||te?Te.hiresUrl??Te.url:Te.url:L===Ln?(U==null?void 0:U.imageUrl)??"":""},[oi,U,Ln]),au=f.useMemo(()=>si(tt,Cs),[si,tt,Cs]),Wt=f.useMemo(()=>[...Ot.keys()].sort((L,te)=>L-te),[Ot]),nn=f.useRef(tt);nn.current=tt;const sr=f.useRef(0),ar=f.useRef({page:null,timer:null}),lu=f.useCallback(L=>{const te=ar.current;L!==te.page&&(te.timer&&(clearTimeout(te.timer),te.timer=null),te.page=null,!(L===nn.current||Date.now()<sr.current)&&(te.page=L,te.timer=setTimeout(()=>{te.timer=null,te.page=null,!(Date.now()<sr.current||nn.current===L)&&(nn.current=L,xt(L))},qx)))},[]);f.useEffect(()=>()=>{ar.current.timer&&clearTimeout(ar.current.timer)},[]);const ai=f.useCallback(L=>{var te;nn.current===L||!Ot.has(L)||(sr.current=Date.now()+1e3,nn.current=L,xt(L),(te=Ot.get(L))!=null&&te.columns.some(Te=>Te.chars.length>0)&&st(Te=>({page:L,nonce:((Te==null?void 0:Te.nonce)??0)+1})))},[Ot]),An=f.useCallback(L=>{const te=nn.current,Te=Wt.indexOf(te),rt=Wt[Te<0?0:Te+L];rt===void 0||rt===te||ai(rt)},[Wt,ai]),zs=f.useCallback(L=>{if(!L.trim().match(/^\d+$/)||Wt.length===0)return null;const Te=parseInt(L.trim(),10),rt=Number.isFinite(Te)?Te:Number.MAX_SAFE_INTEGER;return Wt.reduce((Ze,It)=>Math.abs(It-rt)<Math.abs(Ze-rt)?It:Ze,Wt[0])},[Wt]),[lr,cr]=f.useState(null),li=f.useRef(null),cu=f.useCallback(L=>{li.current=L,cr(L)},[]),Ns=f.useCallback(()=>{const L=li.current;if(li.current=null,cr(null),L===null)return;const te=zs(L);te!==null&&ai(te)},[zs,ai]),dr=Wt.indexOf(tt),du=f.useCallback(L=>{if(L.altKey||L.ctrlKey||L.metaKey)return;const te=L.target.tagName;te==="INPUT"||te==="TEXTAREA"||te==="SELECT"||(L.key==="ArrowLeft"||L.key==="PageUp"?(L.preventDefault(),An(-1)):(L.key==="ArrowRight"||L.key==="PageDown")&&(L.preventDefault(),An(1)))},[An]),Ts=f.useRef(null);f.useEffect(()=>{if(!U)return;const L=Ts.current;if(!(!L||L.offsetWidth===0))for(const te of[1,-1]){const Te=si(tt+te);Te&&eo(Te)}},[U,tt,si]);const Is=f.useMemo(()=>{var Ds;if(!U)return null;if(tt===Ln)return U;const L=Ot.get(tt);if(L&&L.width>0&&L.height>0)return{page_id:`p:${tt}`,title:`第${tt}葉`,image_size:[L.width,L.height],total_warped_w:L.width,columns:[{col:1,warped_w:L.width,warped_h:L.height,offset_x:0,strips:[],chars:L.columns.flatMap(Je=>Je.chars).map(Je=>({id:Je.id,char:Je.char,slot:Je.slot,pos:Je.pos,sub:Je.sub,bbox_col:Je.bbox??[0,0,0,0]}))}],...L.columns.some(Je=>Je.kind==="figure"&&Je.figBox)?{figBlocks:L.columns.filter(Je=>Je.kind==="figure"&&Je.figBox).map(Je=>({id:Je.fig,box:Je.figBox}))}:{}};const te=(Ds=U.pages)==null?void 0:Ds.find(Je=>Je.page===tt),[Te,rt]=U.image_size||[2386,3082];if(!(Te>0&&rt>0))return null;const Ze=oi(tt),It=(Ze==null?void 0:Ze.width)??Te,fr=(Ze==null?void 0:Ze.height)??rt,Ws=It/Te,Fs=fr/rt,Hs=new Map;for(const Je of U.columns){const St=(Je.strips||[]).flatMap(mi=>mi.srcQuad.map(gi=>gi[0]));if(St.length===0)continue;const Ft=Je.top_y??0,hr=Je.bottom_y??Ft+Je.warped_h;Hs.set(Je.col,{x0:Math.min(...St),x1:Math.max(...St),top:Ft,slotH:(hr-Ft)/21})}return{page_id:`p:${tt}`,title:`第${tt}葉`,image_size:[It,fr],total_warped_w:It,columns:te?te.columns.map(Je=>{const St=Hs.get(Je.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Je.col,warped_w:It,warped_h:fr,offset_x:0,strips:[],chars:Je.chars.map(Ft=>{const hr=Ft.slot??Ft.pos??0,mi=(St.top+(hr-1)*St.slotH)*Fs,gi=(St.x0+St.x1)/2,[vu,ku]=Ft.sub==="a"?[gi,St.x1]:Ft.sub==="b"?[St.x0,gi]:[St.x0,St.x1];return{...Ft,bbox_col:[vu*Ws,mi,ku*Ws,mi+St.slotH*Fs]}})}}):[]}},[U,tt,Ln,Ot,oi]),{entryTitle:ci,authors:Es}=nb(n,i,c===void 0),[Rs,pr]=f.useState("text");f.useEffect(()=>{pr("text")},[H,T]);const pu=f.useMemo(()=>be?Jx(be,B,Ka(ye,be),R,it,or):[],[be,B,ye,R,it,or]);if(ne==="loading")return t.jsx(Ya,{className:C,style:$,title:c??ci,label:S("reader.loading")});if(ne==="missing"||!M||!ye)return t.jsx("div",{className:C,style:{...$,...Ga},children:S("reader.noText")});if(oe==="failed")return t.jsx("div",{className:C,style:{...$,...Ga},children:S("reader.tocFailed")});if(!be)return t.jsx(Ya,{className:C,style:$,title:c??ci,label:S("reader.tocLoading")});const gn=Ka(ye,be),uu=pu,Ls=Ge&&H&&Ge.chapter===H?as(H,Ge.anchor):null,mu=Ls&&ce&&or(ce).some(L=>L.anchor===Ge.anchor)?Ls:H??null,ur=M.versions.map(L=>({key:L.key,label:Ie.textVersionLabel(L),optionLabel:R(Ie.textVersionLabel(L)),sourceName:Xa(L)?S("reader.originalSource"):L.source_name?R(L.source_name):void 0,license:L.license??void 0,sourceUrl:L.source_url??void 0,primary:L.key===Q})),wt=Xx((Os=be.source)==null?void 0:Os.upstream),di=(typeof c=="string"?R(c):c)??(be.title?R(be.title):ci?R(ci):void 0),As=ye.edition_label?R(ye.edition_label):void 0,mr=di?t.jsx("a",{href:P(n),title:S("reader.viewEntry"),onClick:l?L=>{L.metaKey||L.ctrlKey||(L.preventDefault(),l(n))}:void 0,children:di}):void 0,gu=mr&&As?t.jsxs(t.Fragment,{children:[mr,t.jsxs("span",{className:"bim-rd-ed",children:["·",As]})]}):mr,fu=Es.length>0?R(Es.slice(0,2).map(L=>`${L.dynasty?`〔${L.dynasty}〕`:""}${L.name}${` ${L.role||S("reader.defaultRole")}`}`).join("、")):void 0,gr=ce?Id(ce,gn,R,it):void 0,rn=it&&!!(pe!=null&&pe.json),on=(pe==null?void 0:pe.json)??null,fn=(pe==null?void 0:pe.md)??null,Ms=rn&&!$e&&bd(on.sections),hu=Ms&&!(fn&&K.readingMode==="paragraph"&&Ti(fn)),xu=rn&&Ms?t.jsx(rx,{juan:on,view:Rs,onView:pr,textHasEntries:hu}):void 0,bu=!0,pi=fn?fn.replace(/^##\s+[^\n]+\n+/,""):null,ui=Xa(ye),Kt=ui?S("reader.originalSource"):ye.source_name?R(ye.source_name):void 0,yu=(typeof p=="string"?R(p):p)??(ui?void 0:Kt??R(Ie.textVersionLabel(ye))),ju=(U==null?void 0:U.hasNorm)===!0;return t.jsxs(Rc,{className:C,style:$,title:gu,subtitle:yu,byline:fu,current:gr,pagerUnit:gn,rail:xu,revisedAt:j,backHref:b,backLabel:_,onReportError:x?L=>x({...L,bookTitle:typeof di=="string"?di:void 0,entryId:n}):void 0,workLinkToggle:rn&&!$e&&!!l&&!!(on!=null&&on.sections.some(L=>L.work_id)),toc:uu,tocCaption:S("reader.tocCaption",{n:be.chapters.length,unit:R(gn)}),tocHeader:it&&be.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:$e?S("reader.searchChaptersPlaceholder"):S("reader.searchUnitPlaceholder",{unit:R(gn)}),"aria-label":$e?S("reader.searchChapters"):S("reader.searchUnit",{unit:R(gn)}),value:E,onChange:L=>ge(L.target.value)}):void 0,activeKey:H??null,tocActiveKey:mu,onSelect:Re,images:ro(ce)&&Me&&!U?null:V.images,renderImageOverlay:m,imagePanel:U?"open":u,isWarpMode:!!U,customImagePanel:U&&Is?t.jsxs("div",{ref:Ts,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:du,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:[he.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ee(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",he.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:q<=1,onClick:()=>{var L;return(L=qe.current)==null?void 0:L.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(q*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:q>=6,onClick:()=>{var L;return(L=qe.current)==null?void 0:L.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:q===1,onClick:()=>{var L;return(L=qe.current)==null?void 0:L.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(Dx,{ref:qe,resetKey:tt,onScaleChange:Ae,style:{flex:1,minHeight:0},children:t.jsx(Aa,{store:Ye,children:L=>t.jsx(es,{imageUrl:au,pageData:Is,selectedCharIds:he,hoveredCharId:L,preserveMargins:ct,renderScale:q,selectedFigBlock:Se,onFigBlockClick:te=>Fe(te),onCharClick:te=>{Fe(null),Ee(rt=>{const Ze=new Set(rt);return Ze.has(te)?Ze.delete(te):(Ze.clear(),Ze.add(te)),Ze});const Te=document.querySelector(`[data-char-id="${te}"]`);Te&&Te.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Ye.set})})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":S("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:dr<=0,onClick:()=>An(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":tt,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":S("reader.facsimilePageInput"),size:Math.max(2,String(lr??tt).length),value:lr??String(tt),onFocus:L=>L.currentTarget.select(),onChange:L=>cu(L.target.value),onKeyDown:L=>{L.key==="Enter"?(L.preventDefault(),Ns()):L.key==="Escape"&&(li.current=null,cr(null)),L.stopPropagation()},onBlur:Ns,style:{width:`${Math.max(2,String(lr??tt).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:dr<0||dr>=Wt.length-1,onClick:()=>An(1),children:"›"})]})]}):void 0,settingsAnnotate:U?t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${et?"bim-rd-on":""}`,"aria-pressed":et,title:"切换外挂现代断句标点",onClick:()=>Ke(L=>!L),children:et?"标点":"无标点"}):void 0,prefs:K,onPrefsChange:I,versions:ur.length>1?ur:void 0,currentVersionKey:ur.length>1?ye.key:void 0,onVersionChange:ee,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Ti(fn),allowVertical:h,origScriptAvailable:ju,contentLoading:Xe,children:[(Xe||Me&&!U&&!rn&&pi==null)&&t.jsx(un,{}),!Xe&&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:ce!=null&&ce.title?R(ce.title):gr}),(Kt||ye.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Kt,ye.license&&t.jsxs(t.Fragment,{children:[Kt&&t.jsx("span",{className:"bim-rd-dot"}),ye.license]})]})]}),t.jsx(Aa,{store:Ye,children:L=>t.jsx(os,{pageData:U,pages:U.pages,punctuations:U.punctuations||Kx,selectedCharIds:he,hoveredCharId:L,onSelectionChange:su,figures:U.figures,figUrl:U.figUrl,onFigureBlockClick:({page:te,fig:Te})=>{Ee(new Set),Fe(Te),xt(te)},onCharClick:te=>{Fe(null),Ee(rt=>{const Ze=new Set(rt);return Ze.has(te)?Ze.delete(te):(Ze.clear(),Ze.add(te)),Ze});const Te=parseInt(te.split(":")[0],10);isNaN(Te)||xt(Te)},onCharHover:Ye.set,mode:"horizontal",showPunctuation:et,entities:ke,entityTransport:i,onEntityNavigate:v,onVisiblePageChange:lu,convert:R,scrollToPage:Qe,scrollToAnchor:Ce&&Ce.chapter===H&&rr?Ce:null,onVisibleHeadingChange:te=>nt(te&&H?{chapter:H,anchor:te}:null),pageBreaks:K.pageBreaks,pageIndicatorY:K.pageIndicatorY,onPageIndicatorYChange:te=>I({pageIndicatorY:te}),quoteStyle:K.quoteStyle,bookTitleStyle:K.bookTitleStyle,showWorks:K.showWorks})})]}),!Xe&&!U&&rn&&on&&t.jsx(nx,{juan:on,rawText:fn,positionLabel:eb(ce,be,gn,R),groupLabel:tb(be,H??null),index:Zx(n,be),searchQuery:E,onNavigate:l,transport:i,workLabelCache:Z,prefs:K,view:Rs,onViewChange:pr},`${T}/${H}`),!Xe&&!U&&!rn&&pi!=null&&ce&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:ce.title?R(ce.title):gr}),(Kt||ye.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[ui&&Kt&&t.jsx(t.Fragment,{children:Kt}),!ui&&ye.source_name&&t.jsxs(t.Fragment,{children:[S("reader.textSource")," ",ye.source_url?t.jsx("a",{className:"bim-rd-link",href:ye.source_url,target:"_blank",rel:"noreferrer",children:R(ye.source_name)}):R(ye.source_name)]}),Kt&&ye.license&&t.jsx("span",{className:"bim-rd-dot"}),ye.license]}),wt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[S("reader.upstream")," ",wt.url?t.jsx("a",{className:"bim-rd-link",href:wt.url,target:"_blank",rel:"noreferrer",children:R(wt.name??wt.url)}):R(wt.name??""),wt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),wt.license_url?t.jsx("a",{className:"bim-rd-link",href:wt.license_url,target:"_blank",rel:"noreferrer",children:wt.license}):wt.license]}),wt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(kc,{text:wt.note,convert:R})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Go,{text:pi,mode:K.readingMode,tables:bu,gujiMarkdown:!0,bookMarking:Vo(K),quoteStyle:K.quoteStyle})})]}),!Xe&&!Me&&!U&&!rn&&pi==null&&ce&&t.jsx("div",{className:"bim-rd-state",children:S("reader.chapterFailed")}),!Xe&&be.references&&be.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:S("reader.references")}),t.jsx("ol",{children:be.references.map((L,te)=>t.jsxs("li",{children:[L.url?t.jsx("a",{className:"bim-rd-link",href:L.url,target:"_blank",rel:"noopener noreferrer",children:R(L.title)}):t.jsx("span",{children:R(L.title)}),L.author&&t.jsxs("span",{children:[",",R(L.author)]}),L.note&&t.jsxs("span",{children:["。",R(L.note)]})]},te))})]})]})};function Xa(e){return e.is_original===!0||e.source==="original"}function eb(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 tb(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 nb(e,n,i){const[o,s]=f.useState({entryTitle:void 0,authors:[]});return f.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 Rd={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")}},ib=Rd.other,Ld={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")}},rb=Ld.pending;function ob(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 sb(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 cs=({items:e,loading:n})=>{const i=mt(),{t:o,convert:s}=re();return n?t.jsx(un,{}):e.length===0?t.jsx("div",{style:ab,children:o("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=Rd[a.type]||ib,d=Ld[a.status]||rb,c=typeof window<"u"&&sb(a.pageUrl,window.location.href);return t.jsxs("div",{style:lb,children:[t.jsxs("div",{style:cb,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Za,background:l.color},children:o(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Za,background:d.color},children:o(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:db,children:ob(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:pb,children:[a.resourceId&&t.jsx("a",{href:i(a.resourceId),style:Nr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Nr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Nr,children:a.pageUrl}))]}),t.jsx("div",{style:ub,children:s(a.content)}),a.reply&&t.jsxs("div",{style:mb,children:[t.jsx("div",{style:gb,children:o("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},ab={textAlign:"center",padding:"40px 0",color:r("desc-fg"),fontSize:"14px"},lb={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"16px"},cb={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Za={fontSize:"12px",color:r("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},db={fontSize:"12px",color:r("desc-fg")},pb={fontSize:"12px",marginBottom:"6px"},Nr={color:r("primary"),textDecoration:"none",borderBottom:`1px dashed ${r("primary")}`},ub={fontSize:"14px",lineHeight:"1.6",color:r("fg"),whiteSpace:"pre-wrap"},mb={marginTop:"12px",padding:"10px 12px",background:r("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r("fg")},gb={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r("primary")},oo=({transport:e,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:a})=>{const l=Pe(),[d,c]=f.useState(null),[p,g]=f.useState([]),[m,u]=f.useState("recommend"),[h,x]=f.useState([]),[j,b]=f.useState(!1),_=o??m,y=M=>{u(M),s==null||s(M)},[k,w]=f.useState(!0),[v,C]=f.useState(null),[$,S]=f.useState(null),[R,N]=f.useState(null);f.useEffect(()=>{let M=!1;if(e.getCounts)return e.getCounts().then(F=>{M||c({works:F.works,books:F.books,collections:F.collections})}).catch(()=>{}),()=>{M=!0}},[e]),f.useEffect(()=>{let M=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const ne=await e.getRecommended();if(ne!=null&&ne.groups)return ne.groups.flatMap(je=>je.items.map(ae=>({...ae,group:je.name})))}catch{}return[]})().then(async ne=>{if(M)return;const je=ne.filter(Y=>Y.id);if(je.length===0){w(!1);return}const ae=await Promise.all(je.map(async Y=>{if(Y.type)return{id:Y.id,title:Y.title,type:Y.type,author:Y.author,dynasty:Y.dynasty,role:Y.role,edition:Y.edition,has_text:Y.has_text,has_image:Y.has_image,has_collated:Y.has_collated,subtype:Y.subtype,primary_name:Y.primary_name,group:Y.group,fallbackDescription:Y.description};try{let xe=null;if(e.getEntry)xe=await e.getEntry(Y.id);else{const J=await e.getItem(Y.id);J&&(xe={id:Y.id,title:J.title||Y.id,type:J.type||"work"})}if(xe)return{...xe,group:Y.group,fallbackDescription:Y.description}}catch{}return{id:Y.id,title:Y.title,type:Ie.extractType(Y.id),group:Y.group,fallbackDescription:Y.description}}));M||(g(ae.filter(Y=>Y!==null)),w(!1))}),()=>{M=!0}},[e,i]);const z=f.useRef(!1),I=f.useRef(!1),P=f.useRef(!1);f.useEffect(()=>{if(_!=="catalog"||z.current)return;const M=e.getCatalogProgress??e.getResourceProgress;if(!M)return;z.current=!0;let F=!1;return M.call(e).then(ne=>{F||C(ne)}).catch(()=>{z.current=!1}),()=>{F=!0}},[e,_]),f.useEffect(()=>{if(_!=="collection"||I.current||!e.getCollectionProgress)return;I.current=!0;let M=!1;return e.getCollectionProgress().then(F=>{M||S(F)}).catch(()=>{I.current=!1}),()=>{M=!0}},[e,_]),f.useEffect(()=>{if(_!=="site"||P.current||!e.getSiteProgress)return;P.current=!0;let M=!1;return e.getSiteProgress().then(F=>{M||N(F)}).catch(()=>{P.current=!1}),()=>{M=!0}},[e,_]),f.useEffect(()=>{if(!a||_!=="feedback")return;let M=!1;return b(!0),fetch(a).then(F=>F.json()).then(F=>{!M&&F.success&&x(F.items||[])}).catch(()=>{}).finally(()=>{M||b(!1)}),()=>{M=!0}},[a,_]);const A=M=>t.jsx(Tn,{type:M,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(Wn,{label:l.home.recommendTab,active:_==="recommend",onClick:()=>y("recommend")}),t.jsx(Wn,{label:l.home.catalogTab,active:_==="catalog",onClick:()=>y("catalog")}),t.jsx(Wn,{label:l.home.collectionTab,active:_==="collection",onClick:()=>y("collection")}),t.jsx(Wn,{label:l.home.siteTab,active:_==="site",onClick:()=>y("site")}),a&&t.jsx(Wn,{label:l.home.feedbackTab,active:_==="feedback",onClick:()=>y("feedback")})]}),_==="recommend"&&t.jsx(fb,{recommended:p,loading:k,onNavigate:n,getIcon:A,t:l}),_==="catalog"&&t.jsx(Ja,{progress:v,t:l,onNavigate:n}),_==="collection"&&t.jsx(Ja,{progress:$,t:l,onNavigate:n}),_==="site"&&t.jsx(xb,{progress:R,t:l,totalWorks:(d==null?void 0:d.works)??0}),_==="feedback"&&a&&t.jsx(cs,{items:h,loading:j})]})})},Wn=({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}),fb=({recommended:e,loading:n,onNavigate:i,getIcon:o,t:s})=>{const a=mt();if(n)return t.jsx(un,{});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 g=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return t.jsxs("a",{href:a(p.id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),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})]}),g&&t.jsx("div",{style:{fontSize:"12px",color:r("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:g})]})]},p.id)})})]},d))})},Ja=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(un,{});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(hb,{item:p,t:n,statusColor:l[d],onNavigate:i},p.id))})]},d)})})},hb=({item:e,t:n,statusColor:i,onNavigate:o})=>{const s=mt(),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?$t(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})]})},xb=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(un,{});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(Qa,{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(Qa,{item:c,t:n,totalWorks:i},c.id))})]})]})},Qa=({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})]})},el="(max-width: 768px)";function bb(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(el).matches);return f.useEffect(()=>{const i=window.matchMedia(el),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),e}const yb=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var I;const a=Pe(),{convert:l}=De(),d=bb(),[c,p]=f.useState(null),[g,m]=f.useState(null),[u,h]=f.useState(!1),[x,j]=f.useState("detail"),[b,_]=f.useState([]),[y,k]=f.useState(!1),w=f.useCallback(async P=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){_([]);return}k(!0);try{if(e.getCollectionCatalogs){const A=await e.getCollectionCatalogs(P);_(A||[])}else if(e.getCollectionCatalog){const A=await e.getCollectionCatalog(P);_(A?[{resource_id:"",data:A}]:[])}}catch{_([])}finally{k(!1)}},[e]),v=f.useCallback(async P=>{if(i){i(P);return}p(P),m(null),_([]),j("detail"),h(!0);try{const A=await e.getItem(P.id);A&&(m(A),A.type==="collection"&&w(P.id))}catch(A){console.error("加载详情失败:",A)}finally{h(!1)}},[e,i,w]),C=f.useCallback(async P=>{m(null),_([]),j("detail"),h(!0);try{const A=await e.getItem(P);A&&(m(A),p({id:P,title:A.title||P,type:A.type||"book"}),A.type==="collection"&&w(P))}catch(A){console.error("导航失败:",A)}finally{h(!1)}},[e,w]),$=typeof(g==null?void 0:g.text_count)=="number"&&g.text_count>0,S=(g==null?void 0:g.type)==="collection"&&(b.length>0||y)||(g==null?void 0:g.type)==="work"&&$,R=d&&(u||g),N=f.useCallback(()=>{p(null),m(null),_([]),j("detail")},[]),z=t.jsx(t.Fragment,{children:u?t.jsx(un,{}):g?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:()=>j("detail"),style:yi(x==="detail"),children:a.detailTab.basicInfo}),g.type==="collection"&&y&&b.length===0&&t.jsxs("button",{onClick:()=>{},style:yi(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),g.type==="collection"&&b.map(P=>t.jsx("button",{onClick:()=>j(`catalog:${P.resource_id}`),style:yi(x===`catalog:${P.resource_id}`),children:P.short_name?`${l(P.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},P.resource_id)),g.type==="work"&&$&&t.jsx("button",{onClick:()=>j("collated"),style:yi(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(Eo,{data:g,transport:e,onNavigate:C}):x.startsWith("catalog:")?t.jsx(Ro,{data:(I=b.find(P=>`catalog:${P.resource_id}`===x))==null?void 0:I.data,onNavigate:C}):x==="collated"?t.jsx(ls,{id:g.id,transport:e,onNavigate:C}):null})]}):t.jsx(oo,{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:R?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:N,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:z})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Hr,{transport:e,onEntryClick:v,hideModeIndicator:n}),!g&&t.jsx(oo,{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(Hr,{transport:e,onEntryClick:v,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:r("bg"),display:"flex",flexDirection:"column"},children:z})]})};function yi(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 jb=({pageData:e,rawImageUrl:n="",punctuations:i=[],title:o,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=f.useState(new Set),[g,m]=f.useState(null),[u,h]=f.useState("horizontal"),[x,j]=f.useState(!0),b=f.useRef(null),_=f.useCallback(v=>{p(new Set(v))},[]),y=f.useCallback(v=>{if(p(C=>{const $=new Set(C);return $.has(v)?$.delete(v):($.clear(),$.add(v)),$}),b.current){const C=b.current.querySelector(`[data-char-id="${v}"]`);C&&C.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),k=()=>{var v;p(new Set),window.getSelection&&((v=window.getSelection())==null||v.removeAllRanges())},w=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:k,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>j(v=>!v),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>h(v=>v==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:u==="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(es,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:g,onCharClick:y,onCharHover:m})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:b,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:u==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(os,{pageData:e,punctuations:w,selectedCharIds:c,hoveredCharId:g,onSelectionChange:_,onCharClick:y,onCharHover:m,mode:u,showPunctuation:x})]})]})]})},vb=e=>typeof e=="string"&&Array.from(e).length===1,kb=new Set(["point","break","heading"]),wb=/^#{1,6}$/;function Sb(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;if(typeof s.anchor!="string"||typeof s.mark!="string"||s.pre_char!=null&&!vb(s.pre_char)||s.kind!=null&&!kb.has(s.kind)||s.pos!=null&&s.pos!=="after"&&s.pos!=="before")continue;const a={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};if(!(s.kind==="break"&&s.pos==="before")){if(s.kind==="heading"){if(s.pos!=="before"||!wb.test(s.mark))continue;typeof s.label=="string"&&s.label.trim()&&(a.label=s.label.trim()),s.toc===!1&&(a.toc=!1)}i.push(a)}}return i}function _b(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 Ad=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function dt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}const ds=/^[a-z0-9][a-z0-9-]*$/,$b=new Set(["main","solo","jz_r","jz_l"]),Cb=new Set(["body","banxin","blank"]);function zb(e){const n={};return typeof e.lane=="string"&&$b.has(e.lane)&&e.lane!=="main"&&(n.lane=e.lane),e.lacuna===!0&&(n.lacuna=!0),e.lacuna===!0&&e.guess!==!0&&typeof e.guess_c=="string"&&e.guess_c.trim()&&(n.guess_c=e.guess_c.trim()),e.guess===!0&&(n.guess=!0),typeof e.zi=="string"&&e.zi&&(n.zi=e.zi),typeof e.fig=="string"&&ds.test(e.fig)&&e.c==="□"&&!e.lacuna&&!e.guess&&e.guess_c===void 0&&e.zi===void 0&&(n.fig=e.fig),n}function Nb(e){const n={};typeof e.kind=="string"&&Cb.has(e.kind)&&e.kind!=="body"&&(n.kind=e.kind);const i=dt(e.raised);i!==void 0&&Number.isInteger(i)&&i>0&&(n.raised=i);const o=dt(e.lead_blank);return o!==void 0&&Number.isInteger(o)&&o>0&&(n.lead_blank=o),n}function Tr(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(i=>!!i&&typeof i=="object"):[]}function Tb(e){return typeof e=="string"&&Array.from(e).length===1}function Md(e){const n=new Map,i={badAnchor:0,badChar:0,badWhy:0,notObject:0},o=e&&typeof e=="object"?e.items:void 0;for(const s of Array.isArray(o)?o:[]){if(!s||typeof s!="object"){i.notObject++;continue}const{a,t:l,why:d}=s;if(typeof a!="string"||!Ad.test(a)){i.badAnchor++;continue}if(!Tb(l)){i.badChar++;continue}if(d!==void 0&&d!=="异体"){i.badWhy++;continue}n.set(a,l)}return{map:n,dropped:i}}function Pd(e){return Md(e).map}function Ib(e,n,i){var m,u,h,x,j,b,_,y,k,w;const o=i==null?null:Pd(i),s=new Map,a=new Map;for(const v of Tr(n)){const C=dt(v.page);if(C!==void 0){s.set(C,v);for(const $ of Array.isArray(v.cells)?v.cells:[]){const S=$==null?void 0:$.box;typeof($==null?void 0:$.a)=="string"&&Array.isArray(S)&&S.length===4&&S.every(R=>dt(R)!==void 0)&&a.set($.a,[S[0],S[1],S[0]+S[2],S[1]+S[3]])}}}const l=new Map;for(const[v,C]of s)for(const $ of Array.isArray(C.marks)?C.marks:[]){const S=$==null?void 0:$.box;if(($==null?void 0:$.kind)!=="figure"||typeof $.fig!="string"||!Array.isArray(S)||S.length!==4||!S.every(N=>dt(N)!==void 0))continue;let R=l.get(v);R||l.set(v,R=new Map),R.set($.fig,[S[0],S[1],S[0]+S[2],S[1]+S[3]])}const d=[],c=new Map,p=new Map;for(const v of Tr(e)){const C=dt(v.page);C!==void 0&&typeof v.label=="string"&&v.label&&c.set(C,v.label)}for(const v of Tr(e)){const C=dt(v.page);if(C===void 0)continue;const $=[],S=l.get(C);for(const N of Array.isArray(v.columns)?v.columns:[]){const z=dt(N==null?void 0:N.col);if(z===void 0)continue;if(N.kind==="figure"){if(typeof N.fig!="string"||!ds.test(N.fig))continue;const A=dt(N.span),M=S==null?void 0:S.get(N.fig);$.push({col:z,chars:[],kind:"figure",fig:N.fig,...A!==void 0&&Number.isInteger(A)&&A>1?{span:A}:{},...M?{figBox:M}:{}});continue}const I=[];for(const A of Array.isArray(N.cells)?N.cells:[]){const M=Ad.exec(String((A==null?void 0:A.a)??""));if(!M||typeof A.c!="string")continue;const F=parseInt(M[3],10),ne=o==null?void 0:o.get(A.a);I.push({id:A.a,char:A.c,slot:F,pos:F,sub:M[4]||null,bbox:a.get(A.a)??null,...zb(A),...ne!==void 0&&ne!==A.c?{norm:ne}:{}})}const P=Nb(N);(I.length>0||P.kind==="blank")&&$.push({col:z,chars:I,...P})}if(!$.some(N=>N.chars.length>0||N.kind==="figure")){$.length>0&&p.set(C,$);continue}$.sort((N,z)=>N.col-z.col);const R=s.get(C);d.push({page:C,seq:String(((m=R==null?void 0:R.canvas)==null?void 0:m.seq)??""),width:dt((u=R==null?void 0:R.canvas)==null?void 0:u.width)??dt((h=R==null?void 0:R.image)==null?void 0:h.width)??0,height:dt((x=R==null?void 0:R.canvas)==null?void 0:x.height)??dt((j=R==null?void 0:R.image)==null?void 0:j.height)??0,...typeof v.label=="string"&&v.label?{label:v.label}:{},columns:$})}const g=new Set(d.map(v=>v.page));for(const[v,C]of s){const $=(b=C==null?void 0:C.canvas)==null?void 0:b.seq;g.has(v)||typeof $!="string"&&typeof $!="number"||String($)===""||d.push({page:v,seq:String($),width:dt((_=C.canvas)==null?void 0:_.width)??dt((y=C.image)==null?void 0:y.width)??0,height:dt((k=C.canvas)==null?void 0:k.height)??dt((w=C.image)==null?void 0:w.height)??0,...c.has(v)?{label:c.get(v)}:{},columns:p.get(v)??[]})}return d.sort((v,C)=>v.page-C.page)}const Eb=new Set(["image/png","image/webp","image/svg+xml"]);function Rb(e){const n=new Map,i=e&&typeof e=="object"?e.figures:void 0;for(const o of Array.isArray(i)?i:[]){if(!o||typeof o!="object")continue;const s=o;if(typeof s.id!="string"||!ds.test(s.id))continue;const a=s.kind==="block"?"block":s.kind==="inline"?"inline":null;a&&(typeof s.file!="string"||!/^fig\/[\w./-]+$/.test(s.file)||s.file.split("/").includes("..")||typeof s.mime!="string"||!Eb.has(s.mime)||n.set(s.id,{id:s.id,kind:a,alt:typeof s.alt=="string"&&s.alt.trim()?s.alt.trim():"图形符号",file:s.file,mime:s.mime,width:dt(s.width)??0,height:dt(s.height)??0}))}return n}const Lb=({data:e,onNavigate:n,className:i,style:o})=>{var g;const{t:s,convert:a}=re(),[l,d]=f.useState(((g=e.divisions[0])==null?void 0:g.name)??null),[c,p]=f.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(m=>t.jsx(Ab,{division:m,expanded:l===m.name,onToggle:()=>d(l===m.name?null:m.name),expandedCat:c,onCatToggle:u=>p(c===u?null:u),onNavigate:n},m.name))})]})},Ab=({division:e,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=re(),c=e.categories.reduce((p,g)=>{const m=g.stats||{zhulu:0,cunmu:0};return p+(m.zhulu||0)+(m.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 g=`${e.name}/${p.name}`;return t.jsx(Mb,{category:p,expanded:o===g,onToggle:()=>s(g),onNavigate:a},p.name)})})]})},Mb=({category:e,expanded:n,onToggle:i,onNavigate:o})=>{var p,g,m,u;const{t:s,convert:a}=re(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((g=e.books)==null?void 0:g.cunmu)||[],c=(((m=e.stats)==null?void 0:m.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.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(tl,{label:s("catalogPage.zhulu"),books:l,onNavigate:o}),d.length>0&&t.jsx(tl,{label:s("catalogPage.cunmu"),books:d,onNavigate:o})]})]})},tl=({label:e,books:n,onNavigate:i})=>{const{t:o,convert:s}=re(),a=mt(),[l,d]=f.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,g)=>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:m=>{m.metaKey||m.ctrlKey||(m.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)})]},g))}),!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})})]})},Et=({title:e,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const a=Pe();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:Bb,children:"AI"}),n&&t.jsx("button",{onClick:n,style:Pb,children:a.action.save})]})]}),s]})},Pb={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},Bb={padding:"4px 12px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},_t=({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"}})]}),pn=({value:e,onChange:n,placeholder:i})=>{const o=f.useRef(null);return f.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"}})},Ei=({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 Ob(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const _i=({value:e,onChange:n,label:i})=>{const[o,s]=f.useState(!1),a=f.useRef(null),l=Ob(e||"");return f.useEffect(()=>{o&&a.current&&a.current.focus()},[o]),!o&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:nl,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(Ei,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:nl,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"}})]})},nl={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500};function Wb(e){switch(e){case"url":return r("source-url");case"bookID":return r("source-bookid");default:return r("desc-fg")}}function Fb(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Bd=({items:e,onChange:n,onOpenEntityPicker:i})=>{const o=Pe(),[s,a]=f.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=m=>{n(e.filter((u,h)=>h!==m)),s===m&&a(null)},c=(m,u,h)=>{const x=[...e];x[m]={...x[m],[u]:h},n(x)},p=(m,u)=>{const h=[...e];h[m]={...h[m],type:u,id:"",name:""},n(h),u==="bookID"&&i&&i(x=>{const j=[...e];j[m]={...j[m],id:x.id,name:x.title,type:"bookID"},n(j)})},g=m=>{i&&i(u=>{const h=[...e];h[m]={...h[m],id:u.id,name:u.title,type:"bookID"},n(h)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,u)=>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===u?null:u),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===u?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:r("fg")},children:m.name||`${o.editor.sourcePlaceholder} ${u+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Wb(m.type),color:r("on-color-fg"),borderRadius:"3px",fontWeight:500},children:Fb(m.type)}),t.jsx("button",{onClick:h=>{h.stopPropagation(),d(u)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===u&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!m.type&&t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(u,"bookID"),style:{...il,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(u,"url"),style:{...il,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})]})]})]}),m.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:Ht,children:o.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const h=[...e];h[u]={...h[u],type:"",id:"",name:""},n(h)},style:rl,children:o.action.changeType})]}),m.id&&m.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:m.name}),t.jsx("code",{style:{fontSize:"11px",background:r("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:m.id})]}),t.jsx("button",{onClick:()=>g(u),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:()=>g(u),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})]})]})}),m.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:Ht,children:o.label.sourceName}),t.jsx("button",{onClick:()=>{const h=[...e];h[u]={...h[u],type:"",id:"",name:""},n(h)},style:rl,children:o.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:h=>c(u,"name",h.target.value),placeholder:o.editor.sourceNamePlaceholder,style:bn})]}),t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:h=>c(u,"id",h.target.value),placeholder:"https://...",style:bn})]})]}),m.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:{...Ht,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:Ht,children:o.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:h=>c(u,"details",h.target.value),placeholder:o.editor.detailsPlaceholder,style:bn})]}),t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:h=>c(u,"position",h.target.value),placeholder:"如: 卷三, p.52",style:bn})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:h=>c(u,"version",h.target.value),placeholder:"如: v1.0, 2024-01",style:bn})]}),t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:h=>c(u,"processor_version",h.target.value),placeholder:"如: v0.1",style:bn})]})]})]})]})})]},u)),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})]})]})},Ht={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500},bn={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"},il={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"},rl={background:"transparent",border:"none",color:r("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Od(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 Wd(e){return!e||e.length===0?"":JSON.stringify(e)}const Fd=({entityType:e,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:g,onLinkEntity:m,onUnlinkEntity:u,onViewEntity:h,onCreateAndLink:x,onSaveRelations:j})=>{const b=Pe();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:b.section.relations})]}),j&&t.jsx("button",{onClick:j,style:Hb,children:b.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Fn,{direction:"up",title:b.relation.belongsToWork,entity:a,onView:h,onUnlink:()=>u("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(Fn,{direction:"up",title:b.relation.containedInCollection,entity:l,onView:h,onUnlink:()=>u("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),a&&g&&g.length>0&&t.jsx(yn,{direction:"horizontal",title:`${b.relation.siblingVersions} (${g.length})`,entities:g,onView:h,onAdd:()=>x("siblingBook","book",{workId:a.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Fn,{direction:"up",title:b.relation.parentWork,entity:o,onView:h,onUnlink:()=>u("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>x("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),d&&d.length>0&&t.jsx(yn,{direction:"down",title:`${b.relation.childWorks} (${d.length})`,entities:d,onView:h,onAdd:()=>x("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),c&&c.length>0&&t.jsx(yn,{direction:"down",title:`${b.relation.collectionImpl} (${c.length})`,entities:c,onView:h,onAdd:()=>x("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(yn,{direction:"down",title:`${b.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:h,onAdd:()=>x("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Fn,{direction:"up",title:b.relation.correspondingWork,entity:a,onView:h,onUnlink:()=>u("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(Fn,{direction:"up",title:b.relation.parentCollection,entity:s,onView:h,onUnlink:()=>u("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>x("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(yn,{direction:"down",title:`${b.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:h,onAdd:()=>x("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(yn,{direction:"down",title:`${b.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:h,onAdd:()=>x("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},Fn=({direction:e,title:n,entity:i,onView:o,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:g,unlinkLabel:m})=>{const u=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),h=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:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:h}),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:Hd(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(ol,{onClick:()=>o(i),title:g,children:"👁️"}),t.jsx(ol,{onClick:s,title:m,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(so,{onClick:a,children:d}),t.jsx(so,{onClick:l,primary:!0,children:c})]})]})},yn=({direction:e,title:n,entities:i,onView:o,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=f.useState(!1),g=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",u=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:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[u.map(h=>t.jsxs("div",{onClick:()=>o(h),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:r("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Hd(h.type)}),t.jsx("span",{children:h.title})]},h.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(so,{onClick:s,primary:!0,children:["+ ",a]})})]})},ol=({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}),so=({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 Hd(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const Hb={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Dd=({isOpen:e,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[g,m]=f.useState(""),u=p?l.filter(b=>b.id!==p):l;f.useEffect(()=>{e&&(m(""),d(""))},[e]);const h=b=>{m(b),d(b)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",j=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Db,children:t.jsxs("div",{style:Ub,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:Vb,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:g,onChange:b=>h(b.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:Gb})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Ir,children:"搜索中..."}):u.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:u.map(b=>t.jsxs("div",{onClick:()=>o(b),style:Yb,children:[t.jsx("span",{style:{fontSize:"16px"},children:j}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):g?t.jsxs("div",{style:Ir,children:["未找到匹配的",x]}):t.jsxs("div",{style:Ir,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:qb,children:["创建新",x,"并关联"]})]})]})})},Db={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ub={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")},Vb={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Gb={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"},Yb={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:r("primary-soft")},Ir={padding:"20px",textAlign:"center",color:r("desc-fg")},qb={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},sl={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Kb={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ud=({isOpen:e,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:a})=>{const[l,d]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(d((o==null?void 0:o.title)||""),setTimeout(()=>{var u,h;(u=c.current)==null||u.focus(),(h=c.current)==null||h.select()},100))},[e,o==null?void 0:o.title]);const p=u=>{u.key==="Enter"&&l.trim()?g():u.key==="Escape"&&a()},g=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!e)return null;const m=()=>{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`创建新${sl[n]}`}};return t.jsx("div",{style:Xb,onClick:u=>{u.target===u.currentTarget&&a()},children:t.jsxs("div",{style:Zb,onClick:u=>u.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Kb[n]}),t.jsx("span",{children:m()})]}),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:u=>d(u.target.value),onKeyDown:p,placeholder:`请输入${sl[n]}名称...`,style:Jb})]}),((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:Qb,children:"取消"}),t.jsx("button",{onClick:g,disabled:!l.trim(),style:{...ey,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Xb={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Zb={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")},Jb={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"},Qb={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},ey={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg")};function ty(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Vd(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ny(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 Gd=({isOpen:e,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:g})=>{const[m,u]=f.useState(""),[h,x]=f.useState([]),[j,b]=f.useState(!1),[_,y]=f.useState("recent");f.useEffect(()=>{e&&(u(""),x([]),y(o.length>0?"recent":"search"))},[e,o.length]),f.useEffect(()=>{if(!m.trim()){x([]);return}const S=setTimeout(async()=>{b(!0);try{x(await g(m,i))}catch{x([])}finally{b(!1)}},300);return()=>clearTimeout(S)},[m,i,g]);const k=f.useCallback(S=>{u(S.target.value),S.target.value.trim()&&y("search")},[]),w=f.useCallback(S=>s?S.filter(R=>R.id!==s):S,[s]);if(!e)return null;const v=n||(i==="all"?"选择实体":`选择${Vd(i)}`),C=w(o),$=w(h);return t.jsx("div",{style:ry,children:t.jsxs("div",{style:oy,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:v}),t.jsx("button",{onClick:c,style:sy,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:m,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:ay}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),j&&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(al,{active:_==="recent",onClick:()=>y("recent"),children:["最近使用 (",C.length,")"]}),t.jsxs(al,{active:_==="search",onClick:()=>y("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(ll,{entities:C,onSelect:d}):m.trim()?j?t.jsx(Er,{message:"搜索中..."}):$.length>0?t.jsx(ll,{entities:$,onSelect:d}):t.jsx(Er,{message:"未找到匹配的结果"}):t.jsx(Er,{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:ly,children:l||"创建新实体"})]})]})})},al=({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}),ll=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(iy,{entity:i,onClick:()=>n(i)},i.id))}),iy=({entity:e,onClick:n})=>{const[i,o]=f.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:ty(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:ny(e.type),color:r("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Vd(e.type)})]})},Er=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:e}),ry={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},oy={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")},sy={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},ay={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"},ly={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},cy={work:r("editor-type-work"),collection:r("editor-type-collection"),book:r("editor-type-book"),entity:r("editor-type-entity")},dy={work:"📜",collection:"📚",book:"📖",entity:"👤"},Yd=({data:e,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:g,relations:m,onRelationsChange:u})=>{var de;const h=Pe(),[x,j]=f.useState(!1),[b,_]=f.useState("work"),[y,k]=f.useState(""),[w,v]=f.useState(""),[C,$]=f.useState([]),[S,R]=f.useState(!1),[N,z]=f.useState(!1),[I,P]=f.useState("work"),[A,M]=f.useState(""),[F,ne]=f.useState(),[je,ae]=f.useState(!1),[Y,xe]=f.useState(null),[J,le]=f.useState([]);f.useRef(null);const we=e.type,ye=we==="work",Q=we==="collection",T=we==="book",G=f.useCallback((ee,Ce)=>{n({...e,[ee]:Ce})},[e,n]),fe=f.useCallback((ee,Ce)=>{k(ee),_(Ce),v(h.editor.selectToLink+h.indexType[Ce]),$([]),j(!0)},[h]),se=f.useCallback(ee=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(e.id,ee)},[o,e.id]),Be=f.useCallback(ee=>{s==null||s(ee.id,ee.type)},[s]),Oe=f.useCallback((ee,Ce,Ue)=>{const Ge={...Ue,author:(Ue==null?void 0:Ue.author)||e.author,dynasty:Ue==null?void 0:Ue.dynasty};P(Ce),M(ee),ne(Ge),z(!0)},[e.author]),X=f.useCallback((ee,Ce)=>{o!=null&&o.createAndLink&&o.createAndLink(e.id,A,{type:I,title:ee,inheritData:Ce}),z(!1)},[o,e.id,A,I]),oe=f.useCallback(ee=>{if(!ee.trim()){$([]);return}R(!0),o!=null&&o.searchEntities&&o.searchEntities(ee,b).then(Ce=>{$(Ce),R(!1)}).catch(()=>{$([]),R(!1)})},[o,b]),ze=f.useCallback(ee=>{o!=null&&o.linkEntity&&o.linkEntity(e.id,y,ee.id),j(!1)},[o,e.id,y]),We=f.useCallback(()=>{i()},[i]),be=f.useCallback(ee=>{xe(()=>ee),ae(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(le).catch(()=>{})},[o]),H=f.useCallback((ee,Ce)=>o!=null&&o.searchEntities?o.searchEntities(ee,Ce==="all"?void 0:Ce):Promise.resolve([]),[o]),ce=f.useCallback(ee=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(ee),le(Ce=>[ee,...Ce.filter(Ue=>Ue.id!==ee.id)].slice(0,10)),Y==null||Y(ee),ae(!1),xe(null)},[o,Y]);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:dy[we]}),t.jsx("span",{children:e.title||h.editor.untitled}),t.jsx(Ei,{children:e.id}),t.jsx(Ei,{color:cy[we],children:h.indexType[we]})]})}),t.jsx(Et,{title:h.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(_i,{label:ye?h.editor.workTitle:Q?h.editor.collectionTitle:h.editor.bookTitle,value:e.title,onChange:ee=>G("title",ee)}),T&&t.jsx(_i,{label:h.editor.belongsToWork,value:e.workName||"",onChange:ee=>G("workName",ee)}),t.jsx(_t,{label:h.editor.authorLabel,value:e.author||"",onChange:ee=>G("author",ee)}),t.jsx(_t,{label:h.editor.publicationYearLabel,value:e.publicationYear||"",onChange:ee=>G("publicationYear",ee)}),(T||Q)&&t.jsx(_i,{label:h.editor.containedIn,value:e.collection||"",onChange:ee=>G("collection",ee)}),(T||Q)&&t.jsx(_t,{label:h.editor.holderLabel,value:e.holder||"",onChange:ee=>G("holder",ee)}),(T||Q)&&t.jsx(_t,{label:T?h.editor.pageLabel:h.editor.volumeLabel,value:e.pages||"",onChange:ee=>G("pages",ee)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(_t,{label:h.editor.firstImageLabel,value:e.firstImage||"",onChange:ee=>G("firstImage",ee)})})]})}),t.jsx(Et,{title:h.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(pn,{value:e.description||"",onChange:ee=>G("description",ee),placeholder:h.editor.descriptionPlaceholder})}),(((de=e.additional_works)==null?void 0:de.length)||0)>0&&t.jsx(Et,{title:h.section.additionalWorks,onSave:i,children:t.jsx(py,{items:e.additional_works||[],onChange:ee=>G("additional_works",ee)})}),t.jsx(Et,{title:h.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(uy,{items:e.indexed_by||[],onChange:ee=>G("indexed_by",ee)})}),t.jsx(Et,{title:h.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(my,{items:e.emendated_by||[],onChange:ee=>G("emendated_by",ee)})}),t.jsx(Et,{title:h.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(Br,{items:e.resources||[],onChange:ee=>G("resources",ee),onDownload:p,downloadStatuses:g,filterType:"text"})}),t.jsx(Et,{title:h.section.imageResources,onSave:i,children:t.jsx(Br,{items:e.resources||[],onChange:ee=>G("resources",ee),onDownload:p,downloadStatuses:g,filterType:"image"})}),t.jsx(Et,{title:h.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(Bd,{items:Od(e.sources||""),onChange:ee=>G("sources",Wd(ee)),onOpenEntityPicker:be})}),(T||Q)&&t.jsx(Et,{title:h.section.provenance,onSave:i,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(pn,{value:e.provenance||"",onChange:ee=>G("provenance",ee),placeholder:h.editor.provenancePlaceholder})}),T&&t.jsx(Et,{title:h.section.otherEditions,onSave:i,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(pn,{value:e.otherEditions||"",onChange:ee=>G("otherEditions",ee),placeholder:h.editor.otherEditionsPlaceholder})}),t.jsx(Fd,{entityType:we,entityId:e.id,entityTitle:e.title,parentWork:m==null?void 0:m.parentWork,parentCollection:m==null?void 0:m.parentCollection,belongsToWork:m==null?void 0:m.belongsToWork,belongsToCollection:m==null?void 0:m.belongsToCollection,childWorks:m==null?void 0:m.childWorks,childCollections:m==null?void 0:m.childCollections,containedBooks:m==null?void 0:m.containedBooks,siblingBooks:m==null?void 0:m.siblingBooks,onLinkEntity:fe,onUnlinkEntity:se,onViewEntity:Be,onCreateAndLink:Oe,onSaveRelations:We}),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:h.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"12px"},children:h.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:h.editor.deleteEntity})]}),t.jsx(Dd,{isOpen:x,entityType:b,title:w,onSelect:ze,onCancel:()=>j(!1),onCreate:()=>{j(!1),Oe(y,b)},searchResults:C,onSearch:oe,isLoading:S,excludeId:e.id}),t.jsx(Ud,{isOpen:N,entityType:I,relationField:A,inheritData:F,onConfirm:X,onCancel:()=>z(!1)}),t.jsx(Gd,{isOpen:je,title:h.action.selectBookOrWork,filterType:"all",recentEntities:J,excludeId:e.id,onSelect:ce,onCancel:()=>{ae(!1),xe(null)},onSearch:H})]})};function py({items:e,onChange:n}){const i=Pe(),o=(l,d,c)=>{const p=e.map((g,m)=>m===l?{...g,[d]:c}:g);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(_t,{label:i.editor.bookNameLabel,value:l.book_title,onChange:c=>o(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(_t,{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 qd({items:e,onChange:n,showMeta:i,addLabel:o}){const s=Pe(),[a,l]=f.useState(null),d=(g,m,u)=>{const h=e.map((x,j)=>j===g?{...x,[m]:u||void 0}:x);n(h)},c=g=>{n(e.filter((m,u)=>u!==g)),a===g&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,m)=>{const u=a===m;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:u?`color-mix(in srgb, ${r("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(u?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:r("desc-fg"),transition:"transform 0.2s",transform:u?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:g.source||s.editor.unnamedSource}),g.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:r("desc-fg")},children:g.source_bid}),t.jsx("button",{onClick:h=>{h.stopPropagation(),c(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${r("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:r("muted")},children:"✕"})]}),!u&&i&&(g.title_info||g.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:r("desc-fg")},children:[g.title_info,g.title_info&&g.author_info&&" — ",g.author_info]}),u&&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(_t,{label:s.label.sourceName,value:g.source,onChange:h=>d(m,"source",h)}),t.jsx(_t,{label:s.label.sourceBid,value:g.source_bid||"",onChange:h=>d(m,"source_bid",h)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(_t,{label:s.label.titleInfo,value:g.title_info||"",onChange:h=>d(m,"title_info",h)}),t.jsx(_t,{label:s.label.authorInfo,value:g.author_info||"",onChange:h=>d(m,"author_info",h)})]}),t.jsx(_t,{label:s.label.edition,value:g.edition||"",onChange:h=>d(m,"edition",h)})]}),t.jsx(pn,{value:g.summary||"",onChange:h=>d(m,"summary",h),placeholder:s.editor.summaryPlaceholder}),t.jsx(pn,{value:g.comment||"",onChange:h=>d(m,"comment",h),placeholder:s.editor.commentPlaceholder}),t.jsx(pn,{value:g.additional_comment||"",onChange:h=>d(m,"additional_comment",h),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),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 uy({items:e,onChange:n}){const i=Pe();return t.jsx(qd,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function my({items:e,onChange:n}){const i=Pe();return t.jsx(qd,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Kd(e){var d,c,p,g,m,u,h;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=((g=e.current_location)==null?void 0:g.name)||"",s=(m=e.page_count)!=null&&m.number?String(e.page_count.number):((u=e.page_count)==null?void 0:u.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 j=x.related_works.find(b=>b.relation==="part_of");j&&(l.parentWorkId=j.id,l.parentWorkName=j.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=(h=x.contained_in[0])==null?void 0:h.id)}return l}function gy(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 fy=e=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:g,onAskAI:m,renderSectionActions:u,onDownloadResource:h,downloadStatuses:x,relations:j,onRelationsChange:b,headerExtra:_,className:y,style:k}=e,w=Pe(),[v,C]=f.useState(s),$=a?s:v;f.useEffect(()=>{s!==v&&C(s)},[s]);const S=f.useCallback(()=>{const M=$==="view"?"edit":"view";a?a(M):C(M)},[$,a]),[R,N]=f.useState(null);f.useEffect(()=>{i&&o&&o.getItem(i).then(M=>{M&&N(M)})},[i,o]);const z=n||R,I=f.useMemo(()=>z?Kd(z):null,[z]),P=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"?w.common.switchToEdit:w.common.switchToView,children:$==="view"?w.common.modeEdit:w.common.modeView}):null,A=t.jsxs(t.Fragment,{children:[P,_]});return!z&&!I?t.jsx(un,{}):$==="view"?t.jsx(Eo,{data:z,transport:o,onNavigate:p?M=>p(M):void 0,renderLink:g,headerExtra:A,className:y,style:k}):I?t.jsxs("div",{className:y,style:k,children:[A&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:A}),t.jsx(Yd,{data:I,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:m,renderSectionActions:u,onDownloadResource:h,downloadStatuses:x,relations:j,onRelationsChange:b})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:r("muted")},children:w.common.noData})},hy=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Xd=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const{t:s}=re(),[a,l]=f.useState(null),[d,c]=f.useState(""),[p,g]=f.useState(""),[m,u]=f.useState("idle"),[h,x]=f.useState(""),j=f.useRef(null);f.useEffect(()=>{e&&(l(null),c(""),g(""),u("idle"),x(""))},[e]),f.useEffect(()=>{a&&setTimeout(()=>{var y;return(y=j.current)==null?void 0:y.focus()},100)},[a]),f.useEffect(()=>{if(m==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[m,n]),f.useEffect(()=>{if(!e)return;const y=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const b=async()=>{if(!(!a||!d.trim())){u("submitting"),x("");try{await i({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),u("success")}catch(y){u("error"),x(y instanceof Error?y.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const _=a&&d.trim()&&m!=="submitting";return t.jsx("div",{style:xy,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:by,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:yy,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:jy,"aria-label":s("feedback.close"),children:"✕"})]}),m==="success"?t.jsxs("div",{style:_y,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:hy.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{...vy,...a===y.value?ky:{}},children:[t.jsx("span",{children:y.icon})," ",s(`feedback.submitType.${y.value}`)]},y.value))}),t.jsx("textarea",{ref:j,value:d,onChange:y=>c(y.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||m==="submitting",style:{...wy,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:y=>g(y.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||m==="submitting","aria-label":s("feedback.contactLabel"),style:Cy}),t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),m==="error"&&t.jsx("div",{style:$y,children:h}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:b,disabled:!_,style:{...Sy,opacity:_?1:.6,cursor:_?"pointer":"not-allowed"},children:s(m==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},xy={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},by={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r("shadow-dialog")},yy={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},jy={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r("desc-fg"),padding:"4px 8px",borderRadius:"4px"},vy={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"},ky={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},wy={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"},Sy={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},_y={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r("success")},$y={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Cy={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"},ao="--bim-feedback-fab-offset",lo=48,zy=16,Ny=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:o=!1,zIndex:s})=>{const{t:a}=re(),[l,d]=f.useState(!1),c=n.bottom??24;return f.useEffect(()=>{if(o||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(ao,`calc(${c+lo+zy}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(ao)}},[o,c]),t.jsxs(t.Fragment,{children:[!o&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Ty,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(Xd,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},Ty={position:"fixed",width:`${lo}px`,height:`${lo}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"},Iy=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Zd=({onSubmit:e})=>{const{t:n}=re(),[i,o]=f.useState("bug"),[s,a]=f.useState(""),[l,d]=f.useState(""),[c,p]=f.useState("idle"),[g,m]=f.useState(""),u=f.useRef(null);f.useEffect(()=>{i&&setTimeout(()=>{var j;return(j=u.current)==null?void 0:j.focus()},100)},[i]);const h=async()=>{if(!(!i||!s.trim())){p("submitting"),m("");try{await e({type:i,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),o("bug")}catch(j){p("error"),m(j instanceof Error?j.message:n("feedback.submitFailedRetry"))}}},x=i&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:cl,children:t.jsxs("div",{style:My,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:Py,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:cl,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Iy.map(j=>t.jsxs("button",{onClick:()=>o(j.value),style:{...Ey,...i===j.value?Ry:{}},children:[t.jsx("span",{children:j.icon})," ",n(`feedback.submitType.${j.value}`)]},j.value))}),t.jsx("textarea",{ref:u,value:s,onChange:j=>a(j.target.value),placeholder:n(i?`feedback.placeholder.${i}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...Ly}}),t.jsx("input",{type:"text",value:l,onChange:j=>d(j.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:Oy}),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:h,disabled:!x,style:{...Ay,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:By,children:g})]})},cl={padding:"16px",border:`1px solid ${r("widget-border")}`,borderRadius:"8px",background:r("input-bg")},Ey={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"},Ry={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},Ly={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"},Ay={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},My={display:"flex",alignItems:"center",gap:"12px",color:r("success"),fontSize:"14px"},Py={background:"none",border:"none",color:r("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},By={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginTop:"8px"},Oy={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 dl(e){return typeof e=="function"?e():e??"/api/feedback"}const Jd=({resourceId:e,apiUrl:n})=>{const{t:i}=re(),[o,s]=f.useState([]),[a,l]=f.useState(!0),d=f.useCallback(async()=>{const p=dl(n);l(!0);try{const m=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();m.success&&s(m.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{d()},[d]);const c=async p=>{const g=dl(n),m=await fetch(g,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!m.ok){const u=await m.json().catch(()=>null);throw new Error((u==null?void 0:u.error)||i("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(cs,{items:o,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Zd,{onSubmit:c})})]})},Ki=8;async function Xi(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 Wy=Ai["zh-Hant"].relation,Fy=Ai["zh-Hant"].lossStatus,Hy=Ai["zh-Hant"].resourceKind,Zi=Nn("zh-Hant"),ps=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function pl(e,n=Zi){return e?ps(Wy,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function Dy(e,n=Zi){return ps(Fy,e)?n(`detail.lossStatus.${e}`):e}function Uy(e,n=Zi){return ps(Hy,e)?n(`detail.resourceKind.${e}`):""}function us({authors:e,onNavigate:n,renderLink:i}){const{convert:o}=re(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=$o(a.role);return t.jsxs(f.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(pt,{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 Qd(e,n,i=Zi){var c,p;const o=So(e,n),s=o.mirrors.map(g=>({key:g.key,label:g.label,description:g.description,rows:g.items.filter(m=>m.group_role!=="mirror"),mirrors:g.items.filter(m=>m.group_role==="mirror")})),a=o.buckets.filter(g=>g.key==="image"||g.key==="textImage").flatMap(g=>g.items);a.length&&s.push({key:"_images",label:s.length?i("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=o.buckets.find(g=>g.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(g=>g.key==="text"))==null?void 0:p.items)??[],groups:s}}function ep(e,n){const i=(e.url?$n(e.url):void 0)||e.name,o=Kl(e,n);return o?`${i}(${o})`:i}function ms({item:e,siblings:n,listedVolumeCounts:i}){const{t:o,convert:s}=re(),[a,l]=f.useState(!1),d=Li(e),c=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),p=s(ep(e,n)),g=Cn(e),m=Oi(e,o)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var h,x;const u=(h=e.metadata)!=null&&h.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 g?t.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),u]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,u]})})(),m&&t.jsx("span",{className:"bim-d-meta",children:s(m)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Wo,{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(u=>!u),children:a?o("detail.collapseVolumes"):o("detail.expandVolumes",{n:d.expected})})})]})}function tp({groups:e,listedVolumeCounts:n}){const{t:i,convert:o}=re();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(ms,{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=Cn(a),c=o(ep(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 Kn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function co(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Kn.find(o=>n.startsWith(o.key[0])))==null?void 0:i.key}const ul=12,Vy=60,np=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,railTop:a,back:l,railLinks:d})=>{var ze,We,be;const{t:c,convert:p,messages:g}=re(),m=f.useMemo(()=>Co({_books:e._books}),[e._books]),[u,h]=f.useState(new Map),[x,j]=f.useState(!1),[b,_]=f.useState(""),[y,k]=f.useState(!1),w=m.length<=Vy,v=w||x||!!b||y,C=f.useMemo(()=>v?m:m.slice(0,ul),[m,v]);f.useEffect(()=>{if(!n||C.length===0)return;const H=C.filter(de=>!u.has(de));if(H.length===0)return;let ce=!1;return Xi(H,Ki,de=>n.getItem(de).then(ee=>{var Ue;const Ce=ee??{};return[de,{id:de,title:Ce.title,edition:Ce.edition,resources:Ce.resources,publication_info:Ce.publication_info,current_location:Ce.current_location,lineage:Ce.lineage,measure_info:Ce.measure_info,summary:Gy((Ue=ee==null?void 0:ee.description)==null?void 0:Ue.text)}]}).catch(()=>[de,{id:de}]),()=>ce).then(de=>{ce||h(ee=>{const Ce=new Map(ee);for(const[Ue,Ge]of de)Ce.set(Ue,Ge);return Ce})}),()=>{ce=!0}},[n,C,u]);const $=f.useMemo(()=>m.map(H=>u.get(H)??{id:H}),[m,u]),S=m.length>0&&m.every(H=>u.has(H)),R=!!n&&C.some(H=>!u.has(H)),N=w||v,z=f.useMemo(()=>Zl($,e.version_graph,{era:b,scanOnly:y,sort:N?"year":"default"}),[$,e.version_graph,b,y,N]),I=x?z.rows:z.rows.slice(0,ul),P=z.allRows.filter(H=>H.hasImage).length,A=z.allRows.reduce((H,ce)=>{var de;return H+(((de=ce.copies)==null?void 0:de.length)??0)},0),M=f.useMemo(()=>(e._related||[]).map(H=>({...H,title:H.title??""})),[e._related]),F=M.filter(H=>H.relation==="collected_in"),ne=f.useMemo(()=>{const H=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ce=de=>{const ee=H.indexOf(de??"");return ee<0?H.length:ee};return M.filter(de=>de.relation!=="collected_in").map((de,ee)=>({r:de,i:ee})).sort((de,ee)=>ce(de.r.relation)-ce(ee.r.relation)||de.i-ee.i).map(de=>de.r)},[M]),je=f.useMemo(()=>{const H=So(e.resources,e.resource_groups);return[...H.mirrors.flatMap(ce=>ce.items.map(de=>({r:de,kind:p(ce.label)}))),...H.buckets.flatMap(ce=>ce.items.map(de=>({r:de,kind:p(Uy(ce.key,c))})))]},[e.resources,e.resource_groups,p,c]),ae=e.indexed_by||[],Y=e.emendated_by||[],xe=f.useMemo(()=>{var O,ue,Re;const H=[],ce=(ue=(O=e.authors)==null?void 0:O[0])==null?void 0:ue.dynasty;ce&&H.push({label:c("workPage.fact.written"),value:p(ce)});const de=Yt(e,g.unit.juan);if(de){const W=(Re=e.juan_count)==null?void 0:Re.description;H.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(de),W&&W!==de?t.jsxs("span",{className:"bim-d-meta",children:["(",p(W),")"]}):null]})})}e.loss_status&&H.push({label:c("workPage.fact.loss"),value:p(Dy(e.loss_status,c))});const ee=z.allRows.filter(W=>W.sortYear!=null),Ce=ee.length>0?ee.reduce((W,pe)=>W.sortYear<=pe.sortYear?W:pe):null;Ce!=null&&Ce.era.era?H.push({label:c("workPage.fact.earliest"),value:p([Ce.era.era,Ce.era.reign].filter(Boolean).join(" ")),title:Ce.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):R&&H.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),Y.length&&H.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:Y.length})});const Ue=ml(e.additional_titles);Ue.length&&H.push({label:c("workPage.fact.alias"),value:Ue.map(p).join("、")});const Ge=ml(e.attached_texts);Ge.length&&H.push({label:c("workPage.fact.attached"),value:Ge.map(p).join("、")});const nt=(e.additional_works||[]).map(W=>p(W.book_title)+(W.n_juan!=null?` ${W.n_juan}${g.unit.juan}`:""));return nt.length&&H.push({label:c("workPage.fact.appendix"),value:nt.join("、")}),H},[e,p,c,g,R,z.allRows,Y.length]),le=[{value:e._edition_count??m.length,label:c("workPage.stat.editions")},{value:S?P:0,label:c("workPage.stat.hasImage")},{value:ae.length,label:c("workPage.stat.catalogs")}],we=zo(e),ye=we?[we.l1,we.l2,we.l3,we.l4].filter(Boolean).map(H=>p(H)):[],Q=e.subtype?g.workSubtype[e.subtype]??p(e.subtype):"",T=t.jsx(ei,{title:p(e.title),byline:t.jsx(us,{authors:e.authors,onNavigate:i,renderLink:o}),meta:t.jsx(ft,{items:[...ye,we!=null&&we.source?c("workPage.classifiedBy",{source:p(we.source.split("/")[0])}):"",Q]}),description:(ze=e.description)!=null&&ze.text?t.jsxs(t.Fragment,{children:[t.jsx(qt,{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(H=>({text:p(Fm(H)),href:Hm(H)})).filter(H=>H.text).map((H,ce)=>t.jsxs(f.Fragment,{children:[ce>0?" · ":null,H.href?t.jsx("a",{href:H.href,target:"_blank",rel:"noopener noreferrer",children:H.text}):H.text]},ce))}):null]}):void 0,stats:le,facts:xe,readAction:s,foot:t.jsx(ti,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(be=e.appendix)==null?void 0:be.map((H,ce)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(H.title)}),t.jsx(qt,{text:H.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ce))}),G=z.eras.length>=2?[{key:"",label:c("catalog.all")},...z.eras.map(H=>({key:H,label:`${H} ${z.allRows.filter(ce=>ce.era.era===H).length}`}))]:[],fe=[];m.length&&fe.push({id:"versions",label:c("workPage.sec.versions"),count:m.length}),ae.length&&fe.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:ae.length}),F.length&&fe.push({id:"collected",label:c("workPage.sec.collected"),count:F.length}),ne.length&&fe.push({id:"related",label:c("workPage.sec.related"),count:ne.length}),je.length&&fe.push({id:"resources",label:c("workPage.sec.resources"),count:je.length});const se=m.length===0&&ae.length===0,Be=t.jsxs(t.Fragment,{children:[m.length>0&&t.jsxs(ht,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(ft,{items:[c("workPage.versionsTotal",{n:m.length-A}),S&&P?c("workPage.versionsWithImage",{n:P}):"",z.rows.length!==z.allRows.length?c("workPage.versionsCurrent",{n:z.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":R&&G.length===0&&m.length>1?"":void 0,children:[G.length>0&&t.jsx(Vi,{items:G,value:b,onChange:H=>{_(H),j(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Hc,{label:c("workPage.scanOnly"),checked:y,onChange:H=>{k(H),j(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(N?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&Gi(z.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:I.map(H=>{var ce;return t.jsx(qy,{row:H,measure:(ce=u.get(H.id))==null?void 0:ce.measure_info,loaded:u.has(H.id),onNavigate:i,renderLink:o},`${H.id}:${u.has(H.id)?"r":"p"}`)})})]}),I.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(b||y?"workPage.noVersionsFiltered":"workPage.noVersions")}),!x&&t.jsx(Mo,{total:z.rows.length,shown:I.length,unit:c("workPage.moreUnit"),onClick:()=>j(!0)}),z.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),ae.length>0&&t.jsx(Ky,{items:ae,transport:n,onNavigate:i,renderLink:o}),se&&t.jsx(ht,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),Oe=(H,ce)=>t.jsx(pt,{id:H,label:p(ce),onNavigate:i,renderLink:o,dense:!0}),X=f.useMemo(()=>{const H=new Map;for(const ce of ne){const de=pl(ce.relation,c);H.set(de,(H.get(de)??0)+1)}return H.size>1?[...H.entries()].sort((ce,de)=>de[1]-ce[1]).slice(0,4).map(([ce,de])=>`${p(ce)} ${de}`).join(" · "):void 0},[ne,p,c]),oe=t.jsxs(t.Fragment,{children:[t.jsx(dn,{id:"collected",title:c("workPage.sec.collected"),items:F.map(H=>Oe(H.id,H.title))}),t.jsx(dn,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:ne.length}),sub:X,items:ne.map(H=>t.jsxs(t.Fragment,{children:[Oe(H.id,H.title),t.jsx("span",{className:"bim-d-meta",title:H.note?p(H.note):void 0,children:p(pl(H.relation,c))})]}))}),t.jsx(dn,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:je.map(({r:H,kind:ce})=>{const de=p((H.url?$n(H.url):void 0)||H.name),ee=Cn(H);return t.jsxs(t.Fragment,{children:[ee?t.jsxs("a",{href:ee,target:"_blank",rel:"noopener noreferrer",children:[de," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:de}),ce&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ce})]})})})]});return t.jsx(Qn,{railTop:a,back:l,nav:fe,railLinks:d,main:Be,card:T,side:oe})};function ml(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function po(e,n){return n((e.url?$n(e.url):void 0)||e.name)}function Gy(e){var a;if(!e)return;const i=e.replace(/\*\*/g,"").split(/\n/)[0].trim().match(/[^。]+。?/g)??[],s=((i.length>1&&((a=i[0])!=null&&a.startsWith("《"))?i[1]:i[0])??"").trim();return s?s.length>120?`${s.slice(0,120)}…`:s:void 0}function Yy({copies:e,onNavigate:n,renderLink:i}){const{t:o,convert:s}=re(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?po(l.holders[0],s):"")||"",c=a.get(d)??[];c.push(l),a.set(d,c)}return t.jsxs("span",{className:"bim-d-zt-copies",children:[o("workPage.sameEditionCopies",{n:e.length}),[...a].map(([l,d],c)=>t.jsxs(f.Fragment,{children:[c>0?";":"",l?`${s(l)} `:"",d.map((p,g)=>t.jsxs(f.Fragment,{children:[g>0?" · ":"",t.jsx(pt,{id:p.id,label:p.callNumber||p.id,onNavigate:n,renderLink:i,dense:!0})]},p.id))]},l||c))]})}function qy({row:e,measure:n,loaded:i,onNavigate:o,renderLink:s}){const{t:a,convert:l}=re(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],g=e.copies??[],m=g.length&&e.locationName?l(e.locationName):p?po(p,l):e.locationName?l(e.locationName):"",u=e.images[0],h=u?Cn(u):void 0,x=e.images.map(j=>po(j,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",className:g.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:g.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(pt,{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:" "}),g.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:l(e.summary)}),g.length>0&&t.jsx(Yy,{copies:g,onNavigate:o,renderLink:s})]}),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),g.length>0&&e.callNumber&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:e.callNumber}),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(h?t.jsx("a",{className:"bim-d-flag",href:h,target:"_blank",rel:"noopener noreferrer",title:x,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:x,children:a("workPage.hasImage")}))})]})}function Ky({items:e,transport:n,onNavigate:i,renderLink:o}){const{t:s,convert:a}=re(),[l,d]=f.useState(0),c=Math.min(l,e.length-1),p=e[c],[g,m]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const u=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(u.length===0)return;let h=!1;return Promise.all(u.map(x=>n.getItem(x).then(j=>{var b,_;return[x,((_=(b=j==null?void 0:j.authors)==null?void 0:b[0])==null?void 0:_.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{h||m(new Map(x.filter(([,j])=>j)))}),()=>{h=!0}},[n,e]),t.jsx(ht,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(ft,{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((u,h)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":h===c,"aria-label":a(u.source),onClick:()=>d(h),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:g.get(u.source_bid??"")?a(g.get(u.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(u.source)].slice(0,9).map((x,j)=>t.jsx("span",{children:x},j))})]})},h))}),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(ft,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(pt,{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:Ct(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:Ct(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:Ct(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 Xy(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 Zy(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 gl(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 Jy(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 Qy(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[g,m]of Object.entries(e.node_groups))l.has(m)&&d.add(g);let c=null;if(i.hypothetical_ids&&(c=new Set(i.hypothetical_ids)),l){c||(c=new Set);for(const g of e.hypothetical_nodes??[])g.group&&l.has(g.group)&&c.add(g.id)}return{books:d,hypos:c}}function $i(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=Qy(o,i??o.default_collection??"all"),c=d!==null,p=(d==null?void 0:d.books)??null,g=(d==null?void 0:d.hypos)??null,m=new Set,u=new Set;if(c){const w=new Map(n.map(N=>[N.id,N])),v=new Map((o.hypothetical_nodes??[]).map(N=>[N.id,N])),C=N=>{const z=w.get(N);if(z&&z.lineage)return(z.lineage.derived_from??[]).map(P=>P.ref);const I=v.get(N);return I?(I.derived_from??[]).map(P=>P.ref):[]},$=N=>v.has(N)?!g||g.has(N):!p||p.has(N),S=new Set,R=N=>{if(!S.has(N)){S.add(N);for(const z of C(N))a.has(z)||($(z)||(v.has(z)?u.add(z):w.has(z)&&m.add(z)),R(z))}};for(const N of n)p&&p.has(N.id)&&!a.has(N.id)&&R(N.id);for(const N of o.hypothetical_nodes??[])g&&g.has(N.id)&&R(N.id)}const h=n.filter(w=>!a.has(w.id)).filter(w=>!p||p.has(w.id)||m.has(w.id)).map(w=>{const v=Zy(w,l);return v&&m.has(w.id)&&(v.bridge=!0),v}).filter(w=>w!==null),x=(o.hypothetical_nodes??[]).filter(w=>!g||g.has(w.id)||u.has(w.id)).map(w=>{const v=Xy(w);return u.has(w.id)&&(v.bridge=!0),v}),j=[...h,...x],b=new Set(j.map(w=>w.id)),_=new Set,y=[],k=w=>{_.has(w.id)||!b.has(w.source)||!b.has(w.target)||(_.add(w.id),y.push(w))};for(const w of n)a.has(w.id)||!w.lineage||p&&!p.has(w.id)&&!m.has(w.id)||((w.lineage.derived_from??[]).forEach((v,C)=>{k(gl(w.id,v,C))}),(w.lineage.related_to??[]).forEach((v,C)=>{k(Jy(w.id,v,C))}));for(const w of o.hypothetical_nodes??[])g&&!g.has(w.id)&&!u.has(w.id)||(w.derived_from??[]).forEach((v,C)=>{k(gl(w.id,v,C))});return{nodes:j,edges:y,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(a)}}function ip(e,n,i){const o=(e??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function e0(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(g=>d(p,g)),(c.lineage.related_to??[]).forEach(g=>{s.has(g.book_id)||i.push(`${p}: related_to.book_id "${g.book_id}" 不在 books 列表中`)})}for(const c of o.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(g=>d(p,g))}return i}const rp=({graph:e,renderLink:n,className:i,style:o})=>{const{t:s,convert:a}=re();if(!e.nodes.length)return t.jsx("div",{style:{...g0,...o},className:i,children:s("lineage.emptyGraph")});const l=new Map,d=new Map;for(const h of e.edges)if(h.kind==="derive"){const x=l.get(h.target)??[];x.push(h),l.set(h.target,x)}else for(const x of[h.source,h.target]){const j=d.get(x)??[];j.push(h),d.set(x,j)}const c=new Map(e.nodes.map(h=>[h.id,h])),p=new Map,g=[];for(const h of e.nodes)if(h.group){const x=p.get(h.group)??[];x.push(h),p.set(h.group,x)}else g.push(h);const m=(h,x)=>(h.year??9999)-(x.year??9999);p.forEach(h=>h.sort(m)),g.sort(m);const u=e.groups.filter(h=>p.has(h.id));return t.jsxs("div",{className:i,style:{...n0,...o},children:[e.title&&t.jsx("div",{style:i0,children:a(e.title)}),e.description&&t.jsx("div",{style:r0,children:a(e.description)}),u.map(h=>t.jsx(fl,{label:h.label,color:h.color,nodes:p.get(h.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},h.id)),g.length>0&&t.jsx(fl,{label:s("lineage.otherGroup"),nodes:g,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},fl=({label:e,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=re();return t.jsxs("div",{style:o0,children:[t.jsx("div",{style:{...s0,borderLeftColor:n??r("widget-border")},children:d(e)}),i.map(c=>t.jsx(t0,{node:c,incoming:o.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},t0=({node:e,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=re();return t.jsxs("div",{style:{...a0,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:l0,children:[t.jsx("span",{style:c0,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:d0,children:ip(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:p0,children:[e.category&&t.jsx(Hn,{children:c(e.category)}),e.status==="lost"&&t.jsx(Hn,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Hn,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Hn,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Hn,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:u0,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:m0,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:xl,children:[t.jsx("div",{style:bl,children:d("lineage.sources")}),n.map(p=>{const g=o.get(p.source);return t.jsxs("div",{style:yl(p.confidence),children:[t.jsx("span",{style:jl,children:c(p.relation)}),t.jsx("span",{children:(g==null?void 0:g.kind)==="book"&&s?s(g.id,c(g.label)):c((g==null?void 0:g.label)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(hl,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:vl,children:["· ",c(p.evidence)]})]},p.id)})]}),i.length>0&&t.jsxs("div",{style:xl,children:[t.jsx("div",{style:bl,children:d("lineage.related")}),i.map(p=>{const g=p.source===e.id?p.target:p.source,m=o.get(g);return t.jsxs("div",{style:yl(p.confidence),children:[t.jsx("span",{style:jl,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)??g)}),t.jsx(hl,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:vl,children:["· ",c(p.evidence)]})]},p.id)})]})]})},Hn=({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})},hl=({level:e})=>{const{t:n}=re(),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},n0={fontSize:"14px",color:r("fg")},i0={fontSize:"16px",fontWeight:600,marginBottom:"8px"},r0={fontSize:"13px",color:r("muted"),marginBottom:"16px",lineHeight:1.6},o0={marginBottom:"16px"},s0={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r("fg")},a0={border:`1px solid ${r("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r("bg")},l0={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},c0={fontSize:"15px",fontWeight:600},d0={fontSize:"12px",color:r("muted")},p0={marginBottom:"6px"},u0={fontSize:"12px",color:r("muted"),margin:"2px 0"},m0={fontSize:"12px",color:r("muted"),fontStyle:"italic",margin:"4px 0"},xl={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r("widget-border")}`},bl={fontSize:"11px",color:r("muted"),marginBottom:"2px"},yl=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),jl={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r("tag-bg"),color:r("fg"),borderRadius:"3px",marginRight:"6px"},vl={fontSize:"11px",color:r("muted")},g0={padding:"20px",textAlign:"center",color:r("muted"),fontSize:"13px"},op=({selectedNodeId:e,...n})=>{const{t:i}=re(),[o,s]=f.useState("loading"),[a,l]=f.useState(null);return f.useEffect(()=>{let d=!1;return f0().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),o==="loading"?t.jsx("div",{style:wl,children:i("lineage.graphLoading")}):o==="missing"||!a?t.jsxs("div",{style:wl,children:[t.jsx("div",{children:kl(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:kl(i("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(h0,{modules:a,selectedNodeId:e,...n})};function kl(e,n){return e.split(/(\{\w+\})/).map((i,o)=>{const s=/^\{(\w+)\}$/.exec(i);return t.jsx(f.Fragment,{children:s&&s[1]in n?n[s[1]]:i},o)})}async function f0(){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 h0=({graph:e,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:p,Handle:g,Position:m,BaseEdge:u,EdgeLabelRenderer:h,getSmoothStepPath:x,dagre:j}=l,b=f.useMemo(()=>({lineage:C=>{var F,ne,je,ae;const $=((F=C.data)==null?void 0:F.stepPosition)??.85,[S,R,N]=x({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:$,borderRadius:5}),z=!!((ne=C.data)!=null&&ne.isSibling),I=z?R:C.targetX-18,P=z?N:C.targetY-12,A=(je=C.data)==null?void 0:je.labelStyle,M=(ae=C.data)==null?void 0:ae.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:C.id,path:S,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&t.jsx(h,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${I}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")}`,...M,...A},children:C.label})})]})}}),[u,h,x]),_=f.useMemo(()=>({version:C=>{const{t:$}=re(),S=C.data,R=S.kind==="hypothetical",N=S.status==="lost",z=S.isSelected,I=S.bridge,P=S.borderColor??r("muted"),A=I||R?"dashed":"solid",M=I?.5:N?.6:1;return t.jsxs("div",{style:{background:r(I?"bg-subtle":"bg"),border:`2px ${A} ${z?r("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:z?r("shadow-node-selected"):R||I?"none":r("shadow-node")},title:I?$("lineage.bridgeTitle"):void 0,children:[t.jsx(g,{type:"target",position:m.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:R||!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:ip(S.yearText,void 0,S.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:r("lost-fg"),marginTop:1},children:$("lineage.lost")}),t.jsx(g,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[g,m]),{convert:y}=re(),{rfNodes:k,rfEdges:w}=f.useMemo(()=>x0(e,j,n,a,y),[e,j,n,a,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:o,children:t.jsxs(d,{nodes:k,edges:w,nodeTypes:_,edgeTypes:b,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 x0(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 g=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const _ of e.edges)_.kind==="derive"&&(g.has(_.relation)||c.setEdge(_.source,_.target));n.layout(c);const m=e.nodes.map(_=>{const y=c.node(_.id),k=o?_.id===o:void 0,w={kind:_.kind,label:s(_.label),bookId:_.kind==="book"?_.id:void 0,yearText:s(_.year_text??y0(_)),uncertain:_.year_uncertain,category:_.category,status:_.status,borderColor:_.group?p.get(_.group):void 0,renderLink:i,isSelected:k,description:s(_.description),bridge:_.bridge};return{id:_.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:w,draggable:!1,selected:k}}),u=.78,h=.06,x=new Map;for(const _ of e.edges)_.kind==="derive"&&(x.has(_.source)||x.set(_.source,[]),x.get(_.source).push(_));const j=new Map;for(const[_,y]of x){if(y.length<=1)continue;const k=[...y].sort((v,C)=>{var R,N;const $=((R=c.node(v.target))==null?void 0:R.y)??0,S=((N=c.node(C.target))==null?void 0:N.y)??0;return $-S}),w=k.length;k.forEach((v,C)=>{const $=(C-(w-1)/2)*h;j.set(v.id,u+$)})}const b=e.edges.map(_=>b0(_,j.get(_.id),s));return{rfNodes:m,rfEdges:b}}function b0(e,n,i=o=>o??""){const o=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=j0(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 y0(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function j0(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 wl={padding:"40px 20px",textAlign:"center",color:r("muted"),fontSize:"13px",border:`1px dashed ${r("widget-border")}`,borderRadius:8,background:r("bg")},gs=({graph:e,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:g,style:m})=>{var w;const{t:u,convert:h}=re(),[x,j]=f.useState(n),b=v=>{j(v),a==null||a(v)},_=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),y=!!(d&&_.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r("muted"),textAlign:"center"},children:u("lineage.empty")});const k=l?(w=c==null?void 0:c[l])==null?void 0:w.description:void 0;return t.jsxs("div",{className:g,style:m,children:[t.jsxs("div",{style:v0,children:[t.jsx("button",{onClick:()=>b("list"),style:Rr(x==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>b("graph"),style:Rr(x==="graph"),children:u("lineage.modeGraph")}),y&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:r("muted"),marginRight:4},children:u("lineage.collectionLabel")}),_.map(([v,C])=>{const $=p==null?void 0:p[v];return t.jsxs("button",{onClick:()=>d==null?void 0:d(v),style:Rr(l===v),title:C.description?h(C.description):void 0,children:[h(C.label),$!=null?` ${$}`:""]},v)})]})]}),y&&k&&t.jsx("div",{style:{fontSize:12,color:r("muted"),marginBottom:8,padding:"4px 8px",background:r("bg-subtle"),borderRadius:4},children:h(k)}),x==="list"?t.jsx(rp,{graph:e,renderLink:i}):t.jsx(op,{graph:e,renderLink:i,height:o,selectedNodeId:s})]})},v0={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Rr=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"}),Sl=40,_l=2,k0=9,w0=new Set(["certain","consensus","probable","disputed"]);function Lr(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const sp=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:g})=>{var ue,Re,W,pe,ie,Ne,Le,Ve,Xe,ot,it;const m=Pe(),{t:u,convert:h}=re(),[x,j]=f.useState(null),[b,_]=f.useState(new Map),[y,k]=f.useState([]),[w,v]=f.useState(new Map),[C,$]=f.useState(!1),[S,R]=f.useState("flow"),[N,z]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){j(null);return}let E=!1;return n.getItem(e.work_id).then(ge=>{!E&&ge&&ge.type==="work"&&j(ge)}).catch(()=>{}),()=>{E=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){z(null);return}let E=!1;return n.getLineageGraph(e.work_id).then(ge=>{E||z(ge&&ge.nodes.length>1?ge:null)}).catch(()=>{E||z(null)}),()=>{E=!0}},[n,e.work_id]),f.useEffect(()=>{const E=e._collections||[];if(!n||E.length===0){_(new Map);return}let ge=!1;return Promise.all(E.map(ve=>{const $e=ve.id;return n.getItem($e).then(D=>[$e,D]).catch(()=>[$e,null])})).then(ve=>{if(ge)return;const $e=new Map;for(const[D,B]of ve)B&&$e.set(D,B);_($e)}),()=>{ge=!0}},[n,e._collections]);const I=f.useMemo(()=>{const E=new Set([...x?Co(x):[],...e.related_books||[]]);return E.add(e.id),[...E]},[x,e.related_books,e.id]),P=I.length-1;f.useEffect(()=>{if(!n||P<=0){k([]);return}const E=I.length<=Sl,ge=E?I:I.slice(0,8);let ve=!1;return Promise.all(ge.map($e=>$e===e.id?Promise.resolve({id:$e,title:e.title,edition:e.edition,year:zi(e)}):n.getItem($e).then(D=>{const B=D??{};return{id:$e,title:B.title,edition:B.edition,year:D?zi(B):void 0}}).catch(()=>({id:$e})))).then($e=>{if(ve)return;const D=$e.filter(B=>B.id===e.id||B.title||B.edition);E&&D.sort((B,Z)=>(B.year??1/0)-(Z.year??1/0)),k(D)}),()=>{ve=!0}},[n,I,P,e]);const A=e.lineage,M=f.useMemo(()=>[...((A==null?void 0:A.derived_from)||[]).filter(E=>E.ref_type==="book").map(E=>E.ref),...((A==null?void 0:A.related_to)||[]).map(E=>E.book_id)].filter(Boolean),[A]);f.useEffect(()=>{if(!n||M.length===0){v(new Map);return}let E=!1;return Promise.all(M.map(ge=>n.getItem(ge).then(ve=>[ge,{id:ge,title:ve==null?void 0:ve.title,edition:ve==null?void 0:ve.edition}]).catch(()=>[ge,{id:ge}]))).then(ge=>{E||v(new Map(ge))}),()=>{E=!0}},[n,M]);const F=f.useMemo(()=>Qd(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),ne=F.groups.reduce((E,ge)=>E+ge.rows.length+ge.mirrors.length,0),je=F.groups.length>0&&F.groups.every(E=>E.key==="_physical"),ae=Jn(e),Y=nc(e),xe=Yt(e,m.unit.juan),J=new Set((e._collections||[]).map(E=>Gn(E.vol).length).filter(E=>E>0)),le=E=>{var $e;const ge=($e=e.base_edition)==null?void 0:$e.find(D=>D.book_id===E&&D.name);if(ge!=null&&ge.name)return ge.name;const ve=w.get(E);return(ve==null?void 0:ve.edition)||(ve==null?void 0:ve.title)||""},we=f.useMemo(()=>{var V,U,Me,He,_e;const E=[];Y&&E.push({label:u("bookPage.fact.editionType"),value:h(Y),title:e.edition_type||(V=e.lineage)!=null&&V.category?void 0:u("bookPage.inferredFromEdition")}),(U=e.publication_info)!=null&&U.details?E.push({label:u("bookPage.fact.publication"),value:h(e.publication_info.details)}):(ae.era||ae.reign)&&E.push({label:u("bookPage.fact.era"),value:h([ae.era,ae.reign].filter(Boolean).join(" ")),title:ae.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),xe&&E.push({label:u("bookPage.fact.measure"),value:h(xe)});const ge=(e._collections||[]).flatMap(K=>Gn(K.vol));ge.length&&E.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Wi(ge,m.unit.volume),unit:m.unit.volume,n:ge.length})});const ve=(((Me=e.lineage)==null?void 0:Me.derived_from)||[]).find(K=>K.relation==="底本"&&K.ref_type==="book");ve&&le(ve.ref)&&E.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(pt,{id:ve.ref,label:h(le(ve.ref)),onNavigate:i,renderLink:o,dense:!0})});const $e=(e.base_edition||[]).filter(K=>K&&K.name);for(const K of["底本","配補","參校"]){if(K==="底本"&&ve&&le(ve.ref))continue;const ke=$e.filter(he=>he.role===K);ke.length&&E.push({label:h(K),value:ke.map((he,Ee)=>t.jsxs(f.Fragment,{children:[Ee>0&&"、",he.book_id?t.jsx(pt,{id:he.book_id,label:h(he.name),onNavigate:i,renderLink:o,dense:!0}):h(he.name)]},Ee))})}const D=(e.provenance||[]).filter(K=>K&&K.institution),B=(e.resources||[]).filter(K=>Gt(K).includes("physical"));if(D.length){E.push({label:u("bookPage.fact.holdings"),value:D.slice(0,2).map(he=>h(he.institution)).join("、")+(D.length>2?u("bookPage.andMorePlaces",{n:D.length}):"")});const K=D.filter(he=>he.call_number).slice(0,2).map(he=>`${h(he.institution)} ${he.call_number}`);K.length&&E.push({label:u("bookPage.fact.callNumber"),value:K.join(";")+(D.filter(he=>he.call_number).length>2?"…":"")});const ke=D.flatMap(he=>he.seals||[]).filter(Boolean);ke.length&&E.push({label:u("bookPage.fact.seals"),value:h(ke.join("、"))})}else B.length?E.push({label:u("bookPage.fact.holdings"),value:B.slice(0,2).map(K=>h(K.name)).join("、")+(B.length>2?u("bookPage.andMorePlaces",{n:B.length}):"")}):(He=e.current_location)!=null&&He.name&&E.push({label:u("bookPage.fact.holdings"),value:h(e.current_location.name)});const Z=e.physical_description;if(Z){const K=[[u("bookPage.fact.leafStyle"),Z.leaf_style],[u("bookPage.fact.binding"),Z.binding],[u("bookPage.fact.dimensions"),Z.dimensions],[u("bookPage.fact.condition"),Z.condition]];for(const[ke,he]of K)he&&he.trim()&&E.push({label:ke,value:h(he)})}(_e=e.page_count)!=null&&_e.description&&E.push({label:m.label.pageCount,value:h(e.page_count.description)});const me=[...Zr(e.additional_titles),...Zr(e.attached_texts)];return me.length&&E.push({label:u("bookPage.fact.aliases"),value:me.map(h).join("、")}),E},[e,h,m,u,ae,Y,xe,w,i,o]),ye=h(e.title),Q=e.edition?h(e.edition):void 0,T=((ue=e.lineage)==null?void 0:ue.year_text)||"",G=t.jsx(ei,{kind:u("bookPage.kind"),title:ye,subtitle:Q,byline:t.jsx(us,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:i,renderLink:o}),meta:(()=>{const E=[Y?h(Y):"",ae.era?h([ae.era,ae.reign].filter(Boolean).join("")):"",xe?h(xe):""].filter(Boolean);return E.length?t.jsx("span",{className:"bim-d-tags",children:E.map((ge,ve)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ve,2)}`,children:ge},ve))}):null})(),description:(Re=e.description)!=null&&Re.text?t.jsx(qt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Bo((W=e.description)==null?void 0:W.text)?6:void 0,facts:we,readAction:s,secondaryAction:s&&ne>0&&!je?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(ti,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),fe=e._collections||[],se=(a==null?void 0:a.chapters)||[],Be=h(se[0]&&Lr(se[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),Oe=u("bookPage.chapterCount",{n:se.length,unit:Be}),X=!!((pe=A==null?void 0:A.derived_from)!=null&&pe.length||(ie=A==null?void 0:A.related_to)!=null&&ie.length||(Ne=e.appendix)!=null&&Ne.length),oe=[],ze=u(je?"bookPage.sec.physical":"bookPage.sec.images");(se.length||F.text.length||l)&&oe.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:se.length?Oe:void 0}),F.groups.length&&oe.push({id:"images",label:ze,count:ne}),X&&oe.push({id:"lineage",label:u("bookPage.sec.lineage")}),fe.length&&oe.push({id:"collections",label:u("section.containedIn"),count:fe.length}),(Le=e.location_history)!=null&&Le.length&&oe.push({id:"provenance",label:u("section.locationHistory")});const We=E=>(d==null?void 0:d(E))??null,be=se[0],H=be?We(be.file):null,ce=C?se:se.slice(0,k0),de=(E,ge,ve)=>E?t.jsx("a",{className:ve,href:E.href??"#",onClick:E.onClick?$e=>{$e.metaKey||$e.ctrlKey||($e.preventDefault(),E.onClick())}:void 0,children:ge}):t.jsx("span",{className:ve,children:ge}),ee=t.jsxs(t.Fragment,{children:[(se.length>0||F.text.length>0||l)&&t.jsxs(ht,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:se.length>0?t.jsx(ft,{items:[Oe,(Ve=a==null?void 0:a.source)!=null&&Ve.name?u("bookPage.sourceBy",{src:h(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!be&&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"})]}),be&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:h(Lr(be.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:h((be.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),de(H,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),se.length>1&&t.jsx("ul",{className:"bim-d-chap",children:ce.map(E=>{const[ge,ve]=Lr(E.title);return t.jsx("li",{children:de(We(E.file),t.jsxs(t.Fragment,{children:[ge&&t.jsx("b",{children:h(ge)}),h(ve||E.file)]}))},E.file)})}),se.length>ce.length&&t.jsx(Po,{label:u("detail.expandRest",{n:se.length-ce.length,unit:Be}),onClick:()=>$(!0)}),F.text.length>0&&t.jsxs(t.Fragment,{children:[(se.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:u("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:F.text.map((E,ge)=>t.jsx(ms,{item:E,siblings:F.text,listedVolumeCounts:J},`${E.id||E.url||E.name}-${ge}`))})})]})]}),F.groups.length>0&&t.jsx(ht,{id:"images",title:ze,meta:t.jsx(ft,{items:[F.groups.length>1?u("bookPage.groupCount",{n:F.groups.length}):"",u("bookPage.placeCount",{n:ne})]}),children:t.jsx(tp,{groups:F.groups,listedVolumeCounts:J})}),X&&t.jsx(ht,{id:"lineage",title:u("bookPage.sec.lineage"),meta:(Xe=A==null?void 0:A.derived_from)!=null&&Xe.length?u("bookPage.lineageMeta"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":u("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>R("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>R("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:S==="graph"&&N?t.jsx(gs,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(E,ge)=>t.jsx(pt,{id:E,label:h(ge),onNavigate:i,renderLink:o,dense:!0})}):t.jsx(_0,{data:e,heading:Q||ye,yearText:T,refName:le,onNavigate:i,renderLink:o})}),fe.length>0&&t.jsx(ht,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:fe.map((E,ge)=>{const ve=E.id,$e=Gn(E.vol),D=b.get(ve),B=Om(D);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(pt,{id:ve,label:D?h(D.title):ve,onNavigate:i,renderLink:o,dense:!0}),$e.length>0&&t.jsx(S0,{volumes:$e,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:B>0&&u("bookPage.totalOf",{n:B,unit:m.unit.bu})})]},`${ve}-${ge}`)})})})}),(ot=e.location_history)!=null&&ot.length?t.jsx(ht,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((E,ge)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:h(E.name)}),([E.start_date,E.end_date].filter(Boolean).join("—")||E.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(ft,{items:[[E.start_date,E.end_date].filter(Boolean).join("—"),E.description?h(E.description):""]})})]},ge))})}):null,oe.length===0&&t.jsx(ht,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),Ce=y.findIndex(E=>E.id===e.id),Ue=I.length<=Sl,Ge=Ue&&Ce>=0?y.slice(Math.max(0,Ce-_l),Ce+_l+1):y.filter(E=>E.id!==e.id),nt=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:h(m.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(pt,{id:x.id,label:h(x.title),onNavigate:i,renderLink:o})}),t.jsx(ft,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(E=>`${E.dynasty?`〔${h(E.dynasty)}〕`:""}${h(E.name)}`),h(Yt(x,m.unit.juan)),x._edition_count?u("bookPage.editionCount",{n:x._edition_count}):""]}),((it=x.description)==null?void 0:it.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:h(x.description.text.replace(/[#*_>`[\]]/g,""))})]}),P>0&&Ge.length>0&&t.jsxs("div",{children:[t.jsx(dn,{id:"siblings",timeline:!0,title:Ue?u("bookPage.siblings"):m.relation.siblingVersions,meta:Ue?u("bookPage.byEra"):u("bookPage.kindCount",{n:P}),cap:Ge.length,items:Ge.map(E=>E.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:h(E.edition||E.title||E.id)}):t.jsx(pt,{id:E.id,label:h(E.edition||E.title||E.id),onNavigate:i,renderLink:o,dense:!0})),metas:Ge.map(E=>[E.year!=null?E.year<0?u("detail.bce",{n:-E.year}):String(E.year):"",E.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:Ge.findIndex(E=>E.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(pt,{id:x.id,label:u("bookPage.viewAllInWork",{n:I.length}),onNavigate:i,renderLink:o,dense:!0})})]})]}),O=e.work_id?t.jsx(Fc,{caption:m.section.belongsToWork,children:t.jsx(pt,{id:e.work_id,label:x?h(x.title):" ",onNavigate:i,renderLink:o,dense:!0})}):void 0;return t.jsx(Qn,{railTop:c,back:p,up:O,nav:oe,railLinks:g,main:ee,card:G,side:nt})};function S0({volumes:e,unit:n}){const{t:i}=re();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i("bookPage.volumeRange",{range:Wi(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 _0({data:e,heading:n,yearText:i,refName:o,onNavigate:s,renderLink:a}){var _;const{t:l,convert:d}=re(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],g=p.filter(y=>y.ref_type!=="book"),m=p.filter(y=>y.ref_type==="book"&&y.relation==="底本"),u=p.filter(y=>y.ref_type==="book"&&y.relation!=="底本"),h=(c==null?void 0:c.related_to)||[],x=p.length>0||h.length>0,j=y=>y&&w0.has(y)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${y}`)}):"",b=(y,k)=>t.jsx(pt,{id:y,label:d(k||y),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:[g.map((y,k)=>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:y.relation?d(y.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),y.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(y.evidence),j(y.confidence)]})]})},`a-${k}`)),m.map((y,k)=>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(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:b(y.ref,o(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(y.evidence),j(y.confidence)]})]})},`b-${k}`)),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)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((y,k)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:b(y.ref,o(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(y.evidence),j(y.confidence)]})]},k))})]}),h.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:h.map((y,k)=>t.jsxs("span",{className:"bim-d-lf-chip",title:y.evidence?d(y.evidence):void 0,children:[b(y.book_id,o(y.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(y.relation)})]},k))})]})]}),(_=e.appendix)==null?void 0:_.map((y,k)=>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(y.title)]}),t.jsx(qt,{text:y.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${k}`)),(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 Dn=16,$0=200,C0=16,ap=({data:e,catalog:n,transport:i,onNavigate:o,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var Ce,Ue,Ge,nt,O,ue,Re;const{t:p,convert:g,messages:m}=re(),[u,h]=f.useState(""),[x,j]=f.useState(!1),[b,_]=f.useState(null),[y,k]=f.useState(""),[w,v]=f.useState(!1),C=f.useMemo(()=>tc(e,n),[e,n]),$=f.useMemo(()=>ec(e),[e]),[S,R]=f.useState(new Map),N=!!i&&C.rows.length>0&&C.rows.length<=$0,z=N&&(C.rows.length<=Dn||w),I=z&&C.rows.every(W=>!W.id||S.has(W.id)),P=W=>{var pe;return co(W?(pe=S.get(W))==null?void 0:pe.l1:void 0)},A=f.useMemo(()=>{const W=u.trim(),pe=W?g(W):"";return C.rows.filter(ie=>{var Le,Ve;if(y&&co(ie.id?(Le=S.get(ie.id))==null?void 0:Le.l1:void 0)!==y)return!1;if(!pe)return!0;const Ne=ie.id&&((Ve=S.get(ie.id))==null?void 0:Ve.title)||ie.title;return g(Ne).includes(pe)||(ie.subItems||[]).some(Xe=>g(Xe).includes(pe))})},[C.rows,u,y,S,g]),M=x?A:A.slice(0,Dn),F=f.useMemo(()=>(z?C.rows:M).filter(W=>W.id&&!S.has(W.id)).map(W=>W.id),[z,C.rows,M,S]);f.useEffect(()=>{if(!i||F.length===0)return;let W=!1;const pe=F.slice(0,C0);return Xi(pe,Ki,ie=>i.getItem(ie).then(Ne=>{var Xe,ot;const Le=Ne??{},Ve={title:Le.title,edition:Le.edition,authors:Le.authors,measure:Ne?Yt(Ne,m.unit.juan):void 0,versionCount:Le._edition_count??((Xe=Le._books)==null?void 0:Xe.length),l1:((ot=zo(Le))==null?void 0:ot.l1)||void 0};return[ie,Ve]}).catch(()=>[ie,{}]),()=>W).then(ie=>{W||R(Ne=>{const Le=new Map(Ne);for(const[Ve,Xe]of ie)Le.set(Ve,Xe);return Le})}),()=>{W=!0}},[i,F,m.unit.juan]);const ne=(Ce=(e.contained_in||[])[0])==null?void 0:Ce.id;f.useEffect(()=>{if(!ne){_(null);return}if(_({id:ne}),!i)return;let W=!1;return i.getItem(ne).then(pe=>{W||_({id:ne,title:pe==null?void 0:pe.title})}).catch(()=>{}),()=>{W=!0}},[i,ne]);const je=f.useMemo(()=>Qd(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),ae=je.text.length+je.groups.reduce((W,pe)=>W+pe.rows.length+pe.mirrors.length,0),Y=$.works,xe=new Set(C.rows.map(W=>W.id).filter(Boolean)),J=Y.length>0&&!Y.every(W=>xe.has(W.id)),le=(()=>{const W=C.rows.map(pe=>pe.edition).filter(Boolean);return W.length>1&&new Set(W).size===1})(),we=C.rows.some(W=>W.volumes.length>0||W.expected!=null),ye=$.total,Q=$.truncated?ye:C.rows.length,T=Yt(e,m.unit.juan),G=e.count,fe=W=>typeof W=="number"&&Number.isFinite(W)?W:null,se=fe(G==null?void 0:G.juan)??fe((Ue=e.juan_count)==null?void 0:Ue.number),Be=fe(G==null?void 0:G.ce)??(C.totalVolumes||null),Oe=[{value:Q,label:p("collectionPage.stat.titles")},{value:se??0,label:m.unit.juan},{value:Be??0,label:m.unit.volume}],X=f.useMemo(()=>{var ie,Ne;const W=[];if((ie=e.publication_info)!=null&&ie.details&&W.push({label:p("collectionPage.fact.publication"),value:g(e.publication_info.details)}),ye&&(ye!==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");W.push({label:Le,value:`${ye} ${m.unit.bu}`,title:p("collectionPage.memberNote")})}const pe=[fe(G==null?void 0:G.zhong)!=null?p("collectionPage.nZhong",{n:G.zhong}):"",fe(G==null?void 0:G.han)!=null?p("collectionPage.nHan",{n:G.han}):""].filter(Boolean);return pe.length&&W.push({label:p("collectionPage.fact.expected"),value:pe.join(" ")}),se==null&&T&&W.push({label:p("collectionPage.fact.measure"),value:g(T),title:(Ne=e.juan_count)!=null&&Ne.description?g(e.juan_count.description):void 0}),W},[e,ye,$.truncated,C.rows.length,se,T,G,g,p,m]),oe=f.useMemo(()=>{if(!I)return[];const W=new Map;for(const ie of C.rows){const Ne=P(ie.id);Ne&&W.set(Ne,(W.get(Ne)??0)+1)}const pe=Kn.filter(ie=>(W.get(ie.key)??0)>0);return pe.length<2?[]:[{key:"",label:`${m.catalog.all} ${Q}`},...pe.map(ie=>({key:ie.key,label:`${ie.label} ${W.get(ie.key)}`}))]},[I,C.rows,S,m]),ze=f.useMemo(()=>{if(!I||!C.rows.some(Ne=>Ne.volumes.length>0))return null;const W=[],pe=C.rows.filter(Ne=>Ne.volumes.length>0).map(Ne=>({k:P(Ne.id)??"",from:Math.min(...Ne.volumes),to:Math.max(...Ne.volumes)})).sort((Ne,Le)=>Ne.from-Le.from);for(const Ne of pe){const Le=Ne.to-Ne.from+1,Ve=W[W.length-1];Ve&&Ve.key===Ne.k?(Ve.to=Math.max(Ve.to,Ne.to),Ve.n+=Le):W.push({key:Ne.k,from:Ne.from,to:Ne.to,n:Le})}const ie=pe.reduce((Ne,Le)=>Math.max(Ne,Le.to),0);return W.length>1&&W.some(Ne=>Ne.key)?{segs:W,last:ie}:null},[I,C.rows,S]),We=(Ge=e.description)==null?void 0:Ge.text,be=t.jsx(ei,{kind:p("collectionPage.kind"),title:g(e.title),byline:t.jsx(us,{authors:e.authors,onNavigate:o,renderLink:s}),meta:t.jsx(ft,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(nt=e.publication_info)!=null&&nt.year?g(e.publication_info.year):""]}),description:We||(O=e.history)!=null&&O.length?t.jsxs(t.Fragment,{children:[We&&t.jsx(qt,{text:We,style:{fontSize:15,lineHeight:1.85}}),(ue=e.history)!=null&&ue.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((W,pe)=>t.jsx("li",{children:g(W)},pe))}):null]}):void 0,clampDescription:Bo(We)||(((Re=e.history)==null?void 0:Re.length)??0)>2?6:void 0,stats:Oe,facts:X,foot:t.jsx(ti,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ze&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:p("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":p("collectionPage.dist.head"),children:ze.segs.map((W,pe)=>{const ie=Kn.find(Ne=>Ne.key===W.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!ie,title:ie?p("collectionPage.dist.segTitle",{section:g(ie.label),from:W.from,to:W.to}):void 0,"aria-label":ie?p("collectionPage.dist.only",{section:g(ie.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!ie&&y===W.key,style:{flexGrow:W.n,background:r(ie?ie.token:"rule")},onClick:()=>{ie&&(k(y===W.key?"":W.key),j(!1))}},pe)})}),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:ze.last})})]})]})}),H=[];C.rows.length&&H.push({id:"titles",label:p("collectionPage.sec.titles"),count:Q}),ae&&H.push({id:"resources",label:p("collectionPage.sec.resources"),count:ae}),J&&H.push({id:"works",label:m.section.containedWorks,count:Y.length});const ce=t.jsxs(t.Fragment,{children:[C.rows.length>0&&t.jsxs(ht,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(ft,{items:[`${Q} ${m.unit.items}`,C.totalVolumes?p("collectionPage.totalVolumes",{n:C.totalVolumes,unit:m.unit.volume}):"",A.length!==Q?p("collectionPage.currentN",{n:A.length,unit:m.unit.items}):""]}),action:a,children:[(C.rows.length>Dn||oe.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[oe.length>0&&t.jsx(Vi,{items:oe,value:y,onChange:W=>{k(W),j(!1)}}),N&&C.rows.length>Dn&&!I&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:w,onClick:()=>v(!0),title:p("collectionPage.loadAllTitle",{n:C.rows.length,unit:m.unit.items}),children:p(w?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),C.rows.length>Dn&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:W=>{h(W.target.value),j(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Gi(A.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[we&&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:M.map((W,pe)=>{var it;const ie=W.id?S.get(W.id):void 0,Ne=ie!=null&&ie.title&&W.title===W.id?ie.title:W.title,Le=((ie==null?void 0:ie.authors)||[]).find(E=>E&&E.name),Ve=[Le?`${Le.dynasty?`〔${g(Le.dynasty)}〕`:""}${g(Le.name)}${Le.role?` ${g(Le.role)}`:""}`:"",ie!=null&&ie.measure?g(ie.measure):"",(it=W.subItems)!=null&&it.length?W.subItems.map(E=>g(E)).join("、"):"",(ie!=null&&ie.edition||W.edition)&&!le?g((ie==null?void 0:ie.edition)||W.edition||""):""].filter(Boolean),Xe=Kn.find(E=>E.key===P(W.id)),ot=W.volumes.length>0?p("collectionPage.volumeRange",{range:Wi(W.volumes,m.unit.volume),unit:m.unit.volume}):W.expected!=null?`${W.found??0}/${W.expected} ${m.unit.volume}`:"";return t.jsxs("tr",{children:[we&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ot?"":" bim-d-zt-blank"}`,children:[Xe&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r(Xe.token)}}),ot||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[W.id?t.jsx(pt,{id:W.id,label:g(Ne),onNavigate:o,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:g(Ne)}),Ve.length>0?t.jsx(ft,{items:Ve}):W.id&&!ie&&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${ie!=null&&ie.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ie!=null&&ie.versionCount?p("collectionPage.nZhong",{n:ie.versionCount}):""})]},`${W.id??W.title}-${pe}`)})})]}),M.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:A.length,shown:M.length,unit:m.unit.items,onClick:()=>j(!0)})]}),ae>0&&t.jsxs(ht,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:ae}),children:[je.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[je.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:je.text.map((W,pe)=>t.jsx(ms,{item:W,siblings:je.text},`${W.id||W.url||W.name}-${pe}`))})})]}),t.jsx(tp,{groups:je.groups})]}),C.rows.length===0&&ae===0&&t.jsx(ht,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),de=J?t.jsx(dn,{id:"works",title:m.section.containedWorks,meta:p("collectionPage.nZhong",{n:Y.length}),cap:12,items:Y.map(W=>t.jsx(pt,{id:W.id,label:g(W.title),onNavigate:o,renderLink:s,dense:!0}))}):null,ee=b?t.jsx(Fc,{caption:p("collectionPage.parent"),children:t.jsx(pt,{id:b.id,label:g(b.title||b.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return t.jsx(Qn,{railTop:l,back:d,up:ee,nav:H,railLinks:c,main:ce,card:be,side:de})},z0=8;function lp(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(n=>n==="..")?null:e}function N0(e){return(e||[]).filter(n=>{var i,o;return lp(n==null?void 0:n.file)&&((i=n.credit)==null?void 0:i.trim())&&((o=n.license)==null?void 0:o.trim())}).slice(0,z0)}function T0({images:e,assetBase:n,name:i}){const{t:o,convert:s}=re(),[a,l]=f.useState(0),[d,c]=f.useState(!1),p=n?N0(e):[];if(!n||d||p.length===0)return null;const g=n.endsWith("/")?n:n+"/",m=p[Math.min(a,p.length-1)],u=m.width&&m.height&&m.width>0&&m.height>0?`${m.width} / ${m.height}`:void 0,h=x=>g+lp(x.file).split("/").map(encodeURIComponent).join("/");return t.jsxs("figure",{className:"bim-d-seal bim-d-ui",children:[t.jsx("img",{className:"bim-d-seal-main",src:h(m),alt:o("entityPage.sealAlt",{name:i})+(p.length>1?` ${a+1}`:""),style:u?{"--seal-ar":u}:void 0,width:m.width,height:m.height,decoding:"async",fetchPriority:"high",onError:()=>c(!0)},m.file),p.length>1&&t.jsx("div",{className:"bim-d-seal-thumbs",children:p.map((x,j)=>t.jsx("button",{type:"button","aria-pressed":j===a,"aria-label":`${o("entityPage.sealAlt",{name:i})} ${j+1}`,onClick:()=>l(j),children:t.jsx("img",{src:h(x),alt:"",loading:"lazy",decoding:"async"})},x.file))}),t.jsxs("figcaption",{children:[o("entityPage.imgCredit",{credit:s(m.credit)})," · ",o("entityPage.imgLicense",{license:s(m.license)}),m.source_url&&/^https?:\/\//i.test(m.source_url)&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:m.source_url,target:"_blank",rel:"noopener noreferrer nofollow",children:o("entityPage.imgSource")})]}),m.note&&t.jsxs(t.Fragment,{children:[" · ",s(m.note)]})]})]})}const I0=16,Ar=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function $l(e){if(!e)return Ar.length;const n=Ar.indexOf(e);return n===-1?Ar.length:n}function E0(e,n,i){if(n)return e[n]??i(n)}function R0(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const L0={秦:[-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]},cp=({data:e,transport:n,onNavigate:i,renderLink:o,railTop:s,back:a,railLinks:l,assetBase:d})=>{var ee,Ce,Ue,Ge,nt;const{t:c,convert:p,messages:g}=re(),m=O=>R0(O,c),[u,h]=f.useState("全部"),[x,j]=f.useState(!1),[b,_]=f.useState("default"),[y,k]=f.useState(new Map),w=f.useMemo(()=>e._works||[],[e._works]),v=f.useMemo(()=>w.map(O=>{const ue=y.get(O.work_id);return{id:O.work_id,title:(ue==null?void 0:ue.title)??O.title??O.work_id,role:O.role||"",cls:_o(O.role),versionCount:ue==null?void 0:ue.versionCount,section:ue==null?void 0:ue.cls,l1:ue==null?void 0:ue.l1,measure:ue==null?void 0:ue.measure,hasImage:ue==null?void 0:ue.hasImage,loaded:!!(ue!=null&&ue.loaded)}}),[w,y]),C=f.useMemo(()=>Ql(w.map(O=>O.role),c("detail.roleAll")),[w,c]),$=f.useMemo(()=>{const O=u==="全部"?v:v.filter(ue=>ue.cls===u);return b==="versions"?[...O].sort((ue,Re)=>(Re.versionCount??-1)-(ue.versionCount??-1)):O},[v,u,b]),S=x?$:$.slice(0,I0),R=f.useMemo(()=>S.filter(O=>!y.has(O.id)).map(O=>O.id),[S,y]);f.useEffect(()=>{if(!n||R.length===0)return;let O=!1;return Xi(R,Ki,ue=>n.getItem(ue).then(Re=>{var Le;const W=Re??{},pe=W._edition_count??((Le=W._books)==null?void 0:Le.length)??0,ie=zo(W),Ne=[ie==null?void 0:ie.l1,ie==null?void 0:ie.l2].filter(Boolean).join(" ");return[ue,{id:ue,title:W.title,versionCount:pe,loaded:!0,cls:Ne||void 0,l1:(ie==null?void 0:ie.l1)||void 0,measure:Re&&Yt(Re,g.unit.juan)||void 0,hasImage:!!W._has_image}]}).catch(()=>[ue,{id:ue,loaded:!0}]),()=>O).then(ue=>{O||k(Re=>{const W=new Map(Re);for(const[pe,ie]of ue)W.set(pe,ie);return W})}),()=>{O=!0}},[n,R,g.unit.juan]);const N=f.useMemo(()=>{const O=new Map;for(const ue of e.alt_names||[]){const Re=ue.type||g.section.aliases;O.has(Re)||O.set(Re,[]),O.get(Re).push(ue.name)}return[...O.entries()].sort((ue,Re)=>$l(ue[0])-$l(Re[0])).map(([ue,Re])=>({label:ue,names:Re}))},[e.alt_names,g]),z=((ee=e.dates)==null?void 0:ee.birth)??void 0,I=((Ce=e.dates)==null?void 0:Ce.death)??void 0,P=(Ue=e.dates)==null?void 0:Ue.floruit,A=z!=null||I!=null?`${m(z)||"?"}—${m(I)||"?"}`:Array.isArray(P)&&P.length===2&&P.every(O=>Number.isFinite(O))?c("entityPage.floruit",{from:m(P[0]),to:m(P[1])}):"",M=new Set(["本名","字","號","号"]),F=N.filter(O=>M.has(O.label)),ne=N.filter(O=>!M.has(O.label)),je=ne.reduce((O,ue)=>O+ue.names.length,0),ae=f.useMemo(()=>{const O=[];for(const Re of F)O.push({label:Re.label,value:Re.names.map(W=>p(W)).join("、")});const ue=w.length;return ue&&O.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:ue})}),O},[w,F,p,c]),Y=O=>{var ue;return(ue=N.find(Re=>O.includes(Re.label)))==null?void 0:ue.names[0]},xe=Y(["字"]),J=Y(["號","号"]),le=[xe?c("entityPage.zi",{name:p(xe)}):"",J?c("entityPage.hao",{name:p(J)}):""].filter(Boolean).join(","),we=e.native_place,ye=e.dynasty?L0[e.dynasty]:void 0,Q=(()=>{if(!ye||z==null||I==null||I<z)return null;const[O,ue]=ye,Re=Math.max(z,O),W=Math.min(I,ue);if(W<=Re)return null;const pe=ue-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":c("entityPage.lifeAria",{birth:m(z),death:m(I),years:I-z+1}),children:t.jsx("i",{style:{left:`${(Re-O)/pe*100}%`,width:`${(W-Re)/pe*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${m(O)} ${p(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:I-z+1})}),t.jsx("span",{children:m(ue)})]})]})})(),T=f.useMemo(()=>{if(!n||v.length===0||v.some(Re=>!Re.loaded))return null;const O=new Map;for(const Re of v){const W=co(Re.l1);W&&O.set(W,(O.get(W)??0)+1)}const ue=Kn.map(Re=>({...Re,n:O.get(Re.key)??0})).filter(Re=>Re.n>0);return ue.length?ue:null},[v,n]),G=t.jsxs(ei,{kind:E0(g.entityPage.subtype,e.subtype,p),title:p(e.primary_name||e.title),subtitle:le||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(ft,{items:[e.dynasty?p(e.dynasty):"",A,we?c("entityPage.nativePlace",{place:p(we)}):""]}),Q,t.jsx(T0,{images:e.images,assetBase:d,name:p(e.primary_name||e.title)})]}),description:(Ge=e.description)!=null&&Ge.text?t.jsx(qt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Bo((nt=e.description)==null?void 0:nt.text)?6:void 0,facts:ae,foot:t.jsx(ti,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[je>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:je})}),t.jsx("dl",{children:ne.map(O=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:p(O.label)}),t.jsx("dd",{children:O.names.map(ue=>p(ue)).join("、")})]},O.label))})]}),T&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:T.map(O=>t.jsx("i",{style:{flexGrow:O.n,background:r(O.token)}},O.key))}),t.jsx("div",{className:"bim-d-dist-key",children:T.map(O=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r(O.token)}}),p(O.label)," ",O.n]},O.key))})]})]}),fe=f.useMemo(()=>v.filter(O=>O.loaded&&(O.versionCount??0)>0).sort((O,ue)=>(ue.versionCount??0)-(O.versionCount??0)).slice(0,3),[v]),se=!!n&&v.length>=3&&S.some(O=>!O.loaded),Be=u==="全部"&&(se||fe.length>=2),Oe=e.external_ids||{},X=[];Oe.cbdb_id!=null&&X.push({label:"CBDB",id:String(Oe.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${Oe.cbdb_id}`,note:Oe.cbdb_match==="auto"?c("entityPage.autoMatch"):void 0});const oe=Oe.wikidata_id;oe&&X.push({label:"Wikidata",id:oe,href:`https://www.wikidata.org/wiki/${oe}`});const ze=Oe.viaf_id;ze&&X.push({label:"VIAF",id:ze,href:`https://viaf.org/viaf/${ze}`});const We=C.map(O=>({key:O.cls,label:`${O.label} ${O.count}`})),be=[...Be&&!se?[{id:"featured",label:c("entityPage.sec.featured"),count:fe.length}]:[],...v.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:v.length}]:[],...X.length?[{id:"external",label:c("entityPage.sec.external"),count:X.length}]:[]],H=Be?t.jsxs(ht,{id:"featured",title:c("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":se||void 0,children:[se&&[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)),!se&&fe.map(O=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(pt,{id:O.id,label:p(O.title),onNavigate:i,renderLink:o,dense:!0})}),t.jsx(ft,{items:[O.section?p(O.section):"",O.measure?p(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:c("entityPage.versionsUnit")}),O.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},O.id))]})]}):null,ce=v.length===0?t.jsx(ht,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}):t.jsxs(t.Fragment,{children:[H,t.jsxs(ht,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(ft,{items:[c("entityPage.total",{n:v.length}),$.length!==v.length?c("entityPage.current",{n:$.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[We.length>1&&t.jsx(Vi,{items:We,value:u,onChange:O=>{h(O),j(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":b==="versions",onClick:()=>{b==="default"&&j(!0),_(O=>O==="default"?"versions":"default")},children:c(b==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Gi($.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("entityPage.col.work")}),t.jsx("th",{children:c("entityPage.col.section")}),t.jsx("th",{children:c("entityPage.col.role")}),t.jsx("th",{children:c("entityPage.col.versions")}),t.jsx("th",{"aria-label":c("entityPage.col.image")})]})}),t.jsx("tbody",{children:S.map(O=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(pt,{id:O.id,label:p(O.title),onNavigate:i,renderLink:o,dense:!0}),O.measure?t.jsx(ft,{items:[p(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?p(O.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${O.role?"":" bim-d-zt-blank"}`,children:O.role?p(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?c("entityPage.nZhong",{n:O.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("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:c("entityPage.hasImage")})})]},O.id))})]}),S.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!x&&t.jsx(Mo,{total:$.length,shown:S.length,unit:c("entityPage.moreUnit"),onClick:()=>j(!0)})]})]}),de=X.length>0?t.jsx(dn,{id:"external",title:c("entityPage.sec.external"),items:X.map(O=>t.jsxs("a",{href:O.href,target:"_blank",rel:"noopener noreferrer",children:[O.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:X.map(O=>O.id),foot:Oe.cbdb_id!=null&&Oe.cbdb_match==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Qn,{railTop:s,back:a,nav:be,railLinks:l,main:ce,card:G,side:de})},fs="(max-width: 719px)",A0=`${fs}, (pointer: coarse)`,dp=`
1445
+ ${H??""}`,[Rn,_s]=f.useState({key:In,data:U,started:!!U});if(Rn.key!==In)_s({key:In,data:U,started:!1});else if(U!==Rn.data&&(_s({key:In,data:U,started:!!U}),U)){const L=U.pages??[];(!Rn.started||!L.some(ne=>ne.page===tt))&&xt(Tt(U))}f.useEffect(()=>{Ie(new Set),Ye.set(null)},[H,T,Ye]);const or=Rn.key===In&&Rn.started,$s=!!ce&&ro(ce.headings).length===0,Cs=f.useMemo(()=>$s&&or&&U?Td(U.pages,U.punctuations):[],[$s,or,U]),sr=f.useCallback(L=>{const ne=ro(L.headings);return ne.length>0?ne:L.file===H?Cs:[]},[H,Cs]),lu=f.useCallback(L=>{if(Ie(new Set(L)),L.length>0){const ne=L[0],Te=parseInt(ne.split(":")[0],10);isNaN(Te)||xt(Te)}},[]),Ot=f.useMemo(()=>{const L=new Map;for(const ne of(U==null?void 0:U.pages)??[])L.set(ne.page,ne);return L},[U]),Ln=lt(U),si=f.useCallback(L=>{var rt;const ne=V.images;if(!ne||ne.length===0)return;const Te=(rt=Ot.get(L))==null?void 0:rt.seq;return(Te?ne.find(Ze=>Ze.seq===Te):void 0)??ne.find(Ze=>Ze.pageNo===L)??ne[L-1]},[V.images,Ot]),zs=K>1.5,ai=f.useCallback((L,ne=!1)=>{const Te=si(L);return Te?L===Ln||ne?Te.hiresUrl??Te.url:Te.url:L===Ln?(U==null?void 0:U.imageUrl)??"":""},[si,U,Ln]),cu=f.useMemo(()=>ai(tt,zs),[ai,tt,zs]),Wt=f.useMemo(()=>[...Ot.keys()].sort((L,ne)=>L-ne),[Ot]),nn=f.useRef(tt);nn.current=tt;const ar=f.useRef(0),lr=f.useRef({page:null,timer:null}),du=f.useCallback(L=>{const ne=lr.current;L!==ne.page&&(ne.timer&&(clearTimeout(ne.timer),ne.timer=null),ne.page=null,!(L===nn.current||Date.now()<ar.current)&&(ne.page=L,ne.timer=setTimeout(()=>{ne.timer=null,ne.page=null,!(Date.now()<ar.current||nn.current===L)&&(nn.current=L,xt(L))},Jx)))},[]);f.useEffect(()=>()=>{lr.current.timer&&clearTimeout(lr.current.timer)},[]);const li=f.useCallback(L=>{var ne;nn.current===L||!Ot.has(L)||(ar.current=Date.now()+1e3,nn.current=L,xt(L),(ne=Ot.get(L))!=null&&ne.columns.some(Te=>Te.chars.length>0)&&at(Te=>({page:L,nonce:((Te==null?void 0:Te.nonce)??0)+1})))},[Ot]),An=f.useCallback(L=>{const ne=nn.current,Te=Wt.indexOf(ne),rt=Wt[Te<0?0:Te+L];rt===void 0||rt===ne||li(rt)},[Wt,li]),Ns=f.useCallback(L=>{if(!L.trim().match(/^\d+$/)||Wt.length===0)return null;const Te=parseInt(L.trim(),10),rt=Number.isFinite(Te)?Te:Number.MAX_SAFE_INTEGER;return Wt.reduce((Ze,Et)=>Math.abs(Et-rt)<Math.abs(Ze-rt)?Et:Ze,Wt[0])},[Wt]),[cr,dr]=f.useState(null),ci=f.useRef(null),pu=f.useCallback(L=>{ci.current=L,dr(L)},[]),Ts=f.useCallback(()=>{const L=ci.current;if(ci.current=null,dr(null),L===null)return;const ne=Ns(L);ne!==null&&li(ne)},[Ns,li]),pr=Wt.indexOf(tt),uu=f.useCallback(L=>{if(L.altKey||L.ctrlKey||L.metaKey)return;const ne=L.target.tagName;ne==="INPUT"||ne==="TEXTAREA"||ne==="SELECT"||(L.key==="ArrowLeft"||L.key==="PageUp"?(L.preventDefault(),An(-1)):(L.key==="ArrowRight"||L.key==="PageDown")&&(L.preventDefault(),An(1)))},[An]),Es=f.useRef(null);f.useEffect(()=>{if(!U)return;const L=Es.current;if(!(!L||L.offsetWidth===0))for(const ne of[1,-1]){const Te=ai(tt+ne);Te&&eo(Te)}},[U,tt,ai]);const Is=f.useMemo(()=>{var Us;if(!U)return null;if(tt===Ln)return U;const L=Ot.get(tt);if(L&&L.width>0&&L.height>0)return{page_id:`p:${tt}`,title:`第${tt}葉`,image_size:[L.width,L.height],total_warped_w:L.width,columns:[{col:1,warped_w:L.width,warped_h:L.height,offset_x:0,strips:[],chars:L.columns.flatMap(Je=>Je.chars).map(Je=>({id:Je.id,char:Je.char,slot:Je.slot,pos:Je.pos,sub:Je.sub,bbox_col:Je.bbox??[0,0,0,0]}))}],...L.columns.some(Je=>Je.kind==="figure"&&Je.figBox)?{figBlocks:L.columns.filter(Je=>Je.kind==="figure"&&Je.figBox).map(Je=>({id:Je.fig,box:Je.figBox}))}:{}};const ne=(Us=U.pages)==null?void 0:Us.find(Je=>Je.page===tt),[Te,rt]=U.image_size||[2386,3082];if(!(Te>0&&rt>0))return null;const Ze=si(tt),Et=(Ze==null?void 0:Ze.width)??Te,hr=(Ze==null?void 0:Ze.height)??rt,Fs=Et/Te,Hs=hr/rt,Ds=new Map;for(const Je of U.columns){const St=(Je.strips||[]).flatMap(gi=>gi.srcQuad.map(fi=>fi[0]));if(St.length===0)continue;const Ft=Je.top_y??0,xr=Je.bottom_y??Ft+Je.warped_h;Ds.set(Je.col,{x0:Math.min(...St),x1:Math.max(...St),top:Ft,slotH:(xr-Ft)/21})}return{page_id:`p:${tt}`,title:`第${tt}葉`,image_size:[Et,hr],total_warped_w:Et,columns:ne?ne.columns.map(Je=>{const St=Ds.get(Je.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Je.col,warped_w:Et,warped_h:hr,offset_x:0,strips:[],chars:Je.chars.map(Ft=>{const xr=Ft.slot??Ft.pos??0,gi=(St.top+(xr-1)*St.slotH)*Hs,fi=(St.x0+St.x1)/2,[wu,Su]=Ft.sub==="a"?[fi,St.x1]:Ft.sub==="b"?[St.x0,fi]:[St.x0,St.x1];return{...Ft,bbox_col:[wu*Fs,gi,Su*Fs,gi+St.slotH*Hs]}})}}):[]}},[U,tt,Ln,Ot,si]),{entryTitle:di,authors:Rs}=sb(n,i,c===void 0),[Ls,ur]=f.useState("text");f.useEffect(()=>{ur("text")},[H,T]);const mu=f.useMemo(()=>ye?nb(ye,B,Ka(je,ye),I,it,sr):[],[ye,B,je,I,it,sr]);if(q==="loading")return t.jsx(Ya,{className:C,style:$,title:c??di,label:S("reader.loading")});if(q==="missing"||!M||!je)return t.jsx("div",{className:C,style:{...$,...Ga},children:S("reader.noText")});if(oe==="failed")return t.jsx("div",{className:C,style:{...$,...Ga},children:S("reader.tocFailed")});if(!ye)return t.jsx(Ya,{className:C,style:$,title:c??di,label:S("reader.tocLoading")});const gn=Ka(je,ye),gu=mu,As=Ge&&H&&Ge.chapter===H?ls(H,Ge.anchor):null,fu=As&&ce&&sr(ce).some(L=>L.anchor===Ge.anchor)?As:H??null,mr=M.versions.map(L=>({key:L.key,label:Ee.textVersionLabel(L),optionLabel:I(Ee.textVersionLabel(L)),sourceName:Xa(L)?S("reader.originalSource"):L.source_name?I(L.source_name):void 0,license:L.license??void 0,sourceUrl:L.source_url??void 0,primary:L.key===ee})),wt=eb((Ws=ye.source)==null?void 0:Ws.upstream),pi=(typeof c=="string"?I(c):c)??(ye.title?I(ye.title):di?I(di):void 0),Ms=je.edition_label?I(je.edition_label):void 0,gr=pi?t.jsx("a",{href:P(n),title:S("reader.viewEntry"),onClick:l?L=>{L.metaKey||L.ctrlKey||(L.preventDefault(),l(n))}:void 0,children:pi}):void 0,hu=gr&&Ms?t.jsxs(t.Fragment,{children:[gr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Ms]})]}):gr,xu=Rs.length>0?I(Rs.slice(0,2).map(L=>`${L.dynasty?`〔${L.dynasty}〕`:""}${L.name}${` ${L.role||S("reader.defaultRole")}`}`).join("、")):void 0,fr=ce?Rd(ce,gn,I,it):void 0,rn=it&&!!(pe!=null&&pe.json),on=(pe==null?void 0:pe.json)??null,fn=(pe==null?void 0:pe.md)??null,Ps=rn&&!$e&&bd(on.sections),bu=Ps&&!(fn&&X.readingMode==="paragraph"&&Ei(fn)),yu=rn&&Ps?t.jsx(ax,{juan:on,view:Ls,onView:ur,textHasEntries:bu}):void 0,ju=!0,ui=fn?fn.replace(/^##\s+[^\n]+\n+/,""):null,mi=Xa(je),Kt=mi?S("reader.originalSource"):je.source_name?I(je.source_name):void 0,vu=(typeof p=="string"?I(p):p)??(mi?void 0:Kt??I(Ee.textVersionLabel(je))),ku=(U==null?void 0:U.hasNorm)===!0;return t.jsxs(Rc,{className:C,style:$,title:hu,subtitle:vu,byline:xu,current:fr,pagerUnit:gn,rail:yu,revisedAt:j,backHref:b,backLabel:_,onReportError:x?L=>x({...L,bookTitle:typeof pi=="string"?pi:void 0,entryId:n}):void 0,workLinkToggle:rn&&!$e&&!!l&&!!(on!=null&&on.sections.some(L=>L.work_id)),toc:gu,tocCaption:S("reader.tocCaption",{n:ye.chapters.length,unit:I(gn)}),tocHeader:it&&ye.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:$e?S("reader.searchChaptersPlaceholder"):S("reader.searchUnitPlaceholder",{unit:I(gn)}),"aria-label":$e?S("reader.searchChapters"):S("reader.searchUnit",{unit:I(gn)}),value:R,onChange:L=>ge(L.target.value)}):void 0,activeKey:H??null,tocActiveKey:fu,onSelect:Re,images:oo(ce)&&Me&&!U?null:V.images,renderImageOverlay:g,imagePanel:U?"open":u,isWarpMode:!!U,customImagePanel:U&&Is?t.jsxs("div",{ref:Es,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:uu,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:[he.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ie(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",he.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:K<=1,onClick:()=>{var L;return(L=qe.current)==null?void 0:L.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(K*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:K>=6,onClick:()=>{var L;return(L=qe.current)==null?void 0:L.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:K===1,onClick:()=>{var L;return(L=qe.current)==null?void 0:L.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(Yx,{ref:qe,resetKey:tt,onScaleChange:Ae,style:{flex:1,minHeight:0},children:t.jsx(Ma,{store:Ye,children:L=>t.jsx(ts,{imageUrl:cu,pageData:Is,selectedCharIds:he,hoveredCharId:L,preserveMargins:dt,renderScale:K,selectedFigBlock:Se,onFigBlockClick:ne=>Fe(ne),onCharClick:ne=>{Fe(null),Ie(rt=>{const Ze=new Set(rt);return Ze.has(ne)?Ze.delete(ne):(Ze.clear(),Ze.add(ne)),Ze});const Te=document.querySelector(`[data-char-id="${ne}"]`);Te&&Te.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Ye.set})})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":S("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:pr<=0,onClick:()=>An(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":tt,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":S("reader.facsimilePageInput"),size:Math.max(2,String(cr??tt).length),value:cr??String(tt),onFocus:L=>L.currentTarget.select(),onChange:L=>pu(L.target.value),onKeyDown:L=>{L.key==="Enter"?(L.preventDefault(),Ts()):L.key==="Escape"&&(ci.current=null,dr(null)),L.stopPropagation()},onBlur:Ts,style:{width:`${Math.max(2,String(cr??tt).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:pr<0||pr>=Wt.length-1,onClick:()=>An(1),children:"›"})]})]}):void 0,settingsAnnotate:U?t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${et?"bim-rd-on":""}`,"aria-pressed":et,title:"切换外挂现代断句标点",onClick:()=>Ke(L=>!L),children:et?"标点":"无标点"}):void 0,prefs:X,onPrefsChange:E,versions:mr.length>1?mr:void 0,currentVersionKey:mr.length>1?je.key:void 0,onVersionChange:te,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Ei(fn),allowVertical:h,origScriptAvailable:ku,contentLoading:Xe,children:[(Xe||Me&&!U&&!rn&&ui==null)&&t.jsx(un,{}),!Xe&&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:ce!=null&&ce.title?I(ce.title):fr}),(Kt||je.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Kt,je.license&&t.jsxs(t.Fragment,{children:[Kt&&t.jsx("span",{className:"bim-rd-dot"}),je.license]})]})]}),t.jsx(Ma,{store:Ye,children:L=>t.jsx(ss,{pageData:U,pages:U.pages,punctuations:U.punctuations||Qx,selectedCharIds:he,hoveredCharId:L,onSelectionChange:lu,figures:U.figures,figUrl:U.figUrl,onFigureBlockClick:({page:ne,fig:Te})=>{Ie(new Set),Fe(Te),xt(ne)},onCharClick:ne=>{Fe(null),Ie(rt=>{const Ze=new Set(rt);return Ze.has(ne)?Ze.delete(ne):(Ze.clear(),Ze.add(ne)),Ze});const Te=parseInt(ne.split(":")[0],10);isNaN(Te)||xt(Te)},onCharHover:Ye.set,mode:"horizontal",showPunctuation:et,entities:ke,entityTransport:i,onEntityNavigate:v,onVisiblePageChange:du,convert:I,scrollToPage:Qe,scrollToAnchor:Ce&&Ce.chapter===H&&or?Ce:null,onVisibleHeadingChange:ne=>nt(ne&&H?{chapter:H,anchor:ne}:null),pageBreaks:X.pageBreaks,pageIndicatorY:X.pageIndicatorY,onPageIndicatorYChange:ne=>E({pageIndicatorY:ne}),quoteStyle:X.quoteStyle,bookTitleStyle:X.bookTitleStyle,showWorks:X.showWorks})})]}),!Xe&&!U&&rn&&on&&t.jsx(ox,{juan:on,rawText:fn,positionLabel:rb(ce,ye,gn,I),groupLabel:ob(ye,H??null),index:tb(n,ye),searchQuery:R,onNavigate:l,transport:i,workLabelCache:J,prefs:X,view:Ls,onViewChange:ur},`${T}/${H}`),!Xe&&!U&&!rn&&ui!=null&&ce&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:ce.title?I(ce.title):fr}),(Kt||je.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[mi&&Kt&&t.jsx(t.Fragment,{children:Kt}),!mi&&je.source_name&&t.jsxs(t.Fragment,{children:[S("reader.textSource")," ",je.source_url?t.jsx("a",{className:"bim-rd-link",href:je.source_url,target:"_blank",rel:"noreferrer",children:I(je.source_name)}):I(je.source_name)]}),Kt&&je.license&&t.jsx("span",{className:"bim-rd-dot"}),je.license]}),wt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[S("reader.upstream")," ",wt.url?t.jsx("a",{className:"bim-rd-link",href:wt.url,target:"_blank",rel:"noreferrer",children:I(wt.name??wt.url)}):I(wt.name??""),wt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),wt.license_url?t.jsx("a",{className:"bim-rd-link",href:wt.license_url,target:"_blank",rel:"noreferrer",children:wt.license}):wt.license]}),wt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(kc,{text:wt.note,convert:I})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Yo,{text:ui,mode:X.readingMode,tables:ju,gujiMarkdown:!0,bookMarking:Go(X),quoteStyle:X.quoteStyle})})]}),!Xe&&!Me&&!U&&!rn&&ui==null&&ce&&t.jsx("div",{className:"bim-rd-state",children:S("reader.chapterFailed")}),!Xe&&ye.references&&ye.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:S("reader.references")}),t.jsx("ol",{children:ye.references.map((L,ne)=>t.jsxs("li",{children:[L.url?t.jsx("a",{className:"bim-rd-link",href:L.url,target:"_blank",rel:"noopener noreferrer",children:I(L.title)}):t.jsx("span",{children:I(L.title)}),L.author&&t.jsxs("span",{children:[",",I(L.author)]}),L.note&&t.jsxs("span",{children:["。",I(L.note)]})]},ne))})]})]})};function Xa(e){return e.is_original===!0||e.source==="original"}function rb(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 ob(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 sb(e,n,i){const[o,s]=f.useState({entryTitle:void 0,authors:[]});return f.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 Ad={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")}},ab=Ad.other,Md={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")}},lb=Md.pending;function cb(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 db(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 ds=({items:e,loading:n})=>{const i=mt(),{t:o,convert:s}=ie();return n?t.jsx(un,{}):e.length===0?t.jsx("div",{style:pb,children:o("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=Ad[a.type]||ab,d=Md[a.status]||lb,c=typeof window<"u"&&db(a.pageUrl,window.location.href);return t.jsxs("div",{style:ub,children:[t.jsxs("div",{style:mb,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Za,background:l.color},children:o(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Za,background:d.color},children:o(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:gb,children:cb(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:fb,children:[a.resourceId&&t.jsx("a",{href:i(a.resourceId),style:Tr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Tr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Tr,children:a.pageUrl}))]}),t.jsx("div",{style:hb,children:s(a.content)}),a.reply&&t.jsxs("div",{style:xb,children:[t.jsx("div",{style:bb,children:o("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},pb={textAlign:"center",padding:"40px 0",color:r("desc-fg"),fontSize:"14px"},ub={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"16px"},mb={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Za={fontSize:"12px",color:r("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},gb={fontSize:"12px",color:r("desc-fg")},fb={fontSize:"12px",marginBottom:"6px"},Tr={color:r("primary"),textDecoration:"none",borderBottom:`1px dashed ${r("primary")}`},hb={fontSize:"14px",lineHeight:"1.6",color:r("fg"),whiteSpace:"pre-wrap"},xb={marginTop:"12px",padding:"10px 12px",background:r("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r("fg")},bb={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r("primary")},so=({transport:e,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:a})=>{const l=Pe(),[d,c]=f.useState(null),[p,m]=f.useState([]),[g,u]=f.useState("recommend"),[h,x]=f.useState([]),[j,b]=f.useState(!1),_=o??g,y=M=>{u(M),s==null||s(M)},[k,w]=f.useState(!0),[v,C]=f.useState(null),[$,S]=f.useState(null),[I,N]=f.useState(null);f.useEffect(()=>{let M=!1;if(e.getCounts)return e.getCounts().then(F=>{M||c({works:F.works,books:F.books,collections:F.collections})}).catch(()=>{}),()=>{M=!0}},[e]),f.useEffect(()=>{let M=!1;return(async()=>{if(i)return i;if(e.getRecommended)try{const q=await e.getRecommended();if(q!=null&&q.groups)return q.groups.flatMap(be=>be.items.map(se=>({...se,group:be.name})))}catch{}return[]})().then(async q=>{if(M)return;const be=q.filter(Y=>Y.id);if(be.length===0){w(!1);return}const se=await Promise.all(be.map(async Y=>{if(Y.type)return{id:Y.id,title:Y.title,type:Y.type,author:Y.author,dynasty:Y.dynasty,role:Y.role,edition:Y.edition,has_text:Y.has_text,has_image:Y.has_image,has_collated:Y.has_collated,subtype:Y.subtype,primary_name:Y.primary_name,group:Y.group,fallbackDescription:Y.description};try{let xe=null;if(e.getEntry)xe=await e.getEntry(Y.id);else{const Q=await e.getItem(Y.id);Q&&(xe={id:Y.id,title:Q.title||Y.id,type:Q.type||"work"})}if(xe)return{...xe,group:Y.group,fallbackDescription:Y.description}}catch{}return{id:Y.id,title:Y.title,type:Ee.extractType(Y.id),group:Y.group,fallbackDescription:Y.description}}));M||(m(se.filter(Y=>Y!==null)),w(!1))}),()=>{M=!0}},[e,i]);const z=f.useRef(!1),E=f.useRef(!1),P=f.useRef(!1);f.useEffect(()=>{if(_!=="catalog"||z.current)return;const M=e.getCatalogProgress??e.getResourceProgress;if(!M)return;z.current=!0;let F=!1;return M.call(e).then(q=>{F||C(q)}).catch(()=>{z.current=!1}),()=>{F=!0}},[e,_]),f.useEffect(()=>{if(_!=="collection"||E.current||!e.getCollectionProgress)return;E.current=!0;let M=!1;return e.getCollectionProgress().then(F=>{M||S(F)}).catch(()=>{E.current=!1}),()=>{M=!0}},[e,_]),f.useEffect(()=>{if(_!=="site"||P.current||!e.getSiteProgress)return;P.current=!0;let M=!1;return e.getSiteProgress().then(F=>{M||N(F)}).catch(()=>{P.current=!1}),()=>{M=!0}},[e,_]),f.useEffect(()=>{if(!a||_!=="feedback")return;let M=!1;return b(!0),fetch(a).then(F=>F.json()).then(F=>{!M&&F.success&&x(F.items||[])}).catch(()=>{}).finally(()=>{M||b(!1)}),()=>{M=!0}},[a,_]);const A=M=>t.jsx(Tn,{type:M,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(Wn,{label:l.home.recommendTab,active:_==="recommend",onClick:()=>y("recommend")}),t.jsx(Wn,{label:l.home.catalogTab,active:_==="catalog",onClick:()=>y("catalog")}),t.jsx(Wn,{label:l.home.collectionTab,active:_==="collection",onClick:()=>y("collection")}),t.jsx(Wn,{label:l.home.siteTab,active:_==="site",onClick:()=>y("site")}),a&&t.jsx(Wn,{label:l.home.feedbackTab,active:_==="feedback",onClick:()=>y("feedback")})]}),_==="recommend"&&t.jsx(yb,{recommended:p,loading:k,onNavigate:n,getIcon:A,t:l}),_==="catalog"&&t.jsx(Ja,{progress:v,t:l,onNavigate:n}),_==="collection"&&t.jsx(Ja,{progress:$,t:l,onNavigate:n}),_==="site"&&t.jsx(vb,{progress:I,t:l,totalWorks:(d==null?void 0:d.works)??0}),_==="feedback"&&a&&t.jsx(ds,{items:h,loading:j})]})})},Wn=({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}),yb=({recommended:e,loading:n,onNavigate:i,getIcon:o,t:s})=>{const a=mt();if(n)return t.jsx(un,{});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:g=>{g.metaKey||g.ctrlKey||(g.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))})},Ja=({progress:e,t:n,onNavigate:i})=>{if(!e)return t.jsx(un,{});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(jb,{item:p,t:n,statusColor:l[d],onNavigate:i},p.id))})]},d)})})},jb=({item:e,t:n,statusColor:i,onNavigate:o})=>{const s=mt(),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?$t(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})]})},vb=({progress:e,t:n,totalWorks:i})=>{if(!e)return t.jsx(un,{});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(Qa,{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(Qa,{item:c,t:n,totalWorks:i},c.id))})]})]})},Qa=({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})]})},el="(max-width: 768px)";function kb(){const[e,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(el).matches);return f.useEffect(()=>{const i=window.matchMedia(el),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),e}const wb=({transport:e,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var E;const a=Pe(),{convert:l}=De(),d=kb(),[c,p]=f.useState(null),[m,g]=f.useState(null),[u,h]=f.useState(!1),[x,j]=f.useState("detail"),[b,_]=f.useState([]),[y,k]=f.useState(!1),w=f.useCallback(async P=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){_([]);return}k(!0);try{if(e.getCollectionCatalogs){const A=await e.getCollectionCatalogs(P);_(A||[])}else if(e.getCollectionCatalog){const A=await e.getCollectionCatalog(P);_(A?[{resource_id:"",data:A}]:[])}}catch{_([])}finally{k(!1)}},[e]),v=f.useCallback(async P=>{if(i){i(P);return}p(P),g(null),_([]),j("detail"),h(!0);try{const A=await e.getItem(P.id);A&&(g(A),A.type==="collection"&&w(P.id))}catch(A){console.error("加载详情失败:",A)}finally{h(!1)}},[e,i,w]),C=f.useCallback(async P=>{g(null),_([]),j("detail"),h(!0);try{const A=await e.getItem(P);A&&(g(A),p({id:P,title:A.title||P,type:A.type||"book"}),A.type==="collection"&&w(P))}catch(A){console.error("导航失败:",A)}finally{h(!1)}},[e,w]),$=typeof(m==null?void 0:m.text_count)=="number"&&m.text_count>0,S=(m==null?void 0:m.type)==="collection"&&(b.length>0||y)||(m==null?void 0:m.type)==="work"&&$,I=d&&(u||m),N=f.useCallback(()=>{p(null),g(null),_([]),j("detail")},[]),z=t.jsx(t.Fragment,{children:u?t.jsx(un,{}):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:()=>j("detail"),style:ji(x==="detail"),children:a.detailTab.basicInfo}),m.type==="collection"&&y&&b.length===0&&t.jsxs("button",{onClick:()=>{},style:ji(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),m.type==="collection"&&b.map(P=>t.jsx("button",{onClick:()=>j(`catalog:${P.resource_id}`),style:ji(x===`catalog:${P.resource_id}`),children:P.short_name?`${l(P.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},P.resource_id)),m.type==="work"&&$&&t.jsx("button",{onClick:()=>j("collated"),style:ji(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(Ro,{data:m,transport:e,onNavigate:C}):x.startsWith("catalog:")?t.jsx(Lo,{data:(E=b.find(P=>`catalog:${P.resource_id}`===x))==null?void 0:E.data,onNavigate:C}):x==="collated"?t.jsx(cs,{id:m.id,transport:e,onNavigate:C}):null})]}):t.jsx(so,{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:I?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:N,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:z})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(Dr,{transport:e,onEntryClick:v,hideModeIndicator:n}),!m&&t.jsx(so,{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(Dr,{transport:e,onEntryClick:v,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:r("bg"),display:"flex",flexDirection:"column"},children:z})]})};function ji(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 Sb=({pageData:e,rawImageUrl:n="",punctuations:i=[],title:o,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=f.useState(new Set),[m,g]=f.useState(null),[u,h]=f.useState("horizontal"),[x,j]=f.useState(!0),b=f.useRef(null),_=f.useCallback(v=>{p(new Set(v))},[]),y=f.useCallback(v=>{if(p(C=>{const $=new Set(C);return $.has(v)?$.delete(v):($.clear(),$.add(v)),$}),b.current){const C=b.current.querySelector(`[data-char-id="${v}"]`);C&&C.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),k=()=>{var v;p(new Set),window.getSelection&&((v=window.getSelection())==null||v.removeAllRanges())},w=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:k,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>j(v=>!v),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>h(v=>v==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:u==="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(ts,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:m,onCharClick:y,onCharHover:g})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:b,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:u==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(ss,{pageData:e,punctuations:w,selectedCharIds:c,hoveredCharId:m,onSelectionChange:_,onCharClick:y,onCharHover:g,mode:u,showPunctuation:x})]})]})]})},_b=e=>typeof e=="string"&&Array.from(e).length===1,$b=new Set(["point","break","heading"]),Cb=/^#{1,6}$/;function zb(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;if(typeof s.anchor!="string"||typeof s.mark!="string"||s.pre_char!=null&&!_b(s.pre_char)||s.kind!=null&&!$b.has(s.kind)||s.pos!=null&&s.pos!=="after"&&s.pos!=="before")continue;const a={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};if(!(s.kind==="break"&&s.pos==="before")){if(s.kind==="heading"){if(s.pos!=="before"||!Cb.test(s.mark))continue;typeof s.label=="string"&&s.label.trim()&&(a.label=s.label.trim()),s.toc===!1&&(a.toc=!1)}i.push(a)}}return i}function Nb(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 Pd=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function pt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}const ps=/^[a-z0-9][a-z0-9-]*$/,Tb=new Set(["main","solo","jz_r","jz_l"]),Eb=new Set(["body","banxin","blank"]);function Ib(e){const n={};return typeof e.lane=="string"&&Tb.has(e.lane)&&e.lane!=="main"&&(n.lane=e.lane),e.lacuna===!0&&(n.lacuna=!0),e.lacuna===!0&&e.guess!==!0&&typeof e.guess_c=="string"&&e.guess_c.trim()&&(n.guess_c=e.guess_c.trim()),e.guess===!0&&(n.guess=!0),typeof e.zi=="string"&&e.zi&&(n.zi=e.zi),typeof e.fig=="string"&&ps.test(e.fig)&&e.c==="□"&&!e.lacuna&&!e.guess&&e.guess_c===void 0&&e.zi===void 0&&(n.fig=e.fig),n}function Rb(e){const n={};typeof e.kind=="string"&&Eb.has(e.kind)&&e.kind!=="body"&&(n.kind=e.kind);const i=pt(e.raised);i!==void 0&&Number.isInteger(i)&&i>0&&(n.raised=i);const o=pt(e.lead_blank);return o!==void 0&&Number.isInteger(o)&&o>0&&(n.lead_blank=o),n}function Er(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(i=>!!i&&typeof i=="object"):[]}function Lb(e){return typeof e=="string"&&Array.from(e).length===1}function Bd(e){const n=new Map,i={badAnchor:0,badChar:0,badWhy:0,notObject:0},o=e&&typeof e=="object"?e.items:void 0;for(const s of Array.isArray(o)?o:[]){if(!s||typeof s!="object"){i.notObject++;continue}const{a,t:l,why:d}=s;if(typeof a!="string"||!Pd.test(a)){i.badAnchor++;continue}if(!Lb(l)){i.badChar++;continue}if(d!==void 0&&d!=="异体"){i.badWhy++;continue}n.set(a,l)}return{map:n,dropped:i}}function Od(e){return Bd(e).map}function Ab(e,n,i){var g,u,h,x,j,b,_,y,k,w;const o=i==null?null:Od(i),s=new Map,a=new Map;for(const v of Er(n)){const C=pt(v.page);if(C!==void 0){s.set(C,v);for(const $ of Array.isArray(v.cells)?v.cells:[]){const S=$==null?void 0:$.box;typeof($==null?void 0:$.a)=="string"&&Array.isArray(S)&&S.length===4&&S.every(I=>pt(I)!==void 0)&&a.set($.a,[S[0],S[1],S[0]+S[2],S[1]+S[3]])}}}const l=new Map;for(const[v,C]of s)for(const $ of Array.isArray(C.marks)?C.marks:[]){const S=$==null?void 0:$.box;if(($==null?void 0:$.kind)!=="figure"||typeof $.fig!="string"||!Array.isArray(S)||S.length!==4||!S.every(N=>pt(N)!==void 0))continue;let I=l.get(v);I||l.set(v,I=new Map),I.set($.fig,[S[0],S[1],S[0]+S[2],S[1]+S[3]])}const d=[],c=new Map,p=new Map;for(const v of Er(e)){const C=pt(v.page);C!==void 0&&typeof v.label=="string"&&v.label&&c.set(C,v.label)}for(const v of Er(e)){const C=pt(v.page);if(C===void 0)continue;const $=[],S=l.get(C);for(const N of Array.isArray(v.columns)?v.columns:[]){const z=pt(N==null?void 0:N.col);if(z===void 0)continue;if(N.kind==="figure"){if(typeof N.fig!="string"||!ps.test(N.fig))continue;const A=pt(N.span),M=S==null?void 0:S.get(N.fig);$.push({col:z,chars:[],kind:"figure",fig:N.fig,...A!==void 0&&Number.isInteger(A)&&A>1?{span:A}:{},...M?{figBox:M}:{}});continue}const E=[];for(const A of Array.isArray(N.cells)?N.cells:[]){const M=Pd.exec(String((A==null?void 0:A.a)??""));if(!M||typeof A.c!="string")continue;const F=parseInt(M[3],10),q=o==null?void 0:o.get(A.a);E.push({id:A.a,char:A.c,slot:F,pos:F,sub:M[4]||null,bbox:a.get(A.a)??null,...Ib(A),...q!==void 0&&q!==A.c?{norm:q}:{}})}const P=Rb(N);(E.length>0||P.kind==="blank")&&$.push({col:z,chars:E,...P})}if(!$.some(N=>N.chars.length>0||N.kind==="figure")){$.length>0&&p.set(C,$);continue}$.sort((N,z)=>N.col-z.col);const I=s.get(C);d.push({page:C,seq:String(((g=I==null?void 0:I.canvas)==null?void 0:g.seq)??""),width:pt((u=I==null?void 0:I.canvas)==null?void 0:u.width)??pt((h=I==null?void 0:I.image)==null?void 0:h.width)??0,height:pt((x=I==null?void 0:I.canvas)==null?void 0:x.height)??pt((j=I==null?void 0:I.image)==null?void 0:j.height)??0,...typeof v.label=="string"&&v.label?{label:v.label}:{},columns:$})}const m=new Set(d.map(v=>v.page));for(const[v,C]of s){const $=(b=C==null?void 0:C.canvas)==null?void 0:b.seq;m.has(v)||typeof $!="string"&&typeof $!="number"||String($)===""||d.push({page:v,seq:String($),width:pt((_=C.canvas)==null?void 0:_.width)??pt((y=C.image)==null?void 0:y.width)??0,height:pt((k=C.canvas)==null?void 0:k.height)??pt((w=C.image)==null?void 0:w.height)??0,...c.has(v)?{label:c.get(v)}:{},columns:p.get(v)??[]})}return d.sort((v,C)=>v.page-C.page)}const Mb=new Set(["image/png","image/webp","image/svg+xml"]);function Pb(e){const n=new Map,i=e&&typeof e=="object"?e.figures:void 0;for(const o of Array.isArray(i)?i:[]){if(!o||typeof o!="object")continue;const s=o;if(typeof s.id!="string"||!ps.test(s.id))continue;const a=s.kind==="block"?"block":s.kind==="inline"?"inline":null;a&&(typeof s.file!="string"||!/^fig\/[\w./-]+$/.test(s.file)||s.file.split("/").includes("..")||typeof s.mime!="string"||!Mb.has(s.mime)||n.set(s.id,{id:s.id,kind:a,alt:typeof s.alt=="string"&&s.alt.trim()?s.alt.trim():"图形符号",file:s.file,mime:s.mime,width:pt(s.width)??0,height:pt(s.height)??0}))}return n}const Bb=({data:e,onNavigate:n,className:i,style:o})=>{var m;const{t:s,convert:a}=ie(),[l,d]=f.useState(((m=e.divisions[0])==null?void 0:m.name)??null),[c,p]=f.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(g=>t.jsx(Ob,{division:g,expanded:l===g.name,onToggle:()=>d(l===g.name?null:g.name),expandedCat:c,onCatToggle:u=>p(c===u?null:u),onNavigate:n},g.name))})]})},Ob=({division:e,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=ie(),c=e.categories.reduce((p,m)=>{const g=m.stats||{zhulu:0,cunmu:0};return p+(g.zhulu||0)+(g.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(Wb,{category:p,expanded:o===m,onToggle:()=>s(m),onNavigate:a},p.name)})})]})},Wb=({category:e,expanded:n,onToggle:i,onNavigate:o})=>{var p,m,g,u;const{t:s,convert:a}=ie(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((m=e.books)==null?void 0:m.cunmu)||[],c=(((g=e.stats)==null?void 0:g.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.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(tl,{label:s("catalogPage.zhulu"),books:l,onNavigate:o}),d.length>0&&t.jsx(tl,{label:s("catalogPage.cunmu"),books:d,onNavigate:o})]})]})},tl=({label:e,books:n,onNavigate:i})=>{const{t:o,convert:s}=ie(),a=mt(),[l,d]=f.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:g=>{g.metaKey||g.ctrlKey||(g.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})})]})},It=({title:e,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const a=Pe();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:Hb,children:"AI"}),n&&t.jsx("button",{onClick:n,style:Fb,children:a.action.save})]})]}),s]})},Fb={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},Hb={padding:"4px 12px",fontSize:"12px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},_t=({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"}})]}),pn=({value:e,onChange:n,placeholder:i})=>{const o=f.useRef(null);return f.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"}})},Ri=({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 Db(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const $i=({value:e,onChange:n,label:i})=>{const[o,s]=f.useState(!1),a=f.useRef(null),l=Db(e||"");return f.useEffect(()=>{o&&a.current&&a.current.focus()},[o]),!o&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:nl,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(Ri,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:nl,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"}})]})},nl={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500};function Ub(e){switch(e){case"url":return r("source-url");case"bookID":return r("source-bookid");default:return r("desc-fg")}}function Vb(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Wd=({items:e,onChange:n,onOpenEntityPicker:i})=>{const o=Pe(),[s,a]=f.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=g=>{n(e.filter((u,h)=>h!==g)),s===g&&a(null)},c=(g,u,h)=>{const x=[...e];x[g]={...x[g],[u]:h},n(x)},p=(g,u)=>{const h=[...e];h[g]={...h[g],type:u,id:"",name:""},n(h),u==="bookID"&&i&&i(x=>{const j=[...e];j[g]={...j[g],id:x.id,name:x.title,type:"bookID"},n(j)})},m=g=>{i&&i(u=>{const h=[...e];h[g]={...h[g],id:u.id,name:u.title,type:"bookID"},n(h)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((g,u)=>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===u?null:u),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===u?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:r("fg")},children:g.name||`${o.editor.sourcePlaceholder} ${u+1}`}),g.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ub(g.type),color:r("on-color-fg"),borderRadius:"3px",fontWeight:500},children:Vb(g.type)}),t.jsx("button",{onClick:h=>{h.stopPropagation(),d(u)},style:{background:"transparent",border:"none",color:r("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===u&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${r("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!g.type&&t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(u,"bookID"),style:{...il,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(u,"url"),style:{...il,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})]})]})]}),g.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:Ht,children:o.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const h=[...e];h[u]={...h[u],type:"",id:"",name:""},n(h)},style:rl,children:o.action.changeType})]}),g.id&&g.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:g.name}),t.jsx("code",{style:{fontSize:"11px",background:r("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:g.id})]}),t.jsx("button",{onClick:()=>m(u),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(u),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})]})]})}),g.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:Ht,children:o.label.sourceName}),t.jsx("button",{onClick:()=>{const h=[...e];h[u]={...h[u],type:"",id:"",name:""},n(h)},style:rl,children:o.action.changeType})]}),t.jsx("input",{type:"text",value:g.name,onChange:h=>c(u,"name",h.target.value),placeholder:o.editor.sourceNamePlaceholder,style:bn})]}),t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.urlAddress}),t.jsx("input",{type:"text",value:g.id,onChange:h=>c(u,"id",h.target.value),placeholder:"https://...",style:bn})]})]}),g.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:{...Ht,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:Ht,children:o.label.detailsOptional}),t.jsx("input",{type:"text",value:g.details,onChange:h=>c(u,"details",h.target.value),placeholder:o.editor.detailsPlaceholder,style:bn})]}),t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.positionOptional}),t.jsx("input",{type:"text",value:g.position,onChange:h=>c(u,"position",h.target.value),placeholder:"如: 卷三, p.52",style:bn})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.dataVersionOptional}),t.jsx("input",{type:"text",value:g.version,onChange:h=>c(u,"version",h.target.value),placeholder:"如: v1.0, 2024-01",style:bn})]}),t.jsxs("div",{children:[t.jsx("label",{style:Ht,children:o.label.processorVersionOptional}),t.jsx("input",{type:"text",value:g.processor_version,onChange:h=>c(u,"processor_version",h.target.value),placeholder:"如: v0.1",style:bn})]})]})]})]})})]},u)),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})]})]})},Ht={display:"block",fontSize:"11px",color:r("desc-fg"),marginBottom:"4px",fontWeight:500},bn={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"},il={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"},rl={background:"transparent",border:"none",color:r("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function Fd(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 Hd(e){return!e||e.length===0?"":JSON.stringify(e)}const Dd=({entityType:e,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:m,onLinkEntity:g,onUnlinkEntity:u,onViewEntity:h,onCreateAndLink:x,onSaveRelations:j})=>{const b=Pe();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:b.section.relations})]}),j&&t.jsx("button",{onClick:j,style:Gb,children:b.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(Fn,{direction:"up",title:b.relation.belongsToWork,entity:a,onView:h,onUnlink:()=>u("workId"),onLink:()=>g("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(Fn,{direction:"up",title:b.relation.containedInCollection,entity:l,onView:h,onUnlink:()=>u("collectionId"),onLink:()=>g("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),a&&m&&m.length>0&&t.jsx(yn,{direction:"horizontal",title:`${b.relation.siblingVersions} (${m.length})`,entities:m,onView:h,onAdd:()=>x("siblingBook","book",{workId:a.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(Fn,{direction:"up",title:b.relation.parentWork,entity:o,onView:h,onUnlink:()=>u("parentWorkId"),onLink:()=>g("parentWorkId","work"),onCreate:()=>x("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),d&&d.length>0&&t.jsx(yn,{direction:"down",title:`${b.relation.childWorks} (${d.length})`,entities:d,onView:h,onAdd:()=>x("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),c&&c.length>0&&t.jsx(yn,{direction:"down",title:`${b.relation.collectionImpl} (${c.length})`,entities:c,onView:h,onAdd:()=>x("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(yn,{direction:"down",title:`${b.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:h,onAdd:()=>x("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(Fn,{direction:"up",title:b.relation.correspondingWork,entity:a,onView:h,onUnlink:()=>u("workId"),onLink:()=>g("workId","work"),onCreate:()=>x("workId","work",{title:i}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(Fn,{direction:"up",title:b.relation.parentCollection,entity:s,onView:h,onUnlink:()=>u("parentCollectionId"),onLink:()=>g("parentCollectionId","collection"),onCreate:()=>x("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),t.jsx(yn,{direction:"down",title:`${b.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:h,onAdd:()=>x("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),t.jsx(yn,{direction:"down",title:`${b.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:h,onAdd:()=>x("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},Fn=({direction:e,title:n,entity:i,onView:o,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:m,unlinkLabel:g})=>{const u=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),h=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:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:h}),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:Ud(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(ol,{onClick:()=>o(i),title:m,children:"👁️"}),t.jsx(ol,{onClick:s,title:g,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(ao,{onClick:a,children:d}),t.jsx(ao,{onClick:l,primary:!0,children:c})]})]})},yn=({direction:e,title:n,entities:i,onView:o,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=f.useState(!1),m=r(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),g=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",u=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:g}),t.jsx("span",{children:n})]}),i.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[u.map(h=>t.jsxs("div",{onClick:()=>o(h),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:r("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:Ud(h.type)}),t.jsx("span",{children:h.title})]},h.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(ao,{onClick:s,primary:!0,children:["+ ",a]})})]})},ol=({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}),ao=({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 Ud(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const Gb={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Vd=({isOpen:e,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[m,g]=f.useState(""),u=p?l.filter(b=>b.id!==p):l;f.useEffect(()=>{e&&(g(""),d(""))},[e]);const h=b=>{g(b),d(b)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",j=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:Yb,children:t.jsxs("div",{style:qb,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:Kb,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:m,onChange:b=>h(b.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:Xb})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Ir,children:"搜索中..."}):u.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:u.map(b=>t.jsxs("div",{onClick:()=>o(b),style:Zb,children:[t.jsx("span",{style:{fontSize:"16px"},children:j}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):m?t.jsxs("div",{style:Ir,children:["未找到匹配的",x]}):t.jsxs("div",{style:Ir,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:Jb,children:["创建新",x,"并关联"]})]})]})})},Yb={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},qb={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")},Kb={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Xb={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"},Zb={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:r("primary-soft")},Ir={padding:"20px",textAlign:"center",color:r("desc-fg")},Jb={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},sl={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Qb={work:"📜",book:"📖",collection:"📚",entity:"👤"},Gd=({isOpen:e,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:a})=>{const[l,d]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{e&&(d((o==null?void 0:o.title)||""),setTimeout(()=>{var u,h;(u=c.current)==null||u.focus(),(h=c.current)==null||h.select()},100))},[e,o==null?void 0:o.title]);const p=u=>{u.key==="Enter"&&l.trim()?m():u.key==="Escape"&&a()},m=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!e)return null;const g=()=>{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`创建新${sl[n]}`}};return t.jsx("div",{style:ey,onClick:u=>{u.target===u.currentTarget&&a()},children:t.jsxs("div",{style:ty,onClick:u=>u.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Qb[n]}),t.jsx("span",{children:g()})]}),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:u=>d(u.target.value),onKeyDown:p,placeholder:`请输入${sl[n]}名称...`,style:ny})]}),((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:iy,children:"取消"}),t.jsx("button",{onClick:m,disabled:!l.trim(),style:{...ry,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},ey={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ty={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")},ny={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"},iy={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r("widget-border")}`,borderRadius:"4px",background:"transparent",color:r("fg"),cursor:"pointer"},ry={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg")};function oy(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Yd(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function sy(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 qd=({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[g,u]=f.useState(""),[h,x]=f.useState([]),[j,b]=f.useState(!1),[_,y]=f.useState("recent");f.useEffect(()=>{e&&(u(""),x([]),y(o.length>0?"recent":"search"))},[e,o.length]),f.useEffect(()=>{if(!g.trim()){x([]);return}const S=setTimeout(async()=>{b(!0);try{x(await m(g,i))}catch{x([])}finally{b(!1)}},300);return()=>clearTimeout(S)},[g,i,m]);const k=f.useCallback(S=>{u(S.target.value),S.target.value.trim()&&y("search")},[]),w=f.useCallback(S=>s?S.filter(I=>I.id!==s):S,[s]);if(!e)return null;const v=n||(i==="all"?"选择实体":`选择${Yd(i)}`),C=w(o),$=w(h);return t.jsx("div",{style:ly,children:t.jsxs("div",{style:cy,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:v}),t.jsx("button",{onClick:c,style:dy,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:g,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:py}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),j&&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(al,{active:_==="recent",onClick:()=>y("recent"),children:["最近使用 (",C.length,")"]}),t.jsxs(al,{active:_==="search",onClick:()=>y("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(ll,{entities:C,onSelect:d}):g.trim()?j?t.jsx(Rr,{message:"搜索中..."}):$.length>0?t.jsx(ll,{entities:$,onSelect:d}):t.jsx(Rr,{message:"未找到匹配的结果"}):t.jsx(Rr,{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:uy,children:l||"创建新实体"})]})]})})},al=({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}),ll=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(i=>t.jsx(ay,{entity:i,onClick:()=>n(i)},i.id))}),ay=({entity:e,onClick:n})=>{const[i,o]=f.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:oy(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:sy(e.type),color:r("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:Yd(e.type)})]})},Rr=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:r("desc-fg"),fontSize:"13px"},children:e}),ly={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},cy={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")},dy={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},py={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"},uy={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:r("primary"),color:r("primary-fg"),cursor:"pointer"},my={work:r("editor-type-work"),collection:r("editor-type-collection"),book:r("editor-type-book"),entity:r("editor-type-entity")},gy={work:"📜",collection:"📚",book:"📖",entity:"👤"},Kd=({data:e,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:m,relations:g,onRelationsChange:u})=>{var de;const h=Pe(),[x,j]=f.useState(!1),[b,_]=f.useState("work"),[y,k]=f.useState(""),[w,v]=f.useState(""),[C,$]=f.useState([]),[S,I]=f.useState(!1),[N,z]=f.useState(!1),[E,P]=f.useState("work"),[A,M]=f.useState(""),[F,q]=f.useState(),[be,se]=f.useState(!1),[Y,xe]=f.useState(null),[Q,le]=f.useState([]);f.useRef(null);const we=e.type,je=we==="work",ee=we==="collection",T=we==="book",G=f.useCallback((te,Ce)=>{n({...e,[te]:Ce})},[e,n]),fe=f.useCallback((te,Ce)=>{k(te),_(Ce),v(h.editor.selectToLink+h.indexType[Ce]),$([]),j(!0)},[h]),ae=f.useCallback(te=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(e.id,te)},[o,e.id]),Be=f.useCallback(te=>{s==null||s(te.id,te.type)},[s]),Oe=f.useCallback((te,Ce,Ue)=>{const Ge={...Ue,author:(Ue==null?void 0:Ue.author)||e.author,dynasty:Ue==null?void 0:Ue.dynasty};P(Ce),M(te),q(Ge),z(!0)},[e.author]),Z=f.useCallback((te,Ce)=>{o!=null&&o.createAndLink&&o.createAndLink(e.id,A,{type:E,title:te,inheritData:Ce}),z(!1)},[o,e.id,A,E]),oe=f.useCallback(te=>{if(!te.trim()){$([]);return}I(!0),o!=null&&o.searchEntities&&o.searchEntities(te,b).then(Ce=>{$(Ce),I(!1)}).catch(()=>{$([]),I(!1)})},[o,b]),ze=f.useCallback(te=>{o!=null&&o.linkEntity&&o.linkEntity(e.id,y,te.id),j(!1)},[o,e.id,y]),We=f.useCallback(()=>{i()},[i]),ye=f.useCallback(te=>{xe(()=>te),se(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(le).catch(()=>{})},[o]),H=f.useCallback((te,Ce)=>o!=null&&o.searchEntities?o.searchEntities(te,Ce==="all"?void 0:Ce):Promise.resolve([]),[o]),ce=f.useCallback(te=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(te),le(Ce=>[te,...Ce.filter(Ue=>Ue.id!==te.id)].slice(0,10)),Y==null||Y(te),se(!1),xe(null)},[o,Y]);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:gy[we]}),t.jsx("span",{children:e.title||h.editor.untitled}),t.jsx(Ri,{children:e.id}),t.jsx(Ri,{color:my[we],children:h.indexType[we]})]})}),t.jsx(It,{title:h.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($i,{label:je?h.editor.workTitle:ee?h.editor.collectionTitle:h.editor.bookTitle,value:e.title,onChange:te=>G("title",te)}),T&&t.jsx($i,{label:h.editor.belongsToWork,value:e.workName||"",onChange:te=>G("workName",te)}),t.jsx(_t,{label:h.editor.authorLabel,value:e.author||"",onChange:te=>G("author",te)}),t.jsx(_t,{label:h.editor.publicationYearLabel,value:e.publicationYear||"",onChange:te=>G("publicationYear",te)}),(T||ee)&&t.jsx($i,{label:h.editor.containedIn,value:e.collection||"",onChange:te=>G("collection",te)}),(T||ee)&&t.jsx(_t,{label:h.editor.holderLabel,value:e.holder||"",onChange:te=>G("holder",te)}),(T||ee)&&t.jsx(_t,{label:T?h.editor.pageLabel:h.editor.volumeLabel,value:e.pages||"",onChange:te=>G("pages",te)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(_t,{label:h.editor.firstImageLabel,value:e.firstImage||"",onChange:te=>G("firstImage",te)})})]})}),t.jsx(It,{title:h.section.description,onSave:i,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(pn,{value:e.description||"",onChange:te=>G("description",te),placeholder:h.editor.descriptionPlaceholder})}),(((de=e.additional_works)==null?void 0:de.length)||0)>0&&t.jsx(It,{title:h.section.additionalWorks,onSave:i,children:t.jsx(fy,{items:e.additional_works||[],onChange:te=>G("additional_works",te)})}),t.jsx(It,{title:h.section.indexedBy,onSave:i,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(hy,{items:e.indexed_by||[],onChange:te=>G("indexed_by",te)})}),t.jsx(It,{title:h.section.emendatedBy,onSave:i,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(xy,{items:e.emendated_by||[],onChange:te=>G("emendated_by",te)})}),t.jsx(It,{title:h.section.textResources,onSave:i,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(Or,{items:e.resources||[],onChange:te=>G("resources",te),onDownload:p,downloadStatuses:m,filterType:"text"})}),t.jsx(It,{title:h.section.imageResources,onSave:i,children:t.jsx(Or,{items:e.resources||[],onChange:te=>G("resources",te),onDownload:p,downloadStatuses:m,filterType:"image"})}),t.jsx(It,{title:h.section.sources,onSave:i,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(Wd,{items:Fd(e.sources||""),onChange:te=>G("sources",Hd(te)),onOpenEntityPicker:ye})}),(T||ee)&&t.jsx(It,{title:h.section.provenance,onSave:i,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(pn,{value:e.provenance||"",onChange:te=>G("provenance",te),placeholder:h.editor.provenancePlaceholder})}),T&&t.jsx(It,{title:h.section.otherEditions,onSave:i,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(pn,{value:e.otherEditions||"",onChange:te=>G("otherEditions",te),placeholder:h.editor.otherEditionsPlaceholder})}),t.jsx(Dd,{entityType:we,entityId:e.id,entityTitle:e.title,parentWork:g==null?void 0:g.parentWork,parentCollection:g==null?void 0:g.parentCollection,belongsToWork:g==null?void 0:g.belongsToWork,belongsToCollection:g==null?void 0:g.belongsToCollection,childWorks:g==null?void 0:g.childWorks,childCollections:g==null?void 0:g.childCollections,containedBooks:g==null?void 0:g.containedBooks,siblingBooks:g==null?void 0:g.siblingBooks,onLinkEntity:fe,onUnlinkEntity:ae,onViewEntity:Be,onCreateAndLink:Oe,onSaveRelations:We}),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:h.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:r("desc-fg"),marginBottom:"12px"},children:h.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:h.editor.deleteEntity})]}),t.jsx(Vd,{isOpen:x,entityType:b,title:w,onSelect:ze,onCancel:()=>j(!1),onCreate:()=>{j(!1),Oe(y,b)},searchResults:C,onSearch:oe,isLoading:S,excludeId:e.id}),t.jsx(Gd,{isOpen:N,entityType:E,relationField:A,inheritData:F,onConfirm:Z,onCancel:()=>z(!1)}),t.jsx(qd,{isOpen:be,title:h.action.selectBookOrWork,filterType:"all",recentEntities:Q,excludeId:e.id,onSelect:ce,onCancel:()=>{se(!1),xe(null)},onSearch:H})]})};function fy({items:e,onChange:n}){const i=Pe(),o=(l,d,c)=>{const p=e.map((m,g)=>g===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(_t,{label:i.editor.bookNameLabel,value:l.book_title,onChange:c=>o(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(_t,{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 Xd({items:e,onChange:n,showMeta:i,addLabel:o}){const s=Pe(),[a,l]=f.useState(null),d=(m,g,u)=>{const h=e.map((x,j)=>j===m?{...x,[g]:u||void 0}:x);n(h)},c=m=>{n(e.filter((g,u)=>u!==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,g)=>{const u=a===g;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:u?`color-mix(in srgb, ${r("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(u?null:g),children:[t.jsx("span",{style:{fontSize:"10px",color:r("desc-fg"),transition:"transform 0.2s",transform:u?"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:h=>{h.stopPropagation(),c(g)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${r("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:r("muted")},children:"✕"})]}),!u&&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]}),u&&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(_t,{label:s.label.sourceName,value:m.source,onChange:h=>d(g,"source",h)}),t.jsx(_t,{label:s.label.sourceBid,value:m.source_bid||"",onChange:h=>d(g,"source_bid",h)})]}),i&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(_t,{label:s.label.titleInfo,value:m.title_info||"",onChange:h=>d(g,"title_info",h)}),t.jsx(_t,{label:s.label.authorInfo,value:m.author_info||"",onChange:h=>d(g,"author_info",h)})]}),t.jsx(_t,{label:s.label.edition,value:m.edition||"",onChange:h=>d(g,"edition",h)})]}),t.jsx(pn,{value:m.summary||"",onChange:h=>d(g,"summary",h),placeholder:s.editor.summaryPlaceholder}),t.jsx(pn,{value:m.comment||"",onChange:h=>d(g,"comment",h),placeholder:s.editor.commentPlaceholder}),t.jsx(pn,{value:m.additional_comment||"",onChange:h=>d(g,"additional_comment",h),placeholder:s.editor.additionalCommentPlaceholder})]})]},g)}),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 hy({items:e,onChange:n}){const i=Pe();return t.jsx(Xd,{items:e,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function xy({items:e,onChange:n}){const i=Pe();return t.jsx(Xd,{items:e,onChange:n,addLabel:i.action.addEmendatedBy})}function Zd(e){var d,c,p,m,g,u,h;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=(g=e.page_count)!=null&&g.number?String(e.page_count.number):((u=e.page_count)==null?void 0:u.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 j=x.related_works.find(b=>b.relation==="part_of");j&&(l.parentWorkId=j.id,l.parentWorkName=j.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=(h=x.contained_in[0])==null?void 0:h.id)}return l}function by(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 yy=e=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:m,onAskAI:g,renderSectionActions:u,onDownloadResource:h,downloadStatuses:x,relations:j,onRelationsChange:b,headerExtra:_,className:y,style:k}=e,w=Pe(),[v,C]=f.useState(s),$=a?s:v;f.useEffect(()=>{s!==v&&C(s)},[s]);const S=f.useCallback(()=>{const M=$==="view"?"edit":"view";a?a(M):C(M)},[$,a]),[I,N]=f.useState(null);f.useEffect(()=>{i&&o&&o.getItem(i).then(M=>{M&&N(M)})},[i,o]);const z=n||I,E=f.useMemo(()=>z?Zd(z):null,[z]),P=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"?w.common.switchToEdit:w.common.switchToView,children:$==="view"?w.common.modeEdit:w.common.modeView}):null,A=t.jsxs(t.Fragment,{children:[P,_]});return!z&&!E?t.jsx(un,{}):$==="view"?t.jsx(Ro,{data:z,transport:o,onNavigate:p?M=>p(M):void 0,renderLink:m,headerExtra:A,className:y,style:k}):E?t.jsxs("div",{className:y,style:k,children:[A&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:A}),t.jsx(Kd,{data:E,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:o,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:g,renderSectionActions:u,onDownloadResource:h,downloadStatuses:x,relations:j,onRelationsChange:b})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:r("muted")},children:w.common.noData})},jy=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Jd=({isOpen:e,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const{t:s}=ie(),[a,l]=f.useState(null),[d,c]=f.useState(""),[p,m]=f.useState(""),[g,u]=f.useState("idle"),[h,x]=f.useState(""),j=f.useRef(null);f.useEffect(()=>{e&&(l(null),c(""),m(""),u("idle"),x(""))},[e]),f.useEffect(()=>{a&&setTimeout(()=>{var y;return(y=j.current)==null?void 0:y.focus()},100)},[a]),f.useEffect(()=>{if(g==="success"){const y=setTimeout(n,2e3);return()=>clearTimeout(y)}},[g,n]),f.useEffect(()=>{if(!e)return;const y=k=>{k.key==="Escape"&&n()};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[e,n]);const b=async()=>{if(!(!a||!d.trim())){u("submitting"),x("");try{await i({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),u("success")}catch(y){u("error"),x(y instanceof Error?y.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const _=a&&d.trim()&&g!=="submitting";return t.jsx("div",{style:vy,onClick:y=>{y.target===y.currentTarget&&n()},children:t.jsxs("div",{style:ky,onClick:y=>y.stopPropagation(),children:[t.jsxs("div",{style:wy,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:Sy,"aria-label":s("feedback.close"),children:"✕"})]}),g==="success"?t.jsxs("div",{style:Ny,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:jy.map(y=>t.jsxs("button",{onClick:()=>l(y.value),style:{..._y,...a===y.value?$y:{}},children:[t.jsx("span",{children:y.icon})," ",s(`feedback.submitType.${y.value}`)]},y.value))}),t.jsx("textarea",{ref:j,value:d,onChange:y=>c(y.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||g==="submitting",style:{...Cy,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:y=>m(y.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||g==="submitting","aria-label":s("feedback.contactLabel"),style:Ey}),t.jsxs("div",{style:{fontSize:"12px",color:r("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),g==="error"&&t.jsx("div",{style:Ty,children:h}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:b,disabled:!_,style:{...zy,opacity:_?1:.6,cursor:_?"pointer":"not-allowed"},children:s(g==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},vy={position:"fixed",top:0,left:0,right:0,bottom:0,background:r("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ky={background:r("bg"),border:`1px solid ${r("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r("shadow-dialog")},wy={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Sy={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r("desc-fg"),padding:"4px 8px",borderRadius:"4px"},_y={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"},$y={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},Cy={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"},zy={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},Ny={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r("success")},Ty={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Ey={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"},lo="--bim-feedback-fab-offset",co=48,Iy=16,Ry=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:i,hidden:o=!1,zIndex:s})=>{const{t:a}=ie(),[l,d]=f.useState(!1),c=n.bottom??24;return f.useEffect(()=>{if(o||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(lo,`calc(${c+co+Iy}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(lo)}},[o,c]),t.jsxs(t.Fragment,{children:[!o&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Ly,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(Jd,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:i})]})},Ly={position:"fixed",width:`${co}px`,height:`${co}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"},Ay=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],Qd=({onSubmit:e})=>{const{t:n}=ie(),[i,o]=f.useState("bug"),[s,a]=f.useState(""),[l,d]=f.useState(""),[c,p]=f.useState("idle"),[m,g]=f.useState(""),u=f.useRef(null);f.useEffect(()=>{i&&setTimeout(()=>{var j;return(j=u.current)==null?void 0:j.focus()},100)},[i]);const h=async()=>{if(!(!i||!s.trim())){p("submitting"),g("");try{await e({type:i,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),o("bug")}catch(j){p("error"),g(j instanceof Error?j.message:n("feedback.submitFailedRetry"))}}},x=i&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:cl,children:t.jsxs("div",{style:Wy,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:Fy,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:cl,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Ay.map(j=>t.jsxs("button",{onClick:()=>o(j.value),style:{...My,...i===j.value?Py:{}},children:[t.jsx("span",{children:j.icon})," ",n(`feedback.submitType.${j.value}`)]},j.value))}),t.jsx("textarea",{ref:u,value:s,onChange:j=>a(j.target.value),placeholder:n(i?`feedback.placeholder.${i}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...By}}),t.jsx("input",{type:"text",value:l,onChange:j=>d(j.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:Dy}),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:h,disabled:!x,style:{...Oy,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:Hy,children:m})]})},cl={padding:"16px",border:`1px solid ${r("widget-border")}`,borderRadius:"8px",background:r("input-bg")},My={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"},Py={borderColor:r("primary"),background:r("list-active-bg"),color:r("primary"),fontWeight:500},By={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"},Oy={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r("primary"),color:r("primary-fg"),fontWeight:500},Wy={display:"flex",alignItems:"center",gap:"12px",color:r("success"),fontSize:"14px"},Fy={background:"none",border:"none",color:r("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Hy={fontSize:"13px",color:r("danger"),padding:"8px 12px",background:r("danger-bg"),borderRadius:"4px",marginTop:"8px"},Dy={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 dl(e){return typeof e=="function"?e():e??"/api/feedback"}const ep=({resourceId:e,apiUrl:n})=>{const{t:i}=ie(),[o,s]=f.useState([]),[a,l]=f.useState(!0),d=f.useCallback(async()=>{const p=dl(n);l(!0);try{const g=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();g.success&&s(g.items)}catch{}finally{l(!1)}},[e,n]);f.useEffect(()=>{d()},[d]);const c=async p=>{const m=dl(n),g=await fetch(m,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!g.ok){const u=await g.json().catch(()=>null);throw new Error((u==null?void 0:u.error)||i("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(ds,{items:o,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(Qd,{onSubmit:c})})]})},Xi=8;async function Zi(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 Uy=Mi["zh-Hant"].relation,Vy=Mi["zh-Hant"].lossStatus,Gy=Mi["zh-Hant"].resourceKind,Ji=Nn("zh-Hant"),us=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function pl(e,n=Ji){return e?us(Uy,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function Yy(e,n=Ji){return us(Vy,e)?n(`detail.lossStatus.${e}`):e}function qy(e,n=Ji){return us(Gy,e)?n(`detail.resourceKind.${e}`):""}function ms({authors:e,onNavigate:n,renderLink:i}){const{convert:o}=ie(),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(f.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(ut,{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 tp(e,n,i=Ji){var c,p;const o=_o(e,n),s=o.mirrors.map(m=>({key:m.key,label:m.label,description:m.description,rows:m.items.filter(g=>g.group_role!=="mirror"),mirrors:m.items.filter(g=>g.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 np(e,n){const i=(e.url?$n(e.url):void 0)||e.name,o=Kl(e,n);return o?`${i}(${o})`:i}function gs({item:e,siblings:n,listedVolumeCounts:i}){const{t:o,convert:s}=ie(),[a,l]=f.useState(!1),d=Ai(e),c=!!d&&d.expected>0&&!(i!=null&&i.has(d.expected)),p=s(np(e,n)),m=Cn(e),g=Wi(e,o)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var h,x;const u=(h=e.metadata)!=null&&h.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:"↗"}),u]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,u]})})(),g&&t.jsx("span",{className:"bim-d-meta",children:s(g)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Fo,{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(u=>!u),children:a?o("detail.collapseVolumes"):o("detail.expandVolumes",{n:d.expected})})})]})}function ip({groups:e,listedVolumeCounts:n}){const{t:i,convert:o}=ie();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(gs,{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=Cn(a),c=o(np(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 Kn=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function po(e){var i;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(i=Kn.find(o=>n.startsWith(o.key[0])))==null?void 0:i.key}const ul=12,Ky=60,rp=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,railTop:a,back:l,railLinks:d})=>{var ze,We,ye;const{t:c,convert:p,messages:m}=ie(),g=f.useMemo(()=>zo({_books:e._books}),[e._books]),[u,h]=f.useState(new Map),[x,j]=f.useState(!1),[b,_]=f.useState(""),[y,k]=f.useState(!1),w=g.length<=Ky,v=w||x||!!b||y,C=f.useMemo(()=>v?g:g.slice(0,ul),[g,v]);f.useEffect(()=>{if(!n||C.length===0)return;const H=C.filter(de=>!u.has(de));if(H.length===0)return;let ce=!1;return Zi(H,Xi,de=>n.getItem(de).then(te=>{var Ue;const Ce=te??{};return[de,{id:de,title:Ce.title,edition:Ce.edition,resources:Ce.resources,publication_info:Ce.publication_info,current_location:Ce.current_location,lineage:Ce.lineage,measure_info:Ce.measure_info,summary:Xy((Ue=te==null?void 0:te.description)==null?void 0:Ue.text)}]}).catch(()=>[de,{id:de}]),()=>ce).then(de=>{ce||h(te=>{const Ce=new Map(te);for(const[Ue,Ge]of de)Ce.set(Ue,Ge);return Ce})}),()=>{ce=!0}},[n,C,u]);const $=f.useMemo(()=>g.map(H=>u.get(H)??{id:H}),[g,u]),S=g.length>0&&g.every(H=>u.has(H)),I=!!n&&C.some(H=>!u.has(H)),N=w||v,z=f.useMemo(()=>Zl($,e.version_graph,{era:b,scanOnly:y,sort:N?"year":"default"}),[$,e.version_graph,b,y,N]),E=x?z.rows:z.rows.slice(0,ul),P=z.allRows.filter(H=>H.hasImage).length,A=z.allRows.reduce((H,ce)=>{var de;return H+(((de=ce.copies)==null?void 0:de.length)??0)},0),M=f.useMemo(()=>(e._related||[]).map(H=>({...H,title:H.title??""})),[e._related]),F=M.filter(H=>H.relation==="collected_in"),q=f.useMemo(()=>{const H=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ce=de=>{const te=H.indexOf(de??"");return te<0?H.length:te};return M.filter(de=>de.relation!=="collected_in").map((de,te)=>({r:de,i:te})).sort((de,te)=>ce(de.r.relation)-ce(te.r.relation)||de.i-te.i).map(de=>de.r)},[M]),be=f.useMemo(()=>{const H=_o(e.resources,e.resource_groups);return[...H.mirrors.flatMap(ce=>ce.items.map(de=>({r:de,kind:p(ce.label)}))),...H.buckets.flatMap(ce=>ce.items.map(de=>({r:de,kind:p(qy(ce.key,c))})))]},[e.resources,e.resource_groups,p,c]),se=e.indexed_by||[],Y=e.emendated_by||[],xe=f.useMemo(()=>{var O,ue,Re;const H=[],ce=(ue=(O=e.authors)==null?void 0:O[0])==null?void 0:ue.dynasty;ce&&H.push({label:c("workPage.fact.written"),value:p(ce)});const de=Yt(e,m.unit.juan);if(de){const W=(Re=e.juan_count)==null?void 0:Re.description;H.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(de),W&&W!==de?t.jsxs("span",{className:"bim-d-meta",children:["(",p(W),")"]}):null]})})}e.loss_status&&H.push({label:c("workPage.fact.loss"),value:p(Yy(e.loss_status,c))});const te=z.allRows.filter(W=>W.sortYear!=null),Ce=te.length>0?te.reduce((W,pe)=>W.sortYear<=pe.sortYear?W:pe):null;Ce!=null&&Ce.era.era?H.push({label:c("workPage.fact.earliest"),value:p([Ce.era.era,Ce.era.reign].filter(Boolean).join(" ")),title:Ce.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):I&&H.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),Y.length&&H.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:Y.length})});const Ue=ml(e.additional_titles);Ue.length&&H.push({label:c("workPage.fact.alias"),value:Ue.map(p).join("、")});const Ge=ml(e.attached_texts);Ge.length&&H.push({label:c("workPage.fact.attached"),value:Ge.map(p).join("、")});const nt=(e.additional_works||[]).map(W=>p(W.book_title)+(W.n_juan!=null?` ${W.n_juan}${m.unit.juan}`:""));return nt.length&&H.push({label:c("workPage.fact.appendix"),value:nt.join("、")}),H},[e,p,c,m,I,z.allRows,Y.length]),le=[{value:e._edition_count??g.length,label:c("workPage.stat.editions")},{value:S?P:0,label:c("workPage.stat.hasImage")},{value:se.length,label:c("workPage.stat.catalogs")}],we=No(e),je=we?[we.l1,we.l2,we.l3,we.l4].filter(Boolean).map(H=>p(H)):[],ee=e.subtype?m.workSubtype[e.subtype]??p(e.subtype):"",T=t.jsx(ti,{title:p(e.title),byline:t.jsx(ms,{authors:e.authors,onNavigate:i,renderLink:o}),meta:t.jsx(ft,{items:[...je,we!=null&&we.source?c("workPage.classifiedBy",{source:p(we.source.split("/")[0])}):"",ee]}),description:(ze=e.description)!=null&&ze.text?t.jsxs(t.Fragment,{children:[t.jsx(qt,{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(H=>({text:p(Dm(H)),href:Um(H)})).filter(H=>H.text).map((H,ce)=>t.jsxs(f.Fragment,{children:[ce>0?" · ":null,H.href?t.jsx("a",{href:H.href,target:"_blank",rel:"noopener noreferrer",children:H.text}):H.text]},ce))}):null]}):void 0,stats:le,facts:xe,readAction:s,foot:t.jsx(ni,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(ye=e.appendix)==null?void 0:ye.map((H,ce)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(H.title)}),t.jsx(qt,{text:H.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ce))}),G=z.eras.length>=2?[{key:"",label:c("catalog.all")},...z.eras.map(H=>({key:H,label:`${H} ${z.allRows.filter(ce=>ce.era.era===H).length}`}))]:[],fe=[];g.length&&fe.push({id:"versions",label:c("workPage.sec.versions"),count:g.length}),se.length&&fe.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:se.length}),F.length&&fe.push({id:"collected",label:c("workPage.sec.collected"),count:F.length}),q.length&&fe.push({id:"related",label:c("workPage.sec.related"),count:q.length}),be.length&&fe.push({id:"resources",label:c("workPage.sec.resources"),count:be.length});const ae=g.length===0&&se.length===0,Be=t.jsxs(t.Fragment,{children:[g.length>0&&t.jsxs(ht,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(ft,{items:[c("workPage.versionsTotal",{n:g.length-A}),S&&P?c("workPage.versionsWithImage",{n:P}):"",z.rows.length!==z.allRows.length?c("workPage.versionsCurrent",{n:z.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":I&&G.length===0&&g.length>1?"":void 0,children:[G.length>0&&t.jsx(Gi,{items:G,value:b,onChange:H=>{_(H),j(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Hc,{label:c("workPage.scanOnly"),checked:y,onChange:H=>{k(H),j(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(N?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&Yi(z.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:E.map(H=>{var ce;return t.jsx(Jy,{row:H,measure:(ce=u.get(H.id))==null?void 0:ce.measure_info,loaded:u.has(H.id),onNavigate:i,renderLink:o},`${H.id}:${u.has(H.id)?"r":"p"}`)})})]}),E.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(b||y?"workPage.noVersionsFiltered":"workPage.noVersions")}),!x&&t.jsx(Po,{total:z.rows.length,shown:E.length,unit:c("workPage.moreUnit"),onClick:()=>j(!0)}),z.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),se.length>0&&t.jsx(Qy,{items:se,transport:n,onNavigate:i,renderLink:o}),ae&&t.jsx(ht,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),Oe=(H,ce)=>t.jsx(ut,{id:H,label:p(ce),onNavigate:i,renderLink:o,dense:!0}),Z=f.useMemo(()=>{const H=new Map;for(const ce of q){const de=pl(ce.relation,c);H.set(de,(H.get(de)??0)+1)}return H.size>1?[...H.entries()].sort((ce,de)=>de[1]-ce[1]).slice(0,4).map(([ce,de])=>`${p(ce)} ${de}`).join(" · "):void 0},[q,p,c]),oe=t.jsxs(t.Fragment,{children:[t.jsx(dn,{id:"collected",title:c("workPage.sec.collected"),items:F.map(H=>Oe(H.id,H.title))}),t.jsx(dn,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:q.length}),sub:Z,items:q.map(H=>t.jsxs(t.Fragment,{children:[Oe(H.id,H.title),t.jsx("span",{className:"bim-d-meta",title:H.note?p(H.note):void 0,children:p(pl(H.relation,c))})]}))}),t.jsx(dn,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:be.map(({r:H,kind:ce})=>{const de=p((H.url?$n(H.url):void 0)||H.name),te=Cn(H);return t.jsxs(t.Fragment,{children:[te?t.jsxs("a",{href:te,target:"_blank",rel:"noopener noreferrer",children:[de," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:de}),ce&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ce})]})})})]});return t.jsx(ei,{railTop:a,back:l,nav:fe,railLinks:d,main:Be,card:T,side:oe})};function ml(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function uo(e,n){return n((e.url?$n(e.url):void 0)||e.name)}function Xy(e){var a;if(!e)return;const i=e.replace(/\*\*/g,"").split(/\n/)[0].trim().match(/[^。]+。?/g)??[],s=((i.length>1&&((a=i[0])!=null&&a.startsWith("《"))?i[1]:i[0])??"").trim();return s?s.length>120?`${s.slice(0,120)}…`:s:void 0}function Zy({copies:e,onNavigate:n,renderLink:i}){const{t:o,convert:s}=ie(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?uo(l.holders[0],s):"")||"",c=a.get(d)??[];c.push(l),a.set(d,c)}return t.jsxs("span",{className:"bim-d-zt-copies",children:[o("workPage.sameEditionCopies",{n:e.length}),[...a].map(([l,d],c)=>t.jsxs(f.Fragment,{children:[c>0?";":"",l?`${s(l)} `:"",d.map((p,m)=>t.jsxs(f.Fragment,{children:[m>0?" · ":"",t.jsx(ut,{id:p.id,label:p.callNumber||p.id,onNavigate:n,renderLink:i,dense:!0})]},p.id))]},l||c))]})}function Jy({row:e,measure:n,loaded:i,onNavigate:o,renderLink:s}){const{t:a,convert:l}=ie(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],m=e.copies??[],g=m.length&&e.locationName?l(e.locationName):p?uo(p,l):e.locationName?l(e.locationName):"",u=e.images[0],h=u?Cn(u):void 0,x=e.images.map(j=>uo(j,l)).join("、");return t.jsxs("tr",{"data-loading":i?void 0:"",className:m.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:m.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(ut,{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:" "}),m.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:l(e.summary)}),m.length>0&&t.jsx(Zy,{copies:m,onNavigate:o,renderLink:s})]}),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${g?"":" bim-d-zt-blank"}`,children:[g||(i?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),m.length>0&&e.callNumber&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:e.callNumber}),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(h?t.jsx("a",{className:"bim-d-flag",href:h,target:"_blank",rel:"noopener noreferrer",title:x,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:x,children:a("workPage.hasImage")}))})]})}function Qy({items:e,transport:n,onNavigate:i,renderLink:o}){const{t:s,convert:a}=ie(),[l,d]=f.useState(0),c=Math.min(l,e.length-1),p=e[c],[m,g]=f.useState(new Map);return f.useEffect(()=>{if(!n)return;const u=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(u.length===0)return;let h=!1;return Promise.all(u.map(x=>n.getItem(x).then(j=>{var b,_;return[x,((_=(b=j==null?void 0:j.authors)==null?void 0:b[0])==null?void 0:_.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{h||g(new Map(x.filter(([,j])=>j)))}),()=>{h=!0}},[n,e]),t.jsx(ht,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(ft,{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((u,h)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":h===c,"aria-label":a(u.source),onClick:()=>d(h),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:m.get(u.source_bid??"")?a(m.get(u.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(u.source)].slice(0,9).map((x,j)=>t.jsx("span",{children:x},j))})]})},h))}),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(ft,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(ut,{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:Ct(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:Ct(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:Ct(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 e0(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 t0(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 gl(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 n0(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 i0(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,g]of Object.entries(e.node_groups))l.has(g)&&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 Ci(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=i0(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,g=new Set,u=new Set;if(c){const w=new Map(n.map(N=>[N.id,N])),v=new Map((o.hypothetical_nodes??[]).map(N=>[N.id,N])),C=N=>{const z=w.get(N);if(z&&z.lineage)return(z.lineage.derived_from??[]).map(P=>P.ref);const E=v.get(N);return E?(E.derived_from??[]).map(P=>P.ref):[]},$=N=>v.has(N)?!m||m.has(N):!p||p.has(N),S=new Set,I=N=>{if(!S.has(N)){S.add(N);for(const z of C(N))a.has(z)||($(z)||(v.has(z)?u.add(z):w.has(z)&&g.add(z)),I(z))}};for(const N of n)p&&p.has(N.id)&&!a.has(N.id)&&I(N.id);for(const N of o.hypothetical_nodes??[])m&&m.has(N.id)&&I(N.id)}const h=n.filter(w=>!a.has(w.id)).filter(w=>!p||p.has(w.id)||g.has(w.id)).map(w=>{const v=t0(w,l);return v&&g.has(w.id)&&(v.bridge=!0),v}).filter(w=>w!==null),x=(o.hypothetical_nodes??[]).filter(w=>!m||m.has(w.id)||u.has(w.id)).map(w=>{const v=e0(w);return u.has(w.id)&&(v.bridge=!0),v}),j=[...h,...x],b=new Set(j.map(w=>w.id)),_=new Set,y=[],k=w=>{_.has(w.id)||!b.has(w.source)||!b.has(w.target)||(_.add(w.id),y.push(w))};for(const w of n)a.has(w.id)||!w.lineage||p&&!p.has(w.id)&&!g.has(w.id)||((w.lineage.derived_from??[]).forEach((v,C)=>{k(gl(w.id,v,C))}),(w.lineage.related_to??[]).forEach((v,C)=>{k(n0(w.id,v,C))}));for(const w of o.hypothetical_nodes??[])m&&!m.has(w.id)&&!u.has(w.id)||(w.derived_from??[]).forEach((v,C)=>{k(gl(w.id,v,C))});return{nodes:j,edges:y,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(a)}}function op(e,n,i){const o=(e??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function r0(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 sp=({graph:e,renderLink:n,className:i,style:o})=>{const{t:s,convert:a}=ie();if(!e.nodes.length)return t.jsx("div",{style:{...b0,...o},className:i,children:s("lineage.emptyGraph")});const l=new Map,d=new Map;for(const h of e.edges)if(h.kind==="derive"){const x=l.get(h.target)??[];x.push(h),l.set(h.target,x)}else for(const x of[h.source,h.target]){const j=d.get(x)??[];j.push(h),d.set(x,j)}const c=new Map(e.nodes.map(h=>[h.id,h])),p=new Map,m=[];for(const h of e.nodes)if(h.group){const x=p.get(h.group)??[];x.push(h),p.set(h.group,x)}else m.push(h);const g=(h,x)=>(h.year??9999)-(x.year??9999);p.forEach(h=>h.sort(g)),m.sort(g);const u=e.groups.filter(h=>p.has(h.id));return t.jsxs("div",{className:i,style:{...s0,...o},children:[e.title&&t.jsx("div",{style:a0,children:a(e.title)}),e.description&&t.jsx("div",{style:l0,children:a(e.description)}),u.map(h=>t.jsx(fl,{label:h.label,color:h.color,nodes:p.get(h.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},h.id)),m.length>0&&t.jsx(fl,{label:s("lineage.otherGroup"),nodes:m,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},fl=({label:e,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=ie();return t.jsxs("div",{style:c0,children:[t.jsx("div",{style:{...d0,borderLeftColor:n??r("widget-border")},children:d(e)}),i.map(c=>t.jsx(o0,{node:c,incoming:o.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},o0=({node:e,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=ie();return t.jsxs("div",{style:{...p0,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:u0,children:[t.jsx("span",{style:m0,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:g0,children:op(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:f0,children:[e.category&&t.jsx(Hn,{children:c(e.category)}),e.status==="lost"&&t.jsx(Hn,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Hn,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Hn,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Hn,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:h0,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:x0,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:xl,children:[t.jsx("div",{style:bl,children:d("lineage.sources")}),n.map(p=>{const m=o.get(p.source);return t.jsxs("div",{style:yl(p.confidence),children:[t.jsx("span",{style:jl,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(hl,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:vl,children:["· ",c(p.evidence)]})]},p.id)})]}),i.length>0&&t.jsxs("div",{style:xl,children:[t.jsx("div",{style:bl,children:d("lineage.related")}),i.map(p=>{const m=p.source===e.id?p.target:p.source,g=o.get(m);return t.jsxs("div",{style:yl(p.confidence),children:[t.jsx("span",{style:jl,children:c(p.relation)}),t.jsx("span",{children:(g==null?void 0:g.kind)==="book"&&s?s(g.id,c(g.label)):c((g==null?void 0:g.label)??m)}),t.jsx(hl,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:vl,children:["· ",c(p.evidence)]})]},p.id)})]})]})},Hn=({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})},hl=({level:e})=>{const{t:n}=ie(),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},s0={fontSize:"14px",color:r("fg")},a0={fontSize:"16px",fontWeight:600,marginBottom:"8px"},l0={fontSize:"13px",color:r("muted"),marginBottom:"16px",lineHeight:1.6},c0={marginBottom:"16px"},d0={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r("fg")},p0={border:`1px solid ${r("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r("bg")},u0={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},m0={fontSize:"15px",fontWeight:600},g0={fontSize:"12px",color:r("muted")},f0={marginBottom:"6px"},h0={fontSize:"12px",color:r("muted"),margin:"2px 0"},x0={fontSize:"12px",color:r("muted"),fontStyle:"italic",margin:"4px 0"},xl={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r("widget-border")}`},bl={fontSize:"11px",color:r("muted"),marginBottom:"2px"},yl=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),jl={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r("tag-bg"),color:r("fg"),borderRadius:"3px",marginRight:"6px"},vl={fontSize:"11px",color:r("muted")},b0={padding:"20px",textAlign:"center",color:r("muted"),fontSize:"13px"},ap=({selectedNodeId:e,...n})=>{const{t:i}=ie(),[o,s]=f.useState("loading"),[a,l]=f.useState(null);return f.useEffect(()=>{let d=!1;return y0().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),o==="loading"?t.jsx("div",{style:wl,children:i("lineage.graphLoading")}):o==="missing"||!a?t.jsxs("div",{style:wl,children:[t.jsx("div",{children:kl(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:kl(i("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(j0,{modules:a,selectedNodeId:e,...n})};function kl(e,n){return e.split(/(\{\w+\})/).map((i,o)=>{const s=/^\{(\w+)\}$/.exec(i);return t.jsx(f.Fragment,{children:s&&s[1]in n?n[s[1]]:i},o)})}async function y0(){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 j0=({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:g,BaseEdge:u,EdgeLabelRenderer:h,getSmoothStepPath:x,dagre:j}=l,b=f.useMemo(()=>({lineage:C=>{var F,q,be,se;const $=((F=C.data)==null?void 0:F.stepPosition)??.85,[S,I,N]=x({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:$,borderRadius:5}),z=!!((q=C.data)!=null&&q.isSibling),E=z?I:C.targetX-18,P=z?N:C.targetY-12,A=(be=C.data)==null?void 0:be.labelStyle,M=(se=C.data)==null?void 0:se.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:C.id,path:S,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&t.jsx(h,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${E}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")}`,...M,...A},children:C.label})})]})}}),[u,h,x]),_=f.useMemo(()=>({version:C=>{const{t:$}=ie(),S=C.data,I=S.kind==="hypothetical",N=S.status==="lost",z=S.isSelected,E=S.bridge,P=S.borderColor??r("muted"),A=E||I?"dashed":"solid",M=E?.5:N?.6:1;return t.jsxs("div",{style:{background:r(E?"bg-subtle":"bg"),border:`2px ${A} ${z?r("primary"):P}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:z?r("shadow-node-selected"):I||E?"none":r("shadow-node")},title:E?$("lineage.bridgeTitle"):void 0,children:[t.jsx(m,{type:"target",position:g.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:I||!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:op(S.yearText,void 0,S.uncertain)}),N&&t.jsx("div",{style:{fontSize:9,color:r("lost-fg"),marginTop:1},children:$("lineage.lost")}),t.jsx(m,{type:"source",position:g.Right,style:{visibility:"hidden"}})]})}}),[m,g]),{convert:y}=ie(),{rfNodes:k,rfEdges:w}=f.useMemo(()=>v0(e,j,n,a,y),[e,j,n,a,y]);return t.jsx("div",{style:{width:"100%",height:i,...s},className:o,children:t.jsxs(d,{nodes:k,edges:w,nodeTypes:_,edgeTypes:b,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 v0(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 g=e.nodes.map(_=>{const y=c.node(_.id),k=o?_.id===o:void 0,w={kind:_.kind,label:s(_.label),bookId:_.kind==="book"?_.id:void 0,yearText:s(_.year_text??w0(_)),uncertain:_.year_uncertain,category:_.category,status:_.status,borderColor:_.group?p.get(_.group):void 0,renderLink:i,isSelected:k,description:s(_.description),bridge:_.bridge};return{id:_.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:w,draggable:!1,selected:k}}),u=.78,h=.06,x=new Map;for(const _ of e.edges)_.kind==="derive"&&(x.has(_.source)||x.set(_.source,[]),x.get(_.source).push(_));const j=new Map;for(const[_,y]of x){if(y.length<=1)continue;const k=[...y].sort((v,C)=>{var I,N;const $=((I=c.node(v.target))==null?void 0:I.y)??0,S=((N=c.node(C.target))==null?void 0:N.y)??0;return $-S}),w=k.length;k.forEach((v,C)=>{const $=(C-(w-1)/2)*h;j.set(v.id,u+$)})}const b=e.edges.map(_=>k0(_,j.get(_.id),s));return{rfNodes:g,rfEdges:b}}function k0(e,n,i=o=>o??""){const o=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=S0(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 w0(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function S0(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 wl={padding:"40px 20px",textAlign:"center",color:r("muted"),fontSize:"13px",border:`1px dashed ${r("widget-border")}`,borderRadius:8,background:r("bg")},fs=({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:g})=>{var w;const{t:u,convert:h}=ie(),[x,j]=f.useState(n),b=v=>{j(v),a==null||a(v)},_=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),y=!!(d&&_.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r("muted"),textAlign:"center"},children:u("lineage.empty")});const k=l?(w=c==null?void 0:c[l])==null?void 0:w.description:void 0;return t.jsxs("div",{className:m,style:g,children:[t.jsxs("div",{style:_0,children:[t.jsx("button",{onClick:()=>b("list"),style:Lr(x==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>b("graph"),style:Lr(x==="graph"),children:u("lineage.modeGraph")}),y&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:r("muted"),marginRight:4},children:u("lineage.collectionLabel")}),_.map(([v,C])=>{const $=p==null?void 0:p[v];return t.jsxs("button",{onClick:()=>d==null?void 0:d(v),style:Lr(l===v),title:C.description?h(C.description):void 0,children:[h(C.label),$!=null?` ${$}`:""]},v)})]})]}),y&&k&&t.jsx("div",{style:{fontSize:12,color:r("muted"),marginBottom:8,padding:"4px 8px",background:r("bg-subtle"),borderRadius:4},children:h(k)}),x==="list"?t.jsx(sp,{graph:e,renderLink:i}):t.jsx(ap,{graph:e,renderLink:i,height:o,selectedNodeId:s})]})},_0={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Lr=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"}),Sl=40,_l=2,$0=9,C0=new Set(["certain","consensus","probable","disputed"]);function Ar(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const lp=({data:e,transport:n,onNavigate:i,renderLink:o,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:m})=>{var ue,Re,W,pe,re,Ne,Le,Ve,Xe,ot,it;const g=Pe(),{t:u,convert:h}=ie(),[x,j]=f.useState(null),[b,_]=f.useState(new Map),[y,k]=f.useState([]),[w,v]=f.useState(new Map),[C,$]=f.useState(!1),[S,I]=f.useState("flow"),[N,z]=f.useState(null);f.useEffect(()=>{if(!n||!e.work_id){j(null);return}let R=!1;return n.getItem(e.work_id).then(ge=>{!R&&ge&&ge.type==="work"&&j(ge)}).catch(()=>{}),()=>{R=!0}},[n,e.work_id]),f.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){z(null);return}let R=!1;return n.getLineageGraph(e.work_id).then(ge=>{R||z(ge&&ge.nodes.length>1?ge:null)}).catch(()=>{R||z(null)}),()=>{R=!0}},[n,e.work_id]),f.useEffect(()=>{const R=e._collections||[];if(!n||R.length===0){_(new Map);return}let ge=!1;return Promise.all(R.map(ve=>{const $e=ve.id;return n.getItem($e).then(D=>[$e,D]).catch(()=>[$e,null])})).then(ve=>{if(ge)return;const $e=new Map;for(const[D,B]of ve)B&&$e.set(D,B);_($e)}),()=>{ge=!0}},[n,e._collections]);const E=f.useMemo(()=>{const R=new Set([...x?zo(x):[],...e.related_books||[]]);return R.add(e.id),[...R]},[x,e.related_books,e.id]),P=E.length-1;f.useEffect(()=>{if(!n||P<=0){k([]);return}const R=E.length<=Sl,ge=R?E:E.slice(0,8);let ve=!1;return Promise.all(ge.map($e=>$e===e.id?Promise.resolve({id:$e,title:e.title,edition:e.edition,year:Ni(e)}):n.getItem($e).then(D=>{const B=D??{};return{id:$e,title:B.title,edition:B.edition,year:D?Ni(B):void 0}}).catch(()=>({id:$e})))).then($e=>{if(ve)return;const D=$e.filter(B=>B.id===e.id||B.title||B.edition);R&&D.sort((B,J)=>(B.year??1/0)-(J.year??1/0)),k(D)}),()=>{ve=!0}},[n,E,P,e]);const A=e.lineage,M=f.useMemo(()=>[...((A==null?void 0:A.derived_from)||[]).filter(R=>R.ref_type==="book").map(R=>R.ref),...((A==null?void 0:A.related_to)||[]).map(R=>R.book_id)].filter(Boolean),[A]);f.useEffect(()=>{if(!n||M.length===0){v(new Map);return}let R=!1;return Promise.all(M.map(ge=>n.getItem(ge).then(ve=>[ge,{id:ge,title:ve==null?void 0:ve.title,edition:ve==null?void 0:ve.edition}]).catch(()=>[ge,{id:ge}]))).then(ge=>{R||v(new Map(ge))}),()=>{R=!0}},[n,M]);const F=f.useMemo(()=>tp(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),q=F.groups.reduce((R,ge)=>R+ge.rows.length+ge.mirrors.length,0),be=F.groups.length>0&&F.groups.every(R=>R.key==="_physical"),se=Qn(e),Y=nc(e),xe=Yt(e,g.unit.juan),Q=new Set((e._collections||[]).map(R=>Gn(R.vol).length).filter(R=>R>0)),le=R=>{var $e;const ge=($e=e.base_edition)==null?void 0:$e.find(D=>D.book_id===R&&D.name);if(ge!=null&&ge.name)return ge.name;const ve=w.get(R);return(ve==null?void 0:ve.edition)||(ve==null?void 0:ve.title)||""},we=f.useMemo(()=>{var V,U,Me,He,_e;const R=[];Y&&R.push({label:u("bookPage.fact.editionType"),value:h(Y),title:e.edition_type||(V=e.lineage)!=null&&V.category?void 0:u("bookPage.inferredFromEdition")}),(U=e.publication_info)!=null&&U.details?R.push({label:u("bookPage.fact.publication"),value:h(e.publication_info.details)}):(se.era||se.reign)&&R.push({label:u("bookPage.fact.era"),value:h([se.era,se.reign].filter(Boolean).join(" ")),title:se.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),xe&&R.push({label:u("bookPage.fact.measure"),value:h(xe)});const ge=(e._collections||[]).flatMap(X=>Gn(X.vol));ge.length&&R.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Fi(ge,g.unit.volume),unit:g.unit.volume,n:ge.length})});const ve=(((Me=e.lineage)==null?void 0:Me.derived_from)||[]).find(X=>X.relation==="底本"&&X.ref_type==="book");ve&&le(ve.ref)&&R.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(ut,{id:ve.ref,label:h(le(ve.ref)),onNavigate:i,renderLink:o,dense:!0})});const $e=(e.base_edition||[]).filter(X=>X&&X.name);for(const X of["底本","配補","參校"]){if(X==="底本"&&ve&&le(ve.ref))continue;const ke=$e.filter(he=>he.role===X);ke.length&&R.push({label:h(X),value:ke.map((he,Ie)=>t.jsxs(f.Fragment,{children:[Ie>0&&"、",he.book_id?t.jsx(ut,{id:he.book_id,label:h(he.name),onNavigate:i,renderLink:o,dense:!0}):h(he.name)]},Ie))})}const D=(e.provenance||[]).filter(X=>X&&X.institution),B=(e.resources||[]).filter(X=>Gt(X).includes("physical"));if(D.length){R.push({label:u("bookPage.fact.holdings"),value:D.slice(0,2).map(he=>h(he.institution)).join("、")+(D.length>2?u("bookPage.andMorePlaces",{n:D.length}):"")});const X=D.filter(he=>he.call_number).slice(0,2).map(he=>`${h(he.institution)} ${he.call_number}`);X.length&&R.push({label:u("bookPage.fact.callNumber"),value:X.join(";")+(D.filter(he=>he.call_number).length>2?"…":"")});const ke=D.flatMap(he=>he.seals||[]).filter(Boolean);ke.length&&R.push({label:u("bookPage.fact.seals"),value:h(ke.join("、"))})}else B.length?R.push({label:u("bookPage.fact.holdings"),value:B.slice(0,2).map(X=>h(X.name)).join("、")+(B.length>2?u("bookPage.andMorePlaces",{n:B.length}):"")}):(He=e.current_location)!=null&&He.name&&R.push({label:u("bookPage.fact.holdings"),value:h(e.current_location.name)});const J=e.physical_description;if(J){const X=[[u("bookPage.fact.leafStyle"),J.leaf_style],[u("bookPage.fact.binding"),J.binding],[u("bookPage.fact.dimensions"),J.dimensions],[u("bookPage.fact.condition"),J.condition]];for(const[ke,he]of X)he&&he.trim()&&R.push({label:ke,value:h(he)})}(_e=e.page_count)!=null&&_e.description&&R.push({label:g.label.pageCount,value:h(e.page_count.description)});const me=[...Jr(e.additional_titles),...Jr(e.attached_texts)];return me.length&&R.push({label:u("bookPage.fact.aliases"),value:me.map(h).join("、")}),R},[e,h,g,u,se,Y,xe,w,i,o]),je=h(e.title),ee=e.edition?h(e.edition):void 0,T=((ue=e.lineage)==null?void 0:ue.year_text)||"",G=t.jsx(ti,{kind:u("bookPage.kind"),title:je,subtitle:ee,byline:t.jsx(ms,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:i,renderLink:o}),meta:(()=>{const R=[Y?h(Y):"",se.era?h([se.era,se.reign].filter(Boolean).join("")):"",xe?h(xe):""].filter(Boolean);return R.length?t.jsx("span",{className:"bim-d-tags",children:R.map((ge,ve)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ve,2)}`,children:ge},ve))}):null})(),description:(Re=e.description)!=null&&Re.text?t.jsx(qt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Oo((W=e.description)==null?void 0:W.text)?6:void 0,facts:we,readAction:s,secondaryAction:s&&q>0&&!be?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(ni,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),fe=e._collections||[],ae=(a==null?void 0:a.chapters)||[],Be=h(ae[0]&&Ar(ae[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),Oe=u("bookPage.chapterCount",{n:ae.length,unit:Be}),Z=!!((pe=A==null?void 0:A.derived_from)!=null&&pe.length||(re=A==null?void 0:A.related_to)!=null&&re.length||(Ne=e.appendix)!=null&&Ne.length),oe=[],ze=u(be?"bookPage.sec.physical":"bookPage.sec.images");(ae.length||F.text.length||l)&&oe.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:ae.length?Oe:void 0}),F.groups.length&&oe.push({id:"images",label:ze,count:q}),Z&&oe.push({id:"lineage",label:u("bookPage.sec.lineage")}),fe.length&&oe.push({id:"collections",label:u("section.containedIn"),count:fe.length}),(Le=e.location_history)!=null&&Le.length&&oe.push({id:"provenance",label:u("section.locationHistory")});const We=R=>(d==null?void 0:d(R))??null,ye=ae[0],H=ye?We(ye.file):null,ce=C?ae:ae.slice(0,$0),de=(R,ge,ve)=>R?t.jsx("a",{className:ve,href:R.href??"#",onClick:R.onClick?$e=>{$e.metaKey||$e.ctrlKey||($e.preventDefault(),R.onClick())}:void 0,children:ge}):t.jsx("span",{className:ve,children:ge}),te=t.jsxs(t.Fragment,{children:[(ae.length>0||F.text.length>0||l)&&t.jsxs(ht,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:ae.length>0?t.jsx(ft,{items:[Oe,(Ve=a==null?void 0:a.source)!=null&&Ve.name?u("bookPage.sourceBy",{src:h(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!ye&&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"})]}),ye&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:h(Ar(ye.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:h((ye.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),de(H,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ae.length>1&&t.jsx("ul",{className:"bim-d-chap",children:ce.map(R=>{const[ge,ve]=Ar(R.title);return t.jsx("li",{children:de(We(R.file),t.jsxs(t.Fragment,{children:[ge&&t.jsx("b",{children:h(ge)}),h(ve||R.file)]}))},R.file)})}),ae.length>ce.length&&t.jsx(Bo,{label:u("detail.expandRest",{n:ae.length-ce.length,unit:Be}),onClick:()=>$(!0)}),F.text.length>0&&t.jsxs(t.Fragment,{children:[(ae.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:u("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:F.text.map((R,ge)=>t.jsx(gs,{item:R,siblings:F.text,listedVolumeCounts:Q},`${R.id||R.url||R.name}-${ge}`))})})]})]}),F.groups.length>0&&t.jsx(ht,{id:"images",title:ze,meta:t.jsx(ft,{items:[F.groups.length>1?u("bookPage.groupCount",{n:F.groups.length}):"",u("bookPage.placeCount",{n:q})]}),children:t.jsx(ip,{groups:F.groups,listedVolumeCounts:Q})}),Z&&t.jsx(ht,{id:"lineage",title:u("bookPage.sec.lineage"),meta:(Xe=A==null?void 0:A.derived_from)!=null&&Xe.length?u("bookPage.lineageMeta"):void 0,action:N?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":u("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":S==="flow",onClick:()=>I("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":S==="graph",onClick:()=>I("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:S==="graph"&&N?t.jsx(fs,{graph:N,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(R,ge)=>t.jsx(ut,{id:R,label:h(ge),onNavigate:i,renderLink:o,dense:!0})}):t.jsx(N0,{data:e,heading:ee||je,yearText:T,refName:le,onNavigate:i,renderLink:o})}),fe.length>0&&t.jsx(ht,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:fe.map((R,ge)=>{const ve=R.id,$e=Gn(R.vol),D=b.get(ve),B=Fm(D);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(ut,{id:ve,label:D?h(D.title):ve,onNavigate:i,renderLink:o,dense:!0}),$e.length>0&&t.jsx(z0,{volumes:$e,unit:g.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:B>0&&u("bookPage.totalOf",{n:B,unit:g.unit.bu})})]},`${ve}-${ge}`)})})})}),(ot=e.location_history)!=null&&ot.length?t.jsx(ht,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((R,ge)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:h(R.name)}),([R.start_date,R.end_date].filter(Boolean).join("—")||R.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(ft,{items:[[R.start_date,R.end_date].filter(Boolean).join("—"),R.description?h(R.description):""]})})]},ge))})}):null,oe.length===0&&t.jsx(ht,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),Ce=y.findIndex(R=>R.id===e.id),Ue=E.length<=Sl,Ge=Ue&&Ce>=0?y.slice(Math.max(0,Ce-_l),Ce+_l+1):y.filter(R=>R.id!==e.id),nt=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:h(g.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(ut,{id:x.id,label:h(x.title),onNavigate:i,renderLink:o})}),t.jsx(ft,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(R=>`${R.dynasty?`〔${h(R.dynasty)}〕`:""}${h(R.name)}`),h(Yt(x,g.unit.juan)),x._edition_count?u("bookPage.editionCount",{n:x._edition_count}):""]}),((it=x.description)==null?void 0:it.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:h(x.description.text.replace(/[#*_>`[\]]/g,""))})]}),P>0&&Ge.length>0&&t.jsxs("div",{children:[t.jsx(dn,{id:"siblings",timeline:!0,title:Ue?u("bookPage.siblings"):g.relation.siblingVersions,meta:Ue?u("bookPage.byEra"):u("bookPage.kindCount",{n:P}),cap:Ge.length,items:Ge.map(R=>R.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:h(R.edition||R.title||R.id)}):t.jsx(ut,{id:R.id,label:h(R.edition||R.title||R.id),onNavigate:i,renderLink:o,dense:!0})),metas:Ge.map(R=>[R.year!=null?R.year<0?u("detail.bce",{n:-R.year}):String(R.year):"",R.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:Ge.findIndex(R=>R.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(ut,{id:x.id,label:u("bookPage.viewAllInWork",{n:E.length}),onNavigate:i,renderLink:o,dense:!0})})]})]}),O=e.work_id?t.jsx(Fc,{caption:g.section.belongsToWork,children:t.jsx(ut,{id:e.work_id,label:x?h(x.title):" ",onNavigate:i,renderLink:o,dense:!0})}):void 0;return t.jsx(ei,{railTop:c,back:p,up:O,nav:oe,railLinks:m,main:te,card:G,side:nt})};function z0({volumes:e,unit:n}){const{t:i}=ie();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[i("bookPage.volumeRange",{range:Fi(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 N0({data:e,heading:n,yearText:i,refName:o,onNavigate:s,renderLink:a}){var _;const{t:l,convert:d}=ie(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],m=p.filter(y=>y.ref_type!=="book"),g=p.filter(y=>y.ref_type==="book"&&y.relation==="底本"),u=p.filter(y=>y.ref_type==="book"&&y.relation!=="底本"),h=(c==null?void 0:c.related_to)||[],x=p.length>0||h.length>0,j=y=>y&&C0.has(y)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${y}`)}):"",b=(y,k)=>t.jsx(ut,{id:y,label:d(k||y),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((y,k)=>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:y.relation?d(y.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),y.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(y.evidence),j(y.confidence)]})]})},`a-${k}`)),g.map((y,k)=>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(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:b(y.ref,o(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(y.evidence),j(y.confidence)]})]})},`b-${k}`)),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)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((y,k)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(y.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:b(y.ref,o(y.ref))}),y.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(y.evidence),j(y.confidence)]})]},k))})]}),h.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:h.map((y,k)=>t.jsxs("span",{className:"bim-d-lf-chip",title:y.evidence?d(y.evidence):void 0,children:[b(y.book_id,o(y.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(y.relation)})]},k))})]})]}),(_=e.appendix)==null?void 0:_.map((y,k)=>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(y.title)]}),t.jsx(qt,{text:y.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${k}`)),(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 Dn=16,T0=200,E0=16,cp=({data:e,catalog:n,transport:i,onNavigate:o,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var Ce,Ue,Ge,nt,O,ue,Re;const{t:p,convert:m,messages:g}=ie(),[u,h]=f.useState(""),[x,j]=f.useState(!1),[b,_]=f.useState(null),[y,k]=f.useState(""),[w,v]=f.useState(!1),C=f.useMemo(()=>tc(e,n),[e,n]),$=f.useMemo(()=>ec(e),[e]),[S,I]=f.useState(new Map),N=!!i&&C.rows.length>0&&C.rows.length<=T0,z=N&&(C.rows.length<=Dn||w),E=z&&C.rows.every(W=>!W.id||S.has(W.id)),P=W=>{var pe;return po(W?(pe=S.get(W))==null?void 0:pe.l1:void 0)},A=f.useMemo(()=>{const W=u.trim(),pe=W?m(W):"";return C.rows.filter(re=>{var Le,Ve;if(y&&po(re.id?(Le=S.get(re.id))==null?void 0:Le.l1:void 0)!==y)return!1;if(!pe)return!0;const Ne=re.id&&((Ve=S.get(re.id))==null?void 0:Ve.title)||re.title;return m(Ne).includes(pe)||(re.subItems||[]).some(Xe=>m(Xe).includes(pe))})},[C.rows,u,y,S,m]),M=x?A:A.slice(0,Dn),F=f.useMemo(()=>(z?C.rows:M).filter(W=>W.id&&!S.has(W.id)).map(W=>W.id),[z,C.rows,M,S]);f.useEffect(()=>{if(!i||F.length===0)return;let W=!1;const pe=F.slice(0,E0);return Zi(pe,Xi,re=>i.getItem(re).then(Ne=>{var Xe,ot;const Le=Ne??{},Ve={title:Le.title,edition:Le.edition,authors:Le.authors,measure:Ne?Yt(Ne,g.unit.juan):void 0,versionCount:Le._edition_count??((Xe=Le._books)==null?void 0:Xe.length),l1:((ot=No(Le))==null?void 0:ot.l1)||void 0};return[re,Ve]}).catch(()=>[re,{}]),()=>W).then(re=>{W||I(Ne=>{const Le=new Map(Ne);for(const[Ve,Xe]of re)Le.set(Ve,Xe);return Le})}),()=>{W=!0}},[i,F,g.unit.juan]);const q=(Ce=(e.contained_in||[])[0])==null?void 0:Ce.id;f.useEffect(()=>{if(!q){_(null);return}if(_({id:q}),!i)return;let W=!1;return i.getItem(q).then(pe=>{W||_({id:q,title:pe==null?void 0:pe.title})}).catch(()=>{}),()=>{W=!0}},[i,q]);const be=f.useMemo(()=>tp(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),se=be.text.length+be.groups.reduce((W,pe)=>W+pe.rows.length+pe.mirrors.length,0),Y=$.works,xe=new Set(C.rows.map(W=>W.id).filter(Boolean)),Q=Y.length>0&&!Y.every(W=>xe.has(W.id)),le=(()=>{const W=C.rows.map(pe=>pe.edition).filter(Boolean);return W.length>1&&new Set(W).size===1})(),we=C.rows.some(W=>W.volumes.length>0||W.expected!=null),je=$.total,ee=$.truncated?je:C.rows.length,T=Yt(e,g.unit.juan),G=e.count,fe=W=>typeof W=="number"&&Number.isFinite(W)?W:null,ae=fe(G==null?void 0:G.juan)??fe((Ue=e.juan_count)==null?void 0:Ue.number),Be=fe(G==null?void 0:G.ce)??(C.totalVolumes||null),Oe=[{value:ee,label:p("collectionPage.stat.titles")},{value:ae??0,label:g.unit.juan},{value:Be??0,label:g.unit.volume}],Z=f.useMemo(()=>{var re,Ne;const W=[];if((re=e.publication_info)!=null&&re.details&&W.push({label:p("collectionPage.fact.publication"),value:m(e.publication_info.details)}),je&&(je!==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");W.push({label:Le,value:`${je} ${g.unit.bu}`,title:p("collectionPage.memberNote")})}const pe=[fe(G==null?void 0:G.zhong)!=null?p("collectionPage.nZhong",{n:G.zhong}):"",fe(G==null?void 0:G.han)!=null?p("collectionPage.nHan",{n:G.han}):""].filter(Boolean);return pe.length&&W.push({label:p("collectionPage.fact.expected"),value:pe.join(" ")}),ae==null&&T&&W.push({label:p("collectionPage.fact.measure"),value:m(T),title:(Ne=e.juan_count)!=null&&Ne.description?m(e.juan_count.description):void 0}),W},[e,je,$.truncated,C.rows.length,ae,T,G,m,p,g]),oe=f.useMemo(()=>{if(!E)return[];const W=new Map;for(const re of C.rows){const Ne=P(re.id);Ne&&W.set(Ne,(W.get(Ne)??0)+1)}const pe=Kn.filter(re=>(W.get(re.key)??0)>0);return pe.length<2?[]:[{key:"",label:`${g.catalog.all} ${ee}`},...pe.map(re=>({key:re.key,label:`${re.label} ${W.get(re.key)}`}))]},[E,C.rows,S,g]),ze=f.useMemo(()=>{if(!E||!C.rows.some(Ne=>Ne.volumes.length>0))return null;const W=[],pe=C.rows.filter(Ne=>Ne.volumes.length>0).map(Ne=>({k:P(Ne.id)??"",from:Math.min(...Ne.volumes),to:Math.max(...Ne.volumes)})).sort((Ne,Le)=>Ne.from-Le.from);for(const Ne of pe){const Le=Ne.to-Ne.from+1,Ve=W[W.length-1];Ve&&Ve.key===Ne.k?(Ve.to=Math.max(Ve.to,Ne.to),Ve.n+=Le):W.push({key:Ne.k,from:Ne.from,to:Ne.to,n:Le})}const re=pe.reduce((Ne,Le)=>Math.max(Ne,Le.to),0);return W.length>1&&W.some(Ne=>Ne.key)?{segs:W,last:re}:null},[E,C.rows,S]),We=(Ge=e.description)==null?void 0:Ge.text,ye=t.jsx(ti,{kind:p("collectionPage.kind"),title:m(e.title),byline:t.jsx(ms,{authors:e.authors,onNavigate:o,renderLink:s}),meta:t.jsx(ft,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(nt=e.publication_info)!=null&&nt.year?m(e.publication_info.year):""]}),description:We||(O=e.history)!=null&&O.length?t.jsxs(t.Fragment,{children:[We&&t.jsx(qt,{text:We,style:{fontSize:15,lineHeight:1.85}}),(ue=e.history)!=null&&ue.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((W,pe)=>t.jsx("li",{children:m(W)},pe))}):null]}):void 0,clampDescription:Oo(We)||(((Re=e.history)==null?void 0:Re.length)??0)>2?6:void 0,stats:Oe,facts:Z,foot:t.jsx(ni,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ze&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:p("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":p("collectionPage.dist.head"),children:ze.segs.map((W,pe)=>{const re=Kn.find(Ne=>Ne.key===W.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!re,title:re?p("collectionPage.dist.segTitle",{section:m(re.label),from:W.from,to:W.to}):void 0,"aria-label":re?p("collectionPage.dist.only",{section:m(re.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!re&&y===W.key,style:{flexGrow:W.n,background:r(re?re.token:"rule")},onClick:()=>{re&&(k(y===W.key?"":W.key),j(!1))}},pe)})}),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:ze.last})})]})]})}),H=[];C.rows.length&&H.push({id:"titles",label:p("collectionPage.sec.titles"),count:ee}),se&&H.push({id:"resources",label:p("collectionPage.sec.resources"),count:se}),Q&&H.push({id:"works",label:g.section.containedWorks,count:Y.length});const ce=t.jsxs(t.Fragment,{children:[C.rows.length>0&&t.jsxs(ht,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(ft,{items:[`${ee} ${g.unit.items}`,C.totalVolumes?p("collectionPage.totalVolumes",{n:C.totalVolumes,unit:g.unit.volume}):"",A.length!==ee?p("collectionPage.currentN",{n:A.length,unit:g.unit.items}):""]}),action:a,children:[(C.rows.length>Dn||oe.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[oe.length>0&&t.jsx(Gi,{items:oe,value:y,onChange:W=>{k(W),j(!1)}}),N&&C.rows.length>Dn&&!E&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:w,onClick:()=>v(!0),title:p("collectionPage.loadAllTitle",{n:C.rows.length,unit:g.unit.items}),children:p(w?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),C.rows.length>Dn&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:W=>{h(W.target.value),j(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Yi(A.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[we&&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:M.map((W,pe)=>{var it;const re=W.id?S.get(W.id):void 0,Ne=re!=null&&re.title&&W.title===W.id?re.title:W.title,Le=((re==null?void 0:re.authors)||[]).find(R=>R&&R.name),Ve=[Le?`${Le.dynasty?`〔${m(Le.dynasty)}〕`:""}${m(Le.name)}${Le.role?` ${m(Le.role)}`:""}`:"",re!=null&&re.measure?m(re.measure):"",(it=W.subItems)!=null&&it.length?W.subItems.map(R=>m(R)).join("、"):"",(re!=null&&re.edition||W.edition)&&!le?m((re==null?void 0:re.edition)||W.edition||""):""].filter(Boolean),Xe=Kn.find(R=>R.key===P(W.id)),ot=W.volumes.length>0?p("collectionPage.volumeRange",{range:Fi(W.volumes,g.unit.volume),unit:g.unit.volume}):W.expected!=null?`${W.found??0}/${W.expected} ${g.unit.volume}`:"";return t.jsxs("tr",{children:[we&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ot?"":" bim-d-zt-blank"}`,children:[Xe&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r(Xe.token)}}),ot||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[W.id?t.jsx(ut,{id:W.id,label:m(Ne),onNavigate:o,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:m(Ne)}),Ve.length>0?t.jsx(ft,{items:Ve}):W.id&&!re&&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${re!=null&&re.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:re!=null&&re.versionCount?p("collectionPage.nZhong",{n:re.versionCount}):""})]},`${W.id??W.title}-${pe}`)})})]}),M.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:p("catalog.noMatch")}),!x&&t.jsx(Po,{total:A.length,shown:M.length,unit:g.unit.items,onClick:()=>j(!0)})]}),se>0&&t.jsxs(ht,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:se}),children:[be.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[be.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:be.text.map((W,pe)=>t.jsx(gs,{item:W,siblings:be.text},`${W.id||W.url||W.name}-${pe}`))})})]}),t.jsx(ip,{groups:be.groups})]}),C.rows.length===0&&se===0&&t.jsx(ht,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),de=Q?t.jsx(dn,{id:"works",title:g.section.containedWorks,meta:p("collectionPage.nZhong",{n:Y.length}),cap:12,items:Y.map(W=>t.jsx(ut,{id:W.id,label:m(W.title),onNavigate:o,renderLink:s,dense:!0}))}):null,te=b?t.jsx(Fc,{caption:p("collectionPage.parent"),children:t.jsx(ut,{id:b.id,label:m(b.title||b.id),onNavigate:o,renderLink:s,dense:!0})}):void 0;return t.jsx(ei,{railTop:l,back:d,up:te,nav:H,railLinks:c,main:ce,card:ye,side:de})},I0=8;function dp(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(n=>n==="..")?null:e}function R0(e){return(e||[]).filter(n=>{var i,o;return dp(n==null?void 0:n.file)&&((i=n.credit)==null?void 0:i.trim())&&((o=n.license)==null?void 0:o.trim())}).slice(0,I0)}function L0({images:e,assetBase:n,name:i}){const{t:o,convert:s}=ie(),[a,l]=f.useState(0),[d,c]=f.useState(!1),p=n?R0(e):[];if(!n||d||p.length===0)return null;const m=n.endsWith("/")?n:n+"/",g=p[Math.min(a,p.length-1)],u=g.width&&g.height&&g.width>0&&g.height>0?`${g.width} / ${g.height}`:void 0,h=x=>m+dp(x.file).split("/").map(encodeURIComponent).join("/");return t.jsxs("figure",{className:"bim-d-seal bim-d-ui",children:[t.jsx("img",{className:"bim-d-seal-main",src:h(g),alt:o("entityPage.sealAlt",{name:i})+(p.length>1?` ${a+1}`:""),style:u?{"--seal-ar":u}:void 0,width:g.width,height:g.height,decoding:"async",fetchPriority:"high",onError:()=>c(!0)},g.file),p.length>1&&t.jsx("div",{className:"bim-d-seal-thumbs",children:p.map((x,j)=>t.jsx("button",{type:"button","aria-pressed":j===a,"aria-label":`${o("entityPage.sealAlt",{name:i})} ${j+1}`,onClick:()=>l(j),children:t.jsx("img",{src:h(x),alt:"",loading:"lazy",decoding:"async"})},x.file))}),t.jsxs("figcaption",{children:[o("entityPage.imgCredit",{credit:s(g.credit)})," · ",o("entityPage.imgLicense",{license:s(g.license)}),g.source_url&&/^https?:\/\//i.test(g.source_url)&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:g.source_url,target:"_blank",rel:"noopener noreferrer nofollow",children:o("entityPage.imgSource")})]}),g.note&&t.jsxs(t.Fragment,{children:[" · ",s(g.note)]})]})]})}const A0=16,Mr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function $l(e){if(!e)return Mr.length;const n=Mr.indexOf(e);return n===-1?Mr.length:n}function M0(e,n,i){if(n)return e[n]??i(n)}function P0(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const B0={秦:[-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]},pp=({data:e,transport:n,onNavigate:i,renderLink:o,railTop:s,back:a,railLinks:l,assetBase:d})=>{var te,Ce,Ue,Ge,nt;const{t:c,convert:p,messages:m}=ie(),g=O=>P0(O,c),[u,h]=f.useState("全部"),[x,j]=f.useState(!1),[b,_]=f.useState("default"),[y,k]=f.useState(new Map),w=f.useMemo(()=>e._works||[],[e._works]),v=f.useMemo(()=>w.map(O=>{const ue=y.get(O.work_id);return{id:O.work_id,title:(ue==null?void 0:ue.title)??O.title??O.work_id,role:O.role||"",cls:$o(O.role),versionCount:ue==null?void 0:ue.versionCount,section:ue==null?void 0:ue.cls,l1:ue==null?void 0:ue.l1,measure:ue==null?void 0:ue.measure,hasImage:ue==null?void 0:ue.hasImage,loaded:!!(ue!=null&&ue.loaded)}}),[w,y]),C=f.useMemo(()=>Ql(w.map(O=>O.role),c("detail.roleAll")),[w,c]),$=f.useMemo(()=>{const O=u==="全部"?v:v.filter(ue=>ue.cls===u);return b==="versions"?[...O].sort((ue,Re)=>(Re.versionCount??-1)-(ue.versionCount??-1)):O},[v,u,b]),S=x?$:$.slice(0,A0),I=f.useMemo(()=>S.filter(O=>!y.has(O.id)).map(O=>O.id),[S,y]);f.useEffect(()=>{if(!n||I.length===0)return;let O=!1;return Zi(I,Xi,ue=>n.getItem(ue).then(Re=>{var Le;const W=Re??{},pe=W._edition_count??((Le=W._books)==null?void 0:Le.length)??0,re=No(W),Ne=[re==null?void 0:re.l1,re==null?void 0:re.l2].filter(Boolean).join(" ");return[ue,{id:ue,title:W.title,versionCount:pe,loaded:!0,cls:Ne||void 0,l1:(re==null?void 0:re.l1)||void 0,measure:Re&&Yt(Re,m.unit.juan)||void 0,hasImage:!!W._has_image}]}).catch(()=>[ue,{id:ue,loaded:!0}]),()=>O).then(ue=>{O||k(Re=>{const W=new Map(Re);for(const[pe,re]of ue)W.set(pe,re);return W})}),()=>{O=!0}},[n,I,m.unit.juan]);const N=f.useMemo(()=>{const O=new Map;for(const ue of e.alt_names||[]){const Re=ue.type||m.section.aliases;O.has(Re)||O.set(Re,[]),O.get(Re).push(ue.name)}return[...O.entries()].sort((ue,Re)=>$l(ue[0])-$l(Re[0])).map(([ue,Re])=>({label:ue,names:Re}))},[e.alt_names,m]),z=((te=e.dates)==null?void 0:te.birth)??void 0,E=((Ce=e.dates)==null?void 0:Ce.death)??void 0,P=(Ue=e.dates)==null?void 0:Ue.floruit,A=z!=null||E!=null?`${g(z)||"?"}—${g(E)||"?"}`:Array.isArray(P)&&P.length===2&&P.every(O=>Number.isFinite(O))?c("entityPage.floruit",{from:g(P[0]),to:g(P[1])}):"",M=new Set(["本名","字","號","号"]),F=N.filter(O=>M.has(O.label)),q=N.filter(O=>!M.has(O.label)),be=q.reduce((O,ue)=>O+ue.names.length,0),se=f.useMemo(()=>{const O=[];for(const Re of F)O.push({label:Re.label,value:Re.names.map(W=>p(W)).join("、")});const ue=w.length;return ue&&O.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:ue})}),O},[w,F,p,c]),Y=O=>{var ue;return(ue=N.find(Re=>O.includes(Re.label)))==null?void 0:ue.names[0]},xe=Y(["字"]),Q=Y(["號","号"]),le=[xe?c("entityPage.zi",{name:p(xe)}):"",Q?c("entityPage.hao",{name:p(Q)}):""].filter(Boolean).join(","),we=e.native_place,je=e.dynasty?B0[e.dynasty]:void 0,ee=(()=>{if(!je||z==null||E==null||E<z)return null;const[O,ue]=je,Re=Math.max(z,O),W=Math.min(E,ue);if(W<=Re)return null;const pe=ue-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":c("entityPage.lifeAria",{birth:g(z),death:g(E),years:E-z+1}),children:t.jsx("i",{style:{left:`${(Re-O)/pe*100}%`,width:`${(W-Re)/pe*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${g(O)} ${p(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:E-z+1})}),t.jsx("span",{children:g(ue)})]})]})})(),T=f.useMemo(()=>{if(!n||v.length===0||v.some(Re=>!Re.loaded))return null;const O=new Map;for(const Re of v){const W=po(Re.l1);W&&O.set(W,(O.get(W)??0)+1)}const ue=Kn.map(Re=>({...Re,n:O.get(Re.key)??0})).filter(Re=>Re.n>0);return ue.length?ue:null},[v,n]),G=t.jsxs(ti,{kind:M0(m.entityPage.subtype,e.subtype,p),title:p(e.primary_name||e.title),subtitle:le||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(ft,{items:[e.dynasty?p(e.dynasty):"",A,we?c("entityPage.nativePlace",{place:p(we)}):""]}),ee,t.jsx(L0,{images:e.images,assetBase:d,name:p(e.primary_name||e.title)})]}),description:(Ge=e.description)!=null&&Ge.text?t.jsx(qt,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Oo((nt=e.description)==null?void 0:nt.text)?6:void 0,facts:se,foot:t.jsx(ni,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[be>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:be})}),t.jsx("dl",{children:q.map(O=>t.jsxs(f.Fragment,{children:[t.jsx("dt",{children:p(O.label)}),t.jsx("dd",{children:O.names.map(ue=>p(ue)).join("、")})]},O.label))})]}),T&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:T.map(O=>t.jsx("i",{style:{flexGrow:O.n,background:r(O.token)}},O.key))}),t.jsx("div",{className:"bim-d-dist-key",children:T.map(O=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r(O.token)}}),p(O.label)," ",O.n]},O.key))})]})]}),fe=f.useMemo(()=>v.filter(O=>O.loaded&&(O.versionCount??0)>0).sort((O,ue)=>(ue.versionCount??0)-(O.versionCount??0)).slice(0,3),[v]),ae=!!n&&v.length>=3&&S.some(O=>!O.loaded),Be=u==="全部"&&(ae||fe.length>=2),Oe=e.external_ids||{},Z=[];Oe.cbdb_id!=null&&Z.push({label:"CBDB",id:String(Oe.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${Oe.cbdb_id}`,note:Oe.cbdb_match==="auto"?c("entityPage.autoMatch"):void 0});const oe=Oe.wikidata_id;oe&&Z.push({label:"Wikidata",id:oe,href:`https://www.wikidata.org/wiki/${oe}`});const ze=Oe.viaf_id;ze&&Z.push({label:"VIAF",id:ze,href:`https://viaf.org/viaf/${ze}`});const We=C.map(O=>({key:O.cls,label:`${O.label} ${O.count}`})),ye=[...Be&&!ae?[{id:"featured",label:c("entityPage.sec.featured"),count:fe.length}]:[],...v.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:v.length}]:[],...Z.length?[{id:"external",label:c("entityPage.sec.external"),count:Z.length}]:[]],H=Be?t.jsxs(ht,{id:"featured",title:c("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":ae||void 0,children:[ae&&[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)),!ae&&fe.map(O=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(ut,{id:O.id,label:p(O.title),onNavigate:i,renderLink:o,dense:!0})}),t.jsx(ft,{items:[O.section?p(O.section):"",O.measure?p(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:c("entityPage.versionsUnit")}),O.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},O.id))]})]}):null,ce=v.length===0?t.jsx(ht,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}):t.jsxs(t.Fragment,{children:[H,t.jsxs(ht,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(ft,{items:[c("entityPage.total",{n:v.length}),$.length!==v.length?c("entityPage.current",{n:$.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[We.length>1&&t.jsx(Gi,{items:We,value:u,onChange:O=>{h(O),j(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":b==="versions",onClick:()=>{b==="default"&&j(!0),_(O=>O==="default"?"versions":"default")},children:c(b==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&Yi($.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("entityPage.col.work")}),t.jsx("th",{children:c("entityPage.col.section")}),t.jsx("th",{children:c("entityPage.col.role")}),t.jsx("th",{children:c("entityPage.col.versions")}),t.jsx("th",{"aria-label":c("entityPage.col.image")})]})}),t.jsx("tbody",{children:S.map(O=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(ut,{id:O.id,label:p(O.title),onNavigate:i,renderLink:o,dense:!0}),O.measure?t.jsx(ft,{items:[p(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?p(O.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${O.role?"":" bim-d-zt-blank"}`,children:O.role?p(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?c("entityPage.nZhong",{n:O.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("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:c("entityPage.hasImage")})})]},O.id))})]}),S.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!x&&t.jsx(Po,{total:$.length,shown:S.length,unit:c("entityPage.moreUnit"),onClick:()=>j(!0)})]})]}),de=Z.length>0?t.jsx(dn,{id:"external",title:c("entityPage.sec.external"),items:Z.map(O=>t.jsxs("a",{href:O.href,target:"_blank",rel:"noopener noreferrer",children:[O.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Z.map(O=>O.id),foot:Oe.cbdb_id!=null&&Oe.cbdb_match==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(ei,{railTop:s,back:a,nav:ye,railLinks:l,main:ce,card:G,side:de})},hs="(max-width: 719px)",O0=`${hs}, (pointer: coarse)`,up=`
1428
1446
  .bim-ct {
1429
1447
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
1430
1448
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -1532,7 +1550,7 @@ ${H??""}`,[Rn,Ss]=f.useState({key:En,data:U,started:!!U});if(Rn.key!==En)Ss({key
1532
1550
  .bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1533
1551
  }
1534
1552
 
1535
- @media ${fs} {
1553
+ @media ${hs} {
1536
1554
  .bim-ct { display: block; padding: 12px 16px 40px; }
1537
1555
  .bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
1538
1556
  .bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
@@ -1557,7 +1575,7 @@ ${H??""}`,[Rn,Ss]=f.useState({key:En,data:U,started:!!U});if(Rn.key!==En)Ss({key
1557
1575
  }
1558
1576
 
1559
1577
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
1560
- @media ${A0} {
1578
+ @media ${O0} {
1561
1579
  .bim-ct-row { min-height: 44px; }
1562
1580
  .bim-ct-tw { width: 44px; }
1563
1581
  .bim-ct-pg { min-width: 44px; height: 44px; }
@@ -1583,7 +1601,7 @@ ${H??""}`,[Rn,Ss]=f.useState({key:En,data:U,started:!!U});if(Rn.key!==En)Ss({key
1583
1601
  /* 窄屏分类抽屉:界栏下按钮和面板都有框 */
1584
1602
  :root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${r("fr-bd")}; background: ${r("fr-bg")}; }
1585
1603
  :root[data-layout="boxed"] .bim-ct-drawer { border: ${r("fr-bd")}; }
1586
- `,cn="未分類",Ut="all",hs=20;function ii(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 M0(e){const n=ii(e);return n.length?n.join("/"):cn}function P0(e){const n=ii(e);return n.length?n.map((i,o)=>n.slice(0,o+1).join("/")):[cn]}function B0(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(g=>!!g);p.forEach((g,m)=>{const u=p.slice(0,m+1).join("/");i.has(u)||i.set(u,c)})});const o=new Map;let s=0;for(const d of e){const c=ii(d.classification);if(!c.length){s++;continue}let p=o;c.forEach((g,m)=>{const u=c.slice(0,m+1).join("/");let h=p.get(g);h||(h={id:u,label:g,count:0,children:new Map},p.set(g,h)),h.count++,p=h.children})}const a=d=>[...d.values()].sort((c,p)=>{const g=c.label===cn?1:0,m=p.label===cn?1:0;if(g!==m)return g-m;const u=i.get(c.id)??1/0,h=i.get(p.id)??1/0;return u!==h?u-h: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:cn,label:cn,count:s}),l}function vn(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const o=vn(i.children,n);if(o.length)return[i,...o]}}return[]}function xs(e){return e.reduce((n,i)=>n+i.count,0)}function O0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function W0(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=O0(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);a&&(n.summary=a);const l=ii(e.classification);return l.length&&(n.classification=l),n}function F0(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 H0(e,n=hs){return Math.max(1,Math.ceil(e/n))}function pp(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 D0=()=>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 U0(e,n,i){const o=[];i&&o.push({id:Ut,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 up({tree:e,selectedId:n,onSelect:i,allLabel:o,label:s}){const{t:a,convert:l}=re(),d=o===void 0?a("catalogPage.all"):o,c=s??a("catalogPage.classification"),p=f.useRef(null),g=n&&n!==Ut?n:null,m=d!==null,[u,h]=f.useState(()=>{const S=new Set;for(const R of vn(e,g))S.add(R.id);return S});f.useEffect(()=>{const S=vn(e,g);S.length&&h(R=>{if(S.every(z=>R.has(z.id)))return R;const N=new Set(R);for(const z of S)N.add(z.id);return N})},[e,g]);const x=f.useMemo(()=>U0(e,u,m),[e,u,m]),[j,b]=f.useState(null);f.useEffect(()=>{b(null)},[n]);const _=g??(m?Ut:null),y=f.useMemo(()=>{var N;const S=new Set(x.map(z=>z.id));if(j&&S.has(j))return j;if(_&&S.has(_))return _;const R=vn(e,g).map(z=>z.id).filter(z=>S.has(z));return R.length?R[R.length-1]:((N=x[0])==null?void 0:N.id)??null},[x,j,_,e,g]),k=f.useCallback((S,R)=>{h(N=>{const z=N.has(S),I=R??!z;if(I===z)return N;const P=new Set(N);return I?P.add(S):P.delete(S),P})},[]),w=f.useCallback(S=>{b(S),requestAnimationFrame(()=>{var N;const R=Array.from(((N=p.current)==null?void 0:N.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===S);R==null||R.focus()})},[]),v=f.useCallback((S,R)=>{R&&k(S,!0),i(S)},[i,k]),C=f.useCallback(S=>{const R=S.target.closest("[data-ct-id]");if(!R)return;const N=R.dataset.ctId,z=x.findIndex(A=>A.id===N);if(z<0)return;const I=x[z];let P=null;switch(S.key){case"ArrowDown":P=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":P=x[Math.max(0,z-1)].id;break;case"Home":P=x[0].id;break;case"End":P=x[x.length-1].id;break;case"ArrowRight":if(!I.hasChildren)break;u.has(N)?P=I.firstChildId:k(N,!0);break;case"ArrowLeft":I.hasChildren&&u.has(N)?k(N,!1):P=I.parentId;break;case"Enter":case" ":S.preventDefault(),v(N,I.hasChildren);return;default:return}S.preventDefault(),P&&P!==N&&w(P)},[x,u,k,w,v]),$=(S,R)=>S.map((N,z)=>{var F;const I=(F=N.children)!=null&&F.length?N.children:null,P=!!I&&u.has(N.id),A=N.id===g,M=R===1&&S.length>1&&z===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":R,"aria-expanded":I?P:void 0,"aria-selected":A,tabIndex:y===N.id?0:-1,"data-ct-id":N.id,className:M?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":R-1},onClick:()=>{b(N.id),v(N.id,!!I)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:I?ne=>{ne.stopPropagation(),b(N.id),k(N.id)}:void 0,children:I?t.jsx(D0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(N.label)}),t.jsx("span",{className:"bim-ct-n",children:N.count.toLocaleString("en-US")})]}),P&&t.jsx("ul",{role:"group",children:$(I,R+1)})]},N.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:C,children:[m&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!g,tabIndex:y===Ut?0:-1,"data-ct-id":Ut,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{b(Ut),i(Ut)},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:xs(e).toLocaleString("en-US")})]})}),$(e,1)]})}const mp=e=>`/item/${encodeURIComponent(e)}`;function V0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function gp(e,n){return e==null||e===""?null:typeof e=="number"?n("catalogPage.juanN",{n:e}):e}function fp({work:e,href:n}){var d,c;const{t:i,convert:o}=re(),s=gp(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,g)=>t.jsxs(f.Fragment,{children:[g>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},g))}),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 hp({work:e,href:n}){var d,c;const{t:i,convert:o}=re(),s=gp(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,g)=>t.jsxs(f.Fragment,{children:[g>0&&"、",p.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",o(p.dynasty),"〕"]}),o(p.name)]},g))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(p=>o(p)).join(" · ")})]})})}function xp({page:e,pageCount:n,onPage:i,pageHref:o,label:s}){const{t:a,convert:l}=re();if(n<=1)return null;const d=p=>g=>{i&&(o&&!V0(g)||(g.preventDefault(),i(p)))},c=(p,g,m)=>{if(m.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:g});const u={className:"bim-ct-pg","aria-current":m.current?"page":void 0,"aria-label":m.aria};return o?t.jsx("a",{...u,href:o(p),onClick:d(p),children:g}):t.jsx("button",{type:"button",...u,onClick:m.current?void 0:d(p),children:g})};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:pp(e,n).map((p,g)=>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${g}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",n]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=n})]})}function bp({works:e,workLink:n=mp,emptyText:i,view:o="card",...s}){const{t:a,convert:l}=re();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(hp,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(fp,{work:d,href:n(d.id)},d.id))}),t.jsx(xp,{...s})]})}const G0=()=>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 Y0({tree:e,selectedId:n,page:i,pageCount:o,works:s,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:p,allLabel:g,allTitle:m,pageSize:u=hs,className:h,view:x,onViewChange:j}){const{t:b,convert:_}=re(),y=g===void 0?b("catalogPage.all"):g,k=m??b("catalogPage.allTitle"),v=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[C,$]=f.useState(!1),[S,R]=f.useState("card"),N=x??S,z=ne=>{R(ne),j==null||j(ne)},I=vn(e,n&&n!==Ut?n:null),P=I.length?I[I.length-1]:null,A=P?P.label:k,M=P?P.count:xs(e),F=f.useCallback(ne=>{$(!1),a(ne)},[a]);return t.jsxs("div",{className:h?`bim-ct ${h}`:"bim-ct","data-drawer":C?"open":"closed",children:[t.jsx("style",{children:dp}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":C,"aria-controls":v,onClick:()=>$(ne=>!ne),children:[t.jsx("span",{children:b("catalogPage.drawerLabel",{path:_(I.length?I.map(ne=>ne.label).join(" › "):y??k)})}),t.jsx(G0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:v,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("catalogPage.classification")}),t.jsx(up,{tree:e,selectedId:n,onSelect:F,allLabel:y})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:_(A)}),I.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:_(I.slice(0,-1).map(ne=>ne.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[b("catalogPage.stat",{total:M.toLocaleString("en-US"),size:u}),o>1&&b("catalogPage.statPage",{page:i,pages:o})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":b("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":N==="card",onClick:()=>z("card"),children:b("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":N==="list",onClick:()=>z("list"),children:b("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(bp,{works:s,view:N,workLink:c,page:i,pageCount:o,onPage:l,pageHref:p})]})]})}const ri="(max-width: 719px)",q0="(max-width: 1079px)",K0=`${ri}, (pointer: coarse)`,X0=[8,18,30,42,88],bs=`
1604
+ `,cn="未分類",Ut="all",xs=20;function ri(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 W0(e){const n=ri(e);return n.length?n.join("/"):cn}function F0(e){const n=ri(e);return n.length?n.map((i,o)=>n.slice(0,o+1).join("/")):[cn]}function H0(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,g)=>{const u=p.slice(0,g+1).join("/");i.has(u)||i.set(u,c)})});const o=new Map;let s=0;for(const d of e){const c=ri(d.classification);if(!c.length){s++;continue}let p=o;c.forEach((m,g)=>{const u=c.slice(0,g+1).join("/");let h=p.get(m);h||(h={id:u,label:m,count:0,children:new Map},p.set(m,h)),h.count++,p=h.children})}const a=d=>[...d.values()].sort((c,p)=>{const m=c.label===cn?1:0,g=p.label===cn?1:0;if(m!==g)return m-g;const u=i.get(c.id)??1/0,h=i.get(p.id)??1/0;return u!==h?u-h: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:cn,label:cn,count:s}),l}function vn(e,n){if(!n)return[];for(const i of e){if(i.id===n)return[i];if(i.children){const o=vn(i.children,n);if(o.length)return[i,...o]}}return[]}function bs(e){return e.reduce((n,i)=>n+i.count,0)}function D0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function U0(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=D0(typeof e.description=="string"?e.description:(d=e.description)==null?void 0:d.text);a&&(n.summary=a);const l=ri(e.classification);return l.length&&(n.classification=l),n}function V0(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 G0(e,n=xs){return Math.max(1,Math.ceil(e/n))}function mp(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 Y0=()=>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 q0(e,n,i){const o=[];i&&o.push({id:Ut,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 gp({tree:e,selectedId:n,onSelect:i,allLabel:o,label:s}){const{t:a,convert:l}=ie(),d=o===void 0?a("catalogPage.all"):o,c=s??a("catalogPage.classification"),p=f.useRef(null),m=n&&n!==Ut?n:null,g=d!==null,[u,h]=f.useState(()=>{const S=new Set;for(const I of vn(e,m))S.add(I.id);return S});f.useEffect(()=>{const S=vn(e,m);S.length&&h(I=>{if(S.every(z=>I.has(z.id)))return I;const N=new Set(I);for(const z of S)N.add(z.id);return N})},[e,m]);const x=f.useMemo(()=>q0(e,u,g),[e,u,g]),[j,b]=f.useState(null);f.useEffect(()=>{b(null)},[n]);const _=m??(g?Ut:null),y=f.useMemo(()=>{var N;const S=new Set(x.map(z=>z.id));if(j&&S.has(j))return j;if(_&&S.has(_))return _;const I=vn(e,m).map(z=>z.id).filter(z=>S.has(z));return I.length?I[I.length-1]:((N=x[0])==null?void 0:N.id)??null},[x,j,_,e,m]),k=f.useCallback((S,I)=>{h(N=>{const z=N.has(S),E=I??!z;if(E===z)return N;const P=new Set(N);return E?P.add(S):P.delete(S),P})},[]),w=f.useCallback(S=>{b(S),requestAnimationFrame(()=>{var N;const I=Array.from(((N=p.current)==null?void 0:N.querySelectorAll("[data-ct-id]"))??[]).find(z=>z.dataset.ctId===S);I==null||I.focus()})},[]),v=f.useCallback((S,I)=>{I&&k(S,!0),i(S)},[i,k]),C=f.useCallback(S=>{const I=S.target.closest("[data-ct-id]");if(!I)return;const N=I.dataset.ctId,z=x.findIndex(A=>A.id===N);if(z<0)return;const E=x[z];let P=null;switch(S.key){case"ArrowDown":P=x[Math.min(x.length-1,z+1)].id;break;case"ArrowUp":P=x[Math.max(0,z-1)].id;break;case"Home":P=x[0].id;break;case"End":P=x[x.length-1].id;break;case"ArrowRight":if(!E.hasChildren)break;u.has(N)?P=E.firstChildId:k(N,!0);break;case"ArrowLeft":E.hasChildren&&u.has(N)?k(N,!1):P=E.parentId;break;case"Enter":case" ":S.preventDefault(),v(N,E.hasChildren);return;default:return}S.preventDefault(),P&&P!==N&&w(P)},[x,u,k,w,v]),$=(S,I)=>S.map((N,z)=>{var F;const E=(F=N.children)!=null&&F.length?N.children:null,P=!!E&&u.has(N.id),A=N.id===m,M=I===1&&S.length>1&&z===S.length-1;return t.jsxs("li",{role:"treeitem","aria-level":I,"aria-expanded":E?P:void 0,"aria-selected":A,tabIndex:y===N.id?0:-1,"data-ct-id":N.id,className:M?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":I-1},onClick:()=>{b(N.id),v(N.id,!!E)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:E?q=>{q.stopPropagation(),b(N.id),k(N.id)}:void 0,children:E?t.jsx(Y0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(N.label)}),t.jsx("span",{className:"bim-ct-n",children:N.count.toLocaleString("en-US")})]}),P&&t.jsx("ul",{role:"group",children:$(E,I+1)})]},N.id)});return t.jsxs("ul",{ref:p,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:C,children:[g&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!m,tabIndex:y===Ut?0:-1,"data-ct-id":Ut,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{b(Ut),i(Ut)},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:bs(e).toLocaleString("en-US")})]})}),$(e,1)]})}const fp=e=>`/item/${encodeURIComponent(e)}`;function K0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function hp(e,n){return e==null||e===""?null:typeof e=="number"?n("catalogPage.juanN",{n:e}):e}function xp({work:e,href:n}){var d,c;const{t:i,convert:o}=ie(),s=hp(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(f.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 bp({work:e,href:n}){var d,c;const{t:i,convert:o}=ie(),s=hp(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(f.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 yp({page:e,pageCount:n,onPage:i,pageHref:o,label:s}){const{t:a,convert:l}=ie();if(n<=1)return null;const d=p=>m=>{i&&(o&&!K0(m)||(m.preventDefault(),i(p)))},c=(p,m,g)=>{if(g.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:m});const u={className:"bim-ct-pg","aria-current":g.current?"page":void 0,"aria-label":g.aria};return o?t.jsx("a",{...u,href:o(p),onClick:d(p),children:m}):t.jsx("button",{type:"button",...u,onClick:g.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:mp(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 jp({works:e,workLink:n=fp,emptyText:i,view:o="card",...s}){const{t:a,convert:l}=ie();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(bp,{work:d,href:n(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(xp,{work:d,href:n(d.id)},d.id))}),t.jsx(yp,{...s})]})}const X0=()=>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 Z0({tree:e,selectedId:n,page:i,pageCount:o,works:s,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:p,allLabel:m,allTitle:g,pageSize:u=xs,className:h,view:x,onViewChange:j}){const{t:b,convert:_}=ie(),y=m===void 0?b("catalogPage.all"):m,k=g??b("catalogPage.allTitle"),v=`bim-ct-drawer-${f.useId().replace(/:/g,"")}`,[C,$]=f.useState(!1),[S,I]=f.useState("card"),N=x??S,z=q=>{I(q),j==null||j(q)},E=vn(e,n&&n!==Ut?n:null),P=E.length?E[E.length-1]:null,A=P?P.label:k,M=P?P.count:bs(e),F=f.useCallback(q=>{$(!1),a(q)},[a]);return t.jsxs("div",{className:h?`bim-ct ${h}`:"bim-ct","data-drawer":C?"open":"closed",children:[t.jsx("style",{children:up}),t.jsxs("aside",{className:"bim-ct-side","aria-label":b("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":C,"aria-controls":v,onClick:()=>$(q=>!q),children:[t.jsx("span",{children:b("catalogPage.drawerLabel",{path:_(E.length?E.map(q=>q.label).join(" › "):y??k)})}),t.jsx(X0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:v,children:[t.jsx("h2",{className:"bim-ct-side-h",children:b("catalogPage.classification")}),t.jsx(gp,{tree:e,selectedId:n,onSelect:F,allLabel:y})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:_(A)}),E.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:_(E.slice(0,-1).map(q=>q.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[b("catalogPage.stat",{total:M.toLocaleString("en-US"),size:u}),o>1&&b("catalogPage.statPage",{page:i,pages:o})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":b("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":N==="card",onClick:()=>z("card"),children:b("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":N==="list",onClick:()=>z("list"),children:b("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(jp,{works:s,view:N,workLink:c,page:i,pageCount:o,onPage:l,pageHref:p})]})]})}const oi="(max-width: 719px)",J0="(max-width: 1079px)",Q0=`${oi}, (pointer: coarse)`,e1=[8,18,30,42,88],ys=`
1587
1605
  .bim-rh { color: ${r("ink")}; font-family: ${r("font-ui")}; font-size: 14px; line-height: 1.6; }
1588
1606
  .bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
1589
1607
  .bim-rh a { color: ${r("accent")}; text-decoration: none; }
@@ -1731,7 +1749,7 @@ ${H??""}`,[Rn,Ss]=f.useState({key:En,data:U,started:!!U});if(Rn.key!==En)Ss({key
1731
1749
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
1732
1750
  color: ${r("ink")} !important; font-size: 13px;
1733
1751
  }
1734
- ${X0.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb, ${r("accent")} ${e}%, ${r("card-bg")}); }`).join(`
1752
+ ${e1.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb, ${r("accent")} ${e}%, ${r("card-bg")}); }`).join(`
1735
1753
  `)}
1736
1754
  .bim-rh-band a[data-k="4"] { color: ${r("page-bg")} !important; }
1737
1755
  .bim-rh-band a:hover { outline: 2px solid ${r("ink")}; outline-offset: -2px; }
@@ -1759,13 +1777,13 @@ ${X0.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1759
1777
  }
1760
1778
 
1761
1779
  /* ── 中屏 ── */
1762
- @media ${q0} {
1780
+ @media ${J0} {
1763
1781
  .bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1764
1782
  .bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
1765
1783
  }
1766
1784
 
1767
1785
  /* ── 手机 ── */
1768
- @media ${ri} {
1786
+ @media ${oi} {
1769
1787
  .bim-rh-main { padding-top: 24px; }
1770
1788
  .bim-rh-stats { gap: 4px 18px; }
1771
1789
  .bim-rh-stats b { font-size: 16px; }
@@ -1802,7 +1820,7 @@ ${X0.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1802
1820
  }
1803
1821
 
1804
1822
  /* 触屏或窄屏:点击目标放大到 44px */
1805
- @media ${K0} {
1823
+ @media ${Q0} {
1806
1824
  .bim-rh-rows a, .bim-rh-bu-l a, .bim-rh-au li a, .bim-rh-chip, .bim-rh-secnav a, .bim-rh-expand { min-height: 44px; display: flex; align-items: center; }
1807
1825
  .bim-rh-chip { display: inline-flex; }
1808
1826
  }
@@ -1813,7 +1831,7 @@ ${X0.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1813
1831
  }
1814
1832
 
1815
1833
  @media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
1816
- `,Z0=jo["zh-Hant"].period,yp={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function en(e){return{...yp,...e??{}}}function ys(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 Ji(e){return(e.authors??[]).filter(i=>i==null?void 0:i.name).map(i=>i.dynasty?`〔${i.dynasty}〕${i.name}`:i.name).join(" ")}function jp(e,n=jo["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 vp(e){return Math.max(150,Array.from(e).length*18+44)}function kp(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 wp=.04;function lt(e){return e.toLocaleString("en-US")}function Sp({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((n,i)=>t.jsx("span",{children:n},i))})}function vt({id:e,title:n,sub:i,more:o,children:s}){const{convert:a}=re(),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 _p({counts:e}){const{t:n}=re();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:lt(e.readable)}),n("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:lt(e.pieces)}),n("readHome.pieces")]})]})}function $p({picks:e,links:n}){const{t:i,convert:o}=re(),s=en(n);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=Ji(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(Sp,{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 Cp(e,n){return e&&e>1?n("readHome.nCopies",{n:e}):null}function js({topic:e,links:n,hint:i,legendCount:o,showTitle:s=!0,legendExtra:a}){const{t:l,convert:d}=re(),c=en(n);if(!e.items.length)return null;const p=o===void 0?l("readHome.shelfLegendCount"):o,g=jp(e.items,l("readHome.shelfOther")),m=u=>{const h=u.records?lt(u.records):Cp(u.text_count,l),x=ys(u),j=[d(u.title),u.orig?l("readHome.origZhi"):"",x?l("readHome.spineBy",{name:d(x)}):"",u.records?l("readHome.spineRecords",{n:h}):h?l("readHome.spineOnSite",{n:h}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":j,title:j,style:{height:vp(u.title)},children:[t.jsx(Sp,{text:d(u.title)}),h&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:h})]})},u.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:g.map(u=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(u.label),children:u.items.map(m)}),t.jsx("span",{"aria-hidden":"true",children:d(u.label)})]},u.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(u=>t.jsx("span",{children:d(u)},u))]})]})}const J0=4,Zn=e=>e>J0+1;function zp({topic:e,links:n}){const{t:i,convert:o}=re(),s=en(n),[a,l]=f.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":Zn(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:lt(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const p=Cp(c.text_count,i),g=ys(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}),g&&t.jsx("small",{children:o(g)})]})},c.id)})}),Zn(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 Np({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(js,{topic:s,links:n},s.key)),o.length>0&&t.jsx("div",{className:"bim-rh-groups",children:o.map(s=>t.jsx(zp,{topic:s,links:n},s.key))})]})}function Tp({famous:e,links:n}){const{t:i,convert:o}=re(),s=en(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 vs({bu:e,unclassified:n,links:i,unclassifiedNote:o}){const{t:s,convert:a}=re(),l=en(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:lt(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(g=>t.jsx("li",{children:t.jsxs("a",{href:l.node(g.id),children:[t.jsx("span",{children:a(g.label)}),t.jsx("small",{className:"bim-rh-num",children:lt(g.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(g.count/c*100)}%`}})]})},g.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:lt(n)})}),t.jsx("span",{children:o?a(o):s("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:s("readHome.viewUnclassified")})]})]})}function Ip({periods:e,unknown:n,links:i}){const{t:o,convert:s,messages:a}=re(),l=a.readHome.period,d=en(i),c=e.filter(m=>m.count>0);if(!c.length)return null;const p=c.reduce((m,u)=>m+u.count,0),g=Math.max(...c.map(m=>m.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(m=>{const u=m.label?s(m.label):l[m.key]??s(m.key),h=m.count/p,x=o("readHome.periodItem",{label:u,n:lt(m.count)});return t.jsx("li",{style:{flex:`0 0 ${(h*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(m.key),"data-k":kp(m.count,g),"data-narrow":h<wp?"":void 0,"aria-label":x,title:x,children:[t.jsx("span",{className:"bim-rh-pl",children:u}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(u)[0]}),t.jsx("small",{className:"bim-rh-num",children:lt(m.count)})]})},m.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&t.jsx("span",{children:o("readHome.periodUnknown",{n:lt(n)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:o("readHome.hoverHint")})]})]})}function Ep({authors:e,links:n}){const{t:i,convert:o}=re(),s=en(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:lt(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 Rp={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function Q0({sections:e,links:n,head:i,piecesMoreHref:o,className:s}){const{t:a}=re(),l=e,d=Rp,c=l.topics.filter(u=>!u.shelf),p={picks:l.picks.length>0,topics:c.some(u=>u.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(u=>u.count>0),pieces:l.pieces.authors.length>0},g=Object.keys(d).filter(u=>p[u]),m=u=>a(`readHome.nav.${u}`);return t.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[t.jsx("style",{children:bs}),t.jsxs("div",{className:"bim-rh-head",children:[i,t.jsx(_p,{counts:l.counts})]}),g.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:g.map(u=>t.jsx("li",{children:t.jsx("a",{href:`#${d[u]}`,children:m(u)})},u))})}),t.jsxs("div",{className:"bim-rh-main",children:[p.picks&&t.jsx(vt,{id:d.picks,title:m("picks"),sub:a("readHome.picksSub"),children:t.jsx($p,{picks:l.picks,links:n})}),p.topics&&t.jsx(vt,{id:d.topics,title:m("topics"),sub:a("readHome.topicsSub"),children:t.jsx(Np,{topics:c,links:n})}),p.famous&&t.jsx(vt,{id:d.famous,title:m("famous"),sub:a("readHome.famousSub"),children:t.jsx(Tp,{famous:l.famous,links:n})}),p.sibu&&t.jsx(vt,{id:d.sibu,title:m("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(vs,{bu:l.bu,unclassified:l.unclassified,links:n})}),p.period&&t.jsx(vt,{id:d.period,title:m("period"),sub:a("readHome.periodSub"),children:t.jsx(Ip,{periods:l.periods,unknown:l.period_unknown,links:n})}),p.pieces&&t.jsx(vt,{id:d.pieces,title:m("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(Ep,{authors:l.pieces.authors,links:n})})]})]})}const e1="(max-width: 1079px)",t1=`${ri}, (pointer: coarse)`,Lp=`
1834
+ `,t1=vo["zh-Hant"].period,vp={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function en(e){return{...vp,...e??{}}}function js(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 Qi(e){return(e.authors??[]).filter(i=>i==null?void 0:i.name).map(i=>i.dynasty?`〔${i.dynasty}〕${i.name}`:i.name).join(" ")}function kp(e,n=vo["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 wp(e){return Math.max(150,Array.from(e).length*18+44)}function Sp(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 _p=.04;function ct(e){return e.toLocaleString("en-US")}function $p({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((n,i)=>t.jsx("span",{children:n},i))})}function vt({id:e,title:n,sub:i,more:o,children:s}){const{convert:a}=ie(),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 Cp({counts:e}){const{t:n}=ie();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:ct(e.readable)}),n("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:ct(e.pieces)}),n("readHome.pieces")]})]})}function zp({picks:e,links:n}){const{t:i,convert:o}=ie(),s=en(n);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=Qi(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($p,{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 Np(e,n){return e&&e>1?n("readHome.nCopies",{n:e}):null}function vs({topic:e,links:n,hint:i,legendCount:o,showTitle:s=!0,legendExtra:a}){const{t:l,convert:d}=ie(),c=en(n);if(!e.items.length)return null;const p=o===void 0?l("readHome.shelfLegendCount"):o,m=kp(e.items,l("readHome.shelfOther")),g=u=>{const h=u.records?ct(u.records):Np(u.text_count,l),x=js(u),j=[d(u.title),u.orig?l("readHome.origZhi"):"",x?l("readHome.spineBy",{name:d(x)}):"",u.records?l("readHome.spineRecords",{n:h}):h?l("readHome.spineOnSite",{n:h}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":j,title:j,style:{height:wp(u.title)},children:[t.jsx($p,{text:d(u.title)}),h&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:h})]})},u.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(u=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(u.label),children:u.items.map(g)}),t.jsx("span",{"aria-hidden":"true",children:d(u.label)})]},u.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(u=>t.jsx("span",{children:d(u)},u))]})]})}const n1=4,Jn=e=>e>n1+1;function Tp({topic:e,links:n}){const{t:i,convert:o}=ie(),s=en(n),[a,l]=f.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":Jn(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:ct(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const p=Np(c.text_count,i),m=js(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)})}),Jn(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 Ep({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(vs,{topic:s,links:n},s.key)),o.length>0&&t.jsx("div",{className:"bim-rh-groups",children:o.map(s=>t.jsx(Tp,{topic:s,links:n},s.key))})]})}function Ip({famous:e,links:n}){const{t:i,convert:o}=ie(),s=en(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 ks({bu:e,unclassified:n,links:i,unclassifiedNote:o}){const{t:s,convert:a}=ie(),l=en(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:ct(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:ct(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:ct(n)})}),t.jsx("span",{children:o?a(o):s("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:s("readHome.viewUnclassified")})]})]})}function Rp({periods:e,unknown:n,links:i}){const{t:o,convert:s,messages:a}=ie(),l=a.readHome.period,d=en(i),c=e.filter(g=>g.count>0);if(!c.length)return null;const p=c.reduce((g,u)=>g+u.count,0),m=Math.max(...c.map(g=>g.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(g=>{const u=g.label?s(g.label):l[g.key]??s(g.key),h=g.count/p,x=o("readHome.periodItem",{label:u,n:ct(g.count)});return t.jsx("li",{style:{flex:`0 0 ${(h*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(g.key),"data-k":Sp(g.count,m),"data-narrow":h<_p?"":void 0,"aria-label":x,title:x,children:[t.jsx("span",{className:"bim-rh-pl",children:u}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(u)[0]}),t.jsx("small",{className:"bim-rh-num",children:ct(g.count)})]})},g.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!n&&t.jsx("span",{children:o("readHome.periodUnknown",{n:ct(n)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:o("readHome.hoverHint")})]})]})}function Lp({authors:e,links:n}){const{t:i,convert:o}=ie(),s=en(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:ct(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 Ap={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function i1({sections:e,links:n,head:i,piecesMoreHref:o,className:s}){const{t:a}=ie(),l=e,d=Ap,c=l.topics.filter(u=>!u.shelf),p={picks:l.picks.length>0,topics:c.some(u=>u.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(u=>u.count>0),pieces:l.pieces.authors.length>0},m=Object.keys(d).filter(u=>p[u]),g=u=>a(`readHome.nav.${u}`);return t.jsxs("div",{className:s?`bim-rh ${s}`:"bim-rh",children:[t.jsx("style",{children:ys}),t.jsxs("div",{className:"bim-rh-head",children:[i,t.jsx(Cp,{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(u=>t.jsx("li",{children:t.jsx("a",{href:`#${d[u]}`,children:g(u)})},u))})}),t.jsxs("div",{className:"bim-rh-main",children:[p.picks&&t.jsx(vt,{id:d.picks,title:g("picks"),sub:a("readHome.picksSub"),children:t.jsx(zp,{picks:l.picks,links:n})}),p.topics&&t.jsx(vt,{id:d.topics,title:g("topics"),sub:a("readHome.topicsSub"),children:t.jsx(Ep,{topics:c,links:n})}),p.famous&&t.jsx(vt,{id:d.famous,title:g("famous"),sub:a("readHome.famousSub"),children:t.jsx(Ip,{famous:l.famous,links:n})}),p.sibu&&t.jsx(vt,{id:d.sibu,title:g("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(ks,{bu:l.bu,unclassified:l.unclassified,links:n})}),p.period&&t.jsx(vt,{id:d.period,title:g("period"),sub:a("readHome.periodSub"),children:t.jsx(Rp,{periods:l.periods,unknown:l.period_unknown,links:n})}),p.pieces&&t.jsx(vt,{id:d.pieces,title:g("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(Lp,{authors:l.pieces.authors,links:n})})]})]})}const r1="(max-width: 1079px)",o1=`${oi}, (pointer: coarse)`,Mp=`
1817
1835
  /* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
1818
1836
  .bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
1819
1837
  .bim-mh-q { min-width: 0; }
@@ -1953,7 +1971,7 @@ ${X0.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1953
1971
  .bim-mh-cc0 { display: inline-block; margin-right: 8px; padding: 1px 7px; font-size: 11.5px; letter-spacing: 0.08em; background: ${r("check-fine-bg")}; color: ${r("check-fine-fg")}; }
1954
1972
 
1955
1973
  /* ── 中屏 ── */
1956
- @media ${e1} {
1974
+ @media ${r1} {
1957
1975
  .bim-mh-head, .bim-mh-zhi { grid-template-columns: minmax(0, 1fr); }
1958
1976
  .bim-mh-cg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1959
1977
  .bim-mh-lin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@@ -1963,7 +1981,7 @@ ${X0.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1963
1981
  }
1964
1982
 
1965
1983
  /* ── 手机 ── */
1966
- @media ${ri} {
1984
+ @media ${oi} {
1967
1985
  .bim-mh-cg, .bim-mh-data { grid-template-columns: minmax(0, 1fr); }
1968
1986
  .bim-mh-ge { grid-template-columns: repeat(4, minmax(0, 1fr)); }
1969
1987
  .bim-mh-lin { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@@ -1980,8 +1998,8 @@ ${X0.map((e,n)=>`.bim-rh-band a[data-k="${n}"] { background: color-mix(in srgb,
1980
1998
  .bim-mh-tbl tr > :nth-child(2), .bim-mh-tbl tr > :nth-child(3) { display: none; }
1981
1999
  }
1982
2000
 
1983
- @media ${t1} {
2001
+ @media ${o1} {
1984
2002
  .bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
1985
2003
  .bim-mh-recent-h button { min-height: 44px; }
1986
2004
  }
1987
- `,Ap={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function tn(e){return{...Ap,...e??{}}}function Mp(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 ks(e,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(e/n*100)))}function Pp(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 g=Number.isFinite(p.birth_year)?p.birth_year:p.death_year-50,m=Number.isFinite(p.death_year)?p.death_year:p.birth_year+50;return[Math.min(g,m),Math.max(g,m)]},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,g)=>({p,from:s[g][0],to:s[g][1]})).sort((p,g)=>p.from-g.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 Ri(e,n=Nn("zh-Hant")){return e<0?n("metaHome.yearBC",{n:-e}):String(e)}function n1(e){return{read:e.item,work:e.item,node:e.node}}function Bp({counts:e,links:n}){const{t:i}=re(),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:lt(d)})]})},a))})}function Op(e,n=5){const[i,o]=f.useState(null);f.useEffect(()=>{let a=!1;const l=Qt().slice(0,n);if(!l.length||!e){o([]);return}return Promise.all(l.map(d=>Io(e,d))).then(d=>{a||o(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,n]);const s=f.useCallback(()=>{To(),o([])},[]);return{entries:i,clear:s}}function i1(e,n,i){const o=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return o?i(o):Wp(e.type,n)}function Wp(e,n){return n(`metaHome.typeLabel.${e}`)}function Fp({entries:e,onClear:n,links:i}){const{t:o,convert:s}=re(),a=tn(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?Wp(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:i1(l,o,s)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:o("metaHome.recentEmpty")})]})}function Hp(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 Dp({rows:e,links:n}){const{t:i,convert:o}=re(),s=tn(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=ks(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:lt(a.total)}),t.jsx("td",{className:"bim-mh-r",children:lt(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:Hp(a.status,i,o)})})]},a.id||a.name)})})]})}):null}function Up({items:e,links:n,label:i}){const{convert:o}=re();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 Vp({works:e,links:n}){const{t:i}=re(),[o,s]=f.useState(!1);if(!e.length)return null;const a=Zn(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(Up,{items:e.map(l=>({id:l.id,title:l.title,sub:Ji(l)||void 0})),links:tn(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 Gp="siku_qige";function r1({group:e,links:n}){const{t:i,convert:o}=re(),[s,a]=f.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Zn(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(Up,{items:e.items,links:n,label:e.label}),Zn(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 Yp({groups:e,links:n}){const{t:i,convert:o}=re(),s=tn(n);if(!e.length)return null;const a=e.find(c=>c.key===Gp),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(r1,{group:c,links:s},c.key))})]})}const Cl=34,zl=13;function Nl(e,n){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Ri(e.birth_year,n):"?"}–${e.death_year!=null?Ri(e.death_year,n):"?"}`}function o1(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 qp({people:e,links:n}){const{t:i,convert:o}=re(),s=tn(n);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=Pp(e),p=[],g=d.map(u=>{const h=u.left>70,x=h?Math.min(u.left,u.left+u.width-zl):u.left;let j=0;for(;p[j]!=null&&p[j]>x;)j++;return p[j]=h?u.left+u.width:u.left+Math.max(u.width,zl),{...u,lane:j,end:h}}),m=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[g.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:p.length*Cl+10},children:g.map(u=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":u.end?"":void 0,style:{left:`${u.left}%`,top:u.lane*Cl+4,width:`${Math.max(u.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:s.item(u.p.id),children:[o(u.p.name),t.jsx("small",{className:"bim-rh-num",children:Nl(u.p,i)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:o1(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/m*100}%`},children:Ri(u,i)},u))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":g.length?void 0:"",children:(g.length?e:c).map(u=>t.jsx("li",{children:t.jsxs("a",{href:s.item(u.id),children:[t.jsx("span",{children:o(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?o(u.dynasty):"",Nl(u,i)].filter(Boolean).join(" ")})]})},u.id))}),c.length>0&&g.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:i("metaHome.missingLife",{names:o(c.map(u=>u.name).join("、"))})})]})}const s1=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 Kp({works:e,links:n}){const{t:i,convert:o}=re(),s=tn(n);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=Ji(a);return t.jsx("li",{children:t.jsxs("a",{href:Mp(s,a.id),children:[s1,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 Xp({sites:e}){const{t:n,convert:i}=re(),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=ks(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:[`${lt(a.imported)} / ${lt(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:Hp(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 Tl=["extant","partially_extant","lost","unknown"];function Zp({stats:e,links:n,version:i,repoUrl:o,downloadHref:s}){const{t:a}=re(),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=Tl.some(p=>{var g;return(((g=e.loss)==null?void 0:g[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,g])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:lt(p)}),t.jsx("span",{children:g})]},g))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:Tl.map(p=>{var u;const g=((u=e.loss)==null?void 0:u[p])??0,m=a(`metaHome.lossNote.${p}`);return t.jsx("li",{children:t.jsxs("a",{href:d(p),children:[a(`metaHome.loss.${p}`),t.jsx("small",{className:"bim-rh-num",children:c&&g>0?a("metaHome.lossCount",{n:lt(g),note:m}):m})]})},p)})})]}),t.jsxs("div",{className:"bim-mh-lic",children:[t.jsxs("p",{children:[t.jsx("span",{className:"bim-mh-cc0",children:"CC BY-SA 4.0"}),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 Jp={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function a1({sections:e,links:n,head:i,transport:o,catalogHref:s,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:p,className:g}){var v,C;const{t:m}=re(),u=e,h=tn(n),x=n1(h),j=Jp,b=Op(o),_={zhi:!!((v=u.shelf)!=null&&v.items.length)||u.catalog_progress.length>0||u.related_catalogs.length>0,sibu:u.bu.length>0||u.unclassified>0,cong:u.collection_groups.length>0,people:u.bibliographers.length>0,lineage:u.lineage.length>0,sites:u.sites.length>0,data:!0},y=Object.keys(j).filter($=>_[$]),k=$=>m(`metaHome.nav.${$}`),w=($,S)=>$?t.jsx("a",{className:"bim-rh-more",href:$,children:S}):void 0;return t.jsxs("div",{className:g?`bim-rh bim-mh ${g}`:"bim-rh bim-mh",children:[t.jsx("style",{children:bs+Lp}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[i,t.jsx(Bp,{counts:u.counts,links:n})]}),o&&t.jsx(Fp,{entries:b.entries,onClear:b.clear,links:n})]}),y.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":m("metaHome.navLabel"),children:t.jsx("ul",{children:y.map($=>t.jsx("li",{children:t.jsx("a",{href:`#${j[$]}`,children:k($)})},$))})}),t.jsxs("div",{className:"bim-rh-main",children:[_.zhi&&t.jsxs(vt,{id:j.zhi,title:k("zhi"),sub:m("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(js,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:x,showTitle:!1,legendCount:u.shelf.items.some($=>$.records)?m("metaHome.shelfLegendCount"):null,legendExtra:[m("metaHome.shelfLegendClick")]}),(u.catalog_progress.length>0||u.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(C=u.shelf)!=null&&C.items.length?void 0:{marginTop:0},children:[t.jsx(Dp,{rows:u.catalog_progress,links:n}),t.jsx(Vp,{works:u.related_catalogs,links:n})]})]}),_.sibu&&t.jsx(vt,{id:j.sibu,title:k("sibu"),sub:m("metaHome.sibuSub"),more:w(s,m("metaHome.toCatalog")),children:t.jsx(vs,{bu:u.bu,unclassified:u.unclassified,links:x,unclassifiedNote:m("metaHome.unclassifiedNote")})}),_.cong&&t.jsx(vt,{id:j.cong,title:k("cong"),sub:m("metaHome.congSub"),more:w(a,m("metaHome.allNKindsMore",{n:lt(u.counts.collections)})),children:t.jsx(Yp,{groups:u.collection_groups,links:n})}),_.people&&t.jsx(vt,{id:j.people,title:k("people"),sub:m("metaHome.peopleSub"),more:w(l,m("metaHome.allNPeopleMore",{n:lt(u.counts.entities)})),children:t.jsx(qp,{people:u.bibliographers,links:n})}),_.lineage&&t.jsx(vt,{id:j.lineage,title:k("lineage"),sub:m("metaHome.lineageSub"),children:t.jsx(Kp,{works:u.lineage,links:n})}),_.sites&&t.jsx(vt,{id:j.sites,title:k("sites"),sub:m("metaHome.sitesSub"),children:t.jsx(Xp,{sites:u.sites})}),t.jsx(vt,{id:j.data,title:k("data"),sub:m("metaHome.dataSub"),children:t.jsx(Zp,{stats:u.stats,links:n,version:d,repoUrl:c,downloadHref:p})})]})]})}const Qp=["_related","_catalogs","_collections","_members","_children"],l1=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),uo=e=>l1(e)&&!!e.h;function c1(e){return e?Qp.some(n=>{const i=e[n];return Array.isArray(i)&&i.some(uo)}):!1}function d1(e,n){const i={...e};if(!n)return i;for(const o of Qp){const s=e[o];!Array.isArray(s)||!s.some(uo)||(i[o]=s.map(a=>{var c;if(!uo(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 p1(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&&d1(d,c1(d)?await i():null)};const a=Reflect.get(o,s,o);return typeof a=="function"?a.bind(o):a}})}const mo=({style:e})=>{const n=f.useContext(Bt),{t:i}=re();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")})]})},go=({href:e,label:n,size:i=16,className:o,style:s})=>{const{t:a}=re(),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 Mr(e){const n=e.text_count;return typeof n=="number"&&n>0}function Pr(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function u1(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const m1=({id:e,transport:n,initialDetail:i,initialEntry:o,activeTab:s,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:p,lineageCollection:g,onLineageCollectionChange:m,initialPage:u=1,selectedLineageNodeId:h,onNavigate:x,onBack:j,backLabel:b,renderLink:_,assetBase:y,enrichDetail:k,getSourceLink:w,readLink:v,railTop:C,extraTabs:$=[],showFeedbackTab:S=!0,feedbackApiUrl:R,height:N,footerExtra:z,hideHeaderControls:I=!1,className:P,style:A})=>{const M=f.useMemo(()=>p1(n),[n]),F=Pe(),{t:ne,convert:je}=re(),[ae]=f.useState(()=>{if(!u1(e,i))return null;const V={...i},U=o??Pr(e,V);return k&&k(U,V),{id:e,entry:U,detail:V}}),[Y,xe]=f.useState((ae==null?void 0:ae.entry)??null),[J,le]=f.useState((ae==null?void 0:ae.detail)??null),[we,ye]=f.useState(!ae),[Q,T]=f.useState(!1),[G,fe]=f.useState([]),[se,Be]=f.useState(!1),[Oe,X]=f.useState(null),[oe,ze]=f.useState(null),[We,be]=f.useState(null),[H,ce]=f.useState(!1),de=f.useRef(null),ee=f.useRef(0),[Ce,Ue]=f.useState(null),Ge=l!==void 0?l:Ce,nt=f.useCallback(V=>{d?d(V):Ue(V)},[d]),O=f.useCallback(async V=>{if(!M.getCollectionCatalogs&&!M.getCollectionCatalog){fe([]);return}Be(!0);try{if(M.getCollectionCatalogs)fe(await M.getCollectionCatalogs(V)||[]);else if(M.getCollectionCatalog){const U=await M.getCollectionCatalog(V);fe(U?[{resource_id:"",data:U}]:[])}}catch{fe([])}finally{Be(!1)}},[M]),ue=f.useCallback(async V=>{var U,Me;if(!M.getTextManifest||!M.getTextIndex){X(null),ze(V);return}try{const He=Ie.pickTextVersion(await M.getTextManifest(V)),_e=He?await M.getTextIndex(V,He.key):null;X(_e&&_e.chapters.length>0?{chapters:_e.chapters.map(K=>({n:K.n,title:K.title,file:K.file})),source:{name:((U=_e.source)==null?void 0:U.name)??(He==null?void 0:He.source_name),license:((Me=_e.source)==null?void 0:Me.license)??(He==null?void 0:He.license)??void 0}}:null)}catch{X(null)}finally{ze(V)}},[M]),Re=f.useCallback(async(V,U)=>{const Me=++ee.current,He=()=>Me!==ee.current;ce(!0);try{if(M.getLineageGraph){const Fe=await M.getLineageGraph(V);if(He())return;Fe&&be(Fe)}const _e=U.version_graph;if(!_e||!_e.enabled){We||be(null),de.current=null;return}const K=Co(U),he=(await Xi(K,Ki,async Fe=>{try{return await M.getItem(Fe)}catch{return null}},He)).filter(Boolean);if(He())return;de.current={work:U,books:he};const Ee=g??_e.default_collection??(_e.core_books&&_e.core_books.length>0?"core":"all"),Se=Ee==="core"&&Array.isArray(_e.core_books)&&_e.core_books.length>0?"core":Ee??"all";be($i(U,he,Se))}catch{if(He())return;be(null),de.current=null}finally{He()||ce(!1)}},[M]),W=f.useRef({initialDetail:i,initialEntry:o});W.current={initialDetail:i,initialEntry:o},f.useEffect(()=>{let V=!1;ee.current++,ce(!1);const U=K=>{K.type==="collection"?O(e):K.type==="work"?(K.version_graph||M.getLineageGraph)&&Re(e,K):K.type==="book"&&Mr(K)&&ue(e)},Me=W.current;let He=null;if(ae&&ae.id===e)He=ae;else if(Me.initialDetail&&Me.initialDetail.id===e){const K={...Me.initialDetail},ke=Me.initialEntry??Pr(e,K);k&&k(ke,K),He={entry:ke,detail:K}}return He?(T(!1),fe(K=>K.length?[]:K),X(null),be(null),de.current=null,xe(He.entry),le(He.detail),ye(!1),U(He.detail),()=>{V=!0}):((async()=>{ye(!0),T(!1),xe(null),le(null),fe([]),X(null),be(null),de.current=null;try{const K=await M.getItem(e);if(V)return;if(!K){T(!0);return}const ke=K;let he=null;if(M.getEntry&&(he=await M.getEntry(e),V))return;he||(he=Pr(e,ke)),k&&k(he,ke),xe(he),le(ke),U(ke)}catch{V||T(!0)}finally{V||ye(!1)}})(),()=>{V=!0})},[e,M,ae,k,O,Re,ue]),f.useEffect(()=>{const V=de.current;!V||!g||be($i(V.work,V.books,g))},[g]);const pe=[];if(J){if(pe.push({key:"basic",label:F.detailTab.basicInfo}),J.type==="collection"){se&&G.length===0&&pe.push({key:"catalog:loading",label:`${F.detailTab.catalog}…`});for(const V of G)pe.push({key:`catalog:${V.resource_id}`,label:V.short_name?`${je(V.short_name)}${F.detailTab.catalogSuffix}`:F.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&pe.push({key:s,label:F.detailTab.fullText}),J.type==="work"&&(We||H)&&pe.push({key:"lineage",label:H?`${F.detailTab.lineage}…`:F.detailTab.lineage});for(const V of $)(V.position??"before-feedback")==="before-feedback"&&V.shouldShow(J)&&pe.push({key:V.key,label:V.label});S&&s==="feedback"&&pe.push({key:"feedback",label:F.detailTab.feedback});for(const V of $)V.position==="after-feedback"&&V.shouldShow(J)&&pe.push({key:V.key,label:V.label})}f.useEffect(()=>{if(s!=="emendated"||!J)return;a("basic");const V=setTimeout(()=>{var U;(U=document.getElementById("studies"))==null||U.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(V)},[s,J,a]);const ie=Y&&J&&w?w({activeTab:s,activeJuan:Ge,entry:Y,detail:J}):null,Ne=f.useMemo(()=>{var _e,K,ke,he,Ee;if(!J)return null;const U=(J.authors??[]).map(Se=>{const Fe=$o(Se.role);return`${Se.dynasty?`〔${je(Se.dynasty)}〕`:""}${je(Se.name)}${Fe?` ${je(Fe)}`:""}`}).join(" · ");let Me=!1;try{Me=Ie.extractStatus(J.id)==="draft"}catch{}if(J.type==="book"){const Se=J;return{title:je(Se.title),subtitle:Se.edition?je(Se.edition):U||void 0,aside:[Me?F.status.draft:"",U&&Se.edition?U:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(J.type==="collection"){const Se=J;return{title:je(Se.title),subtitle:je(Yt(Se,F.unit.juan))||void 0,aside:[(_e=Se.publication_info)==null?void 0:_e.year,Me?F.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:U||void 0}}if(J.type==="entity"){const Se=J,Fe=et=>et==null?"":et<0?ne("detail.bce",{n:-et}):String(et),Ye=((K=Se.dates)==null?void 0:K.birth)!=null||((ke=Se.dates)==null?void 0:ke.death)!=null?`${Fe(((he=Se.dates)==null?void 0:he.birth)??void 0)||"?"}—${Fe(((Ee=Se.dates)==null?void 0:Ee.death)??void 0)||"?"}`:"";return{title:je(Se.primary_name||Se.title),subtitle:[Se.dynasty?`〔${je(Se.dynasty)}〕`:"",Ye].filter(Boolean).join(" ")||void 0,aside:Me?F.status.draft:void 0,secondLine:void 0}}const He=je(Yt(J,F.unit.juan));return{title:je(J.title),subtitle:[He,U].filter(Boolean).join(" · ")||void 0,aside:[f1(F,J.subtype),Me?F.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[J,je,F,ne]),Le=J&&Mr(J)?"text":null,Ve=()=>{nt(null),a("fulltext")};let Xe=null;if(J&&v){const V=v({detail:J,kind:Le});V&&(Xe=t.jsx(qr,{href:V}))}else Le&&(Xe=t.jsx(qr,{onClick:Ve}));const ot=V=>{if(!J)return null;const U=V.replace(/\.[^.]+$/,"");if(v){const Me=v({detail:J,kind:Le,juan:U});return Me?{href:Me}:null}return{onClick:()=>{nt(U),a("fulltext")}}},it=new Set($.map(V=>V.key)),E=pe.filter(V=>V.key.startsWith("catalog:")&&V.key!=="catalog:loading"||V.key==="lineage"&&!!We&&!H||it.has(V.key)).map(V=>({key:V.key,label:V.label,onClick:()=>a(V.key)})),ge=()=>{var V;return J?J.type==="work"?t.jsx(np,{data:J,transport:M,onNavigate:x,renderLink:_,readAction:Xe,railTop:C,railLinks:E}):J.type==="book"?t.jsx(sp,{data:J,transport:M,onNavigate:x,renderLink:_,readAction:Xe,fullText:Oe,fullTextPending:Mr(J)&&!!M.getTextManifest&&oe!==J.id,chapterLink:ot,railTop:C,railLinks:E}):J.type==="collection"?t.jsx(ap,{data:J,catalog:(V=G[0])==null?void 0:V.data,transport:M,onNavigate:x,renderLink:_,readAction:Xe,railTop:C,railLinks:E,catalogAction:G.length>0?t.jsxs("a",{href:"#catalog",onClick:U=>{U.preventDefault(),a(`catalog:${G[0].resource_id}`)},children:[je(F.detailTab.collectionCatalog)," →"]}):null}):t.jsx(cp,{data:J,transport:M,onNavigate:x,renderLink:_,railTop:C,railLinks:E,assetBase:y}):null},ve=()=>{var U,Me,He;if(!Y||!J)return null;if(s==="basic"||s==="emendated")return ge();if(typeof s=="string"&&s.startsWith("catalog:")){const _e=(U=G.find(K=>`catalog:${K.resource_id}`===s))==null?void 0:U.data;return t.jsx(Ro,{data:_e,onNavigate:x,renderLink:_})}if(s==="collated"||s==="fulltext")return t.jsx(ls,{id:e,transport:M,chapter:Ge,onLocationChange:_e=>nt(_e.chapter),onNavigate:x});if(s==="lineage"){if(!We)return t.jsx("div",{style:{color:r("label-fg"),padding:"24px 0"},children:ne(H?"detail.loading":"detail.noLineageGraph")});const _e=J.type==="work"?J:null;return t.jsx(gs,{graph:We,renderLink:_,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:p,selectedNodeId:h,collection:g??((Me=_e==null?void 0:_e.version_graph)==null?void 0:Me.default_collection),onCollectionChange:m,collectionsAvailable:(He=_e==null?void 0:_e.version_graph)==null?void 0:He.collections,collectionCounts:(()=>{var Ee,Se,Fe,Ye,et,Ke,ct;if(!_e)return;const K={},ke=((Ee=de.current)==null?void 0:Ee.books)??[];K.all=(((Se=_e._books)==null?void 0:Se.length)??0)-(((Ye=(Fe=_e.version_graph)==null?void 0:Fe.excluded_books)==null?void 0:Ye.length)??0);const he=(et=_e.version_graph)==null?void 0:et.collections;if(he)for(const qe of Object.keys(he))K[qe]=$i(_e,ke,qe).nodes.filter(q=>q.kind==="book"&&!q.bridge).length;return K.core==null&&((ct=(Ke=_e.version_graph)==null?void 0:Ke.core_books)!=null&&ct.length)&&(K.core=_e.version_graph.core_books.length),K})()})}if(s==="feedback"&&S)return t.jsx(Jd,{resourceId:e,apiUrl:R});const V=$.find(_e=>_e.key===s);return V?V.render({detail:J,entry:Y,transport:M,onNavigate:x}):null};if(we)return t.jsx(Un,{style:{minHeight:N,...A},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((V,U)=>t.jsx("div",{style:{height:U===1?40:16,width:V,opacity:.35,background:r("rule")}},U))})});if(Q||!J||!Y||!Ne)return t.jsx(Un,{style:{minHeight:N,...A},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r("label-fg"),fontSize:14},children:ne("detail.notFound")})});const $e=s==="basic"||s==="emendated",D=[{label:b??F.detailTab.backToIndex,onClick:j}];if(J.type==="book"&&J.work_id){const V=J.work_id;D.push({label:F.indexType.work,id:V,onClick:()=>x==null?void 0:x(V)})}D.push({label:F.indexType[J.type]});const B=s==="collated"||s==="fulltext",Z=typeof z=="string"?F.status[z.trim()]??z:z,me=t.jsx(ed,{left:t.jsxs(t.Fragment,{children:[Z,Z?" · ":"",t.jsx(g1,{id:J.id,label:F.label.id,copied:F.action.copied,copyLabel:F.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!$e&&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:F.detailTab.submitVersion}),ie&&t.jsx("a",{href:ie.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r("meta-fg")},children:F.detailTab.dataLicense})]})});return $e?t.jsx("div",{className:P,children:t.jsxs(Un,{grid:!0,style:{minHeight:N,...A},children:[t.jsx(Kr,{breadcrumb:t.jsx(Xr,{items:D}),actions:t.jsxs(t.Fragment,{children:[!I&&t.jsx(mo,{style:{border:"none",background:"transparent"}}),!I&&ie&&t.jsx(go,{...ie})]})}),ge(),me]})}):t.jsx("div",{className:P,children:t.jsxs(Un,{wide:B,style:{minHeight:N,...A},children:[t.jsx(Kr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Oo,{char:"籍"}),t.jsx(Xr,{items:D})]}),actions:t.jsxs(t.Fragment,{children:[!I&&t.jsx(mo,{}),S&&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:F.detailTab.feedback}),!I&&ie&&t.jsx(go,{...ie})]})}),t.jsx(Vc,{...Ne,aside:B?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:[ne("detail.workInfo")," →"]}):Ne.aside}),!B&&pe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:pe.map(V=>t.jsx(Gc,{label:V.label,active:V.key===s||$e&&V.key==="basic",onClick:()=>a(V.key)},V.key))}),t.jsx("div",{style:{marginTop:!B&&pe.length>1?8:0},children:ve()}),me]})})};function g1({id:e,label:n,copied:i,copyLabel:o}){const[s,a]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var 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 f1(e,n){return n?e.workSubtype[n]??n:""}const eu=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],Qi="zhusha",er="bim-theme";function tu(e){return e==="zhusha"||e==="indigo"||e==="ink"}function tr(e){return tu(e)?e:Qi}function h1(){try{return tr(window.localStorage.getItem(er))}catch{return Qi}}function nu(e){try{window.localStorage.setItem(er,e)}catch{}}function iu(e){const n=tr(e);return document.documentElement.setAttribute("data-theme",n),n}function ru(){return tr(document.documentElement.getAttribute("data-theme"))}const x1=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],ws="airy",nr="bim-layout";function ou(e){return e==="airy"||e==="boxed"}function ir(e){return ou(e)?e:ws}function b1(){try{return ir(window.localStorage.getItem(nr))}catch{return ws}}function y1(e){try{window.localStorage.setItem(nr,e)}catch{}}function j1(e){const n=ir(e);return document.documentElement.setAttribute("data-layout",n),n}function v1(){return ir(document.documentElement.getAttribute("data-layout"))}const k1=`try{var t=localStorage.getItem(${JSON.stringify(er)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(nr)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,w1={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},S1=({onChange:e,style:n})=>{const{t:i}=re(),[o,s]=f.useState(Qi);f.useEffect(()=>{s(ru())},[]);const a=l=>{s(iu(l)),nu(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":i("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...n},children:eu.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(w1[l.name]),boxShadow:d?`0 0 0 2px ${r("page-bg")}, 0 0 0 3.5px ${r("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=Ie.BidLink;exports.BookIndexError=Ie.BookIndexError;exports.BookIndexManager=Ie.BookIndexManager;exports.BookIndexStorage=Ie.BookIndexStorage;exports.BundleStorage=Ie.BundleStorage;exports.ConfigError=Ie.ConfigError;exports.GithubStorage=Ie.GithubStorage;exports.IdGenerationError=Ie.IdGenerationError;exports.IdGenerator=Ie.IdGenerator;exports.LocalStorage=Ie.LocalStorage;exports.MigrationError=Ie.MigrationError;exports.StorageError=Ie.StorageError;exports.VARIANT_CHARS=Ie.VARIANT_CHARS;exports.base36Decode=Ie.base36Decode;exports.base36Encode=Ie.base36Encode;exports.base58Decode=Ie.base58Decode;exports.buildId=Ie.buildId;exports.buildPromotionMap=Ie.buildPromotionMap;exports.cleanName=Ie.cleanName;exports.decodeId=Ie.decodeId;exports.decodeIdString=Ie.decodeIdString;exports.encodeId=Ie.encodeId;exports.extractIdFromUrl=Ie.extractIdFromUrl;exports.extractStatus=Ie.extractStatus;exports.extractType=Ie.extractType;exports.isChapterSegment=Ie.isChapterSegment;exports.isTextKey=Ie.isTextKey;exports.matchChapterAcrossVersions=Ie.matchChapterAcrossVersions;exports.normalizeCatalog=Ie.normalizeCatalog;exports.normalizeVariants=Ie.normalizeVariants;exports.parseId=Ie.parseId;exports.pickTextVersion=Ie.pickTextVersion;exports.shardOf=Ie.shardOf;exports.smartDecode=Ie.smartDecode;exports.textVersionLabel=Ie.textVersionLabel;exports.validateResource=Ie.validateResource;exports.VARIANT_SUPPLEMENT=Il.VARIANT_SUPPLEMENT;exports.Badge=Ei;exports.BidUrlProvider=Ru;exports.BookDetailLayout=m1;exports.BookPage=sp;exports.Breadcrumb=Xr;exports.CATALOG_ALL_ID=Ut;exports.CATALOG_CSS=dp;exports.CATALOG_NARROW_QUERY=fs;exports.CATALOG_PAGE_SIZE=hs;exports.CATALOG_UNCLASSIFIED_ID=cn;exports.CLASSIFICATIONS=Di;exports.COMMON_TRADITIONAL_CHARS=Hl;exports.CardFoot=ti;exports.CatalogPage=Y0;exports.CatalogPager=xp;exports.CatalogTree=up;exports.CheckFilter=Hc;exports.Chip=Yc;exports.ChipWall=Pf;exports.CollectionCatalog=Ro;exports.CollectionPage=ap;exports.CreateEntityDialog=Ud;exports.DEFAULT_LAYOUT=ws;exports.DEFAULT_META_HOME_LINKS=Ap;exports.DEFAULT_READER_PREFS=Ao;exports.DEFAULT_READ_HOME_LINKS=yp;exports.DEFAULT_THEME=Qi;exports.DETAIL_CSS=Uc;exports.DYNASTY_GROUPS=Hi;exports.Dash=Df;exports.DataTable=Of;exports.DetailFooter=ed;exports.DetailGrid=Qn;exports.DetailHeader=Vc;exports.EMPTY_FILTERS=Fi;exports.ENTITY_TEXT_CSS=ts;exports.EmendatedBySection=yc;exports.EmptyNote=Xf;exports.EntityDetail=gc;exports.EntityMark=is;exports.EntityPage=cp;exports.EntityPickerDialog=Gd;exports.EntitySelector=Dd;exports.EntityText=yx;exports.ExpandRow=Uf;exports.ExtLink=Zf;exports.FEEDBACK_FAB_OFFSET_VAR=ao;exports.FILTER_SUPPORT=oc;exports.FONT_SIZE_STEPS=Dt;exports.FactList=Rf;exports.FeedbackButton=Ny;exports.FeedbackDialog=Xd;exports.FeedbackForm=Zd;exports.FeedbackList=cs;exports.FeedbackTab=Jd;exports.FilterChip=Gc;exports.FormInput=_t;exports.FormTextArea=pn;exports.GUJI_MARKDOWN_FIELD=bf;exports.GUJI_TABLE_NOTATION=td;exports.GlyphBadge=Oo;exports.GujiInteractiveReader=jb;exports.GujiTable=Ho;exports.GujiTextViewer=os;exports.GujiWarpCanvas=es;exports.HomePage=oo;exports.ImagePanel=Ur;exports.IndexApp=yb;exports.IndexBrowser=Hr;exports.IndexDetail=Eo;exports.IndexEditor=Yd;exports.IndexView=fy;exports.IntroGrid=Ef;exports.LAYOUTS=x1;exports.LAYOUT_STORAGE_KEY=nr;exports.LOSS_OPTIONS=rc;exports.LocaleContext=Bt;exports.LocaleProvider=am;exports.LocaleToggle=mo;exports.META_HOME_CSS=Lp;exports.META_HOME_SECTION_IDS=Jp;exports.MetaCatalogTable=Dp;exports.MetaCollectionGroups=Yp;exports.MetaDataLicense=Zp;exports.MetaHomeView=a1;exports.MetaLine=ft;exports.MetaLineageCards=Kp;exports.MetaOnlineSites=Xp;exports.MetaPeopleTimeline=qp;exports.MetaRecentPanel=Fp;exports.MetaRelatedCatalogs=Vp;exports.MetaTypeChips=Bp;exports.ModeIndicator=Ul;exports.MoreButton=Mf;exports.MoreLink=Po;exports.PAGE_MAX_WIDTH=wi;exports.PERIOD_NARROW_SHARE=wp;exports.PageFrame=Un;exports.Quote=Gf;exports.READER_CSS=_c;exports.READ_HOME_CSS=bs;exports.READ_HOME_NARROW_QUERY=ri;exports.READ_HOME_SECTION_IDS=Rp;exports.READ_PERIOD_LABELS=Z0;exports.RECENT_IDS_STORAGE_KEY=Sn;exports.ROLE_CLASS_ORDER=Jl;exports.ReadButton=qr;exports.ReadFamousWorks=Tp;exports.ReadHomeView=Q0;exports.ReadPeriodBand=Ip;exports.ReadPicks=$p;exports.ReadPieces=Ep;exports.ReadSection=vt;exports.ReadShelf=js;exports.ReadSibu=vs;exports.ReadStats=_p;exports.ReadTopicGroup=zp;exports.ReadTopics=Np;exports.ReaderMdText=Go;exports.ReaderShell=Rc;exports.ReaderToc=$c;exports.RelationPanel=Fd;exports.RepoSourceLink=go;exports.ResourceEditor=Br;exports.ResourceGroup=Yf;exports.ResourceLine=qf;exports.ResourceList=vo;exports.ResourceRow=Jc;exports.SEARCH_VIEW_STORAGE_KEY=No;exports.SEVEN_PAVILIONS_KEY=Gp;exports.SNIPPET_MARK_END=Ll;exports.SNIPPET_MARK_START=Rl;exports.SORTABLE_TYPES=ic;exports.SearchInput=Gl;exports.SearchResults=pc;exports.Sec=ht;exports.Section=Et;exports.SectionHead=Lf;exports.SideList=dn;exports.SmartBidInput=_i;exports.SourceEditor=Bd;exports.StripWarpRenderer=Qr;exports.SummaryCard=ei;exports.THEMES=eu;exports.THEME_INIT_SCRIPT=k1;exports.THEME_STORAGE_KEY=er;exports.TRADITIONAL_ALLOWLIST=Dl;exports.TabFilter=Vi;exports.TableHead=Wf;exports.TableRow=Ff;exports.TagRow=Qc;exports.TagRows=Kf;exports.TextButton=Af;exports.TextReader=ls;exports.ThemeToggle=S1;exports.TopStrip=Kr;exports.VersionLineageGraph=op;exports.VersionLineageList=rp;exports.VersionLineageView=gs;exports.VolumeChips=Bf;exports.VolumeLinks=Wo;exports.WorkCard=fp;exports.WorkCardGrid=bp;exports.WorkCatalog=Lb;exports.WorkPage=np;exports.WorkRow=hp;exports.adaptCharCord=Ib;exports.adaptEntityJson=md;exports.adaptFig=Rb;exports.adaptNorm=Pd;exports.adaptNormDetailed=Md;exports.adaptPunctJson=Sb;exports.applyLayout=j1;exports.applyTheme=iu;exports.authorsLine=Ji;exports.bookIndexUriToId=Jr;exports.bookMarkingOf=Vo;exports.bucketResources=So;exports.buildCatalogTree=B0;exports.buildCollectionTable=tc;exports.buildLineageGraph=$i;exports.buildMeiliFilter=Gm;exports.buildPageUrl=yo;exports.buildParagraphBlocks=ld;exports.buildVersionRow=Xl;exports.buildVersionTable=Zl;exports.canParagraphize=Ti;exports.catalogNodeIdOf=M0;exports.catalogNodeIdsOf=P0;exports.catalogPageCount=H0;exports.catalogTotal=xs;exports.classificationPath=ii;exports.clearAllRecentIds=To;exports.compareCatalogCards=F0;exports.computeVersionPartition=Pm;exports.countActiveFilters=Ui;exports.createTextApi=vc;exports.currentLayout=v1;exports.currentTheme=ru;exports.defaultEntityHref=kd;exports.defaultWorkLink=mp;exports.deriveDating=Tm;exports.deriveEditionType=nc;exports.deriveEra=Jn;exports.deriveYear=Bi;exports.deriveYearRange=wo;exports.detailToEditor=Kd;exports.detectGenre=Yi;exports.displayAuthorRole=$o;exports.editorToDetail=gy;exports.eraRank=Wr;exports.filtersFromParams=Ym;exports.filtersToParams=Ni;exports.findCatalogPath=vn;exports.findTraditionalChars=dm;exports.firstAuthorText=ys;exports.flattenTitles=Zr;exports.flattenToc=Ec;exports.fmtCount=lt;exports.formatHitCount=ji;exports.formatTemplate=$t;exports.formatVolumeRange=Wi;exports.getDisplayNameFromUrl=$n;exports.getMessages=zn;exports.getStartPage=bo;exports.getT=Nn;exports.getTypeGroupKey=ho;exports.groupRelatedWorks=Im;exports.gujiInlineToPlain=Wc;exports.hasActiveFilters=sc;exports.hasGujiMarkdownV02=yf;exports.hasGujiTableNotation=Jf;exports.hasSearchOptions=Dm;exports.headingKey=as;exports.headingsFromPunct=zd;exports.iiifVolumeOf=_b;exports.isCountedChar=Yo;exports.isDuiduChapter=ro;exports.isLayoutName=ou;exports.isThemeName=tu;exports.lineageHref=Mp;exports.loadRecentIds=Qt;exports.measureText=Yt;exports.mergeVolumeResources=xo;exports.nestHeadings=Td;exports.normalizeEra=gt;exports.normalizeLayout=ir;exports.normalizeRole=_o;exports.normalizeTheme=tr;exports.normalizeVolumeIndex=Gn;exports.normalizeVolumes=Pl;exports.numberToChinese=In;exports.paginationItems=pp;exports.parseChineseNumber=Ci;exports.parseGujiInline=Oc;exports.parseGujiTable=id;exports.parseHeadingKey=Nd;exports.parseSourceString=Od;exports.pct=ks;exports.periodLevel=kp;exports.pickReaderVersion=Ic;exports.readStoredLayout=b1;exports.readStoredTheme=h1;exports.readerVersionOptionLabel=Gr;exports.remapPlainOffsets=gd;exports.removeRecentId=uc;exports.renderFullTextBody=lh;exports.renderProperNames=pd;exports.renderReaderInline=qi;exports.resolveRecentEntry=Io;exports.resourceHref=Cn;exports.resourceNote=Oi;exports.resultTabFromParam=ig;exports.resultTabToParam=rg;exports.roleFacets=Ql;exports.rowNo=Hf;exports.sameFilters=qm;exports.sanitizeHeadings=io;exports.saveRecentId=Fr;exports.segmentEntities=fd;exports.shelfColumns=jp;exports.sortFor=Um;exports.sortYear=zi;exports.spineHeight=vp;exports.splitFullTextTables=Fo;exports.splitHighlightSnippet=fo;exports.splitTableRow=nd;exports.storeLayout=y1;exports.storeTheme=nu;exports.stringifySources=Wd;exports.summaryFromEntry=jd;exports.summaryFromItem=yd;exports.timelineLayout=Pp;exports.toCatalogWorkCard=W0;exports.transportSummaryLoader=vd;exports.typeSupportsFilters=ac;exports.useBidUrl=mt;exports.useChapterWarpData=Cd;exports.useConvert=De;exports.useEntitySummaryLoader=ns;exports.useI18n=re;exports.useReaderPrefs=Tc;exports.useRecentEntries=Op;exports.useT=Pe;exports.validateLineageGraph=e0;exports.volumeStats=Li;exports.withDefaultLinks=en;exports.withMetaLinks=tn;exports.yearText=Ri;
2005
+ `,Pp={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function tn(e){return{...Pp,...e??{}}}function Bp(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 ws(e,n){return!n||n<=0?0:Math.max(0,Math.min(100,Math.round(e/n*100)))}function Op(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,g=Number.isFinite(p.death_year)?p.death_year:p.birth_year+50;return[Math.min(m,g),Math.max(m,g)]},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 Li(e,n=Nn("zh-Hant")){return e<0?n("metaHome.yearBC",{n:-e}):String(e)}function s1(e){return{read:e.item,work:e.item,node:e.node}}function Wp({counts:e,links:n}){const{t:i}=ie(),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:ct(d)})]})},a))})}function Fp(e,n=5){const[i,o]=f.useState(null);f.useEffect(()=>{let a=!1;const l=Qt().slice(0,n);if(!l.length||!e){o([]);return}return Promise.all(l.map(d=>Io(e,d))).then(d=>{a||o(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,n]);const s=f.useCallback(()=>{Eo(),o([])},[]);return{entries:i,clear:s}}function a1(e,n,i){const o=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return o?i(o):Hp(e.type,n)}function Hp(e,n){return n(`metaHome.typeLabel.${e}`)}function Dp({entries:e,onClear:n,links:i}){const{t:o,convert:s}=ie(),a=tn(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?Hp(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:a1(l,o,s)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:o("metaHome.recentEmpty")})]})}function Up(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 Vp({rows:e,links:n}){const{t:i,convert:o}=ie(),s=tn(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=ws(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:ct(a.total)}),t.jsx("td",{className:"bim-mh-r",children:ct(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:Up(a.status,i,o)})})]},a.id||a.name)})})]})}):null}function Gp({items:e,links:n,label:i}){const{convert:o}=ie();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 Yp({works:e,links:n}){const{t:i}=ie(),[o,s]=f.useState(!1);if(!e.length)return null;const a=Jn(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(Gp,{items:e.map(l=>({id:l.id,title:l.title,sub:Qi(l)||void 0})),links:tn(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 qp="siku_qige";function l1({group:e,links:n}){const{t:i,convert:o}=ie(),[s,a]=f.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Jn(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(Gp,{items:e.items,links:n,label:e.label}),Jn(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 Kp({groups:e,links:n}){const{t:i,convert:o}=ie(),s=tn(n);if(!e.length)return null;const a=e.find(c=>c.key===qp),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(l1,{group:c,links:s},c.key))})]})}const Cl=34,zl=13;function Nl(e,n){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Li(e.birth_year,n):"?"}–${e.death_year!=null?Li(e.death_year,n):"?"}`}function c1(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 Xp({people:e,links:n}){const{t:i,convert:o}=ie(),s=tn(n);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=Op(e),p=[],m=d.map(u=>{const h=u.left>70,x=h?Math.min(u.left,u.left+u.width-zl):u.left;let j=0;for(;p[j]!=null&&p[j]>x;)j++;return p[j]=h?u.left+u.width:u.left+Math.max(u.width,zl),{...u,lane:j,end:h}}),g=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*Cl+10},children:m.map(u=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":u.end?"":void 0,style:{left:`${u.left}%`,top:u.lane*Cl+4,width:`${Math.max(u.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:s.item(u.p.id),children:[o(u.p.name),t.jsx("small",{className:"bim-rh-num",children:Nl(u.p,i)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:c1(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/g*100}%`},children:Li(u,i)},u))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":m.length?void 0:"",children:(m.length?e:c).map(u=>t.jsx("li",{children:t.jsxs("a",{href:s.item(u.id),children:[t.jsx("span",{children:o(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?o(u.dynasty):"",Nl(u,i)].filter(Boolean).join(" ")})]})},u.id))}),c.length>0&&m.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:i("metaHome.missingLife",{names:o(c.map(u=>u.name).join("、"))})})]})}const d1=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 Zp({works:e,links:n}){const{t:i,convert:o}=ie(),s=tn(n);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=Qi(a);return t.jsx("li",{children:t.jsxs("a",{href:Bp(s,a.id),children:[d1,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 Jp({sites:e}){const{t:n,convert:i}=ie(),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=ws(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:[`${ct(a.imported)} / ${ct(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:Up(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 Tl=["extant","partially_extant","lost","unknown"];function Qp({stats:e,links:n,version:i,repoUrl:o,downloadHref:s}){const{t:a}=ie(),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=Tl.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:ct(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:Tl.map(p=>{var u;const m=((u=e.loss)==null?void 0:u[p])??0,g=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:ct(m),note:g}):g})]})},p)})})]}),t.jsxs("div",{className:"bim-mh-lic",children:[t.jsxs("p",{children:[t.jsx("span",{className:"bim-mh-cc0",children:"CC BY-SA 4.0"}),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 eu={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function p1({sections:e,links:n,head:i,transport:o,catalogHref:s,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:p,className:m}){var v,C;const{t:g}=ie(),u=e,h=tn(n),x=s1(h),j=eu,b=Fp(o),_={zhi:!!((v=u.shelf)!=null&&v.items.length)||u.catalog_progress.length>0||u.related_catalogs.length>0,sibu:u.bu.length>0||u.unclassified>0,cong:u.collection_groups.length>0,people:u.bibliographers.length>0,lineage:u.lineage.length>0,sites:u.sites.length>0,data:!0},y=Object.keys(j).filter($=>_[$]),k=$=>g(`metaHome.nav.${$}`),w=($,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:ys+Mp}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[i,t.jsx(Wp,{counts:u.counts,links:n})]}),o&&t.jsx(Dp,{entries:b.entries,onClear:b.clear,links:n})]}),y.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":g("metaHome.navLabel"),children:t.jsx("ul",{children:y.map($=>t.jsx("li",{children:t.jsx("a",{href:`#${j[$]}`,children:k($)})},$))})}),t.jsxs("div",{className:"bim-rh-main",children:[_.zhi&&t.jsxs(vt,{id:j.zhi,title:k("zhi"),sub:g("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(vs,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:x,showTitle:!1,legendCount:u.shelf.items.some($=>$.records)?g("metaHome.shelfLegendCount"):null,legendExtra:[g("metaHome.shelfLegendClick")]}),(u.catalog_progress.length>0||u.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(C=u.shelf)!=null&&C.items.length?void 0:{marginTop:0},children:[t.jsx(Vp,{rows:u.catalog_progress,links:n}),t.jsx(Yp,{works:u.related_catalogs,links:n})]})]}),_.sibu&&t.jsx(vt,{id:j.sibu,title:k("sibu"),sub:g("metaHome.sibuSub"),more:w(s,g("metaHome.toCatalog")),children:t.jsx(ks,{bu:u.bu,unclassified:u.unclassified,links:x,unclassifiedNote:g("metaHome.unclassifiedNote")})}),_.cong&&t.jsx(vt,{id:j.cong,title:k("cong"),sub:g("metaHome.congSub"),more:w(a,g("metaHome.allNKindsMore",{n:ct(u.counts.collections)})),children:t.jsx(Kp,{groups:u.collection_groups,links:n})}),_.people&&t.jsx(vt,{id:j.people,title:k("people"),sub:g("metaHome.peopleSub"),more:w(l,g("metaHome.allNPeopleMore",{n:ct(u.counts.entities)})),children:t.jsx(Xp,{people:u.bibliographers,links:n})}),_.lineage&&t.jsx(vt,{id:j.lineage,title:k("lineage"),sub:g("metaHome.lineageSub"),children:t.jsx(Zp,{works:u.lineage,links:n})}),_.sites&&t.jsx(vt,{id:j.sites,title:k("sites"),sub:g("metaHome.sitesSub"),children:t.jsx(Jp,{sites:u.sites})}),t.jsx(vt,{id:j.data,title:k("data"),sub:g("metaHome.dataSub"),children:t.jsx(Qp,{stats:u.stats,links:n,version:d,repoUrl:c,downloadHref:p})})]})]})}const tu=["_related","_catalogs","_collections","_members","_children"],u1=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),mo=e=>u1(e)&&!!e.h;function m1(e){return e?tu.some(n=>{const i=e[n];return Array.isArray(i)&&i.some(mo)}):!1}function g1(e,n){const i={...e};if(!n)return i;for(const o of tu){const s=e[o];!Array.isArray(s)||!s.some(mo)||(i[o]=s.map(a=>{var c;if(!mo(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 f1(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&&g1(d,m1(d)?await i():null)};const a=Reflect.get(o,s,o);return typeof a=="function"?a.bind(o):a}})}const go=({style:e})=>{const n=f.useContext(Bt),{t:i}=ie();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")})]})},fo=({href:e,label:n,size:i=16,className:o,style:s})=>{const{t:a}=ie(),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 Pr(e){const n=e.text_count;return typeof n=="number"&&n>0}function Br(e,n){return{id:e,title:n.title??n.primary_name??e,type:n.type??"book"}}function h1(e,n){if(!n)return!1;const i=n.id;return i===void 0||i===e}const x1=({id:e,transport:n,initialDetail:i,initialEntry:o,activeTab:s,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:p,lineageCollection:m,onLineageCollectionChange:g,initialPage:u=1,selectedLineageNodeId:h,onNavigate:x,onBack:j,backLabel:b,renderLink:_,assetBase:y,enrichDetail:k,getSourceLink:w,readLink:v,railTop:C,extraTabs:$=[],showFeedbackTab:S=!0,feedbackApiUrl:I,height:N,footerExtra:z,hideHeaderControls:E=!1,className:P,style:A})=>{const M=f.useMemo(()=>f1(n),[n]),F=Pe(),{t:q,convert:be}=ie(),[se]=f.useState(()=>{if(!h1(e,i))return null;const V={...i},U=o??Br(e,V);return k&&k(U,V),{id:e,entry:U,detail:V}}),[Y,xe]=f.useState((se==null?void 0:se.entry)??null),[Q,le]=f.useState((se==null?void 0:se.detail)??null),[we,je]=f.useState(!se),[ee,T]=f.useState(!1),[G,fe]=f.useState([]),[ae,Be]=f.useState(!1),[Oe,Z]=f.useState(null),[oe,ze]=f.useState(null),[We,ye]=f.useState(null),[H,ce]=f.useState(!1),de=f.useRef(null),te=f.useRef(0),[Ce,Ue]=f.useState(null),Ge=l!==void 0?l:Ce,nt=f.useCallback(V=>{d?d(V):Ue(V)},[d]),O=f.useCallback(async V=>{if(!M.getCollectionCatalogs&&!M.getCollectionCatalog){fe([]);return}Be(!0);try{if(M.getCollectionCatalogs)fe(await M.getCollectionCatalogs(V)||[]);else if(M.getCollectionCatalog){const U=await M.getCollectionCatalog(V);fe(U?[{resource_id:"",data:U}]:[])}}catch{fe([])}finally{Be(!1)}},[M]),ue=f.useCallback(async V=>{var U,Me;if(!M.getTextManifest||!M.getTextIndex){Z(null),ze(V);return}try{const He=Ee.pickTextVersion(await M.getTextManifest(V)),_e=He?await M.getTextIndex(V,He.key):null;Z(_e&&_e.chapters.length>0?{chapters:_e.chapters.map(X=>({n:X.n,title:X.title,file:X.file})),source:{name:((U=_e.source)==null?void 0:U.name)??(He==null?void 0:He.source_name),license:((Me=_e.source)==null?void 0:Me.license)??(He==null?void 0:He.license)??void 0}}:null)}catch{Z(null)}finally{ze(V)}},[M]),Re=f.useCallback(async(V,U)=>{const Me=++te.current,He=()=>Me!==te.current;ce(!0);try{if(M.getLineageGraph){const Fe=await M.getLineageGraph(V);if(He())return;Fe&&ye(Fe)}const _e=U.version_graph;if(!_e||!_e.enabled){We||ye(null),de.current=null;return}const X=zo(U),he=(await Zi(X,Xi,async Fe=>{try{return await M.getItem(Fe)}catch{return null}},He)).filter(Boolean);if(He())return;de.current={work:U,books:he};const Ie=m??_e.default_collection??(_e.core_books&&_e.core_books.length>0?"core":"all"),Se=Ie==="core"&&Array.isArray(_e.core_books)&&_e.core_books.length>0?"core":Ie??"all";ye(Ci(U,he,Se))}catch{if(He())return;ye(null),de.current=null}finally{He()||ce(!1)}},[M]),W=f.useRef({initialDetail:i,initialEntry:o});W.current={initialDetail:i,initialEntry:o},f.useEffect(()=>{let V=!1;te.current++,ce(!1);const U=X=>{X.type==="collection"?O(e):X.type==="work"?(X.version_graph||M.getLineageGraph)&&Re(e,X):X.type==="book"&&Pr(X)&&ue(e)},Me=W.current;let He=null;if(se&&se.id===e)He=se;else if(Me.initialDetail&&Me.initialDetail.id===e){const X={...Me.initialDetail},ke=Me.initialEntry??Br(e,X);k&&k(ke,X),He={entry:ke,detail:X}}return He?(T(!1),fe(X=>X.length?[]:X),Z(null),ye(null),de.current=null,xe(He.entry),le(He.detail),je(!1),U(He.detail),()=>{V=!0}):((async()=>{je(!0),T(!1),xe(null),le(null),fe([]),Z(null),ye(null),de.current=null;try{const X=await M.getItem(e);if(V)return;if(!X){T(!0);return}const ke=X;let he=null;if(M.getEntry&&(he=await M.getEntry(e),V))return;he||(he=Br(e,ke)),k&&k(he,ke),xe(he),le(ke),U(ke)}catch{V||T(!0)}finally{V||je(!1)}})(),()=>{V=!0})},[e,M,se,k,O,Re,ue]),f.useEffect(()=>{const V=de.current;!V||!m||ye(Ci(V.work,V.books,m))},[m]);const pe=[];if(Q){if(pe.push({key:"basic",label:F.detailTab.basicInfo}),Q.type==="collection"){ae&&G.length===0&&pe.push({key:"catalog:loading",label:`${F.detailTab.catalog}…`});for(const V of G)pe.push({key:`catalog:${V.resource_id}`,label:V.short_name?`${be(V.short_name)}${F.detailTab.catalogSuffix}`:F.detailTab.collectionCatalog})}(s==="collated"||s==="fulltext")&&pe.push({key:s,label:F.detailTab.fullText}),Q.type==="work"&&(We||H)&&pe.push({key:"lineage",label:H?`${F.detailTab.lineage}…`:F.detailTab.lineage});for(const V of $)(V.position??"before-feedback")==="before-feedback"&&V.shouldShow(Q)&&pe.push({key:V.key,label:V.label});S&&s==="feedback"&&pe.push({key:"feedback",label:F.detailTab.feedback});for(const V of $)V.position==="after-feedback"&&V.shouldShow(Q)&&pe.push({key:V.key,label:V.label})}f.useEffect(()=>{if(s!=="emendated"||!Q)return;a("basic");const V=setTimeout(()=>{var U;(U=document.getElementById("studies"))==null||U.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(V)},[s,Q,a]);const re=Y&&Q&&w?w({activeTab:s,activeJuan:Ge,entry:Y,detail:Q}):null,Ne=f.useMemo(()=>{var _e,X,ke,he,Ie;if(!Q)return null;const U=(Q.authors??[]).map(Se=>{const Fe=Co(Se.role);return`${Se.dynasty?`〔${be(Se.dynasty)}〕`:""}${be(Se.name)}${Fe?` ${be(Fe)}`:""}`}).join(" · ");let Me=!1;try{Me=Ee.extractStatus(Q.id)==="draft"}catch{}if(Q.type==="book"){const Se=Q;return{title:be(Se.title),subtitle:Se.edition?be(Se.edition):U||void 0,aside:[Me?F.status.draft:"",U&&Se.edition?U:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(Q.type==="collection"){const Se=Q;return{title:be(Se.title),subtitle:be(Yt(Se,F.unit.juan))||void 0,aside:[(_e=Se.publication_info)==null?void 0:_e.year,Me?F.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:U||void 0}}if(Q.type==="entity"){const Se=Q,Fe=et=>et==null?"":et<0?q("detail.bce",{n:-et}):String(et),Ye=((X=Se.dates)==null?void 0:X.birth)!=null||((ke=Se.dates)==null?void 0:ke.death)!=null?`${Fe(((he=Se.dates)==null?void 0:he.birth)??void 0)||"?"}—${Fe(((Ie=Se.dates)==null?void 0:Ie.death)??void 0)||"?"}`:"";return{title:be(Se.primary_name||Se.title),subtitle:[Se.dynasty?`〔${be(Se.dynasty)}〕`:"",Ye].filter(Boolean).join(" ")||void 0,aside:Me?F.status.draft:void 0,secondLine:void 0}}const He=be(Yt(Q,F.unit.juan));return{title:be(Q.title),subtitle:[He,U].filter(Boolean).join(" · ")||void 0,aside:[y1(F,Q.subtype),Me?F.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[Q,be,F,q]),Le=Q&&Pr(Q)?"text":null,Ve=()=>{nt(null),a("fulltext")};let Xe=null;if(Q&&v){const V=v({detail:Q,kind:Le});V&&(Xe=t.jsx(Kr,{href:V}))}else Le&&(Xe=t.jsx(Kr,{onClick:Ve}));const ot=V=>{if(!Q)return null;const U=V.replace(/\.[^.]+$/,"");if(v){const Me=v({detail:Q,kind:Le,juan:U});return Me?{href:Me}:null}return{onClick:()=>{nt(U),a("fulltext")}}},it=new Set($.map(V=>V.key)),R=pe.filter(V=>V.key.startsWith("catalog:")&&V.key!=="catalog:loading"||V.key==="lineage"&&!!We&&!H||it.has(V.key)).map(V=>({key:V.key,label:V.label,onClick:()=>a(V.key)})),ge=()=>{var V;return Q?Q.type==="work"?t.jsx(rp,{data:Q,transport:M,onNavigate:x,renderLink:_,readAction:Xe,railTop:C,railLinks:R}):Q.type==="book"?t.jsx(lp,{data:Q,transport:M,onNavigate:x,renderLink:_,readAction:Xe,fullText:Oe,fullTextPending:Pr(Q)&&!!M.getTextManifest&&oe!==Q.id,chapterLink:ot,railTop:C,railLinks:R}):Q.type==="collection"?t.jsx(cp,{data:Q,catalog:(V=G[0])==null?void 0:V.data,transport:M,onNavigate:x,renderLink:_,readAction:Xe,railTop:C,railLinks:R,catalogAction:G.length>0?t.jsxs("a",{href:"#catalog",onClick:U=>{U.preventDefault(),a(`catalog:${G[0].resource_id}`)},children:[be(F.detailTab.collectionCatalog)," →"]}):null}):t.jsx(pp,{data:Q,transport:M,onNavigate:x,renderLink:_,railTop:C,railLinks:R,assetBase:y}):null},ve=()=>{var U,Me,He;if(!Y||!Q)return null;if(s==="basic"||s==="emendated")return ge();if(typeof s=="string"&&s.startsWith("catalog:")){const _e=(U=G.find(X=>`catalog:${X.resource_id}`===s))==null?void 0:U.data;return t.jsx(Lo,{data:_e,onNavigate:x,renderLink:_})}if(s==="collated"||s==="fulltext")return t.jsx(cs,{id:e,transport:M,chapter:Ge,onLocationChange:_e=>nt(_e.chapter),onNavigate:x});if(s==="lineage"){if(!We)return t.jsx("div",{style:{color:r("label-fg"),padding:"24px 0"},children:q(H?"detail.loading":"detail.noLineageGraph")});const _e=Q.type==="work"?Q:null;return t.jsx(fs,{graph:We,renderLink:_,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:p,selectedNodeId:h,collection:m??((Me=_e==null?void 0:_e.version_graph)==null?void 0:Me.default_collection),onCollectionChange:g,collectionsAvailable:(He=_e==null?void 0:_e.version_graph)==null?void 0:He.collections,collectionCounts:(()=>{var Ie,Se,Fe,Ye,et,Ke,dt;if(!_e)return;const X={},ke=((Ie=de.current)==null?void 0:Ie.books)??[];X.all=(((Se=_e._books)==null?void 0:Se.length)??0)-(((Ye=(Fe=_e.version_graph)==null?void 0:Fe.excluded_books)==null?void 0:Ye.length)??0);const he=(et=_e.version_graph)==null?void 0:et.collections;if(he)for(const qe of Object.keys(he))X[qe]=Ci(_e,ke,qe).nodes.filter(K=>K.kind==="book"&&!K.bridge).length;return X.core==null&&((dt=(Ke=_e.version_graph)==null?void 0:Ke.core_books)!=null&&dt.length)&&(X.core=_e.version_graph.core_books.length),X})()})}if(s==="feedback"&&S)return t.jsx(ep,{resourceId:e,apiUrl:I});const V=$.find(_e=>_e.key===s);return V?V.render({detail:Q,entry:Y,transport:M,onNavigate:x}):null};if(we)return t.jsx(Un,{style:{minHeight:N,...A},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((V,U)=>t.jsx("div",{style:{height:U===1?40:16,width:V,opacity:.35,background:r("rule")}},U))})});if(ee||!Q||!Y||!Ne)return t.jsx(Un,{style:{minHeight:N,...A},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r("label-fg"),fontSize:14},children:q("detail.notFound")})});const $e=s==="basic"||s==="emendated",D=[{label:b??F.detailTab.backToIndex,onClick:j}];if(Q.type==="book"&&Q.work_id){const V=Q.work_id;D.push({label:F.indexType.work,id:V,onClick:()=>x==null?void 0:x(V)})}D.push({label:F.indexType[Q.type]});const B=s==="collated"||s==="fulltext",J=typeof z=="string"?F.status[z.trim()]??z:z,me=t.jsx(ed,{left:t.jsxs(t.Fragment,{children:[J,J?" · ":"",t.jsx(b1,{id:Q.id,label:F.label.id,copied:F.action.copied,copyLabel:F.action.copy})]}),right:t.jsxs(t.Fragment,{children:[S&&!$e&&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:F.detailTab.submitVersion}),re&&t.jsx("a",{href:re.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r("meta-fg")},children:F.detailTab.dataLicense})]})});return $e?t.jsx("div",{className:P,children:t.jsxs(Un,{grid:!0,style:{minHeight:N,...A},children:[t.jsx(Xr,{breadcrumb:t.jsx(Zr,{items:D}),actions:t.jsxs(t.Fragment,{children:[!E&&t.jsx(go,{style:{border:"none",background:"transparent"}}),!E&&re&&t.jsx(fo,{...re})]})}),ge(),me]})}):t.jsx("div",{className:P,children:t.jsxs(Un,{wide:B,style:{minHeight:N,...A},children:[t.jsx(Xr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Wo,{char:"籍"}),t.jsx(Zr,{items:D})]}),actions:t.jsxs(t.Fragment,{children:[!E&&t.jsx(go,{}),S&&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:F.detailTab.feedback}),!E&&re&&t.jsx(fo,{...re})]})}),t.jsx(Vc,{...Ne,aside:B?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:[q("detail.workInfo")," →"]}):Ne.aside}),!B&&pe.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:pe.map(V=>t.jsx(Gc,{label:V.label,active:V.key===s||$e&&V.key==="basic",onClick:()=>a(V.key)},V.key))}),t.jsx("div",{style:{marginTop:!B&&pe.length>1?8:0},children:ve()}),me]})})};function b1({id:e,label:n,copied:i,copyLabel:o}){const[s,a]=f.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[n," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var 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 y1(e,n){return n?e.workSubtype[n]??n:""}const nu=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],er="zhusha",tr="bim-theme";function iu(e){return e==="zhusha"||e==="indigo"||e==="ink"}function nr(e){return iu(e)?e:er}function j1(){try{return nr(window.localStorage.getItem(tr))}catch{return er}}function ru(e){try{window.localStorage.setItem(tr,e)}catch{}}function ou(e){const n=nr(e);return document.documentElement.setAttribute("data-theme",n),n}function su(){return nr(document.documentElement.getAttribute("data-theme"))}const v1=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],Ss="airy",ir="bim-layout";function au(e){return e==="airy"||e==="boxed"}function rr(e){return au(e)?e:Ss}function k1(){try{return rr(window.localStorage.getItem(ir))}catch{return Ss}}function w1(e){try{window.localStorage.setItem(ir,e)}catch{}}function S1(e){const n=rr(e);return document.documentElement.setAttribute("data-layout",n),n}function _1(){return rr(document.documentElement.getAttribute("data-layout"))}const $1=`try{var t=localStorage.getItem(${JSON.stringify(tr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(ir)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,C1={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},z1=({onChange:e,style:n})=>{const{t:i}=ie(),[o,s]=f.useState(er);f.useEffect(()=>{s(su())},[]);const a=l=>{s(ou(l)),ru(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":i("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...n},children:nu.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(C1[l.name]),boxShadow:d?`0 0 0 2px ${r("page-bg")}, 0 0 0 3.5px ${r("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=Ee.BidLink;exports.BookIndexError=Ee.BookIndexError;exports.BookIndexManager=Ee.BookIndexManager;exports.BookIndexStorage=Ee.BookIndexStorage;exports.BundleStorage=Ee.BundleStorage;exports.ConfigError=Ee.ConfigError;exports.GithubStorage=Ee.GithubStorage;exports.IdGenerationError=Ee.IdGenerationError;exports.IdGenerator=Ee.IdGenerator;exports.LocalStorage=Ee.LocalStorage;exports.MigrationError=Ee.MigrationError;exports.StorageError=Ee.StorageError;exports.VARIANT_CHARS=Ee.VARIANT_CHARS;exports.base36Decode=Ee.base36Decode;exports.base36Encode=Ee.base36Encode;exports.base58Decode=Ee.base58Decode;exports.buildId=Ee.buildId;exports.buildPromotionMap=Ee.buildPromotionMap;exports.cleanName=Ee.cleanName;exports.decodeId=Ee.decodeId;exports.decodeIdString=Ee.decodeIdString;exports.encodeId=Ee.encodeId;exports.extractIdFromUrl=Ee.extractIdFromUrl;exports.extractStatus=Ee.extractStatus;exports.extractType=Ee.extractType;exports.isChapterSegment=Ee.isChapterSegment;exports.isTextKey=Ee.isTextKey;exports.matchChapterAcrossVersions=Ee.matchChapterAcrossVersions;exports.normalizeCatalog=Ee.normalizeCatalog;exports.normalizeVariants=Ee.normalizeVariants;exports.parseId=Ee.parseId;exports.pickTextVersion=Ee.pickTextVersion;exports.shardOf=Ee.shardOf;exports.smartDecode=Ee.smartDecode;exports.textVersionLabel=Ee.textVersionLabel;exports.validateResource=Ee.validateResource;exports.VARIANT_SUPPLEMENT=El.VARIANT_SUPPLEMENT;exports.Badge=Ri;exports.BidUrlProvider=Au;exports.BookDetailLayout=x1;exports.BookPage=lp;exports.Breadcrumb=Zr;exports.CATALOG_ALL_ID=Ut;exports.CATALOG_CSS=up;exports.CATALOG_NARROW_QUERY=hs;exports.CATALOG_PAGE_SIZE=xs;exports.CATALOG_UNCLASSIFIED_ID=cn;exports.CLASSIFICATIONS=Ui;exports.COMMON_TRADITIONAL_CHARS=Hl;exports.CardFoot=ni;exports.CatalogPage=Z0;exports.CatalogPager=yp;exports.CatalogTree=gp;exports.CheckFilter=Hc;exports.Chip=Yc;exports.ChipWall=Of;exports.CollectionCatalog=Lo;exports.CollectionPage=cp;exports.CreateEntityDialog=Gd;exports.DEFAULT_LAYOUT=Ss;exports.DEFAULT_META_HOME_LINKS=Pp;exports.DEFAULT_READER_PREFS=Mo;exports.DEFAULT_READ_HOME_LINKS=vp;exports.DEFAULT_THEME=er;exports.DETAIL_CSS=Uc;exports.DYNASTY_GROUPS=Di;exports.Dash=Vf;exports.DataTable=Ff;exports.DetailFooter=ed;exports.DetailGrid=ei;exports.DetailHeader=Vc;exports.EMPTY_FILTERS=Hi;exports.ENTITY_TEXT_CSS=ns;exports.EmendatedBySection=yc;exports.EmptyNote=Jf;exports.EntityDetail=gc;exports.EntityMark=rs;exports.EntityPage=pp;exports.EntityPickerDialog=qd;exports.EntitySelector=Vd;exports.EntityText=jx;exports.ExpandRow=Gf;exports.ExtLink=Qf;exports.FEEDBACK_FAB_OFFSET_VAR=lo;exports.FILTER_SUPPORT=oc;exports.FONT_SIZE_STEPS=Dt;exports.FactList=Af;exports.FeedbackButton=Ry;exports.FeedbackDialog=Jd;exports.FeedbackForm=Qd;exports.FeedbackList=ds;exports.FeedbackTab=ep;exports.FilterChip=Gc;exports.FormInput=_t;exports.FormTextArea=pn;exports.GUJI_MARKDOWN_FIELD=jf;exports.GUJI_TABLE_NOTATION=td;exports.GlyphBadge=Wo;exports.GujiInteractiveReader=Sb;exports.GujiTable=Do;exports.GujiTextViewer=ss;exports.GujiWarpCanvas=ts;exports.HomePage=so;exports.ImagePanel=Vr;exports.IndexApp=wb;exports.IndexBrowser=Dr;exports.IndexDetail=Ro;exports.IndexEditor=Kd;exports.IndexView=yy;exports.IntroGrid=Lf;exports.LAYOUTS=v1;exports.LAYOUT_STORAGE_KEY=ir;exports.LOSS_OPTIONS=rc;exports.LocaleContext=Bt;exports.LocaleProvider=cm;exports.LocaleToggle=go;exports.META_HOME_CSS=Mp;exports.META_HOME_SECTION_IDS=eu;exports.MetaCatalogTable=Vp;exports.MetaCollectionGroups=Kp;exports.MetaDataLicense=Qp;exports.MetaHomeView=p1;exports.MetaLine=ft;exports.MetaLineageCards=Zp;exports.MetaOnlineSites=Jp;exports.MetaPeopleTimeline=Xp;exports.MetaRecentPanel=Dp;exports.MetaRelatedCatalogs=Yp;exports.MetaTypeChips=Wp;exports.ModeIndicator=Ul;exports.MoreButton=Bf;exports.MoreLink=Bo;exports.PAGE_MAX_WIDTH=Si;exports.PERIOD_NARROW_SHARE=_p;exports.PageFrame=Un;exports.Quote=qf;exports.READER_CSS=_c;exports.READ_HOME_CSS=ys;exports.READ_HOME_NARROW_QUERY=oi;exports.READ_HOME_SECTION_IDS=Ap;exports.READ_PERIOD_LABELS=t1;exports.RECENT_IDS_STORAGE_KEY=Sn;exports.ROLE_CLASS_ORDER=Jl;exports.ReadButton=Kr;exports.ReadFamousWorks=Ip;exports.ReadHomeView=i1;exports.ReadPeriodBand=Rp;exports.ReadPicks=zp;exports.ReadPieces=Lp;exports.ReadSection=vt;exports.ReadShelf=vs;exports.ReadSibu=ks;exports.ReadStats=Cp;exports.ReadTopicGroup=Tp;exports.ReadTopics=Ep;exports.ReaderMdText=Yo;exports.ReaderShell=Rc;exports.ReaderToc=$c;exports.RelationPanel=Dd;exports.RepoSourceLink=fo;exports.ResourceEditor=Or;exports.ResourceGroup=Kf;exports.ResourceLine=Xf;exports.ResourceList=ko;exports.ResourceRow=Jc;exports.SEARCH_VIEW_STORAGE_KEY=To;exports.SEVEN_PAVILIONS_KEY=qp;exports.SNIPPET_MARK_END=Ll;exports.SNIPPET_MARK_START=Rl;exports.SORTABLE_TYPES=ic;exports.SearchInput=Gl;exports.SearchResults=pc;exports.Sec=ht;exports.Section=It;exports.SectionHead=Mf;exports.SideList=dn;exports.SmartBidInput=$i;exports.SourceEditor=Wd;exports.StripWarpRenderer=Qr;exports.SummaryCard=ti;exports.THEMES=nu;exports.THEME_INIT_SCRIPT=$1;exports.THEME_STORAGE_KEY=tr;exports.TRADITIONAL_ALLOWLIST=Dl;exports.TabFilter=Gi;exports.TableHead=Hf;exports.TableRow=Df;exports.TagRow=Qc;exports.TagRows=Zf;exports.TextButton=Pf;exports.TextReader=cs;exports.ThemeToggle=z1;exports.TopStrip=Xr;exports.VersionLineageGraph=ap;exports.VersionLineageList=sp;exports.VersionLineageView=fs;exports.VolumeChips=Wf;exports.VolumeLinks=Fo;exports.WorkCard=xp;exports.WorkCardGrid=jp;exports.WorkCatalog=Bb;exports.WorkPage=rp;exports.WorkRow=bp;exports.adaptCharCord=Ab;exports.adaptEntityJson=md;exports.adaptFig=Pb;exports.adaptNorm=Od;exports.adaptNormDetailed=Bd;exports.adaptPunctJson=zb;exports.applyLayout=S1;exports.applyTheme=ou;exports.authorsLine=Qi;exports.bookIndexUriToId=Zn;exports.bookMarkingOf=Go;exports.bucketResources=_o;exports.buildCatalogTree=H0;exports.buildCollectionTable=tc;exports.buildLineageGraph=Ci;exports.buildMeiliFilter=qm;exports.buildPageUrl=jo;exports.buildParagraphBlocks=ld;exports.buildVersionRow=Xl;exports.buildVersionTable=Zl;exports.canParagraphize=Ei;exports.catalogNodeIdOf=W0;exports.catalogNodeIdsOf=F0;exports.catalogPageCount=G0;exports.catalogTotal=bs;exports.classificationPath=ri;exports.clearAllRecentIds=Eo;exports.compareCatalogCards=V0;exports.computeVersionPartition=Om;exports.countActiveFilters=Vi;exports.createTextApi=vc;exports.currentLayout=_1;exports.currentTheme=su;exports.defaultEntityHref=wd;exports.defaultWorkLink=fp;exports.deriveDating=Im;exports.deriveEditionType=nc;exports.deriveEra=Qn;exports.deriveYear=Oi;exports.deriveYearRange=So;exports.detailToEditor=Zd;exports.detectGenre=qi;exports.displayAuthorRole=Co;exports.editorToDetail=by;exports.eraRank=Fr;exports.filtersFromParams=Km;exports.filtersToParams=Ti;exports.findCatalogPath=vn;exports.findTraditionalChars=um;exports.firstAuthorText=js;exports.flattenTitles=Jr;exports.flattenToc=Ic;exports.fmtCount=ct;exports.formatHitCount=vi;exports.formatTemplate=$t;exports.formatVolumeRange=Fi;exports.getDisplayNameFromUrl=$n;exports.getMessages=zn;exports.getStartPage=yo;exports.getT=Nn;exports.getTypeGroupKey=xo;exports.groupRelatedWorks=Rm;exports.gujiInlineToPlain=Wc;exports.hasActiveFilters=sc;exports.hasGujiMarkdownV02=vf;exports.hasGujiTableNotation=eh;exports.hasSearchOptions=Vm;exports.headingKey=ls;exports.headingsFromPunct=Td;exports.iiifVolumeOf=Nb;exports.isCountedChar=qo;exports.isDuiduChapter=oo;exports.isLayoutName=au;exports.isThemeName=iu;exports.lineageHref=Bp;exports.loadRecentIds=Qt;exports.measureText=Yt;exports.mergeVolumeResources=bo;exports.nestHeadings=Id;exports.normalizeEra=gt;exports.normalizeLayout=rr;exports.normalizeRole=$o;exports.normalizeTheme=nr;exports.normalizeVolumeIndex=Gn;exports.normalizeVolumes=Pl;exports.numberToChinese=En;exports.paginationItems=mp;exports.parseChineseNumber=zi;exports.parseGujiInline=Oc;exports.parseGujiTable=id;exports.parseHeadingKey=Ed;exports.parseSourceString=Fd;exports.pct=ws;exports.periodLevel=Sp;exports.pickReaderVersion=Ec;exports.readStoredLayout=k1;exports.readStoredTheme=j1;exports.readerVersionOptionLabel=Yr;exports.remapPlainOffsets=gd;exports.removeRecentId=uc;exports.renderFullTextBody=dh;exports.renderProperNames=pd;exports.renderReaderInline=Ki;exports.resolveRecentEntry=Io;exports.resourceHref=Cn;exports.resourceNote=Wi;exports.resultTabFromParam=og;exports.resultTabToParam=sg;exports.roleFacets=Ql;exports.rowNo=Uf;exports.sameFilters=Xm;exports.sanitizeHeadings=ro;exports.saveRecentId=Hr;exports.segmentEntities=fd;exports.shelfColumns=kp;exports.sortFor=Gm;exports.sortYear=Ni;exports.spineHeight=wp;exports.splitFullTextTables=Ho;exports.splitHighlightSnippet=ho;exports.splitTableRow=nd;exports.storeLayout=w1;exports.storeTheme=ru;exports.stringifySources=Hd;exports.summaryFromEntry=jd;exports.summaryFromItem=yd;exports.timelineLayout=Op;exports.toCatalogWorkCard=U0;exports.transportSummaryLoader=vd;exports.typeSupportsFilters=ac;exports.useBidUrl=mt;exports.useChapterWarpData=Nd;exports.useConvert=De;exports.useEntitySummaryLoader=is;exports.useI18n=ie;exports.useReaderPrefs=Tc;exports.useRecentEntries=Fp;exports.useT=Pe;exports.validateLineageGraph=r0;exports.volumeStats=Ai;exports.withDefaultLinks=en;exports.withMetaLinks=tn;exports.yearText=Li;