book-index-ui 0.66.6 → 0.66.7
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 +21 -20
- package/dist/index.js +543 -531
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Km=Object.create;var Bo=Object.defineProperty;var Ym=Object.getOwnPropertyDescriptor;var Vm=Object.getOwnPropertyNames;var Gm=Object.getPrototypeOf,qm=Object.prototype.hasOwnProperty;var Xm=(e,i,n,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of Vm(i))!qm.call(e,o)&&o!==n&&Bo(e,o,{get:()=>i[o],enumerable:!(s=Ym(i,o))||s.enumerable});return e};var hn=(e,i,n)=>(n=e!=null?Km(Gm(e)):{},Xm(i||!e||!e.__esModule?Bo(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./storage-entry-D6X5zpk8.cjs"),t=require("react/jsx-runtime"),b=require("react"),r=require("./Badge-Czc0_9hI.cjs"),Jm=require("opencc-js/t2cn"),vi=require("./variant-chars-kDZNY5eM.cjs"),Zm=require("react-markdown"),Qm=require("remark-gfm"),eu=require("./variant-supplement.cjs"),tu=e=>`/item/${e}`,gl=b.createContext(tu);function iu({buildUrl:e,children:i}){const n=b.useMemo(()=>e,[e]);return t.jsx(gl.Provider,{value:n,children:i})}function It(){return b.useContext(gl)}const xl="",yl="";function bs(e){const i=[];let n=!1,s=e;for(;s.length;){const o=n?yl:xl,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 Mi=null;function jl(){if(Mi)return Mi;try{const e=Jm.Converter({from:"t",to:"cn"});Mi=r.withProtectedTerms(i=>e(vi.normalizeVariants(i)))}catch{Mi=e=>e}return Mi}const kl="bim-locale";function nu(){try{const e=localStorage.getItem(kl);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function ru(e){try{localStorage.setItem(kl,e)}catch{}}const su="zh-Hans",ou=({locale:e,onLocaleChange:i,converter:n,children:s})=>{const[o,a]=b.useState(e??su),l=e??o;b.useEffect(()=>{if(e)return;const p=nu();p&&p!==o&&a(p)},[]);const d=b.useMemo(()=>l==="zh-Hans"?n??jl():null,[l,n]),c=b.useCallback(p=>{a(p),ru(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})},au=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>=au){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 oe(){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 lu(e,i,n){return e?e==="orig"?null:i==="zh-Hans"?n??jl():e==="hant"?vi.normalizeVariants:n:i==="zh-Hans"?n:vi.normalizeVariants}const cu=({mode:e,children:i})=>{const n=b.useContext(r.LocaleContext),s=b.useMemo(()=>n&&{...n,converter:lu(e,n.locale,n.converter)},[n,e]);return t.jsx(r.LocaleContext.Provider,{value:s,children:i})},Ho={text:r.bim("restype-text"),image:r.bim("restype-image"),"text+image":r.bim("restype-text-image"),physical:r.bim("restype-physical")};function du(e){return e.includes("text")&&e.includes("image")?Ho["text+image"]:Ho[e[0]||"physical"]}const mu=({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 k=new Map,x=[],j=new Map;d.forEach((v,$)=>{const _=v.group||(v.label?`_label:${$}`:void 0);!v.group&&v.label&&_&&j.set(_,v.label),_?(k.has(_)||k.set(_,[]),k.get(_).push(v)):x.push(v)});for(const v of k.values())v.sort(($,_)=>{const N=I=>I.group_role==="origin"?0:I.group_role==="mirror"?1:2;return N($)-N(_)});return{mirrorGroups:k,ungroupedItems:x,labelOnlyKeys:j}},[d]),h={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=k=>h[k]?h[k]:k.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((k,x)=>t.jsx(vr,{item:k},k.id||x))});const f=(k,x)=>{const j=n==null?void 0:n[k],v=p.get(k)||(j==null?void 0:j.label)||k,$=j==null?void 0:j.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(vr,{item:_,onNavigate:s,renderLink:o},_.id||N))})]},`group-${k}`)},g=new Map;for(const k of m){const x=r.getTypeGroupKey(r.getResourceTypes(k));g.has(x)||g.set(x,[]),g.get(x).push(k)}const y=["text","image","text+image","physical"],S=[...y.filter(k=>g.has(k)),...[...g.keys()].filter(k=>!y.includes(k)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([k,x])=>f(k,x)),S.map(k=>{const x=g.get(k),j=du(k.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:u(k)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((v,$)=>t.jsx(vr,{item:v,onNavigate:s,renderLink:o},v.id||$))})]},k)})]})},uu={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")}},vr=({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?{...uu[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)})})]})},wl=({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})]})]})},Fn="bim-search-history",Do=10,Wo=8;function Di(){try{const e=localStorage.getItem(Fn);return e?JSON.parse(e):[]}catch{return[]}}function vl(e){try{const i=Di().filter(n=>n!==e);i.unshift(e),i.length>Do&&(i.length=Do),localStorage.setItem(Fn,JSON.stringify(i))}catch{}}function pu(e){try{const i=Di().filter(n=>n!==e);localStorage.setItem(Fn,JSON.stringify(i))}catch{}}function bu(){try{localStorage.removeItem(Fn)}catch{}}const Sl=({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,S]=b.useState(Di),k=b.useRef(null),x=b.useRef(null),j=b.useRef(null),v=b.useRef(!1);b.useEffect(()=>{g(-1);const R=i.trim();if(!R){u(y.map(q=>({type:"history",text:q})));return}if(!e.searchAll){u([]);return}let O=!1;const M=setTimeout(()=>{e.searchAll(R,Wo).then(q=>{if(O)return;const P=[...q.works,...q.books,...q.collections,...q.entities??[]];u(P.slice(0,Wo).map(le=>({type:"entry",text:le.title||le.id,entry:le})))}).catch(()=>{O||u([])})},80);return()=>{O=!0,clearTimeout(M)}},[i,y,e]),b.useEffect(()=>{const R=O=>{j.current&&!j.current.contains(O.target)&&p(!1)};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]),b.useEffect(()=>{const R=O=>{var M,q;if(O.key==="/"&&document.activeElement!==k.current){const P=(M=document.activeElement)==null?void 0:M.tagName;if(P==="INPUT"||P==="TEXTAREA"||P==="SELECT")return;O.preventDefault(),(q=k.current)==null||q.focus()}};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[]);const $=b.useCallback(R=>{R.trim()&&(vl(R.trim()),S(Di())),s(R),p(!1)},[s]),_=b.useCallback(R=>{R.type==="history"?(n(R.text),$(R.text)):R.entry&&(o?(o(R.entry),p(!1)):(n(R.text),$(R.text)))},[n,$,o]),N=b.useCallback(R=>{if(!m||h.length===0){R.key==="Enter"&&$(i);return}switch(R.key){case"ArrowDown":R.preventDefault(),g(O=>(O+1)%h.length);break;case"ArrowUp":R.preventDefault(),g(O=>(O-1+h.length)%h.length);break;case"Enter":R.preventDefault(),f>=0&&f<h.length?_(h[f]):$(i);break;case"Escape":R.preventDefault(),p(!1);break}},[m,h,f,i,$,_]),I=b.useCallback((R,O)=>{O.stopPropagation(),pu(R),S(Di()),u(M=>M.filter(q=>!(q.type==="history"&&q.text===R)))},[]),D=b.useCallback(R=>{R.stopPropagation(),bu(),S([]),u([])},[]);b.useEffect(()=>{if(f>=0&&x.current){const R=x.current.children;R[f]&&R[f].scrollIntoView({block:"nearest"})}},[f]);const E=!i.trim()&&y.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:k,type:"text",placeholder:d,value:i,onChange:R=>{n(R.target.value),p(!0)},onCompositionStart:()=>{v.current=!0},onCompositionEnd:()=>{v.current=!1},onFocus:()=>{p(!0)},onKeyDown:N,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:[E&&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:D,style:{border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),h.map((R,O)=>t.jsxs("div",{onClick:()=>_(R),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r.bim("fg"),background:O===f?r.bim("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:R.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.text}),R.entry&&t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),flexShrink:0},children:[c[R.entry.type],R.entry.edition&&` · ${R.entry.edition}`,R.entry.author&&` · ${R.entry.author}`]}),R.type==="history"&&t.jsx("button",{onClick:M=>I(R.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:"×"})]},`${R.type}-${R.text}-${O}`))]})]})},Xi=({type:e,size:i=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:i,height:i,borderRadius:1,flex:"none",background: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 hu(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 En(e){return!!e.lineage||Gt(e).length>0||mi(e).length>0}function fu(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 gu(e,i){var s,o,a,l,d;if(!En(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 Uo(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 xu(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 yu(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 wn(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=yu(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(E=>[E.id,E])),$=new Map((s.hypothetical_nodes??[]).map(E=>[E.id,E])),_=E=>{const R=v.get(E);if(R&&En(R))return Gt(R).map(M=>M.ref);const O=$.get(E);return O?(O.derived_from??[]).map(M=>M.ref):[]},N=E=>$.has(E)?!p||p.has(E):!m||m.has(E),I=new Set,D=E=>{if(!I.has(E)){I.add(E);for(const R of _(E))a.has(R)||(N(R)||($.has(R)?u.add(R):v.has(R)&&h.add(R)),D(R))}};for(const E of i)m&&m.has(E.id)&&!a.has(E.id)&&D(E.id);for(const E of s.hypothetical_nodes??[])p&&p.has(E.id)&&D(E.id)}const f=i.filter(v=>!a.has(v.id)).filter(v=>!m||m.has(v.id)||h.has(v.id)).map(v=>{const $=gu(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 $=fu(v);return u.has(v.id)&&($.bridge=!0),$}),y=[...f,...g],S=new Set(y.map(v=>v.id)),k=new Set,x=[],j=v=>{k.has(v.id)||!S.has(v.source)||!S.has(v.target)||(k.add(v.id),x.push(v))};for(const v of i)a.has(v.id)||!En(v)||m&&!m.has(v.id)&&!h.has(v.id)||(Gt(v).forEach(($,_)=>{j(Uo(v.id,$,_))}),mi(v).forEach(($,_)=>{j(xu(v.id,$,_))}));for(const v of s.hypothetical_nodes??[])p&&!p.has(v.id)&&!u.has(v.id)||(v.derived_from??[]).forEach(($,_)=>{j(Uo(v.id,$,_))});return{nodes:y,edges:x,groups:s.groups??[],title:s.title,description:s.description,layout:s.layout??"LR",excluded:Array.from(a)}}function $l(e,i,n){const s=(e??(i!=null?String(i):"")).trim();return s?!n||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(s)?s:`约 ${s}`:""}function ju(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(!En(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 _l=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],ku={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Tt(e){return ku[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},Nl={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Bn(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 wu(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 vu=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Ko={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function hs(e){const i=e.trim().replace(/[代朝]$/,"");for(const o of Object.keys(Ko))if(i.startsWith(o))return Ko[o];const n=Tt(i);if(yi[n]!=null)return n;const s=Qt(i);if(s&&i.length<=s.length+1)return Tt(s)}function li(e,i){if(i){const n=Nl[`${i}|${e}`];if(n!=null)return n}return $i[e]}const Su=1911;function $u(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 _u={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Rn(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=_u[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 _l)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&&Nl[`${n}|${s}`]==null))return s}function Hn(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 Ji(e){var a,l;e=Hn(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=Bn(s);if(d)return{era:wu(d.from),reign:"",source:"publication"};const c=Qt(s)??hs(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:Tt(p),reign:m,source:"publication"}}const o=e.edition||e.title||"";if(o){const d=Qt(o);if(d)return{era:Tt(d),reign:ki(o,d)??"",source:"edition"};const c=Si.find(m=>m.pattern.test(o));if(c)return{era:Tt(c.era),reign:ki(o,c.era)??c.reign??"",source:"edition"}}return i}function Dn(e){var s,o,a,l,d,c;if(e=Hn(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=Bn(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)||hs(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 S=parseInt(h[1],10);if(S>=100&&S<=2100)return S}const u=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(u){const S=Qt(m);if(!S||Tt(S)==="民國"){const x=Rn(u[1]);if(x!=null&&x>=1&&x<=120)return Su+x}}const f=Qt(m)??((d=Si.find(S=>S.pattern.test(m)))==null?void 0:d.era),g=f?Tt(f):void 0,y=ki(m,g)??(Qt(m)||(c=Si.find(S=>S.pattern.test(m)))==null?void 0:c.reign);if(y){const S=li(y,g);if(S==null)continue;const k=m.indexOf(y),x=k>=0?m.slice(k+y.length):"",j=x.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??x.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),v=j?Rn(j[1]):void 0;return S+(v?v-1:0)}}}function fs(e){var o,a,l,d;e=Hn(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=Bn(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=zl[Tt(m[1])],h=yi[Tt(m[2])];if(p!=null&&h!=null)return{from:Math.min(p,h)-20,to:Math.max(p,h)+40}}}const 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)??hs(c)??((d=Si.find(u=>u.pattern.test(c)))==null?void 0:d.era),p=m?Tt(m):void 0,h=[];for(const u of Object.keys($i))c.includes(u)&&(p&&Ht[u]&&Ht[u]!==p||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(S=>li(S,p)).filter(S=>S!=null),f=Math.min(...u),g=h.reduce((S,k)=>li(S,p)>=li(k,p)?S:k),y=$u(g)??Sr(p??"")??Math.max(...u);return{from:f,to:y>f?y:Sr(p??Ht[g]??"")??f}}if(p&&yi[p]!=null)return{from:yi[p],to:Sr(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},Nu=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],zu=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Yo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Vo(e,i){for(const n of _l){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),Tt(n)))continue}const o=Tt(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?Rn(p[1]):void 0;d=c+(h?h-1:0)}}return{era:o,reign:l,year:d}}for(const n of Si)if(n.pattern.test(e))return{era:Tt(n.era),reign:n.reign??""}}function Cu(e){var y,S;e=Hn(e);const i=Ji(e),n=((y=e.publication_info)==null?void 0:y.year)??"",s=n?Bn(n):void 0;if(!i.era&&!i.reign&&!s)return;const o=e.edition||e.title||"",a=/[間间]/.test(o),l=i.source==="publication"&&vu.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=Dn(e);const p=m==null?fs(e):void 0;let h;i.source==="publication"&&(l||Yo.test(n))?h="uncertain":i.source==="publication"?h="attested":Yo.test(o)||!i.reign&&m==null?h="uncertain":h="inferred";const u=i.source==="edition"?`題名「${o}」`:`出版著錄「${((S=e.publication_info)==null?void 0:S.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 k=n.match(/[、,,]\s*([宋元明清])/);k&&k[1]!==f.era&&(f.laterRepair={era:k[1]})}if(!f.laterRepair&&zu.test(o)){const k=o.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);k&&k[1]!==i.era&&(f.laterRepair={era:k[1]})}const g=Nu.find(k=>k.re.test(o));if(g){const k=o.search(g.re),x=o.slice(k),j=Vo(x,i.era)??Vo(o,i.era);j&&(f.basedOn={era:j.era,reign:j.reign,year:j.year,relation:g.relation})}return f}const zl={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Sr(e){return zl[e]}function Tn(e){const i=Dn(e);if(i!=null)return i;const n=fs(e);if(n)return n.from;const s=Ji(e).era;return s?yi[s]:void 0}const Go=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Ur(e){const i=Go.indexOf(e);return i===-1?Go.length:i}function Eu(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 gs(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 Wn(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 Cl(e,i){if(Wn(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 Ru="同版";function Tu(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 Iu(e){for(const i of mi(e)){const n=i.ref??i.book_id;if(i.relation===Ru&&n&&n!==e.id)return n}}function Mu(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 El(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:Ji(e),year:Dn(e),sortYear:Tn(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:Tu(o[0]),copyOf:Iu(e),summary:e.summary,important:Au(e.id,i),group:(c=i==null?void 0:i.node_groups)==null?void 0:c[e.id],hasImage:s.length>0}}function Au(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 Rl(e,i,n={}){const s=new Set((i==null?void 0:i.excluded_books)??[]),o=Mu(e.filter(c=>!s.has(c.id)).map(c=>El(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)=>Ur(c)-Ur(m));return{rows:a,allRows:o,eras:d,hasInferredEra:o.some(c=>c.era.source==="edition")}}function Lu(e,i){var S,k;if(!i||!i.default_collection||!i.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const n=(S=i.collections)==null?void 0:S[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 j=i.node_groups[x];return j!=null&&d.has(j)},p=[],h=new Map,u=[];for(const x of e)if(!((k=i.excluded_books)!=null&&k.includes(x)))if(m(x))p.push(x);else{const j=i.node_groups[x];j?(h.has(j)||h.set(j,[]),h.get(j).push(x)):u.push(x)}if(u.length+[...h.values()].reduce((x,j)=>x+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const g=new Map((i.groups??[]).map(x=>[x.id,x])),y=[...h.entries()].map(([x,j])=>{const v=g.get(x);return{id:x,label:(v==null?void 0:v.label)??x,description:v==null?void 0:v.description,ids:j}});return u.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:p,groupedIds:y}}const Tl=["撰","編","注","校","譯","繪","其他"],Pu=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function xs(e){if(!e||!e.trim())return"撰";const i=e.replace(/[\s-]/g,"");if(!i)return"撰";for(const{cls:n,re:s}of Pu)if(s.test(i))return n;return"其他"}function ys(e){if(!e)return"";const i=e.trim();return!i||!/[一-鿿]/.test(i)?"":i}function Il(e,i="全部"){const n=new Map;for(const o of e){const a=xs(o);n.set(a,(n.get(a)??0)+1)}const s=[{cls:"全部",label:i,count:e.length}];for(const o of Tl){const a=n.get(o);a&&s.push({cls:o,label:o,count:a})}return s.length>2?s:[]}function js(e){return(e._books??[]).map(i=>i.id).filter(i=>typeof i=="string")}function ks(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 Ml(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:Wi(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 Ou(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 Al(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}=Ml(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 Wi(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(i=>typeof i=="number");if(typeof e=="string"){const i=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(i){const[n,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 Un(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 Fu=["〇","一","二","三","四","五","六","七","八","九"],qo=["","十","百","千"];function Vi(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return $r(e,!0);const i=Math.floor(e/1e4),n=e%1e4;let s=$r(i,!0)+"萬";return n>0&&(s+=(n<1e3?"〇":"")+$r(n,!1)),s}function $r(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+=qo[c]:o+=Fu[d]+qo[c])}return o}function Bu(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function Hu(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 Vi(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=>Vi(l.number)+(l.unit==="卷"?i:l.unit)).join(""):""}function Ll(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 Kn={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Pl=new Set(["work","book","entity"]);function Du(e){return Bl(e)||!!e.sort}function Wu(e,i){return i.sort&&Pl.has(e)?i.sort:void 0}const Yn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Vn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Ol=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Fl={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Gn(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 Bl(e){return Gn(e)>0}function Uu(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 Hl(e,i){const n=Fl[e];return Uu(i).every(s=>n.has(s))}const Ai=e=>JSON.stringify(e);function Ku(e,i){if(!Hl(i,e))return null;const n=[];if(e.dynasty.length){const s=Array.from(new Set(e.dynasty.flatMap(o=>{var a;return((a=Yn.find(l=>l.key===o))==null?void 0:a.values)??[]})));s.length===1?n.push(`dynasty = ${Ai(s[0])}`):s.length>1&&n.push(`dynasty IN [${s.map(Ai).join(", ")}]`)}return e.classification.length&&n.push(e.classification.length===1?`classification = ${Ai(e.classification[0])}`:`classification IN [${e.classification.map(Ai).join(", ")}]`),e.hasImage&&n.push("has_image = true"),e.hasText&&n.push("has_text = true"),e.hasCollated&&n.push("has_collated = true"),e.loss&&n.push(`loss_status = ${Ai(e.loss)}`),n.join(" AND ")}const Nt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},Dl="_";function In(e,i=new URLSearchParams){for(const n of Object.values(Nt))i.delete(n);return e.dynasty.length&&i.set(Nt.dynasty,e.dynasty.join(",")),e.classification.length&&i.set(Nt.classification,e.classification.map(n=>n||Dl).join(",")),e.hasImage&&i.set(Nt.hasImage,"1"),e.hasText&&i.set(Nt.hasText,"1"),e.hasCollated&&i.set(Nt.hasCollated,"1"),e.loss&&i.set(Nt.loss,e.loss),e.sort&&i.set(Nt.sort,e.sort),i}function Yu(e){const i=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),n=new Set(Yn.map(a=>a.key)),s=new Set(Vn.map(a=>a.value)),o=e.get(Nt.loss);return{dynasty:Array.from(new Set(i(Nt.dynasty).filter(a=>n.has(a)))),classification:Array.from(new Set(i(Nt.classification).map(a=>a===Dl?"":a).filter(a=>s.has(a)))),hasImage:e.get(Nt.hasImage)==="1",hasText:e.get(Nt.hasText)==="1"||e.get(Nt.hasCollated)==="1",hasCollated:!1,loss:o==="extant"||o==="partially_extant"||o==="lost"?o:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(a=>a===e.get(Nt.sort))??""}}function Vu(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 Xo(e,i){return e.includes(i)?e.filter(n=>n!==i):[...e,i]}const Gu=({filters:e,onChange:i})=>{const n=r.useT(),s=n.searchV4,{convert:o}=gt(),[a,l]=b.useState(!1),d=b.useId(),c=Gn(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:Yn.map(p=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(p.key),onClick:()=>m({dynasty:Xo(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)}),Vn.map(p=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(p.value),onChange:()=>m({classification:Xo(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:Ol.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({...Kn,sort:e.sort}),children:o(s.clearAllFilters)})]})]})};function Wl({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 Jo=({entries:e,query:i,onEntryLinkClick:n,typeName:s})=>{const o=r.useT(),a=o.searchV4,{convert:l}=gt(),d=It();return t.jsx("div",{className:"bim-sr-tablewrap",children:t.jsxs("table",{className:"bim-sr-table",children:[t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"34%"}}),t.jsx("col",{style:{width:"8%"}}),t.jsx("col",{style:{width:"19%"}}),t.jsx("col",{style:{width:"13%"}}),t.jsx("col",{style:{width:"12%"}}),t.jsx("col",{style:{width:"14%"}})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:l(a.colTitle)}),t.jsx("th",{scope:"col",children:l(a.colType)}),t.jsx("th",{scope:"col",children:l(a.colAuthor)}),t.jsx("th",{scope:"col",children:l(a.colEra)}),t.jsx("th",{scope:"col",children:l(a.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:l(a.colResource)})]})}),t.jsx("tbody",{children:e.map(c=>{const m=l(c.title||c.primary_name||c.id),p=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${o.unit.juan}`:"",h=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${l(c.author)}${c.role&&c.role!=="author"?` ${l(c.role)}`:""}`:"",u=c.type==="book"?c.era??c.dynasty:c.dynasty,f=u?l(u):"",g=c.classification?l(c.classification):"",y=[];c.has_image&&y.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&y.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&y.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const S=[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:k=>n(c,k),children:t.jsx(Wl,{text:m,query:i?l(i):void 0})}),p&&t.jsx("span",{className:"bim-sr-measure",children:p})]}),S&&t.jsx("span",{className:"bim-sr-sub",children:S})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Xi,{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(k=>t.jsx("span",{className:`bim-sr-tag ${k.cls}`,children:l(k.label)},k.label))})]},c.id)})})]})})},qu=`
|
|
1
|
+
"use strict";var Km=Object.create;var Bo=Object.defineProperty;var Ym=Object.getOwnPropertyDescriptor;var Vm=Object.getOwnPropertyNames;var Gm=Object.getPrototypeOf,qm=Object.prototype.hasOwnProperty;var Xm=(e,i,n,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of Vm(i))!qm.call(e,o)&&o!==n&&Bo(e,o,{get:()=>i[o],enumerable:!(s=Ym(i,o))||s.enumerable});return e};var hn=(e,i,n)=>(n=e!=null?Km(Gm(e)):{},Xm(i||!e||!e.__esModule?Bo(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./storage-entry-D6X5zpk8.cjs"),t=require("react/jsx-runtime"),b=require("react"),r=require("./Badge-Czc0_9hI.cjs"),Jm=require("opencc-js/t2cn"),vi=require("./variant-chars-kDZNY5eM.cjs"),Zm=require("react-markdown"),Qm=require("remark-gfm"),eu=require("./variant-supplement.cjs"),tu=e=>`/item/${e}`,gl=b.createContext(tu);function iu({buildUrl:e,children:i}){const n=b.useMemo(()=>e,[e]);return t.jsx(gl.Provider,{value:n,children:i})}function It(){return b.useContext(gl)}const xl="",yl="";function bs(e){const i=[];let n=!1,s=e;for(;s.length;){const o=n?yl:xl,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 Mi=null;function jl(){if(Mi)return Mi;try{const e=Jm.Converter({from:"t",to:"cn"});Mi=r.withProtectedTerms(i=>e(vi.normalizeVariants(i)))}catch{Mi=e=>e}return Mi}const kl="bim-locale";function nu(){try{const e=localStorage.getItem(kl);if(e==="zh-Hant"||e==="zh-Hans")return e}catch{}}function ru(e){try{localStorage.setItem(kl,e)}catch{}}const su="zh-Hans",ou=({locale:e,onLocaleChange:i,converter:n,children:s})=>{const[o,a]=b.useState(e??su),l=e??o;b.useEffect(()=>{if(e)return;const p=nu();p&&p!==o&&a(p)},[]);const d=b.useMemo(()=>l==="zh-Hans"?n??jl():null,[l,n]),c=b.useCallback(p=>{a(p),ru(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})},au=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>=au){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 oe(){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 lu(e,i,n){return e?e==="orig"?null:i==="zh-Hans"?n??jl():e==="hant"?vi.normalizeVariants:n:i==="zh-Hans"?n:vi.normalizeVariants}const cu=({mode:e,children:i})=>{const n=b.useContext(r.LocaleContext),s=b.useMemo(()=>n&&{...n,converter:lu(e,n.locale,n.converter)},[n,e]);return t.jsx(r.LocaleContext.Provider,{value:s,children:i})},Ho={text:r.bim("restype-text"),image:r.bim("restype-image"),"text+image":r.bim("restype-text-image"),physical:r.bim("restype-physical")};function du(e){return e.includes("text")&&e.includes("image")?Ho["text+image"]:Ho[e[0]||"physical"]}const mu=({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 k=new Map,x=[],j=new Map;d.forEach((S,$)=>{const _=S.group||(S.label?`_label:${$}`:void 0);!S.group&&S.label&&_&&j.set(_,S.label),_?(k.has(_)||k.set(_,[]),k.get(_).push(S)):x.push(S)});for(const S of k.values())S.sort(($,_)=>{const N=I=>I.group_role==="origin"?0:I.group_role==="mirror"?1:2;return N($)-N(_)});return{mirrorGroups:k,ungroupedItems:x,labelOnlyKeys:j}},[d]),h={text:a.resourceType.text,image:a.resourceType.image,"text+image":a.resourceType.textImage,physical:a.resourceType.physical},u=k=>h[k]?h[k]:k.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((k,x)=>t.jsx(vr,{item:k},k.id||x))});const f=(k,x)=>{const j=n==null?void 0:n[k],S=p.get(k)||(j==null?void 0:j.label)||k,$=j==null?void 0:j.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)=>t.jsx(vr,{item:_,onNavigate:s,renderLink:o},_.id||N))})]},`group-${k}`)},g=new Map;for(const k of m){const x=r.getTypeGroupKey(r.getResourceTypes(k));g.has(x)||g.set(x,[]),g.get(x).push(k)}const y=["text","image","text+image","physical"],v=[...y.filter(k=>g.has(k)),...[...g.keys()].filter(k=>!y.includes(k)).sort()];return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...c.entries()].map(([k,x])=>f(k,x)),v.map(k=>{const x=g.get(k),j=du(k.split("+"));return t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:j,whiteSpace:"nowrap",flexShrink:0},children:u(k)}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:x.map((S,$)=>t.jsx(vr,{item:S,onNavigate:s,renderLink:o},S.id||$))})]},k)})]})},uu={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")}},vr=({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?{...uu[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)})})]})},wl=({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})]})]})},Fn="bim-search-history",Do=10,Wo=8;function Di(){try{const e=localStorage.getItem(Fn);return e?JSON.parse(e):[]}catch{return[]}}function vl(e){try{const i=Di().filter(n=>n!==e);i.unshift(e),i.length>Do&&(i.length=Do),localStorage.setItem(Fn,JSON.stringify(i))}catch{}}function pu(e){try{const i=Di().filter(n=>n!==e);localStorage.setItem(Fn,JSON.stringify(i))}catch{}}function bu(){try{localStorage.removeItem(Fn)}catch{}}const Sl=({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,v]=b.useState(Di),k=b.useRef(null),x=b.useRef(null),j=b.useRef(null),S=b.useRef(!1);b.useEffect(()=>{g(-1);const R=i.trim();if(!R){u(y.map(q=>({type:"history",text:q})));return}if(!e.searchAll){u([]);return}let O=!1;const M=setTimeout(()=>{e.searchAll(R,Wo).then(q=>{if(O)return;const P=[...q.works,...q.books,...q.collections,...q.entities??[]];u(P.slice(0,Wo).map(le=>({type:"entry",text:le.title||le.id,entry:le})))}).catch(()=>{O||u([])})},80);return()=>{O=!0,clearTimeout(M)}},[i,y,e]),b.useEffect(()=>{const R=O=>{j.current&&!j.current.contains(O.target)&&p(!1)};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[]),b.useEffect(()=>{const R=O=>{var M,q;if(O.key==="/"&&document.activeElement!==k.current){const P=(M=document.activeElement)==null?void 0:M.tagName;if(P==="INPUT"||P==="TEXTAREA"||P==="SELECT")return;O.preventDefault(),(q=k.current)==null||q.focus()}};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[]);const $=b.useCallback(R=>{R.trim()&&(vl(R.trim()),v(Di())),s(R),p(!1)},[s]),_=b.useCallback(R=>{R.type==="history"?(n(R.text),$(R.text)):R.entry&&(o?(o(R.entry),p(!1)):(n(R.text),$(R.text)))},[n,$,o]),N=b.useCallback(R=>{if(!m||h.length===0){R.key==="Enter"&&$(i);return}switch(R.key){case"ArrowDown":R.preventDefault(),g(O=>(O+1)%h.length);break;case"ArrowUp":R.preventDefault(),g(O=>(O-1+h.length)%h.length);break;case"Enter":R.preventDefault(),f>=0&&f<h.length?_(h[f]):$(i);break;case"Escape":R.preventDefault(),p(!1);break}},[m,h,f,i,$,_]),I=b.useCallback((R,O)=>{O.stopPropagation(),pu(R),v(Di()),u(M=>M.filter(q=>!(q.type==="history"&&q.text===R)))},[]),D=b.useCallback(R=>{R.stopPropagation(),bu(),v([]),u([])},[]);b.useEffect(()=>{if(f>=0&&x.current){const R=x.current.children;R[f]&&R[f].scrollIntoView({block:"nearest"})}},[f]);const E=!i.trim()&&y.length>0;return t.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[t.jsx("input",{ref:k,type:"text",placeholder:d,value:i,onChange:R=>{n(R.target.value),p(!0)},onCompositionStart:()=>{S.current=!0},onCompositionEnd:()=>{S.current=!1},onFocus:()=>{p(!0)},onKeyDown:N,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:[E&&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:D,style:{border:"none",background:"transparent",color:r.bim("desc-fg"),cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),h.map((R,O)=>t.jsxs("div",{onClick:()=>_(R),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:r.bim("fg"),background:O===f?r.bim("list-active-bg"):"transparent"},children:[t.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:R.type==="history"?"🕐":"🔍"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:R.text}),R.entry&&t.jsxs("span",{style:{fontSize:"11px",color:r.bim("desc-fg"),flexShrink:0},children:[c[R.entry.type],R.entry.edition&&` · ${R.entry.edition}`,R.entry.author&&` · ${R.entry.author}`]}),R.type==="history"&&t.jsx("button",{onClick:M=>I(R.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:"×"})]},`${R.type}-${R.text}-${O}`))]})]})},Xi=({type:e,size:i=9})=>t.jsx("span",{"aria-hidden":"true",style:{display:"inline-block",width:i,height:i,borderRadius:1,flex:"none",background: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 hu(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 En(e){return!!e.lineage||Gt(e).length>0||mi(e).length>0}function fu(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 gu(e,i){var s,o,a,l,d;if(!En(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 Uo(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 xu(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 yu(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 wn(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=yu(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(E=>[E.id,E])),$=new Map((s.hypothetical_nodes??[]).map(E=>[E.id,E])),_=E=>{const R=S.get(E);if(R&&En(R))return Gt(R).map(M=>M.ref);const O=$.get(E);return O?(O.derived_from??[]).map(M=>M.ref):[]},N=E=>$.has(E)?!p||p.has(E):!m||m.has(E),I=new Set,D=E=>{if(!I.has(E)){I.add(E);for(const R of _(E))a.has(R)||(N(R)||($.has(R)?u.add(R):S.has(R)&&h.add(R)),D(R))}};for(const E of i)m&&m.has(E.id)&&!a.has(E.id)&&D(E.id);for(const E of s.hypothetical_nodes??[])p&&p.has(E.id)&&D(E.id)}const f=i.filter(S=>!a.has(S.id)).filter(S=>!m||m.has(S.id)||h.has(S.id)).map(S=>{const $=gu(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 $=fu(S);return u.has(S.id)&&($.bridge=!0),$}),y=[...f,...g],v=new Set(y.map(S=>S.id)),k=new Set,x=[],j=S=>{k.has(S.id)||!v.has(S.source)||!v.has(S.target)||(k.add(S.id),x.push(S))};for(const S of i)a.has(S.id)||!En(S)||m&&!m.has(S.id)&&!h.has(S.id)||(Gt(S).forEach(($,_)=>{j(Uo(S.id,$,_))}),mi(S).forEach(($,_)=>{j(xu(S.id,$,_))}));for(const S of s.hypothetical_nodes??[])p&&!p.has(S.id)&&!u.has(S.id)||(S.derived_from??[]).forEach(($,_)=>{j(Uo(S.id,$,_))});return{nodes:y,edges:x,groups:s.groups??[],title:s.title,description:s.description,layout:s.layout??"LR",excluded:Array.from(a)}}function $l(e,i,n){const s=(e??(i!=null?String(i):"")).trim();return s?!n||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(s)?s:`约 ${s}`:""}function ju(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(!En(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 _l=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],ku={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function Tt(e){return ku[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},Nl={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Bn(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 wu(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 vu=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,Ko={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function hs(e){const i=e.trim().replace(/[代朝]$/,"");for(const o of Object.keys(Ko))if(i.startsWith(o))return Ko[o];const n=Tt(i);if(yi[n]!=null)return n;const s=Qt(i);if(s&&i.length<=s.length+1)return Tt(s)}function li(e,i){if(i){const n=Nl[`${i}|${e}`];if(n!=null)return n}return $i[e]}const Su=1911;function $u(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 _u={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Rn(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=_u[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 _l)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&&Nl[`${n}|${s}`]==null))return s}function Hn(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 Ji(e){var a,l;e=Hn(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=Bn(s);if(d)return{era:wu(d.from),reign:"",source:"publication"};const c=Qt(s)??hs(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:Tt(p),reign:m,source:"publication"}}const o=e.edition||e.title||"";if(o){const d=Qt(o);if(d)return{era:Tt(d),reign:ki(o,d)??"",source:"edition"};const c=Si.find(m=>m.pattern.test(o));if(c)return{era:Tt(c.era),reign:ki(o,c.era)??c.reign??"",source:"edition"}}return i}function Dn(e){var s,o,a,l,d,c;if(e=Hn(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=Bn(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)||hs(p)))break;const h=m.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??m.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(h){const v=parseInt(h[1],10);if(v>=100&&v<=2100)return v}const u=m.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(u){const v=Qt(m);if(!v||Tt(v)==="民國"){const x=Rn(u[1]);if(x!=null&&x>=1&&x<=120)return Su+x}}const f=Qt(m)??((d=Si.find(v=>v.pattern.test(m)))==null?void 0:d.era),g=f?Tt(f):void 0,y=ki(m,g)??(Qt(m)||(c=Si.find(v=>v.pattern.test(m)))==null?void 0:c.reign);if(y){const v=li(y,g);if(v==null)continue;const k=m.indexOf(y),x=k>=0?m.slice(k+y.length):"",j=x.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??x.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=j?Rn(j[1]):void 0;return v+(S?S-1:0)}}}function fs(e){var o,a,l,d;e=Hn(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=Bn(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=zl[Tt(m[1])],h=yi[Tt(m[2])];if(p!=null&&h!=null)return{from:Math.min(p,h)-20,to:Math.max(p,h)+40}}}const 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)??hs(c)??((d=Si.find(u=>u.pattern.test(c)))==null?void 0:d.era),p=m?Tt(m):void 0,h=[];for(const u of Object.keys($i))c.includes(u)&&(p&&Ht[u]&&Ht[u]!==p||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(v=>li(v,p)).filter(v=>v!=null),f=Math.min(...u),g=h.reduce((v,k)=>li(v,p)>=li(k,p)?v:k),y=$u(g)??Sr(p??"")??Math.max(...u);return{from:f,to:y>f?y:Sr(p??Ht[g]??"")??f}}if(p&&yi[p]!=null)return{from:yi[p],to:Sr(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},Nu=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],zu=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,Yo=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function Vo(e,i){for(const n of _l){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),Tt(n)))continue}const o=Tt(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?Rn(p[1]):void 0;d=c+(h?h-1:0)}}return{era:o,reign:l,year:d}}for(const n of Si)if(n.pattern.test(e))return{era:Tt(n.era),reign:n.reign??""}}function Cu(e){var y,v;e=Hn(e);const i=Ji(e),n=((y=e.publication_info)==null?void 0:y.year)??"",s=n?Bn(n):void 0;if(!i.era&&!i.reign&&!s)return;const o=e.edition||e.title||"",a=/[間间]/.test(o),l=i.source==="publication"&&vu.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=Dn(e);const p=m==null?fs(e):void 0;let h;i.source==="publication"&&(l||Yo.test(n))?h="uncertain":i.source==="publication"?h="attested":Yo.test(o)||!i.reign&&m==null?h="uncertain":h="inferred";const u=i.source==="edition"?`題名「${o}」`:`出版著錄「${((v=e.publication_info)==null?void 0:v.year)??""}」`,f={era:i.era,reign:i.reign,year:m,yearRange:p,certainty:h,source:i.source==="edition"?"edition":"catalog",basis:u};if(c){const k=n.match(/[、,,]\s*([宋元明清])/);k&&k[1]!==f.era&&(f.laterRepair={era:k[1]})}if(!f.laterRepair&&zu.test(o)){const k=o.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);k&&k[1]!==i.era&&(f.laterRepair={era:k[1]})}const g=Nu.find(k=>k.re.test(o));if(g){const k=o.search(g.re),x=o.slice(k),j=Vo(x,i.era)??Vo(o,i.era);j&&(f.basedOn={era:j.era,reign:j.reign,year:j.year,relation:g.relation})}return f}const zl={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function Sr(e){return zl[e]}function Tn(e){const i=Dn(e);if(i!=null)return i;const n=fs(e);if(n)return n.from;const s=Ji(e).era;return s?yi[s]:void 0}const Go=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function Ur(e){const i=Go.indexOf(e);return i===-1?Go.length:i}function Eu(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 gs(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 Wn(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 Cl(e,i){if(Wn(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 Ru="同版";function Tu(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 Iu(e){for(const i of mi(e)){const n=i.ref??i.book_id;if(i.relation===Ru&&n&&n!==e.id)return n}}function Mu(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 El(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:Ji(e),year:Dn(e),sortYear:Tn(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:Tu(o[0]),copyOf:Iu(e),summary:e.summary,important:Au(e.id,i),group:(c=i==null?void 0:i.node_groups)==null?void 0:c[e.id],hasImage:s.length>0}}function Au(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 Rl(e,i,n={}){const s=new Set((i==null?void 0:i.excluded_books)??[]),o=Mu(e.filter(c=>!s.has(c.id)).map(c=>El(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)=>Ur(c)-Ur(m));return{rows:a,allRows:o,eras:d,hasInferredEra:o.some(c=>c.era.source==="edition")}}function Lu(e,i){var v,k;if(!i||!i.default_collection||!i.node_groups)return{useGrouping:!1,coreIds:e,groupedIds:[]};const n=(v=i.collections)==null?void 0:v[i.default_collection],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 j=i.node_groups[x];return j!=null&&d.has(j)},p=[],h=new Map,u=[];for(const x of e)if(!((k=i.excluded_books)!=null&&k.includes(x)))if(m(x))p.push(x);else{const j=i.node_groups[x];j?(h.has(j)||h.set(j,[]),h.get(j).push(x)):u.push(x)}if(u.length+[...h.values()].reduce((x,j)=>x+j.length,0)<3)return{useGrouping:!1,coreIds:e,groupedIds:[]};const g=new Map((i.groups??[]).map(x=>[x.id,x])),y=[...h.entries()].map(([x,j])=>{const S=g.get(x);return{id:x,label:(S==null?void 0:S.label)??x,description:S==null?void 0:S.description,ids:j}});return u.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:u}),{useGrouping:!0,coreIds:p,groupedIds:y}}const Tl=["撰","編","注","校","譯","繪","其他"],Pu=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function xs(e){if(!e||!e.trim())return"撰";const i=e.replace(/[\s-]/g,"");if(!i)return"撰";for(const{cls:n,re:s}of Pu)if(s.test(i))return n;return"其他"}function ys(e){if(!e)return"";const i=e.trim();return!i||!/[一-鿿]/.test(i)?"":i}function Il(e,i="全部"){const n=new Map;for(const o of e){const a=xs(o);n.set(a,(n.get(a)??0)+1)}const s=[{cls:"全部",label:i,count:e.length}];for(const o of Tl){const a=n.get(o);a&&s.push({cls:o,label:o,count:a})}return s.length>2?s:[]}function js(e){return(e._books??[]).map(i=>i.id).filter(i=>typeof i=="string")}function ks(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 Ml(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:Wi(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 Ou(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 Al(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}=Ml(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 Wi(e){if(e==null)return[];if(typeof e=="number")return[e];if(Array.isArray(e))return e.filter(i=>typeof i=="number");if(typeof e=="string"){const i=e.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(i){const[n,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 Un(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 Fu=["〇","一","二","三","四","五","六","七","八","九"],qo=["","十","百","千"];function Vi(e){if(!Number.isInteger(e)||e<=0)return"";if(e>=1e8)return String(e);if(e<1e4)return $r(e,!0);const i=Math.floor(e/1e4),n=e%1e4;let s=$r(i,!0)+"萬";return n>0&&(s+=(n<1e3?"〇":"")+$r(n,!1)),s}function $r(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+=qo[c]:o+=Fu[d]+qo[c])}return o}function Bu(e){return e==null?"":typeof e=="string"?e:"name"in e&&e.name?e.name:"title"in e&&e.title||""}function Hu(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 Vi(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=>Vi(l.number)+(l.unit==="卷"?i:l.unit)).join(""):""}function Ll(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 Kn={dynasty:[],classification:[],hasImage:!1,hasText:!1,hasCollated:!1,loss:"",sort:""},Pl=new Set(["work","book","entity"]);function Du(e){return Bl(e)||!!e.sort}function Wu(e,i){return i.sort&&Pl.has(e)?i.sort:void 0}const Yn=[{key:"漢",values:["漢","西漢","東漢"]},{key:"魏晉南北朝",values:["三國魏","三國蜀","三國吳","三國","晉","西晉","東晉","南朝宋","南朝齊","南朝梁","南朝陳","北魏","東魏","西魏","北齊","北周"]},{key:"唐",values:["隋","唐","五代","前蜀","後蜀","南唐"]},{key:"宋",values:["宋","北宋","南宋","宋末元初","遼","金"]},{key:"元",values:["元","元末明初"]},{key:"明",values:["明","明末清初"]},{key:"清",values:["清"]}],Vn=[{value:"經部",label:"經部"},{value:"史部",label:"史部"},{value:"子部",label:"子部"},{value:"集部",label:"集部"},{value:"",label:"未分類"}],Ol=[{value:"",label:"全部"},{value:"extant",label:"存"},{value:"partially_extant",label:"殘"},{value:"lost",label:"佚"}],Fl={work:new Set(["dynasty","classification","hasImage","hasText","hasCollated","loss"]),book:new Set(["dynasty","hasImage","hasText"]),collection:new Set,entity:new Set(["dynasty"])};function Gn(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 Bl(e){return Gn(e)>0}function Uu(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 Hl(e,i){const n=Fl[e];return Uu(i).every(s=>n.has(s))}const Ai=e=>JSON.stringify(e);function Ku(e,i){if(!Hl(i,e))return null;const n=[];if(e.dynasty.length){const s=Array.from(new Set(e.dynasty.flatMap(o=>{var a;return((a=Yn.find(l=>l.key===o))==null?void 0:a.values)??[]})));s.length===1?n.push(`dynasty = ${Ai(s[0])}`):s.length>1&&n.push(`dynasty IN [${s.map(Ai).join(", ")}]`)}return e.classification.length&&n.push(e.classification.length===1?`classification = ${Ai(e.classification[0])}`:`classification IN [${e.classification.map(Ai).join(", ")}]`),e.hasImage&&n.push("has_image = true"),e.hasText&&n.push("has_text = true"),e.hasCollated&&n.push("has_collated = true"),e.loss&&n.push(`loss_status = ${Ai(e.loss)}`),n.join(" AND ")}const Nt={dynasty:"dy",classification:"cls",hasImage:"img",hasText:"txt",hasCollated:"col",loss:"loss",sort:"sort"},Dl="_";function In(e,i=new URLSearchParams){for(const n of Object.values(Nt))i.delete(n);return e.dynasty.length&&i.set(Nt.dynasty,e.dynasty.join(",")),e.classification.length&&i.set(Nt.classification,e.classification.map(n=>n||Dl).join(",")),e.hasImage&&i.set(Nt.hasImage,"1"),e.hasText&&i.set(Nt.hasText,"1"),e.hasCollated&&i.set(Nt.hasCollated,"1"),e.loss&&i.set(Nt.loss,e.loss),e.sort&&i.set(Nt.sort,e.sort),i}function Yu(e){const i=a=>(e.get(a)??"").split(",").map(l=>l.trim()).filter(Boolean),n=new Set(Yn.map(a=>a.key)),s=new Set(Vn.map(a=>a.value)),o=e.get(Nt.loss);return{dynasty:Array.from(new Set(i(Nt.dynasty).filter(a=>n.has(a)))),classification:Array.from(new Set(i(Nt.classification).map(a=>a===Dl?"":a).filter(a=>s.has(a)))),hasImage:e.get(Nt.hasImage)==="1",hasText:e.get(Nt.hasText)==="1"||e.get(Nt.hasCollated)==="1",hasCollated:!1,loss:o==="extant"||o==="partially_extant"||o==="lost"?o:"",sort:["era:asc","era:desc","title:asc","title:desc"].find(a=>a===e.get(Nt.sort))??""}}function Vu(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 Xo(e,i){return e.includes(i)?e.filter(n=>n!==i):[...e,i]}const Gu=({filters:e,onChange:i})=>{const n=r.useT(),s=n.searchV4,{convert:o}=gt(),[a,l]=b.useState(!1),d=b.useId(),c=Gn(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:Yn.map(p=>t.jsx("button",{type:"button",className:"bim-sr-chip","aria-pressed":e.dynasty.includes(p.key),onClick:()=>m({dynasty:Xo(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)}),Vn.map(p=>t.jsxs("label",{className:"bim-sr-opt",children:[t.jsx("input",{type:"checkbox",checked:e.classification.includes(p.value),onChange:()=>m({classification:Xo(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:Ol.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({...Kn,sort:e.sort}),children:o(s.clearAllFilters)})]})]})};function Wl({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 Jo=({entries:e,query:i,onEntryLinkClick:n,typeName:s})=>{const o=r.useT(),a=o.searchV4,{convert:l}=gt(),d=It();return t.jsx("div",{className:"bim-sr-tablewrap",children:t.jsxs("table",{className:"bim-sr-table",children:[t.jsxs("colgroup",{children:[t.jsx("col",{style:{width:"34%"}}),t.jsx("col",{style:{width:"8%"}}),t.jsx("col",{style:{width:"19%"}}),t.jsx("col",{style:{width:"13%"}}),t.jsx("col",{style:{width:"12%"}}),t.jsx("col",{style:{width:"14%"}})]}),t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{scope:"col",children:l(a.colTitle)}),t.jsx("th",{scope:"col",children:l(a.colType)}),t.jsx("th",{scope:"col",children:l(a.colAuthor)}),t.jsx("th",{scope:"col",children:l(a.colEra)}),t.jsx("th",{scope:"col",children:l(a.colClass)}),t.jsx("th",{scope:"col",style:{textAlign:"right"},children:l(a.colResource)})]})}),t.jsx("tbody",{children:e.map(c=>{const m=l(c.title||c.primary_name||c.id),p=c.measure_info?l(c.measure_info):c.juan_count?`${c.juan_count}${o.unit.juan}`:"",h=c.type==="entity"?[c.birth_year!=null||c.death_year!=null?`${c.birth_year??"?"}—${c.death_year??"?"}`:""].filter(Boolean).join(""):c.author?`${l(c.author)}${c.role&&c.role!=="author"?` ${l(c.role)}`:""}`:"",u=c.type==="book"?c.era??c.dynasty:c.dynasty,f=u?l(u):"",g=c.classification?l(c.classification):"",y=[];c.has_image&&y.push({label:a.tagImage,cls:"bim-sr-tag--img"}),(c.has_text||c.has_collated)&&y.push({label:a.tagText,cls:""}),c.loss_status==="lost"&&y.push({label:a.tagLost,cls:"bim-sr-tag--lost"});const v=[h,f,g].filter(Boolean).join(" · ");return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-sr-c-title",children:[t.jsxs("div",{className:"bim-sr-tl",children:[t.jsx("a",{href:d(c.id),onClick:k=>n(c,k),children:t.jsx(Wl,{text:m,query:i?l(i):void 0})}),p&&t.jsx("span",{className:"bim-sr-measure",children:p})]}),v&&t.jsx("span",{className:"bim-sr-sub",children:v})]}),t.jsxs("td",{className:"bim-sr-c-type",children:[t.jsx(Xi,{type:c.type,size:6})," ",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(k=>t.jsx("span",{className:`bim-sr-tag ${k.cls}`,children:l(k.label)},k.label))})]},c.id)})})]})})},qu=`
|
|
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
|
-
`,Zo=({entries:e,query:i,onEntryLinkClick:n,typeName:s})=>{const o=r.useT(),a=o.searchV4,{convert:l}=gt(),d=It();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:qu}),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(Wl,{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:bs(c.descriptionSnippet).map((y,
|
|
15
|
+
`,Zo=({entries:e,query:i,onEntryLinkClick:n,typeName:s})=>{const o=r.useT(),a=o.searchV4,{convert:l}=gt(),d=It();return t.jsxs("div",{className:"bim-sc-grid",children:[t.jsx("style",{children:qu}),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(Wl,{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:bs(c.descriptionSnippet).map((y,v)=>y.marked?t.jsx("mark",{children:l(y.text)},v):t.jsx(b.Fragment,{children:l(y.text)},v))}),t.jsx("span",{className:"bim-sc-sp"}),t.jsxs("div",{className:"bim-sc-f",children:[t.jsx("span",{className:"bim-sc-fl",children:f}),t.jsx("span",{className:"bim-sc-tags",children:g.map(y=>t.jsx("span",{className:`bim-sr-tag ${y.cls}`,children:l(y.label)},y.label))})]})]},c.id)})]})};function Xu(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 Ju(e,i,n){const s=Math.max(1,Math.ceil(i/n));return Math.min(Math.max(1,e),s)}const Zu=({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)})}),Xu(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)})})]})]})},Ul="(max-width: 719px)",Qu=`${Ul}, (pointer: coarse)`,ep=`
|
|
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; }
|
|
@@ -117,7 +117,7 @@
|
|
|
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
|
-
`,ws="bim-search-view",_r=50,Qo=5,Ui=1e3;function vn(e){return e>=Ui?`${Ui.toLocaleString()}+`:e.toLocaleString()}const tp={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function ip(e){return e&&tp[e.toLowerCase()]||"all"}function np(e){return e==="all"?null:e}const ea=["work","collection","book","entity"],rp={work:"works",collection:"collections",book:"books",entity:"entities"},sp={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function op(){try{return window.localStorage.getItem(ws)==="card"?"card":"table"}catch{return"table"}}function ap(e){try{window.localStorage.setItem(ws,e)}catch{}}const gi=(e,i)=>(e==null?void 0:e[sp[i]])??0,Nr=(e,i)=>(e==null?void 0:e[rp[i]])??[],Kl=({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:Kn,[f,n]),[y,S]=b.useState("table");b.useEffect(()=>{S(op())},[]);const k=B=>{S(B),ap(B)},[x,j]=b.useState(l??"all"),v=b.useRef(x);v.current=x,b.useEffect(()=>{l!==void 0&&l!==v.current&&(j(l),_(1))},[l]);const[$,_]=b.useState(c&&c>0?c:1),N=b.useRef($);N.current=$,b.useEffect(()=>{c!==void 0&&c>0&&c!==N.current&&_(c)},[c]);const I=b.useRef(null),D=b.useCallback(B=>{var Me;_(B),m==null||m(B);const de=I.current;de&&de.getBoundingClientRect().top<0&&((Me=de.scrollIntoView)==null||Me.call(de,{block:"start",behavior:"instant"}))},[m]),[E,R]=b.useState(null),[O,M]=b.useState(null),[q,P]=b.useState(!1),[le,ae]=b.useState(""),Ce=In(g).toString(),xe=Gn(g)>0,fe=In({...g,sort:""}).toString(),se=b.useRef({query:i,filterOnlyKey:fe,sort:g.sort});b.useEffect(()=>{const B=se.current;B.query!==i||B.filterOnlyKey!==fe?(j("all"),_(1)):B.sort!==g.sort&&_(1),se.current={query:i,filterOnlyKey:fe,sort:g.sort}},[i,fe,g.sort]),b.useEffect(()=>{let B=!1;return P(!0),ae(""),(async()=>{try{let de;if(e.searchAll)de=await e.searchAll(i,Qo,g);else{const Me=["work","book","collection","entity"],Se=await Promise.all(Me.map(Je=>e.search(i,Je,{page:1,pageSize:Qo,filters:g})));de={works:Se[0].entries,books:Se[1].entries,collections:Se[2].entries,entities:Se[3].entries,totalWorks:Se[0].total,totalBooks:Se[1].total,totalCollections:Se[2].total,totalEntities:Se[3].total}}B||R(de)}catch(de){B||(ae(de instanceof Error?de.message:String(de)),R(null))}finally{B||P(!1)}})(),()=>{B=!0}},[e,i,Ce]);const Re=x;b.useEffect(()=>{if(x==="all"){M(null);return}let B=!1;return P(!0),(async()=>{try{const de=await e.search(i,x,{page:$,pageSize:_r,filters:g});B||M({key:Re,entries:de.entries,total:de.total})}catch(de){B||(ae(de instanceof Error?de.message:String(de)),M(null))}finally{B||P(!1)}})(),()=>{B=!0}},[e,i,Ce,x,$]);const H=O&&O.key===Re?O:null;b.useEffect(()=>{if(x==="all"||!H||q)return;const B=Math.min(H.total,Ui),de=Ju($,B,_r);H.entries.length===0&&B>0&&de!==$&&(_(de),m==null||m(de))},[x,H,q,$]);const me=b.useMemo(()=>ea.filter(B=>gi(E,B)>0),[E]),W=me.reduce((B,de)=>B+gi(E,de),0),K=me.some(B=>gi(E,B)>=Ui)?`${W.toLocaleString()}+`:W.toLocaleString(),re=!q&&!le&&E!==null&&W===0,Y=b.useCallback(B=>{j(B),_(1),d==null||d(B)},[d]),T=b.useMemo(()=>{const B=[];return g.dynasty.forEach(de=>B.push({name:de,remove:()=>s({...g,dynasty:g.dynasty.filter(Me=>Me!==de)})})),g.classification.forEach(de=>{var Me;return B.push({name:de?((Me=Vn.find(Se=>Se.value===de))==null?void 0:Me.label)??de:p.searchPage.unclassified,remove:()=>s({...g,classification:g.classification.filter(Se=>Se!==de)})})}),g.hasImage&&B.push({name:h.hasImage,remove:()=>s({...g,hasImage:!1})}),g.hasText&&B.push({name:h.hasText,remove:()=>s({...g,hasText:!1})}),g.hasCollated&&B.push({name:h.hasCollated,remove:()=>s({...g,hasCollated:!1})}),g.loss&&B.push({name:`${h.extant}:${p.searchPage.loss[g.loss]}`,remove:()=>s({...g,loss:""})}),B},[g,s,h,p]),ue={query:i,onEntryLinkClick:o,typeName:a},ye=B=>y==="table"?t.jsx(Jo,{entries:B,...ue}):t.jsx(Zo,{entries:B,...ue}),Ne=ea.flatMap(B=>Nr(E,B));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:ep}),f&&t.jsx(Gu,{filters:g,onChange:s}),t.jsxs("div",{className:"bim-sr-main","aria-busy":q,ref:I,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(ta,{on:x==="all",onClick:()=>Y("all"),children:[p.search.allTab," ",t.jsx("small",{children:K})]}),me.map(B=>t.jsxs(ta,{on:x===B,onClick:()=>Y(B),children:[a(B)," ",t.jsx("small",{children:vn(gi(E,B))})]},B))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":u(h.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!g.sort,onClick:()=>s({...g,sort:""}),children:u(h.sortRelevance)}),["era","title"].map(B=>{const de=g.sort.startsWith(`${B}:`)?g.sort.endsWith("desc")?"desc":"asc":null,Me=B==="era"?h.sortEra:h.sortTitle,Se=B==="era"?de==="desc"?h.sortEraDesc:h.sortEraAsc:de==="desc"?h.sortTitleDesc:h.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":de!==null,title:u(Se),onClick:()=>s({...g,sort:`${B}:${de==="asc"?"desc":"asc"}`}),children:[u(Me),de?t.jsxs("span",{"aria-hidden":"true",children:[" ",de==="asc"?"↑":"↓"]}):null]},B)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":u(h.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":y==="table",onClick:()=>k("table"),children:u(h.viewTable)}),t.jsx("button",{type:"button","aria-pressed":y==="card",onClick:()=>k("card"),children:u(h.viewCard)})]})]}),xe&&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:K}))}),T.map(B=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u(r.formatTemplate(h.removeFilter,{name:B.name})),onClick:B.remove,children:[u(B.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},B.name))]}),le&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:le}),re&&t.jsx("div",{className:"bim-sr-empty",children:u(xe?h.emptyFiltered:r.formatTemplate(p.search.noResultsFor,{query:i}))}),!le&&!re&&x==="all"&&E&&(y==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Jo,{entries:Ne,...ue}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(h.limitedNote)})]}):t.jsx(t.Fragment,{children:me.map(B=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xi,{type:B,size:8}),a(B),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r.bim("meta-fg")},children:[vn(gi(E,B))," ",p.unit.items]})]}),gi(E,B)>Nr(E,B).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>Y(B),children:p.action.viewAll})]}),t.jsx(Zo,{entries:Nr(E,B),...ue})]},B))})),!le&&x!=="all"&&!H&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:p.search.loading}),!le&&x!=="all"&&H&&H.entries.length>0&&t.jsxs(t.Fragment,{children:[ye(H.entries),t.jsx(Zu,{page:$,pageSize:_r,total:Math.min(H.total,Ui),totalLabel:vn(H.total),onPage:D})]}),!le&&x!=="all"&&H&&H.entries.length===0&&!q&&t.jsxs("div",{className:"bim-sr-empty",children:[u(xe?h.emptyFiltered:r.formatTemplate(p.search.noResultsFor,{query:i})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>Y("all"),children:p.search.allTab})})]})]})]})};function ta({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",ia="bim-recent-entries",na=50;function ei(){try{const e=localStorage.getItem(_i);if(e)return JSON.parse(e);const i=localStorage.getItem(ia);if(i){const n=JSON.parse(i).map(s=>s.id);return localStorage.setItem(_i,JSON.stringify(n)),localStorage.removeItem(ia),n}return[]}catch{return[]}}function Kr(e){try{const i=ei().filter(n=>n!==e);i.unshift(e),i.length>na&&(i.length=na),localStorage.setItem(_i,JSON.stringify(i))}catch{}}function Yl(e){try{const i=ei().filter(n=>n!==e);localStorage.setItem(_i,JSON.stringify(i))}catch{}}function vs(){try{localStorage.removeItem(_i)}catch{}}async function Ss(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 zr=5,lp=50,cp=200,ra={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},dp=({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:S=!1,filters:k=Kn,onFiltersChange:x,resultTab:j,onResultTabChange:v,resultPage:$,onResultPageChange:_})=>{const N=r.useT(),I=[{type:"work",name:N.indexType.work,key:"works"},{type:"book",name:N.indexType.book,key:"books"},{type:"collection",name:N.indexType.collection,key:"collections"},{type:"entity",name:N.indexType.entity,key:"entities"}],D=["work","collection","book","entity"],[E,R]=b.useState(u??""),[O,M]=b.useState(null),[q,P]=b.useState(u??""),le=In(k).toString(),[ae,Ce]=b.useState(k);b.useEffect(()=>{Ce(k)},[le]);const xe=V=>{Ce(V),x==null||x(V)},[fe,se]=b.useState(null),[Re,H]=b.useState("all"),[me,W]=b.useState(!1),[K,re]=b.useState(null),[Y,T]=b.useState(""),[ue,ye]=b.useState(!(u!=null&&u.trim())),[Ne,B]=b.useState(ei),[de,Me]=b.useState([]),[Se,Je]=b.useState(!1),[X,je]=b.useState(!1),[L,G]=b.useState(null),[ie,te]=b.useState(null),ce=b.useRef(void 0),be=b.useRef(!1),Fe=b.useCallback(async(V,ze)=>{if(!V.trim()){ye(!0),M(null),se(null);return}if(ye(!1),S){P(V);return}W(!0),T("");try{if(e.searchAll){const we=await e.searchAll(V,ze??zr);M(we)}else{const we=["work","book","collection","entity"],Te=await Promise.all(we.map(tt=>e.search(V,tt,{page:1,pageSize:ze??zr})));M({works:Te[0].entries,books:Te[1].entries,collections:Te[2].entries,entities:Te[3].entries,totalWorks:Te[0].total,totalBooks:Te[1].total,totalCollections:Te[2].total,totalEntities:Te[3].total})}}catch(we){T(we instanceof Error?we.message:String(we)),M(null)}finally{W(!1)}},[e,S]);b.useEffect(()=>{let V=!1;const ze=()=>{var it,yt;const we=["work","book","collection","entity"],Te=Promise.all(we.map(De=>e.loadEntries(De,{page:1,pageSize:1}).catch(()=>({total:0})))),tt=((it=e.getResourceCounts)==null?void 0:it.call(e).catch(()=>null))??Promise.resolve(null),Pe=((yt=e.getSubtypeStats)==null?void 0:yt.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Te,tt,Pe]).then(([De,J,ve])=>{V||(G({works:De[0].total,books:De[1].total,collections:De[2].total,entities:De[3].total,hasText:J==null?void 0:J.hasText,hasImage:J==null?void 0:J.hasImage}),ve&&te(ve))})};return e.getCounts?e.getCounts().then(we=>{var Te,tt;V||(G({works:we.works,books:we.books,collections:we.collections,entities:we.entities,hasText:(Te=we.resourceCounts)==null?void 0:Te.hasText,hasImage:(tt=we.resourceCounts)==null?void 0:tt.hasImage}),we.subtypeStats&&te(we.subtypeStats))}).catch(()=>{V||ze()}):ze(),()=>{V=!0}},[e]),b.useEffect(()=>{be.current||!(u!=null&&u.trim())||(be.current=!0,Fe(u))},[u,Fe]);const Xe=b.useCallback(V=>{if(R(V),!V.trim()){f==null||f(V),ye(!0),M(null),se(null),H("all");return}ce.current&&clearTimeout(ce.current),ce.current=setTimeout(()=>{se(null),H("all"),f==null||f(V),Fe(V)},cp)},[Fe,f]),Be=b.useCallback(V=>{ce.current&&clearTimeout(ce.current),H("all"),f==null||f(V),Fe(V)},[Fe,f]),Ke=b.useCallback(V=>{se(V),Fe(E,lp)},[E,Fe]);b.useEffect(()=>{if(!Ne.length){Me([]);return}let V=!1;return Je(!0),Promise.all(Ne.slice(0,10).map(ze=>Ss(e,ze))).then(ze=>{V||(Me(ze),Je(!1))}),()=>{V=!0}},[Ne,e]);const Ye=V=>{re(V.id),Kr(V.id),B(ei()),s==null||s(V)},w=(V,ze)=>{if(s&&up(ze)){ze.preventDefault(),Ye(V);return}Kr(V.id),B(ei())},ee=V=>{Yl(V),B(ei())},Z=()=>{vs(),B([])},he=V=>I.find(ze=>ze.type===V),Le=!ue&&!O&&!Y,C=O&&(O.works.length>0||O.books.length>0||O.collections.length>0),ge=t.jsxs(t.Fragment,{children:[t.jsx(Sl,{transport:e,value:E,onChange:Xe,onSearch:Be,onEntrySelect:Ye}),S&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const V=E.trim();V&&vl(V),Be(E)},children:N.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:N.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:y?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:pp+(S?bp:"")}),(!S||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:[S?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:r.bim("fg")},children:N.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!m&&t.jsx(wl,{variant:"index-browser",indexSource:i,syncConfig:n,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),S?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:ge})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:`12px ${r.bim("browser-pad-x")}`,alignItems:"center"},children:ge}),ue&&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:L&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:ie?t.jsxs(t.Fragment,{children:[(ie.book??0)>0&&t.jsxs(t.Fragment,{children:[N.searchPage.statBook," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ie.book.toLocaleString()})," ",N.unit.bu,N.searchPage.statComma,t.jsx("strong",{style:{color:r.bim("fg")},children:L.books.toLocaleString()})," ",N.searchPage.statBookCopies]}),ie.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.searchPage.statArticle," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ie.article.toLocaleString()})," ",N.searchPage.statArticleUnit]}):null,ie.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.searchPage.statPoem," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ie.poem.toLocaleString()})," ",N.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.searchPage.statCollection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[N.indexType.work," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.indexType.book," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.indexType.collection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.collections.toLocaleString()}),L.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.indexType.entity," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.entities.toLocaleString()})]})]})}),L.hasImage!=null&&L.hasText!=null&&t.jsxs("span",{children:[N.resourceType.image," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.resourceType.text," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.hasText.toLocaleString()})]})]})}),S&&!ue&&t.jsx(Kl,{transport:e,query:q,filters:ae,onFiltersChange:xe,onEntryLinkClick:w,typeName:V=>he(V).name,tab:j,onTabChange:v,page:$,onPageChange:_}),!(S&&!ue)&&t.jsx("div",{style:{padding:`0 ${r.bim("browser-pad-x")} 20px`,flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:me||Le?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg"),minHeight:mp,boxSizing:"border-box"},children:N.search.searching}):Y?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r.bim("desc-fg")},children:Y})}):ue?t.jsx("div",{style:{flex:1},children:Se?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg")},children:N.search.loading}):de.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:N.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:N.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:de.slice(0,X?10:3).map(V=>V.notFound?t.jsx(xp,{id:V.id,onRemove:ee,t:N},V.id):t.jsx(sa,{entry:V,selected:K===V.id,onClick:w,getConfig:he,onRemove:ee},V.id))}),!X&&de.length>3&&t.jsx("button",{onClick:()=>je(!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:N.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:N.search.searchTitle}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:N.search.searchSubtitle})]})}):C?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:hp}),(()=>{const V=Pe=>O[ra[Pe]]??0,ze=D.map(Pe=>I.find(it=>it.type===Pe)).filter(Pe=>V(Pe.key)>0);if(ze.length<2)return null;const we=ze.reduce((Pe,it)=>Pe+V(it.key),0),Te=Pe=>{if(H(Pe),Pe!=="all"&&fe!==Pe){const it=I.find(De=>De.type===Pe),yt=(O[it.key]??[]).length;V(it.key)>yt&&Ke(Pe)}},tt=Pe=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:Pe?r.bim("fg"):r.bim("desc-fg"),fontWeight:Pe?700:400,boxShadow:Pe?`inset 0 -2px 0 ${r.bim("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":N.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${r.bim("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":Re==="all",style:tt(Re==="all"),onClick:()=>Te("all"),children:[N.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:we.toLocaleString()})]}),ze.map(Pe=>t.jsxs("button",{type:"button","aria-pressed":Re===Pe.type,style:tt(Re===Pe.type),onClick:()=>Te(Pe.type),children:[Pe.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:V(Pe.key).toLocaleString()})]},Pe.type))]})})(),I.map(({type:V,name:ze,key:we})=>{const Te=O[we]??[],tt=ra[we],Pe=O[tt]??0;if(Te.length===0||Re!=="all"&&Re!==V)return null;const yt=Re==="all"&&!(fe===V)&&Pe>zr;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(Xi,{type:V})," ",ze,t.jsxs("span",{style:{fontWeight:400,color:r.bim("desc-fg"),marginLeft:"6px"},children:[Pe," ",N.unit.items]})]}),yt&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>Ke(V),style:{border:"none",background:"transparent",color:r.bim("primary"),cursor:"pointer",fontSize:"12px"},children:N.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:Te.map(De=>{if(h)return t.jsx(b.Fragment,{children:h(De)},De.id);const J=p==="card"?gp:sa;return t.jsx(J,{entry:De,selected:K===De.id,onClick:w,getConfig:he,query:E},De.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(N.search.noResultsFor,{query:E})}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:N.search.tryOther})]})})]})},mp=240;function up(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const pp=`
|
|
120
|
+
`,ws="bim-search-view",_r=50,Qo=5,Ui=1e3;function vn(e){return e>=Ui?`${Ui.toLocaleString()}+`:e.toLocaleString()}const tp={work:"work",works:"work",book:"book",books:"book",collection:"collection",collections:"collection",entity:"entity",entities:"entity"};function ip(e){return e&&tp[e.toLowerCase()]||"all"}function np(e){return e==="all"?null:e}const ea=["work","collection","book","entity"],rp={work:"works",collection:"collections",book:"books",entity:"entities"},sp={work:"totalWorks",collection:"totalCollections",book:"totalBooks",entity:"totalEntities"};function op(){try{return window.localStorage.getItem(ws)==="card"?"card":"table"}catch{return"table"}}function ap(e){try{window.localStorage.setItem(ws,e)}catch{}}const gi=(e,i)=>(e==null?void 0:e[sp[i]])??0,Nr=(e,i)=>(e==null?void 0:e[rp[i]])??[],Kl=({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:Kn,[f,n]),[y,v]=b.useState("table");b.useEffect(()=>{v(op())},[]);const k=B=>{v(B),ap(B)},[x,j]=b.useState(l??"all"),S=b.useRef(x);S.current=x,b.useEffect(()=>{l!==void 0&&l!==S.current&&(j(l),_(1))},[l]);const[$,_]=b.useState(c&&c>0?c:1),N=b.useRef($);N.current=$,b.useEffect(()=>{c!==void 0&&c>0&&c!==N.current&&_(c)},[c]);const I=b.useRef(null),D=b.useCallback(B=>{var Me;_(B),m==null||m(B);const de=I.current;de&&de.getBoundingClientRect().top<0&&((Me=de.scrollIntoView)==null||Me.call(de,{block:"start",behavior:"instant"}))},[m]),[E,R]=b.useState(null),[O,M]=b.useState(null),[q,P]=b.useState(!1),[le,ae]=b.useState(""),Ce=In(g).toString(),xe=Gn(g)>0,fe=In({...g,sort:""}).toString(),se=b.useRef({query:i,filterOnlyKey:fe,sort:g.sort});b.useEffect(()=>{const B=se.current;B.query!==i||B.filterOnlyKey!==fe?(j("all"),_(1)):B.sort!==g.sort&&_(1),se.current={query:i,filterOnlyKey:fe,sort:g.sort}},[i,fe,g.sort]),b.useEffect(()=>{let B=!1;return P(!0),ae(""),(async()=>{try{let de;if(e.searchAll)de=await e.searchAll(i,Qo,g);else{const Me=["work","book","collection","entity"],Se=await Promise.all(Me.map(Je=>e.search(i,Je,{page:1,pageSize:Qo,filters:g})));de={works:Se[0].entries,books:Se[1].entries,collections:Se[2].entries,entities:Se[3].entries,totalWorks:Se[0].total,totalBooks:Se[1].total,totalCollections:Se[2].total,totalEntities:Se[3].total}}B||R(de)}catch(de){B||(ae(de instanceof Error?de.message:String(de)),R(null))}finally{B||P(!1)}})(),()=>{B=!0}},[e,i,Ce]);const Re=x;b.useEffect(()=>{if(x==="all"){M(null);return}let B=!1;return P(!0),(async()=>{try{const de=await e.search(i,x,{page:$,pageSize:_r,filters:g});B||M({key:Re,entries:de.entries,total:de.total})}catch(de){B||(ae(de instanceof Error?de.message:String(de)),M(null))}finally{B||P(!1)}})(),()=>{B=!0}},[e,i,Ce,x,$]);const H=O&&O.key===Re?O:null;b.useEffect(()=>{if(x==="all"||!H||q)return;const B=Math.min(H.total,Ui),de=Ju($,B,_r);H.entries.length===0&&B>0&&de!==$&&(_(de),m==null||m(de))},[x,H,q,$]);const me=b.useMemo(()=>ea.filter(B=>gi(E,B)>0),[E]),W=me.reduce((B,de)=>B+gi(E,de),0),K=me.some(B=>gi(E,B)>=Ui)?`${W.toLocaleString()}+`:W.toLocaleString(),re=!q&&!le&&E!==null&&W===0,Y=b.useCallback(B=>{j(B),_(1),d==null||d(B)},[d]),T=b.useMemo(()=>{const B=[];return g.dynasty.forEach(de=>B.push({name:de,remove:()=>s({...g,dynasty:g.dynasty.filter(Me=>Me!==de)})})),g.classification.forEach(de=>{var Me;return B.push({name:de?((Me=Vn.find(Se=>Se.value===de))==null?void 0:Me.label)??de:p.searchPage.unclassified,remove:()=>s({...g,classification:g.classification.filter(Se=>Se!==de)})})}),g.hasImage&&B.push({name:h.hasImage,remove:()=>s({...g,hasImage:!1})}),g.hasText&&B.push({name:h.hasText,remove:()=>s({...g,hasText:!1})}),g.hasCollated&&B.push({name:h.hasCollated,remove:()=>s({...g,hasCollated:!1})}),g.loss&&B.push({name:`${h.extant}:${p.searchPage.loss[g.loss]}`,remove:()=>s({...g,loss:""})}),B},[g,s,h,p]),ue={query:i,onEntryLinkClick:o,typeName:a},ye=B=>y==="table"?t.jsx(Jo,{entries:B,...ue}):t.jsx(Zo,{entries:B,...ue}),Ne=ea.flatMap(B=>Nr(E,B));return t.jsxs("div",{className:"bim-sr-layout","data-nofilters":f?void 0:"true",children:[t.jsx("style",{children:ep}),f&&t.jsx(Gu,{filters:g,onChange:s}),t.jsxs("div",{className:"bim-sr-main","aria-busy":q,ref:I,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(ta,{on:x==="all",onClick:()=>Y("all"),children:[p.search.allTab," ",t.jsx("small",{children:K})]}),me.map(B=>t.jsxs(ta,{on:x===B,onClick:()=>Y(B),children:[a(B)," ",t.jsx("small",{children:vn(gi(E,B))})]},B))]}),t.jsxs("div",{className:"bim-sr-tools",children:[f&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bim-sr-sorts",role:"group","aria-label":u(h.sortLabel),children:[t.jsx("button",{type:"button","aria-pressed":!g.sort,onClick:()=>s({...g,sort:""}),children:u(h.sortRelevance)}),["era","title"].map(B=>{const de=g.sort.startsWith(`${B}:`)?g.sort.endsWith("desc")?"desc":"asc":null,Me=B==="era"?h.sortEra:h.sortTitle,Se=B==="era"?de==="desc"?h.sortEraDesc:h.sortEraAsc:de==="desc"?h.sortTitleDesc:h.sortTitleAsc;return t.jsxs("button",{type:"button","aria-pressed":de!==null,title:u(Se),onClick:()=>s({...g,sort:`${B}:${de==="asc"?"desc":"asc"}`}),children:[u(Me),de?t.jsxs("span",{"aria-hidden":"true",children:[" ",de==="asc"?"↑":"↓"]}):null]},B)})]}),t.jsx("span",{className:"bim-sr-vsep","aria-hidden":"true"})]}),t.jsxs("div",{className:"bim-sr-view",role:"group","aria-label":u(h.viewLabel),children:[t.jsx("button",{type:"button","aria-pressed":y==="table",onClick:()=>k("table"),children:u(h.viewTable)}),t.jsx("button",{type:"button","aria-pressed":y==="card",onClick:()=>k("card"),children:u(h.viewCard)})]})]}),xe&&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:K}))}),T.map(B=>t.jsxs("button",{type:"button",className:"bim-sr-tag-x","aria-label":u(r.formatTemplate(h.removeFilter,{name:B.name})),onClick:B.remove,children:[u(B.name),t.jsx("span",{"aria-hidden":"true",children:"×"})]},B.name))]}),le&&t.jsx("div",{className:"bim-sr-empty",role:"alert",children:le}),re&&t.jsx("div",{className:"bim-sr-empty",children:u(xe?h.emptyFiltered:r.formatTemplate(p.search.noResultsFor,{query:i}))}),!le&&!re&&x==="all"&&E&&(y==="table"?t.jsxs(t.Fragment,{children:[t.jsx(Jo,{entries:Ne,...ue}),t.jsx("p",{className:"bim-sr-note",style:{marginTop:10},children:u(h.limitedNote)})]}):t.jsx(t.Fragment,{children:me.map(B=>t.jsxs("section",{style:{marginTop:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,marginBottom:10},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,letterSpacing:".1em",display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xi,{type:B,size:8}),a(B),t.jsxs("span",{style:{fontSize:12.5,fontWeight:400,color:r.bim("meta-fg")},children:[vn(gi(E,B))," ",p.unit.items]})]}),gi(E,B)>Nr(E,B).length&&t.jsx("button",{type:"button",className:"bim-sr-clear",style:{textDecoration:"none"},onClick:()=>Y(B),children:p.action.viewAll})]}),t.jsx(Zo,{entries:Nr(E,B),...ue})]},B))})),!le&&x!=="all"&&!H&&t.jsx("div",{className:"bim-sr-empty",role:"status",style:{minHeight:240},children:p.search.loading}),!le&&x!=="all"&&H&&H.entries.length>0&&t.jsxs(t.Fragment,{children:[ye(H.entries),t.jsx(Zu,{page:$,pageSize:_r,total:Math.min(H.total,Ui),totalLabel:vn(H.total),onPage:D})]}),!le&&x!=="all"&&H&&H.entries.length===0&&!q&&t.jsxs("div",{className:"bim-sr-empty",children:[u(xe?h.emptyFiltered:r.formatTemplate(p.search.noResultsFor,{query:i})),t.jsx("div",{children:t.jsx("button",{type:"button",className:"bim-sr-clear",onClick:()=>Y("all"),children:p.search.allTab})})]})]})]})};function ta({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",ia="bim-recent-entries",na=50;function ei(){try{const e=localStorage.getItem(_i);if(e)return JSON.parse(e);const i=localStorage.getItem(ia);if(i){const n=JSON.parse(i).map(s=>s.id);return localStorage.setItem(_i,JSON.stringify(n)),localStorage.removeItem(ia),n}return[]}catch{return[]}}function Kr(e){try{const i=ei().filter(n=>n!==e);i.unshift(e),i.length>na&&(i.length=na),localStorage.setItem(_i,JSON.stringify(i))}catch{}}function Yl(e){try{const i=ei().filter(n=>n!==e);localStorage.setItem(_i,JSON.stringify(i))}catch{}}function vs(){try{localStorage.removeItem(_i)}catch{}}async function Ss(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 zr=5,lp=50,cp=200,ra={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},dp=({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:v=!1,filters:k=Kn,onFiltersChange:x,resultTab:j,onResultTabChange:S,resultPage:$,onResultPageChange:_})=>{const N=r.useT(),I=[{type:"work",name:N.indexType.work,key:"works"},{type:"book",name:N.indexType.book,key:"books"},{type:"collection",name:N.indexType.collection,key:"collections"},{type:"entity",name:N.indexType.entity,key:"entities"}],D=["work","collection","book","entity"],[E,R]=b.useState(u??""),[O,M]=b.useState(null),[q,P]=b.useState(u??""),le=In(k).toString(),[ae,Ce]=b.useState(k);b.useEffect(()=>{Ce(k)},[le]);const xe=V=>{Ce(V),x==null||x(V)},[fe,se]=b.useState(null),[Re,H]=b.useState("all"),[me,W]=b.useState(!1),[K,re]=b.useState(null),[Y,T]=b.useState(""),[ue,ye]=b.useState(!(u!=null&&u.trim())),[Ne,B]=b.useState(ei),[de,Me]=b.useState([]),[Se,Je]=b.useState(!1),[X,je]=b.useState(!1),[L,G]=b.useState(null),[ie,te]=b.useState(null),ce=b.useRef(void 0),be=b.useRef(!1),Fe=b.useCallback(async(V,ze)=>{if(!V.trim()){ye(!0),M(null),se(null);return}if(ye(!1),v){P(V);return}W(!0),T("");try{if(e.searchAll){const we=await e.searchAll(V,ze??zr);M(we)}else{const we=["work","book","collection","entity"],Te=await Promise.all(we.map(tt=>e.search(V,tt,{page:1,pageSize:ze??zr})));M({works:Te[0].entries,books:Te[1].entries,collections:Te[2].entries,entities:Te[3].entries,totalWorks:Te[0].total,totalBooks:Te[1].total,totalCollections:Te[2].total,totalEntities:Te[3].total})}}catch(we){T(we instanceof Error?we.message:String(we)),M(null)}finally{W(!1)}},[e,v]);b.useEffect(()=>{let V=!1;const ze=()=>{var it,yt;const we=["work","book","collection","entity"],Te=Promise.all(we.map(De=>e.loadEntries(De,{page:1,pageSize:1}).catch(()=>({total:0})))),tt=((it=e.getResourceCounts)==null?void 0:it.call(e).catch(()=>null))??Promise.resolve(null),Pe=((yt=e.getSubtypeStats)==null?void 0:yt.call(e).catch(()=>null))??Promise.resolve(null);Promise.all([Te,tt,Pe]).then(([De,J,ve])=>{V||(G({works:De[0].total,books:De[1].total,collections:De[2].total,entities:De[3].total,hasText:J==null?void 0:J.hasText,hasImage:J==null?void 0:J.hasImage}),ve&&te(ve))})};return e.getCounts?e.getCounts().then(we=>{var Te,tt;V||(G({works:we.works,books:we.books,collections:we.collections,entities:we.entities,hasText:(Te=we.resourceCounts)==null?void 0:Te.hasText,hasImage:(tt=we.resourceCounts)==null?void 0:tt.hasImage}),we.subtypeStats&&te(we.subtypeStats))}).catch(()=>{V||ze()}):ze(),()=>{V=!0}},[e]),b.useEffect(()=>{be.current||!(u!=null&&u.trim())||(be.current=!0,Fe(u))},[u,Fe]);const Xe=b.useCallback(V=>{if(R(V),!V.trim()){f==null||f(V),ye(!0),M(null),se(null),H("all");return}ce.current&&clearTimeout(ce.current),ce.current=setTimeout(()=>{se(null),H("all"),f==null||f(V),Fe(V)},cp)},[Fe,f]),Be=b.useCallback(V=>{ce.current&&clearTimeout(ce.current),H("all"),f==null||f(V),Fe(V)},[Fe,f]),Ke=b.useCallback(V=>{se(V),Fe(E,lp)},[E,Fe]);b.useEffect(()=>{if(!Ne.length){Me([]);return}let V=!1;return Je(!0),Promise.all(Ne.slice(0,10).map(ze=>Ss(e,ze))).then(ze=>{V||(Me(ze),Je(!1))}),()=>{V=!0}},[Ne,e]);const Ye=V=>{re(V.id),Kr(V.id),B(ei()),s==null||s(V)},w=(V,ze)=>{if(s&&up(ze)){ze.preventDefault(),Ye(V);return}Kr(V.id),B(ei())},ee=V=>{Yl(V),B(ei())},Z=()=>{vs(),B([])},he=V=>I.find(ze=>ze.type===V),Le=!ue&&!O&&!Y,C=O&&(O.works.length>0||O.books.length>0||O.collections.length>0),ge=t.jsxs(t.Fragment,{children:[t.jsx(Sl,{transport:e,value:E,onChange:Xe,onSearch:Be,onEntrySelect:Ye}),v&&t.jsx("button",{type:"button",className:"bim-ib-submit",onClick:()=>{const V=E.trim();V&&vl(V),Be(E)},children:N.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:N.action.newEntry})]});return t.jsxs("div",{className:"bim-browser-container",style:y?{minHeight:"100svh"}:void 0,children:[t.jsx("style",{children:pp+(v?bp:"")}),(!v||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:[v?t.jsx("span",{}):t.jsx("h1",{style:{margin:0,fontSize:"18px",color:r.bim("fg")},children:N.browser.title}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!m&&t.jsx(wl,{variant:"index-browser",indexSource:i,syncConfig:n,onSwitchMode:a,onToggleDraft:l,onConfigurePath:d,onSelectFolder:c})]})]})}),v?t.jsxs("div",{className:"bim-ib-bar","data-nofilters":e.supportsSearchFilters?void 0:"true",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("div",{className:"bim-ib-bar-main",children:ge})]}):t.jsx("div",{style:{display:"flex",gap:"8px",padding:`12px ${r.bim("browser-pad-x")}`,alignItems:"center"},children:ge}),ue&&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:L&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:ie?t.jsxs(t.Fragment,{children:[(ie.book??0)>0&&t.jsxs(t.Fragment,{children:[N.searchPage.statBook," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ie.book.toLocaleString()})," ",N.unit.bu,N.searchPage.statComma,t.jsx("strong",{style:{color:r.bim("fg")},children:L.books.toLocaleString()})," ",N.searchPage.statBookCopies]}),ie.article?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.searchPage.statArticle," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ie.article.toLocaleString()})," ",N.searchPage.statArticleUnit]}):null,ie.poem?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.searchPage.statPoem," ",t.jsx("strong",{style:{color:r.bim("fg")},children:ie.poem.toLocaleString()})," ",N.searchPage.statPoemUnit]}):null,t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.searchPage.statCollection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.collections.toLocaleString()})]}):t.jsxs(t.Fragment,{children:[N.indexType.work," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.works.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.indexType.book," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.books.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.indexType.collection," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.collections.toLocaleString()}),L.entities>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.indexType.entity," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.entities.toLocaleString()})]})]})}),L.hasImage!=null&&L.hasText!=null&&t.jsxs("span",{children:[N.resourceType.image," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.hasImage.toLocaleString()}),t.jsx("span",{style:{margin:"0 6px"},children:"·"}),N.resourceType.text," ",t.jsx("strong",{style:{color:r.bim("fg")},children:L.hasText.toLocaleString()})]})]})}),v&&!ue&&t.jsx(Kl,{transport:e,query:q,filters:ae,onFiltersChange:xe,onEntryLinkClick:w,typeName:V=>he(V).name,tab:j,onTabChange:S,page:$,onPageChange:_}),!(v&&!ue)&&t.jsx("div",{style:{padding:`0 ${r.bim("browser-pad-x")} 20px`,flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:me||Le?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg"),minHeight:mp,boxSizing:"border-box"},children:N.search.searching}):Y?t.jsx("div",{style:{textAlign:"center",padding:"40px"},children:t.jsx("p",{style:{color:r.bim("desc-fg")},children:Y})}):ue?t.jsx("div",{style:{flex:1},children:Se?t.jsx("div",{style:{textAlign:"center",padding:"40px",color:r.bim("desc-fg")},children:N.search.loading}):de.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:N.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:N.search.clearRecent})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:de.slice(0,X?10:3).map(V=>V.notFound?t.jsx(xp,{id:V.id,onRemove:ee,t:N},V.id):t.jsx(sa,{entry:V,selected:K===V.id,onClick:w,getConfig:he,onRemove:ee},V.id))}),!X&&de.length>3&&t.jsx("button",{onClick:()=>je(!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:N.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:N.search.searchTitle}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:N.search.searchSubtitle})]})}):C?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[t.jsx("style",{children:hp}),(()=>{const V=Pe=>O[ra[Pe]]??0,ze=D.map(Pe=>I.find(it=>it.type===Pe)).filter(Pe=>V(Pe.key)>0);if(ze.length<2)return null;const we=ze.reduce((Pe,it)=>Pe+V(it.key),0),Te=Pe=>{if(H(Pe),Pe!=="all"&&fe!==Pe){const it=I.find(De=>De.type===Pe),yt=(O[it.key]??[]).length;V(it.key)>yt&&Ke(Pe)}},tt=Pe=>({border:"none",background:"transparent",cursor:"pointer",font:"inherit",fontSize:"14px",padding:"8px 12px",minHeight:44,color:Pe?r.bim("fg"):r.bim("desc-fg"),fontWeight:Pe?700:400,boxShadow:Pe?`inset 0 -2px 0 ${r.bim("primary")}`:"none"});return t.jsxs("div",{role:"group","aria-label":N.search.resultTabs,style:{display:"flex",flexWrap:"wrap",borderBottom:`1px solid ${r.bim("widget-border")}`},children:[t.jsxs("button",{type:"button","aria-pressed":Re==="all",style:tt(Re==="all"),onClick:()=>Te("all"),children:[N.search.allTab," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:we.toLocaleString()})]}),ze.map(Pe=>t.jsxs("button",{type:"button","aria-pressed":Re===Pe.type,style:tt(Re===Pe.type),onClick:()=>Te(Pe.type),children:[Pe.name," ",t.jsx("span",{style:{fontSize:12,fontWeight:400},children:V(Pe.key).toLocaleString()})]},Pe.type))]})})(),I.map(({type:V,name:ze,key:we})=>{const Te=O[we]??[],tt=ra[we],Pe=O[tt]??0;if(Te.length===0||Re!=="all"&&Re!==V)return null;const yt=Re==="all"&&!(fe===V)&&Pe>zr;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(Xi,{type:V})," ",ze,t.jsxs("span",{style:{fontWeight:400,color:r.bim("desc-fg"),marginLeft:"6px"},children:[Pe," ",N.unit.items]})]}),yt&&t.jsx("button",{className:"bim-ib-viewall",onClick:()=>Ke(V),style:{border:"none",background:"transparent",color:r.bim("primary"),cursor:"pointer",fontSize:"12px"},children:N.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:Te.map(De=>{if(h)return t.jsx(b.Fragment,{children:h(De)},De.id);const J=p==="card"?gp:sa;return t.jsx(J,{entry:De,selected:K===De.id,onClick:w,getConfig:he,query:E},De.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(N.search.noResultsFor,{query:E})}),t.jsx("p",{style:{color:r.bim("desc-fg"),fontSize:"13px"},children:N.search.tryOther})]})})]})},mp=240;function up(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}const pp=`
|
|
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
|
`,bp=`
|
|
@@ -142,7 +142,7 @@
|
|
|
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
|
-
}`,Vl={color:"inherit",textDecoration:"none"},fp=({snippet:e})=>{const{convert:i}=gt();return t.jsx("div",{style:{fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.6},children:bs(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))})},gp=({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?`${Vi(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=It();return t.jsxs("a",{href:u(e.id),onClick:f=>n(e,f),className:"bim-result-card",style:{...Vl,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(fp,{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(Xi,{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})]})]})]})},sa=({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=It();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:{...Vl,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:a?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(Xi,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color: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:[Vi(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:"×"})]})},xp=({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 yp({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 jp({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:oa(i===null),children:s.catalog.all}),e.map(o=>t.jsxs("button",{onClick:()=>n(o.name),style:oa(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 oa(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 kp({id:e,label:i,onNavigate:n,renderLink:s}){const o=It();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 wp(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 aa({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?wp(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(kp,{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 Gl=({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),[S,k]=b.useState(""),x=e||c;b.useEffect(()=>{if(e||!i||!(n!=null&&n.getCollectionCatalog))return;let N=!1;return h(!0),f(null),n.getCollectionCatalog(i).then(I=>{N||(I?m(I):f(d.catalog.notFound))}).catch(I=>{N||f(I instanceof Error?I.message:d.catalog.loadFailed)}).finally(()=>{N||h(!1)}),()=>{N=!0}},[e,i,n,d]);const j=(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 N=x.books.map(D=>D.volumes[0]).filter(D=>D!=null);return new Set(N).size<N.length},[x]),$=b.useMemo(()=>{if(!x)return[];let N=x.books;if(g&&(N=N.filter(I=>I.section===g)),S.trim()){const I=S.trim().toLowerCase();N=N.filter(D=>D.title.toLowerCase().includes(I)||D.sub_items&&D.sub_items.some(E=>E.toLowerCase().includes(I))||D.edition&&D.edition.toLowerCase().includes(I))}return N},[x,g,S]),_=b.useMemo(()=>{if(!v)return null;const N=[],I=new Map;for(const E of $){if(!E.volumes||E.volumes.length===0)continue;const R=E.volumes[0];I.has(R)||I.set(R,[]),I.get(R).push(E)}const D=[...I.keys()].sort((E,R)=>E-R);for(const E of D)N.push({volume:E,books:I.get(E)});return N},[$,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(yp,{data:x}),j&&t.jsx(jp,{sections:x.sections,activeSection:g,onSelect:y}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:S,onChange:N=>k(N.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:[_?_.map((N,I)=>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:N.volume})}),N.books.map((D,E)=>t.jsx(aa,{book:D,onNavigate:s,renderLink:o,showVolumes:D.volumes.length>1},`${N.volume}-${E}`))]},`${N.volume}-${I}`)):$.map((N,I)=>t.jsx(aa,{book:N,onNavigate:s,renderLink:o,showVolumes:!0},I)),$.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Fi=e=>typeof e=="string"&&e?e:void 0;function vp(e){if(!e||typeof e!="object")return e;const i=[],n=o=>{const a=Fi(o);a&&!i.includes(a)&&i.push(a)};return n(e.work_id),Array.isArray(e.work_ids)&&e.work_ids.forEach(n),"work_id"in e||"work_ids"in e?{...e,work_ids:i,work_id:i[0]??null}:e}function Sp(e){if(!e||typeof e!="object")return e??null;const i=e.meta,n={...e};return i&&typeof i=="object"&&(n.page_title===void 0&&Fi(i.page_title)&&(n.page_title=Fi(i.page_title)),n.source_url===void 0&&Fi(i.source_url)&&(n.source_url=Fi(i.source_url))),Array.isArray(e.sections)&&(n.sections=e.sections.map(vp)),n}const Cr=e=>e?e.catch(()=>null):Promise.resolve(null);function ql(e){const i=new Map;function n(s){var a;let o=i.get(s);return o||(o=Cr((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 _e.isSafeSegment(s)?n(s):Promise.resolve(null)},async getIndex(s,o){return!_e.isSafeSegment(s)||!_e.isSafeSegment(o)||!e.getTextIndex?null:Cr(e.getTextIndex(s,o))},async getChapter(s,o,a,l){if(!_e.isSafeSegment(s)||!_e.isSafeSegment(o)||!_e.isSafeSegment(a)||!e.getChapter)return null;const d=await Cr(e.getChapter(s,o,a,l));return d&&d.json?{...d,json:Sp(d.json)}:d}}}const Xl=()=>{const{t:e}=oe(),[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)})},Er=String.raw`https?:\/\/[^\s()()<>"]+`,$p=new RegExp(String.raw`\[([^\]\n]+)\]\((${Er})\)`+String.raw`|(《[^》\n]+》)\s?[((](${Er})[))]`+`|(${Er})`,"g");function _p(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Np(e){const i=[];let n=0;for(const s of e.matchAll($p)){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:_p(s[5]),url:s[5]}),n=o+s[0].length}return n<e.length&&i.push({text:e.slice(n)}),i}function Jl({text:e,convert:i,className:n="bim-rd-link"}){return t.jsx(t.Fragment,{children:Np(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 $s="(min-width: 1100px)",Sn="(max-width: 719px)",$n="(max-width: 859px)",zp=`${Sn}, (pointer: coarse)`,Bt=r.bim("reader-top"),Cp="48px",Zl=`
|
|
145
|
+
}`,Vl={color:"inherit",textDecoration:"none"},fp=({snippet:e})=>{const{convert:i}=gt();return t.jsx("div",{style:{fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.6},children:bs(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))})},gp=({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?`${Vi(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=It();return t.jsxs("a",{href:u(e.id),onClick:f=>n(e,f),className:"bim-result-card",style:{...Vl,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(fp,{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(Xi,{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})]})]})]})},sa=({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=It();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:{...Vl,flex:1,minWidth:0,display:"flex",alignItems:"flex-start",gap:"10px",padding:a?"10px 0 10px 12px":"10px 12px",borderRadius:"6px",cursor:"pointer"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[t.jsx(Xi,{type:e.type,size:12}),t.jsx("span",{style:{fontSize:"9px",color: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:[Vi(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:"×"})]})},xp=({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 yp({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 jp({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:oa(i===null),children:s.catalog.all}),e.map(o=>t.jsxs("button",{onClick:()=>n(o.name),style:oa(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 oa(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 kp({id:e,label:i,onNavigate:n,renderLink:s}){const o=It();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 wp(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 aa({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?wp(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(kp,{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 Gl=({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),[v,k]=b.useState(""),x=e||c;b.useEffect(()=>{if(e||!i||!(n!=null&&n.getCollectionCatalog))return;let N=!1;return h(!0),f(null),n.getCollectionCatalog(i).then(I=>{N||(I?m(I):f(d.catalog.notFound))}).catch(I=>{N||f(I instanceof Error?I.message:d.catalog.loadFailed)}).finally(()=>{N||h(!1)}),()=>{N=!0}},[e,i,n,d]);const j=(x==null?void 0:x.sections)&&x.sections.length>0,S=b.useMemo(()=>{if(!x)return!1;if(x.volume_index&&Object.keys(x.volume_index).length>0)return!0;const N=x.books.map(D=>D.volumes[0]).filter(D=>D!=null);return new Set(N).size<N.length},[x]),$=b.useMemo(()=>{if(!x)return[];let N=x.books;if(g&&(N=N.filter(I=>I.section===g)),v.trim()){const I=v.trim().toLowerCase();N=N.filter(D=>D.title.toLowerCase().includes(I)||D.sub_items&&D.sub_items.some(E=>E.toLowerCase().includes(I))||D.edition&&D.edition.toLowerCase().includes(I))}return N},[x,g,v]),_=b.useMemo(()=>{if(!S)return null;const N=[],I=new Map;for(const E of $){if(!E.volumes||E.volumes.length===0)continue;const R=E.volumes[0];I.has(R)||I.set(R,[]),I.get(R).push(E)}const D=[...I.keys()].sort((E,R)=>E-R);for(const E of D)N.push({volume:E,books:I.get(E)});return N},[$,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(yp,{data:x}),j&&t.jsx(jp,{sections:x.sections,activeSection:g,onSelect:y}),t.jsxs("div",{style:{marginBottom:"12px"},children:[t.jsx("input",{type:"text",placeholder:d.search.searchBookName,value:v,onChange:N=>k(N.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:[_?_.map((N,I)=>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:N.volume})}),N.books.map((D,E)=>t.jsx(aa,{book:D,onNavigate:s,renderLink:o,showVolumes:D.volumes.length>1},`${N.volume}-${E}`))]},`${N.volume}-${I}`)):$.map((N,I)=>t.jsx(aa,{book:N,onNavigate:s,renderLink:o,showVolumes:!0},I)),$.length===0&&t.jsx("div",{style:{padding:"32px",textAlign:"center",color:r.bim("desc-fg"),fontSize:"13px"},children:d.catalog.noMatch})]})]}):null},Fi=e=>typeof e=="string"&&e?e:void 0;function vp(e){if(!e||typeof e!="object")return e;const i=[],n=o=>{const a=Fi(o);a&&!i.includes(a)&&i.push(a)};return n(e.work_id),Array.isArray(e.work_ids)&&e.work_ids.forEach(n),"work_id"in e||"work_ids"in e?{...e,work_ids:i,work_id:i[0]??null}:e}function Sp(e){if(!e||typeof e!="object")return e??null;const i=e.meta,n={...e};return i&&typeof i=="object"&&(n.page_title===void 0&&Fi(i.page_title)&&(n.page_title=Fi(i.page_title)),n.source_url===void 0&&Fi(i.source_url)&&(n.source_url=Fi(i.source_url))),Array.isArray(e.sections)&&(n.sections=e.sections.map(vp)),n}const Cr=e=>e?e.catch(()=>null):Promise.resolve(null);function ql(e){const i=new Map;function n(s){var a;let o=i.get(s);return o||(o=Cr((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 _e.isSafeSegment(s)?n(s):Promise.resolve(null)},async getIndex(s,o){return!_e.isSafeSegment(s)||!_e.isSafeSegment(o)||!e.getTextIndex?null:Cr(e.getTextIndex(s,o))},async getChapter(s,o,a,l){if(!_e.isSafeSegment(s)||!_e.isSafeSegment(o)||!_e.isSafeSegment(a)||!e.getChapter)return null;const d=await Cr(e.getChapter(s,o,a,l));return d&&d.json?{...d,json:Sp(d.json)}:d}}}const Xl=()=>{const{t:e}=oe(),[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)})},Er=String.raw`https?:\/\/[^\s()()<>"]+`,$p=new RegExp(String.raw`\[([^\]\n]+)\]\((${Er})\)`+String.raw`|(《[^》\n]+》)\s?[((](${Er})[))]`+`|(${Er})`,"g");function _p(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return e}}function Np(e){const i=[];let n=0;for(const s of e.matchAll($p)){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:_p(s[5]),url:s[5]}),n=o+s[0].length}return n<e.length&&i.push({text:e.slice(n)}),i}function Jl({text:e,convert:i,className:n="bim-rd-link"}){return t.jsx(t.Fragment,{children:Np(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 $s="(min-width: 1100px)",Sn="(max-width: 719px)",$n="(max-width: 859px)",zp=`${Sn}, (pointer: coarse)`,Bt=r.bim("reader-top"),Cp="48px",Zl=`
|
|
146
146
|
.bim-rd {
|
|
147
147
|
/* 阅读器范围的字体:宿主覆盖 --bim-font-reader-*(见 README「样式契约」),不必再写 .bim-rd 选择器 */
|
|
148
148
|
--bim-font-ui: ${r.bim("font-reader-ui")};
|
|
@@ -778,8 +778,8 @@ button.bim-rd-pg:hover { border-color: ${r.bim("accent")}; }
|
|
|
778
778
|
.guji-page-indicator:hover, .guji-page-indicator:focus-visible { opacity: 1; }
|
|
779
779
|
.guji-page-indicator:focus-visible { outline: 2px solid ${r.bim("accent")}; outline-offset: 1px; border-radius: 3px; }
|
|
780
780
|
@media ${Sn} { .guji-page-indicator { display: none; } }
|
|
781
|
-
`;function _s(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(s=>_s(s,i))):!1}const la=()=>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 Ep({item:e,activeKey:i,onSelect:n,tabKey:s}){const{t:o}=oe(),a=_s(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(la,{})}),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(Yr,{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(la,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Yr,{items:e.children,activeKey:i,onSelect:n,tabKey:s})]})}function Yr({items:e,activeKey:i,onSelect:n,tabKey:s}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(Ep,{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 ca(e,i){var n;for(const s of e)if(s.key===i||_s(s,i))return s.key;return((n=e[0])==null?void 0:n.key)??null}function Ql({items:e,activeKey:i,onSelect:n,label:s}){const{t:o}=oe(),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??ca(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===ca(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 S=y;if(h.key==="ArrowDown"?S=Math.min(g.length-1,y+1):h.key==="ArrowUp"?S=Math.max(0,y-1):h.key==="Home"?S=0:h.key==="End"&&(S=g.length-1),S<0||S===y)return;h.preventDefault();const k=g[S];for(const x of g)x.tabIndex=-1;k.tabIndex=0,k.focus(),c(k.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(Yr,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function da({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 Rp(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 Vr({pages:e,loading:i,page:n,onPageChange:s,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=oe(),[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?Rp(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(da,{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(da,{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 Tp(e){return e==="lite"||e==="full"}const Gi=[.1,.9],ec=[{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 Ip(e){var i;return((i=ec.find(n=>n.key===e))==null?void 0:i.stack)??null}const Ns={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!1,banxinMode:"cut"},Yt=[15,16,17,18,20,22,24],Gr=18,tc="bim-reader-prefs",qr=3,Mp="bim-reading-mode";function Ap(){const e={...Ns};try{const i=localStorage.getItem(tc),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(Mp))==="paragraph"&&(e.readingMode="paragraph"),n.properNameMode==="off"||n.properNameMode==="lite"||n.properNameMode==="full"?e.properNameMode=n.properNameMode:n.properNames===!0?e.properNameMode="full":n.properNames===!1&&(e.properNameMode="off"),n.writingMode==="vertical"&&(e.writingMode="vertical"),n.workLinks===!1&&(e.workLinks=!1),(n.fontFamily==="kai"||n.fontFamily==="system")&&(e.fontFamily=n.fontFamily);const o=n.v,a=o===2||o===qr;a&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Gi[0]&&n.pageIndicatorY<=Gi[1]&&(e.pageIndicatorY=n.pageIndicatorY),a&&(n.bookTitleStyle==="wavy"||n.bookTitleStyle==="bracket")&&(e.bookTitleStyle=n.bookTitleStyle),n.showWorks===!1&&(e.showWorks=!1),(n.quoteStyle==="modern"||n.quoteStyle==="classic")&&(e.quoteStyle=n.quoteStyle),(n.scriptMode==="orig"||n.scriptMode==="hant"||n.scriptMode==="hans")&&(e.scriptMode=n.scriptMode),o===qr&&typeof n.preserveMargins=="boolean"&&(e.preserveMargins=n.preserveMargins),(n.banxinMode==="full"||n.banxinMode==="none")&&(e.banxinMode=n.banxinMode)}catch{}return e}function Lp(e){try{localStorage.setItem(tc,JSON.stringify({...e,v:qr}))}catch{}}function fn(e,i){const n=e??Gr,s=Yt;let o=s.indexOf(n);return o<0&&(o=s.indexOf(Gr)),s[Math.max(0,Math.min(s.length-1,o+i))]}function ic(){const[e,i]=b.useState(Ns);b.useEffect(()=>{i(Ap())},[]);const n=b.useCallback(s=>{i(o=>{const a={...o,...s};return Lp(a),a})},[]);return[e,n]}function Xr(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 nc(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 rc(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 ma=()=>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"})}),Pp=()=>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"})}),Op=()=>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"})}),ua=()=>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"})]}),pa=()=>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 ba(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 ha(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 Fp({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=oe();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 Bi({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 Bp({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=oe(),a=(s==null?void 0:s.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(Bi,{label:o("reader.script"),value:l,options:[{key:"orig",label:o("reader.scriptOrig"),title:n?void 0:o("reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:d=>{i({scriptMode:d}),d==="hant"?s==null||s.setLocale("zh-Hant"):d==="hans"&&(s==null||s.setLocale("zh-Hans"))}})}function Hp(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 Dp(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 sc({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:S,origScriptAvailable:k=!0,byline:x,current:j,workLinkToggle:v,rail:$,onReportError:_,revisedAt:N,backHref:I,backLabel:D,bottomBar:E=!0,pager:R=!0,contentLoading:O=!1,pagerUnit:M,versions:q,currentVersionKey:P,onVersionChange:le,versionSource:ae=!0,keepChapterOnVersionChange:Ce=!1,customImagePanel:xe,isWarpMode:fe,showPreserveMargins:se=!0,pluginSettings:Re,pluginToolbar:H,pluginOverlay:me,textRootRef:W,children:K,className:re,style:Y}){const{t:T,convert:ue}=oe(),ye=D??T("reader.back"),Ne=ue(M??T("reader.unitJuan")),B=b.useId().replace(/:/g,""),de=`bim-rd-toc-${B}`,Me=`bim-rd-text-${B}`,Se=b.useRef(null),Je=b.useRef(null),X=b.useRef(null),je=b.useRef(null),L=ha($s,!0),G=ha($n,!1),ie=E&&G,[te,ce]=b.useState(null),[be,Fe]=b.useState(!1),Xe=b.useRef(null),Be=`bim-rd-set-${B}`,Ke=b.useRef(null),Ye=b.useRef(null),w=(F,ke)=>{Ye.current=ke,ce(Ze=>Ze===F?null:F)},ee=b.useCallback(()=>{var F;ce(null),(F=Ye.current)==null||F.focus()},[]);b.useEffect(()=>{ie||ce(null)},[ie]),b.useEffect(()=>{var F,ke;te&&((ke=(F=Ke.current)==null?void 0:F.querySelector("button:not([disabled])"))==null||ke.focus())},[te]);const[Z,he]=b.useState("auto"),Le=Z==="auto"?L:Z==="open",C=!L,ge=!!xe||!!c&&c.length>0,[V,ze]=b.useState(h);b.useEffect(()=>{ze(h)},[h]);const we=V==="auto"?ge||!!m:V==="open",Te=b.useCallback(F=>{var ke;he("auto"),F&&((ke=je.current)==null||ke.focus())},[]),tt=()=>he(Le?"closed":"open");b.useEffect(()=>{if(!C||Z!=="open")return;const F=X.current,ke=F==null?void 0:F.querySelector('input, [data-rd-toc-key][tabindex="0"]');ke==null||ke.focus()},[C,Z]);const Pe=b.useCallback(F=>{a(F),C&&Te(!1);const ke=Je.current,Ze=Se.current;if(ke&&Ze&&typeof window<"u"){const Ge=ke.getBoundingClientRect().top-Ze.getBoundingClientRect().bottom;Ge<0&&window.scrollBy({top:Ge})}},[a,C,Te]),it=b.useMemo(()=>rc(n),[n]),[yt,De]=b.useState(null),J=nc(q,P!==void 0?P:yt),ve=(J==null?void 0:J.key)??null,Qe=b.useMemo(()=>it.map(F=>F.key).join(`
|
|
782
|
-
`),[it]),et=b.useRef(null),We=F=>{F!==ve&&(Ce||(et.current={key:F,sig:Qe,done:!1}),P===void 0&&De(F),le==null||le(F))};b.useEffect(()=>{const F=et.current;if(!F||F.key!==ve)return;const ke=it.find(Ge=>!Ge.disabled);if(!ke)return;const Ze=Qe!==F.sig;!Ze&&F.done||(Ze?et.current=null:F.done=!0,ke.key!==s&&Pe(ke.key))},[ve,Qe,it,s,Pe]);const He=it.find(F=>F.key===s),ut=()=>{var F;_==null||_({chapterKey:s,chapterLabel:typeof(He==null?void 0:He.label)=="string"?He.label:void 0,anchor:Hp(Je.current,((F=Se.current)==null?void 0:F.getBoundingClientRect().bottom)??0),selectedText:Dp(Je.current)})},pt=it.findIndex(F=>F.key===s),bt=pt>0?it.slice(0,pt).reverse().find(F=>!F.disabled):void 0,Ue=pt>=0?it.slice(pt+1).find(F=>!F.disabled):void 0,ft=u.fontSize??Gr,Q=Ip(u.fontFamily),A={...Y,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...Q?{"--bimrd-ff":Q}:null},ne={song:T("reader.fontSong"),kai:T("reader.fontKai"),system:T("reader.fontSystem")},$e=F=>(Re??[]).filter(ke=>ke.group===F).map(ke=>t.jsx(b.Fragment,{children:ke.node},ke.key)),Ie=$e("text"),Oe=$e("annotate"),at=$e("layout"),lt=$e("more"),qe=[];for(const F of Re??[]){if(["text","annotate","layout","more"].includes(F.group))continue;let ke=qe.find(Ze=>Ze.group===F.group);ke?ke.title==null&&(ke.title=F.title):qe.push(ke={group:F.group,title:F.title,nodes:[]}),ke.nodes.push(t.jsx(b.Fragment,{children:F.node},F.key))}const Ae=C?[H==null?void 0:H.subtitle,H==null?void 0:H.actions].filter(Boolean):[],Ee=lt.length>0||Ae.length>0,rt=y||Oe.length>0,st=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g1`,children:[t.jsx("h3",{id:`${Be}-g1`,className:"bim-rd-sp-h",children:T("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:T("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":T("reader.font"),value:u.fontFamily,onChange:F=>f({fontFamily:F.target.value}),children:ec.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:T("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:fn(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":T("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:fn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Bp,{prefs:u,onPrefsChange:f,origAvailable:k}),t.jsx(Bi,{label:T("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:T("reader.quoteModern")},{key:"classic",label:T("reader.quoteClassic")},{key:"original",label:T("reader.quoteOriginal")}],onPick:F=>f({quoteStyle:F})}),Ie]}),rt&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g2`,children:[t.jsx("h3",{id:`${Be}-g2`,className:"bim-rd-sp-h",children:T("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Bi,{label:T("reader.properName"),value:u.properNameMode,title:T("reader.properNameTitle"),options:[{key:"off",label:T("reader.properNameOff")},{key:"lite",label:T("reader.properNameLite"),title:T("reader.properNameLiteTitle")},{key:"full",label:T("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:T("reader.showWorks")})]}),t.jsx(Bi,{label:T("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:T("reader.bookTitleWavy")},{key:"bracket",label:T("reader.bookTitleBracket")}],onPick:F=>f({bookTitleStyle:F})})]}),Oe]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g3`,children:[t.jsx("h3",{id:`${Be}-g3`,className:"bim-rd-sp-h",children:T("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:T("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:T("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:T("reader.workLinks")})]}),S&&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:T("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:T("reader.pageBreaks")})]}),se&&!u.preserveMargins&&t.jsx(Bi,{label:T("reader.banxinMode"),value:u.banxinMode,options:[{key:"cut",label:T("reader.banxinCut")},{key:"full",label:T("reader.banxinFull")},{key:"none",label:T("reader.banxinNone")}],onPick:F=>f({banxinMode:F})}),se&&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:T("reader.preserveMargins")})]}),at]}),qe.map((F,ke)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-c${ke}`,children:[t.jsx("h3",{id:`${Be}-c${ke}`,className:"bim-rd-sp-h",children:F.title??F.group}),F.nodes]},F.group)),Ee&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g4`,children:[t.jsx("h3",{id:`${Be}-g4`,className:"bim-rd-sp-h",children:T("reader.groupMore")}),lt,Ae.map((F,ke)=>t.jsx("div",{className:"bim-rd-sp-row",children:F},`tb${ke}`))]})]}),Ve=b.useRef(null);return b.useEffect(()=>{const F=Ve.current;if(!F||!we)return;let ke=0,Ze=-1;const Ge=()=>{ke=0;const Pt=parseFloat(getComputedStyle(F).top);if(!Number.isFinite(Pt))return;const ct=Math.max(0,Math.round(F.getBoundingClientRect().top-Pt));ct!==Ze&&(Ze=ct,F.style.setProperty("--bimrd-img-lead",`${ct}px`))},kt=()=>{ke||(ke=requestAnimationFrame(Ge))};kt(),window.addEventListener("scroll",kt,{passive:!0}),window.addEventListener("resize",kt);const nt=typeof ResizeObserver<"u"?new ResizeObserver(kt):null;return nt==null||nt.observe(document.body),()=>{window.removeEventListener("scroll",kt),window.removeEventListener("resize",kt),nt==null||nt.disconnect(),ke&&cancelAnimationFrame(ke),F.style.removeProperty("--bimrd-img-lead")}},[we]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&S?"bim-rd-vertical":"",re].filter(Boolean).join(" "),"data-toc":Z,"data-img":we?"open":"closed","data-bb":ie?"":void 0,"data-set":!ie&&be?"open":void 0,"data-warp":fe?"true":void 0,style:A,children:[t.jsx("style",{children:Zl}),t.jsx("a",{className:"bim-rd-skip",href:`#${Me}`,onClick:F=>{var ke,Ze,Ge;F.preventDefault(),(ke=Je.current)==null||ke.focus(),(Ge=(Ze=Je.current)==null?void 0:Ze.scrollIntoView)==null||Ge.call(Ze,{block:"start"})},children:T("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:Se,children:[I&&t.jsxs("a",{className:"bim-rd-back",href:I,"aria-label":T("reader.backAria",{label:ye}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:ye})]}),(e||i||x||j||!C&&(H==null?void 0:H.subtitle))&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),x&&t.jsx("span",{className:"bim-rd-by",children:x}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!C&&(H==null?void 0:H.subtitle)&&t.jsx("span",{className:"bim-rd-ttl-src",children:H.subtitle})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":T("reader.settings"),children:[q&&q.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:J?ue(Xr(J)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:T("reader.versionShort")}),t.jsx("select",{"aria-label":T("reader.version"),value:ve??"",onChange:F=>We(F.target.value),children:q.map(F=>t.jsx("option",{value:F.key,children:ue(Xr(F))},F.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),R&&(bt||Ue)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":T("reader.pagerGroup",{unit:Ne}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.prevUnit",{unit:Ne}),title:bt?typeof bt.label=="string"&&bt.label?T("reader.prevUnitTitle",{unit:Ne,label:bt.label}):T("reader.prevUnit",{unit:Ne}):T("reader.firstUnit",{unit:Ne}),disabled:!bt,onClick:()=>bt&&Pe(bt.key),children:t.jsx(Pp,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.nextUnit",{unit:Ne}),title:Ue?typeof Ue.label=="string"&&Ue.label?T("reader.nextUnitTitle",{unit:Ne,label:Ue.label}):T("reader.nextUnit",{unit:Ne}):T("reader.lastUnit",{unit:Ne}),disabled:!Ue,onClick:()=>Ue&&Pe(Ue.key),children:t.jsx(Op,{})})]}),R&&(bt||Ue)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:je,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Le,"aria-controls":de,onClick:tt,children:[t.jsx(ma,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":we,onClick:()=>ze(we?"closed":"open"),children:[t.jsx(pa,{}),T("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Fp,{prefs:u,onPrefsChange:f,origAvailable:k}),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":T("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:fn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":T("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:fn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:Xe,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":be,"aria-controls":Be,onClick:()=>Fe(F=>!F),children:[t.jsx(ua,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.settings")})]}),!C&&(H==null?void 0:H.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:de,ref:X,role:C&&Le?"dialog":void 0,"aria-modal":C&&Le?!0:void 0,"aria-label":C&&Le?T("reader.toc"):void 0,onKeyDown:F=>{if(!(!C||!Le)){if(F.key==="Escape"){F.stopPropagation(),Te(!0);return}F.key==="Tab"&&ba(F,X.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??T("reader.toc")}),C&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeToc"),onClick:()=>Te(!0),children:"✕"})]}),l]}),t.jsx(Ql,{items:n,activeKey:o!==void 0?o:s,onSelect:Pe})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Te(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":T("reader.images"),ref:Ve,children:we&&(xe||t.jsx(Vr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!ie&&be&&t.jsxs("aside",{className:"bim-rd-set",id:Be,"aria-label":T("reader.settings"),onKeyDown:F=>{var ke;F.key==="Escape"&&(F.stopPropagation(),Fe(!1),(ke=Xe.current)==null||ke.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:T("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeSettings"),onClick:()=>{var F;Fe(!1),(F=Xe.current)==null||F.focus()},children:"✕"})]}),st]}),t.jsxs("div",{className:"bim-rd-text",id:Me,ref:F=>{Je.current=F,W&&(W.current=F)},tabIndex:-1,"data-rail":($||_)&&!fe?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[K,ae&&J&&(J.sourceName||J.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":J.key,children:[J.sourceName&&t.jsxs(t.Fragment,{children:[T("reader.sourceLabel")," ",J.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:J.sourceUrl,target:"_blank",rel:"noreferrer",children:ue(J.sourceName)}):ue(J.sourceName)]}),J.sourceName&&J.license&&t.jsx("span",{className:"bim-rd-dot"}),J.license&&t.jsx(t.Fragment,{children:T("reader.licenseOf",{license:J.license})})]}),N&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:T("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:ut,children:T("reader.reportError")})}),R&&!O&&(bt||Ue)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":T("reader.pagerNav"),children:[bt?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Pe(bt.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),T("reader.prevUnit",{unit:Ne})]}),t.jsx("span",{className:"bim-rd-pglabel",children:bt.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",T("reader.firstUnit",{unit:Ne})]}),Ue?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Pe(Ue.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[T("reader.nextUnit",{unit:Ne}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:Ue.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[T("reader.lastUnit",{unit:Ne})," →"]})]})]}),($||_)&&!fe&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":T("reader.rail"),children:[$,_&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:ut,children:T("reader.reportError")})})]})]})]}),ie&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":T("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":Le,"aria-controls":de,onClick:()=>{ce(null),tt()},children:[t.jsx(ma,{}),t.jsx("span",{children:T("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":te==="img","aria-haspopup":"dialog",onClick:F=>w("img",F.currentTarget),children:[t.jsx(pa,{}),t.jsx("span",{children:T("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":te==="set","aria-haspopup":"dialog",onClick:F=>w("set",F.currentTarget),children:[t.jsx(ua,{}),t.jsx("span",{children:T("reader.settingsShort")})]}),_&&t.jsxs("button",{type:"button",onMouseDown:F=>F.preventDefault(),onClick:()=>{ce(null),ut()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:T("reader.reportError")})]})]}),ie&&te&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:ee}),t.jsxs("div",{className:"bim-rd-sheet",ref:Ke,role:"dialog","aria-modal":"true","aria-label":T(te==="img"?"reader.images":"reader.settings"),onKeyDown:F=>{if(F.key==="Escape"){F.stopPropagation(),ee();return}F.key==="Tab"&&ba(F,Ke.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:T(te==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.close"),onClick:ee,children:"✕"})]}),te==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Vr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):st]})]}),me&&t.jsx("div",{className:"bim-rd-overlay",children:me})]})}function Wp(e,i,n){return n?oc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function oc(e){return e.replace(/\r\n/g,`
|
|
781
|
+
`;function _s(e,i){var n;return i?e.key===i?!0:!!((n=e.children)!=null&&n.some(s=>_s(s,i))):!1}const la=()=>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 Ep({item:e,activeKey:i,onSelect:n,tabKey:s}){const{t:o}=oe(),a=_s(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(la,{})}),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(Yr,{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(la,{}),t.jsx("span",{children:e.label}),e.hint!=null&&t.jsx("span",{className:"bim-rd-hint",children:e.hint})]}),l&&t.jsx(Yr,{items:e.children,activeKey:i,onSelect:n,tabKey:s})]})}function Yr({items:e,activeKey:i,onSelect:n,tabKey:s}){return t.jsx("ul",{children:e.map(o=>o.children&&o.children.length>0?t.jsx(Ep,{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 ca(e,i){var n;for(const s of e)if(s.key===i||_s(s,i))return s.key;return((n=e[0])==null?void 0:n.key)??null}function Ql({items:e,activeKey:i,onSelect:n,label:s}){const{t:o}=oe(),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??ca(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===ca(e,i))??u.find(g=>!g.disabled)??u[0];for(const g of u)g.tabIndex=g===f?0:-1}),b.useEffect(()=>{const h=l.current,u=h==null?void 0:h.closest(".bim-rd-toc");if(!h||!u||!i)return;const f=Array.from(h.querySelectorAll("[data-rd-toc-key]")).find(y=>y.dataset.rdTocKey===i);if(!f)return;const g=f.getBoundingClientRect().top-u.getBoundingClientRect().top+u.scrollTop;(g<u.scrollTop+80||g>u.scrollTop+u.clientHeight-40)&&(u.scrollTop=Math.max(0,g-u.clientHeight/3))},[i]);const p=b.useCallback(h=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(h.key))return;const f=l.current;if(!f)return;const g=Array.from(f.querySelectorAll("[data-rd-toc-key]")).filter(x=>!x.disabled),y=g.indexOf(document.activeElement);let v=y;if(h.key==="ArrowDown"?v=Math.min(g.length-1,y+1):h.key==="ArrowUp"?v=Math.max(0,y-1):h.key==="Home"?v=0:h.key==="End"&&(v=g.length-1),v<0||v===y)return;h.preventDefault();const k=g[v];for(const x of g)x.tabIndex=-1;k.tabIndex=0,k.focus(),c(k.dataset.rdTocKey??null)},[]);return t.jsx("div",{ref:l,role:"navigation","aria-label":a,onKeyDown:p,children:t.jsx(Yr,{items:e,activeKey:i,onSelect:n,tabKey:m})})}function da({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 Rp(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 Vr({pages:e,loading:i,page:n,onPageChange:s,renderOverlay:o,preserveMargins:a=!0}){const{t:l}=oe(),[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?Rp(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(da,{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(da,{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 Tp(e){return e==="lite"||e==="full"}const Gi=[.1,.9],ec=[{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 Ip(e){var i;return((i=ec.find(n=>n.key===e))==null?void 0:i.stack)??null}const Ns={fontSize:null,readingMode:"line",properNameMode:null,writingMode:"horizontal",workLinks:!0,fontFamily:"song",pageBreaks:!1,pageIndicatorY:.33,bookTitleStyle:"bracket",showWorks:!0,quoteStyle:"original",scriptMode:null,preserveMargins:!1,banxinMode:"cut"},Yt=[15,16,17,18,20,22,24],Gr=18,tc="bim-reader-prefs",qr=3,Mp="bim-reading-mode";function Ap(){const e={...Ns};try{const i=localStorage.getItem(tc),n=i?JSON.parse(i):{};typeof n.fontSize=="number"&&Yt.includes(n.fontSize)&&(e.fontSize=n.fontSize),(n.readingMode??localStorage.getItem(Mp))==="paragraph"&&(e.readingMode="paragraph"),n.properNameMode==="off"||n.properNameMode==="lite"||n.properNameMode==="full"?e.properNameMode=n.properNameMode:n.properNames===!0?e.properNameMode="full":n.properNames===!1&&(e.properNameMode="off"),n.writingMode==="vertical"&&(e.writingMode="vertical"),n.workLinks===!1&&(e.workLinks=!1),(n.fontFamily==="kai"||n.fontFamily==="system")&&(e.fontFamily=n.fontFamily);const o=n.v,a=o===2||o===qr;a&&typeof n.pageBreaks=="boolean"&&(e.pageBreaks=n.pageBreaks),typeof n.pageIndicatorY=="number"&&Number.isFinite(n.pageIndicatorY)&&n.pageIndicatorY>=Gi[0]&&n.pageIndicatorY<=Gi[1]&&(e.pageIndicatorY=n.pageIndicatorY),a&&(n.bookTitleStyle==="wavy"||n.bookTitleStyle==="bracket")&&(e.bookTitleStyle=n.bookTitleStyle),n.showWorks===!1&&(e.showWorks=!1),(n.quoteStyle==="modern"||n.quoteStyle==="classic")&&(e.quoteStyle=n.quoteStyle),(n.scriptMode==="orig"||n.scriptMode==="hant"||n.scriptMode==="hans")&&(e.scriptMode=n.scriptMode),o===qr&&typeof n.preserveMargins=="boolean"&&(e.preserveMargins=n.preserveMargins),(n.banxinMode==="full"||n.banxinMode==="none")&&(e.banxinMode=n.banxinMode)}catch{}return e}function Lp(e){try{localStorage.setItem(tc,JSON.stringify({...e,v:qr}))}catch{}}function fn(e,i){const n=e??Gr,s=Yt;let o=s.indexOf(n);return o<0&&(o=s.indexOf(Gr)),s[Math.max(0,Math.min(s.length-1,o+i))]}function ic(){const[e,i]=b.useState(Ns);b.useEffect(()=>{i(Ap())},[]);const n=b.useCallback(s=>{i(o=>{const a={...o,...s};return Lp(a),a})},[]);return[e,n]}function Xr(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 nc(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 rc(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 ma=()=>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"})}),Pp=()=>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"})}),Op=()=>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"})}),ua=()=>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"})]}),pa=()=>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 ba(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 ha(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 Fp({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=oe();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 Bi({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 Bp({prefs:e,onPrefsChange:i,origAvailable:n}){const s=b.useContext(r.LocaleContext),{t:o}=oe(),a=(s==null?void 0:s.locale)==="zh-Hans"?"hans":"hant",l=e.scriptMode==="orig"?"orig":a;return t.jsx(Bi,{label:o("reader.script"),value:l,options:[{key:"orig",label:o("reader.scriptOrig"),title:n?void 0:o("reader.scriptOrigUnavailable"),disabled:!n},{key:"hant",label:o("reader.scriptHant")},{key:"hans",label:o("reader.scriptHans")}],onPick:d=>{i({scriptMode:d}),d==="hant"?s==null||s.setLocale("zh-Hant"):d==="hans"&&(s==null||s.setLocale("zh-Hans"))}})}function Hp(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 Dp(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 sc({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:v,origScriptAvailable:k=!0,byline:x,current:j,workLinkToggle:S,rail:$,onReportError:_,revisedAt:N,backHref:I,backLabel:D,bottomBar:E=!0,pager:R=!0,contentLoading:O=!1,pagerUnit:M,versions:q,currentVersionKey:P,onVersionChange:le,versionSource:ae=!0,keepChapterOnVersionChange:Ce=!1,customImagePanel:xe,isWarpMode:fe,showPreserveMargins:se=!0,pluginSettings:Re,pluginToolbar:H,pluginOverlay:me,textRootRef:W,children:K,className:re,style:Y}){const{t:T,convert:ue}=oe(),ye=D??T("reader.back"),Ne=ue(M??T("reader.unitJuan")),B=b.useId().replace(/:/g,""),de=`bim-rd-toc-${B}`,Me=`bim-rd-text-${B}`,Se=b.useRef(null),Je=b.useRef(null),X=b.useRef(null),je=b.useRef(null),L=ha($s,!0),G=ha($n,!1),ie=E&&G,[te,ce]=b.useState(null),[be,Fe]=b.useState(!1),Xe=b.useRef(null),Be=`bim-rd-set-${B}`,Ke=b.useRef(null),Ye=b.useRef(null),w=(F,ke)=>{Ye.current=ke,ce(Ze=>Ze===F?null:F)},ee=b.useCallback(()=>{var F;ce(null),(F=Ye.current)==null||F.focus()},[]);b.useEffect(()=>{ie||ce(null)},[ie]),b.useEffect(()=>{var F,ke;te&&((ke=(F=Ke.current)==null?void 0:F.querySelector("button:not([disabled])"))==null||ke.focus())},[te]);const[Z,he]=b.useState("auto"),Le=Z==="auto"?L:Z==="open",C=!L,ge=!!xe||!!c&&c.length>0,[V,ze]=b.useState(h);b.useEffect(()=>{ze(h)},[h]);const we=V==="auto"?ge||!!m:V==="open",Te=b.useCallback(F=>{var ke;he("auto"),F&&((ke=je.current)==null||ke.focus())},[]),tt=()=>he(Le?"closed":"open");b.useEffect(()=>{if(!C||Z!=="open")return;const F=X.current,ke=F==null?void 0:F.querySelector('input, [data-rd-toc-key][tabindex="0"]');ke==null||ke.focus()},[C,Z]);const Pe=b.useCallback(F=>{a(F),C&&Te(!1);const ke=Je.current,Ze=Se.current;if(ke&&Ze&&typeof window<"u"){const Ge=ke.getBoundingClientRect().top-Ze.getBoundingClientRect().bottom;Ge<0&&window.scrollBy({top:Ge})}},[a,C,Te]),it=b.useMemo(()=>rc(n),[n]),[yt,De]=b.useState(null),J=nc(q,P!==void 0?P:yt),ve=(J==null?void 0:J.key)??null,Qe=b.useMemo(()=>it.map(F=>F.key).join(`
|
|
782
|
+
`),[it]),et=b.useRef(null),We=F=>{F!==ve&&(Ce||(et.current={key:F,sig:Qe,done:!1}),P===void 0&&De(F),le==null||le(F))};b.useEffect(()=>{const F=et.current;if(!F||F.key!==ve)return;const ke=it.find(Ge=>!Ge.disabled);if(!ke)return;const Ze=Qe!==F.sig;!Ze&&F.done||(Ze?et.current=null:F.done=!0,ke.key!==s&&Pe(ke.key))},[ve,Qe,it,s,Pe]);const He=it.find(F=>F.key===s),ut=()=>{var F;_==null||_({chapterKey:s,chapterLabel:typeof(He==null?void 0:He.label)=="string"?He.label:void 0,anchor:Hp(Je.current,((F=Se.current)==null?void 0:F.getBoundingClientRect().bottom)??0),selectedText:Dp(Je.current)})},pt=it.findIndex(F=>F.key===s),bt=pt>0?it.slice(0,pt).reverse().find(F=>!F.disabled):void 0,Ue=pt>=0?it.slice(pt+1).find(F=>!F.disabled):void 0,ft=u.fontSize??Gr,Q=Ip(u.fontFamily),A={...Y,...u.fontSize?{"--bimrd-fs":`${u.fontSize}px`}:null,...Q?{"--bimrd-ff":Q}:null},ne={song:T("reader.fontSong"),kai:T("reader.fontKai"),system:T("reader.fontSystem")},$e=F=>(Re??[]).filter(ke=>ke.group===F).map(ke=>t.jsx(b.Fragment,{children:ke.node},ke.key)),Ie=$e("text"),Oe=$e("annotate"),at=$e("layout"),lt=$e("more"),qe=[];for(const F of Re??[]){if(["text","annotate","layout","more"].includes(F.group))continue;let ke=qe.find(Ze=>Ze.group===F.group);ke?ke.title==null&&(ke.title=F.title):qe.push(ke={group:F.group,title:F.title,nodes:[]}),ke.nodes.push(t.jsx(b.Fragment,{children:F.node},F.key))}const Ae=C?[H==null?void 0:H.subtitle,H==null?void 0:H.actions].filter(Boolean):[],Ee=lt.length>0||Ae.length>0,rt=y||Oe.length>0,st=t.jsxs("div",{className:"bim-rd-sp",children:[t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g1`,children:[t.jsx("h3",{id:`${Be}-g1`,className:"bim-rd-sp-h",children:T("reader.groupText")}),t.jsxs("div",{className:"bim-rd-sp-row",children:[t.jsx("span",{className:"bim-rd-sp-l",children:T("reader.font")}),t.jsx("select",{className:"bim-rd-sp-sel","aria-label":T("reader.font"),value:u.fontFamily,onChange:F=>f({fontFamily:F.target.value}),children:ec.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:T("reader.fontSize")}),t.jsxs("span",{className:"bim-rd-sp-fs",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:fn(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":T("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:fn(u.fontSize,1)}),children:"A+"})]})]}),t.jsx(Bp,{prefs:u,onPrefsChange:f,origAvailable:k}),t.jsx(Bi,{label:T("reader.quoteStyle"),value:u.quoteStyle,options:[{key:"modern",label:T("reader.quoteModern")},{key:"classic",label:T("reader.quoteClassic")},{key:"original",label:T("reader.quoteOriginal")}],onPick:F=>f({quoteStyle:F})}),Ie]}),rt&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g2`,children:[t.jsx("h3",{id:`${Be}-g2`,className:"bim-rd-sp-h",children:T("reader.groupMark")}),y&&t.jsxs(t.Fragment,{children:[t.jsx(Bi,{label:T("reader.properName"),value:u.properNameMode,title:T("reader.properNameTitle"),options:[{key:"off",label:T("reader.properNameOff")},{key:"lite",label:T("reader.properNameLite"),title:T("reader.properNameLiteTitle")},{key:"full",label:T("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:T("reader.showWorks")})]}),t.jsx(Bi,{label:T("reader.bookTitleStyle"),value:u.bookTitleStyle,options:[{key:"wavy",label:T("reader.bookTitleWavy")},{key:"bracket",label:T("reader.bookTitleBracket")}],onPick:F=>f({bookTitleStyle:F})})]}),Oe]}),t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g3`,children:[t.jsx("h3",{id:`${Be}-g3`,className:"bim-rd-sp-h",children:T("reader.groupLayout")}),g&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.readingMode==="paragraph",title:T("reader.paragraphTitle"),onClick:()=>f({readingMode:u.readingMode==="paragraph"?"line":"paragraph"}),children:T("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:F=>f({workLinks:F.target.checked})}),t.jsx("span",{children:T("reader.workLinks")})]}),v&&t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-sp-tg","aria-pressed":u.writingMode==="vertical",onClick:()=>f({writingMode:u.writingMode==="vertical"?"horizontal":"vertical"}),children:T("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:T("reader.pageBreaks")})]}),se&&!u.preserveMargins&&t.jsx(Bi,{label:T("reader.banxinMode"),value:u.banxinMode,options:[{key:"cut",label:T("reader.banxinCut")},{key:"full",label:T("reader.banxinFull")},{key:"none",label:T("reader.banxinNone")}],onPick:F=>f({banxinMode:F})}),se&&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:T("reader.preserveMargins")})]}),at]}),qe.map((F,ke)=>t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-c${ke}`,children:[t.jsx("h3",{id:`${Be}-c${ke}`,className:"bim-rd-sp-h",children:F.title??F.group}),F.nodes]},F.group)),Ee&&t.jsxs("section",{className:"bim-rd-sp-g","aria-labelledby":`${Be}-g4`,children:[t.jsx("h3",{id:`${Be}-g4`,className:"bim-rd-sp-h",children:T("reader.groupMore")}),lt,Ae.map((F,ke)=>t.jsx("div",{className:"bim-rd-sp-row",children:F},`tb${ke}`))]})]}),Ve=b.useRef(null);return b.useEffect(()=>{const F=Ve.current;if(!F||!we)return;let ke=0,Ze=-1;const Ge=()=>{ke=0;const Pt=parseFloat(getComputedStyle(F).top);if(!Number.isFinite(Pt))return;const ct=Math.max(0,Math.round(F.getBoundingClientRect().top-Pt));ct!==Ze&&(Ze=ct,F.style.setProperty("--bimrd-img-lead",`${ct}px`))},kt=()=>{ke||(ke=requestAnimationFrame(Ge))};kt(),window.addEventListener("scroll",kt,{passive:!0}),window.addEventListener("resize",kt);const nt=typeof ResizeObserver<"u"?new ResizeObserver(kt):null;return nt==null||nt.observe(document.body),()=>{window.removeEventListener("scroll",kt),window.removeEventListener("resize",kt),nt==null||nt.disconnect(),ke&&cancelAnimationFrame(ke),F.style.removeProperty("--bimrd-img-lead")}},[we]),t.jsxs("div",{className:["bim-rd",u.writingMode==="vertical"&&v?"bim-rd-vertical":"",re].filter(Boolean).join(" "),"data-toc":Z,"data-img":we?"open":"closed","data-bb":ie?"":void 0,"data-set":!ie&&be?"open":void 0,"data-warp":fe?"true":void 0,style:A,children:[t.jsx("style",{children:Zl}),t.jsx("a",{className:"bim-rd-skip",href:`#${Me}`,onClick:F=>{var ke,Ze,Ge;F.preventDefault(),(ke=Je.current)==null||ke.focus(),(Ge=(Ze=Je.current)==null?void 0:Ze.scrollIntoView)==null||Ge.call(Ze,{block:"start"})},children:T("reader.skipToText")}),t.jsxs("div",{className:"bim-rd-bar",ref:Se,children:[I&&t.jsxs("a",{className:"bim-rd-back",href:I,"aria-label":T("reader.backAria",{label:ye}),children:[t.jsx("span",{"aria-hidden":"true",children:"‹"}),t.jsx("span",{className:"bim-rd-tlabel","aria-hidden":"true",children:ye})]}),(e||i||x||j||!C&&(H==null?void 0:H.subtitle))&&t.jsxs("p",{className:"bim-rd-ttl",style:{margin:0},children:[e&&t.jsx("b",{children:e}),x&&t.jsx("span",{className:"bim-rd-by",children:x}),j&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-rd-cur",children:j})]}),i&&t.jsx("span",{className:"bim-rd-ttl-src",children:i}),!C&&(H==null?void 0:H.subtitle)&&t.jsx("span",{className:"bim-rd-ttl-src",children:H.subtitle})]}),t.jsxs("div",{className:"bim-rd-tools",role:"group","aria-label":T("reader.settings"),children:[q&&q.length>1&&t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"bim-rd-ver",title:J?ue(Xr(J)):void 0,children:[t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.version")}),t.jsx("span",{className:"bim-rd-ver-short","aria-hidden":"true",children:T("reader.versionShort")}),t.jsx("select",{"aria-label":T("reader.version"),value:ve??"",onChange:F=>We(F.target.value),children:q.map(F=>t.jsx("option",{value:F.key,children:ue(Xr(F))},F.key))})]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"})]}),R&&(bt||Ue)&&t.jsxs("span",{className:"bim-rd-nav bim-rd-hide-narrow",role:"group","aria-label":T("reader.pagerGroup",{unit:Ne}),children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.prevUnit",{unit:Ne}),title:bt?typeof bt.label=="string"&&bt.label?T("reader.prevUnitTitle",{unit:Ne,label:bt.label}):T("reader.prevUnit",{unit:Ne}):T("reader.firstUnit",{unit:Ne}),disabled:!bt,onClick:()=>bt&&Pe(bt.key),children:t.jsx(Pp,{})}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.nextUnit",{unit:Ne}),title:Ue?typeof Ue.label=="string"&&Ue.label?T("reader.nextUnitTitle",{unit:Ne,label:Ue.label}):T("reader.nextUnit",{unit:Ne}):T("reader.lastUnit",{unit:Ne}),disabled:!Ue,onClick:()=>Ue&&Pe(Ue.key),children:t.jsx(Op,{})})]}),R&&(bt||Ue)&&t.jsx("span",{className:"bim-rd-sep bim-rd-hide-narrow","aria-hidden":"true"}),t.jsxs("button",{ref:je,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":Le,"aria-controls":de,onClick:tt,children:[t.jsx(ma,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.toc")})]}),t.jsxs("button",{type:"button",className:"bim-rd-t bim-rd-hide-narrow","aria-pressed":we,onClick:()=>ze(we?"closed":"open"),children:[t.jsx(pa,{}),T("reader.images")]}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsx(Fp,{prefs:u,onPrefsChange:f,origAvailable:k}),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":T("reader.fontSmaller"),disabled:ft<=Yt[0],onClick:()=>f({fontSize:fn(u.fontSize,-1)}),children:"A−"}),t.jsx("button",{type:"button",className:"bim-rd-t bim-rd-fs bim-rd-bb-dup","aria-label":T("reader.fontLarger"),disabled:ft>=Yt[Yt.length-1],onClick:()=>f({fontSize:fn(u.fontSize,1)}),children:"A+"}),t.jsx("span",{className:"bim-rd-sep","aria-hidden":"true"}),t.jsxs("button",{ref:Xe,type:"button",className:"bim-rd-t bim-rd-bb-dup","aria-expanded":be,"aria-controls":Be,onClick:()=>Fe(F=>!F),children:[t.jsx(ua,{}),t.jsx("span",{className:"bim-rd-tlabel",children:T("reader.settings")})]}),!C&&(H==null?void 0:H.actions)]})]}),t.jsxs("div",{className:"bim-rd-body",children:[t.jsxs("div",{className:"bim-rd-toc",id:de,ref:X,role:C&&Le?"dialog":void 0,"aria-modal":C&&Le?!0:void 0,"aria-label":C&&Le?T("reader.toc"):void 0,onKeyDown:F=>{if(!(!C||!Le)){if(F.key==="Escape"){F.stopPropagation(),Te(!0);return}F.key==="Tab"&&ba(F,X.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??T("reader.toc")}),C&&t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeToc"),onClick:()=>Te(!0),children:"✕"})]}),l]}),t.jsx(Ql,{items:n,activeKey:o!==void 0?o:s,onSelect:Pe})]}),t.jsx("div",{className:"bim-rd-scrim","aria-hidden":"true",onClick:()=>Te(!0)}),t.jsx("aside",{className:"bim-rd-img","aria-label":T("reader.images"),ref:Ve,children:we&&(xe||t.jsx(Vr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins}))}),!ie&&be&&t.jsxs("aside",{className:"bim-rd-set",id:Be,"aria-label":T("reader.settings"),onKeyDown:F=>{var ke;F.key==="Escape"&&(F.stopPropagation(),Fe(!1),(ke=Xe.current)==null||ke.focus())},children:[t.jsxs("div",{className:"bim-rd-sp-top",children:[t.jsx("span",{children:T("reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.closeSettings"),onClick:()=>{var F;Fe(!1),(F=Xe.current)==null||F.focus()},children:"✕"})]}),st]}),t.jsxs("div",{className:"bim-rd-text",id:Me,ref:F=>{Je.current=F,W&&(W.current=F)},tabIndex:-1,"data-rail":($||_)&&!fe?"true":void 0,children:[t.jsxs("div",{className:"bim-rd-col",children:[K,ae&&J&&(J.sourceName||J.license)&&t.jsxs("p",{className:"bim-rd-src","data-version":J.key,children:[J.sourceName&&t.jsxs(t.Fragment,{children:[T("reader.sourceLabel")," ",J.sourceUrl?t.jsx("a",{className:"bim-rd-link",href:J.sourceUrl,target:"_blank",rel:"noreferrer",children:ue(J.sourceName)}):ue(J.sourceName)]}),J.sourceName&&J.license&&t.jsx("span",{className:"bim-rd-dot"}),J.license&&t.jsx(t.Fragment,{children:T("reader.licenseOf",{license:J.license})})]}),N&&t.jsx("p",{className:"bim-rd-src bim-rd-rev",children:T("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:ut,children:T("reader.reportError")})}),R&&!O&&(bt||Ue)&&t.jsxs("nav",{className:"bim-rd-pager","aria-label":T("reader.pagerNav"),children:[bt?t.jsxs("button",{type:"button",className:"bim-rd-pg",onClick:()=>Pe(bt.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[t.jsx("span",{"aria-hidden":"true",children:"← "}),T("reader.prevUnit",{unit:Ne})]}),t.jsx("span",{className:"bim-rd-pglabel",children:bt.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-end","aria-hidden":"true",children:["← ",T("reader.firstUnit",{unit:Ne})]}),Ue?t.jsxs("button",{type:"button",className:"bim-rd-pg bim-rd-pg-next",onClick:()=>Pe(Ue.key),children:[t.jsxs("span",{className:"bim-rd-pgcap",children:[T("reader.nextUnit",{unit:Ne}),t.jsx("span",{"aria-hidden":"true",children:" →"})]}),t.jsx("span",{className:"bim-rd-pglabel",children:Ue.label})]}):t.jsxs("span",{className:"bim-rd-pg bim-rd-pg-next bim-rd-pg-end","aria-hidden":"true",children:[T("reader.lastUnit",{unit:Ne})," →"]})]})]}),($||_)&&!fe&&t.jsxs("aside",{className:"bim-rd-rail","aria-label":T("reader.rail"),children:[$,_&&t.jsx("div",{className:"bim-rd-rail-acts",children:t.jsx("button",{type:"button",className:"bim-rd-rail-report",onMouseDown:F=>F.preventDefault(),onClick:ut,children:T("reader.reportError")})})]})]})]}),ie&&t.jsxs("nav",{className:"bim-rd-bb","aria-label":T("reader.bottomBar"),children:[t.jsxs("button",{type:"button","aria-expanded":Le,"aria-controls":de,onClick:()=>{ce(null),tt()},children:[t.jsx(ma,{}),t.jsx("span",{children:T("reader.tocShort")})]}),t.jsxs("button",{type:"button","aria-expanded":te==="img","aria-haspopup":"dialog",onClick:F=>w("img",F.currentTarget),children:[t.jsx(pa,{}),t.jsx("span",{children:T("reader.images")})]}),t.jsxs("button",{type:"button","aria-expanded":te==="set","aria-haspopup":"dialog",onClick:F=>w("set",F.currentTarget),children:[t.jsx(ua,{}),t.jsx("span",{children:T("reader.settingsShort")})]}),_&&t.jsxs("button",{type:"button",onMouseDown:F=>F.preventDefault(),onClick:()=>{ce(null),ut()},children:[t.jsx("span",{className:"bim-rd-bb-ic","aria-hidden":"true",children:"!"}),t.jsx("span",{children:T("reader.reportError")})]})]}),ie&&te&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-rd-sheet-scrim","aria-hidden":"true",onClick:ee}),t.jsxs("div",{className:"bim-rd-sheet",ref:Ke,role:"dialog","aria-modal":"true","aria-label":T(te==="img"?"reader.images":"reader.settings"),onKeyDown:F=>{if(F.key==="Escape"){F.stopPropagation(),ee();return}F.key==="Tab"&&ba(F,Ke.current)},children:[t.jsxs("div",{className:"bim-rd-sheet-head",children:[t.jsx("span",{children:T(te==="img"?"reader.images":"reader.settings")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":T("reader.close"),onClick:ee,children:"✕"})]}),te==="img"?t.jsx("div",{className:"bim-rd-sheet-img",children:t.jsx(Vr,{pages:c??null,loading:m,renderOverlay:p,preserveMargins:u.preserveMargins})}):st]})]}),me&&t.jsx("div",{className:"bim-rd-overlay",children:me})]})}function Wp(e,i,n){return n?oc(e).includes("\r")?"lone-cr":Array.from(e).length!==Array.from(i).length?"convert-length":i.includes(":::")?"tables":null:"quoteStyle"}function oc(e){return e.replace(/\r\n/g,`
|
|
783
783
|
`)}const fa=2,Up=400,Kp=6,ac=e=>e==="*"||e==="#"||e==="<"||e===">"||/\s/.test(e);function lc(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 Yp(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=lc(e,s);if(a>=0){s=a+1;continue}if(ac(e[s])){s++;continue}if(n[o]===" "){o++;continue}return-1}return s}function Vp(e){const i=Array.from(oc(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>=Kp;let l=0;for(let d=n;d<i.length&&d-n<=(a?Up:fa+64);d++){const c=lc(i,d);if(c>=0){d=c;continue}if(!ac(i[d])){const p=Yp(i,d,o);if(p>=0)return n=p,d;if(l++,!a&&l>fa)return}}}}}const Gp=65536,qp="guji_markdown";function Xp(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 Jp=/^□\{guess=([^\s{}]+)\}/;function Zp(e,i){const n=e[i+1];return n!==void 0&&!/[A-Za-z/!?>\s]/.test(n)}function cc(e,i){let n=0;for(let s=i;s<e.length;s++){const o=e[s];if(o===`
|
|
784
784
|
`)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 eb(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(`
|
|
785
785
|
`)<0?{node:{type:"qw",label:e.slice(i+2,s)},end:s+2}:null}if(n===":"&&e.startsWith(":zi[",i)){const s=cc(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=Jp.exec(e.slice(i,i+64));if(s)return{node:{type:"qz",guess:s[1]},end:i+s[0].length}}return null}function dc(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===`
|
|
@@ -907,6 +907,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
907
907
|
.bim-d-lu-pager button:disabled { cursor: default; }
|
|
908
908
|
.bim-d-lu-pager button:not(:disabled):hover { text-decoration: underline; text-underline-offset: 3px; }
|
|
909
909
|
.bim-d-lu-body { padding: 18px 22px 14px; min-width: 0; border-radius: 10px; background: ${r.bim("card-bg")}; }
|
|
910
|
+
.bim-d-lu-entry + .bim-d-lu-entry { margin-top: 20px; padding-top: 16px; border-top: 1px solid ${r.bim("rule-strong")}; }
|
|
910
911
|
.bim-d-lu-title { font-size: 17px; font-weight: 700; color: ${r.bim("ink")}; }
|
|
911
912
|
.bim-d-quote { margin: 14px 0 0; font-family: ${r.bim("font-serif")}; font-size: 17px; line-height: 2;
|
|
912
913
|
color: ${r.bim("ink")}; text-align: justify; }
|
|
@@ -1307,7 +1308,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1307
1308
|
: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 {
|
|
1308
1309
|
text-decoration-color: currentColor; text-decoration-thickness: 2px;
|
|
1309
1310
|
}
|
|
1310
|
-
`;function Zi({railTop:e,back:i,up:n,nav:s,railLinks:o,main:a,card:l,side:d}){const{t:c,convert:m}=oe(),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 pc({caption:e,children:i}){const{convert:n}=oe();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:n(e)}),i]})}function _t({id:e,title:i,meta:n,action:s,children:o}){const{convert:a}=oe();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:a(i)}),n!=null&&n!==""&&t.jsx("span",{className:"bim-d-meta",children:n}),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 qn({items:e,value:i,onChange:n}){const{convert:s}=oe();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 bc({label:e,checked:i,onChange:n}){const{convert:s}=oe();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 hc=6,Xn=e=>e>hc+1;function zs({total:e,shown:i,unit:n,onClick:s}){const{t:o,convert:a}=oe(),l=e-i,d=Xn(e)?e-Math.min(i,hc):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 Cs({label:e,onClick:i}){const{convert:n}=oe();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:i,children:n(e)})}function Qi({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}=oe(),y=(d||[]).filter(
|
|
1311
|
+
`;function Zi({railTop:e,back:i,up:n,nav:s,railLinks:o,main:a,card:l,side:d}){const{t:c,convert:m}=oe(),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 pc({caption:e,children:i}){const{convert:n}=oe();return t.jsxs("div",{className:"bim-d-up bim-d-ui",children:[t.jsx("span",{className:"bim-d-up-cap",children:n(e)}),i]})}function _t({id:e,title:i,meta:n,action:s,children:o}){const{convert:a}=oe();return t.jsxs("section",{id:e,className:"bim-d-sec",children:[t.jsxs("div",{className:"bim-d-sec-head bim-d-ui",children:[t.jsx("h2",{children:a(i)}),n!=null&&n!==""&&t.jsx("span",{className:"bim-d-meta",children:n}),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 qn({items:e,value:i,onChange:n}){const{convert:s}=oe();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 bc({label:e,checked:i,onChange:n}){const{convert:s}=oe();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 hc=6,Xn=e=>e>hc+1;function zs({total:e,shown:i,unit:n,onClick:s}){const{t:o,convert:a}=oe(),l=e-i,d=Xn(e)?e-Math.min(i,hc):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 Cs({label:e,onClick:i}){const{convert:n}=oe();return t.jsx("button",{type:"button",className:"bim-d-more bim-d-ui",onClick:i,children:n(e)})}function Qi({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}=oe(),y=(d||[]).filter(S=>S.value!=null&&S.value!==""),v=(c||[]).filter(S=>S.value!=null&&S.value!==""&&S.value!==0),[k,x]=b.useState(!1),j=!!l&&!k;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:j?"bim-d-card-desc bim-d-clamp":"bim-d-card-desc",style:j?{"--detail-clamp":l}:void 0,children:a}),a&&!!l&&t.jsx("button",{type:"button",className:"bim-d-card-toggle bim-d-ui","aria-expanded":k,onClick:()=>x(S=>!S),children:f(k?"action.collapse":"action.expand")}),v.length>0&&t.jsx("div",{className:"bim-d-stats bim-d-ui",children:v.map((S,$)=>t.jsxs("div",{children:[t.jsx("b",{children:S.value}),t.jsx("span",{children:g(S.label)})]},$))}),y.length>0&&t.jsx("dl",{className:"bim-d-ui",children:y.map((S,$)=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:g(S.label)}),t.jsx("dd",{title:S.title,children:S.value})]},$))}),h,m,p,u&&t.jsx("div",{className:"bim-d-card-foot bim-d-ui",children:u})]})}function Es(e){return!!e&&[...e.replace(/\s+/g,"")].length>110}function Zr({href:e,onClick:i,label:n}){const{t:s,convert:o}=oe(),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}=oe(),[f,g]=b.useState(!1);if(!s.length)return null;const y=f?s:s.slice(0,l),v=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((k,x)=>t.jsxs("li",{className:x===a?"bim-d-side-cur":void 0,"aria-current":x===a?"page":void 0,children:[k,o!=null&&o[x]?t.jsx("span",{className:"bim-d-meta",style:{marginLeft:"auto"},children:o[x]}):null]},x))}),v>0&&t.jsx(Cs,{label:d?d(v):h("detail.showMore",{n:v}),onClick:()=>g(!0)}),c&&t.jsx("p",{className:"bim-d-side-note bim-d-ui",children:c})]})}const ob=new Set(["reviewed","disputed","unreviewed","draft"]);function en({revision:e,revisedAt:i,review:n,todo:s}){const{t:o,convert:a}=oe(),l=n&&ob.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,xa=208,ab=1440,lb="(max-width: 719px)",fc=`
|
|
1311
1312
|
.bim-d-page {
|
|
1312
1313
|
background: ${r.bim("page-bg")};
|
|
1313
1314
|
color: ${r.bim("ink")};
|
|
@@ -1403,7 +1404,7 @@ a.bim-d-flag:hover { text-decoration: none !important; background: ${r.bim("tint
|
|
|
1403
1404
|
}
|
|
1404
1405
|
}
|
|
1405
1406
|
${sb}`;function Hi({children:e,style:i,wide:n,grid:s}){return t.jsxs("div",{className:"bim-d-page",style:i,children:[t.jsx("style",{children:fc}),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 Qr({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 Rs({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 es({items:e}){const i=It();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 gc({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 cb({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 db({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 mb({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(Rs,{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 xc({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 ub({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 pb({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 yc({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 bb({children:e}){return t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:e})}function hb({volumes:e,unit:i,max:n=60}){const{t:s}=oe(),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 fb({children:e}){return t.jsx("div",{style:{borderTop:`1px solid ${r.bim("rule-strong")}`},children:e})}function gb({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 xb({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 yb(e){return String(e+1).padStart(2,"0")}function jb(){return t.jsx("span",{style:{color:r.bim("hint-fg")},children:"—"})}function kb({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 jc(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(`
|
|
1406
|
-
`)||(i.push({start:n,end:l+1,inner:d}),n=l)}return i}function kc(e,i){if(e.length<=i)return e;let n=i;for(const s of jc(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 wc={fontSize:".78em",color:r.bim("meta-fg"),lineHeight:1.55},wb={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 vc(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?wc:void 0,children:vc(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:wb,children:o.label},a)}})}function Lt(e,i=s=>s,n){if(!e)return"";if(n!=null&&n.gujiMarkdown)return tb(e)?vc(mc(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 jc(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:wc,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 vb({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 Sb({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 Sc({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 $b({item:e,siblings:i,showVolumes:n=!0,fallbackNote:s}){const{t:o,convert:a}=oe(),[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?Cl(e,i):"",u=h?`${p}(${h})`:p;return t.jsx(Sc,{name:u,note:Wn(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(Ts,{item:e})]}):void 0})}function Ts({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 $c({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(yc,{children:n(s)},o))]}):null}function _b({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($c,{label:n.label,items:n.items},n.label))}):null}function _c(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function Nc({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 Nb({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=It();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 zb({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 zc="guji-table-v1";function Cb(e){return!!e&&e.table_notation===zc}const Eb=/^:::table(?:\{[^}]*\})?[ \t]*$/,Rb=/^:::[ \t]*$/;function Cc(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=cc(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 Tb=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Ib(e){if(e==="^")return{cont:!0};const i=Tb.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 Ec(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=Cc(p).map(Ib),f=a.map(k=>k>0),g=a.map(k=>k>0?k-1:0),y=[];let
|
|
1407
|
+
`)||(i.push({start:n,end:l+1,inner:d}),n=l)}return i}function kc(e,i){if(e.length<=i)return e;let n=i;for(const s of jc(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 wc={fontSize:".78em",color:r.bim("meta-fg"),lineHeight:1.55},wb={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 vc(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?wc:void 0,children:vc(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:wb,children:o.label},a)}})}function Lt(e,i=s=>s,n){if(!e)return"";if(n!=null&&n.gujiMarkdown)return tb(e)?vc(mc(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 jc(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:wc,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 vb({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 Sb({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 Sc({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 $b({item:e,siblings:i,showVolumes:n=!0,fallbackNote:s}){const{t:o,convert:a}=oe(),[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?Cl(e,i):"",u=h?`${p}(${h})`:p;return t.jsx(Sc,{name:u,note:Wn(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(Ts,{item:e})]}):void 0})}function Ts({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 $c({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(yc,{children:n(s)},o))]}):null}function _b({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($c,{label:n.label,items:n.items},n.label))}):null}function _c(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function Nc({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 Nb({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=It();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 zb({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 zc="guji-table-v1";function Cb(e){return!!e&&e.table_notation===zc}const Eb=/^:::table(?:\{[^}]*\})?[ \t]*$/,Rb=/^:::[ \t]*$/;function Cc(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=cc(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 Tb=/^([\s\S]*?)(?:\{(\d+)\})?(?:\^(\d+))?$/;function Ib(e){if(e==="^")return{cont:!0};const i=Tb.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 Ec(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=Cc(p).map(Ib),f=a.map(k=>k>0),g=a.map(k=>k>0?k-1:0),y=[];let v=0;for(const k of u){if(k.cont){f[v]||n.push(`第 ${m} 行第 ${v+1} 列:续格 ^ 上方没有跨行格`),v+=1;continue}const{cell:x}=k;for(let j=v;j<v+x.colspan;j++)if(f[j]){n.push(`第 ${m} 行第 ${j+1} 列:此处被上方跨行格占住,应写 ^`);break}if(x.rowspan>1)for(let j=v;j<v+x.colspan;j++)g[j]=x.rowspan-1;y.push(x),v+=x.colspan}for(let k=v;k<f.length;k++)f[k]&&n.push(`第 ${m} 行第 ${k+1} 列:被上方跨行格占住,但本行缺续格 ^`);for(let k=0;k<g.length;k++)g[k]===void 0&&(g[k]=0);a=g,s.push({header:h,cells:y}),o.push({width:v,line:m})});const l=o.reduce((d,c)=>Math.max(d,c.width),0);for(const d of o)d.width!==l&&n.push(`第 ${d.line} 行:占 ${d.width} 列,与总列数 ${l} 不符`);return a.some(d=>d>0)&&n.push("表尾:有跨行格超出了表的最后一行"),s.length===0&&n.push("空表"),{rows:s,columns:l,warnings:n}}function Is(e){const i=e.split(`
|
|
1407
1408
|
`),n=[];let s=[];const o=()=>{if(s.length===0)return;const l=s.join(`
|
|
1408
1409
|
`);s=[],n.push({type:"text",text:l})};let a=0;for(;a<i.length;){if(Eb.test(i[a].trim())){let l=a+1;for(;l<i.length&&!Rb.test(i[l].trim());)l++;if(l<i.length){o();const d=i.slice(a+1,l);n.push({type:"table",table:Ec(d,a+1),source:i.slice(a,l+1).join(`
|
|
1409
1410
|
`)}),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 Mb={overflowX:"auto",WebkitOverflowScrolling:"touch",margin:"0.8em 0",maxWidth:"100%"},Ab={borderCollapse:"collapse",fontSize:"0.9em",lineHeight:1.6,whiteSpace:"normal"},Lb=`1px solid ${r.bim("table-border")}`,Rc={border:Lb,padding:"4px 8px",verticalAlign:"top",textAlign:"left",minWidth:"3em"},Pb={...Rc,background:r.bim("table-head-bg"),fontWeight:600};function Ms({table:e,opts:i}){return t.jsx("div",{className:"bim-guji-table-wrap",style:Mb,children:t.jsx("table",{className:"bim-guji-table",style:Ab,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?Pb:Rc,children:o.empty?null:Lt(o.text,void 0,i)},a)})},s))})})})}function Ob(e,i){return e.indexOf("**")<0?Lt(e,void 0,i):e.split(/(^\*\*[^*\n]+\*\*[ \t]*$)/m).map((s,o)=>o%2===1?t.jsx("strong",{children:Lt(s.trim().slice(2,-2),void 0,i)},o):t.jsx(b.Fragment,{children:Lt(s,void 0,i)},o))}function Fb(e,i,n=!1){const s=n?{gujiMarkdown:!0}:void 0;return i?Is(e).map((o,a)=>o.type==="table"?t.jsx(Ms,{table:o.table,opts:s},a):t.jsx(b.Fragment,{children:Ob(o.text,s)},a)):Lt(e,void 0,s)}const Bb=/^(#{1,6})\s+(.*)$/,Hb=/^\*\*([^*\n]+)\*\*\s*$/;function As(e){const i=e.match(Bb);if(i)return{level:i[1].length,text:i[2].trim()};const n=e.trim().match(Hb);return n?{level:3,text:n[1].trim()}:null}const Ls=/^<!--.*-->$/;function Tc(e){return e.split(/\n\s*\n/).map(i=>i.trim()).filter(Boolean)}function Ic(e){return e.split(`
|
|
@@ -1413,15 +1414,15 @@ ${sb}`;function Hi({children:e,style:i,wide:n,grid:s}){return t.jsxs("div",{clas
|
|
|
1413
1414
|
`)}),o=[]};for(const l of i){const d=As(l);if(d){a(),s={kind:"heading",level:d.level,text:d.text};continue}o.push(l)}return a(),n}function ya(e){const i=[];for(const n of e.split(`
|
|
1414
1415
|
`)){const s=As(n);if(s){i.push({kind:"heading",level:s.level,text:s.text});continue}const o=n.trim();!o||Ls.test(o)||i.push({kind:"body",text:n})}return i}function Ac(e){if(!e)return[];const i=Jn(e);if(i==="unknown")return ya(e);const n=[];for(const{heading:s,body:o}of Ub(e)){s&&n.push(s);const a=Tc(o);if(a.length!==0){if(Mc(o)){n.push(...ya(o));continue}if(i==="record"){const l=a.join(" ");l&&n.push({kind:"body",text:l})}else for(const l of a){const d=Ic(l);d.length&&n.push({kind:"body",text:d.join(" ")})}}}return n}const Kb={"「":"“","」":"”","『":"‘","』":"’"},Yb={"“":"「","”":"」","‘":"『","’":"』"},Vb=new Set(["《","》","〈","〉"]);function Lc(e,i){const n=i.quoteStyle==="modern"?Kb:i.quoteStyle==="classic"?Yb:null;let s="";for(const o of e)i.hideBookBrackets&&Vb.has(o)||(s+=(n==null?void 0:n[o])??o);return s}const Pc=e=>e;function Ps(e){return e.showWorks?e.bookTitleStyle==="bracket"?"bracket":Tp(e.properNameMode)?"wavy":"bracket":"none"}function Oc(e,i=Pc,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 Zn(e,i={}){let n=i.renderText??Pc;const s=i.quoteStyle;if(s&&s!=="original"){const d=n;n=c=>d(Lc(c,{quoteStyle:s}))}const o=i.bookMarking??(i.properNames?"wavy":"bracket"),a=o==="bracket"?n:d=>Oc(d,n,o),l=i.gujiMarkdown?{gujiMarkdown:!0,t:i.t}:void 0;return Lt(e,a,l)}function ja(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 Rr=/^(#{1,6})\s+(.*)$/,Gb=/^\s*<!--.*-->\s*$/;function Fc(e){return e.replace(/<!--[\s\S]*?-->/g,i=>i.includes(`
|
|
1415
1416
|
`)?"":i)}function qb(e){return e<=1?2:e===2?3:4}function Xb(){let e=1;return i=>{const n=qb(i),s=Math.min(n,e+1);return e=s,{Tag:`h${s}`,className:`bim-rd-hl${n}`}}}function Mn(e){return e?Jn(Fc(e))!=="unknown":!1}function Jb(e){return/^\u3000{2}/.test(e)}const ka=e=>Jb(e)?"bim-rd-noindent":void 0;function wa({text:e,mode:i,inline:n,dropTitle:s,onStart:o}){o==null||o();const a=Fc(e),l=(p,h,u)=>!!s&&u<=1&&p<=2&&h.trim()===s.trim(),d=Xb();if(i==="paragraph"&&Jn(a)!=="unknown"){const p=Ac(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:ka(h.text),children:ja(h.text,n,u)},u)})})}const c=a.split(`
|
|
1416
|
-
`);let m=0;return t.jsx(t.Fragment,{children:c.map((p,h)=>{const u=p.match(Rr);if(u){const g=m++;if(l(u[1].length,u[2],g))return null;const{Tag:y,className:
|
|
1417
|
+
`);let m=0;return t.jsx(t.Fragment,{children:c.map((p,h)=>{const u=p.match(Rr);if(u){const g=m++;if(l(u[1].length,u[2],g))return null;const{Tag:y,className:v}=d(u[1].length);return t.jsx(y,{className:v,children:n(u[2])},h)}if(!p.trim())return h>=2&&!!c[h-1].trim()&&!!c[h-2].trim()&&!Rr.test(c[h-1])&&!Rr.test(c[h-2])?t.jsx("div",{className:"bim-rd-gap","aria-hidden":"true"},h):null;if(Gb.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:ka(p),children:ja(p,n,h)},h)})})}function Zb(e){const{convert:i}=gt();return b.useMemo(()=>e?i(e):"",[e,i])}function Os({text:e,mode:i,tables:n=!1,gujiMarkdown:s=!1,properNames:o=!1,bookMarking:a,quoteStyle:l,renderText:d,dropTitle:c}){const m=Zb(e),{t:p,convert:h}=oe();let u=null;const f=!!d&&!Wp(e,m,!l||l==="original"),g=d&&f?j=>d(j,{mdStart:u==null?void 0:u.align(j)}):d,y=f?()=>{u=Vp(e)}:void 0,v=j=>Zn(j,{renderText:g,properNames:o,bookMarking:a,quoteStyle:l,gujiMarkdown:s,t:p}),k=s?{gujiMarkdown:!0,t:p}:void 0,x=c?h(c):void 0;return!n||m.indexOf(":::")<0?t.jsx(wa,{text:m,mode:i,inline:v,dropTitle:x,onStart:y}):t.jsx(t.Fragment,{children:Is(m).map((j,S)=>j.type==="table"?t.jsx(Ms,{table:j.table,opts:k},S):t.jsx(wa,{text:j.text,mode:i,inline:v,dropTitle:S===0?x:void 0},S))})}const va={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(va,e)&&va[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 ht(e){return typeof e=="string"&&e?e:void 0}function eh(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={};ht(o.entity_id)!==void 0&&(a.entity_id=ht(o.entity_id)),ht(o.canonical_name)!==void 0&&(a.canonical_name=ht(o.canonical_name)),Zt(o.confidence)!==void 0&&(a.confidence=Zt(o.confidence)),n.push(a)}return n}function th(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(ht(s.entity_id))??ui(ht(s.href));o&&i.push({id:o,...ht(s.canonical_name)?{canonicalName:ht(s.canonical_name)}:{},...ht(s.part)?{part:ht(s.part)}:{}})}return i.length>=2?i:void 0}function ih(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(ht(a.entity_id))??ui(ht(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 Bc(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=ht(h.start),f=ht(h.end);if(!p&&!!!(u&&f))return;const y=ht(d.status),v=y===void 0||y==="matched"?ui(ht(d.entity_id))??ui(ht(d.href))??void 0:void 0,k=Zt(d.confidence),x=y==="matched_multi"?th(d):void 0,j=eh(a.ambiguous),S=ih(a.decomposition);n.push({...u&&f?{anchor:{start:u,end:f}}:{},key:ht(a.id)??`e${o}`,kind:Qb(a.type),...p?{start:c,end:m}:{},text:ht(a.text),targetId:v,canonicalName:ht(d.canonical_name),...x?{targets:x}:{},confidence:Zt(a.confidence)??k,...k!==void 0?{targetConfidence:k}:{},...ht(d.level)!==void 0?{targetLevel:ht(d.level)}:{},...ht(d.note)!==void 0?{targetNote:ht(d.note)}:{},...ht(a.group)!==void 0?{group:ht(a.group)}:{},...j!==void 0?{candidates:j}:{},...S?{parts:S}:{}})}),n.sort((s,o)=>!ji(s)||!ji(o)?+!ji(s)-+!ji(o):s.start-o.start||o.end-s.end)}const nh=new Set(Array.from(`《》/<>\r
|
|
1417
1418
|
,。、;:?!「」『』()…—·`));function Fs(e){return!nh.has(e)}function Hc(e,i,n=0){const s=[],o=Array.from(e);let a=0;for(const d of o)Fs(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 rh(e,i){return i.text?Array.from(e.slice(i.start,i.end)).filter(Fs).join("")===i.text:!0}function sh(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 Dc(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||!rh(e,d))&&(d=sh(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 oh={off:[],lite:["people","place","dynasty"],full:["people","place","dynasty","office","reign","other"]};function ah(e,i,n){const s=(n==null?void 0:n.showWorks)!==!1,o=new Set(oh[i]);return e.filter(a=>a.kind==="work"?s:o.has(a.kind))}function lh(e,i,n,s=""){const o=`${s}
|
|
1418
1419
|
${n.versionKey??""}
|
|
1419
|
-
${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 ch(){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 dh(e){return b.useSyncExternalStore(e.subscribe,e.get,e.get)}function Sa({store:e,children:i}){const n=dh(e);return b.createElement(b.Fragment,null,i(n))}const An="t:",mh=/\s/,uh="bim-text-highlights";function Ln(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++)mh.test(a[l])||(n+=a[l],s.push({node:o,off:l}))}return{text:n,at:s}}function ph(e){const i=[];for(let n=0;n<e.text.length;n++)i.push({anchor:`${An}${n}:1`,char:e.text[n],page:0,col:0});return i}function bh(){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 hh={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")}},fh={solid:"underline",dotted:"underline dotted",dashed:"underline dashed",wavy:"underline wavy"};function gh(e){const i=e.tone?hh[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?fh[e.underline]:e.focus?"underline":void 0;return[n&&`background-color:${n}`,s&&`color:${s}`,o&&`text-decoration:${o}`].filter(Boolean).join(";")}function xh(e,i,n){const s=bh();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=gh(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((
|
|
1420
|
+
${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 ch(){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 dh(e){return b.useSyncExternalStore(e.subscribe,e.get,e.get)}function Sa({store:e,children:i}){const n=dh(e);return b.createElement(b.Fragment,null,i(n))}const An="t:",mh=/\s/,uh="bim-text-highlights";function Ln(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++)mh.test(a[l])||(n+=a[l],s.push({node:o,off:l}))}return{text:n,at:s}}function ph(e){const i=[];for(let n=0;n<e.text.length;n++)i.push({anchor:`${An}${n}:1`,char:e.text[n],page:0,col:0});return i}function bh(){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 hh={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")}},fh={solid:"underline",dotted:"underline dotted",dashed:"underline dashed",wavy:"underline wavy"};function gh(e){const i=e.tone?hh[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?fh[e.underline]:e.focus?"underline":void 0;return[n&&`background-color:${n}`,s&&`color:${s}`,o&&`text-decoration:${o}`].filter(Boolean).join(";")}function xh(e,i,n){const s=bh();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=gh(m);if(!u)return;const f=o.get(u);f?f.push(Number(h[1])):o.set(u,[Number(h[1])])}),o.size===0)return()=>{};const a=[],l=[];let d=0;o.forEach((m,p)=>{m.sort((v,k)=>v-k);const h=[];let u=-1,f=-2;const g=()=>{if(u<0)return;const v=e.at[u],k=e.at[f];if(!v||!k)return;let x=u;for(let j=u+1;j<=f+1;j++)if(j>f||e.at[j].node!==e.at[x].node){const S=e.at[x],$=e.at[j-1],_=document.createRange();_.setStart(S.node,S.off),_.setEnd($.node,$.off+1),h.push(_),x=j}};for(const v of m){if(v===f+1){f=v;continue}g(),u=f=v}g();const y=`bim-cd-${n}-${d++}`;a.push(y),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=`${uh}-${n}`,c.textContent=l.join(`
|
|
1420
1421
|
`),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 Wc(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,...yh(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 yh(e){const i={};for(const n of Object.keys(e))e[n]!==void 0&&(i[n]=e[n]);return i}function jh(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 Tr=[],gn=new Map,Ir=500,kh=120;function wh(e,i,n){if(!e)return null;const s=Ln(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`${An}${l}:${a.length}`}return null}function $a(e,i){const n=/^t:(\d+):(\d+)$/.exec(i);if(!e||!n)return null;const{at:s}=Ln(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 vh(e){let i=0;for(let n=0;n<e.length;n++)i=i*31+e.charCodeAt(n)|0;return Math.abs(i)}function Sh(){const[e,i]=b.useState(!1);return b.useEffect(()=>{var o;if(typeof window>"u"||!window.matchMedia)return;const n=window.matchMedia($s),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 $h={settings:[],toolbar:{},overlay:null,decorations:void 0,onCellClick:()=>{},onCellHover:()=>{}};function _h(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}
|
|
1421
1422
|
${n.versionKey}
|
|
1422
1423
|
${n.chapterKey}`:null,f=i.filter(W=>W.onChapter).map(W=>W.id).join(`
|
|
1423
|
-
`),g=b.useRef({plugins:i,ctx:n});g.current={plugins:i,ctx:n};const[y,S]=b.useState({key:null,map:gn});b.useEffect(()=>{const W=g.current.ctx;if(!u||!W){S({key:null,map:gn});return}let K=!1;S({key:u,map:gn});for(const re of g.current.plugins){if(!re.onChapter)continue;const Y=ue=>{K||S(ye=>ye.key===u?{key:u,map:new Map(ye.map).set(re.id,ue)}:ye)},T=Kt(re,"onChapter",()=>re.onChapter(W),void 0);Promise.resolve(T).then(Y,ue=>{console.error(`[reader-plugin:${re.id}] onChapter 出错`,ue)})}return()=>{K=!0}},[u,f]);const k=y.key===u?y.map:gn,[x,j]=b.useState(0),v=b.useCallback(()=>j(W=>W+1),[]),$=b.useMemo(()=>{if(!d||d.length===0||i.length===0)return Tr;const W=[];for(const K of d)for(const re of K.columns)for(const Y of re.chars)Y.fig||W.push({anchor:Y.id,char:Y.char,page:K.page,col:re.col});return W},[d,i.length]),_=$.length===0&&i.some(W=>W.decorate),[N,I]=b.useState(Tr);b.useEffect(()=>{const W=m.current;if(!_||!W){I(Tr);return}let K;const re=()=>{const T=ph(Ln(W));I(ue=>ue.length===T.length&&ue.every((ye,Ne)=>ye.char===T[Ne].char)?ue:T)};if(re(),typeof MutationObserver>"u")return;const Y=new MutationObserver(()=>{clearTimeout(K),K=setTimeout(re,80)});return Y.observe(W,{childList:!0,subtree:!0,characterData:!0}),()=>{Y.disconnect(),clearTimeout(K)}},[_,u,m]);const D=b.useMemo(()=>{const W=new Map;for(const K of $)W.set(K.anchor,K);return W},[$]),E=b.useCallback(W=>{var Y,T;if(W.startsWith(An))return((T=(Y=$a(m.current,W))==null?void 0:Y.getBoundingClientRect)==null?void 0:T.call(Y))??null;const K=c.current;if(!K)return null;const re=K.querySelector(`[data-char-id="${W.replace(/["\\]/g,"\\$&")}"]`);return re?re.getBoundingClientRect():null},[c,m]),R=b.useCallback(W=>{var ye,Ne;if("cp"in W)return((ye=$[W.cp])==null?void 0:ye.anchor)??null;if(!W.text)return null;if($.length===0)return wh(m.current,W.text,l);let K="";const re=[];for(const B of $)re.push(K.length),K+=B.char;const Y=K.indexOf(W.text);if(Y<0)return null;let T=0,ue=re.length-1;for(;T<ue;){const B=T+ue+1>>1;re[B]<=Y?T=B:ue=B-1}return((Ne=$[T])==null?void 0:Ne.anchor)??null},[$,m,l]),O=b.useCallback(W=>{var re,Y;if(!W.startsWith(An)){h(W);return}const K=(Y=(re=$a(m.current,W))==null?void 0:re.getBoundingClientRect)==null?void 0:Y.call(re);K&&window.scrollTo({top:window.scrollY+K.top-kh,behavior:"instant"})},[h,m]),M=b.useMemo(()=>n?{ctx:n,state:W=>k.get(W),cells:$,textCells:N,scrollTo:O,rectOf:E,locate:R,refresh:v,prefs:s,setPref:o,t:a,convert:l}:null,[n,k,$,N,O,E,R,v,s,o,a,l,x]),q=b.useMemo(()=>{if(!M)return;const W=[];for(const K of i){if(!K.decorate)continue;const re=Kt(K,"decorate",()=>K.decorate(M),void 0);re&&re.size>0&&W.push(re)}return W.length===0?void 0:W.length===1?W[0]:Wc(W)},[i,M]);b.useEffect(()=>{const W=m.current;if(!($.length>0||!W||!q||q.size===0))return xh(Ln(W),q,u?String(vh(u)):"x")},[$.length,q,m,u,N]);const P=b.useCallback(W=>{var K;return{anchor:W,char:((K=D.get(W))==null?void 0:K.char)??"",rect:E(W)}},[D,E]),le=b.useCallback(W=>{var re;if(!M)return;const K=P(W);for(const Y of i)(re=Y.onCell)!=null&&re.click&&Kt(Y,"onCell.click",()=>Y.onCell.click(K,M),void 0)},[M,i,P]),ae=b.useCallback(W=>{var re;if(!M)return;const K=W?P(W):null;for(const Y of i)(re=Y.onCell)!=null&&re.hover&&Kt(Y,"onCell.hover",()=>Y.onCell.hover(K,M),void 0)},[M,i,P]),Ce=$.length===0&&i.some(W=>W.selectionActions),[xe,fe]=b.useState(null);b.useEffect(()=>{if(!Ce){fe(null);return}const W=()=>{var de,Me;const K=document.getSelection(),re=m.current;if(!K||K.isCollapsed||K.rangeCount===0||!re){fe(null);return}const Y=K.getRangeAt(0),T=Y.commonAncestorContainer,ue=T instanceof Element?T:T.parentElement;if(!re.contains(T)||ue!=null&&ue.closest('input,textarea,button,select,[contenteditable="true"]')){fe(null);return}const ye=K.toString().trim().slice(0,Ir);if(!ye){fe(null);return}const Ne=(de=Y.getClientRects)==null?void 0:de.call(Y),B=(Ne&&Ne.length>0?Ne[Ne.length-1]:(Me=Y.getBoundingClientRect)==null?void 0:Me.call(Y))??null;fe(Se=>Se&&Se.text===ye?Se:{text:ye,rect:B})};return document.addEventListener("selectionchange",W),()=>document.removeEventListener("selectionchange",W)},[Ce,m]),b.useEffect(()=>{fe(null)},[u]);const se=b.useMemo(()=>{if(!M||!i.some(Y=>Y.selectionActions))return[];if($.length===0){if(!xe)return[];const Y={anchors:[],text:xe.text,rect:xe.rect};return i.flatMap(T=>T.selectionActions?Kt(T,"selectionActions",()=>T.selectionActions(Y,M),[]):[])}if(p.size===0)return[];const W=[];let K="";for(const Y of $)p.has(Y.anchor)&&(W.push(Y.anchor),K.length<Ir&&(K+=Y.char));if(W.length===0)return[];const re={anchors:W,text:K.slice(0,Ir),rect:E(W[W.length-1])};return i.flatMap(Y=>Y.selectionActions?Kt(Y,"selectionActions",()=>Y.selectionActions(re,M),[]):[])},[M,i,p,$,E,xe]),Re=b.useMemo(()=>M?i.filter(W=>W.settings).map((W,K)=>({p:W,i:K,order:W.settings.order??100})).sort((W,K)=>W.order-K.order||W.i-K.i).map(({p:W})=>({key:W.id,group:W.settings.group,title:W.settings.title,node:Kt(W,"settings.render",()=>W.settings.render(M),null)})):[],[i,M]),H=b.useMemo(()=>{if(!M)return{};const W=K=>{const re=i.filter(Y=>{var T;return((T=Y.toolbar)==null?void 0:T.slot)===K}).map((Y,T)=>({p:Y,i:T,order:Y.toolbar.order??100})).sort((Y,T)=>Y.order-T.order||Y.i-T.i).map(({p:Y})=>t.jsx(b.Fragment,{children:Kt(Y,"toolbar.render",()=>Y.toolbar.render(M),null)},Y.id));return re.length>0?t.jsx(t.Fragment,{children:re}):void 0};return{subtitle:W("subtitle"),actions:W("actions")}},[i,M]),me=b.useMemo(()=>{if(!M)return null;const W=i.filter(K=>K.overlay).map(K=>t.jsx(b.Fragment,{children:Kt(K,"overlay",()=>K.overlay(M),null)},K.id));return W.length===0&&se.length===0?null:t.jsxs(t.Fragment,{children:[W,se.length>0&&t.jsx("div",{className:"bim-rd-selbar",role:"toolbar","aria-label":a("reader.selectionActions"),"data-testid":"reader-selbar",children:se.map(K=>t.jsx("button",{type:"button",title:K.title,onMouseDown:re=>re.preventDefault(),onClick:K.onClick,children:K.label},K.key))})]})},[i,M,se,a]);return i.length===0?$h:{settings:Re,toolbar:H,overlay:me,decorations:q,onCellClick:le,onCellHover:ae}}function Nh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(r.TEXT_QUALITY_LABELS,e)?e:null}function zh(e){if(e==="none")return{color:r.bim("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r.bim("quality-placeholder"),fontWeight:400}}const Ch={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Uc="\0";function Eh(e,i,n){const[s,o=""]=e.split(Uc);return t.jsxs(t.Fragment,{children:[s,t.jsx(Jl,{text:i,convert:n}),o]})}function Ft(e){return typeof e!="string"?"":Ch[e]??e}const Rh=["〇","一","二","三","四","五","六","七","八","九"],_a=["","十","百","千"],Th=["","萬","億"];function Bs(e){if(e===0)return"〇";if(e<0)return`負${Bs(-e)}`;const i=[];let n=e,s=0;for(;n>0;){const o=n%1e4;o>0?i.unshift(Ih(o,s>0)+Th[s]):i.length>0&&i.unshift("〇"),n=Math.floor(n/1e4),s++}return i.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ih(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+=_a[d]:o+=Rh[l]+_a[d]}return o.replace(/〇$/,"")}let Ki=null,xn=null;const Pn=new Set;function Mh(){return Ki?Promise.resolve():xn||(xn=import("opencc-js/t2cn").then(e=>{const i=e.Converter({from:"t",to:"cn"});Ki=n=>i(vi.normalizeVariants(n)),Pn.forEach(n=>n())}).catch(()=>{Ki=e=>e,Pn.forEach(e=>e())}),xn)}const Ah=e=>e;function pi(){const[,e]=b.useState(0);return b.useEffect(()=>{if(Ki)return;const i=()=>e(n=>n+1);return Pn.add(i),Mh(),()=>{Pn.delete(i)}},[]),Ki??Ah}function Ni(e,i){return i(e).toLowerCase()}const Lh=r.bim("highlight-bg");function tn(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:Lh,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 Hs(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 Ph(e,i,n){return i?Ni(e,n).includes(Ni(i,n)):!0}const Ds={类:r.bim("section-lei"),书:r.bim("section-shu"),序:r.bim("section-xu"),结语:r.bim("section-jieyu"),注释:r.bim("section-zhushi")},Oh={考证:r.bim("section-kaozhen")};function Ws(e,i,n){return e.collated.sectionType[i]??n(i)}function Kc(e){var s;const i=e.files.length,n=((s=e.children)==null?void 0:s.reduce((o,a)=>o+Kc(a),0))||0;return i+n}function Fh(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 Bh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Us({enabled:e,expanded:i,onClick:n,style:s,children:o}){return e?t.jsx("button",{type:"button","aria-expanded":i,onClick:n,style:{...Bh,...s},children:o}):t.jsx("span",{style:s,children:o})}function Hh({type:e}){const{convert:i,messages:n}=oe(),s=Ft(e),o=Ds[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:Ws(n,s,i)})}function Dh({section:e,onNavigate:i,highlightQuery:n="",no:s,showUnlinked:o=!1,domId:a}){const{t:l,convert:d}=oe(),c=It(),m=pi(),p=j=>j?Lt(d(j),v=>n?tn(v,n,m):v,{t:l}):"",[h,u]=b.useState(!1),f=!!e.summary,g=!!e.comment,y=!!e.additional_comment,S=!!(e.content&&e.content.length>60),k=f||g||y||S;b.useEffect(()=>{n&&u(!0)},[n]);const x=!h&&S?kc(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:()=>k&&u(!h),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:k?"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(Us,{enabled:k,expanded:h,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[k&&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(Bs(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:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.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&&k&&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)})]}),S&&!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 Wh({section:e,highlightQuery:i=""}){const{t:n,convert:s}=oe(),o=pi(),a=m=>m?Lt(s(m),p=>i?tn(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(Us,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Hh,{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, ${Ds[Ft(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 Uh=100;function Ks(e){return Ft(e.type)!=="page_header"?!1:(e.content||"").length>=Uh}function Kh({section:e,highlightQuery:i=""}){const{t:n,convert:s,messages:o}=oe(),a=pi();if(Ft(e.type)==="page_header"&&!Ks(e)||!e.content&&!e.title)return null;const l=s((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1424
|
-
`)),d=Lt(l,h=>i?tn(h,i,a):h,{t:n}),c=Ft(e.type),m=Ds[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:Ws(o,c,s)}),d]})}function Yh(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 S=await i.getEntry(p);if(S)return{title:S.title,author:S.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 Vh({section:e,onNavigate:i,transport:n,workLabelCache:s,highlightQuery:o=""}){const{t:a,convert:l,messages:d}=oe(),c=It(),m=pi(),p=v=>v?Lt(l(v),$=>o?tn($,o,m):$,{t:a}):"",[h,u]=b.useState(!1);b.useEffect(()=>{o&&u(!0)},[o]);const f=Ft(e.type),g=Oh[f]||r.bim("desc-fg"),y=!!e.content,S=e.work_ids||[],k=S.length>1,x=Yh(k?S:[],n,s),j=y&&!h&&e.content.length>80?kc(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(Us,{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&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.7},children:p(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[S.length===1&&i&&t.jsx("a",{href:c(S[0]),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),i(S[0]))},style:{fontSize:"11px",color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),k&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:S.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:Ws(d,f,l)})]})]}),k&&i&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:S.map(v=>{const $=x[v],_=$?`${l($.title)}${$.author?`(${l($.author)})`:""}`:v.slice(0,8)+"…";return t.jsxs("a",{href:c(v),onClick:N=>{N.metaKey||N.ctrlKey||(N.preventDefault(),N.stopPropagation(),i(v))},style:{fontSize:"12px",color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:v,children:["→",_]},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 Gh({juan:e,searchQuery:i,onNavigate:n,transport:s,workLabelCache:o}){const{t:a}=oe(),l=pi(),d=i.trim(),c=b.useMemo(()=>d?e.sections.filter(m=>Hs(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(Vh,{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 qh(){let e=!1;return i=>i==="类"?(e=!0,"h2"):e?"h3":"h2"}function Xh({sections:e,onNavigate:i,inline:n,workLinks:s=!0}){const o=It(),{t:a,convert:l}=oe(),d=qh();return t.jsx(t.Fragment,{children:e.map((c,m)=>{const p=Ft(c.type);if(p==="page_header"&&!Ks(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:Bs(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 Yc(e){return e.some(i=>{const n=Ft(i.type);return n==="书"||n==="诗"||n==="考证"||n==="注释"||n==="类"||(n==="序"||n==="结语")&&!!i.content||n==="page_header"&&Ks(i)})}function Jh({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 Re;const{t:u,convert:f,messages:g}=oe(),y=pi(),[S,k]=b.useState("text"),x=p??S,j=H=>{k(H),h==null||h(H)},v=a.trim(),$=(o==null?void 0:o.type)==="kaozhen",_=b.useCallback(H=>v?tn(H,v,y):H,[v,y]),N=Ps(m),I=H=>Zn(H,{renderText:_,bookMarking:N,quoteStyle:m.quoteStyle,t:u}),D=b.useMemo(()=>v?e.sections.filter(H=>Hs(H,v,$,y)):e.sections,[e.sections,v,$,y]),E=(H,me)=>me.filter(W=>Ft(W.type)===H).length,R=E("书",e.sections),O=E("诗",e.sections),M=E("考证",e.sections);let q="";$?q=v?u("collated.countTiaoOf",{m:E("考证",D),n:M}):u("collated.countTiao",{n:M}):O>0?q=v?u("collated.countPoemsOf",{m:E("诗",D),n:O}):u("collated.countPoems",{n:O}):R>0&&(q=v?u("collated.countBooksOf",{m:E("书",D),n:R}):u("collated.countBooks",{n:R}));const P=o!=null&&o.text_quality?Nh(o.text_quality.grade):null,le=[];if(q&&le.push(q),$&&(o!=null&&o.target_source)&&le.push(t.jsx(t.Fragment,{children:u("collated.kaozhenTarget",{target:f(o.target_source)})})),P){const H=t.jsx("span",{className:"bim-rd-grade",style:zh(P),children:g.collated.qualityLabel[P]});le.push(t.jsx("span",{title:g.collated.qualityCriteria[P],children:(Re=o==null?void 0:o.text_quality)!=null&&Re.source_note?t.jsxs(t.Fragment,{children:[Eh(u("collated.baseText",{note:Uc}),o.text_quality.source_note,f),H]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),H]})}))}e.source_url&&le.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:u("collated.originalSource")}));const ae=!$&&Yc(e.sections),Ce=!!i&&(!ae||m.readingMode==="paragraph"&&Mn(i)),xe=!$&&(ae||!!i),fe=$||!xe?"entries":x;let se=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)}),le.length>0&&t.jsx("p",{className:"bim-rd-meta",children:le.map((H,me)=>t.jsxs(b.Fragment,{children:[me>0&&t.jsx("span",{className:"bim-rd-dot"}),H]},me))}),xe&&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":fe==="text",onClick:()=>j("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":fe==="entries",onClick:()=>j("entries"),children:u("collated.viewEntries")})]})]}),fe==="text"&&t.jsx("article",{className:"bim-rd-prose",children:Ce?t.jsx(Os,{text:i,mode:m.readingMode,bookMarking:N,quoteStyle:m.quoteStyle,renderText:_,dropTitle:e.title}):t.jsx(Xh,{sections:e.sections,onNavigate:l,inline:I,workLinks:m.workLinks})}),fe==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:$?t.jsx(Gh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[D.some(H=>["书","诗","考证"].includes(Ft(H.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")})]}),D.map((H,me)=>{const W=Ft(H.type);return W==="书"||W==="诗"||W==="考证"?(se+=1,t.jsx(Dh,{domId:`rd-e-${e.sections.indexOf(H)}`,section:H,onNavigate:m.workLinks?l:void 0,highlightQuery:v,no:se,showUnlinked:m.workLinks&&!!l},me)):W==="类"?t.jsx(Wh,{section:H,highlightQuery:v},me):t.jsx(Kh,{section:H,highlightQuery:v},me)}),D.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function Zh(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((k,x)=>{const j=x==null?void 0:x.title;j&&g(v=>v[k]===j?v:{...v,[k]:j})},[]);b.useEffect(()=>{o&&a&&(p.current.set(o,{juan:a,rawText:l}),y(o,a))},[o,a,l,y]),b.useEffect(()=>{p.current.clear(),u({}),g({})},[i]);const S=b.useCallback((k,x)=>{let j=0;if(k.juan)for(const v of k.juan.sections)Hs(v,x,c,m)&&j++;return j===0&&k.rawText&&Ph(k.rawText,x,m)&&(j=1),j},[c,m]);return b.useEffect(()=>{const k=d.trim();if(!k){u({});return}if(!n||s.length===0)return;let x=!1;const j={},v=[];for(const D of s){const E=p.current.get(D);E?j[D]=S(E,k):(j[D]="loading",v.push(D))}u(j);const $=8;let _=0;const N=async()=>{for(;_<v.length;){if(x)return;const D=_++,E=v[D];try{const R=await n(E),O=R.juan;if(p.current.set(E,R),y(E,O),x)return;u(M=>({...M,[E]:S(R,k)}))}catch{if(x)return;u(R=>({...R,[E]:0}))}}},I=Array.from({length:Math.min($,v.length)},()=>N());return Promise.all(I),()=>{x=!0}},[d,i,n,s.join(","),S,m,y]),{matchStates:h,titles:f}}function Qh({juan:e,view:i,onView:n,textHasEntries:s}){const{t:o,convert:a}=oe(),l=e.sections.map((p,h)=>({s:p,i:h,t:Ft(p.type)})).filter(p=>p.t==="书"||p.t==="诗");if(l.length===0)return null;const d=l.filter(p=>!!p.s.work_id).length,c=l.every(p=>p.t==="诗")?o("collated.railUnitPoems"):o("collated.railUnitBooks"),m=p=>{const h=()=>{var u,f;return(f=(u=document.getElementById(`rd-e-${p}`))==null?void 0:u.scrollIntoView)==null?void 0:f.call(u,{block:"start",behavior:"smooth"})};i==="text"&&!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:Zn(a(p.book_title||p.title),{t:o})})]})},h))})]})]})}const ef=`
|
|
1424
|
+
`),g=b.useRef({plugins:i,ctx:n});g.current={plugins:i,ctx:n};const[y,v]=b.useState({key:null,map:gn});b.useEffect(()=>{const W=g.current.ctx;if(!u||!W){v({key:null,map:gn});return}let K=!1;v({key:u,map:gn});for(const re of g.current.plugins){if(!re.onChapter)continue;const Y=ue=>{K||v(ye=>ye.key===u?{key:u,map:new Map(ye.map).set(re.id,ue)}:ye)},T=Kt(re,"onChapter",()=>re.onChapter(W),void 0);Promise.resolve(T).then(Y,ue=>{console.error(`[reader-plugin:${re.id}] onChapter 出错`,ue)})}return()=>{K=!0}},[u,f]);const k=y.key===u?y.map:gn,[x,j]=b.useState(0),S=b.useCallback(()=>j(W=>W+1),[]),$=b.useMemo(()=>{if(!d||d.length===0||i.length===0)return Tr;const W=[];for(const K of d)for(const re of K.columns)for(const Y of re.chars)Y.fig||W.push({anchor:Y.id,char:Y.char,page:K.page,col:re.col});return W},[d,i.length]),_=$.length===0&&i.some(W=>W.decorate),[N,I]=b.useState(Tr);b.useEffect(()=>{const W=m.current;if(!_||!W){I(Tr);return}let K;const re=()=>{const T=ph(Ln(W));I(ue=>ue.length===T.length&&ue.every((ye,Ne)=>ye.char===T[Ne].char)?ue:T)};if(re(),typeof MutationObserver>"u")return;const Y=new MutationObserver(()=>{clearTimeout(K),K=setTimeout(re,80)});return Y.observe(W,{childList:!0,subtree:!0,characterData:!0}),()=>{Y.disconnect(),clearTimeout(K)}},[_,u,m]);const D=b.useMemo(()=>{const W=new Map;for(const K of $)W.set(K.anchor,K);return W},[$]),E=b.useCallback(W=>{var Y,T;if(W.startsWith(An))return((T=(Y=$a(m.current,W))==null?void 0:Y.getBoundingClientRect)==null?void 0:T.call(Y))??null;const K=c.current;if(!K)return null;const re=K.querySelector(`[data-char-id="${W.replace(/["\\]/g,"\\$&")}"]`);return re?re.getBoundingClientRect():null},[c,m]),R=b.useCallback(W=>{var ye,Ne;if("cp"in W)return((ye=$[W.cp])==null?void 0:ye.anchor)??null;if(!W.text)return null;if($.length===0)return wh(m.current,W.text,l);let K="";const re=[];for(const B of $)re.push(K.length),K+=B.char;const Y=K.indexOf(W.text);if(Y<0)return null;let T=0,ue=re.length-1;for(;T<ue;){const B=T+ue+1>>1;re[B]<=Y?T=B:ue=B-1}return((Ne=$[T])==null?void 0:Ne.anchor)??null},[$,m,l]),O=b.useCallback(W=>{var re,Y;if(!W.startsWith(An)){h(W);return}const K=(Y=(re=$a(m.current,W))==null?void 0:re.getBoundingClientRect)==null?void 0:Y.call(re);K&&window.scrollTo({top:window.scrollY+K.top-kh,behavior:"instant"})},[h,m]),M=b.useMemo(()=>n?{ctx:n,state:W=>k.get(W),cells:$,textCells:N,scrollTo:O,rectOf:E,locate:R,refresh:S,prefs:s,setPref:o,t:a,convert:l}:null,[n,k,$,N,O,E,R,S,s,o,a,l,x]),q=b.useMemo(()=>{if(!M)return;const W=[];for(const K of i){if(!K.decorate)continue;const re=Kt(K,"decorate",()=>K.decorate(M),void 0);re&&re.size>0&&W.push(re)}return W.length===0?void 0:W.length===1?W[0]:Wc(W)},[i,M]);b.useEffect(()=>{const W=m.current;if(!($.length>0||!W||!q||q.size===0))return xh(Ln(W),q,u?String(vh(u)):"x")},[$.length,q,m,u,N]);const P=b.useCallback(W=>{var K;return{anchor:W,char:((K=D.get(W))==null?void 0:K.char)??"",rect:E(W)}},[D,E]),le=b.useCallback(W=>{var re;if(!M)return;const K=P(W);for(const Y of i)(re=Y.onCell)!=null&&re.click&&Kt(Y,"onCell.click",()=>Y.onCell.click(K,M),void 0)},[M,i,P]),ae=b.useCallback(W=>{var re;if(!M)return;const K=W?P(W):null;for(const Y of i)(re=Y.onCell)!=null&&re.hover&&Kt(Y,"onCell.hover",()=>Y.onCell.hover(K,M),void 0)},[M,i,P]),Ce=$.length===0&&i.some(W=>W.selectionActions),[xe,fe]=b.useState(null);b.useEffect(()=>{if(!Ce){fe(null);return}const W=()=>{var de,Me;const K=document.getSelection(),re=m.current;if(!K||K.isCollapsed||K.rangeCount===0||!re){fe(null);return}const Y=K.getRangeAt(0),T=Y.commonAncestorContainer,ue=T instanceof Element?T:T.parentElement;if(!re.contains(T)||ue!=null&&ue.closest('input,textarea,button,select,[contenteditable="true"]')){fe(null);return}const ye=K.toString().trim().slice(0,Ir);if(!ye){fe(null);return}const Ne=(de=Y.getClientRects)==null?void 0:de.call(Y),B=(Ne&&Ne.length>0?Ne[Ne.length-1]:(Me=Y.getBoundingClientRect)==null?void 0:Me.call(Y))??null;fe(Se=>Se&&Se.text===ye?Se:{text:ye,rect:B})};return document.addEventListener("selectionchange",W),()=>document.removeEventListener("selectionchange",W)},[Ce,m]),b.useEffect(()=>{fe(null)},[u]);const se=b.useMemo(()=>{if(!M||!i.some(Y=>Y.selectionActions))return[];if($.length===0){if(!xe)return[];const Y={anchors:[],text:xe.text,rect:xe.rect};return i.flatMap(T=>T.selectionActions?Kt(T,"selectionActions",()=>T.selectionActions(Y,M),[]):[])}if(p.size===0)return[];const W=[];let K="";for(const Y of $)p.has(Y.anchor)&&(W.push(Y.anchor),K.length<Ir&&(K+=Y.char));if(W.length===0)return[];const re={anchors:W,text:K.slice(0,Ir),rect:E(W[W.length-1])};return i.flatMap(Y=>Y.selectionActions?Kt(Y,"selectionActions",()=>Y.selectionActions(re,M),[]):[])},[M,i,p,$,E,xe]),Re=b.useMemo(()=>M?i.filter(W=>W.settings).map((W,K)=>({p:W,i:K,order:W.settings.order??100})).sort((W,K)=>W.order-K.order||W.i-K.i).map(({p:W})=>({key:W.id,group:W.settings.group,title:W.settings.title,node:Kt(W,"settings.render",()=>W.settings.render(M),null)})):[],[i,M]),H=b.useMemo(()=>{if(!M)return{};const W=K=>{const re=i.filter(Y=>{var T;return((T=Y.toolbar)==null?void 0:T.slot)===K}).map((Y,T)=>({p:Y,i:T,order:Y.toolbar.order??100})).sort((Y,T)=>Y.order-T.order||Y.i-T.i).map(({p:Y})=>t.jsx(b.Fragment,{children:Kt(Y,"toolbar.render",()=>Y.toolbar.render(M),null)},Y.id));return re.length>0?t.jsx(t.Fragment,{children:re}):void 0};return{subtitle:W("subtitle"),actions:W("actions")}},[i,M]),me=b.useMemo(()=>{if(!M)return null;const W=i.filter(K=>K.overlay).map(K=>t.jsx(b.Fragment,{children:Kt(K,"overlay",()=>K.overlay(M),null)},K.id));return W.length===0&&se.length===0?null:t.jsxs(t.Fragment,{children:[W,se.length>0&&t.jsx("div",{className:"bim-rd-selbar",role:"toolbar","aria-label":a("reader.selectionActions"),"data-testid":"reader-selbar",children:se.map(K=>t.jsx("button",{type:"button",title:K.title,onMouseDown:re=>re.preventDefault(),onClick:K.onClick,children:K.label},K.key))})]})},[i,M,se,a]);return i.length===0?$h:{settings:Re,toolbar:H,overlay:me,decorations:q,onCellClick:le,onCellHover:ae}}function Nh(e){return typeof e!="string"?null:e==="published"?"source":Object.prototype.hasOwnProperty.call(r.TEXT_QUALITY_LABELS,e)?e:null}function zh(e){if(e==="none")return{color:r.bim("quality-none"),fontWeight:400};if(e==="placeholder")return{color:r.bim("quality-placeholder"),fontWeight:400}}const Ch={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释",tally:"小计"},Uc="\0";function Eh(e,i,n){const[s,o=""]=e.split(Uc);return t.jsxs(t.Fragment,{children:[s,t.jsx(Jl,{text:i,convert:n}),o]})}function Ft(e){return typeof e!="string"?"":Ch[e]??e}const Rh=["〇","一","二","三","四","五","六","七","八","九"],_a=["","十","百","千"],Th=["","萬","億"];function Bs(e){if(e===0)return"〇";if(e<0)return`負${Bs(-e)}`;const i=[];let n=e,s=0;for(;n>0;){const o=n%1e4;o>0?i.unshift(Ih(o,s>0)+Th[s]):i.length>0&&i.unshift("〇"),n=Math.floor(n/1e4),s++}return i.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ih(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+=_a[d]:o+=Rh[l]+_a[d]}return o.replace(/〇$/,"")}let Ki=null,xn=null;const Pn=new Set;function Mh(){return Ki?Promise.resolve():xn||(xn=import("opencc-js/t2cn").then(e=>{const i=e.Converter({from:"t",to:"cn"});Ki=n=>i(vi.normalizeVariants(n)),Pn.forEach(n=>n())}).catch(()=>{Ki=e=>e,Pn.forEach(e=>e())}),xn)}const Ah=e=>e;function pi(){const[,e]=b.useState(0);return b.useEffect(()=>{if(Ki)return;const i=()=>e(n=>n+1);return Pn.add(i),Mh(),()=>{Pn.delete(i)}},[]),Ki??Ah}function Ni(e,i){return i(e).toLowerCase()}const Lh=r.bim("highlight-bg");function tn(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:Lh,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 Hs(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 Ph(e,i,n){return i?Ni(e,n).includes(Ni(i,n)):!0}const Ds={类:r.bim("section-lei"),书:r.bim("section-shu"),序:r.bim("section-xu"),结语:r.bim("section-jieyu"),注释:r.bim("section-zhushi")},Oh={考证:r.bim("section-kaozhen")};function Ws(e,i,n){return e.collated.sectionType[i]??n(i)}function Kc(e){var s;const i=e.files.length,n=((s=e.children)==null?void 0:s.reduce((o,a)=>o+Kc(a),0))||0;return i+n}function Fh(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 Bh={background:"none",border:"none",padding:0,margin:0,font:"inherit",color:"inherit",textAlign:"left",cursor:"pointer"};function Us({enabled:e,expanded:i,onClick:n,style:s,children:o}){return e?t.jsx("button",{type:"button","aria-expanded":i,onClick:n,style:{...Bh,...s},children:o}):t.jsx("span",{style:s,children:o})}function Hh({type:e}){const{convert:i,messages:n}=oe(),s=Ft(e),o=Ds[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:Ws(n,s,i)})}function Dh({section:e,onNavigate:i,highlightQuery:n="",no:s,showUnlinked:o=!1,domId:a}){const{t:l,convert:d}=oe(),c=It(),m=pi(),p=j=>j?Lt(d(j),S=>n?tn(S,n,m):S,{t:l}):"",[h,u]=b.useState(!1),f=!!e.summary,g=!!e.comment,y=!!e.additional_comment,v=!!(e.content&&e.content.length>60),k=f||g||y||v;b.useEffect(()=>{n&&u(!0)},[n]);const x=!h&&v?kc(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:()=>k&&u(!h),style:{padding:"10px 10px",display:"flex",alignItems:"baseline",gap:"8px",cursor:k?"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(Us,{enabled:k,expanded:h,style:{flex:1,minWidth:0,display:"flex",alignItems:"baseline",gap:"8px"},children:[k&&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(Bs(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:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.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&&k&&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)})]}),v&&!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 Wh({section:e,highlightQuery:i=""}){const{t:n,convert:s}=oe(),o=pi(),a=m=>m?Lt(s(m),p=>i?tn(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(Us,{enabled:c,expanded:l,onClick:()=>d(!l),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[t.jsx(Hh,{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, ${Ds[Ft(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 Uh=100;function Ks(e){return Ft(e.type)!=="page_header"?!1:(e.content||"").length>=Uh}function Kh({section:e,highlightQuery:i=""}){const{t:n,convert:s,messages:o}=oe(),a=pi();if(Ft(e.type)==="page_header"&&!Ks(e)||!e.content&&!e.title)return null;const l=s((e.content||e.title||"").replace(/\n{2,}/g,`
|
|
1425
|
+
`)),d=Lt(l,h=>i?tn(h,i,a):h,{t:n}),c=Ft(e.type),m=Ds[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:Ws(o,c,s)}),d]})}function Yh(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 v=await i.getEntry(p);if(v)return{title:v.title,author:v.author}}const u=await i.getItem(p);if(!u)return null;const f=u.title||p,g=u.authors,y=(h=g==null?void 0:g[0])==null?void 0:h.name;return{title:f,author:y}}catch{return null}};return Promise.all(l.map(async p=>{var u;const h=await c(p);return(u=n==null?void 0:n.current)==null||u.set(p,h),[p,h]})).then(p=>{a||o(h=>{const u={...h};for(const[f,g]of p)u[f]=g;return u})}),()=>{a=!0}},[e.join(","),i]),s}function Vh({section:e,onNavigate:i,transport:n,workLabelCache:s,highlightQuery:o=""}){const{t:a,convert:l,messages:d}=oe(),c=It(),m=pi(),p=S=>S?Lt(l(S),$=>o?tn($,o,m):$,{t:a}):"",[h,u]=b.useState(!1);b.useEffect(()=>{o&&u(!0)},[o]);const f=Ft(e.type),g=Oh[f]||r.bim("desc-fg"),y=!!e.content,v=e.work_ids||[],k=v.length>1,x=Yh(k?v:[],n,s),j=y&&!h&&e.content.length>80?kc(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(Us,{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&&j&&t.jsx("span",{style:{display:"block",margin:"4px 0 0",fontSize:"12px",color:r.bim("desc-fg"),lineHeight:1.7},children:p(j)})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[v.length===1&&i&&t.jsx("a",{href:c(v[0]),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),S.stopPropagation(),i(v[0]))},style:{fontSize:"11px",color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",flexShrink:0},title:a("collated.viewWork"),children:a("collated.arrowWork")}),k&&t.jsx("span",{style:{fontSize:"11px",color:r.bim("link-fg"),flexShrink:0},children:a("collated.nWorks",{n:v.length})}),t.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:Ws(d,f,l)})]})]}),k&&i&&t.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:v.map(S=>{const $=x[S],_=$?`${l($.title)}${$.author?`(${l($.author)})`:""}`:S.slice(0,8)+"…";return t.jsxs("a",{href:c(S),onClick:N=>{N.metaKey||N.ctrlKey||(N.preventDefault(),N.stopPropagation(),i(S))},style:{fontSize:"12px",color:r.bim("link-fg"),cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:S,children:["→",_]},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 Gh({juan:e,searchQuery:i,onNavigate:n,transport:s,workLabelCache:o}){const{t:a}=oe(),l=pi(),d=i.trim(),c=b.useMemo(()=>d?e.sections.filter(m=>Hs(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(Vh,{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 qh(){let e=!1;return i=>i==="类"?(e=!0,"h2"):e?"h3":"h2"}function Xh({sections:e,onNavigate:i,inline:n,workLinks:s=!0}){const o=It(),{t:a,convert:l}=oe(),d=qh();return t.jsx(t.Fragment,{children:e.map((c,m)=>{const p=Ft(c.type);if(p==="page_header"&&!Ks(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:Bs(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 Yc(e){return e.some(i=>{const n=Ft(i.type);return n==="书"||n==="诗"||n==="考证"||n==="注释"||n==="类"||(n==="序"||n==="结语")&&!!i.content||n==="page_header"&&Ks(i)})}function Jh({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 Re;const{t:u,convert:f,messages:g}=oe(),y=pi(),[v,k]=b.useState("text"),x=p??v,j=H=>{k(H),h==null||h(H)},S=a.trim(),$=(o==null?void 0:o.type)==="kaozhen",_=b.useCallback(H=>S?tn(H,S,y):H,[S,y]),N=Ps(m),I=H=>Zn(H,{renderText:_,bookMarking:N,quoteStyle:m.quoteStyle,t:u}),D=b.useMemo(()=>S?e.sections.filter(H=>Hs(H,S,$,y)):e.sections,[e.sections,S,$,y]),E=(H,me)=>me.filter(W=>Ft(W.type)===H).length,R=E("书",e.sections),O=E("诗",e.sections),M=E("考证",e.sections);let q="";$?q=S?u("collated.countTiaoOf",{m:E("考证",D),n:M}):u("collated.countTiao",{n:M}):O>0?q=S?u("collated.countPoemsOf",{m:E("诗",D),n:O}):u("collated.countPoems",{n:O}):R>0&&(q=S?u("collated.countBooksOf",{m:E("书",D),n:R}):u("collated.countBooks",{n:R}));const P=o!=null&&o.text_quality?Nh(o.text_quality.grade):null,le=[];if(q&&le.push(q),$&&(o!=null&&o.target_source)&&le.push(t.jsx(t.Fragment,{children:u("collated.kaozhenTarget",{target:f(o.target_source)})})),P){const H=t.jsx("span",{className:"bim-rd-grade",style:zh(P),children:g.collated.qualityLabel[P]});le.push(t.jsx("span",{title:g.collated.qualityCriteria[P],children:(Re=o==null?void 0:o.text_quality)!=null&&Re.source_note?t.jsxs(t.Fragment,{children:[Eh(u("collated.baseText",{note:Uc}),o.text_quality.source_note,f),H]}):t.jsxs(t.Fragment,{children:[u("collated.textQuality"),H]})}))}e.source_url&&le.push(t.jsx("a",{className:"bim-rd-link",href:e.source_url,target:"_blank",rel:"noopener noreferrer",children:u("collated.originalSource")}));const ae=!$&&Yc(e.sections),Ce=!!i&&(!ae||m.readingMode==="paragraph"&&Mn(i)),xe=!$&&(ae||!!i),fe=$||!xe?"entries":x;let se=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)}),le.length>0&&t.jsx("p",{className:"bim-rd-meta",children:le.map((H,me)=>t.jsxs(b.Fragment,{children:[me>0&&t.jsx("span",{className:"bim-rd-dot"}),H]},me))}),xe&&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":fe==="text",onClick:()=>j("text"),children:u("collated.viewText")}),t.jsx("button",{type:"button",className:"bim-rd-t","aria-pressed":fe==="entries",onClick:()=>j("entries"),children:u("collated.viewEntries")})]})]}),fe==="text"&&t.jsx("article",{className:"bim-rd-prose",children:Ce?t.jsx(Os,{text:i,mode:m.readingMode,bookMarking:N,quoteStyle:m.quoteStyle,renderText:_,dropTitle:e.title}):t.jsx(Xh,{sections:e.sections,onNavigate:l,inline:I,workLinks:m.workLinks})}),fe==="entries"&&t.jsx("div",{className:"bim-rd-entries",style:{marginTop:24},children:$?t.jsx(Gh,{juan:e,searchQuery:a,onNavigate:l,transport:d,workLabelCache:c}):t.jsxs(t.Fragment,{children:[D.some(H=>["书","诗","考证"].includes(Ft(H.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")})]}),D.map((H,me)=>{const W=Ft(H.type);return W==="书"||W==="诗"||W==="考证"?(se+=1,t.jsx(Dh,{domId:`rd-e-${e.sections.indexOf(H)}`,section:H,onNavigate:m.workLinks?l:void 0,highlightQuery:S,no:se,showUnlinked:m.workLinks&&!!l},me)):W==="类"?t.jsx(Wh,{section:H,highlightQuery:S},me):t.jsx(Kh,{section:H,highlightQuery:S},me)}),D.length===0&&t.jsx("div",{className:"bim-rd-state",style:{textAlign:"center"},children:u("collated.noMatch")})]})})]})}function Zh(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((k,x)=>{const j=x==null?void 0:x.title;j&&g(S=>S[k]===j?S:{...S,[k]:j})},[]);b.useEffect(()=>{o&&a&&(p.current.set(o,{juan:a,rawText:l}),y(o,a))},[o,a,l,y]),b.useEffect(()=>{p.current.clear(),u({}),g({})},[i]);const v=b.useCallback((k,x)=>{let j=0;if(k.juan)for(const S of k.juan.sections)Hs(S,x,c,m)&&j++;return j===0&&k.rawText&&Ph(k.rawText,x,m)&&(j=1),j},[c,m]);return b.useEffect(()=>{const k=d.trim();if(!k){u({});return}if(!n||s.length===0)return;let x=!1;const j={},S=[];for(const D of s){const E=p.current.get(D);E?j[D]=v(E,k):(j[D]="loading",S.push(D))}u(j);const $=8;let _=0;const N=async()=>{for(;_<S.length;){if(x)return;const D=_++,E=S[D];try{const R=await n(E),O=R.juan;if(p.current.set(E,R),y(E,O),x)return;u(M=>({...M,[E]:v(R,k)}))}catch{if(x)return;u(R=>({...R,[E]:0}))}}},I=Array.from({length:Math.min($,S.length)},()=>N());return Promise.all(I),()=>{x=!0}},[d,i,n,s.join(","),v,m,y]),{matchStates:h,titles:f}}function Qh({juan:e,view:i,onView:n,textHasEntries:s}){const{t:o,convert:a}=oe(),l=e.sections.map((p,h)=>({s:p,i:h,t:Ft(p.type)})).filter(p=>p.t==="书"||p.t==="诗");if(l.length===0)return null;const d=l.filter(p=>!!p.s.work_id).length,c=l.every(p=>p.t==="诗")?o("collated.railUnitPoems"):o("collated.railUnitBooks"),m=p=>{const h=()=>{var u,f;return(f=(u=document.getElementById(`rd-e-${p}`))==null?void 0:u.scrollIntoView)==null?void 0:f.call(u,{block:"start",behavior:"smooth"})};i==="text"&&!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:Zn(a(p.book_title||p.title),{t:o})})]})},h))})]})]})}const ef=`
|
|
1425
1426
|
attribute vec2 a_position; // 目标画布像素坐标 [0, canvasWidth] x [0, canvasHeight]
|
|
1426
1427
|
attribute vec2 a_texCoord; // 原图像素坐标 [0, imgWidth] x [0, imgHeight]
|
|
1427
1428
|
|
|
@@ -1449,7 +1450,7 @@ ${n.chapterKey}`:null,f=i.filter(W=>W.onChapter).map(W=>W.id).join(`
|
|
|
1449
1450
|
vec4 tex = texture2D(u_image, v_texCoord);
|
|
1450
1451
|
gl_FragColor = vec4(tex.rgb, tex.a * u_alpha);
|
|
1451
1452
|
}
|
|
1452
|
-
`;function Na(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 ts{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=Na(n,n.VERTEX_SHADER,ef),o=Na(n,n.FRAGMENT_SHADER,tf);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:S}=u.strip,[k,x,j,v]=S,$=f+k,_=g+x,[N,I,D,E]=y;for(let R=0;R<h;R++){const O=R/h,M=(R+1)/h,q=_+v*O,P=_+v*M,le=[N[0]+(E[0]-N[0])*O,N[1]+(E[1]-N[1])*O],ae=[N[0]+(E[0]-N[0])*M,N[1]+(E[1]-N[1])*M],Ce=[I[0]+(D[0]-I[0])*O,I[1]+(D[1]-I[1])*O],xe=[I[0]+(D[0]-I[0])*M,I[1]+(D[1]-I[1])*M],fe=[$,q],se=[$+j,q],Re=[$,P],H=[$+j,P];m.push(fe[0],fe[1],se[0],se[1],Re[0],Re[1]),p.push(le[0],le[1],Ce[0],Ce[1],ae[0],ae[1]),m.push(se[0],se[1],H[0],H[1],Re[0],Re[1]),p.push(Ce[0],Ce[1],xe[0],xe[1],ae[0],ae[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 za=150,nf=.35,rf=.25,yn=.01,Ca=.25;function sf(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<=yn*n||c>=(1-yn)*n)continue;let m=0,p=0;const h=c*i;for(let u=0;u<i;u++)e[h+u]<za?(p++,p>m&&(m=p)):p=0;m>nf*i&&s.push(c)}if(s.length<2)return null;const o=s[0],a=s[s.length-1]+1;if(a-o<Ca*n)return null;let l=null,d=null;for(let c=0;c<i;c++){if(c<=yn*i||c>=(1-yn)*i)continue;let m=0;for(let p=o;p<a;p++)e[p*i+c]<za&&m++;m/(a-o)>=rf&&(l===null&&(l=c),d=c+1)}return l!==null&&d!==null&&d-l<Ca*i&&(l=null,d=null),{x0:l===null?null:l/i,x1:d===null?null:d/i,y0:o/n,y1:a/n}}const Mr=new WeakMap,of=600;function af(e){if(Mr.has(e))return Mr.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(of,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=sf(m,o,a)}}}catch{i=null}return Mr.set(e,i),i}function lf(e,i,n){const[s,o]=e.image_size||[0,0];if(!(s>0)||!(o>0)||e.columns.some(x=>{var j;return(((j=x.strips)==null?void 0:j.length)??0)>0}))return null;let a=1/0,l=1/0,d=-1/0,c=-1/0;for(const x of e.columns)for(const j of x.chars){const[v,$,_,N]=j.bbox_col;![v,$,_,N].every(Number.isFinite)||!(_>v)||!(N>$)||(a=Math.min(a,x.offset_x+v),l=Math.min(l,$),d=Math.max(d,x.offset_x+_),c=Math.max(c,N))}for(const x of e.figBlocks??[]){const[j,v,$,_]=x.box;![j,v,$,_].every(Number.isFinite)||!($>j)||!(_>v)||(a=Math.min(a,j),l=Math.min(l,v),d=Math.max(d,$),c=Math.max(c,_))}if(!(d>a)||!(c>l))return null;const m=Math.min(s,o)*.03;let p=a-m,h=l-m,u=d+m,f=c+m;if(n&&n.every(Number.isFinite)&&n[2]>0&&n[3]>0){const x=Math.min(s,o)*.005;p=Math.min(a-x,n[0]),h=Math.min(l-x,n[1]),u=Math.max(d+x,n[0]+n[2]),f=Math.max(c+x,n[1]+n[3])}else if(i){const x=Math.min(s,o)*.015;h=Math.min(l-x,i.y0*o-x),f=Math.max(c+x,i.y1*o+x),i.x0!==null&&i.x1!==null&&(p=Math.min(a-x,i.x0*s-x),u=Math.max(d+x,i.x1*s+x))}const g=Math.min(s,Math.max(0,p)),y=Math.min(o,Math.max(0,h)),S=Math.min(s,Math.max(0,u))-g,k=Math.min(o,Math.max(0,f))-y;return!(S>0)||!(k>0)||S>=s*.98&&k>=o*.98?null:{x:g,y,w:S,h:k}}function jn(e,i,n){const s=e[6]*i+e[7]*n+e[8]||1;return[(e[0]*i+e[1]*n+e[2])/s,(e[3]*i+e[4]*n+e[5])/s]}function cf(e){return Array.isArray(e)&&e.length===9&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&Math.abs(e[8])>1e-9}function Ea(e,i,n,s,o){const a=[jn(e,i,n),jn(e,s,n),jn(e,s,o),jn(e,i,o)],l=a.map(c=>c[0]),d=a.map(c=>c[1]);return[Math.min(...l),Math.min(...d),Math.max(...l),Math.max(...d)]}function df(e,i){const n=i.H;return{...e,image_size:[i.src.w,i.src.h],columns:e.columns.map(s=>({...s,offset_x:0,chars:s.chars.map(o=>{const[a,l,d,c]=o.bbox_col,[m,p,h,u]=Ea(n,s.offset_x+a,l,s.offset_x+d,c);return{...o,bbox_col:[m,p,h,u]}})})),...e.figBlocks?{figBlocks:e.figBlocks.map(s=>({...s,box:Ea(n,s.box[0],s.box[1],s.box[2],s.box[3])}))}:{}}}function Ar(e){return Array.isArray(e)&&e.length===4&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&e[2]>0&&e[3]>0}function Ra(e,i,n){const s=i[0]>0?n[0]/i[0]:1,o=i[1]>0?n[1]/i[1]:1;return[e[0]*s,e[1]*o,e[2]*s,e[3]*o]}const mf={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 uf(e){const i=e.tone&&mf[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 Ta=typeof window>"u"?b.useEffect:b.useLayoutEffect;function pf(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 Lr=[1,1.5,2,3,4,6];function bf(e){for(const i of Lr)if(e<=i)return i;return Lr[Lr.length-1]}function hf(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)*bf(o)/64)*64,l=Math.max(1,Math.min(Math.round(e),a)),d=Math.max(1,Math.round(l*i/e));return[l,d]}const Ct=new Map,Ia=8;let Nn=null;function ff(e){Nn=e}function is(e){let i=Ct.get(e);if(i)return Ct.delete(e),Ct.set(e,i),i;const n=Nn==null?void 0:Nn(e);if(n){for(i=n.then(s=>(s||Ct.delete(e),s),()=>(Ct.delete(e),null)),Ct.set(e,i);Ct.size>Ia;)Ct.delete(Ct.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=()=>{Ct.delete(e),s(null)},o.src=e}),Ct.set(e,i);Ct.size>Ia;)Ct.delete(Ct.keys().next().value);return i}function gf(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 Ys=({imageUrl:e,pageData:i,extent:n,selectedCharIds:s,hoveredCharId:o,decorations:a,preserveMargins:l=!1,banxinMode:d="cut",onCharClick:c,onCharHover:m,selectedFigBlock:p,onFigBlockClick:h,renderScale:u=1})=>{var je;const f=!l&&d==="full"&&Ar((je=n==null?void 0:n.views)==null?void 0:je.full),g=b.useMemo(()=>!!((l||f)&&(n!=null&&n.src.url)&&n.src.w>0&&n.src.h>0&&cf(n.H)&&!i.columns.some(L=>{var G;return(((G=L.strips)==null?void 0:G.length)??0)>0})),[l,f,n,i]),y=g?n.src.url:e,S=b.useMemo(()=>g?df(i,n):i,[g,i,n]),[k,x]=b.useState(null),j=b.useMemo(()=>gf(S,k&&k.url===y?k:null),[S,k,y]),[v,$]=b.useState(null),_=b.useRef(null),N=b.useRef(null),I=typeof ResizeObserver<"u",[D,E]=b.useState(null);Ta(()=>{const L=N.current;if(!L||typeof ResizeObserver>"u")return;const G=new ResizeObserver(ie=>{var ce;const te=((ce=ie[ie.length-1])==null?void 0:ce.contentRect.width)??0;E(be=>be===te?be:te)});return G.observe(L),()=>G.disconnect()},[]);const R=!I||D!==null&&D>0,O=b.useRef(null),M=b.useRef(null),q=b.useRef(null),P=b.useRef(null),le=b.useRef(null),[ae,Ce]=b.useState(0),[xe,fe]=b.useState(0),se=b.useRef(""),Re=b.useMemo(()=>Math.max(...j.columns.map(L=>L.warped_h),2440),[j]),H=j.total_warped_w,me=j.banxin,W=b.useMemo(()=>!j.columns.some(L=>{var G;return(((G=L.strips)==null?void 0:G.length)??0)>0}),[j]),K=b.useMemo(()=>{var Fe;if(!l||W)return{top:0,bottom:0,left:0,right:0};const[L,G]=j.image_size||[2386,3082];let ie=1/0,te=-1/0,ce=1/0,be=-1/0;for(const Xe of j.columns)for(const Be of Xe.strips||[])for(const Ke of Be.srcQuad)Ke[0]<ie&&(ie=Ke[0]),Ke[0]>te&&(te=Ke[0]),Ke[1]<ce&&(ce=Ke[1]),Ke[1]>be&&(be=Ke[1]);if((Fe=j.banxin)!=null&&Fe.current_page_strips)for(const Xe of j.banxin.current_page_strips)for(const Be of Xe.srcQuad)Be[0]<ie&&(ie=Be[0]),Be[0]>te&&(te=Be[0]),Be[1]<ce&&(ce=Be[1]),Be[1]>be&&(be=Be[1]);return isFinite(ie)||(ie=0),isFinite(te)||(te=L),isFinite(ce)||(ce=0),isFinite(be)||(be=G),{top:Math.max(0,Math.round(ce)),bottom:Math.max(0,Math.round(G-be)),left:Math.max(0,Math.round(ie)),right:Math.max(0,Math.round(L-te)),rawMinX:ie,rawMaxX:te,rawMinY:ce,rawMaxY:be,imgW:L,imgH:G}},[j,l,W]),re=b.useMemo(()=>{var ce,be;if(!W)return null;const[L,G]=j.image_size||[0,0];if(!(L>0)||!(G>0))return null;if(g&&f&&((ce=n==null?void 0:n.views)!=null&&ce.full)){const Fe=Ra(n.views.full,[n.src.w,n.src.h],j.image_size),Xe=Math.max(0,Fe[0]),Be=Math.max(0,Fe[1]),Ke=Math.min(L,Fe[0]+Fe[2])-Xe,Ye=Math.min(G,Fe[1]+Fe[3])-Be;if(Ke>0&&Ye>0)return{x:Xe,y:Be,w:Ke,h:Ye}}const ie=d==="none"&&Ar((be=n==null?void 0:n.views)==null?void 0:be.none)?n.views.none:n==null?void 0:n.content,te=!g&&n&&Ar(ie)?Ra(ie,i.image_size,j.image_size):null;return!l&&lf(j,v&&v.url===y?v.frame:null,te)||{x:0,y:0,w:L,h:G}},[j,i,l,d,f,W,v,y,n,g]),Y=H+(me?me.total_w:0),T=re?re.w:Y+K.left+K.right,ue=re?re.h:Re+K.top+K.bottom,ye=typeof window<"u"&&window.devicePixelRatio||1,[Ne,B]=I?hf(T,ue,D,ye,u):[Math.round(T),Math.round(ue)],de=b.useCallback(()=>{const L=O.current;if(!(!L||!_.current)&&!(y&&se.current!==y)){if(L.clear(T,ue),l&&K.rawMinX!==void 0&&P.current&&M.current){const{rawMinX:G,rawMaxX:ie,rawMinY:te,rawMaxY:ce,imgW:be,imgH:Fe,top:Xe,bottom:Be,left:Ke,right:Ye}=K,w=[];Ke>0&&w.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[G,0],[G,Fe],[0,Fe]],dstRect:[0,0,Ke,ue]}}),Xe>0&&w.push({colOffsetX:Ke,colOffsetY:0,strip:{srcQuad:[[G,0],[ie,0],[ie,te],[G,te]],dstRect:[0,0,Y,Xe]}}),Be>0&&w.push({colOffsetX:Ke,colOffsetY:Xe+Re,strip:{srcQuad:[[G,ce],[ie,ce],[ie,Fe],[G,Fe]],dstRect:[0,0,Y,Be]}}),Ye>0&&w.push({colOffsetX:Ke+Y,colOffsetY:0,strip:{srcQuad:[[ie,0],[be,0],[be,Fe],[ie,Fe]],dstRect:[0,0,Ye,ue]}}),L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],w,1)}if(P.current&&M.current){const G=j.columns.flatMap(ie=>(ie.strips||[]).map(te=>({colOffsetX:K.left+ie.offset_x,colOffsetY:K.top,strip:te})));if(G.length>0?L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],G,1):L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:re?[[re.x,re.y],[re.x+re.w,re.y],[re.x+re.w,re.y+re.h],[re.x,re.y+re.h]]:[[0,0],[j.image_size[0],0],[j.image_size[0],j.image_size[1]],[0,j.image_size[1]]],dstRect:[0,0,T,ue]}}],1),me&&me.current_page_strips.length>0){const ie=me.current_page_strips.map(te=>({colOffsetX:K.left+H,colOffsetY:K.top,strip:te}));L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],ie,1)}}if(me&&le.current&&q.current&&me.mate_page_strips.length>0){const G=me.mate_page_strips.map(ie=>({colOffsetX:K.left+H+me.half_w,colOffsetY:K.top,strip:ie}));L.renderStripsWithTexture(le.current,T,ue,me.mate_img_size[0],me.mate_img_size[1],G,.65)}}},[y,j,me,T,ue,H,Re,Y,K,l,re]),Me=b.useRef(de);Me.current=de,b.useEffect(()=>{const L=_.current;if(!L)return;const G=ce=>{P.current=M.current?ce.createTexture(M.current):null,le.current=q.current?ce.createTexture(q.current):null,Me.current()};try{const ce=new ts(L);O.current=ce,G(ce)}catch(ce){console.error("Failed to init WebGL renderer:",ce)}const ie=ce=>{ce.preventDefault(),console.warn("WebGL context lost")},te=()=>{console.info("WebGL context restored, re-initializing..."),_.current&&(O.current=new ts(_.current),G(O.current))};return L.addEventListener("webglcontextlost",ie,!1),L.addEventListener("webglcontextrestored",te,!1),()=>{L.removeEventListener("webglcontextlost",ie),L.removeEventListener("webglcontextrestored",te),O.current&&(O.current.deleteTexture(P.current),O.current.deleteTexture(le.current),O.current.destroy(),O.current=null)}},[]),b.useEffect(()=>{if(!y||!R)return;let L=!0;return is(y).then(G=>{if(!L||!G)return;M.current=G,se.current=y,$({url:y,frame:af(G)}),x(te=>te&&te.url===y&&te.w===G.naturalWidth&&te.h===G.naturalHeight?te:{url:y,w:G.naturalWidth,h:G.naturalHeight});const ie=O.current;ie&&(ie.deleteTexture(P.current),P.current=ie.createTexture(G)),Ce(te=>te+1)}),()=>{L=!1}},[y,R]);const Se=me==null?void 0:me.mate_image_url;b.useEffect(()=>{if(!Se||!R)return;let L=!0;return is(Se).then(G=>{if(!L||!G)return;q.current=G;const ie=O.current;ie&&(ie.deleteTexture(le.current),le.current=ie.createTexture(G)),fe(te=>te+1)}),()=>{L=!1}},[Se,R]),Ta(()=>{R&&de()},[de,ae,xe,Ne,B,R]);const Je=b.useMemo(()=>(j.figBlocks??[]).map(L=>{const[G,ie,te,ce]=L.box;return{id:L.id,x:K.left+G-((re==null?void 0:re.x)??0),y:K.top+ie-((re==null?void 0:re.y)??0),w:Math.max(te-G,1),h:Math.max(ce-ie,1)}}),[j,K,re]),X=b.useMemo(()=>{const L=[];for(const G of j.columns)for(const ie of G.chars){const[te,ce,be,Fe]=ie.bbox_col;L.push({id:ie.id,char:ie.char,x:K.left+G.offset_x+te-((re==null?void 0:re.x)??0),y:K.top+ce-((re==null?void 0:re.y)??0),w:Math.max(be-te,1),h:Math.max(Fe-ce,1)})}return L},[j,K,re]);return t.jsxs("div",{ref:N,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${T} / ${ue}`,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:pf(T,ue),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:_,width:Ne,height:B,"data-logical-size":`${Math.floor(T)}x${Math.floor(ue)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:r.bim("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${T} ${ue}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[X.map(L=>{const G=s.has(L.id),ie=o===L.id;return t.jsx("rect",{"data-selected":G?"true":void 0,x:L.x,y:L.y,width:L.w,height:L.h,fill:G?r.bim("warp-sel-bg"):ie?r.bim("warp-hover-bg"):"transparent",stroke:G?r.bim("warp-sel-stroke"):ie?r.bim("warp-hover-stroke"):"transparent",strokeWidth:G?3.5:ie?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>c==null?void 0:c(L.id),onMouseEnter:()=>m==null?void 0:m(L.id),onMouseLeave:()=>m==null?void 0:m(null),children:t.jsx("title",{children:L.char})},L.id)}),a&&a.size>0&&X.map(L=>{const G=a.get(L.id);if(!G)return null;const ie=uf(G),te=Math.max(10,L.w*.42);return t.jsxs("g",{"data-cd":G.tone??"","data-cd-focus":G.focus?"":void 0,pointerEvents:"none",children:[ie.bg&&t.jsx("rect",{x:L.x,y:L.y,width:L.w,height:L.h,fill:ie.bg,fillOpacity:.35}),G.underline&&t.jsx("line",{x1:L.x,x2:L.x+L.w,y1:L.y+L.h,y2:L.y+L.h,stroke:ie.fg,strokeWidth:3,strokeDasharray:G.underline==="dotted"?"2 5":G.underline==="dashed"?"10 6":void 0}),G.focus&&t.jsx("rect",{x:L.x,y:L.y,width:L.w,height:L.h,fill:"none",stroke:r.bim("accent"),strokeWidth:4}),G.sub&&t.jsx("text",{"data-cd-sub":G.sub,x:L.x+L.w,y:L.y+L.h-2,fontSize:te,textAnchor:"end",fill:ie.fg,children:G.sub}),G.insertAfter&&t.jsx("text",{"data-cd-ins":G.insertAfter,x:L.x+L.w/2,y:L.y+L.h+te,fontSize:te,textAnchor:"middle",fill:ie.fg,children:G.insertAfter})]},`cd-${L.id}`)}),Je.map(L=>{const G=p===L.id;return t.jsx("rect",{"data-fig-block":L.id,"data-selected":G?"true":void 0,x:L.x,y:L.y,width:L.w,height:L.h,fill:G?r.bim("warp-sel-bg"):"transparent",stroke:G?r.bim("warp-sel-stroke"):r.bim("warp-hover-stroke"),strokeWidth:G?3.5:2,strokeDasharray:G?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>h==null?void 0:h(L.id),children:t.jsx("title",{children:L.id})},`fig-${L.id}`)}),me&&t.jsxs("g",{children:[t.jsx("line",{x1:K.left+H,y1:K.top,x2:K.left+H,y2:K.top+Re,stroke:r.bim("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:K.left+H+me.half_w,y1:K.top,x2:K.left+H+me.half_w,y2:K.top+Re,stroke:r.bim("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:K.left+Y,y1:K.top,x2:K.left+Y,y2:K.top+Re,stroke:r.bim("warp-banxin-outer"),strokeWidth:1})]})]})]})},Vs=`
|
|
1453
|
+
`;function Na(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 ts{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=Na(n,n.VERTEX_SHADER,ef),o=Na(n,n.FRAGMENT_SHADER,tf);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:v}=u.strip,[k,x,j,S]=v,$=f+k,_=g+x,[N,I,D,E]=y;for(let R=0;R<h;R++){const O=R/h,M=(R+1)/h,q=_+S*O,P=_+S*M,le=[N[0]+(E[0]-N[0])*O,N[1]+(E[1]-N[1])*O],ae=[N[0]+(E[0]-N[0])*M,N[1]+(E[1]-N[1])*M],Ce=[I[0]+(D[0]-I[0])*O,I[1]+(D[1]-I[1])*O],xe=[I[0]+(D[0]-I[0])*M,I[1]+(D[1]-I[1])*M],fe=[$,q],se=[$+j,q],Re=[$,P],H=[$+j,P];m.push(fe[0],fe[1],se[0],se[1],Re[0],Re[1]),p.push(le[0],le[1],Ce[0],Ce[1],ae[0],ae[1]),m.push(se[0],se[1],H[0],H[1],Re[0],Re[1]),p.push(Ce[0],Ce[1],xe[0],xe[1],ae[0],ae[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 za=150,nf=.35,rf=.25,yn=.01,Ca=.25;function sf(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<=yn*n||c>=(1-yn)*n)continue;let m=0,p=0;const h=c*i;for(let u=0;u<i;u++)e[h+u]<za?(p++,p>m&&(m=p)):p=0;m>nf*i&&s.push(c)}if(s.length<2)return null;const o=s[0],a=s[s.length-1]+1;if(a-o<Ca*n)return null;let l=null,d=null;for(let c=0;c<i;c++){if(c<=yn*i||c>=(1-yn)*i)continue;let m=0;for(let p=o;p<a;p++)e[p*i+c]<za&&m++;m/(a-o)>=rf&&(l===null&&(l=c),d=c+1)}return l!==null&&d!==null&&d-l<Ca*i&&(l=null,d=null),{x0:l===null?null:l/i,x1:d===null?null:d/i,y0:o/n,y1:a/n}}const Mr=new WeakMap,of=600;function af(e){if(Mr.has(e))return Mr.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(of,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=sf(m,o,a)}}}catch{i=null}return Mr.set(e,i),i}function lf(e,i,n){const[s,o]=e.image_size||[0,0];if(!(s>0)||!(o>0)||e.columns.some(x=>{var j;return(((j=x.strips)==null?void 0:j.length)??0)>0}))return null;let a=1/0,l=1/0,d=-1/0,c=-1/0;for(const x of e.columns)for(const j of x.chars){const[S,$,_,N]=j.bbox_col;![S,$,_,N].every(Number.isFinite)||!(_>S)||!(N>$)||(a=Math.min(a,x.offset_x+S),l=Math.min(l,$),d=Math.max(d,x.offset_x+_),c=Math.max(c,N))}for(const x of e.figBlocks??[]){const[j,S,$,_]=x.box;![j,S,$,_].every(Number.isFinite)||!($>j)||!(_>S)||(a=Math.min(a,j),l=Math.min(l,S),d=Math.max(d,$),c=Math.max(c,_))}if(!(d>a)||!(c>l))return null;const m=Math.min(s,o)*.03;let p=a-m,h=l-m,u=d+m,f=c+m;if(n&&n.every(Number.isFinite)&&n[2]>0&&n[3]>0){const x=Math.min(s,o)*.005;p=Math.min(a-x,n[0]),h=Math.min(l-x,n[1]),u=Math.max(d+x,n[0]+n[2]),f=Math.max(c+x,n[1]+n[3])}else if(i){const x=Math.min(s,o)*.015;h=Math.min(l-x,i.y0*o-x),f=Math.max(c+x,i.y1*o+x),i.x0!==null&&i.x1!==null&&(p=Math.min(a-x,i.x0*s-x),u=Math.max(d+x,i.x1*s+x))}const g=Math.min(s,Math.max(0,p)),y=Math.min(o,Math.max(0,h)),v=Math.min(s,Math.max(0,u))-g,k=Math.min(o,Math.max(0,f))-y;return!(v>0)||!(k>0)||v>=s*.98&&k>=o*.98?null:{x:g,y,w:v,h:k}}function jn(e,i,n){const s=e[6]*i+e[7]*n+e[8]||1;return[(e[0]*i+e[1]*n+e[2])/s,(e[3]*i+e[4]*n+e[5])/s]}function cf(e){return Array.isArray(e)&&e.length===9&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&Math.abs(e[8])>1e-9}function Ea(e,i,n,s,o){const a=[jn(e,i,n),jn(e,s,n),jn(e,s,o),jn(e,i,o)],l=a.map(c=>c[0]),d=a.map(c=>c[1]);return[Math.min(...l),Math.min(...d),Math.max(...l),Math.max(...d)]}function df(e,i){const n=i.H;return{...e,image_size:[i.src.w,i.src.h],columns:e.columns.map(s=>({...s,offset_x:0,chars:s.chars.map(o=>{const[a,l,d,c]=o.bbox_col,[m,p,h,u]=Ea(n,s.offset_x+a,l,s.offset_x+d,c);return{...o,bbox_col:[m,p,h,u]}})})),...e.figBlocks?{figBlocks:e.figBlocks.map(s=>({...s,box:Ea(n,s.box[0],s.box[1],s.box[2],s.box[3])}))}:{}}}function Ar(e){return Array.isArray(e)&&e.length===4&&e.every(i=>typeof i=="number"&&Number.isFinite(i))&&e[2]>0&&e[3]>0}function Ra(e,i,n){const s=i[0]>0?n[0]/i[0]:1,o=i[1]>0?n[1]/i[1]:1;return[e[0]*s,e[1]*o,e[2]*s,e[3]*o]}const mf={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 uf(e){const i=e.tone&&mf[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 Ta=typeof window>"u"?b.useEffect:b.useLayoutEffect;function pf(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 Lr=[1,1.5,2,3,4,6];function bf(e){for(const i of Lr)if(e<=i)return i;return Lr[Lr.length-1]}function hf(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)*bf(o)/64)*64,l=Math.max(1,Math.min(Math.round(e),a)),d=Math.max(1,Math.round(l*i/e));return[l,d]}const Ct=new Map,Ia=8;let Nn=null;function ff(e){Nn=e}function is(e){let i=Ct.get(e);if(i)return Ct.delete(e),Ct.set(e,i),i;const n=Nn==null?void 0:Nn(e);if(n){for(i=n.then(s=>(s||Ct.delete(e),s),()=>(Ct.delete(e),null)),Ct.set(e,i);Ct.size>Ia;)Ct.delete(Ct.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=()=>{Ct.delete(e),s(null)},o.src=e}),Ct.set(e,i);Ct.size>Ia;)Ct.delete(Ct.keys().next().value);return i}function gf(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 Ys=({imageUrl:e,pageData:i,extent:n,selectedCharIds:s,hoveredCharId:o,decorations:a,preserveMargins:l=!1,banxinMode:d="cut",onCharClick:c,onCharHover:m,selectedFigBlock:p,onFigBlockClick:h,renderScale:u=1})=>{var je;const f=!l&&d==="full"&&Ar((je=n==null?void 0:n.views)==null?void 0:je.full),g=b.useMemo(()=>!!((l||f)&&(n!=null&&n.src.url)&&n.src.w>0&&n.src.h>0&&cf(n.H)&&!i.columns.some(L=>{var G;return(((G=L.strips)==null?void 0:G.length)??0)>0})),[l,f,n,i]),y=g?n.src.url:e,v=b.useMemo(()=>g?df(i,n):i,[g,i,n]),[k,x]=b.useState(null),j=b.useMemo(()=>gf(v,k&&k.url===y?k:null),[v,k,y]),[S,$]=b.useState(null),_=b.useRef(null),N=b.useRef(null),I=typeof ResizeObserver<"u",[D,E]=b.useState(null);Ta(()=>{const L=N.current;if(!L||typeof ResizeObserver>"u")return;const G=new ResizeObserver(ie=>{var ce;const te=((ce=ie[ie.length-1])==null?void 0:ce.contentRect.width)??0;E(be=>be===te?be:te)});return G.observe(L),()=>G.disconnect()},[]);const R=!I||D!==null&&D>0,O=b.useRef(null),M=b.useRef(null),q=b.useRef(null),P=b.useRef(null),le=b.useRef(null),[ae,Ce]=b.useState(0),[xe,fe]=b.useState(0),se=b.useRef(""),Re=b.useMemo(()=>Math.max(...j.columns.map(L=>L.warped_h),2440),[j]),H=j.total_warped_w,me=j.banxin,W=b.useMemo(()=>!j.columns.some(L=>{var G;return(((G=L.strips)==null?void 0:G.length)??0)>0}),[j]),K=b.useMemo(()=>{var Fe;if(!l||W)return{top:0,bottom:0,left:0,right:0};const[L,G]=j.image_size||[2386,3082];let ie=1/0,te=-1/0,ce=1/0,be=-1/0;for(const Xe of j.columns)for(const Be of Xe.strips||[])for(const Ke of Be.srcQuad)Ke[0]<ie&&(ie=Ke[0]),Ke[0]>te&&(te=Ke[0]),Ke[1]<ce&&(ce=Ke[1]),Ke[1]>be&&(be=Ke[1]);if((Fe=j.banxin)!=null&&Fe.current_page_strips)for(const Xe of j.banxin.current_page_strips)for(const Be of Xe.srcQuad)Be[0]<ie&&(ie=Be[0]),Be[0]>te&&(te=Be[0]),Be[1]<ce&&(ce=Be[1]),Be[1]>be&&(be=Be[1]);return isFinite(ie)||(ie=0),isFinite(te)||(te=L),isFinite(ce)||(ce=0),isFinite(be)||(be=G),{top:Math.max(0,Math.round(ce)),bottom:Math.max(0,Math.round(G-be)),left:Math.max(0,Math.round(ie)),right:Math.max(0,Math.round(L-te)),rawMinX:ie,rawMaxX:te,rawMinY:ce,rawMaxY:be,imgW:L,imgH:G}},[j,l,W]),re=b.useMemo(()=>{var ce,be;if(!W)return null;const[L,G]=j.image_size||[0,0];if(!(L>0)||!(G>0))return null;if(g&&f&&((ce=n==null?void 0:n.views)!=null&&ce.full)){const Fe=Ra(n.views.full,[n.src.w,n.src.h],j.image_size),Xe=Math.max(0,Fe[0]),Be=Math.max(0,Fe[1]),Ke=Math.min(L,Fe[0]+Fe[2])-Xe,Ye=Math.min(G,Fe[1]+Fe[3])-Be;if(Ke>0&&Ye>0)return{x:Xe,y:Be,w:Ke,h:Ye}}const ie=d==="none"&&Ar((be=n==null?void 0:n.views)==null?void 0:be.none)?n.views.none:n==null?void 0:n.content,te=!g&&n&&Ar(ie)?Ra(ie,i.image_size,j.image_size):null;return!l&&lf(j,S&&S.url===y?S.frame:null,te)||{x:0,y:0,w:L,h:G}},[j,i,l,d,f,W,S,y,n,g]),Y=H+(me?me.total_w:0),T=re?re.w:Y+K.left+K.right,ue=re?re.h:Re+K.top+K.bottom,ye=typeof window<"u"&&window.devicePixelRatio||1,[Ne,B]=I?hf(T,ue,D,ye,u):[Math.round(T),Math.round(ue)],de=b.useCallback(()=>{const L=O.current;if(!(!L||!_.current)&&!(y&&se.current!==y)){if(L.clear(T,ue),l&&K.rawMinX!==void 0&&P.current&&M.current){const{rawMinX:G,rawMaxX:ie,rawMinY:te,rawMaxY:ce,imgW:be,imgH:Fe,top:Xe,bottom:Be,left:Ke,right:Ye}=K,w=[];Ke>0&&w.push({colOffsetX:0,colOffsetY:0,strip:{srcQuad:[[0,0],[G,0],[G,Fe],[0,Fe]],dstRect:[0,0,Ke,ue]}}),Xe>0&&w.push({colOffsetX:Ke,colOffsetY:0,strip:{srcQuad:[[G,0],[ie,0],[ie,te],[G,te]],dstRect:[0,0,Y,Xe]}}),Be>0&&w.push({colOffsetX:Ke,colOffsetY:Xe+Re,strip:{srcQuad:[[G,ce],[ie,ce],[ie,Fe],[G,Fe]],dstRect:[0,0,Y,Be]}}),Ye>0&&w.push({colOffsetX:Ke+Y,colOffsetY:0,strip:{srcQuad:[[ie,0],[be,0],[be,Fe],[ie,Fe]],dstRect:[0,0,Ye,ue]}}),L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],w,1)}if(P.current&&M.current){const G=j.columns.flatMap(ie=>(ie.strips||[]).map(te=>({colOffsetX:K.left+ie.offset_x,colOffsetY:K.top,strip:te})));if(G.length>0?L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],G,1):L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],[{colOffsetX:0,colOffsetY:0,strip:{srcQuad:re?[[re.x,re.y],[re.x+re.w,re.y],[re.x+re.w,re.y+re.h],[re.x,re.y+re.h]]:[[0,0],[j.image_size[0],0],[j.image_size[0],j.image_size[1]],[0,j.image_size[1]]],dstRect:[0,0,T,ue]}}],1),me&&me.current_page_strips.length>0){const ie=me.current_page_strips.map(te=>({colOffsetX:K.left+H,colOffsetY:K.top,strip:te}));L.renderStripsWithTexture(P.current,T,ue,j.image_size[0],j.image_size[1],ie,1)}}if(me&&le.current&&q.current&&me.mate_page_strips.length>0){const G=me.mate_page_strips.map(ie=>({colOffsetX:K.left+H+me.half_w,colOffsetY:K.top,strip:ie}));L.renderStripsWithTexture(le.current,T,ue,me.mate_img_size[0],me.mate_img_size[1],G,.65)}}},[y,j,me,T,ue,H,Re,Y,K,l,re]),Me=b.useRef(de);Me.current=de,b.useEffect(()=>{const L=_.current;if(!L)return;const G=ce=>{P.current=M.current?ce.createTexture(M.current):null,le.current=q.current?ce.createTexture(q.current):null,Me.current()};try{const ce=new ts(L);O.current=ce,G(ce)}catch(ce){console.error("Failed to init WebGL renderer:",ce)}const ie=ce=>{ce.preventDefault(),console.warn("WebGL context lost")},te=()=>{console.info("WebGL context restored, re-initializing..."),_.current&&(O.current=new ts(_.current),G(O.current))};return L.addEventListener("webglcontextlost",ie,!1),L.addEventListener("webglcontextrestored",te,!1),()=>{L.removeEventListener("webglcontextlost",ie),L.removeEventListener("webglcontextrestored",te),O.current&&(O.current.deleteTexture(P.current),O.current.deleteTexture(le.current),O.current.destroy(),O.current=null)}},[]),b.useEffect(()=>{if(!y||!R)return;let L=!0;return is(y).then(G=>{if(!L||!G)return;M.current=G,se.current=y,$({url:y,frame:af(G)}),x(te=>te&&te.url===y&&te.w===G.naturalWidth&&te.h===G.naturalHeight?te:{url:y,w:G.naturalWidth,h:G.naturalHeight});const ie=O.current;ie&&(ie.deleteTexture(P.current),P.current=ie.createTexture(G)),Ce(te=>te+1)}),()=>{L=!1}},[y,R]);const Se=me==null?void 0:me.mate_image_url;b.useEffect(()=>{if(!Se||!R)return;let L=!0;return is(Se).then(G=>{if(!L||!G)return;q.current=G;const ie=O.current;ie&&(ie.deleteTexture(le.current),le.current=ie.createTexture(G)),fe(te=>te+1)}),()=>{L=!1}},[Se,R]),Ta(()=>{R&&de()},[de,ae,xe,Ne,B,R]);const Je=b.useMemo(()=>(j.figBlocks??[]).map(L=>{const[G,ie,te,ce]=L.box;return{id:L.id,x:K.left+G-((re==null?void 0:re.x)??0),y:K.top+ie-((re==null?void 0:re.y)??0),w:Math.max(te-G,1),h:Math.max(ce-ie,1)}}),[j,K,re]),X=b.useMemo(()=>{const L=[];for(const G of j.columns)for(const ie of G.chars){const[te,ce,be,Fe]=ie.bbox_col;L.push({id:ie.id,char:ie.char,x:K.left+G.offset_x+te-((re==null?void 0:re.x)??0),y:K.top+ce-((re==null?void 0:re.y)??0),w:Math.max(be-te,1),h:Math.max(Fe-ce,1)})}return L},[j,K,re]);return t.jsxs("div",{ref:N,className:"guji-warp-wrapper",style:{position:"relative",maxWidth:"100%",maxHeight:"100%",aspectRatio:`${T} / ${ue}`,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:pf(T,ue),style:{display:"block",width:"100%",height:"100%",visibility:"hidden"}}),t.jsx("canvas",{ref:_,width:Ne,height:B,"data-logical-size":`${Math.floor(T)}x${Math.floor(ue)}`,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block",backgroundColor:r.bim("warp-bg")}}),t.jsxs("svg",{viewBox:`0 0 ${T} ${ue}`,preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",pointerEvents:"none"},children:[X.map(L=>{const G=s.has(L.id),ie=o===L.id;return t.jsx("rect",{"data-selected":G?"true":void 0,x:L.x,y:L.y,width:L.w,height:L.h,fill:G?r.bim("warp-sel-bg"):ie?r.bim("warp-hover-bg"):"transparent",stroke:G?r.bim("warp-sel-stroke"):ie?r.bim("warp-hover-stroke"):"transparent",strokeWidth:G?3.5:ie?2:0,style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>c==null?void 0:c(L.id),onMouseEnter:()=>m==null?void 0:m(L.id),onMouseLeave:()=>m==null?void 0:m(null),children:t.jsx("title",{children:L.char})},L.id)}),a&&a.size>0&&X.map(L=>{const G=a.get(L.id);if(!G)return null;const ie=uf(G),te=Math.max(10,L.w*.42);return t.jsxs("g",{"data-cd":G.tone??"","data-cd-focus":G.focus?"":void 0,pointerEvents:"none",children:[ie.bg&&t.jsx("rect",{x:L.x,y:L.y,width:L.w,height:L.h,fill:ie.bg,fillOpacity:.35}),G.underline&&t.jsx("line",{x1:L.x,x2:L.x+L.w,y1:L.y+L.h,y2:L.y+L.h,stroke:ie.fg,strokeWidth:3,strokeDasharray:G.underline==="dotted"?"2 5":G.underline==="dashed"?"10 6":void 0}),G.focus&&t.jsx("rect",{x:L.x,y:L.y,width:L.w,height:L.h,fill:"none",stroke:r.bim("accent"),strokeWidth:4}),G.sub&&t.jsx("text",{"data-cd-sub":G.sub,x:L.x+L.w,y:L.y+L.h-2,fontSize:te,textAnchor:"end",fill:ie.fg,children:G.sub}),G.insertAfter&&t.jsx("text",{"data-cd-ins":G.insertAfter,x:L.x+L.w/2,y:L.y+L.h+te,fontSize:te,textAnchor:"middle",fill:ie.fg,children:G.insertAfter})]},`cd-${L.id}`)}),Je.map(L=>{const G=p===L.id;return t.jsx("rect",{"data-fig-block":L.id,"data-selected":G?"true":void 0,x:L.x,y:L.y,width:L.w,height:L.h,fill:G?r.bim("warp-sel-bg"):"transparent",stroke:G?r.bim("warp-sel-stroke"):r.bim("warp-hover-stroke"),strokeWidth:G?3.5:2,strokeDasharray:G?void 0:"10 8",style:{pointerEvents:"auto",cursor:"pointer"},onClick:()=>h==null?void 0:h(L.id),children:t.jsx("title",{children:L.id})},`fig-${L.id}`)}),me&&t.jsxs("g",{children:[t.jsx("line",{x1:K.left+H,y1:K.top,x2:K.left+H,y2:K.top+Re,stroke:r.bim("warp-banxin-border"),strokeWidth:1.5}),t.jsx("line",{x1:K.left+H+me.half_w,y1:K.top,x2:K.left+H+me.half_w,y2:K.top+Re,stroke:r.bim("warp-banxin-fold"),strokeWidth:1.5,strokeDasharray:"8 6"}),t.jsx("line",{x1:K.left+Y,y1:K.top,x2:K.left+Y,y2:K.top+Re,stroke:r.bim("warp-banxin-outer"),strokeWidth:1})]})]})]})},Vs=`
|
|
1453
1454
|
.bim-et-w { position: relative; display: inline; }
|
|
1454
1455
|
.bim-et {
|
|
1455
1456
|
color: inherit; text-decoration-line: underline;
|
|
@@ -1537,13 +1538,13 @@ a.bim-et:focus-visible { outline: 2px solid ${r.bim("accent")}; outline-offset:
|
|
|
1537
1538
|
.bim-et-card[data-sheet] { animation: bim-et-up 160ms ease-out; }
|
|
1538
1539
|
@keyframes bim-et-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
|
|
1539
1540
|
}
|
|
1540
|
-
`,xf=120;function Et(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function yf(e,i=xf){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 jf(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 kf(e){if(!Array.isArray(e.authors))return;const i=e.authors.map(n=>{if(!n||typeof n!="object")return"";const s=n,o=Et(s.name);return o?[Et(s.dynasty)&&`〔${Et(s.dynasty)}〕`,o,Et(s.role)].filter(Boolean).join(""):""}).filter(Boolean);return i.length?i.slice(0,3).join("、"):void 0}function Vc(e,i){const n=Et(i.type),s=Et(i.primary_name)??Et(i.title)??e,o=n==="entity"?[Et(i.dynasty),jf(i),Et(i.native_place)].filter(Boolean).join(" · "):[kf(i),Et(i.edition),Et(i.measure_info)].filter(Boolean).join(" · "),a=i.description&&typeof i.description=="object"?Et(i.description.text):Et(i.description);return{id:Et(i.id)??e,type:n,title:s,meta:o||void 0,description:yf(a)}}function Gc(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 qc(e){return async i=>{const n=await e.getItem(i);if(n)return Vc(i,n);if(e.getEntry){const s=await e.getEntry(i);if(s)return Gc(s)}return null}}const Ma=new WeakMap;function Xc(e,i,n){let s=Ma.get(e);s||(s=new Map,Ma.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 Jc=e=>`/item/${encodeURIComponent(e)}`,ns={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Gs=typeof window>"u"?b.useEffect:b.useLayoutEffect;function qs(e,i){return b.useMemo(()=>i?{owner:i,load:i}:e?{owner:e,load:qc(e)}:null,[i,e])}const wf=e=>e,vf=({text:e,entities:i,offsets:n="text",plainBase:s=0,transport:o,loadSummary:a,buildHref:l=Jc,onNavigate:d,renderText:c=wf,hoverDelayMs:m=250,closeDelayMs:p,injectStyles:h=!0,className:u})=>{const f=b.useMemo(()=>{const y=n==="plain"?Hc(e,i,s):i;return Dc(e,y)},[e,i,n,s]),g=qs(o,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[h&&t.jsx("style",{children:Vs}),f.map(y=>y.type==="text"?t.jsx(b.Fragment,{children:c(y.text)},`t${y.start}`):t.jsx(Xs,{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 Xs=({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,S]=b.useState(!1),[k,x]=b.useState(!1),j=b.useRef(!1),v=b.useRef(null),$=b.useRef(null),_=`bim-et bim-et-${e.kind}${s?" bim-et-nu":""}`,N=e.kind==="work"&&!n,I=t.jsxs(t.Fragment,{children:[N&&t.jsx("span",{className:"bim-et-sr",children:"《"}),m(i),N&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),D=()=>{v.current&&(clearTimeout(v.current),v.current=null)},E=()=>{$.current&&(clearTimeout($.current),$.current=null)},R=b.useRef(!1),O=b.useCallback(()=>{R.current=!1,D(),E(),g(!1),S(!1),x(!1),Jt===O&&(Jt=null)},[]);b.useEffect(()=>()=>{D(),E(),Jt===O&&(Jt=null)},[O]);const M=b.useCallback(()=>{Jt&&Jt!==O&&Jt(),Jt=O,g(!0)},[O]),q=b.useCallback(se=>{E(),S(!0),!f&&(D(),se<=0?M():v.current=setTimeout(M,se))},[f,M]),P=b.useCallback(()=>{D(),E(),!R.current&&($.current=setTimeout(O,h))},[O,h]),le=b.useRef(null);b.useEffect(()=>{if(!f||!(e.targets||k))return;const se=k?"click":"pointerdown",Re=H=>{var me;(me=le.current)!=null&&me.contains(H.target)||O()};return document.addEventListener(se,Re),()=>document.removeEventListener(se,Re)},[f,k,e.targets,O]);const ae=b.useCallback(()=>{D(),E(),R.current=!0,S(!0),x(!0),M()},[M]);Gs(()=>{if(!f||!k)return;const se=le.current,Re=se==null?void 0:se.querySelector(".bim-et-card");if(!se||!Re||typeof window>"u")return;const H=()=>{const W=se.getClientRects(),K=W[W.length-1];if(!K)return;const re=K.bottom+12-Re.getBoundingClientRect().top;re>0&&window.scrollBy({top:re,behavior:"smooth"})};if(H(),typeof ResizeObserver>"u")return;const me=new ResizeObserver(H);return me.observe(Re),()=>me.disconnect()},[f,k]);const Ce=!!e.targetId,xe=e.targetId,fe={className:"bim-et-w","data-active":y?"":void 0,onPointerEnter:se=>{j.current=se.pointerType==="touch"},onPointerDown:se=>{j.current=se.pointerType==="touch"},onMouseEnter:()=>{j.current||q(p)},onMouseLeave:()=>{j.current||P()},onBlur:se=>{se.currentTarget.contains(se.relatedTarget)||O()},onKeyDown:se=>{se.key==="Escape"&&f&&(se.stopPropagation(),O())}};return e.targets?t.jsxs("span",{...fe,ref:le,children:[t.jsx("span",{className:`${_} bim-et-multi`,role:"button",tabIndex:0,"aria-haspopup":"true","aria-expanded":f,"aria-controls":f?u:void 0,onFocus:()=>{j.current||q(0)},onClick:()=>{j.current?ae():(E(),R.current=!0,S(!0),M())},onKeyDown:se=>{(se.key==="Enter"||se.key===" ")&&(se.preventDefault(),f?O():(R.current=!0,S(!0),M()))},children:I}),f&&t.jsx(Sf,{id:u,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:k,onClose:O})]}):!Ce||!xe?t.jsxs("span",{...fe,ref:le,children:[t.jsx("span",{className:_,children:I}),f&&!j.current&&t.jsx(Aa,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...fe,ref:le,children:[t.jsx("a",{className:_,href:a(xe),"data-entity-id":xe,"aria-describedby":f?u:void 0,onFocus:()=>{j.current||q(0)},onClick:se=>{if(j.current&&se.detail>0){se.preventDefault(),ae();return}l==null||l(xe,se)},children:I}),f&&t.jsx(Aa,{id:u,entityId:xe,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:k,onClose:O})]})},Aa=({id:e,entityId:i,span:n,loader:s,buildHref:o,onNavigate:a,newTab:l,sheet:d,onClose:c})=>{const{convert:m,t:p}=oe(),h=b.useRef(null),[u,f]=b.useState("start"),[g,y]=b.useState(s&&i?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!s||!i)return;let x=!1;return y({status:"loading"}),Xc(s.owner,s.load,i).then(j=>{x||y({status:"ready",summary:j})}).catch(()=>{x||y({status:"error"})}),()=>{x=!0}},[s,i]),Gs(()=>{const x=h.current;if(!x||typeof window>"u")return;const j=x.getBoundingClientRect(),v=document.documentElement.clientWidth||window.innerWidth;!d&&j.right>v-8&&u==="start"&&f("end")},[g,u,d]);const S=g.status==="ready"?g.summary:null,k=(S==null?void 0:S.title)??n.canonicalName??n.text;return i?t.jsxs("span",{ref:h,id:e,role:d?"dialog":"tooltip","aria-label":d?k:void 0,className:"bim-et-card","data-align":u,"data-sheet":d?"":void 0,children:[d&&c&&t.jsx(Zc,{onClose:c}),t.jsx("span",{className:"bim-et-card-k",children:m(ns[n.kind])}),k&&t.jsx("span",{className:"bim-et-card-t",children:m(k)}),(S==null?void 0:S.meta)&&t.jsx("span",{className:"bim-et-card-m",children:m(S.meta)}),(S==null?void 0:S.description)&&t.jsx("span",{className:"bim-et-card-d",children:m(S.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("摘要載入失敗")}),S&&t.jsx("a",{className:"bim-et-card-a",href:o(S.id||i),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?x=>a(S.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(ns[n.kind])})})},Sf=({id:e,span:i,loader:n,buildHref:s,onNavigate:o,newTab:a,sheet:l,onClose:d})=>{const{convert:c}=oe(),m=b.useRef(null),[p,h]=b.useState(0);Gs(()=>{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(Zc,{onClose:d}),t.jsxs("span",{className:"bim-et-card-k",children:[c("合稱")," · ",c(`${u.length} 條`)]}),u.map(f=>t.jsx($f,{target:f,kind:i.kind,loader:n,buildHref:s,onNavigate:o,newTab:a},f.id))]})},$f=({target:e,kind:i,loader:n,buildHref:s,onNavigate:o,newTab:a})=>{const{convert:l,t:d}=oe(),[c,m]=b.useState(n?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!n)return;let u=!1;return m({status:"loading"}),Xc(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:_f(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(h)}),t.jsx("span",{className:"bim-et-row-k",children:l(ns[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")})]})},_f=(e,i)=>`${i(e)} →`,Zc=({onClose:e})=>{const{t:i}=oe();return t.jsx("button",{type:"button",className:"bim-et-card-x","aria-label":i("reader.close"),onClick:e,children:"×"})},Js=e=>`〔图:${e}〕`,Qc=(e,i)=>e&&i?i(e.file):null;function ed({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:Js(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 Nf({id:e,fig:i,info:n,figUrl:s,cells:o,cont:a,className:l,pageStart:d,children:c}){const{t:m}=oe(),p=(n==null?void 0:n.alt)??"",h=p&&p!==m("reader.figPlain")?m("reader.figLabel",{alt:p}):m("reader.figPlain"),[u,f]=b.useState(!1),g=u||!Qc(n,s);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":Js((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(ed,{fig:i,info:n,figUrl:s,failed:u,onFail:()=>f(!0)})]})}function zf({fig:e,info:i,figUrl:n,onClick:s}){const{t:o}=oe(),a=(i==null?void 0:i.alt)??"图形符号",l=a!==o("reader.figPlain")?o("reader.figLabel",{alt:a}):o("reader.figPlain"),[d,c]=b.useState(!1);return t.jsxs("figure",{className:"guji-fig-block","data-fig-block":e,"data-fig-copy":Js(a),title:l,onClick:s,style:s?{cursor:"pointer"}:void 0,children:[t.jsx(ed,{fig:e,info:i,figUrl:n,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const Cf=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function Ef(e){const i=e.cloneContents();if(!i.querySelector("[data-fig-copy]"))return null;let n="";const s=()=>{n&&!n.endsWith(`
|
|
1541
|
+
`,xf=120;function Et(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function yf(e,i=xf){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 jf(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 kf(e){if(!Array.isArray(e.authors))return;const i=e.authors.map(n=>{if(!n||typeof n!="object")return"";const s=n,o=Et(s.name);return o?[Et(s.dynasty)&&`〔${Et(s.dynasty)}〕`,o,Et(s.role)].filter(Boolean).join(""):""}).filter(Boolean);return i.length?i.slice(0,3).join("、"):void 0}function Vc(e,i){const n=Et(i.type),s=Et(i.primary_name)??Et(i.title)??e,o=n==="entity"?[Et(i.dynasty),jf(i),Et(i.native_place)].filter(Boolean).join(" · "):[kf(i),Et(i.edition),Et(i.measure_info)].filter(Boolean).join(" · "),a=i.description&&typeof i.description=="object"?Et(i.description.text):Et(i.description);return{id:Et(i.id)??e,type:n,title:s,meta:o||void 0,description:yf(a)}}function Gc(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 qc(e){return async i=>{const n=await e.getItem(i);if(n)return Vc(i,n);if(e.getEntry){const s=await e.getEntry(i);if(s)return Gc(s)}return null}}const Ma=new WeakMap;function Xc(e,i,n){let s=Ma.get(e);s||(s=new Map,Ma.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 Jc=e=>`/item/${encodeURIComponent(e)}`,ns={work:"書名",people:"人名",place:"地名",office:"官職",dynasty:"朝代",reign:"年號",other:"專名"},Gs=typeof window>"u"?b.useEffect:b.useLayoutEffect;function qs(e,i){return b.useMemo(()=>i?{owner:i,load:i}:e?{owner:e,load:qc(e)}:null,[i,e])}const wf=e=>e,vf=({text:e,entities:i,offsets:n="text",plainBase:s=0,transport:o,loadSummary:a,buildHref:l=Jc,onNavigate:d,renderText:c=wf,hoverDelayMs:m=250,closeDelayMs:p,injectStyles:h=!0,className:u})=>{const f=b.useMemo(()=>{const y=n==="plain"?Hc(e,i,s):i;return Dc(e,y)},[e,i,n,s]),g=qs(o,a);return t.jsxs("span",{className:u?`bim-et-root ${u}`:"bim-et-root",children:[h&&t.jsx("style",{children:Vs}),f.map(y=>y.type==="text"?t.jsx(b.Fragment,{children:c(y.text)},`t${y.start}`):t.jsx(Xs,{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 Xs=({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,v]=b.useState(!1),[k,x]=b.useState(!1),j=b.useRef(!1),S=b.useRef(null),$=b.useRef(null),_=`bim-et bim-et-${e.kind}${s?" bim-et-nu":""}`,N=e.kind==="work"&&!n,I=t.jsxs(t.Fragment,{children:[N&&t.jsx("span",{className:"bim-et-sr",children:"《"}),m(i),N&&t.jsx("span",{className:"bim-et-sr",children:"》"})]}),D=()=>{S.current&&(clearTimeout(S.current),S.current=null)},E=()=>{$.current&&(clearTimeout($.current),$.current=null)},R=b.useRef(!1),O=b.useCallback(()=>{R.current=!1,D(),E(),g(!1),v(!1),x(!1),Jt===O&&(Jt=null)},[]);b.useEffect(()=>()=>{D(),E(),Jt===O&&(Jt=null)},[O]);const M=b.useCallback(()=>{Jt&&Jt!==O&&Jt(),Jt=O,g(!0)},[O]),q=b.useCallback(se=>{E(),v(!0),!f&&(D(),se<=0?M():S.current=setTimeout(M,se))},[f,M]),P=b.useCallback(()=>{D(),E(),!R.current&&($.current=setTimeout(O,h))},[O,h]),le=b.useRef(null);b.useEffect(()=>{if(!f||!(e.targets||k))return;const se=k?"click":"pointerdown",Re=H=>{var me;(me=le.current)!=null&&me.contains(H.target)||O()};return document.addEventListener(se,Re),()=>document.removeEventListener(se,Re)},[f,k,e.targets,O]);const ae=b.useCallback(()=>{D(),E(),R.current=!0,v(!0),x(!0),M()},[M]);Gs(()=>{if(!f||!k)return;const se=le.current,Re=se==null?void 0:se.querySelector(".bim-et-card");if(!se||!Re||typeof window>"u")return;const H=()=>{const W=se.getClientRects(),K=W[W.length-1];if(!K)return;const re=K.bottom+12-Re.getBoundingClientRect().top;re>0&&window.scrollBy({top:re,behavior:"smooth"})};if(H(),typeof ResizeObserver>"u")return;const me=new ResizeObserver(H);return me.observe(Re),()=>me.disconnect()},[f,k]);const Ce=!!e.targetId,xe=e.targetId,fe={className:"bim-et-w","data-active":y?"":void 0,onPointerEnter:se=>{j.current=se.pointerType==="touch"},onPointerDown:se=>{j.current=se.pointerType==="touch"},onMouseEnter:()=>{j.current||q(p)},onMouseLeave:()=>{j.current||P()},onBlur:se=>{se.currentTarget.contains(se.relatedTarget)||O()},onKeyDown:se=>{se.key==="Escape"&&f&&(se.stopPropagation(),O())}};return e.targets?t.jsxs("span",{...fe,ref:le,children:[t.jsx("span",{className:`${_} bim-et-multi`,role:"button",tabIndex:0,"aria-haspopup":"true","aria-expanded":f,"aria-controls":f?u:void 0,onFocus:()=>{j.current||q(0)},onClick:()=>{j.current?ae():(E(),R.current=!0,v(!0),M())},onKeyDown:se=>{(se.key==="Enter"||se.key===" ")&&(se.preventDefault(),f?O():(R.current=!0,v(!0),M()))},children:I}),f&&t.jsx(Sf,{id:u,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:k,onClose:O})]}):!Ce||!xe?t.jsxs("span",{...fe,ref:le,children:[t.jsx("span",{className:_,children:I}),f&&!j.current&&t.jsx(Aa,{id:u,entityId:null,span:e,loader:null,buildHref:a,onNavigate:l})]}):t.jsxs("span",{...fe,ref:le,children:[t.jsx("a",{className:_,href:a(xe),"data-entity-id":xe,"aria-describedby":f?u:void 0,onFocus:()=>{j.current||q(0)},onClick:se=>{if(j.current&&se.detail>0){se.preventDefault(),ae();return}l==null||l(xe,se)},children:I}),f&&t.jsx(Aa,{id:u,entityId:xe,span:e,loader:o,buildHref:a,onNavigate:c?void 0:d,newTab:c,sheet:k,onClose:O})]})},Aa=({id:e,entityId:i,span:n,loader:s,buildHref:o,onNavigate:a,newTab:l,sheet:d,onClose:c})=>{const{convert:m,t:p}=oe(),h=b.useRef(null),[u,f]=b.useState("start"),[g,y]=b.useState(s&&i?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!s||!i)return;let x=!1;return y({status:"loading"}),Xc(s.owner,s.load,i).then(j=>{x||y({status:"ready",summary:j})}).catch(()=>{x||y({status:"error"})}),()=>{x=!0}},[s,i]),Gs(()=>{const x=h.current;if(!x||typeof window>"u")return;const j=x.getBoundingClientRect(),S=document.documentElement.clientWidth||window.innerWidth;!d&&j.right>S-8&&u==="start"&&f("end")},[g,u,d]);const v=g.status==="ready"?g.summary:null,k=(v==null?void 0:v.title)??n.canonicalName??n.text;return i?t.jsxs("span",{ref:h,id:e,role:d?"dialog":"tooltip","aria-label":d?k:void 0,className:"bim-et-card","data-align":u,"data-sheet":d?"":void 0,children:[d&&c&&t.jsx(Zc,{onClose:c}),t.jsx("span",{className:"bim-et-card-k",children:m(ns[n.kind])}),k&&t.jsx("span",{className:"bim-et-card-t",children:m(k)}),(v==null?void 0:v.meta)&&t.jsx("span",{className:"bim-et-card-m",children:m(v.meta)}),(v==null?void 0:v.description)&&t.jsx("span",{className:"bim-et-card-d",children:m(v.description)}),g.status==="loading"&&t.jsx("span",{className:"bim-et-card-s",children:m("載入中…")}),g.status==="error"&&t.jsx("span",{className:"bim-et-card-s",children:m("摘要載入失敗")}),v&&t.jsx("a",{className:"bim-et-card-a",href:o(v.id||i),...l?{target:"_blank",rel:"noopener"}:{},onClick:a?x=>a(v.id||i,x):void 0,children:p("reader.entityDetail")})]}):t.jsx("span",{ref:h,id:e,role:"tooltip",className:"bim-et-card","data-align":u,children:t.jsx("span",{className:"bim-et-card-k",children:m(ns[n.kind])})})},Sf=({id:e,span:i,loader:n,buildHref:s,onNavigate:o,newTab:a,sheet:l,onClose:d})=>{const{convert:c}=oe(),m=b.useRef(null),[p,h]=b.useState(0);Gs(()=>{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(Zc,{onClose:d}),t.jsxs("span",{className:"bim-et-card-k",children:[c("合稱")," · ",c(`${u.length} 條`)]}),u.map(f=>t.jsx($f,{target:f,kind:i.kind,loader:n,buildHref:s,onNavigate:o,newTab:a},f.id))]})},$f=({target:e,kind:i,loader:n,buildHref:s,onNavigate:o,newTab:a})=>{const{convert:l,t:d}=oe(),[c,m]=b.useState(n?{status:"loading"}:{status:"ready",summary:null});b.useEffect(()=>{if(!n)return;let u=!1;return m({status:"loading"}),Xc(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:_f(e.part,l)}),t.jsx("span",{className:"bim-et-card-t",children:l(h)}),t.jsx("span",{className:"bim-et-row-k",children:l(ns[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")})]})},_f=(e,i)=>`${i(e)} →`,Zc=({onClose:e})=>{const{t:i}=oe();return t.jsx("button",{type:"button",className:"bim-et-card-x","aria-label":i("reader.close"),onClick:e,children:"×"})},Js=e=>`〔图:${e}〕`,Qc=(e,i)=>e&&i?i(e.file):null;function ed({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:Js(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 Nf({id:e,fig:i,info:n,figUrl:s,cells:o,cont:a,className:l,pageStart:d,children:c}){const{t:m}=oe(),p=(n==null?void 0:n.alt)??"",h=p&&p!==m("reader.figPlain")?m("reader.figLabel",{alt:p}):m("reader.figPlain"),[u,f]=b.useState(!1),g=u||!Qc(n,s);return t.jsxs("span",{"data-char-id":e,"data-page-start":d,"data-fig-copy":a?"":Js((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(ed,{fig:i,info:n,figUrl:s,failed:u,onFail:()=>f(!0)})]})}function zf({fig:e,info:i,figUrl:n,onClick:s}){const{t:o}=oe(),a=(i==null?void 0:i.alt)??"图形符号",l=a!==o("reader.figPlain")?o("reader.figLabel",{alt:a}):o("reader.figPlain"),[d,c]=b.useState(!1);return t.jsxs("figure",{className:"guji-fig-block","data-fig-block":e,"data-fig-copy":Js(a),title:l,onClick:s,style:s?{cursor:"pointer"}:void 0,children:[t.jsx(ed,{fig:e,info:i,figUrl:n,block:!0,failed:d,onFail:()=>c(!0)}),t.jsx("figcaption",{className:"guji-fig-caption",children:a})]})}const Cf=new Set(["P","H1","H2","H3","H4","H5","H6","FIGURE","SECTION","DIV","LI"]);function Ef(e){const i=e.cloneContents();if(!i.querySelector("[data-fig-copy]"))return null;let n="";const s=()=>{n&&!n.endsWith(`
|
|
1541
1542
|
`)&&(n+=`
|
|
1542
|
-
`)},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=Cf.has(l.tagName);c&&s(),l.childNodes.forEach(o),c&&s();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const Rf=e=>`/item/${encodeURIComponent(e)}`;function Tf(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 If(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 Zs=({pageData:e,pages:i,punctuations:n=rs,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:S,loadEntitySummary:k,buildEntityHref:x,onEntityNavigate:j,pageBreaks:v=!0,pageIndicatorY:$,onPageIndicatorYChange:_,quoteStyle:N,bookTitleStyle:I,showWorks:D,figures:E,figUrl:R,onFigureBlockClick:O,decorations:M})=>{var bt,Ue,ft;const{t:q}=oe(),P=b.useRef(null),le=b.useRef(0),ae=b.useMemo(()=>{const Q=new Map;return m&&n.forEach((A,ne)=>{const $e=A.id?A:{...A,id:`${A.anchor}#${ne}`},Ie=Q.get($e.anchor)||[];Ie.push($e),Q.set($e.anchor,Ie)}),Q},[n,m]),Ce=b.useMemo(()=>N===void 0&&I===void 0&&D===void 0?null:{quoteStyle:N??"original",hideBookBrackets:I==="wavy"||D===!1},[N,I,D]),xe=I==="bracket",fe=b.useMemo(()=>{var qe;const Q=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],A=new Map;for(const Ae of Q)for(const Ee of Ae.columns)Ee.chars.length>0&&!Ee.raised&&A.set(Ee.lead_blank||0,(A.get(Ee.lead_blank||0)||0)+1);let ne=0,$e=-1;for(const[Ae,Ee]of A)(Ee>$e||Ee===$e&&Ae<ne)&&(ne=Ae,$e=Ee);const Ie=Ae=>!!Ae.raised||(Ae.lead_blank||0)<ne,Oe=Q.filter(Ae=>Ae.columns.some(Ee=>Ee.chars.length>0||Ee.kind==="figure")).map(Ae=>{const Ee=[...Ae.columns].sort((nt,Pt)=>nt.col-Pt.col),rt=[];let st=[];const Ve=()=>{const nt=Uf(ae.get(st[0].charData.id));rt.push({id:`para-p${Ae.page}-${rt.length}`,chars:st,...nt?{heading:{level:nt.mark.length,anchor:st[0].charData.id,...nt.toc===!1?{toc:!1}:{}}}:{}}),st=[]};let F=!1,ke=0,Ze;const Ge=[];for(const nt of Ee){if(nt.kind==="figure"&&nt.fig){st.length>0?Ve():rt.length===0&&(F=!0),Ge.push({before:rt.length,fig:nt.fig,...nt.figBox?{box:nt.figBox}:{}}),ke=0;continue}if(nt.chars.length===0){nt.kind==="blank"&&ke++;continue}const Pt=nt.raised||nt.lead_blank||ke?{raised:nt.raised,leadBlank:nt.lead_blank,blankBefore:ke}:void 0;ke=0,Ie(nt)||(Ze=nt.lead_blank||0);let ct=!0;for(const St of nt.chars){const Ot=ae.get(St.id),{before:zt,after:lr}=Ot?Tf(Ot):Pf,sn=!!Ot&&Ot.some(ni=>ni.kind==="break"&&ni.pos!=="before");Ot&&Ot.some(ni=>ni.kind==="heading")&&(st.length>0?Ve():rt.length===0&&(F=!0)),st.push({charData:St,col:nt.col,beforePuncts:zt,afterPuncts:lr,...ct&&Pt?{start:Pt}:{}}),ct=!1,sn&&Ve()}}const kt=st.length>0;return kt&&Ve(),{page:Ae.page,paragraphs:rt,endsOpen:kt,...Ze!==void 0?{tailLead:Ze}:{},...F?{leadStarts:F}:{},...Ae.label?{label:Ae.label}:{},...ke>0?{trailingBlank:ke}:{},...Ge.length>0?{blocks:Ge}:{}}}),at=new Map;if(!v){let Ae=null;for(const Ee of Oe){const rt=Ee.paragraphs[0],st=(qe=rt==null?void 0:rt.chars[0])==null?void 0:qe.start,Ve=(st==null?void 0:st.leadBlank)||0,F=!!st&&!st.raised&&Ve>=ne&&Ve>((Ae==null?void 0:Ae.tailLead)??ne),ke=!!Ee.leadStarts||!!(st!=null&&st.blankBefore)||F,Ze=Ee.paragraphs.length===1&&!!Ee.trailingBlank;if(Ae&&rt&&!ke&&!Ze){for(const Ge of rt.chars)at.set(Ge.charData.id,Ae.owner);Ae.para.chars=Ae.para.chars.concat(rt.chars),Ee.leadFirstId=rt.chars[0].charData.id,Ee.paragraphs=Ee.paragraphs.slice(1),Ee.blocks&&(Ee.blocks=Ee.blocks.map(Ge=>({...Ge,before:Ge.before-1})))}if(Ee.endsOpen&&!Ee.trailingBlank){const Ge=Ee.paragraphs[Ee.paragraphs.length-1];Ge?Ae={para:Ge,owner:Ee.page,tailLead:Ee.tailLead??(Ae==null?void 0:Ae.tailLead)??ne}:Ae&&Ee.tailLead!==void 0&&(Ae.tailLead=Ee.tailLead)}else Ae=null}}const lt=new Map;for(const Ae of Oe)Ae.leadFirstId&<.set(Ae.leadFirstId,Ae.page);return{pages:Oe,mergedOwner:at,pageStarts:lt}},[i,e,ae,v]),se=fe.pages,Re=b.useRef(se);Re.current=se;const H=b.useMemo(()=>se.map(Q=>Q.paragraphs.reduce((A,ne)=>A+ne.chars.length,0)),[se]),me=b.useCallback((Q,A)=>{let ne=Q,$e=0;for(;ne<H.length&&(ne===Q||$e+H[ne]<=A);)$e+=H[ne++];return ne},[H]),W=`${se.length}:${((ft=(Ue=(bt=se[0])==null?void 0:bt.paragraphs[0])==null?void 0:Ue.chars[0])==null?void 0:ft.charData.id)??""}`,[K,re]=b.useState(()=>({sig:W,n:me(0,Pa)}));let Y=K.n;K.sig!==W&&(Y=me(0,Pa),re({sig:W,n:Y})),Y=Math.min(Y,se.length);const T=Y>=se.length;b.useEffect(()=>T?void 0:(A=>{const ne=window;if(ne.requestIdleCallback){const Ie=ne.requestIdleCallback(A,{timeout:300});return()=>{var Oe;return(Oe=ne.cancelIdleCallback)==null?void 0:Oe.call(ne,Ie)}}const $e=setTimeout(A,16);return()=>clearTimeout($e)})(()=>re(A=>A.sig===W?{sig:A.sig,n:Math.max(A.n,me(A.n,Mf))}:A)),[T,Y,W,me]);const ue=b.useCallback(Q=>{const A=Re.current.findIndex($e=>$e.page>=Q),ne=(A<0?Re.current.length:A)+2;re($e=>$e.n>=ne?$e:{...$e,n:ne})},[]),ye=T?se:se.slice(0,Y);b.useEffect(()=>{let Q;const A=requestAnimationFrame(()=>{Q=setTimeout(()=>{const ne=P.current,$e=ne==null?void 0:ne.querySelector(".guji-reflow-paragraph");if(!ne||!$e)return;const Ie=getComputedStyle($e),Oe=parseFloat(Ie.fontSize),at=$e.clientWidth;if(!(Oe>0)||!(at>0))return;const lt=parseFloat(Ie.lineHeight);ne.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(at/Oe)))),ne.style.setProperty("--gtv-lh",`${Math.round(lt>0?lt:Oe*2)}px`)},0)});return()=>{cancelAnimationFrame(A),Q&&clearTimeout(Q)}},[W]);const Ne=b.useMemo(()=>{const Q=[];for(const A of se)for(const ne of A.paragraphs)for(const $e of ne.chars)Q.push($e.charData.id);return Q},[se]),B=b.useMemo(()=>new Map(Ne.map((Q,A)=>[Q,A])),[Ne]),de=b.useMemo(()=>{const Q=new Map;if(!y||y.length===0)return Q;const A=B;for(const ne of y){if(!ne.anchor)continue;const $e=A.get(ne.anchor.start),Ie=A.get(ne.anchor.end);if(!($e===void 0||Ie===void 0||Ie<$e))for(let Oe=$e;Oe<=Ie;Oe++)Q.has(Ne[Oe])||Q.set(Ne[Oe],ne)}return Q},[y,Ne,B]),Me=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]),Se=b.useMemo(()=>{var $e;if(!Me||!y)return[];const Q=new Set,A=[],ne=(Ie,Oe)=>{const at=`${Ie}:${Oe}`;Q.has(at)||(Q.add(at),A.push([Ie,Oe]))};for(const Ie of y){if(!Ie.anchor)continue;const Oe=B.get(Ie.anchor.start),at=B.get(Ie.anchor.end);if(!(Oe===void 0||at===void 0||at<Oe)){(Ie.targetId&&Me.has(Ie.targetId)||($e=Ie.targets)!=null&&$e.some(lt=>Me.has(lt.id)))&&ne(Oe,at);for(const lt of Ie.parts??[]){if(!Me.has(lt.id))continue;const qe=Oe+lt.offset[0],Ae=Oe+lt.offset[1]-1;Ae>=qe&&Ae<=at&&ne(qe,Ae)}}}return A.sort((Ie,Oe)=>Ie[0]-Oe[0]||Ie[1]-Oe[1])},[Me,y,B]),Je=qs(S,k),X=de.size>0,je=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:O});je.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:O};const L=b.useMemo(()=>({click:Q=>{var A,ne;le.current=Date.now()+1200,(ne=(A=je.current).onCharClick)==null||ne.call(A,Q)},enter:Q=>{var A,ne;return(ne=(A=je.current).onCharHover)==null?void 0:ne.call(A,Q)},leave:()=>{var Q,A;return(A=(Q=je.current).onCharHover)==null?void 0:A.call(Q,null)},figBlock:Q=>{var A,ne;return(ne=(A=je.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"))}}),[]),G=Wf(s,fe.mergedOwner),ie=Df(M,fe.mergedOwner),te=b.useRef(Y);te.current=Y;const ce=b.useRef(null),be=b.useCallback(Q=>{const A=ce.current,ne=A==null?void 0:A.map.get(Q);if(ne&&ne.isConnected)return ne;if(A&&A.for===Re.current&&A.n===te.current&&!ne)return null;const $e=P.current;if(!$e)return null;const Ie=new Map;return $e.querySelectorAll("span[data-char-id]").forEach(Oe=>{Ie.set(Oe.getAttribute("data-char-id"),Oe)}),ce.current={for:Re.current,n:te.current,map:Ie},Ie.get(Q)??null},[]),Fe=b.useRef(null);b.useEffect(()=>{var A;if((A=Fe.current)==null||A.classList.remove("is-hovered"),Fe.current=null,!o)return;const Q=be(o);Q&&(Q.classList.add("is-hovered"),Fe.current=Q)},[o,be]);const Xe=b.useRef(null),Be=Q=>{var ne;const A=Q instanceof Element?Q.closest("span[data-char-id]"):null;return A&&((ne=P.current)!=null&&ne.contains(A))?A.getAttribute("data-char-id"):null},Ke=Q=>{const A=Be(Q.target);A&&L.click(A)},Ye=Q=>{const A=Be(Q.target);A!==Xe.current&&(Xe.current=A,A?L.enter(A):L.leave())},w=Q=>{const A=typeof window<"u"?window.getSelection():null;if(!A||A.isCollapsed||A.rangeCount===0)return;const ne=Ef(A.getRangeAt(0));ne!==null&&(Q.clipboardData.setData("text/plain",ne),Q.preventDefault())},ee=()=>{Xe.current!==null&&(Xe.current=null,L.leave())};b.useEffect(()=>{let Q=null;const A=()=>{var ke,Ze;Q=null;const $e=window.getSelection(),Ie=P.current;if(!$e||$e.isCollapsed||$e.rangeCount===0||!Ie)return;const Oe=$e.getRangeAt(0),at=Oe.commonAncestorContainer,lt=at.nodeType===3?at.parentElement:at;if(!lt||!Ie.contains(lt))return;const qe=Ie.querySelectorAll("span[data-char-id]"),Ae=Ge=>{let kt=Ge;for(;kt.nodeType!==3&&kt.firstChild;)kt=kt.firstChild;return kt};let Ee=0,rt=qe.length;for(;Ee<rt;){const Ge=Ee+rt>>1;Oe.comparePoint(Ae(qe[Ge]),0)<0?Ee=Ge+1:rt=Ge}const st=Ee;for(rt=qe.length;Ee<rt;){const Ge=Ee+rt>>1;Oe.comparePoint(Ae(qe[Ge]),0)<=0?Ee=Ge+1:rt=Ge}let Ve=Ee-1;if(Ve>=st&&Oe.endOffset===0&&Oe.endContainer===Ae(qe[Ve])&&Ve--,Ve<st)return;const F=[];for(let Ge=st;Ge<=Ve;Ge++)F.push(qe[Ge].getAttribute("data-char-id"));F.length>0&&(le.current=Date.now()+1200,(Ze=(ke=je.current).onSelectionChange)==null||Ze.call(ke,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=be(Q);if(A)Z.current=s,A.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ne=parseInt(Q.split(":")[0],10);isNaN(ne)||ue(ne)}},[s,Y,be,ue]);const he=Q=>{var $e;const A=P.current;if(!A)return null;const ne=($e=se.find(Ie=>Ie.page===Q))==null?void 0:$e.leadFirstId;return ne?A.querySelector(`span[data-char-id="${ne}"]`):A.querySelector(`[data-page-section="${Q}"]`)},Le=u==null?void 0:u.nonce,C=b.useRef(null);b.useEffect(()=>{if(!u||C.current===u.nonce)return;const Q=he(u.page);if(!Q){!T&&se.some(A=>A.page>=u.page)&&ue(u.page);return}C.current=u.nonce,le.current=Date.now()+800,Q.scrollIntoView({behavior:"auto",block:"start"})},[Le,Y]);const ge=b.useRef(null),V=b.useRef([]);b.useEffect(()=>{var Oe,at,lt;if(!f||ge.current===f.nonce||f.anchor.startsWith("e="))return;const[Q,A]=f.anchor.split("~"),ne=P.current,$e=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(Q)}"]`),Ie=parseInt(Q.split(":")[0],10);if(!$e){if(!T&&!isNaN(Ie)&&se.some(qe=>qe.page>=Ie)){ue(Ie);return}A&&!isNaN(Ie)&&(ge.current=f.nonce,(Oe=he(Ie))==null||Oe.scrollIntoView({behavior:"auto",block:"start"}));return}ge.current=f.nonce,le.current=Date.now()+800;for(const qe of V.current)qe.classList.remove("guji-hl");if(V.current=[],A){const qe=B.get(Q),Ae=B.get(A);if(qe!==void 0&&Ae!==void 0&&Ae>=qe&&Ae-qe<64)for(let Ee=qe;Ee<=Ae;Ee++){const rt=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(Ne[Ee])}"]`);rt&&(rt.classList.add("guji-hl"),V.current.push(rt))}La($e,le)}else($e.closest(".guji-reflow-paragraph")??$e).scrollIntoView({behavior:"auto",block:"start"});isNaN(Ie)||(lt=(at=je.current).onVisiblePageChange)==null||lt.call(at,Ie)},[f,se,Y,T,ue,Ne,B]);const[ze,we]=b.useState(null),[Te,tt]=b.useState(!1),Pe=b.useRef(null);b.useEffect(()=>{!f||!Me||Pe.current===f.nonce||Se.length===0||(Pe.current=f.nonce,tt(!1),we({k:0,nonce:Date.now()}))},[f,Me,Se]);const it=b.useRef(null);b.useEffect(()=>{var Oe,at;if(!ze||it.current===ze.nonce)return;const Q=Se[ze.k];if(!Q)return;const A=P.current,ne=Ne[Q[0]],$e=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ne)}"]`),Ie=parseInt(ne.split(":")[0],10);if(!$e){!T&&!isNaN(Ie)&&ue(Ie);return}it.current=ze.nonce;for(const lt of V.current)lt.classList.remove("guji-hl");V.current=[];for(let lt=Q[0];lt<=Q[1];lt++){const qe=A==null?void 0:A.querySelector(`span[data-char-id="${Li(Ne[lt])}"]`);qe&&(qe.classList.add("guji-hl"),V.current.push(qe))}La($e,le),isNaN(Ie)||(at=(Oe=je.current).onVisiblePageChange)==null||at.call(Oe,Ie)},[ze,Se,Ne,Y,T,ue]);const yt=b.useMemo(()=>{if(!Me||Te||Se.length===0)return"";const Q=[];for(const[A,ne]of Se)for(let $e=A;$e<=ne;$e++)Q.push(`.guji-text-pane-content span[data-char-id="${Li(Ne[$e])}"]`);return`${Q.join(",")}{background:${r.bim("mark-soft")};border-radius:2px}`},[Me,Te,Se,Ne]),De=Q=>we(A=>{const ne=Se.length;return{k:(((A==null?void 0:A.k)??0)+Q+ne)%ne,nonce:Date.now()}}),J=()=>{tt(!0);for(const Q of V.current)Q.classList.remove("guji-hl");V.current=[]},ve=!!p||!!g,Qe=!!p&&typeof $=="number",[et,We]=b.useState(null),He=ss(et??$??0),ut=b.useRef(null);ut.current=Qe?He:null;const pt=b.useRef(()=>{});return b.useEffect(()=>{var rt,st;if(!ve)return;const Q=new Map,A=new Map;(rt=P.current)==null||rt.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ve=>{const F=Ve.getAttribute("data-page-section");F!==null?Q.set(F,Ve):A.set(Ve.getAttribute("data-page-start"),Ve)});const ne=[],$e=[];for(const Ve of ye){const F=Q.get(String(Ve.page));F&&(ne.push(F),$e.push(Ve.page))}if(ne.length===0)return;const Ie=new Map(ne.map((Ve,F)=>[Ve,F])),Oe=ne.map(()=>[]);let at=0;(st=P.current)==null||st.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ve=>{const F=Ie.get(Ve.closest("[data-page-section]"));F!==void 0&&(Oe[F].push(Ve),at++)});let lt,qe=0;const Ae=()=>{var nt,Pt;if(qe=0,Date.now()<le.current)return;const Ve=ct=>ct.getBoundingClientRect().top;if(ne.length>1&&Ve(ne[0])===Ve(ne[ne.length-1]))return;const F=ut.current===null?120:ut.current*window.innerHeight;let ke=0,Ze=ne.length-1;for(;ke<Ze;){const ct=ke+Ze+1>>1;Ve(ne[ct])<=F?ke=ct:Ze=ct-1}const Ge=Ve(ne[0])>F;let kt=$e[ke];for(let ct=ke+1;ct<ne.length;ct++){const St=A.get(String($e[ct]));if(!St||!ne[ke].contains(St)||Ve(St)>F)break;kt=$e[ct]}if(at>0&&je.current.onVisibleHeadingChange){let ct=null;if(!Ge){const Ot=Oe[ke];for(let zt=Ot.length-1;zt>=0&&!ct;zt--)Ve(Ot[zt])<=F&&(ct=Ot[zt]);for(let zt=ke-1;zt>=0&&!ct;zt--)Oe[zt].length>0&&(ct=Oe[zt][Oe[zt].length-1])}const St=ct?Kf(ct):null;St!==lt&&(lt=St,je.current.onVisibleHeadingChange(St))}(Pt=(nt=je.current).onVisiblePageChange)==null||Pt.call(nt,kt)},Ee=()=>{qe||(qe=requestAnimationFrame(Ae))};return pt.current=()=>{qe||(qe=requestAnimationFrame(Ae))},window.addEventListener("scroll",Ee,{passive:!0}),Ee(),()=>{window.removeEventListener("scroll",Ee),qe&&cancelAnimationFrame(qe),pt.current=()=>{}}},[ve,se,Y]),b.useEffect(()=>{Qe&&pt.current()},[Qe,He]),t.jsxs("div",{ref:P,className:"guji-text-pane-content",onClick:Ke,onMouseOver:Ye,onMouseLeave:ee,onCopy:w,children:[X&&t.jsx("style",{children:Vs}),yt&&t.jsx("style",{children:yt}),yt&&ze&&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:ze.k+1,n:Se.length})}),t.jsx("button",{type:"button",onClick:()=>De(-1),"aria-label":q("mentions.prev"),title:q("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>De(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:"×"})]}),Qe&&t.jsx(Jf,{y:He,containerRef:P,onDrag:We,onCommit:Q=>{We(null),_==null||_(Q)}}),t.jsx("div",{className:"guji-text-reflow-view",children:ye.map((Q,A)=>t.jsx(Gf,{pGroup:Q,first:A===0,pageBreaks:v,markOpts:Ce,plainBooks:xe,selected:G.get(Q.page)??Lf,decorations:ie.get(Q.page),entityOfChar:de,entityLoader:Je,convert:h,buildHref:x??Rf,handlers:L,charCount:H[A]??0,pageStarts:fe.pageStarts,figures:E,figUrl:R},`page-sec-${Q.page}`))})]})};function La(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 Pa=1800,Mf=800,Af="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",Lf=new Set,rs=[],Pf={before:rs,after:rs},Of={};function Ff(e){if(!e)return Of;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 Bf(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function Hf(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function Df(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&&jh(h,p)});s.set(l,c?d:a)})}return n.current=s,s},[e,i])}function Wf(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 Uf(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function Kf(e){return e.getAttribute("data-heading-anchor")}function Li(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Oa({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 Yf(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 Vf({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 Gf=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:S}){const k=b.useMemo(()=>{const _=new Map;if(!p)return _;for(const N of i.paragraphs){const I=Yf(N.chars.map(D=>D.charData.fig?D.charData.char:D.charData.norm??D.charData.char),p);N.chars.forEach((D,E)=>_.set(D.charData.id,D.charData.fig?D.charData.char:I[E]))}return _},[i,p]),x=_=>k.get(_.id)??_.char,{t:j}=oe(),v=_=>{const N=o?Lc(_.mark,o):_.mark;return N?t.jsx("span",{className:"guji-text-punct","data-punct-id":_.id,children:N},_.id):null},$=_=>{var N;return(N=i.blocks)==null?void 0:N.map((I,D)=>I.before===_&&t.jsx(zf,{fig:I.fig,info:y==null?void 0:y.get(I.fig),figUrl:S,onClick:()=>u.figBlock({page:i.page,fig:I.fig,...I.box?{box:I.box}:{}})},`fig-${I.fig}-${D}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:Af,"--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:[$(N),t.jsxs(Vf,{heading:_.heading,children:[If(_.chars,c).map((I,D)=>{const E=I.chars.map(({charData:M,beforePuncts:q,afterPuncts:P,start:le},ae)=>{var W,K,re;const Ce=!!I.entity&&ae===0,xe=!!I.entity&&ae===I.chars.length-1,fe=Ce?[]:q,se=xe?[]:P,Re=!!M.fig&&ae>0&&I.chars[ae-1].charData.fig===M.fig;let H=1;if(M.fig&&!Re)for(;((W=I.chars[ae+H])==null?void 0:W.charData.fig)===M.fig;)H++;const me=`guji-text-char${l.has(M.id)?" is-selected":""}${M.sub?" is-sub":""}${M.lane==="solo"?" is-solo":""}${le!=null&&le.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[le&&le.blankBefore>0&&t.jsx(Oa,{n:le.blankBefore}),fe.map(v),M.fig?t.jsx(Nf,{id:M.id,fig:M.fig,info:y==null?void 0:y.get(M.fig),figUrl:S,cells:H,cont:Re,className:me,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),...Ff(d==null?void 0:d.get(M.id)),style:Bf(d==null?void 0:d.get(M.id)),className:`guji-text-char${Hf(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":""}${le!=null&&le.raised?" is-raised":""}`,"data-raised":(le==null?void 0:le.raised)||void 0,"data-guji-guess":M.lacuna&&M.guess_c?M.guess_c:void 0,title:((K=d==null?void 0:d.get(M.id))==null?void 0:K.title)??(M.pending?j("reader.pendingReason",{label:p?p(_e.pendingReasonLabel(M.pending)):_e.pendingReasonLabel(M.pending)}):M.lacuna?M.guess_c?j("reader.lacunaGuess",{guess:p?p(M.guess_c):M.guess_c}):j("detail.lacuna"):M.zi?j("detail.composedChar",{label:M.zi}):M.guess?j("reader.charGuess"):void 0),children:x(M)}),((re=d==null?void 0:d.get(M.id))==null?void 0:re.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(M.id).insertAfter})]}),se.map(v)]},M.id)});if(!I.entity)return t.jsx(b.Fragment,{children:E},`r${D}`);const R=I.chars[0].beforePuncts.map(v),O=I.chars[I.chars.length-1].afterPuncts.map(v);return t.jsxs(b.Fragment,{children:[R,t.jsx(Xs,{span:I.entity,label:I.chars.map(M=>x(M.charData)).join(""),hasBrackets:!0,plain:a&&I.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>E,hoverDelayMs:250}),O]},`${I.entity.key}@${D}`)}),N===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Oa,{n:i.trailingBlank}):null]})]},_.id)),$(i.paragraphs.length)]})});function ss(e){const[i,n]=Gi,s=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,s))*1e3)/1e3}const qf=.02,xi=16,Xf=4;function Jf({y:e,containerRef:i,onDrag:n,onCommit:s}){const{t:o}=oe(),[a,l]=b.useState(0),d=b.useRef(!1),c=b.useRef(null),m=b.useRef(e);m.current=e;const p=b.useCallback(()=>{var y;const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=f==null?void 0:f.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-xi-Xf))},[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 S of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])S&&(g==null||g.observe(S));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>ss(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(Gi[0]*100),"aria-valuemax":Math.round(Gi[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(ss(e+f*(u.shiftKey?5:1)*qf)))},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 td=1,id=6,kn={s:1,x:0,y:0},zn=(e,i,n)=>Math.min(n,Math.max(i,e));function Qs(e,i,n){const s=zn(e.s,td,id);return{s,x:zn(e.x,i*(1-s),0),y:zn(e.y,n*(1-s),0)}}function Pr(e,i,n,s,o,a){const l=zn(e.s*s,td,id),d=l/e.s;return Qs({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function Zf(e,i,n,s,o){return Qs({s:e.s,x:e.x+i,y:e.y+n},s,o)}function Qf(e,i,n){const s=i===1?e*16:i===2?e*400:e;return Math.exp(-s*(n?.01:.0015))}const Fa=4,eg=b.forwardRef(function({children:i,onScaleChange:n,resetKey:s,style:o},a){const l=b.useRef(null),[d,c]=b.useState(kn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var v;const j=m.current;m.current=x,c(x),x.s!==j.s&&((v=p.current)==null||v.call(p,x.s))},u=()=>{var j;const x=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(x==null?void 0:x.width)??0,h:(x==null?void 0:x.height)??0,left:(x==null?void 0:x.left)??0,top:(x==null?void 0:x.top)??0}};b.useImperativeHandle(a,()=>({zoomBy(x){const{w:j,h:v}=u();h(Pr(m.current,j/2,v/2,x,j,v))},reset(){h(kn)}})),b.useEffect(()=>{h(kn)},[s]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:v,h:$}=u(),_=Qs(m.current,v,$);(_.x!==m.current.x||_.y!==m.current.y)&&h(_)});return j.observe(x),()=>j.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const j=v=>{const $=Qf(v.deltaY,v.deltaMode,v.ctrlKey);if(m.current.s<=1&&$<1)return;v.preventDefault();const{w:_,h:N,left:I,top:D}=u();h(Pr(m.current,v.clientX-I,v.clientY-D,$,_,N))};return x.addEventListener("wheel",j,{passive:!1}),()=>x.removeEventListener("wheel",j)},[]);const f=b.useRef(new Map),g=b.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),y=x=>{if(x.pointerType==="mouse"&&x.button!==0)return;f.current.set(x.pointerId,{x:x.clientX,y:x.clientY});const j=g.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[v,$]=[...f.current.values()];j.pinchDist=Math.hypot(v.x-$.x,v.y-$.y),j.moved=Fa+1}},S=x=>{var O;const j=f.current.get(x.pointerId);if(!j)return;const v={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,v);const $=g.current,{w:_,h:N,left:I,top:D}=u();if(f.current.size>=2){const[M,q]=[...f.current.values()],P=Math.hypot(M.x-q.x,M.y-q.y);if($.pinchDist>0&&P>0){const le=(M.x+q.x)/2-I,ae=(M.y+q.y)/2-D;h(Pr(m.current,le,ae,P/$.pinchDist,_,N))}$.pinchDist=P,$.swallowClick=!0;return}const E=v.x-j.x,R=v.y-j.y;if($.moved+=Math.abs(E)+Math.abs(R),!($.moved<=Fa)){if(!$.dragging){$.dragging=!0;try{(O=l.current)==null||O.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(Zf(m.current,E,R,_,N))}},k=x=>{f.current.delete(x.pointerId);const j=g.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:S,onPointerUp:k,onPointerCancel:k,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(kn),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 nd(e,i,n,s,o=""){const a=`${o}
|
|
1543
|
+
`)},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=Cf.has(l.tagName);c&&s(),l.childNodes.forEach(o),c&&s();return}a.childNodes.forEach(o)}};return o(i),n.replace(/\n+$/,"")}const Rf=e=>`/item/${encodeURIComponent(e)}`;function Tf(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 If(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 Zs=({pageData:e,pages:i,punctuations:n=rs,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:v,loadEntitySummary:k,buildEntityHref:x,onEntityNavigate:j,pageBreaks:S=!0,pageIndicatorY:$,onPageIndicatorYChange:_,quoteStyle:N,bookTitleStyle:I,showWorks:D,figures:E,figUrl:R,onFigureBlockClick:O,decorations:M})=>{var bt,Ue,ft;const{t:q}=oe(),P=b.useRef(null),le=b.useRef(0),ae=b.useMemo(()=>{const Q=new Map;return m&&n.forEach((A,ne)=>{const $e=A.id?A:{...A,id:`${A.anchor}#${ne}`},Ie=Q.get($e.anchor)||[];Ie.push($e),Q.set($e.anchor,Ie)}),Q},[n,m]),Ce=b.useMemo(()=>N===void 0&&I===void 0&&D===void 0?null:{quoteStyle:N??"original",hideBookBrackets:I==="wavy"||D===!1},[N,I,D]),xe=I==="bracket",fe=b.useMemo(()=>{var qe;const Q=i&&i.length>0?i:[{page:parseInt(e.page_id.split(":")[1]||"1",10),columns:e.columns}],A=new Map;for(const Ae of Q)for(const Ee of Ae.columns)Ee.chars.length>0&&!Ee.raised&&A.set(Ee.lead_blank||0,(A.get(Ee.lead_blank||0)||0)+1);let ne=0,$e=-1;for(const[Ae,Ee]of A)(Ee>$e||Ee===$e&&Ae<ne)&&(ne=Ae,$e=Ee);const Ie=Ae=>!!Ae.raised||(Ae.lead_blank||0)<ne,Oe=Q.filter(Ae=>Ae.columns.some(Ee=>Ee.chars.length>0||Ee.kind==="figure")).map(Ae=>{const Ee=[...Ae.columns].sort((nt,Pt)=>nt.col-Pt.col),rt=[];let st=[];const Ve=()=>{const nt=Uf(ae.get(st[0].charData.id));rt.push({id:`para-p${Ae.page}-${rt.length}`,chars:st,...nt?{heading:{level:nt.mark.length,anchor:st[0].charData.id,...nt.toc===!1?{toc:!1}:{}}}:{}}),st=[]};let F=!1,ke=0,Ze;const Ge=[];for(const nt of Ee){if(nt.kind==="figure"&&nt.fig){st.length>0?Ve():rt.length===0&&(F=!0),Ge.push({before:rt.length,fig:nt.fig,...nt.figBox?{box:nt.figBox}:{}}),ke=0;continue}if(nt.chars.length===0){nt.kind==="blank"&&ke++;continue}const Pt=nt.raised||nt.lead_blank||ke?{raised:nt.raised,leadBlank:nt.lead_blank,blankBefore:ke}:void 0;ke=0,Ie(nt)||(Ze=nt.lead_blank||0);let ct=!0;for(const St of nt.chars){const Ot=ae.get(St.id),{before:zt,after:lr}=Ot?Tf(Ot):Pf,sn=!!Ot&&Ot.some(ni=>ni.kind==="break"&&ni.pos!=="before");Ot&&Ot.some(ni=>ni.kind==="heading")&&(st.length>0?Ve():rt.length===0&&(F=!0)),st.push({charData:St,col:nt.col,beforePuncts:zt,afterPuncts:lr,...ct&&Pt?{start:Pt}:{}}),ct=!1,sn&&Ve()}}const kt=st.length>0;return kt&&Ve(),{page:Ae.page,paragraphs:rt,endsOpen:kt,...Ze!==void 0?{tailLead:Ze}:{},...F?{leadStarts:F}:{},...Ae.label?{label:Ae.label}:{},...ke>0?{trailingBlank:ke}:{},...Ge.length>0?{blocks:Ge}:{}}}),at=new Map;if(!S){let Ae=null;for(const Ee of Oe){const rt=Ee.paragraphs[0],st=(qe=rt==null?void 0:rt.chars[0])==null?void 0:qe.start,Ve=(st==null?void 0:st.leadBlank)||0,F=!!st&&!st.raised&&Ve>=ne&&Ve>((Ae==null?void 0:Ae.tailLead)??ne),ke=!!Ee.leadStarts||!!(st!=null&&st.blankBefore)||F,Ze=Ee.paragraphs.length===1&&!!Ee.trailingBlank;if(Ae&&rt&&!ke&&!Ze){for(const Ge of rt.chars)at.set(Ge.charData.id,Ae.owner);Ae.para.chars=Ae.para.chars.concat(rt.chars),Ee.leadFirstId=rt.chars[0].charData.id,Ee.paragraphs=Ee.paragraphs.slice(1),Ee.blocks&&(Ee.blocks=Ee.blocks.map(Ge=>({...Ge,before:Ge.before-1})))}if(Ee.endsOpen&&!Ee.trailingBlank){const Ge=Ee.paragraphs[Ee.paragraphs.length-1];Ge?Ae={para:Ge,owner:Ee.page,tailLead:Ee.tailLead??(Ae==null?void 0:Ae.tailLead)??ne}:Ae&&Ee.tailLead!==void 0&&(Ae.tailLead=Ee.tailLead)}else Ae=null}}const lt=new Map;for(const Ae of Oe)Ae.leadFirstId&<.set(Ae.leadFirstId,Ae.page);return{pages:Oe,mergedOwner:at,pageStarts:lt}},[i,e,ae,S]),se=fe.pages,Re=b.useRef(se);Re.current=se;const H=b.useMemo(()=>se.map(Q=>Q.paragraphs.reduce((A,ne)=>A+ne.chars.length,0)),[se]),me=b.useCallback((Q,A)=>{let ne=Q,$e=0;for(;ne<H.length&&(ne===Q||$e+H[ne]<=A);)$e+=H[ne++];return ne},[H]),W=`${se.length}:${((ft=(Ue=(bt=se[0])==null?void 0:bt.paragraphs[0])==null?void 0:Ue.chars[0])==null?void 0:ft.charData.id)??""}`,[K,re]=b.useState(()=>({sig:W,n:me(0,Pa)}));let Y=K.n;K.sig!==W&&(Y=me(0,Pa),re({sig:W,n:Y})),Y=Math.min(Y,se.length);const T=Y>=se.length;b.useEffect(()=>T?void 0:(A=>{const ne=window;if(ne.requestIdleCallback){const Ie=ne.requestIdleCallback(A,{timeout:300});return()=>{var Oe;return(Oe=ne.cancelIdleCallback)==null?void 0:Oe.call(ne,Ie)}}const $e=setTimeout(A,16);return()=>clearTimeout($e)})(()=>re(A=>A.sig===W?{sig:A.sig,n:Math.max(A.n,me(A.n,Mf))}:A)),[T,Y,W,me]);const ue=b.useCallback(Q=>{const A=Re.current.findIndex($e=>$e.page>=Q),ne=(A<0?Re.current.length:A)+2;re($e=>$e.n>=ne?$e:{...$e,n:ne})},[]),ye=T?se:se.slice(0,Y);b.useEffect(()=>{let Q;const A=requestAnimationFrame(()=>{Q=setTimeout(()=>{const ne=P.current,$e=ne==null?void 0:ne.querySelector(".guji-reflow-paragraph");if(!ne||!$e)return;const Ie=getComputedStyle($e),Oe=parseFloat(Ie.fontSize),at=$e.clientWidth;if(!(Oe>0)||!(at>0))return;const lt=parseFloat(Ie.lineHeight);ne.style.setProperty("--gtv-cpl",String(Math.max(8,Math.floor(at/Oe)))),ne.style.setProperty("--gtv-lh",`${Math.round(lt>0?lt:Oe*2)}px`)},0)});return()=>{cancelAnimationFrame(A),Q&&clearTimeout(Q)}},[W]);const Ne=b.useMemo(()=>{const Q=[];for(const A of se)for(const ne of A.paragraphs)for(const $e of ne.chars)Q.push($e.charData.id);return Q},[se]),B=b.useMemo(()=>new Map(Ne.map((Q,A)=>[Q,A])),[Ne]),de=b.useMemo(()=>{const Q=new Map;if(!y||y.length===0)return Q;const A=B;for(const ne of y){if(!ne.anchor)continue;const $e=A.get(ne.anchor.start),Ie=A.get(ne.anchor.end);if(!($e===void 0||Ie===void 0||Ie<$e))for(let Oe=$e;Oe<=Ie;Oe++)Q.has(Ne[Oe])||Q.set(Ne[Oe],ne)}return Q},[y,Ne,B]),Me=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]),Se=b.useMemo(()=>{var $e;if(!Me||!y)return[];const Q=new Set,A=[],ne=(Ie,Oe)=>{const at=`${Ie}:${Oe}`;Q.has(at)||(Q.add(at),A.push([Ie,Oe]))};for(const Ie of y){if(!Ie.anchor)continue;const Oe=B.get(Ie.anchor.start),at=B.get(Ie.anchor.end);if(!(Oe===void 0||at===void 0||at<Oe)){(Ie.targetId&&Me.has(Ie.targetId)||($e=Ie.targets)!=null&&$e.some(lt=>Me.has(lt.id)))&&ne(Oe,at);for(const lt of Ie.parts??[]){if(!Me.has(lt.id))continue;const qe=Oe+lt.offset[0],Ae=Oe+lt.offset[1]-1;Ae>=qe&&Ae<=at&&ne(qe,Ae)}}}return A.sort((Ie,Oe)=>Ie[0]-Oe[0]||Ie[1]-Oe[1])},[Me,y,B]),Je=qs(v,k),X=de.size>0,je=b.useRef({onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:O});je.current={onCharClick:l,onCharHover:d,onSelectionChange:a,onVisiblePageChange:p,onEntityNavigate:j,onVisibleHeadingChange:g,onFigureBlockClick:O};const L=b.useMemo(()=>({click:Q=>{var A,ne;le.current=Date.now()+1200,(ne=(A=je.current).onCharClick)==null||ne.call(A,Q)},enter:Q=>{var A,ne;return(ne=(A=je.current).onCharHover)==null?void 0:ne.call(A,Q)},leave:()=>{var Q,A;return(A=(Q=je.current).onCharHover)==null?void 0:A.call(Q,null)},figBlock:Q=>{var A,ne;return(ne=(A=je.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"))}}),[]),G=Wf(s,fe.mergedOwner),ie=Df(M,fe.mergedOwner),te=b.useRef(Y);te.current=Y;const ce=b.useRef(null),be=b.useCallback(Q=>{const A=ce.current,ne=A==null?void 0:A.map.get(Q);if(ne&&ne.isConnected)return ne;if(A&&A.for===Re.current&&A.n===te.current&&!ne)return null;const $e=P.current;if(!$e)return null;const Ie=new Map;return $e.querySelectorAll("span[data-char-id]").forEach(Oe=>{Ie.set(Oe.getAttribute("data-char-id"),Oe)}),ce.current={for:Re.current,n:te.current,map:Ie},Ie.get(Q)??null},[]),Fe=b.useRef(null);b.useEffect(()=>{var A;if((A=Fe.current)==null||A.classList.remove("is-hovered"),Fe.current=null,!o)return;const Q=be(o);Q&&(Q.classList.add("is-hovered"),Fe.current=Q)},[o,be]);const Xe=b.useRef(null),Be=Q=>{var ne;const A=Q instanceof Element?Q.closest("span[data-char-id]"):null;return A&&((ne=P.current)!=null&&ne.contains(A))?A.getAttribute("data-char-id"):null},Ke=Q=>{const A=Be(Q.target);A&&L.click(A)},Ye=Q=>{const A=Be(Q.target);A!==Xe.current&&(Xe.current=A,A?L.enter(A):L.leave())},w=Q=>{const A=typeof window<"u"?window.getSelection():null;if(!A||A.isCollapsed||A.rangeCount===0)return;const ne=Ef(A.getRangeAt(0));ne!==null&&(Q.clipboardData.setData("text/plain",ne),Q.preventDefault())},ee=()=>{Xe.current!==null&&(Xe.current=null,L.leave())};b.useEffect(()=>{let Q=null;const A=()=>{var ke,Ze;Q=null;const $e=window.getSelection(),Ie=P.current;if(!$e||$e.isCollapsed||$e.rangeCount===0||!Ie)return;const Oe=$e.getRangeAt(0),at=Oe.commonAncestorContainer,lt=at.nodeType===3?at.parentElement:at;if(!lt||!Ie.contains(lt))return;const qe=Ie.querySelectorAll("span[data-char-id]"),Ae=Ge=>{let kt=Ge;for(;kt.nodeType!==3&&kt.firstChild;)kt=kt.firstChild;return kt};let Ee=0,rt=qe.length;for(;Ee<rt;){const Ge=Ee+rt>>1;Oe.comparePoint(Ae(qe[Ge]),0)<0?Ee=Ge+1:rt=Ge}const st=Ee;for(rt=qe.length;Ee<rt;){const Ge=Ee+rt>>1;Oe.comparePoint(Ae(qe[Ge]),0)<=0?Ee=Ge+1:rt=Ge}let Ve=Ee-1;if(Ve>=st&&Oe.endOffset===0&&Oe.endContainer===Ae(qe[Ve])&&Ve--,Ve<st)return;const F=[];for(let Ge=st;Ge<=Ve;Ge++)F.push(qe[Ge].getAttribute("data-char-id"));F.length>0&&(le.current=Date.now()+1200,(Ze=(ke=je.current).onSelectionChange)==null||Ze.call(ke,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=be(Q);if(A)Z.current=s,A.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"});else{const ne=parseInt(Q.split(":")[0],10);isNaN(ne)||ue(ne)}},[s,Y,be,ue]);const he=Q=>{var $e;const A=P.current;if(!A)return null;const ne=($e=se.find(Ie=>Ie.page===Q))==null?void 0:$e.leadFirstId;return ne?A.querySelector(`span[data-char-id="${ne}"]`):A.querySelector(`[data-page-section="${Q}"]`)},Le=u==null?void 0:u.nonce,C=b.useRef(null);b.useEffect(()=>{if(!u||C.current===u.nonce)return;const Q=he(u.page);if(!Q){!T&&se.some(A=>A.page>=u.page)&&ue(u.page);return}C.current=u.nonce,le.current=Date.now()+800,Q.scrollIntoView({behavior:"auto",block:"start"})},[Le,Y]);const ge=b.useRef(null),V=b.useRef([]);b.useEffect(()=>{var Oe,at,lt;if(!f||ge.current===f.nonce||f.anchor.startsWith("e="))return;const[Q,A]=f.anchor.split("~"),ne=P.current,$e=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(Q)}"]`),Ie=parseInt(Q.split(":")[0],10);if(!$e){if(!T&&!isNaN(Ie)&&se.some(qe=>qe.page>=Ie)){ue(Ie);return}A&&!isNaN(Ie)&&(ge.current=f.nonce,(Oe=he(Ie))==null||Oe.scrollIntoView({behavior:"auto",block:"start"}));return}ge.current=f.nonce,le.current=Date.now()+800;for(const qe of V.current)qe.classList.remove("guji-hl");if(V.current=[],A){const qe=B.get(Q),Ae=B.get(A);if(qe!==void 0&&Ae!==void 0&&Ae>=qe&&Ae-qe<64)for(let Ee=qe;Ee<=Ae;Ee++){const rt=ne==null?void 0:ne.querySelector(`span[data-char-id="${Li(Ne[Ee])}"]`);rt&&(rt.classList.add("guji-hl"),V.current.push(rt))}La($e,le)}else($e.closest(".guji-reflow-paragraph")??$e).scrollIntoView({behavior:"auto",block:"start"});isNaN(Ie)||(lt=(at=je.current).onVisiblePageChange)==null||lt.call(at,Ie)},[f,se,Y,T,ue,Ne,B]);const[ze,we]=b.useState(null),[Te,tt]=b.useState(!1),Pe=b.useRef(null);b.useEffect(()=>{!f||!Me||Pe.current===f.nonce||Se.length===0||(Pe.current=f.nonce,tt(!1),we({k:0,nonce:Date.now()}))},[f,Me,Se]);const it=b.useRef(null);b.useEffect(()=>{var Oe,at;if(!ze||it.current===ze.nonce)return;const Q=Se[ze.k];if(!Q)return;const A=P.current,ne=Ne[Q[0]],$e=A==null?void 0:A.querySelector(`span[data-char-id="${Li(ne)}"]`),Ie=parseInt(ne.split(":")[0],10);if(!$e){!T&&!isNaN(Ie)&&ue(Ie);return}it.current=ze.nonce;for(const lt of V.current)lt.classList.remove("guji-hl");V.current=[];for(let lt=Q[0];lt<=Q[1];lt++){const qe=A==null?void 0:A.querySelector(`span[data-char-id="${Li(Ne[lt])}"]`);qe&&(qe.classList.add("guji-hl"),V.current.push(qe))}La($e,le),isNaN(Ie)||(at=(Oe=je.current).onVisiblePageChange)==null||at.call(Oe,Ie)},[ze,Se,Ne,Y,T,ue]);const yt=b.useMemo(()=>{if(!Me||Te||Se.length===0)return"";const Q=[];for(const[A,ne]of Se)for(let $e=A;$e<=ne;$e++)Q.push(`.guji-text-pane-content span[data-char-id="${Li(Ne[$e])}"]`);return`${Q.join(",")}{background:${r.bim("mark-soft")};border-radius:2px}`},[Me,Te,Se,Ne]),De=Q=>we(A=>{const ne=Se.length;return{k:(((A==null?void 0:A.k)??0)+Q+ne)%ne,nonce:Date.now()}}),J=()=>{tt(!0);for(const Q of V.current)Q.classList.remove("guji-hl");V.current=[]},ve=!!p||!!g,Qe=!!p&&typeof $=="number",[et,We]=b.useState(null),He=ss(et??$??0),ut=b.useRef(null);ut.current=Qe?He:null;const pt=b.useRef(()=>{});return b.useEffect(()=>{var rt,st;if(!ve)return;const Q=new Map,A=new Map;(rt=P.current)==null||rt.querySelectorAll("[data-page-section],[data-page-start]").forEach(Ve=>{const F=Ve.getAttribute("data-page-section");F!==null?Q.set(F,Ve):A.set(Ve.getAttribute("data-page-start"),Ve)});const ne=[],$e=[];for(const Ve of ye){const F=Q.get(String(Ve.page));F&&(ne.push(F),$e.push(Ve.page))}if(ne.length===0)return;const Ie=new Map(ne.map((Ve,F)=>[Ve,F])),Oe=ne.map(()=>[]);let at=0;(st=P.current)==null||st.querySelectorAll('.guji-reflow-heading:not([data-heading-toc="0"])').forEach(Ve=>{const F=Ie.get(Ve.closest("[data-page-section]"));F!==void 0&&(Oe[F].push(Ve),at++)});let lt,qe=0;const Ae=()=>{var nt,Pt;if(qe=0,Date.now()<le.current)return;const Ve=ct=>ct.getBoundingClientRect().top;if(ne.length>1&&Ve(ne[0])===Ve(ne[ne.length-1]))return;const F=ut.current===null?120:ut.current*window.innerHeight;let ke=0,Ze=ne.length-1;for(;ke<Ze;){const ct=ke+Ze+1>>1;Ve(ne[ct])<=F?ke=ct:Ze=ct-1}const Ge=Ve(ne[0])>F;let kt=$e[ke];for(let ct=ke+1;ct<ne.length;ct++){const St=A.get(String($e[ct]));if(!St||!ne[ke].contains(St)||Ve(St)>F)break;kt=$e[ct]}if(at>0&&je.current.onVisibleHeadingChange){let ct=null;if(!Ge){const Ot=Oe[ke];for(let zt=Ot.length-1;zt>=0&&!ct;zt--)Ve(Ot[zt])<=F&&(ct=Ot[zt]);for(let zt=ke-1;zt>=0&&!ct;zt--)Oe[zt].length>0&&(ct=Oe[zt][Oe[zt].length-1])}const St=ct?Kf(ct):null;St!==lt&&(lt=St,je.current.onVisibleHeadingChange(St))}(Pt=(nt=je.current).onVisiblePageChange)==null||Pt.call(nt,kt)},Ee=()=>{qe||(qe=requestAnimationFrame(Ae))};return pt.current=()=>{qe||(qe=requestAnimationFrame(Ae))},window.addEventListener("scroll",Ee,{passive:!0}),Ee(),()=>{window.removeEventListener("scroll",Ee),qe&&cancelAnimationFrame(qe),pt.current=()=>{}}},[ve,se,Y]),b.useEffect(()=>{Qe&&pt.current()},[Qe,He]),t.jsxs("div",{ref:P,className:"guji-text-pane-content",onClick:Ke,onMouseOver:Ye,onMouseLeave:ee,onCopy:w,children:[X&&t.jsx("style",{children:Vs}),yt&&t.jsx("style",{children:yt}),yt&&ze&&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:ze.k+1,n:Se.length})}),t.jsx("button",{type:"button",onClick:()=>De(-1),"aria-label":q("mentions.prev"),title:q("mentions.prev"),children:"‹"}),t.jsx("button",{type:"button",onClick:()=>De(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:"×"})]}),Qe&&t.jsx(Jf,{y:He,containerRef:P,onDrag:We,onCommit:Q=>{We(null),_==null||_(Q)}}),t.jsx("div",{className:"guji-text-reflow-view",children:ye.map((Q,A)=>t.jsx(Gf,{pGroup:Q,first:A===0,pageBreaks:S,markOpts:Ce,plainBooks:xe,selected:G.get(Q.page)??Lf,decorations:ie.get(Q.page),entityOfChar:de,entityLoader:Je,convert:h,buildHref:x??Rf,handlers:L,charCount:H[A]??0,pageStarts:fe.pageStarts,figures:E,figUrl:R},`page-sec-${Q.page}`))})]})};function La(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 Pa=1800,Mf=800,Af="auto calc((var(--gtv-pc) / var(--gtv-cpl, 30) + var(--gtv-pp) * 1.4) * var(--gtv-lh, 44px) + 64px)",Lf=new Set,rs=[],Pf={before:rs,after:rs},Of={};function Ff(e){if(!e)return Of;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 Bf(e){if(!(!e||!e.bg&&!e.fg))return{"--cd-bg":e.bg,"--cd-fg":e.fg}}function Hf(e){return e?` bim-cd${e.tone?` bim-cd-${e.tone}`:""}${e.underline?` bim-cd-ul-${e.underline}`:""}`:""}function Df(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&&jh(h,p)});s.set(l,c?d:a)})}return n.current=s,s},[e,i])}function Wf(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 Uf(e){return e==null?void 0:e.find(i=>i.kind==="heading"&&/^#{1,6}$/.test(i.mark))}function Kf(e){return e.getAttribute("data-heading-anchor")}function Li(e){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e):e.replace(/["\\]/g,"\\$&")}function Oa({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 Yf(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 Vf({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 Gf=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:v}){const k=b.useMemo(()=>{const _=new Map;if(!p)return _;for(const N of i.paragraphs){const I=Yf(N.chars.map(D=>D.charData.fig?D.charData.char:D.charData.norm??D.charData.char),p);N.chars.forEach((D,E)=>_.set(D.charData.id,D.charData.fig?D.charData.char:I[E]))}return _},[i,p]),x=_=>k.get(_.id)??_.char,{t:j}=oe(),S=_=>{const N=o?Lc(_.mark,o):_.mark;return N?t.jsx("span",{className:"guji-text-punct","data-punct-id":_.id,children:N},_.id):null},$=_=>{var N;return(N=i.blocks)==null?void 0:N.map((I,D)=>I.before===_&&t.jsx(zf,{fig:I.fig,info:y==null?void 0:y.get(I.fig),figUrl:v,onClick:()=>u.figBlock({page:i.page,fig:I.fig,...I.box?{box:I.box}:{}})},`fig-${I.fig}-${D}`))};return t.jsxs("section",{"data-page-section":i.page,className:"guji-page-section",style:{position:"relative",scrollMarginTop:96,contentVisibility:"auto",containIntrinsicSize:Af,"--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:[$(N),t.jsxs(Vf,{heading:_.heading,children:[If(_.chars,c).map((I,D)=>{const E=I.chars.map(({charData:M,beforePuncts:q,afterPuncts:P,start:le},ae)=>{var W,K,re;const Ce=!!I.entity&&ae===0,xe=!!I.entity&&ae===I.chars.length-1,fe=Ce?[]:q,se=xe?[]:P,Re=!!M.fig&&ae>0&&I.chars[ae-1].charData.fig===M.fig;let H=1;if(M.fig&&!Re)for(;((W=I.chars[ae+H])==null?void 0:W.charData.fig)===M.fig;)H++;const me=`guji-text-char${l.has(M.id)?" is-selected":""}${M.sub?" is-sub":""}${M.lane==="solo"?" is-solo":""}${le!=null&&le.raised?" is-raised":""}`;return t.jsxs(b.Fragment,{children:[le&&le.blankBefore>0&&t.jsx(Oa,{n:le.blankBefore}),fe.map(S),M.fig?t.jsx(Nf,{id:M.id,fig:M.fig,info:y==null?void 0:y.get(M.fig),figUrl:v,cells:H,cont:Re,className:me,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),...Ff(d==null?void 0:d.get(M.id)),style:Bf(d==null?void 0:d.get(M.id)),className:`guji-text-char${Hf(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":""}${le!=null&&le.raised?" is-raised":""}`,"data-raised":(le==null?void 0:le.raised)||void 0,"data-guji-guess":M.lacuna&&M.guess_c?M.guess_c:void 0,title:((K=d==null?void 0:d.get(M.id))==null?void 0:K.title)??(M.pending?j("reader.pendingReason",{label:p?p(_e.pendingReasonLabel(M.pending)):_e.pendingReasonLabel(M.pending)}):M.lacuna?M.guess_c?j("reader.lacunaGuess",{guess:p?p(M.guess_c):M.guess_c}):j("detail.lacuna"):M.zi?j("detail.composedChar",{label:M.zi}):M.guess?j("reader.charGuess"):void 0),children:x(M)}),((re=d==null?void 0:d.get(M.id))==null?void 0:re.insertAfter)&&t.jsx("span",{className:"bim-cd-ins","aria-hidden":"true","data-cd-ins":d.get(M.id).insertAfter})]}),se.map(S)]},M.id)});if(!I.entity)return t.jsx(b.Fragment,{children:E},`r${D}`);const R=I.chars[0].beforePuncts.map(S),O=I.chars[I.chars.length-1].afterPuncts.map(S);return t.jsxs(b.Fragment,{children:[R,t.jsx(Xs,{span:I.entity,label:I.chars.map(M=>x(M.charData)).join(""),hasBrackets:!0,plain:a&&I.entity.kind==="work",loader:m,buildHref:h,onNavigate:u.navigate,cardNewTab:!0,renderText:()=>E,hoverDelayMs:250}),O]},`${I.entity.key}@${D}`)}),N===i.paragraphs.length-1&&i.trailingBlank?t.jsx(Oa,{n:i.trailingBlank}):null]})]},_.id)),$(i.paragraphs.length)]})});function ss(e){const[i,n]=Gi,s=Number.isFinite(e)?e:.33;return Math.round(Math.min(n,Math.max(i,s))*1e3)/1e3}const qf=.02,xi=16,Xf=4;function Jf({y:e,containerRef:i,onDrag:n,onCommit:s}){const{t:o}=oe(),[a,l]=b.useState(0),d=b.useRef(!1),c=b.useRef(null),m=b.useRef(e);m.current=e;const p=b.useCallback(()=>{var y;const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=f==null?void 0:f.getBoundingClientRect();l(Math.max(0,((g==null?void 0:g.left)??0)-xi-Xf))},[i]);b.useLayoutEffect(()=>{var y;window.addEventListener("resize",p);const u=((y=c.current)==null?void 0:y.parentElement)??i.current,f=(u==null?void 0:u.closest(".bim-rd-col"))??u,g=typeof ResizeObserver<"u"?new ResizeObserver(()=>p()):null;for(const v of[f,u==null?void 0:u.closest(".bim-rd-text"),u==null?void 0:u.closest(".bim-rd-body")])v&&(g==null||g.observe(v));return g||p(),()=>{window.removeEventListener("resize",p),g==null||g.disconnect()}},[p,i]);const h=u=>ss(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(Gi[0]*100),"aria-valuemax":Math.round(Gi[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(ss(e+f*(u.shiftKey?5:1)*qf)))},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 td=1,id=6,kn={s:1,x:0,y:0},zn=(e,i,n)=>Math.min(n,Math.max(i,e));function Qs(e,i,n){const s=zn(e.s,td,id);return{s,x:zn(e.x,i*(1-s),0),y:zn(e.y,n*(1-s),0)}}function Pr(e,i,n,s,o,a){const l=zn(e.s*s,td,id),d=l/e.s;return Qs({s:l,x:i-(i-e.x)*d,y:n-(n-e.y)*d},o,a)}function Zf(e,i,n,s,o){return Qs({s:e.s,x:e.x+i,y:e.y+n},s,o)}function Qf(e,i,n){const s=i===1?e*16:i===2?e*400:e;return Math.exp(-s*(n?.01:.0015))}const Fa=4,eg=b.forwardRef(function({children:i,onScaleChange:n,resetKey:s,style:o},a){const l=b.useRef(null),[d,c]=b.useState(kn),m=b.useRef(d),p=b.useRef(n);p.current=n;const h=x=>{var S;const j=m.current;m.current=x,c(x),x.s!==j.s&&((S=p.current)==null||S.call(p,x.s))},u=()=>{var j;const x=(j=l.current)==null?void 0:j.getBoundingClientRect();return{w:(x==null?void 0:x.width)??0,h:(x==null?void 0:x.height)??0,left:(x==null?void 0:x.left)??0,top:(x==null?void 0:x.top)??0}};b.useImperativeHandle(a,()=>({zoomBy(x){const{w:j,h:S}=u();h(Pr(m.current,j/2,S/2,x,j,S))},reset(){h(kn)}})),b.useEffect(()=>{h(kn)},[s]),b.useEffect(()=>{const x=l.current;if(!x||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{const{w:S,h:$}=u(),_=Qs(m.current,S,$);(_.x!==m.current.x||_.y!==m.current.y)&&h(_)});return j.observe(x),()=>j.disconnect()},[]),b.useEffect(()=>{const x=l.current;if(!x)return;const j=S=>{const $=Qf(S.deltaY,S.deltaMode,S.ctrlKey);if(m.current.s<=1&&$<1)return;S.preventDefault();const{w:_,h:N,left:I,top:D}=u();h(Pr(m.current,S.clientX-I,S.clientY-D,$,_,N))};return x.addEventListener("wheel",j,{passive:!1}),()=>x.removeEventListener("wheel",j)},[]);const f=b.useRef(new Map),g=b.useRef({dragging:!1,moved:0,pinchDist:0,swallowClick:!1}),y=x=>{if(x.pointerType==="mouse"&&x.button!==0)return;f.current.set(x.pointerId,{x:x.clientX,y:x.clientY});const j=g.current;if(j.swallowClick=!1,f.current.size===1&&(j.moved=0,j.dragging=!1),f.current.size===2){const[S,$]=[...f.current.values()];j.pinchDist=Math.hypot(S.x-$.x,S.y-$.y),j.moved=Fa+1}},v=x=>{var O;const j=f.current.get(x.pointerId);if(!j)return;const S={x:x.clientX,y:x.clientY};f.current.set(x.pointerId,S);const $=g.current,{w:_,h:N,left:I,top:D}=u();if(f.current.size>=2){const[M,q]=[...f.current.values()],P=Math.hypot(M.x-q.x,M.y-q.y);if($.pinchDist>0&&P>0){const le=(M.x+q.x)/2-I,ae=(M.y+q.y)/2-D;h(Pr(m.current,le,ae,P/$.pinchDist,_,N))}$.pinchDist=P,$.swallowClick=!0;return}const E=S.x-j.x,R=S.y-j.y;if($.moved+=Math.abs(E)+Math.abs(R),!($.moved<=Fa)){if(!$.dragging){$.dragging=!0;try{(O=l.current)==null||O.setPointerCapture(x.pointerId)}catch{}}$.swallowClick=!0,m.current.s>1&&h(Zf(m.current,E,R,_,N))}},k=x=>{f.current.delete(x.pointerId);const j=g.current;j.pinchDist=0,f.current.size===0&&(j.dragging=!1)};return t.jsx("div",{ref:l,className:"bim-zp","data-zoom":d.s.toFixed(2),onPointerDown:y,onPointerMove:v,onPointerUp:k,onPointerCancel:k,onClickCapture:x=>{g.current.swallowClick&&(g.current.swallowClick=!1,x.stopPropagation(),x.preventDefault())},onDoubleClick:()=>h(kn),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 nd(e,i,n,s,o=""){const a=`${o}
|
|
1543
1544
|
${s.versionKey??""}
|
|
1544
1545
|
${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 tg(e,i,n,s=""){const o=`${s}
|
|
1545
1546
|
${n.versionKey??""}
|
|
1546
|
-
${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?Bc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:ig}const ig=[],ng=/^#{1,6}$/,rg=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function sg(e){let i=e.trim();const n=rg.exec(i);return n&&(i=n[1]+n[2]),i.replace(/[《》〈〉]/g,"").trim()}const Ba=e=>e.kind==null||e.kind==="point";function rd(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=sg(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"&&ng.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)Ba(g)&&g.pos==="before"&&(a.text+=g.mark);a.text+=h.char;for(const g of u)Ba(g)&&g.pos!=="before"&&(a.text+=g.mark)}u.some(g=>g.kind==="break"&&g.pos!=="before")&&l()}}return l(),o}function os(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 eo(e,i){return`${e}#${i}`}function sd(e){const i=e.indexOf("#");return i<=0||i===e.length-1?null:{chapter:e.slice(0,i),anchor:e.slice(i+1)}}function od(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 Cn(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const og=150,Ha="(min-width: 860px)";function ag(){const[e,i]=b.useState(()=>typeof window>"u"||!window.matchMedia?!0:window.matchMedia(Ha).matches);return b.useEffect(()=>{var o;if(!window.matchMedia)return;const n=window.matchMedia(Ha),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 Da={padding:24,color:r.bim("desc-fg"),fontSize:14};function Wa({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 Ua=/^https?:\/\//i,lg=[];function cg(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&&Ua.test(n)?n:void 0,license:i(e.license),license_url:s&&Ua.test(s)?s:void 0,note:i(e.note)};return o.name||o.license||o.note?o:null}function dg(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 Ka(e,i){return(i==null?void 0:i.type)==="kaozhen"?"章":i!=null&&i.juan_metadata&&Object.values(i.juan_metadata).some(n=>n.vol_label)||Array.isArray(i==null?void 0:i.heading_levels)&&i.heading_levels.length>0?"冊":_e.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function ad(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 ld(e,i,n){return i.map(s=>({key:eo(e,s.anchor),label:n(s.label),inChapter:!0,...s.children.length>0?{selectable:!0,children:ld(e,s.children,n)}:{}}))}function mg(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?ad(f,n,s,o):h),hint:d(i[h]),disabled:i[h]===0,...g.length>0?{selectable:!0,children:ld(h,od(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=Fh(u,i);return{key:`group:${f}`,label:s(u.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:Kc(u),defaultExpanded:typeof g=="number"&&g>0,children:[...u.files.filter(
|
|
1547
|
+
${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?Bc(h):[]),()=>m([]))},[e,i,n,o]),a.tag===o?a.spans:ig}const ig=[],ng=/^#{1,6}$/,rg=/^([^《》]*)《([^《》]+)》\s*(?:[〇零一二三四五六七八九十百千]+|不分|無|无)卷/;function sg(e){let i=e.trim();const n=rg.exec(i);return n&&(i=n[1]+n[2]),i.replace(/[《》〈〉]/g,"").trim()}const Ba=e=>e.kind==null||e.kind==="point";function rd(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=sg(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"&&ng.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)Ba(g)&&g.pos==="before"&&(a.text+=g.mark);a.text+=h.char;for(const g of u)Ba(g)&&g.pos!=="before"&&(a.text+=g.mark)}u.some(g=>g.kind==="break"&&g.pos!=="before")&&l()}}return l(),o}function os(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 eo(e,i){return`${e}#${i}`}function sd(e){const i=e.indexOf("#");return i<=0||i===e.length-1?null:{chapter:e.slice(0,i),anchor:e.slice(i+1)}}function od(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 Cn(e){return!!e&&!e.has_json&&typeof e.char_file=="string"&&!!e.char_file&&typeof e.cord_file=="string"&&!!e.cord_file}const og=150,Ha="(min-width: 860px)";function ag(){const[e,i]=b.useState(()=>typeof window>"u"||!window.matchMedia?!0:window.matchMedia(Ha).matches);return b.useEffect(()=>{var o;if(!window.matchMedia)return;const n=window.matchMedia(Ha),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 Da={padding:24,color:r.bim("desc-fg"),fontSize:14};function Wa({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 Ua=/^https?:\/\//i,lg=[];function cg(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&&Ua.test(n)?n:void 0,license:i(e.license),license_url:s&&Ua.test(s)?s:void 0,note:i(e.note)};return o.name||o.license||o.note?o:null}function dg(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 Ka(e,i){return(i==null?void 0:i.type)==="kaozhen"?"章":i!=null&&i.juan_metadata&&Object.values(i.juan_metadata).some(n=>n.vol_label)||Array.isArray(i==null?void 0:i.heading_levels)&&i.heading_levels.length>0?"冊":_e.isCollatedKind(e==null?void 0:e.kind)?"卷":"章"}function ad(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 ld(e,i,n){return i.map(s=>({key:eo(e,s.anchor),label:n(s.label),inChapter:!0,...s.children.length>0?{selectable:!0,children:ld(e,s.children,n)}:{}}))}function mg(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?ad(f,n,s,o):h),hint:d(i[h]),disabled:i[h]===0,...g.length>0?{selectable:!0,children:ld(h,od(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=Fh(u,i);return{key:`group:${f}`,label:s(u.label),hint:g==="loading"?"…":typeof g=="number"&&g>0?`${g}`:Kc(u),defaultExpanded:typeof g=="number"&&g>0,children:[...u.files.filter(v=>l.has(v)).map(v=>c(v)),...(u.children??[]).map((v,k)=>h(v,`${f}.${k}`))]}};return m.map((u,f)=>h(u,`${f}`))}return e.chapters.map(h=>c(h.file))}const cd=e=>{const i=ic(),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(cu,{mode:i[0].scriptMode,children:t.jsx(pg,{...e,prefsState:i,onBodyReady:n?d:void 0})}),n&&!s&&!a&&t.jsx(ug,{data:n})]})};function ug({data:e}){const{t:i}=oe();return t.jsxs("section",{"data-reader-lead":!0,style:{maxWidth:768,margin:"0 auto",padding:"24px 16px",lineHeight:2},children:[e.paragraphs.map((n,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 pg=({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:v,revisedAt:k,backHref:x,backLabel:j,resolveWarpData:S,textFileBase:$,onChapterData:_,hideSupersededVersions:N=!0,warpData:I,resolveEntities:D,onEntityNavigate:E,plugins:R,className:O,style:M})=>{var To,Io,Mo,Ao;const{t:q,convert:P}=oe(),le=b.useMemo(()=>ql(s),[s]),[ae,Ce]=e,xe=It(),fe=b.useRef(l);fe.current=l;const[se,Re]=b.useState(null),[H,me]=b.useState("loading");b.useEffect(()=>{let z=!1;return Re(null),me("loading"),le.getManifest(n).then(U=>{z||(U?(Re(N?_e.readerVersions(U):U),me("ready")):me("missing"))}).catch(()=>{z||me("missing")}),()=>{z=!0}},[le,n,N]);const W=o!==void 0,K=a!==void 0,[re,Y]=b.useState(null),[T,ue]=b.useState(null);b.useEffect(()=>{Y(null),ue(null)},[n]);const ye=_e.pickTextVersion(se,W?o:re),Ne=((To=se==null?void 0:se.versions.find(z=>z.key==="default"))==null?void 0:To.key)??((Io=se==null?void 0:se.versions[0])==null?void 0:Io.key)??"default",B=(ye==null?void 0:ye.key)??null,de=K?a:T,Me=b.useCallback((z,U,pe,ot)=>{var dt;(dt=fe.current)==null||dt.call(fe,{key:z,chapter:U,isDefault:z===Ne,...ot?{anchor:ot}:{}},pe)},[Ne]);b.useEffect(()=>{!se||!W||o==null||se.versions.some(z=>z.key===o)||Me(Ne,null,"auto")},[se,W,o,Ne,Me]);const Se=b.useRef(new Map);b.useEffect(()=>{Se.current.clear()},[le,n]);const Je=b.useCallback(async z=>{const U=`${n}
|
|
1547
1548
|
${z}`;if(Se.current.has(U))return Se.current.get(U)??null;const pe=await le.getIndex(n,z).catch(()=>null);return pe&&Se.current.set(U,pe),pe},[le,n]),[X,je]=b.useState(null),[L,G]=b.useState("loading"),ie=B?`${n}
|
|
1548
1549
|
${B}`:null,te=X&&X.owner===ie?X.idx:null;b.useEffect(()=>{if(!B)return;let z=!1;const U=`${n}
|
|
1549
1550
|
${B}`;return je(null),G("loading"),Je(B).then(pe=>{z||(pe&&pe.chapters.length>0?(je({owner:U,idx:pe}),G("ready")):G("failed"))}),()=>{z=!0}},[n,B,Je]),b.useEffect(()=>{if(!te||!B||de!=null&&te.chapters.some(pe=>pe.file===de))return;const U=te.chapters[0].file;K||ue(U),Me(B,U,"auto")},[te,B,de,K,Me]);const ce=te?de!=null&&te.chapters.some(z=>z.file===de)?de:te.chapters[0].file:de,be=b.useMemo(()=>te&&ce?te.chapters.find(z=>z.file===ce)??null:null,[te,ce]),Fe=b.useRef(0),Xe=b.useCallback(async z=>{if(!se||z===B||!se.versions.some($t=>$t.key===z))return;const U=++Fe.current,pe=await Je(z);if(U!==Fe.current)return;const ot=be??(ce?{file:ce}:null),dt=_e.matchChapterAcrossVersions(ot,pe);W||Y(z),K||ue(dt),Me(z,dt,"version")},[se,B,Je,be,ce,W,K,Me]),[Be,Ke]=b.useState(null),[Ye,w]=b.useState(null),ee=b.useRef(0),Z=b.useCallback((z,U)=>{Ke({chapter:z,anchor:U,nonce:++ee.current}),w({chapter:z,anchor:U})},[]),he=b.useCallback(z=>{if(!B)return;const U=sd(z);if(U){Z(U.chapter,U.anchor),K||ue(U.chapter),Me(B,U.chapter,"chapter",U.anchor);return}K||ue(z),Me(B,z,"chapter")},[B,K,Me,Z]),Le=b.useRef(null);b.useEffect(()=>{!c||!ce||c===Le.current||(Le.current=c,Z(ce,c))},[c,ce,Z]),b.useEffect(()=>{c||(Le.current=null)},[c]);const[C,ge]=b.useState(null),V=B&&be?`${n}
|
|
@@ -1551,9 +1552,9 @@ ${B}
|
|
|
1551
1552
|
${be.file}`:null,[ze,we]=b.useState(null),Te=V!==null&&ze!==V,tt=b.useRef(0);b.useEffect(()=>{if(!B||!be)return;const z=++tt.current,U=`${n}
|
|
1552
1553
|
${B}
|
|
1553
1554
|
${be.file}`;if(ge(null),Cn(be)){we(U);return}le.getChapter(n,B,be.file,{json:!!be.has_json}).then(pe=>{z===tt.current&&ge(pe)}).catch(()=>{z===tt.current&&ge(null)}).finally(()=>{z===tt.current&&we(U)})},[le,n,B,be]);const Pe=_e.isCollatedKind(ye==null?void 0:ye.kind),[it,yt]=b.useState("");b.useEffect(()=>{yt("")},[n,B]);const De=b.useMemo(()=>B&&Pe?async z=>{const U=await le.getChapter(n,B,z,{json:!0});return{juan:(U==null?void 0:U.json)??null,rawText:(U==null?void 0:U.md)??null}}:null,[le,n,B,Pe]),J=(te==null?void 0:te.type)==="kaozhen",ve=b.useMemo(()=>(te==null?void 0:te.chapters.map(z=>z.file))??[],[te]),{matchStates:Qe}=Zh({resetKey:`${n}
|
|
1554
|
-
${B??""}`,load:De,files:ve,activeFile:ce??null,activeJuan:(C==null?void 0:C.json)??null,activeRawText:(C==null?void 0:C.md)??null,query:it,isKaozhen:J}),et=b.useRef(new Map);b.useEffect(()=>{et.current.clear()},[n]);const We=b.useMemo(()=>({versionKey:B,chapter:be??null}),[B,be]),He=ag(),ut=typeof s.getTextFile=="function"||!!$,pt=b.useRef(_);pt.current=_;const bt=b.useMemo(()=>
|
|
1555
|
+
${B??""}`,load:De,files:ve,activeFile:ce??null,activeJuan:(C==null?void 0:C.json)??null,activeRawText:(C==null?void 0:C.md)??null,query:it,isKaozhen:J}),et=b.useRef(new Map);b.useEffect(()=>{et.current.clear()},[n]);const We=b.useMemo(()=>({versionKey:B,chapter:be??null}),[B,be]),He=ag(),ut=typeof s.getTextFile=="function"||!!$,pt=b.useRef(_);pt.current=_;const bt=b.useMemo(()=>S||I!==void 0||!ut?void 0:async(z,U)=>{var ot;const pe=await _e.loadReaderChapter(s,{id:n,versionKey:U==null?void 0:U.versionKey,chapter:U==null?void 0:U.chapter},{cord:He,textFileBase:$});return U!=null&&U.chapter&&((ot=pt.current)==null||ot.call(pt,{chapterKey:z,ctx:U,data:pe})),(pe==null?void 0:pe.warpData)??null},[S,I,ut,s,n,He,$]),Ue=b.useMemo(()=>D||!ut?void 0:async(z,U)=>{var pe;return((pe=await _e.loadReaderFiles(s,{id:n,versionKey:U==null?void 0:U.versionKey,chapter:U==null?void 0:U.chapter},{cord:He,textFileBase:$}))==null?void 0:pe.entity)??null},[D,ut,s,n,He,$]),ft=b.useMemo(()=>h||!u||!ut?void 0:async(z,U)=>{const pe=await _e.loadReaderFiles(s,{id:n,versionKey:U==null?void 0:U.versionKey,chapter:U==null?void 0:U.chapter},{cord:He,textFileBase:$}),ot=pe!=null&&pe.cord?_e.iiifVolumeOf(pe.cord):pe!=null&&pe.cordSkipped?_e.volumeFromChar(pe.char):null;return ot?u(ot.bookId,ot.vol):null},[h,u,ut,s,n,He,$]),Q=lh(h??ft,ce??null,We,n),{warpData:A,loading:ne}=nd(S??bt,I,ce??null,We,n),$e=!Te&&V!==null&&(!!A||!!(C!=null&&C.md)||!!(C!=null&&C.json));b.useEffect(()=>{$e&&(i==null||i())},[$e,i]);const Ie=b.useRef(!1);(A||Q.images&&Q.images.length>0)&&(Ie.current=!0),b.useEffect(()=>{Ie.current=!1},[n]);const Oe=Q.loading||Cn(be)&&ne&&!A,at=Ie.current&&Oe,lt=at,qe=tg(D??Ue,ce??null,We,n),Ae=ae.properNameMode??(qe.length>0?"full":"off"),Ee=b.useMemo(()=>({...ae,properNameMode:Ae}),[ae,Ae]),rt=b.useMemo(()=>ah(qe,Ae,{showWorks:Ee.showWorks}),[qe,Ae,Ee.showWorks]),[st,Ve]=b.useState(new Set),[F,ke]=b.useState(null),[Ze]=b.useState(ch),[Ge,kt]=b.useState(!0),nt=((Mo=ye==null?void 0:ye.facsimile)==null?void 0:Mo.trimmed)??!1,Pt=nt?!0:ae.preserveMargins;b.useCallback(z=>Ce({preserveMargins:z}),[Ce]);const ct=b.useRef(null),[St,Ot]=b.useState(1),[zt,lr]=b.useState(null),sn=z=>{var pe;const U=parseInt(((pe=z==null?void 0:z.page_id)==null?void 0:pe.split(":")[1])??"",10);return isNaN(U)?null:U},ni=z=>{var pe,ot;const U=(z==null?void 0:z.pages)??[];return((pe=U.find(dt=>dt.columns.some($t=>$t.chars.length>0)))==null?void 0:pe.page)??sn(z)??((ot=U[0])==null?void 0:ot.page)??1},[xt,bi]=b.useState(()=>ni(A)),Ci=`${n}
|
|
1555
1556
|
${B}
|
|
1556
|
-
${ce??""}`,[Ei,fo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)fo({key:Ci,data:A,started:!1});else if(A!==Ei.data&&(fo({key:Ci,data:A,started:!!A}),A)){const z=A.pages??[];(!Ei.started||!z.some(U=>U.page===xt))&&bi(ni(A))}b.useEffect(()=>{Ve(new Set),Ze.set(null)},[ce,B,Ze]);const cr=Ei.key===Ci&&Ei.started,go=!!be&&os(be.headings).length===0,xo=b.useMemo(()=>go&&cr&&A?rd(A.pages,A.punctuations):[],[go,cr,A]),dr=b.useCallback(z=>{const U=os(z.headings);return U.length>0?U:z.file===ce?xo:[]},[ce,xo]),$m=b.useCallback(z=>{if(Ve(new Set(z)),z.length>0){const U=z[0],pe=parseInt(U.split(":")[0],10);isNaN(pe)||bi(pe)}},[]),Dt=b.useMemo(()=>{const z=new Map;for(const U of(A==null?void 0:A.pages)??[])z.set(U.page,U);return z},[A]),Ri=sn(A),Ti=b.useCallback(z=>{var ot;const U=Q.images;if(!U||U.length===0)return;const pe=(ot=Dt.get(z))==null?void 0:ot.seq;return(pe?U.find(dt=>dt.seq===pe):void 0)??U.find(dt=>dt.pageNo===z)??U[z-1]},[Q.images,Dt]),yo=St>1.5,on=b.useCallback((z,U=!1)=>{const pe=Ti(z);return pe?z===Ri||U?pe.hiresUrl??pe.url:pe.url:z===Ri?(A==null?void 0:A.imageUrl)??"":""},[Ti,A,Ri]),_m=b.useMemo(()=>on(xt,yo),[on,xt,yo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((z,U)=>z-U),[Dt]),ri=b.useRef(xt);ri.current=xt;const mr=b.useRef(0),ur=b.useRef({page:null,timer:null}),Nm=b.useCallback(z=>{const U=ur.current;z!==U.page&&(U.timer&&(clearTimeout(U.timer),U.timer=null),U.page=null,!(z===ri.current||Date.now()<mr.current)&&(U.page=z,U.timer=setTimeout(()=>{U.timer=null,U.page=null,!(Date.now()<mr.current||ri.current===z)&&(ri.current=z,bi(z))},og)))},[]);b.useEffect(()=>()=>{ur.current.timer&&clearTimeout(ur.current.timer)},[]);const an=b.useCallback(z=>{var U;ri.current===z||!Dt.has(z)||(mr.current=Date.now()+1e3,ri.current=z,bi(z),(U=Dt.get(z))!=null&&U.columns.some(pe=>pe.chars.length>0)&&lr(pe=>({page:z,nonce:((pe==null?void 0:pe.nonce)??0)+1})))},[Dt]),Ii=b.useCallback(z=>{const U=ri.current,pe=Wt.indexOf(U),ot=Wt[pe<0?0:pe+z];ot===void 0||ot===U||an(ot)},[Wt,an]),jo=b.useCallback(z=>{if(!z.trim().match(/^\d+$/)||Wt.length===0)return null;const pe=parseInt(z.trim(),10),ot=Number.isFinite(pe)?pe:Number.MAX_SAFE_INTEGER;return Wt.reduce((dt,$t)=>Math.abs($t-ot)<Math.abs(dt-ot)?$t:dt,Wt[0])},[Wt]),[pr,br]=b.useState(null),ln=b.useRef(null),zm=b.useCallback(z=>{ln.current=z,br(z)},[]),ko=b.useCallback(()=>{const z=ln.current;if(ln.current=null,br(null),z===null)return;const U=jo(z);U!==null&&an(U)},[jo,an]),hr=Wt.indexOf(xt),Cm=b.useCallback(z=>{if(z.altKey||z.ctrlKey||z.metaKey)return;const U=z.target.tagName;U==="INPUT"||U==="TEXTAREA"||U==="SELECT"||(z.key==="ArrowLeft"||z.key==="PageUp"?(z.preventDefault(),Ii(-1)):(z.key==="ArrowRight"||z.key==="PageDown")&&(z.preventDefault(),Ii(1)))},[Ii]),wo=b.useRef(null);b.useEffect(()=>{if(!A)return;const z=wo.current;if(!(!z||z.offsetWidth===0))for(const U of[1,-1]){const pe=on(xt+U);pe&&is(pe)}},[A,xt,on]);const vo=b.useMemo(()=>{var Fo;if(!A)return null;if(xt===Ri)return A;const z=Dt.get(xt);if(z&&z.width>0&&z.height>0)return{page_id:`p:${xt}`,title:`第${xt}葉`,image_size:[z.width,z.height],total_warped_w:z.width,columns:[{col:1,warped_w:z.width,warped_h:z.height,offset_x:0,strips:[],chars:z.columns.flatMap(mt=>mt.chars).map(mt=>({id:mt.id,char:mt.char,slot:mt.slot,pos:mt.pos,sub:mt.sub,bbox_col:mt.bbox??[0,0,0,0]}))}],...z.columns.some(mt=>mt.kind==="figure"&&mt.figBox)?{figBlocks:z.columns.filter(mt=>mt.kind==="figure"&&mt.figBox).map(mt=>({id:mt.fig,box:mt.figBox}))}:{}};const U=(Fo=A.pages)==null?void 0:Fo.find(mt=>mt.page===xt),[pe,ot]=A.image_size||[2386,3082];if(!(pe>0&&ot>0))return null;const dt=Ti(xt),$t=(dt==null?void 0:dt.width)??pe,kr=(dt==null?void 0:dt.height)??ot,Lo=$t/pe,Po=kr/ot,Oo=new Map;for(const mt of A.columns){const At=(mt.strips||[]).flatMap(pn=>pn.srcQuad.map(bn=>bn[0]));if(At.length===0)continue;const Ut=mt.top_y??0,wr=mt.bottom_y??Ut+mt.warped_h;Oo.set(mt.col,{x0:Math.min(...At),x1:Math.max(...At),top:Ut,slotH:(wr-Ut)/21})}return{page_id:`p:${xt}`,title:`第${xt}葉`,image_size:[$t,kr],total_warped_w:$t,columns:U?U.columns.map(mt=>{const At=Oo.get(mt.col)??{x0:0,x1:0,top:0,slotH:118};return{col:mt.col,warped_w:$t,warped_h:kr,offset_x:0,strips:[],chars:mt.chars.map(Ut=>{const wr=Ut.slot??Ut.pos??0,pn=(At.top+(wr-1)*At.slotH)*Po,bn=(At.x0+At.x1)/2,[Wm,Um]=Ut.sub==="a"?[bn,At.x1]:Ut.sub==="b"?[At.x0,bn]:[At.x0,At.x1];return{...Ut,bbox_col:[Wm*Lo,pn,Um*Lo,pn+At.slotH*Po]}})}}):[]}},[A,xt,Ri,Dt,Ti]),{entryTitle:cn,authors:So}=fg(n,s,m===void 0),[$o,fr]=b.useState("text");b.useEffect(()=>{fr("text")},[ce,B]);const Em=b.useMemo(()=>te?mg(te,Qe,Ka(ye,te),P,Pe,dr):[],[te,Qe,ye,P,Pe,dr]),_o=Sh(),No=b.useRef(null),zo=b.useRef(null),gr=b.useMemo(()=>{const z=[];return A&&z.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ge?"bim-rd-on":""}`,"aria-pressed":Ge,title:"切换外挂现代断句标点",onClick:()=>kt(U=>!U),children:Ge?"标点":"无标点"})}}),z},[A,Ge]),Rm=b.useMemo(()=>R&&R.length>0?[...gr,...R]:gr,[gr,R]),Tm=b.useMemo(()=>ye&&be&&B?{entryId:n,versionKey:B,chapterKey:be.file,chapter:be,version:ye,transport:s,viewport:_o}:null,[n,B,be,ye,s,_o]),Im=b.useCallback(z=>{ce&&Z(ce,z)},[ce,Z]),si=_h({plugins:Rm,ctx:Tm,prefs:Ee,setPrefs:Ce,t:q,convert:P,pages:A==null?void 0:A.pages,textRootRef:No,shellTextRef:zo,selectedCharIds:st,scrollToAnchor:Im});if(H==="loading")return t.jsx(Wa,{className:O,style:M,title:m??cn,label:q("reader.loading")});if(H==="missing"||!se||!ye)return t.jsx("div",{className:O,style:{...M,...Da},children:q("reader.noText")});if(L==="failed")return t.jsx("div",{className:O,style:{...M,...Da},children:q("reader.tocFailed")});if(!te)return t.jsx(Wa,{className:O,style:M,title:m??cn,label:q("reader.tocLoading")});const hi=Ka(ye,te),Mm=Em,Co=Ye&&ce&&Ye.chapter===ce?eo(ce,Ye.anchor):null,Am=Co&&be&&dr(be).some(z=>z.anchor===Ye.anchor)?Co:ce??null,xr=se.versions.map(z=>({key:z.key,label:_e.textVersionLabel(z),optionLabel:P(_e.textVersionLabel(z)),sourceName:Ya(z)?q("reader.originalSource"):z.source_name?P(z.source_name):void 0,license:z.license??void 0,sourceUrl:z.source_url??void 0,primary:z.key===Ne})),Mt=cg((Ao=te.source)==null?void 0:Ao.upstream),dn=(typeof m=="string"?P(m):m)??(te.title?P(te.title):cn?P(cn):void 0),Eo=ye.edition_label?P(ye.edition_label):void 0,yr=dn?t.jsx("a",{href:xe(n),title:q("reader.viewEntry"),onClick:d?z=>{z.metaKey||z.ctrlKey||(z.preventDefault(),d(n))}:void 0,children:dn}):void 0,Lm=yr&&Eo?t.jsxs(t.Fragment,{children:[yr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Eo]})]}):yr,Pm=So.length>0?P(So.slice(0,2).map(z=>`${z.dynasty?`〔${z.dynasty}〕`:""}${z.name}${` ${z.role||q("reader.defaultRole")}`}`).join("、")):void 0,jr=be?ad(be,hi,P,Pe):void 0,oi=Pe&&!!(C!=null&&C.json),ai=(C==null?void 0:C.json)??null,fi=(C==null?void 0:C.md)??null,Ro=oi&&!J&&Yc(ai.sections),Om=Ro&&!(fi&&Ee.readingMode==="paragraph"&&Mn(fi)),Fm=oi&&Ro?t.jsx(Qh,{juan:ai,view:$o,onView:fr,textHasEntries:Om}):void 0,Bm=!0,mn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,un=Ya(ye),Xt=un?q("reader.originalSource"):ye.source_name?P(ye.source_name):void 0,Hm=(typeof p=="string"?P(p):p)??(un?void 0:Xt??P(_e.textVersionLabel(ye))),Dm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(sc,{className:O,style:M,title:Lm,subtitle:Hm,byline:Pm,current:jr,pagerUnit:hi,rail:Fm,revisedAt:k,backHref:x,backLabel:j,onReportError:S?z=>S({...z,bookTitle:typeof dn=="string"?dn:void 0,entryId:n}):void 0,workLinkToggle:oi&&!J&&!!d&&!!(ai!=null&&ai.sections.some(z=>z.work_id)),toc:Mm,tocCaption:q("reader.tocCaption",{n:te.chapters.length,unit:P(hi)}),tocHeader:Pe&&te.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:J?q("reader.searchChaptersPlaceholder"):q("reader.searchUnitPlaceholder",{unit:P(hi)}),"aria-label":J?q("reader.searchChapters"):q("reader.searchUnit",{unit:P(hi)}),value:it,onChange:z=>yt(z.target.value)}):void 0,activeKey:ce??null,tocActiveKey:Am,onSelect:he,images:Cn(be)&&ne&&!A?null:Q.images,renderImageOverlay:f,imagePanel:A||at?"open":g,imagesLoading:lt,isWarpMode:!!A,showPreserveMargins:!nt,customImagePanel:A&&vo?t.jsxs("div",{ref:wo,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Cm,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:[st.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ve(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",st.size,")"]}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:2},"data-testid":"facsimile-zoom-tools",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小",title:"缩小",disabled:St<=1,onClick:()=>{var z;return(z=ct.current)==null?void 0:z.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 z;return(z=ct.current)==null?void 0:z.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:St===1,onClick:()=>{var z;return(z=ct.current)==null?void 0:z.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(eg,{ref:ct,resetKey:xt,onScaleChange:Ot,style:{flex:1,minHeight:0},children:t.jsx(Sa,{store:Ze,children:z=>{var U;return t.jsx(Ys,{imageUrl:_m,pageData:vo,selectedCharIds:st,hoveredCharId:z,decorations:si.decorations,preserveMargins:Pt,banxinMode:ae.banxinMode,extent:(U=Ti(xt))==null?void 0:U.extent,renderScale:St,selectedFigBlock:F,onFigBlockClick:pe=>ke(pe),onCharClick:pe=>{ke(null),Ve(dt=>{const $t=new Set(dt);return $t.has(pe)?$t.delete(pe):($t.clear(),$t.add(pe)),$t});const ot=document.querySelector(`[data-char-id="${pe}"]`);ot&&ot.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Ze.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:hr<=0,onClick:()=>Ii(-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(pr??xt).length),value:pr??String(xt),onFocus:z=>z.currentTarget.select(),onChange:z=>zm(z.target.value),onKeyDown:z=>{z.key==="Enter"?(z.preventDefault(),ko()):z.key==="Escape"&&(ln.current=null,br(null)),z.stopPropagation()},onBlur:ko,style:{width:`${Math.max(2,String(pr??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:hr<0||hr>=Wt.length-1,onClick:()=>Ii(1),children:"›"})]})]}):void 0,pluginSettings:si.settings,pluginToolbar:si.toolbar,pluginOverlay:si.overlay,textRootRef:zo,prefs:Ee,onPrefsChange:Ce,versions:xr.length>1?xr:void 0,currentVersionKey:xr.length>1?ye.key:void 0,onVersionChange:Xe,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Mn(fi),allowVertical:y,origScriptAvailable:Dm,contentLoading:Te,children:[(Te||ne&&!A&&!oi&&mn==null)&&t.jsx(Xl,{}),!Te&&A&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:No,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:be!=null&&be.title?P(be.title):jr}),(Xt||ye.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,ye.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),ye.license]})]})]}),t.jsx(Sa,{store:Ze,children:z=>t.jsx(Zs,{pageData:A,pages:A.pages,punctuations:A.punctuations||lg,selectedCharIds:st,hoveredCharId:z,onSelectionChange:$m,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:U,fig:pe})=>{Ve(new Set),ke(pe),bi(U)},onCharClick:U=>{ke(null),Ve(ot=>{const dt=new Set(ot);return dt.has(U)?dt.delete(U):(dt.clear(),dt.add(U)),dt});const pe=parseInt(U.split(":")[0],10);isNaN(pe)||bi(pe),si.onCellClick(U)},onCharHover:U=>{Ze.set(U),si.onCellHover(U)},decorations:si.decorations,mode:"horizontal",showPunctuation:Ge,entities:rt,entityTransport:s,onEntityNavigate:E,onVisiblePageChange:Nm,convert:P,scrollToPage:zt,scrollToAnchor:Be&&Be.chapter===ce&&cr?Be:null,onVisibleHeadingChange:U=>w(U&&ce?{chapter:ce,anchor:U}:null),pageBreaks:Ee.pageBreaks,pageIndicatorY:Ee.pageIndicatorY,onPageIndicatorYChange:U=>Ce({pageIndicatorY:U}),quoteStyle:Ee.quoteStyle,bookTitleStyle:Ee.bookTitleStyle,showWorks:Ee.showWorks})})]}),!Te&&!A&&oi&&ai&&t.jsx(Jh,{juan:ai,rawText:fi,positionLabel:bg(be,te,hi,P),groupLabel:hg(te,ce??null),index:dg(n,te),searchQuery:it,onNavigate:d,transport:s,workLabelCache:et,prefs:Ee,view:$o,onViewChange:fr},`${B}/${ce}`),!Te&&!A&&!oi&&mn!=null&&be&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:be.title?P(be.title):jr}),(Xt||ye.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[un&&Xt&&t.jsx(t.Fragment,{children:Xt}),!un&&ye.source_name&&t.jsxs(t.Fragment,{children:[q("reader.textSource")," ",ye.source_url?t.jsx("a",{className:"bim-rd-link",href:ye.source_url,target:"_blank",rel:"noreferrer",children:P(ye.source_name)}):P(ye.source_name)]}),Xt&&ye.license&&t.jsx("span",{className:"bim-rd-dot"}),ye.license]}),Mt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[q("reader.upstream")," ",Mt.url?t.jsx("a",{className:"bim-rd-link",href:Mt.url,target:"_blank",rel:"noreferrer",children:P(Mt.name??Mt.url)}):P(Mt.name??""),Mt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),Mt.license_url?t.jsx("a",{className:"bim-rd-link",href:Mt.license_url,target:"_blank",rel:"noreferrer",children:Mt.license}):Mt.license]}),Mt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(Jl,{text:Mt.note,convert:P})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Os,{text:mn,mode:Ee.readingMode,tables:Bm,gujiMarkdown:!0,bookMarking:Ps(Ee),quoteStyle:Ee.quoteStyle})})]}),!Te&&!ne&&!A&&!oi&&mn==null&&be&&t.jsx("div",{className:"bim-rd-state",children:q("reader.chapterFailed")}),!Te&&te.references&&te.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:q("reader.references")}),t.jsx("ol",{children:te.references.map((z,U)=>t.jsxs("li",{children:[z.url?t.jsx("a",{className:"bim-rd-link",href:z.url,target:"_blank",rel:"noopener noreferrer",children:P(z.title)}):t.jsx("span",{children:P(z.title)}),z.author&&t.jsxs("span",{children:[",",P(z.author)]}),z.note&&t.jsxs("span",{children:["。",P(z.note)]})]},U))})]})]})};function Ya(e){return e.is_original===!0||e.source==="original"}function bg(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 hg(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 fg(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 gg=({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),S=b.useRef(null),k=b.useCallback($=>{m(new Set($))},[]),x=b.useCallback($=>{if(m(_=>{const N=new Set(_);return N.has($)?N.delete($):(N.clear(),N.add($)),N}),S.current){const _=S.current.querySelector(`[data-char-id="${$}"]`);_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{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:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>y($=>!$),className:`guji-reader-btn ${g?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:g?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f($=>$==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:u==="horizontal"?"切换竖排":"切换横排"})]})]}),t.jsxs("div",{className:"guji-reader-body",children:[t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%",position:"sticky",top:0},children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:"底本书影 (WebGL 分带透视矫正 + 完整版心)"}),t.jsx("span",{className:"guji-pane-hint",children:"点击字框可联动文本定位"})]}),t.jsx("div",{className:"guji-pane-content",children:t.jsx(Ys,{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:S,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(Zs,{pageData:e,punctuations:v,selectedCharIds:c,hoveredCharId:p,onSelectionChange:k,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},xg=({data:e,onNavigate:i,className:n,style:s})=>{var p;const{t:o,convert:a}=oe(),[l,d]=b.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[c,m]=b.useState(null);return t.jsxs("div",{className:n,style: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(yg,{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))})]})},yg=({division:e,expanded:i,onToggle:n,expandedCat:s,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=oe(),c=e.categories.reduce((m,p)=>{const h=p.stats||{zhulu:0,cunmu:0};return m+(h.zhulu||0)+(h.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${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(jg,{category:m,expanded:s===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},jg=({category:e,expanded:i,onToggle:n,onNavigate:s})=>{var m,p,h,u;const{t:o,convert:a}=oe(),l=((m=e.books)==null?void 0:m.zhulu)||[],d=((p=e.books)==null?void 0:p.cunmu)||[],c=(((h=e.stats)==null?void 0:h.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:i?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(Va,{label:o("catalogPage.zhulu"),books:l,onNavigate:s}),d.length>0&&t.jsx(Va,{label:o("catalogPage.cunmu"),books:d,onNavigate:s})]})]})},Va=({label:e,books:i,onNavigate:n})=>{const{t:s,convert:o}=oe(),a=It(),[l,d]=b.useState(i.length<=20),c=l?i:i.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color: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 to(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 dd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const kg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],md=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:s})=>{const{t:o}=oe(),[a,l]=b.useState(null),[d,c]=b.useState(""),[m,p]=b.useState(""),[h,u]=b.useState("idle"),[f,g]=b.useState(""),y=b.useRef(null);b.useEffect(()=>{e&&(l(null),c(""),p(""),u("idle"),g(""))},[e]),b.useEffect(()=>{a&&setTimeout(()=>{var x;return(x=y.current)==null?void 0:x.focus()},100)},[a]),b.useEffect(()=>{if(h==="success"){const x=setTimeout(i,2e3);return()=>clearTimeout(x)}},[h,i]),b.useEffect(()=>{if(!e)return;const x=j=>{j.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const S=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 k=a&&d.trim()&&h!=="submitting";return t.jsx("div",{style:wg,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:vg,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Sg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:$g,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Eg,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:kg.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{..._g,...a===x.value?Ng:{}},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:{...zg,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:Tg}),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:Rg,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:S,disabled:!k,style:{...Cg,opacity:k?1:.6,cursor:k?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},wg={position:"fixed",top:0,left:0,right:0,bottom:0,background:r.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},vg={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r.bim("shadow-dialog")},Sg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},$g={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},_g={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"},Ng={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},zg={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"},Cg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},Eg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r.bim("success")},Rg={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Tg={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"},as="--bim-feedback-fab-offset",ls=48,Ig=16,Mg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:s=!1,zIndex:o})=>{const{t:a}=oe(),[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(as,`calc(${c+ls+Ig}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(as)}},[s,c]),t.jsxs(t.Fragment,{children:[!s&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Ag,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(md,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},Ag={position:"fixed",width:`${ls}px`,height:`${ls}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"},Lg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],ud=({onSubmit:e})=>{const{t:i}=oe(),[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:Ga,children:t.jsxs("div",{style:Hg,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:Dg,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Ga,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Lg.map(y=>t.jsxs("button",{onClick:()=>s(y.value),style:{...Pg,...n===y.value?Og:{}},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:{...Fg}}),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:Ug}),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:{...Bg,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:Wg,children:p})]})},Ga={padding:"16px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",background:r.bim("input-bg")},Pg={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"},Og={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},Fg={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"},Bg={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},Hg={display:"flex",alignItems:"center",gap:"12px",color:r.bim("success"),fontSize:"14px"},Dg={background:"none",border:"none",color:r.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Wg={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},Ug={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"},pd={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")}},Kg=pd.other,bd={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")}},Yg=bd.pending;function Vg(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 Gg(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 hd=({items:e,loading:i})=>{const n=It(),{t:s,convert:o}=oe();return i?t.jsx(Xl,{}):e.length===0?t.jsx("div",{style:qg,children:s("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=pd[a.type]||Kg,d=bd[a.status]||Yg,c=typeof window<"u"&&Gg(a.pageUrl,window.location.href);return t.jsxs("div",{style:Xg,children:[t.jsxs("div",{style:Jg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...qa,background:l.color},children:s(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...qa,background:d.color},children:s(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Zg,children:Vg(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Qg,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Or,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Or,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Or,children:a.pageUrl}))]}),t.jsx("div",{style:ex,children:o(a.content)}),a.reply&&t.jsxs("div",{style:tx,children:[t.jsx("div",{style:ix,children:s("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},qg={textAlign:"center",padding:"40px 0",color:r.bim("desc-fg"),fontSize:"14px"},Xg={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},Jg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},qa={fontSize:"12px",color:r.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Zg={fontSize:"12px",color:r.bim("desc-fg")},Qg={fontSize:"12px",marginBottom:"6px"},Or={color:r.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${r.bim("primary")}`},ex={fontSize:"14px",lineHeight:"1.6",color:r.bim("fg"),whiteSpace:"pre-wrap"},tx={marginTop:"12px",padding:"10px 12px",background:r.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r.bim("fg")},ix={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r.bim("primary")},fd=({resourceId:e,transport:i,apiUrl:n})=>{const{t:s}=oe(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(s);c.current=s;const m=b.useMemo(()=>i??to(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(hd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(ud,{onSubmit:h})})]})},Qn=8;async function er(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 nx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function rx(e){const i=e.search(nx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const gd={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===sx(e))){const[a,l]=rx(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 sx(e){try{return decodeURI(e)}catch{return e}}const ox={...gd,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:s})=>{const{convert:o}=gt(),a=i?ox:gd;return t.jsx("div",{className:s,style:n,children:t.jsx(Zm,{remarkPlugins:[Qm],components:a,children:o(e)})})},ax=r.detail["zh-Hant"].relation,lx=r.detail["zh-Hant"].lossStatus,cx=r.detail["zh-Hant"].resourceKind,tr=r.getT("zh-Hant"),io=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function Xa(e,i=tr){return e?io(ax,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function dx(e,i=tr){return io(lx,e)?i(`detail.lossStatus.${e}`):e}function mx(e,i=tr){return io(cx,e)?i(`detail.resourceKind.${e}`):""}function no({authors:e,onNavigate:i,renderLink:n}){const{convert:s}=oe(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=ys(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 xd(e,i,n=tr){var c,m;const s=gs(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 yd(e,i){const n=(e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name,s=Cl(e,i);return s?`${n}(${s})`:n}function ro({item:e,siblings:i,listedVolumeCounts:n}){const{t:s,convert:o}=oe(),[a,l]=b.useState(!1),d=r.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(yd(e,i)),p=r.resourceHref(e),h=Wn(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(Ts,{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 jd({groups:e,listedVolumeCounts:i}){const{t:n,convert:s}=oe();return t.jsx(t.Fragment,{children:e.map(o=>t.jsxs("div",{className:"bim-d-rg",children:[o.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children: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(ro,{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(yd(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 Yi=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function cs(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Yi.find(s=>i.startsWith(s.key[0])))==null?void 0:n.key}const Ja=12,ux=60,kd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,railTop:a,back:l,railLinks:d})=>{var Me,Se,Je;const{t:c,convert:m,messages:p}=oe(),h=b.useMemo(()=>js({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[S,k]=b.useState(""),[x,j]=b.useState(!1),v=h.length<=ux,$=v||g||!!S||x,_=b.useMemo(()=>$?h:h.slice(0,Ja),[h,$]);b.useEffect(()=>{if(!i||_.length===0)return;const X=_.filter(L=>!u.has(L));if(X.length===0)return;let je=!1;return er(X,Qn,L=>i.getItem(L).then(G=>{var te;const ie=G??{};return[L,{id:L,title:ie.title,edition:ie.edition,resources:ie.resources,publication_info:ie.publication_info,current_location:ie.current_location,provenance:ie.provenance,lineage:ie.lineage,related_books:ie.related_books,dating:ie.dating,measure_info:ie.measure_info,summary:bx((te=G==null?void 0:G.description)==null?void 0:te.text)}]}).catch(()=>[L,{id:L}]),()=>je).then(L=>{je||f(G=>{const ie=new Map(G);for(const[te,ce]of L)ie.set(te,ce);return ie})}),()=>{je=!0}},[i,_,u]);const N=b.useMemo(()=>h.map(X=>u.get(X)??{id:X}),[h,u]),I=h.length>0&&h.every(X=>u.has(X)),D=!!i&&_.some(X=>!u.has(X)),E=v||$,R=b.useMemo(()=>Rl(N,e.version_graph,{era:S,scanOnly:x,sort:E?"year":"default"}),[N,e.version_graph,S,x,E]),O=g?R.rows:R.rows.slice(0,Ja),M=R.allRows.filter(X=>X.hasImage).length,q=R.allRows.reduce((X,je)=>{var L;return X+(((L=je.copies)==null?void 0:L.length)??0)},0),P=b.useMemo(()=>(e._related||[]).map(X=>({...X,title:X.title??""})),[e._related]),le=P.filter(X=>X.relation==="collected_in"),ae=b.useMemo(()=>{const X=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],je=L=>{const G=X.indexOf(L??"");return G<0?X.length:G};return P.filter(L=>L.relation!=="collected_in").map((L,G)=>({r:L,i:G})).sort((L,G)=>je(L.r.relation)-je(G.r.relation)||L.i-G.i).map(L=>L.r)},[P]),Ce=b.useMemo(()=>{const X=gs(e.resources,e.resource_groups);return[...X.mirrors.flatMap(je=>je.items.map(L=>({r:L,kind:m(je.label)}))),...X.buckets.flatMap(je=>je.items.map(L=>({r:L,kind:m(mx(je.key,c))})))]},[e.resources,e.resource_groups,m,c]),xe=e.indexed_by||[],fe=e.emendated_by||[],se=b.useMemo(()=>{var be,Fe,Xe,Be,Ke;const X=[],je=(Fe=(be=e.authors)==null?void 0:be[0])==null?void 0:Fe.dynasty;je&&X.push({label:c("workPage.fact.written"),value:m(je)});const L=qt(e,p.unit.juan);if(L){const Ye=((Xe=e.juan_count)==null?void 0:Xe.description)??((Ke=(Be=e.measures)==null?void 0:Be.find(w=>(w==null?void 0:w.unit)==="卷"&&w.note))==null?void 0:Ke.note);X.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(L),Ye&&Ye!==L?t.jsxs("span",{className:"bim-d-meta",children:["(",m(Ye),")"]}):null]})})}e.loss_status&&X.push({label:c("workPage.fact.loss"),value:m(dx(e.loss_status,c))}),e.authenticity==="forged"&&X.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const G=R.allRows.filter(Ye=>Ye.sortYear!=null),ie=G.length>0?G.reduce((Ye,w)=>Ye.sortYear<=w.sortYear?Ye:w):null;ie!=null&&ie.era.era?X.push({label:c("workPage.fact.earliest"),value:m([ie.era.era,ie.era.reign].filter(Boolean).join(" ")),title:ie.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):D&&X.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),fe.length&&X.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:fe.length})});const te=px(e.additional_titles);te.length&&X.push({label:c("workPage.fact.alias"),value:te.map(m).join("、")});const ce=(e.additional_works||[]).map(Ye=>m(Ye.book_title)+(Ye.n_juan!=null?` ${Ye.n_juan}${p.unit.juan}`:""));return ce.length&&X.push({label:c("workPage.fact.appendix"),value:ce.join("、")}),X},[e,m,c,p,D,R.allRows,fe.length]),H=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:I?M:0,label:c("workPage.stat.hasImage")},{value:xe.length,label:c("workPage.stat.catalogs")}],me=ks(e),W=me?[me.l1,me.l2,me.l3,me.l4].filter(Boolean).map(X=>m(X)):[],K=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",re=t.jsx(Qi,{title:m(e.title),byline:t.jsx(no,{authors:e.authors,onNavigate:n,renderLink:s}),meta:t.jsx(vt,{items:[...W,me!=null&&me.source?c("workPage.classifiedBy",{source:m(me.source.split("/")[0])}):"",K]}),description:(Me=e.description)!=null&&Me.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Se=e.description.sources)!=null&&Se.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(X=>({text:m(Bu(X)),href:Hu(X)})).filter(X=>X.text).map((X,je)=>t.jsxs(b.Fragment,{children:[je>0?" · ":null,X.href?t.jsx("a",{href:X.href,target:"_blank",rel:"noopener noreferrer",children:X.text}):X.text]},je))}):null]}):void 0,stats:H,facts:se,readAction:o,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Je=e.appendix)==null?void 0:Je.map((X,je)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(X.title)}),t.jsx(zi,{text:X.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},je))}),Y=R.eras.length>=2?[{key:"",label:c("catalog.all")},...R.eras.map(X=>({key:X,label:`${X} ${R.allRows.filter(je=>je.era.era===X).length}`}))]:[],T=[];h.length&&T.push({id:"versions",label:c("workPage.sec.versions"),count:h.length}),xe.length&&T.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:xe.length}),le.length&&T.push({id:"collected",label:c("workPage.sec.collected"),count:le.length}),ae.length&&T.push({id:"related",label:c("workPage.sec.related"),count:ae.length}),Ce.length&&T.push({id:"resources",label:c("workPage.sec.resources"),count:Ce.length});const ue=h.length===0&&xe.length===0,ye=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}),I&&M?c("workPage.versionsWithImage",{n:M}):"",R.rows.length!==R.allRows.length?c("workPage.versionsCurrent",{n:R.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":D&&Y.length===0&&h.length>1?"":void 0,children:[Y.length>0&&t.jsx(qn,{items:Y,value:S,onChange:X=>{k(X),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(bc,{label:c("workPage.scanOnly"),checked:x,onChange:X=>{j(X),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(E?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&Xn(R.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:O.map(X=>{var je;return t.jsx(fx,{row:X,measure:(je=u.get(X.id))==null?void 0:je.measure_info,loaded:u.has(X.id),onNavigate:n,renderLink:s},`${X.id}:${u.has(X.id)?"r":"p"}`)})})]}),O.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(S||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx(zs,{total:R.rows.length,shown:O.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),xe.length>0&&t.jsx(gx,{items:xe,transport:i,onNavigate:n,renderLink:s}),ue&&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")})})]}),Ne=(X,je)=>t.jsx(wt,{id:X,label:m(je),onNavigate:n,renderLink:s,dense:!0}),B=b.useMemo(()=>{const X=new Map;for(const je of ae){const L=Xa(je.relation,c);X.set(L,(X.get(L)??0)+1)}return X.size>1?[...X.entries()].sort((je,L)=>L[1]-je[1]).slice(0,4).map(([je,L])=>`${m(je)} ${L}`).join(" · "):void 0},[ae,m,c]),de=t.jsxs(t.Fragment,{children:[t.jsx(di,{id:"collected",title:c("workPage.sec.collected"),items:le.map(X=>Ne(X.id,X.title))}),t.jsx(di,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:ae.length}),sub:B,items:ae.map(X=>t.jsxs(t.Fragment,{children:[Ne(X.id,X.title),t.jsx("span",{className:"bim-d-meta",title:X.note?m(X.note):void 0,children:m(Xa(X.relation,c))})]}))}),t.jsx(di,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:Ce.map(({r:X,kind:je})=>{const L=m((X.url?r.getDisplayNameFromUrl(X.url):void 0)||X.name),G=r.resourceHref(X);return t.jsxs(t.Fragment,{children:[G?t.jsxs("a",{href:G,target:"_blank",rel:"noopener noreferrer",children:[L," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:L}),je&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:je})]})})})]});return t.jsx(Zi,{railTop:a,back:l,nav:T,railLinks:d,main:ye,card:re,side:de})};function px(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function ds(e,i){return i((e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name)}function bx(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 hx({copies:e,onNavigate:i,renderLink:n}){const{t:s,convert:o}=oe(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?ds(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 fx({row:e,measure:i,loaded:n,onNavigate:s,renderLink:o}){const{t:a,convert:l}=oe(),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?ds(m,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?r.resourceHref(u):void 0,g=e.images.map(y=>ds(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(hx,{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 gx({items:e,transport:i,onNavigate:n,renderLink:s}){const{t:o,convert:a}=oe(),[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 S,k;return[g,((k=(S=y==null?void 0:y.authors)==null?void 0:S[0])==null?void 0:k.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:Lt(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:Lt(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:Lt(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 wd=({graph:e,renderLink:i,className:n,style:s})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Rx,...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:{...yx,...s},children:[e.title&&t.jsx("div",{style:jx,children:a(e.title)}),e.description&&t.jsx("div",{style:kx,children:a(e.description)}),u.map(f=>t.jsx(Za,{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(Za,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},Za=({label:e,color:i,nodes:n,incomingMap:s,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:wx,children:[t.jsx("div",{style:{...vx,borderLeftColor:i??r.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(xx,{node:c,incoming:s.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},xx=({node:e,incoming:i,siblings:n,nodeMap:s,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=oe();return t.jsxs("div",{style:{...Sx,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:$x,children:[t.jsx("span",{style:_x,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Nx,children:$l(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:zx,children:[e.category&&t.jsx(Pi,{children:c(e.category)}),e.status==="lost"&&t.jsx(Pi,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Pi,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Pi,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Pi,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Cx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ex,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:el,children:[t.jsx("div",{style:tl,children:d("lineage.sources")}),i.map(m=>{const p=s.get(m.source);return t.jsxs("div",{style:il(m.confidence),children:[t.jsx("span",{style:nl,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(Qa,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:rl,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:el,children:[t.jsx("div",{style:tl,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:il(m.confidence),children:[t.jsx("span",{style:nl,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(Qa,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:rl,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Pi=({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})},Qa=({level:e})=>{const{t:i}=oe(),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},yx={fontSize:"14px",color:r.bim("fg")},jx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},kx={fontSize:"13px",color:r.bim("muted"),marginBottom:"16px",lineHeight:1.6},wx={marginBottom:"16px"},vx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r.bim("fg")},Sx={border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r.bim("bg")},$x={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},_x={fontSize:"15px",fontWeight:600},Nx={fontSize:"12px",color:r.bim("muted")},zx={marginBottom:"6px"},Cx={fontSize:"12px",color:r.bim("muted"),margin:"2px 0"},Ex={fontSize:"12px",color:r.bim("muted"),fontStyle:"italic",margin:"4px 0"},el={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r.bim("widget-border")}`},tl={fontSize:"11px",color:r.bim("muted"),marginBottom:"2px"},il=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),nl={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r.bim("tag-bg"),color:r.bim("fg"),borderRadius:"3px",marginRight:"6px"},rl={fontSize:"11px",color:r.bim("muted")},Rx={padding:"20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px"},vd=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[s,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Tx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),s==="loading"?t.jsx("div",{style:ol,children:n("lineage.graphLoading")}):s==="missing"||!a?t.jsxs("div",{style:ol,children:[t.jsx("div",{children:sl(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:sl(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Ix,{modules:a,selectedNodeId:e,...i})};function sl(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 Tx(){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 Ix=({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,S=b.useMemo(()=>({lineage:_=>{var le,ae,Ce,xe;const N=((le=_.data)==null?void 0:le.stepPosition)??.85,[I,D,E]=g({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:N,borderRadius:5}),R=!!((ae=_.data)!=null&&ae.isSibling),O=R?D:_.targetX-18,M=R?E:_.targetY-12,q=(Ce=_.data)==null?void 0:Ce.labelStyle,P=(xe=_.data)==null?void 0:xe.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:_.id,path:I,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${O}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")}`,...P,...q},children:_.label})})]})}}),[u,f,g]),k=b.useMemo(()=>({version:_=>{const{t:N}=oe(),I=_.data,D=I.kind==="hypothetical",E=I.status==="lost",R=I.isSelected,O=I.bridge,M=I.borderColor??r.bim("muted"),q=O||D?"dashed":"solid",P=O?.5:E?.6:1;return t.jsxs("div",{style:{background:O?r.bim("bg-subtle"):r.bim("bg"),border:`2px ${q} ${R?r.bim("primary"):M}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:P,boxShadow:R?r.bim("shadow-node-selected"):D||O?"none":r.bim("shadow-node")},title:O?N("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:D||!I.renderLink?I.label:I.renderLink(I.bookId,I.label)}),I.description&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:I.description}),I.yearText&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.2},children:$l(I.yearText,void 0,I.uncertain)}),E&&t.jsx("div",{style:{fontSize:9,color:r.bim("lost-fg"),marginTop:1},children:N("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=oe(),{rfNodes:j,rfEdges:v}=b.useMemo(()=>Mx(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:j,edges:v,nodeTypes:k,edgeTypes:S,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 Mx(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(k=>[k.id,k.color??r.bim("muted")]));for(const k of e.nodes)c.setNode(k.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const k of e.edges)k.kind==="derive"&&(p.has(k.relation)||c.setEdge(k.source,k.target));i.layout(c);const h=e.nodes.map(k=>{const x=c.node(k.id),j=s?k.id===s:void 0,v={kind:k.kind,label:o(k.label),bookId:k.kind==="book"?k.id:void 0,yearText:o(k.year_text??Lx(k)),uncertain:k.year_uncertain,category:k.category,status:k.status,borderColor:k.group?m.get(k.group):void 0,renderLink:n,isSelected:j,description:o(k.description),bridge:k.bridge};return{id:k.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:v,draggable:!1,selected:j}}),u=.78,f=.06,g=new Map;for(const k of e.edges)k.kind==="derive"&&(g.has(k.source)||g.set(k.source,[]),g.get(k.source).push(k));const y=new Map;for(const[k,x]of g){if(x.length<=1)continue;const j=[...x].sort(($,_)=>{var D,E;const N=((D=c.node($.target))==null?void 0:D.y)??0,I=((E=c.node(_.target))==null?void 0:E.y)??0;return N-I}),v=j.length;j.forEach(($,_)=>{const N=(_-(v-1)/2)*f;y.set($.id,u+N)})}const S=e.edges.map(k=>Ax(k,y.get(k.id),o));return{rfNodes:h,rfEdges:S}}function Ax(e,i,n=s=>s??""){const s=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Px(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 Lx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Px(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 ol={padding:"40px 20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px",border:`1px dashed ${r.bim("widget-border")}`,borderRadius:8,background:r.bim("bg")},so=({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}=oe(),[g,y]=b.useState(i),S=$=>{y($),a==null||a($)},k=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const j=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:Ox,children:[t.jsx("button",{onClick:()=>S("list"),style:Fr(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>S("graph"),style:Fr(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")}),k.map(([$,_])=>{const N=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Fr(l===$),title:_.description?f(_.description):void 0,children:[f(_.label),N!=null?` ${N}`:""]},$)})]})]}),x&&j&&t.jsx("div",{style:{fontSize:12,color:r.bim("muted"),marginBottom:8,padding:"4px 8px",background:r.bim("bg-subtle"),borderRadius:4},children:f(j)}),g==="list"?t.jsx(wd,{graph:e,renderLink:n}):t.jsx(vd,{graph:e,renderLink:n,height:s,selectedNodeId:o})]})},Ox={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Fr=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"}),al=40,ll=2,Fx=9,Bx=new Set(["certain","consensus","probable","disputed"]);function Br(e){if(!e)return["",""];const i=e.split(/[ ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const Sd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Fe,Xe,Be,Ke,Ye,w,ee,Z,he,Le;const h=r.useT(),{t:u,convert:f}=oe(),[g,y]=b.useState(null),[S,k]=b.useState(new Map),[x,j]=b.useState([]),[v,$]=b.useState(new Map),[_,N]=b.useState(!1),[I,D]=b.useState("flow"),[E,R]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let C=!1;return i.getItem(e.work_id).then(ge=>{!C&&ge&&ge.type==="work"&&y(ge)}).catch(()=>{}),()=>{C=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){R(null);return}let C=!1;return i.getLineageGraph(e.work_id).then(ge=>{C||R(ge&&ge.nodes.length>1?ge:null)}).catch(()=>{C||R(null)}),()=>{C=!0}},[i,e.work_id]),b.useEffect(()=>{const C=e._collections||[];if(!i||C.length===0){k(new Map);return}let ge=!1;return Promise.all(C.map(V=>{const ze=V.id;return i.getItem(ze).then(we=>[ze,we]).catch(()=>[ze,null])})).then(V=>{if(ge)return;const ze=new Map;for(const[we,Te]of V)Te&&ze.set(we,Te);k(ze)}),()=>{ge=!0}},[i,e._collections]);const O=b.useMemo(()=>{const C=new Set([...g?js(g):[],...hu(e)]);return C.add(e.id),[...C]},[g,e.related_books,e.id]),M=O.length-1;b.useEffect(()=>{if(!i||M<=0){j([]);return}const C=O.length<=al,ge=C?O:O.slice(0,8);let V=!1;return Promise.all(ge.map(ze=>ze===e.id?Promise.resolve({id:ze,title:e.title,edition:e.edition,year:Tn(e)}):i.getItem(ze).then(we=>{const Te=we??{};return{id:ze,title:Te.title,edition:Te.edition,year:we?Tn(Te):void 0}}).catch(()=>({id:ze})))).then(ze=>{if(V)return;const we=ze.filter(Te=>Te.id===e.id||Te.title||Te.edition);C&&we.sort((Te,tt)=>(Te.year??1/0)-(tt.year??1/0)),j(we)}),()=>{V=!0}},[i,O,M,e]),e.lineage;const q=b.useMemo(()=>[...Gt(e).filter(C=>C.ref_type==="book").map(C=>C.ref),...mi(e).map(C=>C.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||q.length===0){$(new Map);return}let C=!1;return Promise.all(q.map(ge=>i.getItem(ge).then(V=>[ge,{id:ge,title:V==null?void 0:V.title,edition:V==null?void 0:V.edition}]).catch(()=>[ge,{id:ge}]))).then(ge=>{C||$(new Map(ge))}),()=>{C=!0}},[i,q]);const P=b.useMemo(()=>xd(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),le=P.groups.reduce((C,ge)=>C+ge.rows.length+ge.mirrors.length,0),ae=P.groups.length>0&&P.groups.every(C=>C.key==="_physical"),Ce=Ji(e),xe=Ll(e),fe=qt(e,h.unit.juan),se=new Set((e._collections||[]).map(C=>Wi(C.vol).length).filter(C=>C>0)),Re=C=>{var ze;const ge=(ze=e.base_edition)==null?void 0:ze.find(we=>we.book_id===C&&we.name);if(ge!=null&&ge.name)return ge.name;const V=v.get(C);return(V==null?void 0:V.edition)||(V==null?void 0:V.title)||""},H=b.useMemo(()=>{var it,yt;const C=[];xe&&C.push({label:u("bookPage.fact.editionType"),value:f(xe),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(it=e.publication_info)!=null&&it.details?C.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(Ce.era||Ce.reign)&&C.push({label:u("bookPage.fact.era"),value:f([Ce.era,Ce.reign].filter(Boolean).join(" ")),title:Ce.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),fe&&C.push({label:u("bookPage.fact.measure"),value:f(fe)});const ge=(e._collections||[]).flatMap(De=>Wi(De.vol));ge.length&&C.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Un(ge,h.unit.volume),unit:h.unit.volume,n:ge.length})});const V=Gt(e).find(De=>De.relation==="底本"&&De.ref_type==="book");V&&Re(V.ref)&&C.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(wt,{id:V.ref,label:f(Re(V.ref)),onNavigate:n,renderLink:s,dense:!0})});const ze=(e.base_edition||[]).filter(De=>De&&De.name);for(const De of["底本","配補","參校"]){if(De==="底本"&&V&&Re(V.ref))continue;const J=ze.filter(ve=>ve.role===De);J.length&&C.push({label:f(De),value:J.map((ve,Qe)=>t.jsxs(b.Fragment,{children:[Qe>0&&"、",ve.book_id?t.jsx(wt,{id:ve.book_id,label:f(ve.name),onNavigate:n,renderLink:s,dense:!0}):f(ve.name)]},Qe))})}const we=(e.provenance||[]).filter(De=>De&&De.institution),Te=(e.resources||[]).filter(De=>r.getResourceTypes(De).includes("physical"));if(we.length){C.push({label:u("bookPage.fact.holdings"),value:we.slice(0,2).map(ve=>f(ve.institution)).join("、")+(we.length>2?u("bookPage.andMorePlaces",{n:we.length}):"")});const De=we.filter(ve=>ve.call_number).slice(0,2).map(ve=>`${f(ve.institution)} ${ve.call_number}`);De.length&&C.push({label:u("bookPage.fact.callNumber"),value:De.join(";")+(we.filter(ve=>ve.call_number).length>2?"…":"")});const J=we.flatMap(ve=>ve.seals||[]).filter(Boolean);J.length&&C.push({label:u("bookPage.fact.seals"),value:f(J.join("、"))})}else Te.length&&C.push({label:u("bookPage.fact.holdings"),value:Te.slice(0,2).map(De=>f(De.name)).join("、")+(Te.length>2?u("bookPage.andMorePlaces",{n:Te.length}):"")});const tt=e.physical_description;if(tt){const De=[[u("bookPage.fact.leafStyle"),tt.leaf_style],[u("bookPage.fact.binding"),tt.binding],[u("bookPage.fact.dimensions"),tt.dimensions],[u("bookPage.fact.condition"),tt.condition]];for(const[J,ve]of De)ve&&ve.trim()&&C.push({label:J,value:f(ve)})}(yt=e.page_count)!=null&&yt.description&&C.push({label:h.label.pageCount,value:f(e.page_count.description)});const Pe=_c(e.additional_titles);return Pe.length&&C.push({label:u("bookPage.fact.aliases"),value:Pe.map(f).join("、")}),C},[e,f,h,u,Ce,xe,fe,v,n,s]),me=f(e.title),W=e.edition?f(e.edition):void 0,K=((Fe=e.dating)==null?void 0:Fe.text)||"",re=t.jsx(Qi,{kind:u("bookPage.kind"),title:me,subtitle:W,byline:t.jsx(no,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:s}),meta:(()=>{const C=[xe?f(xe):"",Ce.era?f([Ce.era,Ce.reign].filter(Boolean).join("")):"",fe?f(fe):""].filter(Boolean);return C.length?t.jsx("span",{className:"bim-d-tags",children:C.map((ge,V)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(V,2)}`,children:ge},V))}):null})(),description:(Xe=e.description)!=null&&Xe.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Es((Be=e.description)==null?void 0:Be.text)?6:void 0,facts:H,readAction:o,secondaryAction:o&&le>0&&!ae?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),Y=e._collections||[],T=(a==null?void 0:a.chapters)||[],ue=f(T[0]&&Br(T[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),ye=u("bookPage.chapterCount",{n:T.length,unit:ue}),Ne=!!(Gt(e).length||mi(e).length||(Ke=e.appendix)!=null&&Ke.length),B=[],de=u(ae?"bookPage.sec.physical":"bookPage.sec.images");(T.length||P.text.length||l)&&B.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:T.length?ye:void 0}),P.groups.length&&B.push({id:"images",label:de,count:le}),Ne&&B.push({id:"lineage",label:u("bookPage.sec.lineage")}),Y.length&&B.push({id:"collections",label:u("section.containedIn"),count:Y.length}),(Ye=e.location_history)!=null&&Ye.length&&B.push({id:"provenance",label:u("section.locationHistory")});const Me=C=>(d==null?void 0:d(C))??null,Se=T[0],Je=Se?Me(Se.file):null,X=_?T:T.slice(0,Fx),je=(C,ge,V)=>C?t.jsx("a",{className:V,href:C.href??"#",onClick:C.onClick?ze=>{ze.metaKey||ze.ctrlKey||(ze.preventDefault(),C.onClick())}:void 0,children:ge}):t.jsx("span",{className:V,children:ge}),L=t.jsxs(t.Fragment,{children:[(T.length>0||P.text.length>0||l)&&t.jsxs(_t,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:T.length>0?t.jsx(vt,{items:[ye,(w=a==null?void 0:a.source)!=null&&w.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!Se&&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"})]}),Se&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Br(Se.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((Se.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),je(Je,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),T.length>1&&t.jsx("ul",{className:"bim-d-chap",children:X.map(C=>{const[ge,V]=Br(C.title);return t.jsx("li",{children:je(Me(C.file),t.jsxs(t.Fragment,{children:[ge&&t.jsx("b",{children:f(ge)}),f(V||C.file)]}))},C.file)})}),T.length>X.length&&t.jsx(Cs,{label:u("detail.expandRest",{n:T.length-X.length,unit:ue}),onClick:()=>N(!0)}),P.text.length>0&&t.jsxs(t.Fragment,{children:[(T.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:P.text.map((C,ge)=>t.jsx(ro,{item:C,siblings:P.text,listedVolumeCounts:se},`${C.id||C.url||C.name}-${ge}`))})})]})]}),P.groups.length>0&&t.jsx(_t,{id:"images",title:de,meta:t.jsx(vt,{items:[P.groups.length>1?u("bookPage.groupCount",{n:P.groups.length}):"",u("bookPage.placeCount",{n:le})]}),children:t.jsx(jd,{groups:P.groups,listedVolumeCounts:se})}),Ne&&t.jsx(_t,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Gt(e).length?u("bookPage.lineageMeta"):void 0,action:E?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":I==="flow",onClick:()=>D("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":I==="graph",onClick:()=>D("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:I==="graph"&&E?t.jsx(so,{graph:E,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(C,ge)=>t.jsx(wt,{id:C,label:f(ge),onNavigate:n,renderLink:s,dense:!0})}):t.jsx(Dx,{data:e,heading:W||me,yearText:K,refName:Re,onNavigate:n,renderLink:s})}),Y.length>0&&t.jsx(_t,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Y.map((C,ge)=>{const V=C.id,ze=Wi(C.vol),we=S.get(V),Te=Ou(we);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:V,label:we?f(we.title):V,onNavigate:n,renderLink:s,dense:!0}),ze.length>0&&t.jsx(Hx,{volumes:ze,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Te?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Te>0&&u("bookPage.totalOf",{n:Te,unit:h.unit.bu})})]},`${V}-${ge}`)})})})}),(ee=e.location_history)!=null&&ee.length?t.jsx(_t,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((C,ge)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(C.name||C.location||"")}),([C.start_date,C.end_date].filter(Boolean).join("—")||C.description||C.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[C.start_date,C.end_date].filter(Boolean).join("—"),C.description?f(C.description):"",C.note?f(C.note):""]})})]},ge))})}):null,B.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")})})]}),G=x.findIndex(C=>C.id===e.id),ie=O.length<=al,te=ie&&G>=0?x.slice(Math.max(0,G-ll),G+ll+1):x.filter(C=>C.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(C=>`${C.dynasty?`〔${f(C.dynasty)}〕`:""}${f(C.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}):""]}),((Le=g.description)==null?void 0:Le.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&&te.length>0&&t.jsxs("div",{children:[t.jsx(di,{id:"siblings",timeline:!0,title:ie?u("bookPage.siblings"):h.relation.siblingVersions,meta:ie?u("bookPage.byEra"):u("bookPage.kindCount",{n:M}),cap:te.length,items:te.map(C=>C.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(C.edition||C.title||C.id)}):t.jsx(wt,{id:C.id,label:f(C.edition||C.title||C.id),onNavigate:n,renderLink:s,dense:!0})),metas:te.map(C=>[C.year!=null?C.year<0?u("detail.bce",{n:-C.year}):String(C.year):"",C.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:te.findIndex(C=>C.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:O.length}),onNavigate:n,renderLink:s,dense:!0})})]})]}),be=e.work_id?t.jsx(pc,{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(Zi,{railTop:c,back:m,up:be,nav:B,railLinks:p,main:L,card:re,side:ce})};function Hx({volumes:e,unit:i}){const{t:n}=oe();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Un(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 Dx({data:e,heading:i,yearText:n,refName:s,onNavigate:o,renderLink:a}){var k;const{t:l,convert:d}=oe(),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&&Bx.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",S=(x,j)=>t.jsx(wt,{id:x,label:d(j||x),onNavigate:o,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[p.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:x.relation?d(x.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),x.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(x.evidence),y(x.confidence)]})]})},`a-${j}`)),h.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:i}),n&&t.jsx("span",{className:"bim-d-lf-yr",children:d(n)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((x,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:S(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},j))})]}),f.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((x,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[S(x.book_id,s(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},j))})]})]}),(k=e.appendix)==null?void 0:k.map((x,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(x.title)]}),t.jsx(zi,{text:x.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Oi=16,Wx=200,Ux=16,$d=({data:e,catalog:i,transport:n,onNavigate:s,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var ie,te,ce,be,Fe,Xe,Be,Ke,Ye;const{t:m,convert:p,messages:h}=oe(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[S,k]=b.useState(null),[x,j]=b.useState(""),[v,$]=b.useState(!1),_=b.useMemo(()=>Al(e,i),[e,i]),N=b.useMemo(()=>Ml(e),[e]),[I,D]=b.useState(new Map),E=!!n&&_.rows.length>0&&_.rows.length<=Wx,R=E&&(_.rows.length<=Oi||v),O=R&&_.rows.every(w=>!w.id||I.has(w.id)),M=w=>{var ee;return cs(w?(ee=I.get(w))==null?void 0:ee.l1:void 0)},q=b.useMemo(()=>{const w=u.trim(),ee=w?p(w):"";return _.rows.filter(Z=>{var Le,C;if(x&&cs(Z.id?(Le=I.get(Z.id))==null?void 0:Le.l1:void 0)!==x)return!1;if(!ee)return!0;const he=Z.id&&((C=I.get(Z.id))==null?void 0:C.title)||Z.title;return p(he).includes(ee)||(Z.subItems||[]).some(ge=>p(ge).includes(ee))})},[_.rows,u,x,I,p]),P=g?q:q.slice(0,Oi),le=b.useMemo(()=>(R?_.rows:P).filter(w=>w.id&&!I.has(w.id)).map(w=>w.id),[R,_.rows,P,I]);b.useEffect(()=>{if(!n||le.length===0)return;let w=!1;const ee=le.slice(0,Ux);return er(ee,Qn,Z=>n.getItem(Z).then(he=>{var ge,V;const Le=he??{},C={title:Le.title,edition:Le.edition,authors:Le.authors,measure:he?qt(he,h.unit.juan):void 0,versionCount:Le._edition_count??((ge=Le._books)==null?void 0:ge.length),l1:((V=ks(Le))==null?void 0:V.l1)||void 0};return[Z,C]}).catch(()=>[Z,{}]),()=>w).then(Z=>{w||D(he=>{const Le=new Map(he);for(const[C,ge]of Z)Le.set(C,ge);return Le})}),()=>{w=!0}},[n,le,h.unit.juan]);const ae=(ie=(e.contained_in||[])[0])==null?void 0:ie.id;b.useEffect(()=>{if(!ae){k(null);return}if(k({id:ae}),!n)return;let w=!1;return n.getItem(ae).then(ee=>{w||k({id:ae,title:ee==null?void 0:ee.title})}).catch(()=>{}),()=>{w=!0}},[n,ae]);const Ce=b.useMemo(()=>xd(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),xe=Ce.text.length+Ce.groups.reduce((w,ee)=>w+ee.rows.length+ee.mirrors.length,0),fe=N.works,se=new Set(_.rows.map(w=>w.id).filter(Boolean)),Re=fe.length>0&&!fe.every(w=>se.has(w.id)),H=(()=>{const w=_.rows.map(ee=>ee.edition).filter(Boolean);return w.length>1&&new Set(w).size===1})(),me=_.rows.some(w=>w.volumes.length>0||w.expected!=null),W=N.total,K=N.truncated?W:_.rows.length,re=qt(e,h.unit.juan),Y=e.count,T=w=>typeof w=="number"&&Number.isFinite(w)?w:null,ue=T(Y==null?void 0:Y.juan)??T((te=e.juan_count)==null?void 0:te.number)??T((be=(ce=e.measures)==null?void 0:ce.find(w=>(w==null?void 0:w.unit)==="卷"))==null?void 0:be.number),ye=T(Y==null?void 0:Y.ce)??(_.totalVolumes||null),Ne=[{value:K,label:m("collectionPage.stat.titles")},{value:ue??0,label:h.unit.juan},{value:ye??0,label:h.unit.volume}],B=b.useMemo(()=>{var Z,he;const w=[];if((Z=e.publication_info)!=null&&Z.details&&w.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),W&&(W!==_.rows.length||N.truncated)){const Le=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");w.push({label:Le,value:`${W} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const ee=[T(Y==null?void 0:Y.zhong)!=null?m("collectionPage.nZhong",{n:Y.zhong}):"",T(Y==null?void 0:Y.han)!=null?m("collectionPage.nHan",{n:Y.han}):""].filter(Boolean);return ee.length&&w.push({label:m("collectionPage.fact.expected"),value:ee.join(" ")}),ue==null&&re&&w.push({label:m("collectionPage.fact.measure"),value:p(re),title:(he=e.juan_count)!=null&&he.description?p(e.juan_count.description):void 0}),w},[e,W,N.truncated,_.rows.length,ue,re,Y,p,m,h]),de=b.useMemo(()=>{if(!O)return[];const w=new Map;for(const Z of _.rows){const he=M(Z.id);he&&w.set(he,(w.get(he)??0)+1)}const ee=Yi.filter(Z=>(w.get(Z.key)??0)>0);return ee.length<2?[]:[{key:"",label:`${h.catalog.all} ${K}`},...ee.map(Z=>({key:Z.key,label:`${Z.label} ${w.get(Z.key)}`}))]},[O,_.rows,I,h]),Me=b.useMemo(()=>{if(!O||!_.rows.some(he=>he.volumes.length>0))return null;const w=[],ee=_.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,Le)=>he.from-Le.from);for(const he of ee){const Le=he.to-he.from+1,C=w[w.length-1];C&&C.key===he.k?(C.to=Math.max(C.to,he.to),C.n+=Le):w.push({key:he.k,from:he.from,to:he.to,n:Le})}const Z=ee.reduce((he,Le)=>Math.max(he,Le.to),0);return w.length>1&&w.some(he=>he.key)?{segs:w,last:Z}:null},[O,_.rows,I]),Se=(Fe=e.description)==null?void 0:Fe.text,Je=t.jsx(Qi,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(no,{authors:e.authors,onNavigate:s,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(Xe=e.publication_info)!=null&&Xe.year?p(e.publication_info.year):""]}),description:Se||(Be=e.history)!=null&&Be.length?t.jsxs(t.Fragment,{children:[Se&&t.jsx(zi,{text:Se,style:{fontSize:15,lineHeight:1.85}}),(Ke=e.history)!=null&&Ke.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((w,ee)=>t.jsx("li",{children:p(w)},ee))}):null]}):void 0,clampDescription:Es(Se)||(((Ye=e.history)==null?void 0:Ye.length)??0)>2?6:void 0,stats:Ne,facts:B,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:Me&&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:Me.segs.map((w,ee)=>{const Z=Yi.find(he=>he.key===w.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:w.from,to:w.to}):void 0,"aria-label":Z?m("collectionPage.dist.only",{section:p(Z.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!Z&&x===w.key,style:{flexGrow:w.n,background:Z?r.bim(Z.token):r.bim("rule")},onClick:()=>{Z&&(j(x===w.key?"":w.key),y(!1))}},ee)})}),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:Me.last})})]})]})}),X=[];_.rows.length&&X.push({id:"titles",label:m("collectionPage.sec.titles"),count:K}),xe&&X.push({id:"resources",label:m("collectionPage.sec.resources"),count:xe}),Re&&X.push({id:"works",label:h.section.containedWorks,count:fe.length});const je=t.jsxs(t.Fragment,{children:[_.rows.length>0&&t.jsxs(_t,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${K} ${h.unit.items}`,_.totalVolumes?m("collectionPage.totalVolumes",{n:_.totalVolumes,unit:h.unit.volume}):"",q.length!==K?m("collectionPage.currentN",{n:q.length,unit:h.unit.items}):""]}),action:a,children:[(_.rows.length>Oi||de.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[de.length>0&&t.jsx(qn,{items:de,value:x,onChange:w=>{j(w),y(!1)}}),E&&_.rows.length>Oi&&!O&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:v,onClick:()=>$(!0),title:m("collectionPage.loadAllTitle",{n:_.rows.length,unit:h.unit.items}),children:m(v?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),_.rows.length>Oi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:w=>{f(w.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&Xn(q.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:P.map((w,ee)=>{var ze;const Z=w.id?I.get(w.id):void 0,he=Z!=null&&Z.title&&w.title===w.id?Z.title:w.title,Le=((Z==null?void 0:Z.authors)||[]).find(we=>we&&we.name),C=[Le?`${Le.dynasty?`〔${p(Le.dynasty)}〕`:""}${p(Le.name)}${Le.role?` ${p(Le.role)}`:""}`:"",Z!=null&&Z.measure?p(Z.measure):"",(ze=w.subItems)!=null&&ze.length?w.subItems.map(we=>p(we)).join("、"):"",(Z!=null&&Z.edition||w.edition)&&!H?p((Z==null?void 0:Z.edition)||w.edition||""):""].filter(Boolean),ge=Yi.find(we=>we.key===M(w.id)),V=w.volumes.length>0?m("collectionPage.volumeRange",{range:Un(w.volumes,h.unit.volume),unit:h.unit.volume}):w.expected!=null?`${w.found??0}/${w.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:[ge&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r.bim(ge.token)}}),V||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[w.id?t.jsx(wt,{id:w.id,label:p(he),onNavigate:s,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(he)}),C.length>0?t.jsx(vt,{items:C}):w.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}):""})]},`${w.id??w.title}-${ee}`)})})]}),P.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:m("catalog.noMatch")}),!g&&t.jsx(zs,{total:q.length,shown:P.length,unit:h.unit.items,onClick:()=>y(!0)})]}),xe>0&&t.jsxs(_t,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:xe}),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((w,ee)=>t.jsx(ro,{item:w,siblings:Ce.text},`${w.id||w.url||w.name}-${ee}`))})})]}),t.jsx(jd,{groups:Ce.groups})]}),_.rows.length===0&&xe===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")})})]}),L=Re?t.jsx(di,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:fe.length}),cap:12,items:fe.map(w=>t.jsx(wt,{id:w.id,label:p(w.title),onNavigate:s,renderLink:o,dense:!0}))}):null,G=S?t.jsx(pc,{caption:m("collectionPage.parent"),children:t.jsx(wt,{id:S.id,label:p(S.title||S.id),onNavigate:s,renderLink:o,dense:!0})}):void 0;return t.jsx(Zi,{railTop:l,back:d,up:G,nav:X,railLinks:c,main:je,card:Je,side:L})},Kx=8;function _d(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function Yx(e){return(e||[]).filter(i=>{var n,s;return _d(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((s=i.license)==null?void 0:s.trim())}).slice(0,Kx)}function Vx({images:e,assetBase:i,name:n}){const{t:s,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?Yx(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+_d(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 cl=8,dl=10,ml=30,Nd=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function Gx(e){return`${Nd(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function qx(e,i,n){var s;return`${Nd(i,n.key,n.chapter)}#e=${((s=n.ids)!=null&&s.length?n.ids:[e]).join(",")}`}const Xx=({id:e,transport:i,renderLink:n,onTotal:s})=>{const{t:o,convert:a}=oe(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(cl),[u,f]=b.useState(dl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),S=b.useRef(s);if(S.current=s,b.useEffect(()=>{if(d(null),m("idle"),h(cl),f(dl),!y)return;const $=g.current;let _=!1;const N=()=>{m("loading"),i.getMentions(e).then(D=>{var R,O;if(_)return;const E=D&&"books"in D?D:null;if(!E||!E.total){m("none"),(R=S.current)==null||R.call(S,0);return}d(E),m("ok"),(O=S.current)==null||O.call(S,E.total)}).catch(()=>{_||m("none")})};if(!$||typeof IntersectionObserver>"u")return N(),()=>{_=!0};const I=new IntersectionObserver(D=>{D.some(E=>E.isIntersecting)&&(I.disconnect(),N())},{rootMargin:"400px"});return I.observe($),()=>{_=!0,I.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const k=($,_,N)=>n?n($,_,N):t.jsx("a",{className:N,href:$,children:_}),x=new Map(((l==null?void 0:l.books)??[]).map($=>[$.item,$.title])),j=(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&&j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.examples")}),t.jsx("ol",{className:"bim-d-mentions",children:j.slice(0,p).map(($,_)=>{const N=[x.get($.item),$.heading].filter(Boolean).map(D=>a(D)).join(" · "),I=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-mention-where bim-d-ui",children:N||$.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:k(Gx($),I,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${_}`)})}),j.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(j.length),children:o("mentions.more",{n:j.length-p})})]}),l&&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(Jx,{entityId:e,book:$,open:v.length===1,transport:i,link:k},$.item))}),v.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+ml),children:o("mentions.moreBooks",{n:Math.min(ml,v.length-u)})})]})]})})},Jx=({entityId:e,book:i,open:n,transport:s,link:o})=>{const{t:a,convert:l}=oe(),[d,c]=b.useState(i.chapters??null),[m,p]=b.useState(!1);b.useEffect(()=>{c(i.chapters??null)},[i]);const h=u=>{!u.currentTarget.open||d||m||!(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(qx(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}`))})]})})},Zx=16,Hr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function ul(e){if(!e)return Hr.length;const i=Hr.indexOf(e);return i===-1?Hr.length:i}function Qx(e,i,n){if(i)return e[i]??n(i)}function e0(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const t0={秦:[-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]},zd=({data:e,transport:i,onNavigate:n,renderLink:s,railTop:o,back:a,railLinks:l,assetBase:d})=>{var be,Fe,Xe,Be,Ke,Ye;const{t:c,convert:m,messages:p}=oe(),h=w=>e0(w,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[S,k]=b.useState("default"),[x,j]=b.useState(new Map),[v,$]=b.useState(0),_=b.useMemo(()=>e._works||[],[e._works]),N=b.useMemo(()=>_.map(w=>{const ee=x.get(w.work_id);return{id:w.work_id,title:(ee==null?void 0:ee.title)??w.title??w.work_id,role:w.role||"",cls:xs(w.role),versionCount:ee==null?void 0:ee.versionCount,section:ee==null?void 0:ee.cls,l1:ee==null?void 0:ee.l1,measure:ee==null?void 0:ee.measure,hasImage:ee==null?void 0:ee.hasImage,loaded:!!(ee!=null&&ee.loaded)}}),[_,x]),I=b.useMemo(()=>Il(_.map(w=>w.role),c("detail.roleAll")),[_,c]),D=b.useMemo(()=>{const w=u==="全部"?N:N.filter(ee=>ee.cls===u);return S==="versions"?[...w].sort((ee,Z)=>(Z.versionCount??-1)-(ee.versionCount??-1)):w},[N,u,S]),E=g?D:D.slice(0,Zx),R=b.useMemo(()=>E.filter(w=>!x.has(w.id)).map(w=>w.id),[E,x]);b.useEffect(()=>{if(!i||R.length===0)return;let w=!1;return er(R,Qn,ee=>i.getItem(ee).then(Z=>{var V;const he=Z??{},Le=he._edition_count??((V=he._books)==null?void 0:V.length)??0,C=ks(he),ge=[C==null?void 0:C.l1,C==null?void 0:C.l2].filter(Boolean).join(" ");return[ee,{id:ee,title:he.title,versionCount:Le,loaded:!0,cls:ge||void 0,l1:(C==null?void 0:C.l1)||void 0,measure:Z&&qt(Z,p.unit.juan)||void 0,hasImage:!!he._has_image}]}).catch(()=>[ee,{id:ee,loaded:!0}]),()=>w).then(ee=>{w||j(Z=>{const he=new Map(Z);for(const[Le,C]of ee)he.set(Le,C);return he})}),()=>{w=!0}},[i,R,p.unit.juan]);const O=b.useMemo(()=>{const w=new Map;for(const ee of e.alt_names||[]){const Z=ee.type||p.section.aliases;w.has(Z)||w.set(Z,[]),w.get(Z).push(ee.name)}return[...w.entries()].sort((ee,Z)=>ul(ee[0])-ul(Z[0])).map(([ee,Z])=>({label:ee,names:Z}))},[e.alt_names,p]),M=((be=e.dates)==null?void 0:be.birth)??void 0,q=((Fe=e.dates)==null?void 0:Fe.death)??void 0,P=(Xe=e.dates)==null?void 0:Xe.floruit,le=M!=null||q!=null?`${h(M)||"?"}—${h(q)||"?"}`:Array.isArray(P)&&P.length===2&&P.every(w=>Number.isFinite(w))?c("entityPage.floruit",{from:h(P[0]),to:h(P[1])}):"",ae=new Set(["本名","字","號","号"]),Ce=O.filter(w=>ae.has(w.label)),xe=O.filter(w=>!ae.has(w.label)),fe=xe.reduce((w,ee)=>w+ee.names.length,0),se=b.useMemo(()=>{const w=[];for(const Z of Ce)w.push({label:Z.label,value:Z.names.map(he=>m(he)).join("、")});const ee=_.length;return ee&&w.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:ee})}),w},[_,Ce,m,c]),Re=w=>{var ee;return(ee=O.find(Z=>w.includes(Z.label)))==null?void 0:ee.names[0]},H=Re(["字"]),me=Re(["號","号"]),W=[H?c("entityPage.zi",{name:m(H)}):"",me?c("entityPage.hao",{name:m(me)}):""].filter(Boolean).join(","),K=e.native_place,re=e.dynasty?t0[e.dynasty]:void 0,Y=(()=>{if(!re||M==null||q==null||q<M)return null;const[w,ee]=re,Z=Math.max(M,w),he=Math.min(q,ee);if(he<=Z)return null;const Le=ee-w;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-w)/Le*100}%`,width:`${(he-Z)/Le*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${h(w)} ${m(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:q-M+1})}),t.jsx("span",{children:h(ee)})]})]})})(),T=b.useMemo(()=>{if(!i||N.length===0||N.some(Z=>!Z.loaded))return null;const w=new Map;for(const Z of N){const he=cs(Z.l1);he&&w.set(he,(w.get(he)??0)+1)}const ee=Yi.map(Z=>({...Z,n:w.get(Z.key)??0})).filter(Z=>Z.n>0);return ee.length?ee:null},[N,i]),ue=t.jsxs(Qi,{kind:Qx(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:W||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",le,K?c("entityPage.nativePlace",{place:m(K)}):""]}),Y,t.jsx(Vx,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(Be=e.description)!=null&&Be.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Es((Ke=e.description)==null?void 0:Ke.text)?6:void 0,facts:se,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[fe>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:fe})}),t.jsx("dl",{children:xe.map(w=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(w.label)}),t.jsx("dd",{children:w.names.map(ee=>m(ee)).join("、")})]},w.label))})]}),T&&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:T.map(w=>t.jsx("i",{style:{flexGrow:w.n,background:r.bim(w.token)}},w.key))}),t.jsx("div",{className:"bim-d-dist-key",children:T.map(w=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r.bim(w.token)}}),m(w.label)," ",w.n]},w.key))})]})]}),ye=b.useMemo(()=>N.filter(w=>w.loaded&&(w.versionCount??0)>0).sort((w,ee)=>(ee.versionCount??0)-(w.versionCount??0)).slice(0,3),[N]),Ne=!!i&&N.length>=3&&E.some(w=>!w.loaded),B=u==="全部"&&(Ne||ye.length>=2),de=e.external_ids||{},Me=((Ye=e.external_ids_meta)==null?void 0:Ye.cbdb_match)??de.cbdb_match,Se=[];de.cbdb_id!=null&&Se.push({label:"CBDB",id:String(de.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${de.cbdb_id}`,note:Me==="auto"?c("entityPage.autoMatch"):void 0});const Je=de.wikidata_id;Je&&Se.push({label:"Wikidata",id:Je,href:`https://www.wikidata.org/wiki/${Je}`});const X=de.viaf_id;X&&Se.push({label:"VIAF",id:X,href:`https://viaf.org/viaf/${X}`});const je=I.map(w=>({key:w.cls,label:`${w.label} ${w.count}`})),L=e.id?t.jsx(Xx,{id:e.id,transport:i,onTotal:$}):null,G=[...B&&!Ne?[{id:"featured",label:c("entityPage.sec.featured"),count:ye.length}]:[],...N.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:N.length}]:[],...v?[{id:"mentions",label:c("mentions.title"),count:v}]:[],...Se.length?[{id:"external",label:c("entityPage.sec.external"),count:Se.length}]:[]],ie=B?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":Ne||void 0,children:[Ne&&[0,1,2].map(w=>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:" "})]},w)),!Ne&&ye.map(w=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(wt,{id:w.id,label:m(w.title),onNavigate:n,renderLink:s,dense:!0})}),t.jsx(vt,{items:[w.section?m(w.section):"",w.measure?m(w.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:w.versionCount}),t.jsx("span",{children:c("entityPage.versionsUnit")}),w.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},w.id))]})]}):null,te=N.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")})}),L]}):t.jsxs(t.Fragment,{children:[ie,t.jsxs(_t,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:N.length}),D.length!==N.length?c("entityPage.current",{n:D.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[je.length>1&&t.jsx(qn,{items:je,value:u,onChange:w=>{f(w),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":S==="versions",onClick:()=>{S==="default"&&y(!0),k(w=>w==="default"?"versions":"default")},children:c(S==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&Xn(D.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:E.map(w=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:w.id,label:m(w.title),onNavigate:n,renderLink:s,dense:!0}),w.measure?t.jsx(vt,{items:[m(w.measure)]}):!w.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${w.section||w.loaded?"":" bim-d-zt-blank"}`,children:w.section?m(w.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w.role?"":" bim-d-zt-blank"}`,children:w.role?m(w.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w.loaded?"":" bim-d-zt-blank"}`,children:w.loaded?w.versionCount?c("entityPage.nZhong",{n:w.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("entityPage.notRecorded")}):""}),t.jsx("td",{className:w.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:w.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("entityPage.hasImage")})})]},w.id))})]}),E.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx(zs,{total:D.length,shown:E.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),L]}),ce=Se.length>0?t.jsx(di,{id:"external",title:c("entityPage.sec.external"),items:Se.map(w=>t.jsxs("a",{href:w.href,target:"_blank",rel:"noopener noreferrer",children:[w.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Se.map(w=>w.id),foot:de.cbdb_id!=null&&Me==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Zi,{railTop:o,back:a,nav:G,railLinks:l,main:te,card:ue,side:ce})},oo="(max-width: 719px)",i0=`${oo}, (pointer: coarse)`,Cd=`
|
|
1557
|
+
${ce??""}`,[Ei,fo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)fo({key:Ci,data:A,started:!1});else if(A!==Ei.data&&(fo({key:Ci,data:A,started:!!A}),A)){const z=A.pages??[];(!Ei.started||!z.some(U=>U.page===xt))&&bi(ni(A))}b.useEffect(()=>{Ve(new Set),Ze.set(null)},[ce,B,Ze]);const cr=Ei.key===Ci&&Ei.started,go=!!be&&os(be.headings).length===0,xo=b.useMemo(()=>go&&cr&&A?rd(A.pages,A.punctuations):[],[go,cr,A]),dr=b.useCallback(z=>{const U=os(z.headings);return U.length>0?U:z.file===ce?xo:[]},[ce,xo]),$m=b.useCallback(z=>{if(Ve(new Set(z)),z.length>0){const U=z[0],pe=parseInt(U.split(":")[0],10);isNaN(pe)||bi(pe)}},[]),Dt=b.useMemo(()=>{const z=new Map;for(const U of(A==null?void 0:A.pages)??[])z.set(U.page,U);return z},[A]),Ri=sn(A),Ti=b.useCallback(z=>{var ot;const U=Q.images;if(!U||U.length===0)return;const pe=(ot=Dt.get(z))==null?void 0:ot.seq;return(pe?U.find(dt=>dt.seq===pe):void 0)??U.find(dt=>dt.pageNo===z)??U[z-1]},[Q.images,Dt]),yo=St>1.5,on=b.useCallback((z,U=!1)=>{const pe=Ti(z);return pe?z===Ri||U?pe.hiresUrl??pe.url:pe.url:z===Ri?(A==null?void 0:A.imageUrl)??"":""},[Ti,A,Ri]),_m=b.useMemo(()=>on(xt,yo),[on,xt,yo]),Wt=b.useMemo(()=>[...Dt.keys()].sort((z,U)=>z-U),[Dt]),ri=b.useRef(xt);ri.current=xt;const mr=b.useRef(0),ur=b.useRef({page:null,timer:null}),Nm=b.useCallback(z=>{const U=ur.current;z!==U.page&&(U.timer&&(clearTimeout(U.timer),U.timer=null),U.page=null,!(z===ri.current||Date.now()<mr.current)&&(U.page=z,U.timer=setTimeout(()=>{U.timer=null,U.page=null,!(Date.now()<mr.current||ri.current===z)&&(ri.current=z,bi(z))},og)))},[]);b.useEffect(()=>()=>{ur.current.timer&&clearTimeout(ur.current.timer)},[]);const an=b.useCallback(z=>{var U;ri.current===z||!Dt.has(z)||(mr.current=Date.now()+1e3,ri.current=z,bi(z),(U=Dt.get(z))!=null&&U.columns.some(pe=>pe.chars.length>0)&&lr(pe=>({page:z,nonce:((pe==null?void 0:pe.nonce)??0)+1})))},[Dt]),Ii=b.useCallback(z=>{const U=ri.current,pe=Wt.indexOf(U),ot=Wt[pe<0?0:pe+z];ot===void 0||ot===U||an(ot)},[Wt,an]),jo=b.useCallback(z=>{if(!z.trim().match(/^\d+$/)||Wt.length===0)return null;const pe=parseInt(z.trim(),10),ot=Number.isFinite(pe)?pe:Number.MAX_SAFE_INTEGER;return Wt.reduce((dt,$t)=>Math.abs($t-ot)<Math.abs(dt-ot)?$t:dt,Wt[0])},[Wt]),[pr,br]=b.useState(null),ln=b.useRef(null),zm=b.useCallback(z=>{ln.current=z,br(z)},[]),ko=b.useCallback(()=>{const z=ln.current;if(ln.current=null,br(null),z===null)return;const U=jo(z);U!==null&&an(U)},[jo,an]),hr=Wt.indexOf(xt),Cm=b.useCallback(z=>{if(z.altKey||z.ctrlKey||z.metaKey)return;const U=z.target.tagName;U==="INPUT"||U==="TEXTAREA"||U==="SELECT"||(z.key==="ArrowLeft"||z.key==="PageUp"?(z.preventDefault(),Ii(-1)):(z.key==="ArrowRight"||z.key==="PageDown")&&(z.preventDefault(),Ii(1)))},[Ii]),wo=b.useRef(null);b.useEffect(()=>{if(!A)return;const z=wo.current;if(!(!z||z.offsetWidth===0))for(const U of[1,-1]){const pe=on(xt+U);pe&&is(pe)}},[A,xt,on]);const vo=b.useMemo(()=>{var Fo;if(!A)return null;if(xt===Ri)return A;const z=Dt.get(xt);if(z&&z.width>0&&z.height>0)return{page_id:`p:${xt}`,title:`第${xt}葉`,image_size:[z.width,z.height],total_warped_w:z.width,columns:[{col:1,warped_w:z.width,warped_h:z.height,offset_x:0,strips:[],chars:z.columns.flatMap(mt=>mt.chars).map(mt=>({id:mt.id,char:mt.char,slot:mt.slot,pos:mt.pos,sub:mt.sub,bbox_col:mt.bbox??[0,0,0,0]}))}],...z.columns.some(mt=>mt.kind==="figure"&&mt.figBox)?{figBlocks:z.columns.filter(mt=>mt.kind==="figure"&&mt.figBox).map(mt=>({id:mt.fig,box:mt.figBox}))}:{}};const U=(Fo=A.pages)==null?void 0:Fo.find(mt=>mt.page===xt),[pe,ot]=A.image_size||[2386,3082];if(!(pe>0&&ot>0))return null;const dt=Ti(xt),$t=(dt==null?void 0:dt.width)??pe,kr=(dt==null?void 0:dt.height)??ot,Lo=$t/pe,Po=kr/ot,Oo=new Map;for(const mt of A.columns){const At=(mt.strips||[]).flatMap(pn=>pn.srcQuad.map(bn=>bn[0]));if(At.length===0)continue;const Ut=mt.top_y??0,wr=mt.bottom_y??Ut+mt.warped_h;Oo.set(mt.col,{x0:Math.min(...At),x1:Math.max(...At),top:Ut,slotH:(wr-Ut)/21})}return{page_id:`p:${xt}`,title:`第${xt}葉`,image_size:[$t,kr],total_warped_w:$t,columns:U?U.columns.map(mt=>{const At=Oo.get(mt.col)??{x0:0,x1:0,top:0,slotH:118};return{col:mt.col,warped_w:$t,warped_h:kr,offset_x:0,strips:[],chars:mt.chars.map(Ut=>{const wr=Ut.slot??Ut.pos??0,pn=(At.top+(wr-1)*At.slotH)*Po,bn=(At.x0+At.x1)/2,[Wm,Um]=Ut.sub==="a"?[bn,At.x1]:Ut.sub==="b"?[At.x0,bn]:[At.x0,At.x1];return{...Ut,bbox_col:[Wm*Lo,pn,Um*Lo,pn+At.slotH*Po]}})}}):[]}},[A,xt,Ri,Dt,Ti]),{entryTitle:cn,authors:So}=fg(n,s,m===void 0),[$o,fr]=b.useState("text");b.useEffect(()=>{fr("text")},[ce,B]);const Em=b.useMemo(()=>te?mg(te,Qe,Ka(ye,te),P,Pe,dr):[],[te,Qe,ye,P,Pe,dr]),_o=Sh(),No=b.useRef(null),zo=b.useRef(null),gr=b.useMemo(()=>{const z=[];return A&&z.push({id:"bim:punctuation",settings:{group:"annotate",order:0,render:()=>t.jsx("button",{type:"button",className:`bim-rd-t bim-rd-sp-tg ${Ge?"bim-rd-on":""}`,"aria-pressed":Ge,title:"切换外挂现代断句标点",onClick:()=>kt(U=>!U),children:Ge?"标点":"无标点"})}}),z},[A,Ge]),Rm=b.useMemo(()=>R&&R.length>0?[...gr,...R]:gr,[gr,R]),Tm=b.useMemo(()=>ye&&be&&B?{entryId:n,versionKey:B,chapterKey:be.file,chapter:be,version:ye,transport:s,viewport:_o}:null,[n,B,be,ye,s,_o]),Im=b.useCallback(z=>{ce&&Z(ce,z)},[ce,Z]),si=_h({plugins:Rm,ctx:Tm,prefs:Ee,setPrefs:Ce,t:q,convert:P,pages:A==null?void 0:A.pages,textRootRef:No,shellTextRef:zo,selectedCharIds:st,scrollToAnchor:Im});if(H==="loading")return t.jsx(Wa,{className:O,style:M,title:m??cn,label:q("reader.loading")});if(H==="missing"||!se||!ye)return t.jsx("div",{className:O,style:{...M,...Da},children:q("reader.noText")});if(L==="failed")return t.jsx("div",{className:O,style:{...M,...Da},children:q("reader.tocFailed")});if(!te)return t.jsx(Wa,{className:O,style:M,title:m??cn,label:q("reader.tocLoading")});const hi=Ka(ye,te),Mm=Em,Co=Ye&&ce&&Ye.chapter===ce?eo(ce,Ye.anchor):null,Am=Co&&be&&dr(be).some(z=>z.anchor===Ye.anchor)?Co:ce??null,xr=se.versions.map(z=>({key:z.key,label:_e.textVersionLabel(z),optionLabel:P(_e.textVersionLabel(z)),sourceName:Ya(z)?q("reader.originalSource"):z.source_name?P(z.source_name):void 0,license:z.license??void 0,sourceUrl:z.source_url??void 0,primary:z.key===Ne})),Mt=cg((Ao=te.source)==null?void 0:Ao.upstream),dn=(typeof m=="string"?P(m):m)??(te.title?P(te.title):cn?P(cn):void 0),Eo=ye.edition_label?P(ye.edition_label):void 0,yr=dn?t.jsx("a",{href:xe(n),title:q("reader.viewEntry"),onClick:d?z=>{z.metaKey||z.ctrlKey||(z.preventDefault(),d(n))}:void 0,children:dn}):void 0,Lm=yr&&Eo?t.jsxs(t.Fragment,{children:[yr,t.jsxs("span",{className:"bim-rd-ed",children:["·",Eo]})]}):yr,Pm=So.length>0?P(So.slice(0,2).map(z=>`${z.dynasty?`〔${z.dynasty}〕`:""}${z.name}${` ${z.role||q("reader.defaultRole")}`}`).join("、")):void 0,jr=be?ad(be,hi,P,Pe):void 0,oi=Pe&&!!(C!=null&&C.json),ai=(C==null?void 0:C.json)??null,fi=(C==null?void 0:C.md)??null,Ro=oi&&!J&&Yc(ai.sections),Om=Ro&&!(fi&&Ee.readingMode==="paragraph"&&Mn(fi)),Fm=oi&&Ro?t.jsx(Qh,{juan:ai,view:$o,onView:fr,textHasEntries:Om}):void 0,Bm=!0,mn=fi?fi.replace(/^##\s+[^\n]+\n+/,""):null,un=Ya(ye),Xt=un?q("reader.originalSource"):ye.source_name?P(ye.source_name):void 0,Hm=(typeof p=="string"?P(p):p)??(un?void 0:Xt??P(_e.textVersionLabel(ye))),Dm=(A==null?void 0:A.hasNorm)===!0;return t.jsxs(sc,{className:O,style:M,title:Lm,subtitle:Hm,byline:Pm,current:jr,pagerUnit:hi,rail:Fm,revisedAt:k,backHref:x,backLabel:j,onReportError:v?z=>v({...z,bookTitle:typeof dn=="string"?dn:void 0,entryId:n}):void 0,workLinkToggle:oi&&!J&&!!d&&!!(ai!=null&&ai.sections.some(z=>z.work_id)),toc:Mm,tocCaption:q("reader.tocCaption",{n:te.chapters.length,unit:P(hi)}),tocHeader:Pe&&te.chapters.length>1?t.jsx("input",{type:"search",className:"bim-rd-toc-search",placeholder:J?q("reader.searchChaptersPlaceholder"):q("reader.searchUnitPlaceholder",{unit:P(hi)}),"aria-label":J?q("reader.searchChapters"):q("reader.searchUnit",{unit:P(hi)}),value:it,onChange:z=>yt(z.target.value)}):void 0,activeKey:ce??null,tocActiveKey:Am,onSelect:he,images:Cn(be)&&ne&&!A?null:Q.images,renderImageOverlay:f,imagePanel:A||at?"open":g,imagesLoading:lt,isWarpMode:!!A,showPreserveMargins:!nt,customImagePanel:A&&vo?t.jsxs("div",{ref:wo,className:"bim-fx-panel","data-testid":"facsimile-panel",tabIndex:0,role:"group","aria-label":"底本书影(聚焦后可用 ← → 翻页)",onKeyDown:Cm,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:[st.size>0&&t.jsxs("button",{type:"button",onClick:()=>Ve(new Set),className:"bim-rd-t",style:{fontSize:11,padding:"2px 6px",border:`1px solid ${r.bim("rule")}`,borderRadius:4,cursor:"pointer"},children:["清除选中 (",st.size,")"]}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:2},"data-testid":"facsimile-zoom-tools",children:[t.jsx("button",{type:"button",className:"bim-rd-t","aria-label":"缩小",title:"缩小",disabled:St<=1,onClick:()=>{var z;return(z=ct.current)==null?void 0:z.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 z;return(z=ct.current)==null?void 0:z.zoomBy(1.4)},children:"+"}),t.jsx("button",{type:"button",className:"bim-rd-t",title:"复位(双击书影也可)",disabled:St===1,onClick:()=>{var z;return(z=ct.current)==null?void 0:z.reset()},style:{fontSize:11,padding:"2px 4px"},children:"复位"})]})]})]}),t.jsx(eg,{ref:ct,resetKey:xt,onScaleChange:Ot,style:{flex:1,minHeight:0},children:t.jsx(Sa,{store:Ze,children:z=>{var U;return t.jsx(Ys,{imageUrl:_m,pageData:vo,selectedCharIds:st,hoveredCharId:z,decorations:si.decorations,preserveMargins:Pt,banxinMode:ae.banxinMode,extent:(U=Ti(xt))==null?void 0:U.extent,renderScale:St,selectedFigBlock:F,onFigBlockClick:pe=>ke(pe),onCharClick:pe=>{ke(null),Ve(dt=>{const $t=new Set(dt);return $t.has(pe)?$t.delete(pe):($t.clear(),$t.add(pe)),$t});const ot=document.querySelector(`[data-char-id="${pe}"]`);ot&&ot.scrollIntoView({behavior:"smooth",block:"nearest"})},onCharHover:Ze.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:hr<=0,onClick:()=>Ii(-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(pr??xt).length),value:pr??String(xt),onFocus:z=>z.currentTarget.select(),onChange:z=>zm(z.target.value),onKeyDown:z=>{z.key==="Enter"?(z.preventDefault(),ko()):z.key==="Escape"&&(ln.current=null,br(null)),z.stopPropagation()},onBlur:ko,style:{width:`${Math.max(2,String(pr??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:hr<0||hr>=Wt.length-1,onClick:()=>Ii(1),children:"›"})]})]}):void 0,pluginSettings:si.settings,pluginToolbar:si.toolbar,pluginOverlay:si.overlay,textRootRef:zo,prefs:Ee,onPrefsChange:Ce,versions:xr.length>1?xr:void 0,currentVersionKey:xr.length>1?ye.key:void 0,onVersionChange:Xe,keepChapterOnVersionChange:!0,versionSource:!0,paragraphToggle:Mn(fi),allowVertical:y,origScriptAvailable:Dm,contentLoading:Te,children:[(Te||ne&&!A&&!oi&&mn==null)&&t.jsx(Xl,{}),!Te&&A&&t.jsxs("article",{className:"bim-rd-prose",style:{marginTop:0},ref:No,children:[t.jsxs("header",{style:{marginBottom:16},children:[t.jsx("h1",{className:"bim-rd-h1",children:be!=null&&be.title?P(be.title):jr}),(Xt||ye.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[Xt,ye.license&&t.jsxs(t.Fragment,{children:[Xt&&t.jsx("span",{className:"bim-rd-dot"}),ye.license]})]})]}),t.jsx(Sa,{store:Ze,children:z=>t.jsx(Zs,{pageData:A,pages:A.pages,punctuations:A.punctuations||lg,selectedCharIds:st,hoveredCharId:z,onSelectionChange:$m,figures:A.figures,figUrl:A.figUrl,onFigureBlockClick:({page:U,fig:pe})=>{Ve(new Set),ke(pe),bi(U)},onCharClick:U=>{ke(null),Ve(ot=>{const dt=new Set(ot);return dt.has(U)?dt.delete(U):(dt.clear(),dt.add(U)),dt});const pe=parseInt(U.split(":")[0],10);isNaN(pe)||bi(pe),si.onCellClick(U)},onCharHover:U=>{Ze.set(U),si.onCellHover(U)},decorations:si.decorations,mode:"horizontal",showPunctuation:Ge,entities:rt,entityTransport:s,onEntityNavigate:E,onVisiblePageChange:Nm,convert:P,scrollToPage:zt,scrollToAnchor:Be&&Be.chapter===ce&&cr?Be:null,onVisibleHeadingChange:U=>w(U&&ce?{chapter:ce,anchor:U}:null),pageBreaks:Ee.pageBreaks,pageIndicatorY:Ee.pageIndicatorY,onPageIndicatorYChange:U=>Ce({pageIndicatorY:U}),quoteStyle:Ee.quoteStyle,bookTitleStyle:Ee.bookTitleStyle,showWorks:Ee.showWorks})})]}),!Te&&!A&&oi&&ai&&t.jsx(Jh,{juan:ai,rawText:fi,positionLabel:bg(be,te,hi,P),groupLabel:hg(te,ce??null),index:dg(n,te),searchQuery:it,onNavigate:d,transport:s,workLabelCache:et,prefs:Ee,view:$o,onViewChange:fr},`${B}/${ce}`),!Te&&!A&&!oi&&mn!=null&&be&&t.jsxs(t.Fragment,{children:[t.jsxs("header",{children:[t.jsx("h1",{className:"bim-rd-h1",children:be.title?P(be.title):jr}),(Xt||ye.license)&&t.jsxs("p",{className:"bim-rd-meta bim-rd-meta-src",children:[un&&Xt&&t.jsx(t.Fragment,{children:Xt}),!un&&ye.source_name&&t.jsxs(t.Fragment,{children:[q("reader.textSource")," ",ye.source_url?t.jsx("a",{className:"bim-rd-link",href:ye.source_url,target:"_blank",rel:"noreferrer",children:P(ye.source_name)}):P(ye.source_name)]}),Xt&&ye.license&&t.jsx("span",{className:"bim-rd-dot"}),ye.license]}),Mt&&t.jsxs("p",{className:"bim-rd-meta","data-bim-upstream":"",children:[q("reader.upstream")," ",Mt.url?t.jsx("a",{className:"bim-rd-link",href:Mt.url,target:"_blank",rel:"noreferrer",children:P(Mt.name??Mt.url)}):P(Mt.name??""),Mt.license&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),Mt.license_url?t.jsx("a",{className:"bim-rd-link",href:Mt.license_url,target:"_blank",rel:"noreferrer",children:Mt.license}):Mt.license]}),Mt.note&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-rd-dot"}),t.jsx(Jl,{text:Mt.note,convert:P})]})]})]}),t.jsx("article",{className:"bim-rd-prose",children:t.jsx(Os,{text:mn,mode:Ee.readingMode,tables:Bm,gujiMarkdown:!0,bookMarking:Ps(Ee),quoteStyle:Ee.quoteStyle})})]}),!Te&&!ne&&!A&&!oi&&mn==null&&be&&t.jsx("div",{className:"bim-rd-state",children:q("reader.chapterFailed")}),!Te&&te.references&&te.references.length>0&&t.jsxs("section",{className:"bim-rd-refs",children:[t.jsx("h2",{children:q("reader.references")}),t.jsx("ol",{children:te.references.map((z,U)=>t.jsxs("li",{children:[z.url?t.jsx("a",{className:"bim-rd-link",href:z.url,target:"_blank",rel:"noopener noreferrer",children:P(z.title)}):t.jsx("span",{children:P(z.title)}),z.author&&t.jsxs("span",{children:[",",P(z.author)]}),z.note&&t.jsxs("span",{children:["。",P(z.note)]})]},U))})]})]})};function Ya(e){return e.is_original===!0||e.source==="original"}function bg(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 hg(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 fg(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 gg=({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),v=b.useRef(null),k=b.useCallback($=>{m(new Set($))},[]),x=b.useCallback($=>{if(m(_=>{const N=new Set(_);return N.has($)?N.delete($):(N.clear(),N.add($)),N}),v.current){const _=v.current.querySelector(`[data-char-id="${$}"]`);_&&_.scrollIntoView({behavior:"smooth",block:"nearest"})}},[]),j=()=>{var $;m(new Set),window.getSelection&&(($=window.getSelection())==null||$.removeAllRanges())},S=n.length>0?n:e.punctuations||[];return t.jsxs("div",{className:`guji-reader-container ${l}`,style:d,children:[t.jsxs("header",{className:"guji-reader-header",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[a&&t.jsx("button",{type:"button",onClick:a,className:"guji-reader-btn",style:{marginRight:6},children:"‹ 返回"}),t.jsx("span",{className:"guji-reader-title",children: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:j,className:"guji-reader-btn",children:"清除选中"}),t.jsx("button",{type:"button",onClick:()=>y($=>!$),className:`guji-reader-btn ${g?"active":""}`,title:"独立外挂标点 (guji-punct v0.1)",children:g?"✓ 标点":"底本文本"}),t.jsx("button",{type:"button",onClick:()=>f($=>$==="horizontal"?"vertical":"horizontal"),className:"guji-reader-btn primary",children:u==="horizontal"?"切换竖排":"切换横排"})]})]}),t.jsxs("div",{className:"guji-reader-body",children:[t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%",position:"sticky",top:0},children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:"底本书影 (WebGL 分带透视矫正 + 完整版心)"}),t.jsx("span",{className:"guji-pane-hint",children:"点击字框可联动文本定位"})]}),t.jsx("div",{className:"guji-pane-content",children:t.jsx(Ys,{imageUrl:i,pageData:e,selectedCharIds:c,hoveredCharId:p,onCharClick:x,onCharHover:h})})]}),t.jsxs("div",{className:"guji-pane-card",style:{flex:"1 1 50%"},ref:v,children:[t.jsxs("div",{className:"guji-pane-header",children:[t.jsx("span",{className:"guji-pane-title",children:u==="horizontal"?"排版文本 (横排分段 · 外挂断句标点)":"排版文本 (原刻竖排逐列)"}),t.jsx("span",{className:"guji-pane-hint",children:"支持鼠标跨标点整句划词高亮"})]}),t.jsx(Zs,{pageData:e,punctuations:S,selectedCharIds:c,hoveredCharId:p,onSelectionChange:k,onCharClick:x,onCharHover:h,mode:u,showPunctuation:g})]})]})]})},xg=({data:e,onNavigate:i,className:n,style:s})=>{var p;const{t:o,convert:a}=oe(),[l,d]=b.useState(((p=e.divisions[0])==null?void 0:p.name)??null),[c,m]=b.useState(null);return t.jsxs("div",{className:n,style: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(yg,{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))})]})},yg=({division:e,expanded:i,onToggle:n,expandedCat:s,onCatToggle:o,onNavigate:a})=>{const{t:l,convert:d}=oe(),c=e.categories.reduce((m,p)=>{const h=p.stats||{zhulu:0,cunmu:0};return m+(h.zhulu||0)+(h.cunmu||0)},0);return t.jsxs("div",{style:{border:`1px solid ${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(jg,{category:m,expanded:s===p,onToggle:()=>o(p),onNavigate:a},m.name)})})]})},jg=({category:e,expanded:i,onToggle:n,onNavigate:s})=>{var m,p,h,u;const{t:o,convert:a}=oe(),l=((m=e.books)==null?void 0:m.zhulu)||[],d=((p=e.books)==null?void 0:p.cunmu)||[],c=(((h=e.stats)==null?void 0:h.zhulu)||l.length)+(((u=e.stats)==null?void 0:u.cunmu)||d.length);return t.jsxs("div",{children:[t.jsxs("button",{onClick:n,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:i?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(Va,{label:o("catalogPage.zhulu"),books:l,onNavigate:s}),d.length>0&&t.jsx(Va,{label:o("catalogPage.cunmu"),books:d,onNavigate:s})]})]})},Va=({label:e,books:i,onNavigate:n})=>{const{t:s,convert:o}=oe(),a=It(),[l,d]=b.useState(i.length<=20),c=l?i:i.slice(0,10);return t.jsxs("div",{style:{marginBottom:"8px"},children:[t.jsxs("div",{style:{fontSize:"11px",color: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 to(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 dd(e){return e&&typeof e.listFeedback=="function"&&typeof e.submitFeedback=="function"?e:null}const kg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],md=({isOpen:e,onClose:i,onSubmit:n,feedbackListUrl:s})=>{const{t:o}=oe(),[a,l]=b.useState(null),[d,c]=b.useState(""),[m,p]=b.useState(""),[h,u]=b.useState("idle"),[f,g]=b.useState(""),y=b.useRef(null);b.useEffect(()=>{e&&(l(null),c(""),p(""),u("idle"),g(""))},[e]),b.useEffect(()=>{a&&setTimeout(()=>{var x;return(x=y.current)==null?void 0:x.focus()},100)},[a]),b.useEffect(()=>{if(h==="success"){const x=setTimeout(i,2e3);return()=>clearTimeout(x)}},[h,i]),b.useEffect(()=>{if(!e)return;const x=j=>{j.key==="Escape"&&i()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[e,i]);const v=async()=>{if(!(!a||!d.trim())){u("submitting"),g("");try{await n({type:a,content:d.trim(),...m.trim()?{contact:m.trim()}:{}}),u("success")}catch(x){u("error"),g(x instanceof Error?x.message:o("feedback.submitFailedRetry"))}}};if(!e)return null;const k=a&&d.trim()&&h!=="submitting";return t.jsx("div",{style:wg,onClick:x=>{x.target===x.currentTarget&&i()},children:t.jsxs("div",{style:vg,onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{style:Sg,children:[t.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:o("feedback.title")}),t.jsx("button",{onClick:i,style:$g,"aria-label":o("feedback.close"),children:"✕"})]}),h==="success"?t.jsxs("div",{style:Eg,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:kg.map(x=>t.jsxs("button",{onClick:()=>l(x.value),style:{..._g,...a===x.value?Ng:{}},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:{...zg,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:Tg}),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:Rg,children:f}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{onClick:v,disabled:!k,style:{...Cg,opacity:k?1:.6,cursor:k?"pointer":"not-allowed"},children:o(h==="submitting"?"feedback.submitting":"feedback.submitFeedback")})})]})]})})},wg={position:"fixed",top:0,left:0,right:0,bottom:0,background:r.bim("backdrop"),display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},vg={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:r.bim("shadow-dialog")},Sg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},$g={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:r.bim("desc-fg"),padding:"4px 8px",borderRadius:"4px"},_g={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"},Ng={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},zg={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"},Cg={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},Eg={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:r.bim("success")},Rg={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginBottom:"12px"},Tg={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"},as="--bim-feedback-fab-offset",ls=48,Ig=16,Mg=({onSubmit:e,position:i={bottom:24,right:24},feedbackListUrl:n,hidden:s=!1,zIndex:o})=>{const{t:a}=oe(),[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(as,`calc(${c+ls+Ig}px + env(safe-area-inset-bottom, 0px))`),()=>{m.style.removeProperty(as)}},[s,c]),t.jsxs(t.Fragment,{children:[!s&&t.jsx("button",{type:"button",className:"bim-feedback-fab",onClick:()=>d(!0),style:{...Ag,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(md,{isOpen:l,onClose:()=>d(!1),onSubmit:e,feedbackListUrl:n})]})},Ag={position:"fixed",width:`${ls}px`,height:`${ls}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"},Lg=[{value:"bug",icon:"🐛"},{value:"resource",icon:"📚"},{value:"suggestion",icon:"💡"},{value:"contact",icon:"🤝"}],ud=({onSubmit:e})=>{const{t:i}=oe(),[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:Ga,children:t.jsxs("div",{style:Hg,children:[t.jsxs("span",{children:["✓ ",i("feedback.thanks")]}),t.jsx("button",{onClick:()=>m("idle"),style:Dg,children:i("feedback.continueSubmit")})]})}):t.jsxs("div",{style:Ga,children:[t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Lg.map(y=>t.jsxs("button",{onClick:()=>s(y.value),style:{...Pg,...n===y.value?Og:{}},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:{...Fg}}),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:Ug}),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:{...Bg,opacity:g?1:.6,cursor:g?"pointer":"not-allowed"},children:i(c==="submitting"?"feedback.submitting":"feedback.submit")})]}),c==="error"&&t.jsx("div",{style:Wg,children:p})]})},Ga={padding:"16px",border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",background:r.bim("input-bg")},Pg={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"},Og={borderColor:r.bim("primary"),background:r.bim("list-active-bg"),color:r.bim("primary"),fontWeight:500},Fg={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"},Bg={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:r.bim("primary"),color:r.bim("primary-fg"),fontWeight:500},Hg={display:"flex",alignItems:"center",gap:"12px",color:r.bim("success"),fontSize:"14px"},Dg={background:"none",border:"none",color:r.bim("primary"),cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Wg={fontSize:"13px",color:r.bim("danger"),padding:"8px 12px",background:r.bim("danger-bg"),borderRadius:"4px",marginTop:"8px"},Ug={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"},pd={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")}},Kg=pd.other,bd={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")}},Yg=bd.pending;function Vg(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 Gg(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 hd=({items:e,loading:i})=>{const n=It(),{t:s,convert:o}=oe();return i?t.jsx(Xl,{}):e.length===0?t.jsx("div",{style:qg,children:s("feedback.empty")}):t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:e.map(a=>{const l=pd[a.type]||Kg,d=bd[a.status]||Yg,c=typeof window<"u"&&Gg(a.pageUrl,window.location.href);return t.jsxs("div",{style:Xg,children:[t.jsxs("div",{style:Jg,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[t.jsx("span",{style:{...qa,background:l.color},children:s(`feedback.listType.${l.key}`)}),t.jsx("span",{style:{...qa,background:d.color},children:s(`feedback.status.${d.key}`)})]}),t.jsx("span",{style:Zg,children:Vg(a.createdAt)})]}),(a.resourceId||a.pageUrl)&&t.jsxs("div",{style:Qg,children:[a.resourceId&&t.jsx("a",{href:n(a.resourceId),style:Or,children:a.resourceId}),a.pageUrl&&!a.resourceId&&(c?t.jsx("a",{href:a.pageUrl,style:Or,children:a.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):t.jsx("span",{style:Or,children:a.pageUrl}))]}),t.jsx("div",{style:ex,children:o(a.content)}),a.reply&&t.jsxs("div",{style:tx,children:[t.jsx("div",{style:ix,children:s("feedback.reply")}),t.jsx("div",{children:o(a.reply)})]})]},a.id)})})},qg={textAlign:"center",padding:"40px 0",color:r.bim("desc-fg"),fontSize:"14px"},Xg={background:r.bim("bg"),border:`1px solid ${r.bim("widget-border")}`,borderRadius:"8px",padding:"16px"},Jg={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},qa={fontSize:"12px",color:r.bim("on-color-fg"),padding:"2px 8px",borderRadius:"4px",fontWeight:500},Zg={fontSize:"12px",color:r.bim("desc-fg")},Qg={fontSize:"12px",marginBottom:"6px"},Or={color:r.bim("primary"),textDecoration:"none",borderBottom:`1px dashed ${r.bim("primary")}`},ex={fontSize:"14px",lineHeight:"1.6",color:r.bim("fg"),whiteSpace:"pre-wrap"},tx={marginTop:"12px",padding:"10px 12px",background:r.bim("input-bg"),borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:r.bim("fg")},ix={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:r.bim("primary")},fd=({resourceId:e,transport:i,apiUrl:n})=>{const{t:s}=oe(),[o,a]=b.useState([]),[l,d]=b.useState(!0),c=b.useRef(s);c.current=s;const m=b.useMemo(()=>i??to(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(hd,{items:o,loading:l}),t.jsx("div",{style:{marginTop:"24px"},children:t.jsx(ud,{onSubmit:h})})]})},Qn=8;async function er(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 nx=/[)」』】》〉”’。,、;:!?…(「『【《〈“‘]/;function rx(e){const i=e.search(nx);return i<0?[e,""]:[e.slice(0,i),e.slice(i)]}const gd={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===sx(e))){const[a,l]=rx(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 sx(e){try{return decodeURI(e)}catch{return e}}const ox={...gd,strong:({children:e})=>t.jsx(t.Fragment,{children:e})},zi=({text:e,plainStrong:i,style:n,className:s})=>{const{convert:o}=gt(),a=i?ox:gd;return t.jsx("div",{className:s,style:n,children:t.jsx(Zm,{remarkPlugins:[Qm],components:a,children:o(e)})})},ax=r.detail["zh-Hant"].relation,lx=r.detail["zh-Hant"].lossStatus,cx=r.detail["zh-Hant"].resourceKind,tr=r.getT("zh-Hant"),io=(e,i)=>Object.prototype.hasOwnProperty.call(e,i);function Xa(e,i=tr){return e?io(ax,e)?i(`detail.relation.${e}`):e:i("detail.relation.related")}function dx(e,i=tr){return io(lx,e)?i(`detail.lossStatus.${e}`):e}function mx(e,i=tr){return io(cx,e)?i(`detail.resourceKind.${e}`):""}function no({authors:e,onNavigate:i,renderLink:n}){const{convert:s}=oe(),o=(e||[]).filter(a=>a&&a.name);return o.length?t.jsx(t.Fragment,{children:o.map((a,l)=>{const d=ys(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 xd(e,i,n=tr){var c,m;const s=gs(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 yd(e,i){const n=(e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name,s=Cl(e,i);return s?`${n}(${s})`:n}function ro({item:e,siblings:i,listedVolumeCounts:n}){const{t:s,convert:o}=oe(),[a,l]=b.useState(!1),d=r.volumeStats(e),c=!!d&&d.expected>0&&!(n!=null&&n.has(d.expected)),m=o(yd(e,i)),p=r.resourceHref(e),h=Wn(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(Ts,{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 jd({groups:e,listedVolumeCounts:i}){const{t:n,convert:s}=oe();return t.jsx(t.Fragment,{children:e.map(o=>t.jsxs("div",{className:"bim-d-rg",children:[o.label&&t.jsx("h3",{className:"bim-d-rg-h bim-d-ui",children: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(ro,{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(yd(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 Yi=[{key:"經部",label:"經部",token:"sect-jing"},{key:"史部",label:"史部",token:"sect-shi"},{key:"子部",label:"子部",token:"sect-zi"},{key:"集部",label:"集部",token:"sect-ji"}];function cs(e){var n;if(!e)return;const i=e.replace(/经/g,"經").replace(/史/g,"史").replace(/集/g,"集");return(n=Yi.find(s=>i.startsWith(s.key[0])))==null?void 0:n.key}const Ja=12,ux=60,kd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,railTop:a,back:l,railLinks:d})=>{var Me,Se,Je;const{t:c,convert:m,messages:p}=oe(),h=b.useMemo(()=>js({_books:e._books}),[e._books]),[u,f]=b.useState(new Map),[g,y]=b.useState(!1),[v,k]=b.useState(""),[x,j]=b.useState(!1),S=h.length<=ux,$=S||g||!!v||x,_=b.useMemo(()=>$?h:h.slice(0,Ja),[h,$]);b.useEffect(()=>{if(!i||_.length===0)return;const X=_.filter(L=>!u.has(L));if(X.length===0)return;let je=!1;return er(X,Qn,L=>i.getItem(L).then(G=>{var te;const ie=G??{};return[L,{id:L,title:ie.title,edition:ie.edition,resources:ie.resources,publication_info:ie.publication_info,current_location:ie.current_location,provenance:ie.provenance,lineage:ie.lineage,related_books:ie.related_books,dating:ie.dating,measure_info:ie.measure_info,summary:bx((te=G==null?void 0:G.description)==null?void 0:te.text)}]}).catch(()=>[L,{id:L}]),()=>je).then(L=>{je||f(G=>{const ie=new Map(G);for(const[te,ce]of L)ie.set(te,ce);return ie})}),()=>{je=!0}},[i,_,u]);const N=b.useMemo(()=>h.map(X=>u.get(X)??{id:X}),[h,u]),I=h.length>0&&h.every(X=>u.has(X)),D=!!i&&_.some(X=>!u.has(X)),E=S||$,R=b.useMemo(()=>Rl(N,e.version_graph,{era:v,scanOnly:x,sort:E?"year":"default"}),[N,e.version_graph,v,x,E]),O=g?R.rows:R.rows.slice(0,Ja),M=R.allRows.filter(X=>X.hasImage).length,q=R.allRows.reduce((X,je)=>{var L;return X+(((L=je.copies)==null?void 0:L.length)??0)},0),P=b.useMemo(()=>(e._related||[]).map(X=>({...X,title:X.title??""})),[e._related]),le=P.filter(X=>X.relation==="collected_in"),ae=b.useMemo(()=>{const X=["part_of","has_part","studied_by","studies","preceded_by","followed_by"],je=L=>{const G=X.indexOf(L??"");return G<0?X.length:G};return P.filter(L=>L.relation!=="collected_in").map((L,G)=>({r:L,i:G})).sort((L,G)=>je(L.r.relation)-je(G.r.relation)||L.i-G.i).map(L=>L.r)},[P]),Ce=b.useMemo(()=>{const X=gs(e.resources,e.resource_groups);return[...X.mirrors.flatMap(je=>je.items.map(L=>({r:L,kind:m(je.label)}))),...X.buckets.flatMap(je=>je.items.map(L=>({r:L,kind:m(mx(je.key,c))})))]},[e.resources,e.resource_groups,m,c]),xe=e.indexed_by||[],fe=e.emendated_by||[],se=b.useMemo(()=>{var be,Fe,Xe,Be,Ke;const X=[],je=(Fe=(be=e.authors)==null?void 0:be[0])==null?void 0:Fe.dynasty;je&&X.push({label:c("workPage.fact.written"),value:m(je)});const L=qt(e,p.unit.juan);if(L){const Ye=((Xe=e.juan_count)==null?void 0:Xe.description)??((Ke=(Be=e.measures)==null?void 0:Be.find(w=>(w==null?void 0:w.unit)==="卷"&&w.note))==null?void 0:Ke.note);X.push({label:c("workPage.fact.measure"),value:t.jsxs(t.Fragment,{children:[m(L),Ye&&Ye!==L?t.jsxs("span",{className:"bim-d-meta",children:["(",m(Ye),")"]}):null]})})}e.loss_status&&X.push({label:c("workPage.fact.loss"),value:m(dx(e.loss_status,c))}),e.authenticity==="forged"&&X.push({label:c("workPage.fact.authenticity"),value:m(c("workPage.fact.forged")),title:e.authenticity_basis?m(e.authenticity_basis):void 0});const G=R.allRows.filter(Ye=>Ye.sortYear!=null),ie=G.length>0?G.reduce((Ye,w)=>Ye.sortYear<=w.sortYear?Ye:w):null;ie!=null&&ie.era.era?X.push({label:c("workPage.fact.earliest"),value:m([ie.era.era,ie.era.reign].filter(Boolean).join(" ")),title:ie.era.source==="edition"?c("workPage.inferredFromEdition"):void 0}):D&&X.push({label:c("workPage.fact.earliest"),value:t.jsx("span",{className:"bim-d-meta","aria-label":c("workPage.loading"),children:"…"})}),fe.length&&X.push({label:c("workPage.fact.emendation"),value:c("workPage.emendationCount",{n:fe.length})});const te=px(e.additional_titles);te.length&&X.push({label:c("workPage.fact.alias"),value:te.map(m).join("、")});const ce=(e.additional_works||[]).map(Ye=>m(Ye.book_title)+(Ye.n_juan!=null?` ${Ye.n_juan}${p.unit.juan}`:""));return ce.length&&X.push({label:c("workPage.fact.appendix"),value:ce.join("、")}),X},[e,m,c,p,D,R.allRows,fe.length]),H=[{value:e._edition_count??h.length,label:c("workPage.stat.editions")},{value:I?M:0,label:c("workPage.stat.hasImage")},{value:xe.length,label:c("workPage.stat.catalogs")}],me=ks(e),W=me?[me.l1,me.l2,me.l3,me.l4].filter(Boolean).map(X=>m(X)):[],K=e.subtype?p.workSubtype[e.subtype]??m(e.subtype):"",re=t.jsx(Qi,{title:m(e.title),byline:t.jsx(no,{authors:e.authors,onNavigate:n,renderLink:s}),meta:t.jsx(vt,{items:[...W,me!=null&&me.source?c("workPage.classifiedBy",{source:m(me.source.split("/")[0])}):"",K]}),description:(Me=e.description)!=null&&Me.text?t.jsxs(t.Fragment,{children:[t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}),(Se=e.description.sources)!=null&&Se.length?t.jsx("div",{className:"bim-d-meta bim-d-ui",style:{marginTop:6,fontSize:12},children:e.description.sources.map(X=>({text:m(Bu(X)),href:Hu(X)})).filter(X=>X.text).map((X,je)=>t.jsxs(b.Fragment,{children:[je>0?" · ":null,X.href?t.jsx("a",{href:X.href,target:"_blank",rel:"noopener noreferrer",children:X.text}):X.text]},je))}):null]}):void 0,stats:H,facts:se,readAction:o,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:(Je=e.appendix)==null?void 0:Je.map((X,je)=>t.jsxs("details",{style:{marginTop:12},children:[t.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:13,minHeight:32},children:m(X.title)}),t.jsx(zi,{text:X.text,plainStrong:!0,style:{marginTop:8,fontSize:14,lineHeight:1.9}})]},je))}),Y=R.eras.length>=2?[{key:"",label:c("catalog.all")},...R.eras.map(X=>({key:X,label:`${X} ${R.allRows.filter(je=>je.era.era===X).length}`}))]:[],T=[];h.length&&T.push({id:"versions",label:c("workPage.sec.versions"),count:h.length}),xe.length&&T.push({id:"catalogs",label:c("workPage.sec.catalogs"),count:xe.length}),le.length&&T.push({id:"collected",label:c("workPage.sec.collected"),count:le.length}),ae.length&&T.push({id:"related",label:c("workPage.sec.related"),count:ae.length}),Ce.length&&T.push({id:"resources",label:c("workPage.sec.resources"),count:Ce.length});const ue=h.length===0&&xe.length===0,ye=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}),I&&M?c("workPage.versionsWithImage",{n:M}):"",R.rows.length!==R.allRows.length?c("workPage.versionsCurrent",{n:R.rows.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui","data-pending":D&&Y.length===0&&h.length>1?"":void 0,children:[Y.length>0&&t.jsx(qn,{items:Y,value:v,onChange:X=>{k(X),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx(bc,{label:c("workPage.scanOnly"),checked:x,onChange:X=>{j(X),y(!1)}}),t.jsx("span",{className:"bim-d-meta",children:c(E?"workPage.sortByYear":"workPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt bim-d-zt-ver","data-ncap":!g&&Xn(R.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:O.map(X=>{var je;return t.jsx(fx,{row:X,measure:(je=u.get(X.id))==null?void 0:je.measure_info,loaded:u.has(X.id),onNavigate:n,renderLink:s},`${X.id}:${u.has(X.id)?"r":"p"}`)})})]}),O.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c(v||x?"workPage.noVersionsFiltered":"workPage.noVersions")}),!g&&t.jsx(zs,{total:R.rows.length,shown:O.length,unit:c("workPage.moreUnit"),onClick:()=>y(!0)}),R.hasInferredEra&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"8px 0 0",fontSize:12},children:c("workPage.inferredEraNote")})]}),xe.length>0&&t.jsx(gx,{items:xe,transport:i,onNavigate:n,renderLink:s}),ue&&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")})})]}),Ne=(X,je)=>t.jsx(wt,{id:X,label:m(je),onNavigate:n,renderLink:s,dense:!0}),B=b.useMemo(()=>{const X=new Map;for(const je of ae){const L=Xa(je.relation,c);X.set(L,(X.get(L)??0)+1)}return X.size>1?[...X.entries()].sort((je,L)=>L[1]-je[1]).slice(0,4).map(([je,L])=>`${m(je)} ${L}`).join(" · "):void 0},[ae,m,c]),de=t.jsxs(t.Fragment,{children:[t.jsx(di,{id:"collected",title:c("workPage.sec.collected"),items:le.map(X=>Ne(X.id,X.title))}),t.jsx(di,{id:"related",title:c("workPage.sec.related"),meta:c("workPage.relatedCount",{n:ae.length}),sub:B,items:ae.map(X=>t.jsxs(t.Fragment,{children:[Ne(X.id,X.title),t.jsx("span",{className:"bim-d-meta",title:X.note?m(X.note):void 0,children:m(Xa(X.relation,c))})]}))}),t.jsx(di,{id:"resources",title:c("workPage.sec.resources"),cap:6,items:Ce.map(({r:X,kind:je})=>{const L=m((X.url?r.getDisplayNameFromUrl(X.url):void 0)||X.name),G=r.resourceHref(X);return t.jsxs(t.Fragment,{children:[G?t.jsxs("a",{href:G,target:"_blank",rel:"noopener noreferrer",children:[L," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]}):t.jsx("span",{children:L}),je&&t.jsx("span",{className:"bim-d-meta bim-d-kind",children:je})]})})})]});return t.jsx(Zi,{railTop:a,back:l,nav:T,railLinks:d,main:ye,card:re,side:de})};function px(e){return(e||[]).map(i=>typeof i=="string"?i:i==null?void 0:i.book_title).filter(i=>!!i)}function ds(e,i){return i((e.url?r.getDisplayNameFromUrl(e.url):void 0)||e.name)}function bx(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 hx({copies:e,onNavigate:i,renderLink:n}){const{t:s,convert:o}=oe(),a=new Map;for(const l of e){const d=l.locationName||(l.holders[0]?ds(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 fx({row:e,measure:i,loaded:n,onNavigate:s,renderLink:o}){const{t:a,convert:l}=oe(),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?ds(m,l):e.locationName?l(e.locationName):"",u=e.images[0],f=u?r.resourceHref(u):void 0,g=e.images.map(y=>ds(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(hx,{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 gx({items:e,transport:i,onNavigate:n,renderLink:s}){const{t:o,convert:a}=oe(),{items:l,groups:d}=b.useMemo(()=>{const f=[],g=new Map;for(const y of e){const v=`${y.source}\0${y.source_bid??""}`,k=g.get(v);k?k.push(y):(g.set(v,[y]),f.push(y))}return{items:f,groups:f.map(y=>g.get(`${y.source}\0${y.source_bid??""}`))}},[e]),[c,m]=b.useState(0),p=Math.min(c,l.length-1);l[p];const[h,u]=b.useState(new Map);return b.useEffect(()=>{if(!i)return;const f=[...new Set(l.map(y=>y.source_bid).filter(y=>!!y))];if(f.length===0)return;let g=!1;return Promise.all(f.map(y=>i.getItem(y).then(v=>{var k,x;return[y,((x=(k=v==null?void 0:v.authors)==null?void 0:k[0])==null?void 0:x.dynasty)??""]}).catch(()=>[y,""]))).then(y=>{g||u(new Map(y.filter(([,v])=>v)))}),()=>{g=!0}},[i,l]),t.jsx(_t,{id:"catalogs",title:o("workPage.sec.catalogs"),meta:t.jsx(vt,{items:[o("workPage.catalog.meta",{n:l.length}),o("workPage.sortByCatalog")]}),children:t.jsxs("div",{className:"bim-d-lu",children:[t.jsx("ul",{className:"bim-d-tl2 bim-d-ui",role:"tablist","aria-label":o("workPage.catalog.tablist"),children:l.map((f,g)=>t.jsx("li",{role:"presentation",children:t.jsxs("button",{type:"button",role:"tab","aria-selected":g===p,"aria-label":a(f.source),onClick:()=>m(g),children:[t.jsx("span",{className:"bim-d-tl2-dyn",children:h.get(f.source_bid??"")?a(h.get(f.source_bid??"")):" "}),t.jsx("i",{className:"bim-d-tl2-dot","aria-hidden":"true"}),t.jsx("span",{className:"bim-d-tl2-name","aria-hidden":"true",children:[...a(f.source)].slice(0,9).map((y,v)=>t.jsx("span",{children:y},v))})]})},g))}),t.jsxs("div",{className:"bim-d-lu-body",role:"tabpanel",children:[d[p].map((f,g)=>t.jsxs("div",{className:"bim-d-lu-entry",children:[f.title_info&&t.jsx("div",{className:"bim-d-lu-title",children:a(f.title_info)}),t.jsx(vt,{className:"bim-d-ui",style:{display:"block",marginTop:2},items:[f.source_bid?t.jsx(wt,{id:f.source_bid,label:a(f.source),onNavigate:n,renderLink:s,dense:!0}):a(f.source),f.section?a(f.section):"",f.author_info?`${o("label.authorInfo")} ${a(f.author_info)}`:"",f.edition?`${o("label.edition")} ${a(f.edition)}`:"",f.page??""]}),f.summary&&t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.summary),void 0,{t:o})}),f.comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.comment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.comment),void 0,{t:o})})]}),f.additional_comment&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"bim-d-quote-label bim-d-ui",children:o("section.additionalComment")}),t.jsx("p",{className:"bim-d-quote",children:Lt(a(f.additional_comment),void 0,{t:o})})]}),!f.summary&&!f.comment&&!f.additional_comment&&!f.title_info&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{marginTop:12},children:o("workPage.catalog.titleOnly")})]},g)),l.length>1&&t.jsxs("div",{className:"bim-d-lu-pager bim-d-ui",children:[p>0?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.prev",{name:a(l[p-1].source)}),onClick:()=>m(p-1),children:t.jsxs("span",{"aria-hidden":"true",children:["← ",a(l[p-1].source)]})}):t.jsx("span",{"aria-hidden":"true"}),t.jsxs("span",{className:"bim-d-meta",children:[p+1," / ",l.length]}),p<l.length-1?t.jsx("button",{type:"button","aria-label":o("workPage.catalog.next",{name:a(l[p+1].source)}),onClick:()=>m(p+1),children:t.jsxs("span",{"aria-hidden":"true",children:[a(l[p+1].source)," →"]})}):t.jsx("span",{"aria-hidden":"true"})]})]})]})})}const wd=({graph:e,renderLink:i,className:n,style:s})=>{const{t:o,convert:a}=oe();if(!e.nodes.length)return t.jsx("div",{style:{...Rx,...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:{...yx,...s},children:[e.title&&t.jsx("div",{style:jx,children:a(e.title)}),e.description&&t.jsx("div",{style:kx,children:a(e.description)}),u.map(f=>t.jsx(Za,{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(Za,{label:o("lineage.otherGroup"),nodes:p,incomingMap:l,siblingMap:d,nodeMap:c,renderLink:i})]})},Za=({label:e,color:i,nodes:n,incomingMap:s,siblingMap:o,nodeMap:a,renderLink:l})=>{const{convert:d}=oe();return t.jsxs("div",{style:wx,children:[t.jsx("div",{style:{...vx,borderLeftColor:i??r.bim("widget-border")},children:d(e)}),n.map(c=>t.jsx(xx,{node:c,incoming:s.get(c.id)??[],siblings:o.get(c.id)??[],nodeMap:a,renderLink:l},c.id))]})},xx=({node:e,incoming:i,siblings:n,nodeMap:s,renderLink:o})=>{const a=e.kind==="hypothetical",l=e.bridge,{t:d,convert:c}=oe();return t.jsxs("div",{style:{...Sx,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:$x,children:[t.jsx("span",{style:_x,children:a||!o?c(e.label):o(e.id,c(e.label))}),(e.year_text||e.year!=null)&&t.jsx("span",{style:Nx,children:$l(c(e.year_text),e.year,e.year_uncertain)})]}),t.jsxs("div",{style:zx,children:[e.category&&t.jsx(Pi,{children:c(e.category)}),e.status==="lost"&&t.jsx(Pi,{tone:"warn",children:d("lineage.lost")}),e.status==="fragment"&&t.jsx(Pi,{tone:"warn",children:d("lineage.fragment")}),a&&t.jsx(Pi,{tone:"info",children:d("lineage.hypothetical")}),l&&t.jsx(Pi,{tone:"info",children:d("lineage.bridge")})]}),e.extant_juan&&t.jsx("div",{style:Cx,children:d("lineage.extant",{juan:c(e.extant_juan)})}),e.note&&t.jsx("div",{style:Ex,children:c(e.note)}),i.length>0&&t.jsxs("div",{style:el,children:[t.jsx("div",{style:tl,children:d("lineage.sources")}),i.map(m=>{const p=s.get(m.source);return t.jsxs("div",{style:il(m.confidence),children:[t.jsx("span",{style:nl,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(Qa,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:rl,children:["· ",c(m.evidence)]})]},m.id)})]}),n.length>0&&t.jsxs("div",{style:el,children:[t.jsx("div",{style:tl,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:il(m.confidence),children:[t.jsx("span",{style:nl,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(Qa,{level:m.confidence}),m.evidence&&t.jsxs("span",{style:rl,children:["· ",c(m.evidence)]})]},m.id)})]})]})},Pi=({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})},Qa=({level:e})=>{const{t:i}=oe(),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},yx={fontSize:"14px",color:r.bim("fg")},jx={fontSize:"16px",fontWeight:600,marginBottom:"8px"},kx={fontSize:"13px",color:r.bim("muted"),marginBottom:"16px",lineHeight:1.6},wx={marginBottom:"16px"},vx={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:r.bim("fg")},Sx={border:`1px solid ${r.bim("widget-border")}`,borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:r.bim("bg")},$x={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},_x={fontSize:"15px",fontWeight:600},Nx={fontSize:"12px",color:r.bim("muted")},zx={marginBottom:"6px"},Cx={fontSize:"12px",color:r.bim("muted"),margin:"2px 0"},Ex={fontSize:"12px",color:r.bim("muted"),fontStyle:"italic",margin:"4px 0"},el={marginTop:"6px",paddingTop:"6px",borderTop:`1px dashed ${r.bim("widget-border")}`},tl={fontSize:"11px",color:r.bim("muted"),marginBottom:"2px"},il=e=>({fontSize:"12px",margin:"2px 0",opacity:e==="probable"||e==="disputed"?.85:1}),nl={display:"inline-block",padding:"0 6px",fontSize:"11px",background:r.bim("tag-bg"),color:r.bim("fg"),borderRadius:"3px",marginRight:"6px"},rl={fontSize:"11px",color:r.bim("muted")},Rx={padding:"20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px"},vd=({selectedNodeId:e,...i})=>{const{t:n}=oe(),[s,o]=b.useState("loading"),[a,l]=b.useState(null);return b.useEffect(()=>{let d=!1;return Tx().then(c=>{d||(c?(l(c),o("ready")):o("missing"))}),()=>{d=!0}},[]),s==="loading"?t.jsx("div",{style:ol,children:n("lineage.graphLoading")}):s==="missing"||!a?t.jsxs("div",{style:ol,children:[t.jsx("div",{children:sl(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:sl(n("lineage.graphMissingHint"),{list:t.jsx("code",{children:"VersionLineageList"})})})]}):t.jsx(Ix,{modules:a,selectedNodeId:e,...i})};function sl(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 Tx(){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 Ix=({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,v=b.useMemo(()=>({lineage:_=>{var le,ae,Ce,xe;const N=((le=_.data)==null?void 0:le.stepPosition)??.85,[I,D,E]=g({sourceX:_.sourceX,sourceY:_.sourceY,sourcePosition:_.sourcePosition,targetX:_.targetX,targetY:_.targetY,targetPosition:_.targetPosition,stepPosition:N,borderRadius:5}),R=!!((ae=_.data)!=null&&ae.isSibling),O=R?D:_.targetX-18,M=R?E:_.targetY-12,q=(Ce=_.data)==null?void 0:Ce.labelStyle,P=(xe=_.data)==null?void 0:xe.labelBgStyle;return t.jsxs(t.Fragment,{children:[t.jsx(u,{id:_.id,path:I,style:_.style,markerStart:_.markerStart,markerEnd:_.markerEnd}),_.label&&t.jsx(f,{children:t.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${O}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")}`,...P,...q},children:_.label})})]})}}),[u,f,g]),k=b.useMemo(()=>({version:_=>{const{t:N}=oe(),I=_.data,D=I.kind==="hypothetical",E=I.status==="lost",R=I.isSelected,O=I.bridge,M=I.borderColor??r.bim("muted"),q=O||D?"dashed":"solid",P=O?.5:E?.6:1;return t.jsxs("div",{style:{background:O?r.bim("bg-subtle"):r.bim("bg"),border:`2px ${q} ${R?r.bim("primary"):M}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:P,boxShadow:R?r.bim("shadow-node-selected"):D||O?"none":r.bim("shadow-node")},title:O?N("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:D||!I.renderLink?I.label:I.renderLink(I.bookId,I.label)}),I.description&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.25,marginTop:1},children:I.description}),I.yearText&&t.jsx("div",{style:{fontSize:10,color:r.bim("aux-fg"),lineHeight:1.2},children:$l(I.yearText,void 0,I.uncertain)}),E&&t.jsx("div",{style:{fontSize:9,color:r.bim("lost-fg"),marginTop:1},children:N("lineage.lost")}),t.jsx(p,{type:"source",position:h.Right,style:{visibility:"hidden"}})]})}}),[p,h]),{convert:x}=oe(),{rfNodes:j,rfEdges:S}=b.useMemo(()=>Mx(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:j,edges:S,nodeTypes:k,edgeTypes:v,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[t.jsx(c,{gap:16}),t.jsx(m,{showInteractive:!1})]})})};function Mx(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(k=>[k.id,k.color??r.bim("muted")]));for(const k of e.nodes)c.setNode(k.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const k of e.edges)k.kind==="derive"&&(p.has(k.relation)||c.setEdge(k.source,k.target));i.layout(c);const h=e.nodes.map(k=>{const x=c.node(k.id),j=s?k.id===s:void 0,S={kind:k.kind,label:o(k.label),bookId:k.kind==="book"?k.id:void 0,yearText:o(k.year_text??Lx(k)),uncertain:k.year_uncertain,category:k.category,status:k.status,borderColor:k.group?m.get(k.group):void 0,renderLink:n,isSelected:j,description:o(k.description),bridge:k.bridge};return{id:k.id,type:"version",position:{x:x.x-160/2,y:x.y-90/2},data:S,draggable:!1,selected:j}}),u=.78,f=.06,g=new Map;for(const k of e.edges)k.kind==="derive"&&(g.has(k.source)||g.set(k.source,[]),g.get(k.source).push(k));const y=new Map;for(const[k,x]of g){if(x.length<=1)continue;const j=[...x].sort(($,_)=>{var D,E;const N=((D=c.node($.target))==null?void 0:D.y)??0,I=((E=c.node(_.target))==null?void 0:E.y)??0;return N-I}),S=j.length;j.forEach(($,_)=>{const N=(_-(S-1)/2)*f;y.set($.id,u+N)})}const v=e.edges.map(k=>Ax(k,y.get(k.id),o));return{rfNodes:h,rfEdges:v}}function Ax(e,i,n=s=>s??""){const s=e.confidence==="probable"||e.confidence==="disputed",o=e.kind==="sibling",a=Px(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 Lx(e){if(e.year_range)return`~${e.year_range[0]}–${e.year_range[1]}`;if(typeof e.year=="number")return String(e.year)}function Px(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 ol={padding:"40px 20px",textAlign:"center",color:r.bim("muted"),fontSize:"13px",border:`1px dashed ${r.bim("widget-border")}`,borderRadius:8,background:r.bim("bg")},so=({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}=oe(),[g,y]=b.useState(i),v=$=>{y($),a==null||a($)},k=(()=>{if(!c)return[];const $=Object.entries(c);return $.length===0||c.all?$:[...$,["all",{label:u("lineage.collectionAll"),description:u("lineage.collectionAllDesc")}]]})(),x=!!(d&&k.length>0);if(!e.nodes.length)return t.jsx("div",{style:{padding:24,color:r.bim("muted"),textAlign:"center"},children:u("lineage.empty")});const j=l?(S=c==null?void 0:c[l])==null?void 0:S.description:void 0;return t.jsxs("div",{className:p,style:h,children:[t.jsxs("div",{style:Ox,children:[t.jsx("button",{onClick:()=>v("list"),style:Fr(g==="list"),children:u("lineage.modeList")}),t.jsx("button",{onClick:()=>v("graph"),style:Fr(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")}),k.map(([$,_])=>{const N=m==null?void 0:m[$];return t.jsxs("button",{onClick:()=>d==null?void 0:d($),style:Fr(l===$),title:_.description?f(_.description):void 0,children:[f(_.label),N!=null?` ${N}`:""]},$)})]})]}),x&&j&&t.jsx("div",{style:{fontSize:12,color:r.bim("muted"),marginBottom:8,padding:"4px 8px",background:r.bim("bg-subtle"),borderRadius:4},children:f(j)}),g==="list"?t.jsx(wd,{graph:e,renderLink:n}):t.jsx(vd,{graph:e,renderLink:n,height:s,selectedNodeId:o})]})},Ox={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Fr=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"}),al=40,ll=2,Fx=9,Bx=new Set(["certain","consensus","probable","disputed"]);function Br(e){if(!e)return["",""];const i=e.split(/[ ]+/).filter(Boolean);return i.length>=2&&/^第.+[回章卷篇節节]$/.test(i[0])?[i[0],i[1]]:["",e]}const Sd=({data:e,transport:i,onNavigate:n,renderLink:s,readAction:o,fullText:a,fullTextPending:l,chapterLink:d,railTop:c,back:m,railLinks:p})=>{var Fe,Xe,Be,Ke,Ye,w,ee,Z,he,Le;const h=r.useT(),{t:u,convert:f}=oe(),[g,y]=b.useState(null),[v,k]=b.useState(new Map),[x,j]=b.useState([]),[S,$]=b.useState(new Map),[_,N]=b.useState(!1),[I,D]=b.useState("flow"),[E,R]=b.useState(null);b.useEffect(()=>{if(!i||!e.work_id){y(null);return}let C=!1;return i.getItem(e.work_id).then(ge=>{!C&&ge&&ge.type==="work"&&y(ge)}).catch(()=>{}),()=>{C=!0}},[i,e.work_id]),b.useEffect(()=>{if(!(i!=null&&i.getLineageGraph)||!e.work_id){R(null);return}let C=!1;return i.getLineageGraph(e.work_id).then(ge=>{C||R(ge&&ge.nodes.length>1?ge:null)}).catch(()=>{C||R(null)}),()=>{C=!0}},[i,e.work_id]),b.useEffect(()=>{const C=e._collections||[];if(!i||C.length===0){k(new Map);return}let ge=!1;return Promise.all(C.map(V=>{const ze=V.id;return i.getItem(ze).then(we=>[ze,we]).catch(()=>[ze,null])})).then(V=>{if(ge)return;const ze=new Map;for(const[we,Te]of V)Te&&ze.set(we,Te);k(ze)}),()=>{ge=!0}},[i,e._collections]);const O=b.useMemo(()=>{const C=new Set([...g?js(g):[],...hu(e)]);return C.add(e.id),[...C]},[g,e.related_books,e.id]),M=O.length-1;b.useEffect(()=>{if(!i||M<=0){j([]);return}const C=O.length<=al,ge=C?O:O.slice(0,8);let V=!1;return Promise.all(ge.map(ze=>ze===e.id?Promise.resolve({id:ze,title:e.title,edition:e.edition,year:Tn(e)}):i.getItem(ze).then(we=>{const Te=we??{};return{id:ze,title:Te.title,edition:Te.edition,year:we?Tn(Te):void 0}}).catch(()=>({id:ze})))).then(ze=>{if(V)return;const we=ze.filter(Te=>Te.id===e.id||Te.title||Te.edition);C&&we.sort((Te,tt)=>(Te.year??1/0)-(tt.year??1/0)),j(we)}),()=>{V=!0}},[i,O,M,e]),e.lineage;const q=b.useMemo(()=>[...Gt(e).filter(C=>C.ref_type==="book").map(C=>C.ref),...mi(e).map(C=>C.book_id)].filter(Boolean),[e]);b.useEffect(()=>{if(!i||q.length===0){$(new Map);return}let C=!1;return Promise.all(q.map(ge=>i.getItem(ge).then(V=>[ge,{id:ge,title:V==null?void 0:V.title,edition:V==null?void 0:V.edition}]).catch(()=>[ge,{id:ge}]))).then(ge=>{C||$(new Map(ge))}),()=>{C=!0}},[i,q]);const P=b.useMemo(()=>xd(e.resources,e.resource_groups,u),[e.resources,e.resource_groups,u]),le=P.groups.reduce((C,ge)=>C+ge.rows.length+ge.mirrors.length,0),ae=P.groups.length>0&&P.groups.every(C=>C.key==="_physical"),Ce=Ji(e),xe=Ll(e),fe=qt(e,h.unit.juan),se=new Set((e._collections||[]).map(C=>Wi(C.vol).length).filter(C=>C>0)),Re=C=>{var ze;const ge=(ze=e.base_edition)==null?void 0:ze.find(we=>we.book_id===C&&we.name);if(ge!=null&&ge.name)return ge.name;const V=S.get(C);return(V==null?void 0:V.edition)||(V==null?void 0:V.title)||""},H=b.useMemo(()=>{var it,yt;const C=[];xe&&C.push({label:u("bookPage.fact.editionType"),value:f(xe),title:e.edition_type?void 0:u("bookPage.inferredFromEdition")}),(it=e.publication_info)!=null&&it.details?C.push({label:u("bookPage.fact.publication"),value:f(e.publication_info.details)}):(Ce.era||Ce.reign)&&C.push({label:u("bookPage.fact.era"),value:f([Ce.era,Ce.reign].filter(Boolean).join(" ")),title:Ce.source==="edition"?u("bookPage.inferredFromEdition"):void 0}),fe&&C.push({label:u("bookPage.fact.measure"),value:f(fe)});const ge=(e._collections||[]).flatMap(De=>Wi(De.vol));ge.length&&C.push({label:u("bookPage.fact.volumes"),value:u("bookPage.volumesValue",{range:Un(ge,h.unit.volume),unit:h.unit.volume,n:ge.length})});const V=Gt(e).find(De=>De.relation==="底本"&&De.ref_type==="book");V&&Re(V.ref)&&C.push({label:u("bookPage.fact.baseEdition"),value:t.jsx(wt,{id:V.ref,label:f(Re(V.ref)),onNavigate:n,renderLink:s,dense:!0})});const ze=(e.base_edition||[]).filter(De=>De&&De.name);for(const De of["底本","配補","參校"]){if(De==="底本"&&V&&Re(V.ref))continue;const J=ze.filter(ve=>ve.role===De);J.length&&C.push({label:f(De),value:J.map((ve,Qe)=>t.jsxs(b.Fragment,{children:[Qe>0&&"、",ve.book_id?t.jsx(wt,{id:ve.book_id,label:f(ve.name),onNavigate:n,renderLink:s,dense:!0}):f(ve.name)]},Qe))})}const we=(e.provenance||[]).filter(De=>De&&De.institution),Te=(e.resources||[]).filter(De=>r.getResourceTypes(De).includes("physical"));if(we.length){C.push({label:u("bookPage.fact.holdings"),value:we.slice(0,2).map(ve=>f(ve.institution)).join("、")+(we.length>2?u("bookPage.andMorePlaces",{n:we.length}):"")});const De=we.filter(ve=>ve.call_number).slice(0,2).map(ve=>`${f(ve.institution)} ${ve.call_number}`);De.length&&C.push({label:u("bookPage.fact.callNumber"),value:De.join(";")+(we.filter(ve=>ve.call_number).length>2?"…":"")});const J=we.flatMap(ve=>ve.seals||[]).filter(Boolean);J.length&&C.push({label:u("bookPage.fact.seals"),value:f(J.join("、"))})}else Te.length&&C.push({label:u("bookPage.fact.holdings"),value:Te.slice(0,2).map(De=>f(De.name)).join("、")+(Te.length>2?u("bookPage.andMorePlaces",{n:Te.length}):"")});const tt=e.physical_description;if(tt){const De=[[u("bookPage.fact.leafStyle"),tt.leaf_style],[u("bookPage.fact.binding"),tt.binding],[u("bookPage.fact.dimensions"),tt.dimensions],[u("bookPage.fact.condition"),tt.condition]];for(const[J,ve]of De)ve&&ve.trim()&&C.push({label:J,value:f(ve)})}(yt=e.page_count)!=null&&yt.description&&C.push({label:h.label.pageCount,value:f(e.page_count.description)});const Pe=_c(e.additional_titles);return Pe.length&&C.push({label:u("bookPage.fact.aliases"),value:Pe.map(f).join("、")}),C},[e,f,h,u,Ce,xe,fe,S,n,s]),me=f(e.title),W=e.edition?f(e.edition):void 0,K=((Fe=e.dating)==null?void 0:Fe.text)||"",re=t.jsx(Qi,{kind:u("bookPage.kind"),title:me,subtitle:W,byline:t.jsx(no,{authors:e.authors??(g==null?void 0:g.authors),onNavigate:n,renderLink:s}),meta:(()=>{const C=[xe?f(xe):"",Ce.era?f([Ce.era,Ce.reign].filter(Boolean).join("")):"",fe?f(fe):""].filter(Boolean);return C.length?t.jsx("span",{className:"bim-d-tags",children:C.map((ge,V)=>t.jsx("span",{className:`bim-d-tag bim-d-tag-${Math.min(V,2)}`,children:ge},V))}):null})(),description:(Xe=e.description)!=null&&Xe.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Es((Be=e.description)==null?void 0:Be.text)?6:void 0,facts:H,readAction:o,secondaryAction:o&&le>0&&!ae?t.jsx("a",{className:"bim-d-card-alt bim-d-ui",href:"#images",children:u("bookPage.viewImages")}):void 0,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo})}),Y=e._collections||[],T=(a==null?void 0:a.chapters)||[],ue=f(T[0]&&Br(T[0].title)[0].slice(-1)||"")||u("bookPage.chapterUnit"),ye=u("bookPage.chapterCount",{n:T.length,unit:ue}),Ne=!!(Gt(e).length||mi(e).length||(Ke=e.appendix)!=null&&Ke.length),B=[],de=u(ae?"bookPage.sec.physical":"bookPage.sec.images");(T.length||P.text.length||l)&&B.push({id:"fulltext",label:u("bookPage.sec.fulltext"),count:T.length?ye:void 0}),P.groups.length&&B.push({id:"images",label:de,count:le}),Ne&&B.push({id:"lineage",label:u("bookPage.sec.lineage")}),Y.length&&B.push({id:"collections",label:u("section.containedIn"),count:Y.length}),(Ye=e.location_history)!=null&&Ye.length&&B.push({id:"provenance",label:u("section.locationHistory")});const Me=C=>(d==null?void 0:d(C))??null,Se=T[0],Je=Se?Me(Se.file):null,X=_?T:T.slice(0,Fx),je=(C,ge,V)=>C?t.jsx("a",{className:V,href:C.href??"#",onClick:C.onClick?ze=>{ze.metaKey||ze.ctrlKey||(ze.preventDefault(),C.onClick())}:void 0,children:ge}):t.jsx("span",{className:V,children:ge}),L=t.jsxs(t.Fragment,{children:[(T.length>0||P.text.length>0||l)&&t.jsxs(_t,{id:"fulltext",title:u("bookPage.sec.fulltext"),meta:T.length>0?t.jsx(vt,{items:[ye,(w=a==null?void 0:a.source)!=null&&w.name?u("bookPage.sourceBy",{src:f(`${a.source.name}${a.source.license?` ${a.source.license}`:""}`)}):""]}):void 0,children:[l&&!Se&&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"})]}),Se&&t.jsxs("div",{className:"bim-d-ft",children:[t.jsx("h3",{className:"bim-d-ft-h",children:u("bookPage.readFrom",{ch:f(Br(Se.title)[0])||u("bookPage.firstChapter")})}),t.jsx("span",{className:"bim-d-meta",children:f((Se.title||"").replace(/^第.+?[回章卷篇節节][ ]*/,""))}),je(Je,t.jsxs(t.Fragment,{children:[u("bookPage.enterReader")," ",t.jsx("span",{"aria-hidden":"true",children:"→"})]}),"bim-d-ft-go bim-d-ui")]}),T.length>1&&t.jsx("ul",{className:"bim-d-chap",children:X.map(C=>{const[ge,V]=Br(C.title);return t.jsx("li",{children:je(Me(C.file),t.jsxs(t.Fragment,{children:[ge&&t.jsx("b",{children:f(ge)}),f(V||C.file)]}))},C.file)})}),T.length>X.length&&t.jsx(Cs,{label:u("detail.expandRest",{n:T.length-X.length,unit:ue}),onClick:()=>N(!0)}),P.text.length>0&&t.jsxs(t.Fragment,{children:[(T.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:P.text.map((C,ge)=>t.jsx(ro,{item:C,siblings:P.text,listedVolumeCounts:se},`${C.id||C.url||C.name}-${ge}`))})})]})]}),P.groups.length>0&&t.jsx(_t,{id:"images",title:de,meta:t.jsx(vt,{items:[P.groups.length>1?u("bookPage.groupCount",{n:P.groups.length}):"",u("bookPage.placeCount",{n:le})]}),children:t.jsx(jd,{groups:P.groups,listedVolumeCounts:se})}),Ne&&t.jsx(_t,{id:"lineage",title:u("bookPage.sec.lineage"),meta:Gt(e).length?u("bookPage.lineageMeta"):void 0,action:E?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":I==="flow",onClick:()=>D("flow"),children:u("bookPage.viewCards")}),t.jsx("button",{type:"button","aria-pressed":I==="graph",onClick:()=>D("graph"),children:u("bookPage.viewGraph")})]}):void 0,children:I==="graph"&&E?t.jsx(so,{graph:E,defaultMode:"graph",selectedNodeId:e.id,graphHeight:480,renderLink:(C,ge)=>t.jsx(wt,{id:C,label:f(ge),onNavigate:n,renderLink:s,dense:!0})}):t.jsx(Dx,{data:e,heading:W||me,yearText:K,refName:Re,onNavigate:n,renderLink:s})}),Y.length>0&&t.jsx(_t,{id:"collections",title:u("section.containedIn"),children:t.jsx("table",{className:"bim-d-zt",children:t.jsx("tbody",{children:Y.map((C,ge)=>{const V=C.id,ze=Wi(C.vol),we=v.get(V),Te=Ou(we);return t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:V,label:we?f(we.title):V,onNavigate:n,renderLink:s,dense:!0}),ze.length>0&&t.jsx(Hx,{volumes:ze,unit:h.unit.volume})]}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${Te?"":" bim-d-zt-blank"}`,style:{textAlign:"right"},children:Te>0&&u("bookPage.totalOf",{n:Te,unit:h.unit.bu})})]},`${V}-${ge}`)})})})}),(ee=e.location_history)!=null&&ee.length?t.jsx(_t,{id:"provenance",title:u("section.locationHistory"),children:t.jsx("ul",{className:"bim-d-tl",children:e.location_history.map((C,ge)=>t.jsxs("li",{children:[t.jsx("span",{className:"bim-d-tl-t",children:f(C.name||C.location||"")}),([C.start_date,C.end_date].filter(Boolean).join("—")||C.description||C.note)&&t.jsx("span",{className:"bim-d-tl-ev",style:{marginLeft:0},children:t.jsx(vt,{items:[[C.start_date,C.end_date].filter(Boolean).join("—"),C.description?f(C.description):"",C.note?f(C.note):""]})})]},ge))})}):null,B.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")})})]}),G=x.findIndex(C=>C.id===e.id),ie=O.length<=al,te=ie&&G>=0?x.slice(Math.max(0,G-ll),G+ll+1):x.filter(C=>C.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(C=>`${C.dynasty?`〔${f(C.dynasty)}〕`:""}${f(C.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}):""]}),((Le=g.description)==null?void 0:Le.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&&te.length>0&&t.jsxs("div",{children:[t.jsx(di,{id:"siblings",timeline:!0,title:ie?u("bookPage.siblings"):h.relation.siblingVersions,meta:ie?u("bookPage.byEra"):u("bookPage.kindCount",{n:M}),cap:te.length,items:te.map(C=>C.id===e.id?t.jsx("span",{className:"bim-d-side-cur-mark","data-current":"true",children:f(C.edition||C.title||C.id)}):t.jsx(wt,{id:C.id,label:f(C.edition||C.title||C.id),onNavigate:n,renderLink:s,dense:!0})),metas:te.map(C=>[C.year!=null?C.year<0?u("detail.bce",{n:-C.year}):String(C.year):"",C.id===e.id?u("detail.thisPage"):""].filter(Boolean).join(" ")),currentIndex:te.findIndex(C=>C.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:O.length}),onNavigate:n,renderLink:s,dense:!0})})]})]}),be=e.work_id?t.jsx(pc,{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(Zi,{railTop:c,back:m,up:be,nav:B,railLinks:p,main:L,card:re,side:ce})};function Hx({volumes:e,unit:i}){const{t:n}=oe();return t.jsxs("span",{className:"bim-d-meta bim-d-ui",children:[n("bookPage.volumeRange",{range:Un(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 Dx({data:e,heading:i,yearText:n,refName:s,onNavigate:o,renderLink:a}){var k;const{t:l,convert:d}=oe(),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&&Bx.has(x)?l("bookPage.confidenceNote",{c:l(`bookPage.confidence.${x}`)}):"",v=(x,j)=>t.jsx(wt,{id:x,label:d(j||x),onNavigate:o,renderLink:a,dense:!0});return t.jsxs("div",{className:"bim-d-lf",children:[g&&t.jsxs("ol",{className:"bim-d-lf-list",children:[p.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:x.relation?d(x.relation):l("bookPage.lineage.ancestor")}),t.jsx("span",{className:"bim-d-lf-name",children:l("bookPage.lineage.reconstructed")}),x.evidence&&t.jsxs("span",{className:"bim-d-meta",children:[d(x.evidence),y(x.confidence)]})]})},`a-${j}`)),h.map((x,j)=>t.jsx("li",{className:"bim-d-lf-node",children:t.jsxs("div",{className:"bim-d-lf-card",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]})},`b-${j}`)),t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-cur",children:[t.jsxs("div",{className:"bim-d-lf-here",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:l("bookPage.lineage.thisEdition")}),t.jsx("span",{className:"bim-d-lf-name",children:i}),n&&t.jsx("span",{className:"bim-d-lf-yr",children:d(n)})]}),u.length>0&&t.jsx("div",{className:"bim-d-lf-side",children:u.map((x,j)=>t.jsxs("div",{className:"bim-d-lf-dash",children:[t.jsx("span",{className:"bim-d-lf-tag bim-d-ui",children:d(x.relation)}),t.jsx("span",{className:"bim-d-lf-name",children:v(x.ref,s(x.ref))}),x.evidence&&t.jsxs("p",{className:"bim-d-lf-ev",children:[d(x.evidence),y(x.confidence)]})]},j))})]}),f.length>0&&t.jsxs("li",{className:"bim-d-lf-node bim-d-lf-out",children:[t.jsx("span",{className:"bim-d-lf-out-h bim-d-ui",children:l("bookPage.lineage.derivatives")}),t.jsx("span",{className:"bim-d-lf-chips",children:f.map((x,j)=>t.jsxs("span",{className:"bim-d-lf-chip",title:x.evidence?d(x.evidence):void 0,children:[v(x.book_id,s(x.book_id)),t.jsx("span",{className:"bim-d-meta",children:d(x.relation)})]},j))})]})]}),(k=e.appendix)==null?void 0:k.map((x,j)=>t.jsxs("details",{className:"bim-d-lf-app",children:[t.jsxs("summary",{className:"bim-d-ui",children:[t.jsx("span",{className:"bim-d-meta",children:l("bookPage.lineage.appendix")})," ",d(x.title)]}),t.jsx(zi,{text:x.text,plainStrong:!0,style:{marginTop:6,fontSize:14,lineHeight:1.9}})]},`x-${j}`)),(c==null?void 0:c.note)&&t.jsx("p",{className:"bim-d-meta",style:{margin:"12px 0 0",maxWidth:"46em"},children:d(c.note)})]})}const Oi=16,Wx=200,Ux=16,$d=({data:e,catalog:i,transport:n,onNavigate:s,renderLink:o,catalogAction:a,railTop:l,back:d,railLinks:c})=>{var ie,te,ce,be,Fe,Xe,Be,Ke,Ye;const{t:m,convert:p,messages:h}=oe(),[u,f]=b.useState(""),[g,y]=b.useState(!1),[v,k]=b.useState(null),[x,j]=b.useState(""),[S,$]=b.useState(!1),_=b.useMemo(()=>Al(e,i),[e,i]),N=b.useMemo(()=>Ml(e),[e]),[I,D]=b.useState(new Map),E=!!n&&_.rows.length>0&&_.rows.length<=Wx,R=E&&(_.rows.length<=Oi||S),O=R&&_.rows.every(w=>!w.id||I.has(w.id)),M=w=>{var ee;return cs(w?(ee=I.get(w))==null?void 0:ee.l1:void 0)},q=b.useMemo(()=>{const w=u.trim(),ee=w?p(w):"";return _.rows.filter(Z=>{var Le,C;if(x&&cs(Z.id?(Le=I.get(Z.id))==null?void 0:Le.l1:void 0)!==x)return!1;if(!ee)return!0;const he=Z.id&&((C=I.get(Z.id))==null?void 0:C.title)||Z.title;return p(he).includes(ee)||(Z.subItems||[]).some(ge=>p(ge).includes(ee))})},[_.rows,u,x,I,p]),P=g?q:q.slice(0,Oi),le=b.useMemo(()=>(R?_.rows:P).filter(w=>w.id&&!I.has(w.id)).map(w=>w.id),[R,_.rows,P,I]);b.useEffect(()=>{if(!n||le.length===0)return;let w=!1;const ee=le.slice(0,Ux);return er(ee,Qn,Z=>n.getItem(Z).then(he=>{var ge,V;const Le=he??{},C={title:Le.title,edition:Le.edition,authors:Le.authors,measure:he?qt(he,h.unit.juan):void 0,versionCount:Le._edition_count??((ge=Le._books)==null?void 0:ge.length),l1:((V=ks(Le))==null?void 0:V.l1)||void 0};return[Z,C]}).catch(()=>[Z,{}]),()=>w).then(Z=>{w||D(he=>{const Le=new Map(he);for(const[C,ge]of Z)Le.set(C,ge);return Le})}),()=>{w=!0}},[n,le,h.unit.juan]);const ae=(ie=(e.contained_in||[])[0])==null?void 0:ie.id;b.useEffect(()=>{if(!ae){k(null);return}if(k({id:ae}),!n)return;let w=!1;return n.getItem(ae).then(ee=>{w||k({id:ae,title:ee==null?void 0:ee.title})}).catch(()=>{}),()=>{w=!0}},[n,ae]);const Ce=b.useMemo(()=>xd(e.resources,e.resource_groups,m),[e.resources,e.resource_groups,m]),xe=Ce.text.length+Ce.groups.reduce((w,ee)=>w+ee.rows.length+ee.mirrors.length,0),fe=N.works,se=new Set(_.rows.map(w=>w.id).filter(Boolean)),Re=fe.length>0&&!fe.every(w=>se.has(w.id)),H=(()=>{const w=_.rows.map(ee=>ee.edition).filter(Boolean);return w.length>1&&new Set(w).size===1})(),me=_.rows.some(w=>w.volumes.length>0||w.expected!=null),W=N.total,K=N.truncated?W:_.rows.length,re=qt(e,h.unit.juan),Y=e.count,T=w=>typeof w=="number"&&Number.isFinite(w)?w:null,ue=T(Y==null?void 0:Y.juan)??T((te=e.juan_count)==null?void 0:te.number)??T((be=(ce=e.measures)==null?void 0:ce.find(w=>(w==null?void 0:w.unit)==="卷"))==null?void 0:be.number),ye=T(Y==null?void 0:Y.ce)??(_.totalVolumes||null),Ne=[{value:K,label:m("collectionPage.stat.titles")},{value:ue??0,label:h.unit.juan},{value:ye??0,label:h.unit.volume}],B=b.useMemo(()=>{var Z,he;const w=[];if((Z=e.publication_info)!=null&&Z.details&&w.push({label:m("collectionPage.fact.publication"),value:p(e.publication_info.details)}),W&&(W!==_.rows.length||N.truncated)){const Le=e._member_type==="Book"?m("collectionPage.member.Book"):e._member_type==="Work"?m("collectionPage.member.Work"):m("collectionPage.member.other");w.push({label:Le,value:`${W} ${h.unit.bu}`,title:m("collectionPage.memberNote")})}const ee=[T(Y==null?void 0:Y.zhong)!=null?m("collectionPage.nZhong",{n:Y.zhong}):"",T(Y==null?void 0:Y.han)!=null?m("collectionPage.nHan",{n:Y.han}):""].filter(Boolean);return ee.length&&w.push({label:m("collectionPage.fact.expected"),value:ee.join(" ")}),ue==null&&re&&w.push({label:m("collectionPage.fact.measure"),value:p(re),title:(he=e.juan_count)!=null&&he.description?p(e.juan_count.description):void 0}),w},[e,W,N.truncated,_.rows.length,ue,re,Y,p,m,h]),de=b.useMemo(()=>{if(!O)return[];const w=new Map;for(const Z of _.rows){const he=M(Z.id);he&&w.set(he,(w.get(he)??0)+1)}const ee=Yi.filter(Z=>(w.get(Z.key)??0)>0);return ee.length<2?[]:[{key:"",label:`${h.catalog.all} ${K}`},...ee.map(Z=>({key:Z.key,label:`${Z.label} ${w.get(Z.key)}`}))]},[O,_.rows,I,h]),Me=b.useMemo(()=>{if(!O||!_.rows.some(he=>he.volumes.length>0))return null;const w=[],ee=_.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,Le)=>he.from-Le.from);for(const he of ee){const Le=he.to-he.from+1,C=w[w.length-1];C&&C.key===he.k?(C.to=Math.max(C.to,he.to),C.n+=Le):w.push({key:he.k,from:he.from,to:he.to,n:Le})}const Z=ee.reduce((he,Le)=>Math.max(he,Le.to),0);return w.length>1&&w.some(he=>he.key)?{segs:w,last:Z}:null},[O,_.rows,I]),Se=(Fe=e.description)==null?void 0:Fe.text,Je=t.jsx(Qi,{kind:m("collectionPage.kind"),title:p(e.title),byline:t.jsx(no,{authors:e.authors,onNavigate:s,renderLink:o}),meta:t.jsx(vt,{items:[e.subtype==="work_collection"?m("collectionPage.workCollection"):"",(Xe=e.publication_info)!=null&&Xe.year?p(e.publication_info.year):""]}),description:Se||(Be=e.history)!=null&&Be.length?t.jsxs(t.Fragment,{children:[Se&&t.jsx(zi,{text:Se,style:{fontSize:15,lineHeight:1.85}}),(Ke=e.history)!=null&&Ke.length?t.jsx("ul",{style:{margin:"10px 0 0",paddingLeft:18,fontSize:14},children:e.history.map((w,ee)=>t.jsx("li",{children:p(w)},ee))}):null]}):void 0,clampDescription:Es(Se)||(((Ye=e.history)==null?void 0:Ye.length)??0)>2?6:void 0,stats:Ne,facts:B,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:Me&&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:Me.segs.map((w,ee)=>{const Z=Yi.find(he=>he.key===w.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:w.from,to:w.to}):void 0,"aria-label":Z?m("collectionPage.dist.only",{section:p(Z.label)}):m("collectionPage.dist.unclassified"),"aria-pressed":!!Z&&x===w.key,style:{flexGrow:w.n,background:Z?r.bim(Z.token):r.bim("rule")},onClick:()=>{Z&&(j(x===w.key?"":w.key),y(!1))}},ee)})}),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:Me.last})})]})]})}),X=[];_.rows.length&&X.push({id:"titles",label:m("collectionPage.sec.titles"),count:K}),xe&&X.push({id:"resources",label:m("collectionPage.sec.resources"),count:xe}),Re&&X.push({id:"works",label:h.section.containedWorks,count:fe.length});const je=t.jsxs(t.Fragment,{children:[_.rows.length>0&&t.jsxs(_t,{id:"titles",title:m("collectionPage.sec.titles"),meta:t.jsx(vt,{items:[`${K} ${h.unit.items}`,_.totalVolumes?m("collectionPage.totalVolumes",{n:_.totalVolumes,unit:h.unit.volume}):"",q.length!==K?m("collectionPage.currentN",{n:q.length,unit:h.unit.items}):""]}),action:a,children:[(_.rows.length>Oi||de.length>0)&&t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[de.length>0&&t.jsx(qn,{items:de,value:x,onChange:w=>{j(w),y(!1)}}),E&&_.rows.length>Oi&&!O&&t.jsx("button",{type:"button",className:"bim-d-groupbtn",disabled:S,onClick:()=>$(!0),title:m("collectionPage.loadAllTitle",{n:_.rows.length,unit:h.unit.items}),children:m(S?"collectionPage.grouping":"collectionPage.groupBySection")}),t.jsx("span",{className:"bim-d-spacer"}),_.rows.length>Oi&&t.jsx("input",{type:"search",className:"bim-d-find",value:u,placeholder:m("collectionPage.find"),"aria-label":m("collectionPage.find"),onChange:w=>{f(w.target.value),y(!1)}})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&Xn(q.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:P.map((w,ee)=>{var ze;const Z=w.id?I.get(w.id):void 0,he=Z!=null&&Z.title&&w.title===w.id?Z.title:w.title,Le=((Z==null?void 0:Z.authors)||[]).find(we=>we&&we.name),C=[Le?`${Le.dynasty?`〔${p(Le.dynasty)}〕`:""}${p(Le.name)}${Le.role?` ${p(Le.role)}`:""}`:"",Z!=null&&Z.measure?p(Z.measure):"",(ze=w.subItems)!=null&&ze.length?w.subItems.map(we=>p(we)).join("、"):"",(Z!=null&&Z.edition||w.edition)&&!H?p((Z==null?void 0:Z.edition)||w.edition||""):""].filter(Boolean),ge=Yi.find(we=>we.key===M(w.id)),V=w.volumes.length>0?m("collectionPage.volumeRange",{range:Un(w.volumes,h.unit.volume),unit:h.unit.volume}):w.expected!=null?`${w.found??0}/${w.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:[ge&&t.jsx("i",{className:"bim-d-sq","aria-hidden":"true",style:{background:r.bim(ge.token)}}),V||t.jsx("span",{className:"bim-d-zt-empty",children:"—"})]}),t.jsxs("td",{className:"bim-d-zt-main",children:[w.id?t.jsx(wt,{id:w.id,label:p(he),onNavigate:s,renderLink:o,dense:!0}):t.jsx("span",{className:"bim-d-zt-name",children:p(he)}),C.length>0?t.jsx(vt,{items:C}):w.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}):""})]},`${w.id??w.title}-${ee}`)})})]}),P.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:m("catalog.noMatch")}),!g&&t.jsx(zs,{total:q.length,shown:P.length,unit:h.unit.items,onClick:()=>y(!0)})]}),xe>0&&t.jsxs(_t,{id:"resources",title:m("collectionPage.sec.resources"),meta:m("collectionPage.resourcesCount",{n:xe}),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((w,ee)=>t.jsx(ro,{item:w,siblings:Ce.text},`${w.id||w.url||w.name}-${ee}`))})})]}),t.jsx(jd,{groups:Ce.groups})]}),_.rows.length===0&&xe===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")})})]}),L=Re?t.jsx(di,{id:"works",title:h.section.containedWorks,meta:m("collectionPage.nZhong",{n:fe.length}),cap:12,items:fe.map(w=>t.jsx(wt,{id:w.id,label:p(w.title),onNavigate:s,renderLink:o,dense:!0}))}):null,G=v?t.jsx(pc,{caption:m("collectionPage.parent"),children:t.jsx(wt,{id:v.id,label:p(v.title||v.id),onNavigate:s,renderLink:o,dense:!0})}):void 0;return t.jsx(Zi,{railTop:l,back:d,up:G,nav:X,railLinks:c,main:je,card:Je,side:L})},Kx=8;function _d(e){return typeof e!="string"||!e||e.startsWith("/")||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.split("/").some(i=>i==="..")?null:e}function Yx(e){return(e||[]).filter(i=>{var n,s;return _d(i==null?void 0:i.file)&&((n=i.credit)==null?void 0:n.trim())&&((s=i.license)==null?void 0:s.trim())}).slice(0,Kx)}function Vx({images:e,assetBase:i,name:n}){const{t:s,convert:o}=oe(),[a,l]=b.useState(0),[d,c]=b.useState(!1),m=i?Yx(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+_d(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 cl=8,dl=10,ml=30,Nd=(e,i,n)=>`/read/${e}${i&&i!=="default"?`/${i}`:""}/${n}`;function Gx(e){return`${Nd(e.item,e.key,e.chapter)}#${e.start}~${e.end}`}function qx(e,i,n){var s;return`${Nd(i,n.key,n.chapter)}#e=${((s=n.ids)!=null&&s.length?n.ids:[e]).join(",")}`}const Xx=({id:e,transport:i,renderLink:n,onTotal:s})=>{const{t:o,convert:a}=oe(),[l,d]=b.useState(null),[c,m]=b.useState("idle"),[p,h]=b.useState(cl),[u,f]=b.useState(dl),g=b.useRef(null),y=!!(i!=null&&i.getMentions),v=b.useRef(s);if(v.current=s,b.useEffect(()=>{if(d(null),m("idle"),h(cl),f(dl),!y)return;const $=g.current;let _=!1;const N=()=>{m("loading"),i.getMentions(e).then(D=>{var R,O;if(_)return;const E=D&&"books"in D?D:null;if(!E||!E.total){m("none"),(R=v.current)==null||R.call(v,0);return}d(E),m("ok"),(O=v.current)==null||O.call(v,E.total)}).catch(()=>{_||m("none")})};if(!$||typeof IntersectionObserver>"u")return N(),()=>{_=!0};const I=new IntersectionObserver(D=>{D.some(E=>E.isIntersecting)&&(I.disconnect(),N())},{rootMargin:"400px"});return I.observe($),()=>{_=!0,I.disconnect()}},[e,y,i]),c==="none"||!y)return t.jsx("div",{ref:g});const k=($,_,N)=>n?n($,_,N):t.jsx("a",{className:N,href:$,children:_}),x=new Map(((l==null?void 0:l.books)??[]).map($=>[$.item,$.title])),j=(l==null?void 0:l.examples)??[],S=(l==null?void 0:l.books)??[];return t.jsx("div",{ref:g,children:t.jsxs(_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&&j.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.examples")}),t.jsx("ol",{className:"bim-d-mentions",children:j.slice(0,p).map(($,_)=>{const N=[x.get($.item),$.heading].filter(Boolean).map(D=>a(D)).join(" · "),I=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"bim-d-mention-where bim-d-ui",children:N||$.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:k(Gx($),I,"bim-d-mention")},`${$.item}|${$.key}|${$.chapter}|${$.start}|${_}`)})}),j.length>p&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>h(j.length),children:o("mentions.more",{n:j.length-p})})]}),l&&S.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h3",{className:"bim-d-mentions-h bim-d-ui",children:o("mentions.byBook")}),t.jsx("ul",{className:"bim-d-mbooks",children:S.slice(0,u).map($=>t.jsx(Jx,{entityId:e,book:$,open:S.length===1,transport:i,link:k},$.item))}),S.length>u&&t.jsx("button",{type:"button",className:"bim-d-tab bim-d-ui",onClick:()=>f($=>$+ml),children:o("mentions.moreBooks",{n:Math.min(ml,S.length-u)})})]})]})})},Jx=({entityId:e,book:i,open:n,transport:s,link:o})=>{const{t:a,convert:l}=oe(),[d,c]=b.useState(i.chapters??null),[m,p]=b.useState(!1);b.useEffect(()=>{c(i.chapters??null)},[i]);const h=u=>{!u.currentTarget.open||d||m||!(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(qx(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}`))})]})})},Zx=16,Hr=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function ul(e){if(!e)return Hr.length;const i=Hr.indexOf(e);return i===-1?Hr.length:i}function Qx(e,i,n){if(i)return e[i]??n(i)}function e0(e,i){return e==null?"":e<0?i("entityPage.bce",{n:-e}):String(e)}const t0={秦:[-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]},zd=({data:e,transport:i,onNavigate:n,renderLink:s,railTop:o,back:a,railLinks:l,assetBase:d})=>{var be,Fe,Xe,Be,Ke,Ye;const{t:c,convert:m,messages:p}=oe(),h=w=>e0(w,c),[u,f]=b.useState("全部"),[g,y]=b.useState(!1),[v,k]=b.useState("default"),[x,j]=b.useState(new Map),[S,$]=b.useState(0),_=b.useMemo(()=>e._works||[],[e._works]),N=b.useMemo(()=>_.map(w=>{const ee=x.get(w.work_id);return{id:w.work_id,title:(ee==null?void 0:ee.title)??w.title??w.work_id,role:w.role||"",cls:xs(w.role),versionCount:ee==null?void 0:ee.versionCount,section:ee==null?void 0:ee.cls,l1:ee==null?void 0:ee.l1,measure:ee==null?void 0:ee.measure,hasImage:ee==null?void 0:ee.hasImage,loaded:!!(ee!=null&&ee.loaded)}}),[_,x]),I=b.useMemo(()=>Il(_.map(w=>w.role),c("detail.roleAll")),[_,c]),D=b.useMemo(()=>{const w=u==="全部"?N:N.filter(ee=>ee.cls===u);return v==="versions"?[...w].sort((ee,Z)=>(Z.versionCount??-1)-(ee.versionCount??-1)):w},[N,u,v]),E=g?D:D.slice(0,Zx),R=b.useMemo(()=>E.filter(w=>!x.has(w.id)).map(w=>w.id),[E,x]);b.useEffect(()=>{if(!i||R.length===0)return;let w=!1;return er(R,Qn,ee=>i.getItem(ee).then(Z=>{var V;const he=Z??{},Le=he._edition_count??((V=he._books)==null?void 0:V.length)??0,C=ks(he),ge=[C==null?void 0:C.l1,C==null?void 0:C.l2].filter(Boolean).join(" ");return[ee,{id:ee,title:he.title,versionCount:Le,loaded:!0,cls:ge||void 0,l1:(C==null?void 0:C.l1)||void 0,measure:Z&&qt(Z,p.unit.juan)||void 0,hasImage:!!he._has_image}]}).catch(()=>[ee,{id:ee,loaded:!0}]),()=>w).then(ee=>{w||j(Z=>{const he=new Map(Z);for(const[Le,C]of ee)he.set(Le,C);return he})}),()=>{w=!0}},[i,R,p.unit.juan]);const O=b.useMemo(()=>{const w=new Map;for(const ee of e.alt_names||[]){const Z=ee.type||p.section.aliases;w.has(Z)||w.set(Z,[]),w.get(Z).push(ee.name)}return[...w.entries()].sort((ee,Z)=>ul(ee[0])-ul(Z[0])).map(([ee,Z])=>({label:ee,names:Z}))},[e.alt_names,p]),M=((be=e.dates)==null?void 0:be.birth)??void 0,q=((Fe=e.dates)==null?void 0:Fe.death)??void 0,P=(Xe=e.dates)==null?void 0:Xe.floruit,le=M!=null||q!=null?`${h(M)||"?"}—${h(q)||"?"}`:Array.isArray(P)&&P.length===2&&P.every(w=>Number.isFinite(w))?c("entityPage.floruit",{from:h(P[0]),to:h(P[1])}):"",ae=new Set(["本名","字","號","号"]),Ce=O.filter(w=>ae.has(w.label)),xe=O.filter(w=>!ae.has(w.label)),fe=xe.reduce((w,ee)=>w+ee.names.length,0),se=b.useMemo(()=>{const w=[];for(const Z of Ce)w.push({label:Z.label,value:Z.names.map(he=>m(he)).join("、")});const ee=_.length;return ee&&w.push({label:c("entityPage.fact.works"),value:c("entityPage.nZhong",{n:ee})}),w},[_,Ce,m,c]),Re=w=>{var ee;return(ee=O.find(Z=>w.includes(Z.label)))==null?void 0:ee.names[0]},H=Re(["字"]),me=Re(["號","号"]),W=[H?c("entityPage.zi",{name:m(H)}):"",me?c("entityPage.hao",{name:m(me)}):""].filter(Boolean).join(","),K=e.native_place,re=e.dynasty?t0[e.dynasty]:void 0,Y=(()=>{if(!re||M==null||q==null||q<M)return null;const[w,ee]=re,Z=Math.max(M,w),he=Math.min(q,ee);if(he<=Z)return null;const Le=ee-w;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-w)/Le*100}%`,width:`${(he-Z)/Le*100}%`}})}),t.jsxs("div",{className:"bim-d-life-lab",children:[t.jsx("span",{children:`${h(w)} ${m(e.dynasty)}`}),t.jsx("span",{children:c("entityPage.lifeYears",{years:q-M+1})}),t.jsx("span",{children:h(ee)})]})]})})(),T=b.useMemo(()=>{if(!i||N.length===0||N.some(Z=>!Z.loaded))return null;const w=new Map;for(const Z of N){const he=cs(Z.l1);he&&w.set(he,(w.get(he)??0)+1)}const ee=Yi.map(Z=>({...Z,n:w.get(Z.key)??0})).filter(Z=>Z.n>0);return ee.length?ee:null},[N,i]),ue=t.jsxs(Qi,{kind:Qx(p.entityPage.subtype,e.subtype,m),title:m(e.primary_name||e.title),subtitle:W||void 0,meta:t.jsxs(t.Fragment,{children:[t.jsx(vt,{items:[e.dynasty?m(e.dynasty):"",le,K?c("entityPage.nativePlace",{place:m(K)}):""]}),Y,t.jsx(Vx,{images:e.images,assetBase:d,name:m(e.primary_name||e.title)})]}),description:(Be=e.description)!=null&&Be.text?t.jsx(zi,{text:e.description.text,style:{fontSize:15,lineHeight:1.85}}):void 0,clampDescription:Es((Ke=e.description)==null?void 0:Ke.text)?6:void 0,facts:se,foot:t.jsx(en,{revision:e.revision,revisedAt:e.revised_at,review:e.review,todo:e.todo}),children:[fe>0&&t.jsxs("details",{className:"bim-d-more-names bim-d-ui",children:[t.jsx("summary",{children:c("entityPage.moreNames",{n:fe})}),t.jsx("dl",{children:xe.map(w=>t.jsxs(b.Fragment,{children:[t.jsx("dt",{children:m(w.label)}),t.jsx("dd",{children:w.names.map(ee=>m(ee)).join("、")})]},w.label))})]}),T&&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:T.map(w=>t.jsx("i",{style:{flexGrow:w.n,background:r.bim(w.token)}},w.key))}),t.jsx("div",{className:"bim-d-dist-key",children:T.map(w=>t.jsxs("span",{children:[t.jsx("i",{style:{background:r.bim(w.token)}}),m(w.label)," ",w.n]},w.key))})]})]}),ye=b.useMemo(()=>N.filter(w=>w.loaded&&(w.versionCount??0)>0).sort((w,ee)=>(ee.versionCount??0)-(w.versionCount??0)).slice(0,3),[N]),Ne=!!i&&N.length>=3&&E.some(w=>!w.loaded),B=u==="全部"&&(Ne||ye.length>=2),de=e.external_ids||{},Me=((Ye=e.external_ids_meta)==null?void 0:Ye.cbdb_match)??de.cbdb_match,Se=[];de.cbdb_id!=null&&Se.push({label:"CBDB",id:String(de.cbdb_id),href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${de.cbdb_id}`,note:Me==="auto"?c("entityPage.autoMatch"):void 0});const Je=de.wikidata_id;Je&&Se.push({label:"Wikidata",id:Je,href:`https://www.wikidata.org/wiki/${Je}`});const X=de.viaf_id;X&&Se.push({label:"VIAF",id:X,href:`https://viaf.org/viaf/${X}`});const je=I.map(w=>({key:w.cls,label:`${w.label} ${w.count}`})),L=e.id?t.jsx(Xx,{id:e.id,transport:i,onTotal:$}):null,G=[...B&&!Ne?[{id:"featured",label:c("entityPage.sec.featured"),count:ye.length}]:[],...N.length?[{id:"works",label:c("entityPage.sec.allWorks"),count:N.length}]:[],...S?[{id:"mentions",label:c("mentions.title"),count:S}]:[],...Se.length?[{id:"external",label:c("entityPage.sec.external"),count:Se.length}]:[]],ie=B?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":Ne||void 0,children:[Ne&&[0,1,2].map(w=>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:" "})]},w)),!Ne&&ye.map(w=>t.jsxs("div",{className:"bim-d-pick",children:[t.jsx("span",{className:"bim-d-pick-t",children:t.jsx(wt,{id:w.id,label:m(w.title),onNavigate:n,renderLink:s,dense:!0})}),t.jsx(vt,{items:[w.section?m(w.section):"",w.measure?m(w.measure):""]}),t.jsxs("div",{className:"bim-d-pick-n bim-d-ui",children:[t.jsx("span",{className:"bim-d-pick-num",children:w.versionCount}),t.jsx("span",{children:c("entityPage.versionsUnit")}),w.hasImage&&t.jsx("span",{className:"bim-d-flag",children:c("entityPage.hasImage")})]})]},w.id))]})]}):null,te=N.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")})}),L]}):t.jsxs(t.Fragment,{children:[ie,t.jsxs(_t,{id:"works",title:c("entityPage.sec.works"),meta:t.jsx(vt,{items:[c("entityPage.total",{n:N.length}),D.length!==N.length?c("entityPage.current",{n:D.length}):""]}),children:[t.jsxs("div",{className:"bim-d-filters bim-d-ui",children:[je.length>1&&t.jsx(qn,{items:je,value:u,onChange:w=>{f(w),y(!1)}}),t.jsx("span",{className:"bim-d-spacer"}),t.jsx("button",{type:"button",className:"bim-d-tab","aria-pressed":v==="versions",onClick:()=>{v==="default"&&y(!0),k(w=>w==="default"?"versions":"default")},children:c(v==="default"?"entityPage.sortByVersions":"entityPage.sortByCatalog")})]}),t.jsxs("table",{className:"bim-d-zt","data-ncap":!g&&Xn(D.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:E.map(w=>t.jsxs("tr",{children:[t.jsxs("td",{className:"bim-d-zt-main",children:[t.jsx(wt,{id:w.id,label:m(w.title),onNavigate:n,renderLink:s,dense:!0}),w.measure?t.jsx(vt,{items:[m(w.measure)]}):!w.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${w.section||w.loaded?"":" bim-d-zt-blank"}`,children:w.section?m(w.section):null}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w.role?"":" bim-d-zt-blank"}`,children:w.role?m(w.role):t.jsx("span",{className:"bim-d-zt-empty",children:"—"})}),t.jsx("td",{className:`bim-d-zt-sub bim-d-zt-nowrap${w.loaded?"":" bim-d-zt-blank"}`,children:w.loaded?w.versionCount?c("entityPage.nZhong",{n:w.versionCount}):t.jsx("span",{className:"bim-d-zt-empty",children:c("entityPage.notRecorded")}):""}),t.jsx("td",{className:w.hasImage?void 0:"bim-d-zt-blank",style:{textAlign:"right"},children:w.hasImage&&t.jsx("span",{className:"bim-d-flag bim-d-ui",children:c("entityPage.hasImage")})})]},w.id))})]}),E.length===0&&t.jsx("p",{className:"bim-d-meta bim-d-ui",style:{margin:"12px 12px 0"},children:c("entityPage.emptyRole")}),!g&&t.jsx(zs,{total:D.length,shown:E.length,unit:c("entityPage.moreUnit"),onClick:()=>y(!0)})]}),L]}),ce=Se.length>0?t.jsx(di,{id:"external",title:c("entityPage.sec.external"),items:Se.map(w=>t.jsxs("a",{href:w.href,target:"_blank",rel:"noopener noreferrer",children:[w.label," ",t.jsx("span",{"aria-hidden":"true",children:"↗"})]})),metas:Se.map(w=>w.id),foot:de.cbdb_id!=null&&Me==="auto"?c("entityPage.cbdbAuto"):void 0}):null;return t.jsx(Zi,{railTop:o,back:a,nav:G,railLinks:l,main:te,card:ue,side:ce})},oo="(max-width: 719px)",i0=`${oo}, (pointer: coarse)`,Cd=`
|
|
1557
1558
|
.bim-ct {
|
|
1558
1559
|
display: grid; grid-template-columns: 248px minmax(0, 1fr); column-gap: 32px; align-items: start;
|
|
1559
1560
|
max-width: 1440px; margin: 0 auto; padding: 20px 32px 48px; box-sizing: border-box;
|
|
@@ -1712,7 +1713,7 @@ ${ce??""}`,[Ei,fo]=b.useState({key:Ci,data:A,started:!!A});if(Ei.key!==Ci)fo({ke
|
|
|
1712
1713
|
/* 窄屏分类抽屉:界栏下按钮和面板都有框 */
|
|
1713
1714
|
:root[data-layout="boxed"] .bim-ct-drawer-btn { border: ${r.bim("fr-bd")}; background: ${r.bim("fr-bg")}; }
|
|
1714
1715
|
:root[data-layout="boxed"] .bim-ct-drawer { border: ${r.bim("fr-bd")}; }
|
|
1715
|
-
`,ci="未分類",Vt="all",ao=20;function nn(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 n0(e){const i=nn(e);return i.length?i.join("/"):ci}function r0(e){const i=nn(e);return i.length?i.map((n,s)=>i.slice(0,s+1).join("/")):[ci]}function s0(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=nn(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 lo(e){return e.reduce((i,n)=>i+n.count,0)}function o0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function a0(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=o0(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=nn(e.classification);return l.length&&(i.classification=l),i}function l0(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 c0(e,i=ao){return Math.max(1,Math.ceil(e/i))}function Ed(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 d0=()=>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 m0(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 Rd({tree:e,selectedId:i,onSelect:n,allLabel:s,label:o}){const{t:a,convert:l}=oe(),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 I=new Set;for(const D of wi(e,p))I.add(D.id);return I});b.useEffect(()=>{const I=wi(e,p);I.length&&f(D=>{if(I.every(R=>D.has(R.id)))return D;const E=new Set(D);for(const R of I)E.add(R.id);return E})},[e,p]);const g=b.useMemo(()=>m0(e,u,h),[e,u,h]),[y,S]=b.useState(null);b.useEffect(()=>{S(null)},[i]);const k=p??(h?Vt:null),x=b.useMemo(()=>{var E;const I=new Set(g.map(R=>R.id));if(y&&I.has(y))return y;if(k&&I.has(k))return k;const D=wi(e,p).map(R=>R.id).filter(R=>I.has(R));return D.length?D[D.length-1]:((E=g[0])==null?void 0:E.id)??null},[g,y,k,e,p]),j=b.useCallback((I,D)=>{f(E=>{const R=E.has(I),O=D??!R;if(O===R)return E;const M=new Set(E);return O?M.add(I):M.delete(I),M})},[]),v=b.useCallback(I=>{S(I),requestAnimationFrame(()=>{var E;const D=Array.from(((E=m.current)==null?void 0:E.querySelectorAll("[data-ct-id]"))??[]).find(R=>R.dataset.ctId===I);D==null||D.focus()})},[]),$=b.useCallback((I,D)=>{D&&j(I,!0),n(I)},[n,j]),_=b.useCallback(I=>{const D=I.target.closest("[data-ct-id]");if(!D)return;const E=D.dataset.ctId,R=g.findIndex(q=>q.id===E);if(R<0)return;const O=g[R];let M=null;switch(I.key){case"ArrowDown":M=g[Math.min(g.length-1,R+1)].id;break;case"ArrowUp":M=g[Math.max(0,R-1)].id;break;case"Home":M=g[0].id;break;case"End":M=g[g.length-1].id;break;case"ArrowRight":if(!O.hasChildren)break;u.has(E)?M=O.firstChildId:j(E,!0);break;case"ArrowLeft":O.hasChildren&&u.has(E)?j(E,!1):M=O.parentId;break;case"Enter":case" ":I.preventDefault(),$(E,O.hasChildren);return;default:return}I.preventDefault(),M&&M!==E&&v(M)},[g,u,j,v,$]),N=(I,D)=>I.map((E,R)=>{var le;const O=(le=E.children)!=null&&le.length?E.children:null,M=!!O&&u.has(E.id),q=E.id===p,P=D===1&&I.length>1&&R===I.length-1;return t.jsxs("li",{role:"treeitem","aria-level":D,"aria-expanded":O?M:void 0,"aria-selected":q,tabIndex:x===E.id?0:-1,"data-ct-id":E.id,className:P?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":D-1},onClick:()=>{S(E.id),$(E.id,!!O)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:O?ae=>{ae.stopPropagation(),S(E.id),j(E.id)}:void 0,children:O?t.jsx(d0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(E.label)}),t.jsx("span",{className:"bim-ct-n",children:E.count.toLocaleString("en-US")})]}),M&&t.jsx("ul",{role:"group",children:N(O,D+1)})]},E.id)});return t.jsxs("ul",{ref:m,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:_,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:()=>{S(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:lo(e).toLocaleString("en-US")})]})}),N(e,1)]})}const Td=e=>`/item/${encodeURIComponent(e)}`;function u0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Id(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Md({work:e,href:i}){var d,c;const{t:n,convert:s}=oe(),o=Id(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 Ad({work:e,href:i}){var d,c;const{t:n,convert:s}=oe(),o=Id(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 Ld({page:e,pageCount:i,onPage:n,pageHref:s,label:o}){const{t:a,convert:l}=oe();if(i<=1)return null;const d=m=>p=>{n&&(s&&!u0(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:Ed(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 Pd({works:e,workLink:i=Td,emptyText:n,view:s="card",...o}){const{t:a,convert:l}=oe();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:n===void 0?a("catalogPage.emptyWorks"):typeof n=="string"?l(n):n}):s==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Ad,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Md,{work:d,href:i(d.id)},d.id))}),t.jsx(Ld,{...o})]})}const p0=()=>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 b0({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=ao,className:f,view:g,onViewChange:y}){const{t:S,convert:k}=oe(),x=p===void 0?S("catalogPage.all"):p,j=h??S("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[_,N]=b.useState(!1),[I,D]=b.useState("card"),E=g??I,R=ae=>{D(ae),y==null||y(ae)},O=wi(e,i&&i!==Vt?i:null),M=O.length?O[O.length-1]:null,q=M?M.label:j,P=M?M.count:lo(e),le=b.useCallback(ae=>{N(!1),a(ae)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":_?"open":"closed",children:[t.jsx("style",{children:Cd}),t.jsxs("aside",{className:"bim-ct-side","aria-label":S("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":_,"aria-controls":$,onClick:()=>N(ae=>!ae),children:[t.jsx("span",{children:S("catalogPage.drawerLabel",{path:k(O.length?O.map(ae=>ae.label).join(" › "):x??j)})}),t.jsx(p0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:S("catalogPage.classification")}),t.jsx(Rd,{tree:e,selectedId:i,onSelect:le,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:k(q)}),O.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:k(O.slice(0,-1).map(ae=>ae.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[S("catalogPage.stat",{total:P.toLocaleString("en-US"),size:u}),s>1&&S("catalogPage.statPage",{page:n,pages:s})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":S("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":E==="card",onClick:()=>R("card"),children:S("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":E==="list",onClick:()=>R("list"),children:S("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Pd,{works:o,view:E,workLink:c,page:n,pageCount:s,onPage:l,pageHref:m})]})]})}const rn="(max-width: 719px)",h0="(max-width: 1079px)",f0=`${rn}, (pointer: coarse)`,g0=[8,18,30,42,88],co=`
|
|
1716
|
+
`,ci="未分類",Vt="all",ao=20;function nn(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 n0(e){const i=nn(e);return i.length?i.join("/"):ci}function r0(e){const i=nn(e);return i.length?i.map((n,s)=>i.slice(0,s+1).join("/")):[ci]}function s0(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=nn(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 lo(e){return e.reduce((i,n)=>i+n.count,0)}function o0(e){return(e??"").replace(/\*\*|__/g,"").replace(/\s+/g," ").trim()}function a0(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=o0(typeof e.description=="string"?e.description:(m=e.description)==null?void 0:m.text);a&&(i.summary=a);const l=nn(e.classification);return l.length&&(i.classification=l),i}function l0(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 c0(e,i=ao){return Math.max(1,Math.ceil(e/i))}function Ed(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 d0=()=>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 m0(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 Rd({tree:e,selectedId:i,onSelect:n,allLabel:s,label:o}){const{t:a,convert:l}=oe(),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 I=new Set;for(const D of wi(e,p))I.add(D.id);return I});b.useEffect(()=>{const I=wi(e,p);I.length&&f(D=>{if(I.every(R=>D.has(R.id)))return D;const E=new Set(D);for(const R of I)E.add(R.id);return E})},[e,p]);const g=b.useMemo(()=>m0(e,u,h),[e,u,h]),[y,v]=b.useState(null);b.useEffect(()=>{v(null)},[i]);const k=p??(h?Vt:null),x=b.useMemo(()=>{var E;const I=new Set(g.map(R=>R.id));if(y&&I.has(y))return y;if(k&&I.has(k))return k;const D=wi(e,p).map(R=>R.id).filter(R=>I.has(R));return D.length?D[D.length-1]:((E=g[0])==null?void 0:E.id)??null},[g,y,k,e,p]),j=b.useCallback((I,D)=>{f(E=>{const R=E.has(I),O=D??!R;if(O===R)return E;const M=new Set(E);return O?M.add(I):M.delete(I),M})},[]),S=b.useCallback(I=>{v(I),requestAnimationFrame(()=>{var E;const D=Array.from(((E=m.current)==null?void 0:E.querySelectorAll("[data-ct-id]"))??[]).find(R=>R.dataset.ctId===I);D==null||D.focus()})},[]),$=b.useCallback((I,D)=>{D&&j(I,!0),n(I)},[n,j]),_=b.useCallback(I=>{const D=I.target.closest("[data-ct-id]");if(!D)return;const E=D.dataset.ctId,R=g.findIndex(q=>q.id===E);if(R<0)return;const O=g[R];let M=null;switch(I.key){case"ArrowDown":M=g[Math.min(g.length-1,R+1)].id;break;case"ArrowUp":M=g[Math.max(0,R-1)].id;break;case"Home":M=g[0].id;break;case"End":M=g[g.length-1].id;break;case"ArrowRight":if(!O.hasChildren)break;u.has(E)?M=O.firstChildId:j(E,!0);break;case"ArrowLeft":O.hasChildren&&u.has(E)?j(E,!1):M=O.parentId;break;case"Enter":case" ":I.preventDefault(),$(E,O.hasChildren);return;default:return}I.preventDefault(),M&&M!==E&&S(M)},[g,u,j,S,$]),N=(I,D)=>I.map((E,R)=>{var le;const O=(le=E.children)!=null&&le.length?E.children:null,M=!!O&&u.has(E.id),q=E.id===p,P=D===1&&I.length>1&&R===I.length-1;return t.jsxs("li",{role:"treeitem","aria-level":D,"aria-expanded":O?M:void 0,"aria-selected":q,tabIndex:x===E.id?0:-1,"data-ct-id":E.id,className:P?"bim-ct-last":void 0,children:[t.jsxs("div",{className:"bim-ct-row",style:{"--bimct-lv":D-1},onClick:()=>{v(E.id),$(E.id,!!O)},children:[t.jsx("span",{className:"bim-ct-tw","aria-hidden":"true",onClick:O?ae=>{ae.stopPropagation(),v(E.id),j(E.id)}:void 0,children:O?t.jsx(d0,{}):null}),t.jsx("span",{className:"bim-ct-lb",children:l(E.label)}),t.jsx("span",{className:"bim-ct-n",children:E.count.toLocaleString("en-US")})]}),M&&t.jsx("ul",{role:"group",children:N(O,D+1)})]},E.id)});return t.jsxs("ul",{ref:m,role:"tree","aria-label":l(c),className:"bim-ct-tree",onKeyDown:_,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:()=>{v(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:lo(e).toLocaleString("en-US")})]})}),N(e,1)]})}const Td=e=>`/item/${encodeURIComponent(e)}`;function u0(e){return e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey}function Id(e,i){return e==null||e===""?null:typeof e=="number"?i("catalogPage.juanN",{n:e}):e}function Md({work:e,href:i}){var d,c;const{t:n,convert:s}=oe(),o=Id(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 Ad({work:e,href:i}){var d,c;const{t:n,convert:s}=oe(),o=Id(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 Ld({page:e,pageCount:i,onPage:n,pageHref:s,label:o}){const{t:a,convert:l}=oe();if(i<=1)return null;const d=m=>p=>{n&&(s&&!u0(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:Ed(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 Pd({works:e,workLink:i=Td,emptyText:n,view:s="card",...o}){const{t:a,convert:l}=oe();return t.jsxs("div",{className:"bim-ct-works",children:[e.length===0?t.jsx("p",{className:"bim-ct-empty",children:n===void 0?a("catalogPage.emptyWorks"):typeof n=="string"?l(n):n}):s==="list"?t.jsx("ul",{className:"bim-ct-list",children:e.map(d=>t.jsx(Ad,{work:d,href:i(d.id)},d.id))}):t.jsx("ul",{className:"bim-ct-grid",children:e.map(d=>t.jsx(Md,{work:d,href:i(d.id)},d.id))}),t.jsx(Ld,{...o})]})}const p0=()=>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 b0({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=ao,className:f,view:g,onViewChange:y}){const{t:v,convert:k}=oe(),x=p===void 0?v("catalogPage.all"):p,j=h??v("catalogPage.allTitle"),$=`bim-ct-drawer-${b.useId().replace(/:/g,"")}`,[_,N]=b.useState(!1),[I,D]=b.useState("card"),E=g??I,R=ae=>{D(ae),y==null||y(ae)},O=wi(e,i&&i!==Vt?i:null),M=O.length?O[O.length-1]:null,q=M?M.label:j,P=M?M.count:lo(e),le=b.useCallback(ae=>{N(!1),a(ae)},[a]);return t.jsxs("div",{className:f?`bim-ct ${f}`:"bim-ct","data-drawer":_?"open":"closed",children:[t.jsx("style",{children:Cd}),t.jsxs("aside",{className:"bim-ct-side","aria-label":v("catalogPage.sideNav"),children:[t.jsxs("button",{type:"button",className:"bim-ct-drawer-btn","aria-expanded":_,"aria-controls":$,onClick:()=>N(ae=>!ae),children:[t.jsx("span",{children:v("catalogPage.drawerLabel",{path:k(O.length?O.map(ae=>ae.label).join(" › "):x??j)})}),t.jsx(p0,{})]}),t.jsxs("div",{className:"bim-ct-drawer",id:$,children:[t.jsx("h2",{className:"bim-ct-side-h",children:v("catalogPage.classification")}),t.jsx(Rd,{tree:e,selectedId:i,onSelect:le,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:k(q)}),O.length>1&&t.jsx("span",{className:"bim-ct-crumb",children:k(O.slice(0,-1).map(ae=>ae.label).join(" › "))}),t.jsxs("span",{className:"bim-ct-stat",children:[v("catalogPage.stat",{total:P.toLocaleString("en-US"),size:u}),s>1&&v("catalogPage.statPage",{page:n,pages:s})]}),t.jsxs("span",{className:"bim-ct-view",role:"group","aria-label":v("catalogPage.viewLabel"),children:[t.jsx("button",{type:"button","aria-pressed":E==="card",onClick:()=>R("card"),children:v("catalogPage.viewCard")}),t.jsx("button",{type:"button","aria-pressed":E==="list",onClick:()=>R("list"),children:v("catalogPage.viewList")})]})]}),d&&t.jsx("div",{className:"bim-ct-search",children:d}),t.jsx(Pd,{works:o,view:E,workLink:c,page:n,pageCount:s,onPage:l,pageHref:m})]})]})}const rn="(max-width: 719px)",h0="(max-width: 1079px)",f0=`${rn}, (pointer: coarse)`,g0=[8,18,30,42,88],co=`
|
|
1716
1717
|
.bim-rh { color: ${r.bim("ink")}; font-family: ${r.bim("font-ui")}; font-size: 14px; line-height: 1.6; }
|
|
1717
1718
|
.bim-rh *, .bim-rh *::before, .bim-rh *::after { box-sizing: border-box; }
|
|
1718
1719
|
.bim-rh a { color: ${r.bim("accent")}; text-decoration: none; }
|
|
@@ -2113,4 +2114,4 @@ ${g0.map((e,i)=>`.bim-rh-band a[data-k="${i}"] { background: color-mix(in srgb,
|
|
|
2113
2114
|
.bim-mh-recent li a, .bim-mh-types a, .bim-mh-tl-list a { min-height: 44px; align-items: center; }
|
|
2114
2115
|
.bim-mh-recent-h button { min-height: 44px; }
|
|
2115
2116
|
}
|
|
2116
|
-
`,em={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ii(e){return{...em,...e??{}}}function tm(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 bo(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function im(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 On(e,i=r.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function v0(e){return{read:e.item,work:e.item,node:e.node}}function nm({counts:e,links:i}){const{t:n}=oe(),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 rm(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=>Ss(e,d))).then(d=>{a||s(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{vs(),s([])},[]);return{entries:n,clear:o}}function S0(e,i,n){const s=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return s?n(s):sm(e.type,i)}function sm(e,i){return i(`metaHome.typeLabel.${e}`)}function om({entries:e,onClear:i,links:n}){const{t:s,convert:o}=oe(),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?sm(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:S0(l,s,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:s("metaHome.recentEmpty")})]})}function am(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 lm({rows:e,links:i}){const{t:n,convert:s}=oe(),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=bo(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:am(a.status,n,s)})})]},a.id||a.name)})})]})}):null}function cm({items:e,links:i,label:n}){const{convert:s}=oe();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 dm({works:e,links:i}){const{t:n}=oe(),[s,o]=b.useState(!1);if(!e.length)return null;const a=qi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(cm,{items:e.map(l=>({id:l.id,title:l.title,sub:ir(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 mm="siku_qige";function $0({group:e,links:i}){const{t:n,convert:s}=oe(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[s(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(cm,{items:e.items,links:i,label:e.label}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>a(l=>!l),children:o?n("action.collapse"):n("metaHome.allNKinds",{n:e.items.length})})]})}function um({groups:e,links:i}){const{t:n,convert:s}=oe(),o=ii(i);if(!e.length)return null;const a=e.find(c=>c.key===mm),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($0,{group:c,links:o},c.key))})]})}const pl=34,bl=13;function hl(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?On(e.birth_year,i):"?"}–${e.death_year!=null?On(e.death_year,i):"?"}`}function _0(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 pm({people:e,links:i}){const{t:n,convert:s}=oe(),o=ii(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=im(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-bl):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,bl),{...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*pl+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*pl+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:hl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:_0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:On(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):"",hl(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 N0=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 bm({works:e,links:i}){const{t:n,convert:s}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=ir(a);return t.jsx("li",{children:t.jsxs("a",{href:tm(o,a.id),children:[N0,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 hm({sites:e}){const{t:i,convert:n}=oe(),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=bo(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:am(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 fl=["extant","partially_extant","lost","unknown"];function fm({stats:e,links:i,version:n,repoUrl:s,downloadHref:o}){const{t:a}=oe(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(m=>[e[m],a(`metaHome.stat.${m}`)]).filter(([m])=>m>0),d=i==null?void 0:i.loss,c=fl.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:fl.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 gm={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function z0({sections:e,links:i,head:n,transport:s,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,_;const{t:h}=oe(),u=e,f=ii(i),g=v0(f),y=gm,S=rm(s),k={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(N=>k[N]),j=N=>h(`metaHome.nav.${N}`),v=(N,I)=>N?t.jsx("a",{className:"bim-rh-more",href:N,children:I}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:co+Qd}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(nm,{counts:u.counts,links:i})]}),s&&t.jsx(om,{entries:S.entries,onClear:S.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(N=>t.jsx("li",{children:t.jsx("a",{href:`#${y[N]}`,children:j(N)})},N))})}),t.jsxs("div",{className:"bim-rh-main",children:[k.zhi&&t.jsxs(Rt,{id:y.zhi,title:j("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(uo,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:g,showTitle:!1,legendCount:u.shelf.items.some(N=>N.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:(_=u.shelf)!=null&&_.items.length?void 0:{marginTop:0},children:[t.jsx(lm,{rows:u.catalog_progress,links:i}),t.jsx(dm,{works:u.related_catalogs,links:i})]})]}),k.sibu&&t.jsx(Rt,{id:y.sibu,title:j("sibu"),sub:h("metaHome.sibuSub"),more:v(o,h("metaHome.toCatalog")),children:t.jsx(po,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),k.cong&&t.jsx(Rt,{id:y.cong,title:j("cong"),sub:h("metaHome.congSub"),more:v(a,h("metaHome.allNKindsMore",{n:jt(u.counts.collections)})),children:t.jsx(um,{groups:u.collection_groups,links:i})}),k.people&&t.jsx(Rt,{id:y.people,title:j("people"),sub:h("metaHome.peopleSub"),more:v(l,h("metaHome.allNPeopleMore",{n:jt(u.counts.entities)})),children:t.jsx(pm,{people:u.bibliographers,links:i})}),k.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(bm,{works:u.lineage,links:i})}),k.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(hm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx(fm,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const xm=["_related","_catalogs","_collections","_members","_children"],C0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ms=e=>C0(e)&&!!e.h;function E0(e){return e?xm.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(ms)}):!1}function R0(e,i){const n={...e};if(!i)return n;for(const s of xm){const o=e[s];!Array.isArray(o)||!o.some(ms)||(n[s]=o.map(a=>{var c;if(!ms(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 T0(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&&R0(d,E0(d)?await n():null)};const a=Reflect.get(s,o,s);return typeof a=="function"?a.bind(s):a}})}const us=({style:e})=>{const i=b.useContext(r.LocaleContext),{t:n}=oe();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")})]})},ps=({href:e,label:i,size:n=16,className:s,style:o})=>{const{t:a}=oe(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className: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 Dr(e){const i=e.text_count;return typeof i=="number"&&i>0}function Wr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function I0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const M0=({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:S,renderLink:k,assetBase:x,enrichDetail:j,getSourceLink:v,readLink:$,railTop:_,extraTabs:N=[],showFeedbackTab:I=!0,feedbackApiUrl:D,height:E,footerExtra:R,hideHeaderControls:O=!1,className:M,style:q})=>{const P=b.useMemo(()=>T0(i),[i]),le=b.useMemo(()=>dd(P)??to(D),[P,D]),ae=r.useT(),{t:Ce,convert:xe}=oe(),[fe]=b.useState(()=>{if(!I0(e,n))return null;const J={...n},ve=s??Wr(e,J);return j&&j(ve,J),{id:e,entry:ve,detail:J}}),[se,Re]=b.useState((fe==null?void 0:fe.entry)??null),[H,me]=b.useState((fe==null?void 0:fe.detail)??null),[W,K]=b.useState(!fe),[re,Y]=b.useState(!1),[T,ue]=b.useState([]),[ye,Ne]=b.useState(!1),[B,de]=b.useState(null),[Me,Se]=b.useState(null),[Je,X]=b.useState(null),[je,L]=b.useState(!1),G=b.useRef(null),ie=b.useRef(0),[te,ce]=b.useState(null),be=l!==void 0?l:te,Fe=b.useCallback(J=>{d?d(J):ce(J)},[d]),Xe=b.useCallback(async J=>{if(!P.getCollectionCatalogs&&!P.getCollectionCatalog){ue([]);return}Ne(!0);try{if(P.getCollectionCatalogs)ue(await P.getCollectionCatalogs(J)||[]);else if(P.getCollectionCatalog){const ve=await P.getCollectionCatalog(J);ue(ve?[{resource_id:"",data:ve}]:[])}}catch{ue([])}finally{Ne(!1)}},[P]),Be=b.useCallback(async J=>{var ve,Qe;if(!P.getTextManifest||!P.getTextIndex){de(null),Se(J);return}try{const et=_e.pickTextVersion(await P.getTextManifest(J)),We=et?await P.getTextIndex(J,et.key):null;de(We&&We.chapters.length>0?{chapters:We.chapters.map(He=>({n:He.n,title:He.title,file:He.file})),source:{name:((ve=We.source)==null?void 0:ve.name)??(et==null?void 0:et.source_name),license:((Qe=We.source)==null?void 0:Qe.license)??(et==null?void 0:et.license)??void 0}}:null)}catch{de(null)}finally{Se(J)}},[P]),Ke=b.useCallback(async(J,ve)=>{const Qe=++ie.current,et=()=>Qe!==ie.current;L(!0);try{if(P.getLineageGraph){const ft=await P.getLineageGraph(J);if(et())return;ft&&X(ft)}const We=ve.version_graph;if(!We||!We.enabled){Je||X(null),G.current=null;return}const He=js(ve),pt=(await er(He,Qn,async ft=>{try{return await P.getItem(ft)}catch{return null}},et)).filter(Boolean);if(et())return;G.current={work:ve,books:pt};const bt=p??We.default_collection??(We.core_books&&We.core_books.length>0?"core":"all"),Ue=bt==="core"&&Array.isArray(We.core_books)&&We.core_books.length>0?"core":bt??"all";X(wn(ve,pt,Ue))}catch{if(et())return;X(null),G.current=null}finally{et()||L(!1)}},[P]),Ye=b.useRef({initialDetail:n,initialEntry:s});Ye.current={initialDetail:n,initialEntry:s},b.useEffect(()=>{let J=!1;ie.current++,L(!1);const ve=He=>{He.type==="collection"?Xe(e):He.type==="work"?(He.version_graph||P.getLineageGraph)&&Ke(e,He):He.type==="book"&&Dr(He)&&Be(e)},Qe=Ye.current;let et=null;if(fe&&fe.id===e)et=fe;else if(Qe.initialDetail&&Qe.initialDetail.id===e){const He={...Qe.initialDetail},ut=Qe.initialEntry??Wr(e,He);j&&j(ut,He),et={entry:ut,detail:He}}return et?(Y(!1),ue(He=>He.length?[]:He),de(null),X(null),G.current=null,Re(et.entry),me(et.detail),K(!1),ve(et.detail),()=>{J=!0}):((async()=>{K(!0),Y(!1),Re(null),me(null),ue([]),de(null),X(null),G.current=null;try{const He=await P.getItem(e);if(J)return;if(!He){Y(!0);return}const ut=He;let pt=null;if(P.getEntry&&(pt=await P.getEntry(e),J))return;pt||(pt=Wr(e,ut)),j&&j(pt,ut),Re(pt),me(ut),ve(ut)}catch{J||Y(!0)}finally{J||K(!1)}})(),()=>{J=!0})},[e,P,fe,j,Xe,Ke,Be]),b.useEffect(()=>{const J=G.current;!J||!p||X(wn(J.work,J.books,p))},[p]);const w=[];if(H){if(w.push({key:"basic",label:ae.detailTab.basicInfo}),H.type==="collection"){ye&&T.length===0&&w.push({key:"catalog:loading",label:`${ae.detailTab.catalog}…`});for(const J of T)w.push({key:`catalog:${J.resource_id}`,label:J.short_name?`${xe(J.short_name)}${ae.detailTab.catalogSuffix}`:ae.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&w.push({key:o,label:ae.detailTab.fullText}),H.type==="work"&&(Je||je)&&w.push({key:"lineage",label:je?`${ae.detailTab.lineage}…`:ae.detailTab.lineage});for(const J of N)(J.position??"before-feedback")==="before-feedback"&&J.shouldShow(H)&&w.push({key:J.key,label:J.label});I&&o==="feedback"&&w.push({key:"feedback",label:ae.detailTab.feedback});for(const J of N)J.position==="after-feedback"&&J.shouldShow(H)&&w.push({key:J.key,label:J.label})}b.useEffect(()=>{if(o!=="emendated"||!H)return;a("basic");const J=setTimeout(()=>{var ve;(ve=document.getElementById("studies"))==null||ve.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(J)},[o,H,a]);const ee=se&&H&&v?v({activeTab:o,activeJuan:be,entry:se,detail:H}):null,Z=b.useMemo(()=>{var We,He,ut,pt,bt;if(!H)return null;const ve=(H.authors??[]).map(Ue=>{const ft=ys(Ue.role);return`${Ue.dynasty?`〔${xe(Ue.dynasty)}〕`:""}${xe(Ue.name)}${ft?` ${xe(ft)}`:""}`}).join(" · ");let Qe=!1;try{Qe=_e.extractStatus(H.id)==="draft"}catch{}if(H.type==="book"){const Ue=H;return{title:xe(Ue.title),subtitle:Ue.edition?xe(Ue.edition):ve||void 0,aside:[Qe?ae.status.draft:"",ve&&Ue.edition?ve:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(H.type==="collection"){const Ue=H;return{title:xe(Ue.title),subtitle:xe(qt(Ue,ae.unit.juan))||void 0,aside:[(We=Ue.publication_info)==null?void 0:We.year,Qe?ae.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ve||void 0}}if(H.type==="entity"){const Ue=H,ft=A=>A==null?"":A<0?Ce("detail.bce",{n:-A}):String(A),Q=((He=Ue.dates)==null?void 0:He.birth)!=null||((ut=Ue.dates)==null?void 0:ut.death)!=null?`${ft(((pt=Ue.dates)==null?void 0:pt.birth)??void 0)||"?"}—${ft(((bt=Ue.dates)==null?void 0:bt.death)??void 0)||"?"}`:"";return{title:xe(Ue.primary_name||Ue.title),subtitle:[Ue.dynasty?`〔${xe(Ue.dynasty)}〕`:"",Q].filter(Boolean).join(" ")||void 0,aside:Qe?ae.status.draft:void 0,secondLine:void 0}}const et=xe(qt(H,ae.unit.juan));return{title:xe(H.title),subtitle:[et,ve].filter(Boolean).join(" · ")||void 0,aside:[L0(ae,H.subtype),Qe?ae.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[H,xe,ae,Ce]),he=H&&Dr(H)?"text":null,Le=()=>{Fe(null),a("fulltext")};let C=null;if(H&&$){const J=$({detail:H,kind:he});J&&(C=t.jsx(Zr,{href:J}))}else he&&(C=t.jsx(Zr,{onClick:Le}));const ge=J=>{if(!H)return null;const ve=J.replace(/\.[^.]+$/,"");if($){const Qe=$({detail:H,kind:he,juan:ve});return Qe?{href:Qe}:null}return{onClick:()=>{Fe(ve),a("fulltext")}}},V=new Set(N.map(J=>J.key)),ze=w.filter(J=>J.key.startsWith("catalog:")&&J.key!=="catalog:loading"||J.key==="lineage"&&!!Je&&!je||V.has(J.key)).map(J=>({key:J.key,label:J.label,onClick:()=>a(J.key)})),we=()=>{var J;return H?H.type==="work"?t.jsx(kd,{data:H,transport:P,onNavigate:g,renderLink:k,readAction:C,railTop:_,railLinks:ze}):H.type==="book"?t.jsx(Sd,{data:H,transport:P,onNavigate:g,renderLink:k,readAction:C,fullText:B,fullTextPending:Dr(H)&&!!P.getTextManifest&&Me!==H.id,chapterLink:ge,railTop:_,railLinks:ze}):H.type==="collection"?t.jsx($d,{data:H,catalog:(J=T[0])==null?void 0:J.data,transport:P,onNavigate:g,renderLink:k,readAction:C,railTop:_,railLinks:ze,catalogAction:T.length>0?t.jsxs("a",{href:"#catalog",onClick:ve=>{ve.preventDefault(),a(`catalog:${T[0].resource_id}`)},children:[xe(ae.detailTab.collectionCatalog)," →"]}):null}):t.jsx(zd,{data:H,transport:P,onNavigate:g,renderLink:k,railTop:_,railLinks:ze,assetBase:x}):null},Te=()=>{var ve,Qe,et;if(!se||!H)return null;if(o==="basic"||o==="emendated")return we();if(typeof o=="string"&&o.startsWith("catalog:")){const We=(ve=T.find(He=>`catalog:${He.resource_id}`===o))==null?void 0:ve.data;return t.jsx(Gl,{data:We,onNavigate:g,renderLink:k})}if(o==="collated"||o==="fulltext")return t.jsx(cd,{id:e,transport:P,chapter:be,onLocationChange:We=>Fe(We.chapter),onNavigate:g});if(o==="lineage"){if(!Je)return t.jsx("div",{style:{color:r.bim("label-fg"),padding:"24px 0"},children:Ce(je?"detail.loading":"detail.noLineageGraph")});const We=H.type==="work"?H:null;return t.jsx(so,{graph:Je,renderLink:k,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((Qe=We==null?void 0:We.version_graph)==null?void 0:Qe.default_collection),onCollectionChange:h,collectionsAvailable:(et=We==null?void 0:We.version_graph)==null?void 0:et.collections,collectionCounts:(()=>{var bt,Ue,ft,Q,A,ne,$e;if(!We)return;const He={},ut=((bt=G.current)==null?void 0:bt.books)??[];He.all=(((Ue=We._books)==null?void 0:Ue.length)??0)-(((Q=(ft=We.version_graph)==null?void 0:ft.excluded_books)==null?void 0:Q.length)??0);const pt=(A=We.version_graph)==null?void 0:A.collections;if(pt)for(const Ie of Object.keys(pt))He[Ie]=wn(We,ut,Ie).nodes.filter(Oe=>Oe.kind==="book"&&!Oe.bridge).length;return He.core==null&&(($e=(ne=We.version_graph)==null?void 0:ne.core_books)!=null&&$e.length)&&(He.core=We.version_graph.core_books.length),He})()})}if(o==="feedback"&&I)return t.jsx(fd,{resourceId:e,transport:le});const J=N.find(We=>We.key===o);return J?J.render({detail:H,entry:se,transport:P,onNavigate:g}):null};if(W)return t.jsx(Hi,{style:{minHeight:E,...q},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((J,ve)=>t.jsx("div",{style:{height:ve===1?40:16,width:J,opacity:.35,background:r.bim("rule")}},ve))})});if(re||!H||!se||!Z)return t.jsx(Hi,{style:{minHeight:E,...q},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r.bim("label-fg"),fontSize:14},children:Ce("detail.notFound")})});const tt=o==="basic"||o==="emendated",Pe=[{label:S??ae.detailTab.backToIndex,onClick:y}];if(H.type==="book"&&H.work_id){const J=H.work_id;Pe.push({label:ae.indexType.work,id:J,onClick:()=>g==null?void 0:g(J)})}Pe.push({label:ae.indexType[H.type]});const it=o==="collated"||o==="fulltext",yt=typeof R=="string"?ae.status[R.trim()]??R:R,De=t.jsx(Nc,{left:t.jsxs(t.Fragment,{children:[yt,yt?" · ":"",t.jsx(A0,{id:H.id,label:ae.label.id,copied:ae.action.copied,copyLabel:ae.action.copy})]}),right:t.jsxs(t.Fragment,{children:[I&&!tt&&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:ae.detailTab.submitVersion}),ee&&t.jsx("a",{href:ee.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r.bim("meta-fg")},children:ae.detailTab.dataLicense})]})});return tt?t.jsx("div",{className:M,children:t.jsxs(Hi,{grid:!0,style:{minHeight:E,...q},children:[t.jsx(Qr,{breadcrumb:t.jsx(es,{items:Pe}),actions:t.jsxs(t.Fragment,{children:[!O&&t.jsx(us,{style:{border:"none",background:"transparent"}}),!O&&ee&&t.jsx(ps,{...ee})]})}),we(),De]})}):t.jsx("div",{className:M,children:t.jsxs(Hi,{wide:it,style:{minHeight:E,...q},children:[t.jsx(Qr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Rs,{char:"籍"}),t.jsx(es,{items:Pe})]}),actions:t.jsxs(t.Fragment,{children:[!O&&t.jsx(us,{}),I&&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:ae.detailTab.feedback}),!O&&ee&&t.jsx(ps,{...ee})]})}),t.jsx(gc,{...Z,aside:it?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")," →"]}):Z.aside}),!it&&w.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:w.map(J=>t.jsx(xc,{label:J.label,active:J.key===o||tt&&J.key==="basic",onClick:()=>a(J.key)},J.key))}),t.jsx("div",{style:{marginTop:!it&&w.length>1?8:0},children:Te()}),De]})})};function A0({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 L0(e,i){return i?e.workSubtype[i]??i:""}const ym=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],nr="zhusha",rr="bim-theme";function jm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function sr(e){return jm(e)?e:nr}function P0(){try{return sr(window.localStorage.getItem(rr))}catch{return nr}}function km(e){try{window.localStorage.setItem(rr,e)}catch{}}function wm(e){const i=sr(e);return document.documentElement.setAttribute("data-theme",i),i}function vm(){return sr(document.documentElement.getAttribute("data-theme"))}const O0=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],ho="airy",or="bim-layout";function Sm(e){return e==="airy"||e==="boxed"}function ar(e){return Sm(e)?e:ho}function F0(){try{return ar(window.localStorage.getItem(or))}catch{return ho}}function B0(e){try{window.localStorage.setItem(or,e)}catch{}}function H0(e){const i=ar(e);return document.documentElement.setAttribute("data-layout",i),i}function D0(){return ar(document.documentElement.getAttribute("data-layout"))}const W0=`try{var t=localStorage.getItem(${JSON.stringify(rr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(or)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,U0={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},K0=({onChange:e,style:i})=>{const{t:n}=oe(),[s,o]=b.useState(nr);b.useEffect(()=>{o(vm())},[]);const a=l=>{o(wm(l)),km(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:ym.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(U0[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=_e.BidLink;exports.BookIndexError=_e.BookIndexError;exports.BookIndexManager=_e.BookIndexManager;exports.BookIndexStorage=_e.BookIndexStorage;exports.BundleStorage=_e.BundleStorage;exports.ConfigError=_e.ConfigError;exports.GithubStorage=_e.GithubStorage;exports.IdGenerationError=_e.IdGenerationError;exports.IdGenerator=_e.IdGenerator;exports.LocalStorage=_e.LocalStorage;exports.MigrationError=_e.MigrationError;exports.StorageError=_e.StorageError;exports.adaptCharCord=_e.adaptCharCord;exports.adaptFig=_e.adaptFig;exports.adaptNorm=_e.adaptNorm;exports.adaptNormDetailed=_e.adaptNormDetailed;exports.adaptPunctJson=_e.adaptPunctJson;exports.base36Decode=_e.base36Decode;exports.base36Encode=_e.base36Encode;exports.base58Decode=_e.base58Decode;exports.buildId=_e.buildId;exports.buildPromotionMap=_e.buildPromotionMap;exports.cleanName=_e.cleanName;exports.decodeId=_e.decodeId;exports.decodeIdString=_e.decodeIdString;exports.encodeId=_e.encodeId;exports.extractIdFromUrl=_e.extractIdFromUrl;exports.extractStatus=_e.extractStatus;exports.extractType=_e.extractType;exports.iiifVolumeOf=_e.iiifVolumeOf;exports.isChapterSegment=_e.isChapterSegment;exports.isTextKey=_e.isTextKey;exports.loadFigUrls=_e.loadFigUrls;exports.loadReaderChapter=_e.loadReaderChapter;exports.loadReaderFiles=_e.loadReaderFiles;exports.matchChapterAcrossVersions=_e.matchChapterAcrossVersions;exports.normalizeCatalog=_e.normalizeCatalog;exports.parseId=_e.parseId;exports.pickTextVersion=_e.pickTextVersion;exports.readerManifest=_e.readerManifest;exports.readerVersions=_e.readerVersions;exports.shardOf=_e.shardOf;exports.smartDecode=_e.smartDecode;exports.textVersionLabel=_e.textVersionLabel;exports.validateResource=_e.validateResource;exports.volumeFromChar=_e.volumeFromChar;exports.Badge=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=eu.VARIANT_SUPPLEMENT;exports.BidUrlProvider=iu;exports.BookDetailLayout=M0;exports.BookPage=Sd;exports.Breadcrumb=es;exports.CATALOG_ALL_ID=Vt;exports.CATALOG_CSS=Cd;exports.CATALOG_NARROW_QUERY=oo;exports.CATALOG_PAGE_SIZE=ao;exports.CATALOG_UNCLASSIFIED_ID=ci;exports.CLASSIFICATIONS=Vn;exports.CardFoot=en;exports.CatalogPage=b0;exports.CatalogPager=Ld;exports.CatalogTree=Rd;exports.CheckFilter=bc;exports.Chip=yc;exports.ChipWall=bb;exports.CollectionCatalog=Gl;exports.CollectionPage=$d;exports.DEFAULT_LAYOUT=ho;exports.DEFAULT_META_HOME_LINKS=em;exports.DEFAULT_READER_PREFS=Ns;exports.DEFAULT_READ_HOME_LINKS=Od;exports.DEFAULT_THEME=nr;exports.DETAIL_CSS=fc;exports.DYNASTY_GROUPS=Yn;exports.Dash=jb;exports.DataTable=fb;exports.DetailFooter=Nc;exports.DetailGrid=Zi;exports.DetailHeader=gc;exports.EMPTY_FILTERS=Kn;exports.ENTITY_TEXT_CSS=Vs;exports.EmptyNote=Nb;exports.EntityMark=Xs;exports.EntityPage=zd;exports.EntityText=vf;exports.ExpandRow=kb;exports.ExtLink=zb;exports.FEEDBACK_FAB_OFFSET_VAR=as;exports.FILTER_SUPPORT=Fl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=db;exports.FeedbackButton=Mg;exports.FeedbackDialog=md;exports.FeedbackForm=ud;exports.FeedbackList=hd;exports.FeedbackTab=fd;exports.FilterChip=xc;exports.GUJI_MARKDOWN_FIELD=qp;exports.GUJI_TABLE_NOTATION=zc;exports.GlyphBadge=Rs;exports.GujiInteractiveReader=gg;exports.GujiTable=Ms;exports.GujiTextViewer=Zs;exports.GujiWarpCanvas=Ys;exports.ImagePanel=Vr;exports.IndexBrowser=dp;exports.IntroGrid=cb;exports.LAYOUTS=O0;exports.LAYOUT_STORAGE_KEY=or;exports.LOSS_OPTIONS=Ol;exports.LocaleProvider=ou;exports.LocaleToggle=us;exports.META_HOME_CSS=Qd;exports.META_HOME_SECTION_IDS=gm;exports.MetaCatalogTable=lm;exports.MetaCollectionGroups=um;exports.MetaDataLicense=fm;exports.MetaHomeView=z0;exports.MetaLine=vt;exports.MetaLineageCards=bm;exports.MetaOnlineSites=hm;exports.MetaPeopleTimeline=pm;exports.MetaRecentPanel=om;exports.MetaRelatedCatalogs=dm;exports.MetaTypeChips=nm;exports.ModeIndicator=wl;exports.MoreButton=pb;exports.MoreLink=Cs;exports.PAGE_MAX_WIDTH=_n;exports.PERIOD_NARROW_SHARE=Dd;exports.PageFrame=Hi;exports.Quote=vb;exports.READER_CSS=Zl;exports.READ_HOME_CSS=co;exports.READ_HOME_NARROW_QUERY=rn;exports.READ_HOME_SECTION_IDS=Zd;exports.READ_PERIOD_LABELS=x0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Tl;exports.ReadButton=Zr;exports.ReadFamousWorks=qd;exports.ReadHomeView=j0;exports.ReadPeriodBand=Xd;exports.ReadPicks=Kd;exports.ReadPieces=Jd;exports.ReadSection=Rt;exports.ReadShelf=uo;exports.ReadSibu=po;exports.ReadStats=Ud;exports.ReadTopicGroup=Vd;exports.ReadTopics=Gd;exports.ReaderMdText=Os;exports.ReaderShell=sc;exports.ReaderToc=Ql;exports.RepoSourceLink=ps;exports.ResourceGroup=Sb;exports.ResourceLine=$b;exports.ResourceList=mu;exports.ResourceRow=Sc;exports.SEARCH_VIEW_STORAGE_KEY=ws;exports.SEVEN_PAVILIONS_KEY=mm;exports.SNIPPET_MARK_END=yl;exports.SNIPPET_MARK_START=xl;exports.SORTABLE_TYPES=Pl;exports.SearchInput=Sl;exports.SearchResults=Kl;exports.Sec=_t;exports.SectionHead=mb;exports.SideList=di;exports.StripWarpRenderer=ts;exports.SummaryCard=Qi;exports.THEMES=ym;exports.THEME_INIT_SCRIPT=W0;exports.THEME_STORAGE_KEY=rr;exports.TabFilter=qn;exports.TableHead=gb;exports.TableRow=xb;exports.TagRow=$c;exports.TagRows=_b;exports.TextButton=ub;exports.TextReader=cd;exports.ThemeToggle=K0;exports.TopStrip=Qr;exports.VersionLineageGraph=vd;exports.VersionLineageList=wd;exports.VersionLineageView=so;exports.VolumeChips=hb;exports.VolumeLinks=Ts;exports.WorkCard=Md;exports.WorkCardGrid=Pd;exports.WorkCatalog=xg;exports.WorkPage=kd;exports.WorkRow=Ad;exports.adaptEntityJson=Bc;exports.applyLayout=H0;exports.applyTheme=wm;exports.authorsLine=ir;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Ps;exports.bucketResources=gs;exports.buildCatalogTree=s0;exports.buildCollectionTable=Al;exports.buildLineageGraph=wn;exports.buildMeiliFilter=Ku;exports.buildParagraphBlocks=Ac;exports.buildVersionRow=El;exports.buildVersionTable=Rl;exports.canParagraphize=Mn;exports.catalogNodeIdOf=n0;exports.catalogNodeIdsOf=r0;exports.catalogPageCount=c0;exports.catalogTotal=lo;exports.classificationPath=nn;exports.clearAllRecentIds=vs;exports.compareCatalogCards=l0;exports.computeVersionPartition=Lu;exports.countActiveFilters=Gn;exports.createFeedbackTransport=to;exports.createTextApi=ql;exports.currentLayout=D0;exports.currentTheme=vm;exports.defaultEntityHref=Jc;exports.defaultWorkLink=Td;exports.deriveDating=Cu;exports.deriveEditionType=Ll;exports.deriveEra=Ji;exports.deriveYear=Dn;exports.deriveYearRange=fs;exports.detectGenre=Jn;exports.displayAuthorRole=ys;exports.eraRank=Ur;exports.feedbackTransportOf=dd;exports.filtersFromParams=Yu;exports.filtersToParams=In;exports.findCatalogPath=wi;exports.firstAuthorText=mo;exports.flattenTitles=_c;exports.flattenToc=rc;exports.fmtCount=jt;exports.formatHitCount=vn;exports.formatVolumeRange=Un;exports.groupRelatedWorks=Eu;exports.gujiInlineToPlain=uc;exports.hasActiveFilters=Bl;exports.hasGujiMarkdownV02=Xp;exports.hasGujiTableNotation=Cb;exports.hasSearchOptions=Du;exports.headingKey=eo;exports.headingsFromPunct=rd;exports.isCountedChar=Fs;exports.isDuiduChapter=Cn;exports.isLayoutName=Sm;exports.isThemeName=jm;exports.lineageHref=tm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Wc;exports.nestHeadings=od;exports.normalizeEra=Tt;exports.normalizeLayout=ar;exports.normalizeRole=xs;exports.normalizeTheme=sr;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Vi;exports.paginationItems=Ed;exports.parseChineseNumber=Rn;exports.parseGujiInline=mc;exports.parseGujiTable=Ec;exports.parseHeadingKey=sd;exports.pct=bo;exports.periodLevel=Hd;exports.pickReaderVersion=nc;exports.readStoredLayout=F0;exports.readStoredTheme=P0;exports.readerVersionOptionLabel=Xr;exports.remapPlainOffsets=Hc;exports.removeRecentId=Yl;exports.renderFullTextBody=Fb;exports.renderProperNames=Oc;exports.renderReaderInline=Zn;exports.resolveRecentEntry=Ss;exports.resourceNote=Wn;exports.resultTabFromParam=ip;exports.resultTabToParam=np;exports.roleFacets=Il;exports.rowNo=yb;exports.sameFilters=Vu;exports.sanitizeHeadings=os;exports.saveRecentId=Kr;exports.segmentEntities=Dc;exports.setImageSourceResolver=ff;exports.shelfColumns=Fd;exports.sortFor=Wu;exports.sortYear=Tn;exports.spineHeight=Bd;exports.splitFullTextTables=Is;exports.splitHighlightSnippet=bs;exports.splitTableRow=Cc;exports.storeLayout=B0;exports.storeTheme=km;exports.summaryFromEntry=Gc;exports.summaryFromItem=Vc;exports.timelineLayout=im;exports.toCatalogWorkCard=a0;exports.transportSummaryLoader=qc;exports.typeSupportsFilters=Hl;exports.useBidUrl=It;exports.useChapterWarpData=nd;exports.useConvert=gt;exports.useEntitySummaryLoader=qs;exports.useI18n=oe;exports.useReaderPrefs=ic;exports.useRecentEntries=rm;exports.validateLineageGraph=ju;exports.withDefaultLinks=ti;exports.withMetaLinks=ii;exports.yearText=On;
|
|
2117
|
+
`,em={item:e=>`/item/${encodeURIComponent(e)}`,node:e=>`/catalog?node=${encodeURIComponent(e)}`};function ii(e){return{...em,...e??{}}}function tm(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 bo(e,i){return!i||i<=0?0:Math.max(0,Math.min(100,Math.round(e/i*100)))}function im(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 On(e,i=r.getT("zh-Hant")){return e<0?i("metaHome.yearBC",{n:-e}):String(e)}function v0(e){return{read:e.item,work:e.item,node:e.node}}function nm({counts:e,links:i}){const{t:n}=oe(),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 rm(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=>Ss(e,d))).then(d=>{a||s(d.filter(c=>!c.notFound))}),()=>{a=!0}},[e,i]);const o=b.useCallback(()=>{vs(),s([])},[]);return{entries:n,clear:o}}function S0(e,i,n){const s=e.type==="book"?e.edition||e.era:e.type==="collection"?"":e.dynasty;return s?n(s):sm(e.type,i)}function sm(e,i){return i(`metaHome.typeLabel.${e}`)}function om({entries:e,onClear:i,links:n}){const{t:s,convert:o}=oe(),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?sm(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:S0(l,s,o)})]})},l.id))}),e&&e.length===0&&t.jsx("p",{className:"bim-mh-recent-empty",children:s("metaHome.recentEmpty")})]})}function am(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 lm({rows:e,links:i}){const{t:n,convert:s}=oe(),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=bo(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:am(a.status,n,s)})})]},a.id||a.name)})})]})}):null}function cm({items:e,links:i,label:n}){const{convert:s}=oe();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 dm({works:e,links:i}){const{t:n}=oe(),[s,o]=b.useState(!1);if(!e.length)return null;const a=qi(e.length);return t.jsxs("div",{className:"bim-rh-grp","data-cap":a?"":void 0,"data-open":s?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[n("metaHome.relatedTitle"),t.jsx("small",{children:n("metaHome.relatedNote")})]}),t.jsx(cm,{items:e.map(l=>({id:l.id,title:l.title,sub:ir(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 mm="siku_qige";function $0({group:e,links:i}){const{t:n,convert:s}=oe(),[o,a]=b.useState(!1);return t.jsxs("div",{className:"bim-rh-grp","data-cap":qi(e.items.length)?"":void 0,"data-open":o?"":void 0,children:[t.jsxs("h3",{className:"bim-rh-gt",children:[s(e.label),t.jsx("small",{className:"bim-rh-num",children:n("metaHome.nKinds",{n:e.items.length})})]}),t.jsx(cm,{items:e.items,links:i,label:e.label}),qi(e.items.length)&&t.jsx("button",{type:"button",className:"bim-rh-expand","aria-expanded":o,onClick:()=>a(l=>!l),children:o?n("action.collapse"):n("metaHome.allNKinds",{n:e.items.length})})]})}function um({groups:e,links:i}){const{t:n,convert:s}=oe(),o=ii(i);if(!e.length)return null;const a=e.find(c=>c.key===mm),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($0,{group:c,links:o},c.key))})]})}const pl=34,bl=13;function hl(e,i){return e.birth_year==null&&e.death_year==null?"":`${e.birth_year!=null?On(e.birth_year,i):"?"}–${e.death_year!=null?On(e.death_year,i):"?"}`}function _0(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 pm({people:e,links:i}){const{t:n,convert:s}=oe(),o=ii(i);if(!e.length)return null;const{min:a,max:l,placed:d,missing:c}=im(e),m=[],p=d.map(u=>{const f=u.left>70,g=f?Math.min(u.left,u.left+u.width-bl):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,bl),{...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*pl+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*pl+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:hl(u.p,n)})]})]},u.p.id))}),t.jsx("div",{className:"bim-mh-tl-axis","aria-hidden":"true",children:_0(a,l).map(u=>t.jsx("span",{style:{left:`${(u-a)/h*100}%`},children:On(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):"",hl(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 N0=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 bm({works:e,links:i}){const{t:n,convert:s}=oe(),o=ii(i);return e.length?t.jsx("ul",{className:"bim-mh-lin",children:e.map(a=>{const l=ir(a);return t.jsx("li",{children:t.jsxs("a",{href:tm(o,a.id),children:[N0,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 hm({sites:e}){const{t:i,convert:n}=oe(),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=bo(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:am(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 fl=["extant","partially_extant","lost","unknown"];function fm({stats:e,links:i,version:n,repoUrl:s,downloadHref:o}){const{t:a}=oe(),l=["works","books","collections","entities","has_image","has_text","article","poem"].map(m=>[e[m],a(`metaHome.stat.${m}`)]).filter(([m])=>m>0),d=i==null?void 0:i.loss,c=fl.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:fl.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 gm={zhi:"zhi",sibu:"sibu",cong:"cong",people:"people",lineage:"lineage",sites:"sites",data:"data"};function z0({sections:e,links:i,head:n,transport:s,catalogHref:o,collectionsHref:a,entitiesHref:l,version:d,repoUrl:c,downloadHref:m,className:p}){var $,_;const{t:h}=oe(),u=e,f=ii(i),g=v0(f),y=gm,v=rm(s),k={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(N=>k[N]),j=N=>h(`metaHome.nav.${N}`),S=(N,I)=>N?t.jsx("a",{className:"bim-rh-more",href:N,children:I}):void 0;return t.jsxs("div",{className:p?`bim-rh bim-mh ${p}`:"bim-rh bim-mh",children:[t.jsx("style",{children:co+Qd}),t.jsxs("div",{className:"bim-mh-head",children:[t.jsxs("div",{className:"bim-mh-q",children:[n,t.jsx(nm,{counts:u.counts,links:i})]}),s&&t.jsx(om,{entries:v.entries,onClear:v.clear,links:i})]}),x.length>1&&t.jsx("nav",{className:"bim-rh-secnav","aria-label":h("metaHome.navLabel"),children:t.jsx("ul",{children:x.map(N=>t.jsx("li",{children:t.jsx("a",{href:`#${y[N]}`,children:j(N)})},N))})}),t.jsxs("div",{className:"bim-rh-main",children:[k.zhi&&t.jsxs(Rt,{id:y.zhi,title:j("zhi"),sub:h("metaHome.zhiSub"),children:[u.shelf&&u.shelf.items.length>0&&t.jsx(uo,{topic:{key:"shelf",label:u.shelf.label,shelf:!0,items:u.shelf.items},links:g,showTitle:!1,legendCount:u.shelf.items.some(N=>N.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:(_=u.shelf)!=null&&_.items.length?void 0:{marginTop:0},children:[t.jsx(lm,{rows:u.catalog_progress,links:i}),t.jsx(dm,{works:u.related_catalogs,links:i})]})]}),k.sibu&&t.jsx(Rt,{id:y.sibu,title:j("sibu"),sub:h("metaHome.sibuSub"),more:S(o,h("metaHome.toCatalog")),children:t.jsx(po,{bu:u.bu,unclassified:u.unclassified,links:g,unclassifiedNote:h("metaHome.unclassifiedNote")})}),k.cong&&t.jsx(Rt,{id:y.cong,title:j("cong"),sub:h("metaHome.congSub"),more:S(a,h("metaHome.allNKindsMore",{n:jt(u.counts.collections)})),children:t.jsx(um,{groups:u.collection_groups,links:i})}),k.people&&t.jsx(Rt,{id:y.people,title:j("people"),sub:h("metaHome.peopleSub"),more:S(l,h("metaHome.allNPeopleMore",{n:jt(u.counts.entities)})),children:t.jsx(pm,{people:u.bibliographers,links:i})}),k.lineage&&t.jsx(Rt,{id:y.lineage,title:j("lineage"),sub:h("metaHome.lineageSub"),children:t.jsx(bm,{works:u.lineage,links:i})}),k.sites&&t.jsx(Rt,{id:y.sites,title:j("sites"),sub:h("metaHome.sitesSub"),children:t.jsx(hm,{sites:u.sites})}),t.jsx(Rt,{id:y.data,title:j("data"),sub:h("metaHome.dataSub"),children:t.jsx(fm,{stats:u.stats,links:i,version:d,repoUrl:c,downloadHref:m})})]})]})}const xm=["_related","_catalogs","_collections","_members","_children"],C0=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ms=e=>C0(e)&&!!e.h;function E0(e){return e?xm.some(i=>{const n=e[i];return Array.isArray(n)&&n.some(ms)}):!1}function R0(e,i){const n={...e};if(!i)return n;for(const s of xm){const o=e[s];!Array.isArray(o)||!o.some(ms)||(n[s]=o.map(a=>{var c;if(!ms(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 T0(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&&R0(d,E0(d)?await n():null)};const a=Reflect.get(s,o,s);return typeof a=="function"?a.bind(s):a}})}const us=({style:e})=>{const i=b.useContext(r.LocaleContext),{t:n}=oe();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")})]})},ps=({href:e,label:i,size:n=16,className:s,style:o})=>{const{t:a}=oe(),l=i??a("common.repoSourceLink");return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",title:l,"aria-label":l,className: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 Dr(e){const i=e.text_count;return typeof i=="number"&&i>0}function Wr(e,i){return{id:e,title:i.title??i.primary_name??e,type:i.type??"book"}}function I0(e,i){if(!i)return!1;const n=i.id;return n===void 0||n===e}const M0=({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:v,renderLink:k,assetBase:x,enrichDetail:j,getSourceLink:S,readLink:$,railTop:_,extraTabs:N=[],showFeedbackTab:I=!0,feedbackApiUrl:D,height:E,footerExtra:R,hideHeaderControls:O=!1,className:M,style:q})=>{const P=b.useMemo(()=>T0(i),[i]),le=b.useMemo(()=>dd(P)??to(D),[P,D]),ae=r.useT(),{t:Ce,convert:xe}=oe(),[fe]=b.useState(()=>{if(!I0(e,n))return null;const J={...n},ve=s??Wr(e,J);return j&&j(ve,J),{id:e,entry:ve,detail:J}}),[se,Re]=b.useState((fe==null?void 0:fe.entry)??null),[H,me]=b.useState((fe==null?void 0:fe.detail)??null),[W,K]=b.useState(!fe),[re,Y]=b.useState(!1),[T,ue]=b.useState([]),[ye,Ne]=b.useState(!1),[B,de]=b.useState(null),[Me,Se]=b.useState(null),[Je,X]=b.useState(null),[je,L]=b.useState(!1),G=b.useRef(null),ie=b.useRef(0),[te,ce]=b.useState(null),be=l!==void 0?l:te,Fe=b.useCallback(J=>{d?d(J):ce(J)},[d]),Xe=b.useCallback(async J=>{if(!P.getCollectionCatalogs&&!P.getCollectionCatalog){ue([]);return}Ne(!0);try{if(P.getCollectionCatalogs)ue(await P.getCollectionCatalogs(J)||[]);else if(P.getCollectionCatalog){const ve=await P.getCollectionCatalog(J);ue(ve?[{resource_id:"",data:ve}]:[])}}catch{ue([])}finally{Ne(!1)}},[P]),Be=b.useCallback(async J=>{var ve,Qe;if(!P.getTextManifest||!P.getTextIndex){de(null),Se(J);return}try{const et=_e.pickTextVersion(await P.getTextManifest(J)),We=et?await P.getTextIndex(J,et.key):null;de(We&&We.chapters.length>0?{chapters:We.chapters.map(He=>({n:He.n,title:He.title,file:He.file})),source:{name:((ve=We.source)==null?void 0:ve.name)??(et==null?void 0:et.source_name),license:((Qe=We.source)==null?void 0:Qe.license)??(et==null?void 0:et.license)??void 0}}:null)}catch{de(null)}finally{Se(J)}},[P]),Ke=b.useCallback(async(J,ve)=>{const Qe=++ie.current,et=()=>Qe!==ie.current;L(!0);try{if(P.getLineageGraph){const ft=await P.getLineageGraph(J);if(et())return;ft&&X(ft)}const We=ve.version_graph;if(!We||!We.enabled){Je||X(null),G.current=null;return}const He=js(ve),pt=(await er(He,Qn,async ft=>{try{return await P.getItem(ft)}catch{return null}},et)).filter(Boolean);if(et())return;G.current={work:ve,books:pt};const bt=p??We.default_collection??(We.core_books&&We.core_books.length>0?"core":"all"),Ue=bt==="core"&&Array.isArray(We.core_books)&&We.core_books.length>0?"core":bt??"all";X(wn(ve,pt,Ue))}catch{if(et())return;X(null),G.current=null}finally{et()||L(!1)}},[P]),Ye=b.useRef({initialDetail:n,initialEntry:s});Ye.current={initialDetail:n,initialEntry:s},b.useEffect(()=>{let J=!1;ie.current++,L(!1);const ve=He=>{He.type==="collection"?Xe(e):He.type==="work"?(He.version_graph||P.getLineageGraph)&&Ke(e,He):He.type==="book"&&Dr(He)&&Be(e)},Qe=Ye.current;let et=null;if(fe&&fe.id===e)et=fe;else if(Qe.initialDetail&&Qe.initialDetail.id===e){const He={...Qe.initialDetail},ut=Qe.initialEntry??Wr(e,He);j&&j(ut,He),et={entry:ut,detail:He}}return et?(Y(!1),ue(He=>He.length?[]:He),de(null),X(null),G.current=null,Re(et.entry),me(et.detail),K(!1),ve(et.detail),()=>{J=!0}):((async()=>{K(!0),Y(!1),Re(null),me(null),ue([]),de(null),X(null),G.current=null;try{const He=await P.getItem(e);if(J)return;if(!He){Y(!0);return}const ut=He;let pt=null;if(P.getEntry&&(pt=await P.getEntry(e),J))return;pt||(pt=Wr(e,ut)),j&&j(pt,ut),Re(pt),me(ut),ve(ut)}catch{J||Y(!0)}finally{J||K(!1)}})(),()=>{J=!0})},[e,P,fe,j,Xe,Ke,Be]),b.useEffect(()=>{const J=G.current;!J||!p||X(wn(J.work,J.books,p))},[p]);const w=[];if(H){if(w.push({key:"basic",label:ae.detailTab.basicInfo}),H.type==="collection"){ye&&T.length===0&&w.push({key:"catalog:loading",label:`${ae.detailTab.catalog}…`});for(const J of T)w.push({key:`catalog:${J.resource_id}`,label:J.short_name?`${xe(J.short_name)}${ae.detailTab.catalogSuffix}`:ae.detailTab.collectionCatalog})}(o==="collated"||o==="fulltext")&&w.push({key:o,label:ae.detailTab.fullText}),H.type==="work"&&(Je||je)&&w.push({key:"lineage",label:je?`${ae.detailTab.lineage}…`:ae.detailTab.lineage});for(const J of N)(J.position??"before-feedback")==="before-feedback"&&J.shouldShow(H)&&w.push({key:J.key,label:J.label});I&&o==="feedback"&&w.push({key:"feedback",label:ae.detailTab.feedback});for(const J of N)J.position==="after-feedback"&&J.shouldShow(H)&&w.push({key:J.key,label:J.label})}b.useEffect(()=>{if(o!=="emendated"||!H)return;a("basic");const J=setTimeout(()=>{var ve;(ve=document.getElementById("studies"))==null||ve.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(J)},[o,H,a]);const ee=se&&H&&S?S({activeTab:o,activeJuan:be,entry:se,detail:H}):null,Z=b.useMemo(()=>{var We,He,ut,pt,bt;if(!H)return null;const ve=(H.authors??[]).map(Ue=>{const ft=ys(Ue.role);return`${Ue.dynasty?`〔${xe(Ue.dynasty)}〕`:""}${xe(Ue.name)}${ft?` ${xe(ft)}`:""}`}).join(" · ");let Qe=!1;try{Qe=_e.extractStatus(H.id)==="draft"}catch{}if(H.type==="book"){const Ue=H;return{title:xe(Ue.title),subtitle:Ue.edition?xe(Ue.edition):ve||void 0,aside:[Qe?ae.status.draft:"",ve&&Ue.edition?ve:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(H.type==="collection"){const Ue=H;return{title:xe(Ue.title),subtitle:xe(qt(Ue,ae.unit.juan))||void 0,aside:[(We=Ue.publication_info)==null?void 0:We.year,Qe?ae.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:ve||void 0}}if(H.type==="entity"){const Ue=H,ft=A=>A==null?"":A<0?Ce("detail.bce",{n:-A}):String(A),Q=((He=Ue.dates)==null?void 0:He.birth)!=null||((ut=Ue.dates)==null?void 0:ut.death)!=null?`${ft(((pt=Ue.dates)==null?void 0:pt.birth)??void 0)||"?"}—${ft(((bt=Ue.dates)==null?void 0:bt.death)??void 0)||"?"}`:"";return{title:xe(Ue.primary_name||Ue.title),subtitle:[Ue.dynasty?`〔${xe(Ue.dynasty)}〕`:"",Q].filter(Boolean).join(" ")||void 0,aside:Qe?ae.status.draft:void 0,secondLine:void 0}}const et=xe(qt(H,ae.unit.juan));return{title:xe(H.title),subtitle:[et,ve].filter(Boolean).join(" · ")||void 0,aside:[L0(ae,H.subtype),Qe?ae.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[H,xe,ae,Ce]),he=H&&Dr(H)?"text":null,Le=()=>{Fe(null),a("fulltext")};let C=null;if(H&&$){const J=$({detail:H,kind:he});J&&(C=t.jsx(Zr,{href:J}))}else he&&(C=t.jsx(Zr,{onClick:Le}));const ge=J=>{if(!H)return null;const ve=J.replace(/\.[^.]+$/,"");if($){const Qe=$({detail:H,kind:he,juan:ve});return Qe?{href:Qe}:null}return{onClick:()=>{Fe(ve),a("fulltext")}}},V=new Set(N.map(J=>J.key)),ze=w.filter(J=>J.key.startsWith("catalog:")&&J.key!=="catalog:loading"||J.key==="lineage"&&!!Je&&!je||V.has(J.key)).map(J=>({key:J.key,label:J.label,onClick:()=>a(J.key)})),we=()=>{var J;return H?H.type==="work"?t.jsx(kd,{data:H,transport:P,onNavigate:g,renderLink:k,readAction:C,railTop:_,railLinks:ze}):H.type==="book"?t.jsx(Sd,{data:H,transport:P,onNavigate:g,renderLink:k,readAction:C,fullText:B,fullTextPending:Dr(H)&&!!P.getTextManifest&&Me!==H.id,chapterLink:ge,railTop:_,railLinks:ze}):H.type==="collection"?t.jsx($d,{data:H,catalog:(J=T[0])==null?void 0:J.data,transport:P,onNavigate:g,renderLink:k,readAction:C,railTop:_,railLinks:ze,catalogAction:T.length>0?t.jsxs("a",{href:"#catalog",onClick:ve=>{ve.preventDefault(),a(`catalog:${T[0].resource_id}`)},children:[xe(ae.detailTab.collectionCatalog)," →"]}):null}):t.jsx(zd,{data:H,transport:P,onNavigate:g,renderLink:k,railTop:_,railLinks:ze,assetBase:x}):null},Te=()=>{var ve,Qe,et;if(!se||!H)return null;if(o==="basic"||o==="emendated")return we();if(typeof o=="string"&&o.startsWith("catalog:")){const We=(ve=T.find(He=>`catalog:${He.resource_id}`===o))==null?void 0:ve.data;return t.jsx(Gl,{data:We,onNavigate:g,renderLink:k})}if(o==="collated"||o==="fulltext")return t.jsx(cd,{id:e,transport:P,chapter:be,onLocationChange:We=>Fe(We.chapter),onNavigate:g});if(o==="lineage"){if(!Je)return t.jsx("div",{style:{color:r.bim("label-fg"),padding:"24px 0"},children:Ce(je?"detail.loading":"detail.noLineageGraph")});const We=H.type==="work"?H:null;return t.jsx(so,{graph:Je,renderLink:k,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:c,onModeChange:m,selectedNodeId:f,collection:p??((Qe=We==null?void 0:We.version_graph)==null?void 0:Qe.default_collection),onCollectionChange:h,collectionsAvailable:(et=We==null?void 0:We.version_graph)==null?void 0:et.collections,collectionCounts:(()=>{var bt,Ue,ft,Q,A,ne,$e;if(!We)return;const He={},ut=((bt=G.current)==null?void 0:bt.books)??[];He.all=(((Ue=We._books)==null?void 0:Ue.length)??0)-(((Q=(ft=We.version_graph)==null?void 0:ft.excluded_books)==null?void 0:Q.length)??0);const pt=(A=We.version_graph)==null?void 0:A.collections;if(pt)for(const Ie of Object.keys(pt))He[Ie]=wn(We,ut,Ie).nodes.filter(Oe=>Oe.kind==="book"&&!Oe.bridge).length;return He.core==null&&(($e=(ne=We.version_graph)==null?void 0:ne.core_books)!=null&&$e.length)&&(He.core=We.version_graph.core_books.length),He})()})}if(o==="feedback"&&I)return t.jsx(fd,{resourceId:e,transport:le});const J=N.find(We=>We.key===o);return J?J.render({detail:H,entry:se,transport:P,onNavigate:g}):null};if(W)return t.jsx(Hi,{style:{minHeight:E,...q},children:t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((J,ve)=>t.jsx("div",{style:{height:ve===1?40:16,width:J,opacity:.35,background:r.bim("rule")}},ve))})});if(re||!H||!se||!Z)return t.jsx(Hi,{style:{minHeight:E,...q},children:t.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:r.bim("label-fg"),fontSize:14},children:Ce("detail.notFound")})});const tt=o==="basic"||o==="emendated",Pe=[{label:v??ae.detailTab.backToIndex,onClick:y}];if(H.type==="book"&&H.work_id){const J=H.work_id;Pe.push({label:ae.indexType.work,id:J,onClick:()=>g==null?void 0:g(J)})}Pe.push({label:ae.indexType[H.type]});const it=o==="collated"||o==="fulltext",yt=typeof R=="string"?ae.status[R.trim()]??R:R,De=t.jsx(Nc,{left:t.jsxs(t.Fragment,{children:[yt,yt?" · ":"",t.jsx(A0,{id:H.id,label:ae.label.id,copied:ae.action.copied,copyLabel:ae.action.copy})]}),right:t.jsxs(t.Fragment,{children:[I&&!tt&&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:ae.detailTab.submitVersion}),ee&&t.jsx("a",{href:ee.href,target:"_blank",rel:"noopener noreferrer",className:"bim-d-hit",style:{color:r.bim("meta-fg")},children:ae.detailTab.dataLicense})]})});return tt?t.jsx("div",{className:M,children:t.jsxs(Hi,{grid:!0,style:{minHeight:E,...q},children:[t.jsx(Qr,{breadcrumb:t.jsx(es,{items:Pe}),actions:t.jsxs(t.Fragment,{children:[!O&&t.jsx(us,{style:{border:"none",background:"transparent"}}),!O&&ee&&t.jsx(ps,{...ee})]})}),we(),De]})}):t.jsx("div",{className:M,children:t.jsxs(Hi,{wide:it,style:{minHeight:E,...q},children:[t.jsx(Qr,{breadcrumb:t.jsxs(t.Fragment,{children:[t.jsx(Rs,{char:"籍"}),t.jsx(es,{items:Pe})]}),actions:t.jsxs(t.Fragment,{children:[!O&&t.jsx(us,{}),I&&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:ae.detailTab.feedback}),!O&&ee&&t.jsx(ps,{...ee})]})}),t.jsx(gc,{...Z,aside:it?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")," →"]}):Z.aside}),!it&&w.length>1&&t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:w.map(J=>t.jsx(xc,{label:J.label,active:J.key===o||tt&&J.key==="basic",onClick:()=>a(J.key)},J.key))}),t.jsx("div",{style:{marginTop:!it&&w.length>1?8:0},children:Te()}),De]})})};function A0({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 L0(e,i){return i?e.workSubtype[i]??i:""}const ym=[{name:"zhusha",label:"朱砂"},{name:"indigo",label:"靛青"},{name:"ink",label:"墨"}],nr="zhusha",rr="bim-theme";function jm(e){return e==="zhusha"||e==="indigo"||e==="ink"}function sr(e){return jm(e)?e:nr}function P0(){try{return sr(window.localStorage.getItem(rr))}catch{return nr}}function km(e){try{window.localStorage.setItem(rr,e)}catch{}}function wm(e){const i=sr(e);return document.documentElement.setAttribute("data-theme",i),i}function vm(){return sr(document.documentElement.getAttribute("data-theme"))}const O0=[{name:"airy",label:"疏朗",hint:"留白分区"},{name:"boxed",label:"界欄",hint:"框線分區"}],ho="airy",or="bim-layout";function Sm(e){return e==="airy"||e==="boxed"}function ar(e){return Sm(e)?e:ho}function F0(){try{return ar(window.localStorage.getItem(or))}catch{return ho}}function B0(e){try{window.localStorage.setItem(or,e)}catch{}}function H0(e){const i=ar(e);return document.documentElement.setAttribute("data-layout",i),i}function D0(){return ar(document.documentElement.getAttribute("data-layout"))}const W0=`try{var t=localStorage.getItem(${JSON.stringify(rr)});if(t==='indigo'||t==='ink')document.documentElement.setAttribute('data-theme',t);if(localStorage.getItem(${JSON.stringify(or)})==='boxed')document.documentElement.setAttribute('data-layout','boxed')}catch(e){}`,U0={zhusha:"theme-dot-zhusha",indigo:"theme-dot-indigo",ink:"theme-dot-ink"},K0=({onChange:e,style:i})=>{const{t:n}=oe(),[s,o]=b.useState(nr);b.useEffect(()=>{o(vm())},[]);const a=l=>{o(wm(l)),km(l),e==null||e(l)};return t.jsx("div",{role:"radiogroup","aria-label":n("common.themeLabel"),style:{display:"inline-flex",alignItems:"center",...i},children:ym.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(U0[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=_e.BidLink;exports.BookIndexError=_e.BookIndexError;exports.BookIndexManager=_e.BookIndexManager;exports.BookIndexStorage=_e.BookIndexStorage;exports.BundleStorage=_e.BundleStorage;exports.ConfigError=_e.ConfigError;exports.GithubStorage=_e.GithubStorage;exports.IdGenerationError=_e.IdGenerationError;exports.IdGenerator=_e.IdGenerator;exports.LocalStorage=_e.LocalStorage;exports.MigrationError=_e.MigrationError;exports.StorageError=_e.StorageError;exports.adaptCharCord=_e.adaptCharCord;exports.adaptFig=_e.adaptFig;exports.adaptNorm=_e.adaptNorm;exports.adaptNormDetailed=_e.adaptNormDetailed;exports.adaptPunctJson=_e.adaptPunctJson;exports.base36Decode=_e.base36Decode;exports.base36Encode=_e.base36Encode;exports.base58Decode=_e.base58Decode;exports.buildId=_e.buildId;exports.buildPromotionMap=_e.buildPromotionMap;exports.cleanName=_e.cleanName;exports.decodeId=_e.decodeId;exports.decodeIdString=_e.decodeIdString;exports.encodeId=_e.encodeId;exports.extractIdFromUrl=_e.extractIdFromUrl;exports.extractStatus=_e.extractStatus;exports.extractType=_e.extractType;exports.iiifVolumeOf=_e.iiifVolumeOf;exports.isChapterSegment=_e.isChapterSegment;exports.isTextKey=_e.isTextKey;exports.loadFigUrls=_e.loadFigUrls;exports.loadReaderChapter=_e.loadReaderChapter;exports.loadReaderFiles=_e.loadReaderFiles;exports.matchChapterAcrossVersions=_e.matchChapterAcrossVersions;exports.normalizeCatalog=_e.normalizeCatalog;exports.parseId=_e.parseId;exports.pickTextVersion=_e.pickTextVersion;exports.readerManifest=_e.readerManifest;exports.readerVersions=_e.readerVersions;exports.shardOf=_e.shardOf;exports.smartDecode=_e.smartDecode;exports.textVersionLabel=_e.textVersionLabel;exports.validateResource=_e.validateResource;exports.volumeFromChar=_e.volumeFromChar;exports.Badge=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=eu.VARIANT_SUPPLEMENT;exports.BidUrlProvider=iu;exports.BookDetailLayout=M0;exports.BookPage=Sd;exports.Breadcrumb=es;exports.CATALOG_ALL_ID=Vt;exports.CATALOG_CSS=Cd;exports.CATALOG_NARROW_QUERY=oo;exports.CATALOG_PAGE_SIZE=ao;exports.CATALOG_UNCLASSIFIED_ID=ci;exports.CLASSIFICATIONS=Vn;exports.CardFoot=en;exports.CatalogPage=b0;exports.CatalogPager=Ld;exports.CatalogTree=Rd;exports.CheckFilter=bc;exports.Chip=yc;exports.ChipWall=bb;exports.CollectionCatalog=Gl;exports.CollectionPage=$d;exports.DEFAULT_LAYOUT=ho;exports.DEFAULT_META_HOME_LINKS=em;exports.DEFAULT_READER_PREFS=Ns;exports.DEFAULT_READ_HOME_LINKS=Od;exports.DEFAULT_THEME=nr;exports.DETAIL_CSS=fc;exports.DYNASTY_GROUPS=Yn;exports.Dash=jb;exports.DataTable=fb;exports.DetailFooter=Nc;exports.DetailGrid=Zi;exports.DetailHeader=gc;exports.EMPTY_FILTERS=Kn;exports.ENTITY_TEXT_CSS=Vs;exports.EmptyNote=Nb;exports.EntityMark=Xs;exports.EntityPage=zd;exports.EntityText=vf;exports.ExpandRow=kb;exports.ExtLink=zb;exports.FEEDBACK_FAB_OFFSET_VAR=as;exports.FILTER_SUPPORT=Fl;exports.FONT_SIZE_STEPS=Yt;exports.FactList=db;exports.FeedbackButton=Mg;exports.FeedbackDialog=md;exports.FeedbackForm=ud;exports.FeedbackList=hd;exports.FeedbackTab=fd;exports.FilterChip=xc;exports.GUJI_MARKDOWN_FIELD=qp;exports.GUJI_TABLE_NOTATION=zc;exports.GlyphBadge=Rs;exports.GujiInteractiveReader=gg;exports.GujiTable=Ms;exports.GujiTextViewer=Zs;exports.GujiWarpCanvas=Ys;exports.ImagePanel=Vr;exports.IndexBrowser=dp;exports.IntroGrid=cb;exports.LAYOUTS=O0;exports.LAYOUT_STORAGE_KEY=or;exports.LOSS_OPTIONS=Ol;exports.LocaleProvider=ou;exports.LocaleToggle=us;exports.META_HOME_CSS=Qd;exports.META_HOME_SECTION_IDS=gm;exports.MetaCatalogTable=lm;exports.MetaCollectionGroups=um;exports.MetaDataLicense=fm;exports.MetaHomeView=z0;exports.MetaLine=vt;exports.MetaLineageCards=bm;exports.MetaOnlineSites=hm;exports.MetaPeopleTimeline=pm;exports.MetaRecentPanel=om;exports.MetaRelatedCatalogs=dm;exports.MetaTypeChips=nm;exports.ModeIndicator=wl;exports.MoreButton=pb;exports.MoreLink=Cs;exports.PAGE_MAX_WIDTH=_n;exports.PERIOD_NARROW_SHARE=Dd;exports.PageFrame=Hi;exports.Quote=vb;exports.READER_CSS=Zl;exports.READ_HOME_CSS=co;exports.READ_HOME_NARROW_QUERY=rn;exports.READ_HOME_SECTION_IDS=Zd;exports.READ_PERIOD_LABELS=x0;exports.RECENT_IDS_STORAGE_KEY=_i;exports.ROLE_CLASS_ORDER=Tl;exports.ReadButton=Zr;exports.ReadFamousWorks=qd;exports.ReadHomeView=j0;exports.ReadPeriodBand=Xd;exports.ReadPicks=Kd;exports.ReadPieces=Jd;exports.ReadSection=Rt;exports.ReadShelf=uo;exports.ReadSibu=po;exports.ReadStats=Ud;exports.ReadTopicGroup=Vd;exports.ReadTopics=Gd;exports.ReaderMdText=Os;exports.ReaderShell=sc;exports.ReaderToc=Ql;exports.RepoSourceLink=ps;exports.ResourceGroup=Sb;exports.ResourceLine=$b;exports.ResourceList=mu;exports.ResourceRow=Sc;exports.SEARCH_VIEW_STORAGE_KEY=ws;exports.SEVEN_PAVILIONS_KEY=mm;exports.SNIPPET_MARK_END=yl;exports.SNIPPET_MARK_START=xl;exports.SORTABLE_TYPES=Pl;exports.SearchInput=Sl;exports.SearchResults=Kl;exports.Sec=_t;exports.SectionHead=mb;exports.SideList=di;exports.StripWarpRenderer=ts;exports.SummaryCard=Qi;exports.THEMES=ym;exports.THEME_INIT_SCRIPT=W0;exports.THEME_STORAGE_KEY=rr;exports.TabFilter=qn;exports.TableHead=gb;exports.TableRow=xb;exports.TagRow=$c;exports.TagRows=_b;exports.TextButton=ub;exports.TextReader=cd;exports.ThemeToggle=K0;exports.TopStrip=Qr;exports.VersionLineageGraph=vd;exports.VersionLineageList=wd;exports.VersionLineageView=so;exports.VolumeChips=hb;exports.VolumeLinks=Ts;exports.WorkCard=Md;exports.WorkCardGrid=Pd;exports.WorkCatalog=xg;exports.WorkPage=kd;exports.WorkRow=Ad;exports.adaptEntityJson=Bc;exports.applyLayout=H0;exports.applyTheme=wm;exports.authorsLine=ir;exports.bookIndexUriToId=ui;exports.bookMarkingOf=Ps;exports.bucketResources=gs;exports.buildCatalogTree=s0;exports.buildCollectionTable=Al;exports.buildLineageGraph=wn;exports.buildMeiliFilter=Ku;exports.buildParagraphBlocks=Ac;exports.buildVersionRow=El;exports.buildVersionTable=Rl;exports.canParagraphize=Mn;exports.catalogNodeIdOf=n0;exports.catalogNodeIdsOf=r0;exports.catalogPageCount=c0;exports.catalogTotal=lo;exports.classificationPath=nn;exports.clearAllRecentIds=vs;exports.compareCatalogCards=l0;exports.computeVersionPartition=Lu;exports.countActiveFilters=Gn;exports.createFeedbackTransport=to;exports.createTextApi=ql;exports.currentLayout=D0;exports.currentTheme=vm;exports.defaultEntityHref=Jc;exports.defaultWorkLink=Td;exports.deriveDating=Cu;exports.deriveEditionType=Ll;exports.deriveEra=Ji;exports.deriveYear=Dn;exports.deriveYearRange=fs;exports.detectGenre=Jn;exports.displayAuthorRole=ys;exports.eraRank=Ur;exports.feedbackTransportOf=dd;exports.filtersFromParams=Yu;exports.filtersToParams=In;exports.findCatalogPath=wi;exports.firstAuthorText=mo;exports.flattenTitles=_c;exports.flattenToc=rc;exports.fmtCount=jt;exports.formatHitCount=vn;exports.formatVolumeRange=Un;exports.groupRelatedWorks=Eu;exports.gujiInlineToPlain=uc;exports.hasActiveFilters=Bl;exports.hasGujiMarkdownV02=Xp;exports.hasGujiTableNotation=Cb;exports.hasSearchOptions=Du;exports.headingKey=eo;exports.headingsFromPunct=rd;exports.isCountedChar=Fs;exports.isDuiduChapter=Cn;exports.isLayoutName=Sm;exports.isThemeName=jm;exports.lineageHref=tm;exports.loadRecentIds=ei;exports.measureText=qt;exports.mergeDecorations=Wc;exports.nestHeadings=od;exports.normalizeEra=Tt;exports.normalizeLayout=ar;exports.normalizeRole=xs;exports.normalizeTheme=sr;exports.normalizeVolumeIndex=Wi;exports.numberToChinese=Vi;exports.paginationItems=Ed;exports.parseChineseNumber=Rn;exports.parseGujiInline=mc;exports.parseGujiTable=Ec;exports.parseHeadingKey=sd;exports.pct=bo;exports.periodLevel=Hd;exports.pickReaderVersion=nc;exports.readStoredLayout=F0;exports.readStoredTheme=P0;exports.readerVersionOptionLabel=Xr;exports.remapPlainOffsets=Hc;exports.removeRecentId=Yl;exports.renderFullTextBody=Fb;exports.renderProperNames=Oc;exports.renderReaderInline=Zn;exports.resolveRecentEntry=Ss;exports.resourceNote=Wn;exports.resultTabFromParam=ip;exports.resultTabToParam=np;exports.roleFacets=Il;exports.rowNo=yb;exports.sameFilters=Vu;exports.sanitizeHeadings=os;exports.saveRecentId=Kr;exports.segmentEntities=Dc;exports.setImageSourceResolver=ff;exports.shelfColumns=Fd;exports.sortFor=Wu;exports.sortYear=Tn;exports.spineHeight=Bd;exports.splitFullTextTables=Is;exports.splitHighlightSnippet=bs;exports.splitTableRow=Cc;exports.storeLayout=B0;exports.storeTheme=km;exports.summaryFromEntry=Gc;exports.summaryFromItem=Vc;exports.timelineLayout=im;exports.toCatalogWorkCard=a0;exports.transportSummaryLoader=qc;exports.typeSupportsFilters=Hl;exports.useBidUrl=It;exports.useChapterWarpData=nd;exports.useConvert=gt;exports.useEntitySummaryLoader=qs;exports.useI18n=oe;exports.useReaderPrefs=ic;exports.useRecentEntries=rm;exports.validateLineageGraph=ju;exports.withDefaultLinks=ti;exports.withMetaLinks=ii;exports.yearText=On;
|