book-index-ui 0.46.1 → 0.46.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -859,6 +859,8 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
859
859
  .bim-d-dist-seg[aria-pressed="true"] { outline: 2px solid ${i("ink")}; outline-offset: -2px; }
860
860
  .bim-d-dist-bar:has(.bim-d-dist-seg[aria-pressed="true"]) .bim-d-dist-seg:not([aria-pressed="true"]) { opacity: .35; }
861
861
  .bim-d-sq { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 1px; vertical-align: middle; }
862
+ /* 侧栏卡里的作品简介:不能内联写 margin 简写——会把 boxed 布局给子元素的左右 16px 抹成 0(简介贴边) */
863
+ .bim-d-side-desc { margin: 8px 0 0; }
862
864
  .bim-d-side-note { margin: 8px 0 0; font-size: 12px; color: ${i("aux-fg")}; }
863
865
 
864
866
  /* 提要卡:数字格(版本 / 有影印 / 家著录) */
@@ -1298,7 +1300,7 @@ ${ee}
1298
1300
  ${fe.file}`;Se(null),C.getChapter(e,ee,fe.file,{json:!!fe.has_json}).then(Ae=>{W===te.current&&Se(Ae)}).catch(()=>{W===te.current&&Se(null)}).finally(()=>{W===te.current&&Me(he)})},[C,e,ee,fe]);const ye=(V==null?void 0:V.kind)==="collated",[H,se]=g.useState("");g.useEffect(()=>{se("")},[e,ee]);const ne=g.useMemo(()=>ee&&ye?async W=>{const he=await C.getChapter(e,ee,W,{json:!0});return{juan:(he==null?void 0:he.json)??null,rawText:(he==null?void 0:he.md)??null}}:null,[C,e,ee,ye]),ge=(ie==null?void 0:ie.type)==="kaozhen",Ne=g.useMemo(()=>(ie==null?void 0:ie.chapters.map(W=>W.file))??[],[ie]),{matchStates:Be}=Kh({resetKey:`${e}
1299
1301
  ${ee??""}`,load:ne,files:Ne,activeFile:J??null,activeJuan:(le==null?void 0:le.json)??null,activeRawText:(le==null?void 0:le.md)??null,query:H,isKaozhen:ge}),We=g.useRef(new Map);g.useEffect(()=>{We.current.clear()},[e]);const Ue=g.useMemo(()=>({versionKey:ee,chapter:fe??null}),[ee,fe]),Qe=kh(c,J??null,Ue),{warpData:ce,loading:tt}=cc(y,w,J??null,fe,Ue),E=_g(b,J??null,Ue),[oe,ae]=g.useState(new Set),[je,ke]=g.useState(null),[xe,G]=g.useState(!0),[de,Te]=g.useState(!0),Ee=g.useRef(null),[D,re]=g.useState(1),[Pe,_e]=g.useState(null),Ge=W=>{var Ae;const he=parseInt(((Ae=W==null?void 0:W.page_id)==null?void 0:Ae.split(":")[1])??"",10);return isNaN(he)?null:he},He=W=>{var Ae,Fe;const he=(W==null?void 0:W.pages)??[];return Ge(W)??((Ae=he.find(Ke=>Ke.columns.some(it=>it.chars.length>0)))==null?void 0:Ae.page)??((Fe=he[0])==null?void 0:Fe.page)??1},[De,Tt]=g.useState(()=>He(ce)),Pt=`${e}
1300
1302
  ${ee}
