book-index-ui 0.2.17 → 0.2.19
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 +3 -3
- package/dist/index.d.ts +12 -29
- package/dist/index.js +1988 -1944
- package/dist/storage-entry-D6KFK-rC.cjs +1 -0
- package/dist/{storage-entry-LFNLxpLe.js → storage-entry-Ysz_rfdh.js} +493 -638
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +12 -29
- package/dist/storage.js +1 -1
- package/package.json +1 -1
- package/dist/storage-entry-DSWcaKQ3.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var Pn=Object.create;var ct=Object.defineProperty;var An=Object.getOwnPropertyDescriptor;var Fn=Object.getOwnPropertyNames;var Mn=Object.getPrototypeOf,Hn=Object.prototype.hasOwnProperty;var Dn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Fn(n))!Hn.call(t,s)&&s!==o&&ct(t,s,{get:()=>n[s],enumerable:!(r=An(n,s))||r.enumerable});return t};var Ce=(t,n,o)=>(o=t!=null?Pn(Mn(t)):{},Dn(n||!t||!t.__esModule?ct(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const U=require("./storage-entry-DSWcaKQ3.cjs"),e=require("react/jsx-runtime"),f=require("react"),On=require("react-dom"),Vn=t=>`/book-index?id=${t}`,Xt=f.createContext(Vn);function Un({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(Xt.Provider,{value:o,children:n})}function le(){return f.useContext(Xt)}function he(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Nn(t,n){return he(t).includes(n)}const Qt={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Gn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Yn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},We=f.createContext(null),en={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:"圖片資源"}},Kn={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:"图片资源"}},Jn={"zh-Hant":en,"zh-Hans":Kn},tn="bim-locale";function qn(){try{const t=localStorage.getItem(tn);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Zn(t){try{localStorage.setItem(tn,t)}catch{}}const Xn="zh-Hant",Qn=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=f.useState(t??Xn),i=t??r;f.useEffect(()=>{if(t)return;const u=qn();u&&u!==r&&s(u)},[]);const[l,a]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const p=u.Converter({from:"tw",to:"cn"});a(()=>p)}).catch(()=>{a(()=>u=>u)}):a(null)},[i]);const c=f.useCallback(u=>{s(u),Zn(u),n==null||n(u)},[n]),x=f.useMemo(()=>({locale:i,setLocale:c,messages:Jn[i],converter:l}),[i,c,l]);return e.jsx(We.Provider,{value:x,children:o})};function F(){const t=f.useContext(We);return(t==null?void 0:t.messages)??en}const eo=2e3;function D(){const t=f.useContext(We),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(l=>{if(!l)return"";if(!o)return l;const a=r.current.get(l);if(a!==void 0)return a;const c=o(l);if(r.current.size>=eo){const x=r.current.keys().next().value;x!==void 0&&r.current.delete(x)}return r.current.set(l,c),c},[o]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function $e(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function to(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 no(){return{id:"",name:"",url:"",type:"text",details:""}}const Qe=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=F(),[l,a]=f.useState(null),c=[{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}],x=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],u=y=>{if(!s)return!0;const k=he(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},p=t.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>u(y)),g=()=>{const y=no();s&&(y.type=s),n([...t,y]),a(t.length)},d=y=>{n(t.filter((k,I)=>I!==y)),a(null)},m=(y,k,I)=>{const v=[...t];if(v[y]={...v[y],[k]:I},k==="url"&&!v[y].id){const w=to(I);w&&(v[y].id=w)}n(v)},b=(y,k,I)=>{const w={...t[y].metadata||{}};I?w[k]=I:delete w[k],m(y,"metadata",Object.keys(w).length>0?w:void 0)},h=(y,k)=>{const I=k.trim()?k.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;m(y,"structure",I)},S=(y,k,I)=>{const w=t[y].coverage||{level:1,ranges:""};k==="level"?w.level=parseInt(I)||1:w.ranges=I,m(y,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[p.map(({item:y,originalIndex:k})=>{var I,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:()=>a(l===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:oo(y.type??"text"),color:"#fff"},children:(()=>{var z,E;const j=he(y);return j.length===0?y.type??"text":j.length===1?((z=c.find(W=>W.value===j[0]))==null?void 0:z.label)??j[0]:j.includes("text")&&j.includes("image")?((E=c.find(W=>W.value==="text+image"))==null?void 0:E.label)??"text+image":j.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${i.editor.resourcePlaceholder} ${k+1}`}),y.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:j=>j.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&y.url&&ro(k,r==null?void 0:r[k],o,i),e.jsx("button",{onClick:j=>{j.stopPropagation(),d(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Nn(y,"image")&&y.url&&io(y,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:_e,children:[e.jsx("span",{style:ze,children:i.label.type}),e.jsx("select",{value:y.type,onChange:j=>m(k,"type",j.target.value),style:{...de,flex:1},children:c.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]}),e.jsxs("label",{style:_e,children:[e.jsx("span",{style:ze,children:i.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:j=>m(k,"root_type",j.target.value),style:{...de,flex:1},children:x.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:y.id,onChange:j=>m(k,"id",j.target.value),placeholder:i.editor.idAutoExtract,style:{...de,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:y.name,onChange:j=>m(k,"name",j.target.value),placeholder:i.editor.resourceName,style:{...de,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:j=>m(k,"url",j.target.value),placeholder:i.editor.resourceUrl,style:de}),e.jsx("input",{type:"text",value:((I=y.structure)==null?void 0:I.join("、"))||"",onChange:j=>h(k,j.target.value),placeholder:i.editor.structurePlaceholder,style:de}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:_e,children:[e.jsx("span",{style:ze,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((v=y.coverage)==null?void 0:v.level)??"",onChange:j=>S(k,"level",j.target.value),placeholder:"1",style:{...de,width:"60px"}})]}),e.jsxs("label",{style:{..._e,flex:1},children:[e.jsx("span",{style:ze,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=y.coverage)==null?void 0:w.ranges)||"",onChange:j=>S(k,"ranges",j.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...de,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:j=>m(k,"details",j.target.value),placeholder:i.editor.detailsPlaceholder,style:{...de,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(([j,z])=>{var E;return e.jsxs("label",{style:{..._e,gap:"4px"},children:[e.jsx("span",{style:{...ze,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((E=y.metadata)==null?void 0:E[j])||"",onChange:W=>b(k,j,W.target.value),placeholder:z,style:{...de,flex:1}})]},j)})})]})]})]})]},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 oo(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function ro(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:l=>{l.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 io(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 de={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"},_e={display:"flex",alignItems:"center",gap:"6px"},ze={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},so={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function lo(t){try{const n=new URL(t).hostname;return so[n]}catch{return}}const dt={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function ao(t){return t.includes("text")&&t.includes("image")?dt["text+image"]:dt[t[0]||"physical"]}const pt={text:0,image:1,physical:2};function De(t){return t.length===0?"physical":[...t].sort((n,o)=>(pt[n]??99)-(pt[o]??99)).join("+")}function co(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const a=i.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const l=t[i];if(l.volumes&&l.volumes.length>0)continue;const a=n(l.name);if(!a)continue;const[c,x]=a,u=`${c}|${De(he(l))}`;o.has(u)||o.set(u,{base:{...l,name:c,url:"",volumes:[]},volumes:[]}),o.get(u).volumes.push({volume:x,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((l,a)=>l.volume-a.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let l=0;l<t.length;l++)if(s.has(l)){const a=n(t[l].name),c=a&&`${a[0]}|${De(he(t[l]))}`,x=`${i.base.name}|${De(he(i.base))}`;c===x&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const ot=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=F(),i=f.useMemo(()=>co(t||[]),[t]),l={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},a=p=>l[p]?l[p]:p.split("+").map(g=>l[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((p,g)=>e.jsx(xt,{item:p},p.id||g))});const c=new Map;for(const p of i){const g=De(he(p));c.has(g)||c.set(g,[]),c.get(g).push(p)}const x=["text","image","text+image","physical"],u=[...x.filter(p=>c.has(p)),...[...c.keys()].filter(p=>!x.includes(p)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:u.map(p=>{const g=c.get(p),d=ao(p.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:d,whiteSpace:"nowrap",flexShrink:0},children:a(p)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:g.map((m,b)=>e.jsx(xt,{item:m,onNavigate:o,renderLink:r},m.id||b))})]},p)})})};function po(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 xo(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 uo(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 fo={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},xt=({item:t})=>{const n=F(),{convert:o}=D(),[r,s]=f.useState(!1),i=f.useMemo(()=>(t.url?lo(t.url):void 0)||o(t.name),[t.url,t.name,o]),l=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(m=>({...m,url:m.url||uo(m)})),[t.volumes]),a=l&&l.length>0,c=a?new Set(l.filter(m=>m.status!=="missing").map(m=>m.volume)).size:0,x=a?new Set(l.filter(m=>m.status==="missing").map(m=>m.volume)).size:0,u=t.expected_volumes??(a?c+x:0),p=t.color_mode?{...fo[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!a?o(t.details):null,d={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:d,children:[e.jsx("span",{style:{fontWeight:500},children:i}),p&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:p.bg,color:p.fg},children:p.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),a&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c,"/",u,n.unit.volume,x>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",x]})]}),t.url&&e.jsx("a",{href:(()=>{const m=xo(t.metadata);return m?po(t.url,m):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),a&&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?"▲":"▼"})]}),a&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(m=>{const b=m.status==="missing";return m.url&&!b?e.jsx("a",{href:m.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:m.volume},m.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:b?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:b?"line-through":"none",opacity:b?.6:1},children:m.volume},m.volume)})})]})},nn=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:l})=>{const a=F(),c=t==="local",x=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",p=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)"},d={onMouseOver:b=>b.currentTarget.style.opacity="0.8",onMouseOut:b=>b.currentTarget.style.opacity="1"},m=e.jsxs("div",{onClick:s,title:x?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...g,background:x?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...d,children:[e.jsx("span",{children:x?"📝":"📚"}),e.jsx("span",{children:x?"draft":"official"})]});return o==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[m,e.jsxs("div",{onClick:r,title:a.mode.switchToSync,style:g,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:u||a.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...d,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[m,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:a.mode.switchToLocal,style:g,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:p||a.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...d,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:c?a.mode.switchToGithub:a.mode.switchToLocal,style:g,...d,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:l,title:u||a.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...d,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]}),!c&&p&&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:p})]})]})},Ne="bim-search-history",ut=10,ft=8;function Re(){try{const t=localStorage.getItem(Ne);return t?JSON.parse(t):[]}catch{return[]}}function go(t){try{const n=Re().filter(o=>o!==t);n.unshift(t),n.length>ut&&(n.length=ut),localStorage.setItem(Ne,JSON.stringify(n))}catch{}}function ho(t){try{const n=Re().filter(o=>o!==t);localStorage.setItem(Ne,JSON.stringify(n))}catch{}}function bo(){try{localStorage.removeItem(Ne)}catch{}}const on=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=F(),a=i??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[x,u]=f.useState(!1),[p,g]=f.useState([]),[d,m]=f.useState(-1),[b,h]=f.useState(null),[S,y]=f.useState(Re),k=f.useRef(null),I=f.useRef(null),v=f.useRef(null),w=f.useRef(!1),j=f.useCallback(()=>{w.current||!t.getAllEntries||(w.current=!0,t.getAllEntries().then(C=>{h(C)}).catch(()=>{w.current=!1}))},[t]),z=f.useCallback(C=>{if(!C.trim())return S.map(L=>({type:"history",text:L}));if(!b)return[];const P=C.toLowerCase(),T=[],_=[];for(const L of b){if(T.length+_.length>=ft*2)break;const B=(L.title??"").toLowerCase();if(B.startsWith(P))T.push({type:"entry",text:L.title,entry:L});else if(B.includes(P))_.push({type:"entry",text:L.title,entry:L});else{const M=[...L.additional_titles||[],...L.attached_texts||[]];for(const O of M){const K=typeof O=="string"?O:O==null?void 0:O.book_title;if(K!=null&&K.toLowerCase().includes(P)){T.push({type:"entry",text:`${L.title}`,entry:L});break}}}}return[...T,..._].slice(0,ft)},[b,S]);f.useEffect(()=>{g(z(n)),m(-1)},[n,z]),f.useEffect(()=>{const C=P=>{v.current&&!v.current.contains(P.target)&&u(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),f.useEffect(()=>{const C=P=>{var T,_;if(P.key==="/"&&document.activeElement!==k.current){const L=(T=document.activeElement)==null?void 0:T.tagName;if(L==="INPUT"||L==="TEXTAREA"||L==="SELECT")return;P.preventDefault(),(_=k.current)==null||_.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const E=f.useCallback(C=>{C.trim()&&(go(C.trim()),y(Re())),r(C),u(!1)},[r]),W=f.useCallback(C=>{C.type==="history"?(o(C.text),E(C.text)):C.entry&&(s?(s(C.entry),u(!1)):(o(C.text),E(C.text)))},[o,E,s]),$=f.useCallback(C=>{if(!x||p.length===0){C.key==="Enter"&&E(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),m(P=>(P+1)%p.length);break;case"ArrowUp":C.preventDefault(),m(P=>(P-1+p.length)%p.length);break;case"Enter":C.preventDefault(),d>=0&&d<p.length?W(p[d]):E(n);break;case"Escape":C.preventDefault(),u(!1);break}},[x,p,d,n,E,W]),V=f.useCallback((C,P)=>{P.stopPropagation(),ho(C),y(Re()),g(T=>T.filter(_=>!(_.type==="history"&&_.text===C)))},[]),Y=f.useCallback(C=>{C.stopPropagation(),bo(),y([]),g([])},[]);f.useEffect(()=>{if(d>=0&&I.current){const C=I.current.children;C[d]&&C[d].scrollIntoView({block:"nearest"})}},[d]);const N=!n.trim()&&S.length>0;return e.jsxs("div",{ref:v,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:k,type:"text",placeholder:a,value:n,onChange:C=>{o(C.target.value),u(!0),j()},onFocus:()=>{u(!0),j()},onKeyDown:$,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"}}),x&&p.length>0&&e.jsxs("div",{ref:I,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:[N&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:Y,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),p.map((C,P)=>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:P===d?"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:[c[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:T=>V(C.text,T),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${C.type}-${C.text}-${P}`))]})]})},Be="bim-recent-ids",gt="bim-recent-entries",ht=50,qe=5,mo=50,yo=200;function Ee(){try{const t=localStorage.getItem(Be);if(t)return JSON.parse(t);const n=localStorage.getItem(gt);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(Be,JSON.stringify(o)),localStorage.removeItem(gt),o}return[]}catch{return[]}}function vo(t){try{const n=Ee().filter(o=>o!==t);n.unshift(t),n.length>ht&&(n.length=ht),localStorage.setItem(Be,JSON.stringify(n))}catch{}}function jo(t){try{const n=Ee().filter(o=>o!==t);localStorage.setItem(Be,JSON.stringify(n))}catch{}}function So(){try{localStorage.removeItem(Be)}catch{}}const ko={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},et=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c,hideModeIndicator:x,initialQuery:u,onQueryChange:p,headerRight:g})=>{const d=F(),m=[{type:"work",icon:"✍️",name:d.indexType.work,key:"works"},{type:"book",icon:"📖",name:d.indexType.book,key:"books"},{type:"collection",icon:"📚",name:d.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:d.indexType.entity,key:"entities"}],[b,h]=f.useState(u??""),[S,y]=f.useState(null),[k,I]=f.useState(null),[v,w]=f.useState(!1),[j,z]=f.useState(null),[E,W]=f.useState(""),[$,V]=f.useState(!u),[Y,N]=f.useState(Ee),[C,P]=f.useState([]),[T,_]=f.useState(!1),[L,B]=f.useState(!1),[M,O]=f.useState(null),[K,te]=f.useState(null),ge=f.useRef(void 0),fe=f.useRef(!1),X=f.useCallback(async(A,q)=>{if(!A.trim()){V(!0),y(null),I(null);return}V(!1),w(!0),W("");try{if(t.searchAll){const G=await t.searchAll(A,q??qe);y(G)}else{const G=["work","book","collection","entity"],J=await Promise.all(G.map(Q=>t.search(A,Q,{page:1,pageSize:q??qe})));y({works:J[0].entries,books:J[1].entries,collections:J[2].entries,entities:J[3].entries,totalWorks:J[0].total,totalBooks:J[1].total,totalCollections:J[2].total,totalEntities:J[3].total})}}catch(G){W(G instanceof Error?G.message:String(G)),y(null)}finally{w(!1)}},[t]);f.useEffect(()=>{let A=!1;const q=()=>{var H,ne;const G=["work","book","collection","entity"],J=Promise.all(G.map(ae=>t.loadEntries(ae,{page:1,pageSize:1}).catch(()=>({total:0})))),Q=((H=t.getResourceCounts)==null?void 0:H.call(t).catch(()=>null))??Promise.resolve(null),R=((ne=t.getSubtypeStats)==null?void 0:ne.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([J,Q,R]).then(([ae,ce,at])=>{A||(O({works:ae[0].total,books:ae[1].total,collections:ae[2].total,entities:ae[3].total,hasText:ce==null?void 0:ce.hasText,hasImage:ce==null?void 0:ce.hasImage}),at&&te(at))})};return t.getCounts?t.getCounts().then(G=>{var J,Q;A||(O({works:G.works,books:G.books,collections:G.collections,entities:G.entities,hasText:(J=G.resourceCounts)==null?void 0:J.hasText,hasImage:(Q=G.resourceCounts)==null?void 0:Q.hasImage}),G.subtypeStats&&te(G.subtypeStats))}).catch(()=>{A||q()}):q(),()=>{A=!0}},[t]),f.useEffect(()=>{fe.current||!(u!=null&&u.trim())||(fe.current=!0,X(u))},[u,X]);const Z=f.useCallback(A=>{if(h(A),p==null||p(A),!A.trim()){V(!0),y(null),I(null);return}ge.current&&clearTimeout(ge.current),ge.current=setTimeout(()=>{I(null),X(A)},yo)},[X,p]),Ge=f.useCallback(A=>{ge.current&&clearTimeout(ge.current),p==null||p(A),X(A)},[X,p]),Ye=f.useCallback(A=>{I(A),X(b,mo)},[b,X]);f.useEffect(()=>{if(!Y.length){P([]);return}let A=!1;return _(!0),Promise.all(Y.slice(0,10).map(async q=>{var G,J,Q;try{if(t.getEntry){const H=await t.getEntry(q);if(H)return H}const R=await t.getItem(q);if(R){const H=R.authors;return{id:q,title:R.title||q,type:R.type||"work",author:(G=H==null?void 0:H[0])==null?void 0:G.name,dynasty:(J=H==null?void 0:H[0])==null?void 0:J.dynasty,role:(Q=H==null?void 0:H[0])==null?void 0:Q.role,edition:R.edition||void 0}}}catch{}return{id:q,title:q,type:"work",notFound:!0}})).then(q=>{A||(P(q),_(!1))}),()=>{A=!0}},[Y,t]);const ke=A=>{z(A.id),vo(A.id),N(Ee()),r==null||r(A)},we=A=>{jo(A),N(Ee())},Ke=()=>{So(),N([])},Pe=A=>m.find(q=>q.type===A),Je=S&&(S.works.length>0||S.books.length>0||S.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:d.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!x&&e.jsx(nn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(on,{transport:t,value:b,onChange:Z,onSearch:Ge,onEntrySelect:ke}),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:d.action.newEntry})]}),M&&$&&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:K?e.jsxs(e.Fragment,{children:[(K.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()})," 本"]}),K.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.article.toLocaleString()})," 篇"]}):null,K.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.collections.toLocaleString()}),M.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.entities.toLocaleString()})]})]})}),M.hasImage!=null&&M.hasText!=null&&e.jsxs("span",{children:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:M.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:d.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})]}):$?e.jsx("div",{style:{flex:1},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.loading}):C.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:d.search.recentBrowse}),e.jsx("button",{onClick:Ke,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:d.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:C.slice(0,L?10:3).map(A=>A.notFound?e.jsx(wo,{id:A.id,onRemove:we,t:d},A.id):e.jsx(bt,{entry:A,selected:j===A.id,onClick:ke,getConfig:Pe,onRemove:we},A.id))}),!L&&C.length>3&&e.jsx("button",{onClick:()=>B(!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:d.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:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):Je?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:A,icon:q,name:G,key:J})=>{const Q=S[J]??[],R=ko[J],H=S[R]??0;if(Q.length===0)return null;const ae=!(k===A)&&H>qe;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:[q," ",G,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[H," ",d.unit.items]})]}),ae&&e.jsx("button",{onClick:()=>Ye(A),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:Q.map(ce=>e.jsx(bt,{entry:ce,selected:j===ce.id,onClick:ke,getConfig:Pe,query:b},ce.id))})]},A)})}):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:$e(d.search.noResultsFor,{query:b})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},bt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=F(),{convert:a}=D(),c=[...t.additional_titles||[],...t.attached_texts||[]],x=s&&c.length?c.find(u=>{const p=typeof u=="string"?u:u==null?void 0:u.book_title;return p==null?void 0:p.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:a(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]}),t.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??"?"]})]}),x&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",a(x)]})]}),i?e.jsx("button",{onClick:u=>{u.stopPropagation(),i(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},wo=({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 Co(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 _o({data:t}){const{convert:n}=D(),{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 zo({alt_names:t}){const{convert:n}=D(),o=new Map;for(const i of t){const l=i.type||"別名";o.has(l)||o.set(l,[]),o.get(l).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,l)=>{const a=r.indexOf(i),c=r.indexOf(l);return a===-1&&c===-1?0:a===-1?1:c===-1?-1:a-c});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const l=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:l.map((a,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(a)]},c))})]},i)})})}function Io({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 To({works:t,transport:n,onNavigate:o,renderLink:r}){const s=F(),{convert:i}=D(),l=le(),[a,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const d=t.map(b=>b.work_id);return(async()=>{const b=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(d);let I=!0;for(let v=0;v<d.length;v++){const w=k[v];w!=null&&w.title?b.set(d[v],w.title):w!=null&&w.primary_name?b.set(d[v],w.primary_name):I=!1}if(I)return b}catch{}if(n.getAllEntries)try{const k=await n.getAllEntries(),I=new Map(k.map(w=>[w.id,w.title||w.primary_name||w.id]));let v=!0;for(const w of d){const j=I.get(w);j?b.set(w,j):v=!1}if(v)return b}catch{}const h=[...d],S=8,y=new Array(S).fill(0).map(async()=>{for(;h.length;){const k=h.shift();if(!k)break;if(!b.has(k))try{if(n.getEntry){const w=await n.getEntry(k);if(w!=null&&w.title){b.set(k,w.title);continue}}const I=await n.getItem(k),v=I&&(I.title||I.primary_name)||k;b.set(k,v)}catch{b.set(k,k)}}});return await Promise.all(y),b})().then(b=>{g||c(b)}),()=>{g=!0}},[t,n]);const x=new Map;for(const g of t){const d=g.role||"";x.has(d)||x.set(d,[]),x.get(d).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],p=[...x.keys()].sort((g,d)=>{const m=u.indexOf(g),b=u.indexOf(d);return m===-1&&b===-1?g.localeCompare(d):m===-1?1:b===-1?-1:m-b});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,")"]})]}),p.map(g=>{const d=x.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:["(",d.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:d.map((m,b)=>{const h=i(a.get(m.work_id)||m.work_id);return r?e.jsx("li",{children:r(m.work_id,h)},b):o?e.jsx("li",{children:e.jsx("a",{href:l(m.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),o(m.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:h})},b):e.jsx("li",{children:h},b)})})]},g)})]})}const rn=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var u;const i=F(),{convert:l}=D();let a=!1;try{a=U.extractStatus(t.id)==="draft"}catch{}const c=Co(t),x=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:[l(t.primary_name),e.jsx(_o,{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}),x&&t.subtype!=="people"&&e.jsx("span",{children:x}),a&&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})]}),c&&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(zo,{alt_names:t.alt_names}),e.jsx(Io,{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:l(t.description.text)}),t.works&&t.works.length>0&&e.jsx(To,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},Ro=["〇","一","二","三","四","五","六","七","八","九"],mt=["","十","百","千"];function sn(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 l=parseInt(n[i]),a=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&a===1&&i===0?r+=mt[a]:r+=Ro[l]+mt[a])}return r}function ln({type:t}){const n=F(),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 Eo({isDraft:t}){const n=F();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 Lo({id:t}){const n=F(),[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 re({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 pe({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 an({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const a=s(i.name),c=i.entity_id?e.jsx(se,{id:i.entity_id,label:a,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:a});return e.jsxs("span",{children:[l>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),"〕"]}),c,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},l)})})}function se({id:t,label:n,onNavigate:o,renderLink:r}){const s=le();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 Bo({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:l,meta:a,headerExtra:c,onNavigate:x,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}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(ln,{type:r}),e.jsx(Eo,{isDraft:s}),e.jsx(Lo,{id:t})]}),((i==null?void 0:i.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(an,{authors:i,type:r,onNavigate:x,renderLink:u}),a]})]})}function cn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=F(),{convert:l}=D();if(!t.length)return null;const[a,c]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(re,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((x,u)=>{const p=a===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...p?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>c(p?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:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(x.source)}),!p&&o&&x.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(x.title_info)}),x.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(se,{id:x.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),p&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(x.title_info||x.author_info||x.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[x.title_info&&e.jsx(pe,{label:i.label.titleInfo,children:l(x.title_info)}),x.author_info&&e.jsx(pe,{label:i.label.authorInfo,children:l(x.author_info)}),x.edition&&e.jsx(pe,{label:i.label.edition,children:l(x.edition)})]}),x.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:l(x.summary)})]}),x.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:l(x.comment)})]}),x.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:l(x.additional_comment)})]})]})]},u)})})]})}function Wo({items:t,onNavigate:n,renderLink:o}){const r=F();return e.jsx(cn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function dn({items:t,onNavigate:n,renderLink:o}){const r=F();return e.jsx(cn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function pn({label:t,items:n}){const{convert:o}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(re,{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 $o({items:t}){const n=F();return e.jsx(pn,{label:n.section.aliases,items:t})}function Po({items:t}){const n=F();return e.jsx(pn,{label:n.section.attachedTexts,items:t})}function Ao({items:t}){const n=F(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(re,{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 Fo({items:t}){const n=F(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(re,{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 Mo({items:t}){const n=F(),{convert:o}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(re,{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 yt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=D(),[l,a]=f.useState([]);return f.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(x=>({id:x})));return}let c=!1;return Promise.all(n.map(x=>o.getItem(x).then(u=>({id:x,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:x})))).then(x=>{c||a(x)}),()=>{c=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(re,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(c=>({id:c}))).map(c=>{const x=c.edition?`${i(c.title)||c.id}(${i(c.edition)})`:i(c.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(se,{id:c.id,label:x,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Ho({book:t,onNavigate:n,renderLink:o}){const r=F(),{convert:s}=D(),[i,l]=f.useState(!1),a=t.resources&&t.resources.length>0,c=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:"10px 14px",borderBottom:a&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(se,{id:t.id,label:c,onNavigate:n,renderLink:o})}),a&&e.jsx("span",{onClick:()=>l(x=>!x),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:"▼"})]}),a&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(ot,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Do({ids:t,transport:n,onNavigate:o,renderLink:r,footer:s}){const i=F(),[l,a]=f.useState([]);return f.useEffect(()=>{if(!t.length){a([]);return}if(!n){a(t.map(x=>({id:x})));return}let c=!1;return Promise.all(t.map(x=>n.getItem(x).then(u=>({id:x,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:x})))).then(x=>{c||a(x)}),()=>{c=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(re,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),s,e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:(l.length?l:t.map(c=>({id:c}))).map(c=>e.jsx(Ho,{book:c,onNavigate:o,renderLink:r},c.id))})]}):null}function Oo({workData:t,onNavigate:n,renderLink:o}){var i,l,a;const r=F(),{convert:s}=D();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:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(ln,{type:"work"}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(se,{id:t.id,label:s(t.title),onNavigate:n,renderLink:o})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((i=t.juan_count)==null?void 0:i.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[sn(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(an,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((l=t.description)==null?void 0:l.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children:s(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",fontSize:"13px"},children:e.jsx(pe,{label:r.label.parentWork,children:e.jsx(se,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Vo({items:t,onNavigate:n,renderLink:o}){const r=F(),{convert:s}=D();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(se,{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:$e(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const rt=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:l,className:a,style:c})=>{var V,Y,N,C,P,T;const x=F(),{convert:u}=D(),[p,g]=f.useState(null),[d,m]=f.useState(!1),[b,h]=f.useState(null),[S,y]=f.useState(null),[k,I]=f.useState([]),v=t||p;if(f.useEffect(()=>{if(t||!n||!o)return;let _=!1;return m(!0),h(null),o.getItem(n).then(L=>{_||(L?g(L):h(x.misc.notFoundEntry))}).catch(L=>{_||h(L instanceof Error?L.message:x.misc.loadFailed)}).finally(()=>{_||m(!1)}),()=>{_=!0}},[t,n,o]),f.useEffect(()=>{if(!v||!o){y(null),I([]);return}let _=!1;const L=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(L?o.getItem(L).then(B=>{!_&&B&&B.type==="work"&&y(B)}).catch(()=>{}):y(null),v.type==="book"){const B=v;B.contained_in&&B.contained_in.length>0?Promise.all(B.contained_in.map(M=>{const O=typeof M=="string"?M:M.id,K=typeof M=="string"?void 0:M.volume_index;return o.getItem(O).then(te=>({id:O,title:te&&te.title||O,volume_index:K})).catch(()=>({id:O,title:O,volume_index:K}))})).then(M=>{_||I(M)}):I([])}else I([]);return()=>{_=!0}},[v,o]),d)return e.jsx("div",{className:a,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((_,L)=>e.jsx("div",{style:{height:L===1?"32px":"16px",width:`${_}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},L))})});if(b)return e.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:b});if(!v)return null;if(v.type==="entity")return e.jsx("div",{className:a,style:c,children:e.jsx(rn,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const w=v.type==="book"?v:null,j=v.type==="collection"?v:null,z=v.type==="work"?v:null;let E=!1;try{E=U.extractStatus(v.id)==="draft"}catch{}let W="";v.measure_info?W=u(v.measure_info):(V=v.juan_count)!=null&&V.number?W=sn(v.juan_count.number)+x.unit.juan:(Y=v.juan_count)!=null&&Y.description&&(W=u(v.juan_count.description));const $=[];return(N=v.publication_info)!=null&&N.year&&$.push(e.jsx(pe,{label:x.label.year,children:v.publication_info.year},"year")),(C=v.current_location)!=null&&C.name&&$.push(e.jsx(pe,{label:x.label.currentLocation,children:u(v.current_location.name)},"loc")),(P=v.page_count)!=null&&P.description&&$.push(e.jsx(pe,{label:x.label.pageCount,children:v.page_count.description},"page")),w!=null&&w.edition&&$.push(e.jsx(pe,{label:x.label.edition,children:u(w.edition)},"ver")),z!=null&&z.parent_work&&$.push(e.jsx(pe,{label:x.label.parentWork,children:e.jsx(se,{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&&$.push(e.jsx(pe,{label:x.label.parentWork,children:z.parent_works.map((_,L)=>e.jsxs("span",{children:[L>0&&"、",e.jsx(se,{id:_,onNavigate:r,renderLink:s})]},_))},"pws")),e.jsxs("div",{className:a,style:c,children:[e.jsx(Bo,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:E,authors:v.authors,volumeText:W,meta:$,headerExtra:i,onNavigate:r,renderLink:s}),((T=v.description)==null?void 0:T.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(v.description.text)}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(re,{children:x.section.containedIn}),e.jsx(Vo,{items:k,onNavigate:r,renderLink:s})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx(re,{children:x.section.belongsToWork}),e.jsx(Oo,{workData:S,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&e.jsx(Ao,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&e.jsx($o,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&e.jsx(Po,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&e.jsx(Wo,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&e.jsx(dn,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(re,{children:x.section.resources}),e.jsx(ot,{items:v.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(Fo,{items:w.location_history}),(j==null?void 0:j.history)&&j.history.length>0&&e.jsx(Mo,{items:j.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(yt,{title:x.section.relatedVersions,ids:w.related_books,transport:o,onNavigate:r,renderLink:s}),(j==null?void 0:j.books)&&j.books.length>0&&e.jsx(yt,{title:x.section.containedBooks,ids:j.books,transport:o,onNavigate:r,renderLink:s}),(j==null?void 0:j.contained_works)&&j.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(re,{children:[x.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",j.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.contained_works.map(_=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(se,{id:_.id,label:u(_.title),onNavigate:r,renderLink:s})},_.id))})]}),(z==null?void 0:z.books)&&z.books.length>0&&e.jsx(Do,{ids:z.books,transport:o,onNavigate:r,renderLink:s,footer:l}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const _=[],L=z.related_works.filter(O=>O.relation==="part_of"),B=z.related_works.filter(O=>O.relation==="has_part"),M=z.related_works.filter(O=>!O.relation);return L.length>0&&_.push({label:x.section.belongsToWork,items:L}),B.length>0&&_.push({label:x.section.containedWorks,items:B}),M.length>0&&_.push({label:x.section.relatedWorks,items:M}),_.map(O=>e.jsxs("div",{children:[e.jsxs(re,{children:[O.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",O.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:O.items.map(K=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(se,{id:K.id,label:u(K.title),onNavigate:r,renderLink:s})},K.id))})]},O.label))})()]})};function Uo({data:t}){const n=F(),{convert:o}=D(),{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 No({sections:t,activeSection:n,onSelect:o}){const r=F();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:vt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:vt(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 vt(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 Go({id:t,label:n,onNavigate:o,renderLink:r}){const s=le();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 Yo(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 jt({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=F(),{convert:i}=D(),l=t.book_id||t.work_id,a=r&&t.volumes.length>0?Yo(t.volumes,s.unit.volume):null,c=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:a}),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(x=>i(x)).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:c?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Go,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const xn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const a=F(),[c,x]=f.useState(null),[u,p]=f.useState(!1),[g,d]=f.useState(null),[m,b]=f.useState(null),[h,S]=f.useState(""),y=t||c;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let j=!1;return p(!0),d(null),o.getCollectionCatalog(n).then(z=>{j||(z?x(z):d(a.catalog.notFound))}).catch(z=>{j||d(z instanceof Error?z.message:a.catalog.loadFailed)}).finally(()=>{j||p(!1)}),()=>{j=!0}},[t,n,o,a]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,I=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const j=y.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(j).size<j.length},[y]),v=f.useMemo(()=>{if(!y)return[];let j=y.books;if(m&&(j=j.filter(z=>z.section===m)),h.trim()){const z=h.trim().toLowerCase();j=j.filter(E=>E.title.toLowerCase().includes(z)||E.sub_items&&E.sub_items.some(W=>W.toLowerCase().includes(z))||E.edition&&E.edition.toLowerCase().includes(z))}return j},[y,m,h]),w=f.useMemo(()=>{if(!I)return null;const j=[],z=new Map;for(const W of v){if(!W.volumes||W.volumes.length===0)continue;const $=W.volumes[0];z.has($)||z.set($,[]),z.get($).push(W)}const E=[...z.keys()].sort((W,$)=>W-$);for(const W of E)j.push({volume:W,books:z.get(W)});return j},[v,I]);return u?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a.catalog.loading})}):g?e.jsx("div",{className:i,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):y?e.jsxs("div",{className:i,style:l,children:[e.jsx(Uo,{data:y}),k&&e.jsx(No,{sections:y.sections,activeSection:m,onSelect:b}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:h,onChange:j=>S(j.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," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((j,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:$e(a.catalog.volume,{n:j.volume})}),j.books.map((E,W)=>e.jsx(jt,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${j.volume}-${W}`))]},`${j.volume}-${z}`)):v.map((j,z)=>e.jsx(jt,{book:j,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:a.catalog.noMatch})]})]}):null},me=()=>{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)})},ee=6,Ae=7,Ko=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,a]=f.useState(!1),[c,x]=f.useState(null),u=f.useRef(null),p=f.useRef(null),g=f.useRef(null),d=f.useCallback(()=>{const h=p.current,S=g.current;if(!h||!S)return;const y=h.getBoundingClientRect(),k=S.getBoundingClientRect(),I=window.innerHeight,v=document.documentElement.clientWidth;let w=o;o==="top"&&y.top-k.height-Ae<8&&(w="bottom"),o==="bottom"&&y.bottom+k.height+Ae>I-8&&(w="top");const j=w==="top"?y.top-k.height-Ae:y.bottom+Ae;let z=y.left+y.width/2-k.width/2;z=Math.max(8,Math.min(z,v-k.width-8)),x({left:z,top:j,placement:w})},[o]),m=f.useCallback(()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>a(!0),r)},[r]),b=f.useCallback(()=>{u.current&&clearTimeout(u.current),a(!1),x(null)},[]);return f.useEffect(()=>{if(!l)return;const h=requestAnimationFrame(d);return()=>cancelAnimationFrame(h)},[l,d]),f.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:p,onMouseEnter:m,onMouseLeave:b,onFocus:m,onBlur:b,style:{display:"inline-block",...i},children:n}),l&&On.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(c==null?void 0:c.left)??-9999,top:(c==null?void 0:c.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:c?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-ee,width:0,height:0,...c.placement==="top"?{bottom:-ee,borderTop:`${ee}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ee}px solid transparent`,borderRight:`${ee}px solid transparent`}:{top:-ee,borderBottom:`${ee}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${ee}px solid transparent`,borderRight:`${ee}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...c.placement==="top"?{bottom:-5,borderTop:`${ee-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ee-1}px solid transparent`,borderRight:`${ee-1}px solid transparent`}:{top:-5,borderBottom:`${ee-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${ee-1}px solid transparent`,borderRight:`${ee-1}px solid transparent`}}})]})]}),document.body)]})},St={A:"fine",B:"rough",C:"rough",D:"ocr"};function Jo(t){return typeof t!="string"?null:t in Qt?t:t in St?St[t]:null}const qo=["〇","一","二","三","四","五","六","七","八","九"],kt=["","十","百","千"],Zo=["","萬","億"];function un(t){if(t===0)return"〇";if(t<0)return`負${un(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Xo(s,r>0)+Zo[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Xo(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 l=o[i],a=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&a===1&&i===0&&!n?s+=kt[a]:s+=qo[l]+kt[a]}return s.replace(/〇$/,"")}let Le=null,Fe=null;const Ve=new Set;function Qo(){return Le?Promise.resolve():Fe||(Fe=import("opencc-js/t2cn").then(t=>{Le=t.Converter({from:"tw",to:"cn"}),Ve.forEach(n=>n())}).catch(()=>{Le=t=>t,Ve.forEach(t=>t())}),Fe)}function ue(){const[,t]=f.useState(0);return f.useEffect(()=>{if(Le)return;const n=()=>t(o=>o+1);return Ve.add(n),Qo(),()=>{Ve.delete(n)}},[]),Le??(n=>n)}function je(t,n){return n(t).toLowerCase()}const it="#fff59d";function Se(t,n,o){if(!n)return t;const r=je(n,o);if(!r)return t;const s=je(t,o);if(s.length!==t.length)return t;const i=[];let l=0,a=0;for(;l<t.length;){const c=s.indexOf(r,l);if(c===-1){i.push(t.slice(l));break}c>l&&i.push(t.slice(l,c)),i.push(e.jsx("mark",{style:{background:it,padding:0,color:"inherit"},children:t.slice(c,c+r.length)},a++)),l=c+r.length}return e.jsx(e.Fragment,{children:i})}function st(t,n,o,r){if(!n)return!0;const s=je(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(l=>typeof l=="string"&&je(l,r).includes(s))}function er(t,n,o){return n?je(t,o).includes(je(n,o)):!0}const lt={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},tr={考证:"#5d6d7e"};function nr(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 fn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",a=typeof s=="number"&&s>0,c=nr(t),x=!!(r!=null&&r.vol_label)&&!c.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)":a?`${it}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:[c,x&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function gn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>gn(r,n)))}function hn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+hn(i),0))||0;return n+o}function or(t,n){const o=[],r=l=>{var a;o.push(...l.files),(a=l.children)==null||a.forEach(r)};if(r(t),o.length===0)return;const s=o.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let i=0;for(const l of s)typeof l=="number"&&(i+=l);return i}function bn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var m;const l=gn(t,n||""),a=or(t,i),c=typeof a=="number"&&a>0,x=a===0,[u,p]=f.useState(l||c),g=hn(t),d=!!((m=t.children)!=null&&m.length);if(f.useEffect(()=>{l&&p(!0)},[l]),f.useEffect(()=>{c&&p(!0)},[c]),t.files.length===1&&!d){const b=t.files[0],h=n===b,S=i[b],y=S===0,k=S==="loading",I=typeof S=="number"&&S>0;return e.jsxs("button",{onClick:()=>{y||o(b)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:h?"1px solid var(--bim-primary, #8e6f3e)":y?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:h?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":I?`${it}40`:"transparent",color:h?"var(--bim-primary, #8e6f3e)":y?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:y?"not-allowed":"pointer",fontSize:"12px",fontWeight:h?600:400,lineHeight:1.4,opacity:y?.5:1},children:[t.label,I&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:S}),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:()=>p(!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:l?"var(--bim-primary, #8e6f3e)":x?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:x?.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,")"]}),c&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",a]}),a==="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(b=>e.jsx(fn,{file:b,isActive:n===b,onSelect:o,meta:s==null?void 0:s[b],matchState:i[b]},b))}),d&&t.children.map((b,h)=>e.jsx(bn,{group:b,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},h))]})]})}function rr({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:s,matchStates:i}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((a,c)=>e.jsx(bn,{group:a,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},c))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(a=>e.jsx(fn,{file:a,isActive:o===a,onSelect:r,meta:s==null?void 0:s[a],matchState:i[a]},a))})}function ir({type:t}){const n=lt[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 sr({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=D(),s=le(),i=ue(),l=b=>{if(!b)return"";const h=r(b);return o?Se(h,o,i):h},[a,c]=f.useState(!1),x=!!t.summary,u=!!t.comment,p=!!t.additional_comment,g=!!(t.content&&t.content.length>60),d=x||u||p||g;f.useEffect(()=>{o&&c(!0)},[o]);const m=!a&&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:()=>d&&c(!a),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[un(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!a&&m&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(m)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:b=>{b.metaKey||b.ctrlKey||(b.preventDefault(),b.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),a&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!x&&!u&&!p&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function lr({section:t,highlightQuery:n=""}){const{convert:o}=D(),r=ue(),s=c=>{if(!c)return"";const x=o(c);return n?Se(x,n,r):x},[i,l]=f.useState(!1),a=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>a&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:a?"pointer":"default",userSelect:"none"},children:[e.jsx(ir,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),a&&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&&a&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${lt[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 ar({section:t,highlightQuery:n=""}){const{convert:o}=D(),r=ue();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`)),i=n?
|
|
3
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((l,a)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},a);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},a);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},a);if(!l.trim())return a>0&&!i[a-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},a);const c=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:c.map((x,u)=>x.startsWith("**")&&x.endsWith("**")?e.jsx("strong",{children:s(x.slice(2,-2))},u):e.jsx(f.Fragment,{children:s(x)},u))},a)})})}function ur({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=D(),s=le(),i=ue(),l=x=>{if(!x)return"";const u=r(x);return o?Se(u,o,i):u},a=[];let c=null;for(const x of t)x.type==="类"?(c&&a.push(c),c={category:x.title,categoryContent:x.content||void 0,items:[]}):x.type==="书"?(c||(c={category:"",items:[]}),c.items.push(x)):(x.type==="序"||x.type==="结语")&&(c||(c={category:"",items:[]}),c.items.push(x),x.type==="结语"&&(a.push(c),c=null));return c&&a.push(c),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:a.map((x,u)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[x.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(x.category),x.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(x.categoryContent)})]}),x.items.map((p,g)=>p.type==="序"||p.type==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(p.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&p.work_id?e.jsx("a",{href:s(p.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),n(p.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(p.title),children:e.jsx("strong",{children:l(p.title)})}):e.jsx("strong",{children:l(p.title)}),p.content&&l(p.content)]},g))]},u))})}function fr({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=D(),i=ue(),[l,a]=f.useState("catalog"),c=o.trim(),x=f.useMemo(()=>c?t.sections.filter(d=>st(d,c,!1,i)):t.sections,[t.sections,c,i]),u=t.sections.filter(d=>d.type==="书").length,p=t.sections.filter(d=>d.type==="詩").length,g=c?x.filter(d=>d.type==="书"||d.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(d=>e.jsx("button",{onClick:()=>a(d),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:d==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===d?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===d?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:d==="catalog"?"目錄":"原文"},d))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${p>0?`${p} 首`:`${u} 部書`}`:p>0?`${p} 首`:`${u} 部书`})]}),l==="raw"&&(n?e.jsx(xr,{text:n,highlightQuery:c}):e.jsx(ur,{sections:t.sections,onNavigate:r,highlightQuery:c})),l==="catalog"&&x.map((d,m)=>d.type==="书"||d.type==="詩"?e.jsx(sr,{section:d,onNavigate:r,highlightQuery:c},m):d.type==="类"?e.jsx(lr,{section:d,highlightQuery:c},m):e.jsx(ar,{section:d,highlightQuery:c},m)),l==="catalog"&&x.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function mn(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 wt(t){const n=mn(t);return n.length>0?n[0]:null}function gr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:a,isKaozhen:c}=t,x=ue(),u=f.useRef(new Map),[p,g]=f.useState({});f.useEffect(()=>{s&&i&&u.current.set(s,{juan:i,rawText:l})},[s,i,l]),f.useEffect(()=>{u.current.clear(),g({})},[n]);const d=f.useCallback((m,b)=>{let h=0;if(m.juan)for(const S of m.juan.sections)st(S,b,c,x)&&h++;return h===0&&m.rawText&&er(m.rawText,b,x)&&(h=1),h},[c,x]);return f.useEffect(()=>{const m=a.trim();if(!m){g({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let b=!1;const h={},S=[];for(const w of r){const j=u.current.get(w);j?h[w]=d(j,m):(h[w]="loading",S.push(w))}g(h);const y=8;let k=0;const I=async()=>{var w;for(;k<S.length;){if(b)return;const j=k++,z=S[j];try{const[E,W]=await Promise.all([o.getCollatedJuan(n,z),((w=o.getCollatedJuanText)==null?void 0:w.call(o,n,z))??Promise.resolve(null)]),$={juan:E,rawText:W};if(u.current.set(z,$),b)return;g(V=>({...V,[z]:d($,m)}))}catch{if(b)return;g(E=>({...E,[z]:0}))}}},v=Array.from({length:Math.min(y,S.length)},()=>I());return Promise.all(v),()=>{b=!0}},[a,n,o,r.join(","),d,x]),{matchStates:p}}const yn=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:l,style:a})=>{const[c,x]=f.useState(null),[u,p]=f.useState(!1),[g,d]=f.useState(null),[m,b]=f.useState(null),[h,S]=f.useState(null),[y,k]=f.useState(!1),[I,v]=f.useState(null),[w,j]=f.useState(""),z=f.useRef(new Map),E=s??m,W=f.useCallback(T=>{b(T),i==null||i(T)},[i]),$=t||c;f.useEffect(()=>{t&&(p(!1),d(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let T=!1;return p(!0),d(null),o.getCollatedEditionIndex(n).then(_=>{if(!T)if(!_)d("未找到整理本数据");else{x(_);const L=wt(_);!s&&L&&W(L)}}).catch(_=>{T||d(_ instanceof Error?_.message:"加载失败")}).finally(()=>{T||p(!1)}),()=>{T=!0}},[t,n,o,s,W]),f.useEffect(()=>{const T=t||c;if(T&&!E){const _=wt(T);_&&W(_)}},[t,c,E,W]);const V=n||($==null?void 0:$.work_id),Y=f.useCallback(async T=>{var _;if(!(!V||!(o!=null&&o.getCollatedJuan))){k(!0),S(null),v(null);try{const[L,B]=await Promise.all([o.getCollatedJuan(V,T),((_=o.getCollatedJuanText)==null?void 0:_.call(o,V,T))??Promise.resolve(null)]);S(L),v(B)}catch{S(null),v(null)}finally{k(!1)}}},[V,o]);f.useEffect(()=>{E&&Y(E)},[E,Y]);const N=T=>{W(T)};if(u)return e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!$)return null;const C=$.type==="kaozhen",P=mn($);return e.jsx(hr,{className:l,style:a,index:$,allFiles:P,isKaozhen:C,effectiveWorkId:V,transport:o,activeFile:E,handleSelectFile:N,juanData:h,juanRawText:I,juanLoading:y,searchQuery:w,setSearchQuery:j,onNavigate:r,workLabelCacheRef:z})},hr=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:l,activeFile:a,handleSelectFile:c,juanData:x,juanRawText:u,juanLoading:p,searchQuery:g,setSearchQuery:d,onNavigate:m,workLabelCacheRef:b})=>{const{matchStates:h}=gr({workId:i,transport:l,files:r,activeFile:a,activeJuan:x,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:S=>d(S.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 S=Jo(o.text_quality.grade);return S?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Ko,{content:Gn[S],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Yn[S],cursor:"help"},children:Qt[S]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(rr,{files:r,groups:o.juan_groups,activeFile:a,onSelect:c,juanMeta:o.juan_metadata,matchStates:h}),p?e.jsx(me,{}):x?s?e.jsx(pr,{juan:x,searchQuery:g,onNavigate:m,transport:l,workLabelCache:b}):e.jsx(fr,{juan:x,rawText:u,searchQuery:g,onNavigate:m}):a?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((S,y)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[y+1,". "]}),S.url?e.jsx("a",{href:S.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:S.title}):e.jsx("span",{children:S.title}),S.author&&e.jsxs("span",{children:[",",S.author]}),S.note&&e.jsxs("span",{children:["。",S.note]})]},y))]})]})},br={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},mr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function yr(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 vn=({items:t,loading:n})=>{const o=le();return n?e.jsx(me,{}):t.length===0?e.jsx("div",{style:vr,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=br[r.type],i=mr[r.status];return e.jsxs("div",{style:jr,children:[e.jsxs("div",{style:Sr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Ct,background:s.color},children:s.label}),e.jsx("span",{style:{...Ct,background:i.color},children:i.label})]}),e.jsx("span",{style:kr,children:yr(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:wr,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:_t,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:_t,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Cr,children:r.content}),r.reply&&e.jsxs("div",{style:_r,children:[e.jsx("div",{style:zr,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},vr={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},jr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Sr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Ct={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},kr={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},wr={fontSize:"12px",marginBottom:"6px"},_t={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Cr={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},_r={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},zr={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},tt=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const l=F(),[a,c]=f.useState(null),[x,u]=f.useState([]),[p,g]=f.useState("recommend"),[d,m]=f.useState([]),[b,h]=f.useState(!1),S=r??p,y=C=>{g(C),s==null||s(C)},[k,I]=f.useState(!0),[v,w]=f.useState(null),[j,z]=f.useState(null),[E,W]=f.useState(null);f.useEffect(()=>{let C=!1;const P=_=>{C||c(_)},T=()=>{t.getAllEntries&&t.getAllEntries().then(_=>{P({works:_.filter(L=>L.type==="work").length,books:_.filter(L=>L.type==="book").length,collections:_.filter(L=>L.type==="collection").length})}).catch(()=>{})};return t.getCounts?t.getCounts().then(_=>P({works:_.works,books:_.books,collections:_.collections})).catch(T):T(),()=>{C=!0}},[t]),f.useEffect(()=>{let C=!1;return(async()=>{if(o)return o;if(t.getRecommended)try{const T=await t.getRecommended();if(T!=null&&T.groups)return T.groups.flatMap(_=>_.items.map(L=>({...L,group:_.name})))}catch{}return[]})().then(async T=>{if(C)return;const _=T.filter(B=>B.id);if(_.length===0){I(!1);return}const L=await Promise.all(_.map(async B=>{if(B.type)return{id:B.id,title:B.title,type:B.type,author:B.author,dynasty:B.dynasty,role:B.role,edition:B.edition,has_text:B.has_text,has_image:B.has_image,has_collated:B.has_collated,subtype:B.subtype,primary_name:B.primary_name,group:B.group,fallbackDescription:B.description};try{let M=null;if(t.getEntry)M=await t.getEntry(B.id);else{const O=await t.getItem(B.id);O&&(M={id:B.id,title:O.title||B.id,type:O.type||"work"})}if(M)return{...M,group:B.group,fallbackDescription:B.description}}catch{}return{id:B.id,title:B.title,type:U.extractType(B.id),group:B.group,fallbackDescription:B.description}}));C||(u(L.filter(B=>B!==null)),I(!1))}),()=>{C=!0}},[t,o]);const $=f.useRef(!1),V=f.useRef(!1),Y=f.useRef(!1);f.useEffect(()=>{if(S!=="catalog"||$.current)return;const C=t.getCatalogProgress??t.getResourceProgress;if(!C)return;$.current=!0;let P=!1;return C.call(t).then(T=>{P||w(T)}).catch(()=>{$.current=!1}),()=>{P=!0}},[t,S]),f.useEffect(()=>{if(S!=="collection"||V.current||!t.getCollectionProgress)return;V.current=!0;let C=!1;return t.getCollectionProgress().then(P=>{C||z(P)}).catch(()=>{V.current=!1}),()=>{C=!0}},[t,S]),f.useEffect(()=>{if(S!=="site"||Y.current||!t.getSiteProgress)return;Y.current=!0;let C=!1;return t.getSiteProgress().then(P=>{C||W(P)}).catch(()=>{Y.current=!1}),()=>{C=!0}},[t,S]),f.useEffect(()=>{if(!i||S!=="feedback")return;let C=!1;return h(!0),fetch(i).then(P=>P.json()).then(P=>{!C&&P.success&&m(P.items||[])}).catch(()=>{}).finally(()=>{C||h(!1)}),()=>{C=!0}},[i,S]);const N=C=>{switch(C){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(Ie,{label:l.home.recommendTab,active:S==="recommend",onClick:()=>y("recommend")}),e.jsx(Ie,{label:l.home.catalogTab,active:S==="catalog",onClick:()=>y("catalog")}),e.jsx(Ie,{label:l.home.collectionTab,active:S==="collection",onClick:()=>y("collection")}),e.jsx(Ie,{label:l.home.siteTab,active:S==="site",onClick:()=>y("site")}),i&&e.jsx(Ie,{label:l.home.feedbackTab,active:S==="feedback",onClick:()=>y("feedback")})]}),S==="recommend"&&e.jsx(Ir,{recommended:x,loading:k,onNavigate:n,getIcon:N,t:l}),S==="catalog"&&e.jsx(zt,{progress:v,t:l,onNavigate:n}),S==="collection"&&e.jsx(zt,{progress:j,t:l,onNavigate:n}),S==="site"&&e.jsx(Rr,{progress:E,t:l,totalWorks:(a==null?void 0:a.works)??0}),S==="feedback"&&i&&e.jsx(vn,{items:d,loading:b})]})})},Ie=({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}),Ir=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=le();if(n)return e.jsx(me,{});if(t.length===0)return null;const l=new Map;for(const a of t){const c=a.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(a)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([a,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(x=>{const u=x.dynasty||x.author?`${x.dynasty?`〔${x.dynasty}〕`:""}${x.author||""}`:x.fallbackDescription;return e.jsxs("a",{href:i(x.id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o==null||o(x.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(x.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[x.title,x.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:x.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},x.id)})})]},a))})},zt=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(me,{});const r=[...t.resources].sort((a,c)=>a.priority-c.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:s.map(a=>{const c=r.filter(x=>x.status===a);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[a]}}),i[a]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(x=>e.jsx(Tr,{item:x,t:n,statusColor:l[a],onNavigate:o},x.id))})]},a)})})},Tr=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=le(),i=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const a=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&r?e.jsx("a",{href:s(c),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:x=>x.currentTarget.style.borderBottomStyle="solid",onMouseLeave:x=>x.currentTarget.style.borderBottomStyle="dashed",children:a}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?$e(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})]})},Rr=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(me,{});const r=[...t.resources].sort((c,x)=>c.priority-x.priority),s=r.filter(c=>c.imported>0),i=r.filter(c=>c.imported===0),l=s.reduce((c,x)=>Math.max(c,x.imported),0),a=o>0?Math.round(l/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:l.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",a,"%)"]}),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(c=>e.jsx(It,{item:c,t:n,totalWorks:o},c.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(c=>e.jsx(It,{item:c,t:n,totalWorks:o},c.id))})]})]})},It=({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})]})},Tt="(max-width: 768px)";function Er(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Tt).matches);return f.useEffect(()=>{const o=window.matchMedia(Tt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Lr=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var P;const i=F(),{convert:l}=D(),a=Er(),[c,x]=f.useState(null),[u,p]=f.useState(null),[g,d]=f.useState(!1),[m,b]=f.useState("detail"),[h,S]=f.useState([]),[y,k]=f.useState(!1),[I,v]=f.useState(null),[w,j]=f.useState(!1),z=f.useCallback(async T=>{if(!t.getCollatedEditionIndex){v(null);return}j(!0);try{const _=await t.getCollatedEditionIndex(T);v(_)}catch{v(null)}finally{j(!1)}},[t]),E=f.useCallback(async T=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){S([]);return}k(!0);try{if(t.getCollectionCatalogs){const _=await t.getCollectionCatalogs(T);S(_||[])}else if(t.getCollectionCatalog){const _=await t.getCollectionCatalog(T);S(_?[{resource_id:"",data:_}]:[])}}catch{S([])}finally{k(!1)}},[t]),W=f.useCallback(async T=>{if(o){o(T);return}x(T),p(null),S([]),v(null),b("detail"),d(!0);try{const _=await t.getItem(T.id);_&&(p(_),_.type==="collection"?E(T.id):_.type==="work"&&_.has_collated&&z(T.id))}catch(_){console.error("加载详情失败:",_)}finally{d(!1)}},[t,o,E,z]),$=f.useCallback(async T=>{p(null),S([]),v(null),b("detail"),d(!0);try{const _=await t.getItem(T);_&&(p(_),x({id:T,title:_.title||T,type:_.type||"book"}),_.type==="collection"?E(T):_.type==="work"&&_.has_collated&&z(T))}catch(_){console.error("导航失败:",_)}finally{d(!1)}},[t,E,z]),V=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(I||w),Y=a&&(g||u),N=f.useCallback(()=>{x(null),p(null),S([]),v(null),b("detail")},[]),C=e.jsx(e.Fragment,{children:g?e.jsx(me,{}):u?e.jsxs(e.Fragment,{children:[(V||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[V&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>b("detail"),style:Me(m==="detail"),children:i.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&e.jsxs("button",{onClick:()=>{},style:Me(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(T=>e.jsx("button",{onClick:()=>b(`catalog:${T.resource_id}`),style:Me(m===`catalog:${T.resource_id}`),children:T.short_name?`${l(T.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},T.resource_id)),u.type==="work"&&(I||w)&&e.jsxs("button",{onClick:()=>b("collated"),style:Me(m==="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:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:m==="detail"?e.jsx(rt,{data:u,transport:t,onNavigate:$}):m.startsWith("catalog:")?e.jsx(xn,{data:(P=h.find(T=>`catalog:${T.resource_id}`===m))==null?void 0:P.data,onNavigate:$}):m==="collated"?e.jsx(yn,{index:I||void 0,workId:u.id,transport:t,onNavigate:$}):null})]}):e.jsx(tt,{transport:t,onNavigate:$,recommendedIds:r})});return a?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:Y?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:N,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:C})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(et,{transport:t,onEntryClick:W,hideModeIndicator:n}),!u&&e.jsx(tt,{transport:t,onNavigate:$,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(et,{transport:t,onEntryClick:W,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:C})]})};function Me(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 Br=({data:t,onNavigate:n,className:o,style:r})=>{var u;const s=F(),{convert:i}=D(),[l,a]=f.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[c,x]=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(p=>e.jsx(Wr,{division:p,expanded:l===p.name,onToggle:()=>a(l===p.name?null:p.name),expandedCat:c,onCatToggle:g=>x(c===g?null:g),onNavigate:n},p.name))})]})},Wr=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:l}=D(),a=t.categories.reduce((c,x)=>{const u=x.stats||{zhulu:0,cunmu:0};return c+(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:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const x=`${t.name}/${c.name}`;return e.jsx($r,{category:c,expanded:r===x,onToggle:()=>s(x),onNavigate:i},c.name)})})]})},$r=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var c,x,u,p;const{convert:s}=D(),i=((c=t.books)==null?void 0:c.zhulu)||[],l=((x=t.books)==null?void 0:x.cunmu)||[],a=(((u=t.stats)==null?void 0:u.zhulu)||i.length)+(((p=t.stats)==null?void 0:p.cunmu)||l.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:[a," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Rt,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(Rt,{label:"存目",books:l,onNavigate:r})]})]})},Rt=({label:t,books:n,onNavigate:o})=>{const{convert:r}=D(),s=le(),[i,l]=f.useState(n.length<=20),a=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:a.map((c,x)=>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:c.work_id&&o?e.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(c.title)}):r(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(c.author).slice(0,20)})]},x))}),!i&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ie=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=F();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:Ar,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Pr,children:i.action.save})]})]}),s]})},Pr={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ar={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},oe=({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"}})]}),be=({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"}})},Ue=({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 Fr(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Oe=({value:t,onChange:n,label:o})=>{const[r,s]=f.useState(!1),i=f.useRef(null),l=Fr(t||"");return f.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Et,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:l.name}),e.jsx(Ue,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Et,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:a=>n(a.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"}})]})},Et={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Mr(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Hr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const jn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=F(),[s,i]=f.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},a=p=>{n(t.filter((g,d)=>d!==p)),s===p&&i(null)},c=(p,g,d)=>{const m=[...t];m[p]={...m[p],[g]:d},n(m)},x=(p,g)=>{const d=[...t];d[p]={...d[p],type:g,id:"",name:""},n(d),g==="bookID"&&o&&o(m=>{const b=[...t];b[p]={...b[p],id:m.id,name:m.title,type:"bookID"},n(b)})},u=p=>{o&&o(g=>{const d=[...t];d[p]={...d[p],id:g.id,name:g.title,type:"bookID"},n(d)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,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:p.name||`${r.editor.sourcePlaceholder} ${g+1}`}),p.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Mr(p.type),color:"white",borderRadius:"3px",fontWeight:500},children:Hr(p.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),a(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:[!p.type&&e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>x(g,"bookID"),style:{...Lt,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:()=>x(g,"url"),style:{...Lt,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})]})]})]}),p.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:xe,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const d=[...t];d[g]={...d[g],type:"",id:"",name:""},n(d)},style:Bt,children:r.action.changeType})]}),p.id&&p.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:p.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:p.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})]})]})}),p.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:xe,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const d=[...t];d[g]={...d[g],type:"",id:"",name:""},n(d)},style:Bt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:p.name,onChange:d=>c(g,"name",d.target.value),placeholder:r.editor.sourceNamePlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:p.id,onChange:d=>c(g,"id",d.target.value),placeholder:"https://...",style:ye})]})]}),p.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:{...xe,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:xe,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:p.details,onChange:d=>c(g,"details",d.target.value),placeholder:r.editor.detailsPlaceholder,style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:p.position,onChange:d=>c(g,"position",d.target.value),placeholder:"如: 卷三, p.52",style:ye})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:p.version,onChange:d=>c(g,"version",d.target.value),placeholder:"如: v1.0, 2024-01",style:ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:xe,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:p.processor_version,onChange:d=>c(g,"processor_version",d.target.value),placeholder:"如: v0.1",style:ye})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},xe={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},ye={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Lt={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"},Bt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Sn(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 kn(t){return!t||t.length===0?"":JSON.stringify(t)}const wn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:l,childWorks:a,childCollections:c,containedBooks:x,siblingBooks:u,onLinkEntity:p,onUnlinkEntity:g,onViewEntity:d,onCreateAndLink:m,onSaveRelations:b})=>{const h=F();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:h.section.relations})]}),b&&e.jsx("button",{onClick:b,style:Dr,children:h.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{direction:"up",title:h.relation.belongsToWork,entity:i,onView:d,onUnlink:()=>g("workId"),onLink:()=>p("workId","work"),onCreate:()=>m("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(Te,{direction:"up",title:h.relation.containedInCollection,entity:l,onView:d,onUnlink:()=>g("collectionId"),onLink:()=>p("collectionId","collection"),onCreate:()=>m("collectionId","collection",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),i&&u&&u.length>0&&e.jsx(ve,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:d,onAdd:()=>m("siblingBook","book",{workId:i.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{direction:"up",title:h.relation.parentWork,entity:r,onView:d,onUnlink:()=>g("parentWorkId"),onLink:()=>p("parentWorkId","work"),onCreate:()=>m("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),a&&a.length>0&&e.jsx(ve,{direction:"down",title:`${h.relation.childWorks} (${a.length})`,entities:a,onView:d,onAdd:()=>m("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),c&&c.length>0&&e.jsx(ve,{direction:"down",title:`${h.relation.collectionImpl} (${c.length})`,entities:c,onView:d,onAdd:()=>m("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(ve,{direction:"down",title:`${h.relation.allVersions} (${(x==null?void 0:x.length)??0})`,entities:x||[],onView:d,onAdd:()=>m("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Te,{direction:"up",title:h.relation.correspondingWork,entity:i,onView:d,onUnlink:()=>g("workId"),onLink:()=>p("workId","work"),onCreate:()=>m("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(Te,{direction:"up",title:h.relation.parentCollection,entity:s,onView:d,onUnlink:()=>g("parentCollectionId"),onLink:()=>p("parentCollectionId","collection"),onCreate:()=>m("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ve,{direction:"down",title:`${h.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:d,onAdd:()=>m("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(ve,{direction:"down",title:`${h.relation.containedBooks} (${(x==null?void 0:x.length)??0})`,entities:x||[],onView:d,onAdd:()=>m("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Te=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:l,linkLabel:a,createLabel:c,notLinkedLabel:x,viewLabel:u,unlinkLabel:p})=>{const g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",d=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:d}),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:Cn(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(Wt,{onClick:()=>r(o),title:u,children:"👁️"}),e.jsx(Wt,{onClick:s,title:p,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:x}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(nt,{onClick:i,children:a}),e.jsx(nt,{onClick:l,primary:!0,children:c})]})]})},ve=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:l,expandMoreLabel:a})=>{const[c,x]=f.useState(!1),u=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=c?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:p}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(d=>e.jsxs("div",{onClick:()=>r(d),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:Cn(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.length>5&&!c&&e.jsxs("div",{onClick:()=>x(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",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:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(nt,{onClick:s,primary:!0,children:["+ ",i]})})]})},Wt=({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}),nt=({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 Cn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Dr={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"},_n=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:l,onSearch:a,isLoading:c,excludeId:x})=>{const[u,p]=f.useState(""),g=x?l.filter(h=>h.id!==x):l;f.useEffect(()=>{t&&(p(""),a(""))},[t]);const d=h=>{p(h),a(h)};if(!t)return null;const m=n==="work"?"作品":n==="book"?"书籍":"丛编",b=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Or,children:e.jsxs("div",{style:Vr,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:Ur,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:h=>d(h.target.value),placeholder:`搜索${m}名称或 ID...`,autoFocus:!0,style:Nr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:Ze,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(h=>e.jsxs("div",{onClick:()=>r(h),style:Gr,children:[e.jsx("span",{style:{fontSize:"16px"},children:b}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?e.jsxs("div",{style:Ze,children:["未找到匹配的",m]}):e.jsxs("div",{style:Ze,children:["输入关键词搜索",m]})}),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:Yr,children:["创建新",m,"并关联"]})]})]})})},Or={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},Vr={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)"},Ur={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Nr={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"},Gr={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ze={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Yr={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},$t={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Kr={work:"📜",book:"📖",collection:"📚",entity:"👤"},zn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,a]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var g,d;(g=c.current)==null||g.focus(),(d=c.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const x=g=>{g.key==="Enter"&&l.trim()?u():g.key==="Escape"&&i()},u=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const p=()=>{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`创建新${$t[n]}`}};return e.jsx("div",{style:Jr,onClick:g=>{g.target===g.currentTarget&&i()},children:e.jsxs("div",{style:qr,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:Kr[n]}),e.jsx("span",{children:p()})]}),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:c,type:"text",value:l,onChange:g=>a(g.target.value),onKeyDown:x,placeholder:`请输入${$t[n]}名称...`,style:Zr})]}),((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:Xr,children:"取消"}),e.jsx("button",{onClick:u,disabled:!l.trim(),style:{...Qr,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Jr={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},qr={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)"},Zr={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"},Xr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Qr={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function ei(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function In(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ti(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Tn=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:l,onSelect:a,onCancel:c,onCreate:x,onSearch:u})=>{const[p,g]=f.useState(""),[d,m]=f.useState([]),[b,h]=f.useState(!1),[S,y]=f.useState("recent");f.useEffect(()=>{t&&(g(""),m([]),y(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!p.trim()){m([]);return}const z=setTimeout(async()=>{h(!0);try{m(await u(p,o))}catch{m([])}finally{h(!1)}},300);return()=>clearTimeout(z)},[p,o,u]);const k=f.useCallback(z=>{g(z.target.value),z.target.value.trim()&&y("search")},[]),I=f.useCallback(z=>s?z.filter(E=>E.id!==s):z,[s]);if(!t)return null;const v=n||(o==="all"?"选择实体":`选择${In(o)}`),w=I(r),j=I(d);return e.jsx("div",{style:oi,children:e.jsxs("div",{style:ri,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:c,style:ii,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:p,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:si}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),b&&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(Pt,{active:S==="recent",onClick:()=>y("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(Pt,{active:S==="search",onClick:()=>y("search"),children:["搜索结果 ",j.length>0&&`(${j.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&w.length>0?e.jsx(At,{entities:w,onSelect:a}):p.trim()?b?e.jsx(Xe,{message:"搜索中..."}):j.length>0?e.jsx(At,{entities:j,onSelect:a}):e.jsx(Xe,{message:"未找到匹配的结果"}):e.jsx(Xe,{message:"输入关键词开始搜索"})}),i&&x&&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:x,style:li,children:l||"创建新实体"})]})]})})},Pt=({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}),At=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(ni,{entity:o,onClick:()=>n(o)},o.id))}),ni=({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:ei(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:ti(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:In(t.type)})]})},Xe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),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",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ii={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},si={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"},li={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ai={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},ci={work:"📜",collection:"📚",book:"📖",entity:"👤"},Rn=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:a,renderSectionActions:c,onDownloadResource:x,downloadStatuses:u,relations:p,onRelationsChange:g})=>{var Q;const d=F(),[m,b]=f.useState(!1),[h,S]=f.useState("work"),[y,k]=f.useState(""),[I,v]=f.useState(""),[w,j]=f.useState([]),[z,E]=f.useState(!1),[W,$]=f.useState(!1),[V,Y]=f.useState("work"),[N,C]=f.useState(""),[P,T]=f.useState(),[_,L]=f.useState(!1),[B,M]=f.useState(null),[O,K]=f.useState([]);f.useRef(null);const te=t.type,ge=te==="work",fe=te==="collection",X=te==="book",Z=f.useCallback((R,H)=>{n({...t,[R]:H})},[t,n]),Ge=f.useCallback((R,H)=>{k(R),S(H),v(d.editor.selectToLink+d.indexType[H]),j([]),b(!0)},[d]),Ye=f.useCallback(R=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,R)},[r,t.id]),ke=f.useCallback(R=>{s==null||s(R.id,R.type)},[s]),we=f.useCallback((R,H,ne)=>{const ae={...ne,author:(ne==null?void 0:ne.author)||t.author,dynasty:(ne==null?void 0:ne.dynasty)||t.dynasty};Y(H),C(R),T(ae),$(!0)},[t.author,t.dynasty]),Ke=f.useCallback((R,H)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,N,{type:V,title:R,inheritData:H}),$(!1)},[r,t.id,N,V]),Pe=f.useCallback(R=>{if(!R.trim()){j([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(R,h).then(H=>{j(H),E(!1)}).catch(()=>{j([]),E(!1)})},[r,h]),Je=f.useCallback(R=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,y,R.id),b(!1)},[r,t.id,y]),A=f.useCallback(()=>{o()},[o]),q=f.useCallback(R=>{M(()=>R),L(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(K).catch(()=>{})},[r]),G=f.useCallback((R,H)=>r!=null&&r.searchEntities?r.searchEntities(R,H==="all"?void 0:H):Promise.resolve([]),[r]),J=f.useCallback(R=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(R),K(H=>[R,...H.filter(ne=>ne.id!==R.id)].slice(0,10)),B==null||B(R),L(!1),M(null)},[r,B]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:ci[te]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Ue,{children:t.id}),e.jsx(Ue,{color:ai[te],children:d.indexType[te]})]})}),e.jsx(ie,{title:d.section.basicInfo,onSave:o,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Oe,{label:ge?d.editor.workTitle:fe?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:R=>Z("title",R)}),X&&e.jsx(Oe,{label:d.editor.belongsToWork,value:t.workName||"",onChange:R=>Z("workName",R)}),e.jsx(oe,{label:d.editor.authorLabel,value:t.author||"",onChange:R=>Z("author",R)}),e.jsx(oe,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:R=>Z("dynasty",R)}),(X||fe)&&e.jsx(Oe,{label:d.editor.containedIn,value:t.collection||"",onChange:R=>Z("collection",R)}),(X||fe)&&e.jsx(oe,{label:d.editor.holderLabel,value:t.holder||"",onChange:R=>Z("holder",R)}),(X||fe)&&e.jsx(oe,{label:X?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:R=>Z("pages",R)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(oe,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:R=>Z("firstImage",R)})})]})}),e.jsx(ie,{title:d.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(be,{value:t.description||"",onChange:R=>Z("description",R),placeholder:d.editor.descriptionPlaceholder})}),(((Q=t.additional_works)==null?void 0:Q.length)||0)>0&&e.jsx(ie,{title:d.section.additionalWorks,onSave:o,children:e.jsx(di,{items:t.additional_works||[],onChange:R=>Z("additional_works",R)})}),e.jsx(ie,{title:d.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(pi,{items:t.indexed_by||[],onChange:R=>Z("indexed_by",R)})}),e.jsx(ie,{title:d.section.emendatedBy,onSave:o,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(xi,{items:t.emendated_by||[],onChange:R=>Z("emendated_by",R)})}),e.jsx(ie,{title:d.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(Qe,{items:t.resources||[],onChange:R=>Z("resources",R),onDownload:x,downloadStatuses:u,filterType:"text"})}),e.jsx(ie,{title:d.section.imageResources,onSave:o,children:e.jsx(Qe,{items:t.resources||[],onChange:R=>Z("resources",R),onDownload:x,downloadStatuses:u,filterType:"image"})}),e.jsx(ie,{title:d.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(jn,{items:Sn(t.sources||""),onChange:R=>Z("sources",kn(R)),onOpenEntityPicker:q})}),(X||fe)&&e.jsx(ie,{title:d.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(be,{value:t.provenance||"",onChange:R=>Z("provenance",R),placeholder:d.editor.provenancePlaceholder})}),X&&e.jsx(ie,{title:d.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(be,{value:t.otherEditions||"",onChange:R=>Z("otherEditions",R),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(wn,{entityType:te,entityId:t.id,entityTitle:t.title,parentWork:p==null?void 0:p.parentWork,parentCollection:p==null?void 0:p.parentCollection,belongsToWork:p==null?void 0:p.belongsToWork,belongsToCollection:p==null?void 0:p.belongsToCollection,childWorks:p==null?void 0:p.childWorks,childCollections:p==null?void 0:p.childCollections,containedBooks:p==null?void 0:p.containedBooks,siblingBooks:p==null?void 0:p.siblingBooks,onLinkEntity:Ge,onUnlinkEntity:Ye,onViewEntity:ke,onCreateAndLink:we,onSaveRelations:A}),i&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:d.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:d.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:d.editor.deleteEntity})]}),e.jsx(_n,{isOpen:m,entityType:h,title:I,onSelect:Je,onCancel:()=>b(!1),onCreate:()=>{b(!1),we(y,h)},searchResults:w,onSearch:Pe,isLoading:z,excludeId:t.id}),e.jsx(zn,{isOpen:W,entityType:V,relationField:N,inheritData:P,onConfirm:Ke,onCancel:()=>$(!1)}),e.jsx(Tn,{isOpen:_,title:d.action.selectBookOrWork,filterType:"all",recentEntities:O,excludeId:t.id,onSelect:J,onCancel:()=>{L(!1),M(null)},onSearch:G})]})};function di({items:t,onChange:n}){const o=F(),r=(l,a,c)=>{const x=t.map((u,p)=>p===l?{...u,[a]:c}:u);n(x)},s=l=>n(t.filter((a,c)=>c!==l)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(oe,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(a,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(oe,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(a,"n_juan",c&&parseInt(c,10)||void 0)})}),e.jsx("button",{onClick:()=>s(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),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 En({items:t,onChange:n,showMeta:o,addLabel:r}){const s=F(),[i,l]=f.useState(null),a=(u,p,g)=>{const d=t.map((m,b)=>b===u?{...m,[p]:g||void 0}:m);n(d)},c=u=>{n(t.filter((p,g)=>g!==u)),i===u&&l(null)},x=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,p)=>{const g=i===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:p),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:d=>{d.stopPropagation(),c(p)},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(oe,{label:s.label.sourceName,value:u.source,onChange:d=>a(p,"source",d)}),e.jsx(oe,{label:s.label.sourceBid,value:u.source_bid||"",onChange:d=>a(p,"source_bid",d)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(oe,{label:s.label.titleInfo,value:u.title_info||"",onChange:d=>a(p,"title_info",d)}),e.jsx(oe,{label:s.label.authorInfo,value:u.author_info||"",onChange:d=>a(p,"author_info",d)})]}),e.jsx(oe,{label:s.label.edition,value:u.edition||"",onChange:d=>a(p,"edition",d)})]}),e.jsx(be,{value:u.summary||"",onChange:d=>a(p,"summary",d),placeholder:s.editor.summaryPlaceholder}),e.jsx(be,{value:u.comment||"",onChange:d=>a(p,"comment",d),placeholder:s.editor.commentPlaceholder}),e.jsx(be,{value:u.additional_comment||"",onChange:d=>a(p,"additional_comment",d),placeholder:s.editor.additionalCommentPlaceholder})]})]},p)}),e.jsx("button",{onClick:x,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function pi({items:t,onChange:n}){const o=F();return e.jsx(En,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function xi({items:t,onChange:n}){const o=F();return e.jsx(En,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Ln(t){var a,c,x,u,p,g,d;const n=((c=(a=t.authors)==null?void 0:a[0])==null?void 0:c.name)||"",o=((x=t.publication_info)==null?void 0:x.year)||"",r=((u=t.current_location)==null?void 0:u.name)||"",s=(p=t.page_count)!=null&&p.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||"",l={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 m=t;if(Array.isArray(m.related_works)){const b=m.related_works.find(h=>h.relation==="part_of");b&&(l.parentWorkId=b.id,l.parentWorkName=b.title)}}if(t.type==="book"){const m=t;l.workId=m.work_id,Array.isArray(m.contained_in)&&m.contained_in.length>0&&(l.collectionId=(d=m.contained_in[0])==null?void 0:d.id)}return l}function ui(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 fi=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:l,onSave:a,onDelete:c,onNavigate:x,renderLink:u,onAskAI:p,renderSectionActions:g,onDownloadResource:d,downloadStatuses:m,relations:b,onRelationsChange:h,headerExtra:S,className:y,style:k}=t;F();const[I,v]=f.useState(s),w=i?s:I;f.useEffect(()=>{s!==I&&v(s)},[s]);const j=f.useCallback(()=>{const N=w==="view"?"edit":"view";i?i(N):v(N)},[w,i]),[z,E]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(N=>{N&&E(N)})},[o,r]);const W=n||z,$=f.useMemo(()=>W?Ln(W):null,[W]),V=i||!n?e.jsx("button",{onClick:j,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,Y=e.jsxs(e.Fragment,{children:[V,S]});return!W&&!$?e.jsx(me,{}):w==="view"?e.jsx(rt,{data:W,transport:r,onNavigate:x?N=>x(N):void 0,renderLink:u,headerExtra:Y,className:y,style:k}):$?e.jsxs("div",{className:y,style:k,children:[Y&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:Y}),e.jsx(Rn,{data:$,onChange:l||(()=>{}),onSave:a||(()=>{}),transport:r,onNavigate:x,showDelete:!!c,onDelete:c,onAskAI:p,renderSectionActions:g,onDownloadResource:d,downloadStatuses:m,relations:b,onRelationsChange:h})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Ft=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Bn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=f.useState(null),[l,a]=f.useState(""),[c,x]=f.useState("idle"),[u,p]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(i(null),a(""),x("idle"),p(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var h;return(h=g.current)==null?void 0:h.focus()},100)},[s]),f.useEffect(()=>{if(c==="success"){const h=setTimeout(n,2e3);return()=>clearTimeout(h)}},[c,n]),f.useEffect(()=>{if(!t)return;const h=S=>{S.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t,n]);const d=async()=>{if(!(!s||!l.trim())){x("submitting"),p("");try{await o({type:s,content:l.trim()}),x("success")}catch(h){x("error"),p(h instanceof Error?h.message:"提交失败,请稍后重试")}}};if(!t)return null;const m=s&&l.trim()&&c!=="submitting",b=Ft.find(h=>h.value===s);return e.jsx("div",{style:gi,onClick:h=>{h.target===h.currentTarget&&n()},children:e.jsxs("div",{style:hi,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:bi,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:mi,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:ki,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:Ft.map(h=>e.jsxs("button",{onClick:()=>i(h.value),style:{...yi,...s===h.value?vi:{}},children:[e.jsx("span",{children:h.icon})," ",h.label]},h.value))}),e.jsx("textarea",{ref:g,value:l,onChange:h=>a(h.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||c==="submitting",style:{...ji,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),c==="error"&&e.jsx("div",{style:wi,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!m,style:{...Si,opacity:m?1:.6,cursor:m?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交反馈"})})]})]})})},gi={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},hi={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)"},bi={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},mi={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},yi={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"},vi={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ji={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"},Si={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ki={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},wi={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Ci=({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:{..._i,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(Bn,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},_i={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"},Mt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],zi=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[i,l]=f.useState("idle"),[a,c]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var d;return(d=x.current)==null?void 0:d.focus()},100)},[n]);const u=async()=>{if(!(!n||!r.trim())){l("submitting"),c("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(d){l("error"),c(d instanceof Error?d.message:"提交失败,请稍后重试")}}},p=n&&r.trim()&&i!=="submitting",g=Mt.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:Ht,children:e.jsxs("div",{style:Li,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Bi,children:"继续提交"})]})}):e.jsxs("div",{style:Ht,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Mt.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...Ii,...n===d.value?Ti:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:x,value:r,onChange:d=>s(d.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Ri}}),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:!p,style:{...Ei,opacity:p?1:.6,cursor:p?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Wi,children:a})]})},Ht={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Ii={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"},Ti={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ri={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"},Ei={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Li={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Bi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Wi={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function $i(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}}function Pi(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 Dt(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 Ai(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 Fi(t,n){const o=t.version_graph,r={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return r;const s=new Set(o.excluded_books??[]),i=o.node_groups??{},l=n.filter(d=>!s.has(d.id)).map(d=>Pi(d,i)).filter(d=>d!==null),a=(o.hypothetical_nodes??[]).map($i),c=[...l,...a],x=new Set(c.map(d=>d.id)),u=new Set,p=[],g=d=>{u.has(d.id)||!x.has(d.source)||!x.has(d.target)||(u.add(d.id),p.push(d))};for(const d of n)s.has(d.id)||!d.lineage||((d.lineage.derived_from??[]).forEach((m,b)=>{g(Dt(d.id,m,b))}),(d.lineage.related_to??[]).forEach((m,b)=>{g(Ai(d.id,m,b))}));for(const d of o.hypothetical_nodes??[])(d.derived_from??[]).forEach((m,b)=>{g(Dt(d.id,m,b))});return{nodes:c,edges:p,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(s)}}function Mi(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(c=>c.id)),i=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...i]),a=(c,x)=>{l.has(x.ref)||o.push(`${c}: derived_from.ref "${x.ref}" 未在 books 或 hypothetical_nodes 中找到`),x.ref_type==="book"&&!s.has(x.ref)&&o.push(`${c}: derived_from.ref "${x.ref}" 标记为 book 但不在 books 列表中`),x.ref_type==="hypothetical"&&!i.has(x.ref)&&o.push(`${c}: derived_from.ref "${x.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const x=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>a(x,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${x}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const x=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>a(x,u))}return o}const Wn=({graph:t,renderLink:n,className:o,style:r})=>{if(!t.nodes.length)return e.jsx("div",{style:{...Qi,...r},className:o,children:"暂无版本图数据"});const s=new Map,i=new Map;for(const p of t.edges)if(p.kind==="derive"){const g=s.get(p.target)??[];g.push(p),s.set(p.target,g)}else for(const g of[p.source,p.target]){const d=i.get(g)??[];d.push(p),i.set(g,d)}const l=new Map(t.nodes.map(p=>[p.id,p])),a=new Map,c=[];for(const p of t.nodes)if(p.group){const g=a.get(p.group)??[];g.push(p),a.set(p.group,g)}else c.push(p);const x=(p,g)=>(p.year??9999)-(g.year??9999);a.forEach(p=>p.sort(x)),c.sort(x);const u=t.groups.filter(p=>a.has(p.id));return e.jsxs("div",{className:o,style:{...Di,...r},children:[t.title&&e.jsx("div",{style:Oi,children:t.title}),t.description&&e.jsx("div",{style:Vi,children:t.description}),u.map(p=>e.jsx(Ot,{label:p.label,color:p.color,nodes:a.get(p.id),incomingMap:s,siblingMap:i,nodeMap:l,renderLink:n},p.id)),c.length>0&&e.jsx(Ot,{label:"其他",nodes:c,incomingMap:s,siblingMap:i,nodeMap:l,renderLink:n})]})},Ot=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:l})=>e.jsxs("div",{style:Ui,children:[e.jsx("div",{style:{...Ni,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:t}),o.map(a=>e.jsx(Hi,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:i,renderLink:l},a.id))]}),Hi=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical";return e.jsxs("div",{style:{...Gi,borderStyle:i?"dashed":"solid",opacity:t.status==="lost"?.7:1},children:[e.jsxs("div",{style:Yi,children:[e.jsx("span",{style:Ki,children:i||!s?t.label:s(t.id,t.label)}),t.year&&e.jsxs("span",{style:Ji,children:[t.year_text??t.year,t.year_uncertain?"?":""]})]}),e.jsxs("div",{style:qi,children:[t.category&&e.jsx(He,{children:t.category}),t.status==="lost"&&e.jsx(He,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(He,{tone:"warn",children:"残本"}),i&&e.jsx(He,{tone:"info",children:"假想祖本"})]}),t.extant_juan&&e.jsxs("div",{style:Zi,children:["现存:",t.extant_juan]}),t.note&&e.jsx("div",{style:Xi,children:t.note}),n.length>0&&e.jsxs("div",{style:Ut,children:[e.jsx("div",{style:Nt,children:"来源:"}),n.map(l=>{const a=r.get(l.source);return e.jsxs("div",{style:Gt(l.confidence),children:[e.jsx("span",{style:Yt,children:l.relation}),e.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,a.label):(a==null?void 0:a.label)??l.source}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Vt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Kt,children:["· ",l.evidence]})]},l.id)})]}),o.length>0&&e.jsxs("div",{style:Ut,children:[e.jsx("div",{style:Nt,children:"关联:"}),o.map(l=>{const a=l.source===t.id?l.target:l.source,c=r.get(a);return e.jsxs("div",{style:Gt(l.confidence),children:[e.jsx("span",{style:Yt,children:l.relation}),e.jsx("span",{children:(c==null?void 0:c.kind)==="book"&&s?s(c.id,c.label):(c==null?void 0:c.label)??a}),e.jsx(Vt,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Kt,children:["· ",l.evidence]})]},l.id)})]})]})},He=({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})},Vt=({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},Di={fontSize:"14px",color:"var(--bim-fg, #333)"},Oi={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Vi={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Ui={marginBottom:"16px"},Ni={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Gi={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Yi={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ki={fontSize:"15px",fontWeight:600},Ji={fontSize:"12px",color:"var(--bim-muted, #777)"},qi={marginBottom:"6px"},Zi={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Xi={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Ut={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Nt={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Gt=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Yt={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Kt={fontSize:"11px",color:"var(--bim-muted, #888)"},Qi={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},$n=({selectedNodeId:t,...n})=>{const[o,r]=f.useState("loading"),[s,i]=f.useState(null);return f.useEffect(()=>{let l=!1;return es().then(a=>{l||(a?(i(a),r("ready")):r("missing"))}),()=>{l=!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(ts,{modules:s,selectedNodeId:t,...n})};async function es(){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,dagre:n,cssLoaded:o}}catch{return null}}const ts=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:l})=>{const{ReactFlow:a,Background:c,Controls:x,Handle:u,Position:p,dagre:g}=l,d=f.useMemo(()=>({version:S=>{const y=S.data,k=y.kind==="hypothetical",I=y.status==="lost",v=y.isSelected,w=y.borderColor??"#888";return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:`2px ${k?"dashed":"solid"} ${v?"#0078d4":w}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:I?.6:1,boxShadow:v?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":k?"none":"0 1px 3px rgba(0,0,0,0.1)"},children:[e.jsx(u,{type:"target",position:p.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:k||!y.renderLink?y.label:y.renderLink(y.bookId,y.label)}),y.yearText&&e.jsxs("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:[y.yearText,y.uncertain?"?":"",y.category?` · ${y.category}`:""]}),I&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:p.Right,style:{visibility:"hidden"}})]})}}),[u,p]),{rfNodes:m,rfEdges:b}=f.useMemo(()=>ns(t,g,n,i),[t,g,n,i]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(a,{nodes:m,edges:b,nodeTypes:d,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(c,{gap:16}),e.jsx(x,{showInteractive:!1})]})})};function ns(t,n,o,r){const l=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:l?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20,ranker:"tight-tree",acyclicer:"greedy"}),a.setDefaultEdgeLabel(()=>({}));const c=new Map(t.groups.map(b=>[b.id,b.color??"#888"])),x=new Map(t.groups.map((b,h)=>[b.id,h])),u=[...t.nodes].sort((b,h)=>{var v,w;const S=b.group?x.get(b.group)??999:999,y=h.group?x.get(h.group)??999:999;if(S!==y)return S-y;const k=b.year??((v=b.year_range)==null?void 0:v[0])??9999,I=h.year??((w=h.year_range)==null?void 0:w[0])??9999;return k-I});for(const b of u)a.setNode(b.id,{width:160,height:90});const p=new Set(["配补","参校","参考","佚文輯入"]),g=new Map(t.nodes.map(b=>[b.id,b]));for(const b of t.edges)if(b.kind==="derive"){const h=g.get(b.source),S=g.get(b.target),y=(h==null?void 0:h.group)&&h.group===(S==null?void 0:S.group),k=p.has(b.relation);let I=1;k?I=0:y&&(I=3),a.setEdge(b.source,b.target,{weight:I,minlen:k?0:1})}n.layout(a);const d=t.nodes.map(b=>{const h=a.node(b.id),S=r&&b.id===r,y={kind:b.kind,label:b.label,bookId:b.kind==="book"?b.id:void 0,yearText:b.year_text??rs(b),uncertain:b.year_uncertain,category:b.category,status:b.status,borderColor:b.group?c.get(b.group):void 0,renderLink:o,isSelected:S};return{id:b.id,type:"version",position:{x:h.x-160/2,y:h.y-90/2},data:y,draggable:!1,selected:S}}),m=t.edges.map(b=>os(b));return{rfNodes:d,rfEdges:m}}function os(t){const n=t.confidence==="probable"||t.confidence==="disputed",o=t.kind==="sibling";return{id:t.id,source:t.source,target:t.target,type:"smoothstep",label:t.relation,labelStyle:{fontSize:11,fontWeight:500,fill:Jt(t.confidence)},labelBgPadding:[4,6],labelBgBorderRadius:4,labelBgStyle:{fill:"var(--bim-bg, #fff)",fillOpacity:1,stroke:"var(--bim-widget-border, #ddd)",strokeWidth:.5},labelShowBg:!0,style:{stroke:Jt(t.confidence),strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":n?"6 4":void 0,opacity:n?.75:1},animated:!1,markerEnd:o?void 0:"arrow",zIndex:1e3}}function rs(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Jt(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)"},is=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,className:l,style:a})=>{const[c,x]=f.useState(n),u=p=>{x(p),i==null||i(p)};return t.nodes.length?e.jsxs("div",{className:l,style:a,children:[e.jsxs("div",{style:ss,children:[e.jsx("button",{onClick:()=>u("list"),style:Zt(c==="list"),children:"列表"}),e.jsx("button",{onClick:()=>u("graph"),style:Zt(c==="graph"),children:"关系图"})]}),c==="list"?e.jsx(Wn,{graph:t,renderLink:o}):e.jsx($n,{graph:t,renderLink:o,height:r,selectedNodeId:s})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"})},ss={display:"flex",gap:4,marginBottom:12},Zt=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"}),ls=({style:t})=>{const n=f.useContext(We);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:"简"})]})};exports.BidLink=U.BidLink;exports.BookIndexError=U.BookIndexError;exports.BookIndexManager=U.BookIndexManager;exports.BookIndexStorage=U.BookIndexStorage;exports.BundleStorage=U.BundleStorage;exports.ConfigError=U.ConfigError;exports.GithubStorage=U.GithubStorage;exports.IdGenerationError=U.IdGenerationError;exports.IdGenerator=U.IdGenerator;exports.LocalStorage=U.LocalStorage;exports.MigrationError=U.MigrationError;exports.StorageError=U.StorageError;exports.base36Decode=U.base36Decode;exports.base36Encode=U.base36Encode;exports.base58Decode=U.base58Decode;exports.buildId=U.buildId;exports.decodeId=U.decodeId;exports.decodeIdString=U.decodeIdString;exports.encodeId=U.encodeId;exports.extractIdFromUrl=U.extractIdFromUrl;exports.extractStatus=U.extractStatus;exports.extractType=U.extractType;exports.normalizeCatalog=U.normalizeCatalog;exports.parseId=U.parseId;exports.smartDecode=U.smartDecode;exports.validateResource=U.validateResource;exports.Badge=Ue;exports.BidUrlProvider=Un;exports.CollatedEdition=yn;exports.CollectionCatalog=xn;exports.CreateEntityDialog=zn;exports.EmendatedBySection=dn;exports.EntityDetail=rn;exports.EntityPickerDialog=Tn;exports.EntitySelector=_n;exports.FeedbackButton=Ci;exports.FeedbackDialog=Bn;exports.FeedbackForm=zi;exports.FeedbackList=vn;exports.FormInput=oe;exports.FormTextArea=be;exports.HomePage=tt;exports.IndexApp=Lr;exports.IndexBrowser=et;exports.IndexDetail=rt;exports.IndexEditor=Rn;exports.IndexView=fi;exports.LocaleContext=We;exports.LocaleProvider=Qn;exports.LocaleToggle=ls;exports.ModeIndicator=nn;exports.RelationPanel=wn;exports.ResourceEditor=Qe;exports.ResourceList=ot;exports.SearchInput=on;exports.Section=ie;exports.SmartBidInput=Oe;exports.SourceEditor=jn;exports.VersionLineageGraph=$n;exports.VersionLineageList=Wn;exports.VersionLineageView=is;exports.WorkCatalog=Br;exports.buildLineageGraph=Fi;exports.detailToEditor=Ln;exports.editorToDetail=ui;exports.formatTemplate=$e;exports.parseSourceString=Sn;exports.stringifySources=kn;exports.useBidUrl=le;exports.useConvert=D;exports.useT=F;exports.validateLineageGraph=Mi;
|
|
1
|
+
"use strict";var Pn=Object.create;var dt=Object.defineProperty;var An=Object.getOwnPropertyDescriptor;var Fn=Object.getOwnPropertyNames;var Mn=Object.getPrototypeOf,Hn=Object.prototype.hasOwnProperty;var Dn=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Fn(n))!Hn.call(t,s)&&s!==o&&dt(t,s,{get:()=>n[s],enumerable:!(r=An(n,s))||r.enumerable});return t};var _e=(t,n,o)=>(o=t!=null?Pn(Mn(t)):{},Dn(n||!t||!t.__esModule?dt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("./storage-entry-D6KFK-rC.cjs"),e=require("react/jsx-runtime"),f=require("react"),On=require("react-dom"),Vn=t=>`/book-index?id=${t}`,Zt=f.createContext(Vn);function Un({buildUrl:t,children:n}){const o=f.useMemo(()=>t,[t]);return e.jsx(Zt.Provider,{value:o,children:n})}function ae(){return f.useContext(Zt)}function be(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Nn(t,n){return be(t).includes(n)}const Qt={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Yn={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Gn={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},$e=f.createContext(null),en={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:"圖片資源"}},Kn={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:"图片资源"}},Jn={"zh-Hant":en,"zh-Hans":Kn},tn="bim-locale";function qn(){try{const t=localStorage.getItem(tn);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Xn(t){try{localStorage.setItem(tn,t)}catch{}}const Zn="zh-Hant",Qn=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=f.useState(t??Zn),i=t??r;f.useEffect(()=>{if(t)return;const u=qn();u&&u!==r&&s(u)},[]);const[l,a]=f.useState(null);f.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(u=>{const p=u.Converter({from:"tw",to:"cn"});a(()=>p)}).catch(()=>{a(()=>u=>u)}):a(null)},[i]);const c=f.useCallback(u=>{s(u),Xn(u),n==null||n(u)},[n]),x=f.useMemo(()=>({locale:i,setLocale:c,messages:Jn[i],converter:l}),[i,c,l]);return e.jsx($e.Provider,{value:x,children:o})};function P(){const t=f.useContext($e);return(t==null?void 0:t.messages)??en}const eo=2e3;function D(){const t=f.useContext($e),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(l=>{if(!l)return"";if(!o)return l;const a=r.current.get(l);if(a!==void 0)return a;const c=o(l);if(r.current.size>=eo){const x=r.current.keys().next().value;x!==void 0&&r.current.delete(x)}return r.current.set(l,c),c},[o]);return f.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function Pe(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function to(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 no(){return{id:"",name:"",url:"",type:"text",details:""}}const et=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=P(),[l,a]=f.useState(null),c=[{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}],x=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],u=y=>{if(!s)return!0;const C=be(y);return s==="text"?C.includes("text"):s==="image"?C.includes("image")||C.includes("physical"):s==="physical"?C.includes("physical"):C.includes(s)},p=t.map((y,C)=>({item:y,originalIndex:C})).filter(({item:y})=>u(y)),g=()=>{const y=no();s&&(y.type=s),n([...t,y]),a(t.length)},d=y=>{n(t.filter((C,I)=>I!==y)),a(null)},b=(y,C,I)=>{const v=[...t];if(v[y]={...v[y],[C]:I},C==="url"&&!v[y].id){const k=to(I);k&&(v[y].id=k)}n(v)},m=(y,C,I)=>{const k={...t[y].metadata||{}};I?k[C]=I:delete k[C],b(y,"metadata",Object.keys(k).length>0?k:void 0)},h=(y,C)=>{const I=C.trim()?C.split(/[,,、]/).map(v=>v.trim()).filter(Boolean):void 0;b(y,"structure",I)},S=(y,C,I)=>{const k=t[y].coverage||{level:1,ranges:""};C==="level"?k.level=parseInt(I)||1:k.ranges=I,b(y,"coverage",k.ranges?k:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[p.map(({item:y,originalIndex:C})=>{var I,v,k;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:()=>a(l===C?null:C),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===C?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:oo(y.type??"text"),color:"#fff"},children:(()=>{var _,E;const j=be(y);return j.length===0?y.type??"text":j.length===1?((_=c.find(w=>w.value===j[0]))==null?void 0:_.label)??j[0]:j.includes("text")&&j.includes("image")?((E=c.find(w=>w.value==="text+image"))==null?void 0:E.label)??"text+image":j.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${i.editor.resourcePlaceholder} ${C+1}`}),y.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:j=>j.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&y.url&&ro(C,r==null?void 0:r[C],o,i),e.jsx("button",{onClick:j=>{j.stopPropagation(),d(C)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===C&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Nn(y,"image")&&y.url&&io(y,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:y.type,onChange:j=>b(C,"type",j.target.value),style:{...pe,flex:1},children:c.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]}),e.jsxs("label",{style:ze,children:[e.jsx("span",{style:Ie,children:i.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:j=>b(C,"root_type",j.target.value),style:{...pe,flex:1},children:x.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:y.id,onChange:j=>b(C,"id",j.target.value),placeholder:i.editor.idAutoExtract,style:{...pe,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:y.name,onChange:j=>b(C,"name",j.target.value),placeholder:i.editor.resourceName,style:{...pe,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:j=>b(C,"url",j.target.value),placeholder:i.editor.resourceUrl,style:pe}),e.jsx("input",{type:"text",value:((I=y.structure)==null?void 0:I.join("、"))||"",onChange:j=>h(C,j.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=y.coverage)==null?void 0:v.level)??"",onChange:j=>S(C,"level",j.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:((k=y.coverage)==null?void 0:k.ranges)||"",onChange:j=>S(C,"ranges",j.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...pe,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:j=>b(C,"details",j.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(([j,_])=>{var E;return e.jsxs("label",{style:{...ze,gap:"4px"},children:[e.jsx("span",{style:{...Ie,minWidth:"56px"},children:_}),e.jsx("input",{type:"text",value:((E=y.metadata)==null?void 0:E[j])||"",onChange:w=>m(C,j,w.target.value),placeholder:_,style:{...pe,flex:1}})]},j)})})]})]})]})]},C)}),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 oo(t){switch(t){case"text":return"#2196f3";case"image":return"#ff9800";case"text+image":return"#9c27b0";case"physical":return"#795548"}}function ro(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:l=>{l.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 io(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"},so={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function lo(t){try{const n=new URL(t).hostname;return so[n]}catch{return}}const pt={text:"#2196f3",image:"#ff9800","text+image":"#9c27b0",physical:"#795548"};function ao(t){return t.includes("text")&&t.includes("image")?pt["text+image"]:pt[t[0]||"physical"]}const xt={text:0,image:1,physical:2};function Oe(t){return t.length===0?"physical":[...t].sort((n,o)=>(xt[n]??99)-(xt[o]??99)).join("+")}function co(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const a=i.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const l=t[i];if(l.volumes&&l.volumes.length>0)continue;const a=n(l.name);if(!a)continue;const[c,x]=a,u=`${c}|${Oe(be(l))}`;o.has(u)||o.set(u,{base:{...l,name:c,url:"",volumes:[]},volumes:[]}),o.get(u).volumes.push({volume:x,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((l,a)=>l.volume-a.volume),i.base.volumes=i.volumes,i.base.expected_volumes=i.volumes.length,r.push(i.base);else for(let l=0;l<t.length;l++)if(s.has(l)){const a=n(t[l].name),c=a&&`${a[0]}|${Oe(be(t[l]))}`,x=`${i.base.name}|${Oe(be(i.base))}`;c===x&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const rt=({items:t,groupByType:n=!0,onNavigate:o,renderLink:r})=>{const s=P(),i=f.useMemo(()=>co(t||[]),[t]),l={text:s.resourceType.text,image:s.resourceType.image,"text+image":s.resourceType.textImage,physical:s.resourceType.physical},a=p=>l[p]?l[p]:p.split("+").map(g=>l[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((p,g)=>e.jsx(ut,{item:p},p.id||g))});const c=new Map;for(const p of i){const g=Oe(be(p));c.has(g)||c.set(g,[]),c.get(g).push(p)}const x=["text","image","text+image","physical"],u=[...x.filter(p=>c.has(p)),...[...c.keys()].filter(p=>!x.includes(p)).sort()];return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:u.map(p=>{const g=c.get(p),d=ao(p.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:d,whiteSpace:"nowrap",flexShrink:0},children:a(p)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:g.map((b,m)=>e.jsx(ut,{item:b,onNavigate:o,renderLink:r},b.id||m))})]},p)})})};function po(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 xo(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 uo(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 fo={bw:{label:"",bg:"#f5f5f5",fg:"#757575"},color:{label:"",bg:"#fff8e1",fg:"#f57f17"}},ut=({item:t})=>{const n=P(),{convert:o}=D(),[r,s]=f.useState(!1),i=f.useMemo(()=>(t.url?lo(t.url):void 0)||o(t.name),[t.url,t.name,o]),l=f.useMemo(()=>!t.volumes||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||uo(b)})),[t.volumes]),a=l&&l.length>0,c=a?new Set(l.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,x=a?new Set(l.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,u=t.expected_volumes??(a?c+x:0),p=t.color_mode?{...fo[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!a?o(t.details):null,d={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:d,children:[e.jsx("span",{style:{fontWeight:500},children:i}),p&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:p.bg,color:p.fg},children:p.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),a&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c,"/",u,n.unit.volume,x>0&&e.jsxs("span",{style:{color:"#e67e22",marginLeft:"3px"},children:["缺",x]})]}),t.url&&e.jsx("a",{href:(()=>{const b=xo(t.metadata);return b?po(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),a&&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?"▲":"▼"})]}),a&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(b=>{const m=b.status==="missing";return b.url&&!m?e.jsx("a",{href:b.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:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:m?"#e67e22":"var(--bim-desc-fg, #999)",textDecoration:m?"line-through":"none",opacity:m?.6:1},children:b.volume},b.volume)})})]})},nn=({indexSource:t,syncConfig:n,variant:o="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:i,onSelectFolder:l})=>{const a=P(),c=t==="local",x=(n==null?void 0:n.isDraft)??!0,u=(n==null?void 0:n.repoPath)||"",p=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)"},d={onMouseOver:m=>m.currentTarget.style.opacity="0.8",onMouseOut:m=>m.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:x?a.mode.switchToOfficial:a.mode.switchToDraft,style:{...g,background:x?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...d,children:[e.jsx("span",{children:x?"📝":"📚"}),e.jsx("span",{children:x?"draft":"official"})]});return o==="index-browser"?c?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,title:a.mode.switchToSync,style:g,...d,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:a.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:u||a.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...d,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:a.mode.switchToLocal,style:g,...d,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:a.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:p||a.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...d,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:c?a.mode.switchToGithub:a.mode.switchToLocal,style:g,...d,children:[e.jsx("span",{children:c?"📁":"🌐"}),e.jsx("span",{children:c?a.mode.localMode:a.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),c&&e.jsxs("div",{onClick:l,title:u||a.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:u?"100px":"auto",justifyContent:"space-between"},...d,children:[e.jsx("span",{children:"📂"}),p&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:p})]}),!c&&p&&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:p})]})]})},Ye="bim-search-history",ft=10,gt=8;function Ee(){try{const t=localStorage.getItem(Ye);return t?JSON.parse(t):[]}catch{return[]}}function go(t){try{const n=Ee().filter(o=>o!==t);n.unshift(t),n.length>ft&&(n.length=ft),localStorage.setItem(Ye,JSON.stringify(n))}catch{}}function ho(t){try{const n=Ee().filter(o=>o!==t);localStorage.setItem(Ye,JSON.stringify(n))}catch{}}function bo(){try{localStorage.removeItem(Ye)}catch{}}const on=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=P(),a=i??l.search.placeholder,c={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[x,u]=f.useState(!1),[p,g]=f.useState([]),[d,b]=f.useState(-1),[m,h]=f.useState(Ee),S=f.useRef(null),y=f.useRef(null),C=f.useRef(null);f.useEffect(()=>{b(-1);const w=n.trim();if(!w){g(m.map(F=>({type:"history",text:F})));return}if(!t.searchAll){g([]);return}let R=!1;const A=setTimeout(()=>{t.searchAll(w,gt).then(F=>{if(R)return;const H=[...F.works,...F.books,...F.collections,...F.entities??[]];g(H.slice(0,gt).map(W=>({type:"entry",text:W.title||W.id,entry:W})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(A)}},[n,m,t]),f.useEffect(()=>{const w=R=>{C.current&&!C.current.contains(R.target)&&u(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]),f.useEffect(()=>{const w=R=>{var A,F;if(R.key==="/"&&document.activeElement!==S.current){const H=(A=document.activeElement)==null?void 0:A.tagName;if(H==="INPUT"||H==="TEXTAREA"||H==="SELECT")return;R.preventDefault(),(F=S.current)==null||F.focus()}};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[]);const I=f.useCallback(w=>{w.trim()&&(go(w.trim()),h(Ee())),r(w),u(!1)},[r]),v=f.useCallback(w=>{w.type==="history"?(o(w.text),I(w.text)):w.entry&&(s?(s(w.entry),u(!1)):(o(w.text),I(w.text)))},[o,I,s]),k=f.useCallback(w=>{if(!x||p.length===0){w.key==="Enter"&&I(n);return}switch(w.key){case"ArrowDown":w.preventDefault(),b(R=>(R+1)%p.length);break;case"ArrowUp":w.preventDefault(),b(R=>(R-1+p.length)%p.length);break;case"Enter":w.preventDefault(),d>=0&&d<p.length?v(p[d]):I(n);break;case"Escape":w.preventDefault(),u(!1);break}},[x,p,d,n,I,v]),j=f.useCallback((w,R)=>{R.stopPropagation(),ho(w),h(Ee()),g(A=>A.filter(F=>!(F.type==="history"&&F.text===w)))},[]),_=f.useCallback(w=>{w.stopPropagation(),bo(),h([]),g([])},[]);f.useEffect(()=>{if(d>=0&&y.current){const w=y.current.children;w[d]&&w[d].scrollIntoView({block:"nearest"})}},[d]);const E=!n.trim()&&m.length>0;return e.jsxs("div",{ref:C,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:a,value:n,onChange:w=>{o(w.target.value),u(!0)},onFocus:()=>{u(!0)},onKeyDown:k,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"}}),x&&p.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[E&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:_,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),p.map((w,R)=>e.jsxs("div",{onClick:()=>v(w),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:R===d?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:w.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w.text}),w.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[c[w.entry.type],w.entry.edition&&` · ${w.entry.edition}`,w.entry.author&&` · ${w.entry.author}`]}),w.type==="history"&&e.jsx("button",{onClick:A=>j(w.text,A),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${w.type}-${w.text}-${R}`))]})]})},We="bim-recent-ids",ht="bim-recent-entries",bt=50,Xe=5,mo=50,yo=200;function Le(){try{const t=localStorage.getItem(We);if(t)return JSON.parse(t);const n=localStorage.getItem(ht);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(We,JSON.stringify(o)),localStorage.removeItem(ht),o}return[]}catch{return[]}}function vo(t){try{const n=Le().filter(o=>o!==t);n.unshift(t),n.length>bt&&(n.length=bt),localStorage.setItem(We,JSON.stringify(n))}catch{}}function jo(t){try{const n=Le().filter(o=>o!==t);localStorage.setItem(We,JSON.stringify(n))}catch{}}function So(){try{localStorage.removeItem(We)}catch{}}const ko={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},tt=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c,hideModeIndicator:x,initialQuery:u,onQueryChange:p,headerRight:g})=>{const d=P(),b=[{type:"work",icon:"✍️",name:d.indexType.work,key:"works"},{type:"book",icon:"📖",name:d.indexType.book,key:"books"},{type:"collection",icon:"📚",name:d.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:d.indexType.entity,key:"entities"}],[m,h]=f.useState(u??""),[S,y]=f.useState(null),[C,I]=f.useState(null),[v,k]=f.useState(!1),[j,_]=f.useState(null),[E,w]=f.useState(""),[R,A]=f.useState(!u),[F,H]=f.useState(Le),[W,O]=f.useState([]),[L,z]=f.useState(!1),[V,B]=f.useState(!1),[U,Y]=f.useState(null),[Z,ne]=f.useState(null),he=f.useRef(void 0),ge=f.useRef(!1),Q=f.useCallback(async($,J)=>{if(!$.trim()){A(!0),y(null),I(null);return}A(!1),k(!0),w("");try{if(t.searchAll){const G=await t.searchAll($,J??Xe);y(G)}else{const G=["work","book","collection","entity"],K=await Promise.all(G.map(ee=>t.search($,ee,{page:1,pageSize:J??Xe})));y({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(G){w(G instanceof Error?G.message:String(G)),y(null)}finally{k(!1)}},[t]);f.useEffect(()=>{let $=!1;const J=()=>{var M,oe;const G=["work","book","collection","entity"],K=Promise.all(G.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((M=t.getResourceCounts)==null?void 0:M.call(t).catch(()=>null))??Promise.resolve(null),T=((oe=t.getSubtypeStats)==null?void 0:oe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([K,ee,T]).then(([ce,de,ct])=>{$||(Y({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}),ct&&ne(ct))})};return t.getCounts?t.getCounts().then(G=>{var K,ee;$||(Y({works:G.works,books:G.books,collections:G.collections,entities:G.entities,hasText:(K=G.resourceCounts)==null?void 0:K.hasText,hasImage:(ee=G.resourceCounts)==null?void 0:ee.hasImage}),G.subtypeStats&&ne(G.subtypeStats))}).catch(()=>{$||J()}):J(),()=>{$=!0}},[t]),f.useEffect(()=>{ge.current||!(u!=null&&u.trim())||(ge.current=!0,Q(u))},[u,Q]);const q=f.useCallback($=>{if(h($),p==null||p($),!$.trim()){A(!0),y(null),I(null);return}he.current&&clearTimeout(he.current),he.current=setTimeout(()=>{I(null),Q($)},yo)},[Q,p]),Ge=f.useCallback($=>{he.current&&clearTimeout(he.current),p==null||p($),Q($)},[Q,p]),Ke=f.useCallback($=>{I($),Q(m,mo)},[m,Q]);f.useEffect(()=>{if(!F.length){O([]);return}let $=!1;return z(!0),Promise.all(F.slice(0,10).map(async J=>{var G,K,ee;try{if(t.getEntry){const M=await t.getEntry(J);if(M)return M}const T=await t.getItem(J);if(T){const M=T.authors;return{id:J,title:T.title||J,type:T.type||"work",author:(G=M==null?void 0:M[0])==null?void 0:G.name,dynasty:(K=M==null?void 0:M[0])==null?void 0:K.dynasty,role:(ee=M==null?void 0:M[0])==null?void 0:ee.role,edition:T.edition||void 0}}}catch{}return{id:J,title:J,type:"work",notFound:!0}})).then(J=>{$||(O(J),z(!1))}),()=>{$=!0}},[F,t]);const we=$=>{_($.id),vo($.id),H(Le()),r==null||r($)},Ce=$=>{jo($),H(Le())},Je=()=>{So(),H([])},Ae=$=>b.find(J=>J.type===$),qe=S&&(S.works.length>0||S.books.length>0||S.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:d.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[g,!x&&e.jsx(nn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:a,onSelectFolder:c})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(on,{transport:t,value:m,onChange:q,onSearch:Ge,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:d.action.newEntry})]}),U&&R&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children: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:[d.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.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:"·"}),d.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:[d.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),d.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:d.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})]}):R?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:d.search.loading}):W.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:d.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:d.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:W.slice(0,V?10:3).map($=>$.notFound?e.jsx(wo,{id:$.id,onRemove:Ce,t:d},$.id):e.jsx(mt,{entry:$,selected:j===$.id,onClick:we,getConfig:Ae,onRemove:Ce},$.id))}),!V&&W.length>3&&e.jsx("button",{onClick:()=>B(!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:d.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:d.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.searchSubtitle})]})}):qe?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:b.map(({type:$,icon:J,name:G,key:K})=>{const ee=S[K]??[],T=ko[K],M=S[T]??0;if(ee.length===0)return null;const ce=!(C===$)&&M>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," ",G,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[M," ",d.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>Ke($),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:d.action.viewAll})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:ee.map(de=>e.jsx(mt,{entry:de,selected:j===de.id,onClick:we,getConfig:Ae,query:m},de.id))})]},$)})}):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:Pe(d.search.noResultsFor,{query:m})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:d.search.tryOther})]})})]})},mt=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=P(),{convert:a}=D(),c=[...t.additional_titles||[],...t.attached_texts||[]],x=s&&c.length?c.find(u=>{const p=typeof u=="string"?u:u==null?void 0:u.book_title;return p==null?void 0:p.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:a(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:a(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]}),t.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??"?"]})]}),x&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",a(x)]})]}),i?e.jsx("button",{onClick:u=>{u.stopPropagation(),i(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},wo=({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 Co(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 _o({data:t}){const{convert:n}=D(),{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 zo({alt_names:t}){const{convert:n}=D(),o=new Map;for(const i of t){const l=i.type||"別名";o.has(l)||o.set(l,[]),o.get(l).push(i.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...o.keys()].sort((i,l)=>{const a=r.indexOf(i),c=r.indexOf(l);return a===-1&&c===-1?0:a===-1?1:c===-1?-1:a-c});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(i=>{const l=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:l.map((a,c)=>e.jsxs("span",{children:[c>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(a)]},c))})]},i)})})}function Io({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 To({works:t,transport:n,onNavigate:o,renderLink:r}){const s=P(),{convert:i}=D(),l=ae(),[a,c]=f.useState(new Map);f.useEffect(()=>{if(!n)return;let g=!1;const d=t.map(m=>m.work_id);return(async()=>{const m=new Map;if(n.getEntriesByIds)try{const C=await n.getEntriesByIds(d);let I=!0;for(let v=0;v<d.length;v++){const k=C[v];k!=null&&k.title?m.set(d[v],k.title):k!=null&&k.primary_name?m.set(d[v],k.primary_name):I=!1}if(I)return m}catch{}const h=[...d],S=8,y=new Array(S).fill(0).map(async()=>{for(;h.length;){const C=h.shift();if(!C)break;if(!m.has(C))try{if(n.getEntry){const k=await n.getEntry(C);if(k!=null&&k.title){m.set(C,k.title);continue}}const I=await n.getItem(C),v=I&&(I.title||I.primary_name)||C;m.set(C,v)}catch{m.set(C,C)}}});return await Promise.all(y),m})().then(m=>{g||c(m)}),()=>{g=!0}},[t,n]);const x=new Map;for(const g of t){const d=g.role||"";x.has(d)||x.set(d,[]),x.get(d).push(g)}const u=["撰","編","注","輯","集","校","評","譯","述","作",""],p=[...x.keys()].sort((g,d)=>{const b=u.indexOf(g),m=u.indexOf(d);return b===-1&&m===-1?g.localeCompare(d):b===-1?1:m===-1?-1:b-m});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,")"]})]}),p.map(g=>{const d=x.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:["(",d.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:d.map((b,m)=>{const h=i(a.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,h)},m):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),o(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:h})},m):e.jsx("li",{children:h},m)})})]},g)})]})}const rn=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var u;const i=P(),{convert:l}=D();let a=!1;try{a=N.extractStatus(t.id)==="draft"}catch{}const c=Co(t),x=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:[l(t.primary_name),e.jsx(_o,{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}),x&&t.subtype!=="people"&&e.jsx("span",{children:x}),a&&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})]}),c&&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(zo,{alt_names:t.alt_names}),e.jsx(Io,{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:l(t.description.text)}),t.works&&t.works.length>0&&e.jsx(To,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},Ro=["〇","一","二","三","四","五","六","七","八","九"],yt=["","十","百","千"];function sn(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 l=parseInt(n[i]),a=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&a===1&&i===0?r+=yt[a]:r+=Ro[l]+yt[a])}return r}function ln({type:t}){const n=P(),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 Eo({isDraft:t}){const n=P();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 Lo({id:t}){const n=P(),[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 an({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const a=s(i.name),c=i.entity_id?e.jsx(le,{id:i.entity_id,label:a,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:a});return e.jsxs("span",{children:[l>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),"〕"]}),c,i.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(i.role)]})]},l)})})}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 Bo({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:l,meta:a,headerExtra:c,onNavigate:x,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}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),c&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:c})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(ln,{type:r}),e.jsx(Eo,{isDraft:s}),e.jsx(Lo,{id:t})]}),((i==null?void 0:i.length)||a.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(an,{authors:i,type:r,onNavigate:x,renderLink:u}),a]})]})}function cn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=P(),{convert:l}=D();if(!t.length)return null;const[a,c]=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((x,u)=>{const p=a===u;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...p?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>c(p?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:p?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(x.source)}),!p&&o&&x.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(x.title_info)}),x.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(le,{id:x.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),p&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(x.title_info||x.author_info||x.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[x.title_info&&e.jsx(xe,{label:i.label.titleInfo,children:l(x.title_info)}),x.author_info&&e.jsx(xe,{label:i.label.authorInfo,children:l(x.author_info)}),x.edition&&e.jsx(xe,{label:i.label.edition,children:l(x.edition)})]}),x.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:l(x.summary)})]}),x.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:l(x.comment)})]}),x.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:l(x.additional_comment)})]})]})]},u)})})]})}function Wo({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(cn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function dn({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(cn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function pn({label:t,items:n}){const{convert:o}=D();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 $o({items:t}){const n=P();return e.jsx(pn,{label:n.section.aliases,items:t})}function Po({items:t}){const n=P();return e.jsx(pn,{label:n.section.attachedTexts,items:t})}function Ao({items:t}){const n=P(),{convert:o}=D();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 Fo({items:t}){const n=P(),{convert:o}=D();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 Mo({items:t}){const n=P(),{convert:o}=D();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 vt({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=D(),[l,a]=f.useState([]);return f.useEffect(()=>{if(!n.length){a([]);return}if(!o){a(n.map(x=>({id:x})));return}let c=!1;return Promise.all(n.map(x=>o.getItem(x).then(u=>({id:x,title:u?u.title:void 0,edition:u?u.edition:void 0,type:u?u.type:void 0})).catch(()=>({id:x})))).then(x=>{c||a(x)}),()=>{c=!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:(l.length?l:n.map(c=>({id:c}))).map(c=>{const x=c.edition?`${i(c.title)||c.id}(${i(c.edition)})`:i(c.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:c.id,label:x,onNavigate:r,renderLink:s})},c.id)})})]}):null}function Ho({book:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=D(),[i,l]=f.useState(!1),a=t.resources&&t.resources.length>0,c=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:"10px 14px",borderBottom:a&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1},children:e.jsx(le,{id:t.id,label:c,onNavigate:n,renderLink:o})}),a&&e.jsx("span",{onClick:()=>l(x=>!x),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:"▼"})]}),a&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(rt,{items:t.resources,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Do({ids:t,transport:n,onNavigate:o,renderLink:r,footer:s}){const i=P(),[l,a]=f.useState([]);return f.useEffect(()=>{if(!t.length){a([]);return}if(!n){a(t.map(x=>({id:x})));return}let c=!1;return Promise.all(t.map(x=>n.getItem(x).then(u=>({id:x,title:u?u.title:void 0,edition:u?u.edition:void 0,resources:u?u.resources:void 0})).catch(()=>({id:x})))).then(x=>{c||a(x)}),()=>{c=!0}},[t,n]),t.length?e.jsxs(e.Fragment,{children:[e.jsxs(ie,{children:[i.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),s,e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:(l.length?l:t.map(c=>({id:c}))).map(c=>e.jsx(Ho,{book:c,onNavigate:o,renderLink:r},c.id))})]}):null}function Oo({workData:t,onNavigate:n,renderLink:o}){var i,l,a;const r=P(),{convert:s}=D();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:"12px 16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx(ln,{type:"work"}),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)}):((i=t.juan_count)==null?void 0:i.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[sn(t.juan_count.number),r.unit.juan]}):null]}),e.jsxs("div",{style:{padding:"12px 16px"},children:[t.authors&&t.authors.length>0&&e.jsx(an,{authors:t.authors,type:"work",onNavigate:n,renderLink:o}),((l=t.description)==null?void 0:l.text)&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,margin:(a=t.authors)!=null&&a.length?"8px 0 0":"0",textAlign:"justify"},children:s(t.description.text)}),t.parent_work&&e.jsx("div",{style:{marginTop:"8px",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 Vo({items:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=D();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:Pe(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const it=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:l,className:a,style:c})=>{var A,F,H,W,O,L;const x=P(),{convert:u}=D(),[p,g]=f.useState(null),[d,b]=f.useState(!1),[m,h]=f.useState(null),[S,y]=f.useState(null),[C,I]=f.useState([]),v=t||p;if(f.useEffect(()=>{if(t||!n||!o)return;let z=!1;return b(!0),h(null),o.getItem(n).then(V=>{z||(V?g(V):h(x.misc.notFoundEntry))}).catch(V=>{z||h(V instanceof Error?V.message:x.misc.loadFailed)}).finally(()=>{z||b(!1)}),()=>{z=!0}},[t,n,o]),f.useEffect(()=>{if(!v||!o){y(null),I([]);return}let z=!1;const V=v.type==="book"||v.type==="collection"?v.work_id:void 0;if(V?o.getItem(V).then(B=>{!z&&B&&B.type==="work"&&y(B)}).catch(()=>{}):y(null),v.type==="book"){const B=v;B.contained_in&&B.contained_in.length>0?Promise.all(B.contained_in.map(U=>{const Y=typeof U=="string"?U:U.id,Z=typeof U=="string"?void 0:U.volume_index;return o.getItem(Y).then(ne=>({id:Y,title:ne&&ne.title||Y,volume_index:Z})).catch(()=>({id:Y,title:Y,volume_index:Z}))})).then(U=>{z||I(U)}):I([])}else I([]);return()=>{z=!0}},[v,o]),d)return e.jsx("div",{className:a,style:{...c,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((z,V)=>e.jsx("div",{style:{height:V===1?"32px":"16px",width:`${z}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},V))})});if(m)return e.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:m});if(!v)return null;if(v.type==="entity")return e.jsx("div",{className:a,style:c,children:e.jsx(rn,{data:v,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const k=v.type==="book"?v:null,j=v.type==="collection"?v:null,_=v.type==="work"?v:null;let E=!1;try{E=N.extractStatus(v.id)==="draft"}catch{}let w="";v.measure_info?w=u(v.measure_info):(A=v.juan_count)!=null&&A.number?w=sn(v.juan_count.number)+x.unit.juan:(F=v.juan_count)!=null&&F.description&&(w=u(v.juan_count.description));const R=[];return(H=v.publication_info)!=null&&H.year&&R.push(e.jsx(xe,{label:x.label.year,children:v.publication_info.year},"year")),(W=v.current_location)!=null&&W.name&&R.push(e.jsx(xe,{label:x.label.currentLocation,children:u(v.current_location.name)},"loc")),(O=v.page_count)!=null&&O.description&&R.push(e.jsx(xe,{label:x.label.pageCount,children:v.page_count.description},"page")),k!=null&&k.edition&&R.push(e.jsx(xe,{label:x.label.edition,children:u(k.edition)},"ver")),_!=null&&_.parent_work&&R.push(e.jsx(xe,{label:x.label.parentWork,children:e.jsx(le,{id:_.parent_work.id,label:u(_.parent_work.title),onNavigate:r,renderLink:s})},"pw")),_!=null&&_.parent_works&&_.parent_works.length>0&&!_.parent_work&&R.push(e.jsx(xe,{label:x.label.parentWork,children:_.parent_works.map((z,V)=>e.jsxs("span",{children:[V>0&&"、",e.jsx(le,{id:z,onNavigate:r,renderLink:s})]},z))},"pws")),e.jsxs("div",{className:a,style:c,children:[e.jsx(Bo,{id:v.id,title:u(v.title),edition:v.edition?u(v.edition):void 0,type:v.type,isDraft:E,authors:v.authors,volumeText:w,meta:R,headerExtra:i,onNavigate:r,renderLink:s}),((L=v.description)==null?void 0:L.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"},children:u(v.description.text)}),C.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:x.section.containedIn}),e.jsx(Vo,{items:C,onNavigate:r,renderLink:s})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:x.section.belongsToWork}),e.jsx(Oo,{workData:S,onNavigate:r,renderLink:s})]}),v.additional_works&&v.additional_works.length>0&&e.jsx(Ao,{items:v.additional_works}),v.additional_titles&&v.additional_titles.length>0&&e.jsx($o,{items:v.additional_titles}),v.attached_texts&&v.attached_texts.length>0&&e.jsx(Po,{items:v.attached_texts}),v.indexed_by&&v.indexed_by.length>0&&e.jsx(Wo,{items:v.indexed_by,onNavigate:r,renderLink:s}),v.emendated_by&&v.emendated_by.length>0&&e.jsx(dn,{items:v.emendated_by,onNavigate:r,renderLink:s}),v.resources&&v.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{children:x.section.resources}),e.jsx(rt,{items:v.resources,groupByType:!0,onNavigate:r,renderLink:s})]}),(k==null?void 0:k.location_history)&&k.location_history.length>0&&e.jsx(Fo,{items:k.location_history}),(j==null?void 0:j.history)&&j.history.length>0&&e.jsx(Mo,{items:j.history}),(k==null?void 0:k.related_books)&&k.related_books.length>0&&e.jsx(vt,{title:x.section.relatedVersions,ids:k.related_books,transport:o,onNavigate:r,renderLink:s}),(j==null?void 0:j.books)&&j.books.length>0&&e.jsx(vt,{title:x.section.containedBooks,ids:j.books,transport:o,onNavigate:r,renderLink:s}),(j==null?void 0:j.contained_works)&&j.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ie,{children:[x.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",j.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.contained_works.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))})]}),(_==null?void 0:_.books)&&_.books.length>0&&e.jsx(Do,{ids:_.books,transport:o,onNavigate:r,renderLink:s,footer:l}),(_==null?void 0:_.related_works)&&_.related_works.length>0&&(()=>{const z=[],V=_.related_works.filter(Y=>Y.relation==="part_of"),B=_.related_works.filter(Y=>Y.relation==="has_part"),U=_.related_works.filter(Y=>!Y.relation);return V.length>0&&z.push({label:x.section.belongsToWork,items:V}),B.length>0&&z.push({label:x.section.containedWorks,items:B}),U.length>0&&z.push({label:x.section.relatedWorks,items:U}),z.map(Y=>e.jsxs("div",{children:[e.jsxs(ie,{children:[Y.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",Y.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Y.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))})]},Y.label))})()]})};function Uo({data:t}){const n=P(),{convert:o}=D(),{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 No({sections:t,activeSection:n,onSelect:o}){const r=P();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>o(null),style:jt(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:jt(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 jt(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 Yo({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 Go(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 St({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=P(),{convert:i}=D(),l=t.book_id||t.work_id,a=r&&t.volumes.length>0?Go(t.volumes,s.unit.volume):null,c=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:a}),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(x=>i(x)).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:c?"#e67e22":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Yo,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:o}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const xn=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const a=P(),[c,x]=f.useState(null),[u,p]=f.useState(!1),[g,d]=f.useState(null),[b,m]=f.useState(null),[h,S]=f.useState(""),y=t||c;f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let j=!1;return p(!0),d(null),o.getCollectionCatalog(n).then(_=>{j||(_?x(_):d(a.catalog.notFound))}).catch(_=>{j||d(_ instanceof Error?_.message:a.catalog.loadFailed)}).finally(()=>{j||p(!1)}),()=>{j=!0}},[t,n,o,a]);const C=(y==null?void 0:y.sections)&&y.sections.length>0,I=f.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const j=y.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(j).size<j.length},[y]),v=f.useMemo(()=>{if(!y)return[];let j=y.books;if(b&&(j=j.filter(_=>_.section===b)),h.trim()){const _=h.trim().toLowerCase();j=j.filter(E=>E.title.toLowerCase().includes(_)||E.sub_items&&E.sub_items.some(w=>w.toLowerCase().includes(_))||E.edition&&E.edition.toLowerCase().includes(_))}return j},[y,b,h]),k=f.useMemo(()=>{if(!I)return null;const j=[],_=new Map;for(const w of v){if(!w.volumes||w.volumes.length===0)continue;const R=w.volumes[0];_.has(R)||_.set(R,[]),_.get(R).push(w)}const E=[..._.keys()].sort((w,R)=>w-R);for(const w of E)j.push({volume:w,books:_.get(w)});return j},[v,I]);return u?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:a.catalog.loading})}):g?e.jsx("div",{className:i,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):y?e.jsxs("div",{className:i,style:l,children:[e.jsx(Uo,{data:y}),C&&e.jsx(No,{sections:y.sections,activeSection:b,onSelect:m}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:a.search.searchBookName,value:h,onChange:j=>S(j.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," ",a.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[k?k.map((j,_)=>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:Pe(a.catalog.volume,{n:j.volume})}),j.books.map((E,w)=>e.jsx(St,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${j.volume}-${w}`))]},`${j.volume}-${_}`)):v.map((j,_)=>e.jsx(St,{book:j,onNavigate:r,renderLink:s,showVolumes:!0},_)),v.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:a.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,Ko=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,a]=f.useState(!1),[c,x]=f.useState(null),u=f.useRef(null),p=f.useRef(null),g=f.useRef(null),d=f.useCallback(()=>{const h=p.current,S=g.current;if(!h||!S)return;const y=h.getBoundingClientRect(),C=S.getBoundingClientRect(),I=window.innerHeight,v=document.documentElement.clientWidth;let k=o;o==="top"&&y.top-C.height-Fe<8&&(k="bottom"),o==="bottom"&&y.bottom+C.height+Fe>I-8&&(k="top");const j=k==="top"?y.top-C.height-Fe:y.bottom+Fe;let _=y.left+y.width/2-C.width/2;_=Math.max(8,Math.min(_,v-C.width-8)),x({left:_,top:j,placement:k})},[o]),b=f.useCallback(()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>a(!0),r)},[r]),m=f.useCallback(()=>{u.current&&clearTimeout(u.current),a(!1),x(null)},[]);return f.useEffect(()=>{if(!l)return;const h=requestAnimationFrame(d);return()=>cancelAnimationFrame(h)},[l,d]),f.useEffect(()=>()=>{u.current&&clearTimeout(u.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:p,onMouseEnter:b,onMouseLeave:m,onFocus:b,onBlur:m,style:{display:"inline-block",...i},children:n}),l&&On.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(c==null?void 0:c.left)??-9999,top:(c==null?void 0:c.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:c?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-te,width:0,height:0,...c.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,...c.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)]})},kt={A:"fine",B:"rough",C:"rough",D:"ocr"};function Jo(t){return typeof t!="string"?null:t in Qt?t:t in kt?kt[t]:null}const qo={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function X(t){return typeof t!="string"?"":qo[t]??t}const Xo=["〇","一","二","三","四","五","六","七","八","九"],wt=["","十","百","千"],Zo=["","萬","億"];function un(t){if(t===0)return"〇";if(t<0)return`負${un(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Qo(s,r>0)+Zo[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Qo(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 l=o[i],a=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&a===1&&i===0&&!n?s+=wt[a]:s+=Xo[l]+wt[a]}return s.replace(/〇$/,"")}let Be=null,Me=null;const Ue=new Set;function er(){return Be?Promise.resolve():Me||(Me=import("opencc-js/t2cn").then(t=>{Be=t.Converter({from:"tw",to:"cn"}),Ue.forEach(n=>n())}).catch(()=>{Be=t=>t,Ue.forEach(t=>t())}),Me)}function fe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(Be)return;const n=()=>t(o=>o+1);return Ue.add(n),er(),()=>{Ue.delete(n)}},[]),Be??(n=>n)}function Se(t,n){return n(t).toLowerCase()}const st="#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 l=0,a=0;for(;l<t.length;){const c=s.indexOf(r,l);if(c===-1){i.push(t.slice(l));break}c>l&&i.push(t.slice(l,c)),i.push(e.jsx("mark",{style:{background:st,padding:0,color:"inherit"},children:t.slice(c,c+r.length)},a++)),l=c+r.length}return e.jsx(e.Fragment,{children:i})}function lt(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(l=>typeof l=="string"&&Se(l,r).includes(s))}function tr(t,n,o){return n?Se(t,o).includes(Se(n,o)):!0}const at={类:"#8e6f3e",书:"#c0392b",序:"#1a5276",结语:"#7d6608"},nr={考证:"#5d6d7e"};function or(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 fn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",a=typeof s=="number"&&s>0,c=or(t),x=!!(r!=null&&r.vol_label)&&!c.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)":a?`${st}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:[c,x&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),a&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function gn(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>gn(r,n)))}function hn(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+hn(i),0))||0;return n+o}function rr(t,n){const o=[],r=l=>{var a;o.push(...l.files),(a=l.children)==null||a.forEach(r)};if(r(t),o.length===0)return;const s=o.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let i=0;for(const l of s)typeof l=="number"&&(i+=l);return i}function bn({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=gn(t,n||""),a=rr(t,i),c=typeof a=="number"&&a>0,x=a===0,[u,p]=f.useState(l||c),g=hn(t),d=!!((b=t.children)!=null&&b.length);if(f.useEffect(()=>{l&&p(!0)},[l]),f.useEffect(()=>{c&&p(!0)},[c]),t.files.length===1&&!d){const m=t.files[0],h=n===m,S=i[m],y=S===0,C=S==="loading",I=typeof S=="number"&&S>0;return e.jsxs("button",{onClick:()=>{y||o(m)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:h?"1px solid var(--bim-primary, #8e6f3e)":y?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:h?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":I?`${st}40`:"transparent",color:h?"var(--bim-primary, #8e6f3e)":y?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:y?"not-allowed":"pointer",fontSize:"12px",fontWeight:h?600:400,lineHeight:1.4,opacity:y?.5:1},children:[t.label,I&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"#b78900"},children:S}),C&&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:()=>p(!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:l?"var(--bim-primary, #8e6f3e)":x?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:x?.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,")"]}),c&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"#b78900"},children:["匹配 ",a]}),a==="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(m=>e.jsx(fn,{file:m,isActive:n===m,onSelect:o,meta:s==null?void 0:s[m],matchState:i[m]},m))}),d&&t.children.map((m,h)=>e.jsx(bn,{group:m,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},h))]})]})}function ir({files:t,groups:n,activeFile:o,onSelect:r,juanMeta:s,matchStates:i}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((a,c)=>e.jsx(bn,{group:a,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},c))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(a=>e.jsx(fn,{file:a,isActive:o===a,onSelect:r,meta:s==null?void 0:s[a],matchState:i[a]},a))})}function sr({type:t}){const n=at[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 lr({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=D(),s=ae(),i=fe(),l=m=>{if(!m)return"";const h=r(m);return o?ke(h,o,i):h},[a,c]=f.useState(!1),x=!!t.summary,u=!!t.comment,p=!!t.additional_comment,g=!!(t.content&&t.content.length>60),d=x||u||p||g;f.useEffect(()=>{o&&c(!0)},[o]);const b=!a&&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:()=>d&&c(!a),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:d?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:a?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[un(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!a&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"#e74c3c"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),a&&d&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!x&&!u&&!p&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function ar({section:t,highlightQuery:n=""}){const{convert:o}=D(),r=fe(),s=c=>{if(!c)return"";const x=o(c);return n?ke(x,n,r):x},[i,l]=f.useState(!1),a=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>a&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:a?"pointer":"default",userSelect:"none"},children:[e.jsx(sr,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),a&&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&&a&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid ${at[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 cr({section:t,highlightQuery:n=""}){const{convert:o}=D(),r=fe();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
+
`)),i=n?ke(s,n,r):s,l=at[t.type]||"#717171",a=X(t.type)==="序"||X(t.type)==="结语";return e.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${l}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:l,marginRight:"8px",padding:"1px 5px",border:`1px solid ${l}40`,borderRadius:"2px",background:`${l}08`,verticalAlign:"middle"},children:t.type}),i]})}function dr(t,n,o){const[r,s]=f.useState({});return f.useEffect(()=>{var x;if(!n||t.length===0)return;let i=!1;const l=t.filter(u=>{var p;return!((p=o==null?void 0:o.current)!=null&&p.has(u))}),a={};for(const u of t)(x=o==null?void 0:o.current)!=null&&x.has(u)&&(a[u]=o.current.get(u));if(Object.keys(a).length>0&&s(a),l.length===0)return;const c=async u=>{var p;try{if(n.getEntry){const h=await n.getEntry(u);if(h)return{title:h.title,author:h.author}}const g=await n.getItem(u);if(!g)return null;const d=g.title||u,b=g.authors,m=(p=b==null?void 0:b[0])==null?void 0:p.name;return{title:d,author:m}}catch{return null}};return Promise.all(l.map(async u=>{var g;const p=await c(u);return(g=o==null?void 0:o.current)==null||g.set(u,p),[u,p]})).then(u=>{i||s(p=>{const g={...p};for(const[d,b]of u)g[d]=b;return g})}),()=>{i=!0}},[t.join(","),n]),r}function pr({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=D(),l=ae(),a=fe(),c=y=>{if(!y)return"";const C=i(y);return s?ke(C,s,a):C},[x,u]=f.useState(!1);f.useEffect(()=>{s&&u(!0)},[s]);const p=t.type,g=nr[p]||"#717171",d=!!t.content,b=t.work_ids||[],m=b.length>1,h=dr(m?b:[],o,r),S=d&&!x&&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:()=>d&&u(!x),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:d?"pointer":"default",userSelect:"none"},children:[d&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:x?"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?c(t.header_line):c(t.title)}),!x&&S&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:c(S)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:l(b[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),m&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.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:p})]})]}),m&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(y=>{const C=h[y],I=C?`${i(C.title)}${C.author?`(${i(C.author)})`:""}`:y.slice(0,8)+"…";return e.jsxs("a",{href:l(y),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(y))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",I]},y)})}),x&&d&&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:c(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:c(t.comment)})]})]})}function xr({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=D(),l=fe(),a=n.trim(),c=f.useMemo(()=>a?t.sections.filter(p=>lt(p,a,!0,l)):t.sections,[t.sections,a,l]),x=t.sections.filter(p=>X(p.type)==="考证").length,u=c.filter(p=>X(p.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:a?`${u} / ${x} 條`:`${x} 條`})]}),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:c.map((p,g)=>e.jsx(pr,{section:p,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:a},g))}),c.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function ur({text:t,highlightQuery:n=""}){const{convert:o}=D(),r=fe(),s=l=>{const a=o(l);return n?ke(a,n,r):a},i=t.split(`
|
|
3
|
+
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((l,a)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},a);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},a);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},a);if(!l.trim())return a>0&&!i[a-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},a);const c=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:c.map((x,u)=>x.startsWith("**")&&x.endsWith("**")?e.jsx("strong",{children:s(x.slice(2,-2))},u):e.jsx(f.Fragment,{children:s(x)},u))},a)})})}function fr({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=D(),s=ae(),i=fe(),l=x=>{if(!x)return"";const u=r(x);return o?ke(u,o,i):u},a=[];let c=null;for(const x of t)X(x.type)==="类"?(c&&a.push(c),c={category:x.title,categoryContent:x.content||void 0,items:[]}):X(x.type)==="书"?(c||(c={category:"",items:[]}),c.items.push(x)):(X(x.type)==="序"||X(x.type)==="结语")&&(c||(c={category:"",items:[]}),c.items.push(x),X(x.type)==="结语"&&(a.push(c),c=null));return c&&a.push(c),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:a.map((x,u)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[x.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(x.category),x.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(x.categoryContent)})]}),x.items.map((p,g)=>X(p.type)==="序"||X(p.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(p.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&p.work_id?e.jsx("a",{href:s(p.work_id),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),d.stopPropagation(),n(p.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(p.title),children:e.jsx("strong",{children:l(p.title)})}):e.jsx("strong",{children:l(p.title)}),p.content&&l(p.content)]},g))]},u))})}function gr({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=D(),i=fe(),[l,a]=f.useState("catalog"),c=o.trim(),x=f.useMemo(()=>c?t.sections.filter(d=>lt(d,c,!1,i)):t.sections,[t.sections,c,i]),u=t.sections.filter(d=>X(d.type)==="书").length,p=t.sections.filter(d=>X(d.type)==="诗").length,g=c?x.filter(d=>X(d.type)==="书"||X(d.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(d=>e.jsx("button",{onClick:()=>a(d),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:d==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===d?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===d?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:d==="catalog"?"目錄":"原文"},d))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${p>0?`${p} 首`:`${u} 部書`}`:p>0?`${p} 首`:`${u} 部书`})]}),l==="raw"&&(n?e.jsx(ur,{text:n,highlightQuery:c}):e.jsx(fr,{sections:t.sections,onNavigate:r,highlightQuery:c})),l==="catalog"&&x.map((d,b)=>X(d.type)==="书"||X(d.type)==="诗"?e.jsx(lr,{section:d,onNavigate:r,highlightQuery:c},b):X(d.type)==="类"?e.jsx(ar,{section:d,highlightQuery:c},b):e.jsx(cr,{section:d,highlightQuery:c},b)),l==="catalog"&&x.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function mn(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 Ct(t){const n=mn(t);return n.length>0?n[0]:null}function hr(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:a,isKaozhen:c}=t,x=fe(),u=f.useRef(new Map),[p,g]=f.useState({});f.useEffect(()=>{s&&i&&u.current.set(s,{juan:i,rawText:l})},[s,i,l]),f.useEffect(()=>{u.current.clear(),g({})},[n]);const d=f.useCallback((b,m)=>{let h=0;if(b.juan)for(const S of b.juan.sections)lt(S,m,c,x)&&h++;return h===0&&b.rawText&&tr(b.rawText,m,x)&&(h=1),h},[c,x]);return f.useEffect(()=>{const b=a.trim();if(!b){g({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let m=!1;const h={},S=[];for(const k of r){const j=u.current.get(k);j?h[k]=d(j,b):(h[k]="loading",S.push(k))}g(h);const y=8;let C=0;const I=async()=>{var k;for(;C<S.length;){if(m)return;const j=C++,_=S[j];try{const[E,w]=await Promise.all([o.getCollatedJuan(n,_),((k=o.getCollatedJuanText)==null?void 0:k.call(o,n,_))??Promise.resolve(null)]),R={juan:E,rawText:w};if(u.current.set(_,R),m)return;g(A=>({...A,[_]:d(R,b)}))}catch{if(m)return;g(E=>({...E,[_]:0}))}}},v=Array.from({length:Math.min(y,S.length)},()=>I());return Promise.all(v),()=>{m=!0}},[a,n,o,r.join(","),d,x]),{matchStates:p}}const yn=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:l,style:a})=>{const[c,x]=f.useState(null),[u,p]=f.useState(!1),[g,d]=f.useState(null),[b,m]=f.useState(null),[h,S]=f.useState(null),[y,C]=f.useState(!1),[I,v]=f.useState(null),[k,j]=f.useState(""),_=f.useRef(new Map),E=s??b,w=f.useCallback(L=>{m(L),i==null||i(L)},[i]),R=t||c;f.useEffect(()=>{t&&(p(!1),d(null))},[t]),f.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let L=!1;return p(!0),d(null),o.getCollatedEditionIndex(n).then(z=>{if(!L)if(!z)d("未找到整理本数据");else{x(z);const V=Ct(z);!s&&V&&w(V)}}).catch(z=>{L||d(z instanceof Error?z.message:"加载失败")}).finally(()=>{L||p(!1)}),()=>{L=!0}},[t,n,o,s,w]),f.useEffect(()=>{const L=t||c;if(L&&!E){const z=Ct(L);z&&w(z)}},[t,c,E,w]);const A=n||(R==null?void 0:R.work_id),F=f.useCallback(async L=>{var z;if(!(!A||!(o!=null&&o.getCollatedJuan))){C(!0),S(null),v(null);try{const[V,B]=await Promise.all([o.getCollatedJuan(A,L),((z=o.getCollatedJuanText)==null?void 0:z.call(o,A,L))??Promise.resolve(null)]);S(V),v(B)}catch{S(null),v(null)}finally{C(!1)}}},[A,o]);f.useEffect(()=>{E&&F(E)},[E,F]);const H=L=>{w(L)};if(u)return e.jsx("div",{className:l,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:l,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!R)return null;const W=R.type==="kaozhen",O=mn(R);return e.jsx(br,{className:l,style:a,index:R,allFiles:O,isKaozhen:W,effectiveWorkId:A,transport:o,activeFile:E,handleSelectFile:H,juanData:h,juanRawText:I,juanLoading:y,searchQuery:k,setSearchQuery:j,onNavigate:r,workLabelCacheRef:_})},br=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:l,activeFile:a,handleSelectFile:c,juanData:x,juanRawText:u,juanLoading:p,searchQuery:g,setSearchQuery:d,onNavigate:b,workLabelCacheRef:m})=>{const{matchStates:h}=hr({workId:i,transport:l,files:r,activeFile:a,activeJuan:x,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:S=>d(S.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 S=Jo(o.text_quality.grade);return S?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Ko,{content:Yn[S],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Gn[S],cursor:"help"},children:Qt[S]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(ir,{files:r,groups:o.juan_groups,activeFile:a,onSelect:c,juanMeta:o.juan_metadata,matchStates:h}),p?e.jsx(ye,{}):x?s?e.jsx(xr,{juan:x,searchQuery:g,onNavigate:b,transport:l,workLabelCache:m}):e.jsx(gr,{juan:x,rawText:u,searchQuery:g,onNavigate:b}):a?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((S,y)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[y+1,". "]}),S.url?e.jsx("a",{href:S.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:S.title}):e.jsx("span",{children:S.title}),S.author&&e.jsxs("span",{children:[",",S.author]}),S.note&&e.jsxs("span",{children:["。",S.note]})]},y))]})]})},mr={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},yr={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function vr(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 vn=({items:t,loading:n})=>{const o=ae();return n?e.jsx(ye,{}):t.length===0?e.jsx("div",{style:jr,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=mr[r.type],i=yr[r.status];return e.jsxs("div",{style:Sr,children:[e.jsxs("div",{style:kr,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{..._t,background:s.color},children:s.label}),e.jsx("span",{style:{..._t,background:i.color},children:i.label})]}),e.jsx("span",{style:wr,children:vr(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Cr,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:zt,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:zt,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:_r,children:r.content}),r.reply&&e.jsxs("div",{style:zr,children:[e.jsx("div",{style:Ir,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},jr={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Sr={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},kr={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},_t={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},wr={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Cr={fontSize:"12px",marginBottom:"6px"},zt={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},_r={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},zr={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Ir={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},nt=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const l=P(),[a,c]=f.useState(null),[x,u]=f.useState([]),[p,g]=f.useState("recommend"),[d,b]=f.useState([]),[m,h]=f.useState(!1),S=r??p,y=W=>{g(W),s==null||s(W)},[C,I]=f.useState(!0),[v,k]=f.useState(null),[j,_]=f.useState(null),[E,w]=f.useState(null);f.useEffect(()=>{let W=!1;if(t.getCounts)return t.getCounts().then(O=>{W||c({works:O.works,books:O.books,collections:O.collections})}).catch(()=>{}),()=>{W=!0}},[t]),f.useEffect(()=>{let W=!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(z=>z.items.map(V=>({...V,group:z.name})))}catch{}return[]})().then(async L=>{if(W)return;const z=L.filter(B=>B.id);if(z.length===0){I(!1);return}const V=await Promise.all(z.map(async B=>{if(B.type)return{id:B.id,title:B.title,type:B.type,author:B.author,dynasty:B.dynasty,role:B.role,edition:B.edition,has_text:B.has_text,has_image:B.has_image,has_collated:B.has_collated,subtype:B.subtype,primary_name:B.primary_name,group:B.group,fallbackDescription:B.description};try{let U=null;if(t.getEntry)U=await t.getEntry(B.id);else{const Y=await t.getItem(B.id);Y&&(U={id:B.id,title:Y.title||B.id,type:Y.type||"work"})}if(U)return{...U,group:B.group,fallbackDescription:B.description}}catch{}return{id:B.id,title:B.title,type:N.extractType(B.id),group:B.group,fallbackDescription:B.description}}));W||(u(V.filter(B=>B!==null)),I(!1))}),()=>{W=!0}},[t,o]);const R=f.useRef(!1),A=f.useRef(!1),F=f.useRef(!1);f.useEffect(()=>{if(S!=="catalog"||R.current)return;const W=t.getCatalogProgress??t.getResourceProgress;if(!W)return;R.current=!0;let O=!1;return W.call(t).then(L=>{O||k(L)}).catch(()=>{R.current=!1}),()=>{O=!0}},[t,S]),f.useEffect(()=>{if(S!=="collection"||A.current||!t.getCollectionProgress)return;A.current=!0;let W=!1;return t.getCollectionProgress().then(O=>{W||_(O)}).catch(()=>{A.current=!1}),()=>{W=!0}},[t,S]),f.useEffect(()=>{if(S!=="site"||F.current||!t.getSiteProgress)return;F.current=!0;let W=!1;return t.getSiteProgress().then(O=>{W||w(O)}).catch(()=>{F.current=!1}),()=>{W=!0}},[t,S]),f.useEffect(()=>{if(!i||S!=="feedback")return;let W=!1;return h(!0),fetch(i).then(O=>O.json()).then(O=>{!W&&O.success&&b(O.items||[])}).catch(()=>{}).finally(()=>{W||h(!1)}),()=>{W=!0}},[i,S]);const H=W=>{switch(W){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:l.home.recommendTab,active:S==="recommend",onClick:()=>y("recommend")}),e.jsx(Te,{label:l.home.catalogTab,active:S==="catalog",onClick:()=>y("catalog")}),e.jsx(Te,{label:l.home.collectionTab,active:S==="collection",onClick:()=>y("collection")}),e.jsx(Te,{label:l.home.siteTab,active:S==="site",onClick:()=>y("site")}),i&&e.jsx(Te,{label:l.home.feedbackTab,active:S==="feedback",onClick:()=>y("feedback")})]}),S==="recommend"&&e.jsx(Tr,{recommended:x,loading:C,onNavigate:n,getIcon:H,t:l}),S==="catalog"&&e.jsx(It,{progress:v,t:l,onNavigate:n}),S==="collection"&&e.jsx(It,{progress:j,t:l,onNavigate:n}),S==="site"&&e.jsx(Er,{progress:E,t:l,totalWorks:(a==null?void 0:a.works)??0}),S==="feedback"&&i&&e.jsx(vn,{items:d,loading:m})]})})},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}),Tr=({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 l=new Map;for(const a of t){const c=a.group||s.home.recommendedBrowse;l.has(c)||l.set(c,[]),l.get(c).push(a)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([a,c])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:a}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:c.map(x=>{const u=x.dynasty||x.author?`${x.dynasty?`〔${x.dynasty}〕`:""}${x.author||""}`:x.fallbackDescription;return e.jsxs("a",{href:i(x.id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),o==null||o(x.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(x.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[x.title,x.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:x.edition})]}),u&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u})]})]},x.id)})})]},a))})},It=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((a,c)=>a.priority-c.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"#f59e0b",done:"#10b981",todo:"#9ca3af"};return e.jsx("div",{children:s.map(a=>{const c=r.filter(x=>x.status===a);return c.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[a]}}),i[a]," (",c.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:c.map(x=>e.jsx(Rr,{item:x,t:n,statusColor:l[a],onNavigate:o},x.id))})]},a)})})},Rr=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=ae(),i=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const a=t.edition?`${t.name}·${t.edition}`:t.name,c=t.collection_id||t.work_id;return c&&r?e.jsx("a",{href:s(c),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),r(c))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:x=>x.currentTarget.style.borderBottomStyle="solid",onMouseLeave:x=>x.currentTarget.style.borderBottomStyle="dashed",children:a}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:a}):a})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Pe(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})]})},Er=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(ye,{});const r=[...t.resources].sort((c,x)=>c.priority-x.priority),s=r.filter(c=>c.imported>0),i=r.filter(c=>c.imported===0),l=s.reduce((c,x)=>Math.max(c,x.imported),0),a=o>0?Math.round(l/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:l.toLocaleString()})," / ",o.toLocaleString()," ",n.indexType.work," (",a,"%)"]}),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(c=>e.jsx(Tt,{item:c,t:n,totalWorks:o},c.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(c=>e.jsx(Tt,{item:c,t:n,totalWorks:o},c.id))})]})]})},Tt=({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})]})},Rt="(max-width: 768px)";function Lr(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(Rt).matches);return f.useEffect(()=>{const o=window.matchMedia(Rt),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Br=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var O;const i=P(),{convert:l}=D(),a=Lr(),[c,x]=f.useState(null),[u,p]=f.useState(null),[g,d]=f.useState(!1),[b,m]=f.useState("detail"),[h,S]=f.useState([]),[y,C]=f.useState(!1),[I,v]=f.useState(null),[k,j]=f.useState(!1),_=f.useCallback(async L=>{if(!t.getCollatedEditionIndex){v(null);return}j(!0);try{const z=await t.getCollatedEditionIndex(L);v(z)}catch{v(null)}finally{j(!1)}},[t]),E=f.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){S([]);return}C(!0);try{if(t.getCollectionCatalogs){const z=await t.getCollectionCatalogs(L);S(z||[])}else if(t.getCollectionCatalog){const z=await t.getCollectionCatalog(L);S(z?[{resource_id:"",data:z}]:[])}}catch{S([])}finally{C(!1)}},[t]),w=f.useCallback(async L=>{if(o){o(L);return}x(L),p(null),S([]),v(null),m("detail"),d(!0);try{const z=await t.getItem(L.id);z&&(p(z),z.type==="collection"?E(L.id):z.type==="work"&&z.has_collated&&_(L.id))}catch(z){console.error("加载详情失败:",z)}finally{d(!1)}},[t,o,E,_]),R=f.useCallback(async L=>{p(null),S([]),v(null),m("detail"),d(!0);try{const z=await t.getItem(L);z&&(p(z),x({id:L,title:z.title||L,type:z.type||"book"}),z.type==="collection"?E(L):z.type==="work"&&z.has_collated&&_(L))}catch(z){console.error("导航失败:",z)}finally{d(!1)}},[t,E,_]),A=(u==null?void 0:u.type)==="collection"&&(h.length>0||y)||(u==null?void 0:u.type)==="work"&&(I||k),F=a&&(g||u),H=f.useCallback(()=>{x(null),p(null),S([]),v(null),m("detail")},[]),W=e.jsx(e.Fragment,{children:g?e.jsx(ye,{}):u?e.jsxs(e.Fragment,{children:[(A||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:a?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:a?"auto":void 0},children:[A&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>m("detail"),style:He(b==="detail"),children:i.detailTab.basicInfo}),u.type==="collection"&&y&&h.length===0&&e.jsxs("button",{onClick:()=>{},style:He(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),u.type==="collection"&&h.map(L=>e.jsx("button",{onClick:()=>m(`catalog:${L.resource_id}`),style:He(b===`catalog:${L.resource_id}`),children:L.short_name?`${l(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),u.type==="work"&&(I||k)&&e.jsxs("button",{onClick:()=>m("collated"),style:He(b==="collated"),children:[i.detailTab.collatedEdition,k&&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:a?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(it,{data:u,transport:t,onNavigate:R}):b.startsWith("catalog:")?e.jsx(xn,{data:(O=h.find(L=>`catalog:${L.resource_id}`===b))==null?void 0:O.data,onNavigate:R}):b==="collated"?e.jsx(yn,{index:I||void 0,workId:u.id,transport:t,onNavigate:R}):null})]}):e.jsx(nt,{transport:t,onNavigate:R,recommendedIds:r})});return a?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:F?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:H,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:W})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(tt,{transport:t,onEntryClick:w,hideModeIndicator:n}),!u&&e.jsx(nt,{transport:t,onNavigate:R,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(tt,{transport:t,onEntryClick:w,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:W})]})};function He(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 Wr=({data:t,onNavigate:n,className:o,style:r})=>{var u;const s=P(),{convert:i}=D(),[l,a]=f.useState(((u=t.divisions[0])==null?void 0:u.name)??null),[c,x]=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(p=>e.jsx($r,{division:p,expanded:l===p.name,onToggle:()=>a(l===p.name?null:p.name),expandedCat:c,onCatToggle:g=>x(c===g?null:g),onNavigate:n},p.name))})]})},$r=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:l}=D(),a=t.categories.reduce((c,x)=>{const u=x.stats||{zhulu:0,cunmu:0};return c+(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:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",a," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(c=>{const x=`${t.name}/${c.name}`;return e.jsx(Pr,{category:c,expanded:r===x,onToggle:()=>s(x),onNavigate:i},c.name)})})]})},Pr=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var c,x,u,p;const{convert:s}=D(),i=((c=t.books)==null?void 0:c.zhulu)||[],l=((x=t.books)==null?void 0:x.cunmu)||[],a=(((u=t.stats)==null?void 0:u.zhulu)||i.length)+(((p=t.stats)==null?void 0:p.cunmu)||l.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:[a," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(Et,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(Et,{label:"存目",books:l,onNavigate:r})]})]})},Et=({label:t,books:n,onNavigate:o})=>{const{convert:r}=D(),s=ae(),[i,l]=f.useState(n.length<=20),a=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:a.map((c,x)=>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:c.work_id&&o?e.jsx("a",{href:s(c.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),o(c.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(c.title)}):r(c.title)}),c.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(c.volumes)}),c.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(c.author).slice(0,20)})]},x))}),!i&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},se=({title:t,onSave:n,onAskAI:o,extraButtons:r,children:s})=>{const i=P();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:Fr,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ar,children:i.action.save})]})]}),s]})},Ar={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Fr={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 Mr(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),l=Mr(t||"");return f.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Lt,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:l.name}),e.jsx(Ne,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Lt,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:a=>n(a.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"}})]})},Lt={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Hr(t){switch(t){case"url":return"#2196f3";case"bookID":return"#4caf50";default:return"var(--bim-desc-fg, #717171)"}}function Dr(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const jn=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=P(),[s,i]=f.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},a=p=>{n(t.filter((g,d)=>d!==p)),s===p&&i(null)},c=(p,g,d)=>{const b=[...t];b[p]={...b[p],[g]:d},n(b)},x=(p,g)=>{const d=[...t];d[p]={...d[p],type:g,id:"",name:""},n(d),g==="bookID"&&o&&o(b=>{const m=[...t];m[p]={...m[p],id:b.id,name:b.title,type:"bookID"},n(m)})},u=p=>{o&&o(g=>{const d=[...t];d[p]={...d[p],id:g.id,name:g.title,type:"bookID"},n(d)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,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:p.name||`${r.editor.sourcePlaceholder} ${g+1}`}),p.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Hr(p.type),color:"white",borderRadius:"3px",fontWeight:500},children:Dr(p.type)}),e.jsx("button",{onClick:d=>{d.stopPropagation(),a(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:[!p.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:()=>x(g,"bookID"),style:{...Bt,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:()=>x(g,"url"),style:{...Bt,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})]})]})]}),p.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 d=[...t];d[g]={...d[g],type:"",id:"",name:""},n(d)},style:Wt,children:r.action.changeType})]}),p.id&&p.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:p.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:p.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})]})]})}),p.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 d=[...t];d[g]={...d[g],type:"",id:"",name:""},n(d)},style:Wt,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:p.name,onChange:d=>c(g,"name",d.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:p.id,onChange:d=>c(g,"id",d.target.value),placeholder:"https://...",style:ve})]})]}),p.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:p.details,onChange:d=>c(g,"details",d.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:p.position,onChange:d=>c(g,"position",d.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:p.version,onChange:d=>c(g,"version",d.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:p.processor_version,onChange:d=>c(g,"processor_version",d.target.value),placeholder:"如: v0.1",style:ve})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},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"},Bt={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"},Wt={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Sn(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 kn(t){return!t||t.length===0?"":JSON.stringify(t)}const wn=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:l,childWorks:a,childCollections:c,containedBooks:x,siblingBooks:u,onLinkEntity:p,onUnlinkEntity:g,onViewEntity:d,onCreateAndLink:b,onSaveRelations:m})=>{const h=P();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:h.section.relations})]}),m&&e.jsx("button",{onClick:m,style:Or,children:h.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:h.relation.belongsToWork,entity:i,onView:d,onUnlink:()=>g("workId"),onLink:()=>p("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(Re,{direction:"up",title:h.relation.containedInCollection,entity:l,onView:d,onUnlink:()=>g("collectionId"),onLink:()=>p("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),i&&u&&u.length>0&&e.jsx(je,{direction:"horizontal",title:`${h.relation.siblingVersions} (${u.length})`,entities:u,onView:d,onAdd:()=>b("siblingBook","book",{workId:i.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:h.relation.parentWork,entity:r,onView:d,onUnlink:()=>g("parentWorkId"),onLink:()=>p("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),a&&a.length>0&&e.jsx(je,{direction:"down",title:`${h.relation.childWorks} (${a.length})`,entities:a,onView:d,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),c&&c.length>0&&e.jsx(je,{direction:"down",title:`${h.relation.collectionImpl} (${c.length})`,entities:c,onView:d,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(je,{direction:"down",title:`${h.relation.allVersions} (${(x==null?void 0:x.length)??0})`,entities:x||[],onView:d,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{direction:"up",title:h.relation.correspondingWork,entity:i,onView:d,onUnlink:()=>g("workId"),onLink:()=>p("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(Re,{direction:"up",title:h.relation.parentCollection,entity:s,onView:d,onUnlink:()=>g("parentCollectionId"),onLink:()=>p("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(je,{direction:"down",title:`${h.relation.childCollections} (${(c==null?void 0:c.length)??0})`,entities:c||[],onView:d,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(je,{direction:"down",title:`${h.relation.containedBooks} (${(x==null?void 0:x.length)??0})`,entities:x||[],onView:d,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},Re=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:l,linkLabel:a,createLabel:c,notLinkedLabel:x,viewLabel:u,unlinkLabel:p})=>{const g=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",d=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:d}),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:Cn(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($t,{onClick:()=>r(o),title:u,children:"👁️"}),e.jsx($t,{onClick:s,title:p,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:x}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(ot,{onClick:i,children:a}),e.jsx(ot,{onClick:l,primary:!0,children:c})]})]})},je=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:l,expandMoreLabel:a})=>{const[c,x]=f.useState(!1),u=t==="up"?"#2196f3":t==="down"?"#4caf50":"#ff9800",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=c?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:p}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(d=>e.jsxs("div",{onClick:()=>r(d),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:Cn(d.type)}),e.jsx("span",{children:d.title})]},d.id)),o.length>5&&!c&&e.jsxs("div",{onClick:()=>x(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[a," (",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:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(ot,{onClick:s,primary:!0,children:["+ ",i]})})]})},$t=({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}),ot=({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 Cn(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Or={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"},_n=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:l,onSearch:a,isLoading:c,excludeId:x})=>{const[u,p]=f.useState(""),g=x?l.filter(h=>h.id!==x):l;f.useEffect(()=>{t&&(p(""),a(""))},[t]);const d=h=>{p(h),a(h)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",m=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Vr,children:e.jsxs("div",{style:Ur,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:Nr,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:u,onChange:h=>d(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Yr})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:c?e.jsx("div",{style:Ze,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(h=>e.jsxs("div",{onClick:()=>r(h),style:Gr,children:[e.jsx("span",{style:{fontSize:"16px"},children:m}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):u?e.jsxs("div",{style:Ze,children:["未找到匹配的",b]}):e.jsxs("div",{style:Ze,children:["输入关键词搜索",b]})}),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:Kr,children:["创建新",b,"并关联"]})]})]})})},Vr={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},Ur={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)"},Nr={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Yr={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"},Gr={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ze={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Kr={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Pt={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Jr={work:"📜",book:"📖",collection:"📚",entity:"👤"},zn=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,a]=f.useState(""),c=f.useRef(null);f.useEffect(()=>{t&&(a((r==null?void 0:r.title)||""),setTimeout(()=>{var g,d;(g=c.current)==null||g.focus(),(d=c.current)==null||d.select()},100))},[t,r==null?void 0:r.title]);const x=g=>{g.key==="Enter"&&l.trim()?u():g.key==="Escape"&&i()},u=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const p=()=>{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`创建新${Pt[n]}`}};return e.jsx("div",{style:qr,onClick:g=>{g.target===g.currentTarget&&i()},children:e.jsxs("div",{style:Xr,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:Jr[n]}),e.jsx("span",{children:p()})]}),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:c,type:"text",value:l,onChange:g=>a(g.target.value),onKeyDown:x,placeholder:`请输入${Pt[n]}名称...`,style:Zr})]}),((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:Qr,children:"取消"}),e.jsx("button",{onClick:u,disabled:!l.trim(),style:{...ei,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},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",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Zr={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"},Qr={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ei={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function ti(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function In(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ni(t){switch(t){case"work":return"#4caf50";case"collection":return"#2196f3";case"book":return"#ff9800";default:return"var(--bim-desc-fg, #717171)"}}const Tn=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:l,onSelect:a,onCancel:c,onCreate:x,onSearch:u})=>{const[p,g]=f.useState(""),[d,b]=f.useState([]),[m,h]=f.useState(!1),[S,y]=f.useState("recent");f.useEffect(()=>{t&&(g(""),b([]),y(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!p.trim()){b([]);return}const _=setTimeout(async()=>{h(!0);try{b(await u(p,o))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(_)},[p,o,u]);const C=f.useCallback(_=>{g(_.target.value),_.target.value.trim()&&y("search")},[]),I=f.useCallback(_=>s?_.filter(E=>E.id!==s):_,[s]);if(!t)return null;const v=n||(o==="all"?"选择实体":`选择${In(o)}`),k=I(r),j=I(d);return e.jsx("div",{style:ri,children:e.jsxs("div",{style:ii,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:c,style:si,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:p,onChange:C,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:li}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),m&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),k.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(At,{active:S==="recent",onClick:()=>y("recent"),children:["最近使用 (",k.length,")"]}),e.jsxs(At,{active:S==="search",onClick:()=>y("search"),children:["搜索结果 ",j.length>0&&`(${j.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&k.length>0?e.jsx(Ft,{entities:k,onSelect:a}):p.trim()?m?e.jsx(Qe,{message:"搜索中..."}):j.length>0?e.jsx(Ft,{entities:j,onSelect:a}):e.jsx(Qe,{message:"未找到匹配的结果"}):e.jsx(Qe,{message:"输入关键词开始搜索"})}),i&&x&&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:x,style:ai,children:l||"创建新实体"})]})]})})},At=({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}),Ft=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(oi,{entity:o,onClick:()=>n(o)},o.id))}),oi=({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:ti(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:ni(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:In(t.type)})]})},Qe=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),ri={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},ii={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)"},si={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},li={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"},ai={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ci={work:"#4caf50",collection:"#2196f3",book:"#ff9800",entity:"#9c27b0"},di={work:"📜",collection:"📚",book:"📖",entity:"👤"},Rn=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:a,renderSectionActions:c,onDownloadResource:x,downloadStatuses:u,relations:p,onRelationsChange:g})=>{var ee;const d=P(),[b,m]=f.useState(!1),[h,S]=f.useState("work"),[y,C]=f.useState(""),[I,v]=f.useState(""),[k,j]=f.useState([]),[_,E]=f.useState(!1),[w,R]=f.useState(!1),[A,F]=f.useState("work"),[H,W]=f.useState(""),[O,L]=f.useState(),[z,V]=f.useState(!1),[B,U]=f.useState(null),[Y,Z]=f.useState([]);f.useRef(null);const ne=t.type,he=ne==="work",ge=ne==="collection",Q=ne==="book",q=f.useCallback((T,M)=>{n({...t,[T]:M})},[t,n]),Ge=f.useCallback((T,M)=>{C(T),S(M),v(d.editor.selectToLink+d.indexType[M]),j([]),m(!0)},[d]),Ke=f.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),we=f.useCallback(T=>{s==null||s(T.id,T.type)},[s]),Ce=f.useCallback((T,M,oe)=>{const ce={...oe,author:(oe==null?void 0:oe.author)||t.author,dynasty:(oe==null?void 0:oe.dynasty)||t.dynasty};F(M),W(T),L(ce),R(!0)},[t.author,t.dynasty]),Je=f.useCallback((T,M)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,H,{type:A,title:T,inheritData:M}),R(!1)},[r,t.id,H,A]),Ae=f.useCallback(T=>{if(!T.trim()){j([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(T,h).then(M=>{j(M),E(!1)}).catch(()=>{j([]),E(!1)})},[r,h]),qe=f.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,y,T.id),m(!1)},[r,t.id,y]),$=f.useCallback(()=>{o()},[o]),J=f.useCallback(T=>{U(()=>T),V(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(Z).catch(()=>{})},[r]),G=f.useCallback((T,M)=>r!=null&&r.searchEntities?r.searchEntities(T,M==="all"?void 0:M):Promise.resolve([]),[r]),K=f.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),Z(M=>[T,...M.filter(oe=>oe.id!==T.id)].slice(0,10)),B==null||B(T),V(!1),U(null)},[r,B]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:di[ne]}),e.jsx("span",{children:t.title||d.editor.untitled}),e.jsx(Ne,{children:t.id}),e.jsx(Ne,{color:ci[ne],children:d.indexType[ne]})]})}),e.jsx(se,{title:d.section.basicInfo,onSave:o,onAskAI:a?()=>a("基本信息"):void 0,extraButtons:c==null?void 0:c("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ve,{label:he?d.editor.workTitle:ge?d.editor.collectionTitle:d.editor.bookTitle,value:t.title,onChange:T=>q("title",T)}),Q&&e.jsx(Ve,{label:d.editor.belongsToWork,value:t.workName||"",onChange:T=>q("workName",T)}),e.jsx(re,{label:d.editor.authorLabel,value:t.author||"",onChange:T=>q("author",T)}),e.jsx(re,{label:d.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>q("dynasty",T)}),(Q||ge)&&e.jsx(Ve,{label:d.editor.containedIn,value:t.collection||"",onChange:T=>q("collection",T)}),(Q||ge)&&e.jsx(re,{label:d.editor.holderLabel,value:t.holder||"",onChange:T=>q("holder",T)}),(Q||ge)&&e.jsx(re,{label:Q?d.editor.pageLabel:d.editor.volumeLabel,value:t.pages||"",onChange:T=>q("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(re,{label:d.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>q("firstImage",T)})})]})}),e.jsx(se,{title:d.section.description,onSave:o,onAskAI:a?()=>a("介绍"):void 0,children:e.jsx(me,{value:t.description||"",onChange:T=>q("description",T),placeholder:d.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(se,{title:d.section.additionalWorks,onSave:o,children:e.jsx(pi,{items:t.additional_works||[],onChange:T=>q("additional_works",T)})}),e.jsx(se,{title:d.section.indexedBy,onSave:o,onAskAI:a?()=>a("收录于"):void 0,children:e.jsx(xi,{items:t.indexed_by||[],onChange:T=>q("indexed_by",T)})}),e.jsx(se,{title:d.section.emendatedBy,onSave:o,onAskAI:a?()=>a("考证"):void 0,children:e.jsx(ui,{items:t.emendated_by||[],onChange:T=>q("emendated_by",T)})}),e.jsx(se,{title:d.section.textResources,onSave:o,onAskAI:a?()=>a("资源"):void 0,children:e.jsx(et,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:x,downloadStatuses:u,filterType:"text"})}),e.jsx(se,{title:d.section.imageResources,onSave:o,children:e.jsx(et,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:x,downloadStatuses:u,filterType:"image"})}),e.jsx(se,{title:d.section.sources,onSave:o,onAskAI:a?()=>a("资料来源"):void 0,children:e.jsx(jn,{items:Sn(t.sources||""),onChange:T=>q("sources",kn(T)),onOpenEntityPicker:J})}),(Q||ge)&&e.jsx(se,{title:d.section.provenance,onSave:o,onAskAI:a?()=>a("收藏历史"):void 0,children:e.jsx(me,{value:t.provenance||"",onChange:T=>q("provenance",T),placeholder:d.editor.provenancePlaceholder})}),Q&&e.jsx(se,{title:d.section.otherEditions,onSave:o,onAskAI:a?()=>a("其他版本"):void 0,children:e.jsx(me,{value:t.otherEditions||"",onChange:T=>q("otherEditions",T),placeholder:d.editor.otherEditionsPlaceholder})}),e.jsx(wn,{entityType:ne,entityId:t.id,entityTitle:t.title,parentWork:p==null?void 0:p.parentWork,parentCollection:p==null?void 0:p.parentCollection,belongsToWork:p==null?void 0:p.belongsToWork,belongsToCollection:p==null?void 0:p.belongsToCollection,childWorks:p==null?void 0:p.childWorks,childCollections:p==null?void 0:p.childCollections,containedBooks:p==null?void 0:p.containedBooks,siblingBooks:p==null?void 0:p.siblingBooks,onLinkEntity:Ge,onUnlinkEntity:Ke,onViewEntity:we,onCreateAndLink:Ce,onSaveRelations:$}),i&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:d.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:d.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:d.editor.deleteEntity})]}),e.jsx(_n,{isOpen:b,entityType:h,title:I,onSelect:qe,onCancel:()=>m(!1),onCreate:()=>{m(!1),Ce(y,h)},searchResults:k,onSearch:Ae,isLoading:_,excludeId:t.id}),e.jsx(zn,{isOpen:w,entityType:A,relationField:H,inheritData:O,onConfirm:Je,onCancel:()=>R(!1)}),e.jsx(Tn,{isOpen:z,title:d.action.selectBookOrWork,filterType:"all",recentEntities:Y,excludeId:t.id,onSelect:K,onCancel:()=>{V(!1),U(null)},onSearch:G})]})};function pi({items:t,onChange:n}){const o=P(),r=(l,a,c)=>{const x=t.map((u,p)=>p===l?{...u,[a]:c}:u);n(x)},s=l=>n(t.filter((a,c)=>c!==l)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,a)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(re,{label:o.editor.bookNameLabel,value:l.book_title,onChange:c=>r(a,"book_title",c)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(re,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:c=>r(a,"n_juan",c&&parseInt(c,10)||void 0)})}),e.jsx("button",{onClick:()=>s(a),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid #ddd",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#999",marginTop:"18px"},children:"✕"})]},a)),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 En({items:t,onChange:n,showMeta:o,addLabel:r}){const s=P(),[i,l]=f.useState(null),a=(u,p,g)=>{const d=t.map((b,m)=>m===u?{...b,[p]:g||void 0}:b);n(d)},c=u=>{n(t.filter((p,g)=>g!==u)),i===u&&l(null)},x=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((u,p)=>{const g=i===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:p),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:d=>{d.stopPropagation(),c(p)},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:d=>a(p,"source",d)}),e.jsx(re,{label:s.label.sourceBid,value:u.source_bid||"",onChange:d=>a(p,"source_bid",d)})]}),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:d=>a(p,"title_info",d)}),e.jsx(re,{label:s.label.authorInfo,value:u.author_info||"",onChange:d=>a(p,"author_info",d)})]}),e.jsx(re,{label:s.label.edition,value:u.edition||"",onChange:d=>a(p,"edition",d)})]}),e.jsx(me,{value:u.summary||"",onChange:d=>a(p,"summary",d),placeholder:s.editor.summaryPlaceholder}),e.jsx(me,{value:u.comment||"",onChange:d=>a(p,"comment",d),placeholder:s.editor.commentPlaceholder}),e.jsx(me,{value:u.additional_comment||"",onChange:d=>a(p,"additional_comment",d),placeholder:s.editor.additionalCommentPlaceholder})]})]},p)}),e.jsx("button",{onClick:x,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed #ccc",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"#666",alignSelf:"flex-start"},children:r})]})}function xi({items:t,onChange:n}){const o=P();return e.jsx(En,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function ui({items:t,onChange:n}){const o=P();return e.jsx(En,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function Ln(t){var a,c,x,u,p,g,d;const n=((c=(a=t.authors)==null?void 0:a[0])==null?void 0:c.name)||"",o=((x=t.publication_info)==null?void 0:x.year)||"",r=((u=t.current_location)==null?void 0:u.name)||"",s=(p=t.page_count)!=null&&p.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||"",l={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 b=t;if(Array.isArray(b.related_works)){const m=b.related_works.find(h=>h.relation==="part_of");m&&(l.parentWorkId=m.id,l.parentWorkName=m.title)}}if(t.type==="book"){const b=t;l.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(l.collectionId=(d=b.contained_in[0])==null?void 0:d.id)}return l}function fi(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 gi=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:l,onSave:a,onDelete:c,onNavigate:x,renderLink:u,onAskAI:p,renderSectionActions:g,onDownloadResource:d,downloadStatuses:b,relations:m,onRelationsChange:h,headerExtra:S,className:y,style:C}=t;P();const[I,v]=f.useState(s),k=i?s:I;f.useEffect(()=>{s!==I&&v(s)},[s]);const j=f.useCallback(()=>{const H=k==="view"?"edit":"view";i?i(H):v(H)},[k,i]),[_,E]=f.useState(null);f.useEffect(()=>{o&&r&&r.getItem(o).then(H=>{H&&E(H)})},[o,r]);const w=n||_,R=f.useMemo(()=>w?Ln(w):null,[w]),A=i||!n?e.jsx("button",{onClick:j,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:k==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:k==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:k==="view"?"切换到编辑模式":"切换到查看模式",children:k==="view"?"✏️ 编辑":"👁 查看"}):null,F=e.jsxs(e.Fragment,{children:[A,S]});return!w&&!R?e.jsx(ye,{}):k==="view"?e.jsx(it,{data:w,transport:r,onNavigate:x?H=>x(H):void 0,renderLink:u,headerExtra:F,className:y,style:C}):R?e.jsxs("div",{className:y,style:C,children:[F&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:F}),e.jsx(Rn,{data:R,onChange:l||(()=>{}),onSave:a||(()=>{}),transport:r,onNavigate:x,showDelete:!!c,onDelete:c,onAskAI:p,renderSectionActions:g,onDownloadResource:d,downloadStatuses:b,relations:m,onRelationsChange:h})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"#999"},children:"无数据"})},Mt=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Bn=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=f.useState(null),[l,a]=f.useState(""),[c,x]=f.useState("idle"),[u,p]=f.useState(""),g=f.useRef(null);f.useEffect(()=>{t&&(i(null),a(""),x("idle"),p(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var h;return(h=g.current)==null?void 0:h.focus()},100)},[s]),f.useEffect(()=>{if(c==="success"){const h=setTimeout(n,2e3);return()=>clearTimeout(h)}},[c,n]),f.useEffect(()=>{if(!t)return;const h=S=>{S.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t,n]);const d=async()=>{if(!(!s||!l.trim())){x("submitting"),p("");try{await o({type:s,content:l.trim()}),x("success")}catch(h){x("error"),p(h instanceof Error?h.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=s&&l.trim()&&c!=="submitting",m=Mt.find(h=>h.value===s);return e.jsx("div",{style:hi,onClick:h=>{h.target===h.currentTarget&&n()},children:e.jsxs("div",{style:bi,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:mi,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:yi,"aria-label":"关闭",children:"✕"})]}),c==="success"?e.jsxs("div",{style:wi,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:Mt.map(h=>e.jsxs("button",{onClick:()=>i(h.value),style:{...vi,...s===h.value?ji:{}},children:[e.jsx("span",{children:h.icon})," ",h.label]},h.value))}),e.jsx("textarea",{ref:g,value:l,onChange:h=>a(h.target.value),placeholder:(m==null?void 0:m.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||c==="submitting",style:{...Si,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),c==="error"&&e.jsx("div",{style:Ci,children:u}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:d,disabled:!b,style:{...ki,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交反馈"})})]})]})})},hi={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},bi={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)"},mi={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},yi={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},vi={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"},ji={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Si={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"},ki={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},wi={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Ci={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},_i=({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:{...zi,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(Bn,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},zi={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"},Ht=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ii=({onSubmit:t})=>{const[n,o]=f.useState("bug"),[r,s]=f.useState(""),[i,l]=f.useState("idle"),[a,c]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var d;return(d=x.current)==null?void 0:d.focus()},100)},[n]);const u=async()=>{if(!(!n||!r.trim())){l("submitting"),c("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(d){l("error"),c(d instanceof Error?d.message:"提交失败,请稍后重试")}}},p=n&&r.trim()&&i!=="submitting",g=Ht.find(d=>d.value===n);return i==="success"?e.jsx("div",{style:Dt,children:e.jsxs("div",{style:Bi,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Wi,children:"继续提交"})]})}):e.jsxs("div",{style:Dt,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ht.map(d=>e.jsxs("button",{onClick:()=>o(d.value),style:{...Ti,...n===d.value?Ri:{}},children:[e.jsx("span",{children:d.icon})," ",d.label]},d.value))}),e.jsx("textarea",{ref:x,value:r,onChange:d=>s(d.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Ei}}),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:!p,style:{...Li,opacity:p?1:.6,cursor:p?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:$i,children:a})]})},Dt={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Ti={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"},Ri={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ei={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"},Li={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Bi={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Wi={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},$i={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Pi(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}}function Ai(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 Ot(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 Fi(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 Mi(t,n){const o=t.version_graph,r={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return r;const s=new Set(o.excluded_books??[]),i=o.node_groups??{},l=n.filter(d=>!s.has(d.id)).map(d=>Ai(d,i)).filter(d=>d!==null),a=(o.hypothetical_nodes??[]).map(Pi),c=[...l,...a],x=new Set(c.map(d=>d.id)),u=new Set,p=[],g=d=>{u.has(d.id)||!x.has(d.source)||!x.has(d.target)||(u.add(d.id),p.push(d))};for(const d of n)s.has(d.id)||!d.lineage||((d.lineage.derived_from??[]).forEach((b,m)=>{g(Ot(d.id,b,m))}),(d.lineage.related_to??[]).forEach((b,m)=>{g(Fi(d.id,b,m))}));for(const d of o.hypothetical_nodes??[])(d.derived_from??[]).forEach((b,m)=>{g(Ot(d.id,b,m))});return{nodes:c,edges:p,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(s)}}function Hi(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(c=>c.id)),i=new Set((r.hypothetical_nodes??[]).map(c=>c.id)),l=new Set([...s,...i]),a=(c,x)=>{l.has(x.ref)||o.push(`${c}: derived_from.ref "${x.ref}" 未在 books 或 hypothetical_nodes 中找到`),x.ref_type==="book"&&!s.has(x.ref)&&o.push(`${c}: derived_from.ref "${x.ref}" 标记为 book 但不在 books 列表中`),x.ref_type==="hypothetical"&&!i.has(x.ref)&&o.push(`${c}: derived_from.ref "${x.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const c of n){if(!c.lineage)continue;const x=`Book ${c.id} (${c.title})`;(c.lineage.derived_from??[]).forEach(u=>a(x,u)),(c.lineage.related_to??[]).forEach(u=>{s.has(u.book_id)||o.push(`${x}: related_to.book_id "${u.book_id}" 不在 books 列表中`)})}for(const c of r.hypothetical_nodes??[]){const x=`Hypothetical ${c.id} (${c.label})`;(c.derived_from??[]).forEach(u=>a(x,u))}return o}const Wn=({graph:t,renderLink:n,className:o,style:r})=>{if(!t.nodes.length)return e.jsx("div",{style:{...es,...r},className:o,children:"暂无版本图数据"});const s=new Map,i=new Map;for(const p of t.edges)if(p.kind==="derive"){const g=s.get(p.target)??[];g.push(p),s.set(p.target,g)}else for(const g of[p.source,p.target]){const d=i.get(g)??[];d.push(p),i.set(g,d)}const l=new Map(t.nodes.map(p=>[p.id,p])),a=new Map,c=[];for(const p of t.nodes)if(p.group){const g=a.get(p.group)??[];g.push(p),a.set(p.group,g)}else c.push(p);const x=(p,g)=>(p.year??9999)-(g.year??9999);a.forEach(p=>p.sort(x)),c.sort(x);const u=t.groups.filter(p=>a.has(p.id));return e.jsxs("div",{className:o,style:{...Oi,...r},children:[t.title&&e.jsx("div",{style:Vi,children:t.title}),t.description&&e.jsx("div",{style:Ui,children:t.description}),u.map(p=>e.jsx(Vt,{label:p.label,color:p.color,nodes:a.get(p.id),incomingMap:s,siblingMap:i,nodeMap:l,renderLink:n},p.id)),c.length>0&&e.jsx(Vt,{label:"其他",nodes:c,incomingMap:s,siblingMap:i,nodeMap:l,renderLink:n})]})},Vt=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:l})=>e.jsxs("div",{style:Ni,children:[e.jsx("div",{style:{...Yi,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:t}),o.map(a=>e.jsx(Di,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:i,renderLink:l},a.id))]}),Di=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical";return e.jsxs("div",{style:{...Gi,borderStyle:i?"dashed":"solid",opacity:t.status==="lost"?.7:1},children:[e.jsxs("div",{style:Ki,children:[e.jsx("span",{style:Ji,children:i||!s?t.label:s(t.id,t.label)}),t.year&&e.jsxs("span",{style:qi,children:[t.year_text??t.year,t.year_uncertain?"?":""]})]}),e.jsxs("div",{style:Xi,children:[t.category&&e.jsx(De,{children:t.category}),t.status==="lost"&&e.jsx(De,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(De,{tone:"warn",children:"残本"}),i&&e.jsx(De,{tone:"info",children:"假想祖本"})]}),t.extant_juan&&e.jsxs("div",{style:Zi,children:["现存:",t.extant_juan]}),t.note&&e.jsx("div",{style:Qi,children:t.note}),n.length>0&&e.jsxs("div",{style:Nt,children:[e.jsx("div",{style:Yt,children:"来源:"}),n.map(l=>{const a=r.get(l.source);return e.jsxs("div",{style:Gt(l.confidence),children:[e.jsx("span",{style:Kt,children:l.relation}),e.jsx("span",{children:(a==null?void 0:a.kind)==="book"&&s?s(a.id,a.label):(a==null?void 0:a.label)??l.source}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Ut,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Jt,children:["· ",l.evidence]})]},l.id)})]}),o.length>0&&e.jsxs("div",{style:Nt,children:[e.jsx("div",{style:Yt,children:"关联:"}),o.map(l=>{const a=l.source===t.id?l.target:l.source,c=r.get(a);return e.jsxs("div",{style:Gt(l.confidence),children:[e.jsx("span",{style:Kt,children:l.relation}),e.jsx("span",{children:(c==null?void 0:c.kind)==="book"&&s?s(c.id,c.label):(c==null?void 0:c.label)??a}),e.jsx(Ut,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Jt,children:["· ",l.evidence]})]},l.id)})]})]})},De=({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})},Ut=({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},Oi={fontSize:"14px",color:"var(--bim-fg, #333)"},Vi={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ui={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Ni={marginBottom:"16px"},Yi={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Gi={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Ki={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ji={fontSize:"15px",fontWeight:600},qi={fontSize:"12px",color:"var(--bim-muted, #777)"},Xi={marginBottom:"6px"},Zi={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Qi={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Nt={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Yt={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Gt=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Kt={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Jt={fontSize:"11px",color:"var(--bim-muted, #888)"},es={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},$n=({selectedNodeId:t,...n})=>{const[o,r]=f.useState("loading"),[s,i]=f.useState(null);return f.useEffect(()=>{let l=!1;return ts().then(a=>{l||(a?(i(a),r("ready")):r("missing"))}),()=>{l=!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(ns,{modules:s,selectedNodeId:t,...n})};async function ts(){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 ns=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:l})=>{const{ReactFlow:a,Background:c,Controls:x,Handle:u,Position:p,BaseEdge:g,EdgeLabelRenderer:d,getSmoothStepPath:b,dagre:m}=l,h=f.useMemo(()=>({lineage:v=>{var H,W,O;const[k,j,_]=b({sourceX:v.sourceX,sourceY:v.sourceY,sourcePosition:v.sourcePosition,targetX:v.targetX,targetY:v.targetY,targetPosition:v.targetPosition,stepPosition:.85,borderRadius:5}),E=!!((H=v.data)!=null&&H.isSibling),w=E?j:v.targetX-18,R=E?_:v.targetY-12,A=(W=v.data)==null?void 0:W.labelStyle,F=(O=v.data)==null?void 0:O.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:v.id,path:k,style:v.style,markerStart:v.markerStart,markerEnd:v.markerEnd}),v.label&&e.jsx(d,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${w}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...F,...A},children:v.label})})]})}}),[g,d,b]),S=f.useMemo(()=>({version:v=>{const k=v.data,j=k.kind==="hypothetical",_=k.status==="lost",E=k.isSelected,w=k.borderColor??"#888";return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:`2px ${j?"dashed":"solid"} ${E?"#0078d4":w}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:_?.6:1,boxShadow:E?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":j?"none":"0 1px 3px rgba(0,0,0,0.1)"},children:[e.jsx(u,{type:"target",position:p.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:j||!k.renderLink?k.label:k.renderLink(k.bookId,k.label)}),k.yearText&&e.jsxs("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:[k.yearText,k.uncertain?"?":"",k.category?` · ${k.category}`:""]}),_&&e.jsx("div",{style:{fontSize:9,color:"#c62828",marginTop:1},children:"已佚"}),e.jsx(u,{type:"source",position:p.Right,style:{visibility:"hidden"}})]})}}),[u,p]),{rfNodes:y,rfEdges:C}=f.useMemo(()=>os(t,m,n,i),[t,m,n,i]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(a,{nodes:y,edges:C,nodeTypes:S,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(c,{gap:16}),e.jsx(x,{showInteractive:!1})]})})};function os(t,n,o,r){const l=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:l?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const c=new Map(t.groups.map(g=>[g.id,g.color??"#888"]));for(const g of t.nodes)a.setNode(g.id,{width:160,height:90});const x=new Set(["配补"]);for(const g of t.edges)g.kind==="derive"&&(x.has(g.relation)||a.setEdge(g.source,g.target));if(n.layout(a),l){const g=b=>{const m=t.nodes.find(h=>h.id===b);return(m==null?void 0:m.year)??Number.POSITIVE_INFINITY},d=new Map;for(const b of t.nodes){const m=a.node(b.id);if(!m)continue;const h=Math.round(m.x);d.has(h)||d.set(h,[]),d.get(h).push(b.id)}for(const[,b]of d){if(b.length<2)continue;const m=[...b].sort((S,y)=>g(S)-g(y)),h=b.map(S=>a.node(S).y).sort((S,y)=>S-y);m.forEach((S,y)=>{a.node(S).y=h[y]})}}const u=t.nodes.map(g=>{const d=a.node(g.id),b=r&&g.id===r,m={kind:g.kind,label:g.label,bookId:g.kind==="book"?g.id:void 0,yearText:g.year_text??is(g),uncertain:g.year_uncertain,category:g.category,status:g.status,borderColor:g.group?c.get(g.group):void 0,renderLink:o,isSelected:b};return{id:g.id,type:"version",position:{x:d.x-160/2,y:d.y-90/2},data:m,draggable:!1,selected:b}}),p=t.edges.map(g=>rs(g));return{rfNodes:u,rfEdges:p}}function rs(t){const n=t.confidence==="probable"||t.confidence==="disputed",o=t.kind==="sibling",r=ss(t.confidence),s={type:"arrowclosed",color:r,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:t.relation,data:{labelStyle:{color:"#444"},isSibling:o},style:{stroke:r,strokeWidth:o?1:1.5,strokeDasharray:o?"4 3":n?"6 4":void 0,opacity:n?.75:1},animated:!1,markerEnd:s,markerStart:o?s:void 0,zIndex:1e3}}function is(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function ss(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)"},ls=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,className:l,style:a})=>{const[c,x]=f.useState(n),u=p=>{x(p),i==null||i(p)};return t.nodes.length?e.jsxs("div",{className:l,style:a,children:[e.jsxs("div",{style:as,children:[e.jsx("button",{onClick:()=>u("list"),style:Xt(c==="list"),children:"列表"}),e.jsx("button",{onClick:()=>u("graph"),style:Xt(c==="graph"),children:"关系图"})]}),c==="list"?e.jsx(Wn,{graph:t,renderLink:o}):e.jsx($n,{graph:t,renderLink:o,height:r,selectedNodeId:s})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"})},as={display:"flex",gap:4,marginBottom:12},Xt=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"}),cs=({style:t})=>{const n=f.useContext($e);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:"简"})]})};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.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.smartDecode=N.smartDecode;exports.validateResource=N.validateResource;exports.Badge=Ne;exports.BidUrlProvider=Un;exports.CollatedEdition=yn;exports.CollectionCatalog=xn;exports.CreateEntityDialog=zn;exports.EmendatedBySection=dn;exports.EntityDetail=rn;exports.EntityPickerDialog=Tn;exports.EntitySelector=_n;exports.FeedbackButton=_i;exports.FeedbackDialog=Bn;exports.FeedbackForm=Ii;exports.FeedbackList=vn;exports.FormInput=re;exports.FormTextArea=me;exports.HomePage=nt;exports.IndexApp=Br;exports.IndexBrowser=tt;exports.IndexDetail=it;exports.IndexEditor=Rn;exports.IndexView=gi;exports.LocaleContext=$e;exports.LocaleProvider=Qn;exports.LocaleToggle=cs;exports.ModeIndicator=nn;exports.RelationPanel=wn;exports.ResourceEditor=et;exports.ResourceList=rt;exports.SearchInput=on;exports.Section=se;exports.SmartBidInput=Ve;exports.SourceEditor=jn;exports.VersionLineageGraph=$n;exports.VersionLineageList=Wn;exports.VersionLineageView=ls;exports.WorkCatalog=Wr;exports.buildLineageGraph=Mi;exports.detailToEditor=Ln;exports.editorToDetail=fi;exports.formatTemplate=Pe;exports.parseSourceString=Sn;exports.stringifySources=kn;exports.useBidUrl=ae;exports.useConvert=D;exports.useT=P;exports.validateLineageGraph=Hi;
|