book-index-ui 0.66.13 → 0.66.14
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 +16 -16
- package/dist/index.js +766 -753
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -781,8 +781,8 @@ button.bim-rd-pg:hover { border-color: ${s.bim("accent")}; }
|
|
|
781
781
|
.guji-page-indicator:hover, .guji-page-indicator:focus-visible { opacity: 1; }
|
|
782
782
|
.guji-page-indicator:focus-visible { outline: 2px solid ${s.bim("accent")}; outline-offset: 1px; border-radius: 3px; }
|
|
783
783
|
@media ${_n} { .guji-page-indicator { display: none; } }
|
|
784
|
-
`;function Es(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(r=>Es(r,i))):!1}const pa=()=>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 Wp({item:e,activeKey:i,onSelect:n,tabKey:r}){const{t:o}=oe(),a=Es(e,i),[l,d]=b.useState(a||!!e.defaultExpanded);return b.useEffect(()=>{a&&d(!0)},[a]),b.useEffect(()=>{e.defaultExpanded&&d(!0)},[e.defaultExpanded]),e.selectable?t.jsxs("li",{children:[t.jsxs("div",{className:"bim-rd-ti-row",children:[t.jsx("button",{type:"button",className:"bim-rd-ti-tw","aria-expanded":l,"aria-label":o(l?"reader.tocCollapse":"reader.tocExpand"),tabIndex:-1,onClick:()=>d(c=>!c),children:t.jsx(pa,{})}),t.jsxs("button",{type:"button",className:`bim-rd-ti${e.inChapter?"":" bim-rd-ti-group"}`,"aria-current":e.key===i?"true":void 0,disabled:e.disabled,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>{d(!0),n(e.key)},onKeyDown:c=>{c.key==="ArrowRight"&&!l?(c.preventDefault(),d(!0)):c.key==="ArrowLeft"&&l&&(c.preventDefault(),d(!1))},children:[t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]}):t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(pa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]})}function qr({items:e,activeKey:i,onSelect:n,tabKey:r}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(Wp,{item:o,activeKey:i,onSelect:n,tabKey:r},o.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":o.key===i?"true":void 0,disabled:o.disabled,"data-rd-toc-key":o.key,tabIndex:r===o.key?0:-1,onClick:()=>n(o.key),children:[t.jsx("span",{children:o.label}),o.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:o.hint})]})},o.key))})}function ba(e,i){var n;for(const r of e)if(r.key===i||Es(r,i))return r.key;return((n=e[0])==null?void 0:n.key)??null}function lc({items:e,activeKey:i,onSelect:n,label:r}){const{t:o}=oe(),a=r??o("reader.toc"),l=b.useRef(null),[d,c]=b.useState(null);b.useEffect(()=>{c(null)},[i]);const m=b.useMemo(()=>d||(i??ba(e,i)),[d,i,e]);b.useEffect(()=>{const h=l.current;if(!h)return;const u=Array.from(h.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const f=u.find(g=>g.dataset.rdTocKey===m)??u.find(g=>g.dataset.rdTocKey===ba(e,i))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===f?0:-1}),b.useEffect(()=>{const h=l.current,u=h==null?void 0:h.closest(".bim-rd-toc");if(!h||!u||!i)return;const f=Array.from(h.querySelectorAll("[data-rd-toc-key]")).find(y=>y.dataset.rdTocKey===i);if(!f)return;const g=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[i]);const p=b.useCallback(h=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;const f=l.current;if(!f)return;const g=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(x=>!x.disabled),y=g.indexOf(document.activeElement);let v=y;if(h.key==="ArrowDown"?v=Math.min(g.length-1,y+1):h.key==="ArrowUp"?v=Math.max(0,y-1):h.key==="Home"?v=0:h.key==="End"&&(v=g.length-1),v<0||v===y)return;h.preventDefault();const w=g[v];for(const x of g)x.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(qr,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function ha({page:e,crop:i}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:i?`${i.x} ${i.y} ${i.w} ${i.h}`:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((r,o)=>t.jsx("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:"none",stroke:s.bim("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function Up(e){const{boxes:i,width:n,height:r}=e;if(!(i!=null&&i.length)||!n||!r||e.boxFormat&&e.boxFormat!=="bim-charbox-v0")return null;let o=1/0,a=1/0,l=-1/0,d=-1/0;for(const f of i)[f.x,f.y,f.w,f.h].every(Number.isFinite)&&(o=Math.min(o,f.x),a=Math.min(a,f.y),l=Math.max(l,f.x+f.w),d=Math.max(d,f.y+f.h));if(!(l>o)||!(d>a))return null;const c=Math.min(n,r)*.03,m=Math.min(n,Math.max(0,o-c)),p=Math.min(r,Math.max(0,a-c)),h=Math.min(n,Math.max(0,l+c))-m,u=Math.min(r,Math.max(0,d+c))-p;return!(h>0)||!(u>0)||h>=n*.98&&u>=r*.98?null:{x:m,y:p,w:h,h:u}}function Xr({pages:e,loading:i,page:n,onPageChange:r,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=oe(),[d,c]=b.useState(0),m=n??d,p=y=>{r?r(y):c(y)};if(b.useEffect(()=>{n===void 0&&c(0)},[e,n]),i)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:l("reader.imagesLoading")})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:l("reader.noImages")}),t.jsx("span",{children:l("reader.noImagesHint")})]})});const h=Math.max(0,Math.min(e.length-1,m)),u=e[h],f=u.label??`${h+1}`,g=!a&&!o?Up(u):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:g?t.jsxs("figure",{className:"bim-rd-img-fig bim-rd-img-trimmed","data-trim":`${Math.round(g.x)},${Math.round(g.y)},${Math.round(g.w)},${Math.round(g.h)}`,style:{aspectRatio:`${g.w} / ${g.h}`,overflow:"hidden",width:"100%",maxWidth:`calc((100vh - 200px) * ${g.w/g.h})`},children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${u.width/g.w*100}%`,left:`${-g.x/g.w*100}%`,top:`${-g.y/g.h*100}%`}}),t.jsx(ha,{page:u,crop:g})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(ha,{page:u}),o==null?void 0:o(u,h)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.prevImage"),disabled:h===0,onClick:()=>p(h-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${h+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:h===e.length-1,onClick:()=>p(h+1),children:"›"})]})]})}function Kp(e){return e==="lite"||e==="full"}const Vi=[.1,.9],cc=[{key:"song",stack:null},{key:"kai",stack:'"Kaiti SC", "Kaiti TC", STKaiti, "KaiTi", "AR PL UKai CN", "Noto Serif CJK SC", serif'},{key:"system",stack:"var(--bim-font-ui)"}];function Yp(e){var i;return((i=cc.find(n=>n.key===e))==null?void 0:i.stack)??null}const Rs={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!1,banxinMode:"cut"},Yt=[15,16,17,18,20,22,24],Jr=18,dc="bim-reader-prefs",Zr=3,Gp="bim-reading-mode";function Vp(){const e={...Rs};try{const i=localStorage.getItem(dc),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(Gp))==="paragraph"&&(e.readingMode="paragraph"),n.properNameMode==="off"||n.properNameMode==="lite"||n.properNameMode==="full"?e.properNameMode=n.properNameMode:n.properNames===!0?e.properNameMode="full":n.properNames===!1&&(e.properNameMode="off"),n.writingMode==="vertical"&&(e.writingMode="vertical"),n.workLinks===!1&&(e.workLinks=!1),(n.fontFamily==="kai"||n.fontFamily==="system")&&(e.fontFamily=n.fontFamily);const o=n.v,a=o===2||o===Zr;a&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Vi[0]&&n.pageIndicatorY<=Vi[1]&&(e.pageIndicatorY=n.pageIndicatorY),a&&(n.bookTitleStyle==="wavy"||n.bookTitleStyle==="bracket")&&(e.bookTitleStyle=n.bookTitleStyle),n.showWorks===!1&&(e.showWorks=!1),(n.quoteStyle==="modern"||n.quoteStyle==="classic")&&(e.quoteStyle=n.quoteStyle),(n.scriptMode==="orig"||n.scriptMode==="hant"||n.scriptMode==="hans")&&(e.scriptMode=n.scriptMode),o===Zr&&typeof n.preserveMargins=="boolean"&&(e.preserveMargins=n.preserveMargins),(n.banxinMode==="full"||n.banxinMode==="none")&&(e.banxinMode=n.banxinMode)}catch{}return e}function qp(e){try{localStorage.setItem(dc,JSON.stringify({...e,v:Zr}))}catch{}}function xn(e,i){const n=e??Jr,r=Yt;let o=r.indexOf(n);return o<0&&(o=r.indexOf(Jr)),r[Math.max(0,Math.min(r.length-1,o+i))]}function mc(){const[e,i]=b.useState(Rs);b.useEffect(()=>{i(Vp())},[]);const n=b.useCallback(r=>{i(o=>{const a={...o,...r};return qp(a),a})},[]);return[e,n]}function Qr(e){if(e.optionLabel)return e.optionLabel;const i=e.label||e.key;return!e.sourceName||i.includes(e.sourceName)?i:`${i} · ${e.sourceName}`}function uc(e,i){if(!(!e||e.length===0))return(i!=null?e.find(n=>n.key===i):void 0)??e.find(n=>n.primary)??e[0]}function pc(e){const i=[],n=r=>{for(const o of r){if(o.inChapter)continue;const a=!!o.children&&o.children.length>0;(!a||o.selectable)&&i.push(o),a&&n(o.children)}};return n(e),i}const fa=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Xp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M15 5l-7 7 7 7"})}),Jp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M9 5l7 7-7 7"})}),ga=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M4 7h10M18 7h2M4 17h2M10 17h10"}),t.jsx("circle",{cx:"16",cy:"7",r:"2"}),t.jsx("circle",{cx:"8",cy:"17",r:"2"})]}),xa=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function ya(e,i){if(!i)return;const n=Array.from(i.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(n.length===0)return;const r=n[0],o=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===r||!i.contains(a))?(e.preventDefault(),o.focus()):!e.shiftKey&&(a===o||!i.contains(a))&&(e.preventDefault(),r.focus())}function ja(e,i){const[n,r]=b.useState(i);return b.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const o=window.matchMedia(e);r(o.matches);const a=()=>r(o.matches);return(l=o.addEventListener)==null||l.call(o,"change",a),()=>{var d;return(d=o.removeEventListener)==null?void 0:d.call(o,"change",a)}},[e]),n}function Zp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe();if(!r)return null;const a=r.locale==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a,d=[{key:"orig",short:o("reader.scriptOrigShort"),title:o(n?"reader.scriptOrig":"reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",short:o("common.localeShortHant"),title:o("reader.scriptHant")},{key:"hans",short:o("common.localeShortHans"),title:o("reader.scriptHans")}];return t.jsx("span",{className:"bim-rd-script-sw",role:"group","aria-label":o("reader.scriptQuick"),children:d.map((c,m)=>t.jsxs(b.Fragment,{children:[m>0&&t.jsx("span",{className:"bim-rd-off","aria-hidden":"true",children:"|"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":l===c.key,title:c.title,"aria-label":c.title,disabled:c.disabled,onClick:()=>{c.disabled||(i({scriptMode:c.key}),c.key==="hant"?r.setLocale("zh-Hant"):c.key==="hans"&&r.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function Bi({label:e,value:i,options:n,onPick:r,title:o}){return t.jsxs("div",{className:"bim-rd-sp-row",role:"group","aria-label":e,title:o,children:[t.jsx("span",{className:"bim-rd-sp-l",children:e}),t.jsx("span",{className:"bim-rd-sp-fs",children:n.map(a=>t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":i===a.key,title:a.title,disabled:a.disabled,onClick:()=>{a.disabled||r(a.key)},children:a.label},a.key))})]})}function Qp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe(),a=(r==null?void 0:r.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(Bi,{label:o("reader.script"),value:l,options:[{key:"orig",label:o("reader.scriptOrig"),title:n?void 0:o("reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:d=>{i({scriptMode:d}),d==="hant"?r==null||r.setLocale("zh-Hant"):d==="hans"&&(r==null||r.setLocale("zh-Hans"))}})}function eb(e,i){if(!e)return;let n;for(const r of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(r.getBoundingClientRect().top<=i+8)n=r.id;else break;return n}function tb(e){var a;if(typeof window>"u"||!e)return;const i=(a=window.getSelection)==null?void 0:a.call(window);if(!i||i.isCollapsed||i.rangeCount===0)return;const n=e.querySelector(".bim-rd-col"),r=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(n!=null&&n.contains(l))&&!(d!=null&&d.closest(".bim-rd-src, .bim-rd-pager"))};if(!r(i.anchorNode)||!r(i.focusNode))return;const o=i.toString().replace(/\s+/g," ").trim();return o?o.slice(0,500):void 0}function bc({title:e,subtitle:i,toc:n,activeKey:r,tocActiveKey:o,onSelect:a,tocHeader:l,tocCaption:d,images:c,imagesLoading:m,renderImageOverlay:p,imagePanel:h="auto",prefs:u,onPrefsChange:f,paragraphToggle:g,properNameToggle:y=!0,allowVertical:v,origScriptAvailable:w=!0,byline:x,current:j,workLinkToggle:S,rail:$,onReportError:N,revisedAt:z,backHref:C,backLabel:U,bottomBar:R=!0,pager:L=!0,contentLoading:F=!1,pagerUnit:T,versions:Z,currentVersionKey:O,onVersionChange:ae,versionSource:ce=!0,keepChapterOnVersionChange:Ee=!1,customImagePanel:we,isWarpMode:ye,showPreserveMargins:Q=!0,pluginSettings:Ne,pluginToolbar:W,pluginOverlay:je,textRootRef:K,children:V,className:re,style:J}){const{t:I,convert:ue}=oe(),fe=U??I("reader.back"),ze=ue(T??I("reader.unitJuan")),B=b.useId().replace(/:/g,""),pe=`bim-rd-toc-${B}`,Te=`bim-rd-text-${B}`,ve=b.useRef(null),Ve=b.useRef(null),qe=b.useRef(null),Xe=b.useRef(null),X=ja(Cs,!0),ie=ja(Nn,!1),me=R&&ie,[se,de]=b.useState(null),[ge,Oe]=b.useState(!1),Je=b.useRef(null),Pe=`bim-rd-set-${B}`,Ue=b.useRef(null),nt=b.useRef(null),Y=(D,ke)=>{nt.current=ke,de(Qe=>Qe===D?null:D)},M=b.useCallback(()=>{var D;de(null),(D=nt.current)==null||D.focus()},[]);b.useEffect(()=>{me||de(null)},[me]),b.useEffect(()=>{var D,ke;se&&((ke=(D=Ue.current)==null?void 0:D.querySelector("button:not([disabled])"))==null||ke.focus())},[se]);const[k,P]=b.useState("auto"),q=k==="auto"?X:k==="open",_=!X,le=!!we||!!c&&c.length>0,[H,he]=b.useState(h);b.useEffect(()=>{he(h)},[h]);const xe=H==="auto"?le||!!m:H==="open",Re=b.useCallback(D=>{var ke;P("auto"),D&&((ke=Xe.current)==null||ke.focus())},[]),Ze=()=>P(q?"closed":"open");b.useEffect(()=>{if(!_||k!=="open")return;const D=qe.current,ke=D==null?void 0:D.querySelector('input, [data-rd-toc-key][tabindex="0"]');ke==null||ke.focus()},[_,k]);const Me=b.useCallback(D=>{a(D),_&&Re(!1);const ke=Ve.current,Qe=ve.current;if(ke&&Qe&&typeof window<"u"){const Ye=ke.getBoundingClientRect().top-Qe.getBoundingClientRect().bottom;Ye<0&&window.scrollBy({top:Ye})}},[a,_,Re]),He=b.useMemo(()=>pc(n),[n]),[ct,Be]=b.useState(null),ee=uc(Z,O!==void 0?O:ct),Se=(ee==null?void 0:ee.key)??null,et=b.useMemo(()=>He.map(D=>D.key).join(`
|
|
785
|
-
`),[He]),tt=b.useRef(null),De=D=>{D!==Se&&(Ee||(tt.current={key:D,sig:et,done:!1}),O===void 0&&Be(D),ae==null||ae(D))};b.useEffect(()=>{const D=tt.current;if(!D||D.key!==Se)return;const ke=He.find(Ye=>!Ye.disabled);if(!ke)return;const Qe=et!==D.sig;!Qe&&D.done||(Qe?tt.current=null:D.done=!0,ke.key!==r&&Me(ke.key))},[Se,et,He,r,Me]);const Fe=He.find(D=>D.key===r),pt=()=>{var D;N==null||N({chapterKey:r,chapterLabel:typeof(Fe==null?void 0:Fe.label)=="string"?Fe.label:void 0,anchor:eb(Ve.current,((D=ve.current)==null?void 0:D.getBoundingClientRect().bottom)??0),selectedText:tb(Ve.current)})},bt=He.findIndex(D=>D.key===r),ht=bt>0?He.slice(0,bt).reverse().find(D=>!D.disabled):void 0,We=bt>=0?He.slice(bt+1).find(D=>!D.disabled):void 0,gt=u.fontSize??Jr,te=Yp(u.fontFamily),A={...J,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...te?{"--bimrd-ff":te}:null},ne={song:I("reader.fontSong"),kai:I("reader.fontKai"),system:I("reader.fontSystem")},$e=D=>(Ne??[]).filter(ke=>ke.group===D).map(ke=>t.jsx(b.Fragment,{children:ke.node},ke.key)),Ie=$e("text"),Le=$e("annotate"),at=$e("layout"),lt=$e("more"),Ge=[];for(const D of Ne??[]){if(["text","annotate","layout","more"].includes(D.group))continue;let ke=Ge.find(Qe=>Qe.group===D.group);ke?ke.title==null&&(ke.title=D.title):Ge.push(ke={group:D.group,title:D.title,nodes:[]}),ke.nodes.push(t.jsx(b.Fragment,{children:D.node},D.key))}const Ae=_?[W==null?void 0:W.subtitle,W==null?void 0:W.actions].filter(Boolean):[],Ce=lt.length>0||Ae.length>0,rt=y||Le.length>0,st=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g1`,children:[t.jsx("h3",{id:`${Pe}-g1`,className:"bim-rd-sp-h",children:I("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":I("reader.font"),value:u.fontFamily,onChange:D=>f({fontFamily:D.target.value}),children:cc.map(D=>t.jsx("option",{value:D.key,children:ne[D.key]},D.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[gt,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Qp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx(Bi,{label:I("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:I("reader.quoteModern")},{key:"classic",label:I("reader.quoteClassic")},{key:"original",label:I("reader.quoteOriginal")}],onPick:D=>f({quoteStyle:D})}),Ie]}),rt&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g2`,children:[t.jsx("h3",{id:`${Pe}-g2`,className:"bim-rd-sp-h",children:I("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Bi,{label:I("reader.properName"),value:u.properNameMode,title:I("reader.properNameTitle"),options:[{key:"off",label:I("reader.properNameOff")},{key:"lite",label:I("reader.properNameLite"),title:I("reader.properNameLiteTitle")},{key:"full",label:I("reader.properNameFull")}],onPick:D=>f({properNameMode:D})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:D=>f({showWorks:D.target.checked})}),t.jsx("span",{children:I("reader.showWorks")})]}),t.jsx(Bi,{label:I("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:I("reader.bookTitleWavy")},{key:"bracket",label:I("reader.bookTitleBracket")}],onPick:D=>f({bookTitleStyle:D})})]}),Le]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g3`,children:[t.jsx("h3",{id:`${Pe}-g3`,className:"bim-rd-sp-h",children:I("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:I("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:I("reader.paragraph")}),S&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.workLinks,onChange:D=>f({workLinks:D.target.checked})}),t.jsx("span",{children:I("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>f({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:I("reader.vertical")}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.pageBreaks,onChange:D=>f({pageBreaks:D.target.checked})}),t.jsx("span",{children:I("reader.pageBreaks")})]}),Q&&!u.preserveMargins&&t.jsx(Bi,{label:I("reader.banxinMode"),value:u.banxinMode,options:[{key:"cut",label:I("reader.banxinCut")},{key:"full",label:I("reader.banxinFull")},{key:"none",label:I("reader.banxinNone")}],onPick:D=>f({banxinMode:D})}),Q&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:D=>f({preserveMargins:D.target.checked})}),t.jsx("span",{children:I("reader.preserveMargins")})]}),at]}),Ge.map((D,ke)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-c${ke}`,children:[t.jsx("h3",{id:`${Pe}-c${ke}`,className:"bim-rd-sp-h",children:D.title??D.group}),D.nodes]},D.group)),Ce&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g4`,children:[t.jsx("h3",{id:`${Pe}-g4`,className:"bim-rd-sp-h",children:I("reader.groupMore")}),lt,Ae.map((D,ke)=>t.jsx("div",{className:"bim-rd-sp-row",children:D},`tb${ke}`))]})]}),Ke=b.useRef(null);return b.useEffect(()=>{const D=Ke.current;if(!D||!xe)return;let ke=0,Qe=-1;const Ye=()=>{ke=0;const Pt=parseFloat(getComputedStyle(D).top);if(!Number.isFinite(Pt))return;const dt=Math.max(0,Math.round(D.getBoundingClientRect().top-Pt));dt!==Qe&&(Qe=dt,D.style.setProperty("--bimrd-img-lead",`${dt}px`))},wt=()=>{ke||(ke=requestAnimationFrame(Ye))};wt(),window.addEventListener("scroll",wt,{passive:!0}),window.addEventListener("resize",wt);const it=typeof ResizeObserver<"u"?new ResizeObserver(wt):null;return it==null||it.observe(document.body),()=>{window.removeEventListener("scroll",wt),window.removeEventListener("resize",wt),it==null||it.disconnect(),ke&&cancelAnimationFrame(ke),D.style.removeProperty("--bimrd-img-lead")}},[xe]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",re].filter(Boolean).join(" "),"data-toc":k,"data-img":xe?"open":"closed","data-bb":me?"":void 0,"data-set":!me&&ge?"open":void 0,"data-warp":ye?"true":void 0,style:A,children:[t.jsx("style",{children:ac}),t.jsx("a",{className:"bim-rd-skip",href:`#${Te}`,onClick:D=>{var ke,Qe,Ye;D.preventDefault(),(ke=Ve.current)==null||ke.focus(),(Ye=(Qe=Ve.current)==null?void 0:Qe.scrollIntoView)==null||Ye.call(Qe,{block:"start"})},children:I("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:ve,children:[C&&t.jsxs("a",{className:"bim-rd-back",href:C,"aria-label":I("reader.backAria",{label:fe}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:fe})]}),(e||i||x||j||!_&&(W==null?void 0:W.subtitle))&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),x&&t.jsx("span",{className:"bim-rd-by",children:x}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!_&&(W==null?void 0:W.subtitle)&&t.jsx("span",{className:"bim-rd-ttl-src",children:W.subtitle})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":I("reader.settings"),children:[Z&&Z.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ee?ue(Qr(ee)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:I("reader.versionShort")}),t.jsx("select",{"aria-label":I("reader.version"),value:Se??"",onChange:D=>De(D.target.value),children:Z.map(D=>t.jsx("option",{value:D.key,children:ue(Qr(D))},D.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),L&&(ht||We)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":I("reader.pagerGroup",{unit:ze}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.prevUnit",{unit:ze}),title:ht?typeof ht.label=="string"&&ht.label?I("reader.prevUnitTitle",{unit:ze,label:ht.label}):I("reader.prevUnit",{unit:ze}):I("reader.firstUnit",{unit:ze}),disabled:!ht,onClick:()=>ht&&Me(ht.key),children:t.jsx(Xp,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.nextUnit",{unit:ze}),title:We?typeof We.label=="string"&&We.label?I("reader.nextUnitTitle",{unit:ze,label:We.label}):I("reader.nextUnit",{unit:ze}):I("reader.lastUnit",{unit:ze}),disabled:!We,onClick:()=>We&&Me(We.key),children:t.jsx(Jp,{})})]}),L&&(ht||We)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:Xe,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":q,"aria-controls":pe,onClick:Ze,children:[t.jsx(fa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":xe,onClick:()=>he(xe?"closed":"open"),children:[t.jsx(xa,{}),I("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Zp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:Je,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":ge,"aria-controls":Pe,onClick:()=>Oe(D=>!D),children:[t.jsx(ga,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.settings")})]}),!_&&(W==null?void 0:W.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:pe,ref:qe,role:_&&q?"dialog":void 0,"aria-modal":_&&q?!0:void 0,"aria-label":_&&q?I("reader.toc"):void 0,onKeyDown:D=>{if(!(!_||!q)){if(D.key==="Escape"){D.stopPropagation(),Re(!0);return}D.key==="Tab"&&ya(D,qe.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??I("reader.toc")}),_&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeToc"),onClick:()=>Re(!0),children:"✕"})]}),l]}),t.jsx(lc,{items:n,activeKey:o!==void 0?o:r,onSelect:Me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Re(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":I("reader.images"),ref:Ke,children:xe&&(we||t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!me&&ge&&t.jsxs("aside",{className:"bim-rd-set",id:Pe,"aria-label":I("reader.settings"),onKeyDown:D=>{var ke;D.key==="Escape"&&(D.stopPropagation(),Oe(!1),(ke=Je.current)==null||ke.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:I("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeSettings"),onClick:()=>{var D;Oe(!1),(D=Je.current)==null||D.focus()},children:"✕"})]}),st]}),t.jsxs("div",{className:"bim-rd-text",id:Te,ref:D=>{Ve.current=D,K&&(K.current=D)},tabIndex:-1,"data-rail":($||N)&&!ye?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[V,ce&&ee&&(ee.sourceName||ee.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ee.key,children:[ee.sourceName&&t.jsxs(t.Fragment,{children:[I("reader.sourceLabel")," ",ee.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ee.sourceUrl,target:"_blank",rel:"noreferrer",children:ue(ee.sourceName)}):ue(ee.sourceName)]}),ee.sourceName&&ee.license&&t.jsx("span",{className:"bim-rd-dot"}),ee.license&&t.jsx(t.Fragment,{children:I("reader.licenseOf",{license:ee.license})})]}),z&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:I("reader.revisedAt",{date:z})}),N&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})}),L&&!F&&(ht||We)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":I("reader.pagerNav"),children:[ht?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Me(ht.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),I("reader.prevUnit",{unit:ze})]}),t.jsx("span",{className:"bim-rd-pglabel",children:ht.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",I("reader.firstUnit",{unit:ze})]}),We?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Me(We.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[I("reader.nextUnit",{unit:ze}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:We.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[I("reader.lastUnit",{unit:ze})," →"]})]})]}),($||N)&&!ye&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":I("reader.rail"),children:[$,N&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})})]})]})]}),me&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":I("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":q,"aria-controls":pe,onClick:()=>{de(null),Ze()},children:[t.jsx(fa,{}),t.jsx("span",{children:I("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="img","aria-haspopup":"dialog",onClick:D=>Y("img",D.currentTarget),children:[t.jsx(xa,{}),t.jsx("span",{children:I("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="set","aria-haspopup":"dialog",onClick:D=>Y("set",D.currentTarget),children:[t.jsx(ga,{}),t.jsx("span",{children:I("reader.settingsShort")})]}),N&&t.jsxs("button",{type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>{de(null),pt()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:I("reader.reportError")})]})]}),me&&se&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:M}),t.jsxs("div",{className:"bim-rd-sheet",ref:Ue,role:"dialog","aria-modal":"true","aria-label":I(se==="img"?"reader.images":"reader.settings"),onKeyDown:D=>{if(D.key==="Escape"){D.stopPropagation(),M();return}D.key==="Tab"&&ya(D,Ue.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:I(se==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.close"),onClick:M,children:"✕"})]}),se==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):st]})]}),je&&t.jsx("div",{className:"bim-rd-overlay",children:je})]})}function ib(e,i,n){return n?hc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function hc(e){return e.replace(/\r\n/g,`
|
|
784
|
+
`;function Es(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(r=>Es(r,i))):!1}const pa=()=>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 Wp({item:e,activeKey:i,onSelect:n,tabKey:r}){const{t:o}=oe(),a=Es(e,i),[l,d]=b.useState(a||!!e.defaultExpanded);return b.useEffect(()=>{a&&d(!0)},[a]),b.useEffect(()=>{e.defaultExpanded&&d(!0)},[e.defaultExpanded]),e.selectable?t.jsxs("li",{children:[t.jsxs("div",{className:"bim-rd-ti-row",children:[t.jsx("button",{type:"button",className:"bim-rd-ti-tw","aria-expanded":l,"aria-label":o(l?"reader.tocCollapse":"reader.tocExpand"),tabIndex:-1,onClick:()=>d(c=>!c),children:t.jsx(pa,{})}),t.jsxs("button",{type:"button",className:`bim-rd-ti${e.inChapter?"":" bim-rd-ti-group"}`,"aria-current":e.key===i?"true":void 0,disabled:e.disabled,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>{d(!0),n(e.key)},onKeyDown:c=>{c.key==="ArrowRight"&&!l?(c.preventDefault(),d(!0)):c.key==="ArrowLeft"&&l&&(c.preventDefault(),d(!1))},children:[t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]}):t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(pa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]})}function qr({items:e,activeKey:i,onSelect:n,tabKey:r}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(Wp,{item:o,activeKey:i,onSelect:n,tabKey:r},o.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":o.key===i?"true":void 0,disabled:o.disabled,"data-rd-toc-key":o.key,tabIndex:r===o.key?0:-1,onClick:()=>n(o.key),children:[t.jsx("span",{children:o.label}),o.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:o.hint})]})},o.key))})}function ba(e,i){var n;for(const r of e)if(r.key===i||Es(r,i))return r.key;return((n=e[0])==null?void 0:n.key)??null}function lc({items:e,activeKey:i,onSelect:n,label:r}){const{t:o}=oe(),a=r??o("reader.toc"),l=b.useRef(null),[d,c]=b.useState(null);b.useEffect(()=>{c(null)},[i]);const m=b.useMemo(()=>d||(i??ba(e,i)),[d,i,e]);b.useEffect(()=>{const h=l.current;if(!h)return;const u=Array.from(h.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const f=u.find(g=>g.dataset.rdTocKey===m)??u.find(g=>g.dataset.rdTocKey===ba(e,i))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===f?0:-1}),b.useEffect(()=>{const h=l.current,u=h==null?void 0:h.closest(".bim-rd-toc");if(!h||!u||!i)return;const f=Array.from(h.querySelectorAll("[data-rd-toc-key]")).find(y=>y.dataset.rdTocKey===i);if(!f)return;const g=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[i]);const p=b.useCallback(h=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;const f=l.current;if(!f)return;const g=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(x=>!x.disabled),y=g.indexOf(document.activeElement);let v=y;if(h.key==="ArrowDown"?v=Math.min(g.length-1,y+1):h.key==="ArrowUp"?v=Math.max(0,y-1):h.key==="Home"?v=0:h.key==="End"&&(v=g.length-1),v<0||v===y)return;h.preventDefault();const w=g[v];for(const x of g)x.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(qr,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function ha({page:e,crop:i}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:i?`${i.x} ${i.y} ${i.w} ${i.h}`:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((r,o)=>t.jsx("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:"none",stroke:s.bim("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function Up(e){const{boxes:i,width:n,height:r}=e;if(!(i!=null&&i.length)||!n||!r||e.boxFormat&&e.boxFormat!=="bim-charbox-v0")return null;let o=1/0,a=1/0,l=-1/0,d=-1/0;for(const f of i)[f.x,f.y,f.w,f.h].every(Number.isFinite)&&(o=Math.min(o,f.x),a=Math.min(a,f.y),l=Math.max(l,f.x+f.w),d=Math.max(d,f.y+f.h));if(!(l>o)||!(d>a))return null;const c=Math.min(n,r)*.03,m=Math.min(n,Math.max(0,o-c)),p=Math.min(r,Math.max(0,a-c)),h=Math.min(n,Math.max(0,l+c))-m,u=Math.min(r,Math.max(0,d+c))-p;return!(h>0)||!(u>0)||h>=n*.98&&u>=r*.98?null:{x:m,y:p,w:h,h:u}}function Xr({pages:e,loading:i,page:n,onPageChange:r,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=oe(),[d,c]=b.useState(0),m=n??d,p=y=>{r?r(y):c(y)};if(b.useEffect(()=>{n===void 0&&c(0)},[e,n]),i)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:l("reader.imagesLoading")})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:l("reader.noImages")}),t.jsx("span",{children:l("reader.noImagesHint")})]})});const h=Math.max(0,Math.min(e.length-1,m)),u=e[h],f=u.label??`${h+1}`,g=!a&&!o?Up(u):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:g?t.jsxs("figure",{className:"bim-rd-img-fig bim-rd-img-trimmed","data-trim":`${Math.round(g.x)},${Math.round(g.y)},${Math.round(g.w)},${Math.round(g.h)}`,style:{aspectRatio:`${g.w} / ${g.h}`,overflow:"hidden",width:"100%",maxWidth:`calc((100vh - 200px) * ${g.w/g.h})`},children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${u.width/g.w*100}%`,left:`${-g.x/g.w*100}%`,top:`${-g.y/g.h*100}%`}}),t.jsx(ha,{page:u,crop:g})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(ha,{page:u}),o==null?void 0:o(u,h)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.prevImage"),disabled:h===0,onClick:()=>p(h-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${h+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:h===e.length-1,onClick:()=>p(h+1),children:"›"})]})]})}function Kp(e){return e==="lite"||e==="full"}const Vi=[.1,.9],cc=[{key:"song",stack:null},{key:"kai",stack:'"Kaiti SC", "Kaiti TC", STKaiti, "KaiTi", "AR PL UKai CN", "Noto Serif CJK SC", serif'},{key:"system",stack:"var(--bim-font-ui)"}];function Yp(e){var i;return((i=cc.find(n=>n.key===e))==null?void 0:i.stack)??null}const Rs={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!1,banxinMode:"cut"},Yt=[15,16,17,18,20,22,24],Jr=18,dc="bim-reader-prefs",Zr=3,Gp="bim-reading-mode";function Vp(){const e={...Rs};try{const i=localStorage.getItem(dc),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(Gp))==="paragraph"&&(e.readingMode="paragraph"),n.properNameMode==="off"||n.properNameMode==="lite"||n.properNameMode==="full"?e.properNameMode=n.properNameMode:n.properNames===!0?e.properNameMode="full":n.properNames===!1&&(e.properNameMode="off"),n.writingMode==="vertical"&&(e.writingMode="vertical"),n.workLinks===!1&&(e.workLinks=!1),(n.fontFamily==="kai"||n.fontFamily==="system")&&(e.fontFamily=n.fontFamily);const o=n.v,a=o===2||o===Zr;a&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Vi[0]&&n.pageIndicatorY<=Vi[1]&&(e.pageIndicatorY=n.pageIndicatorY),a&&(n.bookTitleStyle==="wavy"||n.bookTitleStyle==="bracket")&&(e.bookTitleStyle=n.bookTitleStyle),n.showWorks===!1&&(e.showWorks=!1),(n.quoteStyle==="modern"||n.quoteStyle==="classic")&&(e.quoteStyle=n.quoteStyle),(n.scriptMode==="orig"||n.scriptMode==="hant"||n.scriptMode==="hans")&&(e.scriptMode=n.scriptMode),o===Zr&&typeof n.preserveMargins=="boolean"&&(e.preserveMargins=n.preserveMargins),(n.banxinMode==="full"||n.banxinMode==="none")&&(e.banxinMode=n.banxinMode)}catch{}return e}function qp(e){try{localStorage.setItem(dc,JSON.stringify({...e,v:Zr}))}catch{}}function xn(e,i){const n=e??Jr,r=Yt;let o=r.indexOf(n);return o<0&&(o=r.indexOf(Jr)),r[Math.max(0,Math.min(r.length-1,o+i))]}function mc(){const[e,i]=b.useState(Rs);b.useEffect(()=>{i(Vp())},[]);const n=b.useCallback(r=>{i(o=>{const a={...o,...r};return qp(a),a})},[]);return[e,n]}function Qr(e){if(e.optionLabel)return e.optionLabel;const i=e.label||e.key;return!e.sourceName||i.includes(e.sourceName)?i:`${i} · ${e.sourceName}`}function uc(e,i){if(!(!e||e.length===0))return(i!=null?e.find(n=>n.key===i):void 0)??e.find(n=>n.primary)??e[0]}function pc(e){const i=[],n=r=>{for(const o of r){if(o.inChapter)continue;const a=!!o.children&&o.children.length>0;(!a||o.selectable)&&i.push(o),a&&n(o.children)}};return n(e),i}const fa=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Xp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M15 5l-7 7 7 7"})}),Jp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M9 5l7 7-7 7"})}),ga=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M4 7h10M18 7h2M4 17h2M10 17h10"}),t.jsx("circle",{cx:"16",cy:"7",r:"2"}),t.jsx("circle",{cx:"8",cy:"17",r:"2"})]}),xa=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function ya(e,i){if(!i)return;const n=Array.from(i.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(n.length===0)return;const r=n[0],o=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===r||!i.contains(a))?(e.preventDefault(),o.focus()):!e.shiftKey&&(a===o||!i.contains(a))&&(e.preventDefault(),r.focus())}function ja(e,i){const[n,r]=b.useState(i);return b.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const o=window.matchMedia(e);r(o.matches);const a=()=>r(o.matches);return(l=o.addEventListener)==null||l.call(o,"change",a),()=>{var d;return(d=o.removeEventListener)==null?void 0:d.call(o,"change",a)}},[e]),n}function Zp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe();if(!r)return null;const a=r.locale==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a,d=[{key:"orig",short:o("reader.scriptOrigShort"),title:o(n?"reader.scriptOrig":"reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",short:o("common.localeShortHant"),title:o("reader.scriptHant")},{key:"hans",short:o("common.localeShortHans"),title:o("reader.scriptHans")}];return t.jsx("span",{className:"bim-rd-script-sw",role:"group","aria-label":o("reader.scriptQuick"),children:d.map((c,m)=>t.jsxs(b.Fragment,{children:[m>0&&t.jsx("span",{className:"bim-rd-off","aria-hidden":"true",children:"|"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":l===c.key,title:c.title,"aria-label":c.title,disabled:c.disabled,onClick:()=>{c.disabled||(i({scriptMode:c.key}),c.key==="hant"?r.setLocale("zh-Hant"):c.key==="hans"&&r.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function Bi({label:e,value:i,options:n,onPick:r,title:o}){return t.jsxs("div",{className:"bim-rd-sp-row",role:"group","aria-label":e,title:o,children:[t.jsx("span",{className:"bim-rd-sp-l",children:e}),t.jsx("span",{className:"bim-rd-sp-fs",children:n.map(a=>t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":i===a.key,title:a.title,disabled:a.disabled,onClick:()=>{a.disabled||r(a.key)},children:a.label},a.key))})]})}function Qp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe(),a=(r==null?void 0:r.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(Bi,{label:o("reader.script"),value:l,options:[{key:"orig",label:o("reader.scriptOrig"),title:n?void 0:o("reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:d=>{i({scriptMode:d}),d==="hant"?r==null||r.setLocale("zh-Hant"):d==="hans"&&(r==null||r.setLocale("zh-Hans"))}})}function eb(e,i){if(!e)return;let n;for(const r of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(r.getBoundingClientRect().top<=i+8)n=r.id;else break;return n}function tb(e){var a;if(typeof window>"u"||!e)return;const i=(a=window.getSelection)==null?void 0:a.call(window);if(!i||i.isCollapsed||i.rangeCount===0)return;const n=e.querySelector(".bim-rd-col"),r=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(n!=null&&n.contains(l))&&!(d!=null&&d.closest(".bim-rd-src, .bim-rd-pager"))};if(!r(i.anchorNode)||!r(i.focusNode))return;const o=i.toString().replace(/\s+/g," ").trim();return o?o.slice(0,500):void 0}function bc({title:e,subtitle:i,toc:n,activeKey:r,tocActiveKey:o,onSelect:a,tocHeader:l,tocCaption:d,images:c,imagesLoading:m,renderImageOverlay:p,imagePanel:h="auto",prefs:u,onPrefsChange:f,paragraphToggle:g,properNameToggle:y=!0,allowVertical:v,origScriptAvailable:w=!0,byline:x,current:j,workLinkToggle:S,rail:$,onReportError:N,revisedAt:z,backHref:C,backLabel:U,bottomBar:R=!0,pager:L=!0,contentLoading:F=!1,pagerUnit:T,versions:Z,currentVersionKey:O,onVersionChange:ae,versionSource:ce=!0,keepChapterOnVersionChange:Ee=!1,customImagePanel:we,isWarpMode:ye,showPreserveMargins:Q=!0,pluginSettings:Ne,pluginToolbar:W,pluginOverlay:je,textRootRef:K,children:V,className:re,style:J}){const{t:I,convert:ue}=oe(),fe=U??I("reader.back"),ze=ue(T??I("reader.unitJuan")),B=b.useId().replace(/:/g,""),pe=`bim-rd-toc-${B}`,Te=`bim-rd-text-${B}`,ve=b.useRef(null),Ve=b.useRef(null),qe=b.useRef(null),Xe=b.useRef(null),X=ja(Cs,!0),ie=ja(Nn,!1),me=R&&ie,[se,de]=b.useState(null),[ge,Oe]=b.useState(!1),Je=b.useRef(null),Pe=`bim-rd-set-${B}`,Ue=b.useRef(null),nt=b.useRef(null),Y=(D,ke)=>{nt.current=ke,de(Qe=>Qe===D?null:D)},M=b.useCallback(()=>{var D;de(null),(D=nt.current)==null||D.focus()},[]);b.useEffect(()=>{me||de(null)},[me]),b.useEffect(()=>{var D,ke;se&&((ke=(D=Ue.current)==null?void 0:D.querySelector("button:not([disabled])"))==null||ke.focus())},[se]);const[k,P]=b.useState("auto"),q=k==="auto"?X:k==="open",_=!X,le=!!we||!!c&&c.length>0,[H,he]=b.useState(h);b.useEffect(()=>{he(h)},[h]);const xe=H==="auto"?le||!!m:H==="open",Re=b.useCallback(D=>{var ke;P("auto"),D&&((ke=Xe.current)==null||ke.focus())},[]),Ze=()=>P(q?"closed":"open");b.useEffect(()=>{if(!_||k!=="open")return;const D=qe.current,ke=D==null?void 0:D.querySelector('input, [data-rd-toc-key][tabindex="0"]');ke==null||ke.focus()},[_,k]);const Me=b.useCallback(D=>{a(D),_&&Re(!1);const ke=Ve.current,Qe=ve.current;if(ke&&Qe&&typeof window<"u"){const Ge=ke.getBoundingClientRect().top-Qe.getBoundingClientRect().bottom;Ge<0&&window.scrollBy({top:Ge})}},[a,_,Re]),He=b.useMemo(()=>pc(n),[n]),[ct,Be]=b.useState(null),ee=uc(Z,O!==void 0?O:ct),Se=(ee==null?void 0:ee.key)??null,et=b.useMemo(()=>He.map(D=>D.key).join(`
|
|
785
|
+
`),[He]),tt=b.useRef(null),De=D=>{D!==Se&&(Ee||(tt.current={key:D,sig:et,done:!1}),O===void 0&&Be(D),ae==null||ae(D))};b.useEffect(()=>{const D=tt.current;if(!D||D.key!==Se)return;const ke=He.find(Ge=>!Ge.disabled);if(!ke)return;const Qe=et!==D.sig;!Qe&&D.done||(Qe?tt.current=null:D.done=!0,ke.key!==r&&Me(ke.key))},[Se,et,He,r,Me]);const Fe=He.find(D=>D.key===r),pt=()=>{var D;N==null||N({chapterKey:r,chapterLabel:typeof(Fe==null?void 0:Fe.label)=="string"?Fe.label:void 0,anchor:eb(Ve.current,((D=ve.current)==null?void 0:D.getBoundingClientRect().bottom)??0),selectedText:tb(Ve.current)})},bt=He.findIndex(D=>D.key===r),ht=bt>0?He.slice(0,bt).reverse().find(D=>!D.disabled):void 0,We=bt>=0?He.slice(bt+1).find(D=>!D.disabled):void 0,gt=u.fontSize??Jr,te=Yp(u.fontFamily),A={...J,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...te?{"--bimrd-ff":te}:null},ne={song:I("reader.fontSong"),kai:I("reader.fontKai"),system:I("reader.fontSystem")},$e=D=>(Ne??[]).filter(ke=>ke.group===D).map(ke=>t.jsx(b.Fragment,{children:ke.node},ke.key)),Ie=$e("text"),Le=$e("annotate"),at=$e("layout"),lt=$e("more"),Ke=[];for(const D of Ne??[]){if(["text","annotate","layout","more"].includes(D.group))continue;let ke=Ke.find(Qe=>Qe.group===D.group);ke?ke.title==null&&(ke.title=D.title):Ke.push(ke={group:D.group,title:D.title,nodes:[]}),ke.nodes.push(t.jsx(b.Fragment,{children:D.node},D.key))}const Ae=_?[W==null?void 0:W.subtitle,W==null?void 0:W.actions].filter(Boolean):[],Ce=lt.length>0||Ae.length>0,rt=y||Le.length>0,st=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g1`,children:[t.jsx("h3",{id:`${Pe}-g1`,className:"bim-rd-sp-h",children:I("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":I("reader.font"),value:u.fontFamily,onChange:D=>f({fontFamily:D.target.value}),children:cc.map(D=>t.jsx("option",{value:D.key,children:ne[D.key]},D.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[gt,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Qp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx(Bi,{label:I("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:I("reader.quoteModern")},{key:"classic",label:I("reader.quoteClassic")},{key:"original",label:I("reader.quoteOriginal")}],onPick:D=>f({quoteStyle:D})}),Ie]}),rt&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g2`,children:[t.jsx("h3",{id:`${Pe}-g2`,className:"bim-rd-sp-h",children:I("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Bi,{label:I("reader.properName"),value:u.properNameMode,title:I("reader.properNameTitle"),options:[{key:"off",label:I("reader.properNameOff")},{key:"lite",label:I("reader.properNameLite"),title:I("reader.properNameLiteTitle")},{key:"full",label:I("reader.properNameFull")}],onPick:D=>f({properNameMode:D})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:D=>f({showWorks:D.target.checked})}),t.jsx("span",{children:I("reader.showWorks")})]}),t.jsx(Bi,{label:I("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:I("reader.bookTitleWavy")},{key:"bracket",label:I("reader.bookTitleBracket")}],onPick:D=>f({bookTitleStyle:D})})]}),Le]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g3`,children:[t.jsx("h3",{id:`${Pe}-g3`,className:"bim-rd-sp-h",children:I("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:I("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:I("reader.paragraph")}),S&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.workLinks,onChange:D=>f({workLinks:D.target.checked})}),t.jsx("span",{children:I("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>f({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:I("reader.vertical")}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.pageBreaks,onChange:D=>f({pageBreaks:D.target.checked})}),t.jsx("span",{children:I("reader.pageBreaks")})]}),Q&&!u.preserveMargins&&t.jsx(Bi,{label:I("reader.banxinMode"),value:u.banxinMode,options:[{key:"cut",label:I("reader.banxinCut")},{key:"full",label:I("reader.banxinFull")},{key:"none",label:I("reader.banxinNone")}],onPick:D=>f({banxinMode:D})}),Q&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:D=>f({preserveMargins:D.target.checked})}),t.jsx("span",{children:I("reader.preserveMargins")})]}),at]}),Ke.map((D,ke)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-c${ke}`,children:[t.jsx("h3",{id:`${Pe}-c${ke}`,className:"bim-rd-sp-h",children:D.title??D.group}),D.nodes]},D.group)),Ce&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g4`,children:[t.jsx("h3",{id:`${Pe}-g4`,className:"bim-rd-sp-h",children:I("reader.groupMore")}),lt,Ae.map((D,ke)=>t.jsx("div",{className:"bim-rd-sp-row",children:D},`tb${ke}`))]})]}),Ye=b.useRef(null);return b.useEffect(()=>{const D=Ye.current;if(!D||!xe)return;let ke=0,Qe=-1;const Ge=()=>{ke=0;const Pt=parseFloat(getComputedStyle(D).top);if(!Number.isFinite(Pt))return;const dt=Math.max(0,Math.round(D.getBoundingClientRect().top-Pt));dt!==Qe&&(Qe=dt,D.style.setProperty("--bimrd-img-lead",`${dt}px`))},wt=()=>{ke||(ke=requestAnimationFrame(Ge))};wt(),window.addEventListener("scroll",wt,{passive:!0}),window.addEventListener("resize",wt);const it=typeof ResizeObserver<"u"?new ResizeObserver(wt):null;return it==null||it.observe(document.body),()=>{window.removeEventListener("scroll",wt),window.removeEventListener("resize",wt),it==null||it.disconnect(),ke&&cancelAnimationFrame(ke),D.style.removeProperty("--bimrd-img-lead")}},[xe]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",re].filter(Boolean).join(" "),"data-toc":k,"data-img":xe?"open":"closed","data-bb":me?"":void 0,"data-set":!me&&ge?"open":void 0,"data-warp":ye?"true":void 0,style:A,children:[t.jsx("style",{children:ac}),t.jsx("a",{className:"bim-rd-skip",href:`#${Te}`,onClick:D=>{var ke,Qe,Ge;D.preventDefault(),(ke=Ve.current)==null||ke.focus(),(Ge=(Qe=Ve.current)==null?void 0:Qe.scrollIntoView)==null||Ge.call(Qe,{block:"start"})},children:I("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:ve,children:[C&&t.jsxs("a",{className:"bim-rd-back",href:C,"aria-label":I("reader.backAria",{label:fe}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:fe})]}),(e||i||x||j||!_&&(W==null?void 0:W.subtitle))&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),x&&t.jsx("span",{className:"bim-rd-by",children:x}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!_&&(W==null?void 0:W.subtitle)&&t.jsx("span",{className:"bim-rd-ttl-src",children:W.subtitle})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":I("reader.settings"),children:[Z&&Z.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ee?ue(Qr(ee)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:I("reader.versionShort")}),t.jsx("select",{"aria-label":I("reader.version"),value:Se??"",onChange:D=>De(D.target.value),children:Z.map(D=>t.jsx("option",{value:D.key,children:ue(Qr(D))},D.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),L&&(ht||We)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":I("reader.pagerGroup",{unit:ze}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.prevUnit",{unit:ze}),title:ht?typeof ht.label=="string"&&ht.label?I("reader.prevUnitTitle",{unit:ze,label:ht.label}):I("reader.prevUnit",{unit:ze}):I("reader.firstUnit",{unit:ze}),disabled:!ht,onClick:()=>ht&&Me(ht.key),children:t.jsx(Xp,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.nextUnit",{unit:ze}),title:We?typeof We.label=="string"&&We.label?I("reader.nextUnitTitle",{unit:ze,label:We.label}):I("reader.nextUnit",{unit:ze}):I("reader.lastUnit",{unit:ze}),disabled:!We,onClick:()=>We&&Me(We.key),children:t.jsx(Jp,{})})]}),L&&(ht||We)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:Xe,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":q,"aria-controls":pe,onClick:Ze,children:[t.jsx(fa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":xe,onClick:()=>he(xe?"closed":"open"),children:[t.jsx(xa,{}),I("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Zp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:Je,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":ge,"aria-controls":Pe,onClick:()=>Oe(D=>!D),children:[t.jsx(ga,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.settings")})]}),!_&&(W==null?void 0:W.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:pe,ref:qe,role:_&&q?"dialog":void 0,"aria-modal":_&&q?!0:void 0,"aria-label":_&&q?I("reader.toc"):void 0,onKeyDown:D=>{if(!(!_||!q)){if(D.key==="Escape"){D.stopPropagation(),Re(!0);return}D.key==="Tab"&&ya(D,qe.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??I("reader.toc")}),_&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeToc"),onClick:()=>Re(!0),children:"✕"})]}),l]}),t.jsx(lc,{items:n,activeKey:o!==void 0?o:r,onSelect:Me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Re(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":I("reader.images"),ref:Ye,children:xe&&(we||t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!me&&ge&&t.jsxs("aside",{className:"bim-rd-set",id:Pe,"aria-label":I("reader.settings"),onKeyDown:D=>{var ke;D.key==="Escape"&&(D.stopPropagation(),Oe(!1),(ke=Je.current)==null||ke.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:I("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeSettings"),onClick:()=>{var D;Oe(!1),(D=Je.current)==null||D.focus()},children:"✕"})]}),st]}),t.jsxs("div",{className:"bim-rd-text",id:Te,ref:D=>{Ve.current=D,K&&(K.current=D)},tabIndex:-1,"data-rail":($||N)&&!ye?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[V,ce&&ee&&(ee.sourceName||ee.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ee.key,children:[ee.sourceName&&t.jsxs(t.Fragment,{children:[I("reader.sourceLabel")," ",ee.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ee.sourceUrl,target:"_blank",rel:"noreferrer",children:ue(ee.sourceName)}):ue(ee.sourceName)]}),ee.sourceName&&ee.license&&t.jsx("span",{className:"bim-rd-dot"}),ee.license&&t.jsx(t.Fragment,{children:I("reader.licenseOf",{license:ee.license})})]}),z&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:I("reader.revisedAt",{date:z})}),N&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})}),L&&!F&&(ht||We)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":I("reader.pagerNav"),children:[ht?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Me(ht.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),I("reader.prevUnit",{unit:ze})]}),t.jsx("span",{className:"bim-rd-pglabel",children:ht.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",I("reader.firstUnit",{unit:ze})]}),We?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Me(We.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[I("reader.nextUnit",{unit:ze}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:We.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[I("reader.lastUnit",{unit:ze})," →"]})]})]}),($||N)&&!ye&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":I("reader.rail"),children:[$,N&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})})]})]})]}),me&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":I("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":q,"aria-controls":pe,onClick:()=>{de(null),Ze()},children:[t.jsx(fa,{}),t.jsx("span",{children:I("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="img","aria-haspopup":"dialog",onClick:D=>Y("img",D.currentTarget),children:[t.jsx(xa,{}),t.jsx("span",{children:I("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="set","aria-haspopup":"dialog",onClick:D=>Y("set",D.currentTarget),children:[t.jsx(ga,{}),t.jsx("span",{children:I("reader.settingsShort")})]}),N&&t.jsxs("button",{type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>{de(null),pt()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:I("reader.reportError")})]})]}),me&&se&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:M}),t.jsxs("div",{className:"bim-rd-sheet",ref:Ue,role:"dialog","aria-modal":"true","aria-label":I(se==="img"?"reader.images":"reader.settings"),onKeyDown:D=>{if(D.key==="Escape"){D.stopPropagation(),M();return}D.key==="Tab"&&ya(D,Ue.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:I(se==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.close"),onClick:M,children:"✕"})]}),se==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):st]})]}),je&&t.jsx("div",{className:"bim-rd-overlay",children:je})]})}function ib(e,i,n){return n?hc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function hc(e){return e.replace(/\r\n/g,`
|
|
786
786
|
`)}const ka=2,nb=400,rb=6,fc=e=>e==="*"||e==="#"||e==="<"||e===">"||/\s/.test(e);function gc(e,i){if(e[i]!=="<"||e[i+1]!=="!"||e[i+2]!=="-"||e[i+3]!=="-")return-1;for(let n=i+4;n+2<e.length;n++)if(e[n]==="-"&&e[n+1]==="-"&&e[n+2]===">")return n+2;return-1}function sb(e,i,n){let r=i;for(let o=0;o<n.length;){if(r>=e.length)return-1;if(n[o]===e[r]){o++,r++;continue}const a=gc(e,r);if(a>=0){r=a+1;continue}if(fc(e[r])){r++;continue}if(n[o]===" "){o++;continue}return-1}return r}function ob(e){const i=Array.from(hc(e));let n=0;return{align(r){if(!r)return;const o=Array.from(r);if(o.every(d=>d===" "||/\s/.test(d)))return;const a=o.length>=rb;let l=0;for(let d=n;d<i.length&&d-n<=(a?nb:ka+64);d++){const c=gc(i,d);if(c>=0){d=c;continue}if(!fc(i[d])){const p=sb(i,d,o);if(p>=0)return n=p,d;if(l++,!a&&l>ka)return}}}}}const ab=65536,lb="guji_markdown";function cb(e){const i=e==null?void 0:e.guji_markdown;if(typeof i!="string")return!1;const n=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(i.trim());if(!n)return!1;const r=parseInt(n[1],10),o=parseInt(n[2],10);return r>0||o>=2}const db=/^□\{guess=([^\s{}]+)\}/;function mb(e,i){const n=e[i+1];return n!==void 0&&!/[A-Za-z/!?>\s]/.test(n)}function xc(e,i){let n=0;for(let r=i;r<e.length;r++){const o=e[r];if(o===`
|
|
787
787
|
`)return-1;if(o==="\\"){r++;continue}if(o==="[")n++;else if(o==="]"&&(n--,n===0))return r}return-1}function ub(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function pb(e,i){const n=e[i];if(n==="["&&e[i+1]==="["){const r=e.indexOf("]]",i+2);return r>=0&&e.slice(i+2,r).indexOf(`
|
|
788
788
|
`)<0?{node:{type:"qw",label:e.slice(i+2,r)},end:r+2}:null}if(n===":"&&e.startsWith(":zi[",i)){const r=xc(e,i+3);return r>i+4?{node:{type:"zi",label:ub(e.slice(i+4,r))},end:r+1}:null}if(n==="□"&&e[i+1]==="{"){const r=db.exec(e.slice(i,i+64));if(r)return{node:{type:"qz",guess:r[1]},end:i+r[0].length}}return null}function yc(e,i,n,r,o){const a=[];let l="",d=!1;const c=()=>{if(!l)return;let m=l;r&&(m=l.replace(/\\?\|/g,p=>d?"|":(d=!0,""))),m&&a.push({type:"text",text:m}),l=""};for(;i<e.length;){const m=e[i];if(m==="\\"&&(e[i+1]==="<"||e[i+1]===">")){l+=e[i+1],i+=2;continue}if(n!==null){if(m===n)return c(),{nodes:a,end:i};if(m===`
|
|
@@ -1543,11 +1543,11 @@ a.bim-et:focus-visible { outline: 2px solid ${s.bim("accent")}; outline-offset:
|
|
|
1543
1543
|
}
|
|
1544
1544
|
`,Ef=120;function Et(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Rf(e,i=Ef){if(!e)return;const n=e.replace(/\s+/g," ").trim(),r=Array.from(n);return r.length>i?r.slice(0,i).join("")+"…":n}function Tf(e){const i=e.dates&&typeof e.dates=="object"?e.dates:{},n=typeof i.birth=="number"?i.birth:void 0,r=typeof i.death=="number"?i.death:void 0;if(!(n===void 0&&r===void 0))return`${n??"?"}–${r??"?"}`}function If(e){if(!Array.isArray(e.authors))return;const i=e.authors.map(n=>{if(!n||typeof n!="object")return"";const r=n,o=Et(r.name);return o?[Et(r.dynasty)&&`〔${Et(r.dynasty)}〕`,o,Et(r.role)].filter(Boolean).join(""):""}).filter(Boolean);return i.length?i.slice(0,3).join("、"):void 0}function id(e,i){const n=Et(i.type),r=Et(i.primary_name)??Et(i.title)??e,o=n==="entity"?[Et(i.dynasty),Tf(i),Et(i.native_place)].filter(Boolean).join(" · "):[If(i),Et(i.edition),Et(i.measure_info)].filter(Boolean).join(" · "),a=i.description&&typeof i.description=="object"?Et(i.description.text):Et(i.description);return{id:Et(i.id)??e,type:n,title:r,meta:o||void 0,description:Rf(a)}}function nd(e){const i=[e.dynasty,e.author,e.edition].filter(Boolean).join(" · ");return{id:e.id,type:e.type,title:e.title,meta:i||void 0}}function rd(e){return async i=>{const n=await e.getItem(i);if(n)return id(i,n);if(e.getEntry){const r=await e.getEntry(i);if(r)return nd(r)}return null}}const Ha=new WeakMap;function sd(e,i,n){let r=Ha.get(e);r||(r=new Map,Ha.set(e,r));const o=r.get(n);if(o)return o;const a=i(n);return r.set(n,a),a.catch(()=>r.delete(n)),a}const od=e=>`/item/${encodeURIComponent(e)}`,os={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Js=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Zs(e,i){return b.useMemo(()=>i?{owner:i,load:i}:e?{owner:e,load:rd(e)}:null,[i,e])}const Mf=e=>e,Af=({text:e,entities:i,offsets:n="text",plainBase:r=0,transport:o,loadSummary:a,buildHref:l=od,onNavigate:d,renderText:c=Mf,hoverDelayMs:m=250,closeDelayMs:p,injectStyles:h=!0,className:u})=>{const f=b.useMemo(()=>{const y=n==="plain"?Xc(e,i,r):i;return Jc(e,y)},[e,i,n,r]),g=Zs(o,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[h&&t.jsx("style",{children:Xs}),f.map(y=>y.type==="text"?t.jsx(b.Fragment,{children:c(y.text)},`t${y.start}`):t.jsx(Qs,{span:y.span,label:y.text,hasBrackets:e[y.start-1]==="《"&&e[y.start+y.text.length]==="》",loader:g,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:m,closeDelayMs:p},`${y.span.key}@${y.start}`))]})};let Jt=null;const Qs=({span:e,label:i,hasBrackets:n,plain:r,loader:o,buildHref:a,onNavigate:l,onCardNavigate:d=l,cardNewTab:c,renderText:m,hoverDelayMs:p,closeDelayMs:h=280})=>{const u=b.useId(),[f,g]=b.useState(!1),[y,v]=b.useState(!1),[w,x]=b.useState(!1),j=b.useRef(!1),S=b.useRef(null),$=b.useRef(null),N=`bim-et bim-et-${e.kind}${r?" bim-et-nu":""}`,z=e.kind==="work"&&!n,C=t.jsxs(t.Fragment,{children:[z&&t.jsx("span",{className:"bim-et-sr",children:"《"}),m(i),z&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),U=()=>{S.current&&(clearTimeout(S.current),S.current=null)},R=()=>{$.current&&(clearTimeout($.current),$.current=null)},L=b.useRef(!1),F=b.useCallback(()=>{L.current=!1,U(),R(),g(!1),v(!1),x(!1),Jt===F&&(Jt=null)},[]);b.useEffect(()=>()=>{U(),R(),Jt===F&&(Jt=null)},[F]);const T=b.useCallback(()=>{Jt&&Jt!==F&&Jt(),Jt=F,g(!0)},[F]),Z=b.useCallback(Q=>{R(),v(!0),!f&&(U(),Q<=0?T():S.current=setTimeout(T,Q))},[f,T]),O=b.useCallback(()=>{U(),R(),!L.current&&($.current=setTimeout(F,h))},[F,h]),ae=b.useRef(null);b.useEffect(()=>{if(!f||!(e.targets||w))return;const Q=w?"click":"pointerdown",Ne=W=>{var je;(je=ae.current)!=null&&je.contains(W.target)||F()};return document.addEventListener(Q,Ne),()=>document.removeEventListener(Q,Ne)},[f,w,e.targets,F]);const ce=b.useCallback(()=>{U(),R(),L.current=!0,v(!0),x(!0),T()},[T]);Js(()=>{if(!f||!w)return;const Q=ae.current,Ne=Q==null?void 0:Q.querySelector(".bim-et-card");if(!Q||!Ne||typeof window>"u")return;const W=()=>{const K=Q.getClientRects(),V=K[K.length-1];if(!V)return;const re=V.bottom+12-Ne.getBoundingClientRect().top;re>0&&window.scrollBy({top:re,behavior:"smooth"})};if(W(),typeof ResizeObserver>"u")return;const je=new ResizeObserver(W);return je.observe(Ne),()=>je.disconnect()},[f,w]);const Ee=!!e.targetId,we=e.targetId,ye={className:"bim-et-w","data-active":y?"":void 0,onPointerEnter:Q=>{j.current=Q.pointerType==="touch"},onPointerDown:Q=>{j.current=Q.pointerType==="touch"},onMouseEnter:()=>{j.current||Z(p)},onMouseLeave:()=>{j.current||O()},onBlur:Q=>{Q.currentTarget.contains(Q.relatedTarget)||F()},onKeyDown:Q=>{Q.key==="Escape"&&f&&(Q.stopPropagation(),F())}};return e.targets?t.jsxs("span",{...ye,ref:ae,children:[t.jsx("span",{className:`${N} bim-et-multi`,role:"button",tabIndex:0,"aria-haspopup":"true","aria-expanded":f,"aria-controls":f?u:void 0,onFocus:()=>{j.current||Z(0)},onClick:()=>{j.current?ce():(R(),L.current=!0,v(!0),T())},onKeyDown:Q=>{(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),f?F():(L.current=!0,v(!0),T()))},children:C}),f&&t.jsx(Lf,{id:u,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:w,onClose:F})]}):!Ee||!we?t.jsxs("span",{...ye,ref:ae,children:[t.jsx("span",{className:N,children:C}),f&&!j.current&&t.jsx(Da,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...ye,ref:ae,children:[t.jsx("a",{className:N,href:a(we),"data-entity-id":we,"aria-describedby":f?u:void 0,onFocus:()=>{j.current||Z(0)},onClick:Q=>{if(j.current&&Q.detail>0){Q.preventDefault(),ce();return}l==null||l(we,Q)},children:C}),f&&t.jsx(Da,{id:u,entityId:we,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:w,onClose:F})]})},Da=({id:e,entityId:i,span:n,loader:r,buildHref:o,onNavigate:a,newTab:l,sheet:d,onClose:c})=>{const{convert:m,t:p}=oe(),h=b.useRef(null),[u,f]=b.useState("start"),[g,y]=b.useState(r&&i?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!r||!i)return;let x=!1;return y({status:"loading"}),sd(r.owner,r.load,i).then(j=>{x||y({status:"ready",summary:j})}).catch(()=>{x||y({status:"error"})}),()=>{x=!0}},[r,i]),Js(()=>{const x=h.current;if(!x||typeof window>"u")return;const j=x.getBoundingClientRect(),S=document.documentElement.clientWidth||window.innerWidth;!d&&j.right>S-8&&u==="start"&&f("end")},[g,u,d]);const v=g.status==="ready"?g.summary:null,w=(v==null?void 0:v.title)??n.canonicalName??n.text;return i?t.jsxs("span",{ref:h,id:e,role:d?"dialog":"tooltip","aria-label":d?w:void 0,className:"bim-et-card","data-align":u,"data-sheet":d?"":void 0,children:[d&&c&&t.jsx(ad,{onClose:c}),t.jsx("span",{className:"bim-et-card-k",children:m(os[n.kind])}),w&&t.jsx("span",{className:"bim-et-card-t",children:m(w)}),(v==null?void 0:v.meta)&&t.jsx("span",{className:"bim-et-card-m",children:m(v.meta)}),(v==null?void 0:v.description)&&t.jsx("span",{className:"bim-et-card-d",children:m(v.description)}),g.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:m("載入中…")}),g.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:m("摘要載入失敗")}),v&&t.jsx("a",{className:"bim-et-card-a",href:o(v.id||i),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?x=>a(v.id||i,x):void 0,children:p("reader.entityDetail")})]}):t.jsx("span",{ref:h,id:e,role:"tooltip",className:"bim-et-card","data-align":u,children:t.jsx("span",{className:"bim-et-card-k",children:m(os[n.kind])})})},Lf=({id:e,span:i,loader:n,buildHref:r,onNavigate:o,newTab:a,sheet:l,onClose:d})=>{const{convert:c}=oe(),m=b.useRef(null),[p,h]=b.useState(0);Js(()=>{const f=m.current;if(!f||l||typeof window>"u")return;const g=f.getBoundingClientRect();if(!g.width)return;const y=document.documentElement.clientWidth||window.innerWidth;h(Math.max(8-g.left,Math.min(0,y-8-g.right)))},[]);const u=i.targets??[];return t.jsxs("span",{ref:m,id:e,role:"group","aria-label":c(`合稱,${u.length} 條`),className:`bim-et-card bim-et-card-multi${u.length>3?" bim-et-dense":""}`,"data-sheet":l?"":void 0,style:p&&!l?{left:p}:void 0,children:[l&&d&&t.jsx(ad,{onClose:d}),t.jsxs("span",{className:"bim-et-card-k",children:[c("合稱")," · ",c(`${u.length} 條`)]}),u.map(f=>t.jsx(Pf,{target:f,kind:i.kind,loader:n,buildHref:r,onNavigate:o,newTab:a},f.id))]})},Pf=({target:e,kind:i,loader:n,buildHref:r,onNavigate:o,newTab:a})=>{const{convert:l,t:d}=oe(),[c,m]=b.useState(n?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!n)return;let u=!1;return m({status:"loading"}),sd(n.owner,n.load,e.id).then(f=>{u||m({status:"ready",summary:f})}).catch(()=>{u||m({status:"error"})}),()=>{u=!0}},[n,e.id]);const p=c.status==="ready"?c.summary:null,h=(p==null?void 0:p.title)??e.canonicalName??e.id;return t.jsxs("span",{className:"bim-et-row","data-entity-id":e.id,children:[t.jsxs("span",{className:"bim-et-row-t",children:[e.part&&t.jsx("span",{className:"bim-et-row-p",children:Of(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(h)}),t.jsx("span",{className:"bim-et-row-k",children:l(os[i])})]}),(p==null?void 0:p.meta)&&t.jsx("span",{className:"bim-et-card-m",children:l(p.meta)}),(p==null?void 0:p.description)&&t.jsx("span",{className:"bim-et-card-d bim-et-card-d2",children:l(p.description)}),c.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:l("載入中…")}),c.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:l("摘要載入失敗")}),p&&t.jsx("a",{className:"bim-et-card-a",href:r(p.id||e.id),...a?{target:"_blank",rel:"noopener"}:{},onClick:o?u=>o(p.id||e.id,u):void 0,children:d("reader.entityDetail")})]})},Of=(e,i)=>`${i(e)} →`,ad=({onClose:e})=>{const{t:i}=oe();return t.jsx("button",{type:"button",className:"bim-et-card-x","aria-label":i("reader.close"),onClick:e,children:"×"})},eo=e=>`〔图:${e}〕`,ld=(e,i)=>e&&i?i(e.file):null;function cd({fig:e,info:i,figUrl:n,block:r,failed:o,onFail:a}){const l=(i==null?void 0:i.alt)??"图形符号",d=ld(i,n);if(!d||o)return t.jsx("span",{className:"guji-fig-missing","data-fig-missing":e,children:eo(l)});const c=i.width>0&&i.height>0?`${i.width} / ${i.height}`:void 0;return i.mime==="image/svg+xml"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"guji-fig-img is-svg",role:"img","aria-label":l,"data-fig":e,style:{"--guji-fig-src":`url("${d}")`,aspectRatio:c}}),t.jsx("img",{src:d,alt:"",hidden:!0,onError:a})]}):t.jsx("img",{className:`guji-fig-img${r?" is-block":""}`,src:d,alt:r?l:"","data-fig":e,"data-raster":"1",loading:r?"lazy":void 0,decoding:"async",draggable:!1,style:c?{aspectRatio:c}:void 0,onError:a})}function Ff({id:e,fig:i,info:n,figUrl:r,cells:o,cont:a,className:l,pageStart:d,children:c}){const{t:m}=oe(),p=(n==null?void 0:n.alt)??"",h=p&&p!==m("reader.figPlain")?m("reader.figLabel",{alt:p}):m("reader.figPlain"),[u,f]=b.useState(!1),g=u||!ld(n,r);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":eo((n==null?void 0:n.alt)??"图形符号"),className:`${l} is-fig${a?" is-fig-cont":""}${g&&!a?" is-fig-missing":""}`,style:a?void 0:{"--guji-fig-n":o},title:h,"aria-label":h,role:"img",children:[t.jsx("span",{className:"guji-fig-glyph",children:c}),!a&&t.jsx(cd,{fig:i,info:n,figUrl:r,failed:u,onFail:()=>f(!0)})]})}function Bf({fig:e,info:i,figUrl:n,onClick:r}){const{t:o}=oe(),a=(i==null?void 0:i.alt)??"图形符号",l=a!==o("reader.figPlain")?o("reader.figLabel",{alt:a}):o("reader.figPlain"),[d,c]=b.useState(!1);return t.jsxs("figure",{className:"guji-fig-block","data-fig-block":e,"data-fig-copy":eo(a),title:l,onClick:r,style:r?{cursor:"pointer"}:void 0,children:[t.jsx(cd,{fig:e,info:i,figUrl:n,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const Hf=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function Df(e){const i=e.cloneContents();if(!i.querySelector("[data-fig-copy]"))return null;let n="";const r=()=>{n&&!n.endsWith(`
|
|
1545
1545
|
`)&&(n+=`
|
|
1546
|
-
`)},o=a=>{if(a.nodeType===3){n+=a.nodeValue??"";return}if(!(a.nodeType!==1&&a.nodeType!==11)){if(a.nodeType===1){const l=a;if(l.classList.contains("guji-page-divider")||l.style.userSelect==="none")return;const d=l.getAttribute("data-fig-copy");if(d!==null){l.tagName==="FIGURE"?(r(),n+=d,r()):n+=d;return}const c=Hf.has(l.tagName);c&&r(),l.childNodes.forEach(o),c&&r();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const Wf="?",Uf=e=>`/item/${encodeURIComponent(e)}`;function Kf(e){const i=e.filter(n=>n.kind==null||n.kind==="point");return{before:i.filter(n=>n.pos==="before"),after:i.filter(n=>n.pos!=="before")}}function Yf(e,i){const n=[];for(const r of e){const o=i.get(r.charData.id)??null,a=n[n.length-1];a&&a.entity===o?a.chars.push(r):n.push({entity:o,chars:[r]})}return n}const to=({pageData:e,pages:i,punctuations:n=as,selectedCharIds:r,hoveredCharId:o,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:m=!0,onVisiblePageChange:p,convert:h,scrollToPage:u,scrollToAnchor:f,onVisibleHeadingChange:g,entities:y,entityTransport:v,loadEntitySummary:w,buildEntityHref:x,onEntityNavigate:j,pageBreaks:S=!0,pageIndicatorY:$,onPageIndicatorYChange:N,quoteStyle:z,bookTitleStyle:C,showWorks:U,figures:R,figUrl:L,onFigureBlockClick:F,decorations:T})=>{var ht,We,gt;const{t:Z}=oe(),O=b.useRef(null),ae=b.useRef(0),ce=b.useMemo(()=>{const te=new Map;return m&&n.forEach((A,ne)=>{const $e=A.id?A:{...A,id:`${A.anchor}#${ne}`},Ie=te.get($e.anchor)||[];Ie.push($e),te.set($e.anchor,Ie)}),te},[n,m]),Ee=b.useMemo(()=>z===void 0&&C===void 0&&U===void 0?null:{quoteStyle:z??"original",hideBookBrackets:C==="wavy"||U===!1},[z,C,U]),we=C==="bracket",ye=b.useMemo(()=>{var Ge;const te=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],A=new Map;for(const Ae of te)for(const Ce of Ae.columns)Ce.chars.length>0&&!Ce.raised&&A.set(Ce.lead_blank||0,(A.get(Ce.lead_blank||0)||0)+1);let ne=0,$e=-1;for(const[Ae,Ce]of A)(Ce>$e||Ce===$e&&Ae<ne)&&(ne=Ae,$e=Ce);const Ie=Ae=>!!Ae.raised||(Ae.lead_blank||0)<ne,Le=te.filter(Ae=>Ae.columns.some(Ce=>Ce.chars.length>0||Ce.kind==="figure")).map(Ae=>{const Ce=[...Ae.columns].sort((it,Pt)=>it.col-Pt.col),rt=[];let st=[];const Ke=()=>{const it=ng(ce.get(st[0].charData.id));rt.push({id:`para-p${Ae.page}-${rt.length}`,chars:st,...it?{heading:{level:it.mark.length,anchor:st[0].charData.id,...it.toc===!1?{toc:!1}:{}}}:{}}),st=[]};let D=!1,ke=0,Qe;const Ye=[];for(const it of Ce){if(it.kind==="figure"&&it.fig){st.length>0?Ke():rt.length===0&&(D=!0),Ye.push({before:rt.length,fig:it.fig,...it.figBox?{box:it.figBox}:{}}),ke=0;continue}if(it.chars.length===0){it.kind==="blank"&&ke++;continue}const Pt=it.raised||it.lead_blank||ke?{raised:it.raised,leadBlank:it.lead_blank,blankBefore:ke}:void 0;ke=0,Ie(it)||(Qe=it.lead_blank||0);let dt=!0;for(const $t of it.chars){const Ot=ce.get($t.id),{before:zt,after:cr}=Ot?Kf(Ot):Xf,an=!!Ot&&Ot.some(ri=>ri.kind==="break"&&ri.pos!=="before");Ot&&Ot.some(ri=>ri.kind==="heading")&&(st.length>0?Ke():rt.length===0&&(D=!0)),st.push({charData:$t,col:it.col,beforePuncts:zt,afterPuncts:cr,...dt&&Pt?{start:Pt}:{}}),dt=!1,an&&Ke()}}const wt=st.length>0;return wt&&Ke(),{page:Ae.page,paragraphs:rt,endsOpen:wt,...Qe!==void 0?{tailLead:Qe}:{},...D?{leadStarts:D}:{},...Ae.label?{label:Ae.label}:{},...ke>0?{trailingBlank:ke}:{},...Ye.length>0?{blocks:Ye}:{}}}),at=new Map;if(!S){let Ae=null;for(const Ce of Le){const rt=Ce.paragraphs[0],st=(Ge=rt==null?void 0:rt.chars[0])==null?void 0:Ge.start,Ke=(st==null?void 0:st.leadBlank)||0,D=!!st&&!st.raised&&Ke>=ne&&Ke>((Ae==null?void 0:Ae.tailLead)??ne),ke=!!Ce.leadStarts||!!(st!=null&&st.blankBefore)||D,Qe=Ce.paragraphs.length===1&&!!Ce.trailingBlank;if(Ae&&rt&&!ke&&!Qe){for(const Ye of rt.chars)at.set(Ye.charData.id,Ae.owner);Ae.para.chars=Ae.para.chars.concat(rt.chars),Ce.leadFirstId=rt.chars[0].charData.id,Ce.paragraphs=Ce.paragraphs.slice(1),Ce.blocks&&(Ce.blocks=Ce.blocks.map(Ye=>({...Ye,before:Ye.before-1})))}if(Ce.endsOpen&&!Ce.trailingBlank){const Ye=Ce.paragraphs[Ce.paragraphs.length-1];Ye?Ae={para:Ye,owner:Ce.page,tailLead:Ce.tailLead??(Ae==null?void 0:Ae.tailLead)??ne}:Ae&&Ce.tailLead!==void 0&&(Ae.tailLead=Ce.tailLead)}else Ae=null}}const lt=new Map;for(const Ae of Le)Ae.leadFirstId&<.set(Ae.leadFirstId,Ae.page);return{pages:Le,mergedOwner:at,pageStarts:lt}},[i,e,ce,S]),Q=ye.pages,Ne=b.useRef(Q);Ne.current=Q;const W=b.useMemo(()=>Q.map(te=>te.paragraphs.reduce((A,ne)=>A+ne.chars.length,0)),[Q]),je=b.useCallback((te,A)=>{let ne=te,$e=0;for(;ne<W.length&&(ne===te||$e+W[ne]<=A);)$e+=W[ne++];return ne},[W]),K=`${Q.length}:${((gt=(We=(ht=Q[0])==null?void 0:ht.paragraphs[0])==null?void 0:We.chars[0])==null?void 0:gt.charData.id)??""}`,[V,re]=b.useState(()=>({sig:K,n:je(0,Ua)}));let J=V.n;V.sig!==K&&(J=je(0,Ua),re({sig:K,n:J})),J=Math.min(J,Q.length);const I=J>=Q.length;b.useEffect(()=>I?void 0:(A=>{const ne=window;if(ne.requestIdleCallback){const Ie=ne.requestIdleCallback(A,{timeout:300});return()=>{var Le;return(Le=ne.cancelIdleCallback)==null?void 0:Le.call(ne,Ie)}}const $e=setTimeout(A,16);return()=>clearTimeout($e)})(()=>re(A=>A.sig===K?{sig:A.sig,n:Math.max(A.n,je(A.n,Gf))}:A)),[I,J,K,je]);const ue=b.useCallback(te=>{const A=Ne.current.findIndex($e=>$e.page>=te),ne=(A<0?Ne.current.length:A)+2;re($e=>$e.n>=ne?$e:{...$e,n:ne})},[]),fe=I?Q:Q.slice(0,J);b.useEffect(()=>{let te;const A=requestAnimationFrame(()=>{te=setTimeout(()=>{const ne=O.current,$e=ne==null?void 0:ne.querySelector(".guji-reflow-paragraph");if(!ne||!$e)return;const Ie=getComputedStyle($e),Le=parseFloat(Ie.fontSize),at=$e.clientWidth;if(!(Le>0)||!(at>0))return;const lt=parseFloat(Ie.lineHeight);ne.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(at/Le)))),ne.style.setProperty("--gtv-lh",`${Math.round(lt>0?lt:Le*2)}px`)},0)});return()=>{cancelAnimationFrame(A),te&&clearTimeout(te)}},[K]);const ze=b.useMemo(()=>{const te=[];for(const A of Q)for(const ne of A.paragraphs)for(const $e of ne.chars)te.push($e.charData.id);return te},[Q]),B=b.useMemo(()=>new Map(ze.map((te,A)=>[te,A])),[ze]),pe=b.useMemo(()=>{const te=new Map;if(!y||y.length===0)return te;const A=B;for(const ne of y){if(!ne.anchor)continue;const $e=A.get(ne.anchor.start),Ie=A.get(ne.anchor.end);if(!($e===void 0||Ie===void 0||Ie<$e))for(let Le=$e;Le<=Ie;Le++)te.has(ze[Le])||te.set(ze[Le],ne)}return te},[y,ze,B]),Te=b.useMemo(()=>{const te=f==null?void 0:f.anchor;return te&&te.startsWith("e=")?new Set(te.slice(2).split(",").filter(Boolean)):null},[f==null?void 0:f.anchor]),ve=b.useMemo(()=>{var $e;if(!Te||!y)return[];const te=new Set,A=[],ne=(Ie,Le)=>{const at=`${Ie}:${Le}`;te.has(at)||(te.add(at),A.push([Ie,Le]))};for(const Ie of y){if(!Ie.anchor)continue;const Le=B.get(Ie.anchor.start),at=B.get(Ie.anchor.end);if(!(Le===void 0||at===void 0||at<Le)){(Ie.targetId&&Te.has(Ie.targetId)||($e=Ie.targets)!=null&&$e.some(lt=>Te.has(lt.id)))&&ne(Le,at);for(const lt of Ie.parts??[]){if(!Te.has(lt.id))continue;const Ge=Le+lt.offset[0],Ae=Le+lt.offset[1]-1;Ae>=Ge&&Ae<=at&&ne(Ge,Ae)}}}return A.sort((Ie,Le)=>Ie[0]-Le[0]||Ie[1]-Le[1])},[Te,y,B]),Ve=Zs(v,w),qe=pe.size>0,Xe=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F});Xe.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F};const X=b.useMemo(()=>({click:te=>{var A,ne;ae.current=Date.now()+1200,(ne=(A=Xe.current).onCharClick)==null||ne.call(A,te)},enter:te=>{var A,ne;return(ne=(A=Xe.current).onCharHover)==null?void 0:ne.call(A,te)},leave:()=>{var te,A;return(A=(te=Xe.current).onCharHover)==null?void 0:A.call(te,null)},figBlock:te=>{var A,ne;return(ne=(A=Xe.current).onFigureBlockClick)==null?void 0:ne.call(A,te)},navigate:(te,A)=>{A.ctrlKey||A.metaKey||A.shiftKey||(A.preventDefault(),A.detail===0&&window.open(A.currentTarget.href,"_blank","noopener"))}}),[]),ie=ig(r,ye.mergedOwner),me=tg(T,ye.mergedOwner),se=b.useRef(J);se.current=J;const de=b.useRef(null),ge=b.useCallback(te=>{const A=de.current,ne=A==null?void 0:A.map.get(te);if(ne&&ne.isConnected)return ne;if(A&&A.for===Ne.current&&A.n===se.current&&!ne)return null;const $e=O.current;if(!$e)return null;const Ie=new Map;return $e.querySelectorAll("span[data-char-id]").forEach(Le=>{Ie.set(Le.getAttribute("data-char-id"),Le)}),de.current={for:Ne.current,n:se.current,map:Ie},Ie.get(te)??null},[]),Oe=b.useRef(null);b.useEffect(()=>{var A;if((A=Oe.current)==null||A.classList.remove("is-hovered"),Oe.current=null,!o)return;const te=ge(o);te&&(te.classList.add("is-hovered"),Oe.current=te)},[o,ge]);const Je=b.useRef(null),Pe=te=>{var ne;const A=te instanceof Element?te.closest("span[data-char-id]"):null;return A&&((ne=O.current)!=null&&ne.contains(A))?A.getAttribute("data-char-id"):null},Ue=te=>{const A=Pe(te.target);A&&X.click(A)},nt=te=>{const A=Pe(te.target);A!==Je.current&&(Je.current=A,A?X.enter(A):X.leave())},Y=te=>{const A=typeof window<"u"?window.getSelection():null;if(!A||A.isCollapsed||A.rangeCount===0)return;const ne=Df(A.getRangeAt(0));ne!==null&&(te.clipboardData.setData("text/plain",ne),te.preventDefault())},M=()=>{Je.current!==null&&(Je.current=null,X.leave())};b.useEffect(()=>{let te=null;const A=()=>{var ke,Qe;te=null;const $e=window.getSelection(),Ie=O.current;if(!$e||$e.isCollapsed||$e.rangeCount===0||!Ie)return;const Le=$e.getRangeAt(0),at=Le.commonAncestorContainer,lt=at.nodeType===3?at.parentElement:at;if(!lt||!Ie.contains(lt))return;const Ge=Ie.querySelectorAll("span[data-char-id]"),Ae=Ye=>{let wt=Ye;for(;wt.nodeType!==3&&wt.firstChild;)wt=wt.firstChild;return wt};let Ce=0,rt=Ge.length;for(;Ce<rt;){const Ye=Ce+rt>>1;Le.comparePoint(Ae(Ge[Ye]),0)<0?Ce=Ye+1:rt=Ye}const st=Ce;for(rt=Ge.length;Ce<rt;){const Ye=Ce+rt>>1;Le.comparePoint(Ae(Ge[Ye]),0)<=0?Ce=Ye+1:rt=Ye}let Ke=Ce-1;if(Ke>=st&&Le.endOffset===0&&Le.endContainer===Ae(Ge[Ke])&&Ke--,Ke<st)return;const D=[];for(let Ye=st;Ye<=Ke;Ye++)D.push(Ge[Ye].getAttribute("data-char-id"));D.length>0&&(ae.current=Date.now()+1200,(Qe=(ke=Xe.current).onSelectionChange)==null||Qe.call(ke,D))},ne=()=>{te&&clearTimeout(te),te=setTimeout(A,120)};return document.addEventListener("selectionchange",ne),()=>{document.removeEventListener("selectionchange",ne),te&&clearTimeout(te)}},[]);const k=b.useRef(null);b.useEffect(()=>{if(r.size!==1||k.current===r)return;const te=Array.from(r)[0],A=ge(te);if(A)k.current=r,A.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ne=parseInt(te.split(":")[0],10);isNaN(ne)||ue(ne)}},[r,J,ge,ue]);const P=te=>{var $e;const A=O.current;if(!A)return null;const ne=($e=Q.find(Ie=>Ie.page===te))==null?void 0:$e.leadFirstId;return ne?A.querySelector(`span[data-char-id="${ne}"]`):A.querySelector(`[data-page-section="${te}"]`)},q=u==null?void 0:u.nonce,_=b.useRef(null);b.useEffect(()=>{if(!u||_.current===u.nonce)return;const te=P(u.page);if(!te){!I&&Q.some(A=>A.page>=u.page)&&ue(u.page);return}_.current=u.nonce,ae.current=Date.now()+800,te.scrollIntoView({behavior:"auto",block:"start"})},[q,J]);const le=b.useRef(null),H=b.useRef([]);b.useEffect(()=>{var Le,at,lt;if(!f||le.current===f.nonce||f.anchor.startsWith("e="))return;const[te,A]=f.anchor.split("~"),ne=O.current,$e=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(te)}"]`),Ie=parseInt(te.split(":")[0],10);if(!$e){if(!I&&!isNaN(Ie)&&Q.some(Ge=>Ge.page>=Ie)){ue(Ie);return}A&&!isNaN(Ie)&&(le.current=f.nonce,(Le=P(Ie))==null||Le.scrollIntoView({behavior:"auto",block:"start"}));return}le.current=f.nonce,ae.current=Date.now()+800;for(const Ge of H.current)Ge.classList.remove("guji-hl");if(H.current=[],A){const Ge=B.get(te),Ae=B.get(A);if(Ge!==void 0&&Ae!==void 0&&Ae>=Ge&&Ae-Ge<64)for(let Ce=Ge;Ce<=Ae;Ce++){const rt=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(ze[Ce])}"]`);rt&&(rt.classList.add("guji-hl"),H.current.push(rt))}Wa($e,ae)}else($e.closest(".guji-reflow-paragraph")??$e).scrollIntoView({behavior:"auto",block:"start"});isNaN(Ie)||(lt=(at=Xe.current).onVisiblePageChange)==null||lt.call(at,Ie)},[f,Q,J,I,ue,ze,B]);const[he,xe]=b.useState(null),[Re,Ze]=b.useState(!1),Me=b.useRef(null);b.useEffect(()=>{!f||!Te||Me.current===f.nonce||ve.length===0||(Me.current=f.nonce,Ze(!1),xe({k:0,nonce:Date.now()}))},[f,Te,ve]);const He=b.useRef(null);b.useEffect(()=>{var Le,at;if(!he||He.current===he.nonce)return;const te=ve[he.k];if(!te)return;const A=O.current,ne=ze[te[0]],$e=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ne)}"]`),Ie=parseInt(ne.split(":")[0],10);if(!$e){!I&&!isNaN(Ie)&&ue(Ie);return}He.current=he.nonce;for(const lt of H.current)lt.classList.remove("guji-hl");H.current=[];for(let lt=te[0];lt<=te[1];lt++){const Ge=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ze[lt])}"]`);Ge&&(Ge.classList.add("guji-hl"),H.current.push(Ge))}Wa($e,ae),isNaN(Ie)||(at=(Le=Xe.current).onVisiblePageChange)==null||at.call(Le,Ie)},[he,ve,ze,J,I,ue]);const ct=b.useMemo(()=>{if(!Te||Re||ve.length===0)return"";const te=[];for(const[A,ne]of ve)for(let $e=A;$e<=ne;$e++)te.push(`.guji-text-pane-content span[data-char-id="${Li(ze[$e])}"]`);return`${te.join(",")}{background:${s.bim("mark-soft")};border-radius:2px}`},[Te,Re,ve,ze]),Be=te=>xe(A=>{const ne=ve.length;return{k:(((A==null?void 0:A.k)??0)+te+ne)%ne,nonce:Date.now()}}),ee=()=>{Ze(!0);for(const te of H.current)te.classList.remove("guji-hl");H.current=[]},Se=!!p||!!g,et=!!p&&typeof $=="number",[tt,De]=b.useState(null),Fe=ls(tt??$??0),pt=b.useRef(null);pt.current=et?Fe:null;const bt=b.useRef(()=>{});return b.useEffect(()=>{var rt,st;if(!Se)return;const te=new Map,A=new Map;(rt=O.current)==null||rt.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ke=>{const D=Ke.getAttribute("data-page-section");D!==null?te.set(D,Ke):A.set(Ke.getAttribute("data-page-start"),Ke)});const ne=[],$e=[];for(const Ke of fe){const D=te.get(String(Ke.page));D&&(ne.push(D),$e.push(Ke.page))}if(ne.length===0)return;const Ie=new Map(ne.map((Ke,D)=>[Ke,D])),Le=ne.map(()=>[]);let at=0;(st=O.current)==null||st.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ke=>{const D=Ie.get(Ke.closest("[data-page-section]"));D!==void 0&&(Le[D].push(Ke),at++)});let lt,Ge=0;const Ae=()=>{var it,Pt;if(Ge=0,Date.now()<ae.current)return;const Ke=dt=>dt.getBoundingClientRect().top;if(ne.length>1&&Ke(ne[0])===Ke(ne[ne.length-1]))return;const D=pt.current===null?120:pt.current*window.innerHeight;let ke=0,Qe=ne.length-1;for(;ke<Qe;){const dt=ke+Qe+1>>1;Ke(ne[dt])<=D?ke=dt:Qe=dt-1}const Ye=Ke(ne[0])>D;let wt=$e[ke];for(let dt=ke+1;dt<ne.length;dt++){const $t=A.get(String($e[dt]));if(!$t||!ne[ke].contains($t)||Ke($t)>D)break;wt=$e[dt]}if(at>0&&Xe.current.onVisibleHeadingChange){let dt=null;if(!Ye){const Ot=Le[ke];for(let zt=Ot.length-1;zt>=0&&!dt;zt--)Ke(Ot[zt])<=D&&(dt=Ot[zt]);for(let zt=ke-1;zt>=0&&!dt;zt--)Le[zt].length>0&&(dt=Le[zt][Le[zt].length-1])}const $t=dt?rg(dt):null;$t!==lt&&(lt=$t,Xe.current.onVisibleHeadingChange($t))}(Pt=(it=Xe.current).onVisiblePageChange)==null||Pt.call(it,wt)},Ce=()=>{Ge||(Ge=requestAnimationFrame(Ae))};return bt.current=()=>{Ge||(Ge=requestAnimationFrame(Ae))},window.addEventListener("scroll",Ce,{passive:!0}),Ce(),()=>{window.removeEventListener("scroll",Ce),Ge&&cancelAnimationFrame(Ge),bt.current=()=>{}}},[Se,Q,J]),b.useEffect(()=>{et&&bt.current()},[et,Fe]),t.jsxs("div",{ref:O,className:"guji-text-pane-content",onClick:Ue,onMouseOver:nt,onMouseLeave:M,onCopy:Y,children:[qe&&t.jsx("style",{children:Xs}),ct&&t.jsx("style",{children:ct}),ct&&he&&t.jsxs("div",{className:"bim-rd-mnav bim-d-ui",role:"navigation","aria-label":Z("mentions.navLabel"),children:[t.jsx("span",{children:Z("mentions.navCount",{k:he.k+1,n:ve.length})}),t.jsx("button",{type:"button",onClick:()=>Be(-1),"aria-label":Z("mentions.prev"),title:Z("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>Be(1),"aria-label":Z("mentions.next"),title:Z("mentions.next"),children:"›"}),t.jsx("button",{type:"button",onClick:ee,"aria-label":Z("mentions.close"),title:Z("mentions.close"),children:"×"})]}),et&&t.jsx(dg,{y:Fe,containerRef:O,onDrag:De,onCommit:te=>{De(null),N==null||N(te)}}),t.jsx("div",{className:"guji-text-reflow-view",children:fe.map((te,A)=>t.jsx(ag,{pGroup:te,first:A===0,pageBreaks:S,markOpts:Ee,plainBooks:we,selected:ie.get(te.page)??qf,decorations:me.get(te.page),entityOfChar:pe,entityLoader:Ve,convert:h,buildHref:x??Uf,handlers:X,charCount:W[A]??0,pageStarts:ye.pageStarts,figures:R,figUrl:L},`page-sec-${te.page}`))})]})};function Wa(e,i){i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"});let n=!1;const r=()=>{n=!0},o=["wheel","touchstart","keydown","mousedown"];o.forEach(a=>window.addEventListener(a,r,{once:!0,passive:!0})),[120,350,700,1100,1500].forEach((a,l,d)=>setTimeout(()=>{if(!n&&e.isConnected){const c=e.getBoundingClientRect();(c.top<80||c.bottom>window.innerHeight-40)&&(i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"}))}l===d.length-1&&o.forEach(c=>window.removeEventListener(c,r))},a))}const Ua=1800,Gf=800,Vf="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",qf=new Set,as=[],Xf={before:as,after:as},Jf={};function Zf(e){if(!e)return Jf;const i={"data-cd":e.tone??""};return e.sub&&(i["data-cd-sub"]=e.sub),e.focus&&(i["data-cd-focus"]=""),(e.bg||e.fg)&&(i["data-cd-custom"]=""),i}function Qf(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function eg(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function tg(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;if(e&&e.size>0){const o=new Map;e.forEach((a,l)=>{const d=i.get(l)??parseInt(l.split(":")[0],10);let c=o.get(d);c||o.set(d,c=new Map),c.set(l,a)}),o.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(([m,p])=>{const h=d.get(m);return!!h&&Ih(h,p)});r.set(l,c?d:a)})}return n.current=r,r},[e,i])}function ig(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;e.forEach(a=>{const l=i.get(a)??parseInt(a.split(":")[0],10);let d=r.get(l);d||r.set(l,d=new Set),d.add(a)});const o=new Map;return r.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(m=>d.has(m));o.set(l,c?d:a)}),n.current=o,o},[e,i])}function ng(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function rg(e){return e.getAttribute("data-heading-anchor")}function Li(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Ka({n:e}){return t.jsx(t.Fragment,{children:Array.from({length:e},(i,n)=>t.jsx("span",{className:"guji-text-blank-col","aria-hidden":"true","data-blank-col":""},n))})}function sg(e,i){const n=Array.from(i(e.join("")));return n.length===e.length&&e.every(r=>Array.from(r).length===1)?n:e.map(r=>i(r))}function og({heading:e,children:i}){if(!e)return t.jsx("p",{className:"guji-reflow-paragraph",children:i});const n=`h${Math.min(6,e.level+1)}`;return t.jsx(n,{className:`guji-reflow-paragraph guji-reflow-heading guji-reflow-h${e.level}`,"data-heading-anchor":e.anchor,"data-heading-level":e.level,"data-heading-toc":e.toc===!1?"0":void 0,children:i})}const ag=b.memo(function({pGroup:i,first:n,pageBreaks:r,markOpts:o,plainBooks:a,selected:l,decorations:d,entityOfChar:c,entityLoader:m,convert:p,buildHref:h,handlers:u,charCount:f,pageStarts:g,figures:y,figUrl:v}){const w=b.useMemo(()=>{const N=new Map;if(!p)return N;for(const z of i.paragraphs){const C=sg(z.chars.map(U=>U.charData.fig?U.charData.char:U.charData.norm??U.charData.char),p);z.chars.forEach((U,R)=>N.set(U.charData.id,U.charData.fig?U.charData.char:C[R]))}return N},[i,p]),x=N=>N.unk?Wf:w.get(N.id)??N.char,{t:j}=oe(),S=N=>{const z=o?Kc(N.mark,o):N.mark;return z?t.jsx("span",{className:"guji-text-punct","data-punct-id":N.id,children:z},N.id):null},$=N=>{var z;return(z=i.blocks)==null?void 0:z.map((C,U)=>C.before===N&&t.jsx(Bf,{fig:C.fig,info:y==null?void 0:y.get(C.fig),figUrl:v,onClick:()=>u.figBlock({page:i.page,fig:C.fig,...C.box?{box:C.box}:{}})},`fig-${C.fig}-${U}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:Vf,"--gtv-pc":f,"--gtv-pp":i.paragraphs.length},children:[!n&&r&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:s.bim("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},"data-page-label":i.label,title:i.label?`${i.page}`:void 0,children:["第 ",i.label??i.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}})]}),i.paragraphs.map((N,z)=>t.jsxs(b.Fragment,{children:[$(z),t.jsxs(og,{heading:N.heading,children:[Yf(N.chars,c).map((C,U)=>{const R=C.chars.map(({charData:T,beforePuncts:Z,afterPuncts:O,start:ae},ce)=>{var K,V,re;const Ee=!!C.entity&&ce===0,we=!!C.entity&&ce===C.chars.length-1,ye=Ee?[]:Z,Q=we?[]:O,Ne=!!T.fig&&ce>0&&C.chars[ce-1].charData.fig===T.fig;let W=1;if(T.fig&&!Ne)for(;((K=C.chars[ce+W])==null?void 0:K.charData.fig)===T.fig;)W++;const je=`guji-text-char${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${ae!=null&&ae.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[ae&&ae.blankBefore>0&&t.jsx(Ka,{n:ae.blankBefore}),ye.map(S),T.fig?t.jsx(Ff,{id:T.id,fig:T.fig,info:y==null?void 0:y.get(T.fig),figUrl:v,cells:W,cont:Ne,className:je,pageStart:g.get(T.id),children:x(T)}):t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-char-id":T.id,"data-page-start":g.get(T.id),...Zf(d==null?void 0:d.get(T.id)),style:Qf(d==null?void 0:d.get(T.id)),className:`guji-text-char${eg(d==null?void 0:d.get(T.id))}${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${T.lacuna||T.pending&&T.char==="□"?" is-lacuna":""}${T.unk?" is-unk":""}${T.pending?" is-pending":""}${T.lacuna&&T.guess_c?" has-guess":""}${T.guess?" is-guess":""}${T.zi?" is-zi":""}${ae!=null&&ae.raised?" is-raised":""}`,"data-raised":(ae==null?void 0:ae.raised)||void 0,"data-guji-guess":T.lacuna&&T.guess_c?T.guess_c:void 0,title:((V=d==null?void 0:d.get(T.id))==null?void 0:V.title)??(T.unk?j("reader.unkChar",{label:p?p(T.unk):T.unk}):T.pending?j("reader.pendingReason",{label:p?p(_e.pendingReasonLabel(T.pending)):_e.pendingReasonLabel(T.pending)}):T.lacuna?T.guess_c?j("reader.lacunaGuess",{guess:p?p(T.guess_c):T.guess_c}):j("detail.lacuna"):T.zi?j("detail.composedChar",{label:T.zi}):T.guess?j("reader.charGuess"):void 0),children:x(T)}),((re=d==null?void 0:d.get(T.id))==null?void 0:re.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(T.id).insertAfter})]}),Q.map(S)]},T.id)});if(!C.entity)return t.jsx(b.Fragment,{children:R},`r${U}`);const L=C.chars[0].beforePuncts.map(S),F=C.chars[C.chars.length-1].afterPuncts.map(S);return t.jsxs(b.Fragment,{children:[L,t.jsx(Qs,{span:C.entity,label:C.chars.map(T=>x(T.charData)).join(""),hasBrackets:!0,plain:a&&C.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>R,hoverDelayMs:250}),F]},`${C.entity.key}@${U}`)}),z===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Ka,{n:i.trailingBlank}):null]})]},N.id)),$(i.paragraphs.length)]})});function ls(e){const[i,n]=Vi,r=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,r))*1e3)/1e3}const lg=.02,xi=16,cg=4;function dg({y:e,containerRef:i,onDrag:n,onCommit:r}){const{t:o}=oe(),[a,l]=b.useState(0),d=b.useRef(!1),c=b.useRef(null),m=b.useRef(e);m.current=e;const p=b.useCallback(()=>{var y;const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=f==null?void 0:f.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-xi-cg))},[i]);b.useLayoutEffect(()=>{var y;window.addEventListener("resize",p);const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=typeof ResizeObserver<"u"?new ResizeObserver(()=>p()):null;for(const v of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])v&&(g==null||g.observe(v));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>ls(u/Math.max(1,window.innerHeight));return t.jsx("div",{ref:c,role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":o("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Vi[0]*100),"aria-valuemax":Math.round(Vi[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${xi/2}px)`,width:xi,height:xi,zIndex:20,cursor:"ns-resize",touchAction:"none",display:"flex",alignItems:"center",justifyContent:"center",color:s.bim("meta-fg")},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const f=h(u.clientY);m.current=f,n(f)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}r(h(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,r(m.current))},onKeyDown:u=>{const f=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;f&&(u.preventDefault(),r(ls(e+f*(u.shiftKey?5:1)*lg)))},children:t.jsx("svg",{width:xi,height:xi,viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2 8h11M9 4l4 4-4 4"})})})}const dd=1,md=6,vn={s:1,x:0,y:0},En=(e,i,n)=>Math.min(n,Math.max(i,e));function io(e,i,n){const r=En(e.s,dd,md);return{s:r,x:En(e.x,i*(1-r),0),y:En(e.y,n*(1-r),0)}}function Or(e,i,n,r,o,a){const l=En(e.s*r,dd,md),d=l/e.s;return io({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function mg(e,i,n,r,o){return io({s:e.s,x:e.x+i,y:e.y+n},r,o)}function ug(e,i,n){const r=i===1?e*16:i===2?e*400:e;return Math.exp(-r*(n?.01:.0015))}const Ya=4,pg=b.forwardRef(function({children:i,onScaleChange:n,resetKey:r,style:o},a){const l=b.useRef(null),[d,c]=b.useState(vn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var S;const j=m.current;m.current=x,c(x),x.s!==j.s&&((S=p.current)==null||S.call(p,x.s))},u=()=>{var j;const x=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(x==null?void 0:x.width)??0,h:(x==null?void 0:x.height)??0,left:(x==null?void 0:x.left)??0,top:(x==null?void 0:x.top)??0}};b.useImperativeHandle(a,()=>({zoomBy(x){const{w:j,h:S}=u();h(Or(m.current,j/2,S/2,x,j,S))},reset(){h(vn)}})),b.useEffect(()=>{h(vn)},[r]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:S,h:$}=u(),N=io(m.current,S,$);(N.x!==m.current.x||N.y!==m.current.y)&&h(N)});return j.observe(x),()=>j.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const j=S=>{const $=ug(S.deltaY,S.deltaMode,S.ctrlKey);if(m.current.s<=1&&$<1)return;S.preventDefault();const{w:N,h:z,left:C,top:U}=u();h(Or(m.current,S.clientX-C,S.clientY-U,$,N,z))};return x.addEventListener("wheel",j,{passive:!1}),()=>x.removeEventListener("wheel",j)},[]);const f=b.useRef(new Map),g=b.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),y=x=>{if(x.pointerType==="mouse"&&x.button!==0)return;f.current.set(x.pointerId,{x:x.clientX,y:x.clientY});const j=g.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[S,$]=[...f.current.values()];j.pinchDist=Math.hypot(S.x-$.x,S.y-$.y),j.moved=Ya+1}},v=x=>{var F;const j=f.current.get(x.pointerId);if(!j)return;const S={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,S);const $=g.current,{w:N,h:z,left:C,top:U}=u();if(f.current.size>=2){const[T,Z]=[...f.current.values()],O=Math.hypot(T.x-Z.x,T.y-Z.y);if($.pinchDist>0&&O>0){const ae=(T.x+Z.x)/2-C,ce=(T.y+Z.y)/2-U;h(Or(m.current,ae,ce,O/$.pinchDist,N,z))}$.pinchDist=O,$.swallowClick=!0;return}const R=S.x-j.x,L=S.y-j.y;if($.moved+=Math.abs(R)+Math.abs(L),!($.moved<=Ya)){if(!$.dragging){$.dragging=!0;try{(F=l.current)==null||F.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(mg(m.current,R,L,N,z))}},w=x=>{f.current.delete(x.pointerId);const j=g.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:v,onPointerUp:w,onPointerCancel:w,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(vn),style:{position:"relative",overflow:"hidden",touchAction:"none",cursor:d.s>1?"grab":void 0,...o},children:t.jsx("div",{className:"bim-zp-inner",style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",transformOrigin:"0 0",transform:`translate(${d.x}px, ${d.y}px) scale(${d.s})`,willChange:d.s>1?"transform":void 0},children:i})})});function ud(e,i,n,r,o=""){const a=`${o}
|
|
1546
|
+
`)},o=a=>{if(a.nodeType===3){n+=a.nodeValue??"";return}if(!(a.nodeType!==1&&a.nodeType!==11)){if(a.nodeType===1){const l=a;if(l.classList.contains("guji-page-divider")||l.style.userSelect==="none")return;const d=l.getAttribute("data-fig-copy");if(d!==null){l.tagName==="FIGURE"?(r(),n+=d,r()):n+=d;return}const c=Hf.has(l.tagName);c&&r(),l.childNodes.forEach(o),c&&r();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const Wf="?",Uf=e=>`/item/${encodeURIComponent(e)}`;function Kf(e){const i=e.filter(n=>n.kind==null||n.kind==="point");return{before:i.filter(n=>n.pos==="before"),after:i.filter(n=>n.pos!=="before")}}function Yf(e,i){const n=[];for(const r of e){const o=i.get(r.charData.id)??null,a=n[n.length-1];a&&a.entity===o?a.chars.push(r):n.push({entity:o,chars:[r]})}return n}const to=({pageData:e,pages:i,punctuations:n=as,selectedCharIds:r,hoveredCharId:o,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:m=!0,onVisiblePageChange:p,convert:h,scrollToPage:u,scrollToAnchor:f,onVisibleHeadingChange:g,entities:y,entityTransport:v,loadEntitySummary:w,buildEntityHref:x,onEntityNavigate:j,pageBreaks:S=!0,pageIndicatorY:$,onPageIndicatorYChange:N,quoteStyle:z,bookTitleStyle:C,showWorks:U,figures:R,figUrl:L,onFigureBlockClick:F,decorations:T})=>{var ht,We,gt;const{t:Z}=oe(),O=b.useRef(null),ae=b.useRef(0),ce=b.useMemo(()=>{const te=new Map;return m&&n.forEach((A,ne)=>{const $e=A.id?A:{...A,id:`${A.anchor}#${ne}`},Ie=te.get($e.anchor)||[];Ie.push($e),te.set($e.anchor,Ie)}),te},[n,m]),Ee=b.useMemo(()=>z===void 0&&C===void 0&&U===void 0?null:{quoteStyle:z??"original",hideBookBrackets:C==="wavy"||U===!1},[z,C,U]),we=C==="bracket",ye=b.useMemo(()=>{var Ke;const te=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],A=new Map;for(const Ae of te)for(const Ce of Ae.columns)Ce.chars.length>0&&!Ce.raised&&A.set(Ce.lead_blank||0,(A.get(Ce.lead_blank||0)||0)+1);let ne=0,$e=-1;for(const[Ae,Ce]of A)(Ce>$e||Ce===$e&&Ae<ne)&&(ne=Ae,$e=Ce);const Ie=Ae=>!!Ae.raised||(Ae.lead_blank||0)<ne,Le=te.filter(Ae=>Ae.columns.some(Ce=>Ce.chars.length>0||Ce.kind==="figure")).map(Ae=>{const Ce=[...Ae.columns].sort((it,Pt)=>it.col-Pt.col),rt=[];let st=[];const Ye=()=>{const it=rg(ce.get(st[0].charData.id));rt.push({id:`para-p${Ae.page}-${rt.length}`,chars:st,...it?{heading:{level:it.mark.length,anchor:st[0].charData.id,...it.toc===!1?{toc:!1}:{}}}:{}}),st=[]};let D=!1,ke=0,Qe;const Ge=[];for(const it of Ce){if(it.kind==="figure"&&it.fig){st.length>0?Ye():rt.length===0&&(D=!0),Ge.push({before:rt.length,fig:it.fig,...it.figBox?{box:it.figBox}:{}}),ke=0;continue}if(it.chars.length===0){it.kind==="blank"&&ke++;continue}const Pt=it.raised||it.lead_blank||ke?{raised:it.raised,leadBlank:it.lead_blank,blankBefore:ke}:void 0;ke=0,Ie(it)||(Qe=it.lead_blank||0);let dt=!0;for(const $t of it.chars){const Ot=ce.get($t.id),{before:zt,after:cr}=Ot?Kf(Ot):Jf,an=!!Ot&&Ot.some(ri=>ri.kind==="break"&&ri.pos!=="before");Ot&&Ot.some(ri=>ri.kind==="heading")&&(st.length>0?Ye():rt.length===0&&(D=!0)),st.push({charData:$t,col:it.col,beforePuncts:zt,afterPuncts:cr,...dt&&Pt?{start:Pt}:{}}),dt=!1,an&&Ye()}}const wt=st.length>0;return wt&&Ye(),{page:Ae.page,paragraphs:rt,endsOpen:wt,...Qe!==void 0?{tailLead:Qe}:{},...D?{leadStarts:D}:{},...Ae.label?{label:Ae.label}:{},...ke>0?{trailingBlank:ke}:{},...Ge.length>0?{blocks:Ge}:{}}}),at=new Map;if(!S){let Ae=null;for(const Ce of Le){const rt=Ce.paragraphs[0],st=(Ke=rt==null?void 0:rt.chars[0])==null?void 0:Ke.start,Ye=(st==null?void 0:st.leadBlank)||0,D=!!st&&!st.raised&&Ye>=ne&&Ye>((Ae==null?void 0:Ae.tailLead)??ne),ke=!!Ce.leadStarts||!!(st!=null&&st.blankBefore)||D,Qe=Ce.paragraphs.length===1&&!!Ce.trailingBlank;if(Ae&&rt&&!ke&&!Qe){for(const Ge of rt.chars)at.set(Ge.charData.id,Ae.owner);Ae.para.chars=Ae.para.chars.concat(rt.chars),Ce.leadFirstId=rt.chars[0].charData.id,Ce.paragraphs=Ce.paragraphs.slice(1),Ce.blocks&&(Ce.blocks=Ce.blocks.map(Ge=>({...Ge,before:Ge.before-1})))}if(Ce.endsOpen&&!Ce.trailingBlank){const Ge=Ce.paragraphs[Ce.paragraphs.length-1];Ge?Ae={para:Ge,owner:Ce.page,tailLead:Ce.tailLead??(Ae==null?void 0:Ae.tailLead)??ne}:Ae&&Ce.tailLead!==void 0&&(Ae.tailLead=Ce.tailLead)}else Ae=null}}const lt=new Map;for(const Ae of Le)Ae.leadFirstId&<.set(Ae.leadFirstId,Ae.page);return{pages:Le,mergedOwner:at,pageStarts:lt}},[i,e,ce,S]),Q=ye.pages,Ne=b.useRef(Q);Ne.current=Q;const W=b.useMemo(()=>Q.map(te=>te.paragraphs.reduce((A,ne)=>A+ne.chars.length,0)),[Q]),je=b.useCallback((te,A)=>{let ne=te,$e=0;for(;ne<W.length&&(ne===te||$e+W[ne]<=A);)$e+=W[ne++];return ne},[W]),K=`${Q.length}:${((gt=(We=(ht=Q[0])==null?void 0:ht.paragraphs[0])==null?void 0:We.chars[0])==null?void 0:gt.charData.id)??""}`,[V,re]=b.useState(()=>({sig:K,n:je(0,Ua)}));let J=V.n;V.sig!==K&&(J=je(0,Ua),re({sig:K,n:J})),J=Math.min(J,Q.length);const I=J>=Q.length;b.useEffect(()=>I?void 0:(A=>{const ne=window;if(ne.requestIdleCallback){const Ie=ne.requestIdleCallback(A,{timeout:300});return()=>{var Le;return(Le=ne.cancelIdleCallback)==null?void 0:Le.call(ne,Ie)}}const $e=setTimeout(A,16);return()=>clearTimeout($e)})(()=>re(A=>A.sig===K?{sig:A.sig,n:Math.max(A.n,je(A.n,Vf))}:A)),[I,J,K,je]);const ue=b.useCallback(te=>{const A=Ne.current.findIndex($e=>$e.page>=te),ne=(A<0?Ne.current.length:A)+2;re($e=>$e.n>=ne?$e:{...$e,n:ne})},[]),fe=I?Q:Q.slice(0,J);b.useEffect(()=>{let te;const A=requestAnimationFrame(()=>{te=setTimeout(()=>{const ne=O.current,$e=ne==null?void 0:ne.querySelector(".guji-reflow-paragraph");if(!ne||!$e)return;const Ie=getComputedStyle($e),Le=parseFloat(Ie.fontSize),at=$e.clientWidth;if(!(Le>0)||!(at>0))return;const lt=parseFloat(Ie.lineHeight);ne.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(at/Le)))),ne.style.setProperty("--gtv-lh",`${Math.round(lt>0?lt:Le*2)}px`)},0)});return()=>{cancelAnimationFrame(A),te&&clearTimeout(te)}},[K]);const ze=b.useMemo(()=>{const te=[];for(const A of Q)for(const ne of A.paragraphs)for(const $e of ne.chars)te.push($e.charData.id);return te},[Q]),B=b.useMemo(()=>new Map(ze.map((te,A)=>[te,A])),[ze]),pe=b.useMemo(()=>{const te=new Map;if(!y||y.length===0)return te;const A=B;for(const ne of y){if(!ne.anchor)continue;const $e=A.get(ne.anchor.start),Ie=A.get(ne.anchor.end);if(!($e===void 0||Ie===void 0||Ie<$e))for(let Le=$e;Le<=Ie;Le++)te.has(ze[Le])||te.set(ze[Le],ne)}return te},[y,ze,B]),Te=b.useMemo(()=>{const te=f==null?void 0:f.anchor;return te&&te.startsWith("e=")?new Set(te.slice(2).split(",").filter(Boolean)):null},[f==null?void 0:f.anchor]),ve=b.useMemo(()=>{var $e;if(!Te||!y)return[];const te=new Set,A=[],ne=(Ie,Le)=>{const at=`${Ie}:${Le}`;te.has(at)||(te.add(at),A.push([Ie,Le]))};for(const Ie of y){if(!Ie.anchor)continue;const Le=B.get(Ie.anchor.start),at=B.get(Ie.anchor.end);if(!(Le===void 0||at===void 0||at<Le)){(Ie.targetId&&Te.has(Ie.targetId)||($e=Ie.targets)!=null&&$e.some(lt=>Te.has(lt.id)))&&ne(Le,at);for(const lt of Ie.parts??[]){if(!Te.has(lt.id))continue;const Ke=Le+lt.offset[0],Ae=Le+lt.offset[1]-1;Ae>=Ke&&Ae<=at&&ne(Ke,Ae)}}}return A.sort((Ie,Le)=>Ie[0]-Le[0]||Ie[1]-Le[1])},[Te,y,B]),Ve=Zs(v,w),qe=pe.size>0,Xe=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F});Xe.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F};const X=b.useMemo(()=>({click:te=>{var A,ne;ae.current=Date.now()+1200,(ne=(A=Xe.current).onCharClick)==null||ne.call(A,te)},enter:te=>{var A,ne;return(ne=(A=Xe.current).onCharHover)==null?void 0:ne.call(A,te)},leave:()=>{var te,A;return(A=(te=Xe.current).onCharHover)==null?void 0:A.call(te,null)},figBlock:te=>{var A,ne;return(ne=(A=Xe.current).onFigureBlockClick)==null?void 0:ne.call(A,te)},navigate:(te,A)=>{A.ctrlKey||A.metaKey||A.shiftKey||(A.preventDefault(),A.detail===0&&window.open(A.currentTarget.href,"_blank","noopener"))}}),[]),ie=ng(r,ye.mergedOwner),me=ig(T,ye.mergedOwner),se=b.useRef(J);se.current=J;const de=b.useRef(null),ge=b.useCallback(te=>{const A=de.current,ne=A==null?void 0:A.map.get(te);if(ne&&ne.isConnected)return ne;if(A&&A.for===Ne.current&&A.n===se.current&&!ne)return null;const $e=O.current;if(!$e)return null;const Ie=new Map;return $e.querySelectorAll("span[data-char-id]").forEach(Le=>{Ie.set(Le.getAttribute("data-char-id"),Le)}),de.current={for:Ne.current,n:se.current,map:Ie},Ie.get(te)??null},[]),Oe=b.useRef(null);b.useEffect(()=>{var A;if((A=Oe.current)==null||A.classList.remove("is-hovered"),Oe.current=null,!o)return;const te=ge(o);te&&(te.classList.add("is-hovered"),Oe.current=te)},[o,ge]);const Je=b.useRef(null),Pe=te=>{var ne;const A=te instanceof Element?te.closest("span[data-char-id]"):null;return A&&((ne=O.current)!=null&&ne.contains(A))?A.getAttribute("data-char-id"):null},Ue=te=>{const A=Pe(te.target);A&&X.click(A)},nt=te=>{const A=Pe(te.target);A!==Je.current&&(Je.current=A,A?X.enter(A):X.leave())},Y=te=>{const A=typeof window<"u"?window.getSelection():null;if(!A||A.isCollapsed||A.rangeCount===0)return;const ne=Df(A.getRangeAt(0));ne!==null&&(te.clipboardData.setData("text/plain",ne),te.preventDefault())},M=()=>{Je.current!==null&&(Je.current=null,X.leave())};b.useEffect(()=>{let te=null;const A=()=>{var ke,Qe;te=null;const $e=window.getSelection(),Ie=O.current;if(!$e||$e.isCollapsed||$e.rangeCount===0||!Ie)return;const Le=$e.getRangeAt(0),at=Le.commonAncestorContainer,lt=at.nodeType===3?at.parentElement:at;if(!lt||!Ie.contains(lt))return;const Ke=Ie.querySelectorAll("span[data-char-id]"),Ae=Ge=>{let wt=Ge;for(;wt.nodeType!==3&&wt.firstChild;)wt=wt.firstChild;return wt};let Ce=0,rt=Ke.length;for(;Ce<rt;){const Ge=Ce+rt>>1;Le.comparePoint(Ae(Ke[Ge]),0)<0?Ce=Ge+1:rt=Ge}const st=Ce;for(rt=Ke.length;Ce<rt;){const Ge=Ce+rt>>1;Le.comparePoint(Ae(Ke[Ge]),0)<=0?Ce=Ge+1:rt=Ge}let Ye=Ce-1;if(Ye>=st&&Le.endOffset===0&&Le.endContainer===Ae(Ke[Ye])&&Ye--,Ye<st)return;const D=[];for(let Ge=st;Ge<=Ye;Ge++)D.push(Ke[Ge].getAttribute("data-char-id"));D.length>0&&(ae.current=Date.now()+1200,(Qe=(ke=Xe.current).onSelectionChange)==null||Qe.call(ke,D))},ne=()=>{te&&clearTimeout(te),te=setTimeout(A,120)};return document.addEventListener("selectionchange",ne),()=>{document.removeEventListener("selectionchange",ne),te&&clearTimeout(te)}},[]);const k=b.useRef(null);b.useEffect(()=>{if(r.size!==1||k.current===r)return;const te=Array.from(r)[0],A=ge(te);if(A)k.current=r,A.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ne=parseInt(te.split(":")[0],10);isNaN(ne)||ue(ne)}},[r,J,ge,ue]);const P=te=>{var $e;const A=O.current;if(!A)return null;const ne=($e=Q.find(Ie=>Ie.page===te))==null?void 0:$e.leadFirstId;return ne?A.querySelector(`span[data-char-id="${ne}"]`):A.querySelector(`[data-page-section="${te}"]`)},q=u==null?void 0:u.nonce,_=b.useRef(null);b.useEffect(()=>{if(!u||_.current===u.nonce)return;const te=P(u.page);if(!te){!I&&Q.some(A=>A.page>=u.page)&&ue(u.page);return}_.current=u.nonce,ae.current=Date.now()+800,te.scrollIntoView({behavior:"auto",block:"start"})},[q,J]);const le=b.useRef(null),H=b.useRef([]);b.useEffect(()=>{var Le,at,lt;if(!f||le.current===f.nonce||f.anchor.startsWith("e="))return;const[te,A]=f.anchor.split("~"),ne=O.current,$e=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(te)}"]`),Ie=parseInt(te.split(":")[0],10);if(!$e){if(!I&&!isNaN(Ie)&&Q.some(Ke=>Ke.page>=Ie)){ue(Ie);return}A&&!isNaN(Ie)&&(le.current=f.nonce,(Le=P(Ie))==null||Le.scrollIntoView({behavior:"auto",block:"start"}));return}le.current=f.nonce,ae.current=Date.now()+800;for(const Ke of H.current)Ke.classList.remove("guji-hl");if(H.current=[],A){const Ke=B.get(te),Ae=B.get(A);if(Ke!==void 0&&Ae!==void 0&&Ae>=Ke&&Ae-Ke<64)for(let Ce=Ke;Ce<=Ae;Ce++){const rt=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(ze[Ce])}"]`);rt&&(rt.classList.add("guji-hl"),H.current.push(rt))}Wa($e,ae)}else{const Ke=$e.closest(".guji-reflow-paragraph")??$e;Gf(Ke,ae)}isNaN(Ie)||(lt=(at=Xe.current).onVisiblePageChange)==null||lt.call(at,Ie)},[f,Q,J,I,ue,ze,B]);const[he,xe]=b.useState(null),[Re,Ze]=b.useState(!1),Me=b.useRef(null);b.useEffect(()=>{!f||!Te||Me.current===f.nonce||ve.length===0||(Me.current=f.nonce,Ze(!1),xe({k:0,nonce:Date.now()}))},[f,Te,ve]);const He=b.useRef(null);b.useEffect(()=>{var Le,at;if(!he||He.current===he.nonce)return;const te=ve[he.k];if(!te)return;const A=O.current,ne=ze[te[0]],$e=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ne)}"]`),Ie=parseInt(ne.split(":")[0],10);if(!$e){!I&&!isNaN(Ie)&&ue(Ie);return}He.current=he.nonce;for(const lt of H.current)lt.classList.remove("guji-hl");H.current=[];for(let lt=te[0];lt<=te[1];lt++){const Ke=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ze[lt])}"]`);Ke&&(Ke.classList.add("guji-hl"),H.current.push(Ke))}Wa($e,ae),isNaN(Ie)||(at=(Le=Xe.current).onVisiblePageChange)==null||at.call(Le,Ie)},[he,ve,ze,J,I,ue]);const ct=b.useMemo(()=>{if(!Te||Re||ve.length===0)return"";const te=[];for(const[A,ne]of ve)for(let $e=A;$e<=ne;$e++)te.push(`.guji-text-pane-content span[data-char-id="${Li(ze[$e])}"]`);return`${te.join(",")}{background:${s.bim("mark-soft")};border-radius:2px}`},[Te,Re,ve,ze]),Be=te=>xe(A=>{const ne=ve.length;return{k:(((A==null?void 0:A.k)??0)+te+ne)%ne,nonce:Date.now()}}),ee=()=>{Ze(!0);for(const te of H.current)te.classList.remove("guji-hl");H.current=[]},Se=!!p||!!g,et=!!p&&typeof $=="number",[tt,De]=b.useState(null),Fe=ls(tt??$??0),pt=b.useRef(null);pt.current=et?Fe:null;const bt=b.useRef(()=>{});return b.useEffect(()=>{var rt,st;if(!Se)return;const te=new Map,A=new Map;(rt=O.current)==null||rt.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ye=>{const D=Ye.getAttribute("data-page-section");D!==null?te.set(D,Ye):A.set(Ye.getAttribute("data-page-start"),Ye)});const ne=[],$e=[];for(const Ye of fe){const D=te.get(String(Ye.page));D&&(ne.push(D),$e.push(Ye.page))}if(ne.length===0)return;const Ie=new Map(ne.map((Ye,D)=>[Ye,D])),Le=ne.map(()=>[]);let at=0;(st=O.current)==null||st.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ye=>{const D=Ie.get(Ye.closest("[data-page-section]"));D!==void 0&&(Le[D].push(Ye),at++)});let lt,Ke=0;const Ae=()=>{var it,Pt;if(Ke=0,Date.now()<ae.current)return;const Ye=dt=>dt.getBoundingClientRect().top;if(ne.length>1&&Ye(ne[0])===Ye(ne[ne.length-1]))return;const D=pt.current===null?120:pt.current*window.innerHeight;let ke=0,Qe=ne.length-1;for(;ke<Qe;){const dt=ke+Qe+1>>1;Ye(ne[dt])<=D?ke=dt:Qe=dt-1}const Ge=Ye(ne[0])>D;let wt=$e[ke];for(let dt=ke+1;dt<ne.length;dt++){const $t=A.get(String($e[dt]));if(!$t||!ne[ke].contains($t)||Ye($t)>D)break;wt=$e[dt]}if(at>0&&Xe.current.onVisibleHeadingChange){let dt=null;if(!Ge){const Ot=Le[ke];for(let zt=Ot.length-1;zt>=0&&!dt;zt--)Ye(Ot[zt])<=D&&(dt=Ot[zt]);for(let zt=ke-1;zt>=0&&!dt;zt--)Le[zt].length>0&&(dt=Le[zt][Le[zt].length-1])}const $t=dt?sg(dt):null;$t!==lt&&(lt=$t,Xe.current.onVisibleHeadingChange($t))}(Pt=(it=Xe.current).onVisiblePageChange)==null||Pt.call(it,wt)},Ce=()=>{Ke||(Ke=requestAnimationFrame(Ae))};return bt.current=()=>{Ke||(Ke=requestAnimationFrame(Ae))},window.addEventListener("scroll",Ce,{passive:!0}),Ce(),()=>{window.removeEventListener("scroll",Ce),Ke&&cancelAnimationFrame(Ke),bt.current=()=>{}}},[Se,Q,J]),b.useEffect(()=>{et&&bt.current()},[et,Fe]),t.jsxs("div",{ref:O,className:"guji-text-pane-content",onClick:Ue,onMouseOver:nt,onMouseLeave:M,onCopy:Y,children:[qe&&t.jsx("style",{children:Xs}),ct&&t.jsx("style",{children:ct}),ct&&he&&t.jsxs("div",{className:"bim-rd-mnav bim-d-ui",role:"navigation","aria-label":Z("mentions.navLabel"),children:[t.jsx("span",{children:Z("mentions.navCount",{k:he.k+1,n:ve.length})}),t.jsx("button",{type:"button",onClick:()=>Be(-1),"aria-label":Z("mentions.prev"),title:Z("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>Be(1),"aria-label":Z("mentions.next"),title:Z("mentions.next"),children:"›"}),t.jsx("button",{type:"button",onClick:ee,"aria-label":Z("mentions.close"),title:Z("mentions.close"),children:"×"})]}),et&&t.jsx(mg,{y:Fe,containerRef:O,onDrag:De,onCommit:te=>{De(null),N==null||N(te)}}),t.jsx("div",{className:"guji-text-reflow-view",children:fe.map((te,A)=>t.jsx(lg,{pGroup:te,first:A===0,pageBreaks:S,markOpts:Ee,plainBooks:we,selected:ie.get(te.page)??Xf,decorations:me.get(te.page),entityOfChar:pe,entityLoader:Ve,convert:h,buildHref:x??Uf,handlers:X,charCount:W[A]??0,pageStarts:ye.pageStarts,figures:R,figUrl:L},`page-sec-${te.page}`))})]})};function Wa(e,i){i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"});let n=!1;const r=()=>{n=!0},o=["wheel","touchstart","keydown","mousedown"];o.forEach(a=>window.addEventListener(a,r,{once:!0,passive:!0})),[120,350,700,1100,1500].forEach((a,l,d)=>setTimeout(()=>{if(!n&&e.isConnected){const c=e.getBoundingClientRect();(c.top<80||c.bottom>window.innerHeight-40)&&(i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"}))}l===d.length-1&&o.forEach(c=>window.removeEventListener(c,r))},a))}function Gf(e,i){i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"start"});const n=e.getBoundingClientRect().top;let r=!1;const o=()=>{r=!0},a=["wheel","touchstart","keydown","mousedown"];a.forEach(l=>window.addEventListener(l,o,{once:!0,passive:!0})),[120,350,700,1100,1500].forEach((l,d,c)=>setTimeout(()=>{!r&&e.isConnected&&Math.abs(e.getBoundingClientRect().top-n)>4&&(i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"start"})),d===c.length-1&&a.forEach(m=>window.removeEventListener(m,o))},l))}const Ua=1800,Vf=800,qf="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",Xf=new Set,as=[],Jf={before:as,after:as},Zf={};function Qf(e){if(!e)return Zf;const i={"data-cd":e.tone??""};return e.sub&&(i["data-cd-sub"]=e.sub),e.focus&&(i["data-cd-focus"]=""),(e.bg||e.fg)&&(i["data-cd-custom"]=""),i}function eg(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function tg(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function ig(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;if(e&&e.size>0){const o=new Map;e.forEach((a,l)=>{const d=i.get(l)??parseInt(l.split(":")[0],10);let c=o.get(d);c||o.set(d,c=new Map),c.set(l,a)}),o.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(([m,p])=>{const h=d.get(m);return!!h&&Ih(h,p)});r.set(l,c?d:a)})}return n.current=r,r},[e,i])}function ng(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;e.forEach(a=>{const l=i.get(a)??parseInt(a.split(":")[0],10);let d=r.get(l);d||r.set(l,d=new Set),d.add(a)});const o=new Map;return r.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(m=>d.has(m));o.set(l,c?d:a)}),n.current=o,o},[e,i])}function rg(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function sg(e){return e.getAttribute("data-heading-anchor")}function Li(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Ka({n:e}){return t.jsx(t.Fragment,{children:Array.from({length:e},(i,n)=>t.jsx("span",{className:"guji-text-blank-col","aria-hidden":"true","data-blank-col":""},n))})}function og(e,i){const n=Array.from(i(e.join("")));return n.length===e.length&&e.every(r=>Array.from(r).length===1)?n:e.map(r=>i(r))}function ag({heading:e,children:i}){if(!e)return t.jsx("p",{className:"guji-reflow-paragraph",children:i});const n=`h${Math.min(6,e.level+1)}`;return t.jsx(n,{className:`guji-reflow-paragraph guji-reflow-heading guji-reflow-h${e.level}`,"data-heading-anchor":e.anchor,"data-heading-level":e.level,"data-heading-toc":e.toc===!1?"0":void 0,children:i})}const lg=b.memo(function({pGroup:i,first:n,pageBreaks:r,markOpts:o,plainBooks:a,selected:l,decorations:d,entityOfChar:c,entityLoader:m,convert:p,buildHref:h,handlers:u,charCount:f,pageStarts:g,figures:y,figUrl:v}){const w=b.useMemo(()=>{const N=new Map;if(!p)return N;for(const z of i.paragraphs){const C=og(z.chars.map(U=>U.charData.fig?U.charData.char:U.charData.norm??U.charData.char),p);z.chars.forEach((U,R)=>N.set(U.charData.id,U.charData.fig?U.charData.char:C[R]))}return N},[i,p]),x=N=>N.unk?Wf:w.get(N.id)??N.char,{t:j}=oe(),S=N=>{const z=o?Kc(N.mark,o):N.mark;return z?t.jsx("span",{className:"guji-text-punct","data-punct-id":N.id,children:z},N.id):null},$=N=>{var z;return(z=i.blocks)==null?void 0:z.map((C,U)=>C.before===N&&t.jsx(Bf,{fig:C.fig,info:y==null?void 0:y.get(C.fig),figUrl:v,onClick:()=>u.figBlock({page:i.page,fig:C.fig,...C.box?{box:C.box}:{}})},`fig-${C.fig}-${U}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:qf,"--gtv-pc":f,"--gtv-pp":i.paragraphs.length},children:[!n&&r&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:s.bim("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},"data-page-label":i.label,title:i.label?`${i.page}`:void 0,children:["第 ",i.label??i.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}})]}),i.paragraphs.map((N,z)=>t.jsxs(b.Fragment,{children:[$(z),t.jsxs(ag,{heading:N.heading,children:[Yf(N.chars,c).map((C,U)=>{const R=C.chars.map(({charData:T,beforePuncts:Z,afterPuncts:O,start:ae},ce)=>{var K,V,re;const Ee=!!C.entity&&ce===0,we=!!C.entity&&ce===C.chars.length-1,ye=Ee?[]:Z,Q=we?[]:O,Ne=!!T.fig&&ce>0&&C.chars[ce-1].charData.fig===T.fig;let W=1;if(T.fig&&!Ne)for(;((K=C.chars[ce+W])==null?void 0:K.charData.fig)===T.fig;)W++;const je=`guji-text-char${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${ae!=null&&ae.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[ae&&ae.blankBefore>0&&t.jsx(Ka,{n:ae.blankBefore}),ye.map(S),T.fig?t.jsx(Ff,{id:T.id,fig:T.fig,info:y==null?void 0:y.get(T.fig),figUrl:v,cells:W,cont:Ne,className:je,pageStart:g.get(T.id),children:x(T)}):t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-char-id":T.id,"data-page-start":g.get(T.id),...Qf(d==null?void 0:d.get(T.id)),style:eg(d==null?void 0:d.get(T.id)),className:`guji-text-char${tg(d==null?void 0:d.get(T.id))}${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${T.lacuna||T.pending&&T.char==="□"?" is-lacuna":""}${T.unk?" is-unk":""}${T.pending?" is-pending":""}${T.lacuna&&T.guess_c?" has-guess":""}${T.guess?" is-guess":""}${T.zi?" is-zi":""}${ae!=null&&ae.raised?" is-raised":""}`,"data-raised":(ae==null?void 0:ae.raised)||void 0,"data-guji-guess":T.lacuna&&T.guess_c?T.guess_c:void 0,title:((V=d==null?void 0:d.get(T.id))==null?void 0:V.title)??(T.unk?j("reader.unkChar",{label:p?p(T.unk):T.unk}):T.pending?j("reader.pendingReason",{label:p?p(_e.pendingReasonLabel(T.pending)):_e.pendingReasonLabel(T.pending)}):T.lacuna?T.guess_c?j("reader.lacunaGuess",{guess:p?p(T.guess_c):T.guess_c}):j("detail.lacuna"):T.zi?j("detail.composedChar",{label:T.zi}):T.guess?j("reader.charGuess"):void 0),children:x(T)}),((re=d==null?void 0:d.get(T.id))==null?void 0:re.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(T.id).insertAfter})]}),Q.map(S)]},T.id)});if(!C.entity)return t.jsx(b.Fragment,{children:R},`r${U}`);const L=C.chars[0].beforePuncts.map(S),F=C.chars[C.chars.length-1].afterPuncts.map(S);return t.jsxs(b.Fragment,{children:[L,t.jsx(Qs,{span:C.entity,label:C.chars.map(T=>x(T.charData)).join(""),hasBrackets:!0,plain:a&&C.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>R,hoverDelayMs:250}),F]},`${C.entity.key}@${U}`)}),z===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Ka,{n:i.trailingBlank}):null]})]},N.id)),$(i.paragraphs.length)]})});function ls(e){const[i,n]=Vi,r=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,r))*1e3)/1e3}const cg=.02,xi=16,dg=4;function mg({y:e,containerRef:i,onDrag:n,onCommit:r}){const{t:o}=oe(),[a,l]=b.useState(0),d=b.useRef(!1),c=b.useRef(null),m=b.useRef(e);m.current=e;const p=b.useCallback(()=>{var y;const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=f==null?void 0:f.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-xi-dg))},[i]);b.useLayoutEffect(()=>{var y;window.addEventListener("resize",p);const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=typeof ResizeObserver<"u"?new ResizeObserver(()=>p()):null;for(const v of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])v&&(g==null||g.observe(v));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>ls(u/Math.max(1,window.innerHeight));return t.jsx("div",{ref:c,role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":o("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Vi[0]*100),"aria-valuemax":Math.round(Vi[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${xi/2}px)`,width:xi,height:xi,zIndex:20,cursor:"ns-resize",touchAction:"none",display:"flex",alignItems:"center",justifyContent:"center",color:s.bim("meta-fg")},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const f=h(u.clientY);m.current=f,n(f)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}r(h(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,r(m.current))},onKeyDown:u=>{const f=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;f&&(u.preventDefault(),r(ls(e+f*(u.shiftKey?5:1)*cg)))},children:t.jsx("svg",{width:xi,height:xi,viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2 8h11M9 4l4 4-4 4"})})})}const dd=1,md=6,vn={s:1,x:0,y:0},En=(e,i,n)=>Math.min(n,Math.max(i,e));function io(e,i,n){const r=En(e.s,dd,md);return{s:r,x:En(e.x,i*(1-r),0),y:En(e.y,n*(1-r),0)}}function Or(e,i,n,r,o,a){const l=En(e.s*r,dd,md),d=l/e.s;return io({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function ug(e,i,n,r,o){return io({s:e.s,x:e.x+i,y:e.y+n},r,o)}function pg(e,i,n){const r=i===1?e*16:i===2?e*400:e;return Math.exp(-r*(n?.01:.0015))}const Ya=4,bg=b.forwardRef(function({children:i,onScaleChange:n,resetKey:r,style:o},a){const l=b.useRef(null),[d,c]=b.useState(vn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var S;const j=m.current;m.current=x,c(x),x.s!==j.s&&((S=p.current)==null||S.call(p,x.s))},u=()=>{var j;const x=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(x==null?void 0:x.width)??0,h:(x==null?void 0:x.height)??0,left:(x==null?void 0:x.left)??0,top:(x==null?void 0:x.top)??0}};b.useImperativeHandle(a,()=>({zoomBy(x){const{w:j,h:S}=u();h(Or(m.current,j/2,S/2,x,j,S))},reset(){h(vn)}})),b.useEffect(()=>{h(vn)},[r]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:S,h:$}=u(),N=io(m.current,S,$);(N.x!==m.current.x||N.y!==m.current.y)&&h(N)});return j.observe(x),()=>j.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const j=S=>{const $=pg(S.deltaY,S.deltaMode,S.ctrlKey);if(m.current.s<=1&&$<1)return;S.preventDefault();const{w:N,h:z,left:C,top:U}=u();h(Or(m.current,S.clientX-C,S.clientY-U,$,N,z))};return x.addEventListener("wheel",j,{passive:!1}),()=>x.removeEventListener("wheel",j)},[]);const f=b.useRef(new Map),g=b.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),y=x=>{if(x.pointerType==="mouse"&&x.button!==0)return;f.current.set(x.pointerId,{x:x.clientX,y:x.clientY});const j=g.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[S,$]=[...f.current.values()];j.pinchDist=Math.hypot(S.x-$.x,S.y-$.y),j.moved=Ya+1}},v=x=>{var F;const j=f.current.get(x.pointerId);if(!j)return;const S={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,S);const $=g.current,{w:N,h:z,left:C,top:U}=u();if(f.current.size>=2){const[T,Z]=[...f.current.values()],O=Math.hypot(T.x-Z.x,T.y-Z.y);if($.pinchDist>0&&O>0){const ae=(T.x+Z.x)/2-C,ce=(T.y+Z.y)/2-U;h(Or(m.current,ae,ce,O/$.pinchDist,N,z))}$.pinchDist=O,$.swallowClick=!0;return}const R=S.x-j.x,L=S.y-j.y;if($.moved+=Math.abs(R)+Math.abs(L),!($.moved<=Ya)){if(!$.dragging){$.dragging=!0;try{(F=l.current)==null||F.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(ug(m.current,R,L,N,z))}},w=x=>{f.current.delete(x.pointerId);const j=g.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:v,onPointerUp:w,onPointerCancel:w,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(vn),style:{position:"relative",overflow:"hidden",touchAction:"none",cursor:d.s>1?"grab":void 0,...o},children:t.jsx("div",{className:"bim-zp-inner",style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",transformOrigin:"0 0",transform:`translate(${d.x}px, ${d.y}px) scale(${d.s})`,willChange:d.s>1?"transform":void 0},children:i})})});function ud(e,i,n,r,o=""){const a=`${o}
|
|
1547
1547
|
${r.versionKey??""}
|
|
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
|
|
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 hg(e,i,n,r=""){const o=`${r}
|
|
1549
1549
|
${n.versionKey??""}
|
|
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?qc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:
|
|
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?qc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:fg}const fg=[],gg=/^#{1,6}$/,xg=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function yg(e){let i=e.trim();const n=xg.exec(i);return n&&(i=n[1]+n[2]),i.replace(/[《》〈〉]/g,"").trim()}const Ga=e=>e.kind==null||e.kind==="point";function pd(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=yg(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"&&gg.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)Ga(g)&&g.pos==="before"&&(a.text+=g.mark);a.text+=h.char;for(const g of u)Ga(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 bd(e){const i=e.indexOf("#");return i<=0||i===e.length-1?null:{chapter:e.slice(0,i),anchor:e.slice(i+1)}}function hd(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 jg=[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 kg=150,Va="(min-width: 860px)";function wg(){const[e,i]=b.useState(()=>typeof window>"u"||!window.matchMedia?!0:window.matchMedia(Va).matches);return b.useEffect(()=>{var o;if(!window.matchMedia)return;const n=window.matchMedia(Va),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 qa={padding:24,color:s.bim("desc-fg"),fontSize:14};function Xa({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 Ja=/^https?:\/\//i,vg=[];function Sg(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&&Ja.test(n)?n:void 0,license:i(e.license),license_url:r&&Ja.test(r)?r:void 0,note:i(e.note)};return o.name||o.license||o.note?o:null}function $g(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 Za(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 fd(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 gd(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:gd(e,r.children,n)}:{}}))}function _g(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?fd(f,n,r,o):h),hint:d(i[h]),disabled:i[h]===0,...g.length>0?{selectable:!0,children:gd(h,hd(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=Zh(u,i);return{key:`group:${f}`,label:r(u.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:ed(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 xd=e=>{const i=mc(),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(xu,{mode:i[0].scriptMode,children:t.jsx(zg,{...e,prefsState:i,onBodyReady:n?d:void 0})}),n&&!r&&!a&&t.jsx(Ng,{data:n})]})};function Ng({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 zg=({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(()=>rc(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,J]=b.useState(null),[I,ue]=b.useState(null);b.useEffect(()=>{J(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}
|
|
1551
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),[X,ie]=b.useState("loading"),me=B?`${n}
|
|
1552
1552
|
${B}`:null,se=qe&&qe.owner===me?qe.idx:null;b.useEffect(()=>{if(!B)return;let E=!1;const G=`${n}
|
|
1553
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||J(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=bd(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}
|
|
@@ -1555,9 +1555,9 @@ ${B}
|
|
|
1555
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}
|
|
1556
1556
|
${B}
|
|
1557
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}=uf({resetKey:`${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=
|
|
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=wg(),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=kh(h??gt,de??null,De,n),{warpData:A,loading:ne}=ud(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,Ke=hg(U??We,de??null,De,n),Ae=ce.properNameMode??(Ke.length>0?"full":"off"),Ce=b.useMemo(()=>({...ce,properNameMode:Ae}),[ce,Ae]),rt=b.useMemo(()=>jh(Ke,Ae,{showWorks:Ce.showWorks}),[Ke,Ae,Ce.showWorks]),[st,Ye]=b.useState(new Set),[D,ke]=b.useState(null),[Qe]=b.useState(wh),[Ge,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}
|
|
1559
1559
|
${B}
|
|
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?pd(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]),Mm=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]),Am=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}),Lm=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))},jg)))},[]);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),Pm=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),Om=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 yg){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,[Zm,Qm]=Ut.sub==="a"?[fn,At.x1]:Ut.sub==="b"?[At.x0,fn]:[At.x0,At.x1];return{...Ut,bbox_col:[Zm*Fo,hn,Qm*Fo,hn+At.slotH*Bo]}})}}):[]}},[A,yt,Ri,Dt,Ti]),{entryTitle:mn,authors:No}=Eg(n,r,m===void 0),[zo,gr]=b.useState("text");b.useEffect(()=>{gr("text")},[de,B]);const Fm=b.useMemo(()=>se?$g(se,et,Za(fe,se),O,Me,mr):[],[se,et,fe,O,Me,mr]),Co=Ph(),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]),Bm=b.useMemo(()=>L&&L.length>0?[...xr,...L]:xr,[xr,L]),Hm=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]),Dm=b.useCallback(E=>{de&&k(de,E)},[de,k]),oi=Fh({plugins:Bm,ctx:Hm,prefs:Ce,setPrefs:Ee,t:Z,convert:O,pages:A==null?void 0:A.pages,textRootRef:Eo,shellTextRef:Ro,selectedCharIds:st,scrollToAnchor:Dm});if(W==="loading")return t.jsx(Xa,{className:F,style:T,title:m??mn,label:Z("reader.loading")});if(W==="missing"||!Q||!fe)return t.jsx("div",{className:F,style:{...T,...qa},children:Z("reader.noText")});if(X==="failed")return t.jsx("div",{className:F,style:{...T,...qa},children:Z("reader.tocFailed")});if(!se)return t.jsx(Xa,{className:F,style:T,title:m??mn,label:Z("reader.tocLoading")});const hi=Za(fe,se),Wm=Fm,To=nt&&de&&nt.chapter===de?no(de,nt.anchor):null,Um=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:Qa(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=vg((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,Km=jr&&Io?t.jsxs(t.Fragment,{children:[jr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Io]})]}):jr,Ym=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?fd(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&&td(li.sections),Gm=Mo&&!(fi&&Ce.readingMode==="paragraph"&&Ln(fi)),Vm=ai&&Mo?t.jsx(pf,{juan:li,view:zo,onView:gr,textHasEntries:Gm}):void 0,qm=!0,pn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,bn=Qa(fe),Xt=bn?Z("reader.originalSource"):fe.source_name?O(fe.source_name):void 0,Xm=(typeof p=="string"?O(p):p)??(bn?void 0:Xt??O(_e.textVersionLabel(fe))),Jm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(bc,{className:F,style:T,title:Km,subtitle:Xm,byline:Ym,current:kr,pagerUnit:hi,rail:Vm,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:Wm,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:Um,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:Om,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(pg,{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:Am,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=>Pm(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:Jm,contentLoading:Re,children:[(Re||ne&&!A&&!ai&&pn==null)&&t.jsx(sc,{}),!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||wg,selectedCharIds:st,hoveredCharId:E,onSelectionChange:Mm,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:Lm,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(mf,{juan:li,rawText:fi,positionLabel:zg(ge,se,hi,O),groupLabel:Cg(se,de??null),index:Sg(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(oc,{text:Mt.note,convert:O})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Hs,{text:pn,mode:Ce.readingMode,tables:qm,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 Qa(e){return e.is_original===!0||e.source==="original"}function zg(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 Cg(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 Eg(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 Rg=({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})]})]})]})},Tg=({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(Ig,{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))})]})},Ig=({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(Mg,{category:m,expanded:r===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},Mg=({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(el,{label:o("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(el,{label:o("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},el=({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 yd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const Ag=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],jd=({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:Lg,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:Pg,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Og,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:Fg,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Ug,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:Ag.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...Bg,...a===x.value?Hg:{}},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:{...Dg,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:Yg}),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:Kg,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!w,style:{...Wg,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Lg={position:"fixed",top:0,left:0,right:0,bottom:0,background:s.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Pg={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:s.bim("shadow-dialog")},Og={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Fg={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:s.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Bg={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"},Hg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Dg={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"},Wg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},Ug={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:s.bim("success")},Kg={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Yg={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,Gg=16,Vg=({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+Gg}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:{...qg,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(jd,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},qg={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"},Xg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],kd=({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:tl,children:t.jsxs("div",{style:tx,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:ix,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:tl,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Xg.map(y=>t.jsxs("button",{onClick:()=>r(y.value),style:{...Jg,...n===y.value?Zg:{}},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:{...Qg}}),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:rx}),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:{...ex,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:nx,children:p})]})},tl={padding:"16px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",background:s.bim("input-bg")},Jg={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"},Zg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Qg={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"},ex={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},tx={display:"flex",alignItems:"center",gap:"12px",color:s.bim("success"),fontSize:"14px"},ix={background:"none",border:"none",color:s.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},nx={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},rx={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"},wd={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")}},sx=wd.other,vd={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")}},ox=vd.pending;function ax(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 lx(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 Sd=({items:e,loading:i})=>{const n=It(),{t:r,convert:o}=oe();return i?t.jsx(sc,{}):e.length===0?t.jsx("div",{style:cx,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=wd[a.type]||sx,d=vd[a.status]||ox,c=typeof window<"u"&&lx(a.pageUrl,window.location.href);return t.jsxs("div",{style:dx,children:[t.jsxs("div",{style:mx,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...il,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...il,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:ux,children:ax(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:px,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:bx,children:o(a.content)}),a.reply&&t.jsxs("div",{style:hx,children:[t.jsx("div",{style:fx,children:r("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},cx={textAlign:"center",padding:"40px 0",color:s.bim("desc-fg"),fontSize:"14px"},dx={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},mx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},il={fontSize:"12px",color:s.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},ux={fontSize:"12px",color:s.bim("desc-fg")},px={fontSize:"12px",marginBottom:"6px"},Fr={color:s.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${s.bim("primary")}`},bx={fontSize:"14px",lineHeight:"1.6",color:s.bim("fg"),whiteSpace:"pre-wrap"},hx={marginTop:"12px",padding:"10px 12px",background:s.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:s.bim("fg")},fx={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:s.bim("primary")},$d=({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(Sd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(kd,{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 gx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function xx(e){const i=e.search(gx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const _d={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===yx(e))){const[a,l]=xx(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 yx(e){try{return decodeURI(e)}catch{return e}}const jx={..._d,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:r})=>{const{convert:o}=xt(),a=i?jx:_d;return t.jsx("div",{className:r,style:n,children:t.jsx(au,{remarkPlugins:[lu],components:a,children:o(e)})})},kx=s.detail["zh-Hant"].relation,wx=s.detail["zh-Hant"].lossStatus,vx=s.detail["zh-Hant"].resourceKind,ir=s.getT("zh-Hant"),so=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function nl(e,i=ir){return e?so(kx,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function Sx(e,i=ir){return so(wx,e)?i(`detail.lossStatus.${e}`):e}function $x(e,i=ir){return so(vx,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 Nd(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 zd(e,i){const n=(e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name,r=Pl(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(zd(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 Cd({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(zd(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 rl=12,Br=50,_x=60,Ed=({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=Ku(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=>Fl(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,rl),[$,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:zx((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(()=>Bl(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,rl),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=Ju(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]),J=((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($x(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(Sx(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=Nx(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(Qu(M)),href:ep(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))}),X=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}),J&&ie.push({id:"contents",label:c("workPage.sec.contents"),count:J}),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&&!J,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&&X.length===0&&h.length>1?"":void 0,children:[!$&&X.length>0&&t.jsx(Qi,{items:X,value:v,onChange:M=>{w(M),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(vc,{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(sl,{row:q,measure:_==null?void 0:_.measure_info,relations:q.relations??(_?Ol(_):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(sl,{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(Ex,{items:fe,transport:i,onNavigate:n,renderLink:r}),J>0&&e._contents&&t.jsx(Rx,{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=nl(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(nl(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 Nx(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 zx(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 Cx({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 sl({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(Cx,{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 Ex({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 Rx({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 Rd=({graph:e,renderLink:i,className:n,style:r})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Kx,...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:{...Ix,...r},children:[e.title&&t.jsx("div",{style:Mx,children:a(e.title)}),e.description&&t.jsx("div",{style:Ax,children:a(e.description)}),u.map(f=>t.jsx(ol,{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(ol,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},ol=({label:e,color:i,nodes:n,incomingMap:r,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:Lx,children:[t.jsx("div",{style:{...Px,borderLeftColor:i??s.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(Tx,{node:c,incoming:r.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Tx=({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:{...Ox,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:Fx,children:[t.jsx("span",{style:Bx,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Hx,children:Il(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Dx,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:Wx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ux,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:ll,children:[t.jsx("div",{style:cl,children:d("lineage.sources")}),i.map(m=>{const p=r.get(m.source);return t.jsxs("div",{style:dl(m.confidence),children:[t.jsx("span",{style:ml,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(al,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:ul,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:ll,children:[t.jsx("div",{style:cl,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:dl(m.confidence),children:[t.jsx("span",{style:ml,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(al,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:ul,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})},al=({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},Ix={fontSize:"14px",color:s.bim("fg")},Mx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ax={fontSize:"13px",color:s.bim("muted"),marginBottom:"16px",lineHeight:1.6},Lx={marginBottom:"16px"},Px={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:s.bim("fg")},Ox={border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:s.bim("bg")},Fx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Bx={fontSize:"15px",fontWeight:600},Hx={fontSize:"12px",color:s.bim("muted")},Dx={marginBottom:"6px"},Wx={fontSize:"12px",color:s.bim("muted"),margin:"2px 0"},Ux={fontSize:"12px",color:s.bim("muted"),fontStyle:"italic",margin:"4px 0"},ll={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${s.bim("widget-border")}`},cl={fontSize:"11px",color:s.bim("muted"),marginBottom:"2px"},dl=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),ml={display:"inline-block",padding:"0 6px",fontSize:"11px",background:s.bim("tag-bg"),color:s.bim("fg"),borderRadius:"3px",marginRight:"6px"},ul={fontSize:"11px",color:s.bim("muted")},Kx={padding:"20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px"},Td=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[r,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Yx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:bl,children:n("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:bl,children:[t.jsx("div",{children:pl(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:pl(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Gx,{modules:a,selectedNodeId:e,...i})};function pl(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 Yx(){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 Gx=({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:Il(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(()=>Vx(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 Vx(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??Xx(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=>qx(w,y.get(w.id),o));return{rfNodes:h,rfEdges:v}}function qx(e,i,n=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Jx(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 Xx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Jx(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 bl={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:Zx,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(Rd,{graph:e,renderLink:n}):t.jsx(Td,{graph:e,renderLink:n,height:r,selectedNodeId:o})]})},Zx={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"}),hl=40,fl=2,Qx=9,e0=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 Id=({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):[],...Su(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<=hl,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(()=>Nd(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=Kl(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=Ac(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})}),J=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")}),J.length&&B.push({id:"collections",label:u("section.containedIn"),count:J.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,Qx),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}),X=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(Cd,{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(i0,{data:e,heading:K||je,yearText:V,refName:Ne,onNavigate:n,renderLink:r})}),J.length>0&&t.jsx(St,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:J.map((_,le)=>{const H=_.id,he=Wi(_.vol),xe=v.get(H),Re=qu(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(t0,{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<=hl,se=me&&ie>=0?x.slice(Math.max(0,ie-fl),ie+fl+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(wc,{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:X,card:re,side:de})};function t0({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 i0({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&&e0.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,n0=200,r0=16,Md=({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(()=>Ul(e,i),[e,i]),z=b.useMemo(()=>Wl(e),[e]),[C,U]=b.useState(new Map),R=!!n&&N.rows.length>0&&N.rows.length<=n0,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,r0);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(()=>Nd(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),J=e.count,I=Y=>typeof Y=="number"&&Number.isFinite(Y)?Y:null,ue=I(J==null?void 0:J.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(J==null?void 0:J.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(J==null?void 0:J.zhong)!=null?m("collectionPage.nZhong",{n:J.zhong}):"",I(J==null?void 0:J.han)!=null?m("collectionPage.nHan",{n:J.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,J,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(Cd,{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")})})]}),X=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(wc,{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:X})},s0=8;function Ad(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function o0(e){return(e||[]).filter(i=>{var n,r;return Ad(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((r=i.license)==null?void 0:r.trim())}).slice(0,s0)}function a0({images:e,assetBase:i,name:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?o0(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+Ad(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 gl=8,xl=10,yl=30,Ld=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function l0(e){return`${Ld(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function c0(e,i,n){var r;return`${Ld(i,n.key,n.chapter)}#e=${((r=n.ids)!=null&&r.length?n.ids:[e]).join(",")}`}const d0=({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(gl),[u,f]=b.useState(xl),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(gl),f(xl),!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(l0($),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(m0,{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($=>$+yl),children:o("mentions.moreBooks",{n:Math.min(yl,S.length-u)})})]})]})})},m0=({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(c0(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}`))})]})})},u0=16,p0=30,Wr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function jl(e){if(!e)return Wr.length;const i=Wr.indexOf(e);return i===-1?Wr.length:i}function b0(e,i,n){if(i)return e[i]??n(i)}function h0(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const f0={秦:[-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]},Pd=({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=>h0(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(()=>Dl(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,u0),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)=>jl(P[0])-jl(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,J=e.dynasty?f0[e.dynasty]:void 0,I=(()=>{if(!J||Z==null||O==null||O<Z)return null;const[k,P]=J,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:b0(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(a0,{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 X=U.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),ie=e.id?t.jsx(d0,{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(g0,{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:[X.length>1&&t.jsx(Qi,{items:X,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 g0({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,p0);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)",x0=`${co}, (pointer: coarse)`,Od=`
|
|
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(()=>{Ye(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?pd(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]),Mm=b.useCallback(E=>{if(Ye(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]),Am=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}),Lm=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))},kg)))},[]);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),Pm=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),Om=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 jg){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,[Zm,Qm]=Ut.sub==="a"?[fn,At.x1]:Ut.sub==="b"?[At.x0,fn]:[At.x0,At.x1];return{...Ut,bbox_col:[Zm*Fo,hn,Qm*Fo,hn+At.slotH*Bo]}})}}):[]}},[A,yt,Ri,Dt,Ti]),{entryTitle:mn,authors:No}=Rg(n,r,m===void 0),[zo,gr]=b.useState("text");b.useEffect(()=>{gr("text")},[de,B]);const Fm=b.useMemo(()=>se?_g(se,et,Za(fe,se),O,Me,mr):[],[se,et,fe,O,Me,mr]),Co=Ph(),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 ${Ge?"bim-rd-on":""}`,"aria-pressed":Ge,title:"切换外挂现代断句标点",onClick:()=>wt(G=>!G),children:Ge?"标点":"无标点"})}}),E},[A,Ge]),Bm=b.useMemo(()=>L&&L.length>0?[...xr,...L]:xr,[xr,L]),Hm=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]),Dm=b.useCallback(E=>{de&&k(de,E)},[de,k]),oi=Fh({plugins:Bm,ctx:Hm,prefs:Ce,setPrefs:Ee,t:Z,convert:O,pages:A==null?void 0:A.pages,textRootRef:Eo,shellTextRef:Ro,selectedCharIds:st,scrollToAnchor:Dm});if(W==="loading")return t.jsx(Xa,{className:F,style:T,title:m??mn,label:Z("reader.loading")});if(W==="missing"||!Q||!fe)return t.jsx("div",{className:F,style:{...T,...qa},children:Z("reader.noText")});if(X==="failed")return t.jsx("div",{className:F,style:{...T,...qa},children:Z("reader.tocFailed")});if(!se)return t.jsx(Xa,{className:F,style:T,title:m??mn,label:Z("reader.tocLoading")});const hi=Za(fe,se),Wm=Fm,To=nt&&de&&nt.chapter===de?no(de,nt.anchor):null,Um=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:Qa(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=Sg((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,Km=jr&&Io?t.jsxs(t.Fragment,{children:[jr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Io]})]}):jr,Ym=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?fd(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&&td(li.sections),Gm=Mo&&!(fi&&Ce.readingMode==="paragraph"&&Ln(fi)),Vm=ai&&Mo?t.jsx(pf,{juan:li,view:zo,onView:gr,textHasEntries:Gm}):void 0,qm=!0,pn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,bn=Qa(fe),Xt=bn?Z("reader.originalSource"):fe.source_name?O(fe.source_name):void 0,Xm=(typeof p=="string"?O(p):p)??(bn?void 0:Xt??O(_e.textVersionLabel(fe))),Jm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(bc,{className:F,style:T,title:Km,subtitle:Xm,byline:Ym,current:kr,pagerUnit:hi,rail:Vm,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:Wm,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:Um,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:Om,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:()=>Ye(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(bg,{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:Am,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),Ye(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=>Pm(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:Jm,contentLoading:Re,children:[(Re||ne&&!A&&!ai&&pn==null)&&t.jsx(sc,{}),!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||vg,selectedCharIds:st,hoveredCharId:E,onSelectionChange:Mm,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:G,fig:be})=>{Ye(new Set),ke(be),bi(G)},onCharClick:G=>{ke(null),Ye(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:Ge,entities:rt,entityTransport:r,onEntityNavigate:R,onVisiblePageChange:Lm,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(mf,{juan:li,rawText:fi,positionLabel:Cg(ge,se,hi,O),groupLabel:Eg(se,de??null),index:$g(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(oc,{text:Mt.note,convert:O})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Hs,{text:pn,mode:Ce.readingMode,tables:qm,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 Qa(e){return e.is_original===!0||e.source==="original"}function Cg(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 Eg(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 Rg(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 Tg=({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})]})]})]})},Ig=({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(Mg,{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))})]})},Mg=({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(Ag,{category:m,expanded:r===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},Ag=({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(el,{label:o("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(el,{label:o("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},el=({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 yd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const Lg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],jd=({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:Pg,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:Og,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Fg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:Bg,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Kg,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:Lg.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...Hg,...a===x.value?Dg:{}},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:{...Wg,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:Gg}),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:Yg,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!w,style:{...Ug,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Pg={position:"fixed",top:0,left:0,right:0,bottom:0,background:s.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Og={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:s.bim("shadow-dialog")},Fg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Bg={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:s.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Hg={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"},Dg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Wg={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"},Ug={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},Kg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:s.bim("success")},Yg={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Gg={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,Vg=16,qg=({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+Vg}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:{...Xg,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(jd,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},Xg={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"},Jg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],kd=({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:tl,children:t.jsxs("div",{style:ix,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:nx,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:tl,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Jg.map(y=>t.jsxs("button",{onClick:()=>r(y.value),style:{...Zg,...n===y.value?Qg:{}},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:{...ex}}),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:sx}),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:{...tx,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:rx,children:p})]})},tl={padding:"16px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",background:s.bim("input-bg")},Zg={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"},Qg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},ex={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"},tx={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},ix={display:"flex",alignItems:"center",gap:"12px",color:s.bim("success"),fontSize:"14px"},nx={background:"none",border:"none",color:s.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},rx={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},sx={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"},wd={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")}},ox=wd.other,vd={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")}},ax=vd.pending;function lx(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 cx(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 Sd=({items:e,loading:i})=>{const n=It(),{t:r,convert:o}=oe();return i?t.jsx(sc,{}):e.length===0?t.jsx("div",{style:dx,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=wd[a.type]||ox,d=vd[a.status]||ax,c=typeof window<"u"&&cx(a.pageUrl,window.location.href);return t.jsxs("div",{style:mx,children:[t.jsxs("div",{style:ux,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...il,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...il,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:px,children:lx(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:bx,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:hx,children:o(a.content)}),a.reply&&t.jsxs("div",{style:fx,children:[t.jsx("div",{style:gx,children:r("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},dx={textAlign:"center",padding:"40px 0",color:s.bim("desc-fg"),fontSize:"14px"},mx={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},ux={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},il={fontSize:"12px",color:s.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},px={fontSize:"12px",color:s.bim("desc-fg")},bx={fontSize:"12px",marginBottom:"6px"},Fr={color:s.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${s.bim("primary")}`},hx={fontSize:"14px",lineHeight:"1.6",color:s.bim("fg"),whiteSpace:"pre-wrap"},fx={marginTop:"12px",padding:"10px 12px",background:s.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:s.bim("fg")},gx={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:s.bim("primary")},$d=({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(Sd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(kd,{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 xx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function yx(e){const i=e.search(xx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const _d={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===jx(e))){const[a,l]=yx(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 jx(e){try{return decodeURI(e)}catch{return e}}const kx={..._d,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:r})=>{const{convert:o}=xt(),a=i?kx:_d;return t.jsx("div",{className:r,style:n,children:t.jsx(au,{remarkPlugins:[lu],components:a,children:o(e)})})},wx=s.detail["zh-Hant"].relation,vx=s.detail["zh-Hant"].lossStatus,Sx=s.detail["zh-Hant"].resourceKind,ir=s.getT("zh-Hant"),so=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function nl(e,i=ir){return e?so(wx,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function $x(e,i=ir){return so(vx,e)?i(`detail.lossStatus.${e}`):e}function _x(e,i=ir){return so(Sx,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 Nd(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 zd(e,i){const n=(e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name,r=Pl(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(zd(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 Cd({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(zd(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 rl=12,Br=50,Nx=60,Ed=({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=Ku(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=>Fl(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<=Nx,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,rl),[$,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:Cx((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(()=>Bl(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,rl),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=Ju(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]),J=((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(_x(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($x(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=zx(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(Qu(M)),href:ep(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))}),X=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}),J&&ie.push({id:"contents",label:c("workPage.sec.contents"),count:J}),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&&!J,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&&X.length===0&&h.length>1?"":void 0,children:[!$&&X.length>0&&t.jsx(Qi,{items:X,value:v,onChange:M=>{w(M),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(vc,{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(sl,{row:q,measure:_==null?void 0:_.measure_info,relations:q.relations??(_?Ol(_):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(sl,{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(Rx,{items:fe,transport:i,onNavigate:n,renderLink:r}),J>0&&e._contents&&t.jsx(Tx,{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=nl(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(nl(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 zx(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 Cx(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 Ex({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 sl({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(Ex,{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 Rx({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 Tx({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 Rd=({graph:e,renderLink:i,className:n,style:r})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Yx,...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:{...Mx,...r},children:[e.title&&t.jsx("div",{style:Ax,children:a(e.title)}),e.description&&t.jsx("div",{style:Lx,children:a(e.description)}),u.map(f=>t.jsx(ol,{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(ol,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},ol=({label:e,color:i,nodes:n,incomingMap:r,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:Px,children:[t.jsx("div",{style:{...Ox,borderLeftColor:i??s.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(Ix,{node:c,incoming:r.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Ix=({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:{...Fx,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:Bx,children:[t.jsx("span",{style:Hx,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Dx,children:Il(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Wx,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:Ux,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Kx,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:ll,children:[t.jsx("div",{style:cl,children:d("lineage.sources")}),i.map(m=>{const p=r.get(m.source);return t.jsxs("div",{style:dl(m.confidence),children:[t.jsx("span",{style:ml,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(al,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:ul,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:ll,children:[t.jsx("div",{style:cl,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:dl(m.confidence),children:[t.jsx("span",{style:ml,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(al,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:ul,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})},al=({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},Mx={fontSize:"14px",color:s.bim("fg")},Ax={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Lx={fontSize:"13px",color:s.bim("muted"),marginBottom:"16px",lineHeight:1.6},Px={marginBottom:"16px"},Ox={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:s.bim("fg")},Fx={border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:s.bim("bg")},Bx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Hx={fontSize:"15px",fontWeight:600},Dx={fontSize:"12px",color:s.bim("muted")},Wx={marginBottom:"6px"},Ux={fontSize:"12px",color:s.bim("muted"),margin:"2px 0"},Kx={fontSize:"12px",color:s.bim("muted"),fontStyle:"italic",margin:"4px 0"},ll={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${s.bim("widget-border")}`},cl={fontSize:"11px",color:s.bim("muted"),marginBottom:"2px"},dl=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),ml={display:"inline-block",padding:"0 6px",fontSize:"11px",background:s.bim("tag-bg"),color:s.bim("fg"),borderRadius:"3px",marginRight:"6px"},ul={fontSize:"11px",color:s.bim("muted")},Yx={padding:"20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px"},Td=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[r,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Gx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:bl,children:n("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:bl,children:[t.jsx("div",{children:pl(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:pl(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Vx,{modules:a,selectedNodeId:e,...i})};function pl(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 Gx(){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 Vx=({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:Il(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(()=>qx(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 qx(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??Jx(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=>Xx(w,y.get(w.id),o));return{rfNodes:h,rfEdges:v}}function Xx(e,i,n=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Zx(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 Jx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Zx(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 bl={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:Qx,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(Rd,{graph:e,renderLink:n}):t.jsx(Td,{graph:e,renderLink:n,height:r,selectedNodeId:o})]})},Qx={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"}),hl=40,fl=2,e0=9,t0=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 Id=({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):[],...Su(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<=hl,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(()=>Nd(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=Kl(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=Ac(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})}),J=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")}),J.length&&B.push({id:"collections",label:u("section.containedIn"),count:J.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,e0),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}),X=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(Cd,{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(n0,{data:e,heading:K||je,yearText:V,refName:Ne,onNavigate:n,renderLink:r})}),J.length>0&&t.jsx(St,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:J.map((_,le)=>{const H=_.id,he=Wi(_.vol),xe=v.get(H),Re=qu(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(i0,{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<=hl,se=me&&ie>=0?x.slice(Math.max(0,ie-fl),ie+fl+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(wc,{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:X,card:re,side:de})};function i0({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 n0({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&&t0.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,r0=200,s0=16,Md=({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(()=>Ul(e,i),[e,i]),z=b.useMemo(()=>Wl(e),[e]),[C,U]=b.useState(new Map),R=!!n&&N.rows.length>0&&N.rows.length<=r0,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,s0);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(()=>Nd(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),J=e.count,I=Y=>typeof Y=="number"&&Number.isFinite(Y)?Y:null,ue=I(J==null?void 0:J.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(J==null?void 0:J.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(J==null?void 0:J.zhong)!=null?m("collectionPage.nZhong",{n:J.zhong}):"",I(J==null?void 0:J.han)!=null?m("collectionPage.nHan",{n:J.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,J,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(Cd,{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")})})]}),X=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(wc,{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:X})},o0=8;function Ad(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function a0(e){return(e||[]).filter(i=>{var n,r;return Ad(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((r=i.license)==null?void 0:r.trim())}).slice(0,o0)}function l0({images:e,assetBase:i,name:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?a0(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+Ad(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 gl=8,xl=10,yl=30,Ld=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function c0(e){return`${Ld(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function d0(e,i,n){var r;return`${Ld(i,n.key,n.chapter)}#e=${((r=n.ids)!=null&&r.length?n.ids:[e]).join(",")}`}const m0=({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(gl),[u,f]=b.useState(xl),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(gl),f(xl),!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(c0($),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(u0,{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($=>$+yl),children:o("mentions.moreBooks",{n:Math.min(yl,S.length-u)})})]})]})})},u0=({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(d0(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}`))})]})})},p0=16,b0=30,Wr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function jl(e){if(!e)return Wr.length;const i=Wr.indexOf(e);return i===-1?Wr.length:i}function h0(e,i,n){if(i)return e[i]??n(i)}function f0(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const g0={秦:[-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]},Pd=({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=>f0(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(()=>Dl(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,p0),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)=>jl(P[0])-jl(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,J=e.dynasty?g0[e.dynasty]:void 0,I=(()=>{if(!J||Z==null||O==null||O<Z)return null;const[k,P]=J,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:h0(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(l0,{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 X=U.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),ie=e.id?t.jsx(m0,{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(x0,{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:[X.length>1&&t.jsx(Qi,{items:X,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 x0({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,b0);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)",y0=`${co}, (pointer: coarse)`,Od=`
|
|
1561
1561
|
.bim-ct {
|
|
1562
1562
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
1563
1563
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -1690,7 +1690,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
|
|
|
1690
1690
|
}
|
|
1691
1691
|
|
|
1692
1692
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
1693
|
-
@media ${
|
|
1693
|
+
@media ${y0} {
|
|
1694
1694
|
.bim-ct-row { min-height: 44px; }
|
|
1695
1695
|
.bim-ct-tw { width: 44px; }
|
|
1696
1696
|
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
@@ -1716,7 +1716,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
|
|
|
1716
1716
|
/* 窄屏分类抽屉:界栏下按钮和面板都有框 */
|
|
1717
1717
|
:root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${s.bim("fr-bd")}; background: ${s.bim("fr-bg")}; }
|
|
1718
1718
|
:root[data-layout="boxed"] .bim-ct-drawer { border: ${s.bim("fr-bd")}; }
|
|
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 y0(e){const i=sn(e);return i.length?i.join("/"):di}function j0(e){const i=sn(e);return i.length?i.map((n,r)=>i.slice(0,r+1).join("/")):[di]}function k0(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 w0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function v0(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=w0(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 S0(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 $0(e,i=mo){return Math.max(1,Math.ceil(e/i))}function Fd(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 N0(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 Bd({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(()=>N0(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 Hd=e=>`/item/${encodeURIComponent(e)}`;function z0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Dd(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Wd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Dd(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 Ud({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Dd(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 Kd({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&&!z0(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:Fd(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 Yd({works:e,workLink:i=Hd,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(Ud,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Wd,{work:d,href:i(d.id)},d.id))}),t.jsx(Kd,{...o})]})}const C0=()=>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 E0({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:Od}),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(C0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:v("catalogPage.classification")}),t.jsx(Bd,{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(Yd,{works:o,view:R,workLink:c,page:n,pageCount:r,onPage:l,pageHref:m})]})]})}const on="(max-width: 719px)",R0="(max-width: 1079px)",T0=`${on}, (pointer: coarse)`,I0=[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 j0(e){const i=sn(e);return i.length?i.join("/"):di}function k0(e){const i=sn(e);return i.length?i.map((n,r)=>i.slice(0,r+1).join("/")):[di]}function w0(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 v0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function S0(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=v0(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 $0(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 _0(e,i=mo){return Math.max(1,Math.ceil(e/i))}function Fd(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 N0=()=>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 z0(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 Bd({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(()=>z0(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(N0,{}):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 Hd=e=>`/item/${encodeURIComponent(e)}`;function C0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Dd(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Wd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Dd(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 Ud({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Dd(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 Kd({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&&!C0(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:Fd(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 Yd({works:e,workLink:i=Hd,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(Ud,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Wd,{work:d,href:i(d.id)},d.id))}),t.jsx(Kd,{...o})]})}const E0=()=>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 R0({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:Od}),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(E0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:v("catalogPage.classification")}),t.jsx(Bd,{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(Yd,{works:o,view:R,workLink:c,page:n,pageCount:r,onPage:l,pageHref:m})]})]})}const on="(max-width: 719px)",T0="(max-width: 1079px)",I0=`${on}, (pointer: coarse)`,M0=[8,18,30,42,88],po=`
|
|
1720
1720
|
.bim-rh { color: ${s.bim("ink")}; font-family: ${s.bim("font-ui")}; font-size: 14px; line-height: 1.6; }
|
|
1721
1721
|
.bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
|
|
1722
1722
|
.bim-rh a { color: ${s.bim("accent")}; text-decoration: none; }
|
|
@@ -1864,7 +1864,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
|
|
|
1864
1864
|
flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
|
|
1865
1865
|
color: ${s.bim("ink")} !important; font-size: 13px;
|
|
1866
1866
|
}
|
|
1867
|
-
${
|
|
1867
|
+
${M0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb, ${s.bim("accent")} ${e}%, ${s.bim("card-bg")}); }`).join(`
|
|
1868
1868
|
`)}
|
|
1869
1869
|
.bim-rh-band a[data-k="4"] { color: ${s.bim("page-bg")} !important; }
|
|
1870
1870
|
.bim-rh-band a:hover { outline: 2px solid ${s.bim("ink")}; outline-offset: -2px; }
|
|
@@ -1892,7 +1892,7 @@ ${I0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1892
1892
|
}
|
|
1893
1893
|
|
|
1894
1894
|
/* ── 中屏 ── */
|
|
1895
|
-
@media ${
|
|
1895
|
+
@media ${T0} {
|
|
1896
1896
|
.bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
1897
1897
|
.bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
1898
1898
|
}
|
|
@@ -1935,7 +1935,7 @@ ${I0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1935
1935
|
}
|
|
1936
1936
|
|
|
1937
1937
|
/* 触屏或窄屏:点击目标放大到 44px */
|
|
1938
|
-
@media ${
|
|
1938
|
+
@media ${I0} {
|
|
1939
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; }
|
|
1940
1940
|
.bim-rh-chip { display: inline-flex; }
|
|
1941
1941
|
}
|
|
@@ -1946,7 +1946,7 @@ ${I0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1946
1946
|
}
|
|
1947
1947
|
|
|
1948
1948
|
@media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
|
|
1949
|
-
`,M0=s.readHome["zh-Hant"].period,Gd={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{...Gd,...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 Vd(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 qd(e){return Math.max(150,Array.from(e).length*18+44)}function Xd(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 Jd=.04;function kt(e){return e.toLocaleString("en-US")}function Zd({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 Qd({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 em({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(Zd,{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 tm(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=Vd(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?kt(u.records):tm(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:qd(u.title)},children:[t.jsx(Zd,{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 A0=4,qi=e=>e>A0+1;function im({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=tm(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 nm({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(im,{topic:o,links:i},o.key))})]})}function rm({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 sm({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":Xd(h.count,p),"data-narrow":f<Jd?"":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 om({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 am={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function L0({sections:e,links:i,head:n,piecesMoreHref:r,className:o}){const{t:a}=oe(),l=e,d=am,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(Qd,{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(em,{picks:l.picks,links:i})}),m.topics&&t.jsx(Rt,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(nm,{topics:c,links:i})}),m.famous&&t.jsx(Rt,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(rm,{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(sm,{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(om,{authors:l.pieces.authors,links:i})})]})]})}const P0="(max-width: 1079px)",O0=`${on}, (pointer: coarse)`,lm=`
|
|
1949
|
+
`,A0=s.readHome["zh-Hant"].period,Gd={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{...Gd,...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 Vd(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 qd(e){return Math.max(150,Array.from(e).length*18+44)}function Xd(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 Jd=.04;function kt(e){return e.toLocaleString("en-US")}function Zd({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 Qd({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 em({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(Zd,{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 tm(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=Vd(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?kt(u.records):tm(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:qd(u.title)},children:[t.jsx(Zd,{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 L0=4,qi=e=>e>L0+1;function im({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=tm(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 nm({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(im,{topic:o,links:i},o.key))})]})}function rm({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 sm({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":Xd(h.count,p),"data-narrow":f<Jd?"":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 om({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 am={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function P0({sections:e,links:i,head:n,piecesMoreHref:r,className:o}){const{t:a}=oe(),l=e,d=am,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(Qd,{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(em,{picks:l.picks,links:i})}),m.topics&&t.jsx(Rt,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(nm,{topics:c,links:i})}),m.famous&&t.jsx(Rt,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(rm,{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(sm,{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(om,{authors:l.pieces.authors,links:i})})]})]})}const O0="(max-width: 1079px)",F0=`${on}, (pointer: coarse)`,lm=`
|
|
1950
1950
|
/* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
|
|
1951
1951
|
.bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
|
|
1952
1952
|
.bim-mh-q { min-width: 0; }
|
|
@@ -2086,7 +2086,7 @@ ${I0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
2086
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")}; }
|
|
2087
2087
|
|
|
2088
2088
|
/* ── 中屏 ── */
|
|
2089
|
-
@media ${
|
|
2089
|
+
@media ${O0} {
|
|
2090
2090
|
.bim-mh-head, .bim-mh-zhi { grid-template-columns: minmax(0, 1fr); }
|
|
2091
2091
|
.bim-mh-cg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
2092
2092
|
.bim-mh-lin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
@@ -2113,8 +2113,8 @@ ${I0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
2113
2113
|
.bim-mh-tbl tr > :nth-child(2), .bim-mh-tbl tr > :nth-child(3) { display: none; }
|
|
2114
2114
|
}
|
|
2115
2115
|
|
|
2116
|
-
@media ${
|
|
2116
|
+
@media ${F0} {
|
|
2117
2117
|
.bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
|
|
2118
2118
|
.bim-mh-recent-h button { min-height: 44px; }
|
|
2119
2119
|
}
|
|
2120
|
-
`,cm={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ni(e){return{...cm,...e??{}}}function dm(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 mm(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 F0(e){return{read:e.item,work:e.item,node:e.node}}function um({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 pm(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 B0(e,i,n){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?n(r):bm(e.type,i)}function bm(e,i){return i(`metaHome.typeLabel.${e}`)}function hm({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?bm(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:B0(l,r,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function fm(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 gm({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:fm(a.status,n,r)})})]},a.id||a.name)})})]})}):null}function xm({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 ym({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(xm,{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 jm="siku_qige";function H0({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(xm,{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 km({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===jm),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(H0,{group:c,links:o},c.key))})]})}const kl=34,wl=13;function vl(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 D0(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 wm({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}=mm(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-wl):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,wl),{...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*kl+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*kl+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:vl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:D0(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):"",vl(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 W0=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 vm({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:dm(o,a.id),children:[W0,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 Sm({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:fm(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 Sl=["extant","partially_extant","lost","unknown"];function $m({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=Sl.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:Sl.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 _m={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function U0({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=F0(f),y=_m,v=pm(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+lm}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(um,{counts:u.counts,links:i})]}),r&&t.jsx(hm,{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(gm,{rows:u.catalog_progress,links:i}),t.jsx(ym,{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(km,{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(wm,{people:u.bibliographers,links:i})}),w.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(vm,{works:u.lineage,links:i})}),w.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(Sm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx($m,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const Nm=["_related","_catalogs","_collections","_members","_children","_book_groups"],K0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),bs=e=>K0(e)&&!!e.h;function Y0(e){return e?Nm.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(bs)}):!1}function G0(e,i){const n={...e};if(!i)return n;for(const r of Nm){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 V0(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&&G0(d,Y0(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 q0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const X0=({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(()=>V0(i),[i]),ae=b.useMemo(()=>yd(O)??ro(U),[O,U]),ce=s.useT(),{t:Ee,convert:we}=oe(),[ye]=b.useState(()=>{if(!q0(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,J]=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,X]=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;X(!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()||X(!1)}},[O]),nt=b.useRef({initialDetail:n,initialEntry:r});nt.current={initialDetail:n,initialEntry:r},b.useEffect(()=>{let ee=!1;me.current++,X(!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?(J(!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),J(!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){J(!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||J(!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:[Z0(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(Ed,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he}):W.type==="book"?t.jsx(Id,{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(Md,{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(Pd,{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(nc,{data:De,onNavigate:g,renderLink:w})}if(o==="collated"||o==="fulltext")return t.jsx(xd,{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($d,{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(Lc,{left:t.jsxs(t.Fragment,{children:[ct,ct?" · ":"",t.jsx(J0,{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(_c,{...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(Nc,{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 J0({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 Z0(e,i){return i?e.workSubtype[i]??i:""}const zm=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],rr="zhusha",sr="bim-theme";function Cm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function or(e){return Cm(e)?e:rr}function Q0(){try{return or(window.localStorage.getItem(sr))}catch{return rr}}function Em(e){try{window.localStorage.setItem(sr,e)}catch{}}function Rm(e){const i=or(e);return document.documentElement.setAttribute("data-theme",i),i}function Tm(){return or(document.documentElement.getAttribute("data-theme"))}const ey=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],xo="airy",ar="bim-layout";function Im(e){return e==="airy"||e==="boxed"}function lr(e){return Im(e)?e:xo}function ty(){try{return lr(window.localStorage.getItem(ar))}catch{return xo}}function iy(e){try{window.localStorage.setItem(ar,e)}catch{}}function ny(e){const i=lr(e);return document.documentElement.setAttribute("data-layout",i),i}function ry(){return lr(document.documentElement.getAttribute("data-layout"))}const sy=`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){}`,oy={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},ay=({onChange:e,style:i})=>{const{t:n}=oe(),[r,o]=b.useState(rr);b.useEffect(()=>{o(Tm())},[]);const a=l=>{o(Rm(l)),Em(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:zm.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(oy[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=cu.VARIANT_SUPPLEMENT;exports.BidUrlProvider=mu;exports.BookDetailLayout=X0;exports.BookPage=Id;exports.Breadcrumb=ns;exports.CATALOG_ALL_ID=Gt;exports.CATALOG_CSS=Od;exports.CATALOG_NARROW_QUERY=co;exports.CATALOG_PAGE_SIZE=mo;exports.CATALOG_UNCLASSIFIED_ID=di;exports.CLASSIFICATIONS=qn;exports.CardFoot=nn;exports.CatalogPage=E0;exports.CatalogPager=Kd;exports.CatalogTree=Bd;exports.CheckFilter=vc;exports.Chip=zc;exports.ChipWall=Nb;exports.CollectionCatalog=nc;exports.CollectionPage=Md;exports.DEFAULT_LAYOUT=xo;exports.DEFAULT_META_HOME_LINKS=cm;exports.DEFAULT_READER_PREFS=Rs;exports.DEFAULT_READ_HOME_LINKS=Gd;exports.DEFAULT_THEME=rr;exports.DETAIL_CSS=$c;exports.DYNASTY_GROUPS=Vn;exports.Dash=Ib;exports.DataTable=Cb;exports.DetailFooter=Lc;exports.DetailGrid=Zi;exports.DetailHeader=_c;exports.EMPTY_FILTERS=Gn;exports.ENTITY_TEXT_CSS=Xs;exports.EmptyNote=Bb;exports.EntityMark=Qs;exports.EntityPage=Pd;exports.EntityText=Af;exports.ExpandRow=Mb;exports.ExtLink=Hb;exports.FEEDBACK_FAB_OFFSET_VAR=ds;exports.FILTER_SUPPORT=Vl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=vb;exports.FeedbackButton=Vg;exports.FeedbackDialog=jd;exports.FeedbackForm=kd;exports.FeedbackList=Sd;exports.FeedbackTab=$d;exports.FilterChip=Nc;exports.GUJI_MARKDOWN_FIELD=lb;exports.GUJI_TABLE_NOTATION=Pc;exports.GlyphBadge=Ms;exports.GujiInteractiveReader=Rg;exports.GujiTable=Ps;exports.GujiTextViewer=to;exports.GujiWarpCanvas=qs;exports.ImagePanel=Xr;exports.IndexBrowser=vp;exports.IntroGrid=wb;exports.LAYOUTS=ey;exports.LAYOUT_STORAGE_KEY=ar;exports.LOSS_OPTIONS=Gl;exports.LocaleProvider=hu;exports.LocaleToggle=hs;exports.META_HOME_CSS=lm;exports.META_HOME_SECTION_IDS=_m;exports.MetaCatalogTable=gm;exports.MetaCollectionGroups=km;exports.MetaDataLicense=$m;exports.MetaHomeView=U0;exports.MetaLine=vt;exports.MetaLineageCards=vm;exports.MetaOnlineSites=Sm;exports.MetaPeopleTimeline=wm;exports.MetaRecentPanel=hm;exports.MetaRelatedCatalogs=ym;exports.MetaTypeChips=um;exports.ModeIndicator=El;exports.MoreButton=_b;exports.MoreLink=Ts;exports.PAGE_MAX_WIDTH=zn;exports.PERIOD_NARROW_SHARE=Jd;exports.PageFrame=Hi;exports.Quote=Lb;exports.READER_CSS=ac;exports.READ_HOME_CSS=po;exports.READ_HOME_NARROW_QUERY=on;exports.READ_HOME_SECTION_IDS=am;exports.READ_PERIOD_LABELS=M0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Hl;exports.ReadButton=ts;exports.ReadFamousWorks=rm;exports.ReadHomeView=L0;exports.ReadPeriodBand=sm;exports.ReadPicks=em;exports.ReadPieces=om;exports.ReadSection=Rt;exports.ReadShelf=ho;exports.ReadSibu=fo;exports.ReadStats=Qd;exports.ReadTopicGroup=im;exports.ReadTopics=nm;exports.ReaderMdText=Hs;exports.ReaderShell=bc;exports.ReaderToc=lc;exports.RepoSourceLink=fs;exports.ResourceGroup=Pb;exports.ResourceLine=Ob;exports.ResourceList=ju;exports.ResourceRow=Ic;exports.SEARCH_VIEW_STORAGE_KEY=_s;exports.SEVEN_PAVILIONS_KEY=jm;exports.SNIPPET_MARK_END=Nl;exports.SNIPPET_MARK_START=_l;exports.SORTABLE_TYPES=Yl;exports.SearchInput=Tl;exports.SearchResults=ec;exports.Sec=St;exports.SectionHead=Sb;exports.SideList=mi;exports.StripWarpRenderer=rs;exports.SummaryCard=tn;exports.THEMES=zm;exports.THEME_INIT_SCRIPT=sy;exports.THEME_STORAGE_KEY=sr;exports.TabFilter=Qi;exports.TableHead=Eb;exports.TableRow=Rb;exports.TagRow=Mc;exports.TagRows=Fb;exports.TextButton=$b;exports.TextReader=xd;exports.ThemeToggle=ay;exports.TopStrip=is;exports.VersionLineageGraph=Td;exports.VersionLineageList=Rd;exports.VersionLineageView=lo;exports.VolumeChips=zb;exports.VolumeLinks=As;exports.WorkCard=Wd;exports.WorkCardGrid=Yd;exports.WorkCatalog=Tg;exports.WorkPage=Ed;exports.WorkRow=Ud;exports.adaptEntityJson=qc;exports.applyLayout=ny;exports.applyTheme=Rm;exports.authorsLine=nr;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Bs;exports.bucketResources=js;exports.buildCatalogTree=k0;exports.buildCollectionTable=Ul;exports.buildLineageGraph=Sn;exports.buildMeiliFilter=rp;exports.buildParagraphBlocks=Uc;exports.buildVersionRow=ks;exports.buildVersionTable=Bl;exports.canParagraphize=Ln;exports.catalogNodeIdOf=y0;exports.catalogNodeIdsOf=j0;exports.catalogPageCount=$0;exports.catalogTotal=uo;exports.classificationPath=sn;exports.clearAllRecentIds=Ns;exports.compareCatalogCards=S0;exports.computeVersionPartition=Gu;exports.countActiveFilters=Xn;exports.createFeedbackTransport=ro;exports.createTextApi=rc;exports.currentLayout=ry;exports.currentTheme=Tm;exports.defaultEntityHref=od;exports.defaultWorkLink=Hd;exports.deriveDating=Ou;exports.deriveEditionType=Kl;exports.deriveEra=Ji;exports.deriveYear=Un;exports.deriveYearRange=ys;exports.detectGenre=Zn;exports.displayAuthorRole=vs;exports.eraRank=Yr;exports.feedbackTransportOf=yd;exports.filtersFromParams=sp;exports.filtersToParams=An;exports.findCatalogPath=wi;exports.firstAuthorText=bo;exports.flattenTitles=Ac;exports.flattenToc=pc;exports.fmtCount=kt;exports.formatHitCount=$n;exports.formatVolumeRange=Yn;exports.groupRelatedWorks=Fu;exports.gujiInlineToPlain=kc;exports.hasActiveFilters=ql;exports.hasGujiMarkdownV02=cb;exports.hasGujiTableNotation=Db;exports.hasSearchOptions=tp;exports.headingKey=no;exports.headingsFromPunct=pd;exports.isCountedChar=Ds;exports.isDuiduChapter=Rn;exports.isLayoutName=Im;exports.isThemeName=Cm;exports.lineageHref=dm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Zc;exports.nestHeadings=hd;exports.normalizeEra=Tt;exports.normalizeLayout=lr;exports.normalizeRole=ws;exports.normalizeTheme=or;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Gi;exports.paginationItems=Fd;exports.parseChineseNumber=In;exports.parseGujiInline=jc;exports.parseGujiTable=Fc;exports.parseHeadingKey=bd;exports.pct=go;exports.periodLevel=Xd;exports.pickReaderVersion=uc;exports.readStoredLayout=ty;exports.readStoredTheme=Q0;exports.readerVersionOptionLabel=Qr;exports.remapPlainOffsets=Xc;exports.removeRecentId=tc;exports.renderFullTextBody=Zb;exports.renderProperNames=Gc;exports.renderReaderInline=Qn;exports.resolveRecentEntry=zs;exports.resourceNote=Kn;exports.resultTabFromParam=hp;exports.resultTabToParam=fp;exports.roleFacets=Dl;exports.rowNo=Tb;exports.sameFilters=op;exports.sanitizeHeadings=cs;exports.saveRecentId=Vr;exports.segmentEntities=Jc;exports.setImageSourceResolver=zf;exports.shelfColumns=Vd;exports.sortFor=ip;exports.sortYear=Mn;exports.spineHeight=qd;exports.splitFullTextTables=Ls;exports.splitHighlightSnippet=gs;exports.splitTableRow=Oc;exports.storeLayout=iy;exports.storeTheme=Em;exports.summaryFromEntry=nd;exports.summaryFromItem=id;exports.timelineLayout=mm;exports.toCatalogWorkCard=v0;exports.transportSummaryLoader=rd;exports.typeSupportsFilters=Xl;exports.useBidUrl=It;exports.useChapterWarpData=ud;exports.useConvert=xt;exports.useEntitySummaryLoader=Zs;exports.useI18n=oe;exports.useReaderPrefs=mc;exports.useRecentEntries=pm;exports.validateLineageGraph=Cu;exports.withDefaultLinks=ii;exports.withMetaLinks=ni;exports.yearText=Bn;
|
|
2120
|
+
`,cm={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ni(e){return{...cm,...e??{}}}function dm(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 mm(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 B0(e){return{read:e.item,work:e.item,node:e.node}}function um({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 pm(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 H0(e,i,n){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?n(r):bm(e.type,i)}function bm(e,i){return i(`metaHome.typeLabel.${e}`)}function hm({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?bm(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:H0(l,r,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function fm(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 gm({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:fm(a.status,n,r)})})]},a.id||a.name)})})]})}):null}function xm({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 ym({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(xm,{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 jm="siku_qige";function D0({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(xm,{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 km({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===jm),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(D0,{group:c,links:o},c.key))})]})}const kl=34,wl=13;function vl(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 W0(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 wm({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}=mm(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-wl):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,wl),{...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*kl+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*kl+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:vl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:W0(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):"",vl(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 U0=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 vm({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:dm(o,a.id),children:[U0,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 Sm({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:fm(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 Sl=["extant","partially_extant","lost","unknown"];function $m({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=Sl.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:Sl.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 _m={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function K0({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=B0(f),y=_m,v=pm(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+lm}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(um,{counts:u.counts,links:i})]}),r&&t.jsx(hm,{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(gm,{rows:u.catalog_progress,links:i}),t.jsx(ym,{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(km,{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(wm,{people:u.bibliographers,links:i})}),w.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(vm,{works:u.lineage,links:i})}),w.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(Sm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx($m,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const Nm=["_related","_catalogs","_collections","_members","_children","_book_groups"],Y0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),bs=e=>Y0(e)&&!!e.h;function G0(e){return e?Nm.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(bs)}):!1}function V0(e,i){const n={...e};if(!i)return n;for(const r of Nm){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 q0(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&&V0(d,G0(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 X0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const J0=({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(()=>q0(i),[i]),ae=b.useMemo(()=>yd(O)??ro(U),[O,U]),ce=s.useT(),{t:Ee,convert:we}=oe(),[ye]=b.useState(()=>{if(!X0(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,J]=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,X]=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;X(!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()||X(!1)}},[O]),nt=b.useRef({initialDetail:n,initialEntry:r});nt.current={initialDetail:n,initialEntry:r},b.useEffect(()=>{let ee=!1;me.current++,X(!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?(J(!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),J(!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){J(!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||J(!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:[Q0(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(Ed,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he}):W.type==="book"?t.jsx(Id,{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(Md,{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(Pd,{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(nc,{data:De,onNavigate:g,renderLink:w})}if(o==="collated"||o==="fulltext")return t.jsx(xd,{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($d,{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(Lc,{left:t.jsxs(t.Fragment,{children:[ct,ct?" · ":"",t.jsx(Z0,{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(_c,{...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(Nc,{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 Z0({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 Q0(e,i){return i?e.workSubtype[i]??i:""}const zm=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],rr="zhusha",sr="bim-theme";function Cm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function or(e){return Cm(e)?e:rr}function ey(){try{return or(window.localStorage.getItem(sr))}catch{return rr}}function Em(e){try{window.localStorage.setItem(sr,e)}catch{}}function Rm(e){const i=or(e);return document.documentElement.setAttribute("data-theme",i),i}function Tm(){return or(document.documentElement.getAttribute("data-theme"))}const ty=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],xo="airy",ar="bim-layout";function Im(e){return e==="airy"||e==="boxed"}function lr(e){return Im(e)?e:xo}function iy(){try{return lr(window.localStorage.getItem(ar))}catch{return xo}}function ny(e){try{window.localStorage.setItem(ar,e)}catch{}}function ry(e){const i=lr(e);return document.documentElement.setAttribute("data-layout",i),i}function sy(){return lr(document.documentElement.getAttribute("data-layout"))}const oy=`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){}`,ay={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},ly=({onChange:e,style:i})=>{const{t:n}=oe(),[r,o]=b.useState(rr);b.useEffect(()=>{o(Tm())},[]);const a=l=>{o(Rm(l)),Em(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:zm.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(ay[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=cu.VARIANT_SUPPLEMENT;exports.BidUrlProvider=mu;exports.BookDetailLayout=J0;exports.BookPage=Id;exports.Breadcrumb=ns;exports.CATALOG_ALL_ID=Gt;exports.CATALOG_CSS=Od;exports.CATALOG_NARROW_QUERY=co;exports.CATALOG_PAGE_SIZE=mo;exports.CATALOG_UNCLASSIFIED_ID=di;exports.CLASSIFICATIONS=qn;exports.CardFoot=nn;exports.CatalogPage=R0;exports.CatalogPager=Kd;exports.CatalogTree=Bd;exports.CheckFilter=vc;exports.Chip=zc;exports.ChipWall=Nb;exports.CollectionCatalog=nc;exports.CollectionPage=Md;exports.DEFAULT_LAYOUT=xo;exports.DEFAULT_META_HOME_LINKS=cm;exports.DEFAULT_READER_PREFS=Rs;exports.DEFAULT_READ_HOME_LINKS=Gd;exports.DEFAULT_THEME=rr;exports.DETAIL_CSS=$c;exports.DYNASTY_GROUPS=Vn;exports.Dash=Ib;exports.DataTable=Cb;exports.DetailFooter=Lc;exports.DetailGrid=Zi;exports.DetailHeader=_c;exports.EMPTY_FILTERS=Gn;exports.ENTITY_TEXT_CSS=Xs;exports.EmptyNote=Bb;exports.EntityMark=Qs;exports.EntityPage=Pd;exports.EntityText=Af;exports.ExpandRow=Mb;exports.ExtLink=Hb;exports.FEEDBACK_FAB_OFFSET_VAR=ds;exports.FILTER_SUPPORT=Vl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=vb;exports.FeedbackButton=qg;exports.FeedbackDialog=jd;exports.FeedbackForm=kd;exports.FeedbackList=Sd;exports.FeedbackTab=$d;exports.FilterChip=Nc;exports.GUJI_MARKDOWN_FIELD=lb;exports.GUJI_TABLE_NOTATION=Pc;exports.GlyphBadge=Ms;exports.GujiInteractiveReader=Tg;exports.GujiTable=Ps;exports.GujiTextViewer=to;exports.GujiWarpCanvas=qs;exports.ImagePanel=Xr;exports.IndexBrowser=vp;exports.IntroGrid=wb;exports.LAYOUTS=ty;exports.LAYOUT_STORAGE_KEY=ar;exports.LOSS_OPTIONS=Gl;exports.LocaleProvider=hu;exports.LocaleToggle=hs;exports.META_HOME_CSS=lm;exports.META_HOME_SECTION_IDS=_m;exports.MetaCatalogTable=gm;exports.MetaCollectionGroups=km;exports.MetaDataLicense=$m;exports.MetaHomeView=K0;exports.MetaLine=vt;exports.MetaLineageCards=vm;exports.MetaOnlineSites=Sm;exports.MetaPeopleTimeline=wm;exports.MetaRecentPanel=hm;exports.MetaRelatedCatalogs=ym;exports.MetaTypeChips=um;exports.ModeIndicator=El;exports.MoreButton=_b;exports.MoreLink=Ts;exports.PAGE_MAX_WIDTH=zn;exports.PERIOD_NARROW_SHARE=Jd;exports.PageFrame=Hi;exports.Quote=Lb;exports.READER_CSS=ac;exports.READ_HOME_CSS=po;exports.READ_HOME_NARROW_QUERY=on;exports.READ_HOME_SECTION_IDS=am;exports.READ_PERIOD_LABELS=A0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Hl;exports.ReadButton=ts;exports.ReadFamousWorks=rm;exports.ReadHomeView=P0;exports.ReadPeriodBand=sm;exports.ReadPicks=em;exports.ReadPieces=om;exports.ReadSection=Rt;exports.ReadShelf=ho;exports.ReadSibu=fo;exports.ReadStats=Qd;exports.ReadTopicGroup=im;exports.ReadTopics=nm;exports.ReaderMdText=Hs;exports.ReaderShell=bc;exports.ReaderToc=lc;exports.RepoSourceLink=fs;exports.ResourceGroup=Pb;exports.ResourceLine=Ob;exports.ResourceList=ju;exports.ResourceRow=Ic;exports.SEARCH_VIEW_STORAGE_KEY=_s;exports.SEVEN_PAVILIONS_KEY=jm;exports.SNIPPET_MARK_END=Nl;exports.SNIPPET_MARK_START=_l;exports.SORTABLE_TYPES=Yl;exports.SearchInput=Tl;exports.SearchResults=ec;exports.Sec=St;exports.SectionHead=Sb;exports.SideList=mi;exports.StripWarpRenderer=rs;exports.SummaryCard=tn;exports.THEMES=zm;exports.THEME_INIT_SCRIPT=oy;exports.THEME_STORAGE_KEY=sr;exports.TabFilter=Qi;exports.TableHead=Eb;exports.TableRow=Rb;exports.TagRow=Mc;exports.TagRows=Fb;exports.TextButton=$b;exports.TextReader=xd;exports.ThemeToggle=ly;exports.TopStrip=is;exports.VersionLineageGraph=Td;exports.VersionLineageList=Rd;exports.VersionLineageView=lo;exports.VolumeChips=zb;exports.VolumeLinks=As;exports.WorkCard=Wd;exports.WorkCardGrid=Yd;exports.WorkCatalog=Ig;exports.WorkPage=Ed;exports.WorkRow=Ud;exports.adaptEntityJson=qc;exports.applyLayout=ry;exports.applyTheme=Rm;exports.authorsLine=nr;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Bs;exports.bucketResources=js;exports.buildCatalogTree=w0;exports.buildCollectionTable=Ul;exports.buildLineageGraph=Sn;exports.buildMeiliFilter=rp;exports.buildParagraphBlocks=Uc;exports.buildVersionRow=ks;exports.buildVersionTable=Bl;exports.canParagraphize=Ln;exports.catalogNodeIdOf=j0;exports.catalogNodeIdsOf=k0;exports.catalogPageCount=_0;exports.catalogTotal=uo;exports.classificationPath=sn;exports.clearAllRecentIds=Ns;exports.compareCatalogCards=$0;exports.computeVersionPartition=Gu;exports.countActiveFilters=Xn;exports.createFeedbackTransport=ro;exports.createTextApi=rc;exports.currentLayout=sy;exports.currentTheme=Tm;exports.defaultEntityHref=od;exports.defaultWorkLink=Hd;exports.deriveDating=Ou;exports.deriveEditionType=Kl;exports.deriveEra=Ji;exports.deriveYear=Un;exports.deriveYearRange=ys;exports.detectGenre=Zn;exports.displayAuthorRole=vs;exports.eraRank=Yr;exports.feedbackTransportOf=yd;exports.filtersFromParams=sp;exports.filtersToParams=An;exports.findCatalogPath=wi;exports.firstAuthorText=bo;exports.flattenTitles=Ac;exports.flattenToc=pc;exports.fmtCount=kt;exports.formatHitCount=$n;exports.formatVolumeRange=Yn;exports.groupRelatedWorks=Fu;exports.gujiInlineToPlain=kc;exports.hasActiveFilters=ql;exports.hasGujiMarkdownV02=cb;exports.hasGujiTableNotation=Db;exports.hasSearchOptions=tp;exports.headingKey=no;exports.headingsFromPunct=pd;exports.isCountedChar=Ds;exports.isDuiduChapter=Rn;exports.isLayoutName=Im;exports.isThemeName=Cm;exports.lineageHref=dm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Zc;exports.nestHeadings=hd;exports.normalizeEra=Tt;exports.normalizeLayout=lr;exports.normalizeRole=ws;exports.normalizeTheme=or;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Gi;exports.paginationItems=Fd;exports.parseChineseNumber=In;exports.parseGujiInline=jc;exports.parseGujiTable=Fc;exports.parseHeadingKey=bd;exports.pct=go;exports.periodLevel=Xd;exports.pickReaderVersion=uc;exports.readStoredLayout=iy;exports.readStoredTheme=ey;exports.readerVersionOptionLabel=Qr;exports.remapPlainOffsets=Xc;exports.removeRecentId=tc;exports.renderFullTextBody=Zb;exports.renderProperNames=Gc;exports.renderReaderInline=Qn;exports.resolveRecentEntry=zs;exports.resourceNote=Kn;exports.resultTabFromParam=hp;exports.resultTabToParam=fp;exports.roleFacets=Dl;exports.rowNo=Tb;exports.sameFilters=op;exports.sanitizeHeadings=cs;exports.saveRecentId=Vr;exports.segmentEntities=Jc;exports.setImageSourceResolver=zf;exports.shelfColumns=Vd;exports.sortFor=ip;exports.sortYear=Mn;exports.spineHeight=qd;exports.splitFullTextTables=Ls;exports.splitHighlightSnippet=gs;exports.splitTableRow=Oc;exports.storeLayout=ny;exports.storeTheme=Em;exports.summaryFromEntry=nd;exports.summaryFromItem=id;exports.timelineLayout=mm;exports.toCatalogWorkCard=S0;exports.transportSummaryLoader=rd;exports.typeSupportsFilters=Xl;exports.useBidUrl=It;exports.useChapterWarpData=ud;exports.useConvert=xt;exports.useEntitySummaryLoader=Zs;exports.useI18n=oe;exports.useReaderPrefs=mc;exports.useRecentEntries=pm;exports.validateLineageGraph=Cu;exports.withDefaultLinks=ii;exports.withMetaLinks=ni;exports.yearText=Bn;
|