book-index-ui 0.66.10 → 0.66.12

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
@@ -635,15 +635,17 @@ button.bim-rd-pg:hover { border-color: ${s.bim("accent")}; }
635
635
  }
636
636
  .guji-text-reflow-view {
637
637
  width: 100%;
638
- max-width: 760px;
638
+ /* 随字号走:与外层 .bim-rd-col 同为 50em,不再卡死窄宽度(宽屏时两侧留白过大);--bimrd-fs 未设时 18px(同 DEFAULT_FONT_SIZE;原先写死 20px,字号设置对它无效) */
639
+ max-width: 50em;
639
640
  margin: 0 auto;
641
+ font-size: var(--bimrd-fs, 18px);
640
642
  user-select: text;
641
643
  }
642
644
  .guji-reflow-paragraph {
643
- margin: 0 0 1.4rem 0;
644
- text-indent: 2.7rem;
645
+ margin: 0 0 1.1em 0;
646
+ text-indent: 2.16em;
645
647
  font-family: var(--bimrd-ff, var(--bim-font-serif, "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", serif));
646
- font-size: 1.25rem;
648
+ font-size: 1em; /* 继承 .guji-text-reflow-view 的 --bimrd-fs,字号设置才生效 */
647
649
  letter-spacing: 0.02em;
648
650
  color: ${s.bim("ink")};
649
651
  text-align: justify;
@@ -655,13 +657,13 @@ button.bim-rd-pg:hover { border-color: ${s.bim("accent")}; }
655
657
  font-family: var(--bimrd-ff, var(--bim-font-serif, "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", serif));
656
658
  color: ${s.bim("ink")};
657
659
  font-weight: 700;
658
- margin: 2rem 0 1rem;
660
+ margin: 1.6em 0 0.8em;
659
661
  scroll-margin-top: 96px;
660
662
  }
661
- .guji-reflow-heading.guji-reflow-h1 { font-size: 1.6rem; letter-spacing: 0.08em; }
662
- .guji-reflow-heading.guji-reflow-h2 { font-size: 1.4rem; letter-spacing: 0.05em; }
663
- .guji-reflow-heading.guji-reflow-h3 { font-size: 1.25rem; letter-spacing: 0.02em; margin: 1.6rem 0 0.8rem; }
664
- .guji-reflow-heading.guji-reflow-h4, .guji-reflow-heading.guji-reflow-h5, .guji-reflow-heading.guji-reflow-h6 { font-size: 1.25rem; letter-spacing: 0.02em; font-weight: 600; margin: 1.4rem 0 0.7rem; }
663
+ .guji-reflow-heading.guji-reflow-h1 { font-size: 1.28em; letter-spacing: 0.08em; }
664
+ .guji-reflow-heading.guji-reflow-h2 { font-size: 1.12em; letter-spacing: 0.05em; }
665
+ .guji-reflow-heading.guji-reflow-h3 { font-size: 1em; letter-spacing: 0.02em; margin: 1.3em 0 0.65em; }
666
+ .guji-reflow-heading.guji-reflow-h4, .guji-reflow-heading.guji-reflow-h5, .guji-reflow-heading.guji-reflow-h6 { font-size: 1em; letter-spacing: 0.02em; font-weight: 600; margin: 1.1em 0 0.55em; }
665
667
  .guji-text-scroll-v {
666
668
  writing-mode: vertical-rl;
667
669
  text-orientation: upright;
@@ -675,7 +677,7 @@ button.bim-rd-pg:hover { border-color: ${s.bim("accent")}; }
675
677
  display: inline-block;
676
678
  vertical-align: top;
677
679
  font-family: var(--bimrd-ff, var(--bim-font-serif, "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", serif));
678
- font-size: 1.35rem;
680
+ font-size: calc(var(--bimrd-fs, 18px) * 1.08);
679
681
  letter-spacing: 0;
680
682
  margin-left: 18px;
681
683
  user-select: text;
@@ -1545,7 +1547,7 @@ a.bim-et:focus-visible { outline: 2px solid ${s.bim("accent")}; outline-offset:
1545
1547
  ${r.versionKey??""}
1546
1548
  ${n??""}`,[l,d]=b.useState({tag:"",data:null}),c=b.useRef(0);if(b.useEffect(()=>{if(i!==void 0)return;const p=++c.current,h=u=>{p===c.current&&d({tag:a,data:u})};if(!n)return h(null);if(e){let u;try{u=e(n,r)}catch{return h(null)}if(!u||typeof u.then!="function")return h(u??null);u.then(f=>h(f??null),()=>h(null));return}h(null)},[e,i,n,r,a]),i!==void 0)return{warpData:i,loading:!1};const m=l.tag===a;return{warpData:m?l.data:null,loading:!!e&&!!n&&!m}}function pg(e,i,n,r=""){const o=`${r}
1547
1549
  ${n.versionKey??""}
1548
- ${i??""}`,[a,l]=b.useState({tag:"",spans:[]}),d=b.useRef(0);return b.useEffect(()=>{const c=++d.current,m=h=>{c===d.current&&l({tag:o,spans:h})};if(!e||!i){m([]);return}let p;try{p=e(i,n)}catch{m([]);return}Promise.resolve(p).then(h=>m(h?Gc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:bg}const bg=[],hg=/^#{1,6}$/,fg=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function gg(e){let i=e.trim();const n=fg.exec(i);return n&&(i=n[1]+n[2]),i.replace(/[《》〈〉]/g,"").trim()}const Ka=e=>e.kind==null||e.kind==="point";function md(e,i){var d;if(!e||!i||i.length===0)return[];const n=new Map;let r=!1;for(const c of i){c.kind==="heading"&&(r=!0);const m=n.get(c.anchor);m?m.push(c):n.set(c.anchor,[c])}if(!r)return[];const o=[];let a=null;const l=()=>{a&&(a.fixed||(a.h.label=gg(a.text)),a.h.label&&o.push(a.h)),a=null};for(const c of e){const m=[...c.columns].sort((p,h)=>p.col-h.col);for(const p of m)for(const h of p.chars){const u=n.get(h.id)??[],f=u.find(g=>g.kind==="heading"&&g.pos==="before"&&hg.test(g.mark));if(f&&l(),f&&f.toc!==!1){const g=(d=f.label)==null?void 0:d.trim();a={h:{level:f.mark.length,label:g??"",anchor:h.id},text:"",fixed:!!g}}if(a&&!a.fixed){for(const g of u)Ka(g)&&g.pos==="before"&&(a.text+=g.mark);a.text+=h.char;for(const g of u)Ka(g)&&g.pos!=="before"&&(a.text+=g.mark)}u.some(g=>g.kind==="break"&&g.pos!=="before")&&l()}}return l(),o}function cs(e){if(!Array.isArray(e))return[];const i=[];for(const n of e){if(!n||typeof n!="object")continue;const{level:r,label:o,anchor:a}=n;typeof r!="number"||!Number.isInteger(r)||r<1||r>6||typeof o!="string"||!o.trim()||typeof a!="string"||!a||i.push({level:r,label:o.trim(),anchor:a})}return i}function no(e,i){return`${e}#${i}`}function ud(e){const i=e.indexOf("#");return i<=0||i===e.length-1?null:{chapter:e.slice(0,i),anchor:e.slice(i+1)}}function pd(e){const i=[],n=[];for(const r of e){const o={...r,children:[]};for(;n.length>0&&n[n.length-1].level>=r.level;)n.pop();n.length===0?i.push(o):n[n.length-1].children.push(o),n.push(o)}return i}function Rn(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const xg=150,Ya="(min-width: 860px)";function yg(){const[e,i]=b.useState(()=>typeof window>"u"||!window.matchMedia?!0:window.matchMedia(Ya).matches);return b.useEffect(()=>{var o;if(!window.matchMedia)return;const n=window.matchMedia(Ya),r=()=>i(n.matches);return r(),(o=n.addEventListener)==null||o.call(n,"change",r),()=>{var a;return(a=n.removeEventListener)==null?void 0:a.call(n,"change",r)}},[]),e}const Ga={padding:24,color:s.bim("desc-fg"),fontSize:14};function Va({title:e,label:i,className:n,style:r}){const o=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:s.bim("rule")});return t.jsxs("div",{className:n,style:{...r,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:s.bim("ink"),fontFamily:s.bim("font-ui")},children:e}),t.jsx("div",{style:o("42%",24,28)}),t.jsx("div",{style:o("30%",12,10)}),["96%","100%","92%","98%","64%"].map((a,l)=>t.jsx("div",{style:o(a,16,l===0?30:14)},l)),t.jsx("p",{role:"status",style:{marginTop:24,color:s.bim("desc-fg"),fontSize:14,fontFamily:s.bim("font-ui")},children:i})]})}const qa=/^https?:\/\//i,jg=[];function kg(e){if(!e||typeof e!="object")return null;const i=a=>typeof a=="string"&&a.trim()?a.trim():void 0,n=i(e.url),r=i(e.license_url),o={name:i(e.name),url:n&&qa.test(n)?n:void 0,license:i(e.license),license_url:r&&qa.test(r)?r:void 0,note:i(e.note)};return o.name||o.license||o.note?o:null}function wg(e,i){return{work_id:i.work_id??e,title:i.title,type:i.type,juan_files:i.chapters.map(n=>n.file),juan_metadata:i.juan_metadata,juan_groups:i.juan_groups,references:i.references,target_source:i.target_source,target_source_id:i.target_source_id,text_source:i.text_source,text_quality:i.text_quality}}function Xa(e,i){return(i==null?void 0:i.type)==="kaozhen"?"章":i!=null&&i.juan_metadata&&Object.values(i.juan_metadata).some(n=>n.vol_label)||Array.isArray(i==null?void 0:i.heading_levels)&&i.heading_levels.length>0?"冊":_e.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function bd(e,i,n,r=!1){const o=n(`${i}${e.n}`);if(!e.title)return o;const a=n(e.title);return r&&!/^[卷冊册章篇回第]/.test(e.title)?`${o} ${a}`:a}function hd(e,i,n){return i.map(r=>({key:no(e,r.anchor),label:n(r.label),inChapter:!0,...r.children.length>0?{selectable:!0,children:hd(e,r.children,n)}:{}}))}function vg(e,i,n,r,o,a=()=>[]){var p;const l=new Map(e.chapters.map(h=>[h.file,h])),d=h=>h==="loading"?"…":typeof h=="number"&&h>0?h:void 0,c=(h,u)=>{const f=l.get(h),g=f?a(f):[];return{key:h,label:u??(f?bd(f,n,r,o):h),hint:d(i[h]),disabled:i[h]===0,...g.length>0?{selectable:!0,children:hd(h,pd(g),r)}:{}}},m=(p=e.juan_groups)==null?void 0:p.filter(h=>{var u;return h.files.some(f=>l.has(f))||((u=h.children)==null?void 0:u.length)});if(m&&m.length>0){const h=(u,f)=>{var y;if(u.files.length===1&&!((y=u.children)!=null&&y.length))return c(u.files[0],r(u.label));const g=Xh(u,i);return{key:`group:${f}`,label:r(u.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:Zc(u),defaultExpanded:typeof g=="number"&&g>0,children:[...u.files.filter(v=>l.has(v)).map(v=>c(v)),...(u.children??[]).map((v,w)=>h(v,`${f}.${w}`))]}};return m.map((u,f)=>h(u,`${f}`))}return e.chapters.map(h=>c(h.file))}const fd=e=>{const i=cc(),n=e.initialChapter,[r,o]=b.useState(!1),[a,l]=b.useState(!1);b.useEffect(()=>{if(!n)return;const c=window.setTimeout(()=>l(!0),1e4);return()=>window.clearTimeout(c)},[n]);const d=b.useCallback(()=>o(!0),[]);return t.jsxs(t.Fragment,{children:[t.jsx(fu,{mode:i[0].scriptMode,children:t.jsx($g,{...e,prefsState:i,onBodyReady:n?d:void 0})}),n&&!r&&!a&&t.jsx(Sg,{data:n})]})};function Sg({data:e}){const{t:i}=oe();return t.jsxs("section",{"data-reader-lead":!0,style:{maxWidth:768,margin:"0 auto",padding:"24px 16px",lineHeight:2},children:[e.paragraphs.map((n,r)=>t.jsx("p",{style:{marginBottom:16},children:n},r)),e.truncated&&e.selfHref&&t.jsx("p",{children:t.jsx("a",{href:e.selfHref,children:i("reader.continueReading")})}),t.jsxs("nav",{style:{marginTop:16,display:"flex",flexWrap:"wrap",gap:16,fontSize:14},children:[e.prev&&t.jsx("a",{href:e.prev.href,rel:"prev",children:e.prev.label}),e.next&&t.jsx("a",{href:e.next.href,rel:"next",children:e.next.label}),e.itemHref&&t.jsx("a",{href:e.itemHref,children:e.itemLabel})]})]})}const $g=({prefsState:e,onBodyReady:i,id:n,transport:r,versionKey:o,chapter:a,onLocationChange:l,onNavigate:d,anchor:c,title:m,subtitle:p,resolveImages:h,resolveFacsimile:u,renderImageOverlay:f,imagePanel:g,allowVertical:y,onReportError:v,revisedAt:w,backHref:x,backLabel:j,resolveWarpData:S,textFileBase:$,onChapterData:N,hideSupersededVersions:z=!0,warpData:C,resolveEntities:U,onEntityNavigate:R,plugins:L,className:F,style:T})=>{var Ao,Lo,Po,Oo;const{t:Z,convert:O}=oe(),ae=b.useMemo(()=>ic(r),[r]),[ce,Ee]=e,we=It(),ye=b.useRef(l);ye.current=l;const[Q,Ne]=b.useState(null),[W,je]=b.useState("loading");b.useEffect(()=>{let E=!1;return Ne(null),je("loading"),ae.getManifest(n).then(G=>{E||(G?(Ne(z?_e.readerVersions(G):G),je("ready")):je("missing"))}).catch(()=>{E||je("missing")}),()=>{E=!0}},[ae,n,z]);const K=o!==void 0,V=a!==void 0,[re,X]=b.useState(null),[I,ue]=b.useState(null);b.useEffect(()=>{X(null),ue(null)},[n]);const fe=_e.pickTextVersion(Q,K?o:re),ze=((Ao=Q==null?void 0:Q.versions.find(E=>E.key==="default"))==null?void 0:Ao.key)??((Lo=Q==null?void 0:Q.versions[0])==null?void 0:Lo.key)??"default",B=(fe==null?void 0:fe.key)??null,pe=V?a:I,Te=b.useCallback((E,G,be,ot)=>{var mt;(mt=ye.current)==null||mt.call(ye,{key:E,chapter:G,isDefault:E===ze,...ot?{anchor:ot}:{}},be)},[ze]);b.useEffect(()=>{!Q||!K||o==null||Q.versions.some(E=>E.key===o)||Te(ze,null,"auto")},[Q,K,o,ze,Te]);const ve=b.useRef(new Map);b.useEffect(()=>{ve.current.clear()},[ae,n]);const Ve=b.useCallback(async E=>{const G=`${n}
1550
+ ${i??""}`,[a,l]=b.useState({tag:"",spans:[]}),d=b.useRef(0);return b.useEffect(()=>{const c=++d.current,m=h=>{c===d.current&&l({tag:o,spans:h})};if(!e||!i){m([]);return}let p;try{p=e(i,n)}catch{m([]);return}Promise.resolve(p).then(h=>m(h?Gc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:bg}const bg=[],hg=/^#{1,6}$/,fg=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function gg(e){let i=e.trim();const n=fg.exec(i);return n&&(i=n[1]+n[2]),i.replace(/[《》〈〉]/g,"").trim()}const Ka=e=>e.kind==null||e.kind==="point";function md(e,i){var d;if(!e||!i||i.length===0)return[];const n=new Map;let r=!1;for(const c of i){c.kind==="heading"&&(r=!0);const m=n.get(c.anchor);m?m.push(c):n.set(c.anchor,[c])}if(!r)return[];const o=[];let a=null;const l=()=>{a&&(a.fixed||(a.h.label=gg(a.text)),a.h.label&&o.push(a.h)),a=null};for(const c of e){const m=[...c.columns].sort((p,h)=>p.col-h.col);for(const p of m)for(const h of p.chars){const u=n.get(h.id)??[],f=u.find(g=>g.kind==="heading"&&g.pos==="before"&&hg.test(g.mark));if(f&&l(),f&&f.toc!==!1){const g=(d=f.label)==null?void 0:d.trim();a={h:{level:f.mark.length,label:g??"",anchor:h.id},text:"",fixed:!!g}}if(a&&!a.fixed){for(const g of u)Ka(g)&&g.pos==="before"&&(a.text+=g.mark);a.text+=h.char;for(const g of u)Ka(g)&&g.pos!=="before"&&(a.text+=g.mark)}u.some(g=>g.kind==="break"&&g.pos!=="before")&&l()}}return l(),o}function cs(e){if(!Array.isArray(e))return[];const i=[];for(const n of e){if(!n||typeof n!="object")continue;const{level:r,label:o,anchor:a}=n;typeof r!="number"||!Number.isInteger(r)||r<1||r>6||typeof o!="string"||!o.trim()||typeof a!="string"||!a||i.push({level:r,label:o.trim(),anchor:a})}return i}function no(e,i){return`${e}#${i}`}function ud(e){const i=e.indexOf("#");return i<=0||i===e.length-1?null:{chapter:e.slice(0,i),anchor:e.slice(i+1)}}function pd(e){const i=[],n=[];for(const r of e){const o={...r,children:[]};for(;n.length>0&&n[n.length-1].level>=r.level;)n.pop();n.length===0?i.push(o):n[n.length-1].children.push(o),n.push(o)}return i}const xg=[1,2,3,-1];function Rn(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const yg=150,Ya="(min-width: 860px)";function jg(){const[e,i]=b.useState(()=>typeof window>"u"||!window.matchMedia?!0:window.matchMedia(Ya).matches);return b.useEffect(()=>{var o;if(!window.matchMedia)return;const n=window.matchMedia(Ya),r=()=>i(n.matches);return r(),(o=n.addEventListener)==null||o.call(n,"change",r),()=>{var a;return(a=n.removeEventListener)==null?void 0:a.call(n,"change",r)}},[]),e}const Ga={padding:24,color:s.bim("desc-fg"),fontSize:14};function Va({title:e,label:i,className:n,style:r}){const o=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:s.bim("rule")});return t.jsxs("div",{className:n,style:{...r,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:s.bim("ink"),fontFamily:s.bim("font-ui")},children:e}),t.jsx("div",{style:o("42%",24,28)}),t.jsx("div",{style:o("30%",12,10)}),["96%","100%","92%","98%","64%"].map((a,l)=>t.jsx("div",{style:o(a,16,l===0?30:14)},l)),t.jsx("p",{role:"status",style:{marginTop:24,color:s.bim("desc-fg"),fontSize:14,fontFamily:s.bim("font-ui")},children:i})]})}const qa=/^https?:\/\//i,kg=[];function wg(e){if(!e||typeof e!="object")return null;const i=a=>typeof a=="string"&&a.trim()?a.trim():void 0,n=i(e.url),r=i(e.license_url),o={name:i(e.name),url:n&&qa.test(n)?n:void 0,license:i(e.license),license_url:r&&qa.test(r)?r:void 0,note:i(e.note)};return o.name||o.license||o.note?o:null}function vg(e,i){return{work_id:i.work_id??e,title:i.title,type:i.type,juan_files:i.chapters.map(n=>n.file),juan_metadata:i.juan_metadata,juan_groups:i.juan_groups,references:i.references,target_source:i.target_source,target_source_id:i.target_source_id,text_source:i.text_source,text_quality:i.text_quality}}function Xa(e,i){return(i==null?void 0:i.type)==="kaozhen"?"章":i!=null&&i.juan_metadata&&Object.values(i.juan_metadata).some(n=>n.vol_label)||Array.isArray(i==null?void 0:i.heading_levels)&&i.heading_levels.length>0?"冊":_e.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function bd(e,i,n,r=!1){const o=n(`${i}${e.n}`);if(!e.title)return o;const a=n(e.title);return r&&!/^[卷冊册章篇回第]/.test(e.title)?`${o} ${a}`:a}function hd(e,i,n){return i.map(r=>({key:no(e,r.anchor),label:n(r.label),inChapter:!0,...r.children.length>0?{selectable:!0,children:hd(e,r.children,n)}:{}}))}function Sg(e,i,n,r,o,a=()=>[]){var p;const l=new Map(e.chapters.map(h=>[h.file,h])),d=h=>h==="loading"?"…":typeof h=="number"&&h>0?h:void 0,c=(h,u)=>{const f=l.get(h),g=f?a(f):[];return{key:h,label:u??(f?bd(f,n,r,o):h),hint:d(i[h]),disabled:i[h]===0,...g.length>0?{selectable:!0,children:hd(h,pd(g),r)}:{}}},m=(p=e.juan_groups)==null?void 0:p.filter(h=>{var u;return h.files.some(f=>l.has(f))||((u=h.children)==null?void 0:u.length)});if(m&&m.length>0){const h=(u,f)=>{var y;if(u.files.length===1&&!((y=u.children)!=null&&y.length))return c(u.files[0],r(u.label));const g=Xh(u,i);return{key:`group:${f}`,label:r(u.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:Zc(u),defaultExpanded:typeof g=="number"&&g>0,children:[...u.files.filter(v=>l.has(v)).map(v=>c(v)),...(u.children??[]).map((v,w)=>h(v,`${f}.${w}`))]}};return m.map((u,f)=>h(u,`${f}`))}return e.chapters.map(h=>c(h.file))}const fd=e=>{const i=cc(),n=e.initialChapter,[r,o]=b.useState(!1),[a,l]=b.useState(!1);b.useEffect(()=>{if(!n)return;const c=window.setTimeout(()=>l(!0),1e4);return()=>window.clearTimeout(c)},[n]);const d=b.useCallback(()=>o(!0),[]);return t.jsxs(t.Fragment,{children:[t.jsx(fu,{mode:i[0].scriptMode,children:t.jsx(_g,{...e,prefsState:i,onBodyReady:n?d:void 0})}),n&&!r&&!a&&t.jsx($g,{data:n})]})};function $g({data:e}){const{t:i}=oe();return t.jsxs("section",{"data-reader-lead":!0,style:{maxWidth:768,margin:"0 auto",padding:"24px 16px",lineHeight:2},children:[e.paragraphs.map((n,r)=>t.jsx("p",{style:{marginBottom:16},children:n},r)),e.truncated&&e.selfHref&&t.jsx("p",{children:t.jsx("a",{href:e.selfHref,children:i("reader.continueReading")})}),t.jsxs("nav",{style:{marginTop:16,display:"flex",flexWrap:"wrap",gap:16,fontSize:14},children:[e.prev&&t.jsx("a",{href:e.prev.href,rel:"prev",children:e.prev.label}),e.next&&t.jsx("a",{href:e.next.href,rel:"next",children:e.next.label}),e.itemHref&&t.jsx("a",{href:e.itemHref,children:e.itemLabel})]})]})}const _g=({prefsState:e,onBodyReady:i,id:n,transport:r,versionKey:o,chapter:a,onLocationChange:l,onNavigate:d,anchor:c,title:m,subtitle:p,resolveImages:h,resolveFacsimile:u,renderImageOverlay:f,imagePanel:g,allowVertical:y,onReportError:v,revisedAt:w,backHref:x,backLabel:j,resolveWarpData:S,textFileBase:$,onChapterData:N,hideSupersededVersions:z=!0,warpData:C,resolveEntities:U,onEntityNavigate:R,plugins:L,className:F,style:T})=>{var Ao,Lo,Po,Oo;const{t:Z,convert:O}=oe(),ae=b.useMemo(()=>ic(r),[r]),[ce,Ee]=e,we=It(),ye=b.useRef(l);ye.current=l;const[Q,Ne]=b.useState(null),[W,je]=b.useState("loading");b.useEffect(()=>{let E=!1;return Ne(null),je("loading"),ae.getManifest(n).then(G=>{E||(G?(Ne(z?_e.readerVersions(G):G),je("ready")):je("missing"))}).catch(()=>{E||je("missing")}),()=>{E=!0}},[ae,n,z]);const K=o!==void 0,V=a!==void 0,[re,X]=b.useState(null),[I,ue]=b.useState(null);b.useEffect(()=>{X(null),ue(null)},[n]);const fe=_e.pickTextVersion(Q,K?o:re),ze=((Ao=Q==null?void 0:Q.versions.find(E=>E.key==="default"))==null?void 0:Ao.key)??((Lo=Q==null?void 0:Q.versions[0])==null?void 0:Lo.key)??"default",B=(fe==null?void 0:fe.key)??null,pe=V?a:I,Te=b.useCallback((E,G,be,ot)=>{var mt;(mt=ye.current)==null||mt.call(ye,{key:E,chapter:G,isDefault:E===ze,...ot?{anchor:ot}:{}},be)},[ze]);b.useEffect(()=>{!Q||!K||o==null||Q.versions.some(E=>E.key===o)||Te(ze,null,"auto")},[Q,K,o,ze,Te]);const ve=b.useRef(new Map);b.useEffect(()=>{ve.current.clear()},[ae,n]);const Ve=b.useCallback(async E=>{const G=`${n}
1549
1551
  ${E}`;if(ve.current.has(G))return ve.current.get(G)??null;const be=await ae.getIndex(n,E).catch(()=>null);return be&&ve.current.set(G,be),be},[ae,n]),[qe,Xe]=b.useState(null),[J,ie]=b.useState("loading"),me=B?`${n}
1550
1552
  ${B}`:null,se=qe&&qe.owner===me?qe.idx:null;b.useEffect(()=>{if(!B)return;let E=!1;const G=`${n}
1551
1553
  ${B}`;return Xe(null),ie("loading"),Ve(B).then(be=>{E||(be&&be.chapters.length>0?(Xe({owner:G,idx:be}),ie("ready")):ie("failed"))}),()=>{E=!0}},[n,B,Ve]),b.useEffect(()=>{if(!se||!B||pe!=null&&se.chapters.some(be=>be.file===pe))return;const G=se.chapters[0].file;V||ue(G),Te(B,G,"auto")},[se,B,pe,V,Te]);const de=se?pe!=null&&se.chapters.some(E=>E.file===pe)?pe:se.chapters[0].file:pe,ge=b.useMemo(()=>se&&de?se.chapters.find(E=>E.file===de)??null:null,[se,de]),Oe=b.useRef(0),Je=b.useCallback(async E=>{if(!Q||E===B||!Q.versions.some(_t=>_t.key===E))return;const G=++Oe.current,be=await Ve(E);if(G!==Oe.current)return;const ot=ge??(de?{file:de}:null),mt=_e.matchChapterAcrossVersions(ot,be);K||X(E),V||ue(mt),Te(E,mt,"version")},[Q,B,Ve,ge,de,K,V,Te]),[Pe,Ue]=b.useState(null),[nt,Y]=b.useState(null),M=b.useRef(0),k=b.useCallback((E,G)=>{Ue({chapter:E,anchor:G,nonce:++M.current}),Y({chapter:E,anchor:G})},[]),P=b.useCallback(E=>{if(!B)return;const G=ud(E);if(G){k(G.chapter,G.anchor),V||ue(G.chapter),Te(B,G.chapter,"chapter",G.anchor);return}V||ue(E),Te(B,E,"chapter")},[B,V,Te,k]),q=b.useRef(null);b.useEffect(()=>{!c||!de||c===q.current||(q.current=c,k(de,c))},[c,de,k]),b.useEffect(()=>{c||(q.current=null)},[c]);const[_,le]=b.useState(null),H=B&&ge?`${n}
@@ -1553,9 +1555,9 @@ ${B}
1553
1555
  ${ge.file}`:null,[he,xe]=b.useState(null),Re=H!==null&&he!==H,Ze=b.useRef(0);b.useEffect(()=>{if(!B||!ge)return;const E=++Ze.current,G=`${n}
1554
1556
  ${B}
1555
1557
  ${ge.file}`;if(le(null),Rn(ge)){xe(G);return}ae.getChapter(n,B,ge.file,{json:!!ge.has_json}).then(be=>{E===Ze.current&&le(be)}).catch(()=>{E===Ze.current&&le(null)}).finally(()=>{E===Ze.current&&xe(G)})},[ae,n,B,ge]);const Me=_e.isCollatedKind(fe==null?void 0:fe.kind),[He,ct]=b.useState("");b.useEffect(()=>{ct("")},[n,B]);const Be=b.useMemo(()=>B&&Me?async E=>{const G=await ae.getChapter(n,B,E,{json:!0});return{juan:(G==null?void 0:G.json)??null,rawText:(G==null?void 0:G.md)??null}}:null,[ae,n,B,Me]),ee=(se==null?void 0:se.type)==="kaozhen",Se=b.useMemo(()=>(se==null?void 0:se.chapters.map(E=>E.file))??[],[se]),{matchStates:et}=df({resetKey:`${n}
1556
- ${B??""}`,load:Be,files:Se,activeFile:de??null,activeJuan:(_==null?void 0:_.json)??null,activeRawText:(_==null?void 0:_.md)??null,query:He,isKaozhen:ee}),tt=b.useRef(new Map);b.useEffect(()=>{tt.current.clear()},[n]);const De=b.useMemo(()=>({versionKey:B,chapter:ge??null}),[B,ge]),Fe=yg(),pt=typeof r.getTextFile=="function"||!!$,bt=b.useRef(N);bt.current=N;const ht=b.useMemo(()=>S||C!==void 0||!pt?void 0:async(E,G)=>{var ot;const be=await _e.loadReaderChapter(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$});return G!=null&&G.chapter&&((ot=bt.current)==null||ot.call(bt,{chapterKey:E,ctx:G,data:be})),(be==null?void 0:be.warpData)??null},[S,C,pt,r,n,Fe,$]),We=b.useMemo(()=>U||!pt?void 0:async(E,G)=>{var be;return((be=await _e.loadReaderFiles(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$}))==null?void 0:be.entity)??null},[U,pt,r,n,Fe,$]),gt=b.useMemo(()=>h||!u||!pt?void 0:async(E,G)=>{const be=await _e.loadReaderFiles(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$}),ot=be!=null&&be.cord?_e.iiifVolumeOf(be.cord):be!=null&&be.cordSkipped?_e.volumeFromChar(be.char):null;return ot?u(ot.bookId,ot.vol):null},[h,u,pt,r,n,Fe,$]),te=yh(h??gt,de??null,De,n),{warpData:A,loading:ne}=dd(S??ht,C,de??null,De,n),$e=!Re&&H!==null&&(!!A||!!(_!=null&&_.md)||!!(_!=null&&_.json));b.useEffect(()=>{$e&&(i==null||i())},[$e,i]);const Ie=b.useRef(!1);(A||te.images&&te.images.length>0)&&(Ie.current=!0),b.useEffect(()=>{Ie.current=!1},[n]);const Le=te.loading||Rn(ge)&&ne&&!A,at=Ie.current&&Le,lt=at,Ge=pg(U??We,de??null,De,n),Ae=ce.properNameMode??(Ge.length>0?"full":"off"),Ce=b.useMemo(()=>({...ce,properNameMode:Ae}),[ce,Ae]),rt=b.useMemo(()=>xh(Ge,Ae,{showWorks:Ce.showWorks}),[Ge,Ae,Ce.showWorks]),[st,Ke]=b.useState(new Set),[D,ke]=b.useState(null),[Qe]=b.useState(jh),[Ye,wt]=b.useState(!0),it=((Po=fe==null?void 0:fe.facsimile)==null?void 0:Po.trimmed)??!1,Pt=it?!0:ce.preserveMargins;b.useCallback(E=>Ee({preserveMargins:E}),[Ee]);const dt=b.useRef(null),[$t,Ot]=b.useState(1),[zt,cr]=b.useState(null),an=E=>{var be;const G=parseInt(((be=E==null?void 0:E.page_id)==null?void 0:be.split(":")[1])??"",10);return isNaN(G)?null:G},ri=E=>{var be,ot;const G=(E==null?void 0:E.pages)??[];return((be=G.find(mt=>mt.columns.some(_t=>_t.chars.length>0)))==null?void 0:be.page)??an(E)??((ot=G[0])==null?void 0:ot.page)??1},[yt,bi]=b.useState(()=>ri(A)),Ci=`${n}
1558
+ ${B??""}`,load:Be,files:Se,activeFile:de??null,activeJuan:(_==null?void 0:_.json)??null,activeRawText:(_==null?void 0:_.md)??null,query:He,isKaozhen:ee}),tt=b.useRef(new Map);b.useEffect(()=>{tt.current.clear()},[n]);const De=b.useMemo(()=>({versionKey:B,chapter:ge??null}),[B,ge]),Fe=jg(),pt=typeof r.getTextFile=="function"||!!$,bt=b.useRef(N);bt.current=N;const ht=b.useMemo(()=>S||C!==void 0||!pt?void 0:async(E,G)=>{var ot;const be=await _e.loadReaderChapter(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$});return G!=null&&G.chapter&&((ot=bt.current)==null||ot.call(bt,{chapterKey:E,ctx:G,data:be})),(be==null?void 0:be.warpData)??null},[S,C,pt,r,n,Fe,$]),We=b.useMemo(()=>U||!pt?void 0:async(E,G)=>{var be;return((be=await _e.loadReaderFiles(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$}))==null?void 0:be.entity)??null},[U,pt,r,n,Fe,$]),gt=b.useMemo(()=>h||!u||!pt?void 0:async(E,G)=>{const be=await _e.loadReaderFiles(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$}),ot=be!=null&&be.cord?_e.iiifVolumeOf(be.cord):be!=null&&be.cordSkipped?_e.volumeFromChar(be.char):null;return ot?u(ot.bookId,ot.vol):null},[h,u,pt,r,n,Fe,$]),te=yh(h??gt,de??null,De,n),{warpData:A,loading:ne}=dd(S??ht,C,de??null,De,n),$e=!Re&&H!==null&&(!!A||!!(_!=null&&_.md)||!!(_!=null&&_.json));b.useEffect(()=>{$e&&(i==null||i())},[$e,i]);const Ie=b.useRef(!1);(A||te.images&&te.images.length>0)&&(Ie.current=!0),b.useEffect(()=>{Ie.current=!1},[n]);const Le=te.loading||Rn(ge)&&ne&&!A,at=Ie.current&&Le,lt=at,Ge=pg(U??We,de??null,De,n),Ae=ce.properNameMode??(Ge.length>0?"full":"off"),Ce=b.useMemo(()=>({...ce,properNameMode:Ae}),[ce,Ae]),rt=b.useMemo(()=>xh(Ge,Ae,{showWorks:Ce.showWorks}),[Ge,Ae,Ce.showWorks]),[st,Ke]=b.useState(new Set),[D,ke]=b.useState(null),[Qe]=b.useState(jh),[Ye,wt]=b.useState(!0),it=((Po=fe==null?void 0:fe.facsimile)==null?void 0:Po.trimmed)??!1,Pt=it?!0:ce.preserveMargins;b.useCallback(E=>Ee({preserveMargins:E}),[Ee]);const dt=b.useRef(null),[$t,Ot]=b.useState(1),[zt,cr]=b.useState(null),an=E=>{var be;const G=parseInt(((be=E==null?void 0:E.page_id)==null?void 0:be.split(":")[1])??"",10);return isNaN(G)?null:G},ri=E=>{var be,ot;const G=(E==null?void 0:E.pages)??[];return((be=G.find(mt=>mt.columns.some(_t=>_t.chars.length>0)))==null?void 0:be.page)??an(E)??((ot=G[0])==null?void 0:ot.page)??1},[yt,bi]=b.useState(()=>ri(A)),Ci=`${n}
1557
1559
  ${B}
1558
- ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({key:Ci,data:A,started:!1});else if(A!==Ei.data&&(yo({key:Ci,data:A,started:!!A}),A)){const E=A.pages??[];(!Ei.started||!E.some(G=>G.page===yt))&&bi(ri(A))}b.useEffect(()=>{Ke(new Set),Qe.set(null)},[de,B,Qe]);const dr=Ei.key===Ci&&Ei.started,jo=!!ge&&cs(ge.headings).length===0,ko=b.useMemo(()=>jo&&dr&&A?md(A.pages,A.punctuations):[],[jo,dr,A]),mr=b.useCallback(E=>{const G=cs(E.headings);return G.length>0?G:E.file===de?ko:[]},[de,ko]),Tm=b.useCallback(E=>{if(Ke(new Set(E)),E.length>0){const G=E[0],be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be)}},[]),Dt=b.useMemo(()=>{const E=new Map;for(const G of(A==null?void 0:A.pages)??[])E.set(G.page,G);return E},[A]),Ri=an(A),Ti=b.useCallback(E=>{var ot;const G=te.images;if(!G||G.length===0)return;const be=(ot=Dt.get(E))==null?void 0:ot.seq;return(be?G.find(mt=>mt.seq===be):void 0)??G.find(mt=>mt.pageNo===E)??G[E-1]},[te.images,Dt]),wo=$t>1.5,ln=b.useCallback((E,G=!1)=>{const be=Ti(E);return be?E===Ri||G?be.hiresUrl??be.url:be.url:E===Ri?(A==null?void 0:A.imageUrl)??"":""},[Ti,A,Ri]),Im=b.useMemo(()=>ln(yt,wo),[ln,yt,wo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((E,G)=>E-G),[Dt]),si=b.useRef(yt);si.current=yt;const ur=b.useRef(0),pr=b.useRef({page:null,timer:null}),Mm=b.useCallback(E=>{const G=pr.current;E!==G.page&&(G.timer&&(clearTimeout(G.timer),G.timer=null),G.page=null,!(E===si.current||Date.now()<ur.current)&&(G.page=E,G.timer=setTimeout(()=>{G.timer=null,G.page=null,!(Date.now()<ur.current||si.current===E)&&(si.current=E,bi(E))},xg)))},[]);b.useEffect(()=>()=>{pr.current.timer&&clearTimeout(pr.current.timer)},[]);const cn=b.useCallback(E=>{var G;si.current===E||!Dt.has(E)||(ur.current=Date.now()+1e3,si.current=E,bi(E),(G=Dt.get(E))!=null&&G.columns.some(be=>be.chars.length>0)&&cr(be=>({page:E,nonce:((be==null?void 0:be.nonce)??0)+1})))},[Dt]),Ii=b.useCallback(E=>{const G=si.current,be=Wt.indexOf(G),ot=Wt[be<0?0:be+E];ot===void 0||ot===G||cn(ot)},[Wt,cn]),vo=b.useCallback(E=>{if(!E.trim().match(/^\d+$/)||Wt.length===0)return null;const be=parseInt(E.trim(),10),ot=Number.isFinite(be)?be:Number.MAX_SAFE_INTEGER;return Wt.reduce((mt,_t)=>Math.abs(_t-ot)<Math.abs(mt-ot)?_t:mt,Wt[0])},[Wt]),[br,hr]=b.useState(null),dn=b.useRef(null),Am=b.useCallback(E=>{dn.current=E,hr(E)},[]),So=b.useCallback(()=>{const E=dn.current;if(dn.current=null,hr(null),E===null)return;const G=vo(E);G!==null&&cn(G)},[vo,cn]),fr=Wt.indexOf(yt),Lm=b.useCallback(E=>{if(E.altKey||E.ctrlKey||E.metaKey)return;const G=E.target.tagName;G==="INPUT"||G==="TEXTAREA"||G==="SELECT"||(E.key==="ArrowLeft"||E.key==="PageUp"?(E.preventDefault(),Ii(-1)):(E.key==="ArrowRight"||E.key==="PageDown")&&(E.preventDefault(),Ii(1)))},[Ii]),$o=b.useRef(null);b.useEffect(()=>{if(!A)return;const E=$o.current;if(!(!E||E.offsetWidth===0))for(const G of[1,-1]){const be=ln(yt+G);be&&ss(be)}},[A,yt,ln]);const _o=b.useMemo(()=>{var Do;if(!A)return null;if(yt===Ri)return A;const E=Dt.get(yt);if(E&&E.width>0&&E.height>0)return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[E.width,E.height],total_warped_w:E.width,columns:[{col:1,warped_w:E.width,warped_h:E.height,offset_x:0,strips:[],chars:E.columns.flatMap(ut=>ut.chars).map(ut=>({id:ut.id,char:ut.char,slot:ut.slot,pos:ut.pos,sub:ut.sub,bbox_col:ut.bbox??[0,0,0,0]}))}],...E.columns.some(ut=>ut.kind==="figure"&&ut.figBox)?{figBlocks:E.columns.filter(ut=>ut.kind==="figure"&&ut.figBox).map(ut=>({id:ut.fig,box:ut.figBox}))}:{}};const G=(Do=A.pages)==null?void 0:Do.find(ut=>ut.page===yt),[be,ot]=A.image_size||[2386,3082];if(!(be>0&&ot>0))return null;const mt=Ti(yt),_t=(mt==null?void 0:mt.width)??be,wr=(mt==null?void 0:mt.height)??ot,Fo=_t/be,Bo=wr/ot,Ho=new Map;for(const ut of A.columns){const At=(ut.strips||[]).flatMap(hn=>hn.srcQuad.map(fn=>fn[0]));if(At.length===0)continue;const Ut=ut.top_y??0,vr=ut.bottom_y??Ut+ut.warped_h;Ho.set(ut.col,{x0:Math.min(...At),x1:Math.max(...At),top:Ut,slotH:(vr-Ut)/21})}return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[_t,wr],total_warped_w:_t,columns:G?G.columns.map(ut=>{const At=Ho.get(ut.col)??{x0:0,x1:0,top:0,slotH:118};return{col:ut.col,warped_w:_t,warped_h:wr,offset_x:0,strips:[],chars:ut.chars.map(Ut=>{const vr=Ut.slot??Ut.pos??0,hn=(At.top+(vr-1)*At.slotH)*Bo,fn=(At.x0+At.x1)/2,[Xm,Jm]=Ut.sub==="a"?[fn,At.x1]:Ut.sub==="b"?[At.x0,fn]:[At.x0,At.x1];return{...Ut,bbox_col:[Xm*Fo,hn,Jm*Fo,hn+At.slotH*Bo]}})}}):[]}},[A,yt,Ri,Dt,Ti]),{entryTitle:mn,authors:No}=zg(n,r,m===void 0),[zo,gr]=b.useState("text");b.useEffect(()=>{gr("text")},[de,B]);const Pm=b.useMemo(()=>se?vg(se,et,Xa(fe,se),O,Me,mr):[],[se,et,fe,O,Me,mr]),Co=Ah(),Eo=b.useRef(null),Ro=b.useRef(null),xr=b.useMemo(()=>{const E=[];return A&&E.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ye?"bim-rd-on":""}`,"aria-pressed":Ye,title:"切换外挂现代断句标点",onClick:()=>wt(G=>!G),children:Ye?"标点":"无标点"})}}),E},[A,Ye]),Om=b.useMemo(()=>L&&L.length>0?[...xr,...L]:xr,[xr,L]),Fm=b.useMemo(()=>fe&&ge&&B?{entryId:n,versionKey:B,chapterKey:ge.file,chapter:ge,version:fe,transport:r,viewport:Co}:null,[n,B,ge,fe,r,Co]),Bm=b.useCallback(E=>{de&&k(de,E)},[de,k]),oi=Ph({plugins:Om,ctx:Fm,prefs:Ce,setPrefs:Ee,t:Z,convert:O,pages:A==null?void 0:A.pages,textRootRef:Eo,shellTextRef:Ro,selectedCharIds:st,scrollToAnchor:Bm});if(W==="loading")return t.jsx(Va,{className:F,style:T,title:m??mn,label:Z("reader.loading")});if(W==="missing"||!Q||!fe)return t.jsx("div",{className:F,style:{...T,...Ga},children:Z("reader.noText")});if(J==="failed")return t.jsx("div",{className:F,style:{...T,...Ga},children:Z("reader.tocFailed")});if(!se)return t.jsx(Va,{className:F,style:T,title:m??mn,label:Z("reader.tocLoading")});const hi=Xa(fe,se),Hm=Pm,To=nt&&de&&nt.chapter===de?no(de,nt.anchor):null,Dm=To&&ge&&mr(ge).some(E=>E.anchor===nt.anchor)?To:de??null,yr=Q.versions.map(E=>({key:E.key,label:_e.textVersionLabel(E),optionLabel:O(_e.textVersionLabel(E)),sourceName:Ja(E)?Z("reader.originalSource"):E.source_name?O(E.source_name):void 0,license:E.license??void 0,sourceUrl:E.source_url??void 0,primary:E.key===ze})),Mt=kg((Oo=se.source)==null?void 0:Oo.upstream),un=(typeof m=="string"?O(m):m)??(se.title?O(se.title):mn?O(mn):void 0),Io=fe.edition_label?O(fe.edition_label):void 0,jr=un?t.jsx("a",{href:we(n),title:Z("reader.viewEntry"),onClick:d?E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),d(n))}:void 0,children:un}):void 0,Wm=jr&&Io?t.jsxs(t.Fragment,{children:[jr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Io]})]}):jr,Um=No.length>0?O(No.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${` ${E.role||Z("reader.defaultRole")}`}`).join("、")):void 0,kr=ge?bd(ge,hi,O,Me):void 0,ai=Me&&!!(_!=null&&_.json),li=(_==null?void 0:_.json)??null,fi=(_==null?void 0:_.md)??null,Mo=ai&&!ee&&Qc(li.sections),Km=Mo&&!(fi&&Ce.readingMode==="paragraph"&&Ln(fi)),Ym=ai&&Mo?t.jsx(mf,{juan:li,view:zo,onView:gr,textHasEntries:Km}):void 0,Gm=!0,pn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,bn=Ja(fe),Xt=bn?Z("reader.originalSource"):fe.source_name?O(fe.source_name):void 0,Vm=(typeof p=="string"?O(p):p)??(bn?void 0:Xt??O(_e.textVersionLabel(fe))),qm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(uc,{className:F,style:T,title:Wm,subtitle:Vm,byline:Um,current:kr,pagerUnit:hi,rail:Ym,revisedAt:w,backHref:x,backLabel:j,onReportError:v?E=>v({...E,bookTitle:typeof un=="string"?un:void 0,entryId:n}):void 0,workLinkToggle:ai&&!ee&&!!d&&!!(li!=null&&li.sections.some(E=>E.work_id)),toc:Hm,tocCaption:Z("reader.tocCaption",{n:se.chapters.length,unit:O(hi)}),tocHeader:Me&&se.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:ee?Z("reader.searchChaptersPlaceholder"):Z("reader.searchUnitPlaceholder",{unit:O(hi)}),"aria-label":ee?Z("reader.searchChapters"):Z("reader.searchUnit",{unit:O(hi)}),value:He,onChange:E=>ct(E.target.value)}):void 0,activeKey:de??null,tocActiveKey:Dm,onSelect:P,images:Rn(ge)&&ne&&!A?null:te.images,renderImageOverlay:f,imagePanel:A||at?"open":g,imagesLoading:lt,isWarpMode:!!A,showPreserveMargins:!it,customImagePanel:A&&_o?t.jsxs("div",{ref:$o,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Lm,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:s.bim("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:[st.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ke(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${s.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",st.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:$t<=1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round($t*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:$t>=6,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:$t===1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(ug,{ref:dt,resetKey:yt,onScaleChange:Ot,style:{flex:1,minHeight:0},children:t.jsx(Ca,{store:Qe,children:E=>{var G;return t.jsx(qs,{imageUrl:Im,pageData:_o,selectedCharIds:st,hoveredCharId:E,decorations:oi.decorations,preserveMargins:Pt,banxinMode:ce.banxinMode,extent:(G=Ti(yt))==null?void 0:G.extent,renderScale:$t,selectedFigBlock:D,onFigBlockClick:be=>ke(be),onCharClick:be=>{ke(null),Ke(mt=>{const _t=new Set(mt);return _t.has(be)?_t.delete(be):(_t.clear(),_t.add(be)),_t});const ot=document.querySelector(`[data-char-id="${be}"]`);ot&&ot.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Qe.set})}})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":Z("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:s.bim("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:fr<=0,onClick:()=>Ii(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":yt,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:s.bim("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":Z("reader.facsimilePageInput"),size:Math.max(2,String(br??yt).length),value:br??String(yt),onFocus:E=>E.currentTarget.select(),onChange:E=>Am(E.target.value),onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),So()):E.key==="Escape"&&(dn.current=null,hr(null)),E.stopPropagation()},onBlur:So,style:{width:`${Math.max(2,String(br??yt).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${s.bim("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:fr<0||fr>=Wt.length-1,onClick:()=>Ii(1),children:"›"})]})]}):void 0,pluginSettings:oi.settings,pluginToolbar:oi.toolbar,pluginOverlay:oi.overlay,textRootRef:Ro,prefs:Ce,onPrefsChange:Ee,versions:yr.length>1?yr:void 0,currentVersionKey:yr.length>1?fe.key:void 0,onVersionChange:Je,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Ln(fi),allowVertical:y,origScriptAvailable:qm,contentLoading:Re,children:[(Re||ne&&!A&&!ai&&pn==null)&&t.jsx(nc,{}),!Re&&A&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:Eo,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:ge!=null&&ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,fe.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]})]})]}),t.jsx(Ca,{store:Qe,children:E=>t.jsx(to,{pageData:A,pages:A.pages,punctuations:A.punctuations||jg,selectedCharIds:st,hoveredCharId:E,onSelectionChange:Tm,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:G,fig:be})=>{Ke(new Set),ke(be),bi(G)},onCharClick:G=>{ke(null),Ke(ot=>{const mt=new Set(ot);return mt.has(G)?mt.delete(G):(mt.clear(),mt.add(G)),mt});const be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be),oi.onCellClick(G)},onCharHover:G=>{Qe.set(G),oi.onCellHover(G)},decorations:oi.decorations,mode:"horizontal",showPunctuation:Ye,entities:rt,entityTransport:r,onEntityNavigate:R,onVisiblePageChange:Mm,convert:O,scrollToPage:zt,scrollToAnchor:Pe&&Pe.chapter===de&&dr?Pe:null,onVisibleHeadingChange:G=>Y(G&&de?{chapter:de,anchor:G}:null),pageBreaks:Ce.pageBreaks,pageIndicatorY:Ce.pageIndicatorY,onPageIndicatorYChange:G=>Ee({pageIndicatorY:G}),quoteStyle:Ce.quoteStyle,bookTitleStyle:Ce.bookTitleStyle,showWorks:Ce.showWorks})})]}),!Re&&!A&&ai&&li&&t.jsx(cf,{juan:li,rawText:fi,positionLabel:_g(ge,se,hi,O),groupLabel:Ng(se,de??null),index:wg(n,se),searchQuery:He,onNavigate:d,transport:r,workLabelCache:tt,prefs:Ce,view:zo,onViewChange:gr},`${B}/${de}`),!Re&&!A&&!ai&&pn!=null&&ge&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[bn&&Xt&&t.jsx(t.Fragment,{children:Xt}),!bn&&fe.source_name&&t.jsxs(t.Fragment,{children:[Z("reader.textSource")," ",fe.source_url?t.jsx("a",{className:"bim-rd-link",href:fe.source_url,target:"_blank",rel:"noreferrer",children:O(fe.source_name)}):O(fe.source_name)]}),Xt&&fe.license&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]}),Mt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[Z("reader.upstream")," ",Mt.url?t.jsx("a",{className:"bim-rd-link",href:Mt.url,target:"_blank",rel:"noreferrer",children:O(Mt.name??Mt.url)}):O(Mt.name??""),Mt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),Mt.license_url?t.jsx("a",{className:"bim-rd-link",href:Mt.license_url,target:"_blank",rel:"noreferrer",children:Mt.license}):Mt.license]}),Mt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(rc,{text:Mt.note,convert:O})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Hs,{text:pn,mode:Ce.readingMode,tables:Gm,gujiMarkdown:!0,bookMarking:Bs(Ce),quoteStyle:Ce.quoteStyle})})]}),!Re&&!ne&&!A&&!ai&&pn==null&&ge&&t.jsx("div",{className:"bim-rd-state",children:Z("reader.chapterFailed")}),!Re&&se.references&&se.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:Z("reader.references")}),t.jsx("ol",{children:se.references.map((E,G)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:O(E.title)}):t.jsx("span",{children:O(E.title)}),E.author&&t.jsxs("span",{children:[",",O(E.author)]}),E.note&&t.jsxs("span",{children:["。",O(E.note)]})]},G))})]})]})};function Ja(e){return e.is_original===!0||e.source==="original"}function _g(e,i,n,r){var a,l;if(!e)return;const o=(l=(a=i.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(o?`${o}冊`:`${n}${e.n}`)}function Ng(e,i){if(!i)return;const n=r=>{var o;for(const a of r??[]){const l=n(a.children);if(l)return l;if((o=a.files)!=null&&o.includes(i))return a.label}};return n(e.juan_groups)}function zg(e,i,n){const[r,o]=b.useState({entryTitle:void 0,authors:[]});return b.useEffect(()=>{if(o({entryTitle:void 0,authors:[]}),typeof i.getItem!="function")return;let a=!1;return Promise.resolve(i.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);o({entryTitle:n&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,i,n]),r}const Cg=({pageData:e,rawImageUrl:i="",punctuations:n=[],title:r,subtitle:o,onBack:a,className:l="",style:d={}})=>{const[c,m]=b.useState(new Set),[p,h]=b.useState(null),[u,f]=b.useState("horizontal"),[g,y]=b.useState(!0),v=b.useRef(null),w=b.useCallback($=>{m(new Set($))},[]),x=b.useCallback($=>{if(m(N=>{const z=new Set(N);return z.has($)?z.delete($):(z.clear(),z.add($)),z}),v.current){const N=v.current.querySelector(`[data-char-id="${$}"]`);N&&N.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var $;m(new Set),window.getSelection&&(($=window.getSelection())==null||$.removeAllRanges())},S=n.length>0?n:e.punctuations||[];return t.jsxs("div",{className:`guji-reader-container ${l}`,style:d,children:[t.jsxs("header",{className:"guji-reader-header",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&t.jsx("button",{type:"button",onClick:a,className:"guji-reader-btn",style:{marginRight:6},children:"‹ 返回"}),t.jsx("span",{className:"guji-reader-title",children:r||e.title}),o&&t.jsx("span",{style:{fontSize:"0.85rem",color:s.bim("meta-fg")},children:o}),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:s.bim("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:s.bim("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>y($=>!$),className:`guji-reader-btn ${g?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:g?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f($=>$==="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(qs,{imageUrl:i,pageData:e,selectedCharIds:c,hoveredCharId:p,onCharClick:x,onCharHover:h})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:v,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(to,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:p,onSelectionChange:w,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},Eg=({data:e,onNavigate:i,className:n,style:r})=>{var p;const{t:o,convert:a}=oe(),[l,d]=b.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[c,m]=b.useState(null);return t.jsxs("div",{className:n,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:s.bim("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[o("catalog.totalVolumes")," ",t.jsx("strong",{children:e.total_volumes})," ",o("unit.juan")]}),e.stats.zhulu!=null&&t.jsxs("span",{children:[o("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",o("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[o("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",o("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:o("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(h=>t.jsx(Rg,{division:h,expanded:l===h.name,onToggle:()=>d(l===h.name?null:h.name),expandedCat:c,onCatToggle:u=>m(c===u?null:u),onNavigate:i},h.name))})]})},Rg=({division:e,expanded:i,onToggle:n,expandedCat:r,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=oe(),c=e.categories.reduce((m,p)=>{const h=p.stats||{zhulu:0,cunmu:0};return m+(h.zhulu||0)+(h.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:i?`color-mix(in srgb, ${s.bim("primary")} 6%, transparent)`:s.bim("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:s.bim("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:i?"▲":"▼"})]})]}),i&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(m=>{const p=`${e.name}/${m.name}`;return t.jsx(Tg,{category:m,expanded:r===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},Tg=({category:e,expanded:i,onToggle:n,onNavigate:r})=>{var m,p,h,u;const{t:o,convert:a}=oe(),l=((m=e.books)==null?void 0:m.zhulu)||[],d=((p=e.books)==null?void 0:p.cunmu)||[],c=(((h=e.stats)==null?void 0:h.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:i?s.bim("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:s.bim("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginLeft:"8px",fontWeight:400},children:o("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[o("catalogPage.booksN",{n:c})," ",i?"▲":"▼"]})]}),i&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Za,{label:o("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(Za,{label:o("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},Za=({label:e,books:i,onNavigate:n})=>{const{t:r,convert:o}=oe(),a=It(),[l,d]=b.useState(i.length<=20),c=l?i:i.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",i.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((m,p)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:s.bim("fg")},children:m.work_id&&n?t.jsx("a",{href:a(m.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(m.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${s.bim("link-fg")}`},children:o(m.title)}):o(m.title)}),m.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.volumes)}),m.author&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.author).slice(0,20)})]},p))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:s.bim("primary"),background:"transparent",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:i.length})})]})};function ro(e="/api/feedback",i){const n=()=>typeof e=="function"?e():e,r=(...o)=>((i==null?void 0:i.fetch)??fetch)(...o);return{async listFeedback(o){try{const l=await(await r(`${n()}?resourceId=${encodeURIComponent(o)}`)).json();return l!=null&&l.success&&Array.isArray(l.items)?l.items:[]}catch{return[]}},async submitFeedback(o){const a=await r(n(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error((l==null?void 0:l.error)||(i==null?void 0:i.defaultError)||"submit failed")}}}}function gd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const Ig=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],xd=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:r})=>{const{t:o}=oe(),[a,l]=b.useState(null),[d,c]=b.useState(""),[m,p]=b.useState(""),[h,u]=b.useState("idle"),[f,g]=b.useState(""),y=b.useRef(null);b.useEffect(()=>{e&&(l(null),c(""),p(""),u("idle"),g(""))},[e]),b.useEffect(()=>{a&&setTimeout(()=>{var x;return(x=y.current)==null?void 0:x.focus()},100)},[a]),b.useEffect(()=>{if(h==="success"){const x=setTimeout(i,2e3);return()=>clearTimeout(x)}},[h,i]),b.useEffect(()=>{if(!e)return;const x=j=>{j.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const v=async()=>{if(!(!a||!d.trim())){u("submitting"),g("");try{await n({type:a,content:d.trim(),...m.trim()?{contact:m.trim()}:{}}),u("success")}catch(x){u("error"),g(x instanceof Error?x.message:o("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&h!=="submitting";return t.jsx("div",{style:Mg,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:Ag,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Lg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:Pg,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Dg,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:o("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:s.bim("primary"),marginTop:"8px"},children:o("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Ig.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...Og,...a===x.value?Fg:{}},children:[t.jsx("span",{children:x.icon})," ",o(`feedback.submitType.${x.value}`)]},x.value))}),t.jsx("textarea",{ref:y,value:d,onChange:x=>c(x.target.value),placeholder:o(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||h==="submitting",style:{...Bg,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:m,onChange:x=>p(x.target.value),placeholder:o("feedback.contactPlaceholder"),maxLength:200,disabled:!a||h==="submitting","aria-label":o("feedback.contactLabel"),style:Ug}),t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),h==="error"&&t.jsx("div",{style:Wg,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!w,style:{...Hg,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Mg={position:"fixed",top:0,left:0,right:0,bottom:0,background:s.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ag={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:s.bim("shadow-dialog")},Lg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Pg={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:s.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Og={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Fg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Bg={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Hg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},Dg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:s.bim("success")},Wg={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Ug={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},ds="--bim-feedback-fab-offset",ms=48,Kg=16,Yg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:r=!1,zIndex:o})=>{const{t:a}=oe(),[l,d]=b.useState(!1),c=i.bottom??24;return b.useEffect(()=>{if(r||typeof document>"u")return;const m=document.documentElement;return m.style.setProperty(ds,`calc(${c+ms+Kg}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(ds)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Gg,zIndex:o??s.bim("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:i.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:n})]})},Gg={position:"fixed",width:`${ms}px`,height:`${ms}px`,borderRadius:"50%",border:"none",background:s.bim("primary"),color:s.bim("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:s.bim("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Vg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],yd=({onSubmit:e})=>{const{t:i}=oe(),[n,r]=b.useState("bug"),[o,a]=b.useState(""),[l,d]=b.useState(""),[c,m]=b.useState("idle"),[p,h]=b.useState(""),u=b.useRef(null);b.useEffect(()=>{n&&setTimeout(()=>{var y;return(y=u.current)==null?void 0:y.focus()},100)},[n]);const f=async()=>{if(!(!n||!o.trim())){m("submitting"),h("");try{await e({type:n,content:o.trim(),...l.trim()?{contact:l.trim()}:{}}),m("success"),a(""),d(""),r("bug")}catch(y){m("error"),h(y instanceof Error?y.message:i("feedback.submitFailedRetry"))}}},g=n&&o.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:Qa,children:t.jsxs("div",{style:Qg,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:ex,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Qa,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Vg.map(y=>t.jsxs("button",{onClick:()=>r(y.value),style:{...qg,...n===y.value?Xg:{}},children:[t.jsx("span",{children:y.icon})," ",i(`feedback.submitType.${y.value}`)]},y.value))}),t.jsx("textarea",{ref:u,value:o,onChange:y=>a(y.target.value),placeholder:i(n?`feedback.placeholder.${n}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...Jg}}),t.jsx("input",{type:"text",value:l,onChange:y=>d(y.target.value),placeholder:i("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":i("feedback.contactLabel"),style:ix}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[o.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!g,style:{...Zg,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:tx,children:p})]})},Qa={padding:"16px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",background:s.bim("input-bg")},qg={padding:"8px 16px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:"transparent",color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Xg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Jg={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Zg={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},Qg={display:"flex",alignItems:"center",gap:"12px",color:s.bim("success"),fontSize:"14px"},ex={background:"none",border:"none",color:s.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},tx={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},ix={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},jd={bug:{key:"bug",color:s.bim("danger")},resource:{key:"resource",color:s.bim("primary")},suggestion:{key:"suggestion",color:s.bim("primary")},other:{key:"other",color:s.bim("desc-fg")}},nx=jd.other,kd={pending:{key:"pending",color:s.bim("warning")},in_progress:{key:"in_progress",color:s.bim("primary")},resolved:{key:"resolved",color:s.bim("success")},wontfix:{key:"wontfix",color:s.bim("desc-fg")},duplicate:{key:"duplicate",color:s.bim("desc-fg")}},rx=kd.pending;function sx(e){try{const i=new Date(e),n=r=>String(r).padStart(2,"0");return`${i.getFullYear()}-${n(i.getMonth()+1)}-${n(i.getDate())} ${n(i.getHours())}:${n(i.getMinutes())}`}catch{return e}}function ox(e,i){if(!e)return!1;try{const n=new URL(e,i);if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=new URL(i);return n.hostname===r.hostname}catch{return!1}}const wd=({items:e,loading:i})=>{const n=It(),{t:r,convert:o}=oe();return i?t.jsx(nc,{}):e.length===0?t.jsx("div",{style:ax,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=jd[a.type]||nx,d=kd[a.status]||rx,c=typeof window<"u"&&ox(a.pageUrl,window.location.href);return t.jsxs("div",{style:lx,children:[t.jsxs("div",{style:cx,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...el,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...el,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:dx,children:sx(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:mx,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Fr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Fr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Fr,children:a.pageUrl}))]}),t.jsx("div",{style:ux,children:o(a.content)}),a.reply&&t.jsxs("div",{style:px,children:[t.jsx("div",{style:bx,children:r("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},ax={textAlign:"center",padding:"40px 0",color:s.bim("desc-fg"),fontSize:"14px"},lx={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},cx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},el={fontSize:"12px",color:s.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},dx={fontSize:"12px",color:s.bim("desc-fg")},mx={fontSize:"12px",marginBottom:"6px"},Fr={color:s.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${s.bim("primary")}`},ux={fontSize:"14px",lineHeight:"1.6",color:s.bim("fg"),whiteSpace:"pre-wrap"},px={marginTop:"12px",padding:"10px 12px",background:s.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:s.bim("fg")},bx={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:s.bim("primary")},vd=({resourceId:e,transport:i,apiUrl:n})=>{const{t:r}=oe(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(r);c.current=r;const m=b.useMemo(()=>i??ro(n,{defaultError:c.current("feedback.submitFailed")}),[i,n]),p=b.useCallback(async()=>{d(!0);try{a(await m.listFeedback(e))}catch{}finally{d(!1)}},[e,m]);b.useEffect(()=>{p()},[p]);const h=async u=>{await m.submitFeedback({...u,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e}),setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(wd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(yd,{onSubmit:h})})]})},er=8;async function tr(e,i,n,r){const o=Number.isFinite(i)?Math.max(1,Math.floor(i)):1,a=new Array(e.length);let l=0;const d=Array.from({length:Math.min(o,Math.max(1,e.length))},async()=>{for(;l<e.length&&!(r!=null&&r());){const c=l++;a[c]=await n(e[c],c)}});return await Promise.all(d),a}const hx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function fx(e){const i=e.search(hx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const Sd={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:i})=>{let n=e,r="",o=i;if(e&&typeof i=="string"&&(i===e||i===gx(e))){const[a,l]=fx(i);l&&(n=encodeURI(a),o=a,r=l)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:n,target:n!=null&&n.startsWith("http")?"_blank":void 0,rel:n!=null&&n.startsWith("http")?"noopener noreferrer":void 0,style:{color:s.bim("link")},children:o}),r]})},code:({children:e})=>t.jsx("code",{style:{background:s.bim("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function gx(e){try{return decodeURI(e)}catch{return e}}const xx={...Sd,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:r})=>{const{convert:o}=xt(),a=i?xx:Sd;return t.jsx("div",{className:r,style:n,children:t.jsx(su,{remarkPlugins:[ou],components:a,children:o(e)})})},yx=s.detail["zh-Hant"].relation,jx=s.detail["zh-Hant"].lossStatus,kx=s.detail["zh-Hant"].resourceKind,ir=s.getT("zh-Hant"),so=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function tl(e,i=ir){return e?so(yx,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function wx(e,i=ir){return so(jx,e)?i(`detail.lossStatus.${e}`):e}function vx(e,i=ir){return so(kx,e)?i(`detail.resourceKind.${e}`):""}function oo({authors:e,onNavigate:i,renderLink:n}){const{convert:r}=oe(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=vs(a.role);return t.jsxs(b.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(jt,{id:a.entity_id,label:r(a.name),onNavigate:i,renderLink:n,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function $d(e,i,n=ir){var c,m;const r=js(e,i),o=r.mirrors.map(p=>({key:p.key,label:p.label,description:p.description,rows:p.items.filter(h=>h.group_role!=="mirror"),mirrors:p.items.filter(h=>h.group_role==="mirror")})),a=r.buckets.filter(p=>p.key==="image"||p.key==="textImage").flatMap(p=>p.items);a.length&&o.push({key:"_images",label:o.length?n("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(p=>p.key==="physical"))==null?void 0:c.items)??[];return l.length&&o.push({key:"_physical",label:n("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((m=r.buckets.find(p=>p.key==="text"))==null?void 0:m.items)??[],groups:o}}function _d(e,i){const n=(e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name,r=Al(e,i);return r?`${n}(${r})`:n}function ao({item:e,siblings:i,listedVolumeCounts:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(!1),d=s.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(_d(e,i)),p=s.resourceHref(e),h=Kn(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,g;const u=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=e.metadata)==null?void 0:g.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?r("colorMode.color"):r("colorMode.bw")})]}):null;return p?t.jsxs("a",{href:p,target:"_blank",rel:"noopener noreferrer",children:[m," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),u]}):t.jsxs("span",{className:"bim-d-zt-name",children:[m,u]})})(),h&&t.jsx("span",{className:"bim-d-meta",children:o(h)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(As,{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?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Nd({groups:e,listedVolumeCounts:i}){const{t:n,convert:r}=oe();return t.jsx(t.Fragment,{children:e.map(o=>t.jsxs("div",{className:"bim-d-rg",children:[o.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(o.label)}),o.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(o.description)}),o.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:o.rows.map((a,l)=>t.jsx(ao,{item:a,siblings:o.rows,listedVolumeCounts:i},`${a.id||a.url||a.name}-${l}`))})}),o.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[o.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:n("detail.mirror")}),o.mirrors.map((a,l)=>{const d=s.resourceHref(a),c=r(_d(a,o.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?r(a.details):void 0,children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:c},l)})]})]},o.key))})}const Yi=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function us(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Yi.find(r=>i.startsWith(r.key[0])))==null?void 0:n.key}const il=12,Br=50,Sx=60,zd=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,railTop:a,back:l,railLinks:d})=>{var Je,Pe,Ue,nt,Y;const{t:c,convert:m,messages:p}=oe(),h=b.useMemo(()=>Ss({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[v,w]=b.useState(""),[x,j]=b.useState(!1),S=Math.max(h.length,e._edition_count??0),$=S>Zo&&(h.length>Zo||!!((Je=e._book_groups)!=null&&Je.length)),[N,z]=b.useState({}),C=e._book_groups,[U,R]=b.useState({}),L=b.useRef(new Set),F=b.useMemo(()=>{if(!$)return[];const M={};for(const q of C??[])q.id&&q.title&&(M[q.id]=q.title);const k=Wu(e._books??[],e.version_graph,{titles:M,noHolderFallback:!!C});if(!C)return k;const P=new Map(k.map(q=>[q.key,q]));return C.map(q=>{const _=P.get(q.g);if(_&&_.rows.length>=q.n)return{..._,title:_.title||q.title||""};const le=U[q.g],H=(le==null?void 0:le.rows)??(_==null?void 0:_.rows)??[];return{key:q.g,title:q.g!=="_none"&&(q.title||(_==null?void 0:_.title))||"",rows:H,total:q.n,imageCount:H.filter(he=>he.hasImage).length,pagesLeft:Math.max(0,q.pages-((le==null?void 0:le.loaded)??0))}})},[$,e._books,e.version_graph,C,U]),T=b.useMemo(()=>x?F.map(M=>({...M,rows:M.rows.filter(k=>k.hasImage)})).filter(M=>M.rows.length):F,[F,x]);b.useEffect(()=>{var M;if(!(!$||!(i!=null&&i.getBookGroupPage)))for(const k of F){const P=N[k.key]??0;if(!P||!k.pagesLeft||k.rows.length>=P||L.current.has(k.key))continue;const q=(((M=U[k.key])==null?void 0:M.loaded)??0)+1;L.current.add(k.key),i.getBookGroupPage(e.id,k.key,q).then(_=>{const le=(_??[]).map(H=>Pl(H,e.version_graph));R(H=>{const he=H[k.key];return{...H,[k.key]:{rows:[...(he==null?void 0:he.rows)??[],...le],loaded:q}}})}).catch(()=>R(_=>{var le;return{..._,[k.key]:{rows:((le=_[k.key])==null?void 0:le.rows)??[],loaded:q}}})).finally(()=>L.current.delete(k.key))}},[$,F,N,i,e.id,e.version_graph,U]);const Z=h.length<=Sx,O=!$&&(Z||g||!!v||x),ae=b.useMemo(()=>$?T.flatMap(M=>N[M.key]?M.rows.slice(0,N[M.key]).map(k=>k.id):[]):O?h:h.slice(0,il),[$,T,N,h,O]);b.useEffect(()=>{if(!i||ae.length===0)return;const M=ae.filter(P=>!u.has(P));if(M.length===0)return;let k=!1;return tr(M,er,P=>i.getItem(P).then(q=>{var le;const _=q??{};return[P,{id:P,title:_.title,edition:_.edition,resources:_.resources,publication_info:_.publication_info,current_location:_.current_location,provenance:_.provenance,lineage:_.lineage,related_books:_.related_books,dating:_.dating,measure_info:_.measure_info,summary:_x((le=q==null?void 0:q.description)==null?void 0:le.text)}]}).catch(()=>[P,{id:P}]),()=>k).then(P=>{k||f(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,ae,u]);const ce=b.useMemo(()=>$?[]:h.map(M=>u.get(M)??{id:M}),[$,h,u]),Ee=h.length>0&&h.every(M=>u.has(M)),we=!!i&&ae.some(M=>!u.has(M)),ye=Z||O,Q=b.useMemo(()=>Ol(ce,e.version_graph,{era:v,scanOnly:x,sort:ye?"year":"default"}),[ce,e.version_graph,v,x,ye]),Ne=g?Q.rows:Q.rows.slice(0,il),W=$?F.reduce((M,k)=>M+k.imageCount,0):Q.allRows.filter(M=>M.hasImage).length,je=Q.allRows.reduce((M,k)=>{var P;return M+(((P=k.copies)==null?void 0:P.length)??0)},0),K=b.useMemo(()=>(e._related||[]).map(M=>({...M,title:M.title??""})),[e._related]),V=K.filter(M=>M.relation==="collected_in"),re=b.useMemo(()=>{const M=new Map;for(const k of e.related_works||[]){if(k.relation!=="collected_in"||M.has(k.id))continue;const P=qu(k.volume_index,k.order,e.subtype,p.workPage.pos);P&&M.set(k.id,P)}return M},[e.related_works,e.subtype,p.workPage.pos]),X=((Pe=e._contents)==null?void 0:Pe.total)??0,I=b.useMemo(()=>{const M=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],k=P=>{const q=M.indexOf(P??"");return q<0?M.length:q};return K.filter(P=>P.relation!=="collected_in").map((P,q)=>({r:P,i:q})).sort((P,q)=>k(P.r.relation)-k(q.r.relation)||P.i-q.i).map(P=>P.r)},[K]),ue=b.useMemo(()=>{const M=js(e.resources,e.resource_groups);return[...M.mirrors.flatMap(k=>k.items.map(P=>({r:P,kind:m(k.label)}))),...M.buckets.flatMap(k=>k.items.map(P=>({r:P,kind:m(vx(k.key,c))})))]},[e.resources,e.resource_groups,m,c]),fe=e.indexed_by||[],ze=e.emendated_by||[],B=b.useMemo(()=>{var he,xe,Re,Ze,Me;const M=[],k=(xe=(he=e.authors)==null?void 0:he[0])==null?void 0:xe.dynasty;k&&M.push({label:c("workPage.fact.written"),value:m(k)});const P=qt(e,p.unit.juan);if(P){const He=((Re=e.juan_count)==null?void 0:Re.description)??((Me=(Ze=e.measures)==null?void 0:Ze.find(ct=>(ct==null?void 0:ct.unit)==="卷"&&ct.note))==null?void 0:Me.note);M.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(P),He&&He!==P?t.jsxs("span",{className:"bim-d-meta",children:["(",m(He),")"]}):null]})})}e.loss_status&&M.push({label:c("workPage.fact.loss"),value:m(wx(e.loss_status,c))}),e.authenticity==="forged"&&M.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const q=Q.allRows.filter(He=>He.sortYear!=null),_=q.length>0?q.reduce((He,ct)=>He.sortYear<=ct.sortYear?He:ct):null;_!=null&&_.era.era?M.push({label:c("workPage.fact.earliest"),value:m([_.era.era,_.era.reign].filter(Boolean).join(" ")),title:_.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):we&&M.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),ze.length&&M.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:ze.length})});const le=$x(e.additional_titles);le.length&&M.push({label:c("workPage.fact.alias"),value:le.map(m).join("、")});const H=(e.additional_works||[]).map(He=>m(He.book_title)+(He.n_juan!=null?` ${He.n_juan}${p.unit.juan}`:""));return H.length&&M.push({label:c("workPage.fact.appendix"),value:H.join("、")}),M},[e,m,c,p,we,Q.allRows,ze.length]),Te=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:Ee?W:0,label:c("workPage.stat.hasImage")},{value:fe.length,label:c("workPage.stat.catalogs")}],ve=$s(e),Ve=ve?[ve.l1,ve.l2,ve.l3,ve.l4].filter(Boolean).map(M=>m(M)):[],qe=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",Xe=t.jsx(tn,{title:m(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:n,renderLink:r}),meta:t.jsx(vt,{items:[...Ve,ve!=null&&ve.source?c("workPage.classifiedBy",{source:m(ve.source.split("/")[0])}):"",qe]}),description:(Ue=e.description)!=null&&Ue.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(nt=e.description.sources)!=null&&nt.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(M=>({text:m(Ju(M)),href:Zu(M)})).filter(M=>M.text).map((M,k)=>t.jsxs(b.Fragment,{children:[k>0?" · ":null,M.href?t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",children:M.text}):M.text]},k))}):null]}):void 0,stats:Te,facts:B,readAction:o,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Y=e.appendix)==null?void 0:Y.map((M,k)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(M.title)}),t.jsx(zi,{text:M.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},k))}),J=Q.eras.length>=2?[{key:"",label:c("catalog.all")},...Q.eras.map(M=>({key:M,label:`${M} ${Q.allRows.filter(k=>k.era.era===M).length}`}))]:[],ie=[];S&&ie.push({id:"versions",label:c("workPage.sec.versions"),count:S}),fe.length&&ie.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:fe.length}),X&&ie.push({id:"contents",label:c("workPage.sec.contents"),count:X}),V.length&&ie.push({id:"collected",label:c("workPage.sec.collected"),count:V.length}),I.length&&ie.push({id:"related",label:c("workPage.sec.related"),count:I.length}),ue.length&&ie.push({id:"resources",label:c("workPage.sec.resources"),count:ue.length});const me=S===0&&fe.length===0&&!X,se=t.jsxs(t.Fragment,{children:[S>0&&t.jsxs(St,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(vt,{items:[c("workPage.versionsTotal",{n:S-je}),Ee&&W?c("workPage.versionsWithImage",{n:W}):"",Q.rows.length!==Q.allRows.length?c("workPage.versionsCurrent",{n:Q.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":we&&J.length===0&&h.length>1?"":void 0,children:[!$&&J.length>0&&t.jsx(Qi,{items:J,value:v,onChange:M=>{w(M),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(kc,{label:c("workPage.scanOnly"),checked:x,onChange:M=>{j(M),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(ye?"workPage.sortByYear":"workPage.sortByCatalog")})]}),$?t.jsxs("div",{className:"bim-d-groups",children:[t.jsx("div",{className:"bim-d-ui",style:{display:"flex",justifyContent:"flex-end",margin:"4px 0"},children:t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(Object.keys(N).length?{}:Object.fromEntries(T.slice(0,20).map(M=>[M.key,Br]))),children:Object.keys(N).length?c("workPage.groupCollapseAll"):c("workPage.groupExpandAll")})}),T.map(M=>{const k=N[M.key]??0,P=M.rows.slice(0,k);return t.jsxs("details",{open:k>0,onToggle:q=>{const _=q.currentTarget.open;z(le=>{if(_===le[M.key]>0)return le;const H={...le};return _?H[M.key]=Br:delete H[M.key],H})},style:{borderTop:`1px solid ${s.bim("border")}`},children:[t.jsxs("summary",{className:"bim-d-ui",style:{cursor:"pointer",minHeight:40,display:"flex",alignItems:"center",gap:12,padding:"6px 4px"},children:[t.jsx("span",{style:{flex:1},children:m(M.title||c("workPage.groupUngrouped"))}),t.jsx("span",{className:"bim-d-meta",children:c("workPage.groupCount",{n:M.total})}),M.imageCount>0&&t.jsx("span",{className:"bim-d-flag",children:c("workPage.groupImage",{n:M.imageCount})})]}),k>0&&t.jsx("table",{className:"bim-d-zt bim-d-zt-ver",children:t.jsx("tbody",{children:P.map(q=>{const _=u.get(q.id);return t.jsx(nl,{row:q,measure:_==null?void 0:_.measure_info,relations:q.relations??(_?Ll(_):void 0),loaded:!0,onNavigate:n,renderLink:r},q.id)})})}),k>0&&M.total>k&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(q=>({...q,[M.key]:k+Br})),children:c("workPage.groupMore",{n:M.total-k})})]},M.key)})]}):t.jsxs(t.Fragment,{children:[t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&en(Q.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:Ne.map(M=>{var k;return t.jsx(nl,{row:M,measure:(k=u.get(M.id))==null?void 0:k.measure_info,relations:M.relations,loaded:u.has(M.id),onNavigate:n,renderLink:r},`${M.id}:${u.has(M.id)?"r":"p"}`)})})]}),Ne.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(v||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx(Jn,{total:Q.rows.length,shown:Ne.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)})]}),Q.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),fe.length>0&&t.jsx(zx,{items:fe,transport:i,onNavigate:n,renderLink:r}),X>0&&e._contents&&t.jsx(Cx,{workId:e.id,info:e._contents,transport:i,onNavigate:n,renderLink:r}),me&&t.jsx(St,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),de=(M,k)=>t.jsx(jt,{id:M,label:m(k),onNavigate:n,renderLink:r,dense:!0}),ge=b.useMemo(()=>{const M=new Map;for(const k of I){const P=tl(k.relation,c);M.set(P,(M.get(P)??0)+1)}return M.size>1?[...M.entries()].sort((k,P)=>P[1]-k[1]).slice(0,4).map(([k,P])=>`${m(k)} ${P}`).join(" · "):void 0},[I,m,c]),Oe=t.jsxs(t.Fragment,{children:[t.jsx(mi,{id:"collected",title:c("workPage.sec.collected"),items:V.map(M=>de(M.id,M.title)),metas:V.map(M=>re.get(M.id)??"")}),t.jsx(mi,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:I.length}),sub:ge,items:I.map(M=>t.jsxs(t.Fragment,{children:[de(M.id,M.title),t.jsx("span",{className:"bim-d-meta",title:M.note?m(M.note):void 0,children:m(tl(M.relation,c))})]}))}),t.jsx(mi,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:ue.map(({r:M,kind:k})=>{const P=m((M.url?s.getDisplayNameFromUrl(M.url):void 0)||M.name),q=s.resourceHref(M);return t.jsxs(t.Fragment,{children:[q?t.jsxs("a",{href:q,target:"_blank",rel:"noopener noreferrer",children:[P," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:P}),k&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:k})]})})})]});return t.jsx(Zi,{railTop:a,back:l,nav:ie,railLinks:d,main:se,card:Xe,side:Oe})};function $x(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function ps(e,i){return i((e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name)}function _x(e){var a;if(!e)return;const n=e.replace(/\*\*/g,"").split(/\n/)[0].trim().match(/[^。]+。?/g)??[],o=((n.length>1&&((a=n[0])!=null&&a.startsWith("《"))?n[1]:n[0])??"").trim();return o?o.length>120?`${o.slice(0,120)}…`:o:void 0}function Nx({copies:e,onNavigate:i,renderLink:n}){const{t:r,convert:o}=oe(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?ps(l.holders[0],o):"")||"",c=a.get(d)??[];c.push(l),a.set(d,c)}return t.jsxs("span",{className:"bim-d-zt-copies",children:[r("workPage.sameEditionCopies",{n:e.length}),[...a].map(([l,d],c)=>t.jsxs(b.Fragment,{children:[c>0?";":"",l?`${o(l)} `:"",d.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0?" · ":"",t.jsx(jt,{id:m.id,label:m.callNumber||m.id,onNavigate:i,renderLink:n,dense:!0})]},m.id))]},l||c))]})}function nl({row:e,measure:i,relations:n,loaded:r,onNavigate:o,renderLink:a}){const{t:l,convert:d}=oe(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),m=e.era.source==="edition",p=e.holders[0],h=e.copies??[],u=h.length&&e.locationName?d(e.locationName):p?ps(p,d):e.locationName?d(e.locationName):"",f=e.images[0],g=f?s.resourceHref(f):void 0,y=e.images.map(v=>ps(v,d)).join("、");return t.jsxs("tr",{"data-loading":r?void 0:"",className:h.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:h.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(jt,{id:e.id,label:d(e.name),onNavigate:o,renderLink:a,dense:!0}),i?t.jsx("span",{className:"bim-d-meta",children:d(i)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}),n&&n.length>0&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:n.map((v,w)=>t.jsxs(b.Fragment,{children:[w>0?" · ":null,d(l("workPage.relationWith",{relation:v.relation,n:v.ids.length}))]},v.relation))}),h.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:d(e.summary)}),h.length>0&&t.jsx(Nx,{copies:h,onNavigate:o,renderLink:a})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:m?l("workPage.inferredFromEdition"):void 0,children:c?d(c):r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${u?"":" bim-d-zt-blank"}`,children:[u||(r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),h.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&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:y,children:l("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:y,children:l("workPage.hasImage")}))})]})}function zx({items:e,transport:i,onNavigate:n,renderLink:r}){const{t:o,convert:a}=oe(),{items:l,groups:d}=b.useMemo(()=>{const f=[],g=new Map;for(const y of e){const v=`${y.source}\0${y.source_bid??""}`,w=g.get(v);w?w.push(y):(g.set(v,[y]),f.push(y))}return{items:f,groups:f.map(y=>g.get(`${y.source}\0${y.source_bid??""}`))}},[e]),[c,m]=b.useState(0),p=Math.min(c,l.length-1);l[p];const[h,u]=b.useState(new Map);return b.useEffect(()=>{if(!i)return;const f=[...new Set(l.map(y=>y.source_bid).filter(y=>!!y))];if(f.length===0)return;let g=!1;return Promise.all(f.map(y=>i.getItem(y).then(v=>{var w,x;return[y,((x=(w=v==null?void 0:v.authors)==null?void 0:w[0])==null?void 0:x.dynasty)??""]}).catch(()=>[y,""]))).then(y=>{g||u(new Map(y.filter(([,v])=>v)))}),()=>{g=!0}},[i,l]),t.jsx(St,{id:"catalogs",title:o("workPage.sec.catalogs"),meta:t.jsx(vt,{items:[o("workPage.catalog.meta",{n:l.length}),o("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":o("workPage.catalog.tablist"),children:l.map((f,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===p,"aria-label":a(f.source),onClick:()=>m(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:h.get(f.source_bid??"")?a(h.get(f.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...a(f.source)].slice(0,9).map((y,v)=>t.jsx("span",{children:y},v))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d[p].map((f,g)=>t.jsxs("div",{className:"bim-d-lu-entry",children:[f.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(f.title_info)}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[f.source_bid?t.jsx(jt,{id:f.source_bid,label:a(f.source),onNavigate:n,renderLink:r,dense:!0}):a(f.source),f.section?a(f.section):"",f.author_info?`${o("label.authorInfo")} ${a(f.author_info)}`:"",f.edition?`${o("label.edition")} ${a(f.edition)}`:"",f.page??""]}),f.summary&&t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.summary),void 0,{t:o})}),f.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.comment),void 0,{t:o})})]}),f.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.additional_comment),void 0,{t:o})})]}),!f.summary&&!f.comment&&!f.additional_comment&&!f.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:o("workPage.catalog.titleOnly")})]},g)),l.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[p>0?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.prev",{name:a(l[p-1].source)}),onClick:()=>m(p-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(l[p-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[p+1," / ",l.length]}),p<l.length-1?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.next",{name:a(l[p+1].source)}),onClick:()=>m(p+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(l[p+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Cx({workId:e,info:i,transport:n,onNavigate:r,renderLink:o}){const{t:a,convert:l}=oe(),[d,c]=b.useState(1),[m,p]=b.useState(null),[h,u]=b.useState(!1),f=!!(n!=null&&n.getWorkContents);b.useEffect(()=>{if(!(n!=null&&n.getWorkContents))return;let y=!1;return p(null),u(!1),n.getWorkContents(e,d).then(v=>{y||(v?p(v):u(!0))}).catch(()=>{y||u(!0)}),()=>{y=!0}},[n,e,d]);const g=i.pages>1?t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d<=1,onClick:()=>c(y=>y-1),children:a("workPage.contents.prev")}),t.jsx("span",{className:"bim-d-meta",children:a("workPage.contents.page",{page:d,pages:i.pages})}),t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d>=i.pages,onClick:()=>c(y=>y+1),children:a("workPage.contents.next")})]}):null;return t.jsxs(St,{id:"contents",title:a("workPage.sec.contents"),meta:t.jsx(vt,{items:[a("workPage.contents.meta",{n:i.total})]}),children:[f&&g,f&&!m&&!h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.loading")}),f&&h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.error")}),m&&m.length>0&&t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("workPage.contents.vol")}),t.jsx("th",{children:a("workPage.contents.title")}),t.jsx("th",{children:a("workPage.contents.author")})]})}),t.jsx("tbody",{children:m.map((y,v)=>{var j,S;const w=Gr(y.vol),x=v>0?Gr(m[v-1].vol):null;return t.jsxs("tr",{children:[t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w&&w!==x?"":" bim-d-zt-blank"}`,children:w&&w!==x?w:null}),t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:y.id,label:l(y.title??y.id),onNavigate:r,renderLink:o,dense:!0})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${(j=y.au)!=null&&j.length?"":" bim-d-zt-blank"}`,children:(S=y.au)!=null&&S.length?l(y.au.join("、")):null})]},y.id)})})]}),f&&m&&g]})}const Cd=({graph:e,renderLink:i,className:n,style:r})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Wx,...r},className:n,children:o("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const g=l.get(f.target)??[];g.push(f),l.set(f.target,g)}else for(const g of[f.source,f.target]){const y=d.get(g)??[];y.push(f),d.set(g,y)}const c=new Map(e.nodes.map(f=>[f.id,f])),m=new Map,p=[];for(const f of e.nodes)if(f.group){const g=m.get(f.group)??[];g.push(f),m.set(f.group,g)}else p.push(f);const h=(f,g)=>(f.year??9999)-(g.year??9999);m.forEach(f=>f.sort(h)),p.sort(h);const u=e.groups.filter(f=>m.has(f.id));return t.jsxs("div",{className:n,style:{...Rx,...r},children:[e.title&&t.jsx("div",{style:Tx,children:a(e.title)}),e.description&&t.jsx("div",{style:Ix,children:a(e.description)}),u.map(f=>t.jsx(rl,{label:f.label,color:f.color,nodes:m.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i},f.id)),p.length>0&&t.jsx(rl,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},rl=({label:e,color:i,nodes:n,incomingMap:r,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:Mx,children:[t.jsx("div",{style:{...Ax,borderLeftColor:i??s.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(Ex,{node:c,incoming:r.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Ex=({node:e,incoming:i,siblings:n,nodeMap:r,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=oe();return t.jsxs("div",{style:{...Lx,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?s.bim("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Px,children:[t.jsx("span",{style:Ox,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Fx,children:Rl(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Bx,children:[e.category&&t.jsx(Pi,{children:c(e.category)}),e.status==="lost"&&t.jsx(Pi,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Pi,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Pi,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Pi,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Hx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Dx,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:ol,children:[t.jsx("div",{style:al,children:d("lineage.sources")}),i.map(m=>{const p=r.get(m.source);return t.jsxs("div",{style:ll(m.confidence),children:[t.jsx("span",{style:cl,children:c(m.relation)}),t.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&o?o(p.id,c(p.label)):c((p==null?void 0:p.label)??m.source)}),m.confidence!=="consensus"&&m.confidence!=="certain"&&t.jsx(sl,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:dl,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:ol,children:[t.jsx("div",{style:al,children:d("lineage.related")}),n.map(m=>{const p=m.source===e.id?m.target:m.source,h=r.get(p);return t.jsxs("div",{style:ll(m.confidence),children:[t.jsx("span",{style:cl,children:c(m.relation)}),t.jsx("span",{children:(h==null?void 0:h.kind)==="book"&&o?o(h.id,c(h.label)):c((h==null?void 0:h.label)??p)}),t.jsx(sl,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:dl,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Pi=({children:e,tone:i="default"})=>{const r={default:{bg:s.bim("tag-bg"),fg:s.bim("fg")},warn:{bg:s.bim("warn-bg"),fg:s.bim("warn-fg")},info:{bg:s.bim("info-bg"),fg:s.bim("info-fg")}}[i];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},sl=({level:e})=>{const{t:i}=oe(),r={certain:{key:"certain",color:s.bim("confidence-certain")},consensus:{key:"consensus",color:s.bim("confidence-consensus")},probable:{key:"probable",color:s.bim("confidence-probable")},disputed:{key:"disputed",color:s.bim("confidence-disputed")}}[e];return r?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:i(`lineage.confidence.${r.key}`)}):null},Rx={fontSize:"14px",color:s.bim("fg")},Tx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ix={fontSize:"13px",color:s.bim("muted"),marginBottom:"16px",lineHeight:1.6},Mx={marginBottom:"16px"},Ax={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:s.bim("fg")},Lx={border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:s.bim("bg")},Px={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ox={fontSize:"15px",fontWeight:600},Fx={fontSize:"12px",color:s.bim("muted")},Bx={marginBottom:"6px"},Hx={fontSize:"12px",color:s.bim("muted"),margin:"2px 0"},Dx={fontSize:"12px",color:s.bim("muted"),fontStyle:"italic",margin:"4px 0"},ol={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${s.bim("widget-border")}`},al={fontSize:"11px",color:s.bim("muted"),marginBottom:"2px"},ll=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),cl={display:"inline-block",padding:"0 6px",fontSize:"11px",background:s.bim("tag-bg"),color:s.bim("fg"),borderRadius:"3px",marginRight:"6px"},dl={fontSize:"11px",color:s.bim("muted")},Wx={padding:"20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px"},Ed=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[r,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Ux().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:ul,children:n("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:ul,children:[t.jsx("div",{children:ml(n("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:ml(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Kx,{modules:a,selectedNodeId:e,...i})};function ml(e,i){return e.split(/(\{\w+\})/).map((n,r)=>{const o=/^\{(\w+)\}$/.exec(n);return t.jsx(b.Fragment,{children:o&&o[1]in i?i[o[1]]:n},r)})}async function Ux(){try{const[e,i]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let n=!1;try{await import("@xyflow/react/dist/style.css"),n=!0}catch{n=!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:i,cssLoaded:n}}catch{return null}}const Kx=({graph:e,renderLink:i,height:n=600,className:r,style:o,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:m,Handle:p,Position:h,BaseEdge:u,EdgeLabelRenderer:f,getSmoothStepPath:g,dagre:y}=l,v=b.useMemo(()=>({lineage:N=>{var ae,ce,Ee,we;const z=((ae=N.data)==null?void 0:ae.stepPosition)??.85,[C,U,R]=g({sourceX:N.sourceX,sourceY:N.sourceY,sourcePosition:N.sourcePosition,targetX:N.targetX,targetY:N.targetY,targetPosition:N.targetPosition,stepPosition:z,borderRadius:5}),L=!!((ce=N.data)!=null&&ce.isSibling),F=L?U:N.targetX-18,T=L?R:N.targetY-12,Z=(Ee=N.data)==null?void 0:Ee.labelStyle,O=(we=N.data)==null?void 0:we.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:N.id,path:C,style:N.style,markerStart:N.markerStart,markerEnd:N.markerEnd}),N.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${T}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:s.bim("bg"),border:`0.5px solid ${s.bim("widget-border")}`,...O,...Z},children:N.label})})]})}}),[u,f,g]),w=b.useMemo(()=>({version:N=>{const{t:z}=oe(),C=N.data,U=C.kind==="hypothetical",R=C.status==="lost",L=C.isSelected,F=C.bridge,T=C.borderColor??s.bim("muted"),Z=F||U?"dashed":"solid",O=F?.5:R?.6:1;return t.jsxs("div",{style:{background:F?s.bim("bg-subtle"):s.bim("bg"),border:`2px ${Z} ${L?s.bim("primary"):T}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:L?s.bim("shadow-node-selected"):U||F?"none":s.bim("shadow-node")},title:F?z("lineage.bridgeTitle"):void 0,children:[t.jsx(p,{type:"target",position:h.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:U||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.2},children:Rl(C.yearText,void 0,C.uncertain)}),R&&t.jsx("div",{style:{fontSize:9,color:s.bim("lost-fg"),marginTop:1},children:z("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=oe(),{rfNodes:j,rfEdges:S}=b.useMemo(()=>Yx(e,y,i,a,x),[e,y,i,a,x]);return t.jsx("div",{style:{width:"100%",height:n,...o},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:v,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(m,{showInteractive:!1})]})})};function Yx(e,i,n,r,o=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new i.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const m=new Map(e.groups.map(w=>[w.id,w.color??s.bim("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(p.has(w.relation)||c.setEdge(w.source,w.target));i.layout(c);const h=e.nodes.map(w=>{const x=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:o(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:o(w.year_text??Vx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?m.get(w.group):void 0,renderLink:n,isSelected:j,description:o(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:S,draggable:!1,selected:j}}),u=.78,f=.06,g=new Map;for(const w of e.edges)w.kind==="derive"&&(g.has(w.source)||g.set(w.source,[]),g.get(w.source).push(w));const y=new Map;for(const[w,x]of g){if(x.length<=1)continue;const j=[...x].sort(($,N)=>{var U,R;const z=((U=c.node($.target))==null?void 0:U.y)??0,C=((R=c.node(N.target))==null?void 0:R.y)??0;return z-C}),S=j.length;j.forEach(($,N)=>{const z=(N-(S-1)/2)*f;y.set($.id,u+z)})}const v=e.edges.map(w=>Gx(w,y.get(w.id),o));return{rfNodes:h,rfEdges:v}}function Gx(e,i,n=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=qx(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:n(e.relation),data:{labelStyle:{color:s.bim("fg")},isSibling:o,stepPosition:i},style:{stroke:a,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:o?l:void 0,zIndex:1e3}}function Vx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function qx(e){switch(e){case"certain":return s.bim("confidence-certain");case"consensus":return s.bim("lineage-edge-consensus");case"probable":return s.bim("confidence-probable");case"disputed":return s.bim("confidence-disputed");default:return s.bim("muted")}}const ul={padding:"40px 20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px",border:`1px dashed ${s.bim("widget-border")}`,borderRadius:8,background:s.bim("bg")},lo=({graph:e,defaultMode:i="list",renderLink:n,graphHeight:r=600,selectedNodeId:o,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:m,className:p,style:h})=>{var S;const{t:u,convert:f}=oe(),[g,y]=b.useState(i),v=$=>{y($),a==null||a($)},w=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:s.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:p,style:h,children:[t.jsxs("div",{style:Xx,children:[t.jsx("button",{onClick:()=>v("list"),style:Hr(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>v("graph"),style:Hr(g==="graph"),children:u("lineage.modeGraph")}),x&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:s.bim("muted"),marginRight:4},children:u("lineage.collectionLabel")}),w.map(([$,N])=>{const z=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Hr(l===$),title:N.description?f(N.description):void 0,children:[f(N.label),z!=null?` ${z}`:""]},$)})]})]}),x&&j&&t.jsx("div",{style:{fontSize:12,color:s.bim("muted"),marginBottom:8,padding:"4px 8px",background:s.bim("bg-subtle"),borderRadius:4},children:f(j)}),g==="list"?t.jsx(Cd,{graph:e,renderLink:n}):t.jsx(Ed,{graph:e,renderLink:n,height:r,selectedNodeId:o})]})},Xx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Hr=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${s.bim("widget-border")}`,borderRadius:4,background:e?s.bim("primary"):"transparent",color:e?s.bim("primary-fg"):s.bim("fg"),cursor:"pointer"}),pl=40,bl=2,Jx=9,Zx=new Set(["certain","consensus","probable","disputed"]);function Dr(e){if(!e)return["",""];const i=e.split(/[  ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const Rd=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Oe,Je,Pe,Ue,nt,Y,M,k,P,q;const h=s.useT(),{t:u,convert:f}=oe(),[g,y]=b.useState(null),[v,w]=b.useState(new Map),[x,j]=b.useState([]),[S,$]=b.useState(new Map),[N,z]=b.useState(!1),[C,U]=b.useState("flow"),[R,L]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let _=!1;return i.getItem(e.work_id).then(le=>{!_&&le&&le.type==="work"&&y(le)}).catch(()=>{}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){L(null);return}let _=!1;return i.getLineageGraph(e.work_id).then(le=>{_||L(le&&le.nodes.length>1?le:null)}).catch(()=>{_||L(null)}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{const _=e._collections||[];if(!i||_.length===0){w(new Map);return}let le=!1;return Promise.all(_.map(H=>{const he=H.id;return i.getItem(he).then(xe=>[he,xe]).catch(()=>[he,null])})).then(H=>{if(le)return;const he=new Map;for(const[xe,Re]of H)Re&&he.set(xe,Re);w(he)}),()=>{le=!0}},[i,e._collections]);const F=b.useMemo(()=>{const _=new Set([...g?Ss(g):[],...wu(e)]);return _.add(e.id),[..._]},[g,e.related_books,e.id]),T=F.length-1;b.useEffect(()=>{if(!i||T<=0){j([]);return}const _=F.length<=pl,le=_?F:F.slice(0,8);let H=!1;return Promise.all(le.map(he=>he===e.id?Promise.resolve({id:he,title:e.title,edition:e.edition,year:Mn(e)}):i.getItem(he).then(xe=>{const Re=xe??{};return{id:he,title:Re.title,edition:Re.edition,year:xe?Mn(Re):void 0}}).catch(()=>({id:he})))).then(he=>{if(H)return;const xe=he.filter(Re=>Re.id===e.id||Re.title||Re.edition);_&&xe.sort((Re,Ze)=>(Re.year??1/0)-(Ze.year??1/0)),j(xe)}),()=>{H=!0}},[i,F,T,e]),e.lineage;const Z=b.useMemo(()=>[...Vt(e).filter(_=>_.ref_type==="book").map(_=>_.ref),...ti(e).map(_=>_.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||Z.length===0){$(new Map);return}let _=!1;return Promise.all(Z.map(le=>i.getItem(le).then(H=>[le,{id:le,title:H==null?void 0:H.title,edition:H==null?void 0:H.edition}]).catch(()=>[le,{id:le}]))).then(le=>{_||$(new Map(le))}),()=>{_=!0}},[i,Z]);const O=b.useMemo(()=>$d(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),ae=O.groups.reduce((_,le)=>_+le.rows.length+le.mirrors.length,0),ce=O.groups.length>0&&O.groups.every(_=>_.key==="_physical"),Ee=Ji(e),we=Wl(e),ye=qt(e,h.unit.juan),Q=new Set((e._collections||[]).map(_=>Wi(_.vol).length).filter(_=>_>0)),Ne=_=>{var he;const le=(he=e.base_edition)==null?void 0:he.find(xe=>xe.book_id===_&&xe.name);if(le!=null&&le.name)return le.name;const H=S.get(_);return(H==null?void 0:H.edition)||(H==null?void 0:H.title)||""},W=b.useMemo(()=>{var He,ct;const _=[];we&&_.push({label:u("bookPage.fact.editionType"),value:f(we),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(He=e.publication_info)!=null&&He.details?_.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(Ee.era||Ee.reign)&&_.push({label:u("bookPage.fact.era"),value:f([Ee.era,Ee.reign].filter(Boolean).join(" ")),title:Ee.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),ye&&_.push({label:u("bookPage.fact.measure"),value:f(ye)});const le=(e._collections||[]).flatMap(Be=>Wi(Be.vol));le.length&&_.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Yn(le,h.unit.volume),unit:h.unit.volume,n:le.length})});const H=Vt(e).find(Be=>Be.relation==="底本"&&Be.ref_type==="book");H&&Ne(H.ref)&&_.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(jt,{id:H.ref,label:f(Ne(H.ref)),onNavigate:n,renderLink:r,dense:!0})});const he=(e.base_edition||[]).filter(Be=>Be&&Be.name);for(const Be of["底本","配補","參校"]){if(Be==="底本"&&H&&Ne(H.ref))continue;const ee=he.filter(Se=>Se.role===Be);ee.length&&_.push({label:f(Be),value:ee.map((Se,et)=>t.jsxs(b.Fragment,{children:[et>0&&"、",Se.book_id?t.jsx(jt,{id:Se.book_id,label:f(Se.name),onNavigate:n,renderLink:r,dense:!0}):f(Se.name)]},et))})}const xe=(e.provenance||[]).filter(Be=>Be&&Be.institution),Re=(e.resources||[]).filter(Be=>s.getResourceTypes(Be).includes("physical"));if(xe.length){_.push({label:u("bookPage.fact.holdings"),value:xe.slice(0,2).map(Se=>f(Se.institution)).join("、")+(xe.length>2?u("bookPage.andMorePlaces",{n:xe.length}):"")});const Be=xe.filter(Se=>Se.call_number).slice(0,2).map(Se=>`${f(Se.institution)} ${Se.call_number}`);Be.length&&_.push({label:u("bookPage.fact.callNumber"),value:Be.join(";")+(xe.filter(Se=>Se.call_number).length>2?"…":"")});const ee=xe.flatMap(Se=>Se.seals||[]).filter(Boolean);ee.length&&_.push({label:u("bookPage.fact.seals"),value:f(ee.join("、"))})}else Re.length&&_.push({label:u("bookPage.fact.holdings"),value:Re.slice(0,2).map(Be=>f(Be.name)).join("、")+(Re.length>2?u("bookPage.andMorePlaces",{n:Re.length}):"")});const Ze=e.physical_description;if(Ze){const Be=[[u("bookPage.fact.leafStyle"),Ze.leaf_style],[u("bookPage.fact.binding"),Ze.binding],[u("bookPage.fact.dimensions"),Ze.dimensions],[u("bookPage.fact.condition"),Ze.condition]];for(const[ee,Se]of Be)Se&&Se.trim()&&_.push({label:ee,value:f(Se)})}(ct=e.page_count)!=null&&ct.description&&_.push({label:h.label.pageCount,value:f(e.page_count.description)});const Me=Ic(e.additional_titles);return Me.length&&_.push({label:u("bookPage.fact.aliases"),value:Me.map(f).join("、")}),_},[e,f,h,u,Ee,we,ye,S,n,r]),je=f(e.title),K=e.edition?f(e.edition):void 0,V=((Oe=e.dating)==null?void 0:Oe.text)||"",re=t.jsx(tn,{kind:u("bookPage.kind"),title:je,subtitle:K,byline:t.jsx(oo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:r}),meta:(()=>{const _=[we?f(we):"",Ee.era?f([Ee.era,Ee.reign].filter(Boolean).join("")):"",ye?f(ye):""].filter(Boolean);return _.length?t.jsx("span",{className:"bim-d-tags",children:_.map((le,H)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(H,2)}`,children:le},H))}):null})(),description:(Je=e.description)!=null&&Je.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Pe=e.description)==null?void 0:Pe.text)?6:void 0,facts:W,readAction:o,secondaryAction:o&&ae>0&&!ce?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),X=e._collections||[],I=(a==null?void 0:a.chapters)||[],ue=f(I[0]&&Dr(I[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),fe=u("bookPage.chapterCount",{n:I.length,unit:ue}),ze=!!(Vt(e).length||ti(e).length||(Ue=e.appendix)!=null&&Ue.length),B=[],pe=u(ce?"bookPage.sec.physical":"bookPage.sec.images");(I.length||O.text.length||l)&&B.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:I.length?fe:void 0}),O.groups.length&&B.push({id:"images",label:pe,count:ae}),ze&&B.push({id:"lineage",label:u("bookPage.sec.lineage")}),X.length&&B.push({id:"collections",label:u("section.containedIn"),count:X.length}),(nt=e.location_history)!=null&&nt.length&&B.push({id:"provenance",label:u("section.locationHistory")});const Te=_=>(d==null?void 0:d(_))??null,ve=I[0],Ve=ve?Te(ve.file):null,qe=N?I:I.slice(0,Jx),Xe=(_,le,H)=>_?t.jsx("a",{className:H,href:_.href??"#",onClick:_.onClick?he=>{he.metaKey||he.ctrlKey||(he.preventDefault(),_.onClick())}:void 0,children:le}):t.jsx("span",{className:H,children:le}),J=t.jsxs(t.Fragment,{children:[(I.length>0||O.text.length>0||l)&&t.jsxs(St,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:I.length>0?t.jsx(vt,{items:[fe,(Y=a==null?void 0:a.source)!=null&&Y.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!ve&&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"})]}),ve&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Dr(ve.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((ve.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),Xe(Ve,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),I.length>1&&t.jsx("ul",{className:"bim-d-chap",children:qe.map(_=>{const[le,H]=Dr(_.title);return t.jsx("li",{children:Xe(Te(_.file),t.jsxs(t.Fragment,{children:[le&&t.jsx("b",{children:f(le)}),f(H||_.file)]}))},_.file)})}),I.length>qe.length&&t.jsx(Ts,{label:u("detail.expandRest",{n:I.length-qe.length,unit:ue}),onClick:()=>z(!0)}),O.text.length>0&&t.jsxs(t.Fragment,{children:[(I.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:O.text.map((_,le)=>t.jsx(ao,{item:_,siblings:O.text,listedVolumeCounts:Q},`${_.id||_.url||_.name}-${le}`))})})]})]}),O.groups.length>0&&t.jsx(St,{id:"images",title:pe,meta:t.jsx(vt,{items:[O.groups.length>1?u("bookPage.groupCount",{n:O.groups.length}):"",u("bookPage.placeCount",{n:ae})]}),children:t.jsx(Nd,{groups:O.groups,listedVolumeCounts:Q})}),ze&&t.jsx(St,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Vt(e).length?u("bookPage.lineageMeta"):void 0,action:R?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":C==="flow",onClick:()=>U("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>U("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&R?t.jsx(lo,{graph:R,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(_,le)=>t.jsx(jt,{id:_,label:f(le),onNavigate:n,renderLink:r,dense:!0})}):t.jsx(e0,{data:e,heading:K||je,yearText:V,refName:Ne,onNavigate:n,renderLink:r})}),X.length>0&&t.jsx(St,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:X.map((_,le)=>{const H=_.id,he=Wi(_.vol),xe=v.get(H),Re=Gu(xe);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:H,label:xe?f(xe.title):H,onNavigate:n,renderLink:r,dense:!0}),he.length>0&&t.jsx(Qx,{volumes:he,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Re?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Re>0&&u("bookPage.totalOf",{n:Re,unit:h.unit.bu})})]},`${H}-${le}`)})})})}),(M=e.location_history)!=null&&M.length?t.jsx(St,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((_,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(_.name||_.location||"")}),([_.start_date,_.end_date].filter(Boolean).join("—")||_.description||_.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[_.start_date,_.end_date].filter(Boolean).join("—"),_.description?f(_.description):"",_.note?f(_.note):""]})})]},le))})}):null,B.length===0&&t.jsx(St,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),ie=x.findIndex(_=>_.id===e.id),me=F.length<=pl,se=me&&ie>=0?x.slice(Math.max(0,ie-bl),ie+bl+1):x.filter(_=>_.id!==e.id),de=t.jsxs(t.Fragment,{children:[g&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:f(h.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(jt,{id:g.id,label:f(g.title),onNavigate:n,renderLink:r})}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(_=>`${_.dynasty?`〔${f(_.dynasty)}〕`:""}${f(_.name)}`),f(qt(g,h.unit.juan)),g._edition_count??((k=g._books)==null?void 0:k.length)?u("bookPage.editionCount",{n:g._edition_count??((P=g._books)==null?void 0:P.length)??0}):""]}),((q=g.description)==null?void 0:q.text)&&t.jsx("p",{style:{fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc bim-d-side-desc",children:f(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),T>0&&se.length>0&&t.jsxs("div",{children:[t.jsx(mi,{id:"siblings",timeline:!0,title:me?u("bookPage.siblings"):h.relation.siblingVersions,meta:me?u("bookPage.byEra"):u("bookPage.kindCount",{n:T}),cap:se.length,items:se.map(_=>_.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(_.edition||_.title||_.id)}):t.jsx(jt,{id:_.id,label:f(_.edition||_.title||_.id),onNavigate:n,renderLink:r,dense:!0})),metas:se.map(_=>[_.year!=null?_.year<0?u("detail.bce",{n:-_.year}):String(_.year):"",_.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:se.findIndex(_=>_.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(jt,{id:g.id,label:u("bookPage.viewAllInWork",{n:F.length}),onNavigate:n,renderLink:r,dense:!0})})]})]}),ge=e.work_id?t.jsx(jc,{caption:h.section.belongsToWork,children:t.jsx(jt,{id:e.work_id,label:g?f(g.title):" ",onNavigate:n,renderLink:r,dense:!0})}):void 0;return t.jsx(Zi,{railTop:c,back:m,up:ge,nav:B,railLinks:p,main:J,card:re,side:de})};function Qx({volumes:e,unit:i}){const{t:n}=oe();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Yn(e,i),unit:i}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),n("bookPage.volumeCount",{n:e.length,unit:i})]})]})}function e0({data:e,heading:i,yearText:n,refName:r,onNavigate:o,renderLink:a}){var w;const{t:l,convert:d}=oe(),c=e.lineage,m=Vt(e),p=m.filter(x=>x.ref_type!=="book"),h=m.filter(x=>x.ref_type==="book"&&x.relation==="底本"),u=m.filter(x=>x.ref_type==="book"&&x.relation!=="底本"),f=ti(e),g=m.length>0||f.length>0,y=x=>x&&Zx.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",v=(x,j)=>t.jsx(jt,{id:x,label:d(j||x),onNavigate:o,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[p.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:x.relation?d(x.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),x.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(x.evidence),y(x.confidence)]})]})},`a-${j}`)),h.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:i}),n&&t.jsx("span",{className:"bim-d-lf-yr",children:d(n)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((x,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},j))})]}),f.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((x,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[v(x.book_id,r(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((x,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(x.title)]}),t.jsx(zi,{text:x.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Oi=16,t0=200,i0=16,Td=({data:e,catalog:i,transport:n,onNavigate:r,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var me,se,de,ge,Oe,Je,Pe,Ue,nt;const{t:m,convert:p,messages:h}=oe(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[v,w]=b.useState(null),[x,j]=b.useState(""),[S,$]=b.useState(!1),N=b.useMemo(()=>Dl(e,i),[e,i]),z=b.useMemo(()=>Hl(e),[e]),[C,U]=b.useState(new Map),R=!!n&&N.rows.length>0&&N.rows.length<=t0,L=R&&(N.rows.length<=Oi||S),F=L&&N.rows.every(Y=>!Y.id||C.has(Y.id)),T=Y=>{var M;return us(Y?(M=C.get(Y))==null?void 0:M.l1:void 0)},Z=b.useMemo(()=>{const Y=u.trim(),M=Y?p(Y):"";return N.rows.filter(k=>{var q,_;if(x&&us(k.id?(q=C.get(k.id))==null?void 0:q.l1:void 0)!==x)return!1;if(!M)return!0;const P=k.id&&((_=C.get(k.id))==null?void 0:_.title)||k.title;return p(P).includes(M)||(k.subItems||[]).some(le=>p(le).includes(M))})},[N.rows,u,x,C,p]),O=g?Z:Z.slice(0,Oi),ae=b.useMemo(()=>(L?N.rows:O).filter(Y=>Y.id&&!C.has(Y.id)).map(Y=>Y.id),[L,N.rows,O,C]);b.useEffect(()=>{if(!n||ae.length===0)return;let Y=!1;const M=ae.slice(0,i0);return tr(M,er,k=>n.getItem(k).then(P=>{var le,H;const q=P??{},_={title:q.title,edition:q.edition,authors:q.authors,measure:P?qt(P,h.unit.juan):void 0,versionCount:q._edition_count??((le=q._books)==null?void 0:le.length),l1:((H=$s(q))==null?void 0:H.l1)||void 0};return[k,_]}).catch(()=>[k,{}]),()=>Y).then(k=>{Y||U(P=>{const q=new Map(P);for(const[_,le]of k)q.set(_,le);return q})}),()=>{Y=!0}},[n,ae,h.unit.juan]);const ce=(me=(e.contained_in||[])[0])==null?void 0:me.id;b.useEffect(()=>{if(!ce){w(null);return}if(w({id:ce}),!n)return;let Y=!1;return n.getItem(ce).then(M=>{Y||w({id:ce,title:M==null?void 0:M.title})}).catch(()=>{}),()=>{Y=!0}},[n,ce]);const Ee=b.useMemo(()=>$d(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),we=Ee.text.length+Ee.groups.reduce((Y,M)=>Y+M.rows.length+M.mirrors.length,0),ye=z.works,Q=new Set(N.rows.map(Y=>Y.id).filter(Boolean)),Ne=ye.length>0&&!ye.every(Y=>Q.has(Y.id)),W=(()=>{const Y=N.rows.map(M=>M.edition).filter(Boolean);return Y.length>1&&new Set(Y).size===1})(),je=N.rows.some(Y=>Y.volumes.length>0||Y.expected!=null),K=z.total,V=z.truncated?K:N.rows.length,re=qt(e,h.unit.juan),X=e.count,I=Y=>typeof Y=="number"&&Number.isFinite(Y)?Y:null,ue=I(X==null?void 0:X.juan)??I((se=e.juan_count)==null?void 0:se.number)??I((ge=(de=e.measures)==null?void 0:de.find(Y=>(Y==null?void 0:Y.unit)==="卷"))==null?void 0:ge.number),fe=I(X==null?void 0:X.ce)??(N.totalVolumes||null),ze=[{value:V,label:m("collectionPage.stat.titles")},{value:ue??0,label:h.unit.juan},{value:fe??0,label:h.unit.volume}],B=b.useMemo(()=>{var k,P;const Y=[];if((k=e.publication_info)!=null&&k.details&&Y.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),K&&(K!==N.rows.length||z.truncated)){const q=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");Y.push({label:q,value:`${K} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const M=[I(X==null?void 0:X.zhong)!=null?m("collectionPage.nZhong",{n:X.zhong}):"",I(X==null?void 0:X.han)!=null?m("collectionPage.nHan",{n:X.han}):""].filter(Boolean);return M.length&&Y.push({label:m("collectionPage.fact.expected"),value:M.join(" ")}),ue==null&&re&&Y.push({label:m("collectionPage.fact.measure"),value:p(re),title:(P=e.juan_count)!=null&&P.description?p(e.juan_count.description):void 0}),Y},[e,K,z.truncated,N.rows.length,ue,re,X,p,m,h]),pe=b.useMemo(()=>{if(!F)return[];const Y=new Map;for(const k of N.rows){const P=T(k.id);P&&Y.set(P,(Y.get(P)??0)+1)}const M=Yi.filter(k=>(Y.get(k.key)??0)>0);return M.length<2?[]:[{key:"",label:`${h.catalog.all} ${V}`},...M.map(k=>({key:k.key,label:`${k.label} ${Y.get(k.key)}`}))]},[F,N.rows,C,h]),Te=b.useMemo(()=>{if(!F||!N.rows.some(P=>P.volumes.length>0))return null;const Y=[],M=N.rows.filter(P=>P.volumes.length>0).map(P=>({k:T(P.id)??"",from:Math.min(...P.volumes),to:Math.max(...P.volumes)})).sort((P,q)=>P.from-q.from);for(const P of M){const q=P.to-P.from+1,_=Y[Y.length-1];_&&_.key===P.k?(_.to=Math.max(_.to,P.to),_.n+=q):Y.push({key:P.k,from:P.from,to:P.to,n:q})}const k=M.reduce((P,q)=>Math.max(P,q.to),0);return Y.length>1&&Y.some(P=>P.key)?{segs:Y,last:k}:null},[F,N.rows,C]),ve=(Oe=e.description)==null?void 0:Oe.text,Ve=t.jsx(tn,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:r,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(Je=e.publication_info)!=null&&Je.year?p(e.publication_info.year):""]}),description:ve||(Pe=e.history)!=null&&Pe.length?t.jsxs(t.Fragment,{children:[ve&&t.jsx(zi,{text:ve,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((Y,M)=>t.jsx("li",{children:p(Y)},M))}):null]}):void 0,clampDescription:Is(ve)||(((nt=e.history)==null?void 0:nt.length)??0)>2?6:void 0,stats:ze,facts:B,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:Te&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:m("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":m("collectionPage.dist.head"),children:Te.segs.map((Y,M)=>{const k=Yi.find(P=>P.key===Y.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!k,title:k?m("collectionPage.dist.segTitle",{section:p(k.label),from:Y.from,to:Y.to}):void 0,"aria-label":k?m("collectionPage.dist.only",{section:p(k.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!k&&x===Y.key,style:{flexGrow:Y.n,background:k?s.bim(k.token):s.bim("rule")},onClick:()=>{k&&(j(x===Y.key?"":Y.key),y(!1))}},M)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:m("catalog.volume",{n:1})}),t.jsx("span",{children:m("collectionPage.dist.hint")}),t.jsx("span",{children:m("catalog.volume",{n:Te.last})})]})]})}),qe=[];N.rows.length&&qe.push({id:"titles",label:m("collectionPage.sec.titles"),count:V}),we&&qe.push({id:"resources",label:m("collectionPage.sec.resources"),count:we}),Ne&&qe.push({id:"works",label:h.section.containedWorks,count:ye.length});const Xe=t.jsxs(t.Fragment,{children:[N.rows.length>0&&t.jsxs(St,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${V} ${h.unit.items}`,N.totalVolumes?m("collectionPage.totalVolumes",{n:N.totalVolumes,unit:h.unit.volume}):"",Z.length!==V?m("collectionPage.currentN",{n:Z.length,unit:h.unit.items}):""]}),action:a,children:[(N.rows.length>Oi||pe.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[pe.length>0&&t.jsx(Qi,{items:pe,value:x,onChange:Y=>{j(Y),y(!1)}}),R&&N.rows.length>Oi&&!F&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>$(!0),title:m("collectionPage.loadAllTitle",{n:N.rows.length,unit:h.unit.items}),children:m(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),N.rows.length>Oi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:Y=>{f(Y.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(Z.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[je&&t.jsx("th",{style:{width:"8.5em"},children:m("collectionPage.col.volumes")}),t.jsx("th",{children:m("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:m("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:O.map((Y,M)=>{var he;const k=Y.id?C.get(Y.id):void 0,P=k!=null&&k.title&&Y.title===Y.id?k.title:Y.title,q=((k==null?void 0:k.authors)||[]).find(xe=>xe&&xe.name),_=[q?`${q.dynasty?`〔${p(q.dynasty)}〕`:""}${p(q.name)}${q.role?` ${p(q.role)}`:""}`:"",k!=null&&k.measure?p(k.measure):"",(he=Y.subItems)!=null&&he.length?Y.subItems.map(xe=>p(xe)).join("、"):"",(k!=null&&k.edition||Y.edition)&&!W?p((k==null?void 0:k.edition)||Y.edition||""):""].filter(Boolean),le=Yi.find(xe=>xe.key===T(Y.id)),H=Y.volumes.length>0?m("collectionPage.volumeRange",{range:Yn(Y.volumes,h.unit.volume),unit:h.unit.volume}):Y.expected!=null?`${Y.found??0}/${Y.expected} ${h.unit.volume}`:"";return t.jsxs("tr",{children:[je&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H?"":" bim-d-zt-blank"}`,children:[le&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:s.bim(le.token)}}),H||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[Y.id?t.jsx(jt,{id:Y.id,label:p(P),onNavigate:r,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(P)}),_.length>0?t.jsx(vt,{items:_}):Y.id&&!k&&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${k!=null&&k.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:k!=null&&k.versionCount?m("collectionPage.nZhong",{n:k.versionCount}):""})]},`${Y.id??Y.title}-${M}`)})})]}),O.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:m("catalog.noMatch")}),!g&&t.jsx(Jn,{total:Z.length,shown:O.length,unit:h.unit.items,onClick:()=>y(!0)})]}),we>0&&t.jsxs(St,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:we}),children:[Ee.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[Ee.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:m("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Ee.text.map((Y,M)=>t.jsx(ao,{item:Y,siblings:Ee.text},`${Y.id||Y.url||Y.name}-${M}`))})})]}),t.jsx(Nd,{groups:Ee.groups})]}),N.rows.length===0&&we===0&&t.jsx(St,{title:m("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("collectionPage.empty")})})]}),J=Ne?t.jsx(mi,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:ye.length}),cap:12,items:ye.map(Y=>t.jsx(jt,{id:Y.id,label:p(Y.title),onNavigate:r,renderLink:o,dense:!0}))}):null,ie=v?t.jsx(jc,{caption:m("collectionPage.parent"),children:t.jsx(jt,{id:v.id,label:p(v.title||v.id),onNavigate:r,renderLink:o,dense:!0})}):void 0;return t.jsx(Zi,{railTop:l,back:d,up:ie,nav:qe,railLinks:c,main:Xe,card:Ve,side:J})},n0=8;function Id(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function r0(e){return(e||[]).filter(i=>{var n,r;return Id(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((r=i.license)==null?void 0:r.trim())}).slice(0,n0)}function s0({images:e,assetBase:i,name:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?r0(e):[];if(!i||d||m.length===0)return null;const p=i.endsWith("/")?i:i+"/",h=m[Math.min(a,m.length-1)],u=h.width&&h.height&&h.width>0&&h.height>0?`${h.width} / ${h.height}`:void 0,f=g=>p+Id(g.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:f(h),alt:r("entityPage.sealAlt",{name:n})+(m.length>1?` ${a+1}`:""),style:u?{"--seal-ar":u}:void 0,width:h.width,height:h.height,decoding:"async",fetchPriority:"high",onError:()=>c(!0)},h.file),m.length>1&&t.jsx("div",{className:"bim-d-seal-thumbs",children:m.map((g,y)=>t.jsx("button",{type:"button","aria-pressed":y===a,"aria-label":`${r("entityPage.sealAlt",{name:n})} ${y+1}`,onClick:()=>l(y),children:t.jsx("img",{src:f(g),alt:"",loading:"lazy",decoding:"async"})},g.file))}),t.jsxs("figcaption",{children:[r("entityPage.imgCredit",{credit:o(h.credit)})," · ",r("entityPage.imgLicense",{license:o(h.license)}),h.source_url&&/^https?:\/\//i.test(h.source_url)&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:h.source_url,target:"_blank",rel:"noopener noreferrer nofollow",children:r("entityPage.imgSource")})]}),h.note&&t.jsxs(t.Fragment,{children:[" · ",o(h.note)]})]})]})}const hl=8,fl=10,gl=30,Md=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function o0(e){return`${Md(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function a0(e,i,n){var r;return`${Md(i,n.key,n.chapter)}#e=${((r=n.ids)!=null&&r.length?n.ids:[e]).join(",")}`}const l0=({id:e,transport:i,renderLink:n,onTotal:r})=>{const{t:o,convert:a}=oe(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(hl),[u,f]=b.useState(fl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),v=b.useRef(r);if(v.current=r,b.useEffect(()=>{if(d(null),m("idle"),h(hl),f(fl),!y)return;const $=g.current;let N=!1;const z=()=>{m("loading"),i.getMentions(e).then(U=>{var L,F;if(N)return;const R=U&&"books"in U?U:null;if(!R||!R.total){m("none"),(L=v.current)==null||L.call(v,0);return}d(R),m("ok"),(F=v.current)==null||F.call(v,R.total)}).catch(()=>{N||m("none")})};if(!$||typeof IntersectionObserver>"u")return z(),()=>{N=!0};const C=new IntersectionObserver(U=>{U.some(R=>R.isIntersecting)&&(C.disconnect(),z())},{rootMargin:"400px"});return C.observe($),()=>{N=!0,C.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const w=($,N,z)=>n?n($,N,z):t.jsx("a",{className:z,href:$,children:N}),x=new Map(((l==null?void 0:l.books)??[]).map($=>[$.item,$.title])),j=(l==null?void 0:l.examples)??[],S=(l==null?void 0:l.books)??[];return t.jsx("div",{ref:g,children:t.jsxs(St,{id:"mentions",title:o("mentions.title"),meta:l?t.jsx(vt,{items:[o("mentions.total",{n:l.total,b:S.length})]}):void 0,children:[!l&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:o("mentions.loading")}),l&&t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:o("mentions.hint")}),l&&j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.examples")}),t.jsx("ol",{className:"bim-d-mentions",children:j.slice(0,p).map(($,N)=>{const z=[x.get($.item),$.heading].filter(Boolean).map(U=>a(U)).join(" · "),C=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-mention-where bim-d-ui",children:z||$.chapter}),t.jsxs("span",{className:"bim-d-mention-ctx",children:[$.before?"…":"",a($.before),t.jsx("b",{children:a($.text)}),a($.after),$.after?"…":""]})]});return t.jsx("li",{children:w(o0($),C,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${N}`)})}),j.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(j.length),children:o("mentions.more",{n:j.length-p})})]}),l&&S.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.byBook")}),t.jsx("ul",{className:"bim-d-mbooks",children:S.slice(0,u).map($=>t.jsx(c0,{entityId:e,book:$,open:S.length===1,transport:i,link:w},$.item))}),S.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+gl),children:o("mentions.moreBooks",{n:Math.min(gl,S.length-u)})})]})]})})},c0=({entityId:e,book:i,open:n,transport:r,link:o})=>{const{t:a,convert:l}=oe(),[d,c]=b.useState(i.chapters??null),[m,p]=b.useState(!1);b.useEffect(()=>{c(i.chapters??null)},[i]);const h=u=>{!u.currentTarget.open||d||m||!(r!=null&&r.getMentions)||(p(!0),r.getMentions(e,i.item).then(f=>{f&&"chapters"in f&&Array.isArray(f.chapters)&&c(f.chapters)}).catch(()=>{}).finally(()=>p(!1)))};return t.jsx("li",{children:t.jsxs("details",{className:"bim-d-mbook",open:n,onToggle:h,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"bim-d-mbook-t",children:l(i.title??i.item)}),t.jsx("span",{className:"bim-d-mbook-n bim-d-ui",children:a("mentions.bookLine",{n:i.count,c:i.chapter_count})})]}),m&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"0 0 8px 40px"},children:a("mentions.loading")}),d&&t.jsx("ul",{className:"bim-d-mchaps",children:d.map(u=>t.jsx("li",{children:o(a0(e,i.item,u),t.jsxs(t.Fragment,{children:[t.jsx("span",{children:u.heading?`${u.chapter} · ${l(u.heading)}`:u.chapter}),t.jsx("span",{className:"bim-d-ui",children:a("mentions.chapterLine",{n:u.count})})]}),"bim-d-mchap")},`${u.key}|${u.chapter}`))})]})})},d0=16,m0=30,Wr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function xl(e){if(!e)return Wr.length;const i=Wr.indexOf(e);return i===-1?Wr.length:i}function u0(e,i,n){if(i)return e[i]??n(i)}function p0(e,i){return e==null?"":e<0?i("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]},Ad=({data:e,transport:i,onNavigate:n,renderLink:r,railTop:o,back:a,railLinks:l,assetBase:d})=>{var Je,Pe,Ue,nt,Y,M;const{t:c,convert:m,messages:p}=oe(),h=k=>p0(k,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[v,w]=b.useState("default"),[x,j]=b.useState(new Map),[S,$]=b.useState(0),N=b.useMemo(()=>(e._works||[]).filter(k=>!Qo(k.st)),[e._works]),z=b.useMemo(()=>(e._works||[]).filter(k=>Qo(k.st)),[e._works]),C=b.useMemo(()=>N.map(k=>{const P=x.get(k.work_id);return{id:k.work_id,title:(P==null?void 0:P.title)??k.title??k.work_id,role:k.role||"",cls:ws(k.role),versionCount:P==null?void 0:P.versionCount,section:P==null?void 0:P.cls,l1:P==null?void 0:P.l1,measure:P==null?void 0:P.measure,hasImage:P==null?void 0:P.hasImage,loaded:!!(P!=null&&P.loaded)}}),[N,x]),U=b.useMemo(()=>Bl(N.map(k=>k.role),c("detail.roleAll")),[N,c]),R=b.useMemo(()=>{const k=u==="全部"?C:C.filter(P=>P.cls===u);return v==="versions"?[...k].sort((P,q)=>(q.versionCount??-1)-(P.versionCount??-1)):k},[C,u,v]),L=g?R:R.slice(0,d0),F=b.useMemo(()=>L.filter(k=>!x.has(k.id)).map(k=>k.id),[L,x]);b.useEffect(()=>{if(!i||F.length===0)return;let k=!1;return tr(F,er,P=>i.getItem(P).then(q=>{var xe;const _=q??{},le=_._edition_count??((xe=_._books)==null?void 0:xe.length)??0,H=$s(_),he=[H==null?void 0:H.l1,H==null?void 0:H.l2].filter(Boolean).join(" ");return[P,{id:P,title:_.title,versionCount:le,loaded:!0,cls:he||void 0,l1:(H==null?void 0:H.l1)||void 0,measure:q&&qt(q,p.unit.juan)||void 0,hasImage:!!_._has_image}]}).catch(()=>[P,{id:P,loaded:!0}]),()=>k).then(P=>{k||j(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,F,p.unit.juan]);const T=b.useMemo(()=>{const k=new Map;for(const P of e.alt_names||[]){const q=P.type||p.section.aliases;k.has(q)||k.set(q,[]),k.get(q).push(P.name)}return[...k.entries()].sort((P,q)=>xl(P[0])-xl(q[0])).map(([P,q])=>({label:P,names:q}))},[e.alt_names,p]),Z=((Je=e.dates)==null?void 0:Je.birth)??void 0,O=((Pe=e.dates)==null?void 0:Pe.death)??void 0,ae=(Ue=e.dates)==null?void 0:Ue.floruit,ce=Z!=null||O!=null?`${h(Z)||"?"}—${h(O)||"?"}`:Array.isArray(ae)&&ae.length===2&&ae.every(k=>Number.isFinite(k))?c("entityPage.floruit",{from:h(ae[0]),to:h(ae[1])}):"",Ee=new Set(["本名","字","號","号"]),we=T.filter(k=>Ee.has(k.label)),ye=T.filter(k=>!Ee.has(k.label)),Q=ye.reduce((k,P)=>k+P.names.length,0),Ne=b.useMemo(()=>{const k=[];for(const q of we)k.push({label:q.label,value:q.names.map(_=>m(_)).join("、")});const P=N.length;return P&&k.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:P})}),z.length&&k.push({label:c("entityPage.fact.pieces"),value:c("entityPage.nPian",{n:z.length})}),k},[N,z,we,m,c]),W=k=>{var P;return(P=T.find(q=>k.includes(q.label)))==null?void 0:P.names[0]},je=W(["字"]),K=W(["號","号"]),V=[je?c("entityPage.zi",{name:m(je)}):"",K?c("entityPage.hao",{name:m(K)}):""].filter(Boolean).join(","),re=e.native_place,X=e.dynasty?b0[e.dynasty]:void 0,I=(()=>{if(!X||Z==null||O==null||O<Z)return null;const[k,P]=X,q=Math.max(Z,k),_=Math.min(O,P);if(_<=q)return null;const le=P-k;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:h(Z),death:h(O),years:O-Z+1}),children:t.jsx("i",{style:{left:`${(q-k)/le*100}%`,width:`${(_-q)/le*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${h(k)} ${m(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:O-Z+1})}),t.jsx("span",{children:h(P)})]})]})})(),ue=b.useMemo(()=>{if(!i||C.length===0||C.some(q=>!q.loaded))return null;const k=new Map;for(const q of C){const _=us(q.l1);_&&k.set(_,(k.get(_)??0)+1)}const P=Yi.map(q=>({...q,n:k.get(q.key)??0})).filter(q=>q.n>0);return P.length?P:null},[C,i]),fe=t.jsxs(tn,{kind:u0(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:V||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",ce,re?c("entityPage.nativePlace",{place:m(re)}):""]}),I,t.jsx(s0,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(nt=e.description)!=null&&nt.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Y=e.description)==null?void 0:Y.text)?6:void 0,facts:Ne,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[Q>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:Q})}),t.jsx("dl",{children:ye.map(k=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{children:k.names.map(P=>m(P)).join("、")})]},k.label))})]}),ue&&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:ue.map(k=>t.jsx("i",{style:{flexGrow:k.n,background:s.bim(k.token)}},k.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ue.map(k=>t.jsxs("span",{children:[t.jsx("i",{style:{background:s.bim(k.token)}}),m(k.label)," ",k.n]},k.key))})]})]}),ze=b.useMemo(()=>C.filter(k=>k.loaded&&(k.versionCount??0)>0).sort((k,P)=>(P.versionCount??0)-(k.versionCount??0)).slice(0,3),[C]),B=!!i&&C.length>=3&&L.some(k=>!k.loaded),pe=u==="全部"&&(B||ze.length>=2),Te=e.external_ids||{},ve=((M=e.external_ids_meta)==null?void 0:M.cbdb_match)??Te.cbdb_match,Ve=[];Te.cbdb_id!=null&&Ve.push({label:"CBDB",id:String(Te.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${Te.cbdb_id}`,note:ve==="auto"?c("entityPage.autoMatch"):void 0});const qe=Te.wikidata_id;qe&&Ve.push({label:"Wikidata",id:qe,href:`https://www.wikidata.org/wiki/${qe}`});const Xe=Te.viaf_id;Xe&&Ve.push({label:"VIAF",id:Xe,href:`https://viaf.org/viaf/${Xe}`});const J=U.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),ie=e.id?t.jsx(l0,{id:e.id,transport:i,onTotal:$}):null,me=[...pe&&!B?[{id:"featured",label:c("entityPage.sec.featured"),count:ze.length}]:[],...C.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:C.length}]:[],...z.length?[{id:"pieces",label:c("entityPage.sec.pieces"),count:z.length}]:[],...S?[{id:"mentions",label:c("mentions.title"),count:S}]:[],...Ve.length?[{id:"external",label:c("entityPage.sec.external"),count:Ve.length}]:[]],se=pe?t.jsxs(St,{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":B||void 0,children:[B&&[0,1,2].map(k=>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:" "})]},k)),!B&&ze.map(k=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0})}),t.jsx(vt,{items:[k.section?m(k.section):"",k.measure?m(k.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:k.versionCount}),t.jsx("span",{children:c("entityPage.versionsUnit")}),k.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},k.id))]})]}):null,de=z.length?t.jsx(h0,{pieces:z,onNavigate:n,renderLink:r}):null,ge=C.length===0?t.jsxs(t.Fragment,{children:[de??t.jsx(St,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}),ie]}):t.jsxs(t.Fragment,{children:[se,t.jsxs(St,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:C.length}),R.length!==C.length?c("entityPage.current",{n:R.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[J.length>1&&t.jsx(Qi,{items:J,value:u,onChange:k=>{f(k),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":v==="versions",onClick:()=>{v==="default"&&y(!0),w(k=>k==="default"?"versions":"default")},children:c(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(R.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:L.map(k=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0}),k.measure?t.jsx(vt,{items:[m(k.measure)]}):!k.loaded&&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${k.section||k.loaded?"":" bim-d-zt-blank"}`,children:k.section?m(k.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.role?"":" bim-d-zt-blank"}`,children:k.role?m(k.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.loaded?"":" bim-d-zt-blank"}`,children:k.loaded?k.versionCount?c("entityPage.nZhong",{n:k.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("entityPage.notRecorded")}):""}),t.jsx("td",{className:k.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:k.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("entityPage.hasImage")})})]},k.id))})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx(Jn,{total:R.length,shown:L.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),de,ie]}),Oe=Ve.length>0?t.jsx(mi,{id:"external",title:c("entityPage.sec.external"),items:Ve.map(k=>t.jsxs("a",{href:k.href,target:"_blank",rel:"noopener noreferrer",children:[k.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Ve.map(k=>k.id),foot:Te.cbdb_id!=null&&ve==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Zi,{railTop:o,back:a,nav:me,railLinks:l,main:ge,card:fe,side:Oe})};function h0({pieces:e,onNavigate:i,renderLink:n}){const{t:r,convert:o,messages:a}=oe(),[l,d]=b.useState(""),[c,m]=b.useState(!1),p=g=>g?a.workSubtype[g]??o(g):"",h=b.useMemo(()=>{const g=new Map;for(const y of e)g.set(y.st||"",(g.get(y.st||"")??0)+1);return g.size<2?[]:[{key:"",label:`${r("detail.roleAll")} ${e.length}`},...[...g.entries()].sort((y,v)=>v[1]-y[1]).map(([y,v])=>({key:y,label:`${p(y)} ${v}`}))]},[e,r]),u=l?e.filter(g=>(g.st||"")===l):e,f=c?u:u.slice(0,m0);return t.jsxs(St,{id:"pieces",title:r("entityPage.sec.pieces"),meta:t.jsx(vt,{items:[r("entityPage.nPian",{n:e.length}),u.length!==e.length?r("entityPage.current",{n:u.length}):""]}),children:[h.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(Qi,{items:h,value:l,onChange:g=>{d(g),m(!1)}})}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!c&&en(u.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:r("entityPage.piece.title")}),t.jsx("th",{children:r("entityPage.piece.kind")}),t.jsx("th",{children:r("entityPage.col.role")}),t.jsx("th",{"aria-label":r("entityPage.piece.text")})]})}),t.jsx("tbody",{children:f.map(g=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:g.work_id,label:o(g.title??g.work_id),onNavigate:i,renderLink:n,dense:!0})}),t.jsx("td",{className:"bim-d-zt-sub bim-d-zt-nowrap",children:p(g.st)}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${g.role?"":" bim-d-zt-blank"}`,children:g.role?o(g.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:g.txt?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:g.txt&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:r("entityPage.piece.hasText")})})]},g.work_id))})]}),!c&&t.jsx(Jn,{total:u.length,shown:f.length,unit:r("entityPage.piece.moreUnit"),onClick:()=>m(!0)})]})}const co="(max-width: 719px)",f0=`${co}, (pointer: coarse)`,Ld=`
1560
+ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({key:Ci,data:A,started:!1});else if(A!==Ei.data&&(yo({key:Ci,data:A,started:!!A}),A)){const E=A.pages??[];(!Ei.started||!E.some(G=>G.page===yt))&&bi(ri(A))}b.useEffect(()=>{Ke(new Set),Qe.set(null)},[de,B,Qe]);const dr=Ei.key===Ci&&Ei.started,jo=!!ge&&cs(ge.headings).length===0,ko=b.useMemo(()=>jo&&dr&&A?md(A.pages,A.punctuations):[],[jo,dr,A]),mr=b.useCallback(E=>{const G=cs(E.headings);return G.length>0?G:E.file===de?ko:[]},[de,ko]),Tm=b.useCallback(E=>{if(Ke(new Set(E)),E.length>0){const G=E[0],be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be)}},[]),Dt=b.useMemo(()=>{const E=new Map;for(const G of(A==null?void 0:A.pages)??[])E.set(G.page,G);return E},[A]),Ri=an(A),Ti=b.useCallback(E=>{var ot;const G=te.images;if(!G||G.length===0)return;const be=(ot=Dt.get(E))==null?void 0:ot.seq;return(be?G.find(mt=>mt.seq===be):void 0)??G.find(mt=>mt.pageNo===E)??G[E-1]},[te.images,Dt]),wo=$t>1.5,ln=b.useCallback((E,G=!1)=>{const be=Ti(E);return be?E===Ri||G?be.hiresUrl??be.url:be.url:E===Ri?(A==null?void 0:A.imageUrl)??"":""},[Ti,A,Ri]),Im=b.useMemo(()=>ln(yt,wo),[ln,yt,wo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((E,G)=>E-G),[Dt]),si=b.useRef(yt);si.current=yt;const ur=b.useRef(0),pr=b.useRef({page:null,timer:null}),Mm=b.useCallback(E=>{const G=pr.current;E!==G.page&&(G.timer&&(clearTimeout(G.timer),G.timer=null),G.page=null,!(E===si.current||Date.now()<ur.current)&&(G.page=E,G.timer=setTimeout(()=>{G.timer=null,G.page=null,!(Date.now()<ur.current||si.current===E)&&(si.current=E,bi(E))},yg)))},[]);b.useEffect(()=>()=>{pr.current.timer&&clearTimeout(pr.current.timer)},[]);const cn=b.useCallback(E=>{var G;si.current===E||!Dt.has(E)||(ur.current=Date.now()+1e3,si.current=E,bi(E),(G=Dt.get(E))!=null&&G.columns.some(be=>be.chars.length>0)&&cr(be=>({page:E,nonce:((be==null?void 0:be.nonce)??0)+1})))},[Dt]),Ii=b.useCallback(E=>{const G=si.current,be=Wt.indexOf(G),ot=Wt[be<0?0:be+E];ot===void 0||ot===G||cn(ot)},[Wt,cn]),vo=b.useCallback(E=>{if(!E.trim().match(/^\d+$/)||Wt.length===0)return null;const be=parseInt(E.trim(),10),ot=Number.isFinite(be)?be:Number.MAX_SAFE_INTEGER;return Wt.reduce((mt,_t)=>Math.abs(_t-ot)<Math.abs(mt-ot)?_t:mt,Wt[0])},[Wt]),[br,hr]=b.useState(null),dn=b.useRef(null),Am=b.useCallback(E=>{dn.current=E,hr(E)},[]),So=b.useCallback(()=>{const E=dn.current;if(dn.current=null,hr(null),E===null)return;const G=vo(E);G!==null&&cn(G)},[vo,cn]),fr=Wt.indexOf(yt),Lm=b.useCallback(E=>{if(E.altKey||E.ctrlKey||E.metaKey)return;const G=E.target.tagName;G==="INPUT"||G==="TEXTAREA"||G==="SELECT"||(E.key==="ArrowLeft"||E.key==="PageUp"?(E.preventDefault(),Ii(-1)):(E.key==="ArrowRight"||E.key==="PageDown")&&(E.preventDefault(),Ii(1)))},[Ii]),$o=b.useRef(null);b.useEffect(()=>{if(!A)return;const E=$o.current;if(!(!E||E.offsetWidth===0))for(const G of xg){const be=ln(yt+G);be&&ss(be)}},[A,yt,ln]);const _o=b.useMemo(()=>{var Do;if(!A)return null;if(yt===Ri)return A;const E=Dt.get(yt);if(E&&E.width>0&&E.height>0)return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[E.width,E.height],total_warped_w:E.width,columns:[{col:1,warped_w:E.width,warped_h:E.height,offset_x:0,strips:[],chars:E.columns.flatMap(ut=>ut.chars).map(ut=>({id:ut.id,char:ut.char,slot:ut.slot,pos:ut.pos,sub:ut.sub,bbox_col:ut.bbox??[0,0,0,0]}))}],...E.columns.some(ut=>ut.kind==="figure"&&ut.figBox)?{figBlocks:E.columns.filter(ut=>ut.kind==="figure"&&ut.figBox).map(ut=>({id:ut.fig,box:ut.figBox}))}:{}};const G=(Do=A.pages)==null?void 0:Do.find(ut=>ut.page===yt),[be,ot]=A.image_size||[2386,3082];if(!(be>0&&ot>0))return null;const mt=Ti(yt),_t=(mt==null?void 0:mt.width)??be,wr=(mt==null?void 0:mt.height)??ot,Fo=_t/be,Bo=wr/ot,Ho=new Map;for(const ut of A.columns){const At=(ut.strips||[]).flatMap(hn=>hn.srcQuad.map(fn=>fn[0]));if(At.length===0)continue;const Ut=ut.top_y??0,vr=ut.bottom_y??Ut+ut.warped_h;Ho.set(ut.col,{x0:Math.min(...At),x1:Math.max(...At),top:Ut,slotH:(vr-Ut)/21})}return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[_t,wr],total_warped_w:_t,columns:G?G.columns.map(ut=>{const At=Ho.get(ut.col)??{x0:0,x1:0,top:0,slotH:118};return{col:ut.col,warped_w:_t,warped_h:wr,offset_x:0,strips:[],chars:ut.chars.map(Ut=>{const vr=Ut.slot??Ut.pos??0,hn=(At.top+(vr-1)*At.slotH)*Bo,fn=(At.x0+At.x1)/2,[Xm,Jm]=Ut.sub==="a"?[fn,At.x1]:Ut.sub==="b"?[At.x0,fn]:[At.x0,At.x1];return{...Ut,bbox_col:[Xm*Fo,hn,Jm*Fo,hn+At.slotH*Bo]}})}}):[]}},[A,yt,Ri,Dt,Ti]),{entryTitle:mn,authors:No}=Cg(n,r,m===void 0),[zo,gr]=b.useState("text");b.useEffect(()=>{gr("text")},[de,B]);const Pm=b.useMemo(()=>se?Sg(se,et,Xa(fe,se),O,Me,mr):[],[se,et,fe,O,Me,mr]),Co=Ah(),Eo=b.useRef(null),Ro=b.useRef(null),xr=b.useMemo(()=>{const E=[];return A&&E.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ye?"bim-rd-on":""}`,"aria-pressed":Ye,title:"切换外挂现代断句标点",onClick:()=>wt(G=>!G),children:Ye?"标点":"无标点"})}}),E},[A,Ye]),Om=b.useMemo(()=>L&&L.length>0?[...xr,...L]:xr,[xr,L]),Fm=b.useMemo(()=>fe&&ge&&B?{entryId:n,versionKey:B,chapterKey:ge.file,chapter:ge,version:fe,transport:r,viewport:Co}:null,[n,B,ge,fe,r,Co]),Bm=b.useCallback(E=>{de&&k(de,E)},[de,k]),oi=Ph({plugins:Om,ctx:Fm,prefs:Ce,setPrefs:Ee,t:Z,convert:O,pages:A==null?void 0:A.pages,textRootRef:Eo,shellTextRef:Ro,selectedCharIds:st,scrollToAnchor:Bm});if(W==="loading")return t.jsx(Va,{className:F,style:T,title:m??mn,label:Z("reader.loading")});if(W==="missing"||!Q||!fe)return t.jsx("div",{className:F,style:{...T,...Ga},children:Z("reader.noText")});if(J==="failed")return t.jsx("div",{className:F,style:{...T,...Ga},children:Z("reader.tocFailed")});if(!se)return t.jsx(Va,{className:F,style:T,title:m??mn,label:Z("reader.tocLoading")});const hi=Xa(fe,se),Hm=Pm,To=nt&&de&&nt.chapter===de?no(de,nt.anchor):null,Dm=To&&ge&&mr(ge).some(E=>E.anchor===nt.anchor)?To:de??null,yr=Q.versions.map(E=>({key:E.key,label:_e.textVersionLabel(E),optionLabel:O(_e.textVersionLabel(E)),sourceName:Ja(E)?Z("reader.originalSource"):E.source_name?O(E.source_name):void 0,license:E.license??void 0,sourceUrl:E.source_url??void 0,primary:E.key===ze})),Mt=wg((Oo=se.source)==null?void 0:Oo.upstream),un=(typeof m=="string"?O(m):m)??(se.title?O(se.title):mn?O(mn):void 0),Io=fe.edition_label?O(fe.edition_label):void 0,jr=un?t.jsx("a",{href:we(n),title:Z("reader.viewEntry"),onClick:d?E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),d(n))}:void 0,children:un}):void 0,Wm=jr&&Io?t.jsxs(t.Fragment,{children:[jr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Io]})]}):jr,Um=No.length>0?O(No.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${` ${E.role||Z("reader.defaultRole")}`}`).join("、")):void 0,kr=ge?bd(ge,hi,O,Me):void 0,ai=Me&&!!(_!=null&&_.json),li=(_==null?void 0:_.json)??null,fi=(_==null?void 0:_.md)??null,Mo=ai&&!ee&&Qc(li.sections),Km=Mo&&!(fi&&Ce.readingMode==="paragraph"&&Ln(fi)),Ym=ai&&Mo?t.jsx(mf,{juan:li,view:zo,onView:gr,textHasEntries:Km}):void 0,Gm=!0,pn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,bn=Ja(fe),Xt=bn?Z("reader.originalSource"):fe.source_name?O(fe.source_name):void 0,Vm=(typeof p=="string"?O(p):p)??(bn?void 0:Xt??O(_e.textVersionLabel(fe))),qm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(uc,{className:F,style:T,title:Wm,subtitle:Vm,byline:Um,current:kr,pagerUnit:hi,rail:Ym,revisedAt:w,backHref:x,backLabel:j,onReportError:v?E=>v({...E,bookTitle:typeof un=="string"?un:void 0,entryId:n}):void 0,workLinkToggle:ai&&!ee&&!!d&&!!(li!=null&&li.sections.some(E=>E.work_id)),toc:Hm,tocCaption:Z("reader.tocCaption",{n:se.chapters.length,unit:O(hi)}),tocHeader:Me&&se.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:ee?Z("reader.searchChaptersPlaceholder"):Z("reader.searchUnitPlaceholder",{unit:O(hi)}),"aria-label":ee?Z("reader.searchChapters"):Z("reader.searchUnit",{unit:O(hi)}),value:He,onChange:E=>ct(E.target.value)}):void 0,activeKey:de??null,tocActiveKey:Dm,onSelect:P,images:Rn(ge)&&ne&&!A?null:te.images,renderImageOverlay:f,imagePanel:A||at?"open":g,imagesLoading:lt,isWarpMode:!!A,showPreserveMargins:!it,customImagePanel:A&&_o?t.jsxs("div",{ref:$o,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Lm,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:s.bim("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:[st.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ke(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${s.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",st.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:$t<=1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round($t*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:$t>=6,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:$t===1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(ug,{ref:dt,resetKey:yt,onScaleChange:Ot,style:{flex:1,minHeight:0},children:t.jsx(Ca,{store:Qe,children:E=>{var G;return t.jsx(qs,{imageUrl:Im,pageData:_o,selectedCharIds:st,hoveredCharId:E,decorations:oi.decorations,preserveMargins:Pt,banxinMode:ce.banxinMode,extent:(G=Ti(yt))==null?void 0:G.extent,renderScale:$t,selectedFigBlock:D,onFigBlockClick:be=>ke(be),onCharClick:be=>{ke(null),Ke(mt=>{const _t=new Set(mt);return _t.has(be)?_t.delete(be):(_t.clear(),_t.add(be)),_t});const ot=document.querySelector(`[data-char-id="${be}"]`);ot&&ot.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Qe.set})}})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":Z("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:s.bim("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:fr<=0,onClick:()=>Ii(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":yt,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:s.bim("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":Z("reader.facsimilePageInput"),size:Math.max(2,String(br??yt).length),value:br??String(yt),onFocus:E=>E.currentTarget.select(),onChange:E=>Am(E.target.value),onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),So()):E.key==="Escape"&&(dn.current=null,hr(null)),E.stopPropagation()},onBlur:So,style:{width:`${Math.max(2,String(br??yt).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${s.bim("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:fr<0||fr>=Wt.length-1,onClick:()=>Ii(1),children:"›"})]})]}):void 0,pluginSettings:oi.settings,pluginToolbar:oi.toolbar,pluginOverlay:oi.overlay,textRootRef:Ro,prefs:Ce,onPrefsChange:Ee,versions:yr.length>1?yr:void 0,currentVersionKey:yr.length>1?fe.key:void 0,onVersionChange:Je,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Ln(fi),allowVertical:y,origScriptAvailable:qm,contentLoading:Re,children:[(Re||ne&&!A&&!ai&&pn==null)&&t.jsx(nc,{}),!Re&&A&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:Eo,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:ge!=null&&ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,fe.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]})]})]}),t.jsx(Ca,{store:Qe,children:E=>t.jsx(to,{pageData:A,pages:A.pages,punctuations:A.punctuations||kg,selectedCharIds:st,hoveredCharId:E,onSelectionChange:Tm,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:G,fig:be})=>{Ke(new Set),ke(be),bi(G)},onCharClick:G=>{ke(null),Ke(ot=>{const mt=new Set(ot);return mt.has(G)?mt.delete(G):(mt.clear(),mt.add(G)),mt});const be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be),oi.onCellClick(G)},onCharHover:G=>{Qe.set(G),oi.onCellHover(G)},decorations:oi.decorations,mode:"horizontal",showPunctuation:Ye,entities:rt,entityTransport:r,onEntityNavigate:R,onVisiblePageChange:Mm,convert:O,scrollToPage:zt,scrollToAnchor:Pe&&Pe.chapter===de&&dr?Pe:null,onVisibleHeadingChange:G=>Y(G&&de?{chapter:de,anchor:G}:null),pageBreaks:Ce.pageBreaks,pageIndicatorY:Ce.pageIndicatorY,onPageIndicatorYChange:G=>Ee({pageIndicatorY:G}),quoteStyle:Ce.quoteStyle,bookTitleStyle:Ce.bookTitleStyle,showWorks:Ce.showWorks})})]}),!Re&&!A&&ai&&li&&t.jsx(cf,{juan:li,rawText:fi,positionLabel:Ng(ge,se,hi,O),groupLabel:zg(se,de??null),index:vg(n,se),searchQuery:He,onNavigate:d,transport:r,workLabelCache:tt,prefs:Ce,view:zo,onViewChange:gr},`${B}/${de}`),!Re&&!A&&!ai&&pn!=null&&ge&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[bn&&Xt&&t.jsx(t.Fragment,{children:Xt}),!bn&&fe.source_name&&t.jsxs(t.Fragment,{children:[Z("reader.textSource")," ",fe.source_url?t.jsx("a",{className:"bim-rd-link",href:fe.source_url,target:"_blank",rel:"noreferrer",children:O(fe.source_name)}):O(fe.source_name)]}),Xt&&fe.license&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]}),Mt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[Z("reader.upstream")," ",Mt.url?t.jsx("a",{className:"bim-rd-link",href:Mt.url,target:"_blank",rel:"noreferrer",children:O(Mt.name??Mt.url)}):O(Mt.name??""),Mt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),Mt.license_url?t.jsx("a",{className:"bim-rd-link",href:Mt.license_url,target:"_blank",rel:"noreferrer",children:Mt.license}):Mt.license]}),Mt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(rc,{text:Mt.note,convert:O})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Hs,{text:pn,mode:Ce.readingMode,tables:Gm,gujiMarkdown:!0,bookMarking:Bs(Ce),quoteStyle:Ce.quoteStyle})})]}),!Re&&!ne&&!A&&!ai&&pn==null&&ge&&t.jsx("div",{className:"bim-rd-state",children:Z("reader.chapterFailed")}),!Re&&se.references&&se.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:Z("reader.references")}),t.jsx("ol",{children:se.references.map((E,G)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:O(E.title)}):t.jsx("span",{children:O(E.title)}),E.author&&t.jsxs("span",{children:[",",O(E.author)]}),E.note&&t.jsxs("span",{children:["。",O(E.note)]})]},G))})]})]})};function Ja(e){return e.is_original===!0||e.source==="original"}function Ng(e,i,n,r){var a,l;if(!e)return;const o=(l=(a=i.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(o?`${o}冊`:`${n}${e.n}`)}function zg(e,i){if(!i)return;const n=r=>{var o;for(const a of r??[]){const l=n(a.children);if(l)return l;if((o=a.files)!=null&&o.includes(i))return a.label}};return n(e.juan_groups)}function Cg(e,i,n){const[r,o]=b.useState({entryTitle:void 0,authors:[]});return b.useEffect(()=>{if(o({entryTitle:void 0,authors:[]}),typeof i.getItem!="function")return;let a=!1;return Promise.resolve(i.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);o({entryTitle:n&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,i,n]),r}const Eg=({pageData:e,rawImageUrl:i="",punctuations:n=[],title:r,subtitle:o,onBack:a,className:l="",style:d={}})=>{const[c,m]=b.useState(new Set),[p,h]=b.useState(null),[u,f]=b.useState("horizontal"),[g,y]=b.useState(!0),v=b.useRef(null),w=b.useCallback($=>{m(new Set($))},[]),x=b.useCallback($=>{if(m(N=>{const z=new Set(N);return z.has($)?z.delete($):(z.clear(),z.add($)),z}),v.current){const N=v.current.querySelector(`[data-char-id="${$}"]`);N&&N.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var $;m(new Set),window.getSelection&&(($=window.getSelection())==null||$.removeAllRanges())},S=n.length>0?n:e.punctuations||[];return t.jsxs("div",{className:`guji-reader-container ${l}`,style:d,children:[t.jsxs("header",{className:"guji-reader-header",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&t.jsx("button",{type:"button",onClick:a,className:"guji-reader-btn",style:{marginRight:6},children:"‹ 返回"}),t.jsx("span",{className:"guji-reader-title",children:r||e.title}),o&&t.jsx("span",{style:{fontSize:"0.85rem",color:s.bim("meta-fg")},children:o}),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:s.bim("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:s.bim("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>y($=>!$),className:`guji-reader-btn ${g?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:g?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f($=>$==="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(qs,{imageUrl:i,pageData:e,selectedCharIds:c,hoveredCharId:p,onCharClick:x,onCharHover:h})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:v,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(to,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:p,onSelectionChange:w,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},Rg=({data:e,onNavigate:i,className:n,style:r})=>{var p;const{t:o,convert:a}=oe(),[l,d]=b.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[c,m]=b.useState(null);return t.jsxs("div",{className:n,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:s.bim("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[o("catalog.totalVolumes")," ",t.jsx("strong",{children:e.total_volumes})," ",o("unit.juan")]}),e.stats.zhulu!=null&&t.jsxs("span",{children:[o("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",o("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[o("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",o("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:o("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(h=>t.jsx(Tg,{division:h,expanded:l===h.name,onToggle:()=>d(l===h.name?null:h.name),expandedCat:c,onCatToggle:u=>m(c===u?null:u),onNavigate:i},h.name))})]})},Tg=({division:e,expanded:i,onToggle:n,expandedCat:r,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=oe(),c=e.categories.reduce((m,p)=>{const h=p.stats||{zhulu:0,cunmu:0};return m+(h.zhulu||0)+(h.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:i?`color-mix(in srgb, ${s.bim("primary")} 6%, transparent)`:s.bim("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:s.bim("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:i?"▲":"▼"})]})]}),i&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(m=>{const p=`${e.name}/${m.name}`;return t.jsx(Ig,{category:m,expanded:r===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},Ig=({category:e,expanded:i,onToggle:n,onNavigate:r})=>{var m,p,h,u;const{t:o,convert:a}=oe(),l=((m=e.books)==null?void 0:m.zhulu)||[],d=((p=e.books)==null?void 0:p.cunmu)||[],c=(((h=e.stats)==null?void 0:h.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:i?s.bim("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:s.bim("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginLeft:"8px",fontWeight:400},children:o("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[o("catalogPage.booksN",{n:c})," ",i?"▲":"▼"]})]}),i&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Za,{label:o("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(Za,{label:o("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},Za=({label:e,books:i,onNavigate:n})=>{const{t:r,convert:o}=oe(),a=It(),[l,d]=b.useState(i.length<=20),c=l?i:i.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",i.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((m,p)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:s.bim("fg")},children:m.work_id&&n?t.jsx("a",{href:a(m.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(m.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${s.bim("link-fg")}`},children:o(m.title)}):o(m.title)}),m.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.volumes)}),m.author&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.author).slice(0,20)})]},p))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:s.bim("primary"),background:"transparent",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:i.length})})]})};function ro(e="/api/feedback",i){const n=()=>typeof e=="function"?e():e,r=(...o)=>((i==null?void 0:i.fetch)??fetch)(...o);return{async listFeedback(o){try{const l=await(await r(`${n()}?resourceId=${encodeURIComponent(o)}`)).json();return l!=null&&l.success&&Array.isArray(l.items)?l.items:[]}catch{return[]}},async submitFeedback(o){const a=await r(n(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error((l==null?void 0:l.error)||(i==null?void 0:i.defaultError)||"submit failed")}}}}function gd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const Mg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],xd=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:r})=>{const{t:o}=oe(),[a,l]=b.useState(null),[d,c]=b.useState(""),[m,p]=b.useState(""),[h,u]=b.useState("idle"),[f,g]=b.useState(""),y=b.useRef(null);b.useEffect(()=>{e&&(l(null),c(""),p(""),u("idle"),g(""))},[e]),b.useEffect(()=>{a&&setTimeout(()=>{var x;return(x=y.current)==null?void 0:x.focus()},100)},[a]),b.useEffect(()=>{if(h==="success"){const x=setTimeout(i,2e3);return()=>clearTimeout(x)}},[h,i]),b.useEffect(()=>{if(!e)return;const x=j=>{j.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const v=async()=>{if(!(!a||!d.trim())){u("submitting"),g("");try{await n({type:a,content:d.trim(),...m.trim()?{contact:m.trim()}:{}}),u("success")}catch(x){u("error"),g(x instanceof Error?x.message:o("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&h!=="submitting";return t.jsx("div",{style:Ag,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:Lg,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Pg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:Og,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Wg,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:o("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:s.bim("primary"),marginTop:"8px"},children:o("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Mg.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...Fg,...a===x.value?Bg:{}},children:[t.jsx("span",{children:x.icon})," ",o(`feedback.submitType.${x.value}`)]},x.value))}),t.jsx("textarea",{ref:y,value:d,onChange:x=>c(x.target.value),placeholder:o(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||h==="submitting",style:{...Hg,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:m,onChange:x=>p(x.target.value),placeholder:o("feedback.contactPlaceholder"),maxLength:200,disabled:!a||h==="submitting","aria-label":o("feedback.contactLabel"),style:Kg}),t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),h==="error"&&t.jsx("div",{style:Ug,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!w,style:{...Dg,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Ag={position:"fixed",top:0,left:0,right:0,bottom:0,background:s.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lg={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:s.bim("shadow-dialog")},Pg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Og={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:s.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Fg={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Bg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Hg={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Dg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},Wg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:s.bim("success")},Ug={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Kg={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},ds="--bim-feedback-fab-offset",ms=48,Yg=16,Gg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:r=!1,zIndex:o})=>{const{t:a}=oe(),[l,d]=b.useState(!1),c=i.bottom??24;return b.useEffect(()=>{if(r||typeof document>"u")return;const m=document.documentElement;return m.style.setProperty(ds,`calc(${c+ms+Yg}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(ds)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Vg,zIndex:o??s.bim("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:i.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:n})]})},Vg={position:"fixed",width:`${ms}px`,height:`${ms}px`,borderRadius:"50%",border:"none",background:s.bim("primary"),color:s.bim("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:s.bim("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},qg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],yd=({onSubmit:e})=>{const{t:i}=oe(),[n,r]=b.useState("bug"),[o,a]=b.useState(""),[l,d]=b.useState(""),[c,m]=b.useState("idle"),[p,h]=b.useState(""),u=b.useRef(null);b.useEffect(()=>{n&&setTimeout(()=>{var y;return(y=u.current)==null?void 0:y.focus()},100)},[n]);const f=async()=>{if(!(!n||!o.trim())){m("submitting"),h("");try{await e({type:n,content:o.trim(),...l.trim()?{contact:l.trim()}:{}}),m("success"),a(""),d(""),r("bug")}catch(y){m("error"),h(y instanceof Error?y.message:i("feedback.submitFailedRetry"))}}},g=n&&o.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:Qa,children:t.jsxs("div",{style:ex,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:tx,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Qa,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:qg.map(y=>t.jsxs("button",{onClick:()=>r(y.value),style:{...Xg,...n===y.value?Jg:{}},children:[t.jsx("span",{children:y.icon})," ",i(`feedback.submitType.${y.value}`)]},y.value))}),t.jsx("textarea",{ref:u,value:o,onChange:y=>a(y.target.value),placeholder:i(n?`feedback.placeholder.${n}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...Zg}}),t.jsx("input",{type:"text",value:l,onChange:y=>d(y.target.value),placeholder:i("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":i("feedback.contactLabel"),style:nx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[o.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!g,style:{...Qg,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:ix,children:p})]})},Qa={padding:"16px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",background:s.bim("input-bg")},Xg={padding:"8px 16px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:"transparent",color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Jg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Zg={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Qg={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},ex={display:"flex",alignItems:"center",gap:"12px",color:s.bim("success"),fontSize:"14px"},tx={background:"none",border:"none",color:s.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ix={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},nx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},jd={bug:{key:"bug",color:s.bim("danger")},resource:{key:"resource",color:s.bim("primary")},suggestion:{key:"suggestion",color:s.bim("primary")},other:{key:"other",color:s.bim("desc-fg")}},rx=jd.other,kd={pending:{key:"pending",color:s.bim("warning")},in_progress:{key:"in_progress",color:s.bim("primary")},resolved:{key:"resolved",color:s.bim("success")},wontfix:{key:"wontfix",color:s.bim("desc-fg")},duplicate:{key:"duplicate",color:s.bim("desc-fg")}},sx=kd.pending;function ox(e){try{const i=new Date(e),n=r=>String(r).padStart(2,"0");return`${i.getFullYear()}-${n(i.getMonth()+1)}-${n(i.getDate())} ${n(i.getHours())}:${n(i.getMinutes())}`}catch{return e}}function ax(e,i){if(!e)return!1;try{const n=new URL(e,i);if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=new URL(i);return n.hostname===r.hostname}catch{return!1}}const wd=({items:e,loading:i})=>{const n=It(),{t:r,convert:o}=oe();return i?t.jsx(nc,{}):e.length===0?t.jsx("div",{style:lx,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=jd[a.type]||rx,d=kd[a.status]||sx,c=typeof window<"u"&&ax(a.pageUrl,window.location.href);return t.jsxs("div",{style:cx,children:[t.jsxs("div",{style:dx,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...el,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...el,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:mx,children:ox(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:ux,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Fr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Fr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Fr,children:a.pageUrl}))]}),t.jsx("div",{style:px,children:o(a.content)}),a.reply&&t.jsxs("div",{style:bx,children:[t.jsx("div",{style:hx,children:r("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},lx={textAlign:"center",padding:"40px 0",color:s.bim("desc-fg"),fontSize:"14px"},cx={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},dx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},el={fontSize:"12px",color:s.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},mx={fontSize:"12px",color:s.bim("desc-fg")},ux={fontSize:"12px",marginBottom:"6px"},Fr={color:s.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${s.bim("primary")}`},px={fontSize:"14px",lineHeight:"1.6",color:s.bim("fg"),whiteSpace:"pre-wrap"},bx={marginTop:"12px",padding:"10px 12px",background:s.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:s.bim("fg")},hx={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:s.bim("primary")},vd=({resourceId:e,transport:i,apiUrl:n})=>{const{t:r}=oe(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(r);c.current=r;const m=b.useMemo(()=>i??ro(n,{defaultError:c.current("feedback.submitFailed")}),[i,n]),p=b.useCallback(async()=>{d(!0);try{a(await m.listFeedback(e))}catch{}finally{d(!1)}},[e,m]);b.useEffect(()=>{p()},[p]);const h=async u=>{await m.submitFeedback({...u,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e}),setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(wd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(yd,{onSubmit:h})})]})},er=8;async function tr(e,i,n,r){const o=Number.isFinite(i)?Math.max(1,Math.floor(i)):1,a=new Array(e.length);let l=0;const d=Array.from({length:Math.min(o,Math.max(1,e.length))},async()=>{for(;l<e.length&&!(r!=null&&r());){const c=l++;a[c]=await n(e[c],c)}});return await Promise.all(d),a}const fx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function gx(e){const i=e.search(fx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const Sd={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:i})=>{let n=e,r="",o=i;if(e&&typeof i=="string"&&(i===e||i===xx(e))){const[a,l]=gx(i);l&&(n=encodeURI(a),o=a,r=l)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:n,target:n!=null&&n.startsWith("http")?"_blank":void 0,rel:n!=null&&n.startsWith("http")?"noopener noreferrer":void 0,style:{color:s.bim("link")},children:o}),r]})},code:({children:e})=>t.jsx("code",{style:{background:s.bim("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function xx(e){try{return decodeURI(e)}catch{return e}}const yx={...Sd,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:r})=>{const{convert:o}=xt(),a=i?yx:Sd;return t.jsx("div",{className:r,style:n,children:t.jsx(su,{remarkPlugins:[ou],components:a,children:o(e)})})},jx=s.detail["zh-Hant"].relation,kx=s.detail["zh-Hant"].lossStatus,wx=s.detail["zh-Hant"].resourceKind,ir=s.getT("zh-Hant"),so=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function tl(e,i=ir){return e?so(jx,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function vx(e,i=ir){return so(kx,e)?i(`detail.lossStatus.${e}`):e}function Sx(e,i=ir){return so(wx,e)?i(`detail.resourceKind.${e}`):""}function oo({authors:e,onNavigate:i,renderLink:n}){const{convert:r}=oe(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=vs(a.role);return t.jsxs(b.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(jt,{id:a.entity_id,label:r(a.name),onNavigate:i,renderLink:n,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function $d(e,i,n=ir){var c,m;const r=js(e,i),o=r.mirrors.map(p=>({key:p.key,label:p.label,description:p.description,rows:p.items.filter(h=>h.group_role!=="mirror"),mirrors:p.items.filter(h=>h.group_role==="mirror")})),a=r.buckets.filter(p=>p.key==="image"||p.key==="textImage").flatMap(p=>p.items);a.length&&o.push({key:"_images",label:o.length?n("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(p=>p.key==="physical"))==null?void 0:c.items)??[];return l.length&&o.push({key:"_physical",label:n("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((m=r.buckets.find(p=>p.key==="text"))==null?void 0:m.items)??[],groups:o}}function _d(e,i){const n=(e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name,r=Al(e,i);return r?`${n}(${r})`:n}function ao({item:e,siblings:i,listedVolumeCounts:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(!1),d=s.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(_d(e,i)),p=s.resourceHref(e),h=Kn(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,g;const u=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=e.metadata)==null?void 0:g.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?r("colorMode.color"):r("colorMode.bw")})]}):null;return p?t.jsxs("a",{href:p,target:"_blank",rel:"noopener noreferrer",children:[m," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),u]}):t.jsxs("span",{className:"bim-d-zt-name",children:[m,u]})})(),h&&t.jsx("span",{className:"bim-d-meta",children:o(h)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(As,{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?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Nd({groups:e,listedVolumeCounts:i}){const{t:n,convert:r}=oe();return t.jsx(t.Fragment,{children:e.map(o=>t.jsxs("div",{className:"bim-d-rg",children:[o.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(o.label)}),o.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(o.description)}),o.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:o.rows.map((a,l)=>t.jsx(ao,{item:a,siblings:o.rows,listedVolumeCounts:i},`${a.id||a.url||a.name}-${l}`))})}),o.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[o.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:n("detail.mirror")}),o.mirrors.map((a,l)=>{const d=s.resourceHref(a),c=r(_d(a,o.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?r(a.details):void 0,children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:c},l)})]})]},o.key))})}const Yi=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function us(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Yi.find(r=>i.startsWith(r.key[0])))==null?void 0:n.key}const il=12,Br=50,$x=60,zd=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,railTop:a,back:l,railLinks:d})=>{var Je,Pe,Ue,nt,Y;const{t:c,convert:m,messages:p}=oe(),h=b.useMemo(()=>Ss({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[v,w]=b.useState(""),[x,j]=b.useState(!1),S=Math.max(h.length,e._edition_count??0),$=S>Zo&&(h.length>Zo||!!((Je=e._book_groups)!=null&&Je.length)),[N,z]=b.useState({}),C=e._book_groups,[U,R]=b.useState({}),L=b.useRef(new Set),F=b.useMemo(()=>{if(!$)return[];const M={};for(const q of C??[])q.id&&q.title&&(M[q.id]=q.title);const k=Wu(e._books??[],e.version_graph,{titles:M,noHolderFallback:!!C});if(!C)return k;const P=new Map(k.map(q=>[q.key,q]));return C.map(q=>{const _=P.get(q.g);if(_&&_.rows.length>=q.n)return{..._,title:_.title||q.title||""};const le=U[q.g],H=(le==null?void 0:le.rows)??(_==null?void 0:_.rows)??[];return{key:q.g,title:q.g!=="_none"&&(q.title||(_==null?void 0:_.title))||"",rows:H,total:q.n,imageCount:H.filter(he=>he.hasImage).length,pagesLeft:Math.max(0,q.pages-((le==null?void 0:le.loaded)??0))}})},[$,e._books,e.version_graph,C,U]),T=b.useMemo(()=>x?F.map(M=>({...M,rows:M.rows.filter(k=>k.hasImage)})).filter(M=>M.rows.length):F,[F,x]);b.useEffect(()=>{var M;if(!(!$||!(i!=null&&i.getBookGroupPage)))for(const k of F){const P=N[k.key]??0;if(!P||!k.pagesLeft||k.rows.length>=P||L.current.has(k.key))continue;const q=(((M=U[k.key])==null?void 0:M.loaded)??0)+1;L.current.add(k.key),i.getBookGroupPage(e.id,k.key,q).then(_=>{const le=(_??[]).map(H=>Pl(H,e.version_graph));R(H=>{const he=H[k.key];return{...H,[k.key]:{rows:[...(he==null?void 0:he.rows)??[],...le],loaded:q}}})}).catch(()=>R(_=>{var le;return{..._,[k.key]:{rows:((le=_[k.key])==null?void 0:le.rows)??[],loaded:q}}})).finally(()=>L.current.delete(k.key))}},[$,F,N,i,e.id,e.version_graph,U]);const Z=h.length<=$x,O=!$&&(Z||g||!!v||x),ae=b.useMemo(()=>$?T.flatMap(M=>N[M.key]?M.rows.slice(0,N[M.key]).map(k=>k.id):[]):O?h:h.slice(0,il),[$,T,N,h,O]);b.useEffect(()=>{if(!i||ae.length===0)return;const M=ae.filter(P=>!u.has(P));if(M.length===0)return;let k=!1;return tr(M,er,P=>i.getItem(P).then(q=>{var le;const _=q??{};return[P,{id:P,title:_.title,edition:_.edition,resources:_.resources,publication_info:_.publication_info,current_location:_.current_location,provenance:_.provenance,lineage:_.lineage,related_books:_.related_books,dating:_.dating,measure_info:_.measure_info,summary:Nx((le=q==null?void 0:q.description)==null?void 0:le.text)}]}).catch(()=>[P,{id:P}]),()=>k).then(P=>{k||f(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,ae,u]);const ce=b.useMemo(()=>$?[]:h.map(M=>u.get(M)??{id:M}),[$,h,u]),Ee=h.length>0&&h.every(M=>u.has(M)),we=!!i&&ae.some(M=>!u.has(M)),ye=Z||O,Q=b.useMemo(()=>Ol(ce,e.version_graph,{era:v,scanOnly:x,sort:ye?"year":"default"}),[ce,e.version_graph,v,x,ye]),Ne=g?Q.rows:Q.rows.slice(0,il),W=$?F.reduce((M,k)=>M+k.imageCount,0):Q.allRows.filter(M=>M.hasImage).length,je=Q.allRows.reduce((M,k)=>{var P;return M+(((P=k.copies)==null?void 0:P.length)??0)},0),K=b.useMemo(()=>(e._related||[]).map(M=>({...M,title:M.title??""})),[e._related]),V=K.filter(M=>M.relation==="collected_in"),re=b.useMemo(()=>{const M=new Map;for(const k of e.related_works||[]){if(k.relation!=="collected_in"||M.has(k.id))continue;const P=qu(k.volume_index,k.order,e.subtype,p.workPage.pos);P&&M.set(k.id,P)}return M},[e.related_works,e.subtype,p.workPage.pos]),X=((Pe=e._contents)==null?void 0:Pe.total)??0,I=b.useMemo(()=>{const M=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],k=P=>{const q=M.indexOf(P??"");return q<0?M.length:q};return K.filter(P=>P.relation!=="collected_in").map((P,q)=>({r:P,i:q})).sort((P,q)=>k(P.r.relation)-k(q.r.relation)||P.i-q.i).map(P=>P.r)},[K]),ue=b.useMemo(()=>{const M=js(e.resources,e.resource_groups);return[...M.mirrors.flatMap(k=>k.items.map(P=>({r:P,kind:m(k.label)}))),...M.buckets.flatMap(k=>k.items.map(P=>({r:P,kind:m(Sx(k.key,c))})))]},[e.resources,e.resource_groups,m,c]),fe=e.indexed_by||[],ze=e.emendated_by||[],B=b.useMemo(()=>{var he,xe,Re,Ze,Me;const M=[],k=(xe=(he=e.authors)==null?void 0:he[0])==null?void 0:xe.dynasty;k&&M.push({label:c("workPage.fact.written"),value:m(k)});const P=qt(e,p.unit.juan);if(P){const He=((Re=e.juan_count)==null?void 0:Re.description)??((Me=(Ze=e.measures)==null?void 0:Ze.find(ct=>(ct==null?void 0:ct.unit)==="卷"&&ct.note))==null?void 0:Me.note);M.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(P),He&&He!==P?t.jsxs("span",{className:"bim-d-meta",children:["(",m(He),")"]}):null]})})}e.loss_status&&M.push({label:c("workPage.fact.loss"),value:m(vx(e.loss_status,c))}),e.authenticity==="forged"&&M.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const q=Q.allRows.filter(He=>He.sortYear!=null),_=q.length>0?q.reduce((He,ct)=>He.sortYear<=ct.sortYear?He:ct):null;_!=null&&_.era.era?M.push({label:c("workPage.fact.earliest"),value:m([_.era.era,_.era.reign].filter(Boolean).join(" ")),title:_.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):we&&M.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),ze.length&&M.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:ze.length})});const le=_x(e.additional_titles);le.length&&M.push({label:c("workPage.fact.alias"),value:le.map(m).join("、")});const H=(e.additional_works||[]).map(He=>m(He.book_title)+(He.n_juan!=null?` ${He.n_juan}${p.unit.juan}`:""));return H.length&&M.push({label:c("workPage.fact.appendix"),value:H.join("、")}),M},[e,m,c,p,we,Q.allRows,ze.length]),Te=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:Ee?W:0,label:c("workPage.stat.hasImage")},{value:fe.length,label:c("workPage.stat.catalogs")}],ve=$s(e),Ve=ve?[ve.l1,ve.l2,ve.l3,ve.l4].filter(Boolean).map(M=>m(M)):[],qe=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",Xe=t.jsx(tn,{title:m(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:n,renderLink:r}),meta:t.jsx(vt,{items:[...Ve,ve!=null&&ve.source?c("workPage.classifiedBy",{source:m(ve.source.split("/")[0])}):"",qe]}),description:(Ue=e.description)!=null&&Ue.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(nt=e.description.sources)!=null&&nt.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(M=>({text:m(Ju(M)),href:Zu(M)})).filter(M=>M.text).map((M,k)=>t.jsxs(b.Fragment,{children:[k>0?" · ":null,M.href?t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",children:M.text}):M.text]},k))}):null]}):void 0,stats:Te,facts:B,readAction:o,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Y=e.appendix)==null?void 0:Y.map((M,k)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(M.title)}),t.jsx(zi,{text:M.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},k))}),J=Q.eras.length>=2?[{key:"",label:c("catalog.all")},...Q.eras.map(M=>({key:M,label:`${M} ${Q.allRows.filter(k=>k.era.era===M).length}`}))]:[],ie=[];S&&ie.push({id:"versions",label:c("workPage.sec.versions"),count:S}),fe.length&&ie.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:fe.length}),X&&ie.push({id:"contents",label:c("workPage.sec.contents"),count:X}),V.length&&ie.push({id:"collected",label:c("workPage.sec.collected"),count:V.length}),I.length&&ie.push({id:"related",label:c("workPage.sec.related"),count:I.length}),ue.length&&ie.push({id:"resources",label:c("workPage.sec.resources"),count:ue.length});const me=S===0&&fe.length===0&&!X,se=t.jsxs(t.Fragment,{children:[S>0&&t.jsxs(St,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(vt,{items:[c("workPage.versionsTotal",{n:S-je}),Ee&&W?c("workPage.versionsWithImage",{n:W}):"",Q.rows.length!==Q.allRows.length?c("workPage.versionsCurrent",{n:Q.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":we&&J.length===0&&h.length>1?"":void 0,children:[!$&&J.length>0&&t.jsx(Qi,{items:J,value:v,onChange:M=>{w(M),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(kc,{label:c("workPage.scanOnly"),checked:x,onChange:M=>{j(M),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(ye?"workPage.sortByYear":"workPage.sortByCatalog")})]}),$?t.jsxs("div",{className:"bim-d-groups",children:[t.jsx("div",{className:"bim-d-ui",style:{display:"flex",justifyContent:"flex-end",margin:"4px 0"},children:t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(Object.keys(N).length?{}:Object.fromEntries(T.slice(0,20).map(M=>[M.key,Br]))),children:Object.keys(N).length?c("workPage.groupCollapseAll"):c("workPage.groupExpandAll")})}),T.map(M=>{const k=N[M.key]??0,P=M.rows.slice(0,k);return t.jsxs("details",{open:k>0,onToggle:q=>{const _=q.currentTarget.open;z(le=>{if(_===le[M.key]>0)return le;const H={...le};return _?H[M.key]=Br:delete H[M.key],H})},style:{borderTop:`1px solid ${s.bim("border")}`},children:[t.jsxs("summary",{className:"bim-d-ui",style:{cursor:"pointer",minHeight:40,display:"flex",alignItems:"center",gap:12,padding:"6px 4px"},children:[t.jsx("span",{style:{flex:1},children:m(M.title||c("workPage.groupUngrouped"))}),t.jsx("span",{className:"bim-d-meta",children:c("workPage.groupCount",{n:M.total})}),M.imageCount>0&&t.jsx("span",{className:"bim-d-flag",children:c("workPage.groupImage",{n:M.imageCount})})]}),k>0&&t.jsx("table",{className:"bim-d-zt bim-d-zt-ver",children:t.jsx("tbody",{children:P.map(q=>{const _=u.get(q.id);return t.jsx(nl,{row:q,measure:_==null?void 0:_.measure_info,relations:q.relations??(_?Ll(_):void 0),loaded:!0,onNavigate:n,renderLink:r},q.id)})})}),k>0&&M.total>k&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(q=>({...q,[M.key]:k+Br})),children:c("workPage.groupMore",{n:M.total-k})})]},M.key)})]}):t.jsxs(t.Fragment,{children:[t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&en(Q.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:Ne.map(M=>{var k;return t.jsx(nl,{row:M,measure:(k=u.get(M.id))==null?void 0:k.measure_info,relations:M.relations,loaded:u.has(M.id),onNavigate:n,renderLink:r},`${M.id}:${u.has(M.id)?"r":"p"}`)})})]}),Ne.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(v||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx(Jn,{total:Q.rows.length,shown:Ne.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)})]}),Q.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),fe.length>0&&t.jsx(Cx,{items:fe,transport:i,onNavigate:n,renderLink:r}),X>0&&e._contents&&t.jsx(Ex,{workId:e.id,info:e._contents,transport:i,onNavigate:n,renderLink:r}),me&&t.jsx(St,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),de=(M,k)=>t.jsx(jt,{id:M,label:m(k),onNavigate:n,renderLink:r,dense:!0}),ge=b.useMemo(()=>{const M=new Map;for(const k of I){const P=tl(k.relation,c);M.set(P,(M.get(P)??0)+1)}return M.size>1?[...M.entries()].sort((k,P)=>P[1]-k[1]).slice(0,4).map(([k,P])=>`${m(k)} ${P}`).join(" · "):void 0},[I,m,c]),Oe=t.jsxs(t.Fragment,{children:[t.jsx(mi,{id:"collected",title:c("workPage.sec.collected"),items:V.map(M=>de(M.id,M.title)),metas:V.map(M=>re.get(M.id)??"")}),t.jsx(mi,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:I.length}),sub:ge,items:I.map(M=>t.jsxs(t.Fragment,{children:[de(M.id,M.title),t.jsx("span",{className:"bim-d-meta",title:M.note?m(M.note):void 0,children:m(tl(M.relation,c))})]}))}),t.jsx(mi,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:ue.map(({r:M,kind:k})=>{const P=m((M.url?s.getDisplayNameFromUrl(M.url):void 0)||M.name),q=s.resourceHref(M);return t.jsxs(t.Fragment,{children:[q?t.jsxs("a",{href:q,target:"_blank",rel:"noopener noreferrer",children:[P," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:P}),k&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:k})]})})})]});return t.jsx(Zi,{railTop:a,back:l,nav:ie,railLinks:d,main:se,card:Xe,side:Oe})};function _x(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function ps(e,i){return i((e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name)}function Nx(e){var a;if(!e)return;const n=e.replace(/\*\*/g,"").split(/\n/)[0].trim().match(/[^。]+。?/g)??[],o=((n.length>1&&((a=n[0])!=null&&a.startsWith("《"))?n[1]:n[0])??"").trim();return o?o.length>120?`${o.slice(0,120)}…`:o:void 0}function zx({copies:e,onNavigate:i,renderLink:n}){const{t:r,convert:o}=oe(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?ps(l.holders[0],o):"")||"",c=a.get(d)??[];c.push(l),a.set(d,c)}return t.jsxs("span",{className:"bim-d-zt-copies",children:[r("workPage.sameEditionCopies",{n:e.length}),[...a].map(([l,d],c)=>t.jsxs(b.Fragment,{children:[c>0?";":"",l?`${o(l)} `:"",d.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0?" · ":"",t.jsx(jt,{id:m.id,label:m.callNumber||m.id,onNavigate:i,renderLink:n,dense:!0})]},m.id))]},l||c))]})}function nl({row:e,measure:i,relations:n,loaded:r,onNavigate:o,renderLink:a}){const{t:l,convert:d}=oe(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),m=e.era.source==="edition",p=e.holders[0],h=e.copies??[],u=h.length&&e.locationName?d(e.locationName):p?ps(p,d):e.locationName?d(e.locationName):"",f=e.images[0],g=f?s.resourceHref(f):void 0,y=e.images.map(v=>ps(v,d)).join("、");return t.jsxs("tr",{"data-loading":r?void 0:"",className:h.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:h.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(jt,{id:e.id,label:d(e.name),onNavigate:o,renderLink:a,dense:!0}),i?t.jsx("span",{className:"bim-d-meta",children:d(i)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}),n&&n.length>0&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:n.map((v,w)=>t.jsxs(b.Fragment,{children:[w>0?" · ":null,d(l("workPage.relationWith",{relation:v.relation,n:v.ids.length}))]},v.relation))}),h.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:d(e.summary)}),h.length>0&&t.jsx(zx,{copies:h,onNavigate:o,renderLink:a})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:m?l("workPage.inferredFromEdition"):void 0,children:c?d(c):r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${u?"":" bim-d-zt-blank"}`,children:[u||(r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),h.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&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:y,children:l("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:y,children:l("workPage.hasImage")}))})]})}function Cx({items:e,transport:i,onNavigate:n,renderLink:r}){const{t:o,convert:a}=oe(),{items:l,groups:d}=b.useMemo(()=>{const f=[],g=new Map;for(const y of e){const v=`${y.source}\0${y.source_bid??""}`,w=g.get(v);w?w.push(y):(g.set(v,[y]),f.push(y))}return{items:f,groups:f.map(y=>g.get(`${y.source}\0${y.source_bid??""}`))}},[e]),[c,m]=b.useState(0),p=Math.min(c,l.length-1);l[p];const[h,u]=b.useState(new Map);return b.useEffect(()=>{if(!i)return;const f=[...new Set(l.map(y=>y.source_bid).filter(y=>!!y))];if(f.length===0)return;let g=!1;return Promise.all(f.map(y=>i.getItem(y).then(v=>{var w,x;return[y,((x=(w=v==null?void 0:v.authors)==null?void 0:w[0])==null?void 0:x.dynasty)??""]}).catch(()=>[y,""]))).then(y=>{g||u(new Map(y.filter(([,v])=>v)))}),()=>{g=!0}},[i,l]),t.jsx(St,{id:"catalogs",title:o("workPage.sec.catalogs"),meta:t.jsx(vt,{items:[o("workPage.catalog.meta",{n:l.length}),o("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":o("workPage.catalog.tablist"),children:l.map((f,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===p,"aria-label":a(f.source),onClick:()=>m(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:h.get(f.source_bid??"")?a(h.get(f.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...a(f.source)].slice(0,9).map((y,v)=>t.jsx("span",{children:y},v))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d[p].map((f,g)=>t.jsxs("div",{className:"bim-d-lu-entry",children:[f.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(f.title_info)}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[f.source_bid?t.jsx(jt,{id:f.source_bid,label:a(f.source),onNavigate:n,renderLink:r,dense:!0}):a(f.source),f.section?a(f.section):"",f.author_info?`${o("label.authorInfo")} ${a(f.author_info)}`:"",f.edition?`${o("label.edition")} ${a(f.edition)}`:"",f.page??""]}),f.summary&&t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.summary),void 0,{t:o})}),f.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.comment),void 0,{t:o})})]}),f.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.additional_comment),void 0,{t:o})})]}),!f.summary&&!f.comment&&!f.additional_comment&&!f.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:o("workPage.catalog.titleOnly")})]},g)),l.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[p>0?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.prev",{name:a(l[p-1].source)}),onClick:()=>m(p-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(l[p-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[p+1," / ",l.length]}),p<l.length-1?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.next",{name:a(l[p+1].source)}),onClick:()=>m(p+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(l[p+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Ex({workId:e,info:i,transport:n,onNavigate:r,renderLink:o}){const{t:a,convert:l}=oe(),[d,c]=b.useState(1),[m,p]=b.useState(null),[h,u]=b.useState(!1),f=!!(n!=null&&n.getWorkContents);b.useEffect(()=>{if(!(n!=null&&n.getWorkContents))return;let y=!1;return p(null),u(!1),n.getWorkContents(e,d).then(v=>{y||(v?p(v):u(!0))}).catch(()=>{y||u(!0)}),()=>{y=!0}},[n,e,d]);const g=i.pages>1?t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d<=1,onClick:()=>c(y=>y-1),children:a("workPage.contents.prev")}),t.jsx("span",{className:"bim-d-meta",children:a("workPage.contents.page",{page:d,pages:i.pages})}),t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d>=i.pages,onClick:()=>c(y=>y+1),children:a("workPage.contents.next")})]}):null;return t.jsxs(St,{id:"contents",title:a("workPage.sec.contents"),meta:t.jsx(vt,{items:[a("workPage.contents.meta",{n:i.total})]}),children:[f&&g,f&&!m&&!h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.loading")}),f&&h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.error")}),m&&m.length>0&&t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("workPage.contents.vol")}),t.jsx("th",{children:a("workPage.contents.title")}),t.jsx("th",{children:a("workPage.contents.author")})]})}),t.jsx("tbody",{children:m.map((y,v)=>{var j,S;const w=Gr(y.vol),x=v>0?Gr(m[v-1].vol):null;return t.jsxs("tr",{children:[t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w&&w!==x?"":" bim-d-zt-blank"}`,children:w&&w!==x?w:null}),t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:y.id,label:l(y.title??y.id),onNavigate:r,renderLink:o,dense:!0})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${(j=y.au)!=null&&j.length?"":" bim-d-zt-blank"}`,children:(S=y.au)!=null&&S.length?l(y.au.join("、")):null})]},y.id)})})]}),f&&m&&g]})}const Cd=({graph:e,renderLink:i,className:n,style:r})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Ux,...r},className:n,children:o("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const g=l.get(f.target)??[];g.push(f),l.set(f.target,g)}else for(const g of[f.source,f.target]){const y=d.get(g)??[];y.push(f),d.set(g,y)}const c=new Map(e.nodes.map(f=>[f.id,f])),m=new Map,p=[];for(const f of e.nodes)if(f.group){const g=m.get(f.group)??[];g.push(f),m.set(f.group,g)}else p.push(f);const h=(f,g)=>(f.year??9999)-(g.year??9999);m.forEach(f=>f.sort(h)),p.sort(h);const u=e.groups.filter(f=>m.has(f.id));return t.jsxs("div",{className:n,style:{...Tx,...r},children:[e.title&&t.jsx("div",{style:Ix,children:a(e.title)}),e.description&&t.jsx("div",{style:Mx,children:a(e.description)}),u.map(f=>t.jsx(rl,{label:f.label,color:f.color,nodes:m.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i},f.id)),p.length>0&&t.jsx(rl,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},rl=({label:e,color:i,nodes:n,incomingMap:r,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:Ax,children:[t.jsx("div",{style:{...Lx,borderLeftColor:i??s.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(Rx,{node:c,incoming:r.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Rx=({node:e,incoming:i,siblings:n,nodeMap:r,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=oe();return t.jsxs("div",{style:{...Px,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?s.bim("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Ox,children:[t.jsx("span",{style:Fx,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Bx,children:Rl(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Hx,children:[e.category&&t.jsx(Pi,{children:c(e.category)}),e.status==="lost"&&t.jsx(Pi,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Pi,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Pi,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Pi,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Dx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Wx,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:ol,children:[t.jsx("div",{style:al,children:d("lineage.sources")}),i.map(m=>{const p=r.get(m.source);return t.jsxs("div",{style:ll(m.confidence),children:[t.jsx("span",{style:cl,children:c(m.relation)}),t.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&o?o(p.id,c(p.label)):c((p==null?void 0:p.label)??m.source)}),m.confidence!=="consensus"&&m.confidence!=="certain"&&t.jsx(sl,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:dl,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:ol,children:[t.jsx("div",{style:al,children:d("lineage.related")}),n.map(m=>{const p=m.source===e.id?m.target:m.source,h=r.get(p);return t.jsxs("div",{style:ll(m.confidence),children:[t.jsx("span",{style:cl,children:c(m.relation)}),t.jsx("span",{children:(h==null?void 0:h.kind)==="book"&&o?o(h.id,c(h.label)):c((h==null?void 0:h.label)??p)}),t.jsx(sl,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:dl,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Pi=({children:e,tone:i="default"})=>{const r={default:{bg:s.bim("tag-bg"),fg:s.bim("fg")},warn:{bg:s.bim("warn-bg"),fg:s.bim("warn-fg")},info:{bg:s.bim("info-bg"),fg:s.bim("info-fg")}}[i];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},sl=({level:e})=>{const{t:i}=oe(),r={certain:{key:"certain",color:s.bim("confidence-certain")},consensus:{key:"consensus",color:s.bim("confidence-consensus")},probable:{key:"probable",color:s.bim("confidence-probable")},disputed:{key:"disputed",color:s.bim("confidence-disputed")}}[e];return r?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:i(`lineage.confidence.${r.key}`)}):null},Tx={fontSize:"14px",color:s.bim("fg")},Ix={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Mx={fontSize:"13px",color:s.bim("muted"),marginBottom:"16px",lineHeight:1.6},Ax={marginBottom:"16px"},Lx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:s.bim("fg")},Px={border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:s.bim("bg")},Ox={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Fx={fontSize:"15px",fontWeight:600},Bx={fontSize:"12px",color:s.bim("muted")},Hx={marginBottom:"6px"},Dx={fontSize:"12px",color:s.bim("muted"),margin:"2px 0"},Wx={fontSize:"12px",color:s.bim("muted"),fontStyle:"italic",margin:"4px 0"},ol={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${s.bim("widget-border")}`},al={fontSize:"11px",color:s.bim("muted"),marginBottom:"2px"},ll=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),cl={display:"inline-block",padding:"0 6px",fontSize:"11px",background:s.bim("tag-bg"),color:s.bim("fg"),borderRadius:"3px",marginRight:"6px"},dl={fontSize:"11px",color:s.bim("muted")},Ux={padding:"20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px"},Ed=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[r,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Kx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:ul,children:n("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:ul,children:[t.jsx("div",{children:ml(n("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:ml(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Yx,{modules:a,selectedNodeId:e,...i})};function ml(e,i){return e.split(/(\{\w+\})/).map((n,r)=>{const o=/^\{(\w+)\}$/.exec(n);return t.jsx(b.Fragment,{children:o&&o[1]in i?i[o[1]]:n},r)})}async function Kx(){try{const[e,i]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let n=!1;try{await import("@xyflow/react/dist/style.css"),n=!0}catch{n=!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:i,cssLoaded:n}}catch{return null}}const Yx=({graph:e,renderLink:i,height:n=600,className:r,style:o,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:m,Handle:p,Position:h,BaseEdge:u,EdgeLabelRenderer:f,getSmoothStepPath:g,dagre:y}=l,v=b.useMemo(()=>({lineage:N=>{var ae,ce,Ee,we;const z=((ae=N.data)==null?void 0:ae.stepPosition)??.85,[C,U,R]=g({sourceX:N.sourceX,sourceY:N.sourceY,sourcePosition:N.sourcePosition,targetX:N.targetX,targetY:N.targetY,targetPosition:N.targetPosition,stepPosition:z,borderRadius:5}),L=!!((ce=N.data)!=null&&ce.isSibling),F=L?U:N.targetX-18,T=L?R:N.targetY-12,Z=(Ee=N.data)==null?void 0:Ee.labelStyle,O=(we=N.data)==null?void 0:we.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:N.id,path:C,style:N.style,markerStart:N.markerStart,markerEnd:N.markerEnd}),N.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${T}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:s.bim("bg"),border:`0.5px solid ${s.bim("widget-border")}`,...O,...Z},children:N.label})})]})}}),[u,f,g]),w=b.useMemo(()=>({version:N=>{const{t:z}=oe(),C=N.data,U=C.kind==="hypothetical",R=C.status==="lost",L=C.isSelected,F=C.bridge,T=C.borderColor??s.bim("muted"),Z=F||U?"dashed":"solid",O=F?.5:R?.6:1;return t.jsxs("div",{style:{background:F?s.bim("bg-subtle"):s.bim("bg"),border:`2px ${Z} ${L?s.bim("primary"):T}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:L?s.bim("shadow-node-selected"):U||F?"none":s.bim("shadow-node")},title:F?z("lineage.bridgeTitle"):void 0,children:[t.jsx(p,{type:"target",position:h.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:U||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.2},children:Rl(C.yearText,void 0,C.uncertain)}),R&&t.jsx("div",{style:{fontSize:9,color:s.bim("lost-fg"),marginTop:1},children:z("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=oe(),{rfNodes:j,rfEdges:S}=b.useMemo(()=>Gx(e,y,i,a,x),[e,y,i,a,x]);return t.jsx("div",{style:{width:"100%",height:n,...o},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:v,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(m,{showInteractive:!1})]})})};function Gx(e,i,n,r,o=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new i.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const m=new Map(e.groups.map(w=>[w.id,w.color??s.bim("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(p.has(w.relation)||c.setEdge(w.source,w.target));i.layout(c);const h=e.nodes.map(w=>{const x=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:o(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:o(w.year_text??qx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?m.get(w.group):void 0,renderLink:n,isSelected:j,description:o(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:S,draggable:!1,selected:j}}),u=.78,f=.06,g=new Map;for(const w of e.edges)w.kind==="derive"&&(g.has(w.source)||g.set(w.source,[]),g.get(w.source).push(w));const y=new Map;for(const[w,x]of g){if(x.length<=1)continue;const j=[...x].sort(($,N)=>{var U,R;const z=((U=c.node($.target))==null?void 0:U.y)??0,C=((R=c.node(N.target))==null?void 0:R.y)??0;return z-C}),S=j.length;j.forEach(($,N)=>{const z=(N-(S-1)/2)*f;y.set($.id,u+z)})}const v=e.edges.map(w=>Vx(w,y.get(w.id),o));return{rfNodes:h,rfEdges:v}}function Vx(e,i,n=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Xx(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:n(e.relation),data:{labelStyle:{color:s.bim("fg")},isSibling:o,stepPosition:i},style:{stroke:a,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:o?l:void 0,zIndex:1e3}}function qx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Xx(e){switch(e){case"certain":return s.bim("confidence-certain");case"consensus":return s.bim("lineage-edge-consensus");case"probable":return s.bim("confidence-probable");case"disputed":return s.bim("confidence-disputed");default:return s.bim("muted")}}const ul={padding:"40px 20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px",border:`1px dashed ${s.bim("widget-border")}`,borderRadius:8,background:s.bim("bg")},lo=({graph:e,defaultMode:i="list",renderLink:n,graphHeight:r=600,selectedNodeId:o,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:m,className:p,style:h})=>{var S;const{t:u,convert:f}=oe(),[g,y]=b.useState(i),v=$=>{y($),a==null||a($)},w=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:s.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:p,style:h,children:[t.jsxs("div",{style:Jx,children:[t.jsx("button",{onClick:()=>v("list"),style:Hr(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>v("graph"),style:Hr(g==="graph"),children:u("lineage.modeGraph")}),x&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:s.bim("muted"),marginRight:4},children:u("lineage.collectionLabel")}),w.map(([$,N])=>{const z=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Hr(l===$),title:N.description?f(N.description):void 0,children:[f(N.label),z!=null?` ${z}`:""]},$)})]})]}),x&&j&&t.jsx("div",{style:{fontSize:12,color:s.bim("muted"),marginBottom:8,padding:"4px 8px",background:s.bim("bg-subtle"),borderRadius:4},children:f(j)}),g==="list"?t.jsx(Cd,{graph:e,renderLink:n}):t.jsx(Ed,{graph:e,renderLink:n,height:r,selectedNodeId:o})]})},Jx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Hr=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${s.bim("widget-border")}`,borderRadius:4,background:e?s.bim("primary"):"transparent",color:e?s.bim("primary-fg"):s.bim("fg"),cursor:"pointer"}),pl=40,bl=2,Zx=9,Qx=new Set(["certain","consensus","probable","disputed"]);function Dr(e){if(!e)return["",""];const i=e.split(/[  ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const Rd=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Oe,Je,Pe,Ue,nt,Y,M,k,P,q;const h=s.useT(),{t:u,convert:f}=oe(),[g,y]=b.useState(null),[v,w]=b.useState(new Map),[x,j]=b.useState([]),[S,$]=b.useState(new Map),[N,z]=b.useState(!1),[C,U]=b.useState("flow"),[R,L]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let _=!1;return i.getItem(e.work_id).then(le=>{!_&&le&&le.type==="work"&&y(le)}).catch(()=>{}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){L(null);return}let _=!1;return i.getLineageGraph(e.work_id).then(le=>{_||L(le&&le.nodes.length>1?le:null)}).catch(()=>{_||L(null)}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{const _=e._collections||[];if(!i||_.length===0){w(new Map);return}let le=!1;return Promise.all(_.map(H=>{const he=H.id;return i.getItem(he).then(xe=>[he,xe]).catch(()=>[he,null])})).then(H=>{if(le)return;const he=new Map;for(const[xe,Re]of H)Re&&he.set(xe,Re);w(he)}),()=>{le=!0}},[i,e._collections]);const F=b.useMemo(()=>{const _=new Set([...g?Ss(g):[],...wu(e)]);return _.add(e.id),[..._]},[g,e.related_books,e.id]),T=F.length-1;b.useEffect(()=>{if(!i||T<=0){j([]);return}const _=F.length<=pl,le=_?F:F.slice(0,8);let H=!1;return Promise.all(le.map(he=>he===e.id?Promise.resolve({id:he,title:e.title,edition:e.edition,year:Mn(e)}):i.getItem(he).then(xe=>{const Re=xe??{};return{id:he,title:Re.title,edition:Re.edition,year:xe?Mn(Re):void 0}}).catch(()=>({id:he})))).then(he=>{if(H)return;const xe=he.filter(Re=>Re.id===e.id||Re.title||Re.edition);_&&xe.sort((Re,Ze)=>(Re.year??1/0)-(Ze.year??1/0)),j(xe)}),()=>{H=!0}},[i,F,T,e]),e.lineage;const Z=b.useMemo(()=>[...Vt(e).filter(_=>_.ref_type==="book").map(_=>_.ref),...ti(e).map(_=>_.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||Z.length===0){$(new Map);return}let _=!1;return Promise.all(Z.map(le=>i.getItem(le).then(H=>[le,{id:le,title:H==null?void 0:H.title,edition:H==null?void 0:H.edition}]).catch(()=>[le,{id:le}]))).then(le=>{_||$(new Map(le))}),()=>{_=!0}},[i,Z]);const O=b.useMemo(()=>$d(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),ae=O.groups.reduce((_,le)=>_+le.rows.length+le.mirrors.length,0),ce=O.groups.length>0&&O.groups.every(_=>_.key==="_physical"),Ee=Ji(e),we=Wl(e),ye=qt(e,h.unit.juan),Q=new Set((e._collections||[]).map(_=>Wi(_.vol).length).filter(_=>_>0)),Ne=_=>{var he;const le=(he=e.base_edition)==null?void 0:he.find(xe=>xe.book_id===_&&xe.name);if(le!=null&&le.name)return le.name;const H=S.get(_);return(H==null?void 0:H.edition)||(H==null?void 0:H.title)||""},W=b.useMemo(()=>{var He,ct;const _=[];we&&_.push({label:u("bookPage.fact.editionType"),value:f(we),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(He=e.publication_info)!=null&&He.details?_.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(Ee.era||Ee.reign)&&_.push({label:u("bookPage.fact.era"),value:f([Ee.era,Ee.reign].filter(Boolean).join(" ")),title:Ee.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),ye&&_.push({label:u("bookPage.fact.measure"),value:f(ye)});const le=(e._collections||[]).flatMap(Be=>Wi(Be.vol));le.length&&_.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Yn(le,h.unit.volume),unit:h.unit.volume,n:le.length})});const H=Vt(e).find(Be=>Be.relation==="底本"&&Be.ref_type==="book");H&&Ne(H.ref)&&_.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(jt,{id:H.ref,label:f(Ne(H.ref)),onNavigate:n,renderLink:r,dense:!0})});const he=(e.base_edition||[]).filter(Be=>Be&&Be.name);for(const Be of["底本","配補","參校"]){if(Be==="底本"&&H&&Ne(H.ref))continue;const ee=he.filter(Se=>Se.role===Be);ee.length&&_.push({label:f(Be),value:ee.map((Se,et)=>t.jsxs(b.Fragment,{children:[et>0&&"、",Se.book_id?t.jsx(jt,{id:Se.book_id,label:f(Se.name),onNavigate:n,renderLink:r,dense:!0}):f(Se.name)]},et))})}const xe=(e.provenance||[]).filter(Be=>Be&&Be.institution),Re=(e.resources||[]).filter(Be=>s.getResourceTypes(Be).includes("physical"));if(xe.length){_.push({label:u("bookPage.fact.holdings"),value:xe.slice(0,2).map(Se=>f(Se.institution)).join("、")+(xe.length>2?u("bookPage.andMorePlaces",{n:xe.length}):"")});const Be=xe.filter(Se=>Se.call_number).slice(0,2).map(Se=>`${f(Se.institution)} ${Se.call_number}`);Be.length&&_.push({label:u("bookPage.fact.callNumber"),value:Be.join(";")+(xe.filter(Se=>Se.call_number).length>2?"…":"")});const ee=xe.flatMap(Se=>Se.seals||[]).filter(Boolean);ee.length&&_.push({label:u("bookPage.fact.seals"),value:f(ee.join("、"))})}else Re.length&&_.push({label:u("bookPage.fact.holdings"),value:Re.slice(0,2).map(Be=>f(Be.name)).join("、")+(Re.length>2?u("bookPage.andMorePlaces",{n:Re.length}):"")});const Ze=e.physical_description;if(Ze){const Be=[[u("bookPage.fact.leafStyle"),Ze.leaf_style],[u("bookPage.fact.binding"),Ze.binding],[u("bookPage.fact.dimensions"),Ze.dimensions],[u("bookPage.fact.condition"),Ze.condition]];for(const[ee,Se]of Be)Se&&Se.trim()&&_.push({label:ee,value:f(Se)})}(ct=e.page_count)!=null&&ct.description&&_.push({label:h.label.pageCount,value:f(e.page_count.description)});const Me=Ic(e.additional_titles);return Me.length&&_.push({label:u("bookPage.fact.aliases"),value:Me.map(f).join("、")}),_},[e,f,h,u,Ee,we,ye,S,n,r]),je=f(e.title),K=e.edition?f(e.edition):void 0,V=((Oe=e.dating)==null?void 0:Oe.text)||"",re=t.jsx(tn,{kind:u("bookPage.kind"),title:je,subtitle:K,byline:t.jsx(oo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:r}),meta:(()=>{const _=[we?f(we):"",Ee.era?f([Ee.era,Ee.reign].filter(Boolean).join("")):"",ye?f(ye):""].filter(Boolean);return _.length?t.jsx("span",{className:"bim-d-tags",children:_.map((le,H)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(H,2)}`,children:le},H))}):null})(),description:(Je=e.description)!=null&&Je.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Pe=e.description)==null?void 0:Pe.text)?6:void 0,facts:W,readAction:o,secondaryAction:o&&ae>0&&!ce?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),X=e._collections||[],I=(a==null?void 0:a.chapters)||[],ue=f(I[0]&&Dr(I[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),fe=u("bookPage.chapterCount",{n:I.length,unit:ue}),ze=!!(Vt(e).length||ti(e).length||(Ue=e.appendix)!=null&&Ue.length),B=[],pe=u(ce?"bookPage.sec.physical":"bookPage.sec.images");(I.length||O.text.length||l)&&B.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:I.length?fe:void 0}),O.groups.length&&B.push({id:"images",label:pe,count:ae}),ze&&B.push({id:"lineage",label:u("bookPage.sec.lineage")}),X.length&&B.push({id:"collections",label:u("section.containedIn"),count:X.length}),(nt=e.location_history)!=null&&nt.length&&B.push({id:"provenance",label:u("section.locationHistory")});const Te=_=>(d==null?void 0:d(_))??null,ve=I[0],Ve=ve?Te(ve.file):null,qe=N?I:I.slice(0,Zx),Xe=(_,le,H)=>_?t.jsx("a",{className:H,href:_.href??"#",onClick:_.onClick?he=>{he.metaKey||he.ctrlKey||(he.preventDefault(),_.onClick())}:void 0,children:le}):t.jsx("span",{className:H,children:le}),J=t.jsxs(t.Fragment,{children:[(I.length>0||O.text.length>0||l)&&t.jsxs(St,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:I.length>0?t.jsx(vt,{items:[fe,(Y=a==null?void 0:a.source)!=null&&Y.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!ve&&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"})]}),ve&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Dr(ve.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((ve.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),Xe(Ve,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),I.length>1&&t.jsx("ul",{className:"bim-d-chap",children:qe.map(_=>{const[le,H]=Dr(_.title);return t.jsx("li",{children:Xe(Te(_.file),t.jsxs(t.Fragment,{children:[le&&t.jsx("b",{children:f(le)}),f(H||_.file)]}))},_.file)})}),I.length>qe.length&&t.jsx(Ts,{label:u("detail.expandRest",{n:I.length-qe.length,unit:ue}),onClick:()=>z(!0)}),O.text.length>0&&t.jsxs(t.Fragment,{children:[(I.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:O.text.map((_,le)=>t.jsx(ao,{item:_,siblings:O.text,listedVolumeCounts:Q},`${_.id||_.url||_.name}-${le}`))})})]})]}),O.groups.length>0&&t.jsx(St,{id:"images",title:pe,meta:t.jsx(vt,{items:[O.groups.length>1?u("bookPage.groupCount",{n:O.groups.length}):"",u("bookPage.placeCount",{n:ae})]}),children:t.jsx(Nd,{groups:O.groups,listedVolumeCounts:Q})}),ze&&t.jsx(St,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Vt(e).length?u("bookPage.lineageMeta"):void 0,action:R?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":C==="flow",onClick:()=>U("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>U("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&R?t.jsx(lo,{graph:R,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(_,le)=>t.jsx(jt,{id:_,label:f(le),onNavigate:n,renderLink:r,dense:!0})}):t.jsx(t0,{data:e,heading:K||je,yearText:V,refName:Ne,onNavigate:n,renderLink:r})}),X.length>0&&t.jsx(St,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:X.map((_,le)=>{const H=_.id,he=Wi(_.vol),xe=v.get(H),Re=Gu(xe);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:H,label:xe?f(xe.title):H,onNavigate:n,renderLink:r,dense:!0}),he.length>0&&t.jsx(e0,{volumes:he,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Re?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Re>0&&u("bookPage.totalOf",{n:Re,unit:h.unit.bu})})]},`${H}-${le}`)})})})}),(M=e.location_history)!=null&&M.length?t.jsx(St,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((_,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(_.name||_.location||"")}),([_.start_date,_.end_date].filter(Boolean).join("—")||_.description||_.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[_.start_date,_.end_date].filter(Boolean).join("—"),_.description?f(_.description):"",_.note?f(_.note):""]})})]},le))})}):null,B.length===0&&t.jsx(St,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),ie=x.findIndex(_=>_.id===e.id),me=F.length<=pl,se=me&&ie>=0?x.slice(Math.max(0,ie-bl),ie+bl+1):x.filter(_=>_.id!==e.id),de=t.jsxs(t.Fragment,{children:[g&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:f(h.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(jt,{id:g.id,label:f(g.title),onNavigate:n,renderLink:r})}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(_=>`${_.dynasty?`〔${f(_.dynasty)}〕`:""}${f(_.name)}`),f(qt(g,h.unit.juan)),g._edition_count??((k=g._books)==null?void 0:k.length)?u("bookPage.editionCount",{n:g._edition_count??((P=g._books)==null?void 0:P.length)??0}):""]}),((q=g.description)==null?void 0:q.text)&&t.jsx("p",{style:{fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc bim-d-side-desc",children:f(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),T>0&&se.length>0&&t.jsxs("div",{children:[t.jsx(mi,{id:"siblings",timeline:!0,title:me?u("bookPage.siblings"):h.relation.siblingVersions,meta:me?u("bookPage.byEra"):u("bookPage.kindCount",{n:T}),cap:se.length,items:se.map(_=>_.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(_.edition||_.title||_.id)}):t.jsx(jt,{id:_.id,label:f(_.edition||_.title||_.id),onNavigate:n,renderLink:r,dense:!0})),metas:se.map(_=>[_.year!=null?_.year<0?u("detail.bce",{n:-_.year}):String(_.year):"",_.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:se.findIndex(_=>_.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(jt,{id:g.id,label:u("bookPage.viewAllInWork",{n:F.length}),onNavigate:n,renderLink:r,dense:!0})})]})]}),ge=e.work_id?t.jsx(jc,{caption:h.section.belongsToWork,children:t.jsx(jt,{id:e.work_id,label:g?f(g.title):" ",onNavigate:n,renderLink:r,dense:!0})}):void 0;return t.jsx(Zi,{railTop:c,back:m,up:ge,nav:B,railLinks:p,main:J,card:re,side:de})};function e0({volumes:e,unit:i}){const{t:n}=oe();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Yn(e,i),unit:i}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),n("bookPage.volumeCount",{n:e.length,unit:i})]})]})}function t0({data:e,heading:i,yearText:n,refName:r,onNavigate:o,renderLink:a}){var w;const{t:l,convert:d}=oe(),c=e.lineage,m=Vt(e),p=m.filter(x=>x.ref_type!=="book"),h=m.filter(x=>x.ref_type==="book"&&x.relation==="底本"),u=m.filter(x=>x.ref_type==="book"&&x.relation!=="底本"),f=ti(e),g=m.length>0||f.length>0,y=x=>x&&Qx.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",v=(x,j)=>t.jsx(jt,{id:x,label:d(j||x),onNavigate:o,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[p.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:x.relation?d(x.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),x.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(x.evidence),y(x.confidence)]})]})},`a-${j}`)),h.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:i}),n&&t.jsx("span",{className:"bim-d-lf-yr",children:d(n)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((x,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},j))})]}),f.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((x,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[v(x.book_id,r(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((x,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(x.title)]}),t.jsx(zi,{text:x.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Oi=16,i0=200,n0=16,Td=({data:e,catalog:i,transport:n,onNavigate:r,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var me,se,de,ge,Oe,Je,Pe,Ue,nt;const{t:m,convert:p,messages:h}=oe(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[v,w]=b.useState(null),[x,j]=b.useState(""),[S,$]=b.useState(!1),N=b.useMemo(()=>Dl(e,i),[e,i]),z=b.useMemo(()=>Hl(e),[e]),[C,U]=b.useState(new Map),R=!!n&&N.rows.length>0&&N.rows.length<=i0,L=R&&(N.rows.length<=Oi||S),F=L&&N.rows.every(Y=>!Y.id||C.has(Y.id)),T=Y=>{var M;return us(Y?(M=C.get(Y))==null?void 0:M.l1:void 0)},Z=b.useMemo(()=>{const Y=u.trim(),M=Y?p(Y):"";return N.rows.filter(k=>{var q,_;if(x&&us(k.id?(q=C.get(k.id))==null?void 0:q.l1:void 0)!==x)return!1;if(!M)return!0;const P=k.id&&((_=C.get(k.id))==null?void 0:_.title)||k.title;return p(P).includes(M)||(k.subItems||[]).some(le=>p(le).includes(M))})},[N.rows,u,x,C,p]),O=g?Z:Z.slice(0,Oi),ae=b.useMemo(()=>(L?N.rows:O).filter(Y=>Y.id&&!C.has(Y.id)).map(Y=>Y.id),[L,N.rows,O,C]);b.useEffect(()=>{if(!n||ae.length===0)return;let Y=!1;const M=ae.slice(0,n0);return tr(M,er,k=>n.getItem(k).then(P=>{var le,H;const q=P??{},_={title:q.title,edition:q.edition,authors:q.authors,measure:P?qt(P,h.unit.juan):void 0,versionCount:q._edition_count??((le=q._books)==null?void 0:le.length),l1:((H=$s(q))==null?void 0:H.l1)||void 0};return[k,_]}).catch(()=>[k,{}]),()=>Y).then(k=>{Y||U(P=>{const q=new Map(P);for(const[_,le]of k)q.set(_,le);return q})}),()=>{Y=!0}},[n,ae,h.unit.juan]);const ce=(me=(e.contained_in||[])[0])==null?void 0:me.id;b.useEffect(()=>{if(!ce){w(null);return}if(w({id:ce}),!n)return;let Y=!1;return n.getItem(ce).then(M=>{Y||w({id:ce,title:M==null?void 0:M.title})}).catch(()=>{}),()=>{Y=!0}},[n,ce]);const Ee=b.useMemo(()=>$d(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),we=Ee.text.length+Ee.groups.reduce((Y,M)=>Y+M.rows.length+M.mirrors.length,0),ye=z.works,Q=new Set(N.rows.map(Y=>Y.id).filter(Boolean)),Ne=ye.length>0&&!ye.every(Y=>Q.has(Y.id)),W=(()=>{const Y=N.rows.map(M=>M.edition).filter(Boolean);return Y.length>1&&new Set(Y).size===1})(),je=N.rows.some(Y=>Y.volumes.length>0||Y.expected!=null),K=z.total,V=z.truncated?K:N.rows.length,re=qt(e,h.unit.juan),X=e.count,I=Y=>typeof Y=="number"&&Number.isFinite(Y)?Y:null,ue=I(X==null?void 0:X.juan)??I((se=e.juan_count)==null?void 0:se.number)??I((ge=(de=e.measures)==null?void 0:de.find(Y=>(Y==null?void 0:Y.unit)==="卷"))==null?void 0:ge.number),fe=I(X==null?void 0:X.ce)??(N.totalVolumes||null),ze=[{value:V,label:m("collectionPage.stat.titles")},{value:ue??0,label:h.unit.juan},{value:fe??0,label:h.unit.volume}],B=b.useMemo(()=>{var k,P;const Y=[];if((k=e.publication_info)!=null&&k.details&&Y.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),K&&(K!==N.rows.length||z.truncated)){const q=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");Y.push({label:q,value:`${K} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const M=[I(X==null?void 0:X.zhong)!=null?m("collectionPage.nZhong",{n:X.zhong}):"",I(X==null?void 0:X.han)!=null?m("collectionPage.nHan",{n:X.han}):""].filter(Boolean);return M.length&&Y.push({label:m("collectionPage.fact.expected"),value:M.join(" ")}),ue==null&&re&&Y.push({label:m("collectionPage.fact.measure"),value:p(re),title:(P=e.juan_count)!=null&&P.description?p(e.juan_count.description):void 0}),Y},[e,K,z.truncated,N.rows.length,ue,re,X,p,m,h]),pe=b.useMemo(()=>{if(!F)return[];const Y=new Map;for(const k of N.rows){const P=T(k.id);P&&Y.set(P,(Y.get(P)??0)+1)}const M=Yi.filter(k=>(Y.get(k.key)??0)>0);return M.length<2?[]:[{key:"",label:`${h.catalog.all} ${V}`},...M.map(k=>({key:k.key,label:`${k.label} ${Y.get(k.key)}`}))]},[F,N.rows,C,h]),Te=b.useMemo(()=>{if(!F||!N.rows.some(P=>P.volumes.length>0))return null;const Y=[],M=N.rows.filter(P=>P.volumes.length>0).map(P=>({k:T(P.id)??"",from:Math.min(...P.volumes),to:Math.max(...P.volumes)})).sort((P,q)=>P.from-q.from);for(const P of M){const q=P.to-P.from+1,_=Y[Y.length-1];_&&_.key===P.k?(_.to=Math.max(_.to,P.to),_.n+=q):Y.push({key:P.k,from:P.from,to:P.to,n:q})}const k=M.reduce((P,q)=>Math.max(P,q.to),0);return Y.length>1&&Y.some(P=>P.key)?{segs:Y,last:k}:null},[F,N.rows,C]),ve=(Oe=e.description)==null?void 0:Oe.text,Ve=t.jsx(tn,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:r,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(Je=e.publication_info)!=null&&Je.year?p(e.publication_info.year):""]}),description:ve||(Pe=e.history)!=null&&Pe.length?t.jsxs(t.Fragment,{children:[ve&&t.jsx(zi,{text:ve,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((Y,M)=>t.jsx("li",{children:p(Y)},M))}):null]}):void 0,clampDescription:Is(ve)||(((nt=e.history)==null?void 0:nt.length)??0)>2?6:void 0,stats:ze,facts:B,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:Te&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:m("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":m("collectionPage.dist.head"),children:Te.segs.map((Y,M)=>{const k=Yi.find(P=>P.key===Y.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!k,title:k?m("collectionPage.dist.segTitle",{section:p(k.label),from:Y.from,to:Y.to}):void 0,"aria-label":k?m("collectionPage.dist.only",{section:p(k.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!k&&x===Y.key,style:{flexGrow:Y.n,background:k?s.bim(k.token):s.bim("rule")},onClick:()=>{k&&(j(x===Y.key?"":Y.key),y(!1))}},M)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:m("catalog.volume",{n:1})}),t.jsx("span",{children:m("collectionPage.dist.hint")}),t.jsx("span",{children:m("catalog.volume",{n:Te.last})})]})]})}),qe=[];N.rows.length&&qe.push({id:"titles",label:m("collectionPage.sec.titles"),count:V}),we&&qe.push({id:"resources",label:m("collectionPage.sec.resources"),count:we}),Ne&&qe.push({id:"works",label:h.section.containedWorks,count:ye.length});const Xe=t.jsxs(t.Fragment,{children:[N.rows.length>0&&t.jsxs(St,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${V} ${h.unit.items}`,N.totalVolumes?m("collectionPage.totalVolumes",{n:N.totalVolumes,unit:h.unit.volume}):"",Z.length!==V?m("collectionPage.currentN",{n:Z.length,unit:h.unit.items}):""]}),action:a,children:[(N.rows.length>Oi||pe.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[pe.length>0&&t.jsx(Qi,{items:pe,value:x,onChange:Y=>{j(Y),y(!1)}}),R&&N.rows.length>Oi&&!F&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>$(!0),title:m("collectionPage.loadAllTitle",{n:N.rows.length,unit:h.unit.items}),children:m(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),N.rows.length>Oi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:Y=>{f(Y.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(Z.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[je&&t.jsx("th",{style:{width:"8.5em"},children:m("collectionPage.col.volumes")}),t.jsx("th",{children:m("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:m("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:O.map((Y,M)=>{var he;const k=Y.id?C.get(Y.id):void 0,P=k!=null&&k.title&&Y.title===Y.id?k.title:Y.title,q=((k==null?void 0:k.authors)||[]).find(xe=>xe&&xe.name),_=[q?`${q.dynasty?`〔${p(q.dynasty)}〕`:""}${p(q.name)}${q.role?` ${p(q.role)}`:""}`:"",k!=null&&k.measure?p(k.measure):"",(he=Y.subItems)!=null&&he.length?Y.subItems.map(xe=>p(xe)).join("、"):"",(k!=null&&k.edition||Y.edition)&&!W?p((k==null?void 0:k.edition)||Y.edition||""):""].filter(Boolean),le=Yi.find(xe=>xe.key===T(Y.id)),H=Y.volumes.length>0?m("collectionPage.volumeRange",{range:Yn(Y.volumes,h.unit.volume),unit:h.unit.volume}):Y.expected!=null?`${Y.found??0}/${Y.expected} ${h.unit.volume}`:"";return t.jsxs("tr",{children:[je&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H?"":" bim-d-zt-blank"}`,children:[le&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:s.bim(le.token)}}),H||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[Y.id?t.jsx(jt,{id:Y.id,label:p(P),onNavigate:r,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(P)}),_.length>0?t.jsx(vt,{items:_}):Y.id&&!k&&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${k!=null&&k.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:k!=null&&k.versionCount?m("collectionPage.nZhong",{n:k.versionCount}):""})]},`${Y.id??Y.title}-${M}`)})})]}),O.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:m("catalog.noMatch")}),!g&&t.jsx(Jn,{total:Z.length,shown:O.length,unit:h.unit.items,onClick:()=>y(!0)})]}),we>0&&t.jsxs(St,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:we}),children:[Ee.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[Ee.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:m("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Ee.text.map((Y,M)=>t.jsx(ao,{item:Y,siblings:Ee.text},`${Y.id||Y.url||Y.name}-${M}`))})})]}),t.jsx(Nd,{groups:Ee.groups})]}),N.rows.length===0&&we===0&&t.jsx(St,{title:m("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("collectionPage.empty")})})]}),J=Ne?t.jsx(mi,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:ye.length}),cap:12,items:ye.map(Y=>t.jsx(jt,{id:Y.id,label:p(Y.title),onNavigate:r,renderLink:o,dense:!0}))}):null,ie=v?t.jsx(jc,{caption:m("collectionPage.parent"),children:t.jsx(jt,{id:v.id,label:p(v.title||v.id),onNavigate:r,renderLink:o,dense:!0})}):void 0;return t.jsx(Zi,{railTop:l,back:d,up:ie,nav:qe,railLinks:c,main:Xe,card:Ve,side:J})},r0=8;function Id(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function s0(e){return(e||[]).filter(i=>{var n,r;return Id(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((r=i.license)==null?void 0:r.trim())}).slice(0,r0)}function o0({images:e,assetBase:i,name:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?s0(e):[];if(!i||d||m.length===0)return null;const p=i.endsWith("/")?i:i+"/",h=m[Math.min(a,m.length-1)],u=h.width&&h.height&&h.width>0&&h.height>0?`${h.width} / ${h.height}`:void 0,f=g=>p+Id(g.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:f(h),alt:r("entityPage.sealAlt",{name:n})+(m.length>1?` ${a+1}`:""),style:u?{"--seal-ar":u}:void 0,width:h.width,height:h.height,decoding:"async",fetchPriority:"high",onError:()=>c(!0)},h.file),m.length>1&&t.jsx("div",{className:"bim-d-seal-thumbs",children:m.map((g,y)=>t.jsx("button",{type:"button","aria-pressed":y===a,"aria-label":`${r("entityPage.sealAlt",{name:n})} ${y+1}`,onClick:()=>l(y),children:t.jsx("img",{src:f(g),alt:"",loading:"lazy",decoding:"async"})},g.file))}),t.jsxs("figcaption",{children:[r("entityPage.imgCredit",{credit:o(h.credit)})," · ",r("entityPage.imgLicense",{license:o(h.license)}),h.source_url&&/^https?:\/\//i.test(h.source_url)&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:h.source_url,target:"_blank",rel:"noopener noreferrer nofollow",children:r("entityPage.imgSource")})]}),h.note&&t.jsxs(t.Fragment,{children:[" · ",o(h.note)]})]})]})}const hl=8,fl=10,gl=30,Md=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function a0(e){return`${Md(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function l0(e,i,n){var r;return`${Md(i,n.key,n.chapter)}#e=${((r=n.ids)!=null&&r.length?n.ids:[e]).join(",")}`}const c0=({id:e,transport:i,renderLink:n,onTotal:r})=>{const{t:o,convert:a}=oe(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(hl),[u,f]=b.useState(fl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),v=b.useRef(r);if(v.current=r,b.useEffect(()=>{if(d(null),m("idle"),h(hl),f(fl),!y)return;const $=g.current;let N=!1;const z=()=>{m("loading"),i.getMentions(e).then(U=>{var L,F;if(N)return;const R=U&&"books"in U?U:null;if(!R||!R.total){m("none"),(L=v.current)==null||L.call(v,0);return}d(R),m("ok"),(F=v.current)==null||F.call(v,R.total)}).catch(()=>{N||m("none")})};if(!$||typeof IntersectionObserver>"u")return z(),()=>{N=!0};const C=new IntersectionObserver(U=>{U.some(R=>R.isIntersecting)&&(C.disconnect(),z())},{rootMargin:"400px"});return C.observe($),()=>{N=!0,C.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const w=($,N,z)=>n?n($,N,z):t.jsx("a",{className:z,href:$,children:N}),x=new Map(((l==null?void 0:l.books)??[]).map($=>[$.item,$.title])),j=(l==null?void 0:l.examples)??[],S=(l==null?void 0:l.books)??[];return t.jsx("div",{ref:g,children:t.jsxs(St,{id:"mentions",title:o("mentions.title"),meta:l?t.jsx(vt,{items:[o("mentions.total",{n:l.total,b:S.length})]}):void 0,children:[!l&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:o("mentions.loading")}),l&&t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:o("mentions.hint")}),l&&j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.examples")}),t.jsx("ol",{className:"bim-d-mentions",children:j.slice(0,p).map(($,N)=>{const z=[x.get($.item),$.heading].filter(Boolean).map(U=>a(U)).join(" · "),C=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-mention-where bim-d-ui",children:z||$.chapter}),t.jsxs("span",{className:"bim-d-mention-ctx",children:[$.before?"…":"",a($.before),t.jsx("b",{children:a($.text)}),a($.after),$.after?"…":""]})]});return t.jsx("li",{children:w(a0($),C,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${N}`)})}),j.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(j.length),children:o("mentions.more",{n:j.length-p})})]}),l&&S.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.byBook")}),t.jsx("ul",{className:"bim-d-mbooks",children:S.slice(0,u).map($=>t.jsx(d0,{entityId:e,book:$,open:S.length===1,transport:i,link:w},$.item))}),S.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+gl),children:o("mentions.moreBooks",{n:Math.min(gl,S.length-u)})})]})]})})},d0=({entityId:e,book:i,open:n,transport:r,link:o})=>{const{t:a,convert:l}=oe(),[d,c]=b.useState(i.chapters??null),[m,p]=b.useState(!1);b.useEffect(()=>{c(i.chapters??null)},[i]);const h=u=>{!u.currentTarget.open||d||m||!(r!=null&&r.getMentions)||(p(!0),r.getMentions(e,i.item).then(f=>{f&&"chapters"in f&&Array.isArray(f.chapters)&&c(f.chapters)}).catch(()=>{}).finally(()=>p(!1)))};return t.jsx("li",{children:t.jsxs("details",{className:"bim-d-mbook",open:n,onToggle:h,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"bim-d-mbook-t",children:l(i.title??i.item)}),t.jsx("span",{className:"bim-d-mbook-n bim-d-ui",children:a("mentions.bookLine",{n:i.count,c:i.chapter_count})})]}),m&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"0 0 8px 40px"},children:a("mentions.loading")}),d&&t.jsx("ul",{className:"bim-d-mchaps",children:d.map(u=>t.jsx("li",{children:o(l0(e,i.item,u),t.jsxs(t.Fragment,{children:[t.jsx("span",{children:u.heading?`${u.chapter} · ${l(u.heading)}`:u.chapter}),t.jsx("span",{className:"bim-d-ui",children:a("mentions.chapterLine",{n:u.count})})]}),"bim-d-mchap")},`${u.key}|${u.chapter}`))})]})})},m0=16,u0=30,Wr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function xl(e){if(!e)return Wr.length;const i=Wr.indexOf(e);return i===-1?Wr.length:i}function p0(e,i,n){if(i)return e[i]??n(i)}function b0(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const h0={秦:[-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]},Ad=({data:e,transport:i,onNavigate:n,renderLink:r,railTop:o,back:a,railLinks:l,assetBase:d})=>{var Je,Pe,Ue,nt,Y,M;const{t:c,convert:m,messages:p}=oe(),h=k=>b0(k,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[v,w]=b.useState("default"),[x,j]=b.useState(new Map),[S,$]=b.useState(0),N=b.useMemo(()=>(e._works||[]).filter(k=>!Qo(k.st)),[e._works]),z=b.useMemo(()=>(e._works||[]).filter(k=>Qo(k.st)),[e._works]),C=b.useMemo(()=>N.map(k=>{const P=x.get(k.work_id);return{id:k.work_id,title:(P==null?void 0:P.title)??k.title??k.work_id,role:k.role||"",cls:ws(k.role),versionCount:P==null?void 0:P.versionCount,section:P==null?void 0:P.cls,l1:P==null?void 0:P.l1,measure:P==null?void 0:P.measure,hasImage:P==null?void 0:P.hasImage,loaded:!!(P!=null&&P.loaded)}}),[N,x]),U=b.useMemo(()=>Bl(N.map(k=>k.role),c("detail.roleAll")),[N,c]),R=b.useMemo(()=>{const k=u==="全部"?C:C.filter(P=>P.cls===u);return v==="versions"?[...k].sort((P,q)=>(q.versionCount??-1)-(P.versionCount??-1)):k},[C,u,v]),L=g?R:R.slice(0,m0),F=b.useMemo(()=>L.filter(k=>!x.has(k.id)).map(k=>k.id),[L,x]);b.useEffect(()=>{if(!i||F.length===0)return;let k=!1;return tr(F,er,P=>i.getItem(P).then(q=>{var xe;const _=q??{},le=_._edition_count??((xe=_._books)==null?void 0:xe.length)??0,H=$s(_),he=[H==null?void 0:H.l1,H==null?void 0:H.l2].filter(Boolean).join(" ");return[P,{id:P,title:_.title,versionCount:le,loaded:!0,cls:he||void 0,l1:(H==null?void 0:H.l1)||void 0,measure:q&&qt(q,p.unit.juan)||void 0,hasImage:!!_._has_image}]}).catch(()=>[P,{id:P,loaded:!0}]),()=>k).then(P=>{k||j(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,F,p.unit.juan]);const T=b.useMemo(()=>{const k=new Map;for(const P of e.alt_names||[]){const q=P.type||p.section.aliases;k.has(q)||k.set(q,[]),k.get(q).push(P.name)}return[...k.entries()].sort((P,q)=>xl(P[0])-xl(q[0])).map(([P,q])=>({label:P,names:q}))},[e.alt_names,p]),Z=((Je=e.dates)==null?void 0:Je.birth)??void 0,O=((Pe=e.dates)==null?void 0:Pe.death)??void 0,ae=(Ue=e.dates)==null?void 0:Ue.floruit,ce=Z!=null||O!=null?`${h(Z)||"?"}—${h(O)||"?"}`:Array.isArray(ae)&&ae.length===2&&ae.every(k=>Number.isFinite(k))?c("entityPage.floruit",{from:h(ae[0]),to:h(ae[1])}):"",Ee=new Set(["本名","字","號","号"]),we=T.filter(k=>Ee.has(k.label)),ye=T.filter(k=>!Ee.has(k.label)),Q=ye.reduce((k,P)=>k+P.names.length,0),Ne=b.useMemo(()=>{const k=[];for(const q of we)k.push({label:q.label,value:q.names.map(_=>m(_)).join("、")});const P=N.length;return P&&k.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:P})}),z.length&&k.push({label:c("entityPage.fact.pieces"),value:c("entityPage.nPian",{n:z.length})}),k},[N,z,we,m,c]),W=k=>{var P;return(P=T.find(q=>k.includes(q.label)))==null?void 0:P.names[0]},je=W(["字"]),K=W(["號","号"]),V=[je?c("entityPage.zi",{name:m(je)}):"",K?c("entityPage.hao",{name:m(K)}):""].filter(Boolean).join(","),re=e.native_place,X=e.dynasty?h0[e.dynasty]:void 0,I=(()=>{if(!X||Z==null||O==null||O<Z)return null;const[k,P]=X,q=Math.max(Z,k),_=Math.min(O,P);if(_<=q)return null;const le=P-k;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:h(Z),death:h(O),years:O-Z+1}),children:t.jsx("i",{style:{left:`${(q-k)/le*100}%`,width:`${(_-q)/le*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${h(k)} ${m(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:O-Z+1})}),t.jsx("span",{children:h(P)})]})]})})(),ue=b.useMemo(()=>{if(!i||C.length===0||C.some(q=>!q.loaded))return null;const k=new Map;for(const q of C){const _=us(q.l1);_&&k.set(_,(k.get(_)??0)+1)}const P=Yi.map(q=>({...q,n:k.get(q.key)??0})).filter(q=>q.n>0);return P.length?P:null},[C,i]),fe=t.jsxs(tn,{kind:p0(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:V||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",ce,re?c("entityPage.nativePlace",{place:m(re)}):""]}),I,t.jsx(o0,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(nt=e.description)!=null&&nt.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Y=e.description)==null?void 0:Y.text)?6:void 0,facts:Ne,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[Q>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:Q})}),t.jsx("dl",{children:ye.map(k=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{children:k.names.map(P=>m(P)).join("、")})]},k.label))})]}),ue&&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:ue.map(k=>t.jsx("i",{style:{flexGrow:k.n,background:s.bim(k.token)}},k.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ue.map(k=>t.jsxs("span",{children:[t.jsx("i",{style:{background:s.bim(k.token)}}),m(k.label)," ",k.n]},k.key))})]})]}),ze=b.useMemo(()=>C.filter(k=>k.loaded&&(k.versionCount??0)>0).sort((k,P)=>(P.versionCount??0)-(k.versionCount??0)).slice(0,3),[C]),B=!!i&&C.length>=3&&L.some(k=>!k.loaded),pe=u==="全部"&&(B||ze.length>=2),Te=e.external_ids||{},ve=((M=e.external_ids_meta)==null?void 0:M.cbdb_match)??Te.cbdb_match,Ve=[];Te.cbdb_id!=null&&Ve.push({label:"CBDB",id:String(Te.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${Te.cbdb_id}`,note:ve==="auto"?c("entityPage.autoMatch"):void 0});const qe=Te.wikidata_id;qe&&Ve.push({label:"Wikidata",id:qe,href:`https://www.wikidata.org/wiki/${qe}`});const Xe=Te.viaf_id;Xe&&Ve.push({label:"VIAF",id:Xe,href:`https://viaf.org/viaf/${Xe}`});const J=U.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),ie=e.id?t.jsx(c0,{id:e.id,transport:i,onTotal:$}):null,me=[...pe&&!B?[{id:"featured",label:c("entityPage.sec.featured"),count:ze.length}]:[],...C.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:C.length}]:[],...z.length?[{id:"pieces",label:c("entityPage.sec.pieces"),count:z.length}]:[],...S?[{id:"mentions",label:c("mentions.title"),count:S}]:[],...Ve.length?[{id:"external",label:c("entityPage.sec.external"),count:Ve.length}]:[]],se=pe?t.jsxs(St,{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":B||void 0,children:[B&&[0,1,2].map(k=>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:" "})]},k)),!B&&ze.map(k=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0})}),t.jsx(vt,{items:[k.section?m(k.section):"",k.measure?m(k.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:k.versionCount}),t.jsx("span",{children:c("entityPage.versionsUnit")}),k.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},k.id))]})]}):null,de=z.length?t.jsx(f0,{pieces:z,onNavigate:n,renderLink:r}):null,ge=C.length===0?t.jsxs(t.Fragment,{children:[de??t.jsx(St,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}),ie]}):t.jsxs(t.Fragment,{children:[se,t.jsxs(St,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:C.length}),R.length!==C.length?c("entityPage.current",{n:R.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[J.length>1&&t.jsx(Qi,{items:J,value:u,onChange:k=>{f(k),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":v==="versions",onClick:()=>{v==="default"&&y(!0),w(k=>k==="default"?"versions":"default")},children:c(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(R.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:L.map(k=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0}),k.measure?t.jsx(vt,{items:[m(k.measure)]}):!k.loaded&&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${k.section||k.loaded?"":" bim-d-zt-blank"}`,children:k.section?m(k.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.role?"":" bim-d-zt-blank"}`,children:k.role?m(k.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.loaded?"":" bim-d-zt-blank"}`,children:k.loaded?k.versionCount?c("entityPage.nZhong",{n:k.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("entityPage.notRecorded")}):""}),t.jsx("td",{className:k.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:k.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("entityPage.hasImage")})})]},k.id))})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx(Jn,{total:R.length,shown:L.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),de,ie]}),Oe=Ve.length>0?t.jsx(mi,{id:"external",title:c("entityPage.sec.external"),items:Ve.map(k=>t.jsxs("a",{href:k.href,target:"_blank",rel:"noopener noreferrer",children:[k.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Ve.map(k=>k.id),foot:Te.cbdb_id!=null&&ve==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Zi,{railTop:o,back:a,nav:me,railLinks:l,main:ge,card:fe,side:Oe})};function f0({pieces:e,onNavigate:i,renderLink:n}){const{t:r,convert:o,messages:a}=oe(),[l,d]=b.useState(""),[c,m]=b.useState(!1),p=g=>g?a.workSubtype[g]??o(g):"",h=b.useMemo(()=>{const g=new Map;for(const y of e)g.set(y.st||"",(g.get(y.st||"")??0)+1);return g.size<2?[]:[{key:"",label:`${r("detail.roleAll")} ${e.length}`},...[...g.entries()].sort((y,v)=>v[1]-y[1]).map(([y,v])=>({key:y,label:`${p(y)} ${v}`}))]},[e,r]),u=l?e.filter(g=>(g.st||"")===l):e,f=c?u:u.slice(0,u0);return t.jsxs(St,{id:"pieces",title:r("entityPage.sec.pieces"),meta:t.jsx(vt,{items:[r("entityPage.nPian",{n:e.length}),u.length!==e.length?r("entityPage.current",{n:u.length}):""]}),children:[h.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(Qi,{items:h,value:l,onChange:g=>{d(g),m(!1)}})}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!c&&en(u.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:r("entityPage.piece.title")}),t.jsx("th",{children:r("entityPage.piece.kind")}),t.jsx("th",{children:r("entityPage.col.role")}),t.jsx("th",{"aria-label":r("entityPage.piece.text")})]})}),t.jsx("tbody",{children:f.map(g=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:g.work_id,label:o(g.title??g.work_id),onNavigate:i,renderLink:n,dense:!0})}),t.jsx("td",{className:"bim-d-zt-sub bim-d-zt-nowrap",children:p(g.st)}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${g.role?"":" bim-d-zt-blank"}`,children:g.role?o(g.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:g.txt?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:g.txt&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:r("entityPage.piece.hasText")})})]},g.work_id))})]}),!c&&t.jsx(Jn,{total:u.length,shown:f.length,unit:r("entityPage.piece.moreUnit"),onClick:()=>m(!0)})]})}const co="(max-width: 719px)",g0=`${co}, (pointer: coarse)`,Ld=`
1559
1561
  .bim-ct {
1560
1562
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
1561
1563
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
@@ -1688,7 +1690,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
1688
1690
  }
1689
1691
 
1690
1692
  /* 点击目标 ≥44px(Q5):触屏与窄屏 */
1691
- @media ${f0} {
1693
+ @media ${g0} {
1692
1694
  .bim-ct-row { min-height: 44px; }
1693
1695
  .bim-ct-tw { width: 44px; }
1694
1696
  .bim-ct-pg { min-width: 44px; height: 44px; }
@@ -1714,7 +1716,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
1714
1716
  /* 窄屏分类抽屉:界栏下按钮和面板都有框 */
1715
1717
  :root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${s.bim("fr-bd")}; background: ${s.bim("fr-bg")}; }
1716
1718
  :root[data-layout="boxed"] .bim-ct-drawer { border: ${s.bim("fr-bd")}; }
1717
- `,di="未分類",Gt="all",mo=20;function sn(e){if(!e)return[];const i=[];for(const n of[e.l1,e.l2,e.l3,e.l4]){const r=(n??"").trim();if(!r)break;i.push(r)}return i}function g0(e){const i=sn(e);return i.length?i.join("/"):di}function x0(e){const i=sn(e);return i.length?i.map((n,r)=>i.slice(0,r+1).join("/")):[di]}function y0(e,i=[]){const n=new Map;i.forEach((d,c)=>{const m=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(p=>!!p);m.forEach((p,h)=>{const u=m.slice(0,h+1).join("/");n.has(u)||n.set(u,c)})});const r=new Map;let o=0;for(const d of e){const c=sn(d.classification);if(!c.length){o++;continue}let m=r;c.forEach((p,h)=>{const u=c.slice(0,h+1).join("/");let f=m.get(p);f||(f={id:u,label:p,count:0,children:new Map},m.set(p,f)),f.count++,m=f.children})}const a=d=>[...d.values()].sort((c,m)=>{const p=c.label===di?1:0,h=m.label===di?1:0;if(p!==h)return p-h;const u=n.get(c.id)??1/0,f=n.get(m.id)??1/0;return u!==f?u-f:c.label.localeCompare(m.label,"zh")}).map(c=>{const m={id:c.id,label:c.label,count:c.count};return c.children.size&&(m.children=a(c.children)),m}),l=a(r);return o>0&&l.push({id:di,label:di,count:o}),l}function wi(e,i){if(!i)return[];for(const n of e){if(n.id===i)return[n];if(n.children){const r=wi(n.children,i);if(r.length)return[n,...r]}}return[]}function uo(e){return e.reduce((i,n)=>i+n.count,0)}function j0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function k0(e){var d,c,m;const i={id:e.id,title:e.title||e.id},n=e.juan_count,r=typeof n=="number"?n:(n==null?void 0:n.number)??((c=(d=e.measures)==null?void 0:d.find(p=>(p==null?void 0:p.unit)==="卷"&&typeof p.number=="number"))==null?void 0:c.number);typeof r=="number"&&r>0?i.juan=r:e.measure_info&&(i.juan=e.measure_info);const o=(e.authors??[]).filter(p=>p==null?void 0:p.name).map(p=>{const h=p.dynasty||(e.authors.length===1?e.dynasty:void 0);return h?{name:p.name,dynasty:h}:{name:p.name}});o.length&&(i.authors=o);const a=j0(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=sn(e.classification);return l.length&&(i.classification=l),i}function w0(e,i){const n=e.summary?0:1,r=i.summary?0:1;return n!==r?n-r:e.title.localeCompare(i.title,"zh")}function v0(e,i=mo){return Math.max(1,Math.ceil(e/i))}function Pd(e,i,n=2){if(i<=1)return[1];const r=new Set([1,i]);for(let l=e-n;l<=e+n;l++)l>=1&&l<=i&&r.add(l);const o=[...r].sort((l,d)=>l-d),a=[];return o.forEach((l,d)=>{if(d>0){const c=l-o[d-1];c===2?a.push(l-1):c>2&&a.push(null)}a.push(l)}),a}const S0=()=>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 $0(e,i,n){const r=[];n&&r.push({id:Gt,parentId:null,hasChildren:!1,firstChildId:null});const o=(a,l)=>{var d;for(const c of a){const m=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:l,hasChildren:!!m,firstChildId:m?m[0].id:null}),m&&i.has(c.id)&&o(m,c.id)}};return o(e,null),r}function Od({tree:e,selectedId:i,onSelect:n,allLabel:r,label:o}){const{t:a,convert:l}=oe(),d=r===void 0?a("catalogPage.all"):r,c=o??a("catalogPage.classification"),m=b.useRef(null),p=i&&i!==Gt?i:null,h=d!==null,[u,f]=b.useState(()=>{const C=new Set;for(const U of wi(e,p))C.add(U.id);return C});b.useEffect(()=>{const C=wi(e,p);C.length&&f(U=>{if(C.every(L=>U.has(L.id)))return U;const R=new Set(U);for(const L of C)R.add(L.id);return R})},[e,p]);const g=b.useMemo(()=>$0(e,u,h),[e,u,h]),[y,v]=b.useState(null);b.useEffect(()=>{v(null)},[i]);const w=p??(h?Gt:null),x=b.useMemo(()=>{var R;const C=new Set(g.map(L=>L.id));if(y&&C.has(y))return y;if(w&&C.has(w))return w;const U=wi(e,p).map(L=>L.id).filter(L=>C.has(L));return U.length?U[U.length-1]:((R=g[0])==null?void 0:R.id)??null},[g,y,w,e,p]),j=b.useCallback((C,U)=>{f(R=>{const L=R.has(C),F=U??!L;if(F===L)return R;const T=new Set(R);return F?T.add(C):T.delete(C),T})},[]),S=b.useCallback(C=>{v(C),requestAnimationFrame(()=>{var R;const U=Array.from(((R=m.current)==null?void 0:R.querySelectorAll("[data-ct-id]"))??[]).find(L=>L.dataset.ctId===C);U==null||U.focus()})},[]),$=b.useCallback((C,U)=>{U&&j(C,!0),n(C)},[n,j]),N=b.useCallback(C=>{const U=C.target.closest("[data-ct-id]");if(!U)return;const R=U.dataset.ctId,L=g.findIndex(Z=>Z.id===R);if(L<0)return;const F=g[L];let T=null;switch(C.key){case"ArrowDown":T=g[Math.min(g.length-1,L+1)].id;break;case"ArrowUp":T=g[Math.max(0,L-1)].id;break;case"Home":T=g[0].id;break;case"End":T=g[g.length-1].id;break;case"ArrowRight":if(!F.hasChildren)break;u.has(R)?T=F.firstChildId:j(R,!0);break;case"ArrowLeft":F.hasChildren&&u.has(R)?j(R,!1):T=F.parentId;break;case"Enter":case" ":C.preventDefault(),$(R,F.hasChildren);return;default:return}C.preventDefault(),T&&T!==R&&S(T)},[g,u,j,S,$]),z=(C,U)=>C.map((R,L)=>{var ae;const F=(ae=R.children)!=null&&ae.length?R.children:null,T=!!F&&u.has(R.id),Z=R.id===p,O=U===1&&C.length>1&&L===C.length-1;return t.jsxs("li",{role:"treeitem","aria-level":U,"aria-expanded":F?T:void 0,"aria-selected":Z,tabIndex:x===R.id?0:-1,"data-ct-id":R.id,className:O?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":U-1},onClick:()=>{v(R.id),$(R.id,!!F)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:F?ce=>{ce.stopPropagation(),v(R.id),j(R.id)}:void 0,children:F?t.jsx(S0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(R.label)}),t.jsx("span",{className:"bim-ct-n",children:R.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:z(F,U+1)})]},R.id)});return t.jsxs("ul",{ref:m,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:N,children:[h&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:x===Gt?0:-1,"data-ct-id":Gt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{v(Gt),n(Gt)},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:uo(e).toLocaleString("en-US")})]})}),z(e,1)]})}const Fd=e=>`/item/${encodeURIComponent(e)}`;function _0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Bd(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Hd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Bd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:i,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:r(e.title)}),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:r(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Dd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Bd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:i,children:[t.jsxs("span",{className:"bim-ct-lt",children:[r(e.title),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Wd({page:e,pageCount:i,onPage:n,pageHref:r,label:o}){const{t:a,convert:l}=oe();if(i<=1)return null;const d=m=>p=>{n&&(r&&!_0(p)||(p.preventDefault(),n(m)))},c=(m,p,h)=>{if(h.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:p});const u={className:"bim-ct-pg","aria-current":h.current?"page":void 0,"aria-label":h.aria};return r?t.jsx("a",{...u,href:r(m),onClick:d(m),children:p}):t.jsx("button",{type:"button",...u,onClick:h.current?void 0:d(m),children:p})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":o?l(o):a("catalogPage.pagerLabel"),children:[c(e-1,a("catalogPage.prevPage"),{disabled:e<=1}),t.jsx("ol",{children:Pd(e,i).map((m,p)=>t.jsx("li",{style:{display:"contents"},children:m===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):c(m,m,{current:m===e,aria:a("catalogPage.pageN",{n:m})})},m??`gap${p}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",i]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=i})]})}function Ud({works:e,workLink:i=Fd,emptyText:n,view:r="card",...o}){const{t:a,convert:l}=oe();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:n===void 0?a("catalogPage.emptyWorks"):typeof n=="string"?l(n):n}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Dd,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Hd,{work:d,href:i(d.id)},d.id))}),t.jsx(Wd,{...o})]})}const N0=()=>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:i,page:n,pageCount:r,works:o,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:m,allLabel:p,allTitle:h,pageSize:u=mo,className:f,view:g,onViewChange:y}){const{t:v,convert:w}=oe(),x=p===void 0?v("catalogPage.all"):p,j=h??v("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[N,z]=b.useState(!1),[C,U]=b.useState("card"),R=g??C,L=ce=>{U(ce),y==null||y(ce)},F=wi(e,i&&i!==Gt?i:null),T=F.length?F[F.length-1]:null,Z=T?T.label:j,O=T?T.count:uo(e),ae=b.useCallback(ce=>{z(!1),a(ce)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":N?"open":"closed",children:[t.jsx("style",{children:Ld}),t.jsxs("aside",{className:"bim-ct-side","aria-label":v("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":N,"aria-controls":$,onClick:()=>z(ce=>!ce),children:[t.jsx("span",{children:v("catalogPage.drawerLabel",{path:w(F.length?F.map(ce=>ce.label).join(" › "):x??j)})}),t.jsx(N0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:v("catalogPage.classification")}),t.jsx(Od,{tree:e,selectedId:i,onSelect:ae,allLabel:x})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:w(Z)}),F.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:w(F.slice(0,-1).map(ce=>ce.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[v("catalogPage.stat",{total:O.toLocaleString("en-US"),size:u}),r>1&&v("catalogPage.statPage",{page:n,pages:r})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":v("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":R==="card",onClick:()=>L("card"),children:v("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":R==="list",onClick:()=>L("list"),children:v("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Ud,{works:o,view:R,workLink:c,page:n,pageCount:r,onPage:l,pageHref:m})]})]})}const on="(max-width: 719px)",C0="(max-width: 1079px)",E0=`${on}, (pointer: coarse)`,R0=[8,18,30,42,88],po=`
1719
+ `,di="未分類",Gt="all",mo=20;function sn(e){if(!e)return[];const i=[];for(const n of[e.l1,e.l2,e.l3,e.l4]){const r=(n??"").trim();if(!r)break;i.push(r)}return i}function x0(e){const i=sn(e);return i.length?i.join("/"):di}function y0(e){const i=sn(e);return i.length?i.map((n,r)=>i.slice(0,r+1).join("/")):[di]}function j0(e,i=[]){const n=new Map;i.forEach((d,c)=>{const m=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(p=>!!p);m.forEach((p,h)=>{const u=m.slice(0,h+1).join("/");n.has(u)||n.set(u,c)})});const r=new Map;let o=0;for(const d of e){const c=sn(d.classification);if(!c.length){o++;continue}let m=r;c.forEach((p,h)=>{const u=c.slice(0,h+1).join("/");let f=m.get(p);f||(f={id:u,label:p,count:0,children:new Map},m.set(p,f)),f.count++,m=f.children})}const a=d=>[...d.values()].sort((c,m)=>{const p=c.label===di?1:0,h=m.label===di?1:0;if(p!==h)return p-h;const u=n.get(c.id)??1/0,f=n.get(m.id)??1/0;return u!==f?u-f:c.label.localeCompare(m.label,"zh")}).map(c=>{const m={id:c.id,label:c.label,count:c.count};return c.children.size&&(m.children=a(c.children)),m}),l=a(r);return o>0&&l.push({id:di,label:di,count:o}),l}function wi(e,i){if(!i)return[];for(const n of e){if(n.id===i)return[n];if(n.children){const r=wi(n.children,i);if(r.length)return[n,...r]}}return[]}function uo(e){return e.reduce((i,n)=>i+n.count,0)}function k0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function w0(e){var d,c,m;const i={id:e.id,title:e.title||e.id},n=e.juan_count,r=typeof n=="number"?n:(n==null?void 0:n.number)??((c=(d=e.measures)==null?void 0:d.find(p=>(p==null?void 0:p.unit)==="卷"&&typeof p.number=="number"))==null?void 0:c.number);typeof r=="number"&&r>0?i.juan=r:e.measure_info&&(i.juan=e.measure_info);const o=(e.authors??[]).filter(p=>p==null?void 0:p.name).map(p=>{const h=p.dynasty||(e.authors.length===1?e.dynasty:void 0);return h?{name:p.name,dynasty:h}:{name:p.name}});o.length&&(i.authors=o);const a=k0(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=sn(e.classification);return l.length&&(i.classification=l),i}function v0(e,i){const n=e.summary?0:1,r=i.summary?0:1;return n!==r?n-r:e.title.localeCompare(i.title,"zh")}function S0(e,i=mo){return Math.max(1,Math.ceil(e/i))}function Pd(e,i,n=2){if(i<=1)return[1];const r=new Set([1,i]);for(let l=e-n;l<=e+n;l++)l>=1&&l<=i&&r.add(l);const o=[...r].sort((l,d)=>l-d),a=[];return o.forEach((l,d)=>{if(d>0){const c=l-o[d-1];c===2?a.push(l-1):c>2&&a.push(null)}a.push(l)}),a}const $0=()=>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 _0(e,i,n){const r=[];n&&r.push({id:Gt,parentId:null,hasChildren:!1,firstChildId:null});const o=(a,l)=>{var d;for(const c of a){const m=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:l,hasChildren:!!m,firstChildId:m?m[0].id:null}),m&&i.has(c.id)&&o(m,c.id)}};return o(e,null),r}function Od({tree:e,selectedId:i,onSelect:n,allLabel:r,label:o}){const{t:a,convert:l}=oe(),d=r===void 0?a("catalogPage.all"):r,c=o??a("catalogPage.classification"),m=b.useRef(null),p=i&&i!==Gt?i:null,h=d!==null,[u,f]=b.useState(()=>{const C=new Set;for(const U of wi(e,p))C.add(U.id);return C});b.useEffect(()=>{const C=wi(e,p);C.length&&f(U=>{if(C.every(L=>U.has(L.id)))return U;const R=new Set(U);for(const L of C)R.add(L.id);return R})},[e,p]);const g=b.useMemo(()=>_0(e,u,h),[e,u,h]),[y,v]=b.useState(null);b.useEffect(()=>{v(null)},[i]);const w=p??(h?Gt:null),x=b.useMemo(()=>{var R;const C=new Set(g.map(L=>L.id));if(y&&C.has(y))return y;if(w&&C.has(w))return w;const U=wi(e,p).map(L=>L.id).filter(L=>C.has(L));return U.length?U[U.length-1]:((R=g[0])==null?void 0:R.id)??null},[g,y,w,e,p]),j=b.useCallback((C,U)=>{f(R=>{const L=R.has(C),F=U??!L;if(F===L)return R;const T=new Set(R);return F?T.add(C):T.delete(C),T})},[]),S=b.useCallback(C=>{v(C),requestAnimationFrame(()=>{var R;const U=Array.from(((R=m.current)==null?void 0:R.querySelectorAll("[data-ct-id]"))??[]).find(L=>L.dataset.ctId===C);U==null||U.focus()})},[]),$=b.useCallback((C,U)=>{U&&j(C,!0),n(C)},[n,j]),N=b.useCallback(C=>{const U=C.target.closest("[data-ct-id]");if(!U)return;const R=U.dataset.ctId,L=g.findIndex(Z=>Z.id===R);if(L<0)return;const F=g[L];let T=null;switch(C.key){case"ArrowDown":T=g[Math.min(g.length-1,L+1)].id;break;case"ArrowUp":T=g[Math.max(0,L-1)].id;break;case"Home":T=g[0].id;break;case"End":T=g[g.length-1].id;break;case"ArrowRight":if(!F.hasChildren)break;u.has(R)?T=F.firstChildId:j(R,!0);break;case"ArrowLeft":F.hasChildren&&u.has(R)?j(R,!1):T=F.parentId;break;case"Enter":case" ":C.preventDefault(),$(R,F.hasChildren);return;default:return}C.preventDefault(),T&&T!==R&&S(T)},[g,u,j,S,$]),z=(C,U)=>C.map((R,L)=>{var ae;const F=(ae=R.children)!=null&&ae.length?R.children:null,T=!!F&&u.has(R.id),Z=R.id===p,O=U===1&&C.length>1&&L===C.length-1;return t.jsxs("li",{role:"treeitem","aria-level":U,"aria-expanded":F?T:void 0,"aria-selected":Z,tabIndex:x===R.id?0:-1,"data-ct-id":R.id,className:O?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":U-1},onClick:()=>{v(R.id),$(R.id,!!F)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:F?ce=>{ce.stopPropagation(),v(R.id),j(R.id)}:void 0,children:F?t.jsx($0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(R.label)}),t.jsx("span",{className:"bim-ct-n",children:R.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:z(F,U+1)})]},R.id)});return t.jsxs("ul",{ref:m,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:N,children:[h&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:x===Gt?0:-1,"data-ct-id":Gt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{v(Gt),n(Gt)},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:uo(e).toLocaleString("en-US")})]})}),z(e,1)]})}const Fd=e=>`/item/${encodeURIComponent(e)}`;function N0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Bd(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Hd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Bd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:i,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:r(e.title)}),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:r(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Dd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Bd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:i,children:[t.jsxs("span",{className:"bim-ct-lt",children:[r(e.title),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Wd({page:e,pageCount:i,onPage:n,pageHref:r,label:o}){const{t:a,convert:l}=oe();if(i<=1)return null;const d=m=>p=>{n&&(r&&!N0(p)||(p.preventDefault(),n(m)))},c=(m,p,h)=>{if(h.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:p});const u={className:"bim-ct-pg","aria-current":h.current?"page":void 0,"aria-label":h.aria};return r?t.jsx("a",{...u,href:r(m),onClick:d(m),children:p}):t.jsx("button",{type:"button",...u,onClick:h.current?void 0:d(m),children:p})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":o?l(o):a("catalogPage.pagerLabel"),children:[c(e-1,a("catalogPage.prevPage"),{disabled:e<=1}),t.jsx("ol",{children:Pd(e,i).map((m,p)=>t.jsx("li",{style:{display:"contents"},children:m===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):c(m,m,{current:m===e,aria:a("catalogPage.pageN",{n:m})})},m??`gap${p}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",i]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=i})]})}function Ud({works:e,workLink:i=Fd,emptyText:n,view:r="card",...o}){const{t:a,convert:l}=oe();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:n===void 0?a("catalogPage.emptyWorks"):typeof n=="string"?l(n):n}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Dd,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Hd,{work:d,href:i(d.id)},d.id))}),t.jsx(Wd,{...o})]})}const z0=()=>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 C0({tree:e,selectedId:i,page:n,pageCount:r,works:o,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:m,allLabel:p,allTitle:h,pageSize:u=mo,className:f,view:g,onViewChange:y}){const{t:v,convert:w}=oe(),x=p===void 0?v("catalogPage.all"):p,j=h??v("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[N,z]=b.useState(!1),[C,U]=b.useState("card"),R=g??C,L=ce=>{U(ce),y==null||y(ce)},F=wi(e,i&&i!==Gt?i:null),T=F.length?F[F.length-1]:null,Z=T?T.label:j,O=T?T.count:uo(e),ae=b.useCallback(ce=>{z(!1),a(ce)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":N?"open":"closed",children:[t.jsx("style",{children:Ld}),t.jsxs("aside",{className:"bim-ct-side","aria-label":v("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":N,"aria-controls":$,onClick:()=>z(ce=>!ce),children:[t.jsx("span",{children:v("catalogPage.drawerLabel",{path:w(F.length?F.map(ce=>ce.label).join(" › "):x??j)})}),t.jsx(z0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:v("catalogPage.classification")}),t.jsx(Od,{tree:e,selectedId:i,onSelect:ae,allLabel:x})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:w(Z)}),F.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:w(F.slice(0,-1).map(ce=>ce.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[v("catalogPage.stat",{total:O.toLocaleString("en-US"),size:u}),r>1&&v("catalogPage.statPage",{page:n,pages:r})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":v("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":R==="card",onClick:()=>L("card"),children:v("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":R==="list",onClick:()=>L("list"),children:v("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Ud,{works:o,view:R,workLink:c,page:n,pageCount:r,onPage:l,pageHref:m})]})]})}const on="(max-width: 719px)",E0="(max-width: 1079px)",R0=`${on}, (pointer: coarse)`,T0=[8,18,30,42,88],po=`
1718
1720
  .bim-rh { color: ${s.bim("ink")}; font-family: ${s.bim("font-ui")}; font-size: 14px; line-height: 1.6; }
1719
1721
  .bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
1720
1722
  .bim-rh a { color: ${s.bim("accent")}; text-decoration: none; }
@@ -1862,7 +1864,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
1862
1864
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
1863
1865
  color: ${s.bim("ink")} !important; font-size: 13px;
1864
1866
  }
1865
- ${R0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb, ${s.bim("accent")} ${e}%, ${s.bim("card-bg")}); }`).join(`
1867
+ ${T0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb, ${s.bim("accent")} ${e}%, ${s.bim("card-bg")}); }`).join(`
1866
1868
  `)}
1867
1869
  .bim-rh-band a[data-k="4"] { color: ${s.bim("page-bg")} !important; }
1868
1870
  .bim-rh-band a:hover { outline: 2px solid ${s.bim("ink")}; outline-offset: -2px; }
@@ -1890,7 +1892,7 @@ ${R0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
1890
1892
  }
1891
1893
 
1892
1894
  /* ── 中屏 ── */
1893
- @media ${C0} {
1895
+ @media ${E0} {
1894
1896
  .bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1895
1897
  .bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
1896
1898
  }
@@ -1933,7 +1935,7 @@ ${R0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
1933
1935
  }
1934
1936
 
1935
1937
  /* 触屏或窄屏:点击目标放大到 44px */
1936
- @media ${E0} {
1938
+ @media ${R0} {
1937
1939
  .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; }
1938
1940
  .bim-rh-chip { display: inline-flex; }
1939
1941
  }
@@ -1944,7 +1946,7 @@ ${R0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
1944
1946
  }
1945
1947
 
1946
1948
  @media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
1947
- `,T0=s.readHome["zh-Hant"].period,Kd={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function ii(e){return{...Kd,...e??{}}}function bo(e){var n;const i=(n=e.authors)==null?void 0:n.find(r=>r==null?void 0:r.name);return i?i.dynasty?`${i.dynasty} ${i.name}`:i.name:""}function nr(e){return(e.authors??[]).filter(n=>n==null?void 0:n.name).map(n=>n.dynasty?`〔${n.dynasty}〕${n.name}`:n.name).join(" ")}function Yd(e,i=s.readHome["zh-Hant"].shelfOther){var o;const n=[],r=new Map;for(const a of e){const l=((o=a.period_of)==null?void 0:o.trim())||i;let d=r.get(l);d||(d={label:l,items:[]},r.set(l,d),n.push(d)),d.items.push(a)}return n}function Gd(e){return Math.max(150,Array.from(e).length*18+44)}function Vd(e,i){if(i<=0||e<=0)return 0;const n=e/i;return n<.15?0:n<.35?1:n<.6?2:n<.85?3:4}const qd=.04;function kt(e){return e.toLocaleString("en-US")}function Xd({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((i,n)=>t.jsx("span",{children:i},n))})}function Rt({id:e,title:i,sub:n,more:r,children:o}){const{convert:a}=oe(),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(i)}),n&&t.jsx("span",{className:"bim-rh-sub",children:n}),r]}),t.jsx("div",{className:"bim-rh-bd",children:o})]})}function Jd({counts:e}){const{t:i}=oe();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:kt(e.readable)}),i("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:kt(e.pieces)}),i("readHome.pieces")]})]})}function Zd({picks:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=nr(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:o.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(Xd,{text:r(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:r(d)}),t.jsx("h3",{children:r(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:r(l)}),a.blurb&&t.jsx("p",{children:r(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:n("readHome.startReading")})]})]})},a.id)})}):null}function Qd(e,i){return e&&e>1?i("readHome.nCopies",{n:e}):null}function ho({topic:e,links:i,hint:n,legendCount:r,showTitle:o=!0,legendExtra:a}){const{t:l,convert:d}=oe(),c=ii(i);if(!e.items.length)return null;const m=r===void 0?l("readHome.shelfLegendCount"):r,p=Yd(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?kt(u.records):Qd(u.text_count,l),g=bo(u),y=[d(u.title),u.orig?l("readHome.origZhi"):"",g?l("readHome.spineBy",{name:d(g)}):"",u.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":y,title:y,style:{height:Gd(u.title)},children:[t.jsx(Xd,{text:d(u.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:f})]})},u.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[o&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:n?d(n):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:p.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(h)}),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")]}),m&&t.jsx("span",{children:d(m)}),a==null?void 0:a.map(u=>t.jsx("span",{children:d(u)},u))]})]})}const I0=4,qi=e=>e>I0+1;function em({topic:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i),[a,l]=b.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":qi(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nWorks",{n:kt(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const m=Qd(c.text_count,n),p=bo(c);return t.jsx("li",{children:t.jsxs("a",{href:o.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(c.title)}),m&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:m}),p&&t.jsx("small",{children:r(p)})]})},c.id)})}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?n("action.collapse"):n("readHome.allNWorks",{n:e.items.length})})]})}function tm({topics:e,links:i}){const n=e.filter(o=>o.shelf&&o.items.length),r=e.filter(o=>!o.shelf&&o.items.length);return!n.length&&!r.length?null:t.jsxs(t.Fragment,{children:[n.map(o=>t.jsx(ho,{topic:o,links:i},o.key)),r.length>0&&t.jsx("div",{className:"bim-rh-groups",children:r.map(o=>t.jsx(em,{topic:o,links:i},o.key))})]})}function im({famous:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:r(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:r(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:n("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:o.read(c.id),title:r([c.title,c.edition].filter(Boolean).join(" · ")),children:r(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:o.work(a.work_id),children:n("readHome.workPageLink",{title:r(a.title)})})})]})},a.work_id??a.title))}):null}function fo({bu:e,unclassified:i,links:n,unclassifiedNote:r}){const{t:o,convert:a}=oe(),l=ii(n);return!e.length&&!i?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var m;const c=((m=d.top[0])==null?void 0:m.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:o("readHome.nWorks",{n:kt(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":o("readHome.subClasses",{label:a(d.label)}),children:d.top.map(p=>t.jsx("li",{children:t.jsxs("a",{href:l.node(p.id),children:[t.jsx("span",{children:a(p.label)}),t.jsx("small",{className:"bim-rh-num",children:kt(p.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(p.count/c*100)}%`}})]})},p.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:o("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!i&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:o("readHome.unclassified")}),t.jsx("span",{children:o("readHome.nWorks",{n:kt(i)})}),t.jsx("span",{children:r?a(r):o("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:o("readHome.viewUnclassified")})]})]})}function nm({periods:e,unknown:i,links:n}){const{t:r,convert:o,messages:a}=oe(),l=a.readHome.period,d=ii(n),c=e.filter(h=>h.count>0);if(!c.length)return null;const m=c.reduce((h,u)=>h+u.count,0),p=Math.max(...c.map(h=>h.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(h=>{const u=h.label?o(h.label):l[h.key]??o(h.key),f=h.count/m,g=r("readHome.periodItem",{label:u,n:kt(h.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(h.key),"data-k":Vd(h.count,p),"data-narrow":f<qd?"":void 0,"aria-label":g,title:g,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:kt(h.count)})]})},h.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!i&&t.jsx("span",{children:r("readHome.periodUnknown",{n:kt(i)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:r("readHome.hoverHint")})]})]})}function rm({authors:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[r(a.name),a.dynasty&&t.jsx("span",{children:r(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nPieces",{n:kt(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:o.read(l.id),children:r(l.title)})},l.id))}),o.author&&t.jsx("a",{className:"bim-rh-more",href:o.author(a.name),children:n("readHome.authorAll",{name:r(a.name),n:a.count})})]},a.name))}):null}const sm={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function M0({sections:e,links:i,head:n,piecesMoreHref:r,className:o}){const{t:a}=oe(),l=e,d=sm,c=l.topics.filter(u=>!u.shelf),m={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},p=Object.keys(d).filter(u=>m[u]),h=u=>a(`readHome.nav.${u}`);return t.jsxs("div",{className:o?`bim-rh ${o}`:"bim-rh",children:[t.jsx("style",{children:po}),t.jsxs("div",{className:"bim-rh-head",children:[n,t.jsx(Jd,{counts:l.counts})]}),p.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:p.map(u=>t.jsx("li",{children:t.jsx("a",{href:`#${d[u]}`,children:h(u)})},u))})}),t.jsxs("div",{className:"bim-rh-main",children:[m.picks&&t.jsx(Rt,{id:d.picks,title:h("picks"),sub:a("readHome.picksSub"),children:t.jsx(Zd,{picks:l.picks,links:i})}),m.topics&&t.jsx(Rt,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(tm,{topics:c,links:i})}),m.famous&&t.jsx(Rt,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(im,{famous:l.famous,links:i})}),m.sibu&&t.jsx(Rt,{id:d.sibu,title:h("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(fo,{bu:l.bu,unclassified:l.unclassified,links:i})}),m.period&&t.jsx(Rt,{id:d.period,title:h("period"),sub:a("readHome.periodSub"),children:t.jsx(nm,{periods:l.periods,unknown:l.period_unknown,links:i})}),m.pieces&&t.jsx(Rt,{id:d.pieces,title:h("pieces"),sub:a("readHome.piecesSub"),more:r?t.jsx("a",{className:"bim-rh-more",href:r,children:a("readHome.piecesMore")}):void 0,children:t.jsx(rm,{authors:l.pieces.authors,links:i})})]})]})}const A0="(max-width: 1079px)",L0=`${on}, (pointer: coarse)`,om=`
1949
+ `,I0=s.readHome["zh-Hant"].period,Kd={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function ii(e){return{...Kd,...e??{}}}function bo(e){var n;const i=(n=e.authors)==null?void 0:n.find(r=>r==null?void 0:r.name);return i?i.dynasty?`${i.dynasty} ${i.name}`:i.name:""}function nr(e){return(e.authors??[]).filter(n=>n==null?void 0:n.name).map(n=>n.dynasty?`〔${n.dynasty}〕${n.name}`:n.name).join(" ")}function Yd(e,i=s.readHome["zh-Hant"].shelfOther){var o;const n=[],r=new Map;for(const a of e){const l=((o=a.period_of)==null?void 0:o.trim())||i;let d=r.get(l);d||(d={label:l,items:[]},r.set(l,d),n.push(d)),d.items.push(a)}return n}function Gd(e){return Math.max(150,Array.from(e).length*18+44)}function Vd(e,i){if(i<=0||e<=0)return 0;const n=e/i;return n<.15?0:n<.35?1:n<.6?2:n<.85?3:4}const qd=.04;function kt(e){return e.toLocaleString("en-US")}function Xd({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((i,n)=>t.jsx("span",{children:i},n))})}function Rt({id:e,title:i,sub:n,more:r,children:o}){const{convert:a}=oe(),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(i)}),n&&t.jsx("span",{className:"bim-rh-sub",children:n}),r]}),t.jsx("div",{className:"bim-rh-bd",children:o})]})}function Jd({counts:e}){const{t:i}=oe();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:kt(e.readable)}),i("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:kt(e.pieces)}),i("readHome.pieces")]})]})}function Zd({picks:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=nr(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:o.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(Xd,{text:r(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:r(d)}),t.jsx("h3",{children:r(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:r(l)}),a.blurb&&t.jsx("p",{children:r(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:n("readHome.startReading")})]})]})},a.id)})}):null}function Qd(e,i){return e&&e>1?i("readHome.nCopies",{n:e}):null}function ho({topic:e,links:i,hint:n,legendCount:r,showTitle:o=!0,legendExtra:a}){const{t:l,convert:d}=oe(),c=ii(i);if(!e.items.length)return null;const m=r===void 0?l("readHome.shelfLegendCount"):r,p=Yd(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?kt(u.records):Qd(u.text_count,l),g=bo(u),y=[d(u.title),u.orig?l("readHome.origZhi"):"",g?l("readHome.spineBy",{name:d(g)}):"",u.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":y,title:y,style:{height:Gd(u.title)},children:[t.jsx(Xd,{text:d(u.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:f})]})},u.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[o&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:n?d(n):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:p.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(h)}),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")]}),m&&t.jsx("span",{children:d(m)}),a==null?void 0:a.map(u=>t.jsx("span",{children:d(u)},u))]})]})}const M0=4,qi=e=>e>M0+1;function em({topic:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i),[a,l]=b.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":qi(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nWorks",{n:kt(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const m=Qd(c.text_count,n),p=bo(c);return t.jsx("li",{children:t.jsxs("a",{href:o.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(c.title)}),m&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:m}),p&&t.jsx("small",{children:r(p)})]})},c.id)})}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?n("action.collapse"):n("readHome.allNWorks",{n:e.items.length})})]})}function tm({topics:e,links:i}){const n=e.filter(o=>o.shelf&&o.items.length),r=e.filter(o=>!o.shelf&&o.items.length);return!n.length&&!r.length?null:t.jsxs(t.Fragment,{children:[n.map(o=>t.jsx(ho,{topic:o,links:i},o.key)),r.length>0&&t.jsx("div",{className:"bim-rh-groups",children:r.map(o=>t.jsx(em,{topic:o,links:i},o.key))})]})}function im({famous:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:r(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:r(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:n("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:o.read(c.id),title:r([c.title,c.edition].filter(Boolean).join(" · ")),children:r(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:o.work(a.work_id),children:n("readHome.workPageLink",{title:r(a.title)})})})]})},a.work_id??a.title))}):null}function fo({bu:e,unclassified:i,links:n,unclassifiedNote:r}){const{t:o,convert:a}=oe(),l=ii(n);return!e.length&&!i?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var m;const c=((m=d.top[0])==null?void 0:m.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:o("readHome.nWorks",{n:kt(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":o("readHome.subClasses",{label:a(d.label)}),children:d.top.map(p=>t.jsx("li",{children:t.jsxs("a",{href:l.node(p.id),children:[t.jsx("span",{children:a(p.label)}),t.jsx("small",{className:"bim-rh-num",children:kt(p.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(p.count/c*100)}%`}})]})},p.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:o("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!i&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:o("readHome.unclassified")}),t.jsx("span",{children:o("readHome.nWorks",{n:kt(i)})}),t.jsx("span",{children:r?a(r):o("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:o("readHome.viewUnclassified")})]})]})}function nm({periods:e,unknown:i,links:n}){const{t:r,convert:o,messages:a}=oe(),l=a.readHome.period,d=ii(n),c=e.filter(h=>h.count>0);if(!c.length)return null;const m=c.reduce((h,u)=>h+u.count,0),p=Math.max(...c.map(h=>h.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(h=>{const u=h.label?o(h.label):l[h.key]??o(h.key),f=h.count/m,g=r("readHome.periodItem",{label:u,n:kt(h.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(h.key),"data-k":Vd(h.count,p),"data-narrow":f<qd?"":void 0,"aria-label":g,title:g,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:kt(h.count)})]})},h.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!i&&t.jsx("span",{children:r("readHome.periodUnknown",{n:kt(i)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:r("readHome.hoverHint")})]})]})}function rm({authors:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[r(a.name),a.dynasty&&t.jsx("span",{children:r(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nPieces",{n:kt(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:o.read(l.id),children:r(l.title)})},l.id))}),o.author&&t.jsx("a",{className:"bim-rh-more",href:o.author(a.name),children:n("readHome.authorAll",{name:r(a.name),n:a.count})})]},a.name))}):null}const sm={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function A0({sections:e,links:i,head:n,piecesMoreHref:r,className:o}){const{t:a}=oe(),l=e,d=sm,c=l.topics.filter(u=>!u.shelf),m={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},p=Object.keys(d).filter(u=>m[u]),h=u=>a(`readHome.nav.${u}`);return t.jsxs("div",{className:o?`bim-rh ${o}`:"bim-rh",children:[t.jsx("style",{children:po}),t.jsxs("div",{className:"bim-rh-head",children:[n,t.jsx(Jd,{counts:l.counts})]}),p.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:p.map(u=>t.jsx("li",{children:t.jsx("a",{href:`#${d[u]}`,children:h(u)})},u))})}),t.jsxs("div",{className:"bim-rh-main",children:[m.picks&&t.jsx(Rt,{id:d.picks,title:h("picks"),sub:a("readHome.picksSub"),children:t.jsx(Zd,{picks:l.picks,links:i})}),m.topics&&t.jsx(Rt,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(tm,{topics:c,links:i})}),m.famous&&t.jsx(Rt,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(im,{famous:l.famous,links:i})}),m.sibu&&t.jsx(Rt,{id:d.sibu,title:h("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(fo,{bu:l.bu,unclassified:l.unclassified,links:i})}),m.period&&t.jsx(Rt,{id:d.period,title:h("period"),sub:a("readHome.periodSub"),children:t.jsx(nm,{periods:l.periods,unknown:l.period_unknown,links:i})}),m.pieces&&t.jsx(Rt,{id:d.pieces,title:h("pieces"),sub:a("readHome.piecesSub"),more:r?t.jsx("a",{className:"bim-rh-more",href:r,children:a("readHome.piecesMore")}):void 0,children:t.jsx(rm,{authors:l.pieces.authors,links:i})})]})]})}const L0="(max-width: 1079px)",P0=`${on}, (pointer: coarse)`,om=`
1948
1950
  /* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
1949
1951
  .bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
1950
1952
  .bim-mh-q { min-width: 0; }
@@ -2084,7 +2086,7 @@ ${R0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
2084
2086
  .bim-mh-cc0 { display: inline-block; margin-right: 8px; padding: 1px 7px; font-size: 11.5px; letter-spacing: 0.08em; background: ${s.bim("check-fine-bg")}; color: ${s.bim("check-fine-fg")}; }
2085
2087
 
2086
2088
  /* ── 中屏 ── */
2087
- @media ${A0} {
2089
+ @media ${L0} {
2088
2090
  .bim-mh-head, .bim-mh-zhi { grid-template-columns: minmax(0, 1fr); }
2089
2091
  .bim-mh-cg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
2090
2092
  .bim-mh-lin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@@ -2111,8 +2113,8 @@ ${R0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
2111
2113
  .bim-mh-tbl tr > :nth-child(2), .bim-mh-tbl tr > :nth-child(3) { display: none; }
2112
2114
  }
2113
2115
 
2114
- @media ${L0} {
2116
+ @media ${P0} {
2115
2117
  .bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
2116
2118
  .bim-mh-recent-h button { min-height: 44px; }
2117
2119
  }
2118
- `,am={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ni(e){return{...am,...e??{}}}function lm(e,i){if(e.lineage)return e.lineage(i);const n=e.item(i),r=n.indexOf("#"),[o,a]=r<0?[n,""]:[n.slice(0,r),n.slice(r)];return`${o}${o.includes("?")?"&":"?"}tab=lineage${a}`}function go(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function cm(e){const i=e.filter(m=>Number.isFinite(m.birth_year)||Number.isFinite(m.death_year)),n=e.filter(m=>!i.includes(m));if(!i.length)return{min:0,max:0,placed:[],missing:n};const r=m=>{const p=Number.isFinite(m.birth_year)?m.birth_year:m.death_year-50,h=Number.isFinite(m.death_year)?m.death_year:m.birth_year+50;return[Math.min(p,h),Math.max(p,h)]},o=i.map(r),a=Math.min(...o.map(m=>m[0])),l=Math.max(...o.map(m=>m[1])),d=Math.max(1,l-a),c=i.map((m,p)=>({p:m,from:o[p][0],to:o[p][1]})).sort((m,p)=>m.from-p.from).map(m=>({...m,left:(m.from-a)/d*100,width:Math.max(.8,(m.to-m.from)/d*100)}));return{min:a,max:l,placed:c,missing:n}}function Bn(e,i=s.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function P0(e){return{read:e.item,work:e.item,node:e.node}}function dm({counts:e,links:i}){const{t:n}=oe(),r=i==null?void 0:i.type;if(!r)return null;const o=[["all",n("metaHome.typeAll"),null],["work",n("metaHome.typeLabel.work"),e.works],["book",n("metaHome.typeLabel.book"),e.books],["collection",n("metaHome.typeLabel.collection"),e.collections],["entity",n("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":n("metaHome.typeChipsLabel"),children:o.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:r(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:kt(d)})]})},a))})}function mm(e,i=5){const[n,r]=b.useState(null);b.useEffect(()=>{let a=!1;const l=ei().slice(0,i);if(!l.length||!e){r([]);return}return Promise.all(l.map(d=>zs(e,d))).then(d=>{a||r(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{Ns(),r([])},[]);return{entries:n,clear:o}}function O0(e,i,n){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?n(r):um(e.type,i)}function um(e,i){return i(`metaHome.typeLabel.${e}`)}function pm({entries:e,onClear:i,links:n}){const{t:r,convert:o}=oe(),a=ni(n);return t.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[t.jsxs("div",{className:"bim-mh-recent-h",children:[t.jsx("h2",{id:"bim-mh-recent-h",children:r("metaHome.recentTitle")}),e&&e.length>0&&i&&t.jsx("button",{type:"button",onClick:i,children:r("metaHome.recentClear")})]}),e&&e.length>0&&t.jsx("ol",{children:e.map(l=>t.jsx("li",{children:t.jsxs("a",{href:a.item(l.id),"aria-label":r("metaHome.recentItemLabel",{type:l.type?um(l.type,r):"",title:o(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?r(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:o(l.title)}),t.jsx("small",{"aria-hidden":"true",children:O0(l,r,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function bm(e,i,n,r=!1){return r&&(e==="done"||e==="in_progress")?i(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?i(`metaHome.status.${e}`):n(e)}function hm({rows:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":n("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[n("metaHome.catalogTitle"),t.jsx("small",{children:n("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:n("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:n("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:n("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=go(a.imported,a.total),d=a.work_id??a.collection_id,c=r(a.edition?`${a.name}·${a.edition}`:a.name);return t.jsxs("tr",{children:[t.jsx("th",{scope:"row",children:d?t.jsx("a",{href:o.item(d),children:c}):c}),t.jsx("td",{className:"bim-mh-r",children:kt(a.total)}),t.jsx("td",{className:"bim-mh-r",children:kt(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:bm(a.status,n,r)})})]},a.id||a.name)})})]})}):null}function fm({items:e,links:i,label:n}){const{convert:r}=oe();return t.jsx("ul",{className:"bim-rh-rows","aria-label":n?r(n):void 0,children:e.map(o=>t.jsx("li",{children:t.jsxs("a",{href:i.item(o.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(o.title)}),o.sub&&t.jsx("small",{children:r(o.sub)})]})},o.id))})}function gm({works:e,links:i}){const{t:n}=oe(),[r,o]=b.useState(!1);if(!e.length)return null;const a=qi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":r?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(fm,{items:e.map(l=>({id:l.id,title:l.title,sub:nr(l)||void 0})),links:ni(i)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":r,onClick:()=>o(l=>!l),children:r?n("action.collapse"):n("metaHome.allNWorks",{n:e.length})})]})}const xm="siku_qige";function F0({group:e,links:i}){const{t:n,convert:r}=oe(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(fm,{items:e.items,links:i,label:e.label}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>a(l=>!l),children:o?n("action.collapse"):n("metaHome.allNKinds",{n:e.items.length})})]})}function ym({groups:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const a=e.find(c=>c.key===xm),l=e.filter(c=>c!==a),d=c=>{var m;return((m=c.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:m[1])??c};return t.jsxs(t.Fragment,{children:[a&&t.jsxs(t.Fragment,{children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(a.label),t.jsx("small",{children:r(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":r(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:o.item(c.id),"aria-label":r(c.title),title:r(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:r(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:n("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(F0,{group:c,links:o},c.key))})]})}const yl=34,jl=13;function kl(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Bn(e.birth_year,i):"?"}–${e.death_year!=null?Bn(e.death_year,i):"?"}`}function B0(e,i){const n=i-e,r=n>1200?300:n>400?100:50,o=[];for(let a=Math.ceil(e/r)*r;a<=i;a+=r)o.push(a);return o}function jm({people:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=cm(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-jl):u.left;let y=0;for(;m[y]!=null&&m[y]>g;)y++;return m[y]=f?u.left+u.width:u.left+Math.max(u.width,jl),{...u,lane:y,end:f}}),h=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[p.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:m.length*yl+10},children:p.map(u=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":u.end?"":void 0,style:{left:`${u.left}%`,top:u.lane*yl+4,width:`${Math.max(u.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:o.item(u.p.id),children:[r(u.p.name),t.jsx("small",{className:"bim-rh-num",children:kl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:B0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:Bn(u,n)},u))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":p.length?void 0:"",children:(p.length?e:c).map(u=>t.jsx("li",{children:t.jsxs("a",{href:o.item(u.id),children:[t.jsx("span",{children:r(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?r(u.dynasty):"",kl(u,n)].filter(Boolean).join(" ")})]})},u.id))}),c.length>0&&p.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:n("metaHome.missingLife",{names:r(c.map(u=>u.name).join("、"))})})]})}const H0=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 km({works:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=nr(a);return t.jsx("li",{children:t.jsxs("a",{href:lm(o,a.id),children:[H0,t.jsx("b",{children:r(a.title)}),l&&t.jsx("small",{children:r(l)}),t.jsx("span",{children:n("metaHome.viewLineage")})]})},a.id)})}):null}function wm({sites:e}){const{t:i,convert:n}=oe(),r=e.filter(a=>a.status!=="todo"&&a.total>0),o=e.filter(a=>!r.includes(a));return e.length?t.jsxs(t.Fragment,{children:[r.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:r.map(a=>{const l=go(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:n(a.name)}):t.jsx("span",{children:n(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${kt(a.imported)} / ${kt(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:bm(a.status,i,n,!0)})]})]},a.id||a.name)})}),o.length>0&&t.jsx("p",{className:"bim-mh-todo",children:i("metaHome.plannedSites",{names:n(o.map(a=>a.name).join("、"))})})]}):null}const wl=["extant","partially_extant","lost","unknown"];function vm({stats:e,links:i,version:n,repoUrl:r,downloadHref:o}){const{t:a}=oe(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(m=>[e[m],a(`metaHome.stat.${m}`)]).filter(([m])=>m>0),d=i==null?void 0:i.loss,c=wl.some(m=>{var p;return(((p=e.loss)==null?void 0:p[m])??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(([m,p])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:kt(m)}),t.jsx("span",{children:p})]},p))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:wl.map(m=>{var u;const p=((u=e.loss)==null?void 0:u[m])??0,h=a(`metaHome.lossNote.${m}`);return t.jsx("li",{children:t.jsxs("a",{href:d(m),children:[a(`metaHome.loss.${m}`),t.jsx("small",{className:"bim-rh-num",children:c&&p>0?a("metaHome.lossCount",{n:kt(p),note:h}):h})]})},m)})})]}),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"),r?t.jsx("a",{href:r,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),n&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:n})]}),o&&t.jsx("p",{children:t.jsx("a",{href:o,children:a("metaHome.download")})})]})]})}const Sm={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function D0({sections:e,links:i,head:n,transport:r,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,N;const{t:h}=oe(),u=e,f=ni(i),g=P0(f),y=Sm,v=mm(r),w={zhi:!!(($=u.shelf)!=null&&$.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},x=Object.keys(y).filter(z=>w[z]),j=z=>h(`metaHome.nav.${z}`),S=(z,C)=>z?t.jsx("a",{className:"bim-rh-more",href:z,children:C}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:po+om}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(dm,{counts:u.counts,links:i})]}),r&&t.jsx(pm,{entries:v.entries,onClear:v.clear,links:i})]}),x.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":h("metaHome.navLabel"),children:t.jsx("ul",{children:x.map(z=>t.jsx("li",{children:t.jsx("a",{href:`#${y[z]}`,children:j(z)})},z))})}),t.jsxs("div",{className:"bim-rh-main",children:[w.zhi&&t.jsxs(Rt,{id:y.zhi,title:j("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(ho,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:g,showTitle:!1,legendCount:u.shelf.items.some(z=>z.records)?h("metaHome.shelfLegendCount"):null,legendExtra:[h("metaHome.shelfLegendClick")]}),(u.catalog_progress.length>0||u.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(N=u.shelf)!=null&&N.items.length?void 0:{marginTop:0},children:[t.jsx(hm,{rows:u.catalog_progress,links:i}),t.jsx(gm,{works:u.related_catalogs,links:i})]})]}),w.sibu&&t.jsx(Rt,{id:y.sibu,title:j("sibu"),sub:h("metaHome.sibuSub"),more:S(o,h("metaHome.toCatalog")),children:t.jsx(fo,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),w.cong&&t.jsx(Rt,{id:y.cong,title:j("cong"),sub:h("metaHome.congSub"),more:S(a,h("metaHome.allNKindsMore",{n:kt(u.counts.collections)})),children:t.jsx(ym,{groups:u.collection_groups,links:i})}),w.people&&t.jsx(Rt,{id:y.people,title:j("people"),sub:h("metaHome.peopleSub"),more:S(l,h("metaHome.allNPeopleMore",{n:kt(u.counts.entities)})),children:t.jsx(jm,{people:u.bibliographers,links:i})}),w.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(km,{works:u.lineage,links:i})}),w.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(wm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx(vm,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const $m=["_related","_catalogs","_collections","_members","_children","_book_groups"],W0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),bs=e=>W0(e)&&!!e.h;function U0(e){return e?$m.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(bs)}):!1}function K0(e,i){const n={...e};if(!i)return n;for(const r of $m){const o=e[r];!Array.isArray(o)||!o.some(bs)||(n[r]=o.map(a=>{var c;if(!bs(a)||typeof a.title=="string"&&a.title)return a;const l=a.id??a.bid,d=l?(c=i[l])==null?void 0:c.title:void 0;return d?{...a,title:d}:a}))}return n}function Y0(e){let i=null;const n=()=>e.getHubs?(i??(i=e.getHubs().catch(()=>null)),i):Promise.resolve(null);return new Proxy(e,{get(r,o){if(o==="getItem")return async l=>{const d=await r.getItem(l);return d&&K0(d,U0(d)?await n():null)};const a=Reflect.get(r,o,r);return typeof a=="function"?a.bind(r):a}})}const hs=({style:e})=>{const i=b.useContext(s.LocaleContext),{t:n}=oe();if(!i)return null;const{locale:r,setLocale:o}=i,a=r==="zh-Hant",l=()=>o(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:n(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 ${s.bim("border")}`,borderRadius:"4px",background:s.bim("bg"),color:s.bim("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?s.bim("primary"):void 0,fontWeight:a?700:400},children:n("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:s.bim("primary"),fontWeight:a?400:700},children:n("common.localeShortHans")})]})},fs=({href:e,label:i,size:n=16,className:r,style:o})=>{const{t:a}=oe(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:n+8,height:n+8,borderRadius:4,color:s.bim("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...o},onMouseEnter:d=>{d.currentTarget.style.color=s.bim("fg")},onMouseLeave:d=>{d.currentTarget.style.color=s.bim("desc-fg")},children:t.jsx("svg",{width:n,height:n,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 Ur(e){const i=e.text_count;return typeof i=="number"&&i>0}function Kr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function G0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const V0=({id:e,transport:i,initialDetail:n,initialEntry:r,activeTab:o,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:m,lineageCollection:p,onLineageCollectionChange:h,initialPage:u=1,selectedLineageNodeId:f,onNavigate:g,onBack:y,backLabel:v,renderLink:w,assetBase:x,enrichDetail:j,getSourceLink:S,readLink:$,railTop:N,extraTabs:z=[],showFeedbackTab:C=!0,feedbackApiUrl:U,height:R,footerExtra:L,hideHeaderControls:F=!1,className:T,style:Z})=>{const O=b.useMemo(()=>Y0(i),[i]),ae=b.useMemo(()=>gd(O)??ro(U),[O,U]),ce=s.useT(),{t:Ee,convert:we}=oe(),[ye]=b.useState(()=>{if(!G0(e,n))return null;const ee={...n},Se=r??Kr(e,ee);return j&&j(Se,ee),{id:e,entry:Se,detail:ee}}),[Q,Ne]=b.useState((ye==null?void 0:ye.entry)??null),[W,je]=b.useState((ye==null?void 0:ye.detail)??null),[K,V]=b.useState(!ye),[re,X]=b.useState(!1),[I,ue]=b.useState([]),[fe,ze]=b.useState(!1),[B,pe]=b.useState(null),[Te,ve]=b.useState(null),[Ve,qe]=b.useState(null),[Xe,J]=b.useState(!1),ie=b.useRef(null),me=b.useRef(0),[se,de]=b.useState(null),ge=l!==void 0?l:se,Oe=b.useCallback(ee=>{d?d(ee):de(ee)},[d]),Je=b.useCallback(async ee=>{if(!O.getCollectionCatalogs&&!O.getCollectionCatalog){ue([]);return}ze(!0);try{if(O.getCollectionCatalogs)ue(await O.getCollectionCatalogs(ee)||[]);else if(O.getCollectionCatalog){const Se=await O.getCollectionCatalog(ee);ue(Se?[{resource_id:"",data:Se}]:[])}}catch{ue([])}finally{ze(!1)}},[O]),Pe=b.useCallback(async ee=>{var Se,et;if(!O.getTextManifest||!O.getTextIndex){pe(null),ve(ee);return}try{const tt=_e.pickTextVersion(await O.getTextManifest(ee)),De=tt?await O.getTextIndex(ee,tt.key):null;pe(De&&De.chapters.length>0?{chapters:De.chapters.map(Fe=>({n:Fe.n,title:Fe.title,file:Fe.file})),source:{name:((Se=De.source)==null?void 0:Se.name)??(tt==null?void 0:tt.source_name),license:((et=De.source)==null?void 0:et.license)??(tt==null?void 0:tt.license)??void 0}}:null)}catch{pe(null)}finally{ve(ee)}},[O]),Ue=b.useCallback(async(ee,Se)=>{const et=++me.current,tt=()=>et!==me.current;J(!0);try{if(O.getLineageGraph){const gt=await O.getLineageGraph(ee);if(tt())return;gt&&qe(gt)}const De=Se.version_graph;if(!De||!De.enabled){Ve||qe(null),ie.current=null;return}const Fe=Ss(Se),bt=(await tr(Fe,er,async gt=>{try{return await O.getItem(gt)}catch{return null}},tt)).filter(Boolean);if(tt())return;ie.current={work:Se,books:bt};const ht=p??De.default_collection??(De.core_books&&De.core_books.length>0?"core":"all"),We=ht==="core"&&Array.isArray(De.core_books)&&De.core_books.length>0?"core":ht??"all";qe(Sn(Se,bt,We))}catch{if(tt())return;qe(null),ie.current=null}finally{tt()||J(!1)}},[O]),nt=b.useRef({initialDetail:n,initialEntry:r});nt.current={initialDetail:n,initialEntry:r},b.useEffect(()=>{let ee=!1;me.current++,J(!1);const Se=Fe=>{Fe.type==="collection"?Je(e):Fe.type==="work"?(Fe.version_graph||O.getLineageGraph)&&Ue(e,Fe):Fe.type==="book"&&Ur(Fe)&&Pe(e)},et=nt.current;let tt=null;if(ye&&ye.id===e)tt=ye;else if(et.initialDetail&&et.initialDetail.id===e){const Fe={...et.initialDetail},pt=et.initialEntry??Kr(e,Fe);j&&j(pt,Fe),tt={entry:pt,detail:Fe}}return tt?(X(!1),ue(Fe=>Fe.length?[]:Fe),pe(null),qe(null),ie.current=null,Ne(tt.entry),je(tt.detail),V(!1),Se(tt.detail),()=>{ee=!0}):((async()=>{V(!0),X(!1),Ne(null),je(null),ue([]),pe(null),qe(null),ie.current=null;try{const Fe=await O.getItem(e);if(ee)return;if(!Fe){X(!0);return}const pt=Fe;let bt=null;if(O.getEntry&&(bt=await O.getEntry(e),ee))return;bt||(bt=Kr(e,pt)),j&&j(bt,pt),Ne(bt),je(pt),Se(pt)}catch{ee||X(!0)}finally{ee||V(!1)}})(),()=>{ee=!0})},[e,O,ye,j,Je,Ue,Pe]),b.useEffect(()=>{const ee=ie.current;!ee||!p||qe(Sn(ee.work,ee.books,p))},[p]);const Y=[];if(W){if(Y.push({key:"basic",label:ce.detailTab.basicInfo}),W.type==="collection"){fe&&I.length===0&&Y.push({key:"catalog:loading",label:`${ce.detailTab.catalog}…`});for(const ee of I)Y.push({key:`catalog:${ee.resource_id}`,label:ee.short_name?`${we(ee.short_name)}${ce.detailTab.catalogSuffix}`:ce.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&Y.push({key:o,label:ce.detailTab.fullText}),W.type==="work"&&(Ve||Xe)&&Y.push({key:"lineage",label:Xe?`${ce.detailTab.lineage}…`:ce.detailTab.lineage});for(const ee of z)(ee.position??"before-feedback")==="before-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label});C&&o==="feedback"&&Y.push({key:"feedback",label:ce.detailTab.feedback});for(const ee of z)ee.position==="after-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label})}b.useEffect(()=>{if(o!=="emendated"||!W)return;a("basic");const ee=setTimeout(()=>{var Se;(Se=document.getElementById("studies"))==null||Se.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(ee)},[o,W,a]);const M=Q&&W&&S?S({activeTab:o,activeJuan:ge,entry:Q,detail:W}):null,k=b.useMemo(()=>{var De,Fe,pt,bt,ht;if(!W)return null;const Se=(W.authors??[]).map(We=>{const gt=vs(We.role);return`${We.dynasty?`〔${we(We.dynasty)}〕`:""}${we(We.name)}${gt?` ${we(gt)}`:""}`}).join(" · ");let et=!1;try{et=_e.extractStatus(W.id)==="draft"}catch{}if(W.type==="book"){const We=W;return{title:we(We.title),subtitle:We.edition?we(We.edition):Se||void 0,aside:[et?ce.status.draft:"",Se&&We.edition?Se:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(W.type==="collection"){const We=W;return{title:we(We.title),subtitle:we(qt(We,ce.unit.juan))||void 0,aside:[(De=We.publication_info)==null?void 0:De.year,et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:Se||void 0}}if(W.type==="entity"){const We=W,gt=A=>A==null?"":A<0?Ee("detail.bce",{n:-A}):String(A),te=((Fe=We.dates)==null?void 0:Fe.birth)!=null||((pt=We.dates)==null?void 0:pt.death)!=null?`${gt(((bt=We.dates)==null?void 0:bt.birth)??void 0)||"?"}—${gt(((ht=We.dates)==null?void 0:ht.death)??void 0)||"?"}`:"";return{title:we(We.primary_name||We.title),subtitle:[We.dynasty?`〔${we(We.dynasty)}〕`:"",te].filter(Boolean).join(" ")||void 0,aside:et?ce.status.draft:void 0,secondLine:void 0}}const tt=we(qt(W,ce.unit.juan));return{title:we(W.title),subtitle:[tt,Se].filter(Boolean).join(" · ")||void 0,aside:[X0(ce,W.subtype),et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[W,we,ce,Ee]),P=W&&Ur(W)?"text":null,q=()=>{Oe(null),a("fulltext")};let _=null;if(W&&$){const ee=$({detail:W,kind:P});ee&&(_=t.jsx(ts,{href:ee}))}else P&&(_=t.jsx(ts,{onClick:q}));const le=ee=>{if(!W)return null;const Se=ee.replace(/\.[^.]+$/,"");if($){const et=$({detail:W,kind:P,juan:Se});return et?{href:et}:null}return{onClick:()=>{Oe(Se),a("fulltext")}}},H=new Set(z.map(ee=>ee.key)),he=Y.filter(ee=>ee.key.startsWith("catalog:")&&ee.key!=="catalog:loading"||ee.key==="lineage"&&!!Ve&&!Xe||H.has(ee.key)).map(ee=>({key:ee.key,label:ee.label,onClick:()=>a(ee.key)})),xe=()=>{var ee;return W?W.type==="work"?t.jsx(zd,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he}):W.type==="book"?t.jsx(Rd,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,fullText:B,fullTextPending:Ur(W)&&!!O.getTextManifest&&Te!==W.id,chapterLink:le,railTop:N,railLinks:he}):W.type==="collection"?t.jsx(Td,{data:W,catalog:(ee=I[0])==null?void 0:ee.data,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he,catalogAction:I.length>0?t.jsxs("a",{href:"#catalog",onClick:Se=>{Se.preventDefault(),a(`catalog:${I[0].resource_id}`)},children:[we(ce.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ad,{data:W,transport:O,onNavigate:g,renderLink:w,railTop:N,railLinks:he,assetBase:x}):null},Re=()=>{var Se,et,tt;if(!Q||!W)return null;if(o==="basic"||o==="emendated")return xe();if(typeof o=="string"&&o.startsWith("catalog:")){const De=(Se=I.find(Fe=>`catalog:${Fe.resource_id}`===o))==null?void 0:Se.data;return t.jsx(tc,{data:De,onNavigate:g,renderLink:w})}if(o==="collated"||o==="fulltext")return t.jsx(fd,{id:e,transport:O,chapter:ge,onLocationChange:De=>Oe(De.chapter),onNavigate:g});if(o==="lineage"){if(!Ve)return t.jsx("div",{style:{color:s.bim("label-fg"),padding:"24px 0"},children:Ee(Xe?"detail.loading":"detail.noLineageGraph")});const De=W.type==="work"?W:null;return t.jsx(lo,{graph:Ve,renderLink:w,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((et=De==null?void 0:De.version_graph)==null?void 0:et.default_collection),onCollectionChange:h,collectionsAvailable:(tt=De==null?void 0:De.version_graph)==null?void 0:tt.collections,collectionCounts:(()=>{var ht,We,gt,te,A,ne,$e;if(!De)return;const Fe={},pt=((ht=ie.current)==null?void 0:ht.books)??[];Fe.all=(((We=De._books)==null?void 0:We.length)??0)-(((te=(gt=De.version_graph)==null?void 0:gt.excluded_books)==null?void 0:te.length)??0);const bt=(A=De.version_graph)==null?void 0:A.collections;if(bt)for(const Ie of Object.keys(bt))Fe[Ie]=Sn(De,pt,Ie).nodes.filter(Le=>Le.kind==="book"&&!Le.bridge).length;return Fe.core==null&&(($e=(ne=De.version_graph)==null?void 0:ne.core_books)!=null&&$e.length)&&(Fe.core=De.version_graph.core_books.length),Fe})()})}if(o==="feedback"&&C)return t.jsx(vd,{resourceId:e,transport:ae});const ee=z.find(De=>De.key===o);return ee?ee.render({detail:W,entry:Q,transport:O,onNavigate:g}):null};if(K)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((ee,Se)=>t.jsx("div",{style:{height:Se===1?40:16,width:ee,opacity:.35,background:s.bim("rule")}},Se))})});if(re||!W||!Q||!k)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:s.bim("label-fg"),fontSize:14},children:Ee("detail.notFound")})});const Ze=o==="basic"||o==="emendated",Me=[{label:v??ce.detailTab.backToIndex,onClick:y}];if(W.type==="book"&&W.work_id){const ee=W.work_id;Me.push({label:ce.indexType.work,id:ee,onClick:()=>g==null?void 0:g(ee)})}Me.push({label:ce.indexType[W.type]});const He=o==="collated"||o==="fulltext",ct=typeof L=="string"?ce.status[L.trim()]??L:L,Be=t.jsx(Mc,{left:t.jsxs(t.Fragment,{children:[ct,ct?" · ":"",t.jsx(q0,{id:W.id,label:ce.label.id,copied:ce.action.copied,copyLabel:ce.action.copy})]}),right:t.jsxs(t.Fragment,{children:[C&&!Ze&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.submitVersion}),M&&t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:s.bim("meta-fg")},children:ce.detailTab.dataLicense})]})});return Ze?t.jsx("div",{className:T,children:t.jsxs(Hi,{grid:!0,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsx(ns,{items:Me}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{style:{border:"none",background:"transparent"}}),!F&&M&&t.jsx(fs,{...M})]})}),xe(),Be]})}):t.jsx("div",{className:T,children:t.jsxs(Hi,{wide:He,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Ms,{char:"籍"}),t.jsx(ns,{items:Me})]}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{}),C&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.feedback}),!F&&M&&t.jsx(fs,{...M})]})}),t.jsx(Sc,{...k,aside:He?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:s.bim("accent"),borderBottom:`1px solid ${s.bim("rule")}`},children:[Ee("detail.workInfo")," →"]}):k.aside}),!He&&Y.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:Y.map(ee=>t.jsx($c,{label:ee.label,active:ee.key===o||Ze&&ee.key==="basic",onClick:()=>a(ee.key)},ee.key))}),t.jsx("div",{style:{marginTop:!He&&Y.length>1?8:0},children:Re()}),Be]})})};function q0({id:e,label:i,copied:n,copyLabel:r}){const[o,a]=b.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[i," ",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:o?n:r,"aria-label":o?n:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:s.bim("aux-fg")},children:o?"✓":"⧉"})]})}function X0(e,i){return i?e.workSubtype[i]??i:""}const _m=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],rr="zhusha",sr="bim-theme";function Nm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function or(e){return Nm(e)?e:rr}function J0(){try{return or(window.localStorage.getItem(sr))}catch{return rr}}function zm(e){try{window.localStorage.setItem(sr,e)}catch{}}function Cm(e){const i=or(e);return document.documentElement.setAttribute("data-theme",i),i}function Em(){return or(document.documentElement.getAttribute("data-theme"))}const Z0=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],xo="airy",ar="bim-layout";function Rm(e){return e==="airy"||e==="boxed"}function lr(e){return Rm(e)?e:xo}function Q0(){try{return lr(window.localStorage.getItem(ar))}catch{return xo}}function ey(e){try{window.localStorage.setItem(ar,e)}catch{}}function ty(e){const i=lr(e);return document.documentElement.setAttribute("data-layout",i),i}function iy(){return lr(document.documentElement.getAttribute("data-layout"))}const ny=`try{var t=localStorage.getItem(${JSON.stringify(sr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(ar)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,ry={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},sy=({onChange:e,style:i})=>{const{t:n}=oe(),[r,o]=b.useState(rr);b.useEffect(()=>{o(Em())},[]);const a=l=>{o(Cm(l)),zm(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:_m.map(l=>{const d=r===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":n(`common.theme.${l.name}`),title:n(`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:s.bim(ry[l.name]),boxShadow:d?`0 0 0 2px ${s.bim("page-bg")}, 0 0 0 3.5px ${s.bim("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=_e.BidLink;exports.BookIndexError=_e.BookIndexError;exports.BookIndexManager=_e.BookIndexManager;exports.BookIndexStorage=_e.BookIndexStorage;exports.BundleStorage=_e.BundleStorage;exports.ConfigError=_e.ConfigError;exports.GithubStorage=_e.GithubStorage;exports.IdGenerationError=_e.IdGenerationError;exports.IdGenerator=_e.IdGenerator;exports.LocalStorage=_e.LocalStorage;exports.MigrationError=_e.MigrationError;exports.StorageError=_e.StorageError;exports.adaptCharCord=_e.adaptCharCord;exports.adaptFig=_e.adaptFig;exports.adaptNorm=_e.adaptNorm;exports.adaptNormDetailed=_e.adaptNormDetailed;exports.adaptPunctJson=_e.adaptPunctJson;exports.base36Decode=_e.base36Decode;exports.base36Encode=_e.base36Encode;exports.base58Decode=_e.base58Decode;exports.buildId=_e.buildId;exports.buildPromotionMap=_e.buildPromotionMap;exports.cleanName=_e.cleanName;exports.decodeId=_e.decodeId;exports.decodeIdString=_e.decodeIdString;exports.encodeId=_e.encodeId;exports.extractIdFromUrl=_e.extractIdFromUrl;exports.extractStatus=_e.extractStatus;exports.extractType=_e.extractType;exports.iiifVolumeOf=_e.iiifVolumeOf;exports.isChapterSegment=_e.isChapterSegment;exports.isTextKey=_e.isTextKey;exports.loadFigUrls=_e.loadFigUrls;exports.loadReaderChapter=_e.loadReaderChapter;exports.loadReaderFiles=_e.loadReaderFiles;exports.matchChapterAcrossVersions=_e.matchChapterAcrossVersions;exports.normalizeCatalog=_e.normalizeCatalog;exports.parseId=_e.parseId;exports.pickTextVersion=_e.pickTextVersion;exports.readerManifest=_e.readerManifest;exports.readerVersions=_e.readerVersions;exports.shardOf=_e.shardOf;exports.smartDecode=_e.smartDecode;exports.textVersionLabel=_e.textVersionLabel;exports.validateResource=_e.validateResource;exports.volumeFromChar=_e.volumeFromChar;exports.Badge=s.Badge;exports.COMMON_TRADITIONAL_CHARS=s.COMMON_TRADITIONAL_CHARS;exports.FormInput=s.FormInput;exports.FormTextArea=s.FormTextArea;exports.LocaleContext=s.LocaleContext;exports.Section=s.Section;exports.TRADITIONAL_ALLOWLIST=s.TRADITIONAL_ALLOWLIST;exports.buildPageUrl=s.buildPageUrl;exports.findTraditionalChars=s.findTraditionalChars;exports.formatTemplate=s.formatTemplate;exports.getDisplayNameFromUrl=s.getDisplayNameFromUrl;exports.getMessages=s.getMessages;exports.getStartPage=s.getStartPage;exports.getT=s.getT;exports.getTypeGroupKey=s.getTypeGroupKey;exports.mergeVolumeResources=s.mergeVolumeResources;exports.normalizeVolumes=s.normalizeVolumes;exports.resourceHref=s.resourceHref;exports.useT=s.useT;exports.volumeStats=s.volumeStats;exports.VARIANT_CHARS=vi.VARIANT_CHARS;exports.normalizeVariants=vi.normalizeVariants;exports.VARIANT_SUPPLEMENT=au.VARIANT_SUPPLEMENT;exports.BidUrlProvider=cu;exports.BookDetailLayout=V0;exports.BookPage=Rd;exports.Breadcrumb=ns;exports.CATALOG_ALL_ID=Gt;exports.CATALOG_CSS=Ld;exports.CATALOG_NARROW_QUERY=co;exports.CATALOG_PAGE_SIZE=mo;exports.CATALOG_UNCLASSIFIED_ID=di;exports.CLASSIFICATIONS=qn;exports.CardFoot=nn;exports.CatalogPage=z0;exports.CatalogPager=Wd;exports.CatalogTree=Od;exports.CheckFilter=kc;exports.Chip=_c;exports.ChipWall=$b;exports.CollectionCatalog=tc;exports.CollectionPage=Td;exports.DEFAULT_LAYOUT=xo;exports.DEFAULT_META_HOME_LINKS=am;exports.DEFAULT_READER_PREFS=Rs;exports.DEFAULT_READ_HOME_LINKS=Kd;exports.DEFAULT_THEME=rr;exports.DETAIL_CSS=vc;exports.DYNASTY_GROUPS=Vn;exports.Dash=Rb;exports.DataTable=Nb;exports.DetailFooter=Mc;exports.DetailGrid=Zi;exports.DetailHeader=Sc;exports.EMPTY_FILTERS=Gn;exports.ENTITY_TEXT_CSS=Xs;exports.EmptyNote=Ob;exports.EntityMark=Qs;exports.EntityPage=Ad;exports.EntityText=Mf;exports.ExpandRow=Tb;exports.ExtLink=Fb;exports.FEEDBACK_FAB_OFFSET_VAR=ds;exports.FILTER_SUPPORT=Yl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=kb;exports.FeedbackButton=Yg;exports.FeedbackDialog=xd;exports.FeedbackForm=yd;exports.FeedbackList=wd;exports.FeedbackTab=vd;exports.FilterChip=$c;exports.GUJI_MARKDOWN_FIELD=ob;exports.GUJI_TABLE_NOTATION=Ac;exports.GlyphBadge=Ms;exports.GujiInteractiveReader=Cg;exports.GujiTable=Ps;exports.GujiTextViewer=to;exports.GujiWarpCanvas=qs;exports.ImagePanel=Xr;exports.IndexBrowser=kp;exports.IntroGrid=jb;exports.LAYOUTS=Z0;exports.LAYOUT_STORAGE_KEY=ar;exports.LOSS_OPTIONS=Kl;exports.LocaleProvider=pu;exports.LocaleToggle=hs;exports.META_HOME_CSS=om;exports.META_HOME_SECTION_IDS=Sm;exports.MetaCatalogTable=hm;exports.MetaCollectionGroups=ym;exports.MetaDataLicense=vm;exports.MetaHomeView=D0;exports.MetaLine=vt;exports.MetaLineageCards=km;exports.MetaOnlineSites=wm;exports.MetaPeopleTimeline=jm;exports.MetaRecentPanel=pm;exports.MetaRelatedCatalogs=gm;exports.MetaTypeChips=dm;exports.ModeIndicator=zl;exports.MoreButton=Sb;exports.MoreLink=Ts;exports.PAGE_MAX_WIDTH=zn;exports.PERIOD_NARROW_SHARE=qd;exports.PageFrame=Hi;exports.Quote=Mb;exports.READER_CSS=sc;exports.READ_HOME_CSS=po;exports.READ_HOME_NARROW_QUERY=on;exports.READ_HOME_SECTION_IDS=sm;exports.READ_PERIOD_LABELS=T0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Fl;exports.ReadButton=ts;exports.ReadFamousWorks=im;exports.ReadHomeView=M0;exports.ReadPeriodBand=nm;exports.ReadPicks=Zd;exports.ReadPieces=rm;exports.ReadSection=Rt;exports.ReadShelf=ho;exports.ReadSibu=fo;exports.ReadStats=Jd;exports.ReadTopicGroup=em;exports.ReadTopics=tm;exports.ReaderMdText=Hs;exports.ReaderShell=uc;exports.ReaderToc=oc;exports.RepoSourceLink=fs;exports.ResourceGroup=Ab;exports.ResourceLine=Lb;exports.ResourceList=xu;exports.ResourceRow=Rc;exports.SEARCH_VIEW_STORAGE_KEY=_s;exports.SEVEN_PAVILIONS_KEY=xm;exports.SNIPPET_MARK_END=$l;exports.SNIPPET_MARK_START=Sl;exports.SORTABLE_TYPES=Ul;exports.SearchInput=El;exports.SearchResults=Zl;exports.Sec=St;exports.SectionHead=wb;exports.SideList=mi;exports.StripWarpRenderer=rs;exports.SummaryCard=tn;exports.THEMES=_m;exports.THEME_INIT_SCRIPT=ny;exports.THEME_STORAGE_KEY=sr;exports.TabFilter=Qi;exports.TableHead=zb;exports.TableRow=Cb;exports.TagRow=Tc;exports.TagRows=Pb;exports.TextButton=vb;exports.TextReader=fd;exports.ThemeToggle=sy;exports.TopStrip=is;exports.VersionLineageGraph=Ed;exports.VersionLineageList=Cd;exports.VersionLineageView=lo;exports.VolumeChips=_b;exports.VolumeLinks=As;exports.WorkCard=Hd;exports.WorkCardGrid=Ud;exports.WorkCatalog=Eg;exports.WorkPage=zd;exports.WorkRow=Dd;exports.adaptEntityJson=Gc;exports.applyLayout=ty;exports.applyTheme=Cm;exports.authorsLine=nr;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Bs;exports.bucketResources=js;exports.buildCatalogTree=y0;exports.buildCollectionTable=Dl;exports.buildLineageGraph=Sn;exports.buildMeiliFilter=ip;exports.buildParagraphBlocks=Dc;exports.buildVersionRow=ks;exports.buildVersionTable=Ol;exports.canParagraphize=Ln;exports.catalogNodeIdOf=g0;exports.catalogNodeIdsOf=x0;exports.catalogPageCount=v0;exports.catalogTotal=uo;exports.classificationPath=sn;exports.clearAllRecentIds=Ns;exports.compareCatalogCards=w0;exports.computeVersionPartition=Ku;exports.countActiveFilters=Xn;exports.createFeedbackTransport=ro;exports.createTextApi=ic;exports.currentLayout=iy;exports.currentTheme=Em;exports.defaultEntityHref=rd;exports.defaultWorkLink=Fd;exports.deriveDating=Lu;exports.deriveEditionType=Wl;exports.deriveEra=Ji;exports.deriveYear=Un;exports.deriveYearRange=ys;exports.detectGenre=Zn;exports.displayAuthorRole=vs;exports.eraRank=Yr;exports.feedbackTransportOf=gd;exports.filtersFromParams=np;exports.filtersToParams=An;exports.findCatalogPath=wi;exports.firstAuthorText=bo;exports.flattenTitles=Ic;exports.flattenToc=mc;exports.fmtCount=kt;exports.formatHitCount=$n;exports.formatVolumeRange=Yn;exports.groupRelatedWorks=Pu;exports.gujiInlineToPlain=yc;exports.hasActiveFilters=Gl;exports.hasGujiMarkdownV02=ab;exports.hasGujiTableNotation=Bb;exports.hasSearchOptions=Qu;exports.headingKey=no;exports.headingsFromPunct=md;exports.isCountedChar=Ds;exports.isDuiduChapter=Rn;exports.isLayoutName=Rm;exports.isThemeName=Nm;exports.lineageHref=lm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Xc;exports.nestHeadings=pd;exports.normalizeEra=Tt;exports.normalizeLayout=lr;exports.normalizeRole=ws;exports.normalizeTheme=or;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Gi;exports.paginationItems=Pd;exports.parseChineseNumber=In;exports.parseGujiInline=xc;exports.parseGujiTable=Pc;exports.parseHeadingKey=ud;exports.pct=go;exports.periodLevel=Vd;exports.pickReaderVersion=dc;exports.readStoredLayout=Q0;exports.readStoredTheme=J0;exports.readerVersionOptionLabel=Qr;exports.remapPlainOffsets=Vc;exports.removeRecentId=Ql;exports.renderFullTextBody=Xb;exports.renderProperNames=Kc;exports.renderReaderInline=Qn;exports.resolveRecentEntry=zs;exports.resourceNote=Kn;exports.resultTabFromParam=pp;exports.resultTabToParam=bp;exports.roleFacets=Bl;exports.rowNo=Eb;exports.sameFilters=rp;exports.sanitizeHeadings=cs;exports.saveRecentId=Vr;exports.segmentEntities=qc;exports.setImageSourceResolver=Nf;exports.shelfColumns=Yd;exports.sortFor=ep;exports.sortYear=Mn;exports.spineHeight=Gd;exports.splitFullTextTables=Ls;exports.splitHighlightSnippet=gs;exports.splitTableRow=Lc;exports.storeLayout=ey;exports.storeTheme=zm;exports.summaryFromEntry=td;exports.summaryFromItem=ed;exports.timelineLayout=cm;exports.toCatalogWorkCard=k0;exports.transportSummaryLoader=id;exports.typeSupportsFilters=Vl;exports.useBidUrl=It;exports.useChapterWarpData=dd;exports.useConvert=xt;exports.useEntitySummaryLoader=Zs;exports.useI18n=oe;exports.useReaderPrefs=cc;exports.useRecentEntries=mm;exports.validateLineageGraph=Nu;exports.withDefaultLinks=ii;exports.withMetaLinks=ni;exports.yearText=Bn;
2120
+ `,am={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ni(e){return{...am,...e??{}}}function lm(e,i){if(e.lineage)return e.lineage(i);const n=e.item(i),r=n.indexOf("#"),[o,a]=r<0?[n,""]:[n.slice(0,r),n.slice(r)];return`${o}${o.includes("?")?"&":"?"}tab=lineage${a}`}function go(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function cm(e){const i=e.filter(m=>Number.isFinite(m.birth_year)||Number.isFinite(m.death_year)),n=e.filter(m=>!i.includes(m));if(!i.length)return{min:0,max:0,placed:[],missing:n};const r=m=>{const p=Number.isFinite(m.birth_year)?m.birth_year:m.death_year-50,h=Number.isFinite(m.death_year)?m.death_year:m.birth_year+50;return[Math.min(p,h),Math.max(p,h)]},o=i.map(r),a=Math.min(...o.map(m=>m[0])),l=Math.max(...o.map(m=>m[1])),d=Math.max(1,l-a),c=i.map((m,p)=>({p:m,from:o[p][0],to:o[p][1]})).sort((m,p)=>m.from-p.from).map(m=>({...m,left:(m.from-a)/d*100,width:Math.max(.8,(m.to-m.from)/d*100)}));return{min:a,max:l,placed:c,missing:n}}function Bn(e,i=s.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function O0(e){return{read:e.item,work:e.item,node:e.node}}function dm({counts:e,links:i}){const{t:n}=oe(),r=i==null?void 0:i.type;if(!r)return null;const o=[["all",n("metaHome.typeAll"),null],["work",n("metaHome.typeLabel.work"),e.works],["book",n("metaHome.typeLabel.book"),e.books],["collection",n("metaHome.typeLabel.collection"),e.collections],["entity",n("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":n("metaHome.typeChipsLabel"),children:o.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:r(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:kt(d)})]})},a))})}function mm(e,i=5){const[n,r]=b.useState(null);b.useEffect(()=>{let a=!1;const l=ei().slice(0,i);if(!l.length||!e){r([]);return}return Promise.all(l.map(d=>zs(e,d))).then(d=>{a||r(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{Ns(),r([])},[]);return{entries:n,clear:o}}function F0(e,i,n){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?n(r):um(e.type,i)}function um(e,i){return i(`metaHome.typeLabel.${e}`)}function pm({entries:e,onClear:i,links:n}){const{t:r,convert:o}=oe(),a=ni(n);return t.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[t.jsxs("div",{className:"bim-mh-recent-h",children:[t.jsx("h2",{id:"bim-mh-recent-h",children:r("metaHome.recentTitle")}),e&&e.length>0&&i&&t.jsx("button",{type:"button",onClick:i,children:r("metaHome.recentClear")})]}),e&&e.length>0&&t.jsx("ol",{children:e.map(l=>t.jsx("li",{children:t.jsxs("a",{href:a.item(l.id),"aria-label":r("metaHome.recentItemLabel",{type:l.type?um(l.type,r):"",title:o(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?r(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:o(l.title)}),t.jsx("small",{"aria-hidden":"true",children:F0(l,r,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function bm(e,i,n,r=!1){return r&&(e==="done"||e==="in_progress")?i(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?i(`metaHome.status.${e}`):n(e)}function hm({rows:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":n("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[n("metaHome.catalogTitle"),t.jsx("small",{children:n("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:n("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:n("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:n("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=go(a.imported,a.total),d=a.work_id??a.collection_id,c=r(a.edition?`${a.name}·${a.edition}`:a.name);return t.jsxs("tr",{children:[t.jsx("th",{scope:"row",children:d?t.jsx("a",{href:o.item(d),children:c}):c}),t.jsx("td",{className:"bim-mh-r",children:kt(a.total)}),t.jsx("td",{className:"bim-mh-r",children:kt(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:bm(a.status,n,r)})})]},a.id||a.name)})})]})}):null}function fm({items:e,links:i,label:n}){const{convert:r}=oe();return t.jsx("ul",{className:"bim-rh-rows","aria-label":n?r(n):void 0,children:e.map(o=>t.jsx("li",{children:t.jsxs("a",{href:i.item(o.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(o.title)}),o.sub&&t.jsx("small",{children:r(o.sub)})]})},o.id))})}function gm({works:e,links:i}){const{t:n}=oe(),[r,o]=b.useState(!1);if(!e.length)return null;const a=qi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":r?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(fm,{items:e.map(l=>({id:l.id,title:l.title,sub:nr(l)||void 0})),links:ni(i)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":r,onClick:()=>o(l=>!l),children:r?n("action.collapse"):n("metaHome.allNWorks",{n:e.length})})]})}const xm="siku_qige";function B0({group:e,links:i}){const{t:n,convert:r}=oe(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(fm,{items:e.items,links:i,label:e.label}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>a(l=>!l),children:o?n("action.collapse"):n("metaHome.allNKinds",{n:e.items.length})})]})}function ym({groups:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const a=e.find(c=>c.key===xm),l=e.filter(c=>c!==a),d=c=>{var m;return((m=c.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:m[1])??c};return t.jsxs(t.Fragment,{children:[a&&t.jsxs(t.Fragment,{children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(a.label),t.jsx("small",{children:r(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":r(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:o.item(c.id),"aria-label":r(c.title),title:r(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:r(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:n("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(B0,{group:c,links:o},c.key))})]})}const yl=34,jl=13;function kl(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Bn(e.birth_year,i):"?"}–${e.death_year!=null?Bn(e.death_year,i):"?"}`}function H0(e,i){const n=i-e,r=n>1200?300:n>400?100:50,o=[];for(let a=Math.ceil(e/r)*r;a<=i;a+=r)o.push(a);return o}function jm({people:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=cm(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-jl):u.left;let y=0;for(;m[y]!=null&&m[y]>g;)y++;return m[y]=f?u.left+u.width:u.left+Math.max(u.width,jl),{...u,lane:y,end:f}}),h=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[p.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:m.length*yl+10},children:p.map(u=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":u.end?"":void 0,style:{left:`${u.left}%`,top:u.lane*yl+4,width:`${Math.max(u.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:o.item(u.p.id),children:[r(u.p.name),t.jsx("small",{className:"bim-rh-num",children:kl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:H0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:Bn(u,n)},u))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":p.length?void 0:"",children:(p.length?e:c).map(u=>t.jsx("li",{children:t.jsxs("a",{href:o.item(u.id),children:[t.jsx("span",{children:r(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?r(u.dynasty):"",kl(u,n)].filter(Boolean).join(" ")})]})},u.id))}),c.length>0&&p.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:n("metaHome.missingLife",{names:r(c.map(u=>u.name).join("、"))})})]})}const D0=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 km({works:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=nr(a);return t.jsx("li",{children:t.jsxs("a",{href:lm(o,a.id),children:[D0,t.jsx("b",{children:r(a.title)}),l&&t.jsx("small",{children:r(l)}),t.jsx("span",{children:n("metaHome.viewLineage")})]})},a.id)})}):null}function wm({sites:e}){const{t:i,convert:n}=oe(),r=e.filter(a=>a.status!=="todo"&&a.total>0),o=e.filter(a=>!r.includes(a));return e.length?t.jsxs(t.Fragment,{children:[r.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:r.map(a=>{const l=go(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:n(a.name)}):t.jsx("span",{children:n(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${kt(a.imported)} / ${kt(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:bm(a.status,i,n,!0)})]})]},a.id||a.name)})}),o.length>0&&t.jsx("p",{className:"bim-mh-todo",children:i("metaHome.plannedSites",{names:n(o.map(a=>a.name).join("、"))})})]}):null}const wl=["extant","partially_extant","lost","unknown"];function vm({stats:e,links:i,version:n,repoUrl:r,downloadHref:o}){const{t:a}=oe(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(m=>[e[m],a(`metaHome.stat.${m}`)]).filter(([m])=>m>0),d=i==null?void 0:i.loss,c=wl.some(m=>{var p;return(((p=e.loss)==null?void 0:p[m])??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(([m,p])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:kt(m)}),t.jsx("span",{children:p})]},p))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:wl.map(m=>{var u;const p=((u=e.loss)==null?void 0:u[m])??0,h=a(`metaHome.lossNote.${m}`);return t.jsx("li",{children:t.jsxs("a",{href:d(m),children:[a(`metaHome.loss.${m}`),t.jsx("small",{className:"bim-rh-num",children:c&&p>0?a("metaHome.lossCount",{n:kt(p),note:h}):h})]})},m)})})]}),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"),r?t.jsx("a",{href:r,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),n&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:n})]}),o&&t.jsx("p",{children:t.jsx("a",{href:o,children:a("metaHome.download")})})]})]})}const Sm={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function W0({sections:e,links:i,head:n,transport:r,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,N;const{t:h}=oe(),u=e,f=ni(i),g=O0(f),y=Sm,v=mm(r),w={zhi:!!(($=u.shelf)!=null&&$.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},x=Object.keys(y).filter(z=>w[z]),j=z=>h(`metaHome.nav.${z}`),S=(z,C)=>z?t.jsx("a",{className:"bim-rh-more",href:z,children:C}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:po+om}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(dm,{counts:u.counts,links:i})]}),r&&t.jsx(pm,{entries:v.entries,onClear:v.clear,links:i})]}),x.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":h("metaHome.navLabel"),children:t.jsx("ul",{children:x.map(z=>t.jsx("li",{children:t.jsx("a",{href:`#${y[z]}`,children:j(z)})},z))})}),t.jsxs("div",{className:"bim-rh-main",children:[w.zhi&&t.jsxs(Rt,{id:y.zhi,title:j("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(ho,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:g,showTitle:!1,legendCount:u.shelf.items.some(z=>z.records)?h("metaHome.shelfLegendCount"):null,legendExtra:[h("metaHome.shelfLegendClick")]}),(u.catalog_progress.length>0||u.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(N=u.shelf)!=null&&N.items.length?void 0:{marginTop:0},children:[t.jsx(hm,{rows:u.catalog_progress,links:i}),t.jsx(gm,{works:u.related_catalogs,links:i})]})]}),w.sibu&&t.jsx(Rt,{id:y.sibu,title:j("sibu"),sub:h("metaHome.sibuSub"),more:S(o,h("metaHome.toCatalog")),children:t.jsx(fo,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),w.cong&&t.jsx(Rt,{id:y.cong,title:j("cong"),sub:h("metaHome.congSub"),more:S(a,h("metaHome.allNKindsMore",{n:kt(u.counts.collections)})),children:t.jsx(ym,{groups:u.collection_groups,links:i})}),w.people&&t.jsx(Rt,{id:y.people,title:j("people"),sub:h("metaHome.peopleSub"),more:S(l,h("metaHome.allNPeopleMore",{n:kt(u.counts.entities)})),children:t.jsx(jm,{people:u.bibliographers,links:i})}),w.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(km,{works:u.lineage,links:i})}),w.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(wm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx(vm,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const $m=["_related","_catalogs","_collections","_members","_children","_book_groups"],U0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),bs=e=>U0(e)&&!!e.h;function K0(e){return e?$m.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(bs)}):!1}function Y0(e,i){const n={...e};if(!i)return n;for(const r of $m){const o=e[r];!Array.isArray(o)||!o.some(bs)||(n[r]=o.map(a=>{var c;if(!bs(a)||typeof a.title=="string"&&a.title)return a;const l=a.id??a.bid,d=l?(c=i[l])==null?void 0:c.title:void 0;return d?{...a,title:d}:a}))}return n}function G0(e){let i=null;const n=()=>e.getHubs?(i??(i=e.getHubs().catch(()=>null)),i):Promise.resolve(null);return new Proxy(e,{get(r,o){if(o==="getItem")return async l=>{const d=await r.getItem(l);return d&&Y0(d,K0(d)?await n():null)};const a=Reflect.get(r,o,r);return typeof a=="function"?a.bind(r):a}})}const hs=({style:e})=>{const i=b.useContext(s.LocaleContext),{t:n}=oe();if(!i)return null;const{locale:r,setLocale:o}=i,a=r==="zh-Hant",l=()=>o(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:n(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 ${s.bim("border")}`,borderRadius:"4px",background:s.bim("bg"),color:s.bim("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?s.bim("primary"):void 0,fontWeight:a?700:400},children:n("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:s.bim("primary"),fontWeight:a?400:700},children:n("common.localeShortHans")})]})},fs=({href:e,label:i,size:n=16,className:r,style:o})=>{const{t:a}=oe(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:n+8,height:n+8,borderRadius:4,color:s.bim("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...o},onMouseEnter:d=>{d.currentTarget.style.color=s.bim("fg")},onMouseLeave:d=>{d.currentTarget.style.color=s.bim("desc-fg")},children:t.jsx("svg",{width:n,height:n,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 Ur(e){const i=e.text_count;return typeof i=="number"&&i>0}function Kr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function V0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const q0=({id:e,transport:i,initialDetail:n,initialEntry:r,activeTab:o,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:m,lineageCollection:p,onLineageCollectionChange:h,initialPage:u=1,selectedLineageNodeId:f,onNavigate:g,onBack:y,backLabel:v,renderLink:w,assetBase:x,enrichDetail:j,getSourceLink:S,readLink:$,railTop:N,extraTabs:z=[],showFeedbackTab:C=!0,feedbackApiUrl:U,height:R,footerExtra:L,hideHeaderControls:F=!1,className:T,style:Z})=>{const O=b.useMemo(()=>G0(i),[i]),ae=b.useMemo(()=>gd(O)??ro(U),[O,U]),ce=s.useT(),{t:Ee,convert:we}=oe(),[ye]=b.useState(()=>{if(!V0(e,n))return null;const ee={...n},Se=r??Kr(e,ee);return j&&j(Se,ee),{id:e,entry:Se,detail:ee}}),[Q,Ne]=b.useState((ye==null?void 0:ye.entry)??null),[W,je]=b.useState((ye==null?void 0:ye.detail)??null),[K,V]=b.useState(!ye),[re,X]=b.useState(!1),[I,ue]=b.useState([]),[fe,ze]=b.useState(!1),[B,pe]=b.useState(null),[Te,ve]=b.useState(null),[Ve,qe]=b.useState(null),[Xe,J]=b.useState(!1),ie=b.useRef(null),me=b.useRef(0),[se,de]=b.useState(null),ge=l!==void 0?l:se,Oe=b.useCallback(ee=>{d?d(ee):de(ee)},[d]),Je=b.useCallback(async ee=>{if(!O.getCollectionCatalogs&&!O.getCollectionCatalog){ue([]);return}ze(!0);try{if(O.getCollectionCatalogs)ue(await O.getCollectionCatalogs(ee)||[]);else if(O.getCollectionCatalog){const Se=await O.getCollectionCatalog(ee);ue(Se?[{resource_id:"",data:Se}]:[])}}catch{ue([])}finally{ze(!1)}},[O]),Pe=b.useCallback(async ee=>{var Se,et;if(!O.getTextManifest||!O.getTextIndex){pe(null),ve(ee);return}try{const tt=_e.pickTextVersion(await O.getTextManifest(ee)),De=tt?await O.getTextIndex(ee,tt.key):null;pe(De&&De.chapters.length>0?{chapters:De.chapters.map(Fe=>({n:Fe.n,title:Fe.title,file:Fe.file})),source:{name:((Se=De.source)==null?void 0:Se.name)??(tt==null?void 0:tt.source_name),license:((et=De.source)==null?void 0:et.license)??(tt==null?void 0:tt.license)??void 0}}:null)}catch{pe(null)}finally{ve(ee)}},[O]),Ue=b.useCallback(async(ee,Se)=>{const et=++me.current,tt=()=>et!==me.current;J(!0);try{if(O.getLineageGraph){const gt=await O.getLineageGraph(ee);if(tt())return;gt&&qe(gt)}const De=Se.version_graph;if(!De||!De.enabled){Ve||qe(null),ie.current=null;return}const Fe=Ss(Se),bt=(await tr(Fe,er,async gt=>{try{return await O.getItem(gt)}catch{return null}},tt)).filter(Boolean);if(tt())return;ie.current={work:Se,books:bt};const ht=p??De.default_collection??(De.core_books&&De.core_books.length>0?"core":"all"),We=ht==="core"&&Array.isArray(De.core_books)&&De.core_books.length>0?"core":ht??"all";qe(Sn(Se,bt,We))}catch{if(tt())return;qe(null),ie.current=null}finally{tt()||J(!1)}},[O]),nt=b.useRef({initialDetail:n,initialEntry:r});nt.current={initialDetail:n,initialEntry:r},b.useEffect(()=>{let ee=!1;me.current++,J(!1);const Se=Fe=>{Fe.type==="collection"?Je(e):Fe.type==="work"?(Fe.version_graph||O.getLineageGraph)&&Ue(e,Fe):Fe.type==="book"&&Ur(Fe)&&Pe(e)},et=nt.current;let tt=null;if(ye&&ye.id===e)tt=ye;else if(et.initialDetail&&et.initialDetail.id===e){const Fe={...et.initialDetail},pt=et.initialEntry??Kr(e,Fe);j&&j(pt,Fe),tt={entry:pt,detail:Fe}}return tt?(X(!1),ue(Fe=>Fe.length?[]:Fe),pe(null),qe(null),ie.current=null,Ne(tt.entry),je(tt.detail),V(!1),Se(tt.detail),()=>{ee=!0}):((async()=>{V(!0),X(!1),Ne(null),je(null),ue([]),pe(null),qe(null),ie.current=null;try{const Fe=await O.getItem(e);if(ee)return;if(!Fe){X(!0);return}const pt=Fe;let bt=null;if(O.getEntry&&(bt=await O.getEntry(e),ee))return;bt||(bt=Kr(e,pt)),j&&j(bt,pt),Ne(bt),je(pt),Se(pt)}catch{ee||X(!0)}finally{ee||V(!1)}})(),()=>{ee=!0})},[e,O,ye,j,Je,Ue,Pe]),b.useEffect(()=>{const ee=ie.current;!ee||!p||qe(Sn(ee.work,ee.books,p))},[p]);const Y=[];if(W){if(Y.push({key:"basic",label:ce.detailTab.basicInfo}),W.type==="collection"){fe&&I.length===0&&Y.push({key:"catalog:loading",label:`${ce.detailTab.catalog}…`});for(const ee of I)Y.push({key:`catalog:${ee.resource_id}`,label:ee.short_name?`${we(ee.short_name)}${ce.detailTab.catalogSuffix}`:ce.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&Y.push({key:o,label:ce.detailTab.fullText}),W.type==="work"&&(Ve||Xe)&&Y.push({key:"lineage",label:Xe?`${ce.detailTab.lineage}…`:ce.detailTab.lineage});for(const ee of z)(ee.position??"before-feedback")==="before-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label});C&&o==="feedback"&&Y.push({key:"feedback",label:ce.detailTab.feedback});for(const ee of z)ee.position==="after-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label})}b.useEffect(()=>{if(o!=="emendated"||!W)return;a("basic");const ee=setTimeout(()=>{var Se;(Se=document.getElementById("studies"))==null||Se.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(ee)},[o,W,a]);const M=Q&&W&&S?S({activeTab:o,activeJuan:ge,entry:Q,detail:W}):null,k=b.useMemo(()=>{var De,Fe,pt,bt,ht;if(!W)return null;const Se=(W.authors??[]).map(We=>{const gt=vs(We.role);return`${We.dynasty?`〔${we(We.dynasty)}〕`:""}${we(We.name)}${gt?` ${we(gt)}`:""}`}).join(" · ");let et=!1;try{et=_e.extractStatus(W.id)==="draft"}catch{}if(W.type==="book"){const We=W;return{title:we(We.title),subtitle:We.edition?we(We.edition):Se||void 0,aside:[et?ce.status.draft:"",Se&&We.edition?Se:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(W.type==="collection"){const We=W;return{title:we(We.title),subtitle:we(qt(We,ce.unit.juan))||void 0,aside:[(De=We.publication_info)==null?void 0:De.year,et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:Se||void 0}}if(W.type==="entity"){const We=W,gt=A=>A==null?"":A<0?Ee("detail.bce",{n:-A}):String(A),te=((Fe=We.dates)==null?void 0:Fe.birth)!=null||((pt=We.dates)==null?void 0:pt.death)!=null?`${gt(((bt=We.dates)==null?void 0:bt.birth)??void 0)||"?"}—${gt(((ht=We.dates)==null?void 0:ht.death)??void 0)||"?"}`:"";return{title:we(We.primary_name||We.title),subtitle:[We.dynasty?`〔${we(We.dynasty)}〕`:"",te].filter(Boolean).join(" ")||void 0,aside:et?ce.status.draft:void 0,secondLine:void 0}}const tt=we(qt(W,ce.unit.juan));return{title:we(W.title),subtitle:[tt,Se].filter(Boolean).join(" · ")||void 0,aside:[J0(ce,W.subtype),et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[W,we,ce,Ee]),P=W&&Ur(W)?"text":null,q=()=>{Oe(null),a("fulltext")};let _=null;if(W&&$){const ee=$({detail:W,kind:P});ee&&(_=t.jsx(ts,{href:ee}))}else P&&(_=t.jsx(ts,{onClick:q}));const le=ee=>{if(!W)return null;const Se=ee.replace(/\.[^.]+$/,"");if($){const et=$({detail:W,kind:P,juan:Se});return et?{href:et}:null}return{onClick:()=>{Oe(Se),a("fulltext")}}},H=new Set(z.map(ee=>ee.key)),he=Y.filter(ee=>ee.key.startsWith("catalog:")&&ee.key!=="catalog:loading"||ee.key==="lineage"&&!!Ve&&!Xe||H.has(ee.key)).map(ee=>({key:ee.key,label:ee.label,onClick:()=>a(ee.key)})),xe=()=>{var ee;return W?W.type==="work"?t.jsx(zd,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he}):W.type==="book"?t.jsx(Rd,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,fullText:B,fullTextPending:Ur(W)&&!!O.getTextManifest&&Te!==W.id,chapterLink:le,railTop:N,railLinks:he}):W.type==="collection"?t.jsx(Td,{data:W,catalog:(ee=I[0])==null?void 0:ee.data,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he,catalogAction:I.length>0?t.jsxs("a",{href:"#catalog",onClick:Se=>{Se.preventDefault(),a(`catalog:${I[0].resource_id}`)},children:[we(ce.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ad,{data:W,transport:O,onNavigate:g,renderLink:w,railTop:N,railLinks:he,assetBase:x}):null},Re=()=>{var Se,et,tt;if(!Q||!W)return null;if(o==="basic"||o==="emendated")return xe();if(typeof o=="string"&&o.startsWith("catalog:")){const De=(Se=I.find(Fe=>`catalog:${Fe.resource_id}`===o))==null?void 0:Se.data;return t.jsx(tc,{data:De,onNavigate:g,renderLink:w})}if(o==="collated"||o==="fulltext")return t.jsx(fd,{id:e,transport:O,chapter:ge,onLocationChange:De=>Oe(De.chapter),onNavigate:g});if(o==="lineage"){if(!Ve)return t.jsx("div",{style:{color:s.bim("label-fg"),padding:"24px 0"},children:Ee(Xe?"detail.loading":"detail.noLineageGraph")});const De=W.type==="work"?W:null;return t.jsx(lo,{graph:Ve,renderLink:w,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((et=De==null?void 0:De.version_graph)==null?void 0:et.default_collection),onCollectionChange:h,collectionsAvailable:(tt=De==null?void 0:De.version_graph)==null?void 0:tt.collections,collectionCounts:(()=>{var ht,We,gt,te,A,ne,$e;if(!De)return;const Fe={},pt=((ht=ie.current)==null?void 0:ht.books)??[];Fe.all=(((We=De._books)==null?void 0:We.length)??0)-(((te=(gt=De.version_graph)==null?void 0:gt.excluded_books)==null?void 0:te.length)??0);const bt=(A=De.version_graph)==null?void 0:A.collections;if(bt)for(const Ie of Object.keys(bt))Fe[Ie]=Sn(De,pt,Ie).nodes.filter(Le=>Le.kind==="book"&&!Le.bridge).length;return Fe.core==null&&(($e=(ne=De.version_graph)==null?void 0:ne.core_books)!=null&&$e.length)&&(Fe.core=De.version_graph.core_books.length),Fe})()})}if(o==="feedback"&&C)return t.jsx(vd,{resourceId:e,transport:ae});const ee=z.find(De=>De.key===o);return ee?ee.render({detail:W,entry:Q,transport:O,onNavigate:g}):null};if(K)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((ee,Se)=>t.jsx("div",{style:{height:Se===1?40:16,width:ee,opacity:.35,background:s.bim("rule")}},Se))})});if(re||!W||!Q||!k)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:s.bim("label-fg"),fontSize:14},children:Ee("detail.notFound")})});const Ze=o==="basic"||o==="emendated",Me=[{label:v??ce.detailTab.backToIndex,onClick:y}];if(W.type==="book"&&W.work_id){const ee=W.work_id;Me.push({label:ce.indexType.work,id:ee,onClick:()=>g==null?void 0:g(ee)})}Me.push({label:ce.indexType[W.type]});const He=o==="collated"||o==="fulltext",ct=typeof L=="string"?ce.status[L.trim()]??L:L,Be=t.jsx(Mc,{left:t.jsxs(t.Fragment,{children:[ct,ct?" · ":"",t.jsx(X0,{id:W.id,label:ce.label.id,copied:ce.action.copied,copyLabel:ce.action.copy})]}),right:t.jsxs(t.Fragment,{children:[C&&!Ze&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.submitVersion}),M&&t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:s.bim("meta-fg")},children:ce.detailTab.dataLicense})]})});return Ze?t.jsx("div",{className:T,children:t.jsxs(Hi,{grid:!0,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsx(ns,{items:Me}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{style:{border:"none",background:"transparent"}}),!F&&M&&t.jsx(fs,{...M})]})}),xe(),Be]})}):t.jsx("div",{className:T,children:t.jsxs(Hi,{wide:He,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Ms,{char:"籍"}),t.jsx(ns,{items:Me})]}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{}),C&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.feedback}),!F&&M&&t.jsx(fs,{...M})]})}),t.jsx(Sc,{...k,aside:He?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:s.bim("accent"),borderBottom:`1px solid ${s.bim("rule")}`},children:[Ee("detail.workInfo")," →"]}):k.aside}),!He&&Y.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:Y.map(ee=>t.jsx($c,{label:ee.label,active:ee.key===o||Ze&&ee.key==="basic",onClick:()=>a(ee.key)},ee.key))}),t.jsx("div",{style:{marginTop:!He&&Y.length>1?8:0},children:Re()}),Be]})})};function X0({id:e,label:i,copied:n,copyLabel:r}){const[o,a]=b.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[i," ",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:o?n:r,"aria-label":o?n:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:s.bim("aux-fg")},children:o?"✓":"⧉"})]})}function J0(e,i){return i?e.workSubtype[i]??i:""}const _m=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],rr="zhusha",sr="bim-theme";function Nm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function or(e){return Nm(e)?e:rr}function Z0(){try{return or(window.localStorage.getItem(sr))}catch{return rr}}function zm(e){try{window.localStorage.setItem(sr,e)}catch{}}function Cm(e){const i=or(e);return document.documentElement.setAttribute("data-theme",i),i}function Em(){return or(document.documentElement.getAttribute("data-theme"))}const Q0=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],xo="airy",ar="bim-layout";function Rm(e){return e==="airy"||e==="boxed"}function lr(e){return Rm(e)?e:xo}function ey(){try{return lr(window.localStorage.getItem(ar))}catch{return xo}}function ty(e){try{window.localStorage.setItem(ar,e)}catch{}}function iy(e){const i=lr(e);return document.documentElement.setAttribute("data-layout",i),i}function ny(){return lr(document.documentElement.getAttribute("data-layout"))}const ry=`try{var t=localStorage.getItem(${JSON.stringify(sr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(ar)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,sy={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},oy=({onChange:e,style:i})=>{const{t:n}=oe(),[r,o]=b.useState(rr);b.useEffect(()=>{o(Em())},[]);const a=l=>{o(Cm(l)),zm(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:_m.map(l=>{const d=r===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":n(`common.theme.${l.name}`),title:n(`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:s.bim(sy[l.name]),boxShadow:d?`0 0 0 2px ${s.bim("page-bg")}, 0 0 0 3.5px ${s.bim("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=_e.BidLink;exports.BookIndexError=_e.BookIndexError;exports.BookIndexManager=_e.BookIndexManager;exports.BookIndexStorage=_e.BookIndexStorage;exports.BundleStorage=_e.BundleStorage;exports.ConfigError=_e.ConfigError;exports.GithubStorage=_e.GithubStorage;exports.IdGenerationError=_e.IdGenerationError;exports.IdGenerator=_e.IdGenerator;exports.LocalStorage=_e.LocalStorage;exports.MigrationError=_e.MigrationError;exports.StorageError=_e.StorageError;exports.adaptCharCord=_e.adaptCharCord;exports.adaptFig=_e.adaptFig;exports.adaptNorm=_e.adaptNorm;exports.adaptNormDetailed=_e.adaptNormDetailed;exports.adaptPunctJson=_e.adaptPunctJson;exports.base36Decode=_e.base36Decode;exports.base36Encode=_e.base36Encode;exports.base58Decode=_e.base58Decode;exports.buildId=_e.buildId;exports.buildPromotionMap=_e.buildPromotionMap;exports.cleanName=_e.cleanName;exports.decodeId=_e.decodeId;exports.decodeIdString=_e.decodeIdString;exports.encodeId=_e.encodeId;exports.extractIdFromUrl=_e.extractIdFromUrl;exports.extractStatus=_e.extractStatus;exports.extractType=_e.extractType;exports.iiifVolumeOf=_e.iiifVolumeOf;exports.isChapterSegment=_e.isChapterSegment;exports.isTextKey=_e.isTextKey;exports.loadFigUrls=_e.loadFigUrls;exports.loadReaderChapter=_e.loadReaderChapter;exports.loadReaderFiles=_e.loadReaderFiles;exports.matchChapterAcrossVersions=_e.matchChapterAcrossVersions;exports.normalizeCatalog=_e.normalizeCatalog;exports.parseId=_e.parseId;exports.pickTextVersion=_e.pickTextVersion;exports.readerManifest=_e.readerManifest;exports.readerVersions=_e.readerVersions;exports.shardOf=_e.shardOf;exports.smartDecode=_e.smartDecode;exports.textVersionLabel=_e.textVersionLabel;exports.validateResource=_e.validateResource;exports.volumeFromChar=_e.volumeFromChar;exports.Badge=s.Badge;exports.COMMON_TRADITIONAL_CHARS=s.COMMON_TRADITIONAL_CHARS;exports.FormInput=s.FormInput;exports.FormTextArea=s.FormTextArea;exports.LocaleContext=s.LocaleContext;exports.Section=s.Section;exports.TRADITIONAL_ALLOWLIST=s.TRADITIONAL_ALLOWLIST;exports.buildPageUrl=s.buildPageUrl;exports.findTraditionalChars=s.findTraditionalChars;exports.formatTemplate=s.formatTemplate;exports.getDisplayNameFromUrl=s.getDisplayNameFromUrl;exports.getMessages=s.getMessages;exports.getStartPage=s.getStartPage;exports.getT=s.getT;exports.getTypeGroupKey=s.getTypeGroupKey;exports.mergeVolumeResources=s.mergeVolumeResources;exports.normalizeVolumes=s.normalizeVolumes;exports.resourceHref=s.resourceHref;exports.useT=s.useT;exports.volumeStats=s.volumeStats;exports.VARIANT_CHARS=vi.VARIANT_CHARS;exports.normalizeVariants=vi.normalizeVariants;exports.VARIANT_SUPPLEMENT=au.VARIANT_SUPPLEMENT;exports.BidUrlProvider=cu;exports.BookDetailLayout=q0;exports.BookPage=Rd;exports.Breadcrumb=ns;exports.CATALOG_ALL_ID=Gt;exports.CATALOG_CSS=Ld;exports.CATALOG_NARROW_QUERY=co;exports.CATALOG_PAGE_SIZE=mo;exports.CATALOG_UNCLASSIFIED_ID=di;exports.CLASSIFICATIONS=qn;exports.CardFoot=nn;exports.CatalogPage=C0;exports.CatalogPager=Wd;exports.CatalogTree=Od;exports.CheckFilter=kc;exports.Chip=_c;exports.ChipWall=$b;exports.CollectionCatalog=tc;exports.CollectionPage=Td;exports.DEFAULT_LAYOUT=xo;exports.DEFAULT_META_HOME_LINKS=am;exports.DEFAULT_READER_PREFS=Rs;exports.DEFAULT_READ_HOME_LINKS=Kd;exports.DEFAULT_THEME=rr;exports.DETAIL_CSS=vc;exports.DYNASTY_GROUPS=Vn;exports.Dash=Rb;exports.DataTable=Nb;exports.DetailFooter=Mc;exports.DetailGrid=Zi;exports.DetailHeader=Sc;exports.EMPTY_FILTERS=Gn;exports.ENTITY_TEXT_CSS=Xs;exports.EmptyNote=Ob;exports.EntityMark=Qs;exports.EntityPage=Ad;exports.EntityText=Mf;exports.ExpandRow=Tb;exports.ExtLink=Fb;exports.FEEDBACK_FAB_OFFSET_VAR=ds;exports.FILTER_SUPPORT=Yl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=kb;exports.FeedbackButton=Gg;exports.FeedbackDialog=xd;exports.FeedbackForm=yd;exports.FeedbackList=wd;exports.FeedbackTab=vd;exports.FilterChip=$c;exports.GUJI_MARKDOWN_FIELD=ob;exports.GUJI_TABLE_NOTATION=Ac;exports.GlyphBadge=Ms;exports.GujiInteractiveReader=Eg;exports.GujiTable=Ps;exports.GujiTextViewer=to;exports.GujiWarpCanvas=qs;exports.ImagePanel=Xr;exports.IndexBrowser=kp;exports.IntroGrid=jb;exports.LAYOUTS=Q0;exports.LAYOUT_STORAGE_KEY=ar;exports.LOSS_OPTIONS=Kl;exports.LocaleProvider=pu;exports.LocaleToggle=hs;exports.META_HOME_CSS=om;exports.META_HOME_SECTION_IDS=Sm;exports.MetaCatalogTable=hm;exports.MetaCollectionGroups=ym;exports.MetaDataLicense=vm;exports.MetaHomeView=W0;exports.MetaLine=vt;exports.MetaLineageCards=km;exports.MetaOnlineSites=wm;exports.MetaPeopleTimeline=jm;exports.MetaRecentPanel=pm;exports.MetaRelatedCatalogs=gm;exports.MetaTypeChips=dm;exports.ModeIndicator=zl;exports.MoreButton=Sb;exports.MoreLink=Ts;exports.PAGE_MAX_WIDTH=zn;exports.PERIOD_NARROW_SHARE=qd;exports.PageFrame=Hi;exports.Quote=Mb;exports.READER_CSS=sc;exports.READ_HOME_CSS=po;exports.READ_HOME_NARROW_QUERY=on;exports.READ_HOME_SECTION_IDS=sm;exports.READ_PERIOD_LABELS=I0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Fl;exports.ReadButton=ts;exports.ReadFamousWorks=im;exports.ReadHomeView=A0;exports.ReadPeriodBand=nm;exports.ReadPicks=Zd;exports.ReadPieces=rm;exports.ReadSection=Rt;exports.ReadShelf=ho;exports.ReadSibu=fo;exports.ReadStats=Jd;exports.ReadTopicGroup=em;exports.ReadTopics=tm;exports.ReaderMdText=Hs;exports.ReaderShell=uc;exports.ReaderToc=oc;exports.RepoSourceLink=fs;exports.ResourceGroup=Ab;exports.ResourceLine=Lb;exports.ResourceList=xu;exports.ResourceRow=Rc;exports.SEARCH_VIEW_STORAGE_KEY=_s;exports.SEVEN_PAVILIONS_KEY=xm;exports.SNIPPET_MARK_END=$l;exports.SNIPPET_MARK_START=Sl;exports.SORTABLE_TYPES=Ul;exports.SearchInput=El;exports.SearchResults=Zl;exports.Sec=St;exports.SectionHead=wb;exports.SideList=mi;exports.StripWarpRenderer=rs;exports.SummaryCard=tn;exports.THEMES=_m;exports.THEME_INIT_SCRIPT=ry;exports.THEME_STORAGE_KEY=sr;exports.TabFilter=Qi;exports.TableHead=zb;exports.TableRow=Cb;exports.TagRow=Tc;exports.TagRows=Pb;exports.TextButton=vb;exports.TextReader=fd;exports.ThemeToggle=oy;exports.TopStrip=is;exports.VersionLineageGraph=Ed;exports.VersionLineageList=Cd;exports.VersionLineageView=lo;exports.VolumeChips=_b;exports.VolumeLinks=As;exports.WorkCard=Hd;exports.WorkCardGrid=Ud;exports.WorkCatalog=Rg;exports.WorkPage=zd;exports.WorkRow=Dd;exports.adaptEntityJson=Gc;exports.applyLayout=iy;exports.applyTheme=Cm;exports.authorsLine=nr;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Bs;exports.bucketResources=js;exports.buildCatalogTree=j0;exports.buildCollectionTable=Dl;exports.buildLineageGraph=Sn;exports.buildMeiliFilter=ip;exports.buildParagraphBlocks=Dc;exports.buildVersionRow=ks;exports.buildVersionTable=Ol;exports.canParagraphize=Ln;exports.catalogNodeIdOf=x0;exports.catalogNodeIdsOf=y0;exports.catalogPageCount=S0;exports.catalogTotal=uo;exports.classificationPath=sn;exports.clearAllRecentIds=Ns;exports.compareCatalogCards=v0;exports.computeVersionPartition=Ku;exports.countActiveFilters=Xn;exports.createFeedbackTransport=ro;exports.createTextApi=ic;exports.currentLayout=ny;exports.currentTheme=Em;exports.defaultEntityHref=rd;exports.defaultWorkLink=Fd;exports.deriveDating=Lu;exports.deriveEditionType=Wl;exports.deriveEra=Ji;exports.deriveYear=Un;exports.deriveYearRange=ys;exports.detectGenre=Zn;exports.displayAuthorRole=vs;exports.eraRank=Yr;exports.feedbackTransportOf=gd;exports.filtersFromParams=np;exports.filtersToParams=An;exports.findCatalogPath=wi;exports.firstAuthorText=bo;exports.flattenTitles=Ic;exports.flattenToc=mc;exports.fmtCount=kt;exports.formatHitCount=$n;exports.formatVolumeRange=Yn;exports.groupRelatedWorks=Pu;exports.gujiInlineToPlain=yc;exports.hasActiveFilters=Gl;exports.hasGujiMarkdownV02=ab;exports.hasGujiTableNotation=Bb;exports.hasSearchOptions=Qu;exports.headingKey=no;exports.headingsFromPunct=md;exports.isCountedChar=Ds;exports.isDuiduChapter=Rn;exports.isLayoutName=Rm;exports.isThemeName=Nm;exports.lineageHref=lm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Xc;exports.nestHeadings=pd;exports.normalizeEra=Tt;exports.normalizeLayout=lr;exports.normalizeRole=ws;exports.normalizeTheme=or;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Gi;exports.paginationItems=Pd;exports.parseChineseNumber=In;exports.parseGujiInline=xc;exports.parseGujiTable=Pc;exports.parseHeadingKey=ud;exports.pct=go;exports.periodLevel=Vd;exports.pickReaderVersion=dc;exports.readStoredLayout=ey;exports.readStoredTheme=Z0;exports.readerVersionOptionLabel=Qr;exports.remapPlainOffsets=Vc;exports.removeRecentId=Ql;exports.renderFullTextBody=Xb;exports.renderProperNames=Kc;exports.renderReaderInline=Qn;exports.resolveRecentEntry=zs;exports.resourceNote=Kn;exports.resultTabFromParam=pp;exports.resultTabToParam=bp;exports.roleFacets=Bl;exports.rowNo=Eb;exports.sameFilters=rp;exports.sanitizeHeadings=cs;exports.saveRecentId=Vr;exports.segmentEntities=qc;exports.setImageSourceResolver=Nf;exports.shelfColumns=Yd;exports.sortFor=ep;exports.sortYear=Mn;exports.spineHeight=Gd;exports.splitFullTextTables=Ls;exports.splitHighlightSnippet=gs;exports.splitTableRow=Lc;exports.storeLayout=ty;exports.storeTheme=zm;exports.summaryFromEntry=td;exports.summaryFromItem=ed;exports.timelineLayout=cm;exports.toCatalogWorkCard=w0;exports.transportSummaryLoader=id;exports.typeSupportsFilters=Vl;exports.useBidUrl=It;exports.useChapterWarpData=dd;exports.useConvert=xt;exports.useEntitySummaryLoader=Zs;exports.useI18n=oe;exports.useReaderPrefs=cc;exports.useRecentEntries=mm;exports.validateLineageGraph=Nu;exports.withDefaultLinks=ii;exports.withMetaLinks=ni;exports.yearText=Bn;