book-index-ui 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +13 -5
- package/dist/index.js +1739 -1723
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var Vo=Object.create;var Rn=Object.defineProperty;var Go=Object.getOwnPropertyDescriptor;var Uo=Object.getOwnPropertyNames;var Yo=Object.getPrototypeOf,Ko=Object.prototype.hasOwnProperty;var Jo=(t,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Uo(n))!Ko.call(t,s)&&s!==i&&Rn(t,s,{get:()=>n[s],enumerable:!(o=Go(n,s))||o.enumerable});return t};var et=(t,n,i)=>(i=t!=null?Vo(Yo(t)):{},Jo(n||!t||!t.__esModule?Rn(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("./storage-entry-BszwT2ej.cjs"),e=require("react/jsx-runtime"),u=require("react"),qo=require("react-markdown"),Xo=require("remark-gfm"),Zo=require("react-dom"),Qo=t=>`/book-index?id=${t}`,_i=u.createContext(Qo);function er({buildUrl:t,children:n}){const i=u.useMemo(()=>t,[t]);return e.jsx(_i.Provider,{value:i,children:n})}function me(){return u.useContext(_i)}function Pe(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function tr(t,n){return Pe(t).includes(n)}const Ci={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},nr={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},ir={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},mt=u.createContext(null),Ii={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:"收入",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:"圖片資源"}},or={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:"收入",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:"图片资源"}},rr={"zh-Hant":Ii,"zh-Hans":or},Ti="bim-locale";function sr(){try{const t=localStorage.getItem(Ti);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function lr(t){try{localStorage.setItem(Ti,t)}catch{}}const ar="zh-Hans",cr=({locale:t,onLocaleChange:n,children:i})=>{const[o,s]=u.useState(t??ar),r=t??o;u.useEffect(()=>{if(t)return;const p=sr();p&&p!==o&&s(p)},[]);const[l,c]=u.useState(null);u.useEffect(()=>{r==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const f=p.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>p=>p)}):c(null)},[r]);const a=u.useCallback(p=>{s(p),lr(p),n==null||n(p)},[n]),d=u.useMemo(()=>({locale:r,setLocale:a,messages:rr[r],converter:l}),[r,a,l]);return e.jsx(mt.Provider,{value:d,children:i})};function N(){const t=u.useContext(mt);return(t==null?void 0:t.messages)??Ii}const dr=2e3;function O(){const t=u.useContext(mt),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,o=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const r=u.useCallback(l=>{if(!l)return"";if(!i)return l;const c=o.current.get(l);if(c!==void 0)return c;const a=i(l);if(o.current.size>=dr){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(l,a),a},[i]);return u.useMemo(()=>({convert:r,locale:n,isSimplified:n==="zh-Hans"}),[r,n])}function ht(t,n){return t.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}function pr(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 ur(){return{id:"",name:"",url:"",type:"text",details:""}}const qt=({items:t,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const r=N(),[l,c]=u.useState(null),a=[{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=Pe(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},f=t.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>p(y)),g=()=>{const y=ur();s&&(y.type=s),n([...t,y]),c(t.length)},x=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 I=pr(_);I&&(w[y].id=I)}n(w)},v=(y,k,_)=>{const I={...t[y].metadata||{}};_?I[k]=_:delete I[k],h(y,"metadata",Object.keys(I).length>0?I: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 I=t[y].coverage||{level:1,ranges:""};k==="level"?I.level=parseInt(_)||1:I.ranges=_,h(y,"coverage",I.ranges?I:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,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:xr(y.type??"text"),color:"#fff"},children:(()=>{var T,z;const S=Pe(y);return S.length===0?y.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: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&&fr(k,o==null?void 0:o[k],i,r),e.jsx("button",{onClick:S=>{S.stopPropagation(),x(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisResource,children:"✕"})]}),l===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[tr(y,"image")&&y.url&&gr(y,r),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:tt,children:[e.jsx("span",{style:nt,children:r.label.type}),e.jsx("select",{value:y.type,onChange:S=>h(k,"type",S.target.value),style:{..._e,flex:1},children:a.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:tt,children:[e.jsx("span",{style:nt,children:r.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:S=>h(k,"root_type",S.target.value),style:{..._e,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:{..._e,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:{..._e,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:S=>h(k,"url",S.target.value),placeholder:r.editor.resourceUrl,style:_e}),e.jsx("input",{type:"text",value:((_=y.structure)==null?void 0:_.join("、"))||"",onChange:S=>m(k,S.target.value),placeholder:r.editor.structurePlaceholder,style:_e}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:tt,children:[e.jsx("span",{style:nt,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:{..._e,width:"60px"}})]}),e.jsxs("label",{style:{...tt,flex:1},children:[e.jsx("span",{style:nt,children:r.label.coverageRange}),e.jsx("input",{type:"text",value:((I=y.coverage)==null?void 0:I.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:r.editor.coverageRangePlaceholder,style:{..._e,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:r.editor.detailsPlaceholder,style:{..._e,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,T])=>{var z;return e.jsxs("label",{style:{...tt,gap:"4px"},children:[e.jsx("span",{style:{...nt,minWidth:"56px"},children:T}),e.jsx("input",{type:"text",value:((z=y.metadata)==null?void 0:z[S])||"",onChange:C=>v(k,S,C.target.value),placeholder:T,style:{..._e,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 xr(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 fr(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:l=>{l.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 gr(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 _e={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"},tt={display:"flex",alignItems:"center",gap:"6px"},nt={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},mr={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function xt(t){try{return mr[new URL(t).hostname]}catch{return}}const En={text:0,image:1,physical:2};function nn(t){return t.length===0?"physical":[...t].sort((n,i)=>(En[n]??99)-(En[i]??99)).join("+")}function on(t){const n=l=>{const c=l.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},i=new Map;for(let l=0;l<t.length;l++){const c=t[l];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[d,p]=a,f=`${d}|${nn(Pe(c))}`;i.has(f)||i.set(f,{base:{...c,name:d,url:"",volumes:[]},volumes:[],indices:[]});const g=i.get(f);g.volumes.push({volume:p,url:c.url||void 0,status:"found"}),g.indices.push(l)}const o=[],s=new Set;for(const l of i.values())if(!(l.volumes.length<2)){l.volumes.sort((c,a)=>c.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,o.push(l.base);for(const c of l.indices)s.add(c)}const r=[...o];for(let l=0;l<t.length;l++)s.has(l)||r.push(t[l]);return r}function zi(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 Ri(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||zi(n)}))}function rn(t){const n=Ri(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 sn(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 ln(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 Et(t){if(!t.url)return;const n=sn(t.metadata);return n?ln(t.url,n):t.url}const Bn={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 hr(t){return t.includes("text")&&t.includes("image")?Bn["text+image"]:Bn[t[0]||"physical"]}const an=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const r=N(),{convert:l}=O(),c=u.useMemo(()=>on(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=u.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=I=>I.group_role==="origin"?0:I.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},f=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(Nt,{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: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(Nt,{item:w,onNavigate:o,renderLink:s},w.id||I))})]},`group-${m}`)},x=new Map;for(const m of d){const j=nn(Pe(m));x.has(j)||x.set(j,[]),x.get(j).push(m)}const h=["text","image","text+image","physical"],v=[...h.filter(m=>x.has(m)),...[...x.keys()].filter(m=>!h.includes(m)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([m,j])=>g(m,j)),v.map(m=>{const j=x.get(m),y=hr(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:f(m)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>e.jsx(Nt,{item:k,onNavigate:o,renderLink:s},k.id||_))})]},m)})]})},br={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)"}},Nt=({item:t})=>{const n=N(),{convert:i}=O(),[o,s]=u.useState(!1),r=u.useMemo(()=>(t.url?xt(t.url):void 0)||i(t.name),[t.url,t.name,i]),l=u.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||zi(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),f=t.color_mode?{...br[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?i(t.details):null,x={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:x,children:[e.jsx("span",{style:{fontWeight:500},children:r}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",p,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=sn(t.metadata);return h?ln(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:l.map(h=>{const v=h.status==="missing";return h.url&&!v?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:v?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1},children:h.volume},h.volume)})})]})},Ei=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:r,onSelectFolder:l})=>{const c=N(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",f=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)"},x={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"},...x,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:o,title:c.mode.switchToSync,style:g,...x,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...x,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):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,...x,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:f||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...x,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...x,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...x,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&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:f})]})]})},Wt="bim-search-history",Ln=10,Wn=8;function ct(){try{const t=localStorage.getItem(Wt);return t?JSON.parse(t):[]}catch{return[]}}function yr(t){try{const n=ct().filter(i=>i!==t);n.unshift(t),n.length>Ln&&(n.length=Ln),localStorage.setItem(Wt,JSON.stringify(n))}catch{}}function vr(t){try{const n=ct().filter(i=>i!==t);localStorage.setItem(Wt,JSON.stringify(n))}catch{}}function jr(){try{localStorage.removeItem(Wt)}catch{}}const Bi=({transport:t,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:r})=>{const l=N(),c=r??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=u.useState(!1),[f,g]=u.useState([]),[x,h]=u.useState(-1),[v,m]=u.useState(ct),j=u.useRef(null),y=u.useRef(null),k=u.useRef(null),_=u.useRef(!1);u.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,Wn).then(A=>{if(R)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];g(M.slice(0,Wn).map(P=>({type:"entry",text:P.title||P.id,entry:P})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,v,t]),u.useEffect(()=>{const b=R=>{k.current&&!k.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]),u.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=u.useCallback(b=>{b.trim()&&(yr(b.trim()),m(ct())),o(b),p(!1)},[o]),I=u.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=u.useCallback(b=>{if(!d||f.length===0){b.key==="Enter"&&w(n);return}switch(b.key){case"ArrowDown":b.preventDefault(),h(R=>(R+1)%f.length);break;case"ArrowUp":b.preventDefault(),h(R=>(R-1+f.length)%f.length);break;case"Enter":b.preventDefault(),x>=0&&x<f.length?I(f[x]):w(n);break;case"Escape":b.preventDefault(),p(!1);break}},[d,f,x,n,w,I]),T=u.useCallback((b,R)=>{R.stopPropagation(),vr(b),m(ct()),g(E=>E.filter(A=>!(A.type==="history"&&A.text===b)))},[]),z=u.useCallback(b=>{b.stopPropagation(),jr(),m([]),g([])},[]);u.useEffect(()=>{if(x>=0&&y.current){const b=y.current.children;b[x]&&b[x].scrollIntoView({block:"nearest"})}},[x]);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&&f.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: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})]}),f.map((b,R)=>e.jsxs("div",{onClick:()=>I(b),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:R===x?"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:[a[b.entry.type],b.entry.edition&&` · ${b.entry.edition}`,b.entry.author&&` · ${b.entry.author}`]}),b.type==="history"&&e.jsx("button",{onClick:E=>T(b.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:"×"})]},`${b.type}-${b.text}-${R}`))]})]})},ft="bim-recent-ids",$n="bim-recent-entries",An=50,Vt=5,Sr=50,kr=200;function dt(){try{const t=localStorage.getItem(ft);if(t)return JSON.parse(t);const n=localStorage.getItem($n);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(ft,JSON.stringify(i)),localStorage.removeItem($n),i}return[]}catch{return[]}}function wr(t){try{const n=dt().filter(i=>i!==t);n.unshift(t),n.length>An&&(n.length=An),localStorage.setItem(ft,JSON.stringify(n))}catch{}}function _r(t){try{const n=dt().filter(i=>i!==t);localStorage.setItem(ft,JSON.stringify(n))}catch{}}function Cr(){try{localStorage.removeItem(ft)}catch{}}const Ir={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xt=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:f,initialQuery:g,onQueryChange:x,headerRight:h})=>{const v=N(),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]=u.useState(g??""),[k,_]=u.useState(null),[w,I]=u.useState(null),[S,T]=u.useState(!1),[z,C]=u.useState(null),[b,R]=u.useState(""),[E,A]=u.useState(!g),[M,P]=u.useState(dt),[$,F]=u.useState([]),[W,B]=u.useState(!1),[D,te]=u.useState(!1),[G,Z]=u.useState(null),[re,ne]=u.useState(null),U=u.useRef(void 0),Y=u.useRef(!1),ce=u.useCallback(async(V,ie)=>{if(!V.trim()){A(!0),_(null),I(null);return}A(!1),T(!0),R("");try{if(t.searchAll){const ee=await t.searchAll(V,ie??Vt);_(ee)}else{const ee=["work","book","collection","entity"],L=await Promise.all(ee.map(X=>t.search(V,X,{page:1,pageSize:ie??Vt})));_({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(ee){R(ee instanceof Error?ee.message:String(ee)),_(null)}finally{T(!1)}},[t]);u.useEffect(()=>{let V=!1;const ie=()=>{var J,Be;const ee=["work","book","collection","entity"],L=Promise.all(ee.map(be=>t.loadEntries(be,{page:1,pageSize:1}).catch(()=>({total:0})))),X=((J=t.getResourceCounts)==null?void 0:J.call(t).catch(()=>null))??Promise.resolve(null),se=((Be=t.getSubtypeStats)==null?void 0:Be.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([L,X,se]).then(([be,pe,Ve])=>{V||(Z({works:be[0].total,books:be[1].total,collections:be[2].total,entities:be[3].total,hasText:pe==null?void 0:pe.hasText,hasImage:pe==null?void 0:pe.hasImage}),Ve&&ne(Ve))})};return t.getCounts?t.getCounts().then(ee=>{var L,X;V||(Z({works:ee.works,books:ee.books,collections:ee.collections,entities:ee.entities,hasText:(L=ee.resourceCounts)==null?void 0:L.hasText,hasImage:(X=ee.resourceCounts)==null?void 0:X.hasImage}),ee.subtypeStats&&ne(ee.subtypeStats))}).catch(()=>{V||ie()}):ie(),()=>{V=!0}},[t]),u.useEffect(()=>{Y.current||!(g!=null&&g.trim())||(Y.current=!0,ce(g))},[g,ce]);const Oe=u.useCallback(V=>{if(y(V),!V.trim()){x==null||x(V),A(!0),_(null),I(null);return}U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{I(null),x==null||x(V),ce(V)},kr)},[ce,x]),Se=u.useCallback(V=>{U.current&&clearTimeout(U.current),x==null||x(V),ce(V)},[ce,x]),he=u.useCallback(V=>{I(V),ce(j,Sr)},[j,ce]);u.useEffect(()=>{if(!M.length){F([]);return}let V=!1;return B(!0),Promise.all(M.slice(0,10).map(async ie=>{var ee,L,X;try{if(t.getEntry){const J=await t.getEntry(ie);if(J)return J}const se=await t.getItem(ie);if(se){const J=se.authors;return{id:ie,title:se.title||ie,type:se.type||"work",author:(ee=J==null?void 0:J[0])==null?void 0:ee.name,dynasty:(L=J==null?void 0:J[0])==null?void 0:L.dynasty,role:(X=J==null?void 0:J[0])==null?void 0:X.role,edition:se.edition||void 0}}}catch{}return{id:ie,title:ie,type:"work",notFound:!0}})).then(ie=>{V||(F(ie),B(!1))}),()=>{V=!0}},[M,t]);const Ie=V=>{C(V.id),wr(V.id),P(dt()),o==null||o(V)},Ae=V=>{_r(V),P(dt())},ke=()=>{Cr(),P([])},Ne=V=>m.find(ie=>ie.type===V),Qe=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(Ei,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Bi,{transport:t,value:j,onChange:Oe,onSearch:Se,onEntrySelect:Ie}),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})]}),G&&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:re?e.jsxs(e.Fragment,{children:[(re.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.books.toLocaleString()})," 本"]}),re.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.article.toLocaleString()})," 篇"]}):null,re.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[v.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.collections.toLocaleString()}),G.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:G.entities.toLocaleString()})]})]})}),G.hasImage!=null&&G.hasText!=null&&e.jsxs("span",{children:[v.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.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:W?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:ke,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,D?10:3).map(V=>V.notFound?e.jsx(zr,{id:V.id,onRemove:Ae,t:v},V.id):e.jsx(Mn,{entry:V,selected:z===V.id,onClick:Ie,getConfig:Ne,onRemove:Ae},V.id))}),!D&&$.length>3&&e.jsx("button",{onClick:()=>te(!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})]})}):Qe?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:V,icon:ie,name:ee,key:L})=>{const X=k[L]??[],se=Ir[L],J=k[se]??0;if(X.length===0)return null;const be=!(w===V)&&J>Vt;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:[ie," ",ee,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",v.unit.items]})]}),be&&e.jsx("button",{onClick:()=>he(V),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:X.map(pe=>{if(f)return e.jsx(u.Fragment,{children:f(pe)},pe.id);const Ve=p==="card"?Tr:Mn;return e.jsx(Ve,{entry:pe,selected:z===pe.id,onClick:Ie,getConfig:Ne,query:j},pe.id)})})]},V)})}):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:ht(v.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v.search.tryOther})]})})]})},Tr=({entry:t,selected:n,onClick:i,getConfig:o,query:s})=>{const r=N(),{convert:l}=O(),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}${r.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&d.length?d.find(g=>{const x=typeof g=="string"?g:g==null?void 0:g.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,f="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, ${f} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${f} 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, ${f} 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:f},children:Array.from(c).map((g,x)=>e.jsx("span",{children:g},x))})]}),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.edition&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l(t.edition)}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[r.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:[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]})]})]})]})},Mn=({entry:t,selected:n,onClick:i,getConfig:o,query:s,onRemove:r})=>{const l=N(),{convert:c}=O(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(p=>{const f=typeof p=="string"?p:p==null?void 0:p.book_title;return f==null?void 0:f.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:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.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,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)]})]}),r?e.jsx("button",{onClick:p=>{p.stopPropagation(),r(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:"→"})]})},zr=({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 Rr(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 Er({data:t}){const{convert:n}=O(),{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 Br({alt_names:t}){const{convert:n}=O(),i=new Map;for(const r of t){const l=r.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(r.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((r,l)=>{const c=o.indexOf(r),a=o.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(r=>{const l=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: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))})]},r)})})}function Lr({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 Wr({works:t,transport:n,onNavigate:i,renderLink:o}){const s=N(),{convert:r}=O(),l=me(),[c,a]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let g=!1;const x=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(x);let _=!0;for(let w=0;w<x.length;w++){const I=k[w];I!=null&&I.title?v.set(x[w],I.title):I!=null&&I.primary_name?v.set(x[w],I.primary_name):_=!1}if(_)return v}catch{}const m=[...x],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 I=await n.getEntry(k);if(I!=null&&I.title){v.set(k,I.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||a(v)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const x=g.role||"";d.has(x)||d.set(x,[]),d.get(x).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((g,x)=>{const h=p.indexOf(g),v=p.indexOf(x);return h===-1&&v===-1?g.localeCompare(x):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,")"]})]}),f.map(g=>{const x=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:["(",x.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:x.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: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})},v):e.jsx("li",{children:m},v)})})]},g)})]})}const Li=({data:t,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:r})=>{var f;const l=N(),{convert:c}=O();let a=!1;try{a=q.extractStatus(t.id)==="draft"}catch{}const d=Rr(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(Er,{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(Br,{alt_names:t.alt_names}),e.jsx(Lr,{data:t}),((f=t.description)==null?void 0:f.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(Wr,{works:t.works,transport:n,onNavigate:i,renderLink:o})]})},Wi={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})},$r={...Wi,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Re=({text:t,plainStrong:n,style:i,className:o})=>{const{convert:s}=O(),r=n?$r:Wi;return e.jsx("div",{className:o,style:i,children:e.jsx(qo,{remarkPlugins:[Xo],components:r,children:s(t)})})},Ar=["〇","一","二","三","四","五","六","七","八","九"],Fn=["","十","百","千"];function $i(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 l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=Fn[c]:o+=Ar[l]+Fn[c])}return o}function Ai(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 Mr={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 Fr({type:t}){const n=N();return e.jsx("span",{style:Ai(Mr[t]),children:n.indexType[t]})}function Pr({isDraft:t}){const n=N(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Ai(i),children:t?n.status.draft:n.status.official})}function Hr({id:t}){const n=N(),[i,o]=u.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 fe({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 Ce({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 Mi({authors:t,type:n,onNavigate:i,renderLink:o}){const{convert:s}=O();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,l)=>{const c=s(r.name),a=r.entity_id?e.jsx(ve,{id:r.entity_id,label:c,onNavigate:i,renderLink:o}):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:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(r.dynasty),"〕"]}),a,r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(r.role)]})]},l)})})}function ve({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 Dr({id:t,title:n,edition:i,type:o,isDraft:s,authors:r,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(Fr,{type:o}),e.jsx(Pr,{isDraft:s}),e.jsx(Hr,{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(Mi,{authors:r,type:o,onNavigate:d,renderLink:p}),c]})]})}function Fi({items:t,label:n,showMeta:i,onNavigate:o,renderLink:s}){const r=N(),{convert:l}=O();if(!t.length)return null;const[c,a]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,p)=>{const f=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?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:f?"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)}),!f&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ve,{id:d.source_bid,label:r.action.view,onNavigate:o,renderLink:s})})]}),f&&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(Ce,{label:r.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(Ce,{label:r.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(Ce,{label:r.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:r.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:r.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:r.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 Or({items:t,onNavigate:n,renderLink:i}){const o=N();return e.jsx(Fi,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Pi({items:t,onNavigate:n,renderLink:i}){const o=N();return e.jsx(Fi,{items:t,label:o.section.emendated,onNavigate:n,renderLink:i})}function Hi({label:t,items:n}){const{convert:i}=O();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{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 Nr({items:t}){const n=N();return e.jsx(Hi,{label:n.section.aliases,items:t})}function Vr({items:t}){const n=N();return e.jsx(Hi,{label:n.section.attachedTexts,items:t})}function Gr({items:t}){const n=N(),{convert:i}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{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 Ur({items:t}){const n=N(),{convert:i}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{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 Yr({items:t}){const n=N(),{convert:i}=O();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{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 Pn({title:t,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:r}=O(),[l,c]=u.useState([]);return u.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(fe,{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?`${r(a.title)||a.id}(${r(a.edition)})`:r(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(ve,{id:a.id,label:d,onNavigate:o,renderLink:s})},a.id)})})]}):null}function Gt({book:t,onNavigate:n,renderLink:i}){const o=N(),{convert:s}=O(),[r,l]=u.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&&!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(ve,{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: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(an,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Kr({ids:t,workData:n,transport:i,onNavigate:o,renderLink:s,footer:r}){const l=N(),{convert:c}=O(),[a,d]=u.useState([]);if(u.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(v=>({id:v})));return}let h=!1;return Promise.all(t.map(v=>i.getItem(v).then(m=>({id:v,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:v})))).then(v=>{h||d(v)}),()=>{h=!0}},[t,i]),!t.length)return null;const p=a.length?a:t.map(h=>({id:h})),f=new Map(p.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,x=Jr(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(fe,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),r,x.useGrouping?e.jsxs(e.Fragment,{children:[x.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:x.coreIds.map(h=>{const v=f.get(h);return v?e.jsx(Gt,{book:v,onNavigate:o,renderLink:s},h):null})}),x.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=f.get(v);return m?e.jsx(Gt,{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(Gt,{book:h,onNavigate:o,renderLink:s},h.id))})]})}function Jr(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,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],f=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?(f.has(k)||f.set(k,[]),f.get(k).push(y)):g.push(y)}if(g.length+[...f.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=[...f.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 qr({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const o=N(),{convert:s}=O(),r=!!((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: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(ve,{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:[$i(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Mi,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),r&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(Re,{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(Ce,{label:o.label.parentWork,children:e.jsx(ve,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Xr({items:t,onNavigate:n,renderLink:i}){const o=N(),{convert:s}=O();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(ve,{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:ht(o.catalog.volume,{n:r.volume_index})})]},r.id))}):null}const cn=({data:t,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:r,relatedBooksFooter:l,className:c,style:a})=>{var R,E,A,M,P,$,F,W;const d=N(),{convert:p}=O(),[f,g]=u.useState(null),[x,h]=u.useState(!1),[v,m]=u.useState(null),[j,y]=u.useState(null),[k,_]=u.useState([]),w=t||f;if(u.useEffect(()=>{if(t||!n||!i)return;let B=!1;return h(!0),m(null),i.getItem(n).then(D=>{B||(D?g(D):m(d.misc.notFoundEntry))}).catch(D=>{B||m(D instanceof Error?D.message:d.misc.loadFailed)}).finally(()=>{B||h(!1)}),()=>{B=!0}},[t,n,i]),u.useEffect(()=>{if(!w||!i){y(null),_([]);return}let B=!1;const D=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(D?i.getItem(D).then(te=>{!B&&te&&te.type==="work"&&y(te)}).catch(()=>{}):y(null),w.type==="book"){const te=w;te.contained_in&&te.contained_in.length>0?Promise.all(te.contained_in.map(G=>{const Z=typeof G=="string"?G:G.id,re=typeof G=="string"?void 0:G.volume_index;return i.getItem(Z).then(ne=>({id:Z,title:ne&&ne.title||Z,volume_index:re})).catch(()=>({id:Z,title:Z,volume_index:re}))})).then(G=>{B||_(G)}):_([])}else _([]);return()=>{B=!0}},[w,i]),x)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((B,D)=>e.jsx("div",{style:{height:D===1?"32px":"16px",width:`${B}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},D))})});if(v)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!w)return null;if(w.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Li,{data:w,transport:i,onNavigate:o,renderLink:s,headerExtra:r})});const I=w.type==="book"?w:null,S=w.type==="collection"?w:null,T=w.type==="work"?w:null;let z=!1;try{z=q.extractStatus(w.id)==="draft"}catch{}let C="";w.measure_info?C=p(w.measure_info):(R=w.juan_count)!=null&&R.number?C=$i(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(Ce,{label:d.label.year,children:w.publication_info.year},"year")),(M=w.current_location)!=null&&M.name&&b.push(e.jsx(Ce,{label:d.label.currentLocation,children:p(w.current_location.name)},"loc")),(P=w.page_count)!=null&&P.description&&b.push(e.jsx(Ce,{label:d.label.pageCount,children:w.page_count.description},"page")),I!=null&&I.edition&&b.push(e.jsx(Ce,{label:d.label.edition,children:p(I.edition)},"ver")),T!=null&&T.parent_work&&b.push(e.jsx(Ce,{label:d.label.parentWork,children:e.jsx(ve,{id:T.parent_work.id,label:p(T.parent_work.title),onNavigate:o,renderLink:s})},"pw")),T!=null&&T.parent_works&&T.parent_works.length>0&&!T.parent_work&&b.push(e.jsx(Ce,{label:d.label.parentWork,children:T.parent_works.map((B,D)=>e.jsxs("span",{children:[D>0&&"、",e.jsx(ve,{id:B,onNavigate:o,renderLink:s})]},B))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(Dr,{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(Re,{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((B,D)=>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(B.title)}),e.jsx(Re,{text:B.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},D))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:d.section.containedIn}),e.jsx(Xr,{items:k,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:d.section.belongsToWork}),e.jsx(qr,{workData:j,onNavigate:o,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(Gr,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(Nr,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(Vr,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(Or,{items:w.indexed_by,onNavigate:o,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(Pi,{items:w.emendated_by,onNavigate:o,renderLink:s}),w.resources&&w.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:d.section.resources}),e.jsx(an,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(I==null?void 0:I.location_history)&&I.location_history.length>0&&e.jsx(Ur,{items:I.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Yr,{items:S.history}),(I==null?void 0:I.related_books)&&I.related_books.length>0&&e.jsx(Pn,{title:d.section.relatedVersions,ids:I.related_books,transport:i,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Pn,{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(fe,{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(B=>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(ve,{id:B.id,label:p(B.title),onNavigate:o,renderLink:s})},B.id))})]}),(((F=T==null?void 0:T.books)==null?void 0:F.length)||0)+(((W=T==null?void 0:T.collections)==null?void 0:W.length)||0)>0&&e.jsx(Kr,{ids:[...(T==null?void 0:T.books)||[],...(T==null?void 0:T.collections)||[]],workData:T,transport:i,onNavigate:o,renderLink:s,footer:l}),(T==null?void 0:T.related_works)&&T.related_works.length>0&&(()=>{const B=[],D=T.related_works.filter(U=>U.relation==="part_of"),te=T.related_works.filter(U=>U.relation==="has_part"),G=T.related_works.filter(U=>U.relation==="has_adaptation"),Z=T.related_works.filter(U=>U.relation==="text_carried_by"),re=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ne=T.related_works.filter(U=>!U.relation||!re.has(U.relation));return D.length>0&&B.push({label:d.section.belongsToWork,items:D}),te.length>0&&B.push({label:d.section.containedWorks,items:te}),G.length>0&&B.push({label:d.section.adaptations,items:G}),Z.length>0&&B.push({label:d.section.derivativeWorks,items:Z}),ne.length>0&&B.push({label:d.section.relatedWorks,items:ne}),B.map(U=>e.jsxs("div",{children:[e.jsxs(fe,{children:[U.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",U.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:U.items.map(Y=>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(ve,{id:Y.id,label:p(Y.title),onNavigate:o,renderLink:s})},Y.id))})]},U.label))})()]})};function Zr({data:t}){const n=N(),{convert:i}=O(),{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 Qr({sections:t,activeSection:n,onSelect:i}){const o=N();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:Hn(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:Hn(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 Hn(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 es({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 ts(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 Dn({book:t,onNavigate:n,renderLink:i,showVolumes:o}){const s=N(),{convert:r}=O(),l=t.book_id||t.work_id,c=o&&t.volumes.length>0?ts(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:[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: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(es,{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 dn=({data:t,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:r,style:l})=>{const c=N(),[a,d]=u.useState(null),[p,f]=u.useState(!1),[g,x]=u.useState(null),[h,v]=u.useState(null),[m,j]=u.useState(""),y=t||a;u.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let S=!1;return f(!0),x(null),i.getCollectionCatalog(n).then(T=>{S||(T?d(T):x(c.catalog.notFound))}).catch(T=>{S||x(T instanceof Error?T.message:c.catalog.loadFailed)}).finally(()=>{S||f(!1)}),()=>{S=!0}},[t,n,i,c]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,_=u.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=u.useMemo(()=>{if(!y)return[];let S=y.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},[y,h,m]),I=u.useMemo(()=>{if(!_)return null;const S=[],T=new Map;for(const C of w){if(!C.volumes||C.volumes.length===0)continue;const b=C.volumes[0];T.has(b)||T.set(b,[]),T.get(b).push(C)}const z=[...T.keys()].sort((C,b)=>C-b);for(const C of z)S.push({volume:C,books:T.get(C)});return S},[w,_]);return p?e.jsx("div",{className:r,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:r,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):y?e.jsxs("div",{className:r,style:l,children:[e.jsx(Zr,{data:y}),k&&e.jsx(Qr,{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:[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:ht(c.catalog.volume,{n:S.volume})}),S.books.map((z,C)=>e.jsx(Dn,{book:z,onNavigate:o,renderLink:s,showVolumes:z.volumes.length>1},`${S.volume}-${C}`))]},`${S.volume}-${T}`)):w.map((S,T)=>e.jsx(Dn,{book:S,onNavigate:o,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},De=()=>{const[t,n]=u.useState(1);return u.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)})},de=6,St=7,ns=({content:t,children:n,placement:i="top",delayMs:o=100,maxWidth:s=280,wrapperStyle:r})=>{const[l,c]=u.useState(!1),[a,d]=u.useState(null),p=u.useRef(null),f=u.useRef(null),g=u.useRef(null),x=u.useCallback(()=>{const m=f.current,j=g.current;if(!m||!j)return;const y=m.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,w=document.documentElement.clientWidth;let I=i;i==="top"&&y.top-k.height-St<8&&(I="bottom"),i==="bottom"&&y.bottom+k.height+St>_-8&&(I="top");const S=I==="top"?y.top-k.height-St:y.bottom+St;let T=y.left+y.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=u.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),o)},[o]),v=u.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return u.useEffect(()=>{if(!l)return;const m=requestAnimationFrame(x);return()=>cancelAnimationFrame(m)},[l,x]),u.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:h,onMouseLeave:v,onFocus:h,onBlur:v,style:{display:"inline-block",...r},children:n}),l&&Zo.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-de,width:0,height:0,...a.placement==="top"?{bottom:-de,borderTop:`${de}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${de}px solid transparent`,borderRight:`${de}px solid transparent`}:{top:-de,borderBottom:`${de}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${de}px solid transparent`,borderRight:`${de}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${de-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${de-1}px solid transparent`,borderRight:`${de-1}px solid transparent`}:{top:-5,borderBottom:`${de-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${de-1}px solid transparent`,borderRight:`${de-1}px solid transparent`}}})]})]}),document.body)]})},On={A:"fine",B:"rough",C:"rough",D:"ocr"};function is(t){return typeof t!="string"?null:t in Ci?t:t in On?On[t]:null}const os={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},rs={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ge(t){return typeof t!="string"?"":os[t]??rs[t]??t}const ss=["〇","一","二","三","四","五","六","七","八","九"],Nn=["","十","百","千"],ls=["","萬","億"];function Di(t){if(t===0)return"〇";if(t<0)return`負${Di(-t)}`;const n=[];let i=t,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(as(s,o>0)+ls[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function as(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 l=i[r],c=i.length-1-r;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&r===0&&!n?s+=Nn[c]:s+=ss[l]+Nn[c]}return s.replace(/〇$/,"")}let pt=null,kt=null;const Bt=new Set;function cs(){return pt?Promise.resolve():kt||(kt=import("opencc-js/t2cn").then(t=>{pt=t.Converter({from:"tw",to:"cn"}),Bt.forEach(n=>n())}).catch(()=>{pt=t=>t,Bt.forEach(t=>t())}),kt)}function Ee(){const[,t]=u.useState(0);return u.useEffect(()=>{if(pt)return;const n=()=>t(i=>i+1);return Bt.add(n),cs(),()=>{Bt.delete(n)}},[]),pt??(n=>n)}function Je(t,n){return n(t).toLowerCase()}const pn="var(--bim-highlight-bg, #fff59d)";function Ze(t,n,i){if(!n)return t;const o=Je(n,i);if(!o)return t;const s=Je(t,i);if(s.length!==t.length)return t;const r=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(o,l);if(a===-1){r.push(t.slice(l));break}a>l&&r.push(t.slice(l,a)),r.push(e.jsx("mark",{style:{background:pn,padding:0,color:"inherit"},children:t.slice(a,a+o.length)},c++)),l=a+o.length}return e.jsx(e.Fragment,{children:r})}function un(t,n,i,o){if(!n)return!0;const s=Je(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(l=>typeof l=="string"&&Je(l,o).includes(s))}function ds(t,n,i){return n?Je(t,i).includes(Je(n,i)):!0}const xn={类:"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)"},ps={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function us(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 Oi({file:t,isActive:n,onSelect:i,meta:o,matchState:s}){const r=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=us(t),d=!!(o!=null&&o.vol_label)&&!a.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?`${pn}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:[a,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}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Ni(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(o=>Ni(o,n)))}function Vi(t){var o;const n=t.files.length,i=((o=t.children)==null?void 0:o.reduce((s,r)=>s+Vi(r),0))||0;return n+i}function xs(t,n){const i=[],o=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(o)};if(o(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 r=0;for(const l of s)typeof l=="number"&&(r+=l);return r}function Gi({group:t,activeFile:n,onSelect:i,depth:o=0,juanMeta:s,matchStates:r}){var h;const l=Ni(t,n||""),c=xs(t,r),a=typeof c=="number"&&c>0,d=c===0,[p,f]=u.useState(l||a),g=Vi(t),x=!!((h=t.children)!=null&&h.length);if(u.useEffect(()=>{l&&f(!0)},[l]),u.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!x){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)":_?`${pn}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:()=>f(!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: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:["(",g,")"]}),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+o*16}px`},children:t.files.map(v=>e.jsx(Oi,{file:v,isActive:n===v,onSelect:i,meta:s==null?void 0:s[v],matchState:r[v]},v))}),x&&t.children.map((v,m)=>e.jsx(Gi,{group:v,activeFile:n,onSelect:i,depth:o+1,juanMeta:s,matchStates:r},m))]})]})}function fs({files:t,groups:n,activeFile:i,onSelect:o,juanMeta:s,matchStates:r}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,a)=>e.jsx(Gi,{group:c,activeFile:i,onSelect:o,juanMeta:s,matchStates:r},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(Oi,{file:c,isActive:i===c,onSelect:o,meta:s==null?void 0:s[c],matchState:r[c]},c))})}function gs({type:t}){const n=xn[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 ms({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=O(),s=me(),r=Ee(),l=v=>{if(!v)return"";const m=o(v);return i?Ze(m,i,r):m},[c,a]=u.useState(!1),d=!!t.summary,p=!!t.comment,f=!!t.additional_comment,g=!!(t.content&&t.content.length>60),x=d||p||f||g;u.useEffect(()=>{i&&a(!0)},[i]);const h=!c&&g?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>x&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:x?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[x&&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:[Di(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&x&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!d&&!p&&!f&&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 hs({section:t,highlightQuery:n=""}){const{convert:i}=O(),o=Ee(),s=a=>{if(!a)return"";const d=i(a);return n?Ze(d,n,o):d},[r,l]=u.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!r),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: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, ${xn[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 bs({section:t,highlightQuery:n=""}){const{convert:i}=O(),o=Ee();if(ge(t.type)==="page_header"||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`)),r=n?
|
|
3
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:r.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&&!r[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(u.Fragment,{children:s(d)},p))},c)})})}function ks({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=O(),s=me(),r=Ee(),l=d=>{if(!d)return"";const p=o(d);return i?Ze(p,i,r):p},c=[];let a=null;for(const d of t){const p=ge(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((f,g)=>ge(f.type)==="序"||ge(f.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(f.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&f.work_id?e.jsx("a",{href:s(f.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),x.stopPropagation(),n(f.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(f.title),children:e.jsx("strong",{children:l(f.title)})}):e.jsx("strong",{children:l(f.title)}),f.content&&l(f.content)]},g))]},p))})}function ws({juan:t,rawText:n,searchQuery:i,onNavigate:o}){const{convert:s}=O(),r=Ee(),[l,c]=u.useState("catalog"),a=i.trim(),d=u.useMemo(()=>a?t.sections.filter(x=>un(x,a,!1,r)):t.sections,[t.sections,a,r]),p=t.sections.filter(x=>ge(x.type)==="书").length,f=t.sections.filter(x=>ge(x.type)==="诗").length,g=a?d.filter(x=>ge(x.type)==="书"||ge(x.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(x=>e.jsx("button",{onClick:()=>c(x),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:x==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===x?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===x?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:x==="catalog"?"目錄":"原文"},x))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${f>0?`${f} 首`:`${p} 部書`}`:f>0?`${f} 首`:`${p} 部书`})]}),l==="raw"&&(n?e.jsx(Ss,{text:n,highlightQuery:a}):e.jsx(ks,{sections:t.sections,onNavigate:o,highlightQuery:a})),l==="catalog"&&d.map((x,h)=>{const v=ge(x.type);return v==="书"||v==="诗"||v==="考证"?e.jsx(ms,{section:x,onNavigate:o,highlightQuery:a},h):v==="类"?e.jsx(hs,{section:x,highlightQuery:a},h):e.jsx(bs,{section:x,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 Ui(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 Vn(t){const n=Ui(t);return n.length>0?n[0]:null}function _s(t){const{workId:n,transport:i,files:o,activeFile:s,activeJuan:r,activeRawText:l,query:c,isKaozhen:a}=t,d=Ee(),p=u.useRef(new Map),[f,g]=u.useState({});u.useEffect(()=>{s&&r&&p.current.set(s,{juan:r,rawText:l})},[s,r,l]),u.useEffect(()=>{p.current.clear(),g({})},[n]);const x=u.useCallback((h,v)=>{let m=0;if(h.juan)for(const j of h.juan.sections)un(j,v,a,d)&&m++;return m===0&&h.rawText&&ds(h.rawText,v,d)&&(m=1),m},[a,d]);return u.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 I of o){const S=p.current.get(I);S?m[I]=x(S,h):(m[I]="loading",j.push(I))}g(m);const y=8;let k=0;const _=async()=>{var I;for(;k<j.length;){if(v)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)]),b={juan:z,rawText:C};if(p.current.set(T,b),v)return;g(R=>({...R,[T]:x(b,h)}))}catch{if(v)return;g(z=>({...z,[T]:0}))}}},w=Array.from({length:Math.min(y,j.length)},()=>_());return Promise.all(w),()=>{v=!0}},[c,n,i,o.join(","),x,d]),{matchStates:f}}const fn=({index:t,workId:n,transport:i,onNavigate:o,activeJuan:s,onJuanChange:r,className:l,style:c})=>{const[a,d]=u.useState(null),[p,f]=u.useState(!1),[g,x]=u.useState(null),[h,v]=u.useState(null),[m,j]=u.useState(null),[y,k]=u.useState(!1),[_,w]=u.useState(null),[I,S]=u.useState(""),T=u.useRef(new Map),z=s??h,C=u.useCallback($=>{v($),r==null||r($)},[r]),b=t||a;u.useEffect(()=>{t&&(f(!1),x(null))},[t]),u.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let $=!1;return f(!0),x(null),i.getCollatedEditionIndex(n).then(F=>{if(!$)if(!F)x("未找到整理本数据");else{d(F);const W=Vn(F);!s&&W&&C(W)}}).catch(F=>{$||x(F instanceof Error?F.message:"加载失败")}).finally(()=>{$||f(!1)}),()=>{$=!0}},[t,n,i,s,C]),u.useEffect(()=>{const $=t||a;if($&&!z){const F=Vn($);F&&C(F)}},[t,a,z,C]);const R=n||(b==null?void 0:b.work_id),E=u.useCallback(async $=>{var F;if(!(!R||!(i!=null&&i.getCollatedJuan))){k(!0),j(null),w(null);try{const[W,B]=await Promise.all([i.getCollatedJuan(R,$),((F=i.getCollatedJuanText)==null?void 0:F.call(i,R,$))??Promise.resolve(null)]);j(W),w(B)}catch{j(null),w(null)}finally{k(!1)}}},[R,i]);u.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(g)return e.jsx("div",{className:l,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=Ui(b);return e.jsx(Cs,{className:l,style:c,index:b,allFiles:P,isKaozhen:M,effectiveWorkId:R,transport:i,activeFile:z,handleSelectFile:A,juanData:m,juanRawText:_,juanLoading:y,searchQuery:I,setSearchQuery:S,onNavigate:o,workLabelCacheRef:T})},Cs=({className:t,style:n,index:i,allFiles:o,isKaozhen:s,effectiveWorkId:r,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:f,searchQuery:g,setSearchQuery:x,onNavigate:h,workLabelCacheRef:v})=>{const{matchStates:m}=_s({workId:r,transport:l,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=>x(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=is(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(ns,{content:nr[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:ir[j],cursor:"help"},children:Ci[j]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),e.jsx(fs,{files:o,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:m}),f?e.jsx(De,{}):d?s?e.jsx(js,{juan:d,searchQuery:g,onNavigate:h,transport:l,workLabelCache:v}):e.jsx(ws,{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))]})]})},Is={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Ts={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function zs(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 gn=({items:t,loading:n})=>{const i=me();return n?e.jsx(De,{}):t.length===0?e.jsx("div",{style:Rs,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=Is[o.type],r=Ts[o.status];return e.jsxs("div",{style:Es,children:[e.jsxs("div",{style:Bs,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Gn,background:s.color},children:s.label}),e.jsx("span",{style:{...Gn,background:r.color},children:r.label})]}),e.jsx("span",{style:Ls,children:zs(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:Ws,children:[o.resourceId&&e.jsx("a",{href:i(o.resourceId),style:Un,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:Un,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:$s,children:o.content}),o.reply&&e.jsxs("div",{style:As,children:[e.jsx("div",{style:Ms,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},Rs={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Es={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Bs={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Gn={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Ls={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Ws={fontSize:"12px",marginBottom:"6px"},Un={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},$s={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},As={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Ms={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Zt=({transport:t,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:r})=>{const l=N(),[c,a]=u.useState(null),[d,p]=u.useState([]),[f,g]=u.useState("recommend"),[x,h]=u.useState([]),[v,m]=u.useState(!1),j=o??f,y=M=>{g(M),s==null||s(M)},[k,_]=u.useState(!0),[w,I]=u.useState(null),[S,T]=u.useState(null),[z,C]=u.useState(null);u.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]),u.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(W=>({...W,group:F.name})))}catch{}return[]})().then(async $=>{if(M)return;const F=$.filter(B=>B.id);if(F.length===0){_(!1);return}const W=await Promise.all(F.map(async B=>{if(B.type)return{id:B.id,title:B.title,type:B.type,author:B.author,dynasty:B.dynasty,role:B.role,edition:B.edition,has_text:B.has_text,has_image:B.has_image,has_collated:B.has_collated,subtype:B.subtype,primary_name:B.primary_name,group:B.group,fallbackDescription:B.description};try{let D=null;if(t.getEntry)D=await t.getEntry(B.id);else{const te=await t.getItem(B.id);te&&(D={id:B.id,title:te.title||B.id,type:te.type||"work"})}if(D)return{...D,group:B.group,fallbackDescription:B.description}}catch{}return{id:B.id,title:B.title,type:q.extractType(B.id),group:B.group,fallbackDescription:B.description}}));M||(p(W.filter(B=>B!==null)),_(!1))}),()=>{M=!0}},[t,i]);const b=u.useRef(!1),R=u.useRef(!1),E=u.useRef(!1);u.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||I($)}).catch(()=>{b.current=!1}),()=>{P=!0}},[t,j]),u.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]),u.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]),u.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(it,{label:l.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),e.jsx(it,{label:l.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),e.jsx(it,{label:l.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),e.jsx(it,{label:l.home.siteTab,active:j==="site",onClick:()=>y("site")}),r&&e.jsx(it,{label:l.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&e.jsx(Fs,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:l}),j==="catalog"&&e.jsx(Yn,{progress:w,t:l,onNavigate:n}),j==="collection"&&e.jsx(Yn,{progress:S,t:l,onNavigate:n}),j==="site"&&e.jsx(Hs,{progress:z,t:l,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&r&&e.jsx(gn,{items:x,loading:v})]})})},it=({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}),Fs=({recommended:t,loading:n,onNavigate:i,getIcon:o,t:s})=>{const r=me();if(n)return e.jsx(De,{});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:r(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.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))})},Yn=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(De,{});const o=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],r={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=o.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]}}),r[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Ps,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},Ps=({item:t,t:n,statusColor:i,onNavigate:o})=>{const s=me(),r=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&&o?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(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?ht(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})]})},Hs=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(De,{});const o=[...t.resources].sort((a,d)=>a.priority-d.priority),s=o.filter(a=>a.imported>0),r=o.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(Kn,{item:a,t:n,totalWorks:i},a.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(a=>e.jsx(Kn,{item:a,t:n,totalWorks:i},a.id))})]})]})},Kn=({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})]})},Jn="(max-width: 768px)";function Ds(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(Jn).matches);return u.useEffect(()=>{const i=window.matchMedia(Jn),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),t}const Os=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var P;const r=N(),{convert:l}=O(),c=Ds(),[a,d]=u.useState(null),[p,f]=u.useState(null),[g,x]=u.useState(!1),[h,v]=u.useState("detail"),[m,j]=u.useState([]),[y,k]=u.useState(!1),[_,w]=u.useState(null),[I,S]=u.useState(!1),T=u.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=u.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=u.useCallback(async $=>{if(i){i($);return}d($),f(null),j([]),w(null),v("detail"),x(!0);try{const F=await t.getItem($.id);F&&(f(F),F.type==="collection"?z($.id):F.type==="work"&&F.has_collated&&T($.id))}catch(F){console.error("加载详情失败:",F)}finally{x(!1)}},[t,i,z,T]),b=u.useCallback(async $=>{f(null),j([]),w(null),v("detail"),x(!0);try{const F=await t.getItem($);F&&(f(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{x(!1)}},[t,z,T]),R=(p==null?void 0:p.type)==="collection"&&(m.length>0||y)||(p==null?void 0:p.type)==="work"&&(_||I),E=c&&(g||p),A=u.useCallback(()=>{d(null),f(null),j([]),w(null),v("detail")},[]),M=e.jsx(e.Fragment,{children:g?e.jsx(De,{}):p?e.jsxs(e.Fragment,{children:[(R||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[R&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>v("detail"),style:wt(h==="detail"),children:r.detailTab.basicInfo}),p.type==="collection"&&y&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:wt(!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:wt(h===`catalog:${$.resource_id}`),children:$.short_name?`${l($.short_name)}${r.detailTab.catalogSuffix}`:r.detailTab.collectionCatalog},$.resource_id)),p.type==="work"&&(_||I)&&e.jsxs("button",{onClick:()=>v("collated"),style:wt(h==="collated"),children:[r.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(cn,{data:p,transport:t,onNavigate:b}):h.startsWith("catalog:")?e.jsx(dn,{data:(P=m.find($=>`catalog:${$.resource_id}`===h))==null?void 0:P.data,onNavigate:b}):h==="collated"?e.jsx(fn,{index:_||void 0,workId:p.id,transport:t,onNavigate:b}):null})]}):e.jsx(Zt,{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(Xt,{transport:t,onEntryClick:C,hideModeIndicator:n}),!p&&e.jsx(Zt,{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(Xt,{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 wt(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Me(t){return t.replace(/\.md$/,"")}const Yi=({index:t,bookId:n,transport:i,activeChapter:o,onChapterChange:s})=>{const[r,l]=u.useState(t??null),[c,a]=u.useState(null),d=o!==void 0?o:c,p=u.useCallback(m=>{s?s(m):a(m)},[s]),[f,g]=u.useState(null),[x,h]=u.useState(!1);u.useEffect(()=>{t&&l(t)},[t]),u.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let m=!1;return i.getBookFullTextIndex(n).then(j=>{m||l(j)}),()=>{m=!0}},[n,i,t]),u.useEffect(()=>{if(!r||r.chapters.length===0)return;const m=Me(r.chapters[0].file);if(!d){p(m);return}const j=Me(d);r.chapters.some(k=>Me(k.file)===j)||p(m)},[r,d,p]);const v=u.useMemo(()=>{if(!r||!d)return null;const m=Me(d);return r.chapters.find(j=>Me(j.file)===m)??null},[r,d]);return u.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=Me(m.file),y=j===Me(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]})]})]}),x&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!x&&f&&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:f.replace(/^##\s+[^\n]+\n+/,"")}),!x&&!f&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},Ns=({data:t,onNavigate:n,className:i,style:o})=>{var p;const s=N(),{convert:r}=O(),[l,c]=u.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[a,d]=u.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(f=>e.jsx(Vs,{division:f,expanded:l===f.name,onToggle:()=>c(l===f.name?null:f.name),expandedCat:a,onCatToggle:g=>d(a===g?null:g),onNavigate:n},f.name))})]})},Vs=({division:t,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:r})=>{const{convert:l}=O(),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(Gs,{category:a,expanded:o===d,onToggle:()=>s(d),onNavigate:r},a.name)})})]})},Gs=({category:t,expanded:n,onToggle:i,onNavigate:o})=>{var a,d,p,f;const{convert:s}=O(),r=((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)||r.length)+(((f=t.stats)==null?void 0:f.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&&(r.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[r.length>0&&e.jsx(qn,{label:"著錄",books:r,onNavigate:o}),l.length>0&&e.jsx(qn,{label:"存目",books:l,onNavigate:o})]})]})},qn=({label:t,books:n,onNavigate:i})=>{const{convert:o}=O(),s=me(),[r,l]=u.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((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:o(a.title)}):o(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(a.author).slice(0,20)})]},d))}),!r&&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," 條"]})]})},ye=({title:t,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const r=N();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:Ys,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Us,children:r.action.save})]})]}),s]})},Us={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ys={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},xe=({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"}})]}),Fe=({value:t,onChange:n,placeholder:i})=>{const o=u.useRef(null);return u.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"}})},Lt=({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 Ks(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const _t=({value:t,onChange:n,label:i})=>{const[o,s]=u.useState(!1),r=u.useRef(null),l=Ks(t||"");return u.useEffect(()=>{o&&r.current&&r.current.focus()},[o]),!o&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Xn,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(Lt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Xn,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"}})]})},Xn={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Js(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 qs(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ki=({items:t,onChange:n,onOpenEntityPicker:i})=>{const o=N(),[s,r]=u.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),r(t.length)},c=f=>{n(t.filter((g,x)=>x!==f)),s===f&&r(null)},a=(f,g,x)=>{const h=[...t];h[f]={...h[f],[g]:x},n(h)},d=(f,g)=>{const x=[...t];x[f]={...x[f],type:g,id:"",name:""},n(x),g==="bookID"&&i&&i(h=>{const v=[...t];v[f]={...v[f],id:h.id,name:h.title,type:"bookID"},n(v)})},p=f=>{i&&i(g=>{const x=[...t];x[f]={...x[f],id:g.id,name:g.title,type:"bookID"},n(x)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,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:f.name||`${o.editor.sourcePlaceholder} ${g+1}`}),f.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Js(f.type),color:"white",borderRadius:"3px",fontWeight:500},children:qs(f.type)}),e.jsx("button",{onClick:x=>{x.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:[!f.type&&e.jsxs("div",{children:[e.jsx("label",{style:ze,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Zn,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:{...Zn,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})]})]})]}),f.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:ze,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const x=[...t];x[g]={...x[g],type:"",id:"",name:""},n(x)},style:Qn,children:o.action.changeType})]}),f.id&&f.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:f.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:f.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})]})]})}),f.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:ze,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const x=[...t];x[g]={...x[g],type:"",id:"",name:""},n(x)},style:Qn,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:f.name,onChange:x=>a(g,"name",x.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Ue})]}),e.jsxs("div",{children:[e.jsx("label",{style:ze,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:f.id,onChange:x=>a(g,"id",x.target.value),placeholder:"https://...",style:Ue})]})]}),f.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:{...ze,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:ze,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:f.details,onChange:x=>a(g,"details",x.target.value),placeholder:o.editor.detailsPlaceholder,style:Ue})]}),e.jsxs("div",{children:[e.jsx("label",{style:ze,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:f.position,onChange:x=>a(g,"position",x.target.value),placeholder:"如: 卷三, p.52",style:Ue})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ze,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:f.version,onChange:x=>a(g,"version",x.target.value),placeholder:"如: v1.0, 2024-01",style:Ue})]}),e.jsxs("div",{children:[e.jsx("label",{style:ze,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:f.processor_version,onChange:x=>a(g,"processor_version",x.target.value),placeholder:"如: v0.1",style:Ue})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},ze={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},Ue={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"},Zn={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"},Qn={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Ji(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 qi(t){return!t||t.length===0?"":JSON.stringify(t)}const Xi=({entityType:t,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:r,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:f,onUnlinkEntity:g,onViewEntity:x,onCreateAndLink:h,onSaveRelations:v})=>{const m=N();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:Xs,children:m.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ot,{direction:"up",title:m.relation.belongsToWork,entity:r,onView:x,onUnlink:()=>g("workId"),onLink:()=>f("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(ot,{direction:"up",title:m.relation.containedInCollection,entity:l,onView:x,onUnlink:()=>g("collectionId"),onLink:()=>f("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(Ye,{direction:"horizontal",title:`${m.relation.siblingVersions} (${p.length})`,entities:p,onView:x,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(ot,{direction:"up",title:m.relation.parentWork,entity:o,onView:x,onUnlink:()=>g("parentWorkId"),onLink:()=>f("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(Ye,{direction:"down",title:`${m.relation.childWorks} (${c.length})`,entities:c,onView:x,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),a&&a.length>0&&e.jsx(Ye,{direction:"down",title:`${m.relation.collectionImpl} (${a.length})`,entities:a,onView:x,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ye,{direction:"down",title:`${m.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,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(ot,{direction:"up",title:m.relation.correspondingWork,entity:r,onView:x,onUnlink:()=>g("workId"),onLink:()=>f("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(ot,{direction:"up",title:m.relation.parentCollection,entity:s,onView:x,onUnlink:()=>g("parentCollectionId"),onLink:()=>f("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(Ye,{direction:"down",title:`${m.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:x,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ye,{direction:"down",title:`${m.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},ot=({direction:t,title:n,entity:i,onView:o,onUnlink:s,onLink:r,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:p,unlinkLabel:f})=>{const g=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=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:x}),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:Zi(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(ei,{onClick:()=>o(i),title:p,children:"👁️"}),e.jsx(ei,{onClick:s,title:f,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(Qt,{onClick:r,children:c}),e.jsx(Qt,{onClick:l,primary:!0,children:a})]})]})},Ye=({direction:t,title:n,entities:i,onView:o,onAdd:s,addLabel:r,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=u.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=a?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(x=>e.jsxs("div",{onClick:()=>o(x),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:Zi(x.type)}),e.jsx("span",{children:x.title})]},x.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(Qt,{onClick:s,primary:!0,children:["+ ",r]})})]})},ei=({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}),Qt=({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 Zi(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Xs={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"},Qi=({isOpen:t,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:r,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,f]=u.useState(""),g=d?l.filter(m=>m.id!==d):l;u.useEffect(()=>{t&&(f(""),c(""))},[t]);const x=m=>{f(m),c(m)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Zs,children:e.jsxs("div",{style:Qs,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:el,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:m=>x(m.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:tl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:Ut,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:nl,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:Ut,children:["未找到匹配的",h]}):e.jsxs("div",{style:Ut,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:il,children:["创建新",h,"并关联"]})]})]})})},Zs={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},Qs={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)"},el={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},tl={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"},nl={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ut={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},il={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ti={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},ol={work:"📜",book:"📖",collection:"📚",entity:"👤"},eo=({isOpen:t,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:r})=>{const[l,c]=u.useState(""),a=u.useRef(null);u.useEffect(()=>{t&&(c((o==null?void 0:o.title)||""),setTimeout(()=>{var g,x;(g=a.current)==null||g.focus(),(x=a.current)==null||x.select()},100))},[t,o==null?void 0:o.title]);const d=g=>{g.key==="Enter"&&l.trim()?p():g.key==="Escape"&&r()},p=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!t)return null;const f=()=>{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`创建新${ti[n]}`}};return e.jsx("div",{style:rl,onClick:g=>{g.target===g.currentTarget&&r()},children:e.jsxs("div",{style:sl,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:ol[n]}),e.jsx("span",{children:f()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${ti[n]}名称...`,style:ll})]}),((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:al,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...cl,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},rl={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},sl={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)"},ll={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"},al={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},cl={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function dl(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function to(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function pl(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 no=({isOpen:t,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:r=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:p})=>{const[f,g]=u.useState(""),[x,h]=u.useState([]),[v,m]=u.useState(!1),[j,y]=u.useState("recent");u.useEffect(()=>{t&&(g(""),h([]),y(o.length>0?"recent":"search"))},[t,o.length]),u.useEffect(()=>{if(!f.trim()){h([]);return}const T=setTimeout(async()=>{m(!0);try{h(await p(f,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(T)},[f,i,p]);const k=u.useCallback(T=>{g(T.target.value),T.target.value.trim()&&y("search")},[]),_=u.useCallback(T=>s?T.filter(z=>z.id!==s):T,[s]);if(!t)return null;const w=n||(i==="all"?"选择实体":`选择${to(i)}`),I=_(o),S=_(x);return e.jsx("div",{style:xl,children:e.jsxs("div",{style:fl,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:f,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:ml}),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:"搜索中..."})]})}),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(ni,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",I.length,")"]}),e.jsxs(ni,{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"&&I.length>0?e.jsx(ii,{entities:I,onSelect:c}):f.trim()?v?e.jsx(Yt,{message:"搜索中..."}):S.length>0?e.jsx(ii,{entities:S,onSelect:c}):e.jsx(Yt,{message:"未找到匹配的结果"}):e.jsx(Yt,{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:hl,children:l||"创建新实体"})]})]})})},ni=({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}),ii=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(ul,{entity:i,onClick:()=>n(i)},i.id))}),ul=({entity:t,onClick:n})=>{const[i,o]=u.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:dl(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:pl(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:to(t.type)})]})},Yt=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),xl={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},fl={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"},ml={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"},hl={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},bl={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)"},yl={work:"📜",collection:"📚",book:"📖",entity:"👤"},io=({data:t,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:r,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:f,onRelationsChange:g})=>{var ee;const x=N(),[h,v]=u.useState(!1),[m,j]=u.useState("work"),[y,k]=u.useState(""),[_,w]=u.useState(""),[I,S]=u.useState([]),[T,z]=u.useState(!1),[C,b]=u.useState(!1),[R,E]=u.useState("work"),[A,M]=u.useState(""),[P,$]=u.useState(),[F,W]=u.useState(!1),[B,D]=u.useState(null),[te,G]=u.useState([]);u.useRef(null);const Z=t.type,re=Z==="work",ne=Z==="collection",U=Z==="book",Y=u.useCallback((L,X)=>{n({...t,[L]:X})},[t,n]),ce=u.useCallback((L,X)=>{k(L),j(X),w(x.editor.selectToLink+x.indexType[X]),S([]),v(!0)},[x]),Oe=u.useCallback(L=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,L)},[o,t.id]),Se=u.useCallback(L=>{s==null||s(L.id,L.type)},[s]),he=u.useCallback((L,X,se)=>{const J={...se,author:(se==null?void 0:se.author)||t.author,dynasty:(se==null?void 0:se.dynasty)||t.dynasty};E(X),M(L),$(J),b(!0)},[t.author,t.dynasty]),Ie=u.useCallback((L,X)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,A,{type:R,title:L,inheritData:X}),b(!1)},[o,t.id,A,R]),Ae=u.useCallback(L=>{if(!L.trim()){S([]);return}z(!0),o!=null&&o.searchEntities&&o.searchEntities(L,m).then(X=>{S(X),z(!1)}).catch(()=>{S([]),z(!1)})},[o,m]),ke=u.useCallback(L=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,y,L.id),v(!1)},[o,t.id,y]),Ne=u.useCallback(()=>{i()},[i]),Qe=u.useCallback(L=>{D(()=>L),W(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(G).catch(()=>{})},[o]),V=u.useCallback((L,X)=>o!=null&&o.searchEntities?o.searchEntities(L,X==="all"?void 0:X):Promise.resolve([]),[o]),ie=u.useCallback(L=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(L),G(X=>[L,...X.filter(se=>se.id!==L.id)].slice(0,10)),B==null||B(L),W(!1),D(null)},[o,B]);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:yl[Z]}),e.jsx("span",{children:t.title||x.editor.untitled}),e.jsx(Lt,{children:t.id}),e.jsx(Lt,{color:bl[Z],children:x.indexType[Z]})]})}),e.jsx(ye,{title:x.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:re?x.editor.workTitle:ne?x.editor.collectionTitle:x.editor.bookTitle,value:t.title,onChange:L=>Y("title",L)}),U&&e.jsx(_t,{label:x.editor.belongsToWork,value:t.workName||"",onChange:L=>Y("workName",L)}),e.jsx(xe,{label:x.editor.authorLabel,value:t.author||"",onChange:L=>Y("author",L)}),e.jsx(xe,{label:x.editor.dynastyLabel,value:t.dynasty||"",onChange:L=>Y("dynasty",L)}),(U||ne)&&e.jsx(_t,{label:x.editor.containedIn,value:t.collection||"",onChange:L=>Y("collection",L)}),(U||ne)&&e.jsx(xe,{label:x.editor.holderLabel,value:t.holder||"",onChange:L=>Y("holder",L)}),(U||ne)&&e.jsx(xe,{label:U?x.editor.pageLabel:x.editor.volumeLabel,value:t.pages||"",onChange:L=>Y("pages",L)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(xe,{label:x.editor.firstImageLabel,value:t.firstImage||"",onChange:L=>Y("firstImage",L)})})]})}),e.jsx(ye,{title:x.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Fe,{value:t.description||"",onChange:L=>Y("description",L),placeholder:x.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(ye,{title:x.section.additionalWorks,onSave:i,children:e.jsx(vl,{items:t.additional_works||[],onChange:L=>Y("additional_works",L)})}),e.jsx(ye,{title:x.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(jl,{items:t.indexed_by||[],onChange:L=>Y("indexed_by",L)})}),e.jsx(ye,{title:x.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(Sl,{items:t.emendated_by||[],onChange:L=>Y("emendated_by",L)})}),e.jsx(ye,{title:x.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(qt,{items:t.resources||[],onChange:L=>Y("resources",L),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(ye,{title:x.section.imageResources,onSave:i,children:e.jsx(qt,{items:t.resources||[],onChange:L=>Y("resources",L),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(ye,{title:x.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Ki,{items:Ji(t.sources||""),onChange:L=>Y("sources",qi(L)),onOpenEntityPicker:Qe})}),(U||ne)&&e.jsx(ye,{title:x.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Fe,{value:t.provenance||"",onChange:L=>Y("provenance",L),placeholder:x.editor.provenancePlaceholder})}),U&&e.jsx(ye,{title:x.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Fe,{value:t.otherEditions||"",onChange:L=>Y("otherEditions",L),placeholder:x.editor.otherEditionsPlaceholder})}),e.jsx(Xi,{entityType:Z,entityId:t.id,entityTitle:t.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:ce,onUnlinkEntity:Oe,onViewEntity:Se,onCreateAndLink:he,onSaveRelations:Ne}),r&&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:x.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:x.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:x.editor.deleteEntity})]}),e.jsx(Qi,{isOpen:h,entityType:m,title:_,onSelect:ke,onCancel:()=>v(!1),onCreate:()=>{v(!1),he(y,m)},searchResults:I,onSearch:Ae,isLoading:T,excludeId:t.id}),e.jsx(eo,{isOpen:C,entityType:R,relationField:A,inheritData:P,onConfirm:Ie,onCancel:()=>b(!1)}),e.jsx(no,{isOpen:F,title:x.action.selectBookOrWork,filterType:"all",recentEntities:te,excludeId:t.id,onSelect:ie,onCancel:()=>{W(!1),D(null)},onSearch:V})]})};function vl({items:t,onChange:n}){const i=N(),o=(l,c,a)=>{const d=t.map((p,f)=>f===l?{...p,[c]:a}:p);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),r=()=>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(xe,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>o(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(xe,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>o(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: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 oo({items:t,onChange:n,showMeta:i,addLabel:o}){const s=N(),[r,l]=u.useState(null),c=(p,f,g)=>{const x=t.map((h,v)=>v===p?{...h,[f]:g||void 0}:h);n(x)},a=p=>{n(t.filter((f,g)=>g!==p)),r===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,f)=>{const g=r===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:f),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:x=>{x.stopPropagation(),a(f)},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(xe,{label:s.label.sourceName,value:p.source,onChange:x=>c(f,"source",x)}),e.jsx(xe,{label:s.label.sourceBid,value:p.source_bid||"",onChange:x=>c(f,"source_bid",x)})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(xe,{label:s.label.titleInfo,value:p.title_info||"",onChange:x=>c(f,"title_info",x)}),e.jsx(xe,{label:s.label.authorInfo,value:p.author_info||"",onChange:x=>c(f,"author_info",x)})]}),e.jsx(xe,{label:s.label.edition,value:p.edition||"",onChange:x=>c(f,"edition",x)})]}),e.jsx(Fe,{value:p.summary||"",onChange:x=>c(f,"summary",x),placeholder:s.editor.summaryPlaceholder}),e.jsx(Fe,{value:p.comment||"",onChange:x=>c(f,"comment",x),placeholder:s.editor.commentPlaceholder}),e.jsx(Fe,{value:p.additional_comment||"",onChange:x=>c(f,"additional_comment",x),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),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 jl({items:t,onChange:n}){const i=N();return e.jsx(oo,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function Sl({items:t,onChange:n}){const i=N();return e.jsx(oo,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function ro(t){var c,a,d,p,f,g,x;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)||"",o=((p=t.current_location)==null?void 0:p.name)||"",s=(f=t.page_count)!=null&&f.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||"",l={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&&(l.parentWorkId=v.id,l.parentWorkName=v.title)}}if(t.type==="book"){const h=t;l.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(l.collectionId=(x=h.contained_in[0])==null?void 0:x.id)}return l}function kl(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 wl=t=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:r,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:f,renderSectionActions:g,onDownloadResource:x,downloadStatuses:h,relations:v,onRelationsChange:m,headerExtra:j,className:y,style:k}=t;N();const[_,w]=u.useState(s),I=r?s:_;u.useEffect(()=>{s!==_&&w(s)},[s]);const S=u.useCallback(()=>{const A=I==="view"?"edit":"view";r?r(A):w(A)},[I,r]),[T,z]=u.useState(null);u.useEffect(()=>{i&&o&&o.getItem(i).then(A=>{A&&z(A)})},[i,o]);const C=n||T,b=u.useMemo(()=>C?ro(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: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&&!b?e.jsx(De,{}):I==="view"?e.jsx(cn,{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(io,{data:b,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:o,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:g,onDownloadResource:x,downloadStatuses:h,relations:v,onRelationsChange:m})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},oi=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],so=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const[s,r]=u.useState(null),[l,c]=u.useState(""),[a,d]=u.useState("idle"),[p,f]=u.useState(""),g=u.useRef(null);u.useEffect(()=>{t&&(r(null),c(""),d("idle"),f(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=g.current)==null?void 0:m.focus()},100)},[s]),u.useEffect(()=>{if(a==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[a,n]),u.useEffect(()=>{if(!t)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const x=async()=>{if(!(!s||!l.trim())){d("submitting"),f("");try{await i({type:s,content:l.trim()}),d("success")}catch(m){d("error"),f(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&l.trim()&&a!=="submitting",v=oi.find(m=>m.value===s);return e.jsx("div",{style:_l,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:Cl,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:Il,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Tl,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:Ll,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:oi.map(m=>e.jsxs("button",{onClick:()=>r(m.value),style:{...zl,...s===m.value?Rl:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:g,value:l,onChange:m=>c(m.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...El,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:Wl,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:x,disabled:!h,style:{...Bl,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},_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},Cl={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)"},Il={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Tl={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},zl={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"},Rl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},El={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"},Bl={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ll={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Wl={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},$l=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[o,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...Al,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(so,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},Al={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"},ri=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],lo=({onSubmit:t})=>{const[n,i]=u.useState("bug"),[o,s]=u.useState(""),[r,l]=u.useState("idle"),[c,a]=u.useState(""),d=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var x;return(x=d.current)==null?void 0:x.focus()},100)},[n]);const p=async()=>{if(!(!n||!o.trim())){l("submitting"),a("");try{await t({type:n,content:o.trim()}),l("success"),s(""),i("bug")}catch(x){l("error"),a(x instanceof Error?x.message:"提交失败,请稍后重试")}}},f=n&&o.trim()&&r!=="submitting",g=ri.find(x=>x.value===n);return r==="success"?e.jsx("div",{style:si,children:e.jsxs("div",{style:Dl,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Ol,children:"继续提交"})]})}):e.jsxs("div",{style:si,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:ri.map(x=>e.jsxs("button",{onClick:()=>i(x.value),style:{...Ml,...n===x.value?Fl:{}},children:[e.jsx("span",{children:x.icon})," ",x.label]},x.value))}),e.jsx("textarea",{ref:d,value:o,onChange:x=>s(x.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:r==="submitting",style:{...Pl}}),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:!f,style:{...Hl,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:r==="submitting"?"提交中...":"提交"})]}),r==="error"&&e.jsx("div",{style:Nl,children:c})]})},si={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Ml={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"},Fl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Pl={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"},Hl={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Dl={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Ol={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Nl={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function li(t){return typeof t=="function"?t():t??"/api/feedback"}const ao=({resourceId:t,apiUrl:n})=>{const[i,o]=u.useState([]),[s,r]=u.useState(!0),l=u.useCallback(async()=>{const a=li(n);r(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&o(p.items)}catch{}finally{r(!1)}},[t,n]);u.useEffect(()=>{l()},[l]);const c=async a=>{const d=li(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 f=await p.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(gn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(lo,{onSubmit:c})})]})},Vl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Gl={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function st(t){return Gl[t]??t}const ai=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],co={建安:196,黃初:220,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,會昌: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,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,元祿:1688,享保:1716,延享:1744,寬政:1789,文政:1818,天保:1830,明治:1868,大正:1912,昭和:1926},Ul={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function po(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 l=Ul[r];if(l===void 0)return;o=!0,r==="十"?i=(i||1)*10:r==="廿"||r==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return o&&s>0?s:void 0}function Ct(t){for(const n of Vl)if(t.startsWith(n))return n}const It={};{const t=(n,i)=>{for(const o of i)It[o]=n};t("東漢",["建安"]),t("三國",["黃初"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","元祿","享保","延享","寬政","文政","天保","明治","大正","昭和"])}function lt(t,n){for(const i of Object.keys(co))if(t.includes(i)){if(n&&It[i]&&It[i]!==n){const o=n==="北宋"||n==="南宋"?"宋":n;if(It[i]!==o)continue}return i}}function mn(t){var r,l,c;const n={era:"",reign:"",source:"none"},i=(r=t.lineage)==null?void 0:r.year_text;if(i){const a=Ct(i)??"";return{era:st(a),reign:lt(i,a)??"",source:"lineage"}}const o=(l=t.publication_info)==null?void 0:l.year;if(o){const a=Ct(o)??((c=ai.find(f=>f.pattern.test(o)))==null?void 0:c.era)??"",d=lt(o,a)??"";if(a||d)return{era:st(a),reign:d,source:"publication"};const p=o.match(/\d{3,4}/);if(p)return{era:"",reign:p[0],source:"publication"}}const s=t.edition||t.title||"";if(s){const a=Ct(s);if(a)return{era:st(a),reign:lt(s,a)??"",source:"edition"};const d=ai.find(p=>p.pattern.test(s));if(d)return{era:st(d.era),reign:lt(s,d.era)??d.reign??"",source:"edition"}}return n}function uo(t){var i,o,s;if(typeof((i=t.lineage)==null?void 0:i.year)=="number")return t.lineage.year;const n=[(o=t.lineage)==null?void 0:o.year_text,(s=t.publication_info)==null?void 0:s.year,t.edition,t.title].filter(Boolean);for(const r of n){const l=r.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??r.match(/[((](\d{3,4})\s*年?[))]/);if(l){const d=parseInt(l[1],10);if(d>=100&&d<=2100)return d}const c=Ct(r),a=lt(r,c);if(a){const d=co[a],f=r.slice(r.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=f?po(f[1]):void 0;return d+(g?g-1:0)}}}const ci=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function at(t){const n=ci.indexOf(t);return n===-1?ci.length:n}function xo(t){const n={belongsTo:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const r=s.relation;r==="part_of"||r==="collected_in"?n.belongsTo.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("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),i}function $t(t,n){const i=on(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,f)=>{const g=x=>x.group_role==="origin"?0:x.group_role==="mirror"?1:2;return g(p)-g(f)});const r={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=Pe(d),f=p.includes("text"),g=p.includes("image");f&&g?r.textImage.push(d):f?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]})),a=[...o.entries()].map(([d,p])=>{var f,g;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(g=n==null?void 0:n[d])==null?void 0:g.description,items:p}});return{buckets:c,mirrors:a,total:i.length}}function hn(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=rn(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 Yl(t,n){if(hn(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 fo(t,n){var r,l;const i=t.resources||[],o=[],s=[];for(const c of i){const a=Pe(c);a.includes("image")&&o.push(c),a.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:mn(t),year:uo(t),images:o,holders:s,locationName:(r=t.current_location)==null?void 0:r.name,important:Kl(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:o.length>0}}function Kl(t,n){var c,a;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)??[],l=(a=n.node_groups)==null?void 0:a[t];return!!l&&r.includes(l)}function go(t,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!o.has(a.id)).map(a=>fo(a,n));let r=s;i.era&&(r=r.filter(a=>a.era.era===i.era)),i.scanOnly&&(r=r.filter(a=>a.hasImage)),i.sort==="year"?r=[...r].sort((a,d)=>a.year!=null&&d.year!=null?a.year-d.year:a.year!=null?-1:d.year!=null?1:at(a.era.era)-at(d.era.era)):r=r.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=f=>(f.important?0:1)*2+(f.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)=>at(a)-at(d));return{rows:r,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Jl(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,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],f=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?(f.has(k)||f.set(k,[]),f.get(k).push(y)):g.push(y)}if(g.length+[...f.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=[...f.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 mo=["撰","編","注","校","譯","繪","其他"],ql=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function bn(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:o}of ql)if(o.test(n))return i;return"其他"}function ho(t){const n=new Map;for(const o of t){const s=bn(o);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const o of mo){const s=n.get(o);s&&i.push({cls:o,label:o,count:s})}return i.length>2?i:[]}function bo(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})),r=[...new Set(s.map(l=>l.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:ut(r.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var r,l;return{id:s,title:((r=i==null?void 0:i.get(s))==null?void 0:r.title)||s,edition:(l=i==null?void 0:i.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function ut(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 yn(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((r,l)=>r-l),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 Xl=["〇","一","二","三","四","五","六","七","八","九"],di=["","十","百","千"];function yo(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 l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=di[c]:o+=Xl[l]+di[c])}return o}function He(t,n="卷"){var o,s;const i=t;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?yo(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function vo(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 jo=1e3,Zl="(max-width: 719px)",So=`
|
|
1
|
+
"use strict";var Go=Object.create;var Rn=Object.defineProperty;var Uo=Object.getOwnPropertyDescriptor;var Yo=Object.getOwnPropertyNames;var Ko=Object.getPrototypeOf,Jo=Object.prototype.hasOwnProperty;var qo=(t,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Yo(n))!Jo.call(t,s)&&s!==i&&Rn(t,s,{get:()=>n[s],enumerable:!(o=Uo(n,s))||o.enumerable});return t};var nt=(t,n,i)=>(i=t!=null?Go(Ko(t)):{},qo(n||!t||!t.__esModule?Rn(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"),u=require("react"),Xo=require("react-markdown"),Zo=require("remark-gfm"),Qo=require("react-dom"),er=t=>`/book-index?id=${t}`,_i=u.createContext(er);function tr({buildUrl:t,children:n}){const i=u.useMemo(()=>t,[t]);return e.jsx(_i.Provider,{value:i,children:n})}function me(){return u.useContext(_i)}function De(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function nr(t,n){return De(t).includes(n)}const Ci={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ir={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},or={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},bt=u.createContext(null),Ii={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:"收入",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:"圖片資源"}},rr={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:"收入",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:"图片资源"}},sr={"zh-Hant":Ii,"zh-Hans":rr},zi="bim-locale";function lr(){try{const t=localStorage.getItem(zi);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function ar(t){try{localStorage.setItem(zi,t)}catch{}}const cr="zh-Hans",dr=({locale:t,onLocaleChange:n,children:i})=>{const[o,s]=u.useState(t??cr),r=t??o;u.useEffect(()=>{if(t)return;const p=lr();p&&p!==o&&s(p)},[]);const[l,c]=u.useState(null);u.useEffect(()=>{r==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const f=p.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>p=>p)}):c(null)},[r]);const a=u.useCallback(p=>{s(p),ar(p),n==null||n(p)},[n]),d=u.useMemo(()=>({locale:r,setLocale:a,messages:sr[r],converter:l}),[r,a,l]);return e.jsx(bt.Provider,{value:d,children:i})};function O(){const t=u.useContext(bt);return(t==null?void 0:t.messages)??Ii}const pr=2e3;function D(){const t=u.useContext(bt),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,o=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const r=u.useCallback(l=>{if(!l)return"";if(!i)return l;const c=o.current.get(l);if(c!==void 0)return c;const a=i(l);if(o.current.size>=pr){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(l,a),a},[i]);return u.useMemo(()=>({convert:r,locale:n,isSimplified:n==="zh-Hans"}),[r,n])}function yt(t,n){return t.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}function ur(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 xr(){return{id:"",name:"",url:"",type:"text",details:""}}const qt=({items:t,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const r=O(),[l,c]=u.useState(null),a=[{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=De(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},f=t.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>p(y)),g=()=>{const y=xr();s&&(y.type=s),n([...t,y]),c(t.length)},x=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 z=ur(_);z&&(w[y].id=z)}n(w)},v=(y,k,_)=>{const z={...t[y].metadata||{}};_?z[k]=_:delete z[k],h(y,"metadata",Object.keys(z).length>0?z: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 z=t[y].coverage||{level:1,ranges:""};k==="level"?z.level=parseInt(_)||1:z.ranges=_,h(y,"coverage",z.ranges?z:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,originalIndex:k})=>{var _,w,z;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:fr(y.type??"text"),color:"#fff"},children:(()=>{var I,T;const S=De(y);return S.length===0?y.type??"text":S.length===1?((I=a.find(C=>C.value===S[0]))==null?void 0:I.label)??S[0]:S.includes("text")&&S.includes("image")?((T=a.find(C=>C.value==="text+image"))==null?void 0:T.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&&gr(k,o==null?void 0:o[k],i,r),e.jsx("button",{onClick:S=>{S.stopPropagation(),x(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisResource,children:"✕"})]}),l===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[nr(y,"image")&&y.url&&mr(y,r),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:it,children:[e.jsx("span",{style:ot,children:r.label.type}),e.jsx("select",{value:y.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:it,children:[e.jsx("span",{style:ot,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:it,children:[e.jsx("span",{style:ot,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:{...it,flex:1},children:[e.jsx("span",{style:ot,children:r.label.coverageRange}),e.jsx("input",{type:"text",value:((z=y.coverage)==null?void 0:z.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 T;return e.jsxs("label",{style:{...it,gap:"4px"},children:[e.jsx("span",{style:{...ot,minWidth:"56px"},children:I}),e.jsx("input",{type:"text",value:((T=y.metadata)==null?void 0:T[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 fr(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 gr(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:l=>{l.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 mr(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"},it={display:"flex",alignItems:"center",gap:"6px"},ot={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},hr={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function gt(t){try{return hr[new URL(t).hostname]}catch{return}}const En={text:0,image:1,physical:2};function nn(t){return t.length===0?"physical":[...t].sort((n,i)=>(En[n]??99)-(En[i]??99)).join("+")}function on(t){const n=l=>{const c=l.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},i=new Map;for(let l=0;l<t.length;l++){const c=t[l];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[d,p]=a,f=`${d}|${nn(De(c))}`;i.has(f)||i.set(f,{base:{...c,name:d,url:"",volumes:[]},volumes:[],indices:[]});const g=i.get(f);g.volumes.push({volume:p,url:c.url||void 0,status:"found"}),g.indices.push(l)}const o=[],s=new Set;for(const l of i.values())if(!(l.volumes.length<2)){l.volumes.sort((c,a)=>c.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,o.push(l.base);for(const c of l.indices)s.add(c)}const r=[...o];for(let l=0;l<t.length;l++)s.has(l)||r.push(t[l]);return r}function Ti(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 Ri(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Ti(n)}))}function rn(t){const n=Ri(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 sn(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 ln(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 Bt(t){if(!t.url)return;const n=sn(t.metadata);return n?ln(t.url,n):t.url}const Bn={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 br(t){return t.includes("text")&&t.includes("image")?Bn["text+image"]:Bn[t[0]||"physical"]}const an=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const r=O(),{convert:l}=D(),c=u.useMemo(()=>on(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=u.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=z=>z.group_role==="origin"?0:z.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},f=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(Nt,{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: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,z)=>e.jsx(Nt,{item:w,onNavigate:o,renderLink:s},w.id||z))})]},`group-${m}`)},x=new Map;for(const m of d){const j=nn(De(m));x.has(j)||x.set(j,[]),x.get(j).push(m)}const h=["text","image","text+image","physical"],v=[...h.filter(m=>x.has(m)),...[...x.keys()].filter(m=>!h.includes(m)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([m,j])=>g(m,j)),v.map(m=>{const j=x.get(m),y=br(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:f(m)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>e.jsx(Nt,{item:k,onNavigate:o,renderLink:s},k.id||_))})]},m)})]})},yr={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)"}},Nt=({item:t})=>{const n=O(),{convert:i}=D(),[o,s]=u.useState(!1),r=u.useMemo(()=>(t.url?gt(t.url):void 0)||i(t.name),[t.url,t.name,i]),l=u.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||Ti(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),f=t.color_mode?{...yr[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?i(t.details):null,x={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:x,children:[e.jsx("span",{style:{fontWeight:500},children:r}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",p,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=sn(t.metadata);return h?ln(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:l.map(h=>{const v=h.status==="missing";return h.url&&!v?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:v?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1},children:h.volume},h.volume)})})]})},Ei=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:r,onSelectFolder:l})=>{const c=O(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",f=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)"},x={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"},...x,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:o,title:c.mode.switchToSync,style:g,...x,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...x,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):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,...x,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:f||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...x,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...x,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...x,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&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:f})]})]})},$t="bim-search-history",Ln=10,Wn=8;function pt(){try{const t=localStorage.getItem($t);return t?JSON.parse(t):[]}catch{return[]}}function vr(t){try{const n=pt().filter(i=>i!==t);n.unshift(t),n.length>Ln&&(n.length=Ln),localStorage.setItem($t,JSON.stringify(n))}catch{}}function jr(t){try{const n=pt().filter(i=>i!==t);localStorage.setItem($t,JSON.stringify(n))}catch{}}function Sr(){try{localStorage.removeItem($t)}catch{}}const Bi=({transport:t,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:r})=>{const l=O(),c=r??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=u.useState(!1),[f,g]=u.useState([]),[x,h]=u.useState(-1),[v,m]=u.useState(pt),j=u.useRef(null),y=u.useRef(null),k=u.useRef(null),_=u.useRef(!1);u.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,Wn).then(A=>{if(R)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];g(M.slice(0,Wn).map(P=>({type:"entry",text:P.title||P.id,entry:P})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,v,t]),u.useEffect(()=>{const b=R=>{k.current&&!k.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]),u.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=u.useCallback(b=>{b.trim()&&(vr(b.trim()),m(pt())),o(b),p(!1)},[o]),z=u.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=u.useCallback(b=>{if(!d||f.length===0){b.key==="Enter"&&w(n);return}switch(b.key){case"ArrowDown":b.preventDefault(),h(R=>(R+1)%f.length);break;case"ArrowUp":b.preventDefault(),h(R=>(R-1+f.length)%f.length);break;case"Enter":b.preventDefault(),x>=0&&x<f.length?z(f[x]):w(n);break;case"Escape":b.preventDefault(),p(!1);break}},[d,f,x,n,w,z]),I=u.useCallback((b,R)=>{R.stopPropagation(),jr(b),m(pt()),g(E=>E.filter(A=>!(A.type==="history"&&A.text===b)))},[]),T=u.useCallback(b=>{b.stopPropagation(),Sr(),m([]),g([])},[]);u.useEffect(()=>{if(x>=0&&y.current){const b=y.current.children;b[x]&&b[x].scrollIntoView({block:"nearest"})}},[x]);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&&f.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:l.search.history}),e.jsx("button",{onClick:T,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),f.map((b,R)=>e.jsxs("div",{onClick:()=>z(b),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:R===x?"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:[a[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:l.action.remove,children:"×"})]},`${b.type}-${b.text}-${R}`))]})]})},mt="bim-recent-ids",$n="bim-recent-entries",An=50,Vt=5,kr=50,wr=200;function ut(){try{const t=localStorage.getItem(mt);if(t)return JSON.parse(t);const n=localStorage.getItem($n);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(mt,JSON.stringify(i)),localStorage.removeItem($n),i}return[]}catch{return[]}}function _r(t){try{const n=ut().filter(i=>i!==t);n.unshift(t),n.length>An&&(n.length=An),localStorage.setItem(mt,JSON.stringify(n))}catch{}}function Cr(t){try{const n=ut().filter(i=>i!==t);localStorage.setItem(mt,JSON.stringify(n))}catch{}}function Ir(){try{localStorage.removeItem(mt)}catch{}}const zr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xt=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:f,initialQuery:g,onQueryChange:x,headerRight:h})=>{const v=O(),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]=u.useState(g??""),[k,_]=u.useState(null),[w,z]=u.useState(null),[S,I]=u.useState(!1),[T,C]=u.useState(null),[b,R]=u.useState(""),[E,A]=u.useState(!g),[M,P]=u.useState(ut),[$,F]=u.useState([]),[Q,W]=u.useState(!1),[U,ne]=u.useState(!1),[B,V]=u.useState(null),[Y,ie]=u.useState(null),G=u.useRef(void 0),K=u.useRef(!1),de=u.useCallback(async(N,oe)=>{if(!N.trim()){A(!0),_(null),z(null);return}A(!1),I(!0),R("");try{if(t.searchAll){const te=await t.searchAll(N,oe??Vt);_(te)}else{const te=["work","book","collection","entity"],L=await Promise.all(te.map(Z=>t.search(N,Z,{page:1,pageSize:oe??Vt})));_({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]);u.useEffect(()=>{let N=!1;const oe=()=>{var J,$e;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=(($e=t.getSubtypeStats)==null?void 0:$e.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([L,Z,se]).then(([je,fe,Ue])=>{N||(V({works:je[0].total,books:je[1].total,collections:je[2].total,entities:je[3].total,hasText:fe==null?void 0:fe.hasText,hasImage:fe==null?void 0:fe.hasImage}),Ue&&ie(Ue))})};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]),u.useEffect(()=>{K.current||!(g!=null&&g.trim())||(K.current=!0,de(g))},[g,de]);const he=u.useCallback(N=>{if(y(N),!N.trim()){x==null||x(N),A(!0),_(null),z(null);return}G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{z(null),x==null||x(N),de(N)},wr)},[de,x]),pe=u.useCallback(N=>{G.current&&clearTimeout(G.current),x==null||x(N),de(N)},[de,x]),le=u.useCallback(N=>{z(N),de(j,kr)},[j,de]);u.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 ve=N=>{C(N.id),_r(N.id),P(ut()),o==null||o(N)},Fe=N=>{Cr(N),P(ut())},_e=()=>{Ir(),P([])},Ge=N=>m.find(oe=>oe.type===N),tt=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(Ei,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Bi,{transport:t,value:j,onChange:he,onSearch:pe,onEntrySelect:ve}),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(Rr,{id:N.id,onRemove:Fe,t:v},N.id):e.jsx(Mn,{entry:N,selected:T===N.id,onClick:ve,getConfig:Ge,onRemove:Fe},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})]})}):tt?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=zr[L],J=k[se]??0;if(Z.length===0)return null;const je=!(w===N)&&J>Vt;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]})]}),je&&e.jsx("button",{onClick:()=>le(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(f)return e.jsx(u.Fragment,{children:f(fe)},fe.id);const Ue=p==="card"?Tr:Mn;return e.jsx(Ue,{entry:fe,selected:T===fe.id,onClick:ve,getConfig:Ge,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:yt(v.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v.search.tryOther})]})})]})},Tr=({entry:t,selected:n,onClick:i,getConfig:o,query:s})=>{const r=O(),{convert:l}=D(),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}${r.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&d.length?d.find(g=>{const x=typeof g=="string"?g:g==null?void 0:g.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,f="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, ${f} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${f} 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, ${f} 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:f},children:Array.from(c).map((g,x)=>e.jsx("span",{children:g},x))})]}),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.edition&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l(t.edition)}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[r.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:[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]})]})]})]})},Mn=({entry:t,selected:n,onClick:i,getConfig:o,query:s,onRemove:r})=>{const l=O(),{convert:c}=D(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(p=>{const f=typeof p=="string"?p:p==null?void 0:p.book_title;return f==null?void 0:f.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:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.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,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)]})]}),r?e.jsx("button",{onClick:p=>{p.stopPropagation(),r(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:"→"})]})},Rr=({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 Er(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 Br({data:t}){const{convert:n}=D(),{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 Lr({alt_names:t}){const{convert:n}=D(),i=new Map;for(const r of t){const l=r.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(r.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((r,l)=>{const c=o.indexOf(r),a=o.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(r=>{const l=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: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))})]},r)})})}function Wr({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 $r({works:t,transport:n,onNavigate:i,renderLink:o}){const s=O(),{convert:r}=D(),l=me(),[c,a]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let g=!1;const x=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(x);let _=!0;for(let w=0;w<x.length;w++){const z=k[w];z!=null&&z.title?v.set(x[w],z.title):z!=null&&z.primary_name?v.set(x[w],z.primary_name):_=!1}if(_)return v}catch{}const m=[...x],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 z=await n.getEntry(k);if(z!=null&&z.title){v.set(k,z.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||a(v)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const x=g.role||"";d.has(x)||d.set(x,[]),d.get(x).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((g,x)=>{const h=p.indexOf(g),v=p.indexOf(x);return h===-1&&v===-1?g.localeCompare(x):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,")"]})]}),f.map(g=>{const x=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:["(",x.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:x.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: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})},v):e.jsx("li",{children:m},v)})})]},g)})]})}const Li=({data:t,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:r})=>{var f;const l=O(),{convert:c}=D();let a=!1;try{a=X.extractStatus(t.id)==="draft"}catch{}const d=Er(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(Br,{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(Lr,{alt_names:t.alt_names}),e.jsx(Wr,{data:t}),((f=t.description)==null?void 0:f.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($r,{works:t.works,transport:n,onNavigate:i,renderLink:o})]})},Wi={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})},Ar={...Wi,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Le=({text:t,plainStrong:n,style:i,className:o})=>{const{convert:s}=D(),r=n?Ar:Wi;return e.jsx("div",{className:o,style:i,children:e.jsx(Xo,{remarkPlugins:[Zo],components:r,children:s(t)})})},Mr=["〇","一","二","三","四","五","六","七","八","九"],Fn=["","十","百","千"];function $i(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 l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=Fn[c]:o+=Mr[l]+Fn[c])}return o}function Ai(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 Fr={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 Pr({type:t}){const n=O();return e.jsx("span",{style:Ai(Fr[t]),children:n.indexType[t]})}function Hr({isDraft:t}){const n=O(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Ai(i),children:t?n.status.draft:n.status.official})}function Dr({id:t}){const n=O(),[i,o]=u.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 ze({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 Mi({authors:t,type:n,onNavigate:i,renderLink:o}){const{convert:s}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,l)=>{const c=s(r.name),a=r.entity_id?e.jsx(ke,{id:r.entity_id,label:c,onNavigate:i,renderLink:o}):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:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(r.dynasty),"〕"]}),a,r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(r.role)]})]},l)})})}function ke({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 Or({id:t,title:n,edition:i,type:o,isDraft:s,authors:r,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(Pr,{type:o}),e.jsx(Hr,{isDraft:s}),e.jsx(Dr,{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(Mi,{authors:r,type:o,onNavigate:d,renderLink:p}),c]})]})}function Fi({items:t,label:n,showMeta:i,onNavigate:o,renderLink:s}){const r=O(),{convert:l}=D();if(!t.length)return null;const[c,a]=u.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 f=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?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:f?"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)}),!f&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ke,{id:d.source_bid,label:r.action.view,onNavigate:o,renderLink:s})})]}),f&&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(ze,{label:r.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(ze,{label:r.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(ze,{label:r.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:r.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:r.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:r.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 Nr({items:t,onNavigate:n,renderLink:i}){const o=O();return e.jsx(Fi,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Pi({items:t,onNavigate:n,renderLink:i}){const o=O();return e.jsx(Fi,{items:t,label:o.section.emendated,onNavigate:n,renderLink:i})}function Hi({label:t,items:n}){const{convert:i}=D();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 Vr({items:t}){const n=O();return e.jsx(Hi,{label:n.section.aliases,items:t})}function Gr({items:t}){const n=O();return e.jsx(Hi,{label:n.section.attachedTexts,items:t})}function Ur({items:t}){const n=O(),{convert:i}=D();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 Yr({items:t}){const n=O(),{convert:i}=D();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 Kr({items:t}){const n=O(),{convert:i}=D();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 Pn({title:t,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:r}=D(),[l,c]=u.useState([]);return u.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(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:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${r(a.title)||a.id}(${r(a.edition)})`:r(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:o,renderLink:s})},a.id)})})]}):null}function Gt({book:t,onNavigate:n,renderLink:i}){const o=O(),{convert:s}=D(),[r,l]=u.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&&!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(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: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(an,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Jr({ids:t,workData:n,transport:i,onNavigate:o,renderLink:s,footer:r}){const l=O(),{convert:c}=D(),[a,d]=u.useState([]);if(u.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(v=>({id:v})));return}let h=!1;return Promise.all(t.map(v=>i.getItem(v).then(m=>({id:v,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:v})))).then(v=>{h||d(v)}),()=>{h=!0}},[t,i]),!t.length)return null;const p=a.length?a:t.map(h=>({id:h})),f=new Map(p.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,x=qr(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),r,x.useGrouping?e.jsxs(e.Fragment,{children:[x.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:x.coreIds.map(h=>{const v=f.get(h);return v?e.jsx(Gt,{book:v,onNavigate:o,renderLink:s},h):null})}),x.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=f.get(v);return m?e.jsx(Gt,{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(Gt,{book:h,onNavigate:o,renderLink:s},h.id))})]})}function qr(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,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],f=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?(f.has(k)||f.set(k,[]),f.get(k).push(y)):g.push(y)}if(g.length+[...f.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=[...f.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 Xr({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const o=O(),{convert:s}=D(),r=!!((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: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(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:[$i(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Mi,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),r&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(Le,{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(ze,{label:o.label.parentWork,children:e.jsx(ke,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Zr({items:t,onNavigate:n,renderLink:i}){const o=O(),{convert:s}=D();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(ke,{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:yt(o.catalog.volume,{n:r.volume_index})})]},r.id))}):null}const cn=({data:t,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:r,relatedBooksFooter:l,className:c,style:a})=>{var R,E,A,M,P,$,F,Q;const d=O(),{convert:p}=D(),[f,g]=u.useState(null),[x,h]=u.useState(!1),[v,m]=u.useState(null),[j,y]=u.useState(null),[k,_]=u.useState([]),w=t||f;if(u.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]),u.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]),x)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,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:{...a,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:a,children:e.jsx(Li,{data:w,transport:i,onNavigate:o,renderLink:s,headerExtra:r})});const z=w.type==="book"?w:null,S=w.type==="collection"?w:null,I=w.type==="work"?w:null;let T=!1;try{T=X.extractStatus(w.id)==="draft"}catch{}let C="";w.measure_info?C=p(w.measure_info):(R=w.juan_count)!=null&&R.number?C=$i(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(ze,{label:d.label.year,children:w.publication_info.year},"year")),(M=w.current_location)!=null&&M.name&&b.push(e.jsx(ze,{label:d.label.currentLocation,children:p(w.current_location.name)},"loc")),(P=w.page_count)!=null&&P.description&&b.push(e.jsx(ze,{label:d.label.pageCount,children:w.page_count.description},"page")),z!=null&&z.edition&&b.push(e.jsx(ze,{label:d.label.edition,children:p(z.edition)},"ver")),I!=null&&I.parent_work&&b.push(e.jsx(ze,{label:d.label.parentWork,children:e.jsx(ke,{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(ze,{label:d.label.parentWork,children:I.parent_works.map((W,U)=>e.jsxs("span",{children:[U>0&&"、",e.jsx(ke,{id:W,onNavigate:o,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(Or,{id:w.id,title:p(w.title),edition:w.edition?p(w.edition):void 0,type:w.type,isDraft:T,authors:w.authors,volumeText:C,meta:b,headerExtra:r,onNavigate:o,renderLink:s}),(($=w.description)==null?void 0:$.text)&&e.jsx(Le,{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(Le,{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(Zr,{items:k,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.belongsToWork}),e.jsx(Xr,{workData:j,onNavigate:o,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(Ur,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(Vr,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(Gr,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(Nr,{items:w.indexed_by,onNavigate:o,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(Pi,{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(an,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(Yr,{items:z.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Kr,{items:S.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(Pn,{title:d.section.relatedVersions,ids:z.related_books,transport:i,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Pn,{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(ke,{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(Jr,{ids:[...(I==null?void 0:I.books)||[],...(I==null?void 0:I.collections)||[]],workData:I,transport:i,onNavigate:o,renderLink:s,footer:l}),(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(ke,{id:K.id,label:p(K.title),onNavigate:o,renderLink:s})},K.id))})]},G.label))})()]})};function Qr({data:t}){const n=O(),{convert:i}=D(),{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 es({sections:t,activeSection:n,onSelect:i}){const o=O();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:Hn(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:Hn(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 Hn(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 ts({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 ns(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 Dn({book:t,onNavigate:n,renderLink:i,showVolumes:o}){const s=O(),{convert:r}=D(),l=t.book_id||t.work_id,c=o&&t.volumes.length>0?ns(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:[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: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(ts,{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 dn=({data:t,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:r,style:l})=>{const c=O(),[a,d]=u.useState(null),[p,f]=u.useState(!1),[g,x]=u.useState(null),[h,v]=u.useState(null),[m,j]=u.useState(""),y=t||a;u.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let S=!1;return f(!0),x(null),i.getCollectionCatalog(n).then(I=>{S||(I?d(I):x(c.catalog.notFound))}).catch(I=>{S||x(I instanceof Error?I.message:c.catalog.loadFailed)}).finally(()=>{S||f(!1)}),()=>{S=!0}},[t,n,i,c]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,_=u.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const S=y.books.map(T=>T.volumes[0]).filter(T=>T!=null);return new Set(S).size<S.length},[y]),w=u.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(T=>T.title.toLowerCase().includes(I)||T.sub_items&&T.sub_items.some(C=>C.toLowerCase().includes(I))||T.edition&&T.edition.toLowerCase().includes(I))}return S},[y,h,m]),z=u.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 T=[...I.keys()].sort((C,b)=>C-b);for(const C of T)S.push({volume:C,books:I.get(C)});return S},[w,_]);return p?e.jsx("div",{className:r,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:r,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):y?e.jsxs("div",{className:r,style:l,children:[e.jsx(Qr,{data:y}),k&&e.jsx(es,{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:[z?z.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:yt(c.catalog.volume,{n:S.volume})}),S.books.map((T,C)=>e.jsx(Dn,{book:T,onNavigate:o,renderLink:s,showVolumes:T.volumes.length>1},`${S.volume}-${C}`))]},`${S.volume}-${I}`)):w.map((S,I)=>e.jsx(Dn,{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},Ve=()=>{const[t,n]=u.useState(1);return u.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)})},xe=6,kt=7,is=({content:t,children:n,placement:i="top",delayMs:o=100,maxWidth:s=280,wrapperStyle:r})=>{const[l,c]=u.useState(!1),[a,d]=u.useState(null),p=u.useRef(null),f=u.useRef(null),g=u.useRef(null),x=u.useCallback(()=>{const m=f.current,j=g.current;if(!m||!j)return;const y=m.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,w=document.documentElement.clientWidth;let z=i;i==="top"&&y.top-k.height-kt<8&&(z="bottom"),i==="bottom"&&y.bottom+k.height+kt>_-8&&(z="top");const S=z==="top"?y.top-k.height-kt:y.bottom+kt;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:z})},[i]),h=u.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),o)},[o]),v=u.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return u.useEffect(()=>{if(!l)return;const m=requestAnimationFrame(x);return()=>cancelAnimationFrame(m)},[l,x]),u.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:h,onMouseLeave:v,onFocus:h,onBlur:v,style:{display:"inline-block",...r},children:n}),l&&Qo.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-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)]})},On={A:"fine",B:"rough",C:"rough",D:"ocr"};function os(t){return typeof t!="string"?null:t in Ci?t:t in On?On[t]:null}const rs={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},ss={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ye(t){return typeof t!="string"?"":rs[t]??ss[t]??t}const ls=["〇","一","二","三","四","五","六","七","八","九"],Nn=["","十","百","千"],as=["","萬","億"];function Di(t){if(t===0)return"〇";if(t<0)return`負${Di(-t)}`;const n=[];let i=t,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(cs(s,o>0)+as[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function cs(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 l=i[r],c=i.length-1-r;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&r===0&&!n?s+=Nn[c]:s+=ls[l]+Nn[c]}return s.replace(/〇$/,"")}let xt=null,wt=null;const Lt=new Set;function ds(){return xt?Promise.resolve():wt||(wt=import("opencc-js/t2cn").then(t=>{xt=t.Converter({from:"tw",to:"cn"}),Lt.forEach(n=>n())}).catch(()=>{xt=t=>t,Lt.forEach(t=>t())}),wt)}function We(){const[,t]=u.useState(0);return u.useEffect(()=>{if(xt)return;const n=()=>t(i=>i+1);return Lt.add(n),ds(),()=>{Lt.delete(n)}},[]),xt??(n=>n)}function qe(t,n){return n(t).toLowerCase()}const pn="var(--bim-highlight-bg, #fff59d)";function et(t,n,i){if(!n)return t;const o=qe(n,i);if(!o)return t;const s=qe(t,i);if(s.length!==t.length)return t;const r=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(o,l);if(a===-1){r.push(t.slice(l));break}a>l&&r.push(t.slice(l,a)),r.push(e.jsx("mark",{style:{background:pn,padding:0,color:"inherit"},children:t.slice(a,a+o.length)},c++)),l=a+o.length}return e.jsx(e.Fragment,{children:r})}function un(t,n,i,o){if(!n)return!0;const s=qe(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(l=>typeof l=="string"&&qe(l,o).includes(s))}function ps(t,n,i){return n?qe(t,i).includes(qe(n,i)):!0}const xn={类:"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)"},us={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function xs(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 Oi({file:t,isActive:n,onSelect:i,meta:o,matchState:s}){const r=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=xs(t),d=!!(o!=null&&o.vol_label)&&!a.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?`${pn}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:[a,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}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Ni(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(o=>Ni(o,n)))}function Vi(t){var o;const n=t.files.length,i=((o=t.children)==null?void 0:o.reduce((s,r)=>s+Vi(r),0))||0;return n+i}function fs(t,n){const i=[],o=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(o)};if(o(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 r=0;for(const l of s)typeof l=="number"&&(r+=l);return r}function Gi({group:t,activeFile:n,onSelect:i,depth:o=0,juanMeta:s,matchStates:r}){var h;const l=Ni(t,n||""),c=fs(t,r),a=typeof c=="number"&&c>0,d=c===0,[p,f]=u.useState(l||a),g=Vi(t),x=!!((h=t.children)!=null&&h.length);if(u.useEffect(()=>{l&&f(!0)},[l]),u.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!x){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)":_?`${pn}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:()=>f(!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: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:["(",g,")"]}),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+o*16}px`},children:t.files.map(v=>e.jsx(Oi,{file:v,isActive:n===v,onSelect:i,meta:s==null?void 0:s[v],matchState:r[v]},v))}),x&&t.children.map((v,m)=>e.jsx(Gi,{group:v,activeFile:n,onSelect:i,depth:o+1,juanMeta:s,matchStates:r},m))]})]})}function gs({files:t,groups:n,activeFile:i,onSelect:o,juanMeta:s,matchStates:r}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,a)=>e.jsx(Gi,{group:c,activeFile:i,onSelect:o,juanMeta:s,matchStates:r},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(Oi,{file:c,isActive:i===c,onSelect:o,meta:s==null?void 0:s[c],matchState:r[c]},c))})}function ms({type:t}){const n=xn[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 hs({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=D(),s=me(),r=We(),l=v=>{if(!v)return"";const m=o(v);return i?et(m,i,r):m},[c,a]=u.useState(!1),d=!!t.summary,p=!!t.comment,f=!!t.additional_comment,g=!!(t.content&&t.content.length>60),x=d||p||f||g;u.useEffect(()=>{i&&a(!0)},[i]);const h=!c&&g?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>x&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:x?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[x&&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:[Di(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&x&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!d&&!p&&!f&&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 bs({section:t,highlightQuery:n=""}){const{convert:i}=D(),o=We(),s=a=>{if(!a)return"";const d=i(a);return n?et(d,n,o):d},[r,l]=u.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!r),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ms,{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, ${xn[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 ys({section:t,highlightQuery:n=""}){const{convert:i}=D(),o=We();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?et(s,n,o):s,l=ye(t.type),c=xn[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}),r]})}function vs(t,n,i){const[o,s]=u.useState({});return u.useEffect(()=>{var d;if(!n||t.length===0)return;let r=!1;const l=t.filter(p=>{var f;return!((f=i==null?void 0:i.current)!=null&&f.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 f;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 x=g.title||p,h=g.authors,v=(f=h==null?void 0:h[0])==null?void 0:f.name;return{title:x,author:v}}catch{return null}};return Promise.all(l.map(async p=>{var g;const f=await a(p);return(g=i==null?void 0:i.current)==null||g.set(p,f),[p,f]})).then(p=>{r||s(f=>{const g={...f};for(const[x,h]of p)g[x]=h;return g})}),()=>{r=!0}},[t.join(","),n]),o}function js({section:t,onNavigate:n,transport:i,workLabelCache:o,highlightQuery:s=""}){const{convert:r}=D(),l=me(),c=We(),a=y=>{if(!y)return"";const k=r(y);return s?et(k,s,c):k},[d,p]=u.useState(!1);u.useEffect(()=>{s&&p(!0)},[s]);const f=t.type,g=us[f]||"var(--bim-desc-fg, #717171)",x=!!t.content,h=t.work_ids||[],v=h.length>1,m=vs(v?h:[],i,o),j=x&&!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:()=>x&&p(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:x?"pointer":"default",userSelect:"none"},children:[x&&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: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:f})]})]}),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:l(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&&x&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:a(t.comment)})]})]})}function Ss({juan:t,searchQuery:n,onNavigate:i,transport:o,workLabelCache:s}){const{convert:r}=D(),l=We(),c=n.trim(),a=u.useMemo(()=>c?t.sections.filter(f=>un(f,c,!0,l)):t.sections,[t.sections,c,l]),d=t.sections.filter(f=>ye(f.type)==="考证").length,p=a.filter(f=>ye(f.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:a.map((f,g)=>e.jsx(js,{section:f,onNavigate:i,transport:o,workLabelCache:s,highlightQuery:c},g))}),a.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function ks({text:t,highlightQuery:n=""}){const{convert:i}=D(),o=We(),s=l=>{const c=i(l);return n?et(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((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&&!r[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(u.Fragment,{children:s(d)},p))},c)})})}function ws({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=D(),s=me(),r=We(),l=d=>{if(!d)return"";const p=o(d);return i?et(p,i,r):p},c=[];let a=null;for(const d of t){const p=ye(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((f,g)=>ye(f.type)==="序"||ye(f.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(f.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&f.work_id?e.jsx("a",{href:s(f.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),x.stopPropagation(),n(f.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(f.title),children:e.jsx("strong",{children:l(f.title)})}):e.jsx("strong",{children:l(f.title)}),f.content&&l(f.content)]},g))]},p))})}function _s({juan:t,rawText:n,searchQuery:i,onNavigate:o}){const{convert:s}=D(),r=We(),[l,c]=u.useState("catalog"),a=i.trim(),d=u.useMemo(()=>a?t.sections.filter(x=>un(x,a,!1,r)):t.sections,[t.sections,a,r]),p=t.sections.filter(x=>ye(x.type)==="书").length,f=t.sections.filter(x=>ye(x.type)==="诗").length,g=a?d.filter(x=>ye(x.type)==="书"||ye(x.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(x=>e.jsx("button",{onClick:()=>c(x),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:x==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===x?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===x?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:x==="catalog"?"目錄":"原文"},x))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${f>0?`${f} 首`:`${p} 部書`}`:f>0?`${f} 首`:`${p} 部书`})]}),l==="raw"&&(n?e.jsx(ks,{text:n,highlightQuery:a}):e.jsx(ws,{sections:t.sections,onNavigate:o,highlightQuery:a})),l==="catalog"&&d.map((x,h)=>{const v=ye(x.type);return v==="书"||v==="诗"||v==="考证"?e.jsx(hs,{section:x,onNavigate:o,highlightQuery:a},h):v==="类"?e.jsx(bs,{section:x,highlightQuery:a},h):e.jsx(ys,{section:x,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 Ui(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 Vn(t){const n=Ui(t);return n.length>0?n[0]:null}function Cs(t){const{workId:n,transport:i,files:o,activeFile:s,activeJuan:r,activeRawText:l,query:c,isKaozhen:a}=t,d=We(),p=u.useRef(new Map),[f,g]=u.useState({});u.useEffect(()=>{s&&r&&p.current.set(s,{juan:r,rawText:l})},[s,r,l]),u.useEffect(()=>{p.current.clear(),g({})},[n]);const x=u.useCallback((h,v)=>{let m=0;if(h.juan)for(const j of h.juan.sections)un(j,v,a,d)&&m++;return m===0&&h.rawText&&ps(h.rawText,v,d)&&(m=1),m},[a,d]);return u.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 z of o){const S=p.current.get(z);S?m[z]=x(S,h):(m[z]="loading",j.push(z))}g(m);const y=8;let k=0;const _=async()=>{var z;for(;k<j.length;){if(v)return;const S=k++,I=j[S];try{const[T,C]=await Promise.all([i.getCollatedJuan(n,I),((z=i.getCollatedJuanText)==null?void 0:z.call(i,n,I))??Promise.resolve(null)]),b={juan:T,rawText:C};if(p.current.set(I,b),v)return;g(R=>({...R,[I]:x(b,h)}))}catch{if(v)return;g(T=>({...T,[I]:0}))}}},w=Array.from({length:Math.min(y,j.length)},()=>_());return Promise.all(w),()=>{v=!0}},[c,n,i,o.join(","),x,d]),{matchStates:f}}const fn=({index:t,workId:n,transport:i,onNavigate:o,activeJuan:s,onJuanChange:r,className:l,style:c})=>{const[a,d]=u.useState(null),[p,f]=u.useState(!1),[g,x]=u.useState(null),[h,v]=u.useState(null),[m,j]=u.useState(null),[y,k]=u.useState(!1),[_,w]=u.useState(null),[z,S]=u.useState(""),I=u.useRef(new Map),T=s??h,C=u.useCallback($=>{v($),r==null||r($)},[r]),b=t||a;u.useEffect(()=>{t&&(f(!1),x(null))},[t]),u.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let $=!1;return f(!0),x(null),i.getCollatedEditionIndex(n).then(F=>{if(!$)if(!F)x("未找到整理本数据");else{d(F);const Q=Vn(F);!s&&Q&&C(Q)}}).catch(F=>{$||x(F instanceof Error?F.message:"加载失败")}).finally(()=>{$||f(!1)}),()=>{$=!0}},[t,n,i,s,C]),u.useEffect(()=>{const $=t||a;if($&&!T){const F=Vn($);F&&C(F)}},[t,a,T,C]);const R=n||(b==null?void 0:b.work_id),E=u.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]);u.useEffect(()=>{T&&E(T)},[T,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(g)return e.jsx("div",{className:l,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=Ui(b);return e.jsx(Is,{className:l,style:c,index:b,allFiles:P,isKaozhen:M,effectiveWorkId:R,transport:i,activeFile:T,handleSelectFile:A,juanData:m,juanRawText:_,juanLoading:y,searchQuery:z,setSearchQuery:S,onNavigate:o,workLabelCacheRef:I})},Is=({className:t,style:n,index:i,allFiles:o,isKaozhen:s,effectiveWorkId:r,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:f,searchQuery:g,setSearchQuery:x,onNavigate:h,workLabelCacheRef:v})=>{const{matchStates:m}=Cs({workId:r,transport:l,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=>x(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=os(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(is,{content:ir[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:or[j],cursor:"help"},children:Ci[j]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),e.jsx(gs,{files:o,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:m}),f?e.jsx(Ve,{}):d?s?e.jsx(Ss,{juan:d,searchQuery:g,onNavigate:h,transport:l,workLabelCache:v}):e.jsx(_s,{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))]})]})},zs={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Ts={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Rs(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 gn=({items:t,loading:n})=>{const i=me();return n?e.jsx(Ve,{}):t.length===0?e.jsx("div",{style:Es,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=zs[o.type],r=Ts[o.status];return e.jsxs("div",{style:Bs,children:[e.jsxs("div",{style:Ls,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Gn,background:s.color},children:s.label}),e.jsx("span",{style:{...Gn,background:r.color},children:r.label})]}),e.jsx("span",{style:Ws,children:Rs(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:$s,children:[o.resourceId&&e.jsx("a",{href:i(o.resourceId),style:Un,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:Un,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:As,children:o.content}),o.reply&&e.jsxs("div",{style:Ms,children:[e.jsx("div",{style:Fs,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},Es={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Bs={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Ls={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Gn={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Ws={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},$s={fontSize:"12px",marginBottom:"6px"},Un={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},As={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Ms={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Fs={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Zt=({transport:t,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:r})=>{const l=O(),[c,a]=u.useState(null),[d,p]=u.useState([]),[f,g]=u.useState("recommend"),[x,h]=u.useState([]),[v,m]=u.useState(!1),j=o??f,y=M=>{g(M),s==null||s(M)},[k,_]=u.useState(!0),[w,z]=u.useState(null),[S,I]=u.useState(null),[T,C]=u.useState(null);u.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]),u.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=u.useRef(!1),R=u.useRef(!1),E=u.useRef(!1);u.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||z($)}).catch(()=>{b.current=!1}),()=>{P=!0}},[t,j]),u.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]),u.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]),u.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(rt,{label:l.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),e.jsx(rt,{label:l.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),e.jsx(rt,{label:l.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),e.jsx(rt,{label:l.home.siteTab,active:j==="site",onClick:()=>y("site")}),r&&e.jsx(rt,{label:l.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&e.jsx(Ps,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:l}),j==="catalog"&&e.jsx(Yn,{progress:w,t:l,onNavigate:n}),j==="collection"&&e.jsx(Yn,{progress:S,t:l,onNavigate:n}),j==="site"&&e.jsx(Ds,{progress:T,t:l,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&r&&e.jsx(gn,{items:x,loading:v})]})})},rt=({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}),Ps=({recommended:t,loading:n,onNavigate:i,getIcon:o,t:s})=>{const r=me();if(n)return e.jsx(Ve,{});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:r(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.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))})},Yn=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Ve,{});const o=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],r={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=o.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]}}),r[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Hs,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},Hs=({item:t,t:n,statusColor:i,onNavigate:o})=>{const s=me(),r=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&&o?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(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?yt(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})]})},Ds=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Ve,{});const o=[...t.resources].sort((a,d)=>a.priority-d.priority),s=o.filter(a=>a.imported>0),r=o.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(Kn,{item:a,t:n,totalWorks:i},a.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(a=>e.jsx(Kn,{item:a,t:n,totalWorks:i},a.id))})]})]})},Kn=({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})]})},Jn="(max-width: 768px)";function Os(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(Jn).matches);return u.useEffect(()=>{const i=window.matchMedia(Jn),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),t}const Ns=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var P;const r=O(),{convert:l}=D(),c=Os(),[a,d]=u.useState(null),[p,f]=u.useState(null),[g,x]=u.useState(!1),[h,v]=u.useState("detail"),[m,j]=u.useState([]),[y,k]=u.useState(!1),[_,w]=u.useState(null),[z,S]=u.useState(!1),I=u.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]),T=u.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=u.useCallback(async $=>{if(i){i($);return}d($),f(null),j([]),w(null),v("detail"),x(!0);try{const F=await t.getItem($.id);F&&(f(F),F.type==="collection"?T($.id):F.type==="work"&&F.has_collated&&I($.id))}catch(F){console.error("加载详情失败:",F)}finally{x(!1)}},[t,i,T,I]),b=u.useCallback(async $=>{f(null),j([]),w(null),v("detail"),x(!0);try{const F=await t.getItem($);F&&(f(F),d({id:$,title:F.title||$,type:F.type||"book"}),F.type==="collection"?T($):F.type==="work"&&F.has_collated&&I($))}catch(F){console.error("导航失败:",F)}finally{x(!1)}},[t,T,I]),R=(p==null?void 0:p.type)==="collection"&&(m.length>0||y)||(p==null?void 0:p.type)==="work"&&(_||z),E=c&&(g||p),A=u.useCallback(()=>{d(null),f(null),j([]),w(null),v("detail")},[]),M=e.jsx(e.Fragment,{children:g?e.jsx(Ve,{}):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:_t(h==="detail"),children:r.detailTab.basicInfo}),p.type==="collection"&&y&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:_t(!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:_t(h===`catalog:${$.resource_id}`),children:$.short_name?`${l($.short_name)}${r.detailTab.catalogSuffix}`:r.detailTab.collectionCatalog},$.resource_id)),p.type==="work"&&(_||z)&&e.jsxs("button",{onClick:()=>v("collated"),style:_t(h==="collated"),children:[r.detailTab.collatedEdition,z&&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(cn,{data:p,transport:t,onNavigate:b}):h.startsWith("catalog:")?e.jsx(dn,{data:(P=m.find($=>`catalog:${$.resource_id}`===h))==null?void 0:P.data,onNavigate:b}):h==="collated"?e.jsx(fn,{index:_||void 0,workId:p.id,transport:t,onNavigate:b}):null})]}):e.jsx(Zt,{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(Xt,{transport:t,onEntryClick:C,hideModeIndicator:n}),!p&&e.jsx(Zt,{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(Xt,{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 _t(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 Pe(t){return t.replace(/\.md$/,"")}const Yi=({index:t,bookId:n,transport:i,activeChapter:o,onChapterChange:s})=>{const[r,l]=u.useState(t??null),[c,a]=u.useState(null),d=o!==void 0?o:c,p=u.useCallback(m=>{s?s(m):a(m)},[s]),[f,g]=u.useState(null),[x,h]=u.useState(!1);u.useEffect(()=>{t&&l(t)},[t]),u.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let m=!1;return i.getBookFullTextIndex(n).then(j=>{m||l(j)}),()=>{m=!0}},[n,i,t]),u.useEffect(()=>{if(!r||r.chapters.length===0)return;const m=Pe(r.chapters[0].file);if(!d){p(m);return}const j=Pe(d);r.chapters.some(k=>Pe(k.file)===j)||p(m)},[r,d,p]);const v=u.useMemo(()=>{if(!r||!d)return null;const m=Pe(d);return r.chapters.find(j=>Pe(j.file)===m)??null},[r,d]);return u.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=Pe(m.file),y=j===Pe(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]})]})]}),x&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!x&&f&&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:f.replace(/^##\s+[^\n]+\n+/,"")}),!x&&!f&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},Vs=({data:t,onNavigate:n,className:i,style:o})=>{var p;const s=O(),{convert:r}=D(),[l,c]=u.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[a,d]=u.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(f=>e.jsx(Gs,{division:f,expanded:l===f.name,onToggle:()=>c(l===f.name?null:f.name),expandedCat:a,onCatToggle:g=>d(a===g?null:g),onNavigate:n},f.name))})]})},Gs=({division:t,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:r})=>{const{convert:l}=D(),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(Us,{category:a,expanded:o===d,onToggle:()=>s(d),onNavigate:r},a.name)})})]})},Us=({category:t,expanded:n,onToggle:i,onNavigate:o})=>{var a,d,p,f;const{convert:s}=D(),r=((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)||r.length)+(((f=t.stats)==null?void 0:f.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&&(r.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[r.length>0&&e.jsx(qn,{label:"著錄",books:r,onNavigate:o}),l.length>0&&e.jsx(qn,{label:"存目",books:l,onNavigate:o})]})]})},qn=({label:t,books:n,onNavigate:i})=>{const{convert:o}=D(),s=me(),[r,l]=u.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((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:o(a.title)}):o(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(a.author).slice(0,20)})]},d))}),!r&&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:o,children:s})=>{const r=O();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:Ks,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ys,children:r.action.save})]})]}),s]})},Ys={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ks={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"}})]}),He=({value:t,onChange:n,placeholder:i})=>{const o=u.useRef(null);return u.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"}})},Wt=({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 Js(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ct=({value:t,onChange:n,label:i})=>{const[o,s]=u.useState(!1),r=u.useRef(null),l=Js(t||"");return u.useEffect(()=>{o&&r.current&&r.current.focus()},[o]),!o&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Xn,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(Wt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Xn,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"}})]})},Xn={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function qs(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 Xs(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ki=({items:t,onChange:n,onOpenEntityPicker:i})=>{const o=O(),[s,r]=u.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),r(t.length)},c=f=>{n(t.filter((g,x)=>x!==f)),s===f&&r(null)},a=(f,g,x)=>{const h=[...t];h[f]={...h[f],[g]:x},n(h)},d=(f,g)=>{const x=[...t];x[f]={...x[f],type:g,id:"",name:""},n(x),g==="bookID"&&i&&i(h=>{const v=[...t];v[f]={...v[f],id:h.id,name:h.title,type:"bookID"},n(v)})},p=f=>{i&&i(g=>{const x=[...t];x[f]={...x[f],id:g.id,name:g.title,type:"bookID"},n(x)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,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:f.name||`${o.editor.sourcePlaceholder} ${g+1}`}),f.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:qs(f.type),color:"white",borderRadius:"3px",fontWeight:500},children:Xs(f.type)}),e.jsx("button",{onClick:x=>{x.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:[!f.type&&e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Zn,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:{...Zn,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})]})]})]}),f.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:Be,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const x=[...t];x[g]={...x[g],type:"",id:"",name:""},n(x)},style:Qn,children:o.action.changeType})]}),f.id&&f.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:f.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:f.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})]})]})}),f.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:Be,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const x=[...t];x[g]={...x[g],type:"",id:"",name:""},n(x)},style:Qn,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:f.name,onChange:x=>a(g,"name",x.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:f.id,onChange:x=>a(g,"id",x.target.value),placeholder:"https://...",style:Ye})]})]}),f.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:{...Be,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:Be,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:f.details,onChange:x=>a(g,"details",x.target.value),placeholder:o.editor.detailsPlaceholder,style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:f.position,onChange:x=>a(g,"position",x.target.value),placeholder:"如: 卷三, p.52",style:Ye})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:f.version,onChange:x=>a(g,"version",x.target.value),placeholder:"如: v1.0, 2024-01",style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:f.processor_version,onChange:x=>a(g,"processor_version",x.target.value),placeholder:"如: v0.1",style:Ye})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},Be={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},Ye={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"},Zn={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"},Qn={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Ji(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 qi(t){return!t||t.length===0?"":JSON.stringify(t)}const Xi=({entityType:t,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:r,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:f,onUnlinkEntity:g,onViewEntity:x,onCreateAndLink:h,onSaveRelations:v})=>{const m=O();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:Zs,children:m.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(st,{direction:"up",title:m.relation.belongsToWork,entity:r,onView:x,onUnlink:()=>g("workId"),onLink:()=>f("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(st,{direction:"up",title:m.relation.containedInCollection,entity:l,onView:x,onUnlink:()=>g("collectionId"),onLink:()=>f("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(Ke,{direction:"horizontal",title:`${m.relation.siblingVersions} (${p.length})`,entities:p,onView:x,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(st,{direction:"up",title:m.relation.parentWork,entity:o,onView:x,onUnlink:()=>g("parentWorkId"),onLink:()=>f("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(Ke,{direction:"down",title:`${m.relation.childWorks} (${c.length})`,entities:c,onView:x,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),a&&a.length>0&&e.jsx(Ke,{direction:"down",title:`${m.relation.collectionImpl} (${a.length})`,entities:a,onView:x,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ke,{direction:"down",title:`${m.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,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(st,{direction:"up",title:m.relation.correspondingWork,entity:r,onView:x,onUnlink:()=>g("workId"),onLink:()=>f("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(st,{direction:"up",title:m.relation.parentCollection,entity:s,onView:x,onUnlink:()=>g("parentCollectionId"),onLink:()=>f("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(Ke,{direction:"down",title:`${m.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:x,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ke,{direction:"down",title:`${m.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},st=({direction:t,title:n,entity:i,onView:o,onUnlink:s,onLink:r,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:p,unlinkLabel:f})=>{const g=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=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:x}),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:Zi(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(ei,{onClick:()=>o(i),title:p,children:"👁️"}),e.jsx(ei,{onClick:s,title:f,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(Qt,{onClick:r,children:c}),e.jsx(Qt,{onClick:l,primary:!0,children:a})]})]})},Ke=({direction:t,title:n,entities:i,onView:o,onAdd:s,addLabel:r,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=u.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=a?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(x=>e.jsxs("div",{onClick:()=>o(x),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:Zi(x.type)}),e.jsx("span",{children:x.title})]},x.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(Qt,{onClick:s,primary:!0,children:["+ ",r]})})]})},ei=({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}),Qt=({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 Zi(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Zs={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"},Qi=({isOpen:t,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:r,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,f]=u.useState(""),g=d?l.filter(m=>m.id!==d):l;u.useEffect(()=>{t&&(f(""),c(""))},[t]);const x=m=>{f(m),c(m)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Qs,children:e.jsxs("div",{style:el,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:tl,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:m=>x(m.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:nl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:Ut,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:il,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:Ut,children:["未找到匹配的",h]}):e.jsxs("div",{style:Ut,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:ol,children:["创建新",h,"并关联"]})]})]})})},Qs={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},el={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)"},tl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},nl={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"},il={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ut={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},ol={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ti={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},rl={work:"📜",book:"📖",collection:"📚",entity:"👤"},eo=({isOpen:t,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:r})=>{const[l,c]=u.useState(""),a=u.useRef(null);u.useEffect(()=>{t&&(c((o==null?void 0:o.title)||""),setTimeout(()=>{var g,x;(g=a.current)==null||g.focus(),(x=a.current)==null||x.select()},100))},[t,o==null?void 0:o.title]);const d=g=>{g.key==="Enter"&&l.trim()?p():g.key==="Escape"&&r()},p=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!t)return null;const f=()=>{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`创建新${ti[n]}`}};return e.jsx("div",{style:sl,onClick:g=>{g.target===g.currentTarget&&r()},children:e.jsxs("div",{style:ll,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:rl[n]}),e.jsx("span",{children:f()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${ti[n]}名称...`,style:al})]}),((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:cl,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...dl,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},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},ll={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)"},al={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"},cl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},dl={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function pl(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function to(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ul(t){switch(t){case"work":return"var(--bim-editor-type-work, #4caf50)";case"collection":return"var(--bim-editor-type-collection, #2196f3)";case"book":return"var(--bim-editor-type-book, #ff9800)";default:return"var(--bim-desc-fg, #717171)"}}const no=({isOpen:t,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:r=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:p})=>{const[f,g]=u.useState(""),[x,h]=u.useState([]),[v,m]=u.useState(!1),[j,y]=u.useState("recent");u.useEffect(()=>{t&&(g(""),h([]),y(o.length>0?"recent":"search"))},[t,o.length]),u.useEffect(()=>{if(!f.trim()){h([]);return}const I=setTimeout(async()=>{m(!0);try{h(await p(f,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(I)},[f,i,p]);const k=u.useCallback(I=>{g(I.target.value),I.target.value.trim()&&y("search")},[]),_=u.useCallback(I=>s?I.filter(T=>T.id!==s):I,[s]);if(!t)return null;const w=n||(i==="all"?"选择实体":`选择${to(i)}`),z=_(o),S=_(x);return e.jsx("div",{style:fl,children:e.jsxs("div",{style:gl,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:ml,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:f,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:hl}),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:"搜索中..."})]})}),z.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(ni,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",z.length,")"]}),e.jsxs(ni,{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"&&z.length>0?e.jsx(ii,{entities:z,onSelect:c}):f.trim()?v?e.jsx(Yt,{message:"搜索中..."}):S.length>0?e.jsx(ii,{entities:S,onSelect:c}):e.jsx(Yt,{message:"未找到匹配的结果"}):e.jsx(Yt,{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:bl,children:l||"创建新实体"})]})]})})},ni=({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}),ii=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(xl,{entity:i,onClick:()=>n(i)},i.id))}),xl=({entity:t,onClick:n})=>{const[i,o]=u.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:pl(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:ul(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:to(t.type)})]})},Yt=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),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",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ml={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},hl={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"},bl={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},yl={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)"},vl={work:"📜",collection:"📚",book:"📖",entity:"👤"},io=({data:t,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:r,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:f,onRelationsChange:g})=>{var te;const x=O(),[h,v]=u.useState(!1),[m,j]=u.useState("work"),[y,k]=u.useState(""),[_,w]=u.useState(""),[z,S]=u.useState([]),[I,T]=u.useState(!1),[C,b]=u.useState(!1),[R,E]=u.useState("work"),[A,M]=u.useState(""),[P,$]=u.useState(),[F,Q]=u.useState(!1),[W,U]=u.useState(null),[ne,B]=u.useState([]);u.useRef(null);const V=t.type,Y=V==="work",ie=V==="collection",G=V==="book",K=u.useCallback((L,Z)=>{n({...t,[L]:Z})},[t,n]),de=u.useCallback((L,Z)=>{k(L),j(Z),w(x.editor.selectToLink+x.indexType[Z]),S([]),v(!0)},[x]),he=u.useCallback(L=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,L)},[o,t.id]),pe=u.useCallback(L=>{s==null||s(L.id,L.type)},[s]),le=u.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]),ve=u.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]),Fe=u.useCallback(L=>{if(!L.trim()){S([]);return}T(!0),o!=null&&o.searchEntities&&o.searchEntities(L,m).then(Z=>{S(Z),T(!1)}).catch(()=>{S([]),T(!1)})},[o,m]),_e=u.useCallback(L=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,y,L.id),v(!1)},[o,t.id,y]),Ge=u.useCallback(()=>{i()},[i]),tt=u.useCallback(L=>{U(()=>L),Q(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(B).catch(()=>{})},[o]),N=u.useCallback((L,Z)=>o!=null&&o.searchEntities?o.searchEntities(L,Z==="all"?void 0:Z):Promise.resolve([]),[o]),oe=u.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:vl[V]}),e.jsx("span",{children:t.title||x.editor.untitled}),e.jsx(Wt,{children:t.id}),e.jsx(Wt,{color:yl[V],children:x.indexType[V]})]})}),e.jsx(Se,{title:x.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(Ct,{label:Y?x.editor.workTitle:ie?x.editor.collectionTitle:x.editor.bookTitle,value:t.title,onChange:L=>K("title",L)}),G&&e.jsx(Ct,{label:x.editor.belongsToWork,value:t.workName||"",onChange:L=>K("workName",L)}),e.jsx(ge,{label:x.editor.authorLabel,value:t.author||"",onChange:L=>K("author",L)}),e.jsx(ge,{label:x.editor.dynastyLabel,value:t.dynasty||"",onChange:L=>K("dynasty",L)}),(G||ie)&&e.jsx(Ct,{label:x.editor.containedIn,value:t.collection||"",onChange:L=>K("collection",L)}),(G||ie)&&e.jsx(ge,{label:x.editor.holderLabel,value:t.holder||"",onChange:L=>K("holder",L)}),(G||ie)&&e.jsx(ge,{label:G?x.editor.pageLabel:x.editor.volumeLabel,value:t.pages||"",onChange:L=>K("pages",L)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ge,{label:x.editor.firstImageLabel,value:t.firstImage||"",onChange:L=>K("firstImage",L)})})]})}),e.jsx(Se,{title:x.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(He,{value:t.description||"",onChange:L=>K("description",L),placeholder:x.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(Se,{title:x.section.additionalWorks,onSave:i,children:e.jsx(jl,{items:t.additional_works||[],onChange:L=>K("additional_works",L)})}),e.jsx(Se,{title:x.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Sl,{items:t.indexed_by||[],onChange:L=>K("indexed_by",L)})}),e.jsx(Se,{title:x.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(kl,{items:t.emendated_by||[],onChange:L=>K("emendated_by",L)})}),e.jsx(Se,{title:x.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(qt,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(Se,{title:x.section.imageResources,onSave:i,children:e.jsx(qt,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(Se,{title:x.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Ki,{items:Ji(t.sources||""),onChange:L=>K("sources",qi(L)),onOpenEntityPicker:tt})}),(G||ie)&&e.jsx(Se,{title:x.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(He,{value:t.provenance||"",onChange:L=>K("provenance",L),placeholder:x.editor.provenancePlaceholder})}),G&&e.jsx(Se,{title:x.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(He,{value:t.otherEditions||"",onChange:L=>K("otherEditions",L),placeholder:x.editor.otherEditionsPlaceholder})}),e.jsx(Xi,{entityType:V,entityId:t.id,entityTitle:t.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:de,onUnlinkEntity:he,onViewEntity:pe,onCreateAndLink:le,onSaveRelations:Ge}),r&&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:x.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:x.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:x.editor.deleteEntity})]}),e.jsx(Qi,{isOpen:h,entityType:m,title:_,onSelect:_e,onCancel:()=>v(!1),onCreate:()=>{v(!1),le(y,m)},searchResults:z,onSearch:Fe,isLoading:I,excludeId:t.id}),e.jsx(eo,{isOpen:C,entityType:R,relationField:A,inheritData:P,onConfirm:ve,onCancel:()=>b(!1)}),e.jsx(no,{isOpen:F,title:x.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:oe,onCancel:()=>{Q(!1),U(null)},onSearch:N})]})};function jl({items:t,onChange:n}){const i=O(),o=(l,c,a)=>{const d=t.map((p,f)=>f===l?{...p,[c]:a}:p);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),r=()=>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(ge,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>o(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ge,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>o(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: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 oo({items:t,onChange:n,showMeta:i,addLabel:o}){const s=O(),[r,l]=u.useState(null),c=(p,f,g)=>{const x=t.map((h,v)=>v===p?{...h,[f]:g||void 0}:h);n(x)},a=p=>{n(t.filter((f,g)=>g!==p)),r===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,f)=>{const g=r===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:f),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:x=>{x.stopPropagation(),a(f)},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:x=>c(f,"source",x)}),e.jsx(ge,{label:s.label.sourceBid,value:p.source_bid||"",onChange:x=>c(f,"source_bid",x)})]}),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:x=>c(f,"title_info",x)}),e.jsx(ge,{label:s.label.authorInfo,value:p.author_info||"",onChange:x=>c(f,"author_info",x)})]}),e.jsx(ge,{label:s.label.edition,value:p.edition||"",onChange:x=>c(f,"edition",x)})]}),e.jsx(He,{value:p.summary||"",onChange:x=>c(f,"summary",x),placeholder:s.editor.summaryPlaceholder}),e.jsx(He,{value:p.comment||"",onChange:x=>c(f,"comment",x),placeholder:s.editor.commentPlaceholder}),e.jsx(He,{value:p.additional_comment||"",onChange:x=>c(f,"additional_comment",x),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),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 Sl({items:t,onChange:n}){const i=O();return e.jsx(oo,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function kl({items:t,onChange:n}){const i=O();return e.jsx(oo,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function ro(t){var c,a,d,p,f,g,x;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)||"",o=((p=t.current_location)==null?void 0:p.name)||"",s=(f=t.page_count)!=null&&f.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||"",l={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&&(l.parentWorkId=v.id,l.parentWorkName=v.title)}}if(t.type==="book"){const h=t;l.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(l.collectionId=(x=h.contained_in[0])==null?void 0:x.id)}return l}function wl(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 _l=t=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:r,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:f,renderSectionActions:g,onDownloadResource:x,downloadStatuses:h,relations:v,onRelationsChange:m,headerExtra:j,className:y,style:k}=t;O();const[_,w]=u.useState(s),z=r?s:_;u.useEffect(()=>{s!==_&&w(s)},[s]);const S=u.useCallback(()=>{const A=z==="view"?"edit":"view";r?r(A):w(A)},[z,r]),[I,T]=u.useState(null);u.useEffect(()=>{i&&o&&o.getItem(i).then(A=>{A&&T(A)})},[i,o]);const C=n||I,b=u.useMemo(()=>C?ro(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:z==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:z==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:z==="view"?"切换到编辑模式":"切换到查看模式",children:z==="view"?"✏️ 编辑":"👁 查看"}):null,E=e.jsxs(e.Fragment,{children:[R,j]});return!C&&!b?e.jsx(Ve,{}):z==="view"?e.jsx(cn,{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(io,{data:b,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:o,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:g,onDownloadResource:x,downloadStatuses:h,relations:v,onRelationsChange:m})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},oi=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],so=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const[s,r]=u.useState(null),[l,c]=u.useState(""),[a,d]=u.useState("idle"),[p,f]=u.useState(""),g=u.useRef(null);u.useEffect(()=>{t&&(r(null),c(""),d("idle"),f(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=g.current)==null?void 0:m.focus()},100)},[s]),u.useEffect(()=>{if(a==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[a,n]),u.useEffect(()=>{if(!t)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const x=async()=>{if(!(!s||!l.trim())){d("submitting"),f("");try{await i({type:s,content:l.trim()}),d("success")}catch(m){d("error"),f(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&l.trim()&&a!=="submitting",v=oi.find(m=>m.value===s);return e.jsx("div",{style:Cl,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:Il,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:zl,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Tl,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:Wl,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:oi.map(m=>e.jsxs("button",{onClick:()=>r(m.value),style:{...Rl,...s===m.value?El:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:g,value:l,onChange:m=>c(m.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...Bl,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:$l,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:x,disabled:!h,style:{...Ll,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},Cl={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},Il={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)"},zl={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Tl={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Rl={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"},El={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Bl={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"},Ll={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Wl={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},$l={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Al=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[o,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...Ml,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(so,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},Ml={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"},ri=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],lo=({onSubmit:t})=>{const[n,i]=u.useState("bug"),[o,s]=u.useState(""),[r,l]=u.useState("idle"),[c,a]=u.useState(""),d=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var x;return(x=d.current)==null?void 0:x.focus()},100)},[n]);const p=async()=>{if(!(!n||!o.trim())){l("submitting"),a("");try{await t({type:n,content:o.trim()}),l("success"),s(""),i("bug")}catch(x){l("error"),a(x instanceof Error?x.message:"提交失败,请稍后重试")}}},f=n&&o.trim()&&r!=="submitting",g=ri.find(x=>x.value===n);return r==="success"?e.jsx("div",{style:si,children:e.jsxs("div",{style:Ol,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Nl,children:"继续提交"})]})}):e.jsxs("div",{style:si,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:ri.map(x=>e.jsxs("button",{onClick:()=>i(x.value),style:{...Fl,...n===x.value?Pl:{}},children:[e.jsx("span",{children:x.icon})," ",x.label]},x.value))}),e.jsx("textarea",{ref:d,value:o,onChange:x=>s(x.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:r==="submitting",style:{...Hl}}),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:!f,style:{...Dl,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:r==="submitting"?"提交中...":"提交"})]}),r==="error"&&e.jsx("div",{style:Vl,children:c})]})},si={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Fl={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"},Pl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Hl={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"},Dl={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ol={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Nl={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Vl={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function li(t){return typeof t=="function"?t():t??"/api/feedback"}const ao=({resourceId:t,apiUrl:n})=>{const[i,o]=u.useState([]),[s,r]=u.useState(!0),l=u.useCallback(async()=>{const a=li(n);r(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&o(p.items)}catch{}finally{r(!1)}},[t,n]);u.useEffect(()=>{l()},[l]);const c=async a=>{const d=li(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 f=await p.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(gn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(lo,{onSubmit:c})})]})},Gl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ul={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function at(t){return Ul[t]??t}const ai=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],co={建安:196,黃初:220,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,會昌: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,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,元祿:1688,享保:1716,延享:1744,寬政:1789,文政:1818,天保:1830,明治:1868,大正:1912,昭和:1926},Yl={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function po(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 l=Yl[r];if(l===void 0)return;o=!0,r==="十"?i=(i||1)*10:r==="廿"||r==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return o&&s>0?s:void 0}function It(t){for(const n of Gl)if(t.startsWith(n))return n}const zt={};{const t=(n,i)=>{for(const o of i)zt[o]=n};t("東漢",["建安"]),t("三國",["黃初"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","元祿","享保","延享","寬政","文政","天保","明治","大正","昭和"])}function ct(t,n){for(const i of Object.keys(co))if(t.includes(i)){if(n&&zt[i]&&zt[i]!==n){const o=n==="北宋"||n==="南宋"?"宋":n;if(zt[i]!==o)continue}return i}}function mn(t){var r,l,c;const n={era:"",reign:"",source:"none"},i=(r=t.lineage)==null?void 0:r.year_text;if(i){const a=It(i)??"";return{era:at(a),reign:ct(i,a)??"",source:"lineage"}}const o=(l=t.publication_info)==null?void 0:l.year;if(o){const a=It(o)??((c=ai.find(f=>f.pattern.test(o)))==null?void 0:c.era)??"",d=ct(o,a)??"";if(a||d)return{era:at(a),reign:d,source:"publication"};const p=o.match(/\d{3,4}/);if(p)return{era:"",reign:p[0],source:"publication"}}const s=t.edition||t.title||"";if(s){const a=It(s);if(a)return{era:at(a),reign:ct(s,a)??"",source:"edition"};const d=ai.find(p=>p.pattern.test(s));if(d)return{era:at(d.era),reign:ct(s,d.era)??d.reign??"",source:"edition"}}return n}function uo(t){var i,o,s;if(typeof((i=t.lineage)==null?void 0:i.year)=="number")return t.lineage.year;const n=[(o=t.lineage)==null?void 0:o.year_text,(s=t.publication_info)==null?void 0:s.year,t.edition,t.title].filter(Boolean);for(const r of n){const l=r.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??r.match(/[((](\d{3,4})\s*年?[))]/);if(l){const d=parseInt(l[1],10);if(d>=100&&d<=2100)return d}const c=It(r),a=ct(r,c);if(a){const d=co[a],f=r.slice(r.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=f?po(f[1]):void 0;return d+(g?g-1:0)}}}const ci=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function dt(t){const n=ci.indexOf(t);return n===-1?ci.length:n}function xo(t){const n={belongsTo:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const r=s.relation;r==="part_of"||r==="collected_in"?n.belongsTo.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("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),i}function At(t,n){const i=on(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,f)=>{const g=x=>x.group_role==="origin"?0:x.group_role==="mirror"?1:2;return g(p)-g(f)});const r={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=De(d),f=p.includes("text"),g=p.includes("image");f&&g?r.textImage.push(d):f?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]})),a=[...o.entries()].map(([d,p])=>{var f,g;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(g=n==null?void 0:n[d])==null?void 0:g.description,items:p}});return{buckets:c,mirrors:a,total:i.length}}function hn(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=rn(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 Kl(t,n){if(hn(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 fo(t,n){var r,l;const i=t.resources||[],o=[],s=[];for(const c of i){const a=De(c);a.includes("image")&&o.push(c),a.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:mn(t),year:uo(t),images:o,holders:s,locationName:(r=t.current_location)==null?void 0:r.name,important:Jl(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:o.length>0}}function Jl(t,n){var c,a;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)??[],l=(a=n.node_groups)==null?void 0:a[t];return!!l&&r.includes(l)}function go(t,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!o.has(a.id)).map(a=>fo(a,n));let r=s;i.era&&(r=r.filter(a=>a.era.era===i.era)),i.scanOnly&&(r=r.filter(a=>a.hasImage)),i.sort==="year"?r=[...r].sort((a,d)=>a.year!=null&&d.year!=null?a.year-d.year:a.year!=null?-1:d.year!=null?1:dt(a.era.era)-dt(d.era.era)):r=r.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=f=>(f.important?0:1)*2+(f.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)=>dt(a)-dt(d));return{rows:r,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function ql(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,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],f=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?(f.has(k)||f.set(k,[]),f.get(k).push(y)):g.push(y)}if(g.length+[...f.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=[...f.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 mo=["撰","編","注","校","譯","繪","其他"],Xl=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function bn(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:o}of Xl)if(o.test(n))return i;return"其他"}function ho(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function bo(t){const n=new Map;for(const o of t){const s=bn(o);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const o of mo){const s=n.get(o);s&&i.push({cls:o,label:o,count:s})}return i.length>2?i:[]}function yo(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})),r=[...new Set(s.map(l=>l.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:ft(r.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var r,l;return{id:s,title:((r=i==null?void 0:i.get(s))==null?void 0:r.title)||s,edition:(l=i==null?void 0:i.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function ft(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 yn(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((r,l)=>r-l),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 Zl=["〇","一","二","三","四","五","六","七","八","九"],di=["","十","百","千"];function vo(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 l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=di[c]:o+=Zl[l]+di[c])}return o}function Oe(t,n="卷"){var o,s;const i=t;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?vo(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function jo(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 So=1e3,Ql="(max-width: 719px)",ko=`
|
|
4
4
|
.bim-d-page {
|
|
5
5
|
background: var(--bim-page-bg, #fbf9f3);
|
|
6
6
|
color: var(--bim-ink, #2a231c);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
padding-bottom: 64px;
|
|
10
10
|
}
|
|
11
11
|
.bim-d-main {
|
|
12
|
-
max-width: ${
|
|
12
|
+
max-width: ${So}px;
|
|
13
13
|
margin: 0 auto;
|
|
14
14
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
15
15
|
}
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
align-items: start; margin-bottom: 48px; }
|
|
38
38
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
39
39
|
|
|
40
|
-
@media ${
|
|
40
|
+
@media ${Ql} {
|
|
41
41
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
42
42
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
43
43
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
gap: 4px 14px; font-size: 12px; }
|
|
49
49
|
.bim-d-h1 { font-size: 32px !important; }
|
|
50
50
|
}
|
|
51
|
-
`;function Tt({children:t,style:n}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:So}),e.jsx("div",{className:"bim-d-main",children:t})]})}function ko({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 vn({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 wo({items:t}){return e.jsx(e.Fragment,{children:t.map((n,i)=>{const o=i===t.length-1,s=i>0&&e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${i}`),r=o||!n.onClick&&!n.href?e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:n.label},i):e.jsx("a",{href:n.href??"#",onClick:n.onClick?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:n.label},i);return e.jsxs(u.Fragment,{children:[s,r]},i)})})}function _o({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 bt({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 yt({items:t,horizontal:n}){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((i,o)=>e.jsxs("div",{title:i.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.label}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:i.value})]},o))}):null}function ue({glyph:t,tone:n,title:i,count:o,actions:s,id:r}){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(vn,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children: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 Le({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function We({label:t,active:n,onClick:i,dashed:o}){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:t})}function At({label:t,onClick:n}){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:t})}function $e({label:t,onClick:n,inline:i}){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:t})}function vt({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 Mt({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function Co({volumes:t,unit:n="冊",max:i=60}){const[o,s]=u.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(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)),!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 jt({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function Ft({spec:t}){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:t.mainLabel}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(n=>n.width).join(" "),gap:12},children:t.columns.map(n=>e.jsx("span",{children:n.label},n.label))})]})}function Pt({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 Ht(t){return String(t+1).padStart(2,"0")}function qe(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function Io({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 zt({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 en({title:t,tag:n,children:i}){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:t}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:n})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function To({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 Xe({item:t,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{convert:s}=O(),[r,l]=u.useState(!1),c=rn(t),a=i&&!!c&&c.expected>0,d=(t.url?xt(t.url):void 0)||s(t.name),p=n?Yl(t,n):"",f=p?`${d}(${p})`:d;return e.jsx(To,{name:f,note:hn(t)||o,href:Et(t),extra:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>l(g=>!g),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:r?"收起分冊":`展開 ${c.expected} 冊`}),r&&e.jsx(zo,{item:t})]}):void 0})}function zo({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 jn({label:t,items:n}){const{convert:i}=O();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(vt,{children:i(o)},s))]}):null}function Ro({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(jn,{label:i.label,items:i.items},i.label))}):null}function gt(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Eo({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 Dt({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 je({id:t,label:n,onNavigate:i,renderLink:o,style:s,dense:r}){const l=me();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:r})}):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 tn({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 Ke={versions:12,catalogs:8,chips:12},Bo={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Lo=({data:t,transport:n,onNavigate:i,renderLink:o,lineageAction:s})=>{var C,b,R,E,A,M,P,$,F;const r=N(),{convert:l}=O(),c=u.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[a,d]=u.useState(new Map),[p,f]=u.useState(!1),[g,x]=u.useState(""),[h,v]=u.useState(!1),[m,j]=u.useState("default"),y=p||!!g||h||m==="year",k=u.useMemo(()=>y?c:c.slice(0,Ke.versions),[c,y]);u.useEffect(()=>{if(!n||k.length===0)return;const W=k.filter(D=>!a.has(D));if(W.length===0)return;let B=!1;return Promise.all(W.map(D=>n.getItem(D).then(te=>{const G=te??{};return[D,{id:D,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[D,{id:D}]))).then(D=>{B||d(te=>{const G=new Map(te);for(const[Z,re]of D)G.set(Z,re);return G})}),()=>{B=!0}},[n,k,a]);const _=u.useMemo(()=>c.map(W=>a.get(W)??{id:W}),[c,a]),w=u.useMemo(()=>go(_,t.version_graph,{era:g,scanOnly:h,sort:m}),[_,t.version_graph,g,h,m]),I=p?w.rows:w.rows.slice(0,Ke.versions),S=u.useMemo(()=>$t(t.resources,t.resource_groups),[t.resources,t.resource_groups]),T=u.useMemo(()=>xo((t.related_works||[]).map(W=>({id:W.id,title:W.title,relation:W.relation}))),[t.related_works]),z=u.useMemo(()=>{var te,G,Z,re;const W=[],B=(G=(te=t.authors)==null?void 0:te[0])==null?void 0:G.dynasty;B&&W.push({label:"成書",value:l(B)});const D=He(t,r.unit.juan);if(D){const ne=(Z=t.juan_count)==null?void 0:Z.description;W.push({label:"卷帙",value:l(D),title:ne?l(ne):void 0})}if(y||c.length<=Ke.versions){const ne=w.allRows.map(U=>U.year).filter(U=>U!=null);if(ne.length>0){const U=Math.min(...ne),Y=w.allRows.find(ce=>ce.year===U);Y!=null&&Y.era.era&&W.push({label:"最早存世刻本",value:`${Y.era.era}${Y.era.reign?" "+Y.era.reign:""}`,title:Y.era.source==="edition"?"據版本題名推斷":void 0})}}return(re=t.indexed_by)!=null&&re.length&&W.push({label:"著錄",value:`${t.indexed_by.length} ${r.unit.bu}`}),W},[t,l,r,w.allRows,y,c.length]);return e.jsxs(e.Fragment,{children:[e.jsxs(bt,{facts:z.length?e.jsx(yt,{items:z}):void 0,children:[((C=t.description)==null?void 0:C.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(b=t.description.sources)!=null&&b.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(W=>l(W)).join(" · ")}):null]}),(R=t.appendix)==null?void 0:R.map((W,B)=>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(W.title)}),e.jsx(Re,{text:W.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},B)),e.jsx(Ro,{rows:[{label:r.section.aliases,items:gt(t.additional_titles)},{label:r.section.attachedTexts,items:gt(t.attached_texts)},{label:r.section.appendix,items:(t.additional_works||[]).map(W=>W.book_title+(W.n_juan!=null?` ${W.n_juan}${r.unit.juan}`:""))}]})]}),c.length>0&&e.jsxs(Le,{children:[e.jsx(ue,{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(We,{label:"僅看有影印",active:h,dashed:!0,onClick:()=>{v(W=>!W),f(!1)}}),e.jsx(At,{label:m==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>j(W=>W==="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(We,{label:r.catalog.all,active:!g,onClick:()=>{x(""),f(!1)}}),w.eras.map(W=>e.jsx(We,{label:W,active:g===W,onClick:()=>{x(W),f(!1)}},W))]}),e.jsxs(jt,{children:[e.jsx(Ft,{spec:Bo}),I.map((W,B)=>e.jsx(ta,{row:W,no:B,onNavigate:i,renderLink:o},W.id)),I.length===0&&e.jsx(Dt,{children:g||h?"當前篩選下沒有版本":"暫無版本著錄"})]}),w.rows.length>I.length&&e.jsx($e,{label:`展開其餘 ${w.rows.length-I.length} 種版本`,onClick:()=>f(!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(Le,{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(W=>e.jsx(en,{title:l(W.label),tag:W.description?l(W.description):void 0,children:W.items.map((B,D)=>e.jsx(Xe,{item:B,siblings:W.items},`${B.id||B.url||B.name}-${D}`))},W.key)),S.buckets.map(W=>e.jsx(en,{title:Ql[W.key],tag:ea[W.key],children:W.items.map((B,D)=>e.jsx(Xe,{item:B,siblings:W.items},`${B.id||B.url||B.name}-${D}`))},W.key))]})]}),(E=t.indexed_by)!=null&&E.length||(A=t.emendated_by)!=null&&A.length?e.jsxs("div",{className:(M=t.emendated_by)!=null&&M.length?"bim-d-pair":void 0,style:(P=t.emendated_by)!=null&&P.length?void 0:{marginBottom:48},children:[($=t.indexed_by)!=null&&$.length?e.jsx(ui,{id:"catalogs",glyph:"目",title:r.section.indexed,items:t.indexed_by,unit:r.unit.bu,cap:Ke.catalogs,showMeta:!0,t:r,convert:l,onNavigate:i,renderLink:o}):null,(F=t.emendated_by)!=null&&F.length?e.jsx(ui,{id:"studies",glyph:"考",title:r.section.emendated,items:t.emendated_by,unit:r.unit.bu,cap:Ke.catalogs,t:r,convert:l,onNavigate:i,renderLink:o}):null]}):null,T.map(W=>e.jsx(na,{glyph:W.key==="derivative"?"續":"叢",title:r.section[W.labelKey]??r.section.relatedWorks,items:W.items,convert:l,onNavigate:i,renderLink:o},W.key))]})},Ql={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},ea={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function ta({row:t,no:n,onNavigate:i,renderLink:o}){const{convert:s}=O(),r=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(Pt,{no:Ht(n),spec:Bo,main:e.jsx(je,{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:l?"據版本題名推斷":void 0,children:r||e.jsx(qe,{})}),e.jsx(pi,{items:t.images,convert:s}),e.jsx(pi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function pi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(qe,{});if(t.length===1){const l=t[0],c=(l.url?xt(l.url):void 0)||n(l.name),a=Et(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(tn,{href:a,children:c}):c})}const o=t[0],s=(o.url?xt(o.url):void 0)||n(o.name),r=Et(o);return e.jsxs("span",{style:{minWidth:0},children:[r?e.jsx(tn,{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 ui({id:t,glyph:n,title:i,items:o,unit:s,cap:r,showMeta:l,t:c,convert:a,onNavigate:d,renderLink:p}){const[f,g]=u.useState({}),[x,h]=u.useState(!1),v=o.length>0&&o.every((y,k)=>f[k]),m=u.useCallback(()=>{g(v?{}:Object.fromEntries(o.map((y,k)=>[k,!0])))},[v,o]),j=x?o:o.slice(0,r);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(ue,{glyph:n,tone:"ink",title:i,count:`${o.length} ${s}`,actions:e.jsx(At,{label:v?"收起全部":"+ 展開提要",onClick:m})}),e.jsx(jt,{children:j.map((y,k)=>{const _=y;return e.jsxs(Io,{open:!!f[k],onToggle:()=>g(w=>({...w,[k]:!w[k]})),main:e.jsxs(e.Fragment,{children:[_.source_bid?e.jsx(je,{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(je,{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(zt,{children:a(_.summary)}),_.comment&&e.jsx(zt,{label:c.section.comment,children:a(_.comment)}),_.additional_comment&&e.jsx(zt,{label:c.section.additionalComment,children:a(_.additional_comment)}),l&&_.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($e,{label:`展開其餘 ${o.length-j.length} ${s}`,onClick:()=>h(!0)})]})}function na({glyph:t,title:n,items:i,convert:o,onNavigate:s,renderLink:r}){const[l,c]=u.useState(!1),a=l?i:i.slice(0,Ke.chips);return e.jsxs(Le,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Mt,{children:[a.map(d=>e.jsx(vt,{children:e.jsx(je,{id:d.id,label:o(d.title),onNavigate:s,renderLink:r,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx($e,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const ia=8,Wo=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var k,_,w,I;const s=N(),{convert:r}=O(),[l,c]=u.useState(null),[a,d]=u.useState(new Map),[p,f]=u.useState([]),[g,x]=u.useState(!1);u.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]),u.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(b=>[C,b]).catch(()=>[C,null])})).then(z=>{if(T)return;const C=new Map;for(const[b,R]of z)R&&C.set(b,R);d(C)}),()=>{T=!0}},[n,t.contained_in]);const h=u.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]);u.useEffect(()=>{if(!n||h.length===0){f([]);return}const S=g?h:h.slice(0,ia);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||f(z)}),()=>{T=!0}},[n,h,g]);const v=u.useMemo(()=>$t(t.resources,t.resource_groups),[t.resources,t.resource_groups]),m=u.useMemo(()=>{var E,A,M;const S=[],T=mn(t),z=vo(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"?[]:ut(P.volume_index));C.length&&(S.push({label:"冊數",value:`${C.length} ${s.unit.volume}`}),S.push({label:"冊次",value:`第 ${yn(C,s.unit.volume)} ${s.unit.volume}`}));const b=He(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"&&ut(S.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(bt,{facts:m.length?e.jsx(yt,{items:m,horizontal:!j}):void 0,children:j?e.jsx(Re,{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(Le,{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"?[]:ut(S.volume_index),b=a.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(je,{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(Co,{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(je,{id:l.id,label:r(l.title),onNavigate:i,renderLink:o})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[r(He(l,s.unit.juan)),(_=l.authors)==null?void 0:_.map(S=>`${S.dynasty?`〔${r(S.dynasty)}〕`:""}${r(S.name)}${S.role?" "+r(S.role):""}`).join(" · ")].filter(Boolean).join(" · ")})]}),((w=l.description)==null?void 0:w.text)&&e.jsx(Re,{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(jn,{label:s.section.aliases,items:[...gt(t.additional_titles),...gt(t.attached_texts)]})})]})]}),(v.buckets.length>0||v.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:[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((T,z)=>e.jsx(Xe,{item:T,showVolumes:!y},`${T.id||T.url||T.name}-${z}`))]},S.key)),v.buckets.flatMap(S=>S.items).map((S,T)=>e.jsx(Xe,{item:S,showVolumes:!y},`${S.id||S.url||S.name}-${T}`))]})]})]}),(I=t.location_history)!=null&&I.length?e.jsxs(Le,{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: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)})]},T))})]}):null,h.length>0&&e.jsxs(Le,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"版",tone:"ink",title:s.relation.siblingVersions,count:`${h.length} 種`,actions:l?e.jsx(je,{id:l.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:o,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Mt,{children:[p.map(S=>e.jsx(vt,{children:e.jsx(je,{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($e,{inline:!0,label:`更多 ${h.length-p.length} 種`,onClick:()=>x(!0)})]})]})]})},xi={titles:16,works:16},$o=({data:t,catalog:n,onNavigate:i,renderLink:o,catalogAction:s})=>{var z,C;const r=N(),{convert:l}=O(),[c,a]=u.useState(""),[d,p]=u.useState(!1),[f,g]=u.useState(!1),x=u.useMemo(()=>bo(t,n),[t,n]),h=u.useMemo(()=>c?x.rows.filter(b=>b.section===c):x.rows,[x.rows,c]),v=d?h:h.slice(0,xi.titles),m=u.useMemo(()=>$t(t.resources,t.resource_groups),[t.resources,t.resource_groups]),j=t.contained_works||[],y=new Set(x.rows.map(b=>b.id).filter(Boolean)),k=j.length>0&&!j.every(b=>y.has(b.id)),_=(()=>{const b=x.rows.map(R=>R.edition).filter(Boolean);return b.length>1&&new Set(b).size===1})(),w=f?j:j.slice(0,xi.works),I=x.sections.length>0,S=u.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...I?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[I]),T=u.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:l(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=He(t,r.unit.juan);return(R||E)&&b.push({label:"種數 / 卷數",value:[R?`${R} ${r.unit.bu}`:"",l(E)].filter(Boolean).join(" · "),title:($=t.juan_count)!=null&&$.description?l(t.juan_count.description):void 0}),x.totalVolumes&&b.push({label:"全帙冊數",value:`${x.totalVolumes} ${r.unit.volume}`}),b},[t,j.length,x.totalVolumes,l,r]);return e.jsxs(e.Fragment,{children:[e.jsxs(bt,{facts:T.length?e.jsx(yt,{items:T}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Re,{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:["· ",l(b)]},R))}):null]}),x.rows.length>0&&e.jsxs(Le,{children:[e.jsx(ue,{glyph:"目",title:r.section.containedBooks,count:h.length===x.rows.length?`${r.catalog.contains} ${x.rows.length} ${r.unit.items}`:`${x.rows.length} ${r.unit.items} · 當前 ${h.length} ${r.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,I&&e.jsxs(e.Fragment,{children:[e.jsx(We,{label:r.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),x.sections.map(b=>e.jsx(We,{label:b,active:c===b,onClick:()=>{a(b),p(!1)}},b))]})]})}),e.jsxs(jt,{children:[e.jsx(Ft,{spec:S}),v.map((b,R)=>{var E;return e.jsx(Pt,{no:Ht(R),spec:S,main:e.jsxs(e.Fragment,{children:[b.id?e.jsx(je,{id:b.id,label:l(b.title),onNavigate:i,renderLink:o,dense:!0}):e.jsx("span",{children:l(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=>l(A)).join("、"),")"]}):null,b.edition&&!_&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(b.edition)})]}),meta:e.jsxs(e.Fragment,{children:[I&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:b.section?b.section.endsWith("部")?b.section:`${b.section}部`:e.jsx(qe,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:b.volumes.length>0?`第 ${yn(b.volumes,r.unit.volume)} ${r.unit.volume}`:b.expected!=null?`${b.found??0}/${b.expected} ${r.unit.volume}`:e.jsx(qe,{})})]})},`${b.id??b.title}-${R}`)}),v.length===0&&e.jsx(Dt,{children:r.catalog.noMatch})]}),h.length>v.length&&e.jsx($e,{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(ue,{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(Xe,{item:b,fallbackNote:b.details?l(b.details):void 0},`${b.id||b.url||b.name}-${R}`))})]}),k&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:r.section.containedWorks,count:`${j.length} 種`}),e.jsxs(Mt,{children:[w.map(b=>e.jsx(vt,{children:e.jsx(je,{id:b.id,label:l(b.title),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},b.id)),j.length>w.length&&e.jsx($e,{inline:!0,label:`更多 ${j.length-w.length} 種`,onClick:()=>g(!0)})]})]})]})]})},oa=16,fi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},Kt=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function gi(t){if(!t)return Kt.length;const n=Kt.indexOf(t);return n===-1?Kt.length:n}const Ao=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var S,T,z;const s=N(),{convert:r}=O(),[l,c]=u.useState("全部"),[a,d]=u.useState(!1),[p,f]=u.useState("default"),[g,x]=u.useState(new Map),h=u.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:bn(b.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,g]),v=u.useMemo(()=>ho((t.works||[]).map(C=>C.role)),[t.works]),m=u.useMemo(()=>{const C=l==="全部"?h:h.filter(b=>b.cls===l);return p==="versions"?[...C].sort((b,R)=>(R.versionCount??-1)-(b.versionCount??-1)):C},[h,l,p]),j=a?m:m.slice(0,oa),y=u.useMemo(()=>j.filter(C=>!g.has(C.id)).map(C=>C.id),[j,g]);u.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||x(R=>{const E=new Map(R);for(const[A,M]of b)E.set(A,M);return E})}),()=>{C=!0}},[n,y]);const k=u.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)=>gi(b[0])-gi(R[0])).map(([b,R])=>({label:b,names:R}))},[t.alt_names,s]),_=u.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,I=!!((T=t.description)!=null&&T.text);return e.jsxs(e.Fragment,{children:[e.jsx(bt,{facts:_.length?e.jsx(yt,{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:r(C.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:C.names.map(b=>r(b)).join(" · ")})]},C.label))}),I&&e.jsx(Re,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),h.length>0&&e.jsxs(Le,{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(At,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{f(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(We,{label:`${C.label} ${C.count}`,active:l===C.cls,onClick:()=>{c(C.cls),d(!1)}},C.cls))}),e.jsxs(jt,{children:[e.jsx(Ft,{spec:fi}),j.map((C,b)=>e.jsx(Pt,{no:Ht(b),spec:fi,main:e.jsx(je,{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(qe,{})}),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(Dt,{children:"該職任下的著作尚未著錄。"})]}),m.length>j.length&&e.jsx($e,{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 ra(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 sa(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 mi(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 la(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 aa(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 l=o?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&t.node_groups)for(const[p,f]of Object.entries(t.node_groups))l.has(f)&&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 Rt(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??[]),l=o.node_groups??{},c=aa(o,i??o.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,f=new Set,g=new Set;if(a){const _=new Map(n.map(C=>[C.id,C])),w=new Map((o.hypothetical_nodes??[]).map(C=>[C.id,C])),I=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),T=new Set,z=C=>{if(!T.has(C)){T.add(C);for(const b of I(C))r.has(b)||(S(b)||(w.has(b)?g.add(b):_.has(b)&&f.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 x=n.filter(_=>!r.has(_.id)).filter(_=>!d||d.has(_.id)||f.has(_.id)).map(_=>{const w=sa(_,l);return w&&f.has(_.id)&&(w.bridge=!0),w}).filter(_=>_!==null),h=(o.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||g.has(_.id)).map(_=>{const w=ra(_);return g.has(_.id)&&(w.bridge=!0),w}),v=[...x,...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)&&!f.has(_.id)||((_.lineage.derived_from??[]).forEach((w,I)=>{k(mi(_.id,w,I))}),(_.lineage.related_to??[]).forEach((w,I)=>{k(la(_.id,w,I))}));for(const _ of o.hypothetical_nodes??[])p&&!p.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((w,I)=>{k(mi(_.id,w,I))});return{nodes:v,edges:y,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(r)}}function Mo(t,n,i){const o=(t??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function ca(t,n){const i=[],o=t.version_graph;if(!o)return i;const s=new Set(n.map(a=>a.id)),r=new Set((o.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...r]),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"&&!r.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 o.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const Fo=({graph:t,renderLink:n,className:i,style:o})=>{const{convert:s}=O();if(!t.nodes.length)return e.jsx("div",{style:{...ka,...o},className:i,children:"暂无版本图数据"});const r=new Map,l=new Map;for(const g of t.edges)if(g.kind==="derive"){const x=r.get(g.target)??[];x.push(g),r.set(g.target,x)}else for(const x of[g.source,g.target]){const h=l.get(x)??[];h.push(g),l.set(x,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),a=new Map,d=[];for(const g of t.nodes)if(g.group){const x=a.get(g.group)??[];x.push(g),a.set(g.group,x)}else d.push(g);const p=(g,x)=>(g.year??9999)-(x.year??9999);a.forEach(g=>g.sort(p)),d.sort(p);const f=t.groups.filter(g=>a.has(g.id));return e.jsxs("div",{className:i,style:{...pa,...o},children:[t.title&&e.jsx("div",{style:ua,children:s(t.title)}),t.description&&e.jsx("div",{style:xa,children:s(t.description)}),f.map(g=>e.jsx(hi,{label:g.label,color:g.color,nodes:a.get(g.id),incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(hi,{label:"其他",nodes:d,incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n})]})},hi=({label:t,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:r,renderLink:l})=>{const{convert:c}=O();return e.jsxs("div",{style:fa,children:[e.jsx("div",{style:{...ga,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(da,{node:a,incoming:o.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:r,renderLink:l},a.id))]})},da=({node:t,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const r=t.kind==="hypothetical",l=t.bridge,{convert:c}=O();return e.jsxs("div",{style:{...ma,borderStyle:r||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:ha,children:[e.jsx("span",{style:ba,children:r||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:ya,children:Mo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:va,children:[t.category&&e.jsx(rt,{children:c(t.category)}),t.status==="lost"&&e.jsx(rt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(rt,{tone:"warn",children:"残本"}),r&&e.jsx(rt,{tone:"info",children:"假想祖本"}),l&&e.jsx(rt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:ja,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Sa,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:yi,children:[e.jsx("div",{style:vi,children:"来源:"}),n.map(a=>{const d=o.get(a.source);return e.jsxs("div",{style:ji(a.confidence),children:[e.jsx("span",{style:Si,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(bi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:ki,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:yi,children:[e.jsx("div",{style:vi,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=o.get(d);return e.jsxs("div",{style:ji(a.confidence),children:[e.jsx("span",{style:Si,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(bi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:ki,children:["· ",c(a.evidence)]})]},a.id)})]})]})},rt=({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})},bi=({level:t})=>{const i={certain:{label:"确定",color:"var(--bim-confidence-certain, #2e7d32)"},consensus:{label:"共识",color:"var(--bim-confidence-consensus, #1976d2)"},probable:{label:"推测",color:"var(--bim-confidence-probable, #ed6c02)"},disputed:{label:"有争议",color:"var(--bim-confidence-disputed, #c62828)"}}[t];return i?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},pa={fontSize:"14px",color:"var(--bim-fg, #333)"},ua={fontSize:"16px",fontWeight:600,marginBottom:"8px"},xa={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},fa={marginBottom:"16px"},ga={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)"},ha={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},ba={fontSize:"15px",fontWeight:600},ya={fontSize:"12px",color:"var(--bim-muted, #777)"},va={marginBottom:"6px"},ja={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Sa={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},yi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},vi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},ji=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Si={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},ki={fontSize:"11px",color:"var(--bim-muted, #888)"},ka={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Po=({selectedNodeId:t,...n})=>{const[i,o]=u.useState("loading"),[s,r]=u.useState(null);return u.useEffect(()=>{let l=!1;return wa().then(c=>{l||(c?(r(c),o("ready")):o("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:wi,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:wi,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(_a,{modules:s,selectedNodeId:t,...n})};async function wa(){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 _a=({graph:t,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:r,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:f,BaseEdge:g,EdgeLabelRenderer:x,getSmoothStepPath:h,dagre:v}=l,m=u.useMemo(()=>({lineage:I=>{var P,$,F,W;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}),b=!!(($=I.data)!=null&&$.isSibling),R=b?z:I.targetX-18,E=b?C:I.targetY-12,A=(F=I.data)==null?void 0:F.labelStyle,M=(W=I.data)==null?void 0:W.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:I.id,path:T,style:I.style,markerStart:I.markerStart,markerEnd:I.markerEnd}),I.label&&e.jsx(x,{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})})]})}}),[g,x,h]),j=u.useMemo(()=>({version:I=>{const S=I.data,T=S.kind==="hypothetical",z=S.status==="lost",C=S.isSelected,b=S.bridge,R=S.borderColor??"var(--bim-muted, #888)",E=b||T?"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)":T||b?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:b?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(p,{type:"target",position:f.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:Mo(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:f.Right,style:{visibility:"hidden"}})]})}}),[p,f]),{convert:y}=O(),{rfNodes:k,rfEdges:_}=u.useMemo(()=>Ca(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(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Ca(t,n,i,o,s=r=>r??""){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 f=t.nodes.map(j=>{const y=a.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??Ta(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,x=.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,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)*x;v.set(w.id,g+S)})}const m=t.edges.map(j=>Ia(j,v.get(j.id),s));return{rfNodes:f,rfEdges:m}}function Ia(t,n,i=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",r=za(t.confidence),l={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:l,markerStart:s?l:void 0,zIndex:1e3}}function Ta(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function za(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 wi={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)"},Ho=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:r,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:f})=>{var y;const[g,x]=u.useState(n),h=k=>{x(k),r==null||r(k)},v=(()=>{if(!a)return[];const k=Object.entries(a);return k.length===0||a.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=l?(y=a==null?void 0:a[l])==null?void 0:y.description:void 0;return e.jsxs("div",{className:p,style:f,children:[e.jsxs("div",{style:Ra,children:[e.jsx("button",{onClick:()=>h("list"),style:Jt(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:Jt(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:Jt(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}),g==="list"?e.jsx(Fo,{graph:t,renderLink:i}):e.jsx(Po,{graph:t,renderLink:i,height:o,selectedNodeId:s})]})},Ra={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Jt=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"}),Do=({style:t})=>{const n=u.useContext(mt);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:"简"})]})},Oo=({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"})})}),Ea=({id:t,transport:n,activeTab:i,onTabChange:o,activeJuan:s,onJuanChange:r,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:f,onNavigate:g,onBack:x,backLabel:h,renderLink:v,enrichDetail:m,getSourceLink:j,extraTabs:y=[],showFeedbackTab:k=!0,feedbackApiUrl:_,height:w,footerExtra:I,className:S,style:T})=>{const z=N(),{convert:C}=O(),[b,R]=u.useState(null),[E,A]=u.useState(null),[M,P]=u.useState(!0),[$,F]=u.useState(!1),[W,B]=u.useState([]),[D,te]=u.useState(!1),[G,Z]=u.useState(null),[re,ne]=u.useState(!1),[U,Y]=u.useState(null),[ce,Oe]=u.useState(!1),[Se,he]=u.useState(null),[Ie,Ae]=u.useState(!1),ke=u.useRef(null),[Ne,Qe]=u.useState(null),V=s!==void 0?s:Ne,ie=u.useCallback(H=>{r?r(H):Qe(H)},[r]),ee=u.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){B([]);return}te(!0);try{if(n.getCollectionCatalogs)B(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const oe=await n.getCollectionCatalog(H);B(oe?[{resource_id:"",data:oe}]:[])}}catch{B([])}finally{te(!1)}},[n]),L=u.useCallback(async H=>{if(!n.getCollatedEditionIndex){Z(null);return}ne(!0);try{Z(await n.getCollatedEditionIndex(H))}catch{Z(null)}finally{ne(!1)}},[n]),X=u.useCallback(async H=>{if(!n.getBookFullTextIndex){Y(null);return}Oe(!0);try{Y(await n.getBookFullTextIndex(H))}catch{Y(null)}finally{Oe(!1)}},[n]),se=u.useCallback(async(H,oe)=>{Ae(!0);try{if(n.getLineageGraph){const Te=await n.getLineageGraph(H);Te&&he(Te)}const le=oe.version_graph;if(!le||!le.enabled){Se||he(null),ke.current=null;return}const ae=oe.books??[],Q=[];for(const Te of ae)try{const we=await n.getItem(Te);we&&Q.push(we)}catch{}ke.current={work:oe,books:Q};const K=a??le.default_collection??(le.core_books&&le.core_books.length>0?"core":"all"),Ge=K==="core"&&Array.isArray(le.core_books)&&le.core_books.length>0?"core":K??"all";he(Rt(oe,Q,Ge))}catch{he(null),ke.current=null}finally{Ae(!1)}},[n]);u.useEffect(()=>{let H=!1;return(async()=>{P(!0),F(!1),R(null),A(null),B([]),Z(null),he(null),ke.current=null;try{const le=await n.getItem(t);if(H)return;if(!le){F(!0);return}const ae=le;let Q=null;if(n.getEntry&&(Q=await n.getEntry(t),H))return;Q||(Q={id:t,title:ae.title??ae.primary_name??t,type:ae.type??"book"}),m&&m(Q,ae),R(Q),A(ae),ae.type==="collection"?ee(t):ae.type==="work"?((ae.has_collated||n.getCollatedEditionIndex)&&L(t),(ae.version_graph||n.getLineageGraph)&&se(t,ae)):ae.type==="book"&&ae.has_full_text&&n.getBookFullTextIndex&&X(t)}catch{H||F(!0)}finally{H||P(!1)}})(),()=>{H=!0}},[t,n,m,ee,L,se,X]),u.useEffect(()=>{const H=ke.current;!H||!a||he(Rt(H.work,H.books,a))},[a]);const J=[];if(E){if(J.push({key:"basic",label:z.detailTab.basicInfo}),E.type==="collection"){D&&W.length===0&&J.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const H of W)J.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${C(H.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}E.type==="work"&&(G||re)&&J.push({key:"collated",label:re?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),E.type==="book"&&(U||ce)&&J.push({key:"fulltext",label:ce?`${z.detailTab.fullText}…`:z.detailTab.fullText}),E.type==="work"&&(Se||Ie)&&J.push({key:"lineage",label:Ie?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const H of y)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&J.push({key:H.key,label:H.label});k&&J.push({key:"feedback",label:z.detailTab.feedback});for(const H of y)H.position==="after-feedback"&&H.shouldShow(E)&&J.push({key:H.key,label:H.label})}u.useEffect(()=>{if(i!=="emendated"||!E)return;o("basic");const H=setTimeout(()=>{var oe;(oe=document.getElementById("studies"))==null||oe.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,E,o]);const Be=b&&E&&j?j({activeTab:i,activeJuan:V,entry:b,detail:E}):null,be=u.useMemo(()=>{var Q;if(!E)return null;const oe=(E.authors??[]).map(K=>`${K.dynasty?`〔${C(K.dynasty)}〕`:""}${C(K.name)}${K.role?` ${C(K.role)}`:""}`).join(" · ");let le=!1;try{le=q.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const K=E;return{title:C(K.title),subtitle:K.edition?C(K.edition):oe||void 0,aside:[le?z.status.draft:"",oe&&K.edition?oe:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const K=E;return{title:C(K.title),subtitle:C(He(K,z.unit.juan))||void 0,aside:[(Q=K.publication_info)==null?void 0:Q.year,le?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:oe||void 0}}if(E.type==="entity"){const K=E,Ge=we=>we==null?"":we<0?`前${-we}`:String(we),Te=K.birth_year!=null||K.death_year!=null?`${Ge(K.birth_year)||"?"}—${Ge(K.death_year)||"?"}`:"";return{title:C(K.primary_name||K.title),subtitle:[K.dynasty?`〔${C(K.dynasty)}〕`:"",Te].filter(Boolean).join(" ")||void 0,aside:le?z.status.draft:void 0,secondLine:void 0}}const ae=C(He(E,z.unit.juan));return{title:C(E.title),subtitle:[ae,oe].filter(Boolean).join(" · ")||void 0,aside:[E.subtype,le?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,C,z]),pe=()=>{var H;return E?E.type==="work"?e.jsx(Lo,{data:E,transport:n,onNavigate:g,renderLink:v,lineageAction:Se&&Se.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(Wo,{data:E,transport:n,onNavigate:g,renderLink:v}):E.type==="collection"?e.jsx($o,{data:E,catalog:(H=W[0])==null?void 0:H.data,transport:n,onNavigate:g,renderLink:v,catalogAction:W.length>0?e.jsxs("button",{type:"button",onClick:()=>o(`catalog:${W[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(Ao,{data:E,transport:n,onNavigate:g,renderLink:v}):null},Ve=()=>{var oe,le,ae;if(!b||!E)return null;if(i==="basic"||i==="emendated")return pe();if(typeof i=="string"&&i.startsWith("catalog:")){const Q=(oe=W.find(K=>`catalog:${K.resource_id}`===i))==null?void 0:oe.data;return e.jsx(dn,{data:Q,onNavigate:g,renderLink:v})}if(i==="collated")return e.jsx(fn,{index:G||void 0,workId:t,transport:n,onNavigate:g,activeJuan:V,onJuanChange:ie});if(i==="fulltext")return e.jsx(Yi,{index:U||void 0,bookId:t,transport:n,activeChapter:V,onChapterChange:ie});if(i==="lineage"){if(!Se)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:Ie?"加載中…":"暫無版本圖數據"});const Q=E.type==="work"?E:null;return e.jsx(Ho,{graph:Se,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:f,collection:a??((le=Q==null?void 0:Q.version_graph)==null?void 0:le.default_collection),onCollectionChange:d,collectionsAvailable:(ae=Q==null?void 0:Q.version_graph)==null?void 0:ae.collections,collectionCounts:(()=>{var we,Sn,kn,wn,_n,Cn,In;if(!Q)return;const K={},Ge=((we=ke.current)==null?void 0:we.books)??[];K.all=(((Sn=Q.books)==null?void 0:Sn.length)??0)-(((wn=(kn=Q.version_graph)==null?void 0:kn.excluded_books)==null?void 0:wn.length)??0);const Te=(_n=Q.version_graph)==null?void 0:_n.collections;if(Te)for(const Tn of Object.keys(Te))K[Tn]=Rt(Q,Ge,Tn).nodes.filter(zn=>zn.kind==="book"&&!zn.bridge).length;return K.core==null&&((In=(Cn=Q.version_graph)==null?void 0:Cn.core_books)!=null&&In.length)&&(K.core=Q.version_graph.core_books.length),K})()})}if(i==="feedback"&&k)return e.jsx(ao,{resourceId:t,apiUrl:_});const H=y.find(Q=>Q.key===i);return H?H.render({detail:E,entry:b,transport:n,onNavigate:g}):null};if(M)return e.jsx(Tt,{style:{minHeight:w,...T},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,oe)=>e.jsx("div",{style:{height:oe===1?40:16,width:H,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},oe))})});if($||!E||!b||!be)return e.jsx(Tt,{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 No=i==="basic"||i==="emendated",Ot=[{label:h??z.detailTab.backToIndex,onClick:x}];if(E.type==="book"&&E.work_id){const H=E.work_id;Ot.push({label:z.indexType.work,onClick:()=>g==null?void 0:g(H)})}return Ot.push({label:z.indexType[E.type]}),e.jsx("div",{className:S,children:e.jsxs(Tt,{style:{minHeight:w,...T},children:[e.jsx(ko,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(vn,{char:"籍"}),e.jsx(wo,{items:Ot})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(Do,{}),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}),Be&&e.jsx(Oo,{...Be})]})}),e.jsx(_o,{...be}),J.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:J.map(H=>e.jsx(We,{label:H.label,active:H.key===i||No&&H.key==="basic",onClick:()=>o(H.key)},H.key))}),e.jsx("div",{style:{marginTop:J.length>1?8:0},children:Ve()}),e.jsx(Eo,{left:e.jsxs(e.Fragment,{children:[I,I?" · ":"",e.jsx(Ba,{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}),Be&&e.jsx("a",{href:Be.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function Ba({id:t,label:n,copied:i}){const[o,s]=u.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=q.BidLink;exports.BookIndexError=q.BookIndexError;exports.BookIndexManager=q.BookIndexManager;exports.BookIndexStorage=q.BookIndexStorage;exports.BundleStorage=q.BundleStorage;exports.ConfigError=q.ConfigError;exports.GithubStorage=q.GithubStorage;exports.IdGenerationError=q.IdGenerationError;exports.IdGenerator=q.IdGenerator;exports.LocalStorage=q.LocalStorage;exports.MigrationError=q.MigrationError;exports.StorageError=q.StorageError;exports.base36Decode=q.base36Decode;exports.base36Encode=q.base36Encode;exports.base58Decode=q.base58Decode;exports.buildId=q.buildId;exports.buildPromotionMap=q.buildPromotionMap;exports.cleanName=q.cleanName;exports.decodeId=q.decodeId;exports.decodeIdString=q.decodeIdString;exports.encodeId=q.encodeId;exports.extractIdFromUrl=q.extractIdFromUrl;exports.extractStatus=q.extractStatus;exports.extractType=q.extractType;exports.normalizeCatalog=q.normalizeCatalog;exports.parseId=q.parseId;exports.shardOf=q.shardOf;exports.smartDecode=q.smartDecode;exports.validateResource=q.validateResource;exports.Badge=Lt;exports.BidUrlProvider=er;exports.BookDetailLayout=Ea;exports.BookFullText=Yi;exports.BookPage=Wo;exports.Breadcrumb=wo;exports.Chip=vt;exports.ChipWall=Mt;exports.CollatedEdition=fn;exports.CollectionCatalog=dn;exports.CollectionPage=$o;exports.CreateEntityDialog=eo;exports.DETAIL_CSS=So;exports.Dash=qe;exports.DataTable=jt;exports.DetailFooter=Eo;exports.DetailHeader=_o;exports.EmendatedBySection=Pi;exports.EmptyNote=Dt;exports.EntityDetail=Li;exports.EntityPage=Ao;exports.EntityPickerDialog=no;exports.EntitySelector=Qi;exports.ExpandRow=Io;exports.ExtLink=tn;exports.FactList=yt;exports.FeedbackButton=$l;exports.FeedbackDialog=so;exports.FeedbackForm=lo;exports.FeedbackList=gn;exports.FeedbackTab=ao;exports.FilterChip=We;exports.FormInput=xe;exports.FormTextArea=Fe;exports.GlyphBadge=vn;exports.HomePage=Zt;exports.IndexApp=Os;exports.IndexBrowser=Xt;exports.IndexDetail=cn;exports.IndexEditor=io;exports.IndexView=wl;exports.IntroGrid=bt;exports.LocaleContext=mt;exports.LocaleProvider=cr;exports.LocaleToggle=Do;exports.ModeIndicator=Ei;exports.MoreButton=$e;exports.PAGE_MAX_WIDTH=jo;exports.PageFrame=Tt;exports.Quote=zt;exports.ROLE_CLASS_ORDER=mo;exports.RelationPanel=Xi;exports.RepoSourceLink=Oo;exports.ResourceEditor=qt;exports.ResourceGroup=en;exports.ResourceLine=Xe;exports.ResourceList=an;exports.ResourceRow=To;exports.SearchInput=Bi;exports.Section=ye;exports.SectionHead=ue;exports.SmartBidInput=_t;exports.SourceEditor=Ki;exports.TableHead=Ft;exports.TableRow=Pt;exports.TagRow=jn;exports.TagRows=Ro;exports.TextButton=At;exports.TopStrip=ko;exports.VersionLineageGraph=Po;exports.VersionLineageList=Fo;exports.VersionLineageView=Ho;exports.VolumeChips=Co;exports.VolumeLinks=zo;exports.WorkCatalog=Ns;exports.WorkPage=Lo;exports.bucketResources=$t;exports.buildCollectionTable=bo;exports.buildLineageGraph=Rt;exports.buildPageUrl=ln;exports.buildVersionRow=fo;exports.buildVersionTable=go;exports.computeVersionPartition=Jl;exports.deriveEditionType=vo;exports.deriveEra=mn;exports.deriveYear=uo;exports.detailToEditor=ro;exports.editorToDetail=kl;exports.eraRank=at;exports.flattenTitles=gt;exports.formatTemplate=ht;exports.formatVolumeRange=yn;exports.getDisplayNameFromUrl=xt;exports.getStartPage=sn;exports.getTypeGroupKey=nn;exports.groupRelatedWorks=xo;exports.measureText=He;exports.mergeVolumeResources=on;exports.normalizeEra=st;exports.normalizeRole=bn;exports.normalizeVolumeIndex=ut;exports.normalizeVolumes=Ri;exports.numberToChinese=yo;exports.parseChineseNumber=po;exports.parseSourceString=Ji;exports.resourceHref=Et;exports.resourceNote=hn;exports.roleFacets=ho;exports.rowNo=Ht;exports.stringifySources=qi;exports.useBidUrl=me;exports.useConvert=O;exports.useT=N;exports.validateLineageGraph=ca;exports.volumeStats=rn;
|
|
51
|
+
`;function Tt({children:t,style:n}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:ko}),e.jsx("div",{className:"bim-d-main",children:t})]})}function wo({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 vn({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 _o({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}`),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},o):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},o);return e.jsxs(u.Fragment,{children:[r,c]},o)})})}function Co({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 vt({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 jt({items:t,horizontal:n}){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((i,o)=>e.jsxs("div",{title:i.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.label}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:i.value})]},o))}):null}function ue({glyph:t,tone:n,title:i,count:o,actions:s,id:r}){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(vn,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children: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 Te({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function Ae({label:t,active:n,onClick:i,dashed:o}){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:t})}function Mt({label:t,onClick:n}){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:t})}function Me({label:t,onClick:n,inline:i}){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:t})}function St({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 Ft({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function Io({volumes:t,unit:n="冊",max:i=60}){const[o,s]=u.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(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)),!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 Ne({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function Pt({spec:t}){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:t.mainLabel}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(n=>n.width).join(" "),gap:12},children:t.columns.map(n=>e.jsx("span",{children:n.label},n.label))})]})}function Ht({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 Dt(t){return String(t+1).padStart(2,"0")}function Xe(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function zo({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 Rt({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 en({title:t,tag:n,children:i}){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:t}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:n})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function To({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 Ze({item:t,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{convert:s}=D(),[r,l]=u.useState(!1),c=rn(t),a=i&&!!c&&c.expected>0,d=(t.url?gt(t.url):void 0)||s(t.name),p=n?Kl(t,n):"",f=p?`${d}(${p})`:d;return e.jsx(To,{name:f,note:hn(t)||o,href:Bt(t),extra:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>l(g=>!g),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:r?"收起分冊":`展開 ${c.expected} 冊`}),r&&e.jsx(Ro,{item:t})]}):void 0})}function Ro({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 jn({label:t,items:n}){const{convert:i}=D();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(St,{children:i(o)},s))]}):null}function Eo({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(jn,{label:i.label,items:i.items},i.label))}):null}function ht(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Bo({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 Qe({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 l=me();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:r})}):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 tn({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 Je={versions:12,catalogs:8,chips:12},Lo={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Wo=({data:t,transport:n,onNavigate:i,renderLink:o,lineageAction:s})=>{var b,R,E,A,M,P,$,F,Q,W,U,ne;const r=O(),{convert:l}=D(),c=u.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[a,d]=u.useState(new Map),[p,f]=u.useState(!1),[g,x]=u.useState(""),[h,v]=u.useState(!1),[m,j]=u.useState("default"),y=p||!!g||h||m==="year",k=u.useMemo(()=>y?c:c.slice(0,Je.versions),[c,y]);u.useEffect(()=>{if(!n||k.length===0)return;const B=k.filter(Y=>!a.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,a]);const _=u.useMemo(()=>c.map(B=>a.get(B)??{id:B}),[c,a]),w=u.useMemo(()=>go(_,t.version_graph,{era:g,scanOnly:h,sort:m}),[_,t.version_graph,g,h,m]),z=p?w.rows:w.rows.slice(0,Je.versions),S=u.useMemo(()=>At(t.resources,t.resource_groups),[t.resources,t.resource_groups]),I=u.useMemo(()=>xo((t.related_works||[]).map(B=>({id:B.id,title:B.title,relation:B.relation}))),[t.related_works]),T=u.useMemo(()=>{var ie,G,K,de;const B=[],V=(G=(ie=t.authors)==null?void 0:ie[0])==null?void 0:G.dynasty;V&&B.push({label:"成書",value:l(V)});const Y=Oe(t,r.unit.juan);if(Y){const he=(K=t.juan_count)==null?void 0:K.description;B.push({label:"卷帙",value:l(Y),title:he?l(he):void 0})}if(y||c.length<=Je.versions){const he=w.allRows.map(pe=>pe.year).filter(pe=>pe!=null);if(he.length>0){const pe=Math.min(...he),le=w.allRows.find(ve=>ve.year===pe);le!=null&&le.era.era&&B.push({label:"最早存世刻本",value:`${le.era.era}${le.era.reign?" "+le.era.reign:""}`,title:le.era.source==="edition"?"據版本題名推斷":void 0})}}return(de=t.indexed_by)!=null&&de.length&&B.push({label:"著錄",value:`${t.indexed_by.length} ${r.unit.bu}`}),B},[t,l,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(vt,{facts:T.length?e.jsx(jt,{items:T}):void 0,children:[((A=t.description)==null?void 0:A.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Le,{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(Le,{text:B.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},V)),e.jsx(Eo,{rows:[{label:r.section.aliases,items:ht(t.additional_titles)},{label:r.section.attachedTexts,items:ht(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(Te,{children:[e.jsx(ue,{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(Ae,{label:"僅看有影印",active:h,dashed:!0,onClick:()=>{v(B=>!B),f(!1)}}),e.jsx(Mt,{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(Ae,{label:r.catalog.all,active:!g,onClick:()=>{x(""),f(!1)}}),w.eras.map(B=>e.jsx(Ae,{label:B,active:g===B,onClick:()=>{x(B),f(!1)}},B))]}),e.jsxs(Ne,{children:[e.jsx(Pt,{spec:Lo}),z.map((B,V)=>e.jsx(na,{row:B,no:V,onNavigate:i,renderLink:o},B.id)),z.length===0&&e.jsx(Qe,{children:g||h?"當前篩選下沒有版本":"暫無版本著錄"})]}),w.rows.length>z.length&&e.jsx(Me,{label:`展開其餘 ${w.rows.length-z.length} 種版本`,onClick:()=>f(!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(Te,{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(en,{title:l(B.label),tag:B.description?l(B.description):void 0,children:B.items.map((V,Y)=>e.jsx(Ze,{item:V,siblings:B.items},`${V.id||V.url||V.name}-${Y}`))},B.key)),S.buckets.map(B=>e.jsx(en,{title:ea[B.key],tag:ta[B.key],children:B.items.map((V,Y)=>e.jsx(Ze,{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(ui,{id:"catalogs",glyph:"目",title:r.section.indexed,items:t.indexed_by,unit:r.unit.bu,cap:Je.catalogs,showMeta:!0,t:r,convert:l,onNavigate:i,renderLink:o}):null,(ne=t.emendated_by)!=null&&ne.length?e.jsx(ui,{id:"studies",glyph:"考",title:r.section.emendated,items:t.emendated_by,unit:r.unit.bu,cap:Je.catalogs,t:r,convert:l,onNavigate:i,renderLink:o}):null]}):null,I.map(B=>e.jsx(ia,{glyph:B.key==="derivative"?"續":"叢",title:r.section[B.labelKey]??r.section.relatedWorks,items:B.items,convert:l,onNavigate:i,renderLink:o},B.key)),C&&e.jsxs(Te,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:r.section.relatedVersions}),e.jsx(Ne,{children:e.jsx(Qe,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},ea={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},ta={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function na({row:t,no:n,onNavigate:i,renderLink:o}){const{convert:s}=D(),r=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(Ht,{no:Dt(n),spec:Lo,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:l?"據版本題名推斷":void 0,children:r||e.jsx(Xe,{})}),e.jsx(pi,{items:t.images,convert:s}),e.jsx(pi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function pi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(Xe,{});if(t.length===1){const l=t[0],c=(l.url?gt(l.url):void 0)||n(l.name),a=Bt(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(tn,{href:a,children:c}):c})}const o=t[0],s=(o.url?gt(o.url):void 0)||n(o.name),r=Bt(o);return e.jsxs("span",{style:{minWidth:0},children:[r?e.jsx(tn,{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 ui({id:t,glyph:n,title:i,items:o,unit:s,cap:r,showMeta:l,t:c,convert:a,onNavigate:d,renderLink:p}){const[f,g]=u.useState({}),[x,h]=u.useState(!1),v=o.length>0&&o.every((y,k)=>f[k]),m=u.useCallback(()=>{g(v?{}:Object.fromEntries(o.map((y,k)=>[k,!0])))},[v,o]),j=x?o:o.slice(0,r);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(ue,{glyph:n,tone:"ink",title:i,count:`${o.length} ${s}`,actions:e.jsx(Mt,{label:v?"收起全部":"+ 展開提要",onClick:m})}),e.jsx(Ne,{children:j.map((y,k)=>{const _=y;return e.jsxs(zo,{open:!!f[k],onToggle:()=>g(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(Rt,{children:a(_.summary)}),_.comment&&e.jsx(Rt,{label:c.section.comment,children:a(_.comment)}),_.additional_comment&&e.jsx(Rt,{label:c.section.additionalComment,children:a(_.additional_comment)}),l&&_.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(Me,{label:`展開其餘 ${o.length-j.length} ${s}`,onClick:()=>h(!0)})]})}function ia({glyph:t,title:n,items:i,convert:o,onNavigate:s,renderLink:r}){const[l,c]=u.useState(!1),a=l?i:i.slice(0,Je.chips);return e.jsxs(Te,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Ft,{children:[a.map(d=>e.jsx(St,{children:e.jsx(we,{id:d.id,label:o(d.title),onNavigate:s,renderLink:r,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx(Me,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const oa=8,$o=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var k,_,w,z;const s=O(),{convert:r}=D(),[l,c]=u.useState(null),[a,d]=u.useState(new Map),[p,f]=u.useState([]),[g,x]=u.useState(!1);u.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]),u.useEffect(()=>{const S=t.contained_in||[];if(!n||S.length===0){d(new Map);return}let I=!1;return Promise.all(S.map(T=>{const C=typeof T=="string"?T:T.id;return n.getItem(C).then(b=>[C,b]).catch(()=>[C,null])})).then(T=>{if(I)return;const C=new Map;for(const[b,R]of T)R&&C.set(b,R);d(C)}),()=>{I=!0}},[n,t.contained_in]);const h=u.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]);u.useEffect(()=>{if(!n||h.length===0){f([]);return}const S=g?h:h.slice(0,oa);let I=!1;return Promise.all(S.map(T=>n.getItem(T).then(C=>({id:T,title:C==null?void 0:C.title,edition:C==null?void 0:C.edition})).catch(()=>({id:T})))).then(T=>{I||f(T)}),()=>{I=!0}},[n,h,g]);const v=u.useMemo(()=>At(t.resources,t.resource_groups),[t.resources,t.resource_groups]),m=u.useMemo(()=>{var E,A,M;const S=[],I=mn(t),T=jo(t);T&&S.push({label:"版本類型",value:T,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"?[]:ft(P.volume_index));C.length&&(S.push({label:"冊數",value:`${C.length} ${s.unit.volume}`}),S.push({label:"冊次",value:`第 ${yn(C,s.unit.volume)} ${s.unit.volume}`}));const b=Oe(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"&&ft(S.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(vt,{facts:m.length?e.jsx(jt,{items:m,horizontal:!j}):void 0,children:j?e.jsx(Le,{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(Te,{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,I)=>{var E,A;const T=typeof S=="string"?S:S.id,C=typeof S=="string"?[]:ft(S.volume_index),b=a.get(T),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:T,label:b?r(b.title):T,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(Io,{volumes:C,unit:s.unit.volume})]},`${T}-${I}`)})})]}),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:r(l.title),onNavigate:i,renderLink:o})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[r(Oe(l,s.unit.juan)),(_=l.authors)==null?void 0:_.map(S=>{const I=ho(S.role);return`${S.dynasty?`〔${r(S.dynasty)}〕`:""}${r(S.name)}${I?" "+r(I):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((w=l.description)==null?void 0:w.text)&&e.jsx(Le,{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(jn,{label:s.section.aliases,items:[...ht(t.additional_titles),...ht(t.attached_texts)]})})]})]}),(v.buckets.length>0||v.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:[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,T)=>e.jsx(Ze,{item:I,showVolumes:!y},`${I.id||I.url||I.name}-${T}`))]},S.key)),v.buckets.flatMap(S=>S.items).map((S,I)=>e.jsx(Ze,{item:S,showVolumes:!y},`${S.id||S.url||S.name}-${I}`))]})]})]}),(z=t.location_history)!=null&&z.length?e.jsxs(Te,{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,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(Te,{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:o,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Ft,{children:[p.map(S=>e.jsx(St,{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(Me,{inline:!0,label:`更多 ${h.length-p.length} 種`,onClick:()=>x(!0)})]})]})]})},xi={titles:16,works:16},Ao=({data:t,catalog:n,onNavigate:i,renderLink:o,catalogAction:s})=>{var T,C;const r=O(),{convert:l}=D(),[c,a]=u.useState(""),[d,p]=u.useState(!1),[f,g]=u.useState(!1),x=u.useMemo(()=>yo(t,n),[t,n]),h=u.useMemo(()=>c?x.rows.filter(b=>b.section===c):x.rows,[x.rows,c]),v=d?h:h.slice(0,xi.titles),m=u.useMemo(()=>At(t.resources,t.resource_groups),[t.resources,t.resource_groups]),j=t.contained_works||[],y=new Set(x.rows.map(b=>b.id).filter(Boolean)),k=j.length>0&&!j.every(b=>y.has(b.id)),_=(()=>{const b=x.rows.map(R=>R.edition).filter(Boolean);return b.length>1&&new Set(b).size===1})(),w=f?j:j.slice(0,xi.works),z=x.sections.length>0,S=u.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...z?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[z]),I=u.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:l(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=Oe(t,r.unit.juan);return(R||E)&&b.push({label:"種數 / 卷數",value:[R?`${R} ${r.unit.bu}`:"",l(E)].filter(Boolean).join(" · "),title:($=t.juan_count)!=null&&$.description?l(t.juan_count.description):void 0}),x.totalVolumes&&b.push({label:"全帙冊數",value:`${x.totalVolumes} ${r.unit.volume}`}),b},[t,j.length,x.totalVolumes,l,r]);return e.jsxs(e.Fragment,{children:[e.jsxs(vt,{facts:I.length?e.jsx(jt,{items:I}):void 0,children:[((T=t.description)==null?void 0:T.text)&&e.jsx(Le,{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:["· ",l(b)]},R))}):null]}),x.rows.length>0&&e.jsxs(Te,{children:[e.jsx(ue,{glyph:"目",title:r.section.containedBooks,count:h.length===x.rows.length?`${r.catalog.contains} ${x.rows.length} ${r.unit.items}`:`${x.rows.length} ${r.unit.items} · 當前 ${h.length} ${r.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,z&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:r.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),x.sections.map(b=>e.jsx(Ae,{label:b,active:c===b,onClick:()=>{a(b),p(!1)}},b))]})]})}),e.jsxs(Ne,{children:[e.jsx(Pt,{spec:S}),v.map((b,R)=>{var E;return e.jsx(Ht,{no:Dt(R),spec:S,main:e.jsxs(e.Fragment,{children:[b.id?e.jsx(we,{id:b.id,label:l(b.title),onNavigate:i,renderLink:o,dense:!0}):e.jsx("span",{children:l(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=>l(A)).join("、"),")"]}):null,b.edition&&!_&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(b.edition)})]}),meta:e.jsxs(e.Fragment,{children:[z&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:b.section?b.section.endsWith("部")?b.section:`${b.section}部`:e.jsx(Xe,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:b.volumes.length>0?`第 ${yn(b.volumes,r.unit.volume)} ${r.unit.volume}`:b.expected!=null?`${b.found??0}/${b.expected} ${r.unit.volume}`:e.jsx(Xe,{})})]})},`${b.id??b.title}-${R}`)}),v.length===0&&e.jsx(Qe,{children:r.catalog.noMatch})]}),h.length>v.length&&e.jsx(Me,{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(ue,{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(Ze,{item:b,fallbackNote:b.details?l(b.details):void 0},`${b.id||b.url||b.name}-${R}`))})]}),k&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:r.section.containedWorks,count:`${j.length} 種`}),e.jsxs(Ft,{children:[w.map(b=>e.jsx(St,{children:e.jsx(we,{id:b.id,label:l(b.title),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},b.id)),j.length>w.length&&e.jsx(Me,{inline:!0,label:`更多 ${j.length-w.length} 種`,onClick:()=>g(!0)})]})]})]})]})},ra=16,fi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},Kt=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function gi(t){if(!t)return Kt.length;const n=Kt.indexOf(t);return n===-1?Kt.length:n}const Mo=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var S,I,T;const s=O(),{convert:r}=D(),[l,c]=u.useState("全部"),[a,d]=u.useState(!1),[p,f]=u.useState("default"),[g,x]=u.useState(new Map),h=u.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:bn(b.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,g]),v=u.useMemo(()=>bo((t.works||[]).map(C=>C.role)),[t.works]),m=u.useMemo(()=>{const C=l==="全部"?h:h.filter(b=>b.cls===l);return p==="versions"?[...C].sort((b,R)=>(R.versionCount??-1)-(b.versionCount??-1)):C},[h,l,p]),j=a?m:m.slice(0,ra),y=u.useMemo(()=>j.filter(C=>!g.has(C.id)).map(C=>C.id),[j,g]);u.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||x(R=>{const E=new Map(R);for(const[A,M]of b)E.set(A,M);return E})}),()=>{C=!0}},[n,y]);const k=u.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)=>gi(b[0])-gi(R[0])).map(([b,R])=>({label:b,names:R}))},[t.alt_names,s]),_=u.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,z=!!((I=t.description)!=null&&I.text);return e.jsxs(e.Fragment,{children:[e.jsx(vt,{facts:_.length?e.jsx(jt,{items:_}):void 0,children:(k.length>0||z)&&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))}),z&&e.jsx(Le,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),h.length===0&&e.jsxs(Te,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks}),e.jsx(Ne,{children:e.jsx(Qe,{children:"尚未著錄該人物的關聯作品。"})})]}),h.length>0&&e.jsxs(Te,{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(Mt,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{f(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(Ae,{label:`${C.label} ${C.count}`,active:l===C.cls,onClick:()=>{c(C.cls),d(!1)}},C.cls))}),e.jsxs(Ne,{children:[e.jsx(Pt,{spec:fi}),j.map((C,b)=>e.jsx(Ht,{no:Dt(b),spec:fi,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(Xe,{})}),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(Qe,{children:"該職任下的著作尚未著錄。"})]}),m.length>j.length&&e.jsx(Me,{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,((T=t.external_ids)==null?void 0:T.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function sa(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function la(t,n){if(!t.lineage)return null;const i=t.lineage;return{id:t.id,kind:"book",label:t.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[t.id],note:i.note}}function mi(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 aa(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 ca(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 l=o?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&t.node_groups)for(const[p,f]of Object.entries(t.node_groups))l.has(f)&&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 Et(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??[]),l=o.node_groups??{},c=ca(o,i??o.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,f=new Set,g=new Set;if(a){const _=new Map(n.map(C=>[C.id,C])),w=new Map((o.hypothetical_nodes??[]).map(C=>[C.id,C])),z=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,T=C=>{if(!I.has(C)){I.add(C);for(const b of z(C))r.has(b)||(S(b)||(w.has(b)?g.add(b):_.has(b)&&f.add(b)),T(b))}};for(const C of n)d&&d.has(C.id)&&!r.has(C.id)&&T(C.id);for(const C of o.hypothetical_nodes??[])p&&p.has(C.id)&&T(C.id)}const x=n.filter(_=>!r.has(_.id)).filter(_=>!d||d.has(_.id)||f.has(_.id)).map(_=>{const w=la(_,l);return w&&f.has(_.id)&&(w.bridge=!0),w}).filter(_=>_!==null),h=(o.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||g.has(_.id)).map(_=>{const w=sa(_);return g.has(_.id)&&(w.bridge=!0),w}),v=[...x,...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)&&!f.has(_.id)||((_.lineage.derived_from??[]).forEach((w,z)=>{k(mi(_.id,w,z))}),(_.lineage.related_to??[]).forEach((w,z)=>{k(aa(_.id,w,z))}));for(const _ of o.hypothetical_nodes??[])p&&!p.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((w,z)=>{k(mi(_.id,w,z))});return{nodes:v,edges:y,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(r)}}function Fo(t,n,i){const o=(t??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function da(t,n){const i=[],o=t.version_graph;if(!o)return i;const s=new Set(n.map(a=>a.id)),r=new Set((o.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...r]),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"&&!r.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 o.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const Po=({graph:t,renderLink:n,className:i,style:o})=>{const{convert:s}=D();if(!t.nodes.length)return e.jsx("div",{style:{...wa,...o},className:i,children:"暂无版本图数据"});const r=new Map,l=new Map;for(const g of t.edges)if(g.kind==="derive"){const x=r.get(g.target)??[];x.push(g),r.set(g.target,x)}else for(const x of[g.source,g.target]){const h=l.get(x)??[];h.push(g),l.set(x,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),a=new Map,d=[];for(const g of t.nodes)if(g.group){const x=a.get(g.group)??[];x.push(g),a.set(g.group,x)}else d.push(g);const p=(g,x)=>(g.year??9999)-(x.year??9999);a.forEach(g=>g.sort(p)),d.sort(p);const f=t.groups.filter(g=>a.has(g.id));return e.jsxs("div",{className:i,style:{...ua,...o},children:[t.title&&e.jsx("div",{style:xa,children:s(t.title)}),t.description&&e.jsx("div",{style:fa,children:s(t.description)}),f.map(g=>e.jsx(hi,{label:g.label,color:g.color,nodes:a.get(g.id),incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(hi,{label:"其他",nodes:d,incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n})]})},hi=({label:t,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:r,renderLink:l})=>{const{convert:c}=D();return e.jsxs("div",{style:ga,children:[e.jsx("div",{style:{...ma,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(pa,{node:a,incoming:o.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:r,renderLink:l},a.id))]})},pa=({node:t,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const r=t.kind==="hypothetical",l=t.bridge,{convert:c}=D();return e.jsxs("div",{style:{...ha,borderStyle:r||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:ba,children:[e.jsx("span",{style:ya,children:r||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:va,children:Fo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:ja,children:[t.category&&e.jsx(lt,{children:c(t.category)}),t.status==="lost"&&e.jsx(lt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(lt,{tone:"warn",children:"残本"}),r&&e.jsx(lt,{tone:"info",children:"假想祖本"}),l&&e.jsx(lt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Sa,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:ka,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:yi,children:[e.jsx("div",{style:vi,children:"来源:"}),n.map(a=>{const d=o.get(a.source);return e.jsxs("div",{style:ji(a.confidence),children:[e.jsx("span",{style:Si,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(bi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:ki,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:yi,children:[e.jsx("div",{style:vi,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=o.get(d);return e.jsxs("div",{style:ji(a.confidence),children:[e.jsx("span",{style:Si,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(bi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:ki,children:["· ",c(a.evidence)]})]},a.id)})]})]})},lt=({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})},bi=({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},ua={fontSize:"14px",color:"var(--bim-fg, #333)"},xa={fontSize:"16px",fontWeight:600,marginBottom:"8px"},fa={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},ga={marginBottom:"16px"},ma={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},ha={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"},ya={fontSize:"15px",fontWeight:600},va={fontSize:"12px",color:"var(--bim-muted, #777)"},ja={marginBottom:"6px"},Sa={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},ka={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},yi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},vi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},ji=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Si={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},ki={fontSize:"11px",color:"var(--bim-muted, #888)"},wa={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Ho=({selectedNodeId:t,...n})=>{const[i,o]=u.useState("loading"),[s,r]=u.useState(null);return u.useEffect(()=>{let l=!1;return _a().then(c=>{l||(c?(r(c),o("ready")):o("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:wi,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:wi,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(Ca,{modules:s,selectedNodeId:t,...n})};async function _a(){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 Ca=({graph:t,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:r,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:f,BaseEdge:g,EdgeLabelRenderer:x,getSmoothStepPath:h,dagre:v}=l,m=u.useMemo(()=>({lineage:z=>{var P,$,F,Q;const S=((P=z.data)==null?void 0:P.stepPosition)??.85,[I,T,C]=h({sourceX:z.sourceX,sourceY:z.sourceY,sourcePosition:z.sourcePosition,targetX:z.targetX,targetY:z.targetY,targetPosition:z.targetPosition,stepPosition:S,borderRadius:5}),b=!!(($=z.data)!=null&&$.isSibling),R=b?T:z.targetX-18,E=b?C:z.targetY-12,A=(F=z.data)==null?void 0:F.labelStyle,M=(Q=z.data)==null?void 0:Q.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:z.id,path:I,style:z.style,markerStart:z.markerStart,markerEnd:z.markerEnd}),z.label&&e.jsx(x,{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:z.label})})]})}}),[g,x,h]),j=u.useMemo(()=>({version:z=>{const S=z.data,I=S.kind==="hypothetical",T=S.status==="lost",C=S.isSelected,b=S.bridge,R=S.borderColor??"var(--bim-muted, #888)",E=b||I?"dashed":"solid",A=b?.5:T?.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:f.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:Fo(S.yearText,void 0,S.uncertain)}),T&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(p,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[p,f]),{convert:y}=D(),{rfNodes:k,rfEdges:_}=u.useMemo(()=>Ia(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(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Ia(t,n,i,o,s=r=>r??""){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 f=t.nodes.map(j=>{const y=a.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??Ta(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,x=.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,z)=>{var T,C;const S=((T=a.node(w.target))==null?void 0:T.y)??0,I=((C=a.node(z.target))==null?void 0:C.y)??0;return S-I}),_=k.length;k.forEach((w,z)=>{const S=(z-(_-1)/2)*x;v.set(w.id,g+S)})}const m=t.edges.map(j=>za(j,v.get(j.id),s));return{rfNodes:f,rfEdges:m}}function za(t,n,i=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",r=Ra(t.confidence),l={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:l,markerStart:s?l:void 0,zIndex:1e3}}function Ta(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Ra(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 wi={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)"},Do=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:r,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:f})=>{var y;const[g,x]=u.useState(n),h=k=>{x(k),r==null||r(k)},v=(()=>{if(!a)return[];const k=Object.entries(a);return k.length===0||a.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=l?(y=a==null?void 0:a[l])==null?void 0:y.description:void 0;return e.jsxs("div",{className:p,style:f,children:[e.jsxs("div",{style:Ea,children:[e.jsx("button",{onClick:()=>h("list"),style:Jt(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:Jt(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:Jt(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}),g==="list"?e.jsx(Po,{graph:t,renderLink:i}):e.jsx(Ho,{graph:t,renderLink:i,height:o,selectedNodeId:s})]})},Ea={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Jt=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),Oo=({style:t})=>{const n=u.useContext(bt);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:"简"})]})},No=({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"})})}),Ba=({id:t,transport:n,activeTab:i,onTabChange:o,activeJuan:s,onJuanChange:r,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:f,onNavigate:g,onBack:x,backLabel:h,renderLink:v,enrichDetail:m,getSourceLink:j,extraTabs:y=[],showFeedbackTab:k=!0,feedbackApiUrl:_,height:w,footerExtra:z,className:S,style:I})=>{const T=O(),{convert:C}=D(),[b,R]=u.useState(null),[E,A]=u.useState(null),[M,P]=u.useState(!0),[$,F]=u.useState(!1),[Q,W]=u.useState([]),[U,ne]=u.useState(!1),[B,V]=u.useState(null),[Y,ie]=u.useState(!1),[G,K]=u.useState(null),[de,he]=u.useState(!1),[pe,le]=u.useState(null),[ve,Fe]=u.useState(!1),_e=u.useRef(null),[Ge,tt]=u.useState(null),N=s!==void 0?s:Ge,oe=u.useCallback(H=>{r?r(H):tt(H)},[r]),te=u.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ne(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const re=await n.getCollectionCatalog(H);W(re?[{resource_id:"",data:re}]:[])}}catch{W([])}finally{ne(!1)}},[n]),L=u.useCallback(async H=>{if(!n.getCollatedEditionIndex){V(null);return}ie(!0);try{V(await n.getCollatedEditionIndex(H))}catch{V(null)}finally{ie(!1)}},[n]),Z=u.useCallback(async H=>{if(!n.getBookFullTextIndex){K(null);return}he(!0);try{K(await n.getBookFullTextIndex(H))}catch{K(null)}finally{he(!1)}},[n]),se=u.useCallback(async(H,re)=>{Fe(!0);try{if(n.getLineageGraph){const Ee=await n.getLineageGraph(H);Ee&&le(Ee)}const ae=re.version_graph;if(!ae||!ae.enabled){pe||le(null),_e.current=null;return}const ce=re.books??[],ee=[];for(const Ee of ce)try{const Ce=await n.getItem(Ee);Ce&&ee.push(Ce)}catch{}_e.current={work:re,books:ee};const q=a??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Re=q==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":q??"all";le(Et(re,ee,Re))}catch{le(null),_e.current=null}finally{Fe(!1)}},[n]);u.useEffect(()=>{let H=!1;return(async()=>{P(!0),F(!1),R(null),A(null),W([]),V(null),le(null),_e.current=null;try{const ae=await n.getItem(t);if(H)return;if(!ae){F(!0);return}const ce=ae;let ee=null;if(n.getEntry&&(ee=await n.getEntry(t),H))return;ee||(ee={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),m&&m(ee,ce),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{H||F(!0)}finally{H||P(!1)}})(),()=>{H=!0}},[t,n,m,te,L,se,Z]),u.useEffect(()=>{const H=_e.current;!H||!a||le(Et(H.work,H.books,a))},[a]);const J=[];if(E){if(J.push({key:"basic",label:T.detailTab.basicInfo}),E.type==="collection"){U&&Q.length===0&&J.push({key:"catalog:loading",label:`${T.detailTab.catalog}…`});for(const H of Q)J.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${C(H.short_name)}${T.detailTab.catalogSuffix}`:T.detailTab.collectionCatalog})}E.type==="work"&&(B||Y)&&J.push({key:"collated",label:Y?`${T.detailTab.collatedEdition}…`:T.detailTab.collatedEdition}),E.type==="book"&&(G||de)&&J.push({key:"fulltext",label:de?`${T.detailTab.fullText}…`:T.detailTab.fullText}),E.type==="work"&&(pe||ve)&&J.push({key:"lineage",label:ve?`${T.detailTab.lineage}…`:T.detailTab.lineage});for(const H of y)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&J.push({key:H.key,label:H.label});k&&i==="feedback"&&J.push({key:"feedback",label:T.detailTab.feedback});for(const H of y)H.position==="after-feedback"&&H.shouldShow(E)&&J.push({key:H.key,label:H.label})}u.useEffect(()=>{if(i!=="emendated"||!E)return;o("basic");const H=setTimeout(()=>{var re;(re=document.getElementById("studies"))==null||re.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,E,o]);const $e=b&&E&&j?j({activeTab:i,activeJuan:N,entry:b,detail:E}):null,je=u.useMemo(()=>{var ee;if(!E)return null;const re=(E.authors??[]).map(q=>{const Re=ho(q.role);return`${q.dynasty?`〔${C(q.dynasty)}〕`:""}${C(q.name)}${Re?` ${C(Re)}`:""}`}).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?T.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(Oe(q,T.unit.juan))||void 0,aside:[(ee=q.publication_info)==null?void 0:ee.year,ae?T.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:re||void 0}}if(E.type==="entity"){const q=E,Re=Ce=>Ce==null?"":Ce<0?`前${-Ce}`:String(Ce),Ee=q.birth_year!=null||q.death_year!=null?`${Re(q.birth_year)||"?"}—${Re(q.death_year)||"?"}`:"";return{title:C(q.primary_name||q.title),subtitle:[q.dynasty?`〔${C(q.dynasty)}〕`:"",Ee].filter(Boolean).join(" ")||void 0,aside:ae?T.status.draft:void 0,secondLine:void 0}}const ce=C(Oe(E,T.unit.juan));return{title:C(E.title),subtitle:[ce,re].filter(Boolean).join(" · ")||void 0,aside:[E.subtype,ae?T.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,C,T]),fe=()=>{var H;return E?E.type==="work"?e.jsx(Wo,{data:E,transport:n,onNavigate:g,renderLink:v,lineageAction:pe&&pe.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:[T.detailTab.lineage," →"]}):null}):E.type==="book"?e.jsx($o,{data:E,transport:n,onNavigate:g,renderLink:v}):E.type==="collection"?e.jsx(Ao,{data:E,catalog:(H=Q[0])==null?void 0:H.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:[T.detailTab.collectionCatalog," →"]}):null}):e.jsx(Mo,{data:E,transport:n,onNavigate:g,renderLink:v}):null},Ue=()=>{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(dn,{data:ee,onNavigate:g,renderLink:v})}if(i==="collated")return e.jsx(fn,{index:B||void 0,workId:t,transport:n,onNavigate:g,activeJuan:N,onJuanChange:oe});if(i==="fulltext")return e.jsx(Yi,{index:G||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:oe});if(i==="lineage"){if(!pe)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:ve?"加載中…":"暫無版本圖數據"});const ee=E.type==="work"?E:null;return e.jsx(Do,{graph:pe,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:f,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,Sn,kn,wn,_n,Cn,In;if(!ee)return;const q={},Re=((Ce=_e.current)==null?void 0:Ce.books)??[];q.all=(((Sn=ee.books)==null?void 0:Sn.length)??0)-(((wn=(kn=ee.version_graph)==null?void 0:kn.excluded_books)==null?void 0:wn.length)??0);const Ee=(_n=ee.version_graph)==null?void 0:_n.collections;if(Ee)for(const zn of Object.keys(Ee))q[zn]=Et(ee,Re,zn).nodes.filter(Tn=>Tn.kind==="book"&&!Tn.bridge).length;return q.core==null&&((In=(Cn=ee.version_graph)==null?void 0:Cn.core_books)!=null&&In.length)&&(q.core=ee.version_graph.core_books.length),q})()})}if(i==="feedback"&&k)return e.jsx(ao,{resourceId:t,apiUrl:_});const H=y.find(ee=>ee.key===i);return H?H.render({detail:E,entry:b,transport:n,onNavigate:g}):null};if(M)return e.jsx(Tt,{style:{minHeight:w,...I},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,re)=>e.jsx("div",{style:{height:re===1?40:16,width:H,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},re))})});if($||!E||!b||!je)return e.jsx(Tt,{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 Vo=i==="basic"||i==="emendated",Ot=[{label:h??T.detailTab.backToIndex,onClick:x}];if(E.type==="book"&&E.work_id){const H=E.work_id;Ot.push({label:T.indexType.work,id:H,onClick:()=>g==null?void 0:g(H)})}return Ot.push({label:T.indexType[E.type]}),e.jsx("div",{className:S,children:e.jsxs(Tt,{style:{minHeight:w,...I},children:[e.jsx(wo,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(vn,{char:"籍"}),e.jsx(_o,{items:Ot})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(Oo,{}),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:T.detailTab.feedback}),$e&&e.jsx(No,{...$e})]})}),e.jsx(Co,{...je}),J.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:J.map(H=>e.jsx(Ae,{label:H.label,active:H.key===i||Vo&&H.key==="basic",onClick:()=>o(H.key)},H.key))}),e.jsx("div",{style:{marginTop:J.length>1?8:0},children:Ue()}),e.jsx(Bo,{left:e.jsxs(e.Fragment,{children:[z,z?" · ":"",e.jsx(La,{id:E.id,label:T.label.id,copied:T.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:T.detailTab.submitVersion}),$e&&e.jsx("a",{href:$e.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:T.detailTab.dataLicense})]})})]})})};function La({id:t,label:n,copied:i}){const[o,s]=u.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=Wt;exports.BidUrlProvider=tr;exports.BookDetailLayout=Ba;exports.BookFullText=Yi;exports.BookPage=$o;exports.Breadcrumb=_o;exports.Chip=St;exports.ChipWall=Ft;exports.CollatedEdition=fn;exports.CollectionCatalog=dn;exports.CollectionPage=Ao;exports.CreateEntityDialog=eo;exports.DETAIL_CSS=ko;exports.Dash=Xe;exports.DataTable=Ne;exports.DetailFooter=Bo;exports.DetailHeader=Co;exports.EmendatedBySection=Pi;exports.EmptyNote=Qe;exports.EntityDetail=Li;exports.EntityPage=Mo;exports.EntityPickerDialog=no;exports.EntitySelector=Qi;exports.ExpandRow=zo;exports.ExtLink=tn;exports.FactList=jt;exports.FeedbackButton=Al;exports.FeedbackDialog=so;exports.FeedbackForm=lo;exports.FeedbackList=gn;exports.FeedbackTab=ao;exports.FilterChip=Ae;exports.FormInput=ge;exports.FormTextArea=He;exports.GlyphBadge=vn;exports.HomePage=Zt;exports.IndexApp=Ns;exports.IndexBrowser=Xt;exports.IndexDetail=cn;exports.IndexEditor=io;exports.IndexView=_l;exports.IntroGrid=vt;exports.LocaleContext=bt;exports.LocaleProvider=dr;exports.LocaleToggle=Oo;exports.ModeIndicator=Ei;exports.MoreButton=Me;exports.PAGE_MAX_WIDTH=So;exports.PageFrame=Tt;exports.Quote=Rt;exports.ROLE_CLASS_ORDER=mo;exports.RelationPanel=Xi;exports.RepoSourceLink=No;exports.ResourceEditor=qt;exports.ResourceGroup=en;exports.ResourceLine=Ze;exports.ResourceList=an;exports.ResourceRow=To;exports.SearchInput=Bi;exports.Section=Se;exports.SectionHead=ue;exports.SmartBidInput=Ct;exports.SourceEditor=Ki;exports.TableHead=Pt;exports.TableRow=Ht;exports.TagRow=jn;exports.TagRows=Eo;exports.TextButton=Mt;exports.TopStrip=wo;exports.VersionLineageGraph=Ho;exports.VersionLineageList=Po;exports.VersionLineageView=Do;exports.VolumeChips=Io;exports.VolumeLinks=Ro;exports.WorkCatalog=Vs;exports.WorkPage=Wo;exports.bucketResources=At;exports.buildCollectionTable=yo;exports.buildLineageGraph=Et;exports.buildPageUrl=ln;exports.buildVersionRow=fo;exports.buildVersionTable=go;exports.computeVersionPartition=ql;exports.deriveEditionType=jo;exports.deriveEra=mn;exports.deriveYear=uo;exports.detailToEditor=ro;exports.editorToDetail=wl;exports.eraRank=dt;exports.flattenTitles=ht;exports.formatTemplate=yt;exports.formatVolumeRange=yn;exports.getDisplayNameFromUrl=gt;exports.getStartPage=sn;exports.getTypeGroupKey=nn;exports.groupRelatedWorks=xo;exports.measureText=Oe;exports.mergeVolumeResources=on;exports.normalizeEra=at;exports.normalizeRole=bn;exports.normalizeVolumeIndex=ft;exports.normalizeVolumes=Ri;exports.numberToChinese=vo;exports.parseChineseNumber=po;exports.parseSourceString=Ji;exports.resourceHref=Bt;exports.resourceNote=hn;exports.roleFacets=bo;exports.rowNo=Dt;exports.stringifySources=qi;exports.useBidUrl=me;exports.useConvert=D;exports.useT=O;exports.validateLineageGraph=da;exports.volumeStats=rn;
|