book-index-ui 0.9.0 → 0.9.1
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 +5 -5
- package/dist/index.js +1211 -1186
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var lo=Object.create;var Un=Object.defineProperty;var ao=Object.getOwnPropertyDescriptor;var co=Object.getOwnPropertyNames;var po=Object.getPrototypeOf,uo=Object.prototype.hasOwnProperty;var xo=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of co(n))!uo.call(t,s)&&s!==i&&Un(t,s,{get:()=>n[s],enumerable:!(r=ao(n,s))||r.enumerable});return t};var dt=(t,n,i)=>(i=t!=null?lo(po(t)):{},xo(n||!t||!t.__esModule?Un(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("./storage-entry-VGdfSKGX.cjs"),e=require("react/jsx-runtime"),g=require("react"),fo=require("react-markdown"),go=require("remark-gfm"),mo=require("react-dom"),ho=t=>`/book-index?id=${t}`,Vi=g.createContext(ho);function bo({buildUrl:t,children:n}){const i=g.useMemo(()=>t,[t]);return e.jsx(Vi.Provider,{value:i,children:n})}function be(){return g.useContext(Vi)}function Ke(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function yo(t,n){return Ke(t).includes(n)}const Gi={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},vo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},jo={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},_t=g.createContext(null),Yi={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},So={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},ko={"zh-Hant":Yi,"zh-Hans":So},Ui="bim-locale";function wo(){try{const t=localStorage.getItem(Ui);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function _o(t){try{localStorage.setItem(Ui,t)}catch{}}const Co="zh-Hans",Io=({locale:t,onLocaleChange:n,children:i})=>{const[r,s]=g.useState(t??Co),o=t??r;g.useEffect(()=>{if(t)return;const p=wo();p&&p!==r&&s(p)},[]);const[l,c]=g.useState(null);g.useEffect(()=>{o==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const x=p.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>p=>p)}):c(null)},[o]);const a=g.useCallback(p=>{s(p),_o(p),n==null||n(p)},[n]),d=g.useMemo(()=>({locale:o,setLocale:a,messages:ko[o],converter:l}),[o,a,l]);return e.jsx(_t.Provider,{value:d,children:i})};function D(){const t=g.useContext(_t);return(t==null?void 0:t.messages)??Yi}const To=2e3;function M(){const t=g.useContext(_t),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,r=g.useRef(new Map),s=g.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const o=g.useCallback(l=>{if(!l)return"";if(!i)return l;const c=r.current.get(l);if(c!==void 0)return c;const a=i(l);if(r.current.size>=To){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[i]);return g.useMemo(()=>({convert:o,locale:n,isSimplified:n==="zh-Hans"}),[o,n])}function Ct(t,n){return t.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function zo(t){if(!t)return"";try{const n=new URL(t).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Ro(){return{id:"",name:"",url:"",type:"text",details:""}}const cn=({items:t,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const o=D(),[l,c]=g.useState(null),a=[{value:"text",label:o.resourceTypeShort.text},{value:"image",label:o.resourceTypeShort.image},{value:"text+image",label:o.resourceTypeShort.textImage},{value:"physical",label:o.resourceTypeShort.physical}],d=[{value:"catalog",label:o.rootType.catalog},{value:"search",label:o.rootType.search}],p=b=>{if(!s)return!0;const j=Ke(b);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=t.map((b,j)=>({item:b,originalIndex:j})).filter(({item:b})=>p(b)),f=()=>{const b=Ro();s&&(b.type=s),n([...t,b]),c(t.length)},u=b=>{n(t.filter((j,w)=>w!==b)),c(null)},h=(b,j,w)=>{const k=[...t];if(k[b]={...k[b],[j]:w},j==="url"&&!k[b].id){const C=zo(w);C&&(k[b].id=C)}n(k)},y=(b,j,w)=>{const C={...t[b].metadata||{}};w?C[j]=w:delete C[j],h(b,"metadata",Object.keys(C).length>0?C:void 0)},m=(b,j)=>{const w=j.trim()?j.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;h(b,"structure",w)},S=(b,j,w)=>{const C=t[b].coverage||{level:1,ranges:""};j==="level"?C.level=parseInt(w)||1:C.ranges=w,h(b,"coverage",C.ranges?C:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:j})=>{var w,k,C;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===j?null:j),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===j?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Eo(b.type??"text"),color:"#fff"},children:(()=>{var _,z;const T=Ke(b);return T.length===0?b.type??"text":T.length===1?((_=a.find(I=>I.value===T[0]))==null?void 0:_.label)??T[0]:T.includes("text")&&T.includes("image")?((z=a.find(I=>I.value==="text+image"))==null?void 0:z.label)??"text+image":T.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${o.editor.resourcePlaceholder} ${j+1}`}),b.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:T=>T.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&b.url&&Bo(j,r==null?void 0:r[j],i,o),e.jsx("button",{onClick:T=>{T.stopPropagation(),u(j)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisResource,children:"✕"})]}),l===j&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[yo(b,"image")&&b.url&&Lo(b,o),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.type}),e.jsx("select",{value:b.type,onChange:T=>h(j,"type",T.target.value),style:{...Re,flex:1},children:a.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]}),e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:T=>h(j,"root_type",T.target.value),style:{...Re,flex:1},children:d.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:b.id,onChange:T=>h(j,"id",T.target.value),placeholder:o.editor.idAutoExtract,style:{...Re,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:T=>h(j,"name",T.target.value),placeholder:o.editor.resourceName,style:{...Re,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:T=>h(j,"url",T.target.value),placeholder:o.editor.resourceUrl,style:Re}),e.jsx("input",{type:"text",value:((w=b.structure)==null?void 0:w.join("、"))||"",onChange:T=>m(j,T.target.value),placeholder:o.editor.structurePlaceholder,style:Re}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=b.coverage)==null?void 0:k.level)??"",onChange:T=>S(j,"level",T.target.value),placeholder:"1",style:{...Re,width:"60px"}})]}),e.jsxs("label",{style:{...pt,flex:1},children:[e.jsx("span",{style:ut,children:o.label.coverageRange}),e.jsx("input",{type:"text",value:((C=b.coverage)==null?void 0:C.ranges)||"",onChange:T=>S(j,"ranges",T.target.value),placeholder:o.editor.coverageRangePlaceholder,style:{...Re,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:T=>h(j,"details",T.target.value),placeholder:o.editor.detailsPlaceholder,style:{...Re,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(o.metadata).map(([T,_])=>{var z;return e.jsxs("label",{style:{...pt,gap:"4px"},children:[e.jsx("span",{style:{...ut,minWidth:"56px"},children:_}),e.jsx("input",{type:"text",value:((z=b.metadata)==null?void 0:z[T])||"",onChange:I=>y(j,T,I.target.value),placeholder:_,style:{...Re,flex:1}})]},T)})})]})]})]})]},j)}),e.jsxs("button",{onClick:f,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addResource})]})]})};function Eo(t){switch(t){case"text":return"var(--bim-restype-text, #2196f3)";case"image":return"var(--bim-restype-image, #ff9800)";case"text+image":return"var(--bim-restype-text-image, #9c27b0)";case"physical":return"var(--bim-restype-physical, #795548)"}}function Bo(t,n,i,r){const s=(n==null?void 0:n.status)==="downloading",o=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:l=>{l.stopPropagation(),s||i(t,"")},disabled:s,style:{background:"transparent",border:"none",color:o?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:o?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:o?"✓":s?"⏳":"⬇"})}function Lo(t,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:i?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"var(--bim-overlay-bg, #00000010)"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const Re={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},pt={display:"flex",alignItems:"center",gap:"6px"},ut={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Wo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function St(t){try{return Wo[new URL(t).hostname]}catch{return}}const Kn={text:0,image:1,physical:2};function bn(t){return t.length===0?"physical":[...t].sort((n,i)=>(Kn[n]??99)-(Kn[i]??99)).join("+")}function yn(t){var l;const n=c=>{const a=c.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=c.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let c=0;c<t.length;c++){const a=t[c];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[p,x]=d,f=`${p}|${bn(Ke(a))}`;i.has(f)||i.set(f,{base:{...a,name:p,url:"",volumes:[]},volumes:[],indices:[]});const u=i.get(f);u.volumes.push({volume:x,url:a.url||void 0,status:"found"}),u.indices.push(c)}const r=[],s=new Set;for(const c of i.values())if(!(c.volumes.length<2)){c.volumes.sort((a,d)=>a.volume-d.volume),c.base.volumes=c.volumes,c.base.expected_volumes=c.volumes.length,c.base.url||(c.base.url=((l=c.volumes.find(a=>a.url))==null?void 0:l.url)??""),r.push(c.base);for(const a of c.indices)s.add(a)}const o=[...r];for(let c=0;c<t.length;c++)s.has(c)||o.push(t[c]);return o}function Ki(t){if(t.url)return t.url;for(const[n,i]of Object.entries(t))if(n.endsWith("_url")&&typeof i=="string")return i}function Ji(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Ki(n)}))}function vn(t){const n=Ji(t);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:t.expected_volumes??i+r}}function jn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function Sn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const r=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Ft(t){if(!t.url)return;const n=jn(t.metadata);return n?Sn(t.url,n):t.url}const Jn={text:"var(--bim-restype-text, #2196f3)",image:"var(--bim-restype-image, #ff9800)","text+image":"var(--bim-restype-text-image, #9c27b0)",physical:"var(--bim-restype-physical, #795548)"};function $o(t){return t.includes("text")&&t.includes("image")?Jn["text+image"]:Jn[t[0]||"physical"]}const kn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const o=D(),{convert:l}=M(),c=g.useMemo(()=>yn(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=g.useMemo(()=>{const m=new Map,S=[];for(const b of c){const j=b.group;j?(m.has(j)||m.set(j,[]),m.get(j).push(b)):S.push(b)}for(const b of m.values())b.sort((j,w)=>{const k=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return k(j)-k(w)});return{mirrorGroups:m,ungroupedItems:S}},[c]),p={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical},x=m=>p[m]?p[m]:m.split("+").map(S=>p[S]||S).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((m,S)=>e.jsx(Qt,{item:m},m.id||S))});const f=(m,S)=>{const b=i==null?void 0:i[m],j=(b==null?void 0:b.label)||m,w=b==null?void 0:b.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(j)}),w&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(w)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((k,C)=>e.jsx(Qt,{item:k,onNavigate:r,renderLink:s},k.id||C))})]},`group-${m}`)},u=new Map;for(const m of d){const S=bn(Ke(m));u.has(S)||u.set(S,[]),u.get(S).push(m)}const h=["text","image","text+image","physical"],y=[...h.filter(m=>u.has(m)),...[...u.keys()].filter(m=>!h.includes(m)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([m,S])=>f(m,S)),y.map(m=>{const S=u.get(m),b=$o(m.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:b,whiteSpace:"nowrap",flexShrink:0},children:x(m)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((j,w)=>e.jsx(Qt,{item:j,onNavigate:r,renderLink:s},j.id||w))})]},m)})]})},Ao={bw:{label:"",bg:"var(--bim-colormode-bw-bg, #f5f5f5)",fg:"var(--bim-colormode-bw-fg, #757575)"},color:{label:"",bg:"var(--bim-colormode-color-bg, #fff8e1)",fg:"var(--bim-colormode-color-fg, #f57f17)"}},Qt=({item:t})=>{const n=D(),{convert:i}=M(),[r,s]=g.useState(!1),o=g.useMemo(()=>(t.url?St(t.url):void 0)||i(t.name),[t.url,t.name,i]),l=g.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||Ki(h)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(l.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,p=t.expected_volumes??(c?a+d:0),x=t.color_mode?{...Ao[t.color_mode],label:n.colorMode[t.color_mode]}:null,f=t.details&&!c?i(t.details):null,u={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:u,children:[e.jsx("span",{style:{fontWeight:500},children:o}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),f&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:f}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",p,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=jn(t.metadata);return h?Sn(t.url,h):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(h=>{const y=h.status==="missing";return h.url&&!y?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:h.volume},h.volume)})})]})},qi=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:o,onSelectFolder:l})=>{const c=D(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",x=p?p.split(/[/\\]/).pop()||p:"",f={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},u={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...f,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...u,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:f,...u,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:f,...u,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:o,title:x||c.mode.configurePath,style:{...f,background:"transparent",padding:"6px",fontSize:"12px"},...u,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:f,...u,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...f,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!a&&x&&e.jsxs("div",{style:{...f,background:"var(--bim-mode-active-bg, #2196f3)",color:"white",cursor:"default"},title:p,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Nt="bim-search-history",qn=10,Xn=8;function bt(){try{const t=localStorage.getItem(Nt);return t?JSON.parse(t):[]}catch{return[]}}function Po(t){try{const n=bt().filter(i=>i!==t);n.unshift(t),n.length>qn&&(n.length=qn),localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Mo(t){try{const n=bt().filter(i=>i!==t);localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Fo(){try{localStorage.removeItem(Nt)}catch{}}const Xi=({transport:t,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:o})=>{const l=D(),c=o??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=g.useState(!1),[x,f]=g.useState([]),[u,h]=g.useState(-1),[y,m]=g.useState(bt),S=g.useRef(null),b=g.useRef(null),j=g.useRef(null),w=g.useRef(!1);g.useEffect(()=>{h(-1);const v=n.trim();if(!v){f(y.map(P=>({type:"history",text:P})));return}if(!t.searchAll){f([]);return}let E=!1;const R=setTimeout(()=>{t.searchAll(v,Xn).then(P=>{if(E)return;const $=[...P.works,...P.books,...P.collections,...P.entities??[]];f($.slice(0,Xn).map(O=>({type:"entry",text:O.title||O.id,entry:O})))}).catch(()=>{E||f([])})},80);return()=>{E=!0,clearTimeout(R)}},[n,y,t]),g.useEffect(()=>{const v=E=>{j.current&&!j.current.contains(E.target)&&p(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),g.useEffect(()=>{const v=E=>{var R,P;if(E.key==="/"&&document.activeElement!==S.current){const $=(R=document.activeElement)==null?void 0:R.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;E.preventDefault(),(P=S.current)==null||P.focus()}};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const k=g.useCallback(v=>{v.trim()&&(Po(v.trim()),m(bt())),r(v),p(!1)},[r]),C=g.useCallback(v=>{v.type==="history"?(i(v.text),k(v.text)):v.entry&&(s?(s(v.entry),p(!1)):(i(v.text),k(v.text)))},[i,k,s]),T=g.useCallback(v=>{if(!d||x.length===0){v.key==="Enter"&&k(n);return}switch(v.key){case"ArrowDown":v.preventDefault(),h(E=>(E+1)%x.length);break;case"ArrowUp":v.preventDefault(),h(E=>(E-1+x.length)%x.length);break;case"Enter":v.preventDefault(),u>=0&&u<x.length?C(x[u]):k(n);break;case"Escape":v.preventDefault(),p(!1);break}},[d,x,u,n,k,C]),_=g.useCallback((v,E)=>{E.stopPropagation(),Mo(v),m(bt()),f(R=>R.filter(P=>!(P.type==="history"&&P.text===v)))},[]),z=g.useCallback(v=>{v.stopPropagation(),Fo(),m([]),f([])},[]);g.useEffect(()=>{if(u>=0&&b.current){const v=b.current.children;v[u]&&v[u].scrollIntoView({block:"nearest"})}},[u]);const I=!n.trim()&&y.length>0;return e.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:c,value:n,onChange:v=>{i(v.target.value),p(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{p(!0)},onKeyDown:T,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:z,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((v,E)=>e.jsxs("div",{onClick:()=>C(v),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:E===u?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:v.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.text}),v.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[v.entry.type],v.entry.edition&&` · ${v.entry.edition}`,v.entry.author&&` · ${v.entry.author}`]}),v.type==="history"&&e.jsx("button",{onClick:R=>_(v.text,R),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${v.type}-${v.text}-${E}`))]})]})},kt="bim-recent-ids",Zn="bim-recent-entries",Qn=50,en=5,Ho=50,Oo=200;function yt(){try{const t=localStorage.getItem(kt);if(t)return JSON.parse(t);const n=localStorage.getItem(Zn);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(kt,JSON.stringify(i)),localStorage.removeItem(Zn),i}return[]}catch{return[]}}function Do(t){try{const n=yt().filter(i=>i!==t);n.unshift(t),n.length>Qn&&(n.length=Qn),localStorage.setItem(kt,JSON.stringify(n))}catch{}}function No(t){try{const n=yt().filter(i=>i!==t);localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Vo(){try{localStorage.removeItem(kt)}catch{}}const Go={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},dn=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:o,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:x,initialQuery:f,onQueryChange:u,headerRight:h})=>{const y=D(),m=[{type:"work",icon:"✍️",name:y.indexType.work,key:"works"},{type:"book",icon:"📖",name:y.indexType.book,key:"books"},{type:"collection",icon:"📚",name:y.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:y.indexType.entity,key:"entities"}],[S,b]=g.useState(f??""),[j,w]=g.useState(null),[k,C]=g.useState(null),[T,_]=g.useState(!1),[z,I]=g.useState(null),[v,E]=g.useState(""),[R,P]=g.useState(!f),[$,O]=g.useState(yt),[A,F]=g.useState([]),[te,W]=g.useState(!1),[Y,ie]=g.useState(!1),[K,L]=g.useState(null),[U,J]=g.useState(null),V=g.useRef(void 0),G=g.useRef(!1),de=g.useCallback(async(N,oe)=>{if(!N.trim()){P(!0),w(null),C(null);return}P(!1),_(!0),E("");try{if(t.searchAll){const ne=await t.searchAll(N,oe??en);w(ne)}else{const ne=["work","book","collection","entity"],B=await Promise.all(ne.map(Q=>t.search(N,Q,{page:1,pageSize:oe??en})));w({works:B[0].entries,books:B[1].entries,collections:B[2].entries,entities:B[3].entries,totalWorks:B[0].total,totalBooks:B[1].total,totalCollections:B[2].total,totalEntities:B[3].total})}}catch(ne){E(ne instanceof Error?ne.message:String(ne)),w(null)}finally{_(!1)}},[t]);g.useEffect(()=>{let N=!1;const oe=()=>{var q,Fe;const ne=["work","book","collection","entity"],B=Promise.all(ne.map(ve=>t.loadEntries(ve,{page:1,pageSize:1}).catch(()=>({total:0})))),Q=((q=t.getResourceCounts)==null?void 0:q.call(t).catch(()=>null))??Promise.resolve(null),le=((Fe=t.getSubtypeStats)==null?void 0:Fe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([B,Q,le]).then(([ve,ge,Qe])=>{N||(L({works:ve[0].total,books:ve[1].total,collections:ve[2].total,entities:ve[3].total,hasText:ge==null?void 0:ge.hasText,hasImage:ge==null?void 0:ge.hasImage}),Qe&&J(Qe))})};return t.getCounts?t.getCounts().then(ne=>{var B,Q;N||(L({works:ne.works,books:ne.books,collections:ne.collections,entities:ne.entities,hasText:(B=ne.resourceCounts)==null?void 0:B.hasText,hasImage:(Q=ne.resourceCounts)==null?void 0:Q.hasImage}),ne.subtypeStats&&J(ne.subtypeStats))}).catch(()=>{N||oe()}):oe(),()=>{N=!0}},[t]),g.useEffect(()=>{G.current||!(f!=null&&f.trim())||(G.current=!0,de(f))},[f,de]);const Se=g.useCallback(N=>{if(b(N),!N.trim()){u==null||u(N),P(!0),w(null),C(null);return}V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{C(null),u==null||u(N),de(N)},Oo)},[de,u]),me=g.useCallback(N=>{V.current&&clearTimeout(V.current),u==null||u(N),de(N)},[de,u]),se=g.useCallback(N=>{C(N),de(S,Ho)},[S,de]);g.useEffect(()=>{if(!$.length){F([]);return}let N=!1;return W(!0),Promise.all($.slice(0,10).map(async oe=>{var ne,B,Q;try{if(t.getEntry){const q=await t.getEntry(oe);if(q)return q}const le=await t.getItem(oe);if(le){const q=le.authors;return{id:oe,title:le.title||oe,type:le.type||"work",author:(ne=q==null?void 0:q[0])==null?void 0:ne.name,dynasty:(B=q==null?void 0:q[0])==null?void 0:B.dynasty,role:(Q=q==null?void 0:q[0])==null?void 0:Q.role,edition:le.edition||void 0}}}catch{}return{id:oe,title:oe,type:"work",notFound:!0}})).then(oe=>{N||(F(oe),W(!1))}),()=>{N=!0}},[$,t]);const ye=N=>{I(N.id),Do(N.id),O(yt()),r==null||r(N)},Ie=N=>{No(N),O(yt())},Te=()=>{Vo(),O([])},Ze=N=>m.find(oe=>oe.type===N),ct=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:y.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!d&&e.jsx(qi,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:o,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Xi,{transport:t,value:S,onChange:Se,onSearch:me,onEntrySelect:ye}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:y.action.newEntry})]}),K&&R&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:U?e.jsxs(e.Fragment,{children:[(U.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()})," 本"]}),U.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.article.toLocaleString()})," 篇"]}):null,U.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()}),K.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.entities.toLocaleString()})]})]})}),K.hasImage!=null&&K.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.searching}):v?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:v})]}):R?e.jsx("div",{style:{flex:1},children:te?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):A.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:y.search.recentBrowse}),e.jsx("button",{onClick:Te,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:y.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:A.slice(0,Y?10:3).map(N=>N.notFound?e.jsx(Uo,{id:N.id,onRemove:Ie,t:y},N.id):e.jsx(ei,{entry:N,selected:z===N.id,onClick:ye,getConfig:Ze,onRemove:Ie},N.id))}),!Y&&A.length>3&&e.jsx("button",{onClick:()=>ie(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:y.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:y.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.searchSubtitle})]})}):ct?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:N,icon:oe,name:ne,key:B})=>{const Q=j[B]??[],le=Go[B],q=j[le]??0;if(Q.length===0)return null;const ve=!(k===N)&&q>en;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[oe," ",ne,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[q," ",y.unit.items]})]}),ve&&e.jsx("button",{onClick:()=>se(N),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:y.action.viewAll})]}),e.jsx("div",{style:p==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(ge=>{if(x)return e.jsx(g.Fragment,{children:x(ge)},ge.id);const Qe=p==="card"?Yo:ei;return e.jsx(Qe,{entry:ge,selected:z===ge.id,onClick:ye,getConfig:Ze,query:S},ge.id)})})]},N)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Ct(y.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},Yo=({entry:t,selected:n,onClick:i,getConfig:r,query:s})=>{const o=D(),{convert:l}=M(),c=l(t.title||t.primary_name||t.id),a=t.measure_info?l(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${o.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&d.length?d.find(f=>{const u=typeof f=="string"?f:f==null?void 0:f.book_title;return u==null?void 0:u.toLowerCase().includes(s.toLowerCase())}):void 0,x="var(--bim-cover-accent, #8e6f3e)";return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:"var(--bim-bg, #fff)",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${x} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${x} 7%, var(--bim-bg, #fff)))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${x} 45%, transparent)`}}),e.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:x},children:Array.from(c).map((f,u)=>e.jsx("span",{children:f},u))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c}),a&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs("span",{children:["〔",l(t.era),"〕"]}),t.edition&&e.jsx("span",{children:l(t.edition)})]}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[o.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[r(t.type).icon," ",r(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",o.misc.textResource]}),t.has_image&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["🖼️ ",o.misc.imageResource]})]})]})]})},ei=({entry:t,selected:n,onClick:i,getConfig:r,query:s,onRemove:o})=>{const l=D(),{convert:c}=M(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(p=>{const x=typeof p=="string"?p:p==null?void 0:p.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),(t.era||t.edition)&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs(e.Fragment,{children:["〔",c(t.era),"〕"]}),t.edition&&c(t.edition)]}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),o?e.jsx("button",{onClick:p=>{p.stopPropagation(),o(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},Uo=({id:t,onRemove:n,t:i})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:i.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Ko(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function Jo({data:t}){const{convert:n}=M(),{dynasty:i,birth_year:r,death_year:s}=t,o=[];return i&&o.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?o.push(`${r}—${s}`):r!==void 0?o.push(`${r}—?`):s!==void 0&&o.push(`?—${s}`),o.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:o.join(" ")})}function qo({alt_names:t}){const{convert:n}=M(),i=new Map;for(const o of t){const l=o.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(o.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((o,l)=>{const c=r.indexOf(o),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(o=>{const l=i.get(o);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:o}),e.jsx("span",{children:l.map((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},o)})})}function Xo({data:t}){const n=t.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function Zo({works:t,transport:n,onNavigate:i,renderLink:r}){const s=D(),{convert:o}=M(),l=be(),[c,a]=g.useState(new Map);g.useEffect(()=>{if(!n)return;let f=!1;const u=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(u);let w=!0;for(let k=0;k<u.length;k++){const C=j[k];C!=null&&C.title?y.set(u[k],C.title):C!=null&&C.primary_name?y.set(u[k],C.primary_name):w=!1}if(w)return y}catch{}const m=[...u],S=8,b=new Array(S).fill(0).map(async()=>{for(;m.length;){const j=m.shift();if(!j)break;if(!y.has(j))try{if(n.getEntry){const C=await n.getEntry(j);if(C!=null&&C.title){y.set(j,C.title);continue}}const w=await n.getItem(j),k=w&&(w.title||w.primary_name)||j;y.set(j,k)}catch{y.set(j,j)}}});return await Promise.all(b),y})().then(y=>{f||a(y)}),()=>{f=!0}},[t,n]);const d=new Map;for(const f of t){const u=f.role||"";d.has(u)||d.set(u,[]),d.get(u).push(f)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((f,u)=>{const h=p.indexOf(f),y=p.indexOf(u);return h===-1&&y===-1?f.localeCompare(u):h===-1?1:y===-1?-1:h-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(f=>{const u=d.get(f);return e.jsxs("div",{style:{marginBottom:"8px"},children:[f&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[o(f)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",u.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:f?"16px":"0",listStyle:f?"disc":"none",fontSize:"14px",lineHeight:1.8},children:u.map((h,y)=>{const m=o(c.get(h.work_id)||h.work_id);return r?e.jsx("li",{children:r(h.work_id,m)},y):i?e.jsx("li",{children:e.jsx("a",{href:l(h.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),i(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:m})},y):e.jsx("li",{children:m},y)})})]},f)})]})}const Zi=({data:t,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:o})=>{var x;const l=D(),{convert:c}=M();let a=!1;try{a=Z.extractStatus(t.id)==="draft"}catch{}const d=Ko(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[c(t.primary_name),e.jsx(Jo,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"var(--bim-type-entity, #5b3e8e)",border:"1px solid color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 25%, transparent)",borderRadius:"2px",background:"color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 3%, transparent)"},children:l.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(qo,{alt_names:t.alt_names}),e.jsx(Xo,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Zo,{works:t.works,transport:n,onNavigate:i,renderLink:r})]})},Qi={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},Qo={...Qi,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Pe=({text:t,plainStrong:n,style:i,className:r})=>{const{convert:s}=M(),o=n?Qo:Qi;return e.jsx("div",{className:r,style:i,children:e.jsx(fo,{remarkPlugins:[go],components:o,children:s(t)})})},es=["〇","一","二","三","四","五","六","七","八","九"],ti=["","十","百","千"];function er(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const l=parseInt(n[o]),c=i-1-o;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&o===0?r+=ti[c]:r+=es[l]+ti[c])}return r}function tr(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const ts={book:"var(--bim-type-book, #c0392b)",work:"var(--bim-type-work, #8e6f3e)",collection:"var(--bim-type-collection, #2471a3)",entity:"var(--bim-type-entity, #5b3e8e)"};function ns({type:t}){const n=D();return e.jsx("span",{style:tr(ts[t]),children:n.indexType[t]})}function is({isDraft:t}){const n=D(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:tr(i),children:t?n.status.draft:n.status.official})}function rs({id:t}){const n=D(),[i,r]=g.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-bg-subtle, #f6f6f6)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:o=>o.currentTarget.style.opacity="1",onMouseLeave:o=>o.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function je({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function Ee({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function nr({authors:t,type:n,onNavigate:i,renderLink:r}){const{convert:s}=M();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,l)=>{const c=s(o.name),a=o.entity_id?e.jsx(we,{id:o.entity_id,label:c,onNavigate:i,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(o.dynasty),"〕"]}),a,o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(o.role)]})]},l)})})}function we({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function os({id:t,title:n,edition:i,type:r,isDraft:s,authors:o,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:p}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(ns,{type:r}),e.jsx(is,{isDraft:s}),e.jsx(rs,{id:t})]}),((o==null?void 0:o.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[o&&o.length>0&&e.jsx(nr,{authors:o,type:r,onNavigate:d,renderLink:p}),c]})]})}function ir({items:t,label:n,showMeta:i,onNavigate:r,renderLink:s}){const o=D(),{convert:l}=M();if(!t.length)return null;const[c,a]=g.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,p)=>{const x=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(x?null:p),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!x&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:f=>f.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(we,{id:d.source_bid,label:o.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(Ee,{label:o.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(Ee,{label:o.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(Ee,{label:o.label.edition,children:l(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},p)})})]})}function ss({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function rr({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.emendated,onNavigate:n,renderLink:i})}function or({label:t,items:n}){const{convert:i}=M();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const o=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:i(o)},s)})})]}):null}function ls({items:t}){const n=D();return e.jsx(or,{label:n.section.aliases,items:t})}function as({items:t}){const n=D();return e.jsx(or,{label:n.section.attachedTexts,items:t})}function cs({items:t}){const n=D(),{convert:i}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",i(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function ds({items:t}){const n=D(),{convert:i}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function ps({items:t}){const n=D(),{convert:i}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(r)]},s))})]}):null}function ni({title:t,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:o}=M(),[l,c]=g.useState([]);return g.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(p=>({id:d,title:p?p.title:void 0,edition:p?p.edition:void 0,type:p?p.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${o(a.title)||a.id}(${o(a.edition)})`:o(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(we,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function tn({book:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=M(),[o,l]=g.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!o?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(we,{id:t.id,label:a,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:o?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:o?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!o&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(kn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function us({ids:t,workData:n,transport:i,onNavigate:r,renderLink:s,footer:o}){const l=D(),{convert:c}=M(),[a,d]=g.useState([]);if(g.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(y=>({id:y})));return}let h=!1;return Promise.all(t.map(y=>i.getItem(y).then(m=>({id:y,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:y})))).then(y=>{h||d(y)}),()=>{h=!0}},[t,i]),!t.length)return null;const p=a.length?a:t.map(h=>({id:h})),x=new Map(p.map(h=>[h.id,h])),f=n==null?void 0:n.version_graph,u=xs(t,f);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),o,u.useGrouping?e.jsxs(e.Fragment,{children:[u.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.coreIds.map(h=>{const y=x.get(h);return y?e.jsx(tn,{book:y,onNavigate:r,renderLink:s},h):null})}),u.groupedIds.map(h=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(y=>{const m=x.get(y);return m?e.jsx(tn,{book:m,onNavigate:r,renderLink:s},y):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(h=>e.jsx(tn,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function xs(t,n){var m,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,l=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=b=>{if(a.has(b))return!0;const j=n.node_groups[b];return j!=null&&c.has(j)},p=[],x=new Map,f=[];for(const b of t)if(!((S=n.excluded_books)!=null&&S.includes(b)))if(d(b))p.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):f.push(b)}if(f.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(b=>[b.id,b])),y=[...x.entries()].map(([b,j])=>{const w=h.get(b);return{id:b,label:(w==null?void 0:w.label)??b,description:w==null?void 0:w.description,ids:j}});return f.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:f}),{useGrouping:!0,coreIds:p,groupedIds:y}}function fs({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const r=D(),{convert:s}=M(),o=!!((l=t.description)!=null&&l.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:o?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(we,{id:t.id,label:s(t.title),onNavigate:n,renderLink:i})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[er(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(nr,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),o&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(Pe,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(Ee,{label:r.label.parentWork,children:e.jsx(we,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function gs({items:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=M();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(o=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:r.indexType.collection}),e.jsx(we,{id:o.id,label:s(o.title)||o.id,onNavigate:n,renderLink:i}),o.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ct(r.catalog.volume,{n:o.volume_index})})]},o.id))}):null}const wn=({data:t,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:o,relatedBooksFooter:l,className:c,style:a})=>{var E,R,P,$,O,A,F,te;const d=D(),{convert:p}=M(),[x,f]=g.useState(null),[u,h]=g.useState(!1),[y,m]=g.useState(null),[S,b]=g.useState(null),[j,w]=g.useState([]),k=t||x;if(g.useEffect(()=>{if(t||!n||!i)return;let W=!1;return h(!0),m(null),i.getItem(n).then(Y=>{W||(Y?f(Y):m(d.misc.notFoundEntry))}).catch(Y=>{W||m(Y instanceof Error?Y.message:d.misc.loadFailed)}).finally(()=>{W||h(!1)}),()=>{W=!0}},[t,n,i]),g.useEffect(()=>{if(!k||!i){b(null),w([]);return}let W=!1;const Y=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(Y?i.getItem(Y).then(ie=>{!W&&ie&&ie.type==="work"&&b(ie)}).catch(()=>{}):b(null),k.type==="book"){const ie=k;ie.contained_in&&ie.contained_in.length>0?Promise.all(ie.contained_in.map(K=>{const L=typeof K=="string"?K:K.id,U=typeof K=="string"?void 0:K.volume_index;return i.getItem(L).then(J=>({id:L,title:J&&J.title||L,volume_index:U})).catch(()=>({id:L,title:L,volume_index:U}))})).then(K=>{W||w(K)}):w([])}else w([]);return()=>{W=!0}},[k,i]),u)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,Y)=>e.jsx("div",{style:{height:Y===1?"32px":"16px",width:`${W}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},Y))})});if(y)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!k)return null;if(k.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Zi,{data:k,transport:i,onNavigate:r,renderLink:s,headerExtra:o})});const C=k.type==="book"?k:null,T=k.type==="collection"?k:null,_=k.type==="work"?k:null;let z=!1;try{z=Z.extractStatus(k.id)==="draft"}catch{}let I="";k.measure_info?I=p(k.measure_info):(E=k.juan_count)!=null&&E.number?I=er(k.juan_count.number)+d.unit.juan:(R=k.juan_count)!=null&&R.description&&(I=p(k.juan_count.description));const v=[];return(P=k.publication_info)!=null&&P.year&&v.push(e.jsx(Ee,{label:d.label.year,children:k.publication_info.year},"year")),($=k.current_location)!=null&&$.name&&v.push(e.jsx(Ee,{label:d.label.currentLocation,children:p(k.current_location.name)},"loc")),(O=k.page_count)!=null&&O.description&&v.push(e.jsx(Ee,{label:d.label.pageCount,children:k.page_count.description},"page")),C!=null&&C.edition&&v.push(e.jsx(Ee,{label:d.label.edition,children:p(C.edition)},"ver")),_!=null&&_.parent_work&&v.push(e.jsx(Ee,{label:d.label.parentWork,children:e.jsx(we,{id:_.parent_work.id,label:p(_.parent_work.title),onNavigate:r,renderLink:s})},"pw")),_!=null&&_.parent_works&&_.parent_works.length>0&&!_.parent_work&&v.push(e.jsx(Ee,{label:d.label.parentWork,children:_.parent_works.map((W,Y)=>e.jsxs("span",{children:[Y>0&&"、",e.jsx(we,{id:W,onNavigate:r,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(os,{id:k.id,title:p(k.title),edition:k.edition?p(k.edition):void 0,type:k.type,isDraft:z,authors:k.authors,volumeText:I,meta:v,headerExtra:o,onNavigate:r,renderLink:s}),((A=k.description)==null?void 0:A.text)&&e.jsx(Pe,{text:k.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((W,Y)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:p(W.title)}),e.jsx(Pe,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},Y))}),j.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.containedIn}),e.jsx(gs,{items:j,onNavigate:r,renderLink:s})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.belongsToWork}),e.jsx(fs,{workData:S,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&e.jsx(cs,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&e.jsx(ls,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&e.jsx(as,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&e.jsx(ss,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&e.jsx(rr,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.resources}),e.jsx(kn,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&e.jsx(ds,{items:C.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&e.jsx(ps,{items:T.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&e.jsx(ni,{title:d.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.books)&&T.books.length>0&&e.jsx(ni,{title:d.section.containedBooks,ids:T.books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.contained_works)&&T.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(je,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",T.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:T.contained_works.map(W=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(we,{id:W.id,label:p(W.title),onNavigate:r,renderLink:s})},W.id))})]}),(((F=_==null?void 0:_.books)==null?void 0:F.length)||0)+(((te=_==null?void 0:_.collections)==null?void 0:te.length)||0)>0&&e.jsx(us,{ids:[...(_==null?void 0:_.books)||[],...(_==null?void 0:_.collections)||[]],workData:_,transport:i,onNavigate:r,renderLink:s,footer:l}),(_==null?void 0:_.related_works)&&_.related_works.length>0&&(()=>{const W=[],Y=_.related_works.filter(V=>V.relation==="part_of"),ie=_.related_works.filter(V=>V.relation==="has_part"),K=_.related_works.filter(V=>V.relation==="has_adaptation"),L=_.related_works.filter(V=>V.relation==="text_carried_by"),U=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),J=_.related_works.filter(V=>!V.relation||!U.has(V.relation));return Y.length>0&&W.push({label:d.section.belongsToWork,items:Y}),ie.length>0&&W.push({label:d.section.containedWorks,items:ie}),K.length>0&&W.push({label:d.section.adaptations,items:K}),L.length>0&&W.push({label:d.section.derivativeWorks,items:L}),J.length>0&&W.push({label:d.section.relatedWorks,items:J}),W.map(V=>e.jsxs("div",{children:[e.jsxs(je,{children:[V.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",V.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:V.items.map(G=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(we,{id:G.id,label:p(G.title),onNavigate:r,renderLink:s})},G.id))})]},V.label))})()]})};function ms({data:t}){const n=D(),{convert:i}=M(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,o=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),o!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",o,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function hs({sections:t,activeSection:n,onSelect:i}){const r=D();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:ii(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:ii(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function ii(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function bs({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function ys(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],r=t[t.length-1];return r-i+1===t.length?`${i}–${r}`:t.length<=3?t.join(", "):`${i}–${r} (${t.length}${n})`}function ri({book:t,onNavigate:n,renderLink:i,showVolumes:r}){const s=D(),{convert:o}=M(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?ys(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[o(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>o(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:o(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(bs,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const _n=({data:t,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:o,style:l})=>{const c=D(),[a,d]=g.useState(null),[p,x]=g.useState(!1),[f,u]=g.useState(null),[h,y]=g.useState(null),[m,S]=g.useState(""),b=t||a;g.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let T=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(_=>{T||(_?d(_):u(c.catalog.notFound))}).catch(_=>{T||u(_ instanceof Error?_.message:c.catalog.loadFailed)}).finally(()=>{T||x(!1)}),()=>{T=!0}},[t,n,i,c]);const j=(b==null?void 0:b.sections)&&b.sections.length>0,w=g.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const T=b.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(T).size<T.length},[b]),k=g.useMemo(()=>{if(!b)return[];let T=b.books;if(h&&(T=T.filter(_=>_.section===h)),m.trim()){const _=m.trim().toLowerCase();T=T.filter(z=>z.title.toLowerCase().includes(_)||z.sub_items&&z.sub_items.some(I=>I.toLowerCase().includes(_))||z.edition&&z.edition.toLowerCase().includes(_))}return T},[b,h,m]),C=g.useMemo(()=>{if(!w)return null;const T=[],_=new Map;for(const I of k){if(!I.volumes||I.volumes.length===0)continue;const v=I.volumes[0];_.has(v)||_.set(v,[]),_.get(v).push(I)}const z=[..._.keys()].sort((I,v)=>I-v);for(const I of z)T.push({volume:I,books:_.get(I)});return T},[k,w]);return p?e.jsx("div",{className:o,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):f?e.jsx("div",{className:o,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f}):b?e.jsxs("div",{className:o,style:l,children:[e.jsx(ms,{data:b}),j&&e.jsx(hs,{sections:b.sections,activeSection:h,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:m,onChange:T=>S(T.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[k.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[C?C.map((T,_)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Ct(c.catalog.volume,{n:T.volume})}),T.books.map((z,I)=>e.jsx(ri,{book:z,onNavigate:r,renderLink:s,showVolumes:z.volumes.length>1},`${T.volume}-${I}`))]},`${T.volume}-${_}`)):k.map((T,_)=>e.jsx(ri,{book:T,onNavigate:r,renderLink:s,showVolumes:!0},_)),k.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Xe=()=>{const[t,n]=g.useState(1);return g.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},fe=6,Bt=7,vs=({content:t,children:n,placement:i="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:o})=>{const[l,c]=g.useState(!1),[a,d]=g.useState(null),p=g.useRef(null),x=g.useRef(null),f=g.useRef(null),u=g.useCallback(()=>{const m=x.current,S=f.current;if(!m||!S)return;const b=m.getBoundingClientRect(),j=S.getBoundingClientRect(),w=window.innerHeight,k=document.documentElement.clientWidth;let C=i;i==="top"&&b.top-j.height-Bt<8&&(C="bottom"),i==="bottom"&&b.bottom+j.height+Bt>w-8&&(C="top");const T=C==="top"?b.top-j.height-Bt:b.bottom+Bt;let _=b.left+b.width/2-j.width/2;_=Math.max(8,Math.min(_,k-j.width-8)),d({left:_,top:T,placement:C})},[i]),h=g.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),r)},[r]),y=g.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return g.useEffect(()=>{if(!l)return;const m=requestAnimationFrame(u);return()=>cancelAnimationFrame(m)},[l,u]),g.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:h,onMouseLeave:y,onFocus:h,onBlur:y,style:{display:"inline-block",...o},children:n}),l&&mo.createPortal(e.jsxs("div",{ref:f,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-fe,width:0,height:0,...a.placement==="top"?{bottom:-fe,borderTop:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}:{top:-fe,borderBottom:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}:{top:-5,borderBottom:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}}})]})]}),document.body)]})},sr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],js={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function pe(t){return js[t]??t}const nt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],it={熹平: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},lr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Vt(t){const n=t.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function Ss(t){return t>=1950?"":t>=1912?"民國":t>=1645?"清":t>=1368?"明":t>=1279?"元":t>=960?"宋":t>=907?"五代":t>=618?"唐":t>=581?"隋":t>=420?"南北朝":t>=265?"晉":t>=220?"三國":t>=-202?"漢":""}const ks=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,oi={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Cn(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(oi))if(n.startsWith(s))return oi[s];const i=pe(n);if(Ge[i]!=null)return i;const r=Ae(n);if(r&&n.length<=r.length+1)return pe(r)}function Ve(t,n){if(n){const i=lr[`${n}|${t}`];if(i!=null)return i}return it[t]}const ws=1911;function _s(t){const n=it[t];if(n==null)return;const i=Be[t];let r;for(const[s,o]of Object.entries(it))Be[s]===i&&o>n&&(r==null||o<r)&&(r=o);return r!=null?r-1:void 0}const Cs={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Ht(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,i=0,r=!1;for(const o of t){const l=Cs[o];if(l===void 0)return;r=!0,o==="十"?i=(i||1)*10:o==="廿"||o==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return r&&s>0?s:void 0}function Ae(t){for(const n of sr)if(t.startsWith(n))return n}const Be={};{const t=(n,i)=>{for(const r of i)Be[r]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ye(t,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(it))if(t.includes(r)&&!(i&&Be[r]&&Be[r]!==i&&lr[`${i}|${r}`]==null))return r}function It(t){var l,c,a;const n={era:"",reign:"",source:"none"},i=t.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(l=t.lineage)==null?void 0:l.year_text;if(r){const d=Ae(r)??"";return{era:pe(d),reign:Ye(r,d)??"",source:"lineage"}}const s=(c=t.publication_info)==null?void 0:c.year;if(s){const d=Vt(s);if(d)return{era:Ss(d.from),reign:"",source:"publication"};const p=Ae(s)??Cn(s)??((a=nt.find(u=>u.pattern.test(s)))==null?void 0:a.era)??"",x=Ye(s,p)??"",f=p||(x?Be[x]??"":"");if(f||x)return{era:pe(f),reign:x,source:"publication"}}const o=t.edition||t.title||"";if(o){const d=Ae(o);if(d)return{era:pe(d),reign:Ye(o,d)??"",source:"edition"};const p=nt.find(x=>x.pattern.test(o));if(p)return{era:pe(p.era),reign:Ye(o,p.era)??p.reign??"",source:"edition"}}return n}function Gt(t){var r,s,o,l,c,a,d,p,x;if(((r=t.dating)==null?void 0:r.year)!=null)return t.dating.year;if(typeof((s=t.lineage)==null?void 0:s.year)=="number")return t.lineage.year;const n=(o=t.publication_info)==null?void 0:o.year;if(n){const f=Vt(n);if(f)return f.from}const i=[(l=t.lineage)==null?void 0:l.year_text,(c=t.publication_info)==null?void 0:c.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const f of i){const u=((a=t.publication_info)==null?void 0:a.year)||((d=t.lineage)==null?void 0:d.year_text);if(u&&f!==u&&(Ae(u)||Cn(u)))break;const h=f.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??f.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(h){const j=parseInt(h[1],10);if(j>=100&&j<=2100)return j}const y=f.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(y){const j=Ae(f);if(!j||pe(j)==="民國"){const k=Ht(y[1]);if(k!=null&&k>=1&&k<=120)return ws+k}}const m=Ae(f)??((p=nt.find(j=>j.pattern.test(f)))==null?void 0:p.era),S=m?pe(m):void 0,b=Ye(f,S)??(Ae(f)||(x=nt.find(j=>j.pattern.test(f)))==null?void 0:x.reign);if(b){const j=Ve(b,S);if(j==null)continue;const w=f.indexOf(b),k=w>=0?f.slice(w+b.length):"",C=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),T=C?Ht(C[1]):void 0;return j+(T?T-1:0)}}}function In(t){var l,c,a,d,p,x;const n=(l=t.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(c=t.lineage)==null?void 0:c.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(a=t.lineage)==null?void 0:a.year_text;if(r){const f=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(f){const u=pn[pe(f[1])],h=Ge[pe(f[2])];if(u!=null&&h!=null)return{from:Math.min(u,h)-20,to:Math.max(u,h)+40}}}const s=(d=t.publication_info)==null?void 0:d.year;if(s){const f=Vt(s);if((f==null?void 0:f.to)!=null)return{from:f.from,to:f.to};const u=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(u){const h=pn[pe(u[1])],y=Ge[pe(u[2])];if(h!=null&&y!=null)return{from:Math.min(h,y)-20,to:Math.max(h,y)+40}}}const o=[(p=t.publication_info)==null?void 0:p.year,t.edition,t.title].filter(Boolean);for(const f of o){if(!/[間间]/.test(f))continue;const u=Ae(f)??Cn(f)??((x=nt.find(m=>m.pattern.test(f)))==null?void 0:x.era),h=u?pe(u):void 0,y=[];for(const m of Object.keys(it))f.includes(m)&&(h&&Be[m]&&Be[m]!==h||Ve(m,h)!=null&&y.push(m));if(y.length===0){const m=f.match(/([一-鿿])([一-鿿])[間间]/);if(m&&h){for(const S of[m[1],m[2]])for(const b of Object.keys(it))if(Be[b]===h&&!(b[0]!==S&&b[b.length-1]!==S)&&Ve(b,h)!=null){y.push(b);break}}}if(y.length>0){const m=y.map(w=>Ve(w,h)).filter(w=>w!=null),S=Math.min(...m),b=y.reduce((w,k)=>Ve(w,h)>=Ve(k,h)?w:k),j=_s(b)??nn(h??"")??Math.max(...m);return{from:S,to:j>S?j:nn(h??Be[b]??"")??S}}if(h&&Ge[h]!=null)return{from:Ge[h],to:nn(h)??Ge[h]}}}const Ge={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Is=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Ts=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,si=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function li(t,n){for(const i of sr){const r=t.indexOf(i);if(r<0)continue;if(i.length===1){const a=t[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!Ye(t.slice(r),pe(i)))continue}const s=pe(i);if(s===n)continue;const o=t.slice(r),l=Ye(o,s)??"";let c;if(l){const a=Ve(l,s);if(a!=null){const p=o.slice(o.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=p?Ht(p[1]):void 0;c=a+(x?x-1:0)}}return{era:s,reign:l,year:c}}for(const i of nt)if(i.pattern.test(t))return{era:pe(i.era),reign:i.reign??""}}function zs(t){var S,b,j,w,k;const n=It(t),i=((S=t.publication_info)==null?void 0:S.year)??"",r=i?Vt(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=t.edition||t.title||"",o=/[間间]/.test(s),l=((b=t.lineage)==null?void 0:b.year_text)??"",c=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),a=n.source==="publication"&&ks.test(i),d=n.source==="publication"&&/[間间]/.test(i),p=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;o||c||a||d?x=void 0:p?x=parseInt(p[2],10):x=Gt(t);const f=x==null?In(t):void 0;let u;n.source==="publication"&&(a||si.test(i))?u="uncertain":n.source==="lineage"||n.source==="publication"?u="attested":si.test(s)||!n.reign&&x==null?u="uncertain":u="inferred";const h=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=t.lineage)==null?void 0:j.year_text)??((w=t.lineage)==null?void 0:w.year)??""}」`:`出版著錄「${((k=t.publication_info)==null?void 0:k.year)??""}」`,y={era:n.era,reign:n.reign,year:x,yearRange:f,certainty:u,source:n.source==="edition"?"edition":"catalog",basis:h};if(p){const C=l.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==y.era&&(y.laterRepair={era:C[1]})}if(!y.laterRepair&&Ts.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(y.laterRepair={era:C[1]})}const m=Is.find(C=>C.re.test(s));if(m){const C=s.search(m.re),T=s.slice(C),_=li(T,n.era)??li(s,n.era);_&&(y.basedOn={era:_.era,reign:_.reign,year:_.year,relation:m.relation})}return y}const pn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function nn(t){return pn[t]}function ar(t){const n=Gt(t);if(n!=null)return n;const i=In(t);if(i)return i.from;const r=It(t).era;return r?Ge[r]:void 0}const ai=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function un(t){const n=ai.indexOf(t);return n===-1?ai.length:n}function cr(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const o=s.relation;o==="part_of"?n.belongsTo.push(s):o==="collected_in"?n.collected.push(s):o==="has_part"||o==="contains_text_of"?n.contains.push(s):o==="text_carried_by"||o==="studied_by"||o==="derived_from"||o==="followed_by"||o==="has_adaptation"?n.derivative.push(s):o==="studies"||o==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,o)=>{n[s].length&&i.push({key:s,labelKey:o,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function Yt(t,n){const i=yn(t||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((p,x)=>{const f=u=>u.group_role==="origin"?0:u.group_role==="mirror"?1:2;return f(p)-f(x)});const o={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=Ke(d),x=p.includes("text"),f=p.includes("image");x&&f?o.textImage.push(d):x?o.text.push(d):f?o.image.push(d):o.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>o[d].length>0).map(d=>({key:d,items:o[d]})),a=[...r.entries()].map(([d,p])=>{var x,f;return{key:d,label:((x=n==null?void 0:n[d])==null?void 0:x.label)||d,description:(f=n==null?void 0:n[d])==null?void 0:f.description,items:p}});return{buckets:c,mirrors:a,total:i.length}}function Tn(t){const n=[],i=t.metadata||{};i.edition&&n.push(String(i.edition)),t.source_label&&n.push(t.source_label),t.details&&n.push(t.details);const r=vn(t);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Rs(t,n){if(Tn(t)||n.filter(r=>r.name===t.name).length<2)return"";try{const r=new URL(t.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const o=r.pathname.split("/").filter(Boolean).pop();if(o)return decodeURIComponent(o)}catch{}return""}function dr(t,n){var o,l;const i=t.resources||[],r=[],s=[];for(const c of i){const a=Ke(c);a.includes("image")&&r.push(c),a.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:It(t),year:Gt(t),sortYear:ar(t),images:r,holders:s,locationName:(o=t.current_location)==null?void 0:o.name,important:Es(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:r.length>0}}function Es(t,n){var c,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(c=n.collections)==null?void 0:c[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(t))return!0;const o=(r==null?void 0:r.groups)??[],l=(a=n.node_groups)==null?void 0:a[t];return!!l&&o.includes(l)}function pr(t,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!r.has(a.id)).map(a=>dr(a,n));let o=s;i.era&&(o=o.filter(a=>a.era.era===i.era)),i.scanOnly&&(o=o.filter(a=>a.hasImage)),i.sort==="year"?o=o.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=a.r.sortYear,x=d.r.sortYear;return p!=null&&x!=null?p-x||a.i-d.i:p!=null?-1:x!=null?1:a.i-d.i}).map(a=>a.r):o=o.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=x=>(x.important?0:1)*2+(x.hasImage?0:1);return p(a.r)-p(d.r)||a.i-d.i}).map(a=>a.r);const c=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>un(a)-un(d));return{rows:o,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Bs(t,n){var m,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,l=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=b=>{if(a.has(b))return!0;const j=n.node_groups[b];return j!=null&&c.has(j)},p=[],x=new Map,f=[];for(const b of t)if(!((S=n.excluded_books)!=null&&S.includes(b)))if(d(b))p.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):f.push(b)}if(f.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(b=>[b.id,b])),y=[...x.entries()].map(([b,j])=>{const w=h.get(b);return{id:b,label:(w==null?void 0:w.label)??b,description:w==null?void 0:w.description,ids:j}});return f.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:f}),{useGrouping:!0,coreIds:p,groupedIds:y}}const ur=["撰","編","注","校","譯","繪","其他"],Ls=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function zn(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of Ls)if(r.test(n))return i;return"其他"}function Rn(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function xr(t){const n=new Map;for(const r of t){const s=zn(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const r of ur){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function fr(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),o=[...new Set(s.map(l=>l.section).filter(Boolean))];return{rows:s,source:"catalog",sections:o,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(o=>({id:o.id,title:o.title,volumes:vt(o.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var o,l;return{id:s,title:((o=i==null?void 0:i.get(s))==null?void 0:o.title)||s,edition:(l=i==null?void 0:i.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function vt(t){if(t==null)return[];if(typeof t=="number")return[t];if(Array.isArray(t))return t.filter(n=>typeof n=="number");if(typeof t=="string"){const n=t.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,o)=>i+o)}return t.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function En(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((o,l)=>o-l),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const Ws=["〇","一","二","三","四","五","六","七","八","九"],ci=["","十","百","千"];function gr(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const l=parseInt(n[o]),c=i-1-o;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&o===0?r+=ci[c]:r+=Ws[l]+ci[c])}return r}function $s(t){return t==null?"":typeof t=="string"?t:t.title??""}function Je(t,n="卷"){var r,s;const i=t;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?gr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function mr(t){var r;if((r=t.lineage)!=null&&r.category)return t.lineage.category;const n=t.edition||t.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,o]of i)if(s.test(n))return o;return""}const mt=1e3,rn=208,As="(max-width: 719px)",hr=`
|
|
1
|
+
"use strict";var ao=Object.create;var Un=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var po=Object.getOwnPropertyNames;var uo=Object.getPrototypeOf,xo=Object.prototype.hasOwnProperty;var fo=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of po(n))!xo.call(t,s)&&s!==i&&Un(t,s,{get:()=>n[s],enumerable:!(r=co(n,s))||r.enumerable});return t};var dt=(t,n,i)=>(i=t!=null?ao(uo(t)):{},fo(n||!t||!t.__esModule?Un(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("./storage-entry-VGdfSKGX.cjs"),e=require("react/jsx-runtime"),f=require("react"),go=require("react-markdown"),mo=require("remark-gfm"),ho=require("react-dom"),bo=t=>`/book-index?id=${t}`,Vi=f.createContext(bo);function yo({buildUrl:t,children:n}){const i=f.useMemo(()=>t,[t]);return e.jsx(Vi.Provider,{value:i,children:n})}function be(){return f.useContext(Vi)}function Ke(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function vo(t,n){return Ke(t).includes(n)}const Gi={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},jo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},So={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},_t=f.createContext(null),Yi={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入叢編",collectedIn:"收入叢編",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},ko={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入丛编",collectedIn:"收入丛编",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",publicationYearLabel:"出版年 (Publication year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},wo={"zh-Hant":Yi,"zh-Hans":ko},Ui="bim-locale";function _o(){try{const t=localStorage.getItem(Ui);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Co(t){try{localStorage.setItem(Ui,t)}catch{}}const Io="zh-Hans",To=({locale:t,onLocaleChange:n,children:i})=>{const[r,s]=f.useState(t??Io),o=t??r;f.useEffect(()=>{if(t)return;const p=_o();p&&p!==r&&s(p)},[]);const[l,c]=f.useState(null);f.useEffect(()=>{o==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const x=p.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>p=>p)}):c(null)},[o]);const a=f.useCallback(p=>{s(p),Co(p),n==null||n(p)},[n]),d=f.useMemo(()=>({locale:o,setLocale:a,messages:wo[o],converter:l}),[o,a,l]);return e.jsx(_t.Provider,{value:d,children:i})};function D(){const t=f.useContext(_t);return(t==null?void 0:t.messages)??Yi}const zo=2e3;function P(){const t=f.useContext(_t),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const o=f.useCallback(l=>{if(!l)return"";if(!i)return l;const c=r.current.get(l);if(c!==void 0)return c;const a=i(l);if(r.current.size>=zo){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[i]);return f.useMemo(()=>({convert:o,locale:n,isSimplified:n==="zh-Hans"}),[o,n])}function Ct(t,n){return t.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Ro(t){if(!t)return"";try{const n=new URL(t).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Eo(){return{id:"",name:"",url:"",type:"text",details:""}}const cn=({items:t,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const o=D(),[l,c]=f.useState(null),a=[{value:"text",label:o.resourceTypeShort.text},{value:"image",label:o.resourceTypeShort.image},{value:"text+image",label:o.resourceTypeShort.textImage},{value:"physical",label:o.resourceTypeShort.physical}],d=[{value:"catalog",label:o.rootType.catalog},{value:"search",label:o.rootType.search}],p=b=>{if(!s)return!0;const j=Ke(b);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=t.map((b,j)=>({item:b,originalIndex:j})).filter(({item:b})=>p(b)),g=()=>{const b=Eo();s&&(b.type=s),n([...t,b]),c(t.length)},u=b=>{n(t.filter((j,w)=>w!==b)),c(null)},h=(b,j,w)=>{const k=[...t];if(k[b]={...k[b],[j]:w},j==="url"&&!k[b].id){const C=Ro(w);C&&(k[b].id=C)}n(k)},v=(b,j,w)=>{const C={...t[b].metadata||{}};w?C[j]=w:delete C[j],h(b,"metadata",Object.keys(C).length>0?C:void 0)},m=(b,j)=>{const w=j.trim()?j.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;h(b,"structure",w)},S=(b,j,w)=>{const C=t[b].coverage||{level:1,ranges:""};j==="level"?C.level=parseInt(w)||1:C.ranges=w,h(b,"coverage",C.ranges?C:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:j})=>{var w,k,C;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===j?null:j),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===j?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Bo(b.type??"text"),color:"#fff"},children:(()=>{var _,z;const T=Ke(b);return T.length===0?b.type??"text":T.length===1?((_=a.find(I=>I.value===T[0]))==null?void 0:_.label)??T[0]:T.includes("text")&&T.includes("image")?((z=a.find(I=>I.value==="text+image"))==null?void 0:z.label)??"text+image":T.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${o.editor.resourcePlaceholder} ${j+1}`}),b.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:T=>T.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&b.url&&Lo(j,r==null?void 0:r[j],i,o),e.jsx("button",{onClick:T=>{T.stopPropagation(),u(j)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisResource,children:"✕"})]}),l===j&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[vo(b,"image")&&b.url&&Wo(b,o),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.type}),e.jsx("select",{value:b.type,onChange:T=>h(j,"type",T.target.value),style:{...Re,flex:1},children:a.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]}),e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:T=>h(j,"root_type",T.target.value),style:{...Re,flex:1},children:d.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:b.id,onChange:T=>h(j,"id",T.target.value),placeholder:o.editor.idAutoExtract,style:{...Re,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:T=>h(j,"name",T.target.value),placeholder:o.editor.resourceName,style:{...Re,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:T=>h(j,"url",T.target.value),placeholder:o.editor.resourceUrl,style:Re}),e.jsx("input",{type:"text",value:((w=b.structure)==null?void 0:w.join("、"))||"",onChange:T=>m(j,T.target.value),placeholder:o.editor.structurePlaceholder,style:Re}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=b.coverage)==null?void 0:k.level)??"",onChange:T=>S(j,"level",T.target.value),placeholder:"1",style:{...Re,width:"60px"}})]}),e.jsxs("label",{style:{...pt,flex:1},children:[e.jsx("span",{style:ut,children:o.label.coverageRange}),e.jsx("input",{type:"text",value:((C=b.coverage)==null?void 0:C.ranges)||"",onChange:T=>S(j,"ranges",T.target.value),placeholder:o.editor.coverageRangePlaceholder,style:{...Re,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:T=>h(j,"details",T.target.value),placeholder:o.editor.detailsPlaceholder,style:{...Re,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(o.metadata).map(([T,_])=>{var z;return e.jsxs("label",{style:{...pt,gap:"4px"},children:[e.jsx("span",{style:{...ut,minWidth:"56px"},children:_}),e.jsx("input",{type:"text",value:((z=b.metadata)==null?void 0:z[T])||"",onChange:I=>v(j,T,I.target.value),placeholder:_,style:{...Re,flex:1}})]},T)})})]})]})]})]},j)}),e.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addResource})]})]})};function Bo(t){switch(t){case"text":return"var(--bim-restype-text, #2196f3)";case"image":return"var(--bim-restype-image, #ff9800)";case"text+image":return"var(--bim-restype-text-image, #9c27b0)";case"physical":return"var(--bim-restype-physical, #795548)"}}function Lo(t,n,i,r){const s=(n==null?void 0:n.status)==="downloading",o=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:l=>{l.stopPropagation(),s||i(t,"")},disabled:s,style:{background:"transparent",border:"none",color:o?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:o?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:o?"✓":s?"⏳":"⬇"})}function Wo(t,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:i?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"var(--bim-overlay-bg, #00000010)"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const Re={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},pt={display:"flex",alignItems:"center",gap:"6px"},ut={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},$o={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function St(t){try{return $o[new URL(t).hostname]}catch{return}}const Kn={text:0,image:1,physical:2};function bn(t){return t.length===0?"physical":[...t].sort((n,i)=>(Kn[n]??99)-(Kn[i]??99)).join("+")}function yn(t){var l;const n=c=>{const a=c.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const d=c.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let c=0;c<t.length;c++){const a=t[c];if(a.volumes&&a.volumes.length>0)continue;const d=n(a.name);if(!d)continue;const[p,x]=d,g=`${p}|${bn(Ke(a))}`;i.has(g)||i.set(g,{base:{...a,name:p,url:"",volumes:[]},volumes:[],indices:[]});const u=i.get(g);u.volumes.push({volume:x,url:a.url||void 0,status:"found"}),u.indices.push(c)}const r=[],s=new Set;for(const c of i.values())if(!(c.volumes.length<2)){c.volumes.sort((a,d)=>a.volume-d.volume),c.base.volumes=c.volumes,c.base.expected_volumes=c.volumes.length,c.base.url||(c.base.url=((l=c.volumes.find(a=>a.url))==null?void 0:l.url)??""),r.push(c.base);for(const a of c.indices)s.add(a)}const o=[...r];for(let c=0;c<t.length;c++)s.has(c)||o.push(t[c]);return o}function Ki(t){if(t.url)return t.url;for(const[n,i]of Object.entries(t))if(n.endsWith("_url")&&typeof i=="string")return i}function Ji(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Ki(n)}))}function vn(t){const n=Ji(t);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:t.expected_volumes??i+r}}function jn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function Sn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const r=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Pt(t){if(!t.url)return;const n=jn(t.metadata);return n?Sn(t.url,n):t.url}const Jn={text:"var(--bim-restype-text, #2196f3)",image:"var(--bim-restype-image, #ff9800)","text+image":"var(--bim-restype-text-image, #9c27b0)",physical:"var(--bim-restype-physical, #795548)"};function Ao(t){return t.includes("text")&&t.includes("image")?Jn["text+image"]:Jn[t[0]||"physical"]}const kn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const o=D(),{convert:l}=P(),c=f.useMemo(()=>yn(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=f.useMemo(()=>{const m=new Map,S=[];for(const b of c){const j=b.group;j?(m.has(j)||m.set(j,[]),m.get(j).push(b)):S.push(b)}for(const b of m.values())b.sort((j,w)=>{const k=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return k(j)-k(w)});return{mirrorGroups:m,ungroupedItems:S}},[c]),p={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical},x=m=>p[m]?p[m]:m.split("+").map(S=>p[S]||S).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((m,S)=>e.jsx(Qt,{item:m},m.id||S))});const g=(m,S)=>{const b=i==null?void 0:i[m],j=(b==null?void 0:b.label)||m,w=b==null?void 0:b.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(j)}),w&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(w)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((k,C)=>e.jsx(Qt,{item:k,onNavigate:r,renderLink:s},k.id||C))})]},`group-${m}`)},u=new Map;for(const m of d){const S=bn(Ke(m));u.has(S)||u.set(S,[]),u.get(S).push(m)}const h=["text","image","text+image","physical"],v=[...h.filter(m=>u.has(m)),...[...u.keys()].filter(m=>!h.includes(m)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([m,S])=>g(m,S)),v.map(m=>{const S=u.get(m),b=Ao(m.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:b,whiteSpace:"nowrap",flexShrink:0},children:x(m)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((j,w)=>e.jsx(Qt,{item:j,onNavigate:r,renderLink:s},j.id||w))})]},m)})]})},Mo={bw:{label:"",bg:"var(--bim-colormode-bw-bg, #f5f5f5)",fg:"var(--bim-colormode-bw-fg, #757575)"},color:{label:"",bg:"var(--bim-colormode-color-bg, #fff8e1)",fg:"var(--bim-colormode-color-fg, #f57f17)"}},Qt=({item:t})=>{const n=D(),{convert:i}=P(),[r,s]=f.useState(!1),o=f.useMemo(()=>(t.url?St(t.url):void 0)||i(t.name),[t.url,t.name,i]),l=f.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||Ki(h)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(l.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,p=t.expected_volumes??(c?a+d:0),x=t.color_mode?{...Mo[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?i(t.details):null,u={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:u,children:[e.jsx("span",{style:{fontWeight:500},children:o}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",p,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=jn(t.metadata);return h?Sn(t.url,h):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(h=>{const v=h.status==="missing";return h.url&&!v?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:v?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1},children:h.volume},h.volume)})})]})},qi=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:o,onSelectFolder:l})=>{const c=D(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",x=p?p.split(/[/\\]/).pop()||p:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},u={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...u,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:g,...u,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:o,title:x||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...u,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!a&&x&&e.jsxs("div",{style:{...g,background:"var(--bim-mode-active-bg, #2196f3)",color:"white",cursor:"default"},title:p,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Nt="bim-search-history",qn=10,Xn=8;function bt(){try{const t=localStorage.getItem(Nt);return t?JSON.parse(t):[]}catch{return[]}}function Fo(t){try{const n=bt().filter(i=>i!==t);n.unshift(t),n.length>qn&&(n.length=qn),localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Po(t){try{const n=bt().filter(i=>i!==t);localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Ho(){try{localStorage.removeItem(Nt)}catch{}}const Xi=({transport:t,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:o})=>{const l=D(),c=o??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=f.useState(!1),[x,g]=f.useState([]),[u,h]=f.useState(-1),[v,m]=f.useState(bt),S=f.useRef(null),b=f.useRef(null),j=f.useRef(null),w=f.useRef(!1);f.useEffect(()=>{h(-1);const y=n.trim();if(!y){g(v.map(F=>({type:"history",text:F})));return}if(!t.searchAll){g([]);return}let R=!1;const E=setTimeout(()=>{t.searchAll(y,Xn).then(F=>{if(R)return;const $=[...F.works,...F.books,...F.collections,...F.entities??[]];g($.slice(0,Xn).map(O=>({type:"entry",text:O.title||O.id,entry:O})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,v,t]),f.useEffect(()=>{const y=R=>{j.current&&!j.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]),f.useEffect(()=>{const y=R=>{var E,F;if(R.key==="/"&&document.activeElement!==S.current){const $=(E=document.activeElement)==null?void 0:E.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;R.preventDefault(),(F=S.current)==null||F.focus()}};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[]);const k=f.useCallback(y=>{y.trim()&&(Fo(y.trim()),m(bt())),r(y),p(!1)},[r]),C=f.useCallback(y=>{y.type==="history"?(i(y.text),k(y.text)):y.entry&&(s?(s(y.entry),p(!1)):(i(y.text),k(y.text)))},[i,k,s]),T=f.useCallback(y=>{if(!d||x.length===0){y.key==="Enter"&&k(n);return}switch(y.key){case"ArrowDown":y.preventDefault(),h(R=>(R+1)%x.length);break;case"ArrowUp":y.preventDefault(),h(R=>(R-1+x.length)%x.length);break;case"Enter":y.preventDefault(),u>=0&&u<x.length?C(x[u]):k(n);break;case"Escape":y.preventDefault(),p(!1);break}},[d,x,u,n,k,C]),_=f.useCallback((y,R)=>{R.stopPropagation(),Po(y),m(bt()),g(E=>E.filter(F=>!(F.type==="history"&&F.text===y)))},[]),z=f.useCallback(y=>{y.stopPropagation(),Ho(),m([]),g([])},[]);f.useEffect(()=>{if(u>=0&&b.current){const y=b.current.children;y[u]&&y[u].scrollIntoView({block:"nearest"})}},[u]);const I=!n.trim()&&v.length>0;return e.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:c,value:n,onChange:y=>{i(y.target.value),p(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{p(!0)},onKeyDown:T,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:z,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),x.map((y,R)=>e.jsxs("div",{onClick:()=>C(y),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:R===u?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:y.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y.text}),y.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[y.entry.type],y.entry.edition&&` · ${y.entry.edition}`,y.entry.author&&` · ${y.entry.author}`]}),y.type==="history"&&e.jsx("button",{onClick:E=>_(y.text,E),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${y.type}-${y.text}-${R}`))]})]})},kt="bim-recent-ids",Zn="bim-recent-entries",Qn=50,en=5,Oo=50,Do=200;function yt(){try{const t=localStorage.getItem(kt);if(t)return JSON.parse(t);const n=localStorage.getItem(Zn);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(kt,JSON.stringify(i)),localStorage.removeItem(Zn),i}return[]}catch{return[]}}function No(t){try{const n=yt().filter(i=>i!==t);n.unshift(t),n.length>Qn&&(n.length=Qn),localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Vo(t){try{const n=yt().filter(i=>i!==t);localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Go(){try{localStorage.removeItem(kt)}catch{}}const Yo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},dn=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:o,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:x,initialQuery:g,onQueryChange:u,headerRight:h})=>{const v=D(),m=[{type:"work",icon:"✍️",name:v.indexType.work,key:"works"},{type:"book",icon:"📖",name:v.indexType.book,key:"books"},{type:"collection",icon:"📚",name:v.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:v.indexType.entity,key:"entities"}],[S,b]=f.useState(g??""),[j,w]=f.useState(null),[k,C]=f.useState(null),[T,_]=f.useState(!1),[z,I]=f.useState(null),[y,R]=f.useState(""),[E,F]=f.useState(!g),[$,O]=f.useState(yt),[A,M]=f.useState([]),[J,W]=f.useState(!1),[Y,ie]=f.useState(!1),[K,L]=f.useState(null),[U,q]=f.useState(null),V=f.useRef(void 0),G=f.useRef(!1),de=f.useCallback(async(N,oe)=>{if(!N.trim()){F(!0),w(null),C(null);return}F(!1),_(!0),R("");try{if(t.searchAll){const ne=await t.searchAll(N,oe??en);w(ne)}else{const ne=["work","book","collection","entity"],B=await Promise.all(ne.map(ee=>t.search(N,ee,{page:1,pageSize:oe??en})));w({works:B[0].entries,books:B[1].entries,collections:B[2].entries,entities:B[3].entries,totalWorks:B[0].total,totalBooks:B[1].total,totalCollections:B[2].total,totalEntities:B[3].total})}}catch(ne){R(ne instanceof Error?ne.message:String(ne)),w(null)}finally{_(!1)}},[t]);f.useEffect(()=>{let N=!1;const oe=()=>{var X,Pe;const ne=["work","book","collection","entity"],B=Promise.all(ne.map(ve=>t.loadEntries(ve,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((X=t.getResourceCounts)==null?void 0:X.call(t).catch(()=>null))??Promise.resolve(null),le=((Pe=t.getSubtypeStats)==null?void 0:Pe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([B,ee,le]).then(([ve,ge,Qe])=>{N||(L({works:ve[0].total,books:ve[1].total,collections:ve[2].total,entities:ve[3].total,hasText:ge==null?void 0:ge.hasText,hasImage:ge==null?void 0:ge.hasImage}),Qe&&q(Qe))})};return t.getCounts?t.getCounts().then(ne=>{var B,ee;N||(L({works:ne.works,books:ne.books,collections:ne.collections,entities:ne.entities,hasText:(B=ne.resourceCounts)==null?void 0:B.hasText,hasImage:(ee=ne.resourceCounts)==null?void 0:ee.hasImage}),ne.subtypeStats&&q(ne.subtypeStats))}).catch(()=>{N||oe()}):oe(),()=>{N=!0}},[t]),f.useEffect(()=>{G.current||!(g!=null&&g.trim())||(G.current=!0,de(g))},[g,de]);const Se=f.useCallback(N=>{if(b(N),!N.trim()){u==null||u(N),F(!0),w(null),C(null);return}V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{C(null),u==null||u(N),de(N)},Do)},[de,u]),me=f.useCallback(N=>{V.current&&clearTimeout(V.current),u==null||u(N),de(N)},[de,u]),se=f.useCallback(N=>{C(N),de(S,Oo)},[S,de]);f.useEffect(()=>{if(!$.length){M([]);return}let N=!1;return W(!0),Promise.all($.slice(0,10).map(async oe=>{var ne,B,ee;try{if(t.getEntry){const X=await t.getEntry(oe);if(X)return X}const le=await t.getItem(oe);if(le){const X=le.authors;return{id:oe,title:le.title||oe,type:le.type||"work",author:(ne=X==null?void 0:X[0])==null?void 0:ne.name,dynasty:(B=X==null?void 0:X[0])==null?void 0:B.dynasty,role:(ee=X==null?void 0:X[0])==null?void 0:ee.role,edition:le.edition||void 0}}}catch{}return{id:oe,title:oe,type:"work",notFound:!0}})).then(oe=>{N||(M(oe),W(!1))}),()=>{N=!0}},[$,t]);const ye=N=>{I(N.id),No(N.id),O(yt()),r==null||r(N)},Ie=N=>{Vo(N),O(yt())},Te=()=>{Go(),O([])},Ze=N=>m.find(oe=>oe.type===N),ct=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:v.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!d&&e.jsx(qi,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:o,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Xi,{transport:t,value:S,onChange:Se,onSearch:me,onEntrySelect:ye}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:v.action.newEntry})]}),K&&E&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:U?e.jsxs(e.Fragment,{children:[(U.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()})," 本"]}),U.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.article.toLocaleString()})," 篇"]}):null,U.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[v.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()}),K.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.entities.toLocaleString()})]})]})}),K.hasImage!=null&&K.hasText!=null&&e.jsxs("span",{children:[v.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:v.search.searching}):y?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:y})]}):E?e.jsx("div",{style:{flex:1},children:J?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:v.search.loading}):A.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:v.search.recentBrowse}),e.jsx("button",{onClick:Te,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:A.slice(0,Y?10:3).map(N=>N.notFound?e.jsx(Ko,{id:N.id,onRemove:Ie,t:v},N.id):e.jsx(ei,{entry:N,selected:z===N.id,onClick:ye,getConfig:Ze,onRemove:Ie},N.id))}),!Y&&A.length>3&&e.jsx("button",{onClick:()=>ie(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:v.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:v.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v.search.searchSubtitle})]})}):ct?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:N,icon:oe,name:ne,key:B})=>{const ee=j[B]??[],le=Yo[B],X=j[le]??0;if(ee.length===0)return null;const ve=!(k===N)&&X>en;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[oe," ",ne,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[X," ",v.unit.items]})]}),ve&&e.jsx("button",{onClick:()=>se(N),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),e.jsx("div",{style:p==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:ee.map(ge=>{if(x)return e.jsx(f.Fragment,{children:x(ge)},ge.id);const Qe=p==="card"?Uo:ei;return e.jsx(Qe,{entry:ge,selected:z===ge.id,onClick:ye,getConfig:Ze,query:S},ge.id)})})]},N)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:Ct(v.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v.search.tryOther})]})})]})},Uo=({entry:t,selected:n,onClick:i,getConfig:r,query:s})=>{const o=D(),{convert:l}=P(),c=l(t.title||t.primary_name||t.id),a=t.measure_info?l(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${o.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&d.length?d.find(g=>{const u=typeof g=="string"?g:g==null?void 0:g.book_title;return u==null?void 0:u.toLowerCase().includes(s.toLowerCase())}):void 0,x="var(--bim-cover-accent, #8e6f3e)";return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:"var(--bim-bg, #fff)",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${x} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${x} 7%, var(--bim-bg, #fff)))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${x} 45%, transparent)`}}),e.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:x},children:Array.from(c).map((g,u)=>e.jsx("span",{children:g},u))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c}),a&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs("span",{children:["〔",l(t.era),"〕"]}),t.edition&&e.jsx("span",{children:l(t.edition)})]}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[o.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[r(t.type).icon," ",r(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",o.misc.textResource]}),t.has_image&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["🖼️ ",o.misc.imageResource]})]})]})]})},ei=({entry:t,selected:n,onClick:i,getConfig:r,query:s,onRemove:o})=>{const l=D(),{convert:c}=P(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(p=>{const x=typeof p=="string"?p:p==null?void 0:p.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),(t.era||t.edition)&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs(e.Fragment,{children:["〔",c(t.era),"〕"]}),t.edition&&c(t.edition)]}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),o?e.jsx("button",{onClick:p=>{p.stopPropagation(),o(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},Ko=({id:t,onRemove:n,t:i})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:i.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Jo(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function qo({data:t}){const{convert:n}=P(),{dynasty:i,birth_year:r,death_year:s}=t,o=[];return i&&o.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?o.push(`${r}—${s}`):r!==void 0?o.push(`${r}—?`):s!==void 0&&o.push(`?—${s}`),o.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:o.join(" ")})}function Xo({alt_names:t}){const{convert:n}=P(),i=new Map;for(const o of t){const l=o.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(o.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((o,l)=>{const c=r.indexOf(o),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(o=>{const l=i.get(o);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:o}),e.jsx("span",{children:l.map((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},o)})})}function Zo({data:t}){const n=t.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function Qo({works:t,transport:n,onNavigate:i,renderLink:r}){const s=D(),{convert:o}=P(),l=be(),[c,a]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const u=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const j=await n.getEntriesByIds(u);let w=!0;for(let k=0;k<u.length;k++){const C=j[k];C!=null&&C.title?v.set(u[k],C.title):C!=null&&C.primary_name?v.set(u[k],C.primary_name):w=!1}if(w)return v}catch{}const m=[...u],S=8,b=new Array(S).fill(0).map(async()=>{for(;m.length;){const j=m.shift();if(!j)break;if(!v.has(j))try{if(n.getEntry){const C=await n.getEntry(j);if(C!=null&&C.title){v.set(j,C.title);continue}}const w=await n.getItem(j),k=w&&(w.title||w.primary_name)||j;v.set(j,k)}catch{v.set(j,j)}}});return await Promise.all(b),v})().then(v=>{g||a(v)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const u=g.role||"";d.has(u)||d.set(u,[]),d.get(u).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((g,u)=>{const h=p.indexOf(g),v=p.indexOf(u);return h===-1&&v===-1?g.localeCompare(u):h===-1?1:v===-1?-1:h-v});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(g=>{const u=d.get(g);return e.jsxs("div",{style:{marginBottom:"8px"},children:[g&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[o(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",u.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:u.map((h,v)=>{const m=o(c.get(h.work_id)||h.work_id);return r?e.jsx("li",{children:r(h.work_id,m)},v):i?e.jsx("li",{children:e.jsx("a",{href:l(h.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),i(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:m})},v):e.jsx("li",{children:m},v)})})]},g)})]})}const Zi=({data:t,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:o})=>{var x;const l=D(),{convert:c}=P();let a=!1;try{a=Q.extractStatus(t.id)==="draft"}catch{}const d=Jo(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[c(t.primary_name),e.jsx(qo,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"var(--bim-type-entity, #5b3e8e)",border:"1px solid color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 25%, transparent)",borderRadius:"2px",background:"color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 3%, transparent)"},children:l.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Xo,{alt_names:t.alt_names}),e.jsx(Zo,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Qo,{works:t.works,transport:n,onNavigate:i,renderLink:r})]})},Qi={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},es={...Qi,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Me=({text:t,plainStrong:n,style:i,className:r})=>{const{convert:s}=P(),o=n?es:Qi;return e.jsx("div",{className:r,style:i,children:e.jsx(go,{remarkPlugins:[mo],components:o,children:s(t)})})},ts=["〇","一","二","三","四","五","六","七","八","九"],ti=["","十","百","千"];function er(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const l=parseInt(n[o]),c=i-1-o;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&o===0?r+=ti[c]:r+=ts[l]+ti[c])}return r}function tr(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const ns={book:"var(--bim-type-book, #c0392b)",work:"var(--bim-type-work, #8e6f3e)",collection:"var(--bim-type-collection, #2471a3)",entity:"var(--bim-type-entity, #5b3e8e)"};function is({type:t}){const n=D();return e.jsx("span",{style:tr(ns[t]),children:n.indexType[t]})}function rs({isDraft:t}){const n=D(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:tr(i),children:t?n.status.draft:n.status.official})}function os({id:t}){const n=D(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-bg-subtle, #f6f6f6)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:o=>o.currentTarget.style.opacity="1",onMouseLeave:o=>o.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function je({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function Ee({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function nr({authors:t,type:n,onNavigate:i,renderLink:r}){const{convert:s}=P();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,l)=>{const c=s(o.name),a=o.entity_id?e.jsx(we,{id:o.entity_id,label:c,onNavigate:i,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(o.dynasty),"〕"]}),a,o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(o.role)]})]},l)})})}function we({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ss({id:t,title:n,edition:i,type:r,isDraft:s,authors:o,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:p}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(is,{type:r}),e.jsx(rs,{isDraft:s}),e.jsx(os,{id:t})]}),((o==null?void 0:o.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[o&&o.length>0&&e.jsx(nr,{authors:o,type:r,onNavigate:d,renderLink:p}),c]})]})}function ir({items:t,label:n,showMeta:i,onNavigate:r,renderLink:s}){const o=D(),{convert:l}=P();if(!t.length)return null;const[c,a]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,p)=>{const x=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(x?null:p),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!x&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(we,{id:d.source_bid,label:o.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(Ee,{label:o.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(Ee,{label:o.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(Ee,{label:o.label.edition,children:l(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},p)})})]})}function ls({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function rr({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.emendated,onNavigate:n,renderLink:i})}function or({label:t,items:n}){const{convert:i}=P();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const o=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:i(o)},s)})})]}):null}function as({items:t}){const n=D();return e.jsx(or,{label:n.section.aliases,items:t})}function cs({items:t}){const n=D();return e.jsx(or,{label:n.section.attachedTexts,items:t})}function ds({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",i(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function ps({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function us({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(r)]},s))})]}):null}function ni({title:t,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:o}=P(),[l,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(p=>({id:d,title:p?p.title:void 0,edition:p?p.edition:void 0,type:p?p.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${o(a.title)||a.id}(${o(a.edition)})`:o(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(we,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function tn({book:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=P(),[o,l]=f.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!o?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(we,{id:t.id,label:a,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:o?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:o?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!o&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(kn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function xs({ids:t,workData:n,transport:i,onNavigate:r,renderLink:s,footer:o}){const l=D(),{convert:c}=P(),[a,d]=f.useState([]);if(f.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(v=>({id:v})));return}let h=!1;return Promise.all(t.map(v=>i.getItem(v).then(m=>({id:v,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:v})))).then(v=>{h||d(v)}),()=>{h=!0}},[t,i]),!t.length)return null;const p=a.length?a:t.map(h=>({id:h})),x=new Map(p.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,u=fs(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),o,u.useGrouping?e.jsxs(e.Fragment,{children:[u.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.coreIds.map(h=>{const v=x.get(h);return v?e.jsx(tn,{book:v,onNavigate:r,renderLink:s},h):null})}),u.groupedIds.map(h=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(v=>{const m=x.get(v);return m?e.jsx(tn,{book:m,onNavigate:r,renderLink:s},v):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(h=>e.jsx(tn,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function fs(t,n){var m,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,l=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=b=>{if(a.has(b))return!0;const j=n.node_groups[b];return j!=null&&c.has(j)},p=[],x=new Map,g=[];for(const b of t)if(!((S=n.excluded_books)!=null&&S.includes(b)))if(d(b))p.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):g.push(b)}if(g.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(b=>[b.id,b])),v=[...x.entries()].map(([b,j])=>{const w=h.get(b);return{id:b,label:(w==null?void 0:w.label)??b,description:w==null?void 0:w.description,ids:j}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:v}}function gs({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const r=D(),{convert:s}=P(),o=!!((l=t.description)!=null&&l.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:o?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(we,{id:t.id,label:s(t.title),onNavigate:n,renderLink:i})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[er(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(nr,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),o&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(Me,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(Ee,{label:r.label.parentWork,children:e.jsx(we,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function ms({items:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=P();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(o=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:r.indexType.collection}),e.jsx(we,{id:o.id,label:s(o.title)||o.id,onNavigate:n,renderLink:i}),o.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ct(r.catalog.volume,{n:o.volume_index})})]},o.id))}):null}const wn=({data:t,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:o,relatedBooksFooter:l,className:c,style:a})=>{var R,E,F,$,O,A,M,J;const d=D(),{convert:p}=P(),[x,g]=f.useState(null),[u,h]=f.useState(!1),[v,m]=f.useState(null),[S,b]=f.useState(null),[j,w]=f.useState([]),k=t||x;if(f.useEffect(()=>{if(t||!n||!i)return;let W=!1;return h(!0),m(null),i.getItem(n).then(Y=>{W||(Y?g(Y):m(d.misc.notFoundEntry))}).catch(Y=>{W||m(Y instanceof Error?Y.message:d.misc.loadFailed)}).finally(()=>{W||h(!1)}),()=>{W=!0}},[t,n,i]),f.useEffect(()=>{if(!k||!i){b(null),w([]);return}let W=!1;const Y=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(Y?i.getItem(Y).then(ie=>{!W&&ie&&ie.type==="work"&&b(ie)}).catch(()=>{}):b(null),k.type==="book"){const ie=k;ie.contained_in&&ie.contained_in.length>0?Promise.all(ie.contained_in.map(K=>{const L=typeof K=="string"?K:K.id,U=typeof K=="string"?void 0:K.volume_index;return i.getItem(L).then(q=>({id:L,title:q&&q.title||L,volume_index:U})).catch(()=>({id:L,title:L,volume_index:U}))})).then(K=>{W||w(K)}):w([])}else w([]);return()=>{W=!0}},[k,i]),u)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,Y)=>e.jsx("div",{style:{height:Y===1?"32px":"16px",width:`${W}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},Y))})});if(v)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!k)return null;if(k.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Zi,{data:k,transport:i,onNavigate:r,renderLink:s,headerExtra:o})});const C=k.type==="book"?k:null,T=k.type==="collection"?k:null,_=k.type==="work"?k:null;let z=!1;try{z=Q.extractStatus(k.id)==="draft"}catch{}let I="";k.measure_info?I=p(k.measure_info):(R=k.juan_count)!=null&&R.number?I=er(k.juan_count.number)+d.unit.juan:(E=k.juan_count)!=null&&E.description&&(I=p(k.juan_count.description));const y=[];return(F=k.publication_info)!=null&&F.year&&y.push(e.jsx(Ee,{label:d.label.year,children:k.publication_info.year},"year")),($=k.current_location)!=null&&$.name&&y.push(e.jsx(Ee,{label:d.label.currentLocation,children:p(k.current_location.name)},"loc")),(O=k.page_count)!=null&&O.description&&y.push(e.jsx(Ee,{label:d.label.pageCount,children:k.page_count.description},"page")),C!=null&&C.edition&&y.push(e.jsx(Ee,{label:d.label.edition,children:p(C.edition)},"ver")),_!=null&&_.parent_work&&y.push(e.jsx(Ee,{label:d.label.parentWork,children:e.jsx(we,{id:_.parent_work.id,label:p(_.parent_work.title),onNavigate:r,renderLink:s})},"pw")),_!=null&&_.parent_works&&_.parent_works.length>0&&!_.parent_work&&y.push(e.jsx(Ee,{label:d.label.parentWork,children:_.parent_works.map((W,Y)=>e.jsxs("span",{children:[Y>0&&"、",e.jsx(we,{id:W,onNavigate:r,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(ss,{id:k.id,title:p(k.title),edition:k.edition?p(k.edition):void 0,type:k.type,isDraft:z,authors:k.authors,volumeText:I,meta:y,headerExtra:o,onNavigate:r,renderLink:s}),((A=k.description)==null?void 0:A.text)&&e.jsx(Me,{text:k.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((W,Y)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:p(W.title)}),e.jsx(Me,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},Y))}),j.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.containedIn}),e.jsx(ms,{items:j,onNavigate:r,renderLink:s})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.belongsToWork}),e.jsx(gs,{workData:S,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&e.jsx(ds,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&e.jsx(as,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&e.jsx(cs,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&e.jsx(ls,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&e.jsx(rr,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.resources}),e.jsx(kn,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&e.jsx(ps,{items:C.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&e.jsx(us,{items:T.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&e.jsx(ni,{title:d.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.books)&&T.books.length>0&&e.jsx(ni,{title:d.section.containedBooks,ids:T.books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.contained_works)&&T.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(je,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",T.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:T.contained_works.map(W=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(we,{id:W.id,label:p(W.title),onNavigate:r,renderLink:s})},W.id))})]}),(((M=_==null?void 0:_.books)==null?void 0:M.length)||0)+(((J=_==null?void 0:_.collections)==null?void 0:J.length)||0)>0&&e.jsx(xs,{ids:[...(_==null?void 0:_.books)||[],...(_==null?void 0:_.collections)||[]],workData:_,transport:i,onNavigate:r,renderLink:s,footer:l}),(_==null?void 0:_.related_works)&&_.related_works.length>0&&(()=>{const W=[],Y=_.related_works.filter(V=>V.relation==="part_of"),ie=_.related_works.filter(V=>V.relation==="has_part"),K=_.related_works.filter(V=>V.relation==="has_adaptation"),L=_.related_works.filter(V=>V.relation==="text_carried_by"),U=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),q=_.related_works.filter(V=>!V.relation||!U.has(V.relation));return Y.length>0&&W.push({label:d.section.belongsToWork,items:Y}),ie.length>0&&W.push({label:d.section.containedWorks,items:ie}),K.length>0&&W.push({label:d.section.adaptations,items:K}),L.length>0&&W.push({label:d.section.derivativeWorks,items:L}),q.length>0&&W.push({label:d.section.relatedWorks,items:q}),W.map(V=>e.jsxs("div",{children:[e.jsxs(je,{children:[V.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",V.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:V.items.map(G=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(we,{id:G.id,label:p(G.title),onNavigate:r,renderLink:s})},G.id))})]},V.label))})()]})};function hs({data:t}){const n=D(),{convert:i}=P(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,o=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),o!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",o,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function bs({sections:t,activeSection:n,onSelect:i}){const r=D();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:ii(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:ii(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function ii(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function ys({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function vs(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],r=t[t.length-1];return r-i+1===t.length?`${i}–${r}`:t.length<=3?t.join(", "):`${i}–${r} (${t.length}${n})`}function ri({book:t,onNavigate:n,renderLink:i,showVolumes:r}){const s=D(),{convert:o}=P(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?vs(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[o(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>o(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:o(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(ys,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const _n=({data:t,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:o,style:l})=>{const c=D(),[a,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[h,v]=f.useState(null),[m,S]=f.useState(""),b=t||a;f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let T=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(_=>{T||(_?d(_):u(c.catalog.notFound))}).catch(_=>{T||u(_ instanceof Error?_.message:c.catalog.loadFailed)}).finally(()=>{T||x(!1)}),()=>{T=!0}},[t,n,i,c]);const j=(b==null?void 0:b.sections)&&b.sections.length>0,w=f.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const T=b.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(T).size<T.length},[b]),k=f.useMemo(()=>{if(!b)return[];let T=b.books;if(h&&(T=T.filter(_=>_.section===h)),m.trim()){const _=m.trim().toLowerCase();T=T.filter(z=>z.title.toLowerCase().includes(_)||z.sub_items&&z.sub_items.some(I=>I.toLowerCase().includes(_))||z.edition&&z.edition.toLowerCase().includes(_))}return T},[b,h,m]),C=f.useMemo(()=>{if(!w)return null;const T=[],_=new Map;for(const I of k){if(!I.volumes||I.volumes.length===0)continue;const y=I.volumes[0];_.has(y)||_.set(y,[]),_.get(y).push(I)}const z=[..._.keys()].sort((I,y)=>I-y);for(const I of z)T.push({volume:I,books:_.get(I)});return T},[k,w]);return p?e.jsx("div",{className:o,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:o,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):b?e.jsxs("div",{className:o,style:l,children:[e.jsx(hs,{data:b}),j&&e.jsx(bs,{sections:b.sections,activeSection:h,onSelect:v}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:m,onChange:T=>S(T.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[k.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[C?C.map((T,_)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Ct(c.catalog.volume,{n:T.volume})}),T.books.map((z,I)=>e.jsx(ri,{book:z,onNavigate:r,renderLink:s,showVolumes:z.volumes.length>1},`${T.volume}-${I}`))]},`${T.volume}-${_}`)):k.map((T,_)=>e.jsx(ri,{book:T,onNavigate:r,renderLink:s,showVolumes:!0},_)),k.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Xe=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(i)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},fe=6,Bt=7,js=({content:t,children:n,placement:i="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:o})=>{const[l,c]=f.useState(!1),[a,d]=f.useState(null),p=f.useRef(null),x=f.useRef(null),g=f.useRef(null),u=f.useCallback(()=>{const m=x.current,S=g.current;if(!m||!S)return;const b=m.getBoundingClientRect(),j=S.getBoundingClientRect(),w=window.innerHeight,k=document.documentElement.clientWidth;let C=i;i==="top"&&b.top-j.height-Bt<8&&(C="bottom"),i==="bottom"&&b.bottom+j.height+Bt>w-8&&(C="top");const T=C==="top"?b.top-j.height-Bt:b.bottom+Bt;let _=b.left+b.width/2-j.width/2;_=Math.max(8,Math.min(_,k-j.width-8)),d({left:_,top:T,placement:C})},[i]),h=f.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),r)},[r]),v=f.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!l)return;const m=requestAnimationFrame(u);return()=>cancelAnimationFrame(m)},[l,u]),f.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:h,onMouseLeave:v,onFocus:h,onBlur:v,style:{display:"inline-block",...o},children:n}),l&&ho.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-fe,width:0,height:0,...a.placement==="top"?{bottom:-fe,borderTop:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}:{top:-fe,borderBottom:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}:{top:-5,borderBottom:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}}})]})]}),document.body)]})},sr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ss={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function pe(t){return Ss[t]??t}const nt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],it={熹平: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},lr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Vt(t){const n=t.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function ks(t){return t>=1950?"":t>=1912?"民國":t>=1645?"清":t>=1368?"明":t>=1279?"元":t>=960?"宋":t>=907?"五代":t>=618?"唐":t>=581?"隋":t>=420?"南北朝":t>=265?"晉":t>=220?"三國":t>=-202?"漢":""}const ws=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,oi={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Cn(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(oi))if(n.startsWith(s))return oi[s];const i=pe(n);if(Ge[i]!=null)return i;const r=Ae(n);if(r&&n.length<=r.length+1)return pe(r)}function Ve(t,n){if(n){const i=lr[`${n}|${t}`];if(i!=null)return i}return it[t]}const _s=1911;function Cs(t){const n=it[t];if(n==null)return;const i=Be[t];let r;for(const[s,o]of Object.entries(it))Be[s]===i&&o>n&&(r==null||o<r)&&(r=o);return r!=null?r-1:void 0}const Is={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Ht(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,i=0,r=!1;for(const o of t){const l=Is[o];if(l===void 0)return;r=!0,o==="十"?i=(i||1)*10:o==="廿"||o==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return r&&s>0?s:void 0}function Ae(t){for(const n of sr)if(t.startsWith(n))return n}const Be={};{const t=(n,i)=>{for(const r of i)Be[r]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ye(t,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(it))if(t.includes(r)&&!(i&&Be[r]&&Be[r]!==i&&lr[`${i}|${r}`]==null))return r}function It(t){var l,c,a;const n={era:"",reign:"",source:"none"},i=t.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(l=t.lineage)==null?void 0:l.year_text;if(r){const d=Ae(r)??"";return{era:pe(d),reign:Ye(r,d)??"",source:"lineage"}}const s=(c=t.publication_info)==null?void 0:c.year;if(s){const d=Vt(s);if(d)return{era:ks(d.from),reign:"",source:"publication"};const p=Ae(s)??Cn(s)??((a=nt.find(u=>u.pattern.test(s)))==null?void 0:a.era)??"",x=Ye(s,p)??"",g=p||(x?Be[x]??"":"");if(g||x)return{era:pe(g),reign:x,source:"publication"}}const o=t.edition||t.title||"";if(o){const d=Ae(o);if(d)return{era:pe(d),reign:Ye(o,d)??"",source:"edition"};const p=nt.find(x=>x.pattern.test(o));if(p)return{era:pe(p.era),reign:Ye(o,p.era)??p.reign??"",source:"edition"}}return n}function Gt(t){var r,s,o,l,c,a,d,p,x;if(((r=t.dating)==null?void 0:r.year)!=null)return t.dating.year;if(typeof((s=t.lineage)==null?void 0:s.year)=="number")return t.lineage.year;const n=(o=t.publication_info)==null?void 0:o.year;if(n){const g=Vt(n);if(g)return g.from}const i=[(l=t.lineage)==null?void 0:l.year_text,(c=t.publication_info)==null?void 0:c.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const g of i){const u=((a=t.publication_info)==null?void 0:a.year)||((d=t.lineage)==null?void 0:d.year_text);if(u&&g!==u&&(Ae(u)||Cn(u)))break;const h=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(h){const j=parseInt(h[1],10);if(j>=100&&j<=2100)return j}const v=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(v){const j=Ae(g);if(!j||pe(j)==="民國"){const k=Ht(v[1]);if(k!=null&&k>=1&&k<=120)return _s+k}}const m=Ae(g)??((p=nt.find(j=>j.pattern.test(g)))==null?void 0:p.era),S=m?pe(m):void 0,b=Ye(g,S)??(Ae(g)||(x=nt.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(b){const j=Ve(b,S);if(j==null)continue;const w=g.indexOf(b),k=w>=0?g.slice(w+b.length):"",C=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),T=C?Ht(C[1]):void 0;return j+(T?T-1:0)}}}function In(t){var l,c,a,d,p,x;const n=(l=t.dating)==null?void 0:l.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(c=t.lineage)==null?void 0:c.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(a=t.lineage)==null?void 0:a.year_text;if(r){const g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const u=pn[pe(g[1])],h=Ge[pe(g[2])];if(u!=null&&h!=null)return{from:Math.min(u,h)-20,to:Math.max(u,h)+40}}}const s=(d=t.publication_info)==null?void 0:d.year;if(s){const g=Vt(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const u=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(u){const h=pn[pe(u[1])],v=Ge[pe(u[2])];if(h!=null&&v!=null)return{from:Math.min(h,v)-20,to:Math.max(h,v)+40}}}const o=[(p=t.publication_info)==null?void 0:p.year,t.edition,t.title].filter(Boolean);for(const g of o){if(!/[間间]/.test(g))continue;const u=Ae(g)??Cn(g)??((x=nt.find(m=>m.pattern.test(g)))==null?void 0:x.era),h=u?pe(u):void 0,v=[];for(const m of Object.keys(it))g.includes(m)&&(h&&Be[m]&&Be[m]!==h||Ve(m,h)!=null&&v.push(m));if(v.length===0){const m=g.match(/([一-鿿])([一-鿿])[間间]/);if(m&&h){for(const S of[m[1],m[2]])for(const b of Object.keys(it))if(Be[b]===h&&!(b[0]!==S&&b[b.length-1]!==S)&&Ve(b,h)!=null){v.push(b);break}}}if(v.length>0){const m=v.map(w=>Ve(w,h)).filter(w=>w!=null),S=Math.min(...m),b=v.reduce((w,k)=>Ve(w,h)>=Ve(k,h)?w:k),j=Cs(b)??nn(h??"")??Math.max(...m);return{from:S,to:j>S?j:nn(h??Be[b]??"")??S}}if(h&&Ge[h]!=null)return{from:Ge[h],to:nn(h)??Ge[h]}}}const Ge={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Ts=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],zs=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,si=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function li(t,n){for(const i of sr){const r=t.indexOf(i);if(r<0)continue;if(i.length===1){const a=t[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(a)&&!Ye(t.slice(r),pe(i)))continue}const s=pe(i);if(s===n)continue;const o=t.slice(r),l=Ye(o,s)??"";let c;if(l){const a=Ve(l,s);if(a!=null){const p=o.slice(o.indexOf(l)+l.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=p?Ht(p[1]):void 0;c=a+(x?x-1:0)}}return{era:s,reign:l,year:c}}for(const i of nt)if(i.pattern.test(t))return{era:pe(i.era),reign:i.reign??""}}function Rs(t){var S,b,j,w,k;const n=It(t),i=((S=t.publication_info)==null?void 0:S.year)??"",r=i?Vt(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=t.edition||t.title||"",o=/[間间]/.test(s),l=((b=t.lineage)==null?void 0:b.year_text)??"",c=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(l),a=n.source==="publication"&&ws.test(i),d=n.source==="publication"&&/[間间]/.test(i),p=l.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;o||c||a||d?x=void 0:p?x=parseInt(p[2],10):x=Gt(t);const g=x==null?In(t):void 0;let u;n.source==="publication"&&(a||si.test(i))?u="uncertain":n.source==="lineage"||n.source==="publication"?u="attested":si.test(s)||!n.reign&&x==null?u="uncertain":u="inferred";const h=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=t.lineage)==null?void 0:j.year_text)??((w=t.lineage)==null?void 0:w.year)??""}」`:`出版著錄「${((k=t.publication_info)==null?void 0:k.year)??""}」`,v={era:n.era,reign:n.reign,year:x,yearRange:g,certainty:u,source:n.source==="edition"?"edition":"catalog",basis:h};if(p){const C=l.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==v.era&&(v.laterRepair={era:C[1]})}if(!v.laterRepair&&zs.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(v.laterRepair={era:C[1]})}const m=Ts.find(C=>C.re.test(s));if(m){const C=s.search(m.re),T=s.slice(C),_=li(T,n.era)??li(s,n.era);_&&(v.basedOn={era:_.era,reign:_.reign,year:_.year,relation:m.relation})}return v}const pn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function nn(t){return pn[t]}function ar(t){const n=Gt(t);if(n!=null)return n;const i=In(t);if(i)return i.from;const r=It(t).era;return r?Ge[r]:void 0}const ai=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function un(t){const n=ai.indexOf(t);return n===-1?ai.length:n}function cr(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const o=s.relation;o==="part_of"?n.belongsTo.push(s):o==="collected_in"?n.collected.push(s):o==="has_part"||o==="contains_text_of"?n.contains.push(s):o==="text_carried_by"||o==="studied_by"||o==="derived_from"||o==="followed_by"||o==="has_adaptation"?n.derivative.push(s):o==="studies"||o==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,o)=>{n[s].length&&i.push({key:s,labelKey:o,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function Yt(t,n){const i=yn(t||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((p,x)=>{const g=u=>u.group_role==="origin"?0:u.group_role==="mirror"?1:2;return g(p)-g(x)});const o={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=Ke(d),x=p.includes("text"),g=p.includes("image");x&&g?o.textImage.push(d):x?o.text.push(d):g?o.image.push(d):o.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>o[d].length>0).map(d=>({key:d,items:o[d]})),a=[...r.entries()].map(([d,p])=>{var x,g;return{key:d,label:((x=n==null?void 0:n[d])==null?void 0:x.label)||d,description:(g=n==null?void 0:n[d])==null?void 0:g.description,items:p}});return{buckets:c,mirrors:a,total:i.length}}function Tn(t){const n=[],i=t.metadata||{};i.edition&&n.push(String(i.edition)),t.source_label&&n.push(t.source_label),t.details&&n.push(t.details);const r=vn(t);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Es(t,n){if(Tn(t)||n.filter(r=>r.name===t.name).length<2)return"";try{const r=new URL(t.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const o=r.pathname.split("/").filter(Boolean).pop();if(o)return decodeURIComponent(o)}catch{}return""}function dr(t,n){var o,l;const i=t.resources||[],r=[],s=[];for(const c of i){const a=Ke(c);a.includes("image")&&r.push(c),a.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:It(t),year:Gt(t),sortYear:ar(t),images:r,holders:s,locationName:(o=t.current_location)==null?void 0:o.name,important:Bs(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:r.length>0}}function Bs(t,n){var c,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(c=n.collections)==null?void 0:c[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(t))return!0;const o=(r==null?void 0:r.groups)??[],l=(a=n.node_groups)==null?void 0:a[t];return!!l&&o.includes(l)}function pr(t,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!r.has(a.id)).map(a=>dr(a,n));let o=s;i.era&&(o=o.filter(a=>a.era.era===i.era)),i.scanOnly&&(o=o.filter(a=>a.hasImage)),i.sort==="year"?o=o.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=a.r.sortYear,x=d.r.sortYear;return p!=null&&x!=null?p-x||a.i-d.i:p!=null?-1:x!=null?1:a.i-d.i}).map(a=>a.r):o=o.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=x=>(x.important?0:1)*2+(x.hasImage?0:1);return p(a.r)-p(d.r)||a.i-d.i}).map(a=>a.r);const c=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>un(a)-un(d));return{rows:o,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Ls(t,n){var m,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,l=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=b=>{if(a.has(b))return!0;const j=n.node_groups[b];return j!=null&&c.has(j)},p=[],x=new Map,g=[];for(const b of t)if(!((S=n.excluded_books)!=null&&S.includes(b)))if(d(b))p.push(b);else{const j=n.node_groups[b];j?(x.has(j)||x.set(j,[]),x.get(j).push(b)):g.push(b)}if(g.length+[...x.values()].reduce((b,j)=>b+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(b=>[b.id,b])),v=[...x.entries()].map(([b,j])=>{const w=h.get(b);return{id:b,label:(w==null?void 0:w.label)??b,description:w==null?void 0:w.description,ids:j}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:v}}const ur=["撰","編","注","校","譯","繪","其他"],Ws=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function zn(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of Ws)if(r.test(n))return i;return"其他"}function Rn(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function xr(t){const n=new Map;for(const r of t){const s=zn(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const r of ur){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function fr(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),o=[...new Set(s.map(l=>l.section).filter(Boolean))];return{rows:s,source:"catalog",sections:o,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(o=>({id:o.id,title:o.title,volumes:vt(o.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var o,l;return{id:s,title:((o=i==null?void 0:i.get(s))==null?void 0:o.title)||s,edition:(l=i==null?void 0:i.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function vt(t){if(t==null)return[];if(typeof t=="number")return[t];if(Array.isArray(t))return t.filter(n=>typeof n=="number");if(typeof t=="string"){const n=t.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,o)=>i+o)}return t.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function En(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((o,l)=>o-l),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const $s=["〇","一","二","三","四","五","六","七","八","九"],ci=["","十","百","千"];function gr(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const l=parseInt(n[o]),c=i-1-o;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&o===0?r+=ci[c]:r+=$s[l]+ci[c])}return r}function As(t){return t==null?"":typeof t=="string"?t:t.title??""}function Je(t,n="卷"){var r,s;const i=t;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?gr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function mr(t){var r;if((r=t.lineage)!=null&&r.category)return t.lineage.category;const n=t.edition||t.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,o]of i)if(s.test(n))return o;return""}const mt=1e3,rn=208,Ms="(max-width: 719px)",hr=`
|
|
2
2
|
.bim-d-page {
|
|
3
3
|
background: var(--bim-page-bg, #fbf9f3);
|
|
4
4
|
color: var(--bim-ink, #2a231c);
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
align-items: start; margin-bottom: 48px; }
|
|
76
76
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
77
77
|
|
|
78
|
-
@media ${
|
|
78
|
+
@media ${Ms} {
|
|
79
79
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
80
80
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
81
81
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -93,6 +93,6 @@
|
|
|
93
93
|
padding-right: 0; padding-bottom: 12px;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
`;function $t({children:t,style:n,wide:i}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:hr}),e.jsx("div",{className:i?"bim-d-main bim-d-main-wide":"bim-d-main",children:t})]})}function br({aside:t,children:n}){return e.jsxs("div",{className:"bim-d-reader",children:[e.jsx("aside",{className:"bim-d-reader-aside bim-d-ui",children:t}),e.jsx("div",{className:"bim-d-reader-main",children:n})]})}function yr({breadcrumb:t,actions:n}){return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:"var(--bim-label-fg, #8b7a62)"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:t}),n&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function Bn({char:t,tone:n="accent"}){return e.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:n==="accent"?"var(--bim-accent, #9c3a2c)":"var(--bim-ink, #2a231c)",color:"var(--bim-page-bg, #fbf9f3)"},children:t})}function vr({items:t}){const n=be();return e.jsx(e.Fragment,{children:t.map((i,r)=>{const s=r===t.length-1,o=r>0&&e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${r}`),l=i.id?n(i.id):i.href,c=s||!i.onClick&&!l?e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:i.label},r):e.jsx("a",{href:l??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:i.label},r);return e.jsxs(g.Fragment,{children:[o,c]},r)})})}function jr({title:t,subtitle:n,aside:i,secondLine:r}){return e.jsxs("header",{style:{borderBottom:"2px solid var(--bim-rule-strong, #2a231c)",paddingBottom:18},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[e.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:t}),n&&e.jsx("span",{style:{fontSize:15,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".06em"},children:n})]}),i&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".06em"},children:i})]}),r&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:"var(--bim-quiet-fg, #5b4f40)"},children:r})]})}function Tt({children:t,facts:n}){return!t&&n?e.jsx("div",{style:{padding:"20px 0 26px",borderBottom:"1px solid var(--bim-rule, #e4dbc9)",marginBottom:40},children:n}):e.jsxs("div",{className:"bim-d-intro",children:[e.jsx("div",{style:{minWidth:0},children:t}),n]})}function zt({items:t,horizontal:n}){const{convert:i}=M();return t.length?e.jsx("div",{style:{borderLeft:"2px solid var(--bim-accent, #9c3a2c)",paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:t.map((r,s)=>e.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em",flex:"none"},children:i(r.label)}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function ue({glyph:t,tone:n,title:i,count:r,actions:s,id:o}){const{convert:l}=M();return e.jsxs("div",{id:o,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(Bn,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(i)}),r!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Ce({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function He({label:t,active:n,onClick:i,dashed:r}){const{convert:s}=M();return e.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${n?"var(--bim-accent, #9c3a2c)":"var(--bim-rule, #e0d6c0)"}`,background:n?"var(--bim-accent, #9c3a2c)":"transparent",color:n?"var(--bim-page-bg, #fbf9f3)":"var(--bim-meta-fg, #7b6a54)",fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(t)})}function Ut({label:t,onClick:n}){const{convert:i}=M();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:i(t)})}function De({label:t,onClick:n,inline:i}){const{convert:r}=M();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",cursor:"pointer",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:i?void 0:".08em"},children:r(t)})}function Rt({children:t,href:n,onClick:i,title:r}){const s={display:"inline-block",padding:"4px 10px",border:"1px solid var(--bim-rule, #e0d6c0)",fontSize:13,color:"var(--bim-body-fg, #3b3228)",lineHeight:1.5};return n||i?e.jsx("a",{href:n??"#",title:r,onClick:i?o=>{o.metaKey||o.ctrlKey||(o.preventDefault(),i())}:void 0,style:s,children:t}):e.jsx("span",{title:r,style:s,children:t})}function Kt({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function Sr({volumes:t,unit:n="冊",max:i=60}){const[r,s]=g.useState(!1);if(!t.length)return null;const o=r?t:t.slice(0,i);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[o.map(l=>e.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:"1px solid var(--bim-rule, #e0d6c0)",color:"var(--bim-meta-fg, #7b6a54)"},children:l},l)),!r&&t.length>i&&e.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:["+",t.length-i]}),e.jsx("span",{style:{padding:"2px 6px",color:"var(--bim-hint-fg, #b3a385)"},children:n})]})}function qe({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function Jt({spec:t}){const{convert:n}=M();return e.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${t.leadWidth}px 1fr ${t.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",fontSize:11,color:"var(--bim-label-fg, #8b7a62)",letterSpacing:".1em"},children:[e.jsx("span",{}),e.jsx("span",{children:n(t.mainLabel)}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(i=>i.width).join(" "),gap:12},children:t.columns.map(i=>e.jsx("span",{children:n(i.label)},i.label))})]})}function qt({no:t,main:n,meta:i,spec:r}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-hint-fg, #c2b294)",textAlign:"right"},children:t}),e.jsx("span",{style:{minWidth:0},children:n}),e.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Xt(t){return String(t+1).padStart(2,"0")}function rt(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function kr({open:t,onToggle:n,main:i,action:r,children:s}){return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[e.jsx("button",{type:"button",onClick:n,"aria-expanded":t,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 ${t?"var(--bim-accent, #9c3a2c)":"var(--bim-rule-dashed, #d6c9ae)"}`,background:t?"var(--bim-accent, #9c3a2c)":"transparent",color:t?"var(--bim-page-bg, #fbf9f3)":"var(--bim-accent, #9c3a2c)"},children:t?"-":"+"}),e.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),r]}),t&&s&&e.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:"2px solid var(--bim-rule-accent-soft, #e0d3b6)",marginLeft:12},children:s})]})}function Oe(t,n=i=>i){if(!t)return"";if(t.indexOf("⟨")<0)return n(t);const i=[],r=/\u27e8([^\u27e9]*)\u27e9/g;let s=0,o=0,l;for(;(l=r.exec(t))!==null;)l.index>s&&i.push(e.jsx(g.Fragment,{children:n(t.slice(s,l.index))},o++)),i.push(e.jsx("span",{className:"bim-jiazhu",style:{fontSize:".78em",color:"var(--bim-meta-fg, #7b6a54)",lineHeight:1.55},children:n(l[1])},o++)),s=l.index+l[0].length;return s<t.length&&i.push(e.jsx(g.Fragment,{children:n(t.slice(s))},o++)),i}function At({label:t,children:n}){return e.jsxs("div",{style:{marginBottom:10},children:[t&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:"var(--bim-label-fg, #a3937b)",marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"},children:n})]})}function xn({title:t,tag:n,children:i}){const{convert:r}=M();return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",marginBottom:2},children:[e.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:r(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function wr({name:t,note:n,href:i,extra:r}){const s=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,minWidth:0},children:t}),e.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)",flex:"none"},children:i?"↗":""}),n&&e.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:n})]}),o={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:"1px solid var(--bim-rule, #eae2d0)",color:"var(--bim-body-fg, #3b3228)",alignItems:"baseline"};return e.jsxs(e.Fragment,{children:[i?e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:o,children:s}):e.jsx("div",{style:o,children:s}),r]})}function ot({item:t,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=M(),[o,l]=g.useState(!1),c=vn(t),a=i&&!!c&&c.expected>0,d=(t.url?St(t.url):void 0)||s(t.name),p=n?Rs(t,n):"",x=p?`${d}(${p})`:d;return e.jsx(wr,{name:x,note:Tn(t)||r,href:Ft(t),extra:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>l(f=>!f),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:o?"收起分冊":`展開 ${c.expected} 冊`}),o&&e.jsx(_r,{item:t})]}):void 0})}function _r({item:t}){return e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(t.volumes||[]).map((n,i)=>{const r=n.status==="missing";return n.url&&!r?e.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"1px 5px",border:"1px solid var(--bim-rule, #e0d6c0)"},children:n.volume},i):e.jsx("span",{style:{padding:"1px 5px",color:r?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function Ln({label:t,items:n}){const{convert:i}=M();return n.length?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em"},children:t}),n.map((r,s)=>e.jsx(Rt,{children:i(r)},s))]}):null}function Cr({rows:t}){const n=t.filter(i=>i.items.length>0);return n.length?e.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>e.jsx(Ln,{label:i.label,items:i.items},i.label))}):null}function wt(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ir({left:t,right:n}){return e.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:"1px solid var(--bim-rule, #e4dbc9)",display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[e.jsx("span",{children:t}),n&&e.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function st({children:t,action:n}){return e.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:"var(--bim-label-fg, #a3937b)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[e.jsx("span",{children:t}),n]})}function _e({id:t,label:n,onNavigate:i,renderLink:r,style:s,dense:o}){const l=be();return r?e.jsx(e.Fragment,{children:r(t,typeof n=="string"?n:void 0,{dense:o})}):e.jsx("a",{href:l(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function fn({href:t,children:n}){return e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:[n," ",e.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const di={A:"fine",B:"rough",C:"rough",D:"ocr"};function Ps(t){return typeof t!="string"?null:t in Gi?t:t in di?di[t]:null}const Ms={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Fs={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function xe(t){return typeof t!="string"?"":Ms[t]??Fs[t]??t}const Hs=["〇","一","二","三","四","五","六","七","八","九"],pi=["","十","百","千"],Os=["","萬","億"];function Tr(t){if(t===0)return"〇";if(t<0)return`負${Tr(-t)}`;const n=[];let i=t,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Ds(s,r>0)+Os[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ds(t,n){const i=[];let r=t;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let o=0;o<i.length;o++){const l=i[o],c=i.length-1-o;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&o===0&&!n?s+=pi[c]:s+=Hs[l]+pi[c]}return s.replace(/〇$/,"")}let jt=null,Lt=null;const Ot=new Set;function Ns(){return jt?Promise.resolve():Lt||(Lt=import("opencc-js/t2cn").then(t=>{jt=t.Converter({from:"tw",to:"cn"}),Ot.forEach(n=>n())}).catch(()=>{jt=t=>t,Ot.forEach(t=>t())}),Lt)}function Me(){const[,t]=g.useState(0);return g.useEffect(()=>{if(jt)return;const n=()=>t(i=>i+1);return Ot.add(n),Ns(),()=>{Ot.delete(n)}},[]),jt??(n=>n)}function lt(t,n){return n(t).toLowerCase()}const Wn="var(--bim-highlight-bg, #fff59d)";function at(t,n,i){if(!n)return t;const r=lt(n,i);if(!r)return t;const s=lt(t,i);if(s.length!==t.length)return t;const o=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(r,l);if(a===-1){o.push(t.slice(l));break}a>l&&o.push(t.slice(l,a)),o.push(e.jsx("mark",{style:{background:Wn,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:o})}function $n(t,n,i,r){if(!n)return!0;const s=lt(n,r);return(i?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(l=>typeof l=="string"&<(l,r).includes(s))}function Vs(t,n,i){return n?lt(t,i).includes(lt(n,i)):!0}const An={类:"var(--bim-section-lei, #8e6f3e)",书:"var(--bim-section-shu, #c0392b)",序:"var(--bim-section-xu, #1a5276)",结语:"var(--bim-section-jieyu, #7d6608)",注释:"var(--bim-section-zhushi, #6c5b7b)"},Gs={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Ys(t){const n=t.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function gn({file:t,isActive:n,onSelect:i,meta:r,matchState:s,vertical:o}){const l=s===0,c=s==="loading",a=typeof s=="number"&&s>0,d=r!=null&&r.vol_label?`${r.vol_label}冊`:null,p=d??Ys(t),x=!d&&!!(r!=null&&r.vol_label)&&!p.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{l||i(t)},disabled:l,style:{padding:o?"4px 8px":"3px 8px",textAlign:o?"left":"center",width:o?"100%":void 0,border:o?"1px solid transparent":n?"1px solid var(--bim-primary, #8e6f3e)":l?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderLeft:o?`2px solid ${n?"var(--bim-primary, #8e6f3e)":"transparent"}`:void 0,borderRadius:o?0:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":a?`${Wn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":l?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:l?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:l?.5:1},children:[p,x&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function zr(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(r=>zr(r,n)))}function Rr(t){var r;const n=t.files.length,i=((r=t.children)==null?void 0:r.reduce((s,o)=>s+Rr(o),0))||0;return n+i}function Us(t,n){const i=[],r=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(r)};if(r(t),i.length===0)return;const s=i.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let o=0;for(const l of s)typeof l=="number"&&(o+=l);return o}function Er({group:t,activeFile:n,onSelect:i,depth:r=0,juanMeta:s,matchStates:o,vertical:l}){var y;const c=zr(t,n||""),a=Us(t,o),d=typeof a=="number"&&a>0,p=a===0,[x,f]=g.useState(c||d),u=Rr(t),h=!!((y=t.children)!=null&&y.length);if(g.useEffect(()=>{c&&f(!0)},[c]),g.useEffect(()=>{d&&f(!0)},[d]),t.files.length===1&&!h){const m=t.files[0],S=n===m,b=o[m],j=b===0,w=b==="loading",k=typeof b=="number"&&b>0;return e.jsxs("button",{onClick:()=>{j||i(m)},disabled:j,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:S?"1px solid var(--bim-primary, #8e6f3e)":j?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:S?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":k?`${Wn}40`:"transparent",color:S?"var(--bim-primary, #8e6f3e)":j?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:j?"not-allowed":"pointer",fontSize:"12px",fontWeight:S?600:400,lineHeight:1.4,opacity:j?.5:1},children:[t.label,k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:b}),w&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>f(!x),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:c?"var(--bim-primary, #8e6f3e)":p?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:p?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",u,")"]}),d&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",a]}),a==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:l?"column":"row",flexWrap:l?"nowrap":"wrap",gap:l?"1px":"4px",padding:l?`2px 0 2px ${8+r*10}px`:`4px 0 4px ${24+r*16}px`},children:t.files.map(m=>e.jsx(gn,{file:m,isActive:n===m,onSelect:i,meta:s==null?void 0:s[m],matchState:o[m],vertical:l},m))}),h&&t.children.map((m,S)=>e.jsx(Er,{group:m,activeFile:n,onSelect:i,depth:r+1,juanMeta:s,matchStates:o,vertical:l},S))]})]})}function Ks({files:t,groups:n,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:l}){const c=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:l?0:"16px"},children:n.map((a,d)=>e.jsx(Er,{group:a,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:l},d))}):c.length===0?null:l?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1px"},children:c.map(a=>e.jsx(gn,{file:a,isActive:i===a,onSelect:r,meta:s==null?void 0:s[a],matchState:o[a],vertical:!0},a))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:c.map(a=>e.jsx(gn,{file:a,isActive:i===a,onSelect:r,meta:s==null?void 0:s[a],matchState:o[a]},a))})}function Js({type:t}){const n=xe(t),i=An[n]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function qs({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=M(),s=be(),o=Me(),l=y=>y?Oe(r(y),m=>i?at(m,i,o):m):"",[c,a]=g.useState(!1),d=!!t.summary,p=!!t.comment,x=!!t.additional_comment,f=!!(t.content&&t.content.length>60),u=d||p||x||f;g.useEffect(()=>{i&&a(!0)},[i]);const h=!c&&f?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>u&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:u?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Tr(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&u&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),f&&!d&&!p&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function Xs({section:t,highlightQuery:n=""}){const{convert:i}=M(),r=Me(),s=a=>a?Oe(i(a),d=>n?at(d,n,r):d):"",[o,l]=g.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(Js,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${An[xe(t.type)]||"var(--bim-desc-fg, #717171)"} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}const Zs=100;function Br(t){return xe(t.type)!=="page_header"?!1:(t.content||"").length>=Zs}function Qs({section:t,highlightQuery:n=""}){const{convert:i}=M(),r=Me();if(xe(t.type)==="page_header"&&!Br(t)||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
97
|
-
`)),o=n?at(s,n,r):s,l=xe(t.type),c=An[l]||"var(--bim-desc-fg, #717171)",a=l==="序"||l==="结语"||l==="注释";return e.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${c}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:c,marginRight:"8px",padding:"1px 5px",border:`1px solid ${c}40`,borderRadius:"2px",background:`${c}08`,verticalAlign:"middle"},children:l}),o]})}function
|
|
98
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:o.map((l,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!o[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},p):e.jsx(g.Fragment,{children:s(d)},p))},c)})})}function rl({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=M(),s=be(),o=Me(),l=d=>d?Oe(r(d),p=>i?at(p,i,o):p):"",c=[];let a=null;for(const d of t){const p=xe(d.type);p==="page_header"&&!Br(d)||(p==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(a||(a={category:"",items:[]}),a.items.push(d)):(p==="序"||p==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),p==="结语"&&(c.push(a),a=null)))}return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,p)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((x,f)=>xe(x.type)==="序"||xe(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(x.content||"")},f):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),u.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:l(x.title)})}):e.jsx("strong",{children:l(x.title)}),x.content&&l(x.content)]},f))]},p))})}function ol({juan:t,rawText:n,searchQuery:i,onNavigate:r}){const{convert:s}=M(),o=Me(),[l,c]=g.useState("catalog"),a=i.trim(),d=g.useMemo(()=>a?t.sections.filter(u=>$n(u,a,!1,o)):t.sections,[t.sections,a,o]),p=t.sections.filter(u=>xe(u.type)==="书").length,x=t.sections.filter(u=>xe(u.type)==="诗").length,f=a?d.filter(u=>xe(u.type)==="书"||xe(u.type)==="诗").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:f!=null?`${f} / ${x>0?`${x} 首`:`${p} 部書`}`:x>0?`${x} 首`:p>0?`${p} 部书`:""}),e.jsx("div",{style:{display:"flex",gap:"2px"},children:["catalog","raw"].map(u=>e.jsx("button",{onClick:()=>c(u),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:u==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))})]}),l==="raw"&&(n?e.jsx(il,{text:n,highlightQuery:a}):e.jsx(rl,{sections:t.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((u,h)=>{const y=xe(u.type);return y==="书"||y==="诗"||y==="考证"?e.jsx(qs,{section:u,onNavigate:r,highlightQuery:a},h):y==="类"?e.jsx(Xs,{section:u,highlightQuery:a},h):e.jsx(Qs,{section:u,highlightQuery:a},h)}),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function sl(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function ll(t){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:o,activeRawText:l,query:c,isKaozhen:a}=t,d=Me(),p=g.useRef(new Map),[x,f]=g.useState({});g.useEffect(()=>{s&&o&&p.current.set(s,{juan:o,rawText:l})},[s,o,l]),g.useEffect(()=>{p.current.clear(),f({})},[n]);const u=g.useCallback((h,y)=>{let m=0;if(h.juan)for(const S of h.juan.sections)$n(S,y,a,d)&&m++;return m===0&&h.rawText&&Vs(h.rawText,y,d)&&(m=1),m},[a,d]);return g.useEffect(()=>{const h=c.trim();if(!h){f({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const m={},S=[];for(const C of r){const T=p.current.get(C);T?m[C]=u(T,h):(m[C]="loading",S.push(C))}f(m);const b=8;let j=0;const w=async()=>{var C;for(;j<S.length;){if(y)return;const T=j++,_=S[T];try{const[z,I]=await Promise.all([i.getCollatedJuan(n,_),((C=i.getCollatedJuanText)==null?void 0:C.call(i,n,_))??Promise.resolve(null)]),v={juan:z,rawText:I};if(p.current.set(_,v),y)return;f(E=>({...E,[_]:u(v,h)}))}catch{if(y)return;f(z=>({...z,[_]:0}))}}},k=Array.from({length:Math.min(b,S.length)},()=>w());return Promise.all(k),()=>{y=!0}},[c,n,i,r.join(","),u,d]),{matchStates:x}}const Pn=({index:t,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:o,className:l,style:c})=>{const[a,d]=g.useState(null),[p,x]=g.useState(!1),[f,u]=g.useState(null),[h,y]=g.useState(null),[m,S]=g.useState(null),[b,j]=g.useState(!1),[w,k]=g.useState(null),[C,T]=g.useState(""),_=g.useRef(new Map),z=g.useRef(0),I=s??h,v=g.useCallback(F=>{y(F),o==null||o(F)},[o]),E=t||a,R=n||(E==null?void 0:E.work_id),P=g.useCallback(async F=>{var W;if(!R||!(i!=null&&i.getCollatedJuan))return;const te=++z.current;j(!0),S(null),k(null);try{const[Y,ie]=await Promise.all([i.getCollatedJuan(R,F),((W=i.getCollatedJuanText)==null?void 0:W.call(i,R,F))??Promise.resolve(null)]);if(te!==z.current)return;S(Y),k(ie)}catch{if(te!==z.current)return;S(null),k(null)}finally{te===z.current&&j(!1)}},[R,i]);g.useEffect(()=>{I&&P(I)},[I,P]);const $=F=>{v(F)};if(p)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(f)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:f});if(!E)return null;const O=E.type==="kaozhen",A=sl(E);return e.jsx(al,{className:l,style:c,index:E,allFiles:A,isKaozhen:O,effectiveWorkId:R,transport:i,activeFile:I,handleSelectFile:$,juanData:m,juanRawText:w,juanLoading:b,searchQuery:C,setSearchQuery:T,onNavigate:r,workLabelCacheRef:_})},al=({className:t,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:o,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:x,searchQuery:f,setSearchQuery:u,onNavigate:h,workLabelCacheRef:y})=>{const{matchStates:m}=ll({workId:o,transport:l,files:r,activeFile:c,activeJuan:d,activeRawText:p,query:f,isKaozhen:s}),S=e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:s?"搜索全部章节…":"搜索全部卷…",value:f,onChange:b=>u(b.target.value),style:{width:"100%",padding:"6px 9px",marginBottom:"12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"12.5px",boxSizing:"border-box"}}),e.jsx(Ks,{files:r,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:m,vertical:!0})]});return e.jsx("div",{className:t,style:n,children:e.jsxs(br,{aside:S,children:[e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s&&i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})]})}),i.text_quality&&(()=>{const b=Ps(i.text_quality.grade);return b?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(vs,{content:vo[b],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:jo[b],cursor:"help"},children:Gi[b]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),x?e.jsx(Xe,{}):d?s?e.jsx(nl,{juan:d,searchQuery:f,onNavigate:h,transport:l,workLabelCache:y}):e.jsx(ol,{juan:d,rawText:p,searchQuery:f,onNavigate:h}):c?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,i.references&&i.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),i.references.map((b,j)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[j+1,". "]}),b.url?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:b.title}):e.jsx("span",{children:b.title}),b.author&&e.jsxs("span",{children:[",",b.author]}),b.note&&e.jsxs("span",{children:["。",b.note]})]},j))]})]})})},cl={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},dl={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function pl(t){try{const n=new Date(t),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const Mn=({items:t,loading:n})=>{const i=be();return n?e.jsx(Xe,{}):t.length===0?e.jsx("div",{style:ul,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=cl[r.type],o=dl[r.status];return e.jsxs("div",{style:xl,children:[e.jsxs("div",{style:fl,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...ui,background:s.color},children:s.label}),e.jsx("span",{style:{...ui,background:o.color},children:o.label})]}),e.jsx("span",{style:gl,children:pl(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:ml,children:[r.resourceId&&e.jsx("a",{href:i(r.resourceId),style:xi,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:xi,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:hl,children:r.content}),r.reply&&e.jsxs("div",{style:bl,children:[e.jsx("div",{style:yl,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},ul={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},xl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},fl={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ui={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},gl={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ml={fontSize:"12px",marginBottom:"6px"},xi={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},hl={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},bl={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},yl={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},mn=({transport:t,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:o})=>{const l=D(),[c,a]=g.useState(null),[d,p]=g.useState([]),[x,f]=g.useState("recommend"),[u,h]=g.useState([]),[y,m]=g.useState(!1),S=r??x,b=$=>{f($),s==null||s($)},[j,w]=g.useState(!0),[k,C]=g.useState(null),[T,_]=g.useState(null),[z,I]=g.useState(null);g.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(O=>{$||a({works:O.works,books:O.books,collections:O.collections})}).catch(()=>{}),()=>{$=!0}},[t]),g.useEffect(()=>{let $=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const A=await t.getRecommended();if(A!=null&&A.groups)return A.groups.flatMap(F=>F.items.map(te=>({...te,group:F.name})))}catch{}return[]})().then(async A=>{if($)return;const F=A.filter(W=>W.id);if(F.length===0){w(!1);return}const te=await Promise.all(F.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let Y=null;if(t.getEntry)Y=await t.getEntry(W.id);else{const ie=await t.getItem(W.id);ie&&(Y={id:W.id,title:ie.title||W.id,type:ie.type||"work"})}if(Y)return{...Y,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:Z.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(p(te.filter(W=>W!==null)),w(!1))}),()=>{$=!0}},[t,i]);const v=g.useRef(!1),E=g.useRef(!1),R=g.useRef(!1);g.useEffect(()=>{if(S!=="catalog"||v.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;v.current=!0;let O=!1;return $.call(t).then(A=>{O||C(A)}).catch(()=>{v.current=!1}),()=>{O=!0}},[t,S]),g.useEffect(()=>{if(S!=="collection"||E.current||!t.getCollectionProgress)return;E.current=!0;let $=!1;return t.getCollectionProgress().then(O=>{$||_(O)}).catch(()=>{E.current=!1}),()=>{$=!0}},[t,S]),g.useEffect(()=>{if(S!=="site"||R.current||!t.getSiteProgress)return;R.current=!0;let $=!1;return t.getSiteProgress().then(O=>{$||I(O)}).catch(()=>{R.current=!1}),()=>{$=!0}},[t,S]),g.useEffect(()=>{if(!o||S!=="feedback")return;let $=!1;return m(!0),fetch(o).then(O=>O.json()).then(O=>{!$&&O.success&&h(O.items||[])}).catch(()=>{}).finally(()=>{$||m(!1)}),()=>{$=!0}},[o,S]);const P=$=>{switch($){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(xt,{label:l.home.recommendTab,active:S==="recommend",onClick:()=>b("recommend")}),e.jsx(xt,{label:l.home.catalogTab,active:S==="catalog",onClick:()=>b("catalog")}),e.jsx(xt,{label:l.home.collectionTab,active:S==="collection",onClick:()=>b("collection")}),e.jsx(xt,{label:l.home.siteTab,active:S==="site",onClick:()=>b("site")}),o&&e.jsx(xt,{label:l.home.feedbackTab,active:S==="feedback",onClick:()=>b("feedback")})]}),S==="recommend"&&e.jsx(vl,{recommended:d,loading:j,onNavigate:n,getIcon:P,t:l}),S==="catalog"&&e.jsx(fi,{progress:k,t:l,onNavigate:n}),S==="collection"&&e.jsx(fi,{progress:T,t:l,onNavigate:n}),S==="site"&&e.jsx(Sl,{progress:z,t:l,totalWorks:(c==null?void 0:c.works)??0}),S==="feedback"&&o&&e.jsx(Mn,{items:u,loading:y})]})})},xt=({label:t,active:n,onClick:i})=>e.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),vl=({recommended:t,loading:n,onNavigate:i,getIcon:r,t:s})=>{const o=be();if(n)return e.jsx(Xe,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:o(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),p&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]})]},d.id)})})]},c))})},fi=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],o={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"var(--bim-progress-active, #f59e0b)",done:"var(--bim-progress-done, #10b981)",todo:"var(--bim-progress-todo, #9ca3af)"};return e.jsx("div",{children:s.map(c=>{const a=r.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),o[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(jl,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},jl=({item:t,t:n,statusColor:i,onNavigate:r})=>{const s=be(),o=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ct(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Sl=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),o=r.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=i>0?Math.round(l/i*100):0;return e.jsxs("div",{children:[i>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-done, #10b981)"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>e.jsx(gi,{item:a,t:n,totalWorks:i},a.id))})]}),o.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-todo, #9ca3af)"}}),n.home.statusTodo," (",o.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:o.map(a=>e.jsx(gi,{item:a,t:n,totalWorks:i},a.id))})]})]})},gi=({item:t,t:n,totalWorks:i})=>{const r=i>0?Math.round(t.imported/i*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&i>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},mi="(max-width: 768px)";function kl(){const[t,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(mi).matches);return g.useEffect(()=>{const i=window.matchMedia(mi),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),t}const wl=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var O;const o=D(),{convert:l}=M(),c=kl(),[a,d]=g.useState(null),[p,x]=g.useState(null),[f,u]=g.useState(!1),[h,y]=g.useState("detail"),[m,S]=g.useState([]),[b,j]=g.useState(!1),[w,k]=g.useState(null),[C,T]=g.useState(!1),_=g.useCallback(async A=>{if(!t.getCollatedEditionIndex){k(null);return}T(!0);try{const F=await t.getCollatedEditionIndex(A);k(F)}catch{k(null)}finally{T(!1)}},[t]),z=g.useCallback(async A=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){S([]);return}j(!0);try{if(t.getCollectionCatalogs){const F=await t.getCollectionCatalogs(A);S(F||[])}else if(t.getCollectionCatalog){const F=await t.getCollectionCatalog(A);S(F?[{resource_id:"",data:F}]:[])}}catch{S([])}finally{j(!1)}},[t]),I=g.useCallback(async A=>{if(i){i(A);return}d(A),x(null),S([]),k(null),y("detail"),u(!0);try{const F=await t.getItem(A.id);F&&(x(F),F.type==="collection"?z(A.id):F.type==="work"&&F.has_collated&&_(A.id))}catch(F){console.error("加载详情失败:",F)}finally{u(!1)}},[t,i,z,_]),v=g.useCallback(async A=>{x(null),S([]),k(null),y("detail"),u(!0);try{const F=await t.getItem(A);F&&(x(F),d({id:A,title:F.title||A,type:F.type||"book"}),F.type==="collection"?z(A):F.type==="work"&&F.has_collated&&_(A))}catch(F){console.error("导航失败:",F)}finally{u(!1)}},[t,z,_]),E=(p==null?void 0:p.type)==="collection"&&(m.length>0||b)||(p==null?void 0:p.type)==="work"&&(w||C),R=c&&(f||p),P=g.useCallback(()=>{d(null),x(null),S([]),k(null),y("detail")},[]),$=e.jsx(e.Fragment,{children:f?e.jsx(Xe,{}):p?e.jsxs(e.Fragment,{children:[(E||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[E&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y("detail"),style:Wt(h==="detail"),children:o.detailTab.basicInfo}),p.type==="collection"&&b&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:Wt(!1),children:[o.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&m.map(A=>e.jsx("button",{onClick:()=>y(`catalog:${A.resource_id}`),style:Wt(h===`catalog:${A.resource_id}`),children:A.short_name?`${l(A.short_name)}${o.detailTab.catalogSuffix}`:o.detailTab.collectionCatalog},A.resource_id)),p.type==="work"&&(w||C)&&e.jsxs("button",{onClick:()=>y("collated"),style:Wt(h==="collated"),children:[o.detailTab.collatedEdition,C&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?e.jsx(wn,{data:p,transport:t,onNavigate:v}):h.startsWith("catalog:")?e.jsx(_n,{data:(O=m.find(A=>`catalog:${A.resource_id}`===h))==null?void 0:O.data,onNavigate:v}):h==="collated"?e.jsx(Pn,{index:w||void 0,workId:p.id,transport:t,onNavigate:v}):null})]}):e.jsx(mn,{transport:t,onNavigate:v,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:R?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:P,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",o.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(dn,{transport:t,onEntryClick:I,hideModeIndicator:n}),!p&&e.jsx(mn,{transport:t,onNavigate:v,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(dn,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Wt(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Ne(t){return t.replace(/\.md$/,"")}const Lr=({index:t,bookId:n,transport:i,activeChapter:r,onChapterChange:s})=>{const[o,l]=g.useState(t??null),[c,a]=g.useState(null),d=r!==void 0?r:c,p=g.useCallback(S=>{s?s(S):a(S)},[s]),[x,f]=g.useState(null),[u,h]=g.useState(!1);g.useEffect(()=>{t&&l(t)},[t]),g.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let S=!1;return i.getBookFullTextIndex(n).then(b=>{S||l(b)}),()=>{S=!0}},[n,i,t]),g.useEffect(()=>{if(!o||o.chapters.length===0)return;const S=Ne(o.chapters[0].file);if(!d){p(S);return}const b=Ne(d);o.chapters.some(w=>Ne(w.file)===b)||p(S)},[o,d,p]);const y=g.useMemo(()=>{if(!o||!d)return null;const S=Ne(d);return o.chapters.find(b=>Ne(b.file)===S)??null},[o,d]);if(g.useEffect(()=>{if(!n||!y||!i.getBookFullTextChapter)return;let S=!1;return h(!0),f(null),i.getBookFullTextChapter(n,y.file).then(b=>{S||f(b)}).catch(()=>{S||f(null)}).finally(()=>{S||h(!1)}),()=>{S=!0}},[n,y,i]),!o)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"});if(o.chapters.length===0)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"});const m=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"0 8px 8px",fontSize:12.5,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:o.version_label}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.chapters.map(S=>{const b=Ne(S.file),j=b===Ne(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(b),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:j?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:j?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:j?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:S.title})},S.file)})})]});return e.jsx(br,{aside:m,children:e.jsxs("div",{children:[y&&e.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[e.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:y.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:o.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:o.source.name}),o.source.license&&e.jsxs(e.Fragment,{children:[" · ",o.source.license]})]})]}),u&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!u&&x&&e.jsx("article",{style:{fontSize:16,lineHeight:1.9,color:"var(--bim-fg, #2c2c2c)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:'"Songti SC", "Source Han Serif", "Noto Serif CJK SC", serif'},children:x.replace(/^##\s+[^\n]+\n+/,"")}),!u&&!x&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})})},_l=({data:t,onNavigate:n,className:i,style:r})=>{var p;const s=D(),{convert:o}=M(),[l,c]=g.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[a,d]=g.useState(null);return e.jsxs("div",{className:i,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Cl,{division:x,expanded:l===x.name,onToggle:()=>c(l===x.name?null:x.name),expandedCat:a,onCatToggle:f=>d(a===f?null:f),onNavigate:n},x.name))})]})},Cl=({division:t,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:o})=>{const{convert:l}=M(),c=t.categories.reduce((a,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return a+(p.zhulu||0)+(p.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(Il,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:o},a.name)})})]})},Il=({category:t,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,p,x;const{convert:s}=M(),o=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||o.length)+(((x=t.stats)==null?void 0:x.cunmu)||l.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(o.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[o.length>0&&e.jsx(hi,{label:"著錄",books:o,onNavigate:r}),l.length>0&&e.jsx(hi,{label:"存目",books:l,onNavigate:r})]})]})},hi=({label:t,books:n,onNavigate:i})=>{const{convert:r}=M(),s=be(),[o,l]=g.useState(n.length<=20),c=o?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&i?e.jsx("a",{href:s(a.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},d))}),!o&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ke=({title:t,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const o=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&e.jsx("button",{onClick:i,style:zl,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Tl,children:o.action.save})]})]}),s]})},Tl={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},zl={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},he=({label:t,value:n,onChange:i,placeholder:r,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:o=>i(o.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),Ue=({value:t,onChange:n,placeholder:i})=>{const r=g.useRef(null);return g.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Dt=({children:t,color:n,style:i})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...i},children:t});function Rl(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Pt=({value:t,onChange:n,label:i})=>{const[r,s]=g.useState(!1),o=g.useRef(null),l=Rl(t||"");return g.useEffect(()=>{r&&o.current&&o.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,children:i}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),e.jsx(Dt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,children:i}),e.jsx("input",{ref:o,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},bi={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function El(t){switch(t){case"url":return"var(--bim-source-url, #2196f3)";case"bookID":return"var(--bim-source-bookid, #4caf50)";default:return"var(--bim-desc-fg, #717171)"}}function Bl(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Wr=({items:t,onChange:n,onOpenEntityPicker:i})=>{const r=D(),[s,o]=g.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),o(t.length)},c=x=>{n(t.filter((f,u)=>u!==x)),s===x&&o(null)},a=(x,f,u)=>{const h=[...t];h[x]={...h[x],[f]:u},n(h)},d=(x,f)=>{const u=[...t];u[x]={...u[x],type:f,id:"",name:""},n(u),f==="bookID"&&i&&i(h=>{const y=[...t];y[x]={...y[x],id:h.id,name:h.title,type:"bookID"},n(y)})},p=x=>{i&&i(f=>{const u=[...t];u[x]={...u[x],id:f.id,name:f.title,type:"bookID"},n(u)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,f)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>o(s===f?null:f),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===f?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${f+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:El(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Bl(x.type)}),e.jsx("button",{onClick:u=>{u.stopPropagation(),c(f)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===f&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(f,"bookID"),style:{...yi,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(f,"url"),style:{...yi,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[f]={...u[f],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-source-bookid, #4caf50)",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"var(--bim-source-bookid, #4caf50)",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>p(f),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>p(f),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[f]={...u[f],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:u=>a(f,"name",u.target.value),placeholder:r.editor.sourceNamePlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:u=>a(f,"id",u.target.value),placeholder:"https://...",style:et})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...$e,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:u=>a(f,"details",u.target.value),placeholder:r.editor.detailsPlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:u=>a(f,"position",u.target.value),placeholder:"如: 卷三, p.52",style:et})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:u=>a(f,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:u=>a(f,"processor_version",u.target.value),placeholder:"如: v0.1",style:et})]})]})]})]})})]},f)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},$e={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},et={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},yi={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},vi={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function $r(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Ar(t){return!t||t.length===0?"":JSON.stringify(t)}const Pr=({entityType:t,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:o,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:x,onUnlinkEntity:f,onViewEntity:u,onCreateAndLink:h,onSaveRelations:y})=>{const m=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:m.section.relations})]}),y&&e.jsx("button",{onClick:y,style:Ll,children:m.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:m.relation.belongsToWork,entity:o,onView:u,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(ft,{direction:"up",title:m.relation.containedInCollection,entity:l,onView:u,onUnlink:()=>f("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),o&&p&&p.length>0&&e.jsx(tt,{direction:"horizontal",title:`${m.relation.siblingVersions} (${p.length})`,entities:p,onView:u,onAdd:()=>h("siblingBook","book",{workId:o.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:m.relation.parentWork,entity:r,onView:u,onUnlink:()=>f("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),c&&c.length>0&&e.jsx(tt,{direction:"down",title:`${m.relation.childWorks} (${c.length})`,entities:c,onView:u,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),a&&a.length>0&&e.jsx(tt,{direction:"down",title:`${m.relation.collectionImpl} (${a.length})`,entities:a,onView:u,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(tt,{direction:"down",title:`${m.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>h("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:m.relation.correspondingWork,entity:o,onView:u,onUnlink:()=>f("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(ft,{direction:"up",title:m.relation.parentCollection,entity:s,onView:u,onUnlink:()=>f("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(tt,{direction:"down",title:`${m.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:u,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(tt,{direction:"down",title:`${m.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},ft=({direction:t,title:n,entity:i,onView:r,onUnlink:s,onLink:o,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:p,unlinkLabel:x})=>{const f=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",u=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:f,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:u}),e.jsx("span",{children:n})]}),i?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Mr(i.type)}),e.jsx("span",{style:{fontWeight:500},children:i.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(ji,{onClick:()=>r(i),title:p,children:"👁️"}),e.jsx(ji,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(hn,{onClick:o,children:c}),e.jsx(hn,{onClick:l,primary:!0,children:a})]})]})},tt=({direction:t,title:n,entities:i,onView:r,onAdd:s,addLabel:o,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=g.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",f=a?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[f.map(u=>e.jsxs("div",{onClick:()=>r(u),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Mr(u.type)}),e.jsx("span",{children:u.title})]},u.id)),i.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",i.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(hn,{onClick:s,primary:!0,children:["+ ",o]})})]})},ji=({onClick:t,title:n,danger:i,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),hn=({onClick:t,primary:n,children:i})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:i});function Mr(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Ll={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Fr=({isOpen:t,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:o,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,x]=g.useState(""),f=d?l.filter(m=>m.id!==d):l;g.useEffect(()=>{t&&(x(""),c(""))},[t]);const u=m=>{x(m),c(m)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Wl,children:e.jsxs("div",{style:$l,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),e.jsx("button",{onClick:s,style:Al,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:m=>u(m.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:Pl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:on,children:"搜索中..."}):f.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:f.map(m=>e.jsxs("div",{onClick:()=>r(m),style:Ml,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):p?e.jsxs("div",{style:on,children:["未找到匹配的",h]}):e.jsxs("div",{style:on,children:["输入关键词搜索",h]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:o,style:Fl,children:["创建新",h,"并关联"]})]})]})})},Wl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},$l={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Al={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Pl={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Ml={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},on={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Fl={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Si={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Hl={work:"📜",book:"📖",collection:"📚",entity:"👤"},Hr=({isOpen:t,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:o})=>{const[l,c]=g.useState(""),a=g.useRef(null);g.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var f,u;(f=a.current)==null||f.focus(),(u=a.current)==null||u.select()},100))},[t,r==null?void 0:r.title]);const d=f=>{f.key==="Enter"&&l.trim()?p():f.key==="Escape"&&o()},p=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const x=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Si[n]}`}};return e.jsx("div",{style:Ol,onClick:f=>{f.target===f.currentTarget&&o()},children:e.jsxs("div",{style:Dl,onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Hl[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:f=>c(f.target.value),onKeyDown:d,placeholder:`请输入${Si[n]}名称...`,style:Nl})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:o,style:Vl,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...Gl,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Ol={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Dl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Nl={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},Vl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Gl={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Yl(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Or(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ul(t){switch(t){case"work":return"var(--bim-editor-type-work, #4caf50)";case"collection":return"var(--bim-editor-type-collection, #2196f3)";case"book":return"var(--bim-editor-type-book, #ff9800)";default:return"var(--bim-desc-fg, #717171)"}}const Dr=({isOpen:t,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:o=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:p})=>{const[x,f]=g.useState(""),[u,h]=g.useState([]),[y,m]=g.useState(!1),[S,b]=g.useState("recent");g.useEffect(()=>{t&&(f(""),h([]),b(r.length>0?"recent":"search"))},[t,r.length]),g.useEffect(()=>{if(!x.trim()){h([]);return}const _=setTimeout(async()=>{m(!0);try{h(await p(x,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(_)},[x,i,p]);const j=g.useCallback(_=>{f(_.target.value),_.target.value.trim()&&b("search")},[]),w=g.useCallback(_=>s?_.filter(z=>z.id!==s):_,[s]);if(!t)return null;const k=n||(i==="all"?"选择实体":`选择${Or(i)}`),C=w(r),T=w(u);return e.jsx("div",{style:Jl,children:e.jsxs("div",{style:ql,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),e.jsx("button",{onClick:a,style:Xl,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Zl}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),C.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(ki,{active:S==="recent",onClick:()=>b("recent"),children:["最近使用 (",C.length,")"]}),e.jsxs(ki,{active:S==="search",onClick:()=>b("search"),children:["搜索结果 ",T.length>0&&`(${T.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&C.length>0?e.jsx(wi,{entities:C,onSelect:c}):x.trim()?y?e.jsx(sn,{message:"搜索中..."}):T.length>0?e.jsx(wi,{entities:T,onSelect:c}):e.jsx(sn,{message:"未找到匹配的结果"}):e.jsx(sn,{message:"输入关键词开始搜索"})}),o&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:Ql,children:l||"创建新实体"})]})]})})},ki=({active:t,onClick:n,children:i})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:i}),wi=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(Kl,{entity:i,onClick:()=>n(i)},i.id))}),Kl=({entity:t,onClick:n})=>{const[i,r]=g.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Yl(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Ul(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Or(t.type)})]})},sn=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Jl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ql={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Xl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Zl={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Ql={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ea={work:"var(--bim-editor-type-work, #4caf50)",collection:"var(--bim-editor-type-collection, #2196f3)",book:"var(--bim-editor-type-book, #ff9800)",entity:"var(--bim-editor-type-entity, #9c27b0)"},ta={work:"📜",collection:"📚",book:"📖",entity:"👤"},Nr=({data:t,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:o,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:x,onRelationsChange:f})=>{var ne;const u=D(),[h,y]=g.useState(!1),[m,S]=g.useState("work"),[b,j]=g.useState(""),[w,k]=g.useState(""),[C,T]=g.useState([]),[_,z]=g.useState(!1),[I,v]=g.useState(!1),[E,R]=g.useState("work"),[P,$]=g.useState(""),[O,A]=g.useState(),[F,te]=g.useState(!1),[W,Y]=g.useState(null),[ie,K]=g.useState([]);g.useRef(null);const L=t.type,U=L==="work",J=L==="collection",V=L==="book",G=g.useCallback((B,Q)=>{n({...t,[B]:Q})},[t,n]),de=g.useCallback((B,Q)=>{j(B),S(Q),k(u.editor.selectToLink+u.indexType[Q]),T([]),y(!0)},[u]),Se=g.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,B)},[r,t.id]),me=g.useCallback(B=>{s==null||s(B.id,B.type)},[s]),se=g.useCallback((B,Q,le)=>{const q={...le,author:(le==null?void 0:le.author)||t.author,dynasty:le==null?void 0:le.dynasty};R(Q),$(B),A(q),v(!0)},[t.author]),ye=g.useCallback((B,Q)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,P,{type:E,title:B,inheritData:Q}),v(!1)},[r,t.id,P,E]),Ie=g.useCallback(B=>{if(!B.trim()){T([]);return}z(!0),r!=null&&r.searchEntities&&r.searchEntities(B,m).then(Q=>{T(Q),z(!1)}).catch(()=>{T([]),z(!1)})},[r,m]),Te=g.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,b,B.id),y(!1)},[r,t.id,b]),Ze=g.useCallback(()=>{i()},[i]),ct=g.useCallback(B=>{Y(()=>B),te(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(K).catch(()=>{})},[r]),N=g.useCallback((B,Q)=>r!=null&&r.searchEntities?r.searchEntities(B,Q==="all"?void 0:Q):Promise.resolve([]),[r]),oe=g.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),K(Q=>[B,...Q.filter(le=>le.id!==B.id)].slice(0,10)),W==null||W(B),te(!1),Y(null)},[r,W]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:ta[L]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Dt,{children:t.id}),e.jsx(Dt,{color:ea[L],children:u.indexType[L]})]})}),e.jsx(ke,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Pt,{label:U?u.editor.workTitle:J?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:B=>G("title",B)}),V&&e.jsx(Pt,{label:u.editor.belongsToWork,value:t.workName||"",onChange:B=>G("workName",B)}),e.jsx(he,{label:u.editor.authorLabel,value:t.author||"",onChange:B=>G("author",B)}),e.jsx(he,{label:u.editor.publicationYearLabel,value:t.publicationYear||"",onChange:B=>G("publicationYear",B)}),(V||J)&&e.jsx(Pt,{label:u.editor.containedIn,value:t.collection||"",onChange:B=>G("collection",B)}),(V||J)&&e.jsx(he,{label:u.editor.holderLabel,value:t.holder||"",onChange:B=>G("holder",B)}),(V||J)&&e.jsx(he,{label:V?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:B=>G("pages",B)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(he,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:B=>G("firstImage",B)})})]})}),e.jsx(ke,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Ue,{value:t.description||"",onChange:B=>G("description",B),placeholder:u.editor.descriptionPlaceholder})}),(((ne=t.additional_works)==null?void 0:ne.length)||0)>0&&e.jsx(ke,{title:u.section.additionalWorks,onSave:i,children:e.jsx(na,{items:t.additional_works||[],onChange:B=>G("additional_works",B)})}),e.jsx(ke,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(ia,{items:t.indexed_by||[],onChange:B=>G("indexed_by",B)})}),e.jsx(ke,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(ra,{items:t.emendated_by||[],onChange:B=>G("emendated_by",B)})}),e.jsx(ke,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(cn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(ke,{title:u.section.imageResources,onSave:i,children:e.jsx(cn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(ke,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Wr,{items:$r(t.sources||""),onChange:B=>G("sources",Ar(B)),onOpenEntityPicker:ct})}),(V||J)&&e.jsx(ke,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Ue,{value:t.provenance||"",onChange:B=>G("provenance",B),placeholder:u.editor.provenancePlaceholder})}),V&&e.jsx(ke,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Ue,{value:t.otherEditions||"",onChange:B=>G("otherEditions",B),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(Pr,{entityType:L,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:de,onUnlinkEntity:Se,onViewEntity:me,onCreateAndLink:se,onSaveRelations:Ze}),o&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:u.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:u.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:u.editor.deleteEntity})]}),e.jsx(Fr,{isOpen:h,entityType:m,title:w,onSelect:Te,onCancel:()=>y(!1),onCreate:()=>{y(!1),se(b,m)},searchResults:C,onSearch:Ie,isLoading:_,excludeId:t.id}),e.jsx(Hr,{isOpen:I,entityType:E,relationField:P,inheritData:O,onConfirm:ye,onCancel:()=>v(!1)}),e.jsx(Dr,{isOpen:F,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ie,excludeId:t.id,onSelect:oe,onCancel:()=>{te(!1),Y(null)},onSearch:N})]})};function na({items:t,onChange:n}){const i=D(),r=(l,c,a)=>{const d=t.map((p,x)=>x===l?{...p,[c]:a}:p);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),o=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(he,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(he,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:o,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Vr({items:t,onChange:n,showMeta:i,addLabel:r}){const s=D(),[o,l]=g.useState(null),c=(p,x,f)=>{const u=t.map((h,y)=>y===p?{...h,[x]:f||void 0}:h);n(u)},a=p=>{n(t.filter((x,f)=>f!==p)),o===p&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,x)=>{const f=o===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:f?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(f?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:f?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:p.source||s.editor.unnamedSource}),p.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:p.source_bid}),e.jsx("button",{onClick:u=>{u.stopPropagation(),a(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)"},children:"✕"})]}),!f&&i&&(p.title_info||p.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[p.title_info,p.title_info&&p.author_info&&" — ",p.author_info]}),f&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(he,{label:s.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),e.jsx(he,{label:s.label.sourceBid,value:p.source_bid||"",onChange:u=>c(x,"source_bid",u)})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(he,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),e.jsx(he,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),e.jsx(he,{label:s.label.edition,value:p.edition||"",onChange:u=>c(x,"edition",u)})]}),e.jsx(Ue,{value:p.summary||"",onChange:u=>c(x,"summary",u),placeholder:s.editor.summaryPlaceholder}),e.jsx(Ue,{value:p.comment||"",onChange:u=>c(x,"comment",u),placeholder:s.editor.commentPlaceholder}),e.jsx(Ue,{value:p.additional_comment||"",onChange:u=>c(x,"additional_comment",u),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:r})]})}function ia({items:t,onChange:n}){const i=D();return e.jsx(Vr,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function ra({items:t,onChange:n}){const i=D();return e.jsx(Vr,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function Gr(t){var c,a,d,p,x,f,u;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",r=((p=t.current_location)==null?void 0:p.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((f=t.page_count)==null?void 0:f.description)||"",o=typeof t.description=="object"&&t.description!==null&&t.description.text||"",l={id:t.id,title:t.title,type:t.type,author:n,publicationYear:i,holder:r,pages:s,description:o,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const h=t;if(Array.isArray(h.related_works)){const y=h.related_works.find(m=>m.relation==="part_of");y&&(l.parentWorkId=y.id,l.parentWorkName=y.title)}}if(t.type==="book"){const h=t;l.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(l.collectionId=(u=h.contained_in[0])==null?void 0:u.id)}return l}function oa(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.publicationYear?{year:t.publicationYear}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const sa=t=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:o,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:x,renderSectionActions:f,onDownloadResource:u,downloadStatuses:h,relations:y,onRelationsChange:m,headerExtra:S,className:b,style:j}=t;D();const[w,k]=g.useState(s),C=o?s:w;g.useEffect(()=>{s!==w&&k(s)},[s]);const T=g.useCallback(()=>{const P=C==="view"?"edit":"view";o?o(P):k(P)},[C,o]),[_,z]=g.useState(null);g.useEffect(()=>{i&&r&&r.getItem(i).then(P=>{P&&z(P)})},[i,r]);const I=n||_,v=g.useMemo(()=>I?Gr(I):null,[I]),E=o||!n?e.jsx("button",{onClick:T,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:C==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:C==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:C==="view"?"切换到编辑模式":"切换到查看模式",children:C==="view"?"✏️ 编辑":"👁 查看"}):null,R=e.jsxs(e.Fragment,{children:[E,S]});return!I&&!v?e.jsx(Xe,{}):C==="view"?e.jsx(wn,{data:I,transport:r,onNavigate:d?P=>d(P):void 0,renderLink:p,headerExtra:R,className:b,style:j}):v?e.jsxs("div",{className:b,style:j,children:[R&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:R}),e.jsx(Nr,{data:v,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:x,renderSectionActions:f,onDownloadResource:u,downloadStatuses:h,relations:y,onRelationsChange:m})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},_i=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Yr=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,o]=g.useState(null),[l,c]=g.useState(""),[a,d]=g.useState("idle"),[p,x]=g.useState(""),f=g.useRef(null);g.useEffect(()=>{t&&(o(null),c(""),d("idle"),x(""))},[t]),g.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=f.current)==null?void 0:m.focus()},100)},[s]),g.useEffect(()=>{if(a==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[a,n]),g.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const u=async()=>{if(!(!s||!l.trim())){d("submitting"),x("");try{await i({type:s,content:l.trim()}),d("success")}catch(m){d("error"),x(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&l.trim()&&a!=="submitting",y=_i.find(m=>m.value===s);return e.jsx("div",{style:la,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:aa,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:ca,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:da,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:ga,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:_i.map(m=>e.jsxs("button",{onClick:()=>o(m.value),style:{...pa,...s===m.value?ua:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:f,value:l,onChange:m=>c(m.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...xa,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),a==="error"&&e.jsx("div",{style:ma,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:u,disabled:!h,style:{...fa,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},la={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},aa={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ca={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},da={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},pa={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ua={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},xa={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},fa={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ga={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ma={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ha=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[r,s]=g.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...ba,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.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"})})}),e.jsx(Yr,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},ba={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},Ci=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ur=({onSubmit:t})=>{const[n,i]=g.useState("bug"),[r,s]=g.useState(""),[o,l]=g.useState("idle"),[c,a]=g.useState(""),d=g.useRef(null);g.useEffect(()=>{n&&setTimeout(()=>{var u;return(u=d.current)==null?void 0:u.focus()},100)},[n]);const p=async()=>{if(!(!n||!r.trim())){l("submitting"),a("");try{await t({type:n,content:r.trim()}),l("success"),s(""),i("bug")}catch(u){l("error"),a(u instanceof Error?u.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&o!=="submitting",f=Ci.find(u=>u.value===n);return o==="success"?e.jsx("div",{style:Ii,children:e.jsxs("div",{style:ka,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:wa,children:"继续提交"})]})}):e.jsxs("div",{style:Ii,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ci.map(u=>e.jsxs("button",{onClick:()=>i(u.value),style:{...ya,...n===u.value?va:{}},children:[e.jsx("span",{children:u.icon})," ",u.label]},u.value))}),e.jsx("textarea",{ref:d,value:r,onChange:u=>s(u.target.value),placeholder:(f==null?void 0:f.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:o==="submitting",style:{...ja}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:p,disabled:!x,style:{...Sa,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:o==="submitting"?"提交中...":"提交"})]}),o==="error"&&e.jsx("div",{style:_a,children:c})]})},Ii={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},ya={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},va={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ja={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Sa={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ka={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},wa={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},_a={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Ti(t){return typeof t=="function"?t():t??"/api/feedback"}const Kr=({resourceId:t,apiUrl:n})=>{const[i,r]=g.useState([]),[s,o]=g.useState(!0),l=g.useCallback(async()=>{const a=Ti(n);o(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&r(p.items)}catch{}finally{o(!1)}},[t,n]);g.useEffect(()=>{l()},[l]);const c=async a=>{const d=Ti(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!p.ok){const x=await p.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(Mn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(Ur,{onSubmit:c})})]})},ht={versions:12,catalogs:8,chips:12},Jr={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},qr=({data:t,transport:n,onNavigate:i,renderLink:r,lineageAction:s,collatedSection:o})=>{var E,R,P,$,O,A,F,te,W,Y,ie,K;const l=D(),{convert:c}=M(),a=g.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[d,p]=g.useState(new Map),[x,f]=g.useState(!1),[u,h]=g.useState(""),[y,m]=g.useState(!1),[S,b]=g.useState("default"),j=x||!!u||y||S==="year",w=g.useMemo(()=>j?a:a.slice(0,ht.versions),[a,j]);g.useEffect(()=>{if(!n||w.length===0)return;const L=w.filter(J=>!d.has(J));if(L.length===0)return;let U=!1;return Promise.all(L.map(J=>n.getItem(J).then(V=>{const G=V??{};return[J,{id:J,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[J,{id:J}]))).then(J=>{U||p(V=>{const G=new Map(V);for(const[de,Se]of J)G.set(de,Se);return G})}),()=>{U=!0}},[n,w,d]);const k=g.useMemo(()=>a.map(L=>d.get(L)??{id:L}),[a,d]),C=g.useMemo(()=>pr(k,t.version_graph,{era:u,scanOnly:y,sort:S}),[k,t.version_graph,u,y,S]),T=x?C.rows:C.rows.slice(0,ht.versions),_=g.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),z=g.useMemo(()=>cr((t.related_works||[]).map(L=>({id:L.id,title:L.title,relation:L.relation}))),[t.related_works]),I=g.useMemo(()=>{var G,de,Se,me;const L=[],U=(de=(G=t.authors)==null?void 0:G[0])==null?void 0:de.dynasty;U&&L.push({label:"成書",value:c(U)});const J=Je(t,l.unit.juan);if(J){const se=(Se=t.juan_count)==null?void 0:Se.description;L.push({label:"卷帙",value:c(J),title:se?c(se):void 0})}const V=C.allRows.filter(se=>se.sortYear!=null);if(V.length>0){const se=V.reduce((ye,Ie)=>ye.sortYear<=Ie.sortYear?ye:Ie);se.era.era&&L.push({label:"最早存世刻本",value:`${se.era.era}${se.era.reign?" "+se.era.reign:""}`,title:se.era.source==="edition"?"據版本題名推斷":void 0})}return(me=t.indexed_by)!=null&&me.length&&L.push({label:"著錄",value:`${t.indexed_by.length} ${l.unit.bu}`}),L},[t,c,l,C.allRows,j,a.length]),v=!o&&a.length===0&&_.buckets.length===0&&_.mirrors.length===0&&!((E=t.indexed_by)!=null&&E.length)&&!((R=t.emendated_by)!=null&&R.length)&&z.length===0&&!((P=t.description)!=null&&P.text);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:I.length?e.jsx(zt,{items:I}):void 0,children:[(($=t.description)==null?void 0:$.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(O=t.description.sources)!=null&&O.length?e.jsx("div",{className:"bim-d-ui",style:{marginTop:8,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:t.description.sources.map(L=>c($s(L))).filter(Boolean).join(" · ")}):null]}),(A=t.appendix)==null?void 0:A.map((L,U)=>e.jsxs("details",{style:{marginTop:12},children:[e.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)",display:"inline-block"},children:c(L.title)}),e.jsx(Pe,{text:L.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},U)),e.jsx(Cr,{rows:[{label:l.section.aliases,items:wt(t.additional_titles)},{label:l.section.attachedTexts,items:wt(t.attached_texts)},{label:l.section.appendix,items:(t.additional_works||[]).map(L=>L.book_title+(L.n_juan!=null?` ${L.n_juan}${l.unit.juan}`:""))}]})]}),o,a.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"版",title:l.section.relatedVersions,count:C.rows.length===C.allRows.length?`${C.allRows.length} 種`:`${C.allRows.length} 種 · 當前 ${C.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(He,{label:"僅看有影印",active:y,dashed:!0,onClick:()=>{m(L=>!L),f(!1)}}),e.jsx(Ut,{label:S==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>b(L=>L==="default"?"year":"default")})]})}),C.allRows.length>=6&&C.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(He,{label:l.catalog.all,active:!u,onClick:()=>{h(""),f(!1)}}),C.eras.map(L=>e.jsx(He,{label:L,active:u===L,onClick:()=>{h(L),f(!1)}},L))]}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:Jr}),T.map((L,U)=>e.jsx(Ta,{row:L,no:U,onNavigate:i,renderLink:r},L.id)),T.length===0&&e.jsx(st,{children:u||y?"當前篩選下沒有版本":"暫無版本著錄"})]}),C.rows.length>T.length&&e.jsx(De,{label:`展開其餘 ${C.rows.length-T.length} 種版本`,onClick:()=>f(!0)}),C.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(_.buckets.length>0||_.mirrors.length>0)&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[_.mirrors.map(L=>e.jsx(xn,{title:c(L.label),tag:L.description?c(L.description):void 0,children:L.items.map((U,J)=>e.jsx(ot,{item:U,siblings:L.items},`${U.id||U.url||U.name}-${J}`))},L.key)),_.buckets.map(L=>e.jsx(xn,{title:Ca[L.key],tag:Ia[L.key],children:L.items.map((U,J)=>e.jsx(ot,{item:U,siblings:L.items},`${U.id||U.url||U.name}-${J}`))},L.key))]})]}),(F=t.indexed_by)!=null&&F.length||(te=t.emendated_by)!=null&&te.length?e.jsxs("div",{className:(W=t.emendated_by)!=null&&W.length?"bim-d-pair":void 0,style:(Y=t.emendated_by)!=null&&Y.length?void 0:{marginBottom:48},children:[(ie=t.indexed_by)!=null&&ie.length?e.jsx(Ri,{id:"catalogs",glyph:"目",title:l.section.indexed,items:t.indexed_by,unit:l.unit.bu,cap:ht.catalogs,showMeta:!0,t:l,convert:c,onNavigate:i,renderLink:r}):null,(K=t.emendated_by)!=null&&K.length?e.jsx(Ri,{id:"studies",glyph:"考",title:l.section.emendated,items:t.emendated_by,unit:l.unit.bu,cap:ht.catalogs,t:l,convert:c,onNavigate:i,renderLink:r}):null]}):null,z.map(L=>e.jsx(za,{glyph:L.key==="derivative"?"續":"叢",title:l.section[L.labelKey]??l.section.relatedWorks,items:L.items,convert:c,onNavigate:i,renderLink:r},L.key)),v&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:l.section.relatedVersions}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},Ca={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},Ia={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function Ta({row:t,no:n,onNavigate:i,renderLink:r}){const{convert:s}=M(),o=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(qt,{no:Xt(n),spec:Jr,main:e.jsx(_e,{id:t.id,label:s(t.name),onNavigate:i,renderLink:r,dense:!0,style:{fontWeight:t.important?600:400}}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".04em"},title:l?"據版本題名推斷":void 0,children:o||e.jsx(rt,{})}),e.jsx(zi,{items:t.images,convert:s}),e.jsx(zi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function zi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(rt,{});if(t.length===1){const l=t[0],c=(l.url?St(l.url):void 0)||n(l.name),a=Ft(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(fn,{href:a,children:c}):c})}const r=t[0],s=(r.url?St(r.url):void 0)||n(r.name),o=Ft(r);return e.jsxs("span",{style:{minWidth:0},children:[o?e.jsx(fn,{href:o,children:s}):s,e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:4,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:["+",t.length-1]})]})}function Ri({id:t,glyph:n,title:i,items:r,unit:s,cap:o,showMeta:l,t:c,convert:a,onNavigate:d,renderLink:p}){const[x,f]=g.useState({}),[u,h]=g.useState(!1),y=r.length>0&&r.every((b,j)=>x[j]),m=g.useCallback(()=>{f(y?{}:Object.fromEntries(r.map((b,j)=>[j,!0])))},[y,r]),S=u?r:r.slice(0,o);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(ue,{glyph:n,tone:"ink",title:i,count:`${r.length} ${s}`,actions:e.jsx(Ut,{label:y?"收起全部":"+ 展開提要",onClick:m})}),e.jsx(qe,{children:S.map((b,j)=>{const w=b;return e.jsxs(kr,{open:!!x[j],onToggle:()=>f(k=>({...k,[j]:!k[j]})),main:e.jsxs(e.Fragment,{children:[w.source_bid?e.jsx(_e,{id:w.source_bid,label:a(w.source),onNavigate:d,renderLink:p,dense:!0}):a(w.source),l&&w.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(w.section)})]}),action:w.source_bid?e.jsx(_e,{id:w.source_bid,label:c.action.view,onNavigate:d,renderLink:p,dense:!0,style:{fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"}}):void 0,children:[l&&(w.title_info||w.author_info||w.edition)&&e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:"4px 16px",marginBottom:8,fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:[w.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",a(w.title_info)]}),w.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",a(w.author_info)]}),w.edition&&e.jsxs("span",{children:[c.label.edition," ",a(w.edition)]})]}),w.summary&&e.jsx(At,{children:Oe(a(w.summary))}),w.comment&&e.jsx(At,{label:c.section.comment,children:Oe(a(w.comment))}),w.additional_comment&&e.jsx(At,{label:c.section.additionalComment,children:Oe(a(w.additional_comment))}),l&&w.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:w.page})]},j)})}),r.length>S.length&&e.jsx(De,{label:`展開其餘 ${r.length-S.length} ${s}`,onClick:()=>h(!0)})]})}function za({glyph:t,title:n,items:i,convert:r,onNavigate:s,renderLink:o}){const[l,c]=g.useState(!1),a=l?i:i.slice(0,ht.chips);return e.jsxs(Ce,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Kt,{children:[a.map(d=>e.jsx(Rt,{children:e.jsx(_e,{id:d.id,label:r(d.title),onNavigate:s,renderLink:o,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx(De,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const Ra=8,Xr=({data:t,transport:n,onNavigate:i,renderLink:r,fullTextSection:s})=>{var w,k,C,T;const o=D(),{convert:l}=M(),[c,a]=g.useState(null),[d,p]=g.useState(new Map),[x,f]=g.useState([]),[u,h]=g.useState(!1);g.useEffect(()=>{if(!n||!t.work_id){a(null);return}let _=!1;return n.getItem(t.work_id).then(z=>{!_&&z&&z.type==="work"&&a(z)}).catch(()=>{}),()=>{_=!0}},[n,t.work_id]),g.useEffect(()=>{const _=t.contained_in||[];if(!n||_.length===0){p(new Map);return}let z=!1;return Promise.all(_.map(I=>{const v=typeof I=="string"?I:I.id;return n.getItem(v).then(E=>[v,E]).catch(()=>[v,null])})).then(I=>{if(z)return;const v=new Map;for(const[E,R]of I)R&&v.set(E,R);p(v)}),()=>{z=!0}},[n,t.contained_in]);const y=g.useMemo(()=>{const _=new Set([...(c==null?void 0:c.books)||[],...t.related_books||[]]);return _.delete(t.id),[..._]},[c==null?void 0:c.books,t.related_books,t.id]);g.useEffect(()=>{if(!n||y.length===0){f([]);return}const _=u?y:y.slice(0,Ra);let z=!1;return Promise.all(_.map(I=>n.getItem(I).then(v=>({id:I,title:v==null?void 0:v.title,edition:v==null?void 0:v.edition})).catch(()=>({id:I})))).then(I=>{z||f(I)}),()=>{z=!0}},[n,y,u]);const m=g.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=g.useMemo(()=>{var P,$,O;const _=[],z=It(t),I=mr(t);I&&_.push({label:"版本類型",value:I,title:(P=t.lineage)!=null&&P.category?void 0:"據版本題名推斷"}),(z.era||z.reign)&&_.push({label:"刊寫年代",value:[z.era,z.reign].filter(Boolean).join(" "),title:z.source==="edition"?"據版本題名推斷":void 0});const v=(t.contained_in||[]).flatMap(A=>typeof A=="string"?[]:vt(A.volume_index));v.length&&(_.push({label:"冊數",value:`${v.length} ${o.unit.volume}`}),_.push({label:"冊次",value:`第 ${En(v,o.unit.volume)} ${o.unit.volume}`}));const E=Je(t,o.unit.juan);E&&_.push({label:"卷帙",value:l(E)});const R=(t.resources||[]).filter(A=>(A.types||(A.type?[A.type]:[])).includes("physical"));return R.length?_.push({label:"存藏",value:R.slice(0,2).map(A=>l(A.name)).join("、")+(R.length>2?` 等 ${R.length} 處`:"")}):($=t.current_location)!=null&&$.name&&_.push({label:"存藏",value:l(t.current_location.name)}),(O=t.page_count)!=null&&O.description&&_.push({label:o.label.pageCount,value:t.page_count.description}),_},[t,l,o]),b=!!((w=t.description)!=null&&w.text),j=(t.contained_in||[]).some(_=>typeof _!="string"&&vt(_.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:S.length?e.jsx(zt,{items:S,horizontal:!b}):void 0,children:b?e.jsx(Pe,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),s,(t.contained_in||[]).length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"收",title:o.section.containedIn}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",padding:"14px 4px",display:"flex",flexDirection:"column",gap:12},children:(t.contained_in||[]).map((_,z)=>{var P,$;const I=typeof _=="string"?_:_.id,v=typeof _=="string"?[]:vt(_.volume_index),E=d.get(I),R=((P=E==null?void 0:E.books)==null?void 0:P.length)||(($=E==null?void 0:E.contained_works)==null?void 0:$.length)||0;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"8px 16px",marginBottom:12},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(_e,{id:I,label:E?l(E.title):I,onNavigate:i,renderLink:r})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[R>0&&`全 ${R} ${o.unit.bu}`,R>0&&v.length>0&&" · ",v.length>0&&`本書佔 ${v.length} ${o.unit.volume}`]})]}),v.length>0&&e.jsx(Sr,{volumes:v,unit:o.unit.volume})]},`${I}-${z}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[c&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"作",tone:"ink",title:o.section.belongsToWork}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",padding:"12px 4px 0"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 12px",marginBottom:10},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(_e,{id:c.id,label:l(c.title),onNavigate:i,renderLink:r})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[l(Je(c,o.unit.juan)),(k=c.authors)==null?void 0:k.map(_=>{const z=Rn(_.role);return`${_.dynasty?`〔${l(_.dynasty)}〕`:""}${l(_.name)}${z?" "+l(z):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((C=c.description)==null?void 0:C.text)&&e.jsx(Pe,{text:c.description.text,style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"}}),e.jsx("div",{style:{marginTop:14},children:e.jsx(Ln,{label:o.section.aliases,items:[...wt(t.additional_titles),...wt(t.attached_texts)]})})]})]}),(m.buckets.length>0||m.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[m.mirrors.map(_=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{className:"bim-d-ui",style:{padding:"8px 4px 4px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:l(_.label)}),_.items.map((z,I)=>e.jsx(ot,{item:z,showVolumes:!j},`${z.id||z.url||z.name}-${I}`))]},_.key)),m.buckets.flatMap(_=>_.items).map((_,z)=>e.jsx(ot,{item:_,showVolumes:!j},`${_.id||_.url||_.name}-${z}`))]})]})]}),(T=t.location_history)!=null&&T.length?e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"藏",tone:"ink",title:o.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((_,z)=>e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 12px",padding:"9px 4px",fontSize:14,borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsx("span",{children:l(_.name)}),_.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:l(_.description)})]},z))})]}):null,y.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"版",tone:"ink",title:o.relation.siblingVersions,count:`${y.length} 種`,actions:c?e.jsx(_e,{id:c.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:r,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Kt,{children:[x.map(_=>e.jsx(Rt,{children:e.jsx(_e,{id:_.id,label:l(_.edition||_.title||_.id),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},_.id)),y.length>x.length&&e.jsx(De,{inline:!0,label:`更多 ${y.length-x.length} 種`,onClick:()=>h(!0)})]})]})]})},Ei={titles:16,works:16},Zr=({data:t,catalog:n,onNavigate:i,renderLink:r,catalogAction:s})=>{var z,I;const o=D(),{convert:l}=M(),[c,a]=g.useState(""),[d,p]=g.useState(!1),[x,f]=g.useState(!1),u=g.useMemo(()=>fr(t,n),[t,n]),h=g.useMemo(()=>c?u.rows.filter(v=>v.section===c):u.rows,[u.rows,c]),y=d?h:h.slice(0,Ei.titles),m=g.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=t.contained_works||[],b=new Set(u.rows.map(v=>v.id).filter(Boolean)),j=S.length>0&&!S.every(v=>b.has(v.id)),w=(()=>{const v=u.rows.map(E=>E.edition).filter(Boolean);return v.length>1&&new Set(v).size===1})(),k=x?S:S.slice(0,Ei.works),C=u.sections.length>0,T=g.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...C?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[C]),_=g.useMemo(()=>{var P,$,O,A;const v=[];t.subtype&&v.push({label:o.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(P=t.publication_info)!=null&&P.details&&v.push({label:"刊印",value:l(t.publication_info.details)}),($=t.publication_info)!=null&&$.year&&v.push({label:"年代",value:t.publication_info.year});const E=((O=t.books)==null?void 0:O.length)||S.length,R=Je(t,o.unit.juan);return(E||R)&&v.push({label:"種數 / 卷數",value:[E?`${E} ${o.unit.bu}`:"",l(R)].filter(Boolean).join(" · "),title:(A=t.juan_count)!=null&&A.description?l(t.juan_count.description):void 0}),u.totalVolumes&&v.push({label:"全帙冊數",value:`${u.totalVolumes} ${o.unit.volume}`}),v},[t,S.length,u.totalVolumes,l,o]);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:_.length?e.jsx(zt,{items:_}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Pe,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(I=t.history)!=null&&I.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((v,E)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",l(v)]},E))}):null]}),u.rows.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"目",title:o.section.containedBooks,count:h.length===u.rows.length?`${o.catalog.contains} ${u.rows.length} ${o.unit.items}`:`${u.rows.length} ${o.unit.items} · 當前 ${h.length} ${o.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,C&&e.jsxs(e.Fragment,{children:[e.jsx(He,{label:o.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),u.sections.map(v=>e.jsx(He,{label:v,active:c===v,onClick:()=>{a(v),p(!1)}},v))]})]})}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:T}),y.map((v,E)=>{var R;return e.jsx(qt,{no:Xt(E),spec:T,main:e.jsxs(e.Fragment,{children:[v.id?e.jsx(_e,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0}):e.jsx("span",{children:l(v.title)}),(R=v.subItems)!=null&&R.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",v.subItems.map(P=>l(P)).join("、"),")"]}):null,v.edition&&!w&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(v.edition)})]}),meta:e.jsxs(e.Fragment,{children:[C&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:v.section?v.section.endsWith("部")?v.section:`${v.section}部`:e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:v.volumes.length>0?`第 ${En(v.volumes,o.unit.volume)} ${o.unit.volume}`:v.expected!=null?`${v.found??0}/${v.expected} ${o.unit.volume}`:e.jsx(rt,{})})]})},`${v.id??v.title}-${E}`)}),y.length===0&&e.jsx(st,{children:o.catalog.noMatch})]}),h.length>y.length&&e.jsx(De,{label:`展開其餘 ${h.length-y.length} ${o.unit.items}子目`,onClick:()=>p(!0)})]}),(m.buckets.length>0||j)&&e.jsxs("div",{className:"bim-d-pair bim-d-pair-wide",children:[(m.buckets.length>0||m.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[...m.mirrors.flatMap(v=>v.items),...m.buckets.flatMap(v=>v.items)].map((v,E)=>e.jsx(ot,{item:v,fallbackNote:v.details?l(v.details):void 0},`${v.id||v.url||v.name}-${E}`))})]}),j&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:o.section.containedWorks,count:`${S.length} 種`}),e.jsxs(Kt,{children:[k.map(v=>e.jsx(Rt,{children:e.jsx(_e,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},v.id)),S.length>k.length&&e.jsx(De,{inline:!0,label:`更多 ${S.length-k.length} 種`,onClick:()=>f(!0)})]})]})]})]})},Ea=16,Bi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},ln=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Li(t){if(!t)return ln.length;const n=ln.indexOf(t);return n===-1?ln.length:n}const Qr=({data:t,transport:n,onNavigate:i,renderLink:r})=>{var T,_,z;const s=D(),{convert:o}=M(),[l,c]=g.useState("全部"),[a,d]=g.useState(!1),[p,x]=g.useState("default"),[f,u]=g.useState(new Map),h=g.useMemo(()=>(t.works||[]).map(v=>{const E=f.get(v.work_id);return{id:v.work_id,title:(E==null?void 0:E.title)??v.work_id,role:v.role||"",cls:zn(v.role),versionCount:E==null?void 0:E.versionCount,loaded:!!(E!=null&&E.loaded)}}),[t.works,f]),y=g.useMemo(()=>xr((t.works||[]).map(I=>I.role)),[t.works]),m=g.useMemo(()=>{const I=l==="全部"?h:h.filter(v=>v.cls===l);return p==="versions"?[...I].sort((v,E)=>(E.versionCount??-1)-(v.versionCount??-1)):I},[h,l,p]),S=a?m:m.slice(0,Ea),b=g.useMemo(()=>S.filter(I=>!f.has(I.id)).map(I=>I.id),[S,f]);g.useEffect(()=>{if(!n||b.length===0)return;let I=!1;return Promise.all(b.map(v=>n.getItem(v).then(E=>{var $,O;const R=E??{},P=((($=R.books)==null?void 0:$.length)??0)+(((O=R.collections)==null?void 0:O.length)??0);return[v,{id:v,title:R.title,versionCount:P,loaded:!0}]}).catch(()=>[v,{id:v,loaded:!0}]))).then(v=>{I||u(E=>{const R=new Map(E);for(const[P,$]of v)R.set(P,$);return R})}),()=>{I=!0}},[n,b]);const j=g.useMemo(()=>{const I=new Map;for(const v of t.alt_names||[]){const E=v.type||s.section.aliases;I.has(E)||I.set(E,[]),I.get(E).push(v.name)}return[...I.entries()].sort((v,E)=>Li(v[0])-Li(E[0])).map(([v,E])=>({label:v,names:E}))},[t.alt_names,s]),w=g.useMemo(()=>{const I=[];t.dynasty&&I.push({label:"時代",value:o(t.dynasty)});const v=R=>R==null?"":R<0?`前${-R}`:String(R);(t.birth_year!=null||t.death_year!=null)&&I.push({label:"生卒",value:`${v(t.birth_year)||"?"}—${v(t.death_year)||"?"}`});const E=(t.works||[]).length;return E&&I.push({label:"著作數",value:`${E} 種`}),I},[t,o]),k=(T=t.external_ids)==null?void 0:T.cbdb_id,C=!!((_=t.description)!=null&&_.text);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:w.length?e.jsx(zt,{items:w}):void 0,children:(j.length>0||C)&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[j.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:j.map(I=>e.jsxs("span",{style:{display:"flex",alignItems:"baseline",gap:8,minWidth:0},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".1em",flex:"none"},children:o(I.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:I.names.map(v=>o(v)).join(" · ")})]},I.label))}),C&&e.jsx(Pe,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),h.length===0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該人物的關聯作品。"})})]}),h.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks,count:m.length===h.length?`${h.length} 種`:`${h.length} 種 · 當前 ${m.length} 種`,actions:e.jsx(Ut,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{x(I=>(I==="default"&&d(!0),I==="default"?"versions":"default"))}})}),y.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:y.map(I=>e.jsx(He,{label:`${I.label} ${I.count}`,active:l===I.cls,onClick:()=>{c(I.cls),d(!1)}},I.cls))}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:Bi}),S.map((I,v)=>e.jsx(qt,{no:Xt(v),spec:Bi,main:e.jsx(_e,{id:I.id,label:o(I.title),onNavigate:i,renderLink:r,dense:!0}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:I.role?o(I.role):e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:I.loaded?I.versionCount?`${I.versionCount} 種版本`:e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},I.id)),S.length===0&&e.jsx(st,{children:"該職任下的著作尚未著錄。"})]}),m.length>S.length&&e.jsx(De,{label:`展開其餘 ${m.length-S.length} 條著作`,onClick:()=>d(!0)}),k!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",k,((z=t.external_ids)==null?void 0:z.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function Ba(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function La(t,n){if(!t.lineage)return null;const i=t.lineage;return{id:t.id,kind:"book",label:t.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[t.id],note:i.note}}function Wi(t,n,i){return{id:`derive:${n.ref}->${t}:${i}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Wa(t,n,i){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $a(t,n){var d;if(n==="all")return null;const i=(d=t.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,o=r||s||!!(i!=null&&i.hypothetical_ids);if(!o&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!i||!o)return null;const l=r?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&t.node_groups)for(const[p,x]of Object.entries(t.node_groups))l.has(x)&&c.add(p);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),l){a||(a=new Set);for(const p of t.hypothetical_nodes??[])p.group&&l.has(p.group)&&a.add(p.id)}return{books:c,hypos:a}}function Mt(t,n,i){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const o=new Set(r.excluded_books??[]),l=r.node_groups??{},c=$a(r,i??r.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,x=new Set,f=new Set;if(a){const w=new Map(n.map(I=>[I.id,I])),k=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),C=I=>{const v=w.get(I);if(v&&v.lineage)return(v.lineage.derived_from??[]).map(R=>R.ref);const E=k.get(I);return E?(E.derived_from??[]).map(R=>R.ref):[]},T=I=>k.has(I)?!p||p.has(I):!d||d.has(I),_=new Set,z=I=>{if(!_.has(I)){_.add(I);for(const v of C(I))o.has(v)||(T(v)||(k.has(v)?f.add(v):w.has(v)&&x.add(v)),z(v))}};for(const I of n)d&&d.has(I.id)&&!o.has(I.id)&&z(I.id);for(const I of r.hypothetical_nodes??[])p&&p.has(I.id)&&z(I.id)}const u=n.filter(w=>!o.has(w.id)).filter(w=>!d||d.has(w.id)||x.has(w.id)).map(w=>{const k=La(w,l);return k&&x.has(w.id)&&(k.bridge=!0),k}).filter(w=>w!==null),h=(r.hypothetical_nodes??[]).filter(w=>!p||p.has(w.id)||f.has(w.id)).map(w=>{const k=Ba(w);return f.has(w.id)&&(k.bridge=!0),k}),y=[...u,...h],m=new Set(y.map(w=>w.id)),S=new Set,b=[],j=w=>{S.has(w.id)||!m.has(w.source)||!m.has(w.target)||(S.add(w.id),b.push(w))};for(const w of n)o.has(w.id)||!w.lineage||d&&!d.has(w.id)&&!x.has(w.id)||((w.lineage.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))}),(w.lineage.related_to??[]).forEach((k,C)=>{j(Wa(w.id,k,C))}));for(const w of r.hypothetical_nodes??[])p&&!p.has(w.id)&&!f.has(w.id)||(w.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))});return{nodes:y,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(o)}}function eo(t,n,i){const r=(t??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Aa(t,n){const i=[],r=t.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),o=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...o]),c=(a,d)=>{l.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!o.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(p=>c(d,p)),(a.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const to=({graph:t,renderLink:n,className:i,style:r})=>{const{convert:s}=M();if(!t.nodes.length)return e.jsx("div",{style:{...qa,...r},className:i,children:"暂无版本图数据"});const o=new Map,l=new Map;for(const f of t.edges)if(f.kind==="derive"){const u=o.get(f.target)??[];u.push(f),o.set(f.target,u)}else for(const u of[f.source,f.target]){const h=l.get(u)??[];h.push(f),l.set(u,h)}const c=new Map(t.nodes.map(f=>[f.id,f])),a=new Map,d=[];for(const f of t.nodes)if(f.group){const u=a.get(f.group)??[];u.push(f),a.set(f.group,u)}else d.push(f);const p=(f,u)=>(f.year??9999)-(u.year??9999);a.forEach(f=>f.sort(p)),d.sort(p);const x=t.groups.filter(f=>a.has(f.id));return e.jsxs("div",{className:i,style:{...Ma,...r},children:[t.title&&e.jsx("div",{style:Fa,children:s(t.title)}),t.description&&e.jsx("div",{style:Ha,children:s(t.description)}),x.map(f=>e.jsx($i,{label:f.label,color:f.color,nodes:a.get(f.id),incomingMap:o,siblingMap:l,nodeMap:c,renderLink:n},f.id)),d.length>0&&e.jsx($i,{label:"其他",nodes:d,incomingMap:o,siblingMap:l,nodeMap:c,renderLink:n})]})},$i=({label:t,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:o,renderLink:l})=>{const{convert:c}=M();return e.jsxs("div",{style:Oa,children:[e.jsx("div",{style:{...Da,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(Pa,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:o,renderLink:l},a.id))]})},Pa=({node:t,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const o=t.kind==="hypothetical",l=t.bridge,{convert:c}=M();return e.jsxs("div",{style:{...Na,borderStyle:o||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Va,children:[e.jsx("span",{style:Ga,children:o||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Ya,children:eo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Ua,children:[t.category&&e.jsx(gt,{children:c(t.category)}),t.status==="lost"&&e.jsx(gt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(gt,{tone:"warn",children:"残本"}),o&&e.jsx(gt,{tone:"info",children:"假想祖本"}),l&&e.jsx(gt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Ka,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Ja,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Pi,children:[e.jsx("div",{style:Mi,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return e.jsxs("div",{style:Fi(a.confidence),children:[e.jsx("span",{style:Hi,children:c(a.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&e.jsx(Ai,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:Pi,children:[e.jsx("div",{style:Mi,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=r.get(d);return e.jsxs("div",{style:Fi(a.confidence),children:[e.jsx("span",{style:Hi,children:c(a.relation)}),e.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&s?s(p.id,c(p.label)):c((p==null?void 0:p.label)??d)}),e.jsx(Ai,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(a.evidence)]})]},a.id)})]})]})},gt=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Ai=({level:t})=>{const i={certain:{label:"确定",color:"var(--bim-confidence-certain, #2e7d32)"},consensus:{label:"共识",color:"var(--bim-confidence-consensus, #1976d2)"},probable:{label:"推测",color:"var(--bim-confidence-probable, #ed6c02)"},disputed:{label:"有争议",color:"var(--bim-confidence-disputed, #c62828)"}}[t];return i?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},Ma={fontSize:"14px",color:"var(--bim-fg, #333)"},Fa={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ha={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Oa={marginBottom:"16px"},Da={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Na={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Va={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ga={fontSize:"15px",fontWeight:600},Ya={fontSize:"12px",color:"var(--bim-muted, #777)"},Ua={marginBottom:"6px"},Ka={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Ja={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Pi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Mi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Fi=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Hi={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Oi={fontSize:"11px",color:"var(--bim-muted, #888)"},qa={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},no=({selectedNodeId:t,...n})=>{const[i,r]=g.useState("loading"),[s,o]=g.useState(null);return g.useEffect(()=>{let l=!1;return Xa().then(c=>{l||(c?(o(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:Di,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:Di,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(Za,{modules:s,selectedNodeId:t,...n})};async function Xa(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Za=({graph:t,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:o,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:x,BaseEdge:f,EdgeLabelRenderer:u,getSmoothStepPath:h,dagre:y}=l,m=g.useMemo(()=>({lineage:C=>{var O,A,F,te;const T=((O=C.data)==null?void 0:O.stepPosition)??.85,[_,z,I]=h({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:T,borderRadius:5}),v=!!((A=C.data)!=null&&A.isSibling),E=v?z:C.targetX-18,R=v?I:C.targetY-12,P=(F=C.data)==null?void 0:F.labelStyle,$=(te=C.data)==null?void 0:te.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(f,{id:C.id,path:_,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&e.jsx(u,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${E}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...$,...P},children:C.label})})]})}}),[f,u,h]),S=g.useMemo(()=>({version:C=>{const T=C.data,_=T.kind==="hypothetical",z=T.status==="lost",I=T.isSelected,v=T.bridge,E=T.borderColor??"var(--bim-muted, #888)",R=v||_?"dashed":"solid",P=v?.5:z?.6:1;return e.jsxs("div",{style:{background:v?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${R} ${I?"var(--bim-primary, #0078d4)":E}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:P,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":_||v?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:v?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(p,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:_||!T.renderLink?T.label:T.renderLink(T.bookId,T.label)}),T.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:T.description}),T.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:eo(T.yearText,void 0,T.uncertain)}),z&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(p,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[p,x]),{convert:b}=M(),{rfNodes:j,rfEdges:w}=g.useMemo(()=>Qa(t,y,n,o,b),[t,y,n,o,b]);return e.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:e.jsxs(c,{nodes:j,edges:w,nodeTypes:S,edgeTypes:m,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Qa(t,n,i,r,s=o=>o??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(S=>[S.id,S.color??"var(--bim-muted, #888)"]));for(const S of t.nodes)a.setNode(S.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const S of t.edges)S.kind==="derive"&&(p.has(S.relation)||a.setEdge(S.source,S.target));n.layout(a);const x=t.nodes.map(S=>{const b=a.node(S.id),j=r&&S.id===r,w={kind:S.kind,label:s(S.label),bookId:S.kind==="book"?S.id:void 0,yearText:s(S.year_text??tc(S)),uncertain:S.year_uncertain,category:S.category,status:S.status,borderColor:S.group?d.get(S.group):void 0,renderLink:i,isSelected:j,description:s(S.description),bridge:S.bridge};return{id:S.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:w,draggable:!1,selected:j}}),f=.78,u=.06,h=new Map;for(const S of t.edges)S.kind==="derive"&&(h.has(S.source)||h.set(S.source,[]),h.get(S.source).push(S));const y=new Map;for(const[S,b]of h){if(b.length<=1)continue;const j=[...b].sort((k,C)=>{var z,I;const T=((z=a.node(k.target))==null?void 0:z.y)??0,_=((I=a.node(C.target))==null?void 0:I.y)??0;return T-_}),w=j.length;j.forEach((k,C)=>{const T=(C-(w-1)/2)*u;y.set(k.id,f+T)})}const m=t.edges.map(S=>ec(S,y.get(S.id),s));return{rfNodes:x,rfEdges:m}}function ec(t,n,i=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",o=nc(t.confidence),l={type:"arrowclosed",color:o,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:i(t.relation),data:{labelStyle:{color:"var(--bim-fg, #444)"},isSibling:s,stepPosition:n},style:{stroke:o,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function tc(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function nc(t){switch(t){case"certain":return"var(--bim-confidence-certain, #2e7d32)";case"consensus":return"var(--bim-lineage-edge-consensus, #555)";case"probable":return"var(--bim-confidence-probable, #ed6c02)";case"disputed":return"var(--bim-confidence-disputed, #c62828)";default:return"var(--bim-muted, #888)"}}const Di={padding:"40px 20px",textAlign:"center",color:"var(--bim-muted, #888)",fontSize:"13px",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:8,background:"var(--bim-bg, #fafafa)"},io=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:o,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:x})=>{var b;const[f,u]=g.useState(n),h=j=>{u(j),o==null||o(j)},y=(()=>{if(!a)return[];const j=Object.entries(a);return j.length===0||a.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const S=l?(b=a==null?void 0:a[l])==null?void 0:b.description:void 0;return e.jsxs("div",{className:p,style:x,children:[e.jsxs("div",{style:ic,children:[e.jsx("button",{onClick:()=>h("list"),style:an(f==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:an(f==="graph"),children:"关系图"}),m&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),y.map(([j,w])=>{const k=d==null?void 0:d[j];return e.jsxs("button",{onClick:()=>c==null?void 0:c(j),style:an(l===j),title:w.description,children:[w.label,k!=null?` ${k}`:""]},j)})]})]}),m&&S&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:S}),f==="list"?e.jsx(to,{graph:t,renderLink:i}):e.jsx(no,{graph:t,renderLink:i,height:r,selectedNodeId:s})]})},ic={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},an=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),ro=({style:t})=>{const n=g.useContext(_t);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",o=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:o,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})},oo=({href:t,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:o=>{o.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:o=>{o.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.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"})})}),rc=({id:t,transport:n,activeTab:i,onTabChange:r,activeJuan:s,onJuanChange:o,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:x,onNavigate:f,onBack:u,backLabel:h,renderLink:y,enrichDetail:m,getSourceLink:S,extraTabs:b=[],showFeedbackTab:j=!0,feedbackApiUrl:w,height:k,footerExtra:C,className:T,style:_})=>{const z=D(),{convert:I}=M(),[v,E]=g.useState(null),[R,P]=g.useState(null),[$,O]=g.useState(!0),[A,F]=g.useState(!1),[te,W]=g.useState([]),[Y,ie]=g.useState(!1),[K,L]=g.useState(null),[U,J]=g.useState(!1),[V,G]=g.useState(null),[de,Se]=g.useState(!1),[me,se]=g.useState(null),[ye,Ie]=g.useState(!1),Te=g.useRef(null),[Ze,ct]=g.useState(null),N=s!==void 0?s:Ze,oe=g.useCallback(H=>{o?o(H):ct(H)},[o]),ne=g.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ie(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const re=await n.getCollectionCatalog(H);W(re?[{resource_id:"",data:re}]:[])}}catch{W([])}finally{ie(!1)}},[n]),B=g.useCallback(async H=>{if(!n.getCollatedEditionIndex){L(null);return}J(!0);try{L(await n.getCollatedEditionIndex(H))}catch{L(null)}finally{J(!1)}},[n]),Q=g.useCallback(async H=>{if(!n.getBookFullTextIndex){G(null);return}Se(!0);try{G(await n.getBookFullTextIndex(H))}catch{G(null)}finally{Se(!1)}},[n]),le=g.useCallback(async(H,re)=>{Ie(!0);try{if(n.getLineageGraph){const We=await n.getLineageGraph(H);We&&se(We)}const ae=re.version_graph;if(!ae||!ae.enabled){me||se(null),Te.current=null;return}const ce=re.books??[],ee=[];for(const We of ce)try{const ze=await n.getItem(We);ze&&ee.push(ze)}catch{}Te.current={work:re,books:ee};const X=a??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Le=X==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":X??"all";se(Mt(re,ee,Le))}catch{se(null),Te.current=null}finally{Ie(!1)}},[n]);g.useEffect(()=>{let H=!1;return(async()=>{O(!0),F(!1),E(null),P(null),W([]),L(null),se(null),Te.current=null;try{const ae=await n.getItem(t);if(H)return;if(!ae){F(!0);return}const ce=ae;let ee=null;if(n.getEntry&&(ee=await n.getEntry(t),H))return;ee||(ee={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),m&&m(ee,ce),E(ee),P(ce),ce.type==="collection"?ne(t):ce.type==="work"?((ce.has_collated||n.getCollatedEditionIndex)&&B(t),(ce.version_graph||n.getLineageGraph)&&le(t,ce)):ce.type==="book"&&ce.has_full_text&&n.getBookFullTextIndex&&Q(t)}catch{H||F(!0)}finally{H||O(!1)}})(),()=>{H=!0}},[t,n,m,ne,B,le,Q]),g.useEffect(()=>{const H=Te.current;!H||!a||se(Mt(H.work,H.books,a))},[a]);const q=[];if(R){if(q.push({key:"basic",label:z.detailTab.basicInfo}),R.type==="collection"){Y&&te.length===0&&q.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const H of te)q.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${I(H.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}R.type==="work"&&(K||U)&&i==="collated"&&q.push({key:"collated",label:U?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),R.type==="book"&&(V||de)&&i==="fulltext"&&q.push({key:"fulltext",label:de?`${z.detailTab.fullText}…`:z.detailTab.fullText}),R.type==="work"&&(me||ye)&&q.push({key:"lineage",label:ye?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const H of b)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(R)&&q.push({key:H.key,label:H.label});j&&i==="feedback"&&q.push({key:"feedback",label:z.detailTab.feedback});for(const H of b)H.position==="after-feedback"&&H.shouldShow(R)&&q.push({key:H.key,label:H.label})}g.useEffect(()=>{if(i!=="emendated"||!R)return;r("basic");const H=setTimeout(()=>{var re;(re=document.getElementById("studies"))==null||re.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,R,r]);const Fe=v&&R&&S?S({activeTab:i,activeJuan:N,entry:v,detail:R}):null,ve=g.useMemo(()=>{var ee;if(!R)return null;const re=(R.authors??[]).map(X=>{const Le=Rn(X.role);return`${X.dynasty?`〔${I(X.dynasty)}〕`:""}${I(X.name)}${Le?` ${I(Le)}`:""}`}).join(" · ");let ae=!1;try{ae=Z.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const X=R;return{title:I(X.title),subtitle:X.edition?I(X.edition):re||void 0,aside:[ae?z.status.draft:"",re&&X.edition?re:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const X=R;return{title:I(X.title),subtitle:I(Je(X,z.unit.juan))||void 0,aside:[(ee=X.publication_info)==null?void 0:ee.year,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:re||void 0}}if(R.type==="entity"){const X=R,Le=ze=>ze==null?"":ze<0?`前${-ze}`:String(ze),We=X.birth_year!=null||X.death_year!=null?`${Le(X.birth_year)||"?"}—${Le(X.death_year)||"?"}`:"";return{title:I(X.primary_name||X.title),subtitle:[X.dynasty?`〔${I(X.dynasty)}〕`:"",We].filter(Boolean).join(" ")||void 0,aside:ae?z.status.draft:void 0,secondLine:void 0}}const ce=I(Je(R,z.unit.juan));return{title:I(R.title),subtitle:[ce,re].filter(Boolean).join(" · ")||void 0,aside:[sc(z,R.subtype),ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,I,z]),ge=()=>{var H,re;return R?R.type==="work"?e.jsx(qr,{data:R,transport:n,onNavigate:f,renderLink:y,collatedSection:K&&(((H=K.juan_files)==null?void 0:H.length)??0)>0?e.jsx(Ni,{title:R.title,measure:`${K.juan_files.length} ${I(z.unit.juan)}`,onOpen:()=>{oe(K.juan_files[0]),r("collated")}}):null,lineageAction:me&&me.nodes.length>0?e.jsxs("button",{type:"button",onClick:()=>r("lineage"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.lineage," →"]}):null}):R.type==="book"?e.jsx(Xr,{data:R,transport:n,onNavigate:f,renderLink:y,fullTextSection:V&&V.chapters.length>0?e.jsx(Ni,{title:R.title,measure:[`${V.total_chapters} ${I("章")}`,I(V.version_label)].filter(Boolean).join(" · "),onOpen:()=>{oe(null),r("fulltext")}}):null}):R.type==="collection"?e.jsx(Zr,{data:R,catalog:(re=te[0])==null?void 0:re.data,transport:n,onNavigate:f,renderLink:y,catalogAction:te.length>0?e.jsxs("button",{type:"button",onClick:()=>r(`catalog:${te[0].resource_id}`),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.collectionCatalog," →"]}):null}):e.jsx(Qr,{data:R,transport:n,onNavigate:f,renderLink:y}):null},Qe=()=>{var re,ae,ce;if(!v||!R)return null;if(i==="basic"||i==="emendated")return ge();if(typeof i=="string"&&i.startsWith("catalog:")){const ee=(re=te.find(X=>`catalog:${X.resource_id}`===i))==null?void 0:re.data;return e.jsx(_n,{data:ee,onNavigate:f,renderLink:y})}if(i==="collated")return e.jsx(Pn,{index:K||void 0,workId:t,transport:n,onNavigate:f,activeJuan:N,onJuanChange:oe});if(i==="fulltext")return e.jsx(Lr,{index:V||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:oe});if(i==="lineage"){if(!me)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:ye?"加載中…":"暫無版本圖數據"});const ee=R.type==="work"?R:null;return e.jsx(io,{graph:me,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:x,collection:a??((ae=ee==null?void 0:ee.version_graph)==null?void 0:ae.default_collection),onCollectionChange:d,collectionsAvailable:(ce=ee==null?void 0:ee.version_graph)==null?void 0:ce.collections,collectionCounts:(()=>{var ze,Fn,Hn,On,Dn,Nn,Vn;if(!ee)return;const X={},Le=((ze=Te.current)==null?void 0:ze.books)??[];X.all=(((Fn=ee.books)==null?void 0:Fn.length)??0)-(((On=(Hn=ee.version_graph)==null?void 0:Hn.excluded_books)==null?void 0:On.length)??0);const We=(Dn=ee.version_graph)==null?void 0:Dn.collections;if(We)for(const Gn of Object.keys(We))X[Gn]=Mt(ee,Le,Gn).nodes.filter(Yn=>Yn.kind==="book"&&!Yn.bridge).length;return X.core==null&&((Vn=(Nn=ee.version_graph)==null?void 0:Nn.core_books)!=null&&Vn.length)&&(X.core=ee.version_graph.core_books.length),X})()})}if(i==="feedback"&&j)return e.jsx(Kr,{resourceId:t,apiUrl:w});const H=b.find(ee=>ee.key===i);return H?H.render({detail:R,entry:v,transport:n,onNavigate:f}):null};if($)return e.jsx($t,{style:{minHeight:k,..._},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,re)=>e.jsx("div",{style:{height:re===1?40:16,width:H,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},re))})});if(A||!R||!v||!ve)return e.jsx($t,{style:{minHeight:k,..._},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const so=i==="basic"||i==="emendated",Zt=[{label:h??z.detailTab.backToIndex,onClick:u}];if(R.type==="book"&&R.work_id){const H=R.work_id;Zt.push({label:z.indexType.work,id:H,onClick:()=>f==null?void 0:f(H)})}Zt.push({label:z.indexType[R.type]});const Et=i==="collated"||i==="fulltext";return e.jsx("div",{className:T,children:e.jsxs($t,{wide:Et,style:{minHeight:k,..._},children:[e.jsx(yr,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Bn,{char:"籍"}),e.jsx(vr,{items:Zt})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(ro,{}),j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.feedback}),Fe&&e.jsx(oo,{...Fe})]})}),e.jsx(jr,{...ve,aside:Et?e.jsxs("button",{type:"button",onClick:()=>r("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[I("作品信息")," →"]}):ve.aside}),!Et&&q.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:q.map(H=>e.jsx(He,{label:H.label,active:H.key===i||so&&H.key==="basic",onClick:()=>r(H.key)},H.key))}),e.jsx("div",{style:{marginTop:!Et&&q.length>1?8:0},children:Qe()}),e.jsx(Ir,{left:e.jsxs(e.Fragment,{children:[C,C?" · ":"",e.jsx(oc,{id:R.id,label:z.label.id,copied:z.action.copied})]}),right:e.jsxs(e.Fragment,{children:[j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.submitVersion}),Fe&&e.jsx("a",{href:Fe.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function oc({id:t,label:n,copied:i}){const[r,s]=g.useState(!1);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsxs("span",{children:[n," ",t]}),e.jsx("button",{type:"button",onClick:()=>{var o;(o=navigator.clipboard)==null||o.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}).catch(()=>{})},title:r?i:void 0,style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:r?"✓":"⧉"})]})}function sc(t,n){return n?t.workSubtype[n]??n:""}function Ni({title:t,measure:n,onOpen:i}){const{convert:r}=M(),[s,o]=g.useState(!1),l=r(t?`進入《${t}》全文閲讀`:"進入全文閲讀"),c=[n,r("全文檢索"),r("原書對照")].filter(Boolean).join(" · ");return e.jsx(Ce,{style:{marginTop:-12,marginBottom:28},children:e.jsxs("div",{role:"button",tabIndex:0,onClick:i,onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),i())},onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,flexWrap:"wrap",padding:"14px 26px",cursor:"pointer",background:s?"var(--bim-band-bg-hover, #e6d5b4)":"var(--bim-band-bg, #f0e4cb)",borderLeft:"3px solid var(--bim-accent, #9c3a2c)",transition:"background .18s ease"},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontFamily:"var(--bim-font-body, system-ui, sans-serif)",fontSize:21,fontWeight:600,letterSpacing:".02em",lineHeight:1.3,color:"var(--bim-ink, #2a231c)"},children:l}),e.jsx("div",{className:"bim-d-ui",style:{marginTop:4,fontSize:12.5,letterSpacing:".06em",color:"var(--bim-meta-fg, #7b6a54)"},children:c})]}),e.jsxs("span",{className:"bim-d-ui","aria-hidden":!0,style:{flex:"none",padding:"11px 22px",fontSize:14,letterSpacing:".08em",background:s?"var(--bim-accent-deep, #6f2a20)":"var(--bim-accent, #9c3a2c)",color:"var(--bim-page-bg, #fbf9f3)",transition:"background .18s ease"},children:[r("開始閲讀")," →"]})]})})}exports.BidLink=Z.BidLink;exports.BookIndexError=Z.BookIndexError;exports.BookIndexManager=Z.BookIndexManager;exports.BookIndexStorage=Z.BookIndexStorage;exports.BundleStorage=Z.BundleStorage;exports.ConfigError=Z.ConfigError;exports.GithubStorage=Z.GithubStorage;exports.IdGenerationError=Z.IdGenerationError;exports.IdGenerator=Z.IdGenerator;exports.LocalStorage=Z.LocalStorage;exports.MigrationError=Z.MigrationError;exports.StorageError=Z.StorageError;exports.base36Decode=Z.base36Decode;exports.base36Encode=Z.base36Encode;exports.base58Decode=Z.base58Decode;exports.buildId=Z.buildId;exports.buildPromotionMap=Z.buildPromotionMap;exports.cleanName=Z.cleanName;exports.decodeId=Z.decodeId;exports.decodeIdString=Z.decodeIdString;exports.encodeId=Z.encodeId;exports.extractIdFromUrl=Z.extractIdFromUrl;exports.extractStatus=Z.extractStatus;exports.extractType=Z.extractType;exports.normalizeCatalog=Z.normalizeCatalog;exports.parseId=Z.parseId;exports.shardOf=Z.shardOf;exports.smartDecode=Z.smartDecode;exports.validateResource=Z.validateResource;exports.Badge=Dt;exports.BidUrlProvider=bo;exports.BookDetailLayout=rc;exports.BookFullText=Lr;exports.BookPage=Xr;exports.Breadcrumb=vr;exports.Chip=Rt;exports.ChipWall=Kt;exports.CollatedEdition=Pn;exports.CollectionCatalog=_n;exports.CollectionPage=Zr;exports.CreateEntityDialog=Hr;exports.DETAIL_CSS=hr;exports.Dash=rt;exports.DataTable=qe;exports.DetailFooter=Ir;exports.DetailHeader=jr;exports.EmendatedBySection=rr;exports.EmptyNote=st;exports.EntityDetail=Zi;exports.EntityPage=Qr;exports.EntityPickerDialog=Dr;exports.EntitySelector=Fr;exports.ExpandRow=kr;exports.ExtLink=fn;exports.FactList=zt;exports.FeedbackButton=ha;exports.FeedbackDialog=Yr;exports.FeedbackForm=Ur;exports.FeedbackList=Mn;exports.FeedbackTab=Kr;exports.FilterChip=He;exports.FormInput=he;exports.FormTextArea=Ue;exports.GlyphBadge=Bn;exports.HomePage=mn;exports.IndexApp=wl;exports.IndexBrowser=dn;exports.IndexDetail=wn;exports.IndexEditor=Nr;exports.IndexView=sa;exports.IntroGrid=Tt;exports.LocaleContext=_t;exports.LocaleProvider=Io;exports.LocaleToggle=ro;exports.ModeIndicator=qi;exports.MoreButton=De;exports.PAGE_MAX_WIDTH=mt;exports.PageFrame=$t;exports.Quote=At;exports.ROLE_CLASS_ORDER=ur;exports.RelationPanel=Pr;exports.RepoSourceLink=oo;exports.ResourceEditor=cn;exports.ResourceGroup=xn;exports.ResourceLine=ot;exports.ResourceList=kn;exports.ResourceRow=wr;exports.SearchInput=Xi;exports.Section=ke;exports.SectionHead=ue;exports.SmartBidInput=Pt;exports.SourceEditor=Wr;exports.TableHead=Jt;exports.TableRow=qt;exports.TagRow=Ln;exports.TagRows=Cr;exports.TextButton=Ut;exports.TopStrip=yr;exports.VersionLineageGraph=no;exports.VersionLineageList=to;exports.VersionLineageView=io;exports.VolumeChips=Sr;exports.VolumeLinks=_r;exports.WorkCatalog=_l;exports.WorkPage=qr;exports.bucketResources=Yt;exports.buildCollectionTable=fr;exports.buildLineageGraph=Mt;exports.buildPageUrl=Sn;exports.buildVersionRow=dr;exports.buildVersionTable=pr;exports.computeVersionPartition=Bs;exports.deriveDating=zs;exports.deriveEditionType=mr;exports.deriveEra=It;exports.deriveYear=Gt;exports.deriveYearRange=In;exports.detailToEditor=Gr;exports.displayAuthorRole=Rn;exports.editorToDetail=oa;exports.eraRank=un;exports.flattenTitles=wt;exports.formatTemplate=Ct;exports.formatVolumeRange=En;exports.getDisplayNameFromUrl=St;exports.getStartPage=jn;exports.getTypeGroupKey=bn;exports.groupRelatedWorks=cr;exports.measureText=Je;exports.mergeVolumeResources=yn;exports.normalizeEra=pe;exports.normalizeRole=zn;exports.normalizeVolumeIndex=vt;exports.normalizeVolumes=Ji;exports.numberToChinese=gr;exports.parseChineseNumber=Ht;exports.parseSourceString=$r;exports.resourceHref=Ft;exports.resourceNote=Tn;exports.roleFacets=xr;exports.rowNo=Xt;exports.sortYear=ar;exports.stringifySources=Ar;exports.useBidUrl=be;exports.useConvert=M;exports.useT=D;exports.validateLineageGraph=Aa;exports.volumeStats=vn;
|
|
96
|
+
`;function $t({children:t,style:n,wide:i}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:hr}),e.jsx("div",{className:i?"bim-d-main bim-d-main-wide":"bim-d-main",children:t})]})}function br({aside:t,children:n}){return e.jsxs("div",{className:"bim-d-reader",children:[e.jsx("aside",{className:"bim-d-reader-aside bim-d-ui",children:t}),e.jsx("div",{className:"bim-d-reader-main",children:n})]})}function yr({breadcrumb:t,actions:n}){return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:"var(--bim-label-fg, #8b7a62)"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:t}),n&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function Bn({char:t,tone:n="accent"}){return e.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:n==="accent"?"var(--bim-accent, #9c3a2c)":"var(--bim-ink, #2a231c)",color:"var(--bim-page-bg, #fbf9f3)"},children:t})}function vr({items:t}){const n=be();return e.jsx(e.Fragment,{children:t.map((i,r)=>{const s=r===t.length-1,o=r>0&&e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${r}`),l=i.id?n(i.id):i.href,c=s||!i.onClick&&!l?e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:i.label},r):e.jsx("a",{href:l??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:i.label},r);return e.jsxs(f.Fragment,{children:[o,c]},r)})})}function jr({title:t,subtitle:n,aside:i,secondLine:r}){return e.jsxs("header",{style:{borderBottom:"2px solid var(--bim-rule-strong, #2a231c)",paddingBottom:18},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[e.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:t}),n&&e.jsx("span",{style:{fontSize:15,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".06em"},children:n})]}),i&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".06em"},children:i})]}),r&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:"var(--bim-quiet-fg, #5b4f40)"},children:r})]})}function Tt({children:t,facts:n}){return!t&&n?e.jsx("div",{style:{padding:"20px 0 26px",borderBottom:"1px solid var(--bim-rule, #e4dbc9)",marginBottom:40},children:n}):e.jsxs("div",{className:"bim-d-intro",children:[e.jsx("div",{style:{minWidth:0},children:t}),n]})}function zt({items:t,horizontal:n}){const{convert:i}=P();return t.length?e.jsx("div",{style:{borderLeft:"2px solid var(--bim-accent, #9c3a2c)",paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:t.map((r,s)=>e.jsxs("div",{title:r.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em",flex:"none"},children:i(r.label)}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function ue({glyph:t,tone:n,title:i,count:r,actions:s,id:o}){const{convert:l}=P();return e.jsxs("div",{id:o,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(Bn,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:l(i)}),r!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Ce({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function He({label:t,active:n,onClick:i,dashed:r}){const{convert:s}=P();return e.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!n?"dashed":"solid"} ${n?"var(--bim-accent, #9c3a2c)":"var(--bim-rule, #e0d6c0)"}`,background:n?"var(--bim-accent, #9c3a2c)":"transparent",color:n?"var(--bim-page-bg, #fbf9f3)":"var(--bim-meta-fg, #7b6a54)",fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:s(t)})}function Ut({label:t,onClick:n}){const{convert:i}=P();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:i(t)})}function De({label:t,onClick:n,inline:i}){const{convert:r}=P();return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",cursor:"pointer",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:i?void 0:".08em"},children:r(t)})}function Rt({children:t,href:n,onClick:i,title:r}){const s={display:"inline-block",padding:"4px 10px",border:"1px solid var(--bim-rule, #e0d6c0)",fontSize:13,color:"var(--bim-body-fg, #3b3228)",lineHeight:1.5};return n||i?e.jsx("a",{href:n??"#",title:r,onClick:i?o=>{o.metaKey||o.ctrlKey||(o.preventDefault(),i())}:void 0,style:s,children:t}):e.jsx("span",{title:r,style:s,children:t})}function Kt({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function Sr({volumes:t,unit:n="冊",max:i=60}){const[r,s]=f.useState(!1);if(!t.length)return null;const o=r?t:t.slice(0,i);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[o.map(l=>e.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:"1px solid var(--bim-rule, #e0d6c0)",color:"var(--bim-meta-fg, #7b6a54)"},children:l},l)),!r&&t.length>i&&e.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:["+",t.length-i]}),e.jsx("span",{style:{padding:"2px 6px",color:"var(--bim-hint-fg, #b3a385)"},children:n})]})}function qe({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function Jt({spec:t}){const{convert:n}=P();return e.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${t.leadWidth}px 1fr ${t.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",fontSize:11,color:"var(--bim-label-fg, #8b7a62)",letterSpacing:".1em"},children:[e.jsx("span",{}),e.jsx("span",{children:n(t.mainLabel)}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(i=>i.width).join(" "),gap:12},children:t.columns.map(i=>e.jsx("span",{children:n(i.label)},i.label))})]})}function qt({no:t,main:n,meta:i,spec:r}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.metaWidth}px`,gap:12},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-hint-fg, #c2b294)",textAlign:"right"},children:t}),e.jsx("span",{style:{minWidth:0},children:n}),e.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Xt(t){return String(t+1).padStart(2,"0")}function rt(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function kr({open:t,onToggle:n,main:i,action:r,children:s}){return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[e.jsx("button",{type:"button",onClick:n,"aria-expanded":t,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 ${t?"var(--bim-accent, #9c3a2c)":"var(--bim-rule-dashed, #d6c9ae)"}`,background:t?"var(--bim-accent, #9c3a2c)":"transparent",color:t?"var(--bim-page-bg, #fbf9f3)":"var(--bim-accent, #9c3a2c)"},children:t?"-":"+"}),e.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),r]}),t&&s&&e.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:"2px solid var(--bim-rule-accent-soft, #e0d3b6)",marginLeft:12},children:s})]})}function Oe(t,n=i=>i){if(!t)return"";if(t.indexOf("⟨")<0)return n(t);const i=[],r=/\u27e8([^\u27e9]*)\u27e9/g;let s=0,o=0,l;for(;(l=r.exec(t))!==null;)l.index>s&&i.push(e.jsx(f.Fragment,{children:n(t.slice(s,l.index))},o++)),i.push(e.jsx("span",{className:"bim-jiazhu",style:{fontSize:".78em",color:"var(--bim-meta-fg, #7b6a54)",lineHeight:1.55},children:n(l[1])},o++)),s=l.index+l[0].length;return s<t.length&&i.push(e.jsx(f.Fragment,{children:n(t.slice(s))},o++)),i}function At({label:t,children:n}){return e.jsxs("div",{style:{marginBottom:10},children:[t&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:"var(--bim-label-fg, #a3937b)",marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"},children:n})]})}function xn({title:t,tag:n,children:i}){const{convert:r}=P();return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",marginBottom:2},children:[e.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:r(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:r(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function wr({name:t,note:n,href:i,extra:r}){const s=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,minWidth:0},children:t}),e.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)",flex:"none"},children:i?"↗":""}),n&&e.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:n})]}),o={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:"1px solid var(--bim-rule, #eae2d0)",color:"var(--bim-body-fg, #3b3228)",alignItems:"baseline"};return e.jsxs(e.Fragment,{children:[i?e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:o,children:s}):e.jsx("div",{style:o,children:s}),r]})}function ot({item:t,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=P(),[o,l]=f.useState(!1),c=vn(t),a=i&&!!c&&c.expected>0,d=(t.url?St(t.url):void 0)||s(t.name),p=n?Es(t,n):"",x=p?`${d}(${p})`:d;return e.jsx(wr,{name:x,note:Tn(t)||r,href:Pt(t),extra:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>l(g=>!g),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:o?"收起分冊":`展開 ${c.expected} 冊`}),o&&e.jsx(_r,{item:t})]}):void 0})}function _r({item:t}){return e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(t.volumes||[]).map((n,i)=>{const r=n.status==="missing";return n.url&&!r?e.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"1px 5px",border:"1px solid var(--bim-rule, #e0d6c0)"},children:n.volume},i):e.jsx("span",{style:{padding:"1px 5px",color:r?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function Ln({label:t,items:n}){const{convert:i}=P();return n.length?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em"},children:t}),n.map((r,s)=>e.jsx(Rt,{children:i(r)},s))]}):null}function Cr({rows:t}){const n=t.filter(i=>i.items.length>0);return n.length?e.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>e.jsx(Ln,{label:i.label,items:i.items},i.label))}):null}function wt(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ir({left:t,right:n}){return e.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:"1px solid var(--bim-rule, #e4dbc9)",display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[e.jsx("span",{children:t}),n&&e.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function st({children:t,action:n}){return e.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:"var(--bim-label-fg, #a3937b)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[e.jsx("span",{children:t}),n]})}function _e({id:t,label:n,onNavigate:i,renderLink:r,style:s,dense:o}){const l=be();return r?e.jsx(e.Fragment,{children:r(t,typeof n=="string"?n:void 0,{dense:o})}):e.jsx("a",{href:l(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function fn({href:t,children:n}){return e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:[n," ",e.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const di={A:"fine",B:"rough",C:"rough",D:"ocr"};function Fs(t){return typeof t!="string"?null:t in Gi?t:t in di?di[t]:null}const Ps={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Hs={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function xe(t){return typeof t!="string"?"":Ps[t]??Hs[t]??t}const Os=["〇","一","二","三","四","五","六","七","八","九"],pi=["","十","百","千"],Ds=["","萬","億"];function Tr(t){if(t===0)return"〇";if(t<0)return`負${Tr(-t)}`;const n=[];let i=t,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Ns(s,r>0)+Ds[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Ns(t,n){const i=[];let r=t;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let o=0;o<i.length;o++){const l=i[o],c=i.length-1-o;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&o===0&&!n?s+=pi[c]:s+=Os[l]+pi[c]}return s.replace(/〇$/,"")}let jt=null,Lt=null;const Ot=new Set;function Vs(){return jt?Promise.resolve():Lt||(Lt=import("opencc-js/t2cn").then(t=>{jt=t.Converter({from:"tw",to:"cn"}),Ot.forEach(n=>n())}).catch(()=>{jt=t=>t,Ot.forEach(t=>t())}),Lt)}function Fe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(jt)return;const n=()=>t(i=>i+1);return Ot.add(n),Vs(),()=>{Ot.delete(n)}},[]),jt??(n=>n)}function lt(t,n){return n(t).toLowerCase()}const Wn="var(--bim-highlight-bg, #fff59d)";function at(t,n,i){if(!n)return t;const r=lt(n,i);if(!r)return t;const s=lt(t,i);if(s.length!==t.length)return t;const o=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(r,l);if(a===-1){o.push(t.slice(l));break}a>l&&o.push(t.slice(l,a)),o.push(e.jsx("mark",{style:{background:Wn,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:o})}function $n(t,n,i,r){if(!n)return!0;const s=lt(n,r);return(i?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(l=>typeof l=="string"&<(l,r).includes(s))}function Gs(t,n,i){return n?lt(t,i).includes(lt(n,i)):!0}const An={类:"var(--bim-section-lei, #8e6f3e)",书:"var(--bim-section-shu, #c0392b)",序:"var(--bim-section-xu, #1a5276)",结语:"var(--bim-section-jieyu, #7d6608)",注释:"var(--bim-section-zhushi, #6c5b7b)"},Ys={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Us(t){const n=t.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function gn({file:t,isActive:n,onSelect:i,meta:r,matchState:s,vertical:o}){const l=s===0,c=s==="loading",a=typeof s=="number"&&s>0,d=r!=null&&r.vol_label?`${r.vol_label}冊`:null,p=d??Us(t),x=!d&&!!(r!=null&&r.vol_label)&&!p.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{l||i(t)},disabled:l,style:{padding:o?"4px 8px":"3px 8px",textAlign:o?"left":"center",width:o?"100%":void 0,border:o?"1px solid transparent":n?"1px solid var(--bim-primary, #8e6f3e)":l?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderLeft:o?`2px solid ${n?"var(--bim-primary, #8e6f3e)":"transparent"}`:void 0,borderRadius:o?0:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":a?`${Wn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":l?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:l?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:l?.5:1},children:[p,x&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function zr(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(r=>zr(r,n)))}function Rr(t){var r;const n=t.files.length,i=((r=t.children)==null?void 0:r.reduce((s,o)=>s+Rr(o),0))||0;return n+i}function Ks(t,n){const i=[],r=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(r)};if(r(t),i.length===0)return;const s=i.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let o=0;for(const l of s)typeof l=="number"&&(o+=l);return o}function Er({group:t,activeFile:n,onSelect:i,depth:r=0,juanMeta:s,matchStates:o,vertical:l}){var v;const c=zr(t,n||""),a=Ks(t,o),d=typeof a=="number"&&a>0,p=a===0,[x,g]=f.useState(c||d),u=Rr(t),h=!!((v=t.children)!=null&&v.length);if(f.useEffect(()=>{c&&g(!0)},[c]),f.useEffect(()=>{d&&g(!0)},[d]),t.files.length===1&&!h){const m=t.files[0],S=n===m,b=o[m],j=b===0,w=b==="loading",k=typeof b=="number"&&b>0;return e.jsxs("button",{onClick:()=>{j||i(m)},disabled:j,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:S?"1px solid var(--bim-primary, #8e6f3e)":j?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:S?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":k?`${Wn}40`:"transparent",color:S?"var(--bim-primary, #8e6f3e)":j?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:j?"not-allowed":"pointer",fontSize:"12px",fontWeight:S?600:400,lineHeight:1.4,opacity:j?.5:1},children:[t.label,k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:b}),w&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>g(!x),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:c?"var(--bim-primary, #8e6f3e)":p?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:p?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",u,")"]}),d&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",a]}),a==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:l?"column":"row",flexWrap:l?"nowrap":"wrap",gap:l?"1px":"4px",padding:l?`2px 0 2px ${8+r*10}px`:`4px 0 4px ${24+r*16}px`},children:t.files.map(m=>e.jsx(gn,{file:m,isActive:n===m,onSelect:i,meta:s==null?void 0:s[m],matchState:o[m],vertical:l},m))}),h&&t.children.map((m,S)=>e.jsx(Er,{group:m,activeFile:n,onSelect:i,depth:r+1,juanMeta:s,matchStates:o,vertical:l},S))]})]})}function Js({files:t,groups:n,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:l}){const c=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:l?0:"16px"},children:n.map((a,d)=>e.jsx(Er,{group:a,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:l},d))}):c.length===0?null:l?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1px"},children:c.map(a=>e.jsx(gn,{file:a,isActive:i===a,onSelect:r,meta:s==null?void 0:s[a],matchState:o[a],vertical:!0},a))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:c.map(a=>e.jsx(gn,{file:a,isActive:i===a,onSelect:r,meta:s==null?void 0:s[a],matchState:o[a]},a))})}function qs({type:t}){const n=xe(t),i=An[n]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Xs({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),s=be(),o=Fe(),l=v=>v?Oe(r(v),m=>i?at(m,i,o):m):"",[c,a]=f.useState(!1),d=!!t.summary,p=!!t.comment,x=!!t.additional_comment,g=!!(t.content&&t.content.length>60),u=d||p||x||g;f.useEffect(()=>{i&&a(!0)},[i]);const h=!c&&g?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>u&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:u?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Tr(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&u&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!d&&!p&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function Zs({section:t,highlightQuery:n=""}){const{convert:i}=P(),r=Fe(),s=a=>a?Oe(i(a),d=>n?at(d,n,r):d):"",[o,l]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(qs,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${An[xe(t.type)]||"var(--bim-desc-fg, #717171)"} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}const Qs=100;function Br(t){return xe(t.type)!=="page_header"?!1:(t.content||"").length>=Qs}function el({section:t,highlightQuery:n=""}){const{convert:i}=P(),r=Fe();if(xe(t.type)==="page_header"&&!Br(t)||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
97
|
+
`)),o=n?at(s,n,r):s,l=xe(t.type),c=An[l]||"var(--bim-desc-fg, #717171)",a=l==="序"||l==="结语"||l==="注释";return e.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${c}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:c,marginRight:"8px",padding:"1px 5px",border:`1px solid ${c}40`,borderRadius:"2px",background:`${c}08`,verticalAlign:"middle"},children:l}),o]})}function tl(t,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||t.length===0)return;let o=!1;const l=t.filter(p=>{var x;return!((x=i==null?void 0:i.current)!=null&&x.has(p))}),c={};for(const p of t)(d=i==null?void 0:i.current)!=null&&d.has(p)&&(c[p]=i.current.get(p));if(Object.keys(c).length>0&&s(c),l.length===0)return;const a=async p=>{var x;try{if(n.getEntry){const m=await n.getEntry(p);if(m)return{title:m.title,author:m.author}}const g=await n.getItem(p);if(!g)return null;const u=g.title||p,h=g.authors,v=(x=h==null?void 0:h[0])==null?void 0:x.name;return{title:u,author:v}}catch{return null}};return Promise.all(l.map(async p=>{var g;const x=await a(p);return(g=i==null?void 0:i.current)==null||g.set(p,x),[p,x]})).then(p=>{o||s(x=>{const g={...x};for(const[u,h]of p)g[u]=h;return g})}),()=>{o=!0}},[t.join(","),n]),r}function nl({section:t,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:o}=P(),l=be(),c=Fe(),a=b=>b?Oe(o(b),j=>s?at(j,s,c):j):"",[d,p]=f.useState(!1);f.useEffect(()=>{s&&p(!0)},[s]);const x=xe(t.type),g=Ys[x]||"var(--bim-desc-fg, #717171)",u=!!t.content,h=t.work_ids||[],v=h.length>1,m=tl(v?h:[],i,r),S=u&&!d&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>u&&p(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:u?"pointer":"default",userSelect:"none"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?a(t.header_line):a(t.title)}),!d&&S&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:a(S)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&e.jsx("a",{href:l(h[0]),onClick:b=>{b.metaKey||b.ctrlKey||(b.preventDefault(),b.stopPropagation(),n(h[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),v&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[h.length,"部作品"]}),e.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:x})]})]}),v&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(b=>{const j=m[b],w=j?`${o(j.title)}${j.author?`(${o(j.author)})`:""}`:b.slice(0,8)+"…";return e.jsxs("a",{href:l(b),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(b))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:b,children:["→",w]},b)})}),d&&u&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:a(t.comment)})]})]})}function il({juan:t,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const{convert:o}=P(),l=Fe(),c=n.trim(),a=f.useMemo(()=>c?t.sections.filter(x=>$n(x,c,!0,l)):t.sections,[t.sections,c,l]),d=t.sections.filter(x=>xe(x.type)==="考证").length,p=a.filter(x=>xe(x.type)==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:o(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:c?`${p} / ${d} 條`:`${d} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:a.map((x,g)=>e.jsx(nl,{section:x,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:c},g))}),a.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function rl({text:t,highlightQuery:n=""}){const{convert:i}=P(),r=Fe(),s=l=>Oe(i(l),c=>n?at(c,n,r):c),o=t.split(`
|
|
98
|
+
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:o.map((l,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!o[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},p):e.jsx(f.Fragment,{children:s(d)},p))},c)})})}function ol({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),s=be(),o=Fe(),l=d=>d?Oe(r(d),p=>i?at(p,i,o):p):"",c=[];let a=null;for(const d of t){const p=xe(d.type);p==="page_header"&&!Br(d)||(p==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(a||(a={category:"",items:[]}),a.items.push(d)):(p==="序"||p==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),p==="结语"&&(c.push(a),a=null)))}return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,p)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((x,g)=>xe(x.type)==="序"||xe(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(x.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),u.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:l(x.title)})}):e.jsx("strong",{children:l(x.title)}),x.content&&l(x.content)]},g))]},p))})}function sl({juan:t,rawText:n,searchQuery:i,onNavigate:r}){const{convert:s}=P(),o=Fe(),[l,c]=f.useState("catalog"),a=i.trim(),d=f.useMemo(()=>a?t.sections.filter(u=>$n(u,a,!1,o)):t.sections,[t.sections,a,o]),p=t.sections.filter(u=>xe(u.type)==="书").length,x=t.sections.filter(u=>xe(u.type)==="诗").length,g=a?d.filter(u=>xe(u.type)==="书"||xe(u.type)==="诗").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${x>0?`${x} 首`:`${p} 部書`}`:x>0?`${x} 首`:p>0?`${p} 部书`:""}),e.jsx("div",{style:{display:"flex",gap:"2px"},children:["catalog","raw"].map(u=>e.jsx("button",{onClick:()=>c(u),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:u==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))})]}),l==="raw"&&(n?e.jsx(rl,{text:n,highlightQuery:a}):e.jsx(ol,{sections:t.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((u,h)=>{const v=xe(u.type);return v==="书"||v==="诗"||v==="考证"?e.jsx(Xs,{section:u,onNavigate:r,highlightQuery:a},h):v==="类"?e.jsx(Zs,{section:u,highlightQuery:a},h):e.jsx(el,{section:u,highlightQuery:a},h)}),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Lr(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function ll(t){const n=Lr(t);return n.length>0?n[0]:null}function al(t){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:o,activeRawText:l,query:c,isKaozhen:a}=t,d=Fe(),p=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&o&&p.current.set(s,{juan:o,rawText:l})},[s,o,l]),f.useEffect(()=>{p.current.clear(),g({})},[n]);const u=f.useCallback((h,v)=>{let m=0;if(h.juan)for(const S of h.juan.sections)$n(S,v,a,d)&&m++;return m===0&&h.rawText&&Gs(h.rawText,v,d)&&(m=1),m},[a,d]);return f.useEffect(()=>{const h=c.trim();if(!h){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let v=!1;const m={},S=[];for(const C of r){const T=p.current.get(C);T?m[C]=u(T,h):(m[C]="loading",S.push(C))}g(m);const b=8;let j=0;const w=async()=>{var C;for(;j<S.length;){if(v)return;const T=j++,_=S[T];try{const[z,I]=await Promise.all([i.getCollatedJuan(n,_),((C=i.getCollatedJuanText)==null?void 0:C.call(i,n,_))??Promise.resolve(null)]),y={juan:z,rawText:I};if(p.current.set(_,y),v)return;g(R=>({...R,[_]:u(y,h)}))}catch{if(v)return;g(z=>({...z,[_]:0}))}}},k=Array.from({length:Math.min(b,S.length)},()=>w());return Promise.all(k),()=>{v=!0}},[c,n,i,r.join(","),u,d]),{matchStates:x}}const Mn=({index:t,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:o,className:l,style:c})=>{const[a,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[h,v]=f.useState(null),[m,S]=f.useState(null),[b,j]=f.useState(!1),[w,k]=f.useState(null),[C,T]=f.useState(""),_=f.useRef(new Map),z=f.useRef(0),I=s??h,y=f.useCallback(M=>{v(M),o==null||o(M)},[o]),R=t||a;f.useEffect(()=>{t&&(x(!1),u(null))},[t]),f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let M=!1;return x(!0),u(null),i.getCollatedEditionIndex(n).then(J=>{M||(J?d(J):u("未找到整理本数据"))}).catch(J=>{M||u(J instanceof Error?J.message:"加载失败")}).finally(()=>{M||x(!1)}),()=>{M=!0}},[t,n,i]),f.useEffect(()=>{if(R&&!I){const M=ll(R);M&&y(M)}},[R,I,y]);const E=n||(R==null?void 0:R.work_id),F=f.useCallback(async M=>{var W;if(!E||!(i!=null&&i.getCollatedJuan))return;const J=++z.current;j(!0),S(null),k(null);try{const[Y,ie]=await Promise.all([i.getCollatedJuan(E,M),((W=i.getCollatedJuanText)==null?void 0:W.call(i,E,M))??Promise.resolve(null)]);if(J!==z.current)return;S(Y),k(ie)}catch{if(J!==z.current)return;S(null),k(null)}finally{J===z.current&&j(!1)}},[E,i]);f.useEffect(()=>{I&&F(I)},[I,F]);const $=M=>{y(M)};if(p)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!R)return null;const O=R.type==="kaozhen",A=Lr(R);return e.jsx(cl,{className:l,style:c,index:R,allFiles:A,isKaozhen:O,effectiveWorkId:E,transport:i,activeFile:I,handleSelectFile:$,juanData:m,juanRawText:w,juanLoading:b,searchQuery:C,setSearchQuery:T,onNavigate:r,workLabelCacheRef:_})},cl=({className:t,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:o,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:x,searchQuery:g,setSearchQuery:u,onNavigate:h,workLabelCacheRef:v})=>{const{matchStates:m}=al({workId:o,transport:l,files:r,activeFile:c,activeJuan:d,activeRawText:p,query:g,isKaozhen:s}),S=e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:s?"搜索全部章节…":"搜索全部卷…",value:g,onChange:b=>u(b.target.value),style:{width:"100%",padding:"6px 9px",marginBottom:"12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"12.5px",boxSizing:"border-box"}}),e.jsx(Js,{files:r,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:m,vertical:!0})]});return e.jsx("div",{className:t,style:n,children:e.jsxs(br,{aside:S,children:[e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s&&i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})]})}),i.text_quality&&(()=>{const b=Fs(i.text_quality.grade);return b?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(js,{content:jo[b],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:So[b],cursor:"help"},children:Gi[b]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),x?e.jsx(Xe,{}):d?s?e.jsx(il,{juan:d,searchQuery:g,onNavigate:h,transport:l,workLabelCache:v}):e.jsx(sl,{juan:d,rawText:p,searchQuery:g,onNavigate:h}):c?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,i.references&&i.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),i.references.map((b,j)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[j+1,". "]}),b.url?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:b.title}):e.jsx("span",{children:b.title}),b.author&&e.jsxs("span",{children:[",",b.author]}),b.note&&e.jsxs("span",{children:["。",b.note]})]},j))]})]})})},dl={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},pl={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function ul(t){try{const n=new Date(t),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const Fn=({items:t,loading:n})=>{const i=be();return n?e.jsx(Xe,{}):t.length===0?e.jsx("div",{style:xl,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=dl[r.type],o=pl[r.status];return e.jsxs("div",{style:fl,children:[e.jsxs("div",{style:gl,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...ui,background:s.color},children:s.label}),e.jsx("span",{style:{...ui,background:o.color},children:o.label})]}),e.jsx("span",{style:ml,children:ul(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:hl,children:[r.resourceId&&e.jsx("a",{href:i(r.resourceId),style:xi,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:xi,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:bl,children:r.content}),r.reply&&e.jsxs("div",{style:yl,children:[e.jsx("div",{style:vl,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},xl={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},fl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},gl={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ui={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},ml={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},hl={fontSize:"12px",marginBottom:"6px"},xi={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},bl={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},yl={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},vl={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},mn=({transport:t,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:o})=>{const l=D(),[c,a]=f.useState(null),[d,p]=f.useState([]),[x,g]=f.useState("recommend"),[u,h]=f.useState([]),[v,m]=f.useState(!1),S=r??x,b=$=>{g($),s==null||s($)},[j,w]=f.useState(!0),[k,C]=f.useState(null),[T,_]=f.useState(null),[z,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(O=>{$||a({works:O.works,books:O.books,collections:O.collections})}).catch(()=>{}),()=>{$=!0}},[t]),f.useEffect(()=>{let $=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const A=await t.getRecommended();if(A!=null&&A.groups)return A.groups.flatMap(M=>M.items.map(J=>({...J,group:M.name})))}catch{}return[]})().then(async A=>{if($)return;const M=A.filter(W=>W.id);if(M.length===0){w(!1);return}const J=await Promise.all(M.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let Y=null;if(t.getEntry)Y=await t.getEntry(W.id);else{const ie=await t.getItem(W.id);ie&&(Y={id:W.id,title:ie.title||W.id,type:ie.type||"work"})}if(Y)return{...Y,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:Q.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(p(J.filter(W=>W!==null)),w(!1))}),()=>{$=!0}},[t,i]);const y=f.useRef(!1),R=f.useRef(!1),E=f.useRef(!1);f.useEffect(()=>{if(S!=="catalog"||y.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;y.current=!0;let O=!1;return $.call(t).then(A=>{O||C(A)}).catch(()=>{y.current=!1}),()=>{O=!0}},[t,S]),f.useEffect(()=>{if(S!=="collection"||R.current||!t.getCollectionProgress)return;R.current=!0;let $=!1;return t.getCollectionProgress().then(O=>{$||_(O)}).catch(()=>{R.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(S!=="site"||E.current||!t.getSiteProgress)return;E.current=!0;let $=!1;return t.getSiteProgress().then(O=>{$||I(O)}).catch(()=>{E.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(!o||S!=="feedback")return;let $=!1;return m(!0),fetch(o).then(O=>O.json()).then(O=>{!$&&O.success&&h(O.items||[])}).catch(()=>{}).finally(()=>{$||m(!1)}),()=>{$=!0}},[o,S]);const F=$=>{switch($){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(xt,{label:l.home.recommendTab,active:S==="recommend",onClick:()=>b("recommend")}),e.jsx(xt,{label:l.home.catalogTab,active:S==="catalog",onClick:()=>b("catalog")}),e.jsx(xt,{label:l.home.collectionTab,active:S==="collection",onClick:()=>b("collection")}),e.jsx(xt,{label:l.home.siteTab,active:S==="site",onClick:()=>b("site")}),o&&e.jsx(xt,{label:l.home.feedbackTab,active:S==="feedback",onClick:()=>b("feedback")})]}),S==="recommend"&&e.jsx(jl,{recommended:d,loading:j,onNavigate:n,getIcon:F,t:l}),S==="catalog"&&e.jsx(fi,{progress:k,t:l,onNavigate:n}),S==="collection"&&e.jsx(fi,{progress:T,t:l,onNavigate:n}),S==="site"&&e.jsx(kl,{progress:z,t:l,totalWorks:(c==null?void 0:c.works)??0}),S==="feedback"&&o&&e.jsx(Fn,{items:u,loading:v})]})})},xt=({label:t,active:n,onClick:i})=>e.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),jl=({recommended:t,loading:n,onNavigate:i,getIcon:r,t:s})=>{const o=be();if(n)return e.jsx(Xe,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:o(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),p&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]})]},d.id)})})]},c))})},fi=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],o={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"var(--bim-progress-active, #f59e0b)",done:"var(--bim-progress-done, #10b981)",todo:"var(--bim-progress-todo, #9ca3af)"};return e.jsx("div",{children:s.map(c=>{const a=r.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),o[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Sl,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},Sl=({item:t,t:n,statusColor:i,onNavigate:r})=>{const s=be(),o=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ct(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},kl=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),o=r.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=i>0?Math.round(l/i*100):0;return e.jsxs("div",{children:[i>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-done, #10b981)"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>e.jsx(gi,{item:a,t:n,totalWorks:i},a.id))})]}),o.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-todo, #9ca3af)"}}),n.home.statusTodo," (",o.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:o.map(a=>e.jsx(gi,{item:a,t:n,totalWorks:i},a.id))})]})]})},gi=({item:t,t:n,totalWorks:i})=>{const r=i>0?Math.round(t.imported/i*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&i>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},mi="(max-width: 768px)";function wl(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(mi).matches);return f.useEffect(()=>{const i=window.matchMedia(mi),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),t}const _l=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var O;const o=D(),{convert:l}=P(),c=wl(),[a,d]=f.useState(null),[p,x]=f.useState(null),[g,u]=f.useState(!1),[h,v]=f.useState("detail"),[m,S]=f.useState([]),[b,j]=f.useState(!1),[w,k]=f.useState(null),[C,T]=f.useState(!1),_=f.useCallback(async A=>{if(!t.getCollatedEditionIndex){k(null);return}T(!0);try{const M=await t.getCollatedEditionIndex(A);k(M)}catch{k(null)}finally{T(!1)}},[t]),z=f.useCallback(async A=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){S([]);return}j(!0);try{if(t.getCollectionCatalogs){const M=await t.getCollectionCatalogs(A);S(M||[])}else if(t.getCollectionCatalog){const M=await t.getCollectionCatalog(A);S(M?[{resource_id:"",data:M}]:[])}}catch{S([])}finally{j(!1)}},[t]),I=f.useCallback(async A=>{if(i){i(A);return}d(A),x(null),S([]),k(null),v("detail"),u(!0);try{const M=await t.getItem(A.id);M&&(x(M),M.type==="collection"?z(A.id):M.type==="work"&&M.has_collated&&_(A.id))}catch(M){console.error("加载详情失败:",M)}finally{u(!1)}},[t,i,z,_]),y=f.useCallback(async A=>{x(null),S([]),k(null),v("detail"),u(!0);try{const M=await t.getItem(A);M&&(x(M),d({id:A,title:M.title||A,type:M.type||"book"}),M.type==="collection"?z(A):M.type==="work"&&M.has_collated&&_(A))}catch(M){console.error("导航失败:",M)}finally{u(!1)}},[t,z,_]),R=(p==null?void 0:p.type)==="collection"&&(m.length>0||b)||(p==null?void 0:p.type)==="work"&&(w||C),E=c&&(g||p),F=f.useCallback(()=>{d(null),x(null),S([]),k(null),v("detail")},[]),$=e.jsx(e.Fragment,{children:g?e.jsx(Xe,{}):p?e.jsxs(e.Fragment,{children:[(R||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[R&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>v("detail"),style:Wt(h==="detail"),children:o.detailTab.basicInfo}),p.type==="collection"&&b&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:Wt(!1),children:[o.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&m.map(A=>e.jsx("button",{onClick:()=>v(`catalog:${A.resource_id}`),style:Wt(h===`catalog:${A.resource_id}`),children:A.short_name?`${l(A.short_name)}${o.detailTab.catalogSuffix}`:o.detailTab.collectionCatalog},A.resource_id)),p.type==="work"&&(w||C)&&e.jsxs("button",{onClick:()=>v("collated"),style:Wt(h==="collated"),children:[o.detailTab.collatedEdition,C&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?e.jsx(wn,{data:p,transport:t,onNavigate:y}):h.startsWith("catalog:")?e.jsx(_n,{data:(O=m.find(A=>`catalog:${A.resource_id}`===h))==null?void 0:O.data,onNavigate:y}):h==="collated"?e.jsx(Mn,{index:w||void 0,workId:p.id,transport:t,onNavigate:y}):null})]}):e.jsx(mn,{transport:t,onNavigate:y,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:E?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:F,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",o.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(dn,{transport:t,onEntryClick:I,hideModeIndicator:n}),!p&&e.jsx(mn,{transport:t,onNavigate:y,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(dn,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Wt(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Ne(t){return t.replace(/\.md$/,"")}const Wr=({index:t,bookId:n,transport:i,activeChapter:r,onChapterChange:s})=>{const[o,l]=f.useState(t??null),[c,a]=f.useState(null),d=r!==void 0?r:c,p=f.useCallback(S=>{s?s(S):a(S)},[s]),[x,g]=f.useState(null),[u,h]=f.useState(!1);f.useEffect(()=>{t&&l(t)},[t]),f.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let S=!1;return i.getBookFullTextIndex(n).then(b=>{S||l(b)}),()=>{S=!0}},[n,i,t]),f.useEffect(()=>{if(!o||o.chapters.length===0)return;const S=Ne(o.chapters[0].file);if(!d){p(S);return}const b=Ne(d);o.chapters.some(w=>Ne(w.file)===b)||p(S)},[o,d,p]);const v=f.useMemo(()=>{if(!o||!d)return null;const S=Ne(d);return o.chapters.find(b=>Ne(b.file)===S)??null},[o,d]);if(f.useEffect(()=>{if(!n||!v||!i.getBookFullTextChapter)return;let S=!1;return h(!0),g(null),i.getBookFullTextChapter(n,v.file).then(b=>{S||g(b)}).catch(()=>{S||g(null)}).finally(()=>{S||h(!1)}),()=>{S=!0}},[n,v,i]),!o)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"});if(o.chapters.length===0)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"});const m=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"0 8px 8px",fontSize:12.5,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:o.version_label}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.chapters.map(S=>{const b=Ne(S.file),j=b===Ne(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(b),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:j?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:j?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:j?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:S.title})},S.file)})})]});return e.jsx(br,{aside:m,children:e.jsxs("div",{children:[v&&e.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[e.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:v.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:o.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:o.source.name}),o.source.license&&e.jsxs(e.Fragment,{children:[" · ",o.source.license]})]})]}),u&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!u&&x&&e.jsx("article",{style:{fontSize:16,lineHeight:1.9,color:"var(--bim-fg, #2c2c2c)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:'"Songti SC", "Source Han Serif", "Noto Serif CJK SC", serif'},children:x.replace(/^##\s+[^\n]+\n+/,"")}),!u&&!x&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})})},Cl=({data:t,onNavigate:n,className:i,style:r})=>{var p;const s=D(),{convert:o}=P(),[l,c]=f.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[a,d]=f.useState(null);return e.jsxs("div",{className:i,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Il,{division:x,expanded:l===x.name,onToggle:()=>c(l===x.name?null:x.name),expandedCat:a,onCatToggle:g=>d(a===g?null:g),onNavigate:n},x.name))})]})},Il=({division:t,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:o})=>{const{convert:l}=P(),c=t.categories.reduce((a,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return a+(p.zhulu||0)+(p.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(Tl,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:o},a.name)})})]})},Tl=({category:t,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,p,x;const{convert:s}=P(),o=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||o.length)+(((x=t.stats)==null?void 0:x.cunmu)||l.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(o.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[o.length>0&&e.jsx(hi,{label:"著錄",books:o,onNavigate:r}),l.length>0&&e.jsx(hi,{label:"存目",books:l,onNavigate:r})]})]})},hi=({label:t,books:n,onNavigate:i})=>{const{convert:r}=P(),s=be(),[o,l]=f.useState(n.length<=20),c=o?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&i?e.jsx("a",{href:s(a.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},d))}),!o&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ke=({title:t,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const o=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&e.jsx("button",{onClick:i,style:Rl,children:"AI"}),n&&e.jsx("button",{onClick:n,style:zl,children:o.action.save})]})]}),s]})},zl={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Rl={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},he=({label:t,value:n,onChange:i,placeholder:r,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:o=>i(o.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),Ue=({value:t,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Dt=({children:t,color:n,style:i})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...i},children:t});function El(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Mt=({value:t,onChange:n,label:i})=>{const[r,s]=f.useState(!1),o=f.useRef(null),l=El(t||"");return f.useEffect(()=>{r&&o.current&&o.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,children:i}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),e.jsx(Dt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,children:i}),e.jsx("input",{ref:o,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},bi={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Bl(t){switch(t){case"url":return"var(--bim-source-url, #2196f3)";case"bookID":return"var(--bim-source-bookid, #4caf50)";default:return"var(--bim-desc-fg, #717171)"}}function Ll(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const $r=({items:t,onChange:n,onOpenEntityPicker:i})=>{const r=D(),[s,o]=f.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),o(t.length)},c=x=>{n(t.filter((g,u)=>u!==x)),s===x&&o(null)},a=(x,g,u)=>{const h=[...t];h[x]={...h[x],[g]:u},n(h)},d=(x,g)=>{const u=[...t];u[x]={...u[x],type:g,id:"",name:""},n(u),g==="bookID"&&i&&i(h=>{const v=[...t];v[x]={...v[x],id:h.id,name:h.title,type:"bookID"},n(v)})},p=x=>{i&&i(g=>{const u=[...t];u[x]={...u[x],id:g.id,name:g.title,type:"bookID"},n(u)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>o(s===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Bl(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Ll(x.type)}),e.jsx("button",{onClick:u=>{u.stopPropagation(),c(g)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...yi,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...yi,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-source-bookid, #4caf50)",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"var(--bim-source-bookid, #4caf50)",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>p(g),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>p(g),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:u=>a(g,"name",u.target.value),placeholder:r.editor.sourceNamePlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:u=>a(g,"id",u.target.value),placeholder:"https://...",style:et})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...$e,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:u=>a(g,"details",u.target.value),placeholder:r.editor.detailsPlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:u=>a(g,"position",u.target.value),placeholder:"如: 卷三, p.52",style:et})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:u=>a(g,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:u=>a(g,"processor_version",u.target.value),placeholder:"如: v0.1",style:et})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},$e={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},et={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},yi={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},vi={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Ar(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Mr(t){return!t||t.length===0?"":JSON.stringify(t)}const Fr=({entityType:t,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:o,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:u,onCreateAndLink:h,onSaveRelations:v})=>{const m=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:m.section.relations})]}),v&&e.jsx("button",{onClick:v,style:Wl,children:m.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:m.relation.belongsToWork,entity:o,onView:u,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(ft,{direction:"up",title:m.relation.containedInCollection,entity:l,onView:u,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),o&&p&&p.length>0&&e.jsx(tt,{direction:"horizontal",title:`${m.relation.siblingVersions} (${p.length})`,entities:p,onView:u,onAdd:()=>h("siblingBook","book",{workId:o.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:m.relation.parentWork,entity:r,onView:u,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),c&&c.length>0&&e.jsx(tt,{direction:"down",title:`${m.relation.childWorks} (${c.length})`,entities:c,onView:u,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),a&&a.length>0&&e.jsx(tt,{direction:"down",title:`${m.relation.collectionImpl} (${a.length})`,entities:a,onView:u,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(tt,{direction:"down",title:`${m.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>h("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:m.relation.correspondingWork,entity:o,onView:u,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(ft,{direction:"up",title:m.relation.parentCollection,entity:s,onView:u,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(tt,{direction:"down",title:`${m.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:u,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(tt,{direction:"down",title:`${m.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},ft=({direction:t,title:n,entity:i,onView:r,onUnlink:s,onLink:o,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:p,unlinkLabel:x})=>{const g=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",u=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:u}),e.jsx("span",{children:n})]}),i?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Pr(i.type)}),e.jsx("span",{style:{fontWeight:500},children:i.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(ji,{onClick:()=>r(i),title:p,children:"👁️"}),e.jsx(ji,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(hn,{onClick:o,children:c}),e.jsx(hn,{onClick:l,primary:!0,children:a})]})]})},tt=({direction:t,title:n,entities:i,onView:r,onAdd:s,addLabel:o,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=f.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=a?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(u=>e.jsxs("div",{onClick:()=>r(u),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Pr(u.type)}),e.jsx("span",{children:u.title})]},u.id)),i.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",i.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(hn,{onClick:s,primary:!0,children:["+ ",o]})})]})},ji=({onClick:t,title:n,danger:i,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),hn=({onClick:t,primary:n,children:i})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:i});function Pr(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Wl={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Hr=({isOpen:t,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:o,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,x]=f.useState(""),g=d?l.filter(m=>m.id!==d):l;f.useEffect(()=>{t&&(x(""),c(""))},[t]);const u=m=>{x(m),c(m)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:$l,children:e.jsxs("div",{style:Al,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),e.jsx("button",{onClick:s,style:Ml,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:m=>u(m.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:Fl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:on,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>e.jsxs("div",{onClick:()=>r(m),style:Pl,children:[e.jsx("span",{style:{fontSize:"16px"},children:v}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):p?e.jsxs("div",{style:on,children:["未找到匹配的",h]}):e.jsxs("div",{style:on,children:["输入关键词搜索",h]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:o,style:Hl,children:["创建新",h,"并关联"]})]})]})})},$l={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Al={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Ml={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Fl={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},Pl={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},on={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Hl={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Si={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Ol={work:"📜",book:"📖",collection:"📚",entity:"👤"},Or=({isOpen:t,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:o})=>{const[l,c]=f.useState(""),a=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,u;(g=a.current)==null||g.focus(),(u=a.current)==null||u.select()},100))},[t,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&l.trim()?p():g.key==="Escape"&&o()},p=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const x=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Si[n]}`}};return e.jsx("div",{style:Dl,onClick:g=>{g.target===g.currentTarget&&o()},children:e.jsxs("div",{style:Nl,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Ol[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Si[n]}名称...`,style:Vl})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:o,style:Gl,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...Yl,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Dl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Nl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Vl={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},Gl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Yl={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Ul(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Dr(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Kl(t){switch(t){case"work":return"var(--bim-editor-type-work, #4caf50)";case"collection":return"var(--bim-editor-type-collection, #2196f3)";case"book":return"var(--bim-editor-type-book, #ff9800)";default:return"var(--bim-desc-fg, #717171)"}}const Nr=({isOpen:t,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:o=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:p})=>{const[x,g]=f.useState(""),[u,h]=f.useState([]),[v,m]=f.useState(!1),[S,b]=f.useState("recent");f.useEffect(()=>{t&&(g(""),h([]),b(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!x.trim()){h([]);return}const _=setTimeout(async()=>{m(!0);try{h(await p(x,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(_)},[x,i,p]);const j=f.useCallback(_=>{g(_.target.value),_.target.value.trim()&&b("search")},[]),w=f.useCallback(_=>s?_.filter(z=>z.id!==s):_,[s]);if(!t)return null;const k=n||(i==="all"?"选择实体":`选择${Dr(i)}`),C=w(r),T=w(u);return e.jsx("div",{style:ql,children:e.jsxs("div",{style:Xl,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:k}),e.jsx("button",{onClick:a,style:Zl,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Ql}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),C.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(ki,{active:S==="recent",onClick:()=>b("recent"),children:["最近使用 (",C.length,")"]}),e.jsxs(ki,{active:S==="search",onClick:()=>b("search"),children:["搜索结果 ",T.length>0&&`(${T.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&C.length>0?e.jsx(wi,{entities:C,onSelect:c}):x.trim()?v?e.jsx(sn,{message:"搜索中..."}):T.length>0?e.jsx(wi,{entities:T,onSelect:c}):e.jsx(sn,{message:"未找到匹配的结果"}):e.jsx(sn,{message:"输入关键词开始搜索"})}),o&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:ea,children:l||"创建新实体"})]})]})})},ki=({active:t,onClick:n,children:i})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:i}),wi=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(Jl,{entity:i,onClick:()=>n(i)},i.id))}),Jl=({entity:t,onClick:n})=>{const[i,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Ul(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:Kl(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Dr(t.type)})]})},sn=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),ql={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Xl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Zl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Ql={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},ea={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ta={work:"var(--bim-editor-type-work, #4caf50)",collection:"var(--bim-editor-type-collection, #2196f3)",book:"var(--bim-editor-type-book, #ff9800)",entity:"var(--bim-editor-type-entity, #9c27b0)"},na={work:"📜",collection:"📚",book:"📖",entity:"👤"},Vr=({data:t,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:o,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:x,onRelationsChange:g})=>{var ne;const u=D(),[h,v]=f.useState(!1),[m,S]=f.useState("work"),[b,j]=f.useState(""),[w,k]=f.useState(""),[C,T]=f.useState([]),[_,z]=f.useState(!1),[I,y]=f.useState(!1),[R,E]=f.useState("work"),[F,$]=f.useState(""),[O,A]=f.useState(),[M,J]=f.useState(!1),[W,Y]=f.useState(null),[ie,K]=f.useState([]);f.useRef(null);const L=t.type,U=L==="work",q=L==="collection",V=L==="book",G=f.useCallback((B,ee)=>{n({...t,[B]:ee})},[t,n]),de=f.useCallback((B,ee)=>{j(B),S(ee),k(u.editor.selectToLink+u.indexType[ee]),T([]),v(!0)},[u]),Se=f.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,B)},[r,t.id]),me=f.useCallback(B=>{s==null||s(B.id,B.type)},[s]),se=f.useCallback((B,ee,le)=>{const X={...le,author:(le==null?void 0:le.author)||t.author,dynasty:le==null?void 0:le.dynasty};E(ee),$(B),A(X),y(!0)},[t.author]),ye=f.useCallback((B,ee)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,F,{type:R,title:B,inheritData:ee}),y(!1)},[r,t.id,F,R]),Ie=f.useCallback(B=>{if(!B.trim()){T([]);return}z(!0),r!=null&&r.searchEntities&&r.searchEntities(B,m).then(ee=>{T(ee),z(!1)}).catch(()=>{T([]),z(!1)})},[r,m]),Te=f.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,b,B.id),v(!1)},[r,t.id,b]),Ze=f.useCallback(()=>{i()},[i]),ct=f.useCallback(B=>{Y(()=>B),J(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(K).catch(()=>{})},[r]),N=f.useCallback((B,ee)=>r!=null&&r.searchEntities?r.searchEntities(B,ee==="all"?void 0:ee):Promise.resolve([]),[r]),oe=f.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),K(ee=>[B,...ee.filter(le=>le.id!==B.id)].slice(0,10)),W==null||W(B),J(!1),Y(null)},[r,W]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:na[L]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Dt,{children:t.id}),e.jsx(Dt,{color:ta[L],children:u.indexType[L]})]})}),e.jsx(ke,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Mt,{label:U?u.editor.workTitle:q?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:B=>G("title",B)}),V&&e.jsx(Mt,{label:u.editor.belongsToWork,value:t.workName||"",onChange:B=>G("workName",B)}),e.jsx(he,{label:u.editor.authorLabel,value:t.author||"",onChange:B=>G("author",B)}),e.jsx(he,{label:u.editor.publicationYearLabel,value:t.publicationYear||"",onChange:B=>G("publicationYear",B)}),(V||q)&&e.jsx(Mt,{label:u.editor.containedIn,value:t.collection||"",onChange:B=>G("collection",B)}),(V||q)&&e.jsx(he,{label:u.editor.holderLabel,value:t.holder||"",onChange:B=>G("holder",B)}),(V||q)&&e.jsx(he,{label:V?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:B=>G("pages",B)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(he,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:B=>G("firstImage",B)})})]})}),e.jsx(ke,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Ue,{value:t.description||"",onChange:B=>G("description",B),placeholder:u.editor.descriptionPlaceholder})}),(((ne=t.additional_works)==null?void 0:ne.length)||0)>0&&e.jsx(ke,{title:u.section.additionalWorks,onSave:i,children:e.jsx(ia,{items:t.additional_works||[],onChange:B=>G("additional_works",B)})}),e.jsx(ke,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(ra,{items:t.indexed_by||[],onChange:B=>G("indexed_by",B)})}),e.jsx(ke,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(oa,{items:t.emendated_by||[],onChange:B=>G("emendated_by",B)})}),e.jsx(ke,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(cn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(ke,{title:u.section.imageResources,onSave:i,children:e.jsx(cn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(ke,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx($r,{items:Ar(t.sources||""),onChange:B=>G("sources",Mr(B)),onOpenEntityPicker:ct})}),(V||q)&&e.jsx(ke,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Ue,{value:t.provenance||"",onChange:B=>G("provenance",B),placeholder:u.editor.provenancePlaceholder})}),V&&e.jsx(ke,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Ue,{value:t.otherEditions||"",onChange:B=>G("otherEditions",B),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(Fr,{entityType:L,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:de,onUnlinkEntity:Se,onViewEntity:me,onCreateAndLink:se,onSaveRelations:Ze}),o&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:u.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:u.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:u.editor.deleteEntity})]}),e.jsx(Hr,{isOpen:h,entityType:m,title:w,onSelect:Te,onCancel:()=>v(!1),onCreate:()=>{v(!1),se(b,m)},searchResults:C,onSearch:Ie,isLoading:_,excludeId:t.id}),e.jsx(Or,{isOpen:I,entityType:R,relationField:F,inheritData:O,onConfirm:ye,onCancel:()=>y(!1)}),e.jsx(Nr,{isOpen:M,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ie,excludeId:t.id,onSelect:oe,onCancel:()=>{J(!1),Y(null)},onSearch:N})]})};function ia({items:t,onChange:n}){const i=D(),r=(l,c,a)=>{const d=t.map((p,x)=>x===l?{...p,[c]:a}:p);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),o=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(he,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(he,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:o,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Gr({items:t,onChange:n,showMeta:i,addLabel:r}){const s=D(),[o,l]=f.useState(null),c=(p,x,g)=>{const u=t.map((h,v)=>v===p?{...h,[x]:g||void 0}:h);n(u)},a=p=>{n(t.filter((x,g)=>g!==p)),o===p&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,x)=>{const g=o===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:p.source||s.editor.unnamedSource}),p.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:p.source_bid}),e.jsx("button",{onClick:u=>{u.stopPropagation(),a(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)"},children:"✕"})]}),!g&&i&&(p.title_info||p.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[p.title_info,p.title_info&&p.author_info&&" — ",p.author_info]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(he,{label:s.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),e.jsx(he,{label:s.label.sourceBid,value:p.source_bid||"",onChange:u=>c(x,"source_bid",u)})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(he,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),e.jsx(he,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),e.jsx(he,{label:s.label.edition,value:p.edition||"",onChange:u=>c(x,"edition",u)})]}),e.jsx(Ue,{value:p.summary||"",onChange:u=>c(x,"summary",u),placeholder:s.editor.summaryPlaceholder}),e.jsx(Ue,{value:p.comment||"",onChange:u=>c(x,"comment",u),placeholder:s.editor.commentPlaceholder}),e.jsx(Ue,{value:p.additional_comment||"",onChange:u=>c(x,"additional_comment",u),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:r})]})}function ra({items:t,onChange:n}){const i=D();return e.jsx(Gr,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function oa({items:t,onChange:n}){const i=D();return e.jsx(Gr,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function Yr(t){var c,a,d,p,x,g,u;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",r=((p=t.current_location)==null?void 0:p.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",o=typeof t.description=="object"&&t.description!==null&&t.description.text||"",l={id:t.id,title:t.title,type:t.type,author:n,publicationYear:i,holder:r,pages:s,description:o,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const h=t;if(Array.isArray(h.related_works)){const v=h.related_works.find(m=>m.relation==="part_of");v&&(l.parentWorkId=v.id,l.parentWorkName=v.title)}}if(t.type==="book"){const h=t;l.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(l.collectionId=(u=h.contained_in[0])==null?void 0:u.id)}return l}function sa(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.publicationYear?{year:t.publicationYear}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const la=t=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:o,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:h,relations:v,onRelationsChange:m,headerExtra:S,className:b,style:j}=t;D();const[w,k]=f.useState(s),C=o?s:w;f.useEffect(()=>{s!==w&&k(s)},[s]);const T=f.useCallback(()=>{const F=C==="view"?"edit":"view";o?o(F):k(F)},[C,o]),[_,z]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(F=>{F&&z(F)})},[i,r]);const I=n||_,y=f.useMemo(()=>I?Yr(I):null,[I]),R=o||!n?e.jsx("button",{onClick:T,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:C==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:C==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:C==="view"?"切换到编辑模式":"切换到查看模式",children:C==="view"?"✏️ 编辑":"👁 查看"}):null,E=e.jsxs(e.Fragment,{children:[R,S]});return!I&&!y?e.jsx(Xe,{}):C==="view"?e.jsx(wn,{data:I,transport:r,onNavigate:d?F=>d(F):void 0,renderLink:p,headerExtra:E,className:b,style:j}):y?e.jsxs("div",{className:b,style:j,children:[E&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:E}),e.jsx(Vr,{data:y,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:h,relations:v,onRelationsChange:m})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},_i=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ur=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,o]=f.useState(null),[l,c]=f.useState(""),[a,d]=f.useState("idle"),[p,x]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(o(null),c(""),d("idle"),x(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=g.current)==null?void 0:m.focus()},100)},[s]),f.useEffect(()=>{if(a==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[a,n]),f.useEffect(()=>{if(!t)return;const m=S=>{S.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const u=async()=>{if(!(!s||!l.trim())){d("submitting"),x("");try{await i({type:s,content:l.trim()}),d("success")}catch(m){d("error"),x(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&l.trim()&&a!=="submitting",v=_i.find(m=>m.value===s);return e.jsx("div",{style:aa,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:ca,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:da,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:pa,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:ma,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:_i.map(m=>e.jsxs("button",{onClick:()=>o(m.value),style:{...ua,...s===m.value?xa:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:g,value:l,onChange:m=>c(m.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...fa,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),a==="error"&&e.jsx("div",{style:ha,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:u,disabled:!h,style:{...ga,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},aa={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ca={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},da={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},pa={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},ua={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},xa={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},fa={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ga={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ma={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ha={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ba=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[r,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...ya,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.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"})})}),e.jsx(Ur,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},ya={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},Ci=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Kr=({onSubmit:t})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[o,l]=f.useState("idle"),[c,a]=f.useState(""),d=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var u;return(u=d.current)==null?void 0:u.focus()},100)},[n]);const p=async()=>{if(!(!n||!r.trim())){l("submitting"),a("");try{await t({type:n,content:r.trim()}),l("success"),s(""),i("bug")}catch(u){l("error"),a(u instanceof Error?u.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&o!=="submitting",g=Ci.find(u=>u.value===n);return o==="success"?e.jsx("div",{style:Ii,children:e.jsxs("div",{style:wa,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:_a,children:"继续提交"})]})}):e.jsxs("div",{style:Ii,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ci.map(u=>e.jsxs("button",{onClick:()=>i(u.value),style:{...va,...n===u.value?ja:{}},children:[e.jsx("span",{children:u.icon})," ",u.label]},u.value))}),e.jsx("textarea",{ref:d,value:r,onChange:u=>s(u.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:o==="submitting",style:{...Sa}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:p,disabled:!x,style:{...ka,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:o==="submitting"?"提交中...":"提交"})]}),o==="error"&&e.jsx("div",{style:Ca,children:c})]})},Ii={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},va={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},ja={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Sa={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},ka={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},wa={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},_a={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Ca={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Ti(t){return typeof t=="function"?t():t??"/api/feedback"}const Jr=({resourceId:t,apiUrl:n})=>{const[i,r]=f.useState([]),[s,o]=f.useState(!0),l=f.useCallback(async()=>{const a=Ti(n);o(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&r(p.items)}catch{}finally{o(!1)}},[t,n]);f.useEffect(()=>{l()},[l]);const c=async a=>{const d=Ti(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!p.ok){const x=await p.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(Fn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(Kr,{onSubmit:c})})]})},ht={versions:12,catalogs:8,chips:12},qr={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Xr=({data:t,transport:n,onNavigate:i,renderLink:r,lineageAction:s,collatedSection:o})=>{var R,E,F,$,O,A,M,J,W,Y,ie,K;const l=D(),{convert:c}=P(),a=f.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[d,p]=f.useState(new Map),[x,g]=f.useState(!1),[u,h]=f.useState(""),[v,m]=f.useState(!1),[S,b]=f.useState("default"),j=x||!!u||v||S==="year",w=f.useMemo(()=>j?a:a.slice(0,ht.versions),[a,j]);f.useEffect(()=>{if(!n||w.length===0)return;const L=w.filter(q=>!d.has(q));if(L.length===0)return;let U=!1;return Promise.all(L.map(q=>n.getItem(q).then(V=>{const G=V??{};return[q,{id:q,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[q,{id:q}]))).then(q=>{U||p(V=>{const G=new Map(V);for(const[de,Se]of q)G.set(de,Se);return G})}),()=>{U=!0}},[n,w,d]);const k=f.useMemo(()=>a.map(L=>d.get(L)??{id:L}),[a,d]),C=f.useMemo(()=>pr(k,t.version_graph,{era:u,scanOnly:v,sort:S}),[k,t.version_graph,u,v,S]),T=x?C.rows:C.rows.slice(0,ht.versions),_=f.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),z=f.useMemo(()=>cr((t.related_works||[]).map(L=>({id:L.id,title:L.title,relation:L.relation}))),[t.related_works]),I=f.useMemo(()=>{var G,de,Se,me;const L=[],U=(de=(G=t.authors)==null?void 0:G[0])==null?void 0:de.dynasty;U&&L.push({label:"成書",value:c(U)});const q=Je(t,l.unit.juan);if(q){const se=(Se=t.juan_count)==null?void 0:Se.description;L.push({label:"卷帙",value:c(q),title:se?c(se):void 0})}const V=C.allRows.filter(se=>se.sortYear!=null);if(V.length>0){const se=V.reduce((ye,Ie)=>ye.sortYear<=Ie.sortYear?ye:Ie);se.era.era&&L.push({label:"最早存世刻本",value:`${se.era.era}${se.era.reign?" "+se.era.reign:""}`,title:se.era.source==="edition"?"據版本題名推斷":void 0})}return(me=t.indexed_by)!=null&&me.length&&L.push({label:"著錄",value:`${t.indexed_by.length} ${l.unit.bu}`}),L},[t,c,l,C.allRows,j,a.length]),y=!o&&a.length===0&&_.buckets.length===0&&_.mirrors.length===0&&!((R=t.indexed_by)!=null&&R.length)&&!((E=t.emendated_by)!=null&&E.length)&&z.length===0&&!((F=t.description)!=null&&F.text);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:I.length?e.jsx(zt,{items:I}):void 0,children:[(($=t.description)==null?void 0:$.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(O=t.description.sources)!=null&&O.length?e.jsx("div",{className:"bim-d-ui",style:{marginTop:8,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:t.description.sources.map(L=>c(As(L))).filter(Boolean).join(" · ")}):null]}),(A=t.appendix)==null?void 0:A.map((L,U)=>e.jsxs("details",{style:{marginTop:12},children:[e.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)",display:"inline-block"},children:c(L.title)}),e.jsx(Me,{text:L.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},U)),e.jsx(Cr,{rows:[{label:l.section.aliases,items:wt(t.additional_titles)},{label:l.section.attachedTexts,items:wt(t.attached_texts)},{label:l.section.appendix,items:(t.additional_works||[]).map(L=>L.book_title+(L.n_juan!=null?` ${L.n_juan}${l.unit.juan}`:""))}]})]}),o,a.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"版",title:l.section.relatedVersions,count:C.rows.length===C.allRows.length?`${C.allRows.length} 種`:`${C.allRows.length} 種 · 當前 ${C.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(He,{label:"僅看有影印",active:v,dashed:!0,onClick:()=>{m(L=>!L),g(!1)}}),e.jsx(Ut,{label:S==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>b(L=>L==="default"?"year":"default")})]})}),C.allRows.length>=6&&C.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(He,{label:l.catalog.all,active:!u,onClick:()=>{h(""),g(!1)}}),C.eras.map(L=>e.jsx(He,{label:L,active:u===L,onClick:()=>{h(L),g(!1)}},L))]}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:qr}),T.map((L,U)=>e.jsx(za,{row:L,no:U,onNavigate:i,renderLink:r},L.id)),T.length===0&&e.jsx(st,{children:u||v?"當前篩選下沒有版本":"暫無版本著錄"})]}),C.rows.length>T.length&&e.jsx(De,{label:`展開其餘 ${C.rows.length-T.length} 種版本`,onClick:()=>g(!0)}),C.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(_.buckets.length>0||_.mirrors.length>0)&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[_.mirrors.map(L=>e.jsx(xn,{title:c(L.label),tag:L.description?c(L.description):void 0,children:L.items.map((U,q)=>e.jsx(ot,{item:U,siblings:L.items},`${U.id||U.url||U.name}-${q}`))},L.key)),_.buckets.map(L=>e.jsx(xn,{title:Ia[L.key],tag:Ta[L.key],children:L.items.map((U,q)=>e.jsx(ot,{item:U,siblings:L.items},`${U.id||U.url||U.name}-${q}`))},L.key))]})]}),(M=t.indexed_by)!=null&&M.length||(J=t.emendated_by)!=null&&J.length?e.jsxs("div",{className:(W=t.emendated_by)!=null&&W.length?"bim-d-pair":void 0,style:(Y=t.emendated_by)!=null&&Y.length?void 0:{marginBottom:48},children:[(ie=t.indexed_by)!=null&&ie.length?e.jsx(Ri,{id:"catalogs",glyph:"目",title:l.section.indexed,items:t.indexed_by,unit:l.unit.bu,cap:ht.catalogs,showMeta:!0,t:l,convert:c,onNavigate:i,renderLink:r}):null,(K=t.emendated_by)!=null&&K.length?e.jsx(Ri,{id:"studies",glyph:"考",title:l.section.emendated,items:t.emendated_by,unit:l.unit.bu,cap:ht.catalogs,t:l,convert:c,onNavigate:i,renderLink:r}):null]}):null,z.map(L=>e.jsx(Ra,{glyph:L.key==="derivative"?"續":"叢",title:l.section[L.labelKey]??l.section.relatedWorks,items:L.items,convert:c,onNavigate:i,renderLink:r},L.key)),y&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:l.section.relatedVersions}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},Ia={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},Ta={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function za({row:t,no:n,onNavigate:i,renderLink:r}){const{convert:s}=P(),o=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(qt,{no:Xt(n),spec:qr,main:e.jsx(_e,{id:t.id,label:s(t.name),onNavigate:i,renderLink:r,dense:!0,style:{fontWeight:t.important?600:400}}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".04em"},title:l?"據版本題名推斷":void 0,children:o||e.jsx(rt,{})}),e.jsx(zi,{items:t.images,convert:s}),e.jsx(zi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function zi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(rt,{});if(t.length===1){const l=t[0],c=(l.url?St(l.url):void 0)||n(l.name),a=Pt(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(fn,{href:a,children:c}):c})}const r=t[0],s=(r.url?St(r.url):void 0)||n(r.name),o=Pt(r);return e.jsxs("span",{style:{minWidth:0},children:[o?e.jsx(fn,{href:o,children:s}):s,e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:4,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:["+",t.length-1]})]})}function Ri({id:t,glyph:n,title:i,items:r,unit:s,cap:o,showMeta:l,t:c,convert:a,onNavigate:d,renderLink:p}){const[x,g]=f.useState({}),[u,h]=f.useState(!1),v=r.length>0&&r.every((b,j)=>x[j]),m=f.useCallback(()=>{g(v?{}:Object.fromEntries(r.map((b,j)=>[j,!0])))},[v,r]),S=u?r:r.slice(0,o);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(ue,{glyph:n,tone:"ink",title:i,count:`${r.length} ${s}`,actions:e.jsx(Ut,{label:v?"收起全部":"+ 展開提要",onClick:m})}),e.jsx(qe,{children:S.map((b,j)=>{const w=b;return e.jsxs(kr,{open:!!x[j],onToggle:()=>g(k=>({...k,[j]:!k[j]})),main:e.jsxs(e.Fragment,{children:[w.source_bid?e.jsx(_e,{id:w.source_bid,label:a(w.source),onNavigate:d,renderLink:p,dense:!0}):a(w.source),l&&w.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(w.section)})]}),action:w.source_bid?e.jsx(_e,{id:w.source_bid,label:c.action.view,onNavigate:d,renderLink:p,dense:!0,style:{fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"}}):void 0,children:[l&&(w.title_info||w.author_info||w.edition)&&e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:"4px 16px",marginBottom:8,fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:[w.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",a(w.title_info)]}),w.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",a(w.author_info)]}),w.edition&&e.jsxs("span",{children:[c.label.edition," ",a(w.edition)]})]}),w.summary&&e.jsx(At,{children:Oe(a(w.summary))}),w.comment&&e.jsx(At,{label:c.section.comment,children:Oe(a(w.comment))}),w.additional_comment&&e.jsx(At,{label:c.section.additionalComment,children:Oe(a(w.additional_comment))}),l&&w.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:w.page})]},j)})}),r.length>S.length&&e.jsx(De,{label:`展開其餘 ${r.length-S.length} ${s}`,onClick:()=>h(!0)})]})}function Ra({glyph:t,title:n,items:i,convert:r,onNavigate:s,renderLink:o}){const[l,c]=f.useState(!1),a=l?i:i.slice(0,ht.chips);return e.jsxs(Ce,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Kt,{children:[a.map(d=>e.jsx(Rt,{children:e.jsx(_e,{id:d.id,label:r(d.title),onNavigate:s,renderLink:o,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx(De,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const Ea=8,Zr=({data:t,transport:n,onNavigate:i,renderLink:r,fullTextSection:s})=>{var w,k,C,T;const o=D(),{convert:l}=P(),[c,a]=f.useState(null),[d,p]=f.useState(new Map),[x,g]=f.useState([]),[u,h]=f.useState(!1);f.useEffect(()=>{if(!n||!t.work_id){a(null);return}let _=!1;return n.getItem(t.work_id).then(z=>{!_&&z&&z.type==="work"&&a(z)}).catch(()=>{}),()=>{_=!0}},[n,t.work_id]),f.useEffect(()=>{const _=t.contained_in||[];if(!n||_.length===0){p(new Map);return}let z=!1;return Promise.all(_.map(I=>{const y=typeof I=="string"?I:I.id;return n.getItem(y).then(R=>[y,R]).catch(()=>[y,null])})).then(I=>{if(z)return;const y=new Map;for(const[R,E]of I)E&&y.set(R,E);p(y)}),()=>{z=!0}},[n,t.contained_in]);const v=f.useMemo(()=>{const _=new Set([...(c==null?void 0:c.books)||[],...t.related_books||[]]);return _.delete(t.id),[..._]},[c==null?void 0:c.books,t.related_books,t.id]);f.useEffect(()=>{if(!n||v.length===0){g([]);return}const _=u?v:v.slice(0,Ea);let z=!1;return Promise.all(_.map(I=>n.getItem(I).then(y=>({id:I,title:y==null?void 0:y.title,edition:y==null?void 0:y.edition})).catch(()=>({id:I})))).then(I=>{z||g(I)}),()=>{z=!0}},[n,v,u]);const m=f.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=f.useMemo(()=>{var F,$,O;const _=[],z=It(t),I=mr(t);I&&_.push({label:"版本類型",value:I,title:(F=t.lineage)!=null&&F.category?void 0:"據版本題名推斷"}),(z.era||z.reign)&&_.push({label:"刊寫年代",value:[z.era,z.reign].filter(Boolean).join(" "),title:z.source==="edition"?"據版本題名推斷":void 0});const y=(t.contained_in||[]).flatMap(A=>typeof A=="string"?[]:vt(A.volume_index));y.length&&(_.push({label:"冊數",value:`${y.length} ${o.unit.volume}`}),_.push({label:"冊次",value:`第 ${En(y,o.unit.volume)} ${o.unit.volume}`}));const R=Je(t,o.unit.juan);R&&_.push({label:"卷帙",value:l(R)});const E=(t.resources||[]).filter(A=>(A.types||(A.type?[A.type]:[])).includes("physical"));return E.length?_.push({label:"存藏",value:E.slice(0,2).map(A=>l(A.name)).join("、")+(E.length>2?` 等 ${E.length} 處`:"")}):($=t.current_location)!=null&&$.name&&_.push({label:"存藏",value:l(t.current_location.name)}),(O=t.page_count)!=null&&O.description&&_.push({label:o.label.pageCount,value:t.page_count.description}),_},[t,l,o]),b=!!((w=t.description)!=null&&w.text),j=(t.contained_in||[]).some(_=>typeof _!="string"&&vt(_.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:S.length?e.jsx(zt,{items:S,horizontal:!b}):void 0,children:b?e.jsx(Me,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),s,(t.contained_in||[]).length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"收",title:o.section.containedIn}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",padding:"14px 4px",display:"flex",flexDirection:"column",gap:12},children:(t.contained_in||[]).map((_,z)=>{var F,$;const I=typeof _=="string"?_:_.id,y=typeof _=="string"?[]:vt(_.volume_index),R=d.get(I),E=((F=R==null?void 0:R.books)==null?void 0:F.length)||(($=R==null?void 0:R.contained_works)==null?void 0:$.length)||0;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"8px 16px",marginBottom:12},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(_e,{id:I,label:R?l(R.title):I,onNavigate:i,renderLink:r})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[E>0&&`全 ${E} ${o.unit.bu}`,E>0&&y.length>0&&" · ",y.length>0&&`本書佔 ${y.length} ${o.unit.volume}`]})]}),y.length>0&&e.jsx(Sr,{volumes:y,unit:o.unit.volume})]},`${I}-${z}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[c&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"作",tone:"ink",title:o.section.belongsToWork}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",padding:"12px 4px 0"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 12px",marginBottom:10},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(_e,{id:c.id,label:l(c.title),onNavigate:i,renderLink:r})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[l(Je(c,o.unit.juan)),(k=c.authors)==null?void 0:k.map(_=>{const z=Rn(_.role);return`${_.dynasty?`〔${l(_.dynasty)}〕`:""}${l(_.name)}${z?" "+l(z):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((C=c.description)==null?void 0:C.text)&&e.jsx(Me,{text:c.description.text,style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"}}),e.jsx("div",{style:{marginTop:14},children:e.jsx(Ln,{label:o.section.aliases,items:[...wt(t.additional_titles),...wt(t.attached_texts)]})})]})]}),(m.buckets.length>0||m.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[m.mirrors.map(_=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{className:"bim-d-ui",style:{padding:"8px 4px 4px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:l(_.label)}),_.items.map((z,I)=>e.jsx(ot,{item:z,showVolumes:!j},`${z.id||z.url||z.name}-${I}`))]},_.key)),m.buckets.flatMap(_=>_.items).map((_,z)=>e.jsx(ot,{item:_,showVolumes:!j},`${_.id||_.url||_.name}-${z}`))]})]})]}),(T=t.location_history)!=null&&T.length?e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"藏",tone:"ink",title:o.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((_,z)=>e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 12px",padding:"9px 4px",fontSize:14,borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsx("span",{children:l(_.name)}),_.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:l(_.description)})]},z))})]}):null,v.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"版",tone:"ink",title:o.relation.siblingVersions,count:`${v.length} 種`,actions:c?e.jsx(_e,{id:c.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:r,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Kt,{children:[x.map(_=>e.jsx(Rt,{children:e.jsx(_e,{id:_.id,label:l(_.edition||_.title||_.id),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},_.id)),v.length>x.length&&e.jsx(De,{inline:!0,label:`更多 ${v.length-x.length} 種`,onClick:()=>h(!0)})]})]})]})},Ei={titles:16,works:16},Qr=({data:t,catalog:n,onNavigate:i,renderLink:r,catalogAction:s})=>{var z,I;const o=D(),{convert:l}=P(),[c,a]=f.useState(""),[d,p]=f.useState(!1),[x,g]=f.useState(!1),u=f.useMemo(()=>fr(t,n),[t,n]),h=f.useMemo(()=>c?u.rows.filter(y=>y.section===c):u.rows,[u.rows,c]),v=d?h:h.slice(0,Ei.titles),m=f.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=t.contained_works||[],b=new Set(u.rows.map(y=>y.id).filter(Boolean)),j=S.length>0&&!S.every(y=>b.has(y.id)),w=(()=>{const y=u.rows.map(R=>R.edition).filter(Boolean);return y.length>1&&new Set(y).size===1})(),k=x?S:S.slice(0,Ei.works),C=u.sections.length>0,T=f.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...C?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[C]),_=f.useMemo(()=>{var F,$,O,A;const y=[];t.subtype&&y.push({label:o.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(F=t.publication_info)!=null&&F.details&&y.push({label:"刊印",value:l(t.publication_info.details)}),($=t.publication_info)!=null&&$.year&&y.push({label:"年代",value:t.publication_info.year});const R=((O=t.books)==null?void 0:O.length)||S.length,E=Je(t,o.unit.juan);return(R||E)&&y.push({label:"種數 / 卷數",value:[R?`${R} ${o.unit.bu}`:"",l(E)].filter(Boolean).join(" · "),title:(A=t.juan_count)!=null&&A.description?l(t.juan_count.description):void 0}),u.totalVolumes&&y.push({label:"全帙冊數",value:`${u.totalVolumes} ${o.unit.volume}`}),y},[t,S.length,u.totalVolumes,l,o]);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:_.length?e.jsx(zt,{items:_}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Me,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(I=t.history)!=null&&I.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((y,R)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",l(y)]},R))}):null]}),u.rows.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"目",title:o.section.containedBooks,count:h.length===u.rows.length?`${o.catalog.contains} ${u.rows.length} ${o.unit.items}`:`${u.rows.length} ${o.unit.items} · 當前 ${h.length} ${o.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,C&&e.jsxs(e.Fragment,{children:[e.jsx(He,{label:o.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),u.sections.map(y=>e.jsx(He,{label:y,active:c===y,onClick:()=>{a(y),p(!1)}},y))]})]})}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:T}),v.map((y,R)=>{var E;return e.jsx(qt,{no:Xt(R),spec:T,main:e.jsxs(e.Fragment,{children:[y.id?e.jsx(_e,{id:y.id,label:l(y.title),onNavigate:i,renderLink:r,dense:!0}):e.jsx("span",{children:l(y.title)}),(E=y.subItems)!=null&&E.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",y.subItems.map(F=>l(F)).join("、"),")"]}):null,y.edition&&!w&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(y.edition)})]}),meta:e.jsxs(e.Fragment,{children:[C&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:y.section?y.section.endsWith("部")?y.section:`${y.section}部`:e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:y.volumes.length>0?`第 ${En(y.volumes,o.unit.volume)} ${o.unit.volume}`:y.expected!=null?`${y.found??0}/${y.expected} ${o.unit.volume}`:e.jsx(rt,{})})]})},`${y.id??y.title}-${R}`)}),v.length===0&&e.jsx(st,{children:o.catalog.noMatch})]}),h.length>v.length&&e.jsx(De,{label:`展開其餘 ${h.length-v.length} ${o.unit.items}子目`,onClick:()=>p(!0)})]}),(m.buckets.length>0||j)&&e.jsxs("div",{className:"bim-d-pair bim-d-pair-wide",children:[(m.buckets.length>0||m.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[...m.mirrors.flatMap(y=>y.items),...m.buckets.flatMap(y=>y.items)].map((y,R)=>e.jsx(ot,{item:y,fallbackNote:y.details?l(y.details):void 0},`${y.id||y.url||y.name}-${R}`))})]}),j&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:o.section.containedWorks,count:`${S.length} 種`}),e.jsxs(Kt,{children:[k.map(y=>e.jsx(Rt,{children:e.jsx(_e,{id:y.id,label:l(y.title),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},y.id)),S.length>k.length&&e.jsx(De,{inline:!0,label:`更多 ${S.length-k.length} 種`,onClick:()=>g(!0)})]})]})]})]})},Ba=16,Bi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},ln=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Li(t){if(!t)return ln.length;const n=ln.indexOf(t);return n===-1?ln.length:n}const eo=({data:t,transport:n,onNavigate:i,renderLink:r})=>{var T,_,z;const s=D(),{convert:o}=P(),[l,c]=f.useState("全部"),[a,d]=f.useState(!1),[p,x]=f.useState("default"),[g,u]=f.useState(new Map),h=f.useMemo(()=>(t.works||[]).map(y=>{const R=g.get(y.work_id);return{id:y.work_id,title:(R==null?void 0:R.title)??y.work_id,role:y.role||"",cls:zn(y.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,g]),v=f.useMemo(()=>xr((t.works||[]).map(I=>I.role)),[t.works]),m=f.useMemo(()=>{const I=l==="全部"?h:h.filter(y=>y.cls===l);return p==="versions"?[...I].sort((y,R)=>(R.versionCount??-1)-(y.versionCount??-1)):I},[h,l,p]),S=a?m:m.slice(0,Ba),b=f.useMemo(()=>S.filter(I=>!g.has(I.id)).map(I=>I.id),[S,g]);f.useEffect(()=>{if(!n||b.length===0)return;let I=!1;return Promise.all(b.map(y=>n.getItem(y).then(R=>{var $,O;const E=R??{},F=((($=E.books)==null?void 0:$.length)??0)+(((O=E.collections)==null?void 0:O.length)??0);return[y,{id:y,title:E.title,versionCount:F,loaded:!0}]}).catch(()=>[y,{id:y,loaded:!0}]))).then(y=>{I||u(R=>{const E=new Map(R);for(const[F,$]of y)E.set(F,$);return E})}),()=>{I=!0}},[n,b]);const j=f.useMemo(()=>{const I=new Map;for(const y of t.alt_names||[]){const R=y.type||s.section.aliases;I.has(R)||I.set(R,[]),I.get(R).push(y.name)}return[...I.entries()].sort((y,R)=>Li(y[0])-Li(R[0])).map(([y,R])=>({label:y,names:R}))},[t.alt_names,s]),w=f.useMemo(()=>{const I=[];t.dynasty&&I.push({label:"時代",value:o(t.dynasty)});const y=E=>E==null?"":E<0?`前${-E}`:String(E);(t.birth_year!=null||t.death_year!=null)&&I.push({label:"生卒",value:`${y(t.birth_year)||"?"}—${y(t.death_year)||"?"}`});const R=(t.works||[]).length;return R&&I.push({label:"著作數",value:`${R} 種`}),I},[t,o]),k=(T=t.external_ids)==null?void 0:T.cbdb_id,C=!!((_=t.description)!=null&&_.text);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:w.length?e.jsx(zt,{items:w}):void 0,children:(j.length>0||C)&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[j.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:j.map(I=>e.jsxs("span",{style:{display:"flex",alignItems:"baseline",gap:8,minWidth:0},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".1em",flex:"none"},children:o(I.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:I.names.map(y=>o(y)).join(" · ")})]},I.label))}),C&&e.jsx(Me,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),h.length===0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該人物的關聯作品。"})})]}),h.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks,count:m.length===h.length?`${h.length} 種`:`${h.length} 種 · 當前 ${m.length} 種`,actions:e.jsx(Ut,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{x(I=>(I==="default"&&d(!0),I==="default"?"versions":"default"))}})}),v.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:v.map(I=>e.jsx(He,{label:`${I.label} ${I.count}`,active:l===I.cls,onClick:()=>{c(I.cls),d(!1)}},I.cls))}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:Bi}),S.map((I,y)=>e.jsx(qt,{no:Xt(y),spec:Bi,main:e.jsx(_e,{id:I.id,label:o(I.title),onNavigate:i,renderLink:r,dense:!0}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:I.role?o(I.role):e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:I.loaded?I.versionCount?`${I.versionCount} 種版本`:e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},I.id)),S.length===0&&e.jsx(st,{children:"該職任下的著作尚未著錄。"})]}),m.length>S.length&&e.jsx(De,{label:`展開其餘 ${m.length-S.length} 條著作`,onClick:()=>d(!0)}),k!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",k,((z=t.external_ids)==null?void 0:z.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function La(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function Wa(t,n){if(!t.lineage)return null;const i=t.lineage;return{id:t.id,kind:"book",label:t.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[t.id],note:i.note}}function Wi(t,n,i){return{id:`derive:${n.ref}->${t}:${i}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function $a(t,n,i){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Aa(t,n){var d;if(n==="all")return null;const i=(d=t.collections)==null?void 0:d[n],r=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,o=r||s||!!(i!=null&&i.hypothetical_ids);if(!o&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!i||!o)return null;const l=r?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&t.node_groups)for(const[p,x]of Object.entries(t.node_groups))l.has(x)&&c.add(p);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),l){a||(a=new Set);for(const p of t.hypothetical_nodes??[])p.group&&l.has(p.group)&&a.add(p.id)}return{books:c,hypos:a}}function Ft(t,n,i){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const o=new Set(r.excluded_books??[]),l=r.node_groups??{},c=Aa(r,i??r.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,x=new Set,g=new Set;if(a){const w=new Map(n.map(I=>[I.id,I])),k=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),C=I=>{const y=w.get(I);if(y&&y.lineage)return(y.lineage.derived_from??[]).map(E=>E.ref);const R=k.get(I);return R?(R.derived_from??[]).map(E=>E.ref):[]},T=I=>k.has(I)?!p||p.has(I):!d||d.has(I),_=new Set,z=I=>{if(!_.has(I)){_.add(I);for(const y of C(I))o.has(y)||(T(y)||(k.has(y)?g.add(y):w.has(y)&&x.add(y)),z(y))}};for(const I of n)d&&d.has(I.id)&&!o.has(I.id)&&z(I.id);for(const I of r.hypothetical_nodes??[])p&&p.has(I.id)&&z(I.id)}const u=n.filter(w=>!o.has(w.id)).filter(w=>!d||d.has(w.id)||x.has(w.id)).map(w=>{const k=Wa(w,l);return k&&x.has(w.id)&&(k.bridge=!0),k}).filter(w=>w!==null),h=(r.hypothetical_nodes??[]).filter(w=>!p||p.has(w.id)||g.has(w.id)).map(w=>{const k=La(w);return g.has(w.id)&&(k.bridge=!0),k}),v=[...u,...h],m=new Set(v.map(w=>w.id)),S=new Set,b=[],j=w=>{S.has(w.id)||!m.has(w.source)||!m.has(w.target)||(S.add(w.id),b.push(w))};for(const w of n)o.has(w.id)||!w.lineage||d&&!d.has(w.id)&&!x.has(w.id)||((w.lineage.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))}),(w.lineage.related_to??[]).forEach((k,C)=>{j($a(w.id,k,C))}));for(const w of r.hypothetical_nodes??[])p&&!p.has(w.id)&&!g.has(w.id)||(w.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))});return{nodes:v,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(o)}}function to(t,n,i){const r=(t??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Ma(t,n){const i=[],r=t.version_graph;if(!r)return i;const s=new Set(n.map(a=>a.id)),o=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...o]),c=(a,d)=>{l.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!o.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(p=>c(d,p)),(a.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const no=({graph:t,renderLink:n,className:i,style:r})=>{const{convert:s}=P();if(!t.nodes.length)return e.jsx("div",{style:{...Xa,...r},className:i,children:"暂无版本图数据"});const o=new Map,l=new Map;for(const g of t.edges)if(g.kind==="derive"){const u=o.get(g.target)??[];u.push(g),o.set(g.target,u)}else for(const u of[g.source,g.target]){const h=l.get(u)??[];h.push(g),l.set(u,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),a=new Map,d=[];for(const g of t.nodes)if(g.group){const u=a.get(g.group)??[];u.push(g),a.set(g.group,u)}else d.push(g);const p=(g,u)=>(g.year??9999)-(u.year??9999);a.forEach(g=>g.sort(p)),d.sort(p);const x=t.groups.filter(g=>a.has(g.id));return e.jsxs("div",{className:i,style:{...Pa,...r},children:[t.title&&e.jsx("div",{style:Ha,children:s(t.title)}),t.description&&e.jsx("div",{style:Oa,children:s(t.description)}),x.map(g=>e.jsx($i,{label:g.label,color:g.color,nodes:a.get(g.id),incomingMap:o,siblingMap:l,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx($i,{label:"其他",nodes:d,incomingMap:o,siblingMap:l,nodeMap:c,renderLink:n})]})},$i=({label:t,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:o,renderLink:l})=>{const{convert:c}=P();return e.jsxs("div",{style:Da,children:[e.jsx("div",{style:{...Na,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(Fa,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:o,renderLink:l},a.id))]})},Fa=({node:t,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const o=t.kind==="hypothetical",l=t.bridge,{convert:c}=P();return e.jsxs("div",{style:{...Va,borderStyle:o||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Ga,children:[e.jsx("span",{style:Ya,children:o||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Ua,children:to(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Ka,children:[t.category&&e.jsx(gt,{children:c(t.category)}),t.status==="lost"&&e.jsx(gt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(gt,{tone:"warn",children:"残本"}),o&&e.jsx(gt,{tone:"info",children:"假想祖本"}),l&&e.jsx(gt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Ja,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:qa,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Mi,children:[e.jsx("div",{style:Fi,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return e.jsxs("div",{style:Pi(a.confidence),children:[e.jsx("span",{style:Hi,children:c(a.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&e.jsx(Ai,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:Mi,children:[e.jsx("div",{style:Fi,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=r.get(d);return e.jsxs("div",{style:Pi(a.confidence),children:[e.jsx("span",{style:Hi,children:c(a.relation)}),e.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&s?s(p.id,c(p.label)):c((p==null?void 0:p.label)??d)}),e.jsx(Ai,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(a.evidence)]})]},a.id)})]})]})},gt=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Ai=({level:t})=>{const i={certain:{label:"确定",color:"var(--bim-confidence-certain, #2e7d32)"},consensus:{label:"共识",color:"var(--bim-confidence-consensus, #1976d2)"},probable:{label:"推测",color:"var(--bim-confidence-probable, #ed6c02)"},disputed:{label:"有争议",color:"var(--bim-confidence-disputed, #c62828)"}}[t];return i?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},Pa={fontSize:"14px",color:"var(--bim-fg, #333)"},Ha={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Oa={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Da={marginBottom:"16px"},Na={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Va={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Ga={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ya={fontSize:"15px",fontWeight:600},Ua={fontSize:"12px",color:"var(--bim-muted, #777)"},Ka={marginBottom:"6px"},Ja={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},qa={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Mi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Fi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Pi=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Hi={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Oi={fontSize:"11px",color:"var(--bim-muted, #888)"},Xa={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},io=({selectedNodeId:t,...n})=>{const[i,r]=f.useState("loading"),[s,o]=f.useState(null);return f.useEffect(()=>{let l=!1;return Za().then(c=>{l||(c?(o(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:Di,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:Di,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(Qa,{modules:s,selectedNodeId:t,...n})};async function Za(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Qa=({graph:t,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:o,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:x,BaseEdge:g,EdgeLabelRenderer:u,getSmoothStepPath:h,dagre:v}=l,m=f.useMemo(()=>({lineage:C=>{var O,A,M,J;const T=((O=C.data)==null?void 0:O.stepPosition)??.85,[_,z,I]=h({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:T,borderRadius:5}),y=!!((A=C.data)!=null&&A.isSibling),R=y?z:C.targetX-18,E=y?I:C.targetY-12,F=(M=C.data)==null?void 0:M.labelStyle,$=(J=C.data)==null?void 0:J.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:C.id,path:_,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&e.jsx(u,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${R}px,${E}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...$,...F},children:C.label})})]})}}),[g,u,h]),S=f.useMemo(()=>({version:C=>{const T=C.data,_=T.kind==="hypothetical",z=T.status==="lost",I=T.isSelected,y=T.bridge,R=T.borderColor??"var(--bim-muted, #888)",E=y||_?"dashed":"solid",F=y?.5:z?.6:1;return e.jsxs("div",{style:{background:y?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${E} ${I?"var(--bim-primary, #0078d4)":R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:F,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":_||y?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:y?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(p,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:_||!T.renderLink?T.label:T.renderLink(T.bookId,T.label)}),T.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:T.description}),T.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:to(T.yearText,void 0,T.uncertain)}),z&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(p,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[p,x]),{convert:b}=P(),{rfNodes:j,rfEdges:w}=f.useMemo(()=>ec(t,v,n,o,b),[t,v,n,o,b]);return e.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:e.jsxs(c,{nodes:j,edges:w,nodeTypes:S,edgeTypes:m,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function ec(t,n,i,r,s=o=>o??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(S=>[S.id,S.color??"var(--bim-muted, #888)"]));for(const S of t.nodes)a.setNode(S.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const S of t.edges)S.kind==="derive"&&(p.has(S.relation)||a.setEdge(S.source,S.target));n.layout(a);const x=t.nodes.map(S=>{const b=a.node(S.id),j=r&&S.id===r,w={kind:S.kind,label:s(S.label),bookId:S.kind==="book"?S.id:void 0,yearText:s(S.year_text??nc(S)),uncertain:S.year_uncertain,category:S.category,status:S.status,borderColor:S.group?d.get(S.group):void 0,renderLink:i,isSelected:j,description:s(S.description),bridge:S.bridge};return{id:S.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:w,draggable:!1,selected:j}}),g=.78,u=.06,h=new Map;for(const S of t.edges)S.kind==="derive"&&(h.has(S.source)||h.set(S.source,[]),h.get(S.source).push(S));const v=new Map;for(const[S,b]of h){if(b.length<=1)continue;const j=[...b].sort((k,C)=>{var z,I;const T=((z=a.node(k.target))==null?void 0:z.y)??0,_=((I=a.node(C.target))==null?void 0:I.y)??0;return T-_}),w=j.length;j.forEach((k,C)=>{const T=(C-(w-1)/2)*u;v.set(k.id,g+T)})}const m=t.edges.map(S=>tc(S,v.get(S.id),s));return{rfNodes:x,rfEdges:m}}function tc(t,n,i=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",o=ic(t.confidence),l={type:"arrowclosed",color:o,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:i(t.relation),data:{labelStyle:{color:"var(--bim-fg, #444)"},isSibling:s,stepPosition:n},style:{stroke:o,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function nc(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function ic(t){switch(t){case"certain":return"var(--bim-confidence-certain, #2e7d32)";case"consensus":return"var(--bim-lineage-edge-consensus, #555)";case"probable":return"var(--bim-confidence-probable, #ed6c02)";case"disputed":return"var(--bim-confidence-disputed, #c62828)";default:return"var(--bim-muted, #888)"}}const Di={padding:"40px 20px",textAlign:"center",color:"var(--bim-muted, #888)",fontSize:"13px",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:8,background:"var(--bim-bg, #fafafa)"},ro=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:o,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:x})=>{var b;const[g,u]=f.useState(n),h=j=>{u(j),o==null||o(j)},v=(()=>{if(!a)return[];const j=Object.entries(a);return j.length===0||a.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(c&&v.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const S=l?(b=a==null?void 0:a[l])==null?void 0:b.description:void 0;return e.jsxs("div",{className:p,style:x,children:[e.jsxs("div",{style:rc,children:[e.jsx("button",{onClick:()=>h("list"),style:an(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:an(g==="graph"),children:"关系图"}),m&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),v.map(([j,w])=>{const k=d==null?void 0:d[j];return e.jsxs("button",{onClick:()=>c==null?void 0:c(j),style:an(l===j),title:w.description,children:[w.label,k!=null?` ${k}`:""]},j)})]})]}),m&&S&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:S}),g==="list"?e.jsx(no,{graph:t,renderLink:i}):e.jsx(io,{graph:t,renderLink:i,height:r,selectedNodeId:s})]})},rc={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},an=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),oo=({style:t})=>{const n=f.useContext(_t);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",o=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:o,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})},so=({href:t,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:o=>{o.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:o=>{o.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.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"})})}),oc=({id:t,transport:n,activeTab:i,onTabChange:r,activeJuan:s,onJuanChange:o,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:x,onNavigate:g,onBack:u,backLabel:h,renderLink:v,enrichDetail:m,getSourceLink:S,extraTabs:b=[],showFeedbackTab:j=!0,feedbackApiUrl:w,height:k,footerExtra:C,className:T,style:_})=>{const z=D(),{convert:I}=P(),[y,R]=f.useState(null),[E,F]=f.useState(null),[$,O]=f.useState(!0),[A,M]=f.useState(!1),[J,W]=f.useState([]),[Y,ie]=f.useState(!1),[K,L]=f.useState(null),[U,q]=f.useState(!1),[V,G]=f.useState(null),[de,Se]=f.useState(!1),[me,se]=f.useState(null),[ye,Ie]=f.useState(!1),Te=f.useRef(null),[Ze,ct]=f.useState(null),N=s!==void 0?s:Ze,oe=f.useCallback(H=>{o?o(H):ct(H)},[o]),ne=f.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ie(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const re=await n.getCollectionCatalog(H);W(re?[{resource_id:"",data:re}]:[])}}catch{W([])}finally{ie(!1)}},[n]),B=f.useCallback(async H=>{if(!n.getCollatedEditionIndex){L(null);return}q(!0);try{L(await n.getCollatedEditionIndex(H))}catch{L(null)}finally{q(!1)}},[n]),ee=f.useCallback(async H=>{if(!n.getBookFullTextIndex){G(null);return}Se(!0);try{G(await n.getBookFullTextIndex(H))}catch{G(null)}finally{Se(!1)}},[n]),le=f.useCallback(async(H,re)=>{Ie(!0);try{if(n.getLineageGraph){const We=await n.getLineageGraph(H);We&&se(We)}const ae=re.version_graph;if(!ae||!ae.enabled){me||se(null),Te.current=null;return}const ce=re.books??[],te=[];for(const We of ce)try{const ze=await n.getItem(We);ze&&te.push(ze)}catch{}Te.current={work:re,books:te};const Z=a??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Le=Z==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":Z??"all";se(Ft(re,te,Le))}catch{se(null),Te.current=null}finally{Ie(!1)}},[n]);f.useEffect(()=>{let H=!1;return(async()=>{O(!0),M(!1),R(null),F(null),W([]),L(null),se(null),Te.current=null;try{const ae=await n.getItem(t);if(H)return;if(!ae){M(!0);return}const ce=ae;let te=null;if(n.getEntry&&(te=await n.getEntry(t),H))return;te||(te={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),m&&m(te,ce),R(te),F(ce),ce.type==="collection"?ne(t):ce.type==="work"?((ce.has_collated||n.getCollatedEditionIndex)&&B(t),(ce.version_graph||n.getLineageGraph)&&le(t,ce)):ce.type==="book"&&ce.has_full_text&&n.getBookFullTextIndex&&ee(t)}catch{H||M(!0)}finally{H||O(!1)}})(),()=>{H=!0}},[t,n,m,ne,B,le,ee]),f.useEffect(()=>{const H=Te.current;!H||!a||se(Ft(H.work,H.books,a))},[a]);const X=[];if(E){if(X.push({key:"basic",label:z.detailTab.basicInfo}),E.type==="collection"){Y&&J.length===0&&X.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const H of J)X.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${I(H.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}E.type==="work"&&(K||U)&&i==="collated"&&X.push({key:"collated",label:U?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),E.type==="book"&&(V||de)&&i==="fulltext"&&X.push({key:"fulltext",label:de?`${z.detailTab.fullText}…`:z.detailTab.fullText}),E.type==="work"&&(me||ye)&&X.push({key:"lineage",label:ye?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const H of b)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&X.push({key:H.key,label:H.label});j&&i==="feedback"&&X.push({key:"feedback",label:z.detailTab.feedback});for(const H of b)H.position==="after-feedback"&&H.shouldShow(E)&&X.push({key:H.key,label:H.label})}f.useEffect(()=>{if(i!=="emendated"||!E)return;r("basic");const H=setTimeout(()=>{var re;(re=document.getElementById("studies"))==null||re.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,E,r]);const Pe=y&&E&&S?S({activeTab:i,activeJuan:N,entry:y,detail:E}):null,ve=f.useMemo(()=>{var te;if(!E)return null;const re=(E.authors??[]).map(Z=>{const Le=Rn(Z.role);return`${Z.dynasty?`〔${I(Z.dynasty)}〕`:""}${I(Z.name)}${Le?` ${I(Le)}`:""}`}).join(" · ");let ae=!1;try{ae=Q.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Z=E;return{title:I(Z.title),subtitle:Z.edition?I(Z.edition):re||void 0,aside:[ae?z.status.draft:"",re&&Z.edition?re:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Z=E;return{title:I(Z.title),subtitle:I(Je(Z,z.unit.juan))||void 0,aside:[(te=Z.publication_info)==null?void 0:te.year,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:re||void 0}}if(E.type==="entity"){const Z=E,Le=ze=>ze==null?"":ze<0?`前${-ze}`:String(ze),We=Z.birth_year!=null||Z.death_year!=null?`${Le(Z.birth_year)||"?"}—${Le(Z.death_year)||"?"}`:"";return{title:I(Z.primary_name||Z.title),subtitle:[Z.dynasty?`〔${I(Z.dynasty)}〕`:"",We].filter(Boolean).join(" ")||void 0,aside:ae?z.status.draft:void 0,secondLine:void 0}}const ce=I(Je(E,z.unit.juan));return{title:I(E.title),subtitle:[ce,re].filter(Boolean).join(" · ")||void 0,aside:[lc(z,E.subtype),ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,I,z]),ge=()=>{var H,re;return E?E.type==="work"?e.jsx(Xr,{data:E,transport:n,onNavigate:g,renderLink:v,collatedSection:K&&(((H=K.juan_files)==null?void 0:H.length)??0)>0?e.jsx(Ni,{title:E.title,measure:`${K.juan_files.length} ${I(z.unit.juan)}`,onOpen:()=>{oe(K.juan_files[0]),r("collated")}}):null,lineageAction:me&&me.nodes.length>0?e.jsxs("button",{type:"button",onClick:()=>r("lineage"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.lineage," →"]}):null}):E.type==="book"?e.jsx(Zr,{data:E,transport:n,onNavigate:g,renderLink:v,fullTextSection:V&&V.chapters.length>0?e.jsx(Ni,{title:E.title,measure:[`${V.total_chapters} ${I("章")}`,I(V.version_label)].filter(Boolean).join(" · "),onOpen:()=>{oe(null),r("fulltext")}}):null}):E.type==="collection"?e.jsx(Qr,{data:E,catalog:(re=J[0])==null?void 0:re.data,transport:n,onNavigate:g,renderLink:v,catalogAction:J.length>0?e.jsxs("button",{type:"button",onClick:()=>r(`catalog:${J[0].resource_id}`),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.collectionCatalog," →"]}):null}):e.jsx(eo,{data:E,transport:n,onNavigate:g,renderLink:v}):null},Qe=()=>{var re,ae,ce;if(!y||!E)return null;if(i==="basic"||i==="emendated")return ge();if(typeof i=="string"&&i.startsWith("catalog:")){const te=(re=J.find(Z=>`catalog:${Z.resource_id}`===i))==null?void 0:re.data;return e.jsx(_n,{data:te,onNavigate:g,renderLink:v})}if(i==="collated")return e.jsx(Mn,{index:K||void 0,workId:t,transport:n,onNavigate:g,activeJuan:N,onJuanChange:oe});if(i==="fulltext")return e.jsx(Wr,{index:V||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:oe});if(i==="lineage"){if(!me)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:ye?"加載中…":"暫無版本圖數據"});const te=E.type==="work"?E:null;return e.jsx(ro,{graph:me,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:x,collection:a??((ae=te==null?void 0:te.version_graph)==null?void 0:ae.default_collection),onCollectionChange:d,collectionsAvailable:(ce=te==null?void 0:te.version_graph)==null?void 0:ce.collections,collectionCounts:(()=>{var ze,Pn,Hn,On,Dn,Nn,Vn;if(!te)return;const Z={},Le=((ze=Te.current)==null?void 0:ze.books)??[];Z.all=(((Pn=te.books)==null?void 0:Pn.length)??0)-(((On=(Hn=te.version_graph)==null?void 0:Hn.excluded_books)==null?void 0:On.length)??0);const We=(Dn=te.version_graph)==null?void 0:Dn.collections;if(We)for(const Gn of Object.keys(We))Z[Gn]=Ft(te,Le,Gn).nodes.filter(Yn=>Yn.kind==="book"&&!Yn.bridge).length;return Z.core==null&&((Vn=(Nn=te.version_graph)==null?void 0:Nn.core_books)!=null&&Vn.length)&&(Z.core=te.version_graph.core_books.length),Z})()})}if(i==="feedback"&&j)return e.jsx(Jr,{resourceId:t,apiUrl:w});const H=b.find(te=>te.key===i);return H?H.render({detail:E,entry:y,transport:n,onNavigate:g}):null};if($)return e.jsx($t,{style:{minHeight:k,..._},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,re)=>e.jsx("div",{style:{height:re===1?40:16,width:H,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},re))})});if(A||!E||!y||!ve)return e.jsx($t,{style:{minHeight:k,..._},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const lo=i==="basic"||i==="emendated",Zt=[{label:h??z.detailTab.backToIndex,onClick:u}];if(E.type==="book"&&E.work_id){const H=E.work_id;Zt.push({label:z.indexType.work,id:H,onClick:()=>g==null?void 0:g(H)})}Zt.push({label:z.indexType[E.type]});const Et=i==="collated"||i==="fulltext";return e.jsx("div",{className:T,children:e.jsxs($t,{wide:Et,style:{minHeight:k,..._},children:[e.jsx(yr,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Bn,{char:"籍"}),e.jsx(vr,{items:Zt})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(oo,{}),j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.feedback}),Pe&&e.jsx(so,{...Pe})]})}),e.jsx(jr,{...ve,aside:Et?e.jsxs("button",{type:"button",onClick:()=>r("basic"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[I("作品信息")," →"]}):ve.aside}),!Et&&X.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:X.map(H=>e.jsx(He,{label:H.label,active:H.key===i||lo&&H.key==="basic",onClick:()=>r(H.key)},H.key))}),e.jsx("div",{style:{marginTop:!Et&&X.length>1?8:0},children:Qe()}),e.jsx(Ir,{left:e.jsxs(e.Fragment,{children:[C,C?" · ":"",e.jsx(sc,{id:E.id,label:z.label.id,copied:z.action.copied})]}),right:e.jsxs(e.Fragment,{children:[j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.submitVersion}),Pe&&e.jsx("a",{href:Pe.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function sc({id:t,label:n,copied:i}){const[r,s]=f.useState(!1);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsxs("span",{children:[n," ",t]}),e.jsx("button",{type:"button",onClick:()=>{var o;(o=navigator.clipboard)==null||o.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}).catch(()=>{})},title:r?i:void 0,style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:r?"✓":"⧉"})]})}function lc(t,n){return n?t.workSubtype[n]??n:""}function Ni({title:t,measure:n,onOpen:i}){const{convert:r}=P(),[s,o]=f.useState(!1),l=r(t?`進入《${t}》全文閲讀`:"進入全文閲讀"),c=[n,r("全文檢索"),r("原書對照")].filter(Boolean).join(" · ");return e.jsx(Ce,{style:{marginTop:-12,marginBottom:28},children:e.jsxs("div",{role:"button",tabIndex:0,onClick:i,onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),i())},onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,flexWrap:"wrap",padding:"14px 26px",cursor:"pointer",background:s?"var(--bim-band-bg-hover, #e6d5b4)":"var(--bim-band-bg, #f0e4cb)",borderLeft:"3px solid var(--bim-accent, #9c3a2c)",transition:"background .18s ease"},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontFamily:"var(--bim-font-body, system-ui, sans-serif)",fontSize:21,fontWeight:600,letterSpacing:".02em",lineHeight:1.3,color:"var(--bim-ink, #2a231c)"},children:l}),e.jsx("div",{className:"bim-d-ui",style:{marginTop:4,fontSize:12.5,letterSpacing:".06em",color:"var(--bim-meta-fg, #7b6a54)"},children:c})]}),e.jsxs("span",{className:"bim-d-ui","aria-hidden":!0,style:{flex:"none",padding:"11px 22px",fontSize:14,letterSpacing:".08em",background:s?"var(--bim-accent-deep, #6f2a20)":"var(--bim-accent, #9c3a2c)",color:"var(--bim-page-bg, #fbf9f3)",transition:"background .18s ease"},children:[r("開始閲讀")," →"]})]})})}exports.BidLink=Q.BidLink;exports.BookIndexError=Q.BookIndexError;exports.BookIndexManager=Q.BookIndexManager;exports.BookIndexStorage=Q.BookIndexStorage;exports.BundleStorage=Q.BundleStorage;exports.ConfigError=Q.ConfigError;exports.GithubStorage=Q.GithubStorage;exports.IdGenerationError=Q.IdGenerationError;exports.IdGenerator=Q.IdGenerator;exports.LocalStorage=Q.LocalStorage;exports.MigrationError=Q.MigrationError;exports.StorageError=Q.StorageError;exports.base36Decode=Q.base36Decode;exports.base36Encode=Q.base36Encode;exports.base58Decode=Q.base58Decode;exports.buildId=Q.buildId;exports.buildPromotionMap=Q.buildPromotionMap;exports.cleanName=Q.cleanName;exports.decodeId=Q.decodeId;exports.decodeIdString=Q.decodeIdString;exports.encodeId=Q.encodeId;exports.extractIdFromUrl=Q.extractIdFromUrl;exports.extractStatus=Q.extractStatus;exports.extractType=Q.extractType;exports.normalizeCatalog=Q.normalizeCatalog;exports.parseId=Q.parseId;exports.shardOf=Q.shardOf;exports.smartDecode=Q.smartDecode;exports.validateResource=Q.validateResource;exports.Badge=Dt;exports.BidUrlProvider=yo;exports.BookDetailLayout=oc;exports.BookFullText=Wr;exports.BookPage=Zr;exports.Breadcrumb=vr;exports.Chip=Rt;exports.ChipWall=Kt;exports.CollatedEdition=Mn;exports.CollectionCatalog=_n;exports.CollectionPage=Qr;exports.CreateEntityDialog=Or;exports.DETAIL_CSS=hr;exports.Dash=rt;exports.DataTable=qe;exports.DetailFooter=Ir;exports.DetailHeader=jr;exports.EmendatedBySection=rr;exports.EmptyNote=st;exports.EntityDetail=Zi;exports.EntityPage=eo;exports.EntityPickerDialog=Nr;exports.EntitySelector=Hr;exports.ExpandRow=kr;exports.ExtLink=fn;exports.FactList=zt;exports.FeedbackButton=ba;exports.FeedbackDialog=Ur;exports.FeedbackForm=Kr;exports.FeedbackList=Fn;exports.FeedbackTab=Jr;exports.FilterChip=He;exports.FormInput=he;exports.FormTextArea=Ue;exports.GlyphBadge=Bn;exports.HomePage=mn;exports.IndexApp=_l;exports.IndexBrowser=dn;exports.IndexDetail=wn;exports.IndexEditor=Vr;exports.IndexView=la;exports.IntroGrid=Tt;exports.LocaleContext=_t;exports.LocaleProvider=To;exports.LocaleToggle=oo;exports.ModeIndicator=qi;exports.MoreButton=De;exports.PAGE_MAX_WIDTH=mt;exports.PageFrame=$t;exports.Quote=At;exports.ROLE_CLASS_ORDER=ur;exports.RelationPanel=Fr;exports.RepoSourceLink=so;exports.ResourceEditor=cn;exports.ResourceGroup=xn;exports.ResourceLine=ot;exports.ResourceList=kn;exports.ResourceRow=wr;exports.SearchInput=Xi;exports.Section=ke;exports.SectionHead=ue;exports.SmartBidInput=Mt;exports.SourceEditor=$r;exports.TableHead=Jt;exports.TableRow=qt;exports.TagRow=Ln;exports.TagRows=Cr;exports.TextButton=Ut;exports.TopStrip=yr;exports.VersionLineageGraph=io;exports.VersionLineageList=no;exports.VersionLineageView=ro;exports.VolumeChips=Sr;exports.VolumeLinks=_r;exports.WorkCatalog=Cl;exports.WorkPage=Xr;exports.bucketResources=Yt;exports.buildCollectionTable=fr;exports.buildLineageGraph=Ft;exports.buildPageUrl=Sn;exports.buildVersionRow=dr;exports.buildVersionTable=pr;exports.computeVersionPartition=Ls;exports.deriveDating=Rs;exports.deriveEditionType=mr;exports.deriveEra=It;exports.deriveYear=Gt;exports.deriveYearRange=In;exports.detailToEditor=Yr;exports.displayAuthorRole=Rn;exports.editorToDetail=sa;exports.eraRank=un;exports.flattenTitles=wt;exports.formatTemplate=Ct;exports.formatVolumeRange=En;exports.getDisplayNameFromUrl=St;exports.getStartPage=jn;exports.getTypeGroupKey=bn;exports.groupRelatedWorks=cr;exports.measureText=Je;exports.mergeVolumeResources=yn;exports.normalizeEra=pe;exports.normalizeRole=zn;exports.normalizeVolumeIndex=vt;exports.normalizeVolumes=Ji;exports.numberToChinese=gr;exports.parseChineseNumber=Ht;exports.parseSourceString=Ar;exports.resourceHref=Pt;exports.resourceNote=Tn;exports.roleFacets=xr;exports.rowNo=Xt;exports.sortYear=ar;exports.stringifySources=Mr;exports.useBidUrl=be;exports.useConvert=P;exports.useT=D;exports.validateLineageGraph=Ma;exports.volumeStats=vn;
|