book-index-ui 0.66.2 → 0.66.3
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 +76 -76
- package/dist/index.js +5536 -5484
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Pm=Object.create;var Ao=Object.defineProperty;var Om=Object.getOwnPropertyDescriptor;var Fm=Object.getOwnPropertyNames;var Bm=Object.getPrototypeOf,Hm=Object.prototype.hasOwnProperty;var Dm=(e,i,n,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of Fm(i))!Hm.call(e,o)&&o!==n&&Ao(e,o,{get:()=>i[o],enumerable:!(s=Om(i,o))||s.enumerable});return e};var bn=(e,i,n)=>(n=e!=null?Pm(Bm(e)):{},Dm(i||!e||!e.__esModule?Ao(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Se=require("./storage-entry-D6X5zpk8.cjs"),t=require("react/jsx-runtime"),b=require("react"),r=require("./Badge-DdG0AdQo.cjs"),Wm=require("opencc-js/t2cn"),vi=require("./variant-chars-kDZNY5eM.cjs"),Um=require("react-markdown"),Km=require("remark-gfm"),Ym=require("./variant-supplement.cjs"),Vm=e=>`/item/${e}`,ll=b.createContext(Vm);function Gm({buildUrl:e,children:i}){const n=b.useMemo(()=>e,[e]);return t.jsx(ll.Provider,{value:n,children:i})}function Tt(){return b.useContext(ll)}const cl="",dl="";function cs(e){const i=[];let n=!1,s=e;for(;s.length;){const o=n?dl:cl,a=s.indexOf(o);if(a===-1){i.push({text:s,marked:n});break}a>0&&i.push({text:s.slice(0,a),marked:n}),s=s.slice(a+1),n=!n}return i}let Ii=null;function ml(){if(Ii)return Ii;try{const e=Wm.Converter({from:"t",to:"cn"});Ii=r.withProtectedTerms(i=>e(vi.normalizeVariants(i)))}catch{Ii=e=>e}return Ii}const ul="bim-locale";function qm(){try{const e=localStorage.getItem(ul);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function Xm(e){try{localStorage.setItem(ul,e)}catch{}}const Jm="zh-Hans",Zm=({locale:e,onLocaleChange:i,converter:n,children:s})=>{const[o,a]=b.useState(e??Jm),l=e??o;b.useEffect(()=>{if(e)return;const p=qm();p&&p!==o&&a(p)},[]);const d=b.useMemo(()=>l==="zh-Hans"?n??ml():null,[l,n]),c=b.useCallback(p=>{a(p),Xm(p),i==null||i(p)},[i]),m=b.useMemo(()=>({locale:l,setLocale:c,messages:r.getMessages(l),converter:d}),[l,c,d]);return t.jsx(r.LocaleContext.Provider,{value:m,children:s})},Qm=2e3;function gt(){const e=b.useContext(r.LocaleContext),i=(e==null?void 0:e.locale)??"zh-Hant",n=(e==null?void 0:e.converter)??null,s=b.useRef(new Map),o=b.useRef(i),a=b.useRef(n);(o.current!==i||a.current!==n)&&(s.current.clear(),o.current=i,a.current=n);const l=b.useCallback(d=>{if(!d)return"";if(!n)return d;const c=s.current.get(d);if(c!==void 0)return c;const m=n(d);if(s.current.size>=Qm){const p=s.current.keys().next().value;p!==void 0&&s.current.delete(p)}return s.current.set(d,m),m},[n]);return b.useMemo(()=>({convert:l,locale:i,isSimplified:i==="zh-Hans"}),[l,i])}function se(){const e=b.useContext(r.LocaleContext),{convert:i,locale:n,isSimplified:s}=gt(),o=(e==null?void 0:e.messages)??r.getMessages("zh-Hant"),a=b.useMemo(()=>e?r.makeT(o):r.getT("zh-Hant"),[e,o]);return b.useMemo(()=>({t:a,convert:i,locale:n,isSimplified:s,messages:o}),[a,i,n,s,o])}function eu(e,i,n){return e?e==="orig"?null:i==="zh-Hans"?n??ml():e==="hant"?vi.normalizeVariants:n:i==="zh-Hans"?n:vi.normalizeVariants}const tu=({mode:e,children:i})=>{const n=b.useContext(r.LocaleContext),s=b.useMemo(()=>n&&{...n,converter:eu(e,n.locale,n.converter)},[n,e]);return t.jsx(r.LocaleContext.Provider,{value:s,children:i})},Lo={text:r.bim("restype-text"),image:r.bim("restype-image"),"text+image":r.bim("restype-text-image"),physical:r.bim("restype-physical")};function iu(e){return e.includes("text")&&e.includes("image")?Lo["text+image"]:Lo[e[0]||"physical"]}const nu=({items:e,groupByType:i=!0,resourceGroups:n,onNavigate:s,renderLink:o})=>{const a=r.useT(),{convert:l}=gt(),d=b.useMemo(()=>r.mergeVolumeResources(e||[]),[e]),{mirrorGroups:c,ungroupedItems:m,labelOnlyKeys:p}=b.useMemo(()=>{const j=new Map,x=[],S=new Map;d.forEach((v,$)=>{const N=v.group||(v.label?`_label:${$}`:void 0);!v.group&&v.label&&N&&S.set(N,v.label),N?(j.has(N)||j.set(N,[]),j.get(N).push(v)):x.push(v)});for(const v of j.values())v.sort(($,N)=>{const _=E=>E.group_role==="origin"?0:E.group_role==="mirror"?1:2;return _($)-_(N)});return{mirrorGroups:j,ungroupedItems:x,labelOnlyKeys:S}},[d]),h={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=j=>h[j]?h[j]:j.split("+").map(x=>h[x]||x).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:r.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((j,x)=>t.jsx(kr,{item:j},j.id||x))});const f=(j,x)=>{const S=n==null?void 0:n[j],v=p.get(j)||(S==null?void 0:S.label)||j,$=S==null?void 0:S.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",background:r.bim("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:r.bim("fg")},children:l(v)}),$&&t.jsx("div",{style:{fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.5},children:l($)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((N,_)=>t.jsx(kr,{item:N,onNavigate:s,renderLink:o},N.id||_))})]},`group-${j}`)},g=new Map;for(const j of m){const x=r.getTypeGroupKey(r.getResourceTypes(j));g.has(x)||g.set(x,[]),g.get(x).push(j)}const y=["text","image","text+image","physical"],w=[...y.filter(j=>g.has(j)),...[...g.keys()].filter(j=>!y.includes(j)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([j,x])=>f(j,x)),w.map(j=>{const x=g.get(j),S=iu(j.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:S,whiteSpace:"nowrap",flexShrink:0},children:u(j)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((v,$)=>t.jsx(kr,{item:v,onNavigate:s,renderLink:o},v.id||$))})]},j)})]})},ru={bw:{label:"",bg:r.bim("colormode-bw-bg"),fg:r.bim("colormode-bw-fg")},color:{label:"",bg:r.bim("colormode-color-bg"),fg:r.bim("colormode-color-fg")}},kr=({item:e})=>{const i=r.useT(),{convert:n}=gt(),[s,o]=b.useState(!1),a=b.useMemo(()=>(e.url?r.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||r.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?{...ru[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 ${r.bim("widget-border")}`,borderRadius:"5px",background:r.bim("input-bg"),fontSize:"12px",color:r.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:r.bim("desc-fg")},children:u}),d&&t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:[c,"/",p,i.unit.volume,m>0&&t.jsx("span",{style:{color:r.bim("missing-fg"),marginLeft:"3px"},children:r.formatTemplate(i.common.volumesMissing,{n:m})})]}),e.url&&t.jsx("a",{href:(()=>{const g=r.getStartPage(e.metadata);return g?r.buildPageUrl(e.url,g):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:r.bim("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:i.action.visit}),d&&t.jsx("button",{onClick:()=>o(!s),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",lineHeight:1.4},children:s?"▲":"▼"})]}),d&&s&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${r.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 ${r.bim("widget-border")}`,color:r.bim("link-fg"),textDecoration:"none"},children:g.volume},g.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?r.bim("missing-fg"):r.bim("desc-fg"),textDecoration:y?"line-through":"none",opacity:y?.6:1},children:g.volume},g.volume)})})]})},pl=({indexSource:e,syncConfig:i,variant:n="index-browser",onSwitchMode:s,onToggleDraft:o,onConfigurePath:a,onSelectFolder:l})=>{const d=r.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:r.bim("primary-soft"),color:r.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?r.bim("warning"):r.bim("success"),color:r.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:s,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:s,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:s,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:r.bim("mode-active-bg"),color:r.bim("on-color-fg"),cursor:"default"},title:p,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:h})]})]})},Pn="bim-search-history",Po=10,Oo=8;function Bi(){try{const e=localStorage.getItem(Pn);return e?JSON.parse(e):[]}catch{return[]}}function bl(e){try{const i=Bi().filter(n=>n!==e);i.unshift(e),i.length>Po&&(i.length=Po),localStorage.setItem(Pn,JSON.stringify(i))}catch{}}function su(e){try{const i=Bi().filter(n=>n!==e);localStorage.setItem(Pn,JSON.stringify(i))}catch{}}function ou(){try{localStorage.removeItem(Pn)}catch{}}const hl=({transport:e,value:i,onChange:n,onSearch:s,onEntrySelect:o,placeholder:a})=>{const l=r.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,w]=b.useState(Bi),j=b.useRef(null),x=b.useRef(null),S=b.useRef(null),v=b.useRef(!1);b.useEffect(()=>{g(-1);const I=i.trim();if(!I){u(y.map(q=>({type:"history",text:q})));return}if(!e.searchAll){u([]);return}let H=!1;const M=setTimeout(()=>{e.searchAll(I,Oo).then(q=>{if(H)return;const O=[...q.works,...q.books,...q.collections,...q.entities??[]];u(O.slice(0,Oo).map(ie=>({type:"entry",text:ie.title||ie.id,entry:ie})))}).catch(()=>{H||u([])})},80);return()=>{H=!0,clearTimeout(M)}},[i,y,e]),b.useEffect(()=>{const I=H=>{S.current&&!S.current.contains(H.target)&&p(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[]),b.useEffect(()=>{const I=H=>{var M,q;if(H.key==="/"&&document.activeElement!==j.current){const O=(M=document.activeElement)==null?void 0:M.tagName;if(O==="INPUT"||O==="TEXTAREA"||O==="SELECT")return;H.preventDefault(),(q=j.current)==null||q.focus()}};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]);const $=b.useCallback(I=>{I.trim()&&(bl(I.trim()),w(Bi())),s(I),p(!1)},[s]),N=b.useCallback(I=>{I.type==="history"?(n(I.text),$(I.text)):I.entry&&(o?(o(I.entry),p(!1)):(n(I.text),$(I.text)))},[n,$,o]),_=b.useCallback(I=>{if(!m||h.length===0){I.key==="Enter"&&$(i);return}switch(I.key){case"ArrowDown":I.preventDefault(),g(H=>(H+1)%h.length);break;case"ArrowUp":I.preventDefault(),g(H=>(H-1+h.length)%h.length);break;case"Enter":I.preventDefault(),f>=0&&f<h.length?N(h[f]):$(i);break;case"Escape":I.preventDefault(),p(!1);break}},[m,h,f,i,$,N]),E=b.useCallback((I,H)=>{H.stopPropagation(),su(I),w(Bi()),u(M=>M.filter(q=>!(q.type==="history"&&q.text===I)))},[]),B=b.useCallback(I=>{I.stopPropagation(),ou(),w([]),u([])},[]);b.useEffect(()=>{if(f>=0&&x.current){const I=x.current.children;I[f]&&I[f].scrollIntoView({block:"nearest"})}},[f]);const T=!i.trim()&&y.length>0;return t.jsxs("div",{ref:S,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:d,value:i,onChange:I=>{n(I.target.value),p(!0)},onCompositionStart:()=>{v.current=!0},onCompositionEnd:()=>{v.current=!1},onFocus:()=>{p(!0)},onKeyDown:_,style:{width:"100%",padding:"8px 12px",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("input-bg"),color:r.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:r.bim("input-bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",boxShadow:r.bim("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[T&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:r.bim("desc-fg"),borderBottom:`1px solid ${r.bim("widget-border")}`},children:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:B,style:{border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),h.map((I,H)=>t.jsxs("div",{onClick:()=>N(I),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r.bim("fg"),background:H===f?r.bim("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:I.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.text}),I.entry&&t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),flexShrink:0},children:[c[I.entry.type],I.entry.edition&&` · ${I.entry.edition}`,I.entry.author&&` · ${I.entry.author}`]}),I.type==="history"&&t.jsx("button",{onClick:M=>E(I.text,M),style:{border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${I.type}-${I.text}-${H}`))]})]})},Gi=({type:e,size:i=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:i,height:i,borderRadius:1,flex:"none",background:r.bim(`type-${e}`),verticalAlign:"middle"}});function Gt(e){const i=[],n=new Set;for(const s of e.base_edition??[]){if(!s||!s.relation)continue;const o=!!s.hypothetical_id,a=o?s.hypothetical_id:s.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:s.relation,confidence:s.confidence??void 0,evidence:s.evidence,note:s.note}))}return i}function mi(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 au(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 zn(e){return!!e.lineage||Gt(e).length>0||mi(e).length>0}function lu(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 cu(e,i){var s,o,a,l,d;if(!zn(e))return null;const n=e.lineage??{};return{id:e.id,kind:"book",label:e.title,year:((s=e.dating)==null?void 0:s.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 Fo(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 du(e,i,n){const[s,o]=[e,i.book_id].sort();return{id:`sibling:${s}-${o}:${n}`,source:s,target:o,kind:"sibling",relation:i.relation,confidence:i.confidence,evidence:i.evidence,note:i.note}}function mu(e,i){var m;if(i==="all")return null;const n=(m=e.collections)==null?void 0:m[i],s=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=s||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=s?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 yn(e,i,n){const s=e.version_graph,o={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!s||!s.enabled)return o;const a=new Set(s.excluded_books??[]),l=s.node_groups??{},d=mu(s,n??s.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 v=new Map(i.map(T=>[T.id,T])),$=new Map((s.hypothetical_nodes??[]).map(T=>[T.id,T])),N=T=>{const I=v.get(T);if(I&&zn(I))return Gt(I).map(M=>M.ref);const H=$.get(T);return H?(H.derived_from??[]).map(M=>M.ref):[]},_=T=>$.has(T)?!p||p.has(T):!m||m.has(T),E=new Set,B=T=>{if(!E.has(T)){E.add(T);for(const I of N(T))a.has(I)||(_(I)||($.has(I)?u.add(I):v.has(I)&&h.add(I)),B(I))}};for(const T of i)m&&m.has(T.id)&&!a.has(T.id)&&B(T.id);for(const T of s.hypothetical_nodes??[])p&&p.has(T.id)&&B(T.id)}const f=i.filter(v=>!a.has(v.id)).filter(v=>!m||m.has(v.id)||h.has(v.id)).map(v=>{const $=cu(v,l);return $&&h.has(v.id)&&($.bridge=!0),$}).filter(v=>v!==null),g=(s.hypothetical_nodes??[]).filter(v=>!p||p.has(v.id)||u.has(v.id)).map(v=>{const $=lu(v);return u.has(v.id)&&($.bridge=!0),$}),y=[...f,...g],w=new Set(y.map(v=>v.id)),j=new Set,x=[],S=v=>{j.has(v.id)||!w.has(v.source)||!w.has(v.target)||(j.add(v.id),x.push(v))};for(const v of i)a.has(v.id)||!zn(v)||m&&!m.has(v.id)&&!h.has(v.id)||(Gt(v).forEach(($,N)=>{S(Fo(v.id,$,N))}),mi(v).forEach(($,N)=>{S(du(v.id,$,N))}));for(const v of s.hypothetical_nodes??[])p&&!p.has(v.id)&&!u.has(v.id)||(v.derived_from??[]).forEach(($,N)=>{S(Fo(v.id,$,N))});return{nodes:y,edges:x,groups:s.groups??[],title:s.title,description:s.description,layout:s.layout??"LR",excluded:Array.from(a)}}function fl(e,i,n){const s=(e??(i!=null?String(i):"")).trim();return s?!n||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(s)?s:`约 ${s}`:""}function uu(e,i){const n=[],s=e.version_graph;if(!s)return n;const o=new Set(i.map(c=>c.id)),a=new Set((s.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(!zn(c))continue;const m=`Book ${c.id} (${c.title})`;Gt(c).forEach(p=>d(m,p)),mi(c).forEach(p=>{o.has(p.book_id)||n.push(`${m}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const c of s.hypothetical_nodes??[]){const m=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(p=>d(m,p))}return n}const gl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],pu={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Rt(e){return pu[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},xl={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function On(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 s=i[2]?parseInt(i[2],10):void 0;return{from:n,to:s!=null&&s>=n&&s<=2100?s:void 0}}function bu(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 hu=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Bo={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function ds(e){const i=e.trim().replace(/[代朝]$/,"");for(const o of Object.keys(Bo))if(i.startsWith(o))return Bo[o];const n=Rt(i);if(yi[n]!=null)return n;const s=Qt(i);if(s&&i.length<=s.length+1)return Rt(s)}function li(e,i){if(i){const n=xl[`${i}|${e}`];if(n!=null)return n}return $i[e]}const fu=1911;function gu(e){const i=$i[e];if(i==null)return;const n=Ht[e];let s;for(const[o,a]of Object.entries($i))Ht[o]===n&&a>i&&(s==null||a<s)&&(s=a);return s!=null?s-1:void 0}const xu={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Cn(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let i=0,n=0,s=!1;for(const a of e){const l=xu[a];if(l===void 0)return;s=!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 s&&o>0?o:void 0}function Qt(e){for(const i of gl)if(e.startsWith(i))return i}const Ht={};{const e=(i,n)=>{for(const s of n)Ht[s]=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 s of Object.keys($i))if(e.includes(s)&&!(n&&Ht[s]&&Ht[s]!==n&&xl[`${n}|${s}`]==null))return s}function Fn(e){var s;const i=e.dating;if(!i||i.era||i.reign||(s=e.publication_info)!=null&&s.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 qi(e){var a,l;e=Fn(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 s=(a=e.publication_info)==null?void 0:a.year;if(s){const d=On(s);if(d)return{era:bu(d.from),reign:"",source:"publication"};const c=Qt(s)??ds(s)??((l=Si.find(h=>h.pattern.test(s)))==null?void 0:l.era)??"",m=ki(s,c)??"",p=c||(m?Ht[m]??"":"");if(p||m)return{era:Rt(p),reign:m,source:"publication"}}const o=e.edition||e.title||"";if(o){const d=Qt(o);if(d)return{era:Rt(d),reign:ki(o,d)??"",source:"edition"};const c=Si.find(m=>m.pattern.test(o));if(c)return{era:Rt(c.era),reign:ki(o,c.era)??c.reign??"",source:"edition"}}return i}function Bn(e){var s,o,a,l,d,c;if(e=Fn(e),((s=e.dating)==null?void 0:s.year)!=null)return e.dating.year;const i=(o=e.publication_info)==null?void 0:o.year;if(i){const m=On(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)||ds(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 w=parseInt(h[1],10);if(w>=100&&w<=2100)return w}const u=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(u){const w=Qt(m);if(!w||Rt(w)==="民國"){const x=Cn(u[1]);if(x!=null&&x>=1&&x<=120)return fu+x}}const f=Qt(m)??((d=Si.find(w=>w.pattern.test(m)))==null?void 0:d.era),g=f?Rt(f):void 0,y=ki(m,g)??(Qt(m)||(c=Si.find(w=>w.pattern.test(m)))==null?void 0:c.reign);if(y){const w=li(y,g);if(w==null)continue;const j=m.indexOf(y),x=j>=0?m.slice(j+y.length):"",S=x.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??x.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),v=S?Cn(S[1]):void 0;return w+(v?v-1:0)}}}function ms(e){var o,a,l,d;e=Fn(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=On(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=yl[Rt(m[1])],h=yi[Rt(m[2])];if(p!=null&&h!=null)return{from:Math.min(p,h)-20,to:Math.max(p,h)+40}}}const s=[(l=e.publication_info)==null?void 0:l.year,e.edition,e.title].filter(Boolean);for(const c of s){if(!/[間间]/.test(c))continue;const m=Qt(c)??ds(c)??((d=Si.find(u=>u.pattern.test(c)))==null?void 0:d.era),p=m?Rt(m):void 0,h=[];for(const u of Object.keys($i))c.includes(u)&&(p&&Ht[u]&&Ht[u]!==p||li(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)&&li(g,p)!=null){h.push(g);break}}}if(h.length>0){const u=h.map(w=>li(w,p)).filter(w=>w!=null),f=Math.min(...u),g=h.reduce((w,j)=>li(w,p)>=li(j,p)?w:j),y=gu(g)??wr(p??"")??Math.max(...u);return{from:f,to:y>f?y:wr(p??Ht[g]??"")??f}}if(p&&yi[p]!=null)return{from:yi[p],to:wr(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},yu=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],ju=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Ho=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Do(e,i){for(const n of gl){const s=e.indexOf(n);if(s<0)continue;if(n.length===1){const c=e[s+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!ki(e.slice(s),Rt(n)))continue}const o=Rt(n);if(o===i)continue;const a=e.slice(s),l=ki(a,o)??"";let d;if(l){const c=li(l,o);if(c!=null){const p=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),h=p?Cn(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:Rt(n.era),reign:n.reign??""}}function ku(e){var y,w;e=Fn(e);const i=qi(e),n=((y=e.publication_info)==null?void 0:y.year)??"",s=n?On(n):void 0;if(!i.era&&!i.reign&&!s)return;const o=e.edition||e.title||"",a=/[間间]/.test(o),l=i.source==="publication"&&hu.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=Bn(e);const p=m==null?ms(e):void 0;let h;i.source==="publication"&&(l||Ho.test(n))?h="uncertain":i.source==="publication"?h="attested":Ho.test(o)||!i.reign&&m==null?h="uncertain":h="inferred";const u=i.source==="edition"?`題名「${o}」`:`出版著錄「${((w=e.publication_info)==null?void 0:w.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 j=n.match(/[、,,]\s*([宋元明清])/);j&&j[1]!==f.era&&(f.laterRepair={era:j[1]})}if(!f.laterRepair&&ju.test(o)){const j=o.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);j&&j[1]!==i.era&&(f.laterRepair={era:j[1]})}const g=yu.find(j=>j.re.test(o));if(g){const j=o.search(g.re),x=o.slice(j),S=Do(x,i.era)??Do(o,i.era);S&&(f.basedOn={era:S.era,reign:S.reign,year:S.year,relation:g.relation})}return f}const yl={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function wr(e){return yl[e]}function En(e){const i=Bn(e);if(i!=null)return i;const n=ms(e);if(n)return n.from;const s=qi(e).era;return s?yi[s]:void 0}const Wo=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Br(e){const i=Wo.indexOf(e);return i===-1?Wo.length:i}function wu(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=[],s=(o,a)=>{i[o].length&&n.push({key:o,labelKey:a,items:i[o]})};return s("belongsTo","belongsToWork"),s("collected","collectedIn"),s("contains","containedWorks"),s("derivative","derivativeWorks"),s("studies","studies"),s("related","relatedWorks"),n}function us(e,i){const n=r.mergeVolumeResources(e||[]),s=new Map,o=[],a=new Map;n.forEach((p,h)=>{if(p.group)s.has(p.group)||s.set(p.group,[]),s.get(p.group).push(p);else if(p.label){const u=`_label:${h}`;s.set(u,[p]),a.set(u,p.label)}else o.push(p)});for(const p of s.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=r.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=[...s.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 Hn(e,i=r.getT("zh-Hant")){const n=[],s=e.metadata||{};s.edition&&n.push(String(s.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const o=r.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})),s.version&&n.push(String(s.version)),n.join(" · ")}function jl(e,i){if(Hn(e)||i.filter(s=>s.name===e.name).length<2)return"";try{const s=new URL(e.url),o=s.searchParams.get("res")||s.searchParams.get("id");if(o)return o;const a=s.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}const vu="同版";function Su(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 $u(e){for(const i of mi(e)){const n=i.ref??i.book_id;if(i.relation===vu&&n&&n!==e.id)return n}}function _u(e){const i=new Map(e.map(a=>[a.id,a])),n=a=>{const l=i.get(a);return!!l&&!l.copyOf},s=new Map;for(const a of e)if(a.copyOf&&n(a.copyOf)){const l=s.get(a.copyOf)??[];l.push(a),s.set(a.copyOf,l)}if(s.size===0)return e;const o=[];for(const a of e){if(a.copyOf&&n(a.copyOf))continue;const l=s.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}function kl(e,i){var a,l,d,c;const n=e.resources||[],s=[],o=[];for(const m of n){const p=r.getResourceTypes(m);p.includes("image")&&s.push(m),p.includes("physical")&&o.push(m)}return{id:e.id,name:e.edition||e.title||e.id,era:qi(e),year:Bn(e),sortYear:En(e),images:s,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:Su(o[0]),copyOf:$u(e),summary:e.summary,important:Nu(e.id,i),group:(c=i==null?void 0:i.node_groups)==null?void 0:c[e.id],hasImage:s.length>0}}function Nu(e,i){var d,c;if(!i)return!1;const n=i.default_collection;if(!n)return!1;const s=(d=i.collections)==null?void 0:d[n];if(((s==null?void 0:s.book_ids)??(n==="core"?i.core_books??[]:[])).includes(e))return!0;const a=(s==null?void 0:s.groups)??[],l=(c=i.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function wl(e,i,n={}){const s=new Set((i==null?void 0:i.excluded_books)??[]),o=_u(e.filter(c=>!s.has(c.id)).map(c=>kl(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)=>Br(c)-Br(m));return{rows:a,allRows:o,eras:d,hasInferredEra:o.some(c=>c.era.source==="edition")}}function zu(e,i){var w,j;if(!i||!i.default_collection||!i.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const n=(w=i.collections)==null?void 0:w[i.default_collection],s=(n==null?void 0:n.groups)??[],o=(n==null?void 0:n.book_ids)??[],a=s.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(s),c=new Set([...o,...l]),m=x=>{if(c.has(x))return!0;const S=i.node_groups[x];return S!=null&&d.has(S)},p=[],h=new Map,u=[];for(const x of e)if(!((j=i.excluded_books)!=null&&j.includes(x)))if(m(x))p.push(x);else{const S=i.node_groups[x];S?(h.has(S)||h.set(S,[]),h.get(S).push(x)):u.push(x)}if(u.length+[...h.values()].reduce((x,S)=>x+S.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,S])=>{const v=g.get(x);return{id:x,label:(v==null?void 0:v.label)??x,description:v==null?void 0:v.description,ids:S}});return u.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:p,groupedIds:y}}const vl=["撰","編","注","校","譯","繪","其他"],Cu=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function ps(e){if(!e||!e.trim())return"撰";const i=e.replace(/[\s-]/g,"");if(!i)return"撰";for(const{cls:n,re:s}of Cu)if(s.test(i))return n;return"其他"}function bs(e){if(!e)return"";const i=e.trim();return!i||!/[一-鿿]/.test(i)?"":i}function Sl(e,i="全部"){const n=new Map;for(const o of e){const a=ps(o);n.set(a,(n.get(a)??0)+1)}const s=[{cls:"全部",label:i,count:e.length}];for(const o of vl){const a=n.get(o);a&&s.push({cls:o,label:o,count:a})}return s.length>2?s:[]}function hs(e){return(e._books??[]).map(i=>i.id).filter(i=>typeof i=="string")}function fs(e){const i=e._classifications??[],n=i.find(s=>s.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 $l(e){const i=e._members??[],n=typeof e._member_count=="number"?e._member_count:i.length;return{works:i.filter(s=>s.t==="work").map(s=>({id:s.id,title:s.title??"",volumes:Hi(s.vol)})),bookIds:i.filter(s=>s.t!=="work").map(s=>s.id).filter(s=>typeof s=="string"),total:n,truncated:n>i.length}}function Eu(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 _l(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:s,bookIds:o}=$l(e);return s.length>0?{rows:s.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 Hi(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,s]=[parseInt(i[1]),parseInt(i[2])];return Array.from({length:Math.max(0,s-n+1)},(o,a)=>n+a)}return e.split(/[,、]/).map(n=>parseInt(n.trim())).filter(n=>!isNaN(n))}return[]}function Dn(e,i="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=[...e].sort((a,l)=>a-l),s=n[0],o=n[n.length-1];return o-s+1===n.length?`${s}–${o}`:n.length<=3?n.join(", "):`${s}–${o} (${n.length}${i})`}const Ru=["〇","一","二","三","四","五","六","七","八","九"],Uo=["","十","百","千"];function Ki(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return vr(e,!0);const i=Math.floor(e/1e4),n=e%1e4;let s=vr(i,!0)+"萬";return n>0&&(s+=(n<1e3?"〇":"")+vr(n,!1)),s}function vr(e,i){const n=String(e),s=n.length;let o="",a=!1;for(let l=0;l<s;l++){const d=parseInt(n[l]),c=s-1-l;d===0?a=!0:(a&&o&&(o+="〇"),a=!1,i&&d===1&&c===1&&l===0?o+=Uo[c]:o+=Ru[d]+Uo[c])}return o}function Tu(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function Iu(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 Ki(n.juan_count.number)+i;if((a=n.juan_count)!=null&&a.description)return n.juan_count.description;const s=(n.measures??[]).filter(l=>l&&typeof l.number=="number"&&l.number>0&&l.unit);return s.length?s.map(l=>Ki(l.number)+(l.unit==="卷"?i:l.unit)).join(""):""}function Nl(e){if(e.edition_type)return e.edition_type;const i=e.edition||e.title||"",n=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/油印/,"油印本"],[/曬印|晒印/,"曬印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,o]of n)if(s.test(i))return o;return""}const Wn={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},zl=new Set(["work","book","entity"]);function Mu(e){return Rl(e)||!!e.sort}function Au(e,i){return i.sort&&zl.has(e)?i.sort:void 0}const Un=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Kn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Cl=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],El={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Yn(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 Rl(e){return Yn(e)>0}function Lu(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 Tl(e,i){const n=El[e];return Lu(i).every(s=>n.has(s))}const Mi=e=>JSON.stringify(e);function Pu(e,i){if(!Tl(i,e))return null;const n=[];if(e.dynasty.length){const s=Array.from(new Set(e.dynasty.flatMap(o=>{var a;return((a=Un.find(l=>l.key===o))==null?void 0:a.values)??[]})));s.length===1?n.push(`dynasty = ${Mi(s[0])}`):s.length>1&&n.push(`dynasty IN [${s.map(Mi).join(", ")}]`)}return e.classification.length&&n.push(e.classification.length===1?`classification = ${Mi(e.classification[0])}`:`classification IN [${e.classification.map(Mi).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 = ${Mi(e.loss)}`),n.join(" AND ")}const _t={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},Il="_";function Rn(e,i=new URLSearchParams){for(const n of Object.values(_t))i.delete(n);return e.dynasty.length&&i.set(_t.dynasty,e.dynasty.join(",")),e.classification.length&&i.set(_t.classification,e.classification.map(n=>n||Il).join(",")),e.hasImage&&i.set(_t.hasImage,"1"),e.hasText&&i.set(_t.hasText,"1"),e.hasCollated&&i.set(_t.hasCollated,"1"),e.loss&&i.set(_t.loss,e.loss),e.sort&&i.set(_t.sort,e.sort),i}function Ou(e){const i=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),n=new Set(Un.map(a=>a.key)),s=new Set(Kn.map(a=>a.value)),o=e.get(_t.loss);return{dynasty:Array.from(new Set(i(_t.dynasty).filter(a=>n.has(a)))),classification:Array.from(new Set(i(_t.classification).map(a=>a===Il?"":a).filter(a=>s.has(a)))),hasImage:e.get(_t.hasImage)==="1",hasText:e.get(_t.hasText)==="1"||e.get(_t.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(_t.sort))??""}}function Fu(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 Ko(e,i){return e.includes(i)?e.filter(n=>n!==i):[...e,i]}const Bu=({filters:e,onChange:i})=>{const n=r.useT(),s=n.searchV4,{convert:o}=gt(),[a,l]=b.useState(!1),d=b.useId(),c=Yn(e),m=p=>i({...e,...p});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":o(s.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(s.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:o(r.formatTemplate(s.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[o(a?s.collapse:s.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(s.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:Un.map(p=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(p.key),onClick:()=>m({dynasty:Ko(e.dynasty,p.key)}),children:o(p.key)},p.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(s.classification)}),Kn.map(p=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(p.value),onChange:()=>m({classification:Ko(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(s.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(s.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(s.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:o(s.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:Cl.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({...Wn,sort:e.sort}),children:o(s.clearAllFilters)})]})]})};function Ml({text:e,query:i}){const n=(i??"").trim();if(!n||!e)return t.jsx(t.Fragment,{children:e});const s=e.toLowerCase(),o=n.toLowerCase(),a=[];let l=0,d=0;for(;l<e.length;){const c=s.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 Yo=({entries:e,query:i,onEntryLinkClick:n,typeName:s})=>{const o=r.useT(),a=o.searchV4,{convert:l}=gt(),d=Tt();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 w=[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:j=>n(c,j),children:t.jsx(Ml,{text:m,query:i?l(i):void 0})}),p&&t.jsx("span",{className:"bim-sr-measure",children:p})]}),w&&t.jsx("span",{className:"bim-sr-sub",children:w})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Gi,{type:c.type,size:6})," ",s(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(j=>t.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:l(j.label)},j.label))})]},c.id)})})]})})},Hu=`
|
|
1
|
+
"use strict";var Hm=Object.create;var Po=Object.defineProperty;var Dm=Object.getOwnPropertyDescriptor;var Wm=Object.getOwnPropertyNames;var Um=Object.getPrototypeOf,Km=Object.prototype.hasOwnProperty;var Ym=(e,i,n,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of Wm(i))!Km.call(e,o)&&o!==n&&Po(e,o,{get:()=>i[o],enumerable:!(s=Dm(i,o))||s.enumerable});return e};var bn=(e,i,n)=>(n=e!=null?Hm(Um(e)):{},Ym(i||!e||!e.__esModule?Po(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ve=require("./storage-entry-D6X5zpk8.cjs"),t=require("react/jsx-runtime"),b=require("react"),r=require("./Badge-DdG0AdQo.cjs"),Vm=require("opencc-js/t2cn"),vi=require("./variant-chars-kDZNY5eM.cjs"),Gm=require("react-markdown"),qm=require("remark-gfm"),Xm=require("./variant-supplement.cjs"),Jm=e=>`/item/${e}`,ul=b.createContext(Jm);function Zm({buildUrl:e,children:i}){const n=b.useMemo(()=>e,[e]);return t.jsx(ul.Provider,{value:n,children:i})}function Tt(){return b.useContext(ul)}const pl="",bl="";function ms(e){const i=[];let n=!1,s=e;for(;s.length;){const o=n?bl:pl,a=s.indexOf(o);if(a===-1){i.push({text:s,marked:n});break}a>0&&i.push({text:s.slice(0,a),marked:n}),s=s.slice(a+1),n=!n}return i}let Ii=null;function hl(){if(Ii)return Ii;try{const e=Vm.Converter({from:"t",to:"cn"});Ii=r.withProtectedTerms(i=>e(vi.normalizeVariants(i)))}catch{Ii=e=>e}return Ii}const fl="bim-locale";function Qm(){try{const e=localStorage.getItem(fl);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function eu(e){try{localStorage.setItem(fl,e)}catch{}}const tu="zh-Hans",iu=({locale:e,onLocaleChange:i,converter:n,children:s})=>{const[o,a]=b.useState(e??tu),l=e??o;b.useEffect(()=>{if(e)return;const p=Qm();p&&p!==o&&a(p)},[]);const d=b.useMemo(()=>l==="zh-Hans"?n??hl():null,[l,n]),c=b.useCallback(p=>{a(p),eu(p),i==null||i(p)},[i]),m=b.useMemo(()=>({locale:l,setLocale:c,messages:r.getMessages(l),converter:d}),[l,c,d]);return t.jsx(r.LocaleContext.Provider,{value:m,children:s})},nu=2e3;function gt(){const e=b.useContext(r.LocaleContext),i=(e==null?void 0:e.locale)??"zh-Hant",n=(e==null?void 0:e.converter)??null,s=b.useRef(new Map),o=b.useRef(i),a=b.useRef(n);(o.current!==i||a.current!==n)&&(s.current.clear(),o.current=i,a.current=n);const l=b.useCallback(d=>{if(!d)return"";if(!n)return d;const c=s.current.get(d);if(c!==void 0)return c;const m=n(d);if(s.current.size>=nu){const p=s.current.keys().next().value;p!==void 0&&s.current.delete(p)}return s.current.set(d,m),m},[n]);return b.useMemo(()=>({convert:l,locale:i,isSimplified:i==="zh-Hans"}),[l,i])}function se(){const e=b.useContext(r.LocaleContext),{convert:i,locale:n,isSimplified:s}=gt(),o=(e==null?void 0:e.messages)??r.getMessages("zh-Hant"),a=b.useMemo(()=>e?r.makeT(o):r.getT("zh-Hant"),[e,o]);return b.useMemo(()=>({t:a,convert:i,locale:n,isSimplified:s,messages:o}),[a,i,n,s,o])}function ru(e,i,n){return e?e==="orig"?null:i==="zh-Hans"?n??hl():e==="hant"?vi.normalizeVariants:n:i==="zh-Hans"?n:vi.normalizeVariants}const su=({mode:e,children:i})=>{const n=b.useContext(r.LocaleContext),s=b.useMemo(()=>n&&{...n,converter:ru(e,n.locale,n.converter)},[n,e]);return t.jsx(r.LocaleContext.Provider,{value:s,children:i})},Oo={text:r.bim("restype-text"),image:r.bim("restype-image"),"text+image":r.bim("restype-text-image"),physical:r.bim("restype-physical")};function ou(e){return e.includes("text")&&e.includes("image")?Oo["text+image"]:Oo[e[0]||"physical"]}const au=({items:e,groupByType:i=!0,resourceGroups:n,onNavigate:s,renderLink:o})=>{const a=r.useT(),{convert:l}=gt(),d=b.useMemo(()=>r.mergeVolumeResources(e||[]),[e]),{mirrorGroups:c,ungroupedItems:m,labelOnlyKeys:p}=b.useMemo(()=>{const j=new Map,x=[],v=new Map;d.forEach((S,$)=>{const N=S.group||(S.label?`_label:${$}`:void 0);!S.group&&S.label&&N&&v.set(N,S.label),N?(j.has(N)||j.set(N,[]),j.get(N).push(S)):x.push(S)});for(const S of j.values())S.sort(($,N)=>{const z=R=>R.group_role==="origin"?0:R.group_role==="mirror"?1:2;return z($)-z(N)});return{mirrorGroups:j,ungroupedItems:x,labelOnlyKeys:v}},[d]),h={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=j=>h[j]?h[j]:j.split("+").map(x=>h[x]||x).join("+");if(!d||d.length===0)return t.jsx("div",{style:{padding:"16px",color:r.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((j,x)=>t.jsx(wr,{item:j},j.id||x))});const f=(j,x)=>{const v=n==null?void 0:n[j],S=p.get(j)||(v==null?void 0:v.label)||j,$=v==null?void 0:v.description;return t.jsxs("div",{style:{padding:"10px 12px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",background:r.bim("input-bg"),display:"flex",flexDirection:"column",gap:"8px"},children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:r.bim("fg")},children:l(S)}),$&&t.jsx("div",{style:{fontSize:"12px",color:r.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(wr,{item:N,onNavigate:s,renderLink:o},N.id||z))})]},`group-${j}`)},g=new Map;for(const j of m){const x=r.getTypeGroupKey(r.getResourceTypes(j));g.has(x)||g.set(x,[]),g.get(x).push(j)}const y=["text","image","text+image","physical"],w=[...y.filter(j=>g.has(j)),...[...g.keys()].filter(j=>!y.includes(j)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([j,x])=>f(j,x)),w.map(j=>{const x=g.get(j),v=ou(j.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:v,whiteSpace:"nowrap",flexShrink:0},children:u(j)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((S,$)=>t.jsx(wr,{item:S,onNavigate:s,renderLink:o},S.id||$))})]},j)})]})},lu={bw:{label:"",bg:r.bim("colormode-bw-bg"),fg:r.bim("colormode-bw-fg")},color:{label:"",bg:r.bim("colormode-color-bg"),fg:r.bim("colormode-color-fg")}},wr=({item:e})=>{const i=r.useT(),{convert:n}=gt(),[s,o]=b.useState(!1),a=b.useMemo(()=>(e.url?r.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||r.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?{...lu[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 ${r.bim("widget-border")}`,borderRadius:"5px",background:r.bim("input-bg"),fontSize:"12px",color:r.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:r.bim("desc-fg")},children:u}),d&&t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:[c,"/",p,i.unit.volume,m>0&&t.jsx("span",{style:{color:r.bim("missing-fg"),marginLeft:"3px"},children:r.formatTemplate(i.common.volumesMissing,{n:m})})]}),e.url&&t.jsx("a",{href:(()=>{const g=r.getStartPage(e.metadata);return g?r.buildPageUrl(e.url,g):e.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:r.bim("link-fg"),textDecoration:"none",whiteSpace:"nowrap"},children:i.action.visit}),d&&t.jsx("button",{onClick:()=>o(!s),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",lineHeight:1.4},children:s?"▲":"▼"})]}),d&&s&&t.jsx("div",{style:{padding:"6px 10px",border:`1px solid ${r.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 ${r.bim("widget-border")}`,color:r.bim("link-fg"),textDecoration:"none"},children:g.volume},g.volume):t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?r.bim("missing-fg"):r.bim("desc-fg"),textDecoration:y?"line-through":"none",opacity:y?.6:1},children:g.volume},g.volume)})})]})},gl=({indexSource:e,syncConfig:i,variant:n="index-browser",onSwitchMode:s,onToggleDraft:o,onConfigurePath:a,onSelectFolder:l})=>{const d=r.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:r.bim("primary-soft"),color:r.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?r.bim("warning"):r.bim("success"),color:r.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:s,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:s,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:s,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:r.bim("mode-active-bg"),color:r.bim("on-color-fg"),cursor:"default"},title:p,children:[t.jsx("span",{children:"📂"}),t.jsx("span",{style:{fontSize:"11px"},children:h})]})]})},On="bim-search-history",Fo=10,Bo=8;function Bi(){try{const e=localStorage.getItem(On);return e?JSON.parse(e):[]}catch{return[]}}function xl(e){try{const i=Bi().filter(n=>n!==e);i.unshift(e),i.length>Fo&&(i.length=Fo),localStorage.setItem(On,JSON.stringify(i))}catch{}}function cu(e){try{const i=Bi().filter(n=>n!==e);localStorage.setItem(On,JSON.stringify(i))}catch{}}function du(){try{localStorage.removeItem(On)}catch{}}const yl=({transport:e,value:i,onChange:n,onSearch:s,onEntrySelect:o,placeholder:a})=>{const l=r.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,w]=b.useState(Bi),j=b.useRef(null),x=b.useRef(null),v=b.useRef(null),S=b.useRef(!1);b.useEffect(()=>{g(-1);const I=i.trim();if(!I){u(y.map(X=>({type:"history",text:X})));return}if(!e.searchAll){u([]);return}let D=!1;const A=setTimeout(()=>{e.searchAll(I,Bo).then(X=>{if(D)return;const B=[...X.works,...X.books,...X.collections,...X.entities??[]];u(B.slice(0,Bo).map(ae=>({type:"entry",text:ae.title||ae.id,entry:ae})))}).catch(()=>{D||u([])})},80);return()=>{D=!0,clearTimeout(A)}},[i,y,e]),b.useEffect(()=>{const I=D=>{v.current&&!v.current.contains(D.target)&&p(!1)};return document.addEventListener("mousedown",I),()=>document.removeEventListener("mousedown",I)},[]),b.useEffect(()=>{const I=D=>{var A,X;if(D.key==="/"&&document.activeElement!==j.current){const B=(A=document.activeElement)==null?void 0:A.tagName;if(B==="INPUT"||B==="TEXTAREA"||B==="SELECT")return;D.preventDefault(),(X=j.current)==null||X.focus()}};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[]);const $=b.useCallback(I=>{I.trim()&&(xl(I.trim()),w(Bi())),s(I),p(!1)},[s]),N=b.useCallback(I=>{I.type==="history"?(n(I.text),$(I.text)):I.entry&&(o?(o(I.entry),p(!1)):(n(I.text),$(I.text)))},[n,$,o]),z=b.useCallback(I=>{if(!m||h.length===0){I.key==="Enter"&&$(i);return}switch(I.key){case"ArrowDown":I.preventDefault(),g(D=>(D+1)%h.length);break;case"ArrowUp":I.preventDefault(),g(D=>(D-1+h.length)%h.length);break;case"Enter":I.preventDefault(),f>=0&&f<h.length?N(h[f]):$(i);break;case"Escape":I.preventDefault(),p(!1);break}},[m,h,f,i,$,N]),R=b.useCallback((I,D)=>{D.stopPropagation(),cu(I),w(Bi()),u(A=>A.filter(X=>!(X.type==="history"&&X.text===I)))},[]),O=b.useCallback(I=>{I.stopPropagation(),du(),w([]),u([])},[]);b.useEffect(()=>{if(f>=0&&x.current){const I=x.current.children;I[f]&&I[f].scrollIntoView({block:"nearest"})}},[f]);const C=!i.trim()&&y.length>0;return t.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:j,type:"text",placeholder:d,value:i,onChange:I=>{n(I.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 ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("input-bg"),color:r.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:r.bim("input-bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",boxShadow:r.bim("shadow-dropdown"),zIndex:100,maxHeight:"320px",overflow:"auto"},children:[C&&t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:r.bim("desc-fg"),borderBottom:`1px solid ${r.bim("widget-border")}`},children:[t.jsx("span",{children:l.search.history}),t.jsx("button",{onClick:O,style:{border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),h.map((I,D)=>t.jsxs("div",{onClick:()=>N(I),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r.bim("fg"),background:D===f?r.bim("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:I.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.text}),I.entry&&t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),flexShrink:0},children:[c[I.entry.type],I.entry.edition&&` · ${I.entry.edition}`,I.entry.author&&` · ${I.entry.author}`]}),I.type==="history"&&t.jsx("button",{onClick:A=>R(I.text,A),style:{border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${I.type}-${I.text}-${D}`))]})]})},Gi=({type:e,size:i=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:i,height:i,borderRadius:1,flex:"none",background:r.bim(`type-${e}`),verticalAlign:"middle"}});function Gt(e){const i=[],n=new Set;for(const s of e.base_edition??[]){if(!s||!s.relation)continue;const o=!!s.hypothetical_id,a=o?s.hypothetical_id:s.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:s.relation,confidence:s.confidence??void 0,evidence:s.evidence,note:s.note}))}return i}function mi(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 mu(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 Cn(e){return!!e.lineage||Gt(e).length>0||mi(e).length>0}function uu(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 pu(e,i){var s,o,a,l,d;if(!Cn(e))return null;const n=e.lineage??{};return{id:e.id,kind:"book",label:e.title,year:((s=e.dating)==null?void 0:s.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 Ho(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 bu(e,i,n){const[s,o]=[e,i.book_id].sort();return{id:`sibling:${s}-${o}:${n}`,source:s,target:o,kind:"sibling",relation:i.relation,confidence:i.confidence,evidence:i.evidence,note:i.note}}function hu(e,i){var m;if(i==="all")return null;const n=(m=e.collections)==null?void 0:m[i],s=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=s||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=s?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 jn(e,i,n){const s=e.version_graph,o={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!s||!s.enabled)return o;const a=new Set(s.excluded_books??[]),l=s.node_groups??{},d=hu(s,n??s.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(C=>[C.id,C])),$=new Map((s.hypothetical_nodes??[]).map(C=>[C.id,C])),N=C=>{const I=S.get(C);if(I&&Cn(I))return Gt(I).map(A=>A.ref);const D=$.get(C);return D?(D.derived_from??[]).map(A=>A.ref):[]},z=C=>$.has(C)?!p||p.has(C):!m||m.has(C),R=new Set,O=C=>{if(!R.has(C)){R.add(C);for(const I of N(C))a.has(I)||(z(I)||($.has(I)?u.add(I):S.has(I)&&h.add(I)),O(I))}};for(const C of i)m&&m.has(C.id)&&!a.has(C.id)&&O(C.id);for(const C of s.hypothetical_nodes??[])p&&p.has(C.id)&&O(C.id)}const f=i.filter(S=>!a.has(S.id)).filter(S=>!m||m.has(S.id)||h.has(S.id)).map(S=>{const $=pu(S,l);return $&&h.has(S.id)&&($.bridge=!0),$}).filter(S=>S!==null),g=(s.hypothetical_nodes??[]).filter(S=>!p||p.has(S.id)||u.has(S.id)).map(S=>{const $=uu(S);return u.has(S.id)&&($.bridge=!0),$}),y=[...f,...g],w=new Set(y.map(S=>S.id)),j=new Set,x=[],v=S=>{j.has(S.id)||!w.has(S.source)||!w.has(S.target)||(j.add(S.id),x.push(S))};for(const S of i)a.has(S.id)||!Cn(S)||m&&!m.has(S.id)&&!h.has(S.id)||(Gt(S).forEach(($,N)=>{v(Ho(S.id,$,N))}),mi(S).forEach(($,N)=>{v(bu(S.id,$,N))}));for(const S of s.hypothetical_nodes??[])p&&!p.has(S.id)&&!u.has(S.id)||(S.derived_from??[]).forEach(($,N)=>{v(Ho(S.id,$,N))});return{nodes:y,edges:x,groups:s.groups??[],title:s.title,description:s.description,layout:s.layout??"LR",excluded:Array.from(a)}}function jl(e,i,n){const s=(e??(i!=null?String(i):"")).trim();return s?!n||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(s)?s:`约 ${s}`:""}function fu(e,i){const n=[],s=e.version_graph;if(!s)return n;const o=new Set(i.map(c=>c.id)),a=new Set((s.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(!Cn(c))continue;const m=`Book ${c.id} (${c.title})`;Gt(c).forEach(p=>d(m,p)),mi(c).forEach(p=>{o.has(p.book_id)||n.push(`${m}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const c of s.hypothetical_nodes??[]){const m=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(p=>d(m,p))}return n}const kl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],gu={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Rt(e){return gu[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},wl={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Fn(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 s=i[2]?parseInt(i[2],10):void 0;return{from:n,to:s!=null&&s>=n&&s<=2100?s:void 0}}function xu(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 yu=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Do={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function us(e){const i=e.trim().replace(/[代朝]$/,"");for(const o of Object.keys(Do))if(i.startsWith(o))return Do[o];const n=Rt(i);if(yi[n]!=null)return n;const s=Qt(i);if(s&&i.length<=s.length+1)return Rt(s)}function li(e,i){if(i){const n=wl[`${i}|${e}`];if(n!=null)return n}return $i[e]}const ju=1911;function ku(e){const i=$i[e];if(i==null)return;const n=Ht[e];let s;for(const[o,a]of Object.entries($i))Ht[o]===n&&a>i&&(s==null||a<s)&&(s=a);return s!=null?s-1:void 0}const wu={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function En(e){if(!e)return;if(/^\d+$/.test(e))return parseInt(e,10);let i=0,n=0,s=!1;for(const a of e){const l=wu[a];if(l===void 0)return;s=!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 s&&o>0?o:void 0}function Qt(e){for(const i of kl)if(e.startsWith(i))return i}const Ht={};{const e=(i,n)=>{for(const s of n)Ht[s]=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 s of Object.keys($i))if(e.includes(s)&&!(n&&Ht[s]&&Ht[s]!==n&&wl[`${n}|${s}`]==null))return s}function Bn(e){var s;const i=e.dating;if(!i||i.era||i.reign||(s=e.publication_info)!=null&&s.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 qi(e){var a,l;e=Bn(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 s=(a=e.publication_info)==null?void 0:a.year;if(s){const d=Fn(s);if(d)return{era:xu(d.from),reign:"",source:"publication"};const c=Qt(s)??us(s)??((l=Si.find(h=>h.pattern.test(s)))==null?void 0:l.era)??"",m=ki(s,c)??"",p=c||(m?Ht[m]??"":"");if(p||m)return{era:Rt(p),reign:m,source:"publication"}}const o=e.edition||e.title||"";if(o){const d=Qt(o);if(d)return{era:Rt(d),reign:ki(o,d)??"",source:"edition"};const c=Si.find(m=>m.pattern.test(o));if(c)return{era:Rt(c.era),reign:ki(o,c.era)??c.reign??"",source:"edition"}}return i}function Hn(e){var s,o,a,l,d,c;if(e=Bn(e),((s=e.dating)==null?void 0:s.year)!=null)return e.dating.year;const i=(o=e.publication_info)==null?void 0:o.year;if(i){const m=Fn(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)||us(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 w=parseInt(h[1],10);if(w>=100&&w<=2100)return w}const u=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(u){const w=Qt(m);if(!w||Rt(w)==="民國"){const x=En(u[1]);if(x!=null&&x>=1&&x<=120)return ju+x}}const f=Qt(m)??((d=Si.find(w=>w.pattern.test(m)))==null?void 0:d.era),g=f?Rt(f):void 0,y=ki(m,g)??(Qt(m)||(c=Si.find(w=>w.pattern.test(m)))==null?void 0:c.reign);if(y){const w=li(y,g);if(w==null)continue;const j=m.indexOf(y),x=j>=0?m.slice(j+y.length):"",v=x.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??x.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=v?En(v[1]):void 0;return w+(S?S-1:0)}}}function ps(e){var o,a,l,d;e=Bn(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=Fn(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=vl[Rt(m[1])],h=yi[Rt(m[2])];if(p!=null&&h!=null)return{from:Math.min(p,h)-20,to:Math.max(p,h)+40}}}const s=[(l=e.publication_info)==null?void 0:l.year,e.edition,e.title].filter(Boolean);for(const c of s){if(!/[間间]/.test(c))continue;const m=Qt(c)??us(c)??((d=Si.find(u=>u.pattern.test(c)))==null?void 0:d.era),p=m?Rt(m):void 0,h=[];for(const u of Object.keys($i))c.includes(u)&&(p&&Ht[u]&&Ht[u]!==p||li(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)&&li(g,p)!=null){h.push(g);break}}}if(h.length>0){const u=h.map(w=>li(w,p)).filter(w=>w!=null),f=Math.min(...u),g=h.reduce((w,j)=>li(w,p)>=li(j,p)?w:j),y=ku(g)??vr(p??"")??Math.max(...u);return{from:f,to:y>f?y:vr(p??Ht[g]??"")??f}}if(p&&yi[p]!=null)return{from:yi[p],to:vr(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},vu=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Su=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Wo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Uo(e,i){for(const n of kl){const s=e.indexOf(n);if(s<0)continue;if(n.length===1){const c=e[s+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(c)&&!ki(e.slice(s),Rt(n)))continue}const o=Rt(n);if(o===i)continue;const a=e.slice(s),l=ki(a,o)??"";let d;if(l){const c=li(l,o);if(c!=null){const p=a.slice(a.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),h=p?En(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:Rt(n.era),reign:n.reign??""}}function $u(e){var y,w;e=Bn(e);const i=qi(e),n=((y=e.publication_info)==null?void 0:y.year)??"",s=n?Fn(n):void 0;if(!i.era&&!i.reign&&!s)return;const o=e.edition||e.title||"",a=/[間间]/.test(o),l=i.source==="publication"&&yu.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=Hn(e);const p=m==null?ps(e):void 0;let h;i.source==="publication"&&(l||Wo.test(n))?h="uncertain":i.source==="publication"?h="attested":Wo.test(o)||!i.reign&&m==null?h="uncertain":h="inferred";const u=i.source==="edition"?`題名「${o}」`:`出版著錄「${((w=e.publication_info)==null?void 0:w.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 j=n.match(/[、,,]\s*([宋元明清])/);j&&j[1]!==f.era&&(f.laterRepair={era:j[1]})}if(!f.laterRepair&&Su.test(o)){const j=o.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);j&&j[1]!==i.era&&(f.laterRepair={era:j[1]})}const g=vu.find(j=>j.re.test(o));if(g){const j=o.search(g.re),x=o.slice(j),v=Uo(x,i.era)??Uo(o,i.era);v&&(f.basedOn={era:v.era,reign:v.reign,year:v.year,relation:g.relation})}return f}const vl={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function vr(e){return vl[e]}function Rn(e){const i=Hn(e);if(i!=null)return i;const n=ps(e);if(n)return n.from;const s=qi(e).era;return s?yi[s]:void 0}const Ko=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Dr(e){const i=Ko.indexOf(e);return i===-1?Ko.length:i}function _u(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=[],s=(o,a)=>{i[o].length&&n.push({key:o,labelKey:a,items:i[o]})};return s("belongsTo","belongsToWork"),s("collected","collectedIn"),s("contains","containedWorks"),s("derivative","derivativeWorks"),s("studies","studies"),s("related","relatedWorks"),n}function bs(e,i){const n=r.mergeVolumeResources(e||[]),s=new Map,o=[],a=new Map;n.forEach((p,h)=>{if(p.group)s.has(p.group)||s.set(p.group,[]),s.get(p.group).push(p);else if(p.label){const u=`_label:${h}`;s.set(u,[p]),a.set(u,p.label)}else o.push(p)});for(const p of s.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=r.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=[...s.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 Dn(e,i=r.getT("zh-Hant")){const n=[],s=e.metadata||{};s.edition&&n.push(String(s.edition)),e.source_label&&n.push(e.source_label),e.details&&n.push(e.details);const o=r.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})),s.version&&n.push(String(s.version)),n.join(" · ")}function Sl(e,i){if(Dn(e)||i.filter(s=>s.name===e.name).length<2)return"";try{const s=new URL(e.url),o=s.searchParams.get("res")||s.searchParams.get("id");if(o)return o;const a=s.pathname.split("/").filter(Boolean).pop();if(a)return decodeURIComponent(a)}catch{}return""}const Nu="同版";function zu(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 Cu(e){for(const i of mi(e)){const n=i.ref??i.book_id;if(i.relation===Nu&&n&&n!==e.id)return n}}function Eu(e){const i=new Map(e.map(a=>[a.id,a])),n=a=>{const l=i.get(a);return!!l&&!l.copyOf},s=new Map;for(const a of e)if(a.copyOf&&n(a.copyOf)){const l=s.get(a.copyOf)??[];l.push(a),s.set(a.copyOf,l)}if(s.size===0)return e;const o=[];for(const a of e){if(a.copyOf&&n(a.copyOf))continue;const l=s.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}function $l(e,i){var a,l,d,c;const n=e.resources||[],s=[],o=[];for(const m of n){const p=r.getResourceTypes(m);p.includes("image")&&s.push(m),p.includes("physical")&&o.push(m)}return{id:e.id,name:e.edition||e.title||e.id,era:qi(e),year:Hn(e),sortYear:Rn(e),images:s,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:zu(o[0]),copyOf:Cu(e),summary:e.summary,important:Ru(e.id,i),group:(c=i==null?void 0:i.node_groups)==null?void 0:c[e.id],hasImage:s.length>0}}function Ru(e,i){var d,c;if(!i)return!1;const n=i.default_collection;if(!n)return!1;const s=(d=i.collections)==null?void 0:d[n];if(((s==null?void 0:s.book_ids)??(n==="core"?i.core_books??[]:[])).includes(e))return!0;const a=(s==null?void 0:s.groups)??[],l=(c=i.node_groups)==null?void 0:c[e];return!!l&&a.includes(l)}function _l(e,i,n={}){const s=new Set((i==null?void 0:i.excluded_books)??[]),o=Eu(e.filter(c=>!s.has(c.id)).map(c=>$l(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)=>Dr(c)-Dr(m));return{rows:a,allRows:o,eras:d,hasInferredEra:o.some(c=>c.era.source==="edition")}}function Tu(e,i){var w,j;if(!i||!i.default_collection||!i.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const n=(w=i.collections)==null?void 0:w[i.default_collection],s=(n==null?void 0:n.groups)??[],o=(n==null?void 0:n.book_ids)??[],a=s.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(s),c=new Set([...o,...l]),m=x=>{if(c.has(x))return!0;const v=i.node_groups[x];return v!=null&&d.has(v)},p=[],h=new Map,u=[];for(const x of e)if(!((j=i.excluded_books)!=null&&j.includes(x)))if(m(x))p.push(x);else{const v=i.node_groups[x];v?(h.has(v)||h.set(v,[]),h.get(v).push(x)):u.push(x)}if(u.length+[...h.values()].reduce((x,v)=>x+v.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,v])=>{const S=g.get(x);return{id:x,label:(S==null?void 0:S.label)??x,description:S==null?void 0:S.description,ids:v}});return u.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:p,groupedIds:y}}const Nl=["撰","編","注","校","譯","繪","其他"],Iu=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function hs(e){if(!e||!e.trim())return"撰";const i=e.replace(/[\s-]/g,"");if(!i)return"撰";for(const{cls:n,re:s}of Iu)if(s.test(i))return n;return"其他"}function fs(e){if(!e)return"";const i=e.trim();return!i||!/[一-鿿]/.test(i)?"":i}function zl(e,i="全部"){const n=new Map;for(const o of e){const a=hs(o);n.set(a,(n.get(a)??0)+1)}const s=[{cls:"全部",label:i,count:e.length}];for(const o of Nl){const a=n.get(o);a&&s.push({cls:o,label:o,count:a})}return s.length>2?s:[]}function gs(e){return(e._books??[]).map(i=>i.id).filter(i=>typeof i=="string")}function xs(e){const i=e._classifications??[],n=i.find(s=>s.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 Cl(e){const i=e._members??[],n=typeof e._member_count=="number"?e._member_count:i.length;return{works:i.filter(s=>s.t==="work").map(s=>({id:s.id,title:s.title??"",volumes:Hi(s.vol)})),bookIds:i.filter(s=>s.t!=="work").map(s=>s.id).filter(s=>typeof s=="string"),total:n,truncated:n>i.length}}function Mu(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 El(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:s,bookIds:o}=Cl(e);return s.length>0?{rows:s.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 Hi(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,s]=[parseInt(i[1]),parseInt(i[2])];return Array.from({length:Math.max(0,s-n+1)},(o,a)=>n+a)}return e.split(/[,、]/).map(n=>parseInt(n.trim())).filter(n=>!isNaN(n))}return[]}function Wn(e,i="冊"){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=[...e].sort((a,l)=>a-l),s=n[0],o=n[n.length-1];return o-s+1===n.length?`${s}–${o}`:n.length<=3?n.join(", "):`${s}–${o} (${n.length}${i})`}const Au=["〇","一","二","三","四","五","六","七","八","九"],Yo=["","十","百","千"];function Ki(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return Sr(e,!0);const i=Math.floor(e/1e4),n=e%1e4;let s=Sr(i,!0)+"萬";return n>0&&(s+=(n<1e3?"〇":"")+Sr(n,!1)),s}function Sr(e,i){const n=String(e),s=n.length;let o="",a=!1;for(let l=0;l<s;l++){const d=parseInt(n[l]),c=s-1-l;d===0?a=!0:(a&&o&&(o+="〇"),a=!1,i&&d===1&&c===1&&l===0?o+=Yo[c]:o+=Au[d]+Yo[c])}return o}function Lu(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function Pu(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 Ki(n.juan_count.number)+i;if((a=n.juan_count)!=null&&a.description)return n.juan_count.description;const s=(n.measures??[]).filter(l=>l&&typeof l.number=="number"&&l.number>0&&l.unit);return s.length?s.map(l=>Ki(l.number)+(l.unit==="卷"?i:l.unit)).join(""):""}function Rl(e){if(e.edition_type)return e.edition_type;const i=e.edition||e.title||"",n=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/油印/,"油印本"],[/曬印|晒印/,"曬印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,o]of n)if(s.test(i))return o;return""}const Un={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Tl=new Set(["work","book","entity"]);function Ou(e){return Al(e)||!!e.sort}function Fu(e,i){return i.sort&&Tl.has(e)?i.sort:void 0}const Kn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Yn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Il=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Ml={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Vn(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 Al(e){return Vn(e)>0}function Bu(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 Ll(e,i){const n=Ml[e];return Bu(i).every(s=>n.has(s))}const Mi=e=>JSON.stringify(e);function Hu(e,i){if(!Ll(i,e))return null;const n=[];if(e.dynasty.length){const s=Array.from(new Set(e.dynasty.flatMap(o=>{var a;return((a=Kn.find(l=>l.key===o))==null?void 0:a.values)??[]})));s.length===1?n.push(`dynasty = ${Mi(s[0])}`):s.length>1&&n.push(`dynasty IN [${s.map(Mi).join(", ")}]`)}return e.classification.length&&n.push(e.classification.length===1?`classification = ${Mi(e.classification[0])}`:`classification IN [${e.classification.map(Mi).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 = ${Mi(e.loss)}`),n.join(" AND ")}const _t={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},Pl="_";function Tn(e,i=new URLSearchParams){for(const n of Object.values(_t))i.delete(n);return e.dynasty.length&&i.set(_t.dynasty,e.dynasty.join(",")),e.classification.length&&i.set(_t.classification,e.classification.map(n=>n||Pl).join(",")),e.hasImage&&i.set(_t.hasImage,"1"),e.hasText&&i.set(_t.hasText,"1"),e.hasCollated&&i.set(_t.hasCollated,"1"),e.loss&&i.set(_t.loss,e.loss),e.sort&&i.set(_t.sort,e.sort),i}function Du(e){const i=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),n=new Set(Kn.map(a=>a.key)),s=new Set(Yn.map(a=>a.value)),o=e.get(_t.loss);return{dynasty:Array.from(new Set(i(_t.dynasty).filter(a=>n.has(a)))),classification:Array.from(new Set(i(_t.classification).map(a=>a===Pl?"":a).filter(a=>s.has(a)))),hasImage:e.get(_t.hasImage)==="1",hasText:e.get(_t.hasText)==="1"||e.get(_t.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(_t.sort))??""}}function Wu(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 Vo(e,i){return e.includes(i)?e.filter(n=>n!==i):[...e,i]}const Uu=({filters:e,onChange:i})=>{const n=r.useT(),s=n.searchV4,{convert:o}=gt(),[a,l]=b.useState(!1),d=b.useId(),c=Vn(e),m=p=>i({...e,...p});return t.jsxs("aside",{className:"bim-sr-aside","aria-label":o(s.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(s.filterButton),c>0&&t.jsx("span",{className:"bim-sr-fn",children:o(r.formatTemplate(s.filterSelected,{n:c}))})]}),t.jsxs("span",{className:"bim-sr-fa","aria-hidden":"true",children:[o(a?s.collapse:s.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(s.dynasty)}),t.jsx("div",{className:"bim-sr-chips",children:Kn.map(p=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(p.key),onClick:()=>m({dynasty:Vo(e.dynasty,p.key)}),children:o(p.key)},p.key))})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{children:o(s.classification)}),Yn.map(p=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(p.value),onChange:()=>m({classification:Vo(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(s.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(s.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(s.hasText)]})]}),t.jsxs("section",{className:"bim-sr-fg",children:[t.jsx("h3",{id:`${d}-loss`,children:o(s.extant)}),t.jsx("div",{className:"bim-sr-seg",role:"group","aria-labelledby":`${d}-loss`,children:Il.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({...Un,sort:e.sort}),children:o(s.clearAllFilters)})]})]})};function Ol({text:e,query:i}){const n=(i??"").trim();if(!n||!e)return t.jsx(t.Fragment,{children:e});const s=e.toLowerCase(),o=n.toLowerCase(),a=[];let l=0,d=0;for(;l<e.length;){const c=s.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 Go=({entries:e,query:i,onEntryLinkClick:n,typeName:s})=>{const o=r.useT(),a=o.searchV4,{convert:l}=gt(),d=Tt();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 w=[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:j=>n(c,j),children:t.jsx(Ol,{text:m,query:i?l(i):void 0})}),p&&t.jsx("span",{className:"bim-sr-measure",children:p})]}),w&&t.jsx("span",{className:"bim-sr-sub",children:w})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Gi,{type:c.type,size:6})," ",s(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(j=>t.jsx("span",{className:`bim-sr-tag ${j.cls}`,children:l(j.label)},j.label))})]},c.id)})})]})})},Ku=`
|
|
2
2
|
.bim-sc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; }
|
|
3
3
|
.bim-sc { display: flex; flex-direction: column; min-width: 0; padding: 14px 16px 12px; border: 1px solid ${r.bim("rule")}; background: ${r.bim("card-bg")}; color: inherit; text-decoration: none; }
|
|
4
4
|
.bim-sc:hover { border-color: ${r.bim("rule-dashed")}; box-shadow: ${r.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: ${r.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
|
-
`,
|
|
15
|
+
`,qo=({entries:e,query:i,onEntryLinkClick:n,typeName:s})=>{const o=r.useT(),a=o.searchV4,{convert:l}=gt(),d=Tt();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:Ku}),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=[s(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(Ol,{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:ms(c.descriptionSnippet).map((y,w)=>y.marked?t.jsx("mark",{children:l(y.text)},w):t.jsx(b.Fragment,{children:l(y.text)},w))}),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 Yu(e,i){const n=new Set([1,i,e-1,e,e+1].filter(a=>a>=1&&a<=i)),s=Array.from(n).sort((a,l)=>a-l),o=[];return s.forEach((a,l)=>{l>0&&a-s[l-1]>1&&o.push("gap"),o.push(a)}),o}function Vu(e,i,n){const s=Math.max(1,Math.ceil(i/n));return Math.min(Math.max(1,e),s)}const Gu=({page:e,pageSize:i,total:n,totalLabel:s,onPage:o})=>{const a=r.useT().searchV4,{convert:l}=gt(),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(r.formatTemplate(a.pageInfo,{total:s??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)})}),Yu(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)})})]})]})},Fl="(max-width: 719px)",qu=`${Fl}, (pointer: coarse)`,Xu=`
|
|
16
16
|
.bim-sr-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; align-items: start; padding: 0 ${r.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(${r.bim("reader-top")} + 16px); padding-top: 2px; }
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
.bim-sr-pager .bim-sr-gap { color: ${r.bim("aux-fg")}; padding: 0 2px; }
|
|
82
82
|
.bim-sr-empty { padding: 60px 0; text-align: center; font-size: 14px; color: ${r.bim("meta-fg")}; }
|
|
83
83
|
|
|
84
|
-
@media ${
|
|
84
|
+
@media ${Fl} {
|
|
85
85
|
.bim-sr-layout { grid-template-columns: minmax(0, 1fr); row-gap: 16px; padding: 0 min(${r.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 ${qu} {
|
|
106
106
|
.bim-sr-chip { min-height: 36px; }
|
|
107
107
|
.bim-sr-opt { min-height: 44px; }
|
|
108
108
|
.bim-sr-seg button { min-height: 44px; }
|
|
@@ -117,10 +117,10 @@
|
|
|
117
117
|
:root[data-layout="boxed"] .bim-sr-table th { background: ${r.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
|
-
`,gs="bim-search-view",Sr=50,Go=5,Di=1e3;function jn(e){return e>=Di?`${Di.toLocaleString()}+`:e.toLocaleString()}const Vu={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function Gu(e){return e&&Vu[e.toLowerCase()]||"all"}function qu(e){return e==="all"?null:e}const qo=["work","collection","book","entity"],Xu={work:"works",collection:"collections",book:"books",entity:"entities"},Ju={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function Zu(){try{return window.localStorage.getItem(gs)==="card"?"card":"table"}catch{return"table"}}function Qu(e){try{window.localStorage.setItem(gs,e)}catch{}}const gi=(e,i)=>(e==null?void 0:e[Ju[i]])??0,$r=(e,i)=>(e==null?void 0:e[Xu[i]])??[],Ll=({transport:e,query:i,filters:n,onFiltersChange:s,onEntryLinkClick:o,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:m})=>{const p=r.useT(),h=p.searchV4,{convert:u}=gt(),f=!!e.supportsSearchFilters,g=b.useMemo(()=>f?n:Wn,[f,n]),[y,w]=b.useState("table");b.useEffect(()=>{w(Zu())},[]);const j=z=>{w(z),Qu(z)},[x,S]=b.useState(l??"all"),v=b.useRef(x);v.current=x,b.useEffect(()=>{l!==void 0&&l!==v.current&&(S(l),N(1))},[l]);const[$,N]=b.useState(c&&c>0?c:1),_=b.useRef($);_.current=$,b.useEffect(()=>{c!==void 0&&c>0&&c!==_.current&&N(c)},[c]);const E=b.useRef(null),B=b.useCallback(z=>{var de;N(z),m==null||m(z);const V=E.current;V&&V.getBoundingClientRect().top<0&&((de=V.scrollIntoView)==null||de.call(V,{block:"start",behavior:"instant"}))},[m]),[T,I]=b.useState(null),[H,M]=b.useState(null),[q,O]=b.useState(!1),[ie,oe]=b.useState(""),le=Rn(g).toString(),ae=Yn(g)>0,pe=Rn({...g,sort:""}).toString(),ee=b.useRef({query:i,filterOnlyKey:pe,sort:g.sort});b.useEffect(()=>{const z=ee.current;z.query!==i||z.filterOnlyKey!==pe?(S("all"),N(1)):z.sort!==g.sort&&N(1),ee.current={query:i,filterOnlyKey:pe,sort:g.sort}},[i,pe,g.sort]),b.useEffect(()=>{let z=!1;return O(!0),oe(""),(async()=>{try{let V;if(e.searchAll)V=await e.searchAll(i,Go,g);else{const de=["work","book","collection","entity"],ue=await Promise.all(de.map(He=>e.search(i,He,{page:1,pageSize:Go,filters:g})));V={works:ue[0].entries,books:ue[1].entries,collections:ue[2].entries,entities:ue[3].entries,totalWorks:ue[0].total,totalBooks:ue[1].total,totalCollections:ue[2].total,totalEntities:ue[3].total}}z||I(V)}catch(V){z||(oe(V instanceof Error?V.message:String(V)),I(null))}finally{z||O(!1)}})(),()=>{z=!0}},[e,i,le]);const ge=x;b.useEffect(()=>{if(x==="all"){M(null);return}let z=!1;return O(!0),(async()=>{try{const V=await e.search(i,x,{page:$,pageSize:Sr,filters:g});z||M({key:ge,entries:V.entries,total:V.total})}catch(V){z||(oe(V instanceof Error?V.message:String(V)),M(null))}finally{z||O(!1)}})(),()=>{z=!0}},[e,i,le,x,$]);const W=H&&H.key===ge?H:null;b.useEffect(()=>{if(x==="all"||!W||q)return;const z=Math.min(W.total,Di),V=Wu($,z,Sr);W.entries.length===0&&z>0&&V!==$&&(N(V),m==null||m(V))},[x,W,q,$]);const ze=b.useMemo(()=>qo.filter(z=>gi(T,z)>0),[T]),U=ze.reduce((z,V)=>z+gi(T,V),0),re=ze.some(z=>gi(T,z)>=Di)?`${U.toLocaleString()}+`:U.toLocaleString(),be=!q&&!ie&&T!==null&&U===0,X=b.useCallback(z=>{S(z),N(1),d==null||d(z)},[d]),L=b.useMemo(()=>{const z=[];return g.dynasty.forEach(V=>z.push({name:V,remove:()=>s({...g,dynasty:g.dynasty.filter(de=>de!==V)})})),g.classification.forEach(V=>{var de;return z.push({name:V?((de=Kn.find(ue=>ue.value===V))==null?void 0:de.label)??V:p.searchPage.unclassified,remove:()=>s({...g,classification:g.classification.filter(ue=>ue!==V)})})}),g.hasImage&&z.push({name:h.hasImage,remove:()=>s({...g,hasImage:!1})}),g.hasText&&z.push({name:h.hasText,remove:()=>s({...g,hasText:!1})}),g.hasCollated&&z.push({name:h.hasCollated,remove:()=>s({...g,hasCollated:!1})}),g.loss&&z.push({name:`${h.extant}:${p.searchPage.loss[g.loss]}`,remove:()=>s({...g,loss:""})}),z},[g,s,h,p]),_e={query:i,onEntryLinkClick:o,typeName:a},P=z=>y==="table"?t.jsx(Yo,{entries:z,..._e}):t.jsx(Vo,{entries:z,..._e}),K=qo.flatMap(z=>$r(T,z));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:Yu}),f&&t.jsx(Bu,{filters:g,onChange:s}),t.jsxs("div",{className:"bim-sr-main","aria-busy":q,ref:E,children:[ze.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 ${r.bim("rule")}`},children:[t.jsxs(Xo,{on:x==="all",onClick:()=>X("all"),children:[p.search.allTab," ",t.jsx("small",{children:re})]}),ze.map(z=>t.jsxs(Xo,{on:x===z,onClick:()=>X(z),children:[a(z)," ",t.jsx("small",{children:jn(gi(T,z))})]},z))]}),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:()=>s({...g,sort:""}),children:u(h.sortRelevance)}),["era","title"].map(z=>{const V=g.sort.startsWith(`${z}:`)?g.sort.endsWith("desc")?"desc":"asc":null,de=z==="era"?h.sortEra:h.sortTitle,ue=z==="era"?V==="desc"?h.sortEraDesc:h.sortEraAsc:V==="desc"?h.sortTitleDesc:h.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":V!==null,title:u(ue),onClick:()=>s({...g,sort:`${z}:${V==="asc"?"desc":"asc"}`}),children:[u(de),V?t.jsxs("span",{"aria-hidden":"true",children:[" ",V==="asc"?"↑":"↓"]}):null]},z)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":u(h.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":y==="table",onClick:()=>j("table"),children:u(h.viewTable)}),t.jsx("button",{type:"button","aria-pressed":y==="card",onClick:()=>j("card"),children:u(h.viewCard)})]})]}),ae&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:u(r.formatTemplate(h.filteredCount,{n:re}))}),L.map(z=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u(r.formatTemplate(h.removeFilter,{name:z.name})),onClick:z.remove,children:[u(z.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},z.name))]}),ie&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:ie}),be&&t.jsx("div",{className:"bim-sr-empty",children:u(ae?h.emptyFiltered:r.formatTemplate(p.search.noResultsFor,{query:i}))}),!ie&&!be&&x==="all"&&T&&(y==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Yo,{entries:K,..._e}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(h.limitedNote)})]}):t.jsx(t.Fragment,{children:ze.map(z=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Gi,{type:z,size:8}),a(z),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r.bim("meta-fg")},children:[jn(gi(T,z))," ",p.unit.items]})]}),gi(T,z)>$r(T,z).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>X(z),children:p.action.viewAll})]}),t.jsx(Vo,{entries:$r(T,z),..._e})]},z))})),!ie&&x!=="all"&&!W&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:p.search.loading}),!ie&&x!=="all"&&W&&W.entries.length>0&&t.jsxs(t.Fragment,{children:[P(W.entries),t.jsx(Uu,{page:$,pageSize:Sr,total:Math.min(W.total,Di),totalLabel:jn(W.total),onPage:B})]}),!ie&&x!=="all"&&W&&W.entries.length===0&&!q&&t.jsxs("div",{className:"bim-sr-empty",children:[u(ae?h.emptyFiltered:r.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 Xo({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?r.bim("ink"):r.bim("meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${r.bim("accent")}`:"none"},children:n})}const _i="bim-recent-ids",Jo="bim-recent-entries",Zo=50;function ei(){try{const e=localStorage.getItem(_i);if(e)return JSON.parse(e);const i=localStorage.getItem(Jo);if(i){const n=JSON.parse(i).map(s=>s.id);return localStorage.setItem(_i,JSON.stringify(n)),localStorage.removeItem(Jo),n}return[]}catch{return[]}}function Hr(e){try{const i=ei().filter(n=>n!==e);i.unshift(e),i.length>Zo&&(i.length=Zo),localStorage.setItem(_i,JSON.stringify(i))}catch{}}function Pl(e){try{const i=ei().filter(n=>n!==e);localStorage.setItem(_i,JSON.stringify(i))}catch{}}function xs(){try{localStorage.removeItem(_i)}catch{}}async function ys(e,i){var n,s,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:(s=l==null?void 0:l[0])==null?void 0:s.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 _r=5,ep=50,tp=200,Qo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ip=({transport:e,indexSource:i="local",syncConfig:n,onEntryClick:s,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:w=!1,filters:j=Wn,onFiltersChange:x,resultTab:S,onResultTabChange:v,resultPage:$,onResultPageChange:N})=>{const _=r.useT(),E=[{type:"work",name:_.indexType.work,key:"works"},{type:"book",name:_.indexType.book,key:"books"},{type:"collection",name:_.indexType.collection,key:"collections"},{type:"entity",name:_.indexType.entity,key:"entities"}],B=["work","collection","book","entity"],[T,I]=b.useState(u??""),[H,M]=b.useState(null),[q,O]=b.useState(u??""),ie=Rn(j).toString(),[oe,le]=b.useState(j);b.useEffect(()=>{le(j)},[ie]);const ae=Y=>{le(Y),x==null||x(Y)},[pe,ee]=b.useState(null),[ge,W]=b.useState("all"),[ze,U]=b.useState(!1),[re,be]=b.useState(null),[X,L]=b.useState(""),[_e,P]=b.useState(!(u!=null&&u.trim())),[K,z]=b.useState(ei),[V,de]=b.useState([]),[ue,He]=b.useState(!1),[G,me]=b.useState(!1),[ce,Oe]=b.useState(null),[Te,je]=b.useState(null),Re=b.useRef(void 0),Ie=b.useRef(!1),Je=b.useCallback(async(Y,$e)=>{if(!Y.trim()){P(!0),M(null),ee(null);return}if(P(!1),w){O(Y);return}U(!0),L("");try{if(e.searchAll){const ke=await e.searchAll(Y,$e??_r);M(ke)}else{const ke=["work","book","collection","entity"],Ce=await Promise.all(ke.map(Qe=>e.search(Y,Qe,{page:1,pageSize:$e??_r})));M({works:Ce[0].entries,books:Ce[1].entries,collections:Ce[2].entries,entities:Ce[3].entries,totalWorks:Ce[0].total,totalBooks:Ce[1].total,totalCollections:Ce[2].total,totalEntities:Ce[3].total})}}catch(ke){L(ke instanceof Error?ke.message:String(ke)),M(null)}finally{U(!1)}},[e,w]);b.useEffect(()=>{let Y=!1;const $e=()=>{var et,yt;const ke=["work","book","collection","entity"],Ce=Promise.all(ke.map(Be=>e.loadEntries(Be,{page:1,pageSize:1}).catch(()=>({total:0})))),Qe=((et=e.getResourceCounts)==null?void 0:et.call(e).catch(()=>null))??Promise.resolve(null),Le=((yt=e.getSubtypeStats)==null?void 0:yt.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Ce,Qe,Le]).then(([Be,J,we])=>{Y||(Oe({works:Be[0].total,books:Be[1].total,collections:Be[2].total,entities:Be[3].total,hasText:J==null?void 0:J.hasText,hasImage:J==null?void 0:J.hasImage}),we&&je(we))})};return e.getCounts?e.getCounts().then(ke=>{var Ce,Qe;Y||(Oe({works:ke.works,books:ke.books,collections:ke.collections,entities:ke.entities,hasText:(Ce=ke.resourceCounts)==null?void 0:Ce.hasText,hasImage:(Qe=ke.resourceCounts)==null?void 0:Qe.hasImage}),ke.subtypeStats&&je(ke.subtypeStats))}).catch(()=>{Y||$e()}):$e(),()=>{Y=!0}},[e]),b.useEffect(()=>{Ie.current||!(u!=null&&u.trim())||(Ie.current=!0,Je(u))},[u,Je]);const ut=b.useCallback(Y=>{if(I(Y),!Y.trim()){f==null||f(Y),P(!0),M(null),ee(null),W("all");return}Re.current&&clearTimeout(Re.current),Re.current=setTimeout(()=>{ee(null),W("all"),f==null||f(Y),Je(Y)},tp)},[Je,f]),Ve=b.useCallback(Y=>{Re.current&&clearTimeout(Re.current),W("all"),f==null||f(Y),Je(Y)},[Je,f]),ht=b.useCallback(Y=>{ee(Y),Je(T,ep)},[T,Je]);b.useEffect(()=>{if(!K.length){de([]);return}let Y=!1;return He(!0),Promise.all(K.slice(0,10).map($e=>ys(e,$e))).then($e=>{Y||(de($e),He(!1))}),()=>{Y=!0}},[K,e]);const Ge=Y=>{be(Y.id),Hr(Y.id),z(ei()),s==null||s(Y)},k=(Y,$e)=>{if(s&&rp($e)){$e.preventDefault(),Ge(Y);return}Hr(Y.id),z(ei())},te=Y=>{Pl(Y),z(ei())},Z=()=>{xs(),z([])},he=Y=>E.find($e=>$e.type===Y),Ae=!_e&&!H&&!X,R=H&&(H.works.length>0||H.books.length>0||H.collections.length>0),xe=t.jsxs(t.Fragment,{children:[t.jsx(hl,{transport:e,value:T,onChange:ut,onSearch:Ve,onEntrySelect:Ge}),w&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const Y=T.trim();Y&&bl(Y),Ve(T)},children:_.searchPage.submit}),o&&t.jsx("button",{onClick:()=>o("work"),style:{padding:"8px 14px",border:`1px solid ${r.bim("primary")}`,borderRadius:"6px",background:"transparent",color:r.bim("primary"),cursor:"pointer",fontSize:"13px"},children:_.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:y?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:sp+(w?op:"")}),(!w||g||!m)&&t.jsx("header",{style:{padding:`12px ${r.bim("browser-pad-x")}`,borderBottom:`1px solid ${r.bim("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[w?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:r.bim("fg")},children:_.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!m&&t.jsx(pl,{variant:"index-browser",indexSource:i,syncConfig:n,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),w?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:xe})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:`12px ${r.bim("browser-pad-x")}`,alignItems:"center"},children:xe}),_e&&t.jsx("div",{className:"bim-ib-stats",style:{padding:`0 ${r.bim("browser-pad-x")} 8px`,fontSize:"12px",color:r.bim("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:ce&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:Te?t.jsxs(t.Fragment,{children:[(Te.book??0)>0&&t.jsxs(t.Fragment,{children:[_.searchPage.statBook," ",t.jsx("strong",{style:{color:r.bim("fg")},children:Te.book.toLocaleString()})," ",_.unit.bu,_.searchPage.statComma,t.jsx("strong",{style:{color:r.bim("fg")},children:ce.books.toLocaleString()})," ",_.searchPage.statBookCopies]}),Te.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statArticle," ",t.jsx("strong",{style:{color:r.bim("fg")},children:Te.article.toLocaleString()})," ",_.searchPage.statArticleUnit]}):null,Te.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statPoem," ",t.jsx("strong",{style:{color:r.bim("fg")},children:Te.poem.toLocaleString()})," ",_.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.searchPage.statCollection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ce.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[_.indexType.work," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ce.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.book," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ce.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.collection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ce.collections.toLocaleString()}),ce.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.indexType.entity," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ce.entities.toLocaleString()})]})]})}),ce.hasImage!=null&&ce.hasText!=null&&t.jsxs("span",{children:[_.resourceType.image," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ce.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),_.resourceType.text," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ce.hasText.toLocaleString()})]})]})}),w&&!_e&&t.jsx(Ll,{transport:e,query:q,filters:oe,onFiltersChange:ae,onEntryLinkClick:k,typeName:Y=>he(Y).name,tab:S,onTabChange:v,page:$,onPageChange:N}),!(w&&!_e)&&t.jsx("div",{style:{padding:`0 ${r.bim("browser-pad-x")} 20px`,flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:ze||Ae?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg"),minHeight:np,boxSizing:"border-box"},children:_.search.searching}):X?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r.bim("desc-fg")},children:X})}):_e?t.jsx("div",{style:{flex:1},children:ue?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg")},children:_.search.loading}):V.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:r.bim("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:_.search.recentBrowse}),t.jsx("button",{onClick:Z,style:{border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:_.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:V.slice(0,G?10:3).map(Y=>Y.notFound?t.jsx(dp,{id:Y.id,onRemove:te,t:_},Y.id):t.jsx(ea,{entry:Y,selected:re===Y.id,onClick:k,getConfig:he,onRemove:te},Y.id))}),!G&&V.length>3&&t.jsx("button",{onClick:()=>me(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:r.bim("primary"),background:"transparent",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:_.action.expandMore})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r.bim("fg")},children:_.search.searchTitle}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:_.search.searchSubtitle})]})}):R?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:ap}),(()=>{const Y=Le=>H[Qo[Le]]??0,$e=B.map(Le=>E.find(et=>et.type===Le)).filter(Le=>Y(Le.key)>0);if($e.length<2)return null;const ke=$e.reduce((Le,et)=>Le+Y(et.key),0),Ce=Le=>{if(W(Le),Le!=="all"&&pe!==Le){const et=E.find(Be=>Be.type===Le),yt=(H[et.key]??[]).length;Y(et.key)>yt&&ht(Le)}},Qe=Le=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:Le?r.bim("fg"):r.bim("desc-fg"),fontWeight:Le?700:400,boxShadow:Le?`inset 0 -2px 0 ${r.bim("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":_.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${r.bim("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":ge==="all",style:Qe(ge==="all"),onClick:()=>Ce("all"),children:[_.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:ke.toLocaleString()})]}),$e.map(Le=>t.jsxs("button",{type:"button","aria-pressed":ge===Le.type,style:Qe(ge===Le.type),onClick:()=>Ce(Le.type),children:[Le.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:Y(Le.key).toLocaleString()})]},Le.type))]})})(),E.map(({type:Y,name:$e,key:ke})=>{const Ce=H[ke]??[],Qe=Qo[ke],Le=H[Qe]??0;if(Ce.length===0||ge!=="all"&&ge!==Y)return null;const yt=ge==="all"&&!(pe===Y)&&Le>_r;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${r.bim("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:r.bim("fg")},children:[t.jsx(Gi,{type:Y})," ",$e,t.jsxs("span",{style:{fontWeight:400,color:r.bim("desc-fg"),marginLeft:"6px"},children:[Le," ",_.unit.items]})]}),yt&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>ht(Y),style:{border:"none",background:"transparent",color:r.bim("primary"),cursor:"pointer",fontSize:"12px"},children:_.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:Ce.map(Be=>{if(h)return t.jsx(b.Fragment,{children:h(Be)},Be.id);const J=p==="card"?cp:ea;return t.jsx(J,{entry:Be,selected:re===Be.id,onClick:k,getConfig:he,query:T},Be.id)})})]},Y)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r.bim("fg")},children:r.formatTemplate(_.search.noResultsFor,{query:T})}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:_.search.tryOther})]})})]})},np=240;function rp(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const sp=`
|
|
120
|
+
`,ys="bim-search-view",$r=50,Xo=5,Di=1e3;function kn(e){return e>=Di?`${Di.toLocaleString()}+`:e.toLocaleString()}const Ju={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function Zu(e){return e&&Ju[e.toLowerCase()]||"all"}function Qu(e){return e==="all"?null:e}const Jo=["work","collection","book","entity"],ep={work:"works",collection:"collections",book:"books",entity:"entities"},tp={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function ip(){try{return window.localStorage.getItem(ys)==="card"?"card":"table"}catch{return"table"}}function np(e){try{window.localStorage.setItem(ys,e)}catch{}}const gi=(e,i)=>(e==null?void 0:e[tp[i]])??0,_r=(e,i)=>(e==null?void 0:e[ep[i]])??[],Bl=({transport:e,query:i,filters:n,onFiltersChange:s,onEntryLinkClick:o,typeName:a,tab:l,onTabChange:d,page:c,onPageChange:m})=>{const p=r.useT(),h=p.searchV4,{convert:u}=gt(),f=!!e.supportsSearchFilters,g=b.useMemo(()=>f?n:Un,[f,n]),[y,w]=b.useState("table");b.useEffect(()=>{w(ip())},[]);const j=_=>{w(_),np(_)},[x,v]=b.useState(l??"all"),S=b.useRef(x);S.current=x,b.useEffect(()=>{l!==void 0&&l!==S.current&&(v(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 R=b.useRef(null),O=b.useCallback(_=>{var ie;N(_),m==null||m(_);const P=R.current;P&&P.getBoundingClientRect().top<0&&((ie=P.scrollIntoView)==null||ie.call(P,{block:"start",behavior:"instant"}))},[m]),[C,I]=b.useState(null),[D,A]=b.useState(null),[X,B]=b.useState(!1),[ae,te]=b.useState(""),ce=Tn(g).toString(),be=Vn(g)>0,oe=Tn({...g,sort:""}).toString(),K=b.useRef({query:i,filterOnlyKey:oe,sort:g.sort});b.useEffect(()=>{const _=K.current;_.query!==i||_.filterOnlyKey!==oe?(v("all"),N(1)):_.sort!==g.sort&&N(1),K.current={query:i,filterOnlyKey:oe,sort:g.sort}},[i,oe,g.sort]),b.useEffect(()=>{let _=!1;return B(!0),te(""),(async()=>{try{let P;if(e.searchAll)P=await e.searchAll(i,Xo,g);else{const ie=["work","book","collection","entity"],re=await Promise.all(ie.map(Re=>e.search(i,Re,{page:1,pageSize:Xo,filters:g})));P={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}}_||I(P)}catch(P){_||(te(P instanceof Error?P.message:String(P)),I(null))}finally{_||B(!1)}})(),()=>{_=!0}},[e,i,ce]);const ze=x;b.useEffect(()=>{if(x==="all"){A(null);return}let _=!1;return B(!0),(async()=>{try{const P=await e.search(i,x,{page:$,pageSize:$r,filters:g});_||A({key:ze,entries:P.entries,total:P.total})}catch(P){_||(te(P instanceof Error?P.message:String(P)),A(null))}finally{_||B(!1)}})(),()=>{_=!0}},[e,i,ce,x,$]);const F=D&&D.key===ze?D:null;b.useEffect(()=>{if(x==="all"||!F||X)return;const _=Math.min(F.total,Di),P=Vu($,_,$r);F.entries.length===0&&_>0&&P!==$&&(N(P),m==null||m(P))},[x,F,X,$]);const me=b.useMemo(()=>Jo.filter(_=>gi(C,_)>0),[C]),U=me.reduce((_,P)=>_+gi(C,P),0),ne=me.some(_=>gi(C,_)>=Di)?`${U.toLocaleString()}+`:U.toLocaleString(),ue=!X&&!ae&&C!==null&&U===0,G=b.useCallback(_=>{v(_),N(1),d==null||d(_)},[d]),L=b.useMemo(()=>{const _=[];return g.dynasty.forEach(P=>_.push({name:P,remove:()=>s({...g,dynasty:g.dynasty.filter(ie=>ie!==P)})})),g.classification.forEach(P=>{var ie;return _.push({name:P?((ie=Yn.find(re=>re.value===P))==null?void 0:ie.label)??P:p.searchPage.unclassified,remove:()=>s({...g,classification:g.classification.filter(re=>re!==P)})})}),g.hasImage&&_.push({name:h.hasImage,remove:()=>s({...g,hasImage:!1})}),g.hasText&&_.push({name:h.hasText,remove:()=>s({...g,hasText:!1})}),g.hasCollated&&_.push({name:h.hasCollated,remove:()=>s({...g,hasCollated:!1})}),g.loss&&_.push({name:`${h.extant}:${p.searchPage.loss[g.loss]}`,remove:()=>s({...g,loss:""})}),_},[g,s,h,p]),Se={query:i,onEntryLinkClick:o,typeName:a},ge=_=>y==="table"?t.jsx(Go,{entries:_,...Se}):t.jsx(qo,{entries:_,...Se}),$e=Jo.flatMap(_=>_r(C,_));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:Xu}),f&&t.jsx(Uu,{filters:g,onChange:s}),t.jsxs("div",{className:"bim-sr-main","aria-busy":X,ref:R,children:[me.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 ${r.bim("rule")}`},children:[t.jsxs(Zo,{on:x==="all",onClick:()=>G("all"),children:[p.search.allTab," ",t.jsx("small",{children:ne})]}),me.map(_=>t.jsxs(Zo,{on:x===_,onClick:()=>G(_),children:[a(_)," ",t.jsx("small",{children:kn(gi(C,_))})]},_))]}),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:()=>s({...g,sort:""}),children:u(h.sortRelevance)}),["era","title"].map(_=>{const P=g.sort.startsWith(`${_}:`)?g.sort.endsWith("desc")?"desc":"asc":null,ie=_==="era"?h.sortEra:h.sortTitle,re=_==="era"?P==="desc"?h.sortEraDesc:h.sortEraAsc:P==="desc"?h.sortTitleDesc:h.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":P!==null,title:u(re),onClick:()=>s({...g,sort:`${_}:${P==="asc"?"desc":"asc"}`}),children:[u(ie),P?t.jsxs("span",{"aria-hidden":"true",children:[" ",P==="asc"?"↑":"↓"]}):null]},_)})]}),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:()=>j("table"),children:u(h.viewTable)}),t.jsx("button",{type:"button","aria-pressed":y==="card",onClick:()=>j("card"),children:u(h.viewCard)})]})]}),be&&t.jsxs("div",{className:"bim-sr-chips-row",children:[t.jsx("span",{className:"bim-sr-count",role:"status",children:u(r.formatTemplate(h.filteredCount,{n:ne}))}),L.map(_=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u(r.formatTemplate(h.removeFilter,{name:_.name})),onClick:_.remove,children:[u(_.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},_.name))]}),ae&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:ae}),ue&&t.jsx("div",{className:"bim-sr-empty",children:u(be?h.emptyFiltered:r.formatTemplate(p.search.noResultsFor,{query:i}))}),!ae&&!ue&&x==="all"&&C&&(y==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Go,{entries:$e,...Se}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(h.limitedNote)})]}):t.jsx(t.Fragment,{children:me.map(_=>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(Gi,{type:_,size:8}),a(_),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r.bim("meta-fg")},children:[kn(gi(C,_))," ",p.unit.items]})]}),gi(C,_)>_r(C,_).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>G(_),children:p.action.viewAll})]}),t.jsx(qo,{entries:_r(C,_),...Se})]},_))})),!ae&&x!=="all"&&!F&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:p.search.loading}),!ae&&x!=="all"&&F&&F.entries.length>0&&t.jsxs(t.Fragment,{children:[ge(F.entries),t.jsx(Gu,{page:$,pageSize:$r,total:Math.min(F.total,Di),totalLabel:kn(F.total),onPage:O})]}),!ae&&x!=="all"&&F&&F.entries.length===0&&!X&&t.jsxs("div",{className:"bim-sr-empty",children:[u(be?h.emptyFiltered:r.formatTemplate(p.search.noResultsFor,{query:i})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>G("all"),children:p.search.allTab})})]})]})]})};function Zo({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?r.bim("ink"):r.bim("meta-fg"),fontWeight:e?700:400,boxShadow:e?`inset 0 -2px 0 ${r.bim("accent")}`:"none"},children:n})}const _i="bim-recent-ids",Qo="bim-recent-entries",ea=50;function ei(){try{const e=localStorage.getItem(_i);if(e)return JSON.parse(e);const i=localStorage.getItem(Qo);if(i){const n=JSON.parse(i).map(s=>s.id);return localStorage.setItem(_i,JSON.stringify(n)),localStorage.removeItem(Qo),n}return[]}catch{return[]}}function Wr(e){try{const i=ei().filter(n=>n!==e);i.unshift(e),i.length>ea&&(i.length=ea),localStorage.setItem(_i,JSON.stringify(i))}catch{}}function Hl(e){try{const i=ei().filter(n=>n!==e);localStorage.setItem(_i,JSON.stringify(i))}catch{}}function js(){try{localStorage.removeItem(_i)}catch{}}async function ks(e,i){var n,s,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:(s=l==null?void 0:l[0])==null?void 0:s.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 Nr=5,rp=50,sp=200,ta={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},op=({transport:e,indexSource:i="local",syncConfig:n,onEntryClick:s,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:w=!1,filters:j=Un,onFiltersChange:x,resultTab:v,onResultTabChange:S,resultPage:$,onResultPageChange:N})=>{const z=r.useT(),R=[{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"}],O=["work","collection","book","entity"],[C,I]=b.useState(u??""),[D,A]=b.useState(null),[X,B]=b.useState(u??""),ae=Tn(j).toString(),[te,ce]=b.useState(j);b.useEffect(()=>{ce(j)},[ae]);const be=V=>{ce(V),x==null||x(V)},[oe,K]=b.useState(null),[ze,F]=b.useState("all"),[me,U]=b.useState(!1),[ne,ue]=b.useState(null),[G,L]=b.useState(""),[Se,ge]=b.useState(!(u!=null&&u.trim())),[$e,_]=b.useState(ei),[P,ie]=b.useState([]),[re,Re]=b.useState(!1),[Y,de]=b.useState(!1),[le,Te]=b.useState(null),[_e,xe]=b.useState(null),Ce=b.useRef(void 0),Ae=b.useRef(!1),Je=b.useCallback(async(V,Ne)=>{if(!V.trim()){ge(!0),A(null),K(null);return}if(ge(!1),w){B(V);return}U(!0),L("");try{if(e.searchAll){const je=await e.searchAll(V,Ne??Nr);A(je)}else{const je=["work","book","collection","entity"],Ie=await Promise.all(je.map(Qe=>e.search(V,Qe,{page:1,pageSize:Ne??Nr})));A({works:Ie[0].entries,books:Ie[1].entries,collections:Ie[2].entries,entities:Ie[3].entries,totalWorks:Ie[0].total,totalBooks:Ie[1].total,totalCollections:Ie[2].total,totalEntities:Ie[3].total})}}catch(je){L(je instanceof Error?je.message:String(je)),A(null)}finally{U(!1)}},[e,w]);b.useEffect(()=>{let V=!1;const Ne=()=>{var et,yt;const je=["work","book","collection","entity"],Ie=Promise.all(je.map(He=>e.loadEntries(He,{page:1,pageSize:1}).catch(()=>({total:0})))),Qe=((et=e.getResourceCounts)==null?void 0:et.call(e).catch(()=>null))??Promise.resolve(null),Oe=((yt=e.getSubtypeStats)==null?void 0:yt.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Ie,Qe,Oe]).then(([He,q,ke])=>{V||(Te({works:He[0].total,books:He[1].total,collections:He[2].total,entities:He[3].total,hasText:q==null?void 0:q.hasText,hasImage:q==null?void 0:q.hasImage}),ke&&xe(ke))})};return e.getCounts?e.getCounts().then(je=>{var Ie,Qe;V||(Te({works:je.works,books:je.books,collections:je.collections,entities:je.entities,hasText:(Ie=je.resourceCounts)==null?void 0:Ie.hasText,hasImage:(Qe=je.resourceCounts)==null?void 0:Qe.hasImage}),je.subtypeStats&&xe(je.subtypeStats))}).catch(()=>{V||Ne()}):Ne(),()=>{V=!0}},[e]),b.useEffect(()=>{Ae.current||!(u!=null&&u.trim())||(Ae.current=!0,Je(u))},[u,Je]);const ut=b.useCallback(V=>{if(I(V),!V.trim()){f==null||f(V),ge(!0),A(null),K(null),F("all");return}Ce.current&&clearTimeout(Ce.current),Ce.current=setTimeout(()=>{K(null),F("all"),f==null||f(V),Je(V)},sp)},[Je,f]),Ve=b.useCallback(V=>{Ce.current&&clearTimeout(Ce.current),F("all"),f==null||f(V),Je(V)},[Je,f]),ht=b.useCallback(V=>{K(V),Je(C,rp)},[C,Je]);b.useEffect(()=>{if(!$e.length){ie([]);return}let V=!1;return Re(!0),Promise.all($e.slice(0,10).map(Ne=>ks(e,Ne))).then(Ne=>{V||(ie(Ne),Re(!1))}),()=>{V=!0}},[$e,e]);const Ge=V=>{ue(V.id),Wr(V.id),_(ei()),s==null||s(V)},k=(V,Ne)=>{if(s&&lp(Ne)){Ne.preventDefault(),Ge(V);return}Wr(V.id),_(ei())},Q=V=>{Hl(V),_(ei())},J=()=>{js(),_([])},pe=V=>R.find(Ne=>Ne.type===V),Pe=!Se&&!D&&!G,T=D&&(D.works.length>0||D.books.length>0||D.collections.length>0),fe=t.jsxs(t.Fragment,{children:[t.jsx(yl,{transport:e,value:C,onChange:ut,onSearch:Ve,onEntrySelect:Ge}),w&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const V=C.trim();V&&xl(V),Ve(C)},children:z.searchPage.submit}),o&&t.jsx("button",{onClick:()=>o("work"),style:{padding:"8px 14px",border:`1px solid ${r.bim("primary")}`,borderRadius:"6px",background:"transparent",color:r.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:cp+(w?dp:"")}),(!w||g||!m)&&t.jsx("header",{style:{padding:`12px ${r.bim("browser-pad-x")}`,borderBottom:`1px solid ${r.bim("widget-border")}`},children:t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[w?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:r.bim("fg")},children:z.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!m&&t.jsx(gl,{variant:"index-browser",indexSource:i,syncConfig:n,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),w?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:fe})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:`12px ${r.bim("browser-pad-x")}`,alignItems:"center"},children:fe}),Se&&t.jsx("div",{className:"bim-ib-stats",style:{padding:`0 ${r.bim("browser-pad-x")} 8px`,fontSize:"12px",color:r.bim("desc-fg"),display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:le&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:_e?t.jsxs(t.Fragment,{children:[(_e.book??0)>0&&t.jsxs(t.Fragment,{children:[z.searchPage.statBook," ",t.jsx("strong",{style:{color:r.bim("fg")},children:_e.book.toLocaleString()})," ",z.unit.bu,z.searchPage.statComma,t.jsx("strong",{style:{color:r.bim("fg")},children:le.books.toLocaleString()})," ",z.searchPage.statBookCopies]}),_e.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statArticle," ",t.jsx("strong",{style:{color:r.bim("fg")},children:_e.article.toLocaleString()})," ",z.searchPage.statArticleUnit]}):null,_e.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statPoem," ",t.jsx("strong",{style:{color:r.bim("fg")},children:_e.poem.toLocaleString()})," ",z.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.searchPage.statCollection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:le.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[z.indexType.work," ",t.jsx("strong",{style:{color:r.bim("fg")},children:le.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.book," ",t.jsx("strong",{style:{color:r.bim("fg")},children:le.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.collection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:le.collections.toLocaleString()}),le.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.indexType.entity," ",t.jsx("strong",{style:{color:r.bim("fg")},children:le.entities.toLocaleString()})]})]})}),le.hasImage!=null&&le.hasText!=null&&t.jsxs("span",{children:[z.resourceType.image," ",t.jsx("strong",{style:{color:r.bim("fg")},children:le.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),z.resourceType.text," ",t.jsx("strong",{style:{color:r.bim("fg")},children:le.hasText.toLocaleString()})]})]})}),w&&!Se&&t.jsx(Bl,{transport:e,query:X,filters:te,onFiltersChange:be,onEntryLinkClick:k,typeName:V=>pe(V).name,tab:v,onTabChange:S,page:$,onPageChange:N}),!(w&&!Se)&&t.jsx("div",{style:{padding:`0 ${r.bim("browser-pad-x")} 20px`,flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:me||Pe?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg"),minHeight:ap,boxSizing:"border-box"},children:z.search.searching}):G?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r.bim("desc-fg")},children:G})}):Se?t.jsx("div",{style:{flex:1},children:re?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg")},children:z.search.loading}):P.length>0?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:r.bim("desc-fg"),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[t.jsx("span",{children:z.search.recentBrowse}),t.jsx("button",{onClick:J,style:{border:"none",background:"transparent",color:r.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:P.slice(0,Y?10:3).map(V=>V.notFound?t.jsx(bp,{id:V.id,onRemove:Q,t:z},V.id):t.jsx(ia,{entry:V,selected:ne===V.id,onClick:k,getConfig:pe,onRemove:Q},V.id))}),!Y&&P.length>3&&t.jsx("button",{onClick:()=>de(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:r.bim("primary"),background:"transparent",border:`1px solid ${r.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:r.bim("fg")},children:z.search.searchTitle}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:z.search.searchSubtitle})]})}):T?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:mp}),(()=>{const V=Oe=>D[ta[Oe]]??0,Ne=O.map(Oe=>R.find(et=>et.type===Oe)).filter(Oe=>V(Oe.key)>0);if(Ne.length<2)return null;const je=Ne.reduce((Oe,et)=>Oe+V(et.key),0),Ie=Oe=>{if(F(Oe),Oe!=="all"&&oe!==Oe){const et=R.find(He=>He.type===Oe),yt=(D[et.key]??[]).length;V(et.key)>yt&&ht(Oe)}},Qe=Oe=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:Oe?r.bim("fg"):r.bim("desc-fg"),fontWeight:Oe?700:400,boxShadow:Oe?`inset 0 -2px 0 ${r.bim("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":z.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${r.bim("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":ze==="all",style:Qe(ze==="all"),onClick:()=>Ie("all"),children:[z.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:je.toLocaleString()})]}),Ne.map(Oe=>t.jsxs("button",{type:"button","aria-pressed":ze===Oe.type,style:Qe(ze===Oe.type),onClick:()=>Ie(Oe.type),children:[Oe.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:V(Oe.key).toLocaleString()})]},Oe.type))]})})(),R.map(({type:V,name:Ne,key:je})=>{const Ie=D[je]??[],Qe=ta[je],Oe=D[Qe]??0;if(Ie.length===0||ze!=="all"&&ze!==V)return null;const yt=ze==="all"&&!(oe===V)&&Oe>Nr;return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${r.bim("widget-border")}`,marginBottom:"6px"},children:[t.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:r.bim("fg")},children:[t.jsx(Gi,{type:V})," ",Ne,t.jsxs("span",{style:{fontWeight:400,color:r.bim("desc-fg"),marginLeft:"6px"},children:[Oe," ",z.unit.items]})]}),yt&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>ht(V),style:{border:"none",background:"transparent",color:r.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:Ie.map(He=>{if(h)return t.jsx(b.Fragment,{children:h(He)},He.id);const q=p==="card"?pp:ia;return t.jsx(q,{entry:He,selected:ne===He.id,onClick:k,getConfig:pe,query:C},He.id)})})]},V)})]}):t.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[t.jsx("h2",{style:{margin:"0 0 8px",fontSize:"1.17em",color:r.bim("fg")},children:r.formatTemplate(z.search.noResultsFor,{query:C})}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:z.search.tryOther})]})})]})},ap=240;function lp(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const cp=`
|
|
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
|
+
`,dp=`
|
|
124
124
|
.bim-ib-bar { display: grid; grid-template-columns: 208px minmax(0, 1fr); column-gap: 40px; padding: 0 ${r.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
|
+
`,mp=`
|
|
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
|
-
}`,Ol={color:"inherit",textDecoration:"none"},lp=({snippet:e})=>{const{convert:i}=gt();return t.jsx("div",{style:{fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.6},children:cs(e).map((n,s)=>n.marked?t.jsx("mark",{style:{background:r.bim("highlight-bg"),color:r.bim("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:i(n.text)},s):t.jsx(b.Fragment,{children:i(n.text)},s))})},cp=({entry:e,selected:i,onClick:n,getConfig:s,query:o})=>{const a=r.useT(),{convert:l}=gt(),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?`${Ki(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=r.bim("cover-accent"),u=Tt();return t.jsxs("a",{href:u(e.id),onClick:f=>n(e,f),className:"bim-result-card",style:{...Ol,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:r.bim("bg"),border:i?`1px solid ${r.bim("primary")}`:`1px solid ${r.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%, ${r.bim("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${h} 14%, ${r.bim("bg")}), color-mix(in srgb, ${h} 7%, ${r.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:r.bim("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:r.bim("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:r.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:r.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:r.bim("desc-fg")},children:[a.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.descriptionSnippet&&t.jsx(lp,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r.bim("desc-fg"),border:`1px solid ${r.bim("widget-border")}`},children:[t.jsx(Gi,{type:e.type,size:8})," ",s(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r.bim("desc-fg"),border:`1px solid ${r.bim("widget-border")}`},children:a.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r.bim("desc-fg"),border:`1px solid ${r.bim("widget-border")}`},children:a.misc.imageResource})]})]})]})},ea=({entry:e,selected:i,onClick:n,getConfig:s,query:o,onRemove:a})=>{const l=r.useT(),{convert:d}=gt(),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=Tt();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:i?`1px solid ${r.bim("primary")}`:`1px solid ${r.bim("widget-border")}`,background:r.bim("input-bg")},children:[t.jsxs("a",{href:p(e.id),onClick:h=>n(e,h),className:"bim-result-card",style:{...Ol,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(Gi,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:r.bim("desc-fg"),lineHeight:1},children:s(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:r.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:r.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:r.bim("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:[Ki(e.juan_count),l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:r.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:r.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:r.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},dp=({id:e,onRemove:i,t:n})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${r.bim("widget-border")}`,background:r.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:r.bim("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:r.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:r.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function mp({data:e}){const i=r.useT(),{convert:n}=gt(),{stats:s}=e,o=s.processed_volumes??s.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:r.bim("fg"),margin:"0 0 8px"},children:n(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:r.bim("desc-fg"),marginBottom:"6px"},children:n(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:r.bim("desc-fg")},children:[t.jsxs("span",{children:[i.catalog.totalVolumes," ",t.jsx("strong",{style:{color:r.bim("fg")},children:e.total_volumes})," ",i.unit.volume]}),a!=null&&t.jsxs("span",{children:[i.catalog.processed," ",t.jsx("strong",{style:{color:r.bim("fg")},children:o})," ",i.unit.volume," (",a,"%)"]}),t.jsxs("span",{children:[i.catalog.contains," ",t.jsx("strong",{style:{color:r.bim("fg")},children:s.total_books})," ",i.unit.bu]}),s.matched_works!=null&&s.matched_works>0&&t.jsxs("span",{children:[i.catalog.matched," ",t.jsx("strong",{style:{color:r.bim("fg")},children:s.matched_works})," ",i.unit.bu]}),s.unmatched_works!=null&&s.unmatched_works>0&&t.jsxs("span",{children:[i.catalog.unmatched," ",t.jsx("strong",{style:{color:r.bim("missing-fg")},children:s.unmatched_works})," ",i.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:r.bim("desc-fg")},children:[i.catalog.source," ",e.source]})]})}function up({sections:e,activeSection:i,onSelect:n}){const s=r.useT();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>n(null),style:ta(i===null),children:s.catalog.all}),e.map(o=>t.jsxs("button",{onClick:()=>n(o.name),style:ta(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 ta(e){return{padding:"4px 12px",border:e?`1px solid ${r.bim("primary")}`:`1px solid ${r.bim("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${r.bim("primary")} 8%, transparent)`:"transparent",color:e?r.bim("primary"):r.bim("fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function pp({id:e,label:i,onNavigate:n,renderLink:s}){const o=Tt();return s?t.jsx(t.Fragment,{children:s(e,i)}):n?t.jsx("a",{href:o(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),n(e))},style:{color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${r.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:r.bim("desc-fg")},children:i||e})}function bp(e,i){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=e[0],s=e[e.length-1];return s-n+1===e.length?`${n}–${s}`:e.length<=3?e.join(", "):`${n}–${s} (${e.length}${i})`}function ia({book:e,onNavigate:i,renderLink:n,showVolumes:s}){const o=r.useT(),{convert:a}=gt(),l=e.book_id||e.work_id,d=s&&e.volumes.length>0?bp(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 ${r.bim("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[s&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:r.bim("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:r.bim("fg")},children:[a(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:r.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:r.bim("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:c?r.bim("missing-fg"):r.bim("desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,o.unit.volume]}),l&&t.jsx(pp,{id:l,label:e.book_id?o.indexType.book:o.indexType.work,onNavigate:i,renderLink:n}),!l&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),flexShrink:0},children:o.catalog.unmatched_label})]})}const Fl=({data:e,collectionId:i,transport:n,onNavigate:s,renderLink:o,className:a,style:l})=>{const d=r.useT(),[c,m]=b.useState(null),[p,h]=b.useState(!1),[u,f]=b.useState(null),[g,y]=b.useState(null),[w,j]=b.useState(""),x=e||c;b.useEffect(()=>{if(e||!i||!(n!=null&&n.getCollectionCatalog))return;let _=!1;return h(!0),f(null),n.getCollectionCatalog(i).then(E=>{_||(E?m(E):f(d.catalog.notFound))}).catch(E=>{_||f(E instanceof Error?E.message:d.catalog.loadFailed)}).finally(()=>{_||h(!1)}),()=>{_=!0}},[e,i,n,d]);const S=(x==null?void 0:x.sections)&&x.sections.length>0,v=b.useMemo(()=>{if(!x)return!1;if(x.volume_index&&Object.keys(x.volume_index).length>0)return!0;const _=x.books.map(B=>B.volumes[0]).filter(B=>B!=null);return new Set(_).size<_.length},[x]),$=b.useMemo(()=>{if(!x)return[];let _=x.books;if(g&&(_=_.filter(E=>E.section===g)),w.trim()){const E=w.trim().toLowerCase();_=_.filter(B=>B.title.toLowerCase().includes(E)||B.sub_items&&B.sub_items.some(T=>T.toLowerCase().includes(E))||B.edition&&B.edition.toLowerCase().includes(E))}return _},[x,g,w]),N=b.useMemo(()=>{if(!v)return null;const _=[],E=new Map;for(const T of $){if(!T.volumes||T.volumes.length===0)continue;const I=T.volumes[0];E.has(I)||E.set(I,[]),E.get(I).push(T)}const B=[...E.keys()].sort((T,I)=>T-I);for(const T of B)_.push({volume:T,books:E.get(T)});return _},[$,v]);return p?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):u?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:u}):x?t.jsxs("div",{className:a,style:l,children:[t.jsx(mp,{data:x}),S&&t.jsx(up,{sections:x.sections,activeSection:g,onSelect:y}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:w,onChange:_=>j(_.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${r.bim("input-border")}`,borderRadius:"4px",background:r.bim("input-bg"),color:r.bim("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:r.bim("desc-fg")},children:[$.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[N?N.map((_,E)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:r.bim("bg"),borderBottom:`1px solid ${r.bim("widget-border")}`,fontSize:"12px",fontWeight:600,color:r.bim("desc-fg"),position:"sticky",top:0,zIndex:1},children:r.formatTemplate(d.catalog.volume,{n:_.volume})}),_.books.map((B,T)=>t.jsx(ia,{book:B,onNavigate:s,renderLink:o,showVolumes:B.volumes.length>1},`${_.volume}-${T}`))]},`${_.volume}-${E}`)):$.map((_,E)=>t.jsx(ia,{book:_,onNavigate:s,renderLink:o,showVolumes:!0},E)),$.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Oi=e=>typeof e=="string"&&e?e:void 0;function hp(e){if(!e||typeof e!="object")return e;const i=[],n=o=>{const a=Oi(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 fp(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&&Oi(i.page_title)&&(n.page_title=Oi(i.page_title)),n.source_url===void 0&&Oi(i.source_url)&&(n.source_url=Oi(i.source_url))),Array.isArray(e.sections)&&(n.sections=e.sections.map(hp)),n}const Nr=e=>e?e.catch(()=>null):Promise.resolve(null);function Bl(e){const i=new Map;function n(s){var a;let o=i.get(s);return o||(o=Nr((a=e.getTextManifest)==null?void 0:a.call(e,s)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||i.delete(s),d}),i.set(s,o)),o}return{getManifest(s){return Se.isSafeSegment(s)?n(s):Promise.resolve(null)},async getIndex(s,o){return!Se.isSafeSegment(s)||!Se.isSafeSegment(o)||!e.getTextIndex?null:Nr(e.getTextIndex(s,o))},async getChapter(s,o,a,l){if(!Se.isSafeSegment(s)||!Se.isSafeSegment(o)||!Se.isSafeSegment(a)||!e.getChapter)return null;const d=await Nr(e.getChapter(s,o,a,l));return d&&d.json?{...d,json:fp(d.json)}:d}}}const Hl=()=>{const{t:e}=se(),[i,n]=b.useState(1);return b.useEffect(()=>{const s=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(s)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:r.bim("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(i)})},zr=String.raw`https?:\/\/[^\s()()<>"]+`,gp=new RegExp(String.raw`\[([^\]\n]+)\]\((${zr})\)`+String.raw`|(《[^》\n]+》)\s?[((](${zr})[))]`+`|(${zr})`,"g");function xp(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function yp(e){const i=[];let n=0;for(const s of e.matchAll(gp)){const o=s.index??0;o>n&&i.push({text:e.slice(n,o)}),s[1]!==void 0?i.push({text:s[1],url:s[2]}):s[3]!==void 0?i.push({text:s[3],url:s[4]}):i.push({text:xp(s[5]),url:s[5]}),n=o+s[0].length}return n<e.length&&i.push({text:e.slice(n)}),i}function Dl({text:e,convert:i,className:n="bim-rd-link"}){return t.jsx(t.Fragment,{children:yp(e).map((s,o)=>s.url?t.jsx("a",{className:n,href:s.url,target:"_blank",rel:"noopener noreferrer",children:i(s.text)},o):t.jsx(b.Fragment,{children:i(s.text)},o))})}const js="(min-width: 1100px)",kn="(max-width: 719px)",wn="(max-width: 859px)",jp=`${kn}, (pointer: coarse)`,Bt=r.bim("reader-top"),kp="48px",Wl=`
|
|
145
|
+
}`,Dl={color:"inherit",textDecoration:"none"},up=({snippet:e})=>{const{convert:i}=gt();return t.jsx("div",{style:{fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.6},children:ms(e).map((n,s)=>n.marked?t.jsx("mark",{style:{background:r.bim("highlight-bg"),color:r.bim("highlight-fg"),padding:"0 1px",borderRadius:"2px"},children:i(n.text)},s):t.jsx(b.Fragment,{children:i(n.text)},s))})},pp=({entry:e,selected:i,onClick:n,getConfig:s,query:o})=>{const a=r.useT(),{convert:l}=gt(),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?`${Ki(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=r.bim("cover-accent"),u=Tt();return t.jsxs("a",{href:u(e.id),onClick:f=>n(e,f),className:"bim-result-card",style:{...Dl,display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:r.bim("bg"),border:i?`1px solid ${r.bim("primary")}`:`1px solid ${r.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%, ${r.bim("widget-border")})`,background:`linear-gradient(color-mix(in srgb, ${h} 14%, ${r.bim("bg")}), color-mix(in srgb, ${h} 7%, ${r.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:r.bim("fg")},children:d}),c&&t.jsx("span",{style:{fontSize:"12px",color:r.bim("desc-fg")},children:c})]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"13px",color:r.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:r.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:r.bim("desc-fg")},children:[a.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.descriptionSnippet&&t.jsx(up,{snippet:e.descriptionSnippet}),t.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[t.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r.bim("desc-fg"),border:`1px solid ${r.bim("widget-border")}`},children:[t.jsx(Gi,{type:e.type,size:8})," ",s(e.type).name]}),e.has_text&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r.bim("desc-fg"),border:`1px solid ${r.bim("widget-border")}`},children:a.misc.textResource}),e.has_image&&t.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:r.bim("desc-fg"),border:`1px solid ${r.bim("widget-border")}`},children:a.misc.imageResource})]})]})]})},ia=({entry:e,selected:i,onClick:n,getConfig:s,query:o,onRemove:a})=>{const l=r.useT(),{convert:d}=gt(),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=Tt();return t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",borderRadius:"6px",border:i?`1px solid ${r.bim("primary")}`:`1px solid ${r.bim("widget-border")}`,background:r.bim("input-bg")},children:[t.jsxs("a",{href:p(e.id),onClick:h=>n(e,h),className:"bim-result-card",style:{...Dl,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(Gi,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color:r.bim("desc-fg"),lineHeight:1},children:s(e.type).name})]}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:r.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:r.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:r.bim("desc-fg")},children:d(e.measure_info)}):e.juan_count!=null&&e.juan_count>0?t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:[Ki(e.juan_count),l.unit.juan]}):null]}),(e.dynasty||e.author)&&t.jsxs("div",{style:{fontSize:"12px",color:r.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:r.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:r.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"12px 12px 12px 8px",lineHeight:1,opacity:.5},children:"×"})]})},bp=({id:e,onRemove:i,t:n})=>t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:`1px solid ${r.bim("widget-border")}`,background:r.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:r.bim("fg"),fontFamily:"monospace"},children:e}),t.jsx("div",{style:{fontSize:"11px",color:r.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:r.bim("desc-fg"),cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function hp({data:e}){const i=r.useT(),{convert:n}=gt(),{stats:s}=e,o=s.processed_volumes??s.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:r.bim("fg"),margin:"0 0 8px"},children:n(e.title)}),e.resource_name&&t.jsx("div",{style:{fontSize:"13px",color:r.bim("desc-fg"),marginBottom:"6px"},children:n(e.resource_name)}),t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:r.bim("desc-fg")},children:[t.jsxs("span",{children:[i.catalog.totalVolumes," ",t.jsx("strong",{style:{color:r.bim("fg")},children:e.total_volumes})," ",i.unit.volume]}),a!=null&&t.jsxs("span",{children:[i.catalog.processed," ",t.jsx("strong",{style:{color:r.bim("fg")},children:o})," ",i.unit.volume," (",a,"%)"]}),t.jsxs("span",{children:[i.catalog.contains," ",t.jsx("strong",{style:{color:r.bim("fg")},children:s.total_books})," ",i.unit.bu]}),s.matched_works!=null&&s.matched_works>0&&t.jsxs("span",{children:[i.catalog.matched," ",t.jsx("strong",{style:{color:r.bim("fg")},children:s.matched_works})," ",i.unit.bu]}),s.unmatched_works!=null&&s.unmatched_works>0&&t.jsxs("span",{children:[i.catalog.unmatched," ",t.jsx("strong",{style:{color:r.bim("missing-fg")},children:s.unmatched_works})," ",i.unit.bu]})]}),e.source&&t.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:r.bim("desc-fg")},children:[i.catalog.source," ",e.source]})]})}function fp({sections:e,activeSection:i,onSelect:n}){const s=r.useT();return t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[t.jsx("button",{onClick:()=>n(null),style:na(i===null),children:s.catalog.all}),e.map(o=>t.jsxs("button",{onClick:()=>n(o.name),style:na(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 na(e){return{padding:"4px 12px",border:e?`1px solid ${r.bim("primary")}`:`1px solid ${r.bim("widget-border")}`,borderRadius:"4px",background:e?`color-mix(in srgb, ${r.bim("primary")} 8%, transparent)`:"transparent",color:e?r.bim("primary"):r.bim("fg"),cursor:"pointer",fontSize:"13px",fontWeight:e?600:400}}function gp({id:e,label:i,onNavigate:n,renderLink:s}){const o=Tt();return s?t.jsx(t.Fragment,{children:s(e,i)}):n?t.jsx("a",{href:o(e),onClick:a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),n(e))},style:{color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",borderBottom:`1px dashed ${r.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:r.bim("desc-fg")},children:i||e})}function xp(e,i){if(e.length===0)return"";if(e.length===1)return`${e[0]}`;const n=e[0],s=e[e.length-1];return s-n+1===e.length?`${n}–${s}`:e.length<=3?e.join(", "):`${n}–${s} (${e.length}${i})`}function ra({book:e,onNavigate:i,renderLink:n,showVolumes:s}){const o=r.useT(),{convert:a}=gt(),l=e.book_id||e.work_id,d=s&&e.volumes.length>0?xp(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 ${r.bim("widget-border")}`,fontSize:"14px",lineHeight:1.8},children:[s&&t.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:r.bim("desc-fg"),textAlign:"right"},children:d}),t.jsxs("span",{style:{flex:1,fontWeight:500,color:r.bim("fg")},children:[a(e.title),e.sub_items&&e.sub_items.length>0&&t.jsxs("span",{style:{fontSize:"12px",color:r.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:r.bim("desc-fg"),fontWeight:400,marginLeft:"8px"},children:a(e.edition)})]}),e.expected_volumes!=null&&t.jsxs("span",{style:{fontSize:"11px",color:c?r.bim("missing-fg"):r.bim("desc-fg"),flexShrink:0},children:[e.found_volumes??0,"/",e.expected_volumes,o.unit.volume]}),l&&t.jsx(gp,{id:l,label:e.book_id?o.indexType.book:o.indexType.work,onNavigate:i,renderLink:n}),!l&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),flexShrink:0},children:o.catalog.unmatched_label})]})}const Wl=({data:e,collectionId:i,transport:n,onNavigate:s,renderLink:o,className:a,style:l})=>{const d=r.useT(),[c,m]=b.useState(null),[p,h]=b.useState(!1),[u,f]=b.useState(null),[g,y]=b.useState(null),[w,j]=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(R=>{z||(R?m(R):f(d.catalog.notFound))}).catch(R=>{z||f(R instanceof Error?R.message:d.catalog.loadFailed)}).finally(()=>{z||h(!1)}),()=>{z=!0}},[e,i,n,d]);const v=(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(O=>O.volumes[0]).filter(O=>O!=null);return new Set(z).size<z.length},[x]),$=b.useMemo(()=>{if(!x)return[];let z=x.books;if(g&&(z=z.filter(R=>R.section===g)),w.trim()){const R=w.trim().toLowerCase();z=z.filter(O=>O.title.toLowerCase().includes(R)||O.sub_items&&O.sub_items.some(C=>C.toLowerCase().includes(R))||O.edition&&O.edition.toLowerCase().includes(R))}return z},[x,g,w]),N=b.useMemo(()=>{if(!S)return null;const z=[],R=new Map;for(const C of $){if(!C.volumes||C.volumes.length===0)continue;const I=C.volumes[0];R.has(I)||R.set(I,[]),R.get(I).push(C)}const O=[...R.keys()].sort((C,I)=>C-I);for(const C of O)z.push({volume:C,books:R.get(C)});return z},[$,S]);return p?t.jsx("div",{className:a,style:{...l,padding:"24px"},children:t.jsx("div",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:d.catalog.loading})}):u?t.jsx("div",{className:a,style:{...l,padding:"24px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:u}):x?t.jsxs("div",{className:a,style:l,children:[t.jsx(hp,{data:x}),v&&t.jsx(fp,{sections:x.sections,activeSection:g,onSelect:y}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:w,onChange:z=>j(z.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:`1px solid ${r.bim("input-border")}`,borderRadius:"4px",background:r.bim("input-bg"),color:r.bim("input-fg"),fontSize:"13px",boxSizing:"border-box"}}),t.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:r.bim("desc-fg")},children:[$.length," ",d.unit.bu]})]}),t.jsxs("div",{style:{border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",overflow:"hidden"},children:[N?N.map((z,R)=>t.jsxs("div",{children:[t.jsx("div",{style:{padding:"4px 12px",background:r.bim("bg"),borderBottom:`1px solid ${r.bim("widget-border")}`,fontSize:"12px",fontWeight:600,color:r.bim("desc-fg"),position:"sticky",top:0,zIndex:1},children:r.formatTemplate(d.catalog.volume,{n:z.volume})}),z.books.map((O,C)=>t.jsx(ra,{book:O,onNavigate:s,renderLink:o,showVolumes:O.volumes.length>1},`${z.volume}-${C}`))]},`${z.volume}-${R}`)):$.map((z,R)=>t.jsx(ra,{book:z,onNavigate:s,renderLink:o,showVolumes:!0},R)),$.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Oi=e=>typeof e=="string"&&e?e:void 0;function yp(e){if(!e||typeof e!="object")return e;const i=[],n=o=>{const a=Oi(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 jp(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&&Oi(i.page_title)&&(n.page_title=Oi(i.page_title)),n.source_url===void 0&&Oi(i.source_url)&&(n.source_url=Oi(i.source_url))),Array.isArray(e.sections)&&(n.sections=e.sections.map(yp)),n}const zr=e=>e?e.catch(()=>null):Promise.resolve(null);function Ul(e){const i=new Map;function n(s){var a;let o=i.get(s);return o||(o=zr((a=e.getTextManifest)==null?void 0:a.call(e,s)).then(l=>{const d=l&&Array.isArray(l.versions)&&l.versions.length>0?l:null;return d||i.delete(s),d}),i.set(s,o)),o}return{getManifest(s){return ve.isSafeSegment(s)?n(s):Promise.resolve(null)},async getIndex(s,o){return!ve.isSafeSegment(s)||!ve.isSafeSegment(o)||!e.getTextIndex?null:zr(e.getTextIndex(s,o))},async getChapter(s,o,a,l){if(!ve.isSafeSegment(s)||!ve.isSafeSegment(o)||!ve.isSafeSegment(a)||!e.getChapter)return null;const d=await zr(e.getChapter(s,o,a,l));return d&&d.json?{...d,json:jp(d.json)}:d}}}const Kl=()=>{const{t:e}=se(),[i,n]=b.useState(1);return b.useEffect(()=>{const s=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(s)},[]),t.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:r.bim("desc-fg"),fontSize:"14px"},children:e("common.loading")+".".repeat(i)})},Cr=String.raw`https?:\/\/[^\s()()<>"]+`,kp=new RegExp(String.raw`\[([^\]\n]+)\]\((${Cr})\)`+String.raw`|(《[^》\n]+》)\s?[((](${Cr})[))]`+`|(${Cr})`,"g");function wp(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function vp(e){const i=[];let n=0;for(const s of e.matchAll(kp)){const o=s.index??0;o>n&&i.push({text:e.slice(n,o)}),s[1]!==void 0?i.push({text:s[1],url:s[2]}):s[3]!==void 0?i.push({text:s[3],url:s[4]}):i.push({text:wp(s[5]),url:s[5]}),n=o+s[0].length}return n<e.length&&i.push({text:e.slice(n)}),i}function Yl({text:e,convert:i,className:n="bim-rd-link"}){return t.jsx(t.Fragment,{children:vp(e).map((s,o)=>s.url?t.jsx("a",{className:n,href:s.url,target:"_blank",rel:"noopener noreferrer",children:i(s.text)},o):t.jsx(b.Fragment,{children:i(s.text)},o))})}const ws="(min-width: 1100px)",wn="(max-width: 719px)",vn="(max-width: 859px)",Sp=`${wn}, (pointer: coarse)`,Bt=r.bim("reader-top"),$p="48px",Vl=`
|
|
146
146
|
.bim-rd {
|
|
147
147
|
/* 阅读器范围的字体:宿主覆盖 --bim-font-reader-*(见 README「样式契约」),不必再写 .bim-rd 选择器 */
|
|
148
148
|
--bim-font-ui: ${r.bim("font-reader-ui")};
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
background: ${r.bim("page-bg")};
|
|
154
154
|
color: ${r.bim("ink")};
|
|
155
155
|
font-family: ${r.bim("font-ui")};
|
|
156
|
-
--bimrd-bar-h: ${
|
|
156
|
+
--bimrd-bar-h: ${$p};
|
|
157
157
|
/* 设置侧栏的暖黄:与朱/靛/墨三套主色都不冲,只做底色与选中态 */
|
|
158
158
|
--bimrd-warm: ${r.bim("reader-warm")};
|
|
159
159
|
--bimrd-warm-bg: color-mix(in srgb, var(--bimrd-warm) 8%, ${r.bim("page-bg")});
|
|
@@ -179,11 +179,11 @@
|
|
|
179
179
|
.bim-rd-mnav span { margin-right: 6px; font-variant-numeric: tabular-nums; }
|
|
180
180
|
.bim-rd-mnav button { min-width: 36px; height: 36px; border: 0; border-radius: 999px; background: transparent; color: ${r.bim("accent")}; font-size: 20px; line-height: 1; cursor: pointer; }
|
|
181
181
|
.bim-rd-mnav button:hover { background: ${r.bim("row-hover-bg")}; }
|
|
182
|
-
@media ${
|
|
182
|
+
@media ${vn} { .bim-rd-mnav { bottom: calc(68px + env(safe-area-inset-bottom, 0px)); } }
|
|
183
183
|
/* 插件浮层(ReaderPlugin.overlay)与选字浮条:桌面右下角,窄屏贴底(让开底栏) */
|
|
184
184
|
.bim-rd-overlay { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; max-width: min(420px, calc(100vw - 32px)); pointer-events: none; }
|
|
185
185
|
.bim-rd-overlay > * { pointer-events: auto; }
|
|
186
|
-
@media ${
|
|
186
|
+
@media ${vn} { .bim-rd-overlay { left: 0; right: 0; bottom: calc(68px + env(safe-area-inset-bottom, 0px)); max-width: none; align-items: stretch; padding: 0 12px; } }
|
|
187
187
|
.bim-rd-selbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid ${r.bim("rule")}; border-radius: 8px; background: ${r.bim("card-bg")}; box-shadow: ${r.bim("shadow-dialog")}; }
|
|
188
188
|
.bim-rd-selbar button { font: inherit; font-size: 13px; min-height: 36px; padding: 4px 12px; border: 1px solid ${r.bim("rule")}; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; }
|
|
189
189
|
|
|
@@ -482,7 +482,7 @@ button.bim-rd-pg:hover { border-color: ${r.bim("accent")}; }
|
|
|
482
482
|
.bim-rd-sheet-head .bim-rd-t { margin-left: auto; min-width: 44px; min-height: 44px; justify-content: center; letter-spacing: 0; }
|
|
483
483
|
.bim-rd-sheet-img { display: flex; flex-direction: column; gap: 8px; min-height: 40vh; }
|
|
484
484
|
.bim-rd-sheet-img .bim-rd-img-fig img { max-height: 60vh; }
|
|
485
|
-
@media ${
|
|
485
|
+
@media ${vn} {
|
|
486
486
|
.bim-rd[data-bb] .bim-rd-text { padding-bottom: calc(56px + 64px + env(safe-area-inset-bottom, 0px)); }
|
|
487
487
|
/* 底栏上已有的,工具条上不再重复(目录、字号) */
|
|
488
488
|
.bim-rd[data-bb] .bim-rd-bb-dup { display: none !important; }
|
|
@@ -527,7 +527,7 @@ button.bim-rd-pg:hover { border-color: ${r.bim("accent")}; }
|
|
|
527
527
|
|
|
528
528
|
/* ── 点击区 ≥44×44(INT Q4):伪元素向外扩,按钮外观与排布不变;
|
|
529
529
|
A− A+ 挨着,两边各扩约 10px 会叠在一起,所以二者之间多留 12px ── */
|
|
530
|
-
@media ${
|
|
530
|
+
@media ${Sp} {
|
|
531
531
|
.bim-rd-tools .bim-rd-t, .bim-rd-toc-head .bim-rd-t { position: relative; }
|
|
532
532
|
.bim-rd-tools .bim-rd-t::after, .bim-rd-toc-head .bim-rd-t::after {
|
|
533
533
|
content: ""; position: absolute; left: 50%; top: 50%;
|
|
@@ -540,7 +540,7 @@ button.bim-rd-pg:hover { border-color: ${r.bim("accent")}; }
|
|
|
540
540
|
}
|
|
541
541
|
|
|
542
542
|
/* ── 中屏以下:目录改抽屉 ── */
|
|
543
|
-
@media not all and ${
|
|
543
|
+
@media not all and ${ws} {
|
|
544
544
|
.bim-rd-toc {
|
|
545
545
|
position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; height: auto;
|
|
546
546
|
width: min(86vw, 320px);
|
|
@@ -554,7 +554,7 @@ button.bim-rd-pg:hover { border-color: ${r.bim("accent")}; }
|
|
|
554
554
|
}
|
|
555
555
|
|
|
556
556
|
/* ── 窄屏:书影收起,只留正文 ── */
|
|
557
|
-
@media ${
|
|
557
|
+
@media ${wn} {
|
|
558
558
|
.bim-rd-bar { padding: 0 12px; gap: 10px; }
|
|
559
559
|
.bim-rd-ttl span, .bim-rd-hide-narrow { display: none !important; }
|
|
560
560
|
/* 工具条放不下时(版本、自然段、标出作品链接都在)在条内左右滑,不撑宽页面 */
|
|
@@ -765,7 +765,7 @@ button.bim-rd-pg:hover { border-color: ${r.bim("accent")}; }
|
|
|
765
765
|
}
|
|
766
766
|
|
|
767
767
|
/* ── 手机:正文两侧不留白(放在对读、界栏规则之后才压得过它们) ── */
|
|
768
|
-
@media ${
|
|
768
|
+
@media ${wn} {
|
|
769
769
|
.bim-rd-text, .bim-rd[data-warp="true"] .bim-rd-text { padding-left: 0; padding-right: 0; }
|
|
770
770
|
.bim-rd-col, :root[data-layout="boxed"] .bim-rd-col { padding-left: 14px; padding-right: 14px; }
|
|
771
771
|
:root[data-layout="boxed"] .bim-rd-col { border-left: 0; border-right: 0; }
|
|
@@ -776,17 +776,17 @@ button.bim-rd-pg:hover { border-color: ${r.bim("accent")}; }
|
|
|
776
776
|
.guji-page-indicator { opacity: 0.55; transition: opacity 0.15s; outline: none; }
|
|
777
777
|
.guji-page-indicator:hover, .guji-page-indicator:focus-visible { opacity: 1; }
|
|
778
778
|
.guji-page-indicator:focus-visible { outline: 2px solid ${r.bim("accent")}; outline-offset: 1px; border-radius: 3px; }
|
|
779
|
-
@media ${
|
|
780
|
-
`;function ks(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(s=>ks(s,i))):!1}const na=()=>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:s}){const{t:o}=se(),a=ks(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(na,{})}),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:s===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(Dr,{items:e.children,activeKey:i,onSelect:n,tabKey:s})]}):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:s===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(na,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Dr,{items:e.children,activeKey:i,onSelect:n,tabKey:s})]})}function Dr({items:e,activeKey:i,onSelect:n,tabKey:s}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(wp,{item:o,activeKey:i,onSelect:n,tabKey:s},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:s===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 ra(e,i){var n;for(const s of e)if(s.key===i||ks(s,i))return s.key;return((n=e[0])==null?void 0:n.key)??null}function Ul({items:e,activeKey:i,onSelect:n,label:s}){const{t:o}=se(),a=s??o("reader.toc"),l=b.useRef(null),[d,c]=b.useState(null);b.useEffect(()=>{c(null)},[i]);const m=b.useMemo(()=>d||(i??ra(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===ra(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 w=y;if(h.key==="ArrowDown"?w=Math.min(g.length-1,y+1):h.key==="ArrowUp"?w=Math.max(0,y-1):h.key==="Home"?w=0:h.key==="End"&&(w=g.length-1),w<0||w===y)return;h.preventDefault();const j=g[w];for(const x of g)x.tabIndex=-1;j.tabIndex=0,j.focus(),c(j.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(Dr,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function sa({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((s,o)=>t.jsx("rect",{x:s.x,y:s.y,width:s.w,height:s.h,fill:"none",stroke:r.bim("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function vp(e){const{boxes:i,width:n,height:s}=e;if(!(i!=null&&i.length)||!n||!s||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,s)*.03,m=Math.min(n,Math.max(0,o-c)),p=Math.min(s,Math.max(0,a-c)),h=Math.min(n,Math.max(0,l+c))-m,u=Math.min(s,Math.max(0,d+c))-p;return!(h>0)||!(u>0)||h>=n*.98&&u>=s*.98?null:{x:m,y:p,w:h,h:u}}function Wr({pages:e,loading:i,page:n,onPageChange:s,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=se(),[d,c]=b.useState(0),m=n??d,p=y=>{s?s(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?vp(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(sa,{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(sa,{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 Sp(e){return e==="lite"||e==="full"}const Yi=[.1,.9],Kl=[{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 $p(e){var i;return((i=Kl.find(n=>n.key===e))==null?void 0:i.stack)??null}const ws={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!0},Yt=[15,16,17,18,20,22,24],Ur=18,Yl="bim-reader-prefs",Vl=2,_p="bim-reading-mode";function Np(){const e={...ws};try{const i=localStorage.getItem(Yl),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(_p))==="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===Vl;o&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Yi[0]&&n.pageIndicatorY<=Yi[1]&&(e.pageIndicatorY=n.pageIndicatorY),o&&(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),n.preserveMargins===!1&&(e.preserveMargins=!1)}catch{}return e}function zp(e){try{localStorage.setItem(Yl,JSON.stringify({...e,v:Vl}))}catch{}}function hn(e,i){const n=e??Ur,s=Yt;let o=s.indexOf(n);return o<0&&(o=s.indexOf(Ur)),s[Math.max(0,Math.min(s.length-1,o+i))]}function Gl(){const[e,i]=b.useState(ws);b.useEffect(()=>{i(Np())},[]);const n=b.useCallback(s=>{i(o=>{const a={...o,...s};return zp(a),a})},[]);return[e,n]}function Kr(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 ql(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 Xl(e){const i=[],n=s=>{for(const o of s){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 oa=()=>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"})}),Cp=()=>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"})}),Ep=()=>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"})}),aa=()=>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"})]}),la=()=>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 ca(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 s=n[0],o=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===s||!i.contains(a))?(e.preventDefault(),o.focus()):!e.shiftKey&&(a===o||!i.contains(a))&&(e.preventDefault(),s.focus())}function da(e,i){const[n,s]=b.useState(i);return b.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const o=window.matchMedia(e);s(o.matches);const a=()=>s(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 Rp({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=se();if(!s)return null;const a=s.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"?s.setLocale("zh-Hant"):c.key==="hans"&&s.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function vn({label:e,value:i,options:n,onPick:s,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||s(a.key)},children:a.label},a.key))})]})}function Tp({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=se(),a=(s==null?void 0:s.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(vn,{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"?s==null||s.setLocale("zh-Hant"):d==="hans"&&(s==null||s.setLocale("zh-Hans"))}})}function Ip(e,i){if(!e)return;let n;for(const s of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(s.getBoundingClientRect().top<=i+8)n=s.id;else break;return n}function Mp(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"),s=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(!s(i.anchorNode)||!s(i.focusNode))return;const o=i.toString().replace(/\s+/g," ").trim();return o?o.slice(0,500):void 0}function Jl({title:e,subtitle:i,toc:n,activeKey:s,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:w,origScriptAvailable:j=!0,byline:x,current:S,workLinkToggle:v,rail:$,onReportError:N,revisedAt:_,backHref:E,backLabel:B,bottomBar:T=!0,pager:I=!0,contentLoading:H=!1,pagerUnit:M,versions:q,currentVersionKey:O,onVersionChange:ie,versionSource:oe=!0,keepChapterOnVersionChange:le=!1,customImagePanel:ae,isWarpMode:pe,showPreserveMargins:ee=!0,pluginSettings:ge,pluginToolbar:W,pluginOverlay:ze,textRootRef:U,children:re,className:be,style:X}){const{t:L,convert:_e}=se(),P=B??L("reader.back"),K=_e(M??L("reader.unitJuan")),z=b.useId().replace(/:/g,""),V=`bim-rd-toc-${z}`,de=`bim-rd-text-${z}`,ue=b.useRef(null),He=b.useRef(null),G=b.useRef(null),me=b.useRef(null),ce=da(js,!0),Oe=da(wn,!1),Te=T&&Oe,[je,Re]=b.useState(null),[Ie,Je]=b.useState(!1),ut=b.useRef(null),Ve=`bim-rd-set-${z}`,ht=b.useRef(null),Ge=b.useRef(null),k=(F,ye)=>{Ge.current=ye,Re(qe=>qe===F?null:F)},te=b.useCallback(()=>{var F;Re(null),(F=Ge.current)==null||F.focus()},[]);b.useEffect(()=>{Te||Re(null)},[Te]),b.useEffect(()=>{var F,ye;je&&((ye=(F=ht.current)==null?void 0:F.querySelector("button:not([disabled])"))==null||ye.focus())},[je]);const[Z,he]=b.useState("auto"),Ae=Z==="auto"?ce:Z==="open",R=!ce,xe=!!ae||!!c&&c.length>0,[Y,$e]=b.useState(h);b.useEffect(()=>{$e(h)},[h]);const ke=Y==="auto"?xe||!!m:Y==="open",Ce=b.useCallback(F=>{var ye;he("auto"),F&&((ye=me.current)==null||ye.focus())},[]),Qe=()=>he(Ae?"closed":"open");b.useEffect(()=>{if(!R||Z!=="open")return;const F=G.current,ye=F==null?void 0:F.querySelector('input, [data-rd-toc-key][tabindex="0"]');ye==null||ye.focus()},[R,Z]);const Le=b.useCallback(F=>{a(F),R&&Ce(!1);const ye=He.current,qe=ue.current;if(ye&&qe&&typeof window<"u"){const Ke=ye.getBoundingClientRect().top-qe.getBoundingClientRect().bottom;Ke<0&&window.scrollBy({top:Ke})}},[a,R,Ce]),et=b.useMemo(()=>Xl(n),[n]),[yt,Be]=b.useState(null),J=ql(q,O!==void 0?O:yt),we=(J==null?void 0:J.key)??null,Xe=b.useMemo(()=>et.map(F=>F.key).join(`
|
|
781
|
-
`),[et]),Ze=b.useRef(null),De=F=>{F!==we&&(le||(Ze.current={key:F,sig:Xe,done:!1}),O===void 0&&Be(F),ie==null||ie(F))};b.useEffect(()=>{const F=Ze.current;if(!F||F.key!==we)return;const ye=et.find(Ke=>!Ke.disabled);if(!ye)return;const qe=Xe!==F.sig;!qe&&F.done||(qe?Ze.current=null:F.done=!0,ye.key!==s&&Le(ye.key))},[we,Xe,et,s,Le]);const Fe=et.find(F=>F.key===s),dt=()=>{var F;N==null||N({chapterKey:s,chapterLabel:typeof(Fe==null?void 0:Fe.label)=="string"?Fe.label:void 0,anchor:Ip(He.current,((F=ue.current)==null?void 0:F.getBoundingClientRect().bottom)??0),selectedText:Mp(He.current)})},mt=et.findIndex(F=>F.key===s),pt=mt>0?et.slice(0,mt).reverse().find(F=>!F.disabled):void 0,We=mt>=0?et.slice(mt+1).find(F=>!F.disabled):void 0,ft=u.fontSize??Ur,Q=$p(u.fontFamily),A={...X,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...Q?{"--bimrd-ff":Q}:null},ne={song:L("reader.fontSong"),kai:L("reader.fontKai"),system:L("reader.fontSystem")},ve=F=>(ge??[]).filter(ye=>ye.group===F).map(ye=>t.jsx(b.Fragment,{children:ye.node},ye.key)),Ee=ve("text"),Pe=ve("annotate"),ot=ve("layout"),at=ve("more"),Ye=[];for(const F of ge??[]){if(["text","annotate","layout","more"].includes(F.group))continue;let ye=Ye.find(qe=>qe.group===F.group);ye?ye.title==null&&(ye.title=F.title):Ye.push(ye={group:F.group,title:F.title,nodes:[]}),ye.nodes.push(t.jsx(b.Fragment,{children:F.node},F.key))}const Me=R?[W==null?void 0:W.subtitle,W==null?void 0:W.actions].filter(Boolean):[],Ne=at.length>0||Me.length>0,it=y||Pe.length>0,nt=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g1`,children:[t.jsx("h3",{id:`${Ve}-g1`,className:"bim-rd-sp-h",children:L("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":L("reader.font"),value:u.fontFamily,onChange:F=>f({fontFamily:F.target.value}),children:Kl.map(F=>t.jsx("option",{value:F.key,children:ne[F.key]},F.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:hn(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[ft,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:hn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Tp,{prefs:u,onPrefsChange:f,origAvailable:j}),t.jsx(vn,{label:L("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:L("reader.quoteModern")},{key:"classic",label:L("reader.quoteClassic")},{key:"original",label:L("reader.quoteOriginal")}],onPick:F=>f({quoteStyle:F})}),Ee]}),it&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g2`,children:[t.jsx("h3",{id:`${Ve}-g2`,className:"bim-rd-sp-h",children:L("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(vn,{label:L("reader.properName"),value:u.properNameMode,title:L("reader.properNameTitle"),options:[{key:"off",label:L("reader.properNameOff")},{key:"lite",label:L("reader.properNameLite"),title:L("reader.properNameLiteTitle")},{key:"full",label:L("reader.properNameFull")}],onPick:F=>f({properNameMode:F})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:F=>f({showWorks:F.target.checked})}),t.jsx("span",{children:L("reader.showWorks")})]}),t.jsx(vn,{label:L("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:L("reader.bookTitleWavy")},{key:"bracket",label:L("reader.bookTitleBracket")}],onPick:F=>f({bookTitleStyle:F})})]}),Pe]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g3`,children:[t.jsx("h3",{id:`${Ve}-g3`,className:"bim-rd-sp-h",children:L("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:L("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:L("reader.paragraph")}),v&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.workLinks,onChange:F=>f({workLinks:F.target.checked})}),t.jsx("span",{children:L("reader.workLinks")})]}),w&&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:L("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:F=>f({pageBreaks:F.target.checked})}),t.jsx("span",{children:L("reader.pageBreaks")})]}),ee&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:F=>f({preserveMargins:F.target.checked})}),t.jsx("span",{children:L("reader.preserveMargins")})]}),ot]}),Ye.map((F,ye)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-c${ye}`,children:[t.jsx("h3",{id:`${Ve}-c${ye}`,className:"bim-rd-sp-h",children:F.title??F.group}),F.nodes]},F.group)),Ne&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g4`,children:[t.jsx("h3",{id:`${Ve}-g4`,className:"bim-rd-sp-h",children:L("reader.groupMore")}),at,Me.map((F,ye)=>t.jsx("div",{className:"bim-rd-sp-row",children:F},`tb${ye}`))]})]}),Ue=b.useRef(null);return b.useEffect(()=>{const F=Ue.current;if(!F||!ke)return;let ye=0,qe=-1;const Ke=()=>{ye=0;const Lt=parseFloat(getComputedStyle(F).top);if(!Number.isFinite(Lt))return;const lt=Math.max(0,Math.round(F.getBoundingClientRect().top-Lt));lt!==qe&&(qe=lt,F.style.setProperty("--bimrd-img-lead",`${lt}px`))},kt=()=>{ye||(ye=requestAnimationFrame(Ke))};kt(),window.addEventListener("scroll",kt,{passive:!0}),window.addEventListener("resize",kt);const tt=typeof ResizeObserver<"u"?new ResizeObserver(kt):null;return tt==null||tt.observe(document.body),()=>{window.removeEventListener("scroll",kt),window.removeEventListener("resize",kt),tt==null||tt.disconnect(),ye&&cancelAnimationFrame(ye),F.style.removeProperty("--bimrd-img-lead")}},[ke]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&w?"bim-rd-vertical":"",be].filter(Boolean).join(" "),"data-toc":Z,"data-img":ke?"open":"closed","data-bb":Te?"":void 0,"data-set":!Te&&Ie?"open":void 0,"data-warp":pe?"true":void 0,style:A,children:[t.jsx("style",{children:Wl}),t.jsx("a",{className:"bim-rd-skip",href:`#${de}`,onClick:F=>{var ye,qe,Ke;F.preventDefault(),(ye=He.current)==null||ye.focus(),(Ke=(qe=He.current)==null?void 0:qe.scrollIntoView)==null||Ke.call(qe,{block:"start"})},children:L("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:ue,children:[E&&t.jsxs("a",{className:"bim-rd-back",href:E,"aria-label":L("reader.backAria",{label:P}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:P})]}),(e||i||x||S||!R&&(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}),S&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:S})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!R&&(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":L("reader.settings"),children:[q&&q.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:J?_e(Kr(J)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:L("reader.versionShort")}),t.jsx("select",{"aria-label":L("reader.version"),value:we??"",onChange:F=>De(F.target.value),children:q.map(F=>t.jsx("option",{value:F.key,children:_e(Kr(F))},F.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),I&&(pt||We)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":L("reader.pagerGroup",{unit:K}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.prevUnit",{unit:K}),title:pt?typeof pt.label=="string"&&pt.label?L("reader.prevUnitTitle",{unit:K,label:pt.label}):L("reader.prevUnit",{unit:K}):L("reader.firstUnit",{unit:K}),disabled:!pt,onClick:()=>pt&&Le(pt.key),children:t.jsx(Cp,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.nextUnit",{unit:K}),title:We?typeof We.label=="string"&&We.label?L("reader.nextUnitTitle",{unit:K,label:We.label}):L("reader.nextUnit",{unit:K}):L("reader.lastUnit",{unit:K}),disabled:!We,onClick:()=>We&&Le(We.key),children:t.jsx(Ep,{})})]}),I&&(pt||We)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:me,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Ae,"aria-controls":V,onClick:Qe,children:[t.jsx(oa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":ke,onClick:()=>$e(ke?"closed":"open"),children:[t.jsx(la,{}),L("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Rp,{prefs:u,onPrefsChange:f,origAvailable:j}),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":L("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:hn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":L("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:hn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:ut,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Ie,"aria-controls":Ve,onClick:()=>Je(F=>!F),children:[t.jsx(aa,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.settings")})]}),!R&&(W==null?void 0:W.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:V,ref:G,role:R&&Ae?"dialog":void 0,"aria-modal":R&&Ae?!0:void 0,"aria-label":R&&Ae?L("reader.toc"):void 0,onKeyDown:F=>{if(!(!R||!Ae)){if(F.key==="Escape"){F.stopPropagation(),Ce(!0);return}F.key==="Tab"&&ca(F,G.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??L("reader.toc")}),R&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeToc"),onClick:()=>Ce(!0),children:"✕"})]}),l]}),t.jsx(Ul,{items:n,activeKey:o!==void 0?o:s,onSelect:Le})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Ce(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":L("reader.images"),ref:Ue,children:ke&&(ae||t.jsx(Wr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!Te&&Ie&&t.jsxs("aside",{className:"bim-rd-set",id:Ve,"aria-label":L("reader.settings"),onKeyDown:F=>{var ye;F.key==="Escape"&&(F.stopPropagation(),Je(!1),(ye=ut.current)==null||ye.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:L("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeSettings"),onClick:()=>{var F;Je(!1),(F=ut.current)==null||F.focus()},children:"✕"})]}),nt]}),t.jsxs("div",{className:"bim-rd-text",id:de,ref:F=>{He.current=F,U&&(U.current=F)},tabIndex:-1,"data-rail":($||N)&&!pe?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[re,oe&&J&&(J.sourceName||J.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":J.key,children:[J.sourceName&&t.jsxs(t.Fragment,{children:[L("reader.sourceLabel")," ",J.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:J.sourceUrl,target:"_blank",rel:"noreferrer",children:_e(J.sourceName)}):_e(J.sourceName)]}),J.sourceName&&J.license&&t.jsx("span",{className:"bim-rd-dot"}),J.license&&t.jsx(t.Fragment,{children:L("reader.licenseOf",{license:J.license})})]}),_&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:L("reader.revisedAt",{date:_})}),N&&t.jsx("p",{className:"bim-rd-src bim-rd-report-foot",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:dt,children:L("reader.reportError")})}),I&&!H&&(pt||We)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":L("reader.pagerNav"),children:[pt?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Le(pt.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),L("reader.prevUnit",{unit:K})]}),t.jsx("span",{className:"bim-rd-pglabel",children:pt.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",L("reader.firstUnit",{unit:K})]}),We?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Le(We.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[L("reader.nextUnit",{unit:K}),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:[L("reader.lastUnit",{unit:K})," →"]})]})]}),($||N)&&!pe&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":L("reader.rail"),children:[$,N&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:dt,children:L("reader.reportError")})})]})]})]}),Te&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":L("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":Ae,"aria-controls":V,onClick:()=>{Re(null),Qe()},children:[t.jsx(oa,{}),t.jsx("span",{children:L("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":je==="img","aria-haspopup":"dialog",onClick:F=>k("img",F.currentTarget),children:[t.jsx(la,{}),t.jsx("span",{children:L("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":je==="set","aria-haspopup":"dialog",onClick:F=>k("set",F.currentTarget),children:[t.jsx(aa,{}),t.jsx("span",{children:L("reader.settingsShort")})]}),N&&t.jsxs("button",{type:"button",onMouseDown:F=>F.preventDefault(),onClick:()=>{Re(null),dt()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:L("reader.reportError")})]})]}),Te&&je&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:te}),t.jsxs("div",{className:"bim-rd-sheet",ref:ht,role:"dialog","aria-modal":"true","aria-label":L(je==="img"?"reader.images":"reader.settings"),onKeyDown:F=>{if(F.key==="Escape"){F.stopPropagation(),te();return}F.key==="Tab"&&ca(F,ht.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:L(je==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.close"),onClick:te,children:"✕"})]}),je==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Wr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):nt]})]}),ze&&t.jsx("div",{className:"bim-rd-overlay",children:ze})]})}function Ap(e,i,n){return n?Zl(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function Zl(e){return e.replace(/\r\n/g,`
|
|
782
|
-
`)}const
|
|
783
|
-
`)return-1;if(o==="\\"){s++;continue}if(o==="[")n++;else if(o==="]"&&(n--,n===0))return s}return-1}function
|
|
784
|
-
`)<0?{node:{type:"qw",label:e.slice(i+2,s)},end:s+2}:null}if(n===":"&&e.startsWith(":zi[",i)){const s=
|
|
785
|
-
`)return null}const p=
|
|
786
|
-
.bim-d-main.bim-d-main-grid { max-width: ${
|
|
779
|
+
@media ${wn} { .guji-page-indicator { display: none; } }
|
|
780
|
+
`;function vs(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(s=>vs(s,i))):!1}const sa=()=>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 _p({item:e,activeKey:i,onSelect:n,tabKey:s}){const{t:o}=se(),a=vs(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(sa,{})}),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:s===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(Ur,{items:e.children,activeKey:i,onSelect:n,tabKey:s})]}):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:s===e.key?0:-1,onClick:()=>d(c=>!c),children:[t.jsx(sa,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Ur,{items:e.children,activeKey:i,onSelect:n,tabKey:s})]})}function Ur({items:e,activeKey:i,onSelect:n,tabKey:s}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(_p,{item:o,activeKey:i,onSelect:n,tabKey:s},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:s===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 oa(e,i){var n;for(const s of e)if(s.key===i||vs(s,i))return s.key;return((n=e[0])==null?void 0:n.key)??null}function Gl({items:e,activeKey:i,onSelect:n,label:s}){const{t:o}=se(),a=s??o("reader.toc"),l=b.useRef(null),[d,c]=b.useState(null);b.useEffect(()=>{c(null)},[i]);const m=b.useMemo(()=>d||(i??oa(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===oa(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 w=y;if(h.key==="ArrowDown"?w=Math.min(g.length-1,y+1):h.key==="ArrowUp"?w=Math.max(0,y-1):h.key==="Home"?w=0:h.key==="End"&&(w=g.length-1),w<0||w===y)return;h.preventDefault();const j=g[w];for(const x of g)x.tabIndex=-1;j.tabIndex=0,j.focus(),c(j.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(Ur,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function aa({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((s,o)=>t.jsx("rect",{x:s.x,y:s.y,width:s.w,height:s.h,fill:"none",stroke:r.bim("accent"),strokeOpacity:.55,vectorEffect:"non-scaling-stroke",strokeWidth:1},o))})}function Np(e){const{boxes:i,width:n,height:s}=e;if(!(i!=null&&i.length)||!n||!s||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,s)*.03,m=Math.min(n,Math.max(0,o-c)),p=Math.min(s,Math.max(0,a-c)),h=Math.min(n,Math.max(0,l+c))-m,u=Math.min(s,Math.max(0,d+c))-p;return!(h>0)||!(u>0)||h>=n*.98&&u>=s*.98?null:{x:m,y:p,w:h,h:u}}function Kr({pages:e,loading:i,page:n,onPageChange:s,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=se(),[d,c]=b.useState(0),m=n??d,p=y=>{s?s(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?Np(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(aa,{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(aa,{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 zp(e){return e==="lite"||e==="full"}const Yi=[.1,.9],ql=[{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 Cp(e){var i;return((i=ql.find(n=>n.key===e))==null?void 0:i.stack)??null}const Ss={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!0},Yt=[15,16,17,18,20,22,24],Yr=18,Xl="bim-reader-prefs",Jl=2,Ep="bim-reading-mode";function Rp(){const e={...Ss};try{const i=localStorage.getItem(Xl),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(Ep))==="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===Jl;o&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Yi[0]&&n.pageIndicatorY<=Yi[1]&&(e.pageIndicatorY=n.pageIndicatorY),o&&(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),n.preserveMargins===!1&&(e.preserveMargins=!1)}catch{}return e}function Tp(e){try{localStorage.setItem(Xl,JSON.stringify({...e,v:Jl}))}catch{}}function hn(e,i){const n=e??Yr,s=Yt;let o=s.indexOf(n);return o<0&&(o=s.indexOf(Yr)),s[Math.max(0,Math.min(s.length-1,o+i))]}function Zl(){const[e,i]=b.useState(Ss);b.useEffect(()=>{i(Rp())},[]);const n=b.useCallback(s=>{i(o=>{const a={...o,...s};return Tp(a),a})},[]);return[e,n]}function Vr(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 Ql(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 ec(e){const i=[],n=s=>{for(const o of s){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 la=()=>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"})}),Ip=()=>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"})}),Mp=()=>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"})}),ca=()=>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"})]}),da=()=>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 ma(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 s=n[0],o=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===s||!i.contains(a))?(e.preventDefault(),o.focus()):!e.shiftKey&&(a===o||!i.contains(a))&&(e.preventDefault(),s.focus())}function ua(e,i){const[n,s]=b.useState(i);return b.useEffect(()=>{var l;if(typeof window>"u"||!window.matchMedia)return;const o=window.matchMedia(e);s(o.matches);const a=()=>s(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 Ap({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=se();if(!s)return null;const a=s.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"?s.setLocale("zh-Hant"):c.key==="hans"&&s.setLocale("zh-Hans"))},children:c.short})]},c.key))})}function Sn({label:e,value:i,options:n,onPick:s,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||s(a.key)},children:a.label},a.key))})]})}function Lp({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=se(),a=(s==null?void 0:s.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(Sn,{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"?s==null||s.setLocale("zh-Hant"):d==="hans"&&(s==null||s.setLocale("zh-Hans"))}})}function Pp(e,i){if(!e)return;let n;for(const s of Array.from(e.querySelectorAll('[id^="rd-e-"]')))if(s.getBoundingClientRect().top<=i+8)n=s.id;else break;return n}function Op(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"),s=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(!s(i.anchorNode)||!s(i.focusNode))return;const o=i.toString().replace(/\s+/g," ").trim();return o?o.slice(0,500):void 0}function tc({title:e,subtitle:i,toc:n,activeKey:s,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:w,origScriptAvailable:j=!0,byline:x,current:v,workLinkToggle:S,rail:$,onReportError:N,revisedAt:z,backHref:R,backLabel:O,bottomBar:C=!0,pager:I=!0,contentLoading:D=!1,pagerUnit:A,versions:X,currentVersionKey:B,onVersionChange:ae,versionSource:te=!0,keepChapterOnVersionChange:ce=!1,customImagePanel:be,isWarpMode:oe,showPreserveMargins:K=!0,pluginSettings:ze,pluginToolbar:F,pluginOverlay:me,textRootRef:U,children:ne,className:ue,style:G}){const{t:L,convert:Se}=se(),ge=O??L("reader.back"),$e=Se(A??L("reader.unitJuan")),_=b.useId().replace(/:/g,""),P=`bim-rd-toc-${_}`,ie=`bim-rd-text-${_}`,re=b.useRef(null),Re=b.useRef(null),Y=b.useRef(null),de=b.useRef(null),le=ua(ws,!0),Te=ua(vn,!1),_e=C&&Te,[xe,Ce]=b.useState(null),[Ae,Je]=b.useState(!1),ut=b.useRef(null),Ve=`bim-rd-set-${_}`,ht=b.useRef(null),Ge=b.useRef(null),k=(H,ye)=>{Ge.current=ye,Ce(qe=>qe===H?null:H)},Q=b.useCallback(()=>{var H;Ce(null),(H=Ge.current)==null||H.focus()},[]);b.useEffect(()=>{_e||Ce(null)},[_e]),b.useEffect(()=>{var H,ye;xe&&((ye=(H=ht.current)==null?void 0:H.querySelector("button:not([disabled])"))==null||ye.focus())},[xe]);const[J,pe]=b.useState("auto"),Pe=J==="auto"?le:J==="open",T=!le,fe=!!be||!!c&&c.length>0,[V,Ne]=b.useState(h);b.useEffect(()=>{Ne(h)},[h]);const je=V==="auto"?fe||!!m:V==="open",Ie=b.useCallback(H=>{var ye;pe("auto"),H&&((ye=de.current)==null||ye.focus())},[]),Qe=()=>pe(Pe?"closed":"open");b.useEffect(()=>{if(!T||J!=="open")return;const H=Y.current,ye=H==null?void 0:H.querySelector('input, [data-rd-toc-key][tabindex="0"]');ye==null||ye.focus()},[T,J]);const Oe=b.useCallback(H=>{a(H),T&&Ie(!1);const ye=Re.current,qe=re.current;if(ye&&qe&&typeof window<"u"){const Ke=ye.getBoundingClientRect().top-qe.getBoundingClientRect().bottom;Ke<0&&window.scrollBy({top:Ke})}},[a,T,Ie]),et=b.useMemo(()=>ec(n),[n]),[yt,He]=b.useState(null),q=Ql(X,B!==void 0?B:yt),ke=(q==null?void 0:q.key)??null,Xe=b.useMemo(()=>et.map(H=>H.key).join(`
|
|
781
|
+
`),[et]),Ze=b.useRef(null),De=H=>{H!==ke&&(ce||(Ze.current={key:H,sig:Xe,done:!1}),B===void 0&&He(H),ae==null||ae(H))};b.useEffect(()=>{const H=Ze.current;if(!H||H.key!==ke)return;const ye=et.find(Ke=>!Ke.disabled);if(!ye)return;const qe=Xe!==H.sig;!qe&&H.done||(qe?Ze.current=null:H.done=!0,ye.key!==s&&Oe(ye.key))},[ke,Xe,et,s,Oe]);const Be=et.find(H=>H.key===s),dt=()=>{var H;N==null||N({chapterKey:s,chapterLabel:typeof(Be==null?void 0:Be.label)=="string"?Be.label:void 0,anchor:Pp(Re.current,((H=re.current)==null?void 0:H.getBoundingClientRect().bottom)??0),selectedText:Op(Re.current)})},mt=et.findIndex(H=>H.key===s),pt=mt>0?et.slice(0,mt).reverse().find(H=>!H.disabled):void 0,We=mt>=0?et.slice(mt+1).find(H=>!H.disabled):void 0,ft=u.fontSize??Yr,Z=Cp(u.fontFamily),M={...G,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...Z?{"--bimrd-ff":Z}:null},ee={song:L("reader.fontSong"),kai:L("reader.fontKai"),system:L("reader.fontSystem")},we=H=>(ze??[]).filter(ye=>ye.group===H).map(ye=>t.jsx(b.Fragment,{children:ye.node},ye.key)),Me=we("text"),Fe=we("annotate"),ot=we("layout"),at=we("more"),Ye=[];for(const H of ze??[]){if(["text","annotate","layout","more"].includes(H.group))continue;let ye=Ye.find(qe=>qe.group===H.group);ye?ye.title==null&&(ye.title=H.title):Ye.push(ye={group:H.group,title:H.title,nodes:[]}),ye.nodes.push(t.jsx(b.Fragment,{children:H.node},H.key))}const Le=T?[F==null?void 0:F.subtitle,F==null?void 0:F.actions].filter(Boolean):[],Ee=at.length>0||Le.length>0,it=y||Fe.length>0,nt=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g1`,children:[t.jsx("h3",{id:`${Ve}-g1`,className:"bim-rd-sp-h",children:L("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":L("reader.font"),value:u.fontFamily,onChange:H=>f({fontFamily:H.target.value}),children:ql.map(H=>t.jsx("option",{value:H.key,children:ee[H.key]},H.key))})]}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:L("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:hn(u.fontSize,-1)}),children:"A−"}),t.jsxs("output",{"aria-live":"polite",children:[ft,"px"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:hn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Lp,{prefs:u,onPrefsChange:f,origAvailable:j}),t.jsx(Sn,{label:L("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:L("reader.quoteModern")},{key:"classic",label:L("reader.quoteClassic")},{key:"original",label:L("reader.quoteOriginal")}],onPick:H=>f({quoteStyle:H})}),Me]}),it&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g2`,children:[t.jsx("h3",{id:`${Ve}-g2`,className:"bim-rd-sp-h",children:L("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Sn,{label:L("reader.properName"),value:u.properNameMode,title:L("reader.properNameTitle"),options:[{key:"off",label:L("reader.properNameOff")},{key:"lite",label:L("reader.properNameLite"),title:L("reader.properNameLiteTitle")},{key:"full",label:L("reader.properNameFull")}],onPick:H=>f({properNameMode:H})}),t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.showWorks,onChange:H=>f({showWorks:H.target.checked})}),t.jsx("span",{children:L("reader.showWorks")})]}),t.jsx(Sn,{label:L("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:L("reader.bookTitleWavy")},{key:"bracket",label:L("reader.bookTitleBracket")}],onPick:H=>f({bookTitleStyle:H})})]}),Fe]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g3`,children:[t.jsx("h3",{id:`${Ve}-g3`,className:"bim-rd-sp-h",children:L("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:L("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:L("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:H=>f({workLinks:H.target.checked})}),t.jsx("span",{children:L("reader.workLinks")})]}),w&&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:L("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:H=>f({pageBreaks:H.target.checked})}),t.jsx("span",{children:L("reader.pageBreaks")})]}),K&&t.jsxs("label",{className:"bim-rd-t bim-rd-chk bim-rd-sp-tg",children:[t.jsx("input",{type:"checkbox",checked:u.preserveMargins,onChange:H=>f({preserveMargins:H.target.checked})}),t.jsx("span",{children:L("reader.preserveMargins")})]}),ot]}),Ye.map((H,ye)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-c${ye}`,children:[t.jsx("h3",{id:`${Ve}-c${ye}`,className:"bim-rd-sp-h",children:H.title??H.group}),H.nodes]},H.group)),Ee&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Ve}-g4`,children:[t.jsx("h3",{id:`${Ve}-g4`,className:"bim-rd-sp-h",children:L("reader.groupMore")}),at,Le.map((H,ye)=>t.jsx("div",{className:"bim-rd-sp-row",children:H},`tb${ye}`))]})]}),Ue=b.useRef(null);return b.useEffect(()=>{const H=Ue.current;if(!H||!je)return;let ye=0,qe=-1;const Ke=()=>{ye=0;const Lt=parseFloat(getComputedStyle(H).top);if(!Number.isFinite(Lt))return;const lt=Math.max(0,Math.round(H.getBoundingClientRect().top-Lt));lt!==qe&&(qe=lt,H.style.setProperty("--bimrd-img-lead",`${lt}px`))},kt=()=>{ye||(ye=requestAnimationFrame(Ke))};kt(),window.addEventListener("scroll",kt,{passive:!0}),window.addEventListener("resize",kt);const tt=typeof ResizeObserver<"u"?new ResizeObserver(kt):null;return tt==null||tt.observe(document.body),()=>{window.removeEventListener("scroll",kt),window.removeEventListener("resize",kt),tt==null||tt.disconnect(),ye&&cancelAnimationFrame(ye),H.style.removeProperty("--bimrd-img-lead")}},[je]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&w?"bim-rd-vertical":"",ue].filter(Boolean).join(" "),"data-toc":J,"data-img":je?"open":"closed","data-bb":_e?"":void 0,"data-set":!_e&&Ae?"open":void 0,"data-warp":oe?"true":void 0,style:M,children:[t.jsx("style",{children:Vl}),t.jsx("a",{className:"bim-rd-skip",href:`#${ie}`,onClick:H=>{var ye,qe,Ke;H.preventDefault(),(ye=Re.current)==null||ye.focus(),(Ke=(qe=Re.current)==null?void 0:qe.scrollIntoView)==null||Ke.call(qe,{block:"start"})},children:L("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:re,children:[R&&t.jsxs("a",{className:"bim-rd-back",href:R,"aria-label":L("reader.backAria",{label:ge}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:ge})]}),(e||i||x||v||!T&&(F==null?void 0:F.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}),v&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:v})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!T&&(F==null?void 0:F.subtitle)&&t.jsx("span",{className:"bim-rd-ttl-src",children:F.subtitle})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":L("reader.settings"),children:[X&&X.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:q?Se(Vr(q)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:L("reader.versionShort")}),t.jsx("select",{"aria-label":L("reader.version"),value:ke??"",onChange:H=>De(H.target.value),children:X.map(H=>t.jsx("option",{value:H.key,children:Se(Vr(H))},H.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),I&&(pt||We)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":L("reader.pagerGroup",{unit:$e}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.prevUnit",{unit:$e}),title:pt?typeof pt.label=="string"&&pt.label?L("reader.prevUnitTitle",{unit:$e,label:pt.label}):L("reader.prevUnit",{unit:$e}):L("reader.firstUnit",{unit:$e}),disabled:!pt,onClick:()=>pt&&Oe(pt.key),children:t.jsx(Ip,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.nextUnit",{unit:$e}),title:We?typeof We.label=="string"&&We.label?L("reader.nextUnitTitle",{unit:$e,label:We.label}):L("reader.nextUnit",{unit:$e}):L("reader.lastUnit",{unit:$e}),disabled:!We,onClick:()=>We&&Oe(We.key),children:t.jsx(Mp,{})})]}),I&&(pt||We)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:de,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Pe,"aria-controls":P,onClick:Qe,children:[t.jsx(la,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":je,onClick:()=>Ne(je?"closed":"open"),children:[t.jsx(da,{}),L("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Ap,{prefs:u,onPrefsChange:f,origAvailable:j}),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":L("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:hn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":L("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:hn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:ut,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Ae,"aria-controls":Ve,onClick:()=>Je(H=>!H),children:[t.jsx(ca,{}),t.jsx("span",{className:"bim-rd-tlabel",children:L("reader.settings")})]}),!T&&(F==null?void 0:F.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:P,ref:Y,role:T&&Pe?"dialog":void 0,"aria-modal":T&&Pe?!0:void 0,"aria-label":T&&Pe?L("reader.toc"):void 0,onKeyDown:H=>{if(!(!T||!Pe)){if(H.key==="Escape"){H.stopPropagation(),Ie(!0);return}H.key==="Tab"&&ma(H,Y.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??L("reader.toc")}),T&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeToc"),onClick:()=>Ie(!0),children:"✕"})]}),l]}),t.jsx(Gl,{items:n,activeKey:o!==void 0?o:s,onSelect:Oe})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Ie(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":L("reader.images"),ref:Ue,children:je&&(be||t.jsx(Kr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!_e&&Ae&&t.jsxs("aside",{className:"bim-rd-set",id:Ve,"aria-label":L("reader.settings"),onKeyDown:H=>{var ye;H.key==="Escape"&&(H.stopPropagation(),Je(!1),(ye=ut.current)==null||ye.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:L("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.closeSettings"),onClick:()=>{var H;Je(!1),(H=ut.current)==null||H.focus()},children:"✕"})]}),nt]}),t.jsxs("div",{className:"bim-rd-text",id:ie,ref:H=>{Re.current=H,U&&(U.current=H)},tabIndex:-1,"data-rail":($||N)&&!oe?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[ne,te&&q&&(q.sourceName||q.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":q.key,children:[q.sourceName&&t.jsxs(t.Fragment,{children:[L("reader.sourceLabel")," ",q.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:q.sourceUrl,target:"_blank",rel:"noreferrer",children:Se(q.sourceName)}):Se(q.sourceName)]}),q.sourceName&&q.license&&t.jsx("span",{className:"bim-rd-dot"}),q.license&&t.jsx(t.Fragment,{children:L("reader.licenseOf",{license:q.license})})]}),z&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:L("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:H=>H.preventDefault(),onClick:dt,children:L("reader.reportError")})}),I&&!D&&(pt||We)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":L("reader.pagerNav"),children:[pt?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Oe(pt.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),L("reader.prevUnit",{unit:$e})]}),t.jsx("span",{className:"bim-rd-pglabel",children:pt.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",L("reader.firstUnit",{unit:$e})]}),We?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Oe(We.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[L("reader.nextUnit",{unit:$e}),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:[L("reader.lastUnit",{unit:$e})," →"]})]})]}),($||N)&&!oe&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":L("reader.rail"),children:[$,N&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:H=>H.preventDefault(),onClick:dt,children:L("reader.reportError")})})]})]})]}),_e&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":L("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":Pe,"aria-controls":P,onClick:()=>{Ce(null),Qe()},children:[t.jsx(la,{}),t.jsx("span",{children:L("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":xe==="img","aria-haspopup":"dialog",onClick:H=>k("img",H.currentTarget),children:[t.jsx(da,{}),t.jsx("span",{children:L("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":xe==="set","aria-haspopup":"dialog",onClick:H=>k("set",H.currentTarget),children:[t.jsx(ca,{}),t.jsx("span",{children:L("reader.settingsShort")})]}),N&&t.jsxs("button",{type:"button",onMouseDown:H=>H.preventDefault(),onClick:()=>{Ce(null),dt()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:L("reader.reportError")})]})]}),_e&&xe&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:Q}),t.jsxs("div",{className:"bim-rd-sheet",ref:ht,role:"dialog","aria-modal":"true","aria-label":L(xe==="img"?"reader.images":"reader.settings"),onKeyDown:H=>{if(H.key==="Escape"){H.stopPropagation(),Q();return}H.key==="Tab"&&ma(H,ht.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:L(xe==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":L("reader.close"),onClick:Q,children:"✕"})]}),xe==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Kr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):nt]})]}),me&&t.jsx("div",{className:"bim-rd-overlay",children:me})]})}function Fp(e,i,n){return n?ic(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function ic(e){return e.replace(/\r\n/g,`
|
|
782
|
+
`)}const pa=2,Bp=400,Hp=6,nc=e=>e==="*"||e==="#"||e==="<"||e===">"||/\s/.test(e);function rc(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 Dp(e,i,n){let s=i;for(let o=0;o<n.length;){if(s>=e.length)return-1;if(n[o]===e[s]){o++,s++;continue}const a=rc(e,s);if(a>=0){s=a+1;continue}if(nc(e[s])){s++;continue}if(n[o]===" "){o++;continue}return-1}return s}function Wp(e){const i=Array.from(ic(e));let n=0;return{align(s){if(!s)return;const o=Array.from(s);if(o.every(d=>d===" "||/\s/.test(d)))return;const a=o.length>=Hp;let l=0;for(let d=n;d<i.length&&d-n<=(a?Bp:pa+64);d++){const c=rc(i,d);if(c>=0){d=c;continue}if(!nc(i[d])){const p=Dp(i,d,o);if(p>=0)return n=p,d;if(l++,!a&&l>pa)return}}}}}const Up=65536,Kp="guji_markdown";function Yp(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 s=parseInt(n[1],10),o=parseInt(n[2],10);return s>0||o>=2}const Vp=/^□\{guess=([^\s{}]+)\}/;function Gp(e,i){const n=e[i+1];return n!==void 0&&!/[A-Za-z/!?>\s]/.test(n)}function sc(e,i){let n=0;for(let s=i;s<e.length;s++){const o=e[s];if(o===`
|
|
783
|
+
`)return-1;if(o==="\\"){s++;continue}if(o==="[")n++;else if(o==="]"&&(n--,n===0))return s}return-1}function qp(e){return e.replace(/\\([\\[\]<>|{}])/g,"$1")}function Xp(e,i){const n=e[i];if(n==="["&&e[i+1]==="["){const s=e.indexOf("]]",i+2);return s>=0&&e.slice(i+2,s).indexOf(`
|
|
784
|
+
`)<0?{node:{type:"qw",label:e.slice(i+2,s)},end:s+2}:null}if(n===":"&&e.startsWith(":zi[",i)){const s=sc(e,i+3);return s>i+4?{node:{type:"zi",label:qp(e.slice(i+4,s))},end:s+1}:null}if(n==="□"&&e[i+1]==="{"){const s=Vp.exec(e.slice(i,i+64));if(s)return{node:{type:"qz",guess:s[1]},end:i+s[0].length}}return null}function oc(e,i,n,s,o){const a=[];let l="",d=!1;const c=()=>{if(!l)return;let m=l;s&&(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===`
|
|
785
|
+
`)return null}const p=Xp(e,i);if(p){c(),a.push(p.node),i=p.end;continue}let h=null;if(m==="<"&&Gp(e,i)&&(h=">"),h){const u=oc(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 ac(e,i){return oc(e,0,null,!1,(i==null?void 0:i.jzMaxLength)??Up).nodes}function Jp(e){return/[<□]|\[\[|:zi\[/.test(e)}function lc(e){return e.map(i=>{switch(i.type){case"text":return i.text;case"jz":return`(${lc(i.children)})`;case"qw":return"□";case"qz":return"□";case"zi":return i.label}}).join("")}const Zp=216,ba="clamp(280px, 23vw, 360px)",Qp=1440,Gr="(max-width: 719px)",eb=`${Gr}, (pointer: coarse)`,tb=`
|
|
786
|
+
.bim-d-main.bim-d-main-grid { max-width: ${Qp}px; padding: 16px 32px 0; }
|
|
787
787
|
.bim-d-grid {
|
|
788
788
|
display: grid;
|
|
789
|
-
grid-template-columns: ${
|
|
789
|
+
grid-template-columns: ${Zp}px minmax(0, 1fr) ${ba};
|
|
790
790
|
grid-template-rows: auto 1fr;
|
|
791
791
|
grid-template-areas: "rail main card" "rail main side";
|
|
792
792
|
column-gap: 32px; row-gap: 28px; align-items: start;
|
|
@@ -1164,7 +1164,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1164
1164
|
.bim-d-side li .bim-d-meta { font-size: 12px; flex: none; }
|
|
1165
1165
|
|
|
1166
1166
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
1167
|
-
@media ${
|
|
1167
|
+
@media ${eb} {
|
|
1168
1168
|
.bim-d-tab, .bim-d-check, .bim-d-more, .bim-d-rail-back,
|
|
1169
1169
|
.bim-d-card-foot summary, .bim-d-card-toggle, .bim-d-card details.bim-d-more-names summary,
|
|
1170
1170
|
.bim-d-tl summary, .bim-d-chap a { min-height: 44px; }
|
|
@@ -1202,7 +1202,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1202
1202
|
/* 中等宽度:左栏折到顶部一行 */
|
|
1203
1203
|
@media (max-width: 1100px) {
|
|
1204
1204
|
.bim-d-grid {
|
|
1205
|
-
grid-template-columns: minmax(0, 1fr) ${
|
|
1205
|
+
grid-template-columns: minmax(0, 1fr) ${ba};
|
|
1206
1206
|
grid-template-rows: auto auto 1fr;
|
|
1207
1207
|
grid-template-areas: "rail rail" "main card" "main side";
|
|
1208
1208
|
}
|
|
@@ -1216,7 +1216,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1216
1216
|
}
|
|
1217
1217
|
|
|
1218
1218
|
/* 手机:左栏收起,提要卡 → 正文 → 旁栏 */
|
|
1219
|
-
@media ${
|
|
1219
|
+
@media ${Gr} {
|
|
1220
1220
|
.bim-d-main.bim-d-main-grid { padding: 8px 16px 0; }
|
|
1221
1221
|
.bim-d-grid {
|
|
1222
1222
|
grid-template-columns: minmax(0, 1fr);
|
|
@@ -1291,7 +1291,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1291
1291
|
:root[data-layout="boxed"] .bim-d-g-rail { border: ${r.bim("fr-bd")}; background: ${r.bim("fr-bg")}; padding: 14px 8px; }
|
|
1292
1292
|
:root[data-layout="boxed"] .bim-d-filters { border-bottom: 1px solid ${r.bim("fr-tab-bd")}; }
|
|
1293
1293
|
:root[data-layout="boxed"] .bim-d-filters .bim-d-tab { margin-bottom: -1px; }
|
|
1294
|
-
@media ${
|
|
1294
|
+
@media ${Gr} {
|
|
1295
1295
|
:root[data-layout="boxed"] .bim-d-card { padding: 16px; }
|
|
1296
1296
|
:root[data-layout="boxed"] .bim-d-g-rail { border: 0; background: transparent; padding: 0; }
|
|
1297
1297
|
}
|
|
@@ -1306,7 +1306,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1306
1306
|
: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 {
|
|
1307
1307
|
text-decoration-color: currentColor; text-decoration-thickness: 2px;
|
|
1308
1308
|
}
|
|
1309
|
-
`;function Xi({railTop:e,back:i,up:n,nav:s,railLinks:o,main:a,card:l,side:d}){const{t:c,convert:m}=se(),p=(s||[]).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
|
|
1309
|
+
`;function Xi({railTop:e,back:i,up:n,nav:s,railLinks:o,main:a,card:l,side:d}){const{t:c,convert:m}=se(),p=(s||[]).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 cc({caption:e,children:i}){const{convert:n}=se();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 $t({id:e,title:i,meta:n,action:s,children:o}){const{convert:a}=se();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}),s&&t.jsx("span",{className:"bim-d-sec-act",children:s})]}),t.jsx("div",{className:"bim-d-sec-body",children:o})]})}function vt({items:e,className:i,style:n}){const s=e.filter(o=>o!=null&&o!==""&&o!==!1);return s.length?t.jsx("span",{className:`bim-d-meta${i?` ${i}`:""}`,style:n,children:s.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 Gn({items:e,value:i,onChange:n}){const{convert:s}=se();return t.jsx(t.Fragment,{children:e.map(o=>t.jsx("button",{type:"button",className:[...s(o.label)].length===1?"bim-d-tab bim-d-tab-1":"bim-d-tab","aria-pressed":o.key===i,onClick:()=>n(o.key),children:s(o.label)},o.key))})}function dc({label:e,checked:i,onChange:n}){const{convert:s}=se();return t.jsxs("label",{className:"bim-d-check",children:[t.jsx("input",{type:"checkbox",checked:i,onChange:o=>n(o.target.checked)}),s(e)]})}const mc=6,qn=e=>e>mc+1;function $s({total:e,shown:i,unit:n,onClick:s}){const{t:o,convert:a}=se(),l=e-i,d=qn(e)?e-Math.min(i,mc):l;return d<=0?null:t.jsxs("button",{type:"button",className:`bim-d-more bim-d-ui${l>0?"":" bim-d-more-ncap"}`,onClick:s,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 _s({label:e,onClick:i}){const{convert:n}=se();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:i,children:n(e)})}function Ji({kind:e,title:i,subtitle:n,byline:s,meta:o,description:a,clampDescription:l,facts:d,stats:c,readAction:m,secondaryAction:p,children:h,foot:u}){const{t:f,convert:g}=se(),y=(d||[]).filter(S=>S.value!=null&&S.value!==""),w=(c||[]).filter(S=>S.value!=null&&S.value!==""&&S.value!==0),[j,x]=b.useState(!1),v=!!l&&!j;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}),s&&t.jsx("p",{className:"bim-d-card-byline",style:{marginBottom:0},children:s}),o&&t.jsx("div",{className:"bim-d-card-cls bim-d-ui",children:o}),a&&t.jsx("div",{className:v?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:v?{"--detail-clamp":l}:void 0,children:a}),a&&!!l&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":j,onClick:()=>x(S=>!S),children:f(j?"action.collapse":"action.expand")}),w.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:w.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 Ns(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function qr({href:e,onClick:i,label:n}){const{t:s,convert:o}=se(),a=n??s("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 di({id:e,title:i,meta:n,items:s,metas:o,currentIndex:a,cap:l=8,moreLabel:d,foot:c,sub:m,timeline:p}){const{t:h,convert:u}=se(),[f,g]=b.useState(!1);if(!s.length)return null;const y=f?s:s.slice(0,l),w=s.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((j,x)=>t.jsxs("li",{className:x===a?"bim-d-side-cur":void 0,"aria-current":x===a?"page":void 0,children:[j,o!=null&&o[x]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:o[x]}):null]},x))}),w>0&&t.jsx(_s,{label:d?d(w):h("detail.showMore",{n:w}),onClick:()=>g(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const ib=new Set(["reviewed","disputed","unreviewed","draft"]);function Zi({revision:e,revisedAt:i,review:n,todo:s}){const{t:o,convert:a}=se(),l=n&&ib.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=(s||[]).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 $n=1e3,ha=208,nb=1440,rb="(max-width: 719px)",uc=`
|
|
1310
1310
|
.bim-d-page {
|
|
1311
1311
|
background: ${r.bim("page-bg")};
|
|
1312
1312
|
color: ${r.bim("ink")};
|
|
@@ -1315,7 +1315,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1315
1315
|
padding-bottom: 64px;
|
|
1316
1316
|
}
|
|
1317
1317
|
.bim-d-main {
|
|
1318
|
-
max-width: ${
|
|
1318
|
+
max-width: ${$n}px;
|
|
1319
1319
|
margin: 0 auto;
|
|
1320
1320
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
1321
1321
|
}
|
|
@@ -1326,7 +1326,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1326
1326
|
* PAGE_MAX_WIDTH,读者的行宽体验不变。
|
|
1327
1327
|
*/
|
|
1328
1328
|
.bim-d-main.bim-d-main-wide {
|
|
1329
|
-
max-width: ${
|
|
1329
|
+
max-width: ${nb}px;
|
|
1330
1330
|
}
|
|
1331
1331
|
.bim-d-ui { font-family: var(--bim-font-ui, system-ui, sans-serif); }
|
|
1332
1332
|
|
|
@@ -1358,9 +1358,9 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1358
1358
|
*/
|
|
1359
1359
|
.bim-d-reader {
|
|
1360
1360
|
display: grid;
|
|
1361
|
-
grid-template-columns: ${
|
|
1361
|
+
grid-template-columns: ${ha}px minmax(0, ${$n}px);
|
|
1362
1362
|
gap: 32px;
|
|
1363
|
-
max-width: ${
|
|
1363
|
+
max-width: ${ha+$n+32}px;
|
|
1364
1364
|
margin: 0 auto;
|
|
1365
1365
|
align-items: start;
|
|
1366
1366
|
}
|
|
@@ -1383,7 +1383,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1383
1383
|
align-items: start; margin-bottom: 48px; }
|
|
1384
1384
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
1385
1385
|
|
|
1386
|
-
@media ${
|
|
1386
|
+
@media ${rb} {
|
|
1387
1387
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
1388
1388
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
1389
1389
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -1401,26 +1401,26 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1401
1401
|
padding-right: 0; padding-bottom: 12px;
|
|
1402
1402
|
}
|
|
1403
1403
|
}
|
|
1404
|
-
${
|
|
1405
|
-
`)||(i.push({start:n,end:l+1,inner:d}),n=l)}return i}function
|
|
1404
|
+
${tb}`;function Fi({children:e,style:i,wide:n,grid:s}){return t.jsxs("div",{className:"bim-d-page",style:i,children:[t.jsx("style",{children:uc}),t.jsx("div",{className:s?"bim-d-main bim-d-main-grid":n?"bim-d-main bim-d-main-wide":"bim-d-main",children:e})]})}function Xr({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:r.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 zs({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"?r.bim("accent"):r.bim("ink"),color:r.bim("page-bg")},children:e})}function Jr({items:e}){const i=Tt();return t.jsx(t.Fragment,{children:e.map((n,s)=>{const o=s===e.length-1,a=s>0&&t.jsx("span",{style:{color:r.bim("hint-fg")},children:"/"},`s${s}`),l=n.id?i(n.id):n.href,d=o||!n.onClick&&!l?t.jsx("span",{style:{color:r.bim("ink")},children:n.label},s):t.jsx("a",{href:l??"#",onClick:n.onClick?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),n.onClick())}:void 0,style:{color:r.bim("meta-fg")},children:n.label},s);return t.jsxs(b.Fragment,{children:[a,d]},s)})})}function pc({title:e,subtitle:i,aside:n,secondLine:s}){return t.jsxs("header",{style:{borderBottom:`2px solid ${r.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:r.bim("meta-fg"),letterSpacing:".06em"},children:i})]}),n&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r.bim("label-fg"),letterSpacing:".06em"},children:n})]}),s&&t.jsx("div",{style:{marginTop:12,fontSize:13.5,color:r.bim("quiet-fg")},children:s})]})}function sb({children:e,facts:i}){return!e&&i?t.jsx("div",{style:{padding:"20px 0 26px",borderBottom:`1px solid ${r.bim("rule")}`,marginBottom:40},children:i}):t.jsxs("div",{className:"bim-d-intro",children:[t.jsx("div",{style:{minWidth:0},children:e}),i]})}function ob({items:e,horizontal:i}){const{convert:n}=gt();return e.length?t.jsx("div",{style:{borderLeft:`2px solid ${r.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((s,o)=>t.jsxs("div",{title:s.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:r.bim("label-fg"),letterSpacing:".08em",flex:"none"},children:n(s.label)}),t.jsx("span",{style:{color:r.bim("body-fg"),textAlign:i?"left":"right",minWidth:0},children:s.value})]},o))}):null}function ab({glyph:e,tone:i,title:n,count:s,actions:o,id:a}){const{convert:l}=gt();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(zs,{char:e,tone:i}),t.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(n)}),s!=null&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:r.bim("label-fg")},children:s})]}),o&&t.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:o})]})}function bc({label:e,active:i,onClick:n,dashed:s}){const{convert:o}=gt();return t.jsx("button",{type:"button",onClick:n,"aria-pressed":i,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${s&&!i?"dashed":"solid"} ${i?r.bim("accent"):r.bim("rule")}`,background:i?r.bim("accent"):"transparent",color:i?r.bim("page-bg"):r.bim("meta-fg"),fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:o(e)})}function lb({label:e,onClick:i}){const{convert:n}=gt();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:r.bim("meta-fg"),borderBottom:`1px solid ${r.bim("rule")}`},children:n(e)})}function cb({label:e,onClick:i,inline:n}){const{convert:s}=gt();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 ${r.bim("rule-dashed")}`,cursor:"pointer",fontSize:12,color:r.bim("meta-fg"),letterSpacing:n?void 0:".08em"},children:s(e)})}function hc({children:e,href:i,onClick:n,title:s}){const o={display:"inline-block",padding:"4px 10px",border:`1px solid ${r.bim("rule")}`,fontSize:13,color:r.bim("body-fg"),lineHeight:1.5};return i||n?t.jsx("a",{href:i??"#",title:s,onClick:n?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),n())}:void 0,style:o,children:e}):t.jsx("span",{title:s,style:o,children:e})}function db({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function mb({volumes:e,unit:i,max:n=60}){const{t:s}=se(),o=i??s("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 ${r.bim("rule")}`,color:r.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 ${r.bim("rule-dashed")}`,fontFamily:"inherit",fontSize:11.5,color:r.bim("meta-fg")},children:["+",e.length-n]}),t.jsx("span",{style:{padding:"2px 6px",color:r.bim("hint-fg")},children:o})]})}function ub({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${r.bim("rule-strong")}`},children:e})}function pb({spec:e}){const{convert:i}=gt();return t.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${e.leadWidth}px 1fr ${e.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:`1px solid ${r.bim("rule-strong")}`,fontSize:11,color:r.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 bb({no:e,main:i,meta:n,spec:s}){return t.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${s.leadWidth}px 1fr ${s.metaWidth}px`,gap:12},children:[t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:r.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:s.columns.map(o=>o.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:n})]})}function hb(e){return String(e+1).padStart(2,"0")}function fb(){return t.jsx("span",{style:{color:r.bim("hint-fg")},children:"—"})}function gb({open:e,onToggle:i,main:n,action:s,children:o}){return t.jsxs("div",{style:{borderBottom:`1px solid ${r.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?r.bim("accent"):r.bim("rule-dashed")}`,background:e?r.bim("accent"):"transparent",color:e?r.bim("page-bg"):r.bim("accent")},children:e?"-":"+"}),t.jsx("span",{style:{fontSize:14,minWidth:0},children:n}),s]}),e&&o&&t.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:`2px solid ${r.bim("rule-accent-soft")}`,marginLeft:12},children:o})]})}function fc(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(`
|
|
1405
|
+
`)||(i.push({start:n,end:l+1,inner:d}),n=l)}return i}function gc(e,i){if(e.length<=i)return e;let n=i;for(const s of fc(e)){if(s.start>=n)break;if(s.end>n){n=s.start>0?s.start:s.end;break}}return e.slice(0,n)}const xc={fontSize:".78em",color:r.bim("meta-fg"),lineHeight:1.55},xb={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 yc(e,i,n,s){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?xc:void 0,children:yc(o.children,i,n+1,s)},a);case"qw":return t.jsx("span",{className:"bim-qw guji-qw",title:o.label?s("detail.lacunaWith",{label:o.label}):s("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:s("detail.composedChar",{label:o.label}),style:xb,children:o.label},a)}})}function At(e,i=s=>s,n){if(!e)return"";if(n!=null&&n.gujiMarkdown)return Jp(e)?yc(ac(e,{jzMaxLength:n.jzMaxLength}),i,0,n.t??r.getT("zh-Hant")):i(e);if(e.indexOf("<")<0)return i(e);const s=[];let o=0,a=0;for(const l of fc(e))l.start>o&&s.push(t.jsx(b.Fragment,{children:i(e.slice(o,l.start))},a++)),s.push(t.jsx("span",{className:"bim-jiazhu",style:xc,children:i(l.inner)},a++)),o=l.end;return o<e.length&&s.push(t.jsx(b.Fragment,{children:i(e.slice(o))},a++)),s}function yb({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:r.bim("label-fg"),marginBottom:4},children:e}),t.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:r.bim("quiet-fg"),textAlign:"justify"},children:i})]})}function jb({title:e,tag:i,children:n}){const{convert:s}=gt();return t.jsxs("div",{children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:`1px solid ${r.bim("rule-strong")}`,marginBottom:2},children:[t.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:s(e)}),i&&t.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:r.bim("accent"),letterSpacing:".06em"},children:s(i)})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column"},children:n})]})}function jc({name:e,note:i,href:n,extra:s}){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:r.bim("hint-fg"),flex:"none"},children:n?"↗":""}),i&&t.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:r.bim("label-fg")},children:i})]}),a={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:`1px solid ${r.bim("rule")}`,color:r.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}),s]})}function kb({item:e,siblings:i,showVolumes:n=!0,fallbackNote:s}){const{t:o,convert:a}=se(),[l,d]=b.useState(!1),c=r.volumeStats(e),m=n&&!!c&&c.expected>0,p=(e.url?r.getDisplayNameFromUrl(e.url):void 0)||a(e.name),h=i?Sl(e,i):"",u=h?`${p}(${h})`:p;return t.jsx(jc,{name:u,note:Dn(e,o)||s,href:r.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:r.bim("meta-fg"),borderBottom:`1px solid ${r.bim("rule")}`},children:l?o("detail.collapseVolumes"):o("detail.expandVolumes",{n:c.expected})}),l&&t.jsx(Cs,{item:e})]}):void 0})}function Cs({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 s=i.status==="missing";return i.url&&!s?t.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{padding:"4px 8px",borderRadius:4,background:r.bim("zebra-bg")},children:i.volume},n):t.jsx("span",{style:{padding:"1px 5px",color:s?r.bim("missing-fg"):r.bim("hint-fg"),textDecoration:s?"line-through":void 0},children:i.volume},n)})})}function kc({label:e,items:i}){const{convert:n}=gt();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:r.bim("label-fg"),letterSpacing:".08em"},children:e}),i.map((s,o)=>t.jsx(hc,{children:n(s)},o))]}):null}function wb({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(kc,{label:n.label,items:n.items},n.label))}):null}function wc(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function vc({left:e,right:i}){return t.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:`1px solid ${r.bim("rule")}`,display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:r.bim("aux-fg")},children:[t.jsx("span",{children:e}),i&&t.jsx("span",{style:{display:"flex",gap:16},children:i})]})}function vb({children:e,action:i}){return t.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:r.bim("aux-fg"),borderBottom:`1px solid ${r.bim("rule")}`,display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[t.jsx("span",{children:e}),i]})}function wt({id:e,label:i,onNavigate:n,renderLink:s,style:o,dense:a}){const l=Tt();return s?t.jsx(t.Fragment,{children:s(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 Sb({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 Sc="guji-table-v1";function $b(e){return!!e&&e.table_notation===Sc}const _b=/^:::table(?:\{[^}]*\})?[ \t]*$/,Nb=/^:::[ \t]*$/;function $c(e){const i=[];let n="";for(let s=0;s<e.length;s++){const o=e[s];if(o===":"&&e.startsWith(":zi[",s)){const l=sc(e,s+3);if(l>s+4){n+=e.slice(s,l+1),s=l;continue}}let a=null;if(o==="<"){const l=e[s+1];l!==void 0&&!/[A-Za-z/!?>\s]/.test(l)&&(a=">")}if(a){const l=e.indexOf(a,s+1);if(l>0){n+=e.slice(s,l+1),s=l;continue}}o==="|"?(i.push(n),n=""):n+=o}return i.push(n),i.map(s=>s.trim())}const zb=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Cb(e){if(e==="^")return{cont:!0};const i=zb.exec(e),n=i[1].trim(),s=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:s,rowspan:o}}}function _c(e,i=1){const n=[],s=[],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=$c(p).map(Cb),f=a.map(j=>j>0),g=a.map(j=>j>0?j-1:0),y=[];let w=0;for(const j of u){if(j.cont){f[w]||n.push(`第 ${m} 行第 ${w+1} 列:续格 ^ 上方没有跨行格`),w+=1;continue}const{cell:x}=j;for(let v=w;v<w+x.colspan;v++)if(f[v]){n.push(`第 ${m} 行第 ${v+1} 列:此处被上方跨行格占住,应写 ^`);break}if(x.rowspan>1)for(let v=w;v<w+x.colspan;v++)g[v]=x.rowspan-1;y.push(x),w+=x.colspan}for(let j=w;j<f.length;j++)f[j]&&n.push(`第 ${m} 行第 ${j+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let j=0;j<g.length;j++)g[j]===void 0&&(g[j]=0);a=g,s.push({header:h,cells:y}),o.push({width:w,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("表尾:有跨行格超出了表的最后一行"),s.length===0&&n.push("空表"),{rows:s,columns:l,warnings:n}}function Es(e){const i=e.split(`
|
|
1406
1406
|
`),n=[];let s=[];const o=()=>{if(s.length===0)return;const l=s.join(`
|
|
1407
|
-
`);s=[],n.push({type:"text",text:l})};let a=0;for(;a<i.length;){if(
|
|
1408
|
-
`)}),a=l+1;continue}}s.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
|
|
1409
|
-
`).map(i=>i.trim()).filter(i=>i&&!
|
|
1410
|
-
`)){const o=s.trim();if(!o||
|
|
1407
|
+
`);s=[],n.push({type:"text",text:l})};let a=0;for(;a<i.length;){if(_b.test(i[a].trim())){let l=a+1;for(;l<i.length&&!Nb.test(i[l].trim());)l++;if(l<i.length){o();const d=i.slice(a+1,l);n.push({type:"table",table:_c(d,a+1),source:i.slice(a,l+1).join(`
|
|
1408
|
+
`)}),a=l+1;continue}}s.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 Eb={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Rb={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Tb=`1px solid ${r.bim("table-border")}`,Nc={border:Tb,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Ib={...Nc,background:r.bim("table-head-bg"),fontWeight:600};function Rs({table:e,opts:i}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Eb,children:t.jsx("table",{className:"bim-guji-table",style:Rb,children:t.jsx("tbody",{children:e.rows.map((n,s)=>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?Ib:Nc,children:o.empty?null:At(o.text,void 0,i)},a)})},s))})})})}function Mb(e,i){return e.indexOf("**")<0?At(e,void 0,i):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((s,o)=>o%2===1?t.jsx("strong",{children:At(s.trim().slice(2,-2),void 0,i)},o):t.jsx(b.Fragment,{children:At(s,void 0,i)},o))}function Ab(e,i,n=!1){const s=n?{gujiMarkdown:!0}:void 0;return i?Es(e).map((o,a)=>o.type==="table"?t.jsx(Rs,{table:o.table,opts:s},a):t.jsx(b.Fragment,{children:Mb(o.text,s)},a)):At(e,void 0,s)}const Lb=/^(#{1,6})\s+(.*)$/,Pb=/^\*\*([^*\n]+)\*\*\s*$/;function Ts(e){const i=e.match(Lb);if(i)return{level:i[1].length,text:i[2].trim()};const n=e.trim().match(Pb);return n?{level:3,text:n[1].trim()}:null}const Is=/^<!--.*-->$/;function zc(e){return e.split(/\n\s*\n/).map(i=>i.trim()).filter(Boolean)}function Cc(e){return e.split(`
|
|
1409
|
+
`).map(i=>i.trim()).filter(i=>i&&!Is.test(i))}const Ob=60;function Ec(e){let i=0,n=0;for(const s of e.split(`
|
|
1410
|
+
`)){const o=s.trim();if(!o||Is.test(o)||Ts(o))continue;const a=o.replace(/<[^<>\n]*>/g,"").replace(/\s/g,"").length;i+=a,a>Ob&&(n+=a)}return i>0&&n*2>=i}function Fb(e){return e.replace(/^[ \t]*:::table[^\n]*\n[\s\S]*?^[ \t]*:::[ \t]*$/gm,"")}function Xn(e){if(e=Fb(e),Ec(e))return"unknown";const i=zc(e);if(i.length===0)return"unknown";if(i.length===1)return"catalog";const n=i.map(o=>Cc(o).length).filter(o=>o>0);if(n.length===0)return"unknown";const s=n.reduce((o,a)=>o+a,0)/n.length;return s<=4?"record":s>=8?"catalog":"unknown"}function Bb(e){const i=e.split(`
|
|
1411
1411
|
`),n=[];let s=null,o=[];const a=()=>{n.push({heading:s,body:o.join(`
|
|
1412
|
-
`)}),o=[]};for(const l of i){const d=
|
|
1413
|
-
`)){const s=
|
|
1414
|
-
`)?"":i)}function
|
|
1415
|
-
`);let m=0;return t.jsx(t.Fragment,{children:c.map((p,h)=>{const u=p.match(
|
|
1416
|
-
,。、;:?!「」『』()…—·`));function
|
|
1412
|
+
`)}),o=[]};for(const l of i){const d=Ts(l);if(d){a(),s={kind:"heading",level:d.level,text:d.text};continue}o.push(l)}return a(),n}function fa(e){const i=[];for(const n of e.split(`
|
|
1413
|
+
`)){const s=Ts(n);if(s){i.push({kind:"heading",level:s.level,text:s.text});continue}const o=n.trim();!o||Is.test(o)||i.push({kind:"body",text:n})}return i}function Rc(e){if(!e)return[];const i=Xn(e);if(i==="unknown")return fa(e);const n=[];for(const{heading:s,body:o}of Bb(e)){s&&n.push(s);const a=zc(o);if(a.length!==0){if(Ec(o)){n.push(...fa(o));continue}if(i==="record"){const l=a.join(" ");l&&n.push({kind:"body",text:l})}else for(const l of a){const d=Cc(l);d.length&&n.push({kind:"body",text:d.join(" ")})}}}return n}const Hb={"「":"“","」":"”","『":"‘","』":"’"},Db={"“":"「","”":"」","‘":"『","’":"』"},Wb=new Set(["《","》","〈","〉"]);function Tc(e,i){const n=i.quoteStyle==="modern"?Hb:i.quoteStyle==="classic"?Db:null;let s="";for(const o of e)i.hideBookBrackets&&Wb.has(o)||(s+=(n==null?void 0:n[o])??o);return s}const Ic=e=>e;function Ms(e){return e.showWorks?e.bookTitleStyle==="bracket"?"bracket":zp(e.properNameMode)?"wavy":"bracket":"none"}function Mc(e,i=Ic,n="wavy"){if(e.indexOf("《")<0)return i(e);const s=[],o=/《([^《》\n]+)》/g;let a=0,l=0,d;for(;d=o.exec(e);){d.index>a&&s.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:"》"})]});s.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&&s.push(t.jsx(b.Fragment,{children:i(e.slice(a))},l++)),s)}function Jn(e,i={}){let n=i.renderText??Ic;const s=i.quoteStyle;if(s&&s!=="original"){const d=n;n=c=>d(Tc(c,{quoteStyle:s}))}const o=i.bookMarking??(i.properNames?"wavy":"bracket"),a=o==="bracket"?n:d=>Mc(d,n,o),l=i.gujiMarkdown?{gujiMarkdown:!0,t:i.t}:void 0;return At(e,a,l)}function ga(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 Er=/^(#{1,6})\s+(.*)$/,Ub=/^\s*<!--.*-->\s*$/;function Ac(e){return e.replace(/<!--[\s\S]*?-->/g,i=>i.includes(`
|
|
1414
|
+
`)?"":i)}function Kb(e){return e<=1?2:e===2?3:4}function Yb(){let e=1;return i=>{const n=Kb(i),s=Math.min(n,e+1);return e=s,{Tag:`h${s}`,className:`bim-rd-hl${n}`}}}function In(e){return e?Xn(Ac(e))!=="unknown":!1}function Vb(e){return/^\u3000{2}/.test(e)}const xa=e=>Vb(e)?"bim-rd-noindent":void 0;function ya({text:e,mode:i,inline:n,dropTitle:s,onStart:o}){o==null||o();const a=Ac(e),l=(p,h,u)=>!!s&&u<=1&&p<=2&&h.trim()===s.trim(),d=Yb();if(i==="paragraph"&&Xn(a)!=="unknown"){const p=Rc(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:xa(h.text),children:ga(h.text,n,u)},u)})})}const c=a.split(`
|
|
1415
|
+
`);let m=0;return t.jsx(t.Fragment,{children:c.map((p,h)=>{const u=p.match(Er);if(u){const g=m++;if(l(u[1].length,u[2],g))return null;const{Tag:y,className:w}=d(u[1].length);return t.jsx(y,{className:w,children:n(u[2])},h)}if(!p.trim())return h>=2&&!!c[h-1].trim()&&!!c[h-2].trim()&&!Er.test(c[h-1])&&!Er.test(c[h-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},h):null;if(Ub.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:xa(p),children:ga(p,n,h)},h)})})}function Gb(e){const{convert:i}=gt();return b.useMemo(()=>e?i(e):"",[e,i])}function As({text:e,mode:i,tables:n=!1,gujiMarkdown:s=!1,properNames:o=!1,bookMarking:a,quoteStyle:l,renderText:d,dropTitle:c}){const m=Gb(e),{t:p,convert:h}=se();let u=null;const f=!!d&&!Fp(e,m,!l||l==="original"),g=d&&f?v=>d(v,{mdStart:u==null?void 0:u.align(v)}):d,y=f?()=>{u=Wp(e)}:void 0,w=v=>Jn(v,{renderText:g,properNames:o,bookMarking:a,quoteStyle:l,gujiMarkdown:s,t:p}),j=s?{gujiMarkdown:!0,t:p}:void 0,x=c?h(c):void 0;return!n||m.indexOf(":::")<0?t.jsx(ya,{text:m,mode:i,inline:w,dropTitle:x,onStart:y}):t.jsx(t.Fragment,{children:Es(m).map((v,S)=>v.type==="table"?t.jsx(Rs,{table:v.table,opts:j},S):t.jsx(ya,{text:v.text,mode:i,inline:w,dropTitle:S===0?x:void 0},S))})}const ja={work:"work",book:"work",people:"people",person:"people",place:"place",office:"office",dynasty:"dynasty",reign:"reign"};function qb(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(ja,e)&&ja[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 s=/^bid:\\{1,2}([0-9A-Za-z]+)$/.exec(i);return s?s[1]:/^[0-9A-Za-z]+$/.test(i)?i:null}function Zt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function bt(e){return typeof e=="string"&&e?e:void 0}function Xb(e){const i=e&&typeof e=="object"?e.candidates:void 0;if(!Array.isArray(i))return;const n=[];for(const s of i){if(!s||typeof s!="object"||Array.isArray(s))continue;const o=s,a={};bt(o.entity_id)!==void 0&&(a.entity_id=bt(o.entity_id)),bt(o.canonical_name)!==void 0&&(a.canonical_name=bt(o.canonical_name)),Zt(o.confidence)!==void 0&&(a.confidence=Zt(o.confidence)),n.push(a)}return n}function Jb(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 s=n,o=ui(bt(s.entity_id))??ui(bt(s.href));o&&i.push({id:o,...bt(s.canonical_name)?{canonicalName:bt(s.canonical_name)}:{},...bt(s.part)?{part:bt(s.part)}:{}})}return i.length>=2?i:void 0}function Zb(e){const i=e&&typeof e=="object"?e.parts:void 0;if(!Array.isArray(i))return;const n=[];for(const s of i){if(!s||typeof s!="object")continue;const o=s,a=o.target??{},l=ui(bt(a.entity_id))??ui(bt(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 Lc(e){const i=Array.isArray(e)?e:e&&typeof e=="object"&&Array.isArray(e.entities)?e.entities:[],n=[];return i.forEach((s,o)=>{if(!s||typeof s!="object")return;const a=s,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=bt(h.start),f=bt(h.end);if(!p&&!!!(u&&f))return;const y=bt(d.status),w=y===void 0||y==="matched"?ui(bt(d.entity_id))??ui(bt(d.href))??void 0:void 0,j=Zt(d.confidence),x=y==="matched_multi"?Jb(d):void 0,v=Xb(a.ambiguous),S=Zb(a.decomposition);n.push({...u&&f?{anchor:{start:u,end:f}}:{},key:bt(a.id)??`e${o}`,kind:qb(a.type),...p?{start:c,end:m}:{},text:bt(a.text),targetId:w,canonicalName:bt(d.canonical_name),...x?{targets:x}:{},confidence:Zt(a.confidence)??j,...j!==void 0?{targetConfidence:j}:{},...bt(d.level)!==void 0?{targetLevel:bt(d.level)}:{},...bt(d.note)!==void 0?{targetNote:bt(d.note)}:{},...bt(a.group)!==void 0?{group:bt(a.group)}:{},...v!==void 0?{candidates:v}:{},...S?{parts:S}:{}})}),n.sort((s,o)=>!ji(s)||!ji(o)?+!ji(s)-+!ji(o):s.start-o.start||o.end-s.end)}const Qb=new Set(Array.from(`《》/<>\r
|
|
1416
|
+
,。、;:?!「」『』()…—·`));function Ls(e){return!Qb.has(e)}function Pc(e,i,n=0){const s=[],o=Array.from(e);let a=0;for(const d of o)Ls(d)&&s.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>s.length||m<=c)continue;const p=s[m-1],h=e.codePointAt(p)>65535?2:1;l.push({...d,start:s[c],end:p+h})}return l}function eh(e,i){return i.text?Array.from(e.slice(i.start,i.end)).filter(Ls).join("")===i.text:!0}function th(e,i,n){if(!i.text)return null;let s=-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;(s<0||Math.abs(l-i.start)<Math.abs(s-i.start))&&(s=l),o=l+1}return s<0?null:{...i,start:s,end:s+i.text.length}}function Oc(e,i,n=16){const s=[];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||!eh(e,d))&&(d=th(e,l,n)),d&&s.push(d)}s.sort((l,d)=>l.start-d.start||d.end-l.end);const o=[];let a=0;for(const l of s)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 ih={off:[],lite:["people","place","dynasty"],full:["people","place","dynasty","office","reign","other"]};function nh(e,i,n){const s=(n==null?void 0:n.showWorks)!==!1,o=new Set(ih[i]);return e.filter(a=>a.kind==="work"?s:o.has(a.kind))}function rh(e,i,n,s=""){const o=`${s}
|
|
1417
1417
|
${n.versionKey??""}
|
|
1418
|
-
${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
|
|
1419
|
-
`),document.head.appendChild(c),()=>{for(const m of a)s.reg.delete(m);c.remove()}}function Kt(e,i,n,s){try{return n()}catch(o){return console.error(`[reader-plugin:${e.id}] ${i} 出错`,o),s}}function
|
|
1418
|
+
${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 sh(){let e=null;const i=new Set;return{get:()=>e,set:n=>{n!==e&&(e=n,i.forEach(s=>s()))},subscribe:n=>(i.add(n),()=>{i.delete(n)})}}function oh(e){return b.useSyncExternalStore(e.subscribe,e.get,e.get)}function ka({store:e,children:i}){const n=oh(e);return b.createElement(b.Fragment,null,i(n))}const Mn="t:",ah=/\s/,lh="bim-text-highlights";function An(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 s=[];for(let o=i.nextNode();o;o=i.nextNode()){const a=o.data;for(let l=0;l<a.length;l++)ah.test(a[l])||(n+=a[l],s.push({node:o,off:l}))}return{text:n,at:s}}function ch(e){const i=[];for(let n=0;n<e.text.length;n++)i.push({anchor:`${Mn}${n}:1`,char:e.text[n],page:0,col:0});return i}function dh(){var n;const e=(n=globalThis.CSS)==null?void 0:n.highlights,i=globalThis.Highlight;return!e||!i?null:{reg:e,make:s=>new i(...s)}}const mh={accent:{bg:r.bim("accent-bg")},warn:{bg:r.bim("highlight-bg")},muted:{fg:r.bim("meta-fg")},add:{bg:r.bim("check-fine-bg"),fg:r.bim("check-fine-fg")},omit:{bg:r.bim("danger-soft-bg"),fg:r.bim("danger")}},uh={solid:"underline",dotted:"underline dotted",dashed:"underline dashed",wavy:"underline wavy"};function ph(e){const i=e.tone?mh[e.tone]:void 0,n=e.bg??(i==null?void 0:i.bg)??(e.focus?r.bim("accent-bg"):void 0),s=e.fg??(i==null?void 0:i.fg),o=e.underline?uh[e.underline]:e.focus?"underline":void 0;return[n&&`background-color:${n}`,s&&`color:${s}`,o&&`text-decoration:${o}`].filter(Boolean).join(";")}function bh(e,i,n){const s=dh();if(!s||!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=ph(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((w,j)=>w-j);const h=[];let u=-1,f=-2;const g=()=>{if(u<0)return;const w=e.at[u],j=e.at[f];if(!w||!j)return;let x=u;for(let v=u+1;v<=f+1;v++)if(v>f||e.at[v].node!==e.at[x].node){const S=e.at[x],$=e.at[v-1],N=document.createRange();N.setStart(S.node,S.off),N.setEnd($.node,$.off+1),h.push(N),x=v}};for(const w of m){if(w===f+1){f=w;continue}g(),u=f=w}g();const y=`bim-cd-${n}-${d++}`;a.push(y),s.reg.set(y,s.make(h)),l.push(`::highlight(${y}){${p}}`)});const c=document.createElement("style");return c.setAttribute("data-bim-text-highlights",n),c.id=`${lh}-${n}`,c.textContent=l.join(`
|
|
1419
|
+
`),document.head.appendChild(c),()=>{for(const m of a)s.reg.delete(m);c.remove()}}function Kt(e,i,n,s){try{return n()}catch(o){return console.error(`[reader-plugin:${e.id}] ${i} 出错`,o),s}}function Fc(e){const i=new Map;for(const n of e)n.forEach((s,o)=>{const a=i.get(o);if(!a){i.set(o,s);return}const l={...a,...hh(s)};(a.focus||s.focus)&&(l.focus=!0),a.title&&s.title&&a.title!==s.title&&(l.title=`${a.title};${s.title}`),i.set(o,l)});return i}function hh(e){const i={};for(const n of Object.keys(e))e[n]!==void 0&&(i[n]=e[n]);return i}function fh(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 Rr=[],fn=new Map,Tr=500,gh=120;function xh(e,i,n){if(!e)return null;const s=An(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=s.indexOf(a);if(l>=0)return`${Mn}${l}:${a.length}`}return null}function wa(e,i){const n=/^t:(\d+):(\d+)$/.exec(i);if(!e||!n)return null;const{at:s}=An(e),o=s[Number(n[1])],a=s[Math.min(s.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 yh(e){let i=0;for(let n=0;n<e.length;n++)i=i*31+e.charCodeAt(n)|0;return Math.abs(i)}function jh(){const[e,i]=b.useState(!1);return b.useEffect(()=>{var o;if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia(ws),s=()=>i(!n.matches);return s(),(o=n.addEventListener)==null||o.call(n,"change",s),()=>{var a;return(a=n.removeEventListener)==null?void 0:a.call(n,"change",s)}},[]),e?"narrow":"wide"}const kh={settings:[],toolbar:{},overlay:null,decorations:void 0,onCellClick:()=>{},onCellHover:()=>{}};function wh(e){const{plugins:i,ctx:n,prefs:s,setPrefs:o,t:a,convert:l,pages:d,textRootRef:c,shellTextRef:m,selectedCharIds:p,scrollToAnchor:h}=e,u=n?`${n.entryId}
|
|
1420
1420
|
${n.versionKey}
|
|
1421
1421
|
${n.chapterKey}`:null,f=i.filter(U=>U.onChapter).map(U=>U.id).join(`
|
|
1422
|
-
`),g=b.useRef({plugins:i,ctx:n});g.current={plugins:i,ctx:n};const[y,w]=b.useState({key:null,map:fn});b.useEffect(()=>{const U=g.current.ctx;if(!u||!U){w({key:null,map:fn});return}let re=!1;w({key:u,map:fn});for(const be of g.current.plugins){if(!be.onChapter)continue;const X=_e=>{re||w(P=>P.key===u?{key:u,map:new Map(P.map).set(be.id,_e)}:P)},L=Kt(be,"onChapter",()=>be.onChapter(U),void 0);Promise.resolve(L).then(X,_e=>{console.error(`[reader-plugin:${be.id}] onChapter 出错`,_e)})}return()=>{re=!0}},[u,f]);const j=y.key===u?y.map:fn,[x,S]=b.useState(0),v=b.useCallback(()=>S(U=>U+1),[]),$=b.useMemo(()=>{if(!d||d.length===0||i.length===0)return Er;const U=[];for(const re of d)for(const be of re.columns)for(const X of be.chars)X.fig||U.push({anchor:X.id,char:X.char,page:re.page,col:be.col});return U},[d,i.length]),N=$.length===0&&i.some(U=>U.decorate),[_,E]=b.useState(Er);b.useEffect(()=>{const U=m.current;if(!N||!U){E(Er);return}let re;const be=()=>{const L=sh(Mn(U));E(_e=>_e.length===L.length&&_e.every((P,K)=>P.char===L[K].char)?_e:L)};if(be(),typeof MutationObserver>"u")return;const X=new MutationObserver(()=>{clearTimeout(re),re=setTimeout(be,80)});return X.observe(U,{childList:!0,subtree:!0,characterData:!0}),()=>{X.disconnect(),clearTimeout(re)}},[N,u,m]);const B=b.useMemo(()=>{const U=new Map;for(const re of $)U.set(re.anchor,re);return U},[$]),T=b.useCallback(U=>{var X,L;if(U.startsWith(In))return((L=(X=ja(m.current,U))==null?void 0:X.getBoundingClientRect)==null?void 0:L.call(X))??null;const re=c.current;if(!re)return null;const be=re.querySelector(`[data-char-id="${U.replace(/["\\]/g,"\\$&")}"]`);return be?be.getBoundingClientRect():null},[c,m]),I=b.useCallback(U=>{var P,K;if("cp"in U)return((P=$[U.cp])==null?void 0:P.anchor)??null;if(!U.text)return null;if($.length===0)return bh(m.current,U.text,l);let re="";const be=[];for(const z of $)be.push(re.length),re+=z.char;const X=re.indexOf(U.text);if(X<0)return null;let L=0,_e=be.length-1;for(;L<_e;){const z=L+_e+1>>1;be[z]<=X?L=z:_e=z-1}return((K=$[L])==null?void 0:K.anchor)??null},[$,m,l]),H=b.useCallback(U=>{var be,X;if(!U.startsWith(In)){h(U);return}const re=(X=(be=ja(m.current,U))==null?void 0:be.getBoundingClientRect)==null?void 0:X.call(be);re&&window.scrollTo({top:window.scrollY+re.top-ph,behavior:"instant"})},[h,m]),M=b.useMemo(()=>n?{ctx:n,state:U=>j.get(U),cells:$,textCells:_,scrollTo:H,rectOf:T,locate:I,refresh:v,prefs:s,setPref:o,t:a,convert:l}:null,[n,j,$,_,H,T,I,v,s,o,a,l,x]),q=b.useMemo(()=>{if(!M)return;const U=[];for(const re of i){if(!re.decorate)continue;const be=Kt(re,"decorate",()=>re.decorate(M),void 0);be&&be.size>0&&U.push(be)}return U.length===0?void 0:U.length===1?U[0]:Ac(U)},[i,M]);b.useEffect(()=>{const U=m.current;if(!($.length>0||!U||!q||q.size===0))return dh(Mn(U),q,u?String(hh(u)):"x")},[$.length,q,m,u,_]);const O=b.useCallback(U=>{var re;return{anchor:U,char:((re=B.get(U))==null?void 0:re.char)??"",rect:T(U)}},[B,T]),ie=b.useCallback(U=>{var be;if(!M)return;const re=O(U);for(const X of i)(be=X.onCell)!=null&&be.click&&Kt(X,"onCell.click",()=>X.onCell.click(re,M),void 0)},[M,i,O]),oe=b.useCallback(U=>{var be;if(!M)return;const re=U?O(U):null;for(const X of i)(be=X.onCell)!=null&&be.hover&&Kt(X,"onCell.hover",()=>X.onCell.hover(re,M),void 0)},[M,i,O]),le=$.length===0&&i.some(U=>U.selectionActions),[ae,pe]=b.useState(null);b.useEffect(()=>{if(!le){pe(null);return}const U=()=>{var V,de;const re=document.getSelection(),be=m.current;if(!re||re.isCollapsed||re.rangeCount===0||!be){pe(null);return}const X=re.getRangeAt(0),L=X.commonAncestorContainer,_e=L instanceof Element?L:L.parentElement;if(!be.contains(L)||_e!=null&&_e.closest('input,textarea,button,select,[contenteditable="true"]')){pe(null);return}const P=re.toString().trim().slice(0,Rr);if(!P){pe(null);return}const K=(V=X.getClientRects)==null?void 0:V.call(X),z=(K&&K.length>0?K[K.length-1]:(de=X.getBoundingClientRect)==null?void 0:de.call(X))??null;pe(ue=>ue&&ue.text===P?ue:{text:P,rect:z})};return document.addEventListener("selectionchange",U),()=>document.removeEventListener("selectionchange",U)},[le,m]),b.useEffect(()=>{pe(null)},[u]);const ee=b.useMemo(()=>{if(!M||!i.some(X=>X.selectionActions))return[];if($.length===0){if(!ae)return[];const X={anchors:[],text:ae.text,rect:ae.rect};return i.flatMap(L=>L.selectionActions?Kt(L,"selectionActions",()=>L.selectionActions(X,M),[]):[])}if(p.size===0)return[];const U=[];let re="";for(const X of $)p.has(X.anchor)&&(U.push(X.anchor),re.length<Rr&&(re+=X.char));if(U.length===0)return[];const be={anchors:U,text:re.slice(0,Rr),rect:T(U[U.length-1])};return i.flatMap(X=>X.selectionActions?Kt(X,"selectionActions",()=>X.selectionActions(be,M),[]):[])},[M,i,p,$,T,ae]),ge=b.useMemo(()=>M?i.filter(U=>U.settings).map((U,re)=>({p:U,i:re,order:U.settings.order??100})).sort((U,re)=>U.order-re.order||U.i-re.i).map(({p:U})=>({key:U.id,group:U.settings.group,title:U.settings.title,node:Kt(U,"settings.render",()=>U.settings.render(M),null)})):[],[i,M]),W=b.useMemo(()=>{if(!M)return{};const U=re=>{const be=i.filter(X=>{var L;return((L=X.toolbar)==null?void 0:L.slot)===re}).map((X,L)=>({p:X,i:L,order:X.toolbar.order??100})).sort((X,L)=>X.order-L.order||X.i-L.i).map(({p:X})=>t.jsx(b.Fragment,{children:Kt(X,"toolbar.render",()=>X.toolbar.render(M),null)},X.id));return be.length>0?t.jsx(t.Fragment,{children:be}):void 0};return{subtitle:U("subtitle"),actions:U("actions")}},[i,M]),ze=b.useMemo(()=>{if(!M)return null;const U=i.filter(re=>re.overlay).map(re=>t.jsx(b.Fragment,{children:Kt(re,"overlay",()=>re.overlay(M),null)},re.id));return U.length===0&&ee.length===0?null:t.jsxs(t.Fragment,{children:[U,ee.length>0&&t.jsx("div",{className:"bim-rd-selbar",role:"toolbar","aria-label":a("reader.selectionActions"),"data-testid":"reader-selbar",children:ee.map(re=>t.jsx("button",{type:"button",title:re.title,onMouseDown:be=>be.preventDefault(),onClick:re.onClick,children:re.label},re.key))})]})},[i,M,ee,a]);return i.length===0?gh:{settings:ge,toolbar:W,overlay:ze,decorations:q,onCellClick:ie,onCellHover:oe}}function yh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(r.TEXT_QUALITY_LABELS,e)?e:null}function jh(e){if(e==="none")return{color:r.bim("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r.bim("quality-placeholder"),fontWeight:400}}const kh={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Lc="\0";function wh(e,i,n){const[s,o=""]=e.split(Lc);return t.jsxs(t.Fragment,{children:[s,t.jsx(Dl,{text:i,convert:n}),o]})}function Ot(e){return typeof e!="string"?"":kh[e]??e}const vh=["〇","一","二","三","四","五","六","七","八","九"],ka=["","十","百","千"],Sh=["","萬","億"];function As(e){if(e===0)return"〇";if(e<0)return`負${As(-e)}`;const i=[];let n=e,s=0;for(;n>0;){const o=n%1e4;o>0?i.unshift($h(o,s>0)+Sh[s]):i.length>0&&i.unshift("〇"),n=Math.floor(n/1e4),s++}return i.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function $h(e,i){const n=[];let s=e;for(;s>0;)n.unshift(s%10),s=Math.floor(s/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+=ka[d]:o+=vh[l]+ka[d]}return o.replace(/〇$/,"")}let Wi=null,gn=null;const An=new Set;function _h(){return Wi?Promise.resolve():gn||(gn=import("opencc-js/t2cn").then(e=>{const i=e.Converter({from:"t",to:"cn"});Wi=n=>i(vi.normalizeVariants(n)),An.forEach(n=>n())}).catch(()=>{Wi=e=>e,An.forEach(e=>e())}),gn)}const Nh=e=>e;function pi(){const[,e]=b.useState(0);return b.useEffect(()=>{if(Wi)return;const i=()=>e(n=>n+1);return An.add(i),_h(),()=>{An.delete(i)}},[]),Wi??Nh}function Ni(e,i){return i(e).toLowerCase()}const zh=r.bim("highlight-bg");function Qi(e,i,n){if(!i)return e;const s=Ni(i,n);if(!s)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(s).length,p=[];let h=0,u=0,f=0;for(;h<a.length;){const g=o.indexOf(s,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:zh,padding:0,color:"inherit"},children:a.slice(y,y+m).join("")},f++)),h=y+m,u=g+s.length}return t.jsx(t.Fragment,{children:p})}function Ls(e,i,n,s){if(!i)return!0;const o=Ni(i,s);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,s).includes(o))}function Ch(e,i,n){return i?Ni(e,n).includes(Ni(i,n)):!0}const Ps={类:r.bim("section-lei"),书:r.bim("section-shu"),序:r.bim("section-xu"),结语:r.bim("section-jieyu"),注释:r.bim("section-zhushi")},Eh={考证:r.bim("section-kaozhen")};function Os(e,i,n){return e.collated.sectionType[i]??n(i)}function Pc(e){var s;const i=e.files.length,n=((s=e.children)==null?void 0:s.reduce((o,a)=>o+Pc(a),0))||0;return i+n}function Rh(e,i){const n=[],s=l=>{var d;n.push(...l.files),(d=l.children)==null||d.forEach(s)};if(s(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 Th={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Fs({enabled:e,expanded:i,onClick:n,style:s,children:o}){return e?t.jsx("button",{type:"button","aria-expanded":i,onClick:n,style:{...Th,...s},children:o}):t.jsx("span",{style:s,children:o})}function Ih({type:e}){const{convert:i,messages:n}=se(),s=Ot(e),o=Ps[s]||r.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:Os(n,s,i)})}function Mh({section:e,onNavigate:i,highlightQuery:n="",no:s,showUnlinked:o=!1,domId:a}){const{t:l,convert:d}=se(),c=Tt(),m=pi(),p=S=>S?At(d(S),v=>n?Qi(v,n,m):v,{t:l}):"",[h,u]=b.useState(!1),f=!!e.summary,g=!!e.comment,y=!!e.additional_comment,w=!!(e.content&&e.content.length>60),j=f||g||y||w;b.useEffect(()=>{n&&u(!0)},[n]);const x=!h&&w?pc(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${r.bim("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>j&&u(!h),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:j?"pointer":"default",userSelect:"none"},children:[s!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:r.bim("label-fg")},children:s}),t.jsxs(Fs,{enabled:j,expanded:h,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[j&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r.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:r.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:r.bim("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d(As(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:r.bim("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!h&&x&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:r.bim("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(x)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:p(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&i&&t.jsx("a",{href:c(e.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),i(e.work_id))},style:{fontSize:"11px",color:r.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:r.bim("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),h&&j&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${r.bim("widget-border")}`,background:r.bim("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:r.bim("desc-fg"),marginBottom:"8px"},children:p(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${r.bim("primary")}`,background:`color-mix(in srgb, ${r.bim("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:r.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 ${r.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:r.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 ${r.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:r.bim("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.additional_comment)})]}),w&&!f&&!g&&!y&&t.jsx("p",{style:{fontSize:"13px",color:r.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function Ah({section:e,highlightQuery:i=""}){const{t:n,convert:s}=se(),o=pi(),a=m=>m?At(s(m),p=>i?Qi(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(Fs,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Ih,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:r.bim("fg")},children:a(e.title)}),c&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r.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, ${Ps[Ot(e.type)]||r.bim("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:r.bim("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:r.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})})]})}const Lh=100;function Bs(e){return Ot(e.type)!=="page_header"?!1:(e.content||"").length>=Lh}function Ph({section:e,highlightQuery:i=""}){const{t:n,convert:s,messages:o}=se(),a=pi();if(Ot(e.type)==="page_header"&&!Bs(e)||!e.content&&!e.title)return null;const l=s((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1423
|
-
`)),d=At(l,h=>i?Qi(h,i,a):h,{t:n}),c=Ot(e.type),m=Ps[c]||r.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:r.bim("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:p?`3px solid ${m}40`:void 0,background:p?r.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:Os(o,c,s)}),d]})}function Oh(e,i,n){const[s,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 w=await i.getEntry(p);if(w)return{title:w.title,author:w.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]),s}function Fh({section:e,onNavigate:i,transport:n,workLabelCache:s,highlightQuery:o=""}){const{t:a,convert:l,messages:d}=se(),c=Tt(),m=pi(),p=v=>v?At(l(v),$=>o?Qi($,o,m):$,{t:a}):"",[h,u]=b.useState(!1);b.useEffect(()=>{o&&u(!0)},[o]);const f=Ot(e.type),g=Eh[f]||r.bim("desc-fg"),y=!!e.content,w=e.work_ids||[],j=w.length>1,x=Oh(j?w:[],n,s),S=y&&!h&&e.content.length>80?pc(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${r.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(Fs,{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:r.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:r.bim("fg"),lineHeight:1.6},children:e.header_line?p(e.header_line):p(e.title)}),!h&&S&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.7},children:p(S)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[w.length===1&&i&&t.jsx("a",{href:c(w[0]),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),i(w[0]))},style:{fontSize:"11px",color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),j&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:w.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:Os(d,f,l)})]})]}),j&&i&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:w.map(v=>{const $=x[v],N=$?`${l($.title)}${$.author?`(${l($.author)})`:""}`:v.slice(0,8)+"…";return t.jsxs("a",{href:c(v),onClick:_=>{_.metaKey||_.ctrlKey||(_.preventDefault(),_.stopPropagation(),i(v))},style:{fontSize:"12px",color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:v,children:["→",N]},v)})}),h&&y&&t.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:r.bim("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:r.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 ${r.bim("widget-border")}`,fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:p(e.comment)})]})]})}function Bh({juan:e,searchQuery:i,onNavigate:n,transport:s,workLabelCache:o}){const{t:a}=se(),l=pi(),d=i.trim(),c=b.useMemo(()=>d?e.sections.filter(m=>Ls(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(Fh,{section:m,onNavigate:n,transport:s,workLabelCache:o,highlightQuery:d},p))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function Hh(){let e=!1;return i=>i==="类"?(e=!0,"h2"):e?"h3":"h2"}function Dh({sections:e,onNavigate:i,inline:n,workLinks:s=!0}){const o=Tt(),{t:a,convert:l}=se(),d=Hh();return t.jsx(t.Fragment,{children:e.map((c,m)=>{const p=Ot(c.type);if(p==="page_header"&&!Bs(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:As(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&&s?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 Oc(e){return e.some(i=>{const n=Ot(i.type);return n==="书"||n==="诗"||n==="考证"||n==="注释"||n==="类"||(n==="序"||n==="结语")&&!!i.content||n==="page_header"&&Bs(i)})}function Wh({juan:e,rawText:i,positionLabel:n,groupLabel:s,index:o,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:m,view:p,onViewChange:h}){var ge;const{t:u,convert:f,messages:g}=se(),y=pi(),[w,j]=b.useState("text"),x=p??w,S=W=>{j(W),h==null||h(W)},v=a.trim(),$=(o==null?void 0:o.type)==="kaozhen",N=b.useCallback(W=>v?Qi(W,v,y):W,[v,y]),_=Ts(m),E=W=>Xn(W,{renderText:N,bookMarking:_,quoteStyle:m.quoteStyle,t:u}),B=b.useMemo(()=>v?e.sections.filter(W=>Ls(W,v,$,y)):e.sections,[e.sections,v,$,y]),T=(W,ze)=>ze.filter(U=>Ot(U.type)===W).length,I=T("书",e.sections),H=T("诗",e.sections),M=T("考证",e.sections);let q="";$?q=v?u("collated.countTiaoOf",{m:T("考证",B),n:M}):u("collated.countTiao",{n:M}):H>0?q=v?u("collated.countPoemsOf",{m:T("诗",B),n:H}):u("collated.countPoems",{n:H}):I>0&&(q=v?u("collated.countBooksOf",{m:T("书",B),n:I}):u("collated.countBooks",{n:I}));const O=o!=null&&o.text_quality?yh(o.text_quality.grade):null,ie=[];if(q&&ie.push(q),$&&(o!=null&&o.target_source)&&ie.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:jh(O),children:g.collated.qualityLabel[O]});ie.push(t.jsx("span",{title:g.collated.qualityCriteria[O],children:(ge=o==null?void 0:o.text_quality)!=null&&ge.source_note?t.jsxs(t.Fragment,{children:[wh(u("collated.baseText",{note:Lc}),o.text_quality.source_note,f),W]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),W]})}))}e.source_url&&ie.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:u("collated.originalSource")}));const oe=!$&&Oc(e.sections),le=!!i&&(!oe||m.readingMode==="paragraph"&&Tn(i)),ae=!$&&(oe||!!i),pe=$||!ae?"entries":x;let ee=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(n||s)&&t.jsxs("p",{className:"bim-rd-kicker",children:[n,n&&s&&t.jsx("span",{className:"bim-rd-dot"}),s&&f(s)]}),t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),ie.length>0&&t.jsx("p",{className:"bim-rd-meta",children:ie.map((W,ze)=>t.jsxs(b.Fragment,{children:[ze>0&&t.jsx("span",{className:"bim-rd-dot"}),W]},ze))}),ae&&e.sections.length>0&&t.jsxs("div",{className:"bim-rd-views",role:"group","aria-label":u("collated.viewsGroup"),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":pe==="text",onClick:()=>S("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":pe==="entries",onClick:()=>S("entries"),children:u("collated.viewEntries")})]})]}),pe==="text"&&t.jsx("article",{className:"bim-rd-prose",children:le?t.jsx(Is,{text:i,mode:m.readingMode,bookMarking:_,quoteStyle:m.quoteStyle,renderText:N,dropTitle:e.title}):t.jsx(Dh,{sections:e.sections,onNavigate:l,inline:E,workLinks:m.workLinks})}),pe==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:$?t.jsx(Bh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[B.some(W=>["书","诗","考证"].includes(Ot(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")})]}),B.map((W,ze)=>{const U=Ot(W.type);return U==="书"||U==="诗"||U==="考证"?(ee+=1,t.jsx(Mh,{domId:`rd-e-${e.sections.indexOf(W)}`,section:W,onNavigate:m.workLinks?l:void 0,highlightQuery:v,no:ee,showUnlinked:m.workLinks&&!!l},ze)):U==="类"?t.jsx(Ah,{section:W,highlightQuery:v},ze):t.jsx(Ph,{section:W,highlightQuery:v},ze)}),B.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function Uh(e){const{resetKey:i,load:n,files:s,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((j,x)=>{const S=x==null?void 0:x.title;S&&g(v=>v[j]===S?v:{...v,[j]:S})},[]);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 w=b.useCallback((j,x)=>{let S=0;if(j.juan)for(const v of j.juan.sections)Ls(v,x,c,m)&&S++;return S===0&&j.rawText&&Ch(j.rawText,x,m)&&(S=1),S},[c,m]);return b.useEffect(()=>{const j=d.trim();if(!j){u({});return}if(!n||s.length===0)return;let x=!1;const S={},v=[];for(const B of s){const T=p.current.get(B);T?S[B]=w(T,j):(S[B]="loading",v.push(B))}u(S);const $=8;let N=0;const _=async()=>{for(;N<v.length;){if(x)return;const B=N++,T=v[B];try{const I=await n(T),H=I.juan;if(p.current.set(T,I),y(T,H),x)return;u(M=>({...M,[T]:w(I,j)}))}catch{if(x)return;u(I=>({...I,[T]:0}))}}},E=Array.from({length:Math.min($,v.length)},()=>_());return Promise.all(E),()=>{x=!0}},[d,i,n,s.join(","),w,m,y]),{matchStates:h,titles:f}}function Kh({juan:e,view:i,onView:n,textHasEntries:s}){const{t:o,convert:a}=se(),l=e.sections.map((p,h)=>({s:p,i:h,t:Ot(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"&&!s&&n("entries"),i==="text"&&!s?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:Xn(a(p.book_title||p.title),{t:o})})]})},h))})]})]})}const Yh=`
|
|
1422
|
+
`),g=b.useRef({plugins:i,ctx:n});g.current={plugins:i,ctx:n};const[y,w]=b.useState({key:null,map:fn});b.useEffect(()=>{const U=g.current.ctx;if(!u||!U){w({key:null,map:fn});return}let ne=!1;w({key:u,map:fn});for(const ue of g.current.plugins){if(!ue.onChapter)continue;const G=Se=>{ne||w(ge=>ge.key===u?{key:u,map:new Map(ge.map).set(ue.id,Se)}:ge)},L=Kt(ue,"onChapter",()=>ue.onChapter(U),void 0);Promise.resolve(L).then(G,Se=>{console.error(`[reader-plugin:${ue.id}] onChapter 出错`,Se)})}return()=>{ne=!0}},[u,f]);const j=y.key===u?y.map:fn,[x,v]=b.useState(0),S=b.useCallback(()=>v(U=>U+1),[]),$=b.useMemo(()=>{if(!d||d.length===0||i.length===0)return Rr;const U=[];for(const ne of d)for(const ue of ne.columns)for(const G of ue.chars)G.fig||U.push({anchor:G.id,char:G.char,page:ne.page,col:ue.col});return U},[d,i.length]),N=$.length===0&&i.some(U=>U.decorate),[z,R]=b.useState(Rr);b.useEffect(()=>{const U=m.current;if(!N||!U){R(Rr);return}let ne;const ue=()=>{const L=ch(An(U));R(Se=>Se.length===L.length&&Se.every((ge,$e)=>ge.char===L[$e].char)?Se:L)};if(ue(),typeof MutationObserver>"u")return;const G=new MutationObserver(()=>{clearTimeout(ne),ne=setTimeout(ue,80)});return G.observe(U,{childList:!0,subtree:!0,characterData:!0}),()=>{G.disconnect(),clearTimeout(ne)}},[N,u,m]);const O=b.useMemo(()=>{const U=new Map;for(const ne of $)U.set(ne.anchor,ne);return U},[$]),C=b.useCallback(U=>{var G,L;if(U.startsWith(Mn))return((L=(G=wa(m.current,U))==null?void 0:G.getBoundingClientRect)==null?void 0:L.call(G))??null;const ne=c.current;if(!ne)return null;const ue=ne.querySelector(`[data-char-id="${U.replace(/["\\]/g,"\\$&")}"]`);return ue?ue.getBoundingClientRect():null},[c,m]),I=b.useCallback(U=>{var ge,$e;if("cp"in U)return((ge=$[U.cp])==null?void 0:ge.anchor)??null;if(!U.text)return null;if($.length===0)return xh(m.current,U.text,l);let ne="";const ue=[];for(const _ of $)ue.push(ne.length),ne+=_.char;const G=ne.indexOf(U.text);if(G<0)return null;let L=0,Se=ue.length-1;for(;L<Se;){const _=L+Se+1>>1;ue[_]<=G?L=_:Se=_-1}return(($e=$[L])==null?void 0:$e.anchor)??null},[$,m,l]),D=b.useCallback(U=>{var ue,G;if(!U.startsWith(Mn)){h(U);return}const ne=(G=(ue=wa(m.current,U))==null?void 0:ue.getBoundingClientRect)==null?void 0:G.call(ue);ne&&window.scrollTo({top:window.scrollY+ne.top-gh,behavior:"instant"})},[h,m]),A=b.useMemo(()=>n?{ctx:n,state:U=>j.get(U),cells:$,textCells:z,scrollTo:D,rectOf:C,locate:I,refresh:S,prefs:s,setPref:o,t:a,convert:l}:null,[n,j,$,z,D,C,I,S,s,o,a,l,x]),X=b.useMemo(()=>{if(!A)return;const U=[];for(const ne of i){if(!ne.decorate)continue;const ue=Kt(ne,"decorate",()=>ne.decorate(A),void 0);ue&&ue.size>0&&U.push(ue)}return U.length===0?void 0:U.length===1?U[0]:Fc(U)},[i,A]);b.useEffect(()=>{const U=m.current;if(!($.length>0||!U||!X||X.size===0))return bh(An(U),X,u?String(yh(u)):"x")},[$.length,X,m,u,z]);const B=b.useCallback(U=>{var ne;return{anchor:U,char:((ne=O.get(U))==null?void 0:ne.char)??"",rect:C(U)}},[O,C]),ae=b.useCallback(U=>{var ue;if(!A)return;const ne=B(U);for(const G of i)(ue=G.onCell)!=null&&ue.click&&Kt(G,"onCell.click",()=>G.onCell.click(ne,A),void 0)},[A,i,B]),te=b.useCallback(U=>{var ue;if(!A)return;const ne=U?B(U):null;for(const G of i)(ue=G.onCell)!=null&&ue.hover&&Kt(G,"onCell.hover",()=>G.onCell.hover(ne,A),void 0)},[A,i,B]),ce=$.length===0&&i.some(U=>U.selectionActions),[be,oe]=b.useState(null);b.useEffect(()=>{if(!ce){oe(null);return}const U=()=>{var P,ie;const ne=document.getSelection(),ue=m.current;if(!ne||ne.isCollapsed||ne.rangeCount===0||!ue){oe(null);return}const G=ne.getRangeAt(0),L=G.commonAncestorContainer,Se=L instanceof Element?L:L.parentElement;if(!ue.contains(L)||Se!=null&&Se.closest('input,textarea,button,select,[contenteditable="true"]')){oe(null);return}const ge=ne.toString().trim().slice(0,Tr);if(!ge){oe(null);return}const $e=(P=G.getClientRects)==null?void 0:P.call(G),_=($e&&$e.length>0?$e[$e.length-1]:(ie=G.getBoundingClientRect)==null?void 0:ie.call(G))??null;oe(re=>re&&re.text===ge?re:{text:ge,rect:_})};return document.addEventListener("selectionchange",U),()=>document.removeEventListener("selectionchange",U)},[ce,m]),b.useEffect(()=>{oe(null)},[u]);const K=b.useMemo(()=>{if(!A||!i.some(G=>G.selectionActions))return[];if($.length===0){if(!be)return[];const G={anchors:[],text:be.text,rect:be.rect};return i.flatMap(L=>L.selectionActions?Kt(L,"selectionActions",()=>L.selectionActions(G,A),[]):[])}if(p.size===0)return[];const U=[];let ne="";for(const G of $)p.has(G.anchor)&&(U.push(G.anchor),ne.length<Tr&&(ne+=G.char));if(U.length===0)return[];const ue={anchors:U,text:ne.slice(0,Tr),rect:C(U[U.length-1])};return i.flatMap(G=>G.selectionActions?Kt(G,"selectionActions",()=>G.selectionActions(ue,A),[]):[])},[A,i,p,$,C,be]),ze=b.useMemo(()=>A?i.filter(U=>U.settings).map((U,ne)=>({p:U,i:ne,order:U.settings.order??100})).sort((U,ne)=>U.order-ne.order||U.i-ne.i).map(({p:U})=>({key:U.id,group:U.settings.group,title:U.settings.title,node:Kt(U,"settings.render",()=>U.settings.render(A),null)})):[],[i,A]),F=b.useMemo(()=>{if(!A)return{};const U=ne=>{const ue=i.filter(G=>{var L;return((L=G.toolbar)==null?void 0:L.slot)===ne}).map((G,L)=>({p:G,i:L,order:G.toolbar.order??100})).sort((G,L)=>G.order-L.order||G.i-L.i).map(({p:G})=>t.jsx(b.Fragment,{children:Kt(G,"toolbar.render",()=>G.toolbar.render(A),null)},G.id));return ue.length>0?t.jsx(t.Fragment,{children:ue}):void 0};return{subtitle:U("subtitle"),actions:U("actions")}},[i,A]),me=b.useMemo(()=>{if(!A)return null;const U=i.filter(ne=>ne.overlay).map(ne=>t.jsx(b.Fragment,{children:Kt(ne,"overlay",()=>ne.overlay(A),null)},ne.id));return U.length===0&&K.length===0?null:t.jsxs(t.Fragment,{children:[U,K.length>0&&t.jsx("div",{className:"bim-rd-selbar",role:"toolbar","aria-label":a("reader.selectionActions"),"data-testid":"reader-selbar",children:K.map(ne=>t.jsx("button",{type:"button",title:ne.title,onMouseDown:ue=>ue.preventDefault(),onClick:ne.onClick,children:ne.label},ne.key))})]})},[i,A,K,a]);return i.length===0?kh:{settings:ze,toolbar:F,overlay:me,decorations:X,onCellClick:ae,onCellHover:te}}function vh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(r.TEXT_QUALITY_LABELS,e)?e:null}function Sh(e){if(e==="none")return{color:r.bim("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r.bim("quality-placeholder"),fontWeight:400}}const $h={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Bc="\0";function _h(e,i,n){const[s,o=""]=e.split(Bc);return t.jsxs(t.Fragment,{children:[s,t.jsx(Yl,{text:i,convert:n}),o]})}function Ot(e){return typeof e!="string"?"":$h[e]??e}const Nh=["〇","一","二","三","四","五","六","七","八","九"],va=["","十","百","千"],zh=["","萬","億"];function Ps(e){if(e===0)return"〇";if(e<0)return`負${Ps(-e)}`;const i=[];let n=e,s=0;for(;n>0;){const o=n%1e4;o>0?i.unshift(Ch(o,s>0)+zh[s]):i.length>0&&i.unshift("〇"),n=Math.floor(n/1e4),s++}return i.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ch(e,i){const n=[];let s=e;for(;s>0;)n.unshift(s%10),s=Math.floor(s/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+=va[d]:o+=Nh[l]+va[d]}return o.replace(/〇$/,"")}let Wi=null,gn=null;const Ln=new Set;function Eh(){return Wi?Promise.resolve():gn||(gn=import("opencc-js/t2cn").then(e=>{const i=e.Converter({from:"t",to:"cn"});Wi=n=>i(vi.normalizeVariants(n)),Ln.forEach(n=>n())}).catch(()=>{Wi=e=>e,Ln.forEach(e=>e())}),gn)}const Rh=e=>e;function pi(){const[,e]=b.useState(0);return b.useEffect(()=>{if(Wi)return;const i=()=>e(n=>n+1);return Ln.add(i),Eh(),()=>{Ln.delete(i)}},[]),Wi??Rh}function Ni(e,i){return i(e).toLowerCase()}const Th=r.bim("highlight-bg");function Qi(e,i,n){if(!i)return e;const s=Ni(i,n);if(!s)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(s).length,p=[];let h=0,u=0,f=0;for(;h<a.length;){const g=o.indexOf(s,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:Th,padding:0,color:"inherit"},children:a.slice(y,y+m).join("")},f++)),h=y+m,u=g+s.length}return t.jsx(t.Fragment,{children:p})}function Os(e,i,n,s){if(!i)return!0;const o=Ni(i,s);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,s).includes(o))}function Ih(e,i,n){return i?Ni(e,n).includes(Ni(i,n)):!0}const Fs={类:r.bim("section-lei"),书:r.bim("section-shu"),序:r.bim("section-xu"),结语:r.bim("section-jieyu"),注释:r.bim("section-zhushi")},Mh={考证:r.bim("section-kaozhen")};function Bs(e,i,n){return e.collated.sectionType[i]??n(i)}function Hc(e){var s;const i=e.files.length,n=((s=e.children)==null?void 0:s.reduce((o,a)=>o+Hc(a),0))||0;return i+n}function Ah(e,i){const n=[],s=l=>{var d;n.push(...l.files),(d=l.children)==null||d.forEach(s)};if(s(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 Lh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Hs({enabled:e,expanded:i,onClick:n,style:s,children:o}){return e?t.jsx("button",{type:"button","aria-expanded":i,onClick:n,style:{...Lh,...s},children:o}):t.jsx("span",{style:s,children:o})}function Ph({type:e}){const{convert:i,messages:n}=se(),s=Ot(e),o=Fs[s]||r.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:Bs(n,s,i)})}function Oh({section:e,onNavigate:i,highlightQuery:n="",no:s,showUnlinked:o=!1,domId:a}){const{t:l,convert:d}=se(),c=Tt(),m=pi(),p=v=>v?At(d(v),S=>n?Qi(S,n,m):S,{t:l}):"",[h,u]=b.useState(!1),f=!!e.summary,g=!!e.comment,y=!!e.additional_comment,w=!!(e.content&&e.content.length>60),j=f||g||y||w;b.useEffect(()=>{n&&u(!0)},[n]);const x=!h&&w?gc(e.content.replace(/\n/g," "),80)+"…":null;return t.jsxs("div",{className:"bim-rd-row",id:a,style:{borderBottom:`1px solid ${r.bim("rule")}`,overflow:"hidden"},children:[t.jsxs("div",{onClick:()=>j&&u(!h),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:j?"pointer":"default",userSelect:"none"},children:[s!=null&&t.jsx("span",{className:"bim-rd-no",style:{flex:"none",width:28,fontSize:12,color:r.bim("label-fg")},children:s}),t.jsxs(Hs,{enabled:j,expanded:h,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[j&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r.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:r.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:r.bim("desc-fg"),marginLeft:"6px"},children:l("collated.nJuan",{n:d(Ps(e.n_juan))})}),(e.author_info||e.author)&&t.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:r.bim("desc-fg"),marginLeft:"8px"},children:p(e.author_info||e.author)})]}),!h&&x&&t.jsx("span",{style:{display:"block",fontSize:"12px",color:r.bim("desc-fg"),overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:p(x)})]})]}),e.edition&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:p(e.edition)}),e.tag&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("section-tag-fg")},children:e.tag==="triangle"?"△":e.tag}),e.work_id&&i&&t.jsx("a",{href:c(e.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),i(e.work_id))},style:{fontSize:"11px",color:r.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:r.bim("label-fg"),flexShrink:0},children:l("collated.unlinked")})]}),h&&j&&t.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:`1px solid ${r.bim("widget-border")}`,background:r.bim("bg")},children:[e.author_info&&t.jsx("div",{style:{fontSize:"13px",color:r.bim("desc-fg"),marginBottom:"8px"},children:p(e.author_info)}),e.summary&&t.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:`3px solid ${r.bim("primary")}`,background:`color-mix(in srgb, ${r.bim("primary")} 4%, transparent)`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.summary")}),t.jsx("p",{style:{fontSize:"13px",color:r.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 ${r.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.comment")}),t.jsx("p",{style:{fontSize:"13px",color:r.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 ${r.bim("desc-fg")}`,borderRadius:"0 4px 4px 0"},children:[t.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:r.bim("desc-fg"),marginBottom:"4px",letterSpacing:"1px"},children:l("collated.additionalComment")}),t.jsx("p",{style:{fontSize:"13px",color:r.bim("fg"),lineHeight:1.8,margin:0,fontStyle:"italic"},children:p(e.additional_comment)})]}),w&&!f&&!g&&!y&&t.jsx("p",{style:{fontSize:"13px",color:r.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:p(e.content)})]})]})}function Fh({section:e,highlightQuery:i=""}){const{t:n,convert:s}=se(),o=pi(),a=m=>m?At(s(m),p=>i?Qi(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(Hs,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Ph,{type:e.type}),t.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:r.bim("fg")},children:a(e.title)}),c&&t.jsx("span",{"aria-hidden":"true",style:{fontSize:"9px",color:r.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, ${Fs[Ot(e.type)]||r.bim("desc-fg")} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:r.bim("bg")},children:t.jsx("p",{style:{fontSize:"13px",color:r.bim("fg"),lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(e.content)})})]})}const Bh=100;function Ds(e){return Ot(e.type)!=="page_header"?!1:(e.content||"").length>=Bh}function Hh({section:e,highlightQuery:i=""}){const{t:n,convert:s,messages:o}=se(),a=pi();if(Ot(e.type)==="page_header"&&!Ds(e)||!e.content&&!e.title)return null;const l=s((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1423
|
+
`)),d=At(l,h=>i?Qi(h,i,a):h,{t:n}),c=Ot(e.type),m=Fs[c]||r.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:r.bim("desc-fg"),lineHeight:1.8,whiteSpace:"pre-line",borderLeft:p?`3px solid ${m}40`:void 0,background:p?r.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:Bs(o,c,s)}),d]})}function Dh(e,i,n){const[s,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 w=await i.getEntry(p);if(w)return{title:w.title,author:w.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]),s}function Wh({section:e,onNavigate:i,transport:n,workLabelCache:s,highlightQuery:o=""}){const{t:a,convert:l,messages:d}=se(),c=Tt(),m=pi(),p=S=>S?At(l(S),$=>o?Qi($,o,m):$,{t:a}):"",[h,u]=b.useState(!1);b.useEffect(()=>{o&&u(!0)},[o]);const f=Ot(e.type),g=Mh[f]||r.bim("desc-fg"),y=!!e.content,w=e.work_ids||[],j=w.length>1,x=Dh(j?w:[],n,s),v=y&&!h&&e.content.length>80?gc(e.content,80)+"……":null;return t.jsxs("div",{style:{borderBottom:`1px solid ${r.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(Hs,{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:r.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:r.bim("fg"),lineHeight:1.6},children:e.header_line?p(e.header_line):p(e.title)}),!h&&v&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.7},children:p(v)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[w.length===1&&i&&t.jsx("a",{href:c(w[0]),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),i(w[0]))},style:{fontSize:"11px",color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),j&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:w.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:Bs(d,f,l)})]})]}),j&&i&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:w.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:r.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:r.bim("bg")},children:[t.jsx("p",{style:{fontSize:"13px",color:r.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 ${r.bim("widget-border")}`,fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.8,fontStyle:"italic"},children:p(e.comment)})]})]})}function Uh({juan:e,searchQuery:i,onNavigate:n,transport:s,workLabelCache:o}){const{t:a}=se(),l=pi(),d=i.trim(),c=b.useMemo(()=>d?e.sections.filter(m=>Os(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(Wh,{section:m,onNavigate:n,transport:s,workLabelCache:o,highlightQuery:d},p))}),c.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:a("collated.noMatch")})]})}function Kh(){let e=!1;return i=>i==="类"?(e=!0,"h2"):e?"h3":"h2"}function Yh({sections:e,onNavigate:i,inline:n,workLinks:s=!0}){const o=Tt(),{t:a,convert:l}=se(),d=Kh();return t.jsx(t.Fragment,{children:e.map((c,m)=>{const p=Ot(c.type);if(p==="page_header"&&!Ds(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:Ps(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&&s?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 Dc(e){return e.some(i=>{const n=Ot(i.type);return n==="书"||n==="诗"||n==="考证"||n==="注释"||n==="类"||(n==="序"||n==="结语")&&!!i.content||n==="page_header"&&Ds(i)})}function Vh({juan:e,rawText:i,positionLabel:n,groupLabel:s,index:o,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c,prefs:m,view:p,onViewChange:h}){var ze;const{t:u,convert:f,messages:g}=se(),y=pi(),[w,j]=b.useState("text"),x=p??w,v=F=>{j(F),h==null||h(F)},S=a.trim(),$=(o==null?void 0:o.type)==="kaozhen",N=b.useCallback(F=>S?Qi(F,S,y):F,[S,y]),z=Ms(m),R=F=>Jn(F,{renderText:N,bookMarking:z,quoteStyle:m.quoteStyle,t:u}),O=b.useMemo(()=>S?e.sections.filter(F=>Os(F,S,$,y)):e.sections,[e.sections,S,$,y]),C=(F,me)=>me.filter(U=>Ot(U.type)===F).length,I=C("书",e.sections),D=C("诗",e.sections),A=C("考证",e.sections);let X="";$?X=S?u("collated.countTiaoOf",{m:C("考证",O),n:A}):u("collated.countTiao",{n:A}):D>0?X=S?u("collated.countPoemsOf",{m:C("诗",O),n:D}):u("collated.countPoems",{n:D}):I>0&&(X=S?u("collated.countBooksOf",{m:C("书",O),n:I}):u("collated.countBooks",{n:I}));const B=o!=null&&o.text_quality?vh(o.text_quality.grade):null,ae=[];if(X&&ae.push(X),$&&(o!=null&&o.target_source)&&ae.push(t.jsx(t.Fragment,{children:u("collated.kaozhenTarget",{target:f(o.target_source)})})),B){const F=t.jsx("span",{className:"bim-rd-grade",style:Sh(B),children:g.collated.qualityLabel[B]});ae.push(t.jsx("span",{title:g.collated.qualityCriteria[B],children:(ze=o==null?void 0:o.text_quality)!=null&&ze.source_note?t.jsxs(t.Fragment,{children:[_h(u("collated.baseText",{note:Bc}),o.text_quality.source_note,f),F]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),F]})}))}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 te=!$&&Dc(e.sections),ce=!!i&&(!te||m.readingMode==="paragraph"&&In(i)),be=!$&&(te||!!i),oe=$||!be?"entries":x;let K=0;return t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[(n||s)&&t.jsxs("p",{className:"bim-rd-kicker",children:[n,n&&s&&t.jsx("span",{className:"bim-rd-dot"}),s&&f(s)]}),t.jsx("h1",{className:"bim-rd-h1",children:f(e.title)}),ae.length>0&&t.jsx("p",{className:"bim-rd-meta",children:ae.map((F,me)=>t.jsxs(b.Fragment,{children:[me>0&&t.jsx("span",{className:"bim-rd-dot"}),F]},me))}),be&&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":oe==="text",onClick:()=>v("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":oe==="entries",onClick:()=>v("entries"),children:u("collated.viewEntries")})]})]}),oe==="text"&&t.jsx("article",{className:"bim-rd-prose",children:ce?t.jsx(As,{text:i,mode:m.readingMode,bookMarking:z,quoteStyle:m.quoteStyle,renderText:N,dropTitle:e.title}):t.jsx(Yh,{sections:e.sections,onNavigate:l,inline:R,workLinks:m.workLinks})}),oe==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:$?t.jsx(Uh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[O.some(F=>["书","诗","考证"].includes(Ot(F.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")})]}),O.map((F,me)=>{const U=Ot(F.type);return U==="书"||U==="诗"||U==="考证"?(K+=1,t.jsx(Oh,{domId:`rd-e-${e.sections.indexOf(F)}`,section:F,onNavigate:m.workLinks?l:void 0,highlightQuery:S,no:K,showUnlinked:m.workLinks&&!!l},me)):U==="类"?t.jsx(Fh,{section:F,highlightQuery:S},me):t.jsx(Hh,{section:F,highlightQuery:S},me)}),O.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function Gh(e){const{resetKey:i,load:n,files:s,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((j,x)=>{const v=x==null?void 0:x.title;v&&g(S=>S[j]===v?S:{...S,[j]:v})},[]);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 w=b.useCallback((j,x)=>{let v=0;if(j.juan)for(const S of j.juan.sections)Os(S,x,c,m)&&v++;return v===0&&j.rawText&&Ih(j.rawText,x,m)&&(v=1),v},[c,m]);return b.useEffect(()=>{const j=d.trim();if(!j){u({});return}if(!n||s.length===0)return;let x=!1;const v={},S=[];for(const O of s){const C=p.current.get(O);C?v[O]=w(C,j):(v[O]="loading",S.push(O))}u(v);const $=8;let N=0;const z=async()=>{for(;N<S.length;){if(x)return;const O=N++,C=S[O];try{const I=await n(C),D=I.juan;if(p.current.set(C,I),y(C,D),x)return;u(A=>({...A,[C]:w(I,j)}))}catch{if(x)return;u(I=>({...I,[C]:0}))}}},R=Array.from({length:Math.min($,S.length)},()=>z());return Promise.all(R),()=>{x=!0}},[d,i,n,s.join(","),w,m,y]),{matchStates:h,titles:f}}function qh({juan:e,view:i,onView:n,textHasEntries:s}){const{t:o,convert:a}=se(),l=e.sections.map((p,h)=>({s:p,i:h,t:Ot(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"&&!s&&n("entries"),i==="text"&&!s?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:Jn(a(p.book_title||p.title),{t:o})})]})},h))})]})]})}const Xh=`
|
|
1424
1424
|
attribute vec2 a_position; // 目标画布像素坐标 [0, canvasWidth] x [0, canvasHeight]
|
|
1425
1425
|
attribute vec2 a_texCoord; // 原图像素坐标 [0, imgWidth] x [0, imgHeight]
|
|
1426
1426
|
|
|
@@ -1438,7 +1438,7 @@ ${n.chapterKey}`:null,f=i.filter(U=>U.onChapter).map(U=>U.id).join(`
|
|
|
1438
1438
|
// 纹理坐标归一化 [0, 1]
|
|
1439
1439
|
v_texCoord = a_texCoord / u_imgResolution;
|
|
1440
1440
|
}
|
|
1441
|
-
`,
|
|
1441
|
+
`,Jh=`
|
|
1442
1442
|
precision mediump float;
|
|
1443
1443
|
uniform sampler2D u_image;
|
|
1444
1444
|
uniform float u_alpha;
|
|
@@ -1448,7 +1448,7 @@ ${n.chapterKey}`:null,f=i.filter(U=>U.onChapter).map(U=>U.id).join(`
|
|
|
1448
1448
|
vec4 tex = texture2D(u_image, v_texCoord);
|
|
1449
1449
|
gl_FragColor = vec4(tex.rgb, tex.a * u_alpha);
|
|
1450
1450
|
}
|
|
1451
|
-
`;function wa(e,i,n){const s=e.createShader(i);return s?(e.shaderSource(s,n),e.compileShader(s),e.getShaderParameter(s,e.COMPILE_STATUS)?s:(console.error("Shader compile error:",e.getShaderInfoLog(s)),e.deleteShader(s),null)):null}class Xr{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 s=wa(n,n.VERTEX_SHADER,Yh),o=wa(n,n.FRAGMENT_SHADER,Vh);if(!s||!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,s),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 s=this.gl;s.viewport(0,0,s.drawingBufferWidth,s.drawingBufferHeight),s.clearColor(.98,.97,.95,1),s.clear(s.COLOR_BUFFER_BIT)}createTexture(i){const n=this.gl,s=n.createTexture();return n.bindTexture(n.TEXTURE_2D,s),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),s}renderStripsWithTexture(i,n,s,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,s),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:w}=u.strip,[j,x,S,v]=w,$=f+j,N=g+x,[_,E,B,T]=y;for(let I=0;I<h;I++){const H=I/h,M=(I+1)/h,q=N+v*H,O=N+v*M,ie=[_[0]+(T[0]-_[0])*H,_[1]+(T[1]-_[1])*H],oe=[_[0]+(T[0]-_[0])*M,_[1]+(T[1]-_[1])*M],le=[E[0]+(B[0]-E[0])*H,E[1]+(B[1]-E[1])*H],ae=[E[0]+(B[0]-E[0])*M,E[1]+(B[1]-E[1])*M],pe=[$,q],ee=[$+S,q],ge=[$,O],W=[$+S,O];m.push(pe[0],pe[1],ee[0],ee[1],ge[0],ge[1]),p.push(ie[0],ie[1],le[0],le[1],oe[0],oe[1]),m.push(ee[0],ee[1],W[0],W[1],ge[0],ge[1]),p.push(le[0],le[1],ae[0],ae[1],oe[0],oe[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)}}function Gh(e){const[i,n]=e.image_size||[0,0];if(!(i>0)||!(n>0)||e.columns.some(u=>{var f;return(((f=u.strips)==null?void 0:f.length)??0)>0}))return null;let s=1/0,o=1/0,a=-1/0,l=-1/0;for(const u of e.columns)for(const f of u.chars){const[g,y,w,j]=f.bbox_col;![g,y,w,j].every(Number.isFinite)||!(w>g)||!(j>y)||(s=Math.min(s,u.offset_x+g),o=Math.min(o,y),a=Math.max(a,u.offset_x+w),l=Math.max(l,j))}for(const u of e.figBlocks??[]){const[f,g,y,w]=u.box;![f,g,y,w].every(Number.isFinite)||!(y>f)||!(w>g)||(s=Math.min(s,f),o=Math.min(o,g),a=Math.max(a,y),l=Math.max(l,w))}if(!(a>s)||!(l>o))return null;const d=Math.min(i,n)*.03,c=Math.min(i,Math.max(0,s-d)),m=Math.min(n,Math.max(0,o-d)),p=Math.min(i,Math.max(0,a+d))-c,h=Math.min(n,Math.max(0,l+d))-m;return!(p>0)||!(h>0)||p>=i*.98&&h>=n*.98?null:{x:c,y:m,w:p,h}}const qh={accent:{bg:r.bim("accent-bg"),fg:r.bim("accent")},warn:{bg:r.bim("highlight-bg"),fg:r.bim("highlight-fg")},muted:{fg:r.bim("meta-fg")},add:{bg:r.bim("check-fine-bg"),fg:r.bim("check-fine-fg")},omit:{bg:r.bim("danger-soft-bg"),fg:r.bim("danger")}};function Xh(e){const i=e.tone&&qh[e.tone]||void 0;return{bg:e.bg??(i==null?void 0:i.bg),fg:e.fg??(i==null?void 0:i.fg)??r.bim("accent")}}const va=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Jh(e,i){const n=Math.max(1,Math.round(e)),s=Math.max(1,Math.round(i));return`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${s}"/>`)}`}const Tr=[1,1.5,2,3,4,6];function Zh(e){for(const i of Tr)if(e<=i)return i;return Tr[Tr.length-1]}function Qh(e,i,n,s,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(s,1),2)*Zh(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 zt=new Map,Sa=8;let $n=null;function ef(e){$n=e}function Jr(e){let i=zt.get(e);if(i)return zt.delete(e),zt.set(e,i),i;const n=$n==null?void 0:$n(e);if(n){for(i=n.then(s=>(s||zt.delete(e),s),()=>(zt.delete(e),null)),zt.set(e,i);zt.size>Sa;)zt.delete(zt.keys().next().value);return i}for(i=new Promise(s=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{(o.decode?o.decode().catch(()=>{}):Promise.resolve()).then(()=>s(o))},o.onerror=()=>{zt.delete(e),s(null)},o.src=e}),zt.set(e,i);zt.size>Sa;)zt.delete(zt.keys().next().value);return i}function tf(e,i){if(!i||!(i.w>0)||!(i.h>0))return e;const[n,s]=e.image_size||[0,0];if(!(n>0)||!(s>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/s-1)<=.01)return e;const a=o/s;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 Hs=({imageUrl:e,pageData:i,selectedCharIds:n,hoveredCharId:s,decorations:o,preserveMargins:a=!1,onCharClick:l,onCharHover:d,selectedFigBlock:c,onFigBlockClick:m,renderScale:p=1})=>{const[h,u]=b.useState(null),f=b.useMemo(()=>tf(i,h&&h.url===e?h:null),[i,h,e]),g=b.useRef(null),y=b.useRef(null),w=typeof ResizeObserver<"u",[j,x]=b.useState(null);va(()=>{const P=y.current;if(!P||typeof ResizeObserver>"u")return;const K=new ResizeObserver(z=>{var de;const V=((de=z[z.length-1])==null?void 0:de.contentRect.width)??0;x(ue=>ue===V?ue:V)});return K.observe(P),()=>K.disconnect()},[]);const S=!w||j!==null&&j>0,v=b.useRef(null),$=b.useRef(null),N=b.useRef(null),_=b.useRef(null),E=b.useRef(null),[B,T]=b.useState(0),[I,H]=b.useState(0),M=b.useRef(""),q=b.useMemo(()=>Math.max(...f.columns.map(P=>P.warped_h),2440),[f]),O=f.total_warped_w,ie=f.banxin,oe=b.useMemo(()=>!f.columns.some(P=>{var K;return(((K=P.strips)==null?void 0:K.length)??0)>0}),[f]),le=b.useMemo(()=>{var He;if(!a||oe)return{top:0,bottom:0,left:0,right:0};const[P,K]=f.image_size||[2386,3082];let z=1/0,V=-1/0,de=1/0,ue=-1/0;for(const G of f.columns)for(const me of G.strips||[])for(const ce of me.srcQuad)ce[0]<z&&(z=ce[0]),ce[0]>V&&(V=ce[0]),ce[1]<de&&(de=ce[1]),ce[1]>ue&&(ue=ce[1]);if((He=f.banxin)!=null&&He.current_page_strips)for(const G of f.banxin.current_page_strips)for(const me of G.srcQuad)me[0]<z&&(z=me[0]),me[0]>V&&(V=me[0]),me[1]<de&&(de=me[1]),me[1]>ue&&(ue=me[1]);return isFinite(z)||(z=0),isFinite(V)||(V=P),isFinite(de)||(de=0),isFinite(ue)||(ue=K),{top:Math.max(0,Math.round(de)),bottom:Math.max(0,Math.round(K-ue)),left:Math.max(0,Math.round(z)),right:Math.max(0,Math.round(P-V)),rawMinX:z,rawMaxX:V,rawMinY:de,rawMaxY:ue,imgW:P,imgH:K}},[f,a,oe]),ae=b.useMemo(()=>{if(!oe)return null;const[P,K]=f.image_size||[0,0];return!(P>0)||!(K>0)?null:!a&&Gh(f)||{x:0,y:0,w:P,h:K}},[f,a,oe]),pe=O+(ie?ie.total_w:0),ee=ae?ae.w:pe+le.left+le.right,ge=ae?ae.h:q+le.top+le.bottom,W=typeof window<"u"&&window.devicePixelRatio||1,[ze,U]=w?Qh(ee,ge,j,W,p):[Math.round(ee),Math.round(ge)],re=b.useCallback(()=>{const P=v.current;if(!(!P||!g.current)&&!(e&&M.current!==e)){if(P.clear(ee,ge),a&&le.rawMinX!==void 0&&_.current&&$.current){const{rawMinX:K,rawMaxX:z,rawMinY:V,rawMaxY:de,imgW:ue,imgH:He,top:G,bottom:me,left:ce,right:Oe}=le,Te=[];ce>0&&Te.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[K,0],[K,He],[0,He]],dstRect:[0,0,ce,ge]}}),G>0&&Te.push({colOffsetX:ce,colOffsetY:0,strip:{srcQuad:[[K,0],[z,0],[z,V],[K,V]],dstRect:[0,0,pe,G]}}),me>0&&Te.push({colOffsetX:ce,colOffsetY:G+q,strip:{srcQuad:[[K,de],[z,de],[z,He],[K,He]],dstRect:[0,0,pe,me]}}),Oe>0&&Te.push({colOffsetX:ce+pe,colOffsetY:0,strip:{srcQuad:[[z,0],[ue,0],[ue,He],[z,He]],dstRect:[0,0,Oe,ge]}}),P.renderStripsWithTexture(_.current,ee,ge,f.image_size[0],f.image_size[1],Te,1)}if(_.current&&$.current){const K=f.columns.flatMap(z=>(z.strips||[]).map(V=>({colOffsetX:le.left+z.offset_x,colOffsetY:le.top,strip:V})));if(K.length>0?P.renderStripsWithTexture(_.current,ee,ge,f.image_size[0],f.image_size[1],K,1):P.renderStripsWithTexture(_.current,ee,ge,f.image_size[0],f.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:ae?[[ae.x,ae.y],[ae.x+ae.w,ae.y],[ae.x+ae.w,ae.y+ae.h],[ae.x,ae.y+ae.h]]:[[0,0],[f.image_size[0],0],[f.image_size[0],f.image_size[1]],[0,f.image_size[1]]],dstRect:[0,0,ee,ge]}}],1),ie&&ie.current_page_strips.length>0){const z=ie.current_page_strips.map(V=>({colOffsetX:le.left+O,colOffsetY:le.top,strip:V}));P.renderStripsWithTexture(_.current,ee,ge,f.image_size[0],f.image_size[1],z,1)}}if(ie&&E.current&&N.current&&ie.mate_page_strips.length>0){const K=ie.mate_page_strips.map(z=>({colOffsetX:le.left+O+ie.half_w,colOffsetY:le.top,strip:z}));P.renderStripsWithTexture(E.current,ee,ge,ie.mate_img_size[0],ie.mate_img_size[1],K,.65)}}},[e,f,ie,ee,ge,O,q,pe,le,a,ae]),be=b.useRef(re);be.current=re,b.useEffect(()=>{const P=g.current;if(!P)return;const K=de=>{_.current=$.current?de.createTexture($.current):null,E.current=N.current?de.createTexture(N.current):null,be.current()};try{const de=new Xr(P);v.current=de,K(de)}catch(de){console.error("Failed to init WebGL renderer:",de)}const z=de=>{de.preventDefault(),console.warn("WebGL context lost")},V=()=>{console.info("WebGL context restored, re-initializing..."),g.current&&(v.current=new Xr(g.current),K(v.current))};return P.addEventListener("webglcontextlost",z,!1),P.addEventListener("webglcontextrestored",V,!1),()=>{P.removeEventListener("webglcontextlost",z),P.removeEventListener("webglcontextrestored",V),v.current&&(v.current.deleteTexture(_.current),v.current.deleteTexture(E.current),v.current.destroy(),v.current=null)}},[]),b.useEffect(()=>{if(!e||!S)return;let P=!0;return Jr(e).then(K=>{if(!P||!K)return;$.current=K,M.current=e,u(V=>V&&V.url===e&&V.w===K.naturalWidth&&V.h===K.naturalHeight?V:{url:e,w:K.naturalWidth,h:K.naturalHeight});const z=v.current;z&&(z.deleteTexture(_.current),_.current=z.createTexture(K)),T(V=>V+1)}),()=>{P=!1}},[e,S]);const X=ie==null?void 0:ie.mate_image_url;b.useEffect(()=>{if(!X||!S)return;let P=!0;return Jr(X).then(K=>{if(!P||!K)return;N.current=K;const z=v.current;z&&(z.deleteTexture(E.current),E.current=z.createTexture(K)),H(V=>V+1)}),()=>{P=!1}},[X,S]),va(()=>{S&&re()},[re,B,I,ze,U,S]);const L=b.useMemo(()=>(f.figBlocks??[]).map(P=>{const[K,z,V,de]=P.box;return{id:P.id,x:le.left+K-((ae==null?void 0:ae.x)??0),y:le.top+z-((ae==null?void 0:ae.y)??0),w:Math.max(V-K,1),h:Math.max(de-z,1)}}),[f,le,ae]),_e=b.useMemo(()=>{const P=[];for(const K of f.columns)for(const z of K.chars){const[V,de,ue,He]=z.bbox_col;P.push({id:z.id,char:z.char,x:le.left+K.offset_x+V-((ae==null?void 0:ae.x)??0),y:le.top+de-((ae==null?void 0:ae.y)??0),w:Math.max(ue-V,1),h:Math.max(He-de,1)})}return P},[f,le,ae]);return t.jsxs("div",{ref:y,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${ee} / ${ge}`,backgroundColor:r.bim("warp-bg"),boxShadow:r.bim("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("img",{alt:"","aria-hidden":"true","data-warp-sizer":"",src:Jh(ee,ge),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:g,width:ze,height:U,"data-logical-size":`${Math.floor(ee)}x${Math.floor(ge)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:r.bim("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${ee} ${ge}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[_e.map(P=>{const K=n.has(P.id),z=s===P.id;return t.jsx("rect",{"data-selected":K?"true":void 0,x:P.x,y:P.y,width:P.w,height:P.h,fill:K?r.bim("warp-sel-bg"):z?r.bim("warp-hover-bg"):"transparent",stroke:K?r.bim("warp-sel-stroke"):z?r.bim("warp-hover-stroke"):"transparent",strokeWidth:K?3.5:z?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>l==null?void 0:l(P.id),onMouseEnter:()=>d==null?void 0:d(P.id),onMouseLeave:()=>d==null?void 0:d(null),children:t.jsx("title",{children:P.char})},P.id)}),o&&o.size>0&&_e.map(P=>{const K=o.get(P.id);if(!K)return null;const z=Xh(K),V=Math.max(10,P.w*.42);return t.jsxs("g",{"data-cd":K.tone??"","data-cd-focus":K.focus?"":void 0,pointerEvents:"none",children:[z.bg&&t.jsx("rect",{x:P.x,y:P.y,width:P.w,height:P.h,fill:z.bg,fillOpacity:.35}),K.underline&&t.jsx("line",{x1:P.x,x2:P.x+P.w,y1:P.y+P.h,y2:P.y+P.h,stroke:z.fg,strokeWidth:3,strokeDasharray:K.underline==="dotted"?"2 5":K.underline==="dashed"?"10 6":void 0}),K.focus&&t.jsx("rect",{x:P.x,y:P.y,width:P.w,height:P.h,fill:"none",stroke:r.bim("accent"),strokeWidth:4}),K.sub&&t.jsx("text",{"data-cd-sub":K.sub,x:P.x+P.w,y:P.y+P.h-2,fontSize:V,textAnchor:"end",fill:z.fg,children:K.sub}),K.insertAfter&&t.jsx("text",{"data-cd-ins":K.insertAfter,x:P.x+P.w/2,y:P.y+P.h+V,fontSize:V,textAnchor:"middle",fill:z.fg,children:K.insertAfter})]},`cd-${P.id}`)}),L.map(P=>{const K=c===P.id;return t.jsx("rect",{"data-fig-block":P.id,"data-selected":K?"true":void 0,x:P.x,y:P.y,width:P.w,height:P.h,fill:K?r.bim("warp-sel-bg"):"transparent",stroke:K?r.bim("warp-sel-stroke"):r.bim("warp-hover-stroke"),strokeWidth:K?3.5:2,strokeDasharray:K?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>m==null?void 0:m(P.id),children:t.jsx("title",{children:P.id})},`fig-${P.id}`)}),ie&&t.jsxs("g",{children:[t.jsx("line",{x1:le.left+O,y1:le.top,x2:le.left+O,y2:le.top+q,stroke:r.bim("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:le.left+O+ie.half_w,y1:le.top,x2:le.left+O+ie.half_w,y2:le.top+q,stroke:r.bim("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:le.left+pe,y1:le.top,x2:le.left+pe,y2:le.top+q,stroke:r.bim("warp-banxin-outer"),strokeWidth:1})]})]})]})},Ds=`
|
|
1451
|
+
`;function Sa(e,i,n){const s=e.createShader(i);return s?(e.shaderSource(s,n),e.compileShader(s),e.getShaderParameter(s,e.COMPILE_STATUS)?s:(console.error("Shader compile error:",e.getShaderInfoLog(s)),e.deleteShader(s),null)):null}class Zr{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 s=Sa(n,n.VERTEX_SHADER,Xh),o=Sa(n,n.FRAGMENT_SHADER,Jh);if(!s||!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,s),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 s=this.gl;s.viewport(0,0,s.drawingBufferWidth,s.drawingBufferHeight),s.clearColor(.98,.97,.95,1),s.clear(s.COLOR_BUFFER_BIT)}createTexture(i){const n=this.gl,s=n.createTexture();return n.bindTexture(n.TEXTURE_2D,s),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),s}renderStripsWithTexture(i,n,s,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,s),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:w}=u.strip,[j,x,v,S]=w,$=f+j,N=g+x,[z,R,O,C]=y;for(let I=0;I<h;I++){const D=I/h,A=(I+1)/h,X=N+S*D,B=N+S*A,ae=[z[0]+(C[0]-z[0])*D,z[1]+(C[1]-z[1])*D],te=[z[0]+(C[0]-z[0])*A,z[1]+(C[1]-z[1])*A],ce=[R[0]+(O[0]-R[0])*D,R[1]+(O[1]-R[1])*D],be=[R[0]+(O[0]-R[0])*A,R[1]+(O[1]-R[1])*A],oe=[$,X],K=[$+v,X],ze=[$,B],F=[$+v,B];m.push(oe[0],oe[1],K[0],K[1],ze[0],ze[1]),p.push(ae[0],ae[1],ce[0],ce[1],te[0],te[1]),m.push(K[0],K[1],F[0],F[1],ze[0],ze[1]),p.push(ce[0],ce[1],be[0],be[1],te[0],te[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 $a=150,Zh=.35,Qh=.25,xn=.01,_a=.25;function ef(e,i,n){if(!(i>8)||!(n>8)||e.length<i*n)return null;const s=[];for(let c=0;c<n;c++){if(c<=xn*n||c>=(1-xn)*n)continue;let m=0,p=0;const h=c*i;for(let u=0;u<i;u++)e[h+u]<$a?(p++,p>m&&(m=p)):p=0;m>Zh*i&&s.push(c)}if(s.length<2)return null;const o=s[0],a=s[s.length-1]+1;if(a-o<_a*n)return null;let l=null,d=null;for(let c=0;c<i;c++){if(c<=xn*i||c>=(1-xn)*i)continue;let m=0;for(let p=o;p<a;p++)e[p*i+c]<$a&&m++;m/(a-o)>=Qh&&(l===null&&(l=c),d=c+1)}return l!==null&&d!==null&&d-l<_a*i&&(l=null,d=null),{x0:l===null?null:l/i,x1:d===null?null:d/i,y0:o/n,y1:a/n}}const Ir=new WeakMap,tf=600;function nf(e){if(Ir.has(e))return Ir.get(e)??null;let i=null;try{const n=e.naturalWidth,s=e.naturalHeight;if(n>0&&s>0&&typeof document<"u"){const o=Math.min(tf,n),a=Math.max(1,Math.round(s*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=ef(m,o,a)}}}catch{i=null}return Ir.set(e,i),i}function rf(e,i){const[n,s]=e.image_size||[0,0];if(!(n>0)||!(s>0)||e.columns.some(j=>{var x;return(((x=j.strips)==null?void 0:x.length)??0)>0}))return null;let o=1/0,a=1/0,l=-1/0,d=-1/0;for(const j of e.columns)for(const x of j.chars){const[v,S,$,N]=x.bbox_col;![v,S,$,N].every(Number.isFinite)||!($>v)||!(N>S)||(o=Math.min(o,j.offset_x+v),a=Math.min(a,S),l=Math.max(l,j.offset_x+$),d=Math.max(d,N))}for(const j of e.figBlocks??[]){const[x,v,S,$]=j.box;![x,v,S,$].every(Number.isFinite)||!(S>x)||!($>v)||(o=Math.min(o,x),a=Math.min(a,v),l=Math.max(l,S),d=Math.max(d,$))}if(!(l>o)||!(d>a))return null;const c=Math.min(n,s)*.03;let m=o-c,p=a-c,h=l+c,u=d+c;if(i){const j=Math.min(n,s)*.015;p=Math.min(a-j,i.y0*s-j),u=Math.max(d+j,i.y1*s+j),i.x0!==null&&i.x1!==null&&(m=Math.min(o-j,i.x0*n-j),h=Math.max(l+j,i.x1*n+j))}const f=Math.min(n,Math.max(0,m)),g=Math.min(s,Math.max(0,p)),y=Math.min(n,Math.max(0,h))-f,w=Math.min(s,Math.max(0,u))-g;return!(y>0)||!(w>0)||y>=n*.98&&w>=s*.98?null:{x:f,y:g,w:y,h:w}}const sf={accent:{bg:r.bim("accent-bg"),fg:r.bim("accent")},warn:{bg:r.bim("highlight-bg"),fg:r.bim("highlight-fg")},muted:{fg:r.bim("meta-fg")},add:{bg:r.bim("check-fine-bg"),fg:r.bim("check-fine-fg")},omit:{bg:r.bim("danger-soft-bg"),fg:r.bim("danger")}};function of(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)??r.bim("accent")}}const Na=typeof window>"u"?b.useEffect:b.useLayoutEffect;function af(e,i){const n=Math.max(1,Math.round(e)),s=Math.max(1,Math.round(i));return`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${s}"/>`)}`}const Mr=[1,1.5,2,3,4,6];function lf(e){for(const i of Mr)if(e<=i)return i;return Mr[Mr.length-1]}function cf(e,i,n,s,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(s,1),2)*lf(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 zt=new Map,za=8;let _n=null;function df(e){_n=e}function Qr(e){let i=zt.get(e);if(i)return zt.delete(e),zt.set(e,i),i;const n=_n==null?void 0:_n(e);if(n){for(i=n.then(s=>(s||zt.delete(e),s),()=>(zt.delete(e),null)),zt.set(e,i);zt.size>za;)zt.delete(zt.keys().next().value);return i}for(i=new Promise(s=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>{(o.decode?o.decode().catch(()=>{}):Promise.resolve()).then(()=>s(o))},o.onerror=()=>{zt.delete(e),s(null)},o.src=e}),zt.set(e,i);zt.size>za;)zt.delete(zt.keys().next().value);return i}function mf(e,i){if(!i||!(i.w>0)||!(i.h>0))return e;const[n,s]=e.image_size||[0,0];if(!(n>0)||!(s>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/s-1)<=.01)return e;const a=o/s;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 Ws=({imageUrl:e,pageData:i,selectedCharIds:n,hoveredCharId:s,decorations:o,preserveMargins:a=!1,onCharClick:l,onCharHover:d,selectedFigBlock:c,onFigBlockClick:m,renderScale:p=1})=>{const[h,u]=b.useState(null),f=b.useMemo(()=>mf(i,h&&h.url===e?h:null),[i,h,e]),[g,y]=b.useState(null),w=b.useRef(null),j=b.useRef(null),x=typeof ResizeObserver<"u",[v,S]=b.useState(null);Na(()=>{const _=j.current;if(!_||typeof ResizeObserver>"u")return;const P=new ResizeObserver(ie=>{var Re;const re=((Re=ie[ie.length-1])==null?void 0:Re.contentRect.width)??0;S(Y=>Y===re?Y:re)});return P.observe(_),()=>P.disconnect()},[]);const $=!x||v!==null&&v>0,N=b.useRef(null),z=b.useRef(null),R=b.useRef(null),O=b.useRef(null),C=b.useRef(null),[I,D]=b.useState(0),[A,X]=b.useState(0),B=b.useRef(""),ae=b.useMemo(()=>Math.max(...f.columns.map(_=>_.warped_h),2440),[f]),te=f.total_warped_w,ce=f.banxin,be=b.useMemo(()=>!f.columns.some(_=>{var P;return(((P=_.strips)==null?void 0:P.length)??0)>0}),[f]),oe=b.useMemo(()=>{var de;if(!a||be)return{top:0,bottom:0,left:0,right:0};const[_,P]=f.image_size||[2386,3082];let ie=1/0,re=-1/0,Re=1/0,Y=-1/0;for(const le of f.columns)for(const Te of le.strips||[])for(const _e of Te.srcQuad)_e[0]<ie&&(ie=_e[0]),_e[0]>re&&(re=_e[0]),_e[1]<Re&&(Re=_e[1]),_e[1]>Y&&(Y=_e[1]);if((de=f.banxin)!=null&&de.current_page_strips)for(const le of f.banxin.current_page_strips)for(const Te of le.srcQuad)Te[0]<ie&&(ie=Te[0]),Te[0]>re&&(re=Te[0]),Te[1]<Re&&(Re=Te[1]),Te[1]>Y&&(Y=Te[1]);return isFinite(ie)||(ie=0),isFinite(re)||(re=_),isFinite(Re)||(Re=0),isFinite(Y)||(Y=P),{top:Math.max(0,Math.round(Re)),bottom:Math.max(0,Math.round(P-Y)),left:Math.max(0,Math.round(ie)),right:Math.max(0,Math.round(_-re)),rawMinX:ie,rawMaxX:re,rawMinY:Re,rawMaxY:Y,imgW:_,imgH:P}},[f,a,be]),K=b.useMemo(()=>{if(!be)return null;const[_,P]=f.image_size||[0,0];return!(_>0)||!(P>0)?null:!a&&rf(f,g&&g.url===e?g.frame:null)||{x:0,y:0,w:_,h:P}},[f,a,be,g,e]),ze=te+(ce?ce.total_w:0),F=K?K.w:ze+oe.left+oe.right,me=K?K.h:ae+oe.top+oe.bottom,U=typeof window<"u"&&window.devicePixelRatio||1,[ne,ue]=x?cf(F,me,v,U,p):[Math.round(F),Math.round(me)],G=b.useCallback(()=>{const _=N.current;if(!(!_||!w.current)&&!(e&&B.current!==e)){if(_.clear(F,me),a&&oe.rawMinX!==void 0&&O.current&&z.current){const{rawMinX:P,rawMaxX:ie,rawMinY:re,rawMaxY:Re,imgW:Y,imgH:de,top:le,bottom:Te,left:_e,right:xe}=oe,Ce=[];_e>0&&Ce.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[P,0],[P,de],[0,de]],dstRect:[0,0,_e,me]}}),le>0&&Ce.push({colOffsetX:_e,colOffsetY:0,strip:{srcQuad:[[P,0],[ie,0],[ie,re],[P,re]],dstRect:[0,0,ze,le]}}),Te>0&&Ce.push({colOffsetX:_e,colOffsetY:le+ae,strip:{srcQuad:[[P,Re],[ie,Re],[ie,de],[P,de]],dstRect:[0,0,ze,Te]}}),xe>0&&Ce.push({colOffsetX:_e+ze,colOffsetY:0,strip:{srcQuad:[[ie,0],[Y,0],[Y,de],[ie,de]],dstRect:[0,0,xe,me]}}),_.renderStripsWithTexture(O.current,F,me,f.image_size[0],f.image_size[1],Ce,1)}if(O.current&&z.current){const P=f.columns.flatMap(ie=>(ie.strips||[]).map(re=>({colOffsetX:oe.left+ie.offset_x,colOffsetY:oe.top,strip:re})));if(P.length>0?_.renderStripsWithTexture(O.current,F,me,f.image_size[0],f.image_size[1],P,1):_.renderStripsWithTexture(O.current,F,me,f.image_size[0],f.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:K?[[K.x,K.y],[K.x+K.w,K.y],[K.x+K.w,K.y+K.h],[K.x,K.y+K.h]]:[[0,0],[f.image_size[0],0],[f.image_size[0],f.image_size[1]],[0,f.image_size[1]]],dstRect:[0,0,F,me]}}],1),ce&&ce.current_page_strips.length>0){const ie=ce.current_page_strips.map(re=>({colOffsetX:oe.left+te,colOffsetY:oe.top,strip:re}));_.renderStripsWithTexture(O.current,F,me,f.image_size[0],f.image_size[1],ie,1)}}if(ce&&C.current&&R.current&&ce.mate_page_strips.length>0){const P=ce.mate_page_strips.map(ie=>({colOffsetX:oe.left+te+ce.half_w,colOffsetY:oe.top,strip:ie}));_.renderStripsWithTexture(C.current,F,me,ce.mate_img_size[0],ce.mate_img_size[1],P,.65)}}},[e,f,ce,F,me,te,ae,ze,oe,a,K]),L=b.useRef(G);L.current=G,b.useEffect(()=>{const _=w.current;if(!_)return;const P=Re=>{O.current=z.current?Re.createTexture(z.current):null,C.current=R.current?Re.createTexture(R.current):null,L.current()};try{const Re=new Zr(_);N.current=Re,P(Re)}catch(Re){console.error("Failed to init WebGL renderer:",Re)}const ie=Re=>{Re.preventDefault(),console.warn("WebGL context lost")},re=()=>{console.info("WebGL context restored, re-initializing..."),w.current&&(N.current=new Zr(w.current),P(N.current))};return _.addEventListener("webglcontextlost",ie,!1),_.addEventListener("webglcontextrestored",re,!1),()=>{_.removeEventListener("webglcontextlost",ie),_.removeEventListener("webglcontextrestored",re),N.current&&(N.current.deleteTexture(O.current),N.current.deleteTexture(C.current),N.current.destroy(),N.current=null)}},[]),b.useEffect(()=>{if(!e||!$)return;let _=!0;return Qr(e).then(P=>{if(!_||!P)return;z.current=P,B.current=e,y({url:e,frame:nf(P)}),u(re=>re&&re.url===e&&re.w===P.naturalWidth&&re.h===P.naturalHeight?re:{url:e,w:P.naturalWidth,h:P.naturalHeight});const ie=N.current;ie&&(ie.deleteTexture(O.current),O.current=ie.createTexture(P)),D(re=>re+1)}),()=>{_=!1}},[e,$]);const Se=ce==null?void 0:ce.mate_image_url;b.useEffect(()=>{if(!Se||!$)return;let _=!0;return Qr(Se).then(P=>{if(!_||!P)return;R.current=P;const ie=N.current;ie&&(ie.deleteTexture(C.current),C.current=ie.createTexture(P)),X(re=>re+1)}),()=>{_=!1}},[Se,$]),Na(()=>{$&&G()},[G,I,A,ne,ue,$]);const ge=b.useMemo(()=>(f.figBlocks??[]).map(_=>{const[P,ie,re,Re]=_.box;return{id:_.id,x:oe.left+P-((K==null?void 0:K.x)??0),y:oe.top+ie-((K==null?void 0:K.y)??0),w:Math.max(re-P,1),h:Math.max(Re-ie,1)}}),[f,oe,K]),$e=b.useMemo(()=>{const _=[];for(const P of f.columns)for(const ie of P.chars){const[re,Re,Y,de]=ie.bbox_col;_.push({id:ie.id,char:ie.char,x:oe.left+P.offset_x+re-((K==null?void 0:K.x)??0),y:oe.top+Re-((K==null?void 0:K.y)??0),w:Math.max(Y-re,1),h:Math.max(de-Re,1)})}return _},[f,oe,K]);return t.jsxs("div",{ref:j,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${F} / ${me}`,backgroundColor:r.bim("warp-bg"),boxShadow:r.bim("warp-box-shadow"),borderRadius:"3px",overflow:"hidden",margin:"0 auto"},children:[t.jsx("img",{alt:"","aria-hidden":"true","data-warp-sizer":"",src:af(F,me),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:w,width:ne,height:ue,"data-logical-size":`${Math.floor(F)}x${Math.floor(me)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:r.bim("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${F} ${me}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[$e.map(_=>{const P=n.has(_.id),ie=s===_.id;return t.jsx("rect",{"data-selected":P?"true":void 0,x:_.x,y:_.y,width:_.w,height:_.h,fill:P?r.bim("warp-sel-bg"):ie?r.bim("warp-hover-bg"):"transparent",stroke:P?r.bim("warp-sel-stroke"):ie?r.bim("warp-hover-stroke"):"transparent",strokeWidth:P?3.5:ie?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>l==null?void 0:l(_.id),onMouseEnter:()=>d==null?void 0:d(_.id),onMouseLeave:()=>d==null?void 0:d(null),children:t.jsx("title",{children:_.char})},_.id)}),o&&o.size>0&&$e.map(_=>{const P=o.get(_.id);if(!P)return null;const ie=of(P),re=Math.max(10,_.w*.42);return t.jsxs("g",{"data-cd":P.tone??"","data-cd-focus":P.focus?"":void 0,pointerEvents:"none",children:[ie.bg&&t.jsx("rect",{x:_.x,y:_.y,width:_.w,height:_.h,fill:ie.bg,fillOpacity:.35}),P.underline&&t.jsx("line",{x1:_.x,x2:_.x+_.w,y1:_.y+_.h,y2:_.y+_.h,stroke:ie.fg,strokeWidth:3,strokeDasharray:P.underline==="dotted"?"2 5":P.underline==="dashed"?"10 6":void 0}),P.focus&&t.jsx("rect",{x:_.x,y:_.y,width:_.w,height:_.h,fill:"none",stroke:r.bim("accent"),strokeWidth:4}),P.sub&&t.jsx("text",{"data-cd-sub":P.sub,x:_.x+_.w,y:_.y+_.h-2,fontSize:re,textAnchor:"end",fill:ie.fg,children:P.sub}),P.insertAfter&&t.jsx("text",{"data-cd-ins":P.insertAfter,x:_.x+_.w/2,y:_.y+_.h+re,fontSize:re,textAnchor:"middle",fill:ie.fg,children:P.insertAfter})]},`cd-${_.id}`)}),ge.map(_=>{const P=c===_.id;return t.jsx("rect",{"data-fig-block":_.id,"data-selected":P?"true":void 0,x:_.x,y:_.y,width:_.w,height:_.h,fill:P?r.bim("warp-sel-bg"):"transparent",stroke:P?r.bim("warp-sel-stroke"):r.bim("warp-hover-stroke"),strokeWidth:P?3.5:2,strokeDasharray:P?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>m==null?void 0:m(_.id),children:t.jsx("title",{children:_.id})},`fig-${_.id}`)}),ce&&t.jsxs("g",{children:[t.jsx("line",{x1:oe.left+te,y1:oe.top,x2:oe.left+te,y2:oe.top+ae,stroke:r.bim("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:oe.left+te+ce.half_w,y1:oe.top,x2:oe.left+te+ce.half_w,y2:oe.top+ae,stroke:r.bim("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:oe.left+ze,y1:oe.top,x2:oe.left+ze,y2:oe.top+ae,stroke:r.bim("warp-banxin-outer"),strokeWidth:1})]})]})]})},Us=`
|
|
1452
1452
|
.bim-et-w { position: relative; display: inline; }
|
|
1453
1453
|
.bim-et {
|
|
1454
1454
|
color: inherit; text-decoration-line: underline;
|
|
@@ -1535,23 +1535,23 @@ a.bim-et:focus-visible { outline: 2px solid ${r.bim("accent")}; outline-offset:
|
|
|
1535
1535
|
.bim-et-card[data-sheet] { animation: bim-et-up 160ms ease-out; }
|
|
1536
1536
|
@keyframes bim-et-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
|
|
1537
1537
|
}
|
|
1538
|
-
`,nf=120;function Ct(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function rf(e,i=nf){if(!e)return;const n=e.replace(/\s+/g," ").trim(),s=Array.from(n);return s.length>i?s.slice(0,i).join("")+"…":n}function sf(e){const i=e.dates&&typeof e.dates=="object"?e.dates:{},n=typeof i.birth=="number"?i.birth:void 0,s=typeof i.death=="number"?i.death:void 0;if(!(n===void 0&&s===void 0))return`${n??"?"}–${s??"?"}`}function of(e){if(!Array.isArray(e.authors))return;const i=e.authors.map(n=>{if(!n||typeof n!="object")return"";const s=n,o=Ct(s.name);return o?[Ct(s.dynasty)&&`〔${Ct(s.dynasty)}〕`,o,Ct(s.role)].filter(Boolean).join(""):""}).filter(Boolean);return i.length?i.slice(0,3).join("、"):void 0}function Fc(e,i){const n=Ct(i.type),s=Ct(i.primary_name)??Ct(i.title)??e,o=n==="entity"?[Ct(i.dynasty),sf(i),Ct(i.native_place)].filter(Boolean).join(" · "):[of(i),Ct(i.edition),Ct(i.measure_info)].filter(Boolean).join(" · "),a=i.description&&typeof i.description=="object"?Ct(i.description.text):Ct(i.description);return{id:Ct(i.id)??e,type:n,title:s,meta:o||void 0,description:rf(a)}}function Bc(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 Hc(e){return async i=>{const n=await e.getItem(i);if(n)return Fc(i,n);if(e.getEntry){const s=await e.getEntry(i);if(s)return Bc(s)}return null}}const $a=new WeakMap;function Dc(e,i,n){let s=$a.get(e);s||(s=new Map,$a.set(e,s));const o=s.get(n);if(o)return o;const a=i(n);return s.set(n,a),a.catch(()=>s.delete(n)),a}const Wc=e=>`/item/${encodeURIComponent(e)}`,Zr={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Ws=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Us(e,i){return b.useMemo(()=>i?{owner:i,load:i}:e?{owner:e,load:Hc(e)}:null,[i,e])}const af=e=>e,lf=({text:e,entities:i,offsets:n="text",plainBase:s=0,transport:o,loadSummary:a,buildHref:l=Wc,onNavigate:d,renderText:c=af,hoverDelayMs:m=250,closeDelayMs:p,injectStyles:h=!0,className:u})=>{const f=b.useMemo(()=>{const y=n==="plain"?Ic(e,i,s):i;return Mc(e,y)},[e,i,n,s]),g=Us(o,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[h&&t.jsx("style",{children:Ds}),f.map(y=>y.type==="text"?t.jsx(b.Fragment,{children:c(y.text)},`t${y.start}`):t.jsx(Ks,{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 Ks=({span:e,label:i,hasBrackets:n,plain:s,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,w]=b.useState(!1),[j,x]=b.useState(!1),S=b.useRef(!1),v=b.useRef(null),$=b.useRef(null),N=`bim-et bim-et-${e.kind}${s?" bim-et-nu":""}`,_=e.kind==="work"&&!n,E=t.jsxs(t.Fragment,{children:[_&&t.jsx("span",{className:"bim-et-sr",children:"《"}),m(i),_&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),B=()=>{v.current&&(clearTimeout(v.current),v.current=null)},T=()=>{$.current&&(clearTimeout($.current),$.current=null)},I=b.useRef(!1),H=b.useCallback(()=>{I.current=!1,B(),T(),g(!1),w(!1),x(!1),Jt===H&&(Jt=null)},[]);b.useEffect(()=>()=>{B(),T(),Jt===H&&(Jt=null)},[H]);const M=b.useCallback(()=>{Jt&&Jt!==H&&Jt(),Jt=H,g(!0)},[H]),q=b.useCallback(ee=>{T(),w(!0),!f&&(B(),ee<=0?M():v.current=setTimeout(M,ee))},[f,M]),O=b.useCallback(()=>{B(),T(),!I.current&&($.current=setTimeout(H,h))},[H,h]),ie=b.useRef(null);b.useEffect(()=>{if(!f||!(e.targets||j))return;const ee=j?"click":"pointerdown",ge=W=>{var ze;(ze=ie.current)!=null&&ze.contains(W.target)||H()};return document.addEventListener(ee,ge),()=>document.removeEventListener(ee,ge)},[f,j,e.targets,H]);const oe=b.useCallback(()=>{B(),T(),I.current=!0,w(!0),x(!0),M()},[M]);Ws(()=>{if(!f||!j)return;const ee=ie.current,ge=ee==null?void 0:ee.querySelector(".bim-et-card");if(!ee||!ge||typeof window>"u")return;const W=()=>{const U=ee.getClientRects(),re=U[U.length-1];if(!re)return;const be=re.bottom+12-ge.getBoundingClientRect().top;be>0&&window.scrollBy({top:be,behavior:"smooth"})};if(W(),typeof ResizeObserver>"u")return;const ze=new ResizeObserver(W);return ze.observe(ge),()=>ze.disconnect()},[f,j]);const le=!!e.targetId,ae=e.targetId,pe={className:"bim-et-w","data-active":y?"":void 0,onPointerEnter:ee=>{S.current=ee.pointerType==="touch"},onPointerDown:ee=>{S.current=ee.pointerType==="touch"},onMouseEnter:()=>{S.current||q(p)},onMouseLeave:()=>{S.current||O()},onBlur:ee=>{ee.currentTarget.contains(ee.relatedTarget)||H()},onKeyDown:ee=>{ee.key==="Escape"&&f&&(ee.stopPropagation(),H())}};return e.targets?t.jsxs("span",{...pe,ref:ie,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:()=>{S.current||q(0)},onClick:()=>{S.current?oe():(T(),I.current=!0,w(!0),M())},onKeyDown:ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),f?H():(I.current=!0,w(!0),M()))},children:E}),f&&t.jsx(cf,{id:u,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:j,onClose:H})]}):!le||!ae?t.jsxs("span",{...pe,ref:ie,children:[t.jsx("span",{className:N,children:E}),f&&!S.current&&t.jsx(_a,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...pe,ref:ie,children:[t.jsx("a",{className:N,href:a(ae),"data-entity-id":ae,"aria-describedby":f?u:void 0,onFocus:()=>{S.current||q(0)},onClick:ee=>{if(S.current&&ee.detail>0){ee.preventDefault(),oe();return}l==null||l(ae,ee)},children:E}),f&&t.jsx(_a,{id:u,entityId:ae,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:j,onClose:H})]})},_a=({id:e,entityId:i,span:n,loader:s,buildHref:o,onNavigate:a,newTab:l,sheet:d,onClose:c})=>{const{convert:m,t:p}=se(),h=b.useRef(null),[u,f]=b.useState("start"),[g,y]=b.useState(s&&i?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!s||!i)return;let x=!1;return y({status:"loading"}),Dc(s.owner,s.load,i).then(S=>{x||y({status:"ready",summary:S})}).catch(()=>{x||y({status:"error"})}),()=>{x=!0}},[s,i]),Ws(()=>{const x=h.current;if(!x||typeof window>"u")return;const S=x.getBoundingClientRect(),v=document.documentElement.clientWidth||window.innerWidth;!d&&S.right>v-8&&u==="start"&&f("end")},[g,u,d]);const w=g.status==="ready"?g.summary:null,j=(w==null?void 0:w.title)??n.canonicalName??n.text;return i?t.jsxs("span",{ref:h,id:e,role:d?"dialog":"tooltip","aria-label":d?j:void 0,className:"bim-et-card","data-align":u,"data-sheet":d?"":void 0,children:[d&&c&&t.jsx(Uc,{onClose:c}),t.jsx("span",{className:"bim-et-card-k",children:m(Zr[n.kind])}),j&&t.jsx("span",{className:"bim-et-card-t",children:m(j)}),(w==null?void 0:w.meta)&&t.jsx("span",{className:"bim-et-card-m",children:m(w.meta)}),(w==null?void 0:w.description)&&t.jsx("span",{className:"bim-et-card-d",children:m(w.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("摘要載入失敗")}),w&&t.jsx("a",{className:"bim-et-card-a",href:o(w.id||i),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?x=>a(w.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(Zr[n.kind])})})},cf=({id:e,span:i,loader:n,buildHref:s,onNavigate:o,newTab:a,sheet:l,onClose:d})=>{const{convert:c}=se(),m=b.useRef(null),[p,h]=b.useState(0);Ws(()=>{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(Uc,{onClose:d}),t.jsxs("span",{className:"bim-et-card-k",children:[c("合稱")," · ",c(`${u.length} 條`)]}),u.map(f=>t.jsx(df,{target:f,kind:i.kind,loader:n,buildHref:s,onNavigate:o,newTab:a},f.id))]})},df=({target:e,kind:i,loader:n,buildHref:s,onNavigate:o,newTab:a})=>{const{convert:l,t:d}=se(),[c,m]=b.useState(n?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!n)return;let u=!1;return m({status:"loading"}),Dc(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:mf(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(h)}),t.jsx("span",{className:"bim-et-row-k",children:l(Zr[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:s(p.id||e.id),...a?{target:"_blank",rel:"noopener"}:{},onClick:o?u=>o(p.id||e.id,u):void 0,children:d("reader.entityDetail")})]})},mf=(e,i)=>`${i(e)} →`,Uc=({onClose:e})=>{const{t:i}=se();return t.jsx("button",{type:"button",className:"bim-et-card-x","aria-label":i("reader.close"),onClick:e,children:"×"})},Ys=e=>`〔图:${e}〕`,Kc=(e,i)=>e&&i?i(e.file):null;function Yc({fig:e,info:i,figUrl:n,block:s,failed:o,onFail:a}){const l=(i==null?void 0:i.alt)??"图形符号",d=Kc(i,n);if(!d||o)return t.jsx("span",{className:"guji-fig-missing","data-fig-missing":e,children:Ys(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${s?" is-block":""}`,src:d,alt:s?l:"","data-fig":e,"data-raster":"1",loading:s?"lazy":void 0,decoding:"async",draggable:!1,style:c?{aspectRatio:c}:void 0,onError:a})}function uf({id:e,fig:i,info:n,figUrl:s,cells:o,cont:a,className:l,pageStart:d,children:c}){const{t:m}=se(),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||!Kc(n,s);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":Ys((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(Yc,{fig:i,info:n,figUrl:s,failed:u,onFail:()=>f(!0)})]})}function pf({fig:e,info:i,figUrl:n,onClick:s}){const{t:o}=se(),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":Ys(a),title:l,onClick:s,style:s?{cursor:"pointer"}:void 0,children:[t.jsx(Yc,{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 s=()=>{n&&!n.endsWith(`
|
|
1538
|
+
`,uf=120;function Ct(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function pf(e,i=uf){if(!e)return;const n=e.replace(/\s+/g," ").trim(),s=Array.from(n);return s.length>i?s.slice(0,i).join("")+"…":n}function bf(e){const i=e.dates&&typeof e.dates=="object"?e.dates:{},n=typeof i.birth=="number"?i.birth:void 0,s=typeof i.death=="number"?i.death:void 0;if(!(n===void 0&&s===void 0))return`${n??"?"}–${s??"?"}`}function hf(e){if(!Array.isArray(e.authors))return;const i=e.authors.map(n=>{if(!n||typeof n!="object")return"";const s=n,o=Ct(s.name);return o?[Ct(s.dynasty)&&`〔${Ct(s.dynasty)}〕`,o,Ct(s.role)].filter(Boolean).join(""):""}).filter(Boolean);return i.length?i.slice(0,3).join("、"):void 0}function Wc(e,i){const n=Ct(i.type),s=Ct(i.primary_name)??Ct(i.title)??e,o=n==="entity"?[Ct(i.dynasty),bf(i),Ct(i.native_place)].filter(Boolean).join(" · "):[hf(i),Ct(i.edition),Ct(i.measure_info)].filter(Boolean).join(" · "),a=i.description&&typeof i.description=="object"?Ct(i.description.text):Ct(i.description);return{id:Ct(i.id)??e,type:n,title:s,meta:o||void 0,description:pf(a)}}function Uc(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 Kc(e){return async i=>{const n=await e.getItem(i);if(n)return Wc(i,n);if(e.getEntry){const s=await e.getEntry(i);if(s)return Uc(s)}return null}}const Ca=new WeakMap;function Yc(e,i,n){let s=Ca.get(e);s||(s=new Map,Ca.set(e,s));const o=s.get(n);if(o)return o;const a=i(n);return s.set(n,a),a.catch(()=>s.delete(n)),a}const Vc=e=>`/item/${encodeURIComponent(e)}`,es={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Ks=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Ys(e,i){return b.useMemo(()=>i?{owner:i,load:i}:e?{owner:e,load:Kc(e)}:null,[i,e])}const ff=e=>e,gf=({text:e,entities:i,offsets:n="text",plainBase:s=0,transport:o,loadSummary:a,buildHref:l=Vc,onNavigate:d,renderText:c=ff,hoverDelayMs:m=250,closeDelayMs:p,injectStyles:h=!0,className:u})=>{const f=b.useMemo(()=>{const y=n==="plain"?Pc(e,i,s):i;return Oc(e,y)},[e,i,n,s]),g=Ys(o,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[h&&t.jsx("style",{children:Us}),f.map(y=>y.type==="text"?t.jsx(b.Fragment,{children:c(y.text)},`t${y.start}`):t.jsx(Vs,{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 Vs=({span:e,label:i,hasBrackets:n,plain:s,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,w]=b.useState(!1),[j,x]=b.useState(!1),v=b.useRef(!1),S=b.useRef(null),$=b.useRef(null),N=`bim-et bim-et-${e.kind}${s?" bim-et-nu":""}`,z=e.kind==="work"&&!n,R=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:"》"})]}),O=()=>{S.current&&(clearTimeout(S.current),S.current=null)},C=()=>{$.current&&(clearTimeout($.current),$.current=null)},I=b.useRef(!1),D=b.useCallback(()=>{I.current=!1,O(),C(),g(!1),w(!1),x(!1),Jt===D&&(Jt=null)},[]);b.useEffect(()=>()=>{O(),C(),Jt===D&&(Jt=null)},[D]);const A=b.useCallback(()=>{Jt&&Jt!==D&&Jt(),Jt=D,g(!0)},[D]),X=b.useCallback(K=>{C(),w(!0),!f&&(O(),K<=0?A():S.current=setTimeout(A,K))},[f,A]),B=b.useCallback(()=>{O(),C(),!I.current&&($.current=setTimeout(D,h))},[D,h]),ae=b.useRef(null);b.useEffect(()=>{if(!f||!(e.targets||j))return;const K=j?"click":"pointerdown",ze=F=>{var me;(me=ae.current)!=null&&me.contains(F.target)||D()};return document.addEventListener(K,ze),()=>document.removeEventListener(K,ze)},[f,j,e.targets,D]);const te=b.useCallback(()=>{O(),C(),I.current=!0,w(!0),x(!0),A()},[A]);Ks(()=>{if(!f||!j)return;const K=ae.current,ze=K==null?void 0:K.querySelector(".bim-et-card");if(!K||!ze||typeof window>"u")return;const F=()=>{const U=K.getClientRects(),ne=U[U.length-1];if(!ne)return;const ue=ne.bottom+12-ze.getBoundingClientRect().top;ue>0&&window.scrollBy({top:ue,behavior:"smooth"})};if(F(),typeof ResizeObserver>"u")return;const me=new ResizeObserver(F);return me.observe(ze),()=>me.disconnect()},[f,j]);const ce=!!e.targetId,be=e.targetId,oe={className:"bim-et-w","data-active":y?"":void 0,onPointerEnter:K=>{v.current=K.pointerType==="touch"},onPointerDown:K=>{v.current=K.pointerType==="touch"},onMouseEnter:()=>{v.current||X(p)},onMouseLeave:()=>{v.current||B()},onBlur:K=>{K.currentTarget.contains(K.relatedTarget)||D()},onKeyDown:K=>{K.key==="Escape"&&f&&(K.stopPropagation(),D())}};return e.targets?t.jsxs("span",{...oe,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:()=>{v.current||X(0)},onClick:()=>{v.current?te():(C(),I.current=!0,w(!0),A())},onKeyDown:K=>{(K.key==="Enter"||K.key===" ")&&(K.preventDefault(),f?D():(I.current=!0,w(!0),A()))},children:R}),f&&t.jsx(xf,{id:u,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:j,onClose:D})]}):!ce||!be?t.jsxs("span",{...oe,ref:ae,children:[t.jsx("span",{className:N,children:R}),f&&!v.current&&t.jsx(Ea,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...oe,ref:ae,children:[t.jsx("a",{className:N,href:a(be),"data-entity-id":be,"aria-describedby":f?u:void 0,onFocus:()=>{v.current||X(0)},onClick:K=>{if(v.current&&K.detail>0){K.preventDefault(),te();return}l==null||l(be,K)},children:R}),f&&t.jsx(Ea,{id:u,entityId:be,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:j,onClose:D})]})},Ea=({id:e,entityId:i,span:n,loader:s,buildHref:o,onNavigate:a,newTab:l,sheet:d,onClose:c})=>{const{convert:m,t:p}=se(),h=b.useRef(null),[u,f]=b.useState("start"),[g,y]=b.useState(s&&i?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!s||!i)return;let x=!1;return y({status:"loading"}),Yc(s.owner,s.load,i).then(v=>{x||y({status:"ready",summary:v})}).catch(()=>{x||y({status:"error"})}),()=>{x=!0}},[s,i]),Ks(()=>{const x=h.current;if(!x||typeof window>"u")return;const v=x.getBoundingClientRect(),S=document.documentElement.clientWidth||window.innerWidth;!d&&v.right>S-8&&u==="start"&&f("end")},[g,u,d]);const w=g.status==="ready"?g.summary:null,j=(w==null?void 0:w.title)??n.canonicalName??n.text;return i?t.jsxs("span",{ref:h,id:e,role:d?"dialog":"tooltip","aria-label":d?j:void 0,className:"bim-et-card","data-align":u,"data-sheet":d?"":void 0,children:[d&&c&&t.jsx(Gc,{onClose:c}),t.jsx("span",{className:"bim-et-card-k",children:m(es[n.kind])}),j&&t.jsx("span",{className:"bim-et-card-t",children:m(j)}),(w==null?void 0:w.meta)&&t.jsx("span",{className:"bim-et-card-m",children:m(w.meta)}),(w==null?void 0:w.description)&&t.jsx("span",{className:"bim-et-card-d",children:m(w.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("摘要載入失敗")}),w&&t.jsx("a",{className:"bim-et-card-a",href:o(w.id||i),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?x=>a(w.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(es[n.kind])})})},xf=({id:e,span:i,loader:n,buildHref:s,onNavigate:o,newTab:a,sheet:l,onClose:d})=>{const{convert:c}=se(),m=b.useRef(null),[p,h]=b.useState(0);Ks(()=>{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(Gc,{onClose:d}),t.jsxs("span",{className:"bim-et-card-k",children:[c("合稱")," · ",c(`${u.length} 條`)]}),u.map(f=>t.jsx(yf,{target:f,kind:i.kind,loader:n,buildHref:s,onNavigate:o,newTab:a},f.id))]})},yf=({target:e,kind:i,loader:n,buildHref:s,onNavigate:o,newTab:a})=>{const{convert:l,t:d}=se(),[c,m]=b.useState(n?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!n)return;let u=!1;return m({status:"loading"}),Yc(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:jf(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(h)}),t.jsx("span",{className:"bim-et-row-k",children:l(es[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:s(p.id||e.id),...a?{target:"_blank",rel:"noopener"}:{},onClick:o?u=>o(p.id||e.id,u):void 0,children:d("reader.entityDetail")})]})},jf=(e,i)=>`${i(e)} →`,Gc=({onClose:e})=>{const{t:i}=se();return t.jsx("button",{type:"button",className:"bim-et-card-x","aria-label":i("reader.close"),onClick:e,children:"×"})},Gs=e=>`〔图:${e}〕`,qc=(e,i)=>e&&i?i(e.file):null;function Xc({fig:e,info:i,figUrl:n,block:s,failed:o,onFail:a}){const l=(i==null?void 0:i.alt)??"图形符号",d=qc(i,n);if(!d||o)return t.jsx("span",{className:"guji-fig-missing","data-fig-missing":e,children:Gs(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${s?" is-block":""}`,src:d,alt:s?l:"","data-fig":e,"data-raster":"1",loading:s?"lazy":void 0,decoding:"async",draggable:!1,style:c?{aspectRatio:c}:void 0,onError:a})}function kf({id:e,fig:i,info:n,figUrl:s,cells:o,cont:a,className:l,pageStart:d,children:c}){const{t:m}=se(),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||!qc(n,s);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":Gs((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(Xc,{fig:i,info:n,figUrl:s,failed:u,onFail:()=>f(!0)})]})}function wf({fig:e,info:i,figUrl:n,onClick:s}){const{t:o}=se(),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":Gs(a),title:l,onClick:s,style:s?{cursor:"pointer"}:void 0,children:[t.jsx(Xc,{fig:e,info:i,figUrl:n,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const vf=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function Sf(e){const i=e.cloneContents();if(!i.querySelector("[data-fig-copy]"))return null;let n="";const s=()=>{n&&!n.endsWith(`
|
|
1539
1539
|
`)&&(n+=`
|
|
1540
|
-
`)},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"?(s(),n+=d,s()):n+=d;return}const c=bf.has(l.tagName);c&&s(),l.childNodes.forEach(o),c&&s();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const ff=e=>`/item/${encodeURIComponent(e)}`;function gf(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 xf(e,i){const n=[];for(const s of e){const o=i.get(s.charData.id)??null,a=n[n.length-1];a&&a.entity===o?a.chars.push(s):n.push({entity:o,chars:[s]})}return n}const Vs=({pageData:e,pages:i,punctuations:n=Qr,selectedCharIds:s,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:w,loadEntitySummary:j,buildEntityHref:x,onEntityNavigate:S,pageBreaks:v=!0,pageIndicatorY:$,onPageIndicatorYChange:N,quoteStyle:_,bookTitleStyle:E,showWorks:B,figures:T,figUrl:I,onFigureBlockClick:H,decorations:M})=>{var pt,We,ft;const{t:q}=se(),O=b.useRef(null),ie=b.useRef(0),oe=b.useMemo(()=>{const Q=new Map;return m&&n.forEach((A,ne)=>{const ve=A.id?A:{...A,id:`${A.anchor}#${ne}`},Ee=Q.get(ve.anchor)||[];Ee.push(ve),Q.set(ve.anchor,Ee)}),Q},[n,m]),le=b.useMemo(()=>_===void 0&&E===void 0&&B===void 0?null:{quoteStyle:_??"original",hideBookBrackets:E==="wavy"||B===!1},[_,E,B]),ae=E==="bracket",pe=b.useMemo(()=>{var Ye;const Q=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],A=new Map;for(const Me of Q)for(const Ne of Me.columns)Ne.chars.length>0&&!Ne.raised&&A.set(Ne.lead_blank||0,(A.get(Ne.lead_blank||0)||0)+1);let ne=0,ve=-1;for(const[Me,Ne]of A)(Ne>ve||Ne===ve&&Me<ne)&&(ne=Me,ve=Ne);const Ee=Me=>!!Me.raised||(Me.lead_blank||0)<ne,Pe=Q.filter(Me=>Me.columns.some(Ne=>Ne.chars.length>0||Ne.kind==="figure")).map(Me=>{const Ne=[...Me.columns].sort((tt,Lt)=>tt.col-Lt.col),it=[];let nt=[];const Ue=()=>{const tt=Cf(oe.get(nt[0].charData.id));it.push({id:`para-p${Me.page}-${it.length}`,chars:nt,...tt?{heading:{level:tt.mark.length,anchor:nt[0].charData.id,...tt.toc===!1?{toc:!1}:{}}}:{}}),nt=[]};let F=!1,ye=0,qe;const Ke=[];for(const tt of Ne){if(tt.kind==="figure"&&tt.fig){nt.length>0?Ue():it.length===0&&(F=!0),Ke.push({before:it.length,fig:tt.fig,...tt.figBox?{box:tt.figBox}:{}}),ye=0;continue}if(tt.chars.length===0){tt.kind==="blank"&&ye++;continue}const Lt=tt.raised||tt.lead_blank||ye?{raised:tt.raised,leadBlank:tt.lead_blank,blankBefore:ye}:void 0;ye=0,Ee(tt)||(qe=tt.lead_blank||0);let lt=!0;for(const St of tt.chars){const Pt=oe.get(St.id),{before:Nt,after:or}=Pt?gf(Pt):wf,nn=!!Pt&&Pt.some(ni=>ni.kind==="break"&&ni.pos!=="before");Pt&&Pt.some(ni=>ni.kind==="heading")&&(nt.length>0?Ue():it.length===0&&(F=!0)),nt.push({charData:St,col:tt.col,beforePuncts:Nt,afterPuncts:or,...lt&&Lt?{start:Lt}:{}}),lt=!1,nn&&Ue()}}const kt=nt.length>0;return kt&&Ue(),{page:Me.page,paragraphs:it,endsOpen:kt,...qe!==void 0?{tailLead:qe}:{},...F?{leadStarts:F}:{},...Me.label?{label:Me.label}:{},...ye>0?{trailingBlank:ye}:{},...Ke.length>0?{blocks:Ke}:{}}}),ot=new Map;if(!v){let Me=null;for(const Ne of Pe){const it=Ne.paragraphs[0],nt=(Ye=it==null?void 0:it.chars[0])==null?void 0:Ye.start,Ue=(nt==null?void 0:nt.leadBlank)||0,F=!!nt&&!nt.raised&&Ue>=ne&&Ue>((Me==null?void 0:Me.tailLead)??ne),ye=!!Ne.leadStarts||!!(nt!=null&&nt.blankBefore)||F,qe=Ne.paragraphs.length===1&&!!Ne.trailingBlank;if(Me&&it&&!ye&&!qe){for(const Ke of it.chars)ot.set(Ke.charData.id,Me.owner);Me.para.chars=Me.para.chars.concat(it.chars),Ne.leadFirstId=it.chars[0].charData.id,Ne.paragraphs=Ne.paragraphs.slice(1),Ne.blocks&&(Ne.blocks=Ne.blocks.map(Ke=>({...Ke,before:Ke.before-1})))}if(Ne.endsOpen&&!Ne.trailingBlank){const Ke=Ne.paragraphs[Ne.paragraphs.length-1];Ke?Me={para:Ke,owner:Ne.page,tailLead:Ne.tailLead??(Me==null?void 0:Me.tailLead)??ne}:Me&&Ne.tailLead!==void 0&&(Me.tailLead=Ne.tailLead)}else Me=null}}const at=new Map;for(const Me of Pe)Me.leadFirstId&&at.set(Me.leadFirstId,Me.page);return{pages:Pe,mergedOwner:ot,pageStarts:at}},[i,e,oe,v]),ee=pe.pages,ge=b.useRef(ee);ge.current=ee;const W=b.useMemo(()=>ee.map(Q=>Q.paragraphs.reduce((A,ne)=>A+ne.chars.length,0)),[ee]),ze=b.useCallback((Q,A)=>{let ne=Q,ve=0;for(;ne<W.length&&(ne===Q||ve+W[ne]<=A);)ve+=W[ne++];return ne},[W]),U=`${ee.length}:${((ft=(We=(pt=ee[0])==null?void 0:pt.paragraphs[0])==null?void 0:We.chars[0])==null?void 0:ft.charData.id)??""}`,[re,be]=b.useState(()=>({sig:U,n:ze(0,za)}));let X=re.n;re.sig!==U&&(X=ze(0,za),be({sig:U,n:X})),X=Math.min(X,ee.length);const L=X>=ee.length;b.useEffect(()=>L?void 0:(A=>{const ne=window;if(ne.requestIdleCallback){const Ee=ne.requestIdleCallback(A,{timeout:300});return()=>{var Pe;return(Pe=ne.cancelIdleCallback)==null?void 0:Pe.call(ne,Ee)}}const ve=setTimeout(A,16);return()=>clearTimeout(ve)})(()=>be(A=>A.sig===U?{sig:A.sig,n:Math.max(A.n,ze(A.n,yf))}:A)),[L,X,U,ze]);const _e=b.useCallback(Q=>{const A=ge.current.findIndex(ve=>ve.page>=Q),ne=(A<0?ge.current.length:A)+2;be(ve=>ve.n>=ne?ve:{...ve,n:ne})},[]),P=L?ee:ee.slice(0,X);b.useEffect(()=>{let Q;const A=requestAnimationFrame(()=>{Q=setTimeout(()=>{const ne=O.current,ve=ne==null?void 0:ne.querySelector(".guji-reflow-paragraph");if(!ne||!ve)return;const Ee=getComputedStyle(ve),Pe=parseFloat(Ee.fontSize),ot=ve.clientWidth;if(!(Pe>0)||!(ot>0))return;const at=parseFloat(Ee.lineHeight);ne.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(ot/Pe)))),ne.style.setProperty("--gtv-lh",`${Math.round(at>0?at:Pe*2)}px`)},0)});return()=>{cancelAnimationFrame(A),Q&&clearTimeout(Q)}},[U]);const K=b.useMemo(()=>{const Q=[];for(const A of ee)for(const ne of A.paragraphs)for(const ve of ne.chars)Q.push(ve.charData.id);return Q},[ee]),z=b.useMemo(()=>new Map(K.map((Q,A)=>[Q,A])),[K]),V=b.useMemo(()=>{const Q=new Map;if(!y||y.length===0)return Q;const A=z;for(const ne of y){if(!ne.anchor)continue;const ve=A.get(ne.anchor.start),Ee=A.get(ne.anchor.end);if(!(ve===void 0||Ee===void 0||Ee<ve))for(let Pe=ve;Pe<=Ee;Pe++)Q.has(K[Pe])||Q.set(K[Pe],ne)}return Q},[y,K,z]),de=b.useMemo(()=>{const Q=f==null?void 0:f.anchor;return Q&&Q.startsWith("e=")?new Set(Q.slice(2).split(",").filter(Boolean)):null},[f==null?void 0:f.anchor]),ue=b.useMemo(()=>{var ve;if(!de||!y)return[];const Q=new Set,A=[],ne=(Ee,Pe)=>{const ot=`${Ee}:${Pe}`;Q.has(ot)||(Q.add(ot),A.push([Ee,Pe]))};for(const Ee of y){if(!Ee.anchor)continue;const Pe=z.get(Ee.anchor.start),ot=z.get(Ee.anchor.end);if(!(Pe===void 0||ot===void 0||ot<Pe)){(Ee.targetId&&de.has(Ee.targetId)||(ve=Ee.targets)!=null&&ve.some(at=>de.has(at.id)))&&ne(Pe,ot);for(const at of Ee.parts??[]){if(!de.has(at.id))continue;const Ye=Pe+at.offset[0],Me=Pe+at.offset[1]-1;Me>=Ye&&Me<=ot&&ne(Ye,Me)}}}return A.sort((Ee,Pe)=>Ee[0]-Pe[0]||Ee[1]-Pe[1])},[de,y,z]),He=Us(w,j),G=V.size>0,me=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:S,onVisibleHeadingChange:g,onFigureBlockClick:H});me.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:S,onVisibleHeadingChange:g,onFigureBlockClick:H};const ce=b.useMemo(()=>({click:Q=>{var A,ne;ie.current=Date.now()+1200,(ne=(A=me.current).onCharClick)==null||ne.call(A,Q)},enter:Q=>{var A,ne;return(ne=(A=me.current).onCharHover)==null?void 0:ne.call(A,Q)},leave:()=>{var Q,A;return(A=(Q=me.current).onCharHover)==null?void 0:A.call(Q,null)},figBlock:Q=>{var A,ne;return(ne=(A=me.current).onFigureBlockClick)==null?void 0:ne.call(A,Q)},navigate:(Q,A)=>{A.ctrlKey||A.metaKey||A.shiftKey||(A.preventDefault(),A.detail===0&&window.open(A.currentTarget.href,"_blank","noopener"))}}),[]),Oe=zf(s,pe.mergedOwner),Te=Nf(M,pe.mergedOwner),je=b.useRef(X);je.current=X;const Re=b.useRef(null),Ie=b.useCallback(Q=>{const A=Re.current,ne=A==null?void 0:A.map.get(Q);if(ne&&ne.isConnected)return ne;if(A&&A.for===ge.current&&A.n===je.current&&!ne)return null;const ve=O.current;if(!ve)return null;const Ee=new Map;return ve.querySelectorAll("span[data-char-id]").forEach(Pe=>{Ee.set(Pe.getAttribute("data-char-id"),Pe)}),Re.current={for:ge.current,n:je.current,map:Ee},Ee.get(Q)??null},[]),Je=b.useRef(null);b.useEffect(()=>{var A;if((A=Je.current)==null||A.classList.remove("is-hovered"),Je.current=null,!o)return;const Q=Ie(o);Q&&(Q.classList.add("is-hovered"),Je.current=Q)},[o,Ie]);const ut=b.useRef(null),Ve=Q=>{var ne;const A=Q instanceof Element?Q.closest("span[data-char-id]"):null;return A&&((ne=O.current)!=null&&ne.contains(A))?A.getAttribute("data-char-id"):null},ht=Q=>{const A=Ve(Q.target);A&&ce.click(A)},Ge=Q=>{const A=Ve(Q.target);A!==ut.current&&(ut.current=A,A?ce.enter(A):ce.leave())},k=Q=>{const A=typeof window<"u"?window.getSelection():null;if(!A||A.isCollapsed||A.rangeCount===0)return;const ne=hf(A.getRangeAt(0));ne!==null&&(Q.clipboardData.setData("text/plain",ne),Q.preventDefault())},te=()=>{ut.current!==null&&(ut.current=null,ce.leave())};b.useEffect(()=>{let Q=null;const A=()=>{var ye,qe;Q=null;const ve=window.getSelection(),Ee=O.current;if(!ve||ve.isCollapsed||ve.rangeCount===0||!Ee)return;const Pe=ve.getRangeAt(0),ot=Pe.commonAncestorContainer,at=ot.nodeType===3?ot.parentElement:ot;if(!at||!Ee.contains(at))return;const Ye=Ee.querySelectorAll("span[data-char-id]"),Me=Ke=>{let kt=Ke;for(;kt.nodeType!==3&&kt.firstChild;)kt=kt.firstChild;return kt};let Ne=0,it=Ye.length;for(;Ne<it;){const Ke=Ne+it>>1;Pe.comparePoint(Me(Ye[Ke]),0)<0?Ne=Ke+1:it=Ke}const nt=Ne;for(it=Ye.length;Ne<it;){const Ke=Ne+it>>1;Pe.comparePoint(Me(Ye[Ke]),0)<=0?Ne=Ke+1:it=Ke}let Ue=Ne-1;if(Ue>=nt&&Pe.endOffset===0&&Pe.endContainer===Me(Ye[Ue])&&Ue--,Ue<nt)return;const F=[];for(let Ke=nt;Ke<=Ue;Ke++)F.push(Ye[Ke].getAttribute("data-char-id"));F.length>0&&(ie.current=Date.now()+1200,(qe=(ye=me.current).onSelectionChange)==null||qe.call(ye,F))},ne=()=>{Q&&clearTimeout(Q),Q=setTimeout(A,120)};return document.addEventListener("selectionchange",ne),()=>{document.removeEventListener("selectionchange",ne),Q&&clearTimeout(Q)}},[]);const Z=b.useRef(null);b.useEffect(()=>{if(s.size!==1||Z.current===s)return;const Q=Array.from(s)[0],A=Ie(Q);if(A)Z.current=s,A.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ne=parseInt(Q.split(":")[0],10);isNaN(ne)||_e(ne)}},[s,X,Ie,_e]);const he=Q=>{var ve;const A=O.current;if(!A)return null;const ne=(ve=ee.find(Ee=>Ee.page===Q))==null?void 0:ve.leadFirstId;return ne?A.querySelector(`span[data-char-id="${ne}"]`):A.querySelector(`[data-page-section="${Q}"]`)},Ae=u==null?void 0:u.nonce,R=b.useRef(null);b.useEffect(()=>{if(!u||R.current===u.nonce)return;const Q=he(u.page);if(!Q){!L&&ee.some(A=>A.page>=u.page)&&_e(u.page);return}R.current=u.nonce,ie.current=Date.now()+800,Q.scrollIntoView({behavior:"auto",block:"start"})},[Ae,X]);const xe=b.useRef(null),Y=b.useRef([]);b.useEffect(()=>{var Pe,ot,at;if(!f||xe.current===f.nonce||f.anchor.startsWith("e="))return;const[Q,A]=f.anchor.split("~"),ne=O.current,ve=ne==null?void 0:ne.querySelector(`span[data-char-id="${Ai(Q)}"]`),Ee=parseInt(Q.split(":")[0],10);if(!ve){if(!L&&!isNaN(Ee)&&ee.some(Ye=>Ye.page>=Ee)){_e(Ee);return}A&&!isNaN(Ee)&&(xe.current=f.nonce,(Pe=he(Ee))==null||Pe.scrollIntoView({behavior:"auto",block:"start"}));return}xe.current=f.nonce,ie.current=Date.now()+800;for(const Ye of Y.current)Ye.classList.remove("guji-hl");if(Y.current=[],A){const Ye=z.get(Q),Me=z.get(A);if(Ye!==void 0&&Me!==void 0&&Me>=Ye&&Me-Ye<64)for(let Ne=Ye;Ne<=Me;Ne++){const it=ne==null?void 0:ne.querySelector(`span[data-char-id="${Ai(K[Ne])}"]`);it&&(it.classList.add("guji-hl"),Y.current.push(it))}Na(ve,ie)}else(ve.closest(".guji-reflow-paragraph")??ve).scrollIntoView({behavior:"auto",block:"start"});isNaN(Ee)||(at=(ot=me.current).onVisiblePageChange)==null||at.call(ot,Ee)},[f,ee,X,L,_e,K,z]);const[$e,ke]=b.useState(null),[Ce,Qe]=b.useState(!1),Le=b.useRef(null);b.useEffect(()=>{!f||!de||Le.current===f.nonce||ue.length===0||(Le.current=f.nonce,Qe(!1),ke({k:0,nonce:Date.now()}))},[f,de,ue]);const et=b.useRef(null);b.useEffect(()=>{var Pe,ot;if(!$e||et.current===$e.nonce)return;const Q=ue[$e.k];if(!Q)return;const A=O.current,ne=K[Q[0]],ve=A==null?void 0:A.querySelector(`span[data-char-id="${Ai(ne)}"]`),Ee=parseInt(ne.split(":")[0],10);if(!ve){!L&&!isNaN(Ee)&&_e(Ee);return}et.current=$e.nonce;for(const at of Y.current)at.classList.remove("guji-hl");Y.current=[];for(let at=Q[0];at<=Q[1];at++){const Ye=A==null?void 0:A.querySelector(`span[data-char-id="${Ai(K[at])}"]`);Ye&&(Ye.classList.add("guji-hl"),Y.current.push(Ye))}Na(ve,ie),isNaN(Ee)||(ot=(Pe=me.current).onVisiblePageChange)==null||ot.call(Pe,Ee)},[$e,ue,K,X,L,_e]);const yt=b.useMemo(()=>{if(!de||Ce||ue.length===0)return"";const Q=[];for(const[A,ne]of ue)for(let ve=A;ve<=ne;ve++)Q.push(`.guji-text-pane-content span[data-char-id="${Ai(K[ve])}"]`);return`${Q.join(",")}{background:${r.bim("mark-soft")};border-radius:2px}`},[de,Ce,ue,K]),Be=Q=>ke(A=>{const ne=ue.length;return{k:(((A==null?void 0:A.k)??0)+Q+ne)%ne,nonce:Date.now()}}),J=()=>{Qe(!0);for(const Q of Y.current)Q.classList.remove("guji-hl");Y.current=[]},we=!!p||!!g,Xe=!!p&&typeof $=="number",[Ze,De]=b.useState(null),Fe=es(Ze??$??0),dt=b.useRef(null);dt.current=Xe?Fe:null;const mt=b.useRef(()=>{});return b.useEffect(()=>{var it,nt;if(!we)return;const Q=new Map,A=new Map;(it=O.current)==null||it.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ue=>{const F=Ue.getAttribute("data-page-section");F!==null?Q.set(F,Ue):A.set(Ue.getAttribute("data-page-start"),Ue)});const ne=[],ve=[];for(const Ue of P){const F=Q.get(String(Ue.page));F&&(ne.push(F),ve.push(Ue.page))}if(ne.length===0)return;const Ee=new Map(ne.map((Ue,F)=>[Ue,F])),Pe=ne.map(()=>[]);let ot=0;(nt=O.current)==null||nt.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ue=>{const F=Ee.get(Ue.closest("[data-page-section]"));F!==void 0&&(Pe[F].push(Ue),ot++)});let at,Ye=0;const Me=()=>{var tt,Lt;if(Ye=0,Date.now()<ie.current)return;const Ue=lt=>lt.getBoundingClientRect().top;if(ne.length>1&&Ue(ne[0])===Ue(ne[ne.length-1]))return;const F=dt.current===null?120:dt.current*window.innerHeight;let ye=0,qe=ne.length-1;for(;ye<qe;){const lt=ye+qe+1>>1;Ue(ne[lt])<=F?ye=lt:qe=lt-1}const Ke=Ue(ne[0])>F;let kt=ve[ye];for(let lt=ye+1;lt<ne.length;lt++){const St=A.get(String(ve[lt]));if(!St||!ne[ye].contains(St)||Ue(St)>F)break;kt=ve[lt]}if(ot>0&&me.current.onVisibleHeadingChange){let lt=null;if(!Ke){const Pt=Pe[ye];for(let Nt=Pt.length-1;Nt>=0&&!lt;Nt--)Ue(Pt[Nt])<=F&&(lt=Pt[Nt]);for(let Nt=ye-1;Nt>=0&&!lt;Nt--)Pe[Nt].length>0&&(lt=Pe[Nt][Pe[Nt].length-1])}const St=lt?Ef(lt):null;St!==at&&(at=St,me.current.onVisibleHeadingChange(St))}(Lt=(tt=me.current).onVisiblePageChange)==null||Lt.call(tt,kt)},Ne=()=>{Ye||(Ye=requestAnimationFrame(Me))};return mt.current=()=>{Ye||(Ye=requestAnimationFrame(Me))},window.addEventListener("scroll",Ne,{passive:!0}),Ne(),()=>{window.removeEventListener("scroll",Ne),Ye&&cancelAnimationFrame(Ye),mt.current=()=>{}}},[we,ee,X]),b.useEffect(()=>{Xe&&mt.current()},[Xe,Fe]),t.jsxs("div",{ref:O,className:"guji-text-pane-content",onClick:ht,onMouseOver:Ge,onMouseLeave:te,onCopy:k,children:[G&&t.jsx("style",{children:Ds}),yt&&t.jsx("style",{children:yt}),yt&&$e&&t.jsxs("div",{className:"bim-rd-mnav bim-d-ui",role:"navigation","aria-label":q("mentions.navLabel"),children:[t.jsx("span",{children:q("mentions.navCount",{k:$e.k+1,n:ue.length})}),t.jsx("button",{type:"button",onClick:()=>Be(-1),"aria-label":q("mentions.prev"),title:q("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>Be(1),"aria-label":q("mentions.next"),title:q("mentions.next"),children:"›"}),t.jsx("button",{type:"button",onClick:J,"aria-label":q("mentions.close"),title:q("mentions.close"),children:"×"})]}),Xe&&t.jsx(Lf,{y:Fe,containerRef:O,onDrag:De,onCommit:Q=>{De(null),N==null||N(Q)}}),t.jsx("div",{className:"guji-text-reflow-view",children:P.map((Q,A)=>t.jsx(If,{pGroup:Q,first:A===0,pageBreaks:v,markOpts:le,plainBooks:ae,selected:Oe.get(Q.page)??kf,decorations:Te.get(Q.page),entityOfChar:V,entityLoader:He,convert:h,buildHref:x??ff,handlers:ce,charCount:W[A]??0,pageStarts:pe.pageStarts,figures:T,figUrl:I},`page-sec-${Q.page}`))})]})};function Na(e,i){i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"});let n=!1;const s=()=>{n=!0},o=["wheel","touchstart","keydown","mousedown"];o.forEach(a=>window.addEventListener(a,s,{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,s))},a))}const za=1800,yf=800,jf="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",kf=new Set,Qr=[],wf={before:Qr,after:Qr},vf={};function Sf(e){if(!e)return vf;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 $f(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function _f(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function Nf(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const s=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&&uh(h,p)});s.set(l,c?d:a)})}return n.current=s,s},[e,i])}function zf(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const s=new Map;e.forEach(a=>{const l=i.get(a)??parseInt(a.split(":")[0],10);let d=s.get(l);d||s.set(l,d=new Set),d.add(a)});const o=new Map;return s.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 Cf(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function Ef(e){return e.getAttribute("data-heading-anchor")}function Ai(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Ca({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 Rf(e,i){const n=Array.from(i(e.join("")));return n.length===e.length&&e.every(s=>Array.from(s).length===1)?n:e.map(s=>i(s))}function Tf({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 If=b.memo(function({pGroup:i,first:n,pageBreaks:s,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:w}){const j=b.useMemo(()=>{const N=new Map;if(!p)return N;for(const _ of i.paragraphs){const E=Rf(_.chars.map(B=>B.charData.fig?B.charData.char:B.charData.norm??B.charData.char),p);_.chars.forEach((B,T)=>N.set(B.charData.id,B.charData.fig?B.charData.char:E[T]))}return N},[i,p]),x=N=>j.get(N.id)??N.char,{t:S}=se(),v=N=>{const _=o?zc(N.mark,o):N.mark;return _?t.jsx("span",{className:"guji-text-punct","data-punct-id":N.id,children:_},N.id):null},$=N=>{var _;return(_=i.blocks)==null?void 0:_.map((E,B)=>E.before===N&&t.jsx(pf,{fig:E.fig,info:y==null?void 0:y.get(E.fig),figUrl:w,onClick:()=>u.figBlock({page:i.page,fig:E.fig,...E.box?{box:E.box}:{}})},`fig-${E.fig}-${B}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:jf,"--gtv-pc":f,"--gtv-pp":i.paragraphs.length},children:[!n&&s&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:r.bim("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:r.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:r.bim("rule")}})]}),i.paragraphs.map((N,_)=>t.jsxs(b.Fragment,{children:[$(_),t.jsxs(Tf,{heading:N.heading,children:[xf(N.chars,c).map((E,B)=>{const T=E.chars.map(({charData:M,beforePuncts:q,afterPuncts:O,start:ie},oe)=>{var U,re,be;const le=!!E.entity&&oe===0,ae=!!E.entity&&oe===E.chars.length-1,pe=le?[]:q,ee=ae?[]:O,ge=!!M.fig&&oe>0&&E.chars[oe-1].charData.fig===M.fig;let W=1;if(M.fig&&!ge)for(;((U=E.chars[oe+W])==null?void 0:U.charData.fig)===M.fig;)W++;const ze=`guji-text-char${l.has(M.id)?" is-selected":""}${M.sub?" is-sub":""}${M.lane==="solo"?" is-solo":""}${ie!=null&&ie.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[ie&&ie.blankBefore>0&&t.jsx(Ca,{n:ie.blankBefore}),pe.map(v),M.fig?t.jsx(uf,{id:M.id,fig:M.fig,info:y==null?void 0:y.get(M.fig),figUrl:w,cells:W,cont:ge,className:ze,pageStart:g.get(M.id),children:x(M)}):t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-char-id":M.id,"data-page-start":g.get(M.id),...Sf(d==null?void 0:d.get(M.id)),style:$f(d==null?void 0:d.get(M.id)),className:`guji-text-char${_f(d==null?void 0:d.get(M.id))}${l.has(M.id)?" is-selected":""}${M.sub?" is-sub":""}${M.lane==="solo"?" is-solo":""}${M.lacuna||M.pending&&M.char==="□"?" is-lacuna":""}${M.pending?" is-pending":""}${M.lacuna&&M.guess_c?" has-guess":""}${M.guess?" is-guess":""}${M.zi?" is-zi":""}${ie!=null&&ie.raised?" is-raised":""}`,"data-raised":(ie==null?void 0:ie.raised)||void 0,"data-guji-guess":M.lacuna&&M.guess_c?M.guess_c:void 0,title:((re=d==null?void 0:d.get(M.id))==null?void 0:re.title)??(M.pending?S("reader.pendingReason",{label:p?p(Se.pendingReasonLabel(M.pending)):Se.pendingReasonLabel(M.pending)}):M.lacuna?M.guess_c?S("reader.lacunaGuess",{guess:p?p(M.guess_c):M.guess_c}):S("detail.lacuna"):M.zi?S("detail.composedChar",{label:M.zi}):M.guess?S("reader.charGuess"):void 0),children:x(M)}),((be=d==null?void 0:d.get(M.id))==null?void 0:be.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(M.id).insertAfter})]}),ee.map(v)]},M.id)});if(!E.entity)return t.jsx(b.Fragment,{children:T},`r${B}`);const I=E.chars[0].beforePuncts.map(v),H=E.chars[E.chars.length-1].afterPuncts.map(v);return t.jsxs(b.Fragment,{children:[I,t.jsx(Ks,{span:E.entity,label:E.chars.map(M=>x(M.charData)).join(""),hasBrackets:!0,plain:a&&E.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>T,hoverDelayMs:250}),H]},`${E.entity.key}@${B}`)}),_===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Ca,{n:i.trailingBlank}):null]})]},N.id)),$(i.paragraphs.length)]})});function es(e){const[i,n]=Yi,s=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,s))*1e3)/1e3}const Mf=.02,xi=16,Af=4;function Lf({y:e,containerRef:i,onDrag:n,onCommit:s}){const{t:o}=se(),[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-Af))},[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 w of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])w&&(g==null||g.observe(w));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>es(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(Yi[0]*100),"aria-valuemax":Math.round(Yi[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:r.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{}s(h(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,s(m.current))},onKeyDown:u=>{const f=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;f&&(u.preventDefault(),s(es(e+f*(u.shiftKey?5:1)*Mf)))},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 Vc=1,Gc=6,xn={s:1,x:0,y:0},_n=(e,i,n)=>Math.min(n,Math.max(i,e));function Gs(e,i,n){const s=_n(e.s,Vc,Gc);return{s,x:_n(e.x,i*(1-s),0),y:_n(e.y,n*(1-s),0)}}function Ir(e,i,n,s,o,a){const l=_n(e.s*s,Vc,Gc),d=l/e.s;return Gs({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function Pf(e,i,n,s,o){return Gs({s:e.s,x:e.x+i,y:e.y+n},s,o)}function Of(e,i,n){const s=i===1?e*16:i===2?e*400:e;return Math.exp(-s*(n?.01:.0015))}const Ea=4,Ff=b.forwardRef(function({children:i,onScaleChange:n,resetKey:s,style:o},a){const l=b.useRef(null),[d,c]=b.useState(xn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var v;const S=m.current;m.current=x,c(x),x.s!==S.s&&((v=p.current)==null||v.call(p,x.s))},u=()=>{var S;const x=(S=l.current)==null?void 0:S.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:S,h:v}=u();h(Ir(m.current,S/2,v/2,x,S,v))},reset(){h(xn)}})),b.useEffect(()=>{h(xn)},[s]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const S=new ResizeObserver(()=>{const{w:v,h:$}=u(),N=Gs(m.current,v,$);(N.x!==m.current.x||N.y!==m.current.y)&&h(N)});return S.observe(x),()=>S.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const S=v=>{const $=Of(v.deltaY,v.deltaMode,v.ctrlKey);if(m.current.s<=1&&$<1)return;v.preventDefault();const{w:N,h:_,left:E,top:B}=u();h(Ir(m.current,v.clientX-E,v.clientY-B,$,N,_))};return x.addEventListener("wheel",S,{passive:!1}),()=>x.removeEventListener("wheel",S)},[]);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 S=g.current;if(S.swallowClick=!1,f.current.size===1&&(S.moved=0,S.dragging=!1),f.current.size===2){const[v,$]=[...f.current.values()];S.pinchDist=Math.hypot(v.x-$.x,v.y-$.y),S.moved=Ea+1}},w=x=>{var H;const S=f.current.get(x.pointerId);if(!S)return;const v={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,v);const $=g.current,{w:N,h:_,left:E,top:B}=u();if(f.current.size>=2){const[M,q]=[...f.current.values()],O=Math.hypot(M.x-q.x,M.y-q.y);if($.pinchDist>0&&O>0){const ie=(M.x+q.x)/2-E,oe=(M.y+q.y)/2-B;h(Ir(m.current,ie,oe,O/$.pinchDist,N,_))}$.pinchDist=O,$.swallowClick=!0;return}const T=v.x-S.x,I=v.y-S.y;if($.moved+=Math.abs(T)+Math.abs(I),!($.moved<=Ea)){if(!$.dragging){$.dragging=!0;try{(H=l.current)==null||H.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(Pf(m.current,T,I,N,_))}},j=x=>{f.current.delete(x.pointerId);const S=g.current;S.pinchDist=0,f.current.size===0&&(S.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:w,onPointerUp:j,onPointerCancel:j,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(xn),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 qc(e,i,n,s,o=""){const a=`${o}
|
|
1540
|
+
`)},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"?(s(),n+=d,s()):n+=d;return}const c=vf.has(l.tagName);c&&s(),l.childNodes.forEach(o),c&&s();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const $f=e=>`/item/${encodeURIComponent(e)}`;function _f(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 Nf(e,i){const n=[];for(const s of e){const o=i.get(s.charData.id)??null,a=n[n.length-1];a&&a.entity===o?a.chars.push(s):n.push({entity:o,chars:[s]})}return n}const qs=({pageData:e,pages:i,punctuations:n=ts,selectedCharIds:s,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:w,loadEntitySummary:j,buildEntityHref:x,onEntityNavigate:v,pageBreaks:S=!0,pageIndicatorY:$,onPageIndicatorYChange:N,quoteStyle:z,bookTitleStyle:R,showWorks:O,figures:C,figUrl:I,onFigureBlockClick:D,decorations:A})=>{var pt,We,ft;const{t:X}=se(),B=b.useRef(null),ae=b.useRef(0),te=b.useMemo(()=>{const Z=new Map;return m&&n.forEach((M,ee)=>{const we=M.id?M:{...M,id:`${M.anchor}#${ee}`},Me=Z.get(we.anchor)||[];Me.push(we),Z.set(we.anchor,Me)}),Z},[n,m]),ce=b.useMemo(()=>z===void 0&&R===void 0&&O===void 0?null:{quoteStyle:z??"original",hideBookBrackets:R==="wavy"||O===!1},[z,R,O]),be=R==="bracket",oe=b.useMemo(()=>{var Ye;const Z=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],M=new Map;for(const Le of Z)for(const Ee of Le.columns)Ee.chars.length>0&&!Ee.raised&&M.set(Ee.lead_blank||0,(M.get(Ee.lead_blank||0)||0)+1);let ee=0,we=-1;for(const[Le,Ee]of M)(Ee>we||Ee===we&&Le<ee)&&(ee=Le,we=Ee);const Me=Le=>!!Le.raised||(Le.lead_blank||0)<ee,Fe=Z.filter(Le=>Le.columns.some(Ee=>Ee.chars.length>0||Ee.kind==="figure")).map(Le=>{const Ee=[...Le.columns].sort((tt,Lt)=>tt.col-Lt.col),it=[];let nt=[];const Ue=()=>{const tt=Of(te.get(nt[0].charData.id));it.push({id:`para-p${Le.page}-${it.length}`,chars:nt,...tt?{heading:{level:tt.mark.length,anchor:nt[0].charData.id,...tt.toc===!1?{toc:!1}:{}}}:{}}),nt=[]};let H=!1,ye=0,qe;const Ke=[];for(const tt of Ee){if(tt.kind==="figure"&&tt.fig){nt.length>0?Ue():it.length===0&&(H=!0),Ke.push({before:it.length,fig:tt.fig,...tt.figBox?{box:tt.figBox}:{}}),ye=0;continue}if(tt.chars.length===0){tt.kind==="blank"&&ye++;continue}const Lt=tt.raised||tt.lead_blank||ye?{raised:tt.raised,leadBlank:tt.lead_blank,blankBefore:ye}:void 0;ye=0,Me(tt)||(qe=tt.lead_blank||0);let lt=!0;for(const St of tt.chars){const Pt=te.get(St.id),{before:Nt,after:ar}=Pt?_f(Pt):Rf,nn=!!Pt&&Pt.some(ni=>ni.kind==="break"&&ni.pos!=="before");Pt&&Pt.some(ni=>ni.kind==="heading")&&(nt.length>0?Ue():it.length===0&&(H=!0)),nt.push({charData:St,col:tt.col,beforePuncts:Nt,afterPuncts:ar,...lt&&Lt?{start:Lt}:{}}),lt=!1,nn&&Ue()}}const kt=nt.length>0;return kt&&Ue(),{page:Le.page,paragraphs:it,endsOpen:kt,...qe!==void 0?{tailLead:qe}:{},...H?{leadStarts:H}:{},...Le.label?{label:Le.label}:{},...ye>0?{trailingBlank:ye}:{},...Ke.length>0?{blocks:Ke}:{}}}),ot=new Map;if(!S){let Le=null;for(const Ee of Fe){const it=Ee.paragraphs[0],nt=(Ye=it==null?void 0:it.chars[0])==null?void 0:Ye.start,Ue=(nt==null?void 0:nt.leadBlank)||0,H=!!nt&&!nt.raised&&Ue>=ee&&Ue>((Le==null?void 0:Le.tailLead)??ee),ye=!!Ee.leadStarts||!!(nt!=null&&nt.blankBefore)||H,qe=Ee.paragraphs.length===1&&!!Ee.trailingBlank;if(Le&&it&&!ye&&!qe){for(const Ke of it.chars)ot.set(Ke.charData.id,Le.owner);Le.para.chars=Le.para.chars.concat(it.chars),Ee.leadFirstId=it.chars[0].charData.id,Ee.paragraphs=Ee.paragraphs.slice(1),Ee.blocks&&(Ee.blocks=Ee.blocks.map(Ke=>({...Ke,before:Ke.before-1})))}if(Ee.endsOpen&&!Ee.trailingBlank){const Ke=Ee.paragraphs[Ee.paragraphs.length-1];Ke?Le={para:Ke,owner:Ee.page,tailLead:Ee.tailLead??(Le==null?void 0:Le.tailLead)??ee}:Le&&Ee.tailLead!==void 0&&(Le.tailLead=Ee.tailLead)}else Le=null}}const at=new Map;for(const Le of Fe)Le.leadFirstId&&at.set(Le.leadFirstId,Le.page);return{pages:Fe,mergedOwner:ot,pageStarts:at}},[i,e,te,S]),K=oe.pages,ze=b.useRef(K);ze.current=K;const F=b.useMemo(()=>K.map(Z=>Z.paragraphs.reduce((M,ee)=>M+ee.chars.length,0)),[K]),me=b.useCallback((Z,M)=>{let ee=Z,we=0;for(;ee<F.length&&(ee===Z||we+F[ee]<=M);)we+=F[ee++];return ee},[F]),U=`${K.length}:${((ft=(We=(pt=K[0])==null?void 0:pt.paragraphs[0])==null?void 0:We.chars[0])==null?void 0:ft.charData.id)??""}`,[ne,ue]=b.useState(()=>({sig:U,n:me(0,Ta)}));let G=ne.n;ne.sig!==U&&(G=me(0,Ta),ue({sig:U,n:G})),G=Math.min(G,K.length);const L=G>=K.length;b.useEffect(()=>L?void 0:(M=>{const ee=window;if(ee.requestIdleCallback){const Me=ee.requestIdleCallback(M,{timeout:300});return()=>{var Fe;return(Fe=ee.cancelIdleCallback)==null?void 0:Fe.call(ee,Me)}}const we=setTimeout(M,16);return()=>clearTimeout(we)})(()=>ue(M=>M.sig===U?{sig:M.sig,n:Math.max(M.n,me(M.n,zf))}:M)),[L,G,U,me]);const Se=b.useCallback(Z=>{const M=ze.current.findIndex(we=>we.page>=Z),ee=(M<0?ze.current.length:M)+2;ue(we=>we.n>=ee?we:{...we,n:ee})},[]),ge=L?K:K.slice(0,G);b.useEffect(()=>{let Z;const M=requestAnimationFrame(()=>{Z=setTimeout(()=>{const ee=B.current,we=ee==null?void 0:ee.querySelector(".guji-reflow-paragraph");if(!ee||!we)return;const Me=getComputedStyle(we),Fe=parseFloat(Me.fontSize),ot=we.clientWidth;if(!(Fe>0)||!(ot>0))return;const at=parseFloat(Me.lineHeight);ee.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(ot/Fe)))),ee.style.setProperty("--gtv-lh",`${Math.round(at>0?at:Fe*2)}px`)},0)});return()=>{cancelAnimationFrame(M),Z&&clearTimeout(Z)}},[U]);const $e=b.useMemo(()=>{const Z=[];for(const M of K)for(const ee of M.paragraphs)for(const we of ee.chars)Z.push(we.charData.id);return Z},[K]),_=b.useMemo(()=>new Map($e.map((Z,M)=>[Z,M])),[$e]),P=b.useMemo(()=>{const Z=new Map;if(!y||y.length===0)return Z;const M=_;for(const ee of y){if(!ee.anchor)continue;const we=M.get(ee.anchor.start),Me=M.get(ee.anchor.end);if(!(we===void 0||Me===void 0||Me<we))for(let Fe=we;Fe<=Me;Fe++)Z.has($e[Fe])||Z.set($e[Fe],ee)}return Z},[y,$e,_]),ie=b.useMemo(()=>{const Z=f==null?void 0:f.anchor;return Z&&Z.startsWith("e=")?new Set(Z.slice(2).split(",").filter(Boolean)):null},[f==null?void 0:f.anchor]),re=b.useMemo(()=>{var we;if(!ie||!y)return[];const Z=new Set,M=[],ee=(Me,Fe)=>{const ot=`${Me}:${Fe}`;Z.has(ot)||(Z.add(ot),M.push([Me,Fe]))};for(const Me of y){if(!Me.anchor)continue;const Fe=_.get(Me.anchor.start),ot=_.get(Me.anchor.end);if(!(Fe===void 0||ot===void 0||ot<Fe)){(Me.targetId&&ie.has(Me.targetId)||(we=Me.targets)!=null&&we.some(at=>ie.has(at.id)))&&ee(Fe,ot);for(const at of Me.parts??[]){if(!ie.has(at.id))continue;const Ye=Fe+at.offset[0],Le=Fe+at.offset[1]-1;Le>=Ye&&Le<=ot&&ee(Ye,Le)}}}return M.sort((Me,Fe)=>Me[0]-Fe[0]||Me[1]-Fe[1])},[ie,y,_]),Re=Ys(w,j),Y=P.size>0,de=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:v,onVisibleHeadingChange:g,onFigureBlockClick:D});de.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:v,onVisibleHeadingChange:g,onFigureBlockClick:D};const le=b.useMemo(()=>({click:Z=>{var M,ee;ae.current=Date.now()+1200,(ee=(M=de.current).onCharClick)==null||ee.call(M,Z)},enter:Z=>{var M,ee;return(ee=(M=de.current).onCharHover)==null?void 0:ee.call(M,Z)},leave:()=>{var Z,M;return(M=(Z=de.current).onCharHover)==null?void 0:M.call(Z,null)},figBlock:Z=>{var M,ee;return(ee=(M=de.current).onFigureBlockClick)==null?void 0:ee.call(M,Z)},navigate:(Z,M)=>{M.ctrlKey||M.metaKey||M.shiftKey||(M.preventDefault(),M.detail===0&&window.open(M.currentTarget.href,"_blank","noopener"))}}),[]),Te=Pf(s,oe.mergedOwner),_e=Lf(A,oe.mergedOwner),xe=b.useRef(G);xe.current=G;const Ce=b.useRef(null),Ae=b.useCallback(Z=>{const M=Ce.current,ee=M==null?void 0:M.map.get(Z);if(ee&&ee.isConnected)return ee;if(M&&M.for===ze.current&&M.n===xe.current&&!ee)return null;const we=B.current;if(!we)return null;const Me=new Map;return we.querySelectorAll("span[data-char-id]").forEach(Fe=>{Me.set(Fe.getAttribute("data-char-id"),Fe)}),Ce.current={for:ze.current,n:xe.current,map:Me},Me.get(Z)??null},[]),Je=b.useRef(null);b.useEffect(()=>{var M;if((M=Je.current)==null||M.classList.remove("is-hovered"),Je.current=null,!o)return;const Z=Ae(o);Z&&(Z.classList.add("is-hovered"),Je.current=Z)},[o,Ae]);const ut=b.useRef(null),Ve=Z=>{var ee;const M=Z instanceof Element?Z.closest("span[data-char-id]"):null;return M&&((ee=B.current)!=null&&ee.contains(M))?M.getAttribute("data-char-id"):null},ht=Z=>{const M=Ve(Z.target);M&&le.click(M)},Ge=Z=>{const M=Ve(Z.target);M!==ut.current&&(ut.current=M,M?le.enter(M):le.leave())},k=Z=>{const M=typeof window<"u"?window.getSelection():null;if(!M||M.isCollapsed||M.rangeCount===0)return;const ee=Sf(M.getRangeAt(0));ee!==null&&(Z.clipboardData.setData("text/plain",ee),Z.preventDefault())},Q=()=>{ut.current!==null&&(ut.current=null,le.leave())};b.useEffect(()=>{let Z=null;const M=()=>{var ye,qe;Z=null;const we=window.getSelection(),Me=B.current;if(!we||we.isCollapsed||we.rangeCount===0||!Me)return;const Fe=we.getRangeAt(0),ot=Fe.commonAncestorContainer,at=ot.nodeType===3?ot.parentElement:ot;if(!at||!Me.contains(at))return;const Ye=Me.querySelectorAll("span[data-char-id]"),Le=Ke=>{let kt=Ke;for(;kt.nodeType!==3&&kt.firstChild;)kt=kt.firstChild;return kt};let Ee=0,it=Ye.length;for(;Ee<it;){const Ke=Ee+it>>1;Fe.comparePoint(Le(Ye[Ke]),0)<0?Ee=Ke+1:it=Ke}const nt=Ee;for(it=Ye.length;Ee<it;){const Ke=Ee+it>>1;Fe.comparePoint(Le(Ye[Ke]),0)<=0?Ee=Ke+1:it=Ke}let Ue=Ee-1;if(Ue>=nt&&Fe.endOffset===0&&Fe.endContainer===Le(Ye[Ue])&&Ue--,Ue<nt)return;const H=[];for(let Ke=nt;Ke<=Ue;Ke++)H.push(Ye[Ke].getAttribute("data-char-id"));H.length>0&&(ae.current=Date.now()+1200,(qe=(ye=de.current).onSelectionChange)==null||qe.call(ye,H))},ee=()=>{Z&&clearTimeout(Z),Z=setTimeout(M,120)};return document.addEventListener("selectionchange",ee),()=>{document.removeEventListener("selectionchange",ee),Z&&clearTimeout(Z)}},[]);const J=b.useRef(null);b.useEffect(()=>{if(s.size!==1||J.current===s)return;const Z=Array.from(s)[0],M=Ae(Z);if(M)J.current=s,M.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ee=parseInt(Z.split(":")[0],10);isNaN(ee)||Se(ee)}},[s,G,Ae,Se]);const pe=Z=>{var we;const M=B.current;if(!M)return null;const ee=(we=K.find(Me=>Me.page===Z))==null?void 0:we.leadFirstId;return ee?M.querySelector(`span[data-char-id="${ee}"]`):M.querySelector(`[data-page-section="${Z}"]`)},Pe=u==null?void 0:u.nonce,T=b.useRef(null);b.useEffect(()=>{if(!u||T.current===u.nonce)return;const Z=pe(u.page);if(!Z){!L&&K.some(M=>M.page>=u.page)&&Se(u.page);return}T.current=u.nonce,ae.current=Date.now()+800,Z.scrollIntoView({behavior:"auto",block:"start"})},[Pe,G]);const fe=b.useRef(null),V=b.useRef([]);b.useEffect(()=>{var Fe,ot,at;if(!f||fe.current===f.nonce||f.anchor.startsWith("e="))return;const[Z,M]=f.anchor.split("~"),ee=B.current,we=ee==null?void 0:ee.querySelector(`span[data-char-id="${Ai(Z)}"]`),Me=parseInt(Z.split(":")[0],10);if(!we){if(!L&&!isNaN(Me)&&K.some(Ye=>Ye.page>=Me)){Se(Me);return}M&&!isNaN(Me)&&(fe.current=f.nonce,(Fe=pe(Me))==null||Fe.scrollIntoView({behavior:"auto",block:"start"}));return}fe.current=f.nonce,ae.current=Date.now()+800;for(const Ye of V.current)Ye.classList.remove("guji-hl");if(V.current=[],M){const Ye=_.get(Z),Le=_.get(M);if(Ye!==void 0&&Le!==void 0&&Le>=Ye&&Le-Ye<64)for(let Ee=Ye;Ee<=Le;Ee++){const it=ee==null?void 0:ee.querySelector(`span[data-char-id="${Ai($e[Ee])}"]`);it&&(it.classList.add("guji-hl"),V.current.push(it))}Ra(we,ae)}else(we.closest(".guji-reflow-paragraph")??we).scrollIntoView({behavior:"auto",block:"start"});isNaN(Me)||(at=(ot=de.current).onVisiblePageChange)==null||at.call(ot,Me)},[f,K,G,L,Se,$e,_]);const[Ne,je]=b.useState(null),[Ie,Qe]=b.useState(!1),Oe=b.useRef(null);b.useEffect(()=>{!f||!ie||Oe.current===f.nonce||re.length===0||(Oe.current=f.nonce,Qe(!1),je({k:0,nonce:Date.now()}))},[f,ie,re]);const et=b.useRef(null);b.useEffect(()=>{var Fe,ot;if(!Ne||et.current===Ne.nonce)return;const Z=re[Ne.k];if(!Z)return;const M=B.current,ee=$e[Z[0]],we=M==null?void 0:M.querySelector(`span[data-char-id="${Ai(ee)}"]`),Me=parseInt(ee.split(":")[0],10);if(!we){!L&&!isNaN(Me)&&Se(Me);return}et.current=Ne.nonce;for(const at of V.current)at.classList.remove("guji-hl");V.current=[];for(let at=Z[0];at<=Z[1];at++){const Ye=M==null?void 0:M.querySelector(`span[data-char-id="${Ai($e[at])}"]`);Ye&&(Ye.classList.add("guji-hl"),V.current.push(Ye))}Ra(we,ae),isNaN(Me)||(ot=(Fe=de.current).onVisiblePageChange)==null||ot.call(Fe,Me)},[Ne,re,$e,G,L,Se]);const yt=b.useMemo(()=>{if(!ie||Ie||re.length===0)return"";const Z=[];for(const[M,ee]of re)for(let we=M;we<=ee;we++)Z.push(`.guji-text-pane-content span[data-char-id="${Ai($e[we])}"]`);return`${Z.join(",")}{background:${r.bim("mark-soft")};border-radius:2px}`},[ie,Ie,re,$e]),He=Z=>je(M=>{const ee=re.length;return{k:(((M==null?void 0:M.k)??0)+Z+ee)%ee,nonce:Date.now()}}),q=()=>{Qe(!0);for(const Z of V.current)Z.classList.remove("guji-hl");V.current=[]},ke=!!p||!!g,Xe=!!p&&typeof $=="number",[Ze,De]=b.useState(null),Be=is(Ze??$??0),dt=b.useRef(null);dt.current=Xe?Be:null;const mt=b.useRef(()=>{});return b.useEffect(()=>{var it,nt;if(!ke)return;const Z=new Map,M=new Map;(it=B.current)==null||it.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ue=>{const H=Ue.getAttribute("data-page-section");H!==null?Z.set(H,Ue):M.set(Ue.getAttribute("data-page-start"),Ue)});const ee=[],we=[];for(const Ue of ge){const H=Z.get(String(Ue.page));H&&(ee.push(H),we.push(Ue.page))}if(ee.length===0)return;const Me=new Map(ee.map((Ue,H)=>[Ue,H])),Fe=ee.map(()=>[]);let ot=0;(nt=B.current)==null||nt.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ue=>{const H=Me.get(Ue.closest("[data-page-section]"));H!==void 0&&(Fe[H].push(Ue),ot++)});let at,Ye=0;const Le=()=>{var tt,Lt;if(Ye=0,Date.now()<ae.current)return;const Ue=lt=>lt.getBoundingClientRect().top;if(ee.length>1&&Ue(ee[0])===Ue(ee[ee.length-1]))return;const H=dt.current===null?120:dt.current*window.innerHeight;let ye=0,qe=ee.length-1;for(;ye<qe;){const lt=ye+qe+1>>1;Ue(ee[lt])<=H?ye=lt:qe=lt-1}const Ke=Ue(ee[0])>H;let kt=we[ye];for(let lt=ye+1;lt<ee.length;lt++){const St=M.get(String(we[lt]));if(!St||!ee[ye].contains(St)||Ue(St)>H)break;kt=we[lt]}if(ot>0&&de.current.onVisibleHeadingChange){let lt=null;if(!Ke){const Pt=Fe[ye];for(let Nt=Pt.length-1;Nt>=0&&!lt;Nt--)Ue(Pt[Nt])<=H&&(lt=Pt[Nt]);for(let Nt=ye-1;Nt>=0&&!lt;Nt--)Fe[Nt].length>0&&(lt=Fe[Nt][Fe[Nt].length-1])}const St=lt?Ff(lt):null;St!==at&&(at=St,de.current.onVisibleHeadingChange(St))}(Lt=(tt=de.current).onVisiblePageChange)==null||Lt.call(tt,kt)},Ee=()=>{Ye||(Ye=requestAnimationFrame(Le))};return mt.current=()=>{Ye||(Ye=requestAnimationFrame(Le))},window.addEventListener("scroll",Ee,{passive:!0}),Ee(),()=>{window.removeEventListener("scroll",Ee),Ye&&cancelAnimationFrame(Ye),mt.current=()=>{}}},[ke,K,G]),b.useEffect(()=>{Xe&&mt.current()},[Xe,Be]),t.jsxs("div",{ref:B,className:"guji-text-pane-content",onClick:ht,onMouseOver:Ge,onMouseLeave:Q,onCopy:k,children:[Y&&t.jsx("style",{children:Us}),yt&&t.jsx("style",{children:yt}),yt&&Ne&&t.jsxs("div",{className:"bim-rd-mnav bim-d-ui",role:"navigation","aria-label":X("mentions.navLabel"),children:[t.jsx("span",{children:X("mentions.navCount",{k:Ne.k+1,n:re.length})}),t.jsx("button",{type:"button",onClick:()=>He(-1),"aria-label":X("mentions.prev"),title:X("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>He(1),"aria-label":X("mentions.next"),title:X("mentions.next"),children:"›"}),t.jsx("button",{type:"button",onClick:q,"aria-label":X("mentions.close"),title:X("mentions.close"),children:"×"})]}),Xe&&t.jsx(Kf,{y:Be,containerRef:B,onDrag:De,onCommit:Z=>{De(null),N==null||N(Z)}}),t.jsx("div",{className:"guji-text-reflow-view",children:ge.map((Z,M)=>t.jsx(Df,{pGroup:Z,first:M===0,pageBreaks:S,markOpts:ce,plainBooks:be,selected:Te.get(Z.page)??Ef,decorations:_e.get(Z.page),entityOfChar:P,entityLoader:Re,convert:h,buildHref:x??$f,handlers:le,charCount:F[M]??0,pageStarts:oe.pageStarts,figures:C,figUrl:I},`page-sec-${Z.page}`))})]})};function Ra(e,i){i.current=Date.now()+800,e.scrollIntoView({behavior:"instant",block:"center",inline:"center"});let n=!1;const s=()=>{n=!0},o=["wheel","touchstart","keydown","mousedown"];o.forEach(a=>window.addEventListener(a,s,{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,s))},a))}const Ta=1800,zf=800,Cf="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",Ef=new Set,ts=[],Rf={before:ts,after:ts},Tf={};function If(e){if(!e)return Tf;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 Mf(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function Af(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function Lf(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const s=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&&fh(h,p)});s.set(l,c?d:a)})}return n.current=s,s},[e,i])}function Pf(e,i){const n=b.useRef(new Map);return b.useMemo(()=>{const s=new Map;e.forEach(a=>{const l=i.get(a)??parseInt(a.split(":")[0],10);let d=s.get(l);d||s.set(l,d=new Set),d.add(a)});const o=new Map;return s.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 Of(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function Ff(e){return e.getAttribute("data-heading-anchor")}function Ai(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Ia({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 Bf(e,i){const n=Array.from(i(e.join("")));return n.length===e.length&&e.every(s=>Array.from(s).length===1)?n:e.map(s=>i(s))}function Hf({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 Df=b.memo(function({pGroup:i,first:n,pageBreaks:s,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:w}){const j=b.useMemo(()=>{const N=new Map;if(!p)return N;for(const z of i.paragraphs){const R=Bf(z.chars.map(O=>O.charData.fig?O.charData.char:O.charData.norm??O.charData.char),p);z.chars.forEach((O,C)=>N.set(O.charData.id,O.charData.fig?O.charData.char:R[C]))}return N},[i,p]),x=N=>j.get(N.id)??N.char,{t:v}=se(),S=N=>{const z=o?Tc(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((R,O)=>R.before===N&&t.jsx(wf,{fig:R.fig,info:y==null?void 0:y.get(R.fig),figUrl:w,onClick:()=>u.figBlock({page:i.page,fig:R.fig,...R.box?{box:R.box}:{}})},`fig-${R.fig}-${O}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:Cf,"--gtv-pc":f,"--gtv-pp":i.paragraphs.length},children:[!n&&s&&t.jsxs("div",{className:"guji-page-divider",style:{display:"flex",alignItems:"center",margin:"2rem 0 1.2rem",color:r.bim("meta-fg"),fontSize:"0.82rem",letterSpacing:"0.08em",userSelect:"none"},children:[t.jsx("div",{style:{flex:1,height:"1px",background:r.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:r.bim("rule")}})]}),i.paragraphs.map((N,z)=>t.jsxs(b.Fragment,{children:[$(z),t.jsxs(Hf,{heading:N.heading,children:[Nf(N.chars,c).map((R,O)=>{const C=R.chars.map(({charData:A,beforePuncts:X,afterPuncts:B,start:ae},te)=>{var U,ne,ue;const ce=!!R.entity&&te===0,be=!!R.entity&&te===R.chars.length-1,oe=ce?[]:X,K=be?[]:B,ze=!!A.fig&&te>0&&R.chars[te-1].charData.fig===A.fig;let F=1;if(A.fig&&!ze)for(;((U=R.chars[te+F])==null?void 0:U.charData.fig)===A.fig;)F++;const me=`guji-text-char${l.has(A.id)?" is-selected":""}${A.sub?" is-sub":""}${A.lane==="solo"?" is-solo":""}${ae!=null&&ae.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[ae&&ae.blankBefore>0&&t.jsx(Ia,{n:ae.blankBefore}),oe.map(S),A.fig?t.jsx(kf,{id:A.id,fig:A.fig,info:y==null?void 0:y.get(A.fig),figUrl:w,cells:F,cont:ze,className:me,pageStart:g.get(A.id),children:x(A)}):t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-char-id":A.id,"data-page-start":g.get(A.id),...If(d==null?void 0:d.get(A.id)),style:Mf(d==null?void 0:d.get(A.id)),className:`guji-text-char${Af(d==null?void 0:d.get(A.id))}${l.has(A.id)?" is-selected":""}${A.sub?" is-sub":""}${A.lane==="solo"?" is-solo":""}${A.lacuna||A.pending&&A.char==="□"?" is-lacuna":""}${A.pending?" is-pending":""}${A.lacuna&&A.guess_c?" has-guess":""}${A.guess?" is-guess":""}${A.zi?" is-zi":""}${ae!=null&&ae.raised?" is-raised":""}`,"data-raised":(ae==null?void 0:ae.raised)||void 0,"data-guji-guess":A.lacuna&&A.guess_c?A.guess_c:void 0,title:((ne=d==null?void 0:d.get(A.id))==null?void 0:ne.title)??(A.pending?v("reader.pendingReason",{label:p?p(ve.pendingReasonLabel(A.pending)):ve.pendingReasonLabel(A.pending)}):A.lacuna?A.guess_c?v("reader.lacunaGuess",{guess:p?p(A.guess_c):A.guess_c}):v("detail.lacuna"):A.zi?v("detail.composedChar",{label:A.zi}):A.guess?v("reader.charGuess"):void 0),children:x(A)}),((ue=d==null?void 0:d.get(A.id))==null?void 0:ue.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(A.id).insertAfter})]}),K.map(S)]},A.id)});if(!R.entity)return t.jsx(b.Fragment,{children:C},`r${O}`);const I=R.chars[0].beforePuncts.map(S),D=R.chars[R.chars.length-1].afterPuncts.map(S);return t.jsxs(b.Fragment,{children:[I,t.jsx(Vs,{span:R.entity,label:R.chars.map(A=>x(A.charData)).join(""),hasBrackets:!0,plain:a&&R.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>C,hoverDelayMs:250}),D]},`${R.entity.key}@${O}`)}),z===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Ia,{n:i.trailingBlank}):null]})]},N.id)),$(i.paragraphs.length)]})});function is(e){const[i,n]=Yi,s=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,s))*1e3)/1e3}const Wf=.02,xi=16,Uf=4;function Kf({y:e,containerRef:i,onDrag:n,onCommit:s}){const{t:o}=se(),[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-Uf))},[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 w of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])w&&(g==null||g.observe(w));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>is(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(Yi[0]*100),"aria-valuemax":Math.round(Yi[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:r.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{}s(h(u.clientY))}},onPointerCancel:()=>{d.current&&(d.current=!1,s(m.current))},onKeyDown:u=>{const f=u.key==="ArrowUp"?-1:u.key==="ArrowDown"?1:0;f&&(u.preventDefault(),s(is(e+f*(u.shiftKey?5:1)*Wf)))},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 Jc=1,Zc=6,yn={s:1,x:0,y:0},Nn=(e,i,n)=>Math.min(n,Math.max(i,e));function Xs(e,i,n){const s=Nn(e.s,Jc,Zc);return{s,x:Nn(e.x,i*(1-s),0),y:Nn(e.y,n*(1-s),0)}}function Ar(e,i,n,s,o,a){const l=Nn(e.s*s,Jc,Zc),d=l/e.s;return Xs({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function Yf(e,i,n,s,o){return Xs({s:e.s,x:e.x+i,y:e.y+n},s,o)}function Vf(e,i,n){const s=i===1?e*16:i===2?e*400:e;return Math.exp(-s*(n?.01:.0015))}const Ma=4,Gf=b.forwardRef(function({children:i,onScaleChange:n,resetKey:s,style:o},a){const l=b.useRef(null),[d,c]=b.useState(yn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var S;const v=m.current;m.current=x,c(x),x.s!==v.s&&((S=p.current)==null||S.call(p,x.s))},u=()=>{var v;const x=(v=l.current)==null?void 0:v.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:v,h:S}=u();h(Ar(m.current,v/2,S/2,x,v,S))},reset(){h(yn)}})),b.useEffect(()=>{h(yn)},[s]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const v=new ResizeObserver(()=>{const{w:S,h:$}=u(),N=Xs(m.current,S,$);(N.x!==m.current.x||N.y!==m.current.y)&&h(N)});return v.observe(x),()=>v.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const v=S=>{const $=Vf(S.deltaY,S.deltaMode,S.ctrlKey);if(m.current.s<=1&&$<1)return;S.preventDefault();const{w:N,h:z,left:R,top:O}=u();h(Ar(m.current,S.clientX-R,S.clientY-O,$,N,z))};return x.addEventListener("wheel",v,{passive:!1}),()=>x.removeEventListener("wheel",v)},[]);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 v=g.current;if(v.swallowClick=!1,f.current.size===1&&(v.moved=0,v.dragging=!1),f.current.size===2){const[S,$]=[...f.current.values()];v.pinchDist=Math.hypot(S.x-$.x,S.y-$.y),v.moved=Ma+1}},w=x=>{var D;const v=f.current.get(x.pointerId);if(!v)return;const S={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,S);const $=g.current,{w:N,h:z,left:R,top:O}=u();if(f.current.size>=2){const[A,X]=[...f.current.values()],B=Math.hypot(A.x-X.x,A.y-X.y);if($.pinchDist>0&&B>0){const ae=(A.x+X.x)/2-R,te=(A.y+X.y)/2-O;h(Ar(m.current,ae,te,B/$.pinchDist,N,z))}$.pinchDist=B,$.swallowClick=!0;return}const C=S.x-v.x,I=S.y-v.y;if($.moved+=Math.abs(C)+Math.abs(I),!($.moved<=Ma)){if(!$.dragging){$.dragging=!0;try{(D=l.current)==null||D.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(Yf(m.current,C,I,N,z))}},j=x=>{f.current.delete(x.pointerId);const v=g.current;v.pinchDist=0,f.current.size===0&&(v.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:w,onPointerUp:j,onPointerCancel:j,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(yn),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 Qc(e,i,n,s,o=""){const a=`${o}
|
|
1541
1541
|
${s.versionKey??""}
|
|
1542
|
-
${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,s)}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,s,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
|
|
1542
|
+
${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,s)}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,s,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 qf(e,i,n,s=""){const o=`${s}
|
|
1543
1543
|
${n.versionKey??""}
|
|
1544
|
-
${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?
|
|
1545
|
-
${
|
|
1546
|
-
${
|
|
1547
|
-
${
|
|
1548
|
-
${
|
|
1549
|
-
${
|
|
1550
|
-
${
|
|
1551
|
-
${
|
|
1552
|
-
${
|
|
1553
|
-
${
|
|
1554
|
-
${Re??""}`,[Ei,mo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)mo({key:Ci,data:A,started:!1});else if(A!==Ei.data&&(mo({key:Ci,data:A,started:!!A}),A)){const C=A.pages??[];(!Ei.started||!C.some(D=>D.page===xt))&&bi(ni(A))}b.useEffect(()=>{Ue(new Set),qe.set(null)},[Re,z,qe]);const ar=Ei.key===Ci&&Ei.started,uo=!!Ie&&ts(Ie.headings).length===0,po=b.useMemo(()=>uo&&ar&&A?Xc(A.pages,A.punctuations):[],[uo,ar,A]),lr=b.useCallback(C=>{const D=ts(C.headings);return D.length>0?D:C.file===Re?po:[]},[Re,po]),gm=b.useCallback(C=>{if(Ue(new Set(C)),C.length>0){const D=C[0],fe=parseInt(D.split(":")[0],10);isNaN(fe)||bi(fe)}},[]),Dt=b.useMemo(()=>{const C=new Map;for(const D of(A==null?void 0:A.pages)??[])C.set(D.page,D);return C},[A]),Ri=nn(A),rn=b.useCallback(C=>{var st;const D=Q.images;if(!D||D.length===0)return;const fe=(st=Dt.get(C))==null?void 0:st.seq;return(fe?D.find(rt=>rt.seq===fe):void 0)??D.find(rt=>rt.pageNo===C)??D[C-1]},[Q.images,Dt]),bo=St>1.5,sn=b.useCallback((C,D=!1)=>{const fe=rn(C);return fe?C===Ri||D?fe.hiresUrl??fe.url:fe.url:C===Ri?(A==null?void 0:A.imageUrl)??"":""},[rn,A,Ri]),xm=b.useMemo(()=>sn(xt,bo),[sn,xt,bo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((C,D)=>C-D),[Dt]),ri=b.useRef(xt);ri.current=xt;const cr=b.useRef(0),dr=b.useRef({page:null,timer:null}),ym=b.useCallback(C=>{const D=dr.current;C!==D.page&&(D.timer&&(clearTimeout(D.timer),D.timer=null),D.page=null,!(C===ri.current||Date.now()<cr.current)&&(D.page=C,D.timer=setTimeout(()=>{D.timer=null,D.page=null,!(Date.now()<cr.current||ri.current===C)&&(ri.current=C,bi(C))},Kf)))},[]);b.useEffect(()=>()=>{dr.current.timer&&clearTimeout(dr.current.timer)},[]);const on=b.useCallback(C=>{var D;ri.current===C||!Dt.has(C)||(cr.current=Date.now()+1e3,ri.current=C,bi(C),(D=Dt.get(C))!=null&&D.columns.some(fe=>fe.chars.length>0)&&or(fe=>({page:C,nonce:((fe==null?void 0:fe.nonce)??0)+1})))},[Dt]),Ti=b.useCallback(C=>{const D=ri.current,fe=Wt.indexOf(D),st=Wt[fe<0?0:fe+C];st===void 0||st===D||on(st)},[Wt,on]),ho=b.useCallback(C=>{if(!C.trim().match(/^\d+$/)||Wt.length===0)return null;const fe=parseInt(C.trim(),10),st=Number.isFinite(fe)?fe:Number.MAX_SAFE_INTEGER;return Wt.reduce((rt,Ft)=>Math.abs(Ft-st)<Math.abs(rt-st)?Ft:rt,Wt[0])},[Wt]),[mr,ur]=b.useState(null),an=b.useRef(null),jm=b.useCallback(C=>{an.current=C,ur(C)},[]),fo=b.useCallback(()=>{const C=an.current;if(an.current=null,ur(null),C===null)return;const D=ho(C);D!==null&&on(D)},[ho,on]),pr=Wt.indexOf(xt),km=b.useCallback(C=>{if(C.altKey||C.ctrlKey||C.metaKey)return;const D=C.target.tagName;D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||(C.key==="ArrowLeft"||C.key==="PageUp"?(C.preventDefault(),Ti(-1)):(C.key==="ArrowRight"||C.key==="PageDown")&&(C.preventDefault(),Ti(1)))},[Ti]),go=b.useRef(null);b.useEffect(()=>{if(!A)return;const C=go.current;if(!(!C||C.offsetWidth===0))for(const D of[1,-1]){const fe=sn(xt+D);fe&&Jr(fe)}},[A,xt,sn]);const xo=b.useMemo(()=>{var Mo;if(!A)return null;if(xt===Ri)return A;const C=Dt.get(xt);if(C&&C.width>0&&C.height>0)return{page_id:`p:${xt}`,title:`第${xt}葉`,image_size:[C.width,C.height],total_warped_w:C.width,columns:[{col:1,warped_w:C.width,warped_h:C.height,offset_x:0,strips:[],chars:C.columns.flatMap(ct=>ct.chars).map(ct=>({id:ct.id,char:ct.char,slot:ct.slot,pos:ct.pos,sub:ct.sub,bbox_col:ct.bbox??[0,0,0,0]}))}],...C.columns.some(ct=>ct.kind==="figure"&&ct.figBox)?{figBlocks:C.columns.filter(ct=>ct.kind==="figure"&&ct.figBox).map(ct=>({id:ct.fig,box:ct.figBox}))}:{}};const D=(Mo=A.pages)==null?void 0:Mo.find(ct=>ct.page===xt),[fe,st]=A.image_size||[2386,3082];if(!(fe>0&&st>0))return null;const rt=rn(xt),Ft=(rt==null?void 0:rt.width)??fe,yr=(rt==null?void 0:rt.height)??st,Ro=Ft/fe,To=yr/st,Io=new Map;for(const ct of A.columns){const Mt=(ct.strips||[]).flatMap(un=>un.srcQuad.map(pn=>pn[0]));if(Mt.length===0)continue;const Ut=ct.top_y??0,jr=ct.bottom_y??Ut+ct.warped_h;Io.set(ct.col,{x0:Math.min(...Mt),x1:Math.max(...Mt),top:Ut,slotH:(jr-Ut)/21})}return{page_id:`p:${xt}`,title:`第${xt}葉`,image_size:[Ft,yr],total_warped_w:Ft,columns:D?D.columns.map(ct=>{const Mt=Io.get(ct.col)??{x0:0,x1:0,top:0,slotH:118};return{col:ct.col,warped_w:Ft,warped_h:yr,offset_x:0,strips:[],chars:ct.chars.map(Ut=>{const jr=Ut.slot??Ut.pos??0,un=(Mt.top+(jr-1)*Mt.slotH)*To,pn=(Mt.x0+Mt.x1)/2,[Am,Lm]=Ut.sub==="a"?[pn,Mt.x1]:Ut.sub==="b"?[Mt.x0,pn]:[Mt.x0,Mt.x1];return{...Ut,bbox_col:[Am*Ro,un,Lm*Ro,un+Mt.slotH*To]}})}}):[]}},[A,xt,Ri,Dt,rn]),{entryTitle:ln,authors:yo}=tg(n,s,m===void 0),[jo,br]=b.useState("text");b.useEffect(()=>{br("text")},[Re,z]);const wm=b.useMemo(()=>je?Xf(je,Xe,La(P,je),O,Le,lr):[],[je,Xe,P,O,Le,lr]),ko=fh(),wo=b.useRef(null),vo=b.useRef(null),hr=b.useMemo(()=>{const C=[];return A&&C.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ke?"bim-rd-on":""}`,"aria-pressed":Ke,title:"切换外挂现代断句标点",onClick:()=>kt(D=>!D),children:Ke?"标点":"无标点"})}}),C},[A,Ke]),vm=b.useMemo(()=>I&&I.length>0?[...hr,...I]:hr,[hr,I]),Sm=b.useMemo(()=>P&&Ie&&z?{entryId:n,versionKey:z,chapterKey:Ie.file,chapter:Ie,version:P,transport:s,viewport:ko}:null,[n,z,Ie,P,s,ko]),$m=b.useCallback(C=>{Re&&Z(Re,C)},[Re,Z]),si=xh({plugins:vm,ctx:Sm,prefs:Ne,setPrefs:le,t:q,convert:O,pages:A==null?void 0:A.pages,textRootRef:wo,shellTextRef:vo,selectedCharIds:nt,scrollToAnchor:$m});if(W==="loading")return t.jsx(Ma,{className:H,style:M,title:m??ln,label:q("reader.loading")});if(W==="missing"||!ee||!P)return t.jsx("div",{className:H,style:{...M,...Ia},children:q("reader.noText")});if(ce==="failed")return t.jsx("div",{className:H,style:{...M,...Ia},children:q("reader.tocFailed")});if(!je)return t.jsx(Ma,{className:H,style:M,title:m??ln,label:q("reader.tocLoading")});const hi=La(P,je),_m=wm,So=Ge&&Re&&Ge.chapter===Re?qs(Re,Ge.anchor):null,Nm=So&&Ie&&lr(Ie).some(C=>C.anchor===Ge.anchor)?So:Re??null,fr=ee.versions.map(C=>({key:C.key,label:Se.textVersionLabel(C),optionLabel:O(Se.textVersionLabel(C)),sourceName:Pa(C)?q("reader.originalSource"):C.source_name?O(C.source_name):void 0,license:C.license??void 0,sourceUrl:C.source_url??void 0,primary:C.key===K})),It=Gf((Eo=je.source)==null?void 0:Eo.upstream),cn=(typeof m=="string"?O(m):m)??(je.title?O(je.title):ln?O(ln):void 0),$o=P.edition_label?O(P.edition_label):void 0,gr=cn?t.jsx("a",{href:ae(n),title:q("reader.viewEntry"),onClick:d?C=>{C.metaKey||C.ctrlKey||(C.preventDefault(),d(n))}:void 0,children:cn}):void 0,zm=gr&&$o?t.jsxs(t.Fragment,{children:[gr,t.jsxs("span",{className:"bim-rd-ed",children:["·",$o]})]}):gr,Cm=yo.length>0?O(yo.slice(0,2).map(C=>`${C.dynasty?`〔${C.dynasty}〕`:""}${C.name}${` ${C.role||q("reader.defaultRole")}`}`).join("、")):void 0,xr=Ie?Qc(Ie,hi,O,Le):void 0,oi=Le&&!!(R!=null&&R.json),ai=(R==null?void 0:R.json)??null,fi=(R==null?void 0:R.md)??null,_o=oi&&!J&&Oc(ai.sections),Em=_o&&!(fi&&Ne.readingMode==="paragraph"&&Tn(fi)),Rm=oi&&_o?t.jsx(Kh,{juan:ai,view:jo,onView:br,textHasEntries:Em}):void 0,Tm=!0,dn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,mn=Pa(P),Xt=mn?q("reader.originalSource"):P.source_name?O(P.source_name):void 0,Im=(typeof p=="string"?O(p):p)??(mn?void 0:Xt??O(Se.textVersionLabel(P))),Mm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(Jl,{className:H,style:M,title:zm,subtitle:Im,byline:Cm,current:xr,pagerUnit:hi,rail:Rm,revisedAt:j,backHref:x,backLabel:S,onReportError:w?C=>w({...C,bookTitle:typeof cn=="string"?cn:void 0,entryId:n}):void 0,workLinkToggle:oi&&!J&&!!d&&!!(ai!=null&&ai.sections.some(C=>C.work_id)),toc:_m,tocCaption:q("reader.tocCaption",{n:je.chapters.length,unit:O(hi)}),tocHeader:Le&&je.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:J?q("reader.searchChaptersPlaceholder"):q("reader.searchUnitPlaceholder",{unit:O(hi)}),"aria-label":J?q("reader.searchChapters"):q("reader.searchUnit",{unit:O(hi)}),value:et,onChange:C=>yt(C.target.value)}):void 0,activeKey:Re??null,tocActiveKey:Nm,onSelect:he,images:Nn(Ie)&&ne&&!A?null:Q.images,renderImageOverlay:f,imagePanel:A||ot?"open":g,imagesLoading:at,isWarpMode:!!A,showPreserveMargins:!tt,customImagePanel:A&&xo?t.jsxs("div",{ref:go,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:km,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",outline:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 4px 6px",fontSize:12,color:r.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:[nt.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ue(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",nt.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:St<=1,onClick:()=>{var C;return(C=lt.current)==null?void 0:C.zoomBy(1/1.4)},children:"−"}),t.jsxs("span",{"data-testid":"facsimile-zoom-pct",style:{minWidth:38,textAlign:"center",fontSize:11},children:[Math.round(St*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:St>=6,onClick:()=>{var C;return(C=lt.current)==null?void 0:C.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:St===1,onClick:()=>{var C;return(C=lt.current)==null?void 0:C.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(Ff,{ref:lt,resetKey:xt,onScaleChange:Pt,style:{flex:1,minHeight:0},children:t.jsx(ya,{store:qe,children:C=>t.jsx(Hs,{imageUrl:xm,pageData:xo,selectedCharIds:nt,hoveredCharId:C,decorations:si.decorations,preserveMargins:Lt,renderScale:St,selectedFigBlock:F,onFigBlockClick:D=>ye(D),onCharClick:D=>{ye(null),Ue(st=>{const rt=new Set(st);return rt.has(D)?rt.delete(D):(rt.clear(),rt.add(D)),rt});const fe=document.querySelector(`[data-char-id="${D}"]`);fe&&fe.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:qe.set})})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":q("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:r.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:pr<=0,onClick:()=>Ti(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":xt,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:r.bim("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":q("reader.facsimilePageInput"),size:Math.max(2,String(mr??xt).length),value:mr??String(xt),onFocus:C=>C.currentTarget.select(),onChange:C=>jm(C.target.value),onKeyDown:C=>{C.key==="Enter"?(C.preventDefault(),fo()):C.key==="Escape"&&(an.current=null,ur(null)),C.stopPropagation()},onBlur:fo,style:{width:`${Math.max(2,String(mr??xt).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${r.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:pr<0||pr>=Wt.length-1,onClick:()=>Ti(1),children:"›"})]})]}):void 0,pluginSettings:si.settings,pluginToolbar:si.toolbar,pluginOverlay:si.overlay,textRootRef:vo,prefs:Ne,onPrefsChange:le,versions:fr.length>1?fr:void 0,currentVersionKey:fr.length>1?P.key:void 0,onVersionChange:ut,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Tn(fi),allowVertical:y,origScriptAvailable:Mm,contentLoading:Ce,children:[(Ce||ne&&!A&&!oi&&dn==null)&&t.jsx(Hl,{}),!Ce&&A&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:wo,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:Ie!=null&&Ie.title?O(Ie.title):xr}),(Xt||P.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,P.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),P.license]})]})]}),t.jsx(ya,{store:qe,children:C=>t.jsx(Vs,{pageData:A,pages:A.pages,punctuations:A.punctuations||Vf,selectedCharIds:nt,hoveredCharId:C,onSelectionChange:gm,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:D,fig:fe})=>{Ue(new Set),ye(fe),bi(D)},onCharClick:D=>{ye(null),Ue(st=>{const rt=new Set(st);return rt.has(D)?rt.delete(D):(rt.clear(),rt.add(D)),rt});const fe=parseInt(D.split(":")[0],10);isNaN(fe)||bi(fe),si.onCellClick(D)},onCharHover:D=>{qe.set(D),si.onCellHover(D)},decorations:si.decorations,mode:"horizontal",showPunctuation:Ke,entities:it,entityTransport:s,onEntityNavigate:T,onVisiblePageChange:ym,convert:O,scrollToPage:Nt,scrollToAnchor:Ve&&Ve.chapter===Re&&ar?Ve:null,onVisibleHeadingChange:D=>k(D&&Re?{chapter:Re,anchor:D}:null),pageBreaks:Ne.pageBreaks,pageIndicatorY:Ne.pageIndicatorY,onPageIndicatorYChange:D=>le({pageIndicatorY:D}),quoteStyle:Ne.quoteStyle,bookTitleStyle:Ne.bookTitleStyle,showWorks:Ne.showWorks})})]}),!Ce&&!A&&oi&&ai&&t.jsx(Wh,{juan:ai,rawText:fi,positionLabel:Qf(Ie,je,hi,O),groupLabel:eg(je,Re??null),index:qf(n,je),searchQuery:et,onNavigate:d,transport:s,workLabelCache:Ze,prefs:Ne,view:jo,onViewChange:br},`${z}/${Re}`),!Ce&&!A&&!oi&&dn!=null&&Ie&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:Ie.title?O(Ie.title):xr}),(Xt||P.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[mn&&Xt&&t.jsx(t.Fragment,{children:Xt}),!mn&&P.source_name&&t.jsxs(t.Fragment,{children:[q("reader.textSource")," ",P.source_url?t.jsx("a",{className:"bim-rd-link",href:P.source_url,target:"_blank",rel:"noreferrer",children:O(P.source_name)}):O(P.source_name)]}),Xt&&P.license&&t.jsx("span",{className:"bim-rd-dot"}),P.license]}),It&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[q("reader.upstream")," ",It.url?t.jsx("a",{className:"bim-rd-link",href:It.url,target:"_blank",rel:"noreferrer",children:O(It.name??It.url)}):O(It.name??""),It.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),It.license_url?t.jsx("a",{className:"bim-rd-link",href:It.license_url,target:"_blank",rel:"noreferrer",children:It.license}):It.license]}),It.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(Dl,{text:It.note,convert:O})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Is,{text:dn,mode:Ne.readingMode,tables:Tm,gujiMarkdown:!0,bookMarking:Ts(Ne),quoteStyle:Ne.quoteStyle})})]}),!Ce&&!ne&&!A&&!oi&&dn==null&&Ie&&t.jsx("div",{className:"bim-rd-state",children:q("reader.chapterFailed")}),!Ce&&je.references&&je.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:q("reader.references")}),t.jsx("ol",{children:je.references.map((C,D)=>t.jsxs("li",{children:[C.url?t.jsx("a",{className:"bim-rd-link",href:C.url,target:"_blank",rel:"noopener noreferrer",children:O(C.title)}):t.jsx("span",{children:O(C.title)}),C.author&&t.jsxs("span",{children:[",",O(C.author)]}),C.note&&t.jsxs("span",{children:["。",O(C.note)]})]},D))})]})]})};function Pa(e){return e.is_original===!0||e.source==="original"}function Qf(e,i,n,s){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 s(o?`${o}冊`:`${n}${e.n}`)}function eg(e,i){if(!i)return;const n=s=>{var o;for(const a of s??[]){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 tg(e,i,n){const[s,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]),s}const ig=({pageData:e,rawImageUrl:i="",punctuations:n=[],title:s,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),w=b.useRef(null),j=b.useCallback($=>{m(new Set($))},[]),x=b.useCallback($=>{if(m(N=>{const _=new Set(N);return _.has($)?_.delete($):(_.clear(),_.add($)),_}),w.current){const N=w.current.querySelector(`[data-char-id="${$}"]`);N&&N.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),S=()=>{var $;m(new Set),window.getSelection&&(($=window.getSelection())==null||$.removeAllRanges())},v=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:s||e.title}),o&&t.jsx("span",{style:{fontSize:"0.85rem",color:r.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:r.bim("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:r.bim("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:S,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(Hs,{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:w,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(Vs,{pageData:e,punctuations:v,selectedCharIds:c,hoveredCharId:p,onSelectionChange:j,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},ng=({data:e,onNavigate:i,className:n,style:s})=>{var p;const{t:o,convert:a}=se(),[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:s,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:r.bim("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:r.bim("desc-fg"),display:"flex",gap:"16px"},children:[e.total_volumes!=null&&t.jsxs("span",{children:[o("catalog.totalVolumes")," ",t.jsx("strong",{children:e.total_volumes})," ",o("unit.juan")]}),e.stats.zhulu!=null&&t.jsxs("span",{children:[o("catalogPage.zhulu")," ",t.jsx("strong",{children:e.stats.zhulu})," ",o("unit.bu")]}),e.stats.cunmu!=null&&t.jsxs("span",{children:[o("catalogPage.cunmu")," ",t.jsx("strong",{children:e.stats.cunmu})," ",o("unit.bu")]}),e.stats.categories!=null&&t.jsx("span",{children:o("catalogPage.categoriesN",{n:e.stats.categories})})]})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:e.divisions.map(h=>t.jsx(rg,{division:h,expanded:l===h.name,onToggle:()=>d(l===h.name?null:h.name),expandedCat:c,onCatToggle:u=>m(c===u?null:u),onNavigate:i},h.name))})]})},rg=({division:e,expanded:i,onToggle:n,expandedCat:s,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=se(),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 ${r.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, ${r.bim("primary")} 6%, transparent)`:r.bim("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:r.bim("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:r.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(sg,{category:m,expanded:s===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},sg=({category:e,expanded:i,onToggle:n,onNavigate:s})=>{var m,p,h,u;const{t:o,convert:a}=se(),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?r.bim("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:r.bim("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),marginLeft:"8px",fontWeight:400},children:o("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:r.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(Oa,{label:o("catalogPage.zhulu"),books:l,onNavigate:s}),d.length>0&&t.jsx(Oa,{label:o("catalogPage.cunmu"),books:d,onNavigate:s})]})]})},Oa=({label:e,books:i,onNavigate:n})=>{const{t:s,convert:o}=se(),a=Tt(),[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:r.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:r.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 ${r.bim("link-fg")}`},children:o(m.title)}):o(m.title)}),m.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:o(m.volumes)}),m.author&&t.jsx("span",{style:{fontSize:"11px",color:r.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:r.bim("primary"),background:"transparent",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:s("catalogPage.expandAllN",{n:i.length})})]})};function Xs(e="/api/feedback",i){const n=()=>typeof e=="function"?e():e,s=(...o)=>((i==null?void 0:i.fetch)??fetch)(...o);return{async listFeedback(o){try{const l=await(await s(`${n()}?resourceId=${encodeURIComponent(o)}`)).json();return l!=null&&l.success&&Array.isArray(l.items)?l.items:[]}catch{return[]}},async submitFeedback(o){const a=await s(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 id(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const og=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],nd=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:s})=>{const{t:o}=se(),[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=S=>{S.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const w=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 j=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:cg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:dg,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:hg,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:o("feedback.thanks")}),s&&t.jsx("a",{href:s,style:{fontSize:"13px",color:r.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:og.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...mg,...a===x.value?ug:{}},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:{...pg,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:m,onChange:x=>p(x.target.value),placeholder:o("feedback.contactPlaceholder"),maxLength:200,disabled:!a||h==="submitting","aria-label":o("feedback.contactLabel"),style:gg}),t.jsxs("div",{style:{fontSize:"12px",color:r.bim("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),h==="error"&&t.jsx("div",{style:fg,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!j,style:{...bg,opacity:j?1:.6,cursor:j?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},ag={position:"fixed",top:0,left:0,right:0,bottom:0,background:r.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},lg={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r.bim("shadow-dialog")},cg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},dg={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},mg={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",background:r.bim("input-bg"),color:r.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ug={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},pg={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("input-bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},bg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},hg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r.bim("success")},fg={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},gg={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},is="--bim-feedback-fab-offset",ns=48,xg=16,yg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:s=!1,zIndex:o})=>{const{t:a}=se(),[l,d]=b.useState(!1),c=i.bottom??24;return b.useEffect(()=>{if(s||typeof document>"u")return;const m=document.documentElement;return m.style.setProperty(is,`calc(${c+ns+xg}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(is)}},[s,c]),t.jsxs(t.Fragment,{children:[!s&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...jg,zIndex:o??r.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(nd,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},jg={position:"fixed",width:`${ns}px`,height:`${ns}px`,borderRadius:"50%",border:"none",background:r.bim("primary"),color:r.bim("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:r.bim("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},kg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],rd=({onSubmit:e})=>{const{t:i}=se(),[n,s]=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(""),s("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:Fa,children:t.jsxs("div",{style:_g,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:Ng,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Fa,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:kg.map(y=>t.jsxs("button",{onClick:()=>s(y.value),style:{...wg,...n===y.value?vg:{}},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:{...Sg}}),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:Cg}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:r.bim("desc-fg")},children:[o.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!g,style:{...$g,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:zg,children:p})]})},Fa={padding:"16px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",background:r.bim("input-bg")},wg={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",background:"transparent",color:r.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},vg={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},Sg={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},$g={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},_g={display:"flex",alignItems:"center",gap:"12px",color:r.bim("success"),fontSize:"14px"},Ng={background:"none",border:"none",color:r.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},zg={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},Cg={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},sd={bug:{key:"bug",color:r.bim("danger")},resource:{key:"resource",color:r.bim("primary")},suggestion:{key:"suggestion",color:r.bim("primary")},other:{key:"other",color:r.bim("desc-fg")}},Eg=sd.other,od={pending:{key:"pending",color:r.bim("warning")},in_progress:{key:"in_progress",color:r.bim("primary")},resolved:{key:"resolved",color:r.bim("success")},wontfix:{key:"wontfix",color:r.bim("desc-fg")},duplicate:{key:"duplicate",color:r.bim("desc-fg")}},Rg=od.pending;function Tg(e){try{const i=new Date(e),n=s=>String(s).padStart(2,"0");return`${i.getFullYear()}-${n(i.getMonth()+1)}-${n(i.getDate())} ${n(i.getHours())}:${n(i.getMinutes())}`}catch{return e}}function Ig(e,i){if(!e)return!1;try{const n=new URL(e,i);if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const s=new URL(i);return n.hostname===s.hostname}catch{return!1}}const ad=({items:e,loading:i})=>{const n=Tt(),{t:s,convert:o}=se();return i?t.jsx(Hl,{}):e.length===0?t.jsx("div",{style:Mg,children:s("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=sd[a.type]||Eg,d=od[a.status]||Rg,c=typeof window<"u"&&Ig(a.pageUrl,window.location.href);return t.jsxs("div",{style:Ag,children:[t.jsxs("div",{style:Lg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ba,background:l.color},children:s(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Ba,background:d.color},children:s(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Pg,children:Tg(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Og,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Mr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Mr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Mr,children:a.pageUrl}))]}),t.jsx("div",{style:Fg,children:o(a.content)}),a.reply&&t.jsxs("div",{style:Bg,children:[t.jsx("div",{style:Hg,children:s("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},Mg={textAlign:"center",padding:"40px 0",color:r.bim("desc-fg"),fontSize:"14px"},Ag={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},Lg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ba={fontSize:"12px",color:r.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Pg={fontSize:"12px",color:r.bim("desc-fg")},Og={fontSize:"12px",marginBottom:"6px"},Mr={color:r.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${r.bim("primary")}`},Fg={fontSize:"14px",lineHeight:"1.6",color:r.bim("fg"),whiteSpace:"pre-wrap"},Bg={marginTop:"12px",padding:"10px 12px",background:r.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r.bim("fg")},Hg={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r.bim("primary")},ld=({resourceId:e,transport:i,apiUrl:n})=>{const{t:s}=se(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(s);c.current=s;const m=b.useMemo(()=>i??Xs(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(ad,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(rd,{onSubmit:h})})]})},Jn=8;async function Zn(e,i,n,s){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&&!(s!=null&&s());){const c=l++;a[c]=await n(e[c],c)}});return await Promise.all(d),a}const Dg=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function Wg(e){const i=e.search(Dg);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const cd={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,s="",o=i;if(e&&typeof i=="string"&&(i===e||i===Ug(e))){const[a,l]=Wg(i);l&&(n=encodeURI(a),o=a,s=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:r.bim("link")},children:o}),s]})},code:({children:e})=>t.jsx("code",{style:{background:r.bim("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Ug(e){try{return decodeURI(e)}catch{return e}}const Kg={...cd,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:s})=>{const{convert:o}=gt(),a=i?Kg:cd;return t.jsx("div",{className:s,style:n,children:t.jsx(Um,{remarkPlugins:[Km],components:a,children:o(e)})})},Yg=r.detail["zh-Hant"].relation,Vg=r.detail["zh-Hant"].lossStatus,Gg=r.detail["zh-Hant"].resourceKind,Qn=r.getT("zh-Hant"),Js=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function Ha(e,i=Qn){return e?Js(Yg,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function qg(e,i=Qn){return Js(Vg,e)?i(`detail.lossStatus.${e}`):e}function Xg(e,i=Qn){return Js(Gg,e)?i(`detail.resourceKind.${e}`):""}function Zs({authors:e,onNavigate:i,renderLink:n}){const{convert:s}=se(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=bs(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:["〔",s(a.dynasty),"〕"]}),a.entity_id?t.jsx(wt,{id:a.entity_id,label:s(a.name),onNavigate:i,renderLink:n,dense:!0}):s(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:s(d)})]},l)})}):null}function dd(e,i,n=Qn){var c,m;const s=us(e,i),o=s.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=s.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=s.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=s.buckets.find(p=>p.key==="text"))==null?void 0:m.items)??[],groups:o}}function md(e,i){const n=(e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name,s=jl(e,i);return s?`${n}(${s})`:n}function Qs({item:e,siblings:i,listedVolumeCounts:n}){const{t:s,convert:o}=se(),[a,l]=b.useState(!1),d=r.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(md(e,i)),p=r.resourceHref(e),h=Hn(e,s)||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:s("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?s("colorMode.color"):s("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(Ns,{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?s("detail.collapseVolumes"):s("detail.expandVolumes",{n:d.expected})})})]})}function ud({groups:e,listedVolumeCounts:i}){const{t:n,convert:s}=se();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:s(o.label)}),o.description&&t.jsx("p",{className:"bim-d-rg-d",children:s(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(Qs,{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=r.resourceHref(a),c=s(md(a,o.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?s(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 Ui=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function rs(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Ui.find(s=>i.startsWith(s.key[0])))==null?void 0:n.key}const Da=12,Jg=60,pd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,railTop:a,back:l,railLinks:d})=>{var de,ue,He;const{t:c,convert:m,messages:p}=se(),h=b.useMemo(()=>hs({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[w,j]=b.useState(""),[x,S]=b.useState(!1),v=h.length<=Jg,$=v||g||!!w||x,N=b.useMemo(()=>$?h:h.slice(0,Da),[h,$]);b.useEffect(()=>{if(!i||N.length===0)return;const G=N.filter(ce=>!u.has(ce));if(G.length===0)return;let me=!1;return Zn(G,Jn,ce=>i.getItem(ce).then(Oe=>{var je;const Te=Oe??{};return[ce,{id:ce,title:Te.title,edition:Te.edition,resources:Te.resources,publication_info:Te.publication_info,current_location:Te.current_location,provenance:Te.provenance,lineage:Te.lineage,related_books:Te.related_books,dating:Te.dating,measure_info:Te.measure_info,summary:Qg((je=Oe==null?void 0:Oe.description)==null?void 0:je.text)}]}).catch(()=>[ce,{id:ce}]),()=>me).then(ce=>{me||f(Oe=>{const Te=new Map(Oe);for(const[je,Re]of ce)Te.set(je,Re);return Te})}),()=>{me=!0}},[i,N,u]);const _=b.useMemo(()=>h.map(G=>u.get(G)??{id:G}),[h,u]),E=h.length>0&&h.every(G=>u.has(G)),B=!!i&&N.some(G=>!u.has(G)),T=v||$,I=b.useMemo(()=>wl(_,e.version_graph,{era:w,scanOnly:x,sort:T?"year":"default"}),[_,e.version_graph,w,x,T]),H=g?I.rows:I.rows.slice(0,Da),M=I.allRows.filter(G=>G.hasImage).length,q=I.allRows.reduce((G,me)=>{var ce;return G+(((ce=me.copies)==null?void 0:ce.length)??0)},0),O=b.useMemo(()=>(e._related||[]).map(G=>({...G,title:G.title??""})),[e._related]),ie=O.filter(G=>G.relation==="collected_in"),oe=b.useMemo(()=>{const G=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],me=ce=>{const Oe=G.indexOf(ce??"");return Oe<0?G.length:Oe};return O.filter(ce=>ce.relation!=="collected_in").map((ce,Oe)=>({r:ce,i:Oe})).sort((ce,Oe)=>me(ce.r.relation)-me(Oe.r.relation)||ce.i-Oe.i).map(ce=>ce.r)},[O]),le=b.useMemo(()=>{const G=us(e.resources,e.resource_groups);return[...G.mirrors.flatMap(me=>me.items.map(ce=>({r:ce,kind:m(me.label)}))),...G.buckets.flatMap(me=>me.items.map(ce=>({r:ce,kind:m(Xg(me.key,c))})))]},[e.resources,e.resource_groups,m,c]),ae=e.indexed_by||[],pe=e.emendated_by||[],ee=b.useMemo(()=>{var Ie,Je,ut,Ve,ht;const G=[],me=(Je=(Ie=e.authors)==null?void 0:Ie[0])==null?void 0:Je.dynasty;me&&G.push({label:c("workPage.fact.written"),value:m(me)});const ce=qt(e,p.unit.juan);if(ce){const Ge=((ut=e.juan_count)==null?void 0:ut.description)??((ht=(Ve=e.measures)==null?void 0:Ve.find(k=>(k==null?void 0:k.unit)==="卷"&&k.note))==null?void 0:ht.note);G.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(ce),Ge&&Ge!==ce?t.jsxs("span",{className:"bim-d-meta",children:["(",m(Ge),")"]}):null]})})}e.loss_status&&G.push({label:c("workPage.fact.loss"),value:m(qg(e.loss_status,c))}),e.authenticity==="forged"&&G.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const Oe=I.allRows.filter(Ge=>Ge.sortYear!=null),Te=Oe.length>0?Oe.reduce((Ge,k)=>Ge.sortYear<=k.sortYear?Ge:k):null;Te!=null&&Te.era.era?G.push({label:c("workPage.fact.earliest"),value:m([Te.era.era,Te.era.reign].filter(Boolean).join(" ")),title:Te.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):B&&G.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),pe.length&&G.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:pe.length})});const je=Zg(e.additional_titles);je.length&&G.push({label:c("workPage.fact.alias"),value:je.map(m).join("、")});const Re=(e.additional_works||[]).map(Ge=>m(Ge.book_title)+(Ge.n_juan!=null?` ${Ge.n_juan}${p.unit.juan}`:""));return Re.length&&G.push({label:c("workPage.fact.appendix"),value:Re.join("、")}),G},[e,m,c,p,B,I.allRows,pe.length]),W=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:E?M:0,label:c("workPage.stat.hasImage")},{value:ae.length,label:c("workPage.stat.catalogs")}],ze=fs(e),U=ze?[ze.l1,ze.l2,ze.l3,ze.l4].filter(Boolean).map(G=>m(G)):[],re=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",be=t.jsx(Ji,{title:m(e.title),byline:t.jsx(Zs,{authors:e.authors,onNavigate:n,renderLink:s}),meta:t.jsx(vt,{items:[...U,ze!=null&&ze.source?c("workPage.classifiedBy",{source:m(ze.source.split("/")[0])}):"",re]}),description:(de=e.description)!=null&&de.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(ue=e.description.sources)!=null&&ue.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(G=>({text:m(Tu(G)),href:Iu(G)})).filter(G=>G.text).map((G,me)=>t.jsxs(b.Fragment,{children:[me>0?" · ":null,G.href?t.jsx("a",{href:G.href,target:"_blank",rel:"noopener noreferrer",children:G.text}):G.text]},me))}):null]}):void 0,stats:W,facts:ee,readAction:o,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(He=e.appendix)==null?void 0:He.map((G,me)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(G.title)}),t.jsx(zi,{text:G.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},me))}),X=I.eras.length>=2?[{key:"",label:c("catalog.all")},...I.eras.map(G=>({key:G,label:`${G} ${I.allRows.filter(me=>me.era.era===G).length}`}))]:[],L=[];h.length&&L.push({id:"versions",label:c("workPage.sec.versions"),count:h.length}),ae.length&&L.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:ae.length}),ie.length&&L.push({id:"collected",label:c("workPage.sec.collected"),count:ie.length}),oe.length&&L.push({id:"related",label:c("workPage.sec.related"),count:oe.length}),le.length&&L.push({id:"resources",label:c("workPage.sec.resources"),count:le.length});const _e=h.length===0&&ae.length===0,P=t.jsxs(t.Fragment,{children:[h.length>0&&t.jsxs($t,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(vt,{items:[c("workPage.versionsTotal",{n:h.length-q}),E&&M?c("workPage.versionsWithImage",{n:M}):"",I.rows.length!==I.allRows.length?c("workPage.versionsCurrent",{n:I.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":B&&X.length===0&&h.length>1?"":void 0,children:[X.length>0&&t.jsx(Vn,{items:X,value:w,onChange:G=>{j(G),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(oc,{label:c("workPage.scanOnly"),checked:x,onChange:G=>{S(G),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(T?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&Gn(I.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:H.map(G=>{var me;return t.jsx(tx,{row:G,measure:(me=u.get(G.id))==null?void 0:me.measure_info,loaded:u.has(G.id),onNavigate:n,renderLink:s},`${G.id}:${u.has(G.id)?"r":"p"}`)})})]}),H.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(w||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx(vs,{total:I.rows.length,shown:H.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)}),I.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),ae.length>0&&t.jsx(ix,{items:ae,transport:i,onNavigate:n,renderLink:s}),_e&&t.jsx($t,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),K=(G,me)=>t.jsx(wt,{id:G,label:m(me),onNavigate:n,renderLink:s,dense:!0}),z=b.useMemo(()=>{const G=new Map;for(const me of oe){const ce=Ha(me.relation,c);G.set(ce,(G.get(ce)??0)+1)}return G.size>1?[...G.entries()].sort((me,ce)=>ce[1]-me[1]).slice(0,4).map(([me,ce])=>`${m(me)} ${ce}`).join(" · "):void 0},[oe,m,c]),V=t.jsxs(t.Fragment,{children:[t.jsx(di,{id:"collected",title:c("workPage.sec.collected"),items:ie.map(G=>K(G.id,G.title))}),t.jsx(di,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:oe.length}),sub:z,items:oe.map(G=>t.jsxs(t.Fragment,{children:[K(G.id,G.title),t.jsx("span",{className:"bim-d-meta",title:G.note?m(G.note):void 0,children:m(Ha(G.relation,c))})]}))}),t.jsx(di,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:le.map(({r:G,kind:me})=>{const ce=m((G.url?r.getDisplayNameFromUrl(G.url):void 0)||G.name),Oe=r.resourceHref(G);return t.jsxs(t.Fragment,{children:[Oe?t.jsxs("a",{href:Oe,target:"_blank",rel:"noopener noreferrer",children:[ce," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:ce}),me&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:me})]})})})]});return t.jsx(Xi,{railTop:a,back:l,nav:L,railLinks:d,main:P,card:be,side:V})};function Zg(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function ss(e,i){return i((e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name)}function Qg(e){var a;if(!e)return;const n=e.replace(/\*\*/g,"").split(/\n/)[0].trim().match(/[^。]+。?/g)??[],o=((n.length>1&&((a=n[0])!=null&&a.startsWith("《"))?n[1]:n[0])??"").trim();return o?o.length>120?`${o.slice(0,120)}…`:o:void 0}function ex({copies:e,onNavigate:i,renderLink:n}){const{t:s,convert:o}=se(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?ss(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:[s("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(wt,{id:m.id,label:m.callNumber||m.id,onNavigate:i,renderLink:n,dense:!0})]},m.id))]},l||c))]})}function tx({row:e,measure:i,loaded:n,onNavigate:s,renderLink:o}){const{t:a,convert:l}=se(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",m=e.holders[0],p=e.copies??[],h=p.length&&e.locationName?l(e.locationName):m?ss(m,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?r.resourceHref(u):void 0,g=e.images.map(y=>ss(y,l)).join("、");return t.jsxs("tr",{"data-loading":n?void 0:"",className:p.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:p.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(wt,{id:e.id,label:l(e.name),onNavigate:s,renderLink:o,dense:!0}),i?t.jsx("span",{className:"bim-d-meta",children:l(i)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}),p.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:l(e.summary)}),p.length>0&&t.jsx(ex,{copies:p,onNavigate:s,renderLink:o})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:c?a("workPage.inferredFromEdition"):void 0,children:d?l(d):n?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${h?"":" bim-d-zt-blank"}`,children:[h||(n?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),p.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&&(f?t.jsx("a",{className:"bim-d-flag",href:f,target:"_blank",rel:"noopener noreferrer",title:g,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:g,children:a("workPage.hasImage")}))})]})}function ix({items:e,transport:i,onNavigate:n,renderLink:s}){const{t:o,convert:a}=se(),[l,d]=b.useState(0),c=Math.min(l,e.length-1),m=e[c],[p,h]=b.useState(new Map);return b.useEffect(()=>{if(!i)return;const u=[...new Set(e.map(g=>g.source_bid).filter(g=>!!g))];if(u.length===0)return;let f=!1;return Promise.all(u.map(g=>i.getItem(g).then(y=>{var w,j;return[g,((j=(w=y==null?void 0:y.authors)==null?void 0:w[0])==null?void 0:j.dynasty)??""]}).catch(()=>[g,""]))).then(g=>{f||h(new Map(g.filter(([,y])=>y)))}),()=>{f=!0}},[i,e]),t.jsx($t,{id:"catalogs",title:o("workPage.sec.catalogs"),meta:t.jsx(vt,{items:[o("workPage.catalog.meta",{n:e.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:e.map((u,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(u.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:p.get(u.source_bid??"")?a(p.get(u.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...a(u.source)].slice(0,9).map((g,y)=>t.jsx("span",{children:g},y))})]})},f))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[m.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(m.title_info)}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[m.source_bid?t.jsx(wt,{id:m.source_bid,label:a(m.source),onNavigate:n,renderLink:s,dense:!0}):a(m.source),m.section?a(m.section):"",m.author_info?`${o("label.authorInfo")} ${a(m.author_info)}`:"",m.edition?`${o("label.edition")} ${a(m.edition)}`:"",m.page??""]}),m.summary&&t.jsx("p",{className:"bim-d-quote",children:At(a(m.summary),void 0,{t:o})}),m.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:At(a(m.comment),void 0,{t:o})})]}),m.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:At(a(m.additional_comment),void 0,{t:o})})]}),!m.summary&&!m.comment&&!m.additional_comment&&!m.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:o("workPage.catalog.titleOnly")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.prev",{name:a(e[c-1].source)}),onClick:()=>d(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.next",{name:a(e[c+1].source)}),onClick:()=>d(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}const bd=({graph:e,renderLink:i,className:n,style:s})=>{const{t:o,convert:a}=se();if(!e.nodes.length)return t.jsx("div",{style:{...fx,...s},className:n,children:o("lineage.emptyGraph")});const l=new Map,d=new Map;for(const f of e.edges)if(f.kind==="derive"){const g=l.get(f.target)??[];g.push(f),l.set(f.target,g)}else for(const g of[f.source,f.target]){const y=d.get(g)??[];y.push(f),d.set(g,y)}const c=new Map(e.nodes.map(f=>[f.id,f])),m=new Map,p=[];for(const f of e.nodes)if(f.group){const g=m.get(f.group)??[];g.push(f),m.set(f.group,g)}else p.push(f);const h=(f,g)=>(f.year??9999)-(g.year??9999);m.forEach(f=>f.sort(h)),p.sort(h);const u=e.groups.filter(f=>m.has(f.id));return t.jsxs("div",{className:n,style:{...rx,...s},children:[e.title&&t.jsx("div",{style:sx,children:a(e.title)}),e.description&&t.jsx("div",{style:ox,children:a(e.description)}),u.map(f=>t.jsx(Wa,{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(Wa,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},Wa=({label:e,color:i,nodes:n,incomingMap:s,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=se();return t.jsxs("div",{style:ax,children:[t.jsx("div",{style:{...lx,borderLeftColor:i??r.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(nx,{node:c,incoming:s.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},nx=({node:e,incoming:i,siblings:n,nodeMap:s,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=se();return t.jsxs("div",{style:{...cx,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?r.bim("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:dx,children:[t.jsx("span",{style:mx,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:ux,children:fl(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:px,children:[e.category&&t.jsx(Li,{children:c(e.category)}),e.status==="lost"&&t.jsx(Li,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Li,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Li,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Li,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:bx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:hx,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:Ka,children:[t.jsx("div",{style:Ya,children:d("lineage.sources")}),i.map(m=>{const p=s.get(m.source);return t.jsxs("div",{style:Va(m.confidence),children:[t.jsx("span",{style:Ga,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(Ua,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:qa,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:Ka,children:[t.jsx("div",{style:Ya,children:d("lineage.related")}),n.map(m=>{const p=m.source===e.id?m.target:m.source,h=s.get(p);return t.jsxs("div",{style:Va(m.confidence),children:[t.jsx("span",{style:Ga,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(Ua,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:qa,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Li=({children:e,tone:i="default"})=>{const s={default:{bg:r.bim("tag-bg"),fg:r.bim("fg")},warn:{bg:r.bim("warn-bg"),fg:r.bim("warn-fg")},info:{bg:r.bim("info-bg"),fg:r.bim("info-fg")}}[i];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:s.bg,color:s.fg,marginRight:"4px"},children:e})},Ua=({level:e})=>{const{t:i}=se(),s={certain:{key:"certain",color:r.bim("confidence-certain")},consensus:{key:"consensus",color:r.bim("confidence-consensus")},probable:{key:"probable",color:r.bim("confidence-probable")},disputed:{key:"disputed",color:r.bim("confidence-disputed")}}[e];return s?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${s.color}`,color:s.color,borderRadius:"8px",marginLeft:"4px"},children:i(`lineage.confidence.${s.key}`)}):null},rx={fontSize:"14px",color:r.bim("fg")},sx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},ox={fontSize:"13px",color:r.bim("muted"),marginBottom:"16px",lineHeight:1.6},ax={marginBottom:"16px"},lx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r.bim("fg")},cx={border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r.bim("bg")},dx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},mx={fontSize:"15px",fontWeight:600},ux={fontSize:"12px",color:r.bim("muted")},px={marginBottom:"6px"},bx={fontSize:"12px",color:r.bim("muted"),margin:"2px 0"},hx={fontSize:"12px",color:r.bim("muted"),fontStyle:"italic",margin:"4px 0"},Ka={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r.bim("widget-border")}`},Ya={fontSize:"11px",color:r.bim("muted"),marginBottom:"2px"},Va=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Ga={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r.bim("tag-bg"),color:r.bim("fg"),borderRadius:"3px",marginRight:"6px"},qa={fontSize:"11px",color:r.bim("muted")},fx={padding:"20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px"},hd=({selectedNodeId:e,...i})=>{const{t:n}=se(),[s,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return gx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),s==="loading"?t.jsx("div",{style:Ja,children:n("lineage.graphLoading")}):s==="missing"||!a?t.jsxs("div",{style:Ja,children:[t.jsx("div",{children:Xa(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:Xa(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(xx,{modules:a,selectedNodeId:e,...i})};function Xa(e,i){return e.split(/(\{\w+\})/).map((n,s)=>{const o=/^\{(\w+)\}$/.exec(n);return t.jsx(b.Fragment,{children:o&&o[1]in i?i[o[1]]:n},s)})}async function gx(){try{const[e,i]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let n=!1;try{await import("@xyflow/react/dist/style.css"),n=!0}catch{n=!1}return{ReactFlow:e.ReactFlow,Background:e.Background,Controls:e.Controls,Handle:e.Handle,Position:e.Position,BaseEdge:e.BaseEdge,EdgeLabelRenderer:e.EdgeLabelRenderer,getSmoothStepPath:e.getSmoothStepPath,dagre:i,cssLoaded:n}}catch{return null}}const xx=({graph:e,renderLink:i,height:n=600,className:s,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,w=b.useMemo(()=>({lineage:N=>{var ie,oe,le,ae;const _=((ie=N.data)==null?void 0:ie.stepPosition)??.85,[E,B,T]=g({sourceX:N.sourceX,sourceY:N.sourceY,sourcePosition:N.sourcePosition,targetX:N.targetX,targetY:N.targetY,targetPosition:N.targetPosition,stepPosition:_,borderRadius:5}),I=!!((oe=N.data)!=null&&oe.isSibling),H=I?B:N.targetX-18,M=I?T:N.targetY-12,q=(le=N.data)==null?void 0:le.labelStyle,O=(ae=N.data)==null?void 0:ae.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:N.id,path:E,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(${H}px,${M}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:r.bim("bg"),border:`0.5px solid ${r.bim("widget-border")}`,...O,...q},children:N.label})})]})}}),[u,f,g]),j=b.useMemo(()=>({version:N=>{const{t:_}=se(),E=N.data,B=E.kind==="hypothetical",T=E.status==="lost",I=E.isSelected,H=E.bridge,M=E.borderColor??r.bim("muted"),q=H||B?"dashed":"solid",O=H?.5:T?.6:1;return t.jsxs("div",{style:{background:H?r.bim("bg-subtle"):r.bim("bg"),border:`2px ${q} ${I?r.bim("primary"):M}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:O,boxShadow:I?r.bim("shadow-node-selected"):B||H?"none":r.bim("shadow-node")},title:H?_("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:B||!E.renderLink?E.label:E.renderLink(E.bookId,E.label)}),E.description&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:E.description}),E.yearText&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.2},children:fl(E.yearText,void 0,E.uncertain)}),T&&t.jsx("div",{style:{fontSize:9,color:r.bim("lost-fg"),marginTop:1},children:_("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=se(),{rfNodes:S,rfEdges:v}=b.useMemo(()=>yx(e,y,i,a,x),[e,y,i,a,x]);return t.jsx("div",{style:{width:"100%",height:n,...o},className:s,children:t.jsxs(d,{nodes:S,edges:v,nodeTypes:j,edgeTypes:w,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(m,{showInteractive:!1})]})})};function yx(e,i,n,s,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(j=>[j.id,j.color??r.bim("muted")]));for(const j of e.nodes)c.setNode(j.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(p.has(j.relation)||c.setEdge(j.source,j.target));i.layout(c);const h=e.nodes.map(j=>{const x=c.node(j.id),S=s?j.id===s:void 0,v={kind:j.kind,label:o(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:o(j.year_text??kx(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?m.get(j.group):void 0,renderLink:n,isSelected:S,description:o(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:v,draggable:!1,selected:S}}),u=.78,f=.06,g=new Map;for(const j of e.edges)j.kind==="derive"&&(g.has(j.source)||g.set(j.source,[]),g.get(j.source).push(j));const y=new Map;for(const[j,x]of g){if(x.length<=1)continue;const S=[...x].sort(($,N)=>{var B,T;const _=((B=c.node($.target))==null?void 0:B.y)??0,E=((T=c.node(N.target))==null?void 0:T.y)??0;return _-E}),v=S.length;S.forEach(($,N)=>{const _=(N-(v-1)/2)*f;y.set($.id,u+_)})}const w=e.edges.map(j=>jx(j,y.get(j.id),o));return{rfNodes:h,rfEdges:w}}function jx(e,i,n=s=>s??""){const s=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=wx(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:r.bim("fg")},isSibling:o,stepPosition:i},style:{stroke:a,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":s?"6 4":void 0,opacity:s?.75:1},animated:!1,markerEnd:l,markerStart:o?l:void 0,zIndex:1e3}}function kx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function wx(e){switch(e){case"certain":return r.bim("confidence-certain");case"consensus":return r.bim("lineage-edge-consensus");case"probable":return r.bim("confidence-probable");case"disputed":return r.bim("confidence-disputed");default:return r.bim("muted")}}const Ja={padding:"40px 20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px",border:`1px dashed ${r.bim("widget-border")}`,borderRadius:8,background:r.bim("bg")},eo=({graph:e,defaultMode:i="list",renderLink:n,graphHeight:s=600,selectedNodeId:o,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:m,className:p,style:h})=>{var v;const{t:u,convert:f}=se(),[g,y]=b.useState(i),w=$=>{y($),a==null||a($)},j=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&j.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const S=l?(v=c==null?void 0:c[l])==null?void 0:v.description:void 0;return t.jsxs("div",{className:p,style:h,children:[t.jsxs("div",{style:vx,children:[t.jsx("button",{onClick:()=>w("list"),style:Ar(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>w("graph"),style:Ar(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:r.bim("muted"),marginRight:4},children:u("lineage.collectionLabel")}),j.map(([$,N])=>{const _=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Ar(l===$),title:N.description?f(N.description):void 0,children:[f(N.label),_!=null?` ${_}`:""]},$)})]})]}),x&&S&&t.jsx("div",{style:{fontSize:12,color:r.bim("muted"),marginBottom:8,padding:"4px 8px",background:r.bim("bg-subtle"),borderRadius:4},children:f(S)}),g==="list"?t.jsx(bd,{graph:e,renderLink:n}):t.jsx(hd,{graph:e,renderLink:n,height:s,selectedNodeId:o})]})},vx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Ar=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${r.bim("widget-border")}`,borderRadius:4,background:e?r.bim("primary"):"transparent",color:e?r.bim("primary-fg"):r.bim("fg"),cursor:"pointer"}),Za=40,Qa=2,Sx=9,$x=new Set(["certain","consensus","probable","disputed"]);function Lr(e){if(!e)return["",""];const i=e.split(/[ ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const fd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Je,ut,Ve,ht,Ge,k,te,Z,he,Ae;const h=r.useT(),{t:u,convert:f}=se(),[g,y]=b.useState(null),[w,j]=b.useState(new Map),[x,S]=b.useState([]),[v,$]=b.useState(new Map),[N,_]=b.useState(!1),[E,B]=b.useState("flow"),[T,I]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let R=!1;return i.getItem(e.work_id).then(xe=>{!R&&xe&&xe.type==="work"&&y(xe)}).catch(()=>{}),()=>{R=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){I(null);return}let R=!1;return i.getLineageGraph(e.work_id).then(xe=>{R||I(xe&&xe.nodes.length>1?xe:null)}).catch(()=>{R||I(null)}),()=>{R=!0}},[i,e.work_id]),b.useEffect(()=>{const R=e._collections||[];if(!i||R.length===0){j(new Map);return}let xe=!1;return Promise.all(R.map(Y=>{const $e=Y.id;return i.getItem($e).then(ke=>[$e,ke]).catch(()=>[$e,null])})).then(Y=>{if(xe)return;const $e=new Map;for(const[ke,Ce]of Y)Ce&&$e.set(ke,Ce);j($e)}),()=>{xe=!0}},[i,e._collections]);const H=b.useMemo(()=>{const R=new Set([...g?hs(g):[],...au(e)]);return R.add(e.id),[...R]},[g,e.related_books,e.id]),M=H.length-1;b.useEffect(()=>{if(!i||M<=0){S([]);return}const R=H.length<=Za,xe=R?H:H.slice(0,8);let Y=!1;return Promise.all(xe.map($e=>$e===e.id?Promise.resolve({id:$e,title:e.title,edition:e.edition,year:En(e)}):i.getItem($e).then(ke=>{const Ce=ke??{};return{id:$e,title:Ce.title,edition:Ce.edition,year:ke?En(Ce):void 0}}).catch(()=>({id:$e})))).then($e=>{if(Y)return;const ke=$e.filter(Ce=>Ce.id===e.id||Ce.title||Ce.edition);R&&ke.sort((Ce,Qe)=>(Ce.year??1/0)-(Qe.year??1/0)),S(ke)}),()=>{Y=!0}},[i,H,M,e]),e.lineage;const q=b.useMemo(()=>[...Gt(e).filter(R=>R.ref_type==="book").map(R=>R.ref),...mi(e).map(R=>R.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||q.length===0){$(new Map);return}let R=!1;return Promise.all(q.map(xe=>i.getItem(xe).then(Y=>[xe,{id:xe,title:Y==null?void 0:Y.title,edition:Y==null?void 0:Y.edition}]).catch(()=>[xe,{id:xe}]))).then(xe=>{R||$(new Map(xe))}),()=>{R=!0}},[i,q]);const O=b.useMemo(()=>dd(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),ie=O.groups.reduce((R,xe)=>R+xe.rows.length+xe.mirrors.length,0),oe=O.groups.length>0&&O.groups.every(R=>R.key==="_physical"),le=qi(e),ae=Nl(e),pe=qt(e,h.unit.juan),ee=new Set((e._collections||[]).map(R=>Hi(R.vol).length).filter(R=>R>0)),ge=R=>{var $e;const xe=($e=e.base_edition)==null?void 0:$e.find(ke=>ke.book_id===R&&ke.name);if(xe!=null&&xe.name)return xe.name;const Y=v.get(R);return(Y==null?void 0:Y.edition)||(Y==null?void 0:Y.title)||""},W=b.useMemo(()=>{var et,yt;const R=[];ae&&R.push({label:u("bookPage.fact.editionType"),value:f(ae),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(et=e.publication_info)!=null&&et.details?R.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(le.era||le.reign)&&R.push({label:u("bookPage.fact.era"),value:f([le.era,le.reign].filter(Boolean).join(" ")),title:le.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),pe&&R.push({label:u("bookPage.fact.measure"),value:f(pe)});const xe=(e._collections||[]).flatMap(Be=>Hi(Be.vol));xe.length&&R.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Dn(xe,h.unit.volume),unit:h.unit.volume,n:xe.length})});const Y=Gt(e).find(Be=>Be.relation==="底本"&&Be.ref_type==="book");Y&&ge(Y.ref)&&R.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(wt,{id:Y.ref,label:f(ge(Y.ref)),onNavigate:n,renderLink:s,dense:!0})});const $e=(e.base_edition||[]).filter(Be=>Be&&Be.name);for(const Be of["底本","配補","參校"]){if(Be==="底本"&&Y&&ge(Y.ref))continue;const J=$e.filter(we=>we.role===Be);J.length&&R.push({label:f(Be),value:J.map((we,Xe)=>t.jsxs(b.Fragment,{children:[Xe>0&&"、",we.book_id?t.jsx(wt,{id:we.book_id,label:f(we.name),onNavigate:n,renderLink:s,dense:!0}):f(we.name)]},Xe))})}const ke=(e.provenance||[]).filter(Be=>Be&&Be.institution),Ce=(e.resources||[]).filter(Be=>r.getResourceTypes(Be).includes("physical"));if(ke.length){R.push({label:u("bookPage.fact.holdings"),value:ke.slice(0,2).map(we=>f(we.institution)).join("、")+(ke.length>2?u("bookPage.andMorePlaces",{n:ke.length}):"")});const Be=ke.filter(we=>we.call_number).slice(0,2).map(we=>`${f(we.institution)} ${we.call_number}`);Be.length&&R.push({label:u("bookPage.fact.callNumber"),value:Be.join(";")+(ke.filter(we=>we.call_number).length>2?"…":"")});const J=ke.flatMap(we=>we.seals||[]).filter(Boolean);J.length&&R.push({label:u("bookPage.fact.seals"),value:f(J.join("、"))})}else Ce.length&&R.push({label:u("bookPage.fact.holdings"),value:Ce.slice(0,2).map(Be=>f(Be.name)).join("、")+(Ce.length>2?u("bookPage.andMorePlaces",{n:Ce.length}):"")});const Qe=e.physical_description;if(Qe){const Be=[[u("bookPage.fact.leafStyle"),Qe.leaf_style],[u("bookPage.fact.binding"),Qe.binding],[u("bookPage.fact.dimensions"),Qe.dimensions],[u("bookPage.fact.condition"),Qe.condition]];for(const[J,we]of Be)we&&we.trim()&&R.push({label:J,value:f(we)})}(yt=e.page_count)!=null&&yt.description&&R.push({label:h.label.pageCount,value:f(e.page_count.description)});const Le=xc(e.additional_titles);return Le.length&&R.push({label:u("bookPage.fact.aliases"),value:Le.map(f).join("、")}),R},[e,f,h,u,le,ae,pe,v,n,s]),ze=f(e.title),U=e.edition?f(e.edition):void 0,re=((Je=e.dating)==null?void 0:Je.text)||"",be=t.jsx(Ji,{kind:u("bookPage.kind"),title:ze,subtitle:U,byline:t.jsx(Zs,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:s}),meta:(()=>{const R=[ae?f(ae):"",le.era?f([le.era,le.reign].filter(Boolean).join("")):"",pe?f(pe):""].filter(Boolean);return R.length?t.jsx("span",{className:"bim-d-tags",children:R.map((xe,Y)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(Y,2)}`,children:xe},Y))}):null})(),description:(ut=e.description)!=null&&ut.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:$s((Ve=e.description)==null?void 0:Ve.text)?6:void 0,facts:W,readAction:o,secondaryAction:o&&ie>0&&!oe?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),X=e._collections||[],L=(a==null?void 0:a.chapters)||[],_e=f(L[0]&&Lr(L[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),P=u("bookPage.chapterCount",{n:L.length,unit:_e}),K=!!(Gt(e).length||mi(e).length||(ht=e.appendix)!=null&&ht.length),z=[],V=u(oe?"bookPage.sec.physical":"bookPage.sec.images");(L.length||O.text.length||l)&&z.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:L.length?P:void 0}),O.groups.length&&z.push({id:"images",label:V,count:ie}),K&&z.push({id:"lineage",label:u("bookPage.sec.lineage")}),X.length&&z.push({id:"collections",label:u("section.containedIn"),count:X.length}),(Ge=e.location_history)!=null&&Ge.length&&z.push({id:"provenance",label:u("section.locationHistory")});const de=R=>(d==null?void 0:d(R))??null,ue=L[0],He=ue?de(ue.file):null,G=N?L:L.slice(0,Sx),me=(R,xe,Y)=>R?t.jsx("a",{className:Y,href:R.href??"#",onClick:R.onClick?$e=>{$e.metaKey||$e.ctrlKey||($e.preventDefault(),R.onClick())}:void 0,children:xe}):t.jsx("span",{className:Y,children:xe}),ce=t.jsxs(t.Fragment,{children:[(L.length>0||O.text.length>0||l)&&t.jsxs($t,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:L.length>0?t.jsx(vt,{items:[P,(k=a==null?void 0:a.source)!=null&&k.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!ue&&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"})]}),ue&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Lr(ue.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((ue.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),me(He,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),L.length>1&&t.jsx("ul",{className:"bim-d-chap",children:G.map(R=>{const[xe,Y]=Lr(R.title);return t.jsx("li",{children:me(de(R.file),t.jsxs(t.Fragment,{children:[xe&&t.jsx("b",{children:f(xe)}),f(Y||R.file)]}))},R.file)})}),L.length>G.length&&t.jsx(Ss,{label:u("detail.expandRest",{n:L.length-G.length,unit:_e}),onClick:()=>_(!0)}),O.text.length>0&&t.jsxs(t.Fragment,{children:[(L.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((R,xe)=>t.jsx(Qs,{item:R,siblings:O.text,listedVolumeCounts:ee},`${R.id||R.url||R.name}-${xe}`))})})]})]}),O.groups.length>0&&t.jsx($t,{id:"images",title:V,meta:t.jsx(vt,{items:[O.groups.length>1?u("bookPage.groupCount",{n:O.groups.length}):"",u("bookPage.placeCount",{n:ie})]}),children:t.jsx(ud,{groups:O.groups,listedVolumeCounts:ee})}),K&&t.jsx($t,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Gt(e).length?u("bookPage.lineageMeta"):void 0,action:T?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":E==="flow",onClick:()=>B("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":E==="graph",onClick:()=>B("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:E==="graph"&&T?t.jsx(eo,{graph:T,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(R,xe)=>t.jsx(wt,{id:R,label:f(xe),onNavigate:n,renderLink:s,dense:!0})}):t.jsx(Nx,{data:e,heading:U||ze,yearText:re,refName:ge,onNavigate:n,renderLink:s})}),X.length>0&&t.jsx($t,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:X.map((R,xe)=>{const Y=R.id,$e=Hi(R.vol),ke=w.get(Y),Ce=Eu(ke);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:Y,label:ke?f(ke.title):Y,onNavigate:n,renderLink:s,dense:!0}),$e.length>0&&t.jsx(_x,{volumes:$e,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ce?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ce>0&&u("bookPage.totalOf",{n:Ce,unit:h.unit.bu})})]},`${Y}-${xe}`)})})})}),(te=e.location_history)!=null&&te.length?t.jsx($t,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((R,xe)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(R.name||R.location||"")}),([R.start_date,R.end_date].filter(Boolean).join("—")||R.description||R.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[R.start_date,R.end_date].filter(Boolean).join("—"),R.description?f(R.description):"",R.note?f(R.note):""]})})]},xe))})}):null,z.length===0&&t.jsx($t,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),Oe=x.findIndex(R=>R.id===e.id),Te=H.length<=Za,je=Te&&Oe>=0?x.slice(Math.max(0,Oe-Qa),Oe+Qa+1):x.filter(R=>R.id!==e.id),Re=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(wt,{id:g.id,label:f(g.title),onNavigate:n,renderLink:s})}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(R=>`${R.dynasty?`〔${f(R.dynasty)}〕`:""}${f(R.name)}`),f(qt(g,h.unit.juan)),g._edition_count??((Z=g._books)==null?void 0:Z.length)?u("bookPage.editionCount",{n:g._edition_count??((he=g._books)==null?void 0:he.length)??0}):""]}),((Ae=g.description)==null?void 0:Ae.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,""))})]}),M>0&&je.length>0&&t.jsxs("div",{children:[t.jsx(di,{id:"siblings",timeline:!0,title:Te?u("bookPage.siblings"):h.relation.siblingVersions,meta:Te?u("bookPage.byEra"):u("bookPage.kindCount",{n:M}),cap:je.length,items:je.map(R=>R.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(R.edition||R.title||R.id)}):t.jsx(wt,{id:R.id,label:f(R.edition||R.title||R.id),onNavigate:n,renderLink:s,dense:!0})),metas:je.map(R=>[R.year!=null?R.year<0?u("detail.bce",{n:-R.year}):String(R.year):"",R.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:je.findIndex(R=>R.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(wt,{id:g.id,label:u("bookPage.viewAllInWork",{n:H.length}),onNavigate:n,renderLink:s,dense:!0})})]})]}),Ie=e.work_id?t.jsx(sc,{caption:h.section.belongsToWork,children:t.jsx(wt,{id:e.work_id,label:g?f(g.title):" ",onNavigate:n,renderLink:s,dense:!0})}):void 0;return t.jsx(Xi,{railTop:c,back:m,up:Ie,nav:z,railLinks:p,main:ce,card:be,side:Re})};function _x({volumes:e,unit:i}){const{t:n}=se();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Dn(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 Nx({data:e,heading:i,yearText:n,refName:s,onNavigate:o,renderLink:a}){var j;const{t:l,convert:d}=se(),c=e.lineage,m=Gt(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=mi(e),g=m.length>0||f.length>0,y=x=>x&&$x.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",w=(x,S)=>t.jsx(wt,{id:x,label:d(S||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,S)=>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-${S}`)),h.map((x,S)=>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:w(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${S}`)),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,S)=>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:w(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},S))})]}),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,S)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[w(x.book_id,s(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},S))})]})]}),(j=e.appendix)==null?void 0:j.map((x,S)=>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-${S}`)),(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 Pi=16,zx=200,Cx=16,gd=({data:e,catalog:i,transport:n,onNavigate:s,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var Te,je,Re,Ie,Je,ut,Ve,ht,Ge;const{t:m,convert:p,messages:h}=se(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[w,j]=b.useState(null),[x,S]=b.useState(""),[v,$]=b.useState(!1),N=b.useMemo(()=>_l(e,i),[e,i]),_=b.useMemo(()=>$l(e),[e]),[E,B]=b.useState(new Map),T=!!n&&N.rows.length>0&&N.rows.length<=zx,I=T&&(N.rows.length<=Pi||v),H=I&&N.rows.every(k=>!k.id||E.has(k.id)),M=k=>{var te;return rs(k?(te=E.get(k))==null?void 0:te.l1:void 0)},q=b.useMemo(()=>{const k=u.trim(),te=k?p(k):"";return N.rows.filter(Z=>{var Ae,R;if(x&&rs(Z.id?(Ae=E.get(Z.id))==null?void 0:Ae.l1:void 0)!==x)return!1;if(!te)return!0;const he=Z.id&&((R=E.get(Z.id))==null?void 0:R.title)||Z.title;return p(he).includes(te)||(Z.subItems||[]).some(xe=>p(xe).includes(te))})},[N.rows,u,x,E,p]),O=g?q:q.slice(0,Pi),ie=b.useMemo(()=>(I?N.rows:O).filter(k=>k.id&&!E.has(k.id)).map(k=>k.id),[I,N.rows,O,E]);b.useEffect(()=>{if(!n||ie.length===0)return;let k=!1;const te=ie.slice(0,Cx);return Zn(te,Jn,Z=>n.getItem(Z).then(he=>{var xe,Y;const Ae=he??{},R={title:Ae.title,edition:Ae.edition,authors:Ae.authors,measure:he?qt(he,h.unit.juan):void 0,versionCount:Ae._edition_count??((xe=Ae._books)==null?void 0:xe.length),l1:((Y=fs(Ae))==null?void 0:Y.l1)||void 0};return[Z,R]}).catch(()=>[Z,{}]),()=>k).then(Z=>{k||B(he=>{const Ae=new Map(he);for(const[R,xe]of Z)Ae.set(R,xe);return Ae})}),()=>{k=!0}},[n,ie,h.unit.juan]);const oe=(Te=(e.contained_in||[])[0])==null?void 0:Te.id;b.useEffect(()=>{if(!oe){j(null);return}if(j({id:oe}),!n)return;let k=!1;return n.getItem(oe).then(te=>{k||j({id:oe,title:te==null?void 0:te.title})}).catch(()=>{}),()=>{k=!0}},[n,oe]);const le=b.useMemo(()=>dd(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),ae=le.text.length+le.groups.reduce((k,te)=>k+te.rows.length+te.mirrors.length,0),pe=_.works,ee=new Set(N.rows.map(k=>k.id).filter(Boolean)),ge=pe.length>0&&!pe.every(k=>ee.has(k.id)),W=(()=>{const k=N.rows.map(te=>te.edition).filter(Boolean);return k.length>1&&new Set(k).size===1})(),ze=N.rows.some(k=>k.volumes.length>0||k.expected!=null),U=_.total,re=_.truncated?U:N.rows.length,be=qt(e,h.unit.juan),X=e.count,L=k=>typeof k=="number"&&Number.isFinite(k)?k:null,_e=L(X==null?void 0:X.juan)??L((je=e.juan_count)==null?void 0:je.number)??L((Ie=(Re=e.measures)==null?void 0:Re.find(k=>(k==null?void 0:k.unit)==="卷"))==null?void 0:Ie.number),P=L(X==null?void 0:X.ce)??(N.totalVolumes||null),K=[{value:re,label:m("collectionPage.stat.titles")},{value:_e??0,label:h.unit.juan},{value:P??0,label:h.unit.volume}],z=b.useMemo(()=>{var Z,he;const k=[];if((Z=e.publication_info)!=null&&Z.details&&k.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),U&&(U!==N.rows.length||_.truncated)){const Ae=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");k.push({label:Ae,value:`${U} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const te=[L(X==null?void 0:X.zhong)!=null?m("collectionPage.nZhong",{n:X.zhong}):"",L(X==null?void 0:X.han)!=null?m("collectionPage.nHan",{n:X.han}):""].filter(Boolean);return te.length&&k.push({label:m("collectionPage.fact.expected"),value:te.join(" ")}),_e==null&&be&&k.push({label:m("collectionPage.fact.measure"),value:p(be),title:(he=e.juan_count)!=null&&he.description?p(e.juan_count.description):void 0}),k},[e,U,_.truncated,N.rows.length,_e,be,X,p,m,h]),V=b.useMemo(()=>{if(!H)return[];const k=new Map;for(const Z of N.rows){const he=M(Z.id);he&&k.set(he,(k.get(he)??0)+1)}const te=Ui.filter(Z=>(k.get(Z.key)??0)>0);return te.length<2?[]:[{key:"",label:`${h.catalog.all} ${re}`},...te.map(Z=>({key:Z.key,label:`${Z.label} ${k.get(Z.key)}`}))]},[H,N.rows,E,h]),de=b.useMemo(()=>{if(!H||!N.rows.some(he=>he.volumes.length>0))return null;const k=[],te=N.rows.filter(he=>he.volumes.length>0).map(he=>({k:M(he.id)??"",from:Math.min(...he.volumes),to:Math.max(...he.volumes)})).sort((he,Ae)=>he.from-Ae.from);for(const he of te){const Ae=he.to-he.from+1,R=k[k.length-1];R&&R.key===he.k?(R.to=Math.max(R.to,he.to),R.n+=Ae):k.push({key:he.k,from:he.from,to:he.to,n:Ae})}const Z=te.reduce((he,Ae)=>Math.max(he,Ae.to),0);return k.length>1&&k.some(he=>he.key)?{segs:k,last:Z}:null},[H,N.rows,E]),ue=(Je=e.description)==null?void 0:Je.text,He=t.jsx(Ji,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(Zs,{authors:e.authors,onNavigate:s,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(ut=e.publication_info)!=null&&ut.year?p(e.publication_info.year):""]}),description:ue||(Ve=e.history)!=null&&Ve.length?t.jsxs(t.Fragment,{children:[ue&&t.jsx(zi,{text:ue,style:{fontSize:15,lineHeight:1.85}}),(ht=e.history)!=null&&ht.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((k,te)=>t.jsx("li",{children:p(k)},te))}):null]}):void 0,clampDescription:$s(ue)||(((Ge=e.history)==null?void 0:Ge.length)??0)>2?6:void 0,stats:K,facts:z,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:de&&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:de.segs.map((k,te)=>{const Z=Ui.find(he=>he.key===k.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!Z,title:Z?m("collectionPage.dist.segTitle",{section:p(Z.label),from:k.from,to:k.to}):void 0,"aria-label":Z?m("collectionPage.dist.only",{section:p(Z.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!Z&&x===k.key,style:{flexGrow:k.n,background:Z?r.bim(Z.token):r.bim("rule")},onClick:()=>{Z&&(S(x===k.key?"":k.key),y(!1))}},te)})}),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:de.last})})]})]})}),G=[];N.rows.length&&G.push({id:"titles",label:m("collectionPage.sec.titles"),count:re}),ae&&G.push({id:"resources",label:m("collectionPage.sec.resources"),count:ae}),ge&&G.push({id:"works",label:h.section.containedWorks,count:pe.length});const me=t.jsxs(t.Fragment,{children:[N.rows.length>0&&t.jsxs($t,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${re} ${h.unit.items}`,N.totalVolumes?m("collectionPage.totalVolumes",{n:N.totalVolumes,unit:h.unit.volume}):"",q.length!==re?m("collectionPage.currentN",{n:q.length,unit:h.unit.items}):""]}),action:a,children:[(N.rows.length>Pi||V.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[V.length>0&&t.jsx(Vn,{items:V,value:x,onChange:k=>{S(k),y(!1)}}),T&&N.rows.length>Pi&&!H&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>$(!0),title:m("collectionPage.loadAllTitle",{n:N.rows.length,unit:h.unit.items}),children:m(v?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),N.rows.length>Pi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:k=>{f(k.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&Gn(q.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[ze&&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((k,te)=>{var $e;const Z=k.id?E.get(k.id):void 0,he=Z!=null&&Z.title&&k.title===k.id?Z.title:k.title,Ae=((Z==null?void 0:Z.authors)||[]).find(ke=>ke&&ke.name),R=[Ae?`${Ae.dynasty?`〔${p(Ae.dynasty)}〕`:""}${p(Ae.name)}${Ae.role?` ${p(Ae.role)}`:""}`:"",Z!=null&&Z.measure?p(Z.measure):"",($e=k.subItems)!=null&&$e.length?k.subItems.map(ke=>p(ke)).join("、"):"",(Z!=null&&Z.edition||k.edition)&&!W?p((Z==null?void 0:Z.edition)||k.edition||""):""].filter(Boolean),xe=Ui.find(ke=>ke.key===M(k.id)),Y=k.volumes.length>0?m("collectionPage.volumeRange",{range:Dn(k.volumes,h.unit.volume),unit:h.unit.volume}):k.expected!=null?`${k.found??0}/${k.expected} ${h.unit.volume}`:"";return t.jsxs("tr",{children:[ze&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Y?"":" bim-d-zt-blank"}`,children:[xe&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r.bim(xe.token)}}),Y||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[k.id?t.jsx(wt,{id:k.id,label:p(he),onNavigate:s,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(he)}),R.length>0?t.jsx(vt,{items:R}):k.id&&!Z&&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${Z!=null&&Z.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Z!=null&&Z.versionCount?m("collectionPage.nZhong",{n:Z.versionCount}):""})]},`${k.id??k.title}-${te}`)})})]}),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(vs,{total:q.length,shown:O.length,unit:h.unit.items,onClick:()=>y(!0)})]}),ae>0&&t.jsxs($t,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:ae}),children:[le.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[le.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:le.text.map((k,te)=>t.jsx(Qs,{item:k,siblings:le.text},`${k.id||k.url||k.name}-${te}`))})})]}),t.jsx(ud,{groups:le.groups})]}),N.rows.length===0&&ae===0&&t.jsx($t,{title:m("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("collectionPage.empty")})})]}),ce=ge?t.jsx(di,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:pe.length}),cap:12,items:pe.map(k=>t.jsx(wt,{id:k.id,label:p(k.title),onNavigate:s,renderLink:o,dense:!0}))}):null,Oe=w?t.jsx(sc,{caption:m("collectionPage.parent"),children:t.jsx(wt,{id:w.id,label:p(w.title||w.id),onNavigate:s,renderLink:o,dense:!0})}):void 0;return t.jsx(Xi,{railTop:l,back:d,up:Oe,nav:G,railLinks:c,main:me,card:He,side:ce})},Ex=8;function xd(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function Rx(e){return(e||[]).filter(i=>{var n,s;return xd(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((s=i.license)==null?void 0:s.trim())}).slice(0,Ex)}function Tx({images:e,assetBase:i,name:n}){const{t:s,convert:o}=se(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?Rx(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+xd(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:s("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":`${s("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:[s("entityPage.imgCredit",{credit:o(h.credit)})," · ",s("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:s("entityPage.imgSource")})]}),h.note&&t.jsxs(t.Fragment,{children:[" · ",o(h.note)]})]})]})}const el=8,tl=10,il=30,yd=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function Ix(e){return`${yd(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function Mx(e,i,n){var s;return`${yd(i,n.key,n.chapter)}#e=${((s=n.ids)!=null&&s.length?n.ids:[e]).join(",")}`}const Ax=({id:e,transport:i,renderLink:n,onTotal:s})=>{const{t:o,convert:a}=se(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(el),[u,f]=b.useState(tl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),w=b.useRef(s);if(w.current=s,b.useEffect(()=>{if(d(null),m("idle"),h(el),f(tl),!y)return;const $=g.current;let N=!1;const _=()=>{m("loading"),i.getMentions(e).then(B=>{var I,H;if(N)return;const T=B&&"books"in B?B:null;if(!T||!T.total){m("none"),(I=w.current)==null||I.call(w,0);return}d(T),m("ok"),(H=w.current)==null||H.call(w,T.total)}).catch(()=>{N||m("none")})};if(!$||typeof IntersectionObserver>"u")return _(),()=>{N=!0};const E=new IntersectionObserver(B=>{B.some(T=>T.isIntersecting)&&(E.disconnect(),_())},{rootMargin:"400px"});return E.observe($),()=>{N=!0,E.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const j=($,N,_)=>n?n($,N,_):t.jsx("a",{className:_,href:$,children:N}),x=new Map(((l==null?void 0:l.books)??[]).map($=>[$.item,$.title])),S=(l==null?void 0:l.examples)??[],v=(l==null?void 0:l.books)??[];return t.jsx("div",{ref:g,children:t.jsxs($t,{id:"mentions",title:o("mentions.title"),meta:l?t.jsx(vt,{items:[o("mentions.total",{n:l.total,b:v.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&&S.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:S.slice(0,p).map(($,N)=>{const _=[x.get($.item),$.heading].filter(Boolean).map(B=>a(B)).join(" · "),E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-mention-where bim-d-ui",children:_||$.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:j(Ix($),E,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${N}`)})}),S.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(S.length),children:o("mentions.more",{n:S.length-p})})]}),l&&v.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:v.slice(0,u).map($=>t.jsx(Lx,{entityId:e,book:$,open:v.length===1,transport:i,link:j},$.item))}),v.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+il),children:o("mentions.moreBooks",{n:Math.min(il,v.length-u)})})]})]})})},Lx=({entityId:e,book:i,open:n,transport:s,link:o})=>{const{t:a,convert:l}=se(),[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||!(s!=null&&s.getMentions)||(p(!0),s.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(Mx(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}`))})]})})},Px=16,Pr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function nl(e){if(!e)return Pr.length;const i=Pr.indexOf(e);return i===-1?Pr.length:i}function Ox(e,i,n){if(i)return e[i]??n(i)}function Fx(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const Bx={秦:[-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]},jd=({data:e,transport:i,onNavigate:n,renderLink:s,railTop:o,back:a,railLinks:l,assetBase:d})=>{var Ie,Je,ut,Ve,ht,Ge;const{t:c,convert:m,messages:p}=se(),h=k=>Fx(k,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[w,j]=b.useState("default"),[x,S]=b.useState(new Map),[v,$]=b.useState(0),N=b.useMemo(()=>e._works||[],[e._works]),_=b.useMemo(()=>N.map(k=>{const te=x.get(k.work_id);return{id:k.work_id,title:(te==null?void 0:te.title)??k.title??k.work_id,role:k.role||"",cls:ps(k.role),versionCount:te==null?void 0:te.versionCount,section:te==null?void 0:te.cls,l1:te==null?void 0:te.l1,measure:te==null?void 0:te.measure,hasImage:te==null?void 0:te.hasImage,loaded:!!(te!=null&&te.loaded)}}),[N,x]),E=b.useMemo(()=>Sl(N.map(k=>k.role),c("detail.roleAll")),[N,c]),B=b.useMemo(()=>{const k=u==="全部"?_:_.filter(te=>te.cls===u);return w==="versions"?[...k].sort((te,Z)=>(Z.versionCount??-1)-(te.versionCount??-1)):k},[_,u,w]),T=g?B:B.slice(0,Px),I=b.useMemo(()=>T.filter(k=>!x.has(k.id)).map(k=>k.id),[T,x]);b.useEffect(()=>{if(!i||I.length===0)return;let k=!1;return Zn(I,Jn,te=>i.getItem(te).then(Z=>{var Y;const he=Z??{},Ae=he._edition_count??((Y=he._books)==null?void 0:Y.length)??0,R=fs(he),xe=[R==null?void 0:R.l1,R==null?void 0:R.l2].filter(Boolean).join(" ");return[te,{id:te,title:he.title,versionCount:Ae,loaded:!0,cls:xe||void 0,l1:(R==null?void 0:R.l1)||void 0,measure:Z&&qt(Z,p.unit.juan)||void 0,hasImage:!!he._has_image}]}).catch(()=>[te,{id:te,loaded:!0}]),()=>k).then(te=>{k||S(Z=>{const he=new Map(Z);for(const[Ae,R]of te)he.set(Ae,R);return he})}),()=>{k=!0}},[i,I,p.unit.juan]);const H=b.useMemo(()=>{const k=new Map;for(const te of e.alt_names||[]){const Z=te.type||p.section.aliases;k.has(Z)||k.set(Z,[]),k.get(Z).push(te.name)}return[...k.entries()].sort((te,Z)=>nl(te[0])-nl(Z[0])).map(([te,Z])=>({label:te,names:Z}))},[e.alt_names,p]),M=((Ie=e.dates)==null?void 0:Ie.birth)??void 0,q=((Je=e.dates)==null?void 0:Je.death)??void 0,O=(ut=e.dates)==null?void 0:ut.floruit,ie=M!=null||q!=null?`${h(M)||"?"}—${h(q)||"?"}`:Array.isArray(O)&&O.length===2&&O.every(k=>Number.isFinite(k))?c("entityPage.floruit",{from:h(O[0]),to:h(O[1])}):"",oe=new Set(["本名","字","號","号"]),le=H.filter(k=>oe.has(k.label)),ae=H.filter(k=>!oe.has(k.label)),pe=ae.reduce((k,te)=>k+te.names.length,0),ee=b.useMemo(()=>{const k=[];for(const Z of le)k.push({label:Z.label,value:Z.names.map(he=>m(he)).join("、")});const te=N.length;return te&&k.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:te})}),k},[N,le,m,c]),ge=k=>{var te;return(te=H.find(Z=>k.includes(Z.label)))==null?void 0:te.names[0]},W=ge(["字"]),ze=ge(["號","号"]),U=[W?c("entityPage.zi",{name:m(W)}):"",ze?c("entityPage.hao",{name:m(ze)}):""].filter(Boolean).join(","),re=e.native_place,be=e.dynasty?Bx[e.dynasty]:void 0,X=(()=>{if(!be||M==null||q==null||q<M)return null;const[k,te]=be,Z=Math.max(M,k),he=Math.min(q,te);if(he<=Z)return null;const Ae=te-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(M),death:h(q),years:q-M+1}),children:t.jsx("i",{style:{left:`${(Z-k)/Ae*100}%`,width:`${(he-Z)/Ae*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:q-M+1})}),t.jsx("span",{children:h(te)})]})]})})(),L=b.useMemo(()=>{if(!i||_.length===0||_.some(Z=>!Z.loaded))return null;const k=new Map;for(const Z of _){const he=rs(Z.l1);he&&k.set(he,(k.get(he)??0)+1)}const te=Ui.map(Z=>({...Z,n:k.get(Z.key)??0})).filter(Z=>Z.n>0);return te.length?te:null},[_,i]),_e=t.jsxs(Ji,{kind:Ox(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:U||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",ie,re?c("entityPage.nativePlace",{place:m(re)}):""]}),X,t.jsx(Tx,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(Ve=e.description)!=null&&Ve.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:$s((ht=e.description)==null?void 0:ht.text)?6:void 0,facts:ee,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[pe>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:pe})}),t.jsx("dl",{children:ae.map(k=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{children:k.names.map(te=>m(te)).join("、")})]},k.label))})]}),L&&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:L.map(k=>t.jsx("i",{style:{flexGrow:k.n,background:r.bim(k.token)}},k.key))}),t.jsx("div",{className:"bim-d-dist-key",children:L.map(k=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r.bim(k.token)}}),m(k.label)," ",k.n]},k.key))})]})]}),P=b.useMemo(()=>_.filter(k=>k.loaded&&(k.versionCount??0)>0).sort((k,te)=>(te.versionCount??0)-(k.versionCount??0)).slice(0,3),[_]),K=!!i&&_.length>=3&&T.some(k=>!k.loaded),z=u==="全部"&&(K||P.length>=2),V=e.external_ids||{},de=((Ge=e.external_ids_meta)==null?void 0:Ge.cbdb_match)??V.cbdb_match,ue=[];V.cbdb_id!=null&&ue.push({label:"CBDB",id:String(V.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${V.cbdb_id}`,note:de==="auto"?c("entityPage.autoMatch"):void 0});const He=V.wikidata_id;He&&ue.push({label:"Wikidata",id:He,href:`https://www.wikidata.org/wiki/${He}`});const G=V.viaf_id;G&&ue.push({label:"VIAF",id:G,href:`https://viaf.org/viaf/${G}`});const me=E.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),ce=e.id?t.jsx(Ax,{id:e.id,transport:i,onTotal:$}):null,Oe=[...z&&!K?[{id:"featured",label:c("entityPage.sec.featured"),count:P.length}]:[],..._.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:_.length}]:[],...v?[{id:"mentions",label:c("mentions.title"),count:v}]:[],...ue.length?[{id:"external",label:c("entityPage.sec.external"),count:ue.length}]:[]],Te=z?t.jsxs($t,{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":K||void 0,children:[K&&[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)),!K&&P.map(k=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(wt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:s,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,je=_.length===0?t.jsxs(t.Fragment,{children:[t.jsx($t,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}),ce]}):t.jsxs(t.Fragment,{children:[Te,t.jsxs($t,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:_.length}),B.length!==_.length?c("entityPage.current",{n:B.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[me.length>1&&t.jsx(Vn,{items:me,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":w==="versions",onClick:()=>{w==="default"&&y(!0),j(k=>k==="default"?"versions":"default")},children:c(w==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&Gn(B.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:T.map(k=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:s,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))})]}),T.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx(vs,{total:B.length,shown:T.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),ce]}),Re=ue.length>0?t.jsx(di,{id:"external",title:c("entityPage.sec.external"),items:ue.map(k=>t.jsxs("a",{href:k.href,target:"_blank",rel:"noopener noreferrer",children:[k.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:ue.map(k=>k.id),foot:V.cbdb_id!=null&&de==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Xi,{railTop:o,back:a,nav:Oe,railLinks:l,main:je,card:_e,side:Re})},to="(max-width: 719px)",Hx=`${to}, (pointer: coarse)`,kd=`
|
|
1544
|
+
${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?Lc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:Xf}const Xf=[],Jf=/^#{1,6}$/,Zf=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function Qf(e){let i=e.trim();const n=Zf.exec(i);return n&&(i=n[1]+n[2]),i.replace(/[《》〈〉]/g,"").trim()}const Aa=e=>e.kind==null||e.kind==="point";function ed(e,i){var d;if(!e||!i||i.length===0)return[];const n=new Map;let s=!1;for(const c of i){c.kind==="heading"&&(s=!0);const m=n.get(c.anchor);m?m.push(c):n.set(c.anchor,[c])}if(!s)return[];const o=[];let a=null;const l=()=>{a&&(a.fixed||(a.h.label=Qf(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"&&Jf.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)Aa(g)&&g.pos==="before"&&(a.text+=g.mark);a.text+=h.char;for(const g of u)Aa(g)&&g.pos!=="before"&&(a.text+=g.mark)}u.some(g=>g.kind==="break"&&g.pos!=="before")&&l()}}return l(),o}function ns(e){if(!Array.isArray(e))return[];const i=[];for(const n of e){if(!n||typeof n!="object")continue;const{level:s,label:o,anchor:a}=n;typeof s!="number"||!Number.isInteger(s)||s<1||s>6||typeof o!="string"||!o.trim()||typeof a!="string"||!a||i.push({level:s,label:o.trim(),anchor:a})}return i}function Js(e,i){return`${e}#${i}`}function td(e){const i=e.indexOf("#");return i<=0||i===e.length-1?null:{chapter:e.slice(0,i),anchor:e.slice(i+1)}}function id(e){const i=[],n=[];for(const s of e){const o={...s,children:[]};for(;n.length>0&&n[n.length-1].level>=s.level;)n.pop();n.length===0?i.push(o):n[n.length-1].children.push(o),n.push(o)}return i}function zn(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const eg=150,La="(min-width: 860px)";function tg(){const[e,i]=b.useState(()=>typeof window>"u"||!window.matchMedia?!0:window.matchMedia(La).matches);return b.useEffect(()=>{var o;if(!window.matchMedia)return;const n=window.matchMedia(La),s=()=>i(n.matches);return s(),(o=n.addEventListener)==null||o.call(n,"change",s),()=>{var a;return(a=n.removeEventListener)==null?void 0:a.call(n,"change",s)}},[]),e}const Pa={padding:24,color:r.bim("desc-fg"),fontSize:14};function Oa({title:e,label:i,className:n,style:s}){const o=(a,l=14,d=14)=>({width:a,height:l,marginTop:d,borderRadius:3,background:r.bim("rule")});return t.jsxs("div",{className:n,style:{...s,padding:"20px 24px",maxWidth:760,margin:"0 auto"},"aria-busy":"true",children:[e&&t.jsx("div",{style:{fontSize:15,color:r.bim("ink"),fontFamily:r.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:r.bim("desc-fg"),fontSize:14,fontFamily:r.bim("font-ui")},children:i})]})}const Fa=/^https?:\/\//i,ig=[];function ng(e){if(!e||typeof e!="object")return null;const i=a=>typeof a=="string"&&a.trim()?a.trim():void 0,n=i(e.url),s=i(e.license_url),o={name:i(e.name),url:n&&Fa.test(n)?n:void 0,license:i(e.license),license_url:s&&Fa.test(s)?s:void 0,note:i(e.note)};return o.name||o.license||o.note?o:null}function rg(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 Ba(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?"冊":ve.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function nd(e,i,n,s=!1){const o=n(`${i}${e.n}`);if(!e.title)return o;const a=n(e.title);return s&&!/^[卷冊册章篇回第]/.test(e.title)?`${o} ${a}`:a}function rd(e,i,n){return i.map(s=>({key:Js(e,s.anchor),label:n(s.label),inChapter:!0,...s.children.length>0?{selectable:!0,children:rd(e,s.children,n)}:{}}))}function sg(e,i,n,s,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?nd(f,n,s,o):h),hint:d(i[h]),disabled:i[h]===0,...g.length>0?{selectable:!0,children:rd(h,id(g),s)}:{}}},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],s(u.label));const g=Ah(u,i);return{key:`group:${f}`,label:s(u.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:Hc(u),defaultExpanded:typeof g=="number"&&g>0,children:[...u.files.filter(w=>l.has(w)).map(w=>c(w)),...(u.children??[]).map((w,j)=>h(w,`${f}.${j}`))]}};return m.map((u,f)=>h(u,`${f}`))}return e.chapters.map(h=>c(h.file))}const sd=e=>{const i=Zl(),n=e.initialChapter,[s,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(su,{mode:i[0].scriptMode,children:t.jsx(ag,{...e,prefsState:i,onBodyReady:n?d:void 0})}),n&&!s&&!a&&t.jsx(og,{data:n})]})};function og({data:e}){const{t:i}=se();return t.jsxs("section",{"data-reader-lead":!0,style:{maxWidth:768,margin:"0 auto",padding:"24px 16px",lineHeight:2},children:[e.paragraphs.map((n,s)=>t.jsx("p",{style:{marginBottom:16},children:n},s)),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 ag=({prefsState:e,onBodyReady:i,id:n,transport:s,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:w,revisedAt:j,backHref:x,backLabel:v,resolveWarpData:S,textFileBase:$,onChapterData:N,hideSupersededVersions:z=!0,warpData:R,resolveEntities:O,onEntityNavigate:C,plugins:I,className:D,style:A})=>{var Co,Eo,Ro,To;const{t:X,convert:B}=se(),ae=b.useMemo(()=>Ul(s),[s]),[te,ce]=e,be=Tt(),oe=b.useRef(l);oe.current=l;const[K,ze]=b.useState(null),[F,me]=b.useState("loading");b.useEffect(()=>{let E=!1;return ze(null),me("loading"),ae.getManifest(n).then(W=>{E||(W?(ze(z?ve.readerVersions(W):W),me("ready")):me("missing"))}).catch(()=>{E||me("missing")}),()=>{E=!0}},[ae,n,z]);const U=o!==void 0,ne=a!==void 0,[ue,G]=b.useState(null),[L,Se]=b.useState(null);b.useEffect(()=>{G(null),Se(null)},[n]);const ge=ve.pickTextVersion(K,U?o:ue),$e=((Co=K==null?void 0:K.versions.find(E=>E.key==="default"))==null?void 0:Co.key)??((Eo=K==null?void 0:K.versions[0])==null?void 0:Eo.key)??"default",_=(ge==null?void 0:ge.key)??null,P=ne?a:L,ie=b.useCallback((E,W,he,st)=>{var rt;(rt=oe.current)==null||rt.call(oe,{key:E,chapter:W,isDefault:E===$e,...st?{anchor:st}:{}},he)},[$e]);b.useEffect(()=>{!K||!U||o==null||K.versions.some(E=>E.key===o)||ie($e,null,"auto")},[K,U,o,$e,ie]);const re=b.useRef(new Map);b.useEffect(()=>{re.current.clear()},[ae,n]);const Re=b.useCallback(async E=>{const W=`${n}
|
|
1545
|
+
${E}`;if(re.current.has(W))return re.current.get(W)??null;const he=await ae.getIndex(n,E).catch(()=>null);return he&&re.current.set(W,he),he},[ae,n]),[Y,de]=b.useState(null),[le,Te]=b.useState("loading"),_e=_?`${n}
|
|
1546
|
+
${_}`:null,xe=Y&&Y.owner===_e?Y.idx:null;b.useEffect(()=>{if(!_)return;let E=!1;const W=`${n}
|
|
1547
|
+
${_}`;return de(null),Te("loading"),Re(_).then(he=>{E||(he&&he.chapters.length>0?(de({owner:W,idx:he}),Te("ready")):Te("failed"))}),()=>{E=!0}},[n,_,Re]),b.useEffect(()=>{if(!xe||!_||P!=null&&xe.chapters.some(he=>he.file===P))return;const W=xe.chapters[0].file;ne||Se(W),ie(_,W,"auto")},[xe,_,P,ne,ie]);const Ce=xe?P!=null&&xe.chapters.some(E=>E.file===P)?P:xe.chapters[0].file:P,Ae=b.useMemo(()=>xe&&Ce?xe.chapters.find(E=>E.file===Ce)??null:null,[xe,Ce]),Je=b.useRef(0),ut=b.useCallback(async E=>{if(!K||E===_||!K.versions.some(Ft=>Ft.key===E))return;const W=++Je.current,he=await Re(E);if(W!==Je.current)return;const st=Ae??(Ce?{file:Ce}:null),rt=ve.matchChapterAcrossVersions(st,he);U||G(E),ne||Se(rt),ie(E,rt,"version")},[K,_,Re,Ae,Ce,U,ne,ie]),[Ve,ht]=b.useState(null),[Ge,k]=b.useState(null),Q=b.useRef(0),J=b.useCallback((E,W)=>{ht({chapter:E,anchor:W,nonce:++Q.current}),k({chapter:E,anchor:W})},[]),pe=b.useCallback(E=>{if(!_)return;const W=td(E);if(W){J(W.chapter,W.anchor),ne||Se(W.chapter),ie(_,W.chapter,"chapter",W.anchor);return}ne||Se(E),ie(_,E,"chapter")},[_,ne,ie,J]),Pe=b.useRef(null);b.useEffect(()=>{!c||!Ce||c===Pe.current||(Pe.current=c,J(Ce,c))},[c,Ce,J]),b.useEffect(()=>{c||(Pe.current=null)},[c]);const[T,fe]=b.useState(null),V=_&&Ae?`${n}
|
|
1548
|
+
${_}
|
|
1549
|
+
${Ae.file}`:null,[Ne,je]=b.useState(null),Ie=V!==null&&Ne!==V,Qe=b.useRef(0);b.useEffect(()=>{if(!_||!Ae)return;const E=++Qe.current,W=`${n}
|
|
1550
|
+
${_}
|
|
1551
|
+
${Ae.file}`;if(fe(null),zn(Ae)){je(W);return}ae.getChapter(n,_,Ae.file,{json:!!Ae.has_json}).then(he=>{E===Qe.current&&fe(he)}).catch(()=>{E===Qe.current&&fe(null)}).finally(()=>{E===Qe.current&&je(W)})},[ae,n,_,Ae]);const Oe=ve.isCollatedKind(ge==null?void 0:ge.kind),[et,yt]=b.useState("");b.useEffect(()=>{yt("")},[n,_]);const He=b.useMemo(()=>_&&Oe?async E=>{const W=await ae.getChapter(n,_,E,{json:!0});return{juan:(W==null?void 0:W.json)??null,rawText:(W==null?void 0:W.md)??null}}:null,[ae,n,_,Oe]),q=(xe==null?void 0:xe.type)==="kaozhen",ke=b.useMemo(()=>(xe==null?void 0:xe.chapters.map(E=>E.file))??[],[xe]),{matchStates:Xe}=Gh({resetKey:`${n}
|
|
1552
|
+
${_??""}`,load:He,files:ke,activeFile:Ce??null,activeJuan:(T==null?void 0:T.json)??null,activeRawText:(T==null?void 0:T.md)??null,query:et,isKaozhen:q}),Ze=b.useRef(new Map);b.useEffect(()=>{Ze.current.clear()},[n]);const De=b.useMemo(()=>({versionKey:_,chapter:Ae??null}),[_,Ae]),Be=tg(),dt=typeof s.getTextFile=="function"||!!$,mt=b.useRef(N);mt.current=N;const pt=b.useMemo(()=>S||R!==void 0||!dt?void 0:async(E,W)=>{var st;const he=await ve.loadReaderChapter(s,{id:n,versionKey:W==null?void 0:W.versionKey,chapter:W==null?void 0:W.chapter},{cord:Be,textFileBase:$});return W!=null&&W.chapter&&((st=mt.current)==null||st.call(mt,{chapterKey:E,ctx:W,data:he})),(he==null?void 0:he.warpData)??null},[S,R,dt,s,n,Be,$]),We=b.useMemo(()=>O||!dt?void 0:async(E,W)=>{var he;return((he=await ve.loadReaderFiles(s,{id:n,versionKey:W==null?void 0:W.versionKey,chapter:W==null?void 0:W.chapter},{cord:Be,textFileBase:$}))==null?void 0:he.entity)??null},[O,dt,s,n,Be,$]),ft=b.useMemo(()=>h||!u||!dt?void 0:async(E,W)=>{const he=await ve.loadReaderFiles(s,{id:n,versionKey:W==null?void 0:W.versionKey,chapter:W==null?void 0:W.chapter},{cord:Be,textFileBase:$}),st=he!=null&&he.cord?ve.iiifVolumeOf(he.cord):he!=null&&he.cordSkipped?ve.volumeFromChar(he.char):null;return st?u(st.bookId,st.vol):null},[h,u,dt,s,n,Be,$]),Z=rh(h??ft,Ce??null,De,n),{warpData:M,loading:ee}=Qc(S??pt,R,Ce??null,De,n),we=!Ie&&V!==null&&(!!M||!!(T!=null&&T.md)||!!(T!=null&&T.json));b.useEffect(()=>{we&&(i==null||i())},[we,i]);const Me=b.useRef(!1);(M||Z.images&&Z.images.length>0)&&(Me.current=!0),b.useEffect(()=>{Me.current=!1},[n]);const Fe=Z.loading||zn(Ae)&&ee&&!M,ot=Me.current&&Fe,at=ot,Ye=qf(O??We,Ce??null,De,n),Le=te.properNameMode??(Ye.length>0?"full":"off"),Ee=b.useMemo(()=>({...te,properNameMode:Le}),[te,Le]),it=b.useMemo(()=>nh(Ye,Le,{showWorks:Ee.showWorks}),[Ye,Le,Ee.showWorks]),[nt,Ue]=b.useState(new Set),[H,ye]=b.useState(null),[qe]=b.useState(sh),[Ke,kt]=b.useState(!0),tt=((Ro=ge==null?void 0:ge.facsimile)==null?void 0:Ro.trimmed)??!1,Lt=tt?!0:te.preserveMargins;b.useCallback(E=>ce({preserveMargins:E}),[ce]);const lt=b.useRef(null),[St,Pt]=b.useState(1),[Nt,ar]=b.useState(null),nn=E=>{var he;const W=parseInt(((he=E==null?void 0:E.page_id)==null?void 0:he.split(":")[1])??"",10);return isNaN(W)?null:W},ni=E=>{var he,st;const W=(E==null?void 0:E.pages)??[];return((he=W.find(rt=>rt.columns.some(Ft=>Ft.chars.length>0)))==null?void 0:he.page)??nn(E)??((st=W[0])==null?void 0:st.page)??1},[xt,bi]=b.useState(()=>ni(M)),Ci=`${n}
|
|
1553
|
+
${_}
|
|
1554
|
+
${Ce??""}`,[Ei,po]=b.useState({key:Ci,data:M,started:!!M});if(Ei.key!==Ci)po({key:Ci,data:M,started:!1});else if(M!==Ei.data&&(po({key:Ci,data:M,started:!!M}),M)){const E=M.pages??[];(!Ei.started||!E.some(W=>W.page===xt))&&bi(ni(M))}b.useEffect(()=>{Ue(new Set),qe.set(null)},[Ce,_,qe]);const lr=Ei.key===Ci&&Ei.started,bo=!!Ae&&ns(Ae.headings).length===0,ho=b.useMemo(()=>bo&&lr&&M?ed(M.pages,M.punctuations):[],[bo,lr,M]),cr=b.useCallback(E=>{const W=ns(E.headings);return W.length>0?W:E.file===Ce?ho:[]},[Ce,ho]),km=b.useCallback(E=>{if(Ue(new Set(E)),E.length>0){const W=E[0],he=parseInt(W.split(":")[0],10);isNaN(he)||bi(he)}},[]),Dt=b.useMemo(()=>{const E=new Map;for(const W of(M==null?void 0:M.pages)??[])E.set(W.page,W);return E},[M]),Ri=nn(M),rn=b.useCallback(E=>{var st;const W=Z.images;if(!W||W.length===0)return;const he=(st=Dt.get(E))==null?void 0:st.seq;return(he?W.find(rt=>rt.seq===he):void 0)??W.find(rt=>rt.pageNo===E)??W[E-1]},[Z.images,Dt]),fo=St>1.5,sn=b.useCallback((E,W=!1)=>{const he=rn(E);return he?E===Ri||W?he.hiresUrl??he.url:he.url:E===Ri?(M==null?void 0:M.imageUrl)??"":""},[rn,M,Ri]),wm=b.useMemo(()=>sn(xt,fo),[sn,xt,fo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((E,W)=>E-W),[Dt]),ri=b.useRef(xt);ri.current=xt;const dr=b.useRef(0),mr=b.useRef({page:null,timer:null}),vm=b.useCallback(E=>{const W=mr.current;E!==W.page&&(W.timer&&(clearTimeout(W.timer),W.timer=null),W.page=null,!(E===ri.current||Date.now()<dr.current)&&(W.page=E,W.timer=setTimeout(()=>{W.timer=null,W.page=null,!(Date.now()<dr.current||ri.current===E)&&(ri.current=E,bi(E))},eg)))},[]);b.useEffect(()=>()=>{mr.current.timer&&clearTimeout(mr.current.timer)},[]);const on=b.useCallback(E=>{var W;ri.current===E||!Dt.has(E)||(dr.current=Date.now()+1e3,ri.current=E,bi(E),(W=Dt.get(E))!=null&&W.columns.some(he=>he.chars.length>0)&&ar(he=>({page:E,nonce:((he==null?void 0:he.nonce)??0)+1})))},[Dt]),Ti=b.useCallback(E=>{const W=ri.current,he=Wt.indexOf(W),st=Wt[he<0?0:he+E];st===void 0||st===W||on(st)},[Wt,on]),go=b.useCallback(E=>{if(!E.trim().match(/^\d+$/)||Wt.length===0)return null;const he=parseInt(E.trim(),10),st=Number.isFinite(he)?he:Number.MAX_SAFE_INTEGER;return Wt.reduce((rt,Ft)=>Math.abs(Ft-st)<Math.abs(rt-st)?Ft:rt,Wt[0])},[Wt]),[ur,pr]=b.useState(null),an=b.useRef(null),Sm=b.useCallback(E=>{an.current=E,pr(E)},[]),xo=b.useCallback(()=>{const E=an.current;if(an.current=null,pr(null),E===null)return;const W=go(E);W!==null&&on(W)},[go,on]),br=Wt.indexOf(xt),$m=b.useCallback(E=>{if(E.altKey||E.ctrlKey||E.metaKey)return;const W=E.target.tagName;W==="INPUT"||W==="TEXTAREA"||W==="SELECT"||(E.key==="ArrowLeft"||E.key==="PageUp"?(E.preventDefault(),Ti(-1)):(E.key==="ArrowRight"||E.key==="PageDown")&&(E.preventDefault(),Ti(1)))},[Ti]),yo=b.useRef(null);b.useEffect(()=>{if(!M)return;const E=yo.current;if(!(!E||E.offsetWidth===0))for(const W of[1,-1]){const he=sn(xt+W);he&&Qr(he)}},[M,xt,sn]);const jo=b.useMemo(()=>{var Lo;if(!M)return null;if(xt===Ri)return M;const E=Dt.get(xt);if(E&&E.width>0&&E.height>0)return{page_id:`p:${xt}`,title:`第${xt}葉`,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(ct=>ct.chars).map(ct=>({id:ct.id,char:ct.char,slot:ct.slot,pos:ct.pos,sub:ct.sub,bbox_col:ct.bbox??[0,0,0,0]}))}],...E.columns.some(ct=>ct.kind==="figure"&&ct.figBox)?{figBlocks:E.columns.filter(ct=>ct.kind==="figure"&&ct.figBox).map(ct=>({id:ct.fig,box:ct.figBox}))}:{}};const W=(Lo=M.pages)==null?void 0:Lo.find(ct=>ct.page===xt),[he,st]=M.image_size||[2386,3082];if(!(he>0&&st>0))return null;const rt=rn(xt),Ft=(rt==null?void 0:rt.width)??he,jr=(rt==null?void 0:rt.height)??st,Io=Ft/he,Mo=jr/st,Ao=new Map;for(const ct of M.columns){const Mt=(ct.strips||[]).flatMap(un=>un.srcQuad.map(pn=>pn[0]));if(Mt.length===0)continue;const Ut=ct.top_y??0,kr=ct.bottom_y??Ut+ct.warped_h;Ao.set(ct.col,{x0:Math.min(...Mt),x1:Math.max(...Mt),top:Ut,slotH:(kr-Ut)/21})}return{page_id:`p:${xt}`,title:`第${xt}葉`,image_size:[Ft,jr],total_warped_w:Ft,columns:W?W.columns.map(ct=>{const Mt=Ao.get(ct.col)??{x0:0,x1:0,top:0,slotH:118};return{col:ct.col,warped_w:Ft,warped_h:jr,offset_x:0,strips:[],chars:ct.chars.map(Ut=>{const kr=Ut.slot??Ut.pos??0,un=(Mt.top+(kr-1)*Mt.slotH)*Mo,pn=(Mt.x0+Mt.x1)/2,[Fm,Bm]=Ut.sub==="a"?[pn,Mt.x1]:Ut.sub==="b"?[Mt.x0,pn]:[Mt.x0,Mt.x1];return{...Ut,bbox_col:[Fm*Io,un,Bm*Io,un+Mt.slotH*Mo]}})}}):[]}},[M,xt,Ri,Dt,rn]),{entryTitle:ln,authors:ko}=dg(n,s,m===void 0),[wo,hr]=b.useState("text");b.useEffect(()=>{hr("text")},[Ce,_]);const _m=b.useMemo(()=>xe?sg(xe,Xe,Ba(ge,xe),B,Oe,cr):[],[xe,Xe,ge,B,Oe,cr]),vo=jh(),So=b.useRef(null),$o=b.useRef(null),fr=b.useMemo(()=>{const E=[];return M&&E.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ke?"bim-rd-on":""}`,"aria-pressed":Ke,title:"切换外挂现代断句标点",onClick:()=>kt(W=>!W),children:Ke?"标点":"无标点"})}}),E},[M,Ke]),Nm=b.useMemo(()=>I&&I.length>0?[...fr,...I]:fr,[fr,I]),zm=b.useMemo(()=>ge&&Ae&&_?{entryId:n,versionKey:_,chapterKey:Ae.file,chapter:Ae,version:ge,transport:s,viewport:vo}:null,[n,_,Ae,ge,s,vo]),Cm=b.useCallback(E=>{Ce&&J(Ce,E)},[Ce,J]),si=wh({plugins:Nm,ctx:zm,prefs:Ee,setPrefs:ce,t:X,convert:B,pages:M==null?void 0:M.pages,textRootRef:So,shellTextRef:$o,selectedCharIds:nt,scrollToAnchor:Cm});if(F==="loading")return t.jsx(Oa,{className:D,style:A,title:m??ln,label:X("reader.loading")});if(F==="missing"||!K||!ge)return t.jsx("div",{className:D,style:{...A,...Pa},children:X("reader.noText")});if(le==="failed")return t.jsx("div",{className:D,style:{...A,...Pa},children:X("reader.tocFailed")});if(!xe)return t.jsx(Oa,{className:D,style:A,title:m??ln,label:X("reader.tocLoading")});const hi=Ba(ge,xe),Em=_m,_o=Ge&&Ce&&Ge.chapter===Ce?Js(Ce,Ge.anchor):null,Rm=_o&&Ae&&cr(Ae).some(E=>E.anchor===Ge.anchor)?_o:Ce??null,gr=K.versions.map(E=>({key:E.key,label:ve.textVersionLabel(E),optionLabel:B(ve.textVersionLabel(E)),sourceName:Ha(E)?X("reader.originalSource"):E.source_name?B(E.source_name):void 0,license:E.license??void 0,sourceUrl:E.source_url??void 0,primary:E.key===$e})),It=ng((To=xe.source)==null?void 0:To.upstream),cn=(typeof m=="string"?B(m):m)??(xe.title?B(xe.title):ln?B(ln):void 0),No=ge.edition_label?B(ge.edition_label):void 0,xr=cn?t.jsx("a",{href:be(n),title:X("reader.viewEntry"),onClick:d?E=>{E.metaKey||E.ctrlKey||(E.preventDefault(),d(n))}:void 0,children:cn}):void 0,Tm=xr&&No?t.jsxs(t.Fragment,{children:[xr,t.jsxs("span",{className:"bim-rd-ed",children:["·",No]})]}):xr,Im=ko.length>0?B(ko.slice(0,2).map(E=>`${E.dynasty?`〔${E.dynasty}〕`:""}${E.name}${` ${E.role||X("reader.defaultRole")}`}`).join("、")):void 0,yr=Ae?nd(Ae,hi,B,Oe):void 0,oi=Oe&&!!(T!=null&&T.json),ai=(T==null?void 0:T.json)??null,fi=(T==null?void 0:T.md)??null,zo=oi&&!q&&Dc(ai.sections),Mm=zo&&!(fi&&Ee.readingMode==="paragraph"&&In(fi)),Am=oi&&zo?t.jsx(qh,{juan:ai,view:wo,onView:hr,textHasEntries:Mm}):void 0,Lm=!0,dn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,mn=Ha(ge),Xt=mn?X("reader.originalSource"):ge.source_name?B(ge.source_name):void 0,Pm=(typeof p=="string"?B(p):p)??(mn?void 0:Xt??B(ve.textVersionLabel(ge))),Om=(M==null?void 0:M.hasNorm)===!0;return t.jsxs(tc,{className:D,style:A,title:Tm,subtitle:Pm,byline:Im,current:yr,pagerUnit:hi,rail:Am,revisedAt:j,backHref:x,backLabel:v,onReportError:w?E=>w({...E,bookTitle:typeof cn=="string"?cn:void 0,entryId:n}):void 0,workLinkToggle:oi&&!q&&!!d&&!!(ai!=null&&ai.sections.some(E=>E.work_id)),toc:Em,tocCaption:X("reader.tocCaption",{n:xe.chapters.length,unit:B(hi)}),tocHeader:Oe&&xe.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:q?X("reader.searchChaptersPlaceholder"):X("reader.searchUnitPlaceholder",{unit:B(hi)}),"aria-label":q?X("reader.searchChapters"):X("reader.searchUnit",{unit:B(hi)}),value:et,onChange:E=>yt(E.target.value)}):void 0,activeKey:Ce??null,tocActiveKey:Rm,onSelect:pe,images:zn(Ae)&&ee&&!M?null:Z.images,renderImageOverlay:f,imagePanel:M||ot?"open":g,imagesLoading:at,isWarpMode:!!M,showPreserveMargins:!tt,customImagePanel:M&&jo?t.jsxs("div",{ref:yo,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:$m,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",outline:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 4px 6px",fontSize:12,color:r.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:[nt.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ue(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",nt.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:St<=1,onClick:()=>{var E;return(E=lt.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(St*100),"%"]}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"放大",title:"放大",disabled:St>=6,onClick:()=>{var E;return(E=lt.current)==null?void 0:E.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:St===1,onClick:()=>{var E;return(E=lt.current)==null?void 0:E.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(Gf,{ref:lt,resetKey:xt,onScaleChange:Pt,style:{flex:1,minHeight:0},children:t.jsx(ka,{store:qe,children:E=>t.jsx(Ws,{imageUrl:wm,pageData:jo,selectedCharIds:nt,hoveredCharId:E,decorations:si.decorations,preserveMargins:Lt,renderScale:St,selectedFigBlock:H,onFigBlockClick:W=>ye(W),onCharClick:W=>{ye(null),Ue(st=>{const rt=new Set(st);return rt.has(W)?rt.delete(W):(rt.clear(),rt.add(W)),rt});const he=document.querySelector(`[data-char-id="${W}"]`);he&&he.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:qe.set})})}),t.jsxs("div",{"data-testid":"facsimile-pager",role:"group","aria-label":X("reader.facsimilePager"),style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"6px 4px 0",fontSize:13,color:r.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:br<=0,onClick:()=>Ti(-1),children:"‹"}),t.jsxs("span",{"data-warp-page":xt,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"1px 8px",background:r.bim("rule"),borderRadius:10},children:["第",t.jsx("input",{type:"text",inputMode:"numeric","data-testid":"facsimile-page-input","aria-label":X("reader.facsimilePageInput"),size:Math.max(2,String(ur??xt).length),value:ur??String(xt),onFocus:E=>E.currentTarget.select(),onChange:E=>Sm(E.target.value),onKeyDown:E=>{E.key==="Enter"?(E.preventDefault(),xo()):E.key==="Escape"&&(an.current=null,pr(null)),E.stopPropagation()},onBlur:xo,style:{width:`${Math.max(2,String(ur??xt).length)+1}ch`,minHeight:28,textAlign:"center",font:"inherit",border:`1px solid ${r.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:br<0||br>=Wt.length-1,onClick:()=>Ti(1),children:"›"})]})]}):void 0,pluginSettings:si.settings,pluginToolbar:si.toolbar,pluginOverlay:si.overlay,textRootRef:$o,prefs:Ee,onPrefsChange:ce,versions:gr.length>1?gr:void 0,currentVersionKey:gr.length>1?ge.key:void 0,onVersionChange:ut,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:In(fi),allowVertical:y,origScriptAvailable:Om,contentLoading:Ie,children:[(Ie||ee&&!M&&!oi&&dn==null)&&t.jsx(Kl,{}),!Ie&&M&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:So,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:Ae!=null&&Ae.title?B(Ae.title):yr}),(Xt||ge.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,ge.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),ge.license]})]})]}),t.jsx(ka,{store:qe,children:E=>t.jsx(qs,{pageData:M,pages:M.pages,punctuations:M.punctuations||ig,selectedCharIds:nt,hoveredCharId:E,onSelectionChange:km,figures:M.figures,figUrl:M.figUrl,onFigureBlockClick:({page:W,fig:he})=>{Ue(new Set),ye(he),bi(W)},onCharClick:W=>{ye(null),Ue(st=>{const rt=new Set(st);return rt.has(W)?rt.delete(W):(rt.clear(),rt.add(W)),rt});const he=parseInt(W.split(":")[0],10);isNaN(he)||bi(he),si.onCellClick(W)},onCharHover:W=>{qe.set(W),si.onCellHover(W)},decorations:si.decorations,mode:"horizontal",showPunctuation:Ke,entities:it,entityTransport:s,onEntityNavigate:C,onVisiblePageChange:vm,convert:B,scrollToPage:Nt,scrollToAnchor:Ve&&Ve.chapter===Ce&&lr?Ve:null,onVisibleHeadingChange:W=>k(W&&Ce?{chapter:Ce,anchor:W}:null),pageBreaks:Ee.pageBreaks,pageIndicatorY:Ee.pageIndicatorY,onPageIndicatorYChange:W=>ce({pageIndicatorY:W}),quoteStyle:Ee.quoteStyle,bookTitleStyle:Ee.bookTitleStyle,showWorks:Ee.showWorks})})]}),!Ie&&!M&&oi&&ai&&t.jsx(Vh,{juan:ai,rawText:fi,positionLabel:lg(Ae,xe,hi,B),groupLabel:cg(xe,Ce??null),index:rg(n,xe),searchQuery:et,onNavigate:d,transport:s,workLabelCache:Ze,prefs:Ee,view:wo,onViewChange:hr},`${_}/${Ce}`),!Ie&&!M&&!oi&&dn!=null&&Ae&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:Ae.title?B(Ae.title):yr}),(Xt||ge.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[mn&&Xt&&t.jsx(t.Fragment,{children:Xt}),!mn&&ge.source_name&&t.jsxs(t.Fragment,{children:[X("reader.textSource")," ",ge.source_url?t.jsx("a",{className:"bim-rd-link",href:ge.source_url,target:"_blank",rel:"noreferrer",children:B(ge.source_name)}):B(ge.source_name)]}),Xt&&ge.license&&t.jsx("span",{className:"bim-rd-dot"}),ge.license]}),It&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[X("reader.upstream")," ",It.url?t.jsx("a",{className:"bim-rd-link",href:It.url,target:"_blank",rel:"noreferrer",children:B(It.name??It.url)}):B(It.name??""),It.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),It.license_url?t.jsx("a",{className:"bim-rd-link",href:It.license_url,target:"_blank",rel:"noreferrer",children:It.license}):It.license]}),It.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(Yl,{text:It.note,convert:B})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(As,{text:dn,mode:Ee.readingMode,tables:Lm,gujiMarkdown:!0,bookMarking:Ms(Ee),quoteStyle:Ee.quoteStyle})})]}),!Ie&&!ee&&!M&&!oi&&dn==null&&Ae&&t.jsx("div",{className:"bim-rd-state",children:X("reader.chapterFailed")}),!Ie&&xe.references&&xe.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:X("reader.references")}),t.jsx("ol",{children:xe.references.map((E,W)=>t.jsxs("li",{children:[E.url?t.jsx("a",{className:"bim-rd-link",href:E.url,target:"_blank",rel:"noopener noreferrer",children:B(E.title)}):t.jsx("span",{children:B(E.title)}),E.author&&t.jsxs("span",{children:[",",B(E.author)]}),E.note&&t.jsxs("span",{children:["。",B(E.note)]})]},W))})]})]})};function Ha(e){return e.is_original===!0||e.source==="original"}function lg(e,i,n,s){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 s(o?`${o}冊`:`${n}${e.n}`)}function cg(e,i){if(!i)return;const n=s=>{var o;for(const a of s??[]){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 dg(e,i,n){const[s,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]),s}const mg=({pageData:e,rawImageUrl:i="",punctuations:n=[],title:s,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),w=b.useRef(null),j=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}),w.current){const N=w.current.querySelector(`[data-char-id="${$}"]`);N&&N.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),v=()=>{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:s||e.title}),o&&t.jsx("span",{style:{fontSize:"0.85rem",color:r.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:r.bim("body-fg")},children:["已选字数: ",t.jsx("strong",{style:{color:r.bim("accent")},children:c.size})]}),c.size>0&&t.jsx("button",{type:"button",onClick:v,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(Ws,{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:w,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(qs,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:p,onSelectionChange:j,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},ug=({data:e,onNavigate:i,className:n,style:s})=>{var p;const{t:o,convert:a}=se(),[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:s,children:[t.jsxs("div",{style:{marginBottom:"16px"},children:[t.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:r.bim("fg"),margin:"0 0 8px"},children:a(e.title)}),e.stats&&t.jsxs("div",{style:{fontSize:"13px",color:r.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(pg,{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))})]})},pg=({division:e,expanded:i,onToggle:n,expandedCat:s,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=se(),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 ${r.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, ${r.bim("primary")} 6%, transparent)`:r.bim("bg"),cursor:"pointer",fontSize:"15px",fontWeight:600,color:r.bim("fg"),textAlign:"left"},children:[t.jsx("span",{children:d(e.name)}),t.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:r.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(bg,{category:m,expanded:s===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},bg=({category:e,expanded:i,onToggle:n,onNavigate:s})=>{var m,p,h,u;const{t:o,convert:a}=se(),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?r.bim("input-bg"):"transparent",cursor:"pointer",fontSize:"13px",color:r.bim("fg"),textAlign:"left"},children:[t.jsxs("span",{style:{fontWeight:500},children:[a(e.name),e.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),marginLeft:"8px",fontWeight:400},children:o("catalogPage.categoryJuan",{n:a(e.volumes)})})]}),t.jsxs("span",{style:{fontSize:"11px",color:r.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(Da,{label:o("catalogPage.zhulu"),books:l,onNavigate:s}),d.length>0&&t.jsx(Da,{label:o("catalogPage.cunmu"),books:d,onNavigate:s})]})]})},Da=({label:e,books:i,onNavigate:n})=>{const{t:s,convert:o}=se(),a=Tt(),[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:r.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:r.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 ${r.bim("link-fg")}`},children:o(m.title)}):o(m.title)}),m.volumes&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("desc-fg")},children:o(m.volumes)}),m.author&&t.jsx("span",{style:{fontSize:"11px",color:r.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:r.bim("primary"),background:"transparent",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"4px",cursor:"pointer"},children:s("catalogPage.expandAllN",{n:i.length})})]})};function Zs(e="/api/feedback",i){const n=()=>typeof e=="function"?e():e,s=(...o)=>((i==null?void 0:i.fetch)??fetch)(...o);return{async listFeedback(o){try{const l=await(await s(`${n()}?resourceId=${encodeURIComponent(o)}`)).json();return l!=null&&l.success&&Array.isArray(l.items)?l.items:[]}catch{return[]}},async submitFeedback(o){const a=await s(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 od(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const hg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],ad=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:s})=>{const{t:o}=se(),[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=v=>{v.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const w=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 j=a&&d.trim()&&h!=="submitting";return t.jsx("div",{style:fg,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:gg,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:xg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:yg,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Sg,children:[t.jsx("span",{style:{fontSize:"32px"},children:"✓"}),t.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:o("feedback.thanks")}),s&&t.jsx("a",{href:s,style:{fontSize:"13px",color:r.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:hg.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{...jg,...a===x.value?kg:{}},children:[t.jsx("span",{children:x.icon})," ",o(`feedback.submitType.${x.value}`)]},x.value))}),t.jsx("textarea",{ref:y,value:d,onChange:x=>c(x.target.value),placeholder:o(a?`feedback.placeholder.${a}`:"feedback.chooseTypeFirst"),maxLength:2e3,disabled:!a||h==="submitting",style:{...wg,opacity:a?1:.6}}),t.jsx("input",{type:"text",value:m,onChange:x=>p(x.target.value),placeholder:o("feedback.contactPlaceholder"),maxLength:200,disabled:!a||h==="submitting","aria-label":o("feedback.contactLabel"),style:_g}),t.jsxs("div",{style:{fontSize:"12px",color:r.bim("desc-fg"),textAlign:"right",marginBottom:"12px"},children:[d.length," / 2000"]}),h==="error"&&t.jsx("div",{style:$g,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:w,disabled:!j,style:{...vg,opacity:j?1:.6,cursor:j?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},fg={position:"fixed",top:0,left:0,right:0,bottom:0,background:r.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},gg={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r.bim("shadow-dialog")},xg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},yg={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},jg={flex:"1 1 calc(50% - 4px)",padding:"10px 12px",fontSize:"13px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",background:r.bim("input-bg"),color:r.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},kg={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},wg={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("input-bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},vg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},Sg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r.bim("success")},$g={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},_g={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},rs="--bim-feedback-fab-offset",ss=48,Ng=16,zg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:s=!1,zIndex:o})=>{const{t:a}=se(),[l,d]=b.useState(!1),c=i.bottom??24;return b.useEffect(()=>{if(s||typeof document>"u")return;const m=document.documentElement;return m.style.setProperty(rs,`calc(${c+ss+Ng}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(rs)}},[s,c]),t.jsxs(t.Fragment,{children:[!s&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Cg,zIndex:o??r.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(ad,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},Cg={position:"fixed",width:`${ss}px`,height:`${ss}px`,borderRadius:"50%",border:"none",background:r.bim("primary"),color:r.bim("primary-fg"),cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:r.bim("shadow-fab"),transition:"transform 0.2s, box-shadow 0.2s"},Eg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],ld=({onSubmit:e})=>{const{t:i}=se(),[n,s]=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(""),s("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:Wa,children:t.jsxs("div",{style:Ag,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:Lg,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Wa,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Eg.map(y=>t.jsxs("button",{onClick:()=>s(y.value),style:{...Rg,...n===y.value?Tg:{}},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:{...Ig}}),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:Og}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[t.jsxs("span",{style:{fontSize:"12px",color:r.bim("desc-fg")},children:[o.length," / 2000"]}),t.jsx("button",{onClick:f,disabled:!g,style:{...Mg,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:Pg,children:p})]})},Wa={padding:"16px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",background:r.bim("input-bg")},Rg={padding:"8px 16px",fontSize:"13px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",background:"transparent",color:r.bim("fg"),cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Tg={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},Ig={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Mg={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},Ag={display:"flex",alignItems:"center",gap:"12px",color:r.bim("success"),fontSize:"14px"},Lg={background:"none",border:"none",color:r.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Pg={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},Og={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",border:`1px solid ${r.bim("input-border")}`,borderRadius:"6px",background:r.bim("bg"),color:r.bim("input-fg"),outline:"none",boxSizing:"border-box",fontFamily:"inherit"},cd={bug:{key:"bug",color:r.bim("danger")},resource:{key:"resource",color:r.bim("primary")},suggestion:{key:"suggestion",color:r.bim("primary")},other:{key:"other",color:r.bim("desc-fg")}},Fg=cd.other,dd={pending:{key:"pending",color:r.bim("warning")},in_progress:{key:"in_progress",color:r.bim("primary")},resolved:{key:"resolved",color:r.bim("success")},wontfix:{key:"wontfix",color:r.bim("desc-fg")},duplicate:{key:"duplicate",color:r.bim("desc-fg")}},Bg=dd.pending;function Hg(e){try{const i=new Date(e),n=s=>String(s).padStart(2,"0");return`${i.getFullYear()}-${n(i.getMonth()+1)}-${n(i.getDate())} ${n(i.getHours())}:${n(i.getMinutes())}`}catch{return e}}function Dg(e,i){if(!e)return!1;try{const n=new URL(e,i);if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;const s=new URL(i);return n.hostname===s.hostname}catch{return!1}}const md=({items:e,loading:i})=>{const n=Tt(),{t:s,convert:o}=se();return i?t.jsx(Kl,{}):e.length===0?t.jsx("div",{style:Wg,children:s("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=cd[a.type]||Fg,d=dd[a.status]||Bg,c=typeof window<"u"&&Dg(a.pageUrl,window.location.href);return t.jsxs("div",{style:Ug,children:[t.jsxs("div",{style:Kg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...Ua,background:l.color},children:s(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...Ua,background:d.color},children:s(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Yg,children:Hg(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Vg,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Lr,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Lr,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Lr,children:a.pageUrl}))]}),t.jsx("div",{style:Gg,children:o(a.content)}),a.reply&&t.jsxs("div",{style:qg,children:[t.jsx("div",{style:Xg,children:s("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},Wg={textAlign:"center",padding:"40px 0",color:r.bim("desc-fg"),fontSize:"14px"},Ug={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},Kg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ua={fontSize:"12px",color:r.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Yg={fontSize:"12px",color:r.bim("desc-fg")},Vg={fontSize:"12px",marginBottom:"6px"},Lr={color:r.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${r.bim("primary")}`},Gg={fontSize:"14px",lineHeight:"1.6",color:r.bim("fg"),whiteSpace:"pre-wrap"},qg={marginTop:"12px",padding:"10px 12px",background:r.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r.bim("fg")},Xg={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r.bim("primary")},ud=({resourceId:e,transport:i,apiUrl:n})=>{const{t:s}=se(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(s);c.current=s;const m=b.useMemo(()=>i??Zs(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(md,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(ld,{onSubmit:h})})]})},Zn=8;async function Qn(e,i,n,s){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&&!(s!=null&&s());){const c=l++;a[c]=await n(e[c],c)}});return await Promise.all(d),a}const Jg=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function Zg(e){const i=e.search(Jg);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const pd={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,s="",o=i;if(e&&typeof i=="string"&&(i===e||i===Qg(e))){const[a,l]=Zg(i);l&&(n=encodeURI(a),o=a,s=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:r.bim("link")},children:o}),s]})},code:({children:e})=>t.jsx("code",{style:{background:r.bim("bg-subtle"),padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:e})};function Qg(e){try{return decodeURI(e)}catch{return e}}const ex={...pd,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:s})=>{const{convert:o}=gt(),a=i?ex:pd;return t.jsx("div",{className:s,style:n,children:t.jsx(Gm,{remarkPlugins:[qm],components:a,children:o(e)})})},tx=r.detail["zh-Hant"].relation,ix=r.detail["zh-Hant"].lossStatus,nx=r.detail["zh-Hant"].resourceKind,er=r.getT("zh-Hant"),Qs=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function Ka(e,i=er){return e?Qs(tx,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function rx(e,i=er){return Qs(ix,e)?i(`detail.lossStatus.${e}`):e}function sx(e,i=er){return Qs(nx,e)?i(`detail.resourceKind.${e}`):""}function eo({authors:e,onNavigate:i,renderLink:n}){const{convert:s}=se(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=fs(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:["〔",s(a.dynasty),"〕"]}),a.entity_id?t.jsx(wt,{id:a.entity_id,label:s(a.name),onNavigate:i,renderLink:n,dense:!0}):s(a.name),d&&t.jsx("span",{style:{marginLeft:4},children:s(d)})]},l)})}):null}function bd(e,i,n=er){var c,m;const s=bs(e,i),o=s.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=s.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=s.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=s.buckets.find(p=>p.key==="text"))==null?void 0:m.items)??[],groups:o}}function hd(e,i){const n=(e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name,s=Sl(e,i);return s?`${n}(${s})`:n}function to({item:e,siblings:i,listedVolumeCounts:n}){const{t:s,convert:o}=se(),[a,l]=b.useState(!1),d=r.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(hd(e,i)),p=r.resourceHref(e),h=Dn(e,s)||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:s("detail.fragmentTag")}),e.color_mode&&t.jsx("span",{className:"bim-d-tag",children:e.color_mode==="color"?s("colorMode.color"):s("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(Cs,{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?s("detail.collapseVolumes"):s("detail.expandVolumes",{n:d.expected})})})]})}function fd({groups:e,listedVolumeCounts:i}){const{t:n,convert:s}=se();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:s(o.label)}),o.description&&t.jsx("p",{className:"bim-d-rg-d",children:s(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(to,{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=r.resourceHref(a),c=s(hd(a,o.mirrors));return d?t.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",title:a.details?s(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 Ui=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function os(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Ui.find(s=>i.startsWith(s.key[0])))==null?void 0:n.key}const Ya=12,ox=60,gd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,railTop:a,back:l,railLinks:d})=>{var ie,re,Re;const{t:c,convert:m,messages:p}=se(),h=b.useMemo(()=>gs({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[w,j]=b.useState(""),[x,v]=b.useState(!1),S=h.length<=ox,$=S||g||!!w||x,N=b.useMemo(()=>$?h:h.slice(0,Ya),[h,$]);b.useEffect(()=>{if(!i||N.length===0)return;const Y=N.filter(le=>!u.has(le));if(Y.length===0)return;let de=!1;return Qn(Y,Zn,le=>i.getItem(le).then(Te=>{var xe;const _e=Te??{};return[le,{id:le,title:_e.title,edition:_e.edition,resources:_e.resources,publication_info:_e.publication_info,current_location:_e.current_location,provenance:_e.provenance,lineage:_e.lineage,related_books:_e.related_books,dating:_e.dating,measure_info:_e.measure_info,summary:lx((xe=Te==null?void 0:Te.description)==null?void 0:xe.text)}]}).catch(()=>[le,{id:le}]),()=>de).then(le=>{de||f(Te=>{const _e=new Map(Te);for(const[xe,Ce]of le)_e.set(xe,Ce);return _e})}),()=>{de=!0}},[i,N,u]);const z=b.useMemo(()=>h.map(Y=>u.get(Y)??{id:Y}),[h,u]),R=h.length>0&&h.every(Y=>u.has(Y)),O=!!i&&N.some(Y=>!u.has(Y)),C=S||$,I=b.useMemo(()=>_l(z,e.version_graph,{era:w,scanOnly:x,sort:C?"year":"default"}),[z,e.version_graph,w,x,C]),D=g?I.rows:I.rows.slice(0,Ya),A=I.allRows.filter(Y=>Y.hasImage).length,X=I.allRows.reduce((Y,de)=>{var le;return Y+(((le=de.copies)==null?void 0:le.length)??0)},0),B=b.useMemo(()=>(e._related||[]).map(Y=>({...Y,title:Y.title??""})),[e._related]),ae=B.filter(Y=>Y.relation==="collected_in"),te=b.useMemo(()=>{const Y=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],de=le=>{const Te=Y.indexOf(le??"");return Te<0?Y.length:Te};return B.filter(le=>le.relation!=="collected_in").map((le,Te)=>({r:le,i:Te})).sort((le,Te)=>de(le.r.relation)-de(Te.r.relation)||le.i-Te.i).map(le=>le.r)},[B]),ce=b.useMemo(()=>{const Y=bs(e.resources,e.resource_groups);return[...Y.mirrors.flatMap(de=>de.items.map(le=>({r:le,kind:m(de.label)}))),...Y.buckets.flatMap(de=>de.items.map(le=>({r:le,kind:m(sx(de.key,c))})))]},[e.resources,e.resource_groups,m,c]),be=e.indexed_by||[],oe=e.emendated_by||[],K=b.useMemo(()=>{var Ae,Je,ut,Ve,ht;const Y=[],de=(Je=(Ae=e.authors)==null?void 0:Ae[0])==null?void 0:Je.dynasty;de&&Y.push({label:c("workPage.fact.written"),value:m(de)});const le=qt(e,p.unit.juan);if(le){const Ge=((ut=e.juan_count)==null?void 0:ut.description)??((ht=(Ve=e.measures)==null?void 0:Ve.find(k=>(k==null?void 0:k.unit)==="卷"&&k.note))==null?void 0:ht.note);Y.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(le),Ge&&Ge!==le?t.jsxs("span",{className:"bim-d-meta",children:["(",m(Ge),")"]}):null]})})}e.loss_status&&Y.push({label:c("workPage.fact.loss"),value:m(rx(e.loss_status,c))}),e.authenticity==="forged"&&Y.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const Te=I.allRows.filter(Ge=>Ge.sortYear!=null),_e=Te.length>0?Te.reduce((Ge,k)=>Ge.sortYear<=k.sortYear?Ge:k):null;_e!=null&&_e.era.era?Y.push({label:c("workPage.fact.earliest"),value:m([_e.era.era,_e.era.reign].filter(Boolean).join(" ")),title:_e.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):O&&Y.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),oe.length&&Y.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:oe.length})});const xe=ax(e.additional_titles);xe.length&&Y.push({label:c("workPage.fact.alias"),value:xe.map(m).join("、")});const Ce=(e.additional_works||[]).map(Ge=>m(Ge.book_title)+(Ge.n_juan!=null?` ${Ge.n_juan}${p.unit.juan}`:""));return Ce.length&&Y.push({label:c("workPage.fact.appendix"),value:Ce.join("、")}),Y},[e,m,c,p,O,I.allRows,oe.length]),F=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:R?A:0,label:c("workPage.stat.hasImage")},{value:be.length,label:c("workPage.stat.catalogs")}],me=xs(e),U=me?[me.l1,me.l2,me.l3,me.l4].filter(Boolean).map(Y=>m(Y)):[],ne=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",ue=t.jsx(Ji,{title:m(e.title),byline:t.jsx(eo,{authors:e.authors,onNavigate:n,renderLink:s}),meta:t.jsx(vt,{items:[...U,me!=null&&me.source?c("workPage.classifiedBy",{source:m(me.source.split("/")[0])}):"",ne]}),description:(ie=e.description)!=null&&ie.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(re=e.description.sources)!=null&&re.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(Y=>({text:m(Lu(Y)),href:Pu(Y)})).filter(Y=>Y.text).map((Y,de)=>t.jsxs(b.Fragment,{children:[de>0?" · ":null,Y.href?t.jsx("a",{href:Y.href,target:"_blank",rel:"noopener noreferrer",children:Y.text}):Y.text]},de))}):null]}):void 0,stats:F,facts:K,readAction:o,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Re=e.appendix)==null?void 0:Re.map((Y,de)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(Y.title)}),t.jsx(zi,{text:Y.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},de))}),G=I.eras.length>=2?[{key:"",label:c("catalog.all")},...I.eras.map(Y=>({key:Y,label:`${Y} ${I.allRows.filter(de=>de.era.era===Y).length}`}))]:[],L=[];h.length&&L.push({id:"versions",label:c("workPage.sec.versions"),count:h.length}),be.length&&L.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:be.length}),ae.length&&L.push({id:"collected",label:c("workPage.sec.collected"),count:ae.length}),te.length&&L.push({id:"related",label:c("workPage.sec.related"),count:te.length}),ce.length&&L.push({id:"resources",label:c("workPage.sec.resources"),count:ce.length});const Se=h.length===0&&be.length===0,ge=t.jsxs(t.Fragment,{children:[h.length>0&&t.jsxs($t,{id:"versions",title:c("workPage.sec.versions"),meta:t.jsx(vt,{items:[c("workPage.versionsTotal",{n:h.length-X}),R&&A?c("workPage.versionsWithImage",{n:A}):"",I.rows.length!==I.allRows.length?c("workPage.versionsCurrent",{n:I.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":O&&G.length===0&&h.length>1?"":void 0,children:[G.length>0&&t.jsx(Gn,{items:G,value:w,onChange:Y=>{j(Y),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(dc,{label:c("workPage.scanOnly"),checked:x,onChange:Y=>{v(Y),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(C?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&qn(I.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:D.map(Y=>{var de;return t.jsx(dx,{row:Y,measure:(de=u.get(Y.id))==null?void 0:de.measure_info,loaded:u.has(Y.id),onNavigate:n,renderLink:s},`${Y.id}:${u.has(Y.id)?"r":"p"}`)})})]}),D.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(w||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx($s,{total:I.rows.length,shown:D.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)}),I.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),be.length>0&&t.jsx(mx,{items:be,transport:i,onNavigate:n,renderLink:s}),Se&&t.jsx($t,{title:c("workPage.sec.versions"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("workPage.empty")})})]}),$e=(Y,de)=>t.jsx(wt,{id:Y,label:m(de),onNavigate:n,renderLink:s,dense:!0}),_=b.useMemo(()=>{const Y=new Map;for(const de of te){const le=Ka(de.relation,c);Y.set(le,(Y.get(le)??0)+1)}return Y.size>1?[...Y.entries()].sort((de,le)=>le[1]-de[1]).slice(0,4).map(([de,le])=>`${m(de)} ${le}`).join(" · "):void 0},[te,m,c]),P=t.jsxs(t.Fragment,{children:[t.jsx(di,{id:"collected",title:c("workPage.sec.collected"),items:ae.map(Y=>$e(Y.id,Y.title))}),t.jsx(di,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:te.length}),sub:_,items:te.map(Y=>t.jsxs(t.Fragment,{children:[$e(Y.id,Y.title),t.jsx("span",{className:"bim-d-meta",title:Y.note?m(Y.note):void 0,children:m(Ka(Y.relation,c))})]}))}),t.jsx(di,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:ce.map(({r:Y,kind:de})=>{const le=m((Y.url?r.getDisplayNameFromUrl(Y.url):void 0)||Y.name),Te=r.resourceHref(Y);return t.jsxs(t.Fragment,{children:[Te?t.jsxs("a",{href:Te,target:"_blank",rel:"noopener noreferrer",children:[le," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:le}),de&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:de})]})})})]});return t.jsx(Xi,{railTop:a,back:l,nav:L,railLinks:d,main:ge,card:ue,side:P})};function ax(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function as(e,i){return i((e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name)}function lx(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:s,convert:o}=se(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?as(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:[s("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(wt,{id:m.id,label:m.callNumber||m.id,onNavigate:i,renderLink:n,dense:!0})]},m.id))]},l||c))]})}function dx({row:e,measure:i,loaded:n,onNavigate:s,renderLink:o}){const{t:a,convert:l}=se(),d=[e.era.era,e.era.reign].filter(Boolean).join(" "),c=e.era.source==="edition",m=e.holders[0],p=e.copies??[],h=p.length&&e.locationName?l(e.locationName):m?as(m,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?r.resourceHref(u):void 0,g=e.images.map(y=>as(y,l)).join("、");return t.jsxs("tr",{"data-loading":n?void 0:"",className:p.length?"bim-d-zt-group":void 0,children:[t.jsxs("td",{className:p.length?"bim-d-zt-main bim-d-zt-rep":"bim-d-zt-main",children:[t.jsx(wt,{id:e.id,label:l(e.name),onNavigate:s,renderLink:o,dense:!0}),i?t.jsx("span",{className:"bim-d-meta",children:l(i)}):t.jsx("span",{className:"bim-d-meta","aria-hidden":"true",children:" "}),p.length>0&&e.summary&&t.jsx("span",{className:"bim-d-zt-summary",children:l(e.summary)}),p.length>0&&t.jsx(cx,{copies:p,onNavigate:s,renderLink:o})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${d?"":" bim-d-zt-blank"}`,title:c?a("workPage.inferredFromEdition"):void 0,children:d?l(d):n?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null}),t.jsxs("td",{className:`bim-d-zt-sub${h?"":" bim-d-zt-blank"}`,children:[h||(n?t.jsx("span",{className:"bim-d-zt-empty",children:"—"}):null),p.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&&(f?t.jsx("a",{className:"bim-d-flag",href:f,target:"_blank",rel:"noopener noreferrer",title:g,children:a("workPage.hasImage")}):t.jsx("span",{className:"bim-d-flag",title:g,children:a("workPage.hasImage")}))})]})}function mx({items:e,transport:i,onNavigate:n,renderLink:s}){const{t:o,convert:a}=se(),[l,d]=b.useState(0),c=Math.min(l,e.length-1),m=e[c],[p,h]=b.useState(new Map);return b.useEffect(()=>{if(!i)return;const u=[...new Set(e.map(g=>g.source_bid).filter(g=>!!g))];if(u.length===0)return;let f=!1;return Promise.all(u.map(g=>i.getItem(g).then(y=>{var w,j;return[g,((j=(w=y==null?void 0:y.authors)==null?void 0:w[0])==null?void 0:j.dynasty)??""]}).catch(()=>[g,""]))).then(g=>{f||h(new Map(g.filter(([,y])=>y)))}),()=>{f=!0}},[i,e]),t.jsx($t,{id:"catalogs",title:o("workPage.sec.catalogs"),meta:t.jsx(vt,{items:[o("workPage.catalog.meta",{n:e.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:e.map((u,f)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":f===c,"aria-label":a(u.source),onClick:()=>d(f),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:p.get(u.source_bid??"")?a(p.get(u.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...a(u.source)].slice(0,9).map((g,y)=>t.jsx("span",{children:g},y))})]})},f))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[m.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(m.title_info)}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[m.source_bid?t.jsx(wt,{id:m.source_bid,label:a(m.source),onNavigate:n,renderLink:s,dense:!0}):a(m.source),m.section?a(m.section):"",m.author_info?`${o("label.authorInfo")} ${a(m.author_info)}`:"",m.edition?`${o("label.edition")} ${a(m.edition)}`:"",m.page??""]}),m.summary&&t.jsx("p",{className:"bim-d-quote",children:At(a(m.summary),void 0,{t:o})}),m.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:At(a(m.comment),void 0,{t:o})})]}),m.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:At(a(m.additional_comment),void 0,{t:o})})]}),!m.summary&&!m.comment&&!m.additional_comment&&!m.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:o("workPage.catalog.titleOnly")}),e.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[c>0?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.prev",{name:a(e[c-1].source)}),onClick:()=>d(c-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(e[c-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[c+1," / ",e.length]}),c<e.length-1?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.next",{name:a(e[c+1].source)}),onClick:()=>d(c+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(e[c+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}const xd=({graph:e,renderLink:i,className:n,style:s})=>{const{t:o,convert:a}=se();if(!e.nodes.length)return t.jsx("div",{style:{...$x,...s},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:{...px,...s},children:[e.title&&t.jsx("div",{style:bx,children:a(e.title)}),e.description&&t.jsx("div",{style:hx,children:a(e.description)}),u.map(f=>t.jsx(Va,{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(Va,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},Va=({label:e,color:i,nodes:n,incomingMap:s,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=se();return t.jsxs("div",{style:fx,children:[t.jsx("div",{style:{...gx,borderLeftColor:i??r.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(ux,{node:c,incoming:s.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},ux=({node:e,incoming:i,siblings:n,nodeMap:s,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=se();return t.jsxs("div",{style:{...xx,borderStyle:a||l?"dashed":"solid",opacity:l?.55:e.status==="lost"?.7:1,background:l?r.bim("bg-subtle"):void 0},title:l?d("lineage.bridgeTitle"):void 0,children:[t.jsxs("div",{style:yx,children:[t.jsx("span",{style:jx,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:kx,children:jl(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:wx,children:[e.category&&t.jsx(Li,{children:c(e.category)}),e.status==="lost"&&t.jsx(Li,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Li,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Li,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Li,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:vx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Sx,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:qa,children:[t.jsx("div",{style:Xa,children:d("lineage.sources")}),i.map(m=>{const p=s.get(m.source);return t.jsxs("div",{style:Ja(m.confidence),children:[t.jsx("span",{style:Za,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(Ga,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:Qa,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:qa,children:[t.jsx("div",{style:Xa,children:d("lineage.related")}),n.map(m=>{const p=m.source===e.id?m.target:m.source,h=s.get(p);return t.jsxs("div",{style:Ja(m.confidence),children:[t.jsx("span",{style:Za,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(Ga,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:Qa,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Li=({children:e,tone:i="default"})=>{const s={default:{bg:r.bim("tag-bg"),fg:r.bim("fg")},warn:{bg:r.bim("warn-bg"),fg:r.bim("warn-fg")},info:{bg:r.bim("info-bg"),fg:r.bim("info-fg")}}[i];return t.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:s.bg,color:s.fg,marginRight:"4px"},children:e})},Ga=({level:e})=>{const{t:i}=se(),s={certain:{key:"certain",color:r.bim("confidence-certain")},consensus:{key:"consensus",color:r.bim("confidence-consensus")},probable:{key:"probable",color:r.bim("confidence-probable")},disputed:{key:"disputed",color:r.bim("confidence-disputed")}}[e];return s?t.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${s.color}`,color:s.color,borderRadius:"8px",marginLeft:"4px"},children:i(`lineage.confidence.${s.key}`)}):null},px={fontSize:"14px",color:r.bim("fg")},bx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},hx={fontSize:"13px",color:r.bim("muted"),marginBottom:"16px",lineHeight:1.6},fx={marginBottom:"16px"},gx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r.bim("fg")},xx={border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r.bim("bg")},yx={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},jx={fontSize:"15px",fontWeight:600},kx={fontSize:"12px",color:r.bim("muted")},wx={marginBottom:"6px"},vx={fontSize:"12px",color:r.bim("muted"),margin:"2px 0"},Sx={fontSize:"12px",color:r.bim("muted"),fontStyle:"italic",margin:"4px 0"},qa={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r.bim("widget-border")}`},Xa={fontSize:"11px",color:r.bim("muted"),marginBottom:"2px"},Ja=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),Za={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r.bim("tag-bg"),color:r.bim("fg"),borderRadius:"3px",marginRight:"6px"},Qa={fontSize:"11px",color:r.bim("muted")},$x={padding:"20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px"},yd=({selectedNodeId:e,...i})=>{const{t:n}=se(),[s,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return _x().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),s==="loading"?t.jsx("div",{style:tl,children:n("lineage.graphLoading")}):s==="missing"||!a?t.jsxs("div",{style:tl,children:[t.jsx("div",{children:el(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:el(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Nx,{modules:a,selectedNodeId:e,...i})};function el(e,i){return e.split(/(\{\w+\})/).map((n,s)=>{const o=/^\{(\w+)\}$/.exec(n);return t.jsx(b.Fragment,{children:o&&o[1]in i?i[o[1]]:n},s)})}async function _x(){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 Nx=({graph:e,renderLink:i,height:n=600,className:s,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,w=b.useMemo(()=>({lineage:N=>{var ae,te,ce,be;const z=((ae=N.data)==null?void 0:ae.stepPosition)??.85,[R,O,C]=g({sourceX:N.sourceX,sourceY:N.sourceY,sourcePosition:N.sourcePosition,targetX:N.targetX,targetY:N.targetY,targetPosition:N.targetPosition,stepPosition:z,borderRadius:5}),I=!!((te=N.data)!=null&&te.isSibling),D=I?O:N.targetX-18,A=I?C:N.targetY-12,X=(ce=N.data)==null?void 0:ce.labelStyle,B=(be=N.data)==null?void 0:be.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:N.id,path:R,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(${D}px,${A}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:r.bim("bg"),border:`0.5px solid ${r.bim("widget-border")}`,...B,...X},children:N.label})})]})}}),[u,f,g]),j=b.useMemo(()=>({version:N=>{const{t:z}=se(),R=N.data,O=R.kind==="hypothetical",C=R.status==="lost",I=R.isSelected,D=R.bridge,A=R.borderColor??r.bim("muted"),X=D||O?"dashed":"solid",B=D?.5:C?.6:1;return t.jsxs("div",{style:{background:D?r.bim("bg-subtle"):r.bim("bg"),border:`2px ${X} ${I?r.bim("primary"):A}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:B,boxShadow:I?r.bim("shadow-node-selected"):O||D?"none":r.bim("shadow-node")},title:D?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:O||!R.renderLink?R.label:R.renderLink(R.bookId,R.label)}),R.description&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:R.description}),R.yearText&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.2},children:jl(R.yearText,void 0,R.uncertain)}),C&&t.jsx("div",{style:{fontSize:9,color:r.bim("lost-fg"),marginTop:1},children:z("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=se(),{rfNodes:v,rfEdges:S}=b.useMemo(()=>zx(e,y,i,a,x),[e,y,i,a,x]);return t.jsx("div",{style:{width:"100%",height:n,...o},className:s,children:t.jsxs(d,{nodes:v,edges:S,nodeTypes:j,edgeTypes:w,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 zx(e,i,n,s,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(j=>[j.id,j.color??r.bim("muted")]));for(const j of e.nodes)c.setNode(j.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of e.edges)j.kind==="derive"&&(p.has(j.relation)||c.setEdge(j.source,j.target));i.layout(c);const h=e.nodes.map(j=>{const x=c.node(j.id),v=s?j.id===s:void 0,S={kind:j.kind,label:o(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:o(j.year_text??Ex(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?m.get(j.group):void 0,renderLink:n,isSelected:v,description:o(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:S,draggable:!1,selected:v}}),u=.78,f=.06,g=new Map;for(const j of e.edges)j.kind==="derive"&&(g.has(j.source)||g.set(j.source,[]),g.get(j.source).push(j));const y=new Map;for(const[j,x]of g){if(x.length<=1)continue;const v=[...x].sort(($,N)=>{var O,C;const z=((O=c.node($.target))==null?void 0:O.y)??0,R=((C=c.node(N.target))==null?void 0:C.y)??0;return z-R}),S=v.length;v.forEach(($,N)=>{const z=(N-(S-1)/2)*f;y.set($.id,u+z)})}const w=e.edges.map(j=>Cx(j,y.get(j.id),o));return{rfNodes:h,rfEdges:w}}function Cx(e,i,n=s=>s??""){const s=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Rx(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:r.bim("fg")},isSibling:o,stepPosition:i},style:{stroke:a,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":s?"6 4":void 0,opacity:s?.75:1},animated:!1,markerEnd:l,markerStart:o?l:void 0,zIndex:1e3}}function Ex(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Rx(e){switch(e){case"certain":return r.bim("confidence-certain");case"consensus":return r.bim("lineage-edge-consensus");case"probable":return r.bim("confidence-probable");case"disputed":return r.bim("confidence-disputed");default:return r.bim("muted")}}const tl={padding:"40px 20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px",border:`1px dashed ${r.bim("widget-border")}`,borderRadius:8,background:r.bim("bg")},io=({graph:e,defaultMode:i="list",renderLink:n,graphHeight:s=600,selectedNodeId:o,onModeChange:a,collection:l,onCollectionChange:d,collectionsAvailable:c,collectionCounts:m,className:p,style:h})=>{var S;const{t:u,convert:f}=se(),[g,y]=b.useState(i),w=$=>{y($),a==null||a($)},j=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&j.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const v=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:Tx,children:[t.jsx("button",{onClick:()=>w("list"),style:Pr(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>w("graph"),style:Pr(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:r.bim("muted"),marginRight:4},children:u("lineage.collectionLabel")}),j.map(([$,N])=>{const z=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Pr(l===$),title:N.description?f(N.description):void 0,children:[f(N.label),z!=null?` ${z}`:""]},$)})]})]}),x&&v&&t.jsx("div",{style:{fontSize:12,color:r.bim("muted"),marginBottom:8,padding:"4px 8px",background:r.bim("bg-subtle"),borderRadius:4},children:f(v)}),g==="list"?t.jsx(xd,{graph:e,renderLink:n}):t.jsx(yd,{graph:e,renderLink:n,height:s,selectedNodeId:o})]})},Tx={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Pr=e=>({padding:"4px 12px",fontSize:12,border:`1px solid ${r.bim("widget-border")}`,borderRadius:4,background:e?r.bim("primary"):"transparent",color:e?r.bim("primary-fg"):r.bim("fg"),cursor:"pointer"}),il=40,nl=2,Ix=9,Mx=new Set(["certain","consensus","probable","disputed"]);function Or(e){if(!e)return["",""];const i=e.split(/[ ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const jd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Je,ut,Ve,ht,Ge,k,Q,J,pe,Pe;const h=r.useT(),{t:u,convert:f}=se(),[g,y]=b.useState(null),[w,j]=b.useState(new Map),[x,v]=b.useState([]),[S,$]=b.useState(new Map),[N,z]=b.useState(!1),[R,O]=b.useState("flow"),[C,I]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let T=!1;return i.getItem(e.work_id).then(fe=>{!T&&fe&&fe.type==="work"&&y(fe)}).catch(()=>{}),()=>{T=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){I(null);return}let T=!1;return i.getLineageGraph(e.work_id).then(fe=>{T||I(fe&&fe.nodes.length>1?fe:null)}).catch(()=>{T||I(null)}),()=>{T=!0}},[i,e.work_id]),b.useEffect(()=>{const T=e._collections||[];if(!i||T.length===0){j(new Map);return}let fe=!1;return Promise.all(T.map(V=>{const Ne=V.id;return i.getItem(Ne).then(je=>[Ne,je]).catch(()=>[Ne,null])})).then(V=>{if(fe)return;const Ne=new Map;for(const[je,Ie]of V)Ie&&Ne.set(je,Ie);j(Ne)}),()=>{fe=!0}},[i,e._collections]);const D=b.useMemo(()=>{const T=new Set([...g?gs(g):[],...mu(e)]);return T.add(e.id),[...T]},[g,e.related_books,e.id]),A=D.length-1;b.useEffect(()=>{if(!i||A<=0){v([]);return}const T=D.length<=il,fe=T?D:D.slice(0,8);let V=!1;return Promise.all(fe.map(Ne=>Ne===e.id?Promise.resolve({id:Ne,title:e.title,edition:e.edition,year:Rn(e)}):i.getItem(Ne).then(je=>{const Ie=je??{};return{id:Ne,title:Ie.title,edition:Ie.edition,year:je?Rn(Ie):void 0}}).catch(()=>({id:Ne})))).then(Ne=>{if(V)return;const je=Ne.filter(Ie=>Ie.id===e.id||Ie.title||Ie.edition);T&&je.sort((Ie,Qe)=>(Ie.year??1/0)-(Qe.year??1/0)),v(je)}),()=>{V=!0}},[i,D,A,e]),e.lineage;const X=b.useMemo(()=>[...Gt(e).filter(T=>T.ref_type==="book").map(T=>T.ref),...mi(e).map(T=>T.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||X.length===0){$(new Map);return}let T=!1;return Promise.all(X.map(fe=>i.getItem(fe).then(V=>[fe,{id:fe,title:V==null?void 0:V.title,edition:V==null?void 0:V.edition}]).catch(()=>[fe,{id:fe}]))).then(fe=>{T||$(new Map(fe))}),()=>{T=!0}},[i,X]);const B=b.useMemo(()=>bd(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),ae=B.groups.reduce((T,fe)=>T+fe.rows.length+fe.mirrors.length,0),te=B.groups.length>0&&B.groups.every(T=>T.key==="_physical"),ce=qi(e),be=Rl(e),oe=qt(e,h.unit.juan),K=new Set((e._collections||[]).map(T=>Hi(T.vol).length).filter(T=>T>0)),ze=T=>{var Ne;const fe=(Ne=e.base_edition)==null?void 0:Ne.find(je=>je.book_id===T&&je.name);if(fe!=null&&fe.name)return fe.name;const V=S.get(T);return(V==null?void 0:V.edition)||(V==null?void 0:V.title)||""},F=b.useMemo(()=>{var et,yt;const T=[];be&&T.push({label:u("bookPage.fact.editionType"),value:f(be),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(et=e.publication_info)!=null&&et.details?T.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(ce.era||ce.reign)&&T.push({label:u("bookPage.fact.era"),value:f([ce.era,ce.reign].filter(Boolean).join(" ")),title:ce.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),oe&&T.push({label:u("bookPage.fact.measure"),value:f(oe)});const fe=(e._collections||[]).flatMap(He=>Hi(He.vol));fe.length&&T.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Wn(fe,h.unit.volume),unit:h.unit.volume,n:fe.length})});const V=Gt(e).find(He=>He.relation==="底本"&&He.ref_type==="book");V&&ze(V.ref)&&T.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(wt,{id:V.ref,label:f(ze(V.ref)),onNavigate:n,renderLink:s,dense:!0})});const Ne=(e.base_edition||[]).filter(He=>He&&He.name);for(const He of["底本","配補","參校"]){if(He==="底本"&&V&&ze(V.ref))continue;const q=Ne.filter(ke=>ke.role===He);q.length&&T.push({label:f(He),value:q.map((ke,Xe)=>t.jsxs(b.Fragment,{children:[Xe>0&&"、",ke.book_id?t.jsx(wt,{id:ke.book_id,label:f(ke.name),onNavigate:n,renderLink:s,dense:!0}):f(ke.name)]},Xe))})}const je=(e.provenance||[]).filter(He=>He&&He.institution),Ie=(e.resources||[]).filter(He=>r.getResourceTypes(He).includes("physical"));if(je.length){T.push({label:u("bookPage.fact.holdings"),value:je.slice(0,2).map(ke=>f(ke.institution)).join("、")+(je.length>2?u("bookPage.andMorePlaces",{n:je.length}):"")});const He=je.filter(ke=>ke.call_number).slice(0,2).map(ke=>`${f(ke.institution)} ${ke.call_number}`);He.length&&T.push({label:u("bookPage.fact.callNumber"),value:He.join(";")+(je.filter(ke=>ke.call_number).length>2?"…":"")});const q=je.flatMap(ke=>ke.seals||[]).filter(Boolean);q.length&&T.push({label:u("bookPage.fact.seals"),value:f(q.join("、"))})}else Ie.length&&T.push({label:u("bookPage.fact.holdings"),value:Ie.slice(0,2).map(He=>f(He.name)).join("、")+(Ie.length>2?u("bookPage.andMorePlaces",{n:Ie.length}):"")});const Qe=e.physical_description;if(Qe){const He=[[u("bookPage.fact.leafStyle"),Qe.leaf_style],[u("bookPage.fact.binding"),Qe.binding],[u("bookPage.fact.dimensions"),Qe.dimensions],[u("bookPage.fact.condition"),Qe.condition]];for(const[q,ke]of He)ke&&ke.trim()&&T.push({label:q,value:f(ke)})}(yt=e.page_count)!=null&&yt.description&&T.push({label:h.label.pageCount,value:f(e.page_count.description)});const Oe=wc(e.additional_titles);return Oe.length&&T.push({label:u("bookPage.fact.aliases"),value:Oe.map(f).join("、")}),T},[e,f,h,u,ce,be,oe,S,n,s]),me=f(e.title),U=e.edition?f(e.edition):void 0,ne=((Je=e.dating)==null?void 0:Je.text)||"",ue=t.jsx(Ji,{kind:u("bookPage.kind"),title:me,subtitle:U,byline:t.jsx(eo,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:s}),meta:(()=>{const T=[be?f(be):"",ce.era?f([ce.era,ce.reign].filter(Boolean).join("")):"",oe?f(oe):""].filter(Boolean);return T.length?t.jsx("span",{className:"bim-d-tags",children:T.map((fe,V)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(V,2)}`,children:fe},V))}):null})(),description:(ut=e.description)!=null&&ut.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Ns((Ve=e.description)==null?void 0:Ve.text)?6:void 0,facts:F,readAction:o,secondaryAction:o&&ae>0&&!te?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),G=e._collections||[],L=(a==null?void 0:a.chapters)||[],Se=f(L[0]&&Or(L[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),ge=u("bookPage.chapterCount",{n:L.length,unit:Se}),$e=!!(Gt(e).length||mi(e).length||(ht=e.appendix)!=null&&ht.length),_=[],P=u(te?"bookPage.sec.physical":"bookPage.sec.images");(L.length||B.text.length||l)&&_.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:L.length?ge:void 0}),B.groups.length&&_.push({id:"images",label:P,count:ae}),$e&&_.push({id:"lineage",label:u("bookPage.sec.lineage")}),G.length&&_.push({id:"collections",label:u("section.containedIn"),count:G.length}),(Ge=e.location_history)!=null&&Ge.length&&_.push({id:"provenance",label:u("section.locationHistory")});const ie=T=>(d==null?void 0:d(T))??null,re=L[0],Re=re?ie(re.file):null,Y=N?L:L.slice(0,Ix),de=(T,fe,V)=>T?t.jsx("a",{className:V,href:T.href??"#",onClick:T.onClick?Ne=>{Ne.metaKey||Ne.ctrlKey||(Ne.preventDefault(),T.onClick())}:void 0,children:fe}):t.jsx("span",{className:V,children:fe}),le=t.jsxs(t.Fragment,{children:[(L.length>0||B.text.length>0||l)&&t.jsxs($t,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:L.length>0?t.jsx(vt,{items:[ge,(k=a==null?void 0:a.source)!=null&&k.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!re&&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"})]}),re&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Or(re.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((re.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),de(Re,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),L.length>1&&t.jsx("ul",{className:"bim-d-chap",children:Y.map(T=>{const[fe,V]=Or(T.title);return t.jsx("li",{children:de(ie(T.file),t.jsxs(t.Fragment,{children:[fe&&t.jsx("b",{children:f(fe)}),f(V||T.file)]}))},T.file)})}),L.length>Y.length&&t.jsx(_s,{label:u("detail.expandRest",{n:L.length-Y.length,unit:Se}),onClick:()=>z(!0)}),B.text.length>0&&t.jsxs(t.Fragment,{children:[(L.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:B.text.map((T,fe)=>t.jsx(to,{item:T,siblings:B.text,listedVolumeCounts:K},`${T.id||T.url||T.name}-${fe}`))})})]})]}),B.groups.length>0&&t.jsx($t,{id:"images",title:P,meta:t.jsx(vt,{items:[B.groups.length>1?u("bookPage.groupCount",{n:B.groups.length}):"",u("bookPage.placeCount",{n:ae})]}),children:t.jsx(fd,{groups:B.groups,listedVolumeCounts:K})}),$e&&t.jsx($t,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Gt(e).length?u("bookPage.lineageMeta"):void 0,action:C?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":R==="flow",onClick:()=>O("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":R==="graph",onClick:()=>O("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:R==="graph"&&C?t.jsx(io,{graph:C,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(T,fe)=>t.jsx(wt,{id:T,label:f(fe),onNavigate:n,renderLink:s,dense:!0})}):t.jsx(Lx,{data:e,heading:U||me,yearText:ne,refName:ze,onNavigate:n,renderLink:s})}),G.length>0&&t.jsx($t,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:G.map((T,fe)=>{const V=T.id,Ne=Hi(T.vol),je=w.get(V),Ie=Mu(je);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:V,label:je?f(je.title):V,onNavigate:n,renderLink:s,dense:!0}),Ne.length>0&&t.jsx(Ax,{volumes:Ne,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Ie?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Ie>0&&u("bookPage.totalOf",{n:Ie,unit:h.unit.bu})})]},`${V}-${fe}`)})})})}),(Q=e.location_history)!=null&&Q.length?t.jsx($t,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((T,fe)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(T.name||T.location||"")}),([T.start_date,T.end_date].filter(Boolean).join("—")||T.description||T.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[T.start_date,T.end_date].filter(Boolean).join("—"),T.description?f(T.description):"",T.note?f(T.note):""]})})]},fe))})}):null,_.length===0&&t.jsx($t,{title:u("bookPage.sec.empty"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:u("bookPage.emptyText")})})]}),Te=x.findIndex(T=>T.id===e.id),_e=D.length<=il,xe=_e&&Te>=0?x.slice(Math.max(0,Te-nl),Te+nl+1):x.filter(T=>T.id!==e.id),Ce=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(wt,{id:g.id,label:f(g.title),onNavigate:n,renderLink:s})}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[...(g.authors||[]).slice(0,2).map(T=>`${T.dynasty?`〔${f(T.dynasty)}〕`:""}${f(T.name)}`),f(qt(g,h.unit.juan)),g._edition_count??((J=g._books)==null?void 0:J.length)?u("bookPage.editionCount",{n:g._edition_count??((pe=g._books)==null?void 0:pe.length)??0}):""]}),((Pe=g.description)==null?void 0:Pe.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,""))})]}),A>0&&xe.length>0&&t.jsxs("div",{children:[t.jsx(di,{id:"siblings",timeline:!0,title:_e?u("bookPage.siblings"):h.relation.siblingVersions,meta:_e?u("bookPage.byEra"):u("bookPage.kindCount",{n:A}),cap:xe.length,items:xe.map(T=>T.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(T.edition||T.title||T.id)}):t.jsx(wt,{id:T.id,label:f(T.edition||T.title||T.id),onNavigate:n,renderLink:s,dense:!0})),metas:xe.map(T=>[T.year!=null?T.year<0?u("detail.bce",{n:-T.year}):String(T.year):"",T.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:xe.findIndex(T=>T.id===e.id)}),g&&t.jsx("div",{className:"bim-d-ui bim-d-side-all",style:{marginTop:4,fontSize:13},children:t.jsx(wt,{id:g.id,label:u("bookPage.viewAllInWork",{n:D.length}),onNavigate:n,renderLink:s,dense:!0})})]})]}),Ae=e.work_id?t.jsx(cc,{caption:h.section.belongsToWork,children:t.jsx(wt,{id:e.work_id,label:g?f(g.title):" ",onNavigate:n,renderLink:s,dense:!0})}):void 0;return t.jsx(Xi,{railTop:c,back:m,up:Ae,nav:_,railLinks:p,main:le,card:ue,side:Ce})};function Ax({volumes:e,unit:i}){const{t:n}=se();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Wn(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 Lx({data:e,heading:i,yearText:n,refName:s,onNavigate:o,renderLink:a}){var j;const{t:l,convert:d}=se(),c=e.lineage,m=Gt(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=mi(e),g=m.length>0||f.length>0,y=x=>x&&Mx.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",w=(x,v)=>t.jsx(wt,{id:x,label:d(v||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,v)=>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-${v}`)),h.map((x,v)=>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:w(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${v}`)),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,v)=>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:w(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},v))})]}),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,v)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[w(x.book_id,s(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},v))})]})]}),(j=e.appendix)==null?void 0:j.map((x,v)=>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-${v}`)),(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 Pi=16,Px=200,Ox=16,kd=({data:e,catalog:i,transport:n,onNavigate:s,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var _e,xe,Ce,Ae,Je,ut,Ve,ht,Ge;const{t:m,convert:p,messages:h}=se(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[w,j]=b.useState(null),[x,v]=b.useState(""),[S,$]=b.useState(!1),N=b.useMemo(()=>El(e,i),[e,i]),z=b.useMemo(()=>Cl(e),[e]),[R,O]=b.useState(new Map),C=!!n&&N.rows.length>0&&N.rows.length<=Px,I=C&&(N.rows.length<=Pi||S),D=I&&N.rows.every(k=>!k.id||R.has(k.id)),A=k=>{var Q;return os(k?(Q=R.get(k))==null?void 0:Q.l1:void 0)},X=b.useMemo(()=>{const k=u.trim(),Q=k?p(k):"";return N.rows.filter(J=>{var Pe,T;if(x&&os(J.id?(Pe=R.get(J.id))==null?void 0:Pe.l1:void 0)!==x)return!1;if(!Q)return!0;const pe=J.id&&((T=R.get(J.id))==null?void 0:T.title)||J.title;return p(pe).includes(Q)||(J.subItems||[]).some(fe=>p(fe).includes(Q))})},[N.rows,u,x,R,p]),B=g?X:X.slice(0,Pi),ae=b.useMemo(()=>(I?N.rows:B).filter(k=>k.id&&!R.has(k.id)).map(k=>k.id),[I,N.rows,B,R]);b.useEffect(()=>{if(!n||ae.length===0)return;let k=!1;const Q=ae.slice(0,Ox);return Qn(Q,Zn,J=>n.getItem(J).then(pe=>{var fe,V;const Pe=pe??{},T={title:Pe.title,edition:Pe.edition,authors:Pe.authors,measure:pe?qt(pe,h.unit.juan):void 0,versionCount:Pe._edition_count??((fe=Pe._books)==null?void 0:fe.length),l1:((V=xs(Pe))==null?void 0:V.l1)||void 0};return[J,T]}).catch(()=>[J,{}]),()=>k).then(J=>{k||O(pe=>{const Pe=new Map(pe);for(const[T,fe]of J)Pe.set(T,fe);return Pe})}),()=>{k=!0}},[n,ae,h.unit.juan]);const te=(_e=(e.contained_in||[])[0])==null?void 0:_e.id;b.useEffect(()=>{if(!te){j(null);return}if(j({id:te}),!n)return;let k=!1;return n.getItem(te).then(Q=>{k||j({id:te,title:Q==null?void 0:Q.title})}).catch(()=>{}),()=>{k=!0}},[n,te]);const ce=b.useMemo(()=>bd(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),be=ce.text.length+ce.groups.reduce((k,Q)=>k+Q.rows.length+Q.mirrors.length,0),oe=z.works,K=new Set(N.rows.map(k=>k.id).filter(Boolean)),ze=oe.length>0&&!oe.every(k=>K.has(k.id)),F=(()=>{const k=N.rows.map(Q=>Q.edition).filter(Boolean);return k.length>1&&new Set(k).size===1})(),me=N.rows.some(k=>k.volumes.length>0||k.expected!=null),U=z.total,ne=z.truncated?U:N.rows.length,ue=qt(e,h.unit.juan),G=e.count,L=k=>typeof k=="number"&&Number.isFinite(k)?k:null,Se=L(G==null?void 0:G.juan)??L((xe=e.juan_count)==null?void 0:xe.number)??L((Ae=(Ce=e.measures)==null?void 0:Ce.find(k=>(k==null?void 0:k.unit)==="卷"))==null?void 0:Ae.number),ge=L(G==null?void 0:G.ce)??(N.totalVolumes||null),$e=[{value:ne,label:m("collectionPage.stat.titles")},{value:Se??0,label:h.unit.juan},{value:ge??0,label:h.unit.volume}],_=b.useMemo(()=>{var J,pe;const k=[];if((J=e.publication_info)!=null&&J.details&&k.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),U&&(U!==N.rows.length||z.truncated)){const Pe=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");k.push({label:Pe,value:`${U} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const Q=[L(G==null?void 0:G.zhong)!=null?m("collectionPage.nZhong",{n:G.zhong}):"",L(G==null?void 0:G.han)!=null?m("collectionPage.nHan",{n:G.han}):""].filter(Boolean);return Q.length&&k.push({label:m("collectionPage.fact.expected"),value:Q.join(" ")}),Se==null&&ue&&k.push({label:m("collectionPage.fact.measure"),value:p(ue),title:(pe=e.juan_count)!=null&&pe.description?p(e.juan_count.description):void 0}),k},[e,U,z.truncated,N.rows.length,Se,ue,G,p,m,h]),P=b.useMemo(()=>{if(!D)return[];const k=new Map;for(const J of N.rows){const pe=A(J.id);pe&&k.set(pe,(k.get(pe)??0)+1)}const Q=Ui.filter(J=>(k.get(J.key)??0)>0);return Q.length<2?[]:[{key:"",label:`${h.catalog.all} ${ne}`},...Q.map(J=>({key:J.key,label:`${J.label} ${k.get(J.key)}`}))]},[D,N.rows,R,h]),ie=b.useMemo(()=>{if(!D||!N.rows.some(pe=>pe.volumes.length>0))return null;const k=[],Q=N.rows.filter(pe=>pe.volumes.length>0).map(pe=>({k:A(pe.id)??"",from:Math.min(...pe.volumes),to:Math.max(...pe.volumes)})).sort((pe,Pe)=>pe.from-Pe.from);for(const pe of Q){const Pe=pe.to-pe.from+1,T=k[k.length-1];T&&T.key===pe.k?(T.to=Math.max(T.to,pe.to),T.n+=Pe):k.push({key:pe.k,from:pe.from,to:pe.to,n:Pe})}const J=Q.reduce((pe,Pe)=>Math.max(pe,Pe.to),0);return k.length>1&&k.some(pe=>pe.key)?{segs:k,last:J}:null},[D,N.rows,R]),re=(Je=e.description)==null?void 0:Je.text,Re=t.jsx(Ji,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(eo,{authors:e.authors,onNavigate:s,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(ut=e.publication_info)!=null&&ut.year?p(e.publication_info.year):""]}),description:re||(Ve=e.history)!=null&&Ve.length?t.jsxs(t.Fragment,{children:[re&&t.jsx(zi,{text:re,style:{fontSize:15,lineHeight:1.85}}),(ht=e.history)!=null&&ht.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((k,Q)=>t.jsx("li",{children:p(k)},Q))}):null]}):void 0,clampDescription:Ns(re)||(((Ge=e.history)==null?void 0:Ge.length)??0)>2?6:void 0,stats:$e,facts:_,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:ie&&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:ie.segs.map((k,Q)=>{const J=Ui.find(pe=>pe.key===k.key);return t.jsx("button",{type:"button",className:"bim-d-dist-seg",disabled:!J,title:J?m("collectionPage.dist.segTitle",{section:p(J.label),from:k.from,to:k.to}):void 0,"aria-label":J?m("collectionPage.dist.only",{section:p(J.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!J&&x===k.key,style:{flexGrow:k.n,background:J?r.bim(J.token):r.bim("rule")},onClick:()=>{J&&(v(x===k.key?"":k.key),y(!1))}},Q)})}),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:ie.last})})]})]})}),Y=[];N.rows.length&&Y.push({id:"titles",label:m("collectionPage.sec.titles"),count:ne}),be&&Y.push({id:"resources",label:m("collectionPage.sec.resources"),count:be}),ze&&Y.push({id:"works",label:h.section.containedWorks,count:oe.length});const de=t.jsxs(t.Fragment,{children:[N.rows.length>0&&t.jsxs($t,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${ne} ${h.unit.items}`,N.totalVolumes?m("collectionPage.totalVolumes",{n:N.totalVolumes,unit:h.unit.volume}):"",X.length!==ne?m("collectionPage.currentN",{n:X.length,unit:h.unit.items}):""]}),action:a,children:[(N.rows.length>Pi||P.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[P.length>0&&t.jsx(Gn,{items:P,value:x,onChange:k=>{v(k),y(!1)}}),C&&N.rows.length>Pi&&!D&&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>Pi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:k=>{f(k.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&qn(X.length)?"":void 0,children:[t.jsx("thead",{className:"bim-d-ui",children:t.jsxs("tr",{children:[me&&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:B.map((k,Q)=>{var Ne;const J=k.id?R.get(k.id):void 0,pe=J!=null&&J.title&&k.title===k.id?J.title:k.title,Pe=((J==null?void 0:J.authors)||[]).find(je=>je&&je.name),T=[Pe?`${Pe.dynasty?`〔${p(Pe.dynasty)}〕`:""}${p(Pe.name)}${Pe.role?` ${p(Pe.role)}`:""}`:"",J!=null&&J.measure?p(J.measure):"",(Ne=k.subItems)!=null&&Ne.length?k.subItems.map(je=>p(je)).join("、"):"",(J!=null&&J.edition||k.edition)&&!F?p((J==null?void 0:J.edition)||k.edition||""):""].filter(Boolean),fe=Ui.find(je=>je.key===A(k.id)),V=k.volumes.length>0?m("collectionPage.volumeRange",{range:Wn(k.volumes,h.unit.volume),unit:h.unit.volume}):k.expected!=null?`${k.found??0}/${k.expected} ${h.unit.volume}`:"";return t.jsxs("tr",{children:[me&&t.jsxs("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${V?"":" bim-d-zt-blank"}`,children:[fe&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r.bim(fe.token)}}),V||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[k.id?t.jsx(wt,{id:k.id,label:p(pe),onNavigate:s,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(pe)}),T.length>0?t.jsx(vt,{items:T}):k.id&&!J&&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${J!=null&&J.versionCount?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:J!=null&&J.versionCount?m("collectionPage.nZhong",{n:J.versionCount}):""})]},`${k.id??k.title}-${Q}`)})})]}),B.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:m("catalog.noMatch")}),!g&&t.jsx($s,{total:X.length,shown:B.length,unit:h.unit.items,onClick:()=>y(!0)})]}),be>0&&t.jsxs($t,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:be}),children:[ce.text.length>0&&t.jsxs("div",{className:"bim-d-rg",children:[ce.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:ce.text.map((k,Q)=>t.jsx(to,{item:k,siblings:ce.text},`${k.id||k.url||k.name}-${Q}`))})})]}),t.jsx(fd,{groups:ce.groups})]}),N.rows.length===0&&be===0&&t.jsx($t,{title:m("collectionPage.sec.titles"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:m("collectionPage.empty")})})]}),le=ze?t.jsx(di,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:oe.length}),cap:12,items:oe.map(k=>t.jsx(wt,{id:k.id,label:p(k.title),onNavigate:s,renderLink:o,dense:!0}))}):null,Te=w?t.jsx(cc,{caption:m("collectionPage.parent"),children:t.jsx(wt,{id:w.id,label:p(w.title||w.id),onNavigate:s,renderLink:o,dense:!0})}):void 0;return t.jsx(Xi,{railTop:l,back:d,up:Te,nav:Y,railLinks:c,main:de,card:Re,side:le})},Fx=8;function wd(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function Bx(e){return(e||[]).filter(i=>{var n,s;return wd(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((s=i.license)==null?void 0:s.trim())}).slice(0,Fx)}function Hx({images:e,assetBase:i,name:n}){const{t:s,convert:o}=se(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?Bx(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+wd(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:s("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":`${s("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:[s("entityPage.imgCredit",{credit:o(h.credit)})," · ",s("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:s("entityPage.imgSource")})]}),h.note&&t.jsxs(t.Fragment,{children:[" · ",o(h.note)]})]})]})}const rl=8,sl=10,ol=30,vd=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function Dx(e){return`${vd(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function Wx(e,i,n){var s;return`${vd(i,n.key,n.chapter)}#e=${((s=n.ids)!=null&&s.length?n.ids:[e]).join(",")}`}const Ux=({id:e,transport:i,renderLink:n,onTotal:s})=>{const{t:o,convert:a}=se(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(rl),[u,f]=b.useState(sl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),w=b.useRef(s);if(w.current=s,b.useEffect(()=>{if(d(null),m("idle"),h(rl),f(sl),!y)return;const $=g.current;let N=!1;const z=()=>{m("loading"),i.getMentions(e).then(O=>{var I,D;if(N)return;const C=O&&"books"in O?O:null;if(!C||!C.total){m("none"),(I=w.current)==null||I.call(w,0);return}d(C),m("ok"),(D=w.current)==null||D.call(w,C.total)}).catch(()=>{N||m("none")})};if(!$||typeof IntersectionObserver>"u")return z(),()=>{N=!0};const R=new IntersectionObserver(O=>{O.some(C=>C.isIntersecting)&&(R.disconnect(),z())},{rootMargin:"400px"});return R.observe($),()=>{N=!0,R.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const j=($,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])),v=(l==null?void 0:l.examples)??[],S=(l==null?void 0:l.books)??[];return t.jsx("div",{ref:g,children:t.jsxs($t,{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&&v.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:v.slice(0,p).map(($,N)=>{const z=[x.get($.item),$.heading].filter(Boolean).map(O=>a(O)).join(" · "),R=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:j(Dx($),R,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${N}`)})}),v.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(v.length),children:o("mentions.more",{n:v.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(Kx,{entityId:e,book:$,open:S.length===1,transport:i,link:j},$.item))}),S.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+ol),children:o("mentions.moreBooks",{n:Math.min(ol,S.length-u)})})]})]})})},Kx=({entityId:e,book:i,open:n,transport:s,link:o})=>{const{t:a,convert:l}=se(),[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||!(s!=null&&s.getMentions)||(p(!0),s.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(Wx(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}`))})]})})},Yx=16,Fr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function al(e){if(!e)return Fr.length;const i=Fr.indexOf(e);return i===-1?Fr.length:i}function Vx(e,i,n){if(i)return e[i]??n(i)}function Gx(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const qx={秦:[-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]},Sd=({data:e,transport:i,onNavigate:n,renderLink:s,railTop:o,back:a,railLinks:l,assetBase:d})=>{var Ae,Je,ut,Ve,ht,Ge;const{t:c,convert:m,messages:p}=se(),h=k=>Gx(k,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[w,j]=b.useState("default"),[x,v]=b.useState(new Map),[S,$]=b.useState(0),N=b.useMemo(()=>e._works||[],[e._works]),z=b.useMemo(()=>N.map(k=>{const Q=x.get(k.work_id);return{id:k.work_id,title:(Q==null?void 0:Q.title)??k.title??k.work_id,role:k.role||"",cls:hs(k.role),versionCount:Q==null?void 0:Q.versionCount,section:Q==null?void 0:Q.cls,l1:Q==null?void 0:Q.l1,measure:Q==null?void 0:Q.measure,hasImage:Q==null?void 0:Q.hasImage,loaded:!!(Q!=null&&Q.loaded)}}),[N,x]),R=b.useMemo(()=>zl(N.map(k=>k.role),c("detail.roleAll")),[N,c]),O=b.useMemo(()=>{const k=u==="全部"?z:z.filter(Q=>Q.cls===u);return w==="versions"?[...k].sort((Q,J)=>(J.versionCount??-1)-(Q.versionCount??-1)):k},[z,u,w]),C=g?O:O.slice(0,Yx),I=b.useMemo(()=>C.filter(k=>!x.has(k.id)).map(k=>k.id),[C,x]);b.useEffect(()=>{if(!i||I.length===0)return;let k=!1;return Qn(I,Zn,Q=>i.getItem(Q).then(J=>{var V;const pe=J??{},Pe=pe._edition_count??((V=pe._books)==null?void 0:V.length)??0,T=xs(pe),fe=[T==null?void 0:T.l1,T==null?void 0:T.l2].filter(Boolean).join(" ");return[Q,{id:Q,title:pe.title,versionCount:Pe,loaded:!0,cls:fe||void 0,l1:(T==null?void 0:T.l1)||void 0,measure:J&&qt(J,p.unit.juan)||void 0,hasImage:!!pe._has_image}]}).catch(()=>[Q,{id:Q,loaded:!0}]),()=>k).then(Q=>{k||v(J=>{const pe=new Map(J);for(const[Pe,T]of Q)pe.set(Pe,T);return pe})}),()=>{k=!0}},[i,I,p.unit.juan]);const D=b.useMemo(()=>{const k=new Map;for(const Q of e.alt_names||[]){const J=Q.type||p.section.aliases;k.has(J)||k.set(J,[]),k.get(J).push(Q.name)}return[...k.entries()].sort((Q,J)=>al(Q[0])-al(J[0])).map(([Q,J])=>({label:Q,names:J}))},[e.alt_names,p]),A=((Ae=e.dates)==null?void 0:Ae.birth)??void 0,X=((Je=e.dates)==null?void 0:Je.death)??void 0,B=(ut=e.dates)==null?void 0:ut.floruit,ae=A!=null||X!=null?`${h(A)||"?"}—${h(X)||"?"}`:Array.isArray(B)&&B.length===2&&B.every(k=>Number.isFinite(k))?c("entityPage.floruit",{from:h(B[0]),to:h(B[1])}):"",te=new Set(["本名","字","號","号"]),ce=D.filter(k=>te.has(k.label)),be=D.filter(k=>!te.has(k.label)),oe=be.reduce((k,Q)=>k+Q.names.length,0),K=b.useMemo(()=>{const k=[];for(const J of ce)k.push({label:J.label,value:J.names.map(pe=>m(pe)).join("、")});const Q=N.length;return Q&&k.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:Q})}),k},[N,ce,m,c]),ze=k=>{var Q;return(Q=D.find(J=>k.includes(J.label)))==null?void 0:Q.names[0]},F=ze(["字"]),me=ze(["號","号"]),U=[F?c("entityPage.zi",{name:m(F)}):"",me?c("entityPage.hao",{name:m(me)}):""].filter(Boolean).join(","),ne=e.native_place,ue=e.dynasty?qx[e.dynasty]:void 0,G=(()=>{if(!ue||A==null||X==null||X<A)return null;const[k,Q]=ue,J=Math.max(A,k),pe=Math.min(X,Q);if(pe<=J)return null;const Pe=Q-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(A),death:h(X),years:X-A+1}),children:t.jsx("i",{style:{left:`${(J-k)/Pe*100}%`,width:`${(pe-J)/Pe*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:X-A+1})}),t.jsx("span",{children:h(Q)})]})]})})(),L=b.useMemo(()=>{if(!i||z.length===0||z.some(J=>!J.loaded))return null;const k=new Map;for(const J of z){const pe=os(J.l1);pe&&k.set(pe,(k.get(pe)??0)+1)}const Q=Ui.map(J=>({...J,n:k.get(J.key)??0})).filter(J=>J.n>0);return Q.length?Q:null},[z,i]),Se=t.jsxs(Ji,{kind:Vx(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:U||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",ae,ne?c("entityPage.nativePlace",{place:m(ne)}):""]}),G,t.jsx(Hx,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(Ve=e.description)!=null&&Ve.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Ns((ht=e.description)==null?void 0:ht.text)?6:void 0,facts:K,foot:t.jsx(Zi,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[oe>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:oe})}),t.jsx("dl",{children:be.map(k=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(k.label)}),t.jsx("dd",{children:k.names.map(Q=>m(Q)).join("、")})]},k.label))})]}),L&&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:L.map(k=>t.jsx("i",{style:{flexGrow:k.n,background:r.bim(k.token)}},k.key))}),t.jsx("div",{className:"bim-d-dist-key",children:L.map(k=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r.bim(k.token)}}),m(k.label)," ",k.n]},k.key))})]})]}),ge=b.useMemo(()=>z.filter(k=>k.loaded&&(k.versionCount??0)>0).sort((k,Q)=>(Q.versionCount??0)-(k.versionCount??0)).slice(0,3),[z]),$e=!!i&&z.length>=3&&C.some(k=>!k.loaded),_=u==="全部"&&($e||ge.length>=2),P=e.external_ids||{},ie=((Ge=e.external_ids_meta)==null?void 0:Ge.cbdb_match)??P.cbdb_match,re=[];P.cbdb_id!=null&&re.push({label:"CBDB",id:String(P.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${P.cbdb_id}`,note:ie==="auto"?c("entityPage.autoMatch"):void 0});const Re=P.wikidata_id;Re&&re.push({label:"Wikidata",id:Re,href:`https://www.wikidata.org/wiki/${Re}`});const Y=P.viaf_id;Y&&re.push({label:"VIAF",id:Y,href:`https://viaf.org/viaf/${Y}`});const de=R.map(k=>({key:k.cls,label:`${k.label} ${k.count}`})),le=e.id?t.jsx(Ux,{id:e.id,transport:i,onTotal:$}):null,Te=[..._&&!$e?[{id:"featured",label:c("entityPage.sec.featured"),count:ge.length}]:[],...z.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:z.length}]:[],...S?[{id:"mentions",label:c("mentions.title"),count:S}]:[],...re.length?[{id:"external",label:c("entityPage.sec.external"),count:re.length}]:[]],_e=_?t.jsxs($t,{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":$e||void 0,children:[$e&&[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)),!$e&&ge.map(k=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(wt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:s,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,xe=z.length===0?t.jsxs(t.Fragment,{children:[t.jsx($t,{title:c("entityPage.sec.works"),children:t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:0},children:c("entityPage.empty")})}),le]}):t.jsxs(t.Fragment,{children:[_e,t.jsxs($t,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:z.length}),O.length!==z.length?c("entityPage.current",{n:O.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[de.length>1&&t.jsx(Gn,{items:de,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":w==="versions",onClick:()=>{w==="default"&&y(!0),j(k=>k==="default"?"versions":"default")},children:c(w==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&qn(O.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:C.map(k=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:k.id,label:m(k.title),onNavigate:n,renderLink:s,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))})]}),C.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx($s,{total:O.length,shown:C.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),le]}),Ce=re.length>0?t.jsx(di,{id:"external",title:c("entityPage.sec.external"),items:re.map(k=>t.jsxs("a",{href:k.href,target:"_blank",rel:"noopener noreferrer",children:[k.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:re.map(k=>k.id),foot:P.cbdb_id!=null&&ie==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Xi,{railTop:o,back:a,nav:Te,railLinks:l,main:xe,card:Se,side:Ce})},no="(max-width: 719px)",Xx=`${no}, (pointer: coarse)`,$d=`
|
|
1555
1555
|
.bim-ct {
|
|
1556
1556
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
1557
1557
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -1659,7 +1659,7 @@ ${Re??""}`,[Ei,mo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)mo({ke
|
|
|
1659
1659
|
.bim-ct-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
1660
1660
|
}
|
|
1661
1661
|
|
|
1662
|
-
@media ${
|
|
1662
|
+
@media ${no} {
|
|
1663
1663
|
.bim-ct { display: block; padding: 12px 16px 40px; }
|
|
1664
1664
|
.bim-ct-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
|
|
1665
1665
|
.bim-ct-lrow > a { grid-template-columns: minmax(0, 1fr); }
|
|
@@ -1684,7 +1684,7 @@ ${Re??""}`,[Ei,mo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)mo({ke
|
|
|
1684
1684
|
}
|
|
1685
1685
|
|
|
1686
1686
|
/* 点击目标 ≥44px(Q5):触屏与窄屏 */
|
|
1687
|
-
@media ${
|
|
1687
|
+
@media ${Xx} {
|
|
1688
1688
|
.bim-ct-row { min-height: 44px; }
|
|
1689
1689
|
.bim-ct-tw { width: 44px; }
|
|
1690
1690
|
.bim-ct-pg { min-width: 44px; height: 44px; }
|
|
@@ -1710,7 +1710,7 @@ ${Re??""}`,[Ei,mo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)mo({ke
|
|
|
1710
1710
|
/* 窄屏分类抽屉:界栏下按钮和面板都有框 */
|
|
1711
1711
|
:root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${r.bim("fr-bd")}; background: ${r.bim("fr-bg")}; }
|
|
1712
1712
|
:root[data-layout="boxed"] .bim-ct-drawer { border: ${r.bim("fr-bd")}; }
|
|
1713
|
-
`,ci="未分類",Vt="all",io=20;function en(e){if(!e)return[];const i=[];for(const n of[e.l1,e.l2,e.l3,e.l4]){const s=(n??"").trim();if(!s)break;i.push(s)}return i}function Dx(e){const i=en(e);return i.length?i.join("/"):ci}function Wx(e){const i=en(e);return i.length?i.map((n,s)=>i.slice(0,s+1).join("/")):[ci]}function Ux(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 s=new Map;let o=0;for(const d of e){const c=en(d.classification);if(!c.length){o++;continue}let m=s;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===ci?1:0,h=m.label===ci?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(s);return o>0&&l.push({id:ci,label:ci,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 s=wi(n.children,i);if(s.length)return[n,...s]}}return[]}function no(e){return e.reduce((i,n)=>i+n.count,0)}function Kx(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function Yx(e){var d,c,m;const i={id:e.id,title:e.title||e.id},n=e.juan_count,s=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 s=="number"&&s>0?i.juan=s: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=Kx(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=en(e.classification);return l.length&&(i.classification=l),i}function Vx(e,i){const n=e.summary?0:1,s=i.summary?0:1;return n!==s?n-s:e.title.localeCompare(i.title,"zh")}function Gx(e,i=io){return Math.max(1,Math.ceil(e/i))}function wd(e,i,n=2){if(i<=1)return[1];const s=new Set([1,i]);for(let l=e-n;l<=e+n;l++)l>=1&&l<=i&&s.add(l);const o=[...s].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 qx=()=>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 Xx(e,i,n){const s=[];n&&s.push({id:Vt,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;s.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),s}function vd({tree:e,selectedId:i,onSelect:n,allLabel:s,label:o}){const{t:a,convert:l}=se(),d=s===void 0?a("catalogPage.all"):s,c=o??a("catalogPage.classification"),m=b.useRef(null),p=i&&i!==Vt?i:null,h=d!==null,[u,f]=b.useState(()=>{const E=new Set;for(const B of wi(e,p))E.add(B.id);return E});b.useEffect(()=>{const E=wi(e,p);E.length&&f(B=>{if(E.every(I=>B.has(I.id)))return B;const T=new Set(B);for(const I of E)T.add(I.id);return T})},[e,p]);const g=b.useMemo(()=>Xx(e,u,h),[e,u,h]),[y,w]=b.useState(null);b.useEffect(()=>{w(null)},[i]);const j=p??(h?Vt:null),x=b.useMemo(()=>{var T;const E=new Set(g.map(I=>I.id));if(y&&E.has(y))return y;if(j&&E.has(j))return j;const B=wi(e,p).map(I=>I.id).filter(I=>E.has(I));return B.length?B[B.length-1]:((T=g[0])==null?void 0:T.id)??null},[g,y,j,e,p]),S=b.useCallback((E,B)=>{f(T=>{const I=T.has(E),H=B??!I;if(H===I)return T;const M=new Set(T);return H?M.add(E):M.delete(E),M})},[]),v=b.useCallback(E=>{w(E),requestAnimationFrame(()=>{var T;const B=Array.from(((T=m.current)==null?void 0:T.querySelectorAll("[data-ct-id]"))??[]).find(I=>I.dataset.ctId===E);B==null||B.focus()})},[]),$=b.useCallback((E,B)=>{B&&S(E,!0),n(E)},[n,S]),N=b.useCallback(E=>{const B=E.target.closest("[data-ct-id]");if(!B)return;const T=B.dataset.ctId,I=g.findIndex(q=>q.id===T);if(I<0)return;const H=g[I];let M=null;switch(E.key){case"ArrowDown":M=g[Math.min(g.length-1,I+1)].id;break;case"ArrowUp":M=g[Math.max(0,I-1)].id;break;case"Home":M=g[0].id;break;case"End":M=g[g.length-1].id;break;case"ArrowRight":if(!H.hasChildren)break;u.has(T)?M=H.firstChildId:S(T,!0);break;case"ArrowLeft":H.hasChildren&&u.has(T)?S(T,!1):M=H.parentId;break;case"Enter":case" ":E.preventDefault(),$(T,H.hasChildren);return;default:return}E.preventDefault(),M&&M!==T&&v(M)},[g,u,S,v,$]),_=(E,B)=>E.map((T,I)=>{var ie;const H=(ie=T.children)!=null&&ie.length?T.children:null,M=!!H&&u.has(T.id),q=T.id===p,O=B===1&&E.length>1&&I===E.length-1;return t.jsxs("li",{role:"treeitem","aria-level":B,"aria-expanded":H?M:void 0,"aria-selected":q,tabIndex:x===T.id?0:-1,"data-ct-id":T.id,className:O?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":B-1},onClick:()=>{w(T.id),$(T.id,!!H)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:H?oe=>{oe.stopPropagation(),w(T.id),S(T.id)}:void 0,children:H?t.jsx(qx,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(T.label)}),t.jsx("span",{className:"bim-ct-n",children:T.count.toLocaleString("en-US")})]}),M&&t.jsx("ul",{role:"group",children:_(H,B+1)})]},T.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===Vt?0:-1,"data-ct-id":Vt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{w(Vt),n(Vt)},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:no(e).toLocaleString("en-US")})]})}),_(e,1)]})}const Sd=e=>`/item/${encodeURIComponent(e)}`;function Jx(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function $d(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function _d({work:e,href:i}){var d,c;const{t:n,convert:s}=se(),o=$d(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:s(e.title)}),o&&t.jsx("span",{className:"bim-ct-juan",children:s(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:["〔",s(m.dynasty),"〕"]}),s(m.name)]},p))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:s(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>s(m)).join(" · ")})]})})}function Nd({work:e,href:i}){var d,c;const{t:n,convert:s}=se(),o=$d(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:[s(e.title),o&&t.jsx("span",{className:"bim-ct-juan",children:s(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:["〔",s(m.dynasty),"〕"]}),s(m.name)]},p))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>s(m)).join(" · ")})]})})}function zd({page:e,pageCount:i,onPage:n,pageHref:s,label:o}){const{t:a,convert:l}=se();if(i<=1)return null;const d=m=>p=>{n&&(s&&!Jx(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 s?t.jsx("a",{...u,href:s(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:wd(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 Cd({works:e,workLink:i=Sd,emptyText:n,view:s="card",...o}){const{t:a,convert:l}=se();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}):s==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Nd,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(_d,{work:d,href:i(d.id)},d.id))}),t.jsx(zd,{...o})]})}const Zx=()=>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 Qx({tree:e,selectedId:i,page:n,pageCount:s,works:o,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:m,allLabel:p,allTitle:h,pageSize:u=io,className:f,view:g,onViewChange:y}){const{t:w,convert:j}=se(),x=p===void 0?w("catalogPage.all"):p,S=h??w("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[N,_]=b.useState(!1),[E,B]=b.useState("card"),T=g??E,I=oe=>{B(oe),y==null||y(oe)},H=wi(e,i&&i!==Vt?i:null),M=H.length?H[H.length-1]:null,q=M?M.label:S,O=M?M.count:no(e),ie=b.useCallback(oe=>{_(!1),a(oe)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":N?"open":"closed",children:[t.jsx("style",{children:kd}),t.jsxs("aside",{className:"bim-ct-side","aria-label":w("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":N,"aria-controls":$,onClick:()=>_(oe=>!oe),children:[t.jsx("span",{children:w("catalogPage.drawerLabel",{path:j(H.length?H.map(oe=>oe.label).join(" › "):x??S)})}),t.jsx(Zx,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:w("catalogPage.classification")}),t.jsx(vd,{tree:e,selectedId:i,onSelect:ie,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:j(q)}),H.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:j(H.slice(0,-1).map(oe=>oe.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[w("catalogPage.stat",{total:O.toLocaleString("en-US"),size:u}),s>1&&w("catalogPage.statPage",{page:n,pages:s})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":w("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":T==="card",onClick:()=>I("card"),children:w("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":T==="list",onClick:()=>I("list"),children:w("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Cd,{works:o,view:T,workLink:c,page:n,pageCount:s,onPage:l,pageHref:m})]})]})}const tn="(max-width: 719px)",e0="(max-width: 1079px)",t0=`${tn}, (pointer: coarse)`,i0=[8,18,30,42,88],ro=`
|
|
1713
|
+
`,ci="未分類",Vt="all",ro=20;function en(e){if(!e)return[];const i=[];for(const n of[e.l1,e.l2,e.l3,e.l4]){const s=(n??"").trim();if(!s)break;i.push(s)}return i}function Jx(e){const i=en(e);return i.length?i.join("/"):ci}function Zx(e){const i=en(e);return i.length?i.map((n,s)=>i.slice(0,s+1).join("/")):[ci]}function Qx(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 s=new Map;let o=0;for(const d of e){const c=en(d.classification);if(!c.length){o++;continue}let m=s;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===ci?1:0,h=m.label===ci?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(s);return o>0&&l.push({id:ci,label:ci,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 s=wi(n.children,i);if(s.length)return[n,...s]}}return[]}function so(e){return e.reduce((i,n)=>i+n.count,0)}function e0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function t0(e){var d,c,m;const i={id:e.id,title:e.title||e.id},n=e.juan_count,s=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 s=="number"&&s>0?i.juan=s: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=e0(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=en(e.classification);return l.length&&(i.classification=l),i}function i0(e,i){const n=e.summary?0:1,s=i.summary?0:1;return n!==s?n-s:e.title.localeCompare(i.title,"zh")}function n0(e,i=ro){return Math.max(1,Math.ceil(e/i))}function _d(e,i,n=2){if(i<=1)return[1];const s=new Set([1,i]);for(let l=e-n;l<=e+n;l++)l>=1&&l<=i&&s.add(l);const o=[...s].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 r0=()=>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 s0(e,i,n){const s=[];n&&s.push({id:Vt,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;s.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),s}function Nd({tree:e,selectedId:i,onSelect:n,allLabel:s,label:o}){const{t:a,convert:l}=se(),d=s===void 0?a("catalogPage.all"):s,c=o??a("catalogPage.classification"),m=b.useRef(null),p=i&&i!==Vt?i:null,h=d!==null,[u,f]=b.useState(()=>{const R=new Set;for(const O of wi(e,p))R.add(O.id);return R});b.useEffect(()=>{const R=wi(e,p);R.length&&f(O=>{if(R.every(I=>O.has(I.id)))return O;const C=new Set(O);for(const I of R)C.add(I.id);return C})},[e,p]);const g=b.useMemo(()=>s0(e,u,h),[e,u,h]),[y,w]=b.useState(null);b.useEffect(()=>{w(null)},[i]);const j=p??(h?Vt:null),x=b.useMemo(()=>{var C;const R=new Set(g.map(I=>I.id));if(y&&R.has(y))return y;if(j&&R.has(j))return j;const O=wi(e,p).map(I=>I.id).filter(I=>R.has(I));return O.length?O[O.length-1]:((C=g[0])==null?void 0:C.id)??null},[g,y,j,e,p]),v=b.useCallback((R,O)=>{f(C=>{const I=C.has(R),D=O??!I;if(D===I)return C;const A=new Set(C);return D?A.add(R):A.delete(R),A})},[]),S=b.useCallback(R=>{w(R),requestAnimationFrame(()=>{var C;const O=Array.from(((C=m.current)==null?void 0:C.querySelectorAll("[data-ct-id]"))??[]).find(I=>I.dataset.ctId===R);O==null||O.focus()})},[]),$=b.useCallback((R,O)=>{O&&v(R,!0),n(R)},[n,v]),N=b.useCallback(R=>{const O=R.target.closest("[data-ct-id]");if(!O)return;const C=O.dataset.ctId,I=g.findIndex(X=>X.id===C);if(I<0)return;const D=g[I];let A=null;switch(R.key){case"ArrowDown":A=g[Math.min(g.length-1,I+1)].id;break;case"ArrowUp":A=g[Math.max(0,I-1)].id;break;case"Home":A=g[0].id;break;case"End":A=g[g.length-1].id;break;case"ArrowRight":if(!D.hasChildren)break;u.has(C)?A=D.firstChildId:v(C,!0);break;case"ArrowLeft":D.hasChildren&&u.has(C)?v(C,!1):A=D.parentId;break;case"Enter":case" ":R.preventDefault(),$(C,D.hasChildren);return;default:return}R.preventDefault(),A&&A!==C&&S(A)},[g,u,v,S,$]),z=(R,O)=>R.map((C,I)=>{var ae;const D=(ae=C.children)!=null&&ae.length?C.children:null,A=!!D&&u.has(C.id),X=C.id===p,B=O===1&&R.length>1&&I===R.length-1;return t.jsxs("li",{role:"treeitem","aria-level":O,"aria-expanded":D?A:void 0,"aria-selected":X,tabIndex:x===C.id?0:-1,"data-ct-id":C.id,className:B?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":O-1},onClick:()=>{w(C.id),$(C.id,!!D)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:D?te=>{te.stopPropagation(),w(C.id),v(C.id)}:void 0,children:D?t.jsx(r0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(C.label)}),t.jsx("span",{className:"bim-ct-n",children:C.count.toLocaleString("en-US")})]}),A&&t.jsx("ul",{role:"group",children:z(D,O+1)})]},C.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===Vt?0:-1,"data-ct-id":Vt,children:t.jsxs("div",{className:"bim-ct-row",onClick:()=>{w(Vt),n(Vt)},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:so(e).toLocaleString("en-US")})]})}),z(e,1)]})}const zd=e=>`/item/${encodeURIComponent(e)}`;function o0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Cd(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Ed({work:e,href:i}){var d,c;const{t:n,convert:s}=se(),o=Cd(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:s(e.title)}),o&&t.jsx("span",{className:"bim-ct-juan",children:s(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:["〔",s(m.dynasty),"〕"]}),s(m.name)]},p))}),e.summary&&t.jsx("p",{className:"bim-ct-sum",children:s(e.summary)}),l.length>0&&t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>s(m)).join(" · ")})]})})}function Rd({work:e,href:i}){var d,c;const{t:n,convert:s}=se(),o=Cd(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:[s(e.title),o&&t.jsx("span",{className:"bim-ct-juan",children:s(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:["〔",s(m.dynasty),"〕"]}),s(m.name)]},p))}),t.jsx("span",{className:"bim-ct-cls",children:l.map(m=>s(m)).join(" · ")})]})})}function Td({page:e,pageCount:i,onPage:n,pageHref:s,label:o}){const{t:a,convert:l}=se();if(i<=1)return null;const d=m=>p=>{n&&(s&&!o0(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 s?t.jsx("a",{...u,href:s(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:_d(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 Id({works:e,workLink:i=zd,emptyText:n,view:s="card",...o}){const{t:a,convert:l}=se();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}):s==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Rd,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Ed,{work:d,href:i(d.id)},d.id))}),t.jsx(Td,{...o})]})}const a0=()=>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 l0({tree:e,selectedId:i,page:n,pageCount:s,works:o,onSelect:a,onPage:l,searchSlot:d,workLink:c,pageHref:m,allLabel:p,allTitle:h,pageSize:u=ro,className:f,view:g,onViewChange:y}){const{t:w,convert:j}=se(),x=p===void 0?w("catalogPage.all"):p,v=h??w("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[N,z]=b.useState(!1),[R,O]=b.useState("card"),C=g??R,I=te=>{O(te),y==null||y(te)},D=wi(e,i&&i!==Vt?i:null),A=D.length?D[D.length-1]:null,X=A?A.label:v,B=A?A.count:so(e),ae=b.useCallback(te=>{z(!1),a(te)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":N?"open":"closed",children:[t.jsx("style",{children:$d}),t.jsxs("aside",{className:"bim-ct-side","aria-label":w("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":N,"aria-controls":$,onClick:()=>z(te=>!te),children:[t.jsx("span",{children:w("catalogPage.drawerLabel",{path:j(D.length?D.map(te=>te.label).join(" › "):x??v)})}),t.jsx(a0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:w("catalogPage.classification")}),t.jsx(Nd,{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:j(X)}),D.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:j(D.slice(0,-1).map(te=>te.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[w("catalogPage.stat",{total:B.toLocaleString("en-US"),size:u}),s>1&&w("catalogPage.statPage",{page:n,pages:s})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":w("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":C==="card",onClick:()=>I("card"),children:w("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":C==="list",onClick:()=>I("list"),children:w("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Id,{works:o,view:C,workLink:c,page:n,pageCount:s,onPage:l,pageHref:m})]})]})}const tn="(max-width: 719px)",c0="(max-width: 1079px)",d0=`${tn}, (pointer: coarse)`,m0=[8,18,30,42,88],oo=`
|
|
1714
1714
|
.bim-rh { color: ${r.bim("ink")}; font-family: ${r.bim("font-ui")}; font-size: 14px; line-height: 1.6; }
|
|
1715
1715
|
.bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
|
|
1716
1716
|
.bim-rh a { color: ${r.bim("accent")}; text-decoration: none; }
|
|
@@ -1858,7 +1858,7 @@ ${Re??""}`,[Ei,mo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)mo({ke
|
|
|
1858
1858
|
flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; overflow: hidden;
|
|
1859
1859
|
color: ${r.bim("ink")} !important; font-size: 13px;
|
|
1860
1860
|
}
|
|
1861
|
-
${
|
|
1861
|
+
${m0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb, ${r.bim("accent")} ${e}%, ${r.bim("card-bg")}); }`).join(`
|
|
1862
1862
|
`)}
|
|
1863
1863
|
.bim-rh-band a[data-k="4"] { color: ${r.bim("page-bg")} !important; }
|
|
1864
1864
|
.bim-rh-band a:hover { outline: 2px solid ${r.bim("ink")}; outline-offset: -2px; }
|
|
@@ -1886,7 +1886,7 @@ ${i0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1886
1886
|
}
|
|
1887
1887
|
|
|
1888
1888
|
/* ── 中屏 ── */
|
|
1889
|
-
@media ${
|
|
1889
|
+
@media ${c0} {
|
|
1890
1890
|
.bim-rh-picks, .bim-rh-works, .bim-rh-groups, .bim-rh-bu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
1891
1891
|
.bim-rh-authors { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
1892
1892
|
}
|
|
@@ -1929,7 +1929,7 @@ ${i0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1929
1929
|
}
|
|
1930
1930
|
|
|
1931
1931
|
/* 触屏或窄屏:点击目标放大到 44px */
|
|
1932
|
-
@media ${
|
|
1932
|
+
@media ${d0} {
|
|
1933
1933
|
.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; }
|
|
1934
1934
|
.bim-rh-chip { display: inline-flex; }
|
|
1935
1935
|
}
|
|
@@ -1940,7 +1940,7 @@ ${i0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
1940
1940
|
}
|
|
1941
1941
|
|
|
1942
1942
|
@media (prefers-reduced-motion: reduce) { .bim-rh * { scroll-behavior: auto !important; transition: none !important; } }
|
|
1943
|
-
`,n0=r.readHome["zh-Hant"].period,Ed={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function ti(e){return{...Ed,...e??{}}}function so(e){var n;const i=(n=e.authors)==null?void 0:n.find(s=>s==null?void 0:s.name);return i?i.dynasty?`${i.dynasty} ${i.name}`:i.name:""}function er(e){return(e.authors??[]).filter(n=>n==null?void 0:n.name).map(n=>n.dynasty?`〔${n.dynasty}〕${n.name}`:n.name).join(" ")}function Rd(e,i=r.readHome["zh-Hant"].shelfOther){var o;const n=[],s=new Map;for(const a of e){const l=((o=a.period_of)==null?void 0:o.trim())||i;let d=s.get(l);d||(d={label:l,items:[]},s.set(l,d),n.push(d)),d.items.push(a)}return n}function Td(e){return Math.max(150,Array.from(e).length*18+44)}function Id(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 Md=.04;function jt(e){return e.toLocaleString("en-US")}function Ad({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((i,n)=>t.jsx("span",{children:i},n))})}function Et({id:e,title:i,sub:n,more:s,children:o}){const{convert:a}=se(),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}),s]}),t.jsx("div",{className:"bim-rh-bd",children:o})]})}function Ld({counts:e}){const{t:i}=se();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:jt(e.readable)}),i("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:jt(e.pieces)}),i("readHome.pieces")]})]})}function Pd({picks:e,links:i}){const{t:n,convert:s}=se(),o=ti(i);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=er(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(Ad,{text:s(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:s(d)}),t.jsx("h3",{children:s(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:s(l)}),a.blurb&&t.jsx("p",{children:s(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:n("readHome.startReading")})]})]})},a.id)})}):null}function Od(e,i){return e&&e>1?i("readHome.nCopies",{n:e}):null}function oo({topic:e,links:i,hint:n,legendCount:s,showTitle:o=!0,legendExtra:a}){const{t:l,convert:d}=se(),c=ti(i);if(!e.items.length)return null;const m=s===void 0?l("readHome.shelfLegendCount"):s,p=Rd(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?jt(u.records):Od(u.text_count,l),g=so(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:Td(u.title)},children:[t.jsx(Ad,{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 r0=4,Vi=e=>e>r0+1;function Fd({topic:e,links:i}){const{t:n,convert:s}=se(),o=ti(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":Vi(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[s(e.label),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nWorks",{n:jt(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const m=Od(c.text_count,n),p=so(c);return t.jsx("li",{children:t.jsxs("a",{href:o.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:s(c.title)}),m&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:m}),p&&t.jsx("small",{children:s(p)})]})},c.id)})}),Vi(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 Bd({topics:e,links:i}){const n=e.filter(o=>o.shelf&&o.items.length),s=e.filter(o=>!o.shelf&&o.items.length);return!n.length&&!s.length?null:t.jsxs(t.Fragment,{children:[n.map(o=>t.jsx(oo,{topic:o,links:i},o.key)),s.length>0&&t.jsx("div",{className:"bim-rh-groups",children:s.map(o=>t.jsx(Fd,{topic:o,links:i},o.key))})]})}function Hd({famous:e,links:i}){const{t:n,convert:s}=se(),o=ti(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:s(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:s(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?s(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:s(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:o.read(c.id),title:s([c.title,c.edition].filter(Boolean).join(" · ")),children:s(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:s(a.title)})})})]})},a.work_id??a.title))}):null}function ao({bu:e,unclassified:i,links:n,unclassifiedNote:s}){const{t:o,convert:a}=se(),l=ti(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:jt(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:jt(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:jt(i)})}),t.jsx("span",{children:s?a(s):o("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:o("readHome.viewUnclassified")})]})]})}function Dd({periods:e,unknown:i,links:n}){const{t:s,convert:o,messages:a}=se(),l=a.readHome.period,d=ti(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=s("readHome.periodItem",{label:u,n:jt(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":Id(h.count,p),"data-narrow":f<Md?"":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:jt(h.count)})]})},h.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!i&&t.jsx("span",{children:s("readHome.periodUnknown",{n:jt(i)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:s("readHome.hoverHint")})]})]})}function Wd({authors:e,links:i}){const{t:n,convert:s}=se(),o=ti(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:[s(a.name),a.dynasty&&t.jsx("span",{children:s(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nPieces",{n:jt(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:o.read(l.id),children:s(l.title)})},l.id))}),o.author&&t.jsx("a",{className:"bim-rh-more",href:o.author(a.name),children:n("readHome.authorAll",{name:s(a.name),n:a.count})})]},a.name))}):null}const Ud={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function s0({sections:e,links:i,head:n,piecesMoreHref:s,className:o}){const{t:a}=se(),l=e,d=Ud,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:ro}),t.jsxs("div",{className:"bim-rh-head",children:[n,t.jsx(Ld,{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(Et,{id:d.picks,title:h("picks"),sub:a("readHome.picksSub"),children:t.jsx(Pd,{picks:l.picks,links:i})}),m.topics&&t.jsx(Et,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(Bd,{topics:c,links:i})}),m.famous&&t.jsx(Et,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(Hd,{famous:l.famous,links:i})}),m.sibu&&t.jsx(Et,{id:d.sibu,title:h("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(ao,{bu:l.bu,unclassified:l.unclassified,links:i})}),m.period&&t.jsx(Et,{id:d.period,title:h("period"),sub:a("readHome.periodSub"),children:t.jsx(Dd,{periods:l.periods,unknown:l.period_unknown,links:i})}),m.pieces&&t.jsx(Et,{id:d.pieces,title:h("pieces"),sub:a("readHome.piecesSub"),more:s?t.jsx("a",{className:"bim-rh-more",href:s,children:a("readHome.piecesMore")}):void 0,children:t.jsx(Wd,{authors:l.pieces.authors,links:i})})]})]})}const o0="(max-width: 1079px)",a0=`${tn}, (pointer: coarse)`,Kd=`
|
|
1943
|
+
`,u0=r.readHome["zh-Hant"].period,Md={read:e=>`/read/${encodeURIComponent(e)}`,node:e=>`/read?node=${encodeURIComponent(e)}`,period:e=>`/read?period=${encodeURIComponent(e)}`,work:e=>`/item/${encodeURIComponent(e)}`};function ti(e){return{...Md,...e??{}}}function ao(e){var n;const i=(n=e.authors)==null?void 0:n.find(s=>s==null?void 0:s.name);return i?i.dynasty?`${i.dynasty} ${i.name}`:i.name:""}function tr(e){return(e.authors??[]).filter(n=>n==null?void 0:n.name).map(n=>n.dynasty?`〔${n.dynasty}〕${n.name}`:n.name).join(" ")}function Ad(e,i=r.readHome["zh-Hant"].shelfOther){var o;const n=[],s=new Map;for(const a of e){const l=((o=a.period_of)==null?void 0:o.trim())||i;let d=s.get(l);d||(d={label:l,items:[]},s.set(l,d),n.push(d)),d.items.push(a)}return n}function Ld(e){return Math.max(150,Array.from(e).length*18+44)}function Pd(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 Od=.04;function jt(e){return e.toLocaleString("en-US")}function Fd({text:e}){return t.jsx(t.Fragment,{children:Array.from(e).map((i,n)=>t.jsx("span",{children:i},n))})}function Et({id:e,title:i,sub:n,more:s,children:o}){const{convert:a}=se(),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}),s]}),t.jsx("div",{className:"bim-rh-bd",children:o})]})}function Bd({counts:e}){const{t:i}=se();return t.jsxs("p",{className:"bim-rh-stats bim-rh-num",children:[t.jsxs("span",{children:[t.jsx("b",{children:jt(e.readable)}),i("readHome.readable")]}),e.pieces>0&&t.jsxs("span",{children:[t.jsx("b",{children:jt(e.pieces)}),i("readHome.pieces")]})]})}function Hd({picks:e,links:i}){const{t:n,convert:s}=se(),o=ti(i);return e.length?t.jsx("ul",{className:"bim-rh-picks",children:e.map(a=>{const l=tr(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(Fd,{text:s(a.slip||a.title)})}),t.jsxs("span",{className:"bim-rh-pk-body",children:[d&&t.jsx("span",{className:"bim-rh-badge",children:s(d)}),t.jsx("h3",{children:s(a.title)}),l&&t.jsx("span",{className:"bim-rh-by",children:s(l)}),a.blurb&&t.jsx("p",{children:s(a.blurb)}),t.jsx("span",{className:"bim-rh-go","aria-hidden":"true",children:n("readHome.startReading")})]})]})},a.id)})}):null}function Dd(e,i){return e&&e>1?i("readHome.nCopies",{n:e}):null}function lo({topic:e,links:i,hint:n,legendCount:s,showTitle:o=!0,legendExtra:a}){const{t:l,convert:d}=se(),c=ti(i);if(!e.items.length)return null;const m=s===void 0?l("readHome.shelfLegendCount"):s,p=Ad(e.items,l("readHome.shelfOther")),h=u=>{const f=u.records?jt(u.records):Dd(u.text_count,l),g=ao(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:Ld(u.title)},children:[t.jsx(Fd,{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 p0=4,Vi=e=>e>p0+1;function Wd({topic:e,links:i}){const{t:n,convert:s}=se(),o=ti(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":Vi(e.items.length)?"":void 0,"data-open":a?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",id:d,children:[s(e.label),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nWorks",{n:jt(e.items.length)})})]}),t.jsx("ul",{className:"bim-rh-rows","aria-labelledby":d,children:e.items.map(c=>{const m=Dd(c.text_count,n),p=ao(c);return t.jsx("li",{children:t.jsxs("a",{href:o.read(c.id),children:[t.jsx("span",{className:"bim-rh-t",children:s(c.title)}),m&&t.jsx("em",{className:"bim-rh-cnt bim-rh-num",children:m}),p&&t.jsx("small",{children:s(p)})]})},c.id)})}),Vi(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 Ud({topics:e,links:i}){const n=e.filter(o=>o.shelf&&o.items.length),s=e.filter(o=>!o.shelf&&o.items.length);return!n.length&&!s.length?null:t.jsxs(t.Fragment,{children:[n.map(o=>t.jsx(lo,{topic:o,links:i},o.key)),s.length>0&&t.jsx("div",{className:"bim-rh-groups",children:s.map(o=>t.jsx(Wd,{topic:o,links:i},o.key))})]})}function Kd({famous:e,links:i}){const{t:n,convert:s}=se(),o=ti(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:s(a.title)}),a.authors&&t.jsx("span",{className:"bim-rh-by",children:s(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?s(l.label):void 0,children:[l.label&&t.jsx("small",{"aria-hidden":"true",children:s(l.label)}),l.items.map(c=>t.jsx("a",{className:"bim-rh-chip",href:o.read(c.id),title:s([c.title,c.edition].filter(Boolean).join(" · ")),children:s(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:s(a.title)})})})]})},a.work_id??a.title))}):null}function co({bu:e,unclassified:i,links:n,unclassifiedNote:s}){const{t:o,convert:a}=se(),l=ti(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:jt(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:jt(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:jt(i)})}),t.jsx("span",{children:s?a(s):o("readHome.sibuUnclassifiedNote")}),t.jsx("a",{href:l.node("unclassified"),children:o("readHome.viewUnclassified")})]})]})}function Yd({periods:e,unknown:i,links:n}){const{t:s,convert:o,messages:a}=se(),l=a.readHome.period,d=ti(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=s("readHome.periodItem",{label:u,n:jt(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":Pd(h.count,p),"data-narrow":f<Od?"":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:jt(h.count)})]})},h.key)})}),t.jsxs("p",{className:"bim-rh-pfoot bim-rh-num",children:[!!i&&t.jsx("span",{children:s("readHome.periodUnknown",{n:jt(i)})}),t.jsx("span",{className:"bim-rh-hover-hint",children:s("readHome.hoverHint")})]})]})}function Vd({authors:e,links:i}){const{t:n,convert:s}=se(),o=ti(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:[s(a.name),a.dynasty&&t.jsx("span",{children:s(a.dynasty)}),t.jsx("small",{className:"bim-rh-num",children:n("readHome.nPieces",{n:jt(a.count)})})]}),t.jsx("ul",{children:a.items.map(l=>t.jsx("li",{children:t.jsx("a",{href:o.read(l.id),children:s(l.title)})},l.id))}),o.author&&t.jsx("a",{className:"bim-rh-more",href:o.author(a.name),children:n("readHome.authorAll",{name:s(a.name),n:a.count})})]},a.name))}):null}const Gd={picks:"picks",topics:"topics",famous:"classics",sibu:"sibu",period:"period",pieces:"pieces"};function b0({sections:e,links:i,head:n,piecesMoreHref:s,className:o}){const{t:a}=se(),l=e,d=Gd,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:oo}),t.jsxs("div",{className:"bim-rh-head",children:[n,t.jsx(Bd,{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(Et,{id:d.picks,title:h("picks"),sub:a("readHome.picksSub"),children:t.jsx(Hd,{picks:l.picks,links:i})}),m.topics&&t.jsx(Et,{id:d.topics,title:h("topics"),sub:a("readHome.topicsSub"),children:t.jsx(Ud,{topics:c,links:i})}),m.famous&&t.jsx(Et,{id:d.famous,title:h("famous"),sub:a("readHome.famousSub"),children:t.jsx(Kd,{famous:l.famous,links:i})}),m.sibu&&t.jsx(Et,{id:d.sibu,title:h("sibu"),sub:a("readHome.sibuSub"),children:t.jsx(co,{bu:l.bu,unclassified:l.unclassified,links:i})}),m.period&&t.jsx(Et,{id:d.period,title:h("period"),sub:a("readHome.periodSub"),children:t.jsx(Yd,{periods:l.periods,unknown:l.period_unknown,links:i})}),m.pieces&&t.jsx(Et,{id:d.pieces,title:h("pieces"),sub:a("readHome.piecesSub"),more:s?t.jsx("a",{className:"bim-rh-more",href:s,children:a("readHome.piecesMore")}):void 0,children:t.jsx(Vd,{authors:l.pieces.authors,links:i})})]})]})}const h0="(max-width: 1079px)",f0=`${tn}, (pointer: coarse)`,qd=`
|
|
1944
1944
|
/* ── 页首:检索(宿主插槽)+类型签|最近浏览 ── */
|
|
1945
1945
|
.bim-mh-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px 48px; align-items: start; padding-top: 8px; }
|
|
1946
1946
|
.bim-mh-q { min-width: 0; }
|
|
@@ -2080,7 +2080,7 @@ ${i0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
2080
2080
|
.bim-mh-cc0 { display: inline-block; margin-right: 8px; padding: 1px 7px; font-size: 11.5px; letter-spacing: 0.08em; background: ${r.bim("check-fine-bg")}; color: ${r.bim("check-fine-fg")}; }
|
|
2081
2081
|
|
|
2082
2082
|
/* ── 中屏 ── */
|
|
2083
|
-
@media ${
|
|
2083
|
+
@media ${h0} {
|
|
2084
2084
|
.bim-mh-head, .bim-mh-zhi { grid-template-columns: minmax(0, 1fr); }
|
|
2085
2085
|
.bim-mh-cg { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
2086
2086
|
.bim-mh-lin { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
|
@@ -2107,8 +2107,8 @@ ${i0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
2107
2107
|
.bim-mh-tbl tr > :nth-child(2), .bim-mh-tbl tr > :nth-child(3) { display: none; }
|
|
2108
2108
|
}
|
|
2109
2109
|
|
|
2110
|
-
@media ${
|
|
2110
|
+
@media ${f0} {
|
|
2111
2111
|
.bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
|
|
2112
2112
|
.bim-mh-recent-h button { min-height: 44px; }
|
|
2113
2113
|
}
|
|
2114
|
-
`,Yd={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ii(e){return{...Yd,...e??{}}}function Vd(e,i){if(e.lineage)return e.lineage(i);const n=e.item(i),s=n.indexOf("#"),[o,a]=s<0?[n,""]:[n.slice(0,s),n.slice(s)];return`${o}${o.includes("?")?"&":"?"}tab=lineage${a}`}function lo(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function Gd(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 s=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(s),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 Ln(e,i=r.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function l0(e){return{read:e.item,work:e.item,node:e.node}}function qd({counts:e,links:i}){const{t:n}=se(),s=i==null?void 0:i.type;if(!s)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:s(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:jt(d)})]})},a))})}function Xd(e,i=5){const[n,s]=b.useState(null);b.useEffect(()=>{let a=!1;const l=ei().slice(0,i);if(!l.length||!e){s([]);return}return Promise.all(l.map(d=>ys(e,d))).then(d=>{a||s(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{xs(),s([])},[]);return{entries:n,clear:o}}function c0(e,i,n){const s=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return s?n(s):Jd(e.type,i)}function Jd(e,i){return i(`metaHome.typeLabel.${e}`)}function Zd({entries:e,onClear:i,links:n}){const{t:s,convert:o}=se(),a=ii(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:s("metaHome.recentTitle")}),e&&e.length>0&&i&&t.jsx("button",{type:"button",onClick:i,children:s("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":s("metaHome.recentItemLabel",{type:l.type?Jd(l.type,s):"",title:o(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?s(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:o(l.title)}),t.jsx("small",{"aria-hidden":"true",children:c0(l,s,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:s("metaHome.recentEmpty")})]})}function Qd(e,i,n,s=!1){return s&&(e==="done"||e==="in_progress")?i(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?i(`metaHome.status.${e}`):n(e)}function em({rows:e,links:i}){const{t:n,convert:s}=se(),o=ii(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=lo(a.imported,a.total),d=a.work_id??a.collection_id,c=s(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:jt(a.total)}),t.jsx("td",{className:"bim-mh-r",children:jt(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:Qd(a.status,n,s)})})]},a.id||a.name)})})]})}):null}function tm({items:e,links:i,label:n}){const{convert:s}=se();return t.jsx("ul",{className:"bim-rh-rows","aria-label":n?s(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:s(o.title)}),o.sub&&t.jsx("small",{children:s(o.sub)})]})},o.id))})}function im({works:e,links:i}){const{t:n}=se(),[s,o]=b.useState(!1);if(!e.length)return null;const a=Vi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(tm,{items:e.map(l=>({id:l.id,title:l.title,sub:er(l)||void 0})),links:ii(i)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>o(l=>!l),children:s?n("action.collapse"):n("metaHome.allNWorks",{n:e.length})})]})}const nm="siku_qige";function d0({group:e,links:i}){const{t:n,convert:s}=se(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Vi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[s(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(tm,{items:e.items,links:i,label:e.label}),Vi(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 rm({groups:e,links:i}){const{t:n,convert:s}=se(),o=ii(i);if(!e.length)return null;const a=e.find(c=>c.key===nm),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:[s(a.label),t.jsx("small",{children:s(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":s(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:o.item(c.id),"aria-label":s(c.title),title:s(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:s(d(c.title))}),d(c.title)!==c.title&&t.jsx("small",{"aria-hidden":"true",children:n("metaHome.pavilion")})]})},c.id))})]}),l.length>0&&t.jsx("div",{className:"bim-mh-cg",style:a?void 0:{marginTop:0},children:l.map(c=>t.jsx(d0,{group:c,links:o},c.key))})]})}const rl=34,sl=13;function ol(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Ln(e.birth_year,i):"?"}–${e.death_year!=null?Ln(e.death_year,i):"?"}`}function m0(e,i){const n=i-e,s=n>1200?300:n>400?100:50,o=[];for(let a=Math.ceil(e/s)*s;a<=i;a+=s)o.push(a);return o}function sm({people:e,links:i}){const{t:n,convert:s}=se(),o=ii(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=Gd(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-sl):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,sl),{...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*rl+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*rl+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:[s(u.p.name),t.jsx("small",{className:"bim-rh-num",children:ol(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:m0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:Ln(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:s(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?s(u.dynasty):"",ol(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:s(c.map(u=>u.name).join("、"))})})]})}const u0=t.jsxs("svg",{width:"54",height:"34",viewBox:"0 0 54 34",fill:"none",stroke:"currentColor",strokeWidth:"1.4","aria-hidden":"true",children:[t.jsx("circle",{cx:"27",cy:"5",r:"3.5"}),t.jsx("circle",{cx:"10",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"27",cy:"29",r:"3.5"}),t.jsx("circle",{cx:"44",cy:"29",r:"3.5"}),t.jsx("path",{d:"M27 8.5v17M27 15H10v10.5M27 15h17v10.5"})]});function om({works:e,links:i}){const{t:n,convert:s}=se(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=er(a);return t.jsx("li",{children:t.jsxs("a",{href:Vd(o,a.id),children:[u0,t.jsx("b",{children:s(a.title)}),l&&t.jsx("small",{children:s(l)}),t.jsx("span",{children:n("metaHome.viewLineage")})]})},a.id)})}):null}function am({sites:e}){const{t:i,convert:n}=se(),s=e.filter(a=>a.status!=="todo"&&a.total>0),o=e.filter(a=>!s.includes(a));return e.length?t.jsxs(t.Fragment,{children:[s.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:s.map(a=>{const l=lo(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:[`${jt(a.imported)} / ${jt(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:Qd(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 al=["extant","partially_extant","lost","unknown"];function lm({stats:e,links:i,version:n,repoUrl:s,downloadHref:o}){const{t:a}=se(),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=al.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:jt(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:al.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:jt(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"),s?t.jsx("a",{href:s,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 cm={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function p0({sections:e,links:i,head:n,transport:s,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,N;const{t:h}=se(),u=e,f=ii(i),g=l0(f),y=cm,w=Xd(s),j={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(_=>j[_]),S=_=>h(`metaHome.nav.${_}`),v=(_,E)=>_?t.jsx("a",{className:"bim-rh-more",href:_,children:E}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:ro+Kd}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(qd,{counts:u.counts,links:i})]}),s&&t.jsx(Zd,{entries:w.entries,onClear:w.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(_=>t.jsx("li",{children:t.jsx("a",{href:`#${y[_]}`,children:S(_)})},_))})}),t.jsxs("div",{className:"bim-rh-main",children:[j.zhi&&t.jsxs(Et,{id:y.zhi,title:S("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(oo,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:g,showTitle:!1,legendCount:u.shelf.items.some(_=>_.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(em,{rows:u.catalog_progress,links:i}),t.jsx(im,{works:u.related_catalogs,links:i})]})]}),j.sibu&&t.jsx(Et,{id:y.sibu,title:S("sibu"),sub:h("metaHome.sibuSub"),more:v(o,h("metaHome.toCatalog")),children:t.jsx(ao,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),j.cong&&t.jsx(Et,{id:y.cong,title:S("cong"),sub:h("metaHome.congSub"),more:v(a,h("metaHome.allNKindsMore",{n:jt(u.counts.collections)})),children:t.jsx(rm,{groups:u.collection_groups,links:i})}),j.people&&t.jsx(Et,{id:y.people,title:S("people"),sub:h("metaHome.peopleSub"),more:v(l,h("metaHome.allNPeopleMore",{n:jt(u.counts.entities)})),children:t.jsx(sm,{people:u.bibliographers,links:i})}),j.lineage&&t.jsx(Et,{id:y.lineage,title:S("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(om,{works:u.lineage,links:i})}),j.sites&&t.jsx(Et,{id:y.sites,title:S("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(am,{sites:u.sites})}),t.jsx(Et,{id:y.data,title:S("data"),sub:h("metaHome.dataSub"),children:t.jsx(lm,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const dm=["_related","_catalogs","_collections","_members","_children"],b0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),os=e=>b0(e)&&!!e.h;function h0(e){return e?dm.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(os)}):!1}function f0(e,i){const n={...e};if(!i)return n;for(const s of dm){const o=e[s];!Array.isArray(o)||!o.some(os)||(n[s]=o.map(a=>{var c;if(!os(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(s,o){if(o==="getItem")return async l=>{const d=await s.getItem(l);return d&&f0(d,h0(d)?await n():null)};const a=Reflect.get(s,o,s);return typeof a=="function"?a.bind(s):a}})}const as=({style:e})=>{const i=b.useContext(r.LocaleContext),{t:n}=se();if(!i)return null;const{locale:s,setLocale:o}=i,a=s==="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 ${r.bim("border")}`,borderRadius:"4px",background:r.bim("bg"),color:r.bim("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?r.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:r.bim("primary"),fontWeight:a?400:700},children:n("common.localeShortHans")})]})},ls=({href:e,label:i,size:n=16,className:s,style:o})=>{const{t:a}=se(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:s,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:n+8,height:n+8,borderRadius:4,color:r.bim("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...o},onMouseEnter:d=>{d.currentTarget.style.color=r.bim("fg")},onMouseLeave:d=>{d.currentTarget.style.color=r.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 Or(e){const i=e.text_count;return typeof i=="number"&&i>0}function Fr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function x0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const y0=({id:e,transport:i,initialDetail:n,initialEntry:s,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:w,renderLink:j,assetBase:x,enrichDetail:S,getSourceLink:v,readLink:$,railTop:N,extraTabs:_=[],showFeedbackTab:E=!0,feedbackApiUrl:B,height:T,footerExtra:I,hideHeaderControls:H=!1,className:M,style:q})=>{const O=b.useMemo(()=>g0(i),[i]),ie=b.useMemo(()=>id(O)??Xs(B),[O,B]),oe=r.useT(),{t:le,convert:ae}=se(),[pe]=b.useState(()=>{if(!x0(e,n))return null;const J={...n},we=s??Fr(e,J);return S&&S(we,J),{id:e,entry:we,detail:J}}),[ee,ge]=b.useState((pe==null?void 0:pe.entry)??null),[W,ze]=b.useState((pe==null?void 0:pe.detail)??null),[U,re]=b.useState(!pe),[be,X]=b.useState(!1),[L,_e]=b.useState([]),[P,K]=b.useState(!1),[z,V]=b.useState(null),[de,ue]=b.useState(null),[He,G]=b.useState(null),[me,ce]=b.useState(!1),Oe=b.useRef(null),Te=b.useRef(0),[je,Re]=b.useState(null),Ie=l!==void 0?l:je,Je=b.useCallback(J=>{d?d(J):Re(J)},[d]),ut=b.useCallback(async J=>{if(!O.getCollectionCatalogs&&!O.getCollectionCatalog){_e([]);return}K(!0);try{if(O.getCollectionCatalogs)_e(await O.getCollectionCatalogs(J)||[]);else if(O.getCollectionCatalog){const we=await O.getCollectionCatalog(J);_e(we?[{resource_id:"",data:we}]:[])}}catch{_e([])}finally{K(!1)}},[O]),Ve=b.useCallback(async J=>{var we,Xe;if(!O.getTextManifest||!O.getTextIndex){V(null),ue(J);return}try{const Ze=Se.pickTextVersion(await O.getTextManifest(J)),De=Ze?await O.getTextIndex(J,Ze.key):null;V(De&&De.chapters.length>0?{chapters:De.chapters.map(Fe=>({n:Fe.n,title:Fe.title,file:Fe.file})),source:{name:((we=De.source)==null?void 0:we.name)??(Ze==null?void 0:Ze.source_name),license:((Xe=De.source)==null?void 0:Xe.license)??(Ze==null?void 0:Ze.license)??void 0}}:null)}catch{V(null)}finally{ue(J)}},[O]),ht=b.useCallback(async(J,we)=>{const Xe=++Te.current,Ze=()=>Xe!==Te.current;ce(!0);try{if(O.getLineageGraph){const ft=await O.getLineageGraph(J);if(Ze())return;ft&&G(ft)}const De=we.version_graph;if(!De||!De.enabled){He||G(null),Oe.current=null;return}const Fe=hs(we),mt=(await Zn(Fe,Jn,async ft=>{try{return await O.getItem(ft)}catch{return null}},Ze)).filter(Boolean);if(Ze())return;Oe.current={work:we,books:mt};const pt=p??De.default_collection??(De.core_books&&De.core_books.length>0?"core":"all"),We=pt==="core"&&Array.isArray(De.core_books)&&De.core_books.length>0?"core":pt??"all";G(yn(we,mt,We))}catch{if(Ze())return;G(null),Oe.current=null}finally{Ze()||ce(!1)}},[O]),Ge=b.useRef({initialDetail:n,initialEntry:s});Ge.current={initialDetail:n,initialEntry:s},b.useEffect(()=>{let J=!1;Te.current++,ce(!1);const we=Fe=>{Fe.type==="collection"?ut(e):Fe.type==="work"?(Fe.version_graph||O.getLineageGraph)&&ht(e,Fe):Fe.type==="book"&&Or(Fe)&&Ve(e)},Xe=Ge.current;let Ze=null;if(pe&&pe.id===e)Ze=pe;else if(Xe.initialDetail&&Xe.initialDetail.id===e){const Fe={...Xe.initialDetail},dt=Xe.initialEntry??Fr(e,Fe);S&&S(dt,Fe),Ze={entry:dt,detail:Fe}}return Ze?(X(!1),_e(Fe=>Fe.length?[]:Fe),V(null),G(null),Oe.current=null,ge(Ze.entry),ze(Ze.detail),re(!1),we(Ze.detail),()=>{J=!0}):((async()=>{re(!0),X(!1),ge(null),ze(null),_e([]),V(null),G(null),Oe.current=null;try{const Fe=await O.getItem(e);if(J)return;if(!Fe){X(!0);return}const dt=Fe;let mt=null;if(O.getEntry&&(mt=await O.getEntry(e),J))return;mt||(mt=Fr(e,dt)),S&&S(mt,dt),ge(mt),ze(dt),we(dt)}catch{J||X(!0)}finally{J||re(!1)}})(),()=>{J=!0})},[e,O,pe,S,ut,ht,Ve]),b.useEffect(()=>{const J=Oe.current;!J||!p||G(yn(J.work,J.books,p))},[p]);const k=[];if(W){if(k.push({key:"basic",label:oe.detailTab.basicInfo}),W.type==="collection"){P&&L.length===0&&k.push({key:"catalog:loading",label:`${oe.detailTab.catalog}…`});for(const J of L)k.push({key:`catalog:${J.resource_id}`,label:J.short_name?`${ae(J.short_name)}${oe.detailTab.catalogSuffix}`:oe.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&k.push({key:o,label:oe.detailTab.fullText}),W.type==="work"&&(He||me)&&k.push({key:"lineage",label:me?`${oe.detailTab.lineage}…`:oe.detailTab.lineage});for(const J of _)(J.position??"before-feedback")==="before-feedback"&&J.shouldShow(W)&&k.push({key:J.key,label:J.label});E&&o==="feedback"&&k.push({key:"feedback",label:oe.detailTab.feedback});for(const J of _)J.position==="after-feedback"&&J.shouldShow(W)&&k.push({key:J.key,label:J.label})}b.useEffect(()=>{if(o!=="emendated"||!W)return;a("basic");const J=setTimeout(()=>{var we;(we=document.getElementById("studies"))==null||we.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(J)},[o,W,a]);const te=ee&&W&&v?v({activeTab:o,activeJuan:Ie,entry:ee,detail:W}):null,Z=b.useMemo(()=>{var De,Fe,dt,mt,pt;if(!W)return null;const we=(W.authors??[]).map(We=>{const ft=bs(We.role);return`${We.dynasty?`〔${ae(We.dynasty)}〕`:""}${ae(We.name)}${ft?` ${ae(ft)}`:""}`}).join(" · ");let Xe=!1;try{Xe=Se.extractStatus(W.id)==="draft"}catch{}if(W.type==="book"){const We=W;return{title:ae(We.title),subtitle:We.edition?ae(We.edition):we||void 0,aside:[Xe?oe.status.draft:"",we&&We.edition?we:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(W.type==="collection"){const We=W;return{title:ae(We.title),subtitle:ae(qt(We,oe.unit.juan))||void 0,aside:[(De=We.publication_info)==null?void 0:De.year,Xe?oe.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:we||void 0}}if(W.type==="entity"){const We=W,ft=A=>A==null?"":A<0?le("detail.bce",{n:-A}):String(A),Q=((Fe=We.dates)==null?void 0:Fe.birth)!=null||((dt=We.dates)==null?void 0:dt.death)!=null?`${ft(((mt=We.dates)==null?void 0:mt.birth)??void 0)||"?"}—${ft(((pt=We.dates)==null?void 0:pt.death)??void 0)||"?"}`:"";return{title:ae(We.primary_name||We.title),subtitle:[We.dynasty?`〔${ae(We.dynasty)}〕`:"",Q].filter(Boolean).join(" ")||void 0,aside:Xe?oe.status.draft:void 0,secondLine:void 0}}const Ze=ae(qt(W,oe.unit.juan));return{title:ae(W.title),subtitle:[Ze,we].filter(Boolean).join(" · ")||void 0,aside:[k0(oe,W.subtype),Xe?oe.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[W,ae,oe,le]),he=W&&Or(W)?"text":null,Ae=()=>{Je(null),a("fulltext")};let R=null;if(W&&$){const J=$({detail:W,kind:he});J&&(R=t.jsx(Vr,{href:J}))}else he&&(R=t.jsx(Vr,{onClick:Ae}));const xe=J=>{if(!W)return null;const we=J.replace(/\.[^.]+$/,"");if($){const Xe=$({detail:W,kind:he,juan:we});return Xe?{href:Xe}:null}return{onClick:()=>{Je(we),a("fulltext")}}},Y=new Set(_.map(J=>J.key)),$e=k.filter(J=>J.key.startsWith("catalog:")&&J.key!=="catalog:loading"||J.key==="lineage"&&!!He&&!me||Y.has(J.key)).map(J=>({key:J.key,label:J.label,onClick:()=>a(J.key)})),ke=()=>{var J;return W?W.type==="work"?t.jsx(pd,{data:W,transport:O,onNavigate:g,renderLink:j,readAction:R,railTop:N,railLinks:$e}):W.type==="book"?t.jsx(fd,{data:W,transport:O,onNavigate:g,renderLink:j,readAction:R,fullText:z,fullTextPending:Or(W)&&!!O.getTextManifest&&de!==W.id,chapterLink:xe,railTop:N,railLinks:$e}):W.type==="collection"?t.jsx(gd,{data:W,catalog:(J=L[0])==null?void 0:J.data,transport:O,onNavigate:g,renderLink:j,readAction:R,railTop:N,railLinks:$e,catalogAction:L.length>0?t.jsxs("a",{href:"#catalog",onClick:we=>{we.preventDefault(),a(`catalog:${L[0].resource_id}`)},children:[ae(oe.detailTab.collectionCatalog)," →"]}):null}):t.jsx(jd,{data:W,transport:O,onNavigate:g,renderLink:j,railTop:N,railLinks:$e,assetBase:x}):null},Ce=()=>{var we,Xe,Ze;if(!ee||!W)return null;if(o==="basic"||o==="emendated")return ke();if(typeof o=="string"&&o.startsWith("catalog:")){const De=(we=L.find(Fe=>`catalog:${Fe.resource_id}`===o))==null?void 0:we.data;return t.jsx(Fl,{data:De,onNavigate:g,renderLink:j})}if(o==="collated"||o==="fulltext")return t.jsx(td,{id:e,transport:O,chapter:Ie,onLocationChange:De=>Je(De.chapter),onNavigate:g});if(o==="lineage"){if(!He)return t.jsx("div",{style:{color:r.bim("label-fg"),padding:"24px 0"},children:le(me?"detail.loading":"detail.noLineageGraph")});const De=W.type==="work"?W:null;return t.jsx(eo,{graph:He,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((Xe=De==null?void 0:De.version_graph)==null?void 0:Xe.default_collection),onCollectionChange:h,collectionsAvailable:(Ze=De==null?void 0:De.version_graph)==null?void 0:Ze.collections,collectionCounts:(()=>{var pt,We,ft,Q,A,ne,ve;if(!De)return;const Fe={},dt=((pt=Oe.current)==null?void 0:pt.books)??[];Fe.all=(((We=De._books)==null?void 0:We.length)??0)-(((Q=(ft=De.version_graph)==null?void 0:ft.excluded_books)==null?void 0:Q.length)??0);const mt=(A=De.version_graph)==null?void 0:A.collections;if(mt)for(const Ee of Object.keys(mt))Fe[Ee]=yn(De,dt,Ee).nodes.filter(Pe=>Pe.kind==="book"&&!Pe.bridge).length;return Fe.core==null&&((ve=(ne=De.version_graph)==null?void 0:ne.core_books)!=null&&ve.length)&&(Fe.core=De.version_graph.core_books.length),Fe})()})}if(o==="feedback"&&E)return t.jsx(ld,{resourceId:e,transport:ie});const J=_.find(De=>De.key===o);return J?J.render({detail:W,entry:ee,transport:O,onNavigate:g}):null};if(U)return t.jsx(Fi,{style:{minHeight:T,...q},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((J,we)=>t.jsx("div",{style:{height:we===1?40:16,width:J,opacity:.35,background:r.bim("rule")}},we))})});if(be||!W||!ee||!Z)return t.jsx(Fi,{style:{minHeight:T,...q},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r.bim("label-fg"),fontSize:14},children:le("detail.notFound")})});const Qe=o==="basic"||o==="emendated",Le=[{label:w??oe.detailTab.backToIndex,onClick:y}];if(W.type==="book"&&W.work_id){const J=W.work_id;Le.push({label:oe.indexType.work,id:J,onClick:()=>g==null?void 0:g(J)})}Le.push({label:oe.indexType[W.type]});const et=o==="collated"||o==="fulltext",yt=typeof I=="string"?oe.status[I.trim()]??I:I,Be=t.jsx(yc,{left:t.jsxs(t.Fragment,{children:[yt,yt?" · ":"",t.jsx(j0,{id:W.id,label:oe.label.id,copied:oe.action.copied,copyLabel:oe.action.copy})]}),right:t.jsxs(t.Fragment,{children:[E&&!Qe&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r.bim("meta-fg")},children:oe.detailTab.submitVersion}),te&&t.jsx("a",{href:te.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r.bim("meta-fg")},children:oe.detailTab.dataLicense})]})});return Qe?t.jsx("div",{className:M,children:t.jsxs(Fi,{grid:!0,style:{minHeight:T,...q},children:[t.jsx(Gr,{breadcrumb:t.jsx(qr,{items:Le}),actions:t.jsxs(t.Fragment,{children:[!H&&t.jsx(as,{style:{border:"none",background:"transparent"}}),!H&&te&&t.jsx(ls,{...te})]})}),ke(),Be]})}):t.jsx("div",{className:M,children:t.jsxs(Fi,{wide:et,style:{minHeight:T,...q},children:[t.jsx(Gr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(_s,{char:"籍"}),t.jsx(qr,{items:Le})]}),actions:t.jsxs(t.Fragment,{children:[!H&&t.jsx(as,{}),E&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r.bim("meta-fg")},children:oe.detailTab.feedback}),!H&&te&&t.jsx(ls,{...te})]})}),t.jsx(cc,{...Z,aside:et?t.jsxs("button",{type:"button",onClick:()=>a("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r.bim("accent"),borderBottom:`1px solid ${r.bim("rule")}`},children:[le("detail.workInfo")," →"]}):Z.aside}),!et&&k.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:k.map(J=>t.jsx(dc,{label:J.label,active:J.key===o||Qe&&J.key==="basic",onClick:()=>a(J.key)},J.key))}),t.jsx("div",{style:{marginTop:!et&&k.length>1?8:0},children:Ce()}),Be]})})};function j0({id:e,label:i,copied:n,copyLabel:s}){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:s,"aria-label":o?n:s,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:r.bim("aux-fg")},children:o?"✓":"⧉"})]})}function k0(e,i){return i?e.workSubtype[i]??i:""}const mm=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],tr="zhusha",ir="bim-theme";function um(e){return e==="zhusha"||e==="indigo"||e==="ink"}function nr(e){return um(e)?e:tr}function w0(){try{return nr(window.localStorage.getItem(ir))}catch{return tr}}function pm(e){try{window.localStorage.setItem(ir,e)}catch{}}function bm(e){const i=nr(e);return document.documentElement.setAttribute("data-theme",i),i}function hm(){return nr(document.documentElement.getAttribute("data-theme"))}const v0=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],co="airy",rr="bim-layout";function fm(e){return e==="airy"||e==="boxed"}function sr(e){return fm(e)?e:co}function S0(){try{return sr(window.localStorage.getItem(rr))}catch{return co}}function $0(e){try{window.localStorage.setItem(rr,e)}catch{}}function _0(e){const i=sr(e);return document.documentElement.setAttribute("data-layout",i),i}function N0(){return sr(document.documentElement.getAttribute("data-layout"))}const z0=`try{var t=localStorage.getItem(${JSON.stringify(ir)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(rr)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,C0={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},E0=({onChange:e,style:i})=>{const{t:n}=se(),[s,o]=b.useState(tr);b.useEffect(()=>{o(hm())},[]);const a=l=>{o(bm(l)),pm(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:mm.map(l=>{const d=s===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:r.bim(C0[l.name]),boxShadow:d?`0 0 0 2px ${r.bim("page-bg")}, 0 0 0 3.5px ${r.bim("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=Se.BidLink;exports.BookIndexError=Se.BookIndexError;exports.BookIndexManager=Se.BookIndexManager;exports.BookIndexStorage=Se.BookIndexStorage;exports.BundleStorage=Se.BundleStorage;exports.ConfigError=Se.ConfigError;exports.GithubStorage=Se.GithubStorage;exports.IdGenerationError=Se.IdGenerationError;exports.IdGenerator=Se.IdGenerator;exports.LocalStorage=Se.LocalStorage;exports.MigrationError=Se.MigrationError;exports.StorageError=Se.StorageError;exports.adaptCharCord=Se.adaptCharCord;exports.adaptFig=Se.adaptFig;exports.adaptNorm=Se.adaptNorm;exports.adaptNormDetailed=Se.adaptNormDetailed;exports.adaptPunctJson=Se.adaptPunctJson;exports.base36Decode=Se.base36Decode;exports.base36Encode=Se.base36Encode;exports.base58Decode=Se.base58Decode;exports.buildId=Se.buildId;exports.buildPromotionMap=Se.buildPromotionMap;exports.cleanName=Se.cleanName;exports.decodeId=Se.decodeId;exports.decodeIdString=Se.decodeIdString;exports.encodeId=Se.encodeId;exports.extractIdFromUrl=Se.extractIdFromUrl;exports.extractStatus=Se.extractStatus;exports.extractType=Se.extractType;exports.iiifVolumeOf=Se.iiifVolumeOf;exports.isChapterSegment=Se.isChapterSegment;exports.isTextKey=Se.isTextKey;exports.loadFigUrls=Se.loadFigUrls;exports.loadReaderChapter=Se.loadReaderChapter;exports.loadReaderFiles=Se.loadReaderFiles;exports.matchChapterAcrossVersions=Se.matchChapterAcrossVersions;exports.normalizeCatalog=Se.normalizeCatalog;exports.parseId=Se.parseId;exports.pickTextVersion=Se.pickTextVersion;exports.readerManifest=Se.readerManifest;exports.readerVersions=Se.readerVersions;exports.shardOf=Se.shardOf;exports.smartDecode=Se.smartDecode;exports.textVersionLabel=Se.textVersionLabel;exports.validateResource=Se.validateResource;exports.volumeFromChar=Se.volumeFromChar;exports.Badge=r.Badge;exports.COMMON_TRADITIONAL_CHARS=r.COMMON_TRADITIONAL_CHARS;exports.FormInput=r.FormInput;exports.FormTextArea=r.FormTextArea;exports.LocaleContext=r.LocaleContext;exports.Section=r.Section;exports.TRADITIONAL_ALLOWLIST=r.TRADITIONAL_ALLOWLIST;exports.buildPageUrl=r.buildPageUrl;exports.findTraditionalChars=r.findTraditionalChars;exports.formatTemplate=r.formatTemplate;exports.getDisplayNameFromUrl=r.getDisplayNameFromUrl;exports.getMessages=r.getMessages;exports.getStartPage=r.getStartPage;exports.getT=r.getT;exports.getTypeGroupKey=r.getTypeGroupKey;exports.mergeVolumeResources=r.mergeVolumeResources;exports.normalizeVolumes=r.normalizeVolumes;exports.resourceHref=r.resourceHref;exports.useT=r.useT;exports.volumeStats=r.volumeStats;exports.VARIANT_CHARS=vi.VARIANT_CHARS;exports.normalizeVariants=vi.normalizeVariants;exports.VARIANT_SUPPLEMENT=Ym.VARIANT_SUPPLEMENT;exports.BidUrlProvider=Gm;exports.BookDetailLayout=y0;exports.BookPage=fd;exports.Breadcrumb=qr;exports.CATALOG_ALL_ID=Vt;exports.CATALOG_CSS=kd;exports.CATALOG_NARROW_QUERY=to;exports.CATALOG_PAGE_SIZE=io;exports.CATALOG_UNCLASSIFIED_ID=ci;exports.CLASSIFICATIONS=Kn;exports.CardFoot=Zi;exports.CatalogPage=Qx;exports.CatalogPager=zd;exports.CatalogTree=vd;exports.CheckFilter=oc;exports.Chip=mc;exports.ChipWall=ob;exports.CollectionCatalog=Fl;exports.CollectionPage=gd;exports.DEFAULT_LAYOUT=co;exports.DEFAULT_META_HOME_LINKS=Yd;exports.DEFAULT_READER_PREFS=ws;exports.DEFAULT_READ_HOME_LINKS=Ed;exports.DEFAULT_THEME=tr;exports.DETAIL_CSS=lc;exports.DYNASTY_GROUPS=Un;exports.Dash=ub;exports.DataTable=lb;exports.DetailFooter=yc;exports.DetailGrid=Xi;exports.DetailHeader=cc;exports.EMPTY_FILTERS=Wn;exports.ENTITY_TEXT_CSS=Ds;exports.EmptyNote=yb;exports.EntityMark=Ks;exports.EntityPage=jd;exports.EntityText=lf;exports.ExpandRow=pb;exports.ExtLink=jb;exports.FEEDBACK_FAB_OFFSET_VAR=is;exports.FILTER_SUPPORT=El;exports.FONT_SIZE_STEPS=Yt;exports.FactList=ib;exports.FeedbackButton=yg;exports.FeedbackDialog=nd;exports.FeedbackForm=rd;exports.FeedbackList=ad;exports.FeedbackTab=ld;exports.FilterChip=dc;exports.GUJI_MARKDOWN_FIELD=Hp;exports.GUJI_TABLE_NOTATION=jc;exports.GlyphBadge=_s;exports.GujiInteractiveReader=ig;exports.GujiTable=Cs;exports.GujiTextViewer=Vs;exports.GujiWarpCanvas=Hs;exports.ImagePanel=Wr;exports.IndexBrowser=ip;exports.IntroGrid=tb;exports.LAYOUTS=v0;exports.LAYOUT_STORAGE_KEY=rr;exports.LOSS_OPTIONS=Cl;exports.LocaleProvider=Zm;exports.LocaleToggle=as;exports.META_HOME_CSS=Kd;exports.META_HOME_SECTION_IDS=cm;exports.MetaCatalogTable=em;exports.MetaCollectionGroups=rm;exports.MetaDataLicense=lm;exports.MetaHomeView=p0;exports.MetaLine=vt;exports.MetaLineageCards=om;exports.MetaOnlineSites=am;exports.MetaPeopleTimeline=sm;exports.MetaRecentPanel=Zd;exports.MetaRelatedCatalogs=im;exports.MetaTypeChips=qd;exports.ModeIndicator=pl;exports.MoreButton=sb;exports.MoreLink=Ss;exports.PAGE_MAX_WIDTH=Sn;exports.PERIOD_NARROW_SHARE=Md;exports.PageFrame=Fi;exports.Quote=hb;exports.READER_CSS=Wl;exports.READ_HOME_CSS=ro;exports.READ_HOME_NARROW_QUERY=tn;exports.READ_HOME_SECTION_IDS=Ud;exports.READ_PERIOD_LABELS=n0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=vl;exports.ReadButton=Vr;exports.ReadFamousWorks=Hd;exports.ReadHomeView=s0;exports.ReadPeriodBand=Dd;exports.ReadPicks=Pd;exports.ReadPieces=Wd;exports.ReadSection=Et;exports.ReadShelf=oo;exports.ReadSibu=ao;exports.ReadStats=Ld;exports.ReadTopicGroup=Fd;exports.ReadTopics=Bd;exports.ReaderMdText=Is;exports.ReaderShell=Jl;exports.ReaderToc=Ul;exports.RepoSourceLink=ls;exports.ResourceGroup=fb;exports.ResourceLine=gb;exports.ResourceList=nu;exports.ResourceRow=fc;exports.SEARCH_VIEW_STORAGE_KEY=gs;exports.SEVEN_PAVILIONS_KEY=nm;exports.SNIPPET_MARK_END=dl;exports.SNIPPET_MARK_START=cl;exports.SORTABLE_TYPES=zl;exports.SearchInput=hl;exports.SearchResults=Ll;exports.Sec=$t;exports.SectionHead=nb;exports.SideList=di;exports.StripWarpRenderer=Xr;exports.SummaryCard=Ji;exports.THEMES=mm;exports.THEME_INIT_SCRIPT=z0;exports.THEME_STORAGE_KEY=ir;exports.TabFilter=Vn;exports.TableHead=cb;exports.TableRow=db;exports.TagRow=gc;exports.TagRows=xb;exports.TextButton=rb;exports.TextReader=td;exports.ThemeToggle=E0;exports.TopStrip=Gr;exports.VersionLineageGraph=hd;exports.VersionLineageList=bd;exports.VersionLineageView=eo;exports.VolumeChips=ab;exports.VolumeLinks=Ns;exports.WorkCard=_d;exports.WorkCardGrid=Cd;exports.WorkCatalog=ng;exports.WorkPage=pd;exports.WorkRow=Nd;exports.adaptEntityJson=Tc;exports.applyLayout=_0;exports.applyTheme=bm;exports.authorsLine=er;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Ts;exports.bucketResources=us;exports.buildCatalogTree=Ux;exports.buildCollectionTable=_l;exports.buildLineageGraph=yn;exports.buildMeiliFilter=Pu;exports.buildParagraphBlocks=Nc;exports.buildVersionRow=kl;exports.buildVersionTable=wl;exports.canParagraphize=Tn;exports.catalogNodeIdOf=Dx;exports.catalogNodeIdsOf=Wx;exports.catalogPageCount=Gx;exports.catalogTotal=no;exports.classificationPath=en;exports.clearAllRecentIds=xs;exports.compareCatalogCards=Vx;exports.computeVersionPartition=zu;exports.countActiveFilters=Yn;exports.createFeedbackTransport=Xs;exports.createTextApi=Bl;exports.currentLayout=N0;exports.currentTheme=hm;exports.defaultEntityHref=Wc;exports.defaultWorkLink=Sd;exports.deriveDating=ku;exports.deriveEditionType=Nl;exports.deriveEra=qi;exports.deriveYear=Bn;exports.deriveYearRange=ms;exports.detectGenre=qn;exports.displayAuthorRole=bs;exports.eraRank=Br;exports.feedbackTransportOf=id;exports.filtersFromParams=Ou;exports.filtersToParams=Rn;exports.findCatalogPath=wi;exports.firstAuthorText=so;exports.flattenTitles=xc;exports.flattenToc=Xl;exports.fmtCount=jt;exports.formatHitCount=jn;exports.formatVolumeRange=Dn;exports.groupRelatedWorks=wu;exports.gujiInlineToPlain=rc;exports.hasActiveFilters=Rl;exports.hasGujiMarkdownV02=Dp;exports.hasGujiTableNotation=kb;exports.hasSearchOptions=Mu;exports.headingKey=qs;exports.headingsFromPunct=Xc;exports.isCountedChar=Ms;exports.isDuiduChapter=Nn;exports.isLayoutName=fm;exports.isThemeName=um;exports.lineageHref=Vd;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Ac;exports.nestHeadings=Zc;exports.normalizeEra=Rt;exports.normalizeLayout=sr;exports.normalizeRole=ps;exports.normalizeTheme=nr;exports.normalizeVolumeIndex=Hi;exports.numberToChinese=Ki;exports.paginationItems=wd;exports.parseChineseNumber=Cn;exports.parseGujiInline=nc;exports.parseGujiTable=wc;exports.parseHeadingKey=Jc;exports.pct=lo;exports.periodLevel=Id;exports.pickReaderVersion=ql;exports.readStoredLayout=S0;exports.readStoredTheme=w0;exports.readerVersionOptionLabel=Kr;exports.remapPlainOffsets=Ic;exports.removeRecentId=Pl;exports.renderFullTextBody=Rb;exports.renderProperNames=Ec;exports.renderReaderInline=Xn;exports.resolveRecentEntry=ys;exports.resourceNote=Hn;exports.resultTabFromParam=Gu;exports.resultTabToParam=qu;exports.roleFacets=Sl;exports.rowNo=mb;exports.sameFilters=Fu;exports.sanitizeHeadings=ts;exports.saveRecentId=Hr;exports.segmentEntities=Mc;exports.setImageSourceResolver=ef;exports.shelfColumns=Rd;exports.sortFor=Au;exports.sortYear=En;exports.spineHeight=Td;exports.splitFullTextTables=zs;exports.splitHighlightSnippet=cs;exports.splitTableRow=kc;exports.storeLayout=$0;exports.storeTheme=pm;exports.summaryFromEntry=Bc;exports.summaryFromItem=Fc;exports.timelineLayout=Gd;exports.toCatalogWorkCard=Yx;exports.transportSummaryLoader=Hc;exports.typeSupportsFilters=Tl;exports.useBidUrl=Tt;exports.useChapterWarpData=qc;exports.useConvert=gt;exports.useEntitySummaryLoader=Us;exports.useI18n=se;exports.useReaderPrefs=Gl;exports.useRecentEntries=Xd;exports.validateLineageGraph=uu;exports.withDefaultLinks=ti;exports.withMetaLinks=ii;exports.yearText=Ln;
|
|
2114
|
+
`,Xd={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ii(e){return{...Xd,...e??{}}}function Jd(e,i){if(e.lineage)return e.lineage(i);const n=e.item(i),s=n.indexOf("#"),[o,a]=s<0?[n,""]:[n.slice(0,s),n.slice(s)];return`${o}${o.includes("?")?"&":"?"}tab=lineage${a}`}function mo(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function Zd(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 s=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(s),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 Pn(e,i=r.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function g0(e){return{read:e.item,work:e.item,node:e.node}}function Qd({counts:e,links:i}){const{t:n}=se(),s=i==null?void 0:i.type;if(!s)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:s(a),children:[t.jsx("b",{children:l}),d!=null&&d>0&&t.jsx("small",{children:jt(d)})]})},a))})}function em(e,i=5){const[n,s]=b.useState(null);b.useEffect(()=>{let a=!1;const l=ei().slice(0,i);if(!l.length||!e){s([]);return}return Promise.all(l.map(d=>ks(e,d))).then(d=>{a||s(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{js(),s([])},[]);return{entries:n,clear:o}}function x0(e,i,n){const s=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return s?n(s):tm(e.type,i)}function tm(e,i){return i(`metaHome.typeLabel.${e}`)}function im({entries:e,onClear:i,links:n}){const{t:s,convert:o}=se(),a=ii(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:s("metaHome.recentTitle")}),e&&e.length>0&&i&&t.jsx("button",{type:"button",onClick:i,children:s("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":s("metaHome.recentItemLabel",{type:l.type?tm(l.type,s):"",title:o(l.title)}),children:[t.jsx("i",{className:"bim-mh-ty","aria-hidden":"true",children:l.type?s(`metaHome.typeShort.${l.type}`):""}),t.jsx("span",{children:o(l.title)}),t.jsx("small",{"aria-hidden":"true",children:x0(l,s,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:s("metaHome.recentEmpty")})]})}function nm(e,i,n,s=!1){return s&&(e==="done"||e==="in_progress")?i(`metaHome.siteStatus.${e}`):e==="done"||e==="in_progress"||e==="todo"?i(`metaHome.status.${e}`):n(e)}function rm({rows:e,links:i}){const{t:n,convert:s}=se(),o=ii(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=mo(a.imported,a.total),d=a.work_id??a.collection_id,c=s(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:jt(a.total)}),t.jsx("td",{className:"bim-mh-r",children:jt(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:nm(a.status,n,s)})})]},a.id||a.name)})})]})}):null}function sm({items:e,links:i,label:n}){const{convert:s}=se();return t.jsx("ul",{className:"bim-rh-rows","aria-label":n?s(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:s(o.title)}),o.sub&&t.jsx("small",{children:s(o.sub)})]})},o.id))})}function om({works:e,links:i}){const{t:n}=se(),[s,o]=b.useState(!1);if(!e.length)return null;const a=Vi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(sm,{items:e.map(l=>({id:l.id,title:l.title,sub:tr(l)||void 0})),links:ii(i)}),a&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":s,onClick:()=>o(l=>!l),children:s?n("action.collapse"):n("metaHome.allNWorks",{n:e.length})})]})}const am="siku_qige";function y0({group:e,links:i}){const{t:n,convert:s}=se(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":Vi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[s(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(sm,{items:e.items,links:i,label:e.label}),Vi(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 lm({groups:e,links:i}){const{t:n,convert:s}=se(),o=ii(i);if(!e.length)return null;const a=e.find(c=>c.key===am),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:[s(a.label),t.jsx("small",{children:s(a.items.map(c=>d(c.title)).join("、"))})]}),t.jsx("ul",{className:"bim-mh-ge","aria-label":s(a.label),children:a.items.map(c=>t.jsx("li",{children:t.jsxs("a",{href:o.item(c.id),"aria-label":s(c.title),title:s(c.title),children:[t.jsx("span",{"aria-hidden":"true",children:s(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(y0,{group:c,links:o},c.key))})]})}const ll=34,cl=13;function dl(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?Pn(e.birth_year,i):"?"}–${e.death_year!=null?Pn(e.death_year,i):"?"}`}function j0(e,i){const n=i-e,s=n>1200?300:n>400?100:50,o=[];for(let a=Math.ceil(e/s)*s;a<=i;a+=s)o.push(a);return o}function cm({people:e,links:i}){const{t:n,convert:s}=se(),o=ii(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=Zd(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-cl):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,cl),{...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*ll+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*ll+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:[s(u.p.name),t.jsx("small",{className:"bim-rh-num",children:dl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:j0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:Pn(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:s(u.name)}),t.jsx("small",{className:"bim-rh-num",children:[u.dynasty?s(u.dynasty):"",dl(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:s(c.map(u=>u.name).join("、"))})})]})}const k0=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 dm({works:e,links:i}){const{t:n,convert:s}=se(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=tr(a);return t.jsx("li",{children:t.jsxs("a",{href:Jd(o,a.id),children:[k0,t.jsx("b",{children:s(a.title)}),l&&t.jsx("small",{children:s(l)}),t.jsx("span",{children:n("metaHome.viewLineage")})]})},a.id)})}):null}function mm({sites:e}){const{t:i,convert:n}=se(),s=e.filter(a=>a.status!=="todo"&&a.total>0),o=e.filter(a=>!s.includes(a));return e.length?t.jsxs(t.Fragment,{children:[s.length>0&&t.jsx("ul",{className:"bim-mh-cov",children:s.map(a=>{const l=mo(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:[`${jt(a.imported)} / ${jt(a.total)} ${l}% `,a.status&&t.jsx("span",{className:"bim-mh-st","data-st":a.status,children:nm(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 ml=["extant","partially_extant","lost","unknown"];function um({stats:e,links:i,version:n,repoUrl:s,downloadHref:o}){const{t:a}=se(),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=ml.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:jt(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:ml.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:jt(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"),s?t.jsx("a",{href:s,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 pm={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function w0({sections:e,links:i,head:n,transport:s,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,N;const{t:h}=se(),u=e,f=ii(i),g=g0(f),y=pm,w=em(s),j={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=>j[z]),v=z=>h(`metaHome.nav.${z}`),S=(z,R)=>z?t.jsx("a",{className:"bim-rh-more",href:z,children:R}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:oo+qd}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(Qd,{counts:u.counts,links:i})]}),s&&t.jsx(im,{entries:w.entries,onClear:w.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:v(z)})},z))})}),t.jsxs("div",{className:"bim-rh-main",children:[j.zhi&&t.jsxs(Et,{id:y.zhi,title:v("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(lo,{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(rm,{rows:u.catalog_progress,links:i}),t.jsx(om,{works:u.related_catalogs,links:i})]})]}),j.sibu&&t.jsx(Et,{id:y.sibu,title:v("sibu"),sub:h("metaHome.sibuSub"),more:S(o,h("metaHome.toCatalog")),children:t.jsx(co,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),j.cong&&t.jsx(Et,{id:y.cong,title:v("cong"),sub:h("metaHome.congSub"),more:S(a,h("metaHome.allNKindsMore",{n:jt(u.counts.collections)})),children:t.jsx(lm,{groups:u.collection_groups,links:i})}),j.people&&t.jsx(Et,{id:y.people,title:v("people"),sub:h("metaHome.peopleSub"),more:S(l,h("metaHome.allNPeopleMore",{n:jt(u.counts.entities)})),children:t.jsx(cm,{people:u.bibliographers,links:i})}),j.lineage&&t.jsx(Et,{id:y.lineage,title:v("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(dm,{works:u.lineage,links:i})}),j.sites&&t.jsx(Et,{id:y.sites,title:v("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(mm,{sites:u.sites})}),t.jsx(Et,{id:y.data,title:v("data"),sub:h("metaHome.dataSub"),children:t.jsx(um,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const bm=["_related","_catalogs","_collections","_members","_children"],v0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ls=e=>v0(e)&&!!e.h;function S0(e){return e?bm.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(ls)}):!1}function $0(e,i){const n={...e};if(!i)return n;for(const s of bm){const o=e[s];!Array.isArray(o)||!o.some(ls)||(n[s]=o.map(a=>{var c;if(!ls(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 _0(e){let i=null;const n=()=>e.getHubs?(i??(i=e.getHubs().catch(()=>null)),i):Promise.resolve(null);return new Proxy(e,{get(s,o){if(o==="getItem")return async l=>{const d=await s.getItem(l);return d&&$0(d,S0(d)?await n():null)};const a=Reflect.get(s,o,s);return typeof a=="function"?a.bind(s):a}})}const cs=({style:e})=>{const i=b.useContext(r.LocaleContext),{t:n}=se();if(!i)return null;const{locale:s,setLocale:o}=i,a=s==="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 ${r.bim("border")}`,borderRadius:"4px",background:r.bim("bg"),color:r.bim("fg"),cursor:"pointer",userSelect:"none",...e},children:[t.jsx("span",{style:{color:a?r.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:r.bim("primary"),fontWeight:a?400:700},children:n("common.localeShortHans")})]})},ds=({href:e,label:i,size:n=16,className:s,style:o})=>{const{t:a}=se(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className:s,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:n+8,height:n+8,borderRadius:4,color:r.bim("desc-fg"),textDecoration:"none",transition:"color 120ms, background 120ms",...o},onMouseEnter:d=>{d.currentTarget.style.color=r.bim("fg")},onMouseLeave:d=>{d.currentTarget.style.color=r.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 Br(e){const i=e.text_count;return typeof i=="number"&&i>0}function Hr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function N0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const z0=({id:e,transport:i,initialDetail:n,initialEntry:s,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:w,renderLink:j,assetBase:x,enrichDetail:v,getSourceLink:S,readLink:$,railTop:N,extraTabs:z=[],showFeedbackTab:R=!0,feedbackApiUrl:O,height:C,footerExtra:I,hideHeaderControls:D=!1,className:A,style:X})=>{const B=b.useMemo(()=>_0(i),[i]),ae=b.useMemo(()=>od(B)??Zs(O),[B,O]),te=r.useT(),{t:ce,convert:be}=se(),[oe]=b.useState(()=>{if(!N0(e,n))return null;const q={...n},ke=s??Hr(e,q);return v&&v(ke,q),{id:e,entry:ke,detail:q}}),[K,ze]=b.useState((oe==null?void 0:oe.entry)??null),[F,me]=b.useState((oe==null?void 0:oe.detail)??null),[U,ne]=b.useState(!oe),[ue,G]=b.useState(!1),[L,Se]=b.useState([]),[ge,$e]=b.useState(!1),[_,P]=b.useState(null),[ie,re]=b.useState(null),[Re,Y]=b.useState(null),[de,le]=b.useState(!1),Te=b.useRef(null),_e=b.useRef(0),[xe,Ce]=b.useState(null),Ae=l!==void 0?l:xe,Je=b.useCallback(q=>{d?d(q):Ce(q)},[d]),ut=b.useCallback(async q=>{if(!B.getCollectionCatalogs&&!B.getCollectionCatalog){Se([]);return}$e(!0);try{if(B.getCollectionCatalogs)Se(await B.getCollectionCatalogs(q)||[]);else if(B.getCollectionCatalog){const ke=await B.getCollectionCatalog(q);Se(ke?[{resource_id:"",data:ke}]:[])}}catch{Se([])}finally{$e(!1)}},[B]),Ve=b.useCallback(async q=>{var ke,Xe;if(!B.getTextManifest||!B.getTextIndex){P(null),re(q);return}try{const Ze=ve.pickTextVersion(await B.getTextManifest(q)),De=Ze?await B.getTextIndex(q,Ze.key):null;P(De&&De.chapters.length>0?{chapters:De.chapters.map(Be=>({n:Be.n,title:Be.title,file:Be.file})),source:{name:((ke=De.source)==null?void 0:ke.name)??(Ze==null?void 0:Ze.source_name),license:((Xe=De.source)==null?void 0:Xe.license)??(Ze==null?void 0:Ze.license)??void 0}}:null)}catch{P(null)}finally{re(q)}},[B]),ht=b.useCallback(async(q,ke)=>{const Xe=++_e.current,Ze=()=>Xe!==_e.current;le(!0);try{if(B.getLineageGraph){const ft=await B.getLineageGraph(q);if(Ze())return;ft&&Y(ft)}const De=ke.version_graph;if(!De||!De.enabled){Re||Y(null),Te.current=null;return}const Be=gs(ke),mt=(await Qn(Be,Zn,async ft=>{try{return await B.getItem(ft)}catch{return null}},Ze)).filter(Boolean);if(Ze())return;Te.current={work:ke,books:mt};const pt=p??De.default_collection??(De.core_books&&De.core_books.length>0?"core":"all"),We=pt==="core"&&Array.isArray(De.core_books)&&De.core_books.length>0?"core":pt??"all";Y(jn(ke,mt,We))}catch{if(Ze())return;Y(null),Te.current=null}finally{Ze()||le(!1)}},[B]),Ge=b.useRef({initialDetail:n,initialEntry:s});Ge.current={initialDetail:n,initialEntry:s},b.useEffect(()=>{let q=!1;_e.current++,le(!1);const ke=Be=>{Be.type==="collection"?ut(e):Be.type==="work"?(Be.version_graph||B.getLineageGraph)&&ht(e,Be):Be.type==="book"&&Br(Be)&&Ve(e)},Xe=Ge.current;let Ze=null;if(oe&&oe.id===e)Ze=oe;else if(Xe.initialDetail&&Xe.initialDetail.id===e){const Be={...Xe.initialDetail},dt=Xe.initialEntry??Hr(e,Be);v&&v(dt,Be),Ze={entry:dt,detail:Be}}return Ze?(G(!1),Se(Be=>Be.length?[]:Be),P(null),Y(null),Te.current=null,ze(Ze.entry),me(Ze.detail),ne(!1),ke(Ze.detail),()=>{q=!0}):((async()=>{ne(!0),G(!1),ze(null),me(null),Se([]),P(null),Y(null),Te.current=null;try{const Be=await B.getItem(e);if(q)return;if(!Be){G(!0);return}const dt=Be;let mt=null;if(B.getEntry&&(mt=await B.getEntry(e),q))return;mt||(mt=Hr(e,dt)),v&&v(mt,dt),ze(mt),me(dt),ke(dt)}catch{q||G(!0)}finally{q||ne(!1)}})(),()=>{q=!0})},[e,B,oe,v,ut,ht,Ve]),b.useEffect(()=>{const q=Te.current;!q||!p||Y(jn(q.work,q.books,p))},[p]);const k=[];if(F){if(k.push({key:"basic",label:te.detailTab.basicInfo}),F.type==="collection"){ge&&L.length===0&&k.push({key:"catalog:loading",label:`${te.detailTab.catalog}…`});for(const q of L)k.push({key:`catalog:${q.resource_id}`,label:q.short_name?`${be(q.short_name)}${te.detailTab.catalogSuffix}`:te.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&k.push({key:o,label:te.detailTab.fullText}),F.type==="work"&&(Re||de)&&k.push({key:"lineage",label:de?`${te.detailTab.lineage}…`:te.detailTab.lineage});for(const q of z)(q.position??"before-feedback")==="before-feedback"&&q.shouldShow(F)&&k.push({key:q.key,label:q.label});R&&o==="feedback"&&k.push({key:"feedback",label:te.detailTab.feedback});for(const q of z)q.position==="after-feedback"&&q.shouldShow(F)&&k.push({key:q.key,label:q.label})}b.useEffect(()=>{if(o!=="emendated"||!F)return;a("basic");const q=setTimeout(()=>{var ke;(ke=document.getElementById("studies"))==null||ke.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(q)},[o,F,a]);const Q=K&&F&&S?S({activeTab:o,activeJuan:Ae,entry:K,detail:F}):null,J=b.useMemo(()=>{var De,Be,dt,mt,pt;if(!F)return null;const ke=(F.authors??[]).map(We=>{const ft=fs(We.role);return`${We.dynasty?`〔${be(We.dynasty)}〕`:""}${be(We.name)}${ft?` ${be(ft)}`:""}`}).join(" · ");let Xe=!1;try{Xe=ve.extractStatus(F.id)==="draft"}catch{}if(F.type==="book"){const We=F;return{title:be(We.title),subtitle:We.edition?be(We.edition):ke||void 0,aside:[Xe?te.status.draft:"",ke&&We.edition?ke:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(F.type==="collection"){const We=F;return{title:be(We.title),subtitle:be(qt(We,te.unit.juan))||void 0,aside:[(De=We.publication_info)==null?void 0:De.year,Xe?te.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ke||void 0}}if(F.type==="entity"){const We=F,ft=M=>M==null?"":M<0?ce("detail.bce",{n:-M}):String(M),Z=((Be=We.dates)==null?void 0:Be.birth)!=null||((dt=We.dates)==null?void 0:dt.death)!=null?`${ft(((mt=We.dates)==null?void 0:mt.birth)??void 0)||"?"}—${ft(((pt=We.dates)==null?void 0:pt.death)??void 0)||"?"}`:"";return{title:be(We.primary_name||We.title),subtitle:[We.dynasty?`〔${be(We.dynasty)}〕`:"",Z].filter(Boolean).join(" ")||void 0,aside:Xe?te.status.draft:void 0,secondLine:void 0}}const Ze=be(qt(F,te.unit.juan));return{title:be(F.title),subtitle:[Ze,ke].filter(Boolean).join(" · ")||void 0,aside:[E0(te,F.subtype),Xe?te.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[F,be,te,ce]),pe=F&&Br(F)?"text":null,Pe=()=>{Je(null),a("fulltext")};let T=null;if(F&&$){const q=$({detail:F,kind:pe});q&&(T=t.jsx(qr,{href:q}))}else pe&&(T=t.jsx(qr,{onClick:Pe}));const fe=q=>{if(!F)return null;const ke=q.replace(/\.[^.]+$/,"");if($){const Xe=$({detail:F,kind:pe,juan:ke});return Xe?{href:Xe}:null}return{onClick:()=>{Je(ke),a("fulltext")}}},V=new Set(z.map(q=>q.key)),Ne=k.filter(q=>q.key.startsWith("catalog:")&&q.key!=="catalog:loading"||q.key==="lineage"&&!!Re&&!de||V.has(q.key)).map(q=>({key:q.key,label:q.label,onClick:()=>a(q.key)})),je=()=>{var q;return F?F.type==="work"?t.jsx(gd,{data:F,transport:B,onNavigate:g,renderLink:j,readAction:T,railTop:N,railLinks:Ne}):F.type==="book"?t.jsx(jd,{data:F,transport:B,onNavigate:g,renderLink:j,readAction:T,fullText:_,fullTextPending:Br(F)&&!!B.getTextManifest&&ie!==F.id,chapterLink:fe,railTop:N,railLinks:Ne}):F.type==="collection"?t.jsx(kd,{data:F,catalog:(q=L[0])==null?void 0:q.data,transport:B,onNavigate:g,renderLink:j,readAction:T,railTop:N,railLinks:Ne,catalogAction:L.length>0?t.jsxs("a",{href:"#catalog",onClick:ke=>{ke.preventDefault(),a(`catalog:${L[0].resource_id}`)},children:[be(te.detailTab.collectionCatalog)," →"]}):null}):t.jsx(Sd,{data:F,transport:B,onNavigate:g,renderLink:j,railTop:N,railLinks:Ne,assetBase:x}):null},Ie=()=>{var ke,Xe,Ze;if(!K||!F)return null;if(o==="basic"||o==="emendated")return je();if(typeof o=="string"&&o.startsWith("catalog:")){const De=(ke=L.find(Be=>`catalog:${Be.resource_id}`===o))==null?void 0:ke.data;return t.jsx(Wl,{data:De,onNavigate:g,renderLink:j})}if(o==="collated"||o==="fulltext")return t.jsx(sd,{id:e,transport:B,chapter:Ae,onLocationChange:De=>Je(De.chapter),onNavigate:g});if(o==="lineage"){if(!Re)return t.jsx("div",{style:{color:r.bim("label-fg"),padding:"24px 0"},children:ce(de?"detail.loading":"detail.noLineageGraph")});const De=F.type==="work"?F:null;return t.jsx(io,{graph:Re,renderLink:j,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((Xe=De==null?void 0:De.version_graph)==null?void 0:Xe.default_collection),onCollectionChange:h,collectionsAvailable:(Ze=De==null?void 0:De.version_graph)==null?void 0:Ze.collections,collectionCounts:(()=>{var pt,We,ft,Z,M,ee,we;if(!De)return;const Be={},dt=((pt=Te.current)==null?void 0:pt.books)??[];Be.all=(((We=De._books)==null?void 0:We.length)??0)-(((Z=(ft=De.version_graph)==null?void 0:ft.excluded_books)==null?void 0:Z.length)??0);const mt=(M=De.version_graph)==null?void 0:M.collections;if(mt)for(const Me of Object.keys(mt))Be[Me]=jn(De,dt,Me).nodes.filter(Fe=>Fe.kind==="book"&&!Fe.bridge).length;return Be.core==null&&((we=(ee=De.version_graph)==null?void 0:ee.core_books)!=null&&we.length)&&(Be.core=De.version_graph.core_books.length),Be})()})}if(o==="feedback"&&R)return t.jsx(ud,{resourceId:e,transport:ae});const q=z.find(De=>De.key===o);return q?q.render({detail:F,entry:K,transport:B,onNavigate:g}):null};if(U)return t.jsx(Fi,{style:{minHeight:C,...X},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((q,ke)=>t.jsx("div",{style:{height:ke===1?40:16,width:q,opacity:.35,background:r.bim("rule")}},ke))})});if(ue||!F||!K||!J)return t.jsx(Fi,{style:{minHeight:C,...X},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r.bim("label-fg"),fontSize:14},children:ce("detail.notFound")})});const Qe=o==="basic"||o==="emendated",Oe=[{label:w??te.detailTab.backToIndex,onClick:y}];if(F.type==="book"&&F.work_id){const q=F.work_id;Oe.push({label:te.indexType.work,id:q,onClick:()=>g==null?void 0:g(q)})}Oe.push({label:te.indexType[F.type]});const et=o==="collated"||o==="fulltext",yt=typeof I=="string"?te.status[I.trim()]??I:I,He=t.jsx(vc,{left:t.jsxs(t.Fragment,{children:[yt,yt?" · ":"",t.jsx(C0,{id:F.id,label:te.label.id,copied:te.action.copied,copyLabel:te.action.copy})]}),right:t.jsxs(t.Fragment,{children:[R&&!Qe&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r.bim("meta-fg")},children:te.detailTab.submitVersion}),Q&&t.jsx("a",{href:Q.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r.bim("meta-fg")},children:te.detailTab.dataLicense})]})});return Qe?t.jsx("div",{className:A,children:t.jsxs(Fi,{grid:!0,style:{minHeight:C,...X},children:[t.jsx(Xr,{breadcrumb:t.jsx(Jr,{items:Oe}),actions:t.jsxs(t.Fragment,{children:[!D&&t.jsx(cs,{style:{border:"none",background:"transparent"}}),!D&&Q&&t.jsx(ds,{...Q})]})}),je(),He]})}):t.jsx("div",{className:A,children:t.jsxs(Fi,{wide:et,style:{minHeight:C,...X},children:[t.jsx(Xr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(zs,{char:"籍"}),t.jsx(Jr,{items:Oe})]}),actions:t.jsxs(t.Fragment,{children:[!D&&t.jsx(cs,{}),R&&t.jsx("button",{type:"button",onClick:()=>a("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r.bim("meta-fg")},children:te.detailTab.feedback}),!D&&Q&&t.jsx(ds,{...Q})]})}),t.jsx(pc,{...J,aside:et?t.jsxs("button",{type:"button",onClick:()=>a("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:r.bim("accent"),borderBottom:`1px solid ${r.bim("rule")}`},children:[ce("detail.workInfo")," →"]}):J.aside}),!et&&k.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:k.map(q=>t.jsx(bc,{label:q.label,active:q.key===o||Qe&&q.key==="basic",onClick:()=>a(q.key)},q.key))}),t.jsx("div",{style:{marginTop:!et&&k.length>1?8:0},children:Ie()}),He]})})};function C0({id:e,label:i,copied:n,copyLabel:s}){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:s,"aria-label":o?n:s,className:"bim-d-hit",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:14,minWidth:32,minHeight:32,display:"inline-flex",alignItems:"center",justifyContent:"center",color:r.bim("aux-fg")},children:o?"✓":"⧉"})]})}function E0(e,i){return i?e.workSubtype[i]??i:""}const hm=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],ir="zhusha",nr="bim-theme";function fm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function rr(e){return fm(e)?e:ir}function R0(){try{return rr(window.localStorage.getItem(nr))}catch{return ir}}function gm(e){try{window.localStorage.setItem(nr,e)}catch{}}function xm(e){const i=rr(e);return document.documentElement.setAttribute("data-theme",i),i}function ym(){return rr(document.documentElement.getAttribute("data-theme"))}const T0=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],uo="airy",sr="bim-layout";function jm(e){return e==="airy"||e==="boxed"}function or(e){return jm(e)?e:uo}function I0(){try{return or(window.localStorage.getItem(sr))}catch{return uo}}function M0(e){try{window.localStorage.setItem(sr,e)}catch{}}function A0(e){const i=or(e);return document.documentElement.setAttribute("data-layout",i),i}function L0(){return or(document.documentElement.getAttribute("data-layout"))}const P0=`try{var t=localStorage.getItem(${JSON.stringify(nr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(sr)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,O0={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},F0=({onChange:e,style:i})=>{const{t:n}=se(),[s,o]=b.useState(ir);b.useEffect(()=>{o(ym())},[]);const a=l=>{o(xm(l)),gm(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:hm.map(l=>{const d=s===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:r.bim(O0[l.name]),boxShadow:d?`0 0 0 2px ${r.bim("page-bg")}, 0 0 0 3.5px ${r.bim("aux-fg")}`:"none"}})},l.name)})})};exports.BidLink=ve.BidLink;exports.BookIndexError=ve.BookIndexError;exports.BookIndexManager=ve.BookIndexManager;exports.BookIndexStorage=ve.BookIndexStorage;exports.BundleStorage=ve.BundleStorage;exports.ConfigError=ve.ConfigError;exports.GithubStorage=ve.GithubStorage;exports.IdGenerationError=ve.IdGenerationError;exports.IdGenerator=ve.IdGenerator;exports.LocalStorage=ve.LocalStorage;exports.MigrationError=ve.MigrationError;exports.StorageError=ve.StorageError;exports.adaptCharCord=ve.adaptCharCord;exports.adaptFig=ve.adaptFig;exports.adaptNorm=ve.adaptNorm;exports.adaptNormDetailed=ve.adaptNormDetailed;exports.adaptPunctJson=ve.adaptPunctJson;exports.base36Decode=ve.base36Decode;exports.base36Encode=ve.base36Encode;exports.base58Decode=ve.base58Decode;exports.buildId=ve.buildId;exports.buildPromotionMap=ve.buildPromotionMap;exports.cleanName=ve.cleanName;exports.decodeId=ve.decodeId;exports.decodeIdString=ve.decodeIdString;exports.encodeId=ve.encodeId;exports.extractIdFromUrl=ve.extractIdFromUrl;exports.extractStatus=ve.extractStatus;exports.extractType=ve.extractType;exports.iiifVolumeOf=ve.iiifVolumeOf;exports.isChapterSegment=ve.isChapterSegment;exports.isTextKey=ve.isTextKey;exports.loadFigUrls=ve.loadFigUrls;exports.loadReaderChapter=ve.loadReaderChapter;exports.loadReaderFiles=ve.loadReaderFiles;exports.matchChapterAcrossVersions=ve.matchChapterAcrossVersions;exports.normalizeCatalog=ve.normalizeCatalog;exports.parseId=ve.parseId;exports.pickTextVersion=ve.pickTextVersion;exports.readerManifest=ve.readerManifest;exports.readerVersions=ve.readerVersions;exports.shardOf=ve.shardOf;exports.smartDecode=ve.smartDecode;exports.textVersionLabel=ve.textVersionLabel;exports.validateResource=ve.validateResource;exports.volumeFromChar=ve.volumeFromChar;exports.Badge=r.Badge;exports.COMMON_TRADITIONAL_CHARS=r.COMMON_TRADITIONAL_CHARS;exports.FormInput=r.FormInput;exports.FormTextArea=r.FormTextArea;exports.LocaleContext=r.LocaleContext;exports.Section=r.Section;exports.TRADITIONAL_ALLOWLIST=r.TRADITIONAL_ALLOWLIST;exports.buildPageUrl=r.buildPageUrl;exports.findTraditionalChars=r.findTraditionalChars;exports.formatTemplate=r.formatTemplate;exports.getDisplayNameFromUrl=r.getDisplayNameFromUrl;exports.getMessages=r.getMessages;exports.getStartPage=r.getStartPage;exports.getT=r.getT;exports.getTypeGroupKey=r.getTypeGroupKey;exports.mergeVolumeResources=r.mergeVolumeResources;exports.normalizeVolumes=r.normalizeVolumes;exports.resourceHref=r.resourceHref;exports.useT=r.useT;exports.volumeStats=r.volumeStats;exports.VARIANT_CHARS=vi.VARIANT_CHARS;exports.normalizeVariants=vi.normalizeVariants;exports.VARIANT_SUPPLEMENT=Xm.VARIANT_SUPPLEMENT;exports.BidUrlProvider=Zm;exports.BookDetailLayout=z0;exports.BookPage=jd;exports.Breadcrumb=Jr;exports.CATALOG_ALL_ID=Vt;exports.CATALOG_CSS=$d;exports.CATALOG_NARROW_QUERY=no;exports.CATALOG_PAGE_SIZE=ro;exports.CATALOG_UNCLASSIFIED_ID=ci;exports.CLASSIFICATIONS=Yn;exports.CardFoot=Zi;exports.CatalogPage=l0;exports.CatalogPager=Td;exports.CatalogTree=Nd;exports.CheckFilter=dc;exports.Chip=hc;exports.ChipWall=db;exports.CollectionCatalog=Wl;exports.CollectionPage=kd;exports.DEFAULT_LAYOUT=uo;exports.DEFAULT_META_HOME_LINKS=Xd;exports.DEFAULT_READER_PREFS=Ss;exports.DEFAULT_READ_HOME_LINKS=Md;exports.DEFAULT_THEME=ir;exports.DETAIL_CSS=uc;exports.DYNASTY_GROUPS=Kn;exports.Dash=fb;exports.DataTable=ub;exports.DetailFooter=vc;exports.DetailGrid=Xi;exports.DetailHeader=pc;exports.EMPTY_FILTERS=Un;exports.ENTITY_TEXT_CSS=Us;exports.EmptyNote=vb;exports.EntityMark=Vs;exports.EntityPage=Sd;exports.EntityText=gf;exports.ExpandRow=gb;exports.ExtLink=Sb;exports.FEEDBACK_FAB_OFFSET_VAR=rs;exports.FILTER_SUPPORT=Ml;exports.FONT_SIZE_STEPS=Yt;exports.FactList=ob;exports.FeedbackButton=zg;exports.FeedbackDialog=ad;exports.FeedbackForm=ld;exports.FeedbackList=md;exports.FeedbackTab=ud;exports.FilterChip=bc;exports.GUJI_MARKDOWN_FIELD=Kp;exports.GUJI_TABLE_NOTATION=Sc;exports.GlyphBadge=zs;exports.GujiInteractiveReader=mg;exports.GujiTable=Rs;exports.GujiTextViewer=qs;exports.GujiWarpCanvas=Ws;exports.ImagePanel=Kr;exports.IndexBrowser=op;exports.IntroGrid=sb;exports.LAYOUTS=T0;exports.LAYOUT_STORAGE_KEY=sr;exports.LOSS_OPTIONS=Il;exports.LocaleProvider=iu;exports.LocaleToggle=cs;exports.META_HOME_CSS=qd;exports.META_HOME_SECTION_IDS=pm;exports.MetaCatalogTable=rm;exports.MetaCollectionGroups=lm;exports.MetaDataLicense=um;exports.MetaHomeView=w0;exports.MetaLine=vt;exports.MetaLineageCards=dm;exports.MetaOnlineSites=mm;exports.MetaPeopleTimeline=cm;exports.MetaRecentPanel=im;exports.MetaRelatedCatalogs=om;exports.MetaTypeChips=Qd;exports.ModeIndicator=gl;exports.MoreButton=cb;exports.MoreLink=_s;exports.PAGE_MAX_WIDTH=$n;exports.PERIOD_NARROW_SHARE=Od;exports.PageFrame=Fi;exports.Quote=yb;exports.READER_CSS=Vl;exports.READ_HOME_CSS=oo;exports.READ_HOME_NARROW_QUERY=tn;exports.READ_HOME_SECTION_IDS=Gd;exports.READ_PERIOD_LABELS=u0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Nl;exports.ReadButton=qr;exports.ReadFamousWorks=Kd;exports.ReadHomeView=b0;exports.ReadPeriodBand=Yd;exports.ReadPicks=Hd;exports.ReadPieces=Vd;exports.ReadSection=Et;exports.ReadShelf=lo;exports.ReadSibu=co;exports.ReadStats=Bd;exports.ReadTopicGroup=Wd;exports.ReadTopics=Ud;exports.ReaderMdText=As;exports.ReaderShell=tc;exports.ReaderToc=Gl;exports.RepoSourceLink=ds;exports.ResourceGroup=jb;exports.ResourceLine=kb;exports.ResourceList=au;exports.ResourceRow=jc;exports.SEARCH_VIEW_STORAGE_KEY=ys;exports.SEVEN_PAVILIONS_KEY=am;exports.SNIPPET_MARK_END=bl;exports.SNIPPET_MARK_START=pl;exports.SORTABLE_TYPES=Tl;exports.SearchInput=yl;exports.SearchResults=Bl;exports.Sec=$t;exports.SectionHead=ab;exports.SideList=di;exports.StripWarpRenderer=Zr;exports.SummaryCard=Ji;exports.THEMES=hm;exports.THEME_INIT_SCRIPT=P0;exports.THEME_STORAGE_KEY=nr;exports.TabFilter=Gn;exports.TableHead=pb;exports.TableRow=bb;exports.TagRow=kc;exports.TagRows=wb;exports.TextButton=lb;exports.TextReader=sd;exports.ThemeToggle=F0;exports.TopStrip=Xr;exports.VersionLineageGraph=yd;exports.VersionLineageList=xd;exports.VersionLineageView=io;exports.VolumeChips=mb;exports.VolumeLinks=Cs;exports.WorkCard=Ed;exports.WorkCardGrid=Id;exports.WorkCatalog=ug;exports.WorkPage=gd;exports.WorkRow=Rd;exports.adaptEntityJson=Lc;exports.applyLayout=A0;exports.applyTheme=xm;exports.authorsLine=tr;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Ms;exports.bucketResources=bs;exports.buildCatalogTree=Qx;exports.buildCollectionTable=El;exports.buildLineageGraph=jn;exports.buildMeiliFilter=Hu;exports.buildParagraphBlocks=Rc;exports.buildVersionRow=$l;exports.buildVersionTable=_l;exports.canParagraphize=In;exports.catalogNodeIdOf=Jx;exports.catalogNodeIdsOf=Zx;exports.catalogPageCount=n0;exports.catalogTotal=so;exports.classificationPath=en;exports.clearAllRecentIds=js;exports.compareCatalogCards=i0;exports.computeVersionPartition=Tu;exports.countActiveFilters=Vn;exports.createFeedbackTransport=Zs;exports.createTextApi=Ul;exports.currentLayout=L0;exports.currentTheme=ym;exports.defaultEntityHref=Vc;exports.defaultWorkLink=zd;exports.deriveDating=$u;exports.deriveEditionType=Rl;exports.deriveEra=qi;exports.deriveYear=Hn;exports.deriveYearRange=ps;exports.detectGenre=Xn;exports.displayAuthorRole=fs;exports.eraRank=Dr;exports.feedbackTransportOf=od;exports.filtersFromParams=Du;exports.filtersToParams=Tn;exports.findCatalogPath=wi;exports.firstAuthorText=ao;exports.flattenTitles=wc;exports.flattenToc=ec;exports.fmtCount=jt;exports.formatHitCount=kn;exports.formatVolumeRange=Wn;exports.groupRelatedWorks=_u;exports.gujiInlineToPlain=lc;exports.hasActiveFilters=Al;exports.hasGujiMarkdownV02=Yp;exports.hasGujiTableNotation=$b;exports.hasSearchOptions=Ou;exports.headingKey=Js;exports.headingsFromPunct=ed;exports.isCountedChar=Ls;exports.isDuiduChapter=zn;exports.isLayoutName=jm;exports.isThemeName=fm;exports.lineageHref=Jd;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Fc;exports.nestHeadings=id;exports.normalizeEra=Rt;exports.normalizeLayout=or;exports.normalizeRole=hs;exports.normalizeTheme=rr;exports.normalizeVolumeIndex=Hi;exports.numberToChinese=Ki;exports.paginationItems=_d;exports.parseChineseNumber=En;exports.parseGujiInline=ac;exports.parseGujiTable=_c;exports.parseHeadingKey=td;exports.pct=mo;exports.periodLevel=Pd;exports.pickReaderVersion=Ql;exports.readStoredLayout=I0;exports.readStoredTheme=R0;exports.readerVersionOptionLabel=Vr;exports.remapPlainOffsets=Pc;exports.removeRecentId=Hl;exports.renderFullTextBody=Ab;exports.renderProperNames=Mc;exports.renderReaderInline=Jn;exports.resolveRecentEntry=ks;exports.resourceNote=Dn;exports.resultTabFromParam=Zu;exports.resultTabToParam=Qu;exports.roleFacets=zl;exports.rowNo=hb;exports.sameFilters=Wu;exports.sanitizeHeadings=ns;exports.saveRecentId=Wr;exports.segmentEntities=Oc;exports.setImageSourceResolver=df;exports.shelfColumns=Ad;exports.sortFor=Fu;exports.sortYear=Rn;exports.spineHeight=Ld;exports.splitFullTextTables=Es;exports.splitHighlightSnippet=ms;exports.splitTableRow=$c;exports.storeLayout=M0;exports.storeTheme=gm;exports.summaryFromEntry=Uc;exports.summaryFromItem=Wc;exports.timelineLayout=Zd;exports.toCatalogWorkCard=t0;exports.transportSummaryLoader=Kc;exports.typeSupportsFilters=Ll;exports.useBidUrl=Tt;exports.useChapterWarpData=Qc;exports.useConvert=gt;exports.useEntitySummaryLoader=Ys;exports.useI18n=se;exports.useReaderPrefs=Zl;exports.useRecentEntries=em;exports.validateLineageGraph=fu;exports.withDefaultLinks=ti;exports.withMetaLinks=ii;exports.yearText=Pn;
|