book-index-ui 0.2.26 → 0.2.27

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 CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var Fn=Object.create;var ut=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,Vn=Object.prototype.hasOwnProperty;var Un=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of On(n))!Vn.call(t,s)&&s!==o&&ut(t,s,{get:()=>n[s],enumerable:!(r=Hn(n,s))||r.enumerable});return t};var Ce=(t,n,o)=>(o=t!=null?Fn(Dn(t)):{},Un(n||!t||!t.__esModule?ut(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-C7sHSk4U.cjs"),e=require("react/jsx-runtime"),f=require("react"),Nn=require("react-markdown"),Gn=require("remark-gfm"),Yn=require("react-dom"),Kn=t=>`/book-index?id=${t}`,en=f.createContext(Kn);function Jn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(en.Provider,{value:o,children:n})}function ae(){return f.useContext(en)}function be(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function qn(t,n){return be(t).includes(n)}const tn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Xn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Zn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Pe=f.createContext(null),nn={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:"包含作品"},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:"·目錄"},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:"圖片資源"}},Qn={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:"包含作品"},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:"·目录"},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:"图片资源"}},eo={"zh-Hant":nn,"zh-Hans":Qn},on="bim-locale";function to(){try{const t=localStorage.getItem(on);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function no(t){try{localStorage.setItem(on,t)}catch{}}const oo="zh-Hans",ro=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=f.useState(t??oo),i=t??r;f.useEffect(()=>{if(t)return;const u=to();u&&u!==r&&s(u)},[]);const[a,c]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>u=>u)}):c(null)},[i]);const l=f.useCallback(u=>{s(u),no(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:i,setLocale:l,messages:eo[i],converter:a}),[i,l,a]);return e.jsx(Pe.Provider,{value:d,children:o})};function A(){const t=f.useContext(Pe);return(t==null?void 0:t.messages)??nn}const io=2e3;function F(){const t=f.useContext(Pe),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=f.useCallback(a=>{if(!a)return"";if(!o)return a;const c=r.current.get(a);if(c!==void 0)return c;const l=o(a);if(r.current.size>=io){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,l),l},[o]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Ae(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function so(t){if(!t)return"";try{const n=new URL(t).hostname,o={"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(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function lo(){return{id:"",name:"",url:"",type:"text",details:""}}const nt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=A(),[a,c]=f.useState(null),l=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],d=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],u=m=>{if(!s)return!0;const k=be(m);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},x=t.map((m,k)=>({item:m,originalIndex:k})).filter(({item:m})=>u(m)),g=()=>{const m=lo();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((k,_)=>_!==m)),c(null)},h=(m,k,_)=>{const v=[...t];if(v[m]={...v[m],[k]:_},k==="url"&&!v[m].id){const w=so(_);w&&(v[m].id=w)}n(v)},y=(m,k,_)=>{const w={...t[m].metadata||{}};_?w[k]=_:delete w[k],h(m,"metadata",Object.keys(w).length>0?w:void 0)},b=(m,k)=>{const _=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;h(m,"structure",_)},j=(m,k,_)=>{const w=t[m].coverage||{level:1,ranges:""};k==="level"?w.level=parseInt(_)||1:w.ranges=_,h(m,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:k})=>{var _,v,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(a===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:ao(m.type??"text"),color:"#fff"},children:(()=>{var z,E;const S=be(m);return S.length===0?m.type??"text":S.length===1?((z=l.find(I=>I.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((E=l.find(I=>I.value==="text+image"))==null?void 0:E.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${k+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&co(k,r==null?void 0:r[k],o,i),e.jsx("button",{onClick:S=>{S.stopPropagation(),p(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),a===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[qn(m,"image")&&m.url&&po(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.type}),e.jsx("select",{value:m.type,onChange:S=>h(k,"type",S.target.value),style:{...pe,flex:1},children:l.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:S=>h(k,"root_type",S.target.value),style:{...pe,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:m.id,onChange:S=>h(k,"id",S.target.value),placeholder:i.editor.idAutoExtract,style:{...pe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:S=>h(k,"name",S.target.value),placeholder:i.editor.resourceName,style:{...pe,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:S=>h(k,"url",S.target.value),placeholder:i.editor.resourceUrl,style:pe}),e.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:S=>b(k,S.target.value),placeholder:i.editor.structurePlaceholder,style:pe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((v=m.coverage)==null?void 0:v.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...pe,width:"60px"}})]}),e.jsxs("label",{style:{...ze,flex:1},children:[e.jsx("span",{style:Ie,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...pe,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:i.editor.detailsPlaceholder,style:{...pe,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:i.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(i.metadata).map(([S,z])=>{var E;return e.jsxs("label",{style:{...ze,gap:"4px"},children:[e.jsx("span",{style:{...Ie,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[S])||"",onChange:I=>y(k,S,I.target.value),placeholder:z,style:{...pe,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:i.action.addResource})]})]})};function ao(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function co(t,n,o,r){const s=(n==null?void 0:n.status)==="downloading",i=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||o(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i?"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:i?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function po(t,n){const o=/\.(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:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const pe={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"},ze={display:"flex",alignItems:"center",gap:"6px"},Ie={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},xo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function uo(t){try{const n=new URL(t).hostname;return xo[n]}catch{return}}const ft={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function fo(t){return t.includes("text")&&t.includes("image")?ft["text+image"]:ft[t[0]||"physical"]}const gt={text:0,image:1,physical:2};function De(t){return t.length===0?"physical":[...t].sort((n,o)=>(gt[n]??99)-(gt[o]??99)).join("+")}function go(t){const n=i=>{const a=i.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const c=i.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const a=t[i];if(a.volumes&&a.volumes.length>0)continue;const c=n(a.name);if(!c)continue;const[l,d]=c,u=`${l}|${De(be(a))}`;o.has(u)||o.set(u,{base:{...a,name:l,url:"",volumes:[]},volumes:[]}),o.get(u).volumes.push({volume:d,url:a.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((a,c)=>a.volume-c.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let a=0;a<t.length;a++)if(s.has(a)){const c=n(t[a].name),l=c&&`${c[0]}|${De(be(t[a]))}`,d=`${i.base.name}|${De(be(i.base))}`;l===d&&s.delete(a)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const lt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=A(),i=f.useMemo(()=>go(t||[]),[t]),a={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},c=x=>a[x]?a[x]:x.split("+").map(g=>a[g]||g).join("+");if(!i||i.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((x,g)=>e.jsx(ht,{item:x},x.id||g))});const l=new Map;for(const x of i){const g=De(be(x));l.has(g)||l.set(g,[]),l.get(g).push(x)}const d=["text","image","text+image","physical"],u=[...d.filter(x=>l.has(x)),...[...l.keys()].filter(x=>!d.includes(x)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:u.map(x=>{const g=l.get(x),p=fo(x.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:p,whiteSpace:"nowrap",flexShrink:0},children:c(x)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:g.map((h,y)=>e.jsx(ht,{item:h,onNavigate:o,renderLink:r},h.id||y))})]},x)})})};function ho(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const s=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(s)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(s[1]))}&page=${n}`;const i=new URL(t);return i.searchParams.set("page",String(n)),i.toString()}return t}catch{return t}}function bo(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function mo(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const yo={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},ht=({item:t})=>{const n=A(),{convert:o}=F(),[r,s]=f.useState(!1),i=f.useMemo(()=>(t.url?uo(t.url):void 0)||o(t.name),[t.url,t.name,o]),a=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||mo(h)})),[t.volumes]),c=a&&a.length>0,l=c?new Set(a.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(a.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,u=t.expected_volumes??(c?l+d:0),x=t.color_mode?{...yo[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?o(t.details):null,p={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:p,children:[e.jsx("span",{style:{fontWeight:500},children:i}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=bo(t.metadata);return h?ho(t.url,h):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(h=>{const y=h.status==="missing";return h.url&&!y?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:h.volume},h.volume)})})]})},rn=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:a})=>{const c=A(),l=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",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)"},p={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:g,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:g,...p,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:i,title:x||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:l?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...p,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!l&&x&&e.jsxs("div",{style:{...g,background:"#2196f3",color:"white",cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Ge="bim-search-history",bt=10,mt=8;function Le(){try{const t=localStorage.getItem(Ge);return t?JSON.parse(t):[]}catch{return[]}}function vo(t){try{const n=Le().filter(o=>o!==t);n.unshift(t),n.length>bt&&(n.length=bt),localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function jo(t){try{const n=Le().filter(o=>o!==t);localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function So(){try{localStorage.removeItem(Ge)}catch{}}const sn=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const a=A(),c=i??a.search.placeholder,l={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[x,g]=f.useState([]),[p,h]=f.useState(-1),[y,b]=f.useState(Le),j=f.useRef(null),m=f.useRef(null),k=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{h(-1);const C=n.trim();if(!C){g(y.map(M=>({type:"history",text:M})));return}if(!t.searchAll){g([]);return}let B=!1;const H=setTimeout(()=>{t.searchAll(C,mt).then(M=>{if(B)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];g($.slice(0,mt).map(D=>({type:"entry",text:D.title||D.id,entry:D})))}).catch(()=>{B||g([])})},80);return()=>{B=!0,clearTimeout(H)}},[n,y,t]),f.useEffect(()=>{const C=B=>{k.current&&!k.current.contains(B.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=B=>{var H,M;if(B.key==="/"&&document.activeElement!==j.current){const $=(H=document.activeElement)==null?void 0:H.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;B.preventDefault(),(M=j.current)==null||M.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=f.useCallback(C=>{C.trim()&&(vo(C.trim()),b(Le())),r(C),u(!1)},[r]),w=f.useCallback(C=>{C.type==="history"?(o(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),v(C.text)))},[o,v,s]),S=f.useCallback(C=>{if(!d||x.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),h(B=>(B+1)%x.length);break;case"ArrowUp":C.preventDefault(),h(B=>(B-1+x.length)%x.length);break;case"Enter":C.preventDefault(),p>=0&&p<x.length?w(x[p]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,x,p,n,v,w]),z=f.useCallback((C,B)=>{B.stopPropagation(),jo(C),b(Le()),g(H=>H.filter(M=>!(M.type==="history"&&M.text===C)))},[]),E=f.useCallback(C=>{C.stopPropagation(),So(),b([]),g([])},[]);f.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const I=!n.trim()&&y.length>0;return e.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((C,B)=>e.jsxs("div",{onClick:()=>w(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===p?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[l[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:H=>z(C.text,H),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${C.type}-${C.text}-${B}`))]})]})},$e="bim-recent-ids",yt="bim-recent-entries",vt=50,Xe=5,ko=50,wo=200;function Be(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(yt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem($e,JSON.stringify(o)),localStorage.removeItem(yt),o}return[]}catch{return[]}}function _o(t){try{const n=Be().filter(o=>o!==t);n.unshift(t),n.length>vt&&(n.length=vt),localStorage.setItem($e,JSON.stringify(n))}catch{}}function Co(t){try{const n=Be().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function zo(){try{localStorage.removeItem($e)}catch{}}const Io={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ot=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l,hideModeIndicator:d,initialQuery:u,onQueryChange:x,headerRight:g})=>{const p=A(),h=[{type:"work",icon:"✍️",name:p.indexType.work,key:"works"},{type:"book",icon:"📖",name:p.indexType.book,key:"books"},{type:"collection",icon:"📚",name:p.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:p.indexType.entity,key:"entities"}],[y,b]=f.useState(u??""),[j,m]=f.useState(null),[k,_]=f.useState(null),[v,w]=f.useState(!1),[S,z]=f.useState(null),[E,I]=f.useState(""),[C,B]=f.useState(!u),[H,M]=f.useState(Be),[$,D]=f.useState([]),[L,T]=f.useState(!1),[O,W]=f.useState(!1),[U,G]=f.useState(null),[Z,ne]=f.useState(null),he=f.useRef(void 0),ge=f.useRef(!1),Q=f.useCallback(async(P,J)=>{if(!P.trim()){B(!0),m(null),_(null);return}B(!1),w(!0),I("");try{if(t.searchAll){const Y=await t.searchAll(P,J??Xe);m(Y)}else{const Y=["work","book","collection","entity"],K=await Promise.all(Y.map(ee=>t.search(P,ee,{page:1,pageSize:J??Xe})));m({works:K[0].entries,books:K[1].entries,collections:K[2].entries,entities:K[3].entries,totalWorks:K[0].total,totalBooks:K[1].total,totalCollections:K[2].total,totalEntities:K[3].total})}}catch(Y){I(Y instanceof Error?Y.message:String(Y)),m(null)}finally{w(!1)}},[t]);f.useEffect(()=>{let P=!1;const J=()=>{var V,oe;const Y=["work","book","collection","entity"],K=Promise.all(Y.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((V=t.getResourceCounts)==null?void 0:V.call(t).catch(()=>null))??Promise.resolve(null),R=((oe=t.getSubtypeStats)==null?void 0:oe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([K,ee,R]).then(([ce,de,xt])=>{P||(G({works:ce[0].total,books:ce[1].total,collections:ce[2].total,entities:ce[3].total,hasText:de==null?void 0:de.hasText,hasImage:de==null?void 0:de.hasImage}),xt&&ne(xt))})};return t.getCounts?t.getCounts().then(Y=>{var K,ee;P||(G({works:Y.works,books:Y.books,collections:Y.collections,entities:Y.entities,hasText:(K=Y.resourceCounts)==null?void 0:K.hasText,hasImage:(ee=Y.resourceCounts)==null?void 0:ee.hasImage}),Y.subtypeStats&&ne(Y.subtypeStats))}).catch(()=>{P||J()}):J(),()=>{P=!0}},[t]),f.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Q(u))},[u,Q]);const q=f.useCallback(P=>{if(b(P),!P.trim()){x==null||x(P),B(!0),m(null),_(null);return}he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{_(null),x==null||x(P),Q(P)},wo)},[Q,x]),Ye=f.useCallback(P=>{he.current&&clearTimeout(he.current),x==null||x(P),Q(P)},[Q,x]),Ke=f.useCallback(P=>{_(P),Q(y,ko)},[y,Q]);f.useEffect(()=>{if(!H.length){D([]);return}let P=!1;return T(!0),Promise.all(H.slice(0,10).map(async J=>{var Y,K,ee;try{if(t.getEntry){const V=await t.getEntry(J);if(V)return V}const R=await t.getItem(J);if(R){const V=R.authors;return{id:J,title:R.title||J,type:R.type||"work",author:(Y=V==null?void 0:V[0])==null?void 0:Y.name,dynasty:(K=V==null?void 0:V[0])==null?void 0:K.dynasty,role:(ee=V==null?void 0:V[0])==null?void 0:ee.role,edition:R.edition||void 0}}}catch{}return{id:J,title:J,type:"work",notFound:!0}})).then(J=>{P||(D(J),T(!1))}),()=>{P=!0}},[H,t]);const we=P=>{z(P.id),_o(P.id),M(Be()),r==null||r(P)},_e=P=>{Co(P),M(Be())},Je=()=>{zo(),M([])},Me=P=>h.find(J=>J.type===P),qe=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:p.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!d&&e.jsx(rn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(sn,{transport:t,value:y,onChange:q,onSearch:Ye,onEntrySelect:we}),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:p.action.newEntry})]}),U&&C&&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:Z?e.jsxs(e.Fragment,{children:[(Z.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()})," 本"]}),Z.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.article.toLocaleString()})," 篇"]}):null,Z.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()}),U.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.entities.toLocaleString()})]})]})}),U.hasImage!=null&&U.hasText!=null&&e.jsxs("span",{children:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:v?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.searching}):E?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:E})]}):C?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.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:p.search.recentBrowse}),e.jsx("button",{onClick:Je,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:p.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,O?10:3).map(P=>P.notFound?e.jsx(To,{id:P.id,onRemove:_e,t:p},P.id):e.jsx(jt,{entry:P,selected:S===P.id,onClick:we,getConfig:Me,onRemove:_e},P.id))}),!O&&$.length>3&&e.jsx("button",{onClick:()=>W(!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:p.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:p.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.searchSubtitle})]})}):qe?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:P,icon:J,name:Y,key:K})=>{const ee=j[K]??[],R=Io[K],V=j[R]??0;if(ee.length===0)return null;const ce=!(k===P)&&V>Xe;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:[J," ",Y,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[V," ",p.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>Ke(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:p.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ee.map(de=>e.jsx(jt,{entry:de,selected:S===de.id,onClick:we,getConfig:Me,query:y},de.id))})]},P)})}):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:Ae(p.search.noResultsFor,{query:y})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},jt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const a=A(),{convert:c}=F(),l=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&l.length?l.find(u=>{const x=typeof u=="string"?u:u==null?void 0:u.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:a.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:a.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[a.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:u=>{u.stopPropagation(),i(t.id)},title:a.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},To=({id:t,onRemove:n,t:o})=>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:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Ro(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 Eo({data:t}){const{convert:n}=F(),{dynasty:o,birth_year:r,death_year:s}=t,i=[];return o&&i.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?i.push(`${r}—${s}`):r!==void 0?i.push(`${r}—?`):s!==void 0&&i.push(`?—${s}`),i.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:i.join(" ")})}function Lo({alt_names:t}){const{convert:n}=F(),o=new Map;for(const i of t){const a=i.type||"別名";o.has(a)||o.set(a,[]),o.get(a).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,a)=>{const c=r.indexOf(i),l=r.indexOf(a);return c===-1&&l===-1?0:c===-1?1:l===-1?-1:c-l});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const a=o.get(i);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:i}),e.jsx("span",{children:a.map((c,l)=>e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},l))})]},i)})})}function Bo({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.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")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function Wo({works:t,transport:n,onNavigate:o,renderLink:r}){const s=A(),{convert:i}=F(),a=ae(),[c,l]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const p=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(p);let _=!0;for(let v=0;v<p.length;v++){const w=k[v];w!=null&&w.title?y.set(p[v],w.title):w!=null&&w.primary_name?y.set(p[v],w.primary_name):_=!1}if(_)return y}catch{}const b=[...p],j=8,m=new Array(j).fill(0).map(async()=>{for(;b.length;){const k=b.shift();if(!k)break;if(!y.has(k))try{if(n.getEntry){const w=await n.getEntry(k);if(w!=null&&w.title){y.set(k,w.title);continue}}const _=await n.getItem(k),v=_&&(_.title||_.primary_name)||k;y.set(k,v)}catch{y.set(k,k)}}});return await Promise.all(m),y})().then(y=>{g||l(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const p=g.role||"";d.has(p)||d.set(p,[]),d.get(p).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((g,p)=>{const h=u.indexOf(g),y=u.indexOf(p);return h===-1&&y===-1?g.localeCompare(p):h===-1?1:y===-1?-1:h-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(g=>{const p=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:[i(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((h,y)=>{const b=i(c.get(h.work_id)||h.work_id);return r?e.jsx("li",{children:r(h.work_id,b)},y):o?e.jsx("li",{children:e.jsx("a",{href:a(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),o(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:b})},y):e.jsx("li",{children:b},y)})})]},g)})]})}const ln=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var u;const i=A(),{convert:a}=F();let c=!1;try{c=N.extractStatus(t.id)==="draft"}catch{}const l=Ro(t),d=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{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:[a(t.primary_name),e.jsx(Eo,{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:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:i.indexType.entity}),d&&t.subtype!=="people"&&e.jsx("span",{children:d}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),l&&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(Lo,{alt_names:t.alt_names}),e.jsx(Bo,{data:t}),((u=t.description)==null?void 0:u.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:a(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Wo,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},an={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})},$o={...an,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},rt=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=F(),i=n?$o:an;return e.jsx("div",{className:r,style:o,children:e.jsx(Nn,{remarkPlugins:[Gn],components:i,children:s(t)})})},Po=["〇","一","二","三","四","五","六","七","八","九"],St=["","十","百","千"];function cn(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",s=!1;for(let i=0;i<o;i++){const a=parseInt(n[i]),c=o-1-i;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&i===0?r+=St[c]:r+=Po[a]+St[c])}return r}function Ao({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function Mo({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function Fo({id:t}){const n=A(),[o,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#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:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ie({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 xe({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 dn({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,a)=>{const c=s(i.name),l=i.entity_id?e.jsx(le,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(i.dynasty),"〕"]}),l,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},a)})})}function le({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Ho({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:a,meta:c,headerExtra:l,onNavigate:d,renderLink:u}){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,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),l&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:l})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Ao,{type:r}),e.jsx(Mo,{isDraft:s}),e.jsx(Fo,{id:t})]}),((i==null?void 0:i.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(dn,{authors:i,type:r,onNavigate:d,renderLink:u}),c]})]})}function pn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=A(),{convert:a}=F();if(!t.length)return null;const[c,l]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const x=c===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>l(x?null:u),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(d.source)}),!x&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(le,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(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(xe,{label:i.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(xe,{label:i.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(xe,{label:i.label.edition,children:a(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function Oo({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function xn({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function un({label:t,items:n}){const{convert:o}=F();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const i=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(i)},s)})})]}):null}function Do({items:t}){const n=A();return e.jsx(un,{label:n.section.aliases,items:t})}function Vo({items:t}){const n=A();return e.jsx(un,{label:n.section.attachedTexts,items:t})}function Uo({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function No({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Go({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},s))})]}):null}function kt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=F(),[a,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let l=!1;return Promise.all(n.map(d=>o.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{l||c(d)}),()=>{l=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(l=>({id:l}))).map(l=>{const d=l.edition?`${i(l.title)||l.id}(${i(l.edition)})`:i(l.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(le,{id:l.id,label:d,onNavigate:r,renderLink:s})},l.id)})})]}):null}function Ze({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F(),[i,a]=f.useState(!1),c=t.resources&&t.resources.length>0,l=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!i?"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(le,{id:t.id,label:l,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(lt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Yo({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const a=A(),{convert:c}=F(),[l,d]=f.useState([]);if(f.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(y=>({id:y})));return}let h=!1;return Promise.all(t.map(y=>o.getItem(y).then(b=>({id:y,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0})).catch(()=>({id:y})))).then(y=>{h||d(y)}),()=>{h=!0}},[t,o]),!t.length)return null;const u=l.length?l:t.map(h=>({id:h})),x=new Map(u.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,p=Ko(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i,p.useGrouping?e.jsxs(e.Fragment,{children:[p.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.coreIds.map(h=>{const y=x.get(h);return y?e.jsx(Ze,{book:y,onNavigate:r,renderLink:s},h):null})}),p.groupedIds.map(h=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(y=>{const b=x.get(y);return b?e.jsx(Ze,{book:b,onNavigate:r,renderLink:s},y):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(h=>e.jsx(Ze,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function Ko(t,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(b=n.collections)==null?void 0:b[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],i=r.length>0||s.length>0,a=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const k=n.node_groups[m];return k!=null&&c.has(k)},u=[],x=new Map,g=[];for(const m of t)if(!((j=n.excluded_books)!=null&&j.includes(m)))if(d(m))u.push(m);else{const k=n.node_groups[m];k?(x.has(k)||x.set(k,[]),x.get(k).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,k)=>m+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,k])=>{const _=h.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:k}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:y}}function Jo({workData:t,onNavigate:n,renderLink:o}){var a,c,l,d;const r=A(),{convert:s}=F(),i=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:i?"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(le,{id:t.id,label:s(t.title),onNavigate:n,renderLink:o})}),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:[cn(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(dn,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((l=t.description)==null?void 0:l.text)&&e.jsx(rt,{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(xe,{label:r.label.parentWork,children:e.jsx(le,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function qo({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(le,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:o}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ae(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const at=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:a,className:c,style:l})=>{var B,H,M,$,D,L;const d=A(),{convert:u}=F(),[x,g]=f.useState(null),[p,h]=f.useState(!1),[y,b]=f.useState(null),[j,m]=f.useState(null),[k,_]=f.useState([]),v=t||x;if(f.useEffect(()=>{if(t||!n||!o)return;let T=!1;return h(!0),b(null),o.getItem(n).then(O=>{T||(O?g(O):b(d.misc.notFoundEntry))}).catch(O=>{T||b(O instanceof Error?O.message:d.misc.loadFailed)}).finally(()=>{T||h(!1)}),()=>{T=!0}},[t,n,o]),f.useEffect(()=>{if(!v||!o){m(null),_([]);return}let T=!1;const O=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(O?o.getItem(O).then(W=>{!T&&W&&W.type==="work"&&m(W)}).catch(()=>{}):m(null),v.type==="book"){const W=v;W.contained_in&&W.contained_in.length>0?Promise.all(W.contained_in.map(U=>{const G=typeof U=="string"?U:U.id,Z=typeof U=="string"?void 0:U.volume_index;return o.getItem(G).then(ne=>({id:G,title:ne&&ne.title||G,volume_index:Z})).catch(()=>({id:G,title:G,volume_index:Z}))})).then(U=>{T||_(U)}):_([])}else _([]);return()=>{T=!0}},[v,o]),p)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((T,O)=>e.jsx("div",{style:{height:O===1?"32px":"16px",width:`${T}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},O))})});if(y)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!v)return null;if(v.type==="entity")return e.jsx("div",{className:c,style:l,children:e.jsx(ln,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const w=v.type==="book"?v:null,S=v.type==="collection"?v:null,z=v.type==="work"?v:null;let E=!1;try{E=N.extractStatus(v.id)==="draft"}catch{}let I="";v.measure_info?I=u(v.measure_info):(B=v.juan_count)!=null&&B.number?I=cn(v.juan_count.number)+d.unit.juan:(H=v.juan_count)!=null&&H.description&&(I=u(v.juan_count.description));const C=[];return(M=v.publication_info)!=null&&M.year&&C.push(e.jsx(xe,{label:d.label.year,children:v.publication_info.year},"year")),($=v.current_location)!=null&&$.name&&C.push(e.jsx(xe,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(D=v.page_count)!=null&&D.description&&C.push(e.jsx(xe,{label:d.label.pageCount,children:v.page_count.description},"page")),w!=null&&w.edition&&C.push(e.jsx(xe,{label:d.label.edition,children:u(w.edition)},"ver")),z!=null&&z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:e.jsx(le,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:z.parent_works.map((T,O)=>e.jsxs("span",{children:[O>0&&"、",e.jsx(le,{id:T,onNavigate:r,renderLink:s})]},T))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(Ho,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:E,authors:v.authors,volumeText:I,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=v.description)==null?void 0:L.text)&&e.jsx(rt,{text:v.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((T,O)=>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:u(T.title)}),e.jsx(rt,{text:T.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},O))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.containedIn}),e.jsx(qo,{items:k,onNavigate:r,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.belongsToWork}),e.jsx(Jo,{workData:j,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&e.jsx(Uo,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&e.jsx(Do,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&e.jsx(Vo,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&e.jsx(Oo,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&e.jsx(xn,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.resources}),e.jsx(lt,{items:v.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(No,{items:w.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Go,{items:S.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(kt,{title:d.section.relatedVersions,ids:w.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(kt,{title:d.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ie,{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(T=>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(le,{id:T.id,label:u(T.title),onNavigate:r,renderLink:s})},T.id))})]}),(z==null?void 0:z.books)&&z.books.length>0&&e.jsx(Yo,{ids:z.books,workData:z,transport:o,onNavigate:r,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const T=[],O=z.related_works.filter(G=>G.relation==="part_of"),W=z.related_works.filter(G=>G.relation==="has_part"),U=z.related_works.filter(G=>!G.relation);return O.length>0&&T.push({label:d.section.belongsToWork,items:O}),W.length>0&&T.push({label:d.section.containedWorks,items:W}),U.length>0&&T.push({label:d.section.relatedWorks,items:U}),T.map(G=>e.jsxs("div",{children:[e.jsxs(ie,{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(Z=>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(le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},G.label))})()]})};function Xo({data:t}){const n=A(),{convert:o}=F(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,i=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:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(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]}),i!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",i,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Zo({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:wt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:wt(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 wt(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 Qo({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(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:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function er(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function _t({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=A(),{convert:i}=F(),a=t.book_id||t.work_id,c=r&&t.volumes.length>0?er(t.volumes,s.unit.volume):null,l=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(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=>i(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:l?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(Qo,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const fn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:a})=>{const c=A(),[l,d]=f.useState(null),[u,x]=f.useState(!1),[g,p]=f.useState(null),[h,y]=f.useState(null),[b,j]=f.useState(""),m=t||l;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return x(!0),p(null),o.getCollectionCatalog(n).then(z=>{S||(z?d(z):p(c.catalog.notFound))}).catch(z=>{S||p(z instanceof Error?z.message:c.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o,c]);const k=(m==null?void 0:m.sections)&&m.sections.length>0,_=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const S=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[m]),v=f.useMemo(()=>{if(!m)return[];let S=m.books;if(h&&(S=S.filter(z=>z.section===h)),b.trim()){const z=b.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(z)||E.sub_items&&E.sub_items.some(I=>I.toLowerCase().includes(z))||E.edition&&E.edition.toLowerCase().includes(z))}return S},[m,h,b]),w=f.useMemo(()=>{if(!_)return null;const S=[],z=new Map;for(const I of v){if(!I.volumes||I.volumes.length===0)continue;const C=I.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(I)}const E=[...z.keys()].sort((I,C)=>I-C);for(const I of E)S.push({volume:I,books:z.get(I)});return S},[v,_]);return u?e.jsx("div",{className:i,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:i,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:i,style:a,children:[e.jsx(Xo,{data:m}),k&&e.jsx(Zo,{sections:m.sections,activeSection:h,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:b,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:[v.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((S,z)=>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:Ae(c.catalog.volume,{n:S.volume})}),S.books.map((E,I)=>e.jsx(_t,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${S.volume}-${I}`))]},`${S.volume}-${z}`)):v.map((S,z)=>e.jsx(_t,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},ye=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},te=6,Fe=7,tr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[a,c]=f.useState(!1),[l,d]=f.useState(null),u=f.useRef(null),x=f.useRef(null),g=f.useRef(null),p=f.useCallback(()=>{const b=x.current,j=g.current;if(!b||!j)return;const m=b.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,v=document.documentElement.clientWidth;let w=o;o==="top"&&m.top-k.height-Fe<8&&(w="bottom"),o==="bottom"&&m.bottom+k.height+Fe>_-8&&(w="top");const S=w==="top"?m.top-k.height-Fe:m.bottom+Fe;let z=m.left+m.width/2-k.width/2;z=Math.max(8,Math.min(z,v-k.width-8)),d({left:z,top:S,placement:w})},[o]),h=f.useCallback(()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!0),r)},[r]),y=f.useCallback(()=>{u.current&&clearTimeout(u.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!a)return;const b=requestAnimationFrame(p);return()=>cancelAnimationFrame(b)},[a,p]),f.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:h,onMouseLeave:y,onFocus:h,onBlur:y,style:{display:"inline-block",...i},children:n}),a&&Yn.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(l==null?void 0:l.left)??-9999,top:(l==null?void 0:l.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:l?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-te,width:0,height:0,...l.placement==="top"?{bottom:-te,borderTop:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}:{top:-te,borderBottom:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...l.placement==="top"?{bottom:-5,borderTop:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}:{top:-5,borderBottom:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}}})]})]}),document.body)]})},Ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function nr(t){return typeof t!="string"?null:t in tn?t:t in Ct?Ct[t]:null}const or={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function X(t){return typeof t!="string"?"":or[t]??t}const rr=["〇","一","二","三","四","五","六","七","八","九"],zt=["","十","百","千"],ir=["","萬","億"];function gn(t){if(t===0)return"〇";if(t<0)return`負${gn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(sr(s,r>0)+ir[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function sr(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let i=0;i<o.length;i++){const a=o[i],c=o.length-1-i;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&c===1&&i===0&&!n?s+=zt[c]:s+=rr[a]+zt[c]}return s.replace(/〇$/,"")}let We=null,He=null;const Ue=new Set;function lr(){return We?Promise.resolve():He||(He=import("opencc-js/t2cn").then(t=>{We=t.Converter({from:"tw",to:"cn"}),Ue.forEach(n=>n())}).catch(()=>{We=t=>t,Ue.forEach(t=>t())}),He)}function fe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(We)return;const n=()=>t(o=>o+1);return Ue.add(n),lr(),()=>{Ue.delete(n)}},[]),We??(n=>n)}function Se(t,n){return n(t).toLowerCase()}const ct="#fff59d";function ke(t,n,o){if(!n)return t;const r=Se(n,o);if(!r)return t;const s=Se(t,o);if(s.length!==t.length)return t;const i=[];let a=0,c=0;for(;a<t.length;){const l=s.indexOf(r,a);if(l===-1){i.push(t.slice(a));break}l>a&&i.push(t.slice(a,l)),i.push(e.jsx("mark",{style:{background:ct,padding:0,color:"inherit"},children:t.slice(l,l+r.length)},c++)),a=l+r.length}return e.jsx(e.Fragment,{children:i})}function dt(t,n,o,r){if(!n)return!0;const s=Se(n,r);return(o?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(a=>typeof a=="string"&&Se(a,r).includes(s))}function ar(t,n,o){return n?Se(t,o).includes(Se(n,o)):!0}const pt={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},cr={考证:"#5d6d7e"};function dr(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 hn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,a=s==="loading",c=typeof s=="number"&&s>0,l=dr(t),d=!!(r!=null&&r.vol_label)&&!l.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"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?`${ct}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":i?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:i?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:i?.5:1},children:[l,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function bn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>bn(r,n)))}function mn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+mn(i),0))||0;return n+o}function pr(t,n){const o=[],r=a=>{var c;o.push(...a.files),(c=a.children)==null||c.forEach(r)};if(r(t),o.length===0)return;const s=o.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let i=0;for(const a of s)typeof a=="number"&&(i+=a);return i}function yn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var h;const a=bn(t,n||""),c=pr(t,i),l=typeof c=="number"&&c>0,d=c===0,[u,x]=f.useState(a||l),g=mn(t),p=!!((h=t.children)!=null&&h.length);if(f.useEffect(()=>{a&&x(!0)},[a]),f.useEffect(()=>{l&&x(!0)},[l]),t.files.length===1&&!p){const y=t.files[0],b=n===y,j=i[y],m=j===0,k=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{m||o(y)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:b?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:b?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${ct}40`:"transparent",color:b?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:b?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:j}),k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!u),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:a?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",g,")"]}),l&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),u&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(y=>e.jsx(hn,{file:y,isActive:n===y,onSelect:o,meta:s==null?void 0:s[y],matchState:i[y]},y))}),p&&t.children.map((y,b)=>e.jsx(yn,{group:y,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},b))]})]})}function xr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:s,matchStates:i}){const a=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,l)=>e.jsx(yn,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},l))}):a.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:a.map(c=>e.jsx(hn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function ur({type:t}){const n=pt[t]||"#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 fr({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=F(),s=ae(),i=fe(),a=y=>{if(!y)return"";const b=r(y);return o?ke(b,o,i):b},[c,l]=f.useState(!1),d=!!t.summary,u=!!t.comment,x=!!t.additional_comment,g=!!(t.content&&t.content.length>60),p=d||u||x||g;f.useEffect(()=>{o&&l(!0)},[o]);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:()=>p&&l(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:p?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",a(t.book_title),"》"]}):a(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[gn(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:a(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:a(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&p&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.additional_comment)})]}),g&&!d&&!u&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)})]})]})}function gr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe(),s=l=>{if(!l)return"";const d=o(l);return n?ke(d,n,r):d},[i,a]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&a(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ur,{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:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${pt[t.type]||"#717171"}40`,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 hr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
1
+ "use strict";var Fn=Object.create;var ut=Object.defineProperty;var Hn=Object.getOwnPropertyDescriptor;var On=Object.getOwnPropertyNames;var Dn=Object.getPrototypeOf,Vn=Object.prototype.hasOwnProperty;var Un=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of On(n))!Vn.call(t,s)&&s!==o&&ut(t,s,{get:()=>n[s],enumerable:!(r=Hn(n,s))||r.enumerable});return t};var Ce=(t,n,o)=>(o=t!=null?Fn(Dn(t)):{},Un(n||!t||!t.__esModule?ut(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-BeOfavi5.cjs"),e=require("react/jsx-runtime"),f=require("react"),Nn=require("react-markdown"),Gn=require("remark-gfm"),Yn=require("react-dom"),Kn=t=>`/book-index?id=${t}`,en=f.createContext(Kn);function Jn({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(en.Provider,{value:o,children:n})}function ae(){return f.useContext(en)}function be(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function qn(t,n){return be(t).includes(n)}const tn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Xn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Zn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},Pe=f.createContext(null),nn={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:"包含作品"},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:"·目錄"},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:"圖片資源"}},Qn={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:"包含作品"},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:"·目录"},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:"图片资源"}},eo={"zh-Hant":nn,"zh-Hans":Qn},on="bim-locale";function to(){try{const t=localStorage.getItem(on);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function no(t){try{localStorage.setItem(on,t)}catch{}}const oo="zh-Hans",ro=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=f.useState(t??oo),i=t??r;f.useEffect(()=>{if(t)return;const u=to();u&&u!==r&&s(u)},[]);const[a,c]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const x=u.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>u=>u)}):c(null)},[i]);const l=f.useCallback(u=>{s(u),no(u),n==null||n(u)},[n]),d=f.useMemo(()=>({locale:i,setLocale:l,messages:eo[i],converter:a}),[i,l,a]);return e.jsx(Pe.Provider,{value:d,children:o})};function A(){const t=f.useContext(Pe);return(t==null?void 0:t.messages)??nn}const io=2e3;function F(){const t=f.useContext(Pe),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=f.useCallback(a=>{if(!a)return"";if(!o)return a;const c=r.current.get(a);if(c!==void 0)return c;const l=o(a);if(r.current.size>=io){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,l),l},[o]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Ae(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function so(t){if(!t)return"";try{const n=new URL(t).hostname,o={"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(o[n])return o[n];const r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function lo(){return{id:"",name:"",url:"",type:"text",details:""}}const nt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=A(),[a,c]=f.useState(null),l=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],d=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],u=m=>{if(!s)return!0;const k=be(m);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},x=t.map((m,k)=>({item:m,originalIndex:k})).filter(({item:m})=>u(m)),g=()=>{const m=lo();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((k,_)=>_!==m)),c(null)},h=(m,k,_)=>{const v=[...t];if(v[m]={...v[m],[k]:_},k==="url"&&!v[m].id){const w=so(_);w&&(v[m].id=w)}n(v)},y=(m,k,_)=>{const w={...t[m].metadata||{}};_?w[k]=_:delete w[k],h(m,"metadata",Object.keys(w).length>0?w:void 0)},b=(m,k)=>{const _=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;h(m,"structure",_)},j=(m,k,_)=>{const w=t[m].coverage||{level:1,ranges:""};k==="level"?w.level=parseInt(_)||1:w.ranges=_,h(m,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:k})=>{var _,v,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(a===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:ao(m.type??"text"),color:"#fff"},children:(()=>{var z,E;const S=be(m);return S.length===0?m.type??"text":S.length===1?((z=l.find(I=>I.value===S[0]))==null?void 0:z.label)??S[0]:S.includes("text")&&S.includes("image")?((E=l.find(I=>I.value==="text+image"))==null?void 0:E.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${k+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&co(k,r==null?void 0:r[k],o,i),e.jsx("button",{onClick:S=>{S.stopPropagation(),p(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),a===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[qn(m,"image")&&m.url&&po(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.type}),e.jsx("select",{value:m.type,onChange:S=>h(k,"type",S.target.value),style:{...pe,flex:1},children:l.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:S=>h(k,"root_type",S.target.value),style:{...pe,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:m.id,onChange:S=>h(k,"id",S.target.value),placeholder:i.editor.idAutoExtract,style:{...pe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:S=>h(k,"name",S.target.value),placeholder:i.editor.resourceName,style:{...pe,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:S=>h(k,"url",S.target.value),placeholder:i.editor.resourceUrl,style:pe}),e.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:S=>b(k,S.target.value),placeholder:i.editor.structurePlaceholder,style:pe}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((v=m.coverage)==null?void 0:v.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...pe,width:"60px"}})]}),e.jsxs("label",{style:{...ze,flex:1},children:[e.jsx("span",{style:Ie,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...pe,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:i.editor.detailsPlaceholder,style:{...pe,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:i.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(i.metadata).map(([S,z])=>{var E;return e.jsxs("label",{style:{...ze,gap:"4px"},children:[e.jsx("span",{style:{...Ie,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[S])||"",onChange:I=>y(k,S,I.target.value),placeholder:z,style:{...pe,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:i.action.addResource})]})]})};function ao(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function co(t,n,o,r){const s=(n==null?void 0:n.status)==="downloading",i=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||o(t,"")},disabled:s,style:{background:"transparent",border:"none",color:i?"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:i?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:i?"✓":s?"⏳":"⬇"})}function po(t,n){const o=/\.(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:o?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"#00000010"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"#00000010",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const pe={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"},ze={display:"flex",alignItems:"center",gap:"6px"},Ie={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},xo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function uo(t){try{const n=new URL(t).hostname;return xo[n]}catch{return}}const ft={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function fo(t){return t.includes("text")&&t.includes("image")?ft["text+image"]:ft[t[0]||"physical"]}const gt={text:0,image:1,physical:2};function De(t){return t.length===0?"physical":[...t].sort((n,o)=>(gt[n]??99)-(gt[o]??99)).join("+")}function go(t){const n=i=>{const a=i.match(/^(.+?)·第(\d+)[冊册]$/);if(a)return[a[1],parseInt(a[2])];const c=i.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const a=t[i];if(a.volumes&&a.volumes.length>0)continue;const c=n(a.name);if(!c)continue;const[l,d]=c,u=`${l}|${De(be(a))}`;o.has(u)||o.set(u,{base:{...a,name:l,url:"",volumes:[]},volumes:[]}),o.get(u).volumes.push({volume:d,url:a.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((a,c)=>a.volume-c.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let a=0;a<t.length;a++)if(s.has(a)){const c=n(t[a].name),l=c&&`${c[0]}|${De(be(t[a]))}`,d=`${i.base.name}|${De(be(i.base))}`;l===d&&s.delete(a)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const lt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=A(),i=f.useMemo(()=>go(t||[]),[t]),a={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},c=x=>a[x]?a[x]:x.split("+").map(g=>a[g]||g).join("+");if(!i||i.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:s.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((x,g)=>e.jsx(ht,{item:x},x.id||g))});const l=new Map;for(const x of i){const g=De(be(x));l.has(g)||l.set(g,[]),l.get(g).push(x)}const d=["text","image","text+image","physical"],u=[...d.filter(x=>l.has(x)),...[...l.keys()].filter(x=>!d.includes(x)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:u.map(x=>{const g=l.get(x),p=fo(x.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:p,whiteSpace:"nowrap",flexShrink:0},children:c(x)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:g.map((h,y)=>e.jsx(ht,{item:h,onNavigate:o,renderLink:r},h.id||y))})]},x)})})};function ho(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const s=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(s)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(s[1]))}&page=${n}`;const i=new URL(t);return i.searchParams.set("page",String(n)),i.toString()}return t}catch{return t}}function bo(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const o=n.match(/^(\d+)/);return o?parseInt(o[1],10):void 0}function mo(t){if(t.url)return t.url;for(const[n,o]of Object.entries(t))if(n.endsWith("_url")&&typeof o=="string")return o}const yo={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},ht=({item:t})=>{const n=A(),{convert:o}=F(),[r,s]=f.useState(!1),i=f.useMemo(()=>(t.url?uo(t.url):void 0)||o(t.name),[t.url,t.name,o]),a=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||mo(h)})),[t.volumes]),c=a&&a.length>0,l=c?new Set(a.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(a.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,u=t.expected_volumes??(c?l+d:0),x=t.color_mode?{...yo[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?o(t.details):null,p={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:p,children:[e.jsx("span",{style:{fontWeight:500},children:i}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l,"/",u,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=bo(t.metadata);return h?ho(t.url,h):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(h=>{const y=h.status==="missing";return h.url&&!y?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:h.volume},h.volume)})})]})},rn=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:a})=>{const c=A(),l=t==="local",d=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",x=u?u.split(/[/\\]/).pop()||u:"",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)"},p={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:g,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:g,...p,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:i,title:x||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:l?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...p,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:a,title:u||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!l&&x&&e.jsxs("div",{style:{...g,background:"#2196f3",color:"white",cursor:"default"},title:u,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:x})]})]})},Ge="bim-search-history",bt=10,mt=8;function Le(){try{const t=localStorage.getItem(Ge);return t?JSON.parse(t):[]}catch{return[]}}function vo(t){try{const n=Le().filter(o=>o!==t);n.unshift(t),n.length>bt&&(n.length=bt),localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function jo(t){try{const n=Le().filter(o=>o!==t);localStorage.setItem(Ge,JSON.stringify(n))}catch{}}function So(){try{localStorage.removeItem(Ge)}catch{}}const sn=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const a=A(),c=i??a.search.placeholder,l={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,u]=f.useState(!1),[x,g]=f.useState([]),[p,h]=f.useState(-1),[y,b]=f.useState(Le),j=f.useRef(null),m=f.useRef(null),k=f.useRef(null),_=f.useRef(!1);f.useEffect(()=>{h(-1);const C=n.trim();if(!C){g(y.map(M=>({type:"history",text:M})));return}if(!t.searchAll){g([]);return}let B=!1;const H=setTimeout(()=>{t.searchAll(C,mt).then(M=>{if(B)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];g($.slice(0,mt).map(D=>({type:"entry",text:D.title||D.id,entry:D})))}).catch(()=>{B||g([])})},80);return()=>{B=!0,clearTimeout(H)}},[n,y,t]),f.useEffect(()=>{const C=B=>{k.current&&!k.current.contains(B.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=B=>{var H,M;if(B.key==="/"&&document.activeElement!==j.current){const $=(H=document.activeElement)==null?void 0:H.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;B.preventDefault(),(M=j.current)==null||M.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const v=f.useCallback(C=>{C.trim()&&(vo(C.trim()),b(Le())),r(C),u(!1)},[r]),w=f.useCallback(C=>{C.type==="history"?(o(C.text),v(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),v(C.text)))},[o,v,s]),S=f.useCallback(C=>{if(!d||x.length===0){C.key==="Enter"&&v(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),h(B=>(B+1)%x.length);break;case"ArrowUp":C.preventDefault(),h(B=>(B-1+x.length)%x.length);break;case"Enter":C.preventDefault(),p>=0&&p<x.length?w(x[p]):v(n);break;case"Escape":C.preventDefault(),u(!1);break}},[d,x,p,n,v,w]),z=f.useCallback((C,B)=>{B.stopPropagation(),jo(C),b(Le()),g(H=>H.filter(M=>!(M.type==="history"&&M.text===C)))},[]),E=f.useCallback(C=>{C.stopPropagation(),So(),b([]),g([])},[]);f.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const I=!n.trim()&&y.length>0;return e.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),u(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{u(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((C,B)=>e.jsxs("div",{onClick:()=>w(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:B===p?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[l[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:H=>z(C.text,H),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${C.type}-${C.text}-${B}`))]})]})},$e="bim-recent-ids",yt="bim-recent-entries",vt=50,Xe=5,ko=50,wo=200;function Be(){try{const t=localStorage.getItem($e);if(t)return JSON.parse(t);const n=localStorage.getItem(yt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem($e,JSON.stringify(o)),localStorage.removeItem(yt),o}return[]}catch{return[]}}function _o(t){try{const n=Be().filter(o=>o!==t);n.unshift(t),n.length>vt&&(n.length=vt),localStorage.setItem($e,JSON.stringify(n))}catch{}}function Co(t){try{const n=Be().filter(o=>o!==t);localStorage.setItem($e,JSON.stringify(n))}catch{}}function zo(){try{localStorage.removeItem($e)}catch{}}const Io={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},ot=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l,hideModeIndicator:d,initialQuery:u,onQueryChange:x,headerRight:g})=>{const p=A(),h=[{type:"work",icon:"✍️",name:p.indexType.work,key:"works"},{type:"book",icon:"📖",name:p.indexType.book,key:"books"},{type:"collection",icon:"📚",name:p.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:p.indexType.entity,key:"entities"}],[y,b]=f.useState(u??""),[j,m]=f.useState(null),[k,_]=f.useState(null),[v,w]=f.useState(!1),[S,z]=f.useState(null),[E,I]=f.useState(""),[C,B]=f.useState(!u),[H,M]=f.useState(Be),[$,D]=f.useState([]),[L,T]=f.useState(!1),[O,W]=f.useState(!1),[U,G]=f.useState(null),[Z,ne]=f.useState(null),he=f.useRef(void 0),ge=f.useRef(!1),Q=f.useCallback(async(P,J)=>{if(!P.trim()){B(!0),m(null),_(null);return}B(!1),w(!0),I("");try{if(t.searchAll){const Y=await t.searchAll(P,J??Xe);m(Y)}else{const Y=["work","book","collection","entity"],K=await Promise.all(Y.map(ee=>t.search(P,ee,{page:1,pageSize:J??Xe})));m({works:K[0].entries,books:K[1].entries,collections:K[2].entries,entities:K[3].entries,totalWorks:K[0].total,totalBooks:K[1].total,totalCollections:K[2].total,totalEntities:K[3].total})}}catch(Y){I(Y instanceof Error?Y.message:String(Y)),m(null)}finally{w(!1)}},[t]);f.useEffect(()=>{let P=!1;const J=()=>{var V,oe;const Y=["work","book","collection","entity"],K=Promise.all(Y.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((V=t.getResourceCounts)==null?void 0:V.call(t).catch(()=>null))??Promise.resolve(null),R=((oe=t.getSubtypeStats)==null?void 0:oe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([K,ee,R]).then(([ce,de,xt])=>{P||(G({works:ce[0].total,books:ce[1].total,collections:ce[2].total,entities:ce[3].total,hasText:de==null?void 0:de.hasText,hasImage:de==null?void 0:de.hasImage}),xt&&ne(xt))})};return t.getCounts?t.getCounts().then(Y=>{var K,ee;P||(G({works:Y.works,books:Y.books,collections:Y.collections,entities:Y.entities,hasText:(K=Y.resourceCounts)==null?void 0:K.hasText,hasImage:(ee=Y.resourceCounts)==null?void 0:ee.hasImage}),Y.subtypeStats&&ne(Y.subtypeStats))}).catch(()=>{P||J()}):J(),()=>{P=!0}},[t]),f.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Q(u))},[u,Q]);const q=f.useCallback(P=>{if(b(P),!P.trim()){x==null||x(P),B(!0),m(null),_(null);return}he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{_(null),x==null||x(P),Q(P)},wo)},[Q,x]),Ye=f.useCallback(P=>{he.current&&clearTimeout(he.current),x==null||x(P),Q(P)},[Q,x]),Ke=f.useCallback(P=>{_(P),Q(y,ko)},[y,Q]);f.useEffect(()=>{if(!H.length){D([]);return}let P=!1;return T(!0),Promise.all(H.slice(0,10).map(async J=>{var Y,K,ee;try{if(t.getEntry){const V=await t.getEntry(J);if(V)return V}const R=await t.getItem(J);if(R){const V=R.authors;return{id:J,title:R.title||J,type:R.type||"work",author:(Y=V==null?void 0:V[0])==null?void 0:Y.name,dynasty:(K=V==null?void 0:V[0])==null?void 0:K.dynasty,role:(ee=V==null?void 0:V[0])==null?void 0:ee.role,edition:R.edition||void 0}}}catch{}return{id:J,title:J,type:"work",notFound:!0}})).then(J=>{P||(D(J),T(!1))}),()=>{P=!0}},[H,t]);const we=P=>{z(P.id),_o(P.id),M(Be()),r==null||r(P)},_e=P=>{Co(P),M(Be())},Je=()=>{zo(),M([])},Me=P=>h.find(J=>J.type===P),qe=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:p.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!d&&e.jsx(rn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(sn,{transport:t,value:y,onChange:q,onSearch:Ye,onEntrySelect:we}),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:p.action.newEntry})]}),U&&C&&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:Z?e.jsxs(e.Fragment,{children:[(Z.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()})," 本"]}),Z.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.article.toLocaleString()})," 篇"]}):null,Z.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Z.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[p.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.collections.toLocaleString()}),U.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.entities.toLocaleString()})]})]})}),U.hasImage!=null&&U.hasText!=null&&e.jsxs("span",{children:[p.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),p.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:v?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.search.searching}):E?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:E})]}):C?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:p.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:p.search.recentBrowse}),e.jsx("button",{onClick:Je,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:p.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,O?10:3).map(P=>P.notFound?e.jsx(To,{id:P.id,onRemove:_e,t:p},P.id):e.jsx(jt,{entry:P,selected:S===P.id,onClick:we,getConfig:Me,onRemove:_e},P.id))}),!O&&$.length>3&&e.jsx("button",{onClick:()=>W(!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:p.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:p.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.searchSubtitle})]})}):qe?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:P,icon:J,name:Y,key:K})=>{const ee=j[K]??[],R=Io[K],V=j[R]??0;if(ee.length===0)return null;const ce=!(k===P)&&V>Xe;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:[J," ",Y,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[V," ",p.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>Ke(P),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:p.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ee.map(de=>e.jsx(jt,{entry:de,selected:S===de.id,onClick:we,getConfig:Me,query:y},de.id))})]},P)})}):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:Ae(p.search.noResultsFor,{query:y})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:p.search.tryOther})]})})]})},jt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const a=A(),{convert:c}=F(),l=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&l.length?l.find(u=>{const x=typeof u=="string"?u:u==null?void 0:u.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:a.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:a.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[a.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:u=>{u.stopPropagation(),i(t.id)},title:a.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},To=({id:t,onRemove:n,t:o})=>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:o.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:o.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Ro(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 Eo({data:t}){const{convert:n}=F(),{dynasty:o,birth_year:r,death_year:s}=t,i=[];return o&&i.push(`〔${n(o)}〕`),r!==void 0&&s!==void 0?i.push(`${r}—${s}`):r!==void 0?i.push(`${r}—?`):s!==void 0&&i.push(`?—${s}`),i.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:i.join(" ")})}function Lo({alt_names:t}){const{convert:n}=F(),o=new Map;for(const i of t){const a=i.type||"別名";o.has(a)||o.set(a,[]),o.get(a).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,a)=>{const c=r.indexOf(i),l=r.indexOf(a);return c===-1&&l===-1?0:c===-1?1:l===-1?-1:c-l});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const a=o.get(i);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:i}),e.jsx("span",{children:a.map((c,l)=>e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},l))})]},i)})})}function Bo({data:t}){const n=t.external_ids;if(!n)return null;const o=[];return n.cbdb_id&&o.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")),o.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:o})}function Wo({works:t,transport:n,onNavigate:o,renderLink:r}){const s=A(),{convert:i}=F(),a=ae(),[c,l]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const p=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(p);let _=!0;for(let v=0;v<p.length;v++){const w=k[v];w!=null&&w.title?y.set(p[v],w.title):w!=null&&w.primary_name?y.set(p[v],w.primary_name):_=!1}if(_)return y}catch{}const b=[...p],j=8,m=new Array(j).fill(0).map(async()=>{for(;b.length;){const k=b.shift();if(!k)break;if(!y.has(k))try{if(n.getEntry){const w=await n.getEntry(k);if(w!=null&&w.title){y.set(k,w.title);continue}}const _=await n.getItem(k),v=_&&(_.title||_.primary_name)||k;y.set(k,v)}catch{y.set(k,k)}}});return await Promise.all(m),y})().then(y=>{g||l(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const p=g.role||"";d.has(p)||d.set(p,[]),d.get(p).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((g,p)=>{const h=u.indexOf(g),y=u.indexOf(p);return h===-1&&y===-1?g.localeCompare(p):h===-1?1:y===-1?-1:h-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.map(g=>{const p=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:[i(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((h,y)=>{const b=i(c.get(h.work_id)||h.work_id);return r?e.jsx("li",{children:r(h.work_id,b)},y):o?e.jsx("li",{children:e.jsx("a",{href:a(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),o(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:b})},y):e.jsx("li",{children:b},y)})})]},g)})]})}const ln=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var u;const i=A(),{convert:a}=F();let c=!1;try{c=N.extractStatus(t.id)==="draft"}catch{}const l=Ro(t),d=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{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:[a(t.primary_name),e.jsx(Eo,{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:"#5b3e8e",border:"1px solid #5b3e8e40",borderRadius:"2px",background:"#5b3e8e08"},children:i.indexType.entity}),d&&t.subtype!=="people"&&e.jsx("span",{children:d}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"#fff3cd",border:"1px solid #ffc107",borderRadius:"2px",color:"#856404"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),l&&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(Lo,{alt_names:t.alt_names}),e.jsx(Bo,{data:t}),((u=t.description)==null?void 0:u.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:a(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Wo,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},an={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})},$o={...an,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},rt=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=F(),i=n?$o:an;return e.jsx("div",{className:r,style:o,children:e.jsx(Nn,{remarkPlugins:[Gn],components:i,children:s(t)})})},Po=["〇","一","二","三","四","五","六","七","八","九"],St=["","十","百","千"];function cn(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),o=n.length;let r="",s=!1;for(let i=0;i<o;i++){const a=parseInt(n[i]),c=o-1-i;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&i===0?r+=St[c]:r+=Po[a]+St[c])}return r}function Ao({type:t}){const n=A(),o={book:"#c0392b",work:"#8e6f3e",collection:"#2471a3",entity:"#5b3e8e"};return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:o[t],border:`1px solid ${o[t]}40`,borderRadius:"2px",background:`${o[t]}08`},children:n.indexType[t]})}function Mo({isDraft:t}){const n=A();return e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t?"#e67e22":"#27ae60",border:`1px solid ${t?"#e67e2240":"#27ae6040"}`,borderRadius:"2px",background:t?"#e67e2208":"#27ae6008"},children:t?n.status.draft:n.status.official})}function Fo({id:t}){const n=A(),[o,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"#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:o?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:o?1:.5,transition:"opacity 0.15s"},onMouseEnter:i=>i.currentTarget.style.opacity="1",onMouseLeave:i=>i.currentTarget.style.opacity=o?"1":"0.5",children:o?"✓":"⧉"})]})}function ie({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 xe({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 dn({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=F();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,a)=>{const c=s(i.name),l=i.entity_id?e.jsx(le,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(i.dynasty),"〕"]}),l,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},a)})})}function le({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Ho({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:a,meta:c,headerExtra:l,onNavigate:d,renderLink:u}){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,o&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:o}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),l&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:l})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Ao,{type:r}),e.jsx(Mo,{isDraft:s}),e.jsx(Fo,{id:t})]}),((i==null?void 0:i.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(dn,{authors:i,type:r,onNavigate:d,renderLink:u}),c]})]})}function pn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=A(),{convert:a}=F();if(!t.length)return null;const[c,l]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,u)=>{const x=c===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>l(x?null:u),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(d.source)}),!x&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(le,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),x&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(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(xe,{label:i.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(xe,{label:i.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(xe,{label:i.label.edition,children:a(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},u)})})]})}function Oo({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function xn({items:t,onNavigate:n,renderLink:o}){const r=A();return e.jsx(pn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function un({label:t,items:n}){const{convert:o}=F();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const i=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:o(i)},s)})})]}):null}function Do({items:t}){const n=A();return e.jsx(un,{label:n.section.aliases,items:t})}function Vo({items:t}){const n=A();return e.jsx(un,{label:n.section.attachedTexts,items:t})}function Uo({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",o(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function No({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:o(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:o(r.description)})]},s))]})]}):null}function Go({items:t}){const n=A(),{convert:o}=F();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),o(r)]},s))})]}):null}function kt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=F(),[a,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let l=!1;return Promise.all(n.map(d=>o.getItem(d).then(u=>({id:d,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:d})))).then(d=>{l||c(d)}),()=>{l=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(l=>({id:l}))).map(l=>{const d=l.edition?`${i(l.title)||l.id}(${i(l.edition)})`:i(l.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(le,{id:l.id,label:d,onNavigate:r,renderLink:s})},l.id)})})]}):null}function Ze({book:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F(),[i,a]=f.useState(!1),c=t.resources&&t.resources.length>0,l=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!i?"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(le,{id:t.id,label:l,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(lt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Yo({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const a=A(),{convert:c}=F(),[l,d]=f.useState([]);if(f.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(y=>({id:y})));return}let h=!1;return Promise.all(t.map(y=>o.getItem(y).then(b=>({id:y,title:b?b.title:void 0,edition:b?b.edition:void 0,resources:b?b.resources:void 0})).catch(()=>({id:y})))).then(y=>{h||d(y)}),()=>{h=!0}},[t,o]),!t.length)return null;const u=l.length?l:t.map(h=>({id:h})),x=new Map(u.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,p=Ko(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i,p.useGrouping?e.jsxs(e.Fragment,{children:[p.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.coreIds.map(h=>{const y=x.get(h);return y?e.jsx(Ze,{book:y,onNavigate:r,renderLink:s},h):null})}),p.groupedIds.map(h=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(y=>{const b=x.get(y);return b?e.jsx(Ze,{book:b,onNavigate:r,renderLink:s},y):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.map(h=>e.jsx(Ze,{book:h,onNavigate:r,renderLink:s},h.id))})]})}function Ko(t,n){var b,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(b=n.collections)==null?void 0:b[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],i=r.length>0||s.length>0,a=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const k=n.node_groups[m];return k!=null&&c.has(k)},u=[],x=new Map,g=[];for(const m of t)if(!((j=n.excluded_books)!=null&&j.includes(m)))if(d(m))u.push(m);else{const k=n.node_groups[m];k?(x.has(k)||x.set(k,[]),x.get(k).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,k)=>m+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,k])=>{const _=h.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:k}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:u,groupedIds:y}}function Jo({workData:t,onNavigate:n,renderLink:o}){var a,c,l,d;const r=A(),{convert:s}=F(),i=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:i?"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(le,{id:t.id,label:s(t.title),onNavigate:n,renderLink:o})}),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:[cn(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(dn,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((l=t.description)==null?void 0:l.text)&&e.jsx(rt,{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(xe,{label:r.label.parentWork,children:e.jsx(le,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function qo({items:t,onNavigate:n,renderLink:o}){const r=A(),{convert:s}=F();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid #2471a340",borderRadius:"4px",background:"#2471a308"},children:[e.jsx("span",{style:{fontSize:"11px",color:"#2471a3"},children:r.indexType.collection}),e.jsx(le,{id:i.id,label:s(i.title)||i.id,onNavigate:n,renderLink:o}),i.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ae(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const at=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:a,className:c,style:l})=>{var B,H,M,$,D,L;const d=A(),{convert:u}=F(),[x,g]=f.useState(null),[p,h]=f.useState(!1),[y,b]=f.useState(null),[j,m]=f.useState(null),[k,_]=f.useState([]),v=t||x;if(f.useEffect(()=>{if(t||!n||!o)return;let T=!1;return h(!0),b(null),o.getItem(n).then(O=>{T||(O?g(O):b(d.misc.notFoundEntry))}).catch(O=>{T||b(O instanceof Error?O.message:d.misc.loadFailed)}).finally(()=>{T||h(!1)}),()=>{T=!0}},[t,n,o]),f.useEffect(()=>{if(!v||!o){m(null),_([]);return}let T=!1;const O=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(O?o.getItem(O).then(W=>{!T&&W&&W.type==="work"&&m(W)}).catch(()=>{}):m(null),v.type==="book"){const W=v;W.contained_in&&W.contained_in.length>0?Promise.all(W.contained_in.map(U=>{const G=typeof U=="string"?U:U.id,Z=typeof U=="string"?void 0:U.volume_index;return o.getItem(G).then(ne=>({id:G,title:ne&&ne.title||G,volume_index:Z})).catch(()=>({id:G,title:G,volume_index:Z}))})).then(U=>{T||_(U)}):_([])}else _([]);return()=>{T=!0}},[v,o]),p)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((T,O)=>e.jsx("div",{style:{height:O===1?"32px":"16px",width:`${T}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},O))})});if(y)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!v)return null;if(v.type==="entity")return e.jsx("div",{className:c,style:l,children:e.jsx(ln,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const w=v.type==="book"?v:null,S=v.type==="collection"?v:null,z=v.type==="work"?v:null;let E=!1;try{E=N.extractStatus(v.id)==="draft"}catch{}let I="";v.measure_info?I=u(v.measure_info):(B=v.juan_count)!=null&&B.number?I=cn(v.juan_count.number)+d.unit.juan:(H=v.juan_count)!=null&&H.description&&(I=u(v.juan_count.description));const C=[];return(M=v.publication_info)!=null&&M.year&&C.push(e.jsx(xe,{label:d.label.year,children:v.publication_info.year},"year")),($=v.current_location)!=null&&$.name&&C.push(e.jsx(xe,{label:d.label.currentLocation,children:u(v.current_location.name)},"loc")),(D=v.page_count)!=null&&D.description&&C.push(e.jsx(xe,{label:d.label.pageCount,children:v.page_count.description},"page")),w!=null&&w.edition&&C.push(e.jsx(xe,{label:d.label.edition,children:u(w.edition)},"ver")),z!=null&&z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:e.jsx(le,{id:z.parent_work.id,label:u(z.parent_work.title),onNavigate:r,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(e.jsx(xe,{label:d.label.parentWork,children:z.parent_works.map((T,O)=>e.jsxs("span",{children:[O>0&&"、",e.jsx(le,{id:T,onNavigate:r,renderLink:s})]},T))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(Ho,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:E,authors:v.authors,volumeText:I,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=v.description)==null?void 0:L.text)&&e.jsx(rt,{text:v.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),v.appendix&&v.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:v.appendix.map((T,O)=>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:u(T.title)}),e.jsx(rt,{text:T.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},O))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.containedIn}),e.jsx(qo,{items:k,onNavigate:r,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.belongsToWork}),e.jsx(Jo,{workData:j,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&e.jsx(Uo,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&e.jsx(Do,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&e.jsx(Vo,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&e.jsx(Oo,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&e.jsx(xn,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:d.section.resources}),e.jsx(lt,{items:v.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(No,{items:w.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Go,{items:S.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(kt,{title:d.section.relatedVersions,ids:w.related_books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(kt,{title:d.section.containedBooks,ids:S.books,transport:o,onNavigate:r,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ie,{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(T=>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(le,{id:T.id,label:u(T.title),onNavigate:r,renderLink:s})},T.id))})]}),(z==null?void 0:z.books)&&z.books.length>0&&e.jsx(Yo,{ids:z.books,workData:z,transport:o,onNavigate:r,renderLink:s,footer:a}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const T=[],O=z.related_works.filter(G=>G.relation==="part_of"),W=z.related_works.filter(G=>G.relation==="has_part"),U=z.related_works.filter(G=>!G.relation);return O.length>0&&T.push({label:d.section.belongsToWork,items:O}),W.length>0&&T.push({label:d.section.containedWorks,items:W}),U.length>0&&T.push({label:d.section.relatedWorks,items:U}),T.map(G=>e.jsxs("div",{children:[e.jsxs(ie,{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(Z=>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(le,{id:Z.id,label:u(Z.title),onNavigate:r,renderLink:s})},Z.id))})]},G.label))})()]})};function Xo({data:t}){const n=A(),{convert:o}=F(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,i=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:o(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:o(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]}),i!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",i,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"#e67e22"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Zo({sections:t,activeSection:n,onSelect:o}){const r=A();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:wt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:wt(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 wt(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 Qo({id:t,label:n,onNavigate:o,renderLink:r}){const s=ae();return r?e.jsx(e.Fragment,{children:r(t,n)}):o?e.jsx("a",{href:s(t),onClick:i=>{i.metaKey||i.ctrlKey||(i.preventDefault(),o(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:i=>i.currentTarget.style.borderBottomStyle="solid",onMouseLeave:i=>i.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function er(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const o=t[0],r=t[t.length-1];return r-o+1===t.length?`${o}–${r}`:t.length<=3?t.join(", "):`${o}–${r} (${t.length}${n})`}function _t({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=A(),{convert:i}=F(),a=t.book_id||t.work_id,c=r&&t.volumes.length>0?er(t.volumes,s.unit.volume):null,l=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(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=>i(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:l?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(Qo,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const fn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:a})=>{const c=A(),[l,d]=f.useState(null),[u,x]=f.useState(!1),[g,p]=f.useState(null),[h,y]=f.useState(null),[b,j]=f.useState(""),m=t||l;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let S=!1;return x(!0),p(null),o.getCollectionCatalog(n).then(z=>{S||(z?d(z):p(c.catalog.notFound))}).catch(z=>{S||p(z instanceof Error?z.message:c.catalog.loadFailed)}).finally(()=>{S||x(!1)}),()=>{S=!0}},[t,n,o,c]);const k=(m==null?void 0:m.sections)&&m.sections.length>0,_=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const S=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(S).size<S.length},[m]),v=f.useMemo(()=>{if(!m)return[];let S=m.books;if(h&&(S=S.filter(z=>z.section===h)),b.trim()){const z=b.trim().toLowerCase();S=S.filter(E=>E.title.toLowerCase().includes(z)||E.sub_items&&E.sub_items.some(I=>I.toLowerCase().includes(z))||E.edition&&E.edition.toLowerCase().includes(z))}return S},[m,h,b]),w=f.useMemo(()=>{if(!_)return null;const S=[],z=new Map;for(const I of v){if(!I.volumes||I.volumes.length===0)continue;const C=I.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(I)}const E=[...z.keys()].sort((I,C)=>I-C);for(const I of E)S.push({volume:I,books:z.get(I)});return S},[v,_]);return u?e.jsx("div",{className:i,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:i,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:i,style:a,children:[e.jsx(Xo,{data:m}),k&&e.jsx(Zo,{sections:m.sections,activeSection:h,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:b,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:[v.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((S,z)=>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:Ae(c.catalog.volume,{n:S.volume})}),S.books.map((E,I)=>e.jsx(_t,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${S.volume}-${I}`))]},`${S.volume}-${z}`)):v.map((S,z)=>e.jsx(_t,{book:S,onNavigate:r,renderLink:s,showVolumes:!0},z)),v.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},ye=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const o=setInterval(()=>n(r=>r>=3?1:r+1),500);return()=>clearInterval(o)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},te=6,Fe=7,tr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[a,c]=f.useState(!1),[l,d]=f.useState(null),u=f.useRef(null),x=f.useRef(null),g=f.useRef(null),p=f.useCallback(()=>{const b=x.current,j=g.current;if(!b||!j)return;const m=b.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,v=document.documentElement.clientWidth;let w=o;o==="top"&&m.top-k.height-Fe<8&&(w="bottom"),o==="bottom"&&m.bottom+k.height+Fe>_-8&&(w="top");const S=w==="top"?m.top-k.height-Fe:m.bottom+Fe;let z=m.left+m.width/2-k.width/2;z=Math.max(8,Math.min(z,v-k.width-8)),d({left:z,top:S,placement:w})},[o]),h=f.useCallback(()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!0),r)},[r]),y=f.useCallback(()=>{u.current&&clearTimeout(u.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!a)return;const b=requestAnimationFrame(p);return()=>cancelAnimationFrame(b)},[a,p]),f.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:h,onMouseLeave:y,onFocus:h,onBlur:y,style:{display:"inline-block",...i},children:n}),a&&Yn.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(l==null?void 0:l.left)??-9999,top:(l==null?void 0:l.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:l?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-te,width:0,height:0,...l.placement==="top"?{bottom:-te,borderTop:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}:{top:-te,borderBottom:`${te}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${te}px solid transparent`,borderRight:`${te}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...l.placement==="top"?{bottom:-5,borderTop:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}:{top:-5,borderBottom:`${te-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${te-1}px solid transparent`,borderRight:`${te-1}px solid transparent`}}})]})]}),document.body)]})},Ct={A:"fine",B:"rough",C:"rough",D:"ocr"};function nr(t){return typeof t!="string"?null:t in tn?t:t in Ct?Ct[t]:null}const or={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function X(t){return typeof t!="string"?"":or[t]??t}const rr=["〇","一","二","三","四","五","六","七","八","九"],zt=["","十","百","千"],ir=["","萬","億"];function gn(t){if(t===0)return"〇";if(t<0)return`負${gn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(sr(s,r>0)+ir[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function sr(t,n){const o=[];let r=t;for(;r>0;)o.unshift(r%10),r=Math.floor(r/10);let s="";for(let i=0;i<o.length;i++){const a=o[i],c=o.length-1-i;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&c===1&&i===0&&!n?s+=zt[c]:s+=rr[a]+zt[c]}return s.replace(/〇$/,"")}let We=null,He=null;const Ue=new Set;function lr(){return We?Promise.resolve():He||(He=import("opencc-js/t2cn").then(t=>{We=t.Converter({from:"tw",to:"cn"}),Ue.forEach(n=>n())}).catch(()=>{We=t=>t,Ue.forEach(t=>t())}),He)}function fe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(We)return;const n=()=>t(o=>o+1);return Ue.add(n),lr(),()=>{Ue.delete(n)}},[]),We??(n=>n)}function Se(t,n){return n(t).toLowerCase()}const ct="#fff59d";function ke(t,n,o){if(!n)return t;const r=Se(n,o);if(!r)return t;const s=Se(t,o);if(s.length!==t.length)return t;const i=[];let a=0,c=0;for(;a<t.length;){const l=s.indexOf(r,a);if(l===-1){i.push(t.slice(a));break}l>a&&i.push(t.slice(a,l)),i.push(e.jsx("mark",{style:{background:ct,padding:0,color:"inherit"},children:t.slice(l,l+r.length)},c++)),a=l+r.length}return e.jsx(e.Fragment,{children:i})}function dt(t,n,o,r){if(!n)return!0;const s=Se(n,r);return(o?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(a=>typeof a=="string"&&Se(a,r).includes(s))}function ar(t,n,o){return n?Se(t,o).includes(Se(n,o)):!0}const pt={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},cr={考证:"#5d6d7e"};function dr(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 hn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,a=s==="loading",c=typeof s=="number"&&s>0,l=dr(t),d=!!(r!=null&&r.vol_label)&&!l.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"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?`${ct}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":i?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:i?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:i?.5:1},children:[l,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function bn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>bn(r,n)))}function mn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+mn(i),0))||0;return n+o}function pr(t,n){const o=[],r=a=>{var c;o.push(...a.files),(c=a.children)==null||c.forEach(r)};if(r(t),o.length===0)return;const s=o.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let i=0;for(const a of s)typeof a=="number"&&(i+=a);return i}function yn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var h;const a=bn(t,n||""),c=pr(t,i),l=typeof c=="number"&&c>0,d=c===0,[u,x]=f.useState(a||l),g=mn(t),p=!!((h=t.children)!=null&&h.length);if(f.useEffect(()=>{a&&x(!0)},[a]),f.useEffect(()=>{l&&x(!0)},[l]),t.files.length===1&&!p){const y=t.files[0],b=n===y,j=i[y],m=j===0,k=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{m||o(y)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:b?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:b?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${ct}40`:"transparent",color:b?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:b?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:j}),k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>x(!u),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:a?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:u?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",g,")"]}),l&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),u&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(y=>e.jsx(hn,{file:y,isActive:n===y,onSelect:o,meta:s==null?void 0:s[y],matchState:i[y]},y))}),p&&t.children.map((y,b)=>e.jsx(yn,{group:y,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},b))]})]})}function xr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:s,matchStates:i}){const a=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,l)=>e.jsx(yn,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},l))}):a.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:a.map(c=>e.jsx(hn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function ur({type:t}){const n=pt[t]||"#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 fr({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=F(),s=ae(),i=fe(),a=y=>{if(!y)return"";const b=r(y);return o?ke(b,o,i):b},[c,l]=f.useState(!1),d=!!t.summary,u=!!t.comment,x=!!t.additional_comment,g=!!(t.content&&t.content.length>60),p=d||u||x||g;f.useEffect(()=>{o&&l(!0)},[o]);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:()=>p&&l(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:p?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",a(t.book_title),"》"]}):a(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[gn(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:a(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:a(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&p&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.additional_comment)})]}),g&&!d&&!u&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)})]})]})}function gr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe(),s=l=>{if(!l)return"";const d=o(l);return n?ke(d,n,r):d},[i,a]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&a(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ur,{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:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${pt[t.type]||"#717171"}40`,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 hr({section:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
2
2
  `)),i=n?ke(s,n,r):s,a=pt[t.type]||"#717171",c=X(t.type)==="序"||X(t.type)==="结语";return e.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${a}40`:void 0,background:c?"var(--bim-bg, #fafafa)":void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:a,marginRight:"8px",padding:"1px 5px",border:`1px solid ${a}40`,borderRadius:"2px",background:`${a}08`,verticalAlign:"middle"},children:t.type}),i]})}function br(t,n,o){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||t.length===0)return;let i=!1;const a=t.filter(u=>{var x;return!((x=o==null?void 0:o.current)!=null&&x.has(u))}),c={};for(const u of t)(d=o==null?void 0:o.current)!=null&&d.has(u)&&(c[u]=o.current.get(u));if(Object.keys(c).length>0&&s(c),a.length===0)return;const l=async u=>{var x;try{if(n.getEntry){const b=await n.getEntry(u);if(b)return{title:b.title,author:b.author}}const g=await n.getItem(u);if(!g)return null;const p=g.title||u,h=g.authors,y=(x=h==null?void 0:h[0])==null?void 0:x.name;return{title:p,author:y}}catch{return null}};return Promise.all(a.map(async u=>{var g;const x=await l(u);return(g=o==null?void 0:o.current)==null||g.set(u,x),[u,x]})).then(u=>{i||s(x=>{const g={...x};for(const[p,h]of u)g[p]=h;return g})}),()=>{i=!0}},[t.join(","),n]),r}function mr({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=F(),a=ae(),c=fe(),l=m=>{if(!m)return"";const k=i(m);return s?ke(k,s,c):k},[d,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const x=t.type,g=cr[x]||"#717171",p=!!t.content,h=t.work_ids||[],y=h.length>1,b=br(y?h:[],o,r),j=p&&!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:()=>p&&u(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?l(t.header_line):l(t.title)}),!d&&j&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:l(j)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&e.jsx("a",{href:a(h[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(h[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),y&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[h.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),y&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(m=>{const k=b[m],_=k?`${i(k.title)}${k.author?`(${i(k.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:a(m),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",_]},m)})}),d&&p&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:l(t.comment)})]})]})}function yr({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=F(),a=fe(),c=n.trim(),l=f.useMemo(()=>c?t.sections.filter(x=>dt(x,c,!0,a)):t.sections,[t.sections,c,a]),d=t.sections.filter(x=>X(x.type)==="考证").length,u=l.filter(x=>X(x.type)==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:c?`${u} / ${d} 條`:`${d} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:l.map((x,g)=>e.jsx(mr,{section:x,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},g))}),l.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function vr({text:t,highlightQuery:n=""}){const{convert:o}=F(),r=fe(),s=a=>{const c=o(a);return n?ke(c,n,r):c},i=t.split(`
3
3
  `);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((a,c)=>{if(a.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(a.slice(2))},c);if(a.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(a.slice(3))},c);if(a.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(a.slice(4))},c);if(!a.trim())return c>0&&!i[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const l=a.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.map((d,u)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},u):e.jsx(f.Fragment,{children:s(d)},u))},c)})})}function jr({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=F(),s=ae(),i=fe(),a=d=>{if(!d)return"";const u=r(d);return o?ke(u,o,i):u},c=[];let l=null;for(const d of t)X(d.type)==="类"?(l&&c.push(l),l={category:d.title,categoryContent:d.content||void 0,items:[]}):X(d.type)==="书"?(l||(l={category:"",items:[]}),l.items.push(d)):(X(d.type)==="序"||X(d.type)==="结语")&&(l||(l={category:"",items:[]}),l.items.push(d),X(d.type)==="结语"&&(c.push(l),l=null));return l&&c.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,u)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[a(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:a(d.categoryContent)})]}),d.items.map((x,g)=>X(x.type)==="序"||X(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:a(x.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),p.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:a(x.title)})}):e.jsx("strong",{children:a(x.title)}),x.content&&a(x.content)]},g))]},u))})}function Sr({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=F(),i=fe(),[a,c]=f.useState("catalog"),l=o.trim(),d=f.useMemo(()=>l?t.sections.filter(p=>dt(p,l,!1,i)):t.sections,[t.sections,l,i]),u=t.sections.filter(p=>X(p.type)==="书").length,x=t.sections.filter(p=>X(p.type)==="诗").length,g=l?d.filter(p=>X(p.type)==="书"||X(p.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(p=>e.jsx("button",{onClick:()=>c(p),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:p==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:a===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:a===p?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:p==="catalog"?"目錄":"原文"},p))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${x>0?`${x} 首`:`${u} 部書`}`:x>0?`${x} 首`:`${u} 部书`})]}),a==="raw"&&(n?e.jsx(vr,{text:n,highlightQuery:l}):e.jsx(jr,{sections:t.sections,onNavigate:r,highlightQuery:l})),a==="catalog"&&d.map((p,h)=>X(p.type)==="书"||X(p.type)==="诗"?e.jsx(fr,{section:p,onNavigate:r,highlightQuery:l},h):X(p.type)==="类"?e.jsx(gr,{section:p,highlightQuery:l},h):e.jsx(hr,{section:p,highlightQuery:l},h)),a==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function vn(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 It(t){const n=vn(t);return n.length>0?n[0]:null}function kr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:a,query:c,isKaozhen:l}=t,d=fe(),u=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&i&&u.current.set(s,{juan:i,rawText:a})},[s,i,a]),f.useEffect(()=>{u.current.clear(),g({})},[n]);const p=f.useCallback((h,y)=>{let b=0;if(h.juan)for(const j of h.juan.sections)dt(j,y,l,d)&&b++;return b===0&&h.rawText&&ar(h.rawText,y,d)&&(b=1),b},[l,d]);return f.useEffect(()=>{const h=c.trim();if(!h){g({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let y=!1;const b={},j=[];for(const w of r){const S=u.current.get(w);S?b[w]=p(S,h):(b[w]="loading",j.push(w))}g(b);const m=8;let k=0;const _=async()=>{var w;for(;k<j.length;){if(y)return;const S=k++,z=j[S];try{const[E,I]=await Promise.all([o.getCollatedJuan(n,z),((w=o.getCollatedJuanText)==null?void 0:w.call(o,n,z))??Promise.resolve(null)]),C={juan:E,rawText:I};if(u.current.set(z,C),y)return;g(B=>({...B,[z]:p(C,h)}))}catch{if(y)return;g(E=>({...E,[z]:0}))}}},v=Array.from({length:Math.min(m,j.length)},()=>_());return Promise.all(v),()=>{y=!0}},[c,n,o,r.join(","),p,d]),{matchStates:x}}const jn=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:a,style:c})=>{const[l,d]=f.useState(null),[u,x]=f.useState(!1),[g,p]=f.useState(null),[h,y]=f.useState(null),[b,j]=f.useState(null),[m,k]=f.useState(!1),[_,v]=f.useState(null),[w,S]=f.useState(""),z=f.useRef(new Map),E=s??h,I=f.useCallback(L=>{y(L),i==null||i(L)},[i]),C=t||l;f.useEffect(()=>{t&&(x(!1),p(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let L=!1;return x(!0),p(null),o.getCollatedEditionIndex(n).then(T=>{if(!L)if(!T)p("未找到整理本数据");else{d(T);const O=It(T);!s&&O&&I(O)}}).catch(T=>{L||p(T instanceof Error?T.message:"加载失败")}).finally(()=>{L||x(!1)}),()=>{L=!0}},[t,n,o,s,I]),f.useEffect(()=>{const L=t||l;if(L&&!E){const T=It(L);T&&I(T)}},[t,l,E,I]);const B=n||(C==null?void 0:C.work_id),H=f.useCallback(async L=>{var T;if(!(!B||!(o!=null&&o.getCollatedJuan))){k(!0),j(null),v(null);try{const[O,W]=await Promise.all([o.getCollatedJuan(B,L),((T=o.getCollatedJuanText)==null?void 0:T.call(o,B,L))??Promise.resolve(null)]);j(O),v(W)}catch{j(null),v(null)}finally{k(!1)}}},[B,o]);f.useEffect(()=>{E&&H(E)},[E,H]);const M=L=>{I(L)};if(u)return e.jsx("div",{className:a,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!C)return null;const $=C.type==="kaozhen",D=vn(C);return e.jsx(wr,{className:a,style:c,index:C,allFiles:D,isKaozhen:$,effectiveWorkId:B,transport:o,activeFile:E,handleSelectFile:M,juanData:b,juanRawText:_,juanLoading:m,searchQuery:w,setSearchQuery:S,onNavigate:r,workLabelCacheRef:z})},wr=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:a,activeFile:c,handleSelectFile:l,juanData:d,juanRawText:u,juanLoading:x,searchQuery:g,setSearchQuery:p,onNavigate:h,workLabelCacheRef:y})=>{const{matchStates:b}=kr({workId:i,transport:a,files:r,activeFile:c,activeJuan:d,activeRawText:u,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=>p(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:[o.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_juan})," 卷"]})}),o.text_quality&&(()=>{const j=nr(o.text_quality.grade);return j?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(tr,{content:Xn[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:Zn[j],cursor:"help"},children:tn[j]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(xr,{files:r,groups:o.juan_groups,activeFile:c,onSelect:l,juanMeta:o.juan_metadata,matchStates:b}),x?e.jsx(ye,{}):d?s?e.jsx(yr,{juan:d,searchQuery:g,onNavigate:h,transport:a,workLabelCache:y}):e.jsx(Sr,{juan:d,rawText:u,searchQuery:g,onNavigate:h}):c?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,o.references&&o.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:"參考文獻"}),o.references.map((j,m)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[m+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]})]},m))]})]})},_r={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Cr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function zr(t){try{const n=new Date(t),o=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`}catch{return t}}const Sn=({items:t,loading:n})=>{const o=ae();return n?e.jsx(ye,{}):t.length===0?e.jsx("div",{style:Ir,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=_r[r.type],i=Cr[r.status];return e.jsxs("div",{style:Tr,children:[e.jsxs("div",{style:Rr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Tt,background:s.color},children:s.label}),e.jsx("span",{style:{...Tt,background:i.color},children:i.label})]}),e.jsx("span",{style:Er,children:zr(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Lr,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:Rt,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:Rt,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Br,children:r.content}),r.reply&&e.jsxs("div",{style:Wr,children:[e.jsx("div",{style:$r,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},Ir={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Tr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Rr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Tt={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Er={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Lr={fontSize:"12px",marginBottom:"6px"},Rt={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Br={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Wr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},$r={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},it=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const a=A(),[c,l]=f.useState(null),[d,u]=f.useState([]),[x,g]=f.useState("recommend"),[p,h]=f.useState([]),[y,b]=f.useState(!1),j=r??x,m=$=>{g($),s==null||s($)},[k,_]=f.useState(!0),[v,w]=f.useState(null),[S,z]=f.useState(null),[E,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(D=>{$||l({works:D.works,books:D.books,collections:D.collections})}).catch(()=>{}),()=>{$=!0}},[t]),f.useEffect(()=>{let $=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const L=await t.getRecommended();if(L!=null&&L.groups)return L.groups.flatMap(T=>T.items.map(O=>({...O,group:T.name})))}catch{}return[]})().then(async L=>{if($)return;const T=L.filter(W=>W.id);if(T.length===0){_(!1);return}const O=await Promise.all(T.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 G=await t.getItem(W.id);G&&(U={id:W.id,title:G.title||W.id,type:G.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:N.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(u(O.filter(W=>W!==null)),_(!1))}),()=>{$=!0}},[t,o]);const C=f.useRef(!1),B=f.useRef(!1),H=f.useRef(!1);f.useEffect(()=>{if(j!=="catalog"||C.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;C.current=!0;let D=!1;return $.call(t).then(L=>{D||w(L)}).catch(()=>{C.current=!1}),()=>{D=!0}},[t,j]),f.useEffect(()=>{if(j!=="collection"||B.current||!t.getCollectionProgress)return;B.current=!0;let $=!1;return t.getCollectionProgress().then(D=>{$||z(D)}).catch(()=>{B.current=!1}),()=>{$=!0}},[t,j]),f.useEffect(()=>{if(j!=="site"||H.current||!t.getSiteProgress)return;H.current=!0;let $=!1;return t.getSiteProgress().then(D=>{$||I(D)}).catch(()=>{H.current=!1}),()=>{$=!0}},[t,j]),f.useEffect(()=>{if(!i||j!=="feedback")return;let $=!1;return b(!0),fetch(i).then(D=>D.json()).then(D=>{!$&&D.success&&h(D.items||[])}).catch(()=>{}).finally(()=>{$||b(!1)}),()=>{$=!0}},[i,j]);const M=$=>{switch($){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(Te,{label:a.home.recommendTab,active:j==="recommend",onClick:()=>m("recommend")}),e.jsx(Te,{label:a.home.catalogTab,active:j==="catalog",onClick:()=>m("catalog")}),e.jsx(Te,{label:a.home.collectionTab,active:j==="collection",onClick:()=>m("collection")}),e.jsx(Te,{label:a.home.siteTab,active:j==="site",onClick:()=>m("site")}),i&&e.jsx(Te,{label:a.home.feedbackTab,active:j==="feedback",onClick:()=>m("feedback")})]}),j==="recommend"&&e.jsx(Pr,{recommended:d,loading:k,onNavigate:n,getIcon:M,t:a}),j==="catalog"&&e.jsx(Et,{progress:v,t:a,onNavigate:n}),j==="collection"&&e.jsx(Et,{progress:S,t:a,onNavigate:n}),j==="site"&&e.jsx(Mr,{progress:E,t:a,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&i&&e.jsx(Sn,{items:p,loading:y})]})})},Te=({label:t,active:n,onClick:o})=>e.jsx("button",{onClick:o,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}),Pr=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=ae();if(n)return e.jsx(ye,{});if(t.length===0)return null;const a=new Map;for(const c of t){const l=c.group||s.home.recommendedBrowse;a.has(l)||a.set(l,[]),a.get(l).push(c)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([c,l])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:l.map(d=>{const u=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:i(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o==null||o(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},d.id)})})]},c))})},Et=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((c,l)=>c.priority-l.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:s.map(c=>{const l=r.filter(d=>d.status===c);return l.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[c]}}),i[c]," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(d=>e.jsx(Ar,{item:d,t:n,statusColor:a[c],onNavigate:o},d.id))})]},c)})})},Ar=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=ae(),i=t.total>0?Math.round(t.imported/t.total*100):0,a=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,l=t.collection_id||t.work_id;return l&&r?e.jsx("a",{href:s(l),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(l))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:a})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ae(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:`${i}%`,borderRadius:"2px",background:o,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Mr=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((l,d)=>l.priority-d.priority),s=r.filter(l=>l.imported>0),i=r.filter(l=>l.imported===0),a=s.reduce((l,d)=>Math.max(l,d.imported),0),c=o>0?Math.round(a/o*100):0;return e.jsxs("div",{children:[o>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:a.toLocaleString()})," / ",o.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:"#10b981"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(l=>e.jsx(Lt,{item:l,t:n,totalWorks:o},l.id))})]}),i.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:"#9ca3af"}}),n.home.statusTodo," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(l=>e.jsx(Lt,{item:l,t:n,totalWorks:o},l.id))})]})]})},Lt=({item:t,t:n,totalWorks:o})=>{const r=o>0?Math.round(t.imported/o*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${r}%)`:n.home.statusTodo})]}),t.imported>0&&o>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:"#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})]})},Bt="(max-width: 768px)";function Fr(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Bt).matches);return f.useEffect(()=>{const o=window.matchMedia(Bt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Hr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var D;const i=A(),{convert:a}=F(),c=Fr(),[l,d]=f.useState(null),[u,x]=f.useState(null),[g,p]=f.useState(!1),[h,y]=f.useState("detail"),[b,j]=f.useState([]),[m,k]=f.useState(!1),[_,v]=f.useState(null),[w,S]=f.useState(!1),z=f.useCallback(async L=>{if(!t.getCollatedEditionIndex){v(null);return}S(!0);try{const T=await t.getCollatedEditionIndex(L);v(T)}catch{v(null)}finally{S(!1)}},[t]),E=f.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}k(!0);try{if(t.getCollectionCatalogs){const T=await t.getCollectionCatalogs(L);j(T||[])}else if(t.getCollectionCatalog){const T=await t.getCollectionCatalog(L);j(T?[{resource_id:"",data:T}]:[])}}catch{j([])}finally{k(!1)}},[t]),I=f.useCallback(async L=>{if(o){o(L);return}d(L),x(null),j([]),v(null),y("detail"),p(!0);try{const T=await t.getItem(L.id);T&&(x(T),T.type==="collection"?E(L.id):T.type==="work"&&T.has_collated&&z(L.id))}catch(T){console.error("加载详情失败:",T)}finally{p(!1)}},[t,o,E,z]),C=f.useCallback(async L=>{x(null),j([]),v(null),y("detail"),p(!0);try{const T=await t.getItem(L);T&&(x(T),d({id:L,title:T.title||L,type:T.type||"book"}),T.type==="collection"?E(L):T.type==="work"&&T.has_collated&&z(L))}catch(T){console.error("导航失败:",T)}finally{p(!1)}},[t,E,z]),B=(u==null?void 0:u.type)==="collection"&&(b.length>0||m)||(u==null?void 0:u.type)==="work"&&(_||w),H=c&&(g||u),M=f.useCallback(()=>{d(null),x(null),j([]),v(null),y("detail")},[]),$=e.jsx(e.Fragment,{children:g?e.jsx(ye,{}):u?e.jsxs(e.Fragment,{children:[(B||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:[B&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y("detail"),style:Oe(h==="detail"),children:i.detailTab.basicInfo}),u.type==="collection"&&m&&b.length===0&&e.jsxs("button",{onClick:()=>{},style:Oe(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&b.map(L=>e.jsx("button",{onClick:()=>y(`catalog:${L.resource_id}`),style:Oe(h===`catalog:${L.resource_id}`),children:L.short_name?`${a(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),u.type==="work"&&(_||w)&&e.jsxs("button",{onClick:()=>y("collated"),style:Oe(h==="collated"),children:[i.detailTab.collatedEdition,w&&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(at,{data:u,transport:t,onNavigate:C}):h.startsWith("catalog:")?e.jsx(fn,{data:(D=b.find(L=>`catalog:${L.resource_id}`===h))==null?void 0:D.data,onNavigate:C}):h==="collated"?e.jsx(jn,{index:_||void 0,workId:u.id,transport:t,onNavigate:C}):null})]}):e.jsx(it,{transport:t,onNavigate:C,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:H?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:M,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:["← ",i.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(ot,{transport:t,onEntryClick:I,hideModeIndicator:n}),!u&&e.jsx(it,{transport:t,onNavigate:C,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(ot,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Oe(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}}const Or=({data:t,onNavigate:n,className:o,style:r})=>{var u;const s=A(),{convert:i}=F(),[a,c]=f.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[l,d]=f.useState(null);return e.jsxs("div",{className:o,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Dr,{division:x,expanded:a===x.name,onToggle:()=>c(a===x.name?null:x.name),expandedCat:l,onCatToggle:g=>d(l===g?null:g),onNavigate:n},x.name))})]})},Dr=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:a}=F(),c=t.categories.reduce((l,d)=>{const u=d.stats||{zhulu:0,cunmu:0};return l+(u.zhulu||0)+(u.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:o,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(l=>{const d=`${t.name}/${l.name}`;return e.jsx(Vr,{category:l,expanded:r===d,onToggle:()=>s(d),onNavigate:i},l.name)})})]})},Vr=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var l,d,u,x;const{convert:s}=F(),i=((l=t.books)==null?void 0:l.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],c=(((u=t.stats)==null?void 0:u.zhulu)||i.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:o,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&&(i.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Wt,{label:"著錄",books:i,onNavigate:r}),a.length>0&&e.jsx(Wt,{label:"存目",books:a,onNavigate:r})]})]})},Wt=({label:t,books:n,onNavigate:o})=>{const{convert:r}=F(),s=ae(),[i,a]=f.useState(n.length<=20),c=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((l,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:l.work_id&&o?e.jsx("a",{href:s(l.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(l.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(l.title)}):r(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(l.author).slice(0,20)})]},d))}),!i&&e.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},se=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=A();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,o&&e.jsx("button",{onClick:o,style:Nr,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ur,children:i.action.save})]})]}),s]})},Ur={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Nr={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},re=({label:t,value:n,onChange:o,placeholder:r,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:i=>o(i.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),me=({value:t,onChange:n,placeholder:o})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder:o,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"}})},Ne=({children:t,color:n,style:o})=>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)",...o},children:t});function Gr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ve=({value:t,onChange:n,label:o})=>{const[r,s]=f.useState(!1),i=f.useRef(null),a=Gr(t||"");return f.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:$t,children:o}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:a.name}),e.jsx(Ne,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:$t,children:o}),e.jsx("input",{ref:i,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"}})]})},$t={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Yr(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Kr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const kn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=A(),[s,i]=f.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},c=x=>{n(t.filter((g,p)=>p!==x)),s===x&&i(null)},l=(x,g,p)=>{const h=[...t];h[x]={...h[x],[g]:p},n(h)},d=(x,g)=>{const p=[...t];p[x]={...p[x],type:g,id:"",name:""},n(p),g==="bookID"&&o&&o(h=>{const y=[...t];y[x]={...y[x],id:h.id,name:h.title,type:"bookID"},n(y)})},u=x=>{o&&o(g=>{const p=[...t];p[x]={...p[x],id:g.id,name:g.title,type:"bookID"},n(p)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>i(s===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Yr(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Kr(x.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),c(g)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Pt,borderColor:"#4caf50",color:"#4caf50"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...Pt,borderColor:"#2196f3",color:"#2196f3"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ue,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[g]={...p[g],type:"",id:"",name:""},n(p)},style:At,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid #4caf50",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"#4caf50",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>u(g),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:r.action.reselect})]}):e.jsxs("button",{onClick:()=>u(g),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:ue,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[g]={...p[g],type:"",id:"",name:""},n(p)},style:At,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:p=>l(g,"name",p.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:p=>l(g,"id",p.target.value),placeholder:"https://...",style:ve})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...ue,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:p=>l(g,"details",p.target.value),placeholder:r.editor.detailsPlaceholder,style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:p=>l(g,"position",p.target.value),placeholder:"如: 卷三, p.52",style:ve})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:p=>l(g,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:ve})]}),e.jsxs("div",{children:[e.jsx("label",{style:ue,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:p=>l(g,"processor_version",p.target.value),placeholder:"如: v0.1",style:ve})]})]})]})]})})]},g)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},ue={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ve={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Pt={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"},At={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function wn(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(o=>({id:o.id||"",name:o.name||"",type:o.type||"",details:o.details||"",position:o.position||"",version:o.version||"",processor_version:o.processor_version||""}))}catch{}return[]}function _n(t){return!t||t.length===0?"":JSON.stringify(t)}const Cn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:a,childWorks:c,childCollections:l,containedBooks:d,siblingBooks:u,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:p,onCreateAndLink:h,onSaveRelations:y})=>{const b=A();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:b.section.relations})]}),y&&e.jsx("button",{onClick:y,style:Jr,children:b.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.belongsToWork,entity:i,onView:p,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(Re,{direction:"up",title:b.relation.containedInCollection,entity:a,onView:p,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),i&&u&&u.length>0&&e.jsx(je,{direction:"horizontal",title:`${b.relation.siblingVersions} (${u.length})`,entities:u,onView:p,onAdd:()=>h("siblingBook","book",{workId:i.id}),addLabel:b.relation.addVersionForWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.parentWork,entity:r,onView:p,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),c&&c.length>0&&e.jsx(je,{direction:"down",title:`${b.relation.childWorks} (${c.length})`,entities:c,onView:p,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:b.action.addSubWork,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),l&&l.length>0&&e.jsx(je,{direction:"down",title:`${b.relation.collectionImpl} (${l.length})`,entities:l,onView:p,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:b.action.addCollectionImpl,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(je,{direction:"down",title:`${b.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>h("childBook","book",{workId:n}),addLabel:b.action.addVersion,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:b.relation.correspondingWork,entity:i,onView:p,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>h("workId","work",{title:o}),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(Re,{direction:"up",title:b.relation.parentCollection,entity:s,onView:p,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:b.action.linkExisting,createLabel:b.action.createAndLink,notLinkedLabel:b.relation.notLinked,viewLabel:b.action.viewEntity,unlinkLabel:b.action.unlink}),e.jsx(je,{direction:"down",title:`${b.relation.childCollections} (${(l==null?void 0:l.length)??0})`,entities:l||[],onView:p,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:b.action.addSubCollection,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore}),e.jsx(je,{direction:"down",title:`${b.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:b.action.addBook,noneLabel:b.relation.none,expandMoreLabel:b.action.expandMore})]})]})]})},Re=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:a,linkLabel:c,createLabel:l,notLinkedLabel:d,viewLabel:u,unlinkLabel:x})=>{const g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=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:p}),e.jsx("span",{children:n})]}),o?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:zn(o.type)}),e.jsx("span",{style:{fontWeight:500},children:o.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:o.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(Mt,{onClick:()=>r(o),title:u,children:"👁️"}),e.jsx(Mt,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(st,{onClick:i,children:c}),e.jsx(st,{onClick:a,primary:!0,children:l})]})]})},je=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:a,expandMoreLabel:c})=>{const[l,d]=f.useState(!1),u=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=l?o:o.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:u,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(p=>e.jsxs("div",{onClick:()=>r(p),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:zn(p.type)}),e.jsx("span",{children:p.title})]},p.id)),o.length>5&&!l&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",o.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(st,{onClick:s,primary:!0,children:["+ ",i]})})]})},Mt=({onClick:t,title:n,danger:o,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:o?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),st=({onClick:t,primary:n,children:o})=>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:o});function zn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Jr={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"},In=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:a,onSearch:c,isLoading:l,excludeId:d})=>{const[u,x]=f.useState(""),g=d?a.filter(b=>b.id!==d):a;f.useEffect(()=>{t&&(x(""),c(""))},[t]);const p=b=>{x(b),c(b)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:qr,children:e.jsxs("div",{style:Xr,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:o}),e.jsx("button",{onClick:s,style:Zr,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:b=>p(b.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:Qr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:l?e.jsx("div",{style:Qe,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(b=>e.jsxs("div",{onClick:()=>r(b),style:ei,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[b.title,b.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:b.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[b.id,b.author&&` · ${b.author}`,b.dynasty&&` · ${b.dynasty}`]})]})]},b.id))}):u?e.jsxs("div",{style:Qe,children:["未找到匹配的",h]}):e.jsxs("div",{style:Qe,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:i,style:ti,children:["创建新",h,"并关联"]})]})]})})},qr={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},Xr={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)"},Zr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Qr={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"},ei={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Qe={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},ti={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ft={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},ni={work:"📜",book:"📖",collection:"📚",entity:"👤"},Tn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[a,c]=f.useState(""),l=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,p;(g=l.current)==null||g.focus(),(p=l.current)==null||p.select()},100))},[t,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&a.trim()?u():g.key==="Escape"&&i()},u=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!t)return null;const x=()=>{switch(o){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`创建新${Ft[n]}`}};return e.jsx("div",{style:oi,onClick:g=>{g.target===g.currentTarget&&i()},children:e.jsxs("div",{style:ri,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:ni[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:l,type:"text",value:a,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Ft[n]}名称...`,style:ii})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:i,style:si,children:"取消"}),e.jsx("button",{onClick:u,disabled:!a.trim(),style:{...li,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},oi={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},ri={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)"},ii={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"},si={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},li={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function ai(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Rn(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ci(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const En=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:a,onSelect:c,onCancel:l,onCreate:d,onSearch:u})=>{const[x,g]=f.useState(""),[p,h]=f.useState([]),[y,b]=f.useState(!1),[j,m]=f.useState("recent");f.useEffect(()=>{t&&(g(""),h([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!x.trim()){h([]);return}const z=setTimeout(async()=>{b(!0);try{h(await u(x,o))}catch{h([])}finally{b(!1)}},300);return()=>clearTimeout(z)},[x,o,u]);const k=f.useCallback(z=>{g(z.target.value),z.target.value.trim()&&m("search")},[]),_=f.useCallback(z=>s?z.filter(E=>E.id!==s):z,[s]);if(!t)return null;const v=n||(o==="all"?"选择实体":`选择${Rn(o)}`),w=_(r),S=_(p);return e.jsx("div",{style:pi,children:e.jsxs("div",{style:xi,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:v}),e.jsx("button",{onClick:l,style:ui,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:fi}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),w.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Ht,{active:j==="recent",onClick:()=>m("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(Ht,{active:j==="search",onClick:()=>m("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"&&w.length>0?e.jsx(Ot,{entities:w,onSelect:c}):x.trim()?y?e.jsx(et,{message:"搜索中..."}):S.length>0?e.jsx(Ot,{entities:S,onSelect:c}):e.jsx(et,{message:"未找到匹配的结果"}):e.jsx(et,{message:"输入关键词开始搜索"})}),i&&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:gi,children:a||"创建新实体"})]})]})})},Ht=({active:t,onClick:n,children:o})=>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:o}),Ot=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(di,{entity:o,onClick:()=>n(o)},o.id))}),di=({entity:t,onClick:n})=>{const[o,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:o?"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:ai(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:ci(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Rn(t.type)})]})},et=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),pi={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},xi={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)"},ui={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},fi={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"},gi={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},hi={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},bi={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ln=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:a,onAskAI:c,renderSectionActions:l,onDownloadResource:d,downloadStatuses:u,relations:x,onRelationsChange:g})=>{var ee;const p=A(),[h,y]=f.useState(!1),[b,j]=f.useState("work"),[m,k]=f.useState(""),[_,v]=f.useState(""),[w,S]=f.useState([]),[z,E]=f.useState(!1),[I,C]=f.useState(!1),[B,H]=f.useState("work"),[M,$]=f.useState(""),[D,L]=f.useState(),[T,O]=f.useState(!1),[W,U]=f.useState(null),[G,Z]=f.useState([]);f.useRef(null);const ne=t.type,he=ne==="work",ge=ne==="collection",Q=ne==="book",q=f.useCallback((R,V)=>{n({...t,[R]:V})},[t,n]),Ye=f.useCallback((R,V)=>{k(R),j(V),v(p.editor.selectToLink+p.indexType[V]),S([]),y(!0)},[p]),Ke=f.useCallback(R=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,R)},[r,t.id]),we=f.useCallback(R=>{s==null||s(R.id,R.type)},[s]),_e=f.useCallback((R,V,oe)=>{const ce={...oe,author:(oe==null?void 0:oe.author)||t.author,dynasty:(oe==null?void 0:oe.dynasty)||t.dynasty};H(V),$(R),L(ce),C(!0)},[t.author,t.dynasty]),Je=f.useCallback((R,V)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,M,{type:B,title:R,inheritData:V}),C(!1)},[r,t.id,M,B]),Me=f.useCallback(R=>{if(!R.trim()){S([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(R,b).then(V=>{S(V),E(!1)}).catch(()=>{S([]),E(!1)})},[r,b]),qe=f.useCallback(R=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,R.id),y(!1)},[r,t.id,m]),P=f.useCallback(()=>{o()},[o]),J=f.useCallback(R=>{U(()=>R),O(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Z).catch(()=>{})},[r]),Y=f.useCallback((R,V)=>r!=null&&r.searchEntities?r.searchEntities(R,V==="all"?void 0:V):Promise.resolve([]),[r]),K=f.useCallback(R=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(R),Z(V=>[R,...V.filter(oe=>oe.id!==R.id)].slice(0,10)),W==null||W(R),O(!1),U(null)},[r,W]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:bi[ne]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(Ne,{children:t.id}),e.jsx(Ne,{color:hi[ne],children:p.indexType[ne]})]})}),e.jsx(se,{title:p.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:l==null?void 0:l("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ve,{label:he?p.editor.workTitle:ge?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:R=>q("title",R)}),Q&&e.jsx(Ve,{label:p.editor.belongsToWork,value:t.workName||"",onChange:R=>q("workName",R)}),e.jsx(re,{label:p.editor.authorLabel,value:t.author||"",onChange:R=>q("author",R)}),e.jsx(re,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:R=>q("dynasty",R)}),(Q||ge)&&e.jsx(Ve,{label:p.editor.containedIn,value:t.collection||"",onChange:R=>q("collection",R)}),(Q||ge)&&e.jsx(re,{label:p.editor.holderLabel,value:t.holder||"",onChange:R=>q("holder",R)}),(Q||ge)&&e.jsx(re,{label:Q?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:R=>q("pages",R)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(re,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:R=>q("firstImage",R)})})]})}),e.jsx(se,{title:p.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(me,{value:t.description||"",onChange:R=>q("description",R),placeholder:p.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(se,{title:p.section.additionalWorks,onSave:o,children:e.jsx(mi,{items:t.additional_works||[],onChange:R=>q("additional_works",R)})}),e.jsx(se,{title:p.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(yi,{items:t.indexed_by||[],onChange:R=>q("indexed_by",R)})}),e.jsx(se,{title:p.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(vi,{items:t.emendated_by||[],onChange:R=>q("emendated_by",R)})}),e.jsx(se,{title:p.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(nt,{items:t.resources||[],onChange:R=>q("resources",R),onDownload:d,downloadStatuses:u,filterType:"text"})}),e.jsx(se,{title:p.section.imageResources,onSave:o,children:e.jsx(nt,{items:t.resources||[],onChange:R=>q("resources",R),onDownload:d,downloadStatuses:u,filterType:"image"})}),e.jsx(se,{title:p.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(kn,{items:wn(t.sources||""),onChange:R=>q("sources",_n(R)),onOpenEntityPicker:J})}),(Q||ge)&&e.jsx(se,{title:p.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(me,{value:t.provenance||"",onChange:R=>q("provenance",R),placeholder:p.editor.provenancePlaceholder})}),Q&&e.jsx(se,{title:p.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(me,{value:t.otherEditions||"",onChange:R=>q("otherEditions",R),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx(Cn,{entityType:ne,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:Ye,onUnlinkEntity:Ke,onViewEntity:we,onCreateAndLink:_e,onSaveRelations:P}),i&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:p.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:p.editor.dangerZoneDesc}),e.jsx("button",{onClick:a,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:p.editor.deleteEntity})]}),e.jsx(In,{isOpen:h,entityType:b,title:_,onSelect:qe,onCancel:()=>y(!1),onCreate:()=>{y(!1),_e(m,b)},searchResults:w,onSearch:Me,isLoading:z,excludeId:t.id}),e.jsx(Tn,{isOpen:I,entityType:B,relationField:M,inheritData:D,onConfirm:Je,onCancel:()=>C(!1)}),e.jsx(En,{isOpen:T,title:p.action.selectBookOrWork,filterType:"all",recentEntities:G,excludeId:t.id,onSelect:K,onCancel:()=>{O(!1),U(null)},onSearch:Y})]})};function mi({items:t,onChange:n}){const o=A(),r=(a,c,l)=>{const d=t.map((u,x)=>x===a?{...u,[c]:l}:u);n(d)},s=a=>n(t.filter((c,l)=>l!==a)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(re,{label:o.editor.bookNameLabel,value:a.book_title,onChange:l=>r(c,"book_title",l)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(re,{label:o.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:l=>r(c,"n_juan",l&&parseInt(l,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:i,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function Bn({items:t,onChange:n,showMeta:o,addLabel:r}){const s=A(),[i,a]=f.useState(null),c=(u,x,g)=>{const p=t.map((h,y)=>y===u?{...h,[x]:g||void 0}:h);n(p)},l=u=>{n(t.filter((x,g)=>g!==u)),i===u&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,x)=>{const g=i===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>a(g?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:u.source||s.editor.unnamedSource}),u.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:u.source_bid}),e.jsx("button",{onClick:p=>{p.stopPropagation(),l(x)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid #ddd",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"#999"},children:"✕"})]}),!g&&o&&(u.title_info||u.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[u.title_info,u.title_info&&u.author_info&&" — ",u.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(re,{label:s.label.sourceName,value:u.source,onChange:p=>c(x,"source",p)}),e.jsx(re,{label:s.label.sourceBid,value:u.source_bid||"",onChange:p=>c(x,"source_bid",p)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(re,{label:s.label.titleInfo,value:u.title_info||"",onChange:p=>c(x,"title_info",p)}),e.jsx(re,{label:s.label.authorInfo,value:u.author_info||"",onChange:p=>c(x,"author_info",p)})]}),e.jsx(re,{label:s.label.edition,value:u.edition||"",onChange:p=>c(x,"edition",p)})]}),e.jsx(me,{value:u.summary||"",onChange:p=>c(x,"summary",p),placeholder:s.editor.summaryPlaceholder}),e.jsx(me,{value:u.comment||"",onChange:p=>c(x,"comment",p),placeholder:s.editor.commentPlaceholder}),e.jsx(me,{value:u.additional_comment||"",onChange:p=>c(x,"additional_comment",p),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function yi({items:t,onChange:n}){const o=A();return e.jsx(Bn,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function vi({items:t,onChange:n}){const o=A();return e.jsx(Bn,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Wn(t){var c,l,d,u,x,g,p;const n=((l=(c=t.authors)==null?void 0:c[0])==null?void 0:l.name)||"",o=((d=t.publication_info)==null?void 0:d.year)||"",r=((u=t.current_location)==null?void 0:u.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",i=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,dynasty:o,holder:r,pages:s,description:i,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const h=t;if(Array.isArray(h.related_works)){const y=h.related_works.find(b=>b.relation==="part_of");y&&(a.parentWorkId=y.id,a.parentWorkName=y.title)}}if(t.type==="book"){const h=t;a.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(a.collectionId=(p=h.contained_in[0])==null?void 0:p.id)}return a}function ji(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 Si=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:a,onSave:c,onDelete:l,onNavigate:d,renderLink:u,onAskAI:x,renderSectionActions:g,onDownloadResource:p,downloadStatuses:h,relations:y,onRelationsChange:b,headerExtra:j,className:m,style:k}=t;A();const[_,v]=f.useState(s),w=i?s:_;f.useEffect(()=>{s!==_&&v(s)},[s]);const S=f.useCallback(()=>{const M=w==="view"?"edit":"view";i?i(M):v(M)},[w,i]),[z,E]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(M=>{M&&E(M)})},[o,r]);const I=n||z,C=f.useMemo(()=>I?Wn(I):null,[I]),B=i||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:w==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:w==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:w==="view"?"切换到编辑模式":"切换到查看模式",children:w==="view"?"✏️ 编辑":"👁 查看"}):null,H=e.jsxs(e.Fragment,{children:[B,j]});return!I&&!C?e.jsx(ye,{}):w==="view"?e.jsx(at,{data:I,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:u,headerExtra:H,className:m,style:k}):C?e.jsxs("div",{className:m,style:k,children:[H&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:H}),e.jsx(Ln,{data:C,onChange:a||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!l,onDelete:l,onAskAI:x,renderSectionActions:g,onDownloadResource:p,downloadStatuses:h,relations:y,onRelationsChange:b})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Dt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],$n=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=f.useState(null),[a,c]=f.useState(""),[l,d]=f.useState("idle"),[u,x]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(i(null),c(""),d("idle"),x(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var b;return(b=g.current)==null?void 0:b.focus()},100)},[s]),f.useEffect(()=>{if(l==="success"){const b=setTimeout(n,2e3);return()=>clearTimeout(b)}},[l,n]),f.useEffect(()=>{if(!t)return;const b=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[t,n]);const p=async()=>{if(!(!s||!a.trim())){d("submitting"),x("");try{await o({type:s,content:a.trim()}),d("success")}catch(b){d("error"),x(b instanceof Error?b.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&a.trim()&&l!=="submitting",y=Dt.find(b=>b.value===s);return e.jsx("div",{style:ki,onClick:b=>{b.target===b.currentTarget&&n()},children:e.jsxs("div",{style:wi,onClick:b=>b.stopPropagation(),children:[e.jsxs("div",{style:_i,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Ci,"aria-label":"关闭",children:"✕"})]}),l==="success"?e.jsxs("div",{style:Ei,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:Dt.map(b=>e.jsxs("button",{onClick:()=>i(b.value),style:{...zi,...s===b.value?Ii:{}},children:[e.jsx("span",{children:b.icon})," ",b.label]},b.value))}),e.jsx("textarea",{ref:g,value:a,onChange:b=>c(b.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||l==="submitting",style:{...Ti,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),l==="error"&&e.jsx("div",{style:Li,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:p,disabled:!h,style:{...Ri,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:l==="submitting"?"提交中...":"提交反馈"})})]})]})})},ki={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},wi={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)"},_i={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Ci={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},zi={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"},Ii={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ti={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"},Ri={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ei={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Li={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Bi=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...Wi,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($n,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},Wi={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"},Vt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],$i=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[i,a]=f.useState("idle"),[c,l]=f.useState(""),d=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var p;return(p=d.current)==null?void 0:p.focus()},100)},[n]);const u=async()=>{if(!(!n||!r.trim())){a("submitting"),l("");try{await t({type:n,content:r.trim()}),a("success"),s(""),o("bug")}catch(p){a("error"),l(p instanceof Error?p.message:"提交失败,请稍后重试")}}},x=n&&r.trim()&&i!=="submitting",g=Vt.find(p=>p.value===n);return i==="success"?e.jsx("div",{style:Ut,children:e.jsxs("div",{style:Hi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>a("idle"),style:Oi,children:"继续提交"})]})}):e.jsxs("div",{style:Ut,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Vt.map(p=>e.jsxs("button",{onClick:()=>o(p.value),style:{...Pi,...n===p.value?Ai:{}},children:[e.jsx("span",{children:p.icon})," ",p.label]},p.value))}),e.jsx("textarea",{ref:d,value:r,onChange:p=>s(p.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Mi}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:u,disabled:!x,style:{...Fi,opacity:x?1:.6,cursor:x?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Di,children:c})]})},Ut={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Pi={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"},Ai={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Mi={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"},Fi={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Hi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Oi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Di={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Vi(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 Ui(t,n){if(!t.lineage)return null;const o=t.lineage;return{id:t.id,kind:"book",label:t.title,year:o.year,year_text:o.year_text,year_uncertain:o.year_uncertain,category:o.category,status:o.status,extant_juan:o.extant_juan,group:n[t.id],note:o.note}}function Nt(t,n,o){return{id:`derive:${n.ref}->${t}:${o}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Ni(t,n,o){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${o}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Gi(t,n){var d;if(n==="all")return null;const o=(d=t.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,i=r||s||!!(o!=null&&o.hypothetical_ids);if(!i&&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(!o||!i)return null;const a=r?new Set(o.groups):null,c=new Set(o.book_ids??[]);if(a&&t.node_groups)for(const[u,x]of Object.entries(t.node_groups))a.has(x)&&c.add(u);let l=null;if(o.hypothetical_ids&&(l=new Set(o.hypothetical_ids)),a){l||(l=new Set);for(const u of t.hypothetical_nodes??[])u.group&&a.has(u.group)&&l.add(u.id)}return{books:c,hypos:l}}function Yi(t,n,o){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const i=new Set(r.excluded_books??[]),a=r.node_groups??{},c=Gi(r,o??r.default_collection??"all"),l=c!==null,d=(c==null?void 0:c.books)??null,u=(c==null?void 0:c.hypos)??null,x=new Set,g=new Set;if(l){const _=new Map(n.map(I=>[I.id,I])),v=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),w=I=>{const C=_.get(I);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(H=>H.ref);const B=v.get(I);return B?(B.derived_from??[]).map(H=>H.ref):[]},S=I=>v.has(I)?!u||u.has(I):!d||d.has(I),z=new Set,E=I=>{if(!z.has(I)){z.add(I);for(const C of w(I))i.has(C)||(S(C)||(v.has(C)?g.add(C):_.has(C)&&x.add(C)),E(C))}};for(const I of n)d&&d.has(I.id)&&!i.has(I.id)&&E(I.id);for(const I of r.hypothetical_nodes??[])u&&u.has(I.id)&&E(I.id)}const p=n.filter(_=>!i.has(_.id)).filter(_=>!d||d.has(_.id)||x.has(_.id)).map(_=>{const v=Ui(_,a);return v&&x.has(_.id)&&(v.bridge=!0),v}).filter(_=>_!==null),h=(r.hypothetical_nodes??[]).filter(_=>!u||u.has(_.id)||g.has(_.id)).map(_=>{const v=Vi(_);return g.has(_.id)&&(v.bridge=!0),v}),y=[...p,...h],b=new Set(y.map(_=>_.id)),j=new Set,m=[],k=_=>{j.has(_.id)||!b.has(_.source)||!b.has(_.target)||(j.add(_.id),m.push(_))};for(const _ of n)i.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!x.has(_.id)||((_.lineage.derived_from??[]).forEach((v,w)=>{k(Nt(_.id,v,w))}),(_.lineage.related_to??[]).forEach((v,w)=>{k(Ni(_.id,v,w))}));for(const _ of r.hypothetical_nodes??[])u&&!u.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((v,w)=>{k(Nt(_.id,v,w))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(i)}}function Pn(t,n,o){const r=(t??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Ki(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(l=>l.id)),i=new Set((r.hypothetical_nodes??[]).map(l=>l.id)),a=new Set([...s,...i]),c=(l,d)=>{a.has(d.ref)||o.push(`${l}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${l}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!i.has(d.ref)&&o.push(`${l}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const l of n){if(!l.lineage)continue;const d=`Book ${l.id} (${l.title})`;(l.lineage.derived_from??[]).forEach(u=>c(d,u)),(l.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${d}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const l of r.hypothetical_nodes??[]){const d=`Hypothetical ${l.id} (${l.label})`;(l.derived_from??[]).forEach(u=>c(d,u))}return o}const An=({graph:t,renderLink:n,className:o,style:r})=>{const{convert:s}=F();if(!t.nodes.length)return e.jsx("div",{style:{...as,...r},className:o,children:"暂无版本图数据"});const i=new Map,a=new Map;for(const g of t.edges)if(g.kind==="derive"){const p=i.get(g.target)??[];p.push(g),i.set(g.target,p)}else for(const p of[g.source,g.target]){const h=a.get(p)??[];h.push(g),a.set(p,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),l=new Map,d=[];for(const g of t.nodes)if(g.group){const p=l.get(g.group)??[];p.push(g),l.set(g.group,p)}else d.push(g);const u=(g,p)=>(g.year??9999)-(p.year??9999);l.forEach(g=>g.sort(u)),d.sort(u);const x=t.groups.filter(g=>l.has(g.id));return e.jsxs("div",{className:o,style:{...qi,...r},children:[t.title&&e.jsx("div",{style:Xi,children:s(t.title)}),t.description&&e.jsx("div",{style:Zi,children:s(t.description)}),x.map(g=>e.jsx(Gt,{label:g.label,color:g.color,nodes:l.get(g.id),incomingMap:i,siblingMap:a,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(Gt,{label:"其他",nodes:d,incomingMap:i,siblingMap:a,nodeMap:c,renderLink:n})]})},Gt=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:a})=>{const{convert:c}=F();return e.jsxs("div",{style:Qi,children:[e.jsx("div",{style:{...es,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),o.map(l=>e.jsx(Ji,{node:l,incoming:r.get(l.id)??[],siblings:s.get(l.id)??[],nodeMap:i,renderLink:a},l.id))]})},Ji=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical",a=t.bridge,{convert:c}=F();return e.jsxs("div",{style:{...ts,borderStyle:i||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?"var(--bim-bg-subtle, #fafafa)":void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:ns,children:[e.jsx("span",{style:os,children:i||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:rs,children:Pn(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:is,children:[t.category&&e.jsx(Ee,{children:c(t.category)}),t.status==="lost"&&e.jsx(Ee,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Ee,{tone:"warn",children:"残本"}),i&&e.jsx(Ee,{tone:"info",children:"假想祖本"}),a&&e.jsx(Ee,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:ss,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:ls,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Kt,children:[e.jsx("div",{style:Jt,children:"来源:"}),n.map(l=>{const d=r.get(l.source);return e.jsxs("div",{style:qt(l.confidence),children:[e.jsx("span",{style:Xt,children:c(l.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??l.source)}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Yt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Zt,children:["· ",c(l.evidence)]})]},l.id)})]}),o.length>0&&e.jsxs("div",{style:Kt,children:[e.jsx("div",{style:Jt,children:"关联:"}),o.map(l=>{const d=l.source===t.id?l.target:l.source,u=r.get(d);return e.jsxs("div",{style:qt(l.confidence),children:[e.jsx("span",{style:Xt,children:c(l.relation)}),e.jsx("span",{children:(u==null?void 0:u.kind)==="book"&&s?s(u.id,c(u.label)):c((u==null?void 0:u.label)??d)}),e.jsx(Yt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Zt,children:["· ",c(l.evidence)]})]},l.id)})]})]})},Ee=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Yt=({level:t})=>{const o={certain:{label:"确定",color:"#2e7d32"},consensus:{label:"共识",color:"#1976d2"},probable:{label:"推测",color:"#ed6c02"},disputed:{label:"有争议",color:"#c62828"}}[t];return o?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${o.color}`,color:o.color,borderRadius:"8px",marginLeft:"4px"},children:o.label}):null},qi={fontSize:"14px",color:"var(--bim-fg, #333)"},Xi={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Zi={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Qi={marginBottom:"16px"},es={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},ts={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},ns={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},os={fontSize:"15px",fontWeight:600},rs={fontSize:"12px",color:"var(--bim-muted, #777)"},is={marginBottom:"6px"},ss={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},ls={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Kt={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Jt={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},qt=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Xt={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Zt={fontSize:"11px",color:"var(--bim-muted, #888)"},as={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Mn=({selectedNodeId:t,...n})=>{const[o,r]=f.useState("loading"),[s,i]=f.useState(null);return f.useEffect(()=>{let a=!1;return cs().then(c=>{a||(c?(i(c),r("ready")):r("missing"))}),()=>{a=!0}},[]),o==="loading"?e.jsx("div",{style:Qt,children:"加载图组件中…"}):o==="missing"||!s?e.jsxs("div",{style:Qt,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(ds,{modules:s,selectedNodeId:t,...n})};async function cs(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let o=!1;try{await import("@xyflow/react/dist/style.css"),o=!0}catch{o=!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:o}}catch{return null}}const ds=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:a})=>{const{ReactFlow:c,Background:l,Controls:d,Handle:u,Position:x,BaseEdge:g,EdgeLabelRenderer:p,getSmoothStepPath:h,dagre:y}=a,b=f.useMemo(()=>({lineage:w=>{var D,L,T,O;const S=((D=w.data)==null?void 0:D.stepPosition)??.85,[z,E,I]=h({sourceX:w.sourceX,sourceY:w.sourceY,sourcePosition:w.sourcePosition,targetX:w.targetX,targetY:w.targetY,targetPosition:w.targetPosition,stepPosition:S,borderRadius:5}),C=!!((L=w.data)!=null&&L.isSibling),B=C?E:w.targetX-18,H=C?I:w.targetY-12,M=(T=w.data)==null?void 0:T.labelStyle,$=(O=w.data)==null?void 0:O.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:w.id,path:z,style:w.style,markerStart:w.markerStart,markerEnd:w.markerEnd}),w.label&&e.jsx(p,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${B}px,${H}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},children:w.label})})]})}}),[g,p,h]),j=f.useMemo(()=>({version:w=>{const S=w.data,z=S.kind==="hypothetical",E=S.status==="lost",I=S.isSelected,C=S.bridge,B=S.borderColor??"#888",H=C||z?"dashed":"solid",M=C?.5:E?.6:1;return e.jsxs("div",{style:{background:C?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${H} ${I?"#0078d4":B}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":z||C?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(u,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!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:Pn(S.yearText,void 0,S.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[u,x]),{convert:m}=F(),{rfNodes:k,rfEdges:_}=f.useMemo(()=>ps(t,y,n,i,m),[t,y,n,i,m]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(c,{nodes:k,edges:_,nodeTypes:j,edgeTypes:b,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(l,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function ps(t,n,o,r,s=i=>i??""){const c=t.layout==="LR"||!t.layout,l=new n.graphlib.Graph;l.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),l.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??"#888"]));for(const j of t.nodes)l.setNode(j.id,{width:160,height:90});const u=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(u.has(j.relation)||l.setEdge(j.source,j.target));n.layout(l);const x=t.nodes.map(j=>{const m=l.node(j.id),k=r&&j.id===r,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??us(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:o,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:_,draggable:!1,selected:k}}),g=.78,p=.06,h=new Map;for(const j of t.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const y=new Map;for(const[j,m]of h){if(m.length<=1)continue;const k=[...m].sort((v,w)=>{var E,I;const S=((E=l.node(v.target))==null?void 0:E.y)??0,z=((I=l.node(w.target))==null?void 0:I.y)??0;return S-z}),_=k.length;k.forEach((v,w)=>{const S=(w-(_-1)/2)*p;y.set(v.id,g+S)})}const b=t.edges.map(j=>xs(j,y.get(j.id),s));return{rfNodes:x,rfEdges:b}}function xs(t,n,o=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",i=fs(t.confidence),a={type:"arrowclosed",color:i,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:o(t.relation),data:{labelStyle:{color:"#444"},isSibling:s,stepPosition:n},style:{stroke:i,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function us(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function fs(t){switch(t){case"certain":return"#2e7d32";case"consensus":return"#555";case"probable":return"#ed6c02";case"disputed":return"#c62828";default:return"#888"}}const Qt={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)"},gs=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,collection:a,onCollectionChange:c,collectionsAvailable:l,collectionCounts:d,className:u,style:x})=>{var m;const[g,p]=f.useState(n),h=k=>{p(k),i==null||i(k)},y=(()=>{if(!l)return[];const k=Object.entries(l);return k.length===0||l.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),b=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const j=a?(m=l==null?void 0:l[a])==null?void 0:m.description:void 0;return e.jsxs("div",{className:u,style:x,children:[e.jsxs("div",{style:hs,children:[e.jsx("button",{onClick:()=>h("list"),style:tt(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:tt(g==="graph"),children:"关系图"}),b&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),y.map(([k,_])=>{const v=d==null?void 0:d[k];return e.jsxs("button",{onClick:()=>c==null?void 0:c(k),style:tt(a===k),title:_.description,children:[_.label,v!=null?` ${v}`:""]},k)})]})]}),b&&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(An,{graph:t,renderLink:o}):e.jsx(Mn,{graph:t,renderLink:o,height:r,selectedNodeId:s})]})},hs={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},tt=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"}),bs=({style:t})=>{const n=f.useContext(Pe);if(!n)return null;const{locale:o,setLocale:r}=n,s=o==="zh-Hant",i=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:i,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:"简"})]})},ms=({href:t,label:n="在 GitHub 查看本条目源文件",size:o=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:i=>{i.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:i=>{i.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:o,height:o,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"})})});exports.BidLink=N.BidLink;exports.BookIndexError=N.BookIndexError;exports.BookIndexManager=N.BookIndexManager;exports.BookIndexStorage=N.BookIndexStorage;exports.BundleStorage=N.BundleStorage;exports.ConfigError=N.ConfigError;exports.GithubStorage=N.GithubStorage;exports.IdGenerationError=N.IdGenerationError;exports.IdGenerator=N.IdGenerator;exports.LocalStorage=N.LocalStorage;exports.MigrationError=N.MigrationError;exports.StorageError=N.StorageError;exports.base36Decode=N.base36Decode;exports.base36Encode=N.base36Encode;exports.base58Decode=N.base58Decode;exports.buildId=N.buildId;exports.cleanName=N.cleanName;exports.decodeId=N.decodeId;exports.decodeIdString=N.decodeIdString;exports.encodeId=N.encodeId;exports.extractIdFromUrl=N.extractIdFromUrl;exports.extractStatus=N.extractStatus;exports.extractType=N.extractType;exports.normalizeCatalog=N.normalizeCatalog;exports.parseId=N.parseId;exports.shardOf=N.shardOf;exports.smartDecode=N.smartDecode;exports.validateResource=N.validateResource;exports.Badge=Ne;exports.BidUrlProvider=Jn;exports.CollatedEdition=jn;exports.CollectionCatalog=fn;exports.CreateEntityDialog=Tn;exports.EmendatedBySection=xn;exports.EntityDetail=ln;exports.EntityPickerDialog=En;exports.EntitySelector=In;exports.FeedbackButton=Bi;exports.FeedbackDialog=$n;exports.FeedbackForm=$i;exports.FeedbackList=Sn;exports.FormInput=re;exports.FormTextArea=me;exports.HomePage=it;exports.IndexApp=Hr;exports.IndexBrowser=ot;exports.IndexDetail=at;exports.IndexEditor=Ln;exports.IndexView=Si;exports.LocaleContext=Pe;exports.LocaleProvider=ro;exports.LocaleToggle=bs;exports.ModeIndicator=rn;exports.RelationPanel=Cn;exports.RepoSourceLink=ms;exports.ResourceEditor=nt;exports.ResourceList=lt;exports.SearchInput=sn;exports.Section=se;exports.SmartBidInput=Ve;exports.SourceEditor=kn;exports.VersionLineageGraph=Mn;exports.VersionLineageList=An;exports.VersionLineageView=gs;exports.WorkCatalog=Or;exports.buildLineageGraph=Yi;exports.detailToEditor=Wn;exports.editorToDetail=ji;exports.formatTemplate=Ae;exports.parseSourceString=wn;exports.stringifySources=_n;exports.useBidUrl=ae;exports.useConvert=F;exports.useT=A;exports.validateLineageGraph=Ki;