1301
- ${J??""}`,[qt,mn]=g.useState({key:Pt,data:ce,started:!!ce});if(qt.key!==Pt)mn({key:Pt,data:ce,started:!1});else if(ce!==qt.data&&(mn({key:Pt,data:ce,started:!!ce}),ce)){const W=ce.pages??[];(!qt.started||!W.some(he=>he.page===De))&&Tt(He(ce))}g.useEffect(()=>{ae(new Set),ke(null)},[J,ee]);const On=g.useCallback(W=>{if(ae(new Set(W)),W.length>0){const he=W[0],Ae=parseInt(he.split(":")[0],10);isNaN(Ae)||Tt(Ae)}},[]),ft=g.useMemo(()=>{const W=new Map;for(const he of(ce==null?void 0:ce.pages)??[])W.set(he.page,he);return W},[ce]),hn=Ge(ce),Hn=g.useCallback(W=>{var Fe;const he=Qe.images;if(!he||he.length===0)return;const Ae=(Fe=ft.get(W))==null?void 0:Fe.seq;return(Ae?he.find(Ke=>Ke.seq===Ae):void 0)??he.find(Ke=>Ke.pageNo===W)??he[W-1]},[Qe.images,ft]),Ir=D>1.5,Fn=g.useCallback((W,he=!1)=>{const Ae=Hn(W);return Ae?W===hn||he?Ae.hiresUrl??Ae.url:Ae.url:W===hn?(ce==null?void 0:ce.imageUrl)??"":""},[Hn,ce,hn]),Rd=g.useMemo(()=>Fn(De,Ir),[Fn,De,Ir]),gn=g.useMemo(()=>[...ft.keys()].sort((W,he)=>W-he),[ft]),Ei=g.useRef(De);Ei.current=De;const fn=g.useCallback(W=>{var Ke;const he=Ei.current,Ae=gn.indexOf(he),Fe=gn[Ae<0?0:Ae+W];Fe===void 0||Fe===he||(Ei.current=Fe,Tt(Fe),(Ke=ft.get(Fe))!=null&&Ke.columns.some(it=>it.chars.length>0)&&_e(it=>({page:Fe,nonce:((it==null?void 0:it.nonce)??0)+1})))},[gn,ft]),Ii=gn.indexOf(De),Ld=g.useCallback(W=>{if(W.altKey||W.ctrlKey||W.metaKey)return;const he=W.target.tagName;he==="INPUT"||he==="TEXTAREA"||he==="SELECT"||(W.key==="ArrowLeft"||W.key==="PageUp"?(W.preventDefault(),fn(-1)):(W.key==="ArrowRight"||W.key==="PageDown")&&(W.preventDefault(),fn(1)))},[fn]);g.useEffect(()=>{if(ce)for(const W of[1,-1,2,3]){const he=Fn(De+W);he&&yo(he)}},[ce,De,Fn]);const Rr=g.useMemo(()=>{var Dr;if(!ce)return null;if(De===hn)return ce;const W=ft.get(De);if(W&&W.width>0&&W.height>0)return{page_id:`p:${De}`,title:`第${De}葉`,image_size:[W.width,W.height],total_warped_w:W.width,columns:[{col:1,warped_w:W.width,warped_h:W.height,offset_x:0,strips:[],chars:W.columns.flatMap(Ye=>Ye.chars).map(Ye=>({id:Ye.id,char:Ye.char,slot:Ye.slot,pos:Ye.pos,sub:Ye.sub,bbox_col:Ye.bbox??[0,0,0,0]}))}]};const he=(Dr=ce.pages)==null?void 0:Dr.find(Ye=>Ye.page===De),[Ae,Fe]=ce.image_size||[2386,3082],Ke=Hn(De),it=(Ke==null?void 0:Ke.width)??Ae,Mi=(Ke==null?void 0:Ke.height)??Fe,Or=it/Ae,Hr=Mi/Fe,Fr=new Map;for(const Ye of ce.columns){const lt=(Ye.strips||[]).flatMap(Vn=>Vn.srcQuad.map(Gn=>Gn[0]));if(lt.length===0)continue;const kt=Ye.top_y??0,Bi=Ye.bottom_y??kt+Ye.warped_h;Fr.set(Ye.col,{x0:Math.min(...lt),x1:Math.max(...lt),top:kt,slotH:(Bi-kt)/21})}return{page_id:`p:${De}`,title:`第${De}葉`,image_size:[it,Mi],total_warped_w:it,columns:he?he.columns.map(Ye=>{const lt=Fr.get(Ye.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Ye.col,warped_w:it,warped_h:Mi,offset_x:0,strips:[],chars:Ye.chars.map(kt=>{const Bi=kt.slot??kt.pos??0,Vn=(lt.top+(Bi-1)*lt.slotH)*Hr,Gn=(lt.x0+lt.x1)/2,[Fd,Dd]=kt.sub==="a"?[Gn,lt.x1]:kt.sub==="b"?[lt.x0,Gn]:[lt.x0,lt.x1];return{...kt,bbox_col:[Fd*Or,Vn,Dd*Or,Vn+lt.slotH*Hr]}})}}):[]}},[ce,De,hn,ft,Hn]),{entryTitle:Dn,authors:Lr}=Ig(e,n,l===void 0),[Ar,Ri]=g.useState("text");if(g.useEffect(()=>{Ri("text")},[J,ee]),O==="loading")return t.jsx(As,{className:S,style:v,title:l??Dn,label:$("reader.loading")});if(O==="missing"||!N||!V)return t.jsx("div",{className:S,style:{...v,...Ls},children:$("reader.noText")});if(Le==="failed")return t.jsx("div",{className:S,style:{...v,...Ls},children:$("reader.tocFailed")});if(!ie)return t.jsx(As,{className:S,style:v,title:l??Dn,label:$("reader.tocLoading")});const Mt=zg(V,ie),Ad=Tg(ie,Be,Mt,_,ye),Li=N.versions.map(W=>({key:W.key,label:we.textVersionLabel(W),optionLabel:_(we.textVersionLabel(W)),sourceName:W.source_name?_(W.source_name):void 0,license:W.license??void 0,sourceUrl:W.source_url??void 0,primary:W.key===pe})),at=$g((Wr=ie.source)==null?void 0:Wr.upstream),Un=(typeof l=="string"?_(l):l)??(ie.title?_(ie.title):Dn?_(Dn):void 0),Pd=Un?t.jsx("a",{href:z(e),title:$("reader.viewEntry"),onClick:a?W=>{W.metaKey||W.ctrlKey||(W.preventDefault(),a(e))}:void 0,children:Un}):void 0,Md=Lr.length>0?_(Lr.slice(0,2).map(W=>`${W.dynasty?`〔${W.dynasty}〕`:""}${W.name}${` ${W.role||$("reader.defaultRole")}`}`).join("、")):void 0,Ai=fe?dc(fe,Mt,_,ye):void 0,Xt=ye&&!!(le!=null&&le.json),Bt=(le==null?void 0:le.json)??null,Zt=(le==null?void 0:le.md)??null,Pr=Xt&&!ge&&Ql(Bt.sections),Bd=Pr&&!(Zt&&M.readingMode==="paragraph"&&si(Zt)),Wd=Xt&&Pr?t.jsx(qh,{juan:Bt,view:Ar,onView:Ri,textHasEntries:Bd}):void 0,Od=il(ie)||so(ie),Pi=Zt?Zt.replace(/^##\s+[^\n]+\n+/,""):null,Hd=(typeof d=="string"?_(d):d)??(V.source_name?_(V.source_name):_(we.textVersionLabel(V)));return t.jsxs(bl,{className:S,style:v,title:Pd,subtitle:Hd,byline:Md,current:Ai,pagerUnit:Mt,rail:Wd,revisedAt:f,backHref:x,backLabel:k,onReportError:h?W=>h({...W,bookTitle:typeof Un=="string"?Un:void 0,entryId:e}):void 0,workLinkToggle:Xt&&!ge&&!!a&&!!(Bt!=null&&Bt.sections.some(W=>W.work_id)),toc:Ad,tocCaption:$("reader.tocCaption",{n:ie.chapters.length,unit:_(Mt)}),tocHeader:ye&&ie.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:ge?$("reader.searchChaptersPlaceholder"):$("reader.searchUnitPlaceholder",{unit:_(Mt)}),"aria-label":ge?$("reader.searchChapters"):$("reader.searchUnit",{unit:_(Mt)}),value:H,onChange:W=>se(W.target.value)}):void 0,activeKey:J??null,onSelect:ve,images:Qe.images,imagesLoading:Qe.loading||tt,renderImageOverlay:p,imagePanel:ce?"open":u,isWarpMode:!!ce,customImagePanel:ce&&Rr?t.jsxs("div",{className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Ld,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:i("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",disabled:Ii<=0,onClick:()=>fn(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":De,style:{fontSize:11,padding:"1px 6px",background:i("rule"),borderRadius:10},children:["第 ",De," 葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",disabled:Ii<0||Ii>=gn.length-1,onClick:()=>fn(1),children:"›"})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[oe.size>0&&t.jsxs("button",{type:"button",onClick:()=>ae(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${i("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",oe.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:D<=1,onClick:()=>{var W;return(W=Ee.current)==null?void 0:W.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(D*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:D>=6,onClick:()=>{var W;return(W=Ee.current)==null?void 0:W.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:D===1,onClick:()=>{var W;return(W=Ee.current)==null?void 0:W.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(Sg,{ref:Ee,resetKey:De,onScaleChange:re,style:{flex:1,minHeight:0},children:t.jsx(dr,{imageUrl:Rd,pageData:Rr,selectedCharIds:oe,hoveredCharId:je,preserveMargins:de,onCharClick:W=>{ae(Ae=>{const Fe=new Set(Ae);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const he=document.querySelector(`[data-char-id="${W}"]`);he&&he.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:ke})}),t.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"8px 0 2px"},children:t.jsxs("div",{style:{display:"inline-flex",border:`1px solid ${i("rule")}`,borderRadius:4,overflow:"hidden"},children:[t.jsx("button",{type:"button",onClick:()=>Te(!1),"aria-pressed":!de,className:`bim-rd-t ${de?"":"bim-rd-on"}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:de?"transparent":i("accent-bg"),color:de?"inherit":i("accent")},title:"去空白:紧凑裁切版心",children:"去空白"}),t.jsx("button",{type:"button",onClick:()=>Te(!0),"aria-pressed":de,className:`bim-rd-t ${de?"bim-rd-on":""}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:de?i("accent-bg"):"transparent",color:de?i("accent"):"inherit"},title:"保留空白:完整呈现古籍天头地脚与白边",children:"保留空白"})]})})]}):void 0,toolbarExtra:ce?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-badge-warp",children:"图文对读"}),t.jsx("button",{type:"button",className:`bim-rd-t ${xe?"bim-rd-on":""}`,"aria-pressed":xe,title:"切换外挂现代断句标点",onClick:()=>G(W=>!W),children:xe?"标点":"无标点"})]}):void 0,prefs:M,onPrefsChange:T,versions:Li.length>1?Li:void 0,currentVersionKey:Li.length>1?V.key:void 0,onVersionChange:Y,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:si(Zt),allowVertical:m,children:[B&&t.jsx(Yt,{}),!B&&ce&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:fe!=null&&fe.title?_(fe.title):Ai}),(V.source_name||V.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[V.source_name&&_(V.source_name),V.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),V.license]})]})]}),t.jsx(gr,{pageData:ce,pages:ce.pages,punctuations:ce.punctuations||[],selectedCharIds:oe,hoveredCharId:je,onSelectionChange:On,onCharClick:W=>{ae(Ae=>{const Fe=new Set(Ae);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const he=parseInt(W.split(":")[0],10);isNaN(he)||Tt(he)},onCharHover:ke,mode:"horizontal",showPunctuation:xe,entities:M.properNames?E:void 0,entityTransport:n,onEntityNavigate:j,onVisiblePageChange:W=>Tt(W),convert:_,scrollToPage:Pe})]}),!B&&!ce&&Xt&&Bt&&t.jsx(Yh,{juan:Bt,rawText:Zt,positionLabel:Ng(fe,ie,Mt,_),groupLabel:Eg(ie,J??null),index:Cg(e,ie),searchQuery:H,onNavigate:a,transport:n,workLabelCache:We,prefs:M,view:Ar,onViewChange:Ri},`${ee}/${J}`),!B&&!ce&&!Xt&&Pi!=null&&fe&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:fe.title?_(fe.title):Ai}),(V.source_name||V.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[V.source_name&&t.jsxs(t.Fragment,{children:[$("reader.textSource")," ",V.source_url?t.jsx("a",{className:"bim-rd-link",href:V.source_url,target:"_blank",rel:"noreferrer",children:_(V.source_name)}):_(V.source_name)]}),V.source_name&&V.license&&t.jsx("span",{className:"bim-rd-dot"}),V.license]}),at&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[$("reader.upstream")," ",at.url?t.jsx("a",{className:"bim-rd-link",href:at.url,target:"_blank",rel:"noreferrer",children:_(at.name??at.url)}):_(at.name??""),at.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),at.license_url?t.jsx("a",{className:"bim-rd-link",href:at.license_url,target:"_blank",rel:"noreferrer",children:at.license}):at.license]}),at.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(al,{text:at.note,convert:_})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(ir,{text:Pi,mode:M.readingMode,tables:Od,gujiMarkdown:so(ie),properNames:M.properNames})})]}),!B&&!ce&&!Xt&&Pi==null&&fe&&t.jsx("div",{className:"bim-rd-state",children:$("reader.chapterFailed")}),ie.references&&ie.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:$("reader.references")}),t.jsx("ol",{children:ie.references.map((W,he)=>t.jsxs("li",{children:[W.url?t.jsx("a",{className:"bim-rd-link",href:W.url,target:"_blank",rel:"noopener noreferrer",children:_(W.title)}):t.jsx("span",{children:_(W.title)}),W.author&&t.jsxs("span",{children:[",",_(W.author)]}),W.note&&t.jsxs("span",{children:["。",_(W.note)]})]},he))})]})]})};function Ng(e,n,o,r){var a,l;if(!e)return;const s=(l=(a=n.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(s?`${s}冊`:`${o}${e.n}`)}function Eg(e,n){if(!n)return;const o=r=>{var s;for(const a of r??[]){const l=o(a.children);if(l)return l;if((s=a.files)!=null&&s.includes(n))return a.label}};return o(e.juan_groups)}function Ig(e,n,o){const[r,s]=g.useState({entryTitle:void 0,authors:[]});return g.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let a=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);s({entryTitle:o&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,n,o]),r}const pc={bug:{key:"bug",color:i("danger")},resource:{key:"resource",color:i("primary")},suggestion:{key:"suggestion",color:i("primary")},other:{key:"other",color:i("desc-fg")}},Rg=pc.other,uc={pending:{key:"pending",color:i("warning")},in_progress:{key:"in_progress",color:i("primary")},resolved:{key:"resolved",color:i("success")},wontfix:{key:"wontfix",color:i("desc-fg")},duplicate:{key:"duplicate",color:i("desc-fg")}},Lg=uc.pending;function Ag(e){try{const n=new Date(e),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return e}}function Pg(e,n){if(!e)return!1;try{const o=new URL(e,n);if(o.protocol!=="http:"&&o.protocol!=="https:")return!1;const r=new URL(n);return o.hostname===r.hostname}catch{return!1}}const br=({items:e,loading:n})=>{const o=Xe(),{t:r,convert:s}=Q();return n?t.jsx(Yt,{}):e.length===0?t.jsx("div",{style:Mg,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=pc[a.type]||Rg,d=uc[a.status]||Lg,c=typeof window<"u"&&Pg(a.pageUrl,window.location.href);return t.jsxs("div",{style:Bg,children:[t.jsxs("div",{style:Wg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ms,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Ms,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Og,children:Ag(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Hg,children:[a.resourceId&&t.jsx("a",{href:o(a.resourceId),style:qi,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:qi,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:qi,children:a.pageUrl}))]}),t.jsx("div",{style:Fg,children:s(a.content)}),a.reply&&t.jsxs("div",{style:Dg,children:[t.jsx("div",{style:Ug,children:r("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},Mg={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Bg={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Wg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ms={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Og={fontSize:"12px",color:i("desc-fg")},Hg={fontSize:"12px",marginBottom:"6px"},qi={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Fg={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},Dg={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Ug={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},vo=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:a})=>{const l=$e(),[d,c]=g.useState(null),[p,u]=g.useState([]),[m,h]=g.useState("recommend"),[f,x]=g.useState([]),[k,y]=g.useState(!1),w=r??m,b=O=>{h(O),s==null||s(O)},[j,S]=g.useState(!0),[v,$]=g.useState(null),[_,C]=g.useState(null),[M,T]=g.useState(null);g.useEffect(()=>{let O=!1;if(e.getCounts)return e.getCounts().then(I=>{O||c({works:I.works,books:I.books,collections:I.collections})}).catch(()=>{}),()=>{O=!0}},[e]),g.useEffect(()=>{let O=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const P=await e.getRecommended();if(P!=null&&P.groups)return P.groups.flatMap(U=>U.items.map(K=>({...K,group:U.name})))}catch{}return[]})().then(async P=>{if(O)return;const U=P.filter(L=>L.id);if(U.length===0){S(!1);return}const K=await Promise.all(U.map(async L=>{if(L.type)return{id:L.id,title:L.title,type:L.type,author:L.author,dynasty:L.dynasty,role:L.role,edition:L.edition,has_text:L.has_text,has_image:L.has_image,has_collated:L.has_collated,subtype:L.subtype,primary_name:L.primary_name,group:L.group,fallbackDescription:L.description};try{let Z=null;if(e.getEntry)Z=await e.getEntry(L.id);else{const A=await e.getItem(L.id);A&&(Z={id:L.id,title:A.title||L.id,type:A.type||"work"})}if(Z)return{...Z,group:L.group,fallbackDescription:L.description}}catch{}return{id:L.id,title:L.title,type:we.extractType(L.id),group:L.group,fallbackDescription:L.description}}));O||(u(K.filter(L=>L!==null)),S(!1))}),()=>{O=!0}},[e,o]);const z=g.useRef(!1),F=g.useRef(!1),N=g.useRef(!1);g.useEffect(()=>{if(w!=="catalog"||z.current)return;const O=e.getCatalogProgress??e.getResourceProgress;if(!O)return;z.current=!0;let I=!1;return O.call(e).then(P=>{I||$(P)}).catch(()=>{z.current=!1}),()=>{I=!0}},[e,w]),g.useEffect(()=>{if(w!=="collection"||F.current||!e.getCollectionProgress)return;F.current=!0;let O=!1;return e.getCollectionProgress().then(I=>{O||C(I)}).catch(()=>{F.current=!1}),()=>{O=!0}},[e,w]),g.useEffect(()=>{if(w!=="site"||N.current||!e.getSiteProgress)return;N.current=!0;let O=!1;return e.getSiteProgress().then(I=>{O||T(I)}).catch(()=>{N.current=!1}),()=>{O=!0}},[e,w]),g.useEffect(()=>{if(!a||w!=="feedback")return;let O=!1;return y(!0),fetch(a).then(I=>I.json()).then(I=>{!O&&I.success&&x(I.items||[])}).catch(()=>{}).finally(()=>{O||y(!1)}),()=>{O=!0}},[a,w]);const R=O=>t.jsx(un,{type:O,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[t.jsx(kn,{label:l.home.recommendTab,active:w==="recommend",onClick:()=>b("recommend")}),t.jsx(kn,{label:l.home.catalogTab,active:w==="catalog",onClick:()=>b("catalog")}),t.jsx(kn,{label:l.home.collectionTab,active:w==="collection",onClick:()=>b("collection")}),t.jsx(kn,{label:l.home.siteTab,active:w==="site",onClick:()=>b("site")}),a&&t.jsx(kn,{label:l.home.feedbackTab,active:w==="feedback",onClick:()=>b("feedback")})]}),w==="recommend"&&t.jsx(Vg,{recommended:p,loading:j,onNavigate:n,getIcon:R,t:l}),w==="catalog"&&t.jsx(Bs,{progress:v,t:l,onNavigate:n}),w==="collection"&&t.jsx(Bs,{progress:_,t:l,onNavigate:n}),w==="site"&&t.jsx(Yg,{progress:M,t:l,totalWorks:(d==null?void 0:d.works)??0}),w==="feedback"&&a&&t.jsx(br,{items:f,loading:k})]})})},kn=({label:e,active:n,onClick:o})=>t.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),Vg=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const a=Xe();if(n)return t.jsx(Yt,{});if(e.length===0)return null;const l=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(l.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(p=>{const u=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return t.jsxs("a",{href:a(p.id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o==null||o(p.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(p.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[p.title,p.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:p.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},p.id)})})]},d))})},Bs=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(Yt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],a={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(p=>p.status===d);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[d]}}),a[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(p=>t.jsx(Gg,{item:p,t:n,statusColor:l[d],onNavigate:o},p.id))})]},d)})})},Gg=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Xe(),a=e.total>0?Math.round(e.imported/e.total*100):0,l=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const d=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:p=>p.currentTarget.style.borderBottomStyle="solid",onMouseLeave:p=>p.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:l})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?pt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${a}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},Yg=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(Yt,{});const r=[...e.resources].sort((c,p)=>c.priority-p.priority),s=r.filter(c=>c.imported>0),a=r.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),d=o>0?Math.round(l/o*100):0;return t.jsxs("div",{children:[o>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:l.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Ws,{item:c,t:n,totalWorks:o},c.id))})]}),a.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(Ws,{item:c,t:n,totalWorks:o},c.id))})]})]})},Ws=({item:e,t:n,totalWorks:o})=>{const r=o>0?Math.round(e.imported/o*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&o>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},Os="(max-width: 768px)";function Kg(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(Os).matches);return g.useEffect(()=>{const o=window.matchMedia(Os),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const qg=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var F;const a=$e(),{convert:l}=Ie(),d=Kg(),[c,p]=g.useState(null),[u,m]=g.useState(null),[h,f]=g.useState(!1),[x,k]=g.useState("detail"),[y,w]=g.useState([]),[b,j]=g.useState(!1),S=g.useCallback(async N=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){w([]);return}j(!0);try{if(e.getCollectionCatalogs){const R=await e.getCollectionCatalogs(N);w(R||[])}else if(e.getCollectionCatalog){const R=await e.getCollectionCatalog(N);w(R?[{resource_id:"",data:R}]:[])}}catch{w([])}finally{j(!1)}},[e]),v=g.useCallback(async N=>{if(o){o(N);return}p(N),m(null),w([]),k("detail"),f(!0);try{const R=await e.getItem(N.id);R&&(m(R),R.type==="collection"&&S(N.id))}catch(R){console.error("加载详情失败:",R)}finally{f(!1)}},[e,o,S]),$=g.useCallback(async N=>{m(null),w([]),k("detail"),f(!0);try{const R=await e.getItem(N);R&&(m(R),p({id:N,title:R.title||N,type:R.type||"book"}),R.type==="collection"&&S(N))}catch(R){console.error("导航失败:",R)}finally{f(!1)}},[e,S]),_=typeof(u==null?void 0:u.text_count)=="number"&&u.text_count>0,C=(u==null?void 0:u.type)==="collection"&&(y.length>0||b)||(u==null?void 0:u.type)==="work"&&_,M=d&&(h||u),T=g.useCallback(()=>{p(null),m(null),w([]),k("detail")},[]),z=t.jsx(t.Fragment,{children:h?t.jsx(Yt,{}):u?t.jsxs(t.Fragment,{children:[(C||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:d?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[C&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:Zn(x==="detail"),children:a.detailTab.basicInfo}),u.type==="collection"&&b&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:Zn(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(N=>t.jsx("button",{onClick:()=>k(`catalog:${N.resource_id}`),style:Zn(x===`catalog:${N.resource_id}`),children:N.short_name?`${l(N.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},N.resource_id)),u.type==="work"&&_&&t.jsx("button",{onClick:()=>k("collated"),style:Zn(x==="collated"),children:a.detailTab.collatedEdition})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:x==="detail"?t.jsx(Bo,{data:u,transport:e,onNavigate:$}):x.startsWith("catalog:")?t.jsx(Wo,{data:(F=y.find(N=>`catalog:${N.resource_id}`===x))==null?void 0:F.data,onNavigate:$}):x==="collated"?t.jsx(xr,{id:u.id,transport:e,onNavigate:$}):null})]}):t.jsx(vo,{transport:e,onNavigate:$,recommendedIds:r})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:T,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",a.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:z})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(ro,{transport:e,onEntryClick:v,hideModeIndicator:n}),!u&&t.jsx(vo,{transport:e,onNavigate:$,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(ro,{transport:e,onEntryClick:v,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:z})]})};function Zn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}const Xg=({pageData:e,rawImageUrl:n="",punctuations:o=[],title:r,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=g.useState(new Set),[u,m]=g.useState(null),[h,f]=g.useState("horizontal"),[x,k]=g.useState(!0),y=g.useRef(null),w=g.useCallback(v=>{p(new Set(v))},[]),b=g.useCallback(v=>{if(p($=>{const _=new Set($);return _.has(v)?_.delete(v):(_.clear(),_.add(v)),_}),y.current){const $=y.current.querySelector(`[data-char-id="${v}"]`);$&&$.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var v;p(new Set),window.getSelection&&((v=window.getSelection())==null||v.removeAllRanges())},S=o.length>0?o: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}),s&&t.jsx("span",{style:{fontSize:"0.85rem",color:i("meta-fg")},children:s}),t.jsx("span",{className:"guji-reader-tag",children:"WebGL 客户端透视矫正对读"})]}),t.jsxs("div",{className:"guji-reader-actions",children:[t.jsxs("span",{style:{fontSize:"0.85rem",color:i("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:i("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:()=>k(v=>!v),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f(v=>v==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:h==="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(dr,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:u,onCharClick:b,onCharHover:m})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:y,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:h==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(gr,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:u,onSelectionChange:w,onCharClick:b,onCharHover:m,mode:h,showPunctuation:x})]})]})]})},Zg=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function Qt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Jg(e){var r,s,a,l,d,c;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return[];const o=[];for(const p of n){if(!p||typeof p!="object")continue;const u=p,m=Qt((r=u.page)==null?void 0:r.index),h=Array.isArray(u.cells)?u.cells:[];if(m===void 0||h.length===0)continue;const f=new Map;for(const x of h){if(!x||typeof x!="object")continue;const k=x,y=Zg.exec(String(k.a??""));if(!y||typeof k.c!="string")continue;const w=parseInt(y[2],10),b=parseInt(y[3],10),j=Array.isArray(k.box)&&k.box.length===4&&k.box.every($=>Qt($)!==void 0)?k.box:null,S={id:String(k.a),char:k.c,slot:b,pos:b,sub:y[4]||null,bbox:j?[j[0],j[1],j[0]+j[2],j[1]+j[3]]:null};let v=f.get(w);v||f.set(w,v=[]),v.push(S)}o.push({page:m,seq:String(((s=u.canvas)==null?void 0:s.seq)??""),width:Qt((a=u.canvas)==null?void 0:a.width)??Qt((l=u.image)==null?void 0:l.width)??0,height:Qt((d=u.canvas)==null?void 0:d.height)??Qt((c=u.image)==null?void 0:c.height)??0,columns:Array.from(f.entries()).sort((x,k)=>x[0]-k[0]).map(([x,k])=>({col:x,chars:k}))})}return o}function Qg(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.punctuations)?e.punctuations:[],o=[];for(const r of n){if(!r||typeof r!="object")continue;const s=r;typeof s.anchor!="string"||typeof s.mark!="string"||o.push({id:typeof s.id=="string"?s.id:void 0,anchor:s.anchor,mark:s.mark,kind:s.kind,pos:s.pos,pre_char:s.pre_char})}return o}function ef(e){var o;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return null;for(const r of n){const s=/\/iiif\/([^/]+)\/canvas\/([^/]+)\//.exec(String(((o=r==null?void 0:r.canvas)==null?void 0:o.id)??""));if(s)return{bookId:s[1],vol:s[2]}}return null}const tf=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function mt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Hs(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(o=>!!o&&typeof o=="object"):[]}function nf(e,n){var l,d,c,p,u,m,h,f,x,k;const o=new Map,r=new Map;for(const y of Hs(n)){const w=mt(y.page);if(w!==void 0){o.set(w,y);for(const b of Array.isArray(y.cells)?y.cells:[]){const j=b==null?void 0:b.box;typeof(b==null?void 0:b.a)=="string"&&Array.isArray(j)&&j.length===4&&j.every(S=>mt(S)!==void 0)&&r.set(b.a,[j[0],j[1],j[0]+j[2],j[1]+j[3]])}}}const s=[];for(const y of Hs(e)){const w=mt(y.page);if(w===void 0)continue;const b=[];for(const S of Array.isArray(y.columns)?y.columns:[]){const v=mt(S==null?void 0:S.col);if(v===void 0)continue;const $=[];for(const _ of Array.isArray(S.cells)?S.cells:[]){const C=tf.exec(String((_==null?void 0:_.a)??""));if(!C||typeof _.c!="string")continue;const M=parseInt(C[3],10);$.push({id:_.a,char:_.c,slot:M,pos:M,sub:C[4]||null,bbox:r.get(_.a)??null})}$.length>0&&b.push({col:v,chars:$})}if(b.length===0)continue;b.sort((S,v)=>S.col-v.col);const j=o.get(w);s.push({page:w,seq:String(((l=j==null?void 0:j.canvas)==null?void 0:l.seq)??""),width:mt((d=j==null?void 0:j.canvas)==null?void 0:d.width)??mt((c=j==null?void 0:j.image)==null?void 0:c.width)??0,height:mt((p=j==null?void 0:j.canvas)==null?void 0:p.height)??mt((u=j==null?void 0:j.image)==null?void 0:u.height)??0,columns:b})}const a=new Set(s.map(y=>y.page));for(const[y,w]of o){const b=(m=w==null?void 0:w.canvas)==null?void 0:m.seq;a.has(y)||typeof b!="string"&&typeof b!="number"||String(b)===""||s.push({page:y,seq:String(b),width:mt((h=w.canvas)==null?void 0:h.width)??mt((f=w.image)==null?void 0:f.width)??0,height:mt((x=w.canvas)==null?void 0:x.height)??mt((k=w.image)==null?void 0:k.height)??0,columns:[]})}return s.sort((y,w)=>y.page-w.page)}const of=({data:e,onNavigate:n,className:o,style:r})=>{var u;const{t:s,convert:a}=Q(),[l,d]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,p]=g.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s("catalog.totalVolumes")," ",t.jsx("strong",{children:e.total_volumes})," ",s("unit.juan")]}),e.stats.zhulu!=null&&t.jsxs("span",{children:[s("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",s("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[s("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",s("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:s("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(m=>t.jsx(rf,{division:m,expanded:l===m.name,onToggle:()=>d(l===m.name?null:m.name),expandedCat:c,onCatToggle:h=>p(c===h?null:h),onNavigate:n},m.name))})]})},rf=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=Q(),c=e.categories.reduce((p,u)=>{const m=u.stats||{zhulu:0,cunmu:0};return p+(m.zhulu||0)+(m.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(p=>{const u=`${e.name}/${p.name}`;return t.jsx(sf,{category:p,expanded:r===u,onToggle:()=>s(u),onNavigate:a},p.name)})})]})},sf=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var p,u,m,h;const{t:s,convert:a}=Q(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((u=e.books)==null?void 0:u.cunmu)||[],c=(((m=e.stats)==null?void 0:m.zhulu)||l.length)+(((h=e.stats)==null?void 0:h.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:s("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[s("catalogPage.booksN",{n:c})," ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Fs,{label:s("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(Fs,{label:s("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},Fs=({label:e,books:n,onNavigate:o})=>{const{t:r,convert:s}=Q(),a=Xe(),[l,d]=g.useState(n.length<=20),c=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((p,u)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:i("fg")},children:p.work_id&&o?t.jsx("a",{href:a(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o(p.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:s(p.title)}):s(p.title)}),p.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.volumes)}),p.author&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.author).slice(0,20)})]},u))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:n.length})})]})},xt=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const a=$e();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&t.jsx("button",{onClick:o,style:lf,children:"AI"}),n&&t.jsx("button",{onClick:n,style:af,children:a.action.save})]})]}),s]})},af={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},lf={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},dt=({label:e,value:n,onChange:o,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:a=>o(a.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),Ut=({value:e,onChange:n,placeholder:o})=>{const r=g.useRef(null);return g.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},li=({children:e,color:n,style:o})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...o},children:e});function cf(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const ti=({value:e,onChange:n,label:o})=>{const[r,s]=g.useState(!1),a=g.useRef(null),l=cf(e||"");return g.useEffect(()=>{r&&a.current&&a.current.focus()},[r]),!r&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ds,children:o}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:l.name}),t.jsx(li,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ds,children:o}),t.jsx("input",{ref:a,type:"text",value:e||"",onChange:d=>n(d.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Ds={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function df(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function pf(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const mc=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=$e(),[s,a]=g.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=m=>{n(e.filter((h,f)=>f!==m)),s===m&&a(null)},c=(m,h,f)=>{const x=[...e];x[m]={...x[m],[h]:f},n(x)},p=(m,h)=>{const f=[...e];f[m]={...f[m],type:h,id:"",name:""},n(f),h==="bookID"&&o&&o(x=>{const k=[...e];k[m]={...k[m],id:x.id,name:x.title,type:"bookID"},n(k)})},u=m=>{o&&o(h=>{const f=[...e];f[m]={...f[m],id:h.id,name:h.title,type:"bookID"},n(f)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,h)=>t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(s===h?null:h),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===h?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:m.name||`${r.editor.sourcePlaceholder} ${h+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:df(m.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:pf(m.type)}),t.jsx("button",{onClick:f=>{f.stopPropagation(),d(h)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===h&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!m.type&&t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Us,borderColor:i("source-bookid"),color:i("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>p(h,"url"),style:{...Us,borderColor:i("source-url"),color:i("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),m.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:wt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:Vs,children:r.action.changeType})]}),m.id&&m.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:m.name}),t.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:m.id})]}),t.jsx("button",{onClick:()=>u(h),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(h),style:{width:"100%",padding:"14px",border:`2px dashed ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),m.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:wt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:Vs,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:f=>c(h,"name",f.target.value),placeholder:r.editor.sourceNamePlaceholder,style:en})]}),t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:f=>c(h,"id",f.target.value),placeholder:"https://...",style:en})]})]}),m.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...wt,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:f=>c(h,"details",f.target.value),placeholder:r.editor.detailsPlaceholder,style:en})]}),t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:f=>c(h,"position",f.target.value),placeholder:"如: 卷三, p.52",style:en})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:f=>c(h,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:en})]}),t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:f=>c(h,"processor_version",f.target.value),placeholder:"如: v0.1",style:en})]})]})]})]})})]},h)),t.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},wt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},en={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Us={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Vs={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function hc(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function gc(e){return!e||e.length===0?"":JSON.stringify(e)}const fc=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:u,onLinkEntity:m,onUnlinkEntity:h,onViewEntity:f,onCreateAndLink:x,onSaveRelations:k})=>{const y=$e();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:y.section.relations})]}),k&&t.jsx("button",{onClick:k,style:uf,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(wn,{direction:"up",title:y.relation.belongsToWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(wn,{direction:"up",title:y.relation.containedInCollection,entity:l,onView:f,onUnlink:()=>h("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),a&&u&&u.length>0&&t.jsx(tn,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:f,onAdd:()=>x("siblingBook","book",{workId:a.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(wn,{direction:"up",title:y.relation.parentWork,entity:r,onView:f,onUnlink:()=>h("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>x("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),d&&d.length>0&&t.jsx(tn,{direction:"down",title:`${y.relation.childWorks} (${d.length})`,entities:d,onView:f,onAdd:()=>x("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),c&&c.length>0&&t.jsx(tn,{direction:"down",title:`${y.relation.collectionImpl} (${c.length})`,entities:c,onView:f,onAdd:()=>x("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(tn,{direction:"down",title:`${y.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(wn,{direction:"up",title:y.relation.correspondingWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(wn,{direction:"up",title:y.relation.parentCollection,entity:s,onView:f,onUnlink:()=>h("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>x("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(tn,{direction:"down",title:`${y.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:f,onAdd:()=>x("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(tn,{direction:"down",title:`${y.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},wn=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:u,unlinkLabel:m})=>{const h=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),o?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:xc(o.type)}),t.jsx("span",{style:{fontWeight:500},children:o.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Gs,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(Gs,{onClick:s,title:m,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ko,{onClick:a,children:d}),t.jsx(ko,{onClick:l,primary:!0,children:c})]})]})},tn=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=g.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",h=c?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(f=>t.jsxs("div",{onClick:()=>r(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:xc(f.type)}),t.jsx("span",{children:f.title})]},f.id)),o.length>5&&!c&&t.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[d," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:l}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ko,{onClick:s,primary:!0,children:["+ ",a]})})]})},Gs=({onClick:e,title:n,danger:o,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?i("danger"):"inherit",opacity:.7},children:r}),ko=({onClick:e,primary:n,children:o})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:o});function xc(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const uf={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},bc=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[u,m]=g.useState(""),h=p?l.filter(y=>y.id!==p):l;g.useEffect(()=>{e&&(m(""),d(""))},[e]);const f=y=>{m(y),d(y)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:mf,children:t.jsxs("div",{style:hf,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),t.jsx("button",{onClick:s,style:gf,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:y=>f(y.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:ff})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Xi,children:"搜索中..."}):h.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(y=>t.jsxs("div",{onClick:()=>r(y),style:xf,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?t.jsxs("div",{style:Xi,children:["未找到匹配的",x]}):t.jsxs("div",{style:Xi,children:["输入关键词搜索",x]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:a,style:bf,children:["创建新",x,"并关联"]})]})]})})},mf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},hf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},gf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},ff={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},xf={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},Xi={padding:"20px",textAlign:"center",color:i("desc-fg")},bf={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Ys={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},yf={work:"📜",book:"📖",collection:"📚",entity:"👤"},yc=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:a})=>{const[l,d]=g.useState(""),c=g.useRef(null);g.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var h,f;(h=c.current)==null||h.focus(),(f=c.current)==null||f.select()},100))},[e,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&l.trim()?u():h.key==="Escape"&&a()},u=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!e)return null;const m=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Ys[n]}`}};return t.jsx("div",{style:jf,onClick:h=>{h.target===h.currentTarget&&a()},children:t.jsxs("div",{style:vf,onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:yf[n]}),t.jsx("span",{children:m()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:l,onChange:h=>d(h.target.value),onKeyDown:p,placeholder:`请输入${Ys[n]}名称...`,style:kf})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:a,style:wf,children:"取消"}),t.jsx("button",{onClick:u,disabled:!l.trim(),style:{...Sf,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},jf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},vf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},kf={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},wf={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Sf={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function _f(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function jc(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function $f(e){switch(e){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const vc=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:u})=>{const[m,h]=g.useState(""),[f,x]=g.useState([]),[k,y]=g.useState(!1),[w,b]=g.useState("recent");g.useEffect(()=>{e&&(h(""),x([]),b(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!m.trim()){x([]);return}const C=setTimeout(async()=>{y(!0);try{x(await u(m,o))}catch{x([])}finally{y(!1)}},300);return()=>clearTimeout(C)},[m,o,u]);const j=g.useCallback(C=>{h(C.target.value),C.target.value.trim()&&b("search")},[]),S=g.useCallback(C=>s?C.filter(M=>M.id!==s):C,[s]);if(!e)return null;const v=n||(o==="all"?"选择实体":`选择${jc(o)}`),$=S(r),_=S(f);return t.jsx("div",{style:zf,children:t.jsxs("div",{style:Tf,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Nf,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:m,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ef}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs(Ks,{active:w==="recent",onClick:()=>b("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs(Ks,{active:w==="search",onClick:()=>b("search"),children:["搜索结果 ",_.length>0&&`(${_.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:w==="recent"&&$.length>0?t.jsx(qs,{entities:$,onSelect:d}):m.trim()?k?t.jsx(Zi,{message:"搜索中..."}):_.length>0?t.jsx(qs,{entities:_,onSelect:d}):t.jsx(Zi,{message:"未找到匹配的结果"}):t.jsx(Zi,{message:"输入关键词开始搜索"})}),a&&p&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:p,style:If,children:l||"创建新实体"})]})]})})},Ks=({active:e,onClick:n,children:o})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:o}),qs=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Cf,{entity:o,onClick:()=>n(o)},o.id))}),Cf=({entity:e,onClick:n})=>{const[o,r]=g.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:_f(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:i("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:$f(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:jc(e.type)})]})},Zi=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),zf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Tf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Nf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Ef={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},If={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Rf={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Lf={work:"📜",collection:"📚",book:"📖",entity:"👤"},kc=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:u,relations:m,onRelationsChange:h})=>{var Se;const f=$e(),[x,k]=g.useState(!1),[y,w]=g.useState("work"),[b,j]=g.useState(""),[S,v]=g.useState(""),[$,_]=g.useState([]),[C,M]=g.useState(!1),[T,z]=g.useState(!1),[F,N]=g.useState("work"),[R,O]=g.useState(""),[I,P]=g.useState(),[U,K]=g.useState(!1),[L,Z]=g.useState(null),[A,V]=g.useState([]);g.useRef(null);const pe=e.type,ee=pe==="work",ue=pe==="collection",me=pe==="book",be=g.useCallback((X,Ce)=>{n({...e,[X]:Ce})},[e,n]),Oe=g.useCallback((X,Ce)=>{j(X),w(Ce),v(f.editor.selectToLink+f.indexType[Ce]),_([]),k(!0)},[f]),ie=g.useCallback(X=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,X)},[r,e.id]),Re=g.useCallback(X=>{s==null||s(X.id,X.type)},[s]),Le=g.useCallback((X,Ce,Me)=>{const B={...Me,author:(Me==null?void 0:Me.author)||e.author,dynasty:Me==null?void 0:Me.dynasty};N(Ce),O(X),P(B),z(!0)},[e.author]),q=g.useCallback((X,Ce)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,R,{type:F,title:X,inheritData:Ce}),z(!1)},[r,e.id,R,F]),J=g.useCallback(X=>{if(!X.trim()){_([]);return}M(!0),r!=null&&r.searchEntities&&r.searchEntities(X,y).then(Ce=>{_(Ce),M(!1)}).catch(()=>{_([]),M(!1)})},[r,y]),fe=g.useCallback(X=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,b,X.id),k(!1)},[r,e.id,b]),ze=g.useCallback(()=>{o()},[o]),Y=g.useCallback(X=>{Z(()=>X),K(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(V).catch(()=>{})},[r]),ve=g.useCallback((X,Ce)=>r!=null&&r.searchEntities?r.searchEntities(X,Ce==="all"?void 0:Ce):Promise.resolve([]),[r]),le=g.useCallback(X=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(X),V(Ce=>[X,...Ce.filter(Me=>Me.id!==X.id)].slice(0,10)),L==null||L(X),K(!1),Z(null)},[r,L]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${i("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Lf[pe]}),t.jsx("span",{children:e.title||f.editor.untitled}),t.jsx(li,{children:e.id}),t.jsx(li,{color:Rf[pe],children:f.indexType[pe]})]})}),t.jsx(xt,{title:f.section.basicInfo,onSave:o,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(ti,{label:ee?f.editor.workTitle:ue?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:X=>be("title",X)}),me&&t.jsx(ti,{label:f.editor.belongsToWork,value:e.workName||"",onChange:X=>be("workName",X)}),t.jsx(dt,{label:f.editor.authorLabel,value:e.author||"",onChange:X=>be("author",X)}),t.jsx(dt,{label:f.editor.publicationYearLabel,value:e.publicationYear||"",onChange:X=>be("publicationYear",X)}),(me||ue)&&t.jsx(ti,{label:f.editor.containedIn,value:e.collection||"",onChange:X=>be("collection",X)}),(me||ue)&&t.jsx(dt,{label:f.editor.holderLabel,value:e.holder||"",onChange:X=>be("holder",X)}),(me||ue)&&t.jsx(dt,{label:me?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:X=>be("pages",X)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(dt,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:X=>be("firstImage",X)})})]})}),t.jsx(xt,{title:f.section.description,onSave:o,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Ut,{value:e.description||"",onChange:X=>be("description",X),placeholder:f.editor.descriptionPlaceholder})}),(((Se=e.additional_works)==null?void 0:Se.length)||0)>0&&t.jsx(xt,{title:f.section.additionalWorks,onSave:o,children:t.jsx(Af,{items:e.additional_works||[],onChange:X=>be("additional_works",X)})}),t.jsx(xt,{title:f.section.indexedBy,onSave:o,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Pf,{items:e.indexed_by||[],onChange:X=>be("indexed_by",X)})}),t.jsx(xt,{title:f.section.emendatedBy,onSave:o,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Mf,{items:e.emendated_by||[],onChange:X=>be("emendated_by",X)})}),t.jsx(xt,{title:f.section.textResources,onSave:o,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(io,{items:e.resources||[],onChange:X=>be("resources",X),onDownload:p,downloadStatuses:u,filterType:"text"})}),t.jsx(xt,{title:f.section.imageResources,onSave:o,children:t.jsx(io,{items:e.resources||[],onChange:X=>be("resources",X),onDownload:p,downloadStatuses:u,filterType:"image"})}),t.jsx(xt,{title:f.section.sources,onSave:o,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(mc,{items:hc(e.sources||""),onChange:X=>be("sources",gc(X)),onOpenEntityPicker:Y})}),(me||ue)&&t.jsx(xt,{title:f.section.provenance,onSave:o,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Ut,{value:e.provenance||"",onChange:X=>be("provenance",X),placeholder:f.editor.provenancePlaceholder})}),me&&t.jsx(xt,{title:f.section.otherEditions,onSave:o,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Ut,{value:e.otherEditions||"",onChange:X=>be("otherEditions",X),placeholder:f.editor.otherEditionsPlaceholder})}),t.jsx(fc,{entityType:pe,entityId:e.id,entityTitle:e.title,parentWork:m==null?void 0:m.parentWork,parentCollection:m==null?void 0:m.parentCollection,belongsToWork:m==null?void 0:m.belongsToWork,belongsToCollection:m==null?void 0:m.belongsToCollection,childWorks:m==null?void 0:m.childWorks,childCollections:m==null?void 0:m.childCollections,containedBooks:m==null?void 0:m.containedBooks,siblingBooks:m==null?void 0:m.siblingBooks,onLinkEntity:Oe,onUnlinkEntity:ie,onViewEntity:Re,onCreateAndLink:Le,onSaveRelations:ze}),a&&l&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:f.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:f.editor.dangerZoneDesc}),t.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:f.editor.deleteEntity})]}),t.jsx(bc,{isOpen:x,entityType:y,title:S,onSelect:fe,onCancel:()=>k(!1),onCreate:()=>{k(!1),Le(b,y)},searchResults:$,onSearch:J,isLoading:C,excludeId:e.id}),t.jsx(yc,{isOpen:T,entityType:F,relationField:R,inheritData:I,onConfirm:q,onCancel:()=>z(!1)}),t.jsx(vc,{isOpen:U,title:f.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:e.id,onSelect:le,onCancel:()=>{K(!1),Z(null)},onSearch:ve})]})};function Af({items:e,onChange:n}){const o=$e(),r=(l,d,c)=>{const p=e.map((u,m)=>m===l?{...u,[d]:c}:u);n(p)},s=l=>n(e.filter((d,c)=>c!==l)),a=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((l,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(dt,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(dt,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},d)),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function wc({items:e,onChange:n,showMeta:o,addLabel:r}){const s=$e(),[a,l]=g.useState(null),d=(u,m,h)=>{const f=e.map((x,k)=>k===u?{...x,[m]:h||void 0}:x);n(f)},c=u=>{n(e.filter((m,h)=>h!==u)),a===u&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,m)=>{const h=a===m;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(h?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:f=>{f.stopPropagation(),c(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!h&&o&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),h&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(dt,{label:s.label.sourceName,value:u.source,onChange:f=>d(m,"source",f)}),t.jsx(dt,{label:s.label.sourceBid,value:u.source_bid||"",onChange:f=>d(m,"source_bid",f)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(dt,{label:s.label.titleInfo,value:u.title_info||"",onChange:f=>d(m,"title_info",f)}),t.jsx(dt,{label:s.label.authorInfo,value:u.author_info||"",onChange:f=>d(m,"author_info",f)})]}),t.jsx(dt,{label:s.label.edition,value:u.edition||"",onChange:f=>d(m,"edition",f)})]}),t.jsx(Ut,{value:u.summary||"",onChange:f=>d(m,"summary",f),placeholder:s.editor.summaryPlaceholder}),t.jsx(Ut,{value:u.comment||"",onChange:f=>d(m,"comment",f),placeholder:s.editor.commentPlaceholder}),t.jsx(Ut,{value:u.additional_comment||"",onChange:f=>d(m,"additional_comment",f),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),t.jsx("button",{onClick:p,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Pf({items:e,onChange:n}){const o=$e();return t.jsx(wc,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Mf({items:e,onChange:n}){const o=$e();return t.jsx(wc,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function Sc(e){var d,c,p,u,m,h,f;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",o=((p=e.publication_info)==null?void 0:p.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(m=e.page_count)!=null&&m.number?String(e.page_count.number):((h=e.page_count)==null?void 0:h.description)||"",a=typeof e.description=="object"&&e.description!==null&&e.description.text||"",l={id:e.id,title:e.title,type:e.type,author:n,publicationYear:o,holder:r,pages:s,description:a,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const x=e;if(Array.isArray(x.related_works)){const k=x.related_works.find(y=>y.relation==="part_of");k&&(l.parentWorkId=k.id,l.parentWorkName=k.title)}}if(e.type==="book"){const x=e;l.workId=x.work_id,Array.isArray(x.contained_in)&&x.contained_in.length>0&&(l.collectionId=(f=x.contained_in[0])==null?void 0:f.id)}return l}function Bf(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Wf=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:u,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y,headerExtra:w,className:b,style:j}=e,S=$e(),[v,$]=g.useState(s),_=a?s:v;g.useEffect(()=>{s!==v&&$(s)},[s]);const C=g.useCallback(()=>{const O=_==="view"?"edit":"view";a?a(O):$(O)},[_,a]),[M,T]=g.useState(null);g.useEffect(()=>{o&&r&&r.getItem(o).then(O=>{O&&T(O)})},[o,r]);const z=n||M,F=g.useMemo(()=>z?Sc(z):null,[z]),N=a||!n?t.jsx("button",{onClick:C,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?S.common.switchToEdit:S.common.switchToView,children:_==="view"?S.common.modeEdit:S.common.modeView}):null,R=t.jsxs(t.Fragment,{children:[N,w]});return!z&&!F?t.jsx(Yt,{}):_==="view"?t.jsx(Bo,{data:z,transport:r,onNavigate:p?O=>p(O):void 0,renderLink:u,headerExtra:R,className:b,style:j}):F?t.jsxs("div",{className:b,style:j,children:[R&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:R}),t.jsx(kc,{data:F,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:S.common.noData})},Of=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],_c=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const{t:s}=Q(),[a,l]=g.useState(null),[d,c]=g.useState(""),[p,u]=g.useState(""),[m,h]=g.useState("idle"),[f,x]=g.useState(""),k=g.useRef(null);g.useEffect(()=>{e&&(l(null),c(""),u(""),h("idle"),x(""))},[e]),g.useEffect(()=>{a&&setTimeout(()=>{var b;return(b=k.current)==null?void 0:b.focus()},100)},[a]),g.useEffect(()=>{if(m==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[m,n]),g.useEffect(()=>{if(!e)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const y=async()=>{if(!(!a||!d.trim())){h("submitting"),x("");try{await o({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),h("success")}catch(b){h("error"),x(b instanceof Error?b.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&m!=="submitting";return t.jsx("div",{style:Hf,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:Ff,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:Df,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:Uf,"aria-label":s("feedback.close"),children:"✕"})]}),m==="success"?t.jsxs("div",{style:qf,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:s("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:s("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Of.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...Vf,...a===b.value?Gf:{}},children:[t.jsx("span",{children:b.icon})," ",s(`feedback.submitType.${b.value}`)]},b.value))}),t.jsx("textarea",{ref:k,value:d,onChange:b=>c(b.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||m==="submitting",style:{...Yf,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:b=>u(b.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||m==="submitting","aria-label":s("feedback.contactLabel"),style:Zf}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),m==="error"&&t.jsx("div",{style:Xf,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:y,disabled:!w,style:{...Kf,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:s(m==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Hf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ff={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Df={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Uf={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Vf={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Gf={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Yf={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Kf={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},qf={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},Xf={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Zf={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},wo="--bim-feedback-fab-offset",So=48,Jf=16,Qf=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const{t:a}=Q(),[l,d]=g.useState(!1),c=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(wo,`calc(${c+So+Jf}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(wo)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ex,zIndex:s??i("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":a("feedback.title"),title:a("feedback.title"),children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(_c,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:o})]})},ex={position:"fixed",width:`${So}px`,height:`${So}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},tx=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],$c=({onSubmit:e})=>{const{t:n}=Q(),[o,r]=g.useState("bug"),[s,a]=g.useState(""),[l,d]=g.useState(""),[c,p]=g.useState("idle"),[u,m]=g.useState(""),h=g.useRef(null);g.useEffect(()=>{o&&setTimeout(()=>{var k;return(k=h.current)==null?void 0:k.focus()},100)},[o]);const f=async()=>{if(!(!o||!s.trim())){p("submitting"),m("");try{await e({type:o,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),r("bug")}catch(k){p("error"),m(k instanceof Error?k.message:n("feedback.submitFailedRetry"))}}},x=o&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:Xs,children:t.jsxs("div",{style:sx,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:ax,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Xs,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:tx.map(k=>t.jsxs("button",{onClick:()=>r(k.value),style:{...nx,...o===k.value?ix:{}},children:[t.jsx("span",{children:k.icon})," ",n(`feedback.submitType.${k.value}`)]},k.value))}),t.jsx("textarea",{ref:h,value:s,onChange:k=>a(k.target.value),placeholder:n(o?`feedback.placeholder.${o}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...ox}}),t.jsx("input",{type:"text",value:l,onChange:k=>d(k.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:cx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[s.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!x,style:{...rx,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:lx,children:u})]})},Xs={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},nx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ix={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},ox={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},rx={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},sx={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},ax={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},lx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},cx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Zs(e){return typeof e=="function"?e():e??"/api/feedback"}const Cc=({resourceId:e,apiUrl:n})=>{const{t:o}=Q(),[r,s]=g.useState([]),[a,l]=g.useState(!0),d=g.useCallback(async()=>{const p=Zs(n);l(!0);try{const m=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();m.success&&s(m.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{d()},[d]);const c=async p=>{const u=Zs(n),m=await fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!m.ok){const h=await m.json().catch(()=>null);throw new Error((h==null?void 0:h.error)||o("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(br,{items:r,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx($c,{onSubmit:c})})]})},dx=di["zh-Hant"].relation,px=di["zh-Hant"].lossStatus,ux=di["zh-Hant"].resourceKind,Si=cn("zh-Hant"),yr=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function Js(e,n=Si){return e?yr(dx,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function mx(e,n=Si){return yr(px,e)?n(`detail.lossStatus.${e}`):e}function hx(e,n=Si){return yr(ux,e)?n(`detail.resourceKind.${e}`):""}function jr({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=Q(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=Yo(a.role);return t.jsxs(g.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(qe,{id:a.entity_id,label:r(a.name),onNavigate:n,renderLink:o,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function zc(e,n,o=Si){var c,p;const r=Vo(e,n),s=r.mirrors.map(u=>({key:u.key,label:u.label,description:u.description,rows:u.items.filter(m=>m.group_role!=="mirror"),mirrors:u.items.filter(m=>m.group_role==="mirror")})),a=r.buckets.filter(u=>u.key==="image"||u.key==="textImage").flatMap(u=>u.items);a.length&&s.push({key:"_images",label:s.length?o("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(u=>u.key==="physical"))==null?void 0:c.items)??[];return l.length&&s.push({key:"_physical",label:o("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((p=r.buckets.find(u=>u.key==="text"))==null?void 0:p.items)??[],groups:s}}function Tc(e,n){const o=(e.url?dn(e.url):void 0)||e.name,r=vl(e,n);return r?`${o}(${r})`:o}function vr({item:e,siblings:n,listedVolumeCounts:o}){const{t:r,convert:s}=Q(),[a,l]=g.useState(!1),d=pi(e),c=!!d&&d.expected>0&&!(o!=null&&o.has(d.expected)),p=s(Tc(e,n)),u=pn(e),m=yi(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,x;const h=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((x=e.metadata)==null?void 0:x.fragment)&&t.jsx("span",{className:"bim-d-tag",children: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 u?t.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),h]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,h]})})(),m&&t.jsx("span",{className:"bim-d-meta",children:s(m)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Jo,{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(h=>!h),children:a?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Nc({groups:e,listedVolumeCounts:n}){const{t:o,convert:r}=Q();return t.jsx(t.Fragment,{children:e.map(s=>t.jsxs("div",{className:"bim-d-rg",children:[s.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(s.label)}),s.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(s.description)}),s.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:s.rows.map((a,l)=>t.jsx(vr,{item:a,siblings:s.rows,listedVolumeCounts:n},`${a.id||a.url||a.name}-${l}`))})}),s.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[s.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:o("detail.mirror")}),s.mirrors.map((a,l)=>{const d=pn(a),c=r(Tc(a,s.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)})]})]},s.key))})}const En=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function _o(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=En.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const Qs=12,gx=60,Ec=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:a,back:l,railLinks:d})=>{var J,fe,ze;const{t:c,convert:p,messages:u}=Q(),m=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[h,f]=g.useState(new Map),[x,k]=g.useState(!1),[y,w]=g.useState(""),[b,j]=g.useState(!1),S=m.length<=gx,v=S||x||!!y||b,$=g.useMemo(()=>v?m:m.slice(0,Qs),[m,v]);g.useEffect(()=>{if(!n||$.length===0)return;const Y=$.filter(le=>!h.has(le));if(Y.length===0)return;let ve=!1;return Promise.all(Y.map(le=>n.getItem(le).then(Se=>{const X=Se??{};return[le,{id:le,title:X.title,edition:X.edition,resources:X.resources,publication_info:X.publication_info,current_location:X.current_location,lineage:X.lineage,measure_info:X.measure_info}]}).catch(()=>[le,{id:le}]))).then(le=>{ve||f(Se=>{const X=new Map(Se);for(const[Ce,Me]of le)X.set(Ce,Me);return X})}),()=>{ve=!0}},[n,$,h]);const _=g.useMemo(()=>m.map(Y=>h.get(Y)??{id:Y}),[m,h]),C=m.length>0&&m.every(Y=>h.has(Y)),M=!!n&&$.some(Y=>!h.has(Y)),T=S||v,z=g.useMemo(()=>wl(_,e.version_graph,{era:y,scanOnly:b,sort:T?"year":"default"}),[_,e.version_graph,y,b,T]),F=x?z.rows:z.rows.slice(0,Qs),N=z.allRows.filter(Y=>Y.hasImage).length,R=e.related_works||[],O=R.filter(Y=>Y.relation==="collected_in"),I=g.useMemo(()=>{const Y=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ve=le=>{const Se=Y.indexOf(le??"");return Se<0?Y.length:Se};return R.filter(le=>le.relation!=="collected_in").map((le,Se)=>({r:le,i:Se})).sort((le,Se)=>ve(le.r.relation)-ve(Se.r.relation)||le.i-Se.i).map(le=>le.r)},[R]),P=g.useMemo(()=>{const Y=Vo(e.resources,e.resource_groups);return[...Y.mirrors.flatMap(ve=>ve.items.map(le=>({r:le,kind:p(ve.label)}))),...Y.buckets.flatMap(ve=>ve.items.map(le=>({r:le,kind:p(hx(ve.key,c))})))]},[e.resources,e.resource_groups,p,c]),U=e.indexed_by||[],K=e.emendated_by||[],L=g.useMemo(()=>{var te,ye,H;const Y=[],ve=(ye=(te=e.authors)==null?void 0:te[0])==null?void 0:ye.dynasty;ve&&Y.push({label:c("workPage.fact.written"),value:p(ve)});const le=zt(e,u.unit.juan);if(le){const se=(H=e.juan_count)==null?void 0:H.description;Y.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(le),se&&se!==le?t.jsxs("span",{className:"bim-d-meta",children:["(",p(se),")"]}):null]})})}e.loss_status&&Y.push({label:c("workPage.fact.loss"),value:p(mx(e.loss_status,c))});const Se=z.allRows.filter(se=>se.sortYear!=null),X=Se.length>0?Se.reduce((se,ne)=>se.sortYear<=ne.sortYear?se:ne):null;X!=null&&X.era.era?Y.push({label:c("workPage.fact.earliest"),value:p([X.era.era,X.era.reign].filter(Boolean).join(" ")),title:X.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):M&&Y.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),K.length&&Y.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:K.length})});const Ce=ea(e.additional_titles);Ce.length&&Y.push({label:c("workPage.fact.alias"),value:Ce.map(p).join("、")});const Me=ea(e.attached_texts);Me.length&&Y.push({label:c("workPage.fact.attached"),value:Me.map(p).join("、")});const B=(e.additional_works||[]).map(se=>p(se.book_title)+(se.n_juan!=null?` ${se.n_juan}${u.unit.juan}`:""));return B.length&&Y.push({label:c("workPage.fact.appendix"),value:B.join("、")}),Y},[e,p,c,u,M,z.allRows,K.length]),A=[{value:e._edition_count??m.length,label:c("workPage.stat.editions")},{value:C?N:0,label:c("workPage.stat.hasImage")},{value:U.length,label:c("workPage.stat.catalogs")}],V=e.classification,pe=V?[V.l1,V.l2,V.l3,V.l4].filter(Boolean).map(Y=>p(Y)):[],ee=e.subtype?u.workSubtype[e.subtype]??p(e.subtype):"",ue=t.jsx(An,{title:p(e.title),byline:t.jsx(jr,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(Je,{items:[...pe,V!=null&&V.source?c("workPage.classifiedBy",{source:p(V.source.split("/")[0])}):"",ee]}),description:(J=e.description)!=null&&J.text?t.jsxs(t.Fragment,{children:[t.jsx(Ct,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(fe=e.description.sources)!=null&&fe.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(Y=>p(Im(Y))).filter(Boolean).join(" · ")}):null]}):void 0,stats:A,facts:L,readAction:s,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(ze=e.appendix)==null?void 0:ze.map((Y,ve)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(Y.title)}),t.jsx(Ct,{text:Y.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ve))}),me=z.eras.length>=2?[{key:"",label:c("catalog.all")},...z.eras.map(Y=>({key:Y,label:`${Y} ${z.allRows.filter(ve=>ve.era.era===Y).length}`}))]:[],be=[];m.length&&be.push({id:"versions",label:c("workPage.sec.versions"),count:m.length}),U.length&&be.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:U.length}),O.length&&be.push({id:"collected",label:c("workPage.sec.collected"),count:O.length}),I.length&&be.push({id:"related",label:c("workPage.sec.related"),count:I.length}),P.length&&be.push({id:"resources",label:c("workPage.sec.resources"),count:P.length});const Oe=m.length===0&&U.length===0,ie=t.jsxs(t.Fragment,{children:[m.length>0&&t.jsxs(et,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(Je,{items:[c("workPage.versionsTotal",{n:m.length}),C&&N?c("workPage.versionsWithImage",{n:N}):"",z.rows.length!==z.allRows.length?c("workPage.versionsCurrent",{n:z.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":M&&me.length===0&&m.length>1?"":void 0,children:[me.length>0&&t.jsx(vi,{items:me,value:y,onChange:Y=>{w(Y),k(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Nl,{label:c("workPage.scanOnly"),checked:b,onChange:Y=>{j(Y),k(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(T?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&ki(z.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:F.map(Y=>{var ve;return t.jsx(fx,{row:Y,measure:(ve=h.get(Y.id))==null?void 0:ve.measure_info,loaded:h.has(Y.id),onNavigate:o,renderLink:r},`${Y.id}:${h.has(Y.id)?"r":"p"}`)})})]}),F.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(y||b?"workPage.noVersionsFiltered":"workPage.noVersions")}),!x&&t.jsx(Ko,{total:z.rows.length,shown:F.length,unit:c("workPage.moreUnit"),onClick:()=>k(!0)}),z.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),U.length>0&&t.jsx(xx,{items:U,transport:n,onNavigate:o,renderLink:r}),Oe&&t.jsx(et,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),Re=(Y,ve)=>t.jsx(qe,{id:Y,label:p(ve),onNavigate:o,renderLink:r,dense:!0}),Le=g.useMemo(()=>{const Y=new Map;for(const ve of I){const le=Js(ve.relation,c);Y.set(le,(Y.get(le)??0)+1)}return Y.size>1?[...Y.entries()].sort((ve,le)=>le[1]-ve[1]).slice(0,4).map(([ve,le])=>`${p(ve)} ${le}`).join(" · "):void 0},[I,p,c]),q=t.jsxs(t.Fragment,{children:[t.jsx(Dt,{id:"collected",title:c("workPage.sec.collected"),items:O.map(Y=>Re(Y.id,Y.title))}),t.jsx(Dt,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:I.length}),sub:Le,items:I.map(Y=>t.jsxs(t.Fragment,{children:[Re(Y.id,Y.title),t.jsx("span",{className:"bim-d-meta",title:Y.note?p(Y.note):void 0,children:p(Js(Y.relation,c))})]}))}),t.jsx(Dt,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:P.map(({r:Y,kind:ve})=>{const le=p((Y.url?dn(Y.url):void 0)||Y.name),Se=pn(Y);return t.jsxs(t.Fragment,{children:[Se?t.jsxs("a",{href:Se,target:"_blank",rel:"noopener noreferrer",children:[le," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:le}),ve&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ve})]})})})]});return t.jsx(Ln,{railTop:a,back:l,nav:be,railLinks:d,main:ie,card:ue,side:q})};function ea(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ta(e,n){return n((e.url?dn(e.url):void 0)||e.name)}function fx({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{t:a,convert:l}=Q(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],u=p?ta(p,l):e.locationName?l(e.locationName):"",m=e.images[0],h=m?pn(m):void 0,f=e.images.map(x=>ta(x,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(qe,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:c?a("workPage.inferredFromEdition"):void 0,children:d?l(d):o?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||(o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(h?t.jsx("a",{className:"bim-d-flag",href:h,target:"_blank",rel:"noopener noreferrer",title:f,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:f,children:a("workPage.hasImage")}))})]})}function xx({items:e,transport:n,onNavigate:o,renderLink:r}){const{t:s,convert:a}=Q(),[l,d]=g.useState(0),c=Math.min(l,e.length-1),p=e[c],[u,m]=g.useState(new Map);return g.useEffect(()=>{if(!n)return;const h=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(h.length===0)return;let f=!1;return Promise.all(h.map(x=>n.getItem(x).then(k=>{var y,w;return[x,((w=(y=k==null?void 0:k.authors)==null?void 0:y[0])==null?void 0:w.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{f||m(new Map(x.filter(([,k])=>k)))}),()=>{f=!0}},[n,e]),t.jsx(et,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(Je,{items:[s("workPage.catalog.meta",{n:e.length}),s("workPage.sortByCatalog")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":s("workPage.catalog.tablist"),children:e.map((h,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(h.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(h.source_bid??"")?a(u.get(h.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(h.source)].slice(0,9).map((x,k)=>t.jsx("span",{children:x},k))})]})},f))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(p.title_info)}),t.jsx(Je,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(qe,{id:p.source_bid,label:a(p.source),onNavigate:o,renderLink:r,dense:!0}):a(p.source),p.section?a(p.section):"",p.author_info?`${s("label.authorInfo")} ${a(p.author_info)}`:"",p.edition?`${s("label.edition")} ${a(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:ut(a(p.summary),void 0,{t:s})}),p.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:ut(a(p.comment),void 0,{t:s})})]}),p.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:ut(a(p.additional_comment),void 0,{t:s})})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("workPage.catalog.titleOnly")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.prev",{name:a(e[c-1].source)}),onClick:()=>d(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.next",{name:a(e[c+1].source)}),onClick:()=>d(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function bx(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function yx(e,n){if(!e.lineage)return null;const o=e.lineage;return{id:e.id,kind:"book",label:e.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[e.id],note:o.note}}function na(e,n,o){return{id:`derive:${n.ref}->${e}:${o}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function jx(e,n,o){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function vx(e,n){var p;if(n==="all")return null;const o=(p=e.collections)==null?void 0:p[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,a=r||s||!!(o!=null&&o.hypothetical_ids);if(!a&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!o||!a)return null;const l=r?new Set(o.groups):null,d=new Set(o.book_ids??[]);if(l&&e.node_groups)for(const[u,m]of Object.entries(e.node_groups))l.has(m)&&d.add(u);let c=null;if(o.hypothetical_ids&&(c=new Set(o.hypothetical_ids)),l){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&l.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function ni(e,n,o){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const a=new Set(r.excluded_books??[]),l=r.node_groups??{},d=vx(r,o??r.default_collection??"all"),c=d!==null,p=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,m=new Set,h=new Set;if(c){const S=new Map(n.map(T=>[T.id,T])),v=new Map((r.hypothetical_nodes??[]).map(T=>[T.id,T])),$=T=>{const z=S.get(T);if(z&&z.lineage)return(z.lineage.derived_from??[]).map(N=>N.ref);const F=v.get(T);return F?(F.derived_from??[]).map(N=>N.ref):[]},_=T=>v.has(T)?!u||u.has(T):!p||p.has(T),C=new Set,M=T=>{if(!C.has(T)){C.add(T);for(const z of $(T))a.has(z)||(_(z)||(v.has(z)?h.add(z):S.has(z)&&m.add(z)),M(z))}};for(const T of n)p&&p.has(T.id)&&!a.has(T.id)&&M(T.id);for(const T of r.hypothetical_nodes??[])u&&u.has(T.id)&&M(T.id)}const f=n.filter(S=>!a.has(S.id)).filter(S=>!p||p.has(S.id)||m.has(S.id)).map(S=>{const v=yx(S,l);return v&&m.has(S.id)&&(v.bridge=!0),v}).filter(S=>S!==null),x=(r.hypothetical_nodes??[]).filter(S=>!u||u.has(S.id)||h.has(S.id)).map(S=>{const v=bx(S);return h.has(S.id)&&(v.bridge=!0),v}),k=[...f,...x],y=new Set(k.map(S=>S.id)),w=new Set,b=[],j=S=>{w.has(S.id)||!y.has(S.source)||!y.has(S.target)||(w.add(S.id),b.push(S))};for(const S of n)a.has(S.id)||!S.lineage||p&&!p.has(S.id)&&!m.has(S.id)||((S.lineage.derived_from??[]).forEach((v,$)=>{j(na(S.id,v,$))}),(S.lineage.related_to??[]).forEach((v,$)=>{j(jx(S.id,v,$))}));for(const S of r.hypothetical_nodes??[])u&&!u.has(S.id)&&!h.has(S.id)||(S.derived_from??[]).forEach((v,$)=>{j(na(S.id,v,$))});return{nodes:k,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(a)}}function Ic(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function kx(e,n){const o=[],r=e.version_graph;if(!r)return o;const s=new Set(n.map(c=>c.id)),a=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...a]),d=(c,p)=>{l.has(p.ref)||o.push(`${c}: derived_from.ref "${p.ref}" 未在 books 或 hypothetical_nodes 中找到`),p.ref_type==="book"&&!s.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 book 但不在 books 列表中`),p.ref_type==="hypothetical"&&!a.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const p=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>d(p,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${p}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>d(p,u))}return o}const Rc=({graph:e,renderLink:n,className:o,style:r})=>{const{t:s,convert:a}=Q();if(!e.nodes.length)return t.jsx("div",{style:{...Px,...r},className:o,children:s("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const x=l.get(f.target)??[];x.push(f),l.set(f.target,x)}else for(const x of[f.source,f.target]){const k=d.get(x)??[];k.push(f),d.set(x,k)}const c=new Map(e.nodes.map(f=>[f.id,f])),p=new Map,u=[];for(const f of e.nodes)if(f.group){const x=p.get(f.group)??[];x.push(f),p.set(f.group,x)}else u.push(f);const m=(f,x)=>(f.year??9999)-(x.year??9999);p.forEach(f=>f.sort(m)),u.sort(m);const h=e.groups.filter(f=>p.has(f.id));return t.jsxs("div",{className:o,style:{...Sx,...r},children:[e.title&&t.jsx("div",{style:_x,children:a(e.title)}),e.description&&t.jsx("div",{style:$x,children:a(e.description)}),h.map(f=>t.jsx(ia,{label:f.label,color:f.color,nodes:p.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},f.id)),u.length>0&&t.jsx(ia,{label:s("lineage.otherGroup"),nodes:u,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},ia=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=Q();return t.jsxs("div",{style:Cx,children:[t.jsx("div",{style:{...zx,borderLeftColor:n??i("widget-border")},children:d(e)}),o.map(c=>t.jsx(wx,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},wx=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=Q();return t.jsxs("div",{style:{...Tx,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?i("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Nx,children:[t.jsx("span",{style:Ex,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Ix,children:Ic(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Rx,children:[e.category&&t.jsx(Sn,{children:c(e.category)}),e.status==="lost"&&t.jsx(Sn,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Sn,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Sn,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Sn,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Lx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ax,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:ra,children:[t.jsx("div",{style:sa,children:d("lineage.sources")}),n.map(p=>{const u=r.get(p.source);return t.jsxs("div",{style:aa(p.confidence),children:[t.jsx("span",{style:la,children:c(p.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,c(u.label)):c((u==null?void 0:u.label)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(oa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ca,children:["· ",c(p.evidence)]})]},p.id)})]}),o.length>0&&t.jsxs("div",{style:ra,children:[t.jsx("div",{style:sa,children:d("lineage.related")}),o.map(p=>{const u=p.source===e.id?p.target:p.source,m=r.get(u);return t.jsxs("div",{style:aa(p.confidence),children:[t.jsx("span",{style:la,children:c(p.relation)}),t.jsx("span",{children:(m==null?void 0:m.kind)==="book"&&s?s(m.id,c(m.label)):c((m==null?void 0:m.label)??u)}),t.jsx(oa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ca,children:["· ",c(p.evidence)]})]},p.id)})]})]})},Sn=({children:e,tone:n="default"})=>{const r={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("info-fg")}}[n];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})},oa=({level:e})=>{const{t:n}=Q(),r={certain:{key:"certain",color:i("confidence-certain")},consensus:{key:"consensus",color:i("confidence-consensus")},probable:{key:"probable",color:i("confidence-probable")},disputed:{key:"disputed",color:i("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:n(`lineage.confidence.${r.key}`)}):null},Sx={fontSize:"14px",color:i("fg")},_x={fontSize:"16px",fontWeight:600,marginBottom:"8px"},$x={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Cx={marginBottom:"16px"},zx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Tx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Nx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ex={fontSize:"15px",fontWeight:600},Ix={fontSize:"12px",color:i("muted")},Rx={marginBottom:"6px"},Lx={fontSize:"12px",color:i("muted"),margin:"2px 0"},Ax={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},ra={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},sa={fontSize:"11px",color:i("muted"),marginBottom:"2px"},aa=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),la={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},ca={fontSize:"11px",color:i("muted")},Px={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Lc=({selectedNodeId:e,...n})=>{const{t:o}=Q(),[r,s]=g.useState("loading"),[a,l]=g.useState(null);return g.useEffect(()=>{let d=!1;return Mx().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:pa,children:o("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:pa,children:[t.jsx("div",{children:da(o("lineage.graphMissing"),{xyflow:t.jsx("code",{children:"@xyflow/react"}),dagre:t.jsx("code",{children:"@dagrejs/dagre"})})}),t.jsx("div",{style:{fontSize:"12px",marginTop:"4px"},children:da(o("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Bx,{modules:a,selectedNodeId:e,...n})};function da(e,n){return e.split(/(\{\w+\})/).map((o,r)=>{const s=/^\{(\w+)\}$/.exec(o);return t.jsx(g.Fragment,{children:s&&s[1]in n?n[s[1]]:o},r)})}async function Mx(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:o}}catch{return null}}const Bx=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:p,Handle:u,Position:m,BaseEdge:h,EdgeLabelRenderer:f,getSmoothStepPath:x,dagre:k}=l,y=g.useMemo(()=>({lineage:$=>{var I,P,U,K;const _=((I=$.data)==null?void 0:I.stepPosition)??.85,[C,M,T]=x({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:_,borderRadius:5}),z=!!((P=$.data)!=null&&P.isSibling),F=z?M:$.targetX-18,N=z?T:$.targetY-12,R=(U=$.data)==null?void 0:U.labelStyle,O=(K=$.data)==null?void 0:K.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(h,{id:$.id,path:C,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${N}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...O,...R},children:$.label})})]})}}),[h,f,x]),w=g.useMemo(()=>({version:$=>{const{t:_}=Q(),C=$.data,M=C.kind==="hypothetical",T=C.status==="lost",z=C.isSelected,F=C.bridge,N=C.borderColor??i("muted"),R=F||M?"dashed":"solid",O=F?.5:T?.6:1;return t.jsxs("div",{style:{background:i(F?"bg-subtle":"bg"),border:`2px ${R} ${z?i("primary"):N}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:z?i("shadow-node-selected"):M||F?"none":i("shadow-node")},title:F?_("lineage.bridgeTitle"):void 0,children:[t.jsx(u,{type:"target",position:m.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:M||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Ic(C.yearText,void 0,C.uncertain)}),T&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:_("lineage.lost")}),t.jsx(u,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[u,m]),{convert:b}=Q(),{rfNodes:j,rfEdges:S}=g.useMemo(()=>Wx(e,k,n,a,b),[e,k,n,a,b]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(p,{showInteractive:!1})]})})};function Wx(e,n,o,r,s=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const p=new Map(e.groups.map(w=>[w.id,w.color??i("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(u.has(w.relation)||c.setEdge(w.source,w.target));n.layout(c);const m=e.nodes.map(w=>{const b=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:s(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:s(w.year_text??Hx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?p.get(w.group):void 0,renderLink:o,isSelected:j,description:s(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:S,draggable:!1,selected:j}}),h=.78,f=.06,x=new Map;for(const w of e.edges)w.kind==="derive"&&(x.has(w.source)||x.set(w.source,[]),x.get(w.source).push(w));const k=new Map;for(const[w,b]of x){if(b.length<=1)continue;const j=[...b].sort((v,$)=>{var M,T;const _=((M=c.node(v.target))==null?void 0:M.y)??0,C=((T=c.node($.target))==null?void 0:T.y)??0;return _-C}),S=j.length;j.forEach((v,$)=>{const _=($-(S-1)/2)*f;k.set(v.id,h+_)})}const y=e.edges.map(w=>Ox(w,k.get(w.id),s));return{rfNodes:m,rfEdges:y}}function Ox(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=Fx(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:o(e.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:a,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Hx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Fx(e){switch(e){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const pa={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},kr=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:u,style:m})=>{var S;const{t:h,convert:f}=Q(),[x,k]=g.useState(n),y=v=>{k(v),a==null||a(v)},w=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:h("lineage.collectionAll"),description:h("lineage.collectionAllDesc")}]]})(),b=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:h("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:u,style:m,children:[t.jsxs("div",{style:Dx,children:[t.jsx("button",{onClick:()=>y("list"),style:Ji(x==="list"),children:h("lineage.modeList")}),t.jsx("button",{onClick:()=>y("graph"),style:Ji(x==="graph"),children:h("lineage.modeGraph")}),b&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:h("lineage.collectionLabel")}),w.map(([v,$])=>{const _=p==null?void 0:p[v];return t.jsxs("button",{onClick:()=>d==null?void 0:d(v),style:Ji(l===v),title:$.description?f($.description):void 0,children:[f($.label),_!=null?` ${_}`:""]},v)})]})]}),b&&j&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:f(j)}),x==="list"?t.jsx(Rc,{graph:e,renderLink:o}):t.jsx(Lc,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},Dx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Ji=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:e?i("primary"):"transparent",color:i(e?"primary-fg":"fg"),cursor:"pointer"}),ua=40,ma=2,Ux=9,Vx=new Set(["certain","consensus","probable","disputed"]);function Qi(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Ac=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:u})=>{var H,se,ne,ge,Ne,Be,We,Ue,Qe,ce,tt;const m=$e(),{t:h,convert:f}=Q(),[x,k]=g.useState(null),[y,w]=g.useState(new Map),[b,j]=g.useState([]),[S,v]=g.useState(new Map),[$,_]=g.useState(!1),[C,M]=g.useState("flow"),[T,z]=g.useState(null);g.useEffect(()=>{if(!n||!e.work_id){k(null);return}let E=!1;return n.getItem(e.work_id).then(oe=>{!E&&oe&&oe.type==="work"&&k(oe)}).catch(()=>{}),()=>{E=!0}},[n,e.work_id]),g.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){z(null);return}let E=!1;return n.getLineageGraph(e.work_id).then(oe=>{E||z(oe&&oe.nodes.length>1?oe:null)}).catch(()=>{E||z(null)}),()=>{E=!0}},[n,e.work_id]),g.useEffect(()=>{const E=e.contained_in||[];if(!n||E.length===0){w(new Map);return}let oe=!1;return Promise.all(E.map(ae=>{const je=typeof ae=="string"?ae:ae.id;return n.getItem(je).then(ke=>[je,ke]).catch(()=>[je,null])})).then(ae=>{if(oe)return;const je=new Map;for(const[ke,xe]of ae)xe&&je.set(ke,xe);w(je)}),()=>{oe=!0}},[n,e.contained_in]);const F=g.useMemo(()=>{const E=new Set([...(x==null?void 0:x.books)||[],...e.related_books||[]]);return E.add(e.id),[...E]},[x==null?void 0:x.books,e.related_books,e.id]),N=F.length-1;g.useEffect(()=>{if(!n||N<=0){j([]);return}const E=F.length<=ua,oe=E?F:F.slice(0,8);let ae=!1;return Promise.all(oe.map(je=>je===e.id?Promise.resolve({id:je,title:e.title,edition:e.edition,year:ri(e)}):n.getItem(je).then(ke=>{const xe=ke??{};return{id:je,title:xe.title,edition:xe.edition,year:ke?ri(xe):void 0}}).catch(()=>({id:je})))).then(je=>{if(ae)return;const ke=je.filter(xe=>xe.id===e.id||xe.title||xe.edition);E&&ke.sort((xe,G)=>(xe.year??1/0)-(G.year??1/0)),j(ke)}),()=>{ae=!0}},[n,F,N,e]);const R=e.lineage,O=g.useMemo(()=>[...((R==null?void 0:R.derived_from)||[]).filter(E=>E.ref_type==="book").map(E=>E.ref),...((R==null?void 0:R.related_to)||[]).map(E=>E.book_id)].filter(Boolean),[R]);g.useEffect(()=>{if(!n||O.length===0){v(new Map);return}let E=!1;return Promise.all(O.map(oe=>n.getItem(oe).then(ae=>[oe,{id:oe,title:ae==null?void 0:ae.title,edition:ae==null?void 0:ae.edition}]).catch(()=>[oe,{id:oe}]))).then(oe=>{E||v(new Map(oe))}),()=>{E=!0}},[n,O]);const I=g.useMemo(()=>zc(e.resources,e.resource_groups,h),[e.resources,e.resource_groups,h]),P=I.groups.reduce((E,oe)=>E+oe.rows.length+oe.mirrors.length,0),U=I.groups.length>0&&I.groups.every(E=>E.key==="_physical"),K=Rn(e),L=zl(e),Z=zt(e,m.unit.juan),A=new Set((e.contained_in||[]).map(E=>typeof E=="string"?0:Tn(E.volume_index).length).filter(E=>E>0)),V=E=>{var je;const oe=(je=e.base_edition)==null?void 0:je.find(ke=>ke.book_id===E&&ke.name);if(oe!=null&&oe.name)return oe.name;const ae=S.get(E);return(ae==null?void 0:ae.edition)||(ae==null?void 0:ae.title)||""},pe=g.useMemo(()=>{var Te,Ee,D,re,Pe;const E=[];L&&E.push({label:h("bookPage.fact.editionType"),value:f(L),title:e.edition_type||(Te=e.lineage)!=null&&Te.category?void 0:h("bookPage.inferredFromEdition")}),(Ee=e.publication_info)!=null&&Ee.details?E.push({label:h("bookPage.fact.publication"),value:f(e.publication_info.details)}):(K.era||K.reign)&&E.push({label:h("bookPage.fact.era"),value:f([K.era,K.reign].filter(Boolean).join(" ")),title:K.source==="edition"?h("bookPage.inferredFromEdition"):void 0}),Z&&E.push({label:h("bookPage.fact.measure"),value:f(Z)});const oe=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Tn(_e.volume_index));oe.length&&E.push({label:h("bookPage.fact.volumes"),value:h("bookPage.volumesValue",{range:ji(oe,m.unit.volume),unit:m.unit.volume,n:oe.length})});const ae=(((D=e.lineage)==null?void 0:D.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");ae&&V(ae.ref)&&E.push({label:h("bookPage.fact.baseEdition"),value:t.jsx(qe,{id:ae.ref,label:f(V(ae.ref)),onNavigate:o,renderLink:r,dense:!0})});const je=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&ae&&V(ae.ref))continue;const Ge=je.filter(He=>He.role===_e);Ge.length&&E.push({label:f(_e),value:Ge.map((He,De)=>t.jsxs(g.Fragment,{children:[De>0&&"、",He.book_id?t.jsx(qe,{id:He.book_id,label:f(He.name),onNavigate:o,renderLink:r,dense:!0}):f(He.name)]},De))})}const ke=(e.provenance||[]).filter(_e=>_e&&_e.institution),xe=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(ke.length){E.push({label:h("bookPage.fact.holdings"),value:ke.slice(0,2).map(He=>f(He.institution)).join("、")+(ke.length>2?h("bookPage.andMorePlaces",{n:ke.length}):"")});const _e=ke.filter(He=>He.call_number).slice(0,2).map(He=>`${f(He.institution)} ${He.call_number}`);_e.length&&E.push({label:h("bookPage.fact.callNumber"),value:_e.join(";")+(ke.filter(He=>He.call_number).length>2?"…":"")});const Ge=ke.flatMap(He=>He.seals||[]).filter(Boolean);Ge.length&&E.push({label:h("bookPage.fact.seals"),value:f(Ge.join("、"))})}else xe.length?E.push({label:h("bookPage.fact.holdings"),value:xe.slice(0,2).map(_e=>f(_e.name)).join("、")+(xe.length>2?h("bookPage.andMorePlaces",{n:xe.length}):"")}):(re=e.current_location)!=null&&re.name&&E.push({label:h("bookPage.fact.holdings"),value:f(e.current_location.name)});const G=e.physical_description;if(G){const _e=[[h("bookPage.fact.leafStyle"),G.leaf_style],[h("bookPage.fact.binding"),G.binding],[h("bookPage.fact.dimensions"),G.dimensions],[h("bookPage.fact.condition"),G.condition]];for(const[Ge,He]of _e)He&&He.trim()&&E.push({label:Ge,value:f(He)})}(Pe=e.page_count)!=null&&Pe.description&&E.push({label:m.label.pageCount,value:f(e.page_count.description)});const de=[...xo(e.additional_titles),...xo(e.attached_texts)];return de.length&&E.push({label:h("bookPage.fact.aliases"),value:de.map(f).join("、")}),E},[e,f,m,h,K,L,Z,S,o,r]),ee=f(e.title),ue=e.edition?f(e.edition):void 0,me=((H=e.lineage)==null?void 0:H.year_text)||"",be=t.jsx(An,{kind:h("bookPage.kind"),title:ee,subtitle:ue,byline:t.jsx(jr,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:o,renderLink:r}),meta:(()=>{const E=[L?f(L):"",K.era?f([K.era,K.reign].filter(Boolean).join("")):"",Z?f(Z):""].filter(Boolean);return E.length?t.jsx("span",{className:"bim-d-tags",children:E.map((oe,ae)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ae,2)}`,children:oe},ae))}):null})(),description:(se=e.description)!=null&&se.text?t.jsx(Ct,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Xo((ne=e.description)==null?void 0:ne.text)?6:void 0,facts:pe,readAction:s,secondaryAction:s&&P>0&&!U?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:h("bookPage.viewImages")}):void 0,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),Oe=e.contained_in||[],ie=(a==null?void 0:a.chapters)||[],Re=f(ie[0]&&Qi(ie[0].title)[0].slice(-1)||"")||h("bookPage.chapterUnit"),Le=h("bookPage.chapterCount",{n:ie.length,unit:Re}),q=!!((ge=R==null?void 0:R.derived_from)!=null&&ge.length||(Ne=R==null?void 0:R.related_to)!=null&&Ne.length||(Be=e.appendix)!=null&&Be.length),J=[],fe=h(U?"bookPage.sec.physical":"bookPage.sec.images");(ie.length||I.text.length||l)&&J.push({id:"fulltext",label:h("bookPage.sec.fulltext"),count:ie.length?Le:void 0}),I.groups.length&&J.push({id:"images",label:fe,count:P}),q&&J.push({id:"lineage",label:h("bookPage.sec.lineage")}),Oe.length&&J.push({id:"collections",label:h("section.containedIn"),count:Oe.length}),(We=e.location_history)!=null&&We.length&&J.push({id:"provenance",label:h("section.locationHistory")});const ze=E=>(d==null?void 0:d(E))??null,Y=ie[0],ve=Y?ze(Y.file):null,le=$?ie:ie.slice(0,Ux),Se=(E,oe,ae)=>E?t.jsx("a",{className:ae,href:E.href??"#",onClick:E.onClick?je=>{je.metaKey||je.ctrlKey||(je.preventDefault(),E.onClick())}:void 0,children:oe}):t.jsx("span",{className:ae,children:oe}),X=t.jsxs(t.Fragment,{children:[(ie.length>0||I.text.length>0||l)&&t.jsxs(et,{id:"fulltext",title:h("bookPage.sec.fulltext"),meta:ie.length>0?t.jsx(Je,{items:[Le,(Ue=a==null?void 0:a.source)!=null&&Ue.name?h("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!Y&&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"})]}),Y&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:h("bookPage.readFrom",{ch:f(Qi(Y.title)[0])||h("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((Y.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),Se(ve,t.jsxs(t.Fragment,{children:[h("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ie.length>1&&t.jsx("ul",{className:"bim-d-chap",children:le.map(E=>{const[oe,ae]=Qi(E.title);return t.jsx("li",{children:Se(ze(E.file),t.jsxs(t.Fragment,{children:[oe&&t.jsx("b",{children:f(oe)}),f(ae||E.file)]}))},E.file)})}),ie.length>le.length&&t.jsx(qo,{label:h("detail.expandRest",{n:ie.length-le.length,unit:Re}),onClick:()=>_(!0)}),I.text.length>0&&t.jsxs(t.Fragment,{children:[(ie.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:h("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:I.text.map((E,oe)=>t.jsx(vr,{item:E,siblings:I.text,listedVolumeCounts:A},`${E.id||E.url||E.name}-${oe}`))})})]})]}),I.groups.length>0&&t.jsx(et,{id:"images",title:fe,meta:t.jsx(Je,{items:[I.groups.length>1?h("bookPage.groupCount",{n:I.groups.length}):"",h("bookPage.placeCount",{n:P})]}),children:t.jsx(Nc,{groups:I.groups,listedVolumeCounts:A})}),q&&t.jsx(et,{id:"lineage",title:h("bookPage.sec.lineage"),meta:(Qe=R==null?void 0:R.derived_from)!=null&&Qe.length?h("bookPage.lineageMeta"):void 0,action:T?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":h("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":C==="flow",onClick:()=>M("flow"),children:h("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>M("graph"),children:h("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&T?t.jsx(kr,{graph:T,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(E,oe)=>t.jsx(qe,{id:E,label:f(oe),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(Yx,{data:e,heading:ue||ee,yearText:me,refName:V,onNavigate:o,renderLink:r})}),Oe.length>0&&t.jsx(et,{id:"collections",title:h("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Oe.map((E,oe)=>{var G,de;const ae=typeof E=="string"?E:E.id,je=typeof E=="string"?[]:Tn(E.volume_index),ke=y.get(ae),xe=(ke==null?void 0:ke._member_count)||((G=ke==null?void 0:ke.books)==null?void 0:G.length)||((de=ke==null?void 0:ke.contained_works)==null?void 0:de.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(qe,{id:ae,label:ke?f(ke.title):ae,onNavigate:o,renderLink:r,dense:!0}),je.length>0&&t.jsx(Gx,{volumes:je,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${xe?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:xe>0&&h("bookPage.totalOf",{n:xe,unit:m.unit.bu})})]},`${ae}-${oe}`)})})})}),(ce=e.location_history)!=null&&ce.length?t.jsx(et,{id:"provenance",title:h("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((E,oe)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(E.name)}),([E.start_date,E.end_date].filter(Boolean).join("—")||E.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Je,{items:[[E.start_date,E.end_date].filter(Boolean).join("—"),E.description?f(E.description):""]})})]},oe))})}):null,J.length===0&&t.jsx(et,{title:h("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:h("bookPage.emptyText")})})]}),Ce=b.findIndex(E=>E.id===e.id),Me=F.length<=ua,B=Me&&Ce>=0?b.slice(Math.max(0,Ce-ma),Ce+ma+1):b.filter(E=>E.id!==e.id),te=t.jsxs(t.Fragment,{children:[x&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:f(m.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(qe,{id:x.id,label:f(x.title),onNavigate:o,renderLink:r})}),t.jsx(Je,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(E=>`${E.dynasty?`〔${f(E.dynasty)}〕`:""}${f(E.name)}`),f(zt(x,m.unit.juan)),x._edition_count?h("bookPage.editionCount",{n:x._edition_count}):""]}),((tt=x.description)==null?void 0:tt.text)&&t.jsx("p",{style:{margin:"8px 0 0",fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc",children:f(x.description.text.replace(/[#*_>`[\]]/g,""))})]}),N>0&&B.length>0&&t.jsxs("div",{children:[t.jsx(Dt,{id:"siblings",timeline:!0,title:Me?h("bookPage.siblings"):m.relation.siblingVersions,meta:Me?h("bookPage.byEra"):h("bookPage.kindCount",{n:N}),cap:B.length,items:B.map(E=>E.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(E.edition||E.title||E.id)}):t.jsx(qe,{id:E.id,label:f(E.edition||E.title||E.id),onNavigate:o,renderLink:r,dense:!0})),metas:B.map(E=>[E.year!=null?E.year<0?h("detail.bce",{n:-E.year}):String(E.year):"",E.id===e.id?h("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:B.findIndex(E=>E.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(qe,{id:x.id,label:h("bookPage.viewAllInWork",{n:F.length}),onNavigate:o,renderLink:r,dense:!0})})]})]}),ye=e.work_id?t.jsx(Tl,{caption:m.section.belongsToWork,children:t.jsx(qe,{id:e.work_id,label:x?f(x.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(Ln,{railTop:c,back:p,up:ye,nav:J,railLinks:u,main:X,card:be,side:te})};function Gx({volumes:e,unit:n}){const{t:o}=Q();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o("bookPage.volumeRange",{range:ji(e,n),unit:n}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o("bookPage.volumeCount",{n:e.length,unit:n})]})]})}function Yx({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:a}){var w;const{t:l,convert:d}=Q(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],u=p.filter(b=>b.ref_type!=="book"),m=p.filter(b=>b.ref_type==="book"&&b.relation==="底本"),h=p.filter(b=>b.ref_type==="book"&&b.relation!=="底本"),f=(c==null?void 0:c.related_to)||[],x=p.length>0||f.length>0,k=b=>b&&Vx.has(b)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${b}`)}):"",y=(b,j)=>t.jsx(qe,{id:b,label:d(j||b),onNavigate:s,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[x&&t.jsxs("ol",{className:"bim-d-lf-list",children:[u.map((b,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:b.relation?d(b.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),b.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(b.evidence),k(b.confidence)]})]})},`a-${j}`)),m.map((b,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(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.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:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:d(o)})]}),h.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:h.map((b,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.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((b,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:b.evidence?d(b.evidence):void 0,children:[y(b.book_id,r(b.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(b.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((b,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(b.title)]}),t.jsx(Ct,{text:b.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 _n=16,Kx=200,qx=16,Pc=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var Se,X,Ce,Me,B,te,ye;const{t:p,convert:u,messages:m}=Q(),[h,f]=g.useState(""),[x,k]=g.useState(!1),[y,w]=g.useState(null),[b,j]=g.useState(""),[S,v]=g.useState(!1),$=g.useMemo(()=>$l(e,n),[e,n]),[_,C]=g.useState(new Map),M=!!o&&$.rows.length>0&&$.rows.length<=Kx,T=M&&($.rows.length<=_n||S),z=T&&$.rows.every(H=>!H.id||_.has(H.id)),F=H=>{var se;return _o(H?(se=_.get(H))==null?void 0:se.l1:void 0)},N=g.useMemo(()=>{const H=h.trim(),se=H?u(H):"";return $.rows.filter(ne=>{var Ne,Be;if(b&&_o(ne.id?(Ne=_.get(ne.id))==null?void 0:Ne.l1:void 0)!==b)return!1;if(!se)return!0;const ge=ne.id&&((Be=_.get(ne.id))==null?void 0:Be.title)||ne.title;return u(ge).includes(se)||(ne.subItems||[]).some(We=>u(We).includes(se))})},[$.rows,h,b,_,u]),R=x?N:N.slice(0,_n),O=g.useMemo(()=>(T?$.rows:R).filter(H=>H.id&&!_.has(H.id)).map(H=>H.id),[T,$.rows,R,_]);g.useEffect(()=>{if(!o||O.length===0)return;let H=!1;const se=O.slice(0,qx);return Promise.all(se.map(ne=>o.getItem(ne).then(ge=>{var We,Ue;const Ne=ge??{},Be={title:Ne.title,edition:Ne.edition,authors:Ne.authors,measure:ge?zt(ge,m.unit.juan):void 0,versionCount:Ne._edition_count??((We=Ne.books)==null?void 0:We.length),l1:((Ue=Ne.classification)==null?void 0:Ue.l1)||void 0};return[ne,Be]}).catch(()=>[ne,{}]))).then(ne=>{H||C(ge=>{const Ne=new Map(ge);for(const[Be,We]of ne)Ne.set(Be,We);return Ne})}),()=>{H=!0}},[o,O,m.unit.juan]);const I=(e.contained_in||[])[0];g.useEffect(()=>{if(!I){w(null);return}if(w({id:I}),!o)return;let H=!1;return o.getItem(I).then(se=>{H||w({id:I,title:se==null?void 0:se.title})}).catch(()=>{}),()=>{H=!0}},[o,I]);const P=g.useMemo(()=>zc(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),U=P.text.length+P.groups.reduce((H,se)=>H+se.rows.length+se.mirrors.length,0),K=e.contained_works||[],L=new Set($.rows.map(H=>H.id).filter(Boolean)),Z=K.length>0&&!K.every(H=>L.has(H.id)),A=(()=>{const H=$.rows.map(se=>se.edition).filter(Boolean);return H.length>1&&new Set(H).size===1})(),V=$.rows.some(H=>H.volumes.length>0||H.expected!=null),pe=e._member_count||((Se=e.books)==null?void 0:Se.length)||K.length,ee=zt(e,m.unit.juan),ue=e.count,me=H=>typeof H=="number"&&Number.isFinite(H)?H:null,be=me(ue==null?void 0:ue.juan)??me((X=e.juan_count)==null?void 0:X.number),Oe=me(ue==null?void 0:ue.ce)??($.totalVolumes||null),ie=[{value:$.rows.length,label:p("collectionPage.stat.titles")},{value:be??0,label:m.unit.juan},{value:Oe??0,label:m.unit.volume}],Re=g.useMemo(()=>{var ne,ge;const H=[];if((ne=e.publication_info)!=null&&ne.details&&H.push({label:p("collectionPage.fact.publication"),value:u(e.publication_info.details)}),pe&&pe!==$.rows.length){const Ne=e._member_type==="Book"?p("collectionPage.member.Book"):e._member_type==="Work"?p("collectionPage.member.Work"):p("collectionPage.member.other");H.push({label:Ne,value:`${pe} ${m.unit.bu}`,title:p("collectionPage.memberNote")})}const se=[me(ue==null?void 0:ue.zhong)!=null?p("collectionPage.nZhong",{n:ue.zhong}):"",me(ue==null?void 0:ue.han)!=null?p("collectionPage.nHan",{n:ue.han}):""].filter(Boolean);return se.length&&H.push({label:p("collectionPage.fact.expected"),value:se.join(" ")}),be==null&&ee&&H.push({label:p("collectionPage.fact.measure"),value:u(ee),title:(ge=e.juan_count)!=null&&ge.description?u(e.juan_count.description):void 0}),H},[e,pe,$.rows.length,be,ee,ue,u,p,m]),Le=g.useMemo(()=>{if(!z)return[];const H=new Map;for(const ne of $.rows){const ge=F(ne.id);ge&&H.set(ge,(H.get(ge)??0)+1)}const se=En.filter(ne=>(H.get(ne.key)??0)>0);return se.length<2?[]:[{key:"",label:`${m.catalog.all} ${$.rows.length}`},...se.map(ne=>({key:ne.key,label:`${ne.label} ${H.get(ne.key)}`}))]},[z,$.rows,_,m]),q=g.useMemo(()=>{if(!z||!$.rows.some(ge=>ge.volumes.length>0))return null;const H=[],se=$.rows.filter(ge=>ge.volumes.length>0).map(ge=>({k:F(ge.id)??"",from:Math.min(...ge.volumes),to:Math.max(...ge.volumes)})).sort((ge,Ne)=>ge.from-Ne.from);for(const ge of se){const Ne=ge.to-ge.from+1,Be=H[H.length-1];Be&&Be.key===ge.k?(Be.to=Math.max(Be.to,ge.to),Be.n+=Ne):H.push({key:ge.k,from:ge.from,to:ge.to,n:Ne})}const ne=se.reduce((ge,Ne)=>Math.max(ge,Ne.to),0);return H.length>1&&H.some(ge=>ge.key)?{segs:H,last:ne}:null},[z,$.rows,_]),J=(Ce=e.description)==null?void 0:Ce.text,fe=t.jsx(An,{kind:p("collectionPage.kind"),title:u(e.title),byline:t.jsx(jr,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Je,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(Me=e.publication_info)!=null&&Me.year?u(e.publication_info.year):""]}),description:J||(B=e.history)!=null&&B.length?t.jsxs(t.Fragment,{children:[J&&t.jsx(Ct,{text:J,style:{fontSize:15,lineHeight:1.85}}),(te=e.history)!=null&&te.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((H,se)=>t.jsx("li",{children:u(H)},se))}):null]}):void 0,clampDescription:Xo(J)||(((ye=e.history)==null?void 0:ye.length)??0)>2?6:void 0,stats:ie,facts:Re,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:q&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:p("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":p("collectionPage.dist.head"),children:q.segs.map((H,se)=>{const ne=En.find(ge=>ge.key===H.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!ne,title:ne?p("collectionPage.dist.segTitle",{section:u(ne.label),from:H.from,to:H.to}):void 0,"aria-label":ne?p("collectionPage.dist.only",{section:u(ne.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!ne&&b===H.key,style:{flexGrow:H.n,background:i(ne?ne.token:"rule")},onClick:()=>{ne&&(j(b===H.key?"":H.key),k(!1))}},se)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:p("catalog.volume",{n:1})}),t.jsx("span",{children:p("collectionPage.dist.hint")}),t.jsx("span",{children:p("catalog.volume",{n:q.last})})]})]})}),ze=[];$.rows.length&&ze.push({id:"titles",label:p("collectionPage.sec.titles"),count:$.rows.length}),U&&ze.push({id:"resources",label:p("collectionPage.sec.resources"),count:U}),Z&&ze.push({id:"works",label:m.section.containedWorks,count:K.length});const Y=t.jsxs(t.Fragment,{children:[$.rows.length>0&&t.jsxs(et,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(Je,{items:[`${$.rows.length} ${m.unit.items}`,$.totalVolumes?p("collectionPage.totalVolumes",{n:$.totalVolumes,unit:m.unit.volume}):"",N.length!==$.rows.length?p("collectionPage.currentN",{n:N.length,unit:m.unit.items}):""]}),action:a,children:[($.rows.length>_n||Le.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Le.length>0&&t.jsx(vi,{items:Le,value:b,onChange:H=>{j(H),k(!1)}}),M&&$.rows.length>_n&&!z&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>v(!0),title:p("collectionPage.loadAllTitle",{n:$.rows.length,unit:m.unit.items}),children:p(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),$.rows.length>_n&&t.jsx("input",{type:"search",className:"bim-d-find",value:h,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:H=>{f(H.target.value),k(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&ki(N.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[V&&t.jsx("th",{style:{width:"8.5em"},children:p("collectionPage.col.volumes")}),t.jsx("th",{children:p("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:p("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:R.map((H,se)=>{var Qe;const ne=H.id?_.get(H.id):void 0,ge=ne!=null&&ne.title&&H.title===H.id?ne.title:H.title,Ne=((ne==null?void 0:ne.authors)||[]).find(ce=>ce&&ce.name),Be=[Ne?`${Ne.dynasty?`〔${u(Ne.dynasty)}〕`:""}${u(Ne.name)}${Ne.role?` ${u(Ne.role)}`:""}`:"",ne!=null&&ne.measure?u(ne.measure):"",(Qe=H.subItems)!=null&&Qe.length?H.subItems.map(ce=>u(ce)).join("、"):"",(ne!=null&&ne.edition||H.edition)&&!A?u((ne==null?void 0:ne.edition)||H.edition||""):""].filter(Boolean),We=En.find(ce=>ce.key===F(H.id)),Ue=H.volumes.length>0?p("collectionPage.volumeRange",{range:ji(H.volumes,m.unit.volume),unit:m.unit.volume}):H.expected!=null?`${H.found??0}/${H.expected} ${m.unit.volume}`:"";return t.jsxs("tr",{children:[V&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ue?"":" bim-d-zt-blank"}`,children:[We&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(We.token)}}),Ue||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[H.id?t.jsx(qe,{id:H.id,label:u(ge),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(ge)}),Be.length>0?t.jsx(Je,{items:Be}):H.id&&!ne&&o?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ne!=null&&ne.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ne!=null&&ne.versionCount?p("collectionPage.nZhong",{n:ne.versionCount}):""})]},`${H.id??H.title}-${se}`)})})]}),R.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:p("catalog.noMatch")}),!x&&t.jsx(Ko,{total:N.length,shown:R.length,unit:m.unit.items,onClick:()=>k(!0)})]}),U>0&&t.jsxs(et,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:U}),children:[P.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[P.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:p("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:P.text.map((H,se)=>t.jsx(vr,{item:H,siblings:P.text},`${H.id||H.url||H.name}-${se}`))})})]}),t.jsx(Nc,{groups:P.groups})]}),$.rows.length===0&&U===0&&t.jsx(et,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),ve=Z?t.jsx(Dt,{id:"works",title:m.section.containedWorks,meta:p("collectionPage.nZhong",{n:K.length}),cap:12,items:K.map(H=>t.jsx(qe,{id:H.id,label:u(H.title),onNavigate:r,renderLink:s,dense:!0}))}):null,le=y?t.jsx(Tl,{caption:p("collectionPage.parent"),children:t.jsx(qe,{id:y.id,label:u(y.title||y.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Ln,{railTop:l,back:d,up:le,nav:ze,railLinks:c,main:Y,card:fe,side:ve})},Xx=16,eo=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function ha(e){if(!e)return eo.length;const n=eo.indexOf(e);return n===-1?eo.length:n}function Zx(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const Jx={秦:[-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]},Mc=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:a,railLinks:l})=>{var le,Se,X,Ce,Me;const{t:d,convert:c,messages:p}=Q(),u=B=>Zx(B,d),[m,h]=g.useState("全部"),[f,x]=g.useState(!1),[k,y]=g.useState("default"),[w,b]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(B=>{const te=w.get(B.work_id);return{id:B.work_id,title:(te==null?void 0:te.title)??B.title??B.work_id,role:B.role||"",cls:Go(B.role),versionCount:te==null?void 0:te.versionCount,section:te==null?void 0:te.cls,l1:te==null?void 0:te.l1,measure:te==null?void 0:te.measure,hasImage:te==null?void 0:te.hasImage,loaded:!!(te!=null&&te.loaded)}}),[e.works,w]),S=g.useMemo(()=>_l((e.works||[]).map(B=>B.role),d("detail.roleAll")),[e.works,d]),v=g.useMemo(()=>{const B=m==="全部"?j:j.filter(te=>te.cls===m);return k==="versions"?[...B].sort((te,ye)=>(ye.versionCount??-1)-(te.versionCount??-1)):B},[j,m,k]),$=f?v:v.slice(0,Xx),_=g.useMemo(()=>$.filter(B=>!w.has(B.id)).map(B=>B.id),[$,w]);g.useEffect(()=>{if(!n||_.length===0)return;let B=!1;return Promise.all(_.map(te=>n.getItem(te).then(ye=>{var ge,Ne,Be,We,Ue;const H=ye??{},se=H._edition_count??(((ge=H.books)==null?void 0:ge.length)??0)+(((Ne=H.collections)==null?void 0:Ne.length)??0),ne=[(Be=H.classification)==null?void 0:Be.l1,(We=H.classification)==null?void 0:We.l2].filter(Boolean).join(" ");return[te,{id:te,title:H.title,versionCount:se,loaded:!0,cls:ne||void 0,l1:((Ue=H.classification)==null?void 0:Ue.l1)||void 0,measure:ye&&zt(ye,p.unit.juan)||void 0,hasImage:!!(H.has_image??H._has_image)}]}).catch(()=>[te,{id:te,loaded:!0}]))).then(te=>{B||b(ye=>{const H=new Map(ye);for(const[se,ne]of te)H.set(se,ne);return H})}),()=>{B=!0}},[n,_,p.unit.juan]);const C=g.useMemo(()=>{const B=new Map;for(const te of e.alt_names||[]){const ye=te.type||p.section.aliases;B.has(ye)||B.set(ye,[]),B.get(ye).push(te.name)}return[...B.entries()].sort((te,ye)=>ha(te[0])-ha(ye[0])).map(([te,ye])=>({label:te,names:ye}))},[e.alt_names,p]),M=e.birth_year??((le=e.dates)==null?void 0:le.birth)??void 0,T=e.death_year??((Se=e.dates)==null?void 0:Se.death)??void 0,z=(X=e.dates)==null?void 0:X.floruit,F=M!=null||T!=null?`${u(M)||"?"}—${u(T)||"?"}`:Array.isArray(z)&&z.length===2&&z.every(B=>Number.isFinite(B))?d("entityPage.floruit",{from:u(z[0]),to:u(z[1])}):"",N=new Set(["本名","字","號","号"]),R=C.filter(B=>N.has(B.label)),O=C.filter(B=>!N.has(B.label)),I=O.reduce((B,te)=>B+te.names.length,0),P=g.useMemo(()=>{const B=[];for(const ye of R)B.push({label:ye.label,value:ye.names.map(H=>c(H)).join("、")});const te=(e.works||[]).length;return te&&B.push({label:d("entityPage.fact.works"),value:d("entityPage.nZhong",{n:te})}),B},[e.works,R,c,d]),U=B=>{var te;return(te=C.find(ye=>B.includes(ye.label)))==null?void 0:te.names[0]},K=U(["字"]),L=U(["號","号"]),Z=[K?d("entityPage.zi",{name:c(K)}):"",L?d("entityPage.hao",{name:c(L)}):""].filter(Boolean).join(","),A=e.native_place,V=e.dynasty?Jx[e.dynasty]:void 0,pe=(()=>{if(!V||M==null||T==null||T<M)return null;const[B,te]=V,ye=Math.max(M,B),H=Math.min(T,te);if(H<=ye)return null;const se=te-B;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":d("entityPage.lifeAria",{birth:u(M),death:u(T),years:T-M+1}),children:t.jsx("i",{style:{left:`${(ye-B)/se*100}%`,width:`${(H-ye)/se*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${u(B)} ${c(e.dynasty)}`}),t.jsx("span",{children:d("entityPage.lifeYears",{years:T-M+1})}),t.jsx("span",{children:u(te)})]})]})})(),ee=g.useMemo(()=>{if(!n||j.length===0||j.some(ye=>!ye.loaded))return null;const B=new Map;for(const ye of j){const H=_o(ye.l1);H&&B.set(H,(B.get(H)??0)+1)}const te=En.map(ye=>({...ye,n:B.get(ye.key)??0})).filter(ye=>ye.n>0);return te.length?te:null},[j,n]),ue=t.jsxs(An,{kind:p.entityPage.subtype[e.subtype]??d("entityPage.subtype.people"),title:c(e.primary_name||e.title),subtitle:Z||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Je,{items:[e.dynasty?c(e.dynasty):"",F,A?d("entityPage.nativePlace",{place:c(A)}):""]}),pe]}),description:(Ce=e.description)!=null&&Ce.text?t.jsx(Ct,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Xo((Me=e.description)==null?void 0:Me.text)?6:void 0,facts:P,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[I>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:d("entityPage.moreNames",{n:I})}),t.jsx("dl",{children:O.map(B=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:c(B.label)}),t.jsx("dd",{children:B.names.map(te=>c(te)).join("、")})]},B.label))})]}),ee&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:d("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ee.map(B=>t.jsx("i",{style:{flexGrow:B.n,background:i(B.token)}},B.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ee.map(B=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(B.token)}}),c(B.label)," ",B.n]},B.key))})]})]}),me=g.useMemo(()=>j.filter(B=>B.loaded&&(B.versionCount??0)>0).sort((B,te)=>(te.versionCount??0)-(B.versionCount??0)).slice(0,3),[j]),be=!!n&&j.length>=3&&$.some(B=>!B.loaded),Oe=m==="全部"&&(be||me.length>=2),ie=e.external_ids||{},Re=[];ie.cbdb_id!=null&&Re.push({label:"CBDB",id:String(ie.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ie.cbdb_id}`,note:ie.cbdb_match==="auto"?d("entityPage.autoMatch"):void 0});const Le=ie.wikidata_id;Le&&Re.push({label:"Wikidata",id:Le,href:`https://www.wikidata.org/wiki/${Le}`});const q=ie.viaf_id;q&&Re.push({label:"VIAF",id:q,href:`https://viaf.org/viaf/${q}`});const J=S.map(B=>({key:B.cls,label:`${B.label} ${B.count}`})),fe=[...Oe&&!be?[{id:"featured",label:d("entityPage.sec.featured"),count:me.length}]:[],...j.length?[{id:"works",label:d("entityPage.sec.allWorks"),count:j.length}]:[],...Re.length?[{id:"external",label:d("entityPage.sec.external"),count:Re.length}]:[]],ze=Oe?t.jsxs(et,{id:"featured",title:d("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:d("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":be||void 0,children:[be&&[0,1,2].map(B=>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:" "})]},B)),!be&&me.map(B=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(qe,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(Je,{items:[B.section?c(B.section):"",B.measure?c(B.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:B.versionCount}),t.jsx("span",{children:d("entityPage.versionsUnit")}),B.hasImage&&t.jsx("span",{className:"bim-d-flag",children:d("entityPage.hasImage")})]})]},B.id))]})]}):null,Y=j.length===0?t.jsx(et,{title:d("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("entityPage.empty")})}):t.jsxs(t.Fragment,{children:[ze,t.jsxs(et,{id:"works",title:d("entityPage.sec.works"),meta:t.jsx(Je,{items:[d("entityPage.total",{n:j.length}),v.length!==j.length?d("entityPage.current",{n:v.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[J.length>1&&t.jsx(vi,{items:J,value:m,onChange:B=>{h(B),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":k==="versions",onClick:()=>{k==="default"&&x(!0),y(B=>B==="default"?"versions":"default")},children:d(k==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!f&&ki(v.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("entityPage.col.work")}),t.jsx("th",{children:d("entityPage.col.section")}),t.jsx("th",{children:d("entityPage.col.role")}),t.jsx("th",{children:d("entityPage.col.versions")}),t.jsx("th",{"aria-label":d("entityPage.col.image")})]})}),t.jsx("tbody",{children:$.map(B=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(qe,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0}),B.measure?t.jsx(Je,{items:[c(B.measure)]}):!B.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.section||B.loaded?"":" bim-d-zt-blank"}`,children:B.section?c(B.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.role?"":" bim-d-zt-blank"}`,children:B.role?c(B.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.loaded?"":" bim-d-zt-blank"}`,children:B.loaded?B.versionCount?d("entityPage.nZhong",{n:B.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:d("entityPage.notRecorded")}):""}),t.jsx("td",{className:B.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:B.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:d("entityPage.hasImage")})})]},B.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d("entityPage.emptyRole")}),!f&&t.jsx(Ko,{total:v.length,shown:$.length,unit:d("entityPage.moreUnit"),onClick:()=>x(!0)})]})]}),ve=Re.length>0?t.jsx(Dt,{id:"external",title:d("entityPage.sec.external"),items:Re.map(B=>t.jsxs("a",{href:B.href,target:"_blank",rel:"noopener noreferrer",children:[B.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Re.map(B=>B.id),foot:ie.cbdb_id!=null&&ie.cbdb_match==="auto"?d("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Ln,{railTop:s,back:a,nav:fe,railLinks:l,main:Y,card:ue,side:ve})},wr="(max-width: 719px)",Qx=`${wr}, (pointer: coarse)`,Bc=`
1303
+ ${J??""}`,[qt,mn]=g.useState({key:Pt,data:ce,started:!!ce});if(qt.key!==Pt)mn({key:Pt,data:ce,started:!1});else if(ce!==qt.data&&(mn({key:Pt,data:ce,started:!!ce}),ce)){const W=ce.pages??[];(!qt.started||!W.some(he=>he.page===De))&&Tt(He(ce))}g.useEffect(()=>{ae(new Set),ke(null)},[J,ee]);const On=g.useCallback(W=>{if(ae(new Set(W)),W.length>0){const he=W[0],Ae=parseInt(he.split(":")[0],10);isNaN(Ae)||Tt(Ae)}},[]),ft=g.useMemo(()=>{const W=new Map;for(const he of(ce==null?void 0:ce.pages)??[])W.set(he.page,he);return W},[ce]),hn=Ge(ce),Hn=g.useCallback(W=>{var Fe;const he=Qe.images;if(!he||he.length===0)return;const Ae=(Fe=ft.get(W))==null?void 0:Fe.seq;return(Ae?he.find(Ke=>Ke.seq===Ae):void 0)??he.find(Ke=>Ke.pageNo===W)??he[W-1]},[Qe.images,ft]),Ir=D>1.5,Fn=g.useCallback((W,he=!1)=>{const Ae=Hn(W);return Ae?W===hn||he?Ae.hiresUrl??Ae.url:Ae.url:W===hn?(ce==null?void 0:ce.imageUrl)??"":""},[Hn,ce,hn]),Rd=g.useMemo(()=>Fn(De,Ir),[Fn,De,Ir]),gn=g.useMemo(()=>[...ft.keys()].sort((W,he)=>W-he),[ft]),Ei=g.useRef(De);Ei.current=De;const fn=g.useCallback(W=>{var Ke;const he=Ei.current,Ae=gn.indexOf(he),Fe=gn[Ae<0?0:Ae+W];Fe===void 0||Fe===he||(Ei.current=Fe,Tt(Fe),(Ke=ft.get(Fe))!=null&&Ke.columns.some(it=>it.chars.length>0)&&_e(it=>({page:Fe,nonce:((it==null?void 0:it.nonce)??0)+1})))},[gn,ft]),Ii=gn.indexOf(De),Ld=g.useCallback(W=>{if(W.altKey||W.ctrlKey||W.metaKey)return;const he=W.target.tagName;he==="INPUT"||he==="TEXTAREA"||he==="SELECT"||(W.key==="ArrowLeft"||W.key==="PageUp"?(W.preventDefault(),fn(-1)):(W.key==="ArrowRight"||W.key==="PageDown")&&(W.preventDefault(),fn(1)))},[fn]);g.useEffect(()=>{if(ce)for(const W of[1,-1,2,3]){const he=Fn(De+W);he&&yo(he)}},[ce,De,Fn]);const Rr=g.useMemo(()=>{var Dr;if(!ce)return null;if(De===hn)return ce;const W=ft.get(De);if(W&&W.width>0&&W.height>0)return{page_id:`p:${De}`,title:`第${De}葉`,image_size:[W.width,W.height],total_warped_w:W.width,columns:[{col:1,warped_w:W.width,warped_h:W.height,offset_x:0,strips:[],chars:W.columns.flatMap(Ye=>Ye.chars).map(Ye=>({id:Ye.id,char:Ye.char,slot:Ye.slot,pos:Ye.pos,sub:Ye.sub,bbox_col:Ye.bbox??[0,0,0,0]}))}]};const he=(Dr=ce.pages)==null?void 0:Dr.find(Ye=>Ye.page===De),[Ae,Fe]=ce.image_size||[2386,3082],Ke=Hn(De),it=(Ke==null?void 0:Ke.width)??Ae,Mi=(Ke==null?void 0:Ke.height)??Fe,Or=it/Ae,Hr=Mi/Fe,Fr=new Map;for(const Ye of ce.columns){const lt=(Ye.strips||[]).flatMap(Vn=>Vn.srcQuad.map(Gn=>Gn[0]));if(lt.length===0)continue;const kt=Ye.top_y??0,Bi=Ye.bottom_y??kt+Ye.warped_h;Fr.set(Ye.col,{x0:Math.min(...lt),x1:Math.max(...lt),top:kt,slotH:(Bi-kt)/21})}return{page_id:`p:${De}`,title:`第${De}葉`,image_size:[it,Mi],total_warped_w:it,columns:he?he.columns.map(Ye=>{const lt=Fr.get(Ye.col)??{x0:0,x1:0,top:0,slotH:118};return{col:Ye.col,warped_w:it,warped_h:Mi,offset_x:0,strips:[],chars:Ye.chars.map(kt=>{const Bi=kt.slot??kt.pos??0,Vn=(lt.top+(Bi-1)*lt.slotH)*Hr,Gn=(lt.x0+lt.x1)/2,[Fd,Dd]=kt.sub==="a"?[Gn,lt.x1]:kt.sub==="b"?[lt.x0,Gn]:[lt.x0,lt.x1];return{...kt,bbox_col:[Fd*Or,Vn,Dd*Or,Vn+lt.slotH*Hr]}})}}):[]}},[ce,De,hn,ft,Hn]),{entryTitle:Dn,authors:Lr}=Ig(e,n,l===void 0),[Ar,Ri]=g.useState("text");if(g.useEffect(()=>{Ri("text")},[J,ee]),O==="loading")return t.jsx(As,{className:S,style:v,title:l??Dn,label:$("reader.loading")});if(O==="missing"||!N||!V)return t.jsx("div",{className:S,style:{...v,...Ls},children:$("reader.noText")});if(Le==="failed")return t.jsx("div",{className:S,style:{...v,...Ls},children:$("reader.tocFailed")});if(!ie)return t.jsx(As,{className:S,style:v,title:l??Dn,label:$("reader.tocLoading")});const Mt=zg(V,ie),Ad=Tg(ie,Be,Mt,_,ye),Li=N.versions.map(W=>({key:W.key,label:we.textVersionLabel(W),optionLabel:_(we.textVersionLabel(W)),sourceName:W.source_name?_(W.source_name):void 0,license:W.license??void 0,sourceUrl:W.source_url??void 0,primary:W.key===pe})),at=$g((Wr=ie.source)==null?void 0:Wr.upstream),Un=(typeof l=="string"?_(l):l)??(ie.title?_(ie.title):Dn?_(Dn):void 0),Pd=Un?t.jsx("a",{href:z(e),title:$("reader.viewEntry"),onClick:a?W=>{W.metaKey||W.ctrlKey||(W.preventDefault(),a(e))}:void 0,children:Un}):void 0,Md=Lr.length>0?_(Lr.slice(0,2).map(W=>`${W.dynasty?`〔${W.dynasty}〕`:""}${W.name}${` ${W.role||$("reader.defaultRole")}`}`).join("、")):void 0,Ai=fe?dc(fe,Mt,_,ye):void 0,Xt=ye&&!!(le!=null&&le.json),Bt=(le==null?void 0:le.json)??null,Zt=(le==null?void 0:le.md)??null,Pr=Xt&&!ge&&Ql(Bt.sections),Bd=Pr&&!(Zt&&M.readingMode==="paragraph"&&si(Zt)),Wd=Xt&&Pr?t.jsx(qh,{juan:Bt,view:Ar,onView:Ri,textHasEntries:Bd}):void 0,Od=il(ie)||so(ie),Pi=Zt?Zt.replace(/^##\s+[^\n]+\n+/,""):null,Hd=(typeof d=="string"?_(d):d)??(V.source_name?_(V.source_name):_(we.textVersionLabel(V)));return t.jsxs(bl,{className:S,style:v,title:Pd,subtitle:Hd,byline:Md,current:Ai,pagerUnit:Mt,rail:Wd,revisedAt:f,backHref:x,backLabel:k,onReportError:h?W=>h({...W,bookTitle:typeof Un=="string"?Un:void 0,entryId:e}):void 0,workLinkToggle:Xt&&!ge&&!!a&&!!(Bt!=null&&Bt.sections.some(W=>W.work_id)),toc:Ad,tocCaption:$("reader.tocCaption",{n:ie.chapters.length,unit:_(Mt)}),tocHeader:ye&&ie.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:ge?$("reader.searchChaptersPlaceholder"):$("reader.searchUnitPlaceholder",{unit:_(Mt)}),"aria-label":ge?$("reader.searchChapters"):$("reader.searchUnit",{unit:_(Mt)}),value:H,onChange:W=>se(W.target.value)}):void 0,activeKey:J??null,onSelect:ve,images:Qe.images,imagesLoading:Qe.loading||tt,renderImageOverlay:p,imagePanel:ce?"open":u,isWarpMode:!!ce,customImagePanel:ce&&Rr?t.jsxs("div",{className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Ld,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:i("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",disabled:Ii<=0,onClick:()=>fn(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":De,style:{fontSize:11,padding:"1px 6px",background:i("rule"),borderRadius:10},children:["第 ",De," 葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",disabled:Ii<0||Ii>=gn.length-1,onClick:()=>fn(1),children:"›"})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[oe.size>0&&t.jsxs("button",{type:"button",onClick:()=>ae(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${i("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",oe.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:D<=1,onClick:()=>{var W;return(W=Ee.current)==null?void 0:W.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(D*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:D>=6,onClick:()=>{var W;return(W=Ee.current)==null?void 0:W.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:D===1,onClick:()=>{var W;return(W=Ee.current)==null?void 0:W.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(Sg,{ref:Ee,resetKey:De,onScaleChange:re,style:{flex:1,minHeight:0},children:t.jsx(dr,{imageUrl:Rd,pageData:Rr,selectedCharIds:oe,hoveredCharId:je,preserveMargins:de,onCharClick:W=>{ae(Ae=>{const Fe=new Set(Ae);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const he=document.querySelector(`[data-char-id="${W}"]`);he&&he.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:ke})}),t.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"8px 0 2px"},children:t.jsxs("div",{style:{display:"inline-flex",border:`1px solid ${i("rule")}`,borderRadius:4,overflow:"hidden"},children:[t.jsx("button",{type:"button",onClick:()=>Te(!1),"aria-pressed":!de,className:`bim-rd-t ${de?"":"bim-rd-on"}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:de?"transparent":i("accent-bg"),color:de?"inherit":i("accent")},title:"去空白:紧凑裁切版心",children:"去空白"}),t.jsx("button",{type:"button",onClick:()=>Te(!0),"aria-pressed":de,className:`bim-rd-t ${de?"bim-rd-on":""}`,style:{fontSize:11,padding:"2px 10px",lineHeight:"18px",border:"none",borderRadius:0,cursor:"pointer",background:de?i("accent-bg"):"transparent",color:de?i("accent"):"inherit"},title:"保留空白:完整呈现古籍天头地脚与白边",children:"保留空白"})]})})]}):void 0,toolbarExtra:ce?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-badge-warp",children:"图文对读"}),t.jsx("button",{type:"button",className:`bim-rd-t ${xe?"bim-rd-on":""}`,"aria-pressed":xe,title:"切换外挂现代断句标点",onClick:()=>G(W=>!W),children:xe?"标点":"无标点"})]}):void 0,prefs:M,onPrefsChange:T,versions:Li.length>1?Li:void 0,currentVersionKey:Li.length>1?V.key:void 0,onVersionChange:Y,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:si(Zt),allowVertical:m,children:[B&&t.jsx(Yt,{}),!B&&ce&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:fe!=null&&fe.title?_(fe.title):Ai}),(V.source_name||V.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[V.source_name&&_(V.source_name),V.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),V.license]})]})]}),t.jsx(gr,{pageData:ce,pages:ce.pages,punctuations:ce.punctuations||[],selectedCharIds:oe,hoveredCharId:je,onSelectionChange:On,onCharClick:W=>{ae(Ae=>{const Fe=new Set(Ae);return Fe.has(W)?Fe.delete(W):(Fe.clear(),Fe.add(W)),Fe});const he=parseInt(W.split(":")[0],10);isNaN(he)||Tt(he)},onCharHover:ke,mode:"horizontal",showPunctuation:xe,entities:M.properNames?E:void 0,entityTransport:n,onEntityNavigate:j,onVisiblePageChange:W=>Tt(W),convert:_,scrollToPage:Pe})]}),!B&&!ce&&Xt&&Bt&&t.jsx(Yh,{juan:Bt,rawText:Zt,positionLabel:Ng(fe,ie,Mt,_),groupLabel:Eg(ie,J??null),index:Cg(e,ie),searchQuery:H,onNavigate:a,transport:n,workLabelCache:We,prefs:M,view:Ar,onViewChange:Ri},`${ee}/${J}`),!B&&!ce&&!Xt&&Pi!=null&&fe&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:fe.title?_(fe.title):Ai}),(V.source_name||V.license)&&t.jsxs("p",{className:"bim-rd-meta",children:[V.source_name&&t.jsxs(t.Fragment,{children:[$("reader.textSource")," ",V.source_url?t.jsx("a",{className:"bim-rd-link",href:V.source_url,target:"_blank",rel:"noreferrer",children:_(V.source_name)}):_(V.source_name)]}),V.source_name&&V.license&&t.jsx("span",{className:"bim-rd-dot"}),V.license]}),at&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[$("reader.upstream")," ",at.url?t.jsx("a",{className:"bim-rd-link",href:at.url,target:"_blank",rel:"noreferrer",children:_(at.name??at.url)}):_(at.name??""),at.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),at.license_url?t.jsx("a",{className:"bim-rd-link",href:at.license_url,target:"_blank",rel:"noreferrer",children:at.license}):at.license]}),at.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(al,{text:at.note,convert:_})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(ir,{text:Pi,mode:M.readingMode,tables:Od,gujiMarkdown:so(ie),properNames:M.properNames})})]}),!B&&!ce&&!Xt&&Pi==null&&fe&&t.jsx("div",{className:"bim-rd-state",children:$("reader.chapterFailed")}),ie.references&&ie.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:$("reader.references")}),t.jsx("ol",{children:ie.references.map((W,he)=>t.jsxs("li",{children:[W.url?t.jsx("a",{className:"bim-rd-link",href:W.url,target:"_blank",rel:"noopener noreferrer",children:_(W.title)}):t.jsx("span",{children:_(W.title)}),W.author&&t.jsxs("span",{children:[",",_(W.author)]}),W.note&&t.jsxs("span",{children:["。",_(W.note)]})]},he))})]})]})};function Ng(e,n,o,r){var a,l;if(!e)return;const s=(l=(a=n.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(s?`${s}冊`:`${o}${e.n}`)}function Eg(e,n){if(!n)return;const o=r=>{var s;for(const a of r??[]){const l=o(a.children);if(l)return l;if((s=a.files)!=null&&s.includes(n))return a.label}};return o(e.juan_groups)}function Ig(e,n,o){const[r,s]=g.useState({entryTitle:void 0,authors:[]});return g.useEffect(()=>{if(s({entryTitle:void 0,authors:[]}),typeof n.getItem!="function")return;let a=!1;return Promise.resolve(n.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);s({entryTitle:o&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,n,o]),r}const pc={bug:{key:"bug",color:i("danger")},resource:{key:"resource",color:i("primary")},suggestion:{key:"suggestion",color:i("primary")},other:{key:"other",color:i("desc-fg")}},Rg=pc.other,uc={pending:{key:"pending",color:i("warning")},in_progress:{key:"in_progress",color:i("primary")},resolved:{key:"resolved",color:i("success")},wontfix:{key:"wontfix",color:i("desc-fg")},duplicate:{key:"duplicate",color:i("desc-fg")}},Lg=uc.pending;function Ag(e){try{const n=new Date(e),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return e}}function Pg(e,n){if(!e)return!1;try{const o=new URL(e,n);if(o.protocol!=="http:"&&o.protocol!=="https:")return!1;const r=new URL(n);return o.hostname===r.hostname}catch{return!1}}const br=({items:e,loading:n})=>{const o=Xe(),{t:r,convert:s}=Q();return n?t.jsx(Yt,{}):e.length===0?t.jsx("div",{style:Mg,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=pc[a.type]||Rg,d=uc[a.status]||Lg,c=typeof window<"u"&&Pg(a.pageUrl,window.location.href);return t.jsxs("div",{style:Bg,children:[t.jsxs("div",{style:Wg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ms,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Ms,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Og,children:Ag(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Hg,children:[a.resourceId&&t.jsx("a",{href:o(a.resourceId),style:qi,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:qi,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:qi,children:a.pageUrl}))]}),t.jsx("div",{style:Fg,children:s(a.content)}),a.reply&&t.jsxs("div",{style:Dg,children:[t.jsx("div",{style:Ug,children:r("feedback.reply")}),t.jsx("div",{children:s(a.reply)})]})]},a.id)})})},Mg={textAlign:"center",padding:"40px 0",color:i("desc-fg"),fontSize:"14px"},Bg={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"16px"},Wg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ms={fontSize:"12px",color:i("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Og={fontSize:"12px",color:i("desc-fg")},Hg={fontSize:"12px",marginBottom:"6px"},qi={color:i("primary"),textDecoration:"none",borderBottom:`1px dashed ${i("primary")}`},Fg={fontSize:"14px",lineHeight:"1.6",color:i("fg"),whiteSpace:"pre-wrap"},Dg={marginTop:"12px",padding:"10px 12px",background:i("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:i("fg")},Ug={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:i("primary")},vo=({transport:e,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:a})=>{const l=$e(),[d,c]=g.useState(null),[p,u]=g.useState([]),[m,h]=g.useState("recommend"),[f,x]=g.useState([]),[k,y]=g.useState(!1),w=r??m,b=O=>{h(O),s==null||s(O)},[j,S]=g.useState(!0),[v,$]=g.useState(null),[_,C]=g.useState(null),[M,T]=g.useState(null);g.useEffect(()=>{let O=!1;if(e.getCounts)return e.getCounts().then(I=>{O||c({works:I.works,books:I.books,collections:I.collections})}).catch(()=>{}),()=>{O=!0}},[e]),g.useEffect(()=>{let O=!1;return(async()=>{if(o)return o;if(e.getRecommended)try{const P=await e.getRecommended();if(P!=null&&P.groups)return P.groups.flatMap(U=>U.items.map(K=>({...K,group:U.name})))}catch{}return[]})().then(async P=>{if(O)return;const U=P.filter(L=>L.id);if(U.length===0){S(!1);return}const K=await Promise.all(U.map(async L=>{if(L.type)return{id:L.id,title:L.title,type:L.type,author:L.author,dynasty:L.dynasty,role:L.role,edition:L.edition,has_text:L.has_text,has_image:L.has_image,has_collated:L.has_collated,subtype:L.subtype,primary_name:L.primary_name,group:L.group,fallbackDescription:L.description};try{let Z=null;if(e.getEntry)Z=await e.getEntry(L.id);else{const A=await e.getItem(L.id);A&&(Z={id:L.id,title:A.title||L.id,type:A.type||"work"})}if(Z)return{...Z,group:L.group,fallbackDescription:L.description}}catch{}return{id:L.id,title:L.title,type:we.extractType(L.id),group:L.group,fallbackDescription:L.description}}));O||(u(K.filter(L=>L!==null)),S(!1))}),()=>{O=!0}},[e,o]);const z=g.useRef(!1),F=g.useRef(!1),N=g.useRef(!1);g.useEffect(()=>{if(w!=="catalog"||z.current)return;const O=e.getCatalogProgress??e.getResourceProgress;if(!O)return;z.current=!0;let I=!1;return O.call(e).then(P=>{I||$(P)}).catch(()=>{z.current=!1}),()=>{I=!0}},[e,w]),g.useEffect(()=>{if(w!=="collection"||F.current||!e.getCollectionProgress)return;F.current=!0;let O=!1;return e.getCollectionProgress().then(I=>{O||C(I)}).catch(()=>{F.current=!1}),()=>{O=!0}},[e,w]),g.useEffect(()=>{if(w!=="site"||N.current||!e.getSiteProgress)return;N.current=!0;let O=!1;return e.getSiteProgress().then(I=>{O||T(I)}).catch(()=>{N.current=!1}),()=>{O=!0}},[e,w]),g.useEffect(()=>{if(!a||w!=="feedback")return;let O=!1;return y(!0),fetch(a).then(I=>I.json()).then(I=>{!O&&I.success&&x(I.items||[])}).catch(()=>{}).finally(()=>{O||y(!1)}),()=>{O=!0}},[a,w]);const R=O=>t.jsx(un,{type:O,size:12});return t.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:i("fg")},children:t.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[t.jsxs("div",{style:{display:"flex",borderBottom:`1px solid ${i("widget-border")}`,marginBottom:"16px"},children:[t.jsx(kn,{label:l.home.recommendTab,active:w==="recommend",onClick:()=>b("recommend")}),t.jsx(kn,{label:l.home.catalogTab,active:w==="catalog",onClick:()=>b("catalog")}),t.jsx(kn,{label:l.home.collectionTab,active:w==="collection",onClick:()=>b("collection")}),t.jsx(kn,{label:l.home.siteTab,active:w==="site",onClick:()=>b("site")}),a&&t.jsx(kn,{label:l.home.feedbackTab,active:w==="feedback",onClick:()=>b("feedback")})]}),w==="recommend"&&t.jsx(Vg,{recommended:p,loading:j,onNavigate:n,getIcon:R,t:l}),w==="catalog"&&t.jsx(Bs,{progress:v,t:l,onNavigate:n}),w==="collection"&&t.jsx(Bs,{progress:_,t:l,onNavigate:n}),w==="site"&&t.jsx(Yg,{progress:M,t:l,totalWorks:(d==null?void 0:d.works)??0}),w==="feedback"&&a&&t.jsx(br,{items:f,loading:k})]})})},kn=({label:e,active:n,onClick:o})=>t.jsx("button",{onClick:o,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:i(n?"primary":"desc-fg"),background:"none",border:"none",borderBottom:n?`2px solid ${i("primary")}`:"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:e}),Vg=({recommended:e,loading:n,onNavigate:o,getIcon:r,t:s})=>{const a=Xe();if(n)return t.jsx(Yt,{});if(e.length===0)return null;const l=new Map;for(const d of e){const c=d.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(d)}return t.jsx(t.Fragment,{children:Array.from(l.entries()).map(([d,c])=>t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:d}),t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(p=>{const u=p.dynasty||p.author?`${p.dynasty?`〔${p.dynasty}〕`:""}${p.author||""}`:p.fallbackDescription;return t.jsxs("a",{href:a(p.id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o==null||o(p.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,cursor:"pointer",background:i("input-bg"),textDecoration:"none",color:"inherit"},children:[t.jsx("span",{style:{fontSize:"20px"},children:r(p.type)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[p.title,p.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:p.edition})]}),u&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},p.id)})})]},d))})},Bs=({progress:e,t:n,onNavigate:o})=>{if(!e)return t.jsx(Yt,{});const r=[...e.resources].sort((d,c)=>d.priority-c.priority),s=["in_progress","done","todo"],a={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:i("progress-active"),done:i("progress-done"),todo:i("progress-todo")};return t.jsx("div",{children:s.map(d=>{const c=r.filter(p=>p.status===d);return c.length===0?null:t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[d]}}),a[d]," (",c.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(p=>t.jsx(Gg,{item:p,t:n,statusColor:l[d],onNavigate:o},p.id))})]},d)})})},Gg=({item:e,t:n,statusColor:o,onNavigate:r})=>{const s=Xe(),a=e.total>0?Math.round(e.imported/e.total*100):0,l=e.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const d=e.edition?`${e.name}·${e.edition}`:e.name,c=e.collection_id||e.work_id;return c&&r?t.jsx("a",{href:s(c),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},onMouseEnter:p=>p.currentTarget.style.borderBottomStyle="solid",onMouseLeave:p=>p.currentTarget.style.borderBottomStyle="dashed",children:d}):e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:d}):d})()}),t.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:i("widget-border"),color:i("desc-fg"),whiteSpace:"nowrap"},children:e.collection_id?n.indexType.collection:e.work_id?n.indexType.work:l})]}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.total>0?pt(n.home.progressFormat,{imported:String(e.imported),total:String(e.total)}):n.home.totalPending})]}),e.total>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${a}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},Yg=({progress:e,t:n,totalWorks:o})=>{if(!e)return t.jsx(Yt,{});const r=[...e.resources].sort((c,p)=>c.priority-p.priority),s=r.filter(c=>c.imported>0),a=r.filter(c=>c.imported===0),l=s.reduce((c,p)=>Math.max(c,p.imported),0),d=o>0?Math.round(l/o*100):0;return t.jsxs("div",{children:[o>0&&t.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:`color-mix(in srgb, ${i("primary")} 6%, transparent)`,fontSize:"13px",color:i("fg")},children:[n.home.siteCoverage,": ",t.jsx("strong",{children:l.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",d,"%)"]}),s.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-done")}}),n.home.statusInProgress," (",s.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(c=>t.jsx(Ws,{item:c,t:n,totalWorks:o},c.id))})]}),a.length>0&&t.jsxs("div",{style:{marginBottom:"20px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:i("desc-fg"),marginBottom:"8px"},children:[t.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:i("progress-todo")}}),n.home.statusTodo," (",a.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(c=>t.jsx(Ws,{item:c,t:n,totalWorks:o},c.id))})]})]})},Ws=({item:e,t:n,totalWorks:o})=>{const r=o>0?Math.round(e.imported/o*100):0;return t.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:`1px solid ${i("widget-border")}`,background:i("input-bg")},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:t.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:e.url?t.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:e.name}):e.name})}),t.jsx("span",{style:{fontSize:"12px",color:i("desc-fg"),whiteSpace:"nowrap",marginLeft:"8px"},children:e.imported>0?`${e.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),e.imported>0&&o>0&&t.jsx("div",{style:{height:"4px",borderRadius:"2px",background:i("widget-border"),overflow:"hidden",marginBottom:"4px"},children:t.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i("progress-done"),transition:"width 0.3s ease"}})}),e.description&&t.jsx("div",{style:{fontSize:"12px",color:i("desc-fg"),marginTop:"4px"},children:e.description})]})},Os="(max-width: 768px)";function Kg(){const[e,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(Os).matches);return g.useEffect(()=>{const o=window.matchMedia(Os),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),e}const qg=({transport:e,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var F;const a=$e(),{convert:l}=Ie(),d=Kg(),[c,p]=g.useState(null),[u,m]=g.useState(null),[h,f]=g.useState(!1),[x,k]=g.useState("detail"),[y,w]=g.useState([]),[b,j]=g.useState(!1),S=g.useCallback(async N=>{if(!e.getCollectionCatalogs&&!e.getCollectionCatalog){w([]);return}j(!0);try{if(e.getCollectionCatalogs){const R=await e.getCollectionCatalogs(N);w(R||[])}else if(e.getCollectionCatalog){const R=await e.getCollectionCatalog(N);w(R?[{resource_id:"",data:R}]:[])}}catch{w([])}finally{j(!1)}},[e]),v=g.useCallback(async N=>{if(o){o(N);return}p(N),m(null),w([]),k("detail"),f(!0);try{const R=await e.getItem(N.id);R&&(m(R),R.type==="collection"&&S(N.id))}catch(R){console.error("加载详情失败:",R)}finally{f(!1)}},[e,o,S]),$=g.useCallback(async N=>{m(null),w([]),k("detail"),f(!0);try{const R=await e.getItem(N);R&&(m(R),p({id:N,title:R.title||N,type:R.type||"book"}),R.type==="collection"&&S(N))}catch(R){console.error("导航失败:",R)}finally{f(!1)}},[e,S]),_=typeof(u==null?void 0:u.text_count)=="number"&&u.text_count>0,C=(u==null?void 0:u.type)==="collection"&&(y.length>0||b)||(u==null?void 0:u.type)==="work"&&_,M=d&&(h||u),T=g.useCallback(()=>{p(null),m(null),w([]),k("detail")},[]),z=t.jsx(t.Fragment,{children:h?t.jsx(Yt,{}):u?t.jsxs(t.Fragment,{children:[(C||s)&&t.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:`1px solid ${i("widget-border")}`,padding:d?"0 12px":"0 48px",background:i("input-bg"),flexShrink:0,overflowX:d?"auto":void 0},children:[C&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>k("detail"),style:Zn(x==="detail"),children:a.detailTab.basicInfo}),u.type==="collection"&&b&&y.length===0&&t.jsxs("button",{onClick:()=>{},style:Zn(!1),children:[a.detailTab.catalog,t.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&y.map(N=>t.jsx("button",{onClick:()=>k(`catalog:${N.resource_id}`),style:Zn(x===`catalog:${N.resource_id}`),children:N.short_name?`${l(N.short_name)}${a.detailTab.catalogSuffix}`:a.detailTab.collectionCatalog},N.resource_id)),u.type==="work"&&_&&t.jsx("button",{onClick:()=>k("collated"),style:Zn(x==="collated"),children:a.detailTab.collatedEdition})]}),s&&t.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),t.jsx("div",{style:{padding:d?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:x==="detail"?t.jsx(Bo,{data:u,transport:e,onNavigate:$}):x.startsWith("catalog:")?t.jsx(Wo,{data:(F=y.find(N=>`catalog:${N.resource_id}`===x))==null?void 0:F.data,onNavigate:$}):x==="collated"?t.jsx(xr,{id:u.id,transport:e,onNavigate:$}):null})]}):t.jsx(vo,{transport:e,onNavigate:$,recommendedIds:r})});return d?t.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:M?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"8px 12px",borderBottom:`1px solid ${i("widget-border")}`,background:i("input-bg"),flexShrink:0},children:t.jsxs("button",{onClick:T,style:{padding:"4px 12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px"},children:["← ",a.detailTab.basicInfo]})}),t.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:z})]}):t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsx(ro,{transport:e,onEntryClick:v,hideModeIndicator:n}),!u&&t.jsx(vo,{transport:e,onNavigate:$,recommendedIds:r})]})}):t.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:i("bg"),color:i("fg")},children:[t.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:`1px solid ${i("widget-border")}`,display:"flex",flexDirection:"column",background:i("input-bg"),overflow:"hidden"},children:t.jsx("div",{style:{flex:1,overflow:"auto"},children:t.jsx(ro,{transport:e,onEntryClick:v,hideModeIndicator:n})})}),t.jsx("div",{style:{flex:1,overflow:"auto",background:i("bg"),display:"flex",flexDirection:"column"},children:z})]})};function Zn(e){return{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"primary":"desc-fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}const Xg=({pageData:e,rawImageUrl:n="",punctuations:o=[],title:r,subtitle:s,onBack:a,className:l="",style:d={}})=>{const[c,p]=g.useState(new Set),[u,m]=g.useState(null),[h,f]=g.useState("horizontal"),[x,k]=g.useState(!0),y=g.useRef(null),w=g.useCallback(v=>{p(new Set(v))},[]),b=g.useCallback(v=>{if(p($=>{const _=new Set($);return _.has(v)?_.delete(v):(_.clear(),_.add(v)),_}),y.current){const $=y.current.querySelector(`[data-char-id="${v}"]`);$&&$.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var v;p(new Set),window.getSelection&&((v=window.getSelection())==null||v.removeAllRanges())},S=o.length>0?o: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}),s&&t.jsx("span",{style:{fontSize:"0.85rem",color:i("meta-fg")},children:s}),t.jsx("span",{className:"guji-reader-tag",children:"WebGL 客户端透视矫正对读"})]}),t.jsxs("div",{className:"guji-reader-actions",children:[t.jsxs("span",{style:{fontSize:"0.85rem",color:i("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:i("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:()=>k(v=>!v),className:`guji-reader-btn ${x?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:x?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f(v=>v==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:h==="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(dr,{imageUrl:n,pageData:e,selectedCharIds:c,hoveredCharId:u,onCharClick:b,onCharHover:m})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:y,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:h==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(gr,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:u,onSelectionChange:w,onCharClick:b,onCharHover:m,mode:h,showPunctuation:x})]})]})]})},Zg=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function Qt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Jg(e){var r,s,a,l,d,c;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return[];const o=[];for(const p of n){if(!p||typeof p!="object")continue;const u=p,m=Qt((r=u.page)==null?void 0:r.index),h=Array.isArray(u.cells)?u.cells:[];if(m===void 0||h.length===0)continue;const f=new Map;for(const x of h){if(!x||typeof x!="object")continue;const k=x,y=Zg.exec(String(k.a??""));if(!y||typeof k.c!="string")continue;const w=parseInt(y[2],10),b=parseInt(y[3],10),j=Array.isArray(k.box)&&k.box.length===4&&k.box.every($=>Qt($)!==void 0)?k.box:null,S={id:String(k.a),char:k.c,slot:b,pos:b,sub:y[4]||null,bbox:j?[j[0],j[1],j[0]+j[2],j[1]+j[3]]:null};let v=f.get(w);v||f.set(w,v=[]),v.push(S)}o.push({page:m,seq:String(((s=u.canvas)==null?void 0:s.seq)??""),width:Qt((a=u.canvas)==null?void 0:a.width)??Qt((l=u.image)==null?void 0:l.width)??0,height:Qt((d=u.canvas)==null?void 0:d.height)??Qt((c=u.image)==null?void 0:c.height)??0,columns:Array.from(f.entries()).sort((x,k)=>x[0]-k[0]).map(([x,k])=>({col:x,chars:k}))})}return o}function Qg(e){const n=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.punctuations)?e.punctuations:[],o=[];for(const r of n){if(!r||typeof r!="object")continue;const s=r;typeof s.anchor!="string"||typeof s.mark!="string"||o.push({id:typeof s.id=="string"?s.id:void 0,anchor:s.anchor,mark:s.mark,kind:s.kind,pos:s.pos,pre_char:s.pre_char})}return o}function ef(e){var o;const n=e&&typeof e=="object"?e.pages:void 0;if(!Array.isArray(n))return null;for(const r of n){const s=/\/iiif\/([^/]+)\/canvas\/([^/]+)\//.exec(String(((o=r==null?void 0:r.canvas)==null?void 0:o.id)??""));if(s)return{bookId:s[1],vol:s[2]}}return null}const tf=/^(\d+):(-?\d+):(-?\d+)([a-z]?)$/;function mt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Hs(e){const n=e&&typeof e=="object"?e.pages:void 0;return Array.isArray(n)?n.filter(o=>!!o&&typeof o=="object"):[]}function nf(e,n){var l,d,c,p,u,m,h,f,x,k;const o=new Map,r=new Map;for(const y of Hs(n)){const w=mt(y.page);if(w!==void 0){o.set(w,y);for(const b of Array.isArray(y.cells)?y.cells:[]){const j=b==null?void 0:b.box;typeof(b==null?void 0:b.a)=="string"&&Array.isArray(j)&&j.length===4&&j.every(S=>mt(S)!==void 0)&&r.set(b.a,[j[0],j[1],j[0]+j[2],j[1]+j[3]])}}}const s=[];for(const y of Hs(e)){const w=mt(y.page);if(w===void 0)continue;const b=[];for(const S of Array.isArray(y.columns)?y.columns:[]){const v=mt(S==null?void 0:S.col);if(v===void 0)continue;const $=[];for(const _ of Array.isArray(S.cells)?S.cells:[]){const C=tf.exec(String((_==null?void 0:_.a)??""));if(!C||typeof _.c!="string")continue;const M=parseInt(C[3],10);$.push({id:_.a,char:_.c,slot:M,pos:M,sub:C[4]||null,bbox:r.get(_.a)??null})}$.length>0&&b.push({col:v,chars:$})}if(b.length===0)continue;b.sort((S,v)=>S.col-v.col);const j=o.get(w);s.push({page:w,seq:String(((l=j==null?void 0:j.canvas)==null?void 0:l.seq)??""),width:mt((d=j==null?void 0:j.canvas)==null?void 0:d.width)??mt((c=j==null?void 0:j.image)==null?void 0:c.width)??0,height:mt((p=j==null?void 0:j.canvas)==null?void 0:p.height)??mt((u=j==null?void 0:j.image)==null?void 0:u.height)??0,columns:b})}const a=new Set(s.map(y=>y.page));for(const[y,w]of o){const b=(m=w==null?void 0:w.canvas)==null?void 0:m.seq;a.has(y)||typeof b!="string"&&typeof b!="number"||String(b)===""||s.push({page:y,seq:String(b),width:mt((h=w.canvas)==null?void 0:h.width)??mt((f=w.image)==null?void 0:f.width)??0,height:mt((x=w.canvas)==null?void 0:x.height)??mt((k=w.image)==null?void 0:k.height)??0,columns:[]})}return s.sort((y,w)=>y.page-w.page)}const of=({data:e,onNavigate:n,className:o,style:r})=>{var u;const{t:s,convert:a}=Q(),[l,d]=g.useState(((u=e.divisions[0])==null?void 0:u.name)??null),[c,p]=g.useState(null);return t.jsxs("div",{className:o,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:i("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:i("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[s("catalog.totalVolumes")," ",t.jsx("strong",{children:e.total_volumes})," ",s("unit.juan")]}),e.stats.zhulu!=null&&t.jsxs("span",{children:[s("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",s("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[s("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",s("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:s("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(m=>t.jsx(rf,{division:m,expanded:l===m.name,onToggle:()=>d(l===m.name?null:m.name),expandedCat:c,onCatToggle:h=>p(c===h?null:h),onNavigate:n},m.name))})]})},rf=({division:e,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:a})=>{const{t:l,convert:d}=Q(),c=e.categories.reduce((p,u)=>{const m=u.stats||{zhulu:0,cunmu:0};return p+(m.zhulu||0)+(m.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?`color-mix(in srgb, ${i("primary")} 6%, transparent)`:i("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:i("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:i("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(p=>{const u=`${e.name}/${p.name}`;return t.jsx(sf,{category:p,expanded:r===u,onToggle:()=>s(u),onNavigate:a},p.name)})})]})},sf=({category:e,expanded:n,onToggle:o,onNavigate:r})=>{var p,u,m,h;const{t:s,convert:a}=Q(),l=((p=e.books)==null?void 0:p.zhulu)||[],d=((u=e.books)==null?void 0:u.cunmu)||[],c=(((m=e.stats)==null?void 0:m.zhulu)||l.length)+(((h=e.stats)==null?void 0:h.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?i("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:i("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg"),marginLeft:"8px",fontWeight:400},children:s("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:i("desc-fg")},children:[s("catalogPage.booksN",{n:c})," ",n?"▲":"▼"]})]}),n&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Fs,{label:s("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(Fs,{label:s("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},Fs=({label:e,books:n,onNavigate:o})=>{const{t:r,convert:s}=Q(),a=Xe(),[l,d]=g.useState(n.length<=20),c=l?n:n.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",n.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((p,u)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:i("fg")},children:p.work_id&&o?t.jsx("a",{href:a(p.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),o(p.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${i("link-fg")}`},children:s(p.title)}):s(p.title)}),p.volumes&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.volumes)}),p.author&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:s(p.author).slice(0,20)})]},u))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:i("primary"),background:"transparent",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:n.length})})]})},xt=({title:e,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const a=$e();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:i("fg")},children:e}),t.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&t.jsx("button",{onClick:o,style:lf,children:"AI"}),n&&t.jsx("button",{onClick:n,style:af,children:a.action.save})]})]}),s]})},af={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},lf={padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},dt=({label:e,value:n,onChange:o,placeholder:r,disabled:s})=>t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:{display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},children:e}),t.jsx("input",{type:"text",value:n,onChange:a=>o(a.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),Ut=({value:e,onChange:n,placeholder:o})=>{const r=g.useRef(null);return g.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[e]),t.jsx("textarea",{ref:r,value:e||"",onChange:s=>n(s.target.value),placeholder:o,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},li=({children:e,color:n,style:o})=>t.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||i("primary-soft"),color:i(n?"on-color-fg":"fg"),...o},children:e});function cf(e){const n=e.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const ti=({value:e,onChange:n,label:o})=>{const[r,s]=g.useState(!1),a=g.useRef(null),l=cf(e||"");return g.useEffect(()=>{r&&a.current&&a.current.focus()},[r]),!r&&l?t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ds,children:o}),t.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:`1px solid ${i("input-border")}`,borderRadius:"2px",background:i("input-bg"),cursor:"pointer",minHeight:"30px"},children:[t.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:i("fg")},children:l.name}),t.jsx(li,{children:l.id})]})]}):t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("label",{style:Ds,children:o}),t.jsx("input",{ref:a,type:"text",value:e||"",onChange:d=>n(d.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Ds={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500};function df(e){switch(e){case"url":return i("source-url");case"bookID":return i("source-bookid");default:return i("desc-fg")}}function pf(e){switch(e){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const mc=({items:e,onChange:n,onOpenEntityPicker:o})=>{const r=$e(),[s,a]=g.useState(null),l=()=>{n([...e,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),a(e.length)},d=m=>{n(e.filter((h,f)=>f!==m)),s===m&&a(null)},c=(m,h,f)=>{const x=[...e];x[m]={...x[m],[h]:f},n(x)},p=(m,h)=>{const f=[...e];f[m]={...f[m],type:h,id:"",name:""},n(f),h==="bookID"&&o&&o(x=>{const k=[...e];k[m]={...k[m],id:x.id,name:x.title,type:"bookID"},n(k)})},u=m=>{o&&o(h=>{const f=[...e];f[m]={...f[m],id:h.id,name:h.title,type:"bookID"},n(f)})};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((m,h)=>t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:i("input-bg"),overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>a(s===h?null:h),children:[t.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===h?"▼":"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:i("fg")},children:m.name||`${r.editor.sourcePlaceholder} ${h+1}`}),m.type&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:df(m.type),color:i("on-color-fg"),borderRadius:"3px",fontWeight:500},children:pf(m.type)}),t.jsx("button",{onClick:f=>{f.stopPropagation(),d(h)},style:{background:"transparent",border:"none",color:i("danger"),cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===h&&t.jsx("div",{style:{padding:"12px",borderTop:`1px solid ${i("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!m.type&&t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.editor.selectSourceType}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsxs("button",{onClick:()=>p(h,"bookID"),style:{...Us,borderColor:i("source-bookid"),color:i("source-bookid")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"📚"}),t.jsx("span",{children:"Book ID"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),t.jsxs("button",{onClick:()=>p(h,"url"),style:{...Us,borderColor:i("source-url"),color:i("source-url")},children:[t.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),t.jsx("span",{children:"URL"}),t.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),m.type==="bookID"&&t.jsx(t.Fragment,{children:t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:wt,children:r.action.selectBookOrWork}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:Vs,children:r.action.changeType})]}),m.id&&m.name?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:i("bg"),border:`1px solid ${i("source-bookid")}`,borderRadius:"6px"},children:[t.jsx("span",{style:{color:i("source-bookid"),fontSize:"16px"},children:"✓"}),t.jsxs("div",{style:{flex:1},children:[t.jsx("div",{style:{fontWeight:500},children:m.name}),t.jsx("code",{style:{fontSize:"11px",background:i("primary-soft"),padding:"2px 6px",borderRadius:"3px"},children:m.id})]}),t.jsx("button",{onClick:()=>u(h),style:{background:"transparent",border:`1px solid ${i("widget-border")}`,color:i("fg"),cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):t.jsxs("button",{onClick:()=>u(h),style:{width:"100%",padding:"14px",border:`2px dashed ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[t.jsx("span",{children:"🔍"}),t.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),m.type==="url"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("label",{style:wt,children:r.label.sourceName}),t.jsx("button",{onClick:()=>{const f=[...e];f[h]={...f[h],type:"",id:"",name:""},n(f)},style:Vs,children:r.action.changeType})]}),t.jsx("input",{type:"text",value:m.name,onChange:f=>c(h,"name",f.target.value),placeholder:r.editor.sourceNamePlaceholder,style:en})]}),t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.urlAddress}),t.jsx("input",{type:"text",value:m.id,onChange:f=>c(h,"id",f.target.value),placeholder:"https://...",style:en})]})]}),m.type&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{borderTop:`1px dashed ${i("widget-border")}`,paddingTop:"12px",marginTop:"4px"},children:t.jsx("label",{style:{...wt,opacity:.7},children:r.label.optionalInfo})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.detailsOptional}),t.jsx("input",{type:"text",value:m.details,onChange:f=>c(h,"details",f.target.value),placeholder:r.editor.detailsPlaceholder,style:en})]}),t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.positionOptional}),t.jsx("input",{type:"text",value:m.position,onChange:f=>c(h,"position",f.target.value),placeholder:"如: 卷三, p.52",style:en})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.dataVersionOptional}),t.jsx("input",{type:"text",value:m.version,onChange:f=>c(h,"version",f.target.value),placeholder:"如: v1.0, 2024-01",style:en})]}),t.jsxs("div",{children:[t.jsx("label",{style:wt,children:r.label.processorVersionOptional}),t.jsx("input",{type:"text",value:m.processor_version,onChange:f=>c(h,"processor_version",f.target.value),placeholder:"如: v0.1",style:en})]})]})]})]})})]},h)),t.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:`1px dashed ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer",fontSize:"13px",opacity:.8},children:[t.jsx("span",{children:"+"}),t.jsx("span",{children:r.action.addSource})]})]})},wt={display:"block",fontSize:"11px",color:i("desc-fg"),marginBottom:"4px",fontWeight:500},en={width:"100%",padding:"6px 8px",background:i("input-bg"),color:i("input-fg"),border:`1px solid ${i("input-border")}`,borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Us={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:i("bg"),border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Vs={background:"transparent",border:"none",color:i("link-fg"),cursor:"pointer",fontSize:"11px",padding:0};function hc(e){if(!e||!e.trim())return[];try{const n=JSON.parse(e);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function gc(e){return!e||e.length===0?"":JSON.stringify(e)}const fc=({entityType:e,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:a,belongsToCollection:l,childWorks:d,childCollections:c,containedBooks:p,siblingBooks:u,onLinkEntity:m,onUnlinkEntity:h,onViewEntity:f,onCreateAndLink:x,onSaveRelations:k})=>{const y=$e();return t.jsxs("div",{style:{background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[t.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:"🔗"}),t.jsx("span",{children:y.section.relations})]}),k&&t.jsx("button",{onClick:k,style:uf,children:y.action.save})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e==="book"&&t.jsxs(t.Fragment,{children:[t.jsx(wn,{direction:"up",title:y.relation.belongsToWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(wn,{direction:"up",title:y.relation.containedInCollection,entity:l,onView:f,onUnlink:()=>h("collectionId"),onLink:()=>m("collectionId","collection"),onCreate:()=>x("collectionId","collection",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),a&&u&&u.length>0&&t.jsx(tn,{direction:"horizontal",title:`${y.relation.siblingVersions} (${u.length})`,entities:u,onView:f,onAdd:()=>x("siblingBook","book",{workId:a.id}),addLabel:y.relation.addVersionForWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="work"&&t.jsxs(t.Fragment,{children:[t.jsx(wn,{direction:"up",title:y.relation.parentWork,entity:r,onView:f,onUnlink:()=>h("parentWorkId"),onLink:()=>m("parentWorkId","work"),onCreate:()=>x("parentWorkId","work"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),d&&d.length>0&&t.jsx(tn,{direction:"down",title:`${y.relation.childWorks} (${d.length})`,entities:d,onView:f,onAdd:()=>x("childWork","work",{parentWorkId:n}),addLabel:y.action.addSubWork,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),c&&c.length>0&&t.jsx(tn,{direction:"down",title:`${y.relation.collectionImpl} (${c.length})`,entities:c,onView:f,onAdd:()=>x("childCollection","collection",{workId:n}),addLabel:y.action.addCollectionImpl,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(tn,{direction:"down",title:`${y.relation.allVersions} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("childBook","book",{workId:n}),addLabel:y.action.addVersion,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]}),e==="collection"&&t.jsxs(t.Fragment,{children:[t.jsx(wn,{direction:"up",title:y.relation.correspondingWork,entity:a,onView:f,onUnlink:()=>h("workId"),onLink:()=>m("workId","work"),onCreate:()=>x("workId","work",{title:o}),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(wn,{direction:"up",title:y.relation.parentCollection,entity:s,onView:f,onUnlink:()=>h("parentCollectionId"),onLink:()=>m("parentCollectionId","collection"),onCreate:()=>x("parentCollectionId","collection"),linkLabel:y.action.linkExisting,createLabel:y.action.createAndLink,notLinkedLabel:y.relation.notLinked,viewLabel:y.action.viewEntity,unlinkLabel:y.action.unlink}),t.jsx(tn,{direction:"down",title:`${y.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:f,onAdd:()=>x("childCollection","collection",{parentCollectionId:n}),addLabel:y.action.addSubCollection,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore}),t.jsx(tn,{direction:"down",title:`${y.relation.containedBooks} (${(p==null?void 0:p.length)??0})`,entities:p||[],onView:f,onAdd:()=>x("childBook","book",{collectionId:n}),addLabel:y.action.addBook,noneLabel:y.relation.none,expandMoreLabel:y.action.expandMore})]})]})]})},wn=({direction:e,title:n,entity:o,onView:r,onUnlink:s,onLink:a,onCreate:l,linkLabel:d,createLabel:c,notLinkedLabel:p,viewLabel:u,unlinkLabel:m})=>{const h=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),f=e==="up"?"⬆️":e==="down"?"⬇️":"↔️";return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:f}),t.jsx("span",{children:n})]}),o?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:i("bg"),borderRadius:"4px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:xc(o.type)}),t.jsx("span",{style:{fontWeight:500},children:o.title}),t.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),t.jsxs("div",{style:{display:"flex",gap:"4px"},children:[t.jsx(Gs,{onClick:()=>r(o),title:u,children:"👁️"}),t.jsx(Gs,{onClick:s,title:m,danger:!0,children:"✕"})]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:p}),t.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[t.jsx(ko,{onClick:a,children:d}),t.jsx(ko,{onClick:l,primary:!0,children:c})]})]})},tn=({direction:e,title:n,entities:o,onView:r,onAdd:s,addLabel:a,noneLabel:l,expandMoreLabel:d})=>{const[c,p]=g.useState(!1),u=i(e==="up"?"relation-up":e==="down"?"relation-down":"relation-flat"),m=e==="up"?"⬆️":e==="down"?"⬇️":"↔️",h=c?o:o.slice(0,5);return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"4px",padding:"10px",background:i("input-bg")},children:[t.jsxs("div",{style:{fontSize:"12px",color:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[t.jsx("span",{children:m}),t.jsx("span",{children:n})]}),o.length>0?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(f=>t.jsxs("div",{onClick:()=>r(f),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:i("bg"),borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[t.jsx("span",{children:xc(f.type)}),t.jsx("span",{children:f.title})]},f.id)),o.length>5&&!c&&t.jsxs("div",{onClick:()=>p(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:i("link-fg"),cursor:"pointer"},children:[d," (",o.length-5,")"]})]}):t.jsx("div",{style:{padding:"8px",background:i("bg"),borderRadius:"4px",color:i("desc-fg"),fontSize:"12px",textAlign:"center"},children:l}),t.jsx("div",{style:{marginTop:"8px"},children:t.jsxs(ko,{onClick:s,primary:!0,children:["+ ",a]})})]})},Gs=({onClick:e,title:n,danger:o,children:r})=>t.jsx("button",{onClick:s=>{s.stopPropagation(),e()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?i("danger"):"inherit",opacity:.7},children:r}),ko=({onClick:e,primary:n,children:o})=>t.jsx("button",{onClick:e,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":`1px solid ${i("widget-border")}`,borderRadius:"4px",background:n?i("primary"):"transparent",color:n?i("primary-fg"):"inherit",cursor:"pointer"},children:o});function xc(e){switch(e){case"work":return"📜";case"book":return"📖";case"collection":return"📚";default:return}}const uf={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},bc=({isOpen:e,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:a,searchResults:l,onSearch:d,isLoading:c,excludeId:p})=>{const[u,m]=g.useState(""),h=p?l.filter(y=>y.id!==p):l;g.useEffect(()=>{e&&(m(""),d(""))},[e]);const f=y=>{m(y),d(y)};if(!e)return null;const x=n==="work"?"作品":n==="book"?"书籍":"丛编",k=n==="work"?"📜":n==="book"?"📖":"📚";return t.jsx("div",{style:mf,children:t.jsxs("div",{style:hf,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:o}),t.jsx("button",{onClick:s,style:gf,children:"✕"})]}),t.jsx("div",{style:{padding:"12px 16px"},children:t.jsx("input",{type:"text",value:u,onChange:y=>f(y.target.value),placeholder:`搜索${x}名称或 ID...`,autoFocus:!0,style:ff})}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?t.jsx("div",{style:Xi,children:"搜索中..."}):h.length>0?t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(y=>t.jsxs("div",{onClick:()=>r(y),style:xf,children:[t.jsx("span",{style:{fontSize:"16px"},children:k}),t.jsxs("div",{style:{flex:1},children:[t.jsxs("div",{style:{fontWeight:500},children:[y.title,y.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:y.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[y.id,y.author&&` · ${y.author}`,y.dynasty&&` · ${y.dynasty}`]})]})]},y.id))}):u?t.jsxs("div",{style:Xi,children:["未找到匹配的",x]}):t.jsxs("div",{style:Xi,children:["输入关键词搜索",x]})}),t.jsxs("div",{style:{padding:"12px 16px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsxs("button",{onClick:a,style:bf,children:["创建新",x,"并关联"]})]})]})})},mf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},hf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},gf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},ff={width:"100%",padding:"10px 12px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},xf={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:i("primary-soft")},Xi={padding:"20px",textAlign:"center",color:i("desc-fg")},bf={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Ys={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},yf={work:"📜",book:"📖",collection:"📚",entity:"👤"},yc=({isOpen:e,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:a})=>{const[l,d]=g.useState(""),c=g.useRef(null);g.useEffect(()=>{e&&(d((r==null?void 0:r.title)||""),setTimeout(()=>{var h,f;(h=c.current)==null||h.focus(),(f=c.current)==null||f.select()},100))},[e,r==null?void 0:r.title]);const p=h=>{h.key==="Enter"&&l.trim()?u():h.key==="Escape"&&a()},u=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!e)return null;const m=()=>{switch(o){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Ys[n]}`}};return t.jsx("div",{style:jf,onClick:h=>{h.target===h.currentTarget&&a()},children:t.jsxs("div",{style:vf,onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:yf[n]}),t.jsx("span",{children:m()})]}),t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:i("fg")},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",t.jsx("span",{style:{color:i("danger"),marginLeft:"4px"},children:"*"})]}),t.jsx("input",{ref:c,type:"text",value:l,onChange:h=>d(h.target.value),onKeyDown:p,placeholder:`请输入${Ys[n]}名称...`,style:kf})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),background:i("input-bg"),padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[t.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&t.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&t.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[t.jsx("button",{onClick:a,style:wf,children:"取消"}),t.jsx("button",{onClick:u,disabled:!l.trim(),style:{...Sf,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},jf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},vf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:i("shadow-dialog")},kf={width:"100%",padding:"8px 12px",fontSize:"14px",border:`1px solid ${i("input-border")}`,borderRadius:"4px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box"},wf={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",color:i("fg"),cursor:"pointer"},Sf={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg")};function _f(e){switch(e){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function jc(e){switch(e){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function $f(e){switch(e){case"work":return i("editor-type-work");case"collection":return i("editor-type-collection");case"book":return i("editor-type-book");default:return i("desc-fg")}}const vc=({isOpen:e,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:a=!1,createButtonText:l,onSelect:d,onCancel:c,onCreate:p,onSearch:u})=>{const[m,h]=g.useState(""),[f,x]=g.useState([]),[k,y]=g.useState(!1),[w,b]=g.useState("recent");g.useEffect(()=>{e&&(h(""),x([]),b(r.length>0?"recent":"search"))},[e,r.length]),g.useEffect(()=>{if(!m.trim()){x([]);return}const C=setTimeout(async()=>{y(!0);try{x(await u(m,o))}catch{x([])}finally{y(!1)}},300);return()=>clearTimeout(C)},[m,o,u]);const j=g.useCallback(C=>{h(C.target.value),C.target.value.trim()&&b("search")},[]),S=g.useCallback(C=>s?C.filter(M=>M.id!==s):C,[s]);if(!e)return null;const v=n||(o==="all"?"选择实体":`选择${jc(o)}`),$=S(r),_=S(f);return t.jsx("div",{style:zf,children:t.jsxs("div",{style:Tf,children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:v}),t.jsx("button",{onClick:c,style:Nf,children:"✕"})]}),t.jsx("div",{style:{padding:"16px 20px 12px"},children:t.jsxs("div",{style:{position:"relative"},children:[t.jsx("input",{type:"text",value:m,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ef}),t.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),k&&t.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),$.length>0&&t.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:`1px solid ${i("widget-border")}`},children:[t.jsxs(Ks,{active:w==="recent",onClick:()=>b("recent"),children:["最近使用 (",$.length,")"]}),t.jsxs(Ks,{active:w==="search",onClick:()=>b("search"),children:["搜索结果 ",_.length>0&&`(${_.length})`]})]}),t.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:w==="recent"&&$.length>0?t.jsx(qs,{entities:$,onSelect:d}):m.trim()?k?t.jsx(Zi,{message:"搜索中..."}):_.length>0?t.jsx(qs,{entities:_,onSelect:d}):t.jsx(Zi,{message:"未找到匹配的结果"}):t.jsx(Zi,{message:"输入关键词开始搜索"})}),a&&p&&t.jsxs("div",{style:{padding:"12px 20px",borderTop:`1px solid ${i("widget-border")}`,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),t.jsx("button",{onClick:p,style:If,children:l||"创建新实体"})]})]})})},Ks=({active:e,onClick:n,children:o})=>t.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:e?`2px solid ${i("primary")}`:"2px solid transparent",background:"transparent",color:i(e?"fg":"desc-fg"),cursor:"pointer",fontSize:"12px",fontWeight:e?600:400,marginBottom:"-1px"},children:o}),qs=({entities:e,onSelect:n})=>t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:e.map(o=>t.jsx(Cf,{entity:o,onClick:()=>n(o)},o.id))}),Cf=({entity:e,onClick:n})=>{const[o,r]=g.useState(!1);return t.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i("primary-soft"),transition:"background 0.1s"},children:[t.jsx("span",{style:{fontSize:"18px"},children:_f(e.type)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[e.title,e.edition&&t.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:i("desc-fg"),marginLeft:"4px"},children:e.edition})]}),t.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[t.jsx("code",{style:{fontSize:"10px",background:i("primary-soft"),padding:"1px 4px",borderRadius:"2px"},children:e.id}),e.author&&t.jsx("span",{children:e.author}),e.dynasty&&t.jsx("span",{children:e.dynasty})]})]}),t.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:$f(e.type),color:i("on-color-fg"),borderRadius:"4px",fontWeight:500,flexShrink:0},children:jc(e.type)})]})},Zi=({message:e})=>t.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:i("desc-fg"),fontSize:"13px"},children:e}),zf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Tf={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:i("shadow-dialog")},Nf={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Ef={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),fontSize:"13px",boxSizing:"border-box"},If={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:i("primary"),color:i("primary-fg"),cursor:"pointer"},Rf={work:i("editor-type-work"),collection:i("editor-type-collection"),book:i("editor-type-book"),entity:i("editor-type-entity")},Lf={work:"📜",collection:"📚",book:"📖",entity:"👤"},kc=({data:e,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:a,onDelete:l,onAskAI:d,renderSectionActions:c,onDownloadResource:p,downloadStatuses:u,relations:m,onRelationsChange:h})=>{var Se;const f=$e(),[x,k]=g.useState(!1),[y,w]=g.useState("work"),[b,j]=g.useState(""),[S,v]=g.useState(""),[$,_]=g.useState([]),[C,M]=g.useState(!1),[T,z]=g.useState(!1),[F,N]=g.useState("work"),[R,O]=g.useState(""),[I,P]=g.useState(),[U,K]=g.useState(!1),[L,Z]=g.useState(null),[A,V]=g.useState([]);g.useRef(null);const pe=e.type,ee=pe==="work",ue=pe==="collection",me=pe==="book",be=g.useCallback((X,Ce)=>{n({...e,[X]:Ce})},[e,n]),Oe=g.useCallback((X,Ce)=>{j(X),w(Ce),v(f.editor.selectToLink+f.indexType[Ce]),_([]),k(!0)},[f]),ie=g.useCallback(X=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(e.id,X)},[r,e.id]),Re=g.useCallback(X=>{s==null||s(X.id,X.type)},[s]),Le=g.useCallback((X,Ce,Me)=>{const B={...Me,author:(Me==null?void 0:Me.author)||e.author,dynasty:Me==null?void 0:Me.dynasty};N(Ce),O(X),P(B),z(!0)},[e.author]),q=g.useCallback((X,Ce)=>{r!=null&&r.createAndLink&&r.createAndLink(e.id,R,{type:F,title:X,inheritData:Ce}),z(!1)},[r,e.id,R,F]),J=g.useCallback(X=>{if(!X.trim()){_([]);return}M(!0),r!=null&&r.searchEntities&&r.searchEntities(X,y).then(Ce=>{_(Ce),M(!1)}).catch(()=>{_([]),M(!1)})},[r,y]),fe=g.useCallback(X=>{r!=null&&r.linkEntity&&r.linkEntity(e.id,b,X.id),k(!1)},[r,e.id,b]),ze=g.useCallback(()=>{o()},[o]),Y=g.useCallback(X=>{Z(()=>X),K(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(V).catch(()=>{})},[r]),ve=g.useCallback((X,Ce)=>r!=null&&r.searchEntities?r.searchEntities(X,Ce==="all"?void 0:Ce):Promise.resolve([]),[r]),le=g.useCallback(X=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(X),V(Ce=>[X,...Ce.filter(Me=>Me.id!==X.id)].slice(0,10)),L==null||L(X),K(!1),Z(null)},[r,L]);return t.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[t.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:`1px solid ${i("widget-border")}`,paddingBottom:"16px"},children:t.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{children:Lf[pe]}),t.jsx("span",{children:e.title||f.editor.untitled}),t.jsx(li,{children:e.id}),t.jsx(li,{color:Rf[pe],children:f.indexType[pe]})]})}),t.jsx(xt,{title:f.section.basicInfo,onSave:o,onAskAI:d?()=>d("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[t.jsx(ti,{label:ee?f.editor.workTitle:ue?f.editor.collectionTitle:f.editor.bookTitle,value:e.title,onChange:X=>be("title",X)}),me&&t.jsx(ti,{label:f.editor.belongsToWork,value:e.workName||"",onChange:X=>be("workName",X)}),t.jsx(dt,{label:f.editor.authorLabel,value:e.author||"",onChange:X=>be("author",X)}),t.jsx(dt,{label:f.editor.publicationYearLabel,value:e.publicationYear||"",onChange:X=>be("publicationYear",X)}),(me||ue)&&t.jsx(ti,{label:f.editor.containedIn,value:e.collection||"",onChange:X=>be("collection",X)}),(me||ue)&&t.jsx(dt,{label:f.editor.holderLabel,value:e.holder||"",onChange:X=>be("holder",X)}),(me||ue)&&t.jsx(dt,{label:me?f.editor.pageLabel:f.editor.volumeLabel,value:e.pages||"",onChange:X=>be("pages",X)}),t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(dt,{label:f.editor.firstImageLabel,value:e.firstImage||"",onChange:X=>be("firstImage",X)})})]})}),t.jsx(xt,{title:f.section.description,onSave:o,onAskAI:d?()=>d("介绍"):void 0,children:t.jsx(Ut,{value:e.description||"",onChange:X=>be("description",X),placeholder:f.editor.descriptionPlaceholder})}),(((Se=e.additional_works)==null?void 0:Se.length)||0)>0&&t.jsx(xt,{title:f.section.additionalWorks,onSave:o,children:t.jsx(Af,{items:e.additional_works||[],onChange:X=>be("additional_works",X)})}),t.jsx(xt,{title:f.section.indexedBy,onSave:o,onAskAI:d?()=>d("收录于"):void 0,children:t.jsx(Pf,{items:e.indexed_by||[],onChange:X=>be("indexed_by",X)})}),t.jsx(xt,{title:f.section.emendatedBy,onSave:o,onAskAI:d?()=>d("考证"):void 0,children:t.jsx(Mf,{items:e.emendated_by||[],onChange:X=>be("emendated_by",X)})}),t.jsx(xt,{title:f.section.textResources,onSave:o,onAskAI:d?()=>d("资源"):void 0,children:t.jsx(io,{items:e.resources||[],onChange:X=>be("resources",X),onDownload:p,downloadStatuses:u,filterType:"text"})}),t.jsx(xt,{title:f.section.imageResources,onSave:o,children:t.jsx(io,{items:e.resources||[],onChange:X=>be("resources",X),onDownload:p,downloadStatuses:u,filterType:"image"})}),t.jsx(xt,{title:f.section.sources,onSave:o,onAskAI:d?()=>d("资料来源"):void 0,children:t.jsx(mc,{items:hc(e.sources||""),onChange:X=>be("sources",gc(X)),onOpenEntityPicker:Y})}),(me||ue)&&t.jsx(xt,{title:f.section.provenance,onSave:o,onAskAI:d?()=>d("收藏历史"):void 0,children:t.jsx(Ut,{value:e.provenance||"",onChange:X=>be("provenance",X),placeholder:f.editor.provenancePlaceholder})}),me&&t.jsx(xt,{title:f.section.otherEditions,onSave:o,onAskAI:d?()=>d("其他版本"):void 0,children:t.jsx(Ut,{value:e.otherEditions||"",onChange:X=>be("otherEditions",X),placeholder:f.editor.otherEditionsPlaceholder})}),t.jsx(fc,{entityType:pe,entityId:e.id,entityTitle:e.title,parentWork:m==null?void 0:m.parentWork,parentCollection:m==null?void 0:m.parentCollection,belongsToWork:m==null?void 0:m.belongsToWork,belongsToCollection:m==null?void 0:m.belongsToCollection,childWorks:m==null?void 0:m.childWorks,childCollections:m==null?void 0:m.childCollections,containedBooks:m==null?void 0:m.containedBooks,siblingBooks:m==null?void 0:m.siblingBooks,onLinkEntity:Oe,onUnlinkEntity:ie,onViewEntity:Re,onCreateAndLink:Le,onSaveRelations:ze}),a&&l&&t.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:`1px solid ${i("danger-soft-border")}`,background:i("danger-soft-bg"),borderRadius:"4px"},children:[t.jsx("div",{style:{color:i("danger"),fontWeight:600,marginBottom:"8px"},children:f.section.dangerZone}),t.jsx("p",{style:{fontSize:"12px",color:i("desc-fg"),marginBottom:"12px"},children:f.editor.dangerZoneDesc}),t.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("danger")}`,borderRadius:"4px",background:"transparent",color:i("danger"),cursor:"pointer"},children:f.editor.deleteEntity})]}),t.jsx(bc,{isOpen:x,entityType:y,title:S,onSelect:fe,onCancel:()=>k(!1),onCreate:()=>{k(!1),Le(b,y)},searchResults:$,onSearch:J,isLoading:C,excludeId:e.id}),t.jsx(yc,{isOpen:T,entityType:F,relationField:R,inheritData:I,onConfirm:q,onCancel:()=>z(!1)}),t.jsx(vc,{isOpen:U,title:f.action.selectBookOrWork,filterType:"all",recentEntities:A,excludeId:e.id,onSelect:le,onCancel:()=>{K(!1),Z(null)},onSearch:ve})]})};function Af({items:e,onChange:n}){const o=$e(),r=(l,d,c)=>{const p=e.map((u,m)=>m===l?{...u,[d]:c}:u);n(p)},s=l=>n(e.filter((d,c)=>c!==l)),a=()=>n([...e,{book_title:""}]);return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((l,d)=>t.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[t.jsx(dt,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(d,"book_title",c)}),t.jsx("div",{style:{width:"100px"},children:t.jsx(dt,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(d,"n_juan",c&&parseInt(c,10)||void 0)})}),t.jsx("button",{onClick:()=>s(d),style:{padding:"4px 8px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("muted"),marginTop:"18px"},children:"✕"})]},d)),t.jsx("button",{onClick:a,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function wc({items:e,onChange:n,showMeta:o,addLabel:r}){const s=$e(),[a,l]=g.useState(null),d=(u,m,h)=>{const f=e.map((x,k)=>k===u?{...x,[m]:h||void 0}:x);n(f)},c=u=>{n(e.filter((m,h)=>h!==u)),a===u&&l(null)},p=()=>{n([...e,{source:""}]),l(e.length)};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[e.map((u,m)=>{const h=a===m;return t.jsxs("div",{style:{border:`1px solid ${i("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?`color-mix(in srgb, ${i("primary")} 5%, transparent)`:"transparent",cursor:"pointer"},onClick:()=>l(h?null:m),children:[t.jsx("span",{style:{fontSize:"10px",color:i("desc-fg"),transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),t.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&t.jsx("span",{style:{fontSize:"11px",color:i("desc-fg")},children:u.source_bid}),t.jsx("button",{onClick:f=>{f.stopPropagation(),c(m)},style:{padding:"2px 6px",fontSize:"11px",border:`1px solid ${i("widget-border")}`,borderRadius:"3px",background:"transparent",cursor:"pointer",color:i("muted")},children:"✕"})]}),!h&&o&&(u.title_info||u.author_info)&&t.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:i("desc-fg")},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.author_info]}),h&&t.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(dt,{label:s.label.sourceName,value:u.source,onChange:f=>d(m,"source",f)}),t.jsx(dt,{label:s.label.sourceBid,value:u.source_bid||"",onChange:f=>d(m,"source_bid",f)})]}),o&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[t.jsx(dt,{label:s.label.titleInfo,value:u.title_info||"",onChange:f=>d(m,"title_info",f)}),t.jsx(dt,{label:s.label.authorInfo,value:u.author_info||"",onChange:f=>d(m,"author_info",f)})]}),t.jsx(dt,{label:s.label.edition,value:u.edition||"",onChange:f=>d(m,"edition",f)})]}),t.jsx(Ut,{value:u.summary||"",onChange:f=>d(m,"summary",f),placeholder:s.editor.summaryPlaceholder}),t.jsx(Ut,{value:u.comment||"",onChange:f=>d(m,"comment",f),placeholder:s.editor.commentPlaceholder}),t.jsx(Ut,{value:u.additional_comment||"",onChange:f=>d(m,"additional_comment",f),placeholder:s.editor.additionalCommentPlaceholder})]})]},m)}),t.jsx("button",{onClick:p,style:{padding:"6px 12px",fontSize:"12px",border:`1px dashed ${i("input-border")}`,borderRadius:"4px",background:"transparent",cursor:"pointer",color:i("desc-fg"),alignSelf:"flex-start"},children:r})]})}function Pf({items:e,onChange:n}){const o=$e();return t.jsx(wc,{items:e,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function Mf({items:e,onChange:n}){const o=$e();return t.jsx(wc,{items:e,onChange:n,addLabel:o.action.addEmendatedBy})}function Sc(e){var d,c,p,u,m,h,f;const n=((c=(d=e.authors)==null?void 0:d[0])==null?void 0:c.name)||"",o=((p=e.publication_info)==null?void 0:p.year)||"",r=((u=e.current_location)==null?void 0:u.name)||"",s=(m=e.page_count)!=null&&m.number?String(e.page_count.number):((h=e.page_count)==null?void 0:h.description)||"",a=typeof e.description=="object"&&e.description!==null&&e.description.text||"",l={id:e.id,title:e.title,type:e.type,author:n,publicationYear:o,holder:r,pages:s,description:a,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};if(e.type==="work"){const x=e;if(Array.isArray(x.related_works)){const k=x.related_works.find(y=>y.relation==="part_of");k&&(l.parentWorkId=k.id,l.parentWorkName=k.title)}}if(e.type==="book"){const x=e;l.workId=x.work_id,Array.isArray(x.contained_in)&&x.contained_in.length>0&&(l.collectionId=(f=x.contained_in[0])==null?void 0:f.id)}return l}function Bf(e){const n={id:e.id,title:e.title,type:e.type,description:e.description?{text:e.description}:void 0,authors:e.author?[{name:e.author}]:void 0,publication_info:e.publicationYear?{year:e.publicationYear}:void 0,current_location:e.holder?{name:e.holder}:void 0,page_count:e.pages?{number:parseInt(e.pages)||0,description:e.pages}:void 0,resources:e.resources,additional_works:e.additional_works,indexed_by:e.indexed_by,emendated_by:e.emendated_by};return e.type==="work"&&e.parentWorkId&&(n.related_works=[{id:e.parentWorkId,title:e.parentWorkName||"",relation:"part_of"}]),e.type==="book"&&(n.work_id=e.workId,e.collectionId&&(n.contained_in=[{id:e.collectionId}])),n}const Wf=e=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:a,onChange:l,onSave:d,onDelete:c,onNavigate:p,renderLink:u,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y,headerExtra:w,className:b,style:j}=e,S=$e(),[v,$]=g.useState(s),_=a?s:v;g.useEffect(()=>{s!==v&&$(s)},[s]);const C=g.useCallback(()=>{const O=_==="view"?"edit":"view";a?a(O):$(O)},[_,a]),[M,T]=g.useState(null);g.useEffect(()=>{o&&r&&r.getItem(o).then(O=>{O&&T(O)})},[o,r]);const z=n||M,F=g.useMemo(()=>z?Sc(z):null,[z]),N=a||!n?t.jsx("button",{onClick:C,style:{padding:"4px 12px",fontSize:"12px",border:`1px solid ${i("widget-border")}`,borderRadius:"4px",background:_==="edit"?i("accent-bg"):"transparent",color:i(_==="edit"?"on-color-fg":"fg"),cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:_==="view"?S.common.switchToEdit:S.common.switchToView,children:_==="view"?S.common.modeEdit:S.common.modeView}):null,R=t.jsxs(t.Fragment,{children:[N,w]});return!z&&!F?t.jsx(Yt,{}):_==="view"?t.jsx(Bo,{data:z,transport:r,onNavigate:p?O=>p(O):void 0,renderLink:u,headerExtra:R,className:b,style:j}):F?t.jsxs("div",{className:b,style:j,children:[R&&t.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:R}),t.jsx(kc,{data:F,onChange:l||(()=>{}),onSave:d||(()=>{}),transport:r,onNavigate:p,showDelete:!!c,onDelete:c,onAskAI:m,renderSectionActions:h,onDownloadResource:f,downloadStatuses:x,relations:k,onRelationsChange:y})]}):t.jsx("div",{style:{padding:"24px",textAlign:"center",color:i("muted")},children:S.common.noData})},Of=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],_c=({isOpen:e,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const{t:s}=Q(),[a,l]=g.useState(null),[d,c]=g.useState(""),[p,u]=g.useState(""),[m,h]=g.useState("idle"),[f,x]=g.useState(""),k=g.useRef(null);g.useEffect(()=>{e&&(l(null),c(""),u(""),h("idle"),x(""))},[e]),g.useEffect(()=>{a&&setTimeout(()=>{var b;return(b=k.current)==null?void 0:b.focus()},100)},[a]),g.useEffect(()=>{if(m==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[m,n]),g.useEffect(()=>{if(!e)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[e,n]);const y=async()=>{if(!(!a||!d.trim())){h("submitting"),x("");try{await o({type:a,content:d.trim(),...p.trim()?{contact:p.trim()}:{}}),h("success")}catch(b){h("error"),x(b instanceof Error?b.message:s("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&m!=="submitting";return t.jsx("div",{style:Hf,onClick:b=>{b.target===b.currentTarget&&n()},children:t.jsxs("div",{style:Ff,onClick:b=>b.stopPropagation(),children:[t.jsxs("div",{style:Df,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:s("feedback.title")}),t.jsx("button",{onClick:n,style:Uf,"aria-label":s("feedback.close"),children:"✕"})]}),m==="success"?t.jsxs("div",{style:qf,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:s("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:i("primary"),marginTop:"8px"},children:s("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Of.map(b=>t.jsxs("button",{onClick:()=>l(b.value),style:{...Vf,...a===b.value?Gf:{}},children:[t.jsx("span",{children:b.icon})," ",s(`feedback.submitType.${b.value}`)]},b.value))}),t.jsx("textarea",{ref:k,value:d,onChange:b=>c(b.target.value),placeholder:s(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||m==="submitting",style:{...Yf,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:p,onChange:b=>u(b.target.value),placeholder:s("feedback.contactPlaceholder"),maxLength:200,disabled:!a||m==="submitting","aria-label":s("feedback.contactLabel"),style:Zf}),t.jsxs("div",{style:{fontSize:"12px",color:i("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),m==="error"&&t.jsx("div",{style:Xf,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:y,disabled:!w,style:{...Kf,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:s(m==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Hf={position:"fixed",top:0,left:0,right:0,bottom:0,background:i("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Ff={background:i("bg"),border:`1px solid ${i("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:i("shadow-dialog")},Df={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Uf={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:i("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Vf={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Gf={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},Yf={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("input-bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Kf={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},qf={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:i("success")},Xf={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Zf={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},wo="--bim-feedback-fab-offset",So=48,Jf=16,Qf=({onSubmit:e,position:n={bottom:24,right:24},feedbackListUrl:o,hidden:r=!1,zIndex:s})=>{const{t:a}=Q(),[l,d]=g.useState(!1),c=n.bottom??24;return g.useEffect(()=>{if(r||typeof document>"u")return;const p=document.documentElement;return p.style.setProperty(wo,`calc(${c+So+Jf}px + env(safe-area-inset-bottom, 0px))`),()=>{p.style.removeProperty(wo)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...ex,zIndex:s??i("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:n.right},"aria-label":a("feedback.title"),title:a("feedback.title"),children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(_c,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:o})]})},ex={position:"fixed",width:`${So}px`,height:`${So}px`,borderRadius:"50%",border:"none",background:i("primary"),color:i("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:i("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},tx=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],$c=({onSubmit:e})=>{const{t:n}=Q(),[o,r]=g.useState("bug"),[s,a]=g.useState(""),[l,d]=g.useState(""),[c,p]=g.useState("idle"),[u,m]=g.useState(""),h=g.useRef(null);g.useEffect(()=>{o&&setTimeout(()=>{var k;return(k=h.current)==null?void 0:k.focus()},100)},[o]);const f=async()=>{if(!(!o||!s.trim())){p("submitting"),m("");try{await e({type:o,content:s.trim(),...l.trim()?{contact:l.trim()}:{}}),p("success"),a(""),d(""),r("bug")}catch(k){p("error"),m(k instanceof Error?k.message:n("feedback.submitFailedRetry"))}}},x=o&&s.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:Xs,children:t.jsxs("div",{style:sx,children:[t.jsxs("span",{children:["✓ ",n("feedback.thanks")]}),t.jsx("button",{onClick:()=>p("idle"),style:ax,children:n("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Xs,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:tx.map(k=>t.jsxs("button",{onClick:()=>r(k.value),style:{...nx,...o===k.value?ix:{}},children:[t.jsx("span",{children:k.icon})," ",n(`feedback.submitType.${k.value}`)]},k.value))}),t.jsx("textarea",{ref:h,value:s,onChange:k=>a(k.target.value),placeholder:n(o?`feedback.placeholder.${o}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...ox}}),t.jsx("input",{type:"text",value:l,onChange:k=>d(k.target.value),placeholder:n("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":n("feedback.contactLabel"),style:cx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:i("desc-fg")},children:[s.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!x,style:{...rx,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:n(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:lx,children:u})]})},Xs={padding:"16px",border:`1px solid ${i("widget-border")}`,borderRadius:"8px",background:i("input-bg")},nx={padding:"8px 16px",fontSize:"13px",border:`1px solid ${i("widget-border")}`,borderRadius:"6px",background:"transparent",color:i("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ix={borderColor:i("primary"),background:i("list-active-bg"),color:i("primary"),fontWeight:500},ox={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},rx={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:i("primary"),color:i("primary-fg"),fontWeight:500},sx={display:"flex",alignItems:"center",gap:"12px",color:i("success"),fontSize:"14px"},ax={background:"none",border:"none",color:i("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},lx={fontSize:"13px",color:i("danger"),padding:"8px 12px",background:i("danger-bg"),borderRadius:"4px",marginTop:"8px"},cx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${i("input-border")}`,borderRadius:"6px",background:i("bg"),color:i("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"};function Zs(e){return typeof e=="function"?e():e??"/api/feedback"}const Cc=({resourceId:e,apiUrl:n})=>{const{t:o}=Q(),[r,s]=g.useState([]),[a,l]=g.useState(!0),d=g.useCallback(async()=>{const p=Zs(n);l(!0);try{const m=await(await fetch(`${p}?resourceId=${encodeURIComponent(e)}`)).json();m.success&&s(m.items)}catch{}finally{l(!1)}},[e,n]);g.useEffect(()=>{d()},[d]);const c=async p=>{const u=Zs(n),m=await fetch(u,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...p,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e})});if(!m.ok){const h=await m.json().catch(()=>null);throw new Error((h==null?void 0:h.error)||o("feedback.submitFailed"))}setTimeout(()=>d(),500)};return t.jsxs("div",{children:[t.jsx(br,{items:r,loading:a}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx($c,{onSubmit:c})})]})},dx=di["zh-Hant"].relation,px=di["zh-Hant"].lossStatus,ux=di["zh-Hant"].resourceKind,Si=cn("zh-Hant"),yr=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function Js(e,n=Si){return e?yr(dx,e)?n(`detail.relation.${e}`):e:n("detail.relation.related")}function mx(e,n=Si){return yr(px,e)?n(`detail.lossStatus.${e}`):e}function hx(e,n=Si){return yr(ux,e)?n(`detail.resourceKind.${e}`):""}function jr({authors:e,onNavigate:n,renderLink:o}){const{convert:r}=Q(),s=(e||[]).filter(a=>a&&a.name);return s.length?t.jsx(t.Fragment,{children:s.map((a,l)=>{const d=Yo(a.role);return t.jsxs(g.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(qe,{id:a.entity_id,label:r(a.name),onNavigate:n,renderLink:o,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function zc(e,n,o=Si){var c,p;const r=Vo(e,n),s=r.mirrors.map(u=>({key:u.key,label:u.label,description:u.description,rows:u.items.filter(m=>m.group_role!=="mirror"),mirrors:u.items.filter(m=>m.group_role==="mirror")})),a=r.buckets.filter(u=>u.key==="image"||u.key==="textImage").flatMap(u=>u.items);a.length&&s.push({key:"_images",label:s.length?o("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(u=>u.key==="physical"))==null?void 0:c.items)??[];return l.length&&s.push({key:"_physical",label:o("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((p=r.buckets.find(u=>u.key==="text"))==null?void 0:p.items)??[],groups:s}}function Tc(e,n){const o=(e.url?dn(e.url):void 0)||e.name,r=vl(e,n);return r?`${o}(${r})`:o}function vr({item:e,siblings:n,listedVolumeCounts:o}){const{t:r,convert:s}=Q(),[a,l]=g.useState(!1),d=pi(e),c=!!d&&d.expected>0&&!(o!=null&&o.has(d.expected)),p=s(Tc(e,n)),u=pn(e),m=yi(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,x;const h=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((x=e.metadata)==null?void 0:x.fragment)&&t.jsx("span",{className:"bim-d-tag",children: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 u?t.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:[p," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),h]}):t.jsxs("span",{className:"bim-d-zt-name",children:[p,h]})})(),m&&t.jsx("span",{className:"bim-d-meta",children:s(m)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(Jo,{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(h=>!h),children:a?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Nc({groups:e,listedVolumeCounts:n}){const{t:o,convert:r}=Q();return t.jsx(t.Fragment,{children:e.map(s=>t.jsxs("div",{className:"bim-d-rg",children:[s.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(s.label)}),s.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(s.description)}),s.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:s.rows.map((a,l)=>t.jsx(vr,{item:a,siblings:s.rows,listedVolumeCounts:n},`${a.id||a.url||a.name}-${l}`))})}),s.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[s.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:o("detail.mirror")}),s.mirrors.map((a,l)=>{const d=pn(a),c=r(Tc(a,s.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)})]})]},s.key))})}const En=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function _o(e){var o;if(!e)return;const n=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(o=En.find(r=>n.startsWith(r.key[0])))==null?void 0:o.key}const Qs=12,gx=60,Ec=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,railTop:a,back:l,railLinks:d})=>{var J,fe,ze;const{t:c,convert:p,messages:u}=Q(),m=g.useMemo(()=>[...e.books||[],...e.collections||[]],[e.books,e.collections]),[h,f]=g.useState(new Map),[x,k]=g.useState(!1),[y,w]=g.useState(""),[b,j]=g.useState(!1),S=m.length<=gx,v=S||x||!!y||b,$=g.useMemo(()=>v?m:m.slice(0,Qs),[m,v]);g.useEffect(()=>{if(!n||$.length===0)return;const Y=$.filter(le=>!h.has(le));if(Y.length===0)return;let ve=!1;return Promise.all(Y.map(le=>n.getItem(le).then(Se=>{const X=Se??{};return[le,{id:le,title:X.title,edition:X.edition,resources:X.resources,publication_info:X.publication_info,current_location:X.current_location,lineage:X.lineage,measure_info:X.measure_info}]}).catch(()=>[le,{id:le}]))).then(le=>{ve||f(Se=>{const X=new Map(Se);for(const[Ce,Me]of le)X.set(Ce,Me);return X})}),()=>{ve=!0}},[n,$,h]);const _=g.useMemo(()=>m.map(Y=>h.get(Y)??{id:Y}),[m,h]),C=m.length>0&&m.every(Y=>h.has(Y)),M=!!n&&$.some(Y=>!h.has(Y)),T=S||v,z=g.useMemo(()=>wl(_,e.version_graph,{era:y,scanOnly:b,sort:T?"year":"default"}),[_,e.version_graph,y,b,T]),F=x?z.rows:z.rows.slice(0,Qs),N=z.allRows.filter(Y=>Y.hasImage).length,R=e.related_works||[],O=R.filter(Y=>Y.relation==="collected_in"),I=g.useMemo(()=>{const Y=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],ve=le=>{const Se=Y.indexOf(le??"");return Se<0?Y.length:Se};return R.filter(le=>le.relation!=="collected_in").map((le,Se)=>({r:le,i:Se})).sort((le,Se)=>ve(le.r.relation)-ve(Se.r.relation)||le.i-Se.i).map(le=>le.r)},[R]),P=g.useMemo(()=>{const Y=Vo(e.resources,e.resource_groups);return[...Y.mirrors.flatMap(ve=>ve.items.map(le=>({r:le,kind:p(ve.label)}))),...Y.buckets.flatMap(ve=>ve.items.map(le=>({r:le,kind:p(hx(ve.key,c))})))]},[e.resources,e.resource_groups,p,c]),U=e.indexed_by||[],K=e.emendated_by||[],L=g.useMemo(()=>{var te,ye,H;const Y=[],ve=(ye=(te=e.authors)==null?void 0:te[0])==null?void 0:ye.dynasty;ve&&Y.push({label:c("workPage.fact.written"),value:p(ve)});const le=zt(e,u.unit.juan);if(le){const se=(H=e.juan_count)==null?void 0:H.description;Y.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[p(le),se&&se!==le?t.jsxs("span",{className:"bim-d-meta",children:["(",p(se),")"]}):null]})})}e.loss_status&&Y.push({label:c("workPage.fact.loss"),value:p(mx(e.loss_status,c))});const Se=z.allRows.filter(se=>se.sortYear!=null),X=Se.length>0?Se.reduce((se,ne)=>se.sortYear<=ne.sortYear?se:ne):null;X!=null&&X.era.era?Y.push({label:c("workPage.fact.earliest"),value:p([X.era.era,X.era.reign].filter(Boolean).join(" ")),title:X.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):M&&Y.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),K.length&&Y.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:K.length})});const Ce=ea(e.additional_titles);Ce.length&&Y.push({label:c("workPage.fact.alias"),value:Ce.map(p).join("、")});const Me=ea(e.attached_texts);Me.length&&Y.push({label:c("workPage.fact.attached"),value:Me.map(p).join("、")});const B=(e.additional_works||[]).map(se=>p(se.book_title)+(se.n_juan!=null?` ${se.n_juan}${u.unit.juan}`:""));return B.length&&Y.push({label:c("workPage.fact.appendix"),value:B.join("、")}),Y},[e,p,c,u,M,z.allRows,K.length]),A=[{value:e._edition_count??m.length,label:c("workPage.stat.editions")},{value:C?N:0,label:c("workPage.stat.hasImage")},{value:U.length,label:c("workPage.stat.catalogs")}],V=e.classification,pe=V?[V.l1,V.l2,V.l3,V.l4].filter(Boolean).map(Y=>p(Y)):[],ee=e.subtype?u.workSubtype[e.subtype]??p(e.subtype):"",ue=t.jsx(An,{title:p(e.title),byline:t.jsx(jr,{authors:e.authors,onNavigate:o,renderLink:r}),meta:t.jsx(Je,{items:[...pe,V!=null&&V.source?c("workPage.classifiedBy",{source:p(V.source.split("/")[0])}):"",ee]}),description:(J=e.description)!=null&&J.text?t.jsxs(t.Fragment,{children:[t.jsx(Ct,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(fe=e.description.sources)!=null&&fe.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(Y=>p(Im(Y))).filter(Boolean).join(" · ")}):null]}):void 0,stats:A,facts:L,readAction:s,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(ze=e.appendix)==null?void 0:ze.map((Y,ve)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:p(Y.title)}),t.jsx(Ct,{text:Y.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},ve))}),me=z.eras.length>=2?[{key:"",label:c("catalog.all")},...z.eras.map(Y=>({key:Y,label:`${Y} ${z.allRows.filter(ve=>ve.era.era===Y).length}`}))]:[],be=[];m.length&&be.push({id:"versions",label:c("workPage.sec.versions"),count:m.length}),U.length&&be.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:U.length}),O.length&&be.push({id:"collected",label:c("workPage.sec.collected"),count:O.length}),I.length&&be.push({id:"related",label:c("workPage.sec.related"),count:I.length}),P.length&&be.push({id:"resources",label:c("workPage.sec.resources"),count:P.length});const Oe=m.length===0&&U.length===0,ie=t.jsxs(t.Fragment,{children:[m.length>0&&t.jsxs(et,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(Je,{items:[c("workPage.versionsTotal",{n:m.length}),C&&N?c("workPage.versionsWithImage",{n:N}):"",z.rows.length!==z.allRows.length?c("workPage.versionsCurrent",{n:z.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":M&&me.length===0&&m.length>1?"":void 0,children:[me.length>0&&t.jsx(vi,{items:me,value:y,onChange:Y=>{w(Y),k(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(Nl,{label:c("workPage.scanOnly"),checked:b,onChange:Y=>{j(Y),k(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(T?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!x&&ki(z.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:F.map(Y=>{var ve;return t.jsx(fx,{row:Y,measure:(ve=h.get(Y.id))==null?void 0:ve.measure_info,loaded:h.has(Y.id),onNavigate:o,renderLink:r},`${Y.id}:${h.has(Y.id)?"r":"p"}`)})})]}),F.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(y||b?"workPage.noVersionsFiltered":"workPage.noVersions")}),!x&&t.jsx(Ko,{total:z.rows.length,shown:F.length,unit:c("workPage.moreUnit"),onClick:()=>k(!0)}),z.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),U.length>0&&t.jsx(xx,{items:U,transport:n,onNavigate:o,renderLink:r}),Oe&&t.jsx(et,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),Re=(Y,ve)=>t.jsx(qe,{id:Y,label:p(ve),onNavigate:o,renderLink:r,dense:!0}),Le=g.useMemo(()=>{const Y=new Map;for(const ve of I){const le=Js(ve.relation,c);Y.set(le,(Y.get(le)??0)+1)}return Y.size>1?[...Y.entries()].sort((ve,le)=>le[1]-ve[1]).slice(0,4).map(([ve,le])=>`${p(ve)} ${le}`).join(" · "):void 0},[I,p,c]),q=t.jsxs(t.Fragment,{children:[t.jsx(Dt,{id:"collected",title:c("workPage.sec.collected"),items:O.map(Y=>Re(Y.id,Y.title))}),t.jsx(Dt,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:I.length}),sub:Le,items:I.map(Y=>t.jsxs(t.Fragment,{children:[Re(Y.id,Y.title),t.jsx("span",{className:"bim-d-meta",title:Y.note?p(Y.note):void 0,children:p(Js(Y.relation,c))})]}))}),t.jsx(Dt,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:P.map(({r:Y,kind:ve})=>{const le=p((Y.url?dn(Y.url):void 0)||Y.name),Se=pn(Y);return t.jsxs(t.Fragment,{children:[Se?t.jsxs("a",{href:Se,target:"_blank",rel:"noopener noreferrer",children:[le," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:le}),ve&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:ve})]})})})]});return t.jsx(Ln,{railTop:a,back:l,nav:be,railLinks:d,main:ie,card:ue,side:q})};function ea(e){return(e||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function ta(e,n){return n((e.url?dn(e.url):void 0)||e.name)}function fx({row:e,measure:n,loaded:o,onNavigate:r,renderLink:s}){const{t:a,convert:l}=Q(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",p=e.holders[0],u=p?ta(p,l):e.locationName?l(e.locationName):"",m=e.images[0],h=m?pn(m):void 0,f=e.images.map(x=>ta(x,l)).join("、");return t.jsxs("tr",{"data-loading":o?void 0:"",children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(qe,{id:e.id,label:l(e.name),onNavigate:r,renderLink:s,dense:!0}),n?t.jsx("span",{className:"bim-d-meta",children:l(n)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:c?a("workPage.inferredFromEdition"):void 0,children:d?l(d):o?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||(o?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(h?t.jsx("a",{className:"bim-d-flag",href:h,target:"_blank",rel:"noopener noreferrer",title:f,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:f,children:a("workPage.hasImage")}))})]})}function xx({items:e,transport:n,onNavigate:o,renderLink:r}){const{t:s,convert:a}=Q(),[l,d]=g.useState(0),c=Math.min(l,e.length-1),p=e[c],[u,m]=g.useState(new Map);return g.useEffect(()=>{if(!n)return;const h=[...new Set(e.map(x=>x.source_bid).filter(x=>!!x))];if(h.length===0)return;let f=!1;return Promise.all(h.map(x=>n.getItem(x).then(k=>{var y,w;return[x,((w=(y=k==null?void 0:k.authors)==null?void 0:y[0])==null?void 0:w.dynasty)??""]}).catch(()=>[x,""]))).then(x=>{f||m(new Map(x.filter(([,k])=>k)))}),()=>{f=!0}},[n,e]),t.jsx(et,{id:"catalogs",title:s("workPage.sec.catalogs"),meta:t.jsx(Je,{items:[s("workPage.catalog.meta",{n:e.length}),s("workPage.sortByCatalog")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":s("workPage.catalog.tablist"),children:e.map((h,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(h.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:u.get(h.source_bid??"")?a(u.get(h.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(h.source)].slice(0,9).map((x,k)=>t.jsx("span",{children:x},k))})]})},f))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[p.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(p.title_info)}),t.jsx(Je,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[p.source_bid?t.jsx(qe,{id:p.source_bid,label:a(p.source),onNavigate:o,renderLink:r,dense:!0}):a(p.source),p.section?a(p.section):"",p.author_info?`${s("label.authorInfo")} ${a(p.author_info)}`:"",p.edition?`${s("label.edition")} ${a(p.edition)}`:"",p.page??""]}),p.summary&&t.jsx("p",{className:"bim-d-quote",children:ut(a(p.summary),void 0,{t:s})}),p.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:ut(a(p.comment),void 0,{t:s})})]}),p.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:s("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:ut(a(p.additional_comment),void 0,{t:s})})]}),!p.summary&&!p.comment&&!p.additional_comment&&!p.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:s("workPage.catalog.titleOnly")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.prev",{name:a(e[c-1].source)}),onClick:()=>d(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":s("workPage.catalog.next",{name:a(e[c+1].source)}),onClick:()=>d(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function bx(e){var n;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((n=e.year_range)==null?void 0:n[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function yx(e,n){if(!e.lineage)return null;const o=e.lineage;return{id:e.id,kind:"book",label:e.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[e.id],note:o.note}}function na(e,n,o){return{id:`derive:${n.ref}->${e}:${o}`,source:n.ref,target:e,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function jx(e,n,o){const[r,s]=[e,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function vx(e,n){var p;if(n==="all")return null;const o=(p=e.collections)==null?void 0:p[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,a=r||s||!!(o!=null&&o.hypothetical_ids);if(!a&&n==="core"&&Array.isArray(e.core_books)&&e.core_books.length>0)return{books:new Set(e.core_books),hypos:e.core_hypotheticals?new Set(e.core_hypotheticals):null};if(!o||!a)return null;const l=r?new Set(o.groups):null,d=new Set(o.book_ids??[]);if(l&&e.node_groups)for(const[u,m]of Object.entries(e.node_groups))l.has(m)&&d.add(u);let c=null;if(o.hypothetical_ids&&(c=new Set(o.hypothetical_ids)),l){c||(c=new Set);for(const u of e.hypothetical_nodes??[])u.group&&l.has(u.group)&&c.add(u.id)}return{books:d,hypos:c}}function ni(e,n,o){const r=e.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const a=new Set(r.excluded_books??[]),l=r.node_groups??{},d=vx(r,o??r.default_collection??"all"),c=d!==null,p=(d==null?void 0:d.books)??null,u=(d==null?void 0:d.hypos)??null,m=new Set,h=new Set;if(c){const S=new Map(n.map(T=>[T.id,T])),v=new Map((r.hypothetical_nodes??[]).map(T=>[T.id,T])),$=T=>{const z=S.get(T);if(z&&z.lineage)return(z.lineage.derived_from??[]).map(N=>N.ref);const F=v.get(T);return F?(F.derived_from??[]).map(N=>N.ref):[]},_=T=>v.has(T)?!u||u.has(T):!p||p.has(T),C=new Set,M=T=>{if(!C.has(T)){C.add(T);for(const z of $(T))a.has(z)||(_(z)||(v.has(z)?h.add(z):S.has(z)&&m.add(z)),M(z))}};for(const T of n)p&&p.has(T.id)&&!a.has(T.id)&&M(T.id);for(const T of r.hypothetical_nodes??[])u&&u.has(T.id)&&M(T.id)}const f=n.filter(S=>!a.has(S.id)).filter(S=>!p||p.has(S.id)||m.has(S.id)).map(S=>{const v=yx(S,l);return v&&m.has(S.id)&&(v.bridge=!0),v}).filter(S=>S!==null),x=(r.hypothetical_nodes??[]).filter(S=>!u||u.has(S.id)||h.has(S.id)).map(S=>{const v=bx(S);return h.has(S.id)&&(v.bridge=!0),v}),k=[...f,...x],y=new Set(k.map(S=>S.id)),w=new Set,b=[],j=S=>{w.has(S.id)||!y.has(S.source)||!y.has(S.target)||(w.add(S.id),b.push(S))};for(const S of n)a.has(S.id)||!S.lineage||p&&!p.has(S.id)&&!m.has(S.id)||((S.lineage.derived_from??[]).forEach((v,$)=>{j(na(S.id,v,$))}),(S.lineage.related_to??[]).forEach((v,$)=>{j(jx(S.id,v,$))}));for(const S of r.hypothetical_nodes??[])u&&!u.has(S.id)&&!h.has(S.id)||(S.derived_from??[]).forEach((v,$)=>{j(na(S.id,v,$))});return{nodes:k,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(a)}}function Ic(e,n,o){const r=(e??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function kx(e,n){const o=[],r=e.version_graph;if(!r)return o;const s=new Set(n.map(c=>c.id)),a=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...a]),d=(c,p)=>{l.has(p.ref)||o.push(`${c}: derived_from.ref "${p.ref}" 未在 books 或 hypothetical_nodes 中找到`),p.ref_type==="book"&&!s.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 book 但不在 books 列表中`),p.ref_type==="hypothetical"&&!a.has(p.ref)&&o.push(`${c}: derived_from.ref "${p.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const p=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>d(p,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${p}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const p=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>d(p,u))}return o}const Rc=({graph:e,renderLink:n,className:o,style:r})=>{const{t:s,convert:a}=Q();if(!e.nodes.length)return t.jsx("div",{style:{...Px,...r},className:o,children:s("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const x=l.get(f.target)??[];x.push(f),l.set(f.target,x)}else for(const x of[f.source,f.target]){const k=d.get(x)??[];k.push(f),d.set(x,k)}const c=new Map(e.nodes.map(f=>[f.id,f])),p=new Map,u=[];for(const f of e.nodes)if(f.group){const x=p.get(f.group)??[];x.push(f),p.set(f.group,x)}else u.push(f);const m=(f,x)=>(f.year??9999)-(x.year??9999);p.forEach(f=>f.sort(m)),u.sort(m);const h=e.groups.filter(f=>p.has(f.id));return t.jsxs("div",{className:o,style:{...Sx,...r},children:[e.title&&t.jsx("div",{style:_x,children:a(e.title)}),e.description&&t.jsx("div",{style:$x,children:a(e.description)}),h.map(f=>t.jsx(ia,{label:f.label,color:f.color,nodes:p.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n},f.id)),u.length>0&&t.jsx(ia,{label:s("lineage.otherGroup"),nodes:u,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:n})]})},ia=({label:e,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:a,renderLink:l})=>{const{convert:d}=Q();return t.jsxs("div",{style:Cx,children:[t.jsx("div",{style:{...zx,borderLeftColor:n??i("widget-border")},children:d(e)}),o.map(c=>t.jsx(wx,{node:c,incoming:r.get(c.id)??[],siblings:s.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},wx=({node:e,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=Q();return t.jsxs("div",{style:{...Tx,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?i("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Nx,children:[t.jsx("span",{style:Ex,children:a||!s?c(e.label):s(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Ix,children:Ic(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Rx,children:[e.category&&t.jsx(Sn,{children:c(e.category)}),e.status==="lost"&&t.jsx(Sn,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Sn,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Sn,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Sn,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Lx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ax,children:c(e.note)}),n.length>0&&t.jsxs("div",{style:ra,children:[t.jsx("div",{style:sa,children:d("lineage.sources")}),n.map(p=>{const u=r.get(p.source);return t.jsxs("div",{style:aa(p.confidence),children:[t.jsx("span",{style:la,children:c(p.relation)}),t.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,c(u.label)):c((u==null?void 0:u.label)??p.source)}),p.confidence!=="consensus"&&p.confidence!=="certain"&&t.jsx(oa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ca,children:["· ",c(p.evidence)]})]},p.id)})]}),o.length>0&&t.jsxs("div",{style:ra,children:[t.jsx("div",{style:sa,children:d("lineage.related")}),o.map(p=>{const u=p.source===e.id?p.target:p.source,m=r.get(u);return t.jsxs("div",{style:aa(p.confidence),children:[t.jsx("span",{style:la,children:c(p.relation)}),t.jsx("span",{children:(m==null?void 0:m.kind)==="book"&&s?s(m.id,c(m.label)):c((m==null?void 0:m.label)??u)}),t.jsx(oa,{level:p.confidence}),p.evidence&&t.jsxs("span",{style:ca,children:["· ",c(p.evidence)]})]},p.id)})]})]})},Sn=({children:e,tone:n="default"})=>{const r={default:{bg:i("tag-bg"),fg:i("fg")},warn:{bg:i("warn-bg"),fg:i("warn-fg")},info:{bg:i("info-bg"),fg:i("info-fg")}}[n];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})},oa=({level:e})=>{const{t:n}=Q(),r={certain:{key:"certain",color:i("confidence-certain")},consensus:{key:"consensus",color:i("confidence-consensus")},probable:{key:"probable",color:i("confidence-probable")},disputed:{key:"disputed",color:i("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:n(`lineage.confidence.${r.key}`)}):null},Sx={fontSize:"14px",color:i("fg")},_x={fontSize:"16px",fontWeight:600,marginBottom:"8px"},$x={fontSize:"13px",color:i("muted"),marginBottom:"16px",lineHeight:1.6},Cx={marginBottom:"16px"},zx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:i("fg")},Tx={border:`1px solid ${i("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:i("bg")},Nx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ex={fontSize:"15px",fontWeight:600},Ix={fontSize:"12px",color:i("muted")},Rx={marginBottom:"6px"},Lx={fontSize:"12px",color:i("muted"),margin:"2px 0"},Ax={fontSize:"12px",color:i("muted"),fontStyle:"italic",margin:"4px 0"},ra={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${i("widget-border")}`},sa={fontSize:"11px",color:i("muted"),marginBottom:"2px"},aa=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),la={display:"inline-block",padding:"0 6px",fontSize:"11px",background:i("tag-bg"),color:i("fg"),borderRadius:"3px",marginRight:"6px"},ca={fontSize:"11px",color:i("muted")},Px={padding:"20px",textAlign:"center",color:i("muted"),fontSize:"13px"},Lc=({selectedNodeId:e,...n})=>{const{t:o}=Q(),[r,s]=g.useState("loading"),[a,l]=g.useState(null);return g.useEffect(()=>{let d=!1;return Mx().then(c=>{d||(c?(l(c),s("ready")):s("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:pa,children:o("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:pa,children:[t.jsx("div",{children:da(o("lineage.graphMissing"),{xyflow:t.jsx("code",{children:"@xyflow/react"}),dagre:t.jsx("code",{children:"@dagrejs/dagre"})})}),t.jsx("div",{style:{fontSize:"12px",marginTop:"4px"},children:da(o("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Bx,{modules:a,selectedNodeId:e,...n})};function da(e,n){return e.split(/(\{\w+\})/).map((o,r)=>{const s=/^\{(\w+)\}$/.exec(o);return t.jsx(g.Fragment,{children:s&&s[1]in n?n[s[1]]:o},r)})}async function Mx(){try{const[e,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:n,cssLoaded:o}}catch{return null}}const Bx=({graph:e,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:p,Handle:u,Position:m,BaseEdge:h,EdgeLabelRenderer:f,getSmoothStepPath:x,dagre:k}=l,y=g.useMemo(()=>({lineage:$=>{var I,P,U,K;const _=((I=$.data)==null?void 0:I.stepPosition)??.85,[C,M,T]=x({sourceX:$.sourceX,sourceY:$.sourceY,sourcePosition:$.sourcePosition,targetX:$.targetX,targetY:$.targetY,targetPosition:$.targetPosition,stepPosition:_,borderRadius:5}),z=!!((P=$.data)!=null&&P.isSibling),F=z?M:$.targetX-18,N=z?T:$.targetY-12,R=(U=$.data)==null?void 0:U.labelStyle,O=(K=$.data)==null?void 0:K.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(h,{id:$.id,path:C,style:$.style,markerStart:$.markerStart,markerEnd:$.markerEnd}),$.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${N}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:i("bg"),border:`0.5px solid ${i("widget-border")}`,...O,...R},children:$.label})})]})}}),[h,f,x]),w=g.useMemo(()=>({version:$=>{const{t:_}=Q(),C=$.data,M=C.kind==="hypothetical",T=C.status==="lost",z=C.isSelected,F=C.bridge,N=C.borderColor??i("muted"),R=F||M?"dashed":"solid",O=F?.5:T?.6:1;return t.jsxs("div",{style:{background:i(F?"bg-subtle":"bg"),border:`2px ${R} ${z?i("primary"):N}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:z?i("shadow-node-selected"):M||F?"none":i("shadow-node")},title:F?_("lineage.bridgeTitle"):void 0,children:[t.jsx(u,{type:"target",position:m.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:M||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:i("aux-fg"),lineHeight:1.2},children:Ic(C.yearText,void 0,C.uncertain)}),T&&t.jsx("div",{style:{fontSize:9,color:i("lost-fg"),marginTop:1},children:_("lineage.lost")}),t.jsx(u,{type:"source",position:m.Right,style:{visibility:"hidden"}})]})}}),[u,m]),{convert:b}=Q(),{rfNodes:j,rfEdges:S}=g.useMemo(()=>Wx(e,k,n,a,b),[e,k,n,a,b]);return t.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:y,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(p,{showInteractive:!1})]})})};function Wx(e,n,o,r,s=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new n.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const p=new Map(e.groups.map(w=>[w.id,w.color??i("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(u.has(w.relation)||c.setEdge(w.source,w.target));n.layout(c);const m=e.nodes.map(w=>{const b=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:s(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:s(w.year_text??Hx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?p.get(w.group):void 0,renderLink:o,isSelected:j,description:s(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:S,draggable:!1,selected:j}}),h=.78,f=.06,x=new Map;for(const w of e.edges)w.kind==="derive"&&(x.has(w.source)||x.set(w.source,[]),x.get(w.source).push(w));const k=new Map;for(const[w,b]of x){if(b.length<=1)continue;const j=[...b].sort((v,$)=>{var M,T;const _=((M=c.node(v.target))==null?void 0:M.y)??0,C=((T=c.node($.target))==null?void 0:T.y)??0;return _-C}),S=j.length;j.forEach((v,$)=>{const _=($-(S-1)/2)*f;k.set(v.id,h+_)})}const y=e.edges.map(w=>Ox(w,k.get(w.id),s));return{rfNodes:m,rfEdges:y}}function Ox(e,n,o=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",s=e.kind==="sibling",a=Fx(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:o(e.relation),data:{labelStyle:{color:i("fg")},isSibling:s,stepPosition:n},style:{stroke:a,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Hx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Fx(e){switch(e){case"certain":return i("confidence-certain");case"consensus":return i("lineage-edge-consensus");case"probable":return i("confidence-probable");case"disputed":return i("confidence-disputed");default:return i("muted")}}const pa={padding:"40px 20px",textAlign:"center",color:i("muted"),fontSize:"13px",border:`1px dashed ${i("widget-border")}`,borderRadius:8,background:i("bg")},kr=({graph:e,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:p,className:u,style:m})=>{var S;const{t:h,convert:f}=Q(),[x,k]=g.useState(n),y=v=>{k(v),a==null||a(v)},w=(()=>{if(!c)return[];const v=Object.entries(c);return v.length===0||c.all?v:[...v,["all",{label:h("lineage.collectionAll"),description:h("lineage.collectionAllDesc")}]]})(),b=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:i("muted"),textAlign:"center"},children:h("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:u,style:m,children:[t.jsxs("div",{style:Dx,children:[t.jsx("button",{onClick:()=>y("list"),style:Ji(x==="list"),children:h("lineage.modeList")}),t.jsx("button",{onClick:()=>y("graph"),style:Ji(x==="graph"),children:h("lineage.modeGraph")}),b&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:i("muted"),marginRight:4},children:h("lineage.collectionLabel")}),w.map(([v,$])=>{const _=p==null?void 0:p[v];return t.jsxs("button",{onClick:()=>d==null?void 0:d(v),style:Ji(l===v),title:$.description?f($.description):void 0,children:[f($.label),_!=null?` ${_}`:""]},v)})]})]}),b&&j&&t.jsx("div",{style:{fontSize:12,color:i("muted"),marginBottom:8,padding:"4px 8px",background:i("bg-subtle"),borderRadius:4},children:f(j)}),x==="list"?t.jsx(Rc,{graph:e,renderLink:o}):t.jsx(Lc,{graph:e,renderLink:o,height:r,selectedNodeId:s})]})},Dx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Ji=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${i("widget-border")}`,borderRadius:4,background:e?i("primary"):"transparent",color:i(e?"primary-fg":"fg"),cursor:"pointer"}),ua=40,ma=2,Ux=9,Vx=new Set(["certain","consensus","probable","disputed"]);function Qi(e){if(!e)return["",""];const n=e.split(/[  ]+/).filter(Boolean);return n.length>=2&&/^第.+[回章卷篇節节]$/.test(n[0])?[n[0],n[1]]:["",e]}const Ac=({data:e,transport:n,onNavigate:o,renderLink:r,readAction:s,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:p,railLinks:u})=>{var H,se,ne,ge,Ne,Be,We,Ue,Qe,ce,tt;const m=$e(),{t:h,convert:f}=Q(),[x,k]=g.useState(null),[y,w]=g.useState(new Map),[b,j]=g.useState([]),[S,v]=g.useState(new Map),[$,_]=g.useState(!1),[C,M]=g.useState("flow"),[T,z]=g.useState(null);g.useEffect(()=>{if(!n||!e.work_id){k(null);return}let E=!1;return n.getItem(e.work_id).then(oe=>{!E&&oe&&oe.type==="work"&&k(oe)}).catch(()=>{}),()=>{E=!0}},[n,e.work_id]),g.useEffect(()=>{if(!(n!=null&&n.getLineageGraph)||!e.work_id){z(null);return}let E=!1;return n.getLineageGraph(e.work_id).then(oe=>{E||z(oe&&oe.nodes.length>1?oe:null)}).catch(()=>{E||z(null)}),()=>{E=!0}},[n,e.work_id]),g.useEffect(()=>{const E=e.contained_in||[];if(!n||E.length===0){w(new Map);return}let oe=!1;return Promise.all(E.map(ae=>{const je=typeof ae=="string"?ae:ae.id;return n.getItem(je).then(ke=>[je,ke]).catch(()=>[je,null])})).then(ae=>{if(oe)return;const je=new Map;for(const[ke,xe]of ae)xe&&je.set(ke,xe);w(je)}),()=>{oe=!0}},[n,e.contained_in]);const F=g.useMemo(()=>{const E=new Set([...(x==null?void 0:x.books)||[],...e.related_books||[]]);return E.add(e.id),[...E]},[x==null?void 0:x.books,e.related_books,e.id]),N=F.length-1;g.useEffect(()=>{if(!n||N<=0){j([]);return}const E=F.length<=ua,oe=E?F:F.slice(0,8);let ae=!1;return Promise.all(oe.map(je=>je===e.id?Promise.resolve({id:je,title:e.title,edition:e.edition,year:ri(e)}):n.getItem(je).then(ke=>{const xe=ke??{};return{id:je,title:xe.title,edition:xe.edition,year:ke?ri(xe):void 0}}).catch(()=>({id:je})))).then(je=>{if(ae)return;const ke=je.filter(xe=>xe.id===e.id||xe.title||xe.edition);E&&ke.sort((xe,G)=>(xe.year??1/0)-(G.year??1/0)),j(ke)}),()=>{ae=!0}},[n,F,N,e]);const R=e.lineage,O=g.useMemo(()=>[...((R==null?void 0:R.derived_from)||[]).filter(E=>E.ref_type==="book").map(E=>E.ref),...((R==null?void 0:R.related_to)||[]).map(E=>E.book_id)].filter(Boolean),[R]);g.useEffect(()=>{if(!n||O.length===0){v(new Map);return}let E=!1;return Promise.all(O.map(oe=>n.getItem(oe).then(ae=>[oe,{id:oe,title:ae==null?void 0:ae.title,edition:ae==null?void 0:ae.edition}]).catch(()=>[oe,{id:oe}]))).then(oe=>{E||v(new Map(oe))}),()=>{E=!0}},[n,O]);const I=g.useMemo(()=>zc(e.resources,e.resource_groups,h),[e.resources,e.resource_groups,h]),P=I.groups.reduce((E,oe)=>E+oe.rows.length+oe.mirrors.length,0),U=I.groups.length>0&&I.groups.every(E=>E.key==="_physical"),K=Rn(e),L=zl(e),Z=zt(e,m.unit.juan),A=new Set((e.contained_in||[]).map(E=>typeof E=="string"?0:Tn(E.volume_index).length).filter(E=>E>0)),V=E=>{var je;const oe=(je=e.base_edition)==null?void 0:je.find(ke=>ke.book_id===E&&ke.name);if(oe!=null&&oe.name)return oe.name;const ae=S.get(E);return(ae==null?void 0:ae.edition)||(ae==null?void 0:ae.title)||""},pe=g.useMemo(()=>{var Te,Ee,D,re,Pe;const E=[];L&&E.push({label:h("bookPage.fact.editionType"),value:f(L),title:e.edition_type||(Te=e.lineage)!=null&&Te.category?void 0:h("bookPage.inferredFromEdition")}),(Ee=e.publication_info)!=null&&Ee.details?E.push({label:h("bookPage.fact.publication"),value:f(e.publication_info.details)}):(K.era||K.reign)&&E.push({label:h("bookPage.fact.era"),value:f([K.era,K.reign].filter(Boolean).join(" ")),title:K.source==="edition"?h("bookPage.inferredFromEdition"):void 0}),Z&&E.push({label:h("bookPage.fact.measure"),value:f(Z)});const oe=(e.contained_in||[]).flatMap(_e=>typeof _e=="string"?[]:Tn(_e.volume_index));oe.length&&E.push({label:h("bookPage.fact.volumes"),value:h("bookPage.volumesValue",{range:ji(oe,m.unit.volume),unit:m.unit.volume,n:oe.length})});const ae=(((D=e.lineage)==null?void 0:D.derived_from)||[]).find(_e=>_e.relation==="底本"&&_e.ref_type==="book");ae&&V(ae.ref)&&E.push({label:h("bookPage.fact.baseEdition"),value:t.jsx(qe,{id:ae.ref,label:f(V(ae.ref)),onNavigate:o,renderLink:r,dense:!0})});const je=(e.base_edition||[]).filter(_e=>_e&&_e.name);for(const _e of["底本","配補","參校"]){if(_e==="底本"&&ae&&V(ae.ref))continue;const Ge=je.filter(He=>He.role===_e);Ge.length&&E.push({label:f(_e),value:Ge.map((He,De)=>t.jsxs(g.Fragment,{children:[De>0&&"、",He.book_id?t.jsx(qe,{id:He.book_id,label:f(He.name),onNavigate:o,renderLink:r,dense:!0}):f(He.name)]},De))})}const ke=(e.provenance||[]).filter(_e=>_e&&_e.institution),xe=(e.resources||[]).filter(_e=>(_e.types||(_e.type?[_e.type]:[])).includes("physical"));if(ke.length){E.push({label:h("bookPage.fact.holdings"),value:ke.slice(0,2).map(He=>f(He.institution)).join("、")+(ke.length>2?h("bookPage.andMorePlaces",{n:ke.length}):"")});const _e=ke.filter(He=>He.call_number).slice(0,2).map(He=>`${f(He.institution)} ${He.call_number}`);_e.length&&E.push({label:h("bookPage.fact.callNumber"),value:_e.join(";")+(ke.filter(He=>He.call_number).length>2?"…":"")});const Ge=ke.flatMap(He=>He.seals||[]).filter(Boolean);Ge.length&&E.push({label:h("bookPage.fact.seals"),value:f(Ge.join("、"))})}else xe.length?E.push({label:h("bookPage.fact.holdings"),value:xe.slice(0,2).map(_e=>f(_e.name)).join("、")+(xe.length>2?h("bookPage.andMorePlaces",{n:xe.length}):"")}):(re=e.current_location)!=null&&re.name&&E.push({label:h("bookPage.fact.holdings"),value:f(e.current_location.name)});const G=e.physical_description;if(G){const _e=[[h("bookPage.fact.leafStyle"),G.leaf_style],[h("bookPage.fact.binding"),G.binding],[h("bookPage.fact.dimensions"),G.dimensions],[h("bookPage.fact.condition"),G.condition]];for(const[Ge,He]of _e)He&&He.trim()&&E.push({label:Ge,value:f(He)})}(Pe=e.page_count)!=null&&Pe.description&&E.push({label:m.label.pageCount,value:f(e.page_count.description)});const de=[...xo(e.additional_titles),...xo(e.attached_texts)];return de.length&&E.push({label:h("bookPage.fact.aliases"),value:de.map(f).join("、")}),E},[e,f,m,h,K,L,Z,S,o,r]),ee=f(e.title),ue=e.edition?f(e.edition):void 0,me=((H=e.lineage)==null?void 0:H.year_text)||"",be=t.jsx(An,{kind:h("bookPage.kind"),title:ee,subtitle:ue,byline:t.jsx(jr,{authors:e.authors??(x==null?void 0:x.authors),onNavigate:o,renderLink:r}),meta:(()=>{const E=[L?f(L):"",K.era?f([K.era,K.reign].filter(Boolean).join("")):"",Z?f(Z):""].filter(Boolean);return E.length?t.jsx("span",{className:"bim-d-tags",children:E.map((oe,ae)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(ae,2)}`,children:oe},ae))}):null})(),description:(se=e.description)!=null&&se.text?t.jsx(Ct,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Xo((ne=e.description)==null?void 0:ne.text)?6:void 0,facts:pe,readAction:s,secondaryAction:s&&P>0&&!U?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:h("bookPage.viewImages")}):void 0,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),Oe=e.contained_in||[],ie=(a==null?void 0:a.chapters)||[],Re=f(ie[0]&&Qi(ie[0].title)[0].slice(-1)||"")||h("bookPage.chapterUnit"),Le=h("bookPage.chapterCount",{n:ie.length,unit:Re}),q=!!((ge=R==null?void 0:R.derived_from)!=null&&ge.length||(Ne=R==null?void 0:R.related_to)!=null&&Ne.length||(Be=e.appendix)!=null&&Be.length),J=[],fe=h(U?"bookPage.sec.physical":"bookPage.sec.images");(ie.length||I.text.length||l)&&J.push({id:"fulltext",label:h("bookPage.sec.fulltext"),count:ie.length?Le:void 0}),I.groups.length&&J.push({id:"images",label:fe,count:P}),q&&J.push({id:"lineage",label:h("bookPage.sec.lineage")}),Oe.length&&J.push({id:"collections",label:h("section.containedIn"),count:Oe.length}),(We=e.location_history)!=null&&We.length&&J.push({id:"provenance",label:h("section.locationHistory")});const ze=E=>(d==null?void 0:d(E))??null,Y=ie[0],ve=Y?ze(Y.file):null,le=$?ie:ie.slice(0,Ux),Se=(E,oe,ae)=>E?t.jsx("a",{className:ae,href:E.href??"#",onClick:E.onClick?je=>{je.metaKey||je.ctrlKey||(je.preventDefault(),E.onClick())}:void 0,children:oe}):t.jsx("span",{className:ae,children:oe}),X=t.jsxs(t.Fragment,{children:[(ie.length>0||I.text.length>0||l)&&t.jsxs(et,{id:"fulltext",title:h("bookPage.sec.fulltext"),meta:ie.length>0?t.jsx(Je,{items:[Le,(Ue=a==null?void 0:a.source)!=null&&Ue.name?h("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!Y&&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"})]}),Y&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:h("bookPage.readFrom",{ch:f(Qi(Y.title)[0])||h("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((Y.title||"").replace(/^第.+?[回章卷篇節节][  ]*/,""))}),Se(ve,t.jsxs(t.Fragment,{children:[h("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),ie.length>1&&t.jsx("ul",{className:"bim-d-chap",children:le.map(E=>{const[oe,ae]=Qi(E.title);return t.jsx("li",{children:Se(ze(E.file),t.jsxs(t.Fragment,{children:[oe&&t.jsx("b",{children:f(oe)}),f(ae||E.file)]}))},E.file)})}),ie.length>le.length&&t.jsx(qo,{label:h("detail.expandRest",{n:ie.length-le.length,unit:Re}),onClick:()=>_(!0)}),I.text.length>0&&t.jsxs(t.Fragment,{children:[(ie.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:h("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:I.text.map((E,oe)=>t.jsx(vr,{item:E,siblings:I.text,listedVolumeCounts:A},`${E.id||E.url||E.name}-${oe}`))})})]})]}),I.groups.length>0&&t.jsx(et,{id:"images",title:fe,meta:t.jsx(Je,{items:[I.groups.length>1?h("bookPage.groupCount",{n:I.groups.length}):"",h("bookPage.placeCount",{n:P})]}),children:t.jsx(Nc,{groups:I.groups,listedVolumeCounts:A})}),q&&t.jsx(et,{id:"lineage",title:h("bookPage.sec.lineage"),meta:(Qe=R==null?void 0:R.derived_from)!=null&&Qe.length?h("bookPage.lineageMeta"):void 0,action:T?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":h("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":C==="flow",onClick:()=>M("flow"),children:h("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>M("graph"),children:h("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&T?t.jsx(kr,{graph:T,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(E,oe)=>t.jsx(qe,{id:E,label:f(oe),onNavigate:o,renderLink:r,dense:!0})}):t.jsx(Yx,{data:e,heading:ue||ee,yearText:me,refName:V,onNavigate:o,renderLink:r})}),Oe.length>0&&t.jsx(et,{id:"collections",title:h("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Oe.map((E,oe)=>{var G,de;const ae=typeof E=="string"?E:E.id,je=typeof E=="string"?[]:Tn(E.volume_index),ke=y.get(ae),xe=(ke==null?void 0:ke._member_count)||((G=ke==null?void 0:ke.books)==null?void 0:G.length)||((de=ke==null?void 0:ke.contained_works)==null?void 0:de.length)||0;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(qe,{id:ae,label:ke?f(ke.title):ae,onNavigate:o,renderLink:r,dense:!0}),je.length>0&&t.jsx(Gx,{volumes:je,unit:m.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${xe?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:xe>0&&h("bookPage.totalOf",{n:xe,unit:m.unit.bu})})]},`${ae}-${oe}`)})})})}),(ce=e.location_history)!=null&&ce.length?t.jsx(et,{id:"provenance",title:h("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((E,oe)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(E.name)}),([E.start_date,E.end_date].filter(Boolean).join("—")||E.description)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(Je,{items:[[E.start_date,E.end_date].filter(Boolean).join("—"),E.description?f(E.description):""]})})]},oe))})}):null,J.length===0&&t.jsx(et,{title:h("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:h("bookPage.emptyText")})})]}),Ce=b.findIndex(E=>E.id===e.id),Me=F.length<=ua,B=Me&&Ce>=0?b.slice(Math.max(0,Ce-ma),Ce+ma+1):b.filter(E=>E.id!==e.id),te=t.jsxs(t.Fragment,{children:[x&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:f(m.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(qe,{id:x.id,label:f(x.title),onNavigate:o,renderLink:r})}),t.jsx(Je,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(x.authors||[]).slice(0,2).map(E=>`${E.dynasty?`〔${f(E.dynasty)}〕`:""}${f(E.name)}`),f(zt(x,m.unit.juan)),x._edition_count?h("bookPage.editionCount",{n:x._edition_count}):""]}),((tt=x.description)==null?void 0:tt.text)&&t.jsx("p",{style:{fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc bim-d-side-desc",children:f(x.description.text.replace(/[#*_>`[\]]/g,""))})]}),N>0&&B.length>0&&t.jsxs("div",{children:[t.jsx(Dt,{id:"siblings",timeline:!0,title:Me?h("bookPage.siblings"):m.relation.siblingVersions,meta:Me?h("bookPage.byEra"):h("bookPage.kindCount",{n:N}),cap:B.length,items:B.map(E=>E.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(E.edition||E.title||E.id)}):t.jsx(qe,{id:E.id,label:f(E.edition||E.title||E.id),onNavigate:o,renderLink:r,dense:!0})),metas:B.map(E=>[E.year!=null?E.year<0?h("detail.bce",{n:-E.year}):String(E.year):"",E.id===e.id?h("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:B.findIndex(E=>E.id===e.id)}),x&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(qe,{id:x.id,label:h("bookPage.viewAllInWork",{n:F.length}),onNavigate:o,renderLink:r,dense:!0})})]})]}),ye=e.work_id?t.jsx(Tl,{caption:m.section.belongsToWork,children:t.jsx(qe,{id:e.work_id,label:x?f(x.title):" ",onNavigate:o,renderLink:r,dense:!0})}):void 0;return t.jsx(Ln,{railTop:c,back:p,up:ye,nav:J,railLinks:u,main:X,card:be,side:te})};function Gx({volumes:e,unit:n}){const{t:o}=Q();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[o("bookPage.volumeRange",{range:ji(e,n),unit:n}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),o("bookPage.volumeCount",{n:e.length,unit:n})]})]})}function Yx({data:e,heading:n,yearText:o,refName:r,onNavigate:s,renderLink:a}){var w;const{t:l,convert:d}=Q(),c=e.lineage,p=(c==null?void 0:c.derived_from)||[],u=p.filter(b=>b.ref_type!=="book"),m=p.filter(b=>b.ref_type==="book"&&b.relation==="底本"),h=p.filter(b=>b.ref_type==="book"&&b.relation!=="底本"),f=(c==null?void 0:c.related_to)||[],x=p.length>0||f.length>0,k=b=>b&&Vx.has(b)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${b}`)}):"",y=(b,j)=>t.jsx(qe,{id:b,label:d(j||b),onNavigate:s,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[x&&t.jsxs("ol",{className:"bim-d-lf-list",children:[u.map((b,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:b.relation?d(b.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),b.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(b.evidence),k(b.confidence)]})]})},`a-${j}`)),m.map((b,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(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.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:n}),o&&t.jsx("span",{className:"bim-d-lf-yr",children:d(o)})]}),h.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:h.map((b,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(b.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:y(b.ref,r(b.ref))}),b.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(b.evidence),k(b.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((b,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:b.evidence?d(b.evidence):void 0,children:[y(b.book_id,r(b.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(b.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((b,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(b.title)]}),t.jsx(Ct,{text:b.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 _n=16,Kx=200,qx=16,Pc=({data:e,catalog:n,transport:o,onNavigate:r,renderLink:s,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var Se,X,Ce,Me,B,te,ye;const{t:p,convert:u,messages:m}=Q(),[h,f]=g.useState(""),[x,k]=g.useState(!1),[y,w]=g.useState(null),[b,j]=g.useState(""),[S,v]=g.useState(!1),$=g.useMemo(()=>$l(e,n),[e,n]),[_,C]=g.useState(new Map),M=!!o&&$.rows.length>0&&$.rows.length<=Kx,T=M&&($.rows.length<=_n||S),z=T&&$.rows.every(H=>!H.id||_.has(H.id)),F=H=>{var se;return _o(H?(se=_.get(H))==null?void 0:se.l1:void 0)},N=g.useMemo(()=>{const H=h.trim(),se=H?u(H):"";return $.rows.filter(ne=>{var Ne,Be;if(b&&_o(ne.id?(Ne=_.get(ne.id))==null?void 0:Ne.l1:void 0)!==b)return!1;if(!se)return!0;const ge=ne.id&&((Be=_.get(ne.id))==null?void 0:Be.title)||ne.title;return u(ge).includes(se)||(ne.subItems||[]).some(We=>u(We).includes(se))})},[$.rows,h,b,_,u]),R=x?N:N.slice(0,_n),O=g.useMemo(()=>(T?$.rows:R).filter(H=>H.id&&!_.has(H.id)).map(H=>H.id),[T,$.rows,R,_]);g.useEffect(()=>{if(!o||O.length===0)return;let H=!1;const se=O.slice(0,qx);return Promise.all(se.map(ne=>o.getItem(ne).then(ge=>{var We,Ue;const Ne=ge??{},Be={title:Ne.title,edition:Ne.edition,authors:Ne.authors,measure:ge?zt(ge,m.unit.juan):void 0,versionCount:Ne._edition_count??((We=Ne.books)==null?void 0:We.length),l1:((Ue=Ne.classification)==null?void 0:Ue.l1)||void 0};return[ne,Be]}).catch(()=>[ne,{}]))).then(ne=>{H||C(ge=>{const Ne=new Map(ge);for(const[Be,We]of ne)Ne.set(Be,We);return Ne})}),()=>{H=!0}},[o,O,m.unit.juan]);const I=(e.contained_in||[])[0];g.useEffect(()=>{if(!I){w(null);return}if(w({id:I}),!o)return;let H=!1;return o.getItem(I).then(se=>{H||w({id:I,title:se==null?void 0:se.title})}).catch(()=>{}),()=>{H=!0}},[o,I]);const P=g.useMemo(()=>zc(e.resources,e.resource_groups,p),[e.resources,e.resource_groups,p]),U=P.text.length+P.groups.reduce((H,se)=>H+se.rows.length+se.mirrors.length,0),K=e.contained_works||[],L=new Set($.rows.map(H=>H.id).filter(Boolean)),Z=K.length>0&&!K.every(H=>L.has(H.id)),A=(()=>{const H=$.rows.map(se=>se.edition).filter(Boolean);return H.length>1&&new Set(H).size===1})(),V=$.rows.some(H=>H.volumes.length>0||H.expected!=null),pe=e._member_count||((Se=e.books)==null?void 0:Se.length)||K.length,ee=zt(e,m.unit.juan),ue=e.count,me=H=>typeof H=="number"&&Number.isFinite(H)?H:null,be=me(ue==null?void 0:ue.juan)??me((X=e.juan_count)==null?void 0:X.number),Oe=me(ue==null?void 0:ue.ce)??($.totalVolumes||null),ie=[{value:$.rows.length,label:p("collectionPage.stat.titles")},{value:be??0,label:m.unit.juan},{value:Oe??0,label:m.unit.volume}],Re=g.useMemo(()=>{var ne,ge;const H=[];if((ne=e.publication_info)!=null&&ne.details&&H.push({label:p("collectionPage.fact.publication"),value:u(e.publication_info.details)}),pe&&pe!==$.rows.length){const Ne=e._member_type==="Book"?p("collectionPage.member.Book"):e._member_type==="Work"?p("collectionPage.member.Work"):p("collectionPage.member.other");H.push({label:Ne,value:`${pe} ${m.unit.bu}`,title:p("collectionPage.memberNote")})}const se=[me(ue==null?void 0:ue.zhong)!=null?p("collectionPage.nZhong",{n:ue.zhong}):"",me(ue==null?void 0:ue.han)!=null?p("collectionPage.nHan",{n:ue.han}):""].filter(Boolean);return se.length&&H.push({label:p("collectionPage.fact.expected"),value:se.join(" ")}),be==null&&ee&&H.push({label:p("collectionPage.fact.measure"),value:u(ee),title:(ge=e.juan_count)!=null&&ge.description?u(e.juan_count.description):void 0}),H},[e,pe,$.rows.length,be,ee,ue,u,p,m]),Le=g.useMemo(()=>{if(!z)return[];const H=new Map;for(const ne of $.rows){const ge=F(ne.id);ge&&H.set(ge,(H.get(ge)??0)+1)}const se=En.filter(ne=>(H.get(ne.key)??0)>0);return se.length<2?[]:[{key:"",label:`${m.catalog.all} ${$.rows.length}`},...se.map(ne=>({key:ne.key,label:`${ne.label} ${H.get(ne.key)}`}))]},[z,$.rows,_,m]),q=g.useMemo(()=>{if(!z||!$.rows.some(ge=>ge.volumes.length>0))return null;const H=[],se=$.rows.filter(ge=>ge.volumes.length>0).map(ge=>({k:F(ge.id)??"",from:Math.min(...ge.volumes),to:Math.max(...ge.volumes)})).sort((ge,Ne)=>ge.from-Ne.from);for(const ge of se){const Ne=ge.to-ge.from+1,Be=H[H.length-1];Be&&Be.key===ge.k?(Be.to=Math.max(Be.to,ge.to),Be.n+=Ne):H.push({key:ge.k,from:ge.from,to:ge.to,n:Ne})}const ne=se.reduce((ge,Ne)=>Math.max(ge,Ne.to),0);return H.length>1&&H.some(ge=>ge.key)?{segs:H,last:ne}:null},[z,$.rows,_]),J=(Ce=e.description)==null?void 0:Ce.text,fe=t.jsx(An,{kind:p("collectionPage.kind"),title:u(e.title),byline:t.jsx(jr,{authors:e.authors,onNavigate:r,renderLink:s}),meta:t.jsx(Je,{items:[e.subtype==="work_collection"?p("collectionPage.workCollection"):"",(Me=e.publication_info)!=null&&Me.year?u(e.publication_info.year):""]}),description:J||(B=e.history)!=null&&B.length?t.jsxs(t.Fragment,{children:[J&&t.jsx(Ct,{text:J,style:{fontSize:15,lineHeight:1.85}}),(te=e.history)!=null&&te.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((H,se)=>t.jsx("li",{children:u(H)},se))}):null]}):void 0,clampDescription:Xo(J)||(((ye=e.history)==null?void 0:ye.length)??0)>2?6:void 0,stats:ie,facts:Re,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:q&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:p("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":p("collectionPage.dist.head"),children:q.segs.map((H,se)=>{const ne=En.find(ge=>ge.key===H.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!ne,title:ne?p("collectionPage.dist.segTitle",{section:u(ne.label),from:H.from,to:H.to}):void 0,"aria-label":ne?p("collectionPage.dist.only",{section:u(ne.label)}):p("collectionPage.dist.unclassified"),"aria-pressed":!!ne&&b===H.key,style:{flexGrow:H.n,background:i(ne?ne.token:"rule")},onClick:()=>{ne&&(j(b===H.key?"":H.key),k(!1))}},se)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:p("catalog.volume",{n:1})}),t.jsx("span",{children:p("collectionPage.dist.hint")}),t.jsx("span",{children:p("catalog.volume",{n:q.last})})]})]})}),ze=[];$.rows.length&&ze.push({id:"titles",label:p("collectionPage.sec.titles"),count:$.rows.length}),U&&ze.push({id:"resources",label:p("collectionPage.sec.resources"),count:U}),Z&&ze.push({id:"works",label:m.section.containedWorks,count:K.length});const Y=t.jsxs(t.Fragment,{children:[$.rows.length>0&&t.jsxs(et,{id:"titles",title:p("collectionPage.sec.titles"),meta:t.jsx(Je,{items:[`${$.rows.length} ${m.unit.items}`,$.totalVolumes?p("collectionPage.totalVolumes",{n:$.totalVolumes,unit:m.unit.volume}):"",N.length!==$.rows.length?p("collectionPage.currentN",{n:N.length,unit:m.unit.items}):""]}),action:a,children:[($.rows.length>_n||Le.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[Le.length>0&&t.jsx(vi,{items:Le,value:b,onChange:H=>{j(H),k(!1)}}),M&&$.rows.length>_n&&!z&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>v(!0),title:p("collectionPage.loadAllTitle",{n:$.rows.length,unit:m.unit.items}),children:p(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),$.rows.length>_n&&t.jsx("input",{type:"search",className:"bim-d-find",value:h,placeholder:p("collectionPage.find"),"aria-label":p("collectionPage.find"),onChange:H=>{f(H.target.value),k(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!x&&ki(N.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[V&&t.jsx("th",{style:{width:"8.5em"},children:p("collectionPage.col.volumes")}),t.jsx("th",{children:p("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:p("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:R.map((H,se)=>{var Qe;const ne=H.id?_.get(H.id):void 0,ge=ne!=null&&ne.title&&H.title===H.id?ne.title:H.title,Ne=((ne==null?void 0:ne.authors)||[]).find(ce=>ce&&ce.name),Be=[Ne?`${Ne.dynasty?`〔${u(Ne.dynasty)}〕`:""}${u(Ne.name)}${Ne.role?` ${u(Ne.role)}`:""}`:"",ne!=null&&ne.measure?u(ne.measure):"",(Qe=H.subItems)!=null&&Qe.length?H.subItems.map(ce=>u(ce)).join("、"):"",(ne!=null&&ne.edition||H.edition)&&!A?u((ne==null?void 0:ne.edition)||H.edition||""):""].filter(Boolean),We=En.find(ce=>ce.key===F(H.id)),Ue=H.volumes.length>0?p("collectionPage.volumeRange",{range:ji(H.volumes,m.unit.volume),unit:m.unit.volume}):H.expected!=null?`${H.found??0}/${H.expected} ${m.unit.volume}`:"";return t.jsxs("tr",{children:[V&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ue?"":" bim-d-zt-blank"}`,children:[We&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:i(We.token)}}),Ue||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[H.id?t.jsx(qe,{id:H.id,label:u(ge),onNavigate:r,renderLink:s,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:u(ge)}),Be.length>0?t.jsx(Je,{items:Be}):H.id&&!ne&&o?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${ne!=null&&ne.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:ne!=null&&ne.versionCount?p("collectionPage.nZhong",{n:ne.versionCount}):""})]},`${H.id??H.title}-${se}`)})})]}),R.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:p("catalog.noMatch")}),!x&&t.jsx(Ko,{total:N.length,shown:R.length,unit:m.unit.items,onClick:()=>k(!0)})]}),U>0&&t.jsxs(et,{id:"resources",title:p("collectionPage.sec.resources"),meta:p("collectionPage.resourcesCount",{n:U}),children:[P.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[P.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:p("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:P.text.map((H,se)=>t.jsx(vr,{item:H,siblings:P.text},`${H.id||H.url||H.name}-${se}`))})})]}),t.jsx(Nc,{groups:P.groups})]}),$.rows.length===0&&U===0&&t.jsx(et,{title:p("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:p("collectionPage.empty")})})]}),ve=Z?t.jsx(Dt,{id:"works",title:m.section.containedWorks,meta:p("collectionPage.nZhong",{n:K.length}),cap:12,items:K.map(H=>t.jsx(qe,{id:H.id,label:u(H.title),onNavigate:r,renderLink:s,dense:!0}))}):null,le=y?t.jsx(Tl,{caption:p("collectionPage.parent"),children:t.jsx(qe,{id:y.id,label:u(y.title||y.id),onNavigate:r,renderLink:s,dense:!0})}):void 0;return t.jsx(Ln,{railTop:l,back:d,up:le,nav:ze,railLinks:c,main:Y,card:fe,side:ve})},Xx=16,eo=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function ha(e){if(!e)return eo.length;const n=eo.indexOf(e);return n===-1?eo.length:n}function Zx(e,n){return e==null?"":e<0?n("entityPage.bce",{n:-e}):String(e)}const Jx={秦:[-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]},Mc=({data:e,transport:n,onNavigate:o,renderLink:r,railTop:s,back:a,railLinks:l})=>{var le,Se,X,Ce,Me;const{t:d,convert:c,messages:p}=Q(),u=B=>Zx(B,d),[m,h]=g.useState("全部"),[f,x]=g.useState(!1),[k,y]=g.useState("default"),[w,b]=g.useState(new Map),j=g.useMemo(()=>(e.works||[]).map(B=>{const te=w.get(B.work_id);return{id:B.work_id,title:(te==null?void 0:te.title)??B.title??B.work_id,role:B.role||"",cls:Go(B.role),versionCount:te==null?void 0:te.versionCount,section:te==null?void 0:te.cls,l1:te==null?void 0:te.l1,measure:te==null?void 0:te.measure,hasImage:te==null?void 0:te.hasImage,loaded:!!(te!=null&&te.loaded)}}),[e.works,w]),S=g.useMemo(()=>_l((e.works||[]).map(B=>B.role),d("detail.roleAll")),[e.works,d]),v=g.useMemo(()=>{const B=m==="全部"?j:j.filter(te=>te.cls===m);return k==="versions"?[...B].sort((te,ye)=>(ye.versionCount??-1)-(te.versionCount??-1)):B},[j,m,k]),$=f?v:v.slice(0,Xx),_=g.useMemo(()=>$.filter(B=>!w.has(B.id)).map(B=>B.id),[$,w]);g.useEffect(()=>{if(!n||_.length===0)return;let B=!1;return Promise.all(_.map(te=>n.getItem(te).then(ye=>{var ge,Ne,Be,We,Ue;const H=ye??{},se=H._edition_count??(((ge=H.books)==null?void 0:ge.length)??0)+(((Ne=H.collections)==null?void 0:Ne.length)??0),ne=[(Be=H.classification)==null?void 0:Be.l1,(We=H.classification)==null?void 0:We.l2].filter(Boolean).join(" ");return[te,{id:te,title:H.title,versionCount:se,loaded:!0,cls:ne||void 0,l1:((Ue=H.classification)==null?void 0:Ue.l1)||void 0,measure:ye&&zt(ye,p.unit.juan)||void 0,hasImage:!!(H.has_image??H._has_image)}]}).catch(()=>[te,{id:te,loaded:!0}]))).then(te=>{B||b(ye=>{const H=new Map(ye);for(const[se,ne]of te)H.set(se,ne);return H})}),()=>{B=!0}},[n,_,p.unit.juan]);const C=g.useMemo(()=>{const B=new Map;for(const te of e.alt_names||[]){const ye=te.type||p.section.aliases;B.has(ye)||B.set(ye,[]),B.get(ye).push(te.name)}return[...B.entries()].sort((te,ye)=>ha(te[0])-ha(ye[0])).map(([te,ye])=>({label:te,names:ye}))},[e.alt_names,p]),M=e.birth_year??((le=e.dates)==null?void 0:le.birth)??void 0,T=e.death_year??((Se=e.dates)==null?void 0:Se.death)??void 0,z=(X=e.dates)==null?void 0:X.floruit,F=M!=null||T!=null?`${u(M)||"?"}—${u(T)||"?"}`:Array.isArray(z)&&z.length===2&&z.every(B=>Number.isFinite(B))?d("entityPage.floruit",{from:u(z[0]),to:u(z[1])}):"",N=new Set(["本名","字","號","号"]),R=C.filter(B=>N.has(B.label)),O=C.filter(B=>!N.has(B.label)),I=O.reduce((B,te)=>B+te.names.length,0),P=g.useMemo(()=>{const B=[];for(const ye of R)B.push({label:ye.label,value:ye.names.map(H=>c(H)).join("、")});const te=(e.works||[]).length;return te&&B.push({label:d("entityPage.fact.works"),value:d("entityPage.nZhong",{n:te})}),B},[e.works,R,c,d]),U=B=>{var te;return(te=C.find(ye=>B.includes(ye.label)))==null?void 0:te.names[0]},K=U(["字"]),L=U(["號","号"]),Z=[K?d("entityPage.zi",{name:c(K)}):"",L?d("entityPage.hao",{name:c(L)}):""].filter(Boolean).join(","),A=e.native_place,V=e.dynasty?Jx[e.dynasty]:void 0,pe=(()=>{if(!V||M==null||T==null||T<M)return null;const[B,te]=V,ye=Math.max(M,B),H=Math.min(T,te);if(H<=ye)return null;const se=te-B;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":d("entityPage.lifeAria",{birth:u(M),death:u(T),years:T-M+1}),children:t.jsx("i",{style:{left:`${(ye-B)/se*100}%`,width:`${(H-ye)/se*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${u(B)} ${c(e.dynasty)}`}),t.jsx("span",{children:d("entityPage.lifeYears",{years:T-M+1})}),t.jsx("span",{children:u(te)})]})]})})(),ee=g.useMemo(()=>{if(!n||j.length===0||j.some(ye=>!ye.loaded))return null;const B=new Map;for(const ye of j){const H=_o(ye.l1);H&&B.set(H,(B.get(H)??0)+1)}const te=En.map(ye=>({...ye,n:B.get(ye.key)??0})).filter(ye=>ye.n>0);return te.length?te:null},[j,n]),ue=t.jsxs(An,{kind:p.entityPage.subtype[e.subtype]??d("entityPage.subtype.people"),title:c(e.primary_name||e.title),subtitle:Z||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(Je,{items:[e.dynasty?c(e.dynasty):"",F,A?d("entityPage.nativePlace",{place:c(A)}):""]}),pe]}),description:(Ce=e.description)!=null&&Ce.text?t.jsx(Ct,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Xo((Me=e.description)==null?void 0:Me.text)?6:void 0,facts:P,foot:t.jsx(Pn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[I>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:d("entityPage.moreNames",{n:I})}),t.jsx("dl",{children:O.map(B=>t.jsxs(g.Fragment,{children:[t.jsx("dt",{children:c(B.label)}),t.jsx("dd",{children:B.names.map(te=>c(te)).join("、")})]},B.label))})]}),ee&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:d("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ee.map(B=>t.jsx("i",{style:{flexGrow:B.n,background:i(B.token)}},B.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ee.map(B=>t.jsxs("span",{children:[t.jsx("i",{style:{background:i(B.token)}}),c(B.label)," ",B.n]},B.key))})]})]}),me=g.useMemo(()=>j.filter(B=>B.loaded&&(B.versionCount??0)>0).sort((B,te)=>(te.versionCount??0)-(B.versionCount??0)).slice(0,3),[j]),be=!!n&&j.length>=3&&$.some(B=>!B.loaded),Oe=m==="全部"&&(be||me.length>=2),ie=e.external_ids||{},Re=[];ie.cbdb_id!=null&&Re.push({label:"CBDB",id:String(ie.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${ie.cbdb_id}`,note:ie.cbdb_match==="auto"?d("entityPage.autoMatch"):void 0});const Le=ie.wikidata_id;Le&&Re.push({label:"Wikidata",id:Le,href:`https://www.wikidata.org/wiki/${Le}`});const q=ie.viaf_id;q&&Re.push({label:"VIAF",id:q,href:`https://viaf.org/viaf/${q}`});const J=S.map(B=>({key:B.cls,label:`${B.label} ${B.count}`})),fe=[...Oe&&!be?[{id:"featured",label:d("entityPage.sec.featured"),count:me.length}]:[],...j.length?[{id:"works",label:d("entityPage.sec.allWorks"),count:j.length}]:[],...Re.length?[{id:"external",label:d("entityPage.sec.external"),count:Re.length}]:[]],ze=Oe?t.jsxs(et,{id:"featured",title:d("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:d("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":be||void 0,children:[be&&[0,1,2].map(B=>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:" "})]},B)),!be&&me.map(B=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(qe,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0})}),t.jsx(Je,{items:[B.section?c(B.section):"",B.measure?c(B.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:B.versionCount}),t.jsx("span",{children:d("entityPage.versionsUnit")}),B.hasImage&&t.jsx("span",{className:"bim-d-flag",children:d("entityPage.hasImage")})]})]},B.id))]})]}):null,Y=j.length===0?t.jsx(et,{title:d("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:d("entityPage.empty")})}):t.jsxs(t.Fragment,{children:[ze,t.jsxs(et,{id:"works",title:d("entityPage.sec.works"),meta:t.jsx(Je,{items:[d("entityPage.total",{n:j.length}),v.length!==j.length?d("entityPage.current",{n:v.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[J.length>1&&t.jsx(vi,{items:J,value:m,onChange:B=>{h(B),x(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":k==="versions",onClick:()=>{k==="default"&&x(!0),y(B=>B==="default"?"versions":"default")},children:d(k==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!f&&ki(v.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:d("entityPage.col.work")}),t.jsx("th",{children:d("entityPage.col.section")}),t.jsx("th",{children:d("entityPage.col.role")}),t.jsx("th",{children:d("entityPage.col.versions")}),t.jsx("th",{"aria-label":d("entityPage.col.image")})]})}),t.jsx("tbody",{children:$.map(B=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(qe,{id:B.id,label:c(B.title),onNavigate:o,renderLink:r,dense:!0}),B.measure?t.jsx(Je,{items:[c(B.measure)]}):!B.loaded&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.section||B.loaded?"":" bim-d-zt-blank"}`,children:B.section?c(B.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.role?"":" bim-d-zt-blank"}`,children:B.role?c(B.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${B.loaded?"":" bim-d-zt-blank"}`,children:B.loaded?B.versionCount?d("entityPage.nZhong",{n:B.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:d("entityPage.notRecorded")}):""}),t.jsx("td",{className:B.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:B.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:d("entityPage.hasImage")})})]},B.id))})]}),$.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:d("entityPage.emptyRole")}),!f&&t.jsx(Ko,{total:v.length,shown:$.length,unit:d("entityPage.moreUnit"),onClick:()=>x(!0)})]})]}),ve=Re.length>0?t.jsx(Dt,{id:"external",title:d("entityPage.sec.external"),items:Re.map(B=>t.jsxs("a",{href:B.href,target:"_blank",rel:"noopener noreferrer",children:[B.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Re.map(B=>B.id),foot:ie.cbdb_id!=null&&ie.cbdb_match==="auto"?d("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Ln,{railTop:s,back:a,nav:fe,railLinks:l,main:Y,card:ue,side:ve})},wr="(max-width: 719px)",Qx=`${wr}, (pointer: coarse)`,Bc=`
1302
1304
  .bim-ct {
1303
1305
  display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
1304
1306
  max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
package/dist/index.js CHANGED
@@ -9408,6 +9408,8 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${i("tint-bg"
9408
9408
  .bim-d-dist-seg[aria-pressed="true"] { outline: 2px solid ${i("ink")}; outline-offset: -2px; }
9409
9409
  .bim-d-dist-bar:has(.bim-d-dist-seg[aria-pressed="true"]) .bim-d-dist-seg:not([aria-pressed="true"]) { opacity: .35; }
9410
9410
  .bim-d-sq { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 1px; vertical-align: middle; }
9411
+ /* 侧栏卡里的作品简介:不能内联写 margin 简写——会把 boxed 布局给子元素的左右 16px 抹成 0(简介贴边) */
9412
+ .bim-d-side-desc { margin: 8px 0 0; }
9411
9413
  .bim-d-side-note { margin: 8px 0 0; font-size: 12px; color: ${i("aux-fg")}; }
9412
9414
 
9413
9415
  /* 提要卡:数字格(版本 / 有影印 / 家著录) */
@@ -18771,14 +18773,13 @@ const vf = ({
18771
18773
  }
18772
18774
  ),
18773
18775
  ((lt = b.description) == null ? void 0 : lt.text) && /* @__PURE__ */ t("p", { style: {
18774
- margin: "8px 0 0",
18775
18776
  fontSize: 14,
18776
18777
  lineHeight: 1.8,
18777
18778
  display: "-webkit-box",
18778
18779
  WebkitLineClamp: 3,
18779
18780
  WebkitBoxOrient: "vertical",
18780
18781
  overflow: "hidden"
18781
- }, className: "bim-d-card-desc", children: f(b.description.text.replace(/[#*_>`[\]]/g, "")) })
18782
+ }, className: "bim-d-card-desc bim-d-side-desc", children: f(b.description.text.replace(/[#*_>`[\]]/g, "")) })
18782
18783
  ] }),
18783
18784
  R > 0 && j.length > 0 && /* @__PURE__ */ d("div", { children: [
18784
18785
  /* @__PURE__ */ t(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "book-index-ui",
3
- "version": "0.46.1",
3
+ "version": "0.46.2",
4
4
  "description": "React components for browsing and editing ancient book index metadata",
5
5
  "author": "Li Shaodong",
6
6
  "repository": {