book-index-ui 0.7.5 → 0.8.0
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 +6 -6
- package/dist/index.d.ts +21 -3
- package/dist/index.js +7770 -7690
- package/dist/{storage-entry-DJXViIHU.js → storage-entry-DkYsoB3e.js} +337 -312
- package/dist/storage-entry-VGdfSKGX.cjs +2 -0
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +18 -1
- package/dist/storage.js +1 -1
- package/package.json +1 -1
- package/dist/storage-entry-BszwT2ej.cjs +0 -2
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
"use strict";var Qo=Object.create;var Fn=Object.defineProperty;var er=Object.getOwnPropertyDescriptor;var tr=Object.getOwnPropertyNames;var nr=Object.getPrototypeOf,ir=Object.prototype.hasOwnProperty;var or=(t,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of tr(n))!ir.call(t,s)&&s!==i&&Fn(t,s,{get:()=>n[s],enumerable:!(o=er(n,s))||o.enumerable});return t};var at=(t,n,i)=>(i=t!=null?Qo(nr(t)):{},or(n||!t||!t.__esModule?Fn(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("./storage-entry-BszwT2ej.cjs"),e=require("react/jsx-runtime"),f=require("react"),rr=require("react-markdown"),sr=require("remark-gfm"),lr=require("react-dom"),ar=t=>`/book-index?id=${t}`,Wi=f.createContext(ar);function cr({buildUrl:t,children:n}){const i=f.useMemo(()=>t,[t]);return e.jsx(Wi.Provider,{value:i,children:n})}function me(){return f.useContext(Wi)}function Ue(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function dr(t,n){return Ue(t).includes(n)}const $i={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},pr={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},ur={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},St=f.createContext(null),Ai={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)",dynastyLabel:"朝代/年份 (Dynasty/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:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},xr={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)",dynastyLabel:"朝代/年份 (Dynasty/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:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},fr={"zh-Hant":Ai,"zh-Hans":xr},Mi="bim-locale";function gr(){try{const t=localStorage.getItem(Mi);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function mr(t){try{localStorage.setItem(Mi,t)}catch{}}const hr="zh-Hans",br=({locale:t,onLocaleChange:n,children:i})=>{const[o,s]=f.useState(t??hr),r=t??o;f.useEffect(()=>{if(t)return;const p=gr();p&&p!==o&&s(p)},[]);const[a,c]=f.useState(null);f.useEffect(()=>{r==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const x=p.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>p=>p)}):c(null)},[r]);const l=f.useCallback(p=>{s(p),mr(p),n==null||n(p)},[n]),d=f.useMemo(()=>({locale:r,setLocale:l,messages:fr[r],converter:a}),[r,l,a]);return e.jsx(St.Provider,{value:d,children:i})};function D(){const t=f.useContext(St);return(t==null?void 0:t.messages)??Ai}const yr=2e3;function H(){const t=f.useContext(St),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,o=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const r=f.useCallback(a=>{if(!a)return"";if(!i)return a;const c=o.current.get(a);if(c!==void 0)return c;const l=i(a);if(o.current.size>=yr){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(a,l),l},[i]);return f.useMemo(()=>({convert:r,locale:n,isSimplified:n==="zh-Hans"}),[r,n])}function kt(t,n){return t.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}function vr(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 o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function jr(){return{id:"",name:"",url:"",type:"text",details:""}}const nn=({items:t,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const r=D(),[a,c]=f.useState(null),l=[{value:"text",label:r.resourceTypeShort.text},{value:"image",label:r.resourceTypeShort.image},{value:"text+image",label:r.resourceTypeShort.textImage},{value:"physical",label:r.resourceTypeShort.physical}],d=[{value:"catalog",label:r.rootType.catalog},{value:"search",label:r.rootType.search}],p=y=>{if(!s)return!0;const k=Ue(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},x=t.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>p(y)),g=()=>{const y=jr();s&&(y.type=s),n([...t,y]),c(t.length)},u=y=>{n(t.filter((k,_)=>_!==y)),c(null)},h=(y,k,_)=>{const w=[...t];if(w[y]={...w[y],[k]:_},k==="url"&&!w[y].id){const T=vr(_);T&&(w[y].id=T)}n(w)},v=(y,k,_)=>{const T={...t[y].metadata||{}};_?T[k]=_:delete T[k],h(y,"metadata",Object.keys(T).length>0?T:void 0)},m=(y,k)=>{const _=k.trim()?k.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;h(y,"structure",_)},j=(y,k,_)=>{const T=t[y].coverage||{level:1,ranges:""};k==="level"?T.level=parseInt(_)||1:T.ranges=_,h(y,"coverage",T.ranges?T:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:y,originalIndex:k})=>{var _,w,T;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(a===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Sr(y.type??"text"),color:"#fff"},children:(()=>{var I,z;const S=Ue(y);return S.length===0?y.type??"text":S.length===1?((I=l.find(C=>C.value===S[0]))==null?void 0:I.label)??S[0]:S.includes("text")&&S.includes("image")?((z=l.find(C=>C.value==="text+image"))==null?void 0:z.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${r.editor.resourcePlaceholder} ${k+1}`}),y.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&kr(k,o==null?void 0:o[k],i,r),e.jsx("button",{onClick:S=>{S.stopPropagation(),u(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisResource,children:"✕"})]}),a===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[dr(y,"image")&&y.url&&wr(y,r),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ct,children:[e.jsx("span",{style:dt,children:r.label.type}),e.jsx("select",{value:y.type,onChange:S=>h(k,"type",S.target.value),style:{...Ie,flex:1},children:l.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:ct,children:[e.jsx("span",{style:dt,children:r.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:S=>h(k,"root_type",S.target.value),style:{...Ie,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:y.id,onChange:S=>h(k,"id",S.target.value),placeholder:r.editor.idAutoExtract,style:{...Ie,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:y.name,onChange:S=>h(k,"name",S.target.value),placeholder:r.editor.resourceName,style:{...Ie,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:S=>h(k,"url",S.target.value),placeholder:r.editor.resourceUrl,style:Ie}),e.jsx("input",{type:"text",value:((_=y.structure)==null?void 0:_.join("、"))||"",onChange:S=>m(k,S.target.value),placeholder:r.editor.structurePlaceholder,style:Ie}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ct,children:[e.jsx("span",{style:dt,children:r.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((w=y.coverage)==null?void 0:w.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...Ie,width:"60px"}})]}),e.jsxs("label",{style:{...ct,flex:1},children:[e.jsx("span",{style:dt,children:r.label.coverageRange}),e.jsx("input",{type:"text",value:((T=y.coverage)==null?void 0:T.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:r.editor.coverageRangePlaceholder,style:{...Ie,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:r.editor.detailsPlaceholder,style:{...Ie,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:r.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(r.metadata).map(([S,I])=>{var z;return e.jsxs("label",{style:{...ct,gap:"4px"},children:[e.jsx("span",{style:{...dt,minWidth:"56px"},children:I}),e.jsx("input",{type:"text",value:((z=y.metadata)==null?void 0:z[S])||"",onChange:C=>v(k,S,C.target.value),placeholder:I,style:{...Ie,flex:1}})]},S)})})]})]})]})]},k)}),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:r.action.addResource})]})]})};function Sr(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 kr(t,n,i,o){const s=(n==null?void 0:n.status)==="downloading",r=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||i(t,"")},disabled:s,style:{background:"transparent",border:"none",color:r?"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:r?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:r?"✓":s?"⏳":"⬇"})}function wr(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:o=>{o.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 Ie={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"},ct={display:"flex",alignItems:"center",gap:"6px"},dt={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},_r={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function yt(t){try{return _r[new URL(t).hostname]}catch{return}}const Pn={text:0,image:1,physical:2};function dn(t){return t.length===0?"physical":[...t].sort((n,i)=>(Pn[n]??99)-(Pn[i]??99)).join("+")}function pn(t){var a;const n=c=>{const l=c.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[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 l=t[c];if(l.volumes&&l.volumes.length>0)continue;const d=n(l.name);if(!d)continue;const[p,x]=d,g=`${p}|${dn(Ue(l))}`;i.has(g)||i.set(g,{base:{...l,name:p,url:"",volumes:[]},volumes:[],indices:[]});const u=i.get(g);u.volumes.push({volume:x,url:l.url||void 0,status:"found"}),u.indices.push(c)}const o=[],s=new Set;for(const c of i.values())if(!(c.volumes.length<2)){c.volumes.sort((l,d)=>l.volume-d.volume),c.base.volumes=c.volumes,c.base.expected_volumes=c.volumes.length,c.base.url||(c.base.url=((a=c.volumes.find(l=>l.url))==null?void 0:a.url)??""),o.push(c.base);for(const l of c.indices)s.add(l)}const r=[...o];for(let c=0;c<t.length;c++)s.has(c)||r.push(t[c]);return r}function Fi(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 Pi(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Fi(n)}))}function un(t){const n=Pi(t);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:o,expected:t.expected_volumes??i+o}}function xn(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 fn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const o=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function At(t){if(!t.url)return;const n=xn(t.metadata);return n?fn(t.url,n):t.url}const Hn={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 Cr(t){return t.includes("text")&&t.includes("image")?Hn["text+image"]:Hn[t[0]||"physical"]}const gn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const r=D(),{convert:a}=H(),c=f.useMemo(()=>pn(t||[]),[t]),{mirrorGroups:l,ungroupedItems:d}=f.useMemo(()=>{const m=new Map,j=[];for(const y of c){const k=y.group;k?(m.has(k)||m.set(k,[]),m.get(k).push(y)):j.push(y)}for(const y of m.values())y.sort((k,_)=>{const w=T=>T.group_role==="origin"?0:T.group_role==="mirror"?1:2;return w(k)-w(_)});return{mirrorGroups:m,ungroupedItems:j}},[c]),p={text:r.resourceType.text,image:r.resourceType.image,"text+image":r.resourceType.textImage,physical:r.resourceType.physical},x=m=>p[m]?p[m]:m.split("+").map(j=>p[j]||j).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:r.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((m,j)=>e.jsx(Jt,{item:m},m.id||j))});const g=(m,j)=>{const y=i==null?void 0:i[m],k=(y==null?void 0:y.label)||m,_=y==null?void 0:y.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:a(k)}),_&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:a(_)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((w,T)=>e.jsx(Jt,{item:w,onNavigate:o,renderLink:s},w.id||T))})]},`group-${m}`)},u=new Map;for(const m of d){const j=dn(Ue(m));u.has(j)||u.set(j,[]),u.get(j).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:[[...l.entries()].map(([m,j])=>g(m,j)),v.map(m=>{const j=u.get(m),y=Cr(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:y,whiteSpace:"nowrap",flexShrink:0},children:x(m)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>e.jsx(Jt,{item:k,onNavigate:o,renderLink:s},k.id||_))})]},m)})]})},Ir={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)"}},Jt=({item:t})=>{const n=D(),{convert:i}=H(),[o,s]=f.useState(!1),r=f.useMemo(()=>(t.url?yt(t.url):void 0)||i(t.name),[t.url,t.name,i]),a=f.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||Fi(h)})),[t.volumes]),c=a&&a.length>0,l=c?new Set(a.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(a.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,p=t.expected_volumes??(c?l+d:0),x=t.color_mode?{...Ir[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:r}),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:[l,"/",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=xn(t.metadata);return h?fn(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(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),c&&o&&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:a.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)})})]})},Hi=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:r,onSelectFolder:a})=>{const c=D(),l=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"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:o,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:a,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:o,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:r,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:o,title:l?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:a,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})]}),!l&&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})]})]})},Ht="bim-search-history",On=10,Dn=8;function gt(){try{const t=localStorage.getItem(Ht);return t?JSON.parse(t):[]}catch{return[]}}function Tr(t){try{const n=gt().filter(i=>i!==t);n.unshift(t),n.length>On&&(n.length=On),localStorage.setItem(Ht,JSON.stringify(n))}catch{}}function zr(t){try{const n=gt().filter(i=>i!==t);localStorage.setItem(Ht,JSON.stringify(n))}catch{}}function Rr(){try{localStorage.removeItem(Ht)}catch{}}const Oi=({transport:t,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:r})=>{const a=D(),c=r??a.search.placeholder,l={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,p]=f.useState(!1),[x,g]=f.useState([]),[u,h]=f.useState(-1),[v,m]=f.useState(gt),j=f.useRef(null),y=f.useRef(null),k=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{h(-1);const b=n.trim();if(!b){g(v.map(A=>({type:"history",text:A})));return}if(!t.searchAll){g([]);return}let R=!1;const E=setTimeout(()=>{t.searchAll(b,Dn).then(A=>{if(R)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];g(M.slice(0,Dn).map(P=>({type:"entry",text:P.title||P.id,entry:P})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,v,t]),f.useEffect(()=>{const b=R=>{k.current&&!k.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]),f.useEffect(()=>{const b=R=>{var E,A;if(R.key==="/"&&document.activeElement!==j.current){const M=(E=document.activeElement)==null?void 0:E.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;R.preventDefault(),(A=j.current)==null||A.focus()}};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[]);const w=f.useCallback(b=>{b.trim()&&(Tr(b.trim()),m(gt())),o(b),p(!1)},[o]),T=f.useCallback(b=>{b.type==="history"?(i(b.text),w(b.text)):b.entry&&(s?(s(b.entry),p(!1)):(i(b.text),w(b.text)))},[i,w,s]),S=f.useCallback(b=>{if(!d||x.length===0){b.key==="Enter"&&w(n);return}switch(b.key){case"ArrowDown":b.preventDefault(),h(R=>(R+1)%x.length);break;case"ArrowUp":b.preventDefault(),h(R=>(R-1+x.length)%x.length);break;case"Enter":b.preventDefault(),u>=0&&u<x.length?T(x[u]):w(n);break;case"Escape":b.preventDefault(),p(!1);break}},[d,x,u,n,w,T]),I=f.useCallback((b,R)=>{R.stopPropagation(),zr(b),m(gt()),g(E=>E.filter(A=>!(A.type==="history"&&A.text===b)))},[]),z=f.useCallback(b=>{b.stopPropagation(),Rr(),m([]),g([])},[]);f.useEffect(()=>{if(u>=0&&y.current){const b=y.current.children;b[u]&&b[u].scrollIntoView({block:"nearest"})}},[u]);const C=!n.trim()&&v.length>0;return e.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:b=>{i(b.target.value),p(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{p(!0)},onKeyDown:S,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:y,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:[C&&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:a.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:a.search.clearAll})]}),x.map((b,R)=>e.jsxs("div",{onClick:()=>T(b),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:b.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.text}),b.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[l[b.entry.type],b.entry.edition&&` · ${b.entry.edition}`,b.entry.author&&` · ${b.entry.author}`]}),b.type==="history"&&e.jsx("button",{onClick:E=>I(b.text,E),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${b.type}-${b.text}-${R}`))]})]})},vt="bim-recent-ids",Nn="bim-recent-entries",Vn=50,qt=5,Er=50,Br=200;function mt(){try{const t=localStorage.getItem(vt);if(t)return JSON.parse(t);const n=localStorage.getItem(Nn);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(vt,JSON.stringify(i)),localStorage.removeItem(Nn),i}return[]}catch{return[]}}function Lr(t){try{const n=mt().filter(i=>i!==t);n.unshift(t),n.length>Vn&&(n.length=Vn),localStorage.setItem(vt,JSON.stringify(n))}catch{}}function Wr(t){try{const n=mt().filter(i=>i!==t);localStorage.setItem(vt,JSON.stringify(n))}catch{}}function $r(){try{localStorage.removeItem(vt)}catch{}}const Ar={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},on=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:r,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l,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"}],[j,y]=f.useState(g??""),[k,_]=f.useState(null),[w,T]=f.useState(null),[S,I]=f.useState(!1),[z,C]=f.useState(null),[b,R]=f.useState(""),[E,A]=f.useState(!g),[M,P]=f.useState(mt),[$,F]=f.useState([]),[Q,W]=f.useState(!1),[U,ne]=f.useState(!1),[B,V]=f.useState(null),[Y,ie]=f.useState(null),G=f.useRef(void 0),K=f.useRef(!1),de=f.useCallback(async(N,oe)=>{if(!N.trim()){A(!0),_(null),T(null);return}A(!1),I(!0),R("");try{if(t.searchAll){const te=await t.searchAll(N,oe??qt);_(te)}else{const te=["work","book","collection","entity"],L=await Promise.all(te.map(Z=>t.search(N,Z,{page:1,pageSize:oe??qt})));_({works:L[0].entries,books:L[1].entries,collections:L[2].entries,entities:L[3].entries,totalWorks:L[0].total,totalBooks:L[1].total,totalCollections:L[2].total,totalEntities:L[3].total})}}catch(te){R(te instanceof Error?te.message:String(te)),_(null)}finally{I(!1)}},[t]);f.useEffect(()=>{let N=!1;const oe=()=>{var J,Ae;const te=["work","book","collection","entity"],L=Promise.all(te.map(ve=>t.loadEntries(ve,{page:1,pageSize:1}).catch(()=>({total:0})))),Z=((J=t.getResourceCounts)==null?void 0:J.call(t).catch(()=>null))??Promise.resolve(null),se=((Ae=t.getSubtypeStats)==null?void 0:Ae.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([L,Z,se]).then(([ve,fe,Xe])=>{N||(V({works:ve[0].total,books:ve[1].total,collections:ve[2].total,entities:ve[3].total,hasText:fe==null?void 0:fe.hasText,hasImage:fe==null?void 0:fe.hasImage}),Xe&&ie(Xe))})};return t.getCounts?t.getCounts().then(te=>{var L,Z;N||(V({works:te.works,books:te.books,collections:te.collections,entities:te.entities,hasText:(L=te.resourceCounts)==null?void 0:L.hasText,hasImage:(Z=te.resourceCounts)==null?void 0:Z.hasImage}),te.subtypeStats&&ie(te.subtypeStats))}).catch(()=>{N||oe()}):oe(),()=>{N=!0}},[t]),f.useEffect(()=>{K.current||!(g!=null&&g.trim())||(K.current=!0,de(g))},[g,de]);const Re=f.useCallback(N=>{if(y(N),!N.trim()){u==null||u(N),A(!0),_(null),T(null);return}G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{T(null),u==null||u(N),de(N)},Br)},[de,u]),le=f.useCallback(N=>{G.current&&clearTimeout(G.current),u==null||u(N),de(N)},[de,u]),xe=f.useCallback(N=>{T(N),de(j,Er)},[j,de]);f.useEffect(()=>{if(!M.length){F([]);return}let N=!1;return W(!0),Promise.all(M.slice(0,10).map(async oe=>{var te,L,Z;try{if(t.getEntry){const J=await t.getEntry(oe);if(J)return J}const se=await t.getItem(oe);if(se){const J=se.authors;return{id:oe,title:se.title||oe,type:se.type||"work",author:(te=J==null?void 0:J[0])==null?void 0:te.name,dynasty:(L=J==null?void 0:J[0])==null?void 0:L.dynasty,role:(Z=J==null?void 0:J[0])==null?void 0:Z.role,edition:se.edition||void 0}}}catch{}return{id:oe,title:oe,type:"work",notFound:!0}})).then(oe=>{N||(F(oe),W(!1))}),()=>{N=!0}},[M,t]);const he=N=>{C(N.id),Lr(N.id),P(mt()),o==null||o(N)},Oe=N=>{Wr(N),P(mt())},_e=()=>{$r(),P([])},qe=N=>m.find(oe=>oe.type===N),lt=k&&(k.works.length>0||k.books.length>0||k.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(Hi,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:r,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Oi,{transport:t,value:j,onChange:Re,onSearch:le,onEntrySelect:he}),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})]}),B&&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:Y?e.jsxs(e.Fragment,{children:[(Y.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.books.toLocaleString()})," 本"]}),Y.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.article.toLocaleString()})," 篇"]}):null,Y.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[v.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.collections.toLocaleString()}),B.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:B.entities.toLocaleString()})]})]})}),B.hasImage!=null&&B.hasText!=null&&e.jsxs("span",{children:[v.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:S?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:v.search.searching}):b?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:b})]}):E?e.jsx("div",{style:{flex:1},children:Q?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:v.search.loading}):$.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:_e,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:$.slice(0,U?10:3).map(N=>N.notFound?e.jsx(Fr,{id:N.id,onRemove:Oe,t:v},N.id):e.jsx(Gn,{entry:N,selected:z===N.id,onClick:he,getConfig:qe,onRemove:Oe},N.id))}),!U&&$.length>3&&e.jsx("button",{onClick:()=>ne(!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})]})}):lt?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:N,icon:oe,name:te,key:L})=>{const Z=k[L]??[],se=Ar[L],J=k[se]??0;if(Z.length===0)return null;const ve=!(w===N)&&J>qt;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," ",te,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",v.unit.items]})]}),ve&&e.jsx("button",{onClick:()=>xe(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:Z.map(fe=>{if(x)return e.jsx(f.Fragment,{children:x(fe)},fe.id);const Xe=p==="card"?Mr:Gn;return e.jsx(Xe,{entry:fe,selected:z===fe.id,onClick:he,getConfig:qe,query:j},fe.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:kt(v.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v.search.tryOther})]})})]})},Mr=({entry:t,selected:n,onClick:i,getConfig:o,query:s})=>{const r=D(),{convert:a}=H(),c=a(t.title||t.primary_name||t.id),l=t.measure_info?a(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${r.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}),l&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),t.edition&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a(t.edition)}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[r.search.alias,":",a(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:[o(t.type).icon," ",o(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:["📝 ",r.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:["🖼️ ",r.misc.imageResource]})]})]})]})},Gn=({entry:t,selected:n,onClick:i,getConfig:o,query:s,onRemove:r})=>{const a=D(),{convert:c}=H(),l=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&l.length?l.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:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(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:a.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:a.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children: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,a.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:[a.search.alias,":",c(d)]})]}),r?e.jsx("button",{onClick:p=>{p.stopPropagation(),r(t.id)},title:a.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:"→"})]})},Fr=({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 Pr(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 Hr({data:t}){const{convert:n}=H(),{dynasty:i,birth_year:o,death_year:s}=t,r=[];return i&&r.push(`〔${n(i)}〕`),o!==void 0&&s!==void 0?r.push(`${o}—${s}`):o!==void 0?r.push(`${o}—?`):s!==void 0&&r.push(`?—${s}`),r.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:r.join(" ")})}function Or({alt_names:t}){const{convert:n}=H(),i=new Map;for(const r of t){const a=r.type||"別名";i.has(a)||i.set(a,[]),i.get(a).push(r.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((r,a)=>{const c=o.indexOf(r),l=o.indexOf(a);return c===-1&&l===-1?0:c===-1?1:l===-1?-1:c-l});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(r=>{const a=i.get(r);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:r}),e.jsx("span",{children:a.map((c,l)=>e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},l))})]},r)})})}function Dr({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 Nr({works:t,transport:n,onNavigate:i,renderLink:o}){const s=D(),{convert:r}=H(),a=me(),[c,l]=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 k=await n.getEntriesByIds(u);let _=!0;for(let w=0;w<u.length;w++){const T=k[w];T!=null&&T.title?v.set(u[w],T.title):T!=null&&T.primary_name?v.set(u[w],T.primary_name):_=!1}if(_)return v}catch{}const m=[...u],j=8,y=new Array(j).fill(0).map(async()=>{for(;m.length;){const k=m.shift();if(!k)break;if(!v.has(k))try{if(n.getEntry){const T=await n.getEntry(k);if(T!=null&&T.title){v.set(k,T.title);continue}}const _=await n.getItem(k),w=_&&(_.title||_.primary_name)||k;v.set(k,w)}catch{v.set(k,k)}}});return await Promise.all(y),v})().then(v=>{g||l(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:[r(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=r(c.get(h.work_id)||h.work_id);return o?e.jsx("li",{children:o(h.work_id,m)},v):i?e.jsx("li",{children:e.jsx("a",{href:a(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.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 Di=({data:t,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:r})=>{var x;const a=D(),{convert:c}=H();let l=!1;try{l=X.extractStatus(t.id)==="draft"}catch{}const d=Pr(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!r&&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(Hr,{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:a.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),l&&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:a.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(Or,{alt_names:t.alt_names}),e.jsx(Dr,{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(Nr,{works:t.works,transport:n,onNavigate:i,renderLink:o})]})},Ni={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})},Vr={...Ni,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},We=({text:t,plainStrong:n,style:i,className:o})=>{const{convert:s}=H(),r=n?Vr:Ni;return e.jsx("div",{className:o,style:i,children:e.jsx(rr,{remarkPlugins:[sr],components:r,children:s(t)})})},Gr=["〇","一","二","三","四","五","六","七","八","九"],Un=["","十","百","千"];function Vi(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",s=!1;for(let r=0;r<i;r++){const a=parseInt(n[r]),c=i-1-r;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&c===1&&r===0?o+=Un[c]:o+=Gr[a]+Un[c])}return o}function Gi(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 Ur={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 Yr({type:t}){const n=D();return e.jsx("span",{style:Gi(Ur[t]),children:n.indexType[t]})}function Kr({isDraft:t}){const n=D(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Gi(i),children:t?n.status.draft:n.status.official})}function Jr({id:t}){const n=D(),[i,o]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!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:r=>r.currentTarget.style.opacity="1",onMouseLeave:r=>r.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function be({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 Te({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 Ui({authors:t,type:n,onNavigate:i,renderLink:o}){const{convert:s}=H();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,a)=>{const c=s(r.name),l=r.entity_id?e.jsx(Se,{id:r.entity_id,label:c,onNavigate:i,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(r.dynasty),"〕"]}),l,r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(r.role)]})]},a)})})}function Se({id:t,label:n,onNavigate:i,renderLink:o}){const s=me();return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:s(t),onClick:r=>{r.metaKey||r.ctrlKey||(r.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:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function qr({id:t,title:n,edition:i,type:o,isDraft:s,authors:r,volumeText:a,meta:c,headerExtra:l,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}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),l&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:l})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Yr,{type:o}),e.jsx(Kr,{isDraft:s}),e.jsx(Jr,{id:t})]}),((r==null?void 0:r.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[r&&r.length>0&&e.jsx(Ui,{authors:r,type:o,onNavigate:d,renderLink:p}),c]})]})}function Yi({items:t,label:n,showMeta:i,onNavigate:o,renderLink:s}){const r=D(),{convert:a}=H();if(!t.length)return null;const[c,l]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(be,{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:()=>l(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:a(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:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(Se,{id:d.source_bid,label:r.action.view,onNavigate:o,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(Te,{label:r.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(Te,{label:r.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(Te,{label:r.label.edition,children:a(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:r.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(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:r.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(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:r.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},p)})})]})}function Xr({items:t,onNavigate:n,renderLink:i}){const o=D();return e.jsx(Yi,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Ki({items:t,onNavigate:n,renderLink:i}){const o=D();return e.jsx(Yi,{items:t,label:o.section.emendated,onNavigate:n,renderLink:i})}function Ji({label:t,items:n}){const{convert:i}=H();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const r=typeof o=="string"?o:o.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(r)},s)})})]}):null}function Zr({items:t}){const n=D();return e.jsx(Ji,{label:n.section.aliases,items:t})}function Qr({items:t}){const n=D();return e.jsx(Ji,{label:n.section.attachedTexts,items:t})}function es({items:t}){const n=D(),{convert:i}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,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(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function ts({items:t}){const n=D(),{convert:i}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{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((o,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(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(o.description)})]},s))]})]}):null}function ns({items:t}){const n=D(),{convert:i}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,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(o)]},s))})]}):null}function Yn({title:t,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:r}=H(),[a,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let l=!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=>{l||c(d)}),()=>{l=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(be,{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:(a.length?a:n.map(l=>({id:l}))).map(l=>{const d=l.edition?`${r(l.title)||l.id}(${r(l.edition)})`:r(l.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(Se,{id:l.id,label:d,onNavigate:o,renderLink:s})},l.id)})})]}):null}function Xt({book:t,onNavigate:n,renderLink:i}){const o=D(),{convert:s}=H(),[r,a]=f.useState(!1),c=t.resources&&t.resources.length>0,l=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&&!r?"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(Se,{id:t.id,label:l,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:r?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:r?o.action.expand:o.action.collapse,children:"▼"})]}),c&&!r&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(gn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function is({ids:t,workData:n,transport:i,onNavigate:o,renderLink:s,footer:r}){const a=D(),{convert:c}=H(),[l,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=l.length?l:t.map(h=>({id:h})),x=new Map(p.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,u=os(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),r,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(Xt,{book:v,onNavigate:o,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(Xt,{book:m,onNavigate:o,renderLink:s},v):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(h=>e.jsx(Xt,{book:h,onNavigate:o,renderLink:s},h.id))})]})}function os(t,n){var m,j;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],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],r=o.length>0||s.length>0,a=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),l=new Set([...s,...a]),d=y=>{if(l.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],x=new Map,g=[];for(const y of t)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))p.push(y);else{const k=n.node_groups[y];k?(x.has(k)||x.set(k,[]),x.get(k).push(y)):g.push(y)}if(g.length+[...x.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),v=[...x.entries()].map(([y,k])=>{const _=h.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:v}}function rs({workData:t,onNavigate:n,renderLink:i}){var a,c,l,d;const o=D(),{convert:s}=H(),r=!!((a=t.description)!=null&&a.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:r?"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(Se,{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:[Vi(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Ui,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),r&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((l=t.description)==null?void 0:l.text)&&e.jsx(We,{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(Te,{label:o.label.parentWork,children:e.jsx(Se,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function ss({items:t,onNavigate:n,renderLink:i}){const o=D(),{convert:s}=H();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(r=>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:o.indexType.collection}),e.jsx(Se,{id:r.id,label:s(r.title)||r.id,onNavigate:n,renderLink:i}),r.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:kt(o.catalog.volume,{n:r.volume_index})})]},r.id))}):null}const mn=({data:t,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:r,relatedBooksFooter:a,className:c,style:l})=>{var R,E,A,M,P,$,F,Q;const d=D(),{convert:p}=H(),[x,g]=f.useState(null),[u,h]=f.useState(!1),[v,m]=f.useState(null),[j,y]=f.useState(null),[k,_]=f.useState([]),w=t||x;if(f.useEffect(()=>{if(t||!n||!i)return;let W=!1;return h(!0),m(null),i.getItem(n).then(U=>{W||(U?g(U):m(d.misc.notFoundEntry))}).catch(U=>{W||m(U instanceof Error?U.message:d.misc.loadFailed)}).finally(()=>{W||h(!1)}),()=>{W=!0}},[t,n,i]),f.useEffect(()=>{if(!w||!i){y(null),_([]);return}let W=!1;const U=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(U?i.getItem(U).then(ne=>{!W&&ne&&ne.type==="work"&&y(ne)}).catch(()=>{}):y(null),w.type==="book"){const ne=w;ne.contained_in&&ne.contained_in.length>0?Promise.all(ne.contained_in.map(B=>{const V=typeof B=="string"?B:B.id,Y=typeof B=="string"?void 0:B.volume_index;return i.getItem(V).then(ie=>({id:V,title:ie&&ie.title||V,volume_index:Y})).catch(()=>({id:V,title:V,volume_index:Y}))})).then(B=>{W||_(B)}):_([])}else _([]);return()=>{W=!0}},[w,i]),u)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,U)=>e.jsx("div",{style:{height:U===1?"32px":"16px",width:`${W}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},U))})});if(v)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!w)return null;if(w.type==="entity")return e.jsx("div",{className:c,style:l,children:e.jsx(Di,{data:w,transport:i,onNavigate:o,renderLink:s,headerExtra:r})});const T=w.type==="book"?w:null,S=w.type==="collection"?w:null,I=w.type==="work"?w:null;let z=!1;try{z=X.extractStatus(w.id)==="draft"}catch{}let C="";w.measure_info?C=p(w.measure_info):(R=w.juan_count)!=null&&R.number?C=Vi(w.juan_count.number)+d.unit.juan:(E=w.juan_count)!=null&&E.description&&(C=p(w.juan_count.description));const b=[];return(A=w.publication_info)!=null&&A.year&&b.push(e.jsx(Te,{label:d.label.year,children:w.publication_info.year},"year")),(M=w.current_location)!=null&&M.name&&b.push(e.jsx(Te,{label:d.label.currentLocation,children:p(w.current_location.name)},"loc")),(P=w.page_count)!=null&&P.description&&b.push(e.jsx(Te,{label:d.label.pageCount,children:w.page_count.description},"page")),T!=null&&T.edition&&b.push(e.jsx(Te,{label:d.label.edition,children:p(T.edition)},"ver")),I!=null&&I.parent_work&&b.push(e.jsx(Te,{label:d.label.parentWork,children:e.jsx(Se,{id:I.parent_work.id,label:p(I.parent_work.title),onNavigate:o,renderLink:s})},"pw")),I!=null&&I.parent_works&&I.parent_works.length>0&&!I.parent_work&&b.push(e.jsx(Te,{label:d.label.parentWork,children:I.parent_works.map((W,U)=>e.jsxs("span",{children:[U>0&&"、",e.jsx(Se,{id:W,onNavigate:o,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(qr,{id:w.id,title:p(w.title),edition:w.edition?p(w.edition):void 0,type:w.type,isDraft:z,authors:w.authors,volumeText:C,meta:b,headerExtra:r,onNavigate:o,renderLink:s}),(($=w.description)==null?void 0:$.text)&&e.jsx(We,{text:w.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),w.appendix&&w.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:w.appendix.map((W,U)=>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(We,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},U))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.containedIn}),e.jsx(ss,{items:k,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.belongsToWork}),e.jsx(rs,{workData:j,onNavigate:o,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(es,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(Zr,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(Qr,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(Xr,{items:w.indexed_by,onNavigate:o,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(Ki,{items:w.emendated_by,onNavigate:o,renderLink:s}),w.resources&&w.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.resources}),e.jsx(gn,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(T==null?void 0:T.location_history)&&T.location_history.length>0&&e.jsx(ts,{items:T.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(ns,{items:S.history}),(T==null?void 0:T.related_books)&&T.related_books.length>0&&e.jsx(Yn,{title:d.section.relatedVersions,ids:T.related_books,transport:i,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Yn,{title:d.section.containedBooks,ids:S.books,transport:i,onNavigate:o,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(be,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.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(Se,{id:W.id,label:p(W.title),onNavigate:o,renderLink:s})},W.id))})]}),(((F=I==null?void 0:I.books)==null?void 0:F.length)||0)+(((Q=I==null?void 0:I.collections)==null?void 0:Q.length)||0)>0&&e.jsx(is,{ids:[...(I==null?void 0:I.books)||[],...(I==null?void 0:I.collections)||[]],workData:I,transport:i,onNavigate:o,renderLink:s,footer:a}),(I==null?void 0:I.related_works)&&I.related_works.length>0&&(()=>{const W=[],U=I.related_works.filter(G=>G.relation==="part_of"),ne=I.related_works.filter(G=>G.relation==="has_part"),B=I.related_works.filter(G=>G.relation==="has_adaptation"),V=I.related_works.filter(G=>G.relation==="text_carried_by"),Y=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ie=I.related_works.filter(G=>!G.relation||!Y.has(G.relation));return U.length>0&&W.push({label:d.section.belongsToWork,items:U}),ne.length>0&&W.push({label:d.section.containedWorks,items:ne}),B.length>0&&W.push({label:d.section.adaptations,items:B}),V.length>0&&W.push({label:d.section.derivativeWorks,items:V}),ie.length>0&&W.push({label:d.section.relatedWorks,items:ie}),W.map(G=>e.jsxs("div",{children:[e.jsxs(be,{children:[G.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",G.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:G.items.map(K=>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(Se,{id:K.id,label:p(K.title),onNavigate:o,renderLink:s})},K.id))})]},G.label))})()]})};function ls({data:t}){const n=D(),{convert:i}=H(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,r=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]}),r!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",r,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:o.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 as({sections:t,activeSection:n,onSelect:i}){const o=D();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:Kn(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:Kn(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 Kn(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 cs({id:t,label:n,onNavigate:i,renderLink:o}){const s=me();return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:s(t),onClick:r=>{r.metaKey||r.ctrlKey||(r.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:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function ds(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],o=t[t.length-1];return o-i+1===t.length?`${i}–${o}`:t.length<=3?t.join(", "):`${i}–${o} (${t.length}${n})`}function Jn({book:t,onNavigate:n,renderLink:i,showVolumes:o}){const s=D(),{convert:r}=H(),a=t.book_id||t.work_id,c=o&&t.volumes.length>0?ds(t.volumes,s.unit.volume):null,l=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:[o&&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:[r(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=>r(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:r(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:l?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(cs,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const hn=({data:t,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:r,style:a})=>{const c=D(),[l,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[h,v]=f.useState(null),[m,j]=f.useState(""),y=t||l;f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let S=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(I=>{S||(I?d(I):u(c.catalog.notFound))}).catch(I=>{S||u(I instanceof Error?I.message:c.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,i,c]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,_=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const S=y.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(S).size<S.length},[y]),w=f.useMemo(()=>{if(!y)return[];let S=y.books;if(h&&(S=S.filter(I=>I.section===h)),m.trim()){const I=m.trim().toLowerCase();S=S.filter(z=>z.title.toLowerCase().includes(I)||z.sub_items&&z.sub_items.some(C=>C.toLowerCase().includes(I))||z.edition&&z.edition.toLowerCase().includes(I))}return S},[y,h,m]),T=f.useMemo(()=>{if(!_)return null;const S=[],I=new Map;for(const C of w){if(!C.volumes||C.volumes.length===0)continue;const b=C.volumes[0];I.has(b)||I.set(b,[]),I.get(b).push(C)}const z=[...I.keys()].sort((C,b)=>C-b);for(const C of z)S.push({volume:C,books:I.get(C)});return S},[w,_]);return p?e.jsx("div",{className:r,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:r,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):y?e.jsxs("div",{className:r,style:a,children:[e.jsx(ls,{data:y}),k&&e.jsx(as,{sections:y.sections,activeSection:h,onSelect:v}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:m,onChange:S=>j(S.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:[w.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[T?T.map((S,I)=>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:kt(c.catalog.volume,{n:S.volume})}),S.books.map((z,C)=>e.jsx(Jn,{book:z,onNavigate:o,renderLink:s,showVolumes:z.volumes.length>1},`${S.volume}-${C}`))]},`${S.volume}-${I}`)):w.map((S,I)=>e.jsx(Jn,{book:S,onNavigate:o,renderLink:s,showVolumes:!0},I)),w.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Je=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(o=>o>=3?1:o+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)})},ue=6,Tt=7,ps=({content:t,children:n,placement:i="top",delayMs:o=100,maxWidth:s=280,wrapperStyle:r})=>{const[a,c]=f.useState(!1),[l,d]=f.useState(null),p=f.useRef(null),x=f.useRef(null),g=f.useRef(null),u=f.useCallback(()=>{const m=x.current,j=g.current;if(!m||!j)return;const y=m.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,w=document.documentElement.clientWidth;let T=i;i==="top"&&y.top-k.height-Tt<8&&(T="bottom"),i==="bottom"&&y.bottom+k.height+Tt>_-8&&(T="top");const S=T==="top"?y.top-k.height-Tt:y.bottom+Tt;let I=y.left+y.width/2-k.width/2;I=Math.max(8,Math.min(I,w-k.width-8)),d({left:I,top:S,placement:T})},[i]),h=f.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),o)},[o]),v=f.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!a)return;const m=requestAnimationFrame(u);return()=>cancelAnimationFrame(m)},[a,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",...r},children:n}),a&&lr.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(l==null?void 0:l.left)??-9999,top:(l==null?void 0:l.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:l?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-ue,width:0,height:0,...l.placement==="top"?{bottom:-ue,borderTop:`${ue}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ue}px solid transparent`,borderRight:`${ue}px solid transparent`}:{top:-ue,borderBottom:`${ue}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ue}px solid transparent`,borderRight:`${ue}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...l.placement==="top"?{bottom:-5,borderTop:`${ue-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ue-1}px solid transparent`,borderRight:`${ue-1}px solid transparent`}:{top:-5,borderBottom:`${ue-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ue-1}px solid transparent`,borderRight:`${ue-1}px solid transparent`}}})]})]}),document.body)]})},qn={A:"fine",B:"rough",C:"rough",D:"ocr"};function us(t){return typeof t!="string"?null:t in $i?t:t in qn?qn[t]:null}const xs={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},fs={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ye(t){return typeof t!="string"?"":xs[t]??fs[t]??t}const gs=["〇","一","二","三","四","五","六","七","八","九"],Xn=["","十","百","千"],ms=["","萬","億"];function qi(t){if(t===0)return"〇";if(t<0)return`負${qi(-t)}`;const n=[];let i=t,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(hs(s,o>0)+ms[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function hs(t,n){const i=[];let o=t;for(;o>0;)i.unshift(o%10),o=Math.floor(o/10);let s="";for(let r=0;r<i.length;r++){const a=i[r],c=i.length-1-r;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&c===1&&r===0&&!n?s+=Xn[c]:s+=gs[a]+Xn[c]}return s.replace(/〇$/,"")}let ht=null,zt=null;const Mt=new Set;function bs(){return ht?Promise.resolve():zt||(zt=import("opencc-js/t2cn").then(t=>{ht=t.Converter({from:"tw",to:"cn"}),Mt.forEach(n=>n())}).catch(()=>{ht=t=>t,Mt.forEach(t=>t())}),zt)}function $e(){const[,t]=f.useState(0);return f.useEffect(()=>{if(ht)return;const n=()=>t(i=>i+1);return Mt.add(n),bs(),()=>{Mt.delete(n)}},[]),ht??(n=>n)}function et(t,n){return n(t).toLowerCase()}const bn="var(--bim-highlight-bg, #fff59d)";function st(t,n,i){if(!n)return t;const o=et(n,i);if(!o)return t;const s=et(t,i);if(s.length!==t.length)return t;const r=[];let a=0,c=0;for(;a<t.length;){const l=s.indexOf(o,a);if(l===-1){r.push(t.slice(a));break}l>a&&r.push(t.slice(a,l)),r.push(e.jsx("mark",{style:{background:bn,padding:0,color:"inherit"},children:t.slice(l,l+o.length)},c++)),a=l+o.length}return e.jsx(e.Fragment,{children:r})}function yn(t,n,i,o){if(!n)return!0;const s=et(n,o);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(a=>typeof a=="string"&&et(a,o).includes(s))}function ys(t,n,i){return n?et(t,i).includes(et(n,i)):!0}const vn={类:"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)"},vs={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function js(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Xi({file:t,isActive:n,onSelect:i,meta:o,matchState:s}){const r=s===0,a=s==="loading",c=typeof s=="number"&&s>0,l=js(t),d=!!(o!=null&&o.vol_label)&&!l.includes(o.vol_label);return e.jsxs("button",{onClick:()=>{r||i(t)},disabled:r,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":r?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":c?`${bn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":r?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:r?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:r?.5:1},children:[l,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",o.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Zi(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(o=>Zi(o,n)))}function Qi(t){var o;const n=t.files.length,i=((o=t.children)==null?void 0:o.reduce((s,r)=>s+Qi(r),0))||0;return n+i}function Ss(t,n){const i=[],o=a=>{var c;i.push(...a.files),(c=a.children)==null||c.forEach(o)};if(o(t),i.length===0)return;const s=i.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let r=0;for(const a of s)typeof a=="number"&&(r+=a);return r}function eo({group:t,activeFile:n,onSelect:i,depth:o=0,juanMeta:s,matchStates:r}){var h;const a=Zi(t,n||""),c=Ss(t,r),l=typeof c=="number"&&c>0,d=c===0,[p,x]=f.useState(a||l),g=Qi(t),u=!!((h=t.children)!=null&&h.length);if(f.useEffect(()=>{a&&x(!0)},[a]),f.useEffect(()=>{l&&x(!0)},[l]),t.files.length===1&&!u){const v=t.files[0],m=n===v,j=r[v],y=j===0,k=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{y||i(v)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+o*16}px`,border:m?"1px solid var(--bim-primary, #8e6f3e)":y?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:m?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${bn}40`:"transparent",color:m?"var(--bim-primary, #8e6f3e)":y?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:y?"not-allowed":"pointer",fontSize:"12px",fontWeight:m?600:400,lineHeight:1.4,opacity:y?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:j}),k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!p),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:a?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:p?"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:["(",g,")"]}),l&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),p&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+o*16}px`},children:t.files.map(v=>e.jsx(Xi,{file:v,isActive:n===v,onSelect:i,meta:s==null?void 0:s[v],matchState:r[v]},v))}),u&&t.children.map((v,m)=>e.jsx(eo,{group:v,activeFile:n,onSelect:i,depth:o+1,juanMeta:s,matchStates:r},m))]})]})}function ks({files:t,groups:n,activeFile:i,onSelect:o,juanMeta:s,matchStates:r}){const a=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,l)=>e.jsx(eo,{group:c,activeFile:i,onSelect:o,juanMeta:s,matchStates:r},l))}):a.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:a.map(c=>e.jsx(Xi,{file:c,isActive:i===c,onSelect:o,meta:s==null?void 0:s[c],matchState:r[c]},c))})}function ws({type:t}){const n=vn[t]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function _s({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=H(),s=me(),r=$e(),a=v=>{if(!v)return"";const m=o(v);return i?st(m,i,r):m},[c,l]=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&&l(!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&&l(!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:["《",a(t.book_title),"》"]}):a(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[qi(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:a(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:a(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:a(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:a(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:a(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:a(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:a(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:a(t.content)})]})]})}function Cs({section:t,highlightQuery:n=""}){const{convert:i}=H(),o=$e(),s=l=>{if(!l)return"";const d=i(l);return n?st(d,n,o):d},[r,a]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&a(!r),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ws,{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:r?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),r&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${vn[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)})})]})}function Is({section:t,highlightQuery:n=""}){const{convert:i}=H(),o=$e();if(ye(t.type)==="page_header"||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`)),r=n?st(s,n,o):s,a=ye(t.type),c=vn[a]||"var(--bim-desc-fg, #717171)",l=a==="序"||a==="结语"||a==="注释";return e.jsxs("div",{style:{padding:l?"10px 12px":"6px 0",margin:l?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:l?`3px solid ${c}40`:void 0,background:l?"var(--bim-bg, #fafafa)":void 0,borderRadius:l?"0 4px 4px 0":void 0,position:"relative"},children:[l&&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:a}),r]})}function Ts(t,n,i){const[o,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||t.length===0)return;let r=!1;const a=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),a.length===0)return;const l=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(a.map(async p=>{var g;const x=await l(p);return(g=i==null?void 0:i.current)==null||g.set(p,x),[p,x]})).then(p=>{r||s(x=>{const g={...x};for(const[u,h]of p)g[u]=h;return g})}),()=>{r=!0}},[t.join(","),n]),o}function zs({section:t,onNavigate:n,transport:i,workLabelCache:o,highlightQuery:s=""}){const{convert:r}=H(),a=me(),c=$e(),l=y=>{if(!y)return"";const k=r(y);return s?st(k,s,c):k},[d,p]=f.useState(!1);f.useEffect(()=>{s&&p(!0)},[s]);const x=t.type,g=vs[x]||"var(--bim-desc-fg, #717171)",u=!!t.content,h=t.work_ids||[],v=h.length>1,m=Ts(v?h:[],i,o),j=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?l(t.header_line):l(t.title)}),!d&&j&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:l(j)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&e.jsx("a",{href:a(h[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.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(y=>{const k=m[y],_=k?`${r(k.title)}${k.author?`(${r(k.author)})`:""}`:y.slice(0,8)+"…";return e.jsxs("a",{href:a(y),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(y))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),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:l(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:l(t.comment)})]})]})}function Rs({juan:t,searchQuery:n,onNavigate:i,transport:o,workLabelCache:s}){const{convert:r}=H(),a=$e(),c=n.trim(),l=f.useMemo(()=>c?t.sections.filter(x=>yn(x,c,!0,a)):t.sections,[t.sections,c,a]),d=t.sections.filter(x=>ye(x.type)==="考证").length,p=l.filter(x=>ye(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:r(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:l.map((x,g)=>e.jsx(zs,{section:x,onNavigate:i,transport:o,workLabelCache:s,highlightQuery:c},g))}),l.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Es({text:t,highlightQuery:n=""}){const{convert:i}=H(),o=$e(),s=a=>{const c=i(a);return n?st(c,n,o):c},r=t.split(`
|
|
3
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:r.map((a,c)=>{if(a.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(a.slice(2))},c);if(a.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(a.slice(3))},c);if(a.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(a.slice(4))},c);if(!a.trim())return c>0&&!r[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const l=a.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.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 Bs({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=H(),s=me(),r=$e(),a=d=>{if(!d)return"";const p=o(d);return i?st(p,i,r):p},c=[];let l=null;for(const d of t){const p=ye(d.type);p!=="page_header"&&(p==="类"?(l&&c.push(l),l={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(l||(l={category:"",items:[]}),l.items.push(d)):(p==="序"||p==="结语")&&(l||(l={category:"",items:[]}),l.items.push(d),p==="结语"&&(c.push(l),l=null)))}return l&&c.push(l),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:[a(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:a(d.categoryContent)})]}),d.items.map((x,g)=>ye(x.type)==="序"||ye(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:a(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:o(x.title),children:e.jsx("strong",{children:a(x.title)})}):e.jsx("strong",{children:a(x.title)}),x.content&&a(x.content)]},g))]},p))})}function Ls({juan:t,rawText:n,searchQuery:i,onNavigate:o}){const{convert:s}=H(),r=$e(),[a,c]=f.useState("catalog"),l=i.trim(),d=f.useMemo(()=>l?t.sections.filter(u=>yn(u,l,!1,r)):t.sections,[t.sections,l,r]),p=t.sections.filter(u=>ye(u.type)==="书").length,x=t.sections.filter(u=>ye(u.type)==="诗").length,g=l?d.filter(u=>ye(u.type)==="书"||ye(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("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},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:a===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:a===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))}),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} 部书`})]}),a==="raw"&&(n?e.jsx(Es,{text:n,highlightQuery:l}):e.jsx(Bs,{sections:t.sections,onNavigate:o,highlightQuery:l})),a==="catalog"&&d.map((u,h)=>{const v=ye(u.type);return v==="书"||v==="诗"||v==="考证"?e.jsx(_s,{section:u,onNavigate:o,highlightQuery:l},h):v==="类"?e.jsx(Cs,{section:u,highlightQuery:l},h):e.jsx(Is,{section:u,highlightQuery:l},h)}),a==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function to(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 Zn(t){const n=to(t);return n.length>0?n[0]:null}function Ws(t){const{workId:n,transport:i,files:o,activeFile:s,activeJuan:r,activeRawText:a,query:c,isKaozhen:l}=t,d=$e(),p=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&r&&p.current.set(s,{juan:r,rawText:a})},[s,r,a]),f.useEffect(()=>{p.current.clear(),g({})},[n]);const u=f.useCallback((h,v)=>{let m=0;if(h.juan)for(const j of h.juan.sections)yn(j,v,l,d)&&m++;return m===0&&h.rawText&&ys(h.rawText,v,d)&&(m=1),m},[l,d]);return f.useEffect(()=>{const h=c.trim();if(!h){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||o.length===0)return;let v=!1;const m={},j=[];for(const T of o){const S=p.current.get(T);S?m[T]=u(S,h):(m[T]="loading",j.push(T))}g(m);const y=8;let k=0;const _=async()=>{var T;for(;k<j.length;){if(v)return;const S=k++,I=j[S];try{const[z,C]=await Promise.all([i.getCollatedJuan(n,I),((T=i.getCollatedJuanText)==null?void 0:T.call(i,n,I))??Promise.resolve(null)]),b={juan:z,rawText:C};if(p.current.set(I,b),v)return;g(R=>({...R,[I]:u(b,h)}))}catch{if(v)return;g(z=>({...z,[I]:0}))}}},w=Array.from({length:Math.min(y,j.length)},()=>_());return Promise.all(w),()=>{v=!0}},[c,n,i,o.join(","),u,d]),{matchStates:x}}const jn=({index:t,workId:n,transport:i,onNavigate:o,activeJuan:s,onJuanChange:r,className:a,style:c})=>{const[l,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[h,v]=f.useState(null),[m,j]=f.useState(null),[y,k]=f.useState(!1),[_,w]=f.useState(null),[T,S]=f.useState(""),I=f.useRef(new Map),z=s??h,C=f.useCallback($=>{v($),r==null||r($)},[r]),b=t||l;f.useEffect(()=>{t&&(x(!1),u(null))},[t]),f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let $=!1;return x(!0),u(null),i.getCollatedEditionIndex(n).then(F=>{if(!$)if(!F)u("未找到整理本数据");else{d(F);const Q=Zn(F);!s&&Q&&C(Q)}}).catch(F=>{$||u(F instanceof Error?F.message:"加载失败")}).finally(()=>{$||x(!1)}),()=>{$=!0}},[t,n,i,s,C]),f.useEffect(()=>{const $=t||l;if($&&!z){const F=Zn($);F&&C(F)}},[t,l,z,C]);const R=n||(b==null?void 0:b.work_id),E=f.useCallback(async $=>{var F;if(!(!R||!(i!=null&&i.getCollatedJuan))){k(!0),j(null),w(null);try{const[Q,W]=await Promise.all([i.getCollatedJuan(R,$),((F=i.getCollatedJuanText)==null?void 0:F.call(i,R,$))??Promise.resolve(null)]);j(Q),w(W)}catch{j(null),w(null)}finally{k(!1)}}},[R,i]);f.useEffect(()=>{z&&E(z)},[z,E]);const A=$=>{C($)};if(p)return e.jsx("div",{className:a,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:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!b)return null;const M=b.type==="kaozhen",P=to(b);return e.jsx($s,{className:a,style:c,index:b,allFiles:P,isKaozhen:M,effectiveWorkId:R,transport:i,activeFile:z,handleSelectFile:A,juanData:m,juanRawText:_,juanLoading:y,searchQuery:T,setSearchQuery:S,onNavigate:o,workLabelCacheRef:I})},$s=({className:t,style:n,index:i,allFiles:o,isKaozhen:s,effectiveWorkId:r,transport:a,activeFile:c,handleSelectFile:l,juanData:d,juanRawText:p,juanLoading:x,searchQuery:g,setSearchQuery:u,onNavigate:h,workLabelCacheRef:v})=>{const{matchStates:m}=Ws({workId:r,transport:a,files:o,activeFile:c,activeJuan:d,activeRawText:p,query:g,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:g,onChange:j=>u(j.target.value),style:{width:"100%",maxWidth:"420px",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("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?e.jsxs(e.Fragment,{children:[i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 卷"]})}),i.text_quality&&(()=>{const j=us(i.text_quality.grade);return j?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(ps,{content:pr[j],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:ur[j],cursor:"help"},children:$i[j]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),e.jsx(ks,{files:o,groups:i.juan_groups,activeFile:c,onSelect:l,juanMeta:i.juan_metadata,matchStates:m}),x?e.jsx(Je,{}):d?s?e.jsx(Rs,{juan:d,searchQuery:g,onNavigate:h,transport:a,workLabelCache:v}):e.jsx(Ls,{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((j,y)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[y+1,". "]}),j.url?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:j.title}):e.jsx("span",{children:j.title}),j.author&&e.jsxs("span",{children:[",",j.author]}),j.note&&e.jsxs("span",{children:["。",j.note]})]},y))]})]})},As={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Ms={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Fs(t){try{const n=new Date(t),i=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const Sn=({items:t,loading:n})=>{const i=me();return n?e.jsx(Je,{}):t.length===0?e.jsx("div",{style:Ps,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=As[o.type],r=Ms[o.status];return e.jsxs("div",{style:Hs,children:[e.jsxs("div",{style:Os,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Qn,background:s.color},children:s.label}),e.jsx("span",{style:{...Qn,background:r.color},children:r.label})]}),e.jsx("span",{style:Ds,children:Fs(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:Ns,children:[o.resourceId&&e.jsx("a",{href:i(o.resourceId),style:ei,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:ei,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Vs,children:o.content}),o.reply&&e.jsxs("div",{style:Gs,children:[e.jsx("div",{style:Us,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},Ps={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Hs={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Os={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Qn={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Ds={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Ns={fontSize:"12px",marginBottom:"6px"},ei={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Vs={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Gs={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Us={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},rn=({transport:t,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:r})=>{const a=D(),[c,l]=f.useState(null),[d,p]=f.useState([]),[x,g]=f.useState("recommend"),[u,h]=f.useState([]),[v,m]=f.useState(!1),j=o??x,y=M=>{g(M),s==null||s(M)},[k,_]=f.useState(!0),[w,T]=f.useState(null),[S,I]=f.useState(null),[z,C]=f.useState(null);f.useEffect(()=>{let M=!1;if(t.getCounts)return t.getCounts().then(P=>{M||l({works:P.works,books:P.books,collections:P.collections})}).catch(()=>{}),()=>{M=!0}},[t]),f.useEffect(()=>{let M=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const $=await t.getRecommended();if($!=null&&$.groups)return $.groups.flatMap(F=>F.items.map(Q=>({...Q,group:F.name})))}catch{}return[]})().then(async $=>{if(M)return;const F=$.filter(W=>W.id);if(F.length===0){_(!1);return}const Q=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 U=null;if(t.getEntry)U=await t.getEntry(W.id);else{const ne=await t.getItem(W.id);ne&&(U={id:W.id,title:ne.title||W.id,type:ne.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:X.extractType(W.id),group:W.group,fallbackDescription:W.description}}));M||(p(Q.filter(W=>W!==null)),_(!1))}),()=>{M=!0}},[t,i]);const b=f.useRef(!1),R=f.useRef(!1),E=f.useRef(!1);f.useEffect(()=>{if(j!=="catalog"||b.current)return;const M=t.getCatalogProgress??t.getResourceProgress;if(!M)return;b.current=!0;let P=!1;return M.call(t).then($=>{P||T($)}).catch(()=>{b.current=!1}),()=>{P=!0}},[t,j]),f.useEffect(()=>{if(j!=="collection"||R.current||!t.getCollectionProgress)return;R.current=!0;let M=!1;return t.getCollectionProgress().then(P=>{M||I(P)}).catch(()=>{R.current=!1}),()=>{M=!0}},[t,j]),f.useEffect(()=>{if(j!=="site"||E.current||!t.getSiteProgress)return;E.current=!0;let M=!1;return t.getSiteProgress().then(P=>{M||C(P)}).catch(()=>{E.current=!1}),()=>{M=!0}},[t,j]),f.useEffect(()=>{if(!r||j!=="feedback")return;let M=!1;return m(!0),fetch(r).then(P=>P.json()).then(P=>{!M&&P.success&&h(P.items||[])}).catch(()=>{}).finally(()=>{M||m(!1)}),()=>{M=!0}},[r,j]);const A=M=>{switch(M){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(pt,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),e.jsx(pt,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),e.jsx(pt,{label:a.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),e.jsx(pt,{label:a.home.siteTab,active:j==="site",onClick:()=>y("site")}),r&&e.jsx(pt,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&e.jsx(Ys,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:a}),j==="catalog"&&e.jsx(ti,{progress:w,t:a,onNavigate:n}),j==="collection"&&e.jsx(ti,{progress:S,t:a,onNavigate:n}),j==="site"&&e.jsx(Js,{progress:z,t:a,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&r&&e.jsx(Sn,{items:u,loading:v})]})})},pt=({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}),Ys=({recommended:t,loading:n,onNavigate:i,getIcon:o,t:s})=>{const r=me();if(n)return e.jsx(Je,{});if(t.length===0)return null;const a=new Map;for(const c of t){const l=c.group||s.home.recommendedBrowse;a.has(l)||a.set(l,[]),a.get(l).push(c)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([c,l])=>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:l.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:r(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:o(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))})},ti=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Je,{});const o=[...t.resources].sort((c,l)=>c.priority-l.priority),s=["in_progress","done","todo"],r={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={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 l=o.filter(d=>d.status===c);return l.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:a[c]}}),r[c]," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(d=>e.jsx(Ks,{item:d,t:n,statusColor:a[c],onNavigate:i},d.id))})]},c)})})},Ks=({item:t,t:n,statusColor:i,onNavigate:o})=>{const s=me(),r=t.total>0?Math.round(t.imported/t.total*100):0,a=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,l=t.collection_id||t.work_id;return l&&o?e.jsx("a",{href:s(l),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(l))},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:a})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?kt(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:`${r}%`,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})]})},Js=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Je,{});const o=[...t.resources].sort((l,d)=>l.priority-d.priority),s=o.filter(l=>l.imported>0),r=o.filter(l=>l.imported===0),a=s.reduce((l,d)=>Math.max(l,d.imported),0),c=i>0?Math.round(a/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:a.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(l=>e.jsx(ni,{item:l,t:n,totalWorks:i},l.id))})]}),r.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," (",r.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:r.map(l=>e.jsx(ni,{item:l,t:n,totalWorks:i},l.id))})]})]})},ni=({item:t,t:n,totalWorks:i})=>{const o=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} (${o}%)`: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:`${o}%`,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})]})},ii="(max-width: 768px)";function qs(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(ii).matches);return f.useEffect(()=>{const i=window.matchMedia(ii),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),t}const Xs=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var P;const r=D(),{convert:a}=H(),c=qs(),[l,d]=f.useState(null),[p,x]=f.useState(null),[g,u]=f.useState(!1),[h,v]=f.useState("detail"),[m,j]=f.useState([]),[y,k]=f.useState(!1),[_,w]=f.useState(null),[T,S]=f.useState(!1),I=f.useCallback(async $=>{if(!t.getCollatedEditionIndex){w(null);return}S(!0);try{const F=await t.getCollatedEditionIndex($);w(F)}catch{w(null)}finally{S(!1)}},[t]),z=f.useCallback(async $=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}k(!0);try{if(t.getCollectionCatalogs){const F=await t.getCollectionCatalogs($);j(F||[])}else if(t.getCollectionCatalog){const F=await t.getCollectionCatalog($);j(F?[{resource_id:"",data:F}]:[])}}catch{j([])}finally{k(!1)}},[t]),C=f.useCallback(async $=>{if(i){i($);return}d($),x(null),j([]),w(null),v("detail"),u(!0);try{const F=await t.getItem($.id);F&&(x(F),F.type==="collection"?z($.id):F.type==="work"&&F.has_collated&&I($.id))}catch(F){console.error("加载详情失败:",F)}finally{u(!1)}},[t,i,z,I]),b=f.useCallback(async $=>{x(null),j([]),w(null),v("detail"),u(!0);try{const F=await t.getItem($);F&&(x(F),d({id:$,title:F.title||$,type:F.type||"book"}),F.type==="collection"?z($):F.type==="work"&&F.has_collated&&I($))}catch(F){console.error("导航失败:",F)}finally{u(!1)}},[t,z,I]),R=(p==null?void 0:p.type)==="collection"&&(m.length>0||y)||(p==null?void 0:p.type)==="work"&&(_||T),E=c&&(g||p),A=f.useCallback(()=>{d(null),x(null),j([]),w(null),v("detail")},[]),M=e.jsx(e.Fragment,{children:g?e.jsx(Je,{}):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:Rt(h==="detail"),children:r.detailTab.basicInfo}),p.type==="collection"&&y&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:Rt(!1),children:[r.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&m.map($=>e.jsx("button",{onClick:()=>v(`catalog:${$.resource_id}`),style:Rt(h===`catalog:${$.resource_id}`),children:$.short_name?`${a($.short_name)}${r.detailTab.catalogSuffix}`:r.detailTab.collectionCatalog},$.resource_id)),p.type==="work"&&(_||T)&&e.jsxs("button",{onClick:()=>v("collated"),style:Rt(h==="collated"),children:[r.detailTab.collatedEdition,T&&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(mn,{data:p,transport:t,onNavigate:b}):h.startsWith("catalog:")?e.jsx(hn,{data:(P=m.find($=>`catalog:${$.resource_id}`===h))==null?void 0:P.data,onNavigate:b}):h==="collated"?e.jsx(jn,{index:_||void 0,workId:p.id,transport:t,onNavigate:b}):null})]}):e.jsx(rn,{transport:t,onNavigate:b,recommendedIds:o})});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:A,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:["← ",r.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:M})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(on,{transport:t,onEntryClick:C,hideModeIndicator:n}),!p&&e.jsx(rn,{transport:t,onNavigate:b,recommendedIds:o})]})}):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(on,{transport:t,onEntryClick:C,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:M})]})};function Rt(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 De(t){return t.replace(/\.md$/,"")}const no=({index:t,bookId:n,transport:i,activeChapter:o,onChapterChange:s})=>{const[r,a]=f.useState(t??null),[c,l]=f.useState(null),d=o!==void 0?o:c,p=f.useCallback(m=>{s?s(m):l(m)},[s]),[x,g]=f.useState(null),[u,h]=f.useState(!1);f.useEffect(()=>{t&&a(t)},[t]),f.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let m=!1;return i.getBookFullTextIndex(n).then(j=>{m||a(j)}),()=>{m=!0}},[n,i,t]),f.useEffect(()=>{if(!r||r.chapters.length===0)return;const m=De(r.chapters[0].file);if(!d){p(m);return}const j=De(d);r.chapters.some(k=>De(k.file)===j)||p(m)},[r,d,p]);const v=f.useMemo(()=>{if(!r||!d)return null;const m=De(d);return r.chapters.find(j=>De(j.file)===m)??null},[r,d]);return f.useEffect(()=>{if(!n||!v||!i.getBookFullTextChapter)return;let m=!1;return h(!0),g(null),i.getBookFullTextChapter(n,v.file).then(j=>{m||g(j)}).catch(()=>{m||g(null)}).finally(()=>{m||h(!1)}),()=>{m=!0}},[n,v,i]),r?r.chapters.length===0?e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"}):e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"stretch",minHeight:400},children:[e.jsxs("aside",{style:{flex:"0 0 240px",maxHeight:"calc(100vh - 200px)",overflowY:"auto",borderRight:"1px solid var(--bim-border, #e5e5e5)",paddingRight:12},children:[e.jsxs("div",{style:{padding:"8px 12px",fontSize:13,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:[r.version_label," · 共 ",r.total_chapters," ",(r.chapters.length===1,"章")]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:r.chapters.map(m=>{const j=De(m.file),y=j===De(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(j),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:y?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:y?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:y?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:m.title})},m.file)})})]}),e.jsxs("main",{style:{flex:1,maxHeight:"calc(100vh - 200px)",overflowY:"auto",paddingLeft:8},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:r.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:r.source.name}),r.source.license&&e.jsxs(e.Fragment,{children:[" · ",r.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:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},Zs=({data:t,onNavigate:n,className:i,style:o})=>{var p;const s=D(),{convert:r}=H(),[a,c]=f.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[l,d]=f.useState(null);return e.jsxs("div",{className:i,style:o,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:r(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(Qs,{division:x,expanded:a===x.name,onToggle:()=>c(a===x.name?null:x.name),expandedCat:l,onCatToggle:g=>d(l===g?null:g),onNavigate:n},x.name))})]})},Qs=({division:t,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:r})=>{const{convert:a}=H(),c=t.categories.reduce((l,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return l+(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:a(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(l=>{const d=`${t.name}/${l.name}`;return e.jsx(el,{category:l,expanded:o===d,onToggle:()=>s(d),onNavigate:r},l.name)})})]})},el=({category:t,expanded:n,onToggle:i,onNavigate:o})=>{var l,d,p,x;const{convert:s}=H(),r=((l=t.books)==null?void 0:l.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||r.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.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&&(r.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[r.length>0&&e.jsx(oi,{label:"著錄",books:r,onNavigate:o}),a.length>0&&e.jsx(oi,{label:"存目",books:a,onNavigate:o})]})]})},oi=({label:t,books:n,onNavigate:i})=>{const{convert:o}=H(),s=me(),[r,a]=f.useState(n.length<=20),c=r?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((l,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:l.work_id&&i?e.jsx("a",{href:s(l.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(l.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(l.title)}):o(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(l.author).slice(0,20)})]},d))}),!r&&e.jsxs("button",{onClick:()=>a(!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," 條"]})]})},je=({title:t,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const r=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:[o,i&&e.jsx("button",{onClick:i,style:nl,children:"AI"}),n&&e.jsx("button",{onClick:n,style:tl,children:r.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"},nl={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ge=({label:t,value:n,onChange:i,placeholder:o,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:r=>i(r.target.value),placeholder:o,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"}})]}),Ge=({value:t,onChange:n,placeholder:i})=>{const o=f.useRef(null);return f.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,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"}})},Ft=({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 il(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Et=({value:t,onChange:n,label:i})=>{const[o,s]=f.useState(!1),r=f.useRef(null),a=il(t||"");return f.useEffect(()=>{o&&r.current&&r.current.focus()},[o]),!o&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ri,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:a.name}),e.jsx(Ft,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:ri,children:i}),e.jsx("input",{ref:r,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"}})]})},ri={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function ol(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 rl(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const io=({items:t,onChange:n,onOpenEntityPicker:i})=>{const o=D(),[s,r]=f.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),r(t.length)},c=x=>{n(t.filter((g,u)=>u!==x)),s===x&&r(null)},l=(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:()=>r(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||`${o.editor.sourcePlaceholder} ${g+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:ol(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:rl(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:o.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:Le,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...si,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:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...si,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:o.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:Le,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:li,children:o.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:o.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:o.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:Le,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:li,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:u=>l(g,"name",u.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Ze})]}),e.jsxs("div",{children:[e.jsx("label",{style:Le,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:u=>l(g,"id",u.target.value),placeholder:"https://...",style:Ze})]})]}),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:{...Le,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Le,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:u=>l(g,"details",u.target.value),placeholder:o.editor.detailsPlaceholder,style:Ze})]}),e.jsxs("div",{children:[e.jsx("label",{style:Le,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:u=>l(g,"position",u.target.value),placeholder:"如: 卷三, p.52",style:Ze})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Le,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:u=>l(g,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:Ze})]}),e.jsxs("div",{children:[e.jsx("label",{style:Le,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:u=>l(g,"processor_version",u.target.value),placeholder:"如: v0.1",style:Ze})]})]})]})]})})]},g)),e.jsxs("button",{onClick:a,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.addSource})]})]})},Le={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},Ze={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"},si={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"},li={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function oo(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 ro(t){return!t||t.length===0?"":JSON.stringify(t)}const so=({entityType:t,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:r,belongsToCollection:a,childWorks:c,childCollections:l,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:sl,children:m.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ut,{direction:"up",title:m.relation.belongsToWork,entity:r,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(ut,{direction:"up",title:m.relation.containedInCollection,entity:a,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}),r&&p&&p.length>0&&e.jsx(Qe,{direction:"horizontal",title:`${m.relation.siblingVersions} (${p.length})`,entities:p,onView:u,onAdd:()=>h("siblingBook","book",{workId:r.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ut,{direction:"up",title:m.relation.parentWork,entity:o,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(Qe,{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}),l&&l.length>0&&e.jsx(Qe,{direction:"down",title:`${m.relation.collectionImpl} (${l.length})`,entities:l,onView:u,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Qe,{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(ut,{direction:"up",title:m.relation.correspondingWork,entity:r,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(ut,{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(Qe,{direction:"down",title:`${m.relation.childCollections} (${(l==null?void 0:l.length)??0})`,entities:l||[],onView:u,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Qe,{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})]})]})]})},ut=({direction:t,title:n,entity:i,onView:o,onUnlink:s,onLink:r,onCreate:a,linkLabel:c,createLabel:l,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:lo(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(ai,{onClick:()=>o(i),title:p,children:"👁️"}),e.jsx(ai,{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(sn,{onClick:r,children:c}),e.jsx(sn,{onClick:a,primary:!0,children:l})]})]})},Qe=({direction:t,title:n,entities:i,onView:o,onAdd:s,addLabel:r,noneLabel:a,expandMoreLabel:c})=>{const[l,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=l?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:()=>o(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:lo(u.type)}),e.jsx("span",{children:u.title})]},u.id)),i.length>5&&!l&&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:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(sn,{onClick:s,primary:!0,children:["+ ",r]})})]})},ai=({onClick:t,title:n,danger:i,children:o})=>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:o}),sn=({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 lo(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const sl={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"},ao=({isOpen:t,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:r,searchResults:a,onSearch:c,isLoading:l,excludeId:d})=>{const[p,x]=f.useState(""),g=d?a.filter(m=>m.id!==d):a;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:ll,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:cl,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:dl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:l?e.jsx("div",{style:Zt,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>e.jsxs("div",{onClick:()=>o(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:Zt,children:["未找到匹配的",h]}):e.jsxs("div",{style:Zt,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:r,style:ul,children:["创建新",h,"并关联"]})]})]})})},ll={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)"},cl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},dl={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))"},Zt={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},ul={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ci={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},xl={work:"📜",book:"📖",collection:"📚",entity:"👤"},co=({isOpen:t,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:r})=>{const[a,c]=f.useState(""),l=f.useRef(null);f.useEffect(()=>{t&&(c((o==null?void 0:o.title)||""),setTimeout(()=>{var g,u;(g=l.current)==null||g.focus(),(u=l.current)==null||u.select()},100))},[t,o==null?void 0:o.title]);const d=g=>{g.key==="Enter"&&a.trim()?p():g.key==="Escape"&&r()},p=()=>{a.trim()&&s(a.trim(),{...o,title:a.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`创建新${ci[n]}`}};return e.jsx("div",{style:fl,onClick:g=>{g.target===g.currentTarget&&r()},children:e.jsxs("div",{style:gl,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:xl[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:l,type:"text",value:a,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${ci[n]}名称...`,style:ml})]}),((o==null?void 0:o.author)||(o==null?void 0:o.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:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:r,style:hl,children:"取消"}),e.jsx("button",{onClick:p,disabled:!a.trim(),style:{...bl,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},fl={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},gl={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)"},ml={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"},hl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},bl={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 po(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function vl(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 uo=({isOpen:t,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:r=!1,createButtonText:a,onSelect:c,onCancel:l,onCreate:d,onSearch:p})=>{const[x,g]=f.useState(""),[u,h]=f.useState([]),[v,m]=f.useState(!1),[j,y]=f.useState("recent");f.useEffect(()=>{t&&(g(""),h([]),y(o.length>0?"recent":"search"))},[t,o.length]),f.useEffect(()=>{if(!x.trim()){h([]);return}const I=setTimeout(async()=>{m(!0);try{h(await p(x,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(I)},[x,i,p]);const k=f.useCallback(I=>{g(I.target.value),I.target.value.trim()&&y("search")},[]),_=f.useCallback(I=>s?I.filter(z=>z.id!==s):I,[s]);if(!t)return null;const w=n||(i==="all"?"选择实体":`选择${po(i)}`),T=_(o),S=_(u);return e.jsx("div",{style:Sl,children:e.jsxs("div",{style:kl,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:w}),e.jsx("button",{onClick:l,style:wl,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:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:_l}),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:"搜索中..."})]})}),T.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(di,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",T.length,")"]}),e.jsxs(di,{active:j==="search",onClick:()=>y("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&T.length>0?e.jsx(pi,{entities:T,onSelect:c}):x.trim()?v?e.jsx(Qt,{message:"搜索中..."}):S.length>0?e.jsx(pi,{entities:S,onSelect:c}):e.jsx(Qt,{message:"未找到匹配的结果"}):e.jsx(Qt,{message:"输入关键词开始搜索"})}),r&&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:Cl,children:a||"创建新实体"})]})]})})},di=({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}),pi=({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,o]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!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:vl(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:po(t.type)})]})},Qt=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Sl={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},kl={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)"},wl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},_l={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"},Cl={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Il={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)"},Tl={work:"📜",collection:"📚",book:"📖",entity:"👤"},xo=({data:t,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:r,onDelete:a,onAskAI:c,renderSectionActions:l,onDownloadResource:d,downloadStatuses:p,relations:x,onRelationsChange:g})=>{var te;const u=D(),[h,v]=f.useState(!1),[m,j]=f.useState("work"),[y,k]=f.useState(""),[_,w]=f.useState(""),[T,S]=f.useState([]),[I,z]=f.useState(!1),[C,b]=f.useState(!1),[R,E]=f.useState("work"),[A,M]=f.useState(""),[P,$]=f.useState(),[F,Q]=f.useState(!1),[W,U]=f.useState(null),[ne,B]=f.useState([]);f.useRef(null);const V=t.type,Y=V==="work",ie=V==="collection",G=V==="book",K=f.useCallback((L,Z)=>{n({...t,[L]:Z})},[t,n]),de=f.useCallback((L,Z)=>{k(L),j(Z),w(u.editor.selectToLink+u.indexType[Z]),S([]),v(!0)},[u]),Re=f.useCallback(L=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,L)},[o,t.id]),le=f.useCallback(L=>{s==null||s(L.id,L.type)},[s]),xe=f.useCallback((L,Z,se)=>{const J={...se,author:(se==null?void 0:se.author)||t.author,dynasty:(se==null?void 0:se.dynasty)||t.dynasty};E(Z),M(L),$(J),b(!0)},[t.author,t.dynasty]),he=f.useCallback((L,Z)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,A,{type:R,title:L,inheritData:Z}),b(!1)},[o,t.id,A,R]),Oe=f.useCallback(L=>{if(!L.trim()){S([]);return}z(!0),o!=null&&o.searchEntities&&o.searchEntities(L,m).then(Z=>{S(Z),z(!1)}).catch(()=>{S([]),z(!1)})},[o,m]),_e=f.useCallback(L=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,y,L.id),v(!1)},[o,t.id,y]),qe=f.useCallback(()=>{i()},[i]),lt=f.useCallback(L=>{U(()=>L),Q(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(B).catch(()=>{})},[o]),N=f.useCallback((L,Z)=>o!=null&&o.searchEntities?o.searchEntities(L,Z==="all"?void 0:Z):Promise.resolve([]),[o]),oe=f.useCallback(L=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(L),B(Z=>[L,...Z.filter(se=>se.id!==L.id)].slice(0,10)),W==null||W(L),Q(!1),U(null)},[o,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:Tl[V]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Ft,{children:t.id}),e.jsx(Ft,{color:Il[V],children:u.indexType[V]})]})}),e.jsx(je,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:l==null?void 0:l("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Et,{label:Y?u.editor.workTitle:ie?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:L=>K("title",L)}),G&&e.jsx(Et,{label:u.editor.belongsToWork,value:t.workName||"",onChange:L=>K("workName",L)}),e.jsx(ge,{label:u.editor.authorLabel,value:t.author||"",onChange:L=>K("author",L)}),e.jsx(ge,{label:u.editor.dynastyLabel,value:t.dynasty||"",onChange:L=>K("dynasty",L)}),(G||ie)&&e.jsx(Et,{label:u.editor.containedIn,value:t.collection||"",onChange:L=>K("collection",L)}),(G||ie)&&e.jsx(ge,{label:u.editor.holderLabel,value:t.holder||"",onChange:L=>K("holder",L)}),(G||ie)&&e.jsx(ge,{label:G?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:L=>K("pages",L)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ge,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:L=>K("firstImage",L)})})]})}),e.jsx(je,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Ge,{value:t.description||"",onChange:L=>K("description",L),placeholder:u.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(je,{title:u.section.additionalWorks,onSave:i,children:e.jsx(zl,{items:t.additional_works||[],onChange:L=>K("additional_works",L)})}),e.jsx(je,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Rl,{items:t.indexed_by||[],onChange:L=>K("indexed_by",L)})}),e.jsx(je,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(El,{items:t.emendated_by||[],onChange:L=>K("emendated_by",L)})}),e.jsx(je,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(nn,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(je,{title:u.section.imageResources,onSave:i,children:e.jsx(nn,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(je,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(io,{items:oo(t.sources||""),onChange:L=>K("sources",ro(L)),onOpenEntityPicker:lt})}),(G||ie)&&e.jsx(je,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Ge,{value:t.provenance||"",onChange:L=>K("provenance",L),placeholder:u.editor.provenancePlaceholder})}),G&&e.jsx(je,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Ge,{value:t.otherEditions||"",onChange:L=>K("otherEditions",L),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(so,{entityType:V,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:Re,onViewEntity:le,onCreateAndLink:xe,onSaveRelations:qe}),r&&a&&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:a,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(ao,{isOpen:h,entityType:m,title:_,onSelect:_e,onCancel:()=>v(!1),onCreate:()=>{v(!1),xe(y,m)},searchResults:T,onSearch:Oe,isLoading:I,excludeId:t.id}),e.jsx(co,{isOpen:C,entityType:R,relationField:A,inheritData:P,onConfirm:he,onCancel:()=>b(!1)}),e.jsx(uo,{isOpen:F,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:oe,onCancel:()=>{Q(!1),U(null)},onSearch:N})]})};function zl({items:t,onChange:n}){const i=D(),o=(a,c,l)=>{const d=t.map((p,x)=>x===a?{...p,[c]:l}:p);n(d)},s=a=>n(t.filter((c,l)=>l!==a)),r=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ge,{label:i.editor.bookNameLabel,value:a.book_title,onChange:l=>o(c,"book_title",l)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ge,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:l=>o(c,"n_juan",l&&parseInt(l,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:r,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 fo({items:t,onChange:n,showMeta:i,addLabel:o}){const s=D(),[r,a]=f.useState(null),c=(p,x,g)=>{const u=t.map((h,v)=>v===p?{...h,[x]:g||void 0}:h);n(u)},l=p=>{n(t.filter((x,g)=>g!==p)),r===p&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,x)=>{const g=r===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:()=>a(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(),l(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(ge,{label:s.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),e.jsx(ge,{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(ge,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),e.jsx(ge,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),e.jsx(ge,{label:s.label.edition,value:p.edition||"",onChange:u=>c(x,"edition",u)})]}),e.jsx(Ge,{value:p.summary||"",onChange:u=>c(x,"summary",u),placeholder:s.editor.summaryPlaceholder}),e.jsx(Ge,{value:p.comment||"",onChange:u=>c(x,"comment",u),placeholder:s.editor.commentPlaceholder}),e.jsx(Ge,{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:o})]})}function Rl({items:t,onChange:n}){const i=D();return e.jsx(fo,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function El({items:t,onChange:n}){const i=D();return e.jsx(fo,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function go(t){var c,l,d,p,x,g,u;const n=((l=(c=t.authors)==null?void 0:c[0])==null?void 0:l.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",o=((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)||"",r=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,dynasty:i,holder:o,pages:s,description:r,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&&(a.parentWorkId=v.id,a.parentWorkName=v.title)}}if(t.type==="book"){const h=t;a.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(a.collectionId=(u=h.contained_in[0])==null?void 0:u.id)}return a}function Bl(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.dynasty?{year:t.dynasty}: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 Ll=t=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:r,onChange:a,onSave:c,onDelete:l,onNavigate:d,renderLink:p,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:h,relations:v,onRelationsChange:m,headerExtra:j,className:y,style:k}=t;D();const[_,w]=f.useState(s),T=r?s:_;f.useEffect(()=>{s!==_&&w(s)},[s]);const S=f.useCallback(()=>{const A=T==="view"?"edit":"view";r?r(A):w(A)},[T,r]),[I,z]=f.useState(null);f.useEffect(()=>{i&&o&&o.getItem(i).then(A=>{A&&z(A)})},[i,o]);const C=n||I,b=f.useMemo(()=>C?go(C):null,[C]),R=r||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:T==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:T==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:T==="view"?"切换到编辑模式":"切换到查看模式",children:T==="view"?"✏️ 编辑":"👁 查看"}):null,E=e.jsxs(e.Fragment,{children:[R,j]});return!C&&!b?e.jsx(Je,{}):T==="view"?e.jsx(mn,{data:C,transport:o,onNavigate:d?A=>d(A):void 0,renderLink:p,headerExtra:E,className:y,style:k}):b?e.jsxs("div",{className:y,style:k,children:[E&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:E}),e.jsx(xo,{data:b,onChange:a||(()=>{}),onSave:c||(()=>{}),transport:o,onNavigate:d,showDelete:!!l,onDelete:l,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:"无数据"})},ui=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],mo=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const[s,r]=f.useState(null),[a,c]=f.useState(""),[l,d]=f.useState("idle"),[p,x]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(r(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(l==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[l,n]),f.useEffect(()=>{if(!t)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const u=async()=>{if(!(!s||!a.trim())){d("submitting"),x("");try{await i({type:s,content:a.trim()}),d("success")}catch(m){d("error"),x(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&a.trim()&&l!=="submitting",v=ui.find(m=>m.value===s);return e.jsx("div",{style:Wl,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:$l,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:Al,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Ml,"aria-label":"关闭",children:"✕"})]}),l==="success"?e.jsxs("div",{style:Dl,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,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:ui.map(m=>e.jsxs("button",{onClick:()=>r(m.value),style:{...Fl,...s===m.value?Pl:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:g,value:a,onChange:m=>c(m.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||l==="submitting",style:{...Hl,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),l==="error"&&e.jsx("div",{style:Nl,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:u,disabled:!h,style:{...Ol,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交反馈"})})]})]})})},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",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Al={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Ml={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Fl={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"},Pl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Hl={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"},Ol={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Dl={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Nl={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Vl=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[o,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...Gl,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(mo,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},Gl={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"},xi=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],ho=({onSubmit:t})=>{const[n,i]=f.useState("bug"),[o,s]=f.useState(""),[r,a]=f.useState("idle"),[c,l]=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||!o.trim())){a("submitting"),l("");try{await t({type:n,content:o.trim()}),a("success"),s(""),i("bug")}catch(u){a("error"),l(u instanceof Error?u.message:"提交失败,请稍后重试")}}},x=n&&o.trim()&&r!=="submitting",g=xi.find(u=>u.value===n);return r==="success"?e.jsx("div",{style:fi,children:e.jsxs("div",{style:ql,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>a("idle"),style:Xl,children:"继续提交"})]})}):e.jsxs("div",{style:fi,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:xi.map(u=>e.jsxs("button",{onClick:()=>i(u.value),style:{...Ul,...n===u.value?Yl:{}},children:[e.jsx("span",{children:u.icon})," ",u.label]},u.value))}),e.jsx("textarea",{ref:d,value:o,onChange:u=>s(u.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:r==="submitting",style:{...Kl}}),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:[o.length," / 2000"]}),e.jsx("button",{onClick:p,disabled:!x,style:{...Jl,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:r==="submitting"?"提交中...":"提交"})]}),r==="error"&&e.jsx("div",{style:Zl,children:c})]})},fi={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Ul={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"},Yl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Kl={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"},Jl={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ql={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Xl={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Zl={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function gi(t){return typeof t=="function"?t():t??"/api/feedback"}const bo=({resourceId:t,apiUrl:n})=>{const[i,o]=f.useState([]),[s,r]=f.useState(!0),a=f.useCallback(async()=>{const l=gi(n);r(!0);try{const p=await(await fetch(`${l}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&o(p.items)}catch{}finally{r(!1)}},[t,n]);f.useEffect(()=>{a()},[a]);const c=async l=>{const d=gi(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...l,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(()=>a(),500)};return e.jsxs("div",{children:[e.jsx(Sn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(ho,{onSubmit:c})})]})},yo=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ql={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function ke(t){return Ql[t]??t}const tt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],nt={熹平:172,建安:196,黃初:220,太康: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},vo={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Ne(t,n){if(n){const i=vo[`${n}|${t}`];if(i!=null)return i}return nt[t]}const ea=1911;function ta(t){const n=nt[t];if(n==null)return;const i=Fe[t];let o;for(const[s,r]of Object.entries(nt))Fe[s]===i&&r>n&&(o==null||r<o)&&(o=r);return o!=null?o-1:void 0}const na={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Pt(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,i=0,o=!1;for(const r of t){const a=na[r];if(a===void 0)return;o=!0,r==="十"?i=(i||1)*10:r==="廿"||r==="卅"?(n+=a,i=0):i>=10?(n+=i+a,i=0):i=i*10+a}const s=n+i;return o&&s>0?s:void 0}function Me(t){for(const n of yo)if(t.startsWith(n))return n}const Fe={};{const t=(n,i)=>{for(const o of i)Fe[o]=n};t("東漢",["熹平","建安"]),t("三國",["黃初"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ve(t,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const o of Object.keys(nt))if(t.includes(o)&&!(i&&Fe[o]&&Fe[o]!==i&&vo[`${i}|${o}`]==null))return o}function wt(t){var a,c,l;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 o=(a=t.lineage)==null?void 0:a.year_text;if(o){const d=Me(o)??"";return{era:ke(d),reign:Ve(o,d)??"",source:"lineage"}}const s=(c=t.publication_info)==null?void 0:c.year;if(s){const d=Me(s)??((l=tt.find(g=>g.pattern.test(s)))==null?void 0:l.era)??"",p=Ve(s,d)??"";if(d||p)return{era:ke(d),reign:p,source:"publication"};const x=s.match(/\d{3,4}/);if(x)return{era:"",reign:x[0],source:"publication"}}const r=t.edition||t.title||"";if(r){const d=Me(r);if(d)return{era:ke(d),reign:Ve(r,d)??"",source:"edition"};const p=tt.find(x=>x.pattern.test(r));if(p)return{era:ke(p.era),reign:Ve(r,p.era)??p.reign??"",source:"edition"}}return n}function Ot(t){var i,o,s,r,a,c,l,d;if(((i=t.dating)==null?void 0:i.year)!=null)return t.dating.year;if(typeof((o=t.lineage)==null?void 0:o.year)=="number")return t.lineage.year;const n=[(s=t.lineage)==null?void 0:s.year_text,(r=t.publication_info)==null?void 0:r.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const p of n){const x=((a=t.publication_info)==null?void 0:a.year)||((c=t.lineage)==null?void 0:c.year_text);if(x&&p!==x&&Me(x))break;const g=p.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??p.match(/[((](\d{3,4})\s*年?[))]/);if(g){const j=parseInt(g[1],10);if(j>=100&&j<=2100)return j}const u=p.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(u){const j=Me(p);if(!j||ke(j)==="民國"){const k=Pt(u[1]);if(k!=null&&k>=1&&k<=120)return ea+k}}const h=Me(p)??((l=tt.find(j=>j.pattern.test(p)))==null?void 0:l.era),v=h?ke(h):void 0,m=Ve(p,v)??(Me(p)||(d=tt.find(j=>j.pattern.test(p)))==null?void 0:d.reign);if(m){const j=Ne(m,v);if(j==null)continue;const y=p.indexOf(m),k=y>=0?p.slice(y+m.length):"",_=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),w=_?Pt(_[1]):void 0;return j+(w?w-1:0)}}}function kn(t){var o,s;const n=(o=t.dating)==null?void 0:o.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=[t.edition,t.title].filter(Boolean);for(const r of i){if(!/[間间]/.test(r))continue;const a=Me(r)??((s=tt.find(d=>d.pattern.test(r)))==null?void 0:s.era),c=a?ke(a):void 0,l=[];for(const d of Object.keys(nt))r.includes(d)&&(c&&Fe[d]&&Fe[d]!==c||Ne(d,c)!=null&&l.push(d));if(l.length===0){const d=r.match(/([一-鿿])([一-鿿])[間间]/);if(d&&c){for(const p of[d[1],d[2]])for(const x of Object.keys(nt))if(Fe[x]===c&&!(x[0]!==p&&x[x.length-1]!==p)&&Ne(x,c)!=null){l.push(x);break}}}if(l.length>0){const d=l.map(u=>Ne(u,c)).filter(u=>u!=null),p=Math.min(...d),x=l.reduce((u,h)=>Ne(u,c)>=Ne(h,c)?u:h),g=ta(x)??hi(c??"")??Math.max(...d);return{from:p,to:Math.max(p,g)}}if(c&&Bt[c]!=null)return{from:Bt[c],to:hi(c)??Bt[c]}}}const Bt={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},ia=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],oa=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ra=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function mi(t,n){for(const i of yo){const o=t.indexOf(i);if(o<0)continue;if(i.length===1){const l=t[o+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(l)&&!Ve(t.slice(o),ke(i)))continue}const s=ke(i);if(s===n)continue;const r=t.slice(o),a=Ve(r,s)??"";let c;if(a){const l=Ne(a,s);if(l!=null){const p=r.slice(r.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=p?Pt(p[1]):void 0;c=l+(x?x-1:0)}}return{era:s,reign:a,year:c}}for(const i of tt)if(i.pattern.test(t))return{era:ke(i.era),reign:i.reign??""}}function sa(t){var p,x,g;const n=wt(t);if(!n.era&&!n.reign)return;const i=t.edition||t.title||"",s=/[間间]/.test(i)?void 0:Ot(t),r=s==null?kn(t):void 0;let a;n.source==="lineage"||n.source==="publication"?a="attested":ra.test(i)||!n.reign&&s==null?a="uncertain":a="inferred";const c=n.source==="edition"?`題名「${i}」`:n.source==="lineage"?`版本傳承著錄「${((p=t.lineage)==null?void 0:p.year_text)??((x=t.lineage)==null?void 0:x.year)??""}」`:`出版著錄「${((g=t.publication_info)==null?void 0:g.year)??""}」`,l={era:n.era,reign:n.reign,year:s,yearRange:r,certainty:a,source:n.source==="edition"?"edition":"catalog",basis:c};if(oa.test(i)){const u=i.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);u&&u[1]!==n.era&&(l.laterRepair={era:u[1]})}const d=ia.find(u=>u.re.test(i));if(d){const u=i.search(d.re),h=i.slice(u),v=mi(h,n.era)??mi(i,n.era);v&&(l.basedOn={era:v.era,reign:v.reign,year:v.year,relation:d.relation})}return l}const la={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1644,清:1911,民國:1949,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function hi(t){return la[t]}function jo(t){const n=Ot(t);if(n!=null)return n;const i=kn(t);if(i)return i.from;const o=wt(t).era;return o?Bt[o]:void 0}const bi=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function ln(t){const n=bi.indexOf(t);return n===-1?bi.length:n}function So(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const r=s.relation;r==="part_of"?n.belongsTo.push(s):r==="collected_in"?n.collected.push(s):r==="has_part"||r==="contains_text_of"?n.contains.push(s):r==="text_carried_by"||r==="studied_by"||r==="derived_from"||r==="followed_by"||r==="has_adaptation"?n.derivative.push(s):r==="studies"||r==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],o=(s,r)=>{n[s].length&&i.push({key:s,labelKey:r,items:n[s]})};return o("belongsTo","belongsToWork"),o("collected","collectedIn"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),i}function Dt(t,n){const i=pn(t||[]),o=new Map,s=[];for(const d of i)d.group?(o.has(d.group)||o.set(d.group,[]),o.get(d.group).push(d)):s.push(d);for(const d of o.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 r={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=Ue(d),x=p.includes("text"),g=p.includes("image");x&&g?r.textImage.push(d):x?r.text.push(d):g?r.image.push(d):r.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>r[d].length>0).map(d=>({key:d,items:r[d]})),l=[...o.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:l,total:i.length}}function wn(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 o=un(t);return o&&o.expected>0&&n.push(o.missing>0?`${o.found} / ${o.expected} 冊 缺 ${o.missing}`:`${o.found} / ${o.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function aa(t,n){if(wn(t)||n.filter(o=>o.name===t.name).length<2)return"";try{const o=new URL(t.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const r=o.pathname.split("/").filter(Boolean).pop();if(r)return decodeURIComponent(r)}catch{}return""}function ko(t,n){var r,a;const i=t.resources||[],o=[],s=[];for(const c of i){const l=Ue(c);l.includes("image")&&o.push(c),l.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:wt(t),year:Ot(t),sortYear:jo(t),images:o,holders:s,locationName:(r=t.current_location)==null?void 0:r.name,important:ca(t.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[t.id],hasImage:o.length>0}}function ca(t,n){var c,l;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const o=(c=n.collections)==null?void 0:c[i];if(((o==null?void 0:o.book_ids)??(i==="core"?n.core_books??[]:[])).includes(t))return!0;const r=(o==null?void 0:o.groups)??[],a=(l=n.node_groups)==null?void 0:l[t];return!!a&&r.includes(a)}function wo(t,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(l=>!o.has(l.id)).map(l=>ko(l,n));let r=s;i.era&&(r=r.filter(l=>l.era.era===i.era)),i.scanOnly&&(r=r.filter(l=>l.hasImage)),i.sort==="year"?r=r.map((l,d)=>({r:l,i:d})).sort((l,d)=>{const p=l.r.sortYear,x=d.r.sortYear;return p!=null&&x!=null?p-x||l.i-d.i:p!=null?-1:x!=null?1:l.i-d.i}).map(l=>l.r):r=r.map((l,d)=>({r:l,i:d})).sort((l,d)=>{const p=x=>(x.important?0:1)*2+(x.hasImage?0:1);return p(l.r)-p(d.r)||l.i-d.i}).map(l=>l.r);const c=[...new Set(s.map(l=>l.era.era).filter(Boolean))].sort((l,d)=>ln(l)-ln(d));return{rows:r,allRows:s,eras:c,hasInferredEra:s.some(l=>l.era.source==="edition")}}function da(t,n){var m,j;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],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],r=o.length>0||s.length>0,a=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),l=new Set([...s,...a]),d=y=>{if(l.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],x=new Map,g=[];for(const y of t)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))p.push(y);else{const k=n.node_groups[y];k?(x.has(k)||x.set(k,[]),x.get(k).push(y)):g.push(y)}if(g.length+[...x.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),v=[...x.entries()].map(([y,k])=>{const _=h.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:v}}const _o=["撰","編","注","校","譯","繪","其他"],pa=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function _n(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:o}of pa)if(o.test(n))return i;return"其他"}function Cn(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function Co(t){const n=new Map;for(const o of t){const s=_n(o);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const o of _o){const s=n.get(o);s&&i.push({cls:o,label:o,count:s})}return i.length>2?i:[]}function Io(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),r=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:r,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(r=>({id:r.id,title:r.title,volumes:bt(r.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var r,a;return{id:s,title:((r=i==null?void 0:i.get(s))==null?void 0:r.title)||s,edition:(a=i==null?void 0:i.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function bt(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,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-i+1)},(s,r)=>i+r)}return t.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function In(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((r,a)=>r-a),o=i[0],s=i[i.length-1];return s-o+1===i.length?`${o}–${s}`:i.length<=3?i.join(", "):`${o}–${s} (${i.length}${n})`}const ua=["〇","一","二","三","四","五","六","七","八","九"],yi=["","十","百","千"];function To(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",s=!1;for(let r=0;r<i;r++){const a=parseInt(n[r]),c=i-1-r;a===0?s=!0:(s&&o&&(o+="〇"),s=!1,a===1&&c===1&&r===0?o+=yi[c]:o+=ua[a]+yi[c])}return o}function Ye(t,n="卷"){var o,s;const i=t;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?To(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function zo(t){var o;if((o=t.lineage)!=null&&o.category)return t.lineage.category;const n=t.edition||t.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,r]of i)if(s.test(n))return r;return""}const Ro=1e3,xa="(max-width: 719px)",Eo=`
|
|
1
|
+
"use strict";var ro=Object.create;var Nn=Object.defineProperty;var oo=Object.getOwnPropertyDescriptor;var so=Object.getOwnPropertyNames;var lo=Object.getPrototypeOf,ao=Object.prototype.hasOwnProperty;var co=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of so(n))!ao.call(t,s)&&s!==i&&Nn(t,s,{get:()=>n[s],enumerable:!(r=oo(n,s))||r.enumerable});return t};var dt=(t,n,i)=>(i=t!=null?ro(lo(t)):{},co(n||!t||!t.__esModule?Nn(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("./storage-entry-VGdfSKGX.cjs"),e=require("react/jsx-runtime"),g=require("react"),po=require("react-markdown"),uo=require("remark-gfm"),xo=require("react-dom"),fo=t=>`/book-index?id=${t}`,Hi=g.createContext(fo);function go({buildUrl:t,children:n}){const i=g.useMemo(()=>t,[t]);return e.jsx(Hi.Provider,{value:i,children:n})}function he(){return g.useContext(Hi)}function Ke(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function mo(t,n){return Ke(t).includes(n)}const Oi={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ho={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},bo={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},wt=g.createContext(null),Di={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:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},yo={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:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},vo={"zh-Hant":Di,"zh-Hans":yo},Ni="bim-locale";function jo(){try{const t=localStorage.getItem(Ni);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function So(t){try{localStorage.setItem(Ni,t)}catch{}}const ko="zh-Hans",wo=({locale:t,onLocaleChange:n,children:i})=>{const[r,s]=g.useState(t??ko),o=t??r;g.useEffect(()=>{if(t)return;const p=jo();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),So(p),n==null||n(p)},[n]),d=g.useMemo(()=>({locale:o,setLocale:a,messages:vo[o],converter:l}),[o,a,l]);return e.jsx(wt.Provider,{value:d,children:i})};function D(){const t=g.useContext(wt);return(t==null?void 0:t.messages)??Di}const _o=2e3;function H(){const t=g.useContext(wt),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>=_o){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 _t(t,n){return t.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Co(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 Io(){return{id:"",name:"",url:"",type:"text",details:""}}const sn=({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 k=Ke(b);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},x=t.map((b,k)=>({item:b,originalIndex:k})).filter(({item:b})=>p(b)),f=()=>{const b=Io();s&&(b.type=s),n([...t,b]),c(t.length)},u=b=>{n(t.filter((k,_)=>_!==b)),c(null)},h=(b,k,_)=>{const w=[...t];if(w[b]={...w[b],[k]:_},k==="url"&&!w[b].id){const I=Co(_);I&&(w[b].id=I)}n(w)},y=(b,k,_)=>{const I={...t[b].metadata||{}};_?I[k]=_:delete I[k],h(b,"metadata",Object.keys(I).length>0?I:void 0)},m=(b,k)=>{const _=k.trim()?k.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;h(b,"structure",_)},j=(b,k,_)=>{const I=t[b].coverage||{level:1,ranges:""};k==="level"?I.level=parseInt(_)||1:I.ranges=_,h(b,"coverage",I.ranges?I:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:b,originalIndex:k})=>{var _,w,I;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===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:To(b.type??"text"),color:"#fff"},children:(()=>{var T,z;const S=Ke(b);return S.length===0?b.type??"text":S.length===1?((T=a.find(C=>C.value===S[0]))==null?void 0:T.label)??S[0]:S.includes("text")&&S.includes("image")?((z=a.find(C=>C.value==="text+image"))==null?void 0:z.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${o.editor.resourcePlaceholder} ${k+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:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&b.url&&zo(k,r==null?void 0:r[k],i,o),e.jsx("button",{onClick:S=>{S.stopPropagation(),u(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisResource,children:"✕"})]}),l===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[mo(b,"image")&&b.url&&Ro(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:S=>h(k,"type",S.target.value),style:{...Ie,flex:1},children:a.map(S=>e.jsx("option",{value:S.value,children:S.label},S.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:S=>h(k,"root_type",S.target.value),style:{...Ie,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:b.id,onChange:S=>h(k,"id",S.target.value),placeholder:o.editor.idAutoExtract,style:{...Ie,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:S=>h(k,"name",S.target.value),placeholder:o.editor.resourceName,style:{...Ie,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:S=>h(k,"url",S.target.value),placeholder:o.editor.resourceUrl,style:Ie}),e.jsx("input",{type:"text",value:((_=b.structure)==null?void 0:_.join("、"))||"",onChange:S=>m(k,S.target.value),placeholder:o.editor.structurePlaceholder,style:Ie}),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:((w=b.coverage)==null?void 0:w.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...Ie,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:((I=b.coverage)==null?void 0:I.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:o.editor.coverageRangePlaceholder,style:{...Ie,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:o.editor.detailsPlaceholder,style:{...Ie,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(([S,T])=>{var z;return e.jsxs("label",{style:{...pt,gap:"4px"},children:[e.jsx("span",{style:{...ut,minWidth:"56px"},children:T}),e.jsx("input",{type:"text",value:((z=b.metadata)==null?void 0:z[S])||"",onChange:C=>y(k,S,C.target.value),placeholder:T,style:{...Ie,flex:1}})]},S)})})]})]})]})]},k)}),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 To(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 zo(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 Ro(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 Ie={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"},Eo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function jt(t){try{return Eo[new URL(t).hostname]}catch{return}}const Vn={text:0,image:1,physical:2};function fn(t){return t.length===0?"physical":[...t].sort((n,i)=>(Vn[n]??99)-(Vn[i]??99)).join("+")}function gn(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}|${fn(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 Vi(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 Gi(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Vi(n)}))}function mn(t){const n=Gi(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 hn(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 bn(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 Mt(t){if(!t.url)return;const n=hn(t.metadata);return n?bn(t.url,n):t.url}const Gn={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 Bo(t){return t.includes("text")&&t.includes("image")?Gn["text+image"]:Gn[t[0]||"physical"]}const yn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const o=D(),{convert:l}=H(),c=g.useMemo(()=>gn(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=g.useMemo(()=>{const m=new Map,j=[];for(const b of c){const k=b.group;k?(m.has(k)||m.set(k,[]),m.get(k).push(b)):j.push(b)}for(const b of m.values())b.sort((k,_)=>{const w=I=>I.group_role==="origin"?0:I.group_role==="mirror"?1:2;return w(k)-w(_)});return{mirrorGroups:m,ungroupedItems:j}},[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(j=>p[j]||j).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,j)=>e.jsx(Xt,{item:m},m.id||j))});const f=(m,j)=>{const b=i==null?void 0:i[m],k=(b==null?void 0:b.label)||m,_=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(k)}),_&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(_)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((w,I)=>e.jsx(Xt,{item:w,onNavigate:r,renderLink:s},w.id||I))})]},`group-${m}`)},u=new Map;for(const m of d){const j=fn(Ke(m));u.has(j)||u.set(j,[]),u.get(j).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,j])=>f(m,j)),y.map(m=>{const j=u.get(m),b=Bo(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:j.map((k,_)=>e.jsx(Xt,{item:k,onNavigate:r,renderLink:s},k.id||_))})]},m)})]})},Lo={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)"}},Xt=({item:t})=>{const n=D(),{convert:i}=H(),[r,s]=g.useState(!1),o=g.useMemo(()=>(t.url?jt(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||Vi(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?{...Lo[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=hn(t.metadata);return h?bn(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)})})]})},Yi=({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})]})]})},Ot="bim-search-history",Yn=10,Un=8;function ht(){try{const t=localStorage.getItem(Ot);return t?JSON.parse(t):[]}catch{return[]}}function Wo(t){try{const n=ht().filter(i=>i!==t);n.unshift(t),n.length>Yn&&(n.length=Yn),localStorage.setItem(Ot,JSON.stringify(n))}catch{}}function $o(t){try{const n=ht().filter(i=>i!==t);localStorage.setItem(Ot,JSON.stringify(n))}catch{}}function Ao(){try{localStorage.removeItem(Ot)}catch{}}const Ui=({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(ht),j=g.useRef(null),b=g.useRef(null),k=g.useRef(null),_=g.useRef(!1);g.useEffect(()=>{h(-1);const v=n.trim();if(!v){f(y.map(A=>({type:"history",text:A})));return}if(!t.searchAll){f([]);return}let R=!1;const E=setTimeout(()=>{t.searchAll(v,Un).then(A=>{if(R)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];f(M.slice(0,Un).map(P=>({type:"entry",text:P.title||P.id,entry:P})))}).catch(()=>{R||f([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,y,t]),g.useEffect(()=>{const v=R=>{k.current&&!k.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),g.useEffect(()=>{const v=R=>{var E,A;if(R.key==="/"&&document.activeElement!==j.current){const M=(E=document.activeElement)==null?void 0:E.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;R.preventDefault(),(A=j.current)==null||A.focus()}};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const w=g.useCallback(v=>{v.trim()&&(Wo(v.trim()),m(ht())),r(v),p(!1)},[r]),I=g.useCallback(v=>{v.type==="history"?(i(v.text),w(v.text)):v.entry&&(s?(s(v.entry),p(!1)):(i(v.text),w(v.text)))},[i,w,s]),S=g.useCallback(v=>{if(!d||x.length===0){v.key==="Enter"&&w(n);return}switch(v.key){case"ArrowDown":v.preventDefault(),h(R=>(R+1)%x.length);break;case"ArrowUp":v.preventDefault(),h(R=>(R-1+x.length)%x.length);break;case"Enter":v.preventDefault(),u>=0&&u<x.length?I(x[u]):w(n);break;case"Escape":v.preventDefault(),p(!1);break}},[d,x,u,n,w,I]),T=g.useCallback((v,R)=>{R.stopPropagation(),$o(v),m(ht()),f(E=>E.filter(A=>!(A.type==="history"&&A.text===v)))},[]),z=g.useCallback(v=>{v.stopPropagation(),Ao(),m([]),f([])},[]);g.useEffect(()=>{if(u>=0&&b.current){const v=b.current.children;v[u]&&v[u].scrollIntoView({block:"nearest"})}},[u]);const C=!n.trim()&&y.length>0;return e.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:v=>{i(v.target.value),p(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{p(!0)},onKeyDown:S,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:[C&&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,R)=>e.jsxs("div",{onClick:()=>I(v),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: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:E=>T(v.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:"×"})]},`${v.type}-${v.text}-${R}`))]})]})},St="bim-recent-ids",Kn="bim-recent-entries",Jn=50,Zt=5,Mo=50,Fo=200;function bt(){try{const t=localStorage.getItem(St);if(t)return JSON.parse(t);const n=localStorage.getItem(Kn);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(St,JSON.stringify(i)),localStorage.removeItem(Kn),i}return[]}catch{return[]}}function Po(t){try{const n=bt().filter(i=>i!==t);n.unshift(t),n.length>Jn&&(n.length=Jn),localStorage.setItem(St,JSON.stringify(n))}catch{}}function Ho(t){try{const n=bt().filter(i=>i!==t);localStorage.setItem(St,JSON.stringify(n))}catch{}}function Oo(){try{localStorage.removeItem(St)}catch{}}const Do={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ln=({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"}],[j,b]=g.useState(f??""),[k,_]=g.useState(null),[w,I]=g.useState(null),[S,T]=g.useState(!1),[z,C]=g.useState(null),[v,R]=g.useState(""),[E,A]=g.useState(!f),[M,P]=g.useState(bt),[$,F]=g.useState([]),[Q,W]=g.useState(!1),[Y,ne]=g.useState(!1),[B,V]=g.useState(null),[U,ie]=g.useState(null),G=g.useRef(void 0),K=g.useRef(!1),de=g.useCallback(async(N,re)=>{if(!N.trim()){A(!0),_(null),I(null);return}A(!1),T(!0),R("");try{if(t.searchAll){const te=await t.searchAll(N,re??Zt);_(te)}else{const te=["work","book","collection","entity"],L=await Promise.all(te.map(Z=>t.search(N,Z,{page:1,pageSize:re??Zt})));_({works:L[0].entries,books:L[1].entries,collections:L[2].entries,entities:L[3].entries,totalWorks:L[0].total,totalBooks:L[1].total,totalCollections:L[2].total,totalEntities:L[3].total})}}catch(te){R(te instanceof Error?te.message:String(te)),_(null)}finally{T(!1)}},[t]);g.useEffect(()=>{let N=!1;const re=()=>{var J,Fe;const te=["work","book","collection","entity"],L=Promise.all(te.map(je=>t.loadEntries(je,{page:1,pageSize:1}).catch(()=>({total:0})))),Z=((J=t.getResourceCounts)==null?void 0:J.call(t).catch(()=>null))??Promise.resolve(null),se=((Fe=t.getSubtypeStats)==null?void 0:Fe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([L,Z,se]).then(([je,ge,Qe])=>{N||(V({works:je[0].total,books:je[1].total,collections:je[2].total,entities:je[3].total,hasText:ge==null?void 0:ge.hasText,hasImage:ge==null?void 0:ge.hasImage}),Qe&&ie(Qe))})};return t.getCounts?t.getCounts().then(te=>{var L,Z;N||(V({works:te.works,books:te.books,collections:te.collections,entities:te.entities,hasText:(L=te.resourceCounts)==null?void 0:L.hasText,hasImage:(Z=te.resourceCounts)==null?void 0:Z.hasImage}),te.subtypeStats&&ie(te.subtypeStats))}).catch(()=>{N||re()}):re(),()=>{N=!0}},[t]),g.useEffect(()=>{K.current||!(f!=null&&f.trim())||(K.current=!0,de(f))},[f,de]);const Ee=g.useCallback(N=>{if(b(N),!N.trim()){u==null||u(N),A(!0),_(null),I(null);return}G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{I(null),u==null||u(N),de(N)},Fo)},[de,u]),le=g.useCallback(N=>{G.current&&clearTimeout(G.current),u==null||u(N),de(N)},[de,u]),fe=g.useCallback(N=>{I(N),de(j,Mo)},[j,de]);g.useEffect(()=>{if(!M.length){F([]);return}let N=!1;return W(!0),Promise.all(M.slice(0,10).map(async re=>{var te,L,Z;try{if(t.getEntry){const J=await t.getEntry(re);if(J)return J}const se=await t.getItem(re);if(se){const J=se.authors;return{id:re,title:se.title||re,type:se.type||"work",author:(te=J==null?void 0:J[0])==null?void 0:te.name,dynasty:(L=J==null?void 0:J[0])==null?void 0:L.dynasty,role:(Z=J==null?void 0:J[0])==null?void 0:Z.role,edition:se.edition||void 0}}}catch{}return{id:re,title:re,type:"work",notFound:!0}})).then(re=>{N||(F(re),W(!1))}),()=>{N=!0}},[M,t]);const be=N=>{C(N.id),Po(N.id),P(bt()),r==null||r(N)},De=N=>{Ho(N),P(bt())},_e=()=>{Oo(),P([])},Ze=N=>m.find(re=>re.type===N),ct=k&&(k.works.length>0||k.books.length>0||k.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(Yi,{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(Ui,{transport:t,value:j,onChange:Ee,onSearch:le,onEntrySelect:be}),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})]}),B&&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:B.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:B.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.collections.toLocaleString()}),B.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:B.entities.toLocaleString()})]})]})}),B.hasImage!=null&&B.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:S?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})]}):E?e.jsx("div",{style:{flex:1},children:Q?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):$.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:_e,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:$.slice(0,Y?10:3).map(N=>N.notFound?e.jsx(Vo,{id:N.id,onRemove:De,t:y},N.id):e.jsx(qn,{entry:N,selected:z===N.id,onClick:be,getConfig:Ze,onRemove:De},N.id))}),!Y&&$.length>3&&e.jsx("button",{onClick:()=>ne(!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:re,name:te,key:L})=>{const Z=k[L]??[],se=Do[L],J=k[se]??0;if(Z.length===0)return null;const je=!(w===N)&&J>Zt;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:[re," ",te,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",y.unit.items]})]}),je&&e.jsx("button",{onClick:()=>fe(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:Z.map(ge=>{if(x)return e.jsx(g.Fragment,{children:x(ge)},ge.id);const Qe=p==="card"?No:qn;return e.jsx(Qe,{entry:ge,selected:z===ge.id,onClick:be,getConfig:Ze,query:j},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:_t(y.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},No=({entry:t,selected:n,onClick:i,getConfig:r,query:s})=>{const o=D(),{convert:l}=H(),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]})]})]})]})},qn=({entry:t,selected:n,onClick:i,getConfig:r,query:s,onRemove:o})=>{const l=D(),{convert:c}=H(),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:"→"})]})},Vo=({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 Go(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 Yo({data:t}){const{convert:n}=H(),{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 Uo({alt_names:t}){const{convert:n}=H(),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 Ko({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 Jo({works:t,transport:n,onNavigate:i,renderLink:r}){const s=D(),{convert:o}=H(),l=he(),[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 k=await n.getEntriesByIds(u);let _=!0;for(let w=0;w<u.length;w++){const I=k[w];I!=null&&I.title?y.set(u[w],I.title):I!=null&&I.primary_name?y.set(u[w],I.primary_name):_=!1}if(_)return y}catch{}const m=[...u],j=8,b=new Array(j).fill(0).map(async()=>{for(;m.length;){const k=m.shift();if(!k)break;if(!y.has(k))try{if(n.getEntry){const I=await n.getEntry(k);if(I!=null&&I.title){y.set(k,I.title);continue}}const _=await n.getItem(k),w=_&&(_.title||_.primary_name)||k;y.set(k,w)}catch{y.set(k,k)}}});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:j=>{j.metaKey||j.ctrlKey||(j.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 Ki=({data:t,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:o})=>{var x;const l=D(),{convert:c}=H();let a=!1;try{a=X.extractStatus(t.id)==="draft"}catch{}const d=Go(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(Yo,{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(Uo,{alt_names:t.alt_names}),e.jsx(Ko,{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(Jo,{works:t.works,transport:n,onNavigate:i,renderLink:r})]})},Ji={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={...Ji,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Ae=({text:t,plainStrong:n,style:i,className:r})=>{const{convert:s}=H(),o=n?qo:Ji;return e.jsx("div",{className:r,style:i,children:e.jsx(po,{remarkPlugins:[uo],components:o,children:s(t)})})},Xo=["〇","一","二","三","四","五","六","七","八","九"],Xn=["","十","百","千"];function qi(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+=Xn[c]:r+=Xo[l]+Xn[c])}return r}function Xi(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 Zo={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 Qo({type:t}){const n=D();return e.jsx("span",{style:Xi(Zo[t]),children:n.indexType[t]})}function es({isDraft:t}){const n=D(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Xi(i),children:t?n.status.draft:n.status.official})}function ts({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 ye({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 Te({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 Zi({authors:t,type:n,onNavigate:i,renderLink:r}){const{convert:s}=H();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(ke,{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 ke({id:t,label:n,onNavigate:i,renderLink:r}){const s=he();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 ns({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(Qo,{type:r}),e.jsx(es,{isDraft:s}),e.jsx(ts,{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(Zi,{authors:o,type:r,onNavigate:d,renderLink:p}),c]})]})}function Qi({items:t,label:n,showMeta:i,onNavigate:r,renderLink:s}){const o=D(),{convert:l}=H();if(!t.length)return null;const[c,a]=g.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ye,{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(ke,{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(Te,{label:o.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(Te,{label:o.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(Te,{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 is({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(Qi,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function er({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(Qi,{items:t,label:r.section.emendated,onNavigate:n,renderLink:i})}function tr({label:t,items:n}){const{convert:i}=H();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ye,{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 rs({items:t}){const n=D();return e.jsx(tr,{label:n.section.aliases,items:t})}function os({items:t}){const n=D();return e.jsx(tr,{label:n.section.attachedTexts,items:t})}function ss({items:t}){const n=D(),{convert:i}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ye,{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 ls({items:t}){const n=D(),{convert:i}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ye,{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 as({items:t}){const n=D(),{convert:i}=H();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ye,{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 Zn({title:t,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:o}=H(),[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(ye,{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(ke,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function Qt({book:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=H(),[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(ke,{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(yn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function cs({ids:t,workData:n,transport:i,onNavigate:r,renderLink:s,footer:o}){const l=D(),{convert:c}=H(),[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=ds(t,f);return e.jsxs(e.Fragment,{children:[e.jsxs(ye,{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(Qt,{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(Qt,{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(Qt,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function ds(t,n){var m,j;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 k=n.node_groups[b];return k!=null&&c.has(k)},p=[],x=new Map,f=[];for(const b of t)if(!((j=n.excluded_books)!=null&&j.includes(b)))if(d(b))p.push(b);else{const k=n.node_groups[b];k?(x.has(k)||x.set(k,[]),x.get(k).push(b)):f.push(b)}if(f.length+[...x.values()].reduce((b,k)=>b+k.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,k])=>{const _=h.get(b);return{id:b,label:(_==null?void 0:_.label)??b,description:_==null?void 0:_.description,ids:k}});return f.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:f}),{useGrouping:!0,coreIds:p,groupedIds:y}}function ps({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const r=D(),{convert:s}=H(),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(ke,{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:[qi(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Zi,{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(Ae,{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(Te,{label:r.label.parentWork,children:e.jsx(ke,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function us({items:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=H();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(ke,{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:_t(r.catalog.volume,{n:o.volume_index})})]},o.id))}):null}const vn=({data:t,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:o,relatedBooksFooter:l,className:c,style:a})=>{var R,E,A,M,P,$,F,Q;const d=D(),{convert:p}=H(),[x,f]=g.useState(null),[u,h]=g.useState(!1),[y,m]=g.useState(null),[j,b]=g.useState(null),[k,_]=g.useState([]),w=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(!w||!i){b(null),_([]);return}let W=!1;const Y=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(Y?i.getItem(Y).then(ne=>{!W&&ne&&ne.type==="work"&&b(ne)}).catch(()=>{}):b(null),w.type==="book"){const ne=w;ne.contained_in&&ne.contained_in.length>0?Promise.all(ne.contained_in.map(B=>{const V=typeof B=="string"?B:B.id,U=typeof B=="string"?void 0:B.volume_index;return i.getItem(V).then(ie=>({id:V,title:ie&&ie.title||V,volume_index:U})).catch(()=>({id:V,title:V,volume_index:U}))})).then(B=>{W||_(B)}):_([])}else _([]);return()=>{W=!0}},[w,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(!w)return null;if(w.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Ki,{data:w,transport:i,onNavigate:r,renderLink:s,headerExtra:o})});const I=w.type==="book"?w:null,S=w.type==="collection"?w:null,T=w.type==="work"?w:null;let z=!1;try{z=X.extractStatus(w.id)==="draft"}catch{}let C="";w.measure_info?C=p(w.measure_info):(R=w.juan_count)!=null&&R.number?C=qi(w.juan_count.number)+d.unit.juan:(E=w.juan_count)!=null&&E.description&&(C=p(w.juan_count.description));const v=[];return(A=w.publication_info)!=null&&A.year&&v.push(e.jsx(Te,{label:d.label.year,children:w.publication_info.year},"year")),(M=w.current_location)!=null&&M.name&&v.push(e.jsx(Te,{label:d.label.currentLocation,children:p(w.current_location.name)},"loc")),(P=w.page_count)!=null&&P.description&&v.push(e.jsx(Te,{label:d.label.pageCount,children:w.page_count.description},"page")),I!=null&&I.edition&&v.push(e.jsx(Te,{label:d.label.edition,children:p(I.edition)},"ver")),T!=null&&T.parent_work&&v.push(e.jsx(Te,{label:d.label.parentWork,children:e.jsx(ke,{id:T.parent_work.id,label:p(T.parent_work.title),onNavigate:r,renderLink:s})},"pw")),T!=null&&T.parent_works&&T.parent_works.length>0&&!T.parent_work&&v.push(e.jsx(Te,{label:d.label.parentWork,children:T.parent_works.map((W,Y)=>e.jsxs("span",{children:[Y>0&&"、",e.jsx(ke,{id:W,onNavigate:r,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(ns,{id:w.id,title:p(w.title),edition:w.edition?p(w.edition):void 0,type:w.type,isDraft:z,authors:w.authors,volumeText:C,meta:v,headerExtra:o,onNavigate:r,renderLink:s}),(($=w.description)==null?void 0:$.text)&&e.jsx(Ae,{text:w.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),w.appendix&&w.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:w.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(Ae,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},Y))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:d.section.containedIn}),e.jsx(us,{items:k,onNavigate:r,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:d.section.belongsToWork}),e.jsx(ps,{workData:j,onNavigate:r,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(ss,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(rs,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(os,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(is,{items:w.indexed_by,onNavigate:r,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(er,{items:w.emendated_by,onNavigate:r,renderLink:s}),w.resources&&w.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:d.section.resources}),e.jsx(yn,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(I==null?void 0:I.location_history)&&I.location_history.length>0&&e.jsx(ls,{items:I.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(as,{items:S.history}),(I==null?void 0:I.related_books)&&I.related_books.length>0&&e.jsx(Zn,{title:d.section.relatedVersions,ids:I.related_books,transport:i,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Zn,{title:d.section.containedBooks,ids:S.books,transport:i,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ye,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.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(ke,{id:W.id,label:p(W.title),onNavigate:r,renderLink:s})},W.id))})]}),(((F=T==null?void 0:T.books)==null?void 0:F.length)||0)+(((Q=T==null?void 0:T.collections)==null?void 0:Q.length)||0)>0&&e.jsx(cs,{ids:[...(T==null?void 0:T.books)||[],...(T==null?void 0:T.collections)||[]],workData:T,transport:i,onNavigate:r,renderLink:s,footer:l}),(T==null?void 0:T.related_works)&&T.related_works.length>0&&(()=>{const W=[],Y=T.related_works.filter(G=>G.relation==="part_of"),ne=T.related_works.filter(G=>G.relation==="has_part"),B=T.related_works.filter(G=>G.relation==="has_adaptation"),V=T.related_works.filter(G=>G.relation==="text_carried_by"),U=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ie=T.related_works.filter(G=>!G.relation||!U.has(G.relation));return Y.length>0&&W.push({label:d.section.belongsToWork,items:Y}),ne.length>0&&W.push({label:d.section.containedWorks,items:ne}),B.length>0&&W.push({label:d.section.adaptations,items:B}),V.length>0&&W.push({label:d.section.derivativeWorks,items:V}),ie.length>0&&W.push({label:d.section.relatedWorks,items:ie}),W.map(G=>e.jsxs("div",{children:[e.jsxs(ye,{children:[G.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",G.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:G.items.map(K=>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(ke,{id:K.id,label:p(K.title),onNavigate:r,renderLink:s})},K.id))})]},G.label))})()]})};function xs({data:t}){const n=D(),{convert:i}=H(),{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 fs({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:Qn(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:Qn(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 Qn(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 gs({id:t,label:n,onNavigate:i,renderLink:r}){const s=he();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 ms(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 ei({book:t,onNavigate:n,renderLink:i,showVolumes:r}){const s=D(),{convert:o}=H(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?ms(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(gs,{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 jn=({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,j]=g.useState(""),b=t||a;g.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let S=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(T=>{S||(T?d(T):u(c.catalog.notFound))}).catch(T=>{S||u(T instanceof Error?T.message:c.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,i,c]);const k=(b==null?void 0:b.sections)&&b.sections.length>0,_=g.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const S=b.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(S).size<S.length},[b]),w=g.useMemo(()=>{if(!b)return[];let S=b.books;if(h&&(S=S.filter(T=>T.section===h)),m.trim()){const T=m.trim().toLowerCase();S=S.filter(z=>z.title.toLowerCase().includes(T)||z.sub_items&&z.sub_items.some(C=>C.toLowerCase().includes(T))||z.edition&&z.edition.toLowerCase().includes(T))}return S},[b,h,m]),I=g.useMemo(()=>{if(!_)return null;const S=[],T=new Map;for(const C of w){if(!C.volumes||C.volumes.length===0)continue;const v=C.volumes[0];T.has(v)||T.set(v,[]),T.get(v).push(C)}const z=[...T.keys()].sort((C,v)=>C-v);for(const C of z)S.push({volume:C,books:T.get(C)});return S},[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(xs,{data:b}),k&&e.jsx(fs,{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:S=>j(S.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:[w.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[I?I.map((S,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:_t(c.catalog.volume,{n:S.volume})}),S.books.map((z,C)=>e.jsx(ei,{book:z,onNavigate:r,renderLink:s,showVolumes:z.volumes.length>1},`${S.volume}-${C}`))]},`${S.volume}-${T}`)):w.map((S,T)=>e.jsx(ei,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},T)),w.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)})},xe=6,Rt=7,hs=({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,j=f.current;if(!m||!j)return;const b=m.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,w=document.documentElement.clientWidth;let I=i;i==="top"&&b.top-k.height-Rt<8&&(I="bottom"),i==="bottom"&&b.bottom+k.height+Rt>_-8&&(I="top");const S=I==="top"?b.top-k.height-Rt:b.bottom+Rt;let T=b.left+b.width/2-k.width/2;T=Math.max(8,Math.min(T,w-k.width-8)),d({left:T,top:S,placement:I})},[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&&xo.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:-xe,width:0,height:0,...a.placement==="top"?{bottom:-xe,borderTop:`${xe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${xe}px solid transparent`,borderRight:`${xe}px solid transparent`}:{top:-xe,borderBottom:`${xe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${xe}px solid transparent`,borderRight:`${xe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${xe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${xe-1}px solid transparent`,borderRight:`${xe-1}px solid transparent`}:{top:-5,borderBottom:`${xe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${xe-1}px solid transparent`,borderRight:`${xe-1}px solid transparent`}}})]})]}),document.body)]})},nr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],bs={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function pe(t){return bs[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},ir={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Dt(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 ys(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 vs=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,ti={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Sn(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(ti))if(n.startsWith(s))return ti[s];const i=pe(n);if(Ge[i]!=null)return i;const r=$e(n);if(r&&n.length<=r.length+1)return pe(r)}function Ve(t,n){if(n){const i=ir[`${n}|${t}`];if(i!=null)return i}return it[t]}const js=1911;function Ss(t){const n=it[t];if(n==null)return;const i=ze[t];let r;for(const[s,o]of Object.entries(it))ze[s]===i&&o>n&&(r==null||o<r)&&(r=o);return r!=null?r-1:void 0}const ks={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Ft(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=ks[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 $e(t){for(const n of nr)if(t.startsWith(n))return n}const ze={};{const t=(n,i)=>{for(const r of i)ze[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&&ze[r]&&ze[r]!==i&&ir[`${i}|${r}`]==null))return r}function Ct(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=$e(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=Dt(s);if(d)return{era:ys(d.from),reign:"",source:"publication"};const p=$e(s)??Sn(s)??((a=nt.find(u=>u.pattern.test(s)))==null?void 0:a.era)??"",x=Ye(s,p)??"",f=p||(x?ze[x]??"":"");if(f||x)return{era:pe(f),reign:x,source:"publication"}}const o=t.edition||t.title||"";if(o){const d=$e(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 Nt(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=Dt(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&&($e(u)||Sn(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 k=parseInt(h[1],10);if(k>=100&&k<=2100)return k}const y=f.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(y){const k=$e(f);if(!k||pe(k)==="民國"){const w=Ft(y[1]);if(w!=null&&w>=1&&w<=120)return js+w}}const m=$e(f)??((p=nt.find(k=>k.pattern.test(f)))==null?void 0:p.era),j=m?pe(m):void 0,b=Ye(f,j)??($e(f)||(x=nt.find(k=>k.pattern.test(f)))==null?void 0:x.reign);if(b){const k=Ve(b,j);if(k==null)continue;const _=f.indexOf(b),w=_>=0?f.slice(_+b.length):"",I=w.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??w.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),S=I?Ft(I[1]):void 0;return k+(S?S-1:0)}}}function kn(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=an[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=Dt(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=an[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=$e(f)??Sn(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&&ze[m]&&ze[m]!==h||Ve(m,h)!=null&&y.push(m));if(y.length===0){const m=f.match(/([一-鿿])([一-鿿])[間间]/);if(m&&h){for(const j of[m[1],m[2]])for(const b of Object.keys(it))if(ze[b]===h&&!(b[0]!==j&&b[b.length-1]!==j)&&Ve(b,h)!=null){y.push(b);break}}}if(y.length>0){const m=y.map(_=>Ve(_,h)).filter(_=>_!=null),j=Math.min(...m),b=y.reduce((_,w)=>Ve(_,h)>=Ve(w,h)?_:w),k=Ss(b)??en(h??"")??Math.max(...m);return{from:j,to:k>j?k:en(h??ze[b]??"")??j}}if(h&&Ge[h]!=null)return{from:Ge[h],to:en(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},ws=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],_s=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,ni=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function ii(t,n){for(const i of nr){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?Ft(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 Cs(t){var j,b,k,_,w;const n=Ct(t),i=((j=t.publication_info)==null?void 0:j.year)??"",r=i?Dt(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"&&vs.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=Nt(t);const f=x==null?kn(t):void 0;let u;n.source==="publication"&&(a||ni.test(i))?u="uncertain":n.source==="lineage"||n.source==="publication"?u="attested":ni.test(s)||!n.reign&&x==null?u="uncertain":u="inferred";const h=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((k=t.lineage)==null?void 0:k.year_text)??((_=t.lineage)==null?void 0:_.year)??""}」`:`出版著錄「${((w=t.publication_info)==null?void 0:w.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 I=l.match(/[、,,]\s*([宋元明清])/);I&&I[1]!==y.era&&(y.laterRepair={era:I[1]})}if(!y.laterRepair&&_s.test(s)){const I=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);I&&I[1]!==n.era&&(y.laterRepair={era:I[1]})}const m=ws.find(I=>I.re.test(s));if(m){const I=s.search(m.re),S=s.slice(I),T=ii(S,n.era)??ii(s,n.era);T&&(y.basedOn={era:T.era,reign:T.reign,year:T.year,relation:m.relation})}return y}const an={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function en(t){return an[t]}function rr(t){const n=Nt(t);if(n!=null)return n;const i=kn(t);if(i)return i.from;const r=Ct(t).era;return r?Ge[r]:void 0}const ri=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function cn(t){const n=ri.indexOf(t);return n===-1?ri.length:n}function or(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 Vt(t,n){const i=gn(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 wn(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=mn(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 Is(t,n){if(wn(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 sr(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:Ct(t),year:Nt(t),sortYear:rr(t),images:r,holders:s,locationName:(o=t.current_location)==null?void 0:o.name,important:Ts(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:r.length>0}}function Ts(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 lr(t,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!r.has(a.id)).map(a=>sr(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)=>cn(a)-cn(d));return{rows:o,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function zs(t,n){var m,j;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 k=n.node_groups[b];return k!=null&&c.has(k)},p=[],x=new Map,f=[];for(const b of t)if(!((j=n.excluded_books)!=null&&j.includes(b)))if(d(b))p.push(b);else{const k=n.node_groups[b];k?(x.has(k)||x.set(k,[]),x.get(k).push(b)):f.push(b)}if(f.length+[...x.values()].reduce((b,k)=>b+k.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,k])=>{const _=h.get(b);return{id:b,label:(_==null?void 0:_.label)??b,description:_==null?void 0:_.description,ids:k}});return f.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:f}),{useGrouping:!0,coreIds:p,groupedIds:y}}const ar=["撰","編","注","校","譯","繪","其他"],Rs=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function _n(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of Rs)if(r.test(n))return i;return"其他"}function Cn(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function cr(t){const n=new Map;for(const r of t){const s=_n(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const r of ar){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function dr(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:yt(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 yt(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 In(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 Es=["〇","一","二","三","四","五","六","七","八","九"],oi=["","十","百","千"];function pr(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+=oi[c]:r+=Es[l]+oi[c])}return r}function Je(t,n="卷"){var r,s;const i=t;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?pr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function ur(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 xr=1e3,Bs="(max-width: 719px)",fr=`
|
|
4
2
|
.bim-d-page {
|
|
5
3
|
background: var(--bim-page-bg, #fbf9f3);
|
|
6
4
|
color: var(--bim-ink, #2a231c);
|
|
@@ -9,7 +7,7 @@
|
|
|
9
7
|
padding-bottom: 64px;
|
|
10
8
|
}
|
|
11
9
|
.bim-d-main {
|
|
12
|
-
max-width: ${
|
|
10
|
+
max-width: ${xr}px;
|
|
13
11
|
margin: 0 auto;
|
|
14
12
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
15
13
|
}
|
|
@@ -37,7 +35,7 @@
|
|
|
37
35
|
align-items: start; margin-bottom: 48px; }
|
|
38
36
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
39
37
|
|
|
40
|
-
@media ${
|
|
38
|
+
@media ${Bs} {
|
|
41
39
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
42
40
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
43
41
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -48,4 +46,6 @@
|
|
|
48
46
|
gap: 4px 14px; font-size: 12px; }
|
|
49
47
|
.bim-d-h1 { font-size: 32px !important; }
|
|
50
48
|
}
|
|
51
|
-
`;function Lt({children:t,style:n}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:Eo}),e.jsx("div",{className:"bim-d-main",children:t})]})}function Bo({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 Tn({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 Lo({items:t}){const n=me();return e.jsx(e.Fragment,{children:t.map((i,o)=>{const s=o===t.length-1,r=o>0&&e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${o}`),a=i.id?n(i.id):i.href,c=s||!i.onClick&&!a?e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:i.label},o):e.jsx("a",{href:a??"#",onClick:i.onClick?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:i.label},o);return e.jsxs(f.Fragment,{children:[r,c]},o)})})}function Wo({title:t,subtitle:n,aside:i,secondLine:o}){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})]}),o&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:"var(--bim-quiet-fg, #5b4f40)"},children:o})]})}function _t({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 Ct({items:t,horizontal:n}){const{convert:i}=H();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((o,s)=>e.jsxs("div",{title:o.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(o.label)}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:o.value})]},s))}):null}function pe({glyph:t,tone:n,title:i,count:o,actions:s,id:r}){const{convert:a}=H();return e.jsxs("div",{id:r,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(Tn,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(i)}),o!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:o})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function ze({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function Pe({label:t,active:n,onClick:i,dashed:o}){const{convert:s}=H();return e.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!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 Nt({label:t,onClick:n}){const{convert:i}=H();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 He({label:t,onClick:n,inline:i}){const{convert:o}=H();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:o(t)})}function It({children:t,href:n,onClick:i,title:o}){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:o,onClick:i?r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i())}:void 0,style:s,children:t}):e.jsx("span",{title:o,style:s,children:t})}function Vt({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function $o({volumes:t,unit:n="冊",max:i=60}){const[o,s]=f.useState(!1);if(!t.length)return null;const r=o?t:t.slice(0,i);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[r.map(a=>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:a},a)),!o&&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 Ke({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function Gt({spec:t}){const{convert:n}=H();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 Ut({no:t,main:n,meta:i,spec:o}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o.leadWidth}px 1fr ${o.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:o.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Yt(t){return String(t+1).padStart(2,"0")}function it(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function Ao({open:t,onToggle:n,main:i,action:o,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}),o]}),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 Wt({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 an({title:t,tag:n,children:i}){const{convert:o}=H();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:o(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:o(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function Mo({name:t,note:n,href:i,extra:o}){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})]}),r={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:r,children:s}):e.jsx("div",{style:r,children:s}),o]})}function ot({item:t,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{convert:s}=H(),[r,a]=f.useState(!1),c=un(t),l=i&&!!c&&c.expected>0,d=(t.url?yt(t.url):void 0)||s(t.name),p=n?aa(t,n):"",x=p?`${d}(${p})`:d;return e.jsx(Mo,{name:x,note:wn(t)||o,href:At(t),extra:l?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>a(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:r?"收起分冊":`展開 ${c.expected} 冊`}),r&&e.jsx(Fo,{item:t})]}):void 0})}function Fo({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 o=n.status==="missing";return n.url&&!o?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:o?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:o?"line-through":void 0},children:n.volume},i)})})}function zn({label:t,items:n}){const{convert:i}=H();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((o,s)=>e.jsx(It,{children:i(o)},s))]}):null}function Po({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(zn,{label:i.label,items:i.items},i.label))}):null}function jt(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ho({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 rt({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 we({id:t,label:n,onNavigate:i,renderLink:o,style:s,dense:r}){const a=me();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:r})}):e.jsx("a",{href:a(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function cn({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 ft={versions:12,catalogs:8,chips:12},Oo={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Do=({data:t,transport:n,onNavigate:i,renderLink:o,lineageAction:s})=>{var b,R,E,A,M,P,$,F,Q,W,U,ne;const r=D(),{convert:a}=H(),c=f.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[l,d]=f.useState(new Map),[p,x]=f.useState(!1),[g,u]=f.useState(""),[h,v]=f.useState(!1),[m,j]=f.useState("default"),y=p||!!g||h||m==="year",k=f.useMemo(()=>y?c:c.slice(0,ft.versions),[c,y]);f.useEffect(()=>{if(!n||k.length===0)return;const B=k.filter(Y=>!l.has(Y));if(B.length===0)return;let V=!1;return Promise.all(B.map(Y=>n.getItem(Y).then(ie=>{const G=ie??{};return[Y,{id:Y,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[Y,{id:Y}]))).then(Y=>{V||d(ie=>{const G=new Map(ie);for(const[K,de]of Y)G.set(K,de);return G})}),()=>{V=!0}},[n,k,l]);const _=f.useMemo(()=>c.map(B=>l.get(B)??{id:B}),[c,l]),w=f.useMemo(()=>wo(_,t.version_graph,{era:g,scanOnly:h,sort:m}),[_,t.version_graph,g,h,m]),T=p?w.rows:w.rows.slice(0,ft.versions),S=f.useMemo(()=>Dt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),I=f.useMemo(()=>So((t.related_works||[]).map(B=>({id:B.id,title:B.title,relation:B.relation}))),[t.related_works]),z=f.useMemo(()=>{var G,K,de,Re;const B=[],V=(K=(G=t.authors)==null?void 0:G[0])==null?void 0:K.dynasty;V&&B.push({label:"成書",value:a(V)});const Y=Ye(t,r.unit.juan);if(Y){const le=(de=t.juan_count)==null?void 0:de.description;B.push({label:"卷帙",value:a(Y),title:le?a(le):void 0})}const ie=w.allRows.filter(le=>le.sortYear!=null);if(ie.length>0){const le=ie.reduce((xe,he)=>xe.sortYear<=he.sortYear?xe:he);le.era.era&&B.push({label:"最早存世刻本",value:`${le.era.era}${le.era.reign?" "+le.era.reign:""}`,title:le.era.source==="edition"?"據版本題名推斷":void 0})}return(Re=t.indexed_by)!=null&&Re.length&&B.push({label:"著錄",value:`${t.indexed_by.length} ${r.unit.bu}`}),B},[t,a,r,w.allRows,y,c.length]),C=c.length===0&&S.buckets.length===0&&S.mirrors.length===0&&!((b=t.indexed_by)!=null&&b.length)&&!((R=t.emendated_by)!=null&&R.length)&&I.length===0&&!((E=t.description)!=null&&E.text);return e.jsxs(e.Fragment,{children:[e.jsxs(_t,{facts:z.length?e.jsx(Ct,{items:z}):void 0,children:[((A=t.description)==null?void 0:A.text)&&e.jsxs(e.Fragment,{children:[e.jsx(We,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(M=t.description.sources)!=null&&M.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(B=>a(B)).join(" · ")}):null]}),(P=t.appendix)==null?void 0:P.map((B,V)=>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:a(B.title)}),e.jsx(We,{text:B.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},V)),e.jsx(Po,{rows:[{label:r.section.aliases,items:jt(t.additional_titles)},{label:r.section.attachedTexts,items:jt(t.attached_texts)},{label:r.section.appendix,items:(t.additional_works||[]).map(B=>B.book_title+(B.n_juan!=null?` ${B.n_juan}${r.unit.juan}`:""))}]})]}),c.length>0&&e.jsxs(ze,{children:[e.jsx(pe,{glyph:"版",title:r.section.relatedVersions,count:w.rows.length===w.allRows.length?`${w.allRows.length} 種`:`${w.allRows.length} 種 · 當前 ${w.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(Pe,{label:"僅看有影印",active:h,dashed:!0,onClick:()=>{v(B=>!B),x(!1)}}),e.jsx(Nt,{label:m==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>j(B=>B==="default"?"year":"default")})]})}),w.allRows.length>=6&&w.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(Pe,{label:r.catalog.all,active:!g,onClick:()=>{u(""),x(!1)}}),w.eras.map(B=>e.jsx(Pe,{label:B,active:g===B,onClick:()=>{u(B),x(!1)}},B))]}),e.jsxs(Ke,{children:[e.jsx(Gt,{spec:Oo}),T.map((B,V)=>e.jsx(ma,{row:B,no:V,onNavigate:i,renderLink:o},B.id)),T.length===0&&e.jsx(rt,{children:g||h?"當前篩選下沒有版本":"暫無版本著錄"})]}),w.rows.length>T.length&&e.jsx(He,{label:`展開其餘 ${w.rows.length-T.length} 種版本`,onClick:()=>x(!0)}),w.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(S.buckets.length>0||S.mirrors.length>0)&&e.jsxs(ze,{children:[e.jsx(pe,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[S.mirrors.map(B=>e.jsx(an,{title:a(B.label),tag:B.description?a(B.description):void 0,children:B.items.map((V,Y)=>e.jsx(ot,{item:V,siblings:B.items},`${V.id||V.url||V.name}-${Y}`))},B.key)),S.buckets.map(B=>e.jsx(an,{title:fa[B.key],tag:ga[B.key],children:B.items.map((V,Y)=>e.jsx(ot,{item:V,siblings:B.items},`${V.id||V.url||V.name}-${Y}`))},B.key))]})]}),($=t.indexed_by)!=null&&$.length||(F=t.emendated_by)!=null&&F.length?e.jsxs("div",{className:(Q=t.emendated_by)!=null&&Q.length?"bim-d-pair":void 0,style:(W=t.emendated_by)!=null&&W.length?void 0:{marginBottom:48},children:[(U=t.indexed_by)!=null&&U.length?e.jsx(ji,{id:"catalogs",glyph:"目",title:r.section.indexed,items:t.indexed_by,unit:r.unit.bu,cap:ft.catalogs,showMeta:!0,t:r,convert:a,onNavigate:i,renderLink:o}):null,(ne=t.emendated_by)!=null&&ne.length?e.jsx(ji,{id:"studies",glyph:"考",title:r.section.emendated,items:t.emendated_by,unit:r.unit.bu,cap:ft.catalogs,t:r,convert:a,onNavigate:i,renderLink:o}):null]}):null,I.map(B=>e.jsx(ha,{glyph:B.key==="derivative"?"續":"叢",title:r.section[B.labelKey]??r.section.relatedWorks,items:B.items,convert:a,onNavigate:i,renderLink:o},B.key)),C&&e.jsxs(ze,{style:{marginBottom:0},children:[e.jsx(pe,{glyph:"著",title:r.section.relatedVersions}),e.jsx(Ke,{children:e.jsx(rt,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},fa={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},ga={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function ma({row:t,no:n,onNavigate:i,renderLink:o}){const{convert:s}=H(),r=[t.era.era,t.era.reign].filter(Boolean).join(" · "),a=t.era.source==="edition";return e.jsx(Ut,{no:Yt(n),spec:Oo,main:e.jsx(we,{id:t.id,label:s(t.name),onNavigate:i,renderLink:o,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:a?"據版本題名推斷":void 0,children:r||e.jsx(it,{})}),e.jsx(vi,{items:t.images,convert:s}),e.jsx(vi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function vi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(it,{});if(t.length===1){const a=t[0],c=(a.url?yt(a.url):void 0)||n(a.name),l=At(a);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:l?e.jsx(cn,{href:l,children:c}):c})}const o=t[0],s=(o.url?yt(o.url):void 0)||n(o.name),r=At(o);return e.jsxs("span",{style:{minWidth:0},children:[r?e.jsx(cn,{href:r,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 ji({id:t,glyph:n,title:i,items:o,unit:s,cap:r,showMeta:a,t:c,convert:l,onNavigate:d,renderLink:p}){const[x,g]=f.useState({}),[u,h]=f.useState(!1),v=o.length>0&&o.every((y,k)=>x[k]),m=f.useCallback(()=>{g(v?{}:Object.fromEntries(o.map((y,k)=>[k,!0])))},[v,o]),j=u?o:o.slice(0,r);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(pe,{glyph:n,tone:"ink",title:i,count:`${o.length} ${s}`,actions:e.jsx(Nt,{label:v?"收起全部":"+ 展開提要",onClick:m})}),e.jsx(Ke,{children:j.map((y,k)=>{const _=y;return e.jsxs(Ao,{open:!!x[k],onToggle:()=>g(w=>({...w,[k]:!w[k]})),main:e.jsxs(e.Fragment,{children:[_.source_bid?e.jsx(we,{id:_.source_bid,label:l(_.source),onNavigate:d,renderLink:p,dense:!0}):l(_.source),a&&_.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(_.section)})]}),action:_.source_bid?e.jsx(we,{id:_.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:[a&&(_.title_info||_.author_info||_.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:[_.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",l(_.title_info)]}),_.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",l(_.author_info)]}),_.edition&&e.jsxs("span",{children:[c.label.edition," ",l(_.edition)]})]}),_.summary&&e.jsx(Wt,{children:l(_.summary)}),_.comment&&e.jsx(Wt,{label:c.section.comment,children:l(_.comment)}),_.additional_comment&&e.jsx(Wt,{label:c.section.additionalComment,children:l(_.additional_comment)}),a&&_.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:_.page})]},k)})}),o.length>j.length&&e.jsx(He,{label:`展開其餘 ${o.length-j.length} ${s}`,onClick:()=>h(!0)})]})}function ha({glyph:t,title:n,items:i,convert:o,onNavigate:s,renderLink:r}){const[a,c]=f.useState(!1),l=a?i:i.slice(0,ft.chips);return e.jsxs(ze,{style:{marginBottom:44},children:[e.jsx(pe,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Vt,{children:[l.map(d=>e.jsx(It,{children:e.jsx(we,{id:d.id,label:o(d.title),onNavigate:s,renderLink:r,dense:!0,style:{color:"inherit"}})},d.id)),i.length>l.length&&e.jsx(He,{inline:!0,label:`更多 ${i.length-l.length} 種`,onClick:()=>c(!0)})]})]})}const ba=8,No=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var k,_,w,T;const s=D(),{convert:r}=H(),[a,c]=f.useState(null),[l,d]=f.useState(new Map),[p,x]=f.useState([]),[g,u]=f.useState(!1);f.useEffect(()=>{if(!n||!t.work_id){c(null);return}let S=!1;return n.getItem(t.work_id).then(I=>{!S&&I&&I.type==="work"&&c(I)}).catch(()=>{}),()=>{S=!0}},[n,t.work_id]),f.useEffect(()=>{const S=t.contained_in||[];if(!n||S.length===0){d(new Map);return}let I=!1;return Promise.all(S.map(z=>{const C=typeof z=="string"?z:z.id;return n.getItem(C).then(b=>[C,b]).catch(()=>[C,null])})).then(z=>{if(I)return;const C=new Map;for(const[b,R]of z)R&&C.set(b,R);d(C)}),()=>{I=!0}},[n,t.contained_in]);const h=f.useMemo(()=>{const S=new Set([...(a==null?void 0:a.books)||[],...t.related_books||[]]);return S.delete(t.id),[...S]},[a==null?void 0:a.books,t.related_books,t.id]);f.useEffect(()=>{if(!n||h.length===0){x([]);return}const S=g?h:h.slice(0,ba);let I=!1;return Promise.all(S.map(z=>n.getItem(z).then(C=>({id:z,title:C==null?void 0:C.title,edition:C==null?void 0:C.edition})).catch(()=>({id:z})))).then(z=>{I||x(z)}),()=>{I=!0}},[n,h,g]);const v=f.useMemo(()=>Dt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),m=f.useMemo(()=>{var E,A,M;const S=[],I=wt(t),z=zo(t);z&&S.push({label:"版本類型",value:z,title:(E=t.lineage)!=null&&E.category?void 0:"據版本題名推斷"}),(I.era||I.reign)&&S.push({label:"刊寫年代",value:[I.era,I.reign].filter(Boolean).join(" "),title:I.source==="edition"?"據版本題名推斷":void 0});const C=(t.contained_in||[]).flatMap(P=>typeof P=="string"?[]:bt(P.volume_index));C.length&&(S.push({label:"冊數",value:`${C.length} ${s.unit.volume}`}),S.push({label:"冊次",value:`第 ${In(C,s.unit.volume)} ${s.unit.volume}`}));const b=Ye(t,s.unit.juan);b&&S.push({label:"卷帙",value:r(b)});const R=(t.resources||[]).filter(P=>(P.types||(P.type?[P.type]:[])).includes("physical"));return R.length?S.push({label:"存藏",value:R.slice(0,2).map(P=>r(P.name)).join("、")+(R.length>2?` 等 ${R.length} 處`:"")}):(A=t.current_location)!=null&&A.name&&S.push({label:"存藏",value:r(t.current_location.name)}),(M=t.page_count)!=null&&M.description&&S.push({label:s.label.pageCount,value:t.page_count.description}),S},[t,r,s]),j=!!((k=t.description)!=null&&k.text),y=(t.contained_in||[]).some(S=>typeof S!="string"&&bt(S.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(_t,{facts:m.length?e.jsx(Ct,{items:m,horizontal:!j}):void 0,children:j?e.jsx(We,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),(t.contained_in||[]).length>0&&e.jsxs(ze,{children:[e.jsx(pe,{glyph:"收",title:s.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((S,I)=>{var E,A;const z=typeof S=="string"?S:S.id,C=typeof S=="string"?[]:bt(S.volume_index),b=l.get(z),R=((E=b==null?void 0:b.books)==null?void 0:E.length)||((A=b==null?void 0:b.contained_works)==null?void 0:A.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(we,{id:z,label:b?r(b.title):z,onNavigate:i,renderLink:o})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[R>0&&`全 ${R} ${s.unit.bu}`,R>0&&C.length>0&&" · ",C.length>0&&`本書佔 ${C.length} ${s.unit.volume}`]})]}),C.length>0&&e.jsx($o,{volumes:C,unit:s.unit.volume})]},`${z}-${I}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[a&&e.jsxs("section",{children:[e.jsx(pe,{glyph:"作",tone:"ink",title:s.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(we,{id:a.id,label:r(a.title),onNavigate:i,renderLink:o})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[r(Ye(a,s.unit.juan)),(_=a.authors)==null?void 0:_.map(S=>{const I=Cn(S.role);return`${S.dynasty?`〔${r(S.dynasty)}〕`:""}${r(S.name)}${I?" "+r(I):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((w=a.description)==null?void 0:w.text)&&e.jsx(We,{text:a.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(zn,{label:s.section.aliases,items:[...jt(t.additional_titles),...jt(t.attached_texts)]})})]})]}),(v.buckets.length>0||v.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(pe,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[v.mirrors.map(S=>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:r(S.label)}),S.items.map((I,z)=>e.jsx(ot,{item:I,showVolumes:!y},`${I.id||I.url||I.name}-${z}`))]},S.key)),v.buckets.flatMap(S=>S.items).map((S,I)=>e.jsx(ot,{item:S,showVolumes:!y},`${S.id||S.url||S.name}-${I}`))]})]})]}),(T=t.location_history)!=null&&T.length?e.jsxs(ze,{children:[e.jsx(pe,{glyph:"藏",tone:"ink",title:s.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((S,I)=>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:r(S.name)}),S.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r(S.description)})]},I))})]}):null,h.length>0&&e.jsxs(ze,{style:{marginBottom:0},children:[e.jsx(pe,{glyph:"版",tone:"ink",title:s.relation.siblingVersions,count:`${h.length} 種`,actions:a?e.jsx(we,{id:a.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:o,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Vt,{children:[p.map(S=>e.jsx(It,{children:e.jsx(we,{id:S.id,label:r(S.edition||S.title||S.id),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},S.id)),h.length>p.length&&e.jsx(He,{inline:!0,label:`更多 ${h.length-p.length} 種`,onClick:()=>u(!0)})]})]})]})},Si={titles:16,works:16},Vo=({data:t,catalog:n,onNavigate:i,renderLink:o,catalogAction:s})=>{var z,C;const r=D(),{convert:a}=H(),[c,l]=f.useState(""),[d,p]=f.useState(!1),[x,g]=f.useState(!1),u=f.useMemo(()=>Io(t,n),[t,n]),h=f.useMemo(()=>c?u.rows.filter(b=>b.section===c):u.rows,[u.rows,c]),v=d?h:h.slice(0,Si.titles),m=f.useMemo(()=>Dt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),j=t.contained_works||[],y=new Set(u.rows.map(b=>b.id).filter(Boolean)),k=j.length>0&&!j.every(b=>y.has(b.id)),_=(()=>{const b=u.rows.map(R=>R.edition).filter(Boolean);return b.length>1&&new Set(b).size===1})(),w=x?j:j.slice(0,Si.works),T=u.sections.length>0,S=f.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...T?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[T]),I=f.useMemo(()=>{var A,M,P,$;const b=[];t.subtype&&b.push({label:r.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(A=t.publication_info)!=null&&A.details&&b.push({label:"刊印",value:a(t.publication_info.details)}),(M=t.publication_info)!=null&&M.year&&b.push({label:"年代",value:t.publication_info.year});const R=((P=t.books)==null?void 0:P.length)||j.length,E=Ye(t,r.unit.juan);return(R||E)&&b.push({label:"種數 / 卷數",value:[R?`${R} ${r.unit.bu}`:"",a(E)].filter(Boolean).join(" · "),title:($=t.juan_count)!=null&&$.description?a(t.juan_count.description):void 0}),u.totalVolumes&&b.push({label:"全帙冊數",value:`${u.totalVolumes} ${r.unit.volume}`}),b},[t,j.length,u.totalVolumes,a,r]);return e.jsxs(e.Fragment,{children:[e.jsxs(_t,{facts:I.length?e.jsx(Ct,{items:I}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(We,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(C=t.history)!=null&&C.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((b,R)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",a(b)]},R))}):null]}),u.rows.length>0&&e.jsxs(ze,{children:[e.jsx(pe,{glyph:"目",title:r.section.containedBooks,count:h.length===u.rows.length?`${r.catalog.contains} ${u.rows.length} ${r.unit.items}`:`${u.rows.length} ${r.unit.items} · 當前 ${h.length} ${r.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,T&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{label:r.catalog.all,active:!c,onClick:()=>{l(""),p(!1)}}),u.sections.map(b=>e.jsx(Pe,{label:b,active:c===b,onClick:()=>{l(b),p(!1)}},b))]})]})}),e.jsxs(Ke,{children:[e.jsx(Gt,{spec:S}),v.map((b,R)=>{var E;return e.jsx(Ut,{no:Yt(R),spec:S,main:e.jsxs(e.Fragment,{children:[b.id?e.jsx(we,{id:b.id,label:a(b.title),onNavigate:i,renderLink:o,dense:!0}):e.jsx("span",{children:a(b.title)}),(E=b.subItems)!=null&&E.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",b.subItems.map(A=>a(A)).join("、"),")"]}):null,b.edition&&!_&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(b.edition)})]}),meta:e.jsxs(e.Fragment,{children:[T&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:b.section?b.section.endsWith("部")?b.section:`${b.section}部`:e.jsx(it,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:b.volumes.length>0?`第 ${In(b.volumes,r.unit.volume)} ${r.unit.volume}`:b.expected!=null?`${b.found??0}/${b.expected} ${r.unit.volume}`:e.jsx(it,{})})]})},`${b.id??b.title}-${R}`)}),v.length===0&&e.jsx(rt,{children:r.catalog.noMatch})]}),h.length>v.length&&e.jsx(He,{label:`展開其餘 ${h.length-v.length} ${r.unit.items}子目`,onClick:()=>p(!0)})]}),(m.buckets.length>0||k)&&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(pe,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[...m.mirrors.flatMap(b=>b.items),...m.buckets.flatMap(b=>b.items)].map((b,R)=>e.jsx(ot,{item:b,fallbackNote:b.details?a(b.details):void 0},`${b.id||b.url||b.name}-${R}`))})]}),k&&e.jsxs("section",{children:[e.jsx(pe,{glyph:"叢",tone:"ink",title:r.section.containedWorks,count:`${j.length} 種`}),e.jsxs(Vt,{children:[w.map(b=>e.jsx(It,{children:e.jsx(we,{id:b.id,label:a(b.title),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},b.id)),j.length>w.length&&e.jsx(He,{inline:!0,label:`更多 ${j.length-w.length} 種`,onClick:()=>g(!0)})]})]})]})]})},ya=16,ki={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},en=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function wi(t){if(!t)return en.length;const n=en.indexOf(t);return n===-1?en.length:n}const Go=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var S,I,z;const s=D(),{convert:r}=H(),[a,c]=f.useState("全部"),[l,d]=f.useState(!1),[p,x]=f.useState("default"),[g,u]=f.useState(new Map),h=f.useMemo(()=>(t.works||[]).map(b=>{const R=g.get(b.work_id);return{id:b.work_id,title:(R==null?void 0:R.title)??b.work_id,role:b.role||"",cls:_n(b.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,g]),v=f.useMemo(()=>Co((t.works||[]).map(C=>C.role)),[t.works]),m=f.useMemo(()=>{const C=a==="全部"?h:h.filter(b=>b.cls===a);return p==="versions"?[...C].sort((b,R)=>(R.versionCount??-1)-(b.versionCount??-1)):C},[h,a,p]),j=l?m:m.slice(0,ya),y=f.useMemo(()=>j.filter(C=>!g.has(C.id)).map(C=>C.id),[j,g]);f.useEffect(()=>{if(!n||y.length===0)return;let C=!1;return Promise.all(y.map(b=>n.getItem(b).then(R=>{var M,P;const E=R??{},A=(((M=E.books)==null?void 0:M.length)??0)+(((P=E.collections)==null?void 0:P.length)??0);return[b,{id:b,title:E.title,versionCount:A,loaded:!0}]}).catch(()=>[b,{id:b,loaded:!0}]))).then(b=>{C||u(R=>{const E=new Map(R);for(const[A,M]of b)E.set(A,M);return E})}),()=>{C=!0}},[n,y]);const k=f.useMemo(()=>{const C=new Map;for(const b of t.alt_names||[]){const R=b.type||s.section.aliases;C.has(R)||C.set(R,[]),C.get(R).push(b.name)}return[...C.entries()].sort((b,R)=>wi(b[0])-wi(R[0])).map(([b,R])=>({label:b,names:R}))},[t.alt_names,s]),_=f.useMemo(()=>{const C=[];t.dynasty&&C.push({label:"時代",value:r(t.dynasty)});const b=E=>E==null?"":E<0?`前${-E}`:String(E);(t.birth_year!=null||t.death_year!=null)&&C.push({label:"生卒",value:`${b(t.birth_year)||"?"}—${b(t.death_year)||"?"}`});const R=(t.works||[]).length;return R&&C.push({label:"著作數",value:`${R} 種`}),C},[t,r]),w=(S=t.external_ids)==null?void 0:S.cbdb_id,T=!!((I=t.description)!=null&&I.text);return e.jsxs(e.Fragment,{children:[e.jsx(_t,{facts:_.length?e.jsx(Ct,{items:_}):void 0,children:(k.length>0||T)&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[k.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:k.map(C=>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:r(C.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:C.names.map(b=>r(b)).join(" · ")})]},C.label))}),T&&e.jsx(We,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),h.length===0&&e.jsxs(ze,{style:{marginBottom:0},children:[e.jsx(pe,{glyph:"著",title:s.label.relatedWorks}),e.jsx(Ke,{children:e.jsx(rt,{children:"尚未著錄該人物的關聯作品。"})})]}),h.length>0&&e.jsxs(ze,{style:{marginBottom:0},children:[e.jsx(pe,{glyph:"著",title:s.label.relatedWorks,count:m.length===h.length?`${h.length} 種`:`${h.length} 種 · 當前 ${m.length} 種`,actions:e.jsx(Nt,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{x(C=>(C==="default"&&d(!0),C==="default"?"versions":"default"))}})}),v.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:v.map(C=>e.jsx(Pe,{label:`${C.label} ${C.count}`,active:a===C.cls,onClick:()=>{c(C.cls),d(!1)}},C.cls))}),e.jsxs(Ke,{children:[e.jsx(Gt,{spec:ki}),j.map((C,b)=>e.jsx(Ut,{no:Yt(b),spec:ki,main:e.jsx(we,{id:C.id,label:r(C.title),onNavigate:i,renderLink:o,dense:!0}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:C.role?r(C.role):e.jsx(it,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:C.loaded?C.versionCount?`${C.versionCount} 種版本`:e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},C.id)),j.length===0&&e.jsx(rt,{children:"該職任下的著作尚未著錄。"})]}),m.length>j.length&&e.jsx(He,{label:`展開其餘 ${m.length-j.length} 條著作`,onClick:()=>d(!0)}),w!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",w,((z=t.external_ids)==null?void 0:z.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function va(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 ja(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 _i(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 Sa(t,n,i){const[o,s]=[t,n.book_id].sort();return{id:`sibling:${o}-${s}:${i}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function ka(t,n){var d;if(n==="all")return null;const i=(d=t.collections)==null?void 0:d[n],o=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,r=o||s||!!(i!=null&&i.hypothetical_ids);if(!r&&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||!r)return null;const a=o?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(a&&t.node_groups)for(const[p,x]of Object.entries(t.node_groups))a.has(x)&&c.add(p);let l=null;if(i.hypothetical_ids&&(l=new Set(i.hypothetical_ids)),a){l||(l=new Set);for(const p of t.hypothetical_nodes??[])p.group&&a.has(p.group)&&l.add(p.id)}return{books:c,hypos:l}}function $t(t,n,i){const o=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const r=new Set(o.excluded_books??[]),a=o.node_groups??{},c=ka(o,i??o.default_collection??"all"),l=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(l){const _=new Map(n.map(C=>[C.id,C])),w=new Map((o.hypothetical_nodes??[]).map(C=>[C.id,C])),T=C=>{const b=_.get(C);if(b&&b.lineage)return(b.lineage.derived_from??[]).map(E=>E.ref);const R=w.get(C);return R?(R.derived_from??[]).map(E=>E.ref):[]},S=C=>w.has(C)?!p||p.has(C):!d||d.has(C),I=new Set,z=C=>{if(!I.has(C)){I.add(C);for(const b of T(C))r.has(b)||(S(b)||(w.has(b)?g.add(b):_.has(b)&&x.add(b)),z(b))}};for(const C of n)d&&d.has(C.id)&&!r.has(C.id)&&z(C.id);for(const C of o.hypothetical_nodes??[])p&&p.has(C.id)&&z(C.id)}const u=n.filter(_=>!r.has(_.id)).filter(_=>!d||d.has(_.id)||x.has(_.id)).map(_=>{const w=ja(_,a);return w&&x.has(_.id)&&(w.bridge=!0),w}).filter(_=>_!==null),h=(o.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||g.has(_.id)).map(_=>{const w=va(_);return g.has(_.id)&&(w.bridge=!0),w}),v=[...u,...h],m=new Set(v.map(_=>_.id)),j=new Set,y=[],k=_=>{j.has(_.id)||!m.has(_.source)||!m.has(_.target)||(j.add(_.id),y.push(_))};for(const _ of n)r.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!x.has(_.id)||((_.lineage.derived_from??[]).forEach((w,T)=>{k(_i(_.id,w,T))}),(_.lineage.related_to??[]).forEach((w,T)=>{k(Sa(_.id,w,T))}));for(const _ of o.hypothetical_nodes??[])p&&!p.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((w,T)=>{k(_i(_.id,w,T))});return{nodes:v,edges:y,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(r)}}function Uo(t,n,i){const o=(t??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function wa(t,n){const i=[],o=t.version_graph;if(!o)return i;const s=new Set(n.map(l=>l.id)),r=new Set((o.hypothetical_nodes??[]).map(l=>l.id)),a=new Set([...s,...r]),c=(l,d)=>{a.has(d.ref)||i.push(`${l}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${l}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!r.has(d.ref)&&i.push(`${l}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const l of n){if(!l.lineage)continue;const d=`Book ${l.id} (${l.title})`;(l.lineage.derived_from??[]).forEach(p=>c(d,p)),(l.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const l of o.hypothetical_nodes??[]){const d=`Hypothetical ${l.id} (${l.label})`;(l.derived_from??[]).forEach(p=>c(d,p))}return i}const Yo=({graph:t,renderLink:n,className:i,style:o})=>{const{convert:s}=H();if(!t.nodes.length)return e.jsx("div",{style:{...Fa,...o},className:i,children:"暂无版本图数据"});const r=new Map,a=new Map;for(const g of t.edges)if(g.kind==="derive"){const u=r.get(g.target)??[];u.push(g),r.set(g.target,u)}else for(const u of[g.source,g.target]){const h=a.get(u)??[];h.push(g),a.set(u,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),l=new Map,d=[];for(const g of t.nodes)if(g.group){const u=l.get(g.group)??[];u.push(g),l.set(g.group,u)}else d.push(g);const p=(g,u)=>(g.year??9999)-(u.year??9999);l.forEach(g=>g.sort(p)),d.sort(p);const x=t.groups.filter(g=>l.has(g.id));return e.jsxs("div",{className:i,style:{...Ca,...o},children:[t.title&&e.jsx("div",{style:Ia,children:s(t.title)}),t.description&&e.jsx("div",{style:Ta,children:s(t.description)}),x.map(g=>e.jsx(Ci,{label:g.label,color:g.color,nodes:l.get(g.id),incomingMap:r,siblingMap:a,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(Ci,{label:"其他",nodes:d,incomingMap:r,siblingMap:a,nodeMap:c,renderLink:n})]})},Ci=({label:t,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:r,renderLink:a})=>{const{convert:c}=H();return e.jsxs("div",{style:za,children:[e.jsx("div",{style:{...Ra,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(l=>e.jsx(_a,{node:l,incoming:o.get(l.id)??[],siblings:s.get(l.id)??[],nodeMap:r,renderLink:a},l.id))]})},_a=({node:t,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const r=t.kind==="hypothetical",a=t.bridge,{convert:c}=H();return e.jsxs("div",{style:{...Ea,borderStyle:r||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?"var(--bim-bg-subtle, #fafafa)":void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Ba,children:[e.jsx("span",{style:La,children:r||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Wa,children:Uo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:$a,children:[t.category&&e.jsx(xt,{children:c(t.category)}),t.status==="lost"&&e.jsx(xt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(xt,{tone:"warn",children:"残本"}),r&&e.jsx(xt,{tone:"info",children:"假想祖本"}),a&&e.jsx(xt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Aa,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Ma,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Ti,children:[e.jsx("div",{style:zi,children:"来源:"}),n.map(l=>{const d=o.get(l.source);return e.jsxs("div",{style:Ri(l.confidence),children:[e.jsx("span",{style:Ei,children:c(l.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)??l.source)}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Ii,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Bi,children:["· ",c(l.evidence)]})]},l.id)})]}),i.length>0&&e.jsxs("div",{style:Ti,children:[e.jsx("div",{style:zi,children:"关联:"}),i.map(l=>{const d=l.source===t.id?l.target:l.source,p=o.get(d);return e.jsxs("div",{style:Ri(l.confidence),children:[e.jsx("span",{style:Ei,children:c(l.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(Ii,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Bi,children:["· ",c(l.evidence)]})]},l.id)})]})]})},xt=({children:t,tone:n="default"})=>{const o={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:o.bg,color:o.fg,marginRight:"4px"},children:t})},Ii=({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},Ca={fontSize:"14px",color:"var(--bim-fg, #333)"},Ia={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ta={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},za={marginBottom:"16px"},Ra={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ea={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Ba={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},La={fontSize:"15px",fontWeight:600},Wa={fontSize:"12px",color:"var(--bim-muted, #777)"},$a={marginBottom:"6px"},Aa={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Ma={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Ti={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},zi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Ri=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Ei={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Bi={fontSize:"11px",color:"var(--bim-muted, #888)"},Fa={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Ko=({selectedNodeId:t,...n})=>{const[i,o]=f.useState("loading"),[s,r]=f.useState(null);return f.useEffect(()=>{let a=!1;return Pa().then(c=>{a||(c?(r(c),o("ready")):o("missing"))}),()=>{a=!0}},[]),i==="loading"?e.jsx("div",{style:Li,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:Li,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(Ha,{modules:s,selectedNodeId:t,...n})};async function Pa(){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 Ha=({graph:t,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:r,modules:a})=>{const{ReactFlow:c,Background:l,Controls:d,Handle:p,Position:x,BaseEdge:g,EdgeLabelRenderer:u,getSmoothStepPath:h,dagre:v}=a,m=f.useMemo(()=>({lineage:T=>{var P,$,F,Q;const S=((P=T.data)==null?void 0:P.stepPosition)??.85,[I,z,C]=h({sourceX:T.sourceX,sourceY:T.sourceY,sourcePosition:T.sourcePosition,targetX:T.targetX,targetY:T.targetY,targetPosition:T.targetPosition,stepPosition:S,borderRadius:5}),b=!!(($=T.data)!=null&&$.isSibling),R=b?z:T.targetX-18,E=b?C:T.targetY-12,A=(F=T.data)==null?void 0:F.labelStyle,M=(Q=T.data)==null?void 0:Q.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:T.id,path:I,style:T.style,markerStart:T.markerStart,markerEnd:T.markerEnd}),T.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)",...M,...A},children:T.label})})]})}}),[g,u,h]),j=f.useMemo(()=>({version:T=>{const S=T.data,I=S.kind==="hypothetical",z=S.status==="lost",C=S.isSelected,b=S.bridge,R=S.borderColor??"var(--bim-muted, #888)",E=b||I?"dashed":"solid",A=b?.5:z?.6:1;return e.jsxs("div",{style:{background:b?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${E} ${C?"var(--bim-primary, #0078d4)":R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:C?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":I||b?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:b?"桥接节点:本身不在核心集,为保持派生链完整而显示":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:I||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:Uo(S.yearText,void 0,S.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:y}=H(),{rfNodes:k,rfEdges:_}=f.useMemo(()=>Oa(t,v,n,r,y),[t,v,n,r,y]);return e.jsx("div",{style:{width:"100%",height:i,...s},className:o,children:e.jsxs(c,{nodes:k,edges:_,nodeTypes:j,edgeTypes:m,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(l,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Oa(t,n,i,o,s=r=>r??""){const c=t.layout==="LR"||!t.layout,l=new n.graphlib.Graph;l.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),l.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??"var(--bim-muted, #888)"]));for(const j of t.nodes)l.setNode(j.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(p.has(j.relation)||l.setEdge(j.source,j.target));n.layout(l);const x=t.nodes.map(j=>{const y=l.node(j.id),k=o&&j.id===o,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Na(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:_,draggable:!1,selected:k}}),g=.78,u=.06,h=new Map;for(const j of t.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const v=new Map;for(const[j,y]of h){if(y.length<=1)continue;const k=[...y].sort((w,T)=>{var z,C;const S=((z=l.node(w.target))==null?void 0:z.y)??0,I=((C=l.node(T.target))==null?void 0:C.y)??0;return S-I}),_=k.length;k.forEach((w,T)=>{const S=(T-(_-1)/2)*u;v.set(w.id,g+S)})}const m=t.edges.map(j=>Da(j,v.get(j.id),s));return{rfNodes:x,rfEdges:m}}function Da(t,n,i=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",r=Va(t.confidence),a={type:"arrowclosed",color:r,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:r,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function Na(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Va(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 Li={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)"},Jo=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:r,collection:a,onCollectionChange:c,collectionsAvailable:l,collectionCounts:d,className:p,style:x})=>{var y;const[g,u]=f.useState(n),h=k=>{u(k),r==null||r(k)},v=(()=>{if(!l)return[];const k=Object.entries(l);return k.length===0||l.all?k:[...k,["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 j=a?(y=l==null?void 0:l[a])==null?void 0:y.description:void 0;return e.jsxs("div",{className:p,style:x,children:[e.jsxs("div",{style:Ga,children:[e.jsx("button",{onClick:()=>h("list"),style:tn(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:tn(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(([k,_])=>{const w=d==null?void 0:d[k];return e.jsxs("button",{onClick:()=>c==null?void 0:c(k),style:tn(a===k),title:_.description,children:[_.label,w!=null?` ${w}`:""]},k)})]})]}),m&&j&&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:j}),g==="list"?e.jsx(Yo,{graph:t,renderLink:i}):e.jsx(Ko,{graph:t,renderLink:i,height:o,selectedNodeId:s})]})},Ga={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},tn=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"}),qo=({style:t})=>{const n=f.useContext(St);if(!n)return null;const{locale:i,setLocale:o}=n,s=i==="zh-Hant",r=()=>o(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:r,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:"简"})]})},Xo=({href:t,label:n="在 GitHub 查看本条目源文件",size:i=16,className:o,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:o,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:r=>{r.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:r=>{r.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"})})}),Ua=({id:t,transport:n,activeTab:i,onTabChange:o,activeJuan:s,onJuanChange:r,lineageMode:a="list",onLineageModeChange:c,lineageCollection:l,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:x,onNavigate:g,onBack:u,backLabel:h,renderLink:v,enrichDetail:m,getSourceLink:j,extraTabs:y=[],showFeedbackTab:k=!0,feedbackApiUrl:_,height:w,footerExtra:T,className:S,style:I})=>{const z=D(),{convert:C}=H(),[b,R]=f.useState(null),[E,A]=f.useState(null),[M,P]=f.useState(!0),[$,F]=f.useState(!1),[Q,W]=f.useState([]),[U,ne]=f.useState(!1),[B,V]=f.useState(null),[Y,ie]=f.useState(!1),[G,K]=f.useState(null),[de,Re]=f.useState(!1),[le,xe]=f.useState(null),[he,Oe]=f.useState(!1),_e=f.useRef(null),[qe,lt]=f.useState(null),N=s!==void 0?s:qe,oe=f.useCallback(O=>{r?r(O):lt(O)},[r]),te=f.useCallback(async O=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ne(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(O)||[]);else if(n.getCollectionCatalog){const re=await n.getCollectionCatalog(O);W(re?[{resource_id:"",data:re}]:[])}}catch{W([])}finally{ne(!1)}},[n]),L=f.useCallback(async O=>{if(!n.getCollatedEditionIndex){V(null);return}ie(!0);try{V(await n.getCollatedEditionIndex(O))}catch{V(null)}finally{ie(!1)}},[n]),Z=f.useCallback(async O=>{if(!n.getBookFullTextIndex){K(null);return}Re(!0);try{K(await n.getBookFullTextIndex(O))}catch{K(null)}finally{Re(!1)}},[n]),se=f.useCallback(async(O,re)=>{Oe(!0);try{if(n.getLineageGraph){const Be=await n.getLineageGraph(O);Be&&xe(Be)}const ae=re.version_graph;if(!ae||!ae.enabled){le||xe(null),_e.current=null;return}const ce=re.books??[],ee=[];for(const Be of ce)try{const Ce=await n.getItem(Be);Ce&&ee.push(Ce)}catch{}_e.current={work:re,books:ee};const q=l??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Ee=q==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":q??"all";xe($t(re,ee,Ee))}catch{xe(null),_e.current=null}finally{Oe(!1)}},[n]);f.useEffect(()=>{let O=!1;return(async()=>{P(!0),F(!1),R(null),A(null),W([]),V(null),xe(null),_e.current=null;try{const ae=await n.getItem(t);if(O)return;if(!ae){F(!0);return}const ce=ae;let ee=null;if(n.getEntry&&(ee=await n.getEntry(t),O))return;ee||(ee={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),m&&m(ee,ce),R(ee),A(ce),ce.type==="collection"?te(t):ce.type==="work"?((ce.has_collated||n.getCollatedEditionIndex)&&L(t),(ce.version_graph||n.getLineageGraph)&&se(t,ce)):ce.type==="book"&&ce.has_full_text&&n.getBookFullTextIndex&&Z(t)}catch{O||F(!0)}finally{O||P(!1)}})(),()=>{O=!0}},[t,n,m,te,L,se,Z]),f.useEffect(()=>{const O=_e.current;!O||!l||xe($t(O.work,O.books,l))},[l]);const J=[];if(E){if(J.push({key:"basic",label:z.detailTab.basicInfo}),E.type==="collection"){U&&Q.length===0&&J.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const O of Q)J.push({key:`catalog:${O.resource_id}`,label:O.short_name?`${C(O.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}E.type==="work"&&(B||Y)&&J.push({key:"collated",label:Y?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),E.type==="book"&&(G||de)&&J.push({key:"fulltext",label:de?`${z.detailTab.fullText}…`:z.detailTab.fullText}),E.type==="work"&&(le||he)&&J.push({key:"lineage",label:he?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const O of y)(O.position??"before-feedback")==="before-feedback"&&O.shouldShow(E)&&J.push({key:O.key,label:O.label});k&&i==="feedback"&&J.push({key:"feedback",label:z.detailTab.feedback});for(const O of y)O.position==="after-feedback"&&O.shouldShow(E)&&J.push({key:O.key,label:O.label})}f.useEffect(()=>{if(i!=="emendated"||!E)return;o("basic");const O=setTimeout(()=>{var re;(re=document.getElementById("studies"))==null||re.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(O)},[i,E,o]);const Ae=b&&E&&j?j({activeTab:i,activeJuan:N,entry:b,detail:E}):null,ve=f.useMemo(()=>{var ee;if(!E)return null;const re=(E.authors??[]).map(q=>{const Ee=Cn(q.role);return`${q.dynasty?`〔${C(q.dynasty)}〕`:""}${C(q.name)}${Ee?` ${C(Ee)}`:""}`}).join(" · ");let ae=!1;try{ae=X.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const q=E;return{title:C(q.title),subtitle:q.edition?C(q.edition):re||void 0,aside:[ae?z.status.draft:"",re&&q.edition?re:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const q=E;return{title:C(q.title),subtitle:C(Ye(q,z.unit.juan))||void 0,aside:[(ee=q.publication_info)==null?void 0:ee.year,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:re||void 0}}if(E.type==="entity"){const q=E,Ee=Ce=>Ce==null?"":Ce<0?`前${-Ce}`:String(Ce),Be=q.birth_year!=null||q.death_year!=null?`${Ee(q.birth_year)||"?"}—${Ee(q.death_year)||"?"}`:"";return{title:C(q.primary_name||q.title),subtitle:[q.dynasty?`〔${C(q.dynasty)}〕`:"",Be].filter(Boolean).join(" ")||void 0,aside:ae?z.status.draft:void 0,secondLine:void 0}}const ce=C(Ye(E,z.unit.juan));return{title:C(E.title),subtitle:[ce,re].filter(Boolean).join(" · ")||void 0,aside:[E.subtype,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,C,z]),fe=()=>{var O;return E?E.type==="work"?e.jsx(Do,{data:E,transport:n,onNavigate:g,renderLink:v,lineageAction:le&&le.nodes.length>0?e.jsxs("button",{type:"button",onClick:()=>o("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(No,{data:E,transport:n,onNavigate:g,renderLink:v}):E.type==="collection"?e.jsx(Vo,{data:E,catalog:(O=Q[0])==null?void 0:O.data,transport:n,onNavigate:g,renderLink:v,catalogAction:Q.length>0?e.jsxs("button",{type:"button",onClick:()=>o(`catalog:${Q[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(Go,{data:E,transport:n,onNavigate:g,renderLink:v}):null},Xe=()=>{var re,ae,ce;if(!b||!E)return null;if(i==="basic"||i==="emendated")return fe();if(typeof i=="string"&&i.startsWith("catalog:")){const ee=(re=Q.find(q=>`catalog:${q.resource_id}`===i))==null?void 0:re.data;return e.jsx(hn,{data:ee,onNavigate:g,renderLink:v})}if(i==="collated")return e.jsx(jn,{index:B||void 0,workId:t,transport:n,onNavigate:g,activeJuan:N,onJuanChange:oe});if(i==="fulltext")return e.jsx(no,{index:G||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:oe});if(i==="lineage"){if(!le)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:he?"加載中…":"暫無版本圖數據"});const ee=E.type==="work"?E:null;return e.jsx(Jo,{graph:le,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:c,selectedNodeId:x,collection:l??((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 Ce,Rn,En,Bn,Ln,Wn,$n;if(!ee)return;const q={},Ee=((Ce=_e.current)==null?void 0:Ce.books)??[];q.all=(((Rn=ee.books)==null?void 0:Rn.length)??0)-(((Bn=(En=ee.version_graph)==null?void 0:En.excluded_books)==null?void 0:Bn.length)??0);const Be=(Ln=ee.version_graph)==null?void 0:Ln.collections;if(Be)for(const An of Object.keys(Be))q[An]=$t(ee,Ee,An).nodes.filter(Mn=>Mn.kind==="book"&&!Mn.bridge).length;return q.core==null&&(($n=(Wn=ee.version_graph)==null?void 0:Wn.core_books)!=null&&$n.length)&&(q.core=ee.version_graph.core_books.length),q})()})}if(i==="feedback"&&k)return e.jsx(bo,{resourceId:t,apiUrl:_});const O=y.find(ee=>ee.key===i);return O?O.render({detail:E,entry:b,transport:n,onNavigate:g}):null};if(M)return e.jsx(Lt,{style:{minHeight:w,...I},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((O,re)=>e.jsx("div",{style:{height:re===1?40:16,width:O,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},re))})});if($||!E||!b||!ve)return e.jsx(Lt,{style:{minHeight:w,...I},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const Zo=i==="basic"||i==="emendated",Kt=[{label:h??z.detailTab.backToIndex,onClick:u}];if(E.type==="book"&&E.work_id){const O=E.work_id;Kt.push({label:z.indexType.work,id:O,onClick:()=>g==null?void 0:g(O)})}return Kt.push({label:z.indexType[E.type]}),e.jsx("div",{className:S,children:e.jsxs(Lt,{style:{minHeight:w,...I},children:[e.jsx(Bo,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Tn,{char:"籍"}),e.jsx(Lo,{items:Kt})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(qo,{}),k&&e.jsx("button",{type:"button",onClick:()=>o("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}),Ae&&e.jsx(Xo,{...Ae})]})}),e.jsx(Wo,{...ve}),J.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:J.map(O=>e.jsx(Pe,{label:O.label,active:O.key===i||Zo&&O.key==="basic",onClick:()=>o(O.key)},O.key))}),e.jsx("div",{style:{marginTop:J.length>1?8:0},children:Xe()}),e.jsx(Ho,{left:e.jsxs(e.Fragment,{children:[T,T?" · ":"",e.jsx(Ya,{id:E.id,label:z.label.id,copied:z.action.copied})]}),right:e.jsxs(e.Fragment,{children:[k&&e.jsx("button",{type:"button",onClick:()=>o("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}),Ae&&e.jsx("a",{href:Ae.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function Ya({id:t,label:n,copied:i}){const[o,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 r;(r=navigator.clipboard)==null||r.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}).catch(()=>{})},title:o?i:void 0,style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:o?"✓":"⧉"})]})}exports.BidLink=X.BidLink;exports.BookIndexError=X.BookIndexError;exports.BookIndexManager=X.BookIndexManager;exports.BookIndexStorage=X.BookIndexStorage;exports.BundleStorage=X.BundleStorage;exports.ConfigError=X.ConfigError;exports.GithubStorage=X.GithubStorage;exports.IdGenerationError=X.IdGenerationError;exports.IdGenerator=X.IdGenerator;exports.LocalStorage=X.LocalStorage;exports.MigrationError=X.MigrationError;exports.StorageError=X.StorageError;exports.base36Decode=X.base36Decode;exports.base36Encode=X.base36Encode;exports.base58Decode=X.base58Decode;exports.buildId=X.buildId;exports.buildPromotionMap=X.buildPromotionMap;exports.cleanName=X.cleanName;exports.decodeId=X.decodeId;exports.decodeIdString=X.decodeIdString;exports.encodeId=X.encodeId;exports.extractIdFromUrl=X.extractIdFromUrl;exports.extractStatus=X.extractStatus;exports.extractType=X.extractType;exports.normalizeCatalog=X.normalizeCatalog;exports.parseId=X.parseId;exports.shardOf=X.shardOf;exports.smartDecode=X.smartDecode;exports.validateResource=X.validateResource;exports.Badge=Ft;exports.BidUrlProvider=cr;exports.BookDetailLayout=Ua;exports.BookFullText=no;exports.BookPage=No;exports.Breadcrumb=Lo;exports.Chip=It;exports.ChipWall=Vt;exports.CollatedEdition=jn;exports.CollectionCatalog=hn;exports.CollectionPage=Vo;exports.CreateEntityDialog=co;exports.DETAIL_CSS=Eo;exports.Dash=it;exports.DataTable=Ke;exports.DetailFooter=Ho;exports.DetailHeader=Wo;exports.EmendatedBySection=Ki;exports.EmptyNote=rt;exports.EntityDetail=Di;exports.EntityPage=Go;exports.EntityPickerDialog=uo;exports.EntitySelector=ao;exports.ExpandRow=Ao;exports.ExtLink=cn;exports.FactList=Ct;exports.FeedbackButton=Vl;exports.FeedbackDialog=mo;exports.FeedbackForm=ho;exports.FeedbackList=Sn;exports.FeedbackTab=bo;exports.FilterChip=Pe;exports.FormInput=ge;exports.FormTextArea=Ge;exports.GlyphBadge=Tn;exports.HomePage=rn;exports.IndexApp=Xs;exports.IndexBrowser=on;exports.IndexDetail=mn;exports.IndexEditor=xo;exports.IndexView=Ll;exports.IntroGrid=_t;exports.LocaleContext=St;exports.LocaleProvider=br;exports.LocaleToggle=qo;exports.ModeIndicator=Hi;exports.MoreButton=He;exports.PAGE_MAX_WIDTH=Ro;exports.PageFrame=Lt;exports.Quote=Wt;exports.ROLE_CLASS_ORDER=_o;exports.RelationPanel=so;exports.RepoSourceLink=Xo;exports.ResourceEditor=nn;exports.ResourceGroup=an;exports.ResourceLine=ot;exports.ResourceList=gn;exports.ResourceRow=Mo;exports.SearchInput=Oi;exports.Section=je;exports.SectionHead=pe;exports.SmartBidInput=Et;exports.SourceEditor=io;exports.TableHead=Gt;exports.TableRow=Ut;exports.TagRow=zn;exports.TagRows=Po;exports.TextButton=Nt;exports.TopStrip=Bo;exports.VersionLineageGraph=Ko;exports.VersionLineageList=Yo;exports.VersionLineageView=Jo;exports.VolumeChips=$o;exports.VolumeLinks=Fo;exports.WorkCatalog=Zs;exports.WorkPage=Do;exports.bucketResources=Dt;exports.buildCollectionTable=Io;exports.buildLineageGraph=$t;exports.buildPageUrl=fn;exports.buildVersionRow=ko;exports.buildVersionTable=wo;exports.computeVersionPartition=da;exports.deriveDating=sa;exports.deriveEditionType=zo;exports.deriveEra=wt;exports.deriveYear=Ot;exports.deriveYearRange=kn;exports.detailToEditor=go;exports.displayAuthorRole=Cn;exports.editorToDetail=Bl;exports.eraRank=ln;exports.flattenTitles=jt;exports.formatTemplate=kt;exports.formatVolumeRange=In;exports.getDisplayNameFromUrl=yt;exports.getStartPage=xn;exports.getTypeGroupKey=dn;exports.groupRelatedWorks=So;exports.measureText=Ye;exports.mergeVolumeResources=pn;exports.normalizeEra=ke;exports.normalizeRole=_n;exports.normalizeVolumeIndex=bt;exports.normalizeVolumes=Pi;exports.numberToChinese=To;exports.parseChineseNumber=Pt;exports.parseSourceString=oo;exports.resourceHref=At;exports.resourceNote=wn;exports.roleFacets=Co;exports.rowNo=Yt;exports.sortYear=jo;exports.stringifySources=ro;exports.useBidUrl=me;exports.useConvert=H;exports.useT=D;exports.validateLineageGraph=wa;exports.volumeStats=un;
|
|
49
|
+
`;function Lt({children:t,style:n}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:fr}),e.jsx("div",{className:"bim-d-main",children:t})]})}function gr({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 Tn({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 mr({items:t}){const n=he();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 hr({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 It({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 Tt({items:t,horizontal:n}){const{convert:i}=H();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}=H();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(Tn,{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 Re({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function Pe({label:t,active:n,onClick:i,dashed:r}){const{convert:s}=H();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 Gt({label:t,onClick:n}){const{convert:i}=H();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 Oe({label:t,onClick:n,inline:i}){const{convert:r}=H();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 zt({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 Yt({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function br({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 Ut({spec:t}){const{convert:n}=H();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 Kt({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 Jt(t){return String(t+1).padStart(2,"0")}function rt(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function yr({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 He(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 Wt({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 dn({title:t,tag:n,children:i}){const{convert:r}=H();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 vr({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}=H(),[o,l]=g.useState(!1),c=mn(t),a=i&&!!c&&c.expected>0,d=(t.url?jt(t.url):void 0)||s(t.name),p=n?Is(t,n):"",x=p?`${d}(${p})`:d;return e.jsx(vr,{name:x,note:wn(t)||r,href:Mt(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(jr,{item:t})]}):void 0})}function jr({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 zn({label:t,items:n}){const{convert:i}=H();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(zt,{children:i(r)},s))]}):null}function Sr({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(zn,{label:i.label,items:i.items},i.label))}):null}function kt(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function kr({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 we({id:t,label:n,onNavigate:i,renderLink:r,style:s,dense:o}){const l=he();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 pn({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 si={A:"fine",B:"rough",C:"rough",D:"ocr"};function Ls(t){return typeof t!="string"?null:t in Oi?t:t in si?si[t]:null}const Ws={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},$s={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ve(t){return typeof t!="string"?"":Ws[t]??$s[t]??t}const As=["〇","一","二","三","四","五","六","七","八","九"],li=["","十","百","千"],Ms=["","萬","億"];function wr(t){if(t===0)return"〇";if(t<0)return`負${wr(-t)}`;const n=[];let i=t,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Fs(s,r>0)+Ms[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Fs(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+=li[c]:s+=As[l]+li[c]}return s.replace(/〇$/,"")}let vt=null,Et=null;const Pt=new Set;function Ps(){return vt?Promise.resolve():Et||(Et=import("opencc-js/t2cn").then(t=>{vt=t.Converter({from:"tw",to:"cn"}),Pt.forEach(n=>n())}).catch(()=>{vt=t=>t,Pt.forEach(t=>t())}),Et)}function Me(){const[,t]=g.useState(0);return g.useEffect(()=>{if(vt)return;const n=()=>t(i=>i+1);return Pt.add(n),Ps(),()=>{Pt.delete(n)}},[]),vt??(n=>n)}function lt(t,n){return n(t).toLowerCase()}const Rn="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:Rn,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:o})}function En(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 Hs(t,n,i){return n?lt(t,i).includes(lt(n,i)):!0}const Bn={类:"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)"},Os={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Ds(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function _r({file:t,isActive:n,onSelect:i,meta:r,matchState:s}){const o=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=Ds(t),d=!!(r!=null&&r.vol_label)&&!a.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{o||i(t)},disabled:o,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":o?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":c?`${Rn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":o?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:o?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:o?.5:1},children:[a,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Cr(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(r=>Cr(r,n)))}function Ir(t){var r;const n=t.files.length,i=((r=t.children)==null?void 0:r.reduce((s,o)=>s+Ir(o),0))||0;return n+i}function Ns(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 Tr({group:t,activeFile:n,onSelect:i,depth:r=0,juanMeta:s,matchStates:o}){var h;const l=Cr(t,n||""),c=Ns(t,o),a=typeof c=="number"&&c>0,d=c===0,[p,x]=g.useState(l||a),f=Ir(t),u=!!((h=t.children)!=null&&h.length);if(g.useEffect(()=>{l&&x(!0)},[l]),g.useEffect(()=>{a&&x(!0)},[a]),t.files.length===1&&!u){const y=t.files[0],m=n===y,j=o[y],b=j===0,k=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{b||i(y)},disabled:b,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:m?"1px solid var(--bim-primary, #8e6f3e)":b?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:m?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${Rn}40`:"transparent",color:m?"var(--bim-primary, #8e6f3e)":b?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:b?"not-allowed":"pointer",fontSize:"12px",fontWeight:m?600:400,lineHeight:1.4,opacity:b?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:j}),k&&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:()=>x(!p),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:l?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:p?"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:["(",f,")"]}),a&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),p&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(y=>e.jsx(_r,{file:y,isActive:n===y,onSelect:i,meta:s==null?void 0:s[y],matchState:o[y]},y))}),u&&t.children.map((y,m)=>e.jsx(Tr,{group:y,activeFile:n,onSelect:i,depth:r+1,juanMeta:s,matchStates:o},m))]})]})}function Vs({files:t,groups:n,activeFile:i,onSelect:r,juanMeta:s,matchStates:o}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,a)=>e.jsx(Tr,{group:c,activeFile:i,onSelect:r,juanMeta:s,matchStates:o},a))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(c=>e.jsx(_r,{file:c,isActive:i===c,onSelect:r,meta:s==null?void 0:s[c],matchState:o[c]},c))})}function Gs({type:t}){const n=Bn[t]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function Ys({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=H(),s=he(),o=Me(),l=y=>y?He(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:[wr(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 Us({section:t,highlightQuery:n=""}){const{convert:i}=H(),r=Me(),s=a=>a?He(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(Gs,{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, ${Bn[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)})})]})}function Ks({section:t,highlightQuery:n=""}){const{convert:i}=H(),r=Me();if(ve(t.type)==="page_header"||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
50
|
+
`)),o=n?at(s,n,r):s,l=ve(t.type),c=Bn[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 Js(t,n,i){const[r,s]=g.useState({});return g.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 f=await n.getItem(p);if(!f)return null;const u=f.title||p,h=f.authors,y=(x=h==null?void 0:h[0])==null?void 0:x.name;return{title:u,author:y}}catch{return null}};return Promise.all(l.map(async p=>{var f;const x=await a(p);return(f=i==null?void 0:i.current)==null||f.set(p,x),[p,x]})).then(p=>{o||s(x=>{const f={...x};for(const[u,h]of p)f[u]=h;return f})}),()=>{o=!0}},[t.join(","),n]),r}function qs({section:t,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:o}=H(),l=he(),c=Me(),a=b=>b?He(o(b),k=>s?at(k,s,c):k):"",[d,p]=g.useState(!1);g.useEffect(()=>{s&&p(!0)},[s]);const x=t.type,f=Os[x]||"var(--bim-desc-fg, #717171)",u=!!t.content,h=t.work_ids||[],y=h.length>1,m=Js(y?h:[],i,r),j=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&&j&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:a(j)})]}),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:"→作品"}),y&&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:f,border:`1px solid ${f}40`,borderRadius:"2px",background:`${f}08`},children:x})]})]}),y&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(b=>{const k=m[b],_=k?`${o(k.title)}${k.author?`(${o(k.author)})`:""}`:b.slice(0,8)+"…";return e.jsxs("a",{href:l(b),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(b))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:b,children:["→",_]},b)})}),d&&u&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${f}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 Xs({juan:t,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const{convert:o}=H(),l=Me(),c=n.trim(),a=g.useMemo(()=>c?t.sections.filter(x=>En(x,c,!0,l)):t.sections,[t.sections,c,l]),d=t.sections.filter(x=>ve(x.type)==="考证").length,p=a.filter(x=>ve(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,f)=>e.jsx(qs,{section:x,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:c},f))}),a.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Zs({text:t,highlightQuery:n=""}){const{convert:i}=H(),r=Me(),s=l=>He(i(l),c=>n?at(c,n,r):c),o=t.split(`
|
|
51
|
+
`);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 Qs({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=H(),s=he(),o=Me(),l=d=>d?He(r(d),p=>i?at(p,i,o):p):"",c=[];let a=null;for(const d of t){const p=ve(d.type);p!=="page_header"&&(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)=>ve(x.type)==="序"||ve(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 el({juan:t,rawText:n,searchQuery:i,onNavigate:r}){const{convert:s}=H(),o=Me(),[l,c]=g.useState("catalog"),a=i.trim(),d=g.useMemo(()=>a?t.sections.filter(u=>En(u,a,!1,o)):t.sections,[t.sections,a,o]),p=t.sections.filter(u=>ve(u.type)==="书").length,x=t.sections.filter(u=>ve(u.type)==="诗").length,f=a?d.filter(u=>ve(u.type)==="书"||ve(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("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},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))}),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} 部书`})]}),l==="raw"&&(n?e.jsx(Zs,{text:n,highlightQuery:a}):e.jsx(Qs,{sections:t.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((u,h)=>{const y=ve(u.type);return y==="书"||y==="诗"||y==="考证"?e.jsx(Ys,{section:u,onNavigate:r,highlightQuery:a},h):y==="类"?e.jsx(Us,{section:u,highlightQuery:a},h):e.jsx(Ks,{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 zr(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 ai(t){const n=zr(t);return n.length>0?n[0]:null}function tl(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 j of h.juan.sections)En(j,y,a,d)&&m++;return m===0&&h.rawText&&Hs(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={},j=[];for(const I of r){const S=p.current.get(I);S?m[I]=u(S,h):(m[I]="loading",j.push(I))}f(m);const b=8;let k=0;const _=async()=>{var I;for(;k<j.length;){if(y)return;const S=k++,T=j[S];try{const[z,C]=await Promise.all([i.getCollatedJuan(n,T),((I=i.getCollatedJuanText)==null?void 0:I.call(i,n,T))??Promise.resolve(null)]),v={juan:z,rawText:C};if(p.current.set(T,v),y)return;f(R=>({...R,[T]:u(v,h)}))}catch{if(y)return;f(z=>({...z,[T]:0}))}}},w=Array.from({length:Math.min(b,j.length)},()=>_());return Promise.all(w),()=>{y=!0}},[c,n,i,r.join(","),u,d]),{matchStates:x}}const Ln=({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,j]=g.useState(null),[b,k]=g.useState(!1),[_,w]=g.useState(null),[I,S]=g.useState(""),T=g.useRef(new Map),z=s??h,C=g.useCallback($=>{y($),o==null||o($)},[o]),v=t||a;g.useEffect(()=>{t&&(x(!1),u(null))},[t]),g.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let $=!1;return x(!0),u(null),i.getCollatedEditionIndex(n).then(F=>{if(!$)if(!F)u("未找到整理本数据");else{d(F);const Q=ai(F);!s&&Q&&C(Q)}}).catch(F=>{$||u(F instanceof Error?F.message:"加载失败")}).finally(()=>{$||x(!1)}),()=>{$=!0}},[t,n,i,s,C]),g.useEffect(()=>{const $=t||a;if($&&!z){const F=ai($);F&&C(F)}},[t,a,z,C]);const R=n||(v==null?void 0:v.work_id),E=g.useCallback(async $=>{var F;if(!(!R||!(i!=null&&i.getCollatedJuan))){k(!0),j(null),w(null);try{const[Q,W]=await Promise.all([i.getCollatedJuan(R,$),((F=i.getCollatedJuanText)==null?void 0:F.call(i,R,$))??Promise.resolve(null)]);j(Q),w(W)}catch{j(null),w(null)}finally{k(!1)}}},[R,i]);g.useEffect(()=>{z&&E(z)},[z,E]);const A=$=>{C($)};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(!v)return null;const M=v.type==="kaozhen",P=zr(v);return e.jsx(nl,{className:l,style:c,index:v,allFiles:P,isKaozhen:M,effectiveWorkId:R,transport:i,activeFile:z,handleSelectFile:A,juanData:m,juanRawText:_,juanLoading:b,searchQuery:I,setSearchQuery:S,onNavigate:r,workLabelCacheRef:T})},nl=({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}=tl({workId:o,transport:l,files:r,activeFile:c,activeJuan:d,activeRawText:p,query:f,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:f,onChange:j=>u(j.target.value),style:{width:"100%",maxWidth:"420px",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("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?e.jsxs(e.Fragment,{children:[i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 卷"]})}),i.text_quality&&(()=>{const j=Ls(i.text_quality.grade);return j?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(hs,{content:ho[j],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:bo[j],cursor:"help"},children:Oi[j]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),e.jsx(Vs,{files:r,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:m}),x?e.jsx(Xe,{}):d?s?e.jsx(Xs,{juan:d,searchQuery:f,onNavigate:h,transport:l,workLabelCache:y}):e.jsx(el,{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((j,b)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[b+1,". "]}),j.url?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:j.title}):e.jsx("span",{children:j.title}),j.author&&e.jsxs("span",{children:[",",j.author]}),j.note&&e.jsxs("span",{children:["。",j.note]})]},b))]})]})},il={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},rl={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function ol(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 Wn=({items:t,loading:n})=>{const i=he();return n?e.jsx(Xe,{}):t.length===0?e.jsx("div",{style:sl,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=il[r.type],o=rl[r.status];return e.jsxs("div",{style:ll,children:[e.jsxs("div",{style:al,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...ci,background:s.color},children:s.label}),e.jsx("span",{style:{...ci,background:o.color},children:o.label})]}),e.jsx("span",{style:cl,children:ol(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:dl,children:[r.resourceId&&e.jsx("a",{href:i(r.resourceId),style:di,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:di,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:pl,children:r.content}),r.reply&&e.jsxs("div",{style:ul,children:[e.jsx("div",{style:xl,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},sl={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},ll={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},al={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ci={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},cl={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},dl={fontSize:"12px",marginBottom:"6px"},di={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},pl={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},ul={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},xl={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},un=({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),j=r??x,b=M=>{f(M),s==null||s(M)},[k,_]=g.useState(!0),[w,I]=g.useState(null),[S,T]=g.useState(null),[z,C]=g.useState(null);g.useEffect(()=>{let M=!1;if(t.getCounts)return t.getCounts().then(P=>{M||a({works:P.works,books:P.books,collections:P.collections})}).catch(()=>{}),()=>{M=!0}},[t]),g.useEffect(()=>{let M=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const $=await t.getRecommended();if($!=null&&$.groups)return $.groups.flatMap(F=>F.items.map(Q=>({...Q,group:F.name})))}catch{}return[]})().then(async $=>{if(M)return;const F=$.filter(W=>W.id);if(F.length===0){_(!1);return}const Q=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 ne=await t.getItem(W.id);ne&&(Y={id:W.id,title:ne.title||W.id,type:ne.type||"work"})}if(Y)return{...Y,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:X.extractType(W.id),group:W.group,fallbackDescription:W.description}}));M||(p(Q.filter(W=>W!==null)),_(!1))}),()=>{M=!0}},[t,i]);const v=g.useRef(!1),R=g.useRef(!1),E=g.useRef(!1);g.useEffect(()=>{if(j!=="catalog"||v.current)return;const M=t.getCatalogProgress??t.getResourceProgress;if(!M)return;v.current=!0;let P=!1;return M.call(t).then($=>{P||I($)}).catch(()=>{v.current=!1}),()=>{P=!0}},[t,j]),g.useEffect(()=>{if(j!=="collection"||R.current||!t.getCollectionProgress)return;R.current=!0;let M=!1;return t.getCollectionProgress().then(P=>{M||T(P)}).catch(()=>{R.current=!1}),()=>{M=!0}},[t,j]),g.useEffect(()=>{if(j!=="site"||E.current||!t.getSiteProgress)return;E.current=!0;let M=!1;return t.getSiteProgress().then(P=>{M||C(P)}).catch(()=>{E.current=!1}),()=>{M=!0}},[t,j]),g.useEffect(()=>{if(!o||j!=="feedback")return;let M=!1;return m(!0),fetch(o).then(P=>P.json()).then(P=>{!M&&P.success&&h(P.items||[])}).catch(()=>{}).finally(()=>{M||m(!1)}),()=>{M=!0}},[o,j]);const A=M=>{switch(M){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:j==="recommend",onClick:()=>b("recommend")}),e.jsx(xt,{label:l.home.catalogTab,active:j==="catalog",onClick:()=>b("catalog")}),e.jsx(xt,{label:l.home.collectionTab,active:j==="collection",onClick:()=>b("collection")}),e.jsx(xt,{label:l.home.siteTab,active:j==="site",onClick:()=>b("site")}),o&&e.jsx(xt,{label:l.home.feedbackTab,active:j==="feedback",onClick:()=>b("feedback")})]}),j==="recommend"&&e.jsx(fl,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:l}),j==="catalog"&&e.jsx(pi,{progress:w,t:l,onNavigate:n}),j==="collection"&&e.jsx(pi,{progress:S,t:l,onNavigate:n}),j==="site"&&e.jsx(ml,{progress:z,t:l,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&o&&e.jsx(Wn,{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}),fl=({recommended:t,loading:n,onNavigate:i,getIcon:r,t:s})=>{const o=he();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))})},pi=({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(gl,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},gl=({item:t,t:n,statusColor:i,onNavigate:r})=>{const s=he(),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?_t(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})]})},ml=({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(ui,{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(ui,{item:a,t:n,totalWorks:i},a.id))})]})]})},ui=({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})]})},xi="(max-width: 768px)";function hl(){const[t,n]=g.useState(()=>typeof window>"u"?!1:window.matchMedia(xi).matches);return g.useEffect(()=>{const i=window.matchMedia(xi),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),t}const bl=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var P;const o=D(),{convert:l}=H(),c=hl(),[a,d]=g.useState(null),[p,x]=g.useState(null),[f,u]=g.useState(!1),[h,y]=g.useState("detail"),[m,j]=g.useState([]),[b,k]=g.useState(!1),[_,w]=g.useState(null),[I,S]=g.useState(!1),T=g.useCallback(async $=>{if(!t.getCollatedEditionIndex){w(null);return}S(!0);try{const F=await t.getCollatedEditionIndex($);w(F)}catch{w(null)}finally{S(!1)}},[t]),z=g.useCallback(async $=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}k(!0);try{if(t.getCollectionCatalogs){const F=await t.getCollectionCatalogs($);j(F||[])}else if(t.getCollectionCatalog){const F=await t.getCollectionCatalog($);j(F?[{resource_id:"",data:F}]:[])}}catch{j([])}finally{k(!1)}},[t]),C=g.useCallback(async $=>{if(i){i($);return}d($),x(null),j([]),w(null),y("detail"),u(!0);try{const F=await t.getItem($.id);F&&(x(F),F.type==="collection"?z($.id):F.type==="work"&&F.has_collated&&T($.id))}catch(F){console.error("加载详情失败:",F)}finally{u(!1)}},[t,i,z,T]),v=g.useCallback(async $=>{x(null),j([]),w(null),y("detail"),u(!0);try{const F=await t.getItem($);F&&(x(F),d({id:$,title:F.title||$,type:F.type||"book"}),F.type==="collection"?z($):F.type==="work"&&F.has_collated&&T($))}catch(F){console.error("导航失败:",F)}finally{u(!1)}},[t,z,T]),R=(p==null?void 0:p.type)==="collection"&&(m.length>0||b)||(p==null?void 0:p.type)==="work"&&(_||I),E=c&&(f||p),A=g.useCallback(()=>{d(null),x(null),j([]),w(null),y("detail")},[]),M=e.jsx(e.Fragment,{children:f?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:()=>y("detail"),style:Bt(h==="detail"),children:o.detailTab.basicInfo}),p.type==="collection"&&b&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:Bt(!1),children:[o.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&m.map($=>e.jsx("button",{onClick:()=>y(`catalog:${$.resource_id}`),style:Bt(h===`catalog:${$.resource_id}`),children:$.short_name?`${l($.short_name)}${o.detailTab.catalogSuffix}`:o.detailTab.collectionCatalog},$.resource_id)),p.type==="work"&&(_||I)&&e.jsxs("button",{onClick:()=>y("collated"),style:Bt(h==="collated"),children:[o.detailTab.collatedEdition,I&&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(vn,{data:p,transport:t,onNavigate:v}):h.startsWith("catalog:")?e.jsx(jn,{data:(P=m.find($=>`catalog:${$.resource_id}`===h))==null?void 0:P.data,onNavigate:v}):h==="collated"?e.jsx(Ln,{index:_||void 0,workId:p.id,transport:t,onNavigate:v}):null})]}):e.jsx(un,{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: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:A,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:M})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(ln,{transport:t,onEntryClick:C,hideModeIndicator:n}),!p&&e.jsx(un,{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(ln,{transport:t,onEntryClick:C,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:M})]})};function Bt(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 Rr=({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(m=>{s?s(m):a(m)},[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 m=!1;return i.getBookFullTextIndex(n).then(j=>{m||l(j)}),()=>{m=!0}},[n,i,t]),g.useEffect(()=>{if(!o||o.chapters.length===0)return;const m=Ne(o.chapters[0].file);if(!d){p(m);return}const j=Ne(d);o.chapters.some(k=>Ne(k.file)===j)||p(m)},[o,d,p]);const y=g.useMemo(()=>{if(!o||!d)return null;const m=Ne(d);return o.chapters.find(j=>Ne(j.file)===m)??null},[o,d]);return g.useEffect(()=>{if(!n||!y||!i.getBookFullTextChapter)return;let m=!1;return h(!0),f(null),i.getBookFullTextChapter(n,y.file).then(j=>{m||f(j)}).catch(()=>{m||f(null)}).finally(()=>{m||h(!1)}),()=>{m=!0}},[n,y,i]),o?o.chapters.length===0?e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"}):e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"stretch",minHeight:400},children:[e.jsxs("aside",{style:{flex:"0 0 240px",maxHeight:"calc(100vh - 200px)",overflowY:"auto",borderRight:"1px solid var(--bim-border, #e5e5e5)",paddingRight:12},children:[e.jsxs("div",{style:{padding:"8px 12px",fontSize:13,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:[o.version_label," · 共 ",o.total_chapters," ",(o.chapters.length===1,"章")]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.chapters.map(m=>{const j=Ne(m.file),b=j===Ne(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(j),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:b?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:b?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:b?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:m.title})},m.file)})})]}),e.jsxs("main",{style:{flex:1,maxHeight:"calc(100vh - 200px)",overflowY:"auto",paddingLeft:8},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:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},yl=({data:t,onNavigate:n,className:i,style:r})=>{var p;const s=D(),{convert:o}=H(),[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(vl,{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))})]})},vl=({division:t,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:o})=>{const{convert:l}=H(),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(jl,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:o},a.name)})})]})},jl=({category:t,expanded:n,onToggle:i,onNavigate:r})=>{var a,d,p,x;const{convert:s}=H(),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(fi,{label:"著錄",books:o,onNavigate:r}),l.length>0&&e.jsx(fi,{label:"存目",books:l,onNavigate:r})]})]})},fi=({label:t,books:n,onNavigate:i})=>{const{convert:r}=H(),s=he(),[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," 條"]})]})},Se=({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:kl,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Sl,children:o.action.save})]})]}),s]})},Sl={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},kl={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},me=({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"}})},Ht=({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 wl(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const $t=({value:t,onChange:n,label:i})=>{const[r,s]=g.useState(!1),o=g.useRef(null),l=wl(t||"");return g.useEffect(()=>{r&&o.current&&o.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:gi,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(Ht,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:gi,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"}})]})},gi={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function _l(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 Cl(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Er=({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:_l(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Cl(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:We,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(f,"bookID"),style:{...mi,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:{...mi,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:We,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[f]={...u[f],type:"",id:"",name:""},n(u)},style:hi,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:We,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[f]={...u[f],type:"",id:"",name:""},n(u)},style:hi,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:We,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:{...We,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:We,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:We,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:We,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:We,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})]})]})},We={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"},mi={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"},hi={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Br(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 Lr(t){return!t||t.length===0?"":JSON.stringify(t)}const Wr=({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:Il,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:$r(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(bi,{onClick:()=>r(i),title:p,children:"👁️"}),e.jsx(bi,{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(xn,{onClick:o,children:c}),e.jsx(xn,{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:$r(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(xn,{onClick:s,primary:!0,children:["+ ",o]})})]})},bi=({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}),xn=({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 $r(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Il={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"},Ar=({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:Tl,children:e.jsxs("div",{style:zl,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:Rl,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:El})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:tn,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:Bl,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:tn,children:["未找到匹配的",h]}):e.jsxs("div",{style:tn,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:Ll,children:["创建新",h,"并关联"]})]})]})})},Tl={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},zl={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)"},Rl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},El={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"},Bl={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},tn={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Ll={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},yi={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Wl={work:"📜",book:"📖",collection:"📚",entity:"👤"},Mr=({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`创建新${yi[n]}`}};return e.jsx("div",{style:$l,onClick:f=>{f.target===f.currentTarget&&o()},children:e.jsxs("div",{style:Al,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:Wl[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:`请输入${yi[n]}名称...`,style:Ml})]}),((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:Fl,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...Pl,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},$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",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Ml={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"},Fl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Pl={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Hl(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Fr(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ol(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 Pr=({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),[j,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 T=setTimeout(async()=>{m(!0);try{h(await p(x,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(T)},[x,i,p]);const k=g.useCallback(T=>{f(T.target.value),T.target.value.trim()&&b("search")},[]),_=g.useCallback(T=>s?T.filter(z=>z.id!==s):T,[s]);if(!t)return null;const w=n||(i==="all"?"选择实体":`选择${Fr(i)}`),I=_(r),S=_(u);return e.jsx("div",{style:Nl,children:e.jsxs("div",{style:Vl,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:w}),e.jsx("button",{onClick:a,style:Gl,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:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:Yl}),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:"搜索中..."})]})}),I.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(vi,{active:j==="recent",onClick:()=>b("recent"),children:["最近使用 (",I.length,")"]}),e.jsxs(vi,{active:j==="search",onClick:()=>b("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&I.length>0?e.jsx(ji,{entities:I,onSelect:c}):x.trim()?y?e.jsx(nn,{message:"搜索中..."}):S.length>0?e.jsx(ji,{entities:S,onSelect:c}):e.jsx(nn,{message:"未找到匹配的结果"}):e.jsx(nn,{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:Ul,children:l||"创建新实体"})]})]})})},vi=({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}),ji=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(Dl,{entity:i,onClick:()=>n(i)},i.id))}),Dl=({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:Hl(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:Ol(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Fr(t.type)})]})},nn=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Nl={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},Vl={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)"},Gl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},Yl={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"},Ul={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Kl={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)"},Jl={work:"📜",collection:"📚",book:"📖",entity:"👤"},Hr=({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 te;const u=D(),[h,y]=g.useState(!1),[m,j]=g.useState("work"),[b,k]=g.useState(""),[_,w]=g.useState(""),[I,S]=g.useState([]),[T,z]=g.useState(!1),[C,v]=g.useState(!1),[R,E]=g.useState("work"),[A,M]=g.useState(""),[P,$]=g.useState(),[F,Q]=g.useState(!1),[W,Y]=g.useState(null),[ne,B]=g.useState([]);g.useRef(null);const V=t.type,U=V==="work",ie=V==="collection",G=V==="book",K=g.useCallback((L,Z)=>{n({...t,[L]:Z})},[t,n]),de=g.useCallback((L,Z)=>{k(L),j(Z),w(u.editor.selectToLink+u.indexType[Z]),S([]),y(!0)},[u]),Ee=g.useCallback(L=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,L)},[r,t.id]),le=g.useCallback(L=>{s==null||s(L.id,L.type)},[s]),fe=g.useCallback((L,Z,se)=>{const J={...se,author:(se==null?void 0:se.author)||t.author,dynasty:se==null?void 0:se.dynasty};E(Z),M(L),$(J),v(!0)},[t.author]),be=g.useCallback((L,Z)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,A,{type:R,title:L,inheritData:Z}),v(!1)},[r,t.id,A,R]),De=g.useCallback(L=>{if(!L.trim()){S([]);return}z(!0),r!=null&&r.searchEntities&&r.searchEntities(L,m).then(Z=>{S(Z),z(!1)}).catch(()=>{S([]),z(!1)})},[r,m]),_e=g.useCallback(L=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,b,L.id),y(!1)},[r,t.id,b]),Ze=g.useCallback(()=>{i()},[i]),ct=g.useCallback(L=>{Y(()=>L),Q(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(B).catch(()=>{})},[r]),N=g.useCallback((L,Z)=>r!=null&&r.searchEntities?r.searchEntities(L,Z==="all"?void 0:Z):Promise.resolve([]),[r]),re=g.useCallback(L=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(L),B(Z=>[L,...Z.filter(se=>se.id!==L.id)].slice(0,10)),W==null||W(L),Q(!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:Jl[V]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Ht,{children:t.id}),e.jsx(Ht,{color:Kl[V],children:u.indexType[V]})]})}),e.jsx(Se,{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($t,{label:U?u.editor.workTitle:ie?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:L=>K("title",L)}),G&&e.jsx($t,{label:u.editor.belongsToWork,value:t.workName||"",onChange:L=>K("workName",L)}),e.jsx(me,{label:u.editor.authorLabel,value:t.author||"",onChange:L=>K("author",L)}),e.jsx(me,{label:u.editor.publicationYearLabel,value:t.publicationYear||"",onChange:L=>K("publicationYear",L)}),(G||ie)&&e.jsx($t,{label:u.editor.containedIn,value:t.collection||"",onChange:L=>K("collection",L)}),(G||ie)&&e.jsx(me,{label:u.editor.holderLabel,value:t.holder||"",onChange:L=>K("holder",L)}),(G||ie)&&e.jsx(me,{label:G?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:L=>K("pages",L)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(me,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:L=>K("firstImage",L)})})]})}),e.jsx(Se,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Ue,{value:t.description||"",onChange:L=>K("description",L),placeholder:u.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(Se,{title:u.section.additionalWorks,onSave:i,children:e.jsx(ql,{items:t.additional_works||[],onChange:L=>K("additional_works",L)})}),e.jsx(Se,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Xl,{items:t.indexed_by||[],onChange:L=>K("indexed_by",L)})}),e.jsx(Se,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(Zl,{items:t.emendated_by||[],onChange:L=>K("emendated_by",L)})}),e.jsx(Se,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(sn,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(Se,{title:u.section.imageResources,onSave:i,children:e.jsx(sn,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(Se,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Er,{items:Br(t.sources||""),onChange:L=>K("sources",Lr(L)),onOpenEntityPicker:ct})}),(G||ie)&&e.jsx(Se,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Ue,{value:t.provenance||"",onChange:L=>K("provenance",L),placeholder:u.editor.provenancePlaceholder})}),G&&e.jsx(Se,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Ue,{value:t.otherEditions||"",onChange:L=>K("otherEditions",L),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(Wr,{entityType:V,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:Ee,onViewEntity:le,onCreateAndLink:fe,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(Ar,{isOpen:h,entityType:m,title:_,onSelect:_e,onCancel:()=>y(!1),onCreate:()=>{y(!1),fe(b,m)},searchResults:I,onSearch:De,isLoading:T,excludeId:t.id}),e.jsx(Mr,{isOpen:C,entityType:R,relationField:A,inheritData:P,onConfirm:be,onCancel:()=>v(!1)}),e.jsx(Pr,{isOpen:F,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:re,onCancel:()=>{Q(!1),Y(null)},onSearch:N})]})};function ql({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(me,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(me,{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 Or({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(me,{label:s.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),e.jsx(me,{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(me,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),e.jsx(me,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),e.jsx(me,{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 Xl({items:t,onChange:n}){const i=D();return e.jsx(Or,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Zl({items:t,onChange:n}){const i=D();return e.jsx(Or,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function Dr(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 Ql(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 ea=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:j,className:b,style:k}=t;D();const[_,w]=g.useState(s),I=o?s:_;g.useEffect(()=>{s!==_&&w(s)},[s]);const S=g.useCallback(()=>{const A=I==="view"?"edit":"view";o?o(A):w(A)},[I,o]),[T,z]=g.useState(null);g.useEffect(()=>{i&&r&&r.getItem(i).then(A=>{A&&z(A)})},[i,r]);const C=n||T,v=g.useMemo(()=>C?Dr(C):null,[C]),R=o||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:I==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:I==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:I==="view"?"切换到编辑模式":"切换到查看模式",children:I==="view"?"✏️ 编辑":"👁 查看"}):null,E=e.jsxs(e.Fragment,{children:[R,j]});return!C&&!v?e.jsx(Xe,{}):I==="view"?e.jsx(vn,{data:C,transport:r,onNavigate:d?A=>d(A):void 0,renderLink:p,headerExtra:E,className:b,style:k}):v?e.jsxs("div",{className:b,style:k,children:[E&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:E}),e.jsx(Hr,{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:"无数据"})},Si=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Nr=({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=j=>{j.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=Si.find(m=>m.value===s);return e.jsx("div",{style:ta,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:na,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:ia,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:ra,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:ca,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:Si.map(m=>e.jsxs("button",{onClick:()=>o(m.value),style:{...oa,...s===m.value?sa:{}},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:{...la,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:da,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:u,disabled:!h,style:{...aa,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},ta={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},na={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)"},ia={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},ra={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},oa={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"},sa={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},la={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"},aa={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ca={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},da={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},pa=({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:{...ua,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(Nr,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},ua={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"},ki=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Vr=({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=ki.find(u=>u.value===n);return o==="success"?e.jsx("div",{style:wi,children:e.jsxs("div",{style:ha,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:ba,children:"继续提交"})]})}):e.jsxs("div",{style:wi,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:ki.map(u=>e.jsxs("button",{onClick:()=>i(u.value),style:{...xa,...n===u.value?fa:{}},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:{...ga}}),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:{...ma,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:o==="submitting"?"提交中...":"提交"})]}),o==="error"&&e.jsx("div",{style:ya,children:c})]})},wi={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},xa={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"},fa={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ga={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"},ma={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ha={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},ba={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},ya={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function _i(t){return typeof t=="function"?t():t??"/api/feedback"}const Gr=({resourceId:t,apiUrl:n})=>{const[i,r]=g.useState([]),[s,o]=g.useState(!0),l=g.useCallback(async()=>{const a=_i(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=_i(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(Wn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(Vr,{onSubmit:c})})]})},mt={versions:12,catalogs:8,chips:12},Yr={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Ur=({data:t,transport:n,onNavigate:i,renderLink:r,lineageAction:s})=>{var v,R,E,A,M,P,$,F,Q,W,Y,ne;const o=D(),{convert:l}=H(),c=g.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[a,d]=g.useState(new Map),[p,x]=g.useState(!1),[f,u]=g.useState(""),[h,y]=g.useState(!1),[m,j]=g.useState("default"),b=p||!!f||h||m==="year",k=g.useMemo(()=>b?c:c.slice(0,mt.versions),[c,b]);g.useEffect(()=>{if(!n||k.length===0)return;const B=k.filter(U=>!a.has(U));if(B.length===0)return;let V=!1;return Promise.all(B.map(U=>n.getItem(U).then(ie=>{const G=ie??{};return[U,{id:U,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[U,{id:U}]))).then(U=>{V||d(ie=>{const G=new Map(ie);for(const[K,de]of U)G.set(K,de);return G})}),()=>{V=!0}},[n,k,a]);const _=g.useMemo(()=>c.map(B=>a.get(B)??{id:B}),[c,a]),w=g.useMemo(()=>lr(_,t.version_graph,{era:f,scanOnly:h,sort:m}),[_,t.version_graph,f,h,m]),I=p?w.rows:w.rows.slice(0,mt.versions),S=g.useMemo(()=>Vt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),T=g.useMemo(()=>or((t.related_works||[]).map(B=>({id:B.id,title:B.title,relation:B.relation}))),[t.related_works]),z=g.useMemo(()=>{var G,K,de,Ee;const B=[],V=(K=(G=t.authors)==null?void 0:G[0])==null?void 0:K.dynasty;V&&B.push({label:"成書",value:l(V)});const U=Je(t,o.unit.juan);if(U){const le=(de=t.juan_count)==null?void 0:de.description;B.push({label:"卷帙",value:l(U),title:le?l(le):void 0})}const ie=w.allRows.filter(le=>le.sortYear!=null);if(ie.length>0){const le=ie.reduce((fe,be)=>fe.sortYear<=be.sortYear?fe:be);le.era.era&&B.push({label:"最早存世刻本",value:`${le.era.era}${le.era.reign?" "+le.era.reign:""}`,title:le.era.source==="edition"?"據版本題名推斷":void 0})}return(Ee=t.indexed_by)!=null&&Ee.length&&B.push({label:"著錄",value:`${t.indexed_by.length} ${o.unit.bu}`}),B},[t,l,o,w.allRows,b,c.length]),C=c.length===0&&S.buckets.length===0&&S.mirrors.length===0&&!((v=t.indexed_by)!=null&&v.length)&&!((R=t.emendated_by)!=null&&R.length)&&T.length===0&&!((E=t.description)!=null&&E.text);return e.jsxs(e.Fragment,{children:[e.jsxs(It,{facts:z.length?e.jsx(Tt,{items:z}):void 0,children:[((A=t.description)==null?void 0:A.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(M=t.description.sources)!=null&&M.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(B=>l(B)).join(" · ")}):null]}),(P=t.appendix)==null?void 0:P.map((B,V)=>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:l(B.title)}),e.jsx(Ae,{text:B.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},V)),e.jsx(Sr,{rows:[{label:o.section.aliases,items:kt(t.additional_titles)},{label:o.section.attachedTexts,items:kt(t.attached_texts)},{label:o.section.appendix,items:(t.additional_works||[]).map(B=>B.book_title+(B.n_juan!=null?` ${B.n_juan}${o.unit.juan}`:""))}]})]}),c.length>0&&e.jsxs(Re,{children:[e.jsx(ue,{glyph:"版",title:o.section.relatedVersions,count:w.rows.length===w.allRows.length?`${w.allRows.length} 種`:`${w.allRows.length} 種 · 當前 ${w.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(Pe,{label:"僅看有影印",active:h,dashed:!0,onClick:()=>{y(B=>!B),x(!1)}}),e.jsx(Gt,{label:m==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>j(B=>B==="default"?"year":"default")})]})}),w.allRows.length>=6&&w.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(Pe,{label:o.catalog.all,active:!f,onClick:()=>{u(""),x(!1)}}),w.eras.map(B=>e.jsx(Pe,{label:B,active:f===B,onClick:()=>{u(B),x(!1)}},B))]}),e.jsxs(qe,{children:[e.jsx(Ut,{spec:Yr}),I.map((B,V)=>e.jsx(Sa,{row:B,no:V,onNavigate:i,renderLink:r},B.id)),I.length===0&&e.jsx(st,{children:f||h?"當前篩選下沒有版本":"暫無版本著錄"})]}),w.rows.length>I.length&&e.jsx(Oe,{label:`展開其餘 ${w.rows.length-I.length} 種版本`,onClick:()=>x(!0)}),w.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(S.buckets.length>0||S.mirrors.length>0)&&e.jsxs(Re,{children:[e.jsx(ue,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[S.mirrors.map(B=>e.jsx(dn,{title:l(B.label),tag:B.description?l(B.description):void 0,children:B.items.map((V,U)=>e.jsx(ot,{item:V,siblings:B.items},`${V.id||V.url||V.name}-${U}`))},B.key)),S.buckets.map(B=>e.jsx(dn,{title:va[B.key],tag:ja[B.key],children:B.items.map((V,U)=>e.jsx(ot,{item:V,siblings:B.items},`${V.id||V.url||V.name}-${U}`))},B.key))]})]}),($=t.indexed_by)!=null&&$.length||(F=t.emendated_by)!=null&&F.length?e.jsxs("div",{className:(Q=t.emendated_by)!=null&&Q.length?"bim-d-pair":void 0,style:(W=t.emendated_by)!=null&&W.length?void 0:{marginBottom:48},children:[(Y=t.indexed_by)!=null&&Y.length?e.jsx(Ii,{id:"catalogs",glyph:"目",title:o.section.indexed,items:t.indexed_by,unit:o.unit.bu,cap:mt.catalogs,showMeta:!0,t:o,convert:l,onNavigate:i,renderLink:r}):null,(ne=t.emendated_by)!=null&&ne.length?e.jsx(Ii,{id:"studies",glyph:"考",title:o.section.emendated,items:t.emendated_by,unit:o.unit.bu,cap:mt.catalogs,t:o,convert:l,onNavigate:i,renderLink:r}):null]}):null,T.map(B=>e.jsx(ka,{glyph:B.key==="derivative"?"續":"叢",title:o.section[B.labelKey]??o.section.relatedWorks,items:B.items,convert:l,onNavigate:i,renderLink:r},B.key)),C&&e.jsxs(Re,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:o.section.relatedVersions}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},va={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},ja={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function Sa({row:t,no:n,onNavigate:i,renderLink:r}){const{convert:s}=H(),o=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(Kt,{no:Jt(n),spec:Yr,main:e.jsx(we,{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(Ci,{items:t.images,convert:s}),e.jsx(Ci,{items:t.holders,convert:s,fallback:t.locationName})]})})}function Ci({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?jt(l.url):void 0)||n(l.name),a=Mt(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(pn,{href:a,children:c}):c})}const r=t[0],s=(r.url?jt(r.url):void 0)||n(r.name),o=Mt(r);return e.jsxs("span",{style:{minWidth:0},children:[o?e.jsx(pn,{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 Ii({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,k)=>x[k]),m=g.useCallback(()=>{f(y?{}:Object.fromEntries(r.map((b,k)=>[k,!0])))},[y,r]),j=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(Gt,{label:y?"收起全部":"+ 展開提要",onClick:m})}),e.jsx(qe,{children:j.map((b,k)=>{const _=b;return e.jsxs(yr,{open:!!x[k],onToggle:()=>f(w=>({...w,[k]:!w[k]})),main:e.jsxs(e.Fragment,{children:[_.source_bid?e.jsx(we,{id:_.source_bid,label:a(_.source),onNavigate:d,renderLink:p,dense:!0}):a(_.source),l&&_.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(_.section)})]}),action:_.source_bid?e.jsx(we,{id:_.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&&(_.title_info||_.author_info||_.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:[_.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",a(_.title_info)]}),_.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",a(_.author_info)]}),_.edition&&e.jsxs("span",{children:[c.label.edition," ",a(_.edition)]})]}),_.summary&&e.jsx(Wt,{children:He(a(_.summary))}),_.comment&&e.jsx(Wt,{label:c.section.comment,children:He(a(_.comment))}),_.additional_comment&&e.jsx(Wt,{label:c.section.additionalComment,children:He(a(_.additional_comment))}),l&&_.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:_.page})]},k)})}),r.length>j.length&&e.jsx(Oe,{label:`展開其餘 ${r.length-j.length} ${s}`,onClick:()=>h(!0)})]})}function ka({glyph:t,title:n,items:i,convert:r,onNavigate:s,renderLink:o}){const[l,c]=g.useState(!1),a=l?i:i.slice(0,mt.chips);return e.jsxs(Re,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Yt,{children:[a.map(d=>e.jsx(zt,{children:e.jsx(we,{id:d.id,label:r(d.title),onNavigate:s,renderLink:o,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx(Oe,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const wa=8,Kr=({data:t,transport:n,onNavigate:i,renderLink:r})=>{var k,_,w,I;const s=D(),{convert:o}=H(),[l,c]=g.useState(null),[a,d]=g.useState(new Map),[p,x]=g.useState([]),[f,u]=g.useState(!1);g.useEffect(()=>{if(!n||!t.work_id){c(null);return}let S=!1;return n.getItem(t.work_id).then(T=>{!S&&T&&T.type==="work"&&c(T)}).catch(()=>{}),()=>{S=!0}},[n,t.work_id]),g.useEffect(()=>{const S=t.contained_in||[];if(!n||S.length===0){d(new Map);return}let T=!1;return Promise.all(S.map(z=>{const C=typeof z=="string"?z:z.id;return n.getItem(C).then(v=>[C,v]).catch(()=>[C,null])})).then(z=>{if(T)return;const C=new Map;for(const[v,R]of z)R&&C.set(v,R);d(C)}),()=>{T=!0}},[n,t.contained_in]);const h=g.useMemo(()=>{const S=new Set([...(l==null?void 0:l.books)||[],...t.related_books||[]]);return S.delete(t.id),[...S]},[l==null?void 0:l.books,t.related_books,t.id]);g.useEffect(()=>{if(!n||h.length===0){x([]);return}const S=f?h:h.slice(0,wa);let T=!1;return Promise.all(S.map(z=>n.getItem(z).then(C=>({id:z,title:C==null?void 0:C.title,edition:C==null?void 0:C.edition})).catch(()=>({id:z})))).then(z=>{T||x(z)}),()=>{T=!0}},[n,h,f]);const y=g.useMemo(()=>Vt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),m=g.useMemo(()=>{var E,A,M;const S=[],T=Ct(t),z=ur(t);z&&S.push({label:"版本類型",value:z,title:(E=t.lineage)!=null&&E.category?void 0:"據版本題名推斷"}),(T.era||T.reign)&&S.push({label:"刊寫年代",value:[T.era,T.reign].filter(Boolean).join(" "),title:T.source==="edition"?"據版本題名推斷":void 0});const C=(t.contained_in||[]).flatMap(P=>typeof P=="string"?[]:yt(P.volume_index));C.length&&(S.push({label:"冊數",value:`${C.length} ${s.unit.volume}`}),S.push({label:"冊次",value:`第 ${In(C,s.unit.volume)} ${s.unit.volume}`}));const v=Je(t,s.unit.juan);v&&S.push({label:"卷帙",value:o(v)});const R=(t.resources||[]).filter(P=>(P.types||(P.type?[P.type]:[])).includes("physical"));return R.length?S.push({label:"存藏",value:R.slice(0,2).map(P=>o(P.name)).join("、")+(R.length>2?` 等 ${R.length} 處`:"")}):(A=t.current_location)!=null&&A.name&&S.push({label:"存藏",value:o(t.current_location.name)}),(M=t.page_count)!=null&&M.description&&S.push({label:s.label.pageCount,value:t.page_count.description}),S},[t,o,s]),j=!!((k=t.description)!=null&&k.text),b=(t.contained_in||[]).some(S=>typeof S!="string"&&yt(S.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(It,{facts:m.length?e.jsx(Tt,{items:m,horizontal:!j}):void 0,children:j?e.jsx(Ae,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),(t.contained_in||[]).length>0&&e.jsxs(Re,{children:[e.jsx(ue,{glyph:"收",title:s.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((S,T)=>{var E,A;const z=typeof S=="string"?S:S.id,C=typeof S=="string"?[]:yt(S.volume_index),v=a.get(z),R=((E=v==null?void 0:v.books)==null?void 0:E.length)||((A=v==null?void 0:v.contained_works)==null?void 0:A.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(we,{id:z,label:v?o(v.title):z,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} ${s.unit.bu}`,R>0&&C.length>0&&" · ",C.length>0&&`本書佔 ${C.length} ${s.unit.volume}`]})]}),C.length>0&&e.jsx(br,{volumes:C,unit:s.unit.volume})]},`${z}-${T}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[l&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"作",tone:"ink",title:s.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(we,{id:l.id,label:o(l.title),onNavigate:i,renderLink:r})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[o(Je(l,s.unit.juan)),(_=l.authors)==null?void 0:_.map(S=>{const T=Cn(S.role);return`${S.dynasty?`〔${o(S.dynasty)}〕`:""}${o(S.name)}${T?" "+o(T):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((w=l.description)==null?void 0:w.text)&&e.jsx(Ae,{text:l.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(zn,{label:s.section.aliases,items:[...kt(t.additional_titles),...kt(t.attached_texts)]})})]})]}),(y.buckets.length>0||y.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:[y.mirrors.map(S=>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:o(S.label)}),S.items.map((T,z)=>e.jsx(ot,{item:T,showVolumes:!b},`${T.id||T.url||T.name}-${z}`))]},S.key)),y.buckets.flatMap(S=>S.items).map((S,T)=>e.jsx(ot,{item:S,showVolumes:!b},`${S.id||S.url||S.name}-${T}`))]})]})]}),(I=t.location_history)!=null&&I.length?e.jsxs(Re,{children:[e.jsx(ue,{glyph:"藏",tone:"ink",title:s.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((S,T)=>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:o(S.name)}),S.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:o(S.description)})]},T))})]}):null,h.length>0&&e.jsxs(Re,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"版",tone:"ink",title:s.relation.siblingVersions,count:`${h.length} 種`,actions:l?e.jsx(we,{id:l.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:r,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Yt,{children:[p.map(S=>e.jsx(zt,{children:e.jsx(we,{id:S.id,label:o(S.edition||S.title||S.id),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},S.id)),h.length>p.length&&e.jsx(Oe,{inline:!0,label:`更多 ${h.length-p.length} 種`,onClick:()=>u(!0)})]})]})]})},Ti={titles:16,works:16},Jr=({data:t,catalog:n,onNavigate:i,renderLink:r,catalogAction:s})=>{var z,C;const o=D(),{convert:l}=H(),[c,a]=g.useState(""),[d,p]=g.useState(!1),[x,f]=g.useState(!1),u=g.useMemo(()=>dr(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,Ti.titles),m=g.useMemo(()=>Vt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),j=t.contained_works||[],b=new Set(u.rows.map(v=>v.id).filter(Boolean)),k=j.length>0&&!j.every(v=>b.has(v.id)),_=(()=>{const v=u.rows.map(R=>R.edition).filter(Boolean);return v.length>1&&new Set(v).size===1})(),w=x?j:j.slice(0,Ti.works),I=u.sections.length>0,S=g.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...I?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[I]),T=g.useMemo(()=>{var A,M,P,$;const v=[];t.subtype&&v.push({label:o.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(A=t.publication_info)!=null&&A.details&&v.push({label:"刊印",value:l(t.publication_info.details)}),(M=t.publication_info)!=null&&M.year&&v.push({label:"年代",value:t.publication_info.year});const R=((P=t.books)==null?void 0:P.length)||j.length,E=Je(t,o.unit.juan);return(R||E)&&v.push({label:"種數 / 卷數",value:[R?`${R} ${o.unit.bu}`:"",l(E)].filter(Boolean).join(" · "),title:($=t.juan_count)!=null&&$.description?l(t.juan_count.description):void 0}),u.totalVolumes&&v.push({label:"全帙冊數",value:`${u.totalVolumes} ${o.unit.volume}`}),v},[t,j.length,u.totalVolumes,l,o]);return e.jsxs(e.Fragment,{children:[e.jsxs(It,{facts:T.length?e.jsx(Tt,{items:T}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Ae,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(C=t.history)!=null&&C.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((v,R)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",l(v)]},R))}):null]}),u.rows.length>0&&e.jsxs(Re,{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,I&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{label:o.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),u.sections.map(v=>e.jsx(Pe,{label:v,active:c===v,onClick:()=>{a(v),p(!1)}},v))]})]})}),e.jsxs(qe,{children:[e.jsx(Ut,{spec:S}),y.map((v,R)=>{var E;return e.jsx(Kt,{no:Jt(R),spec:S,main:e.jsxs(e.Fragment,{children:[v.id?e.jsx(we,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0}):e.jsx("span",{children:l(v.title)}),(E=v.subItems)!=null&&E.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",v.subItems.map(A=>l(A)).join("、"),")"]}):null,v.edition&&!_&&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:[I&&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?`第 ${In(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}-${R}`)}),y.length===0&&e.jsx(st,{children:o.catalog.noMatch})]}),h.length>y.length&&e.jsx(Oe,{label:`展開其餘 ${h.length-y.length} ${o.unit.items}子目`,onClick:()=>p(!0)})]}),(m.buckets.length>0||k)&&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,R)=>e.jsx(ot,{item:v,fallbackNote:v.details?l(v.details):void 0},`${v.id||v.url||v.name}-${R}`))})]}),k&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:o.section.containedWorks,count:`${j.length} 種`}),e.jsxs(Yt,{children:[w.map(v=>e.jsx(zt,{children:e.jsx(we,{id:v.id,label:l(v.title),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},v.id)),j.length>w.length&&e.jsx(Oe,{inline:!0,label:`更多 ${j.length-w.length} 種`,onClick:()=>f(!0)})]})]})]})]})},_a=16,zi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},rn=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Ri(t){if(!t)return rn.length;const n=rn.indexOf(t);return n===-1?rn.length:n}const qr=({data:t,transport:n,onNavigate:i,renderLink:r})=>{var S,T,z;const s=D(),{convert:o}=H(),[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 R=f.get(v.work_id);return{id:v.work_id,title:(R==null?void 0:R.title)??v.work_id,role:v.role||"",cls:_n(v.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,f]),y=g.useMemo(()=>cr((t.works||[]).map(C=>C.role)),[t.works]),m=g.useMemo(()=>{const C=l==="全部"?h:h.filter(v=>v.cls===l);return p==="versions"?[...C].sort((v,R)=>(R.versionCount??-1)-(v.versionCount??-1)):C},[h,l,p]),j=a?m:m.slice(0,_a),b=g.useMemo(()=>j.filter(C=>!f.has(C.id)).map(C=>C.id),[j,f]);g.useEffect(()=>{if(!n||b.length===0)return;let C=!1;return Promise.all(b.map(v=>n.getItem(v).then(R=>{var M,P;const E=R??{},A=(((M=E.books)==null?void 0:M.length)??0)+(((P=E.collections)==null?void 0:P.length)??0);return[v,{id:v,title:E.title,versionCount:A,loaded:!0}]}).catch(()=>[v,{id:v,loaded:!0}]))).then(v=>{C||u(R=>{const E=new Map(R);for(const[A,M]of v)E.set(A,M);return E})}),()=>{C=!0}},[n,b]);const k=g.useMemo(()=>{const C=new Map;for(const v of t.alt_names||[]){const R=v.type||s.section.aliases;C.has(R)||C.set(R,[]),C.get(R).push(v.name)}return[...C.entries()].sort((v,R)=>Ri(v[0])-Ri(R[0])).map(([v,R])=>({label:v,names:R}))},[t.alt_names,s]),_=g.useMemo(()=>{const C=[];t.dynasty&&C.push({label:"時代",value:o(t.dynasty)});const v=E=>E==null?"":E<0?`前${-E}`:String(E);(t.birth_year!=null||t.death_year!=null)&&C.push({label:"生卒",value:`${v(t.birth_year)||"?"}—${v(t.death_year)||"?"}`});const R=(t.works||[]).length;return R&&C.push({label:"著作數",value:`${R} 種`}),C},[t,o]),w=(S=t.external_ids)==null?void 0:S.cbdb_id,I=!!((T=t.description)!=null&&T.text);return e.jsxs(e.Fragment,{children:[e.jsx(It,{facts:_.length?e.jsx(Tt,{items:_}):void 0,children:(k.length>0||I)&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[k.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:k.map(C=>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(C.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:C.names.map(v=>o(v)).join(" · ")})]},C.label))}),I&&e.jsx(Ae,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),h.length===0&&e.jsxs(Re,{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(Re,{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(Gt,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{x(C=>(C==="default"&&d(!0),C==="default"?"versions":"default"))}})}),y.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:y.map(C=>e.jsx(Pe,{label:`${C.label} ${C.count}`,active:l===C.cls,onClick:()=>{c(C.cls),d(!1)}},C.cls))}),e.jsxs(qe,{children:[e.jsx(Ut,{spec:zi}),j.map((C,v)=>e.jsx(Kt,{no:Jt(v),spec:zi,main:e.jsx(we,{id:C.id,label:o(C.title),onNavigate:i,renderLink:r,dense:!0}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:C.role?o(C.role):e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:C.loaded?C.versionCount?`${C.versionCount} 種版本`:e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},C.id)),j.length===0&&e.jsx(st,{children:"該職任下的著作尚未著錄。"})]}),m.length>j.length&&e.jsx(Oe,{label:`展開其餘 ${m.length-j.length} 條著作`,onClick:()=>d(!0)}),w!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",w,((z=t.external_ids)==null?void 0:z.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function Ca(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 Ia(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 Ei(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 Ta(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 za(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 At(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=za(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 _=new Map(n.map(C=>[C.id,C])),w=new Map((r.hypothetical_nodes??[]).map(C=>[C.id,C])),I=C=>{const v=_.get(C);if(v&&v.lineage)return(v.lineage.derived_from??[]).map(E=>E.ref);const R=w.get(C);return R?(R.derived_from??[]).map(E=>E.ref):[]},S=C=>w.has(C)?!p||p.has(C):!d||d.has(C),T=new Set,z=C=>{if(!T.has(C)){T.add(C);for(const v of I(C))o.has(v)||(S(v)||(w.has(v)?f.add(v):_.has(v)&&x.add(v)),z(v))}};for(const C of n)d&&d.has(C.id)&&!o.has(C.id)&&z(C.id);for(const C of r.hypothetical_nodes??[])p&&p.has(C.id)&&z(C.id)}const u=n.filter(_=>!o.has(_.id)).filter(_=>!d||d.has(_.id)||x.has(_.id)).map(_=>{const w=Ia(_,l);return w&&x.has(_.id)&&(w.bridge=!0),w}).filter(_=>_!==null),h=(r.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||f.has(_.id)).map(_=>{const w=Ca(_);return f.has(_.id)&&(w.bridge=!0),w}),y=[...u,...h],m=new Set(y.map(_=>_.id)),j=new Set,b=[],k=_=>{j.has(_.id)||!m.has(_.source)||!m.has(_.target)||(j.add(_.id),b.push(_))};for(const _ of n)o.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!x.has(_.id)||((_.lineage.derived_from??[]).forEach((w,I)=>{k(Ei(_.id,w,I))}),(_.lineage.related_to??[]).forEach((w,I)=>{k(Ta(_.id,w,I))}));for(const _ of r.hypothetical_nodes??[])p&&!p.has(_.id)&&!f.has(_.id)||(_.derived_from??[]).forEach((w,I)=>{k(Ei(_.id,w,I))});return{nodes:y,edges:b,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(o)}}function Xr(t,n,i){const r=(t??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Ra(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 Zr=({graph:t,renderLink:n,className:i,style:r})=>{const{convert:s}=H();if(!t.nodes.length)return e.jsx("div",{style:{...Va,...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:{...Ba,...r},children:[t.title&&e.jsx("div",{style:La,children:s(t.title)}),t.description&&e.jsx("div",{style:Wa,children:s(t.description)}),x.map(f=>e.jsx(Bi,{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(Bi,{label:"其他",nodes:d,incomingMap:o,siblingMap:l,nodeMap:c,renderLink:n})]})},Bi=({label:t,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:o,renderLink:l})=>{const{convert:c}=H();return e.jsxs("div",{style:$a,children:[e.jsx("div",{style:{...Aa,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(Ea,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:o,renderLink:l},a.id))]})},Ea=({node:t,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const o=t.kind==="hypothetical",l=t.bridge,{convert:c}=H();return e.jsxs("div",{style:{...Ma,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:Fa,children:[e.jsx("span",{style:Pa,children:o||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Ha,children:Xr(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Oa,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:Da,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Na,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Wi,children:[e.jsx("div",{style:$i,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return e.jsxs("div",{style:Ai(a.confidence),children:[e.jsx("span",{style:Mi,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(Li,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Fi,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:Wi,children:[e.jsx("div",{style:$i,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=r.get(d);return e.jsxs("div",{style:Ai(a.confidence),children:[e.jsx("span",{style:Mi,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(Li,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Fi,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})},Li=({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},Ba={fontSize:"14px",color:"var(--bim-fg, #333)"},La={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Wa={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},$a={marginBottom:"16px"},Aa={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ma={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Fa={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Pa={fontSize:"15px",fontWeight:600},Ha={fontSize:"12px",color:"var(--bim-muted, #777)"},Oa={marginBottom:"6px"},Da={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Na={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Wi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},$i={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Ai=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Mi={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Fi={fontSize:"11px",color:"var(--bim-muted, #888)"},Va={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Qr=({selectedNodeId:t,...n})=>{const[i,r]=g.useState("loading"),[s,o]=g.useState(null);return g.useEffect(()=>{let l=!1;return Ga().then(c=>{l||(c?(o(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:Pi,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:Pi,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(Ya,{modules:s,selectedNodeId:t,...n})};async function Ga(){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 Ya=({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:I=>{var P,$,F,Q;const S=((P=I.data)==null?void 0:P.stepPosition)??.85,[T,z,C]=h({sourceX:I.sourceX,sourceY:I.sourceY,sourcePosition:I.sourcePosition,targetX:I.targetX,targetY:I.targetY,targetPosition:I.targetPosition,stepPosition:S,borderRadius:5}),v=!!(($=I.data)!=null&&$.isSibling),R=v?z:I.targetX-18,E=v?C:I.targetY-12,A=(F=I.data)==null?void 0:F.labelStyle,M=(Q=I.data)==null?void 0:Q.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(f,{id:I.id,path:T,style:I.style,markerStart:I.markerStart,markerEnd:I.markerEnd}),I.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)",...M,...A},children:I.label})})]})}}),[f,u,h]),j=g.useMemo(()=>({version:I=>{const S=I.data,T=S.kind==="hypothetical",z=S.status==="lost",C=S.isSelected,v=S.bridge,R=S.borderColor??"var(--bim-muted, #888)",E=v||T?"dashed":"solid",A=v?.5:z?.6:1;return e.jsxs("div",{style:{background:v?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${E} ${C?"var(--bim-primary, #0078d4)":R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:C?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":T||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||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:Xr(S.yearText,void 0,S.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}=H(),{rfNodes:k,rfEdges:_}=g.useMemo(()=>Ua(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:k,edges:_,nodeTypes:j,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 Ua(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(j=>[j.id,j.color??"var(--bim-muted, #888)"]));for(const j of t.nodes)a.setNode(j.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(p.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const x=t.nodes.map(j=>{const b=a.node(j.id),k=r&&j.id===r,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Ja(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:_,draggable:!1,selected:k}}),f=.78,u=.06,h=new Map;for(const j of t.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const y=new Map;for(const[j,b]of h){if(b.length<=1)continue;const k=[...b].sort((w,I)=>{var z,C;const S=((z=a.node(w.target))==null?void 0:z.y)??0,T=((C=a.node(I.target))==null?void 0:C.y)??0;return S-T}),_=k.length;k.forEach((w,I)=>{const S=(I-(_-1)/2)*u;y.set(w.id,f+S)})}const m=t.edges.map(j=>Ka(j,y.get(j.id),s));return{rfNodes:x,rfEdges:m}}function Ka(t,n,i=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",o=qa(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 Ja(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function qa(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 Pi={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)"},eo=({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=k=>{u(k),o==null||o(k)},y=(()=>{if(!a)return[];const k=Object.entries(a);return k.length===0||a.all?k:[...k,["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 j=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:Xa,children:[e.jsx("button",{onClick:()=>h("list"),style:on(f==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:on(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(([k,_])=>{const w=d==null?void 0:d[k];return e.jsxs("button",{onClick:()=>c==null?void 0:c(k),style:on(l===k),title:_.description,children:[_.label,w!=null?` ${w}`:""]},k)})]})]}),m&&j&&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:j}),f==="list"?e.jsx(Zr,{graph:t,renderLink:i}):e.jsx(Qr,{graph:t,renderLink:i,height:r,selectedNodeId:s})]})},Xa={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},on=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"}),to=({style:t})=>{const n=g.useContext(wt);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:"简"})]})},no=({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"})})}),Za=({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:j,extraTabs:b=[],showFeedbackTab:k=!0,feedbackApiUrl:_,height:w,footerExtra:I,className:S,style:T})=>{const z=D(),{convert:C}=H(),[v,R]=g.useState(null),[E,A]=g.useState(null),[M,P]=g.useState(!0),[$,F]=g.useState(!1),[Q,W]=g.useState([]),[Y,ne]=g.useState(!1),[B,V]=g.useState(null),[U,ie]=g.useState(!1),[G,K]=g.useState(null),[de,Ee]=g.useState(!1),[le,fe]=g.useState(null),[be,De]=g.useState(!1),_e=g.useRef(null),[Ze,ct]=g.useState(null),N=s!==void 0?s:Ze,re=g.useCallback(O=>{o?o(O):ct(O)},[o]),te=g.useCallback(async O=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ne(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(O)||[]);else if(n.getCollectionCatalog){const oe=await n.getCollectionCatalog(O);W(oe?[{resource_id:"",data:oe}]:[])}}catch{W([])}finally{ne(!1)}},[n]),L=g.useCallback(async O=>{if(!n.getCollatedEditionIndex){V(null);return}ie(!0);try{V(await n.getCollatedEditionIndex(O))}catch{V(null)}finally{ie(!1)}},[n]),Z=g.useCallback(async O=>{if(!n.getBookFullTextIndex){K(null);return}Ee(!0);try{K(await n.getBookFullTextIndex(O))}catch{K(null)}finally{Ee(!1)}},[n]),se=g.useCallback(async(O,oe)=>{De(!0);try{if(n.getLineageGraph){const Le=await n.getLineageGraph(O);Le&&fe(Le)}const ae=oe.version_graph;if(!ae||!ae.enabled){le||fe(null),_e.current=null;return}const ce=oe.books??[],ee=[];for(const Le of ce)try{const Ce=await n.getItem(Le);Ce&&ee.push(Ce)}catch{}_e.current={work:oe,books:ee};const q=a??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Be=q==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":q??"all";fe(At(oe,ee,Be))}catch{fe(null),_e.current=null}finally{De(!1)}},[n]);g.useEffect(()=>{let O=!1;return(async()=>{P(!0),F(!1),R(null),A(null),W([]),V(null),fe(null),_e.current=null;try{const ae=await n.getItem(t);if(O)return;if(!ae){F(!0);return}const ce=ae;let ee=null;if(n.getEntry&&(ee=await n.getEntry(t),O))return;ee||(ee={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),m&&m(ee,ce),R(ee),A(ce),ce.type==="collection"?te(t):ce.type==="work"?((ce.has_collated||n.getCollatedEditionIndex)&&L(t),(ce.version_graph||n.getLineageGraph)&&se(t,ce)):ce.type==="book"&&ce.has_full_text&&n.getBookFullTextIndex&&Z(t)}catch{O||F(!0)}finally{O||P(!1)}})(),()=>{O=!0}},[t,n,m,te,L,se,Z]),g.useEffect(()=>{const O=_e.current;!O||!a||fe(At(O.work,O.books,a))},[a]);const J=[];if(E){if(J.push({key:"basic",label:z.detailTab.basicInfo}),E.type==="collection"){Y&&Q.length===0&&J.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const O of Q)J.push({key:`catalog:${O.resource_id}`,label:O.short_name?`${C(O.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}E.type==="work"&&(B||U)&&J.push({key:"collated",label:U?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),E.type==="book"&&(G||de)&&J.push({key:"fulltext",label:de?`${z.detailTab.fullText}…`:z.detailTab.fullText}),E.type==="work"&&(le||be)&&J.push({key:"lineage",label:be?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const O of b)(O.position??"before-feedback")==="before-feedback"&&O.shouldShow(E)&&J.push({key:O.key,label:O.label});k&&i==="feedback"&&J.push({key:"feedback",label:z.detailTab.feedback});for(const O of b)O.position==="after-feedback"&&O.shouldShow(E)&&J.push({key:O.key,label:O.label})}g.useEffect(()=>{if(i!=="emendated"||!E)return;r("basic");const O=setTimeout(()=>{var oe;(oe=document.getElementById("studies"))==null||oe.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(O)},[i,E,r]);const Fe=v&&E&&j?j({activeTab:i,activeJuan:N,entry:v,detail:E}):null,je=g.useMemo(()=>{var ee;if(!E)return null;const oe=(E.authors??[]).map(q=>{const Be=Cn(q.role);return`${q.dynasty?`〔${C(q.dynasty)}〕`:""}${C(q.name)}${Be?` ${C(Be)}`:""}`}).join(" · ");let ae=!1;try{ae=X.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const q=E;return{title:C(q.title),subtitle:q.edition?C(q.edition):oe||void 0,aside:[ae?z.status.draft:"",oe&&q.edition?oe:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const q=E;return{title:C(q.title),subtitle:C(Je(q,z.unit.juan))||void 0,aside:[(ee=q.publication_info)==null?void 0:ee.year,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:oe||void 0}}if(E.type==="entity"){const q=E,Be=Ce=>Ce==null?"":Ce<0?`前${-Ce}`:String(Ce),Le=q.birth_year!=null||q.death_year!=null?`${Be(q.birth_year)||"?"}—${Be(q.death_year)||"?"}`:"";return{title:C(q.primary_name||q.title),subtitle:[q.dynasty?`〔${C(q.dynasty)}〕`:"",Le].filter(Boolean).join(" ")||void 0,aside:ae?z.status.draft:void 0,secondLine:void 0}}const ce=C(Je(E,z.unit.juan));return{title:C(E.title),subtitle:[ce,oe].filter(Boolean).join(" · ")||void 0,aside:[E.subtype,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,C,z]),ge=()=>{var O;return E?E.type==="work"?e.jsx(Ur,{data:E,transport:n,onNavigate:f,renderLink:y,lineageAction:le&&le.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(Kr,{data:E,transport:n,onNavigate:f,renderLink:y}):E.type==="collection"?e.jsx(Jr,{data:E,catalog:(O=Q[0])==null?void 0:O.data,transport:n,onNavigate:f,renderLink:y,catalogAction:Q.length>0?e.jsxs("button",{type:"button",onClick:()=>r(`catalog:${Q[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:E,transport:n,onNavigate:f,renderLink:y}):null},Qe=()=>{var oe,ae,ce;if(!v||!E)return null;if(i==="basic"||i==="emendated")return ge();if(typeof i=="string"&&i.startsWith("catalog:")){const ee=(oe=Q.find(q=>`catalog:${q.resource_id}`===i))==null?void 0:oe.data;return e.jsx(jn,{data:ee,onNavigate:f,renderLink:y})}if(i==="collated")return e.jsx(Ln,{index:B||void 0,workId:t,transport:n,onNavigate:f,activeJuan:N,onJuanChange:re});if(i==="fulltext")return e.jsx(Rr,{index:G||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:re});if(i==="lineage"){if(!le)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:be?"加載中…":"暫無版本圖數據"});const ee=E.type==="work"?E:null;return e.jsx(eo,{graph:le,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 Ce,$n,An,Mn,Fn,Pn,Hn;if(!ee)return;const q={},Be=((Ce=_e.current)==null?void 0:Ce.books)??[];q.all=((($n=ee.books)==null?void 0:$n.length)??0)-(((Mn=(An=ee.version_graph)==null?void 0:An.excluded_books)==null?void 0:Mn.length)??0);const Le=(Fn=ee.version_graph)==null?void 0:Fn.collections;if(Le)for(const On of Object.keys(Le))q[On]=At(ee,Be,On).nodes.filter(Dn=>Dn.kind==="book"&&!Dn.bridge).length;return q.core==null&&((Hn=(Pn=ee.version_graph)==null?void 0:Pn.core_books)!=null&&Hn.length)&&(q.core=ee.version_graph.core_books.length),q})()})}if(i==="feedback"&&k)return e.jsx(Gr,{resourceId:t,apiUrl:_});const O=b.find(ee=>ee.key===i);return O?O.render({detail:E,entry:v,transport:n,onNavigate:f}):null};if(M)return e.jsx(Lt,{style:{minHeight:w,...T},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((O,oe)=>e.jsx("div",{style:{height:oe===1?40:16,width:O,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},oe))})});if($||!E||!v||!je)return e.jsx(Lt,{style:{minHeight:w,...T},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const io=i==="basic"||i==="emendated",qt=[{label:h??z.detailTab.backToIndex,onClick:u}];if(E.type==="book"&&E.work_id){const O=E.work_id;qt.push({label:z.indexType.work,id:O,onClick:()=>f==null?void 0:f(O)})}return qt.push({label:z.indexType[E.type]}),e.jsx("div",{className:S,children:e.jsxs(Lt,{style:{minHeight:w,...T},children:[e.jsx(gr,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Tn,{char:"籍"}),e.jsx(mr,{items:qt})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(to,{}),k&&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(no,{...Fe})]})}),e.jsx(hr,{...je}),J.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:J.map(O=>e.jsx(Pe,{label:O.label,active:O.key===i||io&&O.key==="basic",onClick:()=>r(O.key)},O.key))}),e.jsx("div",{style:{marginTop:J.length>1?8:0},children:Qe()}),e.jsx(kr,{left:e.jsxs(e.Fragment,{children:[I,I?" · ":"",e.jsx(Qa,{id:E.id,label:z.label.id,copied:z.action.copied})]}),right:e.jsxs(e.Fragment,{children:[k&&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 Qa({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?"✓":"⧉"})]})}exports.BidLink=X.BidLink;exports.BookIndexError=X.BookIndexError;exports.BookIndexManager=X.BookIndexManager;exports.BookIndexStorage=X.BookIndexStorage;exports.BundleStorage=X.BundleStorage;exports.ConfigError=X.ConfigError;exports.GithubStorage=X.GithubStorage;exports.IdGenerationError=X.IdGenerationError;exports.IdGenerator=X.IdGenerator;exports.LocalStorage=X.LocalStorage;exports.MigrationError=X.MigrationError;exports.StorageError=X.StorageError;exports.base36Decode=X.base36Decode;exports.base36Encode=X.base36Encode;exports.base58Decode=X.base58Decode;exports.buildId=X.buildId;exports.buildPromotionMap=X.buildPromotionMap;exports.cleanName=X.cleanName;exports.decodeId=X.decodeId;exports.decodeIdString=X.decodeIdString;exports.encodeId=X.encodeId;exports.extractIdFromUrl=X.extractIdFromUrl;exports.extractStatus=X.extractStatus;exports.extractType=X.extractType;exports.normalizeCatalog=X.normalizeCatalog;exports.parseId=X.parseId;exports.shardOf=X.shardOf;exports.smartDecode=X.smartDecode;exports.validateResource=X.validateResource;exports.Badge=Ht;exports.BidUrlProvider=go;exports.BookDetailLayout=Za;exports.BookFullText=Rr;exports.BookPage=Kr;exports.Breadcrumb=mr;exports.Chip=zt;exports.ChipWall=Yt;exports.CollatedEdition=Ln;exports.CollectionCatalog=jn;exports.CollectionPage=Jr;exports.CreateEntityDialog=Mr;exports.DETAIL_CSS=fr;exports.Dash=rt;exports.DataTable=qe;exports.DetailFooter=kr;exports.DetailHeader=hr;exports.EmendatedBySection=er;exports.EmptyNote=st;exports.EntityDetail=Ki;exports.EntityPage=qr;exports.EntityPickerDialog=Pr;exports.EntitySelector=Ar;exports.ExpandRow=yr;exports.ExtLink=pn;exports.FactList=Tt;exports.FeedbackButton=pa;exports.FeedbackDialog=Nr;exports.FeedbackForm=Vr;exports.FeedbackList=Wn;exports.FeedbackTab=Gr;exports.FilterChip=Pe;exports.FormInput=me;exports.FormTextArea=Ue;exports.GlyphBadge=Tn;exports.HomePage=un;exports.IndexApp=bl;exports.IndexBrowser=ln;exports.IndexDetail=vn;exports.IndexEditor=Hr;exports.IndexView=ea;exports.IntroGrid=It;exports.LocaleContext=wt;exports.LocaleProvider=wo;exports.LocaleToggle=to;exports.ModeIndicator=Yi;exports.MoreButton=Oe;exports.PAGE_MAX_WIDTH=xr;exports.PageFrame=Lt;exports.Quote=Wt;exports.ROLE_CLASS_ORDER=ar;exports.RelationPanel=Wr;exports.RepoSourceLink=no;exports.ResourceEditor=sn;exports.ResourceGroup=dn;exports.ResourceLine=ot;exports.ResourceList=yn;exports.ResourceRow=vr;exports.SearchInput=Ui;exports.Section=Se;exports.SectionHead=ue;exports.SmartBidInput=$t;exports.SourceEditor=Er;exports.TableHead=Ut;exports.TableRow=Kt;exports.TagRow=zn;exports.TagRows=Sr;exports.TextButton=Gt;exports.TopStrip=gr;exports.VersionLineageGraph=Qr;exports.VersionLineageList=Zr;exports.VersionLineageView=eo;exports.VolumeChips=br;exports.VolumeLinks=jr;exports.WorkCatalog=yl;exports.WorkPage=Ur;exports.bucketResources=Vt;exports.buildCollectionTable=dr;exports.buildLineageGraph=At;exports.buildPageUrl=bn;exports.buildVersionRow=sr;exports.buildVersionTable=lr;exports.computeVersionPartition=zs;exports.deriveDating=Cs;exports.deriveEditionType=ur;exports.deriveEra=Ct;exports.deriveYear=Nt;exports.deriveYearRange=kn;exports.detailToEditor=Dr;exports.displayAuthorRole=Cn;exports.editorToDetail=Ql;exports.eraRank=cn;exports.flattenTitles=kt;exports.formatTemplate=_t;exports.formatVolumeRange=In;exports.getDisplayNameFromUrl=jt;exports.getStartPage=hn;exports.getTypeGroupKey=fn;exports.groupRelatedWorks=or;exports.measureText=Je;exports.mergeVolumeResources=gn;exports.normalizeEra=pe;exports.normalizeRole=_n;exports.normalizeVolumeIndex=yt;exports.normalizeVolumes=Gi;exports.numberToChinese=pr;exports.parseChineseNumber=Ft;exports.parseSourceString=Br;exports.resourceHref=Mt;exports.resourceNote=wn;exports.roleFacets=cr;exports.rowNo=Jt;exports.sortYear=rr;exports.stringifySources=Lr;exports.useBidUrl=he;exports.useConvert=H;exports.useT=D;exports.validateLineageGraph=Ra;exports.volumeStats=mn;
|