book-index-ui 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.js +2 -2
- package/dist/storage-entry-CnpLkUSw.cjs +2 -0
- package/dist/{storage-entry-BrRCOVK7.js → storage-entry-Dtv8LsVl.js} +265 -223
- package/dist/storage.cjs +1 -1
- package/dist/storage.d.ts +34 -0
- package/dist/storage.js +1 -1
- package/package.json +1 -1
- package/dist/storage-entry-DpzAR0M4.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Io=Object.create;var Xt=Object.defineProperty;var zo=Object.getOwnPropertyDescriptor;var To=Object.getOwnPropertyNames;var Ro=Object.getPrototypeOf,Eo=Object.prototype.hasOwnProperty;var Lo=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of To(n))!Eo.call(t,s)&&s!==o&&Xt(t,s,{get:()=>n[s],enumerable:!(r=zo(n,s))||r.enumerable});return t};var Ve=(t,n,o)=>(o=t!=null?Io(Ro(t)):{},Lo(n||!t||!t.__esModule?Xt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./storage-entry-DpzAR0M4.cjs"),e=require("react/jsx-runtime"),u=require("react"),Bo=require("react-markdown"),Wo=require("remark-gfm"),$o=require("react-dom"),Ao=t=>`/book-index?id=${t}`,Mn=u.createContext(Ao);function Fo({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(Mn.Provider,{value:o,children:n})}function ke(){return u.useContext(Mn)}function Ee(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Po(t,n){return Ee(t).includes(n)}const Hn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Mo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Ho={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},tt=u.createContext(null),On={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評論"},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:"圖片資源"}},Oo={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评论"},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:"图片资源"}},Do={"zh-Hant":On,"zh-Hans":Oo},Dn="bim-locale";function No(){try{const t=localStorage.getItem(Dn);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Vo(t){try{localStorage.setItem(Dn,t)}catch{}}const Uo="zh-Hans",Go=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=u.useState(t??Uo),i=t??r;u.useEffect(()=>{if(t)return;const x=No();x&&x!==r&&s(x)},[]);const[l,c]=u.useState(null);u.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(x=>{const f=x.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>x=>x)}):c(null)},[i]);const a=u.useCallback(x=>{s(x),Vo(x),n==null||n(x)},[n]),d=u.useMemo(()=>({locale:i,setLocale:a,messages:Do[i],converter:l}),[i,a,l]);return e.jsx(tt.Provider,{value:d,children:o})};function P(){const t=u.useContext(tt);return(t==null?void 0:t.messages)??On}const Yo=2e3;function M(){const t=u.useContext(tt),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=u.useCallback(l=>{if(!l)return"";if(!o)return l;const c=r.current.get(l);if(c!==void 0)return c;const a=o(l);if(r.current.size>=Yo){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[o]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function nt(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Ko(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 Jo(){return{id:"",name:"",url:"",type:"text",details:""}}const vt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=P(),[l,c]=u.useState(null),a=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],d=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],x=m=>{if(!s)return!0;const S=Ee(m);return s==="text"?S.includes("text"):s==="image"?S.includes("image")||S.includes("physical"):s==="physical"?S.includes("physical"):S.includes(s)},f=t.map((m,S)=>({item:m,originalIndex:S})).filter(({item:m})=>x(m)),h=()=>{const m=Jo();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((S,_)=>_!==m)),c(null)},b=(m,S,_)=>{const j=[...t];if(j[m]={...j[m],[S]:_},S==="url"&&!j[m].id){const w=Ko(_);w&&(j[m].id=w)}n(j)},y=(m,S,_)=>{const w={...t[m].metadata||{}};_?w[S]=_:delete w[S],b(m,"metadata",Object.keys(w).length>0?w:void 0)},g=(m,S)=>{const _=S.trim()?S.split(/[,,、]/).map(j=>j.trim()).filter(Boolean):void 0;b(m,"structure",_)},v=(m,S,_)=>{const w=t[m].coverage||{level:1,ranges:""};S==="level"?w.level=parseInt(_)||1:w.ranges=_,b(m,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:m,originalIndex:S})=>{var _,j,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===S?null:S),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===S?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:qo(m.type??"text"),color:"#fff"},children:(()=>{var I,E;const k=Ee(m);return k.length===0?m.type??"text":k.length===1?((I=a.find(z=>z.value===k[0]))==null?void 0:I.label)??k[0]:k.includes("text")&&k.includes("image")?((E=a.find(z=>z.value==="text+image"))==null?void 0:E.label)??"text+image":k.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${S+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:k=>k.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&Xo(S,r==null?void 0:r[S],o,i),e.jsx("button",{onClick:k=>{k.stopPropagation(),p(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Po(m,"image")&&m.url&&Zo(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ue,children:[e.jsx("span",{style:Ge,children:i.label.type}),e.jsx("select",{value:m.type,onChange:k=>b(S,"type",k.target.value),style:{...we,flex:1},children:a.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]}),e.jsxs("label",{style:Ue,children:[e.jsx("span",{style:Ge,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:k=>b(S,"root_type",k.target.value),style:{...we,flex:1},children:d.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:k=>b(S,"id",k.target.value),placeholder:i.editor.idAutoExtract,style:{...we,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:k=>b(S,"name",k.target.value),placeholder:i.editor.resourceName,style:{...we,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:k=>b(S,"url",k.target.value),placeholder:i.editor.resourceUrl,style:we}),e.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:k=>g(S,k.target.value),placeholder:i.editor.structurePlaceholder,style:we}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ue,children:[e.jsx("span",{style:Ge,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((j=m.coverage)==null?void 0:j.level)??"",onChange:k=>v(S,"level",k.target.value),placeholder:"1",style:{...we,width:"60px"}})]}),e.jsxs("label",{style:{...Ue,flex:1},children:[e.jsx("span",{style:Ge,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:k=>v(S,"ranges",k.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...we,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:k=>b(S,"details",k.target.value),placeholder:i.editor.detailsPlaceholder,style:{...we,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(([k,I])=>{var E;return e.jsxs("label",{style:{...Ue,gap:"4px"},children:[e.jsx("span",{style:{...Ge,minWidth:"56px"},children:I}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[k])||"",onChange:z=>y(S,k,z.target.value),placeholder:I,style:{...we,flex:1}})]},k)})})]})]})]})]},S)}),e.jsxs("button",{onClick:h,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 qo(t){switch(t){case"text":return"var(--bim-restype-text, #2196f3)";case"image":return"var(--bim-restype-image, #ff9800)";case"text+image":return"var(--bim-restype-text-image, #9c27b0)";case"physical":return"var(--bim-restype-physical, #795548)"}}function Xo(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 Zo(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:"var(--bim-overlay-bg, #00000010)"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const we={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"},Ue={display:"flex",alignItems:"center",gap:"6px"},Ge={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Qo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function er(t){try{const n=new URL(t).hostname;return Qo[n]}catch{return}}const Zt={text:"var(--bim-restype-text, #2196f3)",image:"var(--bim-restype-image, #ff9800)","text+image":"var(--bim-restype-text-image, #9c27b0)",physical:"var(--bim-restype-physical, #795548)"};function tr(t){return t.includes("text")&&t.includes("image")?Zt["text+image"]:Zt[t[0]||"physical"]}const Qt={text:0,image:1,physical:2};function lt(t){return t.length===0?"physical":[...t].sort((n,o)=>(Qt[n]??99)-(Qt[o]??99)).join("+")}function nr(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const c=i.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const l=t[i];if(l.volumes&&l.volumes.length>0)continue;const c=n(l.name);if(!c)continue;const[a,d]=c,x=`${a}|${lt(Ee(l))}`;o.has(x)||o.set(x,{base:{...l,name:a,url:"",volumes:[]},volumes:[]}),o.get(x).volumes.push({volume:d,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((l,c)=>l.volume-c.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 c=n(t[l].name),a=c&&`${c[0]}|${lt(Ee(t[l]))}`,d=`${i.base.name}|${lt(Ee(i.base))}`;a===d&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const _t=({items:t,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const i=P(),{convert:l}=M(),c=u.useMemo(()=>nr(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=u.useMemo(()=>{const g=new Map,v=[];for(const m of c){const S=m.group;S?(g.has(S)||g.set(S,[]),g.get(S).push(m)):v.push(m)}for(const m of g.values())m.sort((S,_)=>{const j=w=>w.group_role==="origin"?0:w.group_role==="mirror"?1:2;return j(S)-j(_)});return{mirrorGroups:g,ungroupedItems:v}},[c]),x={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical},f=g=>x[g]?x[g]:g.split("+").map(v=>x[v]||v).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((g,v)=>e.jsx(ft,{item:g},g.id||v))});const h=(g,v)=>{const m=o==null?void 0:o[g],S=(m==null?void 0:m.label)||g,_=m==null?void 0:m.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(S)}),_&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(_)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((j,w)=>e.jsx(ft,{item:j,onNavigate:r,renderLink:s},j.id||w))})]},`group-${g}`)},p=new Map;for(const g of d){const v=lt(Ee(g));p.has(v)||p.set(v,[]),p.get(v).push(g)}const b=["text","image","text+image","physical"],y=[...b.filter(g=>p.has(g)),...[...p.keys()].filter(g=>!b.includes(g)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([g,v])=>h(g,v)),y.map(g=>{const v=p.get(g),m=tr(g.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:m,whiteSpace:"nowrap",flexShrink:0},children:f(g)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((S,_)=>e.jsx(ft,{item:S,onNavigate:r,renderLink:s},S.id||_))})]},g)})]})};function or(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 rr(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 ir(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 sr={bw:{label:"",bg:"var(--bim-colormode-bw-bg, #f5f5f5)",fg:"var(--bim-colormode-bw-fg, #757575)"},color:{label:"",bg:"var(--bim-colormode-color-bg, #fff8e1)",fg:"var(--bim-colormode-color-fg, #f57f17)"}},ft=({item:t})=>{const n=P(),{convert:o}=M(),[r,s]=u.useState(!1),i=u.useMemo(()=>(t.url?er(t.url):void 0)||o(t.name),[t.url,t.name,o]),l=u.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||ir(b)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(l.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,x=t.expected_volumes??(c?a+d:0),f=t.color_mode?{...sr[t.color_mode],label:n.colorMode[t.color_mode]}:null,h=t.details&&!c?o(t.details):null,p={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:p,children:[e.jsx("span",{style:{fontWeight:500},children:i}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),h&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:h}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",x,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=rr(t.metadata);return b?or(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}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(b=>{const y=b.status==="missing";return b.url&&!y?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:y?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.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 c=P(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,x=(n==null?void 0:n.repoPath)||"",f=x?x.split(/[/\\]/).pop()||x:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},p={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...h,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:f||c.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:x?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&e.jsxs("div",{style:{...h,background:"var(--bim-mode-active-bg, #2196f3)",color:"white",cursor:"default"},title:x,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},xt="bim-search-history",en=10,tn=8;function Xe(){try{const t=localStorage.getItem(xt);return t?JSON.parse(t):[]}catch{return[]}}function lr(t){try{const n=Xe().filter(o=>o!==t);n.unshift(t),n.length>en&&(n.length=en),localStorage.setItem(xt,JSON.stringify(n))}catch{}}function ar(t){try{const n=Xe().filter(o=>o!==t);localStorage.setItem(xt,JSON.stringify(n))}catch{}}function cr(){try{localStorage.removeItem(xt)}catch{}}const Vn=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=P(),c=i??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,x]=u.useState(!1),[f,h]=u.useState([]),[p,b]=u.useState(-1),[y,g]=u.useState(Xe),v=u.useRef(null),m=u.useRef(null),S=u.useRef(null),_=u.useRef(!1);u.useEffect(()=>{b(-1);const C=n.trim();if(!C){h(y.map(B=>({type:"history",text:B})));return}if(!t.searchAll){h([]);return}let W=!1;const H=setTimeout(()=>{t.searchAll(C,tn).then(B=>{if(W)return;const A=[...B.works,...B.books,...B.collections,...B.entities??[]];h(A.slice(0,tn).map(O=>({type:"entry",text:O.title||O.id,entry:O})))}).catch(()=>{W||h([])})},80);return()=>{W=!0,clearTimeout(H)}},[n,y,t]),u.useEffect(()=>{const C=W=>{S.current&&!S.current.contains(W.target)&&x(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),u.useEffect(()=>{const C=W=>{var H,B;if(W.key==="/"&&document.activeElement!==v.current){const A=(H=document.activeElement)==null?void 0:H.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return;W.preventDefault(),(B=v.current)==null||B.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const j=u.useCallback(C=>{C.trim()&&(lr(C.trim()),g(Xe())),r(C),x(!1)},[r]),w=u.useCallback(C=>{C.type==="history"?(o(C.text),j(C.text)):C.entry&&(s?(s(C.entry),x(!1)):(o(C.text),j(C.text)))},[o,j,s]),k=u.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&j(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(W=>(W+1)%f.length);break;case"ArrowUp":C.preventDefault(),b(W=>(W-1+f.length)%f.length);break;case"Enter":C.preventDefault(),p>=0&&p<f.length?w(f[p]):j(n);break;case"Escape":C.preventDefault(),x(!1);break}},[d,f,p,n,j,w]),I=u.useCallback((C,W)=>{W.stopPropagation(),ar(C),g(Xe()),h(H=>H.filter(B=>!(B.type==="history"&&B.text===C)))},[]),E=u.useCallback(C=>{C.stopPropagation(),cr(),g([]),h([])},[]);u.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const z=!n.trim()&&y.length>0;return e.jsxs("div",{ref:S,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),x(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{x(!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"}}),d&&f.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[z&&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:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),f.map((C,W)=>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:W===p?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:H=>I(C.text,H),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}-${W}`))]})]})},et="bim-recent-ids",nn="bim-recent-entries",on=50,gt=5,dr=50,pr=200;function Ze(){try{const t=localStorage.getItem(et);if(t)return JSON.parse(t);const n=localStorage.getItem(nn);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(et,JSON.stringify(o)),localStorage.removeItem(nn),o}return[]}catch{return[]}}function xr(t){try{const n=Ze().filter(o=>o!==t);n.unshift(t),n.length>on&&(n.length=on),localStorage.setItem(et,JSON.stringify(n))}catch{}}function ur(t){try{const n=Ze().filter(o=>o!==t);localStorage.setItem(et,JSON.stringify(n))}catch{}}function fr(){try{localStorage.removeItem(et)}catch{}}const gr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},jt=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:x="compact",renderEntry:f,initialQuery:h,onQueryChange:p,headerRight:b})=>{const y=P(),g=[{type:"work",icon:"✍️",name:y.indexType.work,key:"works"},{type:"book",icon:"📖",name:y.indexType.book,key:"books"},{type:"collection",icon:"📚",name:y.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:y.indexType.entity,key:"entities"}],[v,m]=u.useState(h??""),[S,_]=u.useState(null),[j,w]=u.useState(null),[k,I]=u.useState(!1),[E,z]=u.useState(null),[C,W]=u.useState(""),[H,B]=u.useState(!h),[A,O]=u.useState(Ze),[L,$]=u.useState([]),[Z,R]=u.useState(!1),[N,oe]=u.useState(!1),[K,ee]=u.useState(null),[re,le]=u.useState(null),U=u.useRef(void 0),q=u.useRef(!1),xe=u.useCallback(async(F,Q)=>{if(!F.trim()){B(!0),_(null),w(null);return}B(!1),I(!0),W("");try{if(t.searchAll){const J=await t.searchAll(F,Q??gt);_(J)}else{const J=["work","book","collection","entity"],T=await Promise.all(J.map(Y=>t.search(F,Y,{page:1,pageSize:Q??gt})));_({works:T[0].entries,books:T[1].entries,collections:T[2].entries,entities:T[3].entries,totalWorks:T[0].total,totalBooks:T[1].total,totalCollections:T[2].total,totalEntities:T[3].total})}}catch(J){W(J instanceof Error?J.message:String(J)),_(null)}finally{I(!1)}},[t]);u.useEffect(()=>{let F=!1;const Q=()=>{var te,ae;const J=["work","book","collection","entity"],T=Promise.all(J.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),Y=((te=t.getResourceCounts)==null?void 0:te.call(t).catch(()=>null))??Promise.resolve(null),ne=((ae=t.getSubtypeStats)==null?void 0:ae.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([T,Y,ne]).then(([ce,ue,Fe])=>{F||(ee({works:ce[0].total,books:ce[1].total,collections:ce[2].total,entities:ce[3].total,hasText:ue==null?void 0:ue.hasText,hasImage:ue==null?void 0:ue.hasImage}),Fe&&le(Fe))})};return t.getCounts?t.getCounts().then(J=>{var T,Y;F||(ee({works:J.works,books:J.books,collections:J.collections,entities:J.entities,hasText:(T=J.resourceCounts)==null?void 0:T.hasText,hasImage:(Y=J.resourceCounts)==null?void 0:Y.hasImage}),J.subtypeStats&&le(J.subtypeStats))}).catch(()=>{F||Q()}):Q(),()=>{F=!0}},[t]),u.useEffect(()=>{q.current||!(h!=null&&h.trim())||(q.current=!0,xe(h))},[h,xe]);const We=u.useCallback(F=>{if(m(F),!F.trim()){p==null||p(F),B(!0),_(null),w(null);return}U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{w(null),p==null||p(F),xe(F)},pr)},[xe,p]),$e=u.useCallback(F=>{U.current&&clearTimeout(U.current),p==null||p(F),xe(F)},[xe,p]),he=u.useCallback(F=>{w(F),xe(v,dr)},[v,xe]);u.useEffect(()=>{if(!A.length){$([]);return}let F=!1;return R(!0),Promise.all(A.slice(0,10).map(async Q=>{var J,T,Y;try{if(t.getEntry){const te=await t.getEntry(Q);if(te)return te}const ne=await t.getItem(Q);if(ne){const te=ne.authors;return{id:Q,title:ne.title||Q,type:ne.type||"work",author:(J=te==null?void 0:te[0])==null?void 0:J.name,dynasty:(T=te==null?void 0:te[0])==null?void 0:T.dynasty,role:(Y=te==null?void 0:te[0])==null?void 0:Y.role,edition:ne.edition||void 0}}}catch{}return{id:Q,title:Q,type:"work",notFound:!0}})).then(Q=>{F||($(Q),R(!1))}),()=>{F=!0}},[A,t]);const be=F=>{z(F.id),xr(F.id),O(Ze()),r==null||r(F)},ze=F=>{ur(F),O(Ze())},Ae=()=>{fr(),O([])},me=F=>g.find(Q=>Q.type===F),De=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:y.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&e.jsx(Nn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Vn,{transport:t,value:v,onChange:We,onSearch:$e,onEntrySelect:be}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:y.action.newEntry})]}),K&&H&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:re?e.jsxs(e.Fragment,{children:[(re.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()})," 本"]}),re.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.article.toLocaleString()})," 篇"]}):null,re.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()}),K.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.entities.toLocaleString()})]})]})}),K.hasImage!=null&&K.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:k?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.searching}):C?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:C})]}):H?e.jsx("div",{style:{flex:1},children:Z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):L.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:y.search.recentBrowse}),e.jsx("button",{onClick:Ae,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:y.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:L.slice(0,N?10:3).map(F=>F.notFound?e.jsx(br,{id:F.id,onRemove:ze,t:y},F.id):e.jsx(rn,{entry:F,selected:E===F.id,onClick:be,getConfig:me,onRemove:ze},F.id))}),!N&&L.length>3&&e.jsx("button",{onClick:()=>oe(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:y.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:y.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.searchSubtitle})]})}):De?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:g.map(({type:F,icon:Q,name:J,key:T})=>{const Y=S[T]??[],ne=gr[T],te=S[ne]??0;if(Y.length===0)return null;const ce=!(j===F)&&te>gt;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," ",J,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[te," ",y.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>he(F),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:y.action.viewAll})]}),e.jsx("div",{style:x==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Y.map(ue=>{if(f)return e.jsx(u.Fragment,{children:f(ue)},ue.id);const Fe=x==="card"?hr:rn;return e.jsx(Fe,{entry:ue,selected:E===ue.id,onClick:be,getConfig:me,query:v},ue.id)})})]},F)})}):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:nt(y.search.noResultsFor,{query:v})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},hr=({entry:t,selected:n,onClick:o,getConfig:r,query:s})=>{const i=P(),{convert:l}=M(),c=l(t.title||t.primary_name||t.id),a=t.measure_info?l(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${i.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],x=s&&d.length?d.find(h=>{const p=typeof h=="string"?h:h==null?void 0:h.book_title;return p==null?void 0:p.toLowerCase().includes(s.toLowerCase())}):void 0,f="var(--bim-cover-accent, #8e6f3e)";return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:"var(--bim-bg, #fff)",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${f} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${f} 7%, var(--bim-bg, #fff)))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${f} 45%, transparent)`}}),e.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:f},children:Array.from(c).map((h,p)=>e.jsx("span",{children:h},p))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c}),a&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(t.role)]})]}),t.edition&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l(t.edition)}),x&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[i.search.alias,":",l(typeof x=="string"?x:x.book_title||"")]}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[r(t.type).icon," ",r(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",i.misc.textResource]}),t.has_image&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["🖼️ ",i.misc.imageResource]})]})]})]})},rn=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=P(),{convert:c}=M(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(x=>{const f=typeof x=="string"?x:x==null?void 0:x.book_title;return f==null?void 0:f.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:x=>{x.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:"→"})]})},br=({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 mr(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 yr({data:t}){const{convert:n}=M(),{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 vr({alt_names:t}){const{convert:n}=M(),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 c=r.indexOf(i),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(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((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},i)})})}function jr({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 Sr({works:t,transport:n,onNavigate:o,renderLink:r}){const s=P(),{convert:i}=M(),l=ke(),[c,a]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const p=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const S=await n.getEntriesByIds(p);let _=!0;for(let j=0;j<p.length;j++){const w=S[j];w!=null&&w.title?y.set(p[j],w.title):w!=null&&w.primary_name?y.set(p[j],w.primary_name):_=!1}if(_)return y}catch{}const g=[...p],v=8,m=new Array(v).fill(0).map(async()=>{for(;g.length;){const S=g.shift();if(!S)break;if(!y.has(S))try{if(n.getEntry){const w=await n.getEntry(S);if(w!=null&&w.title){y.set(S,w.title);continue}}const _=await n.getItem(S),j=_&&(_.title||_.primary_name)||S;y.set(S,j)}catch{y.set(S,S)}}});return await Promise.all(m),y})().then(y=>{h||a(y)}),()=>{h=!0}},[t,n]);const d=new Map;for(const h of t){const p=h.role||"";d.has(p)||d.set(p,[]),d.get(p).push(h)}const x=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((h,p)=>{const b=x.indexOf(h),y=x.indexOf(p);return b===-1&&y===-1?h.localeCompare(p):b===-1?1:y===-1?-1:b-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),f.map(h=>{const p=d.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((b,y)=>{const g=i(c.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,g)},y):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),o(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},y):e.jsx("li",{children:g},y)})})]},h)})]})}const Un=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var x;const i=P(),{convert:l}=M();let c=!1;try{c=G.extractStatus(t.id)==="draft"}catch{}const a=mr(t),d=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[l(t.primary_name),e.jsx(yr,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"var(--bim-type-entity, #5b3e8e)",border:"1px solid color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 25%, transparent)",borderRadius:"2px",background:"color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 3%, transparent)"},children:i.indexType.entity}),d&&t.subtype!=="people"&&e.jsx("span",{children:d}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),a&&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(vr,{alt_names:t.alt_names}),e.jsx(jr,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:l(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Sr,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},Gn={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},kr={...Gn,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},St=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=M(),i=n?kr:Gn;return e.jsx("div",{className:r,style:o,children:e.jsx(Bo,{remarkPlugins:[Wo],components:i,children:s(t)})})},wr=["〇","一","二","三","四","五","六","七","八","九"],sn=["","十","百","千"];function Yn(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]),c=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&i===0?r+=sn[c]:r+=wr[l]+sn[c])}return r}function Kn(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const _r={book:"var(--bim-type-book, #c0392b)",work:"var(--bim-type-work, #8e6f3e)",collection:"var(--bim-type-collection, #2471a3)",entity:"var(--bim-type-entity, #5b3e8e)"};function Cr({type:t}){const n=P();return e.jsx("span",{style:Kn(_r[t]),children:n.indexType[t]})}function Ir({isDraft:t}){const n=P(),o=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Kn(o),children:t?n.status.draft:n.status.official})}function zr({id:t}){const n=P(),[o,r]=u.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-bg-subtle, #f6f6f6)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title: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 ve({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 _e({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 Jn({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=M();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const c=s(i.name),a=i.entity_id?e.jsx(Se,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(i.dynasty),"〕"]}),a,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=ke();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 Tr({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:x}){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})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Cr,{type:r}),e.jsx(Ir,{isDraft:s}),e.jsx(zr,{id:t})]}),((i==null?void 0:i.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(Jn,{authors:i,type:r,onNavigate:d,renderLink:x}),c]})]})}function qn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=P(),{convert:l}=M();if(!t.length)return null;const[c,a]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,x)=>{const f=c===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?null:x),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!f&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(Se,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),f&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(_e,{label:i.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(_e,{label:i.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(_e,{label:i.label.edition,children:l(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},x)})})]})}function Rr({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(qn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Ct({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(qn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Xn({label:t,items:n}){const{convert:o}=M();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 Er({items:t}){const n=P();return e.jsx(Xn,{label:n.section.aliases,items:t})}function Lr({items:t}){const n=P();return e.jsx(Xn,{label:n.section.attachedTexts,items:t})}function Br({items:t}){const n=P(),{convert:o}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 Wr({items:t}){const n=P(),{convert:o}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 $r({items:t}){const n=P(),{convert:o}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 ln({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=M(),[l,c]=u.useState([]);return u.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>o.getItem(d).then(x=>({id:d,title:x?x.title:void 0,edition:x?x.edition:void 0,type:x?x.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ve,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${i(a.title)||a.id}(${i(a.edition)})`:i(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(Se,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function ht({book:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=M(),[i,l]=u.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(Se,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(_t,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Ar({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const l=P(),{convert:c}=M(),[a,d]=u.useState([]);if(u.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(y=>({id:y})));return}let b=!1;return Promise.all(t.map(y=>o.getItem(y).then(g=>({id:y,title:g?g.title:void 0,edition:g?g.edition:void 0,resources:g?g.resources:void 0,resource_groups:g?g.resource_groups:void 0})).catch(()=>({id:y})))).then(y=>{b||d(y)}),()=>{b=!0}},[t,o]),!t.length)return null;const x=a.length?a:t.map(b=>({id:b})),f=new Map(x.map(b=>[b.id,b])),h=n==null?void 0:n.version_graph,p=Fr(t,h);return e.jsxs(e.Fragment,{children:[e.jsxs(ve,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i,p.useGrouping?e.jsxs(e.Fragment,{children:[p.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.coreIds.map(b=>{const y=f.get(b);return y?e.jsx(ht,{book:y,onNavigate:r,renderLink:s},b):null})}),p.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(y=>{const g=f.get(y);return g?e.jsx(ht,{book:g,onNavigate:r,renderLink:s},y):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:x.map(b=>e.jsx(ht,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Fr(t,n){var g,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(g=n.collections)==null?void 0:g[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],i=r.length>0||s.length>0,l=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=m=>{if(a.has(m))return!0;const S=n.node_groups[m];return S!=null&&c.has(S)},x=[],f=new Map,h=[];for(const m of t)if(!((v=n.excluded_books)!=null&&v.includes(m)))if(d(m))x.push(m);else{const S=n.node_groups[m];S?(f.has(S)||f.set(S,[]),f.get(S).push(m)):h.push(m)}if(h.length+[...f.values()].reduce((m,S)=>m+S.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...f.entries()].map(([m,S])=>{const _=b.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:S}});return h.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:h}),{useGrouping:!0,coreIds:x,groupedIds:y}}function Pr({workData:t,onNavigate:n,renderLink:o}){var l,c,a,d;const r=P(),{convert:s}=M(),i=!!((l=t.description)!=null&&l.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(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)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Yn(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Jn,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(St,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(_e,{label:r.label.parentWork,children:e.jsx(Se,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Mr({items:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=M();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 color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:r.indexType.collection}),e.jsx(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:nt(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const ut=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:l,className:c,style:a})=>{var W,H,B,A,O,L,$,Z;const d=P(),{convert:x}=M(),[f,h]=u.useState(null),[p,b]=u.useState(!1),[y,g]=u.useState(null),[v,m]=u.useState(null),[S,_]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!o)return;let R=!1;return b(!0),g(null),o.getItem(n).then(N=>{R||(N?h(N):g(d.misc.notFoundEntry))}).catch(N=>{R||g(N instanceof Error?N.message:d.misc.loadFailed)}).finally(()=>{R||b(!1)}),()=>{R=!0}},[t,n,o]),u.useEffect(()=>{if(!j||!o){m(null),_([]);return}let R=!1;const N=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(N?o.getItem(N).then(oe=>{!R&&oe&&oe.type==="work"&&m(oe)}).catch(()=>{}):m(null),j.type==="book"){const oe=j;oe.contained_in&&oe.contained_in.length>0?Promise.all(oe.contained_in.map(K=>{const ee=typeof K=="string"?K:K.id,re=typeof K=="string"?void 0:K.volume_index;return o.getItem(ee).then(le=>({id:ee,title:le&&le.title||ee,volume_index:re})).catch(()=>({id:ee,title:ee,volume_index:re}))})).then(K=>{R||_(K)}):_([])}else _([]);return()=>{R=!0}},[j,o]),p)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((R,N)=>e.jsx("div",{style:{height:N===1?"32px":"16px",width:`${R}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},N))})});if(y)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!j)return null;if(j.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Un,{data:j,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const w=j.type==="book"?j:null,k=j.type==="collection"?j:null,I=j.type==="work"?j:null;let E=!1;try{E=G.extractStatus(j.id)==="draft"}catch{}let z="";j.measure_info?z=x(j.measure_info):(W=j.juan_count)!=null&&W.number?z=Yn(j.juan_count.number)+d.unit.juan:(H=j.juan_count)!=null&&H.description&&(z=x(j.juan_count.description));const C=[];return(B=j.publication_info)!=null&&B.year&&C.push(e.jsx(_e,{label:d.label.year,children:j.publication_info.year},"year")),(A=j.current_location)!=null&&A.name&&C.push(e.jsx(_e,{label:d.label.currentLocation,children:x(j.current_location.name)},"loc")),(O=j.page_count)!=null&&O.description&&C.push(e.jsx(_e,{label:d.label.pageCount,children:j.page_count.description},"page")),w!=null&&w.edition&&C.push(e.jsx(_e,{label:d.label.edition,children:x(w.edition)},"ver")),I!=null&&I.parent_work&&C.push(e.jsx(_e,{label:d.label.parentWork,children:e.jsx(Se,{id:I.parent_work.id,label:x(I.parent_work.title),onNavigate:r,renderLink:s})},"pw")),I!=null&&I.parent_works&&I.parent_works.length>0&&!I.parent_work&&C.push(e.jsx(_e,{label:d.label.parentWork,children:I.parent_works.map((R,N)=>e.jsxs("span",{children:[N>0&&"、",e.jsx(Se,{id:R,onNavigate:r,renderLink:s})]},R))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(Tr,{id:j.id,title:x(j.title),edition:j.edition?x(j.edition):void 0,type:j.type,isDraft:E,authors:j.authors,volumeText:z,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=j.description)==null?void 0:L.text)&&e.jsx(St,{text:j.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),j.appendix&&j.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:j.appendix.map((R,N)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:x(R.title)}),e.jsx(St,{text:R.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},N))}),S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:d.section.containedIn}),e.jsx(Mr,{items:S,onNavigate:r,renderLink:s})]}),v&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:d.section.belongsToWork}),e.jsx(Pr,{workData:v,onNavigate:r,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(Br,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(Er,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(Lr,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(Rr,{items:j.indexed_by,onNavigate:r,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(Ct,{items:j.emendated_by,onNavigate:r,renderLink:s}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:d.section.resources}),e.jsx(_t,{items:j.resources,resourceGroups:j.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(Wr,{items:w.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx($r,{items:k.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(ln,{title:d.section.relatedVersions,ids:w.related_books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(ln,{title:d.section.containedBooks,ids:k.books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.contained_works)&&k.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ve,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",k.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:k.contained_works.map(R=>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:R.id,label:x(R.title),onNavigate:r,renderLink:s})},R.id))})]}),((($=I==null?void 0:I.books)==null?void 0:$.length)||0)+(((Z=I==null?void 0:I.collections)==null?void 0:Z.length)||0)>0&&e.jsx(Ar,{ids:[...(I==null?void 0:I.books)||[],...(I==null?void 0:I.collections)||[]],workData:I,transport:o,onNavigate:r,renderLink:s,footer:l}),(I==null?void 0:I.related_works)&&I.related_works.length>0&&(()=>{const R=[],N=I.related_works.filter(U=>U.relation==="part_of"),oe=I.related_works.filter(U=>U.relation==="has_part"),K=I.related_works.filter(U=>U.relation==="has_adaptation"),ee=I.related_works.filter(U=>U.relation==="text_carried_by"),re=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),le=I.related_works.filter(U=>!U.relation||!re.has(U.relation));return N.length>0&&R.push({label:d.section.belongsToWork,items:N}),oe.length>0&&R.push({label:d.section.containedWorks,items:oe}),K.length>0&&R.push({label:d.section.adaptations,items:K}),ee.length>0&&R.push({label:d.section.derivativeWorks,items:ee}),le.length>0&&R.push({label:d.section.relatedWorks,items:le}),R.map(U=>e.jsxs("div",{children:[e.jsxs(ve,{children:[U.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",U.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:U.items.map(q=>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:q.id,label:x(q.title),onNavigate:r,renderLink:s})},q.id))})]},U.label))})()]})};function Hr({data:t}){const n=P(),{convert:o}=M(),{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:"var(--bim-missing-fg, #e67e22)"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Or({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:an(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:an(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 an(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 Dr({id:t,label:n,onNavigate:o,renderLink:r}){const s=ke();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 Nr(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 cn({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=P(),{convert:i}=M(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?Nr(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>i(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Dr,{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 It=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const c=P(),[a,d]=u.useState(null),[x,f]=u.useState(!1),[h,p]=u.useState(null),[b,y]=u.useState(null),[g,v]=u.useState(""),m=t||a;u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let k=!1;return f(!0),p(null),o.getCollectionCatalog(n).then(I=>{k||(I?d(I):p(c.catalog.notFound))}).catch(I=>{k||p(I instanceof Error?I.message:c.catalog.loadFailed)}).finally(()=>{k||f(!1)}),()=>{k=!0}},[t,n,o,c]);const S=(m==null?void 0:m.sections)&&m.sections.length>0,_=u.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const k=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(k).size<k.length},[m]),j=u.useMemo(()=>{if(!m)return[];let k=m.books;if(b&&(k=k.filter(I=>I.section===b)),g.trim()){const I=g.trim().toLowerCase();k=k.filter(E=>E.title.toLowerCase().includes(I)||E.sub_items&&E.sub_items.some(z=>z.toLowerCase().includes(I))||E.edition&&E.edition.toLowerCase().includes(I))}return k},[m,b,g]),w=u.useMemo(()=>{if(!_)return null;const k=[],I=new Map;for(const z of j){if(!z.volumes||z.volumes.length===0)continue;const C=z.volumes[0];I.has(C)||I.set(C,[]),I.get(C).push(z)}const E=[...I.keys()].sort((z,C)=>z-C);for(const z of E)k.push({volume:z,books:I.get(z)});return k},[j,_]);return x?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):h?e.jsx("div",{className:i,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:i,style:l,children:[e.jsx(Hr,{data:m}),S&&e.jsx(Or,{sections:m.sections,activeSection:b,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:k=>v(k.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:[j.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((k,I)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:nt(c.catalog.volume,{n:k.volume})}),k.books.map((E,z)=>e.jsx(cn,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${k.volume}-${z}`))]},`${k.volume}-${I}`)):j.map((k,I)=>e.jsx(cn,{book:k,onNavigate:r,renderLink:s,showVolumes:!0},I)),j.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Be=()=>{const[t,n]=u.useState(1);return u.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)})},pe=6,rt=7,Vr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,c]=u.useState(!1),[a,d]=u.useState(null),x=u.useRef(null),f=u.useRef(null),h=u.useRef(null),p=u.useCallback(()=>{const g=f.current,v=h.current;if(!g||!v)return;const m=g.getBoundingClientRect(),S=v.getBoundingClientRect(),_=window.innerHeight,j=document.documentElement.clientWidth;let w=o;o==="top"&&m.top-S.height-rt<8&&(w="bottom"),o==="bottom"&&m.bottom+S.height+rt>_-8&&(w="top");const k=w==="top"?m.top-S.height-rt:m.bottom+rt;let I=m.left+m.width/2-S.width/2;I=Math.max(8,Math.min(I,j-S.width-8)),d({left:I,top:k,placement:w})},[o]),b=u.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>c(!0),r)},[r]),y=u.useCallback(()=>{x.current&&clearTimeout(x.current),c(!1),d(null)},[]);return u.useEffect(()=>{if(!l)return;const g=requestAnimationFrame(p);return()=>cancelAnimationFrame(g)},[l,p]),u.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:b,onMouseLeave:y,onFocus:b,onBlur:y,style:{display:"inline-block",...i},children:n}),l&&$o.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-pe,width:0,height:0,...a.placement==="top"?{bottom:-pe,borderTop:`${pe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${pe}px solid transparent`,borderRight:`${pe}px solid transparent`}:{top:-pe,borderBottom:`${pe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${pe}px solid transparent`,borderRight:`${pe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${pe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${pe-1}px solid transparent`,borderRight:`${pe-1}px solid transparent`}:{top:-5,borderBottom:`${pe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${pe-1}px solid transparent`,borderRight:`${pe-1}px solid transparent`}}})]})]}),document.body)]})},dn={A:"fine",B:"rough",C:"rough",D:"ocr"};function Ur(t){return typeof t!="string"?null:t in Hn?t:t in dn?dn[t]:null}const Gr={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function se(t){return typeof t!="string"?"":Gr[t]??t}const Yr=["〇","一","二","三","四","五","六","七","八","九"],pn=["","十","百","千"],Kr=["","萬","億"];function Zn(t){if(t===0)return"〇";if(t<0)return`負${Zn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Jr(s,r>0)+Kr[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Jr(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],c=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&i===0&&!n?s+=pn[c]:s+=Yr[l]+pn[c]}return s.replace(/〇$/,"")}let Qe=null,it=null;const dt=new Set;function qr(){return Qe?Promise.resolve():it||(it=import("opencc-js/t2cn").then(t=>{Qe=t.Converter({from:"tw",to:"cn"}),dt.forEach(n=>n())}).catch(()=>{Qe=t=>t,dt.forEach(t=>t())}),it)}function Ie(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Qe)return;const n=()=>t(o=>o+1);return dt.add(n),qr(),()=>{dt.delete(n)}},[]),Qe??(n=>n)}function He(t,n){return n(t).toLowerCase()}const zt="var(--bim-highlight-bg, #fff59d)";function Oe(t,n,o){if(!n)return t;const r=He(n,o);if(!r)return t;const s=He(t,o);if(s.length!==t.length)return t;const i=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(r,l);if(a===-1){i.push(t.slice(l));break}a>l&&i.push(t.slice(l,a)),i.push(e.jsx("mark",{style:{background:zt,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:i})}function Tt(t,n,o,r){if(!n)return!0;const s=He(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"&&He(l,r).includes(s))}function Xr(t,n,o){return n?He(t,o).includes(He(n,o)):!0}const Rt={类:"var(--bim-section-lei, #8e6f3e)",书:"var(--bim-section-shu, #c0392b)",序:"var(--bim-section-xu, #1a5276)",结语:"var(--bim-section-jieyu, #7d6608)"},Zr={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Qr(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 Qn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=Qr(t),d=!!(r!=null&&r.vol_label)&&!a.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":c?`${zt}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:[a,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function eo(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>eo(r,n)))}function to(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+to(i),0))||0;return n+o}function ei(t,n){const o=[],r=l=>{var c;o.push(...l.files),(c=l.children)==null||c.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 no({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=eo(t,n||""),c=ei(t,i),a=typeof c=="number"&&c>0,d=c===0,[x,f]=u.useState(l||a),h=to(t),p=!!((b=t.children)!=null&&b.length);if(u.useEffect(()=>{l&&f(!0)},[l]),u.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!p){const y=t.files[0],g=n===y,v=i[y],m=v===0,S=v==="loading",_=typeof v=="number"&&v>0;return e.jsxs("button",{onClick:()=>{m||o(y)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:g?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:g?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${zt}40`:"transparent",color:g?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:g?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:v}),S&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>f(!x),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",h,")"]}),a&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(y=>e.jsx(Qn,{file:y,isActive:n===y,onSelect:o,meta:s==null?void 0:s[y],matchState:i[y]},y))}),p&&t.children.map((y,g)=>e.jsx(no,{group:y,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},g))]})]})}function ti({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((c,a)=>e.jsx(no,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},a))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(c=>e.jsx(Qn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function ni({type:t}){const n=Rt[t]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function oi({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=M(),s=ke(),i=Ie(),l=y=>{if(!y)return"";const g=r(y);return o?Oe(g,o,i):g},[c,a]=u.useState(!1),d=!!t.summary,x=!!t.comment,f=!!t.additional_comment,h=!!(t.content&&t.content.length>60),p=d||x||f||h;u.useEffect(()=>{o&&a(!0)},[o]);const b=!c&&h?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>p&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:p?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",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:[Zn(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&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:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&p&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children: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)})]}),h&&!d&&!x&&!f&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function ri({section:t,highlightQuery:n=""}){const{convert:o}=M(),r=Ie(),s=a=>{if(!a)return"";const d=o(a);return n?Oe(d,n,r):d},[i,l]=u.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ni,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Rt[t.type]||"var(--bim-desc-fg, #717171)"} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}function ii({section:t,highlightQuery:n=""}){const{convert:o}=M(),r=Ie();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
1
|
+
"use strict";var Io=Object.create;var Xt=Object.defineProperty;var zo=Object.getOwnPropertyDescriptor;var To=Object.getOwnPropertyNames;var Ro=Object.getPrototypeOf,Eo=Object.prototype.hasOwnProperty;var Lo=(t,n,o,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of To(n))!Eo.call(t,s)&&s!==o&&Xt(t,s,{get:()=>n[s],enumerable:!(r=zo(n,s))||r.enumerable});return t};var Ve=(t,n,o)=>(o=t!=null?Io(Ro(t)):{},Lo(n||!t||!t.__esModule?Xt(o,"default",{value:t,enumerable:!0}):o,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("./storage-entry-CnpLkUSw.cjs"),e=require("react/jsx-runtime"),u=require("react"),Bo=require("react-markdown"),Wo=require("remark-gfm"),$o=require("react-dom"),Ao=t=>`/book-index?id=${t}`,Mn=u.createContext(Ao);function Fo({buildUrl:t,children:n}){const o=u.useMemo(()=>t,[t]);return e.jsx(Mn.Provider,{value:o,children:n})}function ke(){return u.useContext(Mn)}function Ee(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function Po(t,n){return Ee(t).includes(n)}const Hn={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Mo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Ho={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},tt=u.createContext(null),On={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評論"},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:"圖片資源"}},Oo={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评论"},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:"图片资源"}},Do={"zh-Hant":On,"zh-Hans":Oo},Dn="bim-locale";function No(){try{const t=localStorage.getItem(Dn);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Vo(t){try{localStorage.setItem(Dn,t)}catch{}}const Uo="zh-Hans",Go=({locale:t,onLocaleChange:n,children:o})=>{const[r,s]=u.useState(t??Uo),i=t??r;u.useEffect(()=>{if(t)return;const x=No();x&&x!==r&&s(x)},[]);const[l,c]=u.useState(null);u.useEffect(()=>{i==="zh-Hans"?import("opencc-js/t2cn").then(x=>{const f=x.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>x=>x)}):c(null)},[i]);const a=u.useCallback(x=>{s(x),Vo(x),n==null||n(x)},[n]),d=u.useMemo(()=>({locale:i,setLocale:a,messages:Do[i],converter:l}),[i,a,l]);return e.jsx(tt.Provider,{value:d,children:o})};function P(){const t=u.useContext(tt);return(t==null?void 0:t.messages)??On}const Yo=2e3;function M(){const t=u.useContext(tt),n=(t==null?void 0:t.locale)??"zh-Hant",o=(t==null?void 0:t.converter)??null,r=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const i=u.useCallback(l=>{if(!l)return"";if(!o)return l;const c=r.current.get(l);if(c!==void 0)return c;const a=o(l);if(r.current.size>=Yo){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(l,a),a},[o]);return u.useMemo(()=>({convert:i,locale:n,isSimplified:n==="zh-Hans"}),[i,n])}function nt(t,n){return t.replace(/\{(\w+)\}/g,(o,r)=>String(n[r]??""))}function Ko(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 Jo(){return{id:"",name:"",url:"",type:"text",details:""}}const vt=({items:t,onChange:n,onDownload:o,downloadStatuses:r,filterType:s})=>{const i=P(),[l,c]=u.useState(null),a=[{value:"text",label:i.resourceTypeShort.text},{value:"image",label:i.resourceTypeShort.image},{value:"text+image",label:i.resourceTypeShort.textImage},{value:"physical",label:i.resourceTypeShort.physical}],d=[{value:"catalog",label:i.rootType.catalog},{value:"search",label:i.rootType.search}],x=m=>{if(!s)return!0;const S=Ee(m);return s==="text"?S.includes("text"):s==="image"?S.includes("image")||S.includes("physical"):s==="physical"?S.includes("physical"):S.includes(s)},f=t.map((m,S)=>({item:m,originalIndex:S})).filter(({item:m})=>x(m)),h=()=>{const m=Jo();s&&(m.type=s),n([...t,m]),c(t.length)},p=m=>{n(t.filter((S,_)=>_!==m)),c(null)},b=(m,S,_)=>{const j=[...t];if(j[m]={...j[m],[S]:_},S==="url"&&!j[m].id){const w=Ko(_);w&&(j[m].id=w)}n(j)},y=(m,S,_)=>{const w={...t[m].metadata||{}};_?w[S]=_:delete w[S],b(m,"metadata",Object.keys(w).length>0?w:void 0)},g=(m,S)=>{const _=S.trim()?S.split(/[,,、]/).map(j=>j.trim()).filter(Boolean):void 0;b(m,"structure",_)},v=(m,S,_)=>{const w=t[m].coverage||{level:1,ranges:""};S==="level"?w.level=parseInt(_)||1:w.ranges=_,b(m,"coverage",w.ranges?w:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:m,originalIndex:S})=>{var _,j,w;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===S?null:S),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===S?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:qo(m.type??"text"),color:"#fff"},children:(()=>{var I,E;const k=Ee(m);return k.length===0?m.type??"text":k.length===1?((I=a.find(z=>z.value===k[0]))==null?void 0:I.label)??k[0]:k.includes("text")&&k.includes("image")?((E=a.find(z=>z.value==="text+image"))==null?void 0:E.label)??"text+image":k.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${i.editor.resourcePlaceholder} ${S+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:k=>k.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),o&&m.url&&Xo(S,r==null?void 0:r[S],o,i),e.jsx("button",{onClick:k=>{k.stopPropagation(),p(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:i.editor.deleteThisResource,children:"✕"})]}),l===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[Po(m,"image")&&m.url&&Zo(m,i),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ue,children:[e.jsx("span",{style:Ge,children:i.label.type}),e.jsx("select",{value:m.type,onChange:k=>b(S,"type",k.target.value),style:{...we,flex:1},children:a.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]}),e.jsxs("label",{style:Ue,children:[e.jsx("span",{style:Ge,children:i.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:k=>b(S,"root_type",k.target.value),style:{...we,flex:1},children:d.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:k=>b(S,"id",k.target.value),placeholder:i.editor.idAutoExtract,style:{...we,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:k=>b(S,"name",k.target.value),placeholder:i.editor.resourceName,style:{...we,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:k=>b(S,"url",k.target.value),placeholder:i.editor.resourceUrl,style:we}),e.jsx("input",{type:"text",value:((_=m.structure)==null?void 0:_.join("、"))||"",onChange:k=>g(S,k.target.value),placeholder:i.editor.structurePlaceholder,style:we}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:Ue,children:[e.jsx("span",{style:Ge,children:i.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((j=m.coverage)==null?void 0:j.level)??"",onChange:k=>v(S,"level",k.target.value),placeholder:"1",style:{...we,width:"60px"}})]}),e.jsxs("label",{style:{...Ue,flex:1},children:[e.jsx("span",{style:Ge,children:i.label.coverageRange}),e.jsx("input",{type:"text",value:((w=m.coverage)==null?void 0:w.ranges)||"",onChange:k=>v(S,"ranges",k.target.value),placeholder:i.editor.coverageRangePlaceholder,style:{...we,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:k=>b(S,"details",k.target.value),placeholder:i.editor.detailsPlaceholder,style:{...we,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(([k,I])=>{var E;return e.jsxs("label",{style:{...Ue,gap:"4px"},children:[e.jsx("span",{style:{...Ge,minWidth:"56px"},children:I}),e.jsx("input",{type:"text",value:((E=m.metadata)==null?void 0:E[k])||"",onChange:z=>y(S,k,z.target.value),placeholder:I,style:{...we,flex:1}})]},k)})})]})]})]})]},S)}),e.jsxs("button",{onClick:h,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 qo(t){switch(t){case"text":return"var(--bim-restype-text, #2196f3)";case"image":return"var(--bim-restype-image, #ff9800)";case"text+image":return"var(--bim-restype-text-image, #9c27b0)";case"physical":return"var(--bim-restype-physical, #795548)"}}function Xo(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 Zo(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:"var(--bim-overlay-bg, #00000010)"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const we={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"},Ue={display:"flex",alignItems:"center",gap:"6px"},Ge={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Qo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃"};function er(t){try{const n=new URL(t).hostname;return Qo[n]}catch{return}}const Zt={text:"var(--bim-restype-text, #2196f3)",image:"var(--bim-restype-image, #ff9800)","text+image":"var(--bim-restype-text-image, #9c27b0)",physical:"var(--bim-restype-physical, #795548)"};function tr(t){return t.includes("text")&&t.includes("image")?Zt["text+image"]:Zt[t[0]||"physical"]}const Qt={text:0,image:1,physical:2};function lt(t){return t.length===0?"physical":[...t].sort((n,o)=>(Qt[n]??99)-(Qt[o]??99)).join("+")}function nr(t){const n=i=>{const l=i.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const c=i.match(/^(.+?)[·(](\d+)[)]?$/);return c?[c[1],parseInt(c[2])]:null},o=new Map,r=[],s=new Set;for(let i=0;i<t.length;i++){const l=t[i];if(l.volumes&&l.volumes.length>0)continue;const c=n(l.name);if(!c)continue;const[a,d]=c,x=`${a}|${lt(Ee(l))}`;o.has(x)||o.set(x,{base:{...l,name:a,url:"",volumes:[]},volumes:[]}),o.get(x).volumes.push({volume:d,url:l.url||void 0,status:"found"}),s.add(i)}for(const[,i]of o)if(i.volumes.length>=2)i.volumes.sort((l,c)=>l.volume-c.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 c=n(t[l].name),a=c&&`${c[0]}|${lt(Ee(t[l]))}`,d=`${i.base.name}|${lt(Ee(i.base))}`;a===d&&s.delete(l)}for(let i=0;i<t.length;i++)s.has(i)||r.push(t[i]);return r}const _t=({items:t,groupByType:n=!0,resourceGroups:o,onNavigate:r,renderLink:s})=>{const i=P(),{convert:l}=M(),c=u.useMemo(()=>nr(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=u.useMemo(()=>{const g=new Map,v=[];for(const m of c){const S=m.group;S?(g.has(S)||g.set(S,[]),g.get(S).push(m)):v.push(m)}for(const m of g.values())m.sort((S,_)=>{const j=w=>w.group_role==="origin"?0:w.group_role==="mirror"?1:2;return j(S)-j(_)});return{mirrorGroups:g,ungroupedItems:v}},[c]),x={text:i.resourceType.text,image:i.resourceType.image,"text+image":i.resourceType.textImage,physical:i.resourceType.physical},f=g=>x[g]?x[g]:g.split("+").map(v=>x[v]||v).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:i.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((g,v)=>e.jsx(ft,{item:g},g.id||v))});const h=(g,v)=>{const m=o==null?void 0:o[g],S=(m==null?void 0:m.label)||g,_=m==null?void 0:m.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(S)}),_&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(_)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((j,w)=>e.jsx(ft,{item:j,onNavigate:r,renderLink:s},j.id||w))})]},`group-${g}`)},p=new Map;for(const g of d){const v=lt(Ee(g));p.has(v)||p.set(v,[]),p.get(v).push(g)}const b=["text","image","text+image","physical"],y=[...b.filter(g=>p.has(g)),...[...p.keys()].filter(g=>!b.includes(g)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([g,v])=>h(g,v)),y.map(g=>{const v=p.get(g),m=tr(g.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:m,whiteSpace:"nowrap",flexShrink:0},children:f(g)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.map((S,_)=>e.jsx(ft,{item:S,onNavigate:r,renderLink:s},S.id||_))})]},g)})]})};function or(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 rr(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 ir(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 sr={bw:{label:"",bg:"var(--bim-colormode-bw-bg, #f5f5f5)",fg:"var(--bim-colormode-bw-fg, #757575)"},color:{label:"",bg:"var(--bim-colormode-color-bg, #fff8e1)",fg:"var(--bim-colormode-color-fg, #f57f17)"}},ft=({item:t})=>{const n=P(),{convert:o}=M(),[r,s]=u.useState(!1),i=u.useMemo(()=>(t.url?er(t.url):void 0)||o(t.name),[t.url,t.name,o]),l=u.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||ir(b)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(l.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,x=t.expected_volumes??(c?a+d:0),f=t.color_mode?{...sr[t.color_mode],label:n.colorMode[t.color_mode]}:null,h=t.details&&!c?o(t.details):null,p={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:p,children:[e.jsx("span",{style:{fontWeight:500},children:i}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),h&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:h}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",x,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const b=rr(t.metadata);return b?or(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}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(b=>{const y=b.status==="missing";return b.url&&!y?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:y?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.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 c=P(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,x=(n==null?void 0:n.repoPath)||"",f=x?x.split(/[/\\]/).pop()||x:"",h={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},p={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},b=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...h,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...p,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return o==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,title:c.mode.switchToSync,style:h,...p,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,title:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:i,title:f||c.mode.configurePath,style:{...h,background:"transparent",padding:"6px",fontSize:"12px"},...p,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:r,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:h,...p,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:x||c.mode.selectFolder,style:{...h,paddingLeft:"8px",paddingRight:"8px",minWidth:x?"100px":"auto",justifyContent:"space-between"},...p,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&e.jsxs("div",{style:{...h,background:"var(--bim-mode-active-bg, #2196f3)",color:"white",cursor:"default"},title:x,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},xt="bim-search-history",en=10,tn=8;function Xe(){try{const t=localStorage.getItem(xt);return t?JSON.parse(t):[]}catch{return[]}}function lr(t){try{const n=Xe().filter(o=>o!==t);n.unshift(t),n.length>en&&(n.length=en),localStorage.setItem(xt,JSON.stringify(n))}catch{}}function ar(t){try{const n=Xe().filter(o=>o!==t);localStorage.setItem(xt,JSON.stringify(n))}catch{}}function cr(){try{localStorage.removeItem(xt)}catch{}}const Vn=({transport:t,value:n,onChange:o,onSearch:r,onEntrySelect:s,placeholder:i})=>{const l=P(),c=i??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,x]=u.useState(!1),[f,h]=u.useState([]),[p,b]=u.useState(-1),[y,g]=u.useState(Xe),v=u.useRef(null),m=u.useRef(null),S=u.useRef(null),_=u.useRef(!1);u.useEffect(()=>{b(-1);const C=n.trim();if(!C){h(y.map(B=>({type:"history",text:B})));return}if(!t.searchAll){h([]);return}let W=!1;const H=setTimeout(()=>{t.searchAll(C,tn).then(B=>{if(W)return;const A=[...B.works,...B.books,...B.collections,...B.entities??[]];h(A.slice(0,tn).map(O=>({type:"entry",text:O.title||O.id,entry:O})))}).catch(()=>{W||h([])})},80);return()=>{W=!0,clearTimeout(H)}},[n,y,t]),u.useEffect(()=>{const C=W=>{S.current&&!S.current.contains(W.target)&&x(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),u.useEffect(()=>{const C=W=>{var H,B;if(W.key==="/"&&document.activeElement!==v.current){const A=(H=document.activeElement)==null?void 0:H.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT")return;W.preventDefault(),(B=v.current)==null||B.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const j=u.useCallback(C=>{C.trim()&&(lr(C.trim()),g(Xe())),r(C),x(!1)},[r]),w=u.useCallback(C=>{C.type==="history"?(o(C.text),j(C.text)):C.entry&&(s?(s(C.entry),x(!1)):(o(C.text),j(C.text)))},[o,j,s]),k=u.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&j(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),b(W=>(W+1)%f.length);break;case"ArrowUp":C.preventDefault(),b(W=>(W-1+f.length)%f.length);break;case"Enter":C.preventDefault(),p>=0&&p<f.length?w(f[p]):j(n);break;case"Escape":C.preventDefault(),x(!1);break}},[d,f,p,n,j,w]),I=u.useCallback((C,W)=>{W.stopPropagation(),ar(C),g(Xe()),h(H=>H.filter(B=>!(B.type==="history"&&B.text===C)))},[]),E=u.useCallback(C=>{C.stopPropagation(),cr(),g([]),h([])},[]);u.useEffect(()=>{if(p>=0&&m.current){const C=m.current.children;C[p]&&C[p].scrollIntoView({block:"nearest"})}},[p]);const z=!n.trim()&&y.length>0;return e.jsxs("div",{ref:S,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:v,type:"text",placeholder:c,value:n,onChange:C=>{o(C.target.value),x(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{x(!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"}}),d&&f.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[z&&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:E,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),f.map((C,W)=>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:W===p?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:C.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.text}),C.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[C.entry.type],C.entry.edition&&` · ${C.entry.edition}`,C.entry.author&&` · ${C.entry.author}`]}),C.type==="history"&&e.jsx("button",{onClick:H=>I(C.text,H),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}-${W}`))]})]})},et="bim-recent-ids",nn="bim-recent-entries",on=50,gt=5,dr=50,pr=200;function Ze(){try{const t=localStorage.getItem(et);if(t)return JSON.parse(t);const n=localStorage.getItem(nn);if(n){const o=JSON.parse(n).map(r=>r.id);return localStorage.setItem(et,JSON.stringify(o)),localStorage.removeItem(nn),o}return[]}catch{return[]}}function xr(t){try{const n=Ze().filter(o=>o!==t);n.unshift(t),n.length>on&&(n.length=on),localStorage.setItem(et,JSON.stringify(n))}catch{}}function ur(t){try{const n=Ze().filter(o=>o!==t);localStorage.setItem(et,JSON.stringify(n))}catch{}}function fr(){try{localStorage.removeItem(et)}catch{}}const gr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},jt=({transport:t,indexSource:n="local",syncConfig:o,onEntryClick:r,onNewEntry:s,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:x="compact",renderEntry:f,initialQuery:h,onQueryChange:p,headerRight:b})=>{const y=P(),g=[{type:"work",icon:"✍️",name:y.indexType.work,key:"works"},{type:"book",icon:"📖",name:y.indexType.book,key:"books"},{type:"collection",icon:"📚",name:y.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:y.indexType.entity,key:"entities"}],[v,m]=u.useState(h??""),[S,_]=u.useState(null),[j,w]=u.useState(null),[k,I]=u.useState(!1),[E,z]=u.useState(null),[C,W]=u.useState(""),[H,B]=u.useState(!h),[A,O]=u.useState(Ze),[L,$]=u.useState([]),[Z,R]=u.useState(!1),[N,oe]=u.useState(!1),[K,ee]=u.useState(null),[re,le]=u.useState(null),U=u.useRef(void 0),q=u.useRef(!1),xe=u.useCallback(async(F,Q)=>{if(!F.trim()){B(!0),_(null),w(null);return}B(!1),I(!0),W("");try{if(t.searchAll){const J=await t.searchAll(F,Q??gt);_(J)}else{const J=["work","book","collection","entity"],T=await Promise.all(J.map(Y=>t.search(F,Y,{page:1,pageSize:Q??gt})));_({works:T[0].entries,books:T[1].entries,collections:T[2].entries,entities:T[3].entries,totalWorks:T[0].total,totalBooks:T[1].total,totalCollections:T[2].total,totalEntities:T[3].total})}}catch(J){W(J instanceof Error?J.message:String(J)),_(null)}finally{I(!1)}},[t]);u.useEffect(()=>{let F=!1;const Q=()=>{var te,ae;const J=["work","book","collection","entity"],T=Promise.all(J.map(ce=>t.loadEntries(ce,{page:1,pageSize:1}).catch(()=>({total:0})))),Y=((te=t.getResourceCounts)==null?void 0:te.call(t).catch(()=>null))??Promise.resolve(null),ne=((ae=t.getSubtypeStats)==null?void 0:ae.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([T,Y,ne]).then(([ce,ue,Fe])=>{F||(ee({works:ce[0].total,books:ce[1].total,collections:ce[2].total,entities:ce[3].total,hasText:ue==null?void 0:ue.hasText,hasImage:ue==null?void 0:ue.hasImage}),Fe&&le(Fe))})};return t.getCounts?t.getCounts().then(J=>{var T,Y;F||(ee({works:J.works,books:J.books,collections:J.collections,entities:J.entities,hasText:(T=J.resourceCounts)==null?void 0:T.hasText,hasImage:(Y=J.resourceCounts)==null?void 0:Y.hasImage}),J.subtypeStats&&le(J.subtypeStats))}).catch(()=>{F||Q()}):Q(),()=>{F=!0}},[t]),u.useEffect(()=>{q.current||!(h!=null&&h.trim())||(q.current=!0,xe(h))},[h,xe]);const We=u.useCallback(F=>{if(m(F),!F.trim()){p==null||p(F),B(!0),_(null),w(null);return}U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{w(null),p==null||p(F),xe(F)},pr)},[xe,p]),$e=u.useCallback(F=>{U.current&&clearTimeout(U.current),p==null||p(F),xe(F)},[xe,p]),he=u.useCallback(F=>{w(F),xe(v,dr)},[v,xe]);u.useEffect(()=>{if(!A.length){$([]);return}let F=!1;return R(!0),Promise.all(A.slice(0,10).map(async Q=>{var J,T,Y;try{if(t.getEntry){const te=await t.getEntry(Q);if(te)return te}const ne=await t.getItem(Q);if(ne){const te=ne.authors;return{id:Q,title:ne.title||Q,type:ne.type||"work",author:(J=te==null?void 0:te[0])==null?void 0:J.name,dynasty:(T=te==null?void 0:te[0])==null?void 0:T.dynasty,role:(Y=te==null?void 0:te[0])==null?void 0:Y.role,edition:ne.edition||void 0}}}catch{}return{id:Q,title:Q,type:"work",notFound:!0}})).then(Q=>{F||($(Q),R(!1))}),()=>{F=!0}},[A,t]);const be=F=>{z(F.id),xr(F.id),O(Ze()),r==null||r(F)},ze=F=>{ur(F),O(Ze())},Ae=()=>{fr(),O([])},me=F=>g.find(Q=>Q.type===F),De=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:y.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&e.jsx(Nn,{variant:"index-browser",indexSource:n,syncConfig:o,onSwitchMode:i,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Vn,{transport:t,value:v,onChange:We,onSearch:$e,onEntrySelect:be}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:y.action.newEntry})]}),K&&H&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:re?e.jsxs(e.Fragment,{children:[(re.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()})," 本"]}),re.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.article.toLocaleString()})," 篇"]}):null,re.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()}),K.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.entities.toLocaleString()})]})]})}),K.hasImage!=null&&K.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:k?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.searching}):C?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:C})]}):H?e.jsx("div",{style:{flex:1},children:Z?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):L.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:y.search.recentBrowse}),e.jsx("button",{onClick:Ae,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:y.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:L.slice(0,N?10:3).map(F=>F.notFound?e.jsx(br,{id:F.id,onRemove:ze,t:y},F.id):e.jsx(rn,{entry:F,selected:E===F.id,onClick:be,getConfig:me,onRemove:ze},F.id))}),!N&&L.length>3&&e.jsx("button",{onClick:()=>oe(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:y.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:y.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.searchSubtitle})]})}):De?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:g.map(({type:F,icon:Q,name:J,key:T})=>{const Y=S[T]??[],ne=gr[T],te=S[ne]??0;if(Y.length===0)return null;const ce=!(j===F)&&te>gt;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," ",J,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[te," ",y.unit.items]})]}),ce&&e.jsx("button",{onClick:()=>he(F),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:y.action.viewAll})]}),e.jsx("div",{style:x==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Y.map(ue=>{if(f)return e.jsx(u.Fragment,{children:f(ue)},ue.id);const Fe=x==="card"?hr:rn;return e.jsx(Fe,{entry:ue,selected:E===ue.id,onClick:be,getConfig:me,query:v},ue.id)})})]},F)})}):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:nt(y.search.noResultsFor,{query:v})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},hr=({entry:t,selected:n,onClick:o,getConfig:r,query:s})=>{const i=P(),{convert:l}=M(),c=l(t.title||t.primary_name||t.id),a=t.measure_info?l(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${i.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],x=s&&d.length?d.find(h=>{const p=typeof h=="string"?h:h==null?void 0:h.book_title;return p==null?void 0:p.toLowerCase().includes(s.toLowerCase())}):void 0,f="var(--bim-cover-accent, #8e6f3e)";return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:"var(--bim-bg, #fff)",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${f} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${f} 7%, var(--bim-bg, #fff)))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${f} 45%, transparent)`}}),e.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:f},children:Array.from(c).map((h,p)=>e.jsx("span",{children:h},p))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c}),a&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(t.role)]})]}),t.edition&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l(t.edition)}),x&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[i.search.alias,":",l(typeof x=="string"?x:x.book_title||"")]}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[r(t.type).icon," ",r(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",i.misc.textResource]}),t.has_image&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["🖼️ ",i.misc.imageResource]})]})]})]})},rn=({entry:t,selected:n,onClick:o,getConfig:r,query:s,onRemove:i})=>{const l=P(),{convert:c}=M(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(x=>{const f=typeof x=="string"?x:x==null?void 0:x.book_title;return f==null?void 0:f.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>o(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),i?e.jsx("button",{onClick:x=>{x.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:"→"})]})},br=({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 mr(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 yr({data:t}){const{convert:n}=M(),{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 vr({alt_names:t}){const{convert:n}=M(),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 c=r.indexOf(i),a=r.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(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((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},i)})})}function jr({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 Sr({works:t,transport:n,onNavigate:o,renderLink:r}){const s=P(),{convert:i}=M(),l=ke(),[c,a]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let h=!1;const p=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const S=await n.getEntriesByIds(p);let _=!0;for(let j=0;j<p.length;j++){const w=S[j];w!=null&&w.title?y.set(p[j],w.title):w!=null&&w.primary_name?y.set(p[j],w.primary_name):_=!1}if(_)return y}catch{}const g=[...p],v=8,m=new Array(v).fill(0).map(async()=>{for(;g.length;){const S=g.shift();if(!S)break;if(!y.has(S))try{if(n.getEntry){const w=await n.getEntry(S);if(w!=null&&w.title){y.set(S,w.title);continue}}const _=await n.getItem(S),j=_&&(_.title||_.primary_name)||S;y.set(S,j)}catch{y.set(S,S)}}});return await Promise.all(m),y})().then(y=>{h||a(y)}),()=>{h=!0}},[t,n]);const d=new Map;for(const h of t){const p=h.role||"";d.has(p)||d.set(p,[]),d.get(p).push(h)}const x=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((h,p)=>{const b=x.indexOf(h),y=x.indexOf(p);return b===-1&&y===-1?h.localeCompare(p):b===-1?1:y===-1?-1:b-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),f.map(h=>{const p=d.get(h);return e.jsxs("div",{style:{marginBottom:"8px"},children:[h&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[i(h)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",p.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:h?"16px":"0",listStyle:h?"disc":"none",fontSize:"14px",lineHeight:1.8},children:p.map((b,y)=>{const g=i(c.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,g)},y):o?e.jsx("li",{children:e.jsx("a",{href:l(b.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),o(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:g})},y):e.jsx("li",{children:g},y)})})]},h)})]})}const Un=({data:t,transport:n,onNavigate:o,renderLink:r,headerExtra:s})=>{var x;const i=P(),{convert:l}=M();let c=!1;try{c=G.extractStatus(t.id)==="draft"}catch{}const a=mr(t),d=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[l(t.primary_name),e.jsx(yr,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"var(--bim-type-entity, #5b3e8e)",border:"1px solid color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 25%, transparent)",borderRadius:"2px",background:"color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 3%, transparent)"},children:i.indexType.entity}),d&&t.subtype!=="people"&&e.jsx("span",{children:d}),c&&e.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:i.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]}),a&&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(vr,{alt_names:t.alt_names}),e.jsx(jr,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:l(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Sr,{works:t.works,transport:n,onNavigate:o,renderLink:r})]})},Gn={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},kr={...Gn,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},St=({text:t,plainStrong:n,style:o,className:r})=>{const{convert:s}=M(),i=n?kr:Gn;return e.jsx("div",{className:r,style:o,children:e.jsx(Bo,{remarkPlugins:[Wo],components:i,children:s(t)})})},wr=["〇","一","二","三","四","五","六","七","八","九"],sn=["","十","百","千"];function Yn(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]),c=o-1-i;l===0?s=!0:(s&&r&&(r+="〇"),s=!1,l===1&&c===1&&i===0?r+=sn[c]:r+=wr[l]+sn[c])}return r}function Kn(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const _r={book:"var(--bim-type-book, #c0392b)",work:"var(--bim-type-work, #8e6f3e)",collection:"var(--bim-type-collection, #2471a3)",entity:"var(--bim-type-entity, #5b3e8e)"};function Cr({type:t}){const n=P();return e.jsx("span",{style:Kn(_r[t]),children:n.indexType[t]})}function Ir({isDraft:t}){const n=P(),o=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Kn(o),children:t?n.status.draft:n.status.official})}function zr({id:t}){const n=P(),[o,r]=u.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-bg-subtle, #f6f6f6)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title: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 ve({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 _e({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 Jn({authors:t,type:n,onNavigate:o,renderLink:r}){const{convert:s}=M();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((i,l)=>{const c=s(i.name),a=i.entity_id?e.jsx(Se,{id:i.entity_id,label:c,onNavigate:o,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),i.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(i.dynasty),"〕"]}),a,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=ke();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 Tr({id:t,title:n,edition:o,type:r,isDraft:s,authors:i,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:x}){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})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Cr,{type:r}),e.jsx(Ir,{isDraft:s}),e.jsx(zr,{id:t})]}),((i==null?void 0:i.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[i&&i.length>0&&e.jsx(Jn,{authors:i,type:r,onNavigate:d,renderLink:x}),c]})]})}function qn({items:t,label:n,showMeta:o,onNavigate:r,renderLink:s}){const i=P(),{convert:l}=M();if(!t.length)return null;const[c,a]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,x)=>{const f=c===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?null:x),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!f&&o&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:h=>h.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(Se,{id:d.source_bid,label:i.action.view,onNavigate:r,renderLink:s})})]}),f&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(_e,{label:i.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(_e,{label:i.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(_e,{label:i.label.edition,children:l(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:i.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},x)})})]})}function Rr({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(qn,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:o})}function Ct({items:t,onNavigate:n,renderLink:o}){const r=P();return e.jsx(qn,{items:t,label:r.section.emendated,onNavigate:n,renderLink:o})}function Xn({label:t,items:n}){const{convert:o}=M();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 Er({items:t}){const n=P();return e.jsx(Xn,{label:n.section.aliases,items:t})}function Lr({items:t}){const n=P();return e.jsx(Xn,{label:n.section.attachedTexts,items:t})}function Br({items:t}){const n=P(),{convert:o}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 Wr({items:t}){const n=P(),{convert:o}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 $r({items:t}){const n=P(),{convert:o}=M();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(ve,{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 ln({title:t,ids:n,transport:o,onNavigate:r,renderLink:s}){const{convert:i}=M(),[l,c]=u.useState([]);return u.useEffect(()=>{if(!n.length){c([]);return}if(!o){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>o.getItem(d).then(x=>({id:d,title:x?x.title:void 0,edition:x?x.edition:void 0,type:x?x.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,o]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(ve,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${i(a.title)||a.id}(${i(a.edition)})`:i(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(Se,{id:a.id,label:d,onNavigate:r,renderLink:s})},a.id)})})]}):null}function ht({book:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=M(),[i,l]=u.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(Se,{id:t.id,label:a,onNavigate:n,renderLink:o})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:i?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:i?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!i&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(_t,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:o})})]})}function Ar({ids:t,workData:n,transport:o,onNavigate:r,renderLink:s,footer:i}){const l=P(),{convert:c}=M(),[a,d]=u.useState([]);if(u.useEffect(()=>{if(!t.length){d([]);return}if(!o){d(t.map(y=>({id:y})));return}let b=!1;return Promise.all(t.map(y=>o.getItem(y).then(g=>({id:y,title:g?g.title:void 0,edition:g?g.edition:void 0,resources:g?g.resources:void 0,resource_groups:g?g.resource_groups:void 0})).catch(()=>({id:y})))).then(y=>{b||d(y)}),()=>{b=!0}},[t,o]),!t.length)return null;const x=a.length?a:t.map(b=>({id:b})),f=new Map(x.map(b=>[b.id,b])),h=n==null?void 0:n.version_graph,p=Fr(t,h);return e.jsxs(e.Fragment,{children:[e.jsxs(ve,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),i,p.useGrouping?e.jsxs(e.Fragment,{children:[p.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.coreIds.map(b=>{const y=f.get(b);return y?e.jsx(ht,{book:y,onNavigate:r,renderLink:s},b):null})}),p.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(y=>{const g=f.get(y);return g?e.jsx(ht,{book:g,onNavigate:r,renderLink:s},y):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:x.map(b=>e.jsx(ht,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function Fr(t,n){var g,v;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const o=(g=n.collections)==null?void 0:g[n.default_collection],r=(o==null?void 0:o.groups)??[],s=(o==null?void 0:o.book_ids)??[],i=r.length>0||s.length>0,l=!i&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!i&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),a=new Set([...s,...l]),d=m=>{if(a.has(m))return!0;const S=n.node_groups[m];return S!=null&&c.has(S)},x=[],f=new Map,h=[];for(const m of t)if(!((v=n.excluded_books)!=null&&v.includes(m)))if(d(m))x.push(m);else{const S=n.node_groups[m];S?(f.has(S)||f.set(S,[]),f.get(S).push(m)):h.push(m)}if(h.length+[...f.values()].reduce((m,S)=>m+S.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...f.entries()].map(([m,S])=>{const _=b.get(m);return{id:m,label:(_==null?void 0:_.label)??m,description:_==null?void 0:_.description,ids:S}});return h.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:h}),{useGrouping:!0,coreIds:x,groupedIds:y}}function Pr({workData:t,onNavigate:n,renderLink:o}){var l,c,a,d;const r=P(),{convert:s}=M(),i=!!((l=t.description)!=null&&l.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:i?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(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)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Yn(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Jn,{authors:t.authors,type:"work",onNavigate:n,renderLink:o})})]}),i&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(St,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(_e,{label:r.label.parentWork,children:e.jsx(Se,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:o})})})]})]})}function Mr({items:t,onNavigate:n,renderLink:o}){const r=P(),{convert:s}=M();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 color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:r.indexType.collection}),e.jsx(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:nt(r.catalog.volume,{n:i.volume_index})})]},i.id))}):null}const ut=({data:t,id:n,transport:o,onNavigate:r,renderLink:s,headerExtra:i,relatedBooksFooter:l,className:c,style:a})=>{var W,H,B,A,O,L,$,Z;const d=P(),{convert:x}=M(),[f,h]=u.useState(null),[p,b]=u.useState(!1),[y,g]=u.useState(null),[v,m]=u.useState(null),[S,_]=u.useState([]),j=t||f;if(u.useEffect(()=>{if(t||!n||!o)return;let R=!1;return b(!0),g(null),o.getItem(n).then(N=>{R||(N?h(N):g(d.misc.notFoundEntry))}).catch(N=>{R||g(N instanceof Error?N.message:d.misc.loadFailed)}).finally(()=>{R||b(!1)}),()=>{R=!0}},[t,n,o]),u.useEffect(()=>{if(!j||!o){m(null),_([]);return}let R=!1;const N=j.type==="book"||j.type==="collection"?j.work_id:void 0;if(N?o.getItem(N).then(oe=>{!R&&oe&&oe.type==="work"&&m(oe)}).catch(()=>{}):m(null),j.type==="book"){const oe=j;oe.contained_in&&oe.contained_in.length>0?Promise.all(oe.contained_in.map(K=>{const ee=typeof K=="string"?K:K.id,re=typeof K=="string"?void 0:K.volume_index;return o.getItem(ee).then(le=>({id:ee,title:le&&le.title||ee,volume_index:re})).catch(()=>({id:ee,title:ee,volume_index:re}))})).then(K=>{R||_(K)}):_([])}else _([]);return()=>{R=!0}},[j,o]),p)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((R,N)=>e.jsx("div",{style:{height:N===1?"32px":"16px",width:`${R}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},N))})});if(y)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!j)return null;if(j.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Un,{data:j,transport:o,onNavigate:r,renderLink:s,headerExtra:i})});const w=j.type==="book"?j:null,k=j.type==="collection"?j:null,I=j.type==="work"?j:null;let E=!1;try{E=G.extractStatus(j.id)==="draft"}catch{}let z="";j.measure_info?z=x(j.measure_info):(W=j.juan_count)!=null&&W.number?z=Yn(j.juan_count.number)+d.unit.juan:(H=j.juan_count)!=null&&H.description&&(z=x(j.juan_count.description));const C=[];return(B=j.publication_info)!=null&&B.year&&C.push(e.jsx(_e,{label:d.label.year,children:j.publication_info.year},"year")),(A=j.current_location)!=null&&A.name&&C.push(e.jsx(_e,{label:d.label.currentLocation,children:x(j.current_location.name)},"loc")),(O=j.page_count)!=null&&O.description&&C.push(e.jsx(_e,{label:d.label.pageCount,children:j.page_count.description},"page")),w!=null&&w.edition&&C.push(e.jsx(_e,{label:d.label.edition,children:x(w.edition)},"ver")),I!=null&&I.parent_work&&C.push(e.jsx(_e,{label:d.label.parentWork,children:e.jsx(Se,{id:I.parent_work.id,label:x(I.parent_work.title),onNavigate:r,renderLink:s})},"pw")),I!=null&&I.parent_works&&I.parent_works.length>0&&!I.parent_work&&C.push(e.jsx(_e,{label:d.label.parentWork,children:I.parent_works.map((R,N)=>e.jsxs("span",{children:[N>0&&"、",e.jsx(Se,{id:R,onNavigate:r,renderLink:s})]},R))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(Tr,{id:j.id,title:x(j.title),edition:j.edition?x(j.edition):void 0,type:j.type,isDraft:E,authors:j.authors,volumeText:z,meta:C,headerExtra:i,onNavigate:r,renderLink:s}),((L=j.description)==null?void 0:L.text)&&e.jsx(St,{text:j.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),j.appendix&&j.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:j.appendix.map((R,N)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:x(R.title)}),e.jsx(St,{text:R.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},N))}),S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:d.section.containedIn}),e.jsx(Mr,{items:S,onNavigate:r,renderLink:s})]}),v&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:d.section.belongsToWork}),e.jsx(Pr,{workData:v,onNavigate:r,renderLink:s})]}),j.additional_works&&j.additional_works.length>0&&e.jsx(Br,{items:j.additional_works}),j.additional_titles&&j.additional_titles.length>0&&e.jsx(Er,{items:j.additional_titles}),j.attached_texts&&j.attached_texts.length>0&&e.jsx(Lr,{items:j.attached_texts}),j.indexed_by&&j.indexed_by.length>0&&e.jsx(Rr,{items:j.indexed_by,onNavigate:r,renderLink:s}),j.emendated_by&&j.emendated_by.length>0&&e.jsx(Ct,{items:j.emendated_by,onNavigate:r,renderLink:s}),j.resources&&j.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ve,{children:d.section.resources}),e.jsx(_t,{items:j.resources,resourceGroups:j.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(w==null?void 0:w.location_history)&&w.location_history.length>0&&e.jsx(Wr,{items:w.location_history}),(k==null?void 0:k.history)&&k.history.length>0&&e.jsx($r,{items:k.history}),(w==null?void 0:w.related_books)&&w.related_books.length>0&&e.jsx(ln,{title:d.section.relatedVersions,ids:w.related_books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.books)&&k.books.length>0&&e.jsx(ln,{title:d.section.containedBooks,ids:k.books,transport:o,onNavigate:r,renderLink:s}),(k==null?void 0:k.contained_works)&&k.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(ve,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",k.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:k.contained_works.map(R=>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:R.id,label:x(R.title),onNavigate:r,renderLink:s})},R.id))})]}),((($=I==null?void 0:I.books)==null?void 0:$.length)||0)+(((Z=I==null?void 0:I.collections)==null?void 0:Z.length)||0)>0&&e.jsx(Ar,{ids:[...(I==null?void 0:I.books)||[],...(I==null?void 0:I.collections)||[]],workData:I,transport:o,onNavigate:r,renderLink:s,footer:l}),(I==null?void 0:I.related_works)&&I.related_works.length>0&&(()=>{const R=[],N=I.related_works.filter(U=>U.relation==="part_of"),oe=I.related_works.filter(U=>U.relation==="has_part"),K=I.related_works.filter(U=>U.relation==="has_adaptation"),ee=I.related_works.filter(U=>U.relation==="text_carried_by"),re=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),le=I.related_works.filter(U=>!U.relation||!re.has(U.relation));return N.length>0&&R.push({label:d.section.belongsToWork,items:N}),oe.length>0&&R.push({label:d.section.containedWorks,items:oe}),K.length>0&&R.push({label:d.section.adaptations,items:K}),ee.length>0&&R.push({label:d.section.derivativeWorks,items:ee}),le.length>0&&R.push({label:d.section.relatedWorks,items:le}),R.map(U=>e.jsxs("div",{children:[e.jsxs(ve,{children:[U.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",U.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:U.items.map(q=>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:q.id,label:x(q.title),onNavigate:r,renderLink:s})},q.id))})]},U.label))})()]})};function Hr({data:t}){const n=P(),{convert:o}=M(),{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:"var(--bim-missing-fg, #e67e22)"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Or({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:an(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>o(s.name),style:an(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 an(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 Dr({id:t,label:n,onNavigate:o,renderLink:r}){const s=ke();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 Nr(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 cn({book:t,onNavigate:n,renderLink:o,showVolumes:r}){const s=P(),{convert:i}=M(),l=t.book_id||t.work_id,c=r&&t.volumes.length>0?Nr(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[i(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>i(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:i(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Dr,{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 It=({data:t,collectionId:n,transport:o,onNavigate:r,renderLink:s,className:i,style:l})=>{const c=P(),[a,d]=u.useState(null),[x,f]=u.useState(!1),[h,p]=u.useState(null),[b,y]=u.useState(null),[g,v]=u.useState(""),m=t||a;u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollectionCatalog))return;let k=!1;return f(!0),p(null),o.getCollectionCatalog(n).then(I=>{k||(I?d(I):p(c.catalog.notFound))}).catch(I=>{k||p(I instanceof Error?I.message:c.catalog.loadFailed)}).finally(()=>{k||f(!1)}),()=>{k=!0}},[t,n,o,c]);const S=(m==null?void 0:m.sections)&&m.sections.length>0,_=u.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const k=m.books.map(E=>E.volumes[0]).filter(E=>E!=null);return new Set(k).size<k.length},[m]),j=u.useMemo(()=>{if(!m)return[];let k=m.books;if(b&&(k=k.filter(I=>I.section===b)),g.trim()){const I=g.trim().toLowerCase();k=k.filter(E=>E.title.toLowerCase().includes(I)||E.sub_items&&E.sub_items.some(z=>z.toLowerCase().includes(I))||E.edition&&E.edition.toLowerCase().includes(I))}return k},[m,b,g]),w=u.useMemo(()=>{if(!_)return null;const k=[],I=new Map;for(const z of j){if(!z.volumes||z.volumes.length===0)continue;const C=z.volumes[0];I.has(C)||I.set(C,[]),I.get(C).push(z)}const E=[...I.keys()].sort((z,C)=>z-C);for(const z of E)k.push({volume:z,books:I.get(z)});return k},[j,_]);return x?e.jsx("div",{className:i,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):h?e.jsx("div",{className:i,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h}):m?e.jsxs("div",{className:i,style:l,children:[e.jsx(Hr,{data:m}),S&&e.jsx(Or,{sections:m.sections,activeSection:b,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:g,onChange:k=>v(k.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:[j.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[w?w.map((k,I)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:nt(c.catalog.volume,{n:k.volume})}),k.books.map((E,z)=>e.jsx(cn,{book:E,onNavigate:r,renderLink:s,showVolumes:E.volumes.length>1},`${k.volume}-${z}`))]},`${k.volume}-${I}`)):j.map((k,I)=>e.jsx(cn,{book:k,onNavigate:r,renderLink:s,showVolumes:!0},I)),j.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Be=()=>{const[t,n]=u.useState(1);return u.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)})},pe=6,rt=7,Vr=({content:t,children:n,placement:o="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:i})=>{const[l,c]=u.useState(!1),[a,d]=u.useState(null),x=u.useRef(null),f=u.useRef(null),h=u.useRef(null),p=u.useCallback(()=>{const g=f.current,v=h.current;if(!g||!v)return;const m=g.getBoundingClientRect(),S=v.getBoundingClientRect(),_=window.innerHeight,j=document.documentElement.clientWidth;let w=o;o==="top"&&m.top-S.height-rt<8&&(w="bottom"),o==="bottom"&&m.bottom+S.height+rt>_-8&&(w="top");const k=w==="top"?m.top-S.height-rt:m.bottom+rt;let I=m.left+m.width/2-S.width/2;I=Math.max(8,Math.min(I,j-S.width-8)),d({left:I,top:k,placement:w})},[o]),b=u.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>c(!0),r)},[r]),y=u.useCallback(()=>{x.current&&clearTimeout(x.current),c(!1),d(null)},[]);return u.useEffect(()=>{if(!l)return;const g=requestAnimationFrame(p);return()=>cancelAnimationFrame(g)},[l,p]),u.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:b,onMouseLeave:y,onFocus:b,onBlur:y,style:{display:"inline-block",...i},children:n}),l&&$o.createPortal(e.jsxs("div",{ref:h,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-pe,width:0,height:0,...a.placement==="top"?{bottom:-pe,borderTop:`${pe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${pe}px solid transparent`,borderRight:`${pe}px solid transparent`}:{top:-pe,borderBottom:`${pe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${pe}px solid transparent`,borderRight:`${pe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${pe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${pe-1}px solid transparent`,borderRight:`${pe-1}px solid transparent`}:{top:-5,borderBottom:`${pe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${pe-1}px solid transparent`,borderRight:`${pe-1}px solid transparent`}}})]})]}),document.body)]})},dn={A:"fine",B:"rough",C:"rough",D:"ocr"};function Ur(t){return typeof t!="string"?null:t in Hn?t:t in dn?dn[t]:null}const Gr={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"};function se(t){return typeof t!="string"?"":Gr[t]??t}const Yr=["〇","一","二","三","四","五","六","七","八","九"],pn=["","十","百","千"],Kr=["","萬","億"];function Zn(t){if(t===0)return"〇";if(t<0)return`負${Zn(-t)}`;const n=[];let o=t,r=0;for(;o>0;){const s=o%1e4;s>0?n.unshift(Jr(s,r>0)+Kr[r]):n.length>0&&n.unshift("〇"),o=Math.floor(o/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Jr(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],c=o.length-1-i;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&i===0&&!n?s+=pn[c]:s+=Yr[l]+pn[c]}return s.replace(/〇$/,"")}let Qe=null,it=null;const dt=new Set;function qr(){return Qe?Promise.resolve():it||(it=import("opencc-js/t2cn").then(t=>{Qe=t.Converter({from:"tw",to:"cn"}),dt.forEach(n=>n())}).catch(()=>{Qe=t=>t,dt.forEach(t=>t())}),it)}function Ie(){const[,t]=u.useState(0);return u.useEffect(()=>{if(Qe)return;const n=()=>t(o=>o+1);return dt.add(n),qr(),()=>{dt.delete(n)}},[]),Qe??(n=>n)}function He(t,n){return n(t).toLowerCase()}const zt="var(--bim-highlight-bg, #fff59d)";function Oe(t,n,o){if(!n)return t;const r=He(n,o);if(!r)return t;const s=He(t,o);if(s.length!==t.length)return t;const i=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(r,l);if(a===-1){i.push(t.slice(l));break}a>l&&i.push(t.slice(l,a)),i.push(e.jsx("mark",{style:{background:zt,padding:0,color:"inherit"},children:t.slice(a,a+r.length)},c++)),l=a+r.length}return e.jsx(e.Fragment,{children:i})}function Tt(t,n,o,r){if(!n)return!0;const s=He(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"&&He(l,r).includes(s))}function Xr(t,n,o){return n?He(t,o).includes(He(n,o)):!0}const Rt={类:"var(--bim-section-lei, #8e6f3e)",书:"var(--bim-section-shu, #c0392b)",序:"var(--bim-section-xu, #1a5276)",结语:"var(--bim-section-jieyu, #7d6608)"},Zr={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Qr(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 Qn({file:t,isActive:n,onSelect:o,meta:r,matchState:s}){const i=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=Qr(t),d=!!(r!=null&&r.vol_label)&&!a.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{i||o(t)},disabled:i,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":i?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":c?`${zt}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:[a,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function eo(t,n){var o;return t.files.includes(n)?!0:!!((o=t.children)!=null&&o.some(r=>eo(r,n)))}function to(t){var r;const n=t.files.length,o=((r=t.children)==null?void 0:r.reduce((s,i)=>s+to(i),0))||0;return n+o}function ei(t,n){const o=[],r=l=>{var c;o.push(...l.files),(c=l.children)==null||c.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 no({group:t,activeFile:n,onSelect:o,depth:r=0,juanMeta:s,matchStates:i}){var b;const l=eo(t,n||""),c=ei(t,i),a=typeof c=="number"&&c>0,d=c===0,[x,f]=u.useState(l||a),h=to(t),p=!!((b=t.children)!=null&&b.length);if(u.useEffect(()=>{l&&f(!0)},[l]),u.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!p){const y=t.files[0],g=n===y,v=i[y],m=v===0,S=v==="loading",_=typeof v=="number"&&v>0;return e.jsxs("button",{onClick:()=>{m||o(y)},disabled:m,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:g?"1px solid var(--bim-primary, #8e6f3e)":m?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:g?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${zt}40`:"transparent",color:g?"var(--bim-primary, #8e6f3e)":m?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:m?"not-allowed":"pointer",fontSize:"12px",fontWeight:g?600:400,lineHeight:1.4,opacity:m?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:v}),S&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>f(!x),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",h,")"]}),a&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+r*16}px`},children:t.files.map(y=>e.jsx(Qn,{file:y,isActive:n===y,onSelect:o,meta:s==null?void 0:s[y],matchState:i[y]},y))}),p&&t.children.map((y,g)=>e.jsx(no,{group:y,activeFile:n,onSelect:o,depth:r+1,juanMeta:s,matchStates:i},g))]})]})}function ti({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((c,a)=>e.jsx(no,{group:c,activeFile:o,onSelect:r,juanMeta:s,matchStates:i},a))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(c=>e.jsx(Qn,{file:c,isActive:o===c,onSelect:r,meta:s==null?void 0:s[c],matchState:i[c]},c))})}function ni({type:t}){const n=Rt[t]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function oi({section:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=M(),s=ke(),i=Ie(),l=y=>{if(!y)return"";const g=r(y);return o?Oe(g,o,i):g},[c,a]=u.useState(!1),d=!!t.summary,x=!!t.comment,f=!!t.additional_comment,h=!!(t.content&&t.content.length>60),p=d||x||f||h;u.useEffect(()=>{o&&a(!0)},[o]);const b=!c&&h?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>p&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:p?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",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:[Zn(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&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:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&p&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children: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)})]}),h&&!d&&!x&&!f&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function ri({section:t,highlightQuery:n=""}){const{convert:o}=M(),r=Ie(),s=a=>{if(!a)return"";const d=o(a);return n?Oe(d,n,r):d},[i,l]=u.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!i),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ni,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:i?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),i&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Rt[t.type]||"var(--bim-desc-fg, #717171)"} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}function ii({section:t,highlightQuery:n=""}){const{convert:o}=M(),r=Ie();if(!t.content&&!t.title)return null;const s=o((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
2
|
`)),i=n?Oe(s,n,r):s,l=Rt[t.type]||"var(--bim-desc-fg, #717171)",c=se(t.type)==="序"||se(t.type)==="结语";return e.jsxs("div",{style:{padding:c?"10px 12px":"6px 0",margin:c?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:c?`3px solid ${l}40`:void 0,background:c?"var(--bim-bg, #fafafa)":void 0,borderRadius:c?"0 4px 4px 0":void 0,position:"relative"},children:[c&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:l,marginRight:"8px",padding:"1px 5px",border:`1px solid ${l}40`,borderRadius:"2px",background:`${l}08`,verticalAlign:"middle"},children:t.type}),i]})}function si(t,n,o){const[r,s]=u.useState({});return u.useEffect(()=>{var d;if(!n||t.length===0)return;let i=!1;const l=t.filter(x=>{var f;return!((f=o==null?void 0:o.current)!=null&&f.has(x))}),c={};for(const x of t)(d=o==null?void 0:o.current)!=null&&d.has(x)&&(c[x]=o.current.get(x));if(Object.keys(c).length>0&&s(c),l.length===0)return;const a=async x=>{var f;try{if(n.getEntry){const g=await n.getEntry(x);if(g)return{title:g.title,author:g.author}}const h=await n.getItem(x);if(!h)return null;const p=h.title||x,b=h.authors,y=(f=b==null?void 0:b[0])==null?void 0:f.name;return{title:p,author:y}}catch{return null}};return Promise.all(l.map(async x=>{var h;const f=await a(x);return(h=o==null?void 0:o.current)==null||h.set(x,f),[x,f]})).then(x=>{i||s(f=>{const h={...f};for(const[p,b]of x)h[p]=b;return h})}),()=>{i=!0}},[t.join(","),n]),r}function li({section:t,onNavigate:n,transport:o,workLabelCache:r,highlightQuery:s=""}){const{convert:i}=M(),l=ke(),c=Ie(),a=m=>{if(!m)return"";const S=i(m);return s?Oe(S,s,c):S},[d,x]=u.useState(!1);u.useEffect(()=>{s&&x(!0)},[s]);const f=t.type,h=Zr[f]||"var(--bim-desc-fg, #717171)",p=!!t.content,b=t.work_ids||[],y=b.length>1,g=si(y?b:[],o,r),v=p&&!d&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>p&&x(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:p?"pointer":"default",userSelect:"none"},children:[p&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?a(t.header_line):a(t.title)}),!d&&v&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:a(v)})]}),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:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),y&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:h,border:`1px solid ${h}40`,borderRadius:"2px",background:`${h}08`},children:f})]})]}),y&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(m=>{const S=g[m],_=S?`${i(S.title)}${S.author?`(${i(S.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:l(m),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),j.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",_]},m)})}),d&&p&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${h}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:a(t.comment)})]})]})}function ai({juan:t,searchQuery:n,onNavigate:o,transport:r,workLabelCache:s}){const{convert:i}=M(),l=Ie(),c=n.trim(),a=u.useMemo(()=>c?t.sections.filter(f=>Tt(f,c,!0,l)):t.sections,[t.sections,c,l]),d=t.sections.filter(f=>se(f.type)==="考证").length,x=a.filter(f=>se(f.type)==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:i(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:c?`${x} / ${d} 條`:`${d} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:a.map((f,h)=>e.jsx(li,{section:f,onNavigate:o,transport:r,workLabelCache:s,highlightQuery:c},h))}),a.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function ci({text:t,highlightQuery:n=""}){const{convert:o}=M(),r=Ie(),s=l=>{const c=o(l);return n?Oe(c,n,r):c},i=t.split(`
|
|
3
3
|
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:i.map((l,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!i[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,x)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},x):e.jsx(u.Fragment,{children:s(d)},x))},c)})})}function di({sections:t,onNavigate:n,highlightQuery:o=""}){const{convert:r}=M(),s=ke(),i=Ie(),l=d=>{if(!d)return"";const x=r(d);return o?Oe(x,o,i):x},c=[];let a=null;for(const d of t)se(d.type)==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):se(d.type)==="书"?(a||(a={category:"",items:[]}),a.items.push(d)):(se(d.type)==="序"||se(d.type)==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),se(d.type)==="结语"&&(c.push(a),a=null));return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,x)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((f,h)=>se(f.type)==="序"||se(f.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(f.content||"")},h):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&f.work_id?e.jsx("a",{href:s(f.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),p.stopPropagation(),n(f.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(f.title),children:e.jsx("strong",{children:l(f.title)})}):e.jsx("strong",{children:l(f.title)}),f.content&&l(f.content)]},h))]},x))})}function pi({juan:t,rawText:n,searchQuery:o,onNavigate:r}){const{convert:s}=M(),i=Ie(),[l,c]=u.useState("catalog"),a=o.trim(),d=u.useMemo(()=>a?t.sections.filter(p=>Tt(p,a,!1,i)):t.sections,[t.sections,a,i]),x=t.sections.filter(p=>se(p.type)==="书").length,f=t.sections.filter(p=>se(p.type)==="诗").length,h=a?d.filter(p=>se(p.type)==="书"||se(p.type)==="诗").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(p=>e.jsx("button",{onClick:()=>c(p),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:p==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===p?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===p?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:p==="catalog"?"目錄":"原文"},p))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:h!=null?`${h} / ${f>0?`${f} 首`:`${x} 部書`}`:f>0?`${f} 首`:`${x} 部书`})]}),l==="raw"&&(n?e.jsx(ci,{text:n,highlightQuery:a}):e.jsx(di,{sections:t.sections,onNavigate:r,highlightQuery:a})),l==="catalog"&&d.map((p,b)=>se(p.type)==="书"||se(p.type)==="诗"?e.jsx(oi,{section:p,onNavigate:r,highlightQuery:a},b):se(p.type)==="类"?e.jsx(ri,{section:p,highlightQuery:a},b):e.jsx(ii,{section:p,highlightQuery:a},b)),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function oo(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 xn(t){const n=oo(t);return n.length>0?n[0]:null}function xi(t){const{workId:n,transport:o,files:r,activeFile:s,activeJuan:i,activeRawText:l,query:c,isKaozhen:a}=t,d=Ie(),x=u.useRef(new Map),[f,h]=u.useState({});u.useEffect(()=>{s&&i&&x.current.set(s,{juan:i,rawText:l})},[s,i,l]),u.useEffect(()=>{x.current.clear(),h({})},[n]);const p=u.useCallback((b,y)=>{let g=0;if(b.juan)for(const v of b.juan.sections)Tt(v,y,a,d)&&g++;return g===0&&b.rawText&&Xr(b.rawText,y,d)&&(g=1),g},[a,d]);return u.useEffect(()=>{const b=c.trim();if(!b){h({});return}if(!n||!(o!=null&&o.getCollatedJuan)||r.length===0)return;let y=!1;const g={},v=[];for(const w of r){const k=x.current.get(w);k?g[w]=p(k,b):(g[w]="loading",v.push(w))}h(g);const m=8;let S=0;const _=async()=>{var w;for(;S<v.length;){if(y)return;const k=S++,I=v[k];try{const[E,z]=await Promise.all([o.getCollatedJuan(n,I),((w=o.getCollatedJuanText)==null?void 0:w.call(o,n,I))??Promise.resolve(null)]),C={juan:E,rawText:z};if(x.current.set(I,C),y)return;h(W=>({...W,[I]:p(C,b)}))}catch{if(y)return;h(E=>({...E,[I]:0}))}}},j=Array.from({length:Math.min(m,v.length)},()=>_());return Promise.all(j),()=>{y=!0}},[c,n,o,r.join(","),p,d]),{matchStates:f}}const Et=({index:t,workId:n,transport:o,onNavigate:r,activeJuan:s,onJuanChange:i,className:l,style:c})=>{const[a,d]=u.useState(null),[x,f]=u.useState(!1),[h,p]=u.useState(null),[b,y]=u.useState(null),[g,v]=u.useState(null),[m,S]=u.useState(!1),[_,j]=u.useState(null),[w,k]=u.useState(""),I=u.useRef(new Map),E=s??b,z=u.useCallback(L=>{y(L),i==null||i(L)},[i]),C=t||a;u.useEffect(()=>{t&&(f(!1),p(null))},[t]),u.useEffect(()=>{if(t||!n||!(o!=null&&o.getCollatedEditionIndex))return;let L=!1;return f(!0),p(null),o.getCollatedEditionIndex(n).then($=>{if(!L)if(!$)p("未找到整理本数据");else{d($);const Z=xn($);!s&&Z&&z(Z)}}).catch($=>{L||p($ instanceof Error?$.message:"加载失败")}).finally(()=>{L||f(!1)}),()=>{L=!0}},[t,n,o,s,z]),u.useEffect(()=>{const L=t||a;if(L&&!E){const $=xn(L);$&&z($)}},[t,a,E,z]);const W=n||(C==null?void 0:C.work_id),H=u.useCallback(async L=>{var $;if(!(!W||!(o!=null&&o.getCollatedJuan))){S(!0),v(null),j(null);try{const[Z,R]=await Promise.all([o.getCollatedJuan(W,L),(($=o.getCollatedJuanText)==null?void 0:$.call(o,W,L))??Promise.resolve(null)]);v(Z),j(R)}catch{v(null),j(null)}finally{S(!1)}}},[W,o]);u.useEffect(()=>{E&&H(E)},[E,H]);const B=L=>{z(L)};if(x)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(h)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:h});if(!C)return null;const A=C.type==="kaozhen",O=oo(C);return e.jsx(ui,{className:l,style:c,index:C,allFiles:O,isKaozhen:A,effectiveWorkId:W,transport:o,activeFile:E,handleSelectFile:B,juanData:g,juanRawText:_,juanLoading:m,searchQuery:w,setSearchQuery:k,onNavigate:r,workLabelCacheRef:I})},ui=({className:t,style:n,index:o,allFiles:r,isKaozhen:s,effectiveWorkId:i,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:x,juanLoading:f,searchQuery:h,setSearchQuery:p,onNavigate:b,workLabelCacheRef:y})=>{const{matchStates:g}=xi({workId:i,transport:l,files:r,activeFile:c,activeJuan:d,activeRawText:x,query:h,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:h,onChange:v=>p(v.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 v=Ur(o.text_quality.grade);return v?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Vr,{content:Mo[v],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Ho[v],cursor:"help"},children:Hn[v]})}),o.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",o.text_quality.source_note]})]}):null})()]}),e.jsx(ti,{files:r,groups:o.juan_groups,activeFile:c,onSelect:a,juanMeta:o.juan_metadata,matchStates:g}),f?e.jsx(Be,{}):d?s?e.jsx(ai,{juan:d,searchQuery:h,onNavigate:b,transport:l,workLabelCache:y}):e.jsx(pi,{juan:d,rawText:x,searchQuery:h,onNavigate:b}):c?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,o.references&&o.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),o.references.map((v,m)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[m+1,". "]}),v.url?e.jsx("a",{href:v.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:v.title}):e.jsx("span",{children:v.title}),v.author&&e.jsxs("span",{children:[",",v.author]}),v.note&&e.jsxs("span",{children:["。",v.note]})]},m))]})]})},fi={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},gi={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function hi(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 Lt=({items:t,loading:n})=>{const o=ke();return n?e.jsx(Be,{}):t.length===0?e.jsx("div",{style:bi,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=fi[r.type],i=gi[r.status];return e.jsxs("div",{style:mi,children:[e.jsxs("div",{style:yi,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...un,background:s.color},children:s.label}),e.jsx("span",{style:{...un,background:i.color},children:i.label})]}),e.jsx("span",{style:vi,children:hi(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:ji,children:[r.resourceId&&e.jsx("a",{href:o(r.resourceId),style:fn,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:fn,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:Si,children:r.content}),r.reply&&e.jsxs("div",{style:ki,children:[e.jsx("div",{style:wi,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},bi={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},mi={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},yi={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},un={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},vi={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},ji={fontSize:"12px",marginBottom:"6px"},fn={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},Si={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},ki={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},wi={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},kt=({transport:t,onNavigate:n,recommendedIds:o,activeTab:r,onTabChange:s,feedbackApiUrl:i})=>{const l=P(),[c,a]=u.useState(null),[d,x]=u.useState([]),[f,h]=u.useState("recommend"),[p,b]=u.useState([]),[y,g]=u.useState(!1),v=r??f,m=A=>{h(A),s==null||s(A)},[S,_]=u.useState(!0),[j,w]=u.useState(null),[k,I]=u.useState(null),[E,z]=u.useState(null);u.useEffect(()=>{let A=!1;if(t.getCounts)return t.getCounts().then(O=>{A||a({works:O.works,books:O.books,collections:O.collections})}).catch(()=>{}),()=>{A=!0}},[t]),u.useEffect(()=>{let A=!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($=>$.items.map(Z=>({...Z,group:$.name})))}catch{}return[]})().then(async L=>{if(A)return;const $=L.filter(R=>R.id);if($.length===0){_(!1);return}const Z=await Promise.all($.map(async R=>{if(R.type)return{id:R.id,title:R.title,type:R.type,author:R.author,dynasty:R.dynasty,role:R.role,edition:R.edition,has_text:R.has_text,has_image:R.has_image,has_collated:R.has_collated,subtype:R.subtype,primary_name:R.primary_name,group:R.group,fallbackDescription:R.description};try{let N=null;if(t.getEntry)N=await t.getEntry(R.id);else{const oe=await t.getItem(R.id);oe&&(N={id:R.id,title:oe.title||R.id,type:oe.type||"work"})}if(N)return{...N,group:R.group,fallbackDescription:R.description}}catch{}return{id:R.id,title:R.title,type:G.extractType(R.id),group:R.group,fallbackDescription:R.description}}));A||(x(Z.filter(R=>R!==null)),_(!1))}),()=>{A=!0}},[t,o]);const C=u.useRef(!1),W=u.useRef(!1),H=u.useRef(!1);u.useEffect(()=>{if(v!=="catalog"||C.current)return;const A=t.getCatalogProgress??t.getResourceProgress;if(!A)return;C.current=!0;let O=!1;return A.call(t).then(L=>{O||w(L)}).catch(()=>{C.current=!1}),()=>{O=!0}},[t,v]),u.useEffect(()=>{if(v!=="collection"||W.current||!t.getCollectionProgress)return;W.current=!0;let A=!1;return t.getCollectionProgress().then(O=>{A||I(O)}).catch(()=>{W.current=!1}),()=>{A=!0}},[t,v]),u.useEffect(()=>{if(v!=="site"||H.current||!t.getSiteProgress)return;H.current=!0;let A=!1;return t.getSiteProgress().then(O=>{A||z(O)}).catch(()=>{H.current=!1}),()=>{A=!0}},[t,v]),u.useEffect(()=>{if(!i||v!=="feedback")return;let A=!1;return g(!0),fetch(i).then(O=>O.json()).then(O=>{!A&&O.success&&b(O.items||[])}).catch(()=>{}).finally(()=>{A||g(!1)}),()=>{A=!0}},[i,v]);const B=A=>{switch(A){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(Ye,{label:l.home.recommendTab,active:v==="recommend",onClick:()=>m("recommend")}),e.jsx(Ye,{label:l.home.catalogTab,active:v==="catalog",onClick:()=>m("catalog")}),e.jsx(Ye,{label:l.home.collectionTab,active:v==="collection",onClick:()=>m("collection")}),e.jsx(Ye,{label:l.home.siteTab,active:v==="site",onClick:()=>m("site")}),i&&e.jsx(Ye,{label:l.home.feedbackTab,active:v==="feedback",onClick:()=>m("feedback")})]}),v==="recommend"&&e.jsx(_i,{recommended:d,loading:S,onNavigate:n,getIcon:B,t:l}),v==="catalog"&&e.jsx(gn,{progress:j,t:l,onNavigate:n}),v==="collection"&&e.jsx(gn,{progress:k,t:l,onNavigate:n}),v==="site"&&e.jsx(Ii,{progress:E,t:l,totalWorks:(c==null?void 0:c.works)??0}),v==="feedback"&&i&&e.jsx(Lt,{items:p,loading:y})]})})},Ye=({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}),_i=({recommended:t,loading:n,onNavigate:o,getIcon:r,t:s})=>{const i=ke();if(n)return e.jsx(Be,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const x=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:i(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),o==null||o(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:r(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),x&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x})]})]},d.id)})})]},c))})},gn=({progress:t,t:n,onNavigate:o})=>{if(!t)return e.jsx(Be,{});const r=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],i={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"var(--bim-progress-active, #f59e0b)",done:"var(--bim-progress-done, #10b981)",todo:"var(--bim-progress-todo, #9ca3af)"};return e.jsx("div",{children:s.map(c=>{const a=r.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),i[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Ci,{item:d,t:n,statusColor:l[c],onNavigate:o},d.id))})]},c)})})},Ci=({item:t,t:n,statusColor:o,onNavigate:r})=>{const s=ke(),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 c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&r?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?nt(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})]})},Ii=({progress:t,t:n,totalWorks:o})=>{if(!t)return e.jsx(Be,{});const r=[...t.resources].sort((a,d)=>a.priority-d.priority),s=r.filter(a=>a.imported>0),i=r.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=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," (",c,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-done, #10b981)"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>e.jsx(hn,{item:a,t:n,totalWorks:o},a.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:"var(--bim-progress-todo, #9ca3af)"}}),n.home.statusTodo," (",i.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:i.map(a=>e.jsx(hn,{item:a,t:n,totalWorks:o},a.id))})]})]})},hn=({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:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},bn="(max-width: 768px)";function zi(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(bn).matches);return u.useEffect(()=>{const o=window.matchMedia(bn),r=s=>n(s.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[]),t}const Ti=({transport:t,hideModeIndicator:n=!0,onEntryClick:o,recommendedIds:r,headerRight:s})=>{var O;const i=P(),{convert:l}=M(),c=zi(),[a,d]=u.useState(null),[x,f]=u.useState(null),[h,p]=u.useState(!1),[b,y]=u.useState("detail"),[g,v]=u.useState([]),[m,S]=u.useState(!1),[_,j]=u.useState(null),[w,k]=u.useState(!1),I=u.useCallback(async L=>{if(!t.getCollatedEditionIndex){j(null);return}k(!0);try{const $=await t.getCollatedEditionIndex(L);j($)}catch{j(null)}finally{k(!1)}},[t]),E=u.useCallback(async L=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){v([]);return}S(!0);try{if(t.getCollectionCatalogs){const $=await t.getCollectionCatalogs(L);v($||[])}else if(t.getCollectionCatalog){const $=await t.getCollectionCatalog(L);v($?[{resource_id:"",data:$}]:[])}}catch{v([])}finally{S(!1)}},[t]),z=u.useCallback(async L=>{if(o){o(L);return}d(L),f(null),v([]),j(null),y("detail"),p(!0);try{const $=await t.getItem(L.id);$&&(f($),$.type==="collection"?E(L.id):$.type==="work"&&$.has_collated&&I(L.id))}catch($){console.error("加载详情失败:",$)}finally{p(!1)}},[t,o,E,I]),C=u.useCallback(async L=>{f(null),v([]),j(null),y("detail"),p(!0);try{const $=await t.getItem(L);$&&(f($),d({id:L,title:$.title||L,type:$.type||"book"}),$.type==="collection"?E(L):$.type==="work"&&$.has_collated&&I(L))}catch($){console.error("导航失败:",$)}finally{p(!1)}},[t,E,I]),W=(x==null?void 0:x.type)==="collection"&&(g.length>0||m)||(x==null?void 0:x.type)==="work"&&(_||w),H=c&&(h||x),B=u.useCallback(()=>{d(null),f(null),v([]),j(null),y("detail")},[]),A=e.jsx(e.Fragment,{children:h?e.jsx(Be,{}):x?e.jsxs(e.Fragment,{children:[(W||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[W&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y("detail"),style:st(b==="detail"),children:i.detailTab.basicInfo}),x.type==="collection"&&m&&g.length===0&&e.jsxs("button",{onClick:()=>{},style:st(!1),children:[i.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),x.type==="collection"&&g.map(L=>e.jsx("button",{onClick:()=>y(`catalog:${L.resource_id}`),style:st(b===`catalog:${L.resource_id}`),children:L.short_name?`${l(L.short_name)}${i.detailTab.catalogSuffix}`:i.detailTab.collectionCatalog},L.resource_id)),x.type==="work"&&(_||w)&&e.jsxs("button",{onClick:()=>y("collated"),style:st(b==="collated"),children:[i.detailTab.collatedEdition,w&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(ut,{data:x,transport:t,onNavigate:C}):b.startsWith("catalog:")?e.jsx(It,{data:(O=g.find(L=>`catalog:${L.resource_id}`===b))==null?void 0:O.data,onNavigate:C}):b==="collated"?e.jsx(Et,{index:_||void 0,workId:x.id,transport:t,onNavigate:C}):null})]}):e.jsx(kt,{transport:t,onNavigate:C,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:H?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:B,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:A})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(jt,{transport:t,onEntryClick:z,hideModeIndicator:n}),!x&&e.jsx(kt,{transport:t,onNavigate:C,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(jt,{transport:t,onEntryClick:z,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:A})]})};function st(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Re(t){return t.replace(/\.md$/,"")}const ro=({index:t,bookId:n,transport:o,activeChapter:r,onChapterChange:s})=>{const[i,l]=u.useState(t??null),[c,a]=u.useState(null),d=r!==void 0?r:c,x=u.useCallback(g=>{s?s(g):a(g)},[s]),[f,h]=u.useState(null),[p,b]=u.useState(!1);u.useEffect(()=>{t&&l(t)},[t]),u.useEffect(()=>{if(t||!n||!o.getBookFullTextIndex)return;let g=!1;return o.getBookFullTextIndex(n).then(v=>{g||l(v)}),()=>{g=!0}},[n,o,t]),u.useEffect(()=>{if(!i||i.chapters.length===0)return;const g=Re(i.chapters[0].file);if(!d){x(g);return}const v=Re(d);i.chapters.some(S=>Re(S.file)===v)||x(g)},[i,d,x]);const y=u.useMemo(()=>{if(!i||!d)return null;const g=Re(d);return i.chapters.find(v=>Re(v.file)===g)??null},[i,d]);return u.useEffect(()=>{if(!n||!y||!o.getBookFullTextChapter)return;let g=!1;return b(!0),h(null),o.getBookFullTextChapter(n,y.file).then(v=>{g||h(v)}).catch(()=>{g||h(null)}).finally(()=>{g||b(!1)}),()=>{g=!0}},[n,y,o]),i?i.chapters.length===0?e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"}):e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"stretch",minHeight:400},children:[e.jsxs("aside",{style:{flex:"0 0 240px",maxHeight:"calc(100vh - 200px)",overflowY:"auto",borderRight:"1px solid var(--bim-border, #e5e5e5)",paddingRight:12},children:[e.jsxs("div",{style:{padding:"8px 12px",fontSize:13,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:[i.version_label," · 共 ",i.total_chapters," ",(i.chapters.length===1,"章")]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:i.chapters.map(g=>{const v=Re(g.file),m=v===Re(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>x(v),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:m?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:m?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:m?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:g.title})},g.file)})})]}),e.jsxs("main",{style:{flex:1,maxHeight:"calc(100vh - 200px)",overflowY:"auto",paddingLeft:8},children:[y&&e.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[e.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:y.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:i.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:i.source.name}),i.source.license&&e.jsxs(e.Fragment,{children:[" · ",i.source.license]})]})]}),p&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!p&&f&&e.jsx("article",{style:{fontSize:16,lineHeight:1.9,color:"var(--bim-fg, #2c2c2c)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:'"Songti SC", "Source Han Serif", "Noto Serif CJK SC", serif'},children:f.replace(/^##\s+[^\n]+\n+/,"")}),!p&&!f&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},Ri=({data:t,onNavigate:n,className:o,style:r})=>{var x;const s=P(),{convert:i}=M(),[l,c]=u.useState(((x=t.divisions[0])==null?void 0:x.name)??null),[a,d]=u.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(f=>e.jsx(Ei,{division:f,expanded:l===f.name,onToggle:()=>c(l===f.name?null:f.name),expandedCat:a,onCatToggle:h=>d(a===h?null:h),onNavigate:n},f.name))})]})},Ei=({division:t,expanded:n,onToggle:o,expandedCat:r,onCatToggle:s,onNavigate:i})=>{const{convert:l}=M(),c=t.categories.reduce((a,d)=>{const x=d.stats||{zhulu:0,cunmu:0};return a+(x.zhulu||0)+(x.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," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(Li,{category:a,expanded:r===d,onToggle:()=>s(d),onNavigate:i},a.name)})})]})},Li=({category:t,expanded:n,onToggle:o,onNavigate:r})=>{var a,d,x,f;const{convert:s}=M(),i=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((x=t.stats)==null?void 0:x.zhulu)||i.length)+(((f=t.stats)==null?void 0:f.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:[c," 部 ",n?"▲":"▼"]})]}),n&&(i.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[i.length>0&&e.jsx(mn,{label:"著錄",books:i,onNavigate:r}),l.length>0&&e.jsx(mn,{label:"存目",books:l,onNavigate:r})]})]})},mn=({label:t,books:n,onNavigate:o})=>{const{convert:r}=M(),s=ke(),[i,l]=u.useState(n.length<=20),c=i?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&o?e.jsx("a",{href:s(a.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),o(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(a.title)}):r(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(a.author).slice(0,20)})]},d))}),!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," 條"]})]})},je=({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:Wi,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Bi,children:i.action.save})]})]}),s]})},Bi={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Wi={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ge=({label:t,value:n,onChange: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"}})]}),Le=({value:t,onChange:n,placeholder:o})=>{const r=u.useRef(null);return u.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"}})},pt=({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 $i(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const at=({value:t,onChange:n,label:o})=>{const[r,s]=u.useState(!1),i=u.useRef(null),l=$i(t||"");return u.useEffect(()=>{r&&i.current&&i.current.focus()},[r]),!r&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:yn,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(pt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:yn,children:o}),e.jsx("input",{ref:i,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},yn={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Ai(t){switch(t){case"url":return"var(--bim-source-url, #2196f3)";case"bookID":return"var(--bim-source-bookid, #4caf50)";default:return"var(--bim-desc-fg, #717171)"}}function Fi(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const io=({items:t,onChange:n,onOpenEntityPicker:o})=>{const r=P(),[s,i]=u.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),i(t.length)},c=f=>{n(t.filter((h,p)=>p!==f)),s===f&&i(null)},a=(f,h,p)=>{const b=[...t];b[f]={...b[f],[h]:p},n(b)},d=(f,h)=>{const p=[...t];p[f]={...p[f],type:h,id:"",name:""},n(p),h==="bookID"&&o&&o(b=>{const y=[...t];y[f]={...y[f],id:b.id,name:b.title,type:"bookID"},n(y)})},x=f=>{o&&o(h=>{const p=[...t];p[f]={...p[f],id:h.id,name:h.title,type:"bookID"},n(p)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,h)=>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===h?null:h),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===h?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:f.name||`${r.editor.sourcePlaceholder} ${h+1}`}),f.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ai(f.type),color:"white",borderRadius:"3px",fontWeight:500},children:Fi(f.type)}),e.jsx("button",{onClick:p=>{p.stopPropagation(),c(h)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisSource,children:"✕"})]}),s===h&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&e.jsxs("div",{children:[e.jsx("label",{style:Ce,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(h,"bookID"),style:{...vn,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(h,"url"),style:{...vn,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),f.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:Ce,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:jn,children:r.action.changeType})]}),f.id&&f.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-source-bookid, #4caf50)",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"var(--bim-source-bookid, #4caf50)",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:f.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),e.jsx("button",{onClick:()=>x(h),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:()=>x(h),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})]})]})}),f.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:Ce,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const p=[...t];p[h]={...p[h],type:"",id:"",name:""},n(p)},style:jn,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:f.name,onChange:p=>a(h,"name",p.target.value),placeholder:r.editor.sourceNamePlaceholder,style:Pe})]}),e.jsxs("div",{children:[e.jsx("label",{style:Ce,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:f.id,onChange:p=>a(h,"id",p.target.value),placeholder:"https://...",style:Pe})]})]}),f.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...Ce,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:Ce,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:f.details,onChange:p=>a(h,"details",p.target.value),placeholder:r.editor.detailsPlaceholder,style:Pe})]}),e.jsxs("div",{children:[e.jsx("label",{style:Ce,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:f.position,onChange:p=>a(h,"position",p.target.value),placeholder:"如: 卷三, p.52",style:Pe})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Ce,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:f.version,onChange:p=>a(h,"version",p.target.value),placeholder:"如: v1.0, 2024-01",style:Pe})]}),e.jsxs("div",{children:[e.jsx("label",{style:Ce,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:f.processor_version,onChange:p=>a(h,"processor_version",p.target.value),placeholder:"如: v0.1",style:Pe})]})]})]})]})})]},h)),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})]})]})},Ce={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},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"},vn={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"},jn={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function so(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 lo(t){return!t||t.length===0?"":JSON.stringify(t)}const ao=({entityType:t,entityId:n,entityTitle:o,parentWork:r,parentCollection:s,belongsToWork:i,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:x,onLinkEntity:f,onUnlinkEntity:h,onViewEntity:p,onCreateAndLink:b,onSaveRelations:y})=>{const g=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:g.section.relations})]}),y&&e.jsx("button",{onClick:y,style:Pi,children:g.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{direction:"up",title:g.relation.belongsToWork,entity:i,onView:p,onUnlink:()=>h("workId"),onLink:()=>f("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ke,{direction:"up",title:g.relation.containedInCollection,entity:l,onView:p,onUnlink:()=>h("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),i&&x&&x.length>0&&e.jsx(Me,{direction:"horizontal",title:`${g.relation.siblingVersions} (${x.length})`,entities:x,onView:p,onAdd:()=>b("siblingBook","book",{workId:i.id}),addLabel:g.relation.addVersionForWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{direction:"up",title:g.relation.parentWork,entity:r,onView:p,onUnlink:()=>h("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),c&&c.length>0&&e.jsx(Me,{direction:"down",title:`${g.relation.childWorks} (${c.length})`,entities:c,onView:p,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:g.action.addSubWork,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),a&&a.length>0&&e.jsx(Me,{direction:"down",title:`${g.relation.collectionImpl} (${a.length})`,entities:a,onView:p,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:g.action.addCollectionImpl,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(Me,{direction:"down",title:`${g.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>b("childBook","book",{workId:n}),addLabel:g.action.addVersion,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{direction:"up",title:g.relation.correspondingWork,entity:i,onView:p,onUnlink:()=>h("workId"),onLink:()=>f("workId","work"),onCreate:()=>b("workId","work",{title:o}),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Ke,{direction:"up",title:g.relation.parentCollection,entity:s,onView:p,onUnlink:()=>h("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:g.action.linkExisting,createLabel:g.action.createAndLink,notLinkedLabel:g.relation.notLinked,viewLabel:g.action.viewEntity,unlinkLabel:g.action.unlink}),e.jsx(Me,{direction:"down",title:`${g.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:p,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:g.action.addSubCollection,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore}),e.jsx(Me,{direction:"down",title:`${g.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:p,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:g.action.addBook,noneLabel:g.relation.none,expandMoreLabel:g.action.expandMore})]})]})]})},Ke=({direction:t,title:n,entity:o,onView:r,onUnlink:s,onLink:i,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:x,unlinkLabel:f})=>{const h=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",p=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:h,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:p}),e.jsx("span",{children:n})]}),o?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:co(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(Sn,{onClick:()=>r(o),title:x,children:"👁️"}),e.jsx(Sn,{onClick:s,title:f,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(wt,{onClick:i,children:c}),e.jsx(wt,{onClick:l,primary:!0,children:a})]})]})},Me=({direction:t,title:n,entities:o,onView:r,onAdd:s,addLabel:i,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=u.useState(!1),x=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",h=a?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:x,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),o.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[h.map(p=>e.jsxs("div",{onClick:()=>r(p),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:co(p.type)}),e.jsx("span",{children:p.title})]},p.id)),o.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",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(wt,{onClick:s,primary:!0,children:["+ ",i]})})]})},Sn=({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}),wt=({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 co(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Pi={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"},po=({isOpen:t,entityType:n,title:o,onSelect:r,onCancel:s,onCreate:i,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[x,f]=u.useState(""),h=d?l.filter(g=>g.id!==d):l;u.useEffect(()=>{t&&(f(""),c(""))},[t]);const p=g=>{f(g),c(g)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Mi,children:e.jsxs("div",{style:Hi,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:Oi,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:x,onChange:g=>p(g.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Di})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:bt,children:"搜索中..."}):h.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:h.map(g=>e.jsxs("div",{onClick:()=>r(g),style:Ni,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[g.title,g.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:g.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[g.id,g.author&&` · ${g.author}`,g.dynasty&&` · ${g.dynasty}`]})]})]},g.id))}):x?e.jsxs("div",{style:bt,children:["未找到匹配的",b]}):e.jsxs("div",{style:bt,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:Vi,children:["创建新",b,"并关联"]})]})]})})},Mi={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",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},Oi={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Di={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"},Ni={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},bt={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Vi={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},kn={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Ui={work:"📜",book:"📖",collection:"📚",entity:"👤"},xo=({isOpen:t,entityType:n,relationField:o,inheritData:r,onConfirm:s,onCancel:i})=>{const[l,c]=u.useState(""),a=u.useRef(null);u.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var h,p;(h=a.current)==null||h.focus(),(p=a.current)==null||p.select()},100))},[t,r==null?void 0:r.title]);const d=h=>{h.key==="Enter"&&l.trim()?x():h.key==="Escape"&&i()},x=()=>{l.trim()&&s(l.trim(),{...r,title:l.trim()})};if(!t)return null;const f=()=>{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`创建新${kn[n]}`}};return e.jsx("div",{style:Gi,onClick:h=>{h.target===h.currentTarget&&i()},children:e.jsxs("div",{style:Yi,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Ui[n]}),e.jsx("span",{children:f()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:h=>c(h.target.value),onKeyDown:d,placeholder:`请输入${kn[n]}名称...`,style:Ki})]}),((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:Ji,children:"取消"}),e.jsx("button",{onClick:x,disabled:!l.trim(),style:{...qi,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},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},Yi={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)"},Ki={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"},Ji={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},qi={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Xi(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function uo(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Zi(t){switch(t){case"work":return"var(--bim-editor-type-work, #4caf50)";case"collection":return"var(--bim-editor-type-collection, #2196f3)";case"book":return"var(--bim-editor-type-book, #ff9800)";default:return"var(--bim-desc-fg, #717171)"}}const fo=({isOpen:t,title:n,filterType:o="all",recentEntities:r=[],excludeId:s,showCreateButton:i=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:x})=>{const[f,h]=u.useState(""),[p,b]=u.useState([]),[y,g]=u.useState(!1),[v,m]=u.useState("recent");u.useEffect(()=>{t&&(h(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),u.useEffect(()=>{if(!f.trim()){b([]);return}const I=setTimeout(async()=>{g(!0);try{b(await x(f,o))}catch{b([])}finally{g(!1)}},300);return()=>clearTimeout(I)},[f,o,x]);const S=u.useCallback(I=>{h(I.target.value),I.target.value.trim()&&m("search")},[]),_=u.useCallback(I=>s?I.filter(E=>E.id!==s):I,[s]);if(!t)return null;const j=n||(o==="all"?"选择实体":`选择${uo(o)}`),w=_(r),k=_(p);return e.jsx("div",{style:es,children:e.jsxs("div",{style:ts,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:j}),e.jsx("button",{onClick:a,style:ns,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:f,onChange:S,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:os}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),w.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(wn,{active:v==="recent",onClick:()=>m("recent"),children:["最近使用 (",w.length,")"]}),e.jsxs(wn,{active:v==="search",onClick:()=>m("search"),children:["搜索结果 ",k.length>0&&`(${k.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:v==="recent"&&w.length>0?e.jsx(_n,{entities:w,onSelect:c}):f.trim()?y?e.jsx(mt,{message:"搜索中..."}):k.length>0?e.jsx(_n,{entities:k,onSelect:c}):e.jsx(mt,{message:"未找到匹配的结果"}):e.jsx(mt,{message:"输入关键词开始搜索"})}),i&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:rs,children:l||"创建新实体"})]})]})})},wn=({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}),_n=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(o=>e.jsx(Qi,{entity:o,onClick:()=>n(o)},o.id))}),Qi=({entity:t,onClick:n})=>{const[o,r]=u.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:Xi(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:Zi(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:uo(t.type)})]})},mt=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),es={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},ts={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)"},ns={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},os={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"},rs={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},is={work:"var(--bim-editor-type-work, #4caf50)",collection:"var(--bim-editor-type-collection, #2196f3)",book:"var(--bim-editor-type-book, #ff9800)",entity:"var(--bim-editor-type-entity, #9c27b0)"},ss={work:"📜",collection:"📚",book:"📖",entity:"👤"},go=({data:t,onChange:n,onSave:o,transport:r,onNavigate:s,showDelete:i,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:x,relations:f,onRelationsChange:h})=>{var J;const p=P(),[b,y]=u.useState(!1),[g,v]=u.useState("work"),[m,S]=u.useState(""),[_,j]=u.useState(""),[w,k]=u.useState([]),[I,E]=u.useState(!1),[z,C]=u.useState(!1),[W,H]=u.useState("work"),[B,A]=u.useState(""),[O,L]=u.useState(),[$,Z]=u.useState(!1),[R,N]=u.useState(null),[oe,K]=u.useState([]);u.useRef(null);const ee=t.type,re=ee==="work",le=ee==="collection",U=ee==="book",q=u.useCallback((T,Y)=>{n({...t,[T]:Y})},[t,n]),xe=u.useCallback((T,Y)=>{S(T),v(Y),j(p.editor.selectToLink+p.indexType[Y]),k([]),y(!0)},[p]),We=u.useCallback(T=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,T)},[r,t.id]),$e=u.useCallback(T=>{s==null||s(T.id,T.type)},[s]),he=u.useCallback((T,Y,ne)=>{const te={...ne,author:(ne==null?void 0:ne.author)||t.author,dynasty:(ne==null?void 0:ne.dynasty)||t.dynasty};H(Y),A(T),L(te),C(!0)},[t.author,t.dynasty]),be=u.useCallback((T,Y)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,B,{type:W,title:T,inheritData:Y}),C(!1)},[r,t.id,B,W]),ze=u.useCallback(T=>{if(!T.trim()){k([]);return}E(!0),r!=null&&r.searchEntities&&r.searchEntities(T,g).then(Y=>{k(Y),E(!1)}).catch(()=>{k([]),E(!1)})},[r,g]),Ae=u.useCallback(T=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,T.id),y(!1)},[r,t.id,m]),me=u.useCallback(()=>{o()},[o]),De=u.useCallback(T=>{N(()=>T),Z(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(K).catch(()=>{})},[r]),F=u.useCallback((T,Y)=>r!=null&&r.searchEntities?r.searchEntities(T,Y==="all"?void 0:Y):Promise.resolve([]),[r]),Q=u.useCallback(T=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(T),K(Y=>[T,...Y.filter(ne=>ne.id!==T.id)].slice(0,10)),R==null||R(T),Z(!1),N(null)},[r,R]);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:ss[ee]}),e.jsx("span",{children:t.title||p.editor.untitled}),e.jsx(pt,{children:t.id}),e.jsx(pt,{color:is[ee],children:p.indexType[ee]})]})}),e.jsx(je,{title:p.section.basicInfo,onSave:o,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(at,{label:re?p.editor.workTitle:le?p.editor.collectionTitle:p.editor.bookTitle,value:t.title,onChange:T=>q("title",T)}),U&&e.jsx(at,{label:p.editor.belongsToWork,value:t.workName||"",onChange:T=>q("workName",T)}),e.jsx(ge,{label:p.editor.authorLabel,value:t.author||"",onChange:T=>q("author",T)}),e.jsx(ge,{label:p.editor.dynastyLabel,value:t.dynasty||"",onChange:T=>q("dynasty",T)}),(U||le)&&e.jsx(at,{label:p.editor.containedIn,value:t.collection||"",onChange:T=>q("collection",T)}),(U||le)&&e.jsx(ge,{label:p.editor.holderLabel,value:t.holder||"",onChange:T=>q("holder",T)}),(U||le)&&e.jsx(ge,{label:U?p.editor.pageLabel:p.editor.volumeLabel,value:t.pages||"",onChange:T=>q("pages",T)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ge,{label:p.editor.firstImageLabel,value:t.firstImage||"",onChange:T=>q("firstImage",T)})})]})}),e.jsx(je,{title:p.section.description,onSave:o,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Le,{value:t.description||"",onChange:T=>q("description",T),placeholder:p.editor.descriptionPlaceholder})}),(((J=t.additional_works)==null?void 0:J.length)||0)>0&&e.jsx(je,{title:p.section.additionalWorks,onSave:o,children:e.jsx(ls,{items:t.additional_works||[],onChange:T=>q("additional_works",T)})}),e.jsx(je,{title:p.section.indexedBy,onSave:o,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(as,{items:t.indexed_by||[],onChange:T=>q("indexed_by",T)})}),e.jsx(je,{title:p.section.emendatedBy,onSave:o,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(cs,{items:t.emendated_by||[],onChange:T=>q("emendated_by",T)})}),e.jsx(je,{title:p.section.textResources,onSave:o,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(vt,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:d,downloadStatuses:x,filterType:"text"})}),e.jsx(je,{title:p.section.imageResources,onSave:o,children:e.jsx(vt,{items:t.resources||[],onChange:T=>q("resources",T),onDownload:d,downloadStatuses:x,filterType:"image"})}),e.jsx(je,{title:p.section.sources,onSave:o,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(io,{items:so(t.sources||""),onChange:T=>q("sources",lo(T)),onOpenEntityPicker:De})}),(U||le)&&e.jsx(je,{title:p.section.provenance,onSave:o,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Le,{value:t.provenance||"",onChange:T=>q("provenance",T),placeholder:p.editor.provenancePlaceholder})}),U&&e.jsx(je,{title:p.section.otherEditions,onSave:o,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Le,{value:t.otherEditions||"",onChange:T=>q("otherEditions",T),placeholder:p.editor.otherEditionsPlaceholder})}),e.jsx(ao,{entityType:ee,entityId:t.id,entityTitle:t.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:xe,onUnlinkEntity:We,onViewEntity:$e,onCreateAndLink:he,onSaveRelations:me}),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:p.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:p.editor.dangerZoneDesc}),e.jsx("button",{onClick: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:p.editor.deleteEntity})]}),e.jsx(po,{isOpen:b,entityType:g,title:_,onSelect:Ae,onCancel:()=>y(!1),onCreate:()=>{y(!1),he(m,g)},searchResults:w,onSearch:ze,isLoading:I,excludeId:t.id}),e.jsx(xo,{isOpen:z,entityType:W,relationField:B,inheritData:O,onConfirm:be,onCancel:()=>C(!1)}),e.jsx(fo,{isOpen:$,title:p.action.selectBookOrWork,filterType:"all",recentEntities:oe,excludeId:t.id,onSelect:Q,onCancel:()=>{Z(!1),N(null)},onSearch:F})]})};function ls({items:t,onChange:n}){const o=P(),r=(l,c,a)=>{const d=t.map((x,f)=>f===l?{...x,[c]:a}:x);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),i=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ge,{label:o.editor.bookNameLabel,value:l.book_title,onChange:a=>r(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ge,{label:o.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>r(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:i,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:o.action.addAdditionalWork})]})}function ho({items:t,onChange:n,showMeta:o,addLabel:r}){const s=P(),[i,l]=u.useState(null),c=(x,f,h)=>{const p=t.map((b,y)=>y===x?{...b,[f]:h||void 0}:b);n(p)},a=x=>{n(t.filter((f,h)=>h!==x)),i===x&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,f)=>{const h=i===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:h?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(h?null:f),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:h?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:x.source||s.editor.unnamedSource}),x.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:x.source_bid}),e.jsx("button",{onClick:p=>{p.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)"},children:"✕"})]}),!h&&o&&(x.title_info||x.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[x.title_info,x.title_info&&x.author_info&&" — ",x.author_info]}),h&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ge,{label:s.label.sourceName,value:x.source,onChange:p=>c(f,"source",p)}),e.jsx(ge,{label:s.label.sourceBid,value:x.source_bid||"",onChange:p=>c(f,"source_bid",p)})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ge,{label:s.label.titleInfo,value:x.title_info||"",onChange:p=>c(f,"title_info",p)}),e.jsx(ge,{label:s.label.authorInfo,value:x.author_info||"",onChange:p=>c(f,"author_info",p)})]}),e.jsx(ge,{label:s.label.edition,value:x.edition||"",onChange:p=>c(f,"edition",p)})]}),e.jsx(Le,{value:x.summary||"",onChange:p=>c(f,"summary",p),placeholder:s.editor.summaryPlaceholder}),e.jsx(Le,{value:x.comment||"",onChange:p=>c(f,"comment",p),placeholder:s.editor.commentPlaceholder}),e.jsx(Le,{value:x.additional_comment||"",onChange:p=>c(f,"additional_comment",p),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:r})]})}function as({items:t,onChange:n}){const o=P();return e.jsx(ho,{items:t,onChange:n,showMeta:!0,addLabel:o.action.addIndexedBy})}function cs({items:t,onChange:n}){const o=P();return e.jsx(ho,{items:t,onChange:n,addLabel:o.action.addEmendatedBy})}function bo(t){var c,a,d,x,f,h,p;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",o=((d=t.publication_info)==null?void 0:d.year)||"",r=((x=t.current_location)==null?void 0:x.name)||"",s=(f=t.page_count)!=null&&f.number?String(t.page_count.number):((h=t.page_count)==null?void 0:h.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 y=b.related_works.find(g=>g.relation==="part_of");y&&(l.parentWorkId=y.id,l.parentWorkName=y.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=(p=b.contained_in[0])==null?void 0:p.id)}return l}function ds(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 ps=t=>{const{data:n,id:o,transport:r,mode:s="view",onModeChange:i,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:x,onAskAI:f,renderSectionActions:h,onDownloadResource:p,downloadStatuses:b,relations:y,onRelationsChange:g,headerExtra:v,className:m,style:S}=t;P();const[_,j]=u.useState(s),w=i?s:_;u.useEffect(()=>{s!==_&&j(s)},[s]);const k=u.useCallback(()=>{const B=w==="view"?"edit":"view";i?i(B):j(B)},[w,i]),[I,E]=u.useState(null);u.useEffect(()=>{o&&r&&r.getItem(o).then(B=>{B&&E(B)})},[o,r]);const z=n||I,C=u.useMemo(()=>z?bo(z):null,[z]),W=i||!n?e.jsx("button",{onClick:k,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:w==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:w==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:w==="view"?"切换到编辑模式":"切换到查看模式",children:w==="view"?"✏️ 编辑":"👁 查看"}):null,H=e.jsxs(e.Fragment,{children:[W,v]});return!z&&!C?e.jsx(Be,{}):w==="view"?e.jsx(ut,{data:z,transport:r,onNavigate:d?B=>d(B):void 0,renderLink:x,headerExtra:H,className:m,style:S}):C?e.jsxs("div",{className:m,style:S,children:[H&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:H}),e.jsx(go,{data:C,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:h,onDownloadResource:p,downloadStatuses:b,relations:y,onRelationsChange:g})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},Cn=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],mo=({isOpen:t,onClose:n,onSubmit:o,feedbackListUrl:r})=>{const[s,i]=u.useState(null),[l,c]=u.useState(""),[a,d]=u.useState("idle"),[x,f]=u.useState(""),h=u.useRef(null);u.useEffect(()=>{t&&(i(null),c(""),d("idle"),f(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var g;return(g=h.current)==null?void 0:g.focus()},100)},[s]),u.useEffect(()=>{if(a==="success"){const g=setTimeout(n,2e3);return()=>clearTimeout(g)}},[a,n]),u.useEffect(()=>{if(!t)return;const g=v=>{v.key==="Escape"&&n()};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n]);const p=async()=>{if(!(!s||!l.trim())){d("submitting"),f("");try{await o({type:s,content:l.trim()}),d("success")}catch(g){d("error"),f(g instanceof Error?g.message:"提交失败,请稍后重试")}}};if(!t)return null;const b=s&&l.trim()&&a!=="submitting",y=Cn.find(g=>g.value===s);return e.jsx("div",{style:xs,onClick:g=>{g.target===g.currentTarget&&n()},children:e.jsxs("div",{style:us,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:fs,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:gs,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:vs,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:Cn.map(g=>e.jsxs("button",{onClick:()=>i(g.value),style:{...hs,...s===g.value?bs:{}},children:[e.jsx("span",{children:g.icon})," ",g.label]},g.value))}),e.jsx("textarea",{ref:h,value:l,onChange:g=>c(g.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...ms,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),a==="error"&&e.jsx("div",{style:js,children:x}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:p,disabled:!b,style:{...ys,opacity:b?1:.6,cursor:b?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},xs={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},us={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)"},fs={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},gs={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},hs={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"},bs={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ms={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"},ys={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},vs={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},js={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Ss=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:o})=>{const[r,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...ks,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(mo,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:o})]})},ks={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"},In=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],yo=({onSubmit:t})=>{const[n,o]=u.useState("bug"),[r,s]=u.useState(""),[i,l]=u.useState("idle"),[c,a]=u.useState(""),d=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var p;return(p=d.current)==null?void 0:p.focus()},100)},[n]);const x=async()=>{if(!(!n||!r.trim())){l("submitting"),a("");try{await t({type:n,content:r.trim()}),l("success"),s(""),o("bug")}catch(p){l("error"),a(p instanceof Error?p.message:"提交失败,请稍后重试")}}},f=n&&r.trim()&&i!=="submitting",h=In.find(p=>p.value===n);return i==="success"?e.jsx("div",{style:zn,children:e.jsxs("div",{style:zs,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Ts,children:"继续提交"})]})}):e.jsxs("div",{style:zn,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:In.map(p=>e.jsxs("button",{onClick:()=>o(p.value),style:{...ws,...n===p.value?_s:{}},children:[e.jsx("span",{children:p.icon})," ",p.label]},p.value))}),e.jsx("textarea",{ref:d,value:r,onChange:p=>s(p.target.value),placeholder:(h==null?void 0:h.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:i==="submitting",style:{...Cs}}),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:x,disabled:!f,style:{...Is,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:i==="submitting"?"提交中...":"提交"})]}),i==="error"&&e.jsx("div",{style:Rs,children:c})]})},zn={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},ws={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"},_s={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Cs={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"},Is={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},zs={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Ts={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Rs={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function Tn(t){return typeof t=="function"?t():t??"/api/feedback"}const vo=({resourceId:t,apiUrl:n})=>{const[o,r]=u.useState([]),[s,i]=u.useState(!0),l=u.useCallback(async()=>{const a=Tn(n);i(!0);try{const x=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();x.success&&r(x.items)}catch{}finally{i(!1)}},[t,n]);u.useEffect(()=>{l()},[l]);const c=async a=>{const d=Tn(n),x=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!x.ok){const f=await x.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(Lt,{items:o,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(yo,{onSubmit:c})})]})};function Es(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function Ls(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 Rn(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 Bs(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 Ws(t,n){var d;if(n==="all")return null;const o=(d=t.collections)==null?void 0:d[n],r=Array.isArray(o==null?void 0:o.groups)&&o.groups.length>0,s=Array.isArray(o==null?void 0:o.book_ids)&&o.book_ids.length>0,i=r||s||!!(o!=null&&o.hypothetical_ids);if(!i&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!o||!i)return null;const l=r?new Set(o.groups):null,c=new Set(o.book_ids??[]);if(l&&t.node_groups)for(const[x,f]of Object.entries(t.node_groups))l.has(f)&&c.add(x);let a=null;if(o.hypothetical_ids&&(a=new Set(o.hypothetical_ids)),l){a||(a=new Set);for(const x of t.hypothetical_nodes??[])x.group&&l.has(x.group)&&a.add(x.id)}return{books:c,hypos:a}}function ct(t,n,o){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const i=new Set(r.excluded_books??[]),l=r.node_groups??{},c=Ws(r,o??r.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,x=(c==null?void 0:c.hypos)??null,f=new Set,h=new Set;if(a){const _=new Map(n.map(z=>[z.id,z])),j=new Map((r.hypothetical_nodes??[]).map(z=>[z.id,z])),w=z=>{const C=_.get(z);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(H=>H.ref);const W=j.get(z);return W?(W.derived_from??[]).map(H=>H.ref):[]},k=z=>j.has(z)?!x||x.has(z):!d||d.has(z),I=new Set,E=z=>{if(!I.has(z)){I.add(z);for(const C of w(z))i.has(C)||(k(C)||(j.has(C)?h.add(C):_.has(C)&&f.add(C)),E(C))}};for(const z of n)d&&d.has(z.id)&&!i.has(z.id)&&E(z.id);for(const z of r.hypothetical_nodes??[])x&&x.has(z.id)&&E(z.id)}const p=n.filter(_=>!i.has(_.id)).filter(_=>!d||d.has(_.id)||f.has(_.id)).map(_=>{const j=Ls(_,l);return j&&f.has(_.id)&&(j.bridge=!0),j}).filter(_=>_!==null),b=(r.hypothetical_nodes??[]).filter(_=>!x||x.has(_.id)||h.has(_.id)).map(_=>{const j=Es(_);return h.has(_.id)&&(j.bridge=!0),j}),y=[...p,...b],g=new Set(y.map(_=>_.id)),v=new Set,m=[],S=_=>{v.has(_.id)||!g.has(_.source)||!g.has(_.target)||(v.add(_.id),m.push(_))};for(const _ of n)i.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!f.has(_.id)||((_.lineage.derived_from??[]).forEach((j,w)=>{S(Rn(_.id,j,w))}),(_.lineage.related_to??[]).forEach((j,w)=>{S(Bs(_.id,j,w))}));for(const _ of r.hypothetical_nodes??[])x&&!x.has(_.id)&&!h.has(_.id)||(_.derived_from??[]).forEach((j,w)=>{S(Rn(_.id,j,w))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(i)}}function jo(t,n,o){const r=(t??(n!=null?String(n):"")).trim();return r?!o||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function $s(t,n){const o=[],r=t.version_graph;if(!r)return o;const s=new Set(n.map(a=>a.id)),i=new Set((r.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...i]),c=(a,d)=>{l.has(d.ref)||o.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!i.has(d.ref)&&o.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(x=>c(d,x)),(a.lineage.related_to??[]).forEach(x=>{s.has(x.book_id)||o.push(`${d}: related_to.book_id "${x.book_id}" 不在 books 列表中`)})}for(const a of r.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(x=>c(d,x))}return o}const So=({graph:t,renderLink:n,className:o,style:r})=>{const{convert:s}=M();if(!t.nodes.length)return e.jsx("div",{style:{...Js,...r},className:o,children:"暂无版本图数据"});const i=new Map,l=new Map;for(const h of t.edges)if(h.kind==="derive"){const p=i.get(h.target)??[];p.push(h),i.set(h.target,p)}else for(const p of[h.source,h.target]){const b=l.get(p)??[];b.push(h),l.set(p,b)}const c=new Map(t.nodes.map(h=>[h.id,h])),a=new Map,d=[];for(const h of t.nodes)if(h.group){const p=a.get(h.group)??[];p.push(h),a.set(h.group,p)}else d.push(h);const x=(h,p)=>(h.year??9999)-(p.year??9999);a.forEach(h=>h.sort(x)),d.sort(x);const f=t.groups.filter(h=>a.has(h.id));return e.jsxs("div",{className:o,style:{...Fs,...r},children:[t.title&&e.jsx("div",{style:Ps,children:s(t.title)}),t.description&&e.jsx("div",{style:Ms,children:s(t.description)}),f.map(h=>e.jsx(En,{label:h.label,color:h.color,nodes:a.get(h.id),incomingMap:i,siblingMap:l,nodeMap:c,renderLink:n},h.id)),d.length>0&&e.jsx(En,{label:"其他",nodes:d,incomingMap:i,siblingMap:l,nodeMap:c,renderLink:n})]})},En=({label:t,color:n,nodes:o,incomingMap:r,siblingMap:s,nodeMap:i,renderLink:l})=>{const{convert:c}=M();return e.jsxs("div",{style:Hs,children:[e.jsx("div",{style:{...Os,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),o.map(a=>e.jsx(As,{node:a,incoming:r.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:i,renderLink:l},a.id))]})},As=({node:t,incoming:n,siblings:o,nodeMap:r,renderLink:s})=>{const i=t.kind==="hypothetical",l=t.bridge,{convert:c}=M();return e.jsxs("div",{style:{...Ds,borderStyle:i||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Ns,children:[e.jsx("span",{style:Vs,children:i||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:Us,children:jo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Gs,children:[t.category&&e.jsx(Je,{children:c(t.category)}),t.status==="lost"&&e.jsx(Je,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(Je,{tone:"warn",children:"残本"}),i&&e.jsx(Je,{tone:"info",children:"假想祖本"}),l&&e.jsx(Je,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Ys,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Ks,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Bn,children:[e.jsx("div",{style:Wn,children:"来源:"}),n.map(a=>{const d=r.get(a.source);return e.jsxs("div",{style:$n(a.confidence),children:[e.jsx("span",{style:An,children:c(a.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&e.jsx(Ln,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Fn,children:["· ",c(a.evidence)]})]},a.id)})]}),o.length>0&&e.jsxs("div",{style:Bn,children:[e.jsx("div",{style:Wn,children:"关联:"}),o.map(a=>{const d=a.source===t.id?a.target:a.source,x=r.get(d);return e.jsxs("div",{style:$n(a.confidence),children:[e.jsx("span",{style:An,children:c(a.relation)}),e.jsx("span",{children:(x==null?void 0:x.kind)==="book"&&s?s(x.id,c(x.label)):c((x==null?void 0:x.label)??d)}),e.jsx(Ln,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:Fn,children:["· ",c(a.evidence)]})]},a.id)})]})]})},Je=({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})},Ln=({level:t})=>{const o={certain:{label:"确定",color:"var(--bim-confidence-certain, #2e7d32)"},consensus:{label:"共识",color:"var(--bim-confidence-consensus, #1976d2)"},probable:{label:"推测",color:"var(--bim-confidence-probable, #ed6c02)"},disputed:{label:"有争议",color:"var(--bim-confidence-disputed, #c62828)"}}[t];return 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},Fs={fontSize:"14px",color:"var(--bim-fg, #333)"},Ps={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ms={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Hs={marginBottom:"16px"},Os={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ds={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Ns={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Vs={fontSize:"15px",fontWeight:600},Us={fontSize:"12px",color:"var(--bim-muted, #777)"},Gs={marginBottom:"6px"},Ys={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Ks={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Bn={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Wn={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},$n=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),An={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Fn={fontSize:"11px",color:"var(--bim-muted, #888)"},Js={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},ko=({selectedNodeId:t,...n})=>{const[o,r]=u.useState("loading"),[s,i]=u.useState(null);return u.useEffect(()=>{let l=!1;return qs().then(c=>{l||(c?(i(c),r("ready")):r("missing"))}),()=>{l=!0}},[]),o==="loading"?e.jsx("div",{style:Pn,children:"加载图组件中…"}):o==="missing"||!s?e.jsxs("div",{style:Pn,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(Xs,{modules:s,selectedNodeId:t,...n})};async function qs(){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 Xs=({graph:t,renderLink:n,height:o=600,className:r,style:s,selectedNodeId:i,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:x,Position:f,BaseEdge:h,EdgeLabelRenderer:p,getSmoothStepPath:b,dagre:y}=l,g=u.useMemo(()=>({lineage:w=>{var O,L,$,Z;const k=((O=w.data)==null?void 0:O.stepPosition)??.85,[I,E,z]=b({sourceX:w.sourceX,sourceY:w.sourceY,sourcePosition:w.sourcePosition,targetX:w.targetX,targetY:w.targetY,targetPosition:w.targetPosition,stepPosition:k,borderRadius:5}),C=!!((L=w.data)!=null&&L.isSibling),W=C?E:w.targetX-18,H=C?z:w.targetY-12,B=($=w.data)==null?void 0:$.labelStyle,A=(Z=w.data)==null?void 0:Z.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(h,{id:w.id,path:I,style:w.style,markerStart:w.markerStart,markerEnd:w.markerEnd}),w.label&&e.jsx(p,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${W}px,${H}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...A,...B},children:w.label})})]})}}),[h,p,b]),v=u.useMemo(()=>({version:w=>{const k=w.data,I=k.kind==="hypothetical",E=k.status==="lost",z=k.isSelected,C=k.bridge,W=k.borderColor??"var(--bim-muted, #888)",H=C||I?"dashed":"solid",B=C?.5:E?.6:1;return e.jsxs("div",{style:{background:C?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${H} ${z?"var(--bim-primary, #0078d4)":W}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:B,boxShadow:z?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":I||C?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(x,{type:"target",position:f.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:I||!k.renderLink?k.label:k.renderLink(k.bookId,k.label)}),k.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:k.description}),k.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:jo(k.yearText,void 0,k.uncertain)}),E&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(x,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[x,f]),{convert:m}=M(),{rfNodes:S,rfEdges:_}=u.useMemo(()=>Zs(t,y,n,i,m),[t,y,n,i,m]);return e.jsx("div",{style:{width:"100%",height:o,...s},className:r,children:e.jsxs(c,{nodes:S,edges:_,nodeTypes:v,edgeTypes:g,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Zs(t,n,o,r,s=i=>i??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(v=>[v.id,v.color??"var(--bim-muted, #888)"]));for(const v of t.nodes)a.setNode(v.id,{width:160,height:90});const x=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const v of t.edges)v.kind==="derive"&&(x.has(v.relation)||a.setEdge(v.source,v.target));n.layout(a);const f=t.nodes.map(v=>{const m=a.node(v.id),S=r&&v.id===r,_={kind:v.kind,label:s(v.label),bookId:v.kind==="book"?v.id:void 0,yearText:s(v.year_text??el(v)),uncertain:v.year_uncertain,category:v.category,status:v.status,borderColor:v.group?d.get(v.group):void 0,renderLink:o,isSelected:S,description:s(v.description),bridge:v.bridge};return{id:v.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:_,draggable:!1,selected:S}}),h=.78,p=.06,b=new Map;for(const v of t.edges)v.kind==="derive"&&(b.has(v.source)||b.set(v.source,[]),b.get(v.source).push(v));const y=new Map;for(const[v,m]of b){if(m.length<=1)continue;const S=[...m].sort((j,w)=>{var E,z;const k=((E=a.node(j.target))==null?void 0:E.y)??0,I=((z=a.node(w.target))==null?void 0:z.y)??0;return k-I}),_=S.length;S.forEach((j,w)=>{const k=(w-(_-1)/2)*p;y.set(j.id,h+k)})}const g=t.edges.map(v=>Qs(v,y.get(v.id),s));return{rfNodes:f,rfEdges:g}}function Qs(t,n,o=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",i=tl(t.confidence),l={type:"arrowclosed",color:i,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:o(t.relation),data:{labelStyle:{color:"var(--bim-fg, #444)"},isSibling:s,stepPosition:n},style:{stroke:i,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function el(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function tl(t){switch(t){case"certain":return"var(--bim-confidence-certain, #2e7d32)";case"consensus":return"var(--bim-lineage-edge-consensus, #555)";case"probable":return"var(--bim-confidence-probable, #ed6c02)";case"disputed":return"var(--bim-confidence-disputed, #c62828)";default:return"var(--bim-muted, #888)"}}const Pn={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)"},wo=({graph:t,defaultMode:n="list",renderLink:o,graphHeight:r=600,selectedNodeId:s,onModeChange:i,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:x,style:f})=>{var m;const[h,p]=u.useState(n),b=S=>{p(S),i==null||i(S)},y=(()=>{if(!a)return[];const S=Object.entries(a);return S.length===0||a.all?S:[...S,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),g=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const v=l?(m=a==null?void 0:a[l])==null?void 0:m.description:void 0;return e.jsxs("div",{className:x,style:f,children:[e.jsxs("div",{style:nl,children:[e.jsx("button",{onClick:()=>b("list"),style:yt(h==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:yt(h==="graph"),children:"关系图"}),g&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),y.map(([S,_])=>{const j=d==null?void 0:d[S];return e.jsxs("button",{onClick:()=>c==null?void 0:c(S),style:yt(l===S),title:_.description,children:[_.label,j!=null?` ${j}`:""]},S)})]})]}),g&&v&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:v}),h==="list"?e.jsx(So,{graph:t,renderLink:o}):e.jsx(ko,{graph:t,renderLink:o,height:r,selectedNodeId:s})]})},nl={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},yt=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"}),Bt=({style:t})=>{const n=u.useContext(tt);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:"简"})]})},Wt=({href:t,label:n="在 GitHub 查看本条目源文件",size:o=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:o+8,height:o+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:i=>{i.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:i=>{i.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:o,height:o,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})}),ol=`
|
|
4
4
|
.bim-detail-root { flex-direction: row; }
|