book-index-ui 0.66.12 → 0.66.13
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 +56 -56
- package/dist/index.js +1798 -1784
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Zm=Object.create;var Wo=Object.defineProperty;var Qm=Object.getOwnPropertyDescriptor;var eu=Object.getOwnPropertyNames;var tu=Object.getPrototypeOf,iu=Object.prototype.hasOwnProperty;var nu=(e,i,n,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of eu(i))!iu.call(e,o)&&o!==n&&Wo(e,o,{get:()=>i[o],enumerable:!(r=Qm(i,o))||r.enumerable});return e};var gn=(e,i,n)=>(n=e!=null?Zm(tu(e)):{},nu(i||!e||!e.__esModule?Wo(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./storage-entry-tWa4CaT4.cjs"),t=require("react/jsx-runtime"),b=require("react"),s=require("./Badge-gj9fd1yH.cjs"),ru=require("opencc-js/t2cn"),vi=require("./variant-chars-kDZNY5eM.cjs"),su=require("react-markdown"),ou=require("remark-gfm"),au=require("./variant-supplement.cjs"),lu=e=>`/item/${e}`,vl=b.createContext(lu);function cu({buildUrl:e,children:i}){const n=b.useMemo(()=>e,[e]);return t.jsx(vl.Provider,{value:n,children:i})}function It(){return b.useContext(vl)}const Sl="",$l="";function gs(e){const i=[];let n=!1,r=e;for(;r.length;){const o=n?$l:Sl,a=r.indexOf(o);if(a===-1){i.push({text:r,marked:n});break}a>0&&i.push({text:r.slice(0,a),marked:n}),r=r.slice(a+1),n=!n}return i}let Mi=null;function _l(){if(Mi)return Mi;try{const e=ru.Converter({from:"t",to:"cn"});Mi=s.withProtectedTerms(i=>e(vi.normalizeVariants(i)))}catch{Mi=e=>e}return Mi}const Nl="bim-locale";function du(){try{const e=localStorage.getItem(Nl);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function mu(e){try{localStorage.setItem(Nl,e)}catch{}}const uu="zh-Hans",pu=({locale:e,onLocaleChange:i,converter:n,children:r})=>{const[o,a]=b.useState(e??uu),l=e??o;b.useEffect(()=>{if(e)return;const p=du();p&&p!==o&&a(p)},[]);const d=b.useMemo(()=>l==="zh-Hans"?n??_l():null,[l,n]),c=b.useCallback(p=>{a(p),mu(p),i==null||i(p)},[i]),m=b.useMemo(()=>({locale:l,setLocale:c,messages:s.getMessages(l),converter:d}),[l,c,d]);return t.jsx(s.LocaleContext.Provider,{value:m,children:r})},bu=2e3;function xt(){const e=b.useContext(s.LocaleContext),i=(e==null?void 0:e.locale)??"zh-Hant",n=(e==null?void 0:e.converter)??null,r=b.useRef(new Map),o=b.useRef(i),a=b.useRef(n);(o.current!==i||a.current!==n)&&(r.current.clear(),o.current=i,a.current=n);const l=b.useCallback(d=>{if(!d)return"";if(!n)return d;const c=r.current.get(d);if(c!==void 0)return c;const m=n(d);if(r.current.size>=bu){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(d,m),m},[n]);return b.useMemo(()=>({convert:l,locale:i,isSimplified:i==="zh-Hans"}),[l,i])}function oe(){const e=b.useContext(s.LocaleContext),{convert:i,locale:n,isSimplified:r}=xt(),o=(e==null?void 0:e.messages)??s.getMessages("zh-Hant"),a=b.useMemo(()=>e?s.makeT(o):s.getT("zh-Hant"),[e,o]);return b.useMemo(()=>({t:a,convert:i,locale:n,isSimplified:r,messages:o}),[a,i,n,r,o])}function hu(e,i,n){return e?e==="orig"?null:i==="zh-Hans"?n??_l():e==="hant"?vi.normalizeVariants:n:i==="zh-Hans"?n:vi.normalizeVariants}const fu=({mode:e,children:i})=>{const n=b.useContext(s.LocaleContext),r=b.useMemo(()=>n&&{...n,converter:hu(e,n.locale,n.converter)},[n,e]);return t.jsx(s.LocaleContext.Provider,{value:r,children:i})},Uo={text:s.bim("restype-text"),image:s.bim("restype-image"),"text+image":s.bim("restype-text-image"),physical:s.bim("restype-physical")};function gu(e){return e.includes("text")&&e.includes("image")?Uo["text+image"]:Uo[e[0]||"physical"]}const xu=({items:e,groupByType:i=!0,resourceGroups:n,onNavigate:r,renderLink:o})=>{const a=s.useT(),{convert:l}=xt(),d=b.useMemo(()=>s.mergeVolumeResources(e||[]),[e]),{mirrorGroups:c,ungroupedItems:m,labelOnlyKeys:p}=b.useMemo(()=>{const w=new Map,x=[],j=new Map;d.forEach((S,$)=>{const N=S.group||(S.label?`_label:${$}`:void 0);!S.group&&S.label&&N&&j.set(N,S.label),N?(w.has(N)||w.set(N,[]),w.get(N).push(S)):x.push(S)});for(const S of w.values())S.sort(($,N)=>{const z=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return z($)-z(N)});return{mirrorGroups:w,ungroupedItems:x,labelOnlyKeys:j}},[d]),h={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=w=>h[w]?h[w]:w.split("+").map(x=>h[x]||x).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:s.bim("desc-fg"),fontSize:"13px",textAlign:"center"},children:a.misc.noResources});if(!i)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:d.map((w,x)=>t.jsx(Sr,{item:w},w.id||x))});const f=(w,x)=>{const j=n==null?void 0:n[w],S=p.get(w)||(j==null?void 0:j.label)||w,$=j==null?void 0:j.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:s.bim("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:s.bim("fg")},children:l(S)}),$&&t.jsx("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.5},children:l($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((N,z)=>t.jsx(Sr,{item:N,onNavigate:r,renderLink:o},N.id||z))})]},`group-${w}`)},g=new Map;for(const w of m){const x=s.getTypeGroupKey(s.getResourceTypes(w));g.has(x)||g.set(x,[]),g.get(x).push(w)}const y=["text","image","text+image","physical"],v=[...y.filter(w=>g.has(w)),...[...g.keys()].filter(w=>!y.includes(w)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([w,x])=>f(w,x)),v.map(w=>{const x=g.get(w),j=gu(w.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:u(w)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((S,$)=>t.jsx(Sr,{item:S,onNavigate:r,renderLink:o},S.id||$))})]},w)})]})},yu={bw:{label:"",bg:s.bim("colormode-bw-bg"),fg:s.bim("colormode-bw-fg")},color:{label:"",bg:s.bim("colormode-color-bg"),fg:s.bim("colormode-color-fg")}},Sr=({item:e})=>{const i=s.useT(),{convert:n}=xt(),[r,o]=b.useState(!1),a=b.useMemo(()=>(e.url?s.getDisplayNameFromUrl(e.url):void 0)||n(e.name),[e.url,e.name,n]),l=b.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(g=>({...g,url:g.url||s.extractVolumeUrl(g)})),[e.volumes]),d=l&&l.length>0,c=d?new Set(l.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,m=d?new Set(l.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,p=e.expected_volumes??(d?c+m:0),h=e.color_mode?{...yu[e.color_mode],label:i.colorMode[e.color_mode]}:null,u=e.details&&!d?n(e.details):null,f={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"5px",background:s.bim("input-bg"),fontSize:"12px",color:s.bim("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:f,children:[t.jsx("span",{style:{fontWeight:500},children:a}),h&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:h.bg,color:h.fg},children:h.label}),u&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:u}),d&&t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[c,"/",p,i.unit.volume,m>0&&t.jsx("span",{style:{color:s.bim("missing-fg"),marginLeft:"3px"},children:s.formatTemplate(i.common.volumesMissing,{n:m})})]}),e.url&&t.jsx("a",{href:(()=>{const g=s.getStartPage(e.metadata);return g?s.buildPageUrl(e.url,g):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:s.bim("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:i.action.visit}),d&&t.jsx("button",{onClick:()=>o(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),d&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(g=>{const y=g.status==="missing";return g.url&&!y?t.jsx("a",{href:g.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${s.bim("widget-border")}`,color:s.bim("link-fg"),textDecoration:"none"},children:g.volume},g.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?s.bim("missing-fg"):s.bim("desc-fg"),textDecoration:y?"line-through":"none",opacity:y?.6:1},children:g.volume},g.volume)})})]})},zl=({indexSource:e,syncConfig:i,variant:n="index-browser",onSwitchMode:r,onToggleDraft:o,onConfigurePath:a,onSelectFolder:l})=>{const d=s.useT(),c=e==="local",m=(i==null?void 0:i.isDraft)??!0,p=(i==null?void 0:i.repoPath)||"",h=p?p.split(/[/\\]/).pop()||p:"",u={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:s.bim("primary-soft"),color:s.bim("primary")},f={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},g=t.jsxs("div",{onClick:o,title:m?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...u,background:m?s.bim("warning"):s.bim("success"),color:s.bim("on-color-fg")},...f,children:[t.jsx("span",{children:m?"📝":"📚"}),t.jsx("span",{children:m?"draft":"official"})]});return n==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[g,t.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:u,...f,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:l,title:p||d.mode.selectFolder,style:{...u,paddingLeft:"8px",paddingRight:"8px"},...f,children:[t.jsx("span",{children:"📂"}),h&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:h})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:d.mode.switchToLocal,style:u,...f,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:a,title:h||d.mode.configurePath,style:{...u,background:"transparent",padding:"6px",fontSize:"12px"},...f,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:u,...f,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:l,title:p||d.mode.selectFolder,style:{...u,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...f,children:[t.jsx("span",{children:"📂"}),h&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:h})]}),!c&&h&&t.jsxs("div",{style:{...u,background:s.bim("mode-active-bg"),color:s.bim("on-color-fg"),cursor:"default"},title:p,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:h})]})]})},Hn="bim-search-history",Ko=10,Yo=8;function Di(){try{const e=localStorage.getItem(Hn);return e?JSON.parse(e):[]}catch{return[]}}function Cl(e){try{const i=Di().filter(n=>n!==e);i.unshift(e),i.length>Ko&&(i.length=Ko),localStorage.setItem(Hn,JSON.stringify(i))}catch{}}function ju(e){try{const i=Di().filter(n=>n!==e);localStorage.setItem(Hn,JSON.stringify(i))}catch{}}function ku(){try{localStorage.removeItem(Hn)}catch{}}const El=({transport:e,value:i,onChange:n,onSearch:r,onEntrySelect:o,placeholder:a})=>{const l=s.useT(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[m,p]=b.useState(!1),[h,u]=b.useState([]),[f,g]=b.useState(-1),[y,v]=b.useState(Di),w=b.useRef(null),x=b.useRef(null),j=b.useRef(null),S=b.useRef(!1);b.useEffect(()=>{g(-1);const L=i.trim();if(!L){u(y.map(Z=>({type:"history",text:Z})));return}if(!e.searchAll){u([]);return}let F=!1;const T=setTimeout(()=>{e.searchAll(L,Yo).then(Z=>{if(F)return;const O=[...Z.works,...Z.books,...Z.collections,...Z.entities??[]];u(O.slice(0,Yo).map(ae=>({type:"entry",text:ae.title||ae.id,entry:ae})))}).catch(()=>{F||u([])})},80);return()=>{F=!0,clearTimeout(T)}},[i,y,e]),b.useEffect(()=>{const L=F=>{j.current&&!j.current.contains(F.target)&&p(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[]),b.useEffect(()=>{const L=F=>{var T,Z;if(F.key==="/"&&document.activeElement!==w.current){const O=(T=document.activeElement)==null?void 0:T.tagName;if(O==="INPUT"||O==="TEXTAREA"||O==="SELECT")return;F.preventDefault(),(Z=w.current)==null||Z.focus()}};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[]);const $=b.useCallback(L=>{L.trim()&&(Cl(L.trim()),v(Di())),r(L),p(!1)},[r]),N=b.useCallback(L=>{L.type==="history"?(n(L.text),$(L.text)):L.entry&&(o?(o(L.entry),p(!1)):(n(L.text),$(L.text)))},[n,$,o]),z=b.useCallback(L=>{if(!m||h.length===0){L.key==="Enter"&&$(i);return}switch(L.key){case"ArrowDown":L.preventDefault(),g(F=>(F+1)%h.length);break;case"ArrowUp":L.preventDefault(),g(F=>(F-1+h.length)%h.length);break;case"Enter":L.preventDefault(),f>=0&&f<h.length?N(h[f]):$(i);break;case"Escape":L.preventDefault(),p(!1);break}},[m,h,f,i,$,N]),C=b.useCallback((L,F)=>{F.stopPropagation(),ju(L),v(Di()),u(T=>T.filter(Z=>!(Z.type==="history"&&Z.text===L)))},[]),U=b.useCallback(L=>{L.stopPropagation(),ku(),v([]),u([])},[]);b.useEffect(()=>{if(f>=0&&x.current){const L=x.current.children;L[f]&&L[f].scrollIntoView({block:"nearest"})}},[f]);const R=!i.trim()&&y.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:w,type:"text",placeholder:d,value:i,onChange:L=>{n(L.target.value),p(!0)},onCompositionStart:()=>{S.current=!0},onCompositionEnd:()=>{S.current=!1},onFocus:()=>{p(!0)},onKeyDown:z,style:{width:"100%",padding:"8px 12px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),m&&h.length>0&&t.jsxs("div",{ref:x,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:s.bim("input-bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",boxShadow:s.bim("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:s.bim("desc-fg"),borderBottom:`1px solid ${s.bim("widget-border")}`},children:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:U,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),h.map((L,F)=>t.jsxs("div",{onClick:()=>N(L),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:s.bim("fg"),background:F===f?s.bim("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:L.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:L.text}),L.entry&&t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),flexShrink:0},children:[c[L.entry.type],L.entry.edition&&` · ${L.entry.edition}`,L.entry.author&&` · ${L.entry.author}`]}),L.type==="history"&&t.jsx("button",{onClick:T=>C(L.text,T),style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${L.type}-${L.text}-${F}`))]})]})},Xi=({type:e,size:i=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:i,height:i,borderRadius:1,flex:"none",background:s.bim(`type-${e}`),verticalAlign:"middle"}});function Vt(e){const i=[],n=new Set;for(const r of e.base_edition??[]){if(!r||!r.relation)continue;const o=!!r.hypothetical_id,a=o?r.hypothetical_id:r.book_id;if(!a)continue;const l=`${a}|${o?"hypothetical":"book"}`;n.has(l)||(n.add(l),i.push({ref:a,ref_type:o?"hypothetical":"book",relation:r.relation,confidence:r.confidence??void 0,evidence:r.evidence,note:r.note}))}return i}function ti(e){const i=[];for(const n of e.related_books??[])n&&typeof n=="object"&&n.book_id&&n.relation&&i.push({book_id:n.book_id,relation:n.relation,confidence:n.confidence??void 0,evidence:n.evidence});return i}function wu(e){return(e.related_books??[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_id).filter(i=>typeof i=="string"&&i.length>0)}function Tn(e){return!!e.lineage||Vt(e).length>0||ti(e).length>0}function vu(e){var i;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((i=e.year_range)==null?void 0:i[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function Su(e,i){var r,o,a,l,d;if(!Tn(e))return null;const n=e.lineage??{};return{id:e.id,kind:"book",label:e.title,year:((r=e.dating)==null?void 0:r.year)??((a=(o=e.dating)==null?void 0:o.year_range)==null?void 0:a[0]),year_text:(l=e.dating)==null?void 0:l.text,year_uncertain:(d=e.dating)==null?void 0:d.year_uncertain,category:e.edition_type,status:n.status,extant_juan:n.extant_juan,group:i[e.id],note:n.note}}function Go(e,i,n){return{id:`derive:${i.ref}->${e}:${n}`,source:i.ref,target:e,kind:"derive",relation:i.relation,confidence:i.confidence,evidence:i.evidence,note:i.note}}function $u(e,i,n){const[r,o]=[e,i.book_id].sort();return{id:`sibling:${r}-${o}:${n}`,source:r,target:o,kind:"sibling",relation:i.relation,confidence:i.confidence,evidence:i.evidence,note:i.note}}function _u(e,i){var m;if(i==="all")return null;const n=(m=e.collections)==null?void 0:m[i],r=Array.isArray(n==null?void 0:n.groups)&&n.groups.length>0,o=Array.isArray(n==null?void 0:n.book_ids)&&n.book_ids.length>0,a=r||o||!!(n!=null&&n.hypothetical_ids);if(!a&&i==="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(!n||!a)return null;const l=r?new Set(n.groups):null,d=new Set(n.book_ids??[]);if(l&&e.node_groups)for(const[p,h]of Object.entries(e.node_groups))l.has(h)&&d.add(p);let c=null;if(n.hypothetical_ids&&(c=new Set(n.hypothetical_ids)),l){c||(c=new Set);for(const p of e.hypothetical_nodes??[])p.group&&l.has(p.group)&&c.add(p.id)}return{books:d,hypos:c}}function Sn(e,i,n){const r=e.version_graph,o={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return o;const a=new Set(r.excluded_books??[]),l=r.node_groups??{},d=_u(r,n??r.default_collection??"all"),c=d!==null,m=(d==null?void 0:d.books)??null,p=(d==null?void 0:d.hypos)??null,h=new Set,u=new Set;if(c){const S=new Map(i.map(R=>[R.id,R])),$=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),N=R=>{const L=S.get(R);if(L&&Tn(L))return Vt(L).map(T=>T.ref);const F=$.get(R);return F?(F.derived_from??[]).map(T=>T.ref):[]},z=R=>$.has(R)?!p||p.has(R):!m||m.has(R),C=new Set,U=R=>{if(!C.has(R)){C.add(R);for(const L of N(R))a.has(L)||(z(L)||($.has(L)?u.add(L):S.has(L)&&h.add(L)),U(L))}};for(const R of i)m&&m.has(R.id)&&!a.has(R.id)&&U(R.id);for(const R of r.hypothetical_nodes??[])p&&p.has(R.id)&&U(R.id)}const f=i.filter(S=>!a.has(S.id)).filter(S=>!m||m.has(S.id)||h.has(S.id)).map(S=>{const $=Su(S,l);return $&&h.has(S.id)&&($.bridge=!0),$}).filter(S=>S!==null),g=(r.hypothetical_nodes??[]).filter(S=>!p||p.has(S.id)||u.has(S.id)).map(S=>{const $=vu(S);return u.has(S.id)&&($.bridge=!0),$}),y=[...f,...g],v=new Set(y.map(S=>S.id)),w=new Set,x=[],j=S=>{w.has(S.id)||!v.has(S.source)||!v.has(S.target)||(w.add(S.id),x.push(S))};for(const S of i)a.has(S.id)||!Tn(S)||m&&!m.has(S.id)&&!h.has(S.id)||(Vt(S).forEach(($,N)=>{j(Go(S.id,$,N))}),ti(S).forEach(($,N)=>{j($u(S.id,$,N))}));for(const S of r.hypothetical_nodes??[])p&&!p.has(S.id)&&!u.has(S.id)||(S.derived_from??[]).forEach(($,N)=>{j(Go(S.id,$,N))});return{nodes:y,edges:x,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(a)}}function Rl(e,i,n){const r=(e??(i!=null?String(i):"")).trim();return r?!n||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Nu(e,i){const n=[],r=e.version_graph;if(!r)return n;const o=new Set(i.map(c=>c.id)),a=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...o,...a]),d=(c,m)=>{l.has(m.ref)||n.push(`${c}: derived_from.ref "${m.ref}" 未在 books 或 hypothetical_nodes 中找到`),m.ref_type==="book"&&!o.has(m.ref)&&n.push(`${c}: derived_from.ref "${m.ref}" 标记为 book 但不在 books 列表中`),m.ref_type==="hypothetical"&&!a.has(m.ref)&&n.push(`${c}: derived_from.ref "${m.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of i){if(!Tn(c))continue;const m=`Book ${c.id} (${c.title})`;Vt(c).forEach(p=>d(m,p)),ti(c).forEach(p=>{o.has(p.book_id)||n.push(`${m}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const m=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(p=>d(m,p))}return n}const Tl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],zu={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Tt(e){return zu[e]??e}const Si=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],$i={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},Il={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Dn(e){const i=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!i)return;const n=parseInt(i[1],10);if(n<100||n>2100)return;const r=i[2]?parseInt(i[2],10):void 0;return{from:n,to:r!=null&&r>=n&&r<=2100?r:void 0}}function Cu(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Eu=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function xs(e){const i=e.trim().replace(/[代朝]$/,"");for(const o of Object.keys(Vo))if(i.startsWith(o))return Vo[o];const n=Tt(i);if(yi[n]!=null)return n;const r=Qt(i);if(r&&i.length<=r.length+1)return Tt(r)}function ci(e,i){if(i){const n=Il[`${i}|${e}`];if(n!=null)return n}return $i[e]}const Ru=1911;function Tu(e){const i=$i[e];if(i==null)return;const n=Ht[e];let r;for(const[o,a]of Object.entries($i))Ht[o]===n&&a>i&&(r==null||a<r)&&(r=a);return r!=null?r-1:void 0}const Iu={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function In(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let i=0,n=0,r=!1;for(const a of e){const l=Iu[a];if(l===void 0)return;r=!0,a==="十"?n=(n||1)*10:a==="廿"||a==="卅"?(i+=l,n=0):n>=10?(i+=n+l,n=0):n=n*10+l}const o=i+n;return r&&o>0?o:void 0}function Qt(e){for(const i of Tl)if(e.startsWith(i))return i}const Ht={};{const e=(i,n)=>{for(const r of n)Ht[r]=i};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function ki(e,i){const n=i==="北宋"||i==="南宋"?"宋":i;for(const r of Object.keys($i))if(e.includes(r)&&!(n&&Ht[r]&&Ht[r]!==n&&Il[`${n}|${r}`]==null))return r}function Wn(e){var r;const i=e.dating;if(!i||i.era||i.reign||(r=e.publication_info)!=null&&r.year)return e;const n=i.text??(i.year!=null?String(i.year):i.year_range&&i.year_range.length===2?`${i.year_range[0]}-${i.year_range[1]}`:void 0);return n?{...e,publication_info:{...e.publication_info,year:n}}:e}function Ji(e){var a,l;e=Wn(e);const i={era:"",reign:"",source:"none"},n=e.dating;if(n!=null&&n.era||n!=null&&n.reign)return{era:n.era??"",reign:n.reign??"",source:n.certainty==="attested"?"catalog":"edition"};const r=(a=e.publication_info)==null?void 0:a.year;if(r){const d=Dn(r);if(d)return{era:Cu(d.from),reign:"",source:"publication"};const c=Qt(r)??xs(r)??((l=Si.find(h=>h.pattern.test(r)))==null?void 0:l.era)??"",m=ki(r,c)??"",p=c||(m?Ht[m]??"":"");if(p||m)return{era:Tt(p),reign:m,source:"publication"}}const o=e.edition||e.title||"";if(o){const d=Qt(o);if(d)return{era:Tt(d),reign:ki(o,d)??"",source:"edition"};const c=Si.find(m=>m.pattern.test(o));if(c)return{era:Tt(c.era),reign:ki(o,c.era)??c.reign??"",source:"edition"}}return i}function Un(e){var r,o,a,l,d,c;if(e=Wn(e),((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;const i=(o=e.publication_info)==null?void 0:o.year;if(i){const m=Dn(i);if(m)return m.from}const n=[(a=e.publication_info)==null?void 0:a.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const m of n){const p=(l=e.publication_info)==null?void 0:l.year;if(p&&m!==p&&(Qt(p)||xs(p)))break;const h=m.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??m.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(h){const v=parseInt(h[1],10);if(v>=100&&v<=2100)return v}const u=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(u){const v=Qt(m);if(!v||Tt(v)==="民國"){const x=In(u[1]);if(x!=null&&x>=1&&x<=120)return Ru+x}}const f=Qt(m)??((d=Si.find(v=>v.pattern.test(m)))==null?void 0:d.era),g=f?Tt(f):void 0,y=ki(m,g)??(Qt(m)||(c=Si.find(v=>v.pattern.test(m)))==null?void 0:c.reign);if(y){const v=ci(y,g);if(v==null)continue;const w=m.indexOf(y),x=w>=0?m.slice(w+y.length):"",j=x.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??x.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=j?In(j[1]):void 0;return v+(S?S-1:0)}}}function ys(e){var o,a,l,d;e=Wn(e);const i=(o=e.dating)==null?void 0:o.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const n=(a=e.publication_info)==null?void 0:a.year;if(n){const c=Dn(n);if((c==null?void 0:c.to)!=null)return{from:c.from,to:c.to};const m=n.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const p=Ml[Tt(m[1])],h=yi[Tt(m[2])];if(p!=null&&h!=null)return{from:Math.min(p,h)-20,to:Math.max(p,h)+40}}}const r=[(l=e.publication_info)==null?void 0:l.year,e.edition,e.title].filter(Boolean);for(const c of r){if(!/[間间]/.test(c))continue;const m=Qt(c)??xs(c)??((d=Si.find(u=>u.pattern.test(c)))==null?void 0:d.era),p=m?Tt(m):void 0,h=[];for(const u of Object.keys($i))c.includes(u)&&(p&&Ht[u]&&Ht[u]!==p||ci(u,p)!=null&&h.push(u));if(h.length===0){const u=c.match(/([一-鿿])([一-鿿])[間间]/);if(u&&p){for(const f of[u[1],u[2]])for(const g of Object.keys($i))if(Ht[g]===p&&!(g[0]!==f&&g[g.length-1]!==f)&&ci(g,p)!=null){h.push(g);break}}}if(h.length>0){const u=h.map(v=>ci(v,p)).filter(v=>v!=null),f=Math.min(...u),g=h.reduce((v,w)=>ci(v,p)>=ci(w,p)?v:w),y=Tu(g)??$r(p??"")??Math.max(...u);return{from:f,to:y>f?y:$r(p??Ht[g]??"")??f}}if(p&&yi[p]!=null)return{from:yi[p],to:$r(p)??yi[p]}}}const yi={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Mu=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Au=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,qo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Xo(e,i){for(const n of Tl){const r=e.indexOf(n);if(r<0)continue;if(n.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!ki(e.slice(r),Tt(n)))continue}const o=Tt(n);if(o===i)continue;const a=e.slice(r),l=ki(a,o)??"";let d;if(l){const c=ci(l,o);if(c!=null){const p=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),h=p?In(p[1]):void 0;d=c+(h?h-1:0)}}return{era:o,reign:l,year:d}}for(const n of Si)if(n.pattern.test(e))return{era:Tt(n.era),reign:n.reign??""}}function Lu(e){var y,v;e=Wn(e);const i=Ji(e),n=((y=e.publication_info)==null?void 0:y.year)??"",r=n?Dn(n):void 0;if(!i.era&&!i.reign&&!r)return;const o=e.edition||e.title||"",a=/[間间]/.test(o),l=i.source==="publication"&&Eu.test(n),d=i.source==="publication"&&/[間间]/.test(n),c=n.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;a||l||d?m=void 0:c?m=parseInt(c[2],10):m=Un(e);const p=m==null?ys(e):void 0;let h;i.source==="publication"&&(l||qo.test(n))?h="uncertain":i.source==="publication"?h="attested":qo.test(o)||!i.reign&&m==null?h="uncertain":h="inferred";const u=i.source==="edition"?`題名「${o}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,f={era:i.era,reign:i.reign,year:m,yearRange:p,certainty:h,source:i.source==="edition"?"edition":"catalog",basis:u};if(c){const w=n.match(/[、,,]\s*([宋元明清])/);w&&w[1]!==f.era&&(f.laterRepair={era:w[1]})}if(!f.laterRepair&&Au.test(o)){const w=o.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);w&&w[1]!==i.era&&(f.laterRepair={era:w[1]})}const g=Mu.find(w=>w.re.test(o));if(g){const w=o.search(g.re),x=o.slice(w),j=Xo(x,i.era)??Xo(o,i.era);j&&(f.basedOn={era:j.era,reign:j.reign,year:j.year,relation:g.relation})}return f}const Ml={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function $r(e){return Ml[e]}function Mn(e){const i=Un(e);if(i!=null)return i;const n=ys(e);if(n)return n.from;const r=Ji(e).era;return r?yi[r]:void 0}const Jo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Yr(e){const i=Jo.indexOf(e);return i===-1?Jo.length:i}function Pu(e){const i={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const o of e){const a=o.relation;a==="part_of"?i.belongsTo.push(o):a==="collected_in"?i.collected.push(o):a==="has_part"||a==="contains_text_of"?i.contains.push(o):a==="text_carried_by"||a==="studied_by"||a==="derived_from"||a==="followed_by"||a==="has_adaptation"?i.derivative.push(o):a==="studies"||a==="preceded_by"?i.studies.push(o):i.related.push(o)}const n=[],r=(o,a)=>{i[o].length&&n.push({key:o,labelKey:a,items:i[o]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),n}function js(e,i){const n=s.mergeVolumeResources(e||[]),r=new Map,o=[],a=new Map;n.forEach((p,h)=>{if(p.group)r.has(p.group)||r.set(p.group,[]),r.get(p.group).push(p);else if(p.label){const u=`_label:${h}`;r.set(u,[p]),a.set(u,p.label)}else o.push(p)});for(const p of r.values())p.sort((h,u)=>{const f=g=>g.group_role==="origin"?0:g.group_role==="mirror"?1:2;return f(h)-f(u)});const l={text:[],image:[],textImage:[],physical:[]};for(const p of o){const h=s.getResourceTypes(p),u=h.includes("text"),f=h.includes("image");u&&f?l.textImage.push(p):u?l.text.push(p):f?l.image.push(p):l.physical.push(p)}const c=["text","image","textImage","physical"].filter(p=>l[p].length>0).map(p=>({key:p,items:l[p]})),m=[...r.entries()].map(([p,h])=>{var u,f;return{key:p,label:a.get(p)||((u=i==null?void 0:i[p])==null?void 0:u.label)||p,description:a.has(p)||(f=i==null?void 0:i[p])==null?void 0:f.description,items:h}});return{buckets:c,mirrors:m,total:n.length}}function Kn(e,i=s.getT("zh-Hant")){const n=[],r=e.metadata||{};r.edition&&n.push(String(r.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const o=s.volumeStats(e);return o&&o.expected>0&&n.push(o.missing>0?i("detail.volumeStatsMissing",{found:o.found,expected:o.expected,missing:o.missing}):i("detail.volumeStats",{found:o.found,expected:o.expected})),r.version&&n.push(String(r.version)),n.join(" · ")}function Al(e,i){if(Kn(e)||i.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),o=r.searchParams.get("res")||r.searchParams.get("id");if(o)return o;const a=r.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}const Ou="同版";function Fu(e){const i=e==null?void 0:e.metadata;return((i==null?void 0:i.item_id)||(i==null?void 0:i.call_number)||"").trim()||void 0}function Bu(e){for(const i of ti(e)){const n=i.ref??i.book_id;if(i.relation===Ou&&n&&n!==e.id)return n}}function Hu(e){const i=new Map(e.map(a=>[a.id,a])),n=a=>{const l=i.get(a);return!!l&&!l.copyOf},r=new Map;for(const a of e)if(a.copyOf&&n(a.copyOf)){const l=r.get(a.copyOf)??[];l.push(a),r.set(a.copyOf,l)}if(r.size===0)return e;const o=[];for(const a of e){if(a.copyOf&&n(a.copyOf))continue;const l=r.get(a.id);if(!l){o.push(a);continue}const d=[...l].sort((c,m)=>(c.callNumber??c.id).localeCompare(m.callNumber??m.id));o.push({...a,copies:d,hasImage:a.hasImage||d.some(c=>c.hasImage)})}return o}const Du=["同卷","綴合"];function Ll(e){const i=new Map;for(const n of ti(e)){if(!Du.includes(n.relation))continue;const r=n.ref??n.book_id;if(!r)continue;const o=i.get(n.relation)??[];o.includes(r)||o.push(r),i.set(n.relation,o)}return i.size?[...i].map(([n,r])=>({relation:n,ids:r})):void 0}const Zo=200;function Pl(e,i){const[n="",r=""]=(e.dating??"").split(/\s+/),o={id:e.id,title:e.title,edition:e.edition,...n?{dating:{era:n,reign:r}}:{}},a=ks(o,i);return{...a,sortYear:e.y??a.sortYear,year:e.y??a.year,locationName:e.holder||void 0,hasImage:!!e.img}}function Wu(e,i,n={}){var a;const r=new Map;for(const l of e){const d=l.coll?l.coll:!n.noHolderFallback&&l.holder?`h:${l.holder}`:"_none",c=l.coll&&((a=n.titles)==null?void 0:a[l.coll])||l.collt||(d==="_none"?"":l.holder)||l.coll||"";let m=r.get(d);m||(m={key:d,title:c,rows:[],total:0,imageCount:0},r.set(d,m)),m.total++;const p=Pl(l,i);m.rows.push(p),p.hasImage&&m.imageCount++}const o=[...r.values()];return[...o.filter(l=>l.key!=="_none"),...o.filter(l=>l.key==="_none")]}function ks(e,i){var a,l,d,c;const n=e.resources||[],r=[],o=[];for(const m of n){const p=s.getResourceTypes(m);p.includes("image")&&r.push(m),p.includes("physical")&&o.push(m)}return{id:e.id,name:e.edition||e.title||e.id,era:Ji(e),year:Un(e),sortYear:Mn(e),images:r,holders:o,locationName:((a=e.current_location)==null?void 0:a.name)||((d=(l=e.provenance)==null?void 0:l[0])==null?void 0:d.institution)||void 0,callNumber:Fu(o[0]),copyOf:Bu(e),relations:Ll(e),summary:e.summary,important:Uu(e.id,i),group:(c=i==null?void 0:i.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function Uu(e,i){var d,c;if(!i)return!1;const n=i.default_collection;if(!n)return!1;const r=(d=i.collections)==null?void 0:d[n];if(((r==null?void 0:r.book_ids)??(n==="core"?i.core_books??[]:[])).includes(e))return!0;const a=(r==null?void 0:r.groups)??[],l=(c=i.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function Ol(e,i,n={}){const r=new Set((i==null?void 0:i.excluded_books)??[]),o=Hu(e.filter(c=>!r.has(c.id)).map(c=>ks(c,i)));let a=o;n.era&&(a=a.filter(c=>c.era.era===n.era)),n.scanOnly&&(a=a.filter(c=>c.hasImage)),n.sort==="year"?a=a.map((c,m)=>({r:c,i:m})).sort((c,m)=>{const p=c.r.sortYear,h=m.r.sortYear;return p!=null&&h!=null?p-h||c.i-m.i:p!=null?-1:h!=null?1:c.i-m.i}).map(c=>c.r):a=a.map((c,m)=>({r:c,i:m})).sort((c,m)=>{const p=h=>(h.important?0:1)*2+(h.hasImage?0:1);return p(c.r)-p(m.r)||c.i-m.i}).map(c=>c.r);const d=[...new Set(o.map(c=>c.era.era).filter(Boolean))].sort((c,m)=>Yr(c)-Yr(m));return{rows:a,allRows:o,eras:d,hasInferredEra:o.some(c=>c.era.source==="edition")}}function Ku(e,i){var v,w;if(!i||!i.default_collection||!i.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const n=(v=i.collections)==null?void 0:v[i.default_collection],r=(n==null?void 0:n.groups)??[],o=(n==null?void 0:n.book_ids)??[],a=r.length>0||o.length>0,l=!a&&i.default_collection==="core"&&Array.isArray(i.core_books)?i.core_books:[];if(!a&&l.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...o,...l]),m=x=>{if(c.has(x))return!0;const j=i.node_groups[x];return j!=null&&d.has(j)},p=[],h=new Map,u=[];for(const x of e)if(!((w=i.excluded_books)!=null&&w.includes(x)))if(m(x))p.push(x);else{const j=i.node_groups[x];j?(h.has(j)||h.set(j,[]),h.get(j).push(x)):u.push(x)}if(u.length+[...h.values()].reduce((x,j)=>x+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const g=new Map((i.groups??[]).map(x=>[x.id,x])),y=[...h.entries()].map(([x,j])=>{const S=g.get(x);return{id:x,label:(S==null?void 0:S.label)??x,description:S==null?void 0:S.description,ids:j}});return u.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:p,groupedIds:y}}const Fl=["撰","編","注","校","譯","繪","其他"],Yu=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function ws(e){if(!e||!e.trim())return"撰";const i=e.replace(/[\s-]/g,"");if(!i)return"撰";for(const{cls:n,re:r}of Yu)if(r.test(i))return n;return"其他"}function vs(e){if(!e)return"";const i=e.trim();return!i||!/[一-鿿]/.test(i)?"":i}function Bl(e,i="全部"){const n=new Map;for(const o of e){const a=ws(o);n.set(a,(n.get(a)??0)+1)}const r=[{cls:"全部",label:i,count:e.length}];for(const o of Fl){const a=n.get(o);a&&r.push({cls:o,label:o,count:a})}return r.length>2?r:[]}function Ss(e){return(e._books??[]).map(i=>i.id).filter(i=>typeof i=="string")}function $s(e){const i=e._classifications??[],n=i.find(r=>r.scheme==="zongmu")??i[0];if(n)return{l1:n.l1??"",l2:n.l2??"",l3:n.l3??"",l4:n.l4??"",...n.source?{source:n.source}:{}}}function Hl(e){const i=e._members??[],n=typeof e._member_count=="number"?e._member_count:i.length;return{works:i.filter(r=>r.t==="work").map(r=>({id:r.id,title:r.title??"",volumes:Wi(r.vol)})),bookIds:i.filter(r=>r.t!=="work").map(r=>r.id).filter(r=>typeof r=="string"),total:n,truncated:n>i.length}}function Gu(e){var i;return(e==null?void 0:e._member_count)||((i=e==null?void 0:e._members)==null?void 0:i.length)||0}function Dl(e,i,n){if(i&&i.books&&i.books.length>0){const l=i.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),d=[...new Set(l.map(c=>c.section).filter(Boolean))];return{rows:l,source:"catalog",sections:d,totalVolumes:i.total_volumes}}const{works:r,bookIds:o}=Hl(e);return r.length>0?{rows:r.map(d=>({id:d.id,title:d.title,volumes:d.volumes})),source:"works",sections:[]}:{rows:o.map(l=>{var d,c;return{id:l,title:((d=n==null?void 0:n.get(l))==null?void 0:d.title)||l,edition:(c=n==null?void 0:n.get(l))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Wi(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(i=>typeof i=="number");if(typeof e=="string"){const i=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(i){const[n,r]=[parseInt(i[1]),parseInt(i[2])];return Array.from({length:Math.max(0,r-n+1)},(o,a)=>n+a)}return e.split(/[,、]/).map(n=>parseInt(n.trim())).filter(n=>!isNaN(n))}return[]}function Yn(e,i="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=[...e].sort((a,l)=>a-l),r=n[0],o=n[n.length-1];return o-r+1===n.length?`${r}–${o}`:n.length<=3?n.join(", "):`${r}–${o} (${n.length}${i})`}const Vu=["poem","ci","qu","fu","article"];function Qo(e){return!!e&&Vu.includes(e)}function Gr(e){if(e==null||e==="")return"";if(Array.isArray(e)){const i=e.filter(r=>Number.isFinite(r));if(!i.length)return"";if(i.length===1)return String(i[0]);const n=[...i].sort((r,o)=>r-o);return n[n.length-1]-n[0]+1===n.length?`${n[0]}–${n[n.length-1]}`:n.join("、")}return String(e)}function qu(e,i,n,r){const o=[],a=Gr(e);if(a&&o.push(r.vol.replace("{n}",a)),typeof i=="number"&&i>0){const l=n==="poem"||n==="ci"||n==="qu"?r.shou:r.pian;o.push(l.replace("{n}",String(i)))}return o.join(" · ")}const Xu=["〇","一","二","三","四","五","六","七","八","九"],ea=["","十","百","千"];function Gi(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return _r(e,!0);const i=Math.floor(e/1e4),n=e%1e4;let r=_r(i,!0)+"萬";return n>0&&(r+=(n<1e3?"〇":"")+_r(n,!1)),r}function _r(e,i){const n=String(e),r=n.length;let o="",a=!1;for(let l=0;l<r;l++){const d=parseInt(n[l]),c=r-1-l;d===0?a=!0:(a&&o&&(o+="〇"),a=!1,i&&d===1&&c===1&&l===0?o+=ea[c]:o+=Xu[d]+ea[c])}return o}function Ju(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function Zu(e){if(e==null||typeof e=="string")return;const i="url"in e&&e.url?e.url:"type"in e&&e.type==="url"?e.details:void 0;return i&&/^https?:\/\//i.test(i)?i:void 0}function qt(e,i="卷"){var o,a;const n=e;if(n.measure_info)return n.measure_info;if((o=n.juan_count)!=null&&o.number)return Gi(n.juan_count.number)+i;if((a=n.juan_count)!=null&&a.description)return n.juan_count.description;const r=(n.measures??[]).filter(l=>l&&typeof l.number=="number"&&l.number>0&&l.unit);return r.length?r.map(l=>Gi(l.number)+(l.unit==="卷"?i:l.unit)).join(""):""}function Wl(e){if(e.edition_type)return e.edition_type;const i=e.edition||e.title||"",n=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/油印/,"油印本"],[/曬印|晒印/,"曬印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[r,o]of n)if(r.test(i))return o;return""}const Gn={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Ul=new Set(["work","book","entity"]);function Qu(e){return Gl(e)||!!e.sort}function ep(e,i){return i.sort&&Ul.has(e)?i.sort:void 0}const Vn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],qn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Kl=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Yl={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Xn(e){return e.dynasty.length+e.classification.length+(e.hasImage?1:0)+(e.hasText?1:0)+(e.hasCollated?1:0)+(e.loss?1:0)}function Gl(e){return Xn(e)>0}function tp(e){const i=[];return e.dynasty.length&&i.push("dynasty"),e.classification.length&&i.push("classification"),e.hasImage&&i.push("hasImage"),e.hasText&&i.push("hasText"),e.hasCollated&&i.push("hasCollated"),e.loss&&i.push("loss"),i}function Vl(e,i){const n=Yl[e];return tp(i).every(r=>n.has(r))}const Ai=e=>JSON.stringify(e);function ip(e,i){if(!Vl(i,e))return null;const n=[];if(e.dynasty.length){const r=Array.from(new Set(e.dynasty.flatMap(o=>{var a;return((a=Vn.find(l=>l.key===o))==null?void 0:a.values)??[]})));r.length===1?n.push(`dynasty = ${Ai(r[0])}`):r.length>1&&n.push(`dynasty IN [${r.map(Ai).join(", ")}]`)}return e.classification.length&&n.push(e.classification.length===1?`classification = ${Ai(e.classification[0])}`:`classification IN [${e.classification.map(Ai).join(", ")}]`),e.hasImage&&n.push("has_image = true"),e.hasText&&n.push("has_text = true"),e.hasCollated&&n.push("has_collated = true"),e.loss&&n.push(`loss_status = ${Ai(e.loss)}`),n.join(" AND ")}const Nt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},ql="_";function An(e,i=new URLSearchParams){for(const n of Object.values(Nt))i.delete(n);return e.dynasty.length&&i.set(Nt.dynasty,e.dynasty.join(",")),e.classification.length&&i.set(Nt.classification,e.classification.map(n=>n||ql).join(",")),e.hasImage&&i.set(Nt.hasImage,"1"),e.hasText&&i.set(Nt.hasText,"1"),e.hasCollated&&i.set(Nt.hasCollated,"1"),e.loss&&i.set(Nt.loss,e.loss),e.sort&&i.set(Nt.sort,e.sort),i}function np(e){const i=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),n=new Set(Vn.map(a=>a.key)),r=new Set(qn.map(a=>a.value)),o=e.get(Nt.loss);return{dynasty:Array.from(new Set(i(Nt.dynasty).filter(a=>n.has(a)))),classification:Array.from(new Set(i(Nt.classification).map(a=>a===ql?"":a).filter(a=>r.has(a)))),hasImage:e.get(Nt.hasImage)==="1",hasText:e.get(Nt.hasText)==="1"||e.get(Nt.hasCollated)==="1",hasCollated:!1,loss:o==="extant"||o==="partially_extant"||o==="lost"?o:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(a=>a===e.get(Nt.sort))??""}}function rp(e,i){return JSON.stringify([e.dynasty.slice().sort(),e.classification.slice().sort(),e.hasImage,e.hasText,e.hasCollated,e.loss,e.sort])===JSON.stringify([i.dynasty.slice().sort(),i.classification.slice().sort(),i.hasImage,i.hasText,i.hasCollated,i.loss,i.sort])}function ta(e,i){return e.includes(i)?e.filter(n=>n!==i):[...e,i]}const sp=({filters:e,onChange:i})=>{const n=s.useT(),r=n.searchV4,{convert:o}=xt(),[a,l]=b.useState(!1),d=b.useId(),c=Xn(e),m=p=>i({...e,...p});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":o(r.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":a,"aria-controls":d,onClick:()=>l(p=>!p),children:[t.jsxs("span",{children:[o(r.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:o(s.formatTemplate(r.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[o(a?r.collapse:r.expand)," ",a?"▴":"▾"]})]}),t.jsxs("div",{className:"bim-sr-filters",id:d,"data-open":a?"true":"false",...a?{}:{"data-collapsed":"true"},children:[t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(r.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:Vn.map(p=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(p.key),onClick:()=>m({dynasty:ta(e.dynasty,p.key)}),children:o(p.key)},p.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(r.classification)}),qn.map(p=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(p.value),onChange:()=>m({classification:ta(e.classification,p.value)})}),p.value?o(p.label):n.searchPage.unclassified]},p.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(r.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:p=>m({hasImage:p.target.checked})}),o(r.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:p=>m({hasText:p.target.checked})}),o(r.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:o(r.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:Kl.map(p=>t.jsx("button",{type:"button","aria-pressed":e.loss===p.value,onClick:()=>m({loss:p.value}),children:n.searchPage.loss[p.value||"all"]},p.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>i({...Gn,sort:e.sort}),children:o(r.clearAllFilters)})]})]})};function Xl({text:e,query:i}){const n=(i??"").trim();if(!n||!e)return t.jsx(t.Fragment,{children:e});const r=e.toLowerCase(),o=n.toLowerCase(),a=[];let l=0,d=0;for(;l<e.length;){const c=r.indexOf(o,l);if(c<0){a.push(e.slice(l));break}c>l&&a.push(e.slice(l,c)),a.push(t.jsx("mark",{className:"bim-sr-hl",children:e.slice(c,c+o.length)},d++)),l=c+o.length}return t.jsx(t.Fragment,{children:a})}const ia=({entries:e,query:i,onEntryLinkClick:n,typeName:r})=>{const o=s.useT(),a=o.searchV4,{convert:l}=xt(),d=It();return t.jsx("div",{className:"bim-sr-tablewrap",children:t.jsxs("table",{className:"bim-sr-table",children:[t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"34%"}}),t.jsx("col",{style:{width:"8%"}}),t.jsx("col",{style:{width:"19%"}}),t.jsx("col",{style:{width:"13%"}}),t.jsx("col",{style:{width:"12%"}}),t.jsx("col",{style:{width:"14%"}})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:l(a.colTitle)}),t.jsx("th",{scope:"col",children:l(a.colType)}),t.jsx("th",{scope:"col",children:l(a.colAuthor)}),t.jsx("th",{scope:"col",children:l(a.colEra)}),t.jsx("th",{scope:"col",children:l(a.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:l(a.colResource)})]})}),t.jsx("tbody",{children:e.map(c=>{const m=l(c.title||c.primary_name||c.id),p=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${o.unit.juan}`:"",h=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${l(c.author)}${c.role&&c.role!=="author"?` ${l(c.role)}`:""}`:"",u=c.type==="book"?c.era??c.dynasty:c.dynasty,f=u?l(u):"",g=c.classification?l(c.classification):"",y=[];c.has_image&&y.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&y.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&y.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const v=[h,f,g].filter(Boolean).join(" · ");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-sr-c-title",children:[t.jsxs("div",{className:"bim-sr-tl",children:[t.jsx("a",{href:d(c.id),onClick:w=>n(c,w),children:t.jsx(Xl,{text:m,query:i?l(i):void 0})}),p&&t.jsx("span",{className:"bim-sr-measure",children:p})]}),v&&t.jsx("span",{className:"bim-sr-sub",children:v})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Xi,{type:c.type,size:6})," ",r(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:h||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:f||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:g||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:y.map(w=>t.jsx("span",{className:`bim-sr-tag ${w.cls}`,children:l(w.label)},w.label))})]},c.id)})})]})})},op=`
|
|
1
|
+
"use strict";var eu=Object.create;var Wo=Object.defineProperty;var tu=Object.getOwnPropertyDescriptor;var iu=Object.getOwnPropertyNames;var nu=Object.getPrototypeOf,ru=Object.prototype.hasOwnProperty;var su=(e,i,n,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of iu(i))!ru.call(e,o)&&o!==n&&Wo(e,o,{get:()=>i[o],enumerable:!(r=tu(i,o))||r.enumerable});return e};var gn=(e,i,n)=>(n=e!=null?eu(nu(e)):{},su(i||!e||!e.__esModule?Wo(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./storage-entry-tWa4CaT4.cjs"),t=require("react/jsx-runtime"),b=require("react"),s=require("./Badge-gj9fd1yH.cjs"),ou=require("opencc-js/t2cn"),vi=require("./variant-chars-kDZNY5eM.cjs"),au=require("react-markdown"),lu=require("remark-gfm"),cu=require("./variant-supplement.cjs"),du=e=>`/item/${e}`,$l=b.createContext(du);function mu({buildUrl:e,children:i}){const n=b.useMemo(()=>e,[e]);return t.jsx($l.Provider,{value:n,children:i})}function It(){return b.useContext($l)}const _l="",Nl="";function gs(e){const i=[];let n=!1,r=e;for(;r.length;){const o=n?Nl:_l,a=r.indexOf(o);if(a===-1){i.push({text:r,marked:n});break}a>0&&i.push({text:r.slice(0,a),marked:n}),r=r.slice(a+1),n=!n}return i}let Mi=null;function zl(){if(Mi)return Mi;try{const e=ou.Converter({from:"t",to:"cn"});Mi=s.withProtectedTerms(i=>e(vi.normalizeVariants(i)))}catch{Mi=e=>e}return Mi}const Cl="bim-locale";function uu(){try{const e=localStorage.getItem(Cl);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function pu(e){try{localStorage.setItem(Cl,e)}catch{}}const bu="zh-Hans",hu=({locale:e,onLocaleChange:i,converter:n,children:r})=>{const[o,a]=b.useState(e??bu),l=e??o;b.useEffect(()=>{if(e)return;const p=uu();p&&p!==o&&a(p)},[]);const d=b.useMemo(()=>l==="zh-Hans"?n??zl():null,[l,n]),c=b.useCallback(p=>{a(p),pu(p),i==null||i(p)},[i]),m=b.useMemo(()=>({locale:l,setLocale:c,messages:s.getMessages(l),converter:d}),[l,c,d]);return t.jsx(s.LocaleContext.Provider,{value:m,children:r})},fu=2e3;function xt(){const e=b.useContext(s.LocaleContext),i=(e==null?void 0:e.locale)??"zh-Hant",n=(e==null?void 0:e.converter)??null,r=b.useRef(new Map),o=b.useRef(i),a=b.useRef(n);(o.current!==i||a.current!==n)&&(r.current.clear(),o.current=i,a.current=n);const l=b.useCallback(d=>{if(!d)return"";if(!n)return d;const c=r.current.get(d);if(c!==void 0)return c;const m=n(d);if(r.current.size>=fu){const p=r.current.keys().next().value;p!==void 0&&r.current.delete(p)}return r.current.set(d,m),m},[n]);return b.useMemo(()=>({convert:l,locale:i,isSimplified:i==="zh-Hans"}),[l,i])}function oe(){const e=b.useContext(s.LocaleContext),{convert:i,locale:n,isSimplified:r}=xt(),o=(e==null?void 0:e.messages)??s.getMessages("zh-Hant"),a=b.useMemo(()=>e?s.makeT(o):s.getT("zh-Hant"),[e,o]);return b.useMemo(()=>({t:a,convert:i,locale:n,isSimplified:r,messages:o}),[a,i,n,r,o])}function gu(e,i,n){return e?e==="orig"?null:i==="zh-Hans"?n??zl():e==="hant"?vi.normalizeVariants:n:i==="zh-Hans"?n:vi.normalizeVariants}const xu=({mode:e,children:i})=>{const n=b.useContext(s.LocaleContext),r=b.useMemo(()=>n&&{...n,converter:gu(e,n.locale,n.converter)},[n,e]);return t.jsx(s.LocaleContext.Provider,{value:r,children:i})},Uo={text:s.bim("restype-text"),image:s.bim("restype-image"),"text+image":s.bim("restype-text-image"),physical:s.bim("restype-physical")};function yu(e){return e.includes("text")&&e.includes("image")?Uo["text+image"]:Uo[e[0]||"physical"]}const ju=({items:e,groupByType:i=!0,resourceGroups:n,onNavigate:r,renderLink:o})=>{const a=s.useT(),{convert:l}=xt(),d=b.useMemo(()=>s.mergeVolumeResources(e||[]),[e]),{mirrorGroups:c,ungroupedItems:m,labelOnlyKeys:p}=b.useMemo(()=>{const w=new Map,x=[],j=new Map;d.forEach((S,$)=>{const N=S.group||(S.label?`_label:${$}`:void 0);!S.group&&S.label&&N&&j.set(N,S.label),N?(w.has(N)||w.set(N,[]),w.get(N).push(S)):x.push(S)});for(const S of w.values())S.sort(($,N)=>{const z=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return z($)-z(N)});return{mirrorGroups:w,ungroupedItems:x,labelOnlyKeys:j}},[d]),h={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=w=>h[w]?h[w]:w.split("+").map(x=>h[x]||x).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:s.bim("desc-fg"),fontSize:"13px",textAlign:"center"},children:a.misc.noResources});if(!i)return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:d.map((w,x)=>t.jsx(Sr,{item:w},w.id||x))});const f=(w,x)=>{const j=n==null?void 0:n[w],S=p.get(w)||(j==null?void 0:j.label)||w,$=j==null?void 0:j.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:s.bim("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:s.bim("fg")},children:l(S)}),$&&t.jsx("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.5},children:l($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((N,z)=>t.jsx(Sr,{item:N,onNavigate:r,renderLink:o},N.id||z))})]},`group-${w}`)},g=new Map;for(const w of m){const x=s.getTypeGroupKey(s.getResourceTypes(w));g.has(x)||g.set(x,[]),g.get(x).push(w)}const y=["text","image","text+image","physical"],v=[...y.filter(w=>g.has(w)),...[...g.keys()].filter(w=>!y.includes(w)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([w,x])=>f(w,x)),v.map(w=>{const x=g.get(w),j=yu(w.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:u(w)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((S,$)=>t.jsx(Sr,{item:S,onNavigate:r,renderLink:o},S.id||$))})]},w)})]})},ku={bw:{label:"",bg:s.bim("colormode-bw-bg"),fg:s.bim("colormode-bw-fg")},color:{label:"",bg:s.bim("colormode-color-bg"),fg:s.bim("colormode-color-fg")}},Sr=({item:e})=>{const i=s.useT(),{convert:n}=xt(),[r,o]=b.useState(!1),a=b.useMemo(()=>(e.url?s.getDisplayNameFromUrl(e.url):void 0)||n(e.name),[e.url,e.name,n]),l=b.useMemo(()=>!Array.isArray(e.volumes)||e.volumes.length===0?null:e.volumes.map(g=>({...g,url:g.url||s.extractVolumeUrl(g)})),[e.volumes]),d=l&&l.length>0,c=d?new Set(l.filter(g=>g.status!=="missing").map(g=>g.volume)).size:0,m=d?new Set(l.filter(g=>g.status==="missing").map(g=>g.volume)).size:0,p=e.expected_volumes??(d?c+m:0),h=e.color_mode?{...ku[e.color_mode],label:i.colorMode[e.color_mode]}:null,u=e.details&&!d?n(e.details):null,f={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"5px",background:s.bim("input-bg"),fontSize:"12px",color:s.bim("fg"),lineHeight:1.4,verticalAlign:"middle"};return t.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[t.jsxs("div",{style:f,children:[t.jsx("span",{style:{fontWeight:500},children:a}),h&&t.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:h.bg,color:h.fg},children:h.label}),u&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:u}),d&&t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[c,"/",p,i.unit.volume,m>0&&t.jsx("span",{style:{color:s.bim("missing-fg"),marginLeft:"3px"},children:s.formatTemplate(i.common.volumesMissing,{n:m})})]}),e.url&&t.jsx("a",{href:(()=>{const g=s.getStartPage(e.metadata);return g?s.buildPageUrl(e.url,g):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:s.bim("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:i.action.visit}),d&&t.jsx("button",{onClick:()=>o(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),d&&r&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(g=>{const y=g.status==="missing";return g.url&&!y?t.jsx("a",{href:g.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:`1px solid ${s.bim("widget-border")}`,color:s.bim("link-fg"),textDecoration:"none"},children:g.volume},g.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?s.bim("missing-fg"):s.bim("desc-fg"),textDecoration:y?"line-through":"none",opacity:y?.6:1},children:g.volume},g.volume)})})]})},El=({indexSource:e,syncConfig:i,variant:n="index-browser",onSwitchMode:r,onToggleDraft:o,onConfigurePath:a,onSelectFolder:l})=>{const d=s.useT(),c=e==="local",m=(i==null?void 0:i.isDraft)??!0,p=(i==null?void 0:i.repoPath)||"",h=p?p.split(/[/\\]/).pop()||p:"",u={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:s.bim("primary-soft"),color:s.bim("primary")},f={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},g=t.jsxs("div",{onClick:o,title:m?d.mode.switchToOfficial:d.mode.switchToDraft,style:{...u,background:m?s.bim("warning"):s.bim("success"),color:s.bim("on-color-fg")},...f,children:[t.jsx("span",{children:m?"📝":"📚"}),t.jsx("span",{children:m?"draft":"official"})]});return n==="index-browser"?c?t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[g,t.jsxs("div",{onClick:r,title:d.mode.switchToSync,style:u,...f,children:[t.jsx("span",{children:"📁"}),t.jsx("span",{children:d.mode.localMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsxs("div",{onClick:l,title:p||d.mode.selectFolder,style:{...u,paddingLeft:"8px",paddingRight:"8px"},...f,children:[t.jsx("span",{children:"📂"}),h&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:h})]})]}):t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[t.jsxs("div",{onClick:r,title:d.mode.switchToLocal,style:u,...f,children:[t.jsx("span",{children:"🌐"}),t.jsx("span",{children:d.mode.syncMode}),t.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),t.jsx("div",{onClick:a,title:h||d.mode.configurePath,style:{...u,background:"transparent",padding:"6px",fontSize:"12px"},...f,children:t.jsx("span",{children:"⚙️"})})]})]}):t.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[t.jsxs("div",{onClick:r,title:c?d.mode.switchToGithub:d.mode.switchToLocal,style:u,...f,children:[t.jsx("span",{children:c?"📁":"🌐"}),t.jsx("span",{children:c?d.mode.localMode:d.mode.githubSync}),t.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&t.jsxs("div",{onClick:l,title:p||d.mode.selectFolder,style:{...u,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...f,children:[t.jsx("span",{children:"📂"}),h&&t.jsx("span",{style:{fontSize:"11px",opacity:.9},children:h})]}),!c&&h&&t.jsxs("div",{style:{...u,background:s.bim("mode-active-bg"),color:s.bim("on-color-fg"),cursor:"default"},title:p,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:h})]})]})},Hn="bim-search-history",Ko=10,Yo=8;function Di(){try{const e=localStorage.getItem(Hn);return e?JSON.parse(e):[]}catch{return[]}}function Rl(e){try{const i=Di().filter(n=>n!==e);i.unshift(e),i.length>Ko&&(i.length=Ko),localStorage.setItem(Hn,JSON.stringify(i))}catch{}}function wu(e){try{const i=Di().filter(n=>n!==e);localStorage.setItem(Hn,JSON.stringify(i))}catch{}}function vu(){try{localStorage.removeItem(Hn)}catch{}}const Tl=({transport:e,value:i,onChange:n,onSearch:r,onEntrySelect:o,placeholder:a})=>{const l=s.useT(),d=a??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[m,p]=b.useState(!1),[h,u]=b.useState([]),[f,g]=b.useState(-1),[y,v]=b.useState(Di),w=b.useRef(null),x=b.useRef(null),j=b.useRef(null),S=b.useRef(!1);b.useEffect(()=>{g(-1);const L=i.trim();if(!L){u(y.map(Z=>({type:"history",text:Z})));return}if(!e.searchAll){u([]);return}let F=!1;const T=setTimeout(()=>{e.searchAll(L,Yo).then(Z=>{if(F)return;const O=[...Z.works,...Z.books,...Z.collections,...Z.entities??[]];u(O.slice(0,Yo).map(ae=>({type:"entry",text:ae.title||ae.id,entry:ae})))}).catch(()=>{F||u([])})},80);return()=>{F=!0,clearTimeout(T)}},[i,y,e]),b.useEffect(()=>{const L=F=>{j.current&&!j.current.contains(F.target)&&p(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[]),b.useEffect(()=>{const L=F=>{var T,Z;if(F.key==="/"&&document.activeElement!==w.current){const O=(T=document.activeElement)==null?void 0:T.tagName;if(O==="INPUT"||O==="TEXTAREA"||O==="SELECT")return;F.preventDefault(),(Z=w.current)==null||Z.focus()}};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[]);const $=b.useCallback(L=>{L.trim()&&(Rl(L.trim()),v(Di())),r(L),p(!1)},[r]),N=b.useCallback(L=>{L.type==="history"?(n(L.text),$(L.text)):L.entry&&(o?(o(L.entry),p(!1)):(n(L.text),$(L.text)))},[n,$,o]),z=b.useCallback(L=>{if(!m||h.length===0){L.key==="Enter"&&$(i);return}switch(L.key){case"ArrowDown":L.preventDefault(),g(F=>(F+1)%h.length);break;case"ArrowUp":L.preventDefault(),g(F=>(F-1+h.length)%h.length);break;case"Enter":L.preventDefault(),f>=0&&f<h.length?N(h[f]):$(i);break;case"Escape":L.preventDefault(),p(!1);break}},[m,h,f,i,$,N]),C=b.useCallback((L,F)=>{F.stopPropagation(),wu(L),v(Di()),u(T=>T.filter(Z=>!(Z.type==="history"&&Z.text===L)))},[]),U=b.useCallback(L=>{L.stopPropagation(),vu(),v([]),u([])},[]);b.useEffect(()=>{if(f>=0&&x.current){const L=x.current.children;L[f]&&L[f].scrollIntoView({block:"nearest"})}},[f]);const R=!i.trim()&&y.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:w,type:"text",placeholder:d,value:i,onChange:L=>{n(L.target.value),p(!0)},onCompositionStart:()=>{S.current=!0},onCompositionEnd:()=>{S.current=!1},onFocus:()=>{p(!0)},onKeyDown:z,style:{width:"100%",padding:"8px 12px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("input-fg"),fontSize:"14px",boxSizing:"border-box"}}),m&&h.length>0&&t.jsxs("div",{ref:x,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:s.bim("input-bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",boxShadow:s.bim("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[R&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:s.bim("desc-fg"),borderBottom:`1px solid ${s.bim("widget-border")}`},children:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:U,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),h.map((L,F)=>t.jsxs("div",{onClick:()=>N(L),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:s.bim("fg"),background:F===f?s.bim("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:L.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:L.text}),L.entry&&t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),flexShrink:0},children:[c[L.entry.type],L.entry.edition&&` · ${L.entry.edition}`,L.entry.author&&` · ${L.entry.author}`]}),L.type==="history"&&t.jsx("button",{onClick:T=>C(L.text,T),style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${L.type}-${L.text}-${F}`))]})]})},Xi=({type:e,size:i=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:i,height:i,borderRadius:1,flex:"none",background:s.bim(`type-${e}`),verticalAlign:"middle"}});function Vt(e){const i=[],n=new Set;for(const r of e.base_edition??[]){if(!r||!r.relation)continue;const o=!!r.hypothetical_id,a=o?r.hypothetical_id:r.book_id;if(!a)continue;const l=`${a}|${o?"hypothetical":"book"}`;n.has(l)||(n.add(l),i.push({ref:a,ref_type:o?"hypothetical":"book",relation:r.relation,confidence:r.confidence??void 0,evidence:r.evidence,note:r.note}))}return i}function ti(e){const i=[];for(const n of e.related_books??[])n&&typeof n=="object"&&n.book_id&&n.relation&&i.push({book_id:n.book_id,relation:n.relation,confidence:n.confidence??void 0,evidence:n.evidence});return i}function Su(e){return(e.related_books??[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_id).filter(i=>typeof i=="string"&&i.length>0)}function Tn(e){return!!e.lineage||Vt(e).length>0||ti(e).length>0}function $u(e){var i;return{id:e.id,kind:"hypothetical",label:e.label,year:e.year??((i=e.year_range)==null?void 0:i[0]),year_range:e.year_range,year_uncertain:e.year_uncertain,group:e.group,note:e.note,description:e.description}}function _u(e,i){var r,o,a,l,d;if(!Tn(e))return null;const n=e.lineage??{};return{id:e.id,kind:"book",label:e.title,year:((r=e.dating)==null?void 0:r.year)??((a=(o=e.dating)==null?void 0:o.year_range)==null?void 0:a[0]),year_text:(l=e.dating)==null?void 0:l.text,year_uncertain:(d=e.dating)==null?void 0:d.year_uncertain,category:e.edition_type,status:n.status,extant_juan:n.extant_juan,group:i[e.id],note:n.note}}function Go(e,i,n){return{id:`derive:${i.ref}->${e}:${n}`,source:i.ref,target:e,kind:"derive",relation:i.relation,confidence:i.confidence,evidence:i.evidence,note:i.note}}function Nu(e,i,n){const[r,o]=[e,i.book_id].sort();return{id:`sibling:${r}-${o}:${n}`,source:r,target:o,kind:"sibling",relation:i.relation,confidence:i.confidence,evidence:i.evidence,note:i.note}}function zu(e,i){var m;if(i==="all")return null;const n=(m=e.collections)==null?void 0:m[i],r=Array.isArray(n==null?void 0:n.groups)&&n.groups.length>0,o=Array.isArray(n==null?void 0:n.book_ids)&&n.book_ids.length>0,a=r||o||!!(n!=null&&n.hypothetical_ids);if(!a&&i==="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(!n||!a)return null;const l=r?new Set(n.groups):null,d=new Set(n.book_ids??[]);if(l&&e.node_groups)for(const[p,h]of Object.entries(e.node_groups))l.has(h)&&d.add(p);let c=null;if(n.hypothetical_ids&&(c=new Set(n.hypothetical_ids)),l){c||(c=new Set);for(const p of e.hypothetical_nodes??[])p.group&&l.has(p.group)&&c.add(p.id)}return{books:d,hypos:c}}function Sn(e,i,n){const r=e.version_graph,o={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return o;const a=new Set(r.excluded_books??[]),l=r.node_groups??{},d=zu(r,n??r.default_collection??"all"),c=d!==null,m=(d==null?void 0:d.books)??null,p=(d==null?void 0:d.hypos)??null,h=new Set,u=new Set;if(c){const S=new Map(i.map(R=>[R.id,R])),$=new Map((r.hypothetical_nodes??[]).map(R=>[R.id,R])),N=R=>{const L=S.get(R);if(L&&Tn(L))return Vt(L).map(T=>T.ref);const F=$.get(R);return F?(F.derived_from??[]).map(T=>T.ref):[]},z=R=>$.has(R)?!p||p.has(R):!m||m.has(R),C=new Set,U=R=>{if(!C.has(R)){C.add(R);for(const L of N(R))a.has(L)||(z(L)||($.has(L)?u.add(L):S.has(L)&&h.add(L)),U(L))}};for(const R of i)m&&m.has(R.id)&&!a.has(R.id)&&U(R.id);for(const R of r.hypothetical_nodes??[])p&&p.has(R.id)&&U(R.id)}const f=i.filter(S=>!a.has(S.id)).filter(S=>!m||m.has(S.id)||h.has(S.id)).map(S=>{const $=_u(S,l);return $&&h.has(S.id)&&($.bridge=!0),$}).filter(S=>S!==null),g=(r.hypothetical_nodes??[]).filter(S=>!p||p.has(S.id)||u.has(S.id)).map(S=>{const $=$u(S);return u.has(S.id)&&($.bridge=!0),$}),y=[...f,...g],v=new Set(y.map(S=>S.id)),w=new Set,x=[],j=S=>{w.has(S.id)||!v.has(S.source)||!v.has(S.target)||(w.add(S.id),x.push(S))};for(const S of i)a.has(S.id)||!Tn(S)||m&&!m.has(S.id)&&!h.has(S.id)||(Vt(S).forEach(($,N)=>{j(Go(S.id,$,N))}),ti(S).forEach(($,N)=>{j(Nu(S.id,$,N))}));for(const S of r.hypothetical_nodes??[])p&&!p.has(S.id)&&!u.has(S.id)||(S.derived_from??[]).forEach(($,N)=>{j(Go(S.id,$,N))});return{nodes:y,edges:x,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(a)}}function Il(e,i,n){const r=(e??(i!=null?String(i):"")).trim();return r?!n||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Cu(e,i){const n=[],r=e.version_graph;if(!r)return n;const o=new Set(i.map(c=>c.id)),a=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...o,...a]),d=(c,m)=>{l.has(m.ref)||n.push(`${c}: derived_from.ref "${m.ref}" 未在 books 或 hypothetical_nodes 中找到`),m.ref_type==="book"&&!o.has(m.ref)&&n.push(`${c}: derived_from.ref "${m.ref}" 标记为 book 但不在 books 列表中`),m.ref_type==="hypothetical"&&!a.has(m.ref)&&n.push(`${c}: derived_from.ref "${m.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of i){if(!Tn(c))continue;const m=`Book ${c.id} (${c.title})`;Vt(c).forEach(p=>d(m,p)),ti(c).forEach(p=>{o.has(p.book_id)||n.push(`${m}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const m=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(p=>d(m,p))}return n}const Ml=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Eu={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Tt(e){return Eu[e]??e}const Si=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],$i={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},Al={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Dn(e){const i=e.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!i)return;const n=parseInt(i[1],10);if(n<100||n>2100)return;const r=i[2]?parseInt(i[2],10):void 0;return{from:n,to:r!=null&&r>=n&&r<=2100?r:void 0}}function Ru(e){return e>=1950?"":e>=1912?"民國":e>=1645?"清":e>=1368?"明":e>=1279?"元":e>=960?"宋":e>=907?"五代":e>=618?"唐":e>=581?"隋":e>=420?"南北朝":e>=265?"晉":e>=220?"三國":e>=-202?"漢":""}const Tu=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Vo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function xs(e){const i=e.trim().replace(/[代朝]$/,"");for(const o of Object.keys(Vo))if(i.startsWith(o))return Vo[o];const n=Tt(i);if(yi[n]!=null)return n;const r=Qt(i);if(r&&i.length<=r.length+1)return Tt(r)}function ci(e,i){if(i){const n=Al[`${i}|${e}`];if(n!=null)return n}return $i[e]}const Iu=1911;function Mu(e){const i=$i[e];if(i==null)return;const n=Ht[e];let r;for(const[o,a]of Object.entries($i))Ht[o]===n&&a>i&&(r==null||a<r)&&(r=a);return r!=null?r-1:void 0}const Au={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function In(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let i=0,n=0,r=!1;for(const a of e){const l=Au[a];if(l===void 0)return;r=!0,a==="十"?n=(n||1)*10:a==="廿"||a==="卅"?(i+=l,n=0):n>=10?(i+=n+l,n=0):n=n*10+l}const o=i+n;return r&&o>0?o:void 0}function Qt(e){for(const i of Ml)if(e.startsWith(i))return i}const Ht={};{const e=(i,n)=>{for(const r of n)Ht[r]=i};e("東漢",["熹平","建安"]),e("三國",["黃初","正始"]),e("五代",["廣政"]),e("西晉",["太康"]),e("東晉",["永和"]),e("隋",["開皇"]),e("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),e("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),e("金",["大定","明昌"]),e("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),e("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),e("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),e("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function ki(e,i){const n=i==="北宋"||i==="南宋"?"宋":i;for(const r of Object.keys($i))if(e.includes(r)&&!(n&&Ht[r]&&Ht[r]!==n&&Al[`${n}|${r}`]==null))return r}function Wn(e){var r;const i=e.dating;if(!i||i.era||i.reign||(r=e.publication_info)!=null&&r.year)return e;const n=i.text??(i.year!=null?String(i.year):i.year_range&&i.year_range.length===2?`${i.year_range[0]}-${i.year_range[1]}`:void 0);return n?{...e,publication_info:{...e.publication_info,year:n}}:e}function Ji(e){var a,l;e=Wn(e);const i={era:"",reign:"",source:"none"},n=e.dating;if(n!=null&&n.era||n!=null&&n.reign)return{era:n.era??"",reign:n.reign??"",source:n.certainty==="attested"?"catalog":"edition"};const r=(a=e.publication_info)==null?void 0:a.year;if(r){const d=Dn(r);if(d)return{era:Ru(d.from),reign:"",source:"publication"};const c=Qt(r)??xs(r)??((l=Si.find(h=>h.pattern.test(r)))==null?void 0:l.era)??"",m=ki(r,c)??"",p=c||(m?Ht[m]??"":"");if(p||m)return{era:Tt(p),reign:m,source:"publication"}}const o=e.edition||e.title||"";if(o){const d=Qt(o);if(d)return{era:Tt(d),reign:ki(o,d)??"",source:"edition"};const c=Si.find(m=>m.pattern.test(o));if(c)return{era:Tt(c.era),reign:ki(o,c.era)??c.reign??"",source:"edition"}}return i}function Un(e){var r,o,a,l,d,c;if(e=Wn(e),((r=e.dating)==null?void 0:r.year)!=null)return e.dating.year;const i=(o=e.publication_info)==null?void 0:o.year;if(i){const m=Dn(i);if(m)return m.from}const n=[(a=e.publication_info)==null?void 0:a.year,e.edition,e.edition?void 0:e.title].filter(Boolean);for(const m of n){const p=(l=e.publication_info)==null?void 0:l.year;if(p&&m!==p&&(Qt(p)||xs(p)))break;const h=m.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??m.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(h){const v=parseInt(h[1],10);if(v>=100&&v<=2100)return v}const u=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(u){const v=Qt(m);if(!v||Tt(v)==="民國"){const x=In(u[1]);if(x!=null&&x>=1&&x<=120)return Iu+x}}const f=Qt(m)??((d=Si.find(v=>v.pattern.test(m)))==null?void 0:d.era),g=f?Tt(f):void 0,y=ki(m,g)??(Qt(m)||(c=Si.find(v=>v.pattern.test(m)))==null?void 0:c.reign);if(y){const v=ci(y,g);if(v==null)continue;const w=m.indexOf(y),x=w>=0?m.slice(w+y.length):"",j=x.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??x.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=j?In(j[1]):void 0;return v+(S?S-1:0)}}}function ys(e){var o,a,l,d;e=Wn(e);const i=(o=e.dating)==null?void 0:o.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const n=(a=e.publication_info)==null?void 0:a.year;if(n){const c=Dn(n);if((c==null?void 0:c.to)!=null)return{from:c.from,to:c.to};const m=n.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(m){const p=Ll[Tt(m[1])],h=yi[Tt(m[2])];if(p!=null&&h!=null)return{from:Math.min(p,h)-20,to:Math.max(p,h)+40}}}const r=[(l=e.publication_info)==null?void 0:l.year,e.edition,e.title].filter(Boolean);for(const c of r){if(!/[間间]/.test(c))continue;const m=Qt(c)??xs(c)??((d=Si.find(u=>u.pattern.test(c)))==null?void 0:d.era),p=m?Tt(m):void 0,h=[];for(const u of Object.keys($i))c.includes(u)&&(p&&Ht[u]&&Ht[u]!==p||ci(u,p)!=null&&h.push(u));if(h.length===0){const u=c.match(/([一-鿿])([一-鿿])[間间]/);if(u&&p){for(const f of[u[1],u[2]])for(const g of Object.keys($i))if(Ht[g]===p&&!(g[0]!==f&&g[g.length-1]!==f)&&ci(g,p)!=null){h.push(g);break}}}if(h.length>0){const u=h.map(v=>ci(v,p)).filter(v=>v!=null),f=Math.min(...u),g=h.reduce((v,w)=>ci(v,p)>=ci(w,p)?v:w),y=Mu(g)??$r(p??"")??Math.max(...u);return{from:f,to:y>f?y:$r(p??Ht[g]??"")??f}}if(p&&yi[p]!=null)return{from:yi[p],to:$r(p)??yi[p]}}}const yi={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Lu=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Pu=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,qo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Xo(e,i){for(const n of Ml){const r=e.indexOf(n);if(r<0)continue;if(n.length===1){const c=e[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!ki(e.slice(r),Tt(n)))continue}const o=Tt(n);if(o===i)continue;const a=e.slice(r),l=ki(a,o)??"";let d;if(l){const c=ci(l,o);if(c!=null){const p=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),h=p?In(p[1]):void 0;d=c+(h?h-1:0)}}return{era:o,reign:l,year:d}}for(const n of Si)if(n.pattern.test(e))return{era:Tt(n.era),reign:n.reign??""}}function Ou(e){var y,v;e=Wn(e);const i=Ji(e),n=((y=e.publication_info)==null?void 0:y.year)??"",r=n?Dn(n):void 0;if(!i.era&&!i.reign&&!r)return;const o=e.edition||e.title||"",a=/[間间]/.test(o),l=i.source==="publication"&&Tu.test(n),d=i.source==="publication"&&/[間间]/.test(n),c=n.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let m;a||l||d?m=void 0:c?m=parseInt(c[2],10):m=Un(e);const p=m==null?ys(e):void 0;let h;i.source==="publication"&&(l||qo.test(n))?h="uncertain":i.source==="publication"?h="attested":qo.test(o)||!i.reign&&m==null?h="uncertain":h="inferred";const u=i.source==="edition"?`題名「${o}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,f={era:i.era,reign:i.reign,year:m,yearRange:p,certainty:h,source:i.source==="edition"?"edition":"catalog",basis:u};if(c){const w=n.match(/[、,,]\s*([宋元明清])/);w&&w[1]!==f.era&&(f.laterRepair={era:w[1]})}if(!f.laterRepair&&Pu.test(o)){const w=o.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);w&&w[1]!==i.era&&(f.laterRepair={era:w[1]})}const g=Lu.find(w=>w.re.test(o));if(g){const w=o.search(g.re),x=o.slice(w),j=Xo(x,i.era)??Xo(o,i.era);j&&(f.basedOn={era:j.era,reign:j.reign,year:j.year,relation:g.relation})}return f}const Ll={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function $r(e){return Ll[e]}function Mn(e){const i=Un(e);if(i!=null)return i;const n=ys(e);if(n)return n.from;const r=Ji(e).era;return r?yi[r]:void 0}const Jo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Yr(e){const i=Jo.indexOf(e);return i===-1?Jo.length:i}function Fu(e){const i={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const o of e){const a=o.relation;a==="part_of"?i.belongsTo.push(o):a==="collected_in"?i.collected.push(o):a==="has_part"||a==="contains_text_of"?i.contains.push(o):a==="text_carried_by"||a==="studied_by"||a==="derived_from"||a==="followed_by"||a==="has_adaptation"?i.derivative.push(o):a==="studies"||a==="preceded_by"?i.studies.push(o):i.related.push(o)}const n=[],r=(o,a)=>{i[o].length&&n.push({key:o,labelKey:a,items:i[o]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),n}function js(e,i){const n=s.mergeVolumeResources(e||[]),r=new Map,o=[],a=new Map;n.forEach((p,h)=>{if(p.group)r.has(p.group)||r.set(p.group,[]),r.get(p.group).push(p);else if(p.label){const u=`_label:${h}`;r.set(u,[p]),a.set(u,p.label)}else o.push(p)});for(const p of r.values())p.sort((h,u)=>{const f=g=>g.group_role==="origin"?0:g.group_role==="mirror"?1:2;return f(h)-f(u)});const l={text:[],image:[],textImage:[],physical:[]};for(const p of o){const h=s.getResourceTypes(p),u=h.includes("text"),f=h.includes("image");u&&f?l.textImage.push(p):u?l.text.push(p):f?l.image.push(p):l.physical.push(p)}const c=["text","image","textImage","physical"].filter(p=>l[p].length>0).map(p=>({key:p,items:l[p]})),m=[...r.entries()].map(([p,h])=>{var u,f;return{key:p,label:a.get(p)||((u=i==null?void 0:i[p])==null?void 0:u.label)||p,description:a.has(p)||(f=i==null?void 0:i[p])==null?void 0:f.description,items:h}});return{buckets:c,mirrors:m,total:n.length}}function Kn(e,i=s.getT("zh-Hant")){const n=[],r=e.metadata||{};r.edition&&n.push(String(r.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const o=s.volumeStats(e);return o&&o.expected>0&&n.push(o.missing>0?i("detail.volumeStatsMissing",{found:o.found,expected:o.expected,missing:o.missing}):i("detail.volumeStats",{found:o.found,expected:o.expected})),r.version&&n.push(String(r.version)),n.join(" · ")}function Pl(e,i){if(Kn(e)||i.filter(r=>r.name===e.name).length<2)return"";try{const r=new URL(e.url),o=r.searchParams.get("res")||r.searchParams.get("id");if(o)return o;const a=r.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}const Bu="同版";function Hu(e){const i=e==null?void 0:e.metadata;return((i==null?void 0:i.item_id)||(i==null?void 0:i.call_number)||"").trim()||void 0}function Du(e){for(const i of ti(e)){const n=i.ref??i.book_id;if(i.relation===Bu&&n&&n!==e.id)return n}}function Wu(e){const i=new Map(e.map(a=>[a.id,a])),n=a=>{const l=i.get(a);return!!l&&!l.copyOf},r=new Map;for(const a of e)if(a.copyOf&&n(a.copyOf)){const l=r.get(a.copyOf)??[];l.push(a),r.set(a.copyOf,l)}if(r.size===0)return e;const o=[];for(const a of e){if(a.copyOf&&n(a.copyOf))continue;const l=r.get(a.id);if(!l){o.push(a);continue}const d=[...l].sort((c,m)=>(c.callNumber??c.id).localeCompare(m.callNumber??m.id));o.push({...a,copies:d,hasImage:a.hasImage||d.some(c=>c.hasImage)})}return o}const Uu=["同卷","綴合"];function Ol(e){const i=new Map;for(const n of ti(e)){if(!Uu.includes(n.relation))continue;const r=n.ref??n.book_id;if(!r)continue;const o=i.get(n.relation)??[];o.includes(r)||o.push(r),i.set(n.relation,o)}return i.size?[...i].map(([n,r])=>({relation:n,ids:r})):void 0}const Zo=200;function Fl(e,i){const[n="",r=""]=(e.dating??"").split(/\s+/),o={id:e.id,title:e.title,edition:e.edition,...n?{dating:{era:n,reign:r}}:{}},a=ks(o,i);return{...a,sortYear:e.y??a.sortYear,year:e.y??a.year,locationName:e.holder||void 0,hasImage:!!e.img}}function Ku(e,i,n={}){var a;const r=new Map;for(const l of e){const d=l.coll?l.coll:!n.noHolderFallback&&l.holder?`h:${l.holder}`:"_none",c=l.coll&&((a=n.titles)==null?void 0:a[l.coll])||l.collt||(d==="_none"?"":l.holder)||l.coll||"";let m=r.get(d);m||(m={key:d,title:c,rows:[],total:0,imageCount:0},r.set(d,m)),m.total++;const p=Fl(l,i);m.rows.push(p),p.hasImage&&m.imageCount++}const o=[...r.values()];return[...o.filter(l=>l.key!=="_none"),...o.filter(l=>l.key==="_none")]}function ks(e,i){var a,l,d,c;const n=e.resources||[],r=[],o=[];for(const m of n){const p=s.getResourceTypes(m);p.includes("image")&&r.push(m),p.includes("physical")&&o.push(m)}return{id:e.id,name:e.edition||e.title||e.id,era:Ji(e),year:Un(e),sortYear:Mn(e),images:r,holders:o,locationName:((a=e.current_location)==null?void 0:a.name)||((d=(l=e.provenance)==null?void 0:l[0])==null?void 0:d.institution)||void 0,callNumber:Hu(o[0]),copyOf:Du(e),relations:Ol(e),summary:e.summary,important:Yu(e.id,i),group:(c=i==null?void 0:i.node_groups)==null?void 0:c[e.id],hasImage:r.length>0}}function Yu(e,i){var d,c;if(!i)return!1;const n=i.default_collection;if(!n)return!1;const r=(d=i.collections)==null?void 0:d[n];if(((r==null?void 0:r.book_ids)??(n==="core"?i.core_books??[]:[])).includes(e))return!0;const a=(r==null?void 0:r.groups)??[],l=(c=i.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function Bl(e,i,n={}){const r=new Set((i==null?void 0:i.excluded_books)??[]),o=Wu(e.filter(c=>!r.has(c.id)).map(c=>ks(c,i)));let a=o;n.era&&(a=a.filter(c=>c.era.era===n.era)),n.scanOnly&&(a=a.filter(c=>c.hasImage)),n.sort==="year"?a=a.map((c,m)=>({r:c,i:m})).sort((c,m)=>{const p=c.r.sortYear,h=m.r.sortYear;return p!=null&&h!=null?p-h||c.i-m.i:p!=null?-1:h!=null?1:c.i-m.i}).map(c=>c.r):a=a.map((c,m)=>({r:c,i:m})).sort((c,m)=>{const p=h=>(h.important?0:1)*2+(h.hasImage?0:1);return p(c.r)-p(m.r)||c.i-m.i}).map(c=>c.r);const d=[...new Set(o.map(c=>c.era.era).filter(Boolean))].sort((c,m)=>Yr(c)-Yr(m));return{rows:a,allRows:o,eras:d,hasInferredEra:o.some(c=>c.era.source==="edition")}}function Gu(e,i){var v,w;if(!i||!i.default_collection||!i.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const n=(v=i.collections)==null?void 0:v[i.default_collection],r=(n==null?void 0:n.groups)??[],o=(n==null?void 0:n.book_ids)??[],a=r.length>0||o.length>0,l=!a&&i.default_collection==="core"&&Array.isArray(i.core_books)?i.core_books:[];if(!a&&l.length===0)return{useGrouping:!1,coreIds:e,groupedIds:[]};const d=new Set(r),c=new Set([...o,...l]),m=x=>{if(c.has(x))return!0;const j=i.node_groups[x];return j!=null&&d.has(j)},p=[],h=new Map,u=[];for(const x of e)if(!((w=i.excluded_books)!=null&&w.includes(x)))if(m(x))p.push(x);else{const j=i.node_groups[x];j?(h.has(j)||h.set(j,[]),h.get(j).push(x)):u.push(x)}if(u.length+[...h.values()].reduce((x,j)=>x+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const g=new Map((i.groups??[]).map(x=>[x.id,x])),y=[...h.entries()].map(([x,j])=>{const S=g.get(x);return{id:x,label:(S==null?void 0:S.label)??x,description:S==null?void 0:S.description,ids:j}});return u.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:p,groupedIds:y}}const Hl=["撰","編","注","校","譯","繪","其他"],Vu=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function ws(e){if(!e||!e.trim())return"撰";const i=e.replace(/[\s-]/g,"");if(!i)return"撰";for(const{cls:n,re:r}of Vu)if(r.test(i))return n;return"其他"}function vs(e){if(!e)return"";const i=e.trim();return!i||!/[一-鿿]/.test(i)?"":i}function Dl(e,i="全部"){const n=new Map;for(const o of e){const a=ws(o);n.set(a,(n.get(a)??0)+1)}const r=[{cls:"全部",label:i,count:e.length}];for(const o of Hl){const a=n.get(o);a&&r.push({cls:o,label:o,count:a})}return r.length>2?r:[]}function Ss(e){return(e._books??[]).map(i=>i.id).filter(i=>typeof i=="string")}function $s(e){const i=e._classifications??[],n=i.find(r=>r.scheme==="zongmu")??i[0];if(n)return{l1:n.l1??"",l2:n.l2??"",l3:n.l3??"",l4:n.l4??"",...n.source?{source:n.source}:{}}}function Wl(e){const i=e._members??[],n=typeof e._member_count=="number"?e._member_count:i.length;return{works:i.filter(r=>r.t==="work").map(r=>({id:r.id,title:r.title??"",volumes:Wi(r.vol)})),bookIds:i.filter(r=>r.t!=="work").map(r=>r.id).filter(r=>typeof r=="string"),total:n,truncated:n>i.length}}function qu(e){var i;return(e==null?void 0:e._member_count)||((i=e==null?void 0:e._members)==null?void 0:i.length)||0}function Ul(e,i,n){if(i&&i.books&&i.books.length>0){const l=i.books.map(c=>({id:c.work_id||c.book_id||void 0,title:c.title,section:c.section,volumes:c.volumes||[],subItems:c.sub_items,edition:c.edition,found:c.found_volumes,expected:c.expected_volumes})),d=[...new Set(l.map(c=>c.section).filter(Boolean))];return{rows:l,source:"catalog",sections:d,totalVolumes:i.total_volumes}}const{works:r,bookIds:o}=Wl(e);return r.length>0?{rows:r.map(d=>({id:d.id,title:d.title,volumes:d.volumes})),source:"works",sections:[]}:{rows:o.map(l=>{var d,c;return{id:l,title:((d=n==null?void 0:n.get(l))==null?void 0:d.title)||l,edition:(c=n==null?void 0:n.get(l))==null?void 0:c.edition,volumes:[]}}),source:"books",sections:[]}}function Wi(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(i=>typeof i=="number");if(typeof e=="string"){const i=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(i){const[n,r]=[parseInt(i[1]),parseInt(i[2])];return Array.from({length:Math.max(0,r-n+1)},(o,a)=>n+a)}return e.split(/[,、]/).map(n=>parseInt(n.trim())).filter(n=>!isNaN(n))}return[]}function Yn(e,i="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=[...e].sort((a,l)=>a-l),r=n[0],o=n[n.length-1];return o-r+1===n.length?`${r}–${o}`:n.length<=3?n.join(", "):`${r}–${o} (${n.length}${i})`}const Xu=["poem","ci","qu","fu","article"];function Qo(e){return!!e&&Xu.includes(e)}function Gr(e){if(e==null||e==="")return"";if(Array.isArray(e)){const i=e.filter(r=>Number.isFinite(r));if(!i.length)return"";if(i.length===1)return String(i[0]);const n=[...i].sort((r,o)=>r-o);return n[n.length-1]-n[0]+1===n.length?`${n[0]}–${n[n.length-1]}`:n.join("、")}return String(e)}function Ju(e,i,n,r){const o=[],a=Gr(e);if(a&&o.push(r.vol.replace("{n}",a)),typeof i=="number"&&i>0){const l=n==="poem"||n==="ci"||n==="qu"?r.shou:r.pian;o.push(l.replace("{n}",String(i)))}return o.join(" · ")}const Zu=["〇","一","二","三","四","五","六","七","八","九"],ea=["","十","百","千"];function Gi(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return _r(e,!0);const i=Math.floor(e/1e4),n=e%1e4;let r=_r(i,!0)+"萬";return n>0&&(r+=(n<1e3?"〇":"")+_r(n,!1)),r}function _r(e,i){const n=String(e),r=n.length;let o="",a=!1;for(let l=0;l<r;l++){const d=parseInt(n[l]),c=r-1-l;d===0?a=!0:(a&&o&&(o+="〇"),a=!1,i&&d===1&&c===1&&l===0?o+=ea[c]:o+=Zu[d]+ea[c])}return o}function Qu(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function ep(e){if(e==null||typeof e=="string")return;const i="url"in e&&e.url?e.url:"type"in e&&e.type==="url"?e.details:void 0;return i&&/^https?:\/\//i.test(i)?i:void 0}function qt(e,i="卷"){var o,a;const n=e;if(n.measure_info)return n.measure_info;if((o=n.juan_count)!=null&&o.number)return Gi(n.juan_count.number)+i;if((a=n.juan_count)!=null&&a.description)return n.juan_count.description;const r=(n.measures??[]).filter(l=>l&&typeof l.number=="number"&&l.number>0&&l.unit);return r.length?r.map(l=>Gi(l.number)+(l.unit==="卷"?i:l.unit)).join(""):""}function Kl(e){if(e.edition_type)return e.edition_type;const i=e.edition||e.title||"",n=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/油印/,"油印本"],[/曬印|晒印/,"曬印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[r,o]of n)if(r.test(i))return o;return""}const Gn={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Yl=new Set(["work","book","entity"]);function tp(e){return ql(e)||!!e.sort}function ip(e,i){return i.sort&&Yl.has(e)?i.sort:void 0}const Vn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],qn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Gl=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Vl={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Xn(e){return e.dynasty.length+e.classification.length+(e.hasImage?1:0)+(e.hasText?1:0)+(e.hasCollated?1:0)+(e.loss?1:0)}function ql(e){return Xn(e)>0}function np(e){const i=[];return e.dynasty.length&&i.push("dynasty"),e.classification.length&&i.push("classification"),e.hasImage&&i.push("hasImage"),e.hasText&&i.push("hasText"),e.hasCollated&&i.push("hasCollated"),e.loss&&i.push("loss"),i}function Xl(e,i){const n=Vl[e];return np(i).every(r=>n.has(r))}const Ai=e=>JSON.stringify(e);function rp(e,i){if(!Xl(i,e))return null;const n=[];if(e.dynasty.length){const r=Array.from(new Set(e.dynasty.flatMap(o=>{var a;return((a=Vn.find(l=>l.key===o))==null?void 0:a.values)??[]})));r.length===1?n.push(`dynasty = ${Ai(r[0])}`):r.length>1&&n.push(`dynasty IN [${r.map(Ai).join(", ")}]`)}return e.classification.length&&n.push(e.classification.length===1?`classification = ${Ai(e.classification[0])}`:`classification IN [${e.classification.map(Ai).join(", ")}]`),e.hasImage&&n.push("has_image = true"),e.hasText&&n.push("has_text = true"),e.hasCollated&&n.push("has_collated = true"),e.loss&&n.push(`loss_status = ${Ai(e.loss)}`),n.join(" AND ")}const Nt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},Jl="_";function An(e,i=new URLSearchParams){for(const n of Object.values(Nt))i.delete(n);return e.dynasty.length&&i.set(Nt.dynasty,e.dynasty.join(",")),e.classification.length&&i.set(Nt.classification,e.classification.map(n=>n||Jl).join(",")),e.hasImage&&i.set(Nt.hasImage,"1"),e.hasText&&i.set(Nt.hasText,"1"),e.hasCollated&&i.set(Nt.hasCollated,"1"),e.loss&&i.set(Nt.loss,e.loss),e.sort&&i.set(Nt.sort,e.sort),i}function sp(e){const i=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),n=new Set(Vn.map(a=>a.key)),r=new Set(qn.map(a=>a.value)),o=e.get(Nt.loss);return{dynasty:Array.from(new Set(i(Nt.dynasty).filter(a=>n.has(a)))),classification:Array.from(new Set(i(Nt.classification).map(a=>a===Jl?"":a).filter(a=>r.has(a)))),hasImage:e.get(Nt.hasImage)==="1",hasText:e.get(Nt.hasText)==="1"||e.get(Nt.hasCollated)==="1",hasCollated:!1,loss:o==="extant"||o==="partially_extant"||o==="lost"?o:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(a=>a===e.get(Nt.sort))??""}}function op(e,i){return JSON.stringify([e.dynasty.slice().sort(),e.classification.slice().sort(),e.hasImage,e.hasText,e.hasCollated,e.loss,e.sort])===JSON.stringify([i.dynasty.slice().sort(),i.classification.slice().sort(),i.hasImage,i.hasText,i.hasCollated,i.loss,i.sort])}function ta(e,i){return e.includes(i)?e.filter(n=>n!==i):[...e,i]}const ap=({filters:e,onChange:i})=>{const n=s.useT(),r=n.searchV4,{convert:o}=xt(),[a,l]=b.useState(!1),d=b.useId(),c=Xn(e),m=p=>i({...e,...p});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":o(r.filterTitle),children:[t.jsxs("button",{type:"button",className:"bim-sr-fbtn","aria-expanded":a,"aria-controls":d,onClick:()=>l(p=>!p),children:[t.jsxs("span",{children:[o(r.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:o(s.formatTemplate(r.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[o(a?r.collapse:r.expand)," ",a?"▴":"▾"]})]}),t.jsxs("div",{className:"bim-sr-filters",id:d,"data-open":a?"true":"false",...a?{}:{"data-collapsed":"true"},children:[t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(r.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:Vn.map(p=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(p.key),onClick:()=>m({dynasty:ta(e.dynasty,p.key)}),children:o(p.key)},p.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(r.classification)}),qn.map(p=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(p.value),onChange:()=>m({classification:ta(e.classification,p.value)})}),p.value?o(p.label):n.searchPage.unclassified]},p.value||"_"))]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(r.resources)}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasImage,onChange:p=>m({hasImage:p.target.checked})}),o(r.hasImage)]}),t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.hasText,onChange:p=>m({hasText:p.target.checked})}),o(r.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:o(r.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:Gl.map(p=>t.jsx("button",{type:"button","aria-pressed":e.loss===p.value,onClick:()=>m({loss:p.value}),children:n.searchPage.loss[p.value||"all"]},p.value||"all"))})]}),c>0&&t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>i({...Gn,sort:e.sort}),children:o(r.clearAllFilters)})]})]})};function Zl({text:e,query:i}){const n=(i??"").trim();if(!n||!e)return t.jsx(t.Fragment,{children:e});const r=e.toLowerCase(),o=n.toLowerCase(),a=[];let l=0,d=0;for(;l<e.length;){const c=r.indexOf(o,l);if(c<0){a.push(e.slice(l));break}c>l&&a.push(e.slice(l,c)),a.push(t.jsx("mark",{className:"bim-sr-hl",children:e.slice(c,c+o.length)},d++)),l=c+o.length}return t.jsx(t.Fragment,{children:a})}const ia=({entries:e,query:i,onEntryLinkClick:n,typeName:r})=>{const o=s.useT(),a=o.searchV4,{convert:l}=xt(),d=It();return t.jsx("div",{className:"bim-sr-tablewrap",children:t.jsxs("table",{className:"bim-sr-table",children:[t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"34%"}}),t.jsx("col",{style:{width:"8%"}}),t.jsx("col",{style:{width:"19%"}}),t.jsx("col",{style:{width:"13%"}}),t.jsx("col",{style:{width:"12%"}}),t.jsx("col",{style:{width:"14%"}})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:l(a.colTitle)}),t.jsx("th",{scope:"col",children:l(a.colType)}),t.jsx("th",{scope:"col",children:l(a.colAuthor)}),t.jsx("th",{scope:"col",children:l(a.colEra)}),t.jsx("th",{scope:"col",children:l(a.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:l(a.colResource)})]})}),t.jsx("tbody",{children:e.map(c=>{const m=l(c.title||c.primary_name||c.id),p=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${o.unit.juan}`:"",h=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${l(c.author)}${c.role&&c.role!=="author"?` ${l(c.role)}`:""}`:"",u=c.type==="book"?c.era??c.dynasty:c.dynasty,f=u?l(u):"",g=c.classification?l(c.classification):"",y=[];c.has_image&&y.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&y.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&y.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const v=[h,f,g].filter(Boolean).join(" · ");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-sr-c-title",children:[t.jsxs("div",{className:"bim-sr-tl",children:[t.jsx("a",{href:d(c.id),onClick:w=>n(c,w),children:t.jsx(Zl,{text:m,query:i?l(i):void 0})}),p&&t.jsx("span",{className:"bim-sr-measure",children:p})]}),v&&t.jsx("span",{className:"bim-sr-sub",children:v})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Xi,{type:c.type,size:6})," ",r(c.type)]}),t.jsx("td",{className:"bim-sr-c-who",children:h||"—"}),t.jsx("td",{className:"bim-sr-c-era",children:f||"—"}),t.jsx("td",{className:"bim-sr-c-cls",children:g||"—"}),t.jsx("td",{className:"bim-sr-c-res",children:y.map(w=>t.jsx("span",{className:`bim-sr-tag ${w.cls}`,children:l(w.label)},w.label))})]},c.id)})})]})})},lp=`
|
|
2
2
|
.bim-sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; }
|
|
3
3
|
.bim-sc { display: flex; flex-direction: column; min-width: 0; padding: 14px 16px 12px; border: 1px solid ${s.bim("rule")}; background: ${s.bim("card-bg")}; color: inherit; text-decoration: none; }
|
|
4
4
|
.bim-sc:hover { border-color: ${s.bim("rule-dashed")}; box-shadow: ${s.bim("fr-shadow")}; }
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
.bim-sc-fl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: ${s.bim("aux-fg")}; }
|
|
13
13
|
.bim-sc-tags { display: flex; gap: 4px; flex: none; }
|
|
14
14
|
:root[data-layout="boxed"] .bim-sc { box-shadow: none; }
|
|
15
|
-
`,na=({entries:e,query:i,onEntryLinkClick:n,typeName:r})=>{const o=s.useT(),a=o.searchV4,{convert:l}=xt(),d=It();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:
|
|
15
|
+
`,na=({entries:e,query:i,onEntryLinkClick:n,typeName:r})=>{const o=s.useT(),a=o.searchV4,{convert:l}=xt(),d=It();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:lp}),e.map(c=>{const m=l(c.title||c.primary_name||c.id),p=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${o.unit.juan}`:"",u=[c.type==="entity"?c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:"":`${c.dynasty?`〔${l(c.dynasty)}〕`:""}${c.author?l(c.author):""}`,c.type==="book"&&c.edition?l(c.edition):"",p].filter(Boolean).join(" · "),f=[r(c.type),c.classification?l(c.classification):""].filter(Boolean).join(" · "),g=[];return c.has_image&&g.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&g.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&g.push({label:a.tagLost,cls:"bim-sr-tag--lost"}),t.jsxs("a",{className:"bim-sc",href:d(c.id),onClick:y=>n(c,y),children:[t.jsx("span",{className:"bim-sc-t",children:t.jsx(Zl,{text:m,query:i?l(i):void 0})}),u&&t.jsx("span",{className:"bim-sc-m",children:u}),c.descriptionSnippet&&t.jsx("p",{className:"bim-sc-s",children:gs(c.descriptionSnippet).map((y,v)=>y.marked?t.jsx("mark",{children:l(y.text)},v):t.jsx(b.Fragment,{children:l(y.text)},v))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:f}),t.jsx("span",{className:"bim-sc-tags",children:g.map(y=>t.jsx("span",{className:`bim-sr-tag ${y.cls}`,children:l(y.label)},y.label))})]})]},c.id)})]})};function cp(e,i){const n=new Set([1,i,e-1,e,e+1].filter(a=>a>=1&&a<=i)),r=Array.from(n).sort((a,l)=>a-l),o=[];return r.forEach((a,l)=>{l>0&&a-r[l-1]>1&&o.push("gap"),o.push(a)}),o}function dp(e,i,n){const r=Math.max(1,Math.ceil(i/n));return Math.min(Math.max(1,e),r)}const mp=({page:e,pageSize:i,total:n,totalLabel:r,onPage:o})=>{const a=s.useT().searchV4,{convert:l}=xt(),d=Math.max(1,Math.ceil(n/i));return n<=0?null:t.jsxs("nav",{className:"bim-sr-pager","aria-label":l(a.pagerLabel),children:[t.jsx("span",{className:"bim-sr-info",children:l(s.formatTemplate(a.pageInfo,{total:r??n.toLocaleString(),size:i,page:e,pages:d}))}),d>1&&t.jsxs("ul",{children:[t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e<=1,onClick:()=>o(e-1),children:l(a.prevPage)})}),cp(e,d).map((c,m)=>c==="gap"?t.jsx("li",{className:"bim-sr-gap","aria-hidden":"true",children:"…"},`g${m}`):t.jsx("li",{children:t.jsx("button",{type:"button","aria-current":c===e?"page":void 0,"aria-label":`${c}`,onClick:()=>o(c),children:c})},c)),t.jsx("li",{children:t.jsx("button",{type:"button",disabled:e>=d,onClick:()=>o(e+1),children:l(a.nextPage)})})]})]})},Ql="(max-width: 719px)",up=`${Ql}, (pointer: coarse)`,pp=`
|
|
16
16
|
.bim-sr-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; align-items: start; padding: 0 ${s.bim("browser-pad-x")}; }
|
|
17
17
|
.bim-sr-layout[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
|
|
18
18
|
.bim-sr-aside { position: sticky; top: calc(${s.bim("reader-top")} + 16px); padding-top: 2px; }
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
.bim-sr-pager .bim-sr-gap { color: ${s.bim("aux-fg")}; padding: 0 2px; }
|
|
82
82
|
.bim-sr-empty { padding: 60px 0; text-align: center; font-size: 14px; color: ${s.bim("meta-fg")}; }
|
|
83
83
|
|
|
84
|
-
@media ${
|
|
84
|
+
@media ${Ql} {
|
|
85
85
|
.bim-sr-layout { grid-template-columns: minmax(0, 1fr); row-gap: 16px; padding: 0 min(${s.bim("browser-pad-x")}, 16px); }
|
|
86
86
|
.bim-sr-aside { position: static; }
|
|
87
87
|
.bim-sr-fbtn {
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
.bim-sr-table td.bim-sr-c-res { text-align: left; padding-bottom: 2px; }
|
|
103
103
|
.bim-sr-table td.bim-sr-c-res:empty { display: none; }
|
|
104
104
|
}
|
|
105
|
-
@media ${
|
|
105
|
+
@media ${up} {
|
|
106
106
|
.bim-sr-chip { min-height: 36px; }
|
|
107
107
|
.bim-sr-opt { min-height: 44px; }
|
|
108
108
|
.bim-sr-seg button { min-height: 44px; }
|
|
@@ -117,10 +117,10 @@
|
|
|
117
117
|
:root[data-layout="boxed"] .bim-sr-table th { background: ${s.bim("fr-bg")}; }
|
|
118
118
|
/* 墨:主色与正文对比不到 3:1,标题链接另加下划线 */
|
|
119
119
|
:root[data-theme="ink"] .bim-sr-table td.bim-sr-c-title a { text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 3px; }
|
|
120
|
-
`,_s="bim-search-view",Nr=50,ra=5,Ui=1e3;function $n(e){return e>=Ui?`${Ui.toLocaleString()}+`:e.toLocaleString()}const up={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function pp(e){return e&&up[e.toLowerCase()]||"all"}function bp(e){return e==="all"?null:e}const sa=["work","collection","book","entity"],hp={work:"works",collection:"collections",book:"books",entity:"entities"},fp={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function gp(){try{return window.localStorage.getItem(_s)==="card"?"card":"table"}catch{return"table"}}function xp(e){try{window.localStorage.setItem(_s,e)}catch{}}const gi=(e,i)=>(e==null?void 0:e[fp[i]])??0,zr=(e,i)=>(e==null?void 0:e[hp[i]])??[],Zl=({transport:e,query:i,filters:n,onFiltersChange:r,onEntryLinkClick:o,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:m})=>{const p=s.useT(),h=p.searchV4,{convert:u}=xt(),f=!!e.supportsSearchFilters,g=b.useMemo(()=>f?n:Gn,[f,n]),[y,v]=b.useState("table");b.useEffect(()=>{v(gp())},[]);const w=B=>{v(B),xp(B)},[x,j]=b.useState(l??"all"),S=b.useRef(x);S.current=x,b.useEffect(()=>{l!==void 0&&l!==S.current&&(j(l),N(1))},[l]);const[$,N]=b.useState(c&&c>0?c:1),z=b.useRef($);z.current=$,b.useEffect(()=>{c!==void 0&&c>0&&c!==z.current&&N(c)},[c]);const C=b.useRef(null),U=b.useCallback(B=>{var Te;N(B),m==null||m(B);const pe=C.current;pe&&pe.getBoundingClientRect().top<0&&((Te=pe.scrollIntoView)==null||Te.call(pe,{block:"start",behavior:"instant"}))},[m]),[R,L]=b.useState(null),[F,T]=b.useState(null),[Z,O]=b.useState(!1),[ae,ce]=b.useState(""),Ee=An(g).toString(),we=Xn(g)>0,ye=An({...g,sort:""}).toString(),Q=b.useRef({query:i,filterOnlyKey:ye,sort:g.sort});b.useEffect(()=>{const B=Q.current;B.query!==i||B.filterOnlyKey!==ye?(j("all"),N(1)):B.sort!==g.sort&&N(1),Q.current={query:i,filterOnlyKey:ye,sort:g.sort}},[i,ye,g.sort]),b.useEffect(()=>{let B=!1;return O(!0),ce(""),(async()=>{try{let pe;if(e.searchAll)pe=await e.searchAll(i,ra,g);else{const Te=["work","book","collection","entity"],ve=await Promise.all(Te.map(Ve=>e.search(i,Ve,{page:1,pageSize:ra,filters:g})));pe={works:ve[0].entries,books:ve[1].entries,collections:ve[2].entries,entities:ve[3].entries,totalWorks:ve[0].total,totalBooks:ve[1].total,totalCollections:ve[2].total,totalEntities:ve[3].total}}B||L(pe)}catch(pe){B||(ce(pe instanceof Error?pe.message:String(pe)),L(null))}finally{B||O(!1)}})(),()=>{B=!0}},[e,i,Ee]);const Ne=x;b.useEffect(()=>{if(x==="all"){T(null);return}let B=!1;return O(!0),(async()=>{try{const pe=await e.search(i,x,{page:$,pageSize:Nr,filters:g});B||T({key:Ne,entries:pe.entries,total:pe.total})}catch(pe){B||(ce(pe instanceof Error?pe.message:String(pe)),T(null))}finally{B||O(!1)}})(),()=>{B=!0}},[e,i,Ee,x,$]);const W=F&&F.key===Ne?F:null;b.useEffect(()=>{if(x==="all"||!W||Z)return;const B=Math.min(W.total,Ui),pe=lp($,B,Nr);W.entries.length===0&&B>0&&pe!==$&&(N(pe),m==null||m(pe))},[x,W,Z,$]);const je=b.useMemo(()=>sa.filter(B=>gi(R,B)>0),[R]),K=je.reduce((B,pe)=>B+gi(R,pe),0),V=je.some(B=>gi(R,B)>=Ui)?`${K.toLocaleString()}+`:K.toLocaleString(),re=!Z&&!ae&&R!==null&&K===0,X=b.useCallback(B=>{j(B),N(1),d==null||d(B)},[d]),I=b.useMemo(()=>{const B=[];return g.dynasty.forEach(pe=>B.push({name:pe,remove:()=>r({...g,dynasty:g.dynasty.filter(Te=>Te!==pe)})})),g.classification.forEach(pe=>{var Te;return B.push({name:pe?((Te=qn.find(ve=>ve.value===pe))==null?void 0:Te.label)??pe:p.searchPage.unclassified,remove:()=>r({...g,classification:g.classification.filter(ve=>ve!==pe)})})}),g.hasImage&&B.push({name:h.hasImage,remove:()=>r({...g,hasImage:!1})}),g.hasText&&B.push({name:h.hasText,remove:()=>r({...g,hasText:!1})}),g.hasCollated&&B.push({name:h.hasCollated,remove:()=>r({...g,hasCollated:!1})}),g.loss&&B.push({name:`${h.extant}:${p.searchPage.loss[g.loss]}`,remove:()=>r({...g,loss:""})}),B},[g,r,h,p]),ue={query:i,onEntryLinkClick:o,typeName:a},fe=B=>y==="table"?t.jsx(ia,{entries:B,...ue}):t.jsx(na,{entries:B,...ue}),ze=sa.flatMap(B=>zr(R,B));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:mp}),f&&t.jsx(sp,{filters:g,onChange:r}),t.jsxs("div",{className:"bim-sr-main","aria-busy":Z,ref:C,children:[je.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":p.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${s.bim("rule")}`},children:[t.jsxs(oa,{on:x==="all",onClick:()=>X("all"),children:[p.search.allTab," ",t.jsx("small",{children:V})]}),je.map(B=>t.jsxs(oa,{on:x===B,onClick:()=>X(B),children:[a(B)," ",t.jsx("small",{children:$n(gi(R,B))})]},B))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":u(h.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!g.sort,onClick:()=>r({...g,sort:""}),children:u(h.sortRelevance)}),["era","title"].map(B=>{const pe=g.sort.startsWith(`${B}:`)?g.sort.endsWith("desc")?"desc":"asc":null,Te=B==="era"?h.sortEra:h.sortTitle,ve=B==="era"?pe==="desc"?h.sortEraDesc:h.sortEraAsc:pe==="desc"?h.sortTitleDesc:h.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":pe!==null,title:u(ve),onClick:()=>r({...g,sort:`${B}:${pe==="asc"?"desc":"asc"}`}),children:[u(Te),pe?t.jsxs("span",{"aria-hidden":"true",children:[" ",pe==="asc"?"↑":"↓"]}):null]},B)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":u(h.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":y==="table",onClick:()=>w("table"),children:u(h.viewTable)}),t.jsx("button",{type:"button","aria-pressed":y==="card",onClick:()=>w("card"),children:u(h.viewCard)})]})]}),we&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:u(s.formatTemplate(h.filteredCount,{n:V}))}),I.map(B=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u(s.formatTemplate(h.removeFilter,{name:B.name})),onClick:B.remove,children:[u(B.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},B.name))]}),ae&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:ae}),re&&t.jsx("div",{className:"bim-sr-empty",children:u(we?h.emptyFiltered:s.formatTemplate(p.search.noResultsFor,{query:i}))}),!ae&&!re&&x==="all"&&R&&(y==="table"?t.jsxs(t.Fragment,{children:[t.jsx(ia,{entries:ze,...ue}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(h.limitedNote)})]}):t.jsx(t.Fragment,{children:je.map(B=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xi,{type:B,size:8}),a(B),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:s.bim("meta-fg")},children:[$n(gi(R,B))," ",p.unit.items]})]}),gi(R,B)>zr(R,B).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>X(B),children:p.action.viewAll})]}),t.jsx(na,{entries:zr(R,B),...ue})]},B))})),!ae&&x!=="all"&&!W&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:p.search.loading}),!ae&&x!=="all"&&W&&W.entries.length>0&&t.jsxs(t.Fragment,{children:[fe(W.entries),t.jsx(cp,{page:$,pageSize:Nr,total:Math.min(W.total,Ui),totalLabel:$n(W.total),onPage:U})]}),!ae&&x!=="all"&&W&&W.entries.length===0&&!Z&&t.jsxs("div",{className:"bim-sr-empty",children:[u(we?h.emptyFiltered:s.formatTemplate(p.search.noResultsFor,{query:i})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>X("all"),children:p.search.allTab})})]})]})]})};function oa({on:e,onClick:i,children:n}){return t.jsx("button",{type:"button","aria-pressed":e,onClick:i,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:e?s.bim("ink"):s.bim("meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${s.bim("accent")}`:"none"},children:n})}const _i="bim-recent-ids",aa="bim-recent-entries",la=50;function ei(){try{const e=localStorage.getItem(_i);if(e)return JSON.parse(e);const i=localStorage.getItem(aa);if(i){const n=JSON.parse(i).map(r=>r.id);return localStorage.setItem(_i,JSON.stringify(n)),localStorage.removeItem(aa),n}return[]}catch{return[]}}function Vr(e){try{const i=ei().filter(n=>n!==e);i.unshift(e),i.length>la&&(i.length=la),localStorage.setItem(_i,JSON.stringify(i))}catch{}}function Ql(e){try{const i=ei().filter(n=>n!==e);localStorage.setItem(_i,JSON.stringify(i))}catch{}}function Ns(){try{localStorage.removeItem(_i)}catch{}}async function zs(e,i){var n,r,o;try{if(e.getEntry){const l=await e.getEntry(i);if(l)return l}const a=await e.getItem(i);if(a){const l=a.authors;return{id:i,title:a.title||i,type:a.type||"work",author:(n=l==null?void 0:l[0])==null?void 0:n.name,dynasty:(r=l==null?void 0:l[0])==null?void 0:r.dynasty,role:(o=l==null?void 0:l[0])==null?void 0:o.role,edition:a.edition||void 0}}}catch{}return{id:i,title:i,type:"work",notFound:!0}}const Cr=5,yp=50,jp=200,ca={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},kp=({transport:e,indexSource:i="local",syncConfig:n,onEntryClick:r,onNewEntry:o,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:m,resultVariant:p="compact",renderEntry:h,initialQuery:u,onQueryChange:f,headerRight:g,reserveViewportHeight:y=!1,filtersEnabled:v=!1,filters:w=Gn,onFiltersChange:x,resultTab:j,onResultTabChange:S,resultPage:$,onResultPageChange:N})=>{const z=s.useT(),C=[{type:"work",name:z.indexType.work,key:"works"},{type:"book",name:z.indexType.book,key:"books"},{type:"collection",name:z.indexType.collection,key:"collections"},{type:"entity",name:z.indexType.entity,key:"entities"}],U=["work","collection","book","entity"],[R,L]=b.useState(u??""),[F,T]=b.useState(null),[Z,O]=b.useState(u??""),ae=An(w).toString(),[ce,Ee]=b.useState(w);b.useEffect(()=>{Ee(w)},[ae]);const we=H=>{Ee(H),x==null||x(H)},[ye,Q]=b.useState(null),[Ne,W]=b.useState("all"),[je,K]=b.useState(!1),[V,re]=b.useState(null),[X,I]=b.useState(""),[ue,fe]=b.useState(!(u!=null&&u.trim())),[ze,B]=b.useState(ei),[pe,Te]=b.useState([]),[ve,Ve]=b.useState(!1),[qe,Xe]=b.useState(!1),[J,ie]=b.useState(null),[me,se]=b.useState(null),de=b.useRef(void 0),ge=b.useRef(!1),Oe=b.useCallback(async(H,he)=>{if(!H.trim()){fe(!0),T(null),Q(null);return}if(fe(!1),v){O(H);return}K(!0),I("");try{if(e.searchAll){const xe=await e.searchAll(H,he??Cr);T(xe)}else{const xe=["work","book","collection","entity"],Re=await Promise.all(xe.map(Ze=>e.search(H,Ze,{page:1,pageSize:he??Cr})));T({works:Re[0].entries,books:Re[1].entries,collections:Re[2].entries,entities:Re[3].entries,totalWorks:Re[0].total,totalBooks:Re[1].total,totalCollections:Re[2].total,totalEntities:Re[3].total})}}catch(xe){I(xe instanceof Error?xe.message:String(xe)),T(null)}finally{K(!1)}},[e,v]);b.useEffect(()=>{let H=!1;const he=()=>{var He,ct;const xe=["work","book","collection","entity"],Re=Promise.all(xe.map(Be=>e.loadEntries(Be,{page:1,pageSize:1}).catch(()=>({total:0})))),Ze=((He=e.getResourceCounts)==null?void 0:He.call(e).catch(()=>null))??Promise.resolve(null),Me=((ct=e.getSubtypeStats)==null?void 0:ct.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Re,Ze,Me]).then(([Be,ee,Se])=>{H||(ie({works:Be[0].total,books:Be[1].total,collections:Be[2].total,entities:Be[3].total,hasText:ee==null?void 0:ee.hasText,hasImage:ee==null?void 0:ee.hasImage}),Se&&se(Se))})};return e.getCounts?e.getCounts().then(xe=>{var Re,Ze;H||(ie({works:xe.works,books:xe.books,collections:xe.collections,entities:xe.entities,hasText:(Re=xe.resourceCounts)==null?void 0:Re.hasText,hasImage:(Ze=xe.resourceCounts)==null?void 0:Ze.hasImage}),xe.subtypeStats&&se(xe.subtypeStats))}).catch(()=>{H||he()}):he(),()=>{H=!0}},[e]),b.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Oe(u))},[u,Oe]);const Je=b.useCallback(H=>{if(L(H),!H.trim()){f==null||f(H),fe(!0),T(null),Q(null),W("all");return}de.current&&clearTimeout(de.current),de.current=setTimeout(()=>{Q(null),W("all"),f==null||f(H),Oe(H)},jp)},[Oe,f]),Pe=b.useCallback(H=>{de.current&&clearTimeout(de.current),W("all"),f==null||f(H),Oe(H)},[Oe,f]),Ue=b.useCallback(H=>{Q(H),Oe(R,yp)},[R,Oe]);b.useEffect(()=>{if(!ze.length){Te([]);return}let H=!1;return Ve(!0),Promise.all(ze.slice(0,10).map(he=>zs(e,he))).then(he=>{H||(Te(he),Ve(!1))}),()=>{H=!0}},[ze,e]);const nt=H=>{re(H.id),Vr(H.id),B(ei()),r==null||r(H)},Y=(H,he)=>{if(r&&vp(he)){he.preventDefault(),nt(H);return}Vr(H.id),B(ei())},M=H=>{Ql(H),B(ei())},k=()=>{Ns(),B([])},P=H=>C.find(he=>he.type===H),q=!ue&&!F&&!X,_=F&&(F.works.length>0||F.books.length>0||F.collections.length>0),le=t.jsxs(t.Fragment,{children:[t.jsx(El,{transport:e,value:R,onChange:Je,onSearch:Pe,onEntrySelect:nt}),v&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const H=R.trim();H&&Cl(H),Pe(R)},children:z.searchPage.submit}),o&&t.jsx("button",{onClick:()=>o("work"),style:{padding:"8px 14px",border:`1px solid ${s.bim("primary")}`,borderRadius:"6px",background:"transparent",color:s.bim("primary"),cursor:"pointer",fontSize:"13px"},children:z.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:y?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:Sp+(v?$p:"")}),(!v||g||!m)&&t.jsx("header",{style:{padding:`12px ${s.bim("browser-pad-x")}`,borderBottom:`1px solid ${s.bim("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:s.bim("fg")},children:z.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!m&&t.jsx(zl,{variant:"index-browser",indexSource:i,syncConfig:n,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),v?t.jsxs("div",{className:"bim-ib-bar","data-nofilters":e.supportsSearchFilters?void 0:"true",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("div",{className:"bim-ib-bar-main",children:le})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:`12px ${s.bim("browser-pad-x")}`,alignItems:"center"},children:le}),ue&&t.jsx("div",{className:"bim-ib-stats",style:{padding:`0 ${s.bim("browser-pad-x")} 8px`,fontSize:"12px",color:s.bim("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:J&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:me?t.jsxs(t.Fragment,{children:[(me.book??0)>0&&t.jsxs(t.Fragment,{children:[z.searchPage.statBook," ",t.jsx("strong",{style:{color:s.bim("fg")},children:me.book.toLocaleString()})," ",z.unit.bu,z.searchPage.statComma,t.jsx("strong",{style:{color:s.bim("fg")},children:J.books.toLocaleString()})," ",z.searchPage.statBookCopies]}),me.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statArticle," ",t.jsx("strong",{style:{color:s.bim("fg")},children:me.article.toLocaleString()})," ",z.searchPage.statArticleUnit]}):null,me.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statPoem," ",t.jsx("strong",{style:{color:s.bim("fg")},children:me.poem.toLocaleString()})," ",z.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statCollection," ",t.jsx("strong",{style:{color:s.bim("fg")},children:J.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[z.indexType.work," ",t.jsx("strong",{style:{color:s.bim("fg")},children:J.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.book," ",t.jsx("strong",{style:{color:s.bim("fg")},children:J.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.collection," ",t.jsx("strong",{style:{color:s.bim("fg")},children:J.collections.toLocaleString()}),J.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.entity," ",t.jsx("strong",{style:{color:s.bim("fg")},children:J.entities.toLocaleString()})]})]})}),J.hasImage!=null&&J.hasText!=null&&t.jsxs("span",{children:[z.resourceType.image," ",t.jsx("strong",{style:{color:s.bim("fg")},children:J.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.resourceType.text," ",t.jsx("strong",{style:{color:s.bim("fg")},children:J.hasText.toLocaleString()})]})]})}),v&&!ue&&t.jsx(Zl,{transport:e,query:Z,filters:ce,onFiltersChange:we,onEntryLinkClick:Y,typeName:H=>P(H).name,tab:j,onTabChange:S,page:$,onPageChange:N}),!(v&&!ue)&&t.jsx("div",{style:{padding:`0 ${s.bim("browser-pad-x")} 20px`,flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:je||q?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:s.bim("desc-fg"),minHeight:wp,boxSizing:"border-box"},children:z.search.searching}):X?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:s.bim("desc-fg")},children:X})}):ue?t.jsx("div",{style:{flex:1},children:ve?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:s.bim("desc-fg")},children:z.search.loading}):pe.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:s.bim("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:z.search.recentBrowse}),t.jsx("button",{onClick:k,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:z.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:pe.slice(0,qe?10:3).map(H=>H.notFound?t.jsx(Cp,{id:H.id,onRemove:M,t:z},H.id):t.jsx(da,{entry:H,selected:V===H.id,onClick:Y,getConfig:P,onRemove:M},H.id))}),!qe&&pe.length>3&&t.jsx("button",{onClick:()=>Xe(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:s.bim("primary"),background:"transparent",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:z.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:s.bim("fg")},children:z.search.searchTitle}),t.jsx("p",{style:{color:s.bim("desc-fg"),fontSize:"13px"},children:z.search.searchSubtitle})]})}):_?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:_p}),(()=>{const H=Me=>F[ca[Me]]??0,he=U.map(Me=>C.find(He=>He.type===Me)).filter(Me=>H(Me.key)>0);if(he.length<2)return null;const xe=he.reduce((Me,He)=>Me+H(He.key),0),Re=Me=>{if(W(Me),Me!=="all"&&ye!==Me){const He=C.find(Be=>Be.type===Me),ct=(F[He.key]??[]).length;H(He.key)>ct&&Ue(Me)}},Ze=Me=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:Me?s.bim("fg"):s.bim("desc-fg"),fontWeight:Me?700:400,boxShadow:Me?`inset 0 -2px 0 ${s.bim("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":z.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${s.bim("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":Ne==="all",style:Ze(Ne==="all"),onClick:()=>Re("all"),children:[z.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:xe.toLocaleString()})]}),he.map(Me=>t.jsxs("button",{type:"button","aria-pressed":Ne===Me.type,style:Ze(Ne===Me.type),onClick:()=>Re(Me.type),children:[Me.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:H(Me.key).toLocaleString()})]},Me.type))]})})(),C.map(({type:H,name:he,key:xe})=>{const Re=F[xe]??[],Ze=ca[xe],Me=F[Ze]??0;if(Re.length===0||Ne!=="all"&&Ne!==H)return null;const ct=Ne==="all"&&!(ye===H)&&Me>Cr;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${s.bim("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:s.bim("fg")},children:[t.jsx(Xi,{type:H})," ",he,t.jsxs("span",{style:{fontWeight:400,color:s.bim("desc-fg"),marginLeft:"6px"},children:[Me," ",z.unit.items]})]}),ct&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>Ue(H),style:{border:"none",background:"transparent",color:s.bim("primary"),cursor:"pointer",fontSize:"12px"},children:z.action.viewAll})]}),t.jsx("div",{style:p==="list"?{display:"flex",flexDirection:"column",gap:0}:p==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Re.map(Be=>{if(h)return t.jsx(b.Fragment,{children:h(Be)},Be.id);const ee=p==="card"?zp:da;return t.jsx(ee,{entry:Be,selected:V===Be.id,onClick:Y,getConfig:P,query:R},Be.id)})})]},H)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:s.bim("fg")},children:s.formatTemplate(z.search.noResultsFor,{query:R})}),t.jsx("p",{style:{color:s.bim("desc-fg"),fontSize:"13px"},children:z.search.tryOther})]})})]})},wp=240;function vp(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const Sp=`
|
|
120
|
+
`,_s="bim-search-view",Nr=50,ra=5,Ui=1e3;function $n(e){return e>=Ui?`${Ui.toLocaleString()}+`:e.toLocaleString()}const bp={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function hp(e){return e&&bp[e.toLowerCase()]||"all"}function fp(e){return e==="all"?null:e}const sa=["work","collection","book","entity"],gp={work:"works",collection:"collections",book:"books",entity:"entities"},xp={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function yp(){try{return window.localStorage.getItem(_s)==="card"?"card":"table"}catch{return"table"}}function jp(e){try{window.localStorage.setItem(_s,e)}catch{}}const gi=(e,i)=>(e==null?void 0:e[xp[i]])??0,zr=(e,i)=>(e==null?void 0:e[gp[i]])??[],ec=({transport:e,query:i,filters:n,onFiltersChange:r,onEntryLinkClick:o,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:m})=>{const p=s.useT(),h=p.searchV4,{convert:u}=xt(),f=!!e.supportsSearchFilters,g=b.useMemo(()=>f?n:Gn,[f,n]),[y,v]=b.useState("table");b.useEffect(()=>{v(yp())},[]);const w=B=>{v(B),jp(B)},[x,j]=b.useState(l??"all"),S=b.useRef(x);S.current=x,b.useEffect(()=>{l!==void 0&&l!==S.current&&(j(l),N(1))},[l]);const[$,N]=b.useState(c&&c>0?c:1),z=b.useRef($);z.current=$,b.useEffect(()=>{c!==void 0&&c>0&&c!==z.current&&N(c)},[c]);const C=b.useRef(null),U=b.useCallback(B=>{var Te;N(B),m==null||m(B);const pe=C.current;pe&&pe.getBoundingClientRect().top<0&&((Te=pe.scrollIntoView)==null||Te.call(pe,{block:"start",behavior:"instant"}))},[m]),[R,L]=b.useState(null),[F,T]=b.useState(null),[Z,O]=b.useState(!1),[ae,ce]=b.useState(""),Ee=An(g).toString(),we=Xn(g)>0,ye=An({...g,sort:""}).toString(),Q=b.useRef({query:i,filterOnlyKey:ye,sort:g.sort});b.useEffect(()=>{const B=Q.current;B.query!==i||B.filterOnlyKey!==ye?(j("all"),N(1)):B.sort!==g.sort&&N(1),Q.current={query:i,filterOnlyKey:ye,sort:g.sort}},[i,ye,g.sort]),b.useEffect(()=>{let B=!1;return O(!0),ce(""),(async()=>{try{let pe;if(e.searchAll)pe=await e.searchAll(i,ra,g);else{const Te=["work","book","collection","entity"],ve=await Promise.all(Te.map(Ve=>e.search(i,Ve,{page:1,pageSize:ra,filters:g})));pe={works:ve[0].entries,books:ve[1].entries,collections:ve[2].entries,entities:ve[3].entries,totalWorks:ve[0].total,totalBooks:ve[1].total,totalCollections:ve[2].total,totalEntities:ve[3].total}}B||L(pe)}catch(pe){B||(ce(pe instanceof Error?pe.message:String(pe)),L(null))}finally{B||O(!1)}})(),()=>{B=!0}},[e,i,Ee]);const Ne=x;b.useEffect(()=>{if(x==="all"){T(null);return}let B=!1;return O(!0),(async()=>{try{const pe=await e.search(i,x,{page:$,pageSize:Nr,filters:g});B||T({key:Ne,entries:pe.entries,total:pe.total})}catch(pe){B||(ce(pe instanceof Error?pe.message:String(pe)),T(null))}finally{B||O(!1)}})(),()=>{B=!0}},[e,i,Ee,x,$]);const W=F&&F.key===Ne?F:null;b.useEffect(()=>{if(x==="all"||!W||Z)return;const B=Math.min(W.total,Ui),pe=dp($,B,Nr);W.entries.length===0&&B>0&&pe!==$&&(N(pe),m==null||m(pe))},[x,W,Z,$]);const je=b.useMemo(()=>sa.filter(B=>gi(R,B)>0),[R]),K=je.reduce((B,pe)=>B+gi(R,pe),0),V=je.some(B=>gi(R,B)>=Ui)?`${K.toLocaleString()}+`:K.toLocaleString(),re=!Z&&!ae&&R!==null&&K===0,J=b.useCallback(B=>{j(B),N(1),d==null||d(B)},[d]),I=b.useMemo(()=>{const B=[];return g.dynasty.forEach(pe=>B.push({name:pe,remove:()=>r({...g,dynasty:g.dynasty.filter(Te=>Te!==pe)})})),g.classification.forEach(pe=>{var Te;return B.push({name:pe?((Te=qn.find(ve=>ve.value===pe))==null?void 0:Te.label)??pe:p.searchPage.unclassified,remove:()=>r({...g,classification:g.classification.filter(ve=>ve!==pe)})})}),g.hasImage&&B.push({name:h.hasImage,remove:()=>r({...g,hasImage:!1})}),g.hasText&&B.push({name:h.hasText,remove:()=>r({...g,hasText:!1})}),g.hasCollated&&B.push({name:h.hasCollated,remove:()=>r({...g,hasCollated:!1})}),g.loss&&B.push({name:`${h.extant}:${p.searchPage.loss[g.loss]}`,remove:()=>r({...g,loss:""})}),B},[g,r,h,p]),ue={query:i,onEntryLinkClick:o,typeName:a},fe=B=>y==="table"?t.jsx(ia,{entries:B,...ue}):t.jsx(na,{entries:B,...ue}),ze=sa.flatMap(B=>zr(R,B));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:pp}),f&&t.jsx(ap,{filters:g,onChange:r}),t.jsxs("div",{className:"bim-sr-main","aria-busy":Z,ref:C,children:[je.length>0&&t.jsxs("div",{className:"bim-sr-tabs",role:"group","aria-label":p.search.resultTabs,style:{display:"flex",flexWrap:"wrap",gap:"0 4px",borderBottom:`1px solid ${s.bim("rule")}`},children:[t.jsxs(oa,{on:x==="all",onClick:()=>J("all"),children:[p.search.allTab," ",t.jsx("small",{children:V})]}),je.map(B=>t.jsxs(oa,{on:x===B,onClick:()=>J(B),children:[a(B)," ",t.jsx("small",{children:$n(gi(R,B))})]},B))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":u(h.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!g.sort,onClick:()=>r({...g,sort:""}),children:u(h.sortRelevance)}),["era","title"].map(B=>{const pe=g.sort.startsWith(`${B}:`)?g.sort.endsWith("desc")?"desc":"asc":null,Te=B==="era"?h.sortEra:h.sortTitle,ve=B==="era"?pe==="desc"?h.sortEraDesc:h.sortEraAsc:pe==="desc"?h.sortTitleDesc:h.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":pe!==null,title:u(ve),onClick:()=>r({...g,sort:`${B}:${pe==="asc"?"desc":"asc"}`}),children:[u(Te),pe?t.jsxs("span",{"aria-hidden":"true",children:[" ",pe==="asc"?"↑":"↓"]}):null]},B)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":u(h.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":y==="table",onClick:()=>w("table"),children:u(h.viewTable)}),t.jsx("button",{type:"button","aria-pressed":y==="card",onClick:()=>w("card"),children:u(h.viewCard)})]})]}),we&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:u(s.formatTemplate(h.filteredCount,{n:V}))}),I.map(B=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u(s.formatTemplate(h.removeFilter,{name:B.name})),onClick:B.remove,children:[u(B.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},B.name))]}),ae&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:ae}),re&&t.jsx("div",{className:"bim-sr-empty",children:u(we?h.emptyFiltered:s.formatTemplate(p.search.noResultsFor,{query:i}))}),!ae&&!re&&x==="all"&&R&&(y==="table"?t.jsxs(t.Fragment,{children:[t.jsx(ia,{entries:ze,...ue}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(h.limitedNote)})]}):t.jsx(t.Fragment,{children:je.map(B=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xi,{type:B,size:8}),a(B),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:s.bim("meta-fg")},children:[$n(gi(R,B))," ",p.unit.items]})]}),gi(R,B)>zr(R,B).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>J(B),children:p.action.viewAll})]}),t.jsx(na,{entries:zr(R,B),...ue})]},B))})),!ae&&x!=="all"&&!W&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:p.search.loading}),!ae&&x!=="all"&&W&&W.entries.length>0&&t.jsxs(t.Fragment,{children:[fe(W.entries),t.jsx(mp,{page:$,pageSize:Nr,total:Math.min(W.total,Ui),totalLabel:$n(W.total),onPage:U})]}),!ae&&x!=="all"&&W&&W.entries.length===0&&!Z&&t.jsxs("div",{className:"bim-sr-empty",children:[u(we?h.emptyFiltered:s.formatTemplate(p.search.noResultsFor,{query:i})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>J("all"),children:p.search.allTab})})]})]})]})};function oa({on:e,onClick:i,children:n}){return t.jsx("button",{type:"button","aria-pressed":e,onClick:i,style:{border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:14.5,minHeight:44,padding:"8px 12px",letterSpacing:".06em",color:e?s.bim("ink"):s.bim("meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${s.bim("accent")}`:"none"},children:n})}const _i="bim-recent-ids",aa="bim-recent-entries",la=50;function ei(){try{const e=localStorage.getItem(_i);if(e)return JSON.parse(e);const i=localStorage.getItem(aa);if(i){const n=JSON.parse(i).map(r=>r.id);return localStorage.setItem(_i,JSON.stringify(n)),localStorage.removeItem(aa),n}return[]}catch{return[]}}function Vr(e){try{const i=ei().filter(n=>n!==e);i.unshift(e),i.length>la&&(i.length=la),localStorage.setItem(_i,JSON.stringify(i))}catch{}}function tc(e){try{const i=ei().filter(n=>n!==e);localStorage.setItem(_i,JSON.stringify(i))}catch{}}function Ns(){try{localStorage.removeItem(_i)}catch{}}async function zs(e,i){var n,r,o;try{if(e.getEntry){const l=await e.getEntry(i);if(l)return l}const a=await e.getItem(i);if(a){const l=a.authors;return{id:i,title:a.title||i,type:a.type||"work",author:(n=l==null?void 0:l[0])==null?void 0:n.name,dynasty:(r=l==null?void 0:l[0])==null?void 0:r.dynasty,role:(o=l==null?void 0:l[0])==null?void 0:o.role,edition:a.edition||void 0}}}catch{}return{id:i,title:i,type:"work",notFound:!0}}const Cr=5,kp=50,wp=200,ca={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},vp=({transport:e,indexSource:i="local",syncConfig:n,onEntryClick:r,onNewEntry:o,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c,hideModeIndicator:m,resultVariant:p="compact",renderEntry:h,initialQuery:u,onQueryChange:f,headerRight:g,reserveViewportHeight:y=!1,filtersEnabled:v=!1,filters:w=Gn,onFiltersChange:x,resultTab:j,onResultTabChange:S,resultPage:$,onResultPageChange:N})=>{const z=s.useT(),C=[{type:"work",name:z.indexType.work,key:"works"},{type:"book",name:z.indexType.book,key:"books"},{type:"collection",name:z.indexType.collection,key:"collections"},{type:"entity",name:z.indexType.entity,key:"entities"}],U=["work","collection","book","entity"],[R,L]=b.useState(u??""),[F,T]=b.useState(null),[Z,O]=b.useState(u??""),ae=An(w).toString(),[ce,Ee]=b.useState(w);b.useEffect(()=>{Ee(w)},[ae]);const we=H=>{Ee(H),x==null||x(H)},[ye,Q]=b.useState(null),[Ne,W]=b.useState("all"),[je,K]=b.useState(!1),[V,re]=b.useState(null),[J,I]=b.useState(""),[ue,fe]=b.useState(!(u!=null&&u.trim())),[ze,B]=b.useState(ei),[pe,Te]=b.useState([]),[ve,Ve]=b.useState(!1),[qe,Xe]=b.useState(!1),[X,ie]=b.useState(null),[me,se]=b.useState(null),de=b.useRef(void 0),ge=b.useRef(!1),Oe=b.useCallback(async(H,he)=>{if(!H.trim()){fe(!0),T(null),Q(null);return}if(fe(!1),v){O(H);return}K(!0),I("");try{if(e.searchAll){const xe=await e.searchAll(H,he??Cr);T(xe)}else{const xe=["work","book","collection","entity"],Re=await Promise.all(xe.map(Ze=>e.search(H,Ze,{page:1,pageSize:he??Cr})));T({works:Re[0].entries,books:Re[1].entries,collections:Re[2].entries,entities:Re[3].entries,totalWorks:Re[0].total,totalBooks:Re[1].total,totalCollections:Re[2].total,totalEntities:Re[3].total})}}catch(xe){I(xe instanceof Error?xe.message:String(xe)),T(null)}finally{K(!1)}},[e,v]);b.useEffect(()=>{let H=!1;const he=()=>{var He,ct;const xe=["work","book","collection","entity"],Re=Promise.all(xe.map(Be=>e.loadEntries(Be,{page:1,pageSize:1}).catch(()=>({total:0})))),Ze=((He=e.getResourceCounts)==null?void 0:He.call(e).catch(()=>null))??Promise.resolve(null),Me=((ct=e.getSubtypeStats)==null?void 0:ct.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Re,Ze,Me]).then(([Be,ee,Se])=>{H||(ie({works:Be[0].total,books:Be[1].total,collections:Be[2].total,entities:Be[3].total,hasText:ee==null?void 0:ee.hasText,hasImage:ee==null?void 0:ee.hasImage}),Se&&se(Se))})};return e.getCounts?e.getCounts().then(xe=>{var Re,Ze;H||(ie({works:xe.works,books:xe.books,collections:xe.collections,entities:xe.entities,hasText:(Re=xe.resourceCounts)==null?void 0:Re.hasText,hasImage:(Ze=xe.resourceCounts)==null?void 0:Ze.hasImage}),xe.subtypeStats&&se(xe.subtypeStats))}).catch(()=>{H||he()}):he(),()=>{H=!0}},[e]),b.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Oe(u))},[u,Oe]);const Je=b.useCallback(H=>{if(L(H),!H.trim()){f==null||f(H),fe(!0),T(null),Q(null),W("all");return}de.current&&clearTimeout(de.current),de.current=setTimeout(()=>{Q(null),W("all"),f==null||f(H),Oe(H)},wp)},[Oe,f]),Pe=b.useCallback(H=>{de.current&&clearTimeout(de.current),W("all"),f==null||f(H),Oe(H)},[Oe,f]),Ue=b.useCallback(H=>{Q(H),Oe(R,kp)},[R,Oe]);b.useEffect(()=>{if(!ze.length){Te([]);return}let H=!1;return Ve(!0),Promise.all(ze.slice(0,10).map(he=>zs(e,he))).then(he=>{H||(Te(he),Ve(!1))}),()=>{H=!0}},[ze,e]);const nt=H=>{re(H.id),Vr(H.id),B(ei()),r==null||r(H)},Y=(H,he)=>{if(r&&$p(he)){he.preventDefault(),nt(H);return}Vr(H.id),B(ei())},M=H=>{tc(H),B(ei())},k=()=>{Ns(),B([])},P=H=>C.find(he=>he.type===H),q=!ue&&!F&&!J,_=F&&(F.works.length>0||F.books.length>0||F.collections.length>0),le=t.jsxs(t.Fragment,{children:[t.jsx(Tl,{transport:e,value:R,onChange:Je,onSearch:Pe,onEntrySelect:nt}),v&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const H=R.trim();H&&Rl(H),Pe(R)},children:z.searchPage.submit}),o&&t.jsx("button",{onClick:()=>o("work"),style:{padding:"8px 14px",border:`1px solid ${s.bim("primary")}`,borderRadius:"6px",background:"transparent",color:s.bim("primary"),cursor:"pointer",fontSize:"13px"},children:z.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:y?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:_p+(v?Np:"")}),(!v||g||!m)&&t.jsx("header",{style:{padding:`12px ${s.bim("browser-pad-x")}`,borderBottom:`1px solid ${s.bim("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[v?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:s.bim("fg")},children:z.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!m&&t.jsx(El,{variant:"index-browser",indexSource:i,syncConfig:n,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),v?t.jsxs("div",{className:"bim-ib-bar","data-nofilters":e.supportsSearchFilters?void 0:"true",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("div",{className:"bim-ib-bar-main",children:le})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:`12px ${s.bim("browser-pad-x")}`,alignItems:"center"},children:le}),ue&&t.jsx("div",{className:"bim-ib-stats",style:{padding:`0 ${s.bim("browser-pad-x")} 8px`,fontSize:"12px",color:s.bim("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:X&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:me?t.jsxs(t.Fragment,{children:[(me.book??0)>0&&t.jsxs(t.Fragment,{children:[z.searchPage.statBook," ",t.jsx("strong",{style:{color:s.bim("fg")},children:me.book.toLocaleString()})," ",z.unit.bu,z.searchPage.statComma,t.jsx("strong",{style:{color:s.bim("fg")},children:X.books.toLocaleString()})," ",z.searchPage.statBookCopies]}),me.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statArticle," ",t.jsx("strong",{style:{color:s.bim("fg")},children:me.article.toLocaleString()})," ",z.searchPage.statArticleUnit]}):null,me.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statPoem," ",t.jsx("strong",{style:{color:s.bim("fg")},children:me.poem.toLocaleString()})," ",z.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statCollection," ",t.jsx("strong",{style:{color:s.bim("fg")},children:X.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[z.indexType.work," ",t.jsx("strong",{style:{color:s.bim("fg")},children:X.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.book," ",t.jsx("strong",{style:{color:s.bim("fg")},children:X.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.collection," ",t.jsx("strong",{style:{color:s.bim("fg")},children:X.collections.toLocaleString()}),X.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.entity," ",t.jsx("strong",{style:{color:s.bim("fg")},children:X.entities.toLocaleString()})]})]})}),X.hasImage!=null&&X.hasText!=null&&t.jsxs("span",{children:[z.resourceType.image," ",t.jsx("strong",{style:{color:s.bim("fg")},children:X.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.resourceType.text," ",t.jsx("strong",{style:{color:s.bim("fg")},children:X.hasText.toLocaleString()})]})]})}),v&&!ue&&t.jsx(ec,{transport:e,query:Z,filters:ce,onFiltersChange:we,onEntryLinkClick:Y,typeName:H=>P(H).name,tab:j,onTabChange:S,page:$,onPageChange:N}),!(v&&!ue)&&t.jsx("div",{style:{padding:`0 ${s.bim("browser-pad-x")} 20px`,flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:je||q?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:s.bim("desc-fg"),minHeight:Sp,boxSizing:"border-box"},children:z.search.searching}):J?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:s.bim("desc-fg")},children:J})}):ue?t.jsx("div",{style:{flex:1},children:ve?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:s.bim("desc-fg")},children:z.search.loading}):pe.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:s.bim("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:z.search.recentBrowse}),t.jsx("button",{onClick:k,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:z.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:pe.slice(0,qe?10:3).map(H=>H.notFound?t.jsx(Rp,{id:H.id,onRemove:M,t:z},H.id):t.jsx(da,{entry:H,selected:V===H.id,onClick:Y,getConfig:P,onRemove:M},H.id))}),!qe&&pe.length>3&&t.jsx("button",{onClick:()=>Xe(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:s.bim("primary"),background:"transparent",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:z.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:s.bim("fg")},children:z.search.searchTitle}),t.jsx("p",{style:{color:s.bim("desc-fg"),fontSize:"13px"},children:z.search.searchSubtitle})]})}):_?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:zp}),(()=>{const H=Me=>F[ca[Me]]??0,he=U.map(Me=>C.find(He=>He.type===Me)).filter(Me=>H(Me.key)>0);if(he.length<2)return null;const xe=he.reduce((Me,He)=>Me+H(He.key),0),Re=Me=>{if(W(Me),Me!=="all"&&ye!==Me){const He=C.find(Be=>Be.type===Me),ct=(F[He.key]??[]).length;H(He.key)>ct&&Ue(Me)}},Ze=Me=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:Me?s.bim("fg"):s.bim("desc-fg"),fontWeight:Me?700:400,boxShadow:Me?`inset 0 -2px 0 ${s.bim("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":z.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${s.bim("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":Ne==="all",style:Ze(Ne==="all"),onClick:()=>Re("all"),children:[z.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:xe.toLocaleString()})]}),he.map(Me=>t.jsxs("button",{type:"button","aria-pressed":Ne===Me.type,style:Ze(Ne===Me.type),onClick:()=>Re(Me.type),children:[Me.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:H(Me.key).toLocaleString()})]},Me.type))]})})(),C.map(({type:H,name:he,key:xe})=>{const Re=F[xe]??[],Ze=ca[xe],Me=F[Ze]??0;if(Re.length===0||Ne!=="all"&&Ne!==H)return null;const ct=Ne==="all"&&!(ye===H)&&Me>Cr;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${s.bim("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:s.bim("fg")},children:[t.jsx(Xi,{type:H})," ",he,t.jsxs("span",{style:{fontWeight:400,color:s.bim("desc-fg"),marginLeft:"6px"},children:[Me," ",z.unit.items]})]}),ct&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>Ue(H),style:{border:"none",background:"transparent",color:s.bim("primary"),cursor:"pointer",fontSize:"12px"},children:z.action.viewAll})]}),t.jsx("div",{style:p==="list"?{display:"flex",flexDirection:"column",gap:0}:p==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Re.map(Be=>{if(h)return t.jsx(b.Fragment,{children:h(Be)},Be.id);const ee=p==="card"?Ep:da;return t.jsx(ee,{entry:Be,selected:V===Be.id,onClick:Y,getConfig:P,query:R},Be.id)})})]},H)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:s.bim("fg")},children:s.formatTemplate(z.search.noResultsFor,{query:R})}),t.jsx("p",{style:{color:s.bim("desc-fg"),fontSize:"13px"},children:z.search.tryOther})]})})]})},Sp=240;function $p(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const _p=`
|
|
121
121
|
.bim-ib-stats { min-height: 25px; box-sizing: content-box; }
|
|
122
122
|
@media (max-width: 719px) { .bim-ib-stats { min-height: 46px; } }
|
|
123
|
-
|
|
123
|
+
`,Np=`
|
|
124
124
|
.bim-ib-bar { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; padding: 0 ${s.bim("browser-pad-x")} 16px; }
|
|
125
125
|
.bim-ib-bar[data-nofilters] { grid-template-columns: minmax(0, 1fr); }
|
|
126
126
|
.bim-ib-bar[data-nofilters] > [aria-hidden] { display: none; }
|
|
@@ -135,14 +135,14 @@
|
|
|
135
135
|
.bim-ib-bar-main { max-width: none; }
|
|
136
136
|
.bim-ib-submit { min-height: 44px; padding: 0 16px; }
|
|
137
137
|
}
|
|
138
|
-
`,
|
|
138
|
+
`,zp=`
|
|
139
139
|
@media (max-width: 719px), (pointer: coarse) {
|
|
140
140
|
.bim-ib-viewall { position: relative; }
|
|
141
141
|
.bim-ib-viewall::after {
|
|
142
142
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
143
143
|
width: max(calc(100% + 8px), 44px); height: max(100%, 44px); transform: translate(-50%, -50%);
|
|
144
144
|
}
|
|
145
|
-
}`,ec={color:"inherit",textDecoration:"none"},Np=({snippet:e})=>{const{convert:i}=xt();return t.jsx("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.6},children:gs(e).map((n,r)=>n.marked?t.jsx("mark",{style:{background:s.bim("highlight-bg"),color:s.bim("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:i(n.text)},r):t.jsx(b.Fragment,{children:i(n.text)},r))})},zp=({entry:e,selected:i,onClick:n,getConfig:r,query:o})=>{const a=s.useT(),{convert:l}=xt(),d=l(e.title||e.primary_name||e.id),c=e.measure_info?l(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${Gi(e.juan_count)}${a.unit.juan}`:"",m=[...e.additional_titles||[],...e.attached_texts||[]],p=o&&m.length?m.find(f=>{const g=typeof f=="string"?f:f==null?void 0:f.book_title;return g==null?void 0:g.toLowerCase().includes(o.toLowerCase())}):void 0,h=s.bim("cover-accent"),u=It();return t.jsxs("a",{href:u(e.id),onClick:f=>n(e,f),className:"bim-result-card",style:{...ec,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:s.bim("bg"),border:i?`1px solid ${s.bim("primary")}`:`1px solid ${s.bim("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${h} 50%, ${s.bim("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${h} 14%, ${s.bim("bg")}), color-mix(in srgb, ${h} 7%, ${s.bim("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${h} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:h},children:Array.from(d).map((f,g)=>t.jsx("span",{children:f},g))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:s.bim("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:s.bim("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",l(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:l(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",l(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",l(e.era),"〕"]}),e.edition&&t.jsx("span",{children:l(e.edition)})]}),p&&t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[a.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.descriptionSnippet&&t.jsx(Np,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:s.bim("desc-fg"),border:`1px solid ${s.bim("widget-border")}`},children:[t.jsx(Xi,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:s.bim("desc-fg"),border:`1px solid ${s.bim("widget-border")}`},children:a.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:s.bim("desc-fg"),border:`1px solid ${s.bim("widget-border")}`},children:a.misc.imageResource})]})]})]})},da=({entry:e,selected:i,onClick:n,getConfig:r,query:o,onRemove:a})=>{const l=s.useT(),{convert:d}=xt(),c=[...e.additional_titles||[],...e.attached_texts||[]],m=o&&c.length?c.find(h=>{const u=typeof h=="string"?h:h==null?void 0:h.book_title;return u==null?void 0:u.toLowerCase().includes(o.toLowerCase())}):void 0,p=It();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:i?`1px solid ${s.bim("primary")}`:`1px solid ${s.bim("widget-border")}`,background:s.bim("input-bg")},children:[t.jsxs("a",{href:p(e.id),onClick:h=>n(e,h),className:"bim-result-card",style:{...ec,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:a?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(Xi,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:s.bim("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:s.bim("fg")},children:d(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:l.misc.textResource}),e.has_image&&t.jsx("span",{children:l.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[Gi(e.juan_count),l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),m&&t.jsxs("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginTop:"2px"},children:[l.search.alias,":",d(m)]})]}),!a&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),a&&t.jsx("button",{type:"button",onClick:()=>a(e.id),title:l.search.removeFromRecent,"aria-label":l.search.removeFromRecent,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},Cp=({id:e,onRemove:i,t:n})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${s.bim("widget-border")}`,background:s.bim("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:s.bim("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginTop:"2px"},children:n.search.itemNotFound})]}),t.jsx("button",{onClick:()=>i(e),title:n.search.removeFromRecent,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Ep({data:e}){const i=s.useT(),{convert:n}=xt(),{stats:r}=e,o=r.processed_volumes??r.total_found_volumes,a=o!=null&&e.total_volumes>0?Math.round(o/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:s.bim("fg"),margin:"0 0 8px"},children:n(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),marginBottom:"6px"},children:n(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:s.bim("desc-fg")},children:[t.jsxs("span",{children:[i.catalog.totalVolumes," ",t.jsx("strong",{style:{color:s.bim("fg")},children:e.total_volumes})," ",i.unit.volume]}),a!=null&&t.jsxs("span",{children:[i.catalog.processed," ",t.jsx("strong",{style:{color:s.bim("fg")},children:o})," ",i.unit.volume," (",a,"%)"]}),t.jsxs("span",{children:[i.catalog.contains," ",t.jsx("strong",{style:{color:s.bim("fg")},children:r.total_books})," ",i.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[i.catalog.matched," ",t.jsx("strong",{style:{color:s.bim("fg")},children:r.matched_works})," ",i.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[i.catalog.unmatched," ",t.jsx("strong",{style:{color:s.bim("missing-fg")},children:r.unmatched_works})," ",i.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:s.bim("desc-fg")},children:[i.catalog.source," ",e.source]})]})}function Rp({sections:e,activeSection:i,onSelect:n}){const r=s.useT();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>n(null),style:ma(i===null),children:r.catalog.all}),e.map(o=>t.jsxs("button",{onClick:()=>n(o.name),style:ma(i===o.name),children:[o.name,o.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[o.volume_range[0],"–",o.volume_range[1]]})]},o.name))]})}function ma(e){return{padding:"4px 12px",border:e?`1px solid ${s.bim("primary")}`:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${s.bim("primary")} 8%, transparent)`:"transparent",color:e?s.bim("primary"):s.bim("fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Tp({id:e,label:i,onNavigate:n,renderLink:r}){const o=It();return r?t.jsx(t.Fragment,{children:r(e,i)}):n?t.jsx("a",{href:o(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),n(e))},style:{color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${s.bim("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:i||e}):t.jsx("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:i||e})}function Ip(e,i){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=e[0],r=e[e.length-1];return r-n+1===e.length?`${n}–${r}`:e.length<=3?e.join(", "):`${n}–${r} (${e.length}${i})`}function ua({book:e,onNavigate:i,renderLink:n,showVolumes:r}){const o=s.useT(),{convert:a}=xt(),l=e.book_id||e.work_id,d=r&&e.volumes.length>0?Ip(e.volumes,o.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${s.bim("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:s.bim("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:s.bim("fg")},children:[a(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:s.bim("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(m=>a(m)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:c?s.bim("missing-fg"):s.bim("desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,o.unit.volume]}),l&&t.jsx(Tp,{id:l,label:e.book_id?o.indexType.book:o.indexType.work,onNavigate:i,renderLink:n}),!l&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),flexShrink:0},children:o.catalog.unmatched_label})]})}const tc=({data:e,collectionId:i,transport:n,onNavigate:r,renderLink:o,className:a,style:l})=>{const d=s.useT(),[c,m]=b.useState(null),[p,h]=b.useState(!1),[u,f]=b.useState(null),[g,y]=b.useState(null),[v,w]=b.useState(""),x=e||c;b.useEffect(()=>{if(e||!i||!(n!=null&&n.getCollectionCatalog))return;let z=!1;return h(!0),f(null),n.getCollectionCatalog(i).then(C=>{z||(C?m(C):f(d.catalog.notFound))}).catch(C=>{z||f(C instanceof Error?C.message:d.catalog.loadFailed)}).finally(()=>{z||h(!1)}),()=>{z=!0}},[e,i,n,d]);const j=(x==null?void 0:x.sections)&&x.sections.length>0,S=b.useMemo(()=>{if(!x)return!1;if(x.volume_index&&Object.keys(x.volume_index).length>0)return!0;const z=x.books.map(U=>U.volumes[0]).filter(U=>U!=null);return new Set(z).size<z.length},[x]),$=b.useMemo(()=>{if(!x)return[];let z=x.books;if(g&&(z=z.filter(C=>C.section===g)),v.trim()){const C=v.trim().toLowerCase();z=z.filter(U=>U.title.toLowerCase().includes(C)||U.sub_items&&U.sub_items.some(R=>R.toLowerCase().includes(C))||U.edition&&U.edition.toLowerCase().includes(C))}return z},[x,g,v]),N=b.useMemo(()=>{if(!S)return null;const z=[],C=new Map;for(const R of $){if(!R.volumes||R.volumes.length===0)continue;const L=R.volumes[0];C.has(L)||C.set(L,[]),C.get(L).push(R)}const U=[...C.keys()].sort((R,L)=>R-L);for(const R of U)z.push({volume:R,books:C.get(R)});return z},[$,S]);return p?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:s.bim("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):u?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:s.bim("desc-fg"),fontSize:"13px"},children:u}):x?t.jsxs("div",{className:a,style:l,children:[t.jsx(Ep,{data:x}),j&&t.jsx(Rp,{sections:x.sections,activeSection:g,onSelect:y}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:v,onChange:z=>w(z.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"4px",background:s.bim("input-bg"),color:s.bim("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:s.bim("desc-fg")},children:[$.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[N?N.map((z,C)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:s.bim("bg"),borderBottom:`1px solid ${s.bim("widget-border")}`,fontSize:"12px",fontWeight:600,color:s.bim("desc-fg"),position:"sticky",top:0,zIndex:1},children:s.formatTemplate(d.catalog.volume,{n:z.volume})}),z.books.map((U,R)=>t.jsx(ua,{book:U,onNavigate:r,renderLink:o,showVolumes:U.volumes.length>1},`${z.volume}-${R}`))]},`${z.volume}-${C}`)):$.map((z,C)=>t.jsx(ua,{book:z,onNavigate:r,renderLink:o,showVolumes:!0},C)),$.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:s.bim("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Fi=e=>typeof e=="string"&&e?e:void 0;function Mp(e){if(!e||typeof e!="object")return e;const i=[],n=o=>{const a=Fi(o);a&&!i.includes(a)&&i.push(a)};return n(e.work_id),Array.isArray(e.work_ids)&&e.work_ids.forEach(n),"work_id"in e||"work_ids"in e?{...e,work_ids:i,work_id:i[0]??null}:e}function Ap(e){if(!e||typeof e!="object")return e??null;const i=e.meta,n={...e};return i&&typeof i=="object"&&(n.page_title===void 0&&Fi(i.page_title)&&(n.page_title=Fi(i.page_title)),n.source_url===void 0&&Fi(i.source_url)&&(n.source_url=Fi(i.source_url))),Array.isArray(e.sections)&&(n.sections=e.sections.map(Mp)),n}const Er=e=>e?e.catch(()=>null):Promise.resolve(null);function ic(e){const i=new Map;function n(r){var a;let o=i.get(r);return o||(o=Er((a=e.getTextManifest)==null?void 0:a.call(e,r)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||i.delete(r),d}),i.set(r,o)),o}return{getManifest(r){return _e.isSafeSegment(r)?n(r):Promise.resolve(null)},async getIndex(r,o){return!_e.isSafeSegment(r)||!_e.isSafeSegment(o)||!e.getTextIndex?null:Er(e.getTextIndex(r,o))},async getChapter(r,o,a,l){if(!_e.isSafeSegment(r)||!_e.isSafeSegment(o)||!_e.isSafeSegment(a)||!e.getChapter)return null;const d=await Er(e.getChapter(r,o,a,l));return d&&d.json?{...d,json:Ap(d.json)}:d}}}const nc=()=>{const{t:e}=oe(),[i,n]=b.useState(1);return b.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:s.bim("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(i)})},Rr=String.raw`https?:\/\/[^\s()()<>"]+`,Lp=new RegExp(String.raw`\[([^\]\n]+)\]\((${Rr})\)`+String.raw`|(《[^》\n]+》)\s?[((](${Rr})[))]`+`|(${Rr})`,"g");function Pp(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Op(e){const i=[];let n=0;for(const r of e.matchAll(Lp)){const o=r.index??0;o>n&&i.push({text:e.slice(n,o)}),r[1]!==void 0?i.push({text:r[1],url:r[2]}):r[3]!==void 0?i.push({text:r[3],url:r[4]}):i.push({text:Pp(r[5]),url:r[5]}),n=o+r[0].length}return n<e.length&&i.push({text:e.slice(n)}),i}function rc({text:e,convert:i,className:n="bim-rd-link"}){return t.jsx(t.Fragment,{children:Op(e).map((r,o)=>r.url?t.jsx("a",{className:n,href:r.url,target:"_blank",rel:"noopener noreferrer",children:i(r.text)},o):t.jsx(b.Fragment,{children:i(r.text)},o))})}const Cs="(min-width: 1100px)",_n="(max-width: 719px)",Nn="(max-width: 859px)",Fp=`${_n}, (pointer: coarse)`,Bt=s.bim("reader-top"),Bp="48px",sc=`
|
|
145
|
+
}`,ic={color:"inherit",textDecoration:"none"},Cp=({snippet:e})=>{const{convert:i}=xt();return t.jsx("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.6},children:gs(e).map((n,r)=>n.marked?t.jsx("mark",{style:{background:s.bim("highlight-bg"),color:s.bim("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:i(n.text)},r):t.jsx(b.Fragment,{children:i(n.text)},r))})},Ep=({entry:e,selected:i,onClick:n,getConfig:r,query:o})=>{const a=s.useT(),{convert:l}=xt(),d=l(e.title||e.primary_name||e.id),c=e.measure_info?l(e.measure_info):e.juan_count!=null&&e.juan_count>0?`${Gi(e.juan_count)}${a.unit.juan}`:"",m=[...e.additional_titles||[],...e.attached_texts||[]],p=o&&m.length?m.find(f=>{const g=typeof f=="string"?f:f==null?void 0:f.book_title;return g==null?void 0:g.toLowerCase().includes(o.toLowerCase())}):void 0,h=s.bim("cover-accent"),u=It();return t.jsxs("a",{href:u(e.id),onClick:f=>n(e,f),className:"bim-result-card",style:{...ic,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:s.bim("bg"),border:i?`1px solid ${s.bim("primary")}`:`1px solid ${s.bim("widget-border")}`,transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[t.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${h} 50%, ${s.bim("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${h} 14%, ${s.bim("bg")}), color-mix(in srgb, ${h} 7%, ${s.bim("bg")}))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[t.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${h} 45%, transparent)`}}),t.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:h},children:Array.from(d).map((f,g)=>t.jsx("span",{children:f},g))})]}),t.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:s.bim("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:s.bim("desc-fg")},children:[e.dynasty&&t.jsxs("span",{children:["〔",l(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:l(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",l(e.role)]})]}),(e.era||e.edition)&&t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[e.era&&t.jsxs("span",{children:["〔",l(e.era),"〕"]}),e.edition&&t.jsx("span",{children:l(e.edition)})]}),p&&t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[a.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.descriptionSnippet&&t.jsx(Cp,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:s.bim("desc-fg"),border:`1px solid ${s.bim("widget-border")}`},children:[t.jsx(Xi,{type:e.type,size:8})," ",r(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:s.bim("desc-fg"),border:`1px solid ${s.bim("widget-border")}`},children:a.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:s.bim("desc-fg"),border:`1px solid ${s.bim("widget-border")}`},children:a.misc.imageResource})]})]})]})},da=({entry:e,selected:i,onClick:n,getConfig:r,query:o,onRemove:a})=>{const l=s.useT(),{convert:d}=xt(),c=[...e.additional_titles||[],...e.attached_texts||[]],m=o&&c.length?c.find(h=>{const u=typeof h=="string"?h:h==null?void 0:h.book_title;return u==null?void 0:u.toLowerCase().includes(o.toLowerCase())}):void 0,p=It();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:i?`1px solid ${s.bim("primary")}`:`1px solid ${s.bim("widget-border")}`,background:s.bim("input-bg")},children:[t.jsxs("a",{href:p(e.id),onClick:h=>n(e,h),className:"bim-result-card",style:{...ic,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:a?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(Xi,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:s.bim("desc-fg"),lineHeight:1},children:r(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:s.bim("fg")},children:d(e.title||e.primary_name||e.id)}),t.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[e.has_text&&t.jsx("span",{children:l.misc.textResource}),e.has_image&&t.jsx("span",{children:l.misc.imageResource})]}),(e.era||e.edition)&&t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[e.era&&t.jsxs(t.Fragment,{children:["〔",d(e.era),"〕"]}),e.edition&&d(e.edition)]}),e.measure_info?t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[Gi(e.juan_count),l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),marginTop:"2px"},children:[e.dynasty&&t.jsxs("span",{children:["〔",d(e.dynasty),"〕"]}),e.author&&t.jsx("span",{children:d(e.author)}),e.role&&e.role!=="author"&&t.jsxs("span",{children:[" ",d(e.role)]}),e.type==="entity"&&(e.birth_year!=null||e.death_year!=null)&&t.jsxs("span",{style:{marginLeft:e.dynasty?"4px":0},children:[e.birth_year??"?","—",e.death_year??"?"]})]}),m&&t.jsxs("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginTop:"2px"},children:[l.search.alias,":",d(m)]})]}),!a&&t.jsx("span",{"aria-hidden":"true",style:{opacity:.4,marginTop:"2px"},children:"→"})]}),a&&t.jsx("button",{type:"button",onClick:()=>a(e.id),title:l.search.removeFromRecent,"aria-label":l.search.removeFromRecent,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},Rp=({id:e,onRemove:i,t:n})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${s.bim("widget-border")}`,background:s.bim("input-bg"),opacity:.6},children:[t.jsx("span",{style:{fontSize:"16px"},children:"❓"}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:"13px",color:s.bim("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginTop:"2px"},children:n.search.itemNotFound})]}),t.jsx("button",{onClick:()=>i(e),title:n.search.removeFromRecent,style:{border:"none",background:"transparent",color:s.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Tp({data:e}){const i=s.useT(),{convert:n}=xt(),{stats:r}=e,o=r.processed_volumes??r.total_found_volumes,a=o!=null&&e.total_volumes>0?Math.round(o/e.total_volumes*100):null;return t.jsxs("div",{style:{marginBottom:"24px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:s.bim("fg"),margin:"0 0 8px"},children:n(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),marginBottom:"6px"},children:n(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:s.bim("desc-fg")},children:[t.jsxs("span",{children:[i.catalog.totalVolumes," ",t.jsx("strong",{style:{color:s.bim("fg")},children:e.total_volumes})," ",i.unit.volume]}),a!=null&&t.jsxs("span",{children:[i.catalog.processed," ",t.jsx("strong",{style:{color:s.bim("fg")},children:o})," ",i.unit.volume," (",a,"%)"]}),t.jsxs("span",{children:[i.catalog.contains," ",t.jsx("strong",{style:{color:s.bim("fg")},children:r.total_books})," ",i.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&t.jsxs("span",{children:[i.catalog.matched," ",t.jsx("strong",{style:{color:s.bim("fg")},children:r.matched_works})," ",i.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&t.jsxs("span",{children:[i.catalog.unmatched," ",t.jsx("strong",{style:{color:s.bim("missing-fg")},children:r.unmatched_works})," ",i.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:s.bim("desc-fg")},children:[i.catalog.source," ",e.source]})]})}function Ip({sections:e,activeSection:i,onSelect:n}){const r=s.useT();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>n(null),style:ma(i===null),children:r.catalog.all}),e.map(o=>t.jsxs("button",{onClick:()=>n(o.name),style:ma(i===o.name),children:[o.name,o.volume_range&&t.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[o.volume_range[0],"–",o.volume_range[1]]})]},o.name))]})}function ma(e){return{padding:"4px 12px",border:e?`1px solid ${s.bim("primary")}`:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${s.bim("primary")} 8%, transparent)`:"transparent",color:e?s.bim("primary"):s.bim("fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function Mp({id:e,label:i,onNavigate:n,renderLink:r}){const o=It();return r?t.jsx(t.Fragment,{children:r(e,i)}):n?t.jsx("a",{href:o(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),n(e))},style:{color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${s.bim("link-fg")}`,paddingBottom:"1px",fontSize:"12px"},onMouseEnter:a=>a.currentTarget.style.borderBottomStyle="solid",onMouseLeave:a=>a.currentTarget.style.borderBottomStyle="dashed",children:i||e}):t.jsx("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:i||e})}function Ap(e,i){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=e[0],r=e[e.length-1];return r-n+1===e.length?`${n}–${r}`:e.length<=3?e.join(", "):`${n}–${r} (${e.length}${i})`}function ua({book:e,onNavigate:i,renderLink:n,showVolumes:r}){const o=s.useT(),{convert:a}=xt(),l=e.book_id||e.work_id,d=r&&e.volumes.length>0?Ap(e.volumes,o.unit.volume):null,c=e.missing_volumes&&e.missing_volumes.length>0;return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:`1px solid ${s.bim("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[r&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:s.bim("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:s.bim("fg")},children:[a(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:s.bim("desc-fg"),fontWeight:400,marginLeft:"6px"},children:["(",e.sub_items.map(m=>a(m)).join("、"),")"]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:c?s.bim("missing-fg"):s.bim("desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,o.unit.volume]}),l&&t.jsx(Mp,{id:l,label:e.book_id?o.indexType.book:o.indexType.work,onNavigate:i,renderLink:n}),!l&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),flexShrink:0},children:o.catalog.unmatched_label})]})}const nc=({data:e,collectionId:i,transport:n,onNavigate:r,renderLink:o,className:a,style:l})=>{const d=s.useT(),[c,m]=b.useState(null),[p,h]=b.useState(!1),[u,f]=b.useState(null),[g,y]=b.useState(null),[v,w]=b.useState(""),x=e||c;b.useEffect(()=>{if(e||!i||!(n!=null&&n.getCollectionCatalog))return;let z=!1;return h(!0),f(null),n.getCollectionCatalog(i).then(C=>{z||(C?m(C):f(d.catalog.notFound))}).catch(C=>{z||f(C instanceof Error?C.message:d.catalog.loadFailed)}).finally(()=>{z||h(!1)}),()=>{z=!0}},[e,i,n,d]);const j=(x==null?void 0:x.sections)&&x.sections.length>0,S=b.useMemo(()=>{if(!x)return!1;if(x.volume_index&&Object.keys(x.volume_index).length>0)return!0;const z=x.books.map(U=>U.volumes[0]).filter(U=>U!=null);return new Set(z).size<z.length},[x]),$=b.useMemo(()=>{if(!x)return[];let z=x.books;if(g&&(z=z.filter(C=>C.section===g)),v.trim()){const C=v.trim().toLowerCase();z=z.filter(U=>U.title.toLowerCase().includes(C)||U.sub_items&&U.sub_items.some(R=>R.toLowerCase().includes(C))||U.edition&&U.edition.toLowerCase().includes(C))}return z},[x,g,v]),N=b.useMemo(()=>{if(!S)return null;const z=[],C=new Map;for(const R of $){if(!R.volumes||R.volumes.length===0)continue;const L=R.volumes[0];C.has(L)||C.set(L,[]),C.get(L).push(R)}const U=[...C.keys()].sort((R,L)=>R-L);for(const R of U)z.push({volume:R,books:C.get(R)});return z},[$,S]);return p?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:s.bim("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):u?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:s.bim("desc-fg"),fontSize:"13px"},children:u}):x?t.jsxs("div",{className:a,style:l,children:[t.jsx(Tp,{data:x}),j&&t.jsx(Ip,{sections:x.sections,activeSection:g,onSelect:y}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:v,onChange:z=>w(z.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"4px",background:s.bim("input-bg"),color:s.bim("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:s.bim("desc-fg")},children:[$.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[N?N.map((z,C)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:s.bim("bg"),borderBottom:`1px solid ${s.bim("widget-border")}`,fontSize:"12px",fontWeight:600,color:s.bim("desc-fg"),position:"sticky",top:0,zIndex:1},children:s.formatTemplate(d.catalog.volume,{n:z.volume})}),z.books.map((U,R)=>t.jsx(ua,{book:U,onNavigate:r,renderLink:o,showVolumes:U.volumes.length>1},`${z.volume}-${R}`))]},`${z.volume}-${C}`)):$.map((z,C)=>t.jsx(ua,{book:z,onNavigate:r,renderLink:o,showVolumes:!0},C)),$.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:s.bim("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Fi=e=>typeof e=="string"&&e?e:void 0;function Lp(e){if(!e||typeof e!="object")return e;const i=[],n=o=>{const a=Fi(o);a&&!i.includes(a)&&i.push(a)};return n(e.work_id),Array.isArray(e.work_ids)&&e.work_ids.forEach(n),"work_id"in e||"work_ids"in e?{...e,work_ids:i,work_id:i[0]??null}:e}function Pp(e){if(!e||typeof e!="object")return e??null;const i=e.meta,n={...e};return i&&typeof i=="object"&&(n.page_title===void 0&&Fi(i.page_title)&&(n.page_title=Fi(i.page_title)),n.source_url===void 0&&Fi(i.source_url)&&(n.source_url=Fi(i.source_url))),Array.isArray(e.sections)&&(n.sections=e.sections.map(Lp)),n}const Er=e=>e?e.catch(()=>null):Promise.resolve(null);function rc(e){const i=new Map;function n(r){var a;let o=i.get(r);return o||(o=Er((a=e.getTextManifest)==null?void 0:a.call(e,r)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||i.delete(r),d}),i.set(r,o)),o}return{getManifest(r){return _e.isSafeSegment(r)?n(r):Promise.resolve(null)},async getIndex(r,o){return!_e.isSafeSegment(r)||!_e.isSafeSegment(o)||!e.getTextIndex?null:Er(e.getTextIndex(r,o))},async getChapter(r,o,a,l){if(!_e.isSafeSegment(r)||!_e.isSafeSegment(o)||!_e.isSafeSegment(a)||!e.getChapter)return null;const d=await Er(e.getChapter(r,o,a,l));return d&&d.json?{...d,json:Pp(d.json)}:d}}}const sc=()=>{const{t:e}=oe(),[i,n]=b.useState(1);return b.useEffect(()=>{const r=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(r)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:s.bim("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(i)})},Rr=String.raw`https?:\/\/[^\s()()<>"]+`,Op=new RegExp(String.raw`\[([^\]\n]+)\]\((${Rr})\)`+String.raw`|(《[^》\n]+》)\s?[((](${Rr})[))]`+`|(${Rr})`,"g");function Fp(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Bp(e){const i=[];let n=0;for(const r of e.matchAll(Op)){const o=r.index??0;o>n&&i.push({text:e.slice(n,o)}),r[1]!==void 0?i.push({text:r[1],url:r[2]}):r[3]!==void 0?i.push({text:r[3],url:r[4]}):i.push({text:Fp(r[5]),url:r[5]}),n=o+r[0].length}return n<e.length&&i.push({text:e.slice(n)}),i}function oc({text:e,convert:i,className:n="bim-rd-link"}){return t.jsx(t.Fragment,{children:Bp(e).map((r,o)=>r.url?t.jsx("a",{className:n,href:r.url,target:"_blank",rel:"noopener noreferrer",children:i(r.text)},o):t.jsx(b.Fragment,{children:i(r.text)},o))})}const Cs="(min-width: 1100px)",_n="(max-width: 719px)",Nn="(max-width: 859px)",Hp=`${_n}, (pointer: coarse)`,Bt=s.bim("reader-top"),Dp="48px",ac=`
|
|
146
146
|
.bim-rd {
|
|
147
147
|
/* 阅读器范围的字体:宿主覆盖 --bim-font-reader-*(见 README「样式契约」),不必再写 .bim-rd 选择器 */
|
|
148
148
|
--bim-font-ui: ${s.bim("font-reader-ui")};
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
background: ${s.bim("page-bg")};
|
|
154
154
|
color: ${s.bim("ink")};
|
|
155
155
|
font-family: ${s.bim("font-ui")};
|
|
156
|
-
--bimrd-bar-h: ${
|
|
156
|
+
--bimrd-bar-h: ${Dp};
|
|
157
157
|
/* 设置侧栏的暖黄:与朱/靛/墨三套主色都不冲,只做底色与选中态 */
|
|
158
158
|
--bimrd-warm: ${s.bim("reader-warm")};
|
|
159
159
|
--bimrd-warm-bg: color-mix(in srgb, var(--bimrd-warm) 8%, ${s.bim("page-bg")});
|
|
@@ -528,7 +528,7 @@ button.bim-rd-pg:hover { border-color: ${s.bim("accent")}; }
|
|
|
528
528
|
|
|
529
529
|
/* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
|
|
530
530
|
A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
|
|
531
|
-
@media ${
|
|
531
|
+
@media ${Hp} {
|
|
532
532
|
.bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
|
|
533
533
|
.bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
|
|
534
534
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
@@ -781,16 +781,16 @@ button.bim-rd-pg:hover { border-color: ${s.bim("accent")}; }
|
|
|
781
781
|
.guji-page-indicator:hover, .guji-page-indicator:focus-visible { opacity: 1; }
|
|
782
782
|
.guji-page-indicator:focus-visible { outline: 2px solid ${s.bim("accent")}; outline-offset: 1px; border-radius: 3px; }
|
|
783
783
|
@media ${_n} { .guji-page-indicator { display: none; } }
|
|
784
|
-
`;function Es(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(r=>Es(r,i))):!1}const pa=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Hp({item:e,activeKey:i,onSelect:n,tabKey:r}){const{t:o}=oe(),a=Es(e,i),[l,d]=b.useState(a||!!e.defaultExpanded);return b.useEffect(()=>{a&&d(!0)},[a]),b.useEffect(()=>{e.defaultExpanded&&d(!0)},[e.defaultExpanded]),e.selectable?t.jsxs("li",{children:[t.jsxs("div",{className:"bim-rd-ti-row",children:[t.jsx("button",{type:"button",className:"bim-rd-ti-tw","aria-expanded":l,"aria-label":o(l?"reader.tocCollapse":"reader.tocExpand"),tabIndex:-1,onClick:()=>d(c=>!c),children:t.jsx(pa,{})}),t.jsxs("button",{type:"button",className:`bim-rd-ti${e.inChapter?"":" bim-rd-ti-group"}`,"aria-current":e.key===i?"true":void 0,disabled:e.disabled,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>{d(!0),n(e.key)},onKeyDown:c=>{c.key==="ArrowRight"&&!l?(c.preventDefault(),d(!0)):c.key==="ArrowLeft"&&l&&(c.preventDefault(),d(!1))},children:[t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]}):t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(pa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]})}function qr({items:e,activeKey:i,onSelect:n,tabKey:r}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(Hp,{item:o,activeKey:i,onSelect:n,tabKey:r},o.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":o.key===i?"true":void 0,disabled:o.disabled,"data-rd-toc-key":o.key,tabIndex:r===o.key?0:-1,onClick:()=>n(o.key),children:[t.jsx("span",{children:o.label}),o.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:o.hint})]})},o.key))})}function ba(e,i){var n;for(const r of e)if(r.key===i||Es(r,i))return r.key;return((n=e[0])==null?void 0:n.key)??null}function oc({items:e,activeKey:i,onSelect:n,label:r}){const{t:o}=oe(),a=r??o("reader.toc"),l=b.useRef(null),[d,c]=b.useState(null);b.useEffect(()=>{c(null)},[i]);const m=b.useMemo(()=>d||(i??ba(e,i)),[d,i,e]);b.useEffect(()=>{const h=l.current;if(!h)return;const u=Array.from(h.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const f=u.find(g=>g.dataset.rdTocKey===m)??u.find(g=>g.dataset.rdTocKey===ba(e,i))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===f?0:-1}),b.useEffect(()=>{const h=l.current,u=h==null?void 0:h.closest(".bim-rd-toc");if(!h||!u||!i)return;const f=Array.from(h.querySelectorAll("[data-rd-toc-key]")).find(y=>y.dataset.rdTocKey===i);if(!f)return;const g=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[i]);const p=b.useCallback(h=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;const f=l.current;if(!f)return;const g=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(x=>!x.disabled),y=g.indexOf(document.activeElement);let v=y;if(h.key==="ArrowDown"?v=Math.min(g.length-1,y+1):h.key==="ArrowUp"?v=Math.max(0,y-1):h.key==="Home"?v=0:h.key==="End"&&(v=g.length-1),v<0||v===y)return;h.preventDefault();const w=g[v];for(const x of g)x.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(qr,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function ha({page:e,crop:i}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:i?`${i.x} ${i.y} ${i.w} ${i.h}`:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((r,o)=>t.jsx("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:"none",stroke:s.bim("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function Dp(e){const{boxes:i,width:n,height:r}=e;if(!(i!=null&&i.length)||!n||!r||e.boxFormat&&e.boxFormat!=="bim-charbox-v0")return null;let o=1/0,a=1/0,l=-1/0,d=-1/0;for(const f of i)[f.x,f.y,f.w,f.h].every(Number.isFinite)&&(o=Math.min(o,f.x),a=Math.min(a,f.y),l=Math.max(l,f.x+f.w),d=Math.max(d,f.y+f.h));if(!(l>o)||!(d>a))return null;const c=Math.min(n,r)*.03,m=Math.min(n,Math.max(0,o-c)),p=Math.min(r,Math.max(0,a-c)),h=Math.min(n,Math.max(0,l+c))-m,u=Math.min(r,Math.max(0,d+c))-p;return!(h>0)||!(u>0)||h>=n*.98&&u>=r*.98?null:{x:m,y:p,w:h,h:u}}function Xr({pages:e,loading:i,page:n,onPageChange:r,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=oe(),[d,c]=b.useState(0),m=n??d,p=y=>{r?r(y):c(y)};if(b.useEffect(()=>{n===void 0&&c(0)},[e,n]),i)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:l("reader.imagesLoading")})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:l("reader.noImages")}),t.jsx("span",{children:l("reader.noImagesHint")})]})});const h=Math.max(0,Math.min(e.length-1,m)),u=e[h],f=u.label??`${h+1}`,g=!a&&!o?Dp(u):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:g?t.jsxs("figure",{className:"bim-rd-img-fig bim-rd-img-trimmed","data-trim":`${Math.round(g.x)},${Math.round(g.y)},${Math.round(g.w)},${Math.round(g.h)}`,style:{aspectRatio:`${g.w} / ${g.h}`,overflow:"hidden",width:"100%",maxWidth:`calc((100vh - 200px) * ${g.w/g.h})`},children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${u.width/g.w*100}%`,left:`${-g.x/g.w*100}%`,top:`${-g.y/g.h*100}%`}}),t.jsx(ha,{page:u,crop:g})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(ha,{page:u}),o==null?void 0:o(u,h)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.prevImage"),disabled:h===0,onClick:()=>p(h-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${h+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:h===e.length-1,onClick:()=>p(h+1),children:"›"})]})]})}function Wp(e){return e==="lite"||e==="full"}const Vi=[.1,.9],ac=[{key:"song",stack:null},{key:"kai",stack:'"Kaiti SC", "Kaiti TC", STKaiti, "KaiTi", "AR PL UKai CN", "Noto Serif CJK SC", serif'},{key:"system",stack:"var(--bim-font-ui)"}];function Up(e){var i;return((i=ac.find(n=>n.key===e))==null?void 0:i.stack)??null}const Rs={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!1,banxinMode:"cut"},Yt=[15,16,17,18,20,22,24],Jr=18,lc="bim-reader-prefs",Zr=3,Kp="bim-reading-mode";function Yp(){const e={...Rs};try{const i=localStorage.getItem(lc),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(Kp))==="paragraph"&&(e.readingMode="paragraph"),n.properNameMode==="off"||n.properNameMode==="lite"||n.properNameMode==="full"?e.properNameMode=n.properNameMode:n.properNames===!0?e.properNameMode="full":n.properNames===!1&&(e.properNameMode="off"),n.writingMode==="vertical"&&(e.writingMode="vertical"),n.workLinks===!1&&(e.workLinks=!1),(n.fontFamily==="kai"||n.fontFamily==="system")&&(e.fontFamily=n.fontFamily);const o=n.v,a=o===2||o===Zr;a&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Vi[0]&&n.pageIndicatorY<=Vi[1]&&(e.pageIndicatorY=n.pageIndicatorY),a&&(n.bookTitleStyle==="wavy"||n.bookTitleStyle==="bracket")&&(e.bookTitleStyle=n.bookTitleStyle),n.showWorks===!1&&(e.showWorks=!1),(n.quoteStyle==="modern"||n.quoteStyle==="classic")&&(e.quoteStyle=n.quoteStyle),(n.scriptMode==="orig"||n.scriptMode==="hant"||n.scriptMode==="hans")&&(e.scriptMode=n.scriptMode),o===Zr&&typeof n.preserveMargins=="boolean"&&(e.preserveMargins=n.preserveMargins),(n.banxinMode==="full"||n.banxinMode==="none")&&(e.banxinMode=n.banxinMode)}catch{}return e}function Gp(e){try{localStorage.setItem(lc,JSON.stringify({...e,v:Zr}))}catch{}}function xn(e,i){const n=e??Jr,r=Yt;let o=r.indexOf(n);return o<0&&(o=r.indexOf(Jr)),r[Math.max(0,Math.min(r.length-1,o+i))]}function cc(){const[e,i]=b.useState(Rs);b.useEffect(()=>{i(Yp())},[]);const n=b.useCallback(r=>{i(o=>{const a={...o,...r};return Gp(a),a})},[]);return[e,n]}function Qr(e){if(e.optionLabel)return e.optionLabel;const i=e.label||e.key;return!e.sourceName||i.includes(e.sourceName)?i:`${i} · ${e.sourceName}`}function dc(e,i){if(!(!e||e.length===0))return(i!=null?e.find(n=>n.key===i):void 0)??e.find(n=>n.primary)??e[0]}function mc(e){const i=[],n=r=>{for(const o of r){if(o.inChapter)continue;const a=!!o.children&&o.children.length>0;(!a||o.selectable)&&i.push(o),a&&n(o.children)}};return n(e),i}const fa=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Vp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M15 5l-7 7 7 7"})}),qp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M9 5l7 7-7 7"})}),ga=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M4 7h10M18 7h2M4 17h2M10 17h10"}),t.jsx("circle",{cx:"16",cy:"7",r:"2"}),t.jsx("circle",{cx:"8",cy:"17",r:"2"})]}),xa=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function ya(e,i){if(!i)return;const n=Array.from(i.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(n.length===0)return;const r=n[0],o=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===r||!i.contains(a))?(e.preventDefault(),o.focus()):!e.shiftKey&&(a===o||!i.contains(a))&&(e.preventDefault(),r.focus())}function ja(e,i){const[n,r]=b.useState(i);return b.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const o=window.matchMedia(e);r(o.matches);const a=()=>r(o.matches);return(l=o.addEventListener)==null||l.call(o,"change",a),()=>{var d;return(d=o.removeEventListener)==null?void 0:d.call(o,"change",a)}},[e]),n}function Xp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe();if(!r)return null;const a=r.locale==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a,d=[{key:"orig",short:o("reader.scriptOrigShort"),title:o(n?"reader.scriptOrig":"reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",short:o("common.localeShortHant"),title:o("reader.scriptHant")},{key:"hans",short:o("common.localeShortHans"),title:o("reader.scriptHans")}];return t.jsx("span",{className:"bim-rd-script-sw",role:"group","aria-label":o("reader.scriptQuick"),children:d.map((c,m)=>t.jsxs(b.Fragment,{children:[m>0&&t.jsx("span",{className:"bim-rd-off","aria-hidden":"true",children:"|"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":l===c.key,title:c.title,"aria-label":c.title,disabled:c.disabled,onClick:()=>{c.disabled||(i({scriptMode:c.key}),c.key==="hant"?r.setLocale("zh-Hant"):c.key==="hans"&&r.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function Bi({label:e,value:i,options:n,onPick:r,title:o}){return t.jsxs("div",{className:"bim-rd-sp-row",role:"group","aria-label":e,title:o,children:[t.jsx("span",{className:"bim-rd-sp-l",children:e}),t.jsx("span",{className:"bim-rd-sp-fs",children:n.map(a=>t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":i===a.key,title:a.title,disabled:a.disabled,onClick:()=>{a.disabled||r(a.key)},children:a.label},a.key))})]})}function Jp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe(),a=(r==null?void 0:r.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(Bi,{label:o("reader.script"),value:l,options:[{key:"orig",label:o("reader.scriptOrig"),title:n?void 0:o("reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:d=>{i({scriptMode:d}),d==="hant"?r==null||r.setLocale("zh-Hant"):d==="hans"&&(r==null||r.setLocale("zh-Hans"))}})}function Zp(e,i){if(!e)return;let n;for(const r of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(r.getBoundingClientRect().top<=i+8)n=r.id;else break;return n}function Qp(e){var a;if(typeof window>"u"||!e)return;const i=(a=window.getSelection)==null?void 0:a.call(window);if(!i||i.isCollapsed||i.rangeCount===0)return;const n=e.querySelector(".bim-rd-col"),r=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(n!=null&&n.contains(l))&&!(d!=null&&d.closest(".bim-rd-src, .bim-rd-pager"))};if(!r(i.anchorNode)||!r(i.focusNode))return;const o=i.toString().replace(/\s+/g," ").trim();return o?o.slice(0,500):void 0}function uc({title:e,subtitle:i,toc:n,activeKey:r,tocActiveKey:o,onSelect:a,tocHeader:l,tocCaption:d,images:c,imagesLoading:m,renderImageOverlay:p,imagePanel:h="auto",prefs:u,onPrefsChange:f,paragraphToggle:g,properNameToggle:y=!0,allowVertical:v,origScriptAvailable:w=!0,byline:x,current:j,workLinkToggle:S,rail:$,onReportError:N,revisedAt:z,backHref:C,backLabel:U,bottomBar:R=!0,pager:L=!0,contentLoading:F=!1,pagerUnit:T,versions:Z,currentVersionKey:O,onVersionChange:ae,versionSource:ce=!0,keepChapterOnVersionChange:Ee=!1,customImagePanel:we,isWarpMode:ye,showPreserveMargins:Q=!0,pluginSettings:Ne,pluginToolbar:W,pluginOverlay:je,textRootRef:K,children:V,className:re,style:X}){const{t:I,convert:ue}=oe(),fe=U??I("reader.back"),ze=ue(T??I("reader.unitJuan")),B=b.useId().replace(/:/g,""),pe=`bim-rd-toc-${B}`,Te=`bim-rd-text-${B}`,ve=b.useRef(null),Ve=b.useRef(null),qe=b.useRef(null),Xe=b.useRef(null),J=ja(Cs,!0),ie=ja(Nn,!1),me=R&&ie,[se,de]=b.useState(null),[ge,Oe]=b.useState(!1),Je=b.useRef(null),Pe=`bim-rd-set-${B}`,Ue=b.useRef(null),nt=b.useRef(null),Y=(D,ke)=>{nt.current=ke,de(Qe=>Qe===D?null:D)},M=b.useCallback(()=>{var D;de(null),(D=nt.current)==null||D.focus()},[]);b.useEffect(()=>{me||de(null)},[me]),b.useEffect(()=>{var D,ke;se&&((ke=(D=Ue.current)==null?void 0:D.querySelector("button:not([disabled])"))==null||ke.focus())},[se]);const[k,P]=b.useState("auto"),q=k==="auto"?J:k==="open",_=!J,le=!!we||!!c&&c.length>0,[H,he]=b.useState(h);b.useEffect(()=>{he(h)},[h]);const xe=H==="auto"?le||!!m:H==="open",Re=b.useCallback(D=>{var ke;P("auto"),D&&((ke=Xe.current)==null||ke.focus())},[]),Ze=()=>P(q?"closed":"open");b.useEffect(()=>{if(!_||k!=="open")return;const D=qe.current,ke=D==null?void 0:D.querySelector('input, [data-rd-toc-key][tabindex="0"]');ke==null||ke.focus()},[_,k]);const Me=b.useCallback(D=>{a(D),_&&Re(!1);const ke=Ve.current,Qe=ve.current;if(ke&&Qe&&typeof window<"u"){const Ye=ke.getBoundingClientRect().top-Qe.getBoundingClientRect().bottom;Ye<0&&window.scrollBy({top:Ye})}},[a,_,Re]),He=b.useMemo(()=>mc(n),[n]),[ct,Be]=b.useState(null),ee=dc(Z,O!==void 0?O:ct),Se=(ee==null?void 0:ee.key)??null,et=b.useMemo(()=>He.map(D=>D.key).join(`
|
|
785
|
-
`),[He]),tt=b.useRef(null),De=D=>{D!==Se&&(Ee||(tt.current={key:D,sig:et,done:!1}),O===void 0&&Be(D),ae==null||ae(D))};b.useEffect(()=>{const D=tt.current;if(!D||D.key!==Se)return;const ke=He.find(Ye=>!Ye.disabled);if(!ke)return;const Qe=et!==D.sig;!Qe&&D.done||(Qe?tt.current=null:D.done=!0,ke.key!==r&&Me(ke.key))},[Se,et,He,r,Me]);const Fe=He.find(D=>D.key===r),pt=()=>{var D;N==null||N({chapterKey:r,chapterLabel:typeof(Fe==null?void 0:Fe.label)=="string"?Fe.label:void 0,anchor:Zp(Ve.current,((D=ve.current)==null?void 0:D.getBoundingClientRect().bottom)??0),selectedText:Qp(Ve.current)})},bt=He.findIndex(D=>D.key===r),ht=bt>0?He.slice(0,bt).reverse().find(D=>!D.disabled):void 0,We=bt>=0?He.slice(bt+1).find(D=>!D.disabled):void 0,gt=u.fontSize??Jr,te=Up(u.fontFamily),A={...X,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...te?{"--bimrd-ff":te}:null},ne={song:I("reader.fontSong"),kai:I("reader.fontKai"),system:I("reader.fontSystem")},$e=D=>(Ne??[]).filter(ke=>ke.group===D).map(ke=>t.jsx(b.Fragment,{children:ke.node},ke.key)),Ie=$e("text"),Le=$e("annotate"),at=$e("layout"),lt=$e("more"),Ge=[];for(const D of Ne??[]){if(["text","annotate","layout","more"].includes(D.group))continue;let ke=Ge.find(Qe=>Qe.group===D.group);ke?ke.title==null&&(ke.title=D.title):Ge.push(ke={group:D.group,title:D.title,nodes:[]}),ke.nodes.push(t.jsx(b.Fragment,{children:D.node},D.key))}const Ae=_?[W==null?void 0:W.subtitle,W==null?void 0:W.actions].filter(Boolean):[],Ce=lt.length>0||Ae.length>0,rt=y||Le.length>0,st=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g1`,children:[t.jsx("h3",{id:`${Pe}-g1`,className:"bim-rd-sp-h",children:I("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":I("reader.font"),value:u.fontFamily,onChange:D=>f({fontFamily:D.target.value}),children:ac.map(D=>t.jsx("option",{value:D.key,children:ne[D.key]},D.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[gt,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Jp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx(Bi,{label:I("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:I("reader.quoteModern")},{key:"classic",label:I("reader.quoteClassic")},{key:"original",label:I("reader.quoteOriginal")}],onPick:D=>f({quoteStyle:D})}),Ie]}),rt&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g2`,children:[t.jsx("h3",{id:`${Pe}-g2`,className:"bim-rd-sp-h",children:I("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Bi,{label:I("reader.properName"),value:u.properNameMode,title:I("reader.properNameTitle"),options:[{key:"off",label:I("reader.properNameOff")},{key:"lite",label:I("reader.properNameLite"),title:I("reader.properNameLiteTitle")},{key:"full",label:I("reader.properNameFull")}],onPick:D=>f({properNameMode:D})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:D=>f({showWorks:D.target.checked})}),t.jsx("span",{children:I("reader.showWorks")})]}),t.jsx(Bi,{label:I("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:I("reader.bookTitleWavy")},{key:"bracket",label:I("reader.bookTitleBracket")}],onPick:D=>f({bookTitleStyle:D})})]}),Le]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g3`,children:[t.jsx("h3",{id:`${Pe}-g3`,className:"bim-rd-sp-h",children:I("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:I("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:I("reader.paragraph")}),S&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.workLinks,onChange:D=>f({workLinks:D.target.checked})}),t.jsx("span",{children:I("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>f({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:I("reader.vertical")}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.pageBreaks,onChange:D=>f({pageBreaks:D.target.checked})}),t.jsx("span",{children:I("reader.pageBreaks")})]}),Q&&!u.preserveMargins&&t.jsx(Bi,{label:I("reader.banxinMode"),value:u.banxinMode,options:[{key:"cut",label:I("reader.banxinCut")},{key:"full",label:I("reader.banxinFull")},{key:"none",label:I("reader.banxinNone")}],onPick:D=>f({banxinMode:D})}),Q&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:D=>f({preserveMargins:D.target.checked})}),t.jsx("span",{children:I("reader.preserveMargins")})]}),at]}),Ge.map((D,ke)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-c${ke}`,children:[t.jsx("h3",{id:`${Pe}-c${ke}`,className:"bim-rd-sp-h",children:D.title??D.group}),D.nodes]},D.group)),Ce&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g4`,children:[t.jsx("h3",{id:`${Pe}-g4`,className:"bim-rd-sp-h",children:I("reader.groupMore")}),lt,Ae.map((D,ke)=>t.jsx("div",{className:"bim-rd-sp-row",children:D},`tb${ke}`))]})]}),Ke=b.useRef(null);return b.useEffect(()=>{const D=Ke.current;if(!D||!xe)return;let ke=0,Qe=-1;const Ye=()=>{ke=0;const Pt=parseFloat(getComputedStyle(D).top);if(!Number.isFinite(Pt))return;const dt=Math.max(0,Math.round(D.getBoundingClientRect().top-Pt));dt!==Qe&&(Qe=dt,D.style.setProperty("--bimrd-img-lead",`${dt}px`))},wt=()=>{ke||(ke=requestAnimationFrame(Ye))};wt(),window.addEventListener("scroll",wt,{passive:!0}),window.addEventListener("resize",wt);const it=typeof ResizeObserver<"u"?new ResizeObserver(wt):null;return it==null||it.observe(document.body),()=>{window.removeEventListener("scroll",wt),window.removeEventListener("resize",wt),it==null||it.disconnect(),ke&&cancelAnimationFrame(ke),D.style.removeProperty("--bimrd-img-lead")}},[xe]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",re].filter(Boolean).join(" "),"data-toc":k,"data-img":xe?"open":"closed","data-bb":me?"":void 0,"data-set":!me&&ge?"open":void 0,"data-warp":ye?"true":void 0,style:A,children:[t.jsx("style",{children:sc}),t.jsx("a",{className:"bim-rd-skip",href:`#${Te}`,onClick:D=>{var ke,Qe,Ye;D.preventDefault(),(ke=Ve.current)==null||ke.focus(),(Ye=(Qe=Ve.current)==null?void 0:Qe.scrollIntoView)==null||Ye.call(Qe,{block:"start"})},children:I("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:ve,children:[C&&t.jsxs("a",{className:"bim-rd-back",href:C,"aria-label":I("reader.backAria",{label:fe}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:fe})]}),(e||i||x||j||!_&&(W==null?void 0:W.subtitle))&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),x&&t.jsx("span",{className:"bim-rd-by",children:x}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!_&&(W==null?void 0:W.subtitle)&&t.jsx("span",{className:"bim-rd-ttl-src",children:W.subtitle})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":I("reader.settings"),children:[Z&&Z.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ee?ue(Qr(ee)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:I("reader.versionShort")}),t.jsx("select",{"aria-label":I("reader.version"),value:Se??"",onChange:D=>De(D.target.value),children:Z.map(D=>t.jsx("option",{value:D.key,children:ue(Qr(D))},D.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),L&&(ht||We)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":I("reader.pagerGroup",{unit:ze}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.prevUnit",{unit:ze}),title:ht?typeof ht.label=="string"&&ht.label?I("reader.prevUnitTitle",{unit:ze,label:ht.label}):I("reader.prevUnit",{unit:ze}):I("reader.firstUnit",{unit:ze}),disabled:!ht,onClick:()=>ht&&Me(ht.key),children:t.jsx(Vp,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.nextUnit",{unit:ze}),title:We?typeof We.label=="string"&&We.label?I("reader.nextUnitTitle",{unit:ze,label:We.label}):I("reader.nextUnit",{unit:ze}):I("reader.lastUnit",{unit:ze}),disabled:!We,onClick:()=>We&&Me(We.key),children:t.jsx(qp,{})})]}),L&&(ht||We)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:Xe,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":q,"aria-controls":pe,onClick:Ze,children:[t.jsx(fa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":xe,onClick:()=>he(xe?"closed":"open"),children:[t.jsx(xa,{}),I("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Xp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:Je,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":ge,"aria-controls":Pe,onClick:()=>Oe(D=>!D),children:[t.jsx(ga,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.settings")})]}),!_&&(W==null?void 0:W.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:pe,ref:qe,role:_&&q?"dialog":void 0,"aria-modal":_&&q?!0:void 0,"aria-label":_&&q?I("reader.toc"):void 0,onKeyDown:D=>{if(!(!_||!q)){if(D.key==="Escape"){D.stopPropagation(),Re(!0);return}D.key==="Tab"&&ya(D,qe.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??I("reader.toc")}),_&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeToc"),onClick:()=>Re(!0),children:"✕"})]}),l]}),t.jsx(oc,{items:n,activeKey:o!==void 0?o:r,onSelect:Me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Re(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":I("reader.images"),ref:Ke,children:xe&&(we||t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!me&&ge&&t.jsxs("aside",{className:"bim-rd-set",id:Pe,"aria-label":I("reader.settings"),onKeyDown:D=>{var ke;D.key==="Escape"&&(D.stopPropagation(),Oe(!1),(ke=Je.current)==null||ke.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:I("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeSettings"),onClick:()=>{var D;Oe(!1),(D=Je.current)==null||D.focus()},children:"✕"})]}),st]}),t.jsxs("div",{className:"bim-rd-text",id:Te,ref:D=>{Ve.current=D,K&&(K.current=D)},tabIndex:-1,"data-rail":($||N)&&!ye?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[V,ce&&ee&&(ee.sourceName||ee.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ee.key,children:[ee.sourceName&&t.jsxs(t.Fragment,{children:[I("reader.sourceLabel")," ",ee.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ee.sourceUrl,target:"_blank",rel:"noreferrer",children:ue(ee.sourceName)}):ue(ee.sourceName)]}),ee.sourceName&&ee.license&&t.jsx("span",{className:"bim-rd-dot"}),ee.license&&t.jsx(t.Fragment,{children:I("reader.licenseOf",{license:ee.license})})]}),z&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:I("reader.revisedAt",{date:z})}),N&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})}),L&&!F&&(ht||We)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":I("reader.pagerNav"),children:[ht?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Me(ht.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),I("reader.prevUnit",{unit:ze})]}),t.jsx("span",{className:"bim-rd-pglabel",children:ht.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",I("reader.firstUnit",{unit:ze})]}),We?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Me(We.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[I("reader.nextUnit",{unit:ze}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:We.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[I("reader.lastUnit",{unit:ze})," →"]})]})]}),($||N)&&!ye&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":I("reader.rail"),children:[$,N&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})})]})]})]}),me&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":I("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":q,"aria-controls":pe,onClick:()=>{de(null),Ze()},children:[t.jsx(fa,{}),t.jsx("span",{children:I("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="img","aria-haspopup":"dialog",onClick:D=>Y("img",D.currentTarget),children:[t.jsx(xa,{}),t.jsx("span",{children:I("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="set","aria-haspopup":"dialog",onClick:D=>Y("set",D.currentTarget),children:[t.jsx(ga,{}),t.jsx("span",{children:I("reader.settingsShort")})]}),N&&t.jsxs("button",{type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>{de(null),pt()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:I("reader.reportError")})]})]}),me&&se&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:M}),t.jsxs("div",{className:"bim-rd-sheet",ref:Ue,role:"dialog","aria-modal":"true","aria-label":I(se==="img"?"reader.images":"reader.settings"),onKeyDown:D=>{if(D.key==="Escape"){D.stopPropagation(),M();return}D.key==="Tab"&&ya(D,Ue.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:I(se==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.close"),onClick:M,children:"✕"})]}),se==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):st]})]}),je&&t.jsx("div",{className:"bim-rd-overlay",children:je})]})}function eb(e,i,n){return n?pc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function pc(e){return e.replace(/\r\n/g,`
|
|
786
|
-
`)}const ka=2,
|
|
787
|
-
`)return-1;if(o==="\\"){r++;continue}if(o==="[")n++;else if(o==="]"&&(n--,n===0))return r}return-1}function
|
|
788
|
-
`)<0?{node:{type:"qw",label:e.slice(i+2,r)},end:r+2}:null}if(n===":"&&e.startsWith(":zi[",i)){const r=
|
|
789
|
-
`)return null}const p=
|
|
790
|
-
.bim-d-main.bim-d-main-grid { max-width: ${
|
|
784
|
+
`;function Es(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(r=>Es(r,i))):!1}const pa=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function Wp({item:e,activeKey:i,onSelect:n,tabKey:r}){const{t:o}=oe(),a=Es(e,i),[l,d]=b.useState(a||!!e.defaultExpanded);return b.useEffect(()=>{a&&d(!0)},[a]),b.useEffect(()=>{e.defaultExpanded&&d(!0)},[e.defaultExpanded]),e.selectable?t.jsxs("li",{children:[t.jsxs("div",{className:"bim-rd-ti-row",children:[t.jsx("button",{type:"button",className:"bim-rd-ti-tw","aria-expanded":l,"aria-label":o(l?"reader.tocCollapse":"reader.tocExpand"),tabIndex:-1,onClick:()=>d(c=>!c),children:t.jsx(pa,{})}),t.jsxs("button",{type:"button",className:`bim-rd-ti${e.inChapter?"":" bim-rd-ti-group"}`,"aria-current":e.key===i?"true":void 0,disabled:e.disabled,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>{d(!0),n(e.key)},onKeyDown:c=>{c.key==="ArrowRight"&&!l?(c.preventDefault(),d(!0)):c.key==="ArrowLeft"&&l&&(c.preventDefault(),d(!1))},children:[t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]}):t.jsxs("li",{children:[t.jsxs("button",{type:"button",className:"bim-rd-ti bim-rd-ti-group","aria-expanded":l,"data-rd-toc-key":e.key,tabIndex:r===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(pa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(qr,{items:e.children,activeKey:i,onSelect:n,tabKey:r})]})}function qr({items:e,activeKey:i,onSelect:n,tabKey:r}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(Wp,{item:o,activeKey:i,onSelect:n,tabKey:r},o.key):t.jsx("li",{children:t.jsxs("button",{type:"button",className:"bim-rd-ti","aria-current":o.key===i?"true":void 0,disabled:o.disabled,"data-rd-toc-key":o.key,tabIndex:r===o.key?0:-1,onClick:()=>n(o.key),children:[t.jsx("span",{children:o.label}),o.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:o.hint})]})},o.key))})}function ba(e,i){var n;for(const r of e)if(r.key===i||Es(r,i))return r.key;return((n=e[0])==null?void 0:n.key)??null}function lc({items:e,activeKey:i,onSelect:n,label:r}){const{t:o}=oe(),a=r??o("reader.toc"),l=b.useRef(null),[d,c]=b.useState(null);b.useEffect(()=>{c(null)},[i]);const m=b.useMemo(()=>d||(i??ba(e,i)),[d,i,e]);b.useEffect(()=>{const h=l.current;if(!h)return;const u=Array.from(h.querySelectorAll("[data-rd-toc-key]"));if(u.length===0)return;const f=u.find(g=>g.dataset.rdTocKey===m)??u.find(g=>g.dataset.rdTocKey===ba(e,i))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===f?0:-1}),b.useEffect(()=>{const h=l.current,u=h==null?void 0:h.closest(".bim-rd-toc");if(!h||!u||!i)return;const f=Array.from(h.querySelectorAll("[data-rd-toc-key]")).find(y=>y.dataset.rdTocKey===i);if(!f)return;const g=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[i]);const p=b.useCallback(h=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;const f=l.current;if(!f)return;const g=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(x=>!x.disabled),y=g.indexOf(document.activeElement);let v=y;if(h.key==="ArrowDown"?v=Math.min(g.length-1,y+1):h.key==="ArrowUp"?v=Math.max(0,y-1):h.key==="Home"?v=0:h.key==="End"&&(v=g.length-1),v<0||v===y)return;h.preventDefault();const w=g[v];for(const x of g)x.tabIndex=-1;w.tabIndex=0,w.focus(),c(w.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(qr,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function ha({page:e,crop:i}){var n;return!((n=e.boxes)!=null&&n.length)||!e.width||!e.height||e.boxFormat&&e.boxFormat!=="bim-charbox-v0"?null:t.jsx("svg",{viewBox:i?`${i.x} ${i.y} ${i.w} ${i.h}`:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none","aria-hidden":"true",children:e.boxes.map((r,o)=>t.jsx("rect",{x:r.x,y:r.y,width:r.w,height:r.h,fill:"none",stroke:s.bim("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function Up(e){const{boxes:i,width:n,height:r}=e;if(!(i!=null&&i.length)||!n||!r||e.boxFormat&&e.boxFormat!=="bim-charbox-v0")return null;let o=1/0,a=1/0,l=-1/0,d=-1/0;for(const f of i)[f.x,f.y,f.w,f.h].every(Number.isFinite)&&(o=Math.min(o,f.x),a=Math.min(a,f.y),l=Math.max(l,f.x+f.w),d=Math.max(d,f.y+f.h));if(!(l>o)||!(d>a))return null;const c=Math.min(n,r)*.03,m=Math.min(n,Math.max(0,o-c)),p=Math.min(r,Math.max(0,a-c)),h=Math.min(n,Math.max(0,l+c))-m,u=Math.min(r,Math.max(0,d+c))-p;return!(h>0)||!(u>0)||h>=n*.98&&u>=r*.98?null:{x:m,y:p,w:h,h:u}}function Xr({pages:e,loading:i,page:n,onPageChange:r,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=oe(),[d,c]=b.useState(0),m=n??d,p=y=>{r?r(y):c(y)};if(b.useEffect(()=>{n===void 0&&c(0)},[e,n]),i)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsx("div",{className:"bim-rd-img-empty",children:l("reader.imagesLoading")})});if(!e||e.length===0)return t.jsx("div",{className:"bim-rd-img-box",children:t.jsxs("div",{className:"bim-rd-img-empty",children:[t.jsx("div",{className:"bim-rd-img-frame","aria-hidden":"true"}),t.jsx("b",{children:l("reader.noImages")}),t.jsx("span",{children:l("reader.noImagesHint")})]})});const h=Math.max(0,Math.min(e.length-1,m)),u=e[h],f=u.label??`${h+1}`,g=!a&&!o?Up(u):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-img-box",children:g?t.jsxs("figure",{className:"bim-rd-img-fig bim-rd-img-trimmed","data-trim":`${Math.round(g.x)},${Math.round(g.y)},${Math.round(g.w)},${Math.round(g.h)}`,style:{aspectRatio:`${g.w} / ${g.h}`,overflow:"hidden",width:"100%",maxWidth:`calc((100vh - 200px) * ${g.w/g.h})`},children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),decoding:"async",style:{position:"absolute",maxWidth:"none",maxHeight:"none",width:`${u.width/g.w*100}%`,left:`${-g.x/g.w*100}%`,top:`${-g.y/g.h*100}%`}}),t.jsx(ha,{page:u,crop:g})]}):t.jsxs("figure",{className:"bim-rd-img-fig",children:[t.jsx("img",{src:u.url,alt:u.alt??l("reader.imageAlt",{label:f}),width:u.width,height:u.height,loading:"lazy",decoding:"async"}),t.jsx(ha,{page:u}),o==null?void 0:o(u,h)]})}),e.length>1&&t.jsxs("div",{className:"bim-rd-img-pager",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.prevImage"),disabled:h===0,onClick:()=>p(h-1),children:"‹"}),t.jsx("span",{"aria-live":"polite",children:u.label??`${h+1} / ${e.length}`}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":l("reader.nextImage"),disabled:h===e.length-1,onClick:()=>p(h+1),children:"›"})]})]})}function Kp(e){return e==="lite"||e==="full"}const Vi=[.1,.9],cc=[{key:"song",stack:null},{key:"kai",stack:'"Kaiti SC", "Kaiti TC", STKaiti, "KaiTi", "AR PL UKai CN", "Noto Serif CJK SC", serif'},{key:"system",stack:"var(--bim-font-ui)"}];function Yp(e){var i;return((i=cc.find(n=>n.key===e))==null?void 0:i.stack)??null}const Rs={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!1,banxinMode:"cut"},Yt=[15,16,17,18,20,22,24],Jr=18,dc="bim-reader-prefs",Zr=3,Gp="bim-reading-mode";function Vp(){const e={...Rs};try{const i=localStorage.getItem(dc),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(Gp))==="paragraph"&&(e.readingMode="paragraph"),n.properNameMode==="off"||n.properNameMode==="lite"||n.properNameMode==="full"?e.properNameMode=n.properNameMode:n.properNames===!0?e.properNameMode="full":n.properNames===!1&&(e.properNameMode="off"),n.writingMode==="vertical"&&(e.writingMode="vertical"),n.workLinks===!1&&(e.workLinks=!1),(n.fontFamily==="kai"||n.fontFamily==="system")&&(e.fontFamily=n.fontFamily);const o=n.v,a=o===2||o===Zr;a&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Vi[0]&&n.pageIndicatorY<=Vi[1]&&(e.pageIndicatorY=n.pageIndicatorY),a&&(n.bookTitleStyle==="wavy"||n.bookTitleStyle==="bracket")&&(e.bookTitleStyle=n.bookTitleStyle),n.showWorks===!1&&(e.showWorks=!1),(n.quoteStyle==="modern"||n.quoteStyle==="classic")&&(e.quoteStyle=n.quoteStyle),(n.scriptMode==="orig"||n.scriptMode==="hant"||n.scriptMode==="hans")&&(e.scriptMode=n.scriptMode),o===Zr&&typeof n.preserveMargins=="boolean"&&(e.preserveMargins=n.preserveMargins),(n.banxinMode==="full"||n.banxinMode==="none")&&(e.banxinMode=n.banxinMode)}catch{}return e}function qp(e){try{localStorage.setItem(dc,JSON.stringify({...e,v:Zr}))}catch{}}function xn(e,i){const n=e??Jr,r=Yt;let o=r.indexOf(n);return o<0&&(o=r.indexOf(Jr)),r[Math.max(0,Math.min(r.length-1,o+i))]}function mc(){const[e,i]=b.useState(Rs);b.useEffect(()=>{i(Vp())},[]);const n=b.useCallback(r=>{i(o=>{const a={...o,...r};return qp(a),a})},[]);return[e,n]}function Qr(e){if(e.optionLabel)return e.optionLabel;const i=e.label||e.key;return!e.sourceName||i.includes(e.sourceName)?i:`${i} · ${e.sourceName}`}function uc(e,i){if(!(!e||e.length===0))return(i!=null?e.find(n=>n.key===i):void 0)??e.find(n=>n.primary)??e[0]}function pc(e){const i=[],n=r=>{for(const o of r){if(o.inChapter)continue;const a=!!o.children&&o.children.length>0;(!a||o.selectable)&&i.push(o),a&&n(o.children)}};return n(e),i}const fa=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:t.jsx("path",{d:"M4 6h16M4 12h10M4 18h16"})}),Xp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M15 5l-7 7 7 7"})}),Jp=()=>t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M9 5l7 7-7 7"})}),ga=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:[t.jsx("path",{d:"M4 7h10M18 7h2M4 17h2M10 17h10"}),t.jsx("circle",{cx:"16",cy:"7",r:"2"}),t.jsx("circle",{cx:"8",cy:"17",r:"2"})]}),xa=()=>t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"3",width:"16",height:"18",rx:"1.5"}),t.jsx("path",{d:"M9 3v18M13 7v10M16.5 7v10"})]});function ya(e,i){if(!i)return;const n=Array.from(i.querySelectorAll('button:not([disabled]), input:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')).filter(l=>l.tabIndex>=0);if(n.length===0)return;const r=n[0],o=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===r||!i.contains(a))?(e.preventDefault(),o.focus()):!e.shiftKey&&(a===o||!i.contains(a))&&(e.preventDefault(),r.focus())}function ja(e,i){const[n,r]=b.useState(i);return b.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const o=window.matchMedia(e);r(o.matches);const a=()=>r(o.matches);return(l=o.addEventListener)==null||l.call(o,"change",a),()=>{var d;return(d=o.removeEventListener)==null?void 0:d.call(o,"change",a)}},[e]),n}function Zp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe();if(!r)return null;const a=r.locale==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a,d=[{key:"orig",short:o("reader.scriptOrigShort"),title:o(n?"reader.scriptOrig":"reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",short:o("common.localeShortHant"),title:o("reader.scriptHant")},{key:"hans",short:o("common.localeShortHans"),title:o("reader.scriptHans")}];return t.jsx("span",{className:"bim-rd-script-sw",role:"group","aria-label":o("reader.scriptQuick"),children:d.map((c,m)=>t.jsxs(b.Fragment,{children:[m>0&&t.jsx("span",{className:"bim-rd-off","aria-hidden":"true",children:"|"}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":l===c.key,title:c.title,"aria-label":c.title,disabled:c.disabled,onClick:()=>{c.disabled||(i({scriptMode:c.key}),c.key==="hant"?r.setLocale("zh-Hant"):c.key==="hans"&&r.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function Bi({label:e,value:i,options:n,onPick:r,title:o}){return t.jsxs("div",{className:"bim-rd-sp-row",role:"group","aria-label":e,title:o,children:[t.jsx("span",{className:"bim-rd-sp-l",children:e}),t.jsx("span",{className:"bim-rd-sp-fs",children:n.map(a=>t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":i===a.key,title:a.title,disabled:a.disabled,onClick:()=>{a.disabled||r(a.key)},children:a.label},a.key))})]})}function Qp({prefs:e,onPrefsChange:i,origAvailable:n}){const r=b.useContext(s.LocaleContext),{t:o}=oe(),a=(r==null?void 0:r.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(Bi,{label:o("reader.script"),value:l,options:[{key:"orig",label:o("reader.scriptOrig"),title:n?void 0:o("reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:d=>{i({scriptMode:d}),d==="hant"?r==null||r.setLocale("zh-Hant"):d==="hans"&&(r==null||r.setLocale("zh-Hans"))}})}function eb(e,i){if(!e)return;let n;for(const r of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(r.getBoundingClientRect().top<=i+8)n=r.id;else break;return n}function tb(e){var a;if(typeof window>"u"||!e)return;const i=(a=window.getSelection)==null?void 0:a.call(window);if(!i||i.isCollapsed||i.rangeCount===0)return;const n=e.querySelector(".bim-rd-col"),r=l=>{const d=(l==null?void 0:l.nodeType)===1?l:l==null?void 0:l.parentElement;return!!l&&!!(n!=null&&n.contains(l))&&!(d!=null&&d.closest(".bim-rd-src, .bim-rd-pager"))};if(!r(i.anchorNode)||!r(i.focusNode))return;const o=i.toString().replace(/\s+/g," ").trim();return o?o.slice(0,500):void 0}function bc({title:e,subtitle:i,toc:n,activeKey:r,tocActiveKey:o,onSelect:a,tocHeader:l,tocCaption:d,images:c,imagesLoading:m,renderImageOverlay:p,imagePanel:h="auto",prefs:u,onPrefsChange:f,paragraphToggle:g,properNameToggle:y=!0,allowVertical:v,origScriptAvailable:w=!0,byline:x,current:j,workLinkToggle:S,rail:$,onReportError:N,revisedAt:z,backHref:C,backLabel:U,bottomBar:R=!0,pager:L=!0,contentLoading:F=!1,pagerUnit:T,versions:Z,currentVersionKey:O,onVersionChange:ae,versionSource:ce=!0,keepChapterOnVersionChange:Ee=!1,customImagePanel:we,isWarpMode:ye,showPreserveMargins:Q=!0,pluginSettings:Ne,pluginToolbar:W,pluginOverlay:je,textRootRef:K,children:V,className:re,style:J}){const{t:I,convert:ue}=oe(),fe=U??I("reader.back"),ze=ue(T??I("reader.unitJuan")),B=b.useId().replace(/:/g,""),pe=`bim-rd-toc-${B}`,Te=`bim-rd-text-${B}`,ve=b.useRef(null),Ve=b.useRef(null),qe=b.useRef(null),Xe=b.useRef(null),X=ja(Cs,!0),ie=ja(Nn,!1),me=R&&ie,[se,de]=b.useState(null),[ge,Oe]=b.useState(!1),Je=b.useRef(null),Pe=`bim-rd-set-${B}`,Ue=b.useRef(null),nt=b.useRef(null),Y=(D,ke)=>{nt.current=ke,de(Qe=>Qe===D?null:D)},M=b.useCallback(()=>{var D;de(null),(D=nt.current)==null||D.focus()},[]);b.useEffect(()=>{me||de(null)},[me]),b.useEffect(()=>{var D,ke;se&&((ke=(D=Ue.current)==null?void 0:D.querySelector("button:not([disabled])"))==null||ke.focus())},[se]);const[k,P]=b.useState("auto"),q=k==="auto"?X:k==="open",_=!X,le=!!we||!!c&&c.length>0,[H,he]=b.useState(h);b.useEffect(()=>{he(h)},[h]);const xe=H==="auto"?le||!!m:H==="open",Re=b.useCallback(D=>{var ke;P("auto"),D&&((ke=Xe.current)==null||ke.focus())},[]),Ze=()=>P(q?"closed":"open");b.useEffect(()=>{if(!_||k!=="open")return;const D=qe.current,ke=D==null?void 0:D.querySelector('input, [data-rd-toc-key][tabindex="0"]');ke==null||ke.focus()},[_,k]);const Me=b.useCallback(D=>{a(D),_&&Re(!1);const ke=Ve.current,Qe=ve.current;if(ke&&Qe&&typeof window<"u"){const Ye=ke.getBoundingClientRect().top-Qe.getBoundingClientRect().bottom;Ye<0&&window.scrollBy({top:Ye})}},[a,_,Re]),He=b.useMemo(()=>pc(n),[n]),[ct,Be]=b.useState(null),ee=uc(Z,O!==void 0?O:ct),Se=(ee==null?void 0:ee.key)??null,et=b.useMemo(()=>He.map(D=>D.key).join(`
|
|
785
|
+
`),[He]),tt=b.useRef(null),De=D=>{D!==Se&&(Ee||(tt.current={key:D,sig:et,done:!1}),O===void 0&&Be(D),ae==null||ae(D))};b.useEffect(()=>{const D=tt.current;if(!D||D.key!==Se)return;const ke=He.find(Ye=>!Ye.disabled);if(!ke)return;const Qe=et!==D.sig;!Qe&&D.done||(Qe?tt.current=null:D.done=!0,ke.key!==r&&Me(ke.key))},[Se,et,He,r,Me]);const Fe=He.find(D=>D.key===r),pt=()=>{var D;N==null||N({chapterKey:r,chapterLabel:typeof(Fe==null?void 0:Fe.label)=="string"?Fe.label:void 0,anchor:eb(Ve.current,((D=ve.current)==null?void 0:D.getBoundingClientRect().bottom)??0),selectedText:tb(Ve.current)})},bt=He.findIndex(D=>D.key===r),ht=bt>0?He.slice(0,bt).reverse().find(D=>!D.disabled):void 0,We=bt>=0?He.slice(bt+1).find(D=>!D.disabled):void 0,gt=u.fontSize??Jr,te=Yp(u.fontFamily),A={...J,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...te?{"--bimrd-ff":te}:null},ne={song:I("reader.fontSong"),kai:I("reader.fontKai"),system:I("reader.fontSystem")},$e=D=>(Ne??[]).filter(ke=>ke.group===D).map(ke=>t.jsx(b.Fragment,{children:ke.node},ke.key)),Ie=$e("text"),Le=$e("annotate"),at=$e("layout"),lt=$e("more"),Ge=[];for(const D of Ne??[]){if(["text","annotate","layout","more"].includes(D.group))continue;let ke=Ge.find(Qe=>Qe.group===D.group);ke?ke.title==null&&(ke.title=D.title):Ge.push(ke={group:D.group,title:D.title,nodes:[]}),ke.nodes.push(t.jsx(b.Fragment,{children:D.node},D.key))}const Ae=_?[W==null?void 0:W.subtitle,W==null?void 0:W.actions].filter(Boolean):[],Ce=lt.length>0||Ae.length>0,rt=y||Le.length>0,st=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g1`,children:[t.jsx("h3",{id:`${Pe}-g1`,className:"bim-rd-sp-h",children:I("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":I("reader.font"),value:u.fontFamily,onChange:D=>f({fontFamily:D.target.value}),children:cc.map(D=>t.jsx("option",{value:D.key,children:ne[D.key]},D.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:I("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[gt,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Qp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx(Bi,{label:I("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:I("reader.quoteModern")},{key:"classic",label:I("reader.quoteClassic")},{key:"original",label:I("reader.quoteOriginal")}],onPick:D=>f({quoteStyle:D})}),Ie]}),rt&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g2`,children:[t.jsx("h3",{id:`${Pe}-g2`,className:"bim-rd-sp-h",children:I("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Bi,{label:I("reader.properName"),value:u.properNameMode,title:I("reader.properNameTitle"),options:[{key:"off",label:I("reader.properNameOff")},{key:"lite",label:I("reader.properNameLite"),title:I("reader.properNameLiteTitle")},{key:"full",label:I("reader.properNameFull")}],onPick:D=>f({properNameMode:D})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:D=>f({showWorks:D.target.checked})}),t.jsx("span",{children:I("reader.showWorks")})]}),t.jsx(Bi,{label:I("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:I("reader.bookTitleWavy")},{key:"bracket",label:I("reader.bookTitleBracket")}],onPick:D=>f({bookTitleStyle:D})})]}),Le]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g3`,children:[t.jsx("h3",{id:`${Pe}-g3`,className:"bim-rd-sp-h",children:I("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:I("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:I("reader.paragraph")}),S&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.workLinks,onChange:D=>f({workLinks:D.target.checked})}),t.jsx("span",{children:I("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>f({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:I("reader.vertical")}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.pageBreaks,onChange:D=>f({pageBreaks:D.target.checked})}),t.jsx("span",{children:I("reader.pageBreaks")})]}),Q&&!u.preserveMargins&&t.jsx(Bi,{label:I("reader.banxinMode"),value:u.banxinMode,options:[{key:"cut",label:I("reader.banxinCut")},{key:"full",label:I("reader.banxinFull")},{key:"none",label:I("reader.banxinNone")}],onPick:D=>f({banxinMode:D})}),Q&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:D=>f({preserveMargins:D.target.checked})}),t.jsx("span",{children:I("reader.preserveMargins")})]}),at]}),Ge.map((D,ke)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-c${ke}`,children:[t.jsx("h3",{id:`${Pe}-c${ke}`,className:"bim-rd-sp-h",children:D.title??D.group}),D.nodes]},D.group)),Ce&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Pe}-g4`,children:[t.jsx("h3",{id:`${Pe}-g4`,className:"bim-rd-sp-h",children:I("reader.groupMore")}),lt,Ae.map((D,ke)=>t.jsx("div",{className:"bim-rd-sp-row",children:D},`tb${ke}`))]})]}),Ke=b.useRef(null);return b.useEffect(()=>{const D=Ke.current;if(!D||!xe)return;let ke=0,Qe=-1;const Ye=()=>{ke=0;const Pt=parseFloat(getComputedStyle(D).top);if(!Number.isFinite(Pt))return;const dt=Math.max(0,Math.round(D.getBoundingClientRect().top-Pt));dt!==Qe&&(Qe=dt,D.style.setProperty("--bimrd-img-lead",`${dt}px`))},wt=()=>{ke||(ke=requestAnimationFrame(Ye))};wt(),window.addEventListener("scroll",wt,{passive:!0}),window.addEventListener("resize",wt);const it=typeof ResizeObserver<"u"?new ResizeObserver(wt):null;return it==null||it.observe(document.body),()=>{window.removeEventListener("scroll",wt),window.removeEventListener("resize",wt),it==null||it.disconnect(),ke&&cancelAnimationFrame(ke),D.style.removeProperty("--bimrd-img-lead")}},[xe]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",re].filter(Boolean).join(" "),"data-toc":k,"data-img":xe?"open":"closed","data-bb":me?"":void 0,"data-set":!me&&ge?"open":void 0,"data-warp":ye?"true":void 0,style:A,children:[t.jsx("style",{children:ac}),t.jsx("a",{className:"bim-rd-skip",href:`#${Te}`,onClick:D=>{var ke,Qe,Ye;D.preventDefault(),(ke=Ve.current)==null||ke.focus(),(Ye=(Qe=Ve.current)==null?void 0:Qe.scrollIntoView)==null||Ye.call(Qe,{block:"start"})},children:I("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:ve,children:[C&&t.jsxs("a",{className:"bim-rd-back",href:C,"aria-label":I("reader.backAria",{label:fe}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:fe})]}),(e||i||x||j||!_&&(W==null?void 0:W.subtitle))&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),x&&t.jsx("span",{className:"bim-rd-by",children:x}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!_&&(W==null?void 0:W.subtitle)&&t.jsx("span",{className:"bim-rd-ttl-src",children:W.subtitle})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":I("reader.settings"),children:[Z&&Z.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:ee?ue(Qr(ee)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:I("reader.versionShort")}),t.jsx("select",{"aria-label":I("reader.version"),value:Se??"",onChange:D=>De(D.target.value),children:Z.map(D=>t.jsx("option",{value:D.key,children:ue(Qr(D))},D.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),L&&(ht||We)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":I("reader.pagerGroup",{unit:ze}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.prevUnit",{unit:ze}),title:ht?typeof ht.label=="string"&&ht.label?I("reader.prevUnitTitle",{unit:ze,label:ht.label}):I("reader.prevUnit",{unit:ze}):I("reader.firstUnit",{unit:ze}),disabled:!ht,onClick:()=>ht&&Me(ht.key),children:t.jsx(Xp,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.nextUnit",{unit:ze}),title:We?typeof We.label=="string"&&We.label?I("reader.nextUnitTitle",{unit:ze,label:We.label}):I("reader.nextUnit",{unit:ze}):I("reader.lastUnit",{unit:ze}),disabled:!We,onClick:()=>We&&Me(We.key),children:t.jsx(Jp,{})})]}),L&&(ht||We)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:Xe,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":q,"aria-controls":pe,onClick:Ze,children:[t.jsx(fa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":xe,onClick:()=>he(xe?"closed":"open"),children:[t.jsx(xa,{}),I("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Zp,{prefs:u,onPrefsChange:f,origAvailable:w}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontSmaller"),disabled:gt<=Yt[0],onClick:()=>f({fontSize:xn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":I("reader.fontLarger"),disabled:gt>=Yt[Yt.length-1],onClick:()=>f({fontSize:xn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:Je,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":ge,"aria-controls":Pe,onClick:()=>Oe(D=>!D),children:[t.jsx(ga,{}),t.jsx("span",{className:"bim-rd-tlabel",children:I("reader.settings")})]}),!_&&(W==null?void 0:W.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:pe,ref:qe,role:_&&q?"dialog":void 0,"aria-modal":_&&q?!0:void 0,"aria-label":_&&q?I("reader.toc"):void 0,onKeyDown:D=>{if(!(!_||!q)){if(D.key==="Escape"){D.stopPropagation(),Re(!0);return}D.key==="Tab"&&ya(D,qe.current)}},children:[t.jsxs("div",{className:"bim-rd-toc-top",children:[t.jsxs("div",{className:"bim-rd-toc-head",children:[t.jsx("span",{children:d??I("reader.toc")}),_&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeToc"),onClick:()=>Re(!0),children:"✕"})]}),l]}),t.jsx(lc,{items:n,activeKey:o!==void 0?o:r,onSelect:Me})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Re(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":I("reader.images"),ref:Ke,children:xe&&(we||t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!me&&ge&&t.jsxs("aside",{className:"bim-rd-set",id:Pe,"aria-label":I("reader.settings"),onKeyDown:D=>{var ke;D.key==="Escape"&&(D.stopPropagation(),Oe(!1),(ke=Je.current)==null||ke.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:I("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.closeSettings"),onClick:()=>{var D;Oe(!1),(D=Je.current)==null||D.focus()},children:"✕"})]}),st]}),t.jsxs("div",{className:"bim-rd-text",id:Te,ref:D=>{Ve.current=D,K&&(K.current=D)},tabIndex:-1,"data-rail":($||N)&&!ye?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[V,ce&&ee&&(ee.sourceName||ee.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":ee.key,children:[ee.sourceName&&t.jsxs(t.Fragment,{children:[I("reader.sourceLabel")," ",ee.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:ee.sourceUrl,target:"_blank",rel:"noreferrer",children:ue(ee.sourceName)}):ue(ee.sourceName)]}),ee.sourceName&&ee.license&&t.jsx("span",{className:"bim-rd-dot"}),ee.license&&t.jsx(t.Fragment,{children:I("reader.licenseOf",{license:ee.license})})]}),z&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:I("reader.revisedAt",{date:z})}),N&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})}),L&&!F&&(ht||We)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":I("reader.pagerNav"),children:[ht?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Me(ht.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),I("reader.prevUnit",{unit:ze})]}),t.jsx("span",{className:"bim-rd-pglabel",children:ht.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",I("reader.firstUnit",{unit:ze})]}),We?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Me(We.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[I("reader.nextUnit",{unit:ze}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:We.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[I("reader.lastUnit",{unit:ze})," →"]})]})]}),($||N)&&!ye&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":I("reader.rail"),children:[$,N&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:D=>D.preventDefault(),onClick:pt,children:I("reader.reportError")})})]})]})]}),me&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":I("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":q,"aria-controls":pe,onClick:()=>{de(null),Ze()},children:[t.jsx(fa,{}),t.jsx("span",{children:I("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="img","aria-haspopup":"dialog",onClick:D=>Y("img",D.currentTarget),children:[t.jsx(xa,{}),t.jsx("span",{children:I("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":se==="set","aria-haspopup":"dialog",onClick:D=>Y("set",D.currentTarget),children:[t.jsx(ga,{}),t.jsx("span",{children:I("reader.settingsShort")})]}),N&&t.jsxs("button",{type:"button",onMouseDown:D=>D.preventDefault(),onClick:()=>{de(null),pt()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:I("reader.reportError")})]})]}),me&&se&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:M}),t.jsxs("div",{className:"bim-rd-sheet",ref:Ue,role:"dialog","aria-modal":"true","aria-label":I(se==="img"?"reader.images":"reader.settings"),onKeyDown:D=>{if(D.key==="Escape"){D.stopPropagation(),M();return}D.key==="Tab"&&ya(D,Ue.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:I(se==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":I("reader.close"),onClick:M,children:"✕"})]}),se==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Xr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):st]})]}),je&&t.jsx("div",{className:"bim-rd-overlay",children:je})]})}function ib(e,i,n){return n?hc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function hc(e){return e.replace(/\r\n/g,`
|
|
786
|
+
`)}const ka=2,nb=400,rb=6,fc=e=>e==="*"||e==="#"||e==="<"||e===">"||/\s/.test(e);function gc(e,i){if(e[i]!=="<"||e[i+1]!=="!"||e[i+2]!=="-"||e[i+3]!=="-")return-1;for(let n=i+4;n+2<e.length;n++)if(e[n]==="-"&&e[n+1]==="-"&&e[n+2]===">")return n+2;return-1}function sb(e,i,n){let r=i;for(let o=0;o<n.length;){if(r>=e.length)return-1;if(n[o]===e[r]){o++,r++;continue}const a=gc(e,r);if(a>=0){r=a+1;continue}if(fc(e[r])){r++;continue}if(n[o]===" "){o++;continue}return-1}return r}function ob(e){const i=Array.from(hc(e));let n=0;return{align(r){if(!r)return;const o=Array.from(r);if(o.every(d=>d===" "||/\s/.test(d)))return;const a=o.length>=rb;let l=0;for(let d=n;d<i.length&&d-n<=(a?nb:ka+64);d++){const c=gc(i,d);if(c>=0){d=c;continue}if(!fc(i[d])){const p=sb(i,d,o);if(p>=0)return n=p,d;if(l++,!a&&l>ka)return}}}}}const ab=65536,lb="guji_markdown";function cb(e){const i=e==null?void 0:e.guji_markdown;if(typeof i!="string")return!1;const n=/^(\d+)\.(\d+)(?:\.\d+)?$/.exec(i.trim());if(!n)return!1;const r=parseInt(n[1],10),o=parseInt(n[2],10);return r>0||o>=2}const db=/^□\{guess=([^\s{}]+)\}/;function mb(e,i){const n=e[i+1];return n!==void 0&&!/[A-Za-z/!?>\s]/.test(n)}function xc(e,i){let n=0;for(let r=i;r<e.length;r++){const o=e[r];if(o===`
|
|
787
|
+
`)return-1;if(o==="\\"){r++;continue}if(o==="[")n++;else if(o==="]"&&(n--,n===0))return r}return-1}function ub(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function pb(e,i){const n=e[i];if(n==="["&&e[i+1]==="["){const r=e.indexOf("]]",i+2);return r>=0&&e.slice(i+2,r).indexOf(`
|
|
788
|
+
`)<0?{node:{type:"qw",label:e.slice(i+2,r)},end:r+2}:null}if(n===":"&&e.startsWith(":zi[",i)){const r=xc(e,i+3);return r>i+4?{node:{type:"zi",label:ub(e.slice(i+4,r))},end:r+1}:null}if(n==="□"&&e[i+1]==="{"){const r=db.exec(e.slice(i,i+64));if(r)return{node:{type:"qz",guess:r[1]},end:i+r[0].length}}return null}function yc(e,i,n,r,o){const a=[];let l="",d=!1;const c=()=>{if(!l)return;let m=l;r&&(m=l.replace(/\\?\|/g,p=>d?"|":(d=!0,""))),m&&a.push({type:"text",text:m}),l=""};for(;i<e.length;){const m=e[i];if(m==="\\"&&(e[i+1]==="<"||e[i+1]===">")){l+=e[i+1],i+=2;continue}if(n!==null){if(m===n)return c(),{nodes:a,end:i};if(m===`
|
|
789
|
+
`)return null}const p=pb(e,i);if(p){c(),a.push(p.node),i=p.end;continue}let h=null;if(m==="<"&&mb(e,i)&&(h=">"),h){const u=yc(e,i+1,h,!0,o);if(u&&!(u.end-(i+1)>o)){c(),a.push({type:"jz",children:u.nodes}),i=u.end+1;continue}}l+=m,i++}return n!==null?null:(c(),{nodes:a,end:i})}function jc(e,i){return yc(e,0,null,!1,(i==null?void 0:i.jzMaxLength)??ab).nodes}function bb(e){return/[<□]|\[\[|:zi\[/.test(e)}function kc(e){return e.map(i=>{switch(i.type){case"text":return i.text;case"jz":return`(${kc(i.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return i.label}}).join("")}const hb=216,wa="clamp(280px, 23vw, 360px)",fb=1440,es="(max-width: 719px)",gb=`${es}, (pointer: coarse)`,xb=`
|
|
790
|
+
.bim-d-main.bim-d-main-grid { max-width: ${fb}px; padding: 16px 32px 0; }
|
|
791
791
|
.bim-d-grid {
|
|
792
792
|
display: grid;
|
|
793
|
-
grid-template-columns: ${
|
|
793
|
+
grid-template-columns: ${hb}px minmax(0, 1fr) ${wa};
|
|
794
794
|
grid-template-rows: auto 1fr;
|
|
795
795
|
grid-template-areas: "rail main card" "rail main side";
|
|
796
796
|
column-gap: 32px; row-gap: 28px; align-items: start;
|
|
@@ -1169,7 +1169,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${s.bim("tint
|
|
|
1169
1169
|
.bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
|
|
1170
1170
|
|
|
1171
1171
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
1172
|
-
@media ${
|
|
1172
|
+
@media ${gb} {
|
|
1173
1173
|
.bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
|
|
1174
1174
|
.bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
|
|
1175
1175
|
.bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
|
|
@@ -1311,7 +1311,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${s.bim("tint
|
|
|
1311
1311
|
:root[data-theme="ink"] :is(.bim-d-zt, .bim-d-side li, .bim-d-card-desc, .bim-d-desc, .bim-d-lf-card) a:hover {
|
|
1312
1312
|
text-decoration-color: currentColor; text-decoration-thickness: 2px;
|
|
1313
1313
|
}
|
|
1314
|
-
`;function Zi({railTop:e,back:i,up:n,nav:r,railLinks:o,main:a,card:l,side:d}){const{t:c,convert:m}=oe(),p=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,i&&t.jsx("div",{style:{marginTop:e?12:0},children:i}),n,p.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("detail.pageNav"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("detail.thisPage")}),t.jsx("ul",{className:"bim-d-rail-nav",children:p.map(h=>t.jsx("li",{children:t.jsxs("a",{href:`#${h.id}`,children:[t.jsx("span",{children:m(h.label)}),h.count!=null&&t.jsx("span",{className:"bim-d-meta",children:h.count})]})},h.id))})]}),o&&o.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("detail.more"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("detail.more")}),t.jsx("ul",{className:"bim-d-rail-nav",children:o.map(h=>t.jsx("li",{children:t.jsxs("a",{href:h.href??"#",onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),h.onClick())},children:[t.jsx("span",{children:m(h.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},h.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:a}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:d})]})}function
|
|
1314
|
+
`;function Zi({railTop:e,back:i,up:n,nav:r,railLinks:o,main:a,card:l,side:d}){const{t:c,convert:m}=oe(),p=(r||[]).filter(Boolean);return t.jsxs("div",{className:"bim-d-grid",children:[t.jsxs("aside",{className:"bim-d-g-rail bim-d-ui",children:[e,i&&t.jsx("div",{style:{marginTop:e?12:0},children:i}),n,p.length>1&&t.jsxs("nav",{className:"bim-d-rail-navwrap","aria-label":c("detail.pageNav"),style:{marginTop:20},children:[t.jsx("p",{className:"bim-d-rail-cap",style:{marginTop:0},children:c("detail.thisPage")}),t.jsx("ul",{className:"bim-d-rail-nav",children:p.map(h=>t.jsx("li",{children:t.jsxs("a",{href:`#${h.id}`,children:[t.jsx("span",{children:m(h.label)}),h.count!=null&&t.jsx("span",{className:"bim-d-meta",children:h.count})]})},h.id))})]}),o&&o.length>0&&t.jsxs("nav",{className:"bim-d-rail-links","aria-label":c("detail.more"),children:[t.jsx("p",{className:"bim-d-rail-cap",children:c("detail.more")}),t.jsx("ul",{className:"bim-d-rail-nav",children:o.map(h=>t.jsx("li",{children:t.jsxs("a",{href:h.href??"#",onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),h.onClick())},children:[t.jsx("span",{children:m(h.label)}),t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:"→"})]})},h.key))})]})]}),t.jsx("div",{className:"bim-d-g-main",children:a}),t.jsx("div",{className:"bim-d-g-card",children:l}),t.jsx("div",{className:"bim-d-g-side",children:d})]})}function wc({caption:e,children:i}){const{convert:n}=oe();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:n(e)}),i]})}function St({id:e,title:i,meta:n,action:r,children:o}){const{convert:a}=oe();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:a(i)}),n!=null&&n!==""&&t.jsx("span",{className:"bim-d-meta",children:n}),r&&t.jsx("span",{className:"bim-d-sec-act",children:r})]}),t.jsx("div",{className:"bim-d-sec-body",children:o})]})}function vt({items:e,className:i,style:n}){const r=e.filter(o=>o!=null&&o!==""&&o!==!1);return r.length?t.jsx("span",{className:`bim-d-meta${i?` ${i}`:""}`,style:n,children:r.map((o,a)=>t.jsxs(b.Fragment,{children:[a>0&&t.jsx("span",{className:"bim-d-dot"}),t.jsx("span",{children:o})]},a))}):null}function Qi({items:e,value:i,onChange:n}){const{convert:r}=oe();return t.jsx(t.Fragment,{children:e.map(o=>t.jsx("button",{type:"button",className:[...r(o.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":o.key===i,onClick:()=>n(o.key),children:r(o.label)},o.key))})}function vc({label:e,checked:i,onChange:n}){const{convert:r}=oe();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:i,onChange:o=>n(o.target.checked)}),r(e)]})}const Sc=6,en=e=>e>Sc+1;function Jn({total:e,shown:i,unit:n,onClick:r}){const{t:o,convert:a}=oe(),l=e-i,d=en(e)?e-Math.min(i,Sc):l;return d<=0?null:t.jsxs("button",{type:"button",className:`bim-d-more bim-d-ui${l>0?"":" bim-d-more-ncap"}`,onClick:r,children:[l>0&&t.jsx("span",{className:"bim-d-more-w",children:o("detail.expandRest",{n:l,unit:a(n)})}),t.jsx("span",{className:"bim-d-more-n",children:o("detail.expandRest",{n:d,unit:a(n)})})]})}function Ts({label:e,onClick:i}){const{convert:n}=oe();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:i,children:n(e)})}function tn({kind:e,title:i,subtitle:n,byline:r,meta:o,description:a,clampDescription:l,facts:d,stats:c,readAction:m,secondaryAction:p,children:h,foot:u}){const{t:f,convert:g}=oe(),y=(d||[]).filter(S=>S.value!=null&&S.value!==""),v=(c||[]).filter(S=>S.value!=null&&S.value!==""&&S.value!==0),[w,x]=b.useState(!1),j=!!l&&!w;return t.jsxs("div",{className:"bim-d-card",children:[e&&t.jsx("div",{className:"bim-d-card-kind bim-d-ui",children:g(e)}),t.jsx("h1",{className:typeof i=="string"&&[...i].length>7?"bim-d-card-long":void 0,children:i}),n&&t.jsx("div",{className:"bim-d-card-sub",children:n}),r&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:r}),o&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:o}),a&&t.jsx("div",{className:j?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:j?{"--detail-clamp":l}:void 0,children:a}),a&&!!l&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":w,onClick:()=>x(S=>!S),children:f(w?"action.collapse":"action.expand")}),v.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:v.map((S,$)=>t.jsxs("div",{children:[t.jsx("b",{children:S.value}),t.jsx("span",{children:g(S.label)})]},$))}),y.length>0&&t.jsx("dl",{className:"bim-d-ui",children:y.map((S,$)=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:g(S.label)}),t.jsx("dd",{title:S.title,children:S.value})]},$))}),h,m,p,u&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:u})]})}function Is(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function ts({href:e,onClick:i,label:n}){const{t:r,convert:o}=oe(),a=n??r("detail.read");return e?t.jsx("a",{className:"bim-d-btn",href:e,onClick:i?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i())}:void 0,children:o(a)}):t.jsx("button",{type:"button",className:"bim-d-btn",onClick:i,children:o(a)})}function mi({id:e,title:i,meta:n,items:r,metas:o,currentIndex:a,cap:l=8,moreLabel:d,foot:c,sub:m,timeline:p}){const{t:h,convert:u}=oe(),[f,g]=b.useState(!1);if(!r.length)return null;const y=f?r:r.slice(0,l),v=r.length-y.length;return t.jsxs("div",{id:e,className:p?"bim-d-side bim-d-side-tl":"bim-d-side",style:{scrollMarginTop:16},children:[t.jsxs("h2",{className:"bim-d-ui bim-d-side-h",children:[u(i),n!=null&&n!==""&&t.jsx("span",{className:"bim-d-meta",children:n})]}),m&&t.jsx("p",{className:"bim-d-side-sub bim-d-ui",children:m}),t.jsx("ul",{children:y.map((w,x)=>t.jsxs("li",{className:x===a?"bim-d-side-cur":void 0,"aria-current":x===a?"page":void 0,children:[w,o!=null&&o[x]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:o[x]}):null]},x))}),v>0&&t.jsx(Ts,{label:d?d(v):h("detail.showMore",{n:v}),onClick:()=>g(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const yb=new Set(["reviewed","disputed","unreviewed","draft"]);function nn({revision:e,revisedAt:i,review:n,todo:r}){const{t:o,convert:a}=oe(),l=n&&yb.has(n.status)?o(`detail.review.${n.status}`):void 0,d=n&&n.status!=="unreviewed"&&l?[l,n.by,n.date].filter(Boolean).join(" "):"",c=[e!=null&&e!==""?`${o("detail.dataVersion")} ${e}`:"",i??"",a(d)].filter(Boolean),m=(r||[]).filter(p=>p&&p.what);return!c.length&&!m.length?null:t.jsxs(t.Fragment,{children:[c.length>0&&t.jsx(vt,{items:c,style:{fontSize:12}}),m.length>0&&t.jsxs("details",{children:[t.jsx("summary",{children:o("detail.todoCount",{n:m.length})}),t.jsx("ul",{style:{margin:"4px 0 0",paddingLeft:18,lineHeight:1.7},children:m.map((p,h)=>t.jsxs("li",{children:[a(p.what),(p.by||p.date)&&t.jsxs("span",{style:{marginLeft:6},children:["(",[p.by&&a(p.by),p.date].filter(Boolean).join(" · "),")"]})]},h))})]})]})}const zn=1e3,va=208,jb=1440,kb="(max-width: 719px)",$c=`
|
|
1315
1315
|
.bim-d-page {
|
|
1316
1316
|
background: ${s.bim("page-bg")};
|
|
1317
1317
|
color: ${s.bim("ink")};
|
|
@@ -1331,7 +1331,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${s.bim("tint
|
|
|
1331
1331
|
* PAGE_MAX_WIDTH,读者的行宽体验不变。
|
|
1332
1332
|
*/
|
|
1333
1333
|
.bim-d-main.bim-d-main-wide {
|
|
1334
|
-
max-width: ${
|
|
1334
|
+
max-width: ${jb}px;
|
|
1335
1335
|
}
|
|
1336
1336
|
.bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
|
|
1337
1337
|
|
|
@@ -1388,7 +1388,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${s.bim("tint
|
|
|
1388
1388
|
align-items: start; margin-bottom: 48px; }
|
|
1389
1389
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
1390
1390
|
|
|
1391
|
-
@media ${
|
|
1391
|
+
@media ${kb} {
|
|
1392
1392
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
1393
1393
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
1394
1394
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -1406,26 +1406,26 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${s.bim("tint
|
|
|
1406
1406
|
padding-right: 0; padding-bottom: 12px;
|
|
1407
1407
|
}
|
|
1408
1408
|
}
|
|
1409
|
-
${
|
|
1410
|
-
`)||(i.push({start:n,end:l+1,inner:d}),n=l)}return i}function
|
|
1409
|
+
${xb}`;function Hi({children:e,style:i,wide:n,grid:r}){return t.jsxs("div",{className:"bim-d-page",style:i,children:[t.jsx("style",{children:$c}),t.jsx("div",{className:r?"bim-d-main bim-d-main-grid":n?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function is({breadcrumb:e,actions:i}){return t.jsxs("div",{className:"bim-d-ui bim-d-top",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:s.bim("aux-fg")},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:e}),i&&t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:i})]})}function Ms({char:e,tone:i="accent"}){return t.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:i==="accent"?s.bim("accent"):s.bim("ink"),color:s.bim("page-bg")},children:e})}function ns({items:e}){const i=It();return t.jsx(t.Fragment,{children:e.map((n,r)=>{const o=r===e.length-1,a=r>0&&t.jsx("span",{style:{color:s.bim("hint-fg")},children:"/"},`s${r}`),l=n.id?i(n.id):n.href,d=o||!n.onClick&&!l?t.jsx("span",{style:{color:s.bim("ink")},children:n.label},r):t.jsx("a",{href:l??"#",onClick:n.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),n.onClick())}:void 0,style:{color:s.bim("meta-fg")},children:n.label},r);return t.jsxs(b.Fragment,{children:[a,d]},r)})})}function _c({title:e,subtitle:i,aside:n,secondLine:r}){return t.jsxs("header",{style:{borderBottom:`2px solid ${s.bim("rule-strong")}`,paddingBottom:18},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[t.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:e}),i&&t.jsx("span",{style:{fontSize:15,color:s.bim("meta-fg"),letterSpacing:".06em"},children:i})]}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:s.bim("label-fg"),letterSpacing:".06em"},children:n})]}),r&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:s.bim("quiet-fg")},children:r})]})}function wb({children:e,facts:i}){return!e&&i?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${s.bim("rule")}`,marginBottom:40},children:i}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),i]})}function vb({items:e,horizontal:i}){const{convert:n}=xt();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${s.bim("accent")}`,paddingLeft:16,display:i?"grid":"flex",gridTemplateColumns:i?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:i?void 0:"column",gap:i?"14px 40px":10,fontSize:13},children:e.map((r,o)=>t.jsxs("div",{title:r.title,style:i?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[t.jsx("span",{className:"bim-d-ui",style:{color:s.bim("label-fg"),letterSpacing:".08em",flex:"none"},children:n(r.label)}),t.jsx("span",{style:{color:s.bim("body-fg"),textAlign:i?"left":"right",minWidth:0},children:r.value})]},o))}):null}function Sb({glyph:e,tone:i,title:n,count:r,actions:o,id:a}){const{convert:l}=xt();return t.jsxs("div",{id:a,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx(Ms,{char:e,tone:i}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(n)}),r!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:s.bim("label-fg")},children:r})]}),o&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:o})]})}function Nc({label:e,active:i,onClick:n,dashed:r}){const{convert:o}=xt();return t.jsx("button",{type:"button",onClick:n,"aria-pressed":i,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!i?"dashed":"solid"} ${i?s.bim("accent"):s.bim("rule")}`,background:i?s.bim("accent"):"transparent",color:i?s.bim("page-bg"):s.bim("meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:o(e)})}function $b({label:e,onClick:i}){const{convert:n}=xt();return t.jsx("button",{type:"button",onClick:i,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg"),borderBottom:`1px solid ${s.bim("rule")}`},children:n(e)})}function _b({label:e,onClick:i,inline:n}){const{convert:r}=xt();return t.jsx("button",{type:"button",onClick:i,className:"bim-d-ui",style:{marginTop:n?0:12,width:n?void 0:"100%",padding:n?"4px 12px":9,background:"none",border:`1px dashed ${s.bim("rule-dashed")}`,cursor:"pointer",fontSize:12,color:s.bim("meta-fg"),letterSpacing:n?void 0:".08em"},children:r(e)})}function zc({children:e,href:i,onClick:n,title:r}){const o={display:"inline-block",padding:"4px 10px",border:`1px solid ${s.bim("rule")}`,fontSize:13,color:s.bim("body-fg"),lineHeight:1.5};return i||n?t.jsx("a",{href:i??"#",title:r,onClick:n?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),n())}:void 0,style:o,children:e}):t.jsx("span",{title:r,style:o,children:e})}function Nb({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function zb({volumes:e,unit:i,max:n=60}){const{t:r}=oe(),o=i??r("unit.volume"),[a,l]=b.useState(!1);if(!e.length)return null;const d=a?e:e.slice(0,n);return t.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[d.map(c=>t.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:`1px solid ${s.bim("rule")}`,color:s.bim("meta-fg")},children:c},c)),!a&&e.length>n&&t.jsxs("button",{type:"button",onClick:()=>l(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:`1px dashed ${s.bim("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:s.bim("meta-fg")},children:["+",e.length-n]}),t.jsx("span",{style:{padding:"2px 6px",color:s.bim("hint-fg")},children:o})]})}function Cb({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${s.bim("rule-strong")}`},children:e})}function Eb({spec:e}){const{convert:i}=xt();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${s.bim("rule-strong")}`,fontSize:11,color:s.bim("label-fg"),letterSpacing:".1em"},children:[t.jsx("span",{}),t.jsx("span",{children:i(e.mainLabel)}),t.jsx("span",{style:{display:"grid",gridTemplateColumns:e.columns.map(n=>n.width).join(" "),gap:12},children:e.columns.map(n=>t.jsx("span",{children:i(n.label)},n.label))})]})}function Rb({no:e,main:i,meta:n,spec:r}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:s.bim("hint-fg"),textAlign:"right"},children:e}),t.jsx("span",{style:{minWidth:0},children:i}),t.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(o=>o.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:n})]})}function Tb(e){return String(e+1).padStart(2,"0")}function Ib(){return t.jsx("span",{style:{color:s.bim("hint-fg")},children:"—"})}function Mb({open:e,onToggle:i,main:n,action:r,children:o}){return t.jsxs("div",{style:{borderBottom:`1px solid ${s.bim("rule")}`},children:[t.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[t.jsx("button",{type:"button",onClick:i,"aria-expanded":e,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${e?s.bim("accent"):s.bim("rule-dashed")}`,background:e?s.bim("accent"):"transparent",color:e?s.bim("page-bg"):s.bim("accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:n}),r]}),e&&o&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${s.bim("rule-accent-soft")}`,marginLeft:12},children:o})]})}function Cc(e){const i=[];for(let n=0;n<e.length;n++){if(e[n]!=="<")continue;const o=e[n+1];if(o===void 0||/[A-Za-z/!?>\s]/.test(o))continue;const l=e.indexOf(">",n+1);if(l<0)continue;const d=e.slice(n+1,l);d.includes(`
|
|
1410
|
+
`)||(i.push({start:n,end:l+1,inner:d}),n=l)}return i}function Ec(e,i){if(e.length<=i)return e;let n=i;for(const r of Cc(e)){if(r.start>=n)break;if(r.end>n){n=r.start>0?r.start:r.end;break}}return e.slice(0,n)}const Rc={fontSize:".78em",color:s.bim("meta-fg"),lineHeight:1.55},Ab={display:"inline-block",fontSize:"1em",lineHeight:1.15,padding:"0 .12em",margin:"0 .05em",border:"1px solid color-mix(in srgb, currentColor 40%, transparent)",borderRadius:2,verticalAlign:"baseline",whiteSpace:"nowrap"};function Tc(e,i,n,r){return e.map((o,a)=>{switch(o.type){case"text":return t.jsx(b.Fragment,{children:i(o.text)},a);case"jz":return t.jsx("span",{className:"bim-jiazhu",style:n===0?Rc:void 0,children:Tc(o.children,i,n+1,r)},a);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:o.label?r("detail.lacunaWith",{label:o.label}):r("detail.lacuna"),children:"□"},a);case"qz":return t.jsx("span",{className:"bim-qz guji-qz","data-guji-guess":o.guess,children:"□"},a);case"zi":return t.jsx("span",{className:"bim-zi guji-zi",title:r("detail.composedChar",{label:o.label}),style:Ab,children:o.label},a)}})}function Lt(e,i=r=>r,n){if(!e)return"";if(n!=null&&n.gujiMarkdown)return bb(e)?Tc(jc(e,{jzMaxLength:n.jzMaxLength}),i,0,n.t??s.getT("zh-Hant")):i(e);if(e.indexOf("<")<0)return i(e);const r=[];let o=0,a=0;for(const l of Cc(e))l.start>o&&r.push(t.jsx(b.Fragment,{children:i(e.slice(o,l.start))},a++)),r.push(t.jsx("span",{className:"bim-jiazhu",style:Rc,children:i(l.inner)},a++)),o=l.end;return o<e.length&&r.push(t.jsx(b.Fragment,{children:i(e.slice(o))},a++)),r}function Lb({label:e,children:i}){return t.jsxs("div",{style:{marginBottom:10},children:[e&&t.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:s.bim("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:s.bim("quiet-fg"),textAlign:"justify"},children:i})]})}function Pb({title:e,tag:i,children:n}){const{convert:r}=xt();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${s.bim("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(e)}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:s.bim("accent"),letterSpacing:".06em"},children:r(i)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:n})]})}function Ic({name:e,note:i,href:n,extra:r}){const o=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:14,minWidth:0},children:e}),t.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:s.bim("hint-fg"),flex:"none"},children:n?"↗":""}),i&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:s.bim("label-fg")},children:i})]}),a={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${s.bim("rule")}`,color:s.bim("body-fg"),alignItems:"baseline"};return t.jsxs(t.Fragment,{children:[n?t.jsx("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:a,children:o}):t.jsx("div",{style:a,children:o}),r]})}function Ob({item:e,siblings:i,showVolumes:n=!0,fallbackNote:r}){const{t:o,convert:a}=oe(),[l,d]=b.useState(!1),c=s.volumeStats(e),m=n&&!!c&&c.expected>0,p=(e.url?s.getDisplayNameFromUrl(e.url):void 0)||a(e.name),h=i?Pl(e,i):"",u=h?`${p}(${h})`:p;return t.jsx(Ic,{name:u,note:Kn(e,o)||r,href:s.resourceHref(e),extra:m?t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>d(f=>!f),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:s.bim("meta-fg"),borderBottom:`1px solid ${s.bim("rule")}`},children:l?o("detail.collapseVolumes"):o("detail.expandVolumes",{n:c.expected})}),l&&t.jsx(As,{item:e})]}):void 0})}function As({item:e}){return t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(e.volumes||[]).map((i,n)=>{const r=i.status==="missing";return i.url&&!r?t.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:s.bim("zebra-bg")},children:i.volume},n):t.jsx("span",{style:{padding:"1px 5px",color:r?s.bim("missing-fg"):s.bim("hint-fg"),textDecoration:r?"line-through":void 0},children:i.volume},n)})})}function Mc({label:e,items:i}){const{convert:n}=xt();return i.length?t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:s.bim("label-fg"),letterSpacing:".08em"},children:e}),i.map((r,o)=>t.jsx(zc,{children:n(r)},o))]}):null}function Fb({rows:e}){const i=e.filter(n=>n.items.length>0);return i.length?t.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:i.map(n=>t.jsx(Mc,{label:n.label,items:n.items},n.label))}):null}function Ac(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function Lc({left:e,right:i}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${s.bim("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:s.bim("aux-fg")},children:[t.jsx("span",{children:e}),i&&t.jsx("span",{style:{display:"flex",gap:16},children:i})]})}function Bb({children:e,action:i}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:s.bim("aux-fg"),borderBottom:`1px solid ${s.bim("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),i]})}function jt({id:e,label:i,onNavigate:n,renderLink:r,style:o,dense:a}){const l=It();return r?t.jsx(t.Fragment,{children:r(e,typeof i=="string"?i:void 0,{dense:a})}):t.jsx("a",{href:l(e),onClick:n?d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),n(e))}:void 0,style:o,children:i??e})}function Hb({href:e,children:i}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",children:[i," ",t.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const Pc="guji-table-v1";function Db(e){return!!e&&e.table_notation===Pc}const Wb=/^:::table(?:\{[^}]*\})?[ \t]*$/,Ub=/^:::[ \t]*$/;function Oc(e){const i=[];let n="";for(let r=0;r<e.length;r++){const o=e[r];if(o===":"&&e.startsWith(":zi[",r)){const l=xc(e,r+3);if(l>r+4){n+=e.slice(r,l+1),r=l;continue}}let a=null;if(o==="<"){const l=e[r+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(a=">")}if(a){const l=e.indexOf(a,r+1);if(l>0){n+=e.slice(r,l+1),r=l;continue}}o==="|"?(i.push(n),n=""):n+=o}return i.push(n),i.map(r=>r.trim())}const Kb=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Yb(e){if(e==="^")return{cont:!0};const i=Kb.exec(e),n=i[1].trim(),r=i[2]?Math.max(1,parseInt(i[2],10)):1,o=i[3]?Math.max(1,parseInt(i[3],10)):1,a=n==="_";return{cont:!1,cell:{text:a?"":n,empty:a,colspan:r,rowspan:o}}}function Fc(e,i=1){const n=[],r=[],o=[];let a=[];e.forEach((d,c)=>{const m=c+i+1;let p=d.trim();if(!p)return;let h=!1;p.startsWith("!")&&(h=!0,p=p.slice(1));const u=Oc(p).map(Yb),f=a.map(w=>w>0),g=a.map(w=>w>0?w-1:0),y=[];let v=0;for(const w of u){if(w.cont){f[v]||n.push(`第 ${m} 行第 ${v+1} 列:续格 ^ 上方没有跨行格`),v+=1;continue}const{cell:x}=w;for(let j=v;j<v+x.colspan;j++)if(f[j]){n.push(`第 ${m} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(x.rowspan>1)for(let j=v;j<v+x.colspan;j++)g[j]=x.rowspan-1;y.push(x),v+=x.colspan}for(let w=v;w<f.length;w++)f[w]&&n.push(`第 ${m} 行第 ${w+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let w=0;w<g.length;w++)g[w]===void 0&&(g[w]=0);a=g,r.push({header:h,cells:y}),o.push({width:v,line:m})});const l=o.reduce((d,c)=>Math.max(d,c.width),0);for(const d of o)d.width!==l&&n.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${l} 不符`);return a.some(d=>d>0)&&n.push("表尾:有跨行格超出了表的最后一行"),r.length===0&&n.push("空表"),{rows:r,columns:l,warnings:n}}function Ls(e){const i=e.split(`
|
|
1411
1411
|
`),n=[];let r=[];const o=()=>{if(r.length===0)return;const l=r.join(`
|
|
1412
|
-
`);r=[],n.push({type:"text",text:l})};let a=0;for(;a<i.length;){if(
|
|
1413
|
-
`)}),a=l+1;continue}}r.push(i[a]),a++}return o(),n.map((l,d)=>{var m,p;if(l.type!=="text")return l;let c=l.text;return((m=n[d-1])==null?void 0:m.type)==="table"&&(c=c.replace(/^\n+/,"")),((p=n[d+1])==null?void 0:p.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(l=>l.type!=="text"||l.text!=="")}const
|
|
1414
|
-
`).map(i=>i.trim()).filter(i=>i&&!Fs.test(i))}const
|
|
1415
|
-
`)){const o=r.trim();if(!o||Fs.test(o)||Os(o))continue;const a=o.replace(/<[^<>\n]*>/g,"").replace(/\s/g,"").length;i+=a,a>
|
|
1412
|
+
`);r=[],n.push({type:"text",text:l})};let a=0;for(;a<i.length;){if(Wb.test(i[a].trim())){let l=a+1;for(;l<i.length&&!Ub.test(i[l].trim());)l++;if(l<i.length){o();const d=i.slice(a+1,l);n.push({type:"table",table:Fc(d,a+1),source:i.slice(a,l+1).join(`
|
|
1413
|
+
`)}),a=l+1;continue}}r.push(i[a]),a++}return o(),n.map((l,d)=>{var m,p;if(l.type!=="text")return l;let c=l.text;return((m=n[d-1])==null?void 0:m.type)==="table"&&(c=c.replace(/^\n+/,"")),((p=n[d+1])==null?void 0:p.type)==="table"&&(c=c.replace(/\n+$/,"")),{type:"text",text:c}}).filter(l=>l.type!=="text"||l.text!=="")}const Gb={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Vb={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},qb=`1px solid ${s.bim("table-border")}`,Bc={border:qb,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Xb={...Bc,background:s.bim("table-head-bg"),fontWeight:600};function Ps({table:e,opts:i}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Gb,children:t.jsx("table",{className:"bim-guji-table",style:Vb,children:t.jsx("tbody",{children:e.rows.map((n,r)=>t.jsx("tr",{children:n.cells.map((o,a)=>{const l=n.header?"th":"td";return t.jsx(l,{colSpan:o.colspan>1?o.colspan:void 0,rowSpan:o.rowspan>1?o.rowspan:void 0,style:n.header?Xb:Bc,children:o.empty?null:Lt(o.text,void 0,i)},a)})},r))})})})}function Jb(e,i){return e.indexOf("**")<0?Lt(e,void 0,i):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((r,o)=>o%2===1?t.jsx("strong",{children:Lt(r.trim().slice(2,-2),void 0,i)},o):t.jsx(b.Fragment,{children:Lt(r,void 0,i)},o))}function Zb(e,i,n=!1){const r=n?{gujiMarkdown:!0}:void 0;return i?Ls(e).map((o,a)=>o.type==="table"?t.jsx(Ps,{table:o.table,opts:r},a):t.jsx(b.Fragment,{children:Jb(o.text,r)},a)):Lt(e,void 0,r)}const Qb=/^(#{1,6})\s+(.*)$/,eh=/^\*\*([^*\n]+)\*\*\s*$/;function Os(e){const i=e.match(Qb);if(i)return{level:i[1].length,text:i[2].trim()};const n=e.trim().match(eh);return n?{level:3,text:n[1].trim()}:null}const Fs=/^<!--.*-->$/;function Hc(e){return e.split(/\n\s*\n/).map(i=>i.trim()).filter(Boolean)}function Dc(e){return e.split(`
|
|
1414
|
+
`).map(i=>i.trim()).filter(i=>i&&!Fs.test(i))}const th=60;function Wc(e){let i=0,n=0;for(const r of e.split(`
|
|
1415
|
+
`)){const o=r.trim();if(!o||Fs.test(o)||Os(o))continue;const a=o.replace(/<[^<>\n]*>/g,"").replace(/\s/g,"").length;i+=a,a>th&&(n+=a)}return i>0&&n*2>=i}function ih(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Zn(e){if(e=ih(e),Wc(e))return"unknown";const i=Hc(e);if(i.length===0)return"unknown";if(i.length===1)return"catalog";const n=i.map(o=>Dc(o).length).filter(o=>o>0);if(n.length===0)return"unknown";const r=n.reduce((o,a)=>o+a,0)/n.length;return r<=4?"record":r>=8?"catalog":"unknown"}function nh(e){const i=e.split(`
|
|
1416
1416
|
`),n=[];let r=null,o=[];const a=()=>{n.push({heading:r,body:o.join(`
|
|
1417
1417
|
`)}),o=[]};for(const l of i){const d=Os(l);if(d){a(),r={kind:"heading",level:d.level,text:d.text};continue}o.push(l)}return a(),n}function Sa(e){const i=[];for(const n of e.split(`
|
|
1418
|
-
`)){const r=Os(n);if(r){i.push({kind:"heading",level:r.level,text:r.text});continue}const o=n.trim();!o||Fs.test(o)||i.push({kind:"body",text:n})}return i}function
|
|
1419
|
-
`)?"":i)}function
|
|
1420
|
-
`);let m=0;return t.jsx(t.Fragment,{children:c.map((p,h)=>{const u=p.match(Tr);if(u){const g=m++;if(l(u[1].length,u[2],g))return null;const{Tag:y,className:v}=d(u[1].length);return t.jsx(y,{className:v,children:n(u[2])},h)}if(!p.trim())return h>=2&&!!c[h-1].trim()&&!!c[h-2].trim()&&!Tr.test(c[h-1])&&!Tr.test(c[h-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},h):null;if(
|
|
1421
|
-
,。、;:?!「」『』()…—·`));function Ds(e){return!
|
|
1418
|
+
`)){const r=Os(n);if(r){i.push({kind:"heading",level:r.level,text:r.text});continue}const o=n.trim();!o||Fs.test(o)||i.push({kind:"body",text:n})}return i}function Uc(e){if(!e)return[];const i=Zn(e);if(i==="unknown")return Sa(e);const n=[];for(const{heading:r,body:o}of nh(e)){r&&n.push(r);const a=Hc(o);if(a.length!==0){if(Wc(o)){n.push(...Sa(o));continue}if(i==="record"){const l=a.join(" ");l&&n.push({kind:"body",text:l})}else for(const l of a){const d=Dc(l);d.length&&n.push({kind:"body",text:d.join(" ")})}}}return n}const rh={"「":"“","」":"”","『":"‘","』":"’"},sh={"“":"「","”":"」","‘":"『","’":"』"},oh=new Set(["《","》","〈","〉"]);function Kc(e,i){const n=i.quoteStyle==="modern"?rh:i.quoteStyle==="classic"?sh:null;let r="";for(const o of e)i.hideBookBrackets&&oh.has(o)||(r+=(n==null?void 0:n[o])??o);return r}const Yc=e=>e;function Bs(e){return e.showWorks?e.bookTitleStyle==="bracket"?"bracket":Kp(e.properNameMode)?"wavy":"bracket":"none"}function Gc(e,i=Yc,n="wavy"){if(e.indexOf("《")<0)return i(e);const r=[],o=/《([^《》\n]+)》/g;let a=0,l=0,d;for(;d=o.exec(e);){d.index>a&&r.push(t.jsx(b.Fragment,{children:i(e.slice(a,d.index))},l++));const c=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-sr",children:"《"}),i(d[1]),t.jsx("span",{className:"bim-rd-sr",children:"》"})]});r.push(n==="wavy"?t.jsx("span",{className:"bim-rd-pn",children:c},l++):t.jsx(b.Fragment,{children:c},l++)),a=d.index+d[0].length}return a===0?i(e):(a<e.length&&r.push(t.jsx(b.Fragment,{children:i(e.slice(a))},l++)),r)}function Qn(e,i={}){let n=i.renderText??Yc;const r=i.quoteStyle;if(r&&r!=="original"){const d=n;n=c=>d(Kc(c,{quoteStyle:r}))}const o=i.bookMarking??(i.properNames?"wavy":"bracket"),a=o==="bracket"?n:d=>Gc(d,n,o),l=i.gujiMarkdown?{gujiMarkdown:!0,t:i.t}:void 0;return Lt(e,a,l)}function $a(e,i,n){return e.indexOf("**")<0?i(e):e.split(/(\*\*[^*]+\*\*)/g).map((o,a)=>o.startsWith("**")&&o.endsWith("**")&&o.length>4?t.jsx("strong",{children:i(o.slice(2,-2))},`${n}-${a}`):t.jsx(b.Fragment,{children:i(o)},`${n}-${a}`))}const Tr=/^(#{1,6})\s+(.*)$/,ah=/^\s*<!--.*-->\s*$/;function Vc(e){return e.replace(/<!--[\s\S]*?-->/g,i=>i.includes(`
|
|
1419
|
+
`)?"":i)}function lh(e){return e<=1?2:e===2?3:4}function ch(){let e=1;return i=>{const n=lh(i),r=Math.min(n,e+1);return e=r,{Tag:`h${r}`,className:`bim-rd-hl${n}`}}}function Ln(e){return e?Zn(Vc(e))!=="unknown":!1}function dh(e){return/^\u3000{2}/.test(e)}const _a=e=>dh(e)?"bim-rd-noindent":void 0;function Na({text:e,mode:i,inline:n,dropTitle:r,onStart:o}){o==null||o();const a=Vc(e),l=(p,h,u)=>!!r&&u<=1&&p<=2&&h.trim()===r.trim(),d=ch();if(i==="paragraph"&&Zn(a)!=="unknown"){const p=Uc(a);return t.jsx(t.Fragment,{children:p.map((h,u)=>{if(h.kind==="heading"){if(l(h.level??1,h.text,u))return null;const{Tag:f,className:g}=d(h.level??1);return t.jsx(f,{className:g,children:n(h.text)},u)}return t.jsx("p",{className:_a(h.text),children:$a(h.text,n,u)},u)})})}const c=a.split(`
|
|
1420
|
+
`);let m=0;return t.jsx(t.Fragment,{children:c.map((p,h)=>{const u=p.match(Tr);if(u){const g=m++;if(l(u[1].length,u[2],g))return null;const{Tag:y,className:v}=d(u[1].length);return t.jsx(y,{className:v,children:n(u[2])},h)}if(!p.trim())return h>=2&&!!c[h-1].trim()&&!!c[h-2].trim()&&!Tr.test(c[h-1])&&!Tr.test(c[h-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},h):null;if(ah.test(p))return null;if(m++,/^\*\*[^*]+\*\*\s*$/.test(p.trim())){const{Tag:g,className:y}=d(3);return t.jsx(g,{className:y,children:n(p.trim().slice(2,-2))},h)}return t.jsx("p",{className:_a(p),children:$a(p,n,h)},h)})})}function mh(e){const{convert:i}=xt();return b.useMemo(()=>e?i(e):"",[e,i])}function Hs({text:e,mode:i,tables:n=!1,gujiMarkdown:r=!1,properNames:o=!1,bookMarking:a,quoteStyle:l,renderText:d,dropTitle:c}){const m=mh(e),{t:p,convert:h}=oe();let u=null;const f=!!d&&!ib(e,m,!l||l==="original"),g=d&&f?j=>d(j,{mdStart:u==null?void 0:u.align(j)}):d,y=f?()=>{u=ob(e)}:void 0,v=j=>Qn(j,{renderText:g,properNames:o,bookMarking:a,quoteStyle:l,gujiMarkdown:r,t:p}),w=r?{gujiMarkdown:!0,t:p}:void 0,x=c?h(c):void 0;return!n||m.indexOf(":::")<0?t.jsx(Na,{text:m,mode:i,inline:v,dropTitle:x,onStart:y}):t.jsx(t.Fragment,{children:Ls(m).map((j,S)=>j.type==="table"?t.jsx(Ps,{table:j.table,opts:w},S):t.jsx(Na,{text:j.text,mode:i,inline:v,dropTitle:S===0?x:void 0},S))})}const za={work:"work",book:"work",people:"people",person:"people",place:"place",office:"office",dynasty:"dynasty",reign:"reign"};function uh(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(za,e)&&za[e]||"other"}function ui(e){if(!e)return null;const i=e.trim(),n=/^book-index:\/\/(?:[A-Za-z]+\/)*([0-9A-Za-z]+)\/?$/.exec(i);if(n)return n[1];const r=/^bid:\\{1,2}([0-9A-Za-z]+)$/.exec(i);return r?r[1]:/^[0-9A-Za-z]+$/.test(i)?i:null}function Zt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function ft(e){return typeof e=="string"&&e?e:void 0}function ph(e){const i=e&&typeof e=="object"?e.candidates:void 0;if(!Array.isArray(i))return;const n=[];for(const r of i){if(!r||typeof r!="object"||Array.isArray(r))continue;const o=r,a={};ft(o.entity_id)!==void 0&&(a.entity_id=ft(o.entity_id)),ft(o.canonical_name)!==void 0&&(a.canonical_name=ft(o.canonical_name)),Zt(o.confidence)!==void 0&&(a.confidence=Zt(o.confidence)),n.push(a)}return n}function bh(e){if(!Array.isArray(e.targets))return;const i=[];for(const n of e.targets){if(!n||typeof n!="object"||Array.isArray(n))continue;const r=n,o=ui(ft(r.entity_id))??ui(ft(r.href));o&&i.push({id:o,...ft(r.canonical_name)?{canonicalName:ft(r.canonical_name)}:{},...ft(r.part)?{part:ft(r.part)}:{}})}return i.length>=2?i:void 0}function hh(e){const i=e&&typeof e=="object"?e.parts:void 0;if(!Array.isArray(i))return;const n=[];for(const r of i){if(!r||typeof r!="object")continue;const o=r,a=o.target??{},l=ui(ft(a.entity_id))??ui(ft(a.href)),d=o.offset;!l||!Array.isArray(d)||typeof d[0]!="number"||typeof d[1]!="number"||d[0]<0||d[1]<=d[0]||n.push({id:l,offset:[d[0],d[1]]})}return n.length?n:void 0}const ji=e=>e.start!==void 0&&e.end!==void 0;function qc(e){const i=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.entities)?e.entities:[],n=[];return i.forEach((r,o)=>{if(!r||typeof r!="object")return;const a=r,l=a.span??{},d=a.target??{},c=Zt(l.start_offset)??Zt(a.start_offset),m=Zt(l.end_offset)??Zt(a.end_offset),p=c!==void 0&&m!==void 0&&c>=0&&m>c,h=a.anchor??{},u=ft(h.start),f=ft(h.end);if(!p&&!!!(u&&f))return;const y=ft(d.status),v=y===void 0||y==="matched"?ui(ft(d.entity_id))??ui(ft(d.href))??void 0:void 0,w=Zt(d.confidence),x=y==="matched_multi"?bh(d):void 0,j=ph(a.ambiguous),S=hh(a.decomposition);n.push({...u&&f?{anchor:{start:u,end:f}}:{},key:ft(a.id)??`e${o}`,kind:uh(a.type),...p?{start:c,end:m}:{},text:ft(a.text),targetId:v,canonicalName:ft(d.canonical_name),...x?{targets:x}:{},confidence:Zt(a.confidence)??w,...w!==void 0?{targetConfidence:w}:{},...ft(d.level)!==void 0?{targetLevel:ft(d.level)}:{},...ft(d.note)!==void 0?{targetNote:ft(d.note)}:{},...ft(a.group)!==void 0?{group:ft(a.group)}:{},...j!==void 0?{candidates:j}:{},...S?{parts:S}:{}})}),n.sort((r,o)=>!ji(r)||!ji(o)?+!ji(r)-+!ji(o):r.start-o.start||o.end-r.end)}const fh=new Set(Array.from(`《》/<>\r
|
|
1421
|
+
,。、;:?!「」『』()…—·`));function Ds(e){return!fh.has(e)}function Xc(e,i,n=0){const r=[],o=Array.from(e);let a=0;for(const d of o)Ds(d)&&r.push(a),a+=d.length;const l=[];for(const d of i){if(!ji(d))continue;const c=d.start-n,m=d.end-n;if(c<0||m>r.length||m<=c)continue;const p=r[m-1],h=e.codePointAt(p)>65535?2:1;l.push({...d,start:r[c],end:p+h})}return l}function gh(e,i){return i.text?Array.from(e.slice(i.start,i.end)).filter(Ds).join("")===i.text:!0}function xh(e,i,n){if(!i.text)return null;let r=-1,o=Math.max(0,i.start-n);const a=i.start+n;for(;o<=a;){const l=e.indexOf(i.text,o);if(l<0||l>a)break;(r<0||Math.abs(l-i.start)<Math.abs(r-i.start))&&(r=l),o=l+1}return r<0?null:{...i,start:r,end:r+i.text.length}}function Jc(e,i,n=16){const r=[];for(const l of i){if(!ji(l))continue;let d={...l,start:Math.max(0,l.start),end:Math.min(e.length,l.end)};(d.end<=d.start||!gh(e,d))&&(d=xh(e,l,n)),d&&r.push(d)}r.sort((l,d)=>l.start-d.start||d.end-l.end);const o=[];let a=0;for(const l of r)l.start<a||(l.start>a&&o.push({type:"text",text:e.slice(a,l.start),start:a}),o.push({type:"entity",text:e.slice(l.start,l.end),start:l.start,span:l}),a=l.end);return a<e.length&&o.push({type:"text",text:e.slice(a),start:a}),o}const yh={off:[],lite:["people","place","dynasty"],full:["people","place","dynasty","office","reign","other"]};function jh(e,i,n){const r=(n==null?void 0:n.showWorks)!==!1,o=new Set(yh[i]);return e.filter(a=>a.kind==="work"?r:o.has(a.kind))}function kh(e,i,n,r=""){const o=`${r}
|
|
1422
1422
|
${n.versionKey??""}
|
|
1423
|
-
${i??""}`,[a,l]=b.useState({tag:"",images:null}),d=b.useRef(0);b.useEffect(()=>{const m=++d.current,p=u=>{m===d.current&&l({tag:o,images:u})};if(!e||!i){p(null);return}let h;try{h=e(i,n)}catch{p(null);return}if(!h||typeof h.then!="function"){p(h??null);return}h.then(u=>p(u??null),()=>p(null))},[e,i,n,o]);const c=a.tag===o;return{images:c?a.images:null,loading:!!e&&!!i&&!c}}function
|
|
1424
|
-
`),document.head.appendChild(c),()=>{for(const m of a)r.reg.delete(m);c.remove()}}function Kt(e,i,n,r){try{return n()}catch(o){return console.error(`[reader-plugin:${e.id}] ${i} 出错`,o),r}}function
|
|
1423
|
+
${i??""}`,[a,l]=b.useState({tag:"",images:null}),d=b.useRef(0);b.useEffect(()=>{const m=++d.current,p=u=>{m===d.current&&l({tag:o,images:u})};if(!e||!i){p(null);return}let h;try{h=e(i,n)}catch{p(null);return}if(!h||typeof h.then!="function"){p(h??null);return}h.then(u=>p(u??null),()=>p(null))},[e,i,n,o]);const c=a.tag===o;return{images:c?a.images:null,loading:!!e&&!!i&&!c}}function wh(){let e=null;const i=new Set;return{get:()=>e,set:n=>{n!==e&&(e=n,i.forEach(r=>r()))},subscribe:n=>(i.add(n),()=>{i.delete(n)})}}function vh(e){return b.useSyncExternalStore(e.subscribe,e.get,e.get)}function Ca({store:e,children:i}){const n=vh(e);return b.createElement(b.Fragment,null,i(n))}const Pn="t:",Sh=/\s/,$h="bim-text-highlights";function On(e){const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:o=>{var a;return(a=o.parentElement)!=null&&a.closest('script,style,[aria-hidden="true"]')?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}});let n="";const r=[];for(let o=i.nextNode();o;o=i.nextNode()){const a=o.data;for(let l=0;l<a.length;l++)Sh.test(a[l])||(n+=a[l],r.push({node:o,off:l}))}return{text:n,at:r}}function _h(e){const i=[];for(let n=0;n<e.text.length;n++)i.push({anchor:`${Pn}${n}:1`,char:e.text[n],page:0,col:0});return i}function Nh(){var n;const e=(n=globalThis.CSS)==null?void 0:n.highlights,i=globalThis.Highlight;return!e||!i?null:{reg:e,make:r=>new i(...r)}}const zh={accent:{bg:s.bim("accent-bg")},warn:{bg:s.bim("highlight-bg")},muted:{fg:s.bim("meta-fg")},add:{bg:s.bim("check-fine-bg"),fg:s.bim("check-fine-fg")},omit:{bg:s.bim("danger-soft-bg"),fg:s.bim("danger")}},Ch={solid:"underline",dotted:"underline dotted",dashed:"underline dashed",wavy:"underline wavy"};function Eh(e){const i=e.tone?zh[e.tone]:void 0,n=e.bg??(i==null?void 0:i.bg)??(e.focus?s.bim("accent-bg"):void 0),r=e.fg??(i==null?void 0:i.fg),o=e.underline?Ch[e.underline]:e.focus?"underline":void 0;return[n&&`background-color:${n}`,r&&`color:${r}`,o&&`text-decoration:${o}`].filter(Boolean).join(";")}function Rh(e,i,n){const r=Nh();if(!r||!i||i.size===0)return()=>{};const o=new Map;if(i.forEach((m,p)=>{const h=/^t:(\d+):1$/.exec(p);if(!h)return;const u=Eh(m);if(!u)return;const f=o.get(u);f?f.push(Number(h[1])):o.set(u,[Number(h[1])])}),o.size===0)return()=>{};const a=[],l=[];let d=0;o.forEach((m,p)=>{m.sort((v,w)=>v-w);const h=[];let u=-1,f=-2;const g=()=>{if(u<0)return;const v=e.at[u],w=e.at[f];if(!v||!w)return;let x=u;for(let j=u+1;j<=f+1;j++)if(j>f||e.at[j].node!==e.at[x].node){const S=e.at[x],$=e.at[j-1],N=document.createRange();N.setStart(S.node,S.off),N.setEnd($.node,$.off+1),h.push(N),x=j}};for(const v of m){if(v===f+1){f=v;continue}g(),u=f=v}g();const y=`bim-cd-${n}-${d++}`;a.push(y),r.reg.set(y,r.make(h)),l.push(`::highlight(${y}){${p}}`)});const c=document.createElement("style");return c.setAttribute("data-bim-text-highlights",n),c.id=`${$h}-${n}`,c.textContent=l.join(`
|
|
1424
|
+
`),document.head.appendChild(c),()=>{for(const m of a)r.reg.delete(m);c.remove()}}function Kt(e,i,n,r){try{return n()}catch(o){return console.error(`[reader-plugin:${e.id}] ${i} 出错`,o),r}}function Zc(e){const i=new Map;for(const n of e)n.forEach((r,o)=>{const a=i.get(o);if(!a){i.set(o,r);return}const l={...a,...Th(r)};(a.focus||r.focus)&&(l.focus=!0),a.title&&r.title&&a.title!==r.title&&(l.title=`${a.title};${r.title}`),i.set(o,l)});return i}function Th(e){const i={};for(const n of Object.keys(e))e[n]!==void 0&&(i[n]=e[n]);return i}function Ih(e,i){return e.tone===i.tone&&e.underline===i.underline&&e.sub===i.sub&&e.insertAfter===i.insertAfter&&e.bg===i.bg&&e.fg===i.fg&&e.title===i.title&&!!e.focus==!!i.focus}const Ir=[],yn=new Map,Mr=500,Mh=120;function Ah(e,i,n){if(!e)return null;const r=On(e).text;for(const o of[i,n==null?void 0:n(i)]){const a=o==null?void 0:o.replace(/\s+/g,"");if(!a)continue;const l=r.indexOf(a);if(l>=0)return`${Pn}${l}:${a.length}`}return null}function Ea(e,i){const n=/^t:(\d+):(\d+)$/.exec(i);if(!e||!n)return null;const{at:r}=On(e),o=r[Number(n[1])],a=r[Math.min(r.length-1,Number(n[1])+Number(n[2])-1)];if(!o||!a)return null;const l=document.createRange();return l.setStart(o.node,o.off),l.setEnd(a.node,a.off+1),l}function Lh(e){let i=0;for(let n=0;n<e.length;n++)i=i*31+e.charCodeAt(n)|0;return Math.abs(i)}function Ph(){const[e,i]=b.useState(!1);return b.useEffect(()=>{var o;if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(Cs),r=()=>i(!n.matches);return r(),(o=n.addEventListener)==null||o.call(n,"change",r),()=>{var a;return(a=n.removeEventListener)==null?void 0:a.call(n,"change",r)}},[]),e?"narrow":"wide"}const Oh={settings:[],toolbar:{},overlay:null,decorations:void 0,onCellClick:()=>{},onCellHover:()=>{}};function Fh(e){const{plugins:i,ctx:n,prefs:r,setPrefs:o,t:a,convert:l,pages:d,textRootRef:c,shellTextRef:m,selectedCharIds:p,scrollToAnchor:h}=e,u=n?`${n.entryId}
|
|
1425
1425
|
${n.versionKey}
|
|
1426
1426
|
${n.chapterKey}`:null,f=i.filter(K=>K.onChapter).map(K=>K.id).join(`
|
|
1427
|
-
`),g=b.useRef({plugins:i,ctx:n});g.current={plugins:i,ctx:n};const[y,v]=b.useState({key:null,map:yn});b.useEffect(()=>{const K=g.current.ctx;if(!u||!K){v({key:null,map:yn});return}let V=!1;v({key:u,map:yn});for(const re of g.current.plugins){if(!re.onChapter)continue;const X=ue=>{V||v(fe=>fe.key===u?{key:u,map:new Map(fe.map).set(re.id,ue)}:fe)},I=Kt(re,"onChapter",()=>re.onChapter(K),void 0);Promise.resolve(I).then(X,ue=>{console.error(`[reader-plugin:${re.id}] onChapter 出错`,ue)})}return()=>{V=!0}},[u,f]);const w=y.key===u?y.map:yn,[x,j]=b.useState(0),S=b.useCallback(()=>j(K=>K+1),[]),$=b.useMemo(()=>{if(!d||d.length===0||i.length===0)return Ir;const K=[];for(const V of d)for(const re of V.columns)for(const X of re.chars)X.fig||K.push({anchor:X.id,char:X.char,page:V.page,col:re.col});return K},[d,i.length]),N=$.length===0&&i.some(K=>K.decorate),[z,C]=b.useState(Ir);b.useEffect(()=>{const K=m.current;if(!N||!K){C(Ir);return}let V;const re=()=>{const I=Sh(On(K));C(ue=>ue.length===I.length&&ue.every((fe,ze)=>fe.char===I[ze].char)?ue:I)};if(re(),typeof MutationObserver>"u")return;const X=new MutationObserver(()=>{clearTimeout(V),V=setTimeout(re,80)});return X.observe(K,{childList:!0,subtree:!0,characterData:!0}),()=>{X.disconnect(),clearTimeout(V)}},[N,u,m]);const U=b.useMemo(()=>{const K=new Map;for(const V of $)K.set(V.anchor,V);return K},[$]),R=b.useCallback(K=>{var X,I;if(K.startsWith(Pn))return((I=(X=Ea(m.current,K))==null?void 0:X.getBoundingClientRect)==null?void 0:I.call(X))??null;const V=c.current;if(!V)return null;const re=V.querySelector(`[data-char-id="${K.replace(/["\\]/g,"\\$&")}"]`);return re?re.getBoundingClientRect():null},[c,m]),L=b.useCallback(K=>{var fe,ze;if("cp"in K)return((fe=$[K.cp])==null?void 0:fe.anchor)??null;if(!K.text)return null;if($.length===0)return Ih(m.current,K.text,l);let V="";const re=[];for(const B of $)re.push(V.length),V+=B.char;const X=V.indexOf(K.text);if(X<0)return null;let I=0,ue=re.length-1;for(;I<ue;){const B=I+ue+1>>1;re[B]<=X?I=B:ue=B-1}return((ze=$[I])==null?void 0:ze.anchor)??null},[$,m,l]),F=b.useCallback(K=>{var re,X;if(!K.startsWith(Pn)){h(K);return}const V=(X=(re=Ea(m.current,K))==null?void 0:re.getBoundingClientRect)==null?void 0:X.call(re);V&&window.scrollTo({top:window.scrollY+V.top-Th,behavior:"instant"})},[h,m]),T=b.useMemo(()=>n?{ctx:n,state:K=>w.get(K),cells:$,textCells:z,scrollTo:F,rectOf:R,locate:L,refresh:S,prefs:r,setPref:o,t:a,convert:l}:null,[n,w,$,z,F,R,L,S,r,o,a,l,x]),Z=b.useMemo(()=>{if(!T)return;const K=[];for(const V of i){if(!V.decorate)continue;const re=Kt(V,"decorate",()=>V.decorate(T),void 0);re&&re.size>0&&K.push(re)}return K.length===0?void 0:K.length===1?K[0]:Xc(K)},[i,T]);b.useEffect(()=>{const K=m.current;if(!($.length>0||!K||!Z||Z.size===0))return Ch(On(K),Z,u?String(Mh(u)):"x")},[$.length,Z,m,u,z]);const O=b.useCallback(K=>{var V;return{anchor:K,char:((V=U.get(K))==null?void 0:V.char)??"",rect:R(K)}},[U,R]),ae=b.useCallback(K=>{var re;if(!T)return;const V=O(K);for(const X of i)(re=X.onCell)!=null&&re.click&&Kt(X,"onCell.click",()=>X.onCell.click(V,T),void 0)},[T,i,O]),ce=b.useCallback(K=>{var re;if(!T)return;const V=K?O(K):null;for(const X of i)(re=X.onCell)!=null&&re.hover&&Kt(X,"onCell.hover",()=>X.onCell.hover(V,T),void 0)},[T,i,O]),Ee=$.length===0&&i.some(K=>K.selectionActions),[we,ye]=b.useState(null);b.useEffect(()=>{if(!Ee){ye(null);return}const K=()=>{var pe,Te;const V=document.getSelection(),re=m.current;if(!V||V.isCollapsed||V.rangeCount===0||!re){ye(null);return}const X=V.getRangeAt(0),I=X.commonAncestorContainer,ue=I instanceof Element?I:I.parentElement;if(!re.contains(I)||ue!=null&&ue.closest('input,textarea,button,select,[contenteditable="true"]')){ye(null);return}const fe=V.toString().trim().slice(0,Mr);if(!fe){ye(null);return}const ze=(pe=X.getClientRects)==null?void 0:pe.call(X),B=(ze&&ze.length>0?ze[ze.length-1]:(Te=X.getBoundingClientRect)==null?void 0:Te.call(X))??null;ye(ve=>ve&&ve.text===fe?ve:{text:fe,rect:B})};return document.addEventListener("selectionchange",K),()=>document.removeEventListener("selectionchange",K)},[Ee,m]),b.useEffect(()=>{ye(null)},[u]);const Q=b.useMemo(()=>{if(!T||!i.some(X=>X.selectionActions))return[];if($.length===0){if(!we)return[];const X={anchors:[],text:we.text,rect:we.rect};return i.flatMap(I=>I.selectionActions?Kt(I,"selectionActions",()=>I.selectionActions(X,T),[]):[])}if(p.size===0)return[];const K=[];let V="";for(const X of $)p.has(X.anchor)&&(K.push(X.anchor),V.length<Mr&&(V+=X.char));if(K.length===0)return[];const re={anchors:K,text:V.slice(0,Mr),rect:R(K[K.length-1])};return i.flatMap(X=>X.selectionActions?Kt(X,"selectionActions",()=>X.selectionActions(re,T),[]):[])},[T,i,p,$,R,we]),Ne=b.useMemo(()=>T?i.filter(K=>K.settings).map((K,V)=>({p:K,i:V,order:K.settings.order??100})).sort((K,V)=>K.order-V.order||K.i-V.i).map(({p:K})=>({key:K.id,group:K.settings.group,title:K.settings.title,node:Kt(K,"settings.render",()=>K.settings.render(T),null)})):[],[i,T]),W=b.useMemo(()=>{if(!T)return{};const K=V=>{const re=i.filter(X=>{var I;return((I=X.toolbar)==null?void 0:I.slot)===V}).map((X,I)=>({p:X,i:I,order:X.toolbar.order??100})).sort((X,I)=>X.order-I.order||X.i-I.i).map(({p:X})=>t.jsx(b.Fragment,{children:Kt(X,"toolbar.render",()=>X.toolbar.render(T),null)},X.id));return re.length>0?t.jsx(t.Fragment,{children:re}):void 0};return{subtitle:K("subtitle"),actions:K("actions")}},[i,T]),je=b.useMemo(()=>{if(!T)return null;const K=i.filter(V=>V.overlay).map(V=>t.jsx(b.Fragment,{children:Kt(V,"overlay",()=>V.overlay(T),null)},V.id));return K.length===0&&Q.length===0?null:t.jsxs(t.Fragment,{children:[K,Q.length>0&&t.jsx("div",{className:"bim-rd-selbar",role:"toolbar","aria-label":a("reader.selectionActions"),"data-testid":"reader-selbar",children:Q.map(V=>t.jsx("button",{type:"button",title:V.title,onMouseDown:re=>re.preventDefault(),onClick:V.onClick,children:V.label},V.key))})]})},[i,T,Q,a]);return i.length===0?Lh:{settings:Ne,toolbar:W,overlay:je,decorations:Z,onCellClick:ae,onCellHover:ce}}function Oh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(s.TEXT_QUALITY_LABELS,e)?e:null}function Fh(e){if(e==="none")return{color:s.bim("quality-none"),fontWeight:400};if(e==="placeholder")return{color:s.bim("quality-placeholder"),fontWeight:400}}const Bh={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Jc="\0";function Hh(e,i,n){const[r,o=""]=e.split(Jc);return t.jsxs(t.Fragment,{children:[r,t.jsx(rc,{text:i,convert:n}),o]})}function Ft(e){return typeof e!="string"?"":Bh[e]??e}const Dh=["〇","一","二","三","四","五","六","七","八","九"],Ra=["","十","百","千"],Wh=["","萬","億"];function Ws(e){if(e===0)return"〇";if(e<0)return`負${Ws(-e)}`;const i=[];let n=e,r=0;for(;n>0;){const o=n%1e4;o>0?i.unshift(Uh(o,r>0)+Wh[r]):i.length>0&&i.unshift("〇"),n=Math.floor(n/1e4),r++}return i.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Uh(e,i){const n=[];let r=e;for(;r>0;)n.unshift(r%10),r=Math.floor(r/10);let o="";for(let a=0;a<n.length;a++){const l=n[a],d=n.length-1-a;l===0?o&&!o.endsWith("〇")&&(o+="〇"):l===1&&d===1&&a===0&&!i?o+=Ra[d]:o+=Dh[l]+Ra[d]}return o.replace(/〇$/,"")}let Ki=null,jn=null;const Fn=new Set;function Kh(){return Ki?Promise.resolve():jn||(jn=import("opencc-js/t2cn").then(e=>{const i=e.Converter({from:"t",to:"cn"});Ki=n=>i(vi.normalizeVariants(n)),Fn.forEach(n=>n())}).catch(()=>{Ki=e=>e,Fn.forEach(e=>e())}),jn)}const Yh=e=>e;function pi(){const[,e]=b.useState(0);return b.useEffect(()=>{if(Ki)return;const i=()=>e(n=>n+1);return Fn.add(i),Kh(),()=>{Fn.delete(i)}},[]),Ki??Yh}function Ni(e,i){return i(e).toLowerCase()}const Gh=s.bim("highlight-bg");function rn(e,i,n){if(!i)return e;const r=Ni(i,n);if(!r)return e;const o=Ni(e,n),a=Array.from(e),l=Array.from(o);if(l.length!==a.length)return e;const d=new Map;let c=0;l.forEach((g,y)=>{d.set(c,y),c+=g.length});const m=Array.from(r).length,p=[];let h=0,u=0,f=0;for(;h<a.length;){const g=o.indexOf(r,u),y=g===-1?void 0:d.get(g);if(g===-1){p.push(a.slice(h).join(""));break}if(y===void 0){u=g+1;continue}y>h&&p.push(a.slice(h,y).join("")),p.push(t.jsx("mark",{style:{background:Gh,padding:0,color:"inherit"},children:a.slice(y,y+m).join("")},f++)),h=y+m,u=g+r.length}return t.jsx(t.Fragment,{children:p})}function Us(e,i,n,r){if(!i)return!0;const o=Ni(i,r);return(n?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(l=>typeof l=="string"&&Ni(l,r).includes(o))}function Vh(e,i,n){return i?Ni(e,n).includes(Ni(i,n)):!0}const Ks={类:s.bim("section-lei"),书:s.bim("section-shu"),序:s.bim("section-xu"),结语:s.bim("section-jieyu"),注释:s.bim("section-zhushi")},qh={考证:s.bim("section-kaozhen")};function Ys(e,i,n){return e.collated.sectionType[i]??n(i)}function Zc(e){var r;const i=e.files.length,n=((r=e.children)==null?void 0:r.reduce((o,a)=>o+Zc(a),0))||0;return i+n}function Xh(e,i){const n=[],r=l=>{var d;n.push(...l.files),(d=l.children)==null||d.forEach(r)};if(r(e),n.length===0)return;const o=n.map(l=>i[l]);if(o.every(l=>l===void 0))return;if(o.some(l=>l==="loading"))return"loading";let a=0;for(const l of o)typeof l=="number"&&(a+=l);return a}const Jh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Gs({enabled:e,expanded:i,onClick:n,style:r,children:o}){return e?t.jsx("button",{type:"button","aria-expanded":i,onClick:n,style:{...Jh,...r},children:o}):t.jsx("span",{style:r,children:o})}function Zh({type:e}){const{convert:i,messages:n}=oe(),r=Ft(e),o=Ks[r]||s.bim("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:o,border:`1px solid ${o}40`,borderRadius:"2px",background:`${o}08`,flexShrink:0},children:Ys(n,r,i)})}function Qh({section:e,onNavigate:i,highlightQuery:n="",no:r,showUnlinked:o=!1,domId:a}){const{t:l,convert:d}=oe(),c=It(),m=pi(),p=j=>j?Lt(d(j),S=>n?rn(S,n,m):S,{t:l}):"",[h,u]=b.useState(!1),f=!!e.summary,g=!!e.comment,y=!!e.additional_comment,v=!!(e.content&&e.content.length>60),w=f||g||y||v;b.useEffect(()=>{n&&u(!0)},[n]);const x=!h&&v?zc(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${s.bim("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>w&&u(!h),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:w?"pointer":"default",userSelect:"none"},children:[r!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:s.bim("label-fg")},children:r}),t.jsxs(Gs,{enabled:w,expanded:h,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[w&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:s.bim("desc-fg"),transition:"transform 0.15s",transform:h?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:s.bim("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",p(e.book_title),"》"]}):p(e.title),e.n_juan!=null&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d(Ws(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!h&&x&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:s.bim("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(x)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:p(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&i&&t.jsx("a",{href:c(e.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),i(e.work_id))},style:{fontSize:"11px",color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:l("collated.viewWork"),"aria-label":l("collated.viewWorkOf",{title:d(e.book_title||e.title)}),children:l("collated.workArrow")}),o&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),h&&w&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${s.bim("widget-border")}`,background:s.bim("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),marginBottom:"8px"},children:p(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${s.bim("primary")}`,background:`color-mix(in srgb, ${s.bim("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:s.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:p(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${s.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:s.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${s.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:s.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.additional_comment)})]}),v&&!f&&!g&&!y&&t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function ef({section:e,highlightQuery:i=""}){const{t:n,convert:r}=oe(),o=pi(),a=m=>m?Lt(r(m),p=>i?rn(p,i,o):p,{t:n}):"",[l,d]=b.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Gs,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Zh,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:s.bim("fg")},children:a(e.title)}),c&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:s.bim("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&c&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Ks[Ft(e.type)]||s.bim("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:s.bim("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})})]})}const tf=100;function Vs(e){return Ft(e.type)!=="page_header"?!1:(e.content||"").length>=tf}function nf({section:e,highlightQuery:i=""}){const{t:n,convert:r,messages:o}=oe(),a=pi();if(Ft(e.type)==="page_header"&&!Vs(e)||!e.content&&!e.title)return null;const l=r((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1428
|
-
`)),d=Lt(l,h=>i?rn(h,i,a):h,{t:n}),c=Ft(e.type),m=Ks[c]||s.bim("desc-fg"),p=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:p?"10px 12px":"6px 0",margin:p?"8px 0":void 0,fontSize:"13px",color:s.bim("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:p?`3px solid ${m}40`:void 0,background:p?s.bim("bg"):void 0,borderRadius:p?"0 4px 4px 0":void 0,position:"relative"},children:[p&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:m,marginRight:"8px",padding:"1px 5px",border:`1px solid ${m}40`,borderRadius:"2px",background:`${m}08`,verticalAlign:"middle"},children:Ys(o,c,r)}),d]})}function rf(e,i,n){const[r,o]=b.useState({});return b.useEffect(()=>{var m;if(!i||e.length===0)return;let a=!1;const l=e.filter(p=>{var h;return!((h=n==null?void 0:n.current)!=null&&h.has(p))}),d={};for(const p of e)(m=n==null?void 0:n.current)!=null&&m.has(p)&&(d[p]=n.current.get(p));if(Object.keys(d).length>0&&o(d),l.length===0)return;const c=async p=>{var h;try{if(i.getEntry){const v=await i.getEntry(p);if(v)return{title:v.title,author:v.author}}const u=await i.getItem(p);if(!u)return null;const f=u.title||p,g=u.authors,y=(h=g==null?void 0:g[0])==null?void 0:h.name;return{title:f,author:y}}catch{return null}};return Promise.all(l.map(async p=>{var u;const h=await c(p);return(u=n==null?void 0:n.current)==null||u.set(p,h),[p,h]})).then(p=>{a||o(h=>{const u={...h};for(const[f,g]of p)u[f]=g;return u})}),()=>{a=!0}},[e.join(","),i]),r}function sf({section:e,onNavigate:i,transport:n,workLabelCache:r,highlightQuery:o=""}){const{t:a,convert:l,messages:d}=oe(),c=It(),m=pi(),p=S=>S?Lt(l(S),$=>o?rn($,o,m):$,{t:a}):"",[h,u]=b.useState(!1);b.useEffect(()=>{o&&u(!0)},[o]);const f=Ft(e.type),g=qh[f]||s.bim("desc-fg"),y=!!e.content,v=e.work_ids||[],w=v.length>1,x=rf(w?v:[],n,r),j=y&&!h&&e.content.length>80?zc(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${s.bim("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>y&&u(!h),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[t.jsxs(Gs,{enabled:y,expanded:h,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[y&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:s.bim("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:h?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:s.bim("fg"),lineHeight:1.6},children:e.header_line?p(e.header_line):p(e.title)}),!h&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.7},children:p(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[v.length===1&&i&&t.jsx("a",{href:c(v[0]),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),i(v[0]))},style:{fontSize:"11px",color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),w&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:v.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:Ys(d,f,l)})]})]}),w&&i&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:v.map(S=>{const $=x[S],N=$?`${l($.title)}${$.author?`(${l($.author)})`:""}`:S.slice(0,8)+"…";return t.jsxs("a",{href:c(S),onClick:z=>{z.metaKey||z.ctrlKey||(z.preventDefault(),z.stopPropagation(),i(S))},style:{fontSize:"12px",color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:S,children:["→",N]},S)})}),h&&y&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:s.bim("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${s.bim("widget-border")}`,fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:p(e.comment)})]})]})}function of({juan:e,searchQuery:i,onNavigate:n,transport:r,workLabelCache:o}){const{t:a}=oe(),l=pi(),d=i.trim(),c=b.useMemo(()=>d?e.sections.filter(m=>Us(m,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:c.map((m,p)=>t.jsx(sf,{section:m,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:d},p))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:s.bim("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function af(){let e=!1;return i=>i==="类"?(e=!0,"h2"):e?"h3":"h2"}function lf({sections:e,onNavigate:i,inline:n,workLinks:r=!0}){const o=It(),{t:a,convert:l}=oe(),d=af();return t.jsx(t.Fragment,{children:e.map((c,m)=>{const p=Ft(c.type);if(p==="page_header"&&!Vs(c))return null;if(p==="类")return t.jsxs(b.Fragment,{children:[b.createElement(d("类"),null,n(l(c.title))),c.content&&t.jsx("p",{children:n(l(c.content))})]},m);if(p==="书"||p==="诗"||p==="考证"||p==="注释"){const h=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:Ws(c.n_juan)}):""}`:c.title,u=n(l(h));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${m}`,children:[b.createElement(d("条目"),{className:"bim-rd-entry-h"},c.work_id&&i&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:o(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i(c.work_id))},title:a("collated.viewWork"),children:u}),t.jsx("a",{className:"bim-rd-wl",href:o(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(h)}),children:a("collated.workArrow")})]}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:n(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,g)=>t.jsx("p",{children:n(l(f))},g)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.summary")}),n(l(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.comment")}),n(l(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.additionalComment")}),n(l(c.additional_comment))]})]},m)}return p==="小计"&&c.title?t.jsx("p",{children:n(l(c.title))},m):c.content?t.jsx("p",{children:n(l(c.content))},m):null})})}function Qc(e){return e.some(i=>{const n=Ft(i.type);return n==="书"||n==="诗"||n==="考证"||n==="注释"||n==="类"||(n==="序"||n==="结语")&&!!i.content||n==="page_header"&&Vs(i)})}function cf({juan:e,rawText:i,positionLabel:n,groupLabel:r,index:o,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:m,view:p,onViewChange:h}){var Ne;const{t:u,convert:f,messages:g}=oe(),y=pi(),[v,w]=b.useState("text"),x=p??v,j=W=>{w(W),h==null||h(W)},S=a.trim(),$=(o==null?void 0:o.type)==="kaozhen",N=b.useCallback(W=>S?rn(W,S,y):W,[S,y]),z=Bs(m),C=W=>Qn(W,{renderText:N,bookMarking:z,quoteStyle:m.quoteStyle,t:u}),U=b.useMemo(()=>S?e.sections.filter(W=>Us(W,S,$,y)):e.sections,[e.sections,S,$,y]),R=(W,je)=>je.filter(K=>Ft(K.type)===W).length,L=R("书",e.sections),F=R("诗",e.sections),T=R("考证",e.sections);let Z="";$?Z=S?u("collated.countTiaoOf",{m:R("考证",U),n:T}):u("collated.countTiao",{n:T}):F>0?Z=S?u("collated.countPoemsOf",{m:R("诗",U),n:F}):u("collated.countPoems",{n:F}):L>0&&(Z=S?u("collated.countBooksOf",{m:R("书",U),n:L}):u("collated.countBooks",{n:L}));const O=o!=null&&o.text_quality?Oh(o.text_quality.grade):null,ae=[];if(Z&&ae.push(Z),$&&(o!=null&&o.target_source)&&ae.push(t.jsx(t.Fragment,{children:u("collated.kaozhenTarget",{target:f(o.target_source)})})),O){const W=t.jsx("span",{className:"bim-rd-grade",style:Fh(O),children:g.collated.qualityLabel[O]});ae.push(t.jsx("span",{title:g.collated.qualityCriteria[O],children:(Ne=o==null?void 0:o.text_quality)!=null&&Ne.source_note?t.jsxs(t.Fragment,{children:[Hh(u("collated.baseText",{note:Jc}),o.text_quality.source_note,f),W]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),W]})}))}e.source_url&&ae.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:u("collated.originalSource")}));const ce=!$&&Qc(e.sections),Ee=!!i&&(!ce||m.readingMode==="paragraph"&&Ln(i)),we=!$&&(ce||!!i),ye=$||!we?"entries":x;let Q=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(n||r)&&t.jsxs("p",{className:"bim-rd-kicker",children:[n,n&&r&&t.jsx("span",{className:"bim-rd-dot"}),r&&f(r)]}),t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),ae.length>0&&t.jsx("p",{className:"bim-rd-meta",children:ae.map((W,je)=>t.jsxs(b.Fragment,{children:[je>0&&t.jsx("span",{className:"bim-rd-dot"}),W]},je))}),we&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":u("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":ye==="text",onClick:()=>j("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":ye==="entries",onClick:()=>j("entries"),children:u("collated.viewEntries")})]})]}),ye==="text"&&t.jsx("article",{className:"bim-rd-prose",children:Ee?t.jsx(Hs,{text:i,mode:m.readingMode,bookMarking:z,quoteStyle:m.quoteStyle,renderText:N,dropTitle:e.title}):t.jsx(lf,{sections:e.sections,onNavigate:l,inline:C,workLinks:m.workLinks})}),ye==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:$?t.jsx(of,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[U.some(W=>["书","诗","考证"].includes(Ft(W.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:u("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:u("collated.rowHeadTitle")}),t.jsx("span",{children:u("collated.rowHeadWork")})]}),U.map((W,je)=>{const K=Ft(W.type);return K==="书"||K==="诗"||K==="考证"?(Q+=1,t.jsx(Qh,{domId:`rd-e-${e.sections.indexOf(W)}`,section:W,onNavigate:m.workLinks?l:void 0,highlightQuery:S,no:Q,showUnlinked:m.workLinks&&!!l},je)):K==="类"?t.jsx(ef,{section:W,highlightQuery:S},je):t.jsx(nf,{section:W,highlightQuery:S},je)}),U.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function df(e){const{resetKey:i,load:n,files:r,activeFile:o,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,m=pi(),p=b.useRef(new Map),[h,u]=b.useState({}),[f,g]=b.useState({}),y=b.useCallback((w,x)=>{const j=x==null?void 0:x.title;j&&g(S=>S[w]===j?S:{...S,[w]:j})},[]);b.useEffect(()=>{o&&a&&(p.current.set(o,{juan:a,rawText:l}),y(o,a))},[o,a,l,y]),b.useEffect(()=>{p.current.clear(),u({}),g({})},[i]);const v=b.useCallback((w,x)=>{let j=0;if(w.juan)for(const S of w.juan.sections)Us(S,x,c,m)&&j++;return j===0&&w.rawText&&Vh(w.rawText,x,m)&&(j=1),j},[c,m]);return b.useEffect(()=>{const w=d.trim();if(!w){u({});return}if(!n||r.length===0)return;let x=!1;const j={},S=[];for(const U of r){const R=p.current.get(U);R?j[U]=v(R,w):(j[U]="loading",S.push(U))}u(j);const $=8;let N=0;const z=async()=>{for(;N<S.length;){if(x)return;const U=N++,R=S[U];try{const L=await n(R),F=L.juan;if(p.current.set(R,L),y(R,F),x)return;u(T=>({...T,[R]:v(L,w)}))}catch{if(x)return;u(L=>({...L,[R]:0}))}}},C=Array.from({length:Math.min($,S.length)},()=>z());return Promise.all(C),()=>{x=!0}},[d,i,n,r.join(","),v,m,y]),{matchStates:h,titles:f}}function mf({juan:e,view:i,onView:n,textHasEntries:r}){const{t:o,convert:a}=oe(),l=e.sections.map((p,h)=>({s:p,i:h,t:Ft(p.type)})).filter(p=>p.t==="书"||p.t==="诗");if(l.length===0)return null;const d=l.filter(p=>!!p.s.work_id).length,c=l.every(p=>p.t==="诗")?o("collated.railUnitPoems"):o("collated.railUnitBooks"),m=p=>{const h=()=>{var u,f;return(f=(u=document.getElementById(`rd-e-${p}`))==null?void 0:u.scrollIntoView)==null?void 0:f.call(u,{block:"start",behavior:"smooth"})};i==="text"&&!r&&n("entries"),i==="text"&&!r?setTimeout(h,0):h()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:o("collated.railCap")}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:c}),t.jsx("span",{className:"bim-rd-rail-linked",children:o("collated.linkedN",{n:d})})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":o("collated.linkedOf",{n:d,total:l.length}),children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":o("collated.railEntriesNav"),children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:o("collated.viewEntries")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:p,i:h})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${h}`,onClick:u=>{u.preventDefault(),m(h)},children:[t.jsx("span",{className:`bim-rd-rail-dot${p.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:Qn(a(p.book_title||p.title),{t:o})})]})},h))})]})]})}const uf=`
|
|
1427
|
+
`),g=b.useRef({plugins:i,ctx:n});g.current={plugins:i,ctx:n};const[y,v]=b.useState({key:null,map:yn});b.useEffect(()=>{const K=g.current.ctx;if(!u||!K){v({key:null,map:yn});return}let V=!1;v({key:u,map:yn});for(const re of g.current.plugins){if(!re.onChapter)continue;const J=ue=>{V||v(fe=>fe.key===u?{key:u,map:new Map(fe.map).set(re.id,ue)}:fe)},I=Kt(re,"onChapter",()=>re.onChapter(K),void 0);Promise.resolve(I).then(J,ue=>{console.error(`[reader-plugin:${re.id}] onChapter 出错`,ue)})}return()=>{V=!0}},[u,f]);const w=y.key===u?y.map:yn,[x,j]=b.useState(0),S=b.useCallback(()=>j(K=>K+1),[]),$=b.useMemo(()=>{if(!d||d.length===0||i.length===0)return Ir;const K=[];for(const V of d)for(const re of V.columns)for(const J of re.chars)J.fig||K.push({anchor:J.id,char:J.char,page:V.page,col:re.col});return K},[d,i.length]),N=$.length===0&&i.some(K=>K.decorate),[z,C]=b.useState(Ir);b.useEffect(()=>{const K=m.current;if(!N||!K){C(Ir);return}let V;const re=()=>{const I=_h(On(K));C(ue=>ue.length===I.length&&ue.every((fe,ze)=>fe.char===I[ze].char)?ue:I)};if(re(),typeof MutationObserver>"u")return;const J=new MutationObserver(()=>{clearTimeout(V),V=setTimeout(re,80)});return J.observe(K,{childList:!0,subtree:!0,characterData:!0}),()=>{J.disconnect(),clearTimeout(V)}},[N,u,m]);const U=b.useMemo(()=>{const K=new Map;for(const V of $)K.set(V.anchor,V);return K},[$]),R=b.useCallback(K=>{var J,I;if(K.startsWith(Pn))return((I=(J=Ea(m.current,K))==null?void 0:J.getBoundingClientRect)==null?void 0:I.call(J))??null;const V=c.current;if(!V)return null;const re=V.querySelector(`[data-char-id="${K.replace(/["\\]/g,"\\$&")}"]`);return re?re.getBoundingClientRect():null},[c,m]),L=b.useCallback(K=>{var fe,ze;if("cp"in K)return((fe=$[K.cp])==null?void 0:fe.anchor)??null;if(!K.text)return null;if($.length===0)return Ah(m.current,K.text,l);let V="";const re=[];for(const B of $)re.push(V.length),V+=B.char;const J=V.indexOf(K.text);if(J<0)return null;let I=0,ue=re.length-1;for(;I<ue;){const B=I+ue+1>>1;re[B]<=J?I=B:ue=B-1}return((ze=$[I])==null?void 0:ze.anchor)??null},[$,m,l]),F=b.useCallback(K=>{var re,J;if(!K.startsWith(Pn)){h(K);return}const V=(J=(re=Ea(m.current,K))==null?void 0:re.getBoundingClientRect)==null?void 0:J.call(re);V&&window.scrollTo({top:window.scrollY+V.top-Mh,behavior:"instant"})},[h,m]),T=b.useMemo(()=>n?{ctx:n,state:K=>w.get(K),cells:$,textCells:z,scrollTo:F,rectOf:R,locate:L,refresh:S,prefs:r,setPref:o,t:a,convert:l}:null,[n,w,$,z,F,R,L,S,r,o,a,l,x]),Z=b.useMemo(()=>{if(!T)return;const K=[];for(const V of i){if(!V.decorate)continue;const re=Kt(V,"decorate",()=>V.decorate(T),void 0);re&&re.size>0&&K.push(re)}return K.length===0?void 0:K.length===1?K[0]:Zc(K)},[i,T]);b.useEffect(()=>{const K=m.current;if(!($.length>0||!K||!Z||Z.size===0))return Rh(On(K),Z,u?String(Lh(u)):"x")},[$.length,Z,m,u,z]);const O=b.useCallback(K=>{var V;return{anchor:K,char:((V=U.get(K))==null?void 0:V.char)??"",rect:R(K)}},[U,R]),ae=b.useCallback(K=>{var re;if(!T)return;const V=O(K);for(const J of i)(re=J.onCell)!=null&&re.click&&Kt(J,"onCell.click",()=>J.onCell.click(V,T),void 0)},[T,i,O]),ce=b.useCallback(K=>{var re;if(!T)return;const V=K?O(K):null;for(const J of i)(re=J.onCell)!=null&&re.hover&&Kt(J,"onCell.hover",()=>J.onCell.hover(V,T),void 0)},[T,i,O]),Ee=$.length===0&&i.some(K=>K.selectionActions),[we,ye]=b.useState(null);b.useEffect(()=>{if(!Ee){ye(null);return}const K=()=>{var pe,Te;const V=document.getSelection(),re=m.current;if(!V||V.isCollapsed||V.rangeCount===0||!re){ye(null);return}const J=V.getRangeAt(0),I=J.commonAncestorContainer,ue=I instanceof Element?I:I.parentElement;if(!re.contains(I)||ue!=null&&ue.closest('input,textarea,button,select,[contenteditable="true"]')){ye(null);return}const fe=V.toString().trim().slice(0,Mr);if(!fe){ye(null);return}const ze=(pe=J.getClientRects)==null?void 0:pe.call(J),B=(ze&&ze.length>0?ze[ze.length-1]:(Te=J.getBoundingClientRect)==null?void 0:Te.call(J))??null;ye(ve=>ve&&ve.text===fe?ve:{text:fe,rect:B})};return document.addEventListener("selectionchange",K),()=>document.removeEventListener("selectionchange",K)},[Ee,m]),b.useEffect(()=>{ye(null)},[u]);const Q=b.useMemo(()=>{if(!T||!i.some(J=>J.selectionActions))return[];if($.length===0){if(!we)return[];const J={anchors:[],text:we.text,rect:we.rect};return i.flatMap(I=>I.selectionActions?Kt(I,"selectionActions",()=>I.selectionActions(J,T),[]):[])}if(p.size===0)return[];const K=[];let V="";for(const J of $)p.has(J.anchor)&&(K.push(J.anchor),V.length<Mr&&(V+=J.char));if(K.length===0)return[];const re={anchors:K,text:V.slice(0,Mr),rect:R(K[K.length-1])};return i.flatMap(J=>J.selectionActions?Kt(J,"selectionActions",()=>J.selectionActions(re,T),[]):[])},[T,i,p,$,R,we]),Ne=b.useMemo(()=>T?i.filter(K=>K.settings).map((K,V)=>({p:K,i:V,order:K.settings.order??100})).sort((K,V)=>K.order-V.order||K.i-V.i).map(({p:K})=>({key:K.id,group:K.settings.group,title:K.settings.title,node:Kt(K,"settings.render",()=>K.settings.render(T),null)})):[],[i,T]),W=b.useMemo(()=>{if(!T)return{};const K=V=>{const re=i.filter(J=>{var I;return((I=J.toolbar)==null?void 0:I.slot)===V}).map((J,I)=>({p:J,i:I,order:J.toolbar.order??100})).sort((J,I)=>J.order-I.order||J.i-I.i).map(({p:J})=>t.jsx(b.Fragment,{children:Kt(J,"toolbar.render",()=>J.toolbar.render(T),null)},J.id));return re.length>0?t.jsx(t.Fragment,{children:re}):void 0};return{subtitle:K("subtitle"),actions:K("actions")}},[i,T]),je=b.useMemo(()=>{if(!T)return null;const K=i.filter(V=>V.overlay).map(V=>t.jsx(b.Fragment,{children:Kt(V,"overlay",()=>V.overlay(T),null)},V.id));return K.length===0&&Q.length===0?null:t.jsxs(t.Fragment,{children:[K,Q.length>0&&t.jsx("div",{className:"bim-rd-selbar",role:"toolbar","aria-label":a("reader.selectionActions"),"data-testid":"reader-selbar",children:Q.map(V=>t.jsx("button",{type:"button",title:V.title,onMouseDown:re=>re.preventDefault(),onClick:V.onClick,children:V.label},V.key))})]})},[i,T,Q,a]);return i.length===0?Oh:{settings:Ne,toolbar:W,overlay:je,decorations:Z,onCellClick:ae,onCellHover:ce}}function Bh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(s.TEXT_QUALITY_LABELS,e)?e:null}function Hh(e){if(e==="none")return{color:s.bim("quality-none"),fontWeight:400};if(e==="placeholder")return{color:s.bim("quality-placeholder"),fontWeight:400}}const Dh={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Qc="\0";function Wh(e,i,n){const[r,o=""]=e.split(Qc);return t.jsxs(t.Fragment,{children:[r,t.jsx(oc,{text:i,convert:n}),o]})}function Ft(e){return typeof e!="string"?"":Dh[e]??e}const Uh=["〇","一","二","三","四","五","六","七","八","九"],Ra=["","十","百","千"],Kh=["","萬","億"];function Ws(e){if(e===0)return"〇";if(e<0)return`負${Ws(-e)}`;const i=[];let n=e,r=0;for(;n>0;){const o=n%1e4;o>0?i.unshift(Yh(o,r>0)+Kh[r]):i.length>0&&i.unshift("〇"),n=Math.floor(n/1e4),r++}return i.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Yh(e,i){const n=[];let r=e;for(;r>0;)n.unshift(r%10),r=Math.floor(r/10);let o="";for(let a=0;a<n.length;a++){const l=n[a],d=n.length-1-a;l===0?o&&!o.endsWith("〇")&&(o+="〇"):l===1&&d===1&&a===0&&!i?o+=Ra[d]:o+=Uh[l]+Ra[d]}return o.replace(/〇$/,"")}let Ki=null,jn=null;const Fn=new Set;function Gh(){return Ki?Promise.resolve():jn||(jn=import("opencc-js/t2cn").then(e=>{const i=e.Converter({from:"t",to:"cn"});Ki=n=>i(vi.normalizeVariants(n)),Fn.forEach(n=>n())}).catch(()=>{Ki=e=>e,Fn.forEach(e=>e())}),jn)}const Vh=e=>e;function pi(){const[,e]=b.useState(0);return b.useEffect(()=>{if(Ki)return;const i=()=>e(n=>n+1);return Fn.add(i),Gh(),()=>{Fn.delete(i)}},[]),Ki??Vh}function Ni(e,i){return i(e).toLowerCase()}const qh=s.bim("highlight-bg");function rn(e,i,n){if(!i)return e;const r=Ni(i,n);if(!r)return e;const o=Ni(e,n),a=Array.from(e),l=Array.from(o);if(l.length!==a.length)return e;const d=new Map;let c=0;l.forEach((g,y)=>{d.set(c,y),c+=g.length});const m=Array.from(r).length,p=[];let h=0,u=0,f=0;for(;h<a.length;){const g=o.indexOf(r,u),y=g===-1?void 0:d.get(g);if(g===-1){p.push(a.slice(h).join(""));break}if(y===void 0){u=g+1;continue}y>h&&p.push(a.slice(h,y).join("")),p.push(t.jsx("mark",{style:{background:qh,padding:0,color:"inherit"},children:a.slice(y,y+m).join("")},f++)),h=y+m,u=g+r.length}return t.jsx(t.Fragment,{children:p})}function Us(e,i,n,r){if(!i)return!0;const o=Ni(i,r);return(n?[e.title,e.header_line,e.content,e.comment]:[e.title,e.book_title,e.author,e.author_info,e.summary,e.content,e.comment,e.additional_comment]).some(l=>typeof l=="string"&&Ni(l,r).includes(o))}function Xh(e,i,n){return i?Ni(e,n).includes(Ni(i,n)):!0}const Ks={类:s.bim("section-lei"),书:s.bim("section-shu"),序:s.bim("section-xu"),结语:s.bim("section-jieyu"),注释:s.bim("section-zhushi")},Jh={考证:s.bim("section-kaozhen")};function Ys(e,i,n){return e.collated.sectionType[i]??n(i)}function ed(e){var r;const i=e.files.length,n=((r=e.children)==null?void 0:r.reduce((o,a)=>o+ed(a),0))||0;return i+n}function Zh(e,i){const n=[],r=l=>{var d;n.push(...l.files),(d=l.children)==null||d.forEach(r)};if(r(e),n.length===0)return;const o=n.map(l=>i[l]);if(o.every(l=>l===void 0))return;if(o.some(l=>l==="loading"))return"loading";let a=0;for(const l of o)typeof l=="number"&&(a+=l);return a}const Qh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Gs({enabled:e,expanded:i,onClick:n,style:r,children:o}){return e?t.jsx("button",{type:"button","aria-expanded":i,onClick:n,style:{...Qh,...r},children:o}):t.jsx("span",{style:r,children:o})}function ef({type:e}){const{convert:i,messages:n}=oe(),r=Ft(e),o=Ks[r]||s.bim("desc-fg");return t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:o,border:`1px solid ${o}40`,borderRadius:"2px",background:`${o}08`,flexShrink:0},children:Ys(n,r,i)})}function tf({section:e,onNavigate:i,highlightQuery:n="",no:r,showUnlinked:o=!1,domId:a}){const{t:l,convert:d}=oe(),c=It(),m=pi(),p=j=>j?Lt(d(j),S=>n?rn(S,n,m):S,{t:l}):"",[h,u]=b.useState(!1),f=!!e.summary,g=!!e.comment,y=!!e.additional_comment,v=!!(e.content&&e.content.length>60),w=f||g||y||v;b.useEffect(()=>{n&&u(!0)},[n]);const x=!h&&v?Ec(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${s.bim("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>w&&u(!h),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:w?"pointer":"default",userSelect:"none"},children:[r!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:s.bim("label-fg")},children:r}),t.jsxs(Gs,{enabled:w,expanded:h,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[w&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:s.bim("desc-fg"),transition:"transform 0.15s",transform:h?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:s.bim("fg")},children:[e.book_title?t.jsxs(t.Fragment,{children:["《",p(e.book_title),"》"]}):p(e.title),e.n_juan!=null&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d(Ws(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!h&&x&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:s.bim("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(x)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:p(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&i&&t.jsx("a",{href:c(e.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),i(e.work_id))},style:{fontSize:"11px",color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:l("collated.viewWork"),"aria-label":l("collated.viewWorkOf",{title:d(e.book_title||e.title)}),children:l("collated.workArrow")}),o&&!e.work_id&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),h&&w&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${s.bim("widget-border")}`,background:s.bim("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),marginBottom:"8px"},children:p(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${s.bim("primary")}`,background:`color-mix(in srgb, ${s.bim("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:s.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify"},children:p(e.summary)})]}),e.comment&&t.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:`3px solid ${s.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:s.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.comment)})]}),e.additional_comment&&t.jsxs("div",{style:{padding:"8px 14px",borderLeft:`3px solid ${s.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:s.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.additional_comment)})]}),v&&!f&&!g&&!y&&t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function nf({section:e,highlightQuery:i=""}){const{t:n,convert:r}=oe(),o=pi(),a=m=>m?Lt(r(m),p=>i?rn(p,i,o):p,{t:n}):"",[l,d]=b.useState(!1),c=!!e.content;return t.jsxs("div",{style:{padding:"12px 0 6px"},children:[t.jsxs(Gs,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(ef,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:s.bim("fg")},children:a(e.title)}),c&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:s.bim("desc-fg"),transition:"transform 0.15s",transform:l?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),l&&c&&t.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Ks[Ft(e.type)]||s.bim("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:s.bim("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})})]})}const rf=100;function Vs(e){return Ft(e.type)!=="page_header"?!1:(e.content||"").length>=rf}function sf({section:e,highlightQuery:i=""}){const{t:n,convert:r,messages:o}=oe(),a=pi();if(Ft(e.type)==="page_header"&&!Vs(e)||!e.content&&!e.title)return null;const l=r((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1428
|
+
`)),d=Lt(l,h=>i?rn(h,i,a):h,{t:n}),c=Ft(e.type),m=Ks[c]||s.bim("desc-fg"),p=c==="序"||c==="结语"||c==="注释";return t.jsxs("div",{style:{padding:p?"10px 12px":"6px 0",margin:p?"8px 0":void 0,fontSize:"13px",color:s.bim("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:p?`3px solid ${m}40`:void 0,background:p?s.bim("bg"):void 0,borderRadius:p?"0 4px 4px 0":void 0,position:"relative"},children:[p&&t.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:m,marginRight:"8px",padding:"1px 5px",border:`1px solid ${m}40`,borderRadius:"2px",background:`${m}08`,verticalAlign:"middle"},children:Ys(o,c,r)}),d]})}function of(e,i,n){const[r,o]=b.useState({});return b.useEffect(()=>{var m;if(!i||e.length===0)return;let a=!1;const l=e.filter(p=>{var h;return!((h=n==null?void 0:n.current)!=null&&h.has(p))}),d={};for(const p of e)(m=n==null?void 0:n.current)!=null&&m.has(p)&&(d[p]=n.current.get(p));if(Object.keys(d).length>0&&o(d),l.length===0)return;const c=async p=>{var h;try{if(i.getEntry){const v=await i.getEntry(p);if(v)return{title:v.title,author:v.author}}const u=await i.getItem(p);if(!u)return null;const f=u.title||p,g=u.authors,y=(h=g==null?void 0:g[0])==null?void 0:h.name;return{title:f,author:y}}catch{return null}};return Promise.all(l.map(async p=>{var u;const h=await c(p);return(u=n==null?void 0:n.current)==null||u.set(p,h),[p,h]})).then(p=>{a||o(h=>{const u={...h};for(const[f,g]of p)u[f]=g;return u})}),()=>{a=!0}},[e.join(","),i]),r}function af({section:e,onNavigate:i,transport:n,workLabelCache:r,highlightQuery:o=""}){const{t:a,convert:l,messages:d}=oe(),c=It(),m=pi(),p=S=>S?Lt(l(S),$=>o?rn($,o,m):$,{t:a}):"",[h,u]=b.useState(!1);b.useEffect(()=>{o&&u(!0)},[o]);const f=Ft(e.type),g=Jh[f]||s.bim("desc-fg"),y=!!e.content,v=e.work_ids||[],w=v.length>1,x=of(w?v:[],n,r),j=y&&!h&&e.content.length>80?Ec(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${s.bim("widget-border")}`,padding:"10px 0"},children:[t.jsxs("div",{onClick:()=>y&&u(!h),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:y?"pointer":"default",userSelect:"none"},children:[t.jsxs(Gs,{enabled:y,expanded:h,style:{flex:1,display:"flex",alignItems:"flex-start",gap:"8px"},children:[y&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:s.bim("desc-fg"),marginTop:"5px",transition:"transform 0.15s",transform:h?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),t.jsxs("span",{style:{display:"block",flex:1},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:s.bim("fg"),lineHeight:1.6},children:e.header_line?p(e.header_line):p(e.title)}),!h&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.7},children:p(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[v.length===1&&i&&t.jsx("a",{href:c(v[0]),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),i(v[0]))},style:{fontSize:"11px",color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),w&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:v.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:Ys(d,f,l)})]})]}),w&&i&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:v.map(S=>{const $=x[S],N=$?`${l($.title)}${$.author?`(${l($.author)})`:""}`:S.slice(0,8)+"…";return t.jsxs("a",{href:c(S),onClick:z=>{z.metaKey||z.ctrlKey||(z.preventDefault(),z.stopPropagation(),i(S))},style:{fontSize:"12px",color:s.bim("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:S,children:["→",N]},S)})}),h&&y&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:s.bim("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:s.bim("fg"),lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)}),e.comment&&t.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:`1px solid ${s.bim("widget-border")}`,fontSize:"12px",color:s.bim("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:p(e.comment)})]})]})}function lf({juan:e,searchQuery:i,onNavigate:n,transport:r,workLabelCache:o}){const{t:a}=oe(),l=pi(),d=i.trim(),c=b.useMemo(()=>d?e.sections.filter(m=>Us(m,d,!0,l)):e.sections,[e.sections,d,l]);return t.jsxs("div",{children:[t.jsx("div",{children:c.map((m,p)=>t.jsx(af,{section:m,onNavigate:n,transport:r,workLabelCache:o,highlightQuery:d},p))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:s.bim("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function cf(){let e=!1;return i=>i==="类"?(e=!0,"h2"):e?"h3":"h2"}function df({sections:e,onNavigate:i,inline:n,workLinks:r=!0}){const o=It(),{t:a,convert:l}=oe(),d=cf();return t.jsx(t.Fragment,{children:e.map((c,m)=>{const p=Ft(c.type);if(p==="page_header"&&!Vs(c))return null;if(p==="类")return t.jsxs(b.Fragment,{children:[b.createElement(d("类"),null,n(l(c.title))),c.content&&t.jsx("p",{children:n(l(c.content))})]},m);if(p==="书"||p==="诗"||p==="考证"||p==="注释"){const h=c.book_title?`《${c.book_title}》${c.n_juan!=null?a("collated.nJuan",{n:Ws(c.n_juan)}):""}`:c.title,u=n(l(h));return t.jsxs("section",{className:"bim-rd-entry",id:`rd-e-${m}`,children:[b.createElement(d("条目"),{className:"bim-rd-entry-h"},c.work_id&&i&&r?t.jsxs(t.Fragment,{children:[t.jsx("a",{href:o(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i(c.work_id))},title:a("collated.viewWork"),children:u}),t.jsx("a",{className:"bim-rd-wl",href:o(c.work_id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i(c.work_id))},"aria-label":a("collated.viewWorkOf",{title:l(h)}),children:a("collated.workArrow")})]}):u),c.author_info&&t.jsx("p",{className:"bim-rd-sub",children:n(l(c.author_info))}),c.content&&c.content.split(/\n+/).map((f,g)=>t.jsx("p",{children:n(l(f))},g)),c.summary&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.summary")}),n(l(c.summary))]}),c.comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.comment")}),n(l(c.comment))]}),c.additional_comment&&t.jsxs("p",{children:[t.jsx("span",{className:"bim-rd-lbl",children:a("collated.additionalComment")}),n(l(c.additional_comment))]})]},m)}return p==="小计"&&c.title?t.jsx("p",{children:n(l(c.title))},m):c.content?t.jsx("p",{children:n(l(c.content))},m):null})})}function td(e){return e.some(i=>{const n=Ft(i.type);return n==="书"||n==="诗"||n==="考证"||n==="注释"||n==="类"||(n==="序"||n==="结语")&&!!i.content||n==="page_header"&&Vs(i)})}function mf({juan:e,rawText:i,positionLabel:n,groupLabel:r,index:o,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:m,view:p,onViewChange:h}){var Ne;const{t:u,convert:f,messages:g}=oe(),y=pi(),[v,w]=b.useState("text"),x=p??v,j=W=>{w(W),h==null||h(W)},S=a.trim(),$=(o==null?void 0:o.type)==="kaozhen",N=b.useCallback(W=>S?rn(W,S,y):W,[S,y]),z=Bs(m),C=W=>Qn(W,{renderText:N,bookMarking:z,quoteStyle:m.quoteStyle,t:u}),U=b.useMemo(()=>S?e.sections.filter(W=>Us(W,S,$,y)):e.sections,[e.sections,S,$,y]),R=(W,je)=>je.filter(K=>Ft(K.type)===W).length,L=R("书",e.sections),F=R("诗",e.sections),T=R("考证",e.sections);let Z="";$?Z=S?u("collated.countTiaoOf",{m:R("考证",U),n:T}):u("collated.countTiao",{n:T}):F>0?Z=S?u("collated.countPoemsOf",{m:R("诗",U),n:F}):u("collated.countPoems",{n:F}):L>0&&(Z=S?u("collated.countBooksOf",{m:R("书",U),n:L}):u("collated.countBooks",{n:L}));const O=o!=null&&o.text_quality?Bh(o.text_quality.grade):null,ae=[];if(Z&&ae.push(Z),$&&(o!=null&&o.target_source)&&ae.push(t.jsx(t.Fragment,{children:u("collated.kaozhenTarget",{target:f(o.target_source)})})),O){const W=t.jsx("span",{className:"bim-rd-grade",style:Hh(O),children:g.collated.qualityLabel[O]});ae.push(t.jsx("span",{title:g.collated.qualityCriteria[O],children:(Ne=o==null?void 0:o.text_quality)!=null&&Ne.source_note?t.jsxs(t.Fragment,{children:[Wh(u("collated.baseText",{note:Qc}),o.text_quality.source_note,f),W]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),W]})}))}e.source_url&&ae.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:u("collated.originalSource")}));const ce=!$&&td(e.sections),Ee=!!i&&(!ce||m.readingMode==="paragraph"&&Ln(i)),we=!$&&(ce||!!i),ye=$||!we?"entries":x;let Q=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(n||r)&&t.jsxs("p",{className:"bim-rd-kicker",children:[n,n&&r&&t.jsx("span",{className:"bim-rd-dot"}),r&&f(r)]}),t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),ae.length>0&&t.jsx("p",{className:"bim-rd-meta",children:ae.map((W,je)=>t.jsxs(b.Fragment,{children:[je>0&&t.jsx("span",{className:"bim-rd-dot"}),W]},je))}),we&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":u("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":ye==="text",onClick:()=>j("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":ye==="entries",onClick:()=>j("entries"),children:u("collated.viewEntries")})]})]}),ye==="text"&&t.jsx("article",{className:"bim-rd-prose",children:Ee?t.jsx(Hs,{text:i,mode:m.readingMode,bookMarking:z,quoteStyle:m.quoteStyle,renderText:N,dropTitle:e.title}):t.jsx(df,{sections:e.sections,onNavigate:l,inline:C,workLinks:m.workLinks})}),ye==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:$?t.jsx(lf,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[U.some(W=>["书","诗","考证"].includes(Ft(W.type)))&&t.jsxs("div",{className:"bim-rd-rowhead","aria-hidden":"true",children:[t.jsx("span",{style:{width:28},children:u("collated.rowHeadNo")}),t.jsx("span",{style:{flex:1},children:u("collated.rowHeadTitle")}),t.jsx("span",{children:u("collated.rowHeadWork")})]}),U.map((W,je)=>{const K=Ft(W.type);return K==="书"||K==="诗"||K==="考证"?(Q+=1,t.jsx(tf,{domId:`rd-e-${e.sections.indexOf(W)}`,section:W,onNavigate:m.workLinks?l:void 0,highlightQuery:S,no:Q,showUnlinked:m.workLinks&&!!l},je)):K==="类"?t.jsx(nf,{section:W,highlightQuery:S},je):t.jsx(sf,{section:W,highlightQuery:S},je)}),U.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function uf(e){const{resetKey:i,load:n,files:r,activeFile:o,activeJuan:a,activeRawText:l,query:d,isKaozhen:c}=e,m=pi(),p=b.useRef(new Map),[h,u]=b.useState({}),[f,g]=b.useState({}),y=b.useCallback((w,x)=>{const j=x==null?void 0:x.title;j&&g(S=>S[w]===j?S:{...S,[w]:j})},[]);b.useEffect(()=>{o&&a&&(p.current.set(o,{juan:a,rawText:l}),y(o,a))},[o,a,l,y]),b.useEffect(()=>{p.current.clear(),u({}),g({})},[i]);const v=b.useCallback((w,x)=>{let j=0;if(w.juan)for(const S of w.juan.sections)Us(S,x,c,m)&&j++;return j===0&&w.rawText&&Xh(w.rawText,x,m)&&(j=1),j},[c,m]);return b.useEffect(()=>{const w=d.trim();if(!w){u({});return}if(!n||r.length===0)return;let x=!1;const j={},S=[];for(const U of r){const R=p.current.get(U);R?j[U]=v(R,w):(j[U]="loading",S.push(U))}u(j);const $=8;let N=0;const z=async()=>{for(;N<S.length;){if(x)return;const U=N++,R=S[U];try{const L=await n(R),F=L.juan;if(p.current.set(R,L),y(R,F),x)return;u(T=>({...T,[R]:v(L,w)}))}catch{if(x)return;u(L=>({...L,[R]:0}))}}},C=Array.from({length:Math.min($,S.length)},()=>z());return Promise.all(C),()=>{x=!0}},[d,i,n,r.join(","),v,m,y]),{matchStates:h,titles:f}}function pf({juan:e,view:i,onView:n,textHasEntries:r}){const{t:o,convert:a}=oe(),l=e.sections.map((p,h)=>({s:p,i:h,t:Ft(p.type)})).filter(p=>p.t==="书"||p.t==="诗");if(l.length===0)return null;const d=l.filter(p=>!!p.s.work_id).length,c=l.every(p=>p.t==="诗")?o("collated.railUnitPoems"):o("collated.railUnitBooks"),m=p=>{const h=()=>{var u,f;return(f=(u=document.getElementById(`rd-e-${p}`))==null?void 0:u.scrollIntoView)==null?void 0:f.call(u,{block:"start",behavior:"smooth"})};i==="text"&&!r&&n("entries"),i==="text"&&!r?setTimeout(h,0):h()};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-rd-rail-card",children:[t.jsx("div",{className:"bim-rd-rail-cap",children:o("collated.railCap")}),t.jsxs("div",{className:"bim-rd-rail-n",children:[t.jsx("b",{children:l.length}),t.jsx("span",{children:c}),t.jsx("span",{className:"bim-rd-rail-linked",children:o("collated.linkedN",{n:d})})]}),t.jsx("div",{className:"bim-rd-rail-bar",role:"img","aria-label":o("collated.linkedOf",{n:d,total:l.length}),children:t.jsx("span",{style:{width:`${Math.round(d/l.length*100)}%`}})})]}),t.jsxs("nav",{"aria-label":o("collated.railEntriesNav"),children:[t.jsx("div",{className:"bim-rd-rail-cap",style:{margin:"20px 0 6px 12px"},children:o("collated.viewEntries")}),t.jsx("ul",{className:"bim-rd-rail-list",children:l.map(({s:p,i:h})=>t.jsx("li",{children:t.jsxs("a",{href:`#rd-e-${h}`,onClick:u=>{u.preventDefault(),m(h)},children:[t.jsx("span",{className:`bim-rd-rail-dot${p.work_id?" on":""}`,"aria-hidden":"true"}),t.jsx("span",{children:Qn(a(p.book_title||p.title),{t:o})})]})},h))})]})]})}const bf=`
|
|
1429
1429
|
attribute vec2 a_position; // 目标画布像素坐标 [0, canvasWidth] x [0, canvasHeight]
|
|
1430
1430
|
attribute vec2 a_texCoord; // 原图像素坐标 [0, imgWidth] x [0, imgHeight]
|
|
1431
1431
|
|
|
@@ -1443,7 +1443,7 @@ ${n.chapterKey}`:null,f=i.filter(K=>K.onChapter).map(K=>K.id).join(`
|
|
|
1443
1443
|
// 纹理坐标归一化 [0, 1]
|
|
1444
1444
|
v_texCoord = a_texCoord / u_imgResolution;
|
|
1445
1445
|
}
|
|
1446
|
-
`,
|
|
1446
|
+
`,hf=`
|
|
1447
1447
|
precision mediump float;
|
|
1448
1448
|
uniform sampler2D u_image;
|
|
1449
1449
|
uniform float u_alpha;
|
|
@@ -1453,7 +1453,7 @@ ${n.chapterKey}`:null,f=i.filter(K=>K.onChapter).map(K=>K.id).join(`
|
|
|
1453
1453
|
vec4 tex = texture2D(u_image, v_texCoord);
|
|
1454
1454
|
gl_FragColor = vec4(tex.rgb, tex.a * u_alpha);
|
|
1455
1455
|
}
|
|
1456
|
-
`;function Ta(e,i,n){const r=e.createShader(i);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error("Shader compile error:",e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}class rs{constructor(i){const n=i.getContext("webgl",{alpha:!0,antialias:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1});if(!n)throw new Error("WebGL not supported");this.gl=n;const r=Ta(n,n.VERTEX_SHADER,uf),o=Ta(n,n.FRAGMENT_SHADER,pf);if(!r||!o)throw new Error("Failed to create shaders");const a=n.createProgram();if(!a)throw new Error("Failed to create program");if(n.attachShader(a,r),n.attachShader(a,o),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS))throw new Error("Program link error: "+n.getProgramInfoLog(a));this.program=a,this.positionBuffer=n.createBuffer(),this.texCoordBuffer=n.createBuffer(),this.uResolutionLoc=n.getUniformLocation(a,"u_resolution"),this.uImgResolutionLoc=n.getUniformLocation(a,"u_imgResolution"),this.uAlphaLoc=n.getUniformLocation(a,"u_alpha"),this.aPositionLoc=n.getAttribLocation(a,"a_position"),this.aTexCoordLoc=n.getAttribLocation(a,"a_texCoord"),n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),this.clear(i.width,i.height)}clear(i,n){const r=this.gl;r.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight),r.clearColor(.98,.97,.95,1),r.clear(r.COLOR_BUFFER_BIT)}createTexture(i){const n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),r}renderStripsWithTexture(i,n,r,o,a,l,d=1){if(l.length===0)return;const c=this.gl;c.viewport(0,0,c.drawingBufferWidth,c.drawingBufferHeight),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,n,r),c.uniform2f(this.uImgResolutionLoc,o,a),c.uniform1f(this.uAlphaLoc,d);const m=[],p=[],h=8;for(const u of l){const f=u.colOffsetX||0,g=u.colOffsetY||0,{srcQuad:y,dstRect:v}=u.strip,[w,x,j,S]=v,$=f+w,N=g+x,[z,C,U,R]=y;for(let L=0;L<h;L++){const F=L/h,T=(L+1)/h,Z=N+S*F,O=N+S*T,ae=[z[0]+(R[0]-z[0])*F,z[1]+(R[1]-z[1])*F],ce=[z[0]+(R[0]-z[0])*T,z[1]+(R[1]-z[1])*T],Ee=[C[0]+(U[0]-C[0])*F,C[1]+(U[1]-C[1])*F],we=[C[0]+(U[0]-C[0])*T,C[1]+(U[1]-C[1])*T],ye=[$,Z],Q=[$+j,Z],Ne=[$,O],W=[$+j,O];m.push(ye[0],ye[1],Q[0],Q[1],Ne[0],Ne[1]),p.push(ae[0],ae[1],Ee[0],Ee[1],ce[0],ce[1]),m.push(Q[0],Q[1],W[0],W[1],Ne[0],Ne[1]),p.push(Ee[0],Ee[1],we[0],we[1],ce[0],ce[1])}}c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(m),c.STATIC_DRAW),c.enableVertexAttribArray(this.aPositionLoc),c.vertexAttribPointer(this.aPositionLoc,2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,this.texCoordBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(p),c.STATIC_DRAW),c.enableVertexAttribArray(this.aTexCoordLoc),c.vertexAttribPointer(this.aTexCoordLoc,2,c.FLOAT,!1,0,0),c.bindTexture(c.TEXTURE_2D,i),c.drawArrays(c.TRIANGLES,0,m.length/2)}deleteTexture(i){i&&this.gl.deleteTexture(i)}destroy(){const i=this.gl;i.deleteProgram(this.program),i.deleteBuffer(this.positionBuffer),i.deleteBuffer(this.texCoordBuffer)}}const Ia=150,bf=.35,hf=.25,kn=.01,Ma=.25;function ff(e,i,n){if(!(i>8)||!(n>8)||e.length<i*n)return null;const r=[];for(let c=0;c<n;c++){if(c<=kn*n||c>=(1-kn)*n)continue;let m=0,p=0;const h=c*i;for(let u=0;u<i;u++)e[h+u]<Ia?(p++,p>m&&(m=p)):p=0;m>bf*i&&r.push(c)}if(r.length<2)return null;const o=r[0],a=r[r.length-1]+1;if(a-o<Ma*n)return null;let l=null,d=null;for(let c=0;c<i;c++){if(c<=kn*i||c>=(1-kn)*i)continue;let m=0;for(let p=o;p<a;p++)e[p*i+c]<Ia&&m++;m/(a-o)>=hf&&(l===null&&(l=c),d=c+1)}return l!==null&&d!==null&&d-l<Ma*i&&(l=null,d=null),{x0:l===null?null:l/i,x1:d===null?null:d/i,y0:o/n,y1:a/n}}const Ar=new WeakMap,gf=600;function xf(e){if(Ar.has(e))return Ar.get(e)??null;let i=null;try{const n=e.naturalWidth,r=e.naturalHeight;if(n>0&&r>0&&typeof document<"u"){const o=Math.min(gf,n),a=Math.max(1,Math.round(r*o/n)),l=document.createElement("canvas");l.width=o,l.height=a;const d=l.getContext("2d",{willReadFrequently:!0});if(d){d.drawImage(e,0,0,o,a);const c=d.getImageData(0,0,o,a).data,m=new Uint8Array(o*a);for(let p=0,h=0;p<m.length;p++,h+=4)m[p]=c[h]*77+c[h+1]*150+c[h+2]*29>>8;i=ff(m,o,a)}}}catch{i=null}return Ar.set(e,i),i}function yf(e,i,n){const[r,o]=e.image_size||[0,0];if(!(r>0)||!(o>0)||e.columns.some(x=>{var j;return(((j=x.strips)==null?void 0:j.length)??0)>0}))return null;let a=1/0,l=1/0,d=-1/0,c=-1/0;for(const x of e.columns)for(const j of x.chars){const[S,$,N,z]=j.bbox_col;![S,$,N,z].every(Number.isFinite)||!(N>S)||!(z>$)||(a=Math.min(a,x.offset_x+S),l=Math.min(l,$),d=Math.max(d,x.offset_x+N),c=Math.max(c,z))}for(const x of e.figBlocks??[]){const[j,S,$,N]=x.box;![j,S,$,N].every(Number.isFinite)||!($>j)||!(N>S)||(a=Math.min(a,j),l=Math.min(l,S),d=Math.max(d,$),c=Math.max(c,N))}if(!(d>a)||!(c>l))return null;const m=Math.min(r,o)*.03;let p=a-m,h=l-m,u=d+m,f=c+m;if(n&&n.every(Number.isFinite)&&n[2]>0&&n[3]>0){const x=Math.min(r,o)*.005;p=Math.min(a-x,n[0]),h=Math.min(l-x,n[1]),u=Math.max(d+x,n[0]+n[2]),f=Math.max(c+x,n[1]+n[3])}else if(i){const x=Math.min(r,o)*.015;h=Math.min(l-x,i.y0*o-x),f=Math.max(c+x,i.y1*o+x),i.x0!==null&&i.x1!==null&&(p=Math.min(a-x,i.x0*r-x),u=Math.max(d+x,i.x1*r+x))}const g=Math.min(r,Math.max(0,p)),y=Math.min(o,Math.max(0,h)),v=Math.min(r,Math.max(0,u))-g,w=Math.min(o,Math.max(0,f))-y;return!(v>0)||!(w>0)||v>=r*.98&&w>=o*.98?null:{x:g,y,w:v,h:w}}function wn(e,i,n){const r=e[6]*i+e[7]*n+e[8]||1;return[(e[0]*i+e[1]*n+e[2])/r,(e[3]*i+e[4]*n+e[5])/r]}function jf(e){return Array.isArray(e)&&e.length===9&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&Math.abs(e[8])>1e-9}function Aa(e,i,n,r,o){const a=[wn(e,i,n),wn(e,r,n),wn(e,r,o),wn(e,i,o)],l=a.map(c=>c[0]),d=a.map(c=>c[1]);return[Math.min(...l),Math.min(...d),Math.max(...l),Math.max(...d)]}function kf(e,i){const n=i.H;return{...e,image_size:[i.src.w,i.src.h],columns:e.columns.map(r=>({...r,offset_x:0,chars:r.chars.map(o=>{const[a,l,d,c]=o.bbox_col,[m,p,h,u]=Aa(n,r.offset_x+a,l,r.offset_x+d,c);return{...o,bbox_col:[m,p,h,u]}})})),...e.figBlocks?{figBlocks:e.figBlocks.map(r=>({...r,box:Aa(n,r.box[0],r.box[1],r.box[2],r.box[3])}))}:{}}}function Lr(e){return Array.isArray(e)&&e.length===4&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&e[2]>0&&e[3]>0}function La(e,i,n){const r=i[0]>0?n[0]/i[0]:1,o=i[1]>0?n[1]/i[1]:1;return[e[0]*r,e[1]*o,e[2]*r,e[3]*o]}const wf={accent:{bg:s.bim("accent-bg"),fg:s.bim("accent")},warn:{bg:s.bim("highlight-bg"),fg:s.bim("highlight-fg")},muted:{fg:s.bim("meta-fg")},add:{bg:s.bim("check-fine-bg"),fg:s.bim("check-fine-fg")},omit:{bg:s.bim("danger-soft-bg"),fg:s.bim("danger")}};function vf(e){const i=e.tone&&wf[e.tone]||void 0;return{bg:e.bg??(i==null?void 0:i.bg),fg:e.fg??(i==null?void 0:i.fg)??s.bim("accent")}}const Pa=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Sf(e,i){const n=Math.max(1,Math.round(e)),r=Math.max(1,Math.round(i));return`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}"/>`)}`}const Pr=[1,1.5,2,3,4,6];function $f(e){for(const i of Pr)if(e<=i)return i;return Pr[Pr.length-1]}function _f(e,i,n,r,o=1){if(!(e>0)||!(i>0))return[1,1];if(n===null||!(n>0))return[1,1];const a=Math.ceil(n*Math.min(Math.max(r,1),2)*$f(o)/64)*64,l=Math.max(1,Math.min(Math.round(e),a)),d=Math.max(1,Math.round(l*i/e));return[l,d]}const Ct=new Map,Oa=8;let Cn=null;function Nf(e){Cn=e}function ss(e){let i=Ct.get(e);if(i)return Ct.delete(e),Ct.set(e,i),i;const n=Cn==null?void 0:Cn(e);if(n){for(i=n.then(r=>(r||Ct.delete(e),r),()=>(Ct.delete(e),null)),Ct.set(e,i);Ct.size>Oa;)Ct.delete(Ct.keys().next().value);return i}for(i=new Promise(r=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{(o.decode?o.decode().catch(()=>{}):Promise.resolve()).then(()=>r(o))},o.onerror=()=>{Ct.delete(e),r(null)},o.src=e}),Ct.set(e,i);Ct.size>Oa;)Ct.delete(Ct.keys().next().value);return i}function zf(e,i){if(!i||!(i.w>0)||!(i.h>0))return e;const[n,r]=e.image_size||[0,0];if(!(n>0)||!(r>0)||e.columns.some(l=>{var d;return(((d=l.strips)==null?void 0:d.length)??0)>0}))return e;const o=n*i.h/i.w;if(Math.abs(o/r-1)<=.01)return e;const a=o/r;return{...e,image_size:[n,o],columns:e.columns.map(l=>({...l,warped_h:l.warped_h*a,chars:l.chars.map(d=>({...d,bbox_col:[d.bbox_col[0],d.bbox_col[1]*a,d.bbox_col[2],d.bbox_col[3]*a]}))})),...e.figBlocks?{figBlocks:e.figBlocks.map(l=>({...l,box:[l.box[0],l.box[1]*a,l.box[2],l.box[3]*a]}))}:{}}}const qs=({imageUrl:e,pageData:i,extent:n,selectedCharIds:r,hoveredCharId:o,decorations:a,preserveMargins:l=!1,banxinMode:d="cut",onCharClick:c,onCharHover:m,selectedFigBlock:p,onFigBlockClick:h,renderScale:u=1})=>{var Xe;const f=!l&&d==="full"&&Lr((Xe=n==null?void 0:n.views)==null?void 0:Xe.full),g=b.useMemo(()=>!!((l||f)&&(n!=null&&n.src.url)&&n.src.w>0&&n.src.h>0&&jf(n.H)&&!i.columns.some(J=>{var ie;return(((ie=J.strips)==null?void 0:ie.length)??0)>0})),[l,f,n,i]),y=g?n.src.url:e,v=b.useMemo(()=>g?kf(i,n):i,[g,i,n]),[w,x]=b.useState(null),j=b.useMemo(()=>zf(v,w&&w.url===y?w:null),[v,w,y]),[S,$]=b.useState(null),N=b.useRef(null),z=b.useRef(null),C=typeof ResizeObserver<"u",[U,R]=b.useState(null);Pa(()=>{const J=z.current;if(!J||typeof ResizeObserver>"u")return;const ie=new ResizeObserver(me=>{var de;const se=((de=me[me.length-1])==null?void 0:de.contentRect.width)??0;R(ge=>ge===se?ge:se)});return ie.observe(J),()=>ie.disconnect()},[]);const L=!C||U!==null&&U>0,F=b.useRef(null),T=b.useRef(null),Z=b.useRef(null),O=b.useRef(null),ae=b.useRef(null),[ce,Ee]=b.useState(0),[we,ye]=b.useState(0),Q=b.useRef(""),Ne=b.useMemo(()=>Math.max(...j.columns.map(J=>J.warped_h),2440),[j]),W=j.total_warped_w,je=j.banxin,K=b.useMemo(()=>!j.columns.some(J=>{var ie;return(((ie=J.strips)==null?void 0:ie.length)??0)>0}),[j]),V=b.useMemo(()=>{var Oe;if(!l||K)return{top:0,bottom:0,left:0,right:0};const[J,ie]=j.image_size||[2386,3082];let me=1/0,se=-1/0,de=1/0,ge=-1/0;for(const Je of j.columns)for(const Pe of Je.strips||[])for(const Ue of Pe.srcQuad)Ue[0]<me&&(me=Ue[0]),Ue[0]>se&&(se=Ue[0]),Ue[1]<de&&(de=Ue[1]),Ue[1]>ge&&(ge=Ue[1]);if((Oe=j.banxin)!=null&&Oe.current_page_strips)for(const Je of j.banxin.current_page_strips)for(const Pe of Je.srcQuad)Pe[0]<me&&(me=Pe[0]),Pe[0]>se&&(se=Pe[0]),Pe[1]<de&&(de=Pe[1]),Pe[1]>ge&&(ge=Pe[1]);return isFinite(me)||(me=0),isFinite(se)||(se=J),isFinite(de)||(de=0),isFinite(ge)||(ge=ie),{top:Math.max(0,Math.round(de)),bottom:Math.max(0,Math.round(ie-ge)),left:Math.max(0,Math.round(me)),right:Math.max(0,Math.round(J-se)),rawMinX:me,rawMaxX:se,rawMinY:de,rawMaxY:ge,imgW:J,imgH:ie}},[j,l,K]),re=b.useMemo(()=>{var de,ge;if(!K)return null;const[J,ie]=j.image_size||[0,0];if(!(J>0)||!(ie>0))return null;if(g&&f&&((de=n==null?void 0:n.views)!=null&&de.full)){const Oe=La(n.views.full,[n.src.w,n.src.h],j.image_size),Je=Math.max(0,Oe[0]),Pe=Math.max(0,Oe[1]),Ue=Math.min(J,Oe[0]+Oe[2])-Je,nt=Math.min(ie,Oe[1]+Oe[3])-Pe;if(Ue>0&&nt>0)return{x:Je,y:Pe,w:Ue,h:nt}}const me=d==="none"&&Lr((ge=n==null?void 0:n.views)==null?void 0:ge.none)?n.views.none:n==null?void 0:n.content,se=!g&&n&&Lr(me)?La(me,i.image_size,j.image_size):null;return!l&&yf(j,S&&S.url===y?S.frame:null,se)||{x:0,y:0,w:J,h:ie}},[j,i,l,d,f,K,S,y,n,g]),X=W+(je?je.total_w:0),I=re?re.w:X+V.left+V.right,ue=re?re.h:Ne+V.top+V.bottom,fe=typeof window<"u"&&window.devicePixelRatio||1,[ze,B]=C?_f(I,ue,U,fe,u):[Math.round(I),Math.round(ue)],pe=b.useCallback(()=>{const J=F.current;if(!(!J||!N.current)&&!(y&&Q.current!==y)){if(J.clear(I,ue),l&&V.rawMinX!==void 0&&O.current&&T.current){const{rawMinX:ie,rawMaxX:me,rawMinY:se,rawMaxY:de,imgW:ge,imgH:Oe,top:Je,bottom:Pe,left:Ue,right:nt}=V,Y=[];Ue>0&&Y.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[ie,0],[ie,Oe],[0,Oe]],dstRect:[0,0,Ue,ue]}}),Je>0&&Y.push({colOffsetX:Ue,colOffsetY:0,strip:{srcQuad:[[ie,0],[me,0],[me,se],[ie,se]],dstRect:[0,0,X,Je]}}),Pe>0&&Y.push({colOffsetX:Ue,colOffsetY:Je+Ne,strip:{srcQuad:[[ie,de],[me,de],[me,Oe],[ie,Oe]],dstRect:[0,0,X,Pe]}}),nt>0&&Y.push({colOffsetX:Ue+X,colOffsetY:0,strip:{srcQuad:[[me,0],[ge,0],[ge,Oe],[me,Oe]],dstRect:[0,0,nt,ue]}}),J.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],Y,1)}if(O.current&&T.current){const ie=j.columns.flatMap(me=>(me.strips||[]).map(se=>({colOffsetX:V.left+me.offset_x,colOffsetY:V.top,strip:se})));if(ie.length>0?J.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],ie,1):J.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:re?[[re.x,re.y],[re.x+re.w,re.y],[re.x+re.w,re.y+re.h],[re.x,re.y+re.h]]:[[0,0],[j.image_size[0],0],[j.image_size[0],j.image_size[1]],[0,j.image_size[1]]],dstRect:[0,0,I,ue]}}],1),je&&je.current_page_strips.length>0){const me=je.current_page_strips.map(se=>({colOffsetX:V.left+W,colOffsetY:V.top,strip:se}));J.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],me,1)}}if(je&&ae.current&&Z.current&&je.mate_page_strips.length>0){const ie=je.mate_page_strips.map(me=>({colOffsetX:V.left+W+je.half_w,colOffsetY:V.top,strip:me}));J.renderStripsWithTexture(ae.current,I,ue,je.mate_img_size[0],je.mate_img_size[1],ie,.65)}}},[y,j,je,I,ue,W,Ne,X,V,l,re]),Te=b.useRef(pe);Te.current=pe,b.useEffect(()=>{const J=N.current;if(!J)return;const ie=de=>{O.current=T.current?de.createTexture(T.current):null,ae.current=Z.current?de.createTexture(Z.current):null,Te.current()};try{const de=new rs(J);F.current=de,ie(de)}catch(de){console.error("Failed to init WebGL renderer:",de)}const me=de=>{de.preventDefault(),console.warn("WebGL context lost")},se=()=>{console.info("WebGL context restored, re-initializing..."),N.current&&(F.current=new rs(N.current),ie(F.current))};return J.addEventListener("webglcontextlost",me,!1),J.addEventListener("webglcontextrestored",se,!1),()=>{J.removeEventListener("webglcontextlost",me),J.removeEventListener("webglcontextrestored",se),F.current&&(F.current.deleteTexture(O.current),F.current.deleteTexture(ae.current),F.current.destroy(),F.current=null)}},[]),b.useEffect(()=>{if(!y||!L)return;let J=!0;return ss(y).then(ie=>{if(!J||!ie)return;T.current=ie,Q.current=y,$({url:y,frame:xf(ie)}),x(se=>se&&se.url===y&&se.w===ie.naturalWidth&&se.h===ie.naturalHeight?se:{url:y,w:ie.naturalWidth,h:ie.naturalHeight});const me=F.current;me&&(me.deleteTexture(O.current),O.current=me.createTexture(ie)),Ee(se=>se+1)}),()=>{J=!1}},[y,L]);const ve=je==null?void 0:je.mate_image_url;b.useEffect(()=>{if(!ve||!L)return;let J=!0;return ss(ve).then(ie=>{if(!J||!ie)return;Z.current=ie;const me=F.current;me&&(me.deleteTexture(ae.current),ae.current=me.createTexture(ie)),ye(se=>se+1)}),()=>{J=!1}},[ve,L]),Pa(()=>{L&&pe()},[pe,ce,we,ze,B,L]);const Ve=b.useMemo(()=>(j.figBlocks??[]).map(J=>{const[ie,me,se,de]=J.box;return{id:J.id,x:V.left+ie-((re==null?void 0:re.x)??0),y:V.top+me-((re==null?void 0:re.y)??0),w:Math.max(se-ie,1),h:Math.max(de-me,1)}}),[j,V,re]),qe=b.useMemo(()=>{const J=[];for(const ie of j.columns)for(const me of ie.chars){const[se,de,ge,Oe]=me.bbox_col;J.push({id:me.id,char:me.char,x:V.left+ie.offset_x+se-((re==null?void 0:re.x)??0),y:V.top+de-((re==null?void 0:re.y)??0),w:Math.max(ge-se,1),h:Math.max(Oe-de,1)})}return J},[j,V,re]);return t.jsxs("div",{ref:z,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${I} / ${ue}`,backgroundColor:s.bim("warp-bg"),boxShadow:s.bim("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("img",{alt:"","aria-hidden":"true","data-warp-sizer":"",src:Sf(I,ue),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:N,width:ze,height:B,"data-logical-size":`${Math.floor(I)}x${Math.floor(ue)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:s.bim("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${I} ${ue}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[qe.map(J=>{const ie=r.has(J.id),me=o===J.id;return t.jsx("rect",{"data-selected":ie?"true":void 0,x:J.x,y:J.y,width:J.w,height:J.h,fill:ie?s.bim("warp-sel-bg"):me?s.bim("warp-hover-bg"):"transparent",stroke:ie?s.bim("warp-sel-stroke"):me?s.bim("warp-hover-stroke"):"transparent",strokeWidth:ie?3.5:me?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>c==null?void 0:c(J.id),onMouseEnter:()=>m==null?void 0:m(J.id),onMouseLeave:()=>m==null?void 0:m(null),children:t.jsx("title",{children:J.char})},J.id)}),a&&a.size>0&&qe.map(J=>{const ie=a.get(J.id);if(!ie)return null;const me=vf(ie),se=Math.max(10,J.w*.42);return t.jsxs("g",{"data-cd":ie.tone??"","data-cd-focus":ie.focus?"":void 0,pointerEvents:"none",children:[me.bg&&t.jsx("rect",{x:J.x,y:J.y,width:J.w,height:J.h,fill:me.bg,fillOpacity:.35}),ie.underline&&t.jsx("line",{x1:J.x,x2:J.x+J.w,y1:J.y+J.h,y2:J.y+J.h,stroke:me.fg,strokeWidth:3,strokeDasharray:ie.underline==="dotted"?"2 5":ie.underline==="dashed"?"10 6":void 0}),ie.focus&&t.jsx("rect",{x:J.x,y:J.y,width:J.w,height:J.h,fill:"none",stroke:s.bim("accent"),strokeWidth:4}),ie.sub&&t.jsx("text",{"data-cd-sub":ie.sub,x:J.x+J.w,y:J.y+J.h-2,fontSize:se,textAnchor:"end",fill:me.fg,children:ie.sub}),ie.insertAfter&&t.jsx("text",{"data-cd-ins":ie.insertAfter,x:J.x+J.w/2,y:J.y+J.h+se,fontSize:se,textAnchor:"middle",fill:me.fg,children:ie.insertAfter})]},`cd-${J.id}`)}),Ve.map(J=>{const ie=p===J.id;return t.jsx("rect",{"data-fig-block":J.id,"data-selected":ie?"true":void 0,x:J.x,y:J.y,width:J.w,height:J.h,fill:ie?s.bim("warp-sel-bg"):"transparent",stroke:ie?s.bim("warp-sel-stroke"):s.bim("warp-hover-stroke"),strokeWidth:ie?3.5:2,strokeDasharray:ie?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>h==null?void 0:h(J.id),children:t.jsx("title",{children:J.id})},`fig-${J.id}`)}),je&&t.jsxs("g",{children:[t.jsx("line",{x1:V.left+W,y1:V.top,x2:V.left+W,y2:V.top+Ne,stroke:s.bim("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:V.left+W+je.half_w,y1:V.top,x2:V.left+W+je.half_w,y2:V.top+Ne,stroke:s.bim("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:V.left+X,y1:V.top,x2:V.left+X,y2:V.top+Ne,stroke:s.bim("warp-banxin-outer"),strokeWidth:1})]})]})]})},Xs=`
|
|
1456
|
+
`;function Ta(e,i,n){const r=e.createShader(i);return r?(e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.error("Shader compile error:",e.getShaderInfoLog(r)),e.deleteShader(r),null)):null}class rs{constructor(i){const n=i.getContext("webgl",{alpha:!0,antialias:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1});if(!n)throw new Error("WebGL not supported");this.gl=n;const r=Ta(n,n.VERTEX_SHADER,bf),o=Ta(n,n.FRAGMENT_SHADER,hf);if(!r||!o)throw new Error("Failed to create shaders");const a=n.createProgram();if(!a)throw new Error("Failed to create program");if(n.attachShader(a,r),n.attachShader(a,o),n.linkProgram(a),!n.getProgramParameter(a,n.LINK_STATUS))throw new Error("Program link error: "+n.getProgramInfoLog(a));this.program=a,this.positionBuffer=n.createBuffer(),this.texCoordBuffer=n.createBuffer(),this.uResolutionLoc=n.getUniformLocation(a,"u_resolution"),this.uImgResolutionLoc=n.getUniformLocation(a,"u_imgResolution"),this.uAlphaLoc=n.getUniformLocation(a,"u_alpha"),this.aPositionLoc=n.getAttribLocation(a,"a_position"),this.aTexCoordLoc=n.getAttribLocation(a,"a_texCoord"),n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),this.clear(i.width,i.height)}clear(i,n){const r=this.gl;r.viewport(0,0,r.drawingBufferWidth,r.drawingBufferHeight),r.clearColor(.98,.97,.95,1),r.clear(r.COLOR_BUFFER_BIT)}createTexture(i){const n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),r}renderStripsWithTexture(i,n,r,o,a,l,d=1){if(l.length===0)return;const c=this.gl;c.viewport(0,0,c.drawingBufferWidth,c.drawingBufferHeight),c.useProgram(this.program),c.uniform2f(this.uResolutionLoc,n,r),c.uniform2f(this.uImgResolutionLoc,o,a),c.uniform1f(this.uAlphaLoc,d);const m=[],p=[],h=8;for(const u of l){const f=u.colOffsetX||0,g=u.colOffsetY||0,{srcQuad:y,dstRect:v}=u.strip,[w,x,j,S]=v,$=f+w,N=g+x,[z,C,U,R]=y;for(let L=0;L<h;L++){const F=L/h,T=(L+1)/h,Z=N+S*F,O=N+S*T,ae=[z[0]+(R[0]-z[0])*F,z[1]+(R[1]-z[1])*F],ce=[z[0]+(R[0]-z[0])*T,z[1]+(R[1]-z[1])*T],Ee=[C[0]+(U[0]-C[0])*F,C[1]+(U[1]-C[1])*F],we=[C[0]+(U[0]-C[0])*T,C[1]+(U[1]-C[1])*T],ye=[$,Z],Q=[$+j,Z],Ne=[$,O],W=[$+j,O];m.push(ye[0],ye[1],Q[0],Q[1],Ne[0],Ne[1]),p.push(ae[0],ae[1],Ee[0],Ee[1],ce[0],ce[1]),m.push(Q[0],Q[1],W[0],W[1],Ne[0],Ne[1]),p.push(Ee[0],Ee[1],we[0],we[1],ce[0],ce[1])}}c.bindBuffer(c.ARRAY_BUFFER,this.positionBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(m),c.STATIC_DRAW),c.enableVertexAttribArray(this.aPositionLoc),c.vertexAttribPointer(this.aPositionLoc,2,c.FLOAT,!1,0,0),c.bindBuffer(c.ARRAY_BUFFER,this.texCoordBuffer),c.bufferData(c.ARRAY_BUFFER,new Float32Array(p),c.STATIC_DRAW),c.enableVertexAttribArray(this.aTexCoordLoc),c.vertexAttribPointer(this.aTexCoordLoc,2,c.FLOAT,!1,0,0),c.bindTexture(c.TEXTURE_2D,i),c.drawArrays(c.TRIANGLES,0,m.length/2)}deleteTexture(i){i&&this.gl.deleteTexture(i)}destroy(){const i=this.gl;i.deleteProgram(this.program),i.deleteBuffer(this.positionBuffer),i.deleteBuffer(this.texCoordBuffer)}}const Ia=150,ff=.35,gf=.25,kn=.01,Ma=.25;function xf(e,i,n){if(!(i>8)||!(n>8)||e.length<i*n)return null;const r=[];for(let c=0;c<n;c++){if(c<=kn*n||c>=(1-kn)*n)continue;let m=0,p=0;const h=c*i;for(let u=0;u<i;u++)e[h+u]<Ia?(p++,p>m&&(m=p)):p=0;m>ff*i&&r.push(c)}if(r.length<2)return null;const o=r[0],a=r[r.length-1]+1;if(a-o<Ma*n)return null;let l=null,d=null;for(let c=0;c<i;c++){if(c<=kn*i||c>=(1-kn)*i)continue;let m=0;for(let p=o;p<a;p++)e[p*i+c]<Ia&&m++;m/(a-o)>=gf&&(l===null&&(l=c),d=c+1)}return l!==null&&d!==null&&d-l<Ma*i&&(l=null,d=null),{x0:l===null?null:l/i,x1:d===null?null:d/i,y0:o/n,y1:a/n}}const Ar=new WeakMap,yf=600;function jf(e){if(Ar.has(e))return Ar.get(e)??null;let i=null;try{const n=e.naturalWidth,r=e.naturalHeight;if(n>0&&r>0&&typeof document<"u"){const o=Math.min(yf,n),a=Math.max(1,Math.round(r*o/n)),l=document.createElement("canvas");l.width=o,l.height=a;const d=l.getContext("2d",{willReadFrequently:!0});if(d){d.drawImage(e,0,0,o,a);const c=d.getImageData(0,0,o,a).data,m=new Uint8Array(o*a);for(let p=0,h=0;p<m.length;p++,h+=4)m[p]=c[h]*77+c[h+1]*150+c[h+2]*29>>8;i=xf(m,o,a)}}}catch{i=null}return Ar.set(e,i),i}function kf(e,i,n){const[r,o]=e.image_size||[0,0];if(!(r>0)||!(o>0)||e.columns.some(x=>{var j;return(((j=x.strips)==null?void 0:j.length)??0)>0}))return null;let a=1/0,l=1/0,d=-1/0,c=-1/0;for(const x of e.columns)for(const j of x.chars){const[S,$,N,z]=j.bbox_col;![S,$,N,z].every(Number.isFinite)||!(N>S)||!(z>$)||(a=Math.min(a,x.offset_x+S),l=Math.min(l,$),d=Math.max(d,x.offset_x+N),c=Math.max(c,z))}for(const x of e.figBlocks??[]){const[j,S,$,N]=x.box;![j,S,$,N].every(Number.isFinite)||!($>j)||!(N>S)||(a=Math.min(a,j),l=Math.min(l,S),d=Math.max(d,$),c=Math.max(c,N))}if(!(d>a)||!(c>l))return null;const m=Math.min(r,o)*.03;let p=a-m,h=l-m,u=d+m,f=c+m;if(n&&n.every(Number.isFinite)&&n[2]>0&&n[3]>0){const x=Math.min(r,o)*.005;p=Math.min(a-x,n[0]),h=Math.min(l-x,n[1]),u=Math.max(d+x,n[0]+n[2]),f=Math.max(c+x,n[1]+n[3])}else if(i){const x=Math.min(r,o)*.015;h=Math.min(l-x,i.y0*o-x),f=Math.max(c+x,i.y1*o+x),i.x0!==null&&i.x1!==null&&(p=Math.min(a-x,i.x0*r-x),u=Math.max(d+x,i.x1*r+x))}const g=Math.min(r,Math.max(0,p)),y=Math.min(o,Math.max(0,h)),v=Math.min(r,Math.max(0,u))-g,w=Math.min(o,Math.max(0,f))-y;return!(v>0)||!(w>0)||v>=r*.98&&w>=o*.98?null:{x:g,y,w:v,h:w}}function wn(e,i,n){const r=e[6]*i+e[7]*n+e[8]||1;return[(e[0]*i+e[1]*n+e[2])/r,(e[3]*i+e[4]*n+e[5])/r]}function wf(e){return Array.isArray(e)&&e.length===9&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&Math.abs(e[8])>1e-9}function Aa(e,i,n,r,o){const a=[wn(e,i,n),wn(e,r,n),wn(e,r,o),wn(e,i,o)],l=a.map(c=>c[0]),d=a.map(c=>c[1]);return[Math.min(...l),Math.min(...d),Math.max(...l),Math.max(...d)]}function vf(e,i){const n=i.H;return{...e,image_size:[i.src.w,i.src.h],columns:e.columns.map(r=>({...r,offset_x:0,chars:r.chars.map(o=>{const[a,l,d,c]=o.bbox_col,[m,p,h,u]=Aa(n,r.offset_x+a,l,r.offset_x+d,c);return{...o,bbox_col:[m,p,h,u]}})})),...e.figBlocks?{figBlocks:e.figBlocks.map(r=>({...r,box:Aa(n,r.box[0],r.box[1],r.box[2],r.box[3])}))}:{}}}function Lr(e){return Array.isArray(e)&&e.length===4&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&e[2]>0&&e[3]>0}function La(e,i,n){const r=i[0]>0?n[0]/i[0]:1,o=i[1]>0?n[1]/i[1]:1;return[e[0]*r,e[1]*o,e[2]*r,e[3]*o]}const Sf={accent:{bg:s.bim("accent-bg"),fg:s.bim("accent")},warn:{bg:s.bim("highlight-bg"),fg:s.bim("highlight-fg")},muted:{fg:s.bim("meta-fg")},add:{bg:s.bim("check-fine-bg"),fg:s.bim("check-fine-fg")},omit:{bg:s.bim("danger-soft-bg"),fg:s.bim("danger")}};function Pa({text:e,attr:i,left:n,cy:r,fs:o,fg:a}){const l=Array.from(e),d=o*1.04,c=o*.16,m=o*.14,p=o+c*2,h=l.length*d+m*2,u=r-h/2;return t.jsxs("g",{[i]:e,children:[t.jsx("rect",{x:n,y:u,width:p,height:h,rx:o*.22,fill:s.bim("bg"),fillOpacity:.94,stroke:a,strokeWidth:Math.max(1.5,o*.07)}),l.map((f,g)=>t.jsx("text",{x:n+p/2,y:u+m+d*g+o*.86,fontSize:o,fontWeight:600,textAnchor:"middle",fill:a,children:f},g))]})}function Oa(e){const i=e.tone&&Sf[e.tone]||void 0;return{bg:e.bg??(i==null?void 0:i.bg),fg:e.fg??(i==null?void 0:i.fg)??s.bim("accent")}}const Fa=typeof window>"u"?b.useEffect:b.useLayoutEffect;function $f(e,i){const n=Math.max(1,Math.round(e)),r=Math.max(1,Math.round(i));return`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}"/>`)}`}const Pr=[1,1.5,2,3,4,6];function _f(e){for(const i of Pr)if(e<=i)return i;return Pr[Pr.length-1]}function Nf(e,i,n,r,o=1){if(!(e>0)||!(i>0))return[1,1];if(n===null||!(n>0))return[1,1];const a=Math.ceil(n*Math.min(Math.max(r,1),2)*_f(o)/64)*64,l=Math.max(1,Math.min(Math.round(e),a)),d=Math.max(1,Math.round(l*i/e));return[l,d]}const Ct=new Map,Ba=8;let Cn=null;function zf(e){Cn=e}function ss(e){let i=Ct.get(e);if(i)return Ct.delete(e),Ct.set(e,i),i;const n=Cn==null?void 0:Cn(e);if(n){for(i=n.then(r=>(r||Ct.delete(e),r),()=>(Ct.delete(e),null)),Ct.set(e,i);Ct.size>Ba;)Ct.delete(Ct.keys().next().value);return i}for(i=new Promise(r=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{(o.decode?o.decode().catch(()=>{}):Promise.resolve()).then(()=>r(o))},o.onerror=()=>{Ct.delete(e),r(null)},o.src=e}),Ct.set(e,i);Ct.size>Ba;)Ct.delete(Ct.keys().next().value);return i}function Cf(e,i){if(!i||!(i.w>0)||!(i.h>0))return e;const[n,r]=e.image_size||[0,0];if(!(n>0)||!(r>0)||e.columns.some(l=>{var d;return(((d=l.strips)==null?void 0:d.length)??0)>0}))return e;const o=n*i.h/i.w;if(Math.abs(o/r-1)<=.01)return e;const a=o/r;return{...e,image_size:[n,o],columns:e.columns.map(l=>({...l,warped_h:l.warped_h*a,chars:l.chars.map(d=>({...d,bbox_col:[d.bbox_col[0],d.bbox_col[1]*a,d.bbox_col[2],d.bbox_col[3]*a]}))})),...e.figBlocks?{figBlocks:e.figBlocks.map(l=>({...l,box:[l.box[0],l.box[1]*a,l.box[2],l.box[3]*a]}))}:{}}}const qs=({imageUrl:e,pageData:i,extent:n,selectedCharIds:r,hoveredCharId:o,decorations:a,preserveMargins:l=!1,banxinMode:d="cut",onCharClick:c,onCharHover:m,selectedFigBlock:p,onFigBlockClick:h,renderScale:u=1})=>{var Xe;const f=!l&&d==="full"&&Lr((Xe=n==null?void 0:n.views)==null?void 0:Xe.full),g=b.useMemo(()=>!!((l||f)&&(n!=null&&n.src.url)&&n.src.w>0&&n.src.h>0&&wf(n.H)&&!i.columns.some(X=>{var ie;return(((ie=X.strips)==null?void 0:ie.length)??0)>0})),[l,f,n,i]),y=g?n.src.url:e,v=b.useMemo(()=>g?vf(i,n):i,[g,i,n]),[w,x]=b.useState(null),j=b.useMemo(()=>Cf(v,w&&w.url===y?w:null),[v,w,y]),[S,$]=b.useState(null),N=b.useRef(null),z=b.useRef(null),C=typeof ResizeObserver<"u",[U,R]=b.useState(null);Fa(()=>{const X=z.current;if(!X||typeof ResizeObserver>"u")return;const ie=new ResizeObserver(me=>{var de;const se=((de=me[me.length-1])==null?void 0:de.contentRect.width)??0;R(ge=>ge===se?ge:se)});return ie.observe(X),()=>ie.disconnect()},[]);const L=!C||U!==null&&U>0,F=b.useRef(null),T=b.useRef(null),Z=b.useRef(null),O=b.useRef(null),ae=b.useRef(null),[ce,Ee]=b.useState(0),[we,ye]=b.useState(0),Q=b.useRef(""),Ne=b.useMemo(()=>Math.max(...j.columns.map(X=>X.warped_h),2440),[j]),W=j.total_warped_w,je=j.banxin,K=b.useMemo(()=>!j.columns.some(X=>{var ie;return(((ie=X.strips)==null?void 0:ie.length)??0)>0}),[j]),V=b.useMemo(()=>{var Oe;if(!l||K)return{top:0,bottom:0,left:0,right:0};const[X,ie]=j.image_size||[2386,3082];let me=1/0,se=-1/0,de=1/0,ge=-1/0;for(const Je of j.columns)for(const Pe of Je.strips||[])for(const Ue of Pe.srcQuad)Ue[0]<me&&(me=Ue[0]),Ue[0]>se&&(se=Ue[0]),Ue[1]<de&&(de=Ue[1]),Ue[1]>ge&&(ge=Ue[1]);if((Oe=j.banxin)!=null&&Oe.current_page_strips)for(const Je of j.banxin.current_page_strips)for(const Pe of Je.srcQuad)Pe[0]<me&&(me=Pe[0]),Pe[0]>se&&(se=Pe[0]),Pe[1]<de&&(de=Pe[1]),Pe[1]>ge&&(ge=Pe[1]);return isFinite(me)||(me=0),isFinite(se)||(se=X),isFinite(de)||(de=0),isFinite(ge)||(ge=ie),{top:Math.max(0,Math.round(de)),bottom:Math.max(0,Math.round(ie-ge)),left:Math.max(0,Math.round(me)),right:Math.max(0,Math.round(X-se)),rawMinX:me,rawMaxX:se,rawMinY:de,rawMaxY:ge,imgW:X,imgH:ie}},[j,l,K]),re=b.useMemo(()=>{var de,ge;if(!K)return null;const[X,ie]=j.image_size||[0,0];if(!(X>0)||!(ie>0))return null;if(g&&f&&((de=n==null?void 0:n.views)!=null&&de.full)){const Oe=La(n.views.full,[n.src.w,n.src.h],j.image_size),Je=Math.max(0,Oe[0]),Pe=Math.max(0,Oe[1]),Ue=Math.min(X,Oe[0]+Oe[2])-Je,nt=Math.min(ie,Oe[1]+Oe[3])-Pe;if(Ue>0&&nt>0)return{x:Je,y:Pe,w:Ue,h:nt}}const me=d==="none"&&Lr((ge=n==null?void 0:n.views)==null?void 0:ge.none)?n.views.none:n==null?void 0:n.content,se=!g&&n&&Lr(me)?La(me,i.image_size,j.image_size):null;return!l&&kf(j,S&&S.url===y?S.frame:null,se)||{x:0,y:0,w:X,h:ie}},[j,i,l,d,f,K,S,y,n,g]),J=W+(je?je.total_w:0),I=re?re.w:J+V.left+V.right,ue=re?re.h:Ne+V.top+V.bottom,fe=typeof window<"u"&&window.devicePixelRatio||1,[ze,B]=C?Nf(I,ue,U,fe,u):[Math.round(I),Math.round(ue)],pe=b.useCallback(()=>{const X=F.current;if(!(!X||!N.current)&&!(y&&Q.current!==y)){if(X.clear(I,ue),l&&V.rawMinX!==void 0&&O.current&&T.current){const{rawMinX:ie,rawMaxX:me,rawMinY:se,rawMaxY:de,imgW:ge,imgH:Oe,top:Je,bottom:Pe,left:Ue,right:nt}=V,Y=[];Ue>0&&Y.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[ie,0],[ie,Oe],[0,Oe]],dstRect:[0,0,Ue,ue]}}),Je>0&&Y.push({colOffsetX:Ue,colOffsetY:0,strip:{srcQuad:[[ie,0],[me,0],[me,se],[ie,se]],dstRect:[0,0,J,Je]}}),Pe>0&&Y.push({colOffsetX:Ue,colOffsetY:Je+Ne,strip:{srcQuad:[[ie,de],[me,de],[me,Oe],[ie,Oe]],dstRect:[0,0,J,Pe]}}),nt>0&&Y.push({colOffsetX:Ue+J,colOffsetY:0,strip:{srcQuad:[[me,0],[ge,0],[ge,Oe],[me,Oe]],dstRect:[0,0,nt,ue]}}),X.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],Y,1)}if(O.current&&T.current){const ie=j.columns.flatMap(me=>(me.strips||[]).map(se=>({colOffsetX:V.left+me.offset_x,colOffsetY:V.top,strip:se})));if(ie.length>0?X.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],ie,1):X.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:re?[[re.x,re.y],[re.x+re.w,re.y],[re.x+re.w,re.y+re.h],[re.x,re.y+re.h]]:[[0,0],[j.image_size[0],0],[j.image_size[0],j.image_size[1]],[0,j.image_size[1]]],dstRect:[0,0,I,ue]}}],1),je&&je.current_page_strips.length>0){const me=je.current_page_strips.map(se=>({colOffsetX:V.left+W,colOffsetY:V.top,strip:se}));X.renderStripsWithTexture(O.current,I,ue,j.image_size[0],j.image_size[1],me,1)}}if(je&&ae.current&&Z.current&&je.mate_page_strips.length>0){const ie=je.mate_page_strips.map(me=>({colOffsetX:V.left+W+je.half_w,colOffsetY:V.top,strip:me}));X.renderStripsWithTexture(ae.current,I,ue,je.mate_img_size[0],je.mate_img_size[1],ie,.65)}}},[y,j,je,I,ue,W,Ne,J,V,l,re]),Te=b.useRef(pe);Te.current=pe,b.useEffect(()=>{const X=N.current;if(!X)return;const ie=de=>{O.current=T.current?de.createTexture(T.current):null,ae.current=Z.current?de.createTexture(Z.current):null,Te.current()};try{const de=new rs(X);F.current=de,ie(de)}catch(de){console.error("Failed to init WebGL renderer:",de)}const me=de=>{de.preventDefault(),console.warn("WebGL context lost")},se=()=>{console.info("WebGL context restored, re-initializing..."),N.current&&(F.current=new rs(N.current),ie(F.current))};return X.addEventListener("webglcontextlost",me,!1),X.addEventListener("webglcontextrestored",se,!1),()=>{X.removeEventListener("webglcontextlost",me),X.removeEventListener("webglcontextrestored",se),F.current&&(F.current.deleteTexture(O.current),F.current.deleteTexture(ae.current),F.current.destroy(),F.current=null)}},[]),b.useEffect(()=>{if(!y||!L)return;let X=!0;return ss(y).then(ie=>{if(!X||!ie)return;T.current=ie,Q.current=y,$({url:y,frame:jf(ie)}),x(se=>se&&se.url===y&&se.w===ie.naturalWidth&&se.h===ie.naturalHeight?se:{url:y,w:ie.naturalWidth,h:ie.naturalHeight});const me=F.current;me&&(me.deleteTexture(O.current),O.current=me.createTexture(ie)),Ee(se=>se+1)}),()=>{X=!1}},[y,L]);const ve=je==null?void 0:je.mate_image_url;b.useEffect(()=>{if(!ve||!L)return;let X=!0;return ss(ve).then(ie=>{if(!X||!ie)return;Z.current=ie;const me=F.current;me&&(me.deleteTexture(ae.current),ae.current=me.createTexture(ie)),ye(se=>se+1)}),()=>{X=!1}},[ve,L]),Fa(()=>{L&&pe()},[pe,ce,we,ze,B,L]);const Ve=b.useMemo(()=>(j.figBlocks??[]).map(X=>{const[ie,me,se,de]=X.box;return{id:X.id,x:V.left+ie-((re==null?void 0:re.x)??0),y:V.top+me-((re==null?void 0:re.y)??0),w:Math.max(se-ie,1),h:Math.max(de-me,1)}}),[j,V,re]),qe=b.useMemo(()=>{const X=[];for(const ie of j.columns)for(const me of ie.chars){const[se,de,ge,Oe]=me.bbox_col;X.push({id:me.id,char:me.char,x:V.left+ie.offset_x+se-((re==null?void 0:re.x)??0),y:V.top+de-((re==null?void 0:re.y)??0),w:Math.max(ge-se,1),h:Math.max(Oe-de,1)})}return X},[j,V,re]);return t.jsxs("div",{ref:z,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${I} / ${ue}`,backgroundColor:s.bim("warp-bg"),boxShadow:s.bim("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("img",{alt:"","aria-hidden":"true","data-warp-sizer":"",src:$f(I,ue),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:N,width:ze,height:B,"data-logical-size":`${Math.floor(I)}x${Math.floor(ue)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:s.bim("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${I} ${ue}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[qe.map(X=>{const ie=r.has(X.id),me=o===X.id;return t.jsx("rect",{"data-selected":ie?"true":void 0,x:X.x,y:X.y,width:X.w,height:X.h,fill:ie?s.bim("warp-sel-bg"):me?s.bim("warp-hover-bg"):"transparent",stroke:ie?s.bim("warp-sel-stroke"):me?s.bim("warp-hover-stroke"):"transparent",strokeWidth:ie?3.5:me?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>c==null?void 0:c(X.id),onMouseEnter:()=>m==null?void 0:m(X.id),onMouseLeave:()=>m==null?void 0:m(null),children:t.jsx("title",{children:X.char})},X.id)}),a&&a.size>0&&qe.map(X=>{const ie=a.get(X.id);if(!ie)return null;const me=Oa(ie);return t.jsxs("g",{"data-cd":ie.tone??"","data-cd-focus":ie.focus?"":void 0,pointerEvents:"none",children:[me.bg&&t.jsx("rect",{x:X.x,y:X.y,width:X.w,height:X.h,fill:me.bg,fillOpacity:.35}),ie.underline&&t.jsx("line",{x1:X.x,x2:X.x+X.w,y1:X.y+X.h,y2:X.y+X.h,stroke:me.fg,strokeWidth:3,strokeDasharray:ie.underline==="dotted"?"2 5":ie.underline==="dashed"?"10 6":void 0}),ie.focus&&t.jsx("rect",{x:X.x,y:X.y,width:X.w,height:X.h,fill:"none",stroke:s.bim("accent"),strokeWidth:4})]},`cd-${X.id}`)}),a&&a.size>0&&qe.map(X=>{const ie=a.get(X.id);if(!ie||!ie.sub&&!ie.insertAfter)return null;const me=Oa(ie).fg,se=Math.max(12,X.w*.46),de=X.x+X.w-se*.12;return t.jsxs("g",{pointerEvents:"none",children:[ie.sub&&t.jsx(Pa,{text:ie.sub,attr:"data-cd-sub",left:de,cy:X.y+X.h/2,fs:se,fg:me}),ie.insertAfter&&t.jsx(Pa,{text:ie.insertAfter,attr:"data-cd-ins",left:de,cy:X.y+X.h,fs:se,fg:me})]},`cdb-${X.id}`)}),Ve.map(X=>{const ie=p===X.id;return t.jsx("rect",{"data-fig-block":X.id,"data-selected":ie?"true":void 0,x:X.x,y:X.y,width:X.w,height:X.h,fill:ie?s.bim("warp-sel-bg"):"transparent",stroke:ie?s.bim("warp-sel-stroke"):s.bim("warp-hover-stroke"),strokeWidth:ie?3.5:2,strokeDasharray:ie?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>h==null?void 0:h(X.id),children:t.jsx("title",{children:X.id})},`fig-${X.id}`)}),je&&t.jsxs("g",{children:[t.jsx("line",{x1:V.left+W,y1:V.top,x2:V.left+W,y2:V.top+Ne,stroke:s.bim("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:V.left+W+je.half_w,y1:V.top,x2:V.left+W+je.half_w,y2:V.top+Ne,stroke:s.bim("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:V.left+J,y1:V.top,x2:V.left+J,y2:V.top+Ne,stroke:s.bim("warp-banxin-outer"),strokeWidth:1})]})]})]})},Xs=`
|
|
1457
1457
|
.bim-et-w { position: relative; display: inline; }
|
|
1458
1458
|
.bim-et {
|
|
1459
1459
|
color: inherit; text-decoration-line: underline;
|
|
@@ -1541,23 +1541,23 @@ a.bim-et:focus-visible { outline: 2px solid ${s.bim("accent")}; outline-offset:
|
|
|
1541
1541
|
.bim-et-card[data-sheet] { animation: bim-et-up 160ms ease-out; }
|
|
1542
1542
|
@keyframes bim-et-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
|
|
1543
1543
|
}
|
|
1544
|
-
`,Cf=120;function Et(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Ef(e,i=Cf){if(!e)return;const n=e.replace(/\s+/g," ").trim(),r=Array.from(n);return r.length>i?r.slice(0,i).join("")+"…":n}function Rf(e){const i=e.dates&&typeof e.dates=="object"?e.dates:{},n=typeof i.birth=="number"?i.birth:void 0,r=typeof i.death=="number"?i.death:void 0;if(!(n===void 0&&r===void 0))return`${n??"?"}–${r??"?"}`}function Tf(e){if(!Array.isArray(e.authors))return;const i=e.authors.map(n=>{if(!n||typeof n!="object")return"";const r=n,o=Et(r.name);return o?[Et(r.dynasty)&&`〔${Et(r.dynasty)}〕`,o,Et(r.role)].filter(Boolean).join(""):""}).filter(Boolean);return i.length?i.slice(0,3).join("、"):void 0}function ed(e,i){const n=Et(i.type),r=Et(i.primary_name)??Et(i.title)??e,o=n==="entity"?[Et(i.dynasty),Rf(i),Et(i.native_place)].filter(Boolean).join(" · "):[Tf(i),Et(i.edition),Et(i.measure_info)].filter(Boolean).join(" · "),a=i.description&&typeof i.description=="object"?Et(i.description.text):Et(i.description);return{id:Et(i.id)??e,type:n,title:r,meta:o||void 0,description:Ef(a)}}function td(e){const i=[e.dynasty,e.author,e.edition].filter(Boolean).join(" · ");return{id:e.id,type:e.type,title:e.title,meta:i||void 0}}function id(e){return async i=>{const n=await e.getItem(i);if(n)return ed(i,n);if(e.getEntry){const r=await e.getEntry(i);if(r)return td(r)}return null}}const Fa=new WeakMap;function nd(e,i,n){let r=Fa.get(e);r||(r=new Map,Fa.set(e,r));const o=r.get(n);if(o)return o;const a=i(n);return r.set(n,a),a.catch(()=>r.delete(n)),a}const rd=e=>`/item/${encodeURIComponent(e)}`,os={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Js=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Zs(e,i){return b.useMemo(()=>i?{owner:i,load:i}:e?{owner:e,load:id(e)}:null,[i,e])}const If=e=>e,Mf=({text:e,entities:i,offsets:n="text",plainBase:r=0,transport:o,loadSummary:a,buildHref:l=rd,onNavigate:d,renderText:c=If,hoverDelayMs:m=250,closeDelayMs:p,injectStyles:h=!0,className:u})=>{const f=b.useMemo(()=>{const y=n==="plain"?Vc(e,i,r):i;return qc(e,y)},[e,i,n,r]),g=Zs(o,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[h&&t.jsx("style",{children:Xs}),f.map(y=>y.type==="text"?t.jsx(b.Fragment,{children:c(y.text)},`t${y.start}`):t.jsx(Qs,{span:y.span,label:y.text,hasBrackets:e[y.start-1]==="《"&&e[y.start+y.text.length]==="》",loader:g,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:m,closeDelayMs:p},`${y.span.key}@${y.start}`))]})};let Jt=null;const Qs=({span:e,label:i,hasBrackets:n,plain:r,loader:o,buildHref:a,onNavigate:l,onCardNavigate:d=l,cardNewTab:c,renderText:m,hoverDelayMs:p,closeDelayMs:h=280})=>{const u=b.useId(),[f,g]=b.useState(!1),[y,v]=b.useState(!1),[w,x]=b.useState(!1),j=b.useRef(!1),S=b.useRef(null),$=b.useRef(null),N=`bim-et bim-et-${e.kind}${r?" bim-et-nu":""}`,z=e.kind==="work"&&!n,C=t.jsxs(t.Fragment,{children:[z&&t.jsx("span",{className:"bim-et-sr",children:"《"}),m(i),z&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),U=()=>{S.current&&(clearTimeout(S.current),S.current=null)},R=()=>{$.current&&(clearTimeout($.current),$.current=null)},L=b.useRef(!1),F=b.useCallback(()=>{L.current=!1,U(),R(),g(!1),v(!1),x(!1),Jt===F&&(Jt=null)},[]);b.useEffect(()=>()=>{U(),R(),Jt===F&&(Jt=null)},[F]);const T=b.useCallback(()=>{Jt&&Jt!==F&&Jt(),Jt=F,g(!0)},[F]),Z=b.useCallback(Q=>{R(),v(!0),!f&&(U(),Q<=0?T():S.current=setTimeout(T,Q))},[f,T]),O=b.useCallback(()=>{U(),R(),!L.current&&($.current=setTimeout(F,h))},[F,h]),ae=b.useRef(null);b.useEffect(()=>{if(!f||!(e.targets||w))return;const Q=w?"click":"pointerdown",Ne=W=>{var je;(je=ae.current)!=null&&je.contains(W.target)||F()};return document.addEventListener(Q,Ne),()=>document.removeEventListener(Q,Ne)},[f,w,e.targets,F]);const ce=b.useCallback(()=>{U(),R(),L.current=!0,v(!0),x(!0),T()},[T]);Js(()=>{if(!f||!w)return;const Q=ae.current,Ne=Q==null?void 0:Q.querySelector(".bim-et-card");if(!Q||!Ne||typeof window>"u")return;const W=()=>{const K=Q.getClientRects(),V=K[K.length-1];if(!V)return;const re=V.bottom+12-Ne.getBoundingClientRect().top;re>0&&window.scrollBy({top:re,behavior:"smooth"})};if(W(),typeof ResizeObserver>"u")return;const je=new ResizeObserver(W);return je.observe(Ne),()=>je.disconnect()},[f,w]);const Ee=!!e.targetId,we=e.targetId,ye={className:"bim-et-w","data-active":y?"":void 0,onPointerEnter:Q=>{j.current=Q.pointerType==="touch"},onPointerDown:Q=>{j.current=Q.pointerType==="touch"},onMouseEnter:()=>{j.current||Z(p)},onMouseLeave:()=>{j.current||O()},onBlur:Q=>{Q.currentTarget.contains(Q.relatedTarget)||F()},onKeyDown:Q=>{Q.key==="Escape"&&f&&(Q.stopPropagation(),F())}};return e.targets?t.jsxs("span",{...ye,ref:ae,children:[t.jsx("span",{className:`${N} bim-et-multi`,role:"button",tabIndex:0,"aria-haspopup":"true","aria-expanded":f,"aria-controls":f?u:void 0,onFocus:()=>{j.current||Z(0)},onClick:()=>{j.current?ce():(R(),L.current=!0,v(!0),T())},onKeyDown:Q=>{(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),f?F():(L.current=!0,v(!0),T()))},children:C}),f&&t.jsx(Af,{id:u,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:w,onClose:F})]}):!Ee||!we?t.jsxs("span",{...ye,ref:ae,children:[t.jsx("span",{className:N,children:C}),f&&!j.current&&t.jsx(Ba,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...ye,ref:ae,children:[t.jsx("a",{className:N,href:a(we),"data-entity-id":we,"aria-describedby":f?u:void 0,onFocus:()=>{j.current||Z(0)},onClick:Q=>{if(j.current&&Q.detail>0){Q.preventDefault(),ce();return}l==null||l(we,Q)},children:C}),f&&t.jsx(Ba,{id:u,entityId:we,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:w,onClose:F})]})},Ba=({id:e,entityId:i,span:n,loader:r,buildHref:o,onNavigate:a,newTab:l,sheet:d,onClose:c})=>{const{convert:m,t:p}=oe(),h=b.useRef(null),[u,f]=b.useState("start"),[g,y]=b.useState(r&&i?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!r||!i)return;let x=!1;return y({status:"loading"}),nd(r.owner,r.load,i).then(j=>{x||y({status:"ready",summary:j})}).catch(()=>{x||y({status:"error"})}),()=>{x=!0}},[r,i]),Js(()=>{const x=h.current;if(!x||typeof window>"u")return;const j=x.getBoundingClientRect(),S=document.documentElement.clientWidth||window.innerWidth;!d&&j.right>S-8&&u==="start"&&f("end")},[g,u,d]);const v=g.status==="ready"?g.summary:null,w=(v==null?void 0:v.title)??n.canonicalName??n.text;return i?t.jsxs("span",{ref:h,id:e,role:d?"dialog":"tooltip","aria-label":d?w:void 0,className:"bim-et-card","data-align":u,"data-sheet":d?"":void 0,children:[d&&c&&t.jsx(sd,{onClose:c}),t.jsx("span",{className:"bim-et-card-k",children:m(os[n.kind])}),w&&t.jsx("span",{className:"bim-et-card-t",children:m(w)}),(v==null?void 0:v.meta)&&t.jsx("span",{className:"bim-et-card-m",children:m(v.meta)}),(v==null?void 0:v.description)&&t.jsx("span",{className:"bim-et-card-d",children:m(v.description)}),g.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:m("載入中…")}),g.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:m("摘要載入失敗")}),v&&t.jsx("a",{className:"bim-et-card-a",href:o(v.id||i),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?x=>a(v.id||i,x):void 0,children:p("reader.entityDetail")})]}):t.jsx("span",{ref:h,id:e,role:"tooltip",className:"bim-et-card","data-align":u,children:t.jsx("span",{className:"bim-et-card-k",children:m(os[n.kind])})})},Af=({id:e,span:i,loader:n,buildHref:r,onNavigate:o,newTab:a,sheet:l,onClose:d})=>{const{convert:c}=oe(),m=b.useRef(null),[p,h]=b.useState(0);Js(()=>{const f=m.current;if(!f||l||typeof window>"u")return;const g=f.getBoundingClientRect();if(!g.width)return;const y=document.documentElement.clientWidth||window.innerWidth;h(Math.max(8-g.left,Math.min(0,y-8-g.right)))},[]);const u=i.targets??[];return t.jsxs("span",{ref:m,id:e,role:"group","aria-label":c(`合稱,${u.length} 條`),className:`bim-et-card bim-et-card-multi${u.length>3?" bim-et-dense":""}`,"data-sheet":l?"":void 0,style:p&&!l?{left:p}:void 0,children:[l&&d&&t.jsx(sd,{onClose:d}),t.jsxs("span",{className:"bim-et-card-k",children:[c("合稱")," · ",c(`${u.length} 條`)]}),u.map(f=>t.jsx(Lf,{target:f,kind:i.kind,loader:n,buildHref:r,onNavigate:o,newTab:a},f.id))]})},Lf=({target:e,kind:i,loader:n,buildHref:r,onNavigate:o,newTab:a})=>{const{convert:l,t:d}=oe(),[c,m]=b.useState(n?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!n)return;let u=!1;return m({status:"loading"}),nd(n.owner,n.load,e.id).then(f=>{u||m({status:"ready",summary:f})}).catch(()=>{u||m({status:"error"})}),()=>{u=!0}},[n,e.id]);const p=c.status==="ready"?c.summary:null,h=(p==null?void 0:p.title)??e.canonicalName??e.id;return t.jsxs("span",{className:"bim-et-row","data-entity-id":e.id,children:[t.jsxs("span",{className:"bim-et-row-t",children:[e.part&&t.jsx("span",{className:"bim-et-row-p",children:Pf(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(h)}),t.jsx("span",{className:"bim-et-row-k",children:l(os[i])})]}),(p==null?void 0:p.meta)&&t.jsx("span",{className:"bim-et-card-m",children:l(p.meta)}),(p==null?void 0:p.description)&&t.jsx("span",{className:"bim-et-card-d bim-et-card-d2",children:l(p.description)}),c.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:l("載入中…")}),c.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:l("摘要載入失敗")}),p&&t.jsx("a",{className:"bim-et-card-a",href:r(p.id||e.id),...a?{target:"_blank",rel:"noopener"}:{},onClick:o?u=>o(p.id||e.id,u):void 0,children:d("reader.entityDetail")})]})},Pf=(e,i)=>`${i(e)} →`,sd=({onClose:e})=>{const{t:i}=oe();return t.jsx("button",{type:"button",className:"bim-et-card-x","aria-label":i("reader.close"),onClick:e,children:"×"})},eo=e=>`〔图:${e}〕`,od=(e,i)=>e&&i?i(e.file):null;function ad({fig:e,info:i,figUrl:n,block:r,failed:o,onFail:a}){const l=(i==null?void 0:i.alt)??"图形符号",d=od(i,n);if(!d||o)return t.jsx("span",{className:"guji-fig-missing","data-fig-missing":e,children:eo(l)});const c=i.width>0&&i.height>0?`${i.width} / ${i.height}`:void 0;return i.mime==="image/svg+xml"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"guji-fig-img is-svg",role:"img","aria-label":l,"data-fig":e,style:{"--guji-fig-src":`url("${d}")`,aspectRatio:c}}),t.jsx("img",{src:d,alt:"",hidden:!0,onError:a})]}):t.jsx("img",{className:`guji-fig-img${r?" is-block":""}`,src:d,alt:r?l:"","data-fig":e,"data-raster":"1",loading:r?"lazy":void 0,decoding:"async",draggable:!1,style:c?{aspectRatio:c}:void 0,onError:a})}function Of({id:e,fig:i,info:n,figUrl:r,cells:o,cont:a,className:l,pageStart:d,children:c}){const{t:m}=oe(),p=(n==null?void 0:n.alt)??"",h=p&&p!==m("reader.figPlain")?m("reader.figLabel",{alt:p}):m("reader.figPlain"),[u,f]=b.useState(!1),g=u||!od(n,r);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":eo((n==null?void 0:n.alt)??"图形符号"),className:`${l} is-fig${a?" is-fig-cont":""}${g&&!a?" is-fig-missing":""}`,style:a?void 0:{"--guji-fig-n":o},title:h,"aria-label":h,role:"img",children:[t.jsx("span",{className:"guji-fig-glyph",children:c}),!a&&t.jsx(ad,{fig:i,info:n,figUrl:r,failed:u,onFail:()=>f(!0)})]})}function Ff({fig:e,info:i,figUrl:n,onClick:r}){const{t:o}=oe(),a=(i==null?void 0:i.alt)??"图形符号",l=a!==o("reader.figPlain")?o("reader.figLabel",{alt:a}):o("reader.figPlain"),[d,c]=b.useState(!1);return t.jsxs("figure",{className:"guji-fig-block","data-fig-block":e,"data-fig-copy":eo(a),title:l,onClick:r,style:r?{cursor:"pointer"}:void 0,children:[t.jsx(ad,{fig:e,info:i,figUrl:n,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const Bf=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function Hf(e){const i=e.cloneContents();if(!i.querySelector("[data-fig-copy]"))return null;let n="";const r=()=>{n&&!n.endsWith(`
|
|
1544
|
+
`,Ef=120;function Et(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Rf(e,i=Ef){if(!e)return;const n=e.replace(/\s+/g," ").trim(),r=Array.from(n);return r.length>i?r.slice(0,i).join("")+"…":n}function Tf(e){const i=e.dates&&typeof e.dates=="object"?e.dates:{},n=typeof i.birth=="number"?i.birth:void 0,r=typeof i.death=="number"?i.death:void 0;if(!(n===void 0&&r===void 0))return`${n??"?"}–${r??"?"}`}function If(e){if(!Array.isArray(e.authors))return;const i=e.authors.map(n=>{if(!n||typeof n!="object")return"";const r=n,o=Et(r.name);return o?[Et(r.dynasty)&&`〔${Et(r.dynasty)}〕`,o,Et(r.role)].filter(Boolean).join(""):""}).filter(Boolean);return i.length?i.slice(0,3).join("、"):void 0}function id(e,i){const n=Et(i.type),r=Et(i.primary_name)??Et(i.title)??e,o=n==="entity"?[Et(i.dynasty),Tf(i),Et(i.native_place)].filter(Boolean).join(" · "):[If(i),Et(i.edition),Et(i.measure_info)].filter(Boolean).join(" · "),a=i.description&&typeof i.description=="object"?Et(i.description.text):Et(i.description);return{id:Et(i.id)??e,type:n,title:r,meta:o||void 0,description:Rf(a)}}function nd(e){const i=[e.dynasty,e.author,e.edition].filter(Boolean).join(" · ");return{id:e.id,type:e.type,title:e.title,meta:i||void 0}}function rd(e){return async i=>{const n=await e.getItem(i);if(n)return id(i,n);if(e.getEntry){const r=await e.getEntry(i);if(r)return nd(r)}return null}}const Ha=new WeakMap;function sd(e,i,n){let r=Ha.get(e);r||(r=new Map,Ha.set(e,r));const o=r.get(n);if(o)return o;const a=i(n);return r.set(n,a),a.catch(()=>r.delete(n)),a}const od=e=>`/item/${encodeURIComponent(e)}`,os={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Js=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Zs(e,i){return b.useMemo(()=>i?{owner:i,load:i}:e?{owner:e,load:rd(e)}:null,[i,e])}const Mf=e=>e,Af=({text:e,entities:i,offsets:n="text",plainBase:r=0,transport:o,loadSummary:a,buildHref:l=od,onNavigate:d,renderText:c=Mf,hoverDelayMs:m=250,closeDelayMs:p,injectStyles:h=!0,className:u})=>{const f=b.useMemo(()=>{const y=n==="plain"?Xc(e,i,r):i;return Jc(e,y)},[e,i,n,r]),g=Zs(o,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[h&&t.jsx("style",{children:Xs}),f.map(y=>y.type==="text"?t.jsx(b.Fragment,{children:c(y.text)},`t${y.start}`):t.jsx(Qs,{span:y.span,label:y.text,hasBrackets:e[y.start-1]==="《"&&e[y.start+y.text.length]==="》",loader:g,buildHref:l,onNavigate:d,renderText:c,hoverDelayMs:m,closeDelayMs:p},`${y.span.key}@${y.start}`))]})};let Jt=null;const Qs=({span:e,label:i,hasBrackets:n,plain:r,loader:o,buildHref:a,onNavigate:l,onCardNavigate:d=l,cardNewTab:c,renderText:m,hoverDelayMs:p,closeDelayMs:h=280})=>{const u=b.useId(),[f,g]=b.useState(!1),[y,v]=b.useState(!1),[w,x]=b.useState(!1),j=b.useRef(!1),S=b.useRef(null),$=b.useRef(null),N=`bim-et bim-et-${e.kind}${r?" bim-et-nu":""}`,z=e.kind==="work"&&!n,C=t.jsxs(t.Fragment,{children:[z&&t.jsx("span",{className:"bim-et-sr",children:"《"}),m(i),z&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),U=()=>{S.current&&(clearTimeout(S.current),S.current=null)},R=()=>{$.current&&(clearTimeout($.current),$.current=null)},L=b.useRef(!1),F=b.useCallback(()=>{L.current=!1,U(),R(),g(!1),v(!1),x(!1),Jt===F&&(Jt=null)},[]);b.useEffect(()=>()=>{U(),R(),Jt===F&&(Jt=null)},[F]);const T=b.useCallback(()=>{Jt&&Jt!==F&&Jt(),Jt=F,g(!0)},[F]),Z=b.useCallback(Q=>{R(),v(!0),!f&&(U(),Q<=0?T():S.current=setTimeout(T,Q))},[f,T]),O=b.useCallback(()=>{U(),R(),!L.current&&($.current=setTimeout(F,h))},[F,h]),ae=b.useRef(null);b.useEffect(()=>{if(!f||!(e.targets||w))return;const Q=w?"click":"pointerdown",Ne=W=>{var je;(je=ae.current)!=null&&je.contains(W.target)||F()};return document.addEventListener(Q,Ne),()=>document.removeEventListener(Q,Ne)},[f,w,e.targets,F]);const ce=b.useCallback(()=>{U(),R(),L.current=!0,v(!0),x(!0),T()},[T]);Js(()=>{if(!f||!w)return;const Q=ae.current,Ne=Q==null?void 0:Q.querySelector(".bim-et-card");if(!Q||!Ne||typeof window>"u")return;const W=()=>{const K=Q.getClientRects(),V=K[K.length-1];if(!V)return;const re=V.bottom+12-Ne.getBoundingClientRect().top;re>0&&window.scrollBy({top:re,behavior:"smooth"})};if(W(),typeof ResizeObserver>"u")return;const je=new ResizeObserver(W);return je.observe(Ne),()=>je.disconnect()},[f,w]);const Ee=!!e.targetId,we=e.targetId,ye={className:"bim-et-w","data-active":y?"":void 0,onPointerEnter:Q=>{j.current=Q.pointerType==="touch"},onPointerDown:Q=>{j.current=Q.pointerType==="touch"},onMouseEnter:()=>{j.current||Z(p)},onMouseLeave:()=>{j.current||O()},onBlur:Q=>{Q.currentTarget.contains(Q.relatedTarget)||F()},onKeyDown:Q=>{Q.key==="Escape"&&f&&(Q.stopPropagation(),F())}};return e.targets?t.jsxs("span",{...ye,ref:ae,children:[t.jsx("span",{className:`${N} bim-et-multi`,role:"button",tabIndex:0,"aria-haspopup":"true","aria-expanded":f,"aria-controls":f?u:void 0,onFocus:()=>{j.current||Z(0)},onClick:()=>{j.current?ce():(R(),L.current=!0,v(!0),T())},onKeyDown:Q=>{(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),f?F():(L.current=!0,v(!0),T()))},children:C}),f&&t.jsx(Lf,{id:u,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:w,onClose:F})]}):!Ee||!we?t.jsxs("span",{...ye,ref:ae,children:[t.jsx("span",{className:N,children:C}),f&&!j.current&&t.jsx(Da,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...ye,ref:ae,children:[t.jsx("a",{className:N,href:a(we),"data-entity-id":we,"aria-describedby":f?u:void 0,onFocus:()=>{j.current||Z(0)},onClick:Q=>{if(j.current&&Q.detail>0){Q.preventDefault(),ce();return}l==null||l(we,Q)},children:C}),f&&t.jsx(Da,{id:u,entityId:we,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:w,onClose:F})]})},Da=({id:e,entityId:i,span:n,loader:r,buildHref:o,onNavigate:a,newTab:l,sheet:d,onClose:c})=>{const{convert:m,t:p}=oe(),h=b.useRef(null),[u,f]=b.useState("start"),[g,y]=b.useState(r&&i?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!r||!i)return;let x=!1;return y({status:"loading"}),sd(r.owner,r.load,i).then(j=>{x||y({status:"ready",summary:j})}).catch(()=>{x||y({status:"error"})}),()=>{x=!0}},[r,i]),Js(()=>{const x=h.current;if(!x||typeof window>"u")return;const j=x.getBoundingClientRect(),S=document.documentElement.clientWidth||window.innerWidth;!d&&j.right>S-8&&u==="start"&&f("end")},[g,u,d]);const v=g.status==="ready"?g.summary:null,w=(v==null?void 0:v.title)??n.canonicalName??n.text;return i?t.jsxs("span",{ref:h,id:e,role:d?"dialog":"tooltip","aria-label":d?w:void 0,className:"bim-et-card","data-align":u,"data-sheet":d?"":void 0,children:[d&&c&&t.jsx(ad,{onClose:c}),t.jsx("span",{className:"bim-et-card-k",children:m(os[n.kind])}),w&&t.jsx("span",{className:"bim-et-card-t",children:m(w)}),(v==null?void 0:v.meta)&&t.jsx("span",{className:"bim-et-card-m",children:m(v.meta)}),(v==null?void 0:v.description)&&t.jsx("span",{className:"bim-et-card-d",children:m(v.description)}),g.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:m("載入中…")}),g.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:m("摘要載入失敗")}),v&&t.jsx("a",{className:"bim-et-card-a",href:o(v.id||i),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?x=>a(v.id||i,x):void 0,children:p("reader.entityDetail")})]}):t.jsx("span",{ref:h,id:e,role:"tooltip",className:"bim-et-card","data-align":u,children:t.jsx("span",{className:"bim-et-card-k",children:m(os[n.kind])})})},Lf=({id:e,span:i,loader:n,buildHref:r,onNavigate:o,newTab:a,sheet:l,onClose:d})=>{const{convert:c}=oe(),m=b.useRef(null),[p,h]=b.useState(0);Js(()=>{const f=m.current;if(!f||l||typeof window>"u")return;const g=f.getBoundingClientRect();if(!g.width)return;const y=document.documentElement.clientWidth||window.innerWidth;h(Math.max(8-g.left,Math.min(0,y-8-g.right)))},[]);const u=i.targets??[];return t.jsxs("span",{ref:m,id:e,role:"group","aria-label":c(`合稱,${u.length} 條`),className:`bim-et-card bim-et-card-multi${u.length>3?" bim-et-dense":""}`,"data-sheet":l?"":void 0,style:p&&!l?{left:p}:void 0,children:[l&&d&&t.jsx(ad,{onClose:d}),t.jsxs("span",{className:"bim-et-card-k",children:[c("合稱")," · ",c(`${u.length} 條`)]}),u.map(f=>t.jsx(Pf,{target:f,kind:i.kind,loader:n,buildHref:r,onNavigate:o,newTab:a},f.id))]})},Pf=({target:e,kind:i,loader:n,buildHref:r,onNavigate:o,newTab:a})=>{const{convert:l,t:d}=oe(),[c,m]=b.useState(n?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!n)return;let u=!1;return m({status:"loading"}),sd(n.owner,n.load,e.id).then(f=>{u||m({status:"ready",summary:f})}).catch(()=>{u||m({status:"error"})}),()=>{u=!0}},[n,e.id]);const p=c.status==="ready"?c.summary:null,h=(p==null?void 0:p.title)??e.canonicalName??e.id;return t.jsxs("span",{className:"bim-et-row","data-entity-id":e.id,children:[t.jsxs("span",{className:"bim-et-row-t",children:[e.part&&t.jsx("span",{className:"bim-et-row-p",children:Of(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(h)}),t.jsx("span",{className:"bim-et-row-k",children:l(os[i])})]}),(p==null?void 0:p.meta)&&t.jsx("span",{className:"bim-et-card-m",children:l(p.meta)}),(p==null?void 0:p.description)&&t.jsx("span",{className:"bim-et-card-d bim-et-card-d2",children:l(p.description)}),c.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:l("載入中…")}),c.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:l("摘要載入失敗")}),p&&t.jsx("a",{className:"bim-et-card-a",href:r(p.id||e.id),...a?{target:"_blank",rel:"noopener"}:{},onClick:o?u=>o(p.id||e.id,u):void 0,children:d("reader.entityDetail")})]})},Of=(e,i)=>`${i(e)} →`,ad=({onClose:e})=>{const{t:i}=oe();return t.jsx("button",{type:"button",className:"bim-et-card-x","aria-label":i("reader.close"),onClick:e,children:"×"})},eo=e=>`〔图:${e}〕`,ld=(e,i)=>e&&i?i(e.file):null;function cd({fig:e,info:i,figUrl:n,block:r,failed:o,onFail:a}){const l=(i==null?void 0:i.alt)??"图形符号",d=ld(i,n);if(!d||o)return t.jsx("span",{className:"guji-fig-missing","data-fig-missing":e,children:eo(l)});const c=i.width>0&&i.height>0?`${i.width} / ${i.height}`:void 0;return i.mime==="image/svg+xml"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"guji-fig-img is-svg",role:"img","aria-label":l,"data-fig":e,style:{"--guji-fig-src":`url("${d}")`,aspectRatio:c}}),t.jsx("img",{src:d,alt:"",hidden:!0,onError:a})]}):t.jsx("img",{className:`guji-fig-img${r?" is-block":""}`,src:d,alt:r?l:"","data-fig":e,"data-raster":"1",loading:r?"lazy":void 0,decoding:"async",draggable:!1,style:c?{aspectRatio:c}:void 0,onError:a})}function Ff({id:e,fig:i,info:n,figUrl:r,cells:o,cont:a,className:l,pageStart:d,children:c}){const{t:m}=oe(),p=(n==null?void 0:n.alt)??"",h=p&&p!==m("reader.figPlain")?m("reader.figLabel",{alt:p}):m("reader.figPlain"),[u,f]=b.useState(!1),g=u||!ld(n,r);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":eo((n==null?void 0:n.alt)??"图形符号"),className:`${l} is-fig${a?" is-fig-cont":""}${g&&!a?" is-fig-missing":""}`,style:a?void 0:{"--guji-fig-n":o},title:h,"aria-label":h,role:"img",children:[t.jsx("span",{className:"guji-fig-glyph",children:c}),!a&&t.jsx(cd,{fig:i,info:n,figUrl:r,failed:u,onFail:()=>f(!0)})]})}function Bf({fig:e,info:i,figUrl:n,onClick:r}){const{t:o}=oe(),a=(i==null?void 0:i.alt)??"图形符号",l=a!==o("reader.figPlain")?o("reader.figLabel",{alt:a}):o("reader.figPlain"),[d,c]=b.useState(!1);return t.jsxs("figure",{className:"guji-fig-block","data-fig-block":e,"data-fig-copy":eo(a),title:l,onClick:r,style:r?{cursor:"pointer"}:void 0,children:[t.jsx(cd,{fig:e,info:i,figUrl:n,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const Hf=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function Df(e){const i=e.cloneContents();if(!i.querySelector("[data-fig-copy]"))return null;let n="";const r=()=>{n&&!n.endsWith(`
|
|
1545
1545
|
`)&&(n+=`
|
|
1546
|
-
`)},o=a=>{if(a.nodeType===3){n+=a.nodeValue??"";return}if(!(a.nodeType!==1&&a.nodeType!==11)){if(a.nodeType===1){const l=a;if(l.classList.contains("guji-page-divider")||l.style.userSelect==="none")return;const d=l.getAttribute("data-fig-copy");if(d!==null){l.tagName==="FIGURE"?(r(),n+=d,r()):n+=d;return}const c=Bf.has(l.tagName);c&&r(),l.childNodes.forEach(o),c&&r();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const Df="?",Wf=e=>`/item/${encodeURIComponent(e)}`;function Uf(e){const i=e.filter(n=>n.kind==null||n.kind==="point");return{before:i.filter(n=>n.pos==="before"),after:i.filter(n=>n.pos!=="before")}}function Kf(e,i){const n=[];for(const r of e){const o=i.get(r.charData.id)??null,a=n[n.length-1];a&&a.entity===o?a.chars.push(r):n.push({entity:o,chars:[r]})}return n}const to=({pageData:e,pages:i,punctuations:n=as,selectedCharIds:r,hoveredCharId:o,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:m=!0,onVisiblePageChange:p,convert:h,scrollToPage:u,scrollToAnchor:f,onVisibleHeadingChange:g,entities:y,entityTransport:v,loadEntitySummary:w,buildEntityHref:x,onEntityNavigate:j,pageBreaks:S=!0,pageIndicatorY:$,onPageIndicatorYChange:N,quoteStyle:z,bookTitleStyle:C,showWorks:U,figures:R,figUrl:L,onFigureBlockClick:F,decorations:T})=>{var ht,We,gt;const{t:Z}=oe(),O=b.useRef(null),ae=b.useRef(0),ce=b.useMemo(()=>{const te=new Map;return m&&n.forEach((A,ne)=>{const $e=A.id?A:{...A,id:`${A.anchor}#${ne}`},Ie=te.get($e.anchor)||[];Ie.push($e),te.set($e.anchor,Ie)}),te},[n,m]),Ee=b.useMemo(()=>z===void 0&&C===void 0&&U===void 0?null:{quoteStyle:z??"original",hideBookBrackets:C==="wavy"||U===!1},[z,C,U]),we=C==="bracket",ye=b.useMemo(()=>{var Ge;const te=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],A=new Map;for(const Ae of te)for(const Ce of Ae.columns)Ce.chars.length>0&&!Ce.raised&&A.set(Ce.lead_blank||0,(A.get(Ce.lead_blank||0)||0)+1);let ne=0,$e=-1;for(const[Ae,Ce]of A)(Ce>$e||Ce===$e&&Ae<ne)&&(ne=Ae,$e=Ce);const Ie=Ae=>!!Ae.raised||(Ae.lead_blank||0)<ne,Le=te.filter(Ae=>Ae.columns.some(Ce=>Ce.chars.length>0||Ce.kind==="figure")).map(Ae=>{const Ce=[...Ae.columns].sort((it,Pt)=>it.col-Pt.col),rt=[];let st=[];const Ke=()=>{const it=ig(ce.get(st[0].charData.id));rt.push({id:`para-p${Ae.page}-${rt.length}`,chars:st,...it?{heading:{level:it.mark.length,anchor:st[0].charData.id,...it.toc===!1?{toc:!1}:{}}}:{}}),st=[]};let D=!1,ke=0,Qe;const Ye=[];for(const it of Ce){if(it.kind==="figure"&&it.fig){st.length>0?Ke():rt.length===0&&(D=!0),Ye.push({before:rt.length,fig:it.fig,...it.figBox?{box:it.figBox}:{}}),ke=0;continue}if(it.chars.length===0){it.kind==="blank"&&ke++;continue}const Pt=it.raised||it.lead_blank||ke?{raised:it.raised,leadBlank:it.lead_blank,blankBefore:ke}:void 0;ke=0,Ie(it)||(Qe=it.lead_blank||0);let dt=!0;for(const $t of it.chars){const Ot=ce.get($t.id),{before:zt,after:cr}=Ot?Uf(Ot):qf,an=!!Ot&&Ot.some(ri=>ri.kind==="break"&&ri.pos!=="before");Ot&&Ot.some(ri=>ri.kind==="heading")&&(st.length>0?Ke():rt.length===0&&(D=!0)),st.push({charData:$t,col:it.col,beforePuncts:zt,afterPuncts:cr,...dt&&Pt?{start:Pt}:{}}),dt=!1,an&&Ke()}}const wt=st.length>0;return wt&&Ke(),{page:Ae.page,paragraphs:rt,endsOpen:wt,...Qe!==void 0?{tailLead:Qe}:{},...D?{leadStarts:D}:{},...Ae.label?{label:Ae.label}:{},...ke>0?{trailingBlank:ke}:{},...Ye.length>0?{blocks:Ye}:{}}}),at=new Map;if(!S){let Ae=null;for(const Ce of Le){const rt=Ce.paragraphs[0],st=(Ge=rt==null?void 0:rt.chars[0])==null?void 0:Ge.start,Ke=(st==null?void 0:st.leadBlank)||0,D=!!st&&!st.raised&&Ke>=ne&&Ke>((Ae==null?void 0:Ae.tailLead)??ne),ke=!!Ce.leadStarts||!!(st!=null&&st.blankBefore)||D,Qe=Ce.paragraphs.length===1&&!!Ce.trailingBlank;if(Ae&&rt&&!ke&&!Qe){for(const Ye of rt.chars)at.set(Ye.charData.id,Ae.owner);Ae.para.chars=Ae.para.chars.concat(rt.chars),Ce.leadFirstId=rt.chars[0].charData.id,Ce.paragraphs=Ce.paragraphs.slice(1),Ce.blocks&&(Ce.blocks=Ce.blocks.map(Ye=>({...Ye,before:Ye.before-1})))}if(Ce.endsOpen&&!Ce.trailingBlank){const Ye=Ce.paragraphs[Ce.paragraphs.length-1];Ye?Ae={para:Ye,owner:Ce.page,tailLead:Ce.tailLead??(Ae==null?void 0:Ae.tailLead)??ne}:Ae&&Ce.tailLead!==void 0&&(Ae.tailLead=Ce.tailLead)}else Ae=null}}const lt=new Map;for(const Ae of Le)Ae.leadFirstId&<.set(Ae.leadFirstId,Ae.page);return{pages:Le,mergedOwner:at,pageStarts:lt}},[i,e,ce,S]),Q=ye.pages,Ne=b.useRef(Q);Ne.current=Q;const W=b.useMemo(()=>Q.map(te=>te.paragraphs.reduce((A,ne)=>A+ne.chars.length,0)),[Q]),je=b.useCallback((te,A)=>{let ne=te,$e=0;for(;ne<W.length&&(ne===te||$e+W[ne]<=A);)$e+=W[ne++];return ne},[W]),K=`${Q.length}:${((gt=(We=(ht=Q[0])==null?void 0:ht.paragraphs[0])==null?void 0:We.chars[0])==null?void 0:gt.charData.id)??""}`,[V,re]=b.useState(()=>({sig:K,n:je(0,Da)}));let X=V.n;V.sig!==K&&(X=je(0,Da),re({sig:K,n:X})),X=Math.min(X,Q.length);const I=X>=Q.length;b.useEffect(()=>I?void 0:(A=>{const ne=window;if(ne.requestIdleCallback){const Ie=ne.requestIdleCallback(A,{timeout:300});return()=>{var Le;return(Le=ne.cancelIdleCallback)==null?void 0:Le.call(ne,Ie)}}const $e=setTimeout(A,16);return()=>clearTimeout($e)})(()=>re(A=>A.sig===K?{sig:A.sig,n:Math.max(A.n,je(A.n,Yf))}:A)),[I,X,K,je]);const ue=b.useCallback(te=>{const A=Ne.current.findIndex($e=>$e.page>=te),ne=(A<0?Ne.current.length:A)+2;re($e=>$e.n>=ne?$e:{...$e,n:ne})},[]),fe=I?Q:Q.slice(0,X);b.useEffect(()=>{let te;const A=requestAnimationFrame(()=>{te=setTimeout(()=>{const ne=O.current,$e=ne==null?void 0:ne.querySelector(".guji-reflow-paragraph");if(!ne||!$e)return;const Ie=getComputedStyle($e),Le=parseFloat(Ie.fontSize),at=$e.clientWidth;if(!(Le>0)||!(at>0))return;const lt=parseFloat(Ie.lineHeight);ne.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(at/Le)))),ne.style.setProperty("--gtv-lh",`${Math.round(lt>0?lt:Le*2)}px`)},0)});return()=>{cancelAnimationFrame(A),te&&clearTimeout(te)}},[K]);const ze=b.useMemo(()=>{const te=[];for(const A of Q)for(const ne of A.paragraphs)for(const $e of ne.chars)te.push($e.charData.id);return te},[Q]),B=b.useMemo(()=>new Map(ze.map((te,A)=>[te,A])),[ze]),pe=b.useMemo(()=>{const te=new Map;if(!y||y.length===0)return te;const A=B;for(const ne of y){if(!ne.anchor)continue;const $e=A.get(ne.anchor.start),Ie=A.get(ne.anchor.end);if(!($e===void 0||Ie===void 0||Ie<$e))for(let Le=$e;Le<=Ie;Le++)te.has(ze[Le])||te.set(ze[Le],ne)}return te},[y,ze,B]),Te=b.useMemo(()=>{const te=f==null?void 0:f.anchor;return te&&te.startsWith("e=")?new Set(te.slice(2).split(",").filter(Boolean)):null},[f==null?void 0:f.anchor]),ve=b.useMemo(()=>{var $e;if(!Te||!y)return[];const te=new Set,A=[],ne=(Ie,Le)=>{const at=`${Ie}:${Le}`;te.has(at)||(te.add(at),A.push([Ie,Le]))};for(const Ie of y){if(!Ie.anchor)continue;const Le=B.get(Ie.anchor.start),at=B.get(Ie.anchor.end);if(!(Le===void 0||at===void 0||at<Le)){(Ie.targetId&&Te.has(Ie.targetId)||($e=Ie.targets)!=null&&$e.some(lt=>Te.has(lt.id)))&&ne(Le,at);for(const lt of Ie.parts??[]){if(!Te.has(lt.id))continue;const Ge=Le+lt.offset[0],Ae=Le+lt.offset[1]-1;Ae>=Ge&&Ae<=at&&ne(Ge,Ae)}}}return A.sort((Ie,Le)=>Ie[0]-Le[0]||Ie[1]-Le[1])},[Te,y,B]),Ve=Zs(v,w),qe=pe.size>0,Xe=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F});Xe.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F};const J=b.useMemo(()=>({click:te=>{var A,ne;ae.current=Date.now()+1200,(ne=(A=Xe.current).onCharClick)==null||ne.call(A,te)},enter:te=>{var A,ne;return(ne=(A=Xe.current).onCharHover)==null?void 0:ne.call(A,te)},leave:()=>{var te,A;return(A=(te=Xe.current).onCharHover)==null?void 0:A.call(te,null)},figBlock:te=>{var A,ne;return(ne=(A=Xe.current).onFigureBlockClick)==null?void 0:ne.call(A,te)},navigate:(te,A)=>{A.ctrlKey||A.metaKey||A.shiftKey||(A.preventDefault(),A.detail===0&&window.open(A.currentTarget.href,"_blank","noopener"))}}),[]),ie=tg(r,ye.mergedOwner),me=eg(T,ye.mergedOwner),se=b.useRef(X);se.current=X;const de=b.useRef(null),ge=b.useCallback(te=>{const A=de.current,ne=A==null?void 0:A.map.get(te);if(ne&&ne.isConnected)return ne;if(A&&A.for===Ne.current&&A.n===se.current&&!ne)return null;const $e=O.current;if(!$e)return null;const Ie=new Map;return $e.querySelectorAll("span[data-char-id]").forEach(Le=>{Ie.set(Le.getAttribute("data-char-id"),Le)}),de.current={for:Ne.current,n:se.current,map:Ie},Ie.get(te)??null},[]),Oe=b.useRef(null);b.useEffect(()=>{var A;if((A=Oe.current)==null||A.classList.remove("is-hovered"),Oe.current=null,!o)return;const te=ge(o);te&&(te.classList.add("is-hovered"),Oe.current=te)},[o,ge]);const Je=b.useRef(null),Pe=te=>{var ne;const A=te instanceof Element?te.closest("span[data-char-id]"):null;return A&&((ne=O.current)!=null&&ne.contains(A))?A.getAttribute("data-char-id"):null},Ue=te=>{const A=Pe(te.target);A&&J.click(A)},nt=te=>{const A=Pe(te.target);A!==Je.current&&(Je.current=A,A?J.enter(A):J.leave())},Y=te=>{const A=typeof window<"u"?window.getSelection():null;if(!A||A.isCollapsed||A.rangeCount===0)return;const ne=Hf(A.getRangeAt(0));ne!==null&&(te.clipboardData.setData("text/plain",ne),te.preventDefault())},M=()=>{Je.current!==null&&(Je.current=null,J.leave())};b.useEffect(()=>{let te=null;const A=()=>{var ke,Qe;te=null;const $e=window.getSelection(),Ie=O.current;if(!$e||$e.isCollapsed||$e.rangeCount===0||!Ie)return;const Le=$e.getRangeAt(0),at=Le.commonAncestorContainer,lt=at.nodeType===3?at.parentElement:at;if(!lt||!Ie.contains(lt))return;const Ge=Ie.querySelectorAll("span[data-char-id]"),Ae=Ye=>{let wt=Ye;for(;wt.nodeType!==3&&wt.firstChild;)wt=wt.firstChild;return wt};let Ce=0,rt=Ge.length;for(;Ce<rt;){const Ye=Ce+rt>>1;Le.comparePoint(Ae(Ge[Ye]),0)<0?Ce=Ye+1:rt=Ye}const st=Ce;for(rt=Ge.length;Ce<rt;){const Ye=Ce+rt>>1;Le.comparePoint(Ae(Ge[Ye]),0)<=0?Ce=Ye+1:rt=Ye}let Ke=Ce-1;if(Ke>=st&&Le.endOffset===0&&Le.endContainer===Ae(Ge[Ke])&&Ke--,Ke<st)return;const D=[];for(let Ye=st;Ye<=Ke;Ye++)D.push(Ge[Ye].getAttribute("data-char-id"));D.length>0&&(ae.current=Date.now()+1200,(Qe=(ke=Xe.current).onSelectionChange)==null||Qe.call(ke,D))},ne=()=>{te&&clearTimeout(te),te=setTimeout(A,120)};return document.addEventListener("selectionchange",ne),()=>{document.removeEventListener("selectionchange",ne),te&&clearTimeout(te)}},[]);const k=b.useRef(null);b.useEffect(()=>{if(r.size!==1||k.current===r)return;const te=Array.from(r)[0],A=ge(te);if(A)k.current=r,A.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ne=parseInt(te.split(":")[0],10);isNaN(ne)||ue(ne)}},[r,X,ge,ue]);const P=te=>{var $e;const A=O.current;if(!A)return null;const ne=($e=Q.find(Ie=>Ie.page===te))==null?void 0:$e.leadFirstId;return ne?A.querySelector(`span[data-char-id="${ne}"]`):A.querySelector(`[data-page-section="${te}"]`)},q=u==null?void 0:u.nonce,_=b.useRef(null);b.useEffect(()=>{if(!u||_.current===u.nonce)return;const te=P(u.page);if(!te){!I&&Q.some(A=>A.page>=u.page)&&ue(u.page);return}_.current=u.nonce,ae.current=Date.now()+800,te.scrollIntoView({behavior:"auto",block:"start"})},[q,X]);const le=b.useRef(null),H=b.useRef([]);b.useEffect(()=>{var Le,at,lt;if(!f||le.current===f.nonce||f.anchor.startsWith("e="))return;const[te,A]=f.anchor.split("~"),ne=O.current,$e=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(te)}"]`),Ie=parseInt(te.split(":")[0],10);if(!$e){if(!I&&!isNaN(Ie)&&Q.some(Ge=>Ge.page>=Ie)){ue(Ie);return}A&&!isNaN(Ie)&&(le.current=f.nonce,(Le=P(Ie))==null||Le.scrollIntoView({behavior:"auto",block:"start"}));return}le.current=f.nonce,ae.current=Date.now()+800;for(const Ge of H.current)Ge.classList.remove("guji-hl");if(H.current=[],A){const Ge=B.get(te),Ae=B.get(A);if(Ge!==void 0&&Ae!==void 0&&Ae>=Ge&&Ae-Ge<64)for(let Ce=Ge;Ce<=Ae;Ce++){const rt=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(ze[Ce])}"]`);rt&&(rt.classList.add("guji-hl"),H.current.push(rt))}Ha($e,ae)}else($e.closest(".guji-reflow-paragraph")??$e).scrollIntoView({behavior:"auto",block:"start"});isNaN(Ie)||(lt=(at=Xe.current).onVisiblePageChange)==null||lt.call(at,Ie)},[f,Q,X,I,ue,ze,B]);const[he,xe]=b.useState(null),[Re,Ze]=b.useState(!1),Me=b.useRef(null);b.useEffect(()=>{!f||!Te||Me.current===f.nonce||ve.length===0||(Me.current=f.nonce,Ze(!1),xe({k:0,nonce:Date.now()}))},[f,Te,ve]);const He=b.useRef(null);b.useEffect(()=>{var Le,at;if(!he||He.current===he.nonce)return;const te=ve[he.k];if(!te)return;const A=O.current,ne=ze[te[0]],$e=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ne)}"]`),Ie=parseInt(ne.split(":")[0],10);if(!$e){!I&&!isNaN(Ie)&&ue(Ie);return}He.current=he.nonce;for(const lt of H.current)lt.classList.remove("guji-hl");H.current=[];for(let lt=te[0];lt<=te[1];lt++){const Ge=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ze[lt])}"]`);Ge&&(Ge.classList.add("guji-hl"),H.current.push(Ge))}Ha($e,ae),isNaN(Ie)||(at=(Le=Xe.current).onVisiblePageChange)==null||at.call(Le,Ie)},[he,ve,ze,X,I,ue]);const ct=b.useMemo(()=>{if(!Te||Re||ve.length===0)return"";const te=[];for(const[A,ne]of ve)for(let $e=A;$e<=ne;$e++)te.push(`.guji-text-pane-content span[data-char-id="${Li(ze[$e])}"]`);return`${te.join(",")}{background:${s.bim("mark-soft")};border-radius:2px}`},[Te,Re,ve,ze]),Be=te=>xe(A=>{const ne=ve.length;return{k:(((A==null?void 0:A.k)??0)+te+ne)%ne,nonce:Date.now()}}),ee=()=>{Ze(!0);for(const te of H.current)te.classList.remove("guji-hl");H.current=[]},Se=!!p||!!g,et=!!p&&typeof $=="number",[tt,De]=b.useState(null),Fe=ls(tt??$??0),pt=b.useRef(null);pt.current=et?Fe:null;const bt=b.useRef(()=>{});return b.useEffect(()=>{var rt,st;if(!Se)return;const te=new Map,A=new Map;(rt=O.current)==null||rt.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ke=>{const D=Ke.getAttribute("data-page-section");D!==null?te.set(D,Ke):A.set(Ke.getAttribute("data-page-start"),Ke)});const ne=[],$e=[];for(const Ke of fe){const D=te.get(String(Ke.page));D&&(ne.push(D),$e.push(Ke.page))}if(ne.length===0)return;const Ie=new Map(ne.map((Ke,D)=>[Ke,D])),Le=ne.map(()=>[]);let at=0;(st=O.current)==null||st.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ke=>{const D=Ie.get(Ke.closest("[data-page-section]"));D!==void 0&&(Le[D].push(Ke),at++)});let lt,Ge=0;const Ae=()=>{var it,Pt;if(Ge=0,Date.now()<ae.current)return;const Ke=dt=>dt.getBoundingClientRect().top;if(ne.length>1&&Ke(ne[0])===Ke(ne[ne.length-1]))return;const D=pt.current===null?120:pt.current*window.innerHeight;let ke=0,Qe=ne.length-1;for(;ke<Qe;){const dt=ke+Qe+1>>1;Ke(ne[dt])<=D?ke=dt:Qe=dt-1}const Ye=Ke(ne[0])>D;let wt=$e[ke];for(let dt=ke+1;dt<ne.length;dt++){const $t=A.get(String($e[dt]));if(!$t||!ne[ke].contains($t)||Ke($t)>D)break;wt=$e[dt]}if(at>0&&Xe.current.onVisibleHeadingChange){let dt=null;if(!Ye){const Ot=Le[ke];for(let zt=Ot.length-1;zt>=0&&!dt;zt--)Ke(Ot[zt])<=D&&(dt=Ot[zt]);for(let zt=ke-1;zt>=0&&!dt;zt--)Le[zt].length>0&&(dt=Le[zt][Le[zt].length-1])}const $t=dt?ng(dt):null;$t!==lt&&(lt=$t,Xe.current.onVisibleHeadingChange($t))}(Pt=(it=Xe.current).onVisiblePageChange)==null||Pt.call(it,wt)},Ce=()=>{Ge||(Ge=requestAnimationFrame(Ae))};return bt.current=()=>{Ge||(Ge=requestAnimationFrame(Ae))},window.addEventListener("scroll",Ce,{passive:!0}),Ce(),()=>{window.removeEventListener("scroll",Ce),Ge&&cancelAnimationFrame(Ge),bt.current=()=>{}}},[Se,Q,X]),b.useEffect(()=>{et&&bt.current()},[et,Fe]),t.jsxs("div",{ref:O,className:"guji-text-pane-content",onClick:Ue,onMouseOver:nt,onMouseLeave:M,onCopy:Y,children:[qe&&t.jsx("style",{children:Xs}),ct&&t.jsx("style",{children:ct}),ct&&he&&t.jsxs("div",{className:"bim-rd-mnav bim-d-ui",role:"navigation","aria-label":Z("mentions.navLabel"),children:[t.jsx("span",{children:Z("mentions.navCount",{k:he.k+1,n:ve.length})}),t.jsx("button",{type:"button",onClick:()=>Be(-1),"aria-label":Z("mentions.prev"),title:Z("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>Be(1),"aria-label":Z("mentions.next"),title:Z("mentions.next"),children:"›"}),t.jsx("button",{type:"button",onClick:ee,"aria-label":Z("mentions.close"),title:Z("mentions.close"),children:"×"})]}),et&&t.jsx(cg,{y:Fe,containerRef:O,onDrag:De,onCommit:te=>{De(null),N==null||N(te)}}),t.jsx("div",{className:"guji-text-reflow-view",children:fe.map((te,A)=>t.jsx(og,{pGroup:te,first:A===0,pageBreaks:S,markOpts:Ee,plainBooks:we,selected:ie.get(te.page)??Vf,decorations:me.get(te.page),entityOfChar:pe,entityLoader:Ve,convert:h,buildHref:x??Wf,handlers:J,charCount:W[A]??0,pageStarts:ye.pageStarts,figures:R,figUrl:L},`page-sec-${te.page}`))})]})};function Ha(e,i){i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"});let n=!1;const r=()=>{n=!0},o=["wheel","touchstart","keydown","mousedown"];o.forEach(a=>window.addEventListener(a,r,{once:!0,passive:!0})),[120,350,700,1100,1500].forEach((a,l,d)=>setTimeout(()=>{if(!n&&e.isConnected){const c=e.getBoundingClientRect();(c.top<80||c.bottom>window.innerHeight-40)&&(i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"}))}l===d.length-1&&o.forEach(c=>window.removeEventListener(c,r))},a))}const Da=1800,Yf=800,Gf="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",Vf=new Set,as=[],qf={before:as,after:as},Xf={};function Jf(e){if(!e)return Xf;const i={"data-cd":e.tone??""};return e.sub&&(i["data-cd-sub"]=e.sub),e.focus&&(i["data-cd-focus"]=""),(e.bg||e.fg)&&(i["data-cd-custom"]=""),i}function Zf(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function Qf(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function eg(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;if(e&&e.size>0){const o=new Map;e.forEach((a,l)=>{const d=i.get(l)??parseInt(l.split(":")[0],10);let c=o.get(d);c||o.set(d,c=new Map),c.set(l,a)}),o.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(([m,p])=>{const h=d.get(m);return!!h&&Rh(h,p)});r.set(l,c?d:a)})}return n.current=r,r},[e,i])}function tg(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;e.forEach(a=>{const l=i.get(a)??parseInt(a.split(":")[0],10);let d=r.get(l);d||r.set(l,d=new Set),d.add(a)});const o=new Map;return r.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(m=>d.has(m));o.set(l,c?d:a)}),n.current=o,o},[e,i])}function ig(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function ng(e){return e.getAttribute("data-heading-anchor")}function Li(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Wa({n:e}){return t.jsx(t.Fragment,{children:Array.from({length:e},(i,n)=>t.jsx("span",{className:"guji-text-blank-col","aria-hidden":"true","data-blank-col":""},n))})}function rg(e,i){const n=Array.from(i(e.join("")));return n.length===e.length&&e.every(r=>Array.from(r).length===1)?n:e.map(r=>i(r))}function sg({heading:e,children:i}){if(!e)return t.jsx("p",{className:"guji-reflow-paragraph",children:i});const n=`h${Math.min(6,e.level+1)}`;return t.jsx(n,{className:`guji-reflow-paragraph guji-reflow-heading guji-reflow-h${e.level}`,"data-heading-anchor":e.anchor,"data-heading-level":e.level,"data-heading-toc":e.toc===!1?"0":void 0,children:i})}const og=b.memo(function({pGroup:i,first:n,pageBreaks:r,markOpts:o,plainBooks:a,selected:l,decorations:d,entityOfChar:c,entityLoader:m,convert:p,buildHref:h,handlers:u,charCount:f,pageStarts:g,figures:y,figUrl:v}){const w=b.useMemo(()=>{const N=new Map;if(!p)return N;for(const z of i.paragraphs){const C=rg(z.chars.map(U=>U.charData.fig?U.charData.char:U.charData.norm??U.charData.char),p);z.chars.forEach((U,R)=>N.set(U.charData.id,U.charData.fig?U.charData.char:C[R]))}return N},[i,p]),x=N=>N.unk?Df:w.get(N.id)??N.char,{t:j}=oe(),S=N=>{const z=o?Wc(N.mark,o):N.mark;return z?t.jsx("span",{className:"guji-text-punct","data-punct-id":N.id,children:z},N.id):null},$=N=>{var z;return(z=i.blocks)==null?void 0:z.map((C,U)=>C.before===N&&t.jsx(Ff,{fig:C.fig,info:y==null?void 0:y.get(C.fig),figUrl:v,onClick:()=>u.figBlock({page:i.page,fig:C.fig,...C.box?{box:C.box}:{}})},`fig-${C.fig}-${U}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:Gf,"--gtv-pc":f,"--gtv-pp":i.paragraphs.length},children:[!n&&r&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:s.bim("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},"data-page-label":i.label,title:i.label?`${i.page}`:void 0,children:["第 ",i.label??i.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}})]}),i.paragraphs.map((N,z)=>t.jsxs(b.Fragment,{children:[$(z),t.jsxs(sg,{heading:N.heading,children:[Kf(N.chars,c).map((C,U)=>{const R=C.chars.map(({charData:T,beforePuncts:Z,afterPuncts:O,start:ae},ce)=>{var K,V,re;const Ee=!!C.entity&&ce===0,we=!!C.entity&&ce===C.chars.length-1,ye=Ee?[]:Z,Q=we?[]:O,Ne=!!T.fig&&ce>0&&C.chars[ce-1].charData.fig===T.fig;let W=1;if(T.fig&&!Ne)for(;((K=C.chars[ce+W])==null?void 0:K.charData.fig)===T.fig;)W++;const je=`guji-text-char${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${ae!=null&&ae.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[ae&&ae.blankBefore>0&&t.jsx(Wa,{n:ae.blankBefore}),ye.map(S),T.fig?t.jsx(Of,{id:T.id,fig:T.fig,info:y==null?void 0:y.get(T.fig),figUrl:v,cells:W,cont:Ne,className:je,pageStart:g.get(T.id),children:x(T)}):t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-char-id":T.id,"data-page-start":g.get(T.id),...Jf(d==null?void 0:d.get(T.id)),style:Zf(d==null?void 0:d.get(T.id)),className:`guji-text-char${Qf(d==null?void 0:d.get(T.id))}${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${T.lacuna||T.pending&&T.char==="□"?" is-lacuna":""}${T.unk?" is-unk":""}${T.pending?" is-pending":""}${T.lacuna&&T.guess_c?" has-guess":""}${T.guess?" is-guess":""}${T.zi?" is-zi":""}${ae!=null&&ae.raised?" is-raised":""}`,"data-raised":(ae==null?void 0:ae.raised)||void 0,"data-guji-guess":T.lacuna&&T.guess_c?T.guess_c:void 0,title:((V=d==null?void 0:d.get(T.id))==null?void 0:V.title)??(T.unk?j("reader.unkChar",{label:p?p(T.unk):T.unk}):T.pending?j("reader.pendingReason",{label:p?p(_e.pendingReasonLabel(T.pending)):_e.pendingReasonLabel(T.pending)}):T.lacuna?T.guess_c?j("reader.lacunaGuess",{guess:p?p(T.guess_c):T.guess_c}):j("detail.lacuna"):T.zi?j("detail.composedChar",{label:T.zi}):T.guess?j("reader.charGuess"):void 0),children:x(T)}),((re=d==null?void 0:d.get(T.id))==null?void 0:re.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(T.id).insertAfter})]}),Q.map(S)]},T.id)});if(!C.entity)return t.jsx(b.Fragment,{children:R},`r${U}`);const L=C.chars[0].beforePuncts.map(S),F=C.chars[C.chars.length-1].afterPuncts.map(S);return t.jsxs(b.Fragment,{children:[L,t.jsx(Qs,{span:C.entity,label:C.chars.map(T=>x(T.charData)).join(""),hasBrackets:!0,plain:a&&C.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>R,hoverDelayMs:250}),F]},`${C.entity.key}@${U}`)}),z===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Wa,{n:i.trailingBlank}):null]})]},N.id)),$(i.paragraphs.length)]})});function ls(e){const[i,n]=Vi,r=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,r))*1e3)/1e3}const ag=.02,xi=16,lg=4;function cg({y:e,containerRef:i,onDrag:n,onCommit:r}){const{t:o}=oe(),[a,l]=b.useState(0),d=b.useRef(!1),c=b.useRef(null),m=b.useRef(e);m.current=e;const p=b.useCallback(()=>{var y;const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=f==null?void 0:f.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-xi-lg))},[i]);b.useLayoutEffect(()=>{var y;window.addEventListener("resize",p);const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=typeof ResizeObserver<"u"?new ResizeObserver(()=>p()):null;for(const v of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])v&&(g==null||g.observe(v));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>ls(u/Math.max(1,window.innerHeight));return t.jsx("div",{ref:c,role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":o("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Vi[0]*100),"aria-valuemax":Math.round(Vi[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${xi/2}px)`,width:xi,height:xi,zIndex:20,cursor:"ns-resize",touchAction:"none",display:"flex",alignItems:"center",justifyContent:"center",color:s.bim("meta-fg")},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const f=h(u.clientY);m.current=f,n(f)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}r(h(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,r(m.current))},onKeyDown:u=>{const f=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;f&&(u.preventDefault(),r(ls(e+f*(u.shiftKey?5:1)*ag)))},children:t.jsx("svg",{width:xi,height:xi,viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2 8h11M9 4l4 4-4 4"})})})}const ld=1,cd=6,vn={s:1,x:0,y:0},En=(e,i,n)=>Math.min(n,Math.max(i,e));function io(e,i,n){const r=En(e.s,ld,cd);return{s:r,x:En(e.x,i*(1-r),0),y:En(e.y,n*(1-r),0)}}function Or(e,i,n,r,o,a){const l=En(e.s*r,ld,cd),d=l/e.s;return io({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function dg(e,i,n,r,o){return io({s:e.s,x:e.x+i,y:e.y+n},r,o)}function mg(e,i,n){const r=i===1?e*16:i===2?e*400:e;return Math.exp(-r*(n?.01:.0015))}const Ua=4,ug=b.forwardRef(function({children:i,onScaleChange:n,resetKey:r,style:o},a){const l=b.useRef(null),[d,c]=b.useState(vn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var S;const j=m.current;m.current=x,c(x),x.s!==j.s&&((S=p.current)==null||S.call(p,x.s))},u=()=>{var j;const x=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(x==null?void 0:x.width)??0,h:(x==null?void 0:x.height)??0,left:(x==null?void 0:x.left)??0,top:(x==null?void 0:x.top)??0}};b.useImperativeHandle(a,()=>({zoomBy(x){const{w:j,h:S}=u();h(Or(m.current,j/2,S/2,x,j,S))},reset(){h(vn)}})),b.useEffect(()=>{h(vn)},[r]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:S,h:$}=u(),N=io(m.current,S,$);(N.x!==m.current.x||N.y!==m.current.y)&&h(N)});return j.observe(x),()=>j.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const j=S=>{const $=mg(S.deltaY,S.deltaMode,S.ctrlKey);if(m.current.s<=1&&$<1)return;S.preventDefault();const{w:N,h:z,left:C,top:U}=u();h(Or(m.current,S.clientX-C,S.clientY-U,$,N,z))};return x.addEventListener("wheel",j,{passive:!1}),()=>x.removeEventListener("wheel",j)},[]);const f=b.useRef(new Map),g=b.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),y=x=>{if(x.pointerType==="mouse"&&x.button!==0)return;f.current.set(x.pointerId,{x:x.clientX,y:x.clientY});const j=g.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[S,$]=[...f.current.values()];j.pinchDist=Math.hypot(S.x-$.x,S.y-$.y),j.moved=Ua+1}},v=x=>{var F;const j=f.current.get(x.pointerId);if(!j)return;const S={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,S);const $=g.current,{w:N,h:z,left:C,top:U}=u();if(f.current.size>=2){const[T,Z]=[...f.current.values()],O=Math.hypot(T.x-Z.x,T.y-Z.y);if($.pinchDist>0&&O>0){const ae=(T.x+Z.x)/2-C,ce=(T.y+Z.y)/2-U;h(Or(m.current,ae,ce,O/$.pinchDist,N,z))}$.pinchDist=O,$.swallowClick=!0;return}const R=S.x-j.x,L=S.y-j.y;if($.moved+=Math.abs(R)+Math.abs(L),!($.moved<=Ua)){if(!$.dragging){$.dragging=!0;try{(F=l.current)==null||F.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(dg(m.current,R,L,N,z))}},w=x=>{f.current.delete(x.pointerId);const j=g.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:v,onPointerUp:w,onPointerCancel:w,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(vn),style:{position:"relative",overflow:"hidden",touchAction:"none",cursor:d.s>1?"grab":void 0,...o},children:t.jsx("div",{className:"bim-zp-inner",style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",transformOrigin:"0 0",transform:`translate(${d.x}px, ${d.y}px) scale(${d.s})`,willChange:d.s>1?"transform":void 0},children:i})})});function dd(e,i,n,r,o=""){const a=`${o}
|
|
1546
|
+
`)},o=a=>{if(a.nodeType===3){n+=a.nodeValue??"";return}if(!(a.nodeType!==1&&a.nodeType!==11)){if(a.nodeType===1){const l=a;if(l.classList.contains("guji-page-divider")||l.style.userSelect==="none")return;const d=l.getAttribute("data-fig-copy");if(d!==null){l.tagName==="FIGURE"?(r(),n+=d,r()):n+=d;return}const c=Hf.has(l.tagName);c&&r(),l.childNodes.forEach(o),c&&r();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const Wf="?",Uf=e=>`/item/${encodeURIComponent(e)}`;function Kf(e){const i=e.filter(n=>n.kind==null||n.kind==="point");return{before:i.filter(n=>n.pos==="before"),after:i.filter(n=>n.pos!=="before")}}function Yf(e,i){const n=[];for(const r of e){const o=i.get(r.charData.id)??null,a=n[n.length-1];a&&a.entity===o?a.chars.push(r):n.push({entity:o,chars:[r]})}return n}const to=({pageData:e,pages:i,punctuations:n=as,selectedCharIds:r,hoveredCharId:o,onSelectionChange:a,onCharClick:l,onCharHover:d,mode:c="horizontal",showPunctuation:m=!0,onVisiblePageChange:p,convert:h,scrollToPage:u,scrollToAnchor:f,onVisibleHeadingChange:g,entities:y,entityTransport:v,loadEntitySummary:w,buildEntityHref:x,onEntityNavigate:j,pageBreaks:S=!0,pageIndicatorY:$,onPageIndicatorYChange:N,quoteStyle:z,bookTitleStyle:C,showWorks:U,figures:R,figUrl:L,onFigureBlockClick:F,decorations:T})=>{var ht,We,gt;const{t:Z}=oe(),O=b.useRef(null),ae=b.useRef(0),ce=b.useMemo(()=>{const te=new Map;return m&&n.forEach((A,ne)=>{const $e=A.id?A:{...A,id:`${A.anchor}#${ne}`},Ie=te.get($e.anchor)||[];Ie.push($e),te.set($e.anchor,Ie)}),te},[n,m]),Ee=b.useMemo(()=>z===void 0&&C===void 0&&U===void 0?null:{quoteStyle:z??"original",hideBookBrackets:C==="wavy"||U===!1},[z,C,U]),we=C==="bracket",ye=b.useMemo(()=>{var Ge;const te=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],A=new Map;for(const Ae of te)for(const Ce of Ae.columns)Ce.chars.length>0&&!Ce.raised&&A.set(Ce.lead_blank||0,(A.get(Ce.lead_blank||0)||0)+1);let ne=0,$e=-1;for(const[Ae,Ce]of A)(Ce>$e||Ce===$e&&Ae<ne)&&(ne=Ae,$e=Ce);const Ie=Ae=>!!Ae.raised||(Ae.lead_blank||0)<ne,Le=te.filter(Ae=>Ae.columns.some(Ce=>Ce.chars.length>0||Ce.kind==="figure")).map(Ae=>{const Ce=[...Ae.columns].sort((it,Pt)=>it.col-Pt.col),rt=[];let st=[];const Ke=()=>{const it=ng(ce.get(st[0].charData.id));rt.push({id:`para-p${Ae.page}-${rt.length}`,chars:st,...it?{heading:{level:it.mark.length,anchor:st[0].charData.id,...it.toc===!1?{toc:!1}:{}}}:{}}),st=[]};let D=!1,ke=0,Qe;const Ye=[];for(const it of Ce){if(it.kind==="figure"&&it.fig){st.length>0?Ke():rt.length===0&&(D=!0),Ye.push({before:rt.length,fig:it.fig,...it.figBox?{box:it.figBox}:{}}),ke=0;continue}if(it.chars.length===0){it.kind==="blank"&&ke++;continue}const Pt=it.raised||it.lead_blank||ke?{raised:it.raised,leadBlank:it.lead_blank,blankBefore:ke}:void 0;ke=0,Ie(it)||(Qe=it.lead_blank||0);let dt=!0;for(const $t of it.chars){const Ot=ce.get($t.id),{before:zt,after:cr}=Ot?Kf(Ot):Xf,an=!!Ot&&Ot.some(ri=>ri.kind==="break"&&ri.pos!=="before");Ot&&Ot.some(ri=>ri.kind==="heading")&&(st.length>0?Ke():rt.length===0&&(D=!0)),st.push({charData:$t,col:it.col,beforePuncts:zt,afterPuncts:cr,...dt&&Pt?{start:Pt}:{}}),dt=!1,an&&Ke()}}const wt=st.length>0;return wt&&Ke(),{page:Ae.page,paragraphs:rt,endsOpen:wt,...Qe!==void 0?{tailLead:Qe}:{},...D?{leadStarts:D}:{},...Ae.label?{label:Ae.label}:{},...ke>0?{trailingBlank:ke}:{},...Ye.length>0?{blocks:Ye}:{}}}),at=new Map;if(!S){let Ae=null;for(const Ce of Le){const rt=Ce.paragraphs[0],st=(Ge=rt==null?void 0:rt.chars[0])==null?void 0:Ge.start,Ke=(st==null?void 0:st.leadBlank)||0,D=!!st&&!st.raised&&Ke>=ne&&Ke>((Ae==null?void 0:Ae.tailLead)??ne),ke=!!Ce.leadStarts||!!(st!=null&&st.blankBefore)||D,Qe=Ce.paragraphs.length===1&&!!Ce.trailingBlank;if(Ae&&rt&&!ke&&!Qe){for(const Ye of rt.chars)at.set(Ye.charData.id,Ae.owner);Ae.para.chars=Ae.para.chars.concat(rt.chars),Ce.leadFirstId=rt.chars[0].charData.id,Ce.paragraphs=Ce.paragraphs.slice(1),Ce.blocks&&(Ce.blocks=Ce.blocks.map(Ye=>({...Ye,before:Ye.before-1})))}if(Ce.endsOpen&&!Ce.trailingBlank){const Ye=Ce.paragraphs[Ce.paragraphs.length-1];Ye?Ae={para:Ye,owner:Ce.page,tailLead:Ce.tailLead??(Ae==null?void 0:Ae.tailLead)??ne}:Ae&&Ce.tailLead!==void 0&&(Ae.tailLead=Ce.tailLead)}else Ae=null}}const lt=new Map;for(const Ae of Le)Ae.leadFirstId&<.set(Ae.leadFirstId,Ae.page);return{pages:Le,mergedOwner:at,pageStarts:lt}},[i,e,ce,S]),Q=ye.pages,Ne=b.useRef(Q);Ne.current=Q;const W=b.useMemo(()=>Q.map(te=>te.paragraphs.reduce((A,ne)=>A+ne.chars.length,0)),[Q]),je=b.useCallback((te,A)=>{let ne=te,$e=0;for(;ne<W.length&&(ne===te||$e+W[ne]<=A);)$e+=W[ne++];return ne},[W]),K=`${Q.length}:${((gt=(We=(ht=Q[0])==null?void 0:ht.paragraphs[0])==null?void 0:We.chars[0])==null?void 0:gt.charData.id)??""}`,[V,re]=b.useState(()=>({sig:K,n:je(0,Ua)}));let J=V.n;V.sig!==K&&(J=je(0,Ua),re({sig:K,n:J})),J=Math.min(J,Q.length);const I=J>=Q.length;b.useEffect(()=>I?void 0:(A=>{const ne=window;if(ne.requestIdleCallback){const Ie=ne.requestIdleCallback(A,{timeout:300});return()=>{var Le;return(Le=ne.cancelIdleCallback)==null?void 0:Le.call(ne,Ie)}}const $e=setTimeout(A,16);return()=>clearTimeout($e)})(()=>re(A=>A.sig===K?{sig:A.sig,n:Math.max(A.n,je(A.n,Gf))}:A)),[I,J,K,je]);const ue=b.useCallback(te=>{const A=Ne.current.findIndex($e=>$e.page>=te),ne=(A<0?Ne.current.length:A)+2;re($e=>$e.n>=ne?$e:{...$e,n:ne})},[]),fe=I?Q:Q.slice(0,J);b.useEffect(()=>{let te;const A=requestAnimationFrame(()=>{te=setTimeout(()=>{const ne=O.current,$e=ne==null?void 0:ne.querySelector(".guji-reflow-paragraph");if(!ne||!$e)return;const Ie=getComputedStyle($e),Le=parseFloat(Ie.fontSize),at=$e.clientWidth;if(!(Le>0)||!(at>0))return;const lt=parseFloat(Ie.lineHeight);ne.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(at/Le)))),ne.style.setProperty("--gtv-lh",`${Math.round(lt>0?lt:Le*2)}px`)},0)});return()=>{cancelAnimationFrame(A),te&&clearTimeout(te)}},[K]);const ze=b.useMemo(()=>{const te=[];for(const A of Q)for(const ne of A.paragraphs)for(const $e of ne.chars)te.push($e.charData.id);return te},[Q]),B=b.useMemo(()=>new Map(ze.map((te,A)=>[te,A])),[ze]),pe=b.useMemo(()=>{const te=new Map;if(!y||y.length===0)return te;const A=B;for(const ne of y){if(!ne.anchor)continue;const $e=A.get(ne.anchor.start),Ie=A.get(ne.anchor.end);if(!($e===void 0||Ie===void 0||Ie<$e))for(let Le=$e;Le<=Ie;Le++)te.has(ze[Le])||te.set(ze[Le],ne)}return te},[y,ze,B]),Te=b.useMemo(()=>{const te=f==null?void 0:f.anchor;return te&&te.startsWith("e=")?new Set(te.slice(2).split(",").filter(Boolean)):null},[f==null?void 0:f.anchor]),ve=b.useMemo(()=>{var $e;if(!Te||!y)return[];const te=new Set,A=[],ne=(Ie,Le)=>{const at=`${Ie}:${Le}`;te.has(at)||(te.add(at),A.push([Ie,Le]))};for(const Ie of y){if(!Ie.anchor)continue;const Le=B.get(Ie.anchor.start),at=B.get(Ie.anchor.end);if(!(Le===void 0||at===void 0||at<Le)){(Ie.targetId&&Te.has(Ie.targetId)||($e=Ie.targets)!=null&&$e.some(lt=>Te.has(lt.id)))&&ne(Le,at);for(const lt of Ie.parts??[]){if(!Te.has(lt.id))continue;const Ge=Le+lt.offset[0],Ae=Le+lt.offset[1]-1;Ae>=Ge&&Ae<=at&&ne(Ge,Ae)}}}return A.sort((Ie,Le)=>Ie[0]-Le[0]||Ie[1]-Le[1])},[Te,y,B]),Ve=Zs(v,w),qe=pe.size>0,Xe=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F});Xe.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:F};const X=b.useMemo(()=>({click:te=>{var A,ne;ae.current=Date.now()+1200,(ne=(A=Xe.current).onCharClick)==null||ne.call(A,te)},enter:te=>{var A,ne;return(ne=(A=Xe.current).onCharHover)==null?void 0:ne.call(A,te)},leave:()=>{var te,A;return(A=(te=Xe.current).onCharHover)==null?void 0:A.call(te,null)},figBlock:te=>{var A,ne;return(ne=(A=Xe.current).onFigureBlockClick)==null?void 0:ne.call(A,te)},navigate:(te,A)=>{A.ctrlKey||A.metaKey||A.shiftKey||(A.preventDefault(),A.detail===0&&window.open(A.currentTarget.href,"_blank","noopener"))}}),[]),ie=ig(r,ye.mergedOwner),me=tg(T,ye.mergedOwner),se=b.useRef(J);se.current=J;const de=b.useRef(null),ge=b.useCallback(te=>{const A=de.current,ne=A==null?void 0:A.map.get(te);if(ne&&ne.isConnected)return ne;if(A&&A.for===Ne.current&&A.n===se.current&&!ne)return null;const $e=O.current;if(!$e)return null;const Ie=new Map;return $e.querySelectorAll("span[data-char-id]").forEach(Le=>{Ie.set(Le.getAttribute("data-char-id"),Le)}),de.current={for:Ne.current,n:se.current,map:Ie},Ie.get(te)??null},[]),Oe=b.useRef(null);b.useEffect(()=>{var A;if((A=Oe.current)==null||A.classList.remove("is-hovered"),Oe.current=null,!o)return;const te=ge(o);te&&(te.classList.add("is-hovered"),Oe.current=te)},[o,ge]);const Je=b.useRef(null),Pe=te=>{var ne;const A=te instanceof Element?te.closest("span[data-char-id]"):null;return A&&((ne=O.current)!=null&&ne.contains(A))?A.getAttribute("data-char-id"):null},Ue=te=>{const A=Pe(te.target);A&&X.click(A)},nt=te=>{const A=Pe(te.target);A!==Je.current&&(Je.current=A,A?X.enter(A):X.leave())},Y=te=>{const A=typeof window<"u"?window.getSelection():null;if(!A||A.isCollapsed||A.rangeCount===0)return;const ne=Df(A.getRangeAt(0));ne!==null&&(te.clipboardData.setData("text/plain",ne),te.preventDefault())},M=()=>{Je.current!==null&&(Je.current=null,X.leave())};b.useEffect(()=>{let te=null;const A=()=>{var ke,Qe;te=null;const $e=window.getSelection(),Ie=O.current;if(!$e||$e.isCollapsed||$e.rangeCount===0||!Ie)return;const Le=$e.getRangeAt(0),at=Le.commonAncestorContainer,lt=at.nodeType===3?at.parentElement:at;if(!lt||!Ie.contains(lt))return;const Ge=Ie.querySelectorAll("span[data-char-id]"),Ae=Ye=>{let wt=Ye;for(;wt.nodeType!==3&&wt.firstChild;)wt=wt.firstChild;return wt};let Ce=0,rt=Ge.length;for(;Ce<rt;){const Ye=Ce+rt>>1;Le.comparePoint(Ae(Ge[Ye]),0)<0?Ce=Ye+1:rt=Ye}const st=Ce;for(rt=Ge.length;Ce<rt;){const Ye=Ce+rt>>1;Le.comparePoint(Ae(Ge[Ye]),0)<=0?Ce=Ye+1:rt=Ye}let Ke=Ce-1;if(Ke>=st&&Le.endOffset===0&&Le.endContainer===Ae(Ge[Ke])&&Ke--,Ke<st)return;const D=[];for(let Ye=st;Ye<=Ke;Ye++)D.push(Ge[Ye].getAttribute("data-char-id"));D.length>0&&(ae.current=Date.now()+1200,(Qe=(ke=Xe.current).onSelectionChange)==null||Qe.call(ke,D))},ne=()=>{te&&clearTimeout(te),te=setTimeout(A,120)};return document.addEventListener("selectionchange",ne),()=>{document.removeEventListener("selectionchange",ne),te&&clearTimeout(te)}},[]);const k=b.useRef(null);b.useEffect(()=>{if(r.size!==1||k.current===r)return;const te=Array.from(r)[0],A=ge(te);if(A)k.current=r,A.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ne=parseInt(te.split(":")[0],10);isNaN(ne)||ue(ne)}},[r,J,ge,ue]);const P=te=>{var $e;const A=O.current;if(!A)return null;const ne=($e=Q.find(Ie=>Ie.page===te))==null?void 0:$e.leadFirstId;return ne?A.querySelector(`span[data-char-id="${ne}"]`):A.querySelector(`[data-page-section="${te}"]`)},q=u==null?void 0:u.nonce,_=b.useRef(null);b.useEffect(()=>{if(!u||_.current===u.nonce)return;const te=P(u.page);if(!te){!I&&Q.some(A=>A.page>=u.page)&&ue(u.page);return}_.current=u.nonce,ae.current=Date.now()+800,te.scrollIntoView({behavior:"auto",block:"start"})},[q,J]);const le=b.useRef(null),H=b.useRef([]);b.useEffect(()=>{var Le,at,lt;if(!f||le.current===f.nonce||f.anchor.startsWith("e="))return;const[te,A]=f.anchor.split("~"),ne=O.current,$e=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(te)}"]`),Ie=parseInt(te.split(":")[0],10);if(!$e){if(!I&&!isNaN(Ie)&&Q.some(Ge=>Ge.page>=Ie)){ue(Ie);return}A&&!isNaN(Ie)&&(le.current=f.nonce,(Le=P(Ie))==null||Le.scrollIntoView({behavior:"auto",block:"start"}));return}le.current=f.nonce,ae.current=Date.now()+800;for(const Ge of H.current)Ge.classList.remove("guji-hl");if(H.current=[],A){const Ge=B.get(te),Ae=B.get(A);if(Ge!==void 0&&Ae!==void 0&&Ae>=Ge&&Ae-Ge<64)for(let Ce=Ge;Ce<=Ae;Ce++){const rt=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(ze[Ce])}"]`);rt&&(rt.classList.add("guji-hl"),H.current.push(rt))}Wa($e,ae)}else($e.closest(".guji-reflow-paragraph")??$e).scrollIntoView({behavior:"auto",block:"start"});isNaN(Ie)||(lt=(at=Xe.current).onVisiblePageChange)==null||lt.call(at,Ie)},[f,Q,J,I,ue,ze,B]);const[he,xe]=b.useState(null),[Re,Ze]=b.useState(!1),Me=b.useRef(null);b.useEffect(()=>{!f||!Te||Me.current===f.nonce||ve.length===0||(Me.current=f.nonce,Ze(!1),xe({k:0,nonce:Date.now()}))},[f,Te,ve]);const He=b.useRef(null);b.useEffect(()=>{var Le,at;if(!he||He.current===he.nonce)return;const te=ve[he.k];if(!te)return;const A=O.current,ne=ze[te[0]],$e=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ne)}"]`),Ie=parseInt(ne.split(":")[0],10);if(!$e){!I&&!isNaN(Ie)&&ue(Ie);return}He.current=he.nonce;for(const lt of H.current)lt.classList.remove("guji-hl");H.current=[];for(let lt=te[0];lt<=te[1];lt++){const Ge=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ze[lt])}"]`);Ge&&(Ge.classList.add("guji-hl"),H.current.push(Ge))}Wa($e,ae),isNaN(Ie)||(at=(Le=Xe.current).onVisiblePageChange)==null||at.call(Le,Ie)},[he,ve,ze,J,I,ue]);const ct=b.useMemo(()=>{if(!Te||Re||ve.length===0)return"";const te=[];for(const[A,ne]of ve)for(let $e=A;$e<=ne;$e++)te.push(`.guji-text-pane-content span[data-char-id="${Li(ze[$e])}"]`);return`${te.join(",")}{background:${s.bim("mark-soft")};border-radius:2px}`},[Te,Re,ve,ze]),Be=te=>xe(A=>{const ne=ve.length;return{k:(((A==null?void 0:A.k)??0)+te+ne)%ne,nonce:Date.now()}}),ee=()=>{Ze(!0);for(const te of H.current)te.classList.remove("guji-hl");H.current=[]},Se=!!p||!!g,et=!!p&&typeof $=="number",[tt,De]=b.useState(null),Fe=ls(tt??$??0),pt=b.useRef(null);pt.current=et?Fe:null;const bt=b.useRef(()=>{});return b.useEffect(()=>{var rt,st;if(!Se)return;const te=new Map,A=new Map;(rt=O.current)==null||rt.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ke=>{const D=Ke.getAttribute("data-page-section");D!==null?te.set(D,Ke):A.set(Ke.getAttribute("data-page-start"),Ke)});const ne=[],$e=[];for(const Ke of fe){const D=te.get(String(Ke.page));D&&(ne.push(D),$e.push(Ke.page))}if(ne.length===0)return;const Ie=new Map(ne.map((Ke,D)=>[Ke,D])),Le=ne.map(()=>[]);let at=0;(st=O.current)==null||st.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ke=>{const D=Ie.get(Ke.closest("[data-page-section]"));D!==void 0&&(Le[D].push(Ke),at++)});let lt,Ge=0;const Ae=()=>{var it,Pt;if(Ge=0,Date.now()<ae.current)return;const Ke=dt=>dt.getBoundingClientRect().top;if(ne.length>1&&Ke(ne[0])===Ke(ne[ne.length-1]))return;const D=pt.current===null?120:pt.current*window.innerHeight;let ke=0,Qe=ne.length-1;for(;ke<Qe;){const dt=ke+Qe+1>>1;Ke(ne[dt])<=D?ke=dt:Qe=dt-1}const Ye=Ke(ne[0])>D;let wt=$e[ke];for(let dt=ke+1;dt<ne.length;dt++){const $t=A.get(String($e[dt]));if(!$t||!ne[ke].contains($t)||Ke($t)>D)break;wt=$e[dt]}if(at>0&&Xe.current.onVisibleHeadingChange){let dt=null;if(!Ye){const Ot=Le[ke];for(let zt=Ot.length-1;zt>=0&&!dt;zt--)Ke(Ot[zt])<=D&&(dt=Ot[zt]);for(let zt=ke-1;zt>=0&&!dt;zt--)Le[zt].length>0&&(dt=Le[zt][Le[zt].length-1])}const $t=dt?rg(dt):null;$t!==lt&&(lt=$t,Xe.current.onVisibleHeadingChange($t))}(Pt=(it=Xe.current).onVisiblePageChange)==null||Pt.call(it,wt)},Ce=()=>{Ge||(Ge=requestAnimationFrame(Ae))};return bt.current=()=>{Ge||(Ge=requestAnimationFrame(Ae))},window.addEventListener("scroll",Ce,{passive:!0}),Ce(),()=>{window.removeEventListener("scroll",Ce),Ge&&cancelAnimationFrame(Ge),bt.current=()=>{}}},[Se,Q,J]),b.useEffect(()=>{et&&bt.current()},[et,Fe]),t.jsxs("div",{ref:O,className:"guji-text-pane-content",onClick:Ue,onMouseOver:nt,onMouseLeave:M,onCopy:Y,children:[qe&&t.jsx("style",{children:Xs}),ct&&t.jsx("style",{children:ct}),ct&&he&&t.jsxs("div",{className:"bim-rd-mnav bim-d-ui",role:"navigation","aria-label":Z("mentions.navLabel"),children:[t.jsx("span",{children:Z("mentions.navCount",{k:he.k+1,n:ve.length})}),t.jsx("button",{type:"button",onClick:()=>Be(-1),"aria-label":Z("mentions.prev"),title:Z("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>Be(1),"aria-label":Z("mentions.next"),title:Z("mentions.next"),children:"›"}),t.jsx("button",{type:"button",onClick:ee,"aria-label":Z("mentions.close"),title:Z("mentions.close"),children:"×"})]}),et&&t.jsx(dg,{y:Fe,containerRef:O,onDrag:De,onCommit:te=>{De(null),N==null||N(te)}}),t.jsx("div",{className:"guji-text-reflow-view",children:fe.map((te,A)=>t.jsx(ag,{pGroup:te,first:A===0,pageBreaks:S,markOpts:Ee,plainBooks:we,selected:ie.get(te.page)??qf,decorations:me.get(te.page),entityOfChar:pe,entityLoader:Ve,convert:h,buildHref:x??Uf,handlers:X,charCount:W[A]??0,pageStarts:ye.pageStarts,figures:R,figUrl:L},`page-sec-${te.page}`))})]})};function Wa(e,i){i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"});let n=!1;const r=()=>{n=!0},o=["wheel","touchstart","keydown","mousedown"];o.forEach(a=>window.addEventListener(a,r,{once:!0,passive:!0})),[120,350,700,1100,1500].forEach((a,l,d)=>setTimeout(()=>{if(!n&&e.isConnected){const c=e.getBoundingClientRect();(c.top<80||c.bottom>window.innerHeight-40)&&(i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"}))}l===d.length-1&&o.forEach(c=>window.removeEventListener(c,r))},a))}const Ua=1800,Gf=800,Vf="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",qf=new Set,as=[],Xf={before:as,after:as},Jf={};function Zf(e){if(!e)return Jf;const i={"data-cd":e.tone??""};return e.sub&&(i["data-cd-sub"]=e.sub),e.focus&&(i["data-cd-focus"]=""),(e.bg||e.fg)&&(i["data-cd-custom"]=""),i}function Qf(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function eg(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function tg(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;if(e&&e.size>0){const o=new Map;e.forEach((a,l)=>{const d=i.get(l)??parseInt(l.split(":")[0],10);let c=o.get(d);c||o.set(d,c=new Map),c.set(l,a)}),o.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(([m,p])=>{const h=d.get(m);return!!h&&Ih(h,p)});r.set(l,c?d:a)})}return n.current=r,r},[e,i])}function ig(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const r=new Map;e.forEach(a=>{const l=i.get(a)??parseInt(a.split(":")[0],10);let d=r.get(l);d||r.set(l,d=new Set),d.add(a)});const o=new Map;return r.forEach((a,l)=>{const d=n.current.get(l),c=d&&d.size===a.size&&Array.from(a).every(m=>d.has(m));o.set(l,c?d:a)}),n.current=o,o},[e,i])}function ng(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function rg(e){return e.getAttribute("data-heading-anchor")}function Li(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Ka({n:e}){return t.jsx(t.Fragment,{children:Array.from({length:e},(i,n)=>t.jsx("span",{className:"guji-text-blank-col","aria-hidden":"true","data-blank-col":""},n))})}function sg(e,i){const n=Array.from(i(e.join("")));return n.length===e.length&&e.every(r=>Array.from(r).length===1)?n:e.map(r=>i(r))}function og({heading:e,children:i}){if(!e)return t.jsx("p",{className:"guji-reflow-paragraph",children:i});const n=`h${Math.min(6,e.level+1)}`;return t.jsx(n,{className:`guji-reflow-paragraph guji-reflow-heading guji-reflow-h${e.level}`,"data-heading-anchor":e.anchor,"data-heading-level":e.level,"data-heading-toc":e.toc===!1?"0":void 0,children:i})}const ag=b.memo(function({pGroup:i,first:n,pageBreaks:r,markOpts:o,plainBooks:a,selected:l,decorations:d,entityOfChar:c,entityLoader:m,convert:p,buildHref:h,handlers:u,charCount:f,pageStarts:g,figures:y,figUrl:v}){const w=b.useMemo(()=>{const N=new Map;if(!p)return N;for(const z of i.paragraphs){const C=sg(z.chars.map(U=>U.charData.fig?U.charData.char:U.charData.norm??U.charData.char),p);z.chars.forEach((U,R)=>N.set(U.charData.id,U.charData.fig?U.charData.char:C[R]))}return N},[i,p]),x=N=>N.unk?Wf:w.get(N.id)??N.char,{t:j}=oe(),S=N=>{const z=o?Kc(N.mark,o):N.mark;return z?t.jsx("span",{className:"guji-text-punct","data-punct-id":N.id,children:z},N.id):null},$=N=>{var z;return(z=i.blocks)==null?void 0:z.map((C,U)=>C.before===N&&t.jsx(Bf,{fig:C.fig,info:y==null?void 0:y.get(C.fig),figUrl:v,onClick:()=>u.figBlock({page:i.page,fig:C.fig,...C.box?{box:C.box}:{}})},`fig-${C.fig}-${U}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:Vf,"--gtv-pc":f,"--gtv-pp":i.paragraphs.length},children:[!n&&r&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:s.bim("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}}),t.jsxs("span",{style:{padding:"0 12px",fontWeight:500},"data-page-label":i.label,title:i.label?`${i.page}`:void 0,children:["第 ",i.label??i.page," 葉"]}),t.jsx("div",{style:{flex:1,height:"1px",background:s.bim("rule")}})]}),i.paragraphs.map((N,z)=>t.jsxs(b.Fragment,{children:[$(z),t.jsxs(og,{heading:N.heading,children:[Yf(N.chars,c).map((C,U)=>{const R=C.chars.map(({charData:T,beforePuncts:Z,afterPuncts:O,start:ae},ce)=>{var K,V,re;const Ee=!!C.entity&&ce===0,we=!!C.entity&&ce===C.chars.length-1,ye=Ee?[]:Z,Q=we?[]:O,Ne=!!T.fig&&ce>0&&C.chars[ce-1].charData.fig===T.fig;let W=1;if(T.fig&&!Ne)for(;((K=C.chars[ce+W])==null?void 0:K.charData.fig)===T.fig;)W++;const je=`guji-text-char${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${ae!=null&&ae.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[ae&&ae.blankBefore>0&&t.jsx(Ka,{n:ae.blankBefore}),ye.map(S),T.fig?t.jsx(Ff,{id:T.id,fig:T.fig,info:y==null?void 0:y.get(T.fig),figUrl:v,cells:W,cont:Ne,className:je,pageStart:g.get(T.id),children:x(T)}):t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-char-id":T.id,"data-page-start":g.get(T.id),...Zf(d==null?void 0:d.get(T.id)),style:Qf(d==null?void 0:d.get(T.id)),className:`guji-text-char${eg(d==null?void 0:d.get(T.id))}${l.has(T.id)?" is-selected":""}${T.sub?" is-sub":""}${T.lane==="solo"?" is-solo":""}${T.lacuna||T.pending&&T.char==="□"?" is-lacuna":""}${T.unk?" is-unk":""}${T.pending?" is-pending":""}${T.lacuna&&T.guess_c?" has-guess":""}${T.guess?" is-guess":""}${T.zi?" is-zi":""}${ae!=null&&ae.raised?" is-raised":""}`,"data-raised":(ae==null?void 0:ae.raised)||void 0,"data-guji-guess":T.lacuna&&T.guess_c?T.guess_c:void 0,title:((V=d==null?void 0:d.get(T.id))==null?void 0:V.title)??(T.unk?j("reader.unkChar",{label:p?p(T.unk):T.unk}):T.pending?j("reader.pendingReason",{label:p?p(_e.pendingReasonLabel(T.pending)):_e.pendingReasonLabel(T.pending)}):T.lacuna?T.guess_c?j("reader.lacunaGuess",{guess:p?p(T.guess_c):T.guess_c}):j("detail.lacuna"):T.zi?j("detail.composedChar",{label:T.zi}):T.guess?j("reader.charGuess"):void 0),children:x(T)}),((re=d==null?void 0:d.get(T.id))==null?void 0:re.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(T.id).insertAfter})]}),Q.map(S)]},T.id)});if(!C.entity)return t.jsx(b.Fragment,{children:R},`r${U}`);const L=C.chars[0].beforePuncts.map(S),F=C.chars[C.chars.length-1].afterPuncts.map(S);return t.jsxs(b.Fragment,{children:[L,t.jsx(Qs,{span:C.entity,label:C.chars.map(T=>x(T.charData)).join(""),hasBrackets:!0,plain:a&&C.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>R,hoverDelayMs:250}),F]},`${C.entity.key}@${U}`)}),z===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Ka,{n:i.trailingBlank}):null]})]},N.id)),$(i.paragraphs.length)]})});function ls(e){const[i,n]=Vi,r=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,r))*1e3)/1e3}const lg=.02,xi=16,cg=4;function dg({y:e,containerRef:i,onDrag:n,onCommit:r}){const{t:o}=oe(),[a,l]=b.useState(0),d=b.useRef(!1),c=b.useRef(null),m=b.useRef(e);m.current=e;const p=b.useCallback(()=>{var y;const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=f==null?void 0:f.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-xi-cg))},[i]);b.useLayoutEffect(()=>{var y;window.addEventListener("resize",p);const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=typeof ResizeObserver<"u"?new ResizeObserver(()=>p()):null;for(const v of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])v&&(g==null||g.observe(v));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>ls(u/Math.max(1,window.innerHeight));return t.jsx("div",{ref:c,role:"slider",tabIndex:0,className:"guji-page-indicator","aria-label":o("reader.pageIndicator"),"aria-orientation":"vertical","aria-valuemin":Math.round(Vi[0]*100),"aria-valuemax":Math.round(Vi[1]*100),"aria-valuenow":Math.round(e*100),"data-indicator-y":e,style:{position:"fixed",left:a,top:`calc(${e*100}vh - ${xi/2}px)`,width:xi,height:xi,zIndex:20,cursor:"ns-resize",touchAction:"none",display:"flex",alignItems:"center",justifyContent:"center",color:s.bim("meta-fg")},onPointerDown:u=>{d.current=!0;try{u.currentTarget.setPointerCapture(u.pointerId)}catch{}u.preventDefault()},onPointerMove:u=>{if(!d.current)return;const f=h(u.clientY);m.current=f,n(f)},onPointerUp:u=>{if(d.current){d.current=!1;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}r(h(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,r(m.current))},onKeyDown:u=>{const f=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;f&&(u.preventDefault(),r(ls(e+f*(u.shiftKey?5:1)*lg)))},children:t.jsx("svg",{width:xi,height:xi,viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",fill:"none",stroke:"currentColor",strokeWidth:1.6,strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M2 8h11M9 4l4 4-4 4"})})})}const dd=1,md=6,vn={s:1,x:0,y:0},En=(e,i,n)=>Math.min(n,Math.max(i,e));function io(e,i,n){const r=En(e.s,dd,md);return{s:r,x:En(e.x,i*(1-r),0),y:En(e.y,n*(1-r),0)}}function Or(e,i,n,r,o,a){const l=En(e.s*r,dd,md),d=l/e.s;return io({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function mg(e,i,n,r,o){return io({s:e.s,x:e.x+i,y:e.y+n},r,o)}function ug(e,i,n){const r=i===1?e*16:i===2?e*400:e;return Math.exp(-r*(n?.01:.0015))}const Ya=4,pg=b.forwardRef(function({children:i,onScaleChange:n,resetKey:r,style:o},a){const l=b.useRef(null),[d,c]=b.useState(vn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var S;const j=m.current;m.current=x,c(x),x.s!==j.s&&((S=p.current)==null||S.call(p,x.s))},u=()=>{var j;const x=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(x==null?void 0:x.width)??0,h:(x==null?void 0:x.height)??0,left:(x==null?void 0:x.left)??0,top:(x==null?void 0:x.top)??0}};b.useImperativeHandle(a,()=>({zoomBy(x){const{w:j,h:S}=u();h(Or(m.current,j/2,S/2,x,j,S))},reset(){h(vn)}})),b.useEffect(()=>{h(vn)},[r]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:S,h:$}=u(),N=io(m.current,S,$);(N.x!==m.current.x||N.y!==m.current.y)&&h(N)});return j.observe(x),()=>j.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const j=S=>{const $=ug(S.deltaY,S.deltaMode,S.ctrlKey);if(m.current.s<=1&&$<1)return;S.preventDefault();const{w:N,h:z,left:C,top:U}=u();h(Or(m.current,S.clientX-C,S.clientY-U,$,N,z))};return x.addEventListener("wheel",j,{passive:!1}),()=>x.removeEventListener("wheel",j)},[]);const f=b.useRef(new Map),g=b.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),y=x=>{if(x.pointerType==="mouse"&&x.button!==0)return;f.current.set(x.pointerId,{x:x.clientX,y:x.clientY});const j=g.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[S,$]=[...f.current.values()];j.pinchDist=Math.hypot(S.x-$.x,S.y-$.y),j.moved=Ya+1}},v=x=>{var F;const j=f.current.get(x.pointerId);if(!j)return;const S={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,S);const $=g.current,{w:N,h:z,left:C,top:U}=u();if(f.current.size>=2){const[T,Z]=[...f.current.values()],O=Math.hypot(T.x-Z.x,T.y-Z.y);if($.pinchDist>0&&O>0){const ae=(T.x+Z.x)/2-C,ce=(T.y+Z.y)/2-U;h(Or(m.current,ae,ce,O/$.pinchDist,N,z))}$.pinchDist=O,$.swallowClick=!0;return}const R=S.x-j.x,L=S.y-j.y;if($.moved+=Math.abs(R)+Math.abs(L),!($.moved<=Ya)){if(!$.dragging){$.dragging=!0;try{(F=l.current)==null||F.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(mg(m.current,R,L,N,z))}},w=x=>{f.current.delete(x.pointerId);const j=g.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:v,onPointerUp:w,onPointerCancel:w,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(vn),style:{position:"relative",overflow:"hidden",touchAction:"none",cursor:d.s>1?"grab":void 0,...o},children:t.jsx("div",{className:"bim-zp-inner",style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",transformOrigin:"0 0",transform:`translate(${d.x}px, ${d.y}px) scale(${d.s})`,willChange:d.s>1?"transform":void 0},children:i})})});function ud(e,i,n,r,o=""){const a=`${o}
|
|
1547
1547
|
${r.versionKey??""}
|
|
1548
|
-
${n??""}`,[l,d]=b.useState({tag:"",data:null}),c=b.useRef(0);if(b.useEffect(()=>{if(i!==void 0)return;const p=++c.current,h=u=>{p===c.current&&d({tag:a,data:u})};if(!n)return h(null);if(e){let u;try{u=e(n,r)}catch{return h(null)}if(!u||typeof u.then!="function")return h(u??null);u.then(f=>h(f??null),()=>h(null));return}h(null)},[e,i,n,r,a]),i!==void 0)return{warpData:i,loading:!1};const m=l.tag===a;return{warpData:m?l.data:null,loading:!!e&&!!n&&!m}}function
|
|
1548
|
+
${n??""}`,[l,d]=b.useState({tag:"",data:null}),c=b.useRef(0);if(b.useEffect(()=>{if(i!==void 0)return;const p=++c.current,h=u=>{p===c.current&&d({tag:a,data:u})};if(!n)return h(null);if(e){let u;try{u=e(n,r)}catch{return h(null)}if(!u||typeof u.then!="function")return h(u??null);u.then(f=>h(f??null),()=>h(null));return}h(null)},[e,i,n,r,a]),i!==void 0)return{warpData:i,loading:!1};const m=l.tag===a;return{warpData:m?l.data:null,loading:!!e&&!!n&&!m}}function bg(e,i,n,r=""){const o=`${r}
|
|
1549
1549
|
${n.versionKey??""}
|
|
1550
|
-
${i??""}`,[a,l]=b.useState({tag:"",spans:[]}),d=b.useRef(0);return b.useEffect(()=>{const c=++d.current,m=h=>{c===d.current&&l({tag:o,spans:h})};if(!e||!i){m([]);return}let p;try{p=e(i,n)}catch{m([]);return}Promise.resolve(p).then(h=>m(h?
|
|
1551
|
-
${E}`;if(ve.current.has(G))return ve.current.get(G)??null;const be=await ae.getIndex(n,E).catch(()=>null);return be&&ve.current.set(G,be),be},[ae,n]),[qe,Xe]=b.useState(null),[
|
|
1550
|
+
${i??""}`,[a,l]=b.useState({tag:"",spans:[]}),d=b.useRef(0);return b.useEffect(()=>{const c=++d.current,m=h=>{c===d.current&&l({tag:o,spans:h})};if(!e||!i){m([]);return}let p;try{p=e(i,n)}catch{m([]);return}Promise.resolve(p).then(h=>m(h?qc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:hg}const hg=[],fg=/^#{1,6}$/,gg=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function xg(e){let i=e.trim();const n=gg.exec(i);return n&&(i=n[1]+n[2]),i.replace(/[《》〈〉]/g,"").trim()}const Ga=e=>e.kind==null||e.kind==="point";function pd(e,i){var d;if(!e||!i||i.length===0)return[];const n=new Map;let r=!1;for(const c of i){c.kind==="heading"&&(r=!0);const m=n.get(c.anchor);m?m.push(c):n.set(c.anchor,[c])}if(!r)return[];const o=[];let a=null;const l=()=>{a&&(a.fixed||(a.h.label=xg(a.text)),a.h.label&&o.push(a.h)),a=null};for(const c of e){const m=[...c.columns].sort((p,h)=>p.col-h.col);for(const p of m)for(const h of p.chars){const u=n.get(h.id)??[],f=u.find(g=>g.kind==="heading"&&g.pos==="before"&&fg.test(g.mark));if(f&&l(),f&&f.toc!==!1){const g=(d=f.label)==null?void 0:d.trim();a={h:{level:f.mark.length,label:g??"",anchor:h.id},text:"",fixed:!!g}}if(a&&!a.fixed){for(const g of u)Ga(g)&&g.pos==="before"&&(a.text+=g.mark);a.text+=h.char;for(const g of u)Ga(g)&&g.pos!=="before"&&(a.text+=g.mark)}u.some(g=>g.kind==="break"&&g.pos!=="before")&&l()}}return l(),o}function cs(e){if(!Array.isArray(e))return[];const i=[];for(const n of e){if(!n||typeof n!="object")continue;const{level:r,label:o,anchor:a}=n;typeof r!="number"||!Number.isInteger(r)||r<1||r>6||typeof o!="string"||!o.trim()||typeof a!="string"||!a||i.push({level:r,label:o.trim(),anchor:a})}return i}function no(e,i){return`${e}#${i}`}function bd(e){const i=e.indexOf("#");return i<=0||i===e.length-1?null:{chapter:e.slice(0,i),anchor:e.slice(i+1)}}function hd(e){const i=[],n=[];for(const r of e){const o={...r,children:[]};for(;n.length>0&&n[n.length-1].level>=r.level;)n.pop();n.length===0?i.push(o):n[n.length-1].children.push(o),n.push(o)}return i}const yg=[1,2,3,-1];function Rn(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const jg=150,Va="(min-width: 860px)";function kg(){const[e,i]=b.useState(()=>typeof window>"u"||!window.matchMedia?!0:window.matchMedia(Va).matches);return b.useEffect(()=>{var o;if(!window.matchMedia)return;const n=window.matchMedia(Va),r=()=>i(n.matches);return r(),(o=n.addEventListener)==null||o.call(n,"change",r),()=>{var a;return(a=n.removeEventListener)==null?void 0:a.call(n,"change",r)}},[]),e}const qa={padding:24,color:s.bim("desc-fg"),fontSize:14};function Xa({title:e,label:i,className:n,style:r}){const o=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:s.bim("rule")});return t.jsxs("div",{className:n,style:{...r,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:s.bim("ink"),fontFamily:s.bim("font-ui")},children:e}),t.jsx("div",{style:o("42%",24,28)}),t.jsx("div",{style:o("30%",12,10)}),["96%","100%","92%","98%","64%"].map((a,l)=>t.jsx("div",{style:o(a,16,l===0?30:14)},l)),t.jsx("p",{role:"status",style:{marginTop:24,color:s.bim("desc-fg"),fontSize:14,fontFamily:s.bim("font-ui")},children:i})]})}const Ja=/^https?:\/\//i,wg=[];function vg(e){if(!e||typeof e!="object")return null;const i=a=>typeof a=="string"&&a.trim()?a.trim():void 0,n=i(e.url),r=i(e.license_url),o={name:i(e.name),url:n&&Ja.test(n)?n:void 0,license:i(e.license),license_url:r&&Ja.test(r)?r:void 0,note:i(e.note)};return o.name||o.license||o.note?o:null}function Sg(e,i){return{work_id:i.work_id??e,title:i.title,type:i.type,juan_files:i.chapters.map(n=>n.file),juan_metadata:i.juan_metadata,juan_groups:i.juan_groups,references:i.references,target_source:i.target_source,target_source_id:i.target_source_id,text_source:i.text_source,text_quality:i.text_quality}}function Za(e,i){return(i==null?void 0:i.type)==="kaozhen"?"章":i!=null&&i.juan_metadata&&Object.values(i.juan_metadata).some(n=>n.vol_label)||Array.isArray(i==null?void 0:i.heading_levels)&&i.heading_levels.length>0?"冊":_e.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function fd(e,i,n,r=!1){const o=n(`${i}${e.n}`);if(!e.title)return o;const a=n(e.title);return r&&!/^[卷冊册章篇回第]/.test(e.title)?`${o} ${a}`:a}function gd(e,i,n){return i.map(r=>({key:no(e,r.anchor),label:n(r.label),inChapter:!0,...r.children.length>0?{selectable:!0,children:gd(e,r.children,n)}:{}}))}function $g(e,i,n,r,o,a=()=>[]){var p;const l=new Map(e.chapters.map(h=>[h.file,h])),d=h=>h==="loading"?"…":typeof h=="number"&&h>0?h:void 0,c=(h,u)=>{const f=l.get(h),g=f?a(f):[];return{key:h,label:u??(f?fd(f,n,r,o):h),hint:d(i[h]),disabled:i[h]===0,...g.length>0?{selectable:!0,children:gd(h,hd(g),r)}:{}}},m=(p=e.juan_groups)==null?void 0:p.filter(h=>{var u;return h.files.some(f=>l.has(f))||((u=h.children)==null?void 0:u.length)});if(m&&m.length>0){const h=(u,f)=>{var y;if(u.files.length===1&&!((y=u.children)!=null&&y.length))return c(u.files[0],r(u.label));const g=Zh(u,i);return{key:`group:${f}`,label:r(u.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:ed(u),defaultExpanded:typeof g=="number"&&g>0,children:[...u.files.filter(v=>l.has(v)).map(v=>c(v)),...(u.children??[]).map((v,w)=>h(v,`${f}.${w}`))]}};return m.map((u,f)=>h(u,`${f}`))}return e.chapters.map(h=>c(h.file))}const xd=e=>{const i=mc(),n=e.initialChapter,[r,o]=b.useState(!1),[a,l]=b.useState(!1);b.useEffect(()=>{if(!n)return;const c=window.setTimeout(()=>l(!0),1e4);return()=>window.clearTimeout(c)},[n]);const d=b.useCallback(()=>o(!0),[]);return t.jsxs(t.Fragment,{children:[t.jsx(xu,{mode:i[0].scriptMode,children:t.jsx(Ng,{...e,prefsState:i,onBodyReady:n?d:void 0})}),n&&!r&&!a&&t.jsx(_g,{data:n})]})};function _g({data:e}){const{t:i}=oe();return t.jsxs("section",{"data-reader-lead":!0,style:{maxWidth:768,margin:"0 auto",padding:"24px 16px",lineHeight:2},children:[e.paragraphs.map((n,r)=>t.jsx("p",{style:{marginBottom:16},children:n},r)),e.truncated&&e.selfHref&&t.jsx("p",{children:t.jsx("a",{href:e.selfHref,children:i("reader.continueReading")})}),t.jsxs("nav",{style:{marginTop:16,display:"flex",flexWrap:"wrap",gap:16,fontSize:14},children:[e.prev&&t.jsx("a",{href:e.prev.href,rel:"prev",children:e.prev.label}),e.next&&t.jsx("a",{href:e.next.href,rel:"next",children:e.next.label}),e.itemHref&&t.jsx("a",{href:e.itemHref,children:e.itemLabel})]})]})}const Ng=({prefsState:e,onBodyReady:i,id:n,transport:r,versionKey:o,chapter:a,onLocationChange:l,onNavigate:d,anchor:c,title:m,subtitle:p,resolveImages:h,resolveFacsimile:u,renderImageOverlay:f,imagePanel:g,allowVertical:y,onReportError:v,revisedAt:w,backHref:x,backLabel:j,resolveWarpData:S,textFileBase:$,onChapterData:N,hideSupersededVersions:z=!0,warpData:C,resolveEntities:U,onEntityNavigate:R,plugins:L,className:F,style:T})=>{var Ao,Lo,Po,Oo;const{t:Z,convert:O}=oe(),ae=b.useMemo(()=>rc(r),[r]),[ce,Ee]=e,we=It(),ye=b.useRef(l);ye.current=l;const[Q,Ne]=b.useState(null),[W,je]=b.useState("loading");b.useEffect(()=>{let E=!1;return Ne(null),je("loading"),ae.getManifest(n).then(G=>{E||(G?(Ne(z?_e.readerVersions(G):G),je("ready")):je("missing"))}).catch(()=>{E||je("missing")}),()=>{E=!0}},[ae,n,z]);const K=o!==void 0,V=a!==void 0,[re,J]=b.useState(null),[I,ue]=b.useState(null);b.useEffect(()=>{J(null),ue(null)},[n]);const fe=_e.pickTextVersion(Q,K?o:re),ze=((Ao=Q==null?void 0:Q.versions.find(E=>E.key==="default"))==null?void 0:Ao.key)??((Lo=Q==null?void 0:Q.versions[0])==null?void 0:Lo.key)??"default",B=(fe==null?void 0:fe.key)??null,pe=V?a:I,Te=b.useCallback((E,G,be,ot)=>{var mt;(mt=ye.current)==null||mt.call(ye,{key:E,chapter:G,isDefault:E===ze,...ot?{anchor:ot}:{}},be)},[ze]);b.useEffect(()=>{!Q||!K||o==null||Q.versions.some(E=>E.key===o)||Te(ze,null,"auto")},[Q,K,o,ze,Te]);const ve=b.useRef(new Map);b.useEffect(()=>{ve.current.clear()},[ae,n]);const Ve=b.useCallback(async E=>{const G=`${n}
|
|
1551
|
+
${E}`;if(ve.current.has(G))return ve.current.get(G)??null;const be=await ae.getIndex(n,E).catch(()=>null);return be&&ve.current.set(G,be),be},[ae,n]),[qe,Xe]=b.useState(null),[X,ie]=b.useState("loading"),me=B?`${n}
|
|
1552
1552
|
${B}`:null,se=qe&&qe.owner===me?qe.idx:null;b.useEffect(()=>{if(!B)return;let E=!1;const G=`${n}
|
|
1553
|
-
${B}`;return Xe(null),ie("loading"),Ve(B).then(be=>{E||(be&&be.chapters.length>0?(Xe({owner:G,idx:be}),ie("ready")):ie("failed"))}),()=>{E=!0}},[n,B,Ve]),b.useEffect(()=>{if(!se||!B||pe!=null&&se.chapters.some(be=>be.file===pe))return;const G=se.chapters[0].file;V||ue(G),Te(B,G,"auto")},[se,B,pe,V,Te]);const de=se?pe!=null&&se.chapters.some(E=>E.file===pe)?pe:se.chapters[0].file:pe,ge=b.useMemo(()=>se&&de?se.chapters.find(E=>E.file===de)??null:null,[se,de]),Oe=b.useRef(0),Je=b.useCallback(async E=>{if(!Q||E===B||!Q.versions.some(_t=>_t.key===E))return;const G=++Oe.current,be=await Ve(E);if(G!==Oe.current)return;const ot=ge??(de?{file:de}:null),mt=_e.matchChapterAcrossVersions(ot,be);K||
|
|
1553
|
+
${B}`;return Xe(null),ie("loading"),Ve(B).then(be=>{E||(be&&be.chapters.length>0?(Xe({owner:G,idx:be}),ie("ready")):ie("failed"))}),()=>{E=!0}},[n,B,Ve]),b.useEffect(()=>{if(!se||!B||pe!=null&&se.chapters.some(be=>be.file===pe))return;const G=se.chapters[0].file;V||ue(G),Te(B,G,"auto")},[se,B,pe,V,Te]);const de=se?pe!=null&&se.chapters.some(E=>E.file===pe)?pe:se.chapters[0].file:pe,ge=b.useMemo(()=>se&&de?se.chapters.find(E=>E.file===de)??null:null,[se,de]),Oe=b.useRef(0),Je=b.useCallback(async E=>{if(!Q||E===B||!Q.versions.some(_t=>_t.key===E))return;const G=++Oe.current,be=await Ve(E);if(G!==Oe.current)return;const ot=ge??(de?{file:de}:null),mt=_e.matchChapterAcrossVersions(ot,be);K||J(E),V||ue(mt),Te(E,mt,"version")},[Q,B,Ve,ge,de,K,V,Te]),[Pe,Ue]=b.useState(null),[nt,Y]=b.useState(null),M=b.useRef(0),k=b.useCallback((E,G)=>{Ue({chapter:E,anchor:G,nonce:++M.current}),Y({chapter:E,anchor:G})},[]),P=b.useCallback(E=>{if(!B)return;const G=bd(E);if(G){k(G.chapter,G.anchor),V||ue(G.chapter),Te(B,G.chapter,"chapter",G.anchor);return}V||ue(E),Te(B,E,"chapter")},[B,V,Te,k]),q=b.useRef(null);b.useEffect(()=>{!c||!de||c===q.current||(q.current=c,k(de,c))},[c,de,k]),b.useEffect(()=>{c||(q.current=null)},[c]);const[_,le]=b.useState(null),H=B&&ge?`${n}
|
|
1554
1554
|
${B}
|
|
1555
1555
|
${ge.file}`:null,[he,xe]=b.useState(null),Re=H!==null&&he!==H,Ze=b.useRef(0);b.useEffect(()=>{if(!B||!ge)return;const E=++Ze.current,G=`${n}
|
|
1556
1556
|
${B}
|
|
1557
|
-
${ge.file}`;if(le(null),Rn(ge)){xe(G);return}ae.getChapter(n,B,ge.file,{json:!!ge.has_json}).then(be=>{E===Ze.current&&le(be)}).catch(()=>{E===Ze.current&&le(null)}).finally(()=>{E===Ze.current&&xe(G)})},[ae,n,B,ge]);const Me=_e.isCollatedKind(fe==null?void 0:fe.kind),[He,ct]=b.useState("");b.useEffect(()=>{ct("")},[n,B]);const Be=b.useMemo(()=>B&&Me?async E=>{const G=await ae.getChapter(n,B,E,{json:!0});return{juan:(G==null?void 0:G.json)??null,rawText:(G==null?void 0:G.md)??null}}:null,[ae,n,B,Me]),ee=(se==null?void 0:se.type)==="kaozhen",Se=b.useMemo(()=>(se==null?void 0:se.chapters.map(E=>E.file))??[],[se]),{matchStates:et}=
|
|
1558
|
-
${B??""}`,load:Be,files:Se,activeFile:de??null,activeJuan:(_==null?void 0:_.json)??null,activeRawText:(_==null?void 0:_.md)??null,query:He,isKaozhen:ee}),tt=b.useRef(new Map);b.useEffect(()=>{tt.current.clear()},[n]);const De=b.useMemo(()=>({versionKey:B,chapter:ge??null}),[B,ge]),Fe=
|
|
1557
|
+
${ge.file}`;if(le(null),Rn(ge)){xe(G);return}ae.getChapter(n,B,ge.file,{json:!!ge.has_json}).then(be=>{E===Ze.current&&le(be)}).catch(()=>{E===Ze.current&&le(null)}).finally(()=>{E===Ze.current&&xe(G)})},[ae,n,B,ge]);const Me=_e.isCollatedKind(fe==null?void 0:fe.kind),[He,ct]=b.useState("");b.useEffect(()=>{ct("")},[n,B]);const Be=b.useMemo(()=>B&&Me?async E=>{const G=await ae.getChapter(n,B,E,{json:!0});return{juan:(G==null?void 0:G.json)??null,rawText:(G==null?void 0:G.md)??null}}:null,[ae,n,B,Me]),ee=(se==null?void 0:se.type)==="kaozhen",Se=b.useMemo(()=>(se==null?void 0:se.chapters.map(E=>E.file))??[],[se]),{matchStates:et}=uf({resetKey:`${n}
|
|
1558
|
+
${B??""}`,load:Be,files:Se,activeFile:de??null,activeJuan:(_==null?void 0:_.json)??null,activeRawText:(_==null?void 0:_.md)??null,query:He,isKaozhen:ee}),tt=b.useRef(new Map);b.useEffect(()=>{tt.current.clear()},[n]);const De=b.useMemo(()=>({versionKey:B,chapter:ge??null}),[B,ge]),Fe=kg(),pt=typeof r.getTextFile=="function"||!!$,bt=b.useRef(N);bt.current=N;const ht=b.useMemo(()=>S||C!==void 0||!pt?void 0:async(E,G)=>{var ot;const be=await _e.loadReaderChapter(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$});return G!=null&&G.chapter&&((ot=bt.current)==null||ot.call(bt,{chapterKey:E,ctx:G,data:be})),(be==null?void 0:be.warpData)??null},[S,C,pt,r,n,Fe,$]),We=b.useMemo(()=>U||!pt?void 0:async(E,G)=>{var be;return((be=await _e.loadReaderFiles(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$}))==null?void 0:be.entity)??null},[U,pt,r,n,Fe,$]),gt=b.useMemo(()=>h||!u||!pt?void 0:async(E,G)=>{const be=await _e.loadReaderFiles(r,{id:n,versionKey:G==null?void 0:G.versionKey,chapter:G==null?void 0:G.chapter},{cord:Fe,textFileBase:$}),ot=be!=null&&be.cord?_e.iiifVolumeOf(be.cord):be!=null&&be.cordSkipped?_e.volumeFromChar(be.char):null;return ot?u(ot.bookId,ot.vol):null},[h,u,pt,r,n,Fe,$]),te=kh(h??gt,de??null,De,n),{warpData:A,loading:ne}=ud(S??ht,C,de??null,De,n),$e=!Re&&H!==null&&(!!A||!!(_!=null&&_.md)||!!(_!=null&&_.json));b.useEffect(()=>{$e&&(i==null||i())},[$e,i]);const Ie=b.useRef(!1);(A||te.images&&te.images.length>0)&&(Ie.current=!0),b.useEffect(()=>{Ie.current=!1},[n]);const Le=te.loading||Rn(ge)&&ne&&!A,at=Ie.current&&Le,lt=at,Ge=bg(U??We,de??null,De,n),Ae=ce.properNameMode??(Ge.length>0?"full":"off"),Ce=b.useMemo(()=>({...ce,properNameMode:Ae}),[ce,Ae]),rt=b.useMemo(()=>jh(Ge,Ae,{showWorks:Ce.showWorks}),[Ge,Ae,Ce.showWorks]),[st,Ke]=b.useState(new Set),[D,ke]=b.useState(null),[Qe]=b.useState(wh),[Ye,wt]=b.useState(!0),it=((Po=fe==null?void 0:fe.facsimile)==null?void 0:Po.trimmed)??!1,Pt=it?!0:ce.preserveMargins;b.useCallback(E=>Ee({preserveMargins:E}),[Ee]);const dt=b.useRef(null),[$t,Ot]=b.useState(1),[zt,cr]=b.useState(null),an=E=>{var be;const G=parseInt(((be=E==null?void 0:E.page_id)==null?void 0:be.split(":")[1])??"",10);return isNaN(G)?null:G},ri=E=>{var be,ot;const G=(E==null?void 0:E.pages)??[];return((be=G.find(mt=>mt.columns.some(_t=>_t.chars.length>0)))==null?void 0:be.page)??an(E)??((ot=G[0])==null?void 0:ot.page)??1},[yt,bi]=b.useState(()=>ri(A)),Ci=`${n}
|
|
1559
1559
|
${B}
|
|
1560
|
-
${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({key:Ci,data:A,started:!1});else if(A!==Ei.data&&(yo({key:Ci,data:A,started:!!A}),A)){const E=A.pages??[];(!Ei.started||!E.some(G=>G.page===yt))&&bi(ri(A))}b.useEffect(()=>{Ke(new Set),Qe.set(null)},[de,B,Qe]);const dr=Ei.key===Ci&&Ei.started,jo=!!ge&&cs(ge.headings).length===0,ko=b.useMemo(()=>jo&&dr&&A?md(A.pages,A.punctuations):[],[jo,dr,A]),mr=b.useCallback(E=>{const G=cs(E.headings);return G.length>0?G:E.file===de?ko:[]},[de,ko]),Tm=b.useCallback(E=>{if(Ke(new Set(E)),E.length>0){const G=E[0],be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be)}},[]),Dt=b.useMemo(()=>{const E=new Map;for(const G of(A==null?void 0:A.pages)??[])E.set(G.page,G);return E},[A]),Ri=an(A),Ti=b.useCallback(E=>{var ot;const G=te.images;if(!G||G.length===0)return;const be=(ot=Dt.get(E))==null?void 0:ot.seq;return(be?G.find(mt=>mt.seq===be):void 0)??G.find(mt=>mt.pageNo===E)??G[E-1]},[te.images,Dt]),wo=$t>1.5,ln=b.useCallback((E,G=!1)=>{const be=Ti(E);return be?E===Ri||G?be.hiresUrl??be.url:be.url:E===Ri?(A==null?void 0:A.imageUrl)??"":""},[Ti,A,Ri]),Im=b.useMemo(()=>ln(yt,wo),[ln,yt,wo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((E,G)=>E-G),[Dt]),si=b.useRef(yt);si.current=yt;const ur=b.useRef(0),pr=b.useRef({page:null,timer:null}),Mm=b.useCallback(E=>{const G=pr.current;E!==G.page&&(G.timer&&(clearTimeout(G.timer),G.timer=null),G.page=null,!(E===si.current||Date.now()<ur.current)&&(G.page=E,G.timer=setTimeout(()=>{G.timer=null,G.page=null,!(Date.now()<ur.current||si.current===E)&&(si.current=E,bi(E))},yg)))},[]);b.useEffect(()=>()=>{pr.current.timer&&clearTimeout(pr.current.timer)},[]);const cn=b.useCallback(E=>{var G;si.current===E||!Dt.has(E)||(ur.current=Date.now()+1e3,si.current=E,bi(E),(G=Dt.get(E))!=null&&G.columns.some(be=>be.chars.length>0)&&cr(be=>({page:E,nonce:((be==null?void 0:be.nonce)??0)+1})))},[Dt]),Ii=b.useCallback(E=>{const G=si.current,be=Wt.indexOf(G),ot=Wt[be<0?0:be+E];ot===void 0||ot===G||cn(ot)},[Wt,cn]),vo=b.useCallback(E=>{if(!E.trim().match(/^\d+$/)||Wt.length===0)return null;const be=parseInt(E.trim(),10),ot=Number.isFinite(be)?be:Number.MAX_SAFE_INTEGER;return Wt.reduce((mt,_t)=>Math.abs(_t-ot)<Math.abs(mt-ot)?_t:mt,Wt[0])},[Wt]),[br,hr]=b.useState(null),dn=b.useRef(null),Am=b.useCallback(E=>{dn.current=E,hr(E)},[]),So=b.useCallback(()=>{const E=dn.current;if(dn.current=null,hr(null),E===null)return;const G=vo(E);G!==null&&cn(G)},[vo,cn]),fr=Wt.indexOf(yt),Lm=b.useCallback(E=>{if(E.altKey||E.ctrlKey||E.metaKey)return;const G=E.target.tagName;G==="INPUT"||G==="TEXTAREA"||G==="SELECT"||(E.key==="ArrowLeft"||E.key==="PageUp"?(E.preventDefault(),Ii(-1)):(E.key==="ArrowRight"||E.key==="PageDown")&&(E.preventDefault(),Ii(1)))},[Ii]),$o=b.useRef(null);b.useEffect(()=>{if(!A)return;const E=$o.current;if(!(!E||E.offsetWidth===0))for(const G of xg){const be=ln(yt+G);be&&ss(be)}},[A,yt,ln]);const _o=b.useMemo(()=>{var Do;if(!A)return null;if(yt===Ri)return A;const E=Dt.get(yt);if(E&&E.width>0&&E.height>0)return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[E.width,E.height],total_warped_w:E.width,columns:[{col:1,warped_w:E.width,warped_h:E.height,offset_x:0,strips:[],chars:E.columns.flatMap(ut=>ut.chars).map(ut=>({id:ut.id,char:ut.char,slot:ut.slot,pos:ut.pos,sub:ut.sub,bbox_col:ut.bbox??[0,0,0,0]}))}],...E.columns.some(ut=>ut.kind==="figure"&&ut.figBox)?{figBlocks:E.columns.filter(ut=>ut.kind==="figure"&&ut.figBox).map(ut=>({id:ut.fig,box:ut.figBox}))}:{}};const G=(Do=A.pages)==null?void 0:Do.find(ut=>ut.page===yt),[be,ot]=A.image_size||[2386,3082];if(!(be>0&&ot>0))return null;const mt=Ti(yt),_t=(mt==null?void 0:mt.width)??be,wr=(mt==null?void 0:mt.height)??ot,Fo=_t/be,Bo=wr/ot,Ho=new Map;for(const ut of A.columns){const At=(ut.strips||[]).flatMap(hn=>hn.srcQuad.map(fn=>fn[0]));if(At.length===0)continue;const Ut=ut.top_y??0,vr=ut.bottom_y??Ut+ut.warped_h;Ho.set(ut.col,{x0:Math.min(...At),x1:Math.max(...At),top:Ut,slotH:(vr-Ut)/21})}return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[_t,wr],total_warped_w:_t,columns:G?G.columns.map(ut=>{const At=Ho.get(ut.col)??{x0:0,x1:0,top:0,slotH:118};return{col:ut.col,warped_w:_t,warped_h:wr,offset_x:0,strips:[],chars:ut.chars.map(Ut=>{const vr=Ut.slot??Ut.pos??0,hn=(At.top+(vr-1)*At.slotH)*Bo,fn=(At.x0+At.x1)/2,[Xm,Jm]=Ut.sub==="a"?[fn,At.x1]:Ut.sub==="b"?[At.x0,fn]:[At.x0,At.x1];return{...Ut,bbox_col:[Xm*Fo,hn,Jm*Fo,hn+At.slotH*Bo]}})}}):[]}},[A,yt,Ri,Dt,Ti]),{entryTitle:mn,authors:No}=Cg(n,r,m===void 0),[zo,gr]=b.useState("text");b.useEffect(()=>{gr("text")},[de,B]);const Pm=b.useMemo(()=>se?Sg(se,et,Xa(fe,se),O,Me,mr):[],[se,et,fe,O,Me,mr]),Co=Ah(),Eo=b.useRef(null),Ro=b.useRef(null),xr=b.useMemo(()=>{const E=[];return A&&E.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ye?"bim-rd-on":""}`,"aria-pressed":Ye,title:"切换外挂现代断句标点",onClick:()=>wt(G=>!G),children:Ye?"标点":"无标点"})}}),E},[A,Ye]),Om=b.useMemo(()=>L&&L.length>0?[...xr,...L]:xr,[xr,L]),Fm=b.useMemo(()=>fe&&ge&&B?{entryId:n,versionKey:B,chapterKey:ge.file,chapter:ge,version:fe,transport:r,viewport:Co}:null,[n,B,ge,fe,r,Co]),Bm=b.useCallback(E=>{de&&k(de,E)},[de,k]),oi=Ph({plugins:Om,ctx:Fm,prefs:Ce,setPrefs:Ee,t:Z,convert:O,pages:A==null?void 0:A.pages,textRootRef:Eo,shellTextRef:Ro,selectedCharIds:st,scrollToAnchor:Bm});if(W==="loading")return t.jsx(Va,{className:F,style:T,title:m??mn,label:Z("reader.loading")});if(W==="missing"||!Q||!fe)return t.jsx("div",{className:F,style:{...T,...Ga},children:Z("reader.noText")});if(J==="failed")return t.jsx("div",{className:F,style:{...T,...Ga},children:Z("reader.tocFailed")});if(!se)return t.jsx(Va,{className:F,style:T,title:m??mn,label:Z("reader.tocLoading")});const hi=Xa(fe,se),Hm=Pm,To=nt&&de&&nt.chapter===de?no(de,nt.anchor):null,Dm=To&&ge&&mr(ge).some(E=>E.anchor===nt.anchor)?To:de??null,yr=Q.versions.map(E=>({key:E.key,label:_e.textVersionLabel(E),optionLabel:O(_e.textVersionLabel(E)),sourceName:Ja(E)?Z("reader.originalSource"):E.source_name?O(E.source_name):void 0,license:E.license??void 0,sourceUrl:E.source_url??void 0,primary:E.key===ze})),Mt=wg((Oo=se.source)==null?void 0:Oo.upstream),un=(typeof m=="string"?O(m):m)??(se.title?O(se.title):mn?O(mn):void 0),Io=fe.edition_label?O(fe.edition_label):void 0,jr=un?t.jsx("a",{href:we(n),title:Z("reader.viewEntry"),onClick:d?E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),d(n))}:void 0,children:un}):void 0,Wm=jr&&Io?t.jsxs(t.Fragment,{children:[jr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Io]})]}):jr,Um=No.length>0?O(No.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${` ${E.role||Z("reader.defaultRole")}`}`).join("、")):void 0,kr=ge?bd(ge,hi,O,Me):void 0,ai=Me&&!!(_!=null&&_.json),li=(_==null?void 0:_.json)??null,fi=(_==null?void 0:_.md)??null,Mo=ai&&!ee&&Qc(li.sections),Km=Mo&&!(fi&&Ce.readingMode==="paragraph"&&Ln(fi)),Ym=ai&&Mo?t.jsx(mf,{juan:li,view:zo,onView:gr,textHasEntries:Km}):void 0,Gm=!0,pn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,bn=Ja(fe),Xt=bn?Z("reader.originalSource"):fe.source_name?O(fe.source_name):void 0,Vm=(typeof p=="string"?O(p):p)??(bn?void 0:Xt??O(_e.textVersionLabel(fe))),qm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(uc,{className:F,style:T,title:Wm,subtitle:Vm,byline:Um,current:kr,pagerUnit:hi,rail:Ym,revisedAt:w,backHref:x,backLabel:j,onReportError:v?E=>v({...E,bookTitle:typeof un=="string"?un:void 0,entryId:n}):void 0,workLinkToggle:ai&&!ee&&!!d&&!!(li!=null&&li.sections.some(E=>E.work_id)),toc:Hm,tocCaption:Z("reader.tocCaption",{n:se.chapters.length,unit:O(hi)}),tocHeader:Me&&se.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:ee?Z("reader.searchChaptersPlaceholder"):Z("reader.searchUnitPlaceholder",{unit:O(hi)}),"aria-label":ee?Z("reader.searchChapters"):Z("reader.searchUnit",{unit:O(hi)}),value:He,onChange:E=>ct(E.target.value)}):void 0,activeKey:de??null,tocActiveKey:Dm,onSelect:P,images:Rn(ge)&&ne&&!A?null:te.images,renderImageOverlay:f,imagePanel:A||at?"open":g,imagesLoading:lt,isWarpMode:!!A,showPreserveMargins:!it,customImagePanel:A&&_o?t.jsxs("div",{ref:$o,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Lm,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",outline:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 4px 6px",fontSize:12,color:s.bim("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:4},children:t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[st.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ke(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${s.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",st.size,")"]}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:2},"data-testid":"facsimile-zoom-tools",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小",title:"缩小",disabled:$t<=1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round($t*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:$t>=6,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:$t===1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(ug,{ref:dt,resetKey:yt,onScaleChange:Ot,style:{flex:1,minHeight:0},children:t.jsx(Ca,{store:Qe,children:E=>{var G;return t.jsx(qs,{imageUrl:Im,pageData:_o,selectedCharIds:st,hoveredCharId:E,decorations:oi.decorations,preserveMargins:Pt,banxinMode:ce.banxinMode,extent:(G=Ti(yt))==null?void 0:G.extent,renderScale:$t,selectedFigBlock:D,onFigBlockClick:be=>ke(be),onCharClick:be=>{ke(null),Ke(mt=>{const _t=new Set(mt);return _t.has(be)?_t.delete(be):(_t.clear(),_t.add(be)),_t});const ot=document.querySelector(`[data-char-id="${be}"]`);ot&&ot.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Qe.set})}})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":Z("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:s.bim("meta-fg")},children:[t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:fr<=0,onClick:()=>Ii(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":yt,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:s.bim("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":Z("reader.facsimilePageInput"),size:Math.max(2,String(br??yt).length),value:br??String(yt),onFocus:E=>E.currentTarget.select(),onChange:E=>Am(E.target.value),onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),So()):E.key==="Escape"&&(dn.current=null,hr(null)),E.stopPropagation()},onBlur:So,style:{width:`${Math.max(2,String(br??yt).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${s.bim("rule")}`,borderRadius:4,background:"transparent",color:"inherit"}}),"葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:fr<0||fr>=Wt.length-1,onClick:()=>Ii(1),children:"›"})]})]}):void 0,pluginSettings:oi.settings,pluginToolbar:oi.toolbar,pluginOverlay:oi.overlay,textRootRef:Ro,prefs:Ce,onPrefsChange:Ee,versions:yr.length>1?yr:void 0,currentVersionKey:yr.length>1?fe.key:void 0,onVersionChange:Je,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Ln(fi),allowVertical:y,origScriptAvailable:qm,contentLoading:Re,children:[(Re||ne&&!A&&!ai&&pn==null)&&t.jsx(nc,{}),!Re&&A&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:Eo,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:ge!=null&&ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,fe.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]})]})]}),t.jsx(Ca,{store:Qe,children:E=>t.jsx(to,{pageData:A,pages:A.pages,punctuations:A.punctuations||kg,selectedCharIds:st,hoveredCharId:E,onSelectionChange:Tm,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:G,fig:be})=>{Ke(new Set),ke(be),bi(G)},onCharClick:G=>{ke(null),Ke(ot=>{const mt=new Set(ot);return mt.has(G)?mt.delete(G):(mt.clear(),mt.add(G)),mt});const be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be),oi.onCellClick(G)},onCharHover:G=>{Qe.set(G),oi.onCellHover(G)},decorations:oi.decorations,mode:"horizontal",showPunctuation:Ye,entities:rt,entityTransport:r,onEntityNavigate:R,onVisiblePageChange:Mm,convert:O,scrollToPage:zt,scrollToAnchor:Pe&&Pe.chapter===de&&dr?Pe:null,onVisibleHeadingChange:G=>Y(G&&de?{chapter:de,anchor:G}:null),pageBreaks:Ce.pageBreaks,pageIndicatorY:Ce.pageIndicatorY,onPageIndicatorYChange:G=>Ee({pageIndicatorY:G}),quoteStyle:Ce.quoteStyle,bookTitleStyle:Ce.bookTitleStyle,showWorks:Ce.showWorks})})]}),!Re&&!A&&ai&&li&&t.jsx(cf,{juan:li,rawText:fi,positionLabel:Ng(ge,se,hi,O),groupLabel:zg(se,de??null),index:vg(n,se),searchQuery:He,onNavigate:d,transport:r,workLabelCache:tt,prefs:Ce,view:zo,onViewChange:gr},`${B}/${de}`),!Re&&!A&&!ai&&pn!=null&&ge&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[bn&&Xt&&t.jsx(t.Fragment,{children:Xt}),!bn&&fe.source_name&&t.jsxs(t.Fragment,{children:[Z("reader.textSource")," ",fe.source_url?t.jsx("a",{className:"bim-rd-link",href:fe.source_url,target:"_blank",rel:"noreferrer",children:O(fe.source_name)}):O(fe.source_name)]}),Xt&&fe.license&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]}),Mt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[Z("reader.upstream")," ",Mt.url?t.jsx("a",{className:"bim-rd-link",href:Mt.url,target:"_blank",rel:"noreferrer",children:O(Mt.name??Mt.url)}):O(Mt.name??""),Mt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),Mt.license_url?t.jsx("a",{className:"bim-rd-link",href:Mt.license_url,target:"_blank",rel:"noreferrer",children:Mt.license}):Mt.license]}),Mt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(rc,{text:Mt.note,convert:O})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Hs,{text:pn,mode:Ce.readingMode,tables:Gm,gujiMarkdown:!0,bookMarking:Bs(Ce),quoteStyle:Ce.quoteStyle})})]}),!Re&&!ne&&!A&&!ai&&pn==null&&ge&&t.jsx("div",{className:"bim-rd-state",children:Z("reader.chapterFailed")}),!Re&&se.references&&se.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:Z("reader.references")}),t.jsx("ol",{children:se.references.map((E,G)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:O(E.title)}):t.jsx("span",{children:O(E.title)}),E.author&&t.jsxs("span",{children:[",",O(E.author)]}),E.note&&t.jsxs("span",{children:["。",O(E.note)]})]},G))})]})]})};function Ja(e){return e.is_original===!0||e.source==="original"}function Ng(e,i,n,r){var a,l;if(!e)return;const o=(l=(a=i.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(o?`${o}冊`:`${n}${e.n}`)}function zg(e,i){if(!i)return;const n=r=>{var o;for(const a of r??[]){const l=n(a.children);if(l)return l;if((o=a.files)!=null&&o.includes(i))return a.label}};return n(e.juan_groups)}function Cg(e,i,n){const[r,o]=b.useState({entryTitle:void 0,authors:[]});return b.useEffect(()=>{if(o({entryTitle:void 0,authors:[]}),typeof i.getItem!="function")return;let a=!1;return Promise.resolve(i.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);o({entryTitle:n&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,i,n]),r}const Eg=({pageData:e,rawImageUrl:i="",punctuations:n=[],title:r,subtitle:o,onBack:a,className:l="",style:d={}})=>{const[c,m]=b.useState(new Set),[p,h]=b.useState(null),[u,f]=b.useState("horizontal"),[g,y]=b.useState(!0),v=b.useRef(null),w=b.useCallback($=>{m(new Set($))},[]),x=b.useCallback($=>{if(m(N=>{const z=new Set(N);return z.has($)?z.delete($):(z.clear(),z.add($)),z}),v.current){const N=v.current.querySelector(`[data-char-id="${$}"]`);N&&N.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var $;m(new Set),window.getSelection&&(($=window.getSelection())==null||$.removeAllRanges())},S=n.length>0?n:e.punctuations||[];return t.jsxs("div",{className:`guji-reader-container ${l}`,style:d,children:[t.jsxs("header",{className:"guji-reader-header",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&t.jsx("button",{type:"button",onClick:a,className:"guji-reader-btn",style:{marginRight:6},children:"‹ 返回"}),t.jsx("span",{className:"guji-reader-title",children:r||e.title}),o&&t.jsx("span",{style:{fontSize:"0.85rem",color:s.bim("meta-fg")},children:o}),t.jsx("span",{className:"guji-reader-tag",children:"WebGL 客户端透视矫正对读"})]}),t.jsxs("div",{className:"guji-reader-actions",children:[t.jsxs("span",{style:{fontSize:"0.85rem",color:s.bim("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:s.bim("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>y($=>!$),className:`guji-reader-btn ${g?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:g?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f($=>$==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:u==="horizontal"?"切换竖排":"切换横排"})]})]}),t.jsxs("div",{className:"guji-reader-body",children:[t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%",position:"sticky",top:0},children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:"底本书影 (WebGL 分带透视矫正 + 完整版心)"}),t.jsx("span",{className:"guji-pane-hint",children:"点击字框可联动文本定位"})]}),t.jsx("div",{className:"guji-pane-content",children:t.jsx(qs,{imageUrl:i,pageData:e,selectedCharIds:c,hoveredCharId:p,onCharClick:x,onCharHover:h})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:v,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:u==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(to,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:p,onSelectionChange:w,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},Rg=({data:e,onNavigate:i,className:n,style:r})=>{var p;const{t:o,convert:a}=oe(),[l,d]=b.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[c,m]=b.useState(null);return t.jsxs("div",{className:n,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:s.bim("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[o("catalog.totalVolumes")," ",t.jsx("strong",{children:e.total_volumes})," ",o("unit.juan")]}),e.stats.zhulu!=null&&t.jsxs("span",{children:[o("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",o("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[o("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",o("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:o("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(h=>t.jsx(Tg,{division:h,expanded:l===h.name,onToggle:()=>d(l===h.name?null:h.name),expandedCat:c,onCatToggle:u=>m(c===u?null:u),onNavigate:i},h.name))})]})},Tg=({division:e,expanded:i,onToggle:n,expandedCat:r,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=oe(),c=e.categories.reduce((m,p)=>{const h=p.stats||{zhulu:0,cunmu:0};return m+(h.zhulu||0)+(h.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:i?`color-mix(in srgb, ${s.bim("primary")} 6%, transparent)`:s.bim("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:s.bim("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:i?"▲":"▼"})]})]}),i&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(m=>{const p=`${e.name}/${m.name}`;return t.jsx(Ig,{category:m,expanded:r===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},Ig=({category:e,expanded:i,onToggle:n,onNavigate:r})=>{var m,p,h,u;const{t:o,convert:a}=oe(),l=((m=e.books)==null?void 0:m.zhulu)||[],d=((p=e.books)==null?void 0:p.cunmu)||[],c=(((h=e.stats)==null?void 0:h.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:i?s.bim("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:s.bim("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginLeft:"8px",fontWeight:400},children:o("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[o("catalogPage.booksN",{n:c})," ",i?"▲":"▼"]})]}),i&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(Za,{label:o("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(Za,{label:o("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},Za=({label:e,books:i,onNavigate:n})=>{const{t:r,convert:o}=oe(),a=It(),[l,d]=b.useState(i.length<=20),c=l?i:i.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",i.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((m,p)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:s.bim("fg")},children:m.work_id&&n?t.jsx("a",{href:a(m.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(m.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${s.bim("link-fg")}`},children:o(m.title)}):o(m.title)}),m.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.volumes)}),m.author&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.author).slice(0,20)})]},p))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:s.bim("primary"),background:"transparent",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:i.length})})]})};function ro(e="/api/feedback",i){const n=()=>typeof e=="function"?e():e,r=(...o)=>((i==null?void 0:i.fetch)??fetch)(...o);return{async listFeedback(o){try{const l=await(await r(`${n()}?resourceId=${encodeURIComponent(o)}`)).json();return l!=null&&l.success&&Array.isArray(l.items)?l.items:[]}catch{return[]}},async submitFeedback(o){const a=await r(n(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error((l==null?void 0:l.error)||(i==null?void 0:i.defaultError)||"submit failed")}}}}function gd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const Mg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],xd=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:r})=>{const{t:o}=oe(),[a,l]=b.useState(null),[d,c]=b.useState(""),[m,p]=b.useState(""),[h,u]=b.useState("idle"),[f,g]=b.useState(""),y=b.useRef(null);b.useEffect(()=>{e&&(l(null),c(""),p(""),u("idle"),g(""))},[e]),b.useEffect(()=>{a&&setTimeout(()=>{var x;return(x=y.current)==null?void 0:x.focus()},100)},[a]),b.useEffect(()=>{if(h==="success"){const x=setTimeout(i,2e3);return()=>clearTimeout(x)}},[h,i]),b.useEffect(()=>{if(!e)return;const x=j=>{j.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const v=async()=>{if(!(!a||!d.trim())){u("submitting"),g("");try{await n({type:a,content:d.trim(),...m.trim()?{contact:m.trim()}:{}}),u("success")}catch(x){u("error"),g(x instanceof Error?x.message:o("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&h!=="submitting";return t.jsx("div",{style:Ag,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:Lg,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Pg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:Og,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Wg,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:o("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:s.bim("primary"),marginTop:"8px"},children:o("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Mg.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...Fg,...a===x.value?Bg:{}},children:[t.jsx("span",{children:x.icon})," ",o(`feedback.submitType.${x.value}`)]},x.value))}),t.jsx("textarea",{ref:y,value:d,onChange:x=>c(x.target.value),placeholder:o(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||h==="submitting",style:{...Hg,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:m,onChange:x=>p(x.target.value),placeholder:o("feedback.contactPlaceholder"),maxLength:200,disabled:!a||h==="submitting","aria-label":o("feedback.contactLabel"),style:Kg}),t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),h==="error"&&t.jsx("div",{style:Ug,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!w,style:{...Dg,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Ag={position:"fixed",top:0,left:0,right:0,bottom:0,background:s.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Lg={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:s.bim("shadow-dialog")},Pg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Og={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:s.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Fg={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Bg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Hg={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Dg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},Wg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:s.bim("success")},Ug={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Kg={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},ds="--bim-feedback-fab-offset",ms=48,Yg=16,Gg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:r=!1,zIndex:o})=>{const{t:a}=oe(),[l,d]=b.useState(!1),c=i.bottom??24;return b.useEffect(()=>{if(r||typeof document>"u")return;const m=document.documentElement;return m.style.setProperty(ds,`calc(${c+ms+Yg}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(ds)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Vg,zIndex:o??s.bim("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:i.right},"aria-label":a("feedback.title"),title:a("feedback.title"),children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(xd,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},Vg={position:"fixed",width:`${ms}px`,height:`${ms}px`,borderRadius:"50%",border:"none",background:s.bim("primary"),color:s.bim("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:s.bim("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},qg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],yd=({onSubmit:e})=>{const{t:i}=oe(),[n,r]=b.useState("bug"),[o,a]=b.useState(""),[l,d]=b.useState(""),[c,m]=b.useState("idle"),[p,h]=b.useState(""),u=b.useRef(null);b.useEffect(()=>{n&&setTimeout(()=>{var y;return(y=u.current)==null?void 0:y.focus()},100)},[n]);const f=async()=>{if(!(!n||!o.trim())){m("submitting"),h("");try{await e({type:n,content:o.trim(),...l.trim()?{contact:l.trim()}:{}}),m("success"),a(""),d(""),r("bug")}catch(y){m("error"),h(y instanceof Error?y.message:i("feedback.submitFailedRetry"))}}},g=n&&o.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:Qa,children:t.jsxs("div",{style:ex,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:tx,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Qa,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:qg.map(y=>t.jsxs("button",{onClick:()=>r(y.value),style:{...Xg,...n===y.value?Jg:{}},children:[t.jsx("span",{children:y.icon})," ",i(`feedback.submitType.${y.value}`)]},y.value))}),t.jsx("textarea",{ref:u,value:o,onChange:y=>a(y.target.value),placeholder:i(n?`feedback.placeholder.${n}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...Zg}}),t.jsx("input",{type:"text",value:l,onChange:y=>d(y.target.value),placeholder:i("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":i("feedback.contactLabel"),style:nx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[o.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!g,style:{...Qg,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:ix,children:p})]})},Qa={padding:"16px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",background:s.bim("input-bg")},Xg={padding:"8px 16px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:"transparent",color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Jg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Zg={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Qg={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},ex={display:"flex",alignItems:"center",gap:"12px",color:s.bim("success"),fontSize:"14px"},tx={background:"none",border:"none",color:s.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ix={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},nx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},jd={bug:{key:"bug",color:s.bim("danger")},resource:{key:"resource",color:s.bim("primary")},suggestion:{key:"suggestion",color:s.bim("primary")},other:{key:"other",color:s.bim("desc-fg")}},rx=jd.other,kd={pending:{key:"pending",color:s.bim("warning")},in_progress:{key:"in_progress",color:s.bim("primary")},resolved:{key:"resolved",color:s.bim("success")},wontfix:{key:"wontfix",color:s.bim("desc-fg")},duplicate:{key:"duplicate",color:s.bim("desc-fg")}},sx=kd.pending;function ox(e){try{const i=new Date(e),n=r=>String(r).padStart(2,"0");return`${i.getFullYear()}-${n(i.getMonth()+1)}-${n(i.getDate())} ${n(i.getHours())}:${n(i.getMinutes())}`}catch{return e}}function ax(e,i){if(!e)return!1;try{const n=new URL(e,i);if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=new URL(i);return n.hostname===r.hostname}catch{return!1}}const wd=({items:e,loading:i})=>{const n=It(),{t:r,convert:o}=oe();return i?t.jsx(nc,{}):e.length===0?t.jsx("div",{style:lx,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=jd[a.type]||rx,d=kd[a.status]||sx,c=typeof window<"u"&&ax(a.pageUrl,window.location.href);return t.jsxs("div",{style:cx,children:[t.jsxs("div",{style:dx,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...el,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...el,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:mx,children:ox(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:ux,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Fr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Fr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Fr,children:a.pageUrl}))]}),t.jsx("div",{style:px,children:o(a.content)}),a.reply&&t.jsxs("div",{style:bx,children:[t.jsx("div",{style:hx,children:r("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},lx={textAlign:"center",padding:"40px 0",color:s.bim("desc-fg"),fontSize:"14px"},cx={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},dx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},el={fontSize:"12px",color:s.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},mx={fontSize:"12px",color:s.bim("desc-fg")},ux={fontSize:"12px",marginBottom:"6px"},Fr={color:s.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${s.bim("primary")}`},px={fontSize:"14px",lineHeight:"1.6",color:s.bim("fg"),whiteSpace:"pre-wrap"},bx={marginTop:"12px",padding:"10px 12px",background:s.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:s.bim("fg")},hx={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:s.bim("primary")},vd=({resourceId:e,transport:i,apiUrl:n})=>{const{t:r}=oe(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(r);c.current=r;const m=b.useMemo(()=>i??ro(n,{defaultError:c.current("feedback.submitFailed")}),[i,n]),p=b.useCallback(async()=>{d(!0);try{a(await m.listFeedback(e))}catch{}finally{d(!1)}},[e,m]);b.useEffect(()=>{p()},[p]);const h=async u=>{await m.submitFeedback({...u,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e}),setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(wd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(yd,{onSubmit:h})})]})},er=8;async function tr(e,i,n,r){const o=Number.isFinite(i)?Math.max(1,Math.floor(i)):1,a=new Array(e.length);let l=0;const d=Array.from({length:Math.min(o,Math.max(1,e.length))},async()=>{for(;l<e.length&&!(r!=null&&r());){const c=l++;a[c]=await n(e[c],c)}});return await Promise.all(d),a}const fx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function gx(e){const i=e.search(fx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const Sd={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:i})=>{let n=e,r="",o=i;if(e&&typeof i=="string"&&(i===e||i===xx(e))){const[a,l]=gx(i);l&&(n=encodeURI(a),o=a,r=l)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:n,target:n!=null&&n.startsWith("http")?"_blank":void 0,rel:n!=null&&n.startsWith("http")?"noopener noreferrer":void 0,style:{color:s.bim("link")},children:o}),r]})},code:({children:e})=>t.jsx("code",{style:{background:s.bim("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function xx(e){try{return decodeURI(e)}catch{return e}}const yx={...Sd,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:r})=>{const{convert:o}=xt(),a=i?yx:Sd;return t.jsx("div",{className:r,style:n,children:t.jsx(su,{remarkPlugins:[ou],components:a,children:o(e)})})},jx=s.detail["zh-Hant"].relation,kx=s.detail["zh-Hant"].lossStatus,wx=s.detail["zh-Hant"].resourceKind,ir=s.getT("zh-Hant"),so=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function tl(e,i=ir){return e?so(jx,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function vx(e,i=ir){return so(kx,e)?i(`detail.lossStatus.${e}`):e}function Sx(e,i=ir){return so(wx,e)?i(`detail.resourceKind.${e}`):""}function oo({authors:e,onNavigate:i,renderLink:n}){const{convert:r}=oe(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=vs(a.role);return t.jsxs(b.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(jt,{id:a.entity_id,label:r(a.name),onNavigate:i,renderLink:n,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function $d(e,i,n=ir){var c,m;const r=js(e,i),o=r.mirrors.map(p=>({key:p.key,label:p.label,description:p.description,rows:p.items.filter(h=>h.group_role!=="mirror"),mirrors:p.items.filter(h=>h.group_role==="mirror")})),a=r.buckets.filter(p=>p.key==="image"||p.key==="textImage").flatMap(p=>p.items);a.length&&o.push({key:"_images",label:o.length?n("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(p=>p.key==="physical"))==null?void 0:c.items)??[];return l.length&&o.push({key:"_physical",label:n("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((m=r.buckets.find(p=>p.key==="text"))==null?void 0:m.items)??[],groups:o}}function _d(e,i){const n=(e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name,r=Al(e,i);return r?`${n}(${r})`:n}function ao({item:e,siblings:i,listedVolumeCounts:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(!1),d=s.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(_d(e,i)),p=s.resourceHref(e),h=Kn(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,g;const u=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=e.metadata)==null?void 0:g.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?r("colorMode.color"):r("colorMode.bw")})]}):null;return p?t.jsxs("a",{href:p,target:"_blank",rel:"noopener noreferrer",children:[m," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),u]}):t.jsxs("span",{className:"bim-d-zt-name",children:[m,u]})})(),h&&t.jsx("span",{className:"bim-d-meta",children:o(h)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(As,{item:e})})]}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":a,onClick:()=>l(u=>!u),children:a?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Nd({groups:e,listedVolumeCounts:i}){const{t:n,convert:r}=oe();return t.jsx(t.Fragment,{children:e.map(o=>t.jsxs("div",{className:"bim-d-rg",children:[o.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(o.label)}),o.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(o.description)}),o.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:o.rows.map((a,l)=>t.jsx(ao,{item:a,siblings:o.rows,listedVolumeCounts:i},`${a.id||a.url||a.name}-${l}`))})}),o.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[o.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:n("detail.mirror")}),o.mirrors.map((a,l)=>{const d=s.resourceHref(a),c=r(_d(a,o.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?r(a.details):void 0,children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:c},l)})]})]},o.key))})}const Yi=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function us(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Yi.find(r=>i.startsWith(r.key[0])))==null?void 0:n.key}const il=12,Br=50,$x=60,zd=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,railTop:a,back:l,railLinks:d})=>{var Je,Pe,Ue,nt,Y;const{t:c,convert:m,messages:p}=oe(),h=b.useMemo(()=>Ss({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[v,w]=b.useState(""),[x,j]=b.useState(!1),S=Math.max(h.length,e._edition_count??0),$=S>Zo&&(h.length>Zo||!!((Je=e._book_groups)!=null&&Je.length)),[N,z]=b.useState({}),C=e._book_groups,[U,R]=b.useState({}),L=b.useRef(new Set),F=b.useMemo(()=>{if(!$)return[];const M={};for(const q of C??[])q.id&&q.title&&(M[q.id]=q.title);const k=Wu(e._books??[],e.version_graph,{titles:M,noHolderFallback:!!C});if(!C)return k;const P=new Map(k.map(q=>[q.key,q]));return C.map(q=>{const _=P.get(q.g);if(_&&_.rows.length>=q.n)return{..._,title:_.title||q.title||""};const le=U[q.g],H=(le==null?void 0:le.rows)??(_==null?void 0:_.rows)??[];return{key:q.g,title:q.g!=="_none"&&(q.title||(_==null?void 0:_.title))||"",rows:H,total:q.n,imageCount:H.filter(he=>he.hasImage).length,pagesLeft:Math.max(0,q.pages-((le==null?void 0:le.loaded)??0))}})},[$,e._books,e.version_graph,C,U]),T=b.useMemo(()=>x?F.map(M=>({...M,rows:M.rows.filter(k=>k.hasImage)})).filter(M=>M.rows.length):F,[F,x]);b.useEffect(()=>{var M;if(!(!$||!(i!=null&&i.getBookGroupPage)))for(const k of F){const P=N[k.key]??0;if(!P||!k.pagesLeft||k.rows.length>=P||L.current.has(k.key))continue;const q=(((M=U[k.key])==null?void 0:M.loaded)??0)+1;L.current.add(k.key),i.getBookGroupPage(e.id,k.key,q).then(_=>{const le=(_??[]).map(H=>Pl(H,e.version_graph));R(H=>{const he=H[k.key];return{...H,[k.key]:{rows:[...(he==null?void 0:he.rows)??[],...le],loaded:q}}})}).catch(()=>R(_=>{var le;return{..._,[k.key]:{rows:((le=_[k.key])==null?void 0:le.rows)??[],loaded:q}}})).finally(()=>L.current.delete(k.key))}},[$,F,N,i,e.id,e.version_graph,U]);const Z=h.length<=$x,O=!$&&(Z||g||!!v||x),ae=b.useMemo(()=>$?T.flatMap(M=>N[M.key]?M.rows.slice(0,N[M.key]).map(k=>k.id):[]):O?h:h.slice(0,il),[$,T,N,h,O]);b.useEffect(()=>{if(!i||ae.length===0)return;const M=ae.filter(P=>!u.has(P));if(M.length===0)return;let k=!1;return tr(M,er,P=>i.getItem(P).then(q=>{var le;const _=q??{};return[P,{id:P,title:_.title,edition:_.edition,resources:_.resources,publication_info:_.publication_info,current_location:_.current_location,provenance:_.provenance,lineage:_.lineage,related_books:_.related_books,dating:_.dating,measure_info:_.measure_info,summary:Nx((le=q==null?void 0:q.description)==null?void 0:le.text)}]}).catch(()=>[P,{id:P}]),()=>k).then(P=>{k||f(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,ae,u]);const ce=b.useMemo(()=>$?[]:h.map(M=>u.get(M)??{id:M}),[$,h,u]),Ee=h.length>0&&h.every(M=>u.has(M)),we=!!i&&ae.some(M=>!u.has(M)),ye=Z||O,Q=b.useMemo(()=>Ol(ce,e.version_graph,{era:v,scanOnly:x,sort:ye?"year":"default"}),[ce,e.version_graph,v,x,ye]),Ne=g?Q.rows:Q.rows.slice(0,il),W=$?F.reduce((M,k)=>M+k.imageCount,0):Q.allRows.filter(M=>M.hasImage).length,je=Q.allRows.reduce((M,k)=>{var P;return M+(((P=k.copies)==null?void 0:P.length)??0)},0),K=b.useMemo(()=>(e._related||[]).map(M=>({...M,title:M.title??""})),[e._related]),V=K.filter(M=>M.relation==="collected_in"),re=b.useMemo(()=>{const M=new Map;for(const k of e.related_works||[]){if(k.relation!=="collected_in"||M.has(k.id))continue;const P=qu(k.volume_index,k.order,e.subtype,p.workPage.pos);P&&M.set(k.id,P)}return M},[e.related_works,e.subtype,p.workPage.pos]),X=((Pe=e._contents)==null?void 0:Pe.total)??0,I=b.useMemo(()=>{const M=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],k=P=>{const q=M.indexOf(P??"");return q<0?M.length:q};return K.filter(P=>P.relation!=="collected_in").map((P,q)=>({r:P,i:q})).sort((P,q)=>k(P.r.relation)-k(q.r.relation)||P.i-q.i).map(P=>P.r)},[K]),ue=b.useMemo(()=>{const M=js(e.resources,e.resource_groups);return[...M.mirrors.flatMap(k=>k.items.map(P=>({r:P,kind:m(k.label)}))),...M.buckets.flatMap(k=>k.items.map(P=>({r:P,kind:m(Sx(k.key,c))})))]},[e.resources,e.resource_groups,m,c]),fe=e.indexed_by||[],ze=e.emendated_by||[],B=b.useMemo(()=>{var he,xe,Re,Ze,Me;const M=[],k=(xe=(he=e.authors)==null?void 0:he[0])==null?void 0:xe.dynasty;k&&M.push({label:c("workPage.fact.written"),value:m(k)});const P=qt(e,p.unit.juan);if(P){const He=((Re=e.juan_count)==null?void 0:Re.description)??((Me=(Ze=e.measures)==null?void 0:Ze.find(ct=>(ct==null?void 0:ct.unit)==="卷"&&ct.note))==null?void 0:Me.note);M.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(P),He&&He!==P?t.jsxs("span",{className:"bim-d-meta",children:["(",m(He),")"]}):null]})})}e.loss_status&&M.push({label:c("workPage.fact.loss"),value:m(vx(e.loss_status,c))}),e.authenticity==="forged"&&M.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const q=Q.allRows.filter(He=>He.sortYear!=null),_=q.length>0?q.reduce((He,ct)=>He.sortYear<=ct.sortYear?He:ct):null;_!=null&&_.era.era?M.push({label:c("workPage.fact.earliest"),value:m([_.era.era,_.era.reign].filter(Boolean).join(" ")),title:_.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):we&&M.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),ze.length&&M.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:ze.length})});const le=_x(e.additional_titles);le.length&&M.push({label:c("workPage.fact.alias"),value:le.map(m).join("、")});const H=(e.additional_works||[]).map(He=>m(He.book_title)+(He.n_juan!=null?` ${He.n_juan}${p.unit.juan}`:""));return H.length&&M.push({label:c("workPage.fact.appendix"),value:H.join("、")}),M},[e,m,c,p,we,Q.allRows,ze.length]),Te=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:Ee?W:0,label:c("workPage.stat.hasImage")},{value:fe.length,label:c("workPage.stat.catalogs")}],ve=$s(e),Ve=ve?[ve.l1,ve.l2,ve.l3,ve.l4].filter(Boolean).map(M=>m(M)):[],qe=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",Xe=t.jsx(tn,{title:m(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:n,renderLink:r}),meta:t.jsx(vt,{items:[...Ve,ve!=null&&ve.source?c("workPage.classifiedBy",{source:m(ve.source.split("/")[0])}):"",qe]}),description:(Ue=e.description)!=null&&Ue.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(nt=e.description.sources)!=null&&nt.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(M=>({text:m(Ju(M)),href:Zu(M)})).filter(M=>M.text).map((M,k)=>t.jsxs(b.Fragment,{children:[k>0?" · ":null,M.href?t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",children:M.text}):M.text]},k))}):null]}):void 0,stats:Te,facts:B,readAction:o,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Y=e.appendix)==null?void 0:Y.map((M,k)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(M.title)}),t.jsx(zi,{text:M.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},k))}),J=Q.eras.length>=2?[{key:"",label:c("catalog.all")},...Q.eras.map(M=>({key:M,label:`${M} ${Q.allRows.filter(k=>k.era.era===M).length}`}))]:[],ie=[];S&&ie.push({id:"versions",label:c("workPage.sec.versions"),count:S}),fe.length&&ie.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:fe.length}),X&&ie.push({id:"contents",label:c("workPage.sec.contents"),count:X}),V.length&&ie.push({id:"collected",label:c("workPage.sec.collected"),count:V.length}),I.length&&ie.push({id:"related",label:c("workPage.sec.related"),count:I.length}),ue.length&&ie.push({id:"resources",label:c("workPage.sec.resources"),count:ue.length});const me=S===0&&fe.length===0&&!X,se=t.jsxs(t.Fragment,{children:[S>0&&t.jsxs(St,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(vt,{items:[c("workPage.versionsTotal",{n:S-je}),Ee&&W?c("workPage.versionsWithImage",{n:W}):"",Q.rows.length!==Q.allRows.length?c("workPage.versionsCurrent",{n:Q.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":we&&J.length===0&&h.length>1?"":void 0,children:[!$&&J.length>0&&t.jsx(Qi,{items:J,value:v,onChange:M=>{w(M),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(kc,{label:c("workPage.scanOnly"),checked:x,onChange:M=>{j(M),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(ye?"workPage.sortByYear":"workPage.sortByCatalog")})]}),$?t.jsxs("div",{className:"bim-d-groups",children:[t.jsx("div",{className:"bim-d-ui",style:{display:"flex",justifyContent:"flex-end",margin:"4px 0"},children:t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(Object.keys(N).length?{}:Object.fromEntries(T.slice(0,20).map(M=>[M.key,Br]))),children:Object.keys(N).length?c("workPage.groupCollapseAll"):c("workPage.groupExpandAll")})}),T.map(M=>{const k=N[M.key]??0,P=M.rows.slice(0,k);return t.jsxs("details",{open:k>0,onToggle:q=>{const _=q.currentTarget.open;z(le=>{if(_===le[M.key]>0)return le;const H={...le};return _?H[M.key]=Br:delete H[M.key],H})},style:{borderTop:`1px solid ${s.bim("border")}`},children:[t.jsxs("summary",{className:"bim-d-ui",style:{cursor:"pointer",minHeight:40,display:"flex",alignItems:"center",gap:12,padding:"6px 4px"},children:[t.jsx("span",{style:{flex:1},children:m(M.title||c("workPage.groupUngrouped"))}),t.jsx("span",{className:"bim-d-meta",children:c("workPage.groupCount",{n:M.total})}),M.imageCount>0&&t.jsx("span",{className:"bim-d-flag",children:c("workPage.groupImage",{n:M.imageCount})})]}),k>0&&t.jsx("table",{className:"bim-d-zt bim-d-zt-ver",children:t.jsx("tbody",{children:P.map(q=>{const _=u.get(q.id);return t.jsx(nl,{row:q,measure:_==null?void 0:_.measure_info,relations:q.relations??(_?Ll(_):void 0),loaded:!0,onNavigate:n,renderLink:r},q.id)})})}),k>0&&M.total>k&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(q=>({...q,[M.key]:k+Br})),children:c("workPage.groupMore",{n:M.total-k})})]},M.key)})]}):t.jsxs(t.Fragment,{children:[t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&en(Q.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:Ne.map(M=>{var k;return t.jsx(nl,{row:M,measure:(k=u.get(M.id))==null?void 0:k.measure_info,relations:M.relations,loaded:u.has(M.id),onNavigate:n,renderLink:r},`${M.id}:${u.has(M.id)?"r":"p"}`)})})]}),Ne.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(v||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx(Jn,{total:Q.rows.length,shown:Ne.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)})]}),Q.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),fe.length>0&&t.jsx(Cx,{items:fe,transport:i,onNavigate:n,renderLink:r}),X>0&&e._contents&&t.jsx(Ex,{workId:e.id,info:e._contents,transport:i,onNavigate:n,renderLink:r}),me&&t.jsx(St,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),de=(M,k)=>t.jsx(jt,{id:M,label:m(k),onNavigate:n,renderLink:r,dense:!0}),ge=b.useMemo(()=>{const M=new Map;for(const k of I){const P=tl(k.relation,c);M.set(P,(M.get(P)??0)+1)}return M.size>1?[...M.entries()].sort((k,P)=>P[1]-k[1]).slice(0,4).map(([k,P])=>`${m(k)} ${P}`).join(" · "):void 0},[I,m,c]),Oe=t.jsxs(t.Fragment,{children:[t.jsx(mi,{id:"collected",title:c("workPage.sec.collected"),items:V.map(M=>de(M.id,M.title)),metas:V.map(M=>re.get(M.id)??"")}),t.jsx(mi,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:I.length}),sub:ge,items:I.map(M=>t.jsxs(t.Fragment,{children:[de(M.id,M.title),t.jsx("span",{className:"bim-d-meta",title:M.note?m(M.note):void 0,children:m(tl(M.relation,c))})]}))}),t.jsx(mi,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:ue.map(({r:M,kind:k})=>{const P=m((M.url?s.getDisplayNameFromUrl(M.url):void 0)||M.name),q=s.resourceHref(M);return t.jsxs(t.Fragment,{children:[q?t.jsxs("a",{href:q,target:"_blank",rel:"noopener noreferrer",children:[P," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:P}),k&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:k})]})})})]});return t.jsx(Zi,{railTop:a,back:l,nav:ie,railLinks:d,main:se,card:Xe,side:Oe})};function _x(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function ps(e,i){return i((e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name)}function Nx(e){var a;if(!e)return;const n=e.replace(/\*\*/g,"").split(/\n/)[0].trim().match(/[^。]+。?/g)??[],o=((n.length>1&&((a=n[0])!=null&&a.startsWith("《"))?n[1]:n[0])??"").trim();return o?o.length>120?`${o.slice(0,120)}…`:o:void 0}function zx({copies:e,onNavigate:i,renderLink:n}){const{t:r,convert:o}=oe(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?ps(l.holders[0],o):"")||"",c=a.get(d)??[];c.push(l),a.set(d,c)}return t.jsxs("span",{className:"bim-d-zt-copies",children:[r("workPage.sameEditionCopies",{n:e.length}),[...a].map(([l,d],c)=>t.jsxs(b.Fragment,{children:[c>0?";":"",l?`${o(l)} `:"",d.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0?" · ":"",t.jsx(jt,{id:m.id,label:m.callNumber||m.id,onNavigate:i,renderLink:n,dense:!0})]},m.id))]},l||c))]})}function nl({row:e,measure:i,relations:n,loaded:r,onNavigate:o,renderLink:a}){const{t:l,convert:d}=oe(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),m=e.era.source==="edition",p=e.holders[0],h=e.copies??[],u=h.length&&e.locationName?d(e.locationName):p?ps(p,d):e.locationName?d(e.locationName):"",f=e.images[0],g=f?s.resourceHref(f):void 0,y=e.images.map(v=>ps(v,d)).join("、");return t.jsxs("tr",{"data-loading":r?void 0:"",className:h.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:h.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(jt,{id:e.id,label:d(e.name),onNavigate:o,renderLink:a,dense:!0}),i?t.jsx("span",{className:"bim-d-meta",children:d(i)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}),n&&n.length>0&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:n.map((v,w)=>t.jsxs(b.Fragment,{children:[w>0?" · ":null,d(l("workPage.relationWith",{relation:v.relation,n:v.ids.length}))]},v.relation))}),h.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:d(e.summary)}),h.length>0&&t.jsx(zx,{copies:h,onNavigate:o,renderLink:a})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:m?l("workPage.inferredFromEdition"):void 0,children:c?d(c):r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${u?"":" bim-d-zt-blank"}`,children:[u||(r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),h.length>0&&e.callNumber&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:e.callNumber}),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:y,children:l("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:y,children:l("workPage.hasImage")}))})]})}function Cx({items:e,transport:i,onNavigate:n,renderLink:r}){const{t:o,convert:a}=oe(),{items:l,groups:d}=b.useMemo(()=>{const f=[],g=new Map;for(const y of e){const v=`${y.source}\0${y.source_bid??""}`,w=g.get(v);w?w.push(y):(g.set(v,[y]),f.push(y))}return{items:f,groups:f.map(y=>g.get(`${y.source}\0${y.source_bid??""}`))}},[e]),[c,m]=b.useState(0),p=Math.min(c,l.length-1);l[p];const[h,u]=b.useState(new Map);return b.useEffect(()=>{if(!i)return;const f=[...new Set(l.map(y=>y.source_bid).filter(y=>!!y))];if(f.length===0)return;let g=!1;return Promise.all(f.map(y=>i.getItem(y).then(v=>{var w,x;return[y,((x=(w=v==null?void 0:v.authors)==null?void 0:w[0])==null?void 0:x.dynasty)??""]}).catch(()=>[y,""]))).then(y=>{g||u(new Map(y.filter(([,v])=>v)))}),()=>{g=!0}},[i,l]),t.jsx(St,{id:"catalogs",title:o("workPage.sec.catalogs"),meta:t.jsx(vt,{items:[o("workPage.catalog.meta",{n:l.length}),o("workPage.sortByCatalog")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":o("workPage.catalog.tablist"),children:l.map((f,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===p,"aria-label":a(f.source),onClick:()=>m(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:h.get(f.source_bid??"")?a(h.get(f.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...a(f.source)].slice(0,9).map((y,v)=>t.jsx("span",{children:y},v))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d[p].map((f,g)=>t.jsxs("div",{className:"bim-d-lu-entry",children:[f.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(f.title_info)}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[f.source_bid?t.jsx(jt,{id:f.source_bid,label:a(f.source),onNavigate:n,renderLink:r,dense:!0}):a(f.source),f.section?a(f.section):"",f.author_info?`${o("label.authorInfo")} ${a(f.author_info)}`:"",f.edition?`${o("label.edition")} ${a(f.edition)}`:"",f.page??""]}),f.summary&&t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.summary),void 0,{t:o})}),f.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.comment),void 0,{t:o})})]}),f.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.additional_comment),void 0,{t:o})})]}),!f.summary&&!f.comment&&!f.additional_comment&&!f.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:o("workPage.catalog.titleOnly")})]},g)),l.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[p>0?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.prev",{name:a(l[p-1].source)}),onClick:()=>m(p-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(l[p-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[p+1," / ",l.length]}),p<l.length-1?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.next",{name:a(l[p+1].source)}),onClick:()=>m(p+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(l[p+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Ex({workId:e,info:i,transport:n,onNavigate:r,renderLink:o}){const{t:a,convert:l}=oe(),[d,c]=b.useState(1),[m,p]=b.useState(null),[h,u]=b.useState(!1),f=!!(n!=null&&n.getWorkContents);b.useEffect(()=>{if(!(n!=null&&n.getWorkContents))return;let y=!1;return p(null),u(!1),n.getWorkContents(e,d).then(v=>{y||(v?p(v):u(!0))}).catch(()=>{y||u(!0)}),()=>{y=!0}},[n,e,d]);const g=i.pages>1?t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d<=1,onClick:()=>c(y=>y-1),children:a("workPage.contents.prev")}),t.jsx("span",{className:"bim-d-meta",children:a("workPage.contents.page",{page:d,pages:i.pages})}),t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d>=i.pages,onClick:()=>c(y=>y+1),children:a("workPage.contents.next")})]}):null;return t.jsxs(St,{id:"contents",title:a("workPage.sec.contents"),meta:t.jsx(vt,{items:[a("workPage.contents.meta",{n:i.total})]}),children:[f&&g,f&&!m&&!h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.loading")}),f&&h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.error")}),m&&m.length>0&&t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("workPage.contents.vol")}),t.jsx("th",{children:a("workPage.contents.title")}),t.jsx("th",{children:a("workPage.contents.author")})]})}),t.jsx("tbody",{children:m.map((y,v)=>{var j,S;const w=Gr(y.vol),x=v>0?Gr(m[v-1].vol):null;return t.jsxs("tr",{children:[t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w&&w!==x?"":" bim-d-zt-blank"}`,children:w&&w!==x?w:null}),t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:y.id,label:l(y.title??y.id),onNavigate:r,renderLink:o,dense:!0})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${(j=y.au)!=null&&j.length?"":" bim-d-zt-blank"}`,children:(S=y.au)!=null&&S.length?l(y.au.join("、")):null})]},y.id)})})]}),f&&m&&g]})}const Cd=({graph:e,renderLink:i,className:n,style:r})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Ux,...r},className:n,children:o("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const g=l.get(f.target)??[];g.push(f),l.set(f.target,g)}else for(const g of[f.source,f.target]){const y=d.get(g)??[];y.push(f),d.set(g,y)}const c=new Map(e.nodes.map(f=>[f.id,f])),m=new Map,p=[];for(const f of e.nodes)if(f.group){const g=m.get(f.group)??[];g.push(f),m.set(f.group,g)}else p.push(f);const h=(f,g)=>(f.year??9999)-(g.year??9999);m.forEach(f=>f.sort(h)),p.sort(h);const u=e.groups.filter(f=>m.has(f.id));return t.jsxs("div",{className:n,style:{...Tx,...r},children:[e.title&&t.jsx("div",{style:Ix,children:a(e.title)}),e.description&&t.jsx("div",{style:Mx,children:a(e.description)}),u.map(f=>t.jsx(rl,{label:f.label,color:f.color,nodes:m.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i},f.id)),p.length>0&&t.jsx(rl,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},rl=({label:e,color:i,nodes:n,incomingMap:r,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:Ax,children:[t.jsx("div",{style:{...Lx,borderLeftColor:i??s.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(Rx,{node:c,incoming:r.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Rx=({node:e,incoming:i,siblings:n,nodeMap:r,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=oe();return t.jsxs("div",{style:{...Px,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?s.bim("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Ox,children:[t.jsx("span",{style:Fx,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Bx,children:Rl(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Hx,children:[e.category&&t.jsx(Pi,{children:c(e.category)}),e.status==="lost"&&t.jsx(Pi,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Pi,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Pi,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Pi,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Dx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Wx,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:ol,children:[t.jsx("div",{style:al,children:d("lineage.sources")}),i.map(m=>{const p=r.get(m.source);return t.jsxs("div",{style:ll(m.confidence),children:[t.jsx("span",{style:cl,children:c(m.relation)}),t.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&o?o(p.id,c(p.label)):c((p==null?void 0:p.label)??m.source)}),m.confidence!=="consensus"&&m.confidence!=="certain"&&t.jsx(sl,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:dl,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:ol,children:[t.jsx("div",{style:al,children:d("lineage.related")}),n.map(m=>{const p=m.source===e.id?m.target:m.source,h=r.get(p);return t.jsxs("div",{style:ll(m.confidence),children:[t.jsx("span",{style:cl,children:c(m.relation)}),t.jsx("span",{children:(h==null?void 0:h.kind)==="book"&&o?o(h.id,c(h.label)):c((h==null?void 0:h.label)??p)}),t.jsx(sl,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:dl,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Pi=({children:e,tone:i="default"})=>{const r={default:{bg:s.bim("tag-bg"),fg:s.bim("fg")},warn:{bg:s.bim("warn-bg"),fg:s.bim("warn-fg")},info:{bg:s.bim("info-bg"),fg:s.bim("info-fg")}}[i];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},sl=({level:e})=>{const{t:i}=oe(),r={certain:{key:"certain",color:s.bim("confidence-certain")},consensus:{key:"consensus",color:s.bim("confidence-consensus")},probable:{key:"probable",color:s.bim("confidence-probable")},disputed:{key:"disputed",color:s.bim("confidence-disputed")}}[e];return r?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:i(`lineage.confidence.${r.key}`)}):null},Tx={fontSize:"14px",color:s.bim("fg")},Ix={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Mx={fontSize:"13px",color:s.bim("muted"),marginBottom:"16px",lineHeight:1.6},Ax={marginBottom:"16px"},Lx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:s.bim("fg")},Px={border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:s.bim("bg")},Ox={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Fx={fontSize:"15px",fontWeight:600},Bx={fontSize:"12px",color:s.bim("muted")},Hx={marginBottom:"6px"},Dx={fontSize:"12px",color:s.bim("muted"),margin:"2px 0"},Wx={fontSize:"12px",color:s.bim("muted"),fontStyle:"italic",margin:"4px 0"},ol={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${s.bim("widget-border")}`},al={fontSize:"11px",color:s.bim("muted"),marginBottom:"2px"},ll=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),cl={display:"inline-block",padding:"0 6px",fontSize:"11px",background:s.bim("tag-bg"),color:s.bim("fg"),borderRadius:"3px",marginRight:"6px"},dl={fontSize:"11px",color:s.bim("muted")},Ux={padding:"20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px"},Ed=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[r,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Kx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:ul,children:n("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:ul,children:[t.jsx("div",{children:ml(n("lineage.graphMissing"),{xyflow:t.jsx("code",{children:"@xyflow/react"}),dagre:t.jsx("code",{children:"@dagrejs/dagre"})})}),t.jsx("div",{style:{fontSize:"12px",marginTop:"4px"},children:ml(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Yx,{modules:a,selectedNodeId:e,...i})};function ml(e,i){return e.split(/(\{\w+\})/).map((n,r)=>{const o=/^\{(\w+)\}$/.exec(n);return t.jsx(b.Fragment,{children:o&&o[1]in i?i[o[1]]:n},r)})}async function Kx(){try{const[e,i]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let n=!1;try{await import("@xyflow/react/dist/style.css"),n=!0}catch{n=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:i,cssLoaded:n}}catch{return null}}const Yx=({graph:e,renderLink:i,height:n=600,className:r,style:o,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:m,Handle:p,Position:h,BaseEdge:u,EdgeLabelRenderer:f,getSmoothStepPath:g,dagre:y}=l,v=b.useMemo(()=>({lineage:N=>{var ae,ce,Ee,we;const z=((ae=N.data)==null?void 0:ae.stepPosition)??.85,[C,U,R]=g({sourceX:N.sourceX,sourceY:N.sourceY,sourcePosition:N.sourcePosition,targetX:N.targetX,targetY:N.targetY,targetPosition:N.targetPosition,stepPosition:z,borderRadius:5}),L=!!((ce=N.data)!=null&&ce.isSibling),F=L?U:N.targetX-18,T=L?R:N.targetY-12,Z=(Ee=N.data)==null?void 0:Ee.labelStyle,O=(we=N.data)==null?void 0:we.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:N.id,path:C,style:N.style,markerStart:N.markerStart,markerEnd:N.markerEnd}),N.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${T}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:s.bim("bg"),border:`0.5px solid ${s.bim("widget-border")}`,...O,...Z},children:N.label})})]})}}),[u,f,g]),w=b.useMemo(()=>({version:N=>{const{t:z}=oe(),C=N.data,U=C.kind==="hypothetical",R=C.status==="lost",L=C.isSelected,F=C.bridge,T=C.borderColor??s.bim("muted"),Z=F||U?"dashed":"solid",O=F?.5:R?.6:1;return t.jsxs("div",{style:{background:F?s.bim("bg-subtle"):s.bim("bg"),border:`2px ${Z} ${L?s.bim("primary"):T}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:L?s.bim("shadow-node-selected"):U||F?"none":s.bim("shadow-node")},title:F?z("lineage.bridgeTitle"):void 0,children:[t.jsx(p,{type:"target",position:h.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:U||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.2},children:Rl(C.yearText,void 0,C.uncertain)}),R&&t.jsx("div",{style:{fontSize:9,color:s.bim("lost-fg"),marginTop:1},children:z("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=oe(),{rfNodes:j,rfEdges:S}=b.useMemo(()=>Gx(e,y,i,a,x),[e,y,i,a,x]);return t.jsx("div",{style:{width:"100%",height:n,...o},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:v,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(m,{showInteractive:!1})]})})};function Gx(e,i,n,r,o=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new i.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const m=new Map(e.groups.map(w=>[w.id,w.color??s.bim("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(p.has(w.relation)||c.setEdge(w.source,w.target));i.layout(c);const h=e.nodes.map(w=>{const x=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:o(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:o(w.year_text??qx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?m.get(w.group):void 0,renderLink:n,isSelected:j,description:o(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:S,draggable:!1,selected:j}}),u=.78,f=.06,g=new Map;for(const w of e.edges)w.kind==="derive"&&(g.has(w.source)||g.set(w.source,[]),g.get(w.source).push(w));const y=new Map;for(const[w,x]of g){if(x.length<=1)continue;const j=[...x].sort(($,N)=>{var U,R;const z=((U=c.node($.target))==null?void 0:U.y)??0,C=((R=c.node(N.target))==null?void 0:R.y)??0;return z-C}),S=j.length;j.forEach(($,N)=>{const z=(N-(S-1)/2)*f;y.set($.id,u+z)})}const v=e.edges.map(w=>Vx(w,y.get(w.id),o));return{rfNodes:h,rfEdges:v}}function Vx(e,i,n=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Xx(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:n(e.relation),data:{labelStyle:{color:s.bim("fg")},isSibling:o,stepPosition:i},style:{stroke:a,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:o?l:void 0,zIndex:1e3}}function qx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Xx(e){switch(e){case"certain":return s.bim("confidence-certain");case"consensus":return s.bim("lineage-edge-consensus");case"probable":return s.bim("confidence-probable");case"disputed":return s.bim("confidence-disputed");default:return s.bim("muted")}}const ul={padding:"40px 20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px",border:`1px dashed ${s.bim("widget-border")}`,borderRadius:8,background:s.bim("bg")},lo=({graph:e,defaultMode:i="list",renderLink:n,graphHeight:r=600,selectedNodeId:o,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:m,className:p,style:h})=>{var S;const{t:u,convert:f}=oe(),[g,y]=b.useState(i),v=$=>{y($),a==null||a($)},w=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:s.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:p,style:h,children:[t.jsxs("div",{style:Jx,children:[t.jsx("button",{onClick:()=>v("list"),style:Hr(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>v("graph"),style:Hr(g==="graph"),children:u("lineage.modeGraph")}),x&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:s.bim("muted"),marginRight:4},children:u("lineage.collectionLabel")}),w.map(([$,N])=>{const z=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Hr(l===$),title:N.description?f(N.description):void 0,children:[f(N.label),z!=null?` ${z}`:""]},$)})]})]}),x&&j&&t.jsx("div",{style:{fontSize:12,color:s.bim("muted"),marginBottom:8,padding:"4px 8px",background:s.bim("bg-subtle"),borderRadius:4},children:f(j)}),g==="list"?t.jsx(Cd,{graph:e,renderLink:n}):t.jsx(Ed,{graph:e,renderLink:n,height:r,selectedNodeId:o})]})},Jx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Hr=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${s.bim("widget-border")}`,borderRadius:4,background:e?s.bim("primary"):"transparent",color:e?s.bim("primary-fg"):s.bim("fg"),cursor:"pointer"}),pl=40,bl=2,Zx=9,Qx=new Set(["certain","consensus","probable","disputed"]);function Dr(e){if(!e)return["",""];const i=e.split(/[ ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const Rd=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Oe,Je,Pe,Ue,nt,Y,M,k,P,q;const h=s.useT(),{t:u,convert:f}=oe(),[g,y]=b.useState(null),[v,w]=b.useState(new Map),[x,j]=b.useState([]),[S,$]=b.useState(new Map),[N,z]=b.useState(!1),[C,U]=b.useState("flow"),[R,L]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let _=!1;return i.getItem(e.work_id).then(le=>{!_&&le&&le.type==="work"&&y(le)}).catch(()=>{}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){L(null);return}let _=!1;return i.getLineageGraph(e.work_id).then(le=>{_||L(le&&le.nodes.length>1?le:null)}).catch(()=>{_||L(null)}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{const _=e._collections||[];if(!i||_.length===0){w(new Map);return}let le=!1;return Promise.all(_.map(H=>{const he=H.id;return i.getItem(he).then(xe=>[he,xe]).catch(()=>[he,null])})).then(H=>{if(le)return;const he=new Map;for(const[xe,Re]of H)Re&&he.set(xe,Re);w(he)}),()=>{le=!0}},[i,e._collections]);const F=b.useMemo(()=>{const _=new Set([...g?Ss(g):[],...wu(e)]);return _.add(e.id),[..._]},[g,e.related_books,e.id]),T=F.length-1;b.useEffect(()=>{if(!i||T<=0){j([]);return}const _=F.length<=pl,le=_?F:F.slice(0,8);let H=!1;return Promise.all(le.map(he=>he===e.id?Promise.resolve({id:he,title:e.title,edition:e.edition,year:Mn(e)}):i.getItem(he).then(xe=>{const Re=xe??{};return{id:he,title:Re.title,edition:Re.edition,year:xe?Mn(Re):void 0}}).catch(()=>({id:he})))).then(he=>{if(H)return;const xe=he.filter(Re=>Re.id===e.id||Re.title||Re.edition);_&&xe.sort((Re,Ze)=>(Re.year??1/0)-(Ze.year??1/0)),j(xe)}),()=>{H=!0}},[i,F,T,e]),e.lineage;const Z=b.useMemo(()=>[...Vt(e).filter(_=>_.ref_type==="book").map(_=>_.ref),...ti(e).map(_=>_.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||Z.length===0){$(new Map);return}let _=!1;return Promise.all(Z.map(le=>i.getItem(le).then(H=>[le,{id:le,title:H==null?void 0:H.title,edition:H==null?void 0:H.edition}]).catch(()=>[le,{id:le}]))).then(le=>{_||$(new Map(le))}),()=>{_=!0}},[i,Z]);const O=b.useMemo(()=>$d(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),ae=O.groups.reduce((_,le)=>_+le.rows.length+le.mirrors.length,0),ce=O.groups.length>0&&O.groups.every(_=>_.key==="_physical"),Ee=Ji(e),we=Wl(e),ye=qt(e,h.unit.juan),Q=new Set((e._collections||[]).map(_=>Wi(_.vol).length).filter(_=>_>0)),Ne=_=>{var he;const le=(he=e.base_edition)==null?void 0:he.find(xe=>xe.book_id===_&&xe.name);if(le!=null&&le.name)return le.name;const H=S.get(_);return(H==null?void 0:H.edition)||(H==null?void 0:H.title)||""},W=b.useMemo(()=>{var He,ct;const _=[];we&&_.push({label:u("bookPage.fact.editionType"),value:f(we),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(He=e.publication_info)!=null&&He.details?_.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(Ee.era||Ee.reign)&&_.push({label:u("bookPage.fact.era"),value:f([Ee.era,Ee.reign].filter(Boolean).join(" ")),title:Ee.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),ye&&_.push({label:u("bookPage.fact.measure"),value:f(ye)});const le=(e._collections||[]).flatMap(Be=>Wi(Be.vol));le.length&&_.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Yn(le,h.unit.volume),unit:h.unit.volume,n:le.length})});const H=Vt(e).find(Be=>Be.relation==="底本"&&Be.ref_type==="book");H&&Ne(H.ref)&&_.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(jt,{id:H.ref,label:f(Ne(H.ref)),onNavigate:n,renderLink:r,dense:!0})});const he=(e.base_edition||[]).filter(Be=>Be&&Be.name);for(const Be of["底本","配補","參校"]){if(Be==="底本"&&H&&Ne(H.ref))continue;const ee=he.filter(Se=>Se.role===Be);ee.length&&_.push({label:f(Be),value:ee.map((Se,et)=>t.jsxs(b.Fragment,{children:[et>0&&"、",Se.book_id?t.jsx(jt,{id:Se.book_id,label:f(Se.name),onNavigate:n,renderLink:r,dense:!0}):f(Se.name)]},et))})}const xe=(e.provenance||[]).filter(Be=>Be&&Be.institution),Re=(e.resources||[]).filter(Be=>s.getResourceTypes(Be).includes("physical"));if(xe.length){_.push({label:u("bookPage.fact.holdings"),value:xe.slice(0,2).map(Se=>f(Se.institution)).join("、")+(xe.length>2?u("bookPage.andMorePlaces",{n:xe.length}):"")});const Be=xe.filter(Se=>Se.call_number).slice(0,2).map(Se=>`${f(Se.institution)} ${Se.call_number}`);Be.length&&_.push({label:u("bookPage.fact.callNumber"),value:Be.join(";")+(xe.filter(Se=>Se.call_number).length>2?"…":"")});const ee=xe.flatMap(Se=>Se.seals||[]).filter(Boolean);ee.length&&_.push({label:u("bookPage.fact.seals"),value:f(ee.join("、"))})}else Re.length&&_.push({label:u("bookPage.fact.holdings"),value:Re.slice(0,2).map(Be=>f(Be.name)).join("、")+(Re.length>2?u("bookPage.andMorePlaces",{n:Re.length}):"")});const Ze=e.physical_description;if(Ze){const Be=[[u("bookPage.fact.leafStyle"),Ze.leaf_style],[u("bookPage.fact.binding"),Ze.binding],[u("bookPage.fact.dimensions"),Ze.dimensions],[u("bookPage.fact.condition"),Ze.condition]];for(const[ee,Se]of Be)Se&&Se.trim()&&_.push({label:ee,value:f(Se)})}(ct=e.page_count)!=null&&ct.description&&_.push({label:h.label.pageCount,value:f(e.page_count.description)});const Me=Ic(e.additional_titles);return Me.length&&_.push({label:u("bookPage.fact.aliases"),value:Me.map(f).join("、")}),_},[e,f,h,u,Ee,we,ye,S,n,r]),je=f(e.title),K=e.edition?f(e.edition):void 0,V=((Oe=e.dating)==null?void 0:Oe.text)||"",re=t.jsx(tn,{kind:u("bookPage.kind"),title:je,subtitle:K,byline:t.jsx(oo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:r}),meta:(()=>{const _=[we?f(we):"",Ee.era?f([Ee.era,Ee.reign].filter(Boolean).join("")):"",ye?f(ye):""].filter(Boolean);return _.length?t.jsx("span",{className:"bim-d-tags",children:_.map((le,H)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(H,2)}`,children:le},H))}):null})(),description:(Je=e.description)!=null&&Je.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Pe=e.description)==null?void 0:Pe.text)?6:void 0,facts:W,readAction:o,secondaryAction:o&&ae>0&&!ce?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),X=e._collections||[],I=(a==null?void 0:a.chapters)||[],ue=f(I[0]&&Dr(I[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),fe=u("bookPage.chapterCount",{n:I.length,unit:ue}),ze=!!(Vt(e).length||ti(e).length||(Ue=e.appendix)!=null&&Ue.length),B=[],pe=u(ce?"bookPage.sec.physical":"bookPage.sec.images");(I.length||O.text.length||l)&&B.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:I.length?fe:void 0}),O.groups.length&&B.push({id:"images",label:pe,count:ae}),ze&&B.push({id:"lineage",label:u("bookPage.sec.lineage")}),X.length&&B.push({id:"collections",label:u("section.containedIn"),count:X.length}),(nt=e.location_history)!=null&&nt.length&&B.push({id:"provenance",label:u("section.locationHistory")});const Te=_=>(d==null?void 0:d(_))??null,ve=I[0],Ve=ve?Te(ve.file):null,qe=N?I:I.slice(0,Zx),Xe=(_,le,H)=>_?t.jsx("a",{className:H,href:_.href??"#",onClick:_.onClick?he=>{he.metaKey||he.ctrlKey||(he.preventDefault(),_.onClick())}:void 0,children:le}):t.jsx("span",{className:H,children:le}),J=t.jsxs(t.Fragment,{children:[(I.length>0||O.text.length>0||l)&&t.jsxs(St,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:I.length>0?t.jsx(vt,{items:[fe,(Y=a==null?void 0:a.source)!=null&&Y.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!ve&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),ve&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Dr(ve.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((ve.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),Xe(Ve,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),I.length>1&&t.jsx("ul",{className:"bim-d-chap",children:qe.map(_=>{const[le,H]=Dr(_.title);return t.jsx("li",{children:Xe(Te(_.file),t.jsxs(t.Fragment,{children:[le&&t.jsx("b",{children:f(le)}),f(H||_.file)]}))},_.file)})}),I.length>qe.length&&t.jsx(Ts,{label:u("detail.expandRest",{n:I.length-qe.length,unit:ue}),onClick:()=>z(!0)}),O.text.length>0&&t.jsxs(t.Fragment,{children:[(I.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:u("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:O.text.map((_,le)=>t.jsx(ao,{item:_,siblings:O.text,listedVolumeCounts:Q},`${_.id||_.url||_.name}-${le}`))})})]})]}),O.groups.length>0&&t.jsx(St,{id:"images",title:pe,meta:t.jsx(vt,{items:[O.groups.length>1?u("bookPage.groupCount",{n:O.groups.length}):"",u("bookPage.placeCount",{n:ae})]}),children:t.jsx(Nd,{groups:O.groups,listedVolumeCounts:Q})}),ze&&t.jsx(St,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Vt(e).length?u("bookPage.lineageMeta"):void 0,action:R?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":u("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":C==="flow",onClick:()=>U("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>U("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&R?t.jsx(lo,{graph:R,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(_,le)=>t.jsx(jt,{id:_,label:f(le),onNavigate:n,renderLink:r,dense:!0})}):t.jsx(t0,{data:e,heading:K||je,yearText:V,refName:Ne,onNavigate:n,renderLink:r})}),X.length>0&&t.jsx(St,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:X.map((_,le)=>{const H=_.id,he=Wi(_.vol),xe=v.get(H),Re=Gu(xe);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:H,label:xe?f(xe.title):H,onNavigate:n,renderLink:r,dense:!0}),he.length>0&&t.jsx(e0,{volumes:he,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Re?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Re>0&&u("bookPage.totalOf",{n:Re,unit:h.unit.bu})})]},`${H}-${le}`)})})})}),(M=e.location_history)!=null&&M.length?t.jsx(St,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((_,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(_.name||_.location||"")}),([_.start_date,_.end_date].filter(Boolean).join("—")||_.description||_.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[_.start_date,_.end_date].filter(Boolean).join("—"),_.description?f(_.description):"",_.note?f(_.note):""]})})]},le))})}):null,B.length===0&&t.jsx(St,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),ie=x.findIndex(_=>_.id===e.id),me=F.length<=pl,se=me&&ie>=0?x.slice(Math.max(0,ie-bl),ie+bl+1):x.filter(_=>_.id!==e.id),de=t.jsxs(t.Fragment,{children:[g&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:f(h.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(jt,{id:g.id,label:f(g.title),onNavigate:n,renderLink:r})}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(_=>`${_.dynasty?`〔${f(_.dynasty)}〕`:""}${f(_.name)}`),f(qt(g,h.unit.juan)),g._edition_count??((k=g._books)==null?void 0:k.length)?u("bookPage.editionCount",{n:g._edition_count??((P=g._books)==null?void 0:P.length)??0}):""]}),((q=g.description)==null?void 0:q.text)&&t.jsx("p",{style:{fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc bim-d-side-desc",children:f(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),T>0&&se.length>0&&t.jsxs("div",{children:[t.jsx(mi,{id:"siblings",timeline:!0,title:me?u("bookPage.siblings"):h.relation.siblingVersions,meta:me?u("bookPage.byEra"):u("bookPage.kindCount",{n:T}),cap:se.length,items:se.map(_=>_.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(_.edition||_.title||_.id)}):t.jsx(jt,{id:_.id,label:f(_.edition||_.title||_.id),onNavigate:n,renderLink:r,dense:!0})),metas:se.map(_=>[_.year!=null?_.year<0?u("detail.bce",{n:-_.year}):String(_.year):"",_.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:se.findIndex(_=>_.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(jt,{id:g.id,label:u("bookPage.viewAllInWork",{n:F.length}),onNavigate:n,renderLink:r,dense:!0})})]})]}),ge=e.work_id?t.jsx(jc,{caption:h.section.belongsToWork,children:t.jsx(jt,{id:e.work_id,label:g?f(g.title):" ",onNavigate:n,renderLink:r,dense:!0})}):void 0;return t.jsx(Zi,{railTop:c,back:m,up:ge,nav:B,railLinks:p,main:J,card:re,side:de})};function e0({volumes:e,unit:i}){const{t:n}=oe();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Yn(e,i),unit:i}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),n("bookPage.volumeCount",{n:e.length,unit:i})]})]})}function t0({data:e,heading:i,yearText:n,refName:r,onNavigate:o,renderLink:a}){var w;const{t:l,convert:d}=oe(),c=e.lineage,m=Vt(e),p=m.filter(x=>x.ref_type!=="book"),h=m.filter(x=>x.ref_type==="book"&&x.relation==="底本"),u=m.filter(x=>x.ref_type==="book"&&x.relation!=="底本"),f=ti(e),g=m.length>0||f.length>0,y=x=>x&&Qx.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",v=(x,j)=>t.jsx(jt,{id:x,label:d(j||x),onNavigate:o,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[p.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:x.relation?d(x.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),x.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(x.evidence),y(x.confidence)]})]})},`a-${j}`)),h.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:i}),n&&t.jsx("span",{className:"bim-d-lf-yr",children:d(n)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((x,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},j))})]}),f.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((x,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[v(x.book_id,r(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((x,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(x.title)]}),t.jsx(zi,{text:x.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Oi=16,i0=200,n0=16,Td=({data:e,catalog:i,transport:n,onNavigate:r,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var me,se,de,ge,Oe,Je,Pe,Ue,nt;const{t:m,convert:p,messages:h}=oe(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[v,w]=b.useState(null),[x,j]=b.useState(""),[S,$]=b.useState(!1),N=b.useMemo(()=>Dl(e,i),[e,i]),z=b.useMemo(()=>Hl(e),[e]),[C,U]=b.useState(new Map),R=!!n&&N.rows.length>0&&N.rows.length<=i0,L=R&&(N.rows.length<=Oi||S),F=L&&N.rows.every(Y=>!Y.id||C.has(Y.id)),T=Y=>{var M;return us(Y?(M=C.get(Y))==null?void 0:M.l1:void 0)},Z=b.useMemo(()=>{const Y=u.trim(),M=Y?p(Y):"";return N.rows.filter(k=>{var q,_;if(x&&us(k.id?(q=C.get(k.id))==null?void 0:q.l1:void 0)!==x)return!1;if(!M)return!0;const P=k.id&&((_=C.get(k.id))==null?void 0:_.title)||k.title;return p(P).includes(M)||(k.subItems||[]).some(le=>p(le).includes(M))})},[N.rows,u,x,C,p]),O=g?Z:Z.slice(0,Oi),ae=b.useMemo(()=>(L?N.rows:O).filter(Y=>Y.id&&!C.has(Y.id)).map(Y=>Y.id),[L,N.rows,O,C]);b.useEffect(()=>{if(!n||ae.length===0)return;let Y=!1;const M=ae.slice(0,n0);return tr(M,er,k=>n.getItem(k).then(P=>{var le,H;const q=P??{},_={title:q.title,edition:q.edition,authors:q.authors,measure:P?qt(P,h.unit.juan):void 0,versionCount:q._edition_count??((le=q._books)==null?void 0:le.length),l1:((H=$s(q))==null?void 0:H.l1)||void 0};return[k,_]}).catch(()=>[k,{}]),()=>Y).then(k=>{Y||U(P=>{const q=new Map(P);for(const[_,le]of k)q.set(_,le);return q})}),()=>{Y=!0}},[n,ae,h.unit.juan]);const ce=(me=(e.contained_in||[])[0])==null?void 0:me.id;b.useEffect(()=>{if(!ce){w(null);return}if(w({id:ce}),!n)return;let Y=!1;return n.getItem(ce).then(M=>{Y||w({id:ce,title:M==null?void 0:M.title})}).catch(()=>{}),()=>{Y=!0}},[n,ce]);const Ee=b.useMemo(()=>$d(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),we=Ee.text.length+Ee.groups.reduce((Y,M)=>Y+M.rows.length+M.mirrors.length,0),ye=z.works,Q=new Set(N.rows.map(Y=>Y.id).filter(Boolean)),Ne=ye.length>0&&!ye.every(Y=>Q.has(Y.id)),W=(()=>{const Y=N.rows.map(M=>M.edition).filter(Boolean);return Y.length>1&&new Set(Y).size===1})(),je=N.rows.some(Y=>Y.volumes.length>0||Y.expected!=null),K=z.total,V=z.truncated?K:N.rows.length,re=qt(e,h.unit.juan),X=e.count,I=Y=>typeof Y=="number"&&Number.isFinite(Y)?Y:null,ue=I(X==null?void 0:X.juan)??I((se=e.juan_count)==null?void 0:se.number)??I((ge=(de=e.measures)==null?void 0:de.find(Y=>(Y==null?void 0:Y.unit)==="卷"))==null?void 0:ge.number),fe=I(X==null?void 0:X.ce)??(N.totalVolumes||null),ze=[{value:V,label:m("collectionPage.stat.titles")},{value:ue??0,label:h.unit.juan},{value:fe??0,label:h.unit.volume}],B=b.useMemo(()=>{var k,P;const Y=[];if((k=e.publication_info)!=null&&k.details&&Y.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),K&&(K!==N.rows.length||z.truncated)){const q=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");Y.push({label:q,value:`${K} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const M=[I(X==null?void 0:X.zhong)!=null?m("collectionPage.nZhong",{n:X.zhong}):"",I(X==null?void 0:X.han)!=null?m("collectionPage.nHan",{n:X.han}):""].filter(Boolean);return M.length&&Y.push({label:m("collectionPage.fact.expected"),value:M.join(" ")}),ue==null&&re&&Y.push({label:m("collectionPage.fact.measure"),value:p(re),title:(P=e.juan_count)!=null&&P.description?p(e.juan_count.description):void 0}),Y},[e,K,z.truncated,N.rows.length,ue,re,X,p,m,h]),pe=b.useMemo(()=>{if(!F)return[];const Y=new Map;for(const k of N.rows){const P=T(k.id);P&&Y.set(P,(Y.get(P)??0)+1)}const M=Yi.filter(k=>(Y.get(k.key)??0)>0);return M.length<2?[]:[{key:"",label:`${h.catalog.all} ${V}`},...M.map(k=>({key:k.key,label:`${k.label} ${Y.get(k.key)}`}))]},[F,N.rows,C,h]),Te=b.useMemo(()=>{if(!F||!N.rows.some(P=>P.volumes.length>0))return null;const Y=[],M=N.rows.filter(P=>P.volumes.length>0).map(P=>({k:T(P.id)??"",from:Math.min(...P.volumes),to:Math.max(...P.volumes)})).sort((P,q)=>P.from-q.from);for(const P of M){const q=P.to-P.from+1,_=Y[Y.length-1];_&&_.key===P.k?(_.to=Math.max(_.to,P.to),_.n+=q):Y.push({key:P.k,from:P.from,to:P.to,n:q})}const k=M.reduce((P,q)=>Math.max(P,q.to),0);return Y.length>1&&Y.some(P=>P.key)?{segs:Y,last:k}:null},[F,N.rows,C]),ve=(Oe=e.description)==null?void 0:Oe.text,Ve=t.jsx(tn,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:r,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(Je=e.publication_info)!=null&&Je.year?p(e.publication_info.year):""]}),description:ve||(Pe=e.history)!=null&&Pe.length?t.jsxs(t.Fragment,{children:[ve&&t.jsx(zi,{text:ve,style:{fontSize:15,lineHeight:1.85}}),(Ue=e.history)!=null&&Ue.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((Y,M)=>t.jsx("li",{children:p(Y)},M))}):null]}):void 0,clampDescription:Is(ve)||(((nt=e.history)==null?void 0:nt.length)??0)>2?6:void 0,stats:ze,facts:B,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:Te&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:m("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":m("collectionPage.dist.head"),children:Te.segs.map((Y,M)=>{const k=Yi.find(P=>P.key===Y.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!k,title:k?m("collectionPage.dist.segTitle",{section:p(k.label),from:Y.from,to:Y.to}):void 0,"aria-label":k?m("collectionPage.dist.only",{section:p(k.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!k&&x===Y.key,style:{flexGrow:Y.n,background:k?s.bim(k.token):s.bim("rule")},onClick:()=>{k&&(j(x===Y.key?"":Y.key),y(!1))}},M)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:m("catalog.volume",{n:1})}),t.jsx("span",{children:m("collectionPage.dist.hint")}),t.jsx("span",{children:m("catalog.volume",{n:Te.last})})]})]})}),qe=[];N.rows.length&&qe.push({id:"titles",label:m("collectionPage.sec.titles"),count:V}),we&&qe.push({id:"resources",label:m("collectionPage.sec.resources"),count:we}),Ne&&qe.push({id:"works",label:h.section.containedWorks,count:ye.length});const Xe=t.jsxs(t.Fragment,{children:[N.rows.length>0&&t.jsxs(St,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${V} ${h.unit.items}`,N.totalVolumes?m("collectionPage.totalVolumes",{n:N.totalVolumes,unit:h.unit.volume}):"",Z.length!==V?m("collectionPage.currentN",{n:Z.length,unit:h.unit.items}):""]}),action:a,children:[(N.rows.length>Oi||pe.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[pe.length>0&&t.jsx(Qi,{items:pe,value:x,onChange:Y=>{j(Y),y(!1)}}),R&&N.rows.length>Oi&&!F&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>$(!0),title:m("collectionPage.loadAllTitle",{n:N.rows.length,unit:h.unit.items}),children:m(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),N.rows.length>Oi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:Y=>{f(Y.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(Z.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[je&&t.jsx("th",{style:{width:"8.5em"},children:m("collectionPage.col.volumes")}),t.jsx("th",{children:m("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:m("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:O.map((Y,M)=>{var he;const k=Y.id?C.get(Y.id):void 0,P=k!=null&&k.title&&Y.title===Y.id?k.title:Y.title,q=((k==null?void 0:k.authors)||[]).find(xe=>xe&&xe.name),_=[q?`${q.dynasty?`〔${p(q.dynasty)}〕`:""}${p(q.name)}${q.role?` ${p(q.role)}`:""}`:"",k!=null&&k.measure?p(k.measure):"",(he=Y.subItems)!=null&&he.length?Y.subItems.map(xe=>p(xe)).join("、"):"",(k!=null&&k.edition||Y.edition)&&!W?p((k==null?void 0:k.edition)||Y.edition||""):""].filter(Boolean),le=Yi.find(xe=>xe.key===T(Y.id)),H=Y.volumes.length>0?m("collectionPage.volumeRange",{range:Yn(Y.volumes,h.unit.volume),unit:h.unit.volume}):Y.expected!=null?`${Y.found??0}/${Y.expected} ${h.unit.volume}`:"";return t.jsxs("tr",{children:[je&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H?"":" bim-d-zt-blank"}`,children:[le&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:s.bim(le.token)}}),H||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[Y.id?t.jsx(jt,{id:Y.id,label:p(P),onNavigate:r,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(P)}),_.length>0?t.jsx(vt,{items:_}):Y.id&&!k&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k!=null&&k.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:k!=null&&k.versionCount?m("collectionPage.nZhong",{n:k.versionCount}):""})]},`${Y.id??Y.title}-${M}`)})})]}),O.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:m("catalog.noMatch")}),!g&&t.jsx(Jn,{total:Z.length,shown:O.length,unit:h.unit.items,onClick:()=>y(!0)})]}),we>0&&t.jsxs(St,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:we}),children:[Ee.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[Ee.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:m("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Ee.text.map((Y,M)=>t.jsx(ao,{item:Y,siblings:Ee.text},`${Y.id||Y.url||Y.name}-${M}`))})})]}),t.jsx(Nd,{groups:Ee.groups})]}),N.rows.length===0&&we===0&&t.jsx(St,{title:m("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("collectionPage.empty")})})]}),J=Ne?t.jsx(mi,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:ye.length}),cap:12,items:ye.map(Y=>t.jsx(jt,{id:Y.id,label:p(Y.title),onNavigate:r,renderLink:o,dense:!0}))}):null,ie=v?t.jsx(jc,{caption:m("collectionPage.parent"),children:t.jsx(jt,{id:v.id,label:p(v.title||v.id),onNavigate:r,renderLink:o,dense:!0})}):void 0;return t.jsx(Zi,{railTop:l,back:d,up:ie,nav:qe,railLinks:c,main:Xe,card:Ve,side:J})},r0=8;function Id(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function s0(e){return(e||[]).filter(i=>{var n,r;return Id(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((r=i.license)==null?void 0:r.trim())}).slice(0,r0)}function o0({images:e,assetBase:i,name:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?s0(e):[];if(!i||d||m.length===0)return null;const p=i.endsWith("/")?i:i+"/",h=m[Math.min(a,m.length-1)],u=h.width&&h.height&&h.width>0&&h.height>0?`${h.width} / ${h.height}`:void 0,f=g=>p+Id(g.file).split("/").map(encodeURIComponent).join("/");return t.jsxs("figure",{className:"bim-d-seal bim-d-ui",children:[t.jsx("img",{className:"bim-d-seal-main",src:f(h),alt:r("entityPage.sealAlt",{name:n})+(m.length>1?` ${a+1}`:""),style:u?{"--seal-ar":u}:void 0,width:h.width,height:h.height,decoding:"async",fetchPriority:"high",onError:()=>c(!0)},h.file),m.length>1&&t.jsx("div",{className:"bim-d-seal-thumbs",children:m.map((g,y)=>t.jsx("button",{type:"button","aria-pressed":y===a,"aria-label":`${r("entityPage.sealAlt",{name:n})} ${y+1}`,onClick:()=>l(y),children:t.jsx("img",{src:f(g),alt:"",loading:"lazy",decoding:"async"})},g.file))}),t.jsxs("figcaption",{children:[r("entityPage.imgCredit",{credit:o(h.credit)})," · ",r("entityPage.imgLicense",{license:o(h.license)}),h.source_url&&/^https?:\/\//i.test(h.source_url)&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:h.source_url,target:"_blank",rel:"noopener noreferrer nofollow",children:r("entityPage.imgSource")})]}),h.note&&t.jsxs(t.Fragment,{children:[" · ",o(h.note)]})]})]})}const hl=8,fl=10,gl=30,Md=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function a0(e){return`${Md(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function l0(e,i,n){var r;return`${Md(i,n.key,n.chapter)}#e=${((r=n.ids)!=null&&r.length?n.ids:[e]).join(",")}`}const c0=({id:e,transport:i,renderLink:n,onTotal:r})=>{const{t:o,convert:a}=oe(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(hl),[u,f]=b.useState(fl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),v=b.useRef(r);if(v.current=r,b.useEffect(()=>{if(d(null),m("idle"),h(hl),f(fl),!y)return;const $=g.current;let N=!1;const z=()=>{m("loading"),i.getMentions(e).then(U=>{var L,F;if(N)return;const R=U&&"books"in U?U:null;if(!R||!R.total){m("none"),(L=v.current)==null||L.call(v,0);return}d(R),m("ok"),(F=v.current)==null||F.call(v,R.total)}).catch(()=>{N||m("none")})};if(!$||typeof IntersectionObserver>"u")return z(),()=>{N=!0};const C=new IntersectionObserver(U=>{U.some(R=>R.isIntersecting)&&(C.disconnect(),z())},{rootMargin:"400px"});return C.observe($),()=>{N=!0,C.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const w=($,N,z)=>n?n($,N,z):t.jsx("a",{className:z,href:$,children:N}),x=new Map(((l==null?void 0:l.books)??[]).map($=>[$.item,$.title])),j=(l==null?void 0:l.examples)??[],S=(l==null?void 0:l.books)??[];return t.jsx("div",{ref:g,children:t.jsxs(St,{id:"mentions",title:o("mentions.title"),meta:l?t.jsx(vt,{items:[o("mentions.total",{n:l.total,b:S.length})]}):void 0,children:[!l&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:o("mentions.loading")}),l&&t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:o("mentions.hint")}),l&&j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.examples")}),t.jsx("ol",{className:"bim-d-mentions",children:j.slice(0,p).map(($,N)=>{const z=[x.get($.item),$.heading].filter(Boolean).map(U=>a(U)).join(" · "),C=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-mention-where bim-d-ui",children:z||$.chapter}),t.jsxs("span",{className:"bim-d-mention-ctx",children:[$.before?"…":"",a($.before),t.jsx("b",{children:a($.text)}),a($.after),$.after?"…":""]})]});return t.jsx("li",{children:w(a0($),C,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${N}`)})}),j.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(j.length),children:o("mentions.more",{n:j.length-p})})]}),l&&S.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.byBook")}),t.jsx("ul",{className:"bim-d-mbooks",children:S.slice(0,u).map($=>t.jsx(d0,{entityId:e,book:$,open:S.length===1,transport:i,link:w},$.item))}),S.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+gl),children:o("mentions.moreBooks",{n:Math.min(gl,S.length-u)})})]})]})})},d0=({entityId:e,book:i,open:n,transport:r,link:o})=>{const{t:a,convert:l}=oe(),[d,c]=b.useState(i.chapters??null),[m,p]=b.useState(!1);b.useEffect(()=>{c(i.chapters??null)},[i]);const h=u=>{!u.currentTarget.open||d||m||!(r!=null&&r.getMentions)||(p(!0),r.getMentions(e,i.item).then(f=>{f&&"chapters"in f&&Array.isArray(f.chapters)&&c(f.chapters)}).catch(()=>{}).finally(()=>p(!1)))};return t.jsx("li",{children:t.jsxs("details",{className:"bim-d-mbook",open:n,onToggle:h,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"bim-d-mbook-t",children:l(i.title??i.item)}),t.jsx("span",{className:"bim-d-mbook-n bim-d-ui",children:a("mentions.bookLine",{n:i.count,c:i.chapter_count})})]}),m&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"0 0 8px 40px"},children:a("mentions.loading")}),d&&t.jsx("ul",{className:"bim-d-mchaps",children:d.map(u=>t.jsx("li",{children:o(l0(e,i.item,u),t.jsxs(t.Fragment,{children:[t.jsx("span",{children:u.heading?`${u.chapter} · ${l(u.heading)}`:u.chapter}),t.jsx("span",{className:"bim-d-ui",children:a("mentions.chapterLine",{n:u.count})})]}),"bim-d-mchap")},`${u.key}|${u.chapter}`))})]})})},m0=16,u0=30,Wr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function xl(e){if(!e)return Wr.length;const i=Wr.indexOf(e);return i===-1?Wr.length:i}function p0(e,i,n){if(i)return e[i]??n(i)}function b0(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const h0={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},Ad=({data:e,transport:i,onNavigate:n,renderLink:r,railTop:o,back:a,railLinks:l,assetBase:d})=>{var Je,Pe,Ue,nt,Y,M;const{t:c,convert:m,messages:p}=oe(),h=k=>b0(k,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[v,w]=b.useState("default"),[x,j]=b.useState(new Map),[S,$]=b.useState(0),N=b.useMemo(()=>(e._works||[]).filter(k=>!Qo(k.st)),[e._works]),z=b.useMemo(()=>(e._works||[]).filter(k=>Qo(k.st)),[e._works]),C=b.useMemo(()=>N.map(k=>{const P=x.get(k.work_id);return{id:k.work_id,title:(P==null?void 0:P.title)??k.title??k.work_id,role:k.role||"",cls:ws(k.role),versionCount:P==null?void 0:P.versionCount,section:P==null?void 0:P.cls,l1:P==null?void 0:P.l1,measure:P==null?void 0:P.measure,hasImage:P==null?void 0:P.hasImage,loaded:!!(P!=null&&P.loaded)}}),[N,x]),U=b.useMemo(()=>Bl(N.map(k=>k.role),c("detail.roleAll")),[N,c]),R=b.useMemo(()=>{const k=u==="全部"?C:C.filter(P=>P.cls===u);return v==="versions"?[...k].sort((P,q)=>(q.versionCount??-1)-(P.versionCount??-1)):k},[C,u,v]),L=g?R:R.slice(0,m0),F=b.useMemo(()=>L.filter(k=>!x.has(k.id)).map(k=>k.id),[L,x]);b.useEffect(()=>{if(!i||F.length===0)return;let k=!1;return tr(F,er,P=>i.getItem(P).then(q=>{var xe;const _=q??{},le=_._edition_count??((xe=_._books)==null?void 0:xe.length)??0,H=$s(_),he=[H==null?void 0:H.l1,H==null?void 0:H.l2].filter(Boolean).join(" ");return[P,{id:P,title:_.title,versionCount:le,loaded:!0,cls:he||void 0,l1:(H==null?void 0:H.l1)||void 0,measure:q&&qt(q,p.unit.juan)||void 0,hasImage:!!_._has_image}]}).catch(()=>[P,{id:P,loaded:!0}]),()=>k).then(P=>{k||j(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,F,p.unit.juan]);const T=b.useMemo(()=>{const k=new Map;for(const P of e.alt_names||[]){const q=P.type||p.section.aliases;k.has(q)||k.set(q,[]),k.get(q).push(P.name)}return[...k.entries()].sort((P,q)=>xl(P[0])-xl(q[0])).map(([P,q])=>({label:P,names:q}))},[e.alt_names,p]),Z=((Je=e.dates)==null?void 0:Je.birth)??void 0,O=((Pe=e.dates)==null?void 0:Pe.death)??void 0,ae=(Ue=e.dates)==null?void 0:Ue.floruit,ce=Z!=null||O!=null?`${h(Z)||"?"}—${h(O)||"?"}`:Array.isArray(ae)&&ae.length===2&&ae.every(k=>Number.isFinite(k))?c("entityPage.floruit",{from:h(ae[0]),to:h(ae[1])}):"",Ee=new Set(["本名","字","號","号"]),we=T.filter(k=>Ee.has(k.label)),ye=T.filter(k=>!Ee.has(k.label)),Q=ye.reduce((k,P)=>k+P.names.length,0),Ne=b.useMemo(()=>{const k=[];for(const q of we)k.push({label:q.label,value:q.names.map(_=>m(_)).join("、")});const P=N.length;return P&&k.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:P})}),z.length&&k.push({label:c("entityPage.fact.pieces"),value:c("entityPage.nPian",{n:z.length})}),k},[N,z,we,m,c]),W=k=>{var P;return(P=T.find(q=>k.includes(q.label)))==null?void 0:P.names[0]},je=W(["字"]),K=W(["號","号"]),V=[je?c("entityPage.zi",{name:m(je)}):"",K?c("entityPage.hao",{name:m(K)}):""].filter(Boolean).join(","),re=e.native_place,X=e.dynasty?h0[e.dynasty]:void 0,I=(()=>{if(!X||Z==null||O==null||O<Z)return null;const[k,P]=X,q=Math.max(Z,k),_=Math.min(O,P);if(_<=q)return null;const le=P-k;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c("entityPage.lifeAria",{birth:h(Z),death:h(O),years:O-Z+1}),children:t.jsx("i",{style:{left:`${(q-k)/le*100}%`,width:`${(_-q)/le*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${h(k)} ${m(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:O-Z+1})}),t.jsx("span",{children:h(P)})]})]})})(),ue=b.useMemo(()=>{if(!i||C.length===0||C.some(q=>!q.loaded))return null;const k=new Map;for(const q of C){const _=us(q.l1);_&&k.set(_,(k.get(_)??0)+1)}const P=Yi.map(q=>({...q,n:k.get(q.key)??0})).filter(q=>q.n>0);return P.length?P:null},[C,i]),fe=t.jsxs(tn,{kind:p0(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:V||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",ce,re?c("entityPage.nativePlace",{place:m(re)}):""]}),I,t.jsx(o0,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(nt=e.description)!=null&&nt.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Y=e.description)==null?void 0:Y.text)?6:void 0,facts:Ne,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[Q>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:Q})}),t.jsx("dl",{children:ye.map(k=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{children:k.names.map(P=>m(P)).join("、")})]},k.label))})]}),ue&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ue.map(k=>t.jsx("i",{style:{flexGrow:k.n,background:s.bim(k.token)}},k.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ue.map(k=>t.jsxs("span",{children:[t.jsx("i",{style:{background:s.bim(k.token)}}),m(k.label)," ",k.n]},k.key))})]})]}),ze=b.useMemo(()=>C.filter(k=>k.loaded&&(k.versionCount??0)>0).sort((k,P)=>(P.versionCount??0)-(k.versionCount??0)).slice(0,3),[C]),B=!!i&&C.length>=3&&L.some(k=>!k.loaded),pe=u==="全部"&&(B||ze.length>=2),Te=e.external_ids||{},ve=((M=e.external_ids_meta)==null?void 0:M.cbdb_match)??Te.cbdb_match,Ve=[];Te.cbdb_id!=null&&Ve.push({label:"CBDB",id:String(Te.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${Te.cbdb_id}`,note:ve==="auto"?c("entityPage.autoMatch"):void 0});const qe=Te.wikidata_id;qe&&Ve.push({label:"Wikidata",id:qe,href:`https://www.wikidata.org/wiki/${qe}`});const Xe=Te.viaf_id;Xe&&Ve.push({label:"VIAF",id:Xe,href:`https://viaf.org/viaf/${Xe}`});const J=U.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),ie=e.id?t.jsx(c0,{id:e.id,transport:i,onTotal:$}):null,me=[...pe&&!B?[{id:"featured",label:c("entityPage.sec.featured"),count:ze.length}]:[],...C.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:C.length}]:[],...z.length?[{id:"pieces",label:c("entityPage.sec.pieces"),count:z.length}]:[],...S?[{id:"mentions",label:c("mentions.title"),count:S}]:[],...Ve.length?[{id:"external",label:c("entityPage.sec.external"),count:Ve.length}]:[]],se=pe?t.jsxs(St,{id:"featured",title:c("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":B||void 0,children:[B&&[0,1,2].map(k=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},k)),!B&&ze.map(k=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0})}),t.jsx(vt,{items:[k.section?m(k.section):"",k.measure?m(k.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:k.versionCount}),t.jsx("span",{children:c("entityPage.versionsUnit")}),k.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},k.id))]})]}):null,de=z.length?t.jsx(f0,{pieces:z,onNavigate:n,renderLink:r}):null,ge=C.length===0?t.jsxs(t.Fragment,{children:[de??t.jsx(St,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}),ie]}):t.jsxs(t.Fragment,{children:[se,t.jsxs(St,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:C.length}),R.length!==C.length?c("entityPage.current",{n:R.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[J.length>1&&t.jsx(Qi,{items:J,value:u,onChange:k=>{f(k),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":v==="versions",onClick:()=>{v==="default"&&y(!0),w(k=>k==="default"?"versions":"default")},children:c(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(R.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("entityPage.col.work")}),t.jsx("th",{children:c("entityPage.col.section")}),t.jsx("th",{children:c("entityPage.col.role")}),t.jsx("th",{children:c("entityPage.col.versions")}),t.jsx("th",{"aria-label":c("entityPage.col.image")})]})}),t.jsx("tbody",{children:L.map(k=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0}),k.measure?t.jsx(vt,{items:[m(k.measure)]}):!k.loaded&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.section||k.loaded?"":" bim-d-zt-blank"}`,children:k.section?m(k.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.role?"":" bim-d-zt-blank"}`,children:k.role?m(k.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.loaded?"":" bim-d-zt-blank"}`,children:k.loaded?k.versionCount?c("entityPage.nZhong",{n:k.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("entityPage.notRecorded")}):""}),t.jsx("td",{className:k.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:k.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("entityPage.hasImage")})})]},k.id))})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx(Jn,{total:R.length,shown:L.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),de,ie]}),Oe=Ve.length>0?t.jsx(mi,{id:"external",title:c("entityPage.sec.external"),items:Ve.map(k=>t.jsxs("a",{href:k.href,target:"_blank",rel:"noopener noreferrer",children:[k.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Ve.map(k=>k.id),foot:Te.cbdb_id!=null&&ve==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Zi,{railTop:o,back:a,nav:me,railLinks:l,main:ge,card:fe,side:Oe})};function f0({pieces:e,onNavigate:i,renderLink:n}){const{t:r,convert:o,messages:a}=oe(),[l,d]=b.useState(""),[c,m]=b.useState(!1),p=g=>g?a.workSubtype[g]??o(g):"",h=b.useMemo(()=>{const g=new Map;for(const y of e)g.set(y.st||"",(g.get(y.st||"")??0)+1);return g.size<2?[]:[{key:"",label:`${r("detail.roleAll")} ${e.length}`},...[...g.entries()].sort((y,v)=>v[1]-y[1]).map(([y,v])=>({key:y,label:`${p(y)} ${v}`}))]},[e,r]),u=l?e.filter(g=>(g.st||"")===l):e,f=c?u:u.slice(0,u0);return t.jsxs(St,{id:"pieces",title:r("entityPage.sec.pieces"),meta:t.jsx(vt,{items:[r("entityPage.nPian",{n:e.length}),u.length!==e.length?r("entityPage.current",{n:u.length}):""]}),children:[h.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(Qi,{items:h,value:l,onChange:g=>{d(g),m(!1)}})}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!c&&en(u.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:r("entityPage.piece.title")}),t.jsx("th",{children:r("entityPage.piece.kind")}),t.jsx("th",{children:r("entityPage.col.role")}),t.jsx("th",{"aria-label":r("entityPage.piece.text")})]})}),t.jsx("tbody",{children:f.map(g=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:g.work_id,label:o(g.title??g.work_id),onNavigate:i,renderLink:n,dense:!0})}),t.jsx("td",{className:"bim-d-zt-sub bim-d-zt-nowrap",children:p(g.st)}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${g.role?"":" bim-d-zt-blank"}`,children:g.role?o(g.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:g.txt?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:g.txt&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:r("entityPage.piece.hasText")})})]},g.work_id))})]}),!c&&t.jsx(Jn,{total:u.length,shown:f.length,unit:r("entityPage.piece.moreUnit"),onClick:()=>m(!0)})]})}const co="(max-width: 719px)",g0=`${co}, (pointer: coarse)`,Ld=`
|
|
1560
|
+
${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({key:Ci,data:A,started:!1});else if(A!==Ei.data&&(yo({key:Ci,data:A,started:!!A}),A)){const E=A.pages??[];(!Ei.started||!E.some(G=>G.page===yt))&&bi(ri(A))}b.useEffect(()=>{Ke(new Set),Qe.set(null)},[de,B,Qe]);const dr=Ei.key===Ci&&Ei.started,jo=!!ge&&cs(ge.headings).length===0,ko=b.useMemo(()=>jo&&dr&&A?pd(A.pages,A.punctuations):[],[jo,dr,A]),mr=b.useCallback(E=>{const G=cs(E.headings);return G.length>0?G:E.file===de?ko:[]},[de,ko]),Mm=b.useCallback(E=>{if(Ke(new Set(E)),E.length>0){const G=E[0],be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be)}},[]),Dt=b.useMemo(()=>{const E=new Map;for(const G of(A==null?void 0:A.pages)??[])E.set(G.page,G);return E},[A]),Ri=an(A),Ti=b.useCallback(E=>{var ot;const G=te.images;if(!G||G.length===0)return;const be=(ot=Dt.get(E))==null?void 0:ot.seq;return(be?G.find(mt=>mt.seq===be):void 0)??G.find(mt=>mt.pageNo===E)??G[E-1]},[te.images,Dt]),wo=$t>1.5,ln=b.useCallback((E,G=!1)=>{const be=Ti(E);return be?E===Ri||G?be.hiresUrl??be.url:be.url:E===Ri?(A==null?void 0:A.imageUrl)??"":""},[Ti,A,Ri]),Am=b.useMemo(()=>ln(yt,wo),[ln,yt,wo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((E,G)=>E-G),[Dt]),si=b.useRef(yt);si.current=yt;const ur=b.useRef(0),pr=b.useRef({page:null,timer:null}),Lm=b.useCallback(E=>{const G=pr.current;E!==G.page&&(G.timer&&(clearTimeout(G.timer),G.timer=null),G.page=null,!(E===si.current||Date.now()<ur.current)&&(G.page=E,G.timer=setTimeout(()=>{G.timer=null,G.page=null,!(Date.now()<ur.current||si.current===E)&&(si.current=E,bi(E))},jg)))},[]);b.useEffect(()=>()=>{pr.current.timer&&clearTimeout(pr.current.timer)},[]);const cn=b.useCallback(E=>{var G;si.current===E||!Dt.has(E)||(ur.current=Date.now()+1e3,si.current=E,bi(E),(G=Dt.get(E))!=null&&G.columns.some(be=>be.chars.length>0)&&cr(be=>({page:E,nonce:((be==null?void 0:be.nonce)??0)+1})))},[Dt]),Ii=b.useCallback(E=>{const G=si.current,be=Wt.indexOf(G),ot=Wt[be<0?0:be+E];ot===void 0||ot===G||cn(ot)},[Wt,cn]),vo=b.useCallback(E=>{if(!E.trim().match(/^\d+$/)||Wt.length===0)return null;const be=parseInt(E.trim(),10),ot=Number.isFinite(be)?be:Number.MAX_SAFE_INTEGER;return Wt.reduce((mt,_t)=>Math.abs(_t-ot)<Math.abs(mt-ot)?_t:mt,Wt[0])},[Wt]),[br,hr]=b.useState(null),dn=b.useRef(null),Pm=b.useCallback(E=>{dn.current=E,hr(E)},[]),So=b.useCallback(()=>{const E=dn.current;if(dn.current=null,hr(null),E===null)return;const G=vo(E);G!==null&&cn(G)},[vo,cn]),fr=Wt.indexOf(yt),Om=b.useCallback(E=>{if(E.altKey||E.ctrlKey||E.metaKey)return;const G=E.target.tagName;G==="INPUT"||G==="TEXTAREA"||G==="SELECT"||(E.key==="ArrowLeft"||E.key==="PageUp"?(E.preventDefault(),Ii(-1)):(E.key==="ArrowRight"||E.key==="PageDown")&&(E.preventDefault(),Ii(1)))},[Ii]),$o=b.useRef(null);b.useEffect(()=>{if(!A)return;const E=$o.current;if(!(!E||E.offsetWidth===0))for(const G of yg){const be=ln(yt+G);be&&ss(be)}},[A,yt,ln]);const _o=b.useMemo(()=>{var Do;if(!A)return null;if(yt===Ri)return A;const E=Dt.get(yt);if(E&&E.width>0&&E.height>0)return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[E.width,E.height],total_warped_w:E.width,columns:[{col:1,warped_w:E.width,warped_h:E.height,offset_x:0,strips:[],chars:E.columns.flatMap(ut=>ut.chars).map(ut=>({id:ut.id,char:ut.char,slot:ut.slot,pos:ut.pos,sub:ut.sub,bbox_col:ut.bbox??[0,0,0,0]}))}],...E.columns.some(ut=>ut.kind==="figure"&&ut.figBox)?{figBlocks:E.columns.filter(ut=>ut.kind==="figure"&&ut.figBox).map(ut=>({id:ut.fig,box:ut.figBox}))}:{}};const G=(Do=A.pages)==null?void 0:Do.find(ut=>ut.page===yt),[be,ot]=A.image_size||[2386,3082];if(!(be>0&&ot>0))return null;const mt=Ti(yt),_t=(mt==null?void 0:mt.width)??be,wr=(mt==null?void 0:mt.height)??ot,Fo=_t/be,Bo=wr/ot,Ho=new Map;for(const ut of A.columns){const At=(ut.strips||[]).flatMap(hn=>hn.srcQuad.map(fn=>fn[0]));if(At.length===0)continue;const Ut=ut.top_y??0,vr=ut.bottom_y??Ut+ut.warped_h;Ho.set(ut.col,{x0:Math.min(...At),x1:Math.max(...At),top:Ut,slotH:(vr-Ut)/21})}return{page_id:`p:${yt}`,title:`第${yt}葉`,image_size:[_t,wr],total_warped_w:_t,columns:G?G.columns.map(ut=>{const At=Ho.get(ut.col)??{x0:0,x1:0,top:0,slotH:118};return{col:ut.col,warped_w:_t,warped_h:wr,offset_x:0,strips:[],chars:ut.chars.map(Ut=>{const vr=Ut.slot??Ut.pos??0,hn=(At.top+(vr-1)*At.slotH)*Bo,fn=(At.x0+At.x1)/2,[Zm,Qm]=Ut.sub==="a"?[fn,At.x1]:Ut.sub==="b"?[At.x0,fn]:[At.x0,At.x1];return{...Ut,bbox_col:[Zm*Fo,hn,Qm*Fo,hn+At.slotH*Bo]}})}}):[]}},[A,yt,Ri,Dt,Ti]),{entryTitle:mn,authors:No}=Eg(n,r,m===void 0),[zo,gr]=b.useState("text");b.useEffect(()=>{gr("text")},[de,B]);const Fm=b.useMemo(()=>se?$g(se,et,Za(fe,se),O,Me,mr):[],[se,et,fe,O,Me,mr]),Co=Ph(),Eo=b.useRef(null),Ro=b.useRef(null),xr=b.useMemo(()=>{const E=[];return A&&E.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ye?"bim-rd-on":""}`,"aria-pressed":Ye,title:"切换外挂现代断句标点",onClick:()=>wt(G=>!G),children:Ye?"标点":"无标点"})}}),E},[A,Ye]),Bm=b.useMemo(()=>L&&L.length>0?[...xr,...L]:xr,[xr,L]),Hm=b.useMemo(()=>fe&&ge&&B?{entryId:n,versionKey:B,chapterKey:ge.file,chapter:ge,version:fe,transport:r,viewport:Co}:null,[n,B,ge,fe,r,Co]),Dm=b.useCallback(E=>{de&&k(de,E)},[de,k]),oi=Fh({plugins:Bm,ctx:Hm,prefs:Ce,setPrefs:Ee,t:Z,convert:O,pages:A==null?void 0:A.pages,textRootRef:Eo,shellTextRef:Ro,selectedCharIds:st,scrollToAnchor:Dm});if(W==="loading")return t.jsx(Xa,{className:F,style:T,title:m??mn,label:Z("reader.loading")});if(W==="missing"||!Q||!fe)return t.jsx("div",{className:F,style:{...T,...qa},children:Z("reader.noText")});if(X==="failed")return t.jsx("div",{className:F,style:{...T,...qa},children:Z("reader.tocFailed")});if(!se)return t.jsx(Xa,{className:F,style:T,title:m??mn,label:Z("reader.tocLoading")});const hi=Za(fe,se),Wm=Fm,To=nt&&de&&nt.chapter===de?no(de,nt.anchor):null,Um=To&&ge&&mr(ge).some(E=>E.anchor===nt.anchor)?To:de??null,yr=Q.versions.map(E=>({key:E.key,label:_e.textVersionLabel(E),optionLabel:O(_e.textVersionLabel(E)),sourceName:Qa(E)?Z("reader.originalSource"):E.source_name?O(E.source_name):void 0,license:E.license??void 0,sourceUrl:E.source_url??void 0,primary:E.key===ze})),Mt=vg((Oo=se.source)==null?void 0:Oo.upstream),un=(typeof m=="string"?O(m):m)??(se.title?O(se.title):mn?O(mn):void 0),Io=fe.edition_label?O(fe.edition_label):void 0,jr=un?t.jsx("a",{href:we(n),title:Z("reader.viewEntry"),onClick:d?E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),d(n))}:void 0,children:un}):void 0,Km=jr&&Io?t.jsxs(t.Fragment,{children:[jr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Io]})]}):jr,Ym=No.length>0?O(No.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${` ${E.role||Z("reader.defaultRole")}`}`).join("、")):void 0,kr=ge?fd(ge,hi,O,Me):void 0,ai=Me&&!!(_!=null&&_.json),li=(_==null?void 0:_.json)??null,fi=(_==null?void 0:_.md)??null,Mo=ai&&!ee&&td(li.sections),Gm=Mo&&!(fi&&Ce.readingMode==="paragraph"&&Ln(fi)),Vm=ai&&Mo?t.jsx(pf,{juan:li,view:zo,onView:gr,textHasEntries:Gm}):void 0,qm=!0,pn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,bn=Qa(fe),Xt=bn?Z("reader.originalSource"):fe.source_name?O(fe.source_name):void 0,Xm=(typeof p=="string"?O(p):p)??(bn?void 0:Xt??O(_e.textVersionLabel(fe))),Jm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(bc,{className:F,style:T,title:Km,subtitle:Xm,byline:Ym,current:kr,pagerUnit:hi,rail:Vm,revisedAt:w,backHref:x,backLabel:j,onReportError:v?E=>v({...E,bookTitle:typeof un=="string"?un:void 0,entryId:n}):void 0,workLinkToggle:ai&&!ee&&!!d&&!!(li!=null&&li.sections.some(E=>E.work_id)),toc:Wm,tocCaption:Z("reader.tocCaption",{n:se.chapters.length,unit:O(hi)}),tocHeader:Me&&se.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:ee?Z("reader.searchChaptersPlaceholder"):Z("reader.searchUnitPlaceholder",{unit:O(hi)}),"aria-label":ee?Z("reader.searchChapters"):Z("reader.searchUnit",{unit:O(hi)}),value:He,onChange:E=>ct(E.target.value)}):void 0,activeKey:de??null,tocActiveKey:Um,onSelect:P,images:Rn(ge)&&ne&&!A?null:te.images,renderImageOverlay:f,imagePanel:A||at?"open":g,imagesLoading:lt,isWarpMode:!!A,showPreserveMargins:!it,customImagePanel:A&&_o?t.jsxs("div",{ref:$o,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Om,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",outline:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 4px 6px",fontSize:12,color:s.bim("meta-fg"),gap:8,flexWrap:"wrap"},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:4},children:t.jsx("span",{style:{fontWeight:600,marginRight:4},children:"底本书影"})}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[st.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ke(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${s.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",st.size,")"]}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:2},"data-testid":"facsimile-zoom-tools",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小",title:"缩小",disabled:$t<=1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round($t*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:$t>=6,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:$t===1,onClick:()=>{var E;return(E=dt.current)==null?void 0:E.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(pg,{ref:dt,resetKey:yt,onScaleChange:Ot,style:{flex:1,minHeight:0},children:t.jsx(Ca,{store:Qe,children:E=>{var G;return t.jsx(qs,{imageUrl:Am,pageData:_o,selectedCharIds:st,hoveredCharId:E,decorations:oi.decorations,preserveMargins:Pt,banxinMode:ce.banxinMode,extent:(G=Ti(yt))==null?void 0:G.extent,renderScale:$t,selectedFigBlock:D,onFigBlockClick:be=>ke(be),onCharClick:be=>{ke(null),Ke(mt=>{const _t=new Set(mt);return _t.has(be)?_t.delete(be):(_t.clear(),_t.add(be)),_t});const ot=document.querySelector(`[data-char-id="${be}"]`);ot&&ot.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Qe.set})}})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":Z("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:s.bim("meta-fg")},children:[t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-prev","aria-label":"上一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:fr<=0,onClick:()=>Ii(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":yt,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:s.bim("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":Z("reader.facsimilePageInput"),size:Math.max(2,String(br??yt).length),value:br??String(yt),onFocus:E=>E.currentTarget.select(),onChange:E=>Pm(E.target.value),onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),So()):E.key==="Escape"&&(dn.current=null,hr(null)),E.stopPropagation()},onBlur:So,style:{width:`${Math.max(2,String(br??yt).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${s.bim("rule")}`,borderRadius:4,background:"transparent",color:"inherit"}}),"葉"]}),t.jsx("button",{type:"button",className:"bim-rd-t","data-testid":"facsimile-next","aria-label":"下一葉",style:{minWidth:40,minHeight:40,fontSize:20,lineHeight:1},disabled:fr<0||fr>=Wt.length-1,onClick:()=>Ii(1),children:"›"})]})]}):void 0,pluginSettings:oi.settings,pluginToolbar:oi.toolbar,pluginOverlay:oi.overlay,textRootRef:Ro,prefs:Ce,onPrefsChange:Ee,versions:yr.length>1?yr:void 0,currentVersionKey:yr.length>1?fe.key:void 0,onVersionChange:Je,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Ln(fi),allowVertical:y,origScriptAvailable:Jm,contentLoading:Re,children:[(Re||ne&&!A&&!ai&&pn==null)&&t.jsx(sc,{}),!Re&&A&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:Eo,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:ge!=null&&ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,fe.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]})]})]}),t.jsx(Ca,{store:Qe,children:E=>t.jsx(to,{pageData:A,pages:A.pages,punctuations:A.punctuations||wg,selectedCharIds:st,hoveredCharId:E,onSelectionChange:Mm,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:G,fig:be})=>{Ke(new Set),ke(be),bi(G)},onCharClick:G=>{ke(null),Ke(ot=>{const mt=new Set(ot);return mt.has(G)?mt.delete(G):(mt.clear(),mt.add(G)),mt});const be=parseInt(G.split(":")[0],10);isNaN(be)||bi(be),oi.onCellClick(G)},onCharHover:G=>{Qe.set(G),oi.onCellHover(G)},decorations:oi.decorations,mode:"horizontal",showPunctuation:Ye,entities:rt,entityTransport:r,onEntityNavigate:R,onVisiblePageChange:Lm,convert:O,scrollToPage:zt,scrollToAnchor:Pe&&Pe.chapter===de&&dr?Pe:null,onVisibleHeadingChange:G=>Y(G&&de?{chapter:de,anchor:G}:null),pageBreaks:Ce.pageBreaks,pageIndicatorY:Ce.pageIndicatorY,onPageIndicatorYChange:G=>Ee({pageIndicatorY:G}),quoteStyle:Ce.quoteStyle,bookTitleStyle:Ce.bookTitleStyle,showWorks:Ce.showWorks})})]}),!Re&&!A&&ai&&li&&t.jsx(mf,{juan:li,rawText:fi,positionLabel:zg(ge,se,hi,O),groupLabel:Cg(se,de??null),index:Sg(n,se),searchQuery:He,onNavigate:d,transport:r,workLabelCache:tt,prefs:Ce,view:zo,onViewChange:gr},`${B}/${de}`),!Re&&!A&&!ai&&pn!=null&&ge&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:ge.title?O(ge.title):kr}),(Xt||fe.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[bn&&Xt&&t.jsx(t.Fragment,{children:Xt}),!bn&&fe.source_name&&t.jsxs(t.Fragment,{children:[Z("reader.textSource")," ",fe.source_url?t.jsx("a",{className:"bim-rd-link",href:fe.source_url,target:"_blank",rel:"noreferrer",children:O(fe.source_name)}):O(fe.source_name)]}),Xt&&fe.license&&t.jsx("span",{className:"bim-rd-dot"}),fe.license]}),Mt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[Z("reader.upstream")," ",Mt.url?t.jsx("a",{className:"bim-rd-link",href:Mt.url,target:"_blank",rel:"noreferrer",children:O(Mt.name??Mt.url)}):O(Mt.name??""),Mt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),Mt.license_url?t.jsx("a",{className:"bim-rd-link",href:Mt.license_url,target:"_blank",rel:"noreferrer",children:Mt.license}):Mt.license]}),Mt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(oc,{text:Mt.note,convert:O})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Hs,{text:pn,mode:Ce.readingMode,tables:qm,gujiMarkdown:!0,bookMarking:Bs(Ce),quoteStyle:Ce.quoteStyle})})]}),!Re&&!ne&&!A&&!ai&&pn==null&&ge&&t.jsx("div",{className:"bim-rd-state",children:Z("reader.chapterFailed")}),!Re&&se.references&&se.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:Z("reader.references")}),t.jsx("ol",{children:se.references.map((E,G)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:O(E.title)}):t.jsx("span",{children:O(E.title)}),E.author&&t.jsxs("span",{children:[",",O(E.author)]}),E.note&&t.jsxs("span",{children:["。",O(E.note)]})]},G))})]})]})};function Qa(e){return e.is_original===!0||e.source==="original"}function zg(e,i,n,r){var a,l;if(!e)return;const o=(l=(a=i.juan_metadata)==null?void 0:a[e.file])==null?void 0:l.vol_label;return r(o?`${o}冊`:`${n}${e.n}`)}function Cg(e,i){if(!i)return;const n=r=>{var o;for(const a of r??[]){const l=n(a.children);if(l)return l;if((o=a.files)!=null&&o.includes(i))return a.label}};return n(e.juan_groups)}function Eg(e,i,n){const[r,o]=b.useState({entryTitle:void 0,authors:[]});return b.useEffect(()=>{if(o({entryTitle:void 0,authors:[]}),typeof i.getItem!="function")return;let a=!1;return Promise.resolve(i.getItem(e)).then(l=>{if(a||!l)return;const d=(l.authors??[]).filter(c=>c&&c.name);o({entryTitle:n&&typeof l.title=="string"?l.title:void 0,authors:d})}).catch(()=>{}),()=>{a=!0}},[e,i,n]),r}const Rg=({pageData:e,rawImageUrl:i="",punctuations:n=[],title:r,subtitle:o,onBack:a,className:l="",style:d={}})=>{const[c,m]=b.useState(new Set),[p,h]=b.useState(null),[u,f]=b.useState("horizontal"),[g,y]=b.useState(!0),v=b.useRef(null),w=b.useCallback($=>{m(new Set($))},[]),x=b.useCallback($=>{if(m(N=>{const z=new Set(N);return z.has($)?z.delete($):(z.clear(),z.add($)),z}),v.current){const N=v.current.querySelector(`[data-char-id="${$}"]`);N&&N.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var $;m(new Set),window.getSelection&&(($=window.getSelection())==null||$.removeAllRanges())},S=n.length>0?n:e.punctuations||[];return t.jsxs("div",{className:`guji-reader-container ${l}`,style:d,children:[t.jsxs("header",{className:"guji-reader-header",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&t.jsx("button",{type:"button",onClick:a,className:"guji-reader-btn",style:{marginRight:6},children:"‹ 返回"}),t.jsx("span",{className:"guji-reader-title",children:r||e.title}),o&&t.jsx("span",{style:{fontSize:"0.85rem",color:s.bim("meta-fg")},children:o}),t.jsx("span",{className:"guji-reader-tag",children:"WebGL 客户端透视矫正对读"})]}),t.jsxs("div",{className:"guji-reader-actions",children:[t.jsxs("span",{style:{fontSize:"0.85rem",color:s.bim("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:s.bim("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>y($=>!$),className:`guji-reader-btn ${g?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:g?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f($=>$==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:u==="horizontal"?"切换竖排":"切换横排"})]})]}),t.jsxs("div",{className:"guji-reader-body",children:[t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%",position:"sticky",top:0},children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:"底本书影 (WebGL 分带透视矫正 + 完整版心)"}),t.jsx("span",{className:"guji-pane-hint",children:"点击字框可联动文本定位"})]}),t.jsx("div",{className:"guji-pane-content",children:t.jsx(qs,{imageUrl:i,pageData:e,selectedCharIds:c,hoveredCharId:p,onCharClick:x,onCharHover:h})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:v,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:u==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(to,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:p,onSelectionChange:w,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},Tg=({data:e,onNavigate:i,className:n,style:r})=>{var p;const{t:o,convert:a}=oe(),[l,d]=b.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[c,m]=b.useState(null);return t.jsxs("div",{className:n,style:r,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:s.bim("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:s.bim("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[o("catalog.totalVolumes")," ",t.jsx("strong",{children:e.total_volumes})," ",o("unit.juan")]}),e.stats.zhulu!=null&&t.jsxs("span",{children:[o("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",o("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[o("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",o("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:o("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(h=>t.jsx(Ig,{division:h,expanded:l===h.name,onToggle:()=>d(l===h.name?null:h.name),expandedCat:c,onCatToggle:u=>m(c===u?null:u),onNavigate:i},h.name))})]})},Ig=({division:e,expanded:i,onToggle:n,expandedCat:r,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=oe(),c=e.categories.reduce((m,p)=>{const h=p.stats||{zhulu:0,cunmu:0};return m+(h.zhulu||0)+(h.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:i?`color-mix(in srgb, ${s.bim("primary")} 6%, transparent)`:s.bim("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:s.bim("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:s.bim("desc-fg")},children:[l("catalogPage.divisionStat",{cats:e.categories.length,books:c}),t.jsx("span",{style:{marginLeft:"8px"},children:i?"▲":"▼"})]})]}),i&&t.jsx("div",{style:{padding:"4px 0"},children:e.categories.map(m=>{const p=`${e.name}/${m.name}`;return t.jsx(Mg,{category:m,expanded:r===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},Mg=({category:e,expanded:i,onToggle:n,onNavigate:r})=>{var m,p,h,u;const{t:o,convert:a}=oe(),l=((m=e.books)==null?void 0:m.zhulu)||[],d=((p=e.books)==null?void 0:p.cunmu)||[],c=(((h=e.stats)==null?void 0:h.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:i?s.bim("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:s.bim("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginLeft:"8px",fontWeight:400},children:o("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:[o("catalogPage.booksN",{n:c})," ",i?"▲":"▼"]})]}),i&&(l.length>0||d.length>0)&&t.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[l.length>0&&t.jsx(el,{label:o("catalogPage.zhulu"),books:l,onNavigate:r}),d.length>0&&t.jsx(el,{label:o("catalogPage.cunmu"),books:d,onNavigate:r})]})]})},el=({label:e,books:i,onNavigate:n})=>{const{t:r,convert:o}=oe(),a=It(),[l,d]=b.useState(i.length<=20),c=l?i:i.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color:s.bim("desc-fg"),marginBottom:"4px",fontWeight:500},children:[e," (",i.length,")"]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((m,p)=>t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[t.jsx("span",{style:{fontWeight:500,color:s.bim("fg")},children:m.work_id&&n?t.jsx("a",{href:a(m.work_id),onClick:h=>{h.metaKey||h.ctrlKey||(h.preventDefault(),n(m.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:`1px dashed ${s.bim("link-fg")}`},children:o(m.title)}):o(m.title)}),m.volumes&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.volumes)}),m.author&&t.jsx("span",{style:{fontSize:"11px",color:s.bim("desc-fg")},children:o(m.author).slice(0,20)})]},p))}),!l&&t.jsx("button",{onClick:()=>d(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:s.bim("primary"),background:"transparent",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:r("catalogPage.expandAllN",{n:i.length})})]})};function ro(e="/api/feedback",i){const n=()=>typeof e=="function"?e():e,r=(...o)=>((i==null?void 0:i.fetch)??fetch)(...o);return{async listFeedback(o){try{const l=await(await r(`${n()}?resourceId=${encodeURIComponent(o)}`)).json();return l!=null&&l.success&&Array.isArray(l.items)?l.items:[]}catch{return[]}},async submitFeedback(o){const a=await r(n(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});if(!a.ok){const l=await a.json().catch(()=>null);throw new Error((l==null?void 0:l.error)||(i==null?void 0:i.defaultError)||"submit failed")}}}}function yd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const Ag=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],jd=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:r})=>{const{t:o}=oe(),[a,l]=b.useState(null),[d,c]=b.useState(""),[m,p]=b.useState(""),[h,u]=b.useState("idle"),[f,g]=b.useState(""),y=b.useRef(null);b.useEffect(()=>{e&&(l(null),c(""),p(""),u("idle"),g(""))},[e]),b.useEffect(()=>{a&&setTimeout(()=>{var x;return(x=y.current)==null?void 0:x.focus()},100)},[a]),b.useEffect(()=>{if(h==="success"){const x=setTimeout(i,2e3);return()=>clearTimeout(x)}},[h,i]),b.useEffect(()=>{if(!e)return;const x=j=>{j.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const v=async()=>{if(!(!a||!d.trim())){u("submitting"),g("");try{await n({type:a,content:d.trim(),...m.trim()?{contact:m.trim()}:{}}),u("success")}catch(x){u("error"),g(x instanceof Error?x.message:o("feedback.submitFailedRetry"))}}};if(!e)return null;const w=a&&d.trim()&&h!=="submitting";return t.jsx("div",{style:Lg,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:Pg,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Og,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:Fg,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Ug,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:o("feedback.thanks")}),r&&t.jsx("a",{href:r,style:{fontSize:"13px",color:s.bim("primary"),marginTop:"8px"},children:o("feedback.viewList")})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:Ag.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...Bg,...a===x.value?Hg:{}},children:[t.jsx("span",{children:x.icon})," ",o(`feedback.submitType.${x.value}`)]},x.value))}),t.jsx("textarea",{ref:y,value:d,onChange:x=>c(x.target.value),placeholder:o(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||h==="submitting",style:{...Dg,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:m,onChange:x=>p(x.target.value),placeholder:o("feedback.contactPlaceholder"),maxLength:200,disabled:!a||h==="submitting","aria-label":o("feedback.contactLabel"),style:Yg}),t.jsxs("div",{style:{fontSize:"12px",color:s.bim("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),h==="error"&&t.jsx("div",{style:Kg,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!w,style:{...Wg,opacity:w?1:.6,cursor:w?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},Lg={position:"fixed",top:0,left:0,right:0,bottom:0,background:s.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Pg={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:s.bim("shadow-dialog")},Og={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Fg={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:s.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},Bg={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Hg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Dg={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("input-bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Wg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},Ug={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:s.bim("success")},Kg={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Yg={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},ds="--bim-feedback-fab-offset",ms=48,Gg=16,Vg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:r=!1,zIndex:o})=>{const{t:a}=oe(),[l,d]=b.useState(!1),c=i.bottom??24;return b.useEffect(()=>{if(r||typeof document>"u")return;const m=document.documentElement;return m.style.setProperty(ds,`calc(${c+ms+Gg}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(ds)}},[r,c]),t.jsxs(t.Fragment,{children:[!r&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...qg,zIndex:o??s.bim("feedback-fab-z"),bottom:`calc(${c}px + env(safe-area-inset-bottom, 0px))`,right:i.right},"aria-label":a("feedback.title"),title:a("feedback.title"),children:t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),t.jsx(jd,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},qg={position:"fixed",width:`${ms}px`,height:`${ms}px`,borderRadius:"50%",border:"none",background:s.bim("primary"),color:s.bim("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:s.bim("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Xg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],kd=({onSubmit:e})=>{const{t:i}=oe(),[n,r]=b.useState("bug"),[o,a]=b.useState(""),[l,d]=b.useState(""),[c,m]=b.useState("idle"),[p,h]=b.useState(""),u=b.useRef(null);b.useEffect(()=>{n&&setTimeout(()=>{var y;return(y=u.current)==null?void 0:y.focus()},100)},[n]);const f=async()=>{if(!(!n||!o.trim())){m("submitting"),h("");try{await e({type:n,content:o.trim(),...l.trim()?{contact:l.trim()}:{}}),m("success"),a(""),d(""),r("bug")}catch(y){m("error"),h(y instanceof Error?y.message:i("feedback.submitFailedRetry"))}}},g=n&&o.trim()&&c!=="submitting";return c==="success"?t.jsx("div",{style:tl,children:t.jsxs("div",{style:tx,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:ix,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:tl,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Xg.map(y=>t.jsxs("button",{onClick:()=>r(y.value),style:{...Jg,...n===y.value?Zg:{}},children:[t.jsx("span",{children:y.icon})," ",i(`feedback.submitType.${y.value}`)]},y.value))}),t.jsx("textarea",{ref:u,value:o,onChange:y=>a(y.target.value),placeholder:i(n?`feedback.placeholder.${n}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:c==="submitting",style:{...Qg}}),t.jsx("input",{type:"text",value:l,onChange:y=>d(y.target.value),placeholder:i("feedback.contactPlaceholder"),maxLength:200,disabled:c==="submitting","aria-label":i("feedback.contactLabel"),style:rx}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:s.bim("desc-fg")},children:[o.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!g,style:{...ex,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:nx,children:p})]})},tl={padding:"16px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",background:s.bim("input-bg")},Jg={padding:"8px 16px",fontSize:"13px",border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",background:"transparent",color:s.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Zg={borderColor:s.bim("primary"),background:s.bim("list-active-bg"),color:s.bim("primary"),fontWeight:500},Qg={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ex={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:s.bim("primary"),color:s.bim("primary-fg"),fontWeight:500},tx={display:"flex",alignItems:"center",gap:"12px",color:s.bim("success"),fontSize:"14px"},ix={background:"none",border:"none",color:s.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},nx={fontSize:"13px",color:s.bim("danger"),padding:"8px 12px",background:s.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},rx={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${s.bim("input-border")}`,borderRadius:"6px",background:s.bim("bg"),color:s.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},wd={bug:{key:"bug",color:s.bim("danger")},resource:{key:"resource",color:s.bim("primary")},suggestion:{key:"suggestion",color:s.bim("primary")},other:{key:"other",color:s.bim("desc-fg")}},sx=wd.other,vd={pending:{key:"pending",color:s.bim("warning")},in_progress:{key:"in_progress",color:s.bim("primary")},resolved:{key:"resolved",color:s.bim("success")},wontfix:{key:"wontfix",color:s.bim("desc-fg")},duplicate:{key:"duplicate",color:s.bim("desc-fg")}},ox=vd.pending;function ax(e){try{const i=new Date(e),n=r=>String(r).padStart(2,"0");return`${i.getFullYear()}-${n(i.getMonth()+1)}-${n(i.getDate())} ${n(i.getHours())}:${n(i.getMinutes())}`}catch{return e}}function lx(e,i){if(!e)return!1;try{const n=new URL(e,i);if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const r=new URL(i);return n.hostname===r.hostname}catch{return!1}}const Sd=({items:e,loading:i})=>{const n=It(),{t:r,convert:o}=oe();return i?t.jsx(sc,{}):e.length===0?t.jsx("div",{style:cx,children:r("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=wd[a.type]||sx,d=vd[a.status]||ox,c=typeof window<"u"&&lx(a.pageUrl,window.location.href);return t.jsxs("div",{style:dx,children:[t.jsxs("div",{style:mx,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...il,background:l.color},children:r(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...il,background:d.color},children:r(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:ux,children:ax(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:px,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Fr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Fr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Fr,children:a.pageUrl}))]}),t.jsx("div",{style:bx,children:o(a.content)}),a.reply&&t.jsxs("div",{style:hx,children:[t.jsx("div",{style:fx,children:r("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},cx={textAlign:"center",padding:"40px 0",color:s.bim("desc-fg"),fontSize:"14px"},dx={background:s.bim("bg"),border:`1px solid ${s.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},mx={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},il={fontSize:"12px",color:s.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},ux={fontSize:"12px",color:s.bim("desc-fg")},px={fontSize:"12px",marginBottom:"6px"},Fr={color:s.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${s.bim("primary")}`},bx={fontSize:"14px",lineHeight:"1.6",color:s.bim("fg"),whiteSpace:"pre-wrap"},hx={marginTop:"12px",padding:"10px 12px",background:s.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:s.bim("fg")},fx={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:s.bim("primary")},$d=({resourceId:e,transport:i,apiUrl:n})=>{const{t:r}=oe(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(r);c.current=r;const m=b.useMemo(()=>i??ro(n,{defaultError:c.current("feedback.submitFailed")}),[i,n]),p=b.useCallback(async()=>{d(!0);try{a(await m.listFeedback(e))}catch{}finally{d(!1)}},[e,m]);b.useEffect(()=>{p()},[p]);const h=async u=>{await m.submitFeedback({...u,pageUrl:typeof window<"u"?window.location.href:"",resourceId:e}),setTimeout(()=>p(),500)};return t.jsxs("div",{children:[t.jsx(Sd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(kd,{onSubmit:h})})]})},er=8;async function tr(e,i,n,r){const o=Number.isFinite(i)?Math.max(1,Math.floor(i)):1,a=new Array(e.length);let l=0;const d=Array.from({length:Math.min(o,Math.max(1,e.length))},async()=>{for(;l<e.length&&!(r!=null&&r());){const c=l++;a[c]=await n(e[c],c)}});return await Promise.all(d),a}const gx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function xx(e){const i=e.search(gx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const _d={p:({children:e})=>t.jsx("p",{style:{margin:"0 0 0.5em"},children:e}),ul:({children:e})=>t.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:e}),ol:({children:e})=>t.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:e}),li:({children:e})=>t.jsx("li",{style:{marginBottom:"2px"},children:e}),a:({href:e,children:i})=>{let n=e,r="",o=i;if(e&&typeof i=="string"&&(i===e||i===yx(e))){const[a,l]=xx(i);l&&(n=encodeURI(a),o=a,r=l)}return t.jsxs(t.Fragment,{children:[t.jsx("a",{href:n,target:n!=null&&n.startsWith("http")?"_blank":void 0,rel:n!=null&&n.startsWith("http")?"noopener noreferrer":void 0,style:{color:s.bim("link")},children:o}),r]})},code:({children:e})=>t.jsx("code",{style:{background:s.bim("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function yx(e){try{return decodeURI(e)}catch{return e}}const jx={..._d,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:r})=>{const{convert:o}=xt(),a=i?jx:_d;return t.jsx("div",{className:r,style:n,children:t.jsx(au,{remarkPlugins:[lu],components:a,children:o(e)})})},kx=s.detail["zh-Hant"].relation,wx=s.detail["zh-Hant"].lossStatus,vx=s.detail["zh-Hant"].resourceKind,ir=s.getT("zh-Hant"),so=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function nl(e,i=ir){return e?so(kx,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function Sx(e,i=ir){return so(wx,e)?i(`detail.lossStatus.${e}`):e}function $x(e,i=ir){return so(vx,e)?i(`detail.resourceKind.${e}`):""}function oo({authors:e,onNavigate:i,renderLink:n}){const{convert:r}=oe(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=vs(a.role);return t.jsxs(b.Fragment,{children:[l>0&&" ",a.dynasty&&t.jsxs("span",{className:"bim-d-meta",style:{fontSize:"inherit",marginRight:2},children:["〔",r(a.dynasty),"〕"]}),a.entity_id?t.jsx(jt,{id:a.entity_id,label:r(a.name),onNavigate:i,renderLink:n,dense:!0}):r(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:r(d)})]},l)})}):null}function Nd(e,i,n=ir){var c,m;const r=js(e,i),o=r.mirrors.map(p=>({key:p.key,label:p.label,description:p.description,rows:p.items.filter(h=>h.group_role!=="mirror"),mirrors:p.items.filter(h=>h.group_role==="mirror")})),a=r.buckets.filter(p=>p.key==="image"||p.key==="textImage").flatMap(p=>p.items);a.length&&o.push({key:"_images",label:o.length?n("detail.otherImages"):void 0,rows:a,mirrors:[]});const l=((c=r.buckets.find(p=>p.key==="physical"))==null?void 0:c.items)??[];return l.length&&o.push({key:"_physical",label:n("detail.resourceKind.physical"),rows:l,mirrors:[]}),{text:((m=r.buckets.find(p=>p.key==="text"))==null?void 0:m.items)??[],groups:o}}function zd(e,i){const n=(e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name,r=Pl(e,i);return r?`${n}(${r})`:n}function ao({item:e,siblings:i,listedVolumeCounts:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(!1),d=s.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(zd(e,i)),p=s.resourceHref(e),h=Kn(e,r)||e.details;return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[(()=>{var f,g;const u=(f=e.metadata)!=null&&f.fragment||e.color_mode?t.jsxs("span",{className:"bim-d-tags bim-d-ui",style:{display:"inline-flex",margin:"0 0 0 8px",verticalAlign:"middle"},children:[((g=e.metadata)==null?void 0:g.fragment)&&t.jsx("span",{className:"bim-d-tag",children:r("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?r("colorMode.color"):r("colorMode.bw")})]}):null;return p?t.jsxs("a",{href:p,target:"_blank",rel:"noopener noreferrer",children:[m," ",t.jsx("span",{"aria-hidden":"true",children:"↗"}),u]}):t.jsxs("span",{className:"bim-d-zt-name",children:[m,u]})})(),h&&t.jsx("span",{className:"bim-d-meta",children:o(h)}),c&&a&&t.jsx("div",{style:{padding:"0 12px 10px"},children:t.jsx(As,{item:e})})]}),t.jsx("td",{className:c?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:c&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",style:{marginTop:0},"aria-expanded":a,onClick:()=>l(u=>!u),children:a?r("detail.collapseVolumes"):r("detail.expandVolumes",{n:d.expected})})})]})}function Cd({groups:e,listedVolumeCounts:i}){const{t:n,convert:r}=oe();return t.jsx(t.Fragment,{children:e.map(o=>t.jsxs("div",{className:"bim-d-rg",children:[o.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:r(o.label)}),o.description&&t.jsx("p",{className:"bim-d-rg-d",children:r(o.description)}),o.rows.length>0&&t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:o.rows.map((a,l)=>t.jsx(ao,{item:a,siblings:o.rows,listedVolumeCounts:i},`${a.id||a.url||a.name}-${l}`))})}),o.mirrors.length>0&&t.jsxs("div",{className:"bim-d-rg-mir bim-d-ui",children:[o.rows.length>0&&t.jsx("span",{className:"bim-d-meta",style:{marginRight:10},children:n("detail.mirror")}),o.mirrors.map((a,l)=>{const d=s.resourceHref(a),c=r(zd(a,o.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?r(a.details):void 0,children:[c," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]},l):t.jsx("span",{style:{marginRight:14},children:c},l)})]})]},o.key))})}const Yi=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function us(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Yi.find(r=>i.startsWith(r.key[0])))==null?void 0:n.key}const rl=12,Br=50,_x=60,Ed=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,railTop:a,back:l,railLinks:d})=>{var Je,Pe,Ue,nt,Y;const{t:c,convert:m,messages:p}=oe(),h=b.useMemo(()=>Ss({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[v,w]=b.useState(""),[x,j]=b.useState(!1),S=Math.max(h.length,e._edition_count??0),$=S>Zo&&(h.length>Zo||!!((Je=e._book_groups)!=null&&Je.length)),[N,z]=b.useState({}),C=e._book_groups,[U,R]=b.useState({}),L=b.useRef(new Set),F=b.useMemo(()=>{if(!$)return[];const M={};for(const q of C??[])q.id&&q.title&&(M[q.id]=q.title);const k=Ku(e._books??[],e.version_graph,{titles:M,noHolderFallback:!!C});if(!C)return k;const P=new Map(k.map(q=>[q.key,q]));return C.map(q=>{const _=P.get(q.g);if(_&&_.rows.length>=q.n)return{..._,title:_.title||q.title||""};const le=U[q.g],H=(le==null?void 0:le.rows)??(_==null?void 0:_.rows)??[];return{key:q.g,title:q.g!=="_none"&&(q.title||(_==null?void 0:_.title))||"",rows:H,total:q.n,imageCount:H.filter(he=>he.hasImage).length,pagesLeft:Math.max(0,q.pages-((le==null?void 0:le.loaded)??0))}})},[$,e._books,e.version_graph,C,U]),T=b.useMemo(()=>x?F.map(M=>({...M,rows:M.rows.filter(k=>k.hasImage)})).filter(M=>M.rows.length):F,[F,x]);b.useEffect(()=>{var M;if(!(!$||!(i!=null&&i.getBookGroupPage)))for(const k of F){const P=N[k.key]??0;if(!P||!k.pagesLeft||k.rows.length>=P||L.current.has(k.key))continue;const q=(((M=U[k.key])==null?void 0:M.loaded)??0)+1;L.current.add(k.key),i.getBookGroupPage(e.id,k.key,q).then(_=>{const le=(_??[]).map(H=>Fl(H,e.version_graph));R(H=>{const he=H[k.key];return{...H,[k.key]:{rows:[...(he==null?void 0:he.rows)??[],...le],loaded:q}}})}).catch(()=>R(_=>{var le;return{..._,[k.key]:{rows:((le=_[k.key])==null?void 0:le.rows)??[],loaded:q}}})).finally(()=>L.current.delete(k.key))}},[$,F,N,i,e.id,e.version_graph,U]);const Z=h.length<=_x,O=!$&&(Z||g||!!v||x),ae=b.useMemo(()=>$?T.flatMap(M=>N[M.key]?M.rows.slice(0,N[M.key]).map(k=>k.id):[]):O?h:h.slice(0,rl),[$,T,N,h,O]);b.useEffect(()=>{if(!i||ae.length===0)return;const M=ae.filter(P=>!u.has(P));if(M.length===0)return;let k=!1;return tr(M,er,P=>i.getItem(P).then(q=>{var le;const _=q??{};return[P,{id:P,title:_.title,edition:_.edition,resources:_.resources,publication_info:_.publication_info,current_location:_.current_location,provenance:_.provenance,lineage:_.lineage,related_books:_.related_books,dating:_.dating,measure_info:_.measure_info,summary:zx((le=q==null?void 0:q.description)==null?void 0:le.text)}]}).catch(()=>[P,{id:P}]),()=>k).then(P=>{k||f(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,ae,u]);const ce=b.useMemo(()=>$?[]:h.map(M=>u.get(M)??{id:M}),[$,h,u]),Ee=h.length>0&&h.every(M=>u.has(M)),we=!!i&&ae.some(M=>!u.has(M)),ye=Z||O,Q=b.useMemo(()=>Bl(ce,e.version_graph,{era:v,scanOnly:x,sort:ye?"year":"default"}),[ce,e.version_graph,v,x,ye]),Ne=g?Q.rows:Q.rows.slice(0,rl),W=$?F.reduce((M,k)=>M+k.imageCount,0):Q.allRows.filter(M=>M.hasImage).length,je=Q.allRows.reduce((M,k)=>{var P;return M+(((P=k.copies)==null?void 0:P.length)??0)},0),K=b.useMemo(()=>(e._related||[]).map(M=>({...M,title:M.title??""})),[e._related]),V=K.filter(M=>M.relation==="collected_in"),re=b.useMemo(()=>{const M=new Map;for(const k of e.related_works||[]){if(k.relation!=="collected_in"||M.has(k.id))continue;const P=Ju(k.volume_index,k.order,e.subtype,p.workPage.pos);P&&M.set(k.id,P)}return M},[e.related_works,e.subtype,p.workPage.pos]),J=((Pe=e._contents)==null?void 0:Pe.total)??0,I=b.useMemo(()=>{const M=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],k=P=>{const q=M.indexOf(P??"");return q<0?M.length:q};return K.filter(P=>P.relation!=="collected_in").map((P,q)=>({r:P,i:q})).sort((P,q)=>k(P.r.relation)-k(q.r.relation)||P.i-q.i).map(P=>P.r)},[K]),ue=b.useMemo(()=>{const M=js(e.resources,e.resource_groups);return[...M.mirrors.flatMap(k=>k.items.map(P=>({r:P,kind:m(k.label)}))),...M.buckets.flatMap(k=>k.items.map(P=>({r:P,kind:m($x(k.key,c))})))]},[e.resources,e.resource_groups,m,c]),fe=e.indexed_by||[],ze=e.emendated_by||[],B=b.useMemo(()=>{var he,xe,Re,Ze,Me;const M=[],k=(xe=(he=e.authors)==null?void 0:he[0])==null?void 0:xe.dynasty;k&&M.push({label:c("workPage.fact.written"),value:m(k)});const P=qt(e,p.unit.juan);if(P){const He=((Re=e.juan_count)==null?void 0:Re.description)??((Me=(Ze=e.measures)==null?void 0:Ze.find(ct=>(ct==null?void 0:ct.unit)==="卷"&&ct.note))==null?void 0:Me.note);M.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(P),He&&He!==P?t.jsxs("span",{className:"bim-d-meta",children:["(",m(He),")"]}):null]})})}e.loss_status&&M.push({label:c("workPage.fact.loss"),value:m(Sx(e.loss_status,c))}),e.authenticity==="forged"&&M.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const q=Q.allRows.filter(He=>He.sortYear!=null),_=q.length>0?q.reduce((He,ct)=>He.sortYear<=ct.sortYear?He:ct):null;_!=null&&_.era.era?M.push({label:c("workPage.fact.earliest"),value:m([_.era.era,_.era.reign].filter(Boolean).join(" ")),title:_.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):we&&M.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),ze.length&&M.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:ze.length})});const le=Nx(e.additional_titles);le.length&&M.push({label:c("workPage.fact.alias"),value:le.map(m).join("、")});const H=(e.additional_works||[]).map(He=>m(He.book_title)+(He.n_juan!=null?` ${He.n_juan}${p.unit.juan}`:""));return H.length&&M.push({label:c("workPage.fact.appendix"),value:H.join("、")}),M},[e,m,c,p,we,Q.allRows,ze.length]),Te=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:Ee?W:0,label:c("workPage.stat.hasImage")},{value:fe.length,label:c("workPage.stat.catalogs")}],ve=$s(e),Ve=ve?[ve.l1,ve.l2,ve.l3,ve.l4].filter(Boolean).map(M=>m(M)):[],qe=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",Xe=t.jsx(tn,{title:m(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:n,renderLink:r}),meta:t.jsx(vt,{items:[...Ve,ve!=null&&ve.source?c("workPage.classifiedBy",{source:m(ve.source.split("/")[0])}):"",qe]}),description:(Ue=e.description)!=null&&Ue.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(nt=e.description.sources)!=null&&nt.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(M=>({text:m(Qu(M)),href:ep(M)})).filter(M=>M.text).map((M,k)=>t.jsxs(b.Fragment,{children:[k>0?" · ":null,M.href?t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",children:M.text}):M.text]},k))}):null]}):void 0,stats:Te,facts:B,readAction:o,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Y=e.appendix)==null?void 0:Y.map((M,k)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(M.title)}),t.jsx(zi,{text:M.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},k))}),X=Q.eras.length>=2?[{key:"",label:c("catalog.all")},...Q.eras.map(M=>({key:M,label:`${M} ${Q.allRows.filter(k=>k.era.era===M).length}`}))]:[],ie=[];S&&ie.push({id:"versions",label:c("workPage.sec.versions"),count:S}),fe.length&&ie.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:fe.length}),J&&ie.push({id:"contents",label:c("workPage.sec.contents"),count:J}),V.length&&ie.push({id:"collected",label:c("workPage.sec.collected"),count:V.length}),I.length&&ie.push({id:"related",label:c("workPage.sec.related"),count:I.length}),ue.length&&ie.push({id:"resources",label:c("workPage.sec.resources"),count:ue.length});const me=S===0&&fe.length===0&&!J,se=t.jsxs(t.Fragment,{children:[S>0&&t.jsxs(St,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(vt,{items:[c("workPage.versionsTotal",{n:S-je}),Ee&&W?c("workPage.versionsWithImage",{n:W}):"",Q.rows.length!==Q.allRows.length?c("workPage.versionsCurrent",{n:Q.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":we&&X.length===0&&h.length>1?"":void 0,children:[!$&&X.length>0&&t.jsx(Qi,{items:X,value:v,onChange:M=>{w(M),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(vc,{label:c("workPage.scanOnly"),checked:x,onChange:M=>{j(M),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(ye?"workPage.sortByYear":"workPage.sortByCatalog")})]}),$?t.jsxs("div",{className:"bim-d-groups",children:[t.jsx("div",{className:"bim-d-ui",style:{display:"flex",justifyContent:"flex-end",margin:"4px 0"},children:t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(Object.keys(N).length?{}:Object.fromEntries(T.slice(0,20).map(M=>[M.key,Br]))),children:Object.keys(N).length?c("workPage.groupCollapseAll"):c("workPage.groupExpandAll")})}),T.map(M=>{const k=N[M.key]??0,P=M.rows.slice(0,k);return t.jsxs("details",{open:k>0,onToggle:q=>{const _=q.currentTarget.open;z(le=>{if(_===le[M.key]>0)return le;const H={...le};return _?H[M.key]=Br:delete H[M.key],H})},style:{borderTop:`1px solid ${s.bim("border")}`},children:[t.jsxs("summary",{className:"bim-d-ui",style:{cursor:"pointer",minHeight:40,display:"flex",alignItems:"center",gap:12,padding:"6px 4px"},children:[t.jsx("span",{style:{flex:1},children:m(M.title||c("workPage.groupUngrouped"))}),t.jsx("span",{className:"bim-d-meta",children:c("workPage.groupCount",{n:M.total})}),M.imageCount>0&&t.jsx("span",{className:"bim-d-flag",children:c("workPage.groupImage",{n:M.imageCount})})]}),k>0&&t.jsx("table",{className:"bim-d-zt bim-d-zt-ver",children:t.jsx("tbody",{children:P.map(q=>{const _=u.get(q.id);return t.jsx(sl,{row:q,measure:_==null?void 0:_.measure_info,relations:q.relations??(_?Ol(_):void 0),loaded:!0,onNavigate:n,renderLink:r},q.id)})})}),k>0&&M.total>k&&t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:()=>z(q=>({...q,[M.key]:k+Br})),children:c("workPage.groupMore",{n:M.total-k})})]},M.key)})]}):t.jsxs(t.Fragment,{children:[t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&en(Q.rows.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("workPage.col.edition")}),t.jsx("th",{children:c("workPage.col.era")}),t.jsx("th",{children:c("workPage.col.holder")}),t.jsx("th",{children:t.jsx("span",{style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)"},children:c("workPage.col.image")})})]})}),t.jsx("tbody",{children:Ne.map(M=>{var k;return t.jsx(sl,{row:M,measure:(k=u.get(M.id))==null?void 0:k.measure_info,relations:M.relations,loaded:u.has(M.id),onNavigate:n,renderLink:r},`${M.id}:${u.has(M.id)?"r":"p"}`)})})]}),Ne.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(v||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx(Jn,{total:Q.rows.length,shown:Ne.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)})]}),Q.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),fe.length>0&&t.jsx(Ex,{items:fe,transport:i,onNavigate:n,renderLink:r}),J>0&&e._contents&&t.jsx(Rx,{workId:e.id,info:e._contents,transport:i,onNavigate:n,renderLink:r}),me&&t.jsx(St,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),de=(M,k)=>t.jsx(jt,{id:M,label:m(k),onNavigate:n,renderLink:r,dense:!0}),ge=b.useMemo(()=>{const M=new Map;for(const k of I){const P=nl(k.relation,c);M.set(P,(M.get(P)??0)+1)}return M.size>1?[...M.entries()].sort((k,P)=>P[1]-k[1]).slice(0,4).map(([k,P])=>`${m(k)} ${P}`).join(" · "):void 0},[I,m,c]),Oe=t.jsxs(t.Fragment,{children:[t.jsx(mi,{id:"collected",title:c("workPage.sec.collected"),items:V.map(M=>de(M.id,M.title)),metas:V.map(M=>re.get(M.id)??"")}),t.jsx(mi,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:I.length}),sub:ge,items:I.map(M=>t.jsxs(t.Fragment,{children:[de(M.id,M.title),t.jsx("span",{className:"bim-d-meta",title:M.note?m(M.note):void 0,children:m(nl(M.relation,c))})]}))}),t.jsx(mi,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:ue.map(({r:M,kind:k})=>{const P=m((M.url?s.getDisplayNameFromUrl(M.url):void 0)||M.name),q=s.resourceHref(M);return t.jsxs(t.Fragment,{children:[q?t.jsxs("a",{href:q,target:"_blank",rel:"noopener noreferrer",children:[P," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:P}),k&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:k})]})})})]});return t.jsx(Zi,{railTop:a,back:l,nav:ie,railLinks:d,main:se,card:Xe,side:Oe})};function Nx(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function ps(e,i){return i((e.url?s.getDisplayNameFromUrl(e.url):void 0)||e.name)}function zx(e){var a;if(!e)return;const n=e.replace(/\*\*/g,"").split(/\n/)[0].trim().match(/[^。]+。?/g)??[],o=((n.length>1&&((a=n[0])!=null&&a.startsWith("《"))?n[1]:n[0])??"").trim();return o?o.length>120?`${o.slice(0,120)}…`:o:void 0}function Cx({copies:e,onNavigate:i,renderLink:n}){const{t:r,convert:o}=oe(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?ps(l.holders[0],o):"")||"",c=a.get(d)??[];c.push(l),a.set(d,c)}return t.jsxs("span",{className:"bim-d-zt-copies",children:[r("workPage.sameEditionCopies",{n:e.length}),[...a].map(([l,d],c)=>t.jsxs(b.Fragment,{children:[c>0?";":"",l?`${o(l)} `:"",d.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0?" · ":"",t.jsx(jt,{id:m.id,label:m.callNumber||m.id,onNavigate:i,renderLink:n,dense:!0})]},m.id))]},l||c))]})}function sl({row:e,measure:i,relations:n,loaded:r,onNavigate:o,renderLink:a}){const{t:l,convert:d}=oe(),c=[e.era.era,e.era.reign].filter(Boolean).join(" "),m=e.era.source==="edition",p=e.holders[0],h=e.copies??[],u=h.length&&e.locationName?d(e.locationName):p?ps(p,d):e.locationName?d(e.locationName):"",f=e.images[0],g=f?s.resourceHref(f):void 0,y=e.images.map(v=>ps(v,d)).join("、");return t.jsxs("tr",{"data-loading":r?void 0:"",className:h.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:h.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(jt,{id:e.id,label:d(e.name),onNavigate:o,renderLink:a,dense:!0}),i?t.jsx("span",{className:"bim-d-meta",children:d(i)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}),n&&n.length>0&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:n.map((v,w)=>t.jsxs(b.Fragment,{children:[w>0?" · ":null,d(l("workPage.relationWith",{relation:v.relation,n:v.ids.length}))]},v.relation))}),h.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:d(e.summary)}),h.length>0&&t.jsx(Cx,{copies:h,onNavigate:o,renderLink:a})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${c?"":" bim-d-zt-blank"}`,title:m?l("workPage.inferredFromEdition"):void 0,children:c?d(c):r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${u?"":" bim-d-zt-blank"}`,children:[u||(r?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),h.length>0&&e.callNumber&&t.jsx("span",{className:"bim-d-meta",style:{display:"block",fontSize:12},children:e.callNumber}),e.holders.length>1&&t.jsxs("span",{className:"bim-d-meta",children:[" +",e.holders.length-1]})]}),t.jsx("td",{className:e.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:e.hasImage&&(g?t.jsx("a",{className:"bim-d-flag",href:g,target:"_blank",rel:"noopener noreferrer",title:y,children:l("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:y,children:l("workPage.hasImage")}))})]})}function Ex({items:e,transport:i,onNavigate:n,renderLink:r}){const{t:o,convert:a}=oe(),{items:l,groups:d}=b.useMemo(()=>{const f=[],g=new Map;for(const y of e){const v=`${y.source}\0${y.source_bid??""}`,w=g.get(v);w?w.push(y):(g.set(v,[y]),f.push(y))}return{items:f,groups:f.map(y=>g.get(`${y.source}\0${y.source_bid??""}`))}},[e]),[c,m]=b.useState(0),p=Math.min(c,l.length-1);l[p];const[h,u]=b.useState(new Map);return b.useEffect(()=>{if(!i)return;const f=[...new Set(l.map(y=>y.source_bid).filter(y=>!!y))];if(f.length===0)return;let g=!1;return Promise.all(f.map(y=>i.getItem(y).then(v=>{var w,x;return[y,((x=(w=v==null?void 0:v.authors)==null?void 0:w[0])==null?void 0:x.dynasty)??""]}).catch(()=>[y,""]))).then(y=>{g||u(new Map(y.filter(([,v])=>v)))}),()=>{g=!0}},[i,l]),t.jsx(St,{id:"catalogs",title:o("workPage.sec.catalogs"),meta:t.jsx(vt,{items:[o("workPage.catalog.meta",{n:l.length}),o("workPage.sortByCatalog")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":o("workPage.catalog.tablist"),children:l.map((f,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===p,"aria-label":a(f.source),onClick:()=>m(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:h.get(f.source_bid??"")?a(h.get(f.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...a(f.source)].slice(0,9).map((y,v)=>t.jsx("span",{children:y},v))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d[p].map((f,g)=>t.jsxs("div",{className:"bim-d-lu-entry",children:[f.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(f.title_info)}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[f.source_bid?t.jsx(jt,{id:f.source_bid,label:a(f.source),onNavigate:n,renderLink:r,dense:!0}):a(f.source),f.section?a(f.section):"",f.author_info?`${o("label.authorInfo")} ${a(f.author_info)}`:"",f.edition?`${o("label.edition")} ${a(f.edition)}`:"",f.page??""]}),f.summary&&t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.summary),void 0,{t:o})}),f.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.comment),void 0,{t:o})})]}),f.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.additional_comment),void 0,{t:o})})]}),!f.summary&&!f.comment&&!f.additional_comment&&!f.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:o("workPage.catalog.titleOnly")})]},g)),l.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[p>0?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.prev",{name:a(l[p-1].source)}),onClick:()=>m(p-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(l[p-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[p+1," / ",l.length]}),p<l.length-1?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.next",{name:a(l[p+1].source)}),onClick:()=>m(p+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(l[p+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}function Rx({workId:e,info:i,transport:n,onNavigate:r,renderLink:o}){const{t:a,convert:l}=oe(),[d,c]=b.useState(1),[m,p]=b.useState(null),[h,u]=b.useState(!1),f=!!(n!=null&&n.getWorkContents);b.useEffect(()=>{if(!(n!=null&&n.getWorkContents))return;let y=!1;return p(null),u(!1),n.getWorkContents(e,d).then(v=>{y||(v?p(v):u(!0))}).catch(()=>{y||u(!0)}),()=>{y=!0}},[n,e,d]);const g=i.pages>1?t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d<=1,onClick:()=>c(y=>y-1),children:a("workPage.contents.prev")}),t.jsx("span",{className:"bim-d-meta",children:a("workPage.contents.page",{page:d,pages:i.pages})}),t.jsx("button",{type:"button",className:"bim-d-tab",disabled:d>=i.pages,onClick:()=>c(y=>y+1),children:a("workPage.contents.next")})]}):null;return t.jsxs(St,{id:"contents",title:a("workPage.sec.contents"),meta:t.jsx(vt,{items:[a("workPage.contents.meta",{n:i.total})]}),children:[f&&g,f&&!m&&!h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.loading")}),f&&h&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:a("workPage.contents.error")}),m&&m.length>0&&t.jsxs("table",{className:"bim-d-zt",children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:a("workPage.contents.vol")}),t.jsx("th",{children:a("workPage.contents.title")}),t.jsx("th",{children:a("workPage.contents.author")})]})}),t.jsx("tbody",{children:m.map((y,v)=>{var j,S;const w=Gr(y.vol),x=v>0?Gr(m[v-1].vol):null;return t.jsxs("tr",{children:[t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w&&w!==x?"":" bim-d-zt-blank"}`,children:w&&w!==x?w:null}),t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:y.id,label:l(y.title??y.id),onNavigate:r,renderLink:o,dense:!0})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${(j=y.au)!=null&&j.length?"":" bim-d-zt-blank"}`,children:(S=y.au)!=null&&S.length?l(y.au.join("、")):null})]},y.id)})})]}),f&&m&&g]})}const Rd=({graph:e,renderLink:i,className:n,style:r})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Kx,...r},className:n,children:o("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const g=l.get(f.target)??[];g.push(f),l.set(f.target,g)}else for(const g of[f.source,f.target]){const y=d.get(g)??[];y.push(f),d.set(g,y)}const c=new Map(e.nodes.map(f=>[f.id,f])),m=new Map,p=[];for(const f of e.nodes)if(f.group){const g=m.get(f.group)??[];g.push(f),m.set(f.group,g)}else p.push(f);const h=(f,g)=>(f.year??9999)-(g.year??9999);m.forEach(f=>f.sort(h)),p.sort(h);const u=e.groups.filter(f=>m.has(f.id));return t.jsxs("div",{className:n,style:{...Ix,...r},children:[e.title&&t.jsx("div",{style:Mx,children:a(e.title)}),e.description&&t.jsx("div",{style:Ax,children:a(e.description)}),u.map(f=>t.jsx(ol,{label:f.label,color:f.color,nodes:m.get(f.id),incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i},f.id)),p.length>0&&t.jsx(ol,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},ol=({label:e,color:i,nodes:n,incomingMap:r,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:Lx,children:[t.jsx("div",{style:{...Px,borderLeftColor:i??s.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(Tx,{node:c,incoming:r.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},Tx=({node:e,incoming:i,siblings:n,nodeMap:r,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=oe();return t.jsxs("div",{style:{...Ox,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?s.bim("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:Fx,children:[t.jsx("span",{style:Bx,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Hx,children:Il(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:Dx,children:[e.category&&t.jsx(Pi,{children:c(e.category)}),e.status==="lost"&&t.jsx(Pi,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Pi,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Pi,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Pi,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Wx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ux,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:ll,children:[t.jsx("div",{style:cl,children:d("lineage.sources")}),i.map(m=>{const p=r.get(m.source);return t.jsxs("div",{style:dl(m.confidence),children:[t.jsx("span",{style:ml,children:c(m.relation)}),t.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&o?o(p.id,c(p.label)):c((p==null?void 0:p.label)??m.source)}),m.confidence!=="consensus"&&m.confidence!=="certain"&&t.jsx(al,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:ul,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:ll,children:[t.jsx("div",{style:cl,children:d("lineage.related")}),n.map(m=>{const p=m.source===e.id?m.target:m.source,h=r.get(p);return t.jsxs("div",{style:dl(m.confidence),children:[t.jsx("span",{style:ml,children:c(m.relation)}),t.jsx("span",{children:(h==null?void 0:h.kind)==="book"&&o?o(h.id,c(h.label)):c((h==null?void 0:h.label)??p)}),t.jsx(al,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:ul,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Pi=({children:e,tone:i="default"})=>{const r={default:{bg:s.bim("tag-bg"),fg:s.bim("fg")},warn:{bg:s.bim("warn-bg"),fg:s.bim("warn-fg")},info:{bg:s.bim("info-bg"),fg:s.bim("info-fg")}}[i];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:e})},al=({level:e})=>{const{t:i}=oe(),r={certain:{key:"certain",color:s.bim("confidence-certain")},consensus:{key:"consensus",color:s.bim("confidence-consensus")},probable:{key:"probable",color:s.bim("confidence-probable")},disputed:{key:"disputed",color:s.bim("confidence-disputed")}}[e];return r?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${r.color}`,color:r.color,borderRadius:"8px",marginLeft:"4px"},children:i(`lineage.confidence.${r.key}`)}):null},Ix={fontSize:"14px",color:s.bim("fg")},Mx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ax={fontSize:"13px",color:s.bim("muted"),marginBottom:"16px",lineHeight:1.6},Lx={marginBottom:"16px"},Px={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:s.bim("fg")},Ox={border:`1px solid ${s.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:s.bim("bg")},Fx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Bx={fontSize:"15px",fontWeight:600},Hx={fontSize:"12px",color:s.bim("muted")},Dx={marginBottom:"6px"},Wx={fontSize:"12px",color:s.bim("muted"),margin:"2px 0"},Ux={fontSize:"12px",color:s.bim("muted"),fontStyle:"italic",margin:"4px 0"},ll={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${s.bim("widget-border")}`},cl={fontSize:"11px",color:s.bim("muted"),marginBottom:"2px"},dl=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),ml={display:"inline-block",padding:"0 6px",fontSize:"11px",background:s.bim("tag-bg"),color:s.bim("fg"),borderRadius:"3px",marginRight:"6px"},ul={fontSize:"11px",color:s.bim("muted")},Kx={padding:"20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px"},Td=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[r,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Yx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),r==="loading"?t.jsx("div",{style:bl,children:n("lineage.graphLoading")}):r==="missing"||!a?t.jsxs("div",{style:bl,children:[t.jsx("div",{children:pl(n("lineage.graphMissing"),{xyflow:t.jsx("code",{children:"@xyflow/react"}),dagre:t.jsx("code",{children:"@dagrejs/dagre"})})}),t.jsx("div",{style:{fontSize:"12px",marginTop:"4px"},children:pl(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Gx,{modules:a,selectedNodeId:e,...i})};function pl(e,i){return e.split(/(\{\w+\})/).map((n,r)=>{const o=/^\{(\w+)\}$/.exec(n);return t.jsx(b.Fragment,{children:o&&o[1]in i?i[o[1]]:n},r)})}async function Yx(){try{const[e,i]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let n=!1;try{await import("@xyflow/react/dist/style.css"),n=!0}catch{n=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:i,cssLoaded:n}}catch{return null}}const Gx=({graph:e,renderLink:i,height:n=600,className:r,style:o,selectedNodeId:a,modules:l})=>{const{ReactFlow:d,Background:c,Controls:m,Handle:p,Position:h,BaseEdge:u,EdgeLabelRenderer:f,getSmoothStepPath:g,dagre:y}=l,v=b.useMemo(()=>({lineage:N=>{var ae,ce,Ee,we;const z=((ae=N.data)==null?void 0:ae.stepPosition)??.85,[C,U,R]=g({sourceX:N.sourceX,sourceY:N.sourceY,sourcePosition:N.sourcePosition,targetX:N.targetX,targetY:N.targetY,targetPosition:N.targetPosition,stepPosition:z,borderRadius:5}),L=!!((ce=N.data)!=null&&ce.isSibling),F=L?U:N.targetX-18,T=L?R:N.targetY-12,Z=(Ee=N.data)==null?void 0:Ee.labelStyle,O=(we=N.data)==null?void 0:we.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:N.id,path:C,style:N.style,markerStart:N.markerStart,markerEnd:N.markerEnd}),N.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${F}px,${T}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:s.bim("bg"),border:`0.5px solid ${s.bim("widget-border")}`,...O,...Z},children:N.label})})]})}}),[u,f,g]),w=b.useMemo(()=>({version:N=>{const{t:z}=oe(),C=N.data,U=C.kind==="hypothetical",R=C.status==="lost",L=C.isSelected,F=C.bridge,T=C.borderColor??s.bim("muted"),Z=F||U?"dashed":"solid",O=F?.5:R?.6:1;return t.jsxs("div",{style:{background:F?s.bim("bg-subtle"):s.bim("bg"),border:`2px ${Z} ${L?s.bim("primary"):T}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:L?s.bim("shadow-node-selected"):U||F?"none":s.bim("shadow-node")},title:F?z("lineage.bridgeTitle"):void 0,children:[t.jsx(p,{type:"target",position:h.Left,style:{visibility:"hidden"}}),t.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:U||!C.renderLink?C.label:C.renderLink(C.bookId,C.label)}),C.description&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:C.description}),C.yearText&&t.jsx("div",{style:{fontSize:10,color:s.bim("aux-fg"),lineHeight:1.2},children:Il(C.yearText,void 0,C.uncertain)}),R&&t.jsx("div",{style:{fontSize:9,color:s.bim("lost-fg"),marginTop:1},children:z("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=oe(),{rfNodes:j,rfEdges:S}=b.useMemo(()=>Vx(e,y,i,a,x),[e,y,i,a,x]);return t.jsx("div",{style:{width:"100%",height:n,...o},className:r,children:t.jsxs(d,{nodes:j,edges:S,nodeTypes:w,edgeTypes:v,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(m,{showInteractive:!1})]})})};function Vx(e,i,n,r,o=a=>a??""){const d=e.layout==="LR"||!e.layout,c=new i.graphlib.Graph;c.setGraph({rankdir:d?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),c.setDefaultEdgeLabel(()=>({}));const m=new Map(e.groups.map(w=>[w.id,w.color??s.bim("muted")]));for(const w of e.nodes)c.setNode(w.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const w of e.edges)w.kind==="derive"&&(p.has(w.relation)||c.setEdge(w.source,w.target));i.layout(c);const h=e.nodes.map(w=>{const x=c.node(w.id),j=r?w.id===r:void 0,S={kind:w.kind,label:o(w.label),bookId:w.kind==="book"?w.id:void 0,yearText:o(w.year_text??Xx(w)),uncertain:w.year_uncertain,category:w.category,status:w.status,borderColor:w.group?m.get(w.group):void 0,renderLink:n,isSelected:j,description:o(w.description),bridge:w.bridge};return{id:w.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:S,draggable:!1,selected:j}}),u=.78,f=.06,g=new Map;for(const w of e.edges)w.kind==="derive"&&(g.has(w.source)||g.set(w.source,[]),g.get(w.source).push(w));const y=new Map;for(const[w,x]of g){if(x.length<=1)continue;const j=[...x].sort(($,N)=>{var U,R;const z=((U=c.node($.target))==null?void 0:U.y)??0,C=((R=c.node(N.target))==null?void 0:R.y)??0;return z-C}),S=j.length;j.forEach(($,N)=>{const z=(N-(S-1)/2)*f;y.set($.id,u+z)})}const v=e.edges.map(w=>qx(w,y.get(w.id),o));return{rfNodes:h,rfEdges:v}}function qx(e,i,n=r=>r??""){const r=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Jx(e.confidence),l={type:"arrowclosed",color:a,width:14,height:14};return{id:e.id,source:e.source,target:e.target,type:"lineage",label:n(e.relation),data:{labelStyle:{color:s.bim("fg")},isSibling:o,stepPosition:i},style:{stroke:a,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:o?l:void 0,zIndex:1e3}}function Xx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Jx(e){switch(e){case"certain":return s.bim("confidence-certain");case"consensus":return s.bim("lineage-edge-consensus");case"probable":return s.bim("confidence-probable");case"disputed":return s.bim("confidence-disputed");default:return s.bim("muted")}}const bl={padding:"40px 20px",textAlign:"center",color:s.bim("muted"),fontSize:"13px",border:`1px dashed ${s.bim("widget-border")}`,borderRadius:8,background:s.bim("bg")},lo=({graph:e,defaultMode:i="list",renderLink:n,graphHeight:r=600,selectedNodeId:o,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:m,className:p,style:h})=>{var S;const{t:u,convert:f}=oe(),[g,y]=b.useState(i),v=$=>{y($),a==null||a($)},w=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&w.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:s.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:p,style:h,children:[t.jsxs("div",{style:Zx,children:[t.jsx("button",{onClick:()=>v("list"),style:Hr(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>v("graph"),style:Hr(g==="graph"),children:u("lineage.modeGraph")}),x&&t.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12,color:s.bim("muted"),marginRight:4},children:u("lineage.collectionLabel")}),w.map(([$,N])=>{const z=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Hr(l===$),title:N.description?f(N.description):void 0,children:[f(N.label),z!=null?` ${z}`:""]},$)})]})]}),x&&j&&t.jsx("div",{style:{fontSize:12,color:s.bim("muted"),marginBottom:8,padding:"4px 8px",background:s.bim("bg-subtle"),borderRadius:4},children:f(j)}),g==="list"?t.jsx(Rd,{graph:e,renderLink:n}):t.jsx(Td,{graph:e,renderLink:n,height:r,selectedNodeId:o})]})},Zx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Hr=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${s.bim("widget-border")}`,borderRadius:4,background:e?s.bim("primary"):"transparent",color:e?s.bim("primary-fg"):s.bim("fg"),cursor:"pointer"}),hl=40,fl=2,Qx=9,e0=new Set(["certain","consensus","probable","disputed"]);function Dr(e){if(!e)return["",""];const i=e.split(/[ ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const Id=({data:e,transport:i,onNavigate:n,renderLink:r,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Oe,Je,Pe,Ue,nt,Y,M,k,P,q;const h=s.useT(),{t:u,convert:f}=oe(),[g,y]=b.useState(null),[v,w]=b.useState(new Map),[x,j]=b.useState([]),[S,$]=b.useState(new Map),[N,z]=b.useState(!1),[C,U]=b.useState("flow"),[R,L]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let _=!1;return i.getItem(e.work_id).then(le=>{!_&&le&&le.type==="work"&&y(le)}).catch(()=>{}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){L(null);return}let _=!1;return i.getLineageGraph(e.work_id).then(le=>{_||L(le&&le.nodes.length>1?le:null)}).catch(()=>{_||L(null)}),()=>{_=!0}},[i,e.work_id]),b.useEffect(()=>{const _=e._collections||[];if(!i||_.length===0){w(new Map);return}let le=!1;return Promise.all(_.map(H=>{const he=H.id;return i.getItem(he).then(xe=>[he,xe]).catch(()=>[he,null])})).then(H=>{if(le)return;const he=new Map;for(const[xe,Re]of H)Re&&he.set(xe,Re);w(he)}),()=>{le=!0}},[i,e._collections]);const F=b.useMemo(()=>{const _=new Set([...g?Ss(g):[],...Su(e)]);return _.add(e.id),[..._]},[g,e.related_books,e.id]),T=F.length-1;b.useEffect(()=>{if(!i||T<=0){j([]);return}const _=F.length<=hl,le=_?F:F.slice(0,8);let H=!1;return Promise.all(le.map(he=>he===e.id?Promise.resolve({id:he,title:e.title,edition:e.edition,year:Mn(e)}):i.getItem(he).then(xe=>{const Re=xe??{};return{id:he,title:Re.title,edition:Re.edition,year:xe?Mn(Re):void 0}}).catch(()=>({id:he})))).then(he=>{if(H)return;const xe=he.filter(Re=>Re.id===e.id||Re.title||Re.edition);_&&xe.sort((Re,Ze)=>(Re.year??1/0)-(Ze.year??1/0)),j(xe)}),()=>{H=!0}},[i,F,T,e]),e.lineage;const Z=b.useMemo(()=>[...Vt(e).filter(_=>_.ref_type==="book").map(_=>_.ref),...ti(e).map(_=>_.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||Z.length===0){$(new Map);return}let _=!1;return Promise.all(Z.map(le=>i.getItem(le).then(H=>[le,{id:le,title:H==null?void 0:H.title,edition:H==null?void 0:H.edition}]).catch(()=>[le,{id:le}]))).then(le=>{_||$(new Map(le))}),()=>{_=!0}},[i,Z]);const O=b.useMemo(()=>Nd(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),ae=O.groups.reduce((_,le)=>_+le.rows.length+le.mirrors.length,0),ce=O.groups.length>0&&O.groups.every(_=>_.key==="_physical"),Ee=Ji(e),we=Kl(e),ye=qt(e,h.unit.juan),Q=new Set((e._collections||[]).map(_=>Wi(_.vol).length).filter(_=>_>0)),Ne=_=>{var he;const le=(he=e.base_edition)==null?void 0:he.find(xe=>xe.book_id===_&&xe.name);if(le!=null&&le.name)return le.name;const H=S.get(_);return(H==null?void 0:H.edition)||(H==null?void 0:H.title)||""},W=b.useMemo(()=>{var He,ct;const _=[];we&&_.push({label:u("bookPage.fact.editionType"),value:f(we),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(He=e.publication_info)!=null&&He.details?_.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(Ee.era||Ee.reign)&&_.push({label:u("bookPage.fact.era"),value:f([Ee.era,Ee.reign].filter(Boolean).join(" ")),title:Ee.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),ye&&_.push({label:u("bookPage.fact.measure"),value:f(ye)});const le=(e._collections||[]).flatMap(Be=>Wi(Be.vol));le.length&&_.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Yn(le,h.unit.volume),unit:h.unit.volume,n:le.length})});const H=Vt(e).find(Be=>Be.relation==="底本"&&Be.ref_type==="book");H&&Ne(H.ref)&&_.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(jt,{id:H.ref,label:f(Ne(H.ref)),onNavigate:n,renderLink:r,dense:!0})});const he=(e.base_edition||[]).filter(Be=>Be&&Be.name);for(const Be of["底本","配補","參校"]){if(Be==="底本"&&H&&Ne(H.ref))continue;const ee=he.filter(Se=>Se.role===Be);ee.length&&_.push({label:f(Be),value:ee.map((Se,et)=>t.jsxs(b.Fragment,{children:[et>0&&"、",Se.book_id?t.jsx(jt,{id:Se.book_id,label:f(Se.name),onNavigate:n,renderLink:r,dense:!0}):f(Se.name)]},et))})}const xe=(e.provenance||[]).filter(Be=>Be&&Be.institution),Re=(e.resources||[]).filter(Be=>s.getResourceTypes(Be).includes("physical"));if(xe.length){_.push({label:u("bookPage.fact.holdings"),value:xe.slice(0,2).map(Se=>f(Se.institution)).join("、")+(xe.length>2?u("bookPage.andMorePlaces",{n:xe.length}):"")});const Be=xe.filter(Se=>Se.call_number).slice(0,2).map(Se=>`${f(Se.institution)} ${Se.call_number}`);Be.length&&_.push({label:u("bookPage.fact.callNumber"),value:Be.join(";")+(xe.filter(Se=>Se.call_number).length>2?"…":"")});const ee=xe.flatMap(Se=>Se.seals||[]).filter(Boolean);ee.length&&_.push({label:u("bookPage.fact.seals"),value:f(ee.join("、"))})}else Re.length&&_.push({label:u("bookPage.fact.holdings"),value:Re.slice(0,2).map(Be=>f(Be.name)).join("、")+(Re.length>2?u("bookPage.andMorePlaces",{n:Re.length}):"")});const Ze=e.physical_description;if(Ze){const Be=[[u("bookPage.fact.leafStyle"),Ze.leaf_style],[u("bookPage.fact.binding"),Ze.binding],[u("bookPage.fact.dimensions"),Ze.dimensions],[u("bookPage.fact.condition"),Ze.condition]];for(const[ee,Se]of Be)Se&&Se.trim()&&_.push({label:ee,value:f(Se)})}(ct=e.page_count)!=null&&ct.description&&_.push({label:h.label.pageCount,value:f(e.page_count.description)});const Me=Ac(e.additional_titles);return Me.length&&_.push({label:u("bookPage.fact.aliases"),value:Me.map(f).join("、")}),_},[e,f,h,u,Ee,we,ye,S,n,r]),je=f(e.title),K=e.edition?f(e.edition):void 0,V=((Oe=e.dating)==null?void 0:Oe.text)||"",re=t.jsx(tn,{kind:u("bookPage.kind"),title:je,subtitle:K,byline:t.jsx(oo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:r}),meta:(()=>{const _=[we?f(we):"",Ee.era?f([Ee.era,Ee.reign].filter(Boolean).join("")):"",ye?f(ye):""].filter(Boolean);return _.length?t.jsx("span",{className:"bim-d-tags",children:_.map((le,H)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(H,2)}`,children:le},H))}):null})(),description:(Je=e.description)!=null&&Je.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Pe=e.description)==null?void 0:Pe.text)?6:void 0,facts:W,readAction:o,secondaryAction:o&&ae>0&&!ce?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),J=e._collections||[],I=(a==null?void 0:a.chapters)||[],ue=f(I[0]&&Dr(I[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),fe=u("bookPage.chapterCount",{n:I.length,unit:ue}),ze=!!(Vt(e).length||ti(e).length||(Ue=e.appendix)!=null&&Ue.length),B=[],pe=u(ce?"bookPage.sec.physical":"bookPage.sec.images");(I.length||O.text.length||l)&&B.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:I.length?fe:void 0}),O.groups.length&&B.push({id:"images",label:pe,count:ae}),ze&&B.push({id:"lineage",label:u("bookPage.sec.lineage")}),J.length&&B.push({id:"collections",label:u("section.containedIn"),count:J.length}),(nt=e.location_history)!=null&&nt.length&&B.push({id:"provenance",label:u("section.locationHistory")});const Te=_=>(d==null?void 0:d(_))??null,ve=I[0],Ve=ve?Te(ve.file):null,qe=N?I:I.slice(0,Qx),Xe=(_,le,H)=>_?t.jsx("a",{className:H,href:_.href??"#",onClick:_.onClick?he=>{he.metaKey||he.ctrlKey||(he.preventDefault(),_.onClick())}:void 0,children:le}):t.jsx("span",{className:H,children:le}),X=t.jsxs(t.Fragment,{children:[(I.length>0||O.text.length>0||l)&&t.jsxs(St,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:I.length>0?t.jsx(vt,{items:[fe,(Y=a==null?void 0:a.source)!=null&&Y.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!ve&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-d-ft","aria-busy":"true",children:[t.jsx("span",{className:"bim-d-ft-h",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "})]}),t.jsx("div",{className:"bim-d-chap-pending","aria-hidden":"true"})]}),ve&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Dr(ve.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((ve.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),Xe(Ve,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),I.length>1&&t.jsx("ul",{className:"bim-d-chap",children:qe.map(_=>{const[le,H]=Dr(_.title);return t.jsx("li",{children:Xe(Te(_.file),t.jsxs(t.Fragment,{children:[le&&t.jsx("b",{children:f(le)}),f(H||_.file)]}))},_.file)})}),I.length>qe.length&&t.jsx(Ts,{label:u("detail.expandRest",{n:I.length-qe.length,unit:ue}),onClick:()=>z(!0)}),O.text.length>0&&t.jsxs(t.Fragment,{children:[(I.length>0||l)&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"14px 0 4px"},children:u("bookPage.externalText")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:O.text.map((_,le)=>t.jsx(ao,{item:_,siblings:O.text,listedVolumeCounts:Q},`${_.id||_.url||_.name}-${le}`))})})]})]}),O.groups.length>0&&t.jsx(St,{id:"images",title:pe,meta:t.jsx(vt,{items:[O.groups.length>1?u("bookPage.groupCount",{n:O.groups.length}):"",u("bookPage.placeCount",{n:ae})]}),children:t.jsx(Cd,{groups:O.groups,listedVolumeCounts:Q})}),ze&&t.jsx(St,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Vt(e).length?u("bookPage.lineageMeta"):void 0,action:R?t.jsxs("span",{className:"bim-d-seg bim-d-ui",role:"group","aria-label":u("bookPage.lineageView"),children:[t.jsx("button",{type:"button","aria-pressed":C==="flow",onClick:()=>U("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":C==="graph",onClick:()=>U("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:C==="graph"&&R?t.jsx(lo,{graph:R,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(_,le)=>t.jsx(jt,{id:_,label:f(le),onNavigate:n,renderLink:r,dense:!0})}):t.jsx(i0,{data:e,heading:K||je,yearText:V,refName:Ne,onNavigate:n,renderLink:r})}),J.length>0&&t.jsx(St,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:J.map((_,le)=>{const H=_.id,he=Wi(_.vol),xe=v.get(H),Re=qu(xe);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:H,label:xe?f(xe.title):H,onNavigate:n,renderLink:r,dense:!0}),he.length>0&&t.jsx(t0,{volumes:he,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Re?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Re>0&&u("bookPage.totalOf",{n:Re,unit:h.unit.bu})})]},`${H}-${le}`)})})})}),(M=e.location_history)!=null&&M.length?t.jsx(St,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((_,le)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(_.name||_.location||"")}),([_.start_date,_.end_date].filter(Boolean).join("—")||_.description||_.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[_.start_date,_.end_date].filter(Boolean).join("—"),_.description?f(_.description):"",_.note?f(_.note):""]})})]},le))})}):null,B.length===0&&t.jsx(St,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),ie=x.findIndex(_=>_.id===e.id),me=F.length<=hl,se=me&&ie>=0?x.slice(Math.max(0,ie-fl),ie+fl+1):x.filter(_=>_.id!==e.id),de=t.jsxs(t.Fragment,{children:[g&&t.jsxs("div",{id:"work",className:"bim-d-side",style:{scrollMarginTop:16},children:[t.jsx("h2",{className:"bim-d-ui bim-d-side-h",children:f(h.section.belongsToWork)}),t.jsx("div",{style:{fontSize:17,fontWeight:500},children:t.jsx(jt,{id:g.id,label:f(g.title),onNavigate:n,renderLink:r})}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(_=>`${_.dynasty?`〔${f(_.dynasty)}〕`:""}${f(_.name)}`),f(qt(g,h.unit.juan)),g._edition_count??((k=g._books)==null?void 0:k.length)?u("bookPage.editionCount",{n:g._edition_count??((P=g._books)==null?void 0:P.length)??0}):""]}),((q=g.description)==null?void 0:q.text)&&t.jsx("p",{style:{fontSize:14,lineHeight:1.8,display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical",overflow:"hidden"},className:"bim-d-card-desc bim-d-side-desc",children:f(g.description.text.replace(/[#*_>`[\]]/g,""))})]}),T>0&&se.length>0&&t.jsxs("div",{children:[t.jsx(mi,{id:"siblings",timeline:!0,title:me?u("bookPage.siblings"):h.relation.siblingVersions,meta:me?u("bookPage.byEra"):u("bookPage.kindCount",{n:T}),cap:se.length,items:se.map(_=>_.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(_.edition||_.title||_.id)}):t.jsx(jt,{id:_.id,label:f(_.edition||_.title||_.id),onNavigate:n,renderLink:r,dense:!0})),metas:se.map(_=>[_.year!=null?_.year<0?u("detail.bce",{n:-_.year}):String(_.year):"",_.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:se.findIndex(_=>_.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(jt,{id:g.id,label:u("bookPage.viewAllInWork",{n:F.length}),onNavigate:n,renderLink:r,dense:!0})})]})]}),ge=e.work_id?t.jsx(wc,{caption:h.section.belongsToWork,children:t.jsx(jt,{id:e.work_id,label:g?f(g.title):" ",onNavigate:n,renderLink:r,dense:!0})}):void 0;return t.jsx(Zi,{railTop:c,back:m,up:ge,nav:B,railLinks:p,main:X,card:re,side:de})};function t0({volumes:e,unit:i}){const{t:n}=oe();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Yn(e,i),unit:i}),e.length>1&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-dot"}),n("bookPage.volumeCount",{n:e.length,unit:i})]})]})}function i0({data:e,heading:i,yearText:n,refName:r,onNavigate:o,renderLink:a}){var w;const{t:l,convert:d}=oe(),c=e.lineage,m=Vt(e),p=m.filter(x=>x.ref_type!=="book"),h=m.filter(x=>x.ref_type==="book"&&x.relation==="底本"),u=m.filter(x=>x.ref_type==="book"&&x.relation!=="底本"),f=ti(e),g=m.length>0||f.length>0,y=x=>x&&e0.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",v=(x,j)=>t.jsx(jt,{id:x,label:d(j||x),onNavigate:o,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[p.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:x.relation?d(x.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),x.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(x.evidence),y(x.confidence)]})]})},`a-${j}`)),h.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:i}),n&&t.jsx("span",{className:"bim-d-lf-yr",children:d(n)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((x,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,r(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},j))})]}),f.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((x,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[v(x.book_id,r(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},j))})]})]}),(w=e.appendix)==null?void 0:w.map((x,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(x.title)]}),t.jsx(zi,{text:x.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Oi=16,n0=200,r0=16,Md=({data:e,catalog:i,transport:n,onNavigate:r,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var me,se,de,ge,Oe,Je,Pe,Ue,nt;const{t:m,convert:p,messages:h}=oe(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[v,w]=b.useState(null),[x,j]=b.useState(""),[S,$]=b.useState(!1),N=b.useMemo(()=>Ul(e,i),[e,i]),z=b.useMemo(()=>Wl(e),[e]),[C,U]=b.useState(new Map),R=!!n&&N.rows.length>0&&N.rows.length<=n0,L=R&&(N.rows.length<=Oi||S),F=L&&N.rows.every(Y=>!Y.id||C.has(Y.id)),T=Y=>{var M;return us(Y?(M=C.get(Y))==null?void 0:M.l1:void 0)},Z=b.useMemo(()=>{const Y=u.trim(),M=Y?p(Y):"";return N.rows.filter(k=>{var q,_;if(x&&us(k.id?(q=C.get(k.id))==null?void 0:q.l1:void 0)!==x)return!1;if(!M)return!0;const P=k.id&&((_=C.get(k.id))==null?void 0:_.title)||k.title;return p(P).includes(M)||(k.subItems||[]).some(le=>p(le).includes(M))})},[N.rows,u,x,C,p]),O=g?Z:Z.slice(0,Oi),ae=b.useMemo(()=>(L?N.rows:O).filter(Y=>Y.id&&!C.has(Y.id)).map(Y=>Y.id),[L,N.rows,O,C]);b.useEffect(()=>{if(!n||ae.length===0)return;let Y=!1;const M=ae.slice(0,r0);return tr(M,er,k=>n.getItem(k).then(P=>{var le,H;const q=P??{},_={title:q.title,edition:q.edition,authors:q.authors,measure:P?qt(P,h.unit.juan):void 0,versionCount:q._edition_count??((le=q._books)==null?void 0:le.length),l1:((H=$s(q))==null?void 0:H.l1)||void 0};return[k,_]}).catch(()=>[k,{}]),()=>Y).then(k=>{Y||U(P=>{const q=new Map(P);for(const[_,le]of k)q.set(_,le);return q})}),()=>{Y=!0}},[n,ae,h.unit.juan]);const ce=(me=(e.contained_in||[])[0])==null?void 0:me.id;b.useEffect(()=>{if(!ce){w(null);return}if(w({id:ce}),!n)return;let Y=!1;return n.getItem(ce).then(M=>{Y||w({id:ce,title:M==null?void 0:M.title})}).catch(()=>{}),()=>{Y=!0}},[n,ce]);const Ee=b.useMemo(()=>Nd(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),we=Ee.text.length+Ee.groups.reduce((Y,M)=>Y+M.rows.length+M.mirrors.length,0),ye=z.works,Q=new Set(N.rows.map(Y=>Y.id).filter(Boolean)),Ne=ye.length>0&&!ye.every(Y=>Q.has(Y.id)),W=(()=>{const Y=N.rows.map(M=>M.edition).filter(Boolean);return Y.length>1&&new Set(Y).size===1})(),je=N.rows.some(Y=>Y.volumes.length>0||Y.expected!=null),K=z.total,V=z.truncated?K:N.rows.length,re=qt(e,h.unit.juan),J=e.count,I=Y=>typeof Y=="number"&&Number.isFinite(Y)?Y:null,ue=I(J==null?void 0:J.juan)??I((se=e.juan_count)==null?void 0:se.number)??I((ge=(de=e.measures)==null?void 0:de.find(Y=>(Y==null?void 0:Y.unit)==="卷"))==null?void 0:ge.number),fe=I(J==null?void 0:J.ce)??(N.totalVolumes||null),ze=[{value:V,label:m("collectionPage.stat.titles")},{value:ue??0,label:h.unit.juan},{value:fe??0,label:h.unit.volume}],B=b.useMemo(()=>{var k,P;const Y=[];if((k=e.publication_info)!=null&&k.details&&Y.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),K&&(K!==N.rows.length||z.truncated)){const q=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");Y.push({label:q,value:`${K} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const M=[I(J==null?void 0:J.zhong)!=null?m("collectionPage.nZhong",{n:J.zhong}):"",I(J==null?void 0:J.han)!=null?m("collectionPage.nHan",{n:J.han}):""].filter(Boolean);return M.length&&Y.push({label:m("collectionPage.fact.expected"),value:M.join(" ")}),ue==null&&re&&Y.push({label:m("collectionPage.fact.measure"),value:p(re),title:(P=e.juan_count)!=null&&P.description?p(e.juan_count.description):void 0}),Y},[e,K,z.truncated,N.rows.length,ue,re,J,p,m,h]),pe=b.useMemo(()=>{if(!F)return[];const Y=new Map;for(const k of N.rows){const P=T(k.id);P&&Y.set(P,(Y.get(P)??0)+1)}const M=Yi.filter(k=>(Y.get(k.key)??0)>0);return M.length<2?[]:[{key:"",label:`${h.catalog.all} ${V}`},...M.map(k=>({key:k.key,label:`${k.label} ${Y.get(k.key)}`}))]},[F,N.rows,C,h]),Te=b.useMemo(()=>{if(!F||!N.rows.some(P=>P.volumes.length>0))return null;const Y=[],M=N.rows.filter(P=>P.volumes.length>0).map(P=>({k:T(P.id)??"",from:Math.min(...P.volumes),to:Math.max(...P.volumes)})).sort((P,q)=>P.from-q.from);for(const P of M){const q=P.to-P.from+1,_=Y[Y.length-1];_&&_.key===P.k?(_.to=Math.max(_.to,P.to),_.n+=q):Y.push({key:P.k,from:P.from,to:P.to,n:q})}const k=M.reduce((P,q)=>Math.max(P,q.to),0);return Y.length>1&&Y.some(P=>P.key)?{segs:Y,last:k}:null},[F,N.rows,C]),ve=(Oe=e.description)==null?void 0:Oe.text,Ve=t.jsx(tn,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(oo,{authors:e.authors,onNavigate:r,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(Je=e.publication_info)!=null&&Je.year?p(e.publication_info.year):""]}),description:ve||(Pe=e.history)!=null&&Pe.length?t.jsxs(t.Fragment,{children:[ve&&t.jsx(zi,{text:ve,style:{fontSize:15,lineHeight:1.85}}),(Ue=e.history)!=null&&Ue.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((Y,M)=>t.jsx("li",{children:p(Y)},M))}):null]}):void 0,clampDescription:Is(ve)||(((nt=e.history)==null?void 0:nt.length)??0)>2?6:void 0,stats:ze,facts:B,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:Te&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:m("collectionPage.dist.head")})}),t.jsx("div",{className:"bim-d-dist-bar",role:"group","aria-label":m("collectionPage.dist.head"),children:Te.segs.map((Y,M)=>{const k=Yi.find(P=>P.key===Y.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!k,title:k?m("collectionPage.dist.segTitle",{section:p(k.label),from:Y.from,to:Y.to}):void 0,"aria-label":k?m("collectionPage.dist.only",{section:p(k.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!k&&x===Y.key,style:{flexGrow:Y.n,background:k?s.bim(k.token):s.bim("rule")},onClick:()=>{k&&(j(x===Y.key?"":Y.key),y(!1))}},M)})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:m("catalog.volume",{n:1})}),t.jsx("span",{children:m("collectionPage.dist.hint")}),t.jsx("span",{children:m("catalog.volume",{n:Te.last})})]})]})}),qe=[];N.rows.length&&qe.push({id:"titles",label:m("collectionPage.sec.titles"),count:V}),we&&qe.push({id:"resources",label:m("collectionPage.sec.resources"),count:we}),Ne&&qe.push({id:"works",label:h.section.containedWorks,count:ye.length});const Xe=t.jsxs(t.Fragment,{children:[N.rows.length>0&&t.jsxs(St,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${V} ${h.unit.items}`,N.totalVolumes?m("collectionPage.totalVolumes",{n:N.totalVolumes,unit:h.unit.volume}):"",Z.length!==V?m("collectionPage.currentN",{n:Z.length,unit:h.unit.items}):""]}),action:a,children:[(N.rows.length>Oi||pe.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[pe.length>0&&t.jsx(Qi,{items:pe,value:x,onChange:Y=>{j(Y),y(!1)}}),R&&N.rows.length>Oi&&!F&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>$(!0),title:m("collectionPage.loadAllTitle",{n:N.rows.length,unit:h.unit.items}),children:m(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),N.rows.length>Oi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:Y=>{f(Y.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(Z.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[je&&t.jsx("th",{style:{width:"8.5em"},children:m("collectionPage.col.volumes")}),t.jsx("th",{children:m("collectionPage.col.title")}),t.jsx("th",{style:{textAlign:"right"},children:m("collectionPage.col.versions")})]})}),t.jsx("tbody",{children:O.map((Y,M)=>{var he;const k=Y.id?C.get(Y.id):void 0,P=k!=null&&k.title&&Y.title===Y.id?k.title:Y.title,q=((k==null?void 0:k.authors)||[]).find(xe=>xe&&xe.name),_=[q?`${q.dynasty?`〔${p(q.dynasty)}〕`:""}${p(q.name)}${q.role?` ${p(q.role)}`:""}`:"",k!=null&&k.measure?p(k.measure):"",(he=Y.subItems)!=null&&he.length?Y.subItems.map(xe=>p(xe)).join("、"):"",(k!=null&&k.edition||Y.edition)&&!W?p((k==null?void 0:k.edition)||Y.edition||""):""].filter(Boolean),le=Yi.find(xe=>xe.key===T(Y.id)),H=Y.volumes.length>0?m("collectionPage.volumeRange",{range:Yn(Y.volumes,h.unit.volume),unit:h.unit.volume}):Y.expected!=null?`${Y.found??0}/${Y.expected} ${h.unit.volume}`:"";return t.jsxs("tr",{children:[je&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${H?"":" bim-d-zt-blank"}`,children:[le&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:s.bim(le.token)}}),H||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[Y.id?t.jsx(jt,{id:Y.id,label:p(P),onNavigate:r,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(P)}),_.length>0?t.jsx(vt,{items:_}):Y.id&&!k&&n?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k!=null&&k.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:k!=null&&k.versionCount?m("collectionPage.nZhong",{n:k.versionCount}):""})]},`${Y.id??Y.title}-${M}`)})})]}),O.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:m("catalog.noMatch")}),!g&&t.jsx(Jn,{total:Z.length,shown:O.length,unit:h.unit.items,onClick:()=>y(!0)})]}),we>0&&t.jsxs(St,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:we}),children:[Ee.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[Ee.groups.length>0&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children:m("collectionPage.text")}),t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Ee.text.map((Y,M)=>t.jsx(ao,{item:Y,siblings:Ee.text},`${Y.id||Y.url||Y.name}-${M}`))})})]}),t.jsx(Cd,{groups:Ee.groups})]}),N.rows.length===0&&we===0&&t.jsx(St,{title:m("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("collectionPage.empty")})})]}),X=Ne?t.jsx(mi,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:ye.length}),cap:12,items:ye.map(Y=>t.jsx(jt,{id:Y.id,label:p(Y.title),onNavigate:r,renderLink:o,dense:!0}))}):null,ie=v?t.jsx(wc,{caption:m("collectionPage.parent"),children:t.jsx(jt,{id:v.id,label:p(v.title||v.id),onNavigate:r,renderLink:o,dense:!0})}):void 0;return t.jsx(Zi,{railTop:l,back:d,up:ie,nav:qe,railLinks:c,main:Xe,card:Ve,side:X})},s0=8;function Ad(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function o0(e){return(e||[]).filter(i=>{var n,r;return Ad(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((r=i.license)==null?void 0:r.trim())}).slice(0,s0)}function a0({images:e,assetBase:i,name:n}){const{t:r,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?o0(e):[];if(!i||d||m.length===0)return null;const p=i.endsWith("/")?i:i+"/",h=m[Math.min(a,m.length-1)],u=h.width&&h.height&&h.width>0&&h.height>0?`${h.width} / ${h.height}`:void 0,f=g=>p+Ad(g.file).split("/").map(encodeURIComponent).join("/");return t.jsxs("figure",{className:"bim-d-seal bim-d-ui",children:[t.jsx("img",{className:"bim-d-seal-main",src:f(h),alt:r("entityPage.sealAlt",{name:n})+(m.length>1?` ${a+1}`:""),style:u?{"--seal-ar":u}:void 0,width:h.width,height:h.height,decoding:"async",fetchPriority:"high",onError:()=>c(!0)},h.file),m.length>1&&t.jsx("div",{className:"bim-d-seal-thumbs",children:m.map((g,y)=>t.jsx("button",{type:"button","aria-pressed":y===a,"aria-label":`${r("entityPage.sealAlt",{name:n})} ${y+1}`,onClick:()=>l(y),children:t.jsx("img",{src:f(g),alt:"",loading:"lazy",decoding:"async"})},g.file))}),t.jsxs("figcaption",{children:[r("entityPage.imgCredit",{credit:o(h.credit)})," · ",r("entityPage.imgLicense",{license:o(h.license)}),h.source_url&&/^https?:\/\//i.test(h.source_url)&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:h.source_url,target:"_blank",rel:"noopener noreferrer nofollow",children:r("entityPage.imgSource")})]}),h.note&&t.jsxs(t.Fragment,{children:[" · ",o(h.note)]})]})]})}const gl=8,xl=10,yl=30,Ld=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function l0(e){return`${Ld(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function c0(e,i,n){var r;return`${Ld(i,n.key,n.chapter)}#e=${((r=n.ids)!=null&&r.length?n.ids:[e]).join(",")}`}const d0=({id:e,transport:i,renderLink:n,onTotal:r})=>{const{t:o,convert:a}=oe(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(gl),[u,f]=b.useState(xl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),v=b.useRef(r);if(v.current=r,b.useEffect(()=>{if(d(null),m("idle"),h(gl),f(xl),!y)return;const $=g.current;let N=!1;const z=()=>{m("loading"),i.getMentions(e).then(U=>{var L,F;if(N)return;const R=U&&"books"in U?U:null;if(!R||!R.total){m("none"),(L=v.current)==null||L.call(v,0);return}d(R),m("ok"),(F=v.current)==null||F.call(v,R.total)}).catch(()=>{N||m("none")})};if(!$||typeof IntersectionObserver>"u")return z(),()=>{N=!0};const C=new IntersectionObserver(U=>{U.some(R=>R.isIntersecting)&&(C.disconnect(),z())},{rootMargin:"400px"});return C.observe($),()=>{N=!0,C.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const w=($,N,z)=>n?n($,N,z):t.jsx("a",{className:z,href:$,children:N}),x=new Map(((l==null?void 0:l.books)??[]).map($=>[$.item,$.title])),j=(l==null?void 0:l.examples)??[],S=(l==null?void 0:l.books)??[];return t.jsx("div",{ref:g,children:t.jsxs(St,{id:"mentions",title:o("mentions.title"),meta:l?t.jsx(vt,{items:[o("mentions.total",{n:l.total,b:S.length})]}):void 0,children:[!l&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:o("mentions.loading")}),l&&t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:o("mentions.hint")}),l&&j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.examples")}),t.jsx("ol",{className:"bim-d-mentions",children:j.slice(0,p).map(($,N)=>{const z=[x.get($.item),$.heading].filter(Boolean).map(U=>a(U)).join(" · "),C=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-mention-where bim-d-ui",children:z||$.chapter}),t.jsxs("span",{className:"bim-d-mention-ctx",children:[$.before?"…":"",a($.before),t.jsx("b",{children:a($.text)}),a($.after),$.after?"…":""]})]});return t.jsx("li",{children:w(l0($),C,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${N}`)})}),j.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(j.length),children:o("mentions.more",{n:j.length-p})})]}),l&&S.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.byBook")}),t.jsx("ul",{className:"bim-d-mbooks",children:S.slice(0,u).map($=>t.jsx(m0,{entityId:e,book:$,open:S.length===1,transport:i,link:w},$.item))}),S.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+yl),children:o("mentions.moreBooks",{n:Math.min(yl,S.length-u)})})]})]})})},m0=({entityId:e,book:i,open:n,transport:r,link:o})=>{const{t:a,convert:l}=oe(),[d,c]=b.useState(i.chapters??null),[m,p]=b.useState(!1);b.useEffect(()=>{c(i.chapters??null)},[i]);const h=u=>{!u.currentTarget.open||d||m||!(r!=null&&r.getMentions)||(p(!0),r.getMentions(e,i.item).then(f=>{f&&"chapters"in f&&Array.isArray(f.chapters)&&c(f.chapters)}).catch(()=>{}).finally(()=>p(!1)))};return t.jsx("li",{children:t.jsxs("details",{className:"bim-d-mbook",open:n,onToggle:h,children:[t.jsxs("summary",{children:[t.jsx("span",{className:"bim-d-mbook-t",children:l(i.title??i.item)}),t.jsx("span",{className:"bim-d-mbook-n bim-d-ui",children:a("mentions.bookLine",{n:i.count,c:i.chapter_count})})]}),m&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"0 0 8px 40px"},children:a("mentions.loading")}),d&&t.jsx("ul",{className:"bim-d-mchaps",children:d.map(u=>t.jsx("li",{children:o(c0(e,i.item,u),t.jsxs(t.Fragment,{children:[t.jsx("span",{children:u.heading?`${u.chapter} · ${l(u.heading)}`:u.chapter}),t.jsx("span",{className:"bim-d-ui",children:a("mentions.chapterLine",{n:u.count})})]}),"bim-d-mchap")},`${u.key}|${u.chapter}`))})]})})},u0=16,p0=30,Wr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function jl(e){if(!e)return Wr.length;const i=Wr.indexOf(e);return i===-1?Wr.length:i}function b0(e,i,n){if(i)return e[i]??n(i)}function h0(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const f0={秦:[-221,-207],西漢:[-202,8],西汉:[-202,8],東漢:[25,220],东汉:[25,220],漢:[-202,220],汉:[-202,220],三國:[220,280],三国:[220,280],西晉:[265,316],西晋:[265,316],東晉:[317,420],东晋:[317,420],隋:[581,618],唐:[618,907],五代:[907,960],北宋:[960,1127],南宋:[1127,1279],宋:[960,1279],遼:[916,1125],辽:[916,1125],金:[1115,1234],元:[1271,1368],明:[1368,1644],清:[1636,1912]},Pd=({data:e,transport:i,onNavigate:n,renderLink:r,railTop:o,back:a,railLinks:l,assetBase:d})=>{var Je,Pe,Ue,nt,Y,M;const{t:c,convert:m,messages:p}=oe(),h=k=>h0(k,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[v,w]=b.useState("default"),[x,j]=b.useState(new Map),[S,$]=b.useState(0),N=b.useMemo(()=>(e._works||[]).filter(k=>!Qo(k.st)),[e._works]),z=b.useMemo(()=>(e._works||[]).filter(k=>Qo(k.st)),[e._works]),C=b.useMemo(()=>N.map(k=>{const P=x.get(k.work_id);return{id:k.work_id,title:(P==null?void 0:P.title)??k.title??k.work_id,role:k.role||"",cls:ws(k.role),versionCount:P==null?void 0:P.versionCount,section:P==null?void 0:P.cls,l1:P==null?void 0:P.l1,measure:P==null?void 0:P.measure,hasImage:P==null?void 0:P.hasImage,loaded:!!(P!=null&&P.loaded)}}),[N,x]),U=b.useMemo(()=>Dl(N.map(k=>k.role),c("detail.roleAll")),[N,c]),R=b.useMemo(()=>{const k=u==="全部"?C:C.filter(P=>P.cls===u);return v==="versions"?[...k].sort((P,q)=>(q.versionCount??-1)-(P.versionCount??-1)):k},[C,u,v]),L=g?R:R.slice(0,u0),F=b.useMemo(()=>L.filter(k=>!x.has(k.id)).map(k=>k.id),[L,x]);b.useEffect(()=>{if(!i||F.length===0)return;let k=!1;return tr(F,er,P=>i.getItem(P).then(q=>{var xe;const _=q??{},le=_._edition_count??((xe=_._books)==null?void 0:xe.length)??0,H=$s(_),he=[H==null?void 0:H.l1,H==null?void 0:H.l2].filter(Boolean).join(" ");return[P,{id:P,title:_.title,versionCount:le,loaded:!0,cls:he||void 0,l1:(H==null?void 0:H.l1)||void 0,measure:q&&qt(q,p.unit.juan)||void 0,hasImage:!!_._has_image}]}).catch(()=>[P,{id:P,loaded:!0}]),()=>k).then(P=>{k||j(q=>{const _=new Map(q);for(const[le,H]of P)_.set(le,H);return _})}),()=>{k=!0}},[i,F,p.unit.juan]);const T=b.useMemo(()=>{const k=new Map;for(const P of e.alt_names||[]){const q=P.type||p.section.aliases;k.has(q)||k.set(q,[]),k.get(q).push(P.name)}return[...k.entries()].sort((P,q)=>jl(P[0])-jl(q[0])).map(([P,q])=>({label:P,names:q}))},[e.alt_names,p]),Z=((Je=e.dates)==null?void 0:Je.birth)??void 0,O=((Pe=e.dates)==null?void 0:Pe.death)??void 0,ae=(Ue=e.dates)==null?void 0:Ue.floruit,ce=Z!=null||O!=null?`${h(Z)||"?"}—${h(O)||"?"}`:Array.isArray(ae)&&ae.length===2&&ae.every(k=>Number.isFinite(k))?c("entityPage.floruit",{from:h(ae[0]),to:h(ae[1])}):"",Ee=new Set(["本名","字","號","号"]),we=T.filter(k=>Ee.has(k.label)),ye=T.filter(k=>!Ee.has(k.label)),Q=ye.reduce((k,P)=>k+P.names.length,0),Ne=b.useMemo(()=>{const k=[];for(const q of we)k.push({label:q.label,value:q.names.map(_=>m(_)).join("、")});const P=N.length;return P&&k.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:P})}),z.length&&k.push({label:c("entityPage.fact.pieces"),value:c("entityPage.nPian",{n:z.length})}),k},[N,z,we,m,c]),W=k=>{var P;return(P=T.find(q=>k.includes(q.label)))==null?void 0:P.names[0]},je=W(["字"]),K=W(["號","号"]),V=[je?c("entityPage.zi",{name:m(je)}):"",K?c("entityPage.hao",{name:m(K)}):""].filter(Boolean).join(","),re=e.native_place,J=e.dynasty?f0[e.dynasty]:void 0,I=(()=>{if(!J||Z==null||O==null||O<Z)return null;const[k,P]=J,q=Math.max(Z,k),_=Math.min(O,P);if(_<=q)return null;const le=P-k;return t.jsxs("div",{className:"bim-d-life bim-d-ui",children:[t.jsx("div",{className:"bim-d-life-bar",role:"img","aria-label":c("entityPage.lifeAria",{birth:h(Z),death:h(O),years:O-Z+1}),children:t.jsx("i",{style:{left:`${(q-k)/le*100}%`,width:`${(_-q)/le*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${h(k)} ${m(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:O-Z+1})}),t.jsx("span",{children:h(P)})]})]})})(),ue=b.useMemo(()=>{if(!i||C.length===0||C.some(q=>!q.loaded))return null;const k=new Map;for(const q of C){const _=us(q.l1);_&&k.set(_,(k.get(_)??0)+1)}const P=Yi.map(q=>({...q,n:k.get(q.key)??0})).filter(q=>q.n>0);return P.length?P:null},[C,i]),fe=t.jsxs(tn,{kind:b0(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:V||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",ce,re?c("entityPage.nativePlace",{place:m(re)}):""]}),I,t.jsx(a0,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(nt=e.description)!=null&&nt.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Is((Y=e.description)==null?void 0:Y.text)?6:void 0,facts:Ne,foot:t.jsx(nn,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[Q>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:Q})}),t.jsx("dl",{children:ye.map(k=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{children:k.names.map(P=>m(P)).join("、")})]},k.label))})]}),ue&&t.jsxs("div",{className:"bim-d-dist bim-d-ui",children:[t.jsx("div",{className:"bim-d-dist-head",children:t.jsx("span",{children:c("entityPage.dist")})}),t.jsx("div",{className:"bim-d-dist-bar","aria-hidden":"true",children:ue.map(k=>t.jsx("i",{style:{flexGrow:k.n,background:s.bim(k.token)}},k.key))}),t.jsx("div",{className:"bim-d-dist-key",children:ue.map(k=>t.jsxs("span",{children:[t.jsx("i",{style:{background:s.bim(k.token)}}),m(k.label)," ",k.n]},k.key))})]})]}),ze=b.useMemo(()=>C.filter(k=>k.loaded&&(k.versionCount??0)>0).sort((k,P)=>(P.versionCount??0)-(k.versionCount??0)).slice(0,3),[C]),B=!!i&&C.length>=3&&L.some(k=>!k.loaded),pe=u==="全部"&&(B||ze.length>=2),Te=e.external_ids||{},ve=((M=e.external_ids_meta)==null?void 0:M.cbdb_match)??Te.cbdb_match,Ve=[];Te.cbdb_id!=null&&Ve.push({label:"CBDB",id:String(Te.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${Te.cbdb_id}`,note:ve==="auto"?c("entityPage.autoMatch"):void 0});const qe=Te.wikidata_id;qe&&Ve.push({label:"Wikidata",id:qe,href:`https://www.wikidata.org/wiki/${qe}`});const Xe=Te.viaf_id;Xe&&Ve.push({label:"VIAF",id:Xe,href:`https://viaf.org/viaf/${Xe}`});const X=U.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),ie=e.id?t.jsx(d0,{id:e.id,transport:i,onTotal:$}):null,me=[...pe&&!B?[{id:"featured",label:c("entityPage.sec.featured"),count:ze.length}]:[],...C.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:C.length}]:[],...z.length?[{id:"pieces",label:c("entityPage.sec.pieces"),count:z.length}]:[],...S?[{id:"mentions",label:c("mentions.title"),count:S}]:[],...Ve.length?[{id:"external",label:c("entityPage.sec.external"),count:Ve.length}]:[]],se=pe?t.jsxs(St,{id:"featured",title:c("entityPage.sec.featured"),children:[t.jsx("p",{className:"bim-d-sec-sub bim-d-ui",children:c("entityPage.featuredSub")}),t.jsxs("div",{className:"bim-d-picks","aria-busy":B||void 0,children:[B&&[0,1,2].map(k=>t.jsxs("div",{className:"bim-d-pick","aria-hidden":"true",children:[t.jsx("span",{className:"bim-d-pick-t",children:" "}),t.jsx("span",{className:"bim-d-meta",children:" "}),t.jsx("div",{className:"bim-d-pick-n",children:" "})]},k)),!B&&ze.map(k=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0})}),t.jsx(vt,{items:[k.section?m(k.section):"",k.measure?m(k.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:k.versionCount}),t.jsx("span",{children:c("entityPage.versionsUnit")}),k.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},k.id))]})]}):null,de=z.length?t.jsx(g0,{pieces:z,onNavigate:n,renderLink:r}):null,ge=C.length===0?t.jsxs(t.Fragment,{children:[de??t.jsx(St,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}),ie]}):t.jsxs(t.Fragment,{children:[se,t.jsxs(St,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:C.length}),R.length!==C.length?c("entityPage.current",{n:R.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[X.length>1&&t.jsx(Qi,{items:X,value:u,onChange:k=>{f(k),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":v==="versions",onClick:()=>{v==="default"&&y(!0),w(k=>k==="default"?"versions":"default")},children:c(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&en(R.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:c("entityPage.col.work")}),t.jsx("th",{children:c("entityPage.col.section")}),t.jsx("th",{children:c("entityPage.col.role")}),t.jsx("th",{children:c("entityPage.col.versions")}),t.jsx("th",{"aria-label":c("entityPage.col.image")})]})}),t.jsx("tbody",{children:L.map(k=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(jt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:r,dense:!0}),k.measure?t.jsx(vt,{items:[m(k.measure)]}):!k.loaded&&i?t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}):null]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.section||k.loaded?"":" bim-d-zt-blank"}`,children:k.section?m(k.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.role?"":" bim-d-zt-blank"}`,children:k.role?m(k.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${k.loaded?"":" bim-d-zt-blank"}`,children:k.loaded?k.versionCount?c("entityPage.nZhong",{n:k.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("entityPage.notRecorded")}):""}),t.jsx("td",{className:k.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:k.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("entityPage.hasImage")})})]},k.id))})]}),L.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx(Jn,{total:R.length,shown:L.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),de,ie]}),Oe=Ve.length>0?t.jsx(mi,{id:"external",title:c("entityPage.sec.external"),items:Ve.map(k=>t.jsxs("a",{href:k.href,target:"_blank",rel:"noopener noreferrer",children:[k.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Ve.map(k=>k.id),foot:Te.cbdb_id!=null&&ve==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Zi,{railTop:o,back:a,nav:me,railLinks:l,main:ge,card:fe,side:Oe})};function g0({pieces:e,onNavigate:i,renderLink:n}){const{t:r,convert:o,messages:a}=oe(),[l,d]=b.useState(""),[c,m]=b.useState(!1),p=g=>g?a.workSubtype[g]??o(g):"",h=b.useMemo(()=>{const g=new Map;for(const y of e)g.set(y.st||"",(g.get(y.st||"")??0)+1);return g.size<2?[]:[{key:"",label:`${r("detail.roleAll")} ${e.length}`},...[...g.entries()].sort((y,v)=>v[1]-y[1]).map(([y,v])=>({key:y,label:`${p(y)} ${v}`}))]},[e,r]),u=l?e.filter(g=>(g.st||"")===l):e,f=c?u:u.slice(0,p0);return t.jsxs(St,{id:"pieces",title:r("entityPage.sec.pieces"),meta:t.jsx(vt,{items:[r("entityPage.nPian",{n:e.length}),u.length!==e.length?r("entityPage.current",{n:u.length}):""]}),children:[h.length>0&&t.jsx("div",{className:"bim-d-filters bim-d-ui",children:t.jsx(Qi,{items:h,value:l,onChange:g=>{d(g),m(!1)}})}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!c&&en(u.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[t.jsx("th",{children:r("entityPage.piece.title")}),t.jsx("th",{children:r("entityPage.piece.kind")}),t.jsx("th",{children:r("entityPage.col.role")}),t.jsx("th",{"aria-label":r("entityPage.piece.text")})]})}),t.jsx("tbody",{children:f.map(g=>t.jsxs("tr",{children:[t.jsx("td",{className:"bim-d-zt-main",children:t.jsx(jt,{id:g.work_id,label:o(g.title??g.work_id),onNavigate:i,renderLink:n,dense:!0})}),t.jsx("td",{className:"bim-d-zt-sub bim-d-zt-nowrap",children:p(g.st)}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${g.role?"":" bim-d-zt-blank"}`,children:g.role?o(g.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:g.txt?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:g.txt&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:r("entityPage.piece.hasText")})})]},g.work_id))})]}),!c&&t.jsx(Jn,{total:u.length,shown:f.length,unit:r("entityPage.piece.moreUnit"),onClick:()=>m(!0)})]})}const co="(max-width: 719px)",x0=`${co}, (pointer: coarse)`,Od=`
|
|
1561
1561
|
.bim-ct {
|
|
1562
1562
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
1563
1563
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -1690,7 +1690,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
|
|
|
1690
1690
|
}
|
|
1691
1691
|
|
|
1692
1692
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
1693
|
-
@media ${
|
|
1693
|
+
@media ${x0} {
|
|
1694
1694
|
.bim-ct-row { min-height: 44px; }
|
|
1695
1695
|
.bim-ct-tw { width: 44px; }
|
|
1696
1696
|
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
@@ -1716,7 +1716,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
|
|
|
1716
1716
|
/* 窄屏分类抽屉:界栏下按钮和面板都有框 */
|
|
1717
1717
|
:root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${s.bim("fr-bd")}; background: ${s.bim("fr-bg")}; }
|
|
1718
1718
|
:root[data-layout="boxed"] .bim-ct-drawer { border: ${s.bim("fr-bd")}; }
|
|
1719
|
-
`,di="未分類",Gt="all",mo=20;function sn(e){if(!e)return[];const i=[];for(const n of[e.l1,e.l2,e.l3,e.l4]){const r=(n??"").trim();if(!r)break;i.push(r)}return i}function x0(e){const i=sn(e);return i.length?i.join("/"):di}function y0(e){const i=sn(e);return i.length?i.map((n,r)=>i.slice(0,r+1).join("/")):[di]}function j0(e,i=[]){const n=new Map;i.forEach((d,c)=>{const m=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(p=>!!p);m.forEach((p,h)=>{const u=m.slice(0,h+1).join("/");n.has(u)||n.set(u,c)})});const r=new Map;let o=0;for(const d of e){const c=sn(d.classification);if(!c.length){o++;continue}let m=r;c.forEach((p,h)=>{const u=c.slice(0,h+1).join("/");let f=m.get(p);f||(f={id:u,label:p,count:0,children:new Map},m.set(p,f)),f.count++,m=f.children})}const a=d=>[...d.values()].sort((c,m)=>{const p=c.label===di?1:0,h=m.label===di?1:0;if(p!==h)return p-h;const u=n.get(c.id)??1/0,f=n.get(m.id)??1/0;return u!==f?u-f:c.label.localeCompare(m.label,"zh")}).map(c=>{const m={id:c.id,label:c.label,count:c.count};return c.children.size&&(m.children=a(c.children)),m}),l=a(r);return o>0&&l.push({id:di,label:di,count:o}),l}function wi(e,i){if(!i)return[];for(const n of e){if(n.id===i)return[n];if(n.children){const r=wi(n.children,i);if(r.length)return[n,...r]}}return[]}function uo(e){return e.reduce((i,n)=>i+n.count,0)}function k0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function w0(e){var d,c,m;const i={id:e.id,title:e.title||e.id},n=e.juan_count,r=typeof n=="number"?n:(n==null?void 0:n.number)??((c=(d=e.measures)==null?void 0:d.find(p=>(p==null?void 0:p.unit)==="卷"&&typeof p.number=="number"))==null?void 0:c.number);typeof r=="number"&&r>0?i.juan=r:e.measure_info&&(i.juan=e.measure_info);const o=(e.authors??[]).filter(p=>p==null?void 0:p.name).map(p=>{const h=p.dynasty||(e.authors.length===1?e.dynasty:void 0);return h?{name:p.name,dynasty:h}:{name:p.name}});o.length&&(i.authors=o);const a=k0(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=sn(e.classification);return l.length&&(i.classification=l),i}function v0(e,i){const n=e.summary?0:1,r=i.summary?0:1;return n!==r?n-r:e.title.localeCompare(i.title,"zh")}function S0(e,i=mo){return Math.max(1,Math.ceil(e/i))}function Pd(e,i,n=2){if(i<=1)return[1];const r=new Set([1,i]);for(let l=e-n;l<=e+n;l++)l>=1&&l<=i&&r.add(l);const o=[...r].sort((l,d)=>l-d),a=[];return o.forEach((l,d)=>{if(d>0){const c=l-o[d-1];c===2?a.push(l-1):c>2&&a.push(null)}a.push(l)}),a}const $0=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function _0(e,i,n){const r=[];n&&r.push({id:Gt,parentId:null,hasChildren:!1,firstChildId:null});const o=(a,l)=>{var d;for(const c of a){const m=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:l,hasChildren:!!m,firstChildId:m?m[0].id:null}),m&&i.has(c.id)&&o(m,c.id)}};return o(e,null),r}function Od({tree:e,selectedId:i,onSelect:n,allLabel:r,label:o}){const{t:a,convert:l}=oe(),d=r===void 0?a("catalogPage.all"):r,c=o??a("catalogPage.classification"),m=b.useRef(null),p=i&&i!==Gt?i:null,h=d!==null,[u,f]=b.useState(()=>{const C=new Set;for(const U of wi(e,p))C.add(U.id);return C});b.useEffect(()=>{const C=wi(e,p);C.length&&f(U=>{if(C.every(L=>U.has(L.id)))return U;const R=new Set(U);for(const L of C)R.add(L.id);return R})},[e,p]);const g=b.useMemo(()=>_0(e,u,h),[e,u,h]),[y,v]=b.useState(null);b.useEffect(()=>{v(null)},[i]);const w=p??(h?Gt:null),x=b.useMemo(()=>{var R;const C=new Set(g.map(L=>L.id));if(y&&C.has(y))return y;if(w&&C.has(w))return w;const U=wi(e,p).map(L=>L.id).filter(L=>C.has(L));return U.length?U[U.length-1]:((R=g[0])==null?void 0:R.id)??null},[g,y,w,e,p]),j=b.useCallback((C,U)=>{f(R=>{const L=R.has(C),F=U??!L;if(F===L)return R;const T=new Set(R);return F?T.add(C):T.delete(C),T})},[]),S=b.useCallback(C=>{v(C),requestAnimationFrame(()=>{var R;const U=Array.from(((R=m.current)==null?void 0:R.querySelectorAll("[data-ct-id]"))??[]).find(L=>L.dataset.ctId===C);U==null||U.focus()})},[]),$=b.useCallback((C,U)=>{U&&j(C,!0),n(C)},[n,j]),N=b.useCallback(C=>{const U=C.target.closest("[data-ct-id]");if(!U)return;const R=U.dataset.ctId,L=g.findIndex(Z=>Z.id===R);if(L<0)return;const F=g[L];let T=null;switch(C.key){case"ArrowDown":T=g[Math.min(g.length-1,L+1)].id;break;case"ArrowUp":T=g[Math.max(0,L-1)].id;break;case"Home":T=g[0].id;break;case"End":T=g[g.length-1].id;break;case"ArrowRight":if(!F.hasChildren)break;u.has(R)?T=F.firstChildId:j(R,!0);break;case"ArrowLeft":F.hasChildren&&u.has(R)?j(R,!1):T=F.parentId;break;case"Enter":case" ":C.preventDefault(),$(R,F.hasChildren);return;default:return}C.preventDefault(),T&&T!==R&&S(T)},[g,u,j,S,$]),z=(C,U)=>C.map((R,L)=>{var ae;const F=(ae=R.children)!=null&&ae.length?R.children:null,T=!!F&&u.has(R.id),Z=R.id===p,O=U===1&&C.length>1&&L===C.length-1;return t.jsxs("li",{role:"treeitem","aria-level":U,"aria-expanded":F?T:void 0,"aria-selected":Z,tabIndex:x===R.id?0:-1,"data-ct-id":R.id,className:O?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":U-1},onClick:()=>{v(R.id),$(R.id,!!F)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:F?ce=>{ce.stopPropagation(),v(R.id),j(R.id)}:void 0,children:F?t.jsx($0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(R.label)}),t.jsx("span",{className:"bim-ct-n",children:R.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:z(F,U+1)})]},R.id)});return t.jsxs("ul",{ref:m,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:N,children:[h&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:x===Gt?0:-1,"data-ct-id":Gt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{v(Gt),n(Gt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(d)}),t.jsx("span",{className:"bim-ct-n",children:uo(e).toLocaleString("en-US")})]})}),z(e,1)]})}const Fd=e=>`/item/${encodeURIComponent(e)}`;function N0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Bd(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Hd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Bd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:i,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:r(e.title)}),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:r(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Dd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Bd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:i,children:[t.jsxs("span",{className:"bim-ct-lt",children:[r(e.title),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Wd({page:e,pageCount:i,onPage:n,pageHref:r,label:o}){const{t:a,convert:l}=oe();if(i<=1)return null;const d=m=>p=>{n&&(r&&!N0(p)||(p.preventDefault(),n(m)))},c=(m,p,h)=>{if(h.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:p});const u={className:"bim-ct-pg","aria-current":h.current?"page":void 0,"aria-label":h.aria};return r?t.jsx("a",{...u,href:r(m),onClick:d(m),children:p}):t.jsx("button",{type:"button",...u,onClick:h.current?void 0:d(m),children:p})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":o?l(o):a("catalogPage.pagerLabel"),children:[c(e-1,a("catalogPage.prevPage"),{disabled:e<=1}),t.jsx("ol",{children:Pd(e,i).map((m,p)=>t.jsx("li",{style:{display:"contents"},children:m===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):c(m,m,{current:m===e,aria:a("catalogPage.pageN",{n:m})})},m??`gap${p}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",i]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=i})]})}function Ud({works:e,workLink:i=Fd,emptyText:n,view:r="card",...o}){const{t:a,convert:l}=oe();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:n===void 0?a("catalogPage.emptyWorks"):typeof n=="string"?l(n):n}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Dd,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Hd,{work:d,href:i(d.id)},d.id))}),t.jsx(Wd,{...o})]})}const z0=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function C0({tree:e,selectedId:i,page:n,pageCount:r,works:o,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:m,allLabel:p,allTitle:h,pageSize:u=mo,className:f,view:g,onViewChange:y}){const{t:v,convert:w}=oe(),x=p===void 0?v("catalogPage.all"):p,j=h??v("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[N,z]=b.useState(!1),[C,U]=b.useState("card"),R=g??C,L=ce=>{U(ce),y==null||y(ce)},F=wi(e,i&&i!==Gt?i:null),T=F.length?F[F.length-1]:null,Z=T?T.label:j,O=T?T.count:uo(e),ae=b.useCallback(ce=>{z(!1),a(ce)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":N?"open":"closed",children:[t.jsx("style",{children:Ld}),t.jsxs("aside",{className:"bim-ct-side","aria-label":v("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":N,"aria-controls":$,onClick:()=>z(ce=>!ce),children:[t.jsx("span",{children:v("catalogPage.drawerLabel",{path:w(F.length?F.map(ce=>ce.label).join(" › "):x??j)})}),t.jsx(z0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:v("catalogPage.classification")}),t.jsx(Od,{tree:e,selectedId:i,onSelect:ae,allLabel:x})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:w(Z)}),F.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:w(F.slice(0,-1).map(ce=>ce.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[v("catalogPage.stat",{total:O.toLocaleString("en-US"),size:u}),r>1&&v("catalogPage.statPage",{page:n,pages:r})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":v("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":R==="card",onClick:()=>L("card"),children:v("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":R==="list",onClick:()=>L("list"),children:v("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Ud,{works:o,view:R,workLink:c,page:n,pageCount:r,onPage:l,pageHref:m})]})]})}const on="(max-width: 719px)",E0="(max-width: 1079px)",R0=`${on}, (pointer: coarse)`,T0=[8,18,30,42,88],po=`
|
|
1719
|
+
`,di="未分類",Gt="all",mo=20;function sn(e){if(!e)return[];const i=[];for(const n of[e.l1,e.l2,e.l3,e.l4]){const r=(n??"").trim();if(!r)break;i.push(r)}return i}function y0(e){const i=sn(e);return i.length?i.join("/"):di}function j0(e){const i=sn(e);return i.length?i.map((n,r)=>i.slice(0,r+1).join("/")):[di]}function k0(e,i=[]){const n=new Map;i.forEach((d,c)=>{const m=[d.cata_l1,d.cata_l2,d.cata_l3,d.cata_l4].filter(p=>!!p);m.forEach((p,h)=>{const u=m.slice(0,h+1).join("/");n.has(u)||n.set(u,c)})});const r=new Map;let o=0;for(const d of e){const c=sn(d.classification);if(!c.length){o++;continue}let m=r;c.forEach((p,h)=>{const u=c.slice(0,h+1).join("/");let f=m.get(p);f||(f={id:u,label:p,count:0,children:new Map},m.set(p,f)),f.count++,m=f.children})}const a=d=>[...d.values()].sort((c,m)=>{const p=c.label===di?1:0,h=m.label===di?1:0;if(p!==h)return p-h;const u=n.get(c.id)??1/0,f=n.get(m.id)??1/0;return u!==f?u-f:c.label.localeCompare(m.label,"zh")}).map(c=>{const m={id:c.id,label:c.label,count:c.count};return c.children.size&&(m.children=a(c.children)),m}),l=a(r);return o>0&&l.push({id:di,label:di,count:o}),l}function wi(e,i){if(!i)return[];for(const n of e){if(n.id===i)return[n];if(n.children){const r=wi(n.children,i);if(r.length)return[n,...r]}}return[]}function uo(e){return e.reduce((i,n)=>i+n.count,0)}function w0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function v0(e){var d,c,m;const i={id:e.id,title:e.title||e.id},n=e.juan_count,r=typeof n=="number"?n:(n==null?void 0:n.number)??((c=(d=e.measures)==null?void 0:d.find(p=>(p==null?void 0:p.unit)==="卷"&&typeof p.number=="number"))==null?void 0:c.number);typeof r=="number"&&r>0?i.juan=r:e.measure_info&&(i.juan=e.measure_info);const o=(e.authors??[]).filter(p=>p==null?void 0:p.name).map(p=>{const h=p.dynasty||(e.authors.length===1?e.dynasty:void 0);return h?{name:p.name,dynasty:h}:{name:p.name}});o.length&&(i.authors=o);const a=w0(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=sn(e.classification);return l.length&&(i.classification=l),i}function S0(e,i){const n=e.summary?0:1,r=i.summary?0:1;return n!==r?n-r:e.title.localeCompare(i.title,"zh")}function $0(e,i=mo){return Math.max(1,Math.ceil(e/i))}function Fd(e,i,n=2){if(i<=1)return[1];const r=new Set([1,i]);for(let l=e-n;l<=e+n;l++)l>=1&&l<=i&&r.add(l);const o=[...r].sort((l,d)=>l-d),a=[];return o.forEach((l,d)=>{if(d>0){const c=l-o[d-1];c===2?a.push(l-1):c>2&&a.push(null)}a.push(l)}),a}const _0=()=>t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",children:t.jsx("path",{d:"M3 1.5 6.5 5 3 8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function N0(e,i,n){const r=[];n&&r.push({id:Gt,parentId:null,hasChildren:!1,firstChildId:null});const o=(a,l)=>{var d;for(const c of a){const m=(d=c.children)!=null&&d.length?c.children:null;r.push({id:c.id,parentId:l,hasChildren:!!m,firstChildId:m?m[0].id:null}),m&&i.has(c.id)&&o(m,c.id)}};return o(e,null),r}function Bd({tree:e,selectedId:i,onSelect:n,allLabel:r,label:o}){const{t:a,convert:l}=oe(),d=r===void 0?a("catalogPage.all"):r,c=o??a("catalogPage.classification"),m=b.useRef(null),p=i&&i!==Gt?i:null,h=d!==null,[u,f]=b.useState(()=>{const C=new Set;for(const U of wi(e,p))C.add(U.id);return C});b.useEffect(()=>{const C=wi(e,p);C.length&&f(U=>{if(C.every(L=>U.has(L.id)))return U;const R=new Set(U);for(const L of C)R.add(L.id);return R})},[e,p]);const g=b.useMemo(()=>N0(e,u,h),[e,u,h]),[y,v]=b.useState(null);b.useEffect(()=>{v(null)},[i]);const w=p??(h?Gt:null),x=b.useMemo(()=>{var R;const C=new Set(g.map(L=>L.id));if(y&&C.has(y))return y;if(w&&C.has(w))return w;const U=wi(e,p).map(L=>L.id).filter(L=>C.has(L));return U.length?U[U.length-1]:((R=g[0])==null?void 0:R.id)??null},[g,y,w,e,p]),j=b.useCallback((C,U)=>{f(R=>{const L=R.has(C),F=U??!L;if(F===L)return R;const T=new Set(R);return F?T.add(C):T.delete(C),T})},[]),S=b.useCallback(C=>{v(C),requestAnimationFrame(()=>{var R;const U=Array.from(((R=m.current)==null?void 0:R.querySelectorAll("[data-ct-id]"))??[]).find(L=>L.dataset.ctId===C);U==null||U.focus()})},[]),$=b.useCallback((C,U)=>{U&&j(C,!0),n(C)},[n,j]),N=b.useCallback(C=>{const U=C.target.closest("[data-ct-id]");if(!U)return;const R=U.dataset.ctId,L=g.findIndex(Z=>Z.id===R);if(L<0)return;const F=g[L];let T=null;switch(C.key){case"ArrowDown":T=g[Math.min(g.length-1,L+1)].id;break;case"ArrowUp":T=g[Math.max(0,L-1)].id;break;case"Home":T=g[0].id;break;case"End":T=g[g.length-1].id;break;case"ArrowRight":if(!F.hasChildren)break;u.has(R)?T=F.firstChildId:j(R,!0);break;case"ArrowLeft":F.hasChildren&&u.has(R)?j(R,!1):T=F.parentId;break;case"Enter":case" ":C.preventDefault(),$(R,F.hasChildren);return;default:return}C.preventDefault(),T&&T!==R&&S(T)},[g,u,j,S,$]),z=(C,U)=>C.map((R,L)=>{var ae;const F=(ae=R.children)!=null&&ae.length?R.children:null,T=!!F&&u.has(R.id),Z=R.id===p,O=U===1&&C.length>1&&L===C.length-1;return t.jsxs("li",{role:"treeitem","aria-level":U,"aria-expanded":F?T:void 0,"aria-selected":Z,tabIndex:x===R.id?0:-1,"data-ct-id":R.id,className:O?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":U-1},onClick:()=>{v(R.id),$(R.id,!!F)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:F?ce=>{ce.stopPropagation(),v(R.id),j(R.id)}:void 0,children:F?t.jsx(_0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(R.label)}),t.jsx("span",{className:"bim-ct-n",children:R.count.toLocaleString("en-US")})]}),T&&t.jsx("ul",{role:"group",children:z(F,U+1)})]},R.id)});return t.jsxs("ul",{ref:m,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:N,children:[h&&t.jsx("li",{role:"treeitem","aria-level":1,"aria-selected":!p,tabIndex:x===Gt?0:-1,"data-ct-id":Gt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{v(Gt),n(Gt)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true"}),t.jsx("span",{className:"bim-ct-lb",children:l(d)}),t.jsx("span",{className:"bim-ct-n",children:uo(e).toLocaleString("en-US")})]})}),z(e,1)]})}const Hd=e=>`/item/${encodeURIComponent(e)}`;function z0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Dd(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Wd({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Dd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-card",children:t.jsxs("a",{href:i,children:[t.jsxs("div",{className:"bim-ct-ch",children:[t.jsx("h2",{className:"bim-ct-ct",children:r(e.title)}),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),a.length>0&&t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:r(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Ud({work:e,href:i}){var d,c;const{t:n,convert:r}=oe(),o=Dd(e.juan,n),a=((d=e.authors)==null?void 0:d.filter(m=>m.name))??[],l=((c=e.classification)==null?void 0:c.filter(Boolean))??[];return t.jsx("li",{className:"bim-ct-lrow",children:t.jsxs("a",{href:i,children:[t.jsxs("span",{className:"bim-ct-lt",children:[r(e.title),o&&t.jsx("span",{className:"bim-ct-juan",children:r(o)})]}),t.jsx("span",{className:"bim-ct-by",children:a.map((m,p)=>t.jsxs(b.Fragment,{children:[p>0&&"、",m.dynasty&&t.jsxs("span",{className:"bim-ct-dy",children:["〔",r(m.dynasty),"〕"]}),r(m.name)]},p))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>r(m)).join(" · ")})]})})}function Kd({page:e,pageCount:i,onPage:n,pageHref:r,label:o}){const{t:a,convert:l}=oe();if(i<=1)return null;const d=m=>p=>{n&&(r&&!z0(p)||(p.preventDefault(),n(m)))},c=(m,p,h)=>{if(h.disabled)return t.jsx("span",{className:"bim-ct-pg","aria-disabled":"true",children:p});const u={className:"bim-ct-pg","aria-current":h.current?"page":void 0,"aria-label":h.aria};return r?t.jsx("a",{...u,href:r(m),onClick:d(m),children:p}):t.jsx("button",{type:"button",...u,onClick:h.current?void 0:d(m),children:p})};return t.jsxs("nav",{className:"bim-ct-pager","aria-label":o?l(o):a("catalogPage.pagerLabel"),children:[c(e-1,a("catalogPage.prevPage"),{disabled:e<=1}),t.jsx("ol",{children:Fd(e,i).map((m,p)=>t.jsx("li",{style:{display:"contents"},children:m===null?t.jsx("span",{className:"bim-ct-gap","aria-hidden":"true",children:"…"}):c(m,m,{current:m===e,aria:a("catalogPage.pageN",{n:m})})},m??`gap${p}`))}),t.jsxs("span",{className:"bim-ct-pg-of","aria-current":"page",children:[e," / ",i]}),c(e+1,a("catalogPage.nextPage"),{disabled:e>=i})]})}function Yd({works:e,workLink:i=Hd,emptyText:n,view:r="card",...o}){const{t:a,convert:l}=oe();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:n===void 0?a("catalogPage.emptyWorks"):typeof n=="string"?l(n):n}):r==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Ud,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Wd,{work:d,href:i(d.id)},d.id))}),t.jsx(Kd,{...o})]})}const C0=()=>t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",children:t.jsx("path",{d:"M2.5 4.5 6 8l3.5-3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});function E0({tree:e,selectedId:i,page:n,pageCount:r,works:o,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:m,allLabel:p,allTitle:h,pageSize:u=mo,className:f,view:g,onViewChange:y}){const{t:v,convert:w}=oe(),x=p===void 0?v("catalogPage.all"):p,j=h??v("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[N,z]=b.useState(!1),[C,U]=b.useState("card"),R=g??C,L=ce=>{U(ce),y==null||y(ce)},F=wi(e,i&&i!==Gt?i:null),T=F.length?F[F.length-1]:null,Z=T?T.label:j,O=T?T.count:uo(e),ae=b.useCallback(ce=>{z(!1),a(ce)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":N?"open":"closed",children:[t.jsx("style",{children:Od}),t.jsxs("aside",{className:"bim-ct-side","aria-label":v("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":N,"aria-controls":$,onClick:()=>z(ce=>!ce),children:[t.jsx("span",{children:v("catalogPage.drawerLabel",{path:w(F.length?F.map(ce=>ce.label).join(" › "):x??j)})}),t.jsx(C0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:v("catalogPage.classification")}),t.jsx(Bd,{tree:e,selectedId:i,onSelect:ae,allLabel:x})]})]}),t.jsxs("div",{className:"bim-ct-main",children:[t.jsxs("header",{className:"bim-ct-head",children:[t.jsx("h1",{className:"bim-ct-title",children:w(Z)}),F.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:w(F.slice(0,-1).map(ce=>ce.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[v("catalogPage.stat",{total:O.toLocaleString("en-US"),size:u}),r>1&&v("catalogPage.statPage",{page:n,pages:r})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":v("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":R==="card",onClick:()=>L("card"),children:v("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":R==="list",onClick:()=>L("list"),children:v("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Yd,{works:o,view:R,workLink:c,page:n,pageCount:r,onPage:l,pageHref:m})]})]})}const on="(max-width: 719px)",R0="(max-width: 1079px)",T0=`${on}, (pointer: coarse)`,I0=[8,18,30,42,88],po=`
|
|
1720
1720
|
.bim-rh { color: ${s.bim("ink")}; font-family: ${s.bim("font-ui")}; font-size: 14px; line-height: 1.6; }
|
|
1721
1721
|
.bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
|
|
1722
1722
|
.bim-rh a { color: ${s.bim("accent")}; text-decoration: none; }
|
|
@@ -1864,7 +1864,7 @@ ${de??""}`,[Ei,yo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)yo({ke
|
|
|
1864
1864
|
flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
|
|
1865
1865
|
color: ${s.bim("ink")} !important; font-size: 13px;
|
|
1866
1866
|
}
|
|
1867
|
-
${
|
|
1867
|
+
${I0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb, ${s.bim("accent")} ${e}%, ${s.bim("card-bg")}); }`).join(`
|
|
1868
1868
|
`)}
|
|
1869
1869
|
.bim-rh-band a[data-k="4"] { color: ${s.bim("page-bg")} !important; }
|
|
1870
1870
|
.bim-rh-band a:hover { outline: 2px solid ${s.bim("ink")}; outline-offset: -2px; }
|
|
@@ -1892,7 +1892,7 @@ ${T0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1892
1892
|
}
|
|
1893
1893
|
|
|
1894
1894
|
/* ── 中屏 ── */
|
|
1895
|
-
@media ${
|
|
1895
|
+
@media ${R0} {
|
|
1896
1896
|
.bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
1897
1897
|
.bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
1898
1898
|
}
|
|
@@ -1935,7 +1935,7 @@ ${T0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1935
1935
|
}
|
|
1936
1936
|
|
|
1937
1937
|
/* 触屏或窄屏:点击目标放大到 44px */
|
|
1938
|
-
@media ${
|
|
1938
|
+
@media ${T0} {
|
|
1939
1939
|
.bim-rh-rows a, .bim-rh-bu-l a, .bim-rh-au li a, .bim-rh-chip, .bim-rh-secnav a, .bim-rh-expand { min-height: 44px; display: flex; align-items: center; }
|
|
1940
1940
|
.bim-rh-chip { display: inline-flex; }
|
|
1941
1941
|
}
|
|
@@ -1946,7 +1946,7 @@ ${T0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1946
1946
|
}
|
|
1947
1947
|
|
|
1948
1948
|
@media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
|
|
1949
|
-
`,I0=s.readHome["zh-Hant"].period,Kd={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function ii(e){return{...Kd,...e??{}}}function bo(e){var n;const i=(n=e.authors)==null?void 0:n.find(r=>r==null?void 0:r.name);return i?i.dynasty?`${i.dynasty} ${i.name}`:i.name:""}function nr(e){return(e.authors??[]).filter(n=>n==null?void 0:n.name).map(n=>n.dynasty?`〔${n.dynasty}〕${n.name}`:n.name).join(" ")}function Yd(e,i=s.readHome["zh-Hant"].shelfOther){var o;const n=[],r=new Map;for(const a of e){const l=((o=a.period_of)==null?void 0:o.trim())||i;let d=r.get(l);d||(d={label:l,items:[]},r.set(l,d),n.push(d)),d.items.push(a)}return n}function Gd(e){return Math.max(150,Array.from(e).length*18+44)}function Vd(e,i){if(i<=0||e<=0)return 0;const n=e/i;return n<.15?0:n<.35?1:n<.6?2:n<.85?3:4}const qd=.04;function kt(e){return e.toLocaleString("en-US")}function Xd({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((i,n)=>t.jsx("span",{children:i},n))})}function Rt({id:e,title:i,sub:n,more:r,children:o}){const{convert:a}=oe(),l=`${e}-h`;return t.jsxs("section",{className:"bim-rh-sec",id:e,"aria-labelledby":l,children:[t.jsxs("div",{className:"bim-rh-hd",children:[t.jsx("h2",{id:l,children:a(i)}),n&&t.jsx("span",{className:"bim-rh-sub",children:n}),r]}),t.jsx("div",{className:"bim-rh-bd",children:o})]})}function Jd({counts:e}){const{t:i}=oe();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:kt(e.readable)}),i("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:kt(e.pieces)}),i("readHome.pieces")]})]})}function Zd({picks:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=nr(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:o.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(Xd,{text:r(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:r(d)}),t.jsx("h3",{children:r(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:r(l)}),a.blurb&&t.jsx("p",{children:r(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:n("readHome.startReading")})]})]})},a.id)})}):null}function Qd(e,i){return e&&e>1?i("readHome.nCopies",{n:e}):null}function ho({topic:e,links:i,hint:n,legendCount:r,showTitle:o=!0,legendExtra:a}){const{t:l,convert:d}=oe(),c=ii(i);if(!e.items.length)return null;const m=r===void 0?l("readHome.shelfLegendCount"):r,p=Yd(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?kt(u.records):Qd(u.text_count,l),g=bo(u),y=[d(u.title),u.orig?l("readHome.origZhi"):"",g?l("readHome.spineBy",{name:d(g)}):"",u.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":y,title:y,style:{height:Gd(u.title)},children:[t.jsx(Xd,{text:d(u.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:f})]})},u.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[o&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:n?d(n):l("readHome.shelfHint")})]}),t.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":l("readHome.shelfRegion",{label:d(e.label)}),children:t.jsx("ul",{className:"bim-rh-shelf",children:p.map(u=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(u.label),children:u.items.map(h)}),t.jsx("span",{"aria-hidden":"true",children:d(u.label)})]},u.label))})}),t.jsxs("p",{className:"bim-rh-legend",children:[t.jsxs("span",{children:[t.jsx("i",{"data-orig":"","aria-hidden":"true"}),l("readHome.origZhi")]}),t.jsxs("span",{children:[t.jsx("i",{"aria-hidden":"true"}),l("readHome.laterZhi")]}),m&&t.jsx("span",{children:d(m)}),a==null?void 0:a.map(u=>t.jsx("span",{children:d(u)},u))]})]})}const M0=4,qi=e=>e>M0+1;function em({topic:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i),[a,l]=b.useState(!1);if(!e.items.length)return null;const d=`bim-rh-g-${e.key}`;return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nWorks",{n:kt(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const m=Qd(c.text_count,n),p=bo(c);return t.jsx("li",{children:t.jsxs("a",{href:o.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(c.title)}),m&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:m}),p&&t.jsx("small",{children:r(p)})]})},c.id)})}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?n("action.collapse"):n("readHome.allNWorks",{n:e.items.length})})]})}function tm({topics:e,links:i}){const n=e.filter(o=>o.shelf&&o.items.length),r=e.filter(o=>!o.shelf&&o.items.length);return!n.length&&!r.length?null:t.jsxs(t.Fragment,{children:[n.map(o=>t.jsx(ho,{topic:o,links:i},o.key)),r.length>0&&t.jsx("div",{className:"bim-rh-groups",children:r.map(o=>t.jsx(em,{topic:o,links:i},o.key))})]})}function im({famous:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:r(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:r(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:n("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:o.read(c.id),title:r([c.title,c.edition].filter(Boolean).join(" · ")),children:r(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:o.work(a.work_id),children:n("readHome.workPageLink",{title:r(a.title)})})})]})},a.work_id??a.title))}):null}function fo({bu:e,unclassified:i,links:n,unclassifiedNote:r}){const{t:o,convert:a}=oe(),l=ii(n);return!e.length&&!i?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var m;const c=((m=d.top[0])==null?void 0:m.count)||1;return t.jsxs("li",{className:"bim-rh-bu-c",children:[t.jsxs("a",{className:"bim-rh-bu-h",href:l.node(d.id),children:[t.jsx("b",{children:a(d.label)}),t.jsx("span",{className:"bim-rh-num",children:o("readHome.nWorks",{n:kt(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":o("readHome.subClasses",{label:a(d.label)}),children:d.top.map(p=>t.jsx("li",{children:t.jsxs("a",{href:l.node(p.id),children:[t.jsx("span",{children:a(p.label)}),t.jsx("small",{className:"bim-rh-num",children:kt(p.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(p.count/c*100)}%`}})]})},p.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:o("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!i&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:o("readHome.unclassified")}),t.jsx("span",{children:o("readHome.nWorks",{n:kt(i)})}),t.jsx("span",{children:r?a(r):o("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:o("readHome.viewUnclassified")})]})]})}function nm({periods:e,unknown:i,links:n}){const{t:r,convert:o,messages:a}=oe(),l=a.readHome.period,d=ii(n),c=e.filter(h=>h.count>0);if(!c.length)return null;const m=c.reduce((h,u)=>h+u.count,0),p=Math.max(...c.map(h=>h.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(h=>{const u=h.label?o(h.label):l[h.key]??o(h.key),f=h.count/m,g=r("readHome.periodItem",{label:u,n:kt(h.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(h.key),"data-k":Vd(h.count,p),"data-narrow":f<qd?"":void 0,"aria-label":g,title:g,children:[t.jsx("span",{className:"bim-rh-pl",children:u}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(u)[0]}),t.jsx("small",{className:"bim-rh-num",children:kt(h.count)})]})},h.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!i&&t.jsx("span",{children:r("readHome.periodUnknown",{n:kt(i)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:r("readHome.hoverHint")})]})]})}function rm({authors:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[r(a.name),a.dynasty&&t.jsx("span",{children:r(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nPieces",{n:kt(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:o.read(l.id),children:r(l.title)})},l.id))}),o.author&&t.jsx("a",{className:"bim-rh-more",href:o.author(a.name),children:n("readHome.authorAll",{name:r(a.name),n:a.count})})]},a.name))}):null}const sm={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function A0({sections:e,links:i,head:n,piecesMoreHref:r,className:o}){const{t:a}=oe(),l=e,d=sm,c=l.topics.filter(u=>!u.shelf),m={picks:l.picks.length>0,topics:c.some(u=>u.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(u=>u.count>0),pieces:l.pieces.authors.length>0},p=Object.keys(d).filter(u=>m[u]),h=u=>a(`readHome.nav.${u}`);return t.jsxs("div",{className:o?`bim-rh ${o}`:"bim-rh",children:[t.jsx("style",{children:po}),t.jsxs("div",{className:"bim-rh-head",children:[n,t.jsx(Jd,{counts:l.counts})]}),p.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:p.map(u=>t.jsx("li",{children:t.jsx("a",{href:`#${d[u]}`,children:h(u)})},u))})}),t.jsxs("div",{className:"bim-rh-main",children:[m.picks&&t.jsx(Rt,{id:d.picks,title:h("picks"),sub:a("readHome.picksSub"),children:t.jsx(Zd,{picks:l.picks,links:i})}),m.topics&&t.jsx(Rt,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(tm,{topics:c,links:i})}),m.famous&&t.jsx(Rt,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(im,{famous:l.famous,links:i})}),m.sibu&&t.jsx(Rt,{id:d.sibu,title:h("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(fo,{bu:l.bu,unclassified:l.unclassified,links:i})}),m.period&&t.jsx(Rt,{id:d.period,title:h("period"),sub:a("readHome.periodSub"),children:t.jsx(nm,{periods:l.periods,unknown:l.period_unknown,links:i})}),m.pieces&&t.jsx(Rt,{id:d.pieces,title:h("pieces"),sub:a("readHome.piecesSub"),more:r?t.jsx("a",{className:"bim-rh-more",href:r,children:a("readHome.piecesMore")}):void 0,children:t.jsx(rm,{authors:l.pieces.authors,links:i})})]})]})}const L0="(max-width: 1079px)",P0=`${on}, (pointer: coarse)`,om=`
|
|
1949
|
+
`,M0=s.readHome["zh-Hant"].period,Gd={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function ii(e){return{...Gd,...e??{}}}function bo(e){var n;const i=(n=e.authors)==null?void 0:n.find(r=>r==null?void 0:r.name);return i?i.dynasty?`${i.dynasty} ${i.name}`:i.name:""}function nr(e){return(e.authors??[]).filter(n=>n==null?void 0:n.name).map(n=>n.dynasty?`〔${n.dynasty}〕${n.name}`:n.name).join(" ")}function Vd(e,i=s.readHome["zh-Hant"].shelfOther){var o;const n=[],r=new Map;for(const a of e){const l=((o=a.period_of)==null?void 0:o.trim())||i;let d=r.get(l);d||(d={label:l,items:[]},r.set(l,d),n.push(d)),d.items.push(a)}return n}function qd(e){return Math.max(150,Array.from(e).length*18+44)}function Xd(e,i){if(i<=0||e<=0)return 0;const n=e/i;return n<.15?0:n<.35?1:n<.6?2:n<.85?3:4}const Jd=.04;function kt(e){return e.toLocaleString("en-US")}function Zd({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((i,n)=>t.jsx("span",{children:i},n))})}function Rt({id:e,title:i,sub:n,more:r,children:o}){const{convert:a}=oe(),l=`${e}-h`;return t.jsxs("section",{className:"bim-rh-sec",id:e,"aria-labelledby":l,children:[t.jsxs("div",{className:"bim-rh-hd",children:[t.jsx("h2",{id:l,children:a(i)}),n&&t.jsx("span",{className:"bim-rh-sub",children:n}),r]}),t.jsx("div",{className:"bim-rh-bd",children:o})]})}function Qd({counts:e}){const{t:i}=oe();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:kt(e.readable)}),i("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:kt(e.pieces)}),i("readHome.pieces")]})]})}function em({picks:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=nr(a),d=[a.type_label,a.edition].filter(Boolean).join(" · ");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-pk",href:o.read(a.id),children:[t.jsx("span",{className:"bim-rh-slip","aria-hidden":"true",children:t.jsx(Zd,{text:r(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:r(d)}),t.jsx("h3",{children:r(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:r(l)}),a.blurb&&t.jsx("p",{children:r(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:n("readHome.startReading")})]})]})},a.id)})}):null}function tm(e,i){return e&&e>1?i("readHome.nCopies",{n:e}):null}function ho({topic:e,links:i,hint:n,legendCount:r,showTitle:o=!0,legendExtra:a}){const{t:l,convert:d}=oe(),c=ii(i);if(!e.items.length)return null;const m=r===void 0?l("readHome.shelfLegendCount"):r,p=Vd(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?kt(u.records):tm(u.text_count,l),g=bo(u),y=[d(u.title),u.orig?l("readHome.origZhi"):"",g?l("readHome.spineBy",{name:d(g)}):"",u.records?l("readHome.spineRecords",{n:f}):f?l("readHome.spineOnSite",{n:f}):""].filter(Boolean).join(",");return t.jsx("li",{children:t.jsxs("a",{className:"bim-rh-spine",href:c.read(u.id),"data-orig":u.orig?"":void 0,"aria-label":y,title:y,style:{height:qd(u.title)},children:[t.jsx(Zd,{text:d(u.title)}),f&&t.jsx("span",{className:"bim-rh-n bim-rh-num","data-records":u.records?"":void 0,children:f})]})},u.id)};return t.jsxs("div",{className:"bim-rh-shelf-box",children:[o&&t.jsxs("h3",{className:"bim-rh-gt",children:[d(e.label),t.jsx("small",{children:n?d(n):l("readHome.shelfHint")})]}),t.jsx("div",{className:"bim-rh-shelf-wrap",tabIndex:0,role:"region","aria-label":l("readHome.shelfRegion",{label:d(e.label)}),children:t.jsx("ul",{className:"bim-rh-shelf",children:p.map(u=>t.jsxs("li",{className:"bim-rh-era",children:[t.jsx("ul",{className:"bim-rh-spines","aria-label":d(u.label),children:u.items.map(h)}),t.jsx("span",{"aria-hidden":"true",children:d(u.label)})]},u.label))})}),t.jsxs("p",{className:"bim-rh-legend",children:[t.jsxs("span",{children:[t.jsx("i",{"data-orig":"","aria-hidden":"true"}),l("readHome.origZhi")]}),t.jsxs("span",{children:[t.jsx("i",{"aria-hidden":"true"}),l("readHome.laterZhi")]}),m&&t.jsx("span",{children:d(m)}),a==null?void 0:a.map(u=>t.jsx("span",{children:d(u)},u))]})]})}const A0=4,qi=e=>e>A0+1;function im({topic:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i),[a,l]=b.useState(!1);if(!e.items.length)return null;const d=`bim-rh-g-${e.key}`;return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nWorks",{n:kt(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const m=tm(c.text_count,n),p=bo(c);return t.jsx("li",{children:t.jsxs("a",{href:o.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(c.title)}),m&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:m}),p&&t.jsx("small",{children:r(p)})]})},c.id)})}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":a,onClick:()=>l(c=>!c),children:a?n("action.collapse"):n("readHome.allNWorks",{n:e.items.length})})]})}function nm({topics:e,links:i}){const n=e.filter(o=>o.shelf&&o.items.length),r=e.filter(o=>!o.shelf&&o.items.length);return!n.length&&!r.length?null:t.jsxs(t.Fragment,{children:[n.map(o=>t.jsx(ho,{topic:o,links:i},o.key)),r.length>0&&t.jsx("div",{className:"bim-rh-groups",children:r.map(o=>t.jsx(im,{topic:o,links:i},o.key))})]})}function rm({famous:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-works",children:e.map(a=>t.jsx("li",{children:t.jsxs("article",{className:"bim-rh-wk",children:[t.jsxs("div",{className:"bim-rh-wk-h",children:[t.jsx("h3",{children:r(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:r(a.authors)}),t.jsx("span",{className:"bim-rh-c bim-rh-num",children:n("readHome.nCopiesCard",{n:a.text_count})})]}),a.systems.map((l,d)=>t.jsxs("div",{className:"bim-rh-lin",role:"group","aria-label":l.label?r(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:r(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:o.read(c.id),title:r([c.title,c.edition].filter(Boolean).join(" · ")),children:r(c.short)},c.id))]},d)),a.work_id&&t.jsx("div",{className:"bim-rh-wk-f",children:t.jsx("a",{href:o.work(a.work_id),children:n("readHome.workPageLink",{title:r(a.title)})})})]})},a.work_id??a.title))}):null}function fo({bu:e,unclassified:i,links:n,unclassifiedNote:r}){const{t:o,convert:a}=oe(),l=ii(n);return!e.length&&!i?null:t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-bu",children:e.map(d=>{var m;const c=((m=d.top[0])==null?void 0:m.count)||1;return t.jsxs("li",{className:"bim-rh-bu-c",children:[t.jsxs("a",{className:"bim-rh-bu-h",href:l.node(d.id),children:[t.jsx("b",{children:a(d.label)}),t.jsx("span",{className:"bim-rh-num",children:o("readHome.nWorks",{n:kt(d.count)})})]}),d.top.length>0&&t.jsx("ul",{className:"bim-rh-bu-l","aria-label":o("readHome.subClasses",{label:a(d.label)}),children:d.top.map(p=>t.jsx("li",{children:t.jsxs("a",{href:l.node(p.id),children:[t.jsx("span",{children:a(p.label)}),t.jsx("small",{className:"bim-rh-num",children:kt(p.count)}),t.jsx("span",{className:"bim-rh-bar","aria-hidden":"true",style:{"--bimrh-w":`${Math.round(p.count/c*100)}%`}})]})},p.id))}),d.children_total>d.top.length&&t.jsx("a",{className:"bim-rh-bu-more",href:l.node(d.id),children:o("readHome.allNClasses",{label:a(d.label),n:d.children_total})})]},d.id)})}),!!i&&t.jsxs("p",{className:"bim-rh-uncl bim-rh-num",children:[t.jsx("b",{children:o("readHome.unclassified")}),t.jsx("span",{children:o("readHome.nWorks",{n:kt(i)})}),t.jsx("span",{children:r?a(r):o("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:o("readHome.viewUnclassified")})]})]})}function sm({periods:e,unknown:i,links:n}){const{t:r,convert:o,messages:a}=oe(),l=a.readHome.period,d=ii(n),c=e.filter(h=>h.count>0);if(!c.length)return null;const m=c.reduce((h,u)=>h+u.count,0),p=Math.max(...c.map(h=>h.count));return t.jsxs(t.Fragment,{children:[t.jsx("ul",{className:"bim-rh-band",children:c.map(h=>{const u=h.label?o(h.label):l[h.key]??o(h.key),f=h.count/m,g=r("readHome.periodItem",{label:u,n:kt(h.count)});return t.jsx("li",{style:{flex:`0 0 ${(f*100).toFixed(3)}%`},children:t.jsxs("a",{href:d.period(h.key),"data-k":Xd(h.count,p),"data-narrow":f<Jd?"":void 0,"aria-label":g,title:g,children:[t.jsx("span",{className:"bim-rh-pl",children:u}),t.jsx("span",{className:"bim-rh-pl-s","aria-hidden":"true",children:Array.from(u)[0]}),t.jsx("small",{className:"bim-rh-num",children:kt(h.count)})]})},h.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!i&&t.jsx("span",{children:r("readHome.periodUnknown",{n:kt(i)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:r("readHome.hoverHint")})]})]})}function om({authors:e,links:i}){const{t:n,convert:r}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-rh-authors",children:e.map(a=>t.jsxs("li",{className:"bim-rh-au",children:[t.jsxs("h3",{className:"bim-rh-au-h",children:[r(a.name),a.dynasty&&t.jsx("span",{children:r(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nPieces",{n:kt(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:o.read(l.id),children:r(l.title)})},l.id))}),o.author&&t.jsx("a",{className:"bim-rh-more",href:o.author(a.name),children:n("readHome.authorAll",{name:r(a.name),n:a.count})})]},a.name))}):null}const am={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function L0({sections:e,links:i,head:n,piecesMoreHref:r,className:o}){const{t:a}=oe(),l=e,d=am,c=l.topics.filter(u=>!u.shelf),m={picks:l.picks.length>0,topics:c.some(u=>u.items.length>0),famous:l.famous.length>0,sibu:l.bu.length>0||l.unclassified>0,period:l.periods.some(u=>u.count>0),pieces:l.pieces.authors.length>0},p=Object.keys(d).filter(u=>m[u]),h=u=>a(`readHome.nav.${u}`);return t.jsxs("div",{className:o?`bim-rh ${o}`:"bim-rh",children:[t.jsx("style",{children:po}),t.jsxs("div",{className:"bim-rh-head",children:[n,t.jsx(Qd,{counts:l.counts})]}),p.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":a("readHome.navLabel"),children:t.jsx("ul",{children:p.map(u=>t.jsx("li",{children:t.jsx("a",{href:`#${d[u]}`,children:h(u)})},u))})}),t.jsxs("div",{className:"bim-rh-main",children:[m.picks&&t.jsx(Rt,{id:d.picks,title:h("picks"),sub:a("readHome.picksSub"),children:t.jsx(em,{picks:l.picks,links:i})}),m.topics&&t.jsx(Rt,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(nm,{topics:c,links:i})}),m.famous&&t.jsx(Rt,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(rm,{famous:l.famous,links:i})}),m.sibu&&t.jsx(Rt,{id:d.sibu,title:h("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(fo,{bu:l.bu,unclassified:l.unclassified,links:i})}),m.period&&t.jsx(Rt,{id:d.period,title:h("period"),sub:a("readHome.periodSub"),children:t.jsx(sm,{periods:l.periods,unknown:l.period_unknown,links:i})}),m.pieces&&t.jsx(Rt,{id:d.pieces,title:h("pieces"),sub:a("readHome.piecesSub"),more:r?t.jsx("a",{className:"bim-rh-more",href:r,children:a("readHome.piecesMore")}):void 0,children:t.jsx(om,{authors:l.pieces.authors,links:i})})]})]})}const P0="(max-width: 1079px)",O0=`${on}, (pointer: coarse)`,lm=`
|
|
1950
1950
|
/* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
|
|
1951
1951
|
.bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
|
|
1952
1952
|
.bim-mh-q { min-width: 0; }
|
|
@@ -2086,7 +2086,7 @@ ${T0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
2086
2086
|
.bim-mh-cc0 { display: inline-block; margin-right: 8px; padding: 1px 7px; font-size: 11.5px; letter-spacing: 0.08em; background: ${s.bim("check-fine-bg")}; color: ${s.bim("check-fine-fg")}; }
|
|
2087
2087
|
|
|
2088
2088
|
/* ── 中屏 ── */
|
|
2089
|
-
@media ${
|
|
2089
|
+
@media ${P0} {
|
|
2090
2090
|
.bim-mh-head, .bim-mh-zhi { grid-template-columns: minmax(0, 1fr); }
|
|
2091
2091
|
.bim-mh-cg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
2092
2092
|
.bim-mh-lin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
@@ -2113,8 +2113,8 @@ ${T0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
2113
2113
|
.bim-mh-tbl tr > :nth-child(2), .bim-mh-tbl tr > :nth-child(3) { display: none; }
|
|
2114
2114
|
}
|
|
2115
2115
|
|
|
2116
|
-
@media ${
|
|
2116
|
+
@media ${O0} {
|
|
2117
2117
|
.bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
|
|
2118
2118
|
.bim-mh-recent-h button { min-height: 44px; }
|
|
2119
2119
|
}
|
|
2120
|
-
`,am={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ni(e){return{...am,...e??{}}}function lm(e,i){if(e.lineage)return e.lineage(i);const n=e.item(i),r=n.indexOf("#"),[o,a]=r<0?[n,""]:[n.slice(0,r),n.slice(r)];return`${o}${o.includes("?")?"&":"?"}tab=lineage${a}`}function go(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function cm(e){const i=e.filter(m=>Number.isFinite(m.birth_year)||Number.isFinite(m.death_year)),n=e.filter(m=>!i.includes(m));if(!i.length)return{min:0,max:0,placed:[],missing:n};const r=m=>{const p=Number.isFinite(m.birth_year)?m.birth_year:m.death_year-50,h=Number.isFinite(m.death_year)?m.death_year:m.birth_year+50;return[Math.min(p,h),Math.max(p,h)]},o=i.map(r),a=Math.min(...o.map(m=>m[0])),l=Math.max(...o.map(m=>m[1])),d=Math.max(1,l-a),c=i.map((m,p)=>({p:m,from:o[p][0],to:o[p][1]})).sort((m,p)=>m.from-p.from).map(m=>({...m,left:(m.from-a)/d*100,width:Math.max(.8,(m.to-m.from)/d*100)}));return{min:a,max:l,placed:c,missing:n}}function Bn(e,i=s.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function O0(e){return{read:e.item,work:e.item,node:e.node}}function dm({counts:e,links:i}){const{t:n}=oe(),r=i==null?void 0:i.type;if(!r)return null;const o=[["all",n("metaHome.typeAll"),null],["work",n("metaHome.typeLabel.work"),e.works],["book",n("metaHome.typeLabel.book"),e.books],["collection",n("metaHome.typeLabel.collection"),e.collections],["entity",n("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":n("metaHome.typeChipsLabel"),children:o.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:r(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:kt(d)})]})},a))})}function mm(e,i=5){const[n,r]=b.useState(null);b.useEffect(()=>{let a=!1;const l=ei().slice(0,i);if(!l.length||!e){r([]);return}return Promise.all(l.map(d=>zs(e,d))).then(d=>{a||r(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{Ns(),r([])},[]);return{entries:n,clear:o}}function F0(e,i,n){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?n(r):um(e.type,i)}function um(e,i){return i(`metaHome.typeLabel.${e}`)}function pm({entries:e,onClear:i,links:n}){const{t:r,convert:o}=oe(),a=ni(n);return t.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[t.jsxs("div",{className:"bim-mh-recent-h",children:[t.jsx("h2",{id:"bim-mh-recent-h",children:r("metaHome.recentTitle")}),e&&e.length>0&&i&&t.jsx("button",{type:"button",onClick:i,children:r("metaHome.recentClear")})]}),e&&e.length>0&&t.jsx("ol",{children:e.map(l=>t.jsx("li",{children:t.jsxs("a",{href:a.item(l.id),"aria-label":r("metaHome.recentItemLabel",{type:l.type?um(l.type,r):"",title:o(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?r(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:o(l.title)}),t.jsx("small",{"aria-hidden":"true",children:F0(l,r,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function bm(e,i,n,r=!1){return r&&(e==="done"||e==="in_progress")?i(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?i(`metaHome.status.${e}`):n(e)}function hm({rows:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":n("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[n("metaHome.catalogTitle"),t.jsx("small",{children:n("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:n("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:n("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:n("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=go(a.imported,a.total),d=a.work_id??a.collection_id,c=r(a.edition?`${a.name}·${a.edition}`:a.name);return t.jsxs("tr",{children:[t.jsx("th",{scope:"row",children:d?t.jsx("a",{href:o.item(d),children:c}):c}),t.jsx("td",{className:"bim-mh-r",children:kt(a.total)}),t.jsx("td",{className:"bim-mh-r",children:kt(a.imported)}),t.jsx("td",{children:t.jsxs("span",{className:"bim-mh-meter",children:[t.jsx("i",{"aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[l,"%"]})]})}),t.jsx("td",{children:a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:bm(a.status,n,r)})})]},a.id||a.name)})})]})}):null}function fm({items:e,links:i,label:n}){const{convert:r}=oe();return t.jsx("ul",{className:"bim-rh-rows","aria-label":n?r(n):void 0,children:e.map(o=>t.jsx("li",{children:t.jsxs("a",{href:i.item(o.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(o.title)}),o.sub&&t.jsx("small",{children:r(o.sub)})]})},o.id))})}function gm({works:e,links:i}){const{t:n}=oe(),[r,o]=b.useState(!1);if(!e.length)return null;const a=qi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":r?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(fm,{items:e.map(l=>({id:l.id,title:l.title,sub:nr(l)||void 0})),links:ni(i)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":r,onClick:()=>o(l=>!l),children:r?n("action.collapse"):n("metaHome.allNWorks",{n:e.length})})]})}const xm="siku_qige";function B0({group:e,links:i}){const{t:n,convert:r}=oe(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(fm,{items:e.items,links:i,label:e.label}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>a(l=>!l),children:o?n("action.collapse"):n("metaHome.allNKinds",{n:e.items.length})})]})}function ym({groups:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const a=e.find(c=>c.key===xm),l=e.filter(c=>c!==a),d=c=>{var m;return((m=c.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:m[1])??c};return t.jsxs(t.Fragment,{children:[a&&t.jsxs(t.Fragment,{children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(a.label),t.jsx("small",{children:r(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":r(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:o.item(c.id),"aria-label":r(c.title),title:r(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:r(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:n("metaHome.pavilion")})]})},c.id))})]}),l.length>0&&t.jsx("div",{className:"bim-mh-cg",style:a?void 0:{marginTop:0},children:l.map(c=>t.jsx(B0,{group:c,links:o},c.key))})]})}const yl=34,jl=13;function kl(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Bn(e.birth_year,i):"?"}–${e.death_year!=null?Bn(e.death_year,i):"?"}`}function H0(e,i){const n=i-e,r=n>1200?300:n>400?100:50,o=[];for(let a=Math.ceil(e/r)*r;a<=i;a+=r)o.push(a);return o}function jm({people:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=cm(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-jl):u.left;let y=0;for(;m[y]!=null&&m[y]>g;)y++;return m[y]=f?u.left+u.width:u.left+Math.max(u.width,jl),{...u,lane:y,end:f}}),h=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[p.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:m.length*yl+10},children:p.map(u=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":u.end?"":void 0,style:{left:`${u.left}%`,top:u.lane*yl+4,width:`${Math.max(u.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:o.item(u.p.id),children:[r(u.p.name),t.jsx("small",{className:"bim-rh-num",children:kl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:H0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:Bn(u,n)},u))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":p.length?void 0:"",children:(p.length?e:c).map(u=>t.jsx("li",{children:t.jsxs("a",{href:o.item(u.id),children:[t.jsx("span",{children:r(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?r(u.dynasty):"",kl(u,n)].filter(Boolean).join(" ")})]})},u.id))}),c.length>0&&p.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:n("metaHome.missingLife",{names:r(c.map(u=>u.name).join("、"))})})]})}const D0=t.jsxs("svg",{width:"54",height:"34",viewBox:"0 0 54 34",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",children:[t.jsx("circle",{cx:"27",cy:"5",r:"3.5"}),t.jsx("circle",{cx:"10",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"27",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"44",cy:"29",r:"3.5"}),t.jsx("path",{d:"M27 8.5v17M27 15H10v10.5M27 15h17v10.5"})]});function km({works:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=nr(a);return t.jsx("li",{children:t.jsxs("a",{href:lm(o,a.id),children:[D0,t.jsx("b",{children:r(a.title)}),l&&t.jsx("small",{children:r(l)}),t.jsx("span",{children:n("metaHome.viewLineage")})]})},a.id)})}):null}function wm({sites:e}){const{t:i,convert:n}=oe(),r=e.filter(a=>a.status!=="todo"&&a.total>0),o=e.filter(a=>!r.includes(a));return e.length?t.jsxs(t.Fragment,{children:[r.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:r.map(a=>{const l=go(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:n(a.name)}):t.jsx("span",{children:n(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${kt(a.imported)} / ${kt(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:bm(a.status,i,n,!0)})]})]},a.id||a.name)})}),o.length>0&&t.jsx("p",{className:"bim-mh-todo",children:i("metaHome.plannedSites",{names:n(o.map(a=>a.name).join("、"))})})]}):null}const wl=["extant","partially_extant","lost","unknown"];function vm({stats:e,links:i,version:n,repoUrl:r,downloadHref:o}){const{t:a}=oe(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(m=>[e[m],a(`metaHome.stat.${m}`)]).filter(([m])=>m>0),d=i==null?void 0:i.loss,c=wl.some(m=>{var p;return(((p=e.loss)==null?void 0:p[m])??0)>0});return t.jsxs("div",{className:"bim-mh-data",children:[l.length>0&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.dataScale")}),t.jsx("ul",{className:"bim-mh-nums",children:l.map(([m,p])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:kt(m)}),t.jsx("span",{children:p})]},p))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:wl.map(m=>{var u;const p=((u=e.loss)==null?void 0:u[m])??0,h=a(`metaHome.lossNote.${m}`);return t.jsx("li",{children:t.jsxs("a",{href:d(m),children:[a(`metaHome.loss.${m}`),t.jsx("small",{className:"bim-rh-num",children:c&&p>0?a("metaHome.lossCount",{n:kt(p),note:h}):h})]})},m)})})]}),t.jsxs("div",{className:"bim-mh-lic",children:[t.jsxs("p",{children:[t.jsx("span",{className:"bim-mh-cc0",children:"CC BY-SA 4.0"}),a("metaHome.license")]}),t.jsxs("p",{children:[a("metaHome.repo"),r?t.jsx("a",{href:r,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),n&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:n})]}),o&&t.jsx("p",{children:t.jsx("a",{href:o,children:a("metaHome.download")})})]})]})}const Sm={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function W0({sections:e,links:i,head:n,transport:r,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,N;const{t:h}=oe(),u=e,f=ni(i),g=O0(f),y=Sm,v=mm(r),w={zhi:!!(($=u.shelf)!=null&&$.items.length)||u.catalog_progress.length>0||u.related_catalogs.length>0,sibu:u.bu.length>0||u.unclassified>0,cong:u.collection_groups.length>0,people:u.bibliographers.length>0,lineage:u.lineage.length>0,sites:u.sites.length>0,data:!0},x=Object.keys(y).filter(z=>w[z]),j=z=>h(`metaHome.nav.${z}`),S=(z,C)=>z?t.jsx("a",{className:"bim-rh-more",href:z,children:C}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:po+om}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(dm,{counts:u.counts,links:i})]}),r&&t.jsx(pm,{entries:v.entries,onClear:v.clear,links:i})]}),x.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":h("metaHome.navLabel"),children:t.jsx("ul",{children:x.map(z=>t.jsx("li",{children:t.jsx("a",{href:`#${y[z]}`,children:j(z)})},z))})}),t.jsxs("div",{className:"bim-rh-main",children:[w.zhi&&t.jsxs(Rt,{id:y.zhi,title:j("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(ho,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:g,showTitle:!1,legendCount:u.shelf.items.some(z=>z.records)?h("metaHome.shelfLegendCount"):null,legendExtra:[h("metaHome.shelfLegendClick")]}),(u.catalog_progress.length>0||u.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(N=u.shelf)!=null&&N.items.length?void 0:{marginTop:0},children:[t.jsx(hm,{rows:u.catalog_progress,links:i}),t.jsx(gm,{works:u.related_catalogs,links:i})]})]}),w.sibu&&t.jsx(Rt,{id:y.sibu,title:j("sibu"),sub:h("metaHome.sibuSub"),more:S(o,h("metaHome.toCatalog")),children:t.jsx(fo,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),w.cong&&t.jsx(Rt,{id:y.cong,title:j("cong"),sub:h("metaHome.congSub"),more:S(a,h("metaHome.allNKindsMore",{n:kt(u.counts.collections)})),children:t.jsx(ym,{groups:u.collection_groups,links:i})}),w.people&&t.jsx(Rt,{id:y.people,title:j("people"),sub:h("metaHome.peopleSub"),more:S(l,h("metaHome.allNPeopleMore",{n:kt(u.counts.entities)})),children:t.jsx(jm,{people:u.bibliographers,links:i})}),w.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(km,{works:u.lineage,links:i})}),w.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(wm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx(vm,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const $m=["_related","_catalogs","_collections","_members","_children","_book_groups"],U0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),bs=e=>U0(e)&&!!e.h;function K0(e){return e?$m.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(bs)}):!1}function Y0(e,i){const n={...e};if(!i)return n;for(const r of $m){const o=e[r];!Array.isArray(o)||!o.some(bs)||(n[r]=o.map(a=>{var c;if(!bs(a)||typeof a.title=="string"&&a.title)return a;const l=a.id??a.bid,d=l?(c=i[l])==null?void 0:c.title:void 0;return d?{...a,title:d}:a}))}return n}function G0(e){let i=null;const n=()=>e.getHubs?(i??(i=e.getHubs().catch(()=>null)),i):Promise.resolve(null);return new Proxy(e,{get(r,o){if(o==="getItem")return async l=>{const d=await r.getItem(l);return d&&Y0(d,K0(d)?await n():null)};const a=Reflect.get(r,o,r);return typeof a=="function"?a.bind(r):a}})}const hs=({style:e})=>{const i=b.useContext(s.LocaleContext),{t:n}=oe();if(!i)return null;const{locale:r,setLocale:o}=i,a=r==="zh-Hant",l=()=>o(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:n(a?"common.toHans":"common.toHant"),style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${s.bim("border")}`,borderRadius:"4px",background:s.bim("bg"),color:s.bim("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?s.bim("primary"):void 0,fontWeight:a?700:400},children:n("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:s.bim("primary"),fontWeight:a?400:700},children:n("common.localeShortHans")})]})},fs=({href:e,label:i,size:n=16,className:r,style:o})=>{const{t:a}=oe(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:n+8,height:n+8,borderRadius:4,color:s.bim("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...o},onMouseEnter:d=>{d.currentTarget.style.color=s.bim("fg")},onMouseLeave:d=>{d.currentTarget.style.color=s.bim("desc-fg")},children:t.jsx("svg",{width:n,height:n,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})})};function Ur(e){const i=e.text_count;return typeof i=="number"&&i>0}function Kr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function V0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const q0=({id:e,transport:i,initialDetail:n,initialEntry:r,activeTab:o,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:m,lineageCollection:p,onLineageCollectionChange:h,initialPage:u=1,selectedLineageNodeId:f,onNavigate:g,onBack:y,backLabel:v,renderLink:w,assetBase:x,enrichDetail:j,getSourceLink:S,readLink:$,railTop:N,extraTabs:z=[],showFeedbackTab:C=!0,feedbackApiUrl:U,height:R,footerExtra:L,hideHeaderControls:F=!1,className:T,style:Z})=>{const O=b.useMemo(()=>G0(i),[i]),ae=b.useMemo(()=>gd(O)??ro(U),[O,U]),ce=s.useT(),{t:Ee,convert:we}=oe(),[ye]=b.useState(()=>{if(!V0(e,n))return null;const ee={...n},Se=r??Kr(e,ee);return j&&j(Se,ee),{id:e,entry:Se,detail:ee}}),[Q,Ne]=b.useState((ye==null?void 0:ye.entry)??null),[W,je]=b.useState((ye==null?void 0:ye.detail)??null),[K,V]=b.useState(!ye),[re,X]=b.useState(!1),[I,ue]=b.useState([]),[fe,ze]=b.useState(!1),[B,pe]=b.useState(null),[Te,ve]=b.useState(null),[Ve,qe]=b.useState(null),[Xe,J]=b.useState(!1),ie=b.useRef(null),me=b.useRef(0),[se,de]=b.useState(null),ge=l!==void 0?l:se,Oe=b.useCallback(ee=>{d?d(ee):de(ee)},[d]),Je=b.useCallback(async ee=>{if(!O.getCollectionCatalogs&&!O.getCollectionCatalog){ue([]);return}ze(!0);try{if(O.getCollectionCatalogs)ue(await O.getCollectionCatalogs(ee)||[]);else if(O.getCollectionCatalog){const Se=await O.getCollectionCatalog(ee);ue(Se?[{resource_id:"",data:Se}]:[])}}catch{ue([])}finally{ze(!1)}},[O]),Pe=b.useCallback(async ee=>{var Se,et;if(!O.getTextManifest||!O.getTextIndex){pe(null),ve(ee);return}try{const tt=_e.pickTextVersion(await O.getTextManifest(ee)),De=tt?await O.getTextIndex(ee,tt.key):null;pe(De&&De.chapters.length>0?{chapters:De.chapters.map(Fe=>({n:Fe.n,title:Fe.title,file:Fe.file})),source:{name:((Se=De.source)==null?void 0:Se.name)??(tt==null?void 0:tt.source_name),license:((et=De.source)==null?void 0:et.license)??(tt==null?void 0:tt.license)??void 0}}:null)}catch{pe(null)}finally{ve(ee)}},[O]),Ue=b.useCallback(async(ee,Se)=>{const et=++me.current,tt=()=>et!==me.current;J(!0);try{if(O.getLineageGraph){const gt=await O.getLineageGraph(ee);if(tt())return;gt&&qe(gt)}const De=Se.version_graph;if(!De||!De.enabled){Ve||qe(null),ie.current=null;return}const Fe=Ss(Se),bt=(await tr(Fe,er,async gt=>{try{return await O.getItem(gt)}catch{return null}},tt)).filter(Boolean);if(tt())return;ie.current={work:Se,books:bt};const ht=p??De.default_collection??(De.core_books&&De.core_books.length>0?"core":"all"),We=ht==="core"&&Array.isArray(De.core_books)&&De.core_books.length>0?"core":ht??"all";qe(Sn(Se,bt,We))}catch{if(tt())return;qe(null),ie.current=null}finally{tt()||J(!1)}},[O]),nt=b.useRef({initialDetail:n,initialEntry:r});nt.current={initialDetail:n,initialEntry:r},b.useEffect(()=>{let ee=!1;me.current++,J(!1);const Se=Fe=>{Fe.type==="collection"?Je(e):Fe.type==="work"?(Fe.version_graph||O.getLineageGraph)&&Ue(e,Fe):Fe.type==="book"&&Ur(Fe)&&Pe(e)},et=nt.current;let tt=null;if(ye&&ye.id===e)tt=ye;else if(et.initialDetail&&et.initialDetail.id===e){const Fe={...et.initialDetail},pt=et.initialEntry??Kr(e,Fe);j&&j(pt,Fe),tt={entry:pt,detail:Fe}}return tt?(X(!1),ue(Fe=>Fe.length?[]:Fe),pe(null),qe(null),ie.current=null,Ne(tt.entry),je(tt.detail),V(!1),Se(tt.detail),()=>{ee=!0}):((async()=>{V(!0),X(!1),Ne(null),je(null),ue([]),pe(null),qe(null),ie.current=null;try{const Fe=await O.getItem(e);if(ee)return;if(!Fe){X(!0);return}const pt=Fe;let bt=null;if(O.getEntry&&(bt=await O.getEntry(e),ee))return;bt||(bt=Kr(e,pt)),j&&j(bt,pt),Ne(bt),je(pt),Se(pt)}catch{ee||X(!0)}finally{ee||V(!1)}})(),()=>{ee=!0})},[e,O,ye,j,Je,Ue,Pe]),b.useEffect(()=>{const ee=ie.current;!ee||!p||qe(Sn(ee.work,ee.books,p))},[p]);const Y=[];if(W){if(Y.push({key:"basic",label:ce.detailTab.basicInfo}),W.type==="collection"){fe&&I.length===0&&Y.push({key:"catalog:loading",label:`${ce.detailTab.catalog}…`});for(const ee of I)Y.push({key:`catalog:${ee.resource_id}`,label:ee.short_name?`${we(ee.short_name)}${ce.detailTab.catalogSuffix}`:ce.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&Y.push({key:o,label:ce.detailTab.fullText}),W.type==="work"&&(Ve||Xe)&&Y.push({key:"lineage",label:Xe?`${ce.detailTab.lineage}…`:ce.detailTab.lineage});for(const ee of z)(ee.position??"before-feedback")==="before-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label});C&&o==="feedback"&&Y.push({key:"feedback",label:ce.detailTab.feedback});for(const ee of z)ee.position==="after-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label})}b.useEffect(()=>{if(o!=="emendated"||!W)return;a("basic");const ee=setTimeout(()=>{var Se;(Se=document.getElementById("studies"))==null||Se.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(ee)},[o,W,a]);const M=Q&&W&&S?S({activeTab:o,activeJuan:ge,entry:Q,detail:W}):null,k=b.useMemo(()=>{var De,Fe,pt,bt,ht;if(!W)return null;const Se=(W.authors??[]).map(We=>{const gt=vs(We.role);return`${We.dynasty?`〔${we(We.dynasty)}〕`:""}${we(We.name)}${gt?` ${we(gt)}`:""}`}).join(" · ");let et=!1;try{et=_e.extractStatus(W.id)==="draft"}catch{}if(W.type==="book"){const We=W;return{title:we(We.title),subtitle:We.edition?we(We.edition):Se||void 0,aside:[et?ce.status.draft:"",Se&&We.edition?Se:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(W.type==="collection"){const We=W;return{title:we(We.title),subtitle:we(qt(We,ce.unit.juan))||void 0,aside:[(De=We.publication_info)==null?void 0:De.year,et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:Se||void 0}}if(W.type==="entity"){const We=W,gt=A=>A==null?"":A<0?Ee("detail.bce",{n:-A}):String(A),te=((Fe=We.dates)==null?void 0:Fe.birth)!=null||((pt=We.dates)==null?void 0:pt.death)!=null?`${gt(((bt=We.dates)==null?void 0:bt.birth)??void 0)||"?"}—${gt(((ht=We.dates)==null?void 0:ht.death)??void 0)||"?"}`:"";return{title:we(We.primary_name||We.title),subtitle:[We.dynasty?`〔${we(We.dynasty)}〕`:"",te].filter(Boolean).join(" ")||void 0,aside:et?ce.status.draft:void 0,secondLine:void 0}}const tt=we(qt(W,ce.unit.juan));return{title:we(W.title),subtitle:[tt,Se].filter(Boolean).join(" · ")||void 0,aside:[J0(ce,W.subtype),et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[W,we,ce,Ee]),P=W&&Ur(W)?"text":null,q=()=>{Oe(null),a("fulltext")};let _=null;if(W&&$){const ee=$({detail:W,kind:P});ee&&(_=t.jsx(ts,{href:ee}))}else P&&(_=t.jsx(ts,{onClick:q}));const le=ee=>{if(!W)return null;const Se=ee.replace(/\.[^.]+$/,"");if($){const et=$({detail:W,kind:P,juan:Se});return et?{href:et}:null}return{onClick:()=>{Oe(Se),a("fulltext")}}},H=new Set(z.map(ee=>ee.key)),he=Y.filter(ee=>ee.key.startsWith("catalog:")&&ee.key!=="catalog:loading"||ee.key==="lineage"&&!!Ve&&!Xe||H.has(ee.key)).map(ee=>({key:ee.key,label:ee.label,onClick:()=>a(ee.key)})),xe=()=>{var ee;return W?W.type==="work"?t.jsx(zd,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he}):W.type==="book"?t.jsx(Rd,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,fullText:B,fullTextPending:Ur(W)&&!!O.getTextManifest&&Te!==W.id,chapterLink:le,railTop:N,railLinks:he}):W.type==="collection"?t.jsx(Td,{data:W,catalog:(ee=I[0])==null?void 0:ee.data,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he,catalogAction:I.length>0?t.jsxs("a",{href:"#catalog",onClick:Se=>{Se.preventDefault(),a(`catalog:${I[0].resource_id}`)},children:[we(ce.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Ad,{data:W,transport:O,onNavigate:g,renderLink:w,railTop:N,railLinks:he,assetBase:x}):null},Re=()=>{var Se,et,tt;if(!Q||!W)return null;if(o==="basic"||o==="emendated")return xe();if(typeof o=="string"&&o.startsWith("catalog:")){const De=(Se=I.find(Fe=>`catalog:${Fe.resource_id}`===o))==null?void 0:Se.data;return t.jsx(tc,{data:De,onNavigate:g,renderLink:w})}if(o==="collated"||o==="fulltext")return t.jsx(fd,{id:e,transport:O,chapter:ge,onLocationChange:De=>Oe(De.chapter),onNavigate:g});if(o==="lineage"){if(!Ve)return t.jsx("div",{style:{color:s.bim("label-fg"),padding:"24px 0"},children:Ee(Xe?"detail.loading":"detail.noLineageGraph")});const De=W.type==="work"?W:null;return t.jsx(lo,{graph:Ve,renderLink:w,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((et=De==null?void 0:De.version_graph)==null?void 0:et.default_collection),onCollectionChange:h,collectionsAvailable:(tt=De==null?void 0:De.version_graph)==null?void 0:tt.collections,collectionCounts:(()=>{var ht,We,gt,te,A,ne,$e;if(!De)return;const Fe={},pt=((ht=ie.current)==null?void 0:ht.books)??[];Fe.all=(((We=De._books)==null?void 0:We.length)??0)-(((te=(gt=De.version_graph)==null?void 0:gt.excluded_books)==null?void 0:te.length)??0);const bt=(A=De.version_graph)==null?void 0:A.collections;if(bt)for(const Ie of Object.keys(bt))Fe[Ie]=Sn(De,pt,Ie).nodes.filter(Le=>Le.kind==="book"&&!Le.bridge).length;return Fe.core==null&&(($e=(ne=De.version_graph)==null?void 0:ne.core_books)!=null&&$e.length)&&(Fe.core=De.version_graph.core_books.length),Fe})()})}if(o==="feedback"&&C)return t.jsx(vd,{resourceId:e,transport:ae});const ee=z.find(De=>De.key===o);return ee?ee.render({detail:W,entry:Q,transport:O,onNavigate:g}):null};if(K)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((ee,Se)=>t.jsx("div",{style:{height:Se===1?40:16,width:ee,opacity:.35,background:s.bim("rule")}},Se))})});if(re||!W||!Q||!k)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:s.bim("label-fg"),fontSize:14},children:Ee("detail.notFound")})});const Ze=o==="basic"||o==="emendated",Me=[{label:v??ce.detailTab.backToIndex,onClick:y}];if(W.type==="book"&&W.work_id){const ee=W.work_id;Me.push({label:ce.indexType.work,id:ee,onClick:()=>g==null?void 0:g(ee)})}Me.push({label:ce.indexType[W.type]});const He=o==="collated"||o==="fulltext",ct=typeof L=="string"?ce.status[L.trim()]??L:L,Be=t.jsx(Mc,{left:t.jsxs(t.Fragment,{children:[ct,ct?" · ":"",t.jsx(X0,{id:W.id,label:ce.label.id,copied:ce.action.copied,copyLabel:ce.action.copy})]}),right:t.jsxs(t.Fragment,{children:[C&&!Ze&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.submitVersion}),M&&t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:s.bim("meta-fg")},children:ce.detailTab.dataLicense})]})});return Ze?t.jsx("div",{className:T,children:t.jsxs(Hi,{grid:!0,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsx(ns,{items:Me}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{style:{border:"none",background:"transparent"}}),!F&&M&&t.jsx(fs,{...M})]})}),xe(),Be]})}):t.jsx("div",{className:T,children:t.jsxs(Hi,{wide:He,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Ms,{char:"籍"}),t.jsx(ns,{items:Me})]}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{}),C&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.feedback}),!F&&M&&t.jsx(fs,{...M})]})}),t.jsx(Sc,{...k,aside:He?t.jsxs("button",{type:"button",onClick:()=>a("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("accent"),borderBottom:`1px solid ${s.bim("rule")}`},children:[Ee("detail.workInfo")," →"]}):k.aside}),!He&&Y.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:Y.map(ee=>t.jsx($c,{label:ee.label,active:ee.key===o||Ze&&ee.key==="basic",onClick:()=>a(ee.key)},ee.key))}),t.jsx("div",{style:{marginTop:!He&&Y.length>1?8:0},children:Re()}),Be]})})};function X0({id:e,label:i,copied:n,copyLabel:r}){const[o,a]=b.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[i," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var l;(l=navigator.clipboard)==null||l.writeText(e).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},title:o?n:r,"aria-label":o?n:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:s.bim("aux-fg")},children:o?"✓":"⧉"})]})}function J0(e,i){return i?e.workSubtype[i]??i:""}const _m=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],rr="zhusha",sr="bim-theme";function Nm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function or(e){return Nm(e)?e:rr}function Z0(){try{return or(window.localStorage.getItem(sr))}catch{return rr}}function zm(e){try{window.localStorage.setItem(sr,e)}catch{}}function Cm(e){const i=or(e);return document.documentElement.setAttribute("data-theme",i),i}function Em(){return or(document.documentElement.getAttribute("data-theme"))}const Q0=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],xo="airy",ar="bim-layout";function Rm(e){return e==="airy"||e==="boxed"}function lr(e){return Rm(e)?e:xo}function ey(){try{return lr(window.localStorage.getItem(ar))}catch{return xo}}function ty(e){try{window.localStorage.setItem(ar,e)}catch{}}function iy(e){const i=lr(e);return document.documentElement.setAttribute("data-layout",i),i}function ny(){return lr(document.documentElement.getAttribute("data-layout"))}const ry=`try{var t=localStorage.getItem(${JSON.stringify(sr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(ar)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,sy={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},oy=({onChange:e,style:i})=>{const{t:n}=oe(),[r,o]=b.useState(rr);b.useEffect(()=>{o(Em())},[]);const a=l=>{o(Cm(l)),zm(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:_m.map(l=>{const d=r===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":n(`common.theme.${l.name}`),title:n(`common.theme.${l.name}`),onClick:()=>a(l.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:s.bim(sy[l.name]),boxShadow:d?`0 0 0 2px ${s.bim("page-bg")}, 0 0 0 3.5px ${s.bim("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=_e.BidLink;exports.BookIndexError=_e.BookIndexError;exports.BookIndexManager=_e.BookIndexManager;exports.BookIndexStorage=_e.BookIndexStorage;exports.BundleStorage=_e.BundleStorage;exports.ConfigError=_e.ConfigError;exports.GithubStorage=_e.GithubStorage;exports.IdGenerationError=_e.IdGenerationError;exports.IdGenerator=_e.IdGenerator;exports.LocalStorage=_e.LocalStorage;exports.MigrationError=_e.MigrationError;exports.StorageError=_e.StorageError;exports.adaptCharCord=_e.adaptCharCord;exports.adaptFig=_e.adaptFig;exports.adaptNorm=_e.adaptNorm;exports.adaptNormDetailed=_e.adaptNormDetailed;exports.adaptPunctJson=_e.adaptPunctJson;exports.base36Decode=_e.base36Decode;exports.base36Encode=_e.base36Encode;exports.base58Decode=_e.base58Decode;exports.buildId=_e.buildId;exports.buildPromotionMap=_e.buildPromotionMap;exports.cleanName=_e.cleanName;exports.decodeId=_e.decodeId;exports.decodeIdString=_e.decodeIdString;exports.encodeId=_e.encodeId;exports.extractIdFromUrl=_e.extractIdFromUrl;exports.extractStatus=_e.extractStatus;exports.extractType=_e.extractType;exports.iiifVolumeOf=_e.iiifVolumeOf;exports.isChapterSegment=_e.isChapterSegment;exports.isTextKey=_e.isTextKey;exports.loadFigUrls=_e.loadFigUrls;exports.loadReaderChapter=_e.loadReaderChapter;exports.loadReaderFiles=_e.loadReaderFiles;exports.matchChapterAcrossVersions=_e.matchChapterAcrossVersions;exports.normalizeCatalog=_e.normalizeCatalog;exports.parseId=_e.parseId;exports.pickTextVersion=_e.pickTextVersion;exports.readerManifest=_e.readerManifest;exports.readerVersions=_e.readerVersions;exports.shardOf=_e.shardOf;exports.smartDecode=_e.smartDecode;exports.textVersionLabel=_e.textVersionLabel;exports.validateResource=_e.validateResource;exports.volumeFromChar=_e.volumeFromChar;exports.Badge=s.Badge;exports.COMMON_TRADITIONAL_CHARS=s.COMMON_TRADITIONAL_CHARS;exports.FormInput=s.FormInput;exports.FormTextArea=s.FormTextArea;exports.LocaleContext=s.LocaleContext;exports.Section=s.Section;exports.TRADITIONAL_ALLOWLIST=s.TRADITIONAL_ALLOWLIST;exports.buildPageUrl=s.buildPageUrl;exports.findTraditionalChars=s.findTraditionalChars;exports.formatTemplate=s.formatTemplate;exports.getDisplayNameFromUrl=s.getDisplayNameFromUrl;exports.getMessages=s.getMessages;exports.getStartPage=s.getStartPage;exports.getT=s.getT;exports.getTypeGroupKey=s.getTypeGroupKey;exports.mergeVolumeResources=s.mergeVolumeResources;exports.normalizeVolumes=s.normalizeVolumes;exports.resourceHref=s.resourceHref;exports.useT=s.useT;exports.volumeStats=s.volumeStats;exports.VARIANT_CHARS=vi.VARIANT_CHARS;exports.normalizeVariants=vi.normalizeVariants;exports.VARIANT_SUPPLEMENT=au.VARIANT_SUPPLEMENT;exports.BidUrlProvider=cu;exports.BookDetailLayout=q0;exports.BookPage=Rd;exports.Breadcrumb=ns;exports.CATALOG_ALL_ID=Gt;exports.CATALOG_CSS=Ld;exports.CATALOG_NARROW_QUERY=co;exports.CATALOG_PAGE_SIZE=mo;exports.CATALOG_UNCLASSIFIED_ID=di;exports.CLASSIFICATIONS=qn;exports.CardFoot=nn;exports.CatalogPage=C0;exports.CatalogPager=Wd;exports.CatalogTree=Od;exports.CheckFilter=kc;exports.Chip=_c;exports.ChipWall=$b;exports.CollectionCatalog=tc;exports.CollectionPage=Td;exports.DEFAULT_LAYOUT=xo;exports.DEFAULT_META_HOME_LINKS=am;exports.DEFAULT_READER_PREFS=Rs;exports.DEFAULT_READ_HOME_LINKS=Kd;exports.DEFAULT_THEME=rr;exports.DETAIL_CSS=vc;exports.DYNASTY_GROUPS=Vn;exports.Dash=Rb;exports.DataTable=Nb;exports.DetailFooter=Mc;exports.DetailGrid=Zi;exports.DetailHeader=Sc;exports.EMPTY_FILTERS=Gn;exports.ENTITY_TEXT_CSS=Xs;exports.EmptyNote=Ob;exports.EntityMark=Qs;exports.EntityPage=Ad;exports.EntityText=Mf;exports.ExpandRow=Tb;exports.ExtLink=Fb;exports.FEEDBACK_FAB_OFFSET_VAR=ds;exports.FILTER_SUPPORT=Yl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=kb;exports.FeedbackButton=Gg;exports.FeedbackDialog=xd;exports.FeedbackForm=yd;exports.FeedbackList=wd;exports.FeedbackTab=vd;exports.FilterChip=$c;exports.GUJI_MARKDOWN_FIELD=ob;exports.GUJI_TABLE_NOTATION=Ac;exports.GlyphBadge=Ms;exports.GujiInteractiveReader=Eg;exports.GujiTable=Ps;exports.GujiTextViewer=to;exports.GujiWarpCanvas=qs;exports.ImagePanel=Xr;exports.IndexBrowser=kp;exports.IntroGrid=jb;exports.LAYOUTS=Q0;exports.LAYOUT_STORAGE_KEY=ar;exports.LOSS_OPTIONS=Kl;exports.LocaleProvider=pu;exports.LocaleToggle=hs;exports.META_HOME_CSS=om;exports.META_HOME_SECTION_IDS=Sm;exports.MetaCatalogTable=hm;exports.MetaCollectionGroups=ym;exports.MetaDataLicense=vm;exports.MetaHomeView=W0;exports.MetaLine=vt;exports.MetaLineageCards=km;exports.MetaOnlineSites=wm;exports.MetaPeopleTimeline=jm;exports.MetaRecentPanel=pm;exports.MetaRelatedCatalogs=gm;exports.MetaTypeChips=dm;exports.ModeIndicator=zl;exports.MoreButton=Sb;exports.MoreLink=Ts;exports.PAGE_MAX_WIDTH=zn;exports.PERIOD_NARROW_SHARE=qd;exports.PageFrame=Hi;exports.Quote=Mb;exports.READER_CSS=sc;exports.READ_HOME_CSS=po;exports.READ_HOME_NARROW_QUERY=on;exports.READ_HOME_SECTION_IDS=sm;exports.READ_PERIOD_LABELS=I0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Fl;exports.ReadButton=ts;exports.ReadFamousWorks=im;exports.ReadHomeView=A0;exports.ReadPeriodBand=nm;exports.ReadPicks=Zd;exports.ReadPieces=rm;exports.ReadSection=Rt;exports.ReadShelf=ho;exports.ReadSibu=fo;exports.ReadStats=Jd;exports.ReadTopicGroup=em;exports.ReadTopics=tm;exports.ReaderMdText=Hs;exports.ReaderShell=uc;exports.ReaderToc=oc;exports.RepoSourceLink=fs;exports.ResourceGroup=Ab;exports.ResourceLine=Lb;exports.ResourceList=xu;exports.ResourceRow=Rc;exports.SEARCH_VIEW_STORAGE_KEY=_s;exports.SEVEN_PAVILIONS_KEY=xm;exports.SNIPPET_MARK_END=$l;exports.SNIPPET_MARK_START=Sl;exports.SORTABLE_TYPES=Ul;exports.SearchInput=El;exports.SearchResults=Zl;exports.Sec=St;exports.SectionHead=wb;exports.SideList=mi;exports.StripWarpRenderer=rs;exports.SummaryCard=tn;exports.THEMES=_m;exports.THEME_INIT_SCRIPT=ry;exports.THEME_STORAGE_KEY=sr;exports.TabFilter=Qi;exports.TableHead=zb;exports.TableRow=Cb;exports.TagRow=Tc;exports.TagRows=Pb;exports.TextButton=vb;exports.TextReader=fd;exports.ThemeToggle=oy;exports.TopStrip=is;exports.VersionLineageGraph=Ed;exports.VersionLineageList=Cd;exports.VersionLineageView=lo;exports.VolumeChips=_b;exports.VolumeLinks=As;exports.WorkCard=Hd;exports.WorkCardGrid=Ud;exports.WorkCatalog=Rg;exports.WorkPage=zd;exports.WorkRow=Dd;exports.adaptEntityJson=Gc;exports.applyLayout=iy;exports.applyTheme=Cm;exports.authorsLine=nr;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Bs;exports.bucketResources=js;exports.buildCatalogTree=j0;exports.buildCollectionTable=Dl;exports.buildLineageGraph=Sn;exports.buildMeiliFilter=ip;exports.buildParagraphBlocks=Dc;exports.buildVersionRow=ks;exports.buildVersionTable=Ol;exports.canParagraphize=Ln;exports.catalogNodeIdOf=x0;exports.catalogNodeIdsOf=y0;exports.catalogPageCount=S0;exports.catalogTotal=uo;exports.classificationPath=sn;exports.clearAllRecentIds=Ns;exports.compareCatalogCards=v0;exports.computeVersionPartition=Ku;exports.countActiveFilters=Xn;exports.createFeedbackTransport=ro;exports.createTextApi=ic;exports.currentLayout=ny;exports.currentTheme=Em;exports.defaultEntityHref=rd;exports.defaultWorkLink=Fd;exports.deriveDating=Lu;exports.deriveEditionType=Wl;exports.deriveEra=Ji;exports.deriveYear=Un;exports.deriveYearRange=ys;exports.detectGenre=Zn;exports.displayAuthorRole=vs;exports.eraRank=Yr;exports.feedbackTransportOf=gd;exports.filtersFromParams=np;exports.filtersToParams=An;exports.findCatalogPath=wi;exports.firstAuthorText=bo;exports.flattenTitles=Ic;exports.flattenToc=mc;exports.fmtCount=kt;exports.formatHitCount=$n;exports.formatVolumeRange=Yn;exports.groupRelatedWorks=Pu;exports.gujiInlineToPlain=yc;exports.hasActiveFilters=Gl;exports.hasGujiMarkdownV02=ab;exports.hasGujiTableNotation=Bb;exports.hasSearchOptions=Qu;exports.headingKey=no;exports.headingsFromPunct=md;exports.isCountedChar=Ds;exports.isDuiduChapter=Rn;exports.isLayoutName=Rm;exports.isThemeName=Nm;exports.lineageHref=lm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Xc;exports.nestHeadings=pd;exports.normalizeEra=Tt;exports.normalizeLayout=lr;exports.normalizeRole=ws;exports.normalizeTheme=or;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Gi;exports.paginationItems=Pd;exports.parseChineseNumber=In;exports.parseGujiInline=xc;exports.parseGujiTable=Pc;exports.parseHeadingKey=ud;exports.pct=go;exports.periodLevel=Vd;exports.pickReaderVersion=dc;exports.readStoredLayout=ey;exports.readStoredTheme=Z0;exports.readerVersionOptionLabel=Qr;exports.remapPlainOffsets=Vc;exports.removeRecentId=Ql;exports.renderFullTextBody=Xb;exports.renderProperNames=Kc;exports.renderReaderInline=Qn;exports.resolveRecentEntry=zs;exports.resourceNote=Kn;exports.resultTabFromParam=pp;exports.resultTabToParam=bp;exports.roleFacets=Bl;exports.rowNo=Eb;exports.sameFilters=rp;exports.sanitizeHeadings=cs;exports.saveRecentId=Vr;exports.segmentEntities=qc;exports.setImageSourceResolver=Nf;exports.shelfColumns=Yd;exports.sortFor=ep;exports.sortYear=Mn;exports.spineHeight=Gd;exports.splitFullTextTables=Ls;exports.splitHighlightSnippet=gs;exports.splitTableRow=Lc;exports.storeLayout=ty;exports.storeTheme=zm;exports.summaryFromEntry=td;exports.summaryFromItem=ed;exports.timelineLayout=cm;exports.toCatalogWorkCard=w0;exports.transportSummaryLoader=id;exports.typeSupportsFilters=Vl;exports.useBidUrl=It;exports.useChapterWarpData=dd;exports.useConvert=xt;exports.useEntitySummaryLoader=Zs;exports.useI18n=oe;exports.useReaderPrefs=cc;exports.useRecentEntries=mm;exports.validateLineageGraph=Nu;exports.withDefaultLinks=ii;exports.withMetaLinks=ni;exports.yearText=Bn;
|
|
2120
|
+
`,cm={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ni(e){return{...cm,...e??{}}}function dm(e,i){if(e.lineage)return e.lineage(i);const n=e.item(i),r=n.indexOf("#"),[o,a]=r<0?[n,""]:[n.slice(0,r),n.slice(r)];return`${o}${o.includes("?")?"&":"?"}tab=lineage${a}`}function go(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function mm(e){const i=e.filter(m=>Number.isFinite(m.birth_year)||Number.isFinite(m.death_year)),n=e.filter(m=>!i.includes(m));if(!i.length)return{min:0,max:0,placed:[],missing:n};const r=m=>{const p=Number.isFinite(m.birth_year)?m.birth_year:m.death_year-50,h=Number.isFinite(m.death_year)?m.death_year:m.birth_year+50;return[Math.min(p,h),Math.max(p,h)]},o=i.map(r),a=Math.min(...o.map(m=>m[0])),l=Math.max(...o.map(m=>m[1])),d=Math.max(1,l-a),c=i.map((m,p)=>({p:m,from:o[p][0],to:o[p][1]})).sort((m,p)=>m.from-p.from).map(m=>({...m,left:(m.from-a)/d*100,width:Math.max(.8,(m.to-m.from)/d*100)}));return{min:a,max:l,placed:c,missing:n}}function Bn(e,i=s.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function F0(e){return{read:e.item,work:e.item,node:e.node}}function um({counts:e,links:i}){const{t:n}=oe(),r=i==null?void 0:i.type;if(!r)return null;const o=[["all",n("metaHome.typeAll"),null],["work",n("metaHome.typeLabel.work"),e.works],["book",n("metaHome.typeLabel.book"),e.books],["collection",n("metaHome.typeLabel.collection"),e.collections],["entity",n("metaHome.typeLabel.entity"),e.entities]];return t.jsx("ul",{className:"bim-mh-types bim-rh-num","aria-label":n("metaHome.typeChipsLabel"),children:o.map(([a,l,d])=>t.jsx("li",{children:t.jsxs("a",{href:r(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:kt(d)})]})},a))})}function pm(e,i=5){const[n,r]=b.useState(null);b.useEffect(()=>{let a=!1;const l=ei().slice(0,i);if(!l.length||!e){r([]);return}return Promise.all(l.map(d=>zs(e,d))).then(d=>{a||r(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{Ns(),r([])},[]);return{entries:n,clear:o}}function B0(e,i,n){const r=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return r?n(r):bm(e.type,i)}function bm(e,i){return i(`metaHome.typeLabel.${e}`)}function hm({entries:e,onClear:i,links:n}){const{t:r,convert:o}=oe(),a=ni(n);return t.jsxs("aside",{className:"bim-mh-recent","aria-labelledby":"bim-mh-recent-h",children:[t.jsxs("div",{className:"bim-mh-recent-h",children:[t.jsx("h2",{id:"bim-mh-recent-h",children:r("metaHome.recentTitle")}),e&&e.length>0&&i&&t.jsx("button",{type:"button",onClick:i,children:r("metaHome.recentClear")})]}),e&&e.length>0&&t.jsx("ol",{children:e.map(l=>t.jsx("li",{children:t.jsxs("a",{href:a.item(l.id),"aria-label":r("metaHome.recentItemLabel",{type:l.type?bm(l.type,r):"",title:o(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?r(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:o(l.title)}),t.jsx("small",{"aria-hidden":"true",children:B0(l,r,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:r("metaHome.recentEmpty")})]})}function fm(e,i,n,r=!1){return r&&(e==="done"||e==="in_progress")?i(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?i(`metaHome.status.${e}`):n(e)}function gm({rows:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("div",{className:"bim-mh-tbl-wrap",tabIndex:0,role:"region","aria-label":n("metaHome.catalogTitle"),children:t.jsxs("table",{className:"bim-mh-tbl",children:[t.jsxs("caption",{children:[n("metaHome.catalogTitle"),t.jsx("small",{children:n("metaHome.catalogNote")})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:n("metaHome.colCatalog")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colRecords")}),t.jsx("th",{scope:"col",className:"bim-mh-r",children:n("metaHome.colMatched")}),t.jsx("th",{scope:"col",children:n("metaHome.colProgress")}),t.jsx("th",{scope:"col",children:n("metaHome.colStatus")})]})}),t.jsx("tbody",{children:e.map(a=>{const l=go(a.imported,a.total),d=a.work_id??a.collection_id,c=r(a.edition?`${a.name}·${a.edition}`:a.name);return t.jsxs("tr",{children:[t.jsx("th",{scope:"row",children:d?t.jsx("a",{href:o.item(d),children:c}):c}),t.jsx("td",{className:"bim-mh-r",children:kt(a.total)}),t.jsx("td",{className:"bim-mh-r",children:kt(a.imported)}),t.jsx("td",{children:t.jsxs("span",{className:"bim-mh-meter",children:[t.jsx("i",{"aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[l,"%"]})]})}),t.jsx("td",{children:a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:fm(a.status,n,r)})})]},a.id||a.name)})})]})}):null}function xm({items:e,links:i,label:n}){const{convert:r}=oe();return t.jsx("ul",{className:"bim-rh-rows","aria-label":n?r(n):void 0,children:e.map(o=>t.jsx("li",{children:t.jsxs("a",{href:i.item(o.id),children:[t.jsx("span",{className:"bim-rh-t",children:r(o.title)}),o.sub&&t.jsx("small",{children:r(o.sub)})]})},o.id))})}function ym({works:e,links:i}){const{t:n}=oe(),[r,o]=b.useState(!1);if(!e.length)return null;const a=qi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":r?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(xm,{items:e.map(l=>({id:l.id,title:l.title,sub:nr(l)||void 0})),links:ni(i)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":r,onClick:()=>o(l=>!l),children:r?n("action.collapse"):n("metaHome.allNWorks",{n:e.length})})]})}const jm="siku_qige";function H0({group:e,links:i}){const{t:n,convert:r}=oe(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(xm,{items:e.items,links:i,label:e.label}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>a(l=>!l),children:o?n("action.collapse"):n("metaHome.allNKinds",{n:e.items.length})})]})}function km({groups:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const a=e.find(c=>c.key===jm),l=e.filter(c=>c!==a),d=c=>{var m;return((m=c.match(/(文[^\s·・閣阁]+)[閣阁]/))==null?void 0:m[1])??c};return t.jsxs(t.Fragment,{children:[a&&t.jsxs(t.Fragment,{children:[t.jsxs("h3",{className:"bim-rh-gt",children:[r(a.label),t.jsx("small",{children:r(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":r(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:o.item(c.id),"aria-label":r(c.title),title:r(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:r(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:n("metaHome.pavilion")})]})},c.id))})]}),l.length>0&&t.jsx("div",{className:"bim-mh-cg",style:a?void 0:{marginTop:0},children:l.map(c=>t.jsx(H0,{group:c,links:o},c.key))})]})}const kl=34,wl=13;function vl(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Bn(e.birth_year,i):"?"}–${e.death_year!=null?Bn(e.death_year,i):"?"}`}function D0(e,i){const n=i-e,r=n>1200?300:n>400?100:50,o=[];for(let a=Math.ceil(e/r)*r;a<=i;a+=r)o.push(a);return o}function wm({people:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=mm(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-wl):u.left;let y=0;for(;m[y]!=null&&m[y]>g;)y++;return m[y]=f?u.left+u.width:u.left+Math.max(u.width,wl),{...u,lane:y,end:f}}),h=Math.max(1,l-a);return t.jsxs(t.Fragment,{children:[p.length>0&&t.jsxs("div",{className:"bim-mh-tl",children:[t.jsx("ul",{className:"bim-mh-tl-rows",style:{height:m.length*kl+10},children:p.map(u=>t.jsxs("li",{className:"bim-mh-tl-bar","data-end":u.end?"":void 0,style:{left:`${u.left}%`,top:u.lane*kl+4,width:`${Math.max(u.width,.5)}%`},children:[t.jsx("i",{"aria-hidden":"true",style:{width:"100%"}}),t.jsxs("a",{href:o.item(u.p.id),children:[r(u.p.name),t.jsx("small",{className:"bim-rh-num",children:vl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:D0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:Bn(u,n)},u))})]}),t.jsx("ul",{className:"bim-mh-tl-list","data-only":p.length?void 0:"",children:(p.length?e:c).map(u=>t.jsx("li",{children:t.jsxs("a",{href:o.item(u.id),children:[t.jsx("span",{children:r(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?r(u.dynasty):"",vl(u,n)].filter(Boolean).join(" ")})]})},u.id))}),c.length>0&&p.length>0&&t.jsx("p",{className:"bim-mh-tl-foot",children:n("metaHome.missingLife",{names:r(c.map(u=>u.name).join("、"))})})]})}const W0=t.jsxs("svg",{width:"54",height:"34",viewBox:"0 0 54 34",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",children:[t.jsx("circle",{cx:"27",cy:"5",r:"3.5"}),t.jsx("circle",{cx:"10",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"27",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"44",cy:"29",r:"3.5"}),t.jsx("path",{d:"M27 8.5v17M27 15H10v10.5M27 15h17v10.5"})]});function vm({works:e,links:i}){const{t:n,convert:r}=oe(),o=ni(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=nr(a);return t.jsx("li",{children:t.jsxs("a",{href:dm(o,a.id),children:[W0,t.jsx("b",{children:r(a.title)}),l&&t.jsx("small",{children:r(l)}),t.jsx("span",{children:n("metaHome.viewLineage")})]})},a.id)})}):null}function Sm({sites:e}){const{t:i,convert:n}=oe(),r=e.filter(a=>a.status!=="todo"&&a.total>0),o=e.filter(a=>!r.includes(a));return e.length?t.jsxs(t.Fragment,{children:[r.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:r.map(a=>{const l=go(a.imported,a.total);return t.jsxs("li",{children:[a.url?t.jsx("a",{href:a.url,rel:"noopener noreferrer",target:"_blank",children:n(a.name)}):t.jsx("span",{children:n(a.name)}),t.jsx("span",{className:"bim-mh-bar","aria-hidden":"true",style:{"--bimmh-w":`${l}%`}}),t.jsxs("small",{children:[`${kt(a.imported)} / ${kt(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:fm(a.status,i,n,!0)})]})]},a.id||a.name)})}),o.length>0&&t.jsx("p",{className:"bim-mh-todo",children:i("metaHome.plannedSites",{names:n(o.map(a=>a.name).join("、"))})})]}):null}const Sl=["extant","partially_extant","lost","unknown"];function $m({stats:e,links:i,version:n,repoUrl:r,downloadHref:o}){const{t:a}=oe(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(m=>[e[m],a(`metaHome.stat.${m}`)]).filter(([m])=>m>0),d=i==null?void 0:i.loss,c=Sl.some(m=>{var p;return(((p=e.loss)==null?void 0:p[m])??0)>0});return t.jsxs("div",{className:"bim-mh-data",children:[l.length>0&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.dataScale")}),t.jsx("ul",{className:"bim-mh-nums",children:l.map(([m,p])=>t.jsxs("li",{children:[t.jsx("b",{className:"bim-rh-num",children:kt(m)}),t.jsx("span",{children:p})]},p))})]}),d&&t.jsxs("div",{children:[t.jsx("h3",{className:"bim-rh-gt",children:a("metaHome.byLoss")}),t.jsx("ul",{className:"bim-mh-loss",children:Sl.map(m=>{var u;const p=((u=e.loss)==null?void 0:u[m])??0,h=a(`metaHome.lossNote.${m}`);return t.jsx("li",{children:t.jsxs("a",{href:d(m),children:[a(`metaHome.loss.${m}`),t.jsx("small",{className:"bim-rh-num",children:c&&p>0?a("metaHome.lossCount",{n:kt(p),note:h}):h})]})},m)})})]}),t.jsxs("div",{className:"bim-mh-lic",children:[t.jsxs("p",{children:[t.jsx("span",{className:"bim-mh-cc0",children:"CC BY-SA 4.0"}),a("metaHome.license")]}),t.jsxs("p",{children:[a("metaHome.repo"),r?t.jsx("a",{href:r,children:t.jsx("code",{children:"book-index"})}):t.jsx("code",{children:"book-index"}),a("metaHome.repoNote")]}),n&&t.jsxs("p",{children:[a("metaHome.version"),t.jsx("code",{children:n})]}),o&&t.jsx("p",{children:t.jsx("a",{href:o,children:a("metaHome.download")})})]})]})}const _m={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function U0({sections:e,links:i,head:n,transport:r,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,N;const{t:h}=oe(),u=e,f=ni(i),g=F0(f),y=_m,v=pm(r),w={zhi:!!(($=u.shelf)!=null&&$.items.length)||u.catalog_progress.length>0||u.related_catalogs.length>0,sibu:u.bu.length>0||u.unclassified>0,cong:u.collection_groups.length>0,people:u.bibliographers.length>0,lineage:u.lineage.length>0,sites:u.sites.length>0,data:!0},x=Object.keys(y).filter(z=>w[z]),j=z=>h(`metaHome.nav.${z}`),S=(z,C)=>z?t.jsx("a",{className:"bim-rh-more",href:z,children:C}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:po+lm}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(um,{counts:u.counts,links:i})]}),r&&t.jsx(hm,{entries:v.entries,onClear:v.clear,links:i})]}),x.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":h("metaHome.navLabel"),children:t.jsx("ul",{children:x.map(z=>t.jsx("li",{children:t.jsx("a",{href:`#${y[z]}`,children:j(z)})},z))})}),t.jsxs("div",{className:"bim-rh-main",children:[w.zhi&&t.jsxs(Rt,{id:y.zhi,title:j("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(ho,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:g,showTitle:!1,legendCount:u.shelf.items.some(z=>z.records)?h("metaHome.shelfLegendCount"):null,legendExtra:[h("metaHome.shelfLegendClick")]}),(u.catalog_progress.length>0||u.related_catalogs.length>0)&&t.jsxs("div",{className:"bim-mh-zhi",style:(N=u.shelf)!=null&&N.items.length?void 0:{marginTop:0},children:[t.jsx(gm,{rows:u.catalog_progress,links:i}),t.jsx(ym,{works:u.related_catalogs,links:i})]})]}),w.sibu&&t.jsx(Rt,{id:y.sibu,title:j("sibu"),sub:h("metaHome.sibuSub"),more:S(o,h("metaHome.toCatalog")),children:t.jsx(fo,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),w.cong&&t.jsx(Rt,{id:y.cong,title:j("cong"),sub:h("metaHome.congSub"),more:S(a,h("metaHome.allNKindsMore",{n:kt(u.counts.collections)})),children:t.jsx(km,{groups:u.collection_groups,links:i})}),w.people&&t.jsx(Rt,{id:y.people,title:j("people"),sub:h("metaHome.peopleSub"),more:S(l,h("metaHome.allNPeopleMore",{n:kt(u.counts.entities)})),children:t.jsx(wm,{people:u.bibliographers,links:i})}),w.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(vm,{works:u.lineage,links:i})}),w.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(Sm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx($m,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const Nm=["_related","_catalogs","_collections","_members","_children","_book_groups"],K0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),bs=e=>K0(e)&&!!e.h;function Y0(e){return e?Nm.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(bs)}):!1}function G0(e,i){const n={...e};if(!i)return n;for(const r of Nm){const o=e[r];!Array.isArray(o)||!o.some(bs)||(n[r]=o.map(a=>{var c;if(!bs(a)||typeof a.title=="string"&&a.title)return a;const l=a.id??a.bid,d=l?(c=i[l])==null?void 0:c.title:void 0;return d?{...a,title:d}:a}))}return n}function V0(e){let i=null;const n=()=>e.getHubs?(i??(i=e.getHubs().catch(()=>null)),i):Promise.resolve(null);return new Proxy(e,{get(r,o){if(o==="getItem")return async l=>{const d=await r.getItem(l);return d&&G0(d,Y0(d)?await n():null)};const a=Reflect.get(r,o,r);return typeof a=="function"?a.bind(r):a}})}const hs=({style:e})=>{const i=b.useContext(s.LocaleContext),{t:n}=oe();if(!i)return null;const{locale:r,setLocale:o}=i,a=r==="zh-Hant",l=()=>o(a?"zh-Hans":"zh-Hant");return t.jsxs("button",{type:"button",onClick:l,title:n(a?"common.toHans":"common.toHant"),style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:`1px solid ${s.bim("border")}`,borderRadius:"4px",background:s.bim("bg"),color:s.bim("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?s.bim("primary"):void 0,fontWeight:a?700:400},children:n("common.localeShortHant")}),t.jsx("span",{style:{opacity:.3},children:"/"}),t.jsx("span",{style:{color:a?void 0:s.bim("primary"),fontWeight:a?400:700},children:n("common.localeShortHans")})]})},fs=({href:e,label:i,size:n=16,className:r,style:o})=>{const{t:a}=oe(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:n+8,height:n+8,borderRadius:4,color:s.bim("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...o},onMouseEnter:d=>{d.currentTarget.style.color=s.bim("fg")},onMouseLeave:d=>{d.currentTarget.style.color=s.bim("desc-fg")},children:t.jsx("svg",{width:n,height:n,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:t.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})})};function Ur(e){const i=e.text_count;return typeof i=="number"&&i>0}function Kr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function q0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const X0=({id:e,transport:i,initialDetail:n,initialEntry:r,activeTab:o,onTabChange:a,activeJuan:l,onJuanChange:d,lineageMode:c="list",onLineageModeChange:m,lineageCollection:p,onLineageCollectionChange:h,initialPage:u=1,selectedLineageNodeId:f,onNavigate:g,onBack:y,backLabel:v,renderLink:w,assetBase:x,enrichDetail:j,getSourceLink:S,readLink:$,railTop:N,extraTabs:z=[],showFeedbackTab:C=!0,feedbackApiUrl:U,height:R,footerExtra:L,hideHeaderControls:F=!1,className:T,style:Z})=>{const O=b.useMemo(()=>V0(i),[i]),ae=b.useMemo(()=>yd(O)??ro(U),[O,U]),ce=s.useT(),{t:Ee,convert:we}=oe(),[ye]=b.useState(()=>{if(!q0(e,n))return null;const ee={...n},Se=r??Kr(e,ee);return j&&j(Se,ee),{id:e,entry:Se,detail:ee}}),[Q,Ne]=b.useState((ye==null?void 0:ye.entry)??null),[W,je]=b.useState((ye==null?void 0:ye.detail)??null),[K,V]=b.useState(!ye),[re,J]=b.useState(!1),[I,ue]=b.useState([]),[fe,ze]=b.useState(!1),[B,pe]=b.useState(null),[Te,ve]=b.useState(null),[Ve,qe]=b.useState(null),[Xe,X]=b.useState(!1),ie=b.useRef(null),me=b.useRef(0),[se,de]=b.useState(null),ge=l!==void 0?l:se,Oe=b.useCallback(ee=>{d?d(ee):de(ee)},[d]),Je=b.useCallback(async ee=>{if(!O.getCollectionCatalogs&&!O.getCollectionCatalog){ue([]);return}ze(!0);try{if(O.getCollectionCatalogs)ue(await O.getCollectionCatalogs(ee)||[]);else if(O.getCollectionCatalog){const Se=await O.getCollectionCatalog(ee);ue(Se?[{resource_id:"",data:Se}]:[])}}catch{ue([])}finally{ze(!1)}},[O]),Pe=b.useCallback(async ee=>{var Se,et;if(!O.getTextManifest||!O.getTextIndex){pe(null),ve(ee);return}try{const tt=_e.pickTextVersion(await O.getTextManifest(ee)),De=tt?await O.getTextIndex(ee,tt.key):null;pe(De&&De.chapters.length>0?{chapters:De.chapters.map(Fe=>({n:Fe.n,title:Fe.title,file:Fe.file})),source:{name:((Se=De.source)==null?void 0:Se.name)??(tt==null?void 0:tt.source_name),license:((et=De.source)==null?void 0:et.license)??(tt==null?void 0:tt.license)??void 0}}:null)}catch{pe(null)}finally{ve(ee)}},[O]),Ue=b.useCallback(async(ee,Se)=>{const et=++me.current,tt=()=>et!==me.current;X(!0);try{if(O.getLineageGraph){const gt=await O.getLineageGraph(ee);if(tt())return;gt&&qe(gt)}const De=Se.version_graph;if(!De||!De.enabled){Ve||qe(null),ie.current=null;return}const Fe=Ss(Se),bt=(await tr(Fe,er,async gt=>{try{return await O.getItem(gt)}catch{return null}},tt)).filter(Boolean);if(tt())return;ie.current={work:Se,books:bt};const ht=p??De.default_collection??(De.core_books&&De.core_books.length>0?"core":"all"),We=ht==="core"&&Array.isArray(De.core_books)&&De.core_books.length>0?"core":ht??"all";qe(Sn(Se,bt,We))}catch{if(tt())return;qe(null),ie.current=null}finally{tt()||X(!1)}},[O]),nt=b.useRef({initialDetail:n,initialEntry:r});nt.current={initialDetail:n,initialEntry:r},b.useEffect(()=>{let ee=!1;me.current++,X(!1);const Se=Fe=>{Fe.type==="collection"?Je(e):Fe.type==="work"?(Fe.version_graph||O.getLineageGraph)&&Ue(e,Fe):Fe.type==="book"&&Ur(Fe)&&Pe(e)},et=nt.current;let tt=null;if(ye&&ye.id===e)tt=ye;else if(et.initialDetail&&et.initialDetail.id===e){const Fe={...et.initialDetail},pt=et.initialEntry??Kr(e,Fe);j&&j(pt,Fe),tt={entry:pt,detail:Fe}}return tt?(J(!1),ue(Fe=>Fe.length?[]:Fe),pe(null),qe(null),ie.current=null,Ne(tt.entry),je(tt.detail),V(!1),Se(tt.detail),()=>{ee=!0}):((async()=>{V(!0),J(!1),Ne(null),je(null),ue([]),pe(null),qe(null),ie.current=null;try{const Fe=await O.getItem(e);if(ee)return;if(!Fe){J(!0);return}const pt=Fe;let bt=null;if(O.getEntry&&(bt=await O.getEntry(e),ee))return;bt||(bt=Kr(e,pt)),j&&j(bt,pt),Ne(bt),je(pt),Se(pt)}catch{ee||J(!0)}finally{ee||V(!1)}})(),()=>{ee=!0})},[e,O,ye,j,Je,Ue,Pe]),b.useEffect(()=>{const ee=ie.current;!ee||!p||qe(Sn(ee.work,ee.books,p))},[p]);const Y=[];if(W){if(Y.push({key:"basic",label:ce.detailTab.basicInfo}),W.type==="collection"){fe&&I.length===0&&Y.push({key:"catalog:loading",label:`${ce.detailTab.catalog}…`});for(const ee of I)Y.push({key:`catalog:${ee.resource_id}`,label:ee.short_name?`${we(ee.short_name)}${ce.detailTab.catalogSuffix}`:ce.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&Y.push({key:o,label:ce.detailTab.fullText}),W.type==="work"&&(Ve||Xe)&&Y.push({key:"lineage",label:Xe?`${ce.detailTab.lineage}…`:ce.detailTab.lineage});for(const ee of z)(ee.position??"before-feedback")==="before-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label});C&&o==="feedback"&&Y.push({key:"feedback",label:ce.detailTab.feedback});for(const ee of z)ee.position==="after-feedback"&&ee.shouldShow(W)&&Y.push({key:ee.key,label:ee.label})}b.useEffect(()=>{if(o!=="emendated"||!W)return;a("basic");const ee=setTimeout(()=>{var Se;(Se=document.getElementById("studies"))==null||Se.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(ee)},[o,W,a]);const M=Q&&W&&S?S({activeTab:o,activeJuan:ge,entry:Q,detail:W}):null,k=b.useMemo(()=>{var De,Fe,pt,bt,ht;if(!W)return null;const Se=(W.authors??[]).map(We=>{const gt=vs(We.role);return`${We.dynasty?`〔${we(We.dynasty)}〕`:""}${we(We.name)}${gt?` ${we(gt)}`:""}`}).join(" · ");let et=!1;try{et=_e.extractStatus(W.id)==="draft"}catch{}if(W.type==="book"){const We=W;return{title:we(We.title),subtitle:We.edition?we(We.edition):Se||void 0,aside:[et?ce.status.draft:"",Se&&We.edition?Se:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(W.type==="collection"){const We=W;return{title:we(We.title),subtitle:we(qt(We,ce.unit.juan))||void 0,aside:[(De=We.publication_info)==null?void 0:De.year,et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:Se||void 0}}if(W.type==="entity"){const We=W,gt=A=>A==null?"":A<0?Ee("detail.bce",{n:-A}):String(A),te=((Fe=We.dates)==null?void 0:Fe.birth)!=null||((pt=We.dates)==null?void 0:pt.death)!=null?`${gt(((bt=We.dates)==null?void 0:bt.birth)??void 0)||"?"}—${gt(((ht=We.dates)==null?void 0:ht.death)??void 0)||"?"}`:"";return{title:we(We.primary_name||We.title),subtitle:[We.dynasty?`〔${we(We.dynasty)}〕`:"",te].filter(Boolean).join(" ")||void 0,aside:et?ce.status.draft:void 0,secondLine:void 0}}const tt=we(qt(W,ce.unit.juan));return{title:we(W.title),subtitle:[tt,Se].filter(Boolean).join(" · ")||void 0,aside:[Z0(ce,W.subtype),et?ce.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[W,we,ce,Ee]),P=W&&Ur(W)?"text":null,q=()=>{Oe(null),a("fulltext")};let _=null;if(W&&$){const ee=$({detail:W,kind:P});ee&&(_=t.jsx(ts,{href:ee}))}else P&&(_=t.jsx(ts,{onClick:q}));const le=ee=>{if(!W)return null;const Se=ee.replace(/\.[^.]+$/,"");if($){const et=$({detail:W,kind:P,juan:Se});return et?{href:et}:null}return{onClick:()=>{Oe(Se),a("fulltext")}}},H=new Set(z.map(ee=>ee.key)),he=Y.filter(ee=>ee.key.startsWith("catalog:")&&ee.key!=="catalog:loading"||ee.key==="lineage"&&!!Ve&&!Xe||H.has(ee.key)).map(ee=>({key:ee.key,label:ee.label,onClick:()=>a(ee.key)})),xe=()=>{var ee;return W?W.type==="work"?t.jsx(Ed,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he}):W.type==="book"?t.jsx(Id,{data:W,transport:O,onNavigate:g,renderLink:w,readAction:_,fullText:B,fullTextPending:Ur(W)&&!!O.getTextManifest&&Te!==W.id,chapterLink:le,railTop:N,railLinks:he}):W.type==="collection"?t.jsx(Md,{data:W,catalog:(ee=I[0])==null?void 0:ee.data,transport:O,onNavigate:g,renderLink:w,readAction:_,railTop:N,railLinks:he,catalogAction:I.length>0?t.jsxs("a",{href:"#catalog",onClick:Se=>{Se.preventDefault(),a(`catalog:${I[0].resource_id}`)},children:[we(ce.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Pd,{data:W,transport:O,onNavigate:g,renderLink:w,railTop:N,railLinks:he,assetBase:x}):null},Re=()=>{var Se,et,tt;if(!Q||!W)return null;if(o==="basic"||o==="emendated")return xe();if(typeof o=="string"&&o.startsWith("catalog:")){const De=(Se=I.find(Fe=>`catalog:${Fe.resource_id}`===o))==null?void 0:Se.data;return t.jsx(nc,{data:De,onNavigate:g,renderLink:w})}if(o==="collated"||o==="fulltext")return t.jsx(xd,{id:e,transport:O,chapter:ge,onLocationChange:De=>Oe(De.chapter),onNavigate:g});if(o==="lineage"){if(!Ve)return t.jsx("div",{style:{color:s.bim("label-fg"),padding:"24px 0"},children:Ee(Xe?"detail.loading":"detail.noLineageGraph")});const De=W.type==="work"?W:null;return t.jsx(lo,{graph:Ve,renderLink:w,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((et=De==null?void 0:De.version_graph)==null?void 0:et.default_collection),onCollectionChange:h,collectionsAvailable:(tt=De==null?void 0:De.version_graph)==null?void 0:tt.collections,collectionCounts:(()=>{var ht,We,gt,te,A,ne,$e;if(!De)return;const Fe={},pt=((ht=ie.current)==null?void 0:ht.books)??[];Fe.all=(((We=De._books)==null?void 0:We.length)??0)-(((te=(gt=De.version_graph)==null?void 0:gt.excluded_books)==null?void 0:te.length)??0);const bt=(A=De.version_graph)==null?void 0:A.collections;if(bt)for(const Ie of Object.keys(bt))Fe[Ie]=Sn(De,pt,Ie).nodes.filter(Le=>Le.kind==="book"&&!Le.bridge).length;return Fe.core==null&&(($e=(ne=De.version_graph)==null?void 0:ne.core_books)!=null&&$e.length)&&(Fe.core=De.version_graph.core_books.length),Fe})()})}if(o==="feedback"&&C)return t.jsx($d,{resourceId:e,transport:ae});const ee=z.find(De=>De.key===o);return ee?ee.render({detail:W,entry:Q,transport:O,onNavigate:g}):null};if(K)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((ee,Se)=>t.jsx("div",{style:{height:Se===1?40:16,width:ee,opacity:.35,background:s.bim("rule")}},Se))})});if(re||!W||!Q||!k)return t.jsx(Hi,{style:{minHeight:R,...Z},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:s.bim("label-fg"),fontSize:14},children:Ee("detail.notFound")})});const Ze=o==="basic"||o==="emendated",Me=[{label:v??ce.detailTab.backToIndex,onClick:y}];if(W.type==="book"&&W.work_id){const ee=W.work_id;Me.push({label:ce.indexType.work,id:ee,onClick:()=>g==null?void 0:g(ee)})}Me.push({label:ce.indexType[W.type]});const He=o==="collated"||o==="fulltext",ct=typeof L=="string"?ce.status[L.trim()]??L:L,Be=t.jsx(Lc,{left:t.jsxs(t.Fragment,{children:[ct,ct?" · ":"",t.jsx(J0,{id:W.id,label:ce.label.id,copied:ce.action.copied,copyLabel:ce.action.copy})]}),right:t.jsxs(t.Fragment,{children:[C&&!Ze&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.submitVersion}),M&&t.jsx("a",{href:M.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:s.bim("meta-fg")},children:ce.detailTab.dataLicense})]})});return Ze?t.jsx("div",{className:T,children:t.jsxs(Hi,{grid:!0,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsx(ns,{items:Me}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{style:{border:"none",background:"transparent"}}),!F&&M&&t.jsx(fs,{...M})]})}),xe(),Be]})}):t.jsx("div",{className:T,children:t.jsxs(Hi,{wide:He,style:{minHeight:R,...Z},children:[t.jsx(is,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Ms,{char:"籍"}),t.jsx(ns,{items:Me})]}),actions:t.jsxs(t.Fragment,{children:[!F&&t.jsx(hs,{}),C&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("meta-fg")},children:ce.detailTab.feedback}),!F&&M&&t.jsx(fs,{...M})]})}),t.jsx(_c,{...k,aside:He?t.jsxs("button",{type:"button",onClick:()=>a("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:s.bim("accent"),borderBottom:`1px solid ${s.bim("rule")}`},children:[Ee("detail.workInfo")," →"]}):k.aside}),!He&&Y.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:Y.map(ee=>t.jsx(Nc,{label:ee.label,active:ee.key===o||Ze&&ee.key==="basic",onClick:()=>a(ee.key)},ee.key))}),t.jsx("div",{style:{marginTop:!He&&Y.length>1?8:0},children:Re()}),Be]})})};function J0({id:e,label:i,copied:n,copyLabel:r}){const[o,a]=b.useState(!1);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[t.jsxs("span",{children:[i," ",e]}),t.jsx("button",{type:"button",onClick:()=>{var l;(l=navigator.clipboard)==null||l.writeText(e).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},title:o?n:r,"aria-label":o?n:r,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:s.bim("aux-fg")},children:o?"✓":"⧉"})]})}function Z0(e,i){return i?e.workSubtype[i]??i:""}const zm=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],rr="zhusha",sr="bim-theme";function Cm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function or(e){return Cm(e)?e:rr}function Q0(){try{return or(window.localStorage.getItem(sr))}catch{return rr}}function Em(e){try{window.localStorage.setItem(sr,e)}catch{}}function Rm(e){const i=or(e);return document.documentElement.setAttribute("data-theme",i),i}function Tm(){return or(document.documentElement.getAttribute("data-theme"))}const ey=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],xo="airy",ar="bim-layout";function Im(e){return e==="airy"||e==="boxed"}function lr(e){return Im(e)?e:xo}function ty(){try{return lr(window.localStorage.getItem(ar))}catch{return xo}}function iy(e){try{window.localStorage.setItem(ar,e)}catch{}}function ny(e){const i=lr(e);return document.documentElement.setAttribute("data-layout",i),i}function ry(){return lr(document.documentElement.getAttribute("data-layout"))}const sy=`try{var t=localStorage.getItem(${JSON.stringify(sr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(ar)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,oy={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},ay=({onChange:e,style:i})=>{const{t:n}=oe(),[r,o]=b.useState(rr);b.useEffect(()=>{o(Tm())},[]);const a=l=>{o(Rm(l)),Em(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:zm.map(l=>{const d=r===l.name;return t.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":n(`common.theme.${l.name}`),title:n(`common.theme.${l.name}`),onClick:()=>a(l.name),style:{width:28,height:44,padding:0,border:0,background:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx("span",{"aria-hidden":"true",style:{width:14,height:14,borderRadius:"50%",boxSizing:"border-box",background:s.bim(oy[l.name]),boxShadow:d?`0 0 0 2px ${s.bim("page-bg")}, 0 0 0 3.5px ${s.bim("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=_e.BidLink;exports.BookIndexError=_e.BookIndexError;exports.BookIndexManager=_e.BookIndexManager;exports.BookIndexStorage=_e.BookIndexStorage;exports.BundleStorage=_e.BundleStorage;exports.ConfigError=_e.ConfigError;exports.GithubStorage=_e.GithubStorage;exports.IdGenerationError=_e.IdGenerationError;exports.IdGenerator=_e.IdGenerator;exports.LocalStorage=_e.LocalStorage;exports.MigrationError=_e.MigrationError;exports.StorageError=_e.StorageError;exports.adaptCharCord=_e.adaptCharCord;exports.adaptFig=_e.adaptFig;exports.adaptNorm=_e.adaptNorm;exports.adaptNormDetailed=_e.adaptNormDetailed;exports.adaptPunctJson=_e.adaptPunctJson;exports.base36Decode=_e.base36Decode;exports.base36Encode=_e.base36Encode;exports.base58Decode=_e.base58Decode;exports.buildId=_e.buildId;exports.buildPromotionMap=_e.buildPromotionMap;exports.cleanName=_e.cleanName;exports.decodeId=_e.decodeId;exports.decodeIdString=_e.decodeIdString;exports.encodeId=_e.encodeId;exports.extractIdFromUrl=_e.extractIdFromUrl;exports.extractStatus=_e.extractStatus;exports.extractType=_e.extractType;exports.iiifVolumeOf=_e.iiifVolumeOf;exports.isChapterSegment=_e.isChapterSegment;exports.isTextKey=_e.isTextKey;exports.loadFigUrls=_e.loadFigUrls;exports.loadReaderChapter=_e.loadReaderChapter;exports.loadReaderFiles=_e.loadReaderFiles;exports.matchChapterAcrossVersions=_e.matchChapterAcrossVersions;exports.normalizeCatalog=_e.normalizeCatalog;exports.parseId=_e.parseId;exports.pickTextVersion=_e.pickTextVersion;exports.readerManifest=_e.readerManifest;exports.readerVersions=_e.readerVersions;exports.shardOf=_e.shardOf;exports.smartDecode=_e.smartDecode;exports.textVersionLabel=_e.textVersionLabel;exports.validateResource=_e.validateResource;exports.volumeFromChar=_e.volumeFromChar;exports.Badge=s.Badge;exports.COMMON_TRADITIONAL_CHARS=s.COMMON_TRADITIONAL_CHARS;exports.FormInput=s.FormInput;exports.FormTextArea=s.FormTextArea;exports.LocaleContext=s.LocaleContext;exports.Section=s.Section;exports.TRADITIONAL_ALLOWLIST=s.TRADITIONAL_ALLOWLIST;exports.buildPageUrl=s.buildPageUrl;exports.findTraditionalChars=s.findTraditionalChars;exports.formatTemplate=s.formatTemplate;exports.getDisplayNameFromUrl=s.getDisplayNameFromUrl;exports.getMessages=s.getMessages;exports.getStartPage=s.getStartPage;exports.getT=s.getT;exports.getTypeGroupKey=s.getTypeGroupKey;exports.mergeVolumeResources=s.mergeVolumeResources;exports.normalizeVolumes=s.normalizeVolumes;exports.resourceHref=s.resourceHref;exports.useT=s.useT;exports.volumeStats=s.volumeStats;exports.VARIANT_CHARS=vi.VARIANT_CHARS;exports.normalizeVariants=vi.normalizeVariants;exports.VARIANT_SUPPLEMENT=cu.VARIANT_SUPPLEMENT;exports.BidUrlProvider=mu;exports.BookDetailLayout=X0;exports.BookPage=Id;exports.Breadcrumb=ns;exports.CATALOG_ALL_ID=Gt;exports.CATALOG_CSS=Od;exports.CATALOG_NARROW_QUERY=co;exports.CATALOG_PAGE_SIZE=mo;exports.CATALOG_UNCLASSIFIED_ID=di;exports.CLASSIFICATIONS=qn;exports.CardFoot=nn;exports.CatalogPage=E0;exports.CatalogPager=Kd;exports.CatalogTree=Bd;exports.CheckFilter=vc;exports.Chip=zc;exports.ChipWall=Nb;exports.CollectionCatalog=nc;exports.CollectionPage=Md;exports.DEFAULT_LAYOUT=xo;exports.DEFAULT_META_HOME_LINKS=cm;exports.DEFAULT_READER_PREFS=Rs;exports.DEFAULT_READ_HOME_LINKS=Gd;exports.DEFAULT_THEME=rr;exports.DETAIL_CSS=$c;exports.DYNASTY_GROUPS=Vn;exports.Dash=Ib;exports.DataTable=Cb;exports.DetailFooter=Lc;exports.DetailGrid=Zi;exports.DetailHeader=_c;exports.EMPTY_FILTERS=Gn;exports.ENTITY_TEXT_CSS=Xs;exports.EmptyNote=Bb;exports.EntityMark=Qs;exports.EntityPage=Pd;exports.EntityText=Af;exports.ExpandRow=Mb;exports.ExtLink=Hb;exports.FEEDBACK_FAB_OFFSET_VAR=ds;exports.FILTER_SUPPORT=Vl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=vb;exports.FeedbackButton=Vg;exports.FeedbackDialog=jd;exports.FeedbackForm=kd;exports.FeedbackList=Sd;exports.FeedbackTab=$d;exports.FilterChip=Nc;exports.GUJI_MARKDOWN_FIELD=lb;exports.GUJI_TABLE_NOTATION=Pc;exports.GlyphBadge=Ms;exports.GujiInteractiveReader=Rg;exports.GujiTable=Ps;exports.GujiTextViewer=to;exports.GujiWarpCanvas=qs;exports.ImagePanel=Xr;exports.IndexBrowser=vp;exports.IntroGrid=wb;exports.LAYOUTS=ey;exports.LAYOUT_STORAGE_KEY=ar;exports.LOSS_OPTIONS=Gl;exports.LocaleProvider=hu;exports.LocaleToggle=hs;exports.META_HOME_CSS=lm;exports.META_HOME_SECTION_IDS=_m;exports.MetaCatalogTable=gm;exports.MetaCollectionGroups=km;exports.MetaDataLicense=$m;exports.MetaHomeView=U0;exports.MetaLine=vt;exports.MetaLineageCards=vm;exports.MetaOnlineSites=Sm;exports.MetaPeopleTimeline=wm;exports.MetaRecentPanel=hm;exports.MetaRelatedCatalogs=ym;exports.MetaTypeChips=um;exports.ModeIndicator=El;exports.MoreButton=_b;exports.MoreLink=Ts;exports.PAGE_MAX_WIDTH=zn;exports.PERIOD_NARROW_SHARE=Jd;exports.PageFrame=Hi;exports.Quote=Lb;exports.READER_CSS=ac;exports.READ_HOME_CSS=po;exports.READ_HOME_NARROW_QUERY=on;exports.READ_HOME_SECTION_IDS=am;exports.READ_PERIOD_LABELS=M0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Hl;exports.ReadButton=ts;exports.ReadFamousWorks=rm;exports.ReadHomeView=L0;exports.ReadPeriodBand=sm;exports.ReadPicks=em;exports.ReadPieces=om;exports.ReadSection=Rt;exports.ReadShelf=ho;exports.ReadSibu=fo;exports.ReadStats=Qd;exports.ReadTopicGroup=im;exports.ReadTopics=nm;exports.ReaderMdText=Hs;exports.ReaderShell=bc;exports.ReaderToc=lc;exports.RepoSourceLink=fs;exports.ResourceGroup=Pb;exports.ResourceLine=Ob;exports.ResourceList=ju;exports.ResourceRow=Ic;exports.SEARCH_VIEW_STORAGE_KEY=_s;exports.SEVEN_PAVILIONS_KEY=jm;exports.SNIPPET_MARK_END=Nl;exports.SNIPPET_MARK_START=_l;exports.SORTABLE_TYPES=Yl;exports.SearchInput=Tl;exports.SearchResults=ec;exports.Sec=St;exports.SectionHead=Sb;exports.SideList=mi;exports.StripWarpRenderer=rs;exports.SummaryCard=tn;exports.THEMES=zm;exports.THEME_INIT_SCRIPT=sy;exports.THEME_STORAGE_KEY=sr;exports.TabFilter=Qi;exports.TableHead=Eb;exports.TableRow=Rb;exports.TagRow=Mc;exports.TagRows=Fb;exports.TextButton=$b;exports.TextReader=xd;exports.ThemeToggle=ay;exports.TopStrip=is;exports.VersionLineageGraph=Td;exports.VersionLineageList=Rd;exports.VersionLineageView=lo;exports.VolumeChips=zb;exports.VolumeLinks=As;exports.WorkCard=Wd;exports.WorkCardGrid=Yd;exports.WorkCatalog=Tg;exports.WorkPage=Ed;exports.WorkRow=Ud;exports.adaptEntityJson=qc;exports.applyLayout=ny;exports.applyTheme=Rm;exports.authorsLine=nr;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Bs;exports.bucketResources=js;exports.buildCatalogTree=k0;exports.buildCollectionTable=Ul;exports.buildLineageGraph=Sn;exports.buildMeiliFilter=rp;exports.buildParagraphBlocks=Uc;exports.buildVersionRow=ks;exports.buildVersionTable=Bl;exports.canParagraphize=Ln;exports.catalogNodeIdOf=y0;exports.catalogNodeIdsOf=j0;exports.catalogPageCount=$0;exports.catalogTotal=uo;exports.classificationPath=sn;exports.clearAllRecentIds=Ns;exports.compareCatalogCards=S0;exports.computeVersionPartition=Gu;exports.countActiveFilters=Xn;exports.createFeedbackTransport=ro;exports.createTextApi=rc;exports.currentLayout=ry;exports.currentTheme=Tm;exports.defaultEntityHref=od;exports.defaultWorkLink=Hd;exports.deriveDating=Ou;exports.deriveEditionType=Kl;exports.deriveEra=Ji;exports.deriveYear=Un;exports.deriveYearRange=ys;exports.detectGenre=Zn;exports.displayAuthorRole=vs;exports.eraRank=Yr;exports.feedbackTransportOf=yd;exports.filtersFromParams=sp;exports.filtersToParams=An;exports.findCatalogPath=wi;exports.firstAuthorText=bo;exports.flattenTitles=Ac;exports.flattenToc=pc;exports.fmtCount=kt;exports.formatHitCount=$n;exports.formatVolumeRange=Yn;exports.groupRelatedWorks=Fu;exports.gujiInlineToPlain=kc;exports.hasActiveFilters=ql;exports.hasGujiMarkdownV02=cb;exports.hasGujiTableNotation=Db;exports.hasSearchOptions=tp;exports.headingKey=no;exports.headingsFromPunct=pd;exports.isCountedChar=Ds;exports.isDuiduChapter=Rn;exports.isLayoutName=Im;exports.isThemeName=Cm;exports.lineageHref=dm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Zc;exports.nestHeadings=hd;exports.normalizeEra=Tt;exports.normalizeLayout=lr;exports.normalizeRole=ws;exports.normalizeTheme=or;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Gi;exports.paginationItems=Fd;exports.parseChineseNumber=In;exports.parseGujiInline=jc;exports.parseGujiTable=Fc;exports.parseHeadingKey=bd;exports.pct=go;exports.periodLevel=Xd;exports.pickReaderVersion=uc;exports.readStoredLayout=ty;exports.readStoredTheme=Q0;exports.readerVersionOptionLabel=Qr;exports.remapPlainOffsets=Xc;exports.removeRecentId=tc;exports.renderFullTextBody=Zb;exports.renderProperNames=Gc;exports.renderReaderInline=Qn;exports.resolveRecentEntry=zs;exports.resourceNote=Kn;exports.resultTabFromParam=hp;exports.resultTabToParam=fp;exports.roleFacets=Dl;exports.rowNo=Tb;exports.sameFilters=op;exports.sanitizeHeadings=cs;exports.saveRecentId=Vr;exports.segmentEntities=Jc;exports.setImageSourceResolver=zf;exports.shelfColumns=Vd;exports.sortFor=ip;exports.sortYear=Mn;exports.spineHeight=qd;exports.splitFullTextTables=Ls;exports.splitHighlightSnippet=gs;exports.splitTableRow=Oc;exports.storeLayout=iy;exports.storeTheme=Em;exports.summaryFromEntry=nd;exports.summaryFromItem=id;exports.timelineLayout=mm;exports.toCatalogWorkCard=v0;exports.transportSummaryLoader=rd;exports.typeSupportsFilters=Xl;exports.useBidUrl=It;exports.useChapterWarpData=ud;exports.useConvert=xt;exports.useEntitySummaryLoader=Zs;exports.useI18n=oe;exports.useReaderPrefs=mc;exports.useRecentEntries=pm;exports.validateLineageGraph=Cu;exports.withDefaultLinks=ii;exports.withMetaLinks=ni;exports.yearText=Bn;
|