book-index-ui 0.7.0 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +129 -19
- package/dist/index.js +3939 -3725
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var Bo=Object.create;var Cn=Object.defineProperty;var Lo=Object.getOwnPropertyDescriptor;var Wo=Object.getOwnPropertyNames;var $o=Object.getPrototypeOf,Ao=Object.prototype.hasOwnProperty;var Fo=(t,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Wo(n))!Ao.call(t,s)&&s!==i&&Cn(t,s,{get:()=>n[s],enumerable:!(o=Lo(n,s))||o.enumerable});return t};var tt=(t,n,i)=>(i=t!=null?Bo($o(t)):{},Fo(n||!t||!t.__esModule?Cn(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("./storage-entry-BszwT2ej.cjs"),e=require("react/jsx-runtime"),x=require("react"),Mo=require("react-markdown"),Po=require("remark-gfm"),Ho=require("react-dom"),Do=t=>`/book-index?id=${t}`,ji=x.createContext(Do);function Oo({buildUrl:t,children:n}){const i=x.useMemo(()=>t,[t]);return e.jsx(ji.Provider,{value:i,children:n})}function me(){return x.useContext(ji)}function Me(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function No(t,n){return Me(t).includes(n)}const Si={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},Vo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},Go={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},mt=x.createContext(null),ki={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},Uo={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Yo={"zh-Hant":ki,"zh-Hans":Uo},wi="bim-locale";function Ko(){try{const t=localStorage.getItem(wi);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Jo(t){try{localStorage.setItem(wi,t)}catch{}}const qo="zh-Hans",Xo=({locale:t,onLocaleChange:n,children:i})=>{const[o,s]=x.useState(t??qo),r=t??o;x.useEffect(()=>{if(t)return;const p=Ko();p&&p!==o&&s(p)},[]);const[l,c]=x.useState(null);x.useEffect(()=>{r==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const f=p.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>p=>p)}):c(null)},[r]);const a=x.useCallback(p=>{s(p),Jo(p),n==null||n(p)},[n]),d=x.useMemo(()=>({locale:r,setLocale:a,messages:Yo[r],converter:l}),[r,a,l]);return e.jsx(mt.Provider,{value:d,children:i})};function N(){const t=x.useContext(mt);return(t==null?void 0:t.messages)??ki}const Zo=2e3;function V(){const t=x.useContext(mt),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,o=x.useRef(new Map),s=x.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const r=x.useCallback(l=>{if(!l)return"";if(!i)return l;const c=o.current.get(l);if(c!==void 0)return c;const a=i(l);if(o.current.size>=Zo){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(l,a),a},[i]);return x.useMemo(()=>({convert:r,locale:n,isSimplified:n==="zh-Hans"}),[r,n])}function ht(t,n){return t.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}function Qo(t){if(!t)return"";try{const n=new URL(t).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function er(){return{id:"",name:"",url:"",type:"text",details:""}}const Gt=({items:t,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const r=N(),[l,c]=x.useState(null),a=[{value:"text",label:r.resourceTypeShort.text},{value:"image",label:r.resourceTypeShort.image},{value:"text+image",label:r.resourceTypeShort.textImage},{value:"physical",label:r.resourceTypeShort.physical}],d=[{value:"catalog",label:r.rootType.catalog},{value:"search",label:r.rootType.search}],p=b=>{if(!s)return!0;const S=Me(b);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((b,S)=>({item:b,originalIndex:S})).filter(({item:b})=>p(b)),g=()=>{const b=er();s&&(b.type=s),n([...t,b]),c(t.length)},u=b=>{n(t.filter((S,_)=>_!==b)),c(null)},h=(b,S,_)=>{const k=[...t];if(k[b]={...k[b],[S]:_},S==="url"&&!k[b].id){const I=Qo(_);I&&(k[b].id=I)}n(k)},y=(b,S,_)=>{const I={...t[b].metadata||{}};_?I[S]=_:delete I[S],h(b,"metadata",Object.keys(I).length>0?I:void 0)},m=(b,S)=>{const _=S.trim()?S.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;h(b,"structure",_)},j=(b,S,_)=>{const I=t[b].coverage||{level:1,ranges:""};S==="level"?I.level=parseInt(_)||1:I.ranges=_,h(b,"coverage",I.ranges?I:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:b,originalIndex:S})=>{var _,k,I;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===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:tr(b.type??"text"),color:"#fff"},children:(()=>{var z,T;const v=Me(b);return v.length===0?b.type??"text":v.length===1?((z=a.find(w=>w.value===v[0]))==null?void 0:z.label)??v[0]:v.includes("text")&&v.includes("image")?((T=a.find(w=>w.value==="text+image"))==null?void 0:T.label)??"text+image":v.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:b.name||`${r.editor.resourcePlaceholder} ${S+1}`}),b.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:b.id}),b.url&&e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",onClick:v=>v.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&b.url&&nr(S,o==null?void 0:o[S],i,r),e.jsx("button",{onClick:v=>{v.stopPropagation(),u(S)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisResource,children:"✕"})]}),l===S&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[No(b,"image")&&b.url&&ir(b,r),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:nt,children:[e.jsx("span",{style:it,children:r.label.type}),e.jsx("select",{value:b.type,onChange:v=>h(S,"type",v.target.value),style:{...we,flex:1},children:a.map(v=>e.jsx("option",{value:v.value,children:v.label},v.value))})]}),e.jsxs("label",{style:nt,children:[e.jsx("span",{style:it,children:r.label.rootType}),e.jsx("select",{value:b.root_type||"catalog",onChange:v=>h(S,"root_type",v.target.value),style:{...we,flex:1},children:d.map(v=>e.jsx("option",{value:v.value,children:v.label},v.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:b.id,onChange:v=>h(S,"id",v.target.value),placeholder:r.editor.idAutoExtract,style:{...we,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:b.name,onChange:v=>h(S,"name",v.target.value),placeholder:r.editor.resourceName,style:{...we,flex:1}})]}),e.jsx("input",{type:"text",value:b.url,onChange:v=>h(S,"url",v.target.value),placeholder:r.editor.resourceUrl,style:we}),e.jsx("input",{type:"text",value:((_=b.structure)==null?void 0:_.join("、"))||"",onChange:v=>m(S,v.target.value),placeholder:r.editor.structurePlaceholder,style:we}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:nt,children:[e.jsx("span",{style:it,children:r.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=b.coverage)==null?void 0:k.level)??"",onChange:v=>j(S,"level",v.target.value),placeholder:"1",style:{...we,width:"60px"}})]}),e.jsxs("label",{style:{...nt,flex:1},children:[e.jsx("span",{style:it,children:r.label.coverageRange}),e.jsx("input",{type:"text",value:((I=b.coverage)==null?void 0:I.ranges)||"",onChange:v=>j(S,"ranges",v.target.value),placeholder:r.editor.coverageRangePlaceholder,style:{...we,flex:1}})]})]}),e.jsx("textarea",{value:b.details||"",onChange:v=>h(S,"details",v.target.value),placeholder:r.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:r.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(r.metadata).map(([v,z])=>{var T;return e.jsxs("label",{style:{...nt,gap:"4px"},children:[e.jsx("span",{style:{...it,minWidth:"56px"},children:z}),e.jsx("input",{type:"text",value:((T=b.metadata)==null?void 0:T[v])||"",onChange:w=>y(S,v,w.target.value),placeholder:z,style:{...we,flex:1}})]},v)})})]})]})]})]},S)}),e.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addResource})]})]})};function tr(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 nr(t,n,i,o){const s=(n==null?void 0:n.status)==="downloading",r=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:l=>{l.stopPropagation(),s||i(t,"")},disabled:s,style:{background:"transparent",border:"none",color:r?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:r?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:r?"✓":s?"⏳":"⬇"})}function ir(t,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:i?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"var(--bim-overlay-bg, #00000010)"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const 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"},nt={display:"flex",alignItems:"center",gap:"6px"},it={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},or={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function Pe(t){try{return or[new URL(t).hostname]}catch{return}}const In={text:0,image:1,physical:2};function Xt(t){return t.length===0?"physical":[...t].sort((n,i)=>(In[n]??99)-(In[i]??99)).join("+")}function Zt(t){const n=l=>{const c=l.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},i=new Map;for(let l=0;l<t.length;l++){const c=t[l];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[d,p]=a,f=`${d}|${Xt(Me(c))}`;i.has(f)||i.set(f,{base:{...c,name:d,url:"",volumes:[]},volumes:[],indices:[]});const g=i.get(f);g.volumes.push({volume:p,url:c.url||void 0,status:"found"}),g.indices.push(l)}const o=[],s=new Set;for(const l of i.values())if(!(l.volumes.length<2)){l.volumes.sort((c,a)=>c.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,o.push(l.base);for(const c of l.indices)s.add(c)}const r=[...o];for(let l=0;l<t.length;l++)s.has(l)||r.push(t[l]);return r}function _i(t){if(t.url)return t.url;for(const[n,i]of Object.entries(t))if(n.endsWith("_url")&&typeof i=="string")return i}function Ci(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||_i(n)}))}function Rt(t){const n=Ci(t);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:o,expected:t.expected_volumes??i+o}}function Qt(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function en(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const o=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function qe(t){if(!t.url)return;const n=Qt(t.metadata);return n?en(t.url,n):t.url}const zn={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 rr(t){return t.includes("text")&&t.includes("image")?zn["text+image"]:zn[t[0]||"physical"]}const tn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const r=N(),{convert:l}=V(),c=x.useMemo(()=>Zt(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=x.useMemo(()=>{const m=new Map,j=[];for(const b of c){const S=b.group;S?(m.has(S)||m.set(S,[]),m.get(S).push(b)):j.push(b)}for(const b of m.values())b.sort((S,_)=>{const k=I=>I.group_role==="origin"?0:I.group_role==="mirror"?1:2;return k(S)-k(_)});return{mirrorGroups:m,ungroupedItems:j}},[c]),p={text:r.resourceType.text,image:r.resourceType.image,"text+image":r.resourceType.textImage,physical:r.resourceType.physical},f=m=>p[m]?p[m]:m.split("+").map(j=>p[j]||j).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:r.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((m,j)=>e.jsx(Pt,{item:m},m.id||j))});const g=(m,j)=>{const b=i==null?void 0:i[m],S=(b==null?void 0:b.label)||m,_=b==null?void 0:b.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(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:j.map((k,I)=>e.jsx(Pt,{item:k,onNavigate:o,renderLink:s},k.id||I))})]},`group-${m}`)},u=new Map;for(const m of d){const j=Xt(Me(m));u.has(j)||u.set(j,[]),u.get(j).push(m)}const h=["text","image","text+image","physical"],y=[...h.filter(m=>u.has(m)),...[...u.keys()].filter(m=>!h.includes(m)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([m,j])=>g(m,j)),y.map(m=>{const j=u.get(m),b=rr(m.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:b,whiteSpace:"nowrap",flexShrink:0},children:f(m)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((S,_)=>e.jsx(Pt,{item:S,onNavigate:o,renderLink:s},S.id||_))})]},m)})]})},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)"}},Pt=({item:t})=>{const n=N(),{convert:i}=V(),[o,s]=x.useState(!1),r=x.useMemo(()=>(t.url?Pe(t.url):void 0)||i(t.name),[t.url,t.name,i]),l=x.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||_i(h)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(l.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,p=t.expected_volumes??(c?a+d:0),f=t.color_mode?{...sr[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?i(t.details):null,u={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:u,children:[e.jsx("span",{style:{fontWeight:500},children:r}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",p,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=Qt(t.metadata);return h?en(t.url,h):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),c&&o&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(h=>{const y=h.status==="missing";return h.url&&!y?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:h.volume},h.volume)})})]})},Ii=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:r,onSelectFolder:l})=>{const c=N(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",f=p?p.split(/[/\\]/).pop()||p:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},u={onMouseOver:y=>y.currentTarget.style.opacity="0.8",onMouseOut:y=>y.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...u,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:o,title:c.mode.switchToSync,style:g,...u,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...u,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:r,title:f||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...u,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...u,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&e.jsxs("div",{style:{...g,background:"var(--bim-mode-active-bg, #2196f3)",color:"white",cursor:"default"},title:p,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},Et="bim-search-history",Tn=10,Rn=8;function dt(){try{const t=localStorage.getItem(Et);return t?JSON.parse(t):[]}catch{return[]}}function lr(t){try{const n=dt().filter(i=>i!==t);n.unshift(t),n.length>Tn&&(n.length=Tn),localStorage.setItem(Et,JSON.stringify(n))}catch{}}function ar(t){try{const n=dt().filter(i=>i!==t);localStorage.setItem(Et,JSON.stringify(n))}catch{}}function cr(){try{localStorage.removeItem(Et)}catch{}}const zi=({transport:t,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:r})=>{const l=N(),c=r??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=x.useState(!1),[f,g]=x.useState([]),[u,h]=x.useState(-1),[y,m]=x.useState(dt),j=x.useRef(null),b=x.useRef(null),S=x.useRef(null),_=x.useRef(!1);x.useEffect(()=>{h(-1);const C=n.trim();if(!C){g(y.map(M=>({type:"history",text:M})));return}if(!t.searchAll){g([]);return}let W=!1;const R=setTimeout(()=>{t.searchAll(C,Rn).then(M=>{if(W)return;const F=[...M.works,...M.books,...M.collections,...M.entities??[]];g(F.slice(0,Rn).map(P=>({type:"entry",text:P.title||P.id,entry:P})))}).catch(()=>{W||g([])})},80);return()=>{W=!0,clearTimeout(R)}},[n,y,t]),x.useEffect(()=>{const C=W=>{S.current&&!S.current.contains(W.target)&&p(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]),x.useEffect(()=>{const C=W=>{var R,M;if(W.key==="/"&&document.activeElement!==j.current){const F=(R=document.activeElement)==null?void 0:R.tagName;if(F==="INPUT"||F==="TEXTAREA"||F==="SELECT")return;W.preventDefault(),(M=j.current)==null||M.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[]);const k=x.useCallback(C=>{C.trim()&&(lr(C.trim()),m(dt())),o(C),p(!1)},[o]),I=x.useCallback(C=>{C.type==="history"?(i(C.text),k(C.text)):C.entry&&(s?(s(C.entry),p(!1)):(i(C.text),k(C.text)))},[i,k,s]),v=x.useCallback(C=>{if(!d||f.length===0){C.key==="Enter"&&k(n);return}switch(C.key){case"ArrowDown":C.preventDefault(),h(W=>(W+1)%f.length);break;case"ArrowUp":C.preventDefault(),h(W=>(W-1+f.length)%f.length);break;case"Enter":C.preventDefault(),u>=0&&u<f.length?I(f[u]):k(n);break;case"Escape":C.preventDefault(),p(!1);break}},[d,f,u,n,k,I]),z=x.useCallback((C,W)=>{W.stopPropagation(),ar(C),m(dt()),g(R=>R.filter(M=>!(M.type==="history"&&M.text===C)))},[]),T=x.useCallback(C=>{C.stopPropagation(),cr(),m([]),g([])},[]);x.useEffect(()=>{if(u>=0&&b.current){const C=b.current.children;C[u]&&C[u].scrollIntoView({block:"nearest"})}},[u]);const w=!n.trim()&&y.length>0;return e.jsxs("div",{ref:S,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:C=>{i(C.target.value),p(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{p(!0)},onKeyDown:v,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:b,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[w&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:T,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),f.map((C,W)=>e.jsxs("div",{onClick:()=>I(C),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:W===u?"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:R=>z(C.text,R),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}`))]})]})},ft="bim-recent-ids",En="bim-recent-entries",Bn=50,Ht=5,dr=50,pr=200;function pt(){try{const t=localStorage.getItem(ft);if(t)return JSON.parse(t);const n=localStorage.getItem(En);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(ft,JSON.stringify(i)),localStorage.removeItem(En),i}return[]}catch{return[]}}function ur(t){try{const n=pt().filter(i=>i!==t);n.unshift(t),n.length>Bn&&(n.length=Bn),localStorage.setItem(ft,JSON.stringify(n))}catch{}}function xr(t){try{const n=pt().filter(i=>i!==t);localStorage.setItem(ft,JSON.stringify(n))}catch{}}function fr(){try{localStorage.removeItem(ft)}catch{}}const gr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Ut=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:f,initialQuery:g,onQueryChange:u,headerRight:h})=>{const y=N(),m=[{type:"work",icon:"✍️",name:y.indexType.work,key:"works"},{type:"book",icon:"📖",name:y.indexType.book,key:"books"},{type:"collection",icon:"📚",name:y.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:y.indexType.entity,key:"entities"}],[j,b]=x.useState(g??""),[S,_]=x.useState(null),[k,I]=x.useState(null),[v,z]=x.useState(!1),[T,w]=x.useState(null),[C,W]=x.useState(""),[R,M]=x.useState(!g),[F,P]=x.useState(pt),[$,A]=x.useState([]),[L,E]=x.useState(!1),[D,te]=x.useState(!1),[G,Z]=x.useState(null),[re,ne]=x.useState(null),U=x.useRef(void 0),Y=x.useRef(!1),ce=x.useCallback(async(O,ie)=>{if(!O.trim()){M(!0),_(null),I(null);return}M(!1),z(!0),W("");try{if(t.searchAll){const ee=await t.searchAll(O,ie??Ht);_(ee)}else{const ee=["work","book","collection","entity"],B=await Promise.all(ee.map(X=>t.search(O,X,{page:1,pageSize:ie??Ht})));_({works:B[0].entries,books:B[1].entries,collections:B[2].entries,entities:B[3].entries,totalWorks:B[0].total,totalBooks:B[1].total,totalCollections:B[2].total,totalEntities:B[3].total})}}catch(ee){W(ee instanceof Error?ee.message:String(ee)),_(null)}finally{z(!1)}},[t]);x.useEffect(()=>{let O=!1;const ie=()=>{var J,Ee;const ee=["work","book","collection","entity"],B=Promise.all(ee.map(be=>t.loadEntries(be,{page:1,pageSize:1}).catch(()=>({total:0})))),X=((J=t.getResourceCounts)==null?void 0:J.call(t).catch(()=>null))??Promise.resolve(null),se=((Ee=t.getSubtypeStats)==null?void 0:Ee.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([B,X,se]).then(([be,pe,Ge])=>{O||(Z({works:be[0].total,books:be[1].total,collections:be[2].total,entities:be[3].total,hasText:pe==null?void 0:pe.hasText,hasImage:pe==null?void 0:pe.hasImage}),Ge&&ne(Ge))})};return t.getCounts?t.getCounts().then(ee=>{var B,X;O||(Z({works:ee.works,books:ee.books,collections:ee.collections,entities:ee.entities,hasText:(B=ee.resourceCounts)==null?void 0:B.hasText,hasImage:(X=ee.resourceCounts)==null?void 0:X.hasImage}),ee.subtypeStats&&ne(ee.subtypeStats))}).catch(()=>{O||ie()}):ie(),()=>{O=!0}},[t]),x.useEffect(()=>{Y.current||!(g!=null&&g.trim())||(Y.current=!0,ce(g))},[g,ce]);const Ne=x.useCallback(O=>{if(b(O),!O.trim()){u==null||u(O),M(!0),_(null),I(null);return}U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{I(null),u==null||u(O),ce(O)},pr)},[ce,u]),je=x.useCallback(O=>{U.current&&clearTimeout(U.current),u==null||u(O),ce(O)},[ce,u]),he=x.useCallback(O=>{I(O),ce(j,dr)},[j,ce]);x.useEffect(()=>{if(!F.length){A([]);return}let O=!1;return E(!0),Promise.all(F.slice(0,10).map(async ie=>{var ee,B,X;try{if(t.getEntry){const J=await t.getEntry(ie);if(J)return J}const se=await t.getItem(ie);if(se){const J=se.authors;return{id:ie,title:se.title||ie,type:se.type||"work",author:(ee=J==null?void 0:J[0])==null?void 0:ee.name,dynasty:(B=J==null?void 0:J[0])==null?void 0:B.dynasty,role:(X=J==null?void 0:J[0])==null?void 0:X.role,edition:se.edition||void 0}}}catch{}return{id:ie,title:ie,type:"work",notFound:!0}})).then(ie=>{O||(A(ie),E(!1))}),()=>{O=!0}},[F,t]);const Ie=O=>{w(O.id),ur(O.id),P(pt()),o==null||o(O)},Le=O=>{xr(O),P(pt())},Se=()=>{fr(),P([])},Ve=O=>m.find(ie=>ie.type===O),et=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:[h,!d&&e.jsx(Ii,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(zi,{transport:t,value:j,onChange:Ne,onSearch:je,onEntrySelect:Ie}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:y.action.newEntry})]}),G&&R&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:re?e.jsxs(e.Fragment,{children:[(re.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.books.toLocaleString()})," 本"]}),re.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.article.toLocaleString()})," 篇"]}):null,re.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:re.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.collections.toLocaleString()}),G.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.entities.toLocaleString()})]})]})}),G.hasImage!=null&&G.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:G.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:v?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})]}):R?e.jsx("div",{style:{flex:1},children:L?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):$.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:y.search.recentBrowse}),e.jsx("button",{onClick:Se,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:y.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,D?10:3).map(O=>O.notFound?e.jsx(hr,{id:O.id,onRemove:Le,t:y},O.id):e.jsx(Ln,{entry:O,selected:T===O.id,onClick:Ie,getConfig:Ve,onRemove:Le},O.id))}),!D&&$.length>3&&e.jsx("button",{onClick:()=>te(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children: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})]})}):et?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:O,icon:ie,name:ee,key:B})=>{const X=S[B]??[],se=gr[B],J=S[se]??0;if(X.length===0)return null;const be=!(k===O)&&J>Ht;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[ie," ",ee,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",y.unit.items]})]}),be&&e.jsx("button",{onClick:()=>he(O),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:y.action.viewAll})]}),e.jsx("div",{style:p==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:X.map(pe=>{if(f)return e.jsx(x.Fragment,{children:f(pe)},pe.id);const Ge=p==="card"?mr:Ln;return e.jsx(Ge,{entry:pe,selected:T===pe.id,onClick:Ie,getConfig:Ve,query:j},pe.id)})})]},O)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:ht(y.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},mr=({entry:t,selected:n,onClick:i,getConfig:o,query:s})=>{const r=N(),{convert:l}=V(),c=l(t.title||t.primary_name||t.id),a=t.measure_info?l(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${r.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&d.length?d.find(g=>{const u=typeof g=="string"?g:g==null?void 0:g.book_title;return u==null?void 0:u.toLowerCase().includes(s.toLowerCase())}):void 0,f="var(--bim-cover-accent, #8e6f3e)";return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:"var(--bim-bg, #fff)",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${f} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${f} 7%, var(--bim-bg, #fff)))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${f} 45%, transparent)`}}),e.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:f},children:Array.from(c).map((g,u)=>e.jsx("span",{children:g},u))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c}),a&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(t.role)]})]}),t.edition&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l(t.edition)}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[r.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o(t.type).icon," ",o(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",r.misc.textResource]}),t.has_image&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["🖼️ ",r.misc.imageResource]})]})]})]})},Ln=({entry:t,selected:n,onClick:i,getConfig:o,query:s,onRemove:r})=>{const l=N(),{convert:c}=V(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(p=>{const f=typeof p=="string"?p:p==null?void 0:p.book_title;return f==null?void 0:f.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),r?e.jsx("button",{onClick:p=>{p.stopPropagation(),r(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},hr=({id:t,onRemove:n,t:i})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:i.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function br(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}=V(),{dynasty:i,birth_year:o,death_year:s}=t,r=[];return i&&r.push(`〔${n(i)}〕`),o!==void 0&&s!==void 0?r.push(`${o}—${s}`):o!==void 0?r.push(`${o}—?`):s!==void 0&&r.push(`?—${s}`),r.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:r.join(" ")})}function vr({alt_names:t}){const{convert:n}=V(),i=new Map;for(const r of t){const l=r.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(r.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((r,l)=>{const c=o.indexOf(r),a=o.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(r=>{const l=i.get(r);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:r}),e.jsx("span",{children:l.map((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},r)})})}function jr({data:t}){const n=t.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function Sr({works:t,transport:n,onNavigate:i,renderLink:o}){const s=N(),{convert:r}=V(),l=me(),[c,a]=x.useState(new Map);x.useEffect(()=>{if(!n)return;let g=!1;const u=t.map(y=>y.work_id);return(async()=>{const y=new Map;if(n.getEntriesByIds)try{const S=await n.getEntriesByIds(u);let _=!0;for(let k=0;k<u.length;k++){const I=S[k];I!=null&&I.title?y.set(u[k],I.title):I!=null&&I.primary_name?y.set(u[k],I.primary_name):_=!1}if(_)return y}catch{}const m=[...u],j=8,b=new Array(j).fill(0).map(async()=>{for(;m.length;){const S=m.shift();if(!S)break;if(!y.has(S))try{if(n.getEntry){const I=await n.getEntry(S);if(I!=null&&I.title){y.set(S,I.title);continue}}const _=await n.getItem(S),k=_&&(_.title||_.primary_name)||S;y.set(S,k)}catch{y.set(S,S)}}});return await Promise.all(b),y})().then(y=>{g||a(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const u=g.role||"";d.has(u)||d.set(u,[]),d.get(u).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((g,u)=>{const h=p.indexOf(g),y=p.indexOf(u);return h===-1&&y===-1?g.localeCompare(u):h===-1?1:y===-1?-1:h-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),f.map(g=>{const u=d.get(g);return e.jsxs("div",{style:{marginBottom:"8px"},children:[g&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[r(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",u.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:u.map((h,y)=>{const m=r(c.get(h.work_id)||h.work_id);return o?e.jsx("li",{children:o(h.work_id,m)},y):i?e.jsx("li",{children:e.jsx("a",{href:l(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),i(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:m})},y):e.jsx("li",{children:m},y)})})]},g)})]})}const nn=({data:t,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:r})=>{var f;const l=N(),{convert:c}=V();let a=!1;try{a=q.extractStatus(t.id)==="draft"}catch{}const d=br(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[c(t.primary_name),e.jsx(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:l.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(vr,{alt_names:t.alt_names}),e.jsx(jr,{data:t}),((f=t.description)==null?void 0:f.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Sr,{works:t.works,transport:n,onNavigate:i,renderLink:o})]})},Ti={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={...Ti,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Be=({text:t,plainStrong:n,style:i,className:o})=>{const{convert:s}=V(),r=n?kr:Ti;return e.jsx("div",{className:o,style:i,children:e.jsx(Mo,{remarkPlugins:[Po],components:r,children:s(t)})})},wr=["〇","一","二","三","四","五","六","七","八","九"],Wn=["","十","百","千"];function Ri(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",s=!1;for(let r=0;r<i;r++){const l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=Wn[c]:o+=wr[l]+Wn[c])}return o}function Ei(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=N();return e.jsx("span",{style:Ei(_r[t]),children:n.indexType[t]})}function Ir({isDraft:t}){const n=N(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Ei(i),children:t?n.status.draft:n.status.official})}function zr({id:t}){const n=N(),[i,o]=x.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-bg-subtle, #f6f6f6)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:r=>r.currentTarget.style.opacity="1",onMouseLeave:r=>r.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function fe({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function _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 Bi({authors:t,type:n,onNavigate:i,renderLink:o}){const{convert:s}=V();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,l)=>{const c=s(r.name),a=r.entity_id?e.jsx(ve,{id:r.entity_id,label:c,onNavigate:i,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(r.dynasty),"〕"]}),a,r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(r.role)]})]},l)})})}function ve({id:t,label:n,onNavigate:i,renderLink:o}){const s=me();return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:s(t),onClick:r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Tr({id:t,title:n,edition:i,type:o,isDraft:s,authors:r,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:p}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Cr,{type:o}),e.jsx(Ir,{isDraft:s}),e.jsx(zr,{id:t})]}),((r==null?void 0:r.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[r&&r.length>0&&e.jsx(Bi,{authors:r,type:o,onNavigate:d,renderLink:p}),c]})]})}function Li({items:t,label:n,showMeta:i,onNavigate:o,renderLink:s}){const r=N(),{convert:l}=V();if(!t.length)return null;const[c,a]=x.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,p)=>{const f=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?null:p),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!f&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ve,{id:d.source_bid,label:r.action.view,onNavigate:o,renderLink:s})})]}),f&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(_e,{label:r.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(_e,{label:r.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(_e,{label:r.label.edition,children:l(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:r.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:r.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:r.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},p)})})]})}function Rr({items:t,onNavigate:n,renderLink:i}){const o=N();return e.jsx(Li,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Wi({items:t,onNavigate:n,renderLink:i}){const o=N();return e.jsx(Li,{items:t,label:o.section.emendated,onNavigate:n,renderLink:i})}function $i({label:t,items:n}){const{convert:i}=V();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const r=typeof o=="string"?o:o.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:i(r)},s)})})]}):null}function Er({items:t}){const n=N();return e.jsx($i,{label:n.section.aliases,items:t})}function Br({items:t}){const n=N();return e.jsx($i,{label:n.section.attachedTexts,items:t})}function Lr({items:t}){const n=N(),{convert:i}=V();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",i(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function Wr({items:t}){const n=N(),{convert:i}=V();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(o.description)})]},s))]})]}):null}function $r({items:t}){const n=N(),{convert:i}=V();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(o)]},s))})]}):null}function $n({title:t,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:r}=V(),[l,c]=x.useState([]);return x.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(p=>({id:d,title:p?p.title:void 0,edition:p?p.edition:void 0,type:p?p.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(fe,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${r(a.title)||a.id}(${r(a.edition)})`:r(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ve,{id:a.id,label:d,onNavigate:o,renderLink:s})},a.id)})})]}):null}function Dt({book:t,onNavigate:n,renderLink:i}){const o=N(),{convert:s}=V(),[r,l]=x.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!r?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(ve,{id:t.id,label:a,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:r?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:r?o.action.expand:o.action.collapse,children:"▼"})]}),c&&!r&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(tn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Ar({ids:t,workData:n,transport:i,onNavigate:o,renderLink:s,footer:r}){const l=N(),{convert:c}=V(),[a,d]=x.useState([]);if(x.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(y=>({id:y})));return}let h=!1;return Promise.all(t.map(y=>i.getItem(y).then(m=>({id:y,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:y})))).then(y=>{h||d(y)}),()=>{h=!0}},[t,i]),!t.length)return null;const p=a.length?a:t.map(h=>({id:h})),f=new Map(p.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,u=Fr(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(fe,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),r,u.useGrouping?e.jsxs(e.Fragment,{children:[u.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:u.coreIds.map(h=>{const y=f.get(h);return y?e.jsx(Dt,{book:y,onNavigate:o,renderLink:s},h):null})}),u.groupedIds.map(h=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(y=>{const m=f.get(y);return m?e.jsx(Dt,{book:m,onNavigate:o,renderLink:s},y):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(h=>e.jsx(Dt,{book:h,onNavigate:o,renderLink:s},h.id))})]})}function Fr(t,n){var m,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],r=o.length>0||s.length>0,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=b=>{if(a.has(b))return!0;const S=n.node_groups[b];return S!=null&&c.has(S)},p=[],f=new Map,g=[];for(const b of t)if(!((j=n.excluded_books)!=null&&j.includes(b)))if(d(b))p.push(b);else{const S=n.node_groups[b];S?(f.has(S)||f.set(S,[]),f.get(S).push(b)):g.push(b)}if(g.length+[...f.values()].reduce((b,S)=>b+S.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(b=>[b.id,b])),y=[...f.entries()].map(([b,S])=>{const _=h.get(b);return{id:b,label:(_==null?void 0:_.label)??b,description:_==null?void 0:_.description,ids:S}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}function Mr({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const o=N(),{convert:s}=V(),r=!!((l=t.description)!=null&&l.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:r?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ve,{id:t.id,label:s(t.title),onNavigate:n,renderLink:i})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[Ri(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Bi,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),r&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(Be,{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:o.label.parentWork,children:e.jsx(ve,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Pr({items:t,onNavigate:n,renderLink:i}){const o=N(),{convert:s}=V();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(r=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:o.indexType.collection}),e.jsx(ve,{id:r.id,label:s(r.title)||r.id,onNavigate:n,renderLink:i}),r.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:ht(o.catalog.volume,{n:r.volume_index})})]},r.id))}):null}const on=({data:t,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:r,relatedBooksFooter:l,className:c,style:a})=>{var W,R,M,F,P,$,A,L;const d=N(),{convert:p}=V(),[f,g]=x.useState(null),[u,h]=x.useState(!1),[y,m]=x.useState(null),[j,b]=x.useState(null),[S,_]=x.useState([]),k=t||f;if(x.useEffect(()=>{if(t||!n||!i)return;let E=!1;return h(!0),m(null),i.getItem(n).then(D=>{E||(D?g(D):m(d.misc.notFoundEntry))}).catch(D=>{E||m(D instanceof Error?D.message:d.misc.loadFailed)}).finally(()=>{E||h(!1)}),()=>{E=!0}},[t,n,i]),x.useEffect(()=>{if(!k||!i){b(null),_([]);return}let E=!1;const D=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(D?i.getItem(D).then(te=>{!E&&te&&te.type==="work"&&b(te)}).catch(()=>{}):b(null),k.type==="book"){const te=k;te.contained_in&&te.contained_in.length>0?Promise.all(te.contained_in.map(G=>{const Z=typeof G=="string"?G:G.id,re=typeof G=="string"?void 0:G.volume_index;return i.getItem(Z).then(ne=>({id:Z,title:ne&&ne.title||Z,volume_index:re})).catch(()=>({id:Z,title:Z,volume_index:re}))})).then(G=>{E||_(G)}):_([])}else _([]);return()=>{E=!0}},[k,i]),u)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((E,D)=>e.jsx("div",{style:{height:D===1?"32px":"16px",width:`${E}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},D))})});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(!k)return null;if(k.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(nn,{data:k,transport:i,onNavigate:o,renderLink:s,headerExtra:r})});const I=k.type==="book"?k:null,v=k.type==="collection"?k:null,z=k.type==="work"?k:null;let T=!1;try{T=q.extractStatus(k.id)==="draft"}catch{}let w="";k.measure_info?w=p(k.measure_info):(W=k.juan_count)!=null&&W.number?w=Ri(k.juan_count.number)+d.unit.juan:(R=k.juan_count)!=null&&R.description&&(w=p(k.juan_count.description));const C=[];return(M=k.publication_info)!=null&&M.year&&C.push(e.jsx(_e,{label:d.label.year,children:k.publication_info.year},"year")),(F=k.current_location)!=null&&F.name&&C.push(e.jsx(_e,{label:d.label.currentLocation,children:p(k.current_location.name)},"loc")),(P=k.page_count)!=null&&P.description&&C.push(e.jsx(_e,{label:d.label.pageCount,children:k.page_count.description},"page")),I!=null&&I.edition&&C.push(e.jsx(_e,{label:d.label.edition,children:p(I.edition)},"ver")),z!=null&&z.parent_work&&C.push(e.jsx(_e,{label:d.label.parentWork,children:e.jsx(ve,{id:z.parent_work.id,label:p(z.parent_work.title),onNavigate:o,renderLink:s})},"pw")),z!=null&&z.parent_works&&z.parent_works.length>0&&!z.parent_work&&C.push(e.jsx(_e,{label:d.label.parentWork,children:z.parent_works.map((E,D)=>e.jsxs("span",{children:[D>0&&"、",e.jsx(ve,{id:E,onNavigate:o,renderLink:s})]},E))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(Tr,{id:k.id,title:p(k.title),edition:k.edition?p(k.edition):void 0,type:k.type,isDraft:T,authors:k.authors,volumeText:w,meta:C,headerExtra:r,onNavigate:o,renderLink:s}),(($=k.description)==null?void 0:$.text)&&e.jsx(Be,{text:k.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),k.appendix&&k.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:k.appendix.map((E,D)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:p(E.title)}),e.jsx(Be,{text:E.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},D))}),S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:d.section.containedIn}),e.jsx(Pr,{items:S,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:d.section.belongsToWork}),e.jsx(Mr,{workData:j,onNavigate:o,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&e.jsx(Lr,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&e.jsx(Er,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&e.jsx(Br,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&e.jsx(Rr,{items:k.indexed_by,onNavigate:o,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&e.jsx(Wi,{items:k.emendated_by,onNavigate:o,renderLink:s}),k.resources&&k.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:d.section.resources}),e.jsx(tn,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(I==null?void 0:I.location_history)&&I.location_history.length>0&&e.jsx(Wr,{items:I.location_history}),(v==null?void 0:v.history)&&v.history.length>0&&e.jsx($r,{items:v.history}),(I==null?void 0:I.related_books)&&I.related_books.length>0&&e.jsx($n,{title:d.section.relatedVersions,ids:I.related_books,transport:i,onNavigate:o,renderLink:s}),(v==null?void 0:v.books)&&v.books.length>0&&e.jsx($n,{title:d.section.containedBooks,ids:v.books,transport:i,onNavigate:o,renderLink:s}),(v==null?void 0:v.contained_works)&&v.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(fe,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",v.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:v.contained_works.map(E=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ve,{id:E.id,label:p(E.title),onNavigate:o,renderLink:s})},E.id))})]}),(((A=z==null?void 0:z.books)==null?void 0:A.length)||0)+(((L=z==null?void 0:z.collections)==null?void 0:L.length)||0)>0&&e.jsx(Ar,{ids:[...(z==null?void 0:z.books)||[],...(z==null?void 0:z.collections)||[]],workData:z,transport:i,onNavigate:o,renderLink:s,footer:l}),(z==null?void 0:z.related_works)&&z.related_works.length>0&&(()=>{const E=[],D=z.related_works.filter(U=>U.relation==="part_of"),te=z.related_works.filter(U=>U.relation==="has_part"),G=z.related_works.filter(U=>U.relation==="has_adaptation"),Z=z.related_works.filter(U=>U.relation==="text_carried_by"),re=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ne=z.related_works.filter(U=>!U.relation||!re.has(U.relation));return D.length>0&&E.push({label:d.section.belongsToWork,items:D}),te.length>0&&E.push({label:d.section.containedWorks,items:te}),G.length>0&&E.push({label:d.section.adaptations,items:G}),Z.length>0&&E.push({label:d.section.derivativeWorks,items:Z}),ne.length>0&&E.push({label:d.section.relatedWorks,items:ne}),E.map(U=>e.jsxs("div",{children:[e.jsxs(fe,{children:[U.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",U.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:U.items.map(Y=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ve,{id:Y.id,label:p(Y.title),onNavigate:o,renderLink:s})},Y.id))})]},U.label))})()]})};function Hr({data:t}){const n=N(),{convert:i}=V(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,r=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),r!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",r,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function Dr({sections:t,activeSection:n,onSelect:i}){const o=N();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:An(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(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 Or({id:t,label:n,onNavigate:i,renderLink:o}){const s=me();return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:s(t),onClick:r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Nr(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],o=t[t.length-1];return o-i+1===t.length?`${i}–${o}`:t.length<=3?t.join(", "):`${i}–${o} (${t.length}${n})`}function Fn({book:t,onNavigate:n,renderLink:i,showVolumes:o}){const s=N(),{convert:r}=V(),l=t.book_id||t.work_id,c=o&&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:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[r(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>r(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:r(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(Or,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const rn=({data:t,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:r,style:l})=>{const c=N(),[a,d]=x.useState(null),[p,f]=x.useState(!1),[g,u]=x.useState(null),[h,y]=x.useState(null),[m,j]=x.useState(""),b=t||a;x.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let v=!1;return f(!0),u(null),i.getCollectionCatalog(n).then(z=>{v||(z?d(z):u(c.catalog.notFound))}).catch(z=>{v||u(z instanceof Error?z.message:c.catalog.loadFailed)}).finally(()=>{v||f(!1)}),()=>{v=!0}},[t,n,i,c]);const S=(b==null?void 0:b.sections)&&b.sections.length>0,_=x.useMemo(()=>{if(!b)return!1;if(b.volume_index&&Object.keys(b.volume_index).length>0)return!0;const v=b.books.map(T=>T.volumes[0]).filter(T=>T!=null);return new Set(v).size<v.length},[b]),k=x.useMemo(()=>{if(!b)return[];let v=b.books;if(h&&(v=v.filter(z=>z.section===h)),m.trim()){const z=m.trim().toLowerCase();v=v.filter(T=>T.title.toLowerCase().includes(z)||T.sub_items&&T.sub_items.some(w=>w.toLowerCase().includes(z))||T.edition&&T.edition.toLowerCase().includes(z))}return v},[b,h,m]),I=x.useMemo(()=>{if(!_)return null;const v=[],z=new Map;for(const w of k){if(!w.volumes||w.volumes.length===0)continue;const C=w.volumes[0];z.has(C)||z.set(C,[]),z.get(C).push(w)}const T=[...z.keys()].sort((w,C)=>w-C);for(const w of T)v.push({volume:w,books:z.get(w)});return v},[k,_]);return p?e.jsx("div",{className:r,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:r,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):b?e.jsxs("div",{className:r,style:l,children:[e.jsx(Hr,{data:b}),S&&e.jsx(Dr,{sections:b.sections,activeSection:h,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:m,onChange:v=>j(v.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:[k.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[I?I.map((v,z)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:ht(c.catalog.volume,{n:v.volume})}),v.books.map((T,w)=>e.jsx(Fn,{book:T,onNavigate:o,renderLink:s,showVolumes:T.volumes.length>1},`${v.volume}-${w}`))]},`${v.volume}-${z}`)):k.map((v,z)=>e.jsx(Fn,{book:v,onNavigate:o,renderLink:s,showVolumes:!0},z)),k.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Oe=()=>{const[t,n]=x.useState(1);return x.useEffect(()=>{const i=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(i)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},de=6,yt=7,Vr=({content:t,children:n,placement:i="top",delayMs:o=100,maxWidth:s=280,wrapperStyle:r})=>{const[l,c]=x.useState(!1),[a,d]=x.useState(null),p=x.useRef(null),f=x.useRef(null),g=x.useRef(null),u=x.useCallback(()=>{const m=f.current,j=g.current;if(!m||!j)return;const b=m.getBoundingClientRect(),S=j.getBoundingClientRect(),_=window.innerHeight,k=document.documentElement.clientWidth;let I=i;i==="top"&&b.top-S.height-yt<8&&(I="bottom"),i==="bottom"&&b.bottom+S.height+yt>_-8&&(I="top");const v=I==="top"?b.top-S.height-yt:b.bottom+yt;let z=b.left+b.width/2-S.width/2;z=Math.max(8,Math.min(z,k-S.width-8)),d({left:z,top:v,placement:I})},[i]),h=x.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),o)},[o]),y=x.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return x.useEffect(()=>{if(!l)return;const m=requestAnimationFrame(u);return()=>cancelAnimationFrame(m)},[l,u]),x.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:h,onMouseLeave:y,onFocus:h,onBlur:y,style:{display:"inline-block",...r},children:n}),l&&Ho.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-de,width:0,height:0,...a.placement==="top"?{bottom:-de,borderTop:`${de}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${de}px solid transparent`,borderRight:`${de}px solid transparent`}:{top:-de,borderBottom:`${de}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${de}px solid transparent`,borderRight:`${de}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${de-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${de-1}px solid transparent`,borderRight:`${de-1}px solid transparent`}:{top:-5,borderBottom:`${de-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${de-1}px solid transparent`,borderRight:`${de-1}px solid transparent`}}})]})]}),document.body)]})},Mn={A:"fine",B:"rough",C:"rough",D:"ocr"};function Gr(t){return typeof t!="string"?null:t in Si?t:t in Mn?Mn[t]:null}const Ur={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Yr={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ge(t){return typeof t!="string"?"":Ur[t]??Yr[t]??t}const Kr=["〇","一","二","三","四","五","六","七","八","九"],Pn=["","十","百","千"],Jr=["","萬","億"];function Ai(t){if(t===0)return"〇";if(t<0)return`負${Ai(-t)}`;const n=[];let i=t,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(qr(s,o>0)+Jr[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function qr(t,n){const i=[];let o=t;for(;o>0;)i.unshift(o%10),o=Math.floor(o/10);let s="";for(let r=0;r<i.length;r++){const l=i[r],c=i.length-1-r;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&r===0&&!n?s+=Pn[c]:s+=Kr[l]+Pn[c]}return s.replace(/〇$/,"")}let ut=null,vt=null;const zt=new Set;function Xr(){return ut?Promise.resolve():vt||(vt=import("opencc-js/t2cn").then(t=>{ut=t.Converter({from:"tw",to:"cn"}),zt.forEach(n=>n())}).catch(()=>{ut=t=>t,zt.forEach(t=>t())}),vt)}function Re(){const[,t]=x.useState(0);return x.useEffect(()=>{if(ut)return;const n=()=>t(i=>i+1);return zt.add(n),Xr(),()=>{zt.delete(n)}},[]),ut??(n=>n)}function Xe(t,n){return n(t).toLowerCase()}const sn="var(--bim-highlight-bg, #fff59d)";function Ze(t,n,i){if(!n)return t;const o=Xe(n,i);if(!o)return t;const s=Xe(t,i);if(s.length!==t.length)return t;const r=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(o,l);if(a===-1){r.push(t.slice(l));break}a>l&&r.push(t.slice(l,a)),r.push(e.jsx("mark",{style:{background:sn,padding:0,color:"inherit"},children:t.slice(a,a+o.length)},c++)),l=a+o.length}return e.jsx(e.Fragment,{children:r})}function ln(t,n,i,o){if(!n)return!0;const s=Xe(n,o);return(i?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(l=>typeof l=="string"&&Xe(l,o).includes(s))}function Zr(t,n,i){return n?Xe(t,i).includes(Xe(n,i)):!0}const an={类:"var(--bim-section-lei, #8e6f3e)",书:"var(--bim-section-shu, #c0392b)",序:"var(--bim-section-xu, #1a5276)",结语:"var(--bim-section-jieyu, #7d6608)",注释:"var(--bim-section-zhushi, #6c5b7b)"},Qr={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function es(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 Fi({file:t,isActive:n,onSelect:i,meta:o,matchState:s}){const r=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=es(t),d=!!(o!=null&&o.vol_label)&&!a.includes(o.vol_label);return e.jsxs("button",{onClick:()=>{r||i(t)},disabled:r,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":r?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":c?`${sn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":r?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:r?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:r?.5:1},children:[a,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",o.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Mi(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(o=>Mi(o,n)))}function Pi(t){var o;const n=t.files.length,i=((o=t.children)==null?void 0:o.reduce((s,r)=>s+Pi(r),0))||0;return n+i}function ts(t,n){const i=[],o=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(o)};if(o(t),i.length===0)return;const s=i.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let r=0;for(const l of s)typeof l=="number"&&(r+=l);return r}function Hi({group:t,activeFile:n,onSelect:i,depth:o=0,juanMeta:s,matchStates:r}){var h;const l=Mi(t,n||""),c=ts(t,r),a=typeof c=="number"&&c>0,d=c===0,[p,f]=x.useState(l||a),g=Pi(t),u=!!((h=t.children)!=null&&h.length);if(x.useEffect(()=>{l&&f(!0)},[l]),x.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!u){const y=t.files[0],m=n===y,j=r[y],b=j===0,S=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{b||i(y)},disabled:b,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+o*16}px`,border:m?"1px solid var(--bim-primary, #8e6f3e)":b?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:m?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${sn}40`:"transparent",color:m?"var(--bim-primary, #8e6f3e)":b?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:b?"not-allowed":"pointer",fontSize:"12px",fontWeight:m?600:400,lineHeight:1.4,opacity:b?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:j}),S&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>f(!p),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",g,")"]}),a&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),p&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+o*16}px`},children:t.files.map(y=>e.jsx(Fi,{file:y,isActive:n===y,onSelect:i,meta:s==null?void 0:s[y],matchState:r[y]},y))}),u&&t.children.map((y,m)=>e.jsx(Hi,{group:y,activeFile:n,onSelect:i,depth:o+1,juanMeta:s,matchStates:r},m))]})]})}function ns({files:t,groups:n,activeFile:i,onSelect:o,juanMeta:s,matchStates:r}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,a)=>e.jsx(Hi,{group:c,activeFile:i,onSelect:o,juanMeta:s,matchStates:r},a))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(c=>e.jsx(Fi,{file:c,isActive:i===c,onSelect:o,meta:s==null?void 0:s[c],matchState:r[c]},c))})}function is({type:t}){const n=an[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 os({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=V(),s=me(),r=Re(),l=y=>{if(!y)return"";const m=o(y);return i?Ze(m,i,r):m},[c,a]=x.useState(!1),d=!!t.summary,p=!!t.comment,f=!!t.additional_comment,g=!!(t.content&&t.content.length>60),u=d||p||f||g;x.useEffect(()=>{i&&a(!0)},[i]);const h=!c&&g?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>u&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:u?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Ai(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&u&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!d&&!p&&!f&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function rs({section:t,highlightQuery:n=""}){const{convert:i}=V(),o=Re(),s=a=>{if(!a)return"";const d=i(a);return n?Ze(d,n,o):d},[r,l]=x.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!r),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(is,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:r?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),r&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${an[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 ss({section:t,highlightQuery:n=""}){const{convert:i}=V(),o=Re();if(ge(t.type)==="page_header"||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
-
`)),r=n?
|
|
3
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:r.map((l,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!r[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},p):e.jsx(x.Fragment,{children:s(d)},p))},c)})})}function ps({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=V(),s=me(),r=Re(),l=d=>{if(!d)return"";const p=o(d);return i?Ze(p,i,r):p},c=[];let a=null;for(const d of t){const p=ge(d.type);p!=="page_header"&&(p==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(a||(a={category:"",items:[]}),a.items.push(d)):(p==="序"||p==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),p==="结语"&&(c.push(a),a=null)))}return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,p)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((f,g)=>ge(f.type)==="序"||ge(f.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(f.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&f.work_id?e.jsx("a",{href:s(f.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),u.stopPropagation(),n(f.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(f.title),children:e.jsx("strong",{children:l(f.title)})}):e.jsx("strong",{children:l(f.title)}),f.content&&l(f.content)]},g))]},p))})}function us({juan:t,rawText:n,searchQuery:i,onNavigate:o}){const{convert:s}=V(),r=Re(),[l,c]=x.useState("catalog"),a=i.trim(),d=x.useMemo(()=>a?t.sections.filter(u=>ln(u,a,!1,r)):t.sections,[t.sections,a,r]),p=t.sections.filter(u=>ge(u.type)==="书").length,f=t.sections.filter(u=>ge(u.type)==="诗").length,g=a?d.filter(u=>ge(u.type)==="书"||ge(u.type)==="诗").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(u=>e.jsx("button",{onClick:()=>c(u),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:u==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${f>0?`${f} 首`:`${p} 部書`}`:f>0?`${f} 首`:`${p} 部书`})]}),l==="raw"&&(n?e.jsx(ds,{text:n,highlightQuery:a}):e.jsx(ps,{sections:t.sections,onNavigate:o,highlightQuery:a})),l==="catalog"&&d.map((u,h)=>{const y=ge(u.type);return y==="书"||y==="诗"||y==="考证"?e.jsx(os,{section:u,onNavigate:o,highlightQuery:a},h):y==="类"?e.jsx(rs,{section:u,highlightQuery:a},h):e.jsx(ss,{section:u,highlightQuery:a},h)}),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Di(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 Hn(t){const n=Di(t);return n.length>0?n[0]:null}function xs(t){const{workId:n,transport:i,files:o,activeFile:s,activeJuan:r,activeRawText:l,query:c,isKaozhen:a}=t,d=Re(),p=x.useRef(new Map),[f,g]=x.useState({});x.useEffect(()=>{s&&r&&p.current.set(s,{juan:r,rawText:l})},[s,r,l]),x.useEffect(()=>{p.current.clear(),g({})},[n]);const u=x.useCallback((h,y)=>{let m=0;if(h.juan)for(const j of h.juan.sections)ln(j,y,a,d)&&m++;return m===0&&h.rawText&&Zr(h.rawText,y,d)&&(m=1),m},[a,d]);return x.useEffect(()=>{const h=c.trim();if(!h){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||o.length===0)return;let y=!1;const m={},j=[];for(const I of o){const v=p.current.get(I);v?m[I]=u(v,h):(m[I]="loading",j.push(I))}g(m);const b=8;let S=0;const _=async()=>{var I;for(;S<j.length;){if(y)return;const v=S++,z=j[v];try{const[T,w]=await Promise.all([i.getCollatedJuan(n,z),((I=i.getCollatedJuanText)==null?void 0:I.call(i,n,z))??Promise.resolve(null)]),C={juan:T,rawText:w};if(p.current.set(z,C),y)return;g(W=>({...W,[z]:u(C,h)}))}catch{if(y)return;g(T=>({...T,[z]:0}))}}},k=Array.from({length:Math.min(b,j.length)},()=>_());return Promise.all(k),()=>{y=!0}},[c,n,i,o.join(","),u,d]),{matchStates:f}}const cn=({index:t,workId:n,transport:i,onNavigate:o,activeJuan:s,onJuanChange:r,className:l,style:c})=>{const[a,d]=x.useState(null),[p,f]=x.useState(!1),[g,u]=x.useState(null),[h,y]=x.useState(null),[m,j]=x.useState(null),[b,S]=x.useState(!1),[_,k]=x.useState(null),[I,v]=x.useState(""),z=x.useRef(new Map),T=s??h,w=x.useCallback($=>{y($),r==null||r($)},[r]),C=t||a;x.useEffect(()=>{t&&(f(!1),u(null))},[t]),x.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let $=!1;return f(!0),u(null),i.getCollatedEditionIndex(n).then(A=>{if(!$)if(!A)u("未找到整理本数据");else{d(A);const L=Hn(A);!s&&L&&w(L)}}).catch(A=>{$||u(A instanceof Error?A.message:"加载失败")}).finally(()=>{$||f(!1)}),()=>{$=!0}},[t,n,i,s,w]),x.useEffect(()=>{const $=t||a;if($&&!T){const A=Hn($);A&&w(A)}},[t,a,T,w]);const W=n||(C==null?void 0:C.work_id),R=x.useCallback(async $=>{var A;if(!(!W||!(i!=null&&i.getCollatedJuan))){S(!0),j(null),k(null);try{const[L,E]=await Promise.all([i.getCollatedJuan(W,$),((A=i.getCollatedJuanText)==null?void 0:A.call(i,W,$))??Promise.resolve(null)]);j(L),k(E)}catch{j(null),k(null)}finally{S(!1)}}},[W,i]);x.useEffect(()=>{T&&R(T)},[T,R]);const M=$=>{w($)};if(p)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!C)return null;const F=C.type==="kaozhen",P=Di(C);return e.jsx(fs,{className:l,style:c,index:C,allFiles:P,isKaozhen:F,effectiveWorkId:W,transport:i,activeFile:T,handleSelectFile:M,juanData:m,juanRawText:_,juanLoading:b,searchQuery:I,setSearchQuery:v,onNavigate:o,workLabelCacheRef:z})},fs=({className:t,style:n,index:i,allFiles:o,isKaozhen:s,effectiveWorkId:r,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:f,searchQuery:g,setSearchQuery:u,onNavigate:h,workLabelCacheRef:y})=>{const{matchStates:m}=xs({workId:r,transport:l,files:o,activeFile:c,activeJuan:d,activeRawText:p,query:g,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:g,onChange:j=>u(j.target.value),style:{width:"100%",maxWidth:"420px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s?e.jsxs(e.Fragment,{children:[i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 卷"]})}),i.text_quality&&(()=>{const j=Gr(i.text_quality.grade);return j?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(Vr,{content:Vo[j],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:Go[j],cursor:"help"},children:Si[j]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),e.jsx(ns,{files:o,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:m}),f?e.jsx(Oe,{}):d?s?e.jsx(cs,{juan:d,searchQuery:g,onNavigate:h,transport:l,workLabelCache:y}):e.jsx(us,{juan:d,rawText:p,searchQuery:g,onNavigate:h}):c?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,i.references&&i.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),i.references.map((j,b)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[b+1,". "]}),j.url?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:j.title}):e.jsx("span",{children:j.title}),j.author&&e.jsxs("span",{children:[",",j.author]}),j.note&&e.jsxs("span",{children:["。",j.note]})]},b))]})]})},gs={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},ms={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function hs(t){try{const n=new Date(t),i=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const dn=({items:t,loading:n})=>{const i=me();return n?e.jsx(Oe,{}):t.length===0?e.jsx("div",{style:bs,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=gs[o.type],r=ms[o.status];return e.jsxs("div",{style:ys,children:[e.jsxs("div",{style:vs,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Dn,background:s.color},children:s.label}),e.jsx("span",{style:{...Dn,background:r.color},children:r.label})]}),e.jsx("span",{style:js,children:hs(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:Ss,children:[o.resourceId&&e.jsx("a",{href:i(o.resourceId),style:On,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:On,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:ks,children:o.content}),o.reply&&e.jsxs("div",{style:ws,children:[e.jsx("div",{style:_s,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},bs={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},ys={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},vs={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Dn={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},js={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Ss={fontSize:"12px",marginBottom:"6px"},On={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},ks={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},ws={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},_s={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Yt=({transport:t,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:r})=>{const l=N(),[c,a]=x.useState(null),[d,p]=x.useState([]),[f,g]=x.useState("recommend"),[u,h]=x.useState([]),[y,m]=x.useState(!1),j=o??f,b=F=>{g(F),s==null||s(F)},[S,_]=x.useState(!0),[k,I]=x.useState(null),[v,z]=x.useState(null),[T,w]=x.useState(null);x.useEffect(()=>{let F=!1;if(t.getCounts)return t.getCounts().then(P=>{F||a({works:P.works,books:P.books,collections:P.collections})}).catch(()=>{}),()=>{F=!0}},[t]),x.useEffect(()=>{let F=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const $=await t.getRecommended();if($!=null&&$.groups)return $.groups.flatMap(A=>A.items.map(L=>({...L,group:A.name})))}catch{}return[]})().then(async $=>{if(F)return;const A=$.filter(E=>E.id);if(A.length===0){_(!1);return}const L=await Promise.all(A.map(async E=>{if(E.type)return{id:E.id,title:E.title,type:E.type,author:E.author,dynasty:E.dynasty,role:E.role,edition:E.edition,has_text:E.has_text,has_image:E.has_image,has_collated:E.has_collated,subtype:E.subtype,primary_name:E.primary_name,group:E.group,fallbackDescription:E.description};try{let D=null;if(t.getEntry)D=await t.getEntry(E.id);else{const te=await t.getItem(E.id);te&&(D={id:E.id,title:te.title||E.id,type:te.type||"work"})}if(D)return{...D,group:E.group,fallbackDescription:E.description}}catch{}return{id:E.id,title:E.title,type:q.extractType(E.id),group:E.group,fallbackDescription:E.description}}));F||(p(L.filter(E=>E!==null)),_(!1))}),()=>{F=!0}},[t,i]);const C=x.useRef(!1),W=x.useRef(!1),R=x.useRef(!1);x.useEffect(()=>{if(j!=="catalog"||C.current)return;const F=t.getCatalogProgress??t.getResourceProgress;if(!F)return;C.current=!0;let P=!1;return F.call(t).then($=>{P||I($)}).catch(()=>{C.current=!1}),()=>{P=!0}},[t,j]),x.useEffect(()=>{if(j!=="collection"||W.current||!t.getCollectionProgress)return;W.current=!0;let F=!1;return t.getCollectionProgress().then(P=>{F||z(P)}).catch(()=>{W.current=!1}),()=>{F=!0}},[t,j]),x.useEffect(()=>{if(j!=="site"||R.current||!t.getSiteProgress)return;R.current=!0;let F=!1;return t.getSiteProgress().then(P=>{F||w(P)}).catch(()=>{R.current=!1}),()=>{F=!0}},[t,j]),x.useEffect(()=>{if(!r||j!=="feedback")return;let F=!1;return m(!0),fetch(r).then(P=>P.json()).then(P=>{!F&&P.success&&h(P.items||[])}).catch(()=>{}).finally(()=>{F||m(!1)}),()=>{F=!0}},[r,j]);const M=F=>{switch(F){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(ot,{label:l.home.recommendTab,active:j==="recommend",onClick:()=>b("recommend")}),e.jsx(ot,{label:l.home.catalogTab,active:j==="catalog",onClick:()=>b("catalog")}),e.jsx(ot,{label:l.home.collectionTab,active:j==="collection",onClick:()=>b("collection")}),e.jsx(ot,{label:l.home.siteTab,active:j==="site",onClick:()=>b("site")}),r&&e.jsx(ot,{label:l.home.feedbackTab,active:j==="feedback",onClick:()=>b("feedback")})]}),j==="recommend"&&e.jsx(Cs,{recommended:d,loading:S,onNavigate:n,getIcon:M,t:l}),j==="catalog"&&e.jsx(Nn,{progress:k,t:l,onNavigate:n}),j==="collection"&&e.jsx(Nn,{progress:v,t:l,onNavigate:n}),j==="site"&&e.jsx(zs,{progress:T,t:l,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&r&&e.jsx(dn,{items:u,loading:y})]})})},ot=({label:t,active:n,onClick:i})=>e.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Cs=({recommended:t,loading:n,onNavigate:i,getIcon:o,t:s})=>{const r=me();if(n)return e.jsx(Oe,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:r(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:o(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),p&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]})]},d.id)})})]},c))})},Nn=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Oe,{});const o=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],r={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"var(--bim-progress-active, #f59e0b)",done:"var(--bim-progress-done, #10b981)",todo:"var(--bim-progress-todo, #9ca3af)"};return e.jsx("div",{children:s.map(c=>{const a=o.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),r[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Is,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},Is=({item:t,t:n,statusColor:i,onNavigate:o})=>{const s=me(),r=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&o?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?ht(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},zs=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Oe,{});const o=[...t.resources].sort((a,d)=>a.priority-d.priority),s=o.filter(a=>a.imported>0),r=o.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=i>0?Math.round(l/i*100):0;return e.jsxs("div",{children:[i>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-done, #10b981)"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>e.jsx(Vn,{item:a,t:n,totalWorks:i},a.id))})]}),r.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-todo, #9ca3af)"}}),n.home.statusTodo," (",r.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:r.map(a=>e.jsx(Vn,{item:a,t:n,totalWorks:i},a.id))})]})]})},Vn=({item:t,t:n,totalWorks:i})=>{const o=i>0?Math.round(t.imported/i*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&i>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Gn="(max-width: 768px)";function Ts(){const[t,n]=x.useState(()=>typeof window>"u"?!1:window.matchMedia(Gn).matches);return x.useEffect(()=>{const i=window.matchMedia(Gn),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),t}const Rs=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var P;const r=N(),{convert:l}=V(),c=Ts(),[a,d]=x.useState(null),[p,f]=x.useState(null),[g,u]=x.useState(!1),[h,y]=x.useState("detail"),[m,j]=x.useState([]),[b,S]=x.useState(!1),[_,k]=x.useState(null),[I,v]=x.useState(!1),z=x.useCallback(async $=>{if(!t.getCollatedEditionIndex){k(null);return}v(!0);try{const A=await t.getCollatedEditionIndex($);k(A)}catch{k(null)}finally{v(!1)}},[t]),T=x.useCallback(async $=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}S(!0);try{if(t.getCollectionCatalogs){const A=await t.getCollectionCatalogs($);j(A||[])}else if(t.getCollectionCatalog){const A=await t.getCollectionCatalog($);j(A?[{resource_id:"",data:A}]:[])}}catch{j([])}finally{S(!1)}},[t]),w=x.useCallback(async $=>{if(i){i($);return}d($),f(null),j([]),k(null),y("detail"),u(!0);try{const A=await t.getItem($.id);A&&(f(A),A.type==="collection"?T($.id):A.type==="work"&&A.has_collated&&z($.id))}catch(A){console.error("加载详情失败:",A)}finally{u(!1)}},[t,i,T,z]),C=x.useCallback(async $=>{f(null),j([]),k(null),y("detail"),u(!0);try{const A=await t.getItem($);A&&(f(A),d({id:$,title:A.title||$,type:A.type||"book"}),A.type==="collection"?T($):A.type==="work"&&A.has_collated&&z($))}catch(A){console.error("导航失败:",A)}finally{u(!1)}},[t,T,z]),W=(p==null?void 0:p.type)==="collection"&&(m.length>0||b)||(p==null?void 0:p.type)==="work"&&(_||I),R=c&&(g||p),M=x.useCallback(()=>{d(null),f(null),j([]),k(null),y("detail")},[]),F=e.jsx(e.Fragment,{children:g?e.jsx(Oe,{}):p?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:jt(h==="detail"),children:r.detailTab.basicInfo}),p.type==="collection"&&b&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:jt(!1),children:[r.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&m.map($=>e.jsx("button",{onClick:()=>y(`catalog:${$.resource_id}`),style:jt(h===`catalog:${$.resource_id}`),children:$.short_name?`${l($.short_name)}${r.detailTab.catalogSuffix}`:r.detailTab.collectionCatalog},$.resource_id)),p.type==="work"&&(_||I)&&e.jsxs("button",{onClick:()=>y("collated"),style:jt(h==="collated"),children:[r.detailTab.collatedEdition,I&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?e.jsx(on,{data:p,transport:t,onNavigate:C}):h.startsWith("catalog:")?e.jsx(rn,{data:(P=m.find($=>`catalog:${$.resource_id}`===h))==null?void 0:P.data,onNavigate:C}):h==="collated"?e.jsx(cn,{index:_||void 0,workId:p.id,transport:t,onNavigate:C}):null})]}):e.jsx(Yt,{transport:t,onNavigate:C,recommendedIds:o})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:R?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:M,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",r.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:F})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Ut,{transport:t,onEntryClick:w,hideModeIndicator:n}),!p&&e.jsx(Yt,{transport:t,onNavigate:C,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Ut,{transport:t,onEntryClick:w,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:F})]})};function jt(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 We(t){return t.replace(/\.md$/,"")}const Oi=({index:t,bookId:n,transport:i,activeChapter:o,onChapterChange:s})=>{const[r,l]=x.useState(t??null),[c,a]=x.useState(null),d=o!==void 0?o:c,p=x.useCallback(m=>{s?s(m):a(m)},[s]),[f,g]=x.useState(null),[u,h]=x.useState(!1);x.useEffect(()=>{t&&l(t)},[t]),x.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let m=!1;return i.getBookFullTextIndex(n).then(j=>{m||l(j)}),()=>{m=!0}},[n,i,t]),x.useEffect(()=>{if(!r||r.chapters.length===0)return;const m=We(r.chapters[0].file);if(!d){p(m);return}const j=We(d);r.chapters.some(S=>We(S.file)===j)||p(m)},[r,d,p]);const y=x.useMemo(()=>{if(!r||!d)return null;const m=We(d);return r.chapters.find(j=>We(j.file)===m)??null},[r,d]);return x.useEffect(()=>{if(!n||!y||!i.getBookFullTextChapter)return;let m=!1;return h(!0),g(null),i.getBookFullTextChapter(n,y.file).then(j=>{m||g(j)}).catch(()=>{m||g(null)}).finally(()=>{m||h(!1)}),()=>{m=!0}},[n,y,i]),r?r.chapters.length===0?e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"}):e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"stretch",minHeight:400},children:[e.jsxs("aside",{style:{flex:"0 0 240px",maxHeight:"calc(100vh - 200px)",overflowY:"auto",borderRight:"1px solid var(--bim-border, #e5e5e5)",paddingRight:12},children:[e.jsxs("div",{style:{padding:"8px 12px",fontSize:13,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:[r.version_label," · 共 ",r.total_chapters," ",(r.chapters.length===1,"章")]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:r.chapters.map(m=>{const j=We(m.file),b=j===We(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(j),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:b?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:b?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:b?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:m.title})},m.file)})})]}),e.jsxs("main",{style:{flex:1,maxHeight:"calc(100vh - 200px)",overflowY:"auto",paddingLeft:8},children:[y&&e.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[e.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:y.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:r.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:r.source.name}),r.source.license&&e.jsxs(e.Fragment,{children:[" · ",r.source.license]})]})]}),u&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!u&&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+/,"")}),!u&&!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:"加载全文目录…"})},Es=({data:t,onNavigate:n,className:i,style:o})=>{var p;const s=N(),{convert:r}=V(),[l,c]=x.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[a,d]=x.useState(null);return e.jsxs("div",{className:i,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:r(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(f=>e.jsx(Bs,{division:f,expanded:l===f.name,onToggle:()=>c(l===f.name?null:f.name),expandedCat:a,onCatToggle:g=>d(a===g?null:g),onNavigate:n},f.name))})]})},Bs=({division:t,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:r})=>{const{convert:l}=V(),c=t.categories.reduce((a,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return a+(p.zhulu||0)+(p.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(Ls,{category:a,expanded:o===d,onToggle:()=>s(d),onNavigate:r},a.name)})})]})},Ls=({category:t,expanded:n,onToggle:i,onNavigate:o})=>{var a,d,p,f;const{convert:s}=V(),r=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||r.length)+(((f=t.stats)==null?void 0:f.cunmu)||l.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(r.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[r.length>0&&e.jsx(Un,{label:"著錄",books:r,onNavigate:o}),l.length>0&&e.jsx(Un,{label:"存目",books:l,onNavigate:o})]})]})},Un=({label:t,books:n,onNavigate:i})=>{const{convert:o}=V(),s=me(),[r,l]=x.useState(n.length<=20),c=r?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&i?e.jsx("a",{href:s(a.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(a.title)}):o(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(a.author).slice(0,20)})]},d))}),!r&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ye=({title:t,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const r=N();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,i&&e.jsx("button",{onClick:i,style:$s,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ws,children:r.action.save})]})]}),s]})},Ws={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},$s={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ue=({label:t,value:n,onChange:i,placeholder:o,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:r=>i(r.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),$e=({value:t,onChange:n,placeholder:i})=>{const o=x.useRef(null);return x.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Tt=({children:t,color:n,style:i})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...i},children:t});function As(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const St=({value:t,onChange:n,label:i})=>{const[o,s]=x.useState(!1),r=x.useRef(null),l=As(t||"");return x.useEffect(()=>{o&&r.current&&r.current.focus()},[o]),!o&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Yn,children:i}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),e.jsx(Tt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Yn,children:i}),e.jsx("input",{ref:r,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Yn={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Fs(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 Ms(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ni=({items:t,onChange:n,onOpenEntityPicker:i})=>{const o=N(),[s,r]=x.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),r(t.length)},c=f=>{n(t.filter((g,u)=>u!==f)),s===f&&r(null)},a=(f,g,u)=>{const h=[...t];h[f]={...h[f],[g]:u},n(h)},d=(f,g)=>{const u=[...t];u[f]={...u[f],type:g,id:"",name:""},n(u),g==="bookID"&&i&&i(h=>{const y=[...t];y[f]={...y[f],id:h.id,name:h.title,type:"bookID"},n(y)})},p=f=>{i&&i(g=>{const u=[...t];u[f]={...u[f],id:g.id,name:g.title,type:"bookID"},n(u)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>r(s===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:f.name||`${o.editor.sourcePlaceholder} ${g+1}`}),f.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Fs(f.type),color:"white",borderRadius:"3px",fontWeight:500},children:Ms(f.type)}),e.jsx("button",{onClick:u=>{u.stopPropagation(),c(g)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&e.jsxs("div",{children:[e.jsx("label",{style:Te,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Kn,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...Kn,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),f.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:Te,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:Jn,children:o.action.changeType})]}),f.id&&f.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-source-bookid, #4caf50)",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"var(--bim-source-bookid, #4caf50)",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:f.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),e.jsx("button",{onClick:()=>p(g),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>p(g),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),f.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:Te,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:Jn,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:f.name,onChange:u=>a(g,"name",u.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Te,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:f.id,onChange:u=>a(g,"id",u.target.value),placeholder:"https://...",style:Ye})]})]}),f.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...Te,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Te,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:f.details,onChange:u=>a(g,"details",u.target.value),placeholder:o.editor.detailsPlaceholder,style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Te,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:f.position,onChange:u=>a(g,"position",u.target.value),placeholder:"如: 卷三, p.52",style:Ye})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Te,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:f.version,onChange:u=>a(g,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Te,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:f.processor_version,onChange:u=>a(g,"processor_version",u.target.value),placeholder:"如: v0.1",style:Ye})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},Te={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},Ye={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Kn={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 Vi(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function Gi(t){return!t||t.length===0?"":JSON.stringify(t)}const Ui=({entityType:t,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:r,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:f,onUnlinkEntity:g,onViewEntity:u,onCreateAndLink:h,onSaveRelations:y})=>{const m=N();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:m.section.relations})]}),y&&e.jsx("button",{onClick:y,style:Ps,children:m.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{direction:"up",title:m.relation.belongsToWork,entity:r,onView:u,onUnlink:()=>g("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(rt,{direction:"up",title:m.relation.containedInCollection,entity:l,onView:u,onUnlink:()=>g("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),r&&p&&p.length>0&&e.jsx(Ke,{direction:"horizontal",title:`${m.relation.siblingVersions} (${p.length})`,entities:p,onView:u,onAdd:()=>h("siblingBook","book",{workId:r.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{direction:"up",title:m.relation.parentWork,entity:o,onView:u,onUnlink:()=>g("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),c&&c.length>0&&e.jsx(Ke,{direction:"down",title:`${m.relation.childWorks} (${c.length})`,entities:c,onView:u,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),a&&a.length>0&&e.jsx(Ke,{direction:"down",title:`${m.relation.collectionImpl} (${a.length})`,entities:a,onView:u,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ke,{direction:"down",title:`${m.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>h("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(rt,{direction:"up",title:m.relation.correspondingWork,entity:r,onView:u,onUnlink:()=>g("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(rt,{direction:"up",title:m.relation.parentCollection,entity:s,onView:u,onUnlink:()=>g("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(Ke,{direction:"down",title:`${m.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:u,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ke,{direction:"down",title:`${m.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},rt=({direction:t,title:n,entity:i,onView:o,onUnlink:s,onLink:r,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:p,unlinkLabel:f})=>{const g=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",u=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:u}),e.jsx("span",{children:n})]}),i?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Yi(i.type)}),e.jsx("span",{style:{fontWeight:500},children:i.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(qn,{onClick:()=>o(i),title:p,children:"👁️"}),e.jsx(qn,{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(Kt,{onClick:r,children:c}),e.jsx(Kt,{onClick:l,primary:!0,children:a})]})]})},Ke=({direction:t,title:n,entities:i,onView:o,onAdd:s,addLabel:r,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=x.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=a?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(u=>e.jsxs("div",{onClick:()=>o(u),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Yi(u.type)}),e.jsx("span",{children:u.title})]},u.id)),i.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",i.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Kt,{onClick:s,primary:!0,children:["+ ",r]})})]})},qn=({onClick:t,title:n,danger:i,children:o})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),Kt=({onClick:t,primary:n,children:i})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:i});function Yi(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Ps={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"},Ki=({isOpen:t,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:r,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,f]=x.useState(""),g=d?l.filter(m=>m.id!==d):l;x.useEffect(()=>{t&&(f(""),c(""))},[t]);const u=m=>{f(m),c(m)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Hs,children:e.jsxs("div",{style:Ds,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),e.jsx("button",{onClick:s,style:Os,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:m=>u(m.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:Ns})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:Ot,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>e.jsxs("div",{onClick:()=>o(m),style:Vs,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):p?e.jsxs("div",{style:Ot,children:["未找到匹配的",h]}):e.jsxs("div",{style:Ot,children:["输入关键词搜索",h]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:r,style:Gs,children:["创建新",h,"并关联"]})]})]})})},Hs={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},Ds={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)"},Os={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},Ns={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"},Vs={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ot={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Gs={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Xn={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Us={work:"📜",book:"📖",collection:"📚",entity:"👤"},Ji=({isOpen:t,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:r})=>{const[l,c]=x.useState(""),a=x.useRef(null);x.useEffect(()=>{t&&(c((o==null?void 0:o.title)||""),setTimeout(()=>{var g,u;(g=a.current)==null||g.focus(),(u=a.current)==null||u.select()},100))},[t,o==null?void 0:o.title]);const d=g=>{g.key==="Enter"&&l.trim()?p():g.key==="Escape"&&r()},p=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!t)return null;const f=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${Xn[n]}`}};return e.jsx("div",{style:Ys,onClick:g=>{g.target===g.currentTarget&&r()},children:e.jsxs("div",{style:Ks,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Us[n]}),e.jsx("span",{children:f()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Xn[n]}名称...`,style:Js})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:r,style:qs,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...Xs,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Ys={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},Ks={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)"},Js={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"},qs={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Xs={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Zs(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function qi(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Qs(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 Xi=({isOpen:t,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:r=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:p})=>{const[f,g]=x.useState(""),[u,h]=x.useState([]),[y,m]=x.useState(!1),[j,b]=x.useState("recent");x.useEffect(()=>{t&&(g(""),h([]),b(o.length>0?"recent":"search"))},[t,o.length]),x.useEffect(()=>{if(!f.trim()){h([]);return}const z=setTimeout(async()=>{m(!0);try{h(await p(f,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(z)},[f,i,p]);const S=x.useCallback(z=>{g(z.target.value),z.target.value.trim()&&b("search")},[]),_=x.useCallback(z=>s?z.filter(T=>T.id!==s):z,[s]);if(!t)return null;const k=n||(i==="all"?"选择实体":`选择${qi(i)}`),I=_(o),v=_(u);return e.jsx("div",{style:tl,children:e.jsxs("div",{style:nl,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:k}),e.jsx("button",{onClick:a,style:il,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:ol}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),y&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),I.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(Zn,{active:j==="recent",onClick:()=>b("recent"),children:["最近使用 (",I.length,")"]}),e.jsxs(Zn,{active:j==="search",onClick:()=>b("search"),children:["搜索结果 ",v.length>0&&`(${v.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&I.length>0?e.jsx(Qn,{entities:I,onSelect:c}):f.trim()?y?e.jsx(Nt,{message:"搜索中..."}):v.length>0?e.jsx(Qn,{entities:v,onSelect:c}):e.jsx(Nt,{message:"未找到匹配的结果"}):e.jsx(Nt,{message:"输入关键词开始搜索"})}),r&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:rl,children:l||"创建新实体"})]})]})})},Zn=({active:t,onClick:n,children:i})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:i}),Qn=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(el,{entity:i,onClick:()=>n(i)},i.id))}),el=({entity:t,onClick:n})=>{const[i,o]=x.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:Zs(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:Qs(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:qi(t.type)})]})},Nt=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),tl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},nl={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)"},il={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},ol={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"},rl={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},sl={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)"},ll={work:"📜",collection:"📚",book:"📖",entity:"👤"},Zi=({data:t,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:r,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:f,onRelationsChange:g})=>{var ee;const u=N(),[h,y]=x.useState(!1),[m,j]=x.useState("work"),[b,S]=x.useState(""),[_,k]=x.useState(""),[I,v]=x.useState([]),[z,T]=x.useState(!1),[w,C]=x.useState(!1),[W,R]=x.useState("work"),[M,F]=x.useState(""),[P,$]=x.useState(),[A,L]=x.useState(!1),[E,D]=x.useState(null),[te,G]=x.useState([]);x.useRef(null);const Z=t.type,re=Z==="work",ne=Z==="collection",U=Z==="book",Y=x.useCallback((B,X)=>{n({...t,[B]:X})},[t,n]),ce=x.useCallback((B,X)=>{S(B),j(X),k(u.editor.selectToLink+u.indexType[X]),v([]),y(!0)},[u]),Ne=x.useCallback(B=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,B)},[o,t.id]),je=x.useCallback(B=>{s==null||s(B.id,B.type)},[s]),he=x.useCallback((B,X,se)=>{const J={...se,author:(se==null?void 0:se.author)||t.author,dynasty:(se==null?void 0:se.dynasty)||t.dynasty};R(X),F(B),$(J),C(!0)},[t.author,t.dynasty]),Ie=x.useCallback((B,X)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,M,{type:W,title:B,inheritData:X}),C(!1)},[o,t.id,M,W]),Le=x.useCallback(B=>{if(!B.trim()){v([]);return}T(!0),o!=null&&o.searchEntities&&o.searchEntities(B,m).then(X=>{v(X),T(!1)}).catch(()=>{v([]),T(!1)})},[o,m]),Se=x.useCallback(B=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,b,B.id),y(!1)},[o,t.id,b]),Ve=x.useCallback(()=>{i()},[i]),et=x.useCallback(B=>{D(()=>B),L(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(G).catch(()=>{})},[o]),O=x.useCallback((B,X)=>o!=null&&o.searchEntities?o.searchEntities(B,X==="all"?void 0:X):Promise.resolve([]),[o]),ie=x.useCallback(B=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(B),G(X=>[B,...X.filter(se=>se.id!==B.id)].slice(0,10)),E==null||E(B),L(!1),D(null)},[o,E]);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:ll[Z]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Tt,{children:t.id}),e.jsx(Tt,{color:sl[Z],children:u.indexType[Z]})]})}),e.jsx(ye,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(St,{label:re?u.editor.workTitle:ne?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:B=>Y("title",B)}),U&&e.jsx(St,{label:u.editor.belongsToWork,value:t.workName||"",onChange:B=>Y("workName",B)}),e.jsx(ue,{label:u.editor.authorLabel,value:t.author||"",onChange:B=>Y("author",B)}),e.jsx(ue,{label:u.editor.dynastyLabel,value:t.dynasty||"",onChange:B=>Y("dynasty",B)}),(U||ne)&&e.jsx(St,{label:u.editor.containedIn,value:t.collection||"",onChange:B=>Y("collection",B)}),(U||ne)&&e.jsx(ue,{label:u.editor.holderLabel,value:t.holder||"",onChange:B=>Y("holder",B)}),(U||ne)&&e.jsx(ue,{label:U?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:B=>Y("pages",B)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ue,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:B=>Y("firstImage",B)})})]})}),e.jsx(ye,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx($e,{value:t.description||"",onChange:B=>Y("description",B),placeholder:u.editor.descriptionPlaceholder})}),(((ee=t.additional_works)==null?void 0:ee.length)||0)>0&&e.jsx(ye,{title:u.section.additionalWorks,onSave:i,children:e.jsx(al,{items:t.additional_works||[],onChange:B=>Y("additional_works",B)})}),e.jsx(ye,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(cl,{items:t.indexed_by||[],onChange:B=>Y("indexed_by",B)})}),e.jsx(ye,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(dl,{items:t.emendated_by||[],onChange:B=>Y("emendated_by",B)})}),e.jsx(ye,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(Gt,{items:t.resources||[],onChange:B=>Y("resources",B),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(ye,{title:u.section.imageResources,onSave:i,children:e.jsx(Gt,{items:t.resources||[],onChange:B=>Y("resources",B),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(ye,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Ni,{items:Vi(t.sources||""),onChange:B=>Y("sources",Gi(B)),onOpenEntityPicker:et})}),(U||ne)&&e.jsx(ye,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx($e,{value:t.provenance||"",onChange:B=>Y("provenance",B),placeholder:u.editor.provenancePlaceholder})}),U&&e.jsx(ye,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx($e,{value:t.otherEditions||"",onChange:B=>Y("otherEditions",B),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(Ui,{entityType:Z,entityId:t.id,entityTitle:t.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:ce,onUnlinkEntity:Ne,onViewEntity:je,onCreateAndLink:he,onSaveRelations:Ve}),r&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:u.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:u.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:u.editor.deleteEntity})]}),e.jsx(Ki,{isOpen:h,entityType:m,title:_,onSelect:Se,onCancel:()=>y(!1),onCreate:()=>{y(!1),he(b,m)},searchResults:I,onSearch:Le,isLoading:z,excludeId:t.id}),e.jsx(Ji,{isOpen:w,entityType:W,relationField:M,inheritData:P,onConfirm:Ie,onCancel:()=>C(!1)}),e.jsx(Xi,{isOpen:A,title:u.action.selectBookOrWork,filterType:"all",recentEntities:te,excludeId:t.id,onSelect:ie,onCancel:()=>{L(!1),D(null)},onSearch:O})]})};function al({items:t,onChange:n}){const i=N(),o=(l,c,a)=>{const d=t.map((p,f)=>f===l?{...p,[c]:a}:p);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),r=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ue,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>o(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ue,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>o(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:r,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function Qi({items:t,onChange:n,showMeta:i,addLabel:o}){const s=N(),[r,l]=x.useState(null),c=(p,f,g)=>{const u=t.map((h,y)=>y===p?{...h,[f]:g||void 0}:h);n(u)},a=p=>{n(t.filter((f,g)=>g!==p)),r===p&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,f)=>{const g=r===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:f),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:p.source||s.editor.unnamedSource}),p.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:p.source_bid}),e.jsx("button",{onClick:u=>{u.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)"},children:"✕"})]}),!g&&i&&(p.title_info||p.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[p.title_info,p.title_info&&p.author_info&&" — ",p.author_info]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ue,{label:s.label.sourceName,value:p.source,onChange:u=>c(f,"source",u)}),e.jsx(ue,{label:s.label.sourceBid,value:p.source_bid||"",onChange:u=>c(f,"source_bid",u)})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ue,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(f,"title_info",u)}),e.jsx(ue,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(f,"author_info",u)})]}),e.jsx(ue,{label:s.label.edition,value:p.edition||"",onChange:u=>c(f,"edition",u)})]}),e.jsx($e,{value:p.summary||"",onChange:u=>c(f,"summary",u),placeholder:s.editor.summaryPlaceholder}),e.jsx($e,{value:p.comment||"",onChange:u=>c(f,"comment",u),placeholder:s.editor.commentPlaceholder}),e.jsx($e,{value:p.additional_comment||"",onChange:u=>c(f,"additional_comment",u),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:o})]})}function cl({items:t,onChange:n}){const i=N();return e.jsx(Qi,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function dl({items:t,onChange:n}){const i=N();return e.jsx(Qi,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function eo(t){var c,a,d,p,f,g,u;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",o=((p=t.current_location)==null?void 0:p.name)||"",s=(f=t.page_count)!=null&&f.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",r=typeof t.description=="object"&&t.description!==null&&t.description.text||"",l={id:t.id,title:t.title,type:t.type,author:n,dynasty:i,holder:o,pages:s,description:r,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const h=t;if(Array.isArray(h.related_works)){const y=h.related_works.find(m=>m.relation==="part_of");y&&(l.parentWorkId=y.id,l.parentWorkName=y.title)}}if(t.type==="book"){const h=t;l.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(l.collectionId=(u=h.contained_in[0])==null?void 0:u.id)}return l}function pl(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 ul=t=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:r,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:f,renderSectionActions:g,onDownloadResource:u,downloadStatuses:h,relations:y,onRelationsChange:m,headerExtra:j,className:b,style:S}=t;N();const[_,k]=x.useState(s),I=r?s:_;x.useEffect(()=>{s!==_&&k(s)},[s]);const v=x.useCallback(()=>{const M=I==="view"?"edit":"view";r?r(M):k(M)},[I,r]),[z,T]=x.useState(null);x.useEffect(()=>{i&&o&&o.getItem(i).then(M=>{M&&T(M)})},[i,o]);const w=n||z,C=x.useMemo(()=>w?eo(w):null,[w]),W=r||!n?e.jsx("button",{onClick:v,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:I==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:I==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:I==="view"?"切换到编辑模式":"切换到查看模式",children:I==="view"?"✏️ 编辑":"👁 查看"}):null,R=e.jsxs(e.Fragment,{children:[W,j]});return!w&&!C?e.jsx(Oe,{}):I==="view"?e.jsx(on,{data:w,transport:o,onNavigate:d?M=>d(M):void 0,renderLink:p,headerExtra:R,className:b,style:S}):C?e.jsxs("div",{className:b,style:S,children:[R&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:R}),e.jsx(Zi,{data:C,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:o,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:g,onDownloadResource:u,downloadStatuses:h,relations:y,onRelationsChange:m})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},ei=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],to=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const[s,r]=x.useState(null),[l,c]=x.useState(""),[a,d]=x.useState("idle"),[p,f]=x.useState(""),g=x.useRef(null);x.useEffect(()=>{t&&(r(null),c(""),d("idle"),f(""))},[t]),x.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=g.current)==null?void 0:m.focus()},100)},[s]),x.useEffect(()=>{if(a==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[a,n]),x.useEffect(()=>{if(!t)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const u=async()=>{if(!(!s||!l.trim())){d("submitting"),f("");try{await i({type:s,content:l.trim()}),d("success")}catch(m){d("error"),f(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&l.trim()&&a!=="submitting",y=ei.find(m=>m.value===s);return e.jsx("div",{style:xl,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:fl,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:gl,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:ml,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:jl,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:ei.map(m=>e.jsxs("button",{onClick:()=>r(m.value),style:{...hl,...s===m.value?bl:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:g,value:l,onChange:m=>c(m.target.value),placeholder:(y==null?void 0:y.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...yl,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:Sl,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:u,disabled:!h,style:{...vl,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},xl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},fl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},gl={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},ml={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},hl={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"},bl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},yl={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"},vl={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},jl={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Sl={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},kl=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[o,s]=x.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...wl,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(to,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},wl={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"},ti=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],no=({onSubmit:t})=>{const[n,i]=x.useState("bug"),[o,s]=x.useState(""),[r,l]=x.useState("idle"),[c,a]=x.useState(""),d=x.useRef(null);x.useEffect(()=>{n&&setTimeout(()=>{var u;return(u=d.current)==null?void 0:u.focus()},100)},[n]);const p=async()=>{if(!(!n||!o.trim())){l("submitting"),a("");try{await t({type:n,content:o.trim()}),l("success"),s(""),i("bug")}catch(u){l("error"),a(u instanceof Error?u.message:"提交失败,请稍后重试")}}},f=n&&o.trim()&&r!=="submitting",g=ti.find(u=>u.value===n);return r==="success"?e.jsx("div",{style:ni,children:e.jsxs("div",{style:Tl,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Rl,children:"继续提交"})]})}):e.jsxs("div",{style:ni,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:ti.map(u=>e.jsxs("button",{onClick:()=>i(u.value),style:{..._l,...n===u.value?Cl:{}},children:[e.jsx("span",{children:u.icon})," ",u.label]},u.value))}),e.jsx("textarea",{ref:d,value:o,onChange:u=>s(u.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:r==="submitting",style:{...Il}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[o.length," / 2000"]}),e.jsx("button",{onClick:p,disabled:!f,style:{...zl,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:r==="submitting"?"提交中...":"提交"})]}),r==="error"&&e.jsx("div",{style:El,children:c})]})},ni={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},_l={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"},Cl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Il={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"},zl={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Tl={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Rl={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},El={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function ii(t){return typeof t=="function"?t():t??"/api/feedback"}const io=({resourceId:t,apiUrl:n})=>{const[i,o]=x.useState([]),[s,r]=x.useState(!0),l=x.useCallback(async()=>{const a=ii(n);r(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&o(p.items)}catch{}finally{r(!1)}},[t,n]);x.useEffect(()=>{l()},[l]);const c=async a=>{const d=ii(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!p.ok){const f=await p.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(dn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(no,{onSubmit:c})})]})},oo=1e3,Bl="(max-width: 719px)",ro=`
|
|
1
|
+
"use strict";var Go=Object.create;var Rn=Object.defineProperty;var Uo=Object.getOwnPropertyDescriptor;var Yo=Object.getOwnPropertyNames;var Ko=Object.getPrototypeOf,Jo=Object.prototype.hasOwnProperty;var qo=(t,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Yo(n))!Jo.call(t,s)&&s!==i&&Rn(t,s,{get:()=>n[s],enumerable:!(o=Uo(n,s))||o.enumerable});return t};var nt=(t,n,i)=>(i=t!=null?Go(Ko(t)):{},qo(n||!t||!t.__esModule?Rn(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("./storage-entry-BszwT2ej.cjs"),e=require("react/jsx-runtime"),u=require("react"),Xo=require("react-markdown"),Zo=require("remark-gfm"),Qo=require("react-dom"),er=t=>`/book-index?id=${t}`,_i=u.createContext(er);function tr({buildUrl:t,children:n}){const i=u.useMemo(()=>t,[t]);return e.jsx(_i.Provider,{value:i,children:n})}function me(){return u.useContext(_i)}function De(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function nr(t,n){return De(t).includes(n)}const Ci={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ir={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},or={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},bt=u.createContext(null),Ii={indexType:{work:"作品",book:"書籍",collection:"叢編",entity:"人物"},resourceType:{text:"文字資源",image:"圖片資源",textImage:"文字+圖片資源",physical:"館藏"},resourceTypeShort:{text:"文字",image:"圖片",textImage:"文字+圖片",physical:"館藏"},rootType:{catalog:"目錄式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"刪除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"訪問 →",view:"查看 →",viewEntity:"查看",copy:"複製 ID",copied:"已複製",linkExisting:"+ 關聯現有",createAndLink:"+ 創建並關聯",remove:"刪除",clearAll:"清除全部",reselect:"重選",changeType:"更換類型",expand:"展開",collapse:"收起",expandMore:"展開更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加書籍",addSubCollection:"添加子叢編",addCollectionImpl:"添加叢編實現",addSource:"添加來源",addResource:"添加資源",addIndexedBy:"+ 添加收錄來源",addEmendatedBy:"+ 添加考證來源",addAdditionalWork:"+ 添加附屬作品",selectBookOrWork:"選擇書籍/作品",clickToSelectBookOrWork:"點擊選擇書籍/作品",unlink:"解除關聯"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷數",pageCount:"頁數 (Pages)",volumeCount:"冊數 (Volumes)",holder:"現藏於 (Holder)",firstImage:"首頁圖片 (First Image URL)",year:"年代",currentLocation:"現藏",parentWork:"上級作品",relatedWorks:"相關作品",type:"類型",rootType:"根類型",coverageLevel:"覆蓋層級",coverageRange:"覆蓋範圍",metadata:"元數據",optionalInfo:"可選信息",details:"詳細說明",detailsOptional:"詳細說明 (可選)",positionOptional:"位置/頁碼 (可選)",dataVersionOptional:"數據版本 (可選)",processorVersionOptional:"處理器版本 (可選)",sourceName:"來源名稱",sourceBid:"來源 BID",titleInfo:"題名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介紹 (Description)",additionalWorks:"📑 附屬作品 (Additional Works)",indexedBy:"📖 著錄於",emendatedBy:"📝 考證",resources:"資源",textResources:"📝 文字資源 (Text Resources)",imageResources:"🖼️ 圖片資源 (Image Resources)",sources:"📚 資料來源 (Sources)",provenance:"📜 收藏歷史 (Provenance)",relatedVersions:"相關版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危險區域 (Danger Zone)",aliases:"別名",attachedTexts:"附載篇目",appendix:"附錄",containedIn:"收入",belongsToWork:"所屬作品",locationHistory:"流轉歷史",historyOverview:"歷史沿革",containedBooks:"收錄書籍",relations:"關聯關係",summary:"提要",comment:"按語",additionalComment:"附按",indexed:"收錄於",emendated:"考證",relatedWorks:"相關作品",containedWorks:"包含作品",adaptations:"改編作品",derivativeWorks:"續書與評註",studies:"所考典籍"},relation:{belongsToWork:"所屬作品 (Work)",containedInCollection:"收入叢編",siblingVersions:"同作品其他版本",addVersionForWork:"為此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"叢編實現",allVersions:"所有版本",correspondingWork:"對應作品 (Work)",parentCollection:"父叢編 (Parent Collection)",childCollections:"子叢編",containedBooks:"包含書籍",notLinked:"(未關聯)",none:"(暫無)"},search:{placeholder:"搜索作品、書籍、叢編...",searching:"搜索中...",loading:"加載中...",noResults:"無匹配結果",noResultsFor:"未找到與「{query}」相關的結果",tryOther:"試試其他關鍵詞、別名或作者名",recentBrowse:"最近瀏覽",history:"搜索歷史",clearAll:"清除全部",clearRecent:"清除最近瀏覽",itemNotFound:"無法找到,可能已刪除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"輸入關鍵詞搜索作品、書籍或叢編",searchBookName:"搜索書名...",alias:"別名"},home:{title:"古籍索引",subtitle:"從左側搜索框輸入關鍵詞,查找作品、書籍或叢編",recommendedBrowse:"推薦瀏覽",catalogTab:"目錄",collectionTab:"叢編",siteTab:"在線資源",recommendTab:"推薦",feedbackTab:"反饋",statusInProgress:"進行中",statusDone:"已完成",statusTodo:"未開始",typeCatalog:"目錄",typeCollection:"資源集合",totalPending:"待統計",progressFormat:"{imported} / {total}",siteCoverage:"資源覆蓋"},browser:{title:"古籍資源索引",subtitle:""},detailTab:{basicInfo:"概覽",catalog:"目錄",collectionCatalog:"叢編目錄",collatedEdition:"整理本",catalogSuffix:"·目錄",fullText:"全文",lineage:"版本傳承",feedback:"勘誤反饋",dataSource:"數據源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"數據源與授權"},metadata:{edition:"版本",version:"修訂版本",quality:"資源質量",check_type:"校對",image_source:"影像來源",team:"所屬團隊",publisher:"出版社",year:"出版年份",format:"格式",note:"備註",total_page:"頁數",total_pages:"總頁數",page_range:"頁碼範圍",page_count:"頁數",file_page_range:"文件頁碼",file_page_count:"文件頁數",content_page_range:"影印頁碼",volume:"冊",color_mode:"色彩",paragraph_count:"段落數",has_translation:"翻譯"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"叢書名 (Collection Title)",bookTitle:"書名 (Book Title)",belongsToWork:"所屬作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入叢編",holderLabel:"現藏於 (Holder)",pageLabel:"頁數 (Pages)",volumeLabel:"冊數 (Volumes)",firstImageLabel:"首頁圖片 (First Image URL)",descriptionPlaceholder:"簡要介紹...",provenancePlaceholder:"該資源的流轉與收藏記錄...",otherEditionsPlaceholder:"相關版本的 ID...",dangerZoneDesc:"從索引庫中永久刪除該實體的所有元數據文件。",deleteEntity:"刪除該實體 (Delete Entity)",selectToLink:"選擇要關聯的",unnamedSource:"(未命名來源)",selectSourceType:"選擇來源類型",fromExistingBook:"從現有書籍選擇",enterUrl:"輸入網址鏈接",sourceNamePlaceholder:"如: 維基文庫、中國基本古籍庫",deleteThisSource:"刪除此來源",deleteThisResource:"刪除此資源",resourcePlaceholder:"資源",idAutoExtract:"ID (自動從URL提取)",resourceName:"資源名稱",resourceUrl:"資源鏈接 (URL)",structurePlaceholder:"層級結構 (如: 冊、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"詳細說明",summaryPlaceholder:"提要...",commentPlaceholder:"按語...",additionalCommentPlaceholder:"附按...",imageResourceLink:"圖片資源鏈接",bookNameLabel:"書名",sourcePlaceholder:"來源"},download:{completed:"下載完成",downloading:"下載中",downloadThis:"下載此資源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"點擊切換到同步模式",switchToLocal:"點擊切換到本地模式",switchToGithub:"點擊切換到 GitHub 同步模式",switchToDraft:"點擊切換到 draft 倉庫",switchToOfficial:"點擊切換到 official 倉庫",selectFolder:"選擇本地文件夾",configurePath:"配置同步路徑"},catalog:{totalVolumes:"共",processed:"已處理",contains:"收錄",matched:"已匹配",unmatched:"待匹配",source:"來源:",all:"全部",loading:"加載叢編目錄...",notFound:"未找到叢編目錄數據",loadFailed:"加載失敗",noMatch:"無匹配結果",unmatched_label:"未匹配",volume:"第 {n} 冊"},unit:{juan:"卷",volume:"冊",bu:"部",items:"條"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},rr={indexType:{work:"作品",book:"书籍",collection:"丛编",entity:"人物"},resourceType:{text:"文字资源",image:"图片资源",textImage:"文字+图片资源",physical:"馆藏"},resourceTypeShort:{text:"文字",image:"图片",textImage:"文字+图片",physical:"馆藏"},rootType:{catalog:"目录式",search:"搜索式"},status:{draft:"草稿",official:"正式"},checkType:{精校:{label:"精校",bg:"#e8f5e9",fg:"#2e7d32"},粗校:{label:"粗校",bg:"#fff3e0",fg:"#e65100"},AI整理:{label:"AI整理",bg:"#e3f2fd",fg:"#1565c0"}},action:{save:"保存",delete:"删除",newEntry:"+ 新建",viewAll:"查看全部 →",visit:"访问 →",view:"查看 →",viewEntity:"查看",copy:"复制 ID",copied:"已复制",linkExisting:"+ 关联现有",createAndLink:"+ 创建并关联",remove:"删除",clearAll:"清除全部",reselect:"重选",changeType:"更换类型",expand:"展开",collapse:"收起",expandMore:"展开更多",addSubWork:"添加子作品",addVersion:"添加新版本",addBook:"添加书籍",addSubCollection:"添加子丛编",addCollectionImpl:"添加丛编实现",addSource:"添加来源",addResource:"添加资源",addIndexedBy:"+ 添加收录来源",addEmendatedBy:"+ 添加考证来源",addAdditionalWork:"+ 添加附属作品",selectBookOrWork:"选择书籍/作品",clickToSelectBookOrWork:"点击选择书籍/作品",unlink:"解除关联"},label:{id:"ID:",author:"作者 (Author)",dynasty:"朝代/年份 (Dynasty/Year)",edition:"版本",juanCount:"卷数",pageCount:"页数 (Pages)",volumeCount:"册数 (Volumes)",holder:"现藏于 (Holder)",firstImage:"首页图片 (First Image URL)",year:"年代",currentLocation:"现藏",parentWork:"上级作品",relatedWorks:"相关作品",type:"类型",rootType:"根类型",coverageLevel:"覆盖层级",coverageRange:"覆盖范围",metadata:"元数据",optionalInfo:"可选信息",details:"详细说明",detailsOptional:"详细说明 (可选)",positionOptional:"位置/页码 (可选)",dataVersionOptional:"数据版本 (可选)",processorVersionOptional:"处理器版本 (可选)",sourceName:"来源名称",sourceBid:"来源 BID",titleInfo:"题名",authorInfo:"著者",urlAddress:"URL 地址"},section:{basicInfo:"📊 基本信息",description:"📝 介绍 (Description)",additionalWorks:"📑 附属作品 (Additional Works)",indexedBy:"📖 著录于",emendatedBy:"📝 考证",resources:"资源",textResources:"📝 文字资源 (Text Resources)",imageResources:"🖼️ 图片资源 (Image Resources)",sources:"📚 资料来源 (Sources)",provenance:"📜 收藏历史 (Provenance)",relatedVersions:"相关版本",otherEditions:"📚 其他版本 (Other Editions)",dangerZone:"危险区域 (Danger Zone)",aliases:"别名",attachedTexts:"附载篇目",appendix:"附录",containedIn:"收入",belongsToWork:"所属作品",locationHistory:"流转历史",historyOverview:"历史沿革",containedBooks:"收录书籍",relations:"关联关系",summary:"提要",comment:"按语",additionalComment:"附按",indexed:"收录于",emendated:"考证",relatedWorks:"相关作品",containedWorks:"包含作品",adaptations:"改编作品",derivativeWorks:"续书与评注",studies:"所考典籍"},relation:{belongsToWork:"所属作品 (Work)",containedInCollection:"收入丛编",siblingVersions:"同作品其他版本",addVersionForWork:"为此作品添加新版本",parentWork:"父作品 (Parent Work)",childWorks:"子作品",collectionImpl:"丛编实现",allVersions:"所有版本",correspondingWork:"对应作品 (Work)",parentCollection:"父丛编 (Parent Collection)",childCollections:"子丛编",containedBooks:"包含书籍",notLinked:"(未关联)",none:"(暂无)"},search:{placeholder:"搜索作品、书籍、丛编...",searching:"搜索中...",loading:"加载中...",noResults:"无匹配结果",noResultsFor:"未找到与「{query}」相关的结果",tryOther:"试试其他关键词、别名或作者名",recentBrowse:"最近浏览",history:"搜索历史",clearAll:"清除全部",clearRecent:"清除最近浏览",itemNotFound:"无法找到,可能已删除",removeFromRecent:"移除",searchTitle:"搜索古籍索引",searchSubtitle:"输入关键词搜索作品、书籍或丛编",searchBookName:"搜索书名...",alias:"别名"},home:{title:"古籍索引",subtitle:"从左侧搜索框输入关键词,查找作品、书籍或丛编",recommendedBrowse:"推荐浏览",catalogTab:"目录",collectionTab:"丛编",siteTab:"在线资源",recommendTab:"推荐",feedbackTab:"反馈",statusInProgress:"进行中",statusDone:"已完成",statusTodo:"未开始",typeCatalog:"目录",typeCollection:"资源集合",totalPending:"待统计",progressFormat:"{imported} / {total}",siteCoverage:"资源覆盖"},browser:{title:"古籍资源索引",subtitle:""},detailTab:{basicInfo:"概览",catalog:"目录",collectionCatalog:"丛编目录",collatedEdition:"整理本",catalogSuffix:"·目录",fullText:"全文",lineage:"版本传承",feedback:"勘误反馈",dataSource:"数据源",backToIndex:"典籍版本索引",submitVersion:"提交新版本",dataLicense:"数据源与授权"},metadata:{edition:"版本",version:"修订版本",quality:"资源质量",check_type:"校对",image_source:"影像来源",team:"所属团队",publisher:"出版社",year:"出版年份",format:"格式",note:"备注",total_page:"页数",total_pages:"总页数",page_range:"页码范围",page_count:"页数",file_page_range:"文件页码",file_page_count:"文件页数",content_page_range:"影印页码",volume:"册",color_mode:"色彩",paragraph_count:"段落数",has_translation:"翻译"},editor:{untitled:"未命名",workTitle:"作品名 (Work Title)",collectionTitle:"丛书名 (Collection Title)",bookTitle:"书名 (Book Title)",belongsToWork:"所属作品 (Work)",authorLabel:"作者 (Author)",dynastyLabel:"朝代/年份 (Dynasty/Year)",containedIn:"收入丛编",holderLabel:"现藏于 (Holder)",pageLabel:"页数 (Pages)",volumeLabel:"册数 (Volumes)",firstImageLabel:"首页图片 (First Image URL)",descriptionPlaceholder:"简要介绍...",provenancePlaceholder:"该资源的流转与收藏记录...",otherEditionsPlaceholder:"相关版本的 ID...",dangerZoneDesc:"从索引库中永久删除该实体的所有元数据文件。",deleteEntity:"删除该实体 (Delete Entity)",selectToLink:"选择要关联的",unnamedSource:"(未命名来源)",selectSourceType:"选择来源类型",fromExistingBook:"从现有书籍选择",enterUrl:"输入网址链接",sourceNamePlaceholder:"如: 维基文库、中国基本古籍库",deleteThisSource:"删除此来源",deleteThisResource:"删除此资源",resourcePlaceholder:"资源",idAutoExtract:"ID (自动从URL提取)",resourceName:"资源名称",resourceUrl:"资源链接 (URL)",structurePlaceholder:"层级结构 (如: 册、卷)",coverageRangePlaceholder:"如: 2,3,5-8",detailsPlaceholder:"详细说明",summaryPlaceholder:"提要...",commentPlaceholder:"按语...",additionalCommentPlaceholder:"附按...",imageResourceLink:"图片资源链接",bookNameLabel:"书名",sourcePlaceholder:"来源"},download:{completed:"下载完成",downloading:"下载中",downloadThis:"下载此资源"},mode:{localMode:"本地模式",syncMode:"同步模式:",githubSync:"GitHub 同步",switchToSync:"点击切换到同步模式",switchToLocal:"点击切换到本地模式",switchToGithub:"点击切换到 GitHub 同步模式",switchToDraft:"点击切换到 draft 仓库",switchToOfficial:"点击切换到 official 仓库",selectFolder:"选择本地文件夹",configurePath:"配置同步路径"},catalog:{totalVolumes:"共",processed:"已处理",contains:"收录",matched:"已匹配",unmatched:"待匹配",source:"来源:",all:"全部",loading:"加载丛编目录...",notFound:"未找到丛编目录数据",loadFailed:"加载失败",noMatch:"无匹配结果",unmatched_label:"未匹配",volume:"第 {n} 册"},unit:{juan:"卷",volume:"册",bu:"部",items:"条"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},sr={"zh-Hant":Ii,"zh-Hans":rr},zi="bim-locale";function lr(){try{const t=localStorage.getItem(zi);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function ar(t){try{localStorage.setItem(zi,t)}catch{}}const cr="zh-Hans",dr=({locale:t,onLocaleChange:n,children:i})=>{const[o,s]=u.useState(t??cr),r=t??o;u.useEffect(()=>{if(t)return;const p=lr();p&&p!==o&&s(p)},[]);const[l,c]=u.useState(null);u.useEffect(()=>{r==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const f=p.Converter({from:"tw",to:"cn"});c(()=>f)}).catch(()=>{c(()=>p=>p)}):c(null)},[r]);const a=u.useCallback(p=>{s(p),ar(p),n==null||n(p)},[n]),d=u.useMemo(()=>({locale:r,setLocale:a,messages:sr[r],converter:l}),[r,a,l]);return e.jsx(bt.Provider,{value:d,children:i})};function O(){const t=u.useContext(bt);return(t==null?void 0:t.messages)??Ii}const pr=2e3;function D(){const t=u.useContext(bt),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,o=u.useRef(new Map),s=u.useRef(n);s.current!==n&&(o.current.clear(),s.current=n);const r=u.useCallback(l=>{if(!l)return"";if(!i)return l;const c=o.current.get(l);if(c!==void 0)return c;const a=i(l);if(o.current.size>=pr){const d=o.current.keys().next().value;d!==void 0&&o.current.delete(d)}return o.current.set(l,a),a},[i]);return u.useMemo(()=>({convert:r,locale:n,isSimplified:n==="zh-Hans"}),[r,n])}function yt(t,n){return t.replace(/\{(\w+)\}/g,(i,o)=>String(n[o]??""))}function ur(t){if(!t)return"";try{const n=new URL(t).hostname,i={"zh.wikisource.org":"wikisource","www.shidianguji.com":"shidianguji","shidianguji.com":"shidianguji","archive.org":"archive","ctext.org":"ctext","read.nlc.cn":"nlc","www.digital.archives.go.jp":"japan_archives"};if(i[n])return i[n];const o=n.split(".");return o.length>=2?o[o.length-2]:n}catch{return""}}function xr(){return{id:"",name:"",url:"",type:"text",details:""}}const qt=({items:t,onChange:n,onDownload:i,downloadStatuses:o,filterType:s})=>{const r=O(),[l,c]=u.useState(null),a=[{value:"text",label:r.resourceTypeShort.text},{value:"image",label:r.resourceTypeShort.image},{value:"text+image",label:r.resourceTypeShort.textImage},{value:"physical",label:r.resourceTypeShort.physical}],d=[{value:"catalog",label:r.rootType.catalog},{value:"search",label:r.rootType.search}],p=y=>{if(!s)return!0;const k=De(y);return s==="text"?k.includes("text"):s==="image"?k.includes("image")||k.includes("physical"):s==="physical"?k.includes("physical"):k.includes(s)},f=t.map((y,k)=>({item:y,originalIndex:k})).filter(({item:y})=>p(y)),g=()=>{const y=xr();s&&(y.type=s),n([...t,y]),c(t.length)},x=y=>{n(t.filter((k,_)=>_!==y)),c(null)},h=(y,k,_)=>{const w=[...t];if(w[y]={...w[y],[k]:_},k==="url"&&!w[y].id){const z=ur(_);z&&(w[y].id=z)}n(w)},v=(y,k,_)=>{const z={...t[y].metadata||{}};_?z[k]=_:delete z[k],h(y,"metadata",Object.keys(z).length>0?z:void 0)},m=(y,k)=>{const _=k.trim()?k.split(/[,,、]/).map(w=>w.trim()).filter(Boolean):void 0;h(y,"structure",_)},j=(y,k,_)=>{const z=t[y].coverage||{level:1,ranges:""};k==="level"?z.level=parseInt(_)||1:z.ranges=_,h(y,"coverage",z.ranges?z:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[f.map(({item:y,originalIndex:k})=>{var _,w,z;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(l===k?null:k),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:l===k?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:fr(y.type??"text"),color:"#fff"},children:(()=>{var I,T;const S=De(y);return S.length===0?y.type??"text":S.length===1?((I=a.find(C=>C.value===S[0]))==null?void 0:I.label)??S[0]:S.includes("text")&&S.includes("image")?((T=a.find(C=>C.value==="text+image"))==null?void 0:T.label)??"text+image":S.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:y.name||`${r.editor.resourcePlaceholder} ${k+1}`}),y.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:y.id}),y.url&&e.jsx("a",{href:y.url,target:"_blank",rel:"noopener noreferrer",onClick:S=>S.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&y.url&&gr(k,o==null?void 0:o[k],i,r),e.jsx("button",{onClick:S=>{S.stopPropagation(),x(k)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:r.editor.deleteThisResource,children:"✕"})]}),l===k&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[nr(y,"image")&&y.url&&mr(y,r),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:it,children:[e.jsx("span",{style:ot,children:r.label.type}),e.jsx("select",{value:y.type,onChange:S=>h(k,"type",S.target.value),style:{...Ie,flex:1},children:a.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]}),e.jsxs("label",{style:it,children:[e.jsx("span",{style:ot,children:r.label.rootType}),e.jsx("select",{value:y.root_type||"catalog",onChange:S=>h(k,"root_type",S.target.value),style:{...Ie,flex:1},children:d.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:y.id,onChange:S=>h(k,"id",S.target.value),placeholder:r.editor.idAutoExtract,style:{...Ie,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:y.name,onChange:S=>h(k,"name",S.target.value),placeholder:r.editor.resourceName,style:{...Ie,flex:1}})]}),e.jsx("input",{type:"text",value:y.url,onChange:S=>h(k,"url",S.target.value),placeholder:r.editor.resourceUrl,style:Ie}),e.jsx("input",{type:"text",value:((_=y.structure)==null?void 0:_.join("、"))||"",onChange:S=>m(k,S.target.value),placeholder:r.editor.structurePlaceholder,style:Ie}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:it,children:[e.jsx("span",{style:ot,children:r.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((w=y.coverage)==null?void 0:w.level)??"",onChange:S=>j(k,"level",S.target.value),placeholder:"1",style:{...Ie,width:"60px"}})]}),e.jsxs("label",{style:{...it,flex:1},children:[e.jsx("span",{style:ot,children:r.label.coverageRange}),e.jsx("input",{type:"text",value:((z=y.coverage)==null?void 0:z.ranges)||"",onChange:S=>j(k,"ranges",S.target.value),placeholder:r.editor.coverageRangePlaceholder,style:{...Ie,flex:1}})]})]}),e.jsx("textarea",{value:y.details||"",onChange:S=>h(k,"details",S.target.value),placeholder:r.editor.detailsPlaceholder,style:{...Ie,minHeight:"60px",resize:"vertical"}}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",paddingTop:"8px",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:r.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(r.metadata).map(([S,I])=>{var T;return e.jsxs("label",{style:{...it,gap:"4px"},children:[e.jsx("span",{style:{...ot,minWidth:"56px"},children:I}),e.jsx("input",{type:"text",value:((T=y.metadata)==null?void 0:T[S])||"",onChange:C=>v(k,S,C.target.value),placeholder:I,style:{...Ie,flex:1}})]},S)})})]})]})]})]},k)}),e.jsxs("button",{onClick:g,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addResource})]})]})};function fr(t){switch(t){case"text":return"var(--bim-restype-text, #2196f3)";case"image":return"var(--bim-restype-image, #ff9800)";case"text+image":return"var(--bim-restype-text-image, #9c27b0)";case"physical":return"var(--bim-restype-physical, #795548)"}}function gr(t,n,i,o){const s=(n==null?void 0:n.status)==="downloading",r=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:l=>{l.stopPropagation(),s||i(t,"")},disabled:s,style:{background:"transparent",border:"none",color:r?"var(--bim-success, #4caf50)":s?"var(--bim-desc-fg, #717171)":"var(--bim-link-fg, #0066cc)",cursor:s?"default":"pointer",padding:"2px 6px",fontSize:"12px",opacity:s?.6:.9},title:r?o.download.completed:s?`${o.download.downloading} ${(n==null?void 0:n.progress)||0}%`:o.download.downloadThis,children:r?"✓":s?"⏳":"⬇"})}function mr(t,n){const i=/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(t.url)||t.url.includes("iiif")||t.url.includes("image");return e.jsx("div",{style:{marginBottom:"12px"},children:i?e.jsx("div",{style:{width:"100%",maxHeight:"150px",overflow:"hidden",borderRadius:"4px",background:"var(--bim-overlay-bg, #00000010)"},children:e.jsx("img",{src:t.url,alt:t.name,style:{width:"100%",height:"150px",objectFit:"contain"},onError:o=>{o.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const Ie={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},it={display:"flex",alignItems:"center",gap:"6px"},ot={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},hr={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function gt(t){try{return hr[new URL(t).hostname]}catch{return}}const En={text:0,image:1,physical:2};function nn(t){return t.length===0?"physical":[...t].sort((n,i)=>(En[n]??99)-(En[i]??99)).join("+")}function on(t){const n=l=>{const c=l.match(/^(.+?)·第(\d+)[冊册]$/);if(c)return[c[1],parseInt(c[2])];const a=l.match(/^(.+?)[·(](\d+)[)]?$/);return a?[a[1],parseInt(a[2])]:null},i=new Map;for(let l=0;l<t.length;l++){const c=t[l];if(c.volumes&&c.volumes.length>0)continue;const a=n(c.name);if(!a)continue;const[d,p]=a,f=`${d}|${nn(De(c))}`;i.has(f)||i.set(f,{base:{...c,name:d,url:"",volumes:[]},volumes:[],indices:[]});const g=i.get(f);g.volumes.push({volume:p,url:c.url||void 0,status:"found"}),g.indices.push(l)}const o=[],s=new Set;for(const l of i.values())if(!(l.volumes.length<2)){l.volumes.sort((c,a)=>c.volume-a.volume),l.base.volumes=l.volumes,l.base.expected_volumes=l.volumes.length,o.push(l.base);for(const c of l.indices)s.add(c)}const r=[...o];for(let l=0;l<t.length;l++)s.has(l)||r.push(t[l]);return r}function Ti(t){if(t.url)return t.url;for(const[n,i]of Object.entries(t))if(n.endsWith("_url")&&typeof i=="string")return i}function Ri(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Ti(n)}))}function rn(t){const n=Ri(t);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,o=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:o,expected:t.expected_volumes??i+o}}function sn(t){if(!t)return;const n=t.file_page_range||t.page_range;if(!n||typeof n!="string")return;const i=n.match(/^(\d+)/);return i?parseInt(i[1],10):void 0}function ln(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const o=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(o)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(o[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Bt(t){if(!t.url)return;const n=sn(t.metadata);return n?ln(t.url,n):t.url}const Bn={text:"var(--bim-restype-text, #2196f3)",image:"var(--bim-restype-image, #ff9800)","text+image":"var(--bim-restype-text-image, #9c27b0)",physical:"var(--bim-restype-physical, #795548)"};function br(t){return t.includes("text")&&t.includes("image")?Bn["text+image"]:Bn[t[0]||"physical"]}const an=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:o,renderLink:s})=>{const r=O(),{convert:l}=D(),c=u.useMemo(()=>on(t||[]),[t]),{mirrorGroups:a,ungroupedItems:d}=u.useMemo(()=>{const m=new Map,j=[];for(const y of c){const k=y.group;k?(m.has(k)||m.set(k,[]),m.get(k).push(y)):j.push(y)}for(const y of m.values())y.sort((k,_)=>{const w=z=>z.group_role==="origin"?0:z.group_role==="mirror"?1:2;return w(k)-w(_)});return{mirrorGroups:m,ungroupedItems:j}},[c]),p={text:r.resourceType.text,image:r.resourceType.image,"text+image":r.resourceType.textImage,physical:r.resourceType.physical},f=m=>p[m]?p[m]:m.split("+").map(j=>p[j]||j).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:r.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((m,j)=>e.jsx(Nt,{item:m},m.id||j))});const g=(m,j)=>{const y=i==null?void 0:i[m],k=(y==null?void 0:y.label)||m,_=y==null?void 0:y.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(k)}),_&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:l(_)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((w,z)=>e.jsx(Nt,{item:w,onNavigate:o,renderLink:s},w.id||z))})]},`group-${m}`)},x=new Map;for(const m of d){const j=nn(De(m));x.has(j)||x.set(j,[]),x.get(j).push(m)}const h=["text","image","text+image","physical"],v=[...h.filter(m=>x.has(m)),...[...x.keys()].filter(m=>!h.includes(m)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...a.entries()].map(([m,j])=>g(m,j)),v.map(m=>{const j=x.get(m),y=br(m.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:y,whiteSpace:"nowrap",flexShrink:0},children:f(m)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:j.map((k,_)=>e.jsx(Nt,{item:k,onNavigate:o,renderLink:s},k.id||_))})]},m)})]})},yr={bw:{label:"",bg:"var(--bim-colormode-bw-bg, #f5f5f5)",fg:"var(--bim-colormode-bw-fg, #757575)"},color:{label:"",bg:"var(--bim-colormode-color-bg, #fff8e1)",fg:"var(--bim-colormode-color-fg, #f57f17)"}},Nt=({item:t})=>{const n=O(),{convert:i}=D(),[o,s]=u.useState(!1),r=u.useMemo(()=>(t.url?gt(t.url):void 0)||i(t.name),[t.url,t.name,i]),l=u.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(h=>({...h,url:h.url||Ti(h)})),[t.volumes]),c=l&&l.length>0,a=c?new Set(l.filter(h=>h.status!=="missing").map(h=>h.volume)).size:0,d=c?new Set(l.filter(h=>h.status==="missing").map(h=>h.volume)).size:0,p=t.expected_volumes??(c?a+d:0),f=t.color_mode?{...yr[t.color_mode],label:n.colorMode[t.color_mode]}:null,g=t.details&&!c?i(t.details):null,x={display:"inline-flex",alignItems:"center",gap:"5px",padding:"4px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",background:"var(--bim-input-bg, #fff)",fontSize:"12px",color:"var(--bim-fg, #333)",lineHeight:1.4,verticalAlign:"middle"};return e.jsxs("div",{style:{display:"inline-flex",flexDirection:"column",gap:"4px"},children:[e.jsxs("div",{style:x,children:[e.jsx("span",{style:{fontWeight:500},children:r}),f&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:f.bg,color:f.fg},children:f.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[a,"/",p,n.unit.volume,d>0&&e.jsxs("span",{style:{color:"var(--bim-missing-fg, #e67e22)",marginLeft:"3px"},children:["缺",d]})]}),t.url&&e.jsx("a",{href:(()=>{const h=sn(t.metadata);return h?ln(t.url,h):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!o),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:o?"▲":"▼"})]}),c&&o&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:l.map(h=>{const v=h.status==="missing";return h.url&&!v?e.jsx("a",{href:h.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:h.volume},h.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:v?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:v?"line-through":"none",opacity:v?.6:1},children:h.volume},h.volume)})})]})},Ei=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:o,onToggleDraft:s,onConfigurePath:r,onSelectFolder:l})=>{const c=O(),a=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",f=p?p.split(/[/\\]/).pop()||p:"",g={display:"flex",alignItems:"center",gap:"6px",padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,cursor:"pointer",transition:"opacity 0.2s",border:"none",background:"var(--bim-primary-soft, #0078d415)",color:"var(--bim-primary, #0078d4)"},x={onMouseOver:v=>v.currentTarget.style.opacity="0.8",onMouseOut:v=>v.currentTarget.style.opacity="1"},h=e.jsxs("div",{onClick:s,title:d?c.mode.switchToOfficial:c.mode.switchToDraft,style:{...g,background:d?"var(--bim-warning, #ff9800)":"var(--bim-success, #4caf50)",color:"white"},...x,children:[e.jsx("span",{children:d?"📝":"📚"}),e.jsx("span",{children:d?"draft":"official"})]});return i==="index-browser"?a?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[h,e.jsxs("div",{onClick:o,title:c.mode.switchToSync,style:g,...x,children:[e.jsx("span",{children:"📁"}),e.jsx("span",{children:c.mode.localMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...x,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:o,title:c.mode.switchToLocal,style:g,...x,children:[e.jsx("span",{children:"🌐"}),e.jsx("span",{children:c.mode.syncMode}),e.jsx("span",{style:{opacity:.6,marginLeft:"4px"},children:"⇄"})]}),e.jsx("div",{onClick:r,title:f||c.mode.configurePath,style:{...g,background:"transparent",padding:"6px",fontSize:"12px"},...x,children:e.jsx("span",{children:"⚙️"})})]})]}):e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[e.jsxs("div",{onClick:o,title:a?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...x,children:[e.jsx("span",{children:a?"📁":"🌐"}),e.jsx("span",{children:a?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),a&&e.jsxs("div",{onClick:l,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...x,children:[e.jsx("span",{children:"📂"}),f&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:f})]}),!a&&f&&e.jsxs("div",{style:{...g,background:"var(--bim-mode-active-bg, #2196f3)",color:"white",cursor:"default"},title:p,children:[e.jsx("span",{children:"📂"}),e.jsx("span",{style:{fontSize:"11px"},children:f})]})]})},$t="bim-search-history",Ln=10,Wn=8;function pt(){try{const t=localStorage.getItem($t);return t?JSON.parse(t):[]}catch{return[]}}function vr(t){try{const n=pt().filter(i=>i!==t);n.unshift(t),n.length>Ln&&(n.length=Ln),localStorage.setItem($t,JSON.stringify(n))}catch{}}function jr(t){try{const n=pt().filter(i=>i!==t);localStorage.setItem($t,JSON.stringify(n))}catch{}}function Sr(){try{localStorage.removeItem($t)}catch{}}const Bi=({transport:t,value:n,onChange:i,onSearch:o,onEntrySelect:s,placeholder:r})=>{const l=O(),c=r??l.search.placeholder,a={work:l.indexType.work,book:l.indexType.book,collection:l.indexType.collection,entity:l.indexType.entity},[d,p]=u.useState(!1),[f,g]=u.useState([]),[x,h]=u.useState(-1),[v,m]=u.useState(pt),j=u.useRef(null),y=u.useRef(null),k=u.useRef(null),_=u.useRef(!1);u.useEffect(()=>{h(-1);const b=n.trim();if(!b){g(v.map(A=>({type:"history",text:A})));return}if(!t.searchAll){g([]);return}let R=!1;const E=setTimeout(()=>{t.searchAll(b,Wn).then(A=>{if(R)return;const M=[...A.works,...A.books,...A.collections,...A.entities??[]];g(M.slice(0,Wn).map(P=>({type:"entry",text:P.title||P.id,entry:P})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,v,t]),u.useEffect(()=>{const b=R=>{k.current&&!k.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]),u.useEffect(()=>{const b=R=>{var E,A;if(R.key==="/"&&document.activeElement!==j.current){const M=(E=document.activeElement)==null?void 0:E.tagName;if(M==="INPUT"||M==="TEXTAREA"||M==="SELECT")return;R.preventDefault(),(A=j.current)==null||A.focus()}};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[]);const w=u.useCallback(b=>{b.trim()&&(vr(b.trim()),m(pt())),o(b),p(!1)},[o]),z=u.useCallback(b=>{b.type==="history"?(i(b.text),w(b.text)):b.entry&&(s?(s(b.entry),p(!1)):(i(b.text),w(b.text)))},[i,w,s]),S=u.useCallback(b=>{if(!d||f.length===0){b.key==="Enter"&&w(n);return}switch(b.key){case"ArrowDown":b.preventDefault(),h(R=>(R+1)%f.length);break;case"ArrowUp":b.preventDefault(),h(R=>(R-1+f.length)%f.length);break;case"Enter":b.preventDefault(),x>=0&&x<f.length?z(f[x]):w(n);break;case"Escape":b.preventDefault(),p(!1);break}},[d,f,x,n,w,z]),I=u.useCallback((b,R)=>{R.stopPropagation(),jr(b),m(pt()),g(E=>E.filter(A=>!(A.type==="history"&&A.text===b)))},[]),T=u.useCallback(b=>{b.stopPropagation(),Sr(),m([]),g([])},[]);u.useEffect(()=>{if(x>=0&&y.current){const b=y.current.children;b[x]&&b[x].scrollIntoView({block:"nearest"})}},[x]);const C=!n.trim()&&v.length>0;return e.jsxs("div",{ref:k,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:j,type:"text",placeholder:c,value:n,onChange:b=>{i(b.target.value),p(!0)},onCompositionStart:()=>{_.current=!0},onCompositionEnd:()=>{_.current=!1},onFocus:()=>{p(!0)},onKeyDown:S,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&f.length>0&&e.jsxs("div",{ref:y,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[C&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:l.search.history}),e.jsx("button",{onClick:T,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:l.search.clearAll})]}),f.map((b,R)=>e.jsxs("div",{onClick:()=>z(b),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:R===x?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:b.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:b.text}),b.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[a[b.entry.type],b.entry.edition&&` · ${b.entry.edition}`,b.entry.author&&` · ${b.entry.author}`]}),b.type==="history"&&e.jsx("button",{onClick:E=>I(b.text,E),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:l.action.remove,children:"×"})]},`${b.type}-${b.text}-${R}`))]})]})},mt="bim-recent-ids",$n="bim-recent-entries",An=50,Vt=5,kr=50,wr=200;function ut(){try{const t=localStorage.getItem(mt);if(t)return JSON.parse(t);const n=localStorage.getItem($n);if(n){const i=JSON.parse(n).map(o=>o.id);return localStorage.setItem(mt,JSON.stringify(i)),localStorage.removeItem($n),i}return[]}catch{return[]}}function _r(t){try{const n=ut().filter(i=>i!==t);n.unshift(t),n.length>An&&(n.length=An),localStorage.setItem(mt,JSON.stringify(n))}catch{}}function Cr(t){try{const n=ut().filter(i=>i!==t);localStorage.setItem(mt,JSON.stringify(n))}catch{}}function Ir(){try{localStorage.removeItem(mt)}catch{}}const zr={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},Xt=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:o,onNewEntry:s,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a,hideModeIndicator:d,resultVariant:p="compact",renderEntry:f,initialQuery:g,onQueryChange:x,headerRight:h})=>{const v=O(),m=[{type:"work",icon:"✍️",name:v.indexType.work,key:"works"},{type:"book",icon:"📖",name:v.indexType.book,key:"books"},{type:"collection",icon:"📚",name:v.indexType.collection,key:"collections"},{type:"entity",icon:"👤",name:v.indexType.entity,key:"entities"}],[j,y]=u.useState(g??""),[k,_]=u.useState(null),[w,z]=u.useState(null),[S,I]=u.useState(!1),[T,C]=u.useState(null),[b,R]=u.useState(""),[E,A]=u.useState(!g),[M,P]=u.useState(ut),[$,F]=u.useState([]),[Q,W]=u.useState(!1),[U,ne]=u.useState(!1),[B,V]=u.useState(null),[Y,ie]=u.useState(null),G=u.useRef(void 0),K=u.useRef(!1),de=u.useCallback(async(N,oe)=>{if(!N.trim()){A(!0),_(null),z(null);return}A(!1),I(!0),R("");try{if(t.searchAll){const te=await t.searchAll(N,oe??Vt);_(te)}else{const te=["work","book","collection","entity"],L=await Promise.all(te.map(Z=>t.search(N,Z,{page:1,pageSize:oe??Vt})));_({works:L[0].entries,books:L[1].entries,collections:L[2].entries,entities:L[3].entries,totalWorks:L[0].total,totalBooks:L[1].total,totalCollections:L[2].total,totalEntities:L[3].total})}}catch(te){R(te instanceof Error?te.message:String(te)),_(null)}finally{I(!1)}},[t]);u.useEffect(()=>{let N=!1;const oe=()=>{var J,$e;const te=["work","book","collection","entity"],L=Promise.all(te.map(je=>t.loadEntries(je,{page:1,pageSize:1}).catch(()=>({total:0})))),Z=((J=t.getResourceCounts)==null?void 0:J.call(t).catch(()=>null))??Promise.resolve(null),se=(($e=t.getSubtypeStats)==null?void 0:$e.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([L,Z,se]).then(([je,fe,Ue])=>{N||(V({works:je[0].total,books:je[1].total,collections:je[2].total,entities:je[3].total,hasText:fe==null?void 0:fe.hasText,hasImage:fe==null?void 0:fe.hasImage}),Ue&&ie(Ue))})};return t.getCounts?t.getCounts().then(te=>{var L,Z;N||(V({works:te.works,books:te.books,collections:te.collections,entities:te.entities,hasText:(L=te.resourceCounts)==null?void 0:L.hasText,hasImage:(Z=te.resourceCounts)==null?void 0:Z.hasImage}),te.subtypeStats&&ie(te.subtypeStats))}).catch(()=>{N||oe()}):oe(),()=>{N=!0}},[t]),u.useEffect(()=>{K.current||!(g!=null&&g.trim())||(K.current=!0,de(g))},[g,de]);const he=u.useCallback(N=>{if(y(N),!N.trim()){x==null||x(N),A(!0),_(null),z(null);return}G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{z(null),x==null||x(N),de(N)},wr)},[de,x]),pe=u.useCallback(N=>{G.current&&clearTimeout(G.current),x==null||x(N),de(N)},[de,x]),le=u.useCallback(N=>{z(N),de(j,kr)},[j,de]);u.useEffect(()=>{if(!M.length){F([]);return}let N=!1;return W(!0),Promise.all(M.slice(0,10).map(async oe=>{var te,L,Z;try{if(t.getEntry){const J=await t.getEntry(oe);if(J)return J}const se=await t.getItem(oe);if(se){const J=se.authors;return{id:oe,title:se.title||oe,type:se.type||"work",author:(te=J==null?void 0:J[0])==null?void 0:te.name,dynasty:(L=J==null?void 0:J[0])==null?void 0:L.dynasty,role:(Z=J==null?void 0:J[0])==null?void 0:Z.role,edition:se.edition||void 0}}}catch{}return{id:oe,title:oe,type:"work",notFound:!0}})).then(oe=>{N||(F(oe),W(!1))}),()=>{N=!0}},[M,t]);const ve=N=>{C(N.id),_r(N.id),P(ut()),o==null||o(N)},Fe=N=>{Cr(N),P(ut())},_e=()=>{Ir(),P([])},Ge=N=>m.find(oe=>oe.type===N),tt=k&&(k.works.length>0||k.books.length>0||k.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:v.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[h,!d&&e.jsx(Ei,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:r,onToggleDraft:l,onConfigurePath:c,onSelectFolder:a})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Bi,{transport:t,value:j,onChange:he,onSearch:pe,onEntrySelect:ve}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:v.action.newEntry})]}),B&&E&&e.jsxs("div",{style:{padding:"0 20px 8px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",display:"flex",justifyContent:"space-between",flexWrap:"wrap",gap:"4px"},children:[e.jsx("span",{children:Y?e.jsxs(e.Fragment,{children:[(Y.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.books.toLocaleString()})," 本"]}),Y.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.article.toLocaleString()})," 篇"]}):null,Y.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:Y.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[v.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.collections.toLocaleString()}),B.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.entities.toLocaleString()})]})]})}),B.hasImage!=null&&B.hasText!=null&&e.jsxs("span",{children:[v.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),v.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:B.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:S?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:v.search.searching}):b?e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"24px",marginBottom:"8px"},children:"⚠️"}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)"},children:b})]}):E?e.jsx("div",{style:{flex:1},children:Q?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:v.search.loading}):$.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{padding:"8px 0",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{children:v.search.recentBrowse}),e.jsx("button",{onClick:_e,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"11px",padding:"2px 4px"},children:v.search.clearRecent})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:$.slice(0,U?10:3).map(N=>N.notFound?e.jsx(Rr,{id:N.id,onRemove:Fe,t:v},N.id):e.jsx(Mn,{entry:N,selected:T===N.id,onClick:ve,getConfig:Ge,onRemove:Fe},N.id))}),!U&&$.length>3&&e.jsx("button",{onClick:()=>ne(!0),style:{display:"block",margin:"8px auto 0",padding:"4px 16px",fontSize:"12px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:v.action.expandMore})]}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:v.search.searchTitle}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v.search.searchSubtitle})]})}):tt?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:m.map(({type:N,icon:oe,name:te,key:L})=>{const Z=k[L]??[],se=zr[L],J=k[se]??0;if(Z.length===0)return null;const je=!(w===N)&&J>Vt;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"6px"},children:[e.jsxs("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:[oe," ",te,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[J," ",v.unit.items]})]}),je&&e.jsx("button",{onClick:()=>le(N),style:{border:"none",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"12px"},children:v.action.viewAll})]}),e.jsx("div",{style:p==="card"?{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(340px, 100%), 1fr))",gap:"14px"}:{display:"flex",flexDirection:"column",gap:"4px"},children:Z.map(fe=>{if(f)return e.jsx(u.Fragment,{children:f(fe)},fe.id);const Ue=p==="card"?Tr:Mn;return e.jsx(Ue,{entry:fe,selected:T===fe.id,onClick:ve,getConfig:Ge,query:j},fe.id)})})]},N)})}):e.jsxs("div",{style:{textAlign:"center",padding:"40px"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"8px"},children:"📚"}),e.jsx("h3",{style:{margin:"0 0 8px",color:"var(--bim-fg, #333)"},children:yt(v.search.noResultsFor,{query:j})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v.search.tryOther})]})})]})},Tr=({entry:t,selected:n,onClick:i,getConfig:o,query:s})=>{const r=O(),{convert:l}=D(),c=l(t.title||t.primary_name||t.id),a=t.measure_info?l(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${r.unit.juan}`:"",d=[...t.additional_titles||[],...t.attached_texts||[]],p=s&&d.length?d.find(g=>{const x=typeof g=="string"?g:g==null?void 0:g.book_title;return x==null?void 0:x.toLowerCase().includes(s.toLowerCase())}):void 0,f="var(--bim-cover-accent, #8e6f3e)";return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",gap:"1.2rem",alignItems:"stretch",padding:"1.1rem 1.3rem",borderRadius:"12px",cursor:"pointer",background:"var(--bim-bg, #fff)",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",transition:"border-color .2s ease, transform .2s ease, box-shadow .2s ease"},children:[e.jsxs("div",{"aria-hidden":"true",style:{position:"relative",width:"92px",minHeight:"126px",flexShrink:0,borderRadius:"4px",border:`1px solid color-mix(in srgb, ${f} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${f} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${f} 7%, var(--bim-bg, #fff)))`,display:"flex",alignItems:"center",justifyContent:"center",padding:"0.6rem 0.3rem"},children:[e.jsx("span",{style:{position:"absolute",left:"6px",top:0,bottom:0,borderLeft:`1px dashed color-mix(in srgb, ${f} 45%, transparent)`}}),e.jsx("span",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-start",height:"108px",flexShrink:0,overflow:"hidden",fontSize:"1.05rem",fontWeight:700,lineHeight:1.25,color:f},children:Array.from(c).map((g,x)=>e.jsx("span",{children:g},x))})]}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"17px",fontWeight:600,color:"var(--bim-fg, #333)"},children:c}),a&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:a})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",l(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:l(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",l(t.role)]})]}),t.edition&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l(t.edition)}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[r.search.alias,":",l(typeof p=="string"?p:p.book_title||"")]}),e.jsxs("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"auto",paddingTop:"4px"},children:[e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[o(t.type).icon," ",o(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",r.misc.textResource]}),t.has_image&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["🖼️ ",r.misc.imageResource]})]})]})]})},Mn=({entry:t,selected:n,onClick:i,getConfig:o,query:s,onRemove:r})=>{const l=O(),{convert:c}=D(),a=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&a.length?a.find(p=>{const f=typeof p=="string"?p:p==null?void 0:p.book_title;return f==null?void 0:f.toLowerCase().includes(s.toLowerCase())}):void 0;return e.jsxs("div",{onClick:()=>i(t),style:{display:"flex",alignItems:"flex-start",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:n?"1px solid var(--bim-primary, #0078d4)":"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"2px",marginTop:"2px"},children:[e.jsx("span",{style:{fontSize:"16px"},children:o(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:o(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:l.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:l.misc.imageResource,children:"🖼️"})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.edition)}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,l.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[l.search.alias,":",c(d)]})]}),r?e.jsx("button",{onClick:p=>{p.stopPropagation(),r(t.id)},title:l.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},Rr=({id:t,onRemove:n,t:i})=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"6px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",opacity:.6},children:[e.jsx("span",{style:{fontSize:"16px"},children:"❓"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",fontFamily:"monospace"},children:t}),e.jsx("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginTop:"2px"},children:i.search.itemNotFound})]}),e.jsx("button",{onClick:()=>n(t),title:i.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1},children:"×"})]});function Er(t){var n;return!t.dynasty&&!t.birth_year&&!t.death_year&&(!t.alt_names||t.alt_names.length===0)&&!((n=t.description)!=null&&n.text)}function Br({data:t}){const{convert:n}=D(),{dynasty:i,birth_year:o,death_year:s}=t,r=[];return i&&r.push(`〔${n(i)}〕`),o!==void 0&&s!==void 0?r.push(`${o}—${s}`):o!==void 0?r.push(`${o}—?`):s!==void 0&&r.push(`?—${s}`),r.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:r.join(" ")})}function Lr({alt_names:t}){const{convert:n}=D(),i=new Map;for(const r of t){const l=r.type||"別名";i.has(l)||i.set(l,[]),i.get(l).push(r.name)}const o=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((r,l)=>{const c=o.indexOf(r),a=o.indexOf(l);return c===-1&&a===-1?0:c===-1?1:a===-1?-1:c-a});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(r=>{const l=i.get(r);return e.jsxs("div",{style:{display:"flex",gap:"6px",marginBottom:"2px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",minWidth:"36px",paddingTop:"2px"},children:r}),e.jsx("span",{children:l.map((c,a)=>e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},a))})]},r)})})}function Wr({data:t}){const n=t.external_ids;if(!n)return null;const i=[];return n.cbdb_id&&i.push(e.jsxs("a",{href:`https://cbdb.fas.harvard.edu/cbdbapi/person.php?id=${n.cbdb_id}`,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"2px 8px",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",border:"1px solid var(--bim-link-fg, #0066cc)40",borderRadius:"3px",textDecoration:"none",background:"var(--bim-link-fg, #0066cc)08"},title:"CBDB 中国历代人物传记数据库",children:["CBDB ",n.cbdb_id]},"cbdb")),i.length===0?null:e.jsx("div",{style:{display:"flex",gap:"6px",margin:"8px 0",alignItems:"center",flexWrap:"wrap"},children:i})}function $r({works:t,transport:n,onNavigate:i,renderLink:o}){const s=O(),{convert:r}=D(),l=me(),[c,a]=u.useState(new Map);u.useEffect(()=>{if(!n)return;let g=!1;const x=t.map(v=>v.work_id);return(async()=>{const v=new Map;if(n.getEntriesByIds)try{const k=await n.getEntriesByIds(x);let _=!0;for(let w=0;w<x.length;w++){const z=k[w];z!=null&&z.title?v.set(x[w],z.title):z!=null&&z.primary_name?v.set(x[w],z.primary_name):_=!1}if(_)return v}catch{}const m=[...x],j=8,y=new Array(j).fill(0).map(async()=>{for(;m.length;){const k=m.shift();if(!k)break;if(!v.has(k))try{if(n.getEntry){const z=await n.getEntry(k);if(z!=null&&z.title){v.set(k,z.title);continue}}const _=await n.getItem(k),w=_&&(_.title||_.primary_name)||k;v.set(k,w)}catch{v.set(k,k)}}});return await Promise.all(y),v})().then(v=>{g||a(v)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const x=g.role||"";d.has(x)||d.set(x,[]),d.get(x).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],f=[...d.keys()].sort((g,x)=>{const h=p.indexOf(g),v=p.indexOf(x);return h===-1&&v===-1?g.localeCompare(x):h===-1?1:v===-1?-1:h-v});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),f.map(g=>{const x=d.get(g);return e.jsxs("div",{style:{marginBottom:"8px"},children:[g&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginBottom:"2px"},children:[r(g)," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #bbb)"},children:["(",x.length,")"]})]}),e.jsx("ul",{style:{margin:0,paddingLeft:g?"16px":"0",listStyle:g?"disc":"none",fontSize:"14px",lineHeight:1.8},children:x.map((h,v)=>{const m=r(c.get(h.work_id)||h.work_id);return o?e.jsx("li",{children:o(h.work_id,m)},v):i?e.jsx("li",{children:e.jsx("a",{href:l(h.work_id),onClick:j=>{j.metaKey||j.ctrlKey||(j.preventDefault(),i(h.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:m})},v):e.jsx("li",{children:m},v)})})]},g)})]})}const Li=({data:t,transport:n,onNavigate:i,renderLink:o,headerExtra:s,hideHeader:r})=>{var f;const l=O(),{convert:c}=D();let a=!1;try{a=X.extractStatus(t.id)==="draft"}catch{}const d=Er(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",marginBottom:"4px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:600,margin:0,lineHeight:1.3,color:"var(--bim-fg, #222)"},children:[c(t.primary_name),e.jsx(Br,{data:t})]}),s]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:"var(--bim-type-entity, #5b3e8e)",border:"1px solid color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 25%, transparent)",borderRadius:"2px",background:"color-mix(in srgb, var(--bim-type-entity, #5b3e8e) 3%, transparent)"},children:l.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),a&&e.jsx("span",{style:{padding:"1px 6px",background:"var(--bim-warn-bg, #fff3cd)",border:"1px solid var(--bim-warn-border, #ffc107)",borderRadius:"2px",color:"var(--bim-warn-fg, #856404)"},children:l.status.draft}),e.jsx("span",{style:{fontFamily:"monospace",opacity:.6},children:t.id})]})]}),d&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #999)",fontStyle:"italic",padding:"8px 12px",background:"var(--bim-widget-bg, #f8f8f8)",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:"4px",margin:"8px 0"},children:"人物信息暂缺。该 Entity 仅作为作者占位,详细生平资料尚待补充。"}),t.alt_names&&t.alt_names.length>0&&e.jsx(Lr,{alt_names:t.alt_names}),e.jsx(Wr,{data:t}),((f=t.description)==null?void 0:f.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(t.description.text)}),t.works&&t.works.length>0&&e.jsx($r,{works:t.works,transport:n,onNavigate:i,renderLink:o})]})},Wi={p:({children:t})=>e.jsx("p",{style:{margin:"0 0 0.5em"},children:t}),ul:({children:t})=>e.jsx("ul",{style:{margin:"0 0 0.5em",paddingLeft:"1.4em"},children:t}),ol:({children:t})=>e.jsx("ol",{style:{margin:"0 0 0.5em",paddingLeft:"1.6em"},children:t}),li:({children:t})=>e.jsx("li",{style:{marginBottom:"2px"},children:t}),a:({href:t,children:n})=>e.jsx("a",{href:t,target:t!=null&&t.startsWith("http")?"_blank":void 0,rel:t!=null&&t.startsWith("http")?"noopener noreferrer":void 0,style:{color:"var(--bim-link, #1976d2)"},children:n}),code:({children:t})=>e.jsx("code",{style:{background:"var(--bim-bg-subtle, #f4f4f4)",padding:"1px 4px",borderRadius:3,fontSize:"0.92em"},children:t})},Ar={...Wi,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Le=({text:t,plainStrong:n,style:i,className:o})=>{const{convert:s}=D(),r=n?Ar:Wi;return e.jsx("div",{className:o,style:i,children:e.jsx(Xo,{remarkPlugins:[Zo],components:r,children:s(t)})})},Mr=["〇","一","二","三","四","五","六","七","八","九"],Fn=["","十","百","千"];function $i(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",s=!1;for(let r=0;r<i;r++){const l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=Fn[c]:o+=Mr[l]+Fn[c])}return o}function Ai(t){return{display:"inline-block",padding:"1px 6px",fontSize:"11px",fontWeight:500,letterSpacing:"1px",color:t,border:`1px solid color-mix(in srgb, ${t} 25%, transparent)`,borderRadius:"2px",background:`color-mix(in srgb, ${t} 3%, transparent)`}}const Fr={book:"var(--bim-type-book, #c0392b)",work:"var(--bim-type-work, #8e6f3e)",collection:"var(--bim-type-collection, #2471a3)",entity:"var(--bim-type-entity, #5b3e8e)"};function Pr({type:t}){const n=O();return e.jsx("span",{style:Ai(Fr[t]),children:n.indexType[t]})}function Hr({isDraft:t}){const n=O(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:Ai(i),children:t?n.status.draft:n.status.official})}function Dr({id:t}){const n=O(),[i,o]=u.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{o(!0),setTimeout(()=>o(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-bg-subtle, #f6f6f6)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"2px"},children:[e.jsx("span",{children:n.label.id}),e.jsx("span",{style:{fontFamily:"monospace",fontSize:"11px",color:"var(--bim-fg, #333)"},children:t}),e.jsx("span",{onClick:s,title:i?n.action.copied:n.action.copy,style:{cursor:"pointer",fontSize:"11px",opacity:i?1:.5,transition:"opacity 0.15s"},onMouseEnter:r=>r.currentTarget.style.opacity="1",onMouseLeave:r=>r.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function be({children:t,extra:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:"20px",marginBottom:"8px"},children:[e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",letterSpacing:"1px"},children:t}),e.jsx("span",{style:{flex:1}}),n]})}function ze({label:t,children:n}){return e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"4px",fontSize:"13px"},children:[e.jsx("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:t}),e.jsx("span",{style:{color:"var(--bim-fg, #333)"},children:n})]})}function Mi({authors:t,type:n,onNavigate:i,renderLink:o}){const{convert:s}=D();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((r,l)=>{const c=s(r.name),a=r.entity_id?e.jsx(ke,{id:r.entity_id,label:c,onNavigate:i,renderLink:o}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),r.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(r.dynasty),"〕"]}),a,r.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(r.role)]})]},l)})})}function ke({id:t,label:n,onNavigate:i,renderLink:o}){const s=me();return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:s(t),onClick:r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px"},onMouseEnter:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function Or({id:t,title:n,edition:i,type:o,isDraft:s,authors:r,volumeText:l,meta:c,headerExtra:a,onNavigate:d,renderLink:p}){return e.jsxs("div",{style:{marginBottom:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"},children:[e.jsxs("h1",{style:{fontSize:"clamp(18px, 4vw, 24px)",fontWeight:700,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 6px",lineHeight:1.4,letterSpacing:"0.5px",wordBreak:"break-word",flex:1,minWidth:0},children:[n,i&&e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:i}),l&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:l})]}),a&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:a})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(Pr,{type:o}),e.jsx(Hr,{isDraft:s}),e.jsx(Dr,{id:t})]}),((r==null?void 0:r.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[r&&r.length>0&&e.jsx(Mi,{authors:r,type:o,onNavigate:d,renderLink:p}),c]})]})}function Fi({items:t,label:n,showMeta:i,onNavigate:o,renderLink:s}){const r=O(),{convert:l}=D();if(!t.length)return null;const[c,a]=u.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(be,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,p)=>{const f=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...f?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>a(f?null:p),style:{padding:"8px 12px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",display:"flex",alignItems:"baseline",gap:"6px",userSelect:"none"},children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:f?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:l(d.source)}),!f&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(ke,{id:d.source_bid,label:r.action.view,onNavigate:o,renderLink:s})})]}),f&&e.jsxs("div",{style:{padding:"4px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[i&&(d.title_info||d.author_info||d.edition)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 16px",padding:"8px 0",fontSize:"13px"},children:[d.title_info&&e.jsx(ze,{label:r.label.titleInfo,children:l(d.title_info)}),d.author_info&&e.jsx(ze,{label:r.label.authorInfo,children:l(d.author_info)}),d.edition&&e.jsx(ze,{label:r.label.edition,children:l(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:r.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:r.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:r.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(d.additional_comment)})]})]})]},p)})})]})}function Nr({items:t,onNavigate:n,renderLink:i}){const o=O();return e.jsx(Fi,{items:t,label:o.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function Pi({items:t,onNavigate:n,renderLink:i}){const o=O();return e.jsx(Fi,{items:t,label:o.section.emendated,onNavigate:n,renderLink:i})}function Hi({label:t,items:n}){const{convert:i}=D();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((o,s)=>{const r=typeof o=="string"?o:o.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:i(r)},s)})})]}):null}function Vr({items:t}){const n=O();return e.jsx(Hi,{label:n.section.aliases,items:t})}function Gr({items:t}){const n=O();return e.jsx(Hi,{label:n.section.attachedTexts,items:t})}function Ur({items:t}){const n=O(),{convert:i}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((o,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",i(o.book_title),"》",o.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[o.n_juan,n.unit.juan]})]},s))})]}):null}function Yr({items:t}){const n=O(),{convert:i}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((o,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(o.name)}),o.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(o.description)})]},s))]})]}):null}function Kr({items:t}){const n=O(),{convert:i}=D();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((o,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(o)]},s))})]}):null}function Pn({title:t,ids:n,transport:i,onNavigate:o,renderLink:s}){const{convert:r}=D(),[l,c]=u.useState([]);return u.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let a=!1;return Promise.all(n.map(d=>i.getItem(d).then(p=>({id:d,title:p?p.title:void 0,edition:p?p.edition:void 0,type:p?p.type:void 0})).catch(()=>({id:d})))).then(d=>{a||c(d)}),()=>{a=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(l.length?l:n.map(a=>({id:a}))).map(a=>{const d=a.edition?`${r(a.title)||a.id}(${r(a.edition)})`:r(a.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(ke,{id:a.id,label:d,onNavigate:o,renderLink:s})},a.id)})})]}):null}function Gt({book:t,onNavigate:n,renderLink:i}){const o=O(),{convert:s}=D(),[r,l]=u.useState(!1),c=t.resources&&t.resources.length>0,a=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!r?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("div",{style:{flex:1,fontSize:"14px",lineHeight:1.4},children:e.jsx(ke,{id:t.id,label:a,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>l(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:r?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:r?o.action.expand:o.action.collapse,children:"▼"})]}),c&&!r&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(an,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function Jr({ids:t,workData:n,transport:i,onNavigate:o,renderLink:s,footer:r}){const l=O(),{convert:c}=D(),[a,d]=u.useState([]);if(u.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(v=>({id:v})));return}let h=!1;return Promise.all(t.map(v=>i.getItem(v).then(m=>({id:v,title:m?m.title:void 0,edition:m?m.edition:void 0,resources:m?m.resources:void 0,resource_groups:m?m.resource_groups:void 0})).catch(()=>({id:v})))).then(v=>{h||d(v)}),()=>{h=!0}},[t,i]),!t.length)return null;const p=a.length?a:t.map(h=>({id:h})),f=new Map(p.map(h=>[h.id,h])),g=n==null?void 0:n.version_graph,x=qr(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[l.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),r,x.useGrouping?e.jsxs(e.Fragment,{children:[x.coreIds.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:x.coreIds.map(h=>{const v=f.get(h);return v?e.jsx(Gt,{book:v,onNavigate:o,renderLink:s},h):null})}),x.groupedIds.map(h=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(h.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",h.ids.length,")"]}),h.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(h.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:h.ids.map(v=>{const m=f.get(v);return m?e.jsx(Gt,{book:m,onNavigate:o,renderLink:s},v):null})})]},h.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(h=>e.jsx(Gt,{book:h,onNavigate:o,renderLink:s},h.id))})]})}function qr(t,n){var m,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],r=o.length>0||s.length>0,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],f=new Map,g=[];for(const y of t)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))p.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):g.push(y)}if(g.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),v=[...f.entries()].map(([y,k])=>{const _=h.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:v}}function Xr({workData:t,onNavigate:n,renderLink:i}){var l,c,a,d;const o=O(),{convert:s}=D(),r=!!((l=t.description)!=null&&l.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:r?"1px solid var(--bim-widget-border, #e0e0e0)":"none",display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)"},children:[e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)"},children:e.jsx(ke,{id:t.id,label:s(t.title),onNavigate:n,renderLink:i})}),t.measure_info?e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:s(t.measure_info)}):((c=t.juan_count)==null?void 0:c.number)!=null&&t.juan_count.number>0?e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[$i(t.juan_count.number),o.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(Mi,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),r&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((a=t.description)==null?void 0:a.text)&&e.jsx(Le,{text:t.description.text,style:{fontSize:"13px",color:"var(--bim-fg, #444)",lineHeight:1.8,textAlign:"justify"}}),t.parent_work&&e.jsx("div",{style:{marginTop:(d=t.description)!=null&&d.text?"8px":0,fontSize:"13px"},children:e.jsx(ze,{label:o.label.parentWork,children:e.jsx(ke,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function Zr({items:t,onNavigate:n,renderLink:i}){const o=O(),{convert:s}=D();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(r=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:o.indexType.collection}),e.jsx(ke,{id:r.id,label:s(r.title)||r.id,onNavigate:n,renderLink:i}),r.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:yt(o.catalog.volume,{n:r.volume_index})})]},r.id))}):null}const cn=({data:t,id:n,transport:i,onNavigate:o,renderLink:s,headerExtra:r,relatedBooksFooter:l,className:c,style:a})=>{var R,E,A,M,P,$,F,Q;const d=O(),{convert:p}=D(),[f,g]=u.useState(null),[x,h]=u.useState(!1),[v,m]=u.useState(null),[j,y]=u.useState(null),[k,_]=u.useState([]),w=t||f;if(u.useEffect(()=>{if(t||!n||!i)return;let W=!1;return h(!0),m(null),i.getItem(n).then(U=>{W||(U?g(U):m(d.misc.notFoundEntry))}).catch(U=>{W||m(U instanceof Error?U.message:d.misc.loadFailed)}).finally(()=>{W||h(!1)}),()=>{W=!0}},[t,n,i]),u.useEffect(()=>{if(!w||!i){y(null),_([]);return}let W=!1;const U=w.type==="book"||w.type==="collection"?w.work_id:void 0;if(U?i.getItem(U).then(ne=>{!W&&ne&&ne.type==="work"&&y(ne)}).catch(()=>{}):y(null),w.type==="book"){const ne=w;ne.contained_in&&ne.contained_in.length>0?Promise.all(ne.contained_in.map(B=>{const V=typeof B=="string"?B:B.id,Y=typeof B=="string"?void 0:B.volume_index;return i.getItem(V).then(ie=>({id:V,title:ie&&ie.title||V,volume_index:Y})).catch(()=>({id:V,title:V,volume_index:Y}))})).then(B=>{W||_(B)}):_([])}else _([]);return()=>{W=!0}},[w,i]),x)return e.jsx("div",{className:c,style:{...a,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,U)=>e.jsx("div",{style:{height:U===1?"32px":"16px",width:`${W}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},U))})});if(v)return e.jsx("div",{className:c,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:v});if(!w)return null;if(w.type==="entity")return e.jsx("div",{className:c,style:a,children:e.jsx(Li,{data:w,transport:i,onNavigate:o,renderLink:s,headerExtra:r})});const z=w.type==="book"?w:null,S=w.type==="collection"?w:null,I=w.type==="work"?w:null;let T=!1;try{T=X.extractStatus(w.id)==="draft"}catch{}let C="";w.measure_info?C=p(w.measure_info):(R=w.juan_count)!=null&&R.number?C=$i(w.juan_count.number)+d.unit.juan:(E=w.juan_count)!=null&&E.description&&(C=p(w.juan_count.description));const b=[];return(A=w.publication_info)!=null&&A.year&&b.push(e.jsx(ze,{label:d.label.year,children:w.publication_info.year},"year")),(M=w.current_location)!=null&&M.name&&b.push(e.jsx(ze,{label:d.label.currentLocation,children:p(w.current_location.name)},"loc")),(P=w.page_count)!=null&&P.description&&b.push(e.jsx(ze,{label:d.label.pageCount,children:w.page_count.description},"page")),z!=null&&z.edition&&b.push(e.jsx(ze,{label:d.label.edition,children:p(z.edition)},"ver")),I!=null&&I.parent_work&&b.push(e.jsx(ze,{label:d.label.parentWork,children:e.jsx(ke,{id:I.parent_work.id,label:p(I.parent_work.title),onNavigate:o,renderLink:s})},"pw")),I!=null&&I.parent_works&&I.parent_works.length>0&&!I.parent_work&&b.push(e.jsx(ze,{label:d.label.parentWork,children:I.parent_works.map((W,U)=>e.jsxs("span",{children:[U>0&&"、",e.jsx(ke,{id:W,onNavigate:o,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:a,children:[e.jsx(Or,{id:w.id,title:p(w.title),edition:w.edition?p(w.edition):void 0,type:w.type,isDraft:T,authors:w.authors,volumeText:C,meta:b,headerExtra:r,onNavigate:o,renderLink:s}),(($=w.description)==null?void 0:$.text)&&e.jsx(Le,{text:w.description.text,style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"0 0 4px",textAlign:"justify"}}),w.appendix&&w.appendix.length>0&&e.jsx("div",{style:{marginTop:8,marginBottom:4},children:w.appendix.map((W,U)=>e.jsxs("details",{style:{marginTop:6,padding:"6px 10px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4,border:"1px solid var(--bim-widget-border, #ececec)"},children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:600,fontSize:13,color:"var(--bim-muted, #666)"},children:p(W.title)}),e.jsx(Le,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},U))}),k.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.containedIn}),e.jsx(Zr,{items:k,onNavigate:o,renderLink:s})]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.belongsToWork}),e.jsx(Xr,{workData:j,onNavigate:o,renderLink:s})]}),w.additional_works&&w.additional_works.length>0&&e.jsx(Ur,{items:w.additional_works}),w.additional_titles&&w.additional_titles.length>0&&e.jsx(Vr,{items:w.additional_titles}),w.attached_texts&&w.attached_texts.length>0&&e.jsx(Gr,{items:w.attached_texts}),w.indexed_by&&w.indexed_by.length>0&&e.jsx(Nr,{items:w.indexed_by,onNavigate:o,renderLink:s}),w.emendated_by&&w.emendated_by.length>0&&e.jsx(Pi,{items:w.emendated_by,onNavigate:o,renderLink:s}),w.resources&&w.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:d.section.resources}),e.jsx(an,{items:w.resources,resourceGroups:w.resource_groups,groupByType:!0,onNavigate:o,renderLink:s})]}),(z==null?void 0:z.location_history)&&z.location_history.length>0&&e.jsx(Yr,{items:z.location_history}),(S==null?void 0:S.history)&&S.history.length>0&&e.jsx(Kr,{items:S.history}),(z==null?void 0:z.related_books)&&z.related_books.length>0&&e.jsx(Pn,{title:d.section.relatedVersions,ids:z.related_books,transport:i,onNavigate:o,renderLink:s}),(S==null?void 0:S.books)&&S.books.length>0&&e.jsx(Pn,{title:d.section.containedBooks,ids:S.books,transport:i,onNavigate:o,renderLink:s}),(S==null?void 0:S.contained_works)&&S.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(be,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",S.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.contained_works.map(W=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ke,{id:W.id,label:p(W.title),onNavigate:o,renderLink:s})},W.id))})]}),(((F=I==null?void 0:I.books)==null?void 0:F.length)||0)+(((Q=I==null?void 0:I.collections)==null?void 0:Q.length)||0)>0&&e.jsx(Jr,{ids:[...(I==null?void 0:I.books)||[],...(I==null?void 0:I.collections)||[]],workData:I,transport:i,onNavigate:o,renderLink:s,footer:l}),(I==null?void 0:I.related_works)&&I.related_works.length>0&&(()=>{const W=[],U=I.related_works.filter(G=>G.relation==="part_of"),ne=I.related_works.filter(G=>G.relation==="has_part"),B=I.related_works.filter(G=>G.relation==="has_adaptation"),V=I.related_works.filter(G=>G.relation==="text_carried_by"),Y=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),ie=I.related_works.filter(G=>!G.relation||!Y.has(G.relation));return U.length>0&&W.push({label:d.section.belongsToWork,items:U}),ne.length>0&&W.push({label:d.section.containedWorks,items:ne}),B.length>0&&W.push({label:d.section.adaptations,items:B}),V.length>0&&W.push({label:d.section.derivativeWorks,items:V}),ie.length>0&&W.push({label:d.section.relatedWorks,items:ie}),W.map(G=>e.jsxs("div",{children:[e.jsxs(be,{children:[G.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",G.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:G.items.map(K=>e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:e.jsx(ke,{id:K.id,label:p(K.title),onNavigate:o,renderLink:s})},K.id))})]},G.label))})()]})};function Qr({data:t}){const n=O(),{convert:i}=D(),{stats:o}=t,s=o.processed_volumes??o.total_found_volumes,r=s!=null&&t.total_volumes>0?Math.round(s/t.total_volumes*100):null;return e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:i(t.title)}),t.resource_name&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"6px"},children:i(t.resource_name)}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"16px",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsxs("span",{children:[n.catalog.totalVolumes," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:t.total_volumes})," ",n.unit.volume]}),r!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",r,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.total_books})," ",n.unit.bu]}),o.matched_works!=null&&o.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.matched_works})," ",n.unit.bu]}),o.unmatched_works!=null&&o.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:o.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function es({sections:t,activeSection:n,onSelect:i}){const o=O();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:Hn(n===null),children:o.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:Hn(n===s.name),children:[s.name,s.volume_range&&e.jsxs("span",{style:{fontSize:"11px",opacity:.6,marginLeft:"4px"},children:[s.volume_range[0],"–",s.volume_range[1]]})]},s.name))]})}function Hn(t){return{padding:"4px 12px",border:t?"1px solid var(--bim-primary, #2471a3)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:t?"color-mix(in srgb, var(--bim-primary, #2471a3) 8%, transparent)":"transparent",color:t?"var(--bim-primary, #2471a3)":"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function ts({id:t,label:n,onNavigate:i,renderLink:o}){const s=me();return o?e.jsx(e.Fragment,{children:o(t,n)}):i?e.jsx("a",{href:s(t),onClick:r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i(t))},style:{color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)",paddingBottom:"1px",fontSize:"12px"},onMouseEnter:r=>r.currentTarget.style.borderBottomStyle="solid",onMouseLeave:r=>r.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function ns(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],o=t[t.length-1];return o-i+1===t.length?`${i}–${o}`:t.length<=3?t.join(", "):`${i}–${o} (${t.length}${n})`}function Dn({book:t,onNavigate:n,renderLink:i,showVolumes:o}){const s=O(),{convert:r}=D(),l=t.book_id||t.work_id,c=o&&t.volumes.length>0?ns(t.volumes,s.unit.volume):null,a=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[o&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[r(t.title),t.sub_items&&t.sub_items.length>0&&e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",fontWeight:400,marginLeft:"6px"},children:["(",t.sub_items.map(d=>r(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:r(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:a?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),l&&e.jsx(ts,{id:l,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!l&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const dn=({data:t,collectionId:n,transport:i,onNavigate:o,renderLink:s,className:r,style:l})=>{const c=O(),[a,d]=u.useState(null),[p,f]=u.useState(!1),[g,x]=u.useState(null),[h,v]=u.useState(null),[m,j]=u.useState(""),y=t||a;u.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let S=!1;return f(!0),x(null),i.getCollectionCatalog(n).then(I=>{S||(I?d(I):x(c.catalog.notFound))}).catch(I=>{S||x(I instanceof Error?I.message:c.catalog.loadFailed)}).finally(()=>{S||f(!1)}),()=>{S=!0}},[t,n,i,c]);const k=(y==null?void 0:y.sections)&&y.sections.length>0,_=u.useMemo(()=>{if(!y)return!1;if(y.volume_index&&Object.keys(y.volume_index).length>0)return!0;const S=y.books.map(T=>T.volumes[0]).filter(T=>T!=null);return new Set(S).size<S.length},[y]),w=u.useMemo(()=>{if(!y)return[];let S=y.books;if(h&&(S=S.filter(I=>I.section===h)),m.trim()){const I=m.trim().toLowerCase();S=S.filter(T=>T.title.toLowerCase().includes(I)||T.sub_items&&T.sub_items.some(C=>C.toLowerCase().includes(I))||T.edition&&T.edition.toLowerCase().includes(I))}return S},[y,h,m]),z=u.useMemo(()=>{if(!_)return null;const S=[],I=new Map;for(const C of w){if(!C.volumes||C.volumes.length===0)continue;const b=C.volumes[0];I.has(b)||I.set(b,[]),I.get(b).push(C)}const T=[...I.keys()].sort((C,b)=>C-b);for(const C of T)S.push({volume:C,books:I.get(C)});return S},[w,_]);return p?e.jsx("div",{className:r,style:{...l,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:r,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):y?e.jsxs("div",{className:r,style:l,children:[e.jsx(Qr,{data:y}),k&&e.jsx(es,{sections:y.sections,activeSection:h,onSelect:v}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:m,onChange:S=>j(S.target.value),style:{width:"100%",maxWidth:"320px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}}),e.jsxs("span",{style:{marginLeft:"12px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[w.length," ",c.unit.bu]})]}),e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[z?z.map((S,I)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:yt(c.catalog.volume,{n:S.volume})}),S.books.map((T,C)=>e.jsx(Dn,{book:T,onNavigate:o,renderLink:s,showVolumes:T.volumes.length>1},`${S.volume}-${C}`))]},`${S.volume}-${I}`)):w.map((S,I)=>e.jsx(Dn,{book:S,onNavigate:o,renderLink:s,showVolumes:!0},I)),w.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Ve=()=>{const[t,n]=u.useState(1);return u.useEffect(()=>{const i=setInterval(()=>n(o=>o>=3?1:o+1),500);return()=>clearInterval(i)},[]),e.jsx("div",{style:{textAlign:"center",padding:"32px 0",color:"var(--bim-desc-fg, #717171)",fontSize:"14px"},children:"加载中"+".".repeat(t)})},xe=6,kt=7,is=({content:t,children:n,placement:i="top",delayMs:o=100,maxWidth:s=280,wrapperStyle:r})=>{const[l,c]=u.useState(!1),[a,d]=u.useState(null),p=u.useRef(null),f=u.useRef(null),g=u.useRef(null),x=u.useCallback(()=>{const m=f.current,j=g.current;if(!m||!j)return;const y=m.getBoundingClientRect(),k=j.getBoundingClientRect(),_=window.innerHeight,w=document.documentElement.clientWidth;let z=i;i==="top"&&y.top-k.height-kt<8&&(z="bottom"),i==="bottom"&&y.bottom+k.height+kt>_-8&&(z="top");const S=z==="top"?y.top-k.height-kt:y.bottom+kt;let I=y.left+y.width/2-k.width/2;I=Math.max(8,Math.min(I,w-k.width-8)),d({left:I,top:S,placement:z})},[i]),h=u.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),o)},[o]),v=u.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return u.useEffect(()=>{if(!l)return;const m=requestAnimationFrame(x);return()=>cancelAnimationFrame(m)},[l,x]),u.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:f,onMouseEnter:h,onMouseLeave:v,onFocus:h,onBlur:v,style:{display:"inline-block",...r},children:n}),l&&Qo.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(a==null?void 0:a.left)??-9999,top:(a==null?void 0:a.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:a?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,a&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-xe,width:0,height:0,...a.placement==="top"?{bottom:-xe,borderTop:`${xe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${xe}px solid transparent`,borderRight:`${xe}px solid transparent`}:{top:-xe,borderBottom:`${xe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${xe}px solid transparent`,borderRight:`${xe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...a.placement==="top"?{bottom:-5,borderTop:`${xe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${xe-1}px solid transparent`,borderRight:`${xe-1}px solid transparent`}:{top:-5,borderBottom:`${xe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${xe-1}px solid transparent`,borderRight:`${xe-1}px solid transparent`}}})]})]}),document.body)]})},On={A:"fine",B:"rough",C:"rough",D:"ocr"};function os(t){return typeof t!="string"?null:t in Ci?t:t in On?On[t]:null}const rs={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},ss={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function ye(t){return typeof t!="string"?"":rs[t]??ss[t]??t}const ls=["〇","一","二","三","四","五","六","七","八","九"],Nn=["","十","百","千"],as=["","萬","億"];function Di(t){if(t===0)return"〇";if(t<0)return`負${Di(-t)}`;const n=[];let i=t,o=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(cs(s,o>0)+as[o]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),o++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function cs(t,n){const i=[];let o=t;for(;o>0;)i.unshift(o%10),o=Math.floor(o/10);let s="";for(let r=0;r<i.length;r++){const l=i[r],c=i.length-1-r;l===0?s&&!s.endsWith("〇")&&(s+="〇"):l===1&&c===1&&r===0&&!n?s+=Nn[c]:s+=ls[l]+Nn[c]}return s.replace(/〇$/,"")}let xt=null,wt=null;const Lt=new Set;function ds(){return xt?Promise.resolve():wt||(wt=import("opencc-js/t2cn").then(t=>{xt=t.Converter({from:"tw",to:"cn"}),Lt.forEach(n=>n())}).catch(()=>{xt=t=>t,Lt.forEach(t=>t())}),wt)}function We(){const[,t]=u.useState(0);return u.useEffect(()=>{if(xt)return;const n=()=>t(i=>i+1);return Lt.add(n),ds(),()=>{Lt.delete(n)}},[]),xt??(n=>n)}function qe(t,n){return n(t).toLowerCase()}const pn="var(--bim-highlight-bg, #fff59d)";function et(t,n,i){if(!n)return t;const o=qe(n,i);if(!o)return t;const s=qe(t,i);if(s.length!==t.length)return t;const r=[];let l=0,c=0;for(;l<t.length;){const a=s.indexOf(o,l);if(a===-1){r.push(t.slice(l));break}a>l&&r.push(t.slice(l,a)),r.push(e.jsx("mark",{style:{background:pn,padding:0,color:"inherit"},children:t.slice(a,a+o.length)},c++)),l=a+o.length}return e.jsx(e.Fragment,{children:r})}function un(t,n,i,o){if(!n)return!0;const s=qe(n,o);return(i?[t.title,t.header_line,t.content,t.comment]:[t.title,t.book_title,t.author,t.author_info,t.summary,t.content,t.comment,t.additional_comment]).some(l=>typeof l=="string"&&qe(l,o).includes(s))}function ps(t,n,i){return n?qe(t,i).includes(qe(n,i)):!0}const xn={类:"var(--bim-section-lei, #8e6f3e)",书:"var(--bim-section-shu, #c0392b)",序:"var(--bim-section-xu, #1a5276)",结语:"var(--bim-section-jieyu, #7d6608)",注释:"var(--bim-section-zhushi, #6c5b7b)"},us={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function xs(t){const n=t.replace(".json","");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function Oi({file:t,isActive:n,onSelect:i,meta:o,matchState:s}){const r=s===0,l=s==="loading",c=typeof s=="number"&&s>0,a=xs(t),d=!!(o!=null&&o.vol_label)&&!a.includes(o.vol_label);return e.jsxs("button",{onClick:()=>{r||i(t)},disabled:r,style:{padding:"3px 8px",border:n?"1px solid var(--bim-primary, #8e6f3e)":r?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":c?`${pn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":r?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:r?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:r?.5:1},children:[a,d&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",o.vol_label,"冊)"]}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Ni(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(o=>Ni(o,n)))}function Vi(t){var o;const n=t.files.length,i=((o=t.children)==null?void 0:o.reduce((s,r)=>s+Vi(r),0))||0;return n+i}function fs(t,n){const i=[],o=l=>{var c;i.push(...l.files),(c=l.children)==null||c.forEach(o)};if(o(t),i.length===0)return;const s=i.map(l=>n[l]);if(s.every(l=>l===void 0))return;if(s.some(l=>l==="loading"))return"loading";let r=0;for(const l of s)typeof l=="number"&&(r+=l);return r}function Gi({group:t,activeFile:n,onSelect:i,depth:o=0,juanMeta:s,matchStates:r}){var h;const l=Ni(t,n||""),c=fs(t,r),a=typeof c=="number"&&c>0,d=c===0,[p,f]=u.useState(l||a),g=Vi(t),x=!!((h=t.children)!=null&&h.length);if(u.useEffect(()=>{l&&f(!0)},[l]),u.useEffect(()=>{a&&f(!0)},[a]),t.files.length===1&&!x){const v=t.files[0],m=n===v,j=r[v],y=j===0,k=j==="loading",_=typeof j=="number"&&j>0;return e.jsxs("button",{onClick:()=>{y||i(v)},disabled:y,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+o*16}px`,border:m?"1px solid var(--bim-primary, #8e6f3e)":y?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:m?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":_?`${pn}40`:"transparent",color:m?"var(--bim-primary, #8e6f3e)":y?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:y?"not-allowed":"pointer",fontSize:"12px",fontWeight:m?600:400,lineHeight:1.4,opacity:y?.5:1},children:[t.label,_&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:j}),k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:o===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>f(!p),style:{display:"flex",alignItems:"center",gap:"6px",padding:o===0?"4px 8px":"2px 8px",paddingLeft:`${8+o*16}px`,cursor:"pointer",userSelect:"none",fontSize:o===0?"13px":"12px",fontWeight:o===0?600:500,color:l?"var(--bim-primary, #8e6f3e)":d?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:d?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:p?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",g,")"]}),a&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",c]}),c==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),p&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",padding:`4px 0 4px ${24+o*16}px`},children:t.files.map(v=>e.jsx(Oi,{file:v,isActive:n===v,onSelect:i,meta:s==null?void 0:s[v],matchState:r[v]},v))}),x&&t.children.map((v,m)=>e.jsx(Gi,{group:v,activeFile:n,onSelect:i,depth:o+1,juanMeta:s,matchStates:r},m))]})]})}function gs({files:t,groups:n,activeFile:i,onSelect:o,juanMeta:s,matchStates:r}){const l=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:"16px"},children:n.map((c,a)=>e.jsx(Gi,{group:c,activeFile:i,onSelect:o,juanMeta:s,matchStates:r},a))}):l.length===0?null:e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:l.map(c=>e.jsx(Oi,{file:c,isActive:i===c,onSelect:o,meta:s==null?void 0:s[c],matchState:r[c]},c))})}function ms({type:t}){const n=xn[t]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:n,border:`1px solid ${n}40`,borderRadius:"2px",background:`${n}08`,flexShrink:0},children:t})}function hs({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=D(),s=me(),r=We(),l=v=>{if(!v)return"";const m=o(v);return i?et(m,i,r):m},[c,a]=u.useState(!1),d=!!t.summary,p=!!t.comment,f=!!t.additional_comment,g=!!(t.content&&t.content.length>60),x=d||p||f||g;u.useEffect(()=>{i&&a(!0)},[i]);const h=!c&&g?t.content.replace(/\n/g," ").slice(0,80)+"…":null;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",marginBottom:"6px"},children:[e.jsxs("div",{onClick:()=>x&&a(!c),style:{padding:"8px 12px",display:"flex",alignItems:"baseline",gap:"8px",cursor:x?"pointer":"default",userSelect:"none",background:"var(--bim-input-bg, #fff)"},children:[x&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.15s",transform:c?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[t.book_title?e.jsxs(e.Fragment,{children:["《",l(t.book_title),"》"]}):l(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Di(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:l(t.author_info||t.author)})]}),!c&&h&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:l(h)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:l(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-section-tag-fg, #e74c3c)"},children:t.tag==="triangle"?"△":t.tag}),t.work_id&&n&&e.jsx("a",{href:s(t.work_id),onClick:v=>{v.metaKey||v.ctrlKey||(v.preventDefault(),v.stopPropagation(),n(t.work_id))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"})]}),c&&x&&e.jsxs("div",{style:{padding:"8px 12px 12px",borderTop:"1px solid var(--bim-widget-border, #f0f0f0)",background:"var(--bim-bg, #fafafa)"},children:[t.author_info&&e.jsx("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:l(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:l(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:l(t.additional_comment)})]}),g&&!d&&!p&&!f&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)})]})]})}function bs({section:t,highlightQuery:n=""}){const{convert:i}=D(),o=We(),s=a=>{if(!a)return"";const d=i(a);return n?et(d,n,o):d},[r,l]=u.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&l(!r),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(ms,{type:t.type}),e.jsx("span",{style:{fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)"},children:s(t.title)}),c&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",transition:"transform 0.15s",transform:r?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),r&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${xn[t.type]||"var(--bim-desc-fg, #717171)"} 25%, transparent)`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:s(t.content)})})]})}function ys({section:t,highlightQuery:n=""}){const{convert:i}=D(),o=We();if(ye(t.type)==="page_header"||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
2
|
+
`)),r=n?et(s,n,o):s,l=ye(t.type),c=xn[l]||"var(--bim-desc-fg, #717171)",a=l==="序"||l==="结语"||l==="注释";return e.jsxs("div",{style:{padding:a?"10px 12px":"6px 0",margin:a?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:a?`3px solid ${c}40`:void 0,background:a?"var(--bim-bg, #fafafa)":void 0,borderRadius:a?"0 4px 4px 0":void 0,position:"relative"},children:[a&&e.jsx("span",{style:{display:"inline-block",fontSize:"10px",fontWeight:500,color:c,marginRight:"8px",padding:"1px 5px",border:`1px solid ${c}40`,borderRadius:"2px",background:`${c}08`,verticalAlign:"middle"},children:l}),r]})}function vs(t,n,i){const[o,s]=u.useState({});return u.useEffect(()=>{var d;if(!n||t.length===0)return;let r=!1;const l=t.filter(p=>{var f;return!((f=i==null?void 0:i.current)!=null&&f.has(p))}),c={};for(const p of t)(d=i==null?void 0:i.current)!=null&&d.has(p)&&(c[p]=i.current.get(p));if(Object.keys(c).length>0&&s(c),l.length===0)return;const a=async p=>{var f;try{if(n.getEntry){const m=await n.getEntry(p);if(m)return{title:m.title,author:m.author}}const g=await n.getItem(p);if(!g)return null;const x=g.title||p,h=g.authors,v=(f=h==null?void 0:h[0])==null?void 0:f.name;return{title:x,author:v}}catch{return null}};return Promise.all(l.map(async p=>{var g;const f=await a(p);return(g=i==null?void 0:i.current)==null||g.set(p,f),[p,f]})).then(p=>{r||s(f=>{const g={...f};for(const[x,h]of p)g[x]=h;return g})}),()=>{r=!0}},[t.join(","),n]),o}function js({section:t,onNavigate:n,transport:i,workLabelCache:o,highlightQuery:s=""}){const{convert:r}=D(),l=me(),c=We(),a=y=>{if(!y)return"";const k=r(y);return s?et(k,s,c):k},[d,p]=u.useState(!1);u.useEffect(()=>{s&&p(!0)},[s]);const f=t.type,g=us[f]||"var(--bim-desc-fg, #717171)",x=!!t.content,h=t.work_ids||[],v=h.length>1,m=vs(v?h:[],i,o),j=x&&!d&&t.content.length>80?t.content.slice(0,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>x&&p(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:x?"pointer":"default",userSelect:"none"},children:[x&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?a(t.header_line):a(t.title)}),!d&&j&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:a(j)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[h.length===1&&n&&e.jsx("a",{href:l(h[0]),onClick:y=>{y.metaKey||y.ctrlKey||(y.preventDefault(),y.stopPropagation(),n(h[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),v&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[h.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:f})]})]}),v&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:h.map(y=>{const k=m[y],_=k?`${r(k.title)}${k.author?`(${r(k.author)})`:""}`:y.slice(0,8)+"…";return e.jsxs("a",{href:l(y),onClick:w=>{w.metaKey||w.ctrlKey||(w.preventDefault(),w.stopPropagation(),n(y))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:y,children:["→",_]},y)})}),d&&x&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:a(t.comment)})]})]})}function Ss({juan:t,searchQuery:n,onNavigate:i,transport:o,workLabelCache:s}){const{convert:r}=D(),l=We(),c=n.trim(),a=u.useMemo(()=>c?t.sections.filter(f=>un(f,c,!0,l)):t.sections,[t.sections,c,l]),d=t.sections.filter(f=>ye(f.type)==="考证").length,p=a.filter(f=>ye(f.type)==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:r(t.title)}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:c?`${p} / ${d} 條`:`${d} 條`})]}),t.source_url&&e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:"原文來源"})}),e.jsx("div",{children:a.map((f,g)=>e.jsx(js,{section:f,onNavigate:i,transport:o,workLabelCache:s,highlightQuery:c},g))}),a.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function ks({text:t,highlightQuery:n=""}){const{convert:i}=D(),o=We(),s=l=>{const c=i(l);return n?et(c,n,o):c},r=t.split(`
|
|
3
|
+
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:r.map((l,c)=>{if(l.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(l.slice(2))},c);if(l.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(l.slice(3))},c);if(l.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(l.slice(4))},c);if(!l.trim())return c>0&&!r[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const a=l.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:a.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},p):e.jsx(u.Fragment,{children:s(d)},p))},c)})})}function ws({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:o}=D(),s=me(),r=We(),l=d=>{if(!d)return"";const p=o(d);return i?et(p,i,r):p},c=[];let a=null;for(const d of t){const p=ye(d.type);p!=="page_header"&&(p==="类"?(a&&c.push(a),a={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(a||(a={category:"",items:[]}),a.items.push(d)):(p==="序"||p==="结语")&&(a||(a={category:"",items:[]}),a.items.push(d),p==="结语"&&(c.push(a),a=null)))}return a&&c.push(a),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,p)=>e.jsxs("div",{style:{marginBottom:"20px"},children:[d.category&&e.jsxs("h4",{style:{fontSize:"15px",fontWeight:600,margin:"16px 0 8px",color:"var(--bim-fg, #1a1a1a)"},children:[l(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:l(d.categoryContent)})]}),d.items.map((f,g)=>ye(f.type)==="序"||ye(f.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:l(f.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&f.work_id?e.jsx("a",{href:s(f.work_id),onClick:x=>{x.metaKey||x.ctrlKey||(x.preventDefault(),x.stopPropagation(),n(f.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:o(f.title),children:e.jsx("strong",{children:l(f.title)})}):e.jsx("strong",{children:l(f.title)}),f.content&&l(f.content)]},g))]},p))})}function _s({juan:t,rawText:n,searchQuery:i,onNavigate:o}){const{convert:s}=D(),r=We(),[l,c]=u.useState("catalog"),a=i.trim(),d=u.useMemo(()=>a?t.sections.filter(x=>un(x,a,!1,r)):t.sections,[t.sections,a,r]),p=t.sections.filter(x=>ye(x.type)==="书").length,f=t.sections.filter(x=>ye(x.type)==="诗").length,g=a?d.filter(x=>ye(x.type)==="书"||ye(x.type)==="诗").length:null;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"12px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:s(t.title)}),e.jsx("div",{style:{display:"flex",gap:"2px",marginLeft:"8px"},children:["catalog","raw"].map(x=>e.jsx("button",{onClick:()=>c(x),style:{padding:"2px 8px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:x==="catalog"?"3px 0 0 3px":"0 3px 3px 0",background:l===x?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:l===x?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:x==="catalog"?"目錄":"原文"},x))}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${f>0?`${f} 首`:`${p} 部書`}`:f>0?`${f} 首`:`${p} 部书`})]}),l==="raw"&&(n?e.jsx(ks,{text:n,highlightQuery:a}):e.jsx(ws,{sections:t.sections,onNavigate:o,highlightQuery:a})),l==="catalog"&&d.map((x,h)=>{const v=ye(x.type);return v==="书"||v==="诗"||v==="考证"?e.jsx(hs,{section:x,onNavigate:o,highlightQuery:a},h):v==="类"?e.jsx(bs,{section:x,highlightQuery:a},h):e.jsx(ys,{section:x,highlightQuery:a},h)}),l==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Ui(t){return t.juan_files&&t.juan_files.length>0?t.juan_files:t.files&&t.files.length>0?t.files.map(n=>n.filename):[]}function Vn(t){const n=Ui(t);return n.length>0?n[0]:null}function Cs(t){const{workId:n,transport:i,files:o,activeFile:s,activeJuan:r,activeRawText:l,query:c,isKaozhen:a}=t,d=We(),p=u.useRef(new Map),[f,g]=u.useState({});u.useEffect(()=>{s&&r&&p.current.set(s,{juan:r,rawText:l})},[s,r,l]),u.useEffect(()=>{p.current.clear(),g({})},[n]);const x=u.useCallback((h,v)=>{let m=0;if(h.juan)for(const j of h.juan.sections)un(j,v,a,d)&&m++;return m===0&&h.rawText&&ps(h.rawText,v,d)&&(m=1),m},[a,d]);return u.useEffect(()=>{const h=c.trim();if(!h){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||o.length===0)return;let v=!1;const m={},j=[];for(const z of o){const S=p.current.get(z);S?m[z]=x(S,h):(m[z]="loading",j.push(z))}g(m);const y=8;let k=0;const _=async()=>{var z;for(;k<j.length;){if(v)return;const S=k++,I=j[S];try{const[T,C]=await Promise.all([i.getCollatedJuan(n,I),((z=i.getCollatedJuanText)==null?void 0:z.call(i,n,I))??Promise.resolve(null)]),b={juan:T,rawText:C};if(p.current.set(I,b),v)return;g(R=>({...R,[I]:x(b,h)}))}catch{if(v)return;g(T=>({...T,[I]:0}))}}},w=Array.from({length:Math.min(y,j.length)},()=>_());return Promise.all(w),()=>{v=!0}},[c,n,i,o.join(","),x,d]),{matchStates:f}}const fn=({index:t,workId:n,transport:i,onNavigate:o,activeJuan:s,onJuanChange:r,className:l,style:c})=>{const[a,d]=u.useState(null),[p,f]=u.useState(!1),[g,x]=u.useState(null),[h,v]=u.useState(null),[m,j]=u.useState(null),[y,k]=u.useState(!1),[_,w]=u.useState(null),[z,S]=u.useState(""),I=u.useRef(new Map),T=s??h,C=u.useCallback($=>{v($),r==null||r($)},[r]),b=t||a;u.useEffect(()=>{t&&(f(!1),x(null))},[t]),u.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let $=!1;return f(!0),x(null),i.getCollatedEditionIndex(n).then(F=>{if(!$)if(!F)x("未找到整理本数据");else{d(F);const Q=Vn(F);!s&&Q&&C(Q)}}).catch(F=>{$||x(F instanceof Error?F.message:"加载失败")}).finally(()=>{$||f(!1)}),()=>{$=!0}},[t,n,i,s,C]),u.useEffect(()=>{const $=t||a;if($&&!T){const F=Vn($);F&&C(F)}},[t,a,T,C]);const R=n||(b==null?void 0:b.work_id),E=u.useCallback(async $=>{var F;if(!(!R||!(i!=null&&i.getCollatedJuan))){k(!0),j(null),w(null);try{const[Q,W]=await Promise.all([i.getCollatedJuan(R,$),((F=i.getCollatedJuanText)==null?void 0:F.call(i,R,$))??Promise.resolve(null)]);j(Q),w(W)}catch{j(null),w(null)}finally{k(!1)}}},[R,i]);u.useEffect(()=>{T&&E(T)},[T,E]);const A=$=>{C($)};if(p)return e.jsx("div",{className:l,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:l,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!b)return null;const M=b.type==="kaozhen",P=Ui(b);return e.jsx(Is,{className:l,style:c,index:b,allFiles:P,isKaozhen:M,effectiveWorkId:R,transport:i,activeFile:T,handleSelectFile:A,juanData:m,juanRawText:_,juanLoading:y,searchQuery:z,setSearchQuery:S,onNavigate:o,workLabelCacheRef:I})},Is=({className:t,style:n,index:i,allFiles:o,isKaozhen:s,effectiveWorkId:r,transport:l,activeFile:c,handleSelectFile:a,juanData:d,juanRawText:p,juanLoading:f,searchQuery:g,setSearchQuery:x,onNavigate:h,workLabelCacheRef:v})=>{const{matchStates:m}=Cs({workId:r,transport:l,files:o,activeFile:c,activeJuan:d,activeRawText:p,query:g,isKaozhen:s});return e.jsxs("div",{className:t,style:n,children:[e.jsx("div",{style:{marginBottom:"12px"},children:e.jsx("input",{type:"text",placeholder:s?"搜索全部章节(条目、考证内容)...":"搜索全部册(书名、作者、正文)...",value:g,onChange:j=>x(j.target.value),style:{width:"100%",maxWidth:"420px",padding:"6px 10px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"}})}),e.jsxs("div",{style:{marginBottom:"16px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[e.jsx("div",{children:s?e.jsxs(e.Fragment,{children:[i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})," "]}),"共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 章"]}):e.jsxs("span",{children:["共 ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:o.length})," 卷"]})}),i.text_quality&&(()=>{const j=os(i.text_quality.grade);return j?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(is,{content:ir[j],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:or[j],cursor:"help"},children:Ci[j]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),e.jsx(gs,{files:o,groups:i.juan_groups,activeFile:c,onSelect:a,juanMeta:i.juan_metadata,matchStates:m}),f?e.jsx(Ve,{}):d?s?e.jsx(Ss,{juan:d,searchQuery:g,onNavigate:h,transport:l,workLabelCache:v}):e.jsx(_s,{juan:d,rawText:p,searchQuery:g,onNavigate:h}):c?e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"选择一卷查看内容"}):null,i.references&&i.references.length>0&&e.jsxs("div",{style:{marginTop:"32px",paddingTop:"16px",borderTop:"1px solid var(--bim-widget-border, #eee)"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #aaa)",marginBottom:"8px",letterSpacing:"2px"},children:"參考文獻"}),i.references.map((j,y)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[y+1,". "]}),j.url?e.jsx("a",{href:j.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:j.title}):e.jsx("span",{children:j.title}),j.author&&e.jsxs("span",{children:[",",j.author]}),j.note&&e.jsxs("span",{children:["。",j.note]})]},y))]})]})},zs={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},Ts={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function Rs(t){try{const n=new Date(t),i=o=>String(o).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const gn=({items:t,loading:n})=>{const i=me();return n?e.jsx(Ve,{}):t.length===0?e.jsx("div",{style:Es,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(o=>{const s=zs[o.type],r=Ts[o.status];return e.jsxs("div",{style:Bs,children:[e.jsxs("div",{style:Ls,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...Gn,background:s.color},children:s.label}),e.jsx("span",{style:{...Gn,background:r.color},children:r.label})]}),e.jsx("span",{style:Ws,children:Rs(o.createdAt)})]}),(o.resourceId||o.pageUrl)&&e.jsxs("div",{style:$s,children:[o.resourceId&&e.jsx("a",{href:i(o.resourceId),style:Un,children:o.resourceId}),o.pageUrl&&!o.resourceId&&e.jsx("a",{href:o.pageUrl,style:Un,children:o.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:As,children:o.content}),o.reply&&e.jsxs("div",{style:Ms,children:[e.jsx("div",{style:Fs,children:"回复"}),e.jsx("div",{children:o.reply})]})]},o.id)})})},Es={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},Bs={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},Ls={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},Gn={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},Ws={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},$s={fontSize:"12px",marginBottom:"6px"},Un={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},As={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},Ms={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},Fs={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},Zt=({transport:t,onNavigate:n,recommendedIds:i,activeTab:o,onTabChange:s,feedbackApiUrl:r})=>{const l=O(),[c,a]=u.useState(null),[d,p]=u.useState([]),[f,g]=u.useState("recommend"),[x,h]=u.useState([]),[v,m]=u.useState(!1),j=o??f,y=M=>{g(M),s==null||s(M)},[k,_]=u.useState(!0),[w,z]=u.useState(null),[S,I]=u.useState(null),[T,C]=u.useState(null);u.useEffect(()=>{let M=!1;if(t.getCounts)return t.getCounts().then(P=>{M||a({works:P.works,books:P.books,collections:P.collections})}).catch(()=>{}),()=>{M=!0}},[t]),u.useEffect(()=>{let M=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const $=await t.getRecommended();if($!=null&&$.groups)return $.groups.flatMap(F=>F.items.map(Q=>({...Q,group:F.name})))}catch{}return[]})().then(async $=>{if(M)return;const F=$.filter(W=>W.id);if(F.length===0){_(!1);return}const Q=await Promise.all(F.map(async W=>{if(W.type)return{id:W.id,title:W.title,type:W.type,author:W.author,dynasty:W.dynasty,role:W.role,edition:W.edition,has_text:W.has_text,has_image:W.has_image,has_collated:W.has_collated,subtype:W.subtype,primary_name:W.primary_name,group:W.group,fallbackDescription:W.description};try{let U=null;if(t.getEntry)U=await t.getEntry(W.id);else{const ne=await t.getItem(W.id);ne&&(U={id:W.id,title:ne.title||W.id,type:ne.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:X.extractType(W.id),group:W.group,fallbackDescription:W.description}}));M||(p(Q.filter(W=>W!==null)),_(!1))}),()=>{M=!0}},[t,i]);const b=u.useRef(!1),R=u.useRef(!1),E=u.useRef(!1);u.useEffect(()=>{if(j!=="catalog"||b.current)return;const M=t.getCatalogProgress??t.getResourceProgress;if(!M)return;b.current=!0;let P=!1;return M.call(t).then($=>{P||z($)}).catch(()=>{b.current=!1}),()=>{P=!0}},[t,j]),u.useEffect(()=>{if(j!=="collection"||R.current||!t.getCollectionProgress)return;R.current=!0;let M=!1;return t.getCollectionProgress().then(P=>{M||I(P)}).catch(()=>{R.current=!1}),()=>{M=!0}},[t,j]),u.useEffect(()=>{if(j!=="site"||E.current||!t.getSiteProgress)return;E.current=!0;let M=!1;return t.getSiteProgress().then(P=>{M||C(P)}).catch(()=>{E.current=!1}),()=>{M=!0}},[t,j]),u.useEffect(()=>{if(!r||j!=="feedback")return;let M=!1;return m(!0),fetch(r).then(P=>P.json()).then(P=>{!M&&P.success&&h(P.items||[])}).catch(()=>{}).finally(()=>{M||m(!1)}),()=>{M=!0}},[r,j]);const A=M=>{switch(M){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(rt,{label:l.home.recommendTab,active:j==="recommend",onClick:()=>y("recommend")}),e.jsx(rt,{label:l.home.catalogTab,active:j==="catalog",onClick:()=>y("catalog")}),e.jsx(rt,{label:l.home.collectionTab,active:j==="collection",onClick:()=>y("collection")}),e.jsx(rt,{label:l.home.siteTab,active:j==="site",onClick:()=>y("site")}),r&&e.jsx(rt,{label:l.home.feedbackTab,active:j==="feedback",onClick:()=>y("feedback")})]}),j==="recommend"&&e.jsx(Ps,{recommended:d,loading:k,onNavigate:n,getIcon:A,t:l}),j==="catalog"&&e.jsx(Yn,{progress:w,t:l,onNavigate:n}),j==="collection"&&e.jsx(Yn,{progress:S,t:l,onNavigate:n}),j==="site"&&e.jsx(Ds,{progress:T,t:l,totalWorks:(c==null?void 0:c.works)??0}),j==="feedback"&&r&&e.jsx(gn,{items:x,loading:v})]})})},rt=({label:t,active:n,onClick:i})=>e.jsx("button",{onClick:i,style:{padding:"8px 16px",fontSize:"14px",fontWeight:n?600:400,color:n?"var(--bim-primary, #2563eb)":"var(--bim-desc-fg, #717171)",background:"none",border:"none",borderBottom:n?"2px solid var(--bim-primary, #2563eb)":"2px solid transparent",cursor:"pointer",marginBottom:"-1px"},children:t}),Ps=({recommended:t,loading:n,onNavigate:i,getIcon:o,t:s})=>{const r=me();if(n)return e.jsx(Ve,{});if(t.length===0)return null;const l=new Map;for(const c of t){const a=c.group||s.home.recommendedBrowse;l.has(a)||l.set(a,[]),l.get(a).push(c)}return e.jsx(e.Fragment,{children:Array.from(l.entries()).map(([c,a])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:a.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:r(d.id),onClick:f=>{f.metaKey||f.ctrlKey||(f.preventDefault(),i==null||i(d.id))},style:{display:"flex",alignItems:"center",gap:"12px",padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",cursor:"pointer",background:"var(--bim-input-bg, #fff)",textDecoration:"none",color:"inherit"},children:[e.jsx("span",{style:{fontSize:"20px"},children:o(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),p&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p})]})]},d.id)})})]},c))})},Yn=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Ve,{});const o=[...t.resources].sort((c,a)=>c.priority-a.priority),s=["in_progress","done","todo"],r={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},l={in_progress:"var(--bim-progress-active, #f59e0b)",done:"var(--bim-progress-done, #10b981)",todo:"var(--bim-progress-todo, #9ca3af)"};return e.jsx("div",{children:s.map(c=>{const a=o.filter(d=>d.status===c);return a.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:l[c]}}),r[c]," (",a.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(d=>e.jsx(Hs,{item:d,t:n,statusColor:l[c],onNavigate:i},d.id))})]},c)})})},Hs=({item:t,t:n,statusColor:i,onNavigate:o})=>{const s=me(),r=t.total>0?Math.round(t.imported/t.total*100):0,l=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,a=t.collection_id||t.work_id;return a&&o?e.jsx("a",{href:s(a),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),o(a))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:l})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?yt(n.home.progressFormat,{imported:String(t.imported),total:String(t.total)}):n.home.totalPending})]}),t.total>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${r}%`,borderRadius:"2px",background:i,transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Ds=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Ve,{});const o=[...t.resources].sort((a,d)=>a.priority-d.priority),s=o.filter(a=>a.imported>0),r=o.filter(a=>a.imported===0),l=s.reduce((a,d)=>Math.max(a,d.imported),0),c=i>0?Math.round(l/i*100):0;return e.jsxs("div",{children:[i>0&&e.jsxs("div",{style:{padding:"12px 16px",marginBottom:"16px",borderRadius:"8px",background:"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)",fontSize:"13px",color:"var(--bim-fg, #333)"},children:[n.home.siteCoverage,": ",e.jsx("strong",{children:l.toLocaleString()})," / ",i.toLocaleString()," ",n.indexType.work," (",c,"%)"]}),s.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-done, #10b981)"}}),n.home.statusInProgress," (",s.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map(a=>e.jsx(Kn,{item:a,t:n,totalWorks:i},a.id))})]}),r.length>0&&e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:"var(--bim-progress-todo, #9ca3af)"}}),n.home.statusTodo," (",r.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:r.map(a=>e.jsx(Kn,{item:a,t:n,totalWorks:i},a.id))})]})]})},Kn=({item:t,t:n,totalWorks:i})=>{const o=i>0?Math.round(t.imported/i*100):0;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:500},children:t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:t.name}):t.name})}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.imported>0?`${t.imported.toLocaleString()} ${n.indexType.work} (${o}%)`:n.home.statusTodo})]}),t.imported>0&&i>0&&e.jsx("div",{style:{height:"4px",borderRadius:"2px",background:"var(--bim-widget-border, #e0e0e0)",overflow:"hidden",marginBottom:"4px"},children:e.jsx("div",{style:{height:"100%",width:`${o}%`,borderRadius:"2px",background:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},Jn="(max-width: 768px)";function Os(){const[t,n]=u.useState(()=>typeof window>"u"?!1:window.matchMedia(Jn).matches);return u.useEffect(()=>{const i=window.matchMedia(Jn),o=s=>n(s.matches);return i.addEventListener("change",o),()=>i.removeEventListener("change",o)},[]),t}const Ns=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:o,headerRight:s})=>{var P;const r=O(),{convert:l}=D(),c=Os(),[a,d]=u.useState(null),[p,f]=u.useState(null),[g,x]=u.useState(!1),[h,v]=u.useState("detail"),[m,j]=u.useState([]),[y,k]=u.useState(!1),[_,w]=u.useState(null),[z,S]=u.useState(!1),I=u.useCallback(async $=>{if(!t.getCollatedEditionIndex){w(null);return}S(!0);try{const F=await t.getCollatedEditionIndex($);w(F)}catch{w(null)}finally{S(!1)}},[t]),T=u.useCallback(async $=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){j([]);return}k(!0);try{if(t.getCollectionCatalogs){const F=await t.getCollectionCatalogs($);j(F||[])}else if(t.getCollectionCatalog){const F=await t.getCollectionCatalog($);j(F?[{resource_id:"",data:F}]:[])}}catch{j([])}finally{k(!1)}},[t]),C=u.useCallback(async $=>{if(i){i($);return}d($),f(null),j([]),w(null),v("detail"),x(!0);try{const F=await t.getItem($.id);F&&(f(F),F.type==="collection"?T($.id):F.type==="work"&&F.has_collated&&I($.id))}catch(F){console.error("加载详情失败:",F)}finally{x(!1)}},[t,i,T,I]),b=u.useCallback(async $=>{f(null),j([]),w(null),v("detail"),x(!0);try{const F=await t.getItem($);F&&(f(F),d({id:$,title:F.title||$,type:F.type||"book"}),F.type==="collection"?T($):F.type==="work"&&F.has_collated&&I($))}catch(F){console.error("导航失败:",F)}finally{x(!1)}},[t,T,I]),R=(p==null?void 0:p.type)==="collection"&&(m.length>0||y)||(p==null?void 0:p.type)==="work"&&(_||z),E=c&&(g||p),A=u.useCallback(()=>{d(null),f(null),j([]),w(null),v("detail")},[]),M=e.jsx(e.Fragment,{children:g?e.jsx(Ve,{}):p?e.jsxs(e.Fragment,{children:[(R||s)&&e.jsxs("div",{style:{display:"flex",alignItems:"center",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",padding:c?"0 12px":"0 48px",background:"var(--bim-input-bg, #fff)",flexShrink:0,overflowX:c?"auto":void 0},children:[R&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>v("detail"),style:_t(h==="detail"),children:r.detailTab.basicInfo}),p.type==="collection"&&y&&m.length===0&&e.jsxs("button",{onClick:()=>{},style:_t(!1),children:[r.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&m.map($=>e.jsx("button",{onClick:()=>v(`catalog:${$.resource_id}`),style:_t(h===`catalog:${$.resource_id}`),children:$.short_name?`${l($.short_name)}${r.detailTab.catalogSuffix}`:r.detailTab.collectionCatalog},$.resource_id)),p.type==="work"&&(_||z)&&e.jsxs("button",{onClick:()=>v("collated"),style:_t(h==="collated"),children:[r.detailTab.collatedEdition,z&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:h==="detail"?e.jsx(cn,{data:p,transport:t,onNavigate:b}):h.startsWith("catalog:")?e.jsx(dn,{data:(P=m.find($=>`catalog:${$.resource_id}`===h))==null?void 0:P.data,onNavigate:b}):h==="collated"?e.jsx(fn,{index:_||void 0,workId:p.id,transport:t,onNavigate:b}):null})]}):e.jsx(Zt,{transport:t,onNavigate:b,recommendedIds:o})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:E?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)",flexShrink:0},children:e.jsxs("button",{onClick:A,style:{padding:"4px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px"},children:["← ",r.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:M})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(Xt,{transport:t,onEntryClick:C,hideModeIndicator:n}),!p&&e.jsx(Zt,{transport:t,onNavigate:b,recommendedIds:o})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(Xt,{transport:t,onEntryClick:C,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:M})]})};function _t(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Pe(t){return t.replace(/\.md$/,"")}const Yi=({index:t,bookId:n,transport:i,activeChapter:o,onChapterChange:s})=>{const[r,l]=u.useState(t??null),[c,a]=u.useState(null),d=o!==void 0?o:c,p=u.useCallback(m=>{s?s(m):a(m)},[s]),[f,g]=u.useState(null),[x,h]=u.useState(!1);u.useEffect(()=>{t&&l(t)},[t]),u.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let m=!1;return i.getBookFullTextIndex(n).then(j=>{m||l(j)}),()=>{m=!0}},[n,i,t]),u.useEffect(()=>{if(!r||r.chapters.length===0)return;const m=Pe(r.chapters[0].file);if(!d){p(m);return}const j=Pe(d);r.chapters.some(k=>Pe(k.file)===j)||p(m)},[r,d,p]);const v=u.useMemo(()=>{if(!r||!d)return null;const m=Pe(d);return r.chapters.find(j=>Pe(j.file)===m)??null},[r,d]);return u.useEffect(()=>{if(!n||!v||!i.getBookFullTextChapter)return;let m=!1;return h(!0),g(null),i.getBookFullTextChapter(n,v.file).then(j=>{m||g(j)}).catch(()=>{m||g(null)}).finally(()=>{m||h(!1)}),()=>{m=!0}},[n,v,i]),r?r.chapters.length===0?e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"}):e.jsxs("div",{style:{display:"flex",gap:16,alignItems:"stretch",minHeight:400},children:[e.jsxs("aside",{style:{flex:"0 0 240px",maxHeight:"calc(100vh - 200px)",overflowY:"auto",borderRight:"1px solid var(--bim-border, #e5e5e5)",paddingRight:12},children:[e.jsxs("div",{style:{padding:"8px 12px",fontSize:13,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:[r.version_label," · 共 ",r.total_chapters," ",(r.chapters.length===1,"章")]}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:r.chapters.map(m=>{const j=Pe(m.file),y=j===Pe(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(j),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:y?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:y?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:y?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:m.title})},m.file)})})]}),e.jsxs("main",{style:{flex:1,maxHeight:"calc(100vh - 200px)",overflowY:"auto",paddingLeft:8},children:[v&&e.jsxs("header",{style:{marginBottom:16,paddingBottom:12,borderBottom:"1px solid var(--bim-border, #e5e5e5)"},children:[e.jsx("h2",{style:{margin:0,fontSize:20,color:"var(--bim-fg, #2c2c2c)"},children:v.title}),e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"var(--bim-desc-fg, #888)"},children:["来源:",e.jsx("a",{href:r.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:r.source.name}),r.source.license&&e.jsxs(e.Fragment,{children:[" · ",r.source.license]})]})]}),x&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!x&&f&&e.jsx("article",{style:{fontSize:16,lineHeight:1.9,color:"var(--bim-fg, #2c2c2c)",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:'"Songti SC", "Source Han Serif", "Noto Serif CJK SC", serif'},children:f.replace(/^##\s+[^\n]+\n+/,"")}),!x&&!f&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})]}):e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"})},Vs=({data:t,onNavigate:n,className:i,style:o})=>{var p;const s=O(),{convert:r}=D(),[l,c]=u.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[a,d]=u.useState(null);return e.jsxs("div",{className:i,style:o,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:r(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(f=>e.jsx(Gs,{division:f,expanded:l===f.name,onToggle:()=>c(l===f.name?null:f.name),expandedCat:a,onCatToggle:g=>d(a===g?null:g),onNavigate:n},f.name))})]})},Gs=({division:t,expanded:n,onToggle:i,expandedCat:o,onCatToggle:s,onNavigate:r})=>{const{convert:l}=D(),c=t.categories.reduce((a,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return a+(p.zhulu||0)+(p.cunmu||0)},0);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",border:"none",background:n?"color-mix(in srgb, var(--bim-primary, #2563eb) 6%, transparent)":"var(--bim-bg, #f8f8f8)",cursor:"pointer",fontSize:"15px",fontWeight:600,color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsx("span",{children:l(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(a=>{const d=`${t.name}/${a.name}`;return e.jsx(Us,{category:a,expanded:o===d,onToggle:()=>s(d),onNavigate:r},a.name)})})]})},Us=({category:t,expanded:n,onToggle:i,onNavigate:o})=>{var a,d,p,f;const{convert:s}=D(),r=((a=t.books)==null?void 0:a.zhulu)||[],l=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||r.length)+(((f=t.stats)==null?void 0:f.cunmu)||l.length);return e.jsxs("div",{children:[e.jsxs("button",{onClick:i,style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 14px 6px 28px",border:"none",background:n?"var(--bim-input-bg, #fff)":"transparent",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",textAlign:"left"},children:[e.jsxs("span",{style:{fontWeight:500},children:[s(t.name),t.volumes&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px",fontWeight:400},children:["卷",t.volumes]})]}),e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[c," 部 ",n?"▲":"▼"]})]}),n&&(r.length>0||l.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[r.length>0&&e.jsx(qn,{label:"著錄",books:r,onNavigate:o}),l.length>0&&e.jsx(qn,{label:"存目",books:l,onNavigate:o})]})]})},qn=({label:t,books:n,onNavigate:i})=>{const{convert:o}=D(),s=me(),[r,l]=u.useState(n.length<=20),c=r?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((a,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:a.work_id&&i?e.jsx("a",{href:s(a.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(a.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:o(a.title)}):o(a.title)}),a.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:o(a.volumes)}),a.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:o(a.author).slice(0,20)})]},d))}),!r&&e.jsxs("button",{onClick:()=>l(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},Se=({title:t,onSave:n,onAskAI:i,extraButtons:o,children:s})=>{const r=O();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[o,i&&e.jsx("button",{onClick:i,style:Ks,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Ys,children:r.action.save})]})]}),s]})},Ys={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Ks={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},ge=({label:t,value:n,onChange:i,placeholder:o,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:r=>i(r.target.value),placeholder:o,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),He=({value:t,onChange:n,placeholder:i})=>{const o=u.useRef(null);return u.useEffect(()=>{o.current&&(o.current.style.height="auto",o.current.style.height=`${o.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:o,value:t||"",onChange:s=>n(s.target.value),placeholder:i,style:{width:"100%",minHeight:"40px",resize:"none",overflow:"hidden",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",padding:"8px",fontFamily:"inherit",fontSize:"13px",lineHeight:"1.4",outline:"none",boxSizing:"border-box",display:"block"}})},Wt=({children:t,color:n,style:i})=>e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",fontSize:"11px",fontWeight:500,borderRadius:"4px",background:n||"var(--bim-primary-soft, rgba(0,120,212,0.15))",color:n?"#fff":"var(--bim-fg, #333)",...i},children:t});function Js(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ct=({value:t,onChange:n,label:i})=>{const[o,s]=u.useState(!1),r=u.useRef(null),l=Js(t||"");return u.useEffect(()=>{o&&r.current&&r.current.focus()},[o]),!o&&l?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Xn,children:i}),e.jsxs("div",{onClick:()=>s(!0),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",background:"var(--bim-input-bg, #fff)",cursor:"pointer",minHeight:"30px"},children:[e.jsx("span",{style:{fontWeight:500,fontSize:"13px",color:"var(--bim-fg, #333)"},children:l.name}),e.jsx(Wt,{children:l.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:Xn,children:i}),e.jsx("input",{ref:r,type:"text",value:t||"",onChange:c=>n(c.target.value),onBlur:()=>s(!1),style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]})},Xn={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function qs(t){switch(t){case"url":return"var(--bim-source-url, #2196f3)";case"bookID":return"var(--bim-source-bookid, #4caf50)";default:return"var(--bim-desc-fg, #717171)"}}function Xs(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Ki=({items:t,onChange:n,onOpenEntityPicker:i})=>{const o=O(),[s,r]=u.useState(null),l=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),r(t.length)},c=f=>{n(t.filter((g,x)=>x!==f)),s===f&&r(null)},a=(f,g,x)=>{const h=[...t];h[f]={...h[f],[g]:x},n(h)},d=(f,g)=>{const x=[...t];x[f]={...x[f],type:g,id:"",name:""},n(x),g==="bookID"&&i&&i(h=>{const v=[...t];v[f]={...v[f],id:h.id,name:h.title,type:"bookID"},n(v)})},p=f=>{i&&i(g=>{const x=[...t];x[f]={...x[f],id:g.id,name:g.title,type:"bookID"},n(x)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((f,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>r(s===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:f.name||`${o.editor.sourcePlaceholder} ${g+1}`}),f.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:qs(f.type),color:"white",borderRadius:"3px",fontWeight:500},children:Xs(f.type)}),e.jsx("button",{onClick:x=>{x.stopPropagation(),c(g)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!f.type&&e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...Zn,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...Zn,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:o.editor.enterUrl})]})]})]}),f.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:Be,children:o.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const x=[...t];x[g]={...x[g],type:"",id:"",name:""},n(x)},style:Qn,children:o.action.changeType})]}),f.id&&f.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-source-bookid, #4caf50)",borderRadius:"6px"},children:[e.jsx("span",{style:{color:"var(--bim-source-bookid, #4caf50)",fontSize:"16px"},children:"✓"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:f.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:f.id})]}),e.jsx("button",{onClick:()=>p(g),style:{background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-fg, #333)",cursor:"pointer",padding:"4px 10px",borderRadius:"4px",fontSize:"12px"},children:o.action.reselect})]}):e.jsxs("button",{onClick:()=>p(g),style:{width:"100%",padding:"14px",border:"2px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:[e.jsx("span",{children:"🔍"}),e.jsx("span",{children:o.action.clickToSelectBookOrWork})]})]})}),f.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:Be,children:o.label.sourceName}),e.jsx("button",{onClick:()=>{const x=[...t];x[g]={...x[g],type:"",id:"",name:""},n(x)},style:Qn,children:o.action.changeType})]}),e.jsx("input",{type:"text",value:f.name,onChange:x=>a(g,"name",x.target.value),placeholder:o.editor.sourceNamePlaceholder,style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.urlAddress}),e.jsx("input",{type:"text",value:f.id,onChange:x=>a(g,"id",x.target.value),placeholder:"https://...",style:Ye})]})]}),f.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...Be,opacity:.7},children:o.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.detailsOptional}),e.jsx("input",{type:"text",value:f.details,onChange:x=>a(g,"details",x.target.value),placeholder:o.editor.detailsPlaceholder,style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.positionOptional}),e.jsx("input",{type:"text",value:f.position,onChange:x=>a(g,"position",x.target.value),placeholder:"如: 卷三, p.52",style:Ye})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.dataVersionOptional}),e.jsx("input",{type:"text",value:f.version,onChange:x=>a(g,"version",x.target.value),placeholder:"如: v1.0, 2024-01",style:Ye})]}),e.jsxs("div",{children:[e.jsx("label",{style:Be,children:o.label.processorVersionOptional}),e.jsx("input",{type:"text",value:f.processor_version,onChange:x=>a(g,"processor_version",x.target.value),placeholder:"如: v0.1",style:Ye})]})]})]})]})})]},g)),e.jsxs("button",{onClick:l,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:o.action.addSource})]})]})},Be={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},Ye={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},Zn={flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:"4px",padding:"16px 12px",background:"var(--bim-bg, #fff)",border:"2px solid",borderRadius:"8px",cursor:"pointer",fontSize:"13px",fontWeight:500,transition:"all 0.2s"},Qn={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Ji(t){if(!t||!t.trim())return[];try{const n=JSON.parse(t);if(Array.isArray(n))return n.map(i=>({id:i.id||"",name:i.name||"",type:i.type||"",details:i.details||"",position:i.position||"",version:i.version||"",processor_version:i.processor_version||""}))}catch{}return[]}function qi(t){return!t||t.length===0?"":JSON.stringify(t)}const Xi=({entityType:t,entityId:n,entityTitle:i,parentWork:o,parentCollection:s,belongsToWork:r,belongsToCollection:l,childWorks:c,childCollections:a,containedBooks:d,siblingBooks:p,onLinkEntity:f,onUnlinkEntity:g,onViewEntity:x,onCreateAndLink:h,onSaveRelations:v})=>{const m=O();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:m.section.relations})]}),v&&e.jsx("button",{onClick:v,style:Zs,children:m.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(st,{direction:"up",title:m.relation.belongsToWork,entity:r,onView:x,onUnlink:()=>g("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(st,{direction:"up",title:m.relation.containedInCollection,entity:l,onView:x,onUnlink:()=>g("collectionId"),onLink:()=>f("collectionId","collection"),onCreate:()=>h("collectionId","collection",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),r&&p&&p.length>0&&e.jsx(Ke,{direction:"horizontal",title:`${m.relation.siblingVersions} (${p.length})`,entities:p,onView:x,onAdd:()=>h("siblingBook","book",{workId:r.id}),addLabel:m.relation.addVersionForWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(st,{direction:"up",title:m.relation.parentWork,entity:o,onView:x,onUnlink:()=>g("parentWorkId"),onLink:()=>f("parentWorkId","work"),onCreate:()=>h("parentWorkId","work"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),c&&c.length>0&&e.jsx(Ke,{direction:"down",title:`${m.relation.childWorks} (${c.length})`,entities:c,onView:x,onAdd:()=>h("childWork","work",{parentWorkId:n}),addLabel:m.action.addSubWork,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),a&&a.length>0&&e.jsx(Ke,{direction:"down",title:`${m.relation.collectionImpl} (${a.length})`,entities:a,onView:x,onAdd:()=>h("childCollection","collection",{workId:n}),addLabel:m.action.addCollectionImpl,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ke,{direction:"down",title:`${m.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,onAdd:()=>h("childBook","book",{workId:n}),addLabel:m.action.addVersion,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(st,{direction:"up",title:m.relation.correspondingWork,entity:r,onView:x,onUnlink:()=>g("workId"),onLink:()=>f("workId","work"),onCreate:()=>h("workId","work",{title:i}),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(st,{direction:"up",title:m.relation.parentCollection,entity:s,onView:x,onUnlink:()=>g("parentCollectionId"),onLink:()=>f("parentCollectionId","collection"),onCreate:()=>h("parentCollectionId","collection"),linkLabel:m.action.linkExisting,createLabel:m.action.createAndLink,notLinkedLabel:m.relation.notLinked,viewLabel:m.action.viewEntity,unlinkLabel:m.action.unlink}),e.jsx(Ke,{direction:"down",title:`${m.relation.childCollections} (${(a==null?void 0:a.length)??0})`,entities:a||[],onView:x,onAdd:()=>h("childCollection","collection",{parentCollectionId:n}),addLabel:m.action.addSubCollection,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore}),e.jsx(Ke,{direction:"down",title:`${m.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:x,onAdd:()=>h("childBook","book",{collectionId:n}),addLabel:m.action.addBook,noneLabel:m.relation.none,expandMoreLabel:m.action.expandMore})]})]})]})},st=({direction:t,title:n,entity:i,onView:o,onUnlink:s,onLink:r,onCreate:l,linkLabel:c,createLabel:a,notLinkedLabel:d,viewLabel:p,unlinkLabel:f})=>{const g=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️";return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:g,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:x}),e.jsx("span",{children:n})]}),i?e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:Zi(i.type)}),e.jsx("span",{style:{fontWeight:500},children:i.title}),e.jsx("span",{style:{fontSize:"11px",opacity:.6},children:i.id})]}),e.jsxs("div",{style:{display:"flex",gap:"4px"},children:[e.jsx(ei,{onClick:()=>o(i),title:p,children:"👁️"}),e.jsx(ei,{onClick:s,title:f,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(Qt,{onClick:r,children:c}),e.jsx(Qt,{onClick:l,primary:!0,children:a})]})]})},Ke=({direction:t,title:n,entities:i,onView:o,onAdd:s,addLabel:r,noneLabel:l,expandMoreLabel:c})=>{const[a,d]=u.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",f=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=a?i:i.slice(0,5);return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"10px",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{fontSize:"12px",color:p,fontWeight:500,marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:f}),e.jsx("span",{children:n})]}),i.length>0?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[g.map(x=>e.jsxs("div",{onClick:()=>o(x),style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",cursor:"pointer",fontSize:"13px"},children:[e.jsx("span",{children:Zi(x.type)}),e.jsx("span",{children:x.title})]},x.id)),i.length>5&&!a&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",i.length-5,")"]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:l}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(Qt,{onClick:s,primary:!0,children:["+ ",r]})})]})},ei=({onClick:t,title:n,danger:i,children:o})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:o}),Qt=({onClick:t,primary:n,children:i})=>e.jsx("button",{onClick:t,style:{padding:"4px 10px",fontSize:"11px",border:n?"none":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:n?"var(--bim-primary, #0078d4)":"transparent",color:n?"var(--bim-primary-fg, #fff)":"inherit",cursor:"pointer"},children:i});function Zi(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Zs={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",gap:"4px"},Qi=({isOpen:t,entityType:n,title:i,onSelect:o,onCancel:s,onCreate:r,searchResults:l,onSearch:c,isLoading:a,excludeId:d})=>{const[p,f]=u.useState(""),g=d?l.filter(m=>m.id!==d):l;u.useEffect(()=>{t&&(f(""),c(""))},[t]);const x=m=>{f(m),c(m)};if(!t)return null;const h=n==="work"?"作品":n==="book"?"书籍":"丛编",v=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Qs,children:e.jsxs("div",{style:el,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600},children:i}),e.jsx("button",{onClick:s,style:tl,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:m=>x(m.target.value),placeholder:`搜索${h}名称或 ID...`,autoFocus:!0,style:nl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:a?e.jsx("div",{style:Ut,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(m=>e.jsxs("div",{onClick:()=>o(m),style:il,children:[e.jsx("span",{style:{fontSize:"16px"},children:v}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[m.title,m.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:m.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[m.id,m.author&&` · ${m.author}`,m.dynasty&&` · ${m.dynasty}`]})]})]},m.id))}):p?e.jsxs("div",{style:Ut,children:["未找到匹配的",h]}):e.jsxs("div",{style:Ut,children:["输入关键词搜索",h]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:r,style:ol,children:["创建新",h,"并关联"]})]})]})})},Qs={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},el={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},tl={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit"},nl={width:"100%",padding:"10px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},il={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},Ut={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},ol={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},ti={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},rl={work:"📜",book:"📖",collection:"📚",entity:"👤"},eo=({isOpen:t,entityType:n,relationField:i,inheritData:o,onConfirm:s,onCancel:r})=>{const[l,c]=u.useState(""),a=u.useRef(null);u.useEffect(()=>{t&&(c((o==null?void 0:o.title)||""),setTimeout(()=>{var g,x;(g=a.current)==null||g.focus(),(x=a.current)==null||x.select()},100))},[t,o==null?void 0:o.title]);const d=g=>{g.key==="Enter"&&l.trim()?p():g.key==="Escape"&&r()},p=()=>{l.trim()&&s(l.trim(),{...o,title:l.trim()})};if(!t)return null;const f=()=>{switch(i){case"parentWorkId":return"创建父作品";case"workId":return"创建所属作品";case"collectionId":return"创建所属丛编";case"parentCollectionId":return"创建父丛编";case"childWork":return"创建子作品";case"childBook":case"siblingBook":return"创建书籍";case"childCollection":return"创建子丛编";default:return`创建新${ti[n]}`}};return e.jsx("div",{style:sl,onClick:g=>{g.target===g.currentTarget&&r()},children:e.jsxs("div",{style:ll,onClick:g=>g.stopPropagation(),children:[e.jsxs("div",{style:{fontSize:"16px",fontWeight:600,marginBottom:"16px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:rl[n]}),e.jsx("span",{children:f()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:a,type:"text",value:l,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${ti[n]}名称...`,style:al})]}),((o==null?void 0:o.author)||(o==null?void 0:o.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(o==null?void 0:o.author)&&e.jsxs("div",{children:["作者: ",o.author]}),(o==null?void 0:o.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",o.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:r,style:cl,children:"取消"}),e.jsx("button",{onClick:p,disabled:!l.trim(),style:{...dl,opacity:l.trim()?1:.6,cursor:l.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},sl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},ll={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"100%",maxWidth:"min(500px, calc(100vw - 32px))",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},al={width:"100%",padding:"8px 12px",fontSize:"14px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box"},cl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},dl={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function pl(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function to(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function ul(t){switch(t){case"work":return"var(--bim-editor-type-work, #4caf50)";case"collection":return"var(--bim-editor-type-collection, #2196f3)";case"book":return"var(--bim-editor-type-book, #ff9800)";default:return"var(--bim-desc-fg, #717171)"}}const no=({isOpen:t,title:n,filterType:i="all",recentEntities:o=[],excludeId:s,showCreateButton:r=!1,createButtonText:l,onSelect:c,onCancel:a,onCreate:d,onSearch:p})=>{const[f,g]=u.useState(""),[x,h]=u.useState([]),[v,m]=u.useState(!1),[j,y]=u.useState("recent");u.useEffect(()=>{t&&(g(""),h([]),y(o.length>0?"recent":"search"))},[t,o.length]),u.useEffect(()=>{if(!f.trim()){h([]);return}const I=setTimeout(async()=>{m(!0);try{h(await p(f,i))}catch{h([])}finally{m(!1)}},300);return()=>clearTimeout(I)},[f,i,p]);const k=u.useCallback(I=>{g(I.target.value),I.target.value.trim()&&y("search")},[]),_=u.useCallback(I=>s?I.filter(T=>T.id!==s):I,[s]);if(!t)return null;const w=n||(i==="all"?"选择实体":`选择${to(i)}`),z=_(o),S=_(x);return e.jsx("div",{style:fl,children:e.jsxs("div",{style:gl,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"16px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"15px",fontWeight:600},children:w}),e.jsx("button",{onClick:a,style:ml,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:f,onChange:k,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:hl}),e.jsx("span",{style:{position:"absolute",left:"14px",top:"50%",transform:"translateY(-50%)",opacity:.5,fontSize:"14px"},children:"🔍"}),v&&e.jsx("span",{style:{position:"absolute",right:"14px",top:"50%",transform:"translateY(-50%)",fontSize:"12px",opacity:.6},children:"搜索中..."})]})}),z.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(ni,{active:j==="recent",onClick:()=>y("recent"),children:["最近使用 (",z.length,")"]}),e.jsxs(ni,{active:j==="search",onClick:()=>y("search"),children:["搜索结果 ",S.length>0&&`(${S.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:j==="recent"&&z.length>0?e.jsx(ii,{entities:z,onSelect:c}):f.trim()?v?e.jsx(Yt,{message:"搜索中..."}):S.length>0?e.jsx(ii,{entities:S,onSelect:c}):e.jsx(Yt,{message:"未找到匹配的结果"}):e.jsx(Yt,{message:"输入关键词开始搜索"})}),r&&d&&e.jsxs("div",{style:{padding:"12px 20px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsx("button",{onClick:d,style:bl,children:l||"创建新实体"})]})]})})},ni=({active:t,onClick:n,children:i})=>e.jsx("button",{onClick:n,style:{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-fg, #333)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",fontWeight:t?600:400,marginBottom:"-1px"},children:i}),ii=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(xl,{entity:i,onClick:()=>n(i)},i.id))}),xl=({entity:t,onClick:n})=>{const[i,o]=u.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background:i?"var(--bim-primary-soft, rgba(0,120,212,0.15))":"var(--bim-primary-soft, rgba(0,120,212,0.05))",transition:"background 0.1s"},children:[e.jsx("span",{style:{fontSize:"18px"},children:pl(t.type)}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontWeight:500,fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[t.title,t.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:t.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7,display:"flex",alignItems:"center",gap:"6px",marginTop:"2px"},children:[e.jsx("code",{style:{fontSize:"10px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"1px 4px",borderRadius:"2px"},children:t.id}),t.author&&e.jsx("span",{children:t.author}),t.dynasty&&e.jsx("span",{children:t.dynasty})]})]}),e.jsx("span",{style:{fontSize:"10px",padding:"3px 8px",background:ul(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:to(t.type)})]})},Yt=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),fl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},gl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"550px",maxWidth:"calc(100vw - 32px)",maxHeight:"80vh",display:"flex",flexDirection:"column",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},ml={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},hl={width:"100%",padding:"12px 16px",paddingLeft:"40px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"13px",boxSizing:"border-box"},bl={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},yl={work:"var(--bim-editor-type-work, #4caf50)",collection:"var(--bim-editor-type-collection, #2196f3)",book:"var(--bim-editor-type-book, #ff9800)",entity:"var(--bim-editor-type-entity, #9c27b0)"},vl={work:"📜",collection:"📚",book:"📖",entity:"👤"},io=({data:t,onChange:n,onSave:i,transport:o,onNavigate:s,showDelete:r,onDelete:l,onAskAI:c,renderSectionActions:a,onDownloadResource:d,downloadStatuses:p,relations:f,onRelationsChange:g})=>{var te;const x=O(),[h,v]=u.useState(!1),[m,j]=u.useState("work"),[y,k]=u.useState(""),[_,w]=u.useState(""),[z,S]=u.useState([]),[I,T]=u.useState(!1),[C,b]=u.useState(!1),[R,E]=u.useState("work"),[A,M]=u.useState(""),[P,$]=u.useState(),[F,Q]=u.useState(!1),[W,U]=u.useState(null),[ne,B]=u.useState([]);u.useRef(null);const V=t.type,Y=V==="work",ie=V==="collection",G=V==="book",K=u.useCallback((L,Z)=>{n({...t,[L]:Z})},[t,n]),de=u.useCallback((L,Z)=>{k(L),j(Z),w(x.editor.selectToLink+x.indexType[Z]),S([]),v(!0)},[x]),he=u.useCallback(L=>{o!=null&&o.unlinkEntity&&o.unlinkEntity(t.id,L)},[o,t.id]),pe=u.useCallback(L=>{s==null||s(L.id,L.type)},[s]),le=u.useCallback((L,Z,se)=>{const J={...se,author:(se==null?void 0:se.author)||t.author,dynasty:(se==null?void 0:se.dynasty)||t.dynasty};E(Z),M(L),$(J),b(!0)},[t.author,t.dynasty]),ve=u.useCallback((L,Z)=>{o!=null&&o.createAndLink&&o.createAndLink(t.id,A,{type:R,title:L,inheritData:Z}),b(!1)},[o,t.id,A,R]),Fe=u.useCallback(L=>{if(!L.trim()){S([]);return}T(!0),o!=null&&o.searchEntities&&o.searchEntities(L,m).then(Z=>{S(Z),T(!1)}).catch(()=>{S([]),T(!1)})},[o,m]),_e=u.useCallback(L=>{o!=null&&o.linkEntity&&o.linkEntity(t.id,y,L.id),v(!1)},[o,t.id,y]),Ge=u.useCallback(()=>{i()},[i]),tt=u.useCallback(L=>{U(()=>L),Q(!0),o!=null&&o.getRecentEntities&&o.getRecentEntities().then(B).catch(()=>{})},[o]),N=u.useCallback((L,Z)=>o!=null&&o.searchEntities?o.searchEntities(L,Z==="all"?void 0:Z):Promise.resolve([]),[o]),oe=u.useCallback(L=>{o!=null&&o.addRecentEntity&&o.addRecentEntity(L),B(Z=>[L,...Z.filter(se=>se.id!==L.id)].slice(0,10)),W==null||W(L),Q(!1),U(null)},[o,W]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:vl[V]}),e.jsx("span",{children:t.title||x.editor.untitled}),e.jsx(Wt,{children:t.id}),e.jsx(Wt,{color:yl[V],children:x.indexType[V]})]})}),e.jsx(Se,{title:x.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:a==null?void 0:a("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ct,{label:Y?x.editor.workTitle:ie?x.editor.collectionTitle:x.editor.bookTitle,value:t.title,onChange:L=>K("title",L)}),G&&e.jsx(Ct,{label:x.editor.belongsToWork,value:t.workName||"",onChange:L=>K("workName",L)}),e.jsx(ge,{label:x.editor.authorLabel,value:t.author||"",onChange:L=>K("author",L)}),e.jsx(ge,{label:x.editor.dynastyLabel,value:t.dynasty||"",onChange:L=>K("dynasty",L)}),(G||ie)&&e.jsx(Ct,{label:x.editor.containedIn,value:t.collection||"",onChange:L=>K("collection",L)}),(G||ie)&&e.jsx(ge,{label:x.editor.holderLabel,value:t.holder||"",onChange:L=>K("holder",L)}),(G||ie)&&e.jsx(ge,{label:G?x.editor.pageLabel:x.editor.volumeLabel,value:t.pages||"",onChange:L=>K("pages",L)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(ge,{label:x.editor.firstImageLabel,value:t.firstImage||"",onChange:L=>K("firstImage",L)})})]})}),e.jsx(Se,{title:x.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(He,{value:t.description||"",onChange:L=>K("description",L),placeholder:x.editor.descriptionPlaceholder})}),(((te=t.additional_works)==null?void 0:te.length)||0)>0&&e.jsx(Se,{title:x.section.additionalWorks,onSave:i,children:e.jsx(jl,{items:t.additional_works||[],onChange:L=>K("additional_works",L)})}),e.jsx(Se,{title:x.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(Sl,{items:t.indexed_by||[],onChange:L=>K("indexed_by",L)})}),e.jsx(Se,{title:x.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(kl,{items:t.emendated_by||[],onChange:L=>K("emendated_by",L)})}),e.jsx(Se,{title:x.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(qt,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(Se,{title:x.section.imageResources,onSave:i,children:e.jsx(qt,{items:t.resources||[],onChange:L=>K("resources",L),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(Se,{title:x.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Ki,{items:Ji(t.sources||""),onChange:L=>K("sources",qi(L)),onOpenEntityPicker:tt})}),(G||ie)&&e.jsx(Se,{title:x.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(He,{value:t.provenance||"",onChange:L=>K("provenance",L),placeholder:x.editor.provenancePlaceholder})}),G&&e.jsx(Se,{title:x.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(He,{value:t.otherEditions||"",onChange:L=>K("otherEditions",L),placeholder:x.editor.otherEditionsPlaceholder})}),e.jsx(Xi,{entityType:V,entityId:t.id,entityTitle:t.title,parentWork:f==null?void 0:f.parentWork,parentCollection:f==null?void 0:f.parentCollection,belongsToWork:f==null?void 0:f.belongsToWork,belongsToCollection:f==null?void 0:f.belongsToCollection,childWorks:f==null?void 0:f.childWorks,childCollections:f==null?void 0:f.childCollections,containedBooks:f==null?void 0:f.containedBooks,siblingBooks:f==null?void 0:f.siblingBooks,onLinkEntity:de,onUnlinkEntity:he,onViewEntity:pe,onCreateAndLink:le,onSaveRelations:Ge}),r&&l&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children:x.section.dangerZone}),e.jsx("p",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginBottom:"12px"},children:x.editor.dangerZoneDesc}),e.jsx("button",{onClick:l,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:x.editor.deleteEntity})]}),e.jsx(Qi,{isOpen:h,entityType:m,title:_,onSelect:_e,onCancel:()=>v(!1),onCreate:()=>{v(!1),le(y,m)},searchResults:z,onSearch:Fe,isLoading:I,excludeId:t.id}),e.jsx(eo,{isOpen:C,entityType:R,relationField:A,inheritData:P,onConfirm:ve,onCancel:()=>b(!1)}),e.jsx(no,{isOpen:F,title:x.action.selectBookOrWork,filterType:"all",recentEntities:ne,excludeId:t.id,onSelect:oe,onCancel:()=>{Q(!1),U(null)},onSearch:N})]})};function jl({items:t,onChange:n}){const i=O(),o=(l,c,a)=>{const d=t.map((p,f)=>f===l?{...p,[c]:a}:p);n(d)},s=l=>n(t.filter((c,a)=>a!==l)),r=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((l,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(ge,{label:i.editor.bookNameLabel,value:l.book_title,onChange:a=>o(c,"book_title",a)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(ge,{label:i.label.juanCount,value:l.n_juan!=null?String(l.n_juan):"",onChange:a=>o(c,"n_juan",a&&parseInt(a,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:r,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:i.action.addAdditionalWork})]})}function oo({items:t,onChange:n,showMeta:i,addLabel:o}){const s=O(),[r,l]=u.useState(null),c=(p,f,g)=>{const x=t.map((h,v)=>v===p?{...h,[f]:g||void 0}:h);n(x)},a=p=>{n(t.filter((f,g)=>g!==p)),r===p&&l(null)},d=()=>{n([...t,{source:""}]),l(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,f)=>{const g=r===f;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>l(g?null:f),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:p.source||s.editor.unnamedSource}),p.source_bid&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:p.source_bid}),e.jsx("button",{onClick:x=>{x.stopPropagation(),a(f)},style:{padding:"2px 6px",fontSize:"11px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"3px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)"},children:"✕"})]}),!g&&i&&(p.title_info||p.author_info)&&e.jsxs("div",{style:{padding:"0 12px 8px 28px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[p.title_info,p.title_info&&p.author_info&&" — ",p.author_info]}),g&&e.jsxs("div",{style:{padding:"8px 12px 12px",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ge,{label:s.label.sourceName,value:p.source,onChange:x=>c(f,"source",x)}),e.jsx(ge,{label:s.label.sourceBid,value:p.source_bid||"",onChange:x=>c(f,"source_bid",x)})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(ge,{label:s.label.titleInfo,value:p.title_info||"",onChange:x=>c(f,"title_info",x)}),e.jsx(ge,{label:s.label.authorInfo,value:p.author_info||"",onChange:x=>c(f,"author_info",x)})]}),e.jsx(ge,{label:s.label.edition,value:p.edition||"",onChange:x=>c(f,"edition",x)})]}),e.jsx(He,{value:p.summary||"",onChange:x=>c(f,"summary",x),placeholder:s.editor.summaryPlaceholder}),e.jsx(He,{value:p.comment||"",onChange:x=>c(f,"comment",x),placeholder:s.editor.commentPlaceholder}),e.jsx(He,{value:p.additional_comment||"",onChange:x=>c(f,"additional_comment",x),placeholder:s.editor.additionalCommentPlaceholder})]})]},f)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:o})]})}function Sl({items:t,onChange:n}){const i=O();return e.jsx(oo,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function kl({items:t,onChange:n}){const i=O();return e.jsx(oo,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function ro(t){var c,a,d,p,f,g,x;const n=((a=(c=t.authors)==null?void 0:c[0])==null?void 0:a.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",o=((p=t.current_location)==null?void 0:p.name)||"",s=(f=t.page_count)!=null&&f.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",r=typeof t.description=="object"&&t.description!==null&&t.description.text||"",l={id:t.id,title:t.title,type:t.type,author:n,dynasty:i,holder:o,pages:s,description:r,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const h=t;if(Array.isArray(h.related_works)){const v=h.related_works.find(m=>m.relation==="part_of");v&&(l.parentWorkId=v.id,l.parentWorkName=v.title)}}if(t.type==="book"){const h=t;l.workId=h.work_id,Array.isArray(h.contained_in)&&h.contained_in.length>0&&(l.collectionId=(x=h.contained_in[0])==null?void 0:x.id)}return l}function wl(t){const n={id:t.id,title:t.title,type:t.type,description:t.description?{text:t.description}:void 0,authors:t.author?[{name:t.author}]:void 0,publication_info:t.dynasty?{year:t.dynasty}:void 0,current_location:t.holder?{name:t.holder}:void 0,page_count:t.pages?{number:parseInt(t.pages)||0,description:t.pages}:void 0,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};return t.type==="work"&&t.parentWorkId&&(n.related_works=[{id:t.parentWorkId,title:t.parentWorkName||"",relation:"part_of"}]),t.type==="book"&&(n.work_id=t.workId,t.collectionId&&(n.contained_in=[{id:t.collectionId}])),n}const _l=t=>{const{data:n,id:i,transport:o,mode:s="view",onModeChange:r,onChange:l,onSave:c,onDelete:a,onNavigate:d,renderLink:p,onAskAI:f,renderSectionActions:g,onDownloadResource:x,downloadStatuses:h,relations:v,onRelationsChange:m,headerExtra:j,className:y,style:k}=t;O();const[_,w]=u.useState(s),z=r?s:_;u.useEffect(()=>{s!==_&&w(s)},[s]);const S=u.useCallback(()=>{const A=z==="view"?"edit":"view";r?r(A):w(A)},[z,r]),[I,T]=u.useState(null);u.useEffect(()=>{i&&o&&o.getItem(i).then(A=>{A&&T(A)})},[i,o]);const C=n||I,b=u.useMemo(()=>C?ro(C):null,[C]),R=r||!n?e.jsx("button",{onClick:S,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:z==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:z==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:z==="view"?"切换到编辑模式":"切换到查看模式",children:z==="view"?"✏️ 编辑":"👁 查看"}):null,E=e.jsxs(e.Fragment,{children:[R,j]});return!C&&!b?e.jsx(Ve,{}):z==="view"?e.jsx(cn,{data:C,transport:o,onNavigate:d?A=>d(A):void 0,renderLink:p,headerExtra:E,className:y,style:k}):b?e.jsxs("div",{className:y,style:k,children:[E&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:E}),e.jsx(io,{data:b,onChange:l||(()=>{}),onSave:c||(()=>{}),transport:o,onNavigate:d,showDelete:!!a,onDelete:a,onAskAI:f,renderSectionActions:g,onDownloadResource:x,downloadStatuses:h,relations:v,onRelationsChange:m})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},oi=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],so=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:o})=>{const[s,r]=u.useState(null),[l,c]=u.useState(""),[a,d]=u.useState("idle"),[p,f]=u.useState(""),g=u.useRef(null);u.useEffect(()=>{t&&(r(null),c(""),d("idle"),f(""))},[t]),u.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=g.current)==null?void 0:m.focus()},100)},[s]),u.useEffect(()=>{if(a==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[a,n]),u.useEffect(()=>{if(!t)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const x=async()=>{if(!(!s||!l.trim())){d("submitting"),f("");try{await i({type:s,content:l.trim()}),d("success")}catch(m){d("error"),f(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&l.trim()&&a!=="submitting",v=oi.find(m=>m.value===s);return e.jsx("div",{style:Cl,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:Il,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:zl,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:Tl,"aria-label":"关闭",children:"✕"})]}),a==="success"?e.jsxs("div",{style:Wl,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),o&&e.jsx("a",{href:o,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:oi.map(m=>e.jsxs("button",{onClick:()=>r(m.value),style:{...Rl,...s===m.value?El:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:g,value:l,onChange:m=>c(m.target.value),placeholder:(v==null?void 0:v.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||a==="submitting",style:{...Bl,opacity:s?1:.6}}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[l.length," / 2000"]}),a==="error"&&e.jsx("div",{style:$l,children:p}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:x,disabled:!h,style:{...Ll,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:a==="submitting"?"提交中...":"提交反馈"})})]})]})})},Cl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Il={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"20px",width:"450px",maxWidth:"90vw",boxShadow:"0 4px 20px rgba(0,0,0,0.3)"},zl={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},Tl={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},Rl={flex:1,padding:"10px 12px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},El={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Bl={width:"100%",minHeight:"120px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Ll={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Wl={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},$l={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},Al=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[o,s]=u.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...Ml,bottom:n.bottom,right:n.right},"aria-label":"反馈",title:"反馈",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),e.jsx(so,{isOpen:o,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},Ml={position:"fixed",zIndex:900,width:"48px",height:"48px",borderRadius:"50%",border:"none",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 2px 8px rgba(0,0,0,0.25)",transition:"transform 0.2s, box-shadow 0.2s"},ri=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],lo=({onSubmit:t})=>{const[n,i]=u.useState("bug"),[o,s]=u.useState(""),[r,l]=u.useState("idle"),[c,a]=u.useState(""),d=u.useRef(null);u.useEffect(()=>{n&&setTimeout(()=>{var x;return(x=d.current)==null?void 0:x.focus()},100)},[n]);const p=async()=>{if(!(!n||!o.trim())){l("submitting"),a("");try{await t({type:n,content:o.trim()}),l("success"),s(""),i("bug")}catch(x){l("error"),a(x instanceof Error?x.message:"提交失败,请稍后重试")}}},f=n&&o.trim()&&r!=="submitting",g=ri.find(x=>x.value===n);return r==="success"?e.jsx("div",{style:si,children:e.jsxs("div",{style:Ol,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Nl,children:"继续提交"})]})}):e.jsxs("div",{style:si,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:ri.map(x=>e.jsxs("button",{onClick:()=>i(x.value),style:{...Fl,...n===x.value?Pl:{}},children:[e.jsx("span",{children:x.icon})," ",x.label]},x.value))}),e.jsx("textarea",{ref:d,value:o,onChange:x=>s(x.target.value),placeholder:(g==null?void 0:g.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:r==="submitting",style:{...Hl}}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[o.length," / 2000"]}),e.jsx("button",{onClick:p,disabled:!f,style:{...Dl,opacity:f?1:.6,cursor:f?"pointer":"not-allowed"},children:r==="submitting"?"提交中...":"提交"})]}),r==="error"&&e.jsx("div",{style:Vl,children:c})]})},si={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Fl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",display:"flex",alignItems:"center",gap:"6px",transition:"border-color 0.2s, background 0.2s"},Pl={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Hl={width:"100%",minHeight:"100px",padding:"10px 12px",fontSize:"14px",lineHeight:"1.6",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-bg, #fff)",color:"var(--bim-input-fg, #333)",outline:"none",boxSizing:"border-box",resize:"vertical",fontFamily:"inherit"},Dl={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ol={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Nl={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Vl={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"};function li(t){return typeof t=="function"?t():t??"/api/feedback"}const ao=({resourceId:t,apiUrl:n})=>{const[i,o]=u.useState([]),[s,r]=u.useState(!0),l=u.useCallback(async()=>{const a=li(n);r(!0);try{const p=await(await fetch(`${a}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&o(p.items)}catch{}finally{r(!1)}},[t,n]);u.useEffect(()=>{l()},[l]);const c=async a=>{const d=li(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...a,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!p.ok){const f=await p.json().catch(()=>null);throw new Error((f==null?void 0:f.error)||"提交失败")}setTimeout(()=>l(),500)};return e.jsxs("div",{children:[e.jsx(gn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(lo,{onSubmit:c})})]})},Gl=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ul={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function at(t){return Ul[t]??t}const ai=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],co={建安:196,黃初:220,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,元祿:1688,享保:1716,延享:1744,寬政:1789,文政:1818,天保:1830,明治:1868,大正:1912,昭和:1926},Yl={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function po(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,i=0,o=!1;for(const r of t){const l=Yl[r];if(l===void 0)return;o=!0,r==="十"?i=(i||1)*10:r==="廿"||r==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return o&&s>0?s:void 0}function It(t){for(const n of Gl)if(t.startsWith(n))return n}const zt={};{const t=(n,i)=>{for(const o of i)zt[o]=n};t("東漢",["建安"]),t("三國",["黃初"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","元祿","享保","延享","寬政","文政","天保","明治","大正","昭和"])}function ct(t,n){for(const i of Object.keys(co))if(t.includes(i)){if(n&&zt[i]&&zt[i]!==n){const o=n==="北宋"||n==="南宋"?"宋":n;if(zt[i]!==o)continue}return i}}function mn(t){var r,l,c;const n={era:"",reign:"",source:"none"},i=(r=t.lineage)==null?void 0:r.year_text;if(i){const a=It(i)??"";return{era:at(a),reign:ct(i,a)??"",source:"lineage"}}const o=(l=t.publication_info)==null?void 0:l.year;if(o){const a=It(o)??((c=ai.find(f=>f.pattern.test(o)))==null?void 0:c.era)??"",d=ct(o,a)??"";if(a||d)return{era:at(a),reign:d,source:"publication"};const p=o.match(/\d{3,4}/);if(p)return{era:"",reign:p[0],source:"publication"}}const s=t.edition||t.title||"";if(s){const a=It(s);if(a)return{era:at(a),reign:ct(s,a)??"",source:"edition"};const d=ai.find(p=>p.pattern.test(s));if(d)return{era:at(d.era),reign:ct(s,d.era)??d.reign??"",source:"edition"}}return n}function uo(t){var i,o,s;if(typeof((i=t.lineage)==null?void 0:i.year)=="number")return t.lineage.year;const n=[(o=t.lineage)==null?void 0:o.year_text,(s=t.publication_info)==null?void 0:s.year,t.edition,t.title].filter(Boolean);for(const r of n){const l=r.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??r.match(/[((](\d{3,4})\s*年?[))]/);if(l){const d=parseInt(l[1],10);if(d>=100&&d<=2100)return d}const c=It(r),a=ct(r,c);if(a){const d=co[a],f=r.slice(r.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=f?po(f[1]):void 0;return d+(g?g-1:0)}}}const ci=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function dt(t){const n=ci.indexOf(t);return n===-1?ci.length:n}function xo(t){const n={belongsTo:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const r=s.relation;r==="part_of"||r==="collected_in"?n.belongsTo.push(s):r==="has_part"||r==="contains_text_of"?n.contains.push(s):r==="text_carried_by"||r==="studied_by"||r==="derived_from"||r==="followed_by"||r==="has_adaptation"?n.derivative.push(s):r==="studies"||r==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],o=(s,r)=>{n[s].length&&i.push({key:s,labelKey:r,items:n[s]})};return o("belongsTo","belongsToWork"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),i}function At(t,n){const i=on(t||[]),o=new Map,s=[];for(const d of i)d.group?(o.has(d.group)||o.set(d.group,[]),o.get(d.group).push(d)):s.push(d);for(const d of o.values())d.sort((p,f)=>{const g=x=>x.group_role==="origin"?0:x.group_role==="mirror"?1:2;return g(p)-g(f)});const r={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=De(d),f=p.includes("text"),g=p.includes("image");f&&g?r.textImage.push(d):f?r.text.push(d):g?r.image.push(d):r.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>r[d].length>0).map(d=>({key:d,items:r[d]})),a=[...o.entries()].map(([d,p])=>{var f,g;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(g=n==null?void 0:n[d])==null?void 0:g.description,items:p}});return{buckets:c,mirrors:a,total:i.length}}function hn(t){const n=[],i=t.metadata||{};i.edition&&n.push(String(i.edition)),t.source_label&&n.push(t.source_label),t.details&&n.push(t.details);const o=rn(t);return o&&o.expected>0&&n.push(o.missing>0?`${o.found} / ${o.expected} 冊 缺 ${o.missing}`:`${o.found} / ${o.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Kl(t,n){if(hn(t)||n.filter(o=>o.name===t.name).length<2)return"";try{const o=new URL(t.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const r=o.pathname.split("/").filter(Boolean).pop();if(r)return decodeURIComponent(r)}catch{}return""}function fo(t,n){var r,l;const i=t.resources||[],o=[],s=[];for(const c of i){const a=De(c);a.includes("image")&&o.push(c),a.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:mn(t),year:uo(t),images:o,holders:s,locationName:(r=t.current_location)==null?void 0:r.name,important:Jl(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:o.length>0}}function Jl(t,n){var c,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const o=(c=n.collections)==null?void 0:c[i];if(((o==null?void 0:o.book_ids)??(i==="core"?n.core_books??[]:[])).includes(t))return!0;const r=(o==null?void 0:o.groups)??[],l=(a=n.node_groups)==null?void 0:a[t];return!!l&&r.includes(l)}function go(t,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!o.has(a.id)).map(a=>fo(a,n));let r=s;i.era&&(r=r.filter(a=>a.era.era===i.era)),i.scanOnly&&(r=r.filter(a=>a.hasImage)),i.sort==="year"?r=[...r].sort((a,d)=>a.year!=null&&d.year!=null?a.year-d.year:a.year!=null?-1:d.year!=null?1:dt(a.era.era)-dt(d.era.era)):r=r.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=f=>(f.important?0:1)*2+(f.hasImage?0:1);return p(a.r)-p(d.r)||a.i-d.i}).map(a=>a.r);const c=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>dt(a)-dt(d));return{rows:r,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function ql(t,n){var m,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],r=o.length>0||s.length>0,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=y=>{if(a.has(y))return!0;const k=n.node_groups[y];return k!=null&&c.has(k)},p=[],f=new Map,g=[];for(const y of t)if(!((j=n.excluded_books)!=null&&j.includes(y)))if(d(y))p.push(y);else{const k=n.node_groups[y];k?(f.has(k)||f.set(k,[]),f.get(k).push(y)):g.push(y)}if(g.length+[...f.values()].reduce((y,k)=>y+k.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(y=>[y.id,y])),v=[...f.entries()].map(([y,k])=>{const _=h.get(y);return{id:y,label:(_==null?void 0:_.label)??y,description:_==null?void 0:_.description,ids:k}});return g.length>0&&v.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:v}}const mo=["撰","編","注","校","譯","繪","其他"],Xl=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function bn(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:o}of Xl)if(o.test(n))return i;return"其他"}function ho(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function bo(t){const n=new Map;for(const o of t){const s=bn(o);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const o of mo){const s=n.get(o);s&&i.push({cls:o,label:o,count:s})}return i.length>2?i:[]}function yo(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),r=[...new Set(s.map(l=>l.section).filter(Boolean))];return{rows:s,source:"catalog",sections:r,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(r=>({id:r.id,title:r.title,volumes:ft(r.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var r,l;return{id:s,title:((r=i==null?void 0:i.get(s))==null?void 0:r.title)||s,edition:(l=i==null?void 0:i.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function ft(t){if(t==null)return[];if(typeof t=="number")return[t];if(Array.isArray(t))return t.filter(n=>typeof n=="number");if(typeof t=="string"){const n=t.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-i+1)},(s,r)=>i+r)}return t.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function yn(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((r,l)=>r-l),o=i[0],s=i[i.length-1];return s-o+1===i.length?`${o}–${s}`:i.length<=3?i.join(", "):`${o}–${s} (${i.length}${n})`}const Zl=["〇","一","二","三","四","五","六","七","八","九"],di=["","十","百","千"];function vo(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",s=!1;for(let r=0;r<i;r++){const l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=di[c]:o+=Zl[l]+di[c])}return o}function Oe(t,n="卷"){var o,s;const i=t;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?vo(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function jo(t){var o;if((o=t.lineage)!=null&&o.category)return t.lineage.category;const n=t.edition||t.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,r]of i)if(s.test(n))return r;return""}const So=1e3,Ql="(max-width: 719px)",ko=`
|
|
4
4
|
.bim-d-page {
|
|
5
5
|
background: var(--bim-page-bg, #fbf9f3);
|
|
6
6
|
color: var(--bim-ink, #2a231c);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
padding-bottom: 64px;
|
|
10
10
|
}
|
|
11
11
|
.bim-d-main {
|
|
12
|
-
max-width: ${
|
|
12
|
+
max-width: ${So}px;
|
|
13
13
|
margin: 0 auto;
|
|
14
14
|
padding: 24px clamp(16px, 4vw, 28px) 0;
|
|
15
15
|
}
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
align-items: start; margin-bottom: 48px; }
|
|
38
38
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
39
39
|
|
|
40
|
-
@media ${
|
|
40
|
+
@media ${Ql} {
|
|
41
41
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
42
42
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
43
43
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
gap: 4px 14px; font-size: 12px; }
|
|
49
49
|
.bim-d-h1 { font-size: 32px !important; }
|
|
50
50
|
}
|
|
51
|
-
`;function kt({children:t,style:n}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:ro}),e.jsx("div",{className:"bim-d-main",children:t})]})}function so({breadcrumb:t,actions:n}){return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:"var(--bim-label-fg, #8b7a62)"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:t}),n&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function pn({char:t,tone:n="accent"}){return e.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:n==="accent"?"var(--bim-accent, #9c3a2c)":"var(--bim-ink, #2a231c)",color:"var(--bim-page-bg, #fbf9f3)"},children:t})}function lo({items:t}){return e.jsx(e.Fragment,{children:t.map((n,i)=>{const o=i===t.length-1,s=i>0&&e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${i}`),r=o||!n.onClick&&!n.href?e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:n.label},i):e.jsx("a",{href:n.href??"#",onClick:n.onClick?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),n.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:n.label},i);return e.jsxs(x.Fragment,{children:[s,r]},i)})})}function ao({title:t,subtitle:n,aside:i,secondLine:o}){return e.jsxs("header",{style:{borderBottom:"2px solid var(--bim-rule-strong, #2a231c)",paddingBottom:18},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[e.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:t}),n&&e.jsx("span",{style:{fontSize:15,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".06em"},children:n})]}),i&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".06em"},children:i})]}),o&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:"var(--bim-quiet-fg, #5b4f40)"},children:o})]})}function Bt({children:t,facts:n}){return!t&&n?e.jsx("div",{style:{padding:"20px 0 26px",borderBottom:"1px solid var(--bim-rule, #e4dbc9)",marginBottom:40},children:n}):e.jsxs("div",{className:"bim-d-intro",children:[e.jsx("div",{style:{minWidth:0},children:t}),n]})}function Lt({items:t,horizontal:n}){return t.length?e.jsx("div",{style:{borderLeft:"2px solid var(--bim-accent, #9c3a2c)",paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:t.map((i,o)=>e.jsxs("div",{title:i.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em",flex:"none"},children:i.label}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:i.value})]},o))}):null}function xe({glyph:t,tone:n,title:i,count:o,actions:s,id:r}){return e.jsxs("div",{id:r,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(pn,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:i}),o!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:o})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Ae({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function Fe({label:t,active:n,onClick:i,dashed:o}){return e.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!n?"dashed":"solid"} ${n?"var(--bim-accent, #9c3a2c)":"var(--bim-rule, #e0d6c0)"}`,background:n?"var(--bim-accent, #9c3a2c)":"transparent",color:n?"var(--bim-page-bg, #fbf9f3)":"var(--bim-meta-fg, #7b6a54)",fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:t})}function un({label:t,onClick:n}){return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:t})}function He({label:t,onClick:n,inline:i}){return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",cursor:"pointer",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:i?void 0:".08em"},children:t})}function Qe({children:t,href:n,onClick:i,title:o}){const s={display:"inline-block",padding:"4px 10px",border:"1px solid var(--bim-rule, #e0d6c0)",fontSize:13,color:"var(--bim-body-fg, #3b3228)",lineHeight:1.5};return n||i?e.jsx("a",{href:n??"#",title:o,onClick:i?r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i())}:void 0,style:s,children:t}):e.jsx("span",{title:o,style:s,children:t})}function Wt({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function co({volumes:t,unit:n="冊",max:i=60}){const[o,s]=x.useState(!1);if(!t.length)return null;const r=o?t:t.slice(0,i);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[r.map(l=>e.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:"1px solid var(--bim-rule, #e0d6c0)",color:"var(--bim-meta-fg, #7b6a54)"},children:l},l)),!o&&t.length>i&&e.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:["+",t.length-i]}),e.jsx("span",{style:{padding:"2px 6px",color:"var(--bim-hint-fg, #b3a385)"},children:n})]})}function $t({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function xn({leadWidth:t,metaWidth:n,metaColumns:i,mainLabel:o}){return e.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${t}px 1fr ${n}px`,gap:12,padding:"7px 4px",borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",fontSize:11,color:"var(--bim-label-fg, #8b7a62)",letterSpacing:".1em"},children:[e.jsx("span",{}),e.jsx("span",{children:o}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:i.map(s=>s.width).join(" "),gap:12},children:i.map(s=>e.jsx("span",{children:s.label},s.label))})]})}function fn({no:t,main:n,meta:i,leadWidth:o,metaWidth:s,metaColumns:r}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o}px 1fr ${s}px`,gap:12},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-hint-fg, #c2b294)",textAlign:"right"},children:t}),e.jsx("span",{style:{minWidth:0},children:n}),e.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:r.join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function gt(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function po({open:t,onToggle:n,main:i,action:o,children:s}){return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[e.jsx("button",{type:"button",onClick:n,"aria-expanded":t,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${t?"var(--bim-accent, #9c3a2c)":"var(--bim-rule-dashed, #d6c9ae)"}`,background:t?"var(--bim-accent, #9c3a2c)":"transparent",color:t?"var(--bim-page-bg, #fbf9f3)":"var(--bim-accent, #9c3a2c)"},children:t?"-":"+"}),e.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),o]}),t&&s&&e.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:"2px solid var(--bim-rule-accent-soft, #e0d3b6)",marginLeft:12},children:s})]})}function wt({label:t,children:n}){return e.jsxs("div",{style:{marginBottom:10},children:[t&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:"var(--bim-label-fg, #a3937b)",marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"},children:n})]})}function Jt({title:t,tag:n,children:i}){return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",marginBottom:2},children:[e.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:t}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:n})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function At({name:t,note:n,href:i,extra:o}){const s=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,minWidth:0},children:t}),e.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)",flex:"none"},children:i?"↗":""}),n&&e.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:n})]}),r={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:"1px solid var(--bim-rule, #eae2d0)",color:"var(--bim-body-fg, #3b3228)",alignItems:"baseline"};return e.jsxs(e.Fragment,{children:[i?e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:r,children:s}):e.jsx("div",{style:r,children:s}),o]})}function uo({left:t,right:n}){return e.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:"1px solid var(--bim-rule, #e4dbc9)",display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[e.jsx("span",{children:t}),n&&e.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function gn({children:t,action:n}){return e.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:"var(--bim-label-fg, #a3937b)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[e.jsx("span",{children:t}),n]})}function Ce({id:t,label:n,onNavigate:i,renderLink:o,style:s,dense:r}){const l=me();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:r})}):e.jsx("a",{href:l(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function qt({href:t,children:n}){return e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:[n," ",e.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const Ll=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Wl={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function lt(t){return Wl[t]??t}const oi=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],xo={建安:196,黃初:220,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,會昌:841,咸通:860,建隆:960,太平興國:976,咸平:998,天禧:1017,慶曆:1041,皇祐:1049,嘉祐:1056,治平:1064,熙寧:1068,元豐:1078,元祐:1086,紹聖:1094,崇寧:1102,大觀:1107,政和:1111,宣和:1119,建炎:1127,紹興:1131,隆興:1163,乾道:1165,淳熙:1174,紹熙:1190,慶元:1195,嘉泰:1201,開禧:1205,嘉定:1208,寶慶:1225,紹定:1228,端平:1234,嘉熙:1237,淳祐:1241,寶祐:1253,開慶:1259,景定:1260,咸淳:1265,大定:1161,明昌:1190,至元:1264,大德:1297,皇慶:1312,延祐:1314,泰定:1324,天曆:1328,至順:1330,至正:1341,洪武:1368,永樂:1403,宣德:1426,正統:1436,景泰:1450,天順:1457,成化:1465,弘治:1488,正德:1506,嘉靖:1522,隆慶:1567,萬曆:1573,泰昌:1620,天啟:1621,崇禎:1628,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,元祿:1688,享保:1716,延享:1744,寬政:1789,文政:1818,天保:1830,明治:1868,大正:1912,昭和:1926},$l={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function fo(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,i=0,o=!1;for(const r of t){const l=$l[r];if(l===void 0)return;o=!0,r==="十"?i=(i||1)*10:r==="廿"||r==="卅"?(n+=l,i=0):i>=10?(n+=i+l,i=0):i=i*10+l}const s=n+i;return o&&s>0?s:void 0}function _t(t){for(const n of Ll)if(t.startsWith(n))return n}const Ct={};{const t=(n,i)=>{for(const o of i)Ct[o]=n};t("東漢",["建安"]),t("三國",["黃初"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","元祿","享保","延享","寬政","文政","天保","明治","大正","昭和"])}function at(t,n){for(const i of Object.keys(xo))if(t.includes(i)){if(n&&Ct[i]&&Ct[i]!==n){const o=n==="北宋"||n==="南宋"?"宋":n;if(Ct[i]!==o)continue}return i}}function mn(t){var r,l,c;const n={era:"",reign:"",source:"none"},i=(r=t.lineage)==null?void 0:r.year_text;if(i){const a=_t(i)??"";return{era:lt(a),reign:at(i,a)??"",source:"lineage"}}const o=(l=t.publication_info)==null?void 0:l.year;if(o){const a=_t(o)??((c=oi.find(f=>f.pattern.test(o)))==null?void 0:c.era)??"",d=at(o,a)??"";if(a||d)return{era:lt(a),reign:d,source:"publication"};const p=o.match(/\d{3,4}/);if(p)return{era:"",reign:p[0],source:"publication"}}const s=t.edition||t.title||"";if(s){const a=_t(s);if(a)return{era:lt(a),reign:at(s,a)??"",source:"edition"};const d=oi.find(p=>p.pattern.test(s));if(d)return{era:lt(d.era),reign:at(s,d.era)??d.reign??"",source:"edition"}}return n}function go(t){var i,o,s;if(typeof((i=t.lineage)==null?void 0:i.year)=="number")return t.lineage.year;const n=[(o=t.lineage)==null?void 0:o.year_text,(s=t.publication_info)==null?void 0:s.year,t.edition,t.title].filter(Boolean);for(const r of n){const l=r.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??r.match(/[((](\d{3,4})\s*年?[))]/);if(l){const d=parseInt(l[1],10);if(d>=100&&d<=2100)return d}const c=_t(r),a=at(r,c);if(a){const d=xo[a],f=r.slice(r.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),g=f?fo(f[1]):void 0;return d+(g?g-1:0)}}}const ri=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function ct(t){const n=ri.indexOf(t);return n===-1?ri.length:n}function mo(t){const n={belongsTo:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const r=s.relation;r==="part_of"||r==="collected_in"?n.belongsTo.push(s):r==="has_part"||r==="contains_text_of"?n.contains.push(s):r==="text_carried_by"||r==="studied_by"||r==="derived_from"||r==="followed_by"||r==="has_adaptation"?n.derivative.push(s):r==="studies"||r==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],o=(s,r)=>{n[s].length&&i.push({key:s,labelKey:r,items:n[s]})};return o("belongsTo","belongsToWork"),o("contains","containedWorks"),o("derivative","derivativeWorks"),o("studies","studies"),o("related","relatedWorks"),i}function Ft(t,n){const i=Zt(t||[]),o=new Map,s=[];for(const d of i)d.group?(o.has(d.group)||o.set(d.group,[]),o.get(d.group).push(d)):s.push(d);for(const d of o.values())d.sort((p,f)=>{const g=u=>u.group_role==="origin"?0:u.group_role==="mirror"?1:2;return g(p)-g(f)});const r={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=Me(d),f=p.includes("text"),g=p.includes("image");f&&g?r.textImage.push(d):f?r.text.push(d):g?r.image.push(d):r.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>r[d].length>0).map(d=>({key:d,items:r[d]})),a=[...o.entries()].map(([d,p])=>{var f,g;return{key:d,label:((f=n==null?void 0:n[d])==null?void 0:f.label)||d,description:(g=n==null?void 0:n[d])==null?void 0:g.description,items:p}});return{buckets:c,mirrors:a,total:i.length}}function bt(t){const n=[],i=t.metadata||{};i.edition&&n.push(String(i.edition)),t.source_label&&n.push(t.source_label),t.details&&n.push(t.details);const o=Rt(t);return o&&o.expected>0&&n.push(o.missing>0?`${o.found} / ${o.expected} 冊 缺 ${o.missing}`:`${o.found} / ${o.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Al(t,n){if(bt(t)||n.filter(o=>o.name===t.name).length<2)return"";try{const o=new URL(t.url),s=o.searchParams.get("res")||o.searchParams.get("id");if(s)return s;const r=o.pathname.split("/").filter(Boolean).pop();if(r)return decodeURIComponent(r)}catch{}return""}function ho(t,n){var r,l;const i=t.resources||[],o=[],s=[];for(const c of i){const a=Me(c);a.includes("image")&&o.push(c),a.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:mn(t),year:go(t),images:o,holders:s,locationName:(r=t.current_location)==null?void 0:r.name,important:Fl(t.id,n),group:(l=n==null?void 0:n.node_groups)==null?void 0:l[t.id],hasImage:o.length>0}}function Fl(t,n){var c,a;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const o=(c=n.collections)==null?void 0:c[i];if(((o==null?void 0:o.book_ids)??(i==="core"?n.core_books??[]:[])).includes(t))return!0;const r=(o==null?void 0:o.groups)??[],l=(a=n.node_groups)==null?void 0:a[t];return!!l&&r.includes(l)}function bo(t,n,i={}){const o=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(a=>!o.has(a.id)).map(a=>ho(a,n));let r=s;i.era&&(r=r.filter(a=>a.era.era===i.era)),i.scanOnly&&(r=r.filter(a=>a.hasImage)),i.sort==="year"?r=[...r].sort((a,d)=>a.year!=null&&d.year!=null?a.year-d.year:a.year!=null?-1:d.year!=null?1:ct(a.era.era)-ct(d.era.era)):r=r.map((a,d)=>({r:a,i:d})).sort((a,d)=>{const p=f=>(f.important?0:1)*2+(f.hasImage?0:1);return p(a.r)-p(d.r)||a.i-d.i}).map(a=>a.r);const c=[...new Set(s.map(a=>a.era.era).filter(Boolean))].sort((a,d)=>ct(a)-ct(d));return{rows:r,allRows:s,eras:c,hasInferredEra:s.some(a=>a.era.source==="edition")}}function Ml(t,n){var m,j;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(m=n.collections)==null?void 0:m[n.default_collection],o=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],r=o.length>0||s.length>0,l=!r&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!r&&l.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(o),a=new Set([...s,...l]),d=b=>{if(a.has(b))return!0;const S=n.node_groups[b];return S!=null&&c.has(S)},p=[],f=new Map,g=[];for(const b of t)if(!((j=n.excluded_books)!=null&&j.includes(b)))if(d(b))p.push(b);else{const S=n.node_groups[b];S?(f.has(S)||f.set(S,[]),f.get(S).push(b)):g.push(b)}if(g.length+[...f.values()].reduce((b,S)=>b+S.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const h=new Map((n.groups??[]).map(b=>[b.id,b])),y=[...f.entries()].map(([b,S])=>{const _=h.get(b);return{id:b,label:(_==null?void 0:_.label)??b,description:_==null?void 0:_.description,ids:S}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}function yo(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(l=>({id:l.work_id||l.book_id||void 0,title:l.title,section:l.section,volumes:l.volumes||[],subItems:l.sub_items,edition:l.edition,found:l.found_volumes,expected:l.expected_volumes})),r=[...new Set(s.map(l=>l.section).filter(Boolean))];return{rows:s,source:"catalog",sections:r,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(r=>({id:r.id,title:r.title,volumes:xt(r.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var r,l;return{id:s,title:((r=i==null?void 0:i.get(s))==null?void 0:r.title)||s,edition:(l=i==null?void 0:i.get(s))==null?void 0:l.edition,volumes:[]}}),source:"books",sections:[]}}function xt(t){if(t==null)return[];if(typeof t=="number")return[t];if(Array.isArray(t))return t.filter(n=>typeof n=="number");if(typeof t=="string"){const n=t.match(/^(\d+)\s*[-–~]\s*(\d+)$/);if(n){const[i,o]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,o-i+1)},(s,r)=>i+r)}return t.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function hn(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((r,l)=>r-l),o=i[0],s=i[i.length-1];return s-o+1===i.length?`${o}–${s}`:i.length<=3?i.join(", "):`${o}–${s} (${i.length}${n})`}const Pl=["〇","一","二","三","四","五","六","七","八","九"],si=["","十","百","千"];function vo(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let o="",s=!1;for(let r=0;r<i;r++){const l=parseInt(n[r]),c=i-1-r;l===0?s=!0:(s&&o&&(o+="〇"),s=!1,l===1&&c===1&&r===0?o+=si[c]:o+=Pl[l]+si[c])}return o}function De(t,n="卷"){var o,s;const i=t;return i.measure_info?i.measure_info:(o=i.juan_count)!=null&&o.number?vo(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function jo(t){var o;if((o=t.lineage)!=null&&o.category)return t.lineage.category;const n=t.edition||t.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,r]of i)if(s.test(n))return r;return""}const Je={versions:12,catalogs:8,chips:12},So=({data:t,transport:n,onNavigate:i,renderLink:o,lineageAction:s})=>{var w,C,W,R,M,F,P,$,A;const r=N(),{convert:l}=V(),c=x.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[a,d]=x.useState(new Map),[p,f]=x.useState(!1),[g,u]=x.useState(""),[h,y]=x.useState(!1),[m,j]=x.useState("default"),b=p||!!g||h||m==="year",S=x.useMemo(()=>b?c:c.slice(0,Je.versions),[c,b]);x.useEffect(()=>{if(!n||S.length===0)return;const L=S.filter(D=>!a.has(D));if(L.length===0)return;let E=!1;return Promise.all(L.map(D=>n.getItem(D).then(te=>{const G=te??{};return[D,{id:D,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[D,{id:D}]))).then(D=>{E||d(te=>{const G=new Map(te);for(const[Z,re]of D)G.set(Z,re);return G})}),()=>{E=!0}},[n,S,a]);const _=x.useMemo(()=>c.map(L=>a.get(L)??{id:L}),[c,a]),k=x.useMemo(()=>bo(_,t.version_graph,{era:g,scanOnly:h,sort:m}),[_,t.version_graph,g,h,m]),I=p?k.rows:k.rows.slice(0,Je.versions),v=x.useMemo(()=>Ft(t.resources,t.resource_groups),[t.resources,t.resource_groups]),z=x.useMemo(()=>mo((t.related_works||[]).map(L=>({id:L.id,title:L.title,relation:L.relation}))),[t.related_works]),T=x.useMemo(()=>{var te,G,Z,re;const L=[],E=(G=(te=t.authors)==null?void 0:te[0])==null?void 0:G.dynasty;E&&L.push({label:"成書",value:l(E)});const D=De(t,r.unit.juan);if(D){const ne=(Z=t.juan_count)==null?void 0:Z.description;L.push({label:"卷帙",value:l(D),title:ne?l(ne):void 0})}if(b||c.length<=Je.versions){const ne=k.allRows.map(U=>U.year).filter(U=>U!=null);if(ne.length>0){const U=Math.min(...ne),Y=k.allRows.find(ce=>ce.year===U);Y!=null&&Y.era.era&&L.push({label:"最早存世刻本",value:`${Y.era.era}${Y.era.reign?" "+Y.era.reign:""}`,title:Y.era.source==="edition"?"據版本題名推斷":void 0})}}return(re=t.indexed_by)!=null&&re.length&&L.push({label:"著錄",value:`${t.indexed_by.length} ${r.unit.bu}`}),L},[t,l,r,k.allRows,b,c.length]);return e.jsxs(e.Fragment,{children:[e.jsxs(Bt,{facts:T.length?e.jsx(Lt,{items:T}):void 0,children:[((w=t.description)==null?void 0:w.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Be,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(C=t.description.sources)!=null&&C.length?e.jsx("div",{className:"bim-d-ui",style:{marginTop:8,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:t.description.sources.map(L=>l(L)).join(" · ")}):null]}),(W=t.appendix)==null?void 0:W.map((L,E)=>e.jsxs("details",{style:{marginTop:12},children:[e.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)",display:"inline-block"},children:l(L.title)}),e.jsx(Be,{text:L.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},E)),e.jsx(Gl,{data:t,convert:l,t:r})]}),c.length>0&&e.jsxs(Ae,{children:[e.jsx(xe,{glyph:"版",title:r.section.relatedVersions,count:k.rows.length===k.allRows.length?`${k.allRows.length} 種`:`${k.allRows.length} 種 · 當前 ${k.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(Fe,{label:"僅看有影印",active:h,dashed:!0,onClick:()=>{y(L=>!L),f(!1)}}),e.jsx(un,{label:m==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>j(L=>L==="default"?"year":"default")})]})}),k.allRows.length>=6&&k.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(Fe,{label:r.catalog.all,active:!g,onClick:()=>{u(""),f(!1)}}),k.eras.map(L=>e.jsx(Fe,{label:L,active:g===L,onClick:()=>{u(L),f(!1)}},L))]}),e.jsxs($t,{children:[e.jsx(xn,{leadWidth:22,metaWidth:424,mainLabel:"版本名稱",metaColumns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]}),I.map((L,E)=>e.jsx(Nl,{row:L,no:E+1,onNavigate:i,renderLink:o},L.id)),I.length===0&&e.jsx(gn,{children:g||h?"當前篩選下沒有版本":"暫無版本著錄"})]}),k.rows.length>I.length&&e.jsx(He,{label:`展開其餘 ${k.rows.length-I.length} 種版本`,onClick:()=>f(!0)}),k.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(v.buckets.length>0||v.mirrors.length>0)&&e.jsxs(Ae,{children:[e.jsx(xe,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[v.mirrors.map(L=>e.jsx(Jt,{title:l(L.label),tag:L.description?l(L.description):void 0,children:L.items.map((E,D)=>e.jsx(li,{item:E,siblings:L.items,convert:l},`${E.id||E.url||E.name}-${D}`))},L.key)),v.buckets.map(L=>e.jsx(Jt,{title:Hl[L.key],tag:Dl[L.key],children:L.items.map((E,D)=>e.jsx(li,{item:E,siblings:L.items,convert:l},`${E.id||E.url||E.name}-${D}`))},L.key))]})]}),(R=t.indexed_by)!=null&&R.length||(M=t.emendated_by)!=null&&M.length?e.jsxs("div",{className:(F=t.emendated_by)!=null&&F.length?"bim-d-pair":void 0,style:(P=t.emendated_by)!=null&&P.length?void 0:{marginBottom:48},children:[($=t.indexed_by)!=null&&$.length?e.jsx(ci,{id:"catalogs",glyph:"目",title:r.section.indexed,items:t.indexed_by,unit:r.unit.bu,cap:Je.catalogs,showMeta:!0,t:r,convert:l,onNavigate:i,renderLink:o}):null,(A=t.emendated_by)!=null&&A.length?e.jsx(ci,{id:"studies",glyph:"考",title:r.section.emendated,items:t.emendated_by,unit:r.unit.bu,cap:Je.catalogs,t:r,convert:l,onNavigate:i,renderLink:o}):null]}):null,z.map(L=>e.jsx(Vl,{glyph:L.key==="derivative"?"續":"叢",title:r.section[L.labelKey]??r.section.relatedWorks,items:L.items,convert:l,onNavigate:i,renderLink:o},L.key))]})},Hl={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},Dl={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function li({item:t,siblings:n,convert:i}){const[o,s]=x.useState(!1),r=Rt(t),l=!!r&&r.expected>0,c=(t.url?Pe(t.url):void 0)||i(t.name),a=Al(t,n),d=a?`${c}(${a})`:c;return e.jsx(At,{name:d,note:bt(t),href:qe(t),extra:l?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>s(p=>!p),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)",marginTop:4},children:o?"收起分冊":`展開 ${r.expected} 冊`}),o&&e.jsx(Ol,{item:t})]}):void 0})}function Ol({item:t}){const n=t.volumes||[];return e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:n.map((i,o)=>{const s=i.status==="missing",r=i.url;return r&&!s?e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{padding:"1px 5px",border:"1px solid var(--bim-rule, #e0d6c0)"},children:i.volume},o):e.jsx("span",{style:{padding:"1px 5px",color:s?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:s?"line-through":void 0},children:i.volume},o)})})}function Nl({row:t,no:n,onNavigate:i,renderLink:o}){const{convert:s}=V(),r=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(fn,{no:String(n).padStart(2,"0"),leadWidth:22,metaWidth:424,metaColumns:["118px","156px","138px"],main:e.jsx(Ce,{id:t.id,label:s(t.name),onNavigate:i,renderLink:o,dense:!0,style:{fontWeight:t.important?600:400}}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".04em"},title:l?"據版本題名推斷":void 0,children:r||e.jsx(gt,{})}),e.jsx(ai,{items:t.images,convert:s}),e.jsx(ai,{items:t.holders,convert:s,fallback:t.locationName})]})})}function ai({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(gt,{});if(t.length===1){const l=t[0],c=(l.url?Pe(l.url):void 0)||n(l.name),a=qe(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(qt,{href:a,children:c}):c})}const o=t[0],s=(o.url?Pe(o.url):void 0)||n(o.name),r=qe(o);return e.jsxs("span",{style:{minWidth:0},children:[r?e.jsx(qt,{href:r,children:s}):s,e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:4,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:["+",t.length-1]})]})}function ci({id:t,glyph:n,title:i,items:o,unit:s,cap:r,showMeta:l,t:c,convert:a,onNavigate:d,renderLink:p}){const[f,g]=x.useState({}),[u,h]=x.useState(!1),y=o.length>0&&o.every((b,S)=>f[S]),m=x.useCallback(()=>{g(y?{}:Object.fromEntries(o.map((b,S)=>[S,!0])))},[y,o]),j=u?o:o.slice(0,r);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(xe,{glyph:n,tone:"ink",title:i,count:`${o.length} ${s}`,actions:e.jsx(un,{label:y?"收起全部":"+ 展開提要",onClick:m})}),e.jsx($t,{children:j.map((b,S)=>{const _=b;return e.jsxs(po,{open:!!f[S],onToggle:()=>g(k=>({...k,[S]:!k[S]})),main:e.jsxs(e.Fragment,{children:[_.source_bid?e.jsx(Ce,{id:_.source_bid,label:a(_.source),onNavigate:d,renderLink:p,dense:!0}):a(_.source),l&&_.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(_.section)})]}),action:_.source_bid?e.jsx(Ce,{id:_.source_bid,label:c.action.view,onNavigate:d,renderLink:p,dense:!0,style:{fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"}}):void 0,children:[l&&(_.title_info||_.author_info||_.edition)&&e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:"4px 16px",marginBottom:8,fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:[_.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",a(_.title_info)]}),_.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",a(_.author_info)]}),_.edition&&e.jsxs("span",{children:[c.label.edition," ",a(_.edition)]})]}),_.summary&&e.jsx(wt,{children:a(_.summary)}),_.comment&&e.jsx(wt,{label:c.section.comment,children:a(_.comment)}),_.additional_comment&&e.jsx(wt,{label:c.section.additionalComment,children:a(_.additional_comment)}),l&&_.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:_.page})]},S)})}),o.length>j.length&&e.jsx(He,{label:`展開其餘 ${o.length-j.length} ${s}`,onClick:()=>h(!0)})]})}function Vl({glyph:t,title:n,items:i,convert:o,onNavigate:s,renderLink:r}){const[l,c]=x.useState(!1),a=l?i:i.slice(0,Je.chips);return e.jsxs(Ae,{style:{marginBottom:44},children:[e.jsx(xe,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Wt,{children:[a.map(d=>e.jsx(Qe,{children:e.jsx(Ce,{id:d.id,label:o(d.title),onNavigate:s,renderLink:r,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx(He,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}function Gl({data:t,convert:n,t:i}){const o=[],s=(t.additional_titles||[]).map(c=>typeof c=="string"?c:c.book_title).filter(Boolean);s.length&&o.push({label:i.section.aliases,items:s});const r=(t.attached_texts||[]).map(c=>typeof c=="string"?c:c.book_title).filter(Boolean);r.length&&o.push({label:i.section.attachedTexts,items:r});const l=(t.additional_works||[]).map(c=>c.book_title+(c.n_juan!=null?` ${c.n_juan}${i.unit.juan}`:""));return l.length&&o.push({label:i.section.appendix,items:l}),o.length?e.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:o.map(c=>e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em"},children:c.label}),c.items.map((a,d)=>e.jsx(Qe,{children:n(a)},d))]},c.label))}):null}const Ul=8,ko=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var S,_,k,I;const s=N(),{convert:r}=V(),[l,c]=x.useState(null),[a,d]=x.useState(new Map),[p,f]=x.useState([]),[g,u]=x.useState(!1);x.useEffect(()=>{if(!n||!t.work_id){c(null);return}let v=!1;return n.getItem(t.work_id).then(z=>{!v&&z&&z.type==="work"&&c(z)}).catch(()=>{}),()=>{v=!0}},[n,t.work_id]),x.useEffect(()=>{const v=t.contained_in||[];if(!n||v.length===0){d(new Map);return}let z=!1;return Promise.all(v.map(T=>{const w=typeof T=="string"?T:T.id;return n.getItem(w).then(C=>[w,C]).catch(()=>[w,null])})).then(T=>{if(z)return;const w=new Map;for(const[C,W]of T)W&&w.set(C,W);d(w)}),()=>{z=!0}},[n,t.contained_in]);const h=x.useMemo(()=>{const v=new Set([...(l==null?void 0:l.books)||[],...t.related_books||[]]);return v.delete(t.id),[...v]},[l==null?void 0:l.books,t.related_books,t.id]);x.useEffect(()=>{if(!n||h.length===0){f([]);return}const v=g?h:h.slice(0,Ul);let z=!1;return Promise.all(v.map(T=>n.getItem(T).then(w=>({id:T,title:w==null?void 0:w.title,edition:w==null?void 0:w.edition})).catch(()=>({id:T})))).then(T=>{z||f(T)}),()=>{z=!0}},[n,h,g]);const y=x.useMemo(()=>Ft(t.resources,t.resource_groups),[t.resources,t.resource_groups]),m=x.useMemo(()=>{var R,M,F;const v=[],z=mn(t),T=jo(t);T&&v.push({label:"版本類型",value:T,title:(R=t.lineage)!=null&&R.category?void 0:"據版本題名推斷"}),(z.era||z.reign)&&v.push({label:"刊寫年代",value:[z.era,z.reign].filter(Boolean).join(" "),title:z.source==="edition"?"據版本題名推斷":void 0});const w=(t.contained_in||[]).flatMap(P=>typeof P=="string"?[]:xt(P.volume_index));w.length&&(v.push({label:"冊數",value:`${w.length} ${s.unit.volume}`}),v.push({label:"冊次",value:`第 ${hn(w,s.unit.volume)} ${s.unit.volume}`}));const C=De(t,s.unit.juan);C&&v.push({label:"卷帙",value:r(C)});const W=(t.resources||[]).filter(P=>(P.types||(P.type?[P.type]:[])).includes("physical"));return W.length?v.push({label:"存藏",value:W.slice(0,2).map(P=>r(P.name)).join("、")+(W.length>2?` 等 ${W.length} 處`:"")}):(M=t.current_location)!=null&&M.name&&v.push({label:"存藏",value:r(t.current_location.name)}),(F=t.page_count)!=null&&F.description&&v.push({label:s.label.pageCount,value:t.page_count.description}),v},[t,r,s]),j=!!((S=t.description)!=null&&S.text),b=(t.contained_in||[]).some(v=>typeof v!="string"&&xt(v.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(Bt,{facts:m.length?e.jsx(Lt,{items:m,horizontal:!j}):void 0,children:j?e.jsx(Be,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),(t.contained_in||[]).length>0&&e.jsxs(Ae,{children:[e.jsx(xe,{glyph:"收",title:s.section.containedIn}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",padding:"14px 4px",display:"flex",flexDirection:"column",gap:12},children:(t.contained_in||[]).map((v,z)=>{var R,M;const T=typeof v=="string"?v:v.id,w=typeof v=="string"?[]:xt(v.volume_index),C=a.get(T),W=((R=C==null?void 0:C.books)==null?void 0:R.length)||((M=C==null?void 0:C.contained_works)==null?void 0:M.length)||0;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"8px 16px",marginBottom:12},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(Ce,{id:T,label:C?r(C.title):T,onNavigate:i,renderLink:o})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[W>0&&`全 ${W} ${s.unit.bu}`,W>0&&w.length>0&&" · ",w.length>0&&`本書佔 ${w.length} ${s.unit.volume}`]})]}),w.length>0&&e.jsx(co,{volumes:w,unit:s.unit.volume})]},`${T}-${z}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[l&&e.jsxs("section",{children:[e.jsx(xe,{glyph:"作",tone:"ink",title:s.section.belongsToWork}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",padding:"12px 4px 0"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 12px",marginBottom:10},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(Ce,{id:l.id,label:r(l.title),onNavigate:i,renderLink:o})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[r(De(l,s.unit.juan)),(_=l.authors)==null?void 0:_.map(v=>`${v.dynasty?`〔${r(v.dynasty)}〕`:""}${r(v.name)}${v.role?" "+r(v.role):""}`).join(" · ")].filter(Boolean).join(" · ")})]}),((k=l.description)==null?void 0:k.text)&&e.jsx(Be,{text:l.description.text,style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"}}),e.jsx(Yl,{data:t,convert:r,label:s.section.aliases})]})]}),(y.buckets.length>0||y.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(xe,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[y.mirrors.map(v=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{className:"bim-d-ui",style:{padding:"8px 4px 4px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r(v.label)}),v.items.map((z,T)=>e.jsx(di,{item:z,convert:r,showVolumes:!b},`${z.id||z.url||z.name}-${T}`))]},v.key)),y.buckets.flatMap(v=>v.items).map((v,z)=>e.jsx(di,{item:v,convert:r,showVolumes:!b},`${v.id||v.url||v.name}-${z}`))]})]})]}),(I=t.location_history)!=null&&I.length?e.jsxs(Ae,{children:[e.jsx(xe,{glyph:"藏",tone:"ink",title:s.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((v,z)=>e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 12px",padding:"9px 4px",fontSize:14,borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsx("span",{children:r(v.name)}),v.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r(v.description)})]},z))})]}):null,h.length>0&&e.jsxs(Ae,{style:{marginBottom:0},children:[e.jsx(xe,{glyph:"版",tone:"ink",title:s.relation.siblingVersions,count:`${h.length} 種`,actions:l?e.jsx(Ce,{id:l.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:o,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Wt,{children:[p.map(v=>e.jsx(Qe,{children:e.jsx(Ce,{id:v.id,label:r(v.edition||v.title||v.id),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},v.id)),h.length>p.length&&e.jsx(He,{inline:!0,label:`更多 ${h.length-p.length} 種`,onClick:()=>u(!0)})]})]})]})};function di({item:t,convert:n,showVolumes:i=!0}){const[o,s]=x.useState(!1),r=Rt(t),l=i&&!!r&&r.expected>0,c=(t.url?Pe(t.url):void 0)||n(t.name);return e.jsx(At,{name:c,note:bt(t),href:qe(t),extra:l?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>s(a=>!a),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:o?"收起分冊":`展開 ${r.expected} 冊`}),o&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(t.volumes||[]).map((a,d)=>{const p=a.status==="missing";return a.url&&!p?e.jsx("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"1px 5px",border:"1px solid var(--bim-rule, #e0d6c0)"},children:a.volume},d):e.jsx("span",{style:{padding:"1px 5px",color:p?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:p?"line-through":void 0},children:a.volume},d)})})]}):void 0})}function Yl({data:t,convert:n,label:i}){const o=[...t.additional_titles||[],...t.attached_texts||[]].map(s=>typeof s=="string"?s:s.book_title).filter(Boolean);return o.length?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:14,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em"},children:i}),o.map((s,r)=>e.jsx(Qe,{children:n(s)},r))]}):null}const pi={titles:16,works:16},wo=({data:t,catalog:n,onNavigate:i,renderLink:o,catalogAction:s})=>{var z,T;const r=N(),{convert:l}=V(),[c,a]=x.useState(""),[d,p]=x.useState(!1),[f,g]=x.useState(!1),u=x.useMemo(()=>yo(t,n),[t,n]),h=x.useMemo(()=>c?u.rows.filter(w=>w.section===c):u.rows,[u.rows,c]),y=d?h:h.slice(0,pi.titles),m=x.useMemo(()=>Ft(t.resources,t.resource_groups),[t.resources,t.resource_groups]),j=t.contained_works||[],b=new Set(u.rows.map(w=>w.id).filter(Boolean)),S=j.length>0&&!j.every(w=>b.has(w.id)),_=(()=>{const w=u.rows.map(C=>C.edition).filter(Boolean);return w.length>1&&new Set(w).size===1})(),k=f?j:j.slice(0,pi.works),I=u.sections.length>0,v=x.useMemo(()=>{var R,M,F,P;const w=[];t.subtype&&w.push({label:r.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(R=t.publication_info)!=null&&R.details&&w.push({label:"刊印",value:l(t.publication_info.details)}),(M=t.publication_info)!=null&&M.year&&w.push({label:"年代",value:t.publication_info.year});const C=((F=t.books)==null?void 0:F.length)||j.length,W=De(t,r.unit.juan);return(C||W)&&w.push({label:"種數 / 卷數",value:[C?`${C} ${r.unit.bu}`:"",l(W)].filter(Boolean).join(" · "),title:(P=t.juan_count)!=null&&P.description?l(t.juan_count.description):void 0}),u.totalVolumes&&w.push({label:"全帙冊數",value:`${u.totalVolumes} ${r.unit.volume}`}),w},[t,j.length,u.totalVolumes,l,r]);return e.jsxs(e.Fragment,{children:[e.jsxs(Bt,{facts:v.length?e.jsx(Lt,{items:v}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Be,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(T=t.history)!=null&&T.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((w,C)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",l(w)]},C))}):null]}),u.rows.length>0&&e.jsxs(Ae,{children:[e.jsx(xe,{glyph:"目",title:r.section.containedBooks,count:h.length===u.rows.length?`${r.catalog.contains} ${u.rows.length} ${r.unit.items}`:`${u.rows.length} ${r.unit.items} · 當前 ${h.length} ${r.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,I&&e.jsxs(e.Fragment,{children:[e.jsx(Fe,{label:r.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),u.sections.map(w=>e.jsx(Fe,{label:w,active:c===w,onClick:()=>{a(w),p(!1)}},w))]})]})}),e.jsxs($t,{children:[e.jsx(xn,{leadWidth:26,metaWidth:300,mainLabel:"書名",metaColumns:[...I?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),y.map((w,C)=>{var W;return e.jsx(fn,{no:String(C+1).padStart(2,"0"),leadWidth:26,metaWidth:300,metaColumns:I?["64px","1fr"]:["1fr"],main:e.jsxs(e.Fragment,{children:[w.id?e.jsx(Ce,{id:w.id,label:l(w.title),onNavigate:i,renderLink:o,dense:!0}):e.jsx("span",{children:l(w.title)}),(W=w.subItems)!=null&&W.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",w.subItems.map(R=>l(R)).join("、"),")"]}):null,w.edition&&!_&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(w.edition)})]}),meta:e.jsxs(e.Fragment,{children:[I&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:w.section?w.section.endsWith("部")?w.section:`${w.section}部`:e.jsx(gt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:w.volumes.length>0?`第 ${hn(w.volumes,r.unit.volume)} ${r.unit.volume}`:w.expected!=null?`${w.found??0}/${w.expected} ${r.unit.volume}`:e.jsx(gt,{})})]})},`${w.id??w.title}-${C}`)}),y.length===0&&e.jsx(gn,{children:r.catalog.noMatch})]}),h.length>y.length&&e.jsx(He,{label:`展開其餘 ${h.length-y.length} ${r.unit.items}子目`,onClick:()=>p(!0)})]}),(m.buckets.length>0||S)&&e.jsxs("div",{className:"bim-d-pair bim-d-pair-wide",children:[(m.buckets.length>0||m.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(xe,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[...m.mirrors.flatMap(w=>w.items),...m.buckets.flatMap(w=>w.items)].map((w,C)=>e.jsx(Kl,{item:w,convert:l},w.id||C))})]}),S&&e.jsxs("section",{children:[e.jsx(xe,{glyph:"叢",tone:"ink",title:r.section.containedWorks,count:`${j.length} 種`}),e.jsxs(Wt,{children:[k.map(w=>e.jsx(Qe,{children:e.jsx(Ce,{id:w.id,label:l(w.title),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},w.id)),j.length>k.length&&e.jsx(He,{inline:!0,label:`更多 ${j.length-k.length} 種`,onClick:()=>g(!0)})]})]})]})]})};function Kl({item:t,convert:n}){const i=(t.url?Pe(t.url):void 0)||n(t.name);return e.jsx(At,{name:i,note:bt(t)||(t.details?n(t.details):void 0),href:qe(t)})}function Jl(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 ql(t,n){if(!t.lineage)return null;const i=t.lineage;return{id:t.id,kind:"book",label:t.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[t.id],note:i.note}}function ui(t,n,i){return{id:`derive:${n.ref}->${t}:${i}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Xl(t,n,i){const[o,s]=[t,n.book_id].sort();return{id:`sibling:${o}-${s}:${i}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Zl(t,n){var d;if(n==="all")return null;const i=(d=t.collections)==null?void 0:d[n],o=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,r=o||s||!!(i!=null&&i.hypothetical_ids);if(!r&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!i||!r)return null;const l=o?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&t.node_groups)for(const[p,f]of Object.entries(t.node_groups))l.has(f)&&c.add(p);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),l){a||(a=new Set);for(const p of t.hypothetical_nodes??[])p.group&&l.has(p.group)&&a.add(p.id)}return{books:c,hypos:a}}function It(t,n,i){const o=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const r=new Set(o.excluded_books??[]),l=o.node_groups??{},c=Zl(o,i??o.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,f=new Set,g=new Set;if(a){const _=new Map(n.map(w=>[w.id,w])),k=new Map((o.hypothetical_nodes??[]).map(w=>[w.id,w])),I=w=>{const C=_.get(w);if(C&&C.lineage)return(C.lineage.derived_from??[]).map(R=>R.ref);const W=k.get(w);return W?(W.derived_from??[]).map(R=>R.ref):[]},v=w=>k.has(w)?!p||p.has(w):!d||d.has(w),z=new Set,T=w=>{if(!z.has(w)){z.add(w);for(const C of I(w))r.has(C)||(v(C)||(k.has(C)?g.add(C):_.has(C)&&f.add(C)),T(C))}};for(const w of n)d&&d.has(w.id)&&!r.has(w.id)&&T(w.id);for(const w of o.hypothetical_nodes??[])p&&p.has(w.id)&&T(w.id)}const u=n.filter(_=>!r.has(_.id)).filter(_=>!d||d.has(_.id)||f.has(_.id)).map(_=>{const k=ql(_,l);return k&&f.has(_.id)&&(k.bridge=!0),k}).filter(_=>_!==null),h=(o.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||g.has(_.id)).map(_=>{const k=Jl(_);return g.has(_.id)&&(k.bridge=!0),k}),y=[...u,...h],m=new Set(y.map(_=>_.id)),j=new Set,b=[],S=_=>{j.has(_.id)||!m.has(_.source)||!m.has(_.target)||(j.add(_.id),b.push(_))};for(const _ of n)r.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!f.has(_.id)||((_.lineage.derived_from??[]).forEach((k,I)=>{S(ui(_.id,k,I))}),(_.lineage.related_to??[]).forEach((k,I)=>{S(Xl(_.id,k,I))}));for(const _ of o.hypothetical_nodes??[])p&&!p.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((k,I)=>{S(ui(_.id,k,I))});return{nodes:y,edges:b,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(r)}}function _o(t,n,i){const o=(t??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function Ql(t,n){const i=[],o=t.version_graph;if(!o)return i;const s=new Set(n.map(a=>a.id)),r=new Set((o.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...r]),c=(a,d)=>{l.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!r.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(p=>c(d,p)),(a.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const a of o.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const Co=({graph:t,renderLink:n,className:i,style:o})=>{const{convert:s}=V();if(!t.nodes.length)return e.jsx("div",{style:{...xa,...o},className:i,children:"暂无版本图数据"});const r=new Map,l=new Map;for(const g of t.edges)if(g.kind==="derive"){const u=r.get(g.target)??[];u.push(g),r.set(g.target,u)}else for(const u of[g.source,g.target]){const h=l.get(u)??[];h.push(g),l.set(u,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),a=new Map,d=[];for(const g of t.nodes)if(g.group){const u=a.get(g.group)??[];u.push(g),a.set(g.group,u)}else d.push(g);const p=(g,u)=>(g.year??9999)-(u.year??9999);a.forEach(g=>g.sort(p)),d.sort(p);const f=t.groups.filter(g=>a.has(g.id));return e.jsxs("div",{className:i,style:{...ta,...o},children:[t.title&&e.jsx("div",{style:na,children:s(t.title)}),t.description&&e.jsx("div",{style:ia,children:s(t.description)}),f.map(g=>e.jsx(xi,{label:g.label,color:g.color,nodes:a.get(g.id),incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(xi,{label:"其他",nodes:d,incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n})]})},xi=({label:t,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:r,renderLink:l})=>{const{convert:c}=V();return e.jsxs("div",{style:oa,children:[e.jsx("div",{style:{...ra,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(ea,{node:a,incoming:o.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:r,renderLink:l},a.id))]})},ea=({node:t,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const r=t.kind==="hypothetical",l=t.bridge,{convert:c}=V();return e.jsxs("div",{style:{...sa,borderStyle:r||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:la,children:[e.jsx("span",{style:aa,children:r||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:ca,children:_o(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:da,children:[t.category&&e.jsx(st,{children:c(t.category)}),t.status==="lost"&&e.jsx(st,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(st,{tone:"warn",children:"残本"}),r&&e.jsx(st,{tone:"info",children:"假想祖本"}),l&&e.jsx(st,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:pa,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:ua,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:gi,children:[e.jsx("div",{style:mi,children:"来源:"}),n.map(a=>{const d=o.get(a.source);return e.jsxs("div",{style:hi(a.confidence),children:[e.jsx("span",{style:bi,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(fi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:yi,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:gi,children:[e.jsx("div",{style:mi,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=o.get(d);return e.jsxs("div",{style:hi(a.confidence),children:[e.jsx("span",{style:bi,children:c(a.relation)}),e.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&s?s(p.id,c(p.label)):c((p==null?void 0:p.label)??d)}),e.jsx(fi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:yi,children:["· ",c(a.evidence)]})]},a.id)})]})]})},st=({children:t,tone:n="default"})=>{const o={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:o.bg,color:o.fg,marginRight:"4px"},children:t})},fi=({level:t})=>{const i={certain:{label:"确定",color:"var(--bim-confidence-certain, #2e7d32)"},consensus:{label:"共识",color:"var(--bim-confidence-consensus, #1976d2)"},probable:{label:"推测",color:"var(--bim-confidence-probable, #ed6c02)"},disputed:{label:"有争议",color:"var(--bim-confidence-disputed, #c62828)"}}[t];return i?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},ta={fontSize:"14px",color:"var(--bim-fg, #333)"},na={fontSize:"16px",fontWeight:600,marginBottom:"8px"},ia={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},oa={marginBottom:"16px"},ra={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},sa={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},la={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},aa={fontSize:"15px",fontWeight:600},ca={fontSize:"12px",color:"var(--bim-muted, #777)"},da={marginBottom:"6px"},pa={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},ua={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},gi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},mi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},hi=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),bi={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},yi={fontSize:"11px",color:"var(--bim-muted, #888)"},xa={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Io=({selectedNodeId:t,...n})=>{const[i,o]=x.useState("loading"),[s,r]=x.useState(null);return x.useEffect(()=>{let l=!1;return fa().then(c=>{l||(c?(r(c),o("ready")):o("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:vi,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:vi,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(ga,{modules:s,selectedNodeId:t,...n})};async function fa(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const ga=({graph:t,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:r,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:f,BaseEdge:g,EdgeLabelRenderer:u,getSmoothStepPath:h,dagre:y}=l,m=x.useMemo(()=>({lineage:I=>{var P,$,A,L;const v=((P=I.data)==null?void 0:P.stepPosition)??.85,[z,T,w]=h({sourceX:I.sourceX,sourceY:I.sourceY,sourcePosition:I.sourcePosition,targetX:I.targetX,targetY:I.targetY,targetPosition:I.targetPosition,stepPosition:v,borderRadius:5}),C=!!(($=I.data)!=null&&$.isSibling),W=C?T:I.targetX-18,R=C?w:I.targetY-12,M=(A=I.data)==null?void 0:A.labelStyle,F=(L=I.data)==null?void 0:L.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:I.id,path:z,style:I.style,markerStart:I.markerStart,markerEnd:I.markerEnd}),I.label&&e.jsx(u,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${W}px,${R}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...F,...M},children:I.label})})]})}}),[g,u,h]),j=x.useMemo(()=>({version:I=>{const v=I.data,z=v.kind==="hypothetical",T=v.status==="lost",w=v.isSelected,C=v.bridge,W=v.borderColor??"var(--bim-muted, #888)",R=C||z?"dashed":"solid",M=C?.5:T?.6:1;return e.jsxs("div",{style:{background:C?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${R} ${w?"var(--bim-primary, #0078d4)":W}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:w?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":z||C?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:C?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(p,{type:"target",position:f.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:z||!v.renderLink?v.label:v.renderLink(v.bookId,v.label)}),v.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:v.description}),v.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:_o(v.yearText,void 0,v.uncertain)}),T&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(p,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[p,f]),{convert:b}=V(),{rfNodes:S,rfEdges:_}=x.useMemo(()=>ma(t,y,n,r,b),[t,y,n,r,b]);return e.jsx("div",{style:{width:"100%",height:i,...s},className:o,children:e.jsxs(c,{nodes:S,edges:_,nodeTypes:j,edgeTypes:m,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function ma(t,n,i,o,s=r=>r??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??"var(--bim-muted, #888)"]));for(const j of t.nodes)a.setNode(j.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(p.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const f=t.nodes.map(j=>{const b=a.node(j.id),S=o&&j.id===o,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??ba(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:S,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:b.x-160/2,y:b.y-90/2},data:_,draggable:!1,selected:S}}),g=.78,u=.06,h=new Map;for(const j of t.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const y=new Map;for(const[j,b]of h){if(b.length<=1)continue;const S=[...b].sort((k,I)=>{var T,w;const v=((T=a.node(k.target))==null?void 0:T.y)??0,z=((w=a.node(I.target))==null?void 0:w.y)??0;return v-z}),_=S.length;S.forEach((k,I)=>{const v=(I-(_-1)/2)*u;y.set(k.id,g+v)})}const m=t.edges.map(j=>ha(j,y.get(j.id),s));return{rfNodes:f,rfEdges:m}}function ha(t,n,i=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",r=ya(t.confidence),l={type:"arrowclosed",color:r,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:i(t.relation),data:{labelStyle:{color:"var(--bim-fg, #444)"},isSibling:s,stepPosition:n},style:{stroke:r,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function ba(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function ya(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 vi={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)"},zo=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:r,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:f})=>{var b;const[g,u]=x.useState(n),h=S=>{u(S),r==null||r(S)},y=(()=>{if(!a)return[];const S=Object.entries(a);return S.length===0||a.all?S:[...S,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const j=l?(b=a==null?void 0:a[l])==null?void 0:b.description:void 0;return e.jsxs("div",{className:p,style:f,children:[e.jsxs("div",{style:va,children:[e.jsx("button",{onClick:()=>h("list"),style:Vt(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:Vt(g==="graph"),children:"关系图"}),m&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),y.map(([S,_])=>{const k=d==null?void 0:d[S];return e.jsxs("button",{onClick:()=>c==null?void 0:c(S),style:Vt(l===S),title:_.description,children:[_.label,k!=null?` ${k}`:""]},S)})]})]}),m&&j&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:j}),g==="list"?e.jsx(Co,{graph:t,renderLink:i}):e.jsx(Io,{graph:t,renderLink:i,height:o,selectedNodeId:s})]})},va={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Vt=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),To=({style:t})=>{const n=x.useContext(mt);if(!n)return null;const{locale:i,setLocale:o}=n,s=i==="zh-Hant",r=()=>o(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:r,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})},Ro=({href:t,label:n="在 GitHub 查看本条目源文件",size:i=16,className:o,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:r=>{r.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:r=>{r.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})}),ja=({id:t,transport:n,activeTab:i,onTabChange:o,activeJuan:s,onJuanChange:r,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:f,onNavigate:g,onBack:u,backLabel:h,renderLink:y,enrichDetail:m,getSourceLink:j,extraTabs:b=[],showFeedbackTab:S=!0,feedbackApiUrl:_,height:k,footerExtra:I,className:v,style:z})=>{const T=N(),{convert:w}=V(),[C,W]=x.useState(null),[R,M]=x.useState(null),[F,P]=x.useState(!0),[$,A]=x.useState(!1),[L,E]=x.useState([]),[D,te]=x.useState(!1),[G,Z]=x.useState(null),[re,ne]=x.useState(!1),[U,Y]=x.useState(null),[ce,Ne]=x.useState(!1),[je,he]=x.useState(null),[Ie,Le]=x.useState(!1),Se=x.useRef(null),[Ve,et]=x.useState(null),O=s!==void 0?s:Ve,ie=x.useCallback(H=>{r?r(H):et(H)},[r]),ee=x.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){E([]);return}te(!0);try{if(n.getCollectionCatalogs)E(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const oe=await n.getCollectionCatalog(H);E(oe?[{resource_id:"",data:oe}]:[])}}catch{E([])}finally{te(!1)}},[n]),B=x.useCallback(async H=>{if(!n.getCollatedEditionIndex){Z(null);return}ne(!0);try{Z(await n.getCollatedEditionIndex(H))}catch{Z(null)}finally{ne(!1)}},[n]),X=x.useCallback(async H=>{if(!n.getBookFullTextIndex){Y(null);return}Ne(!0);try{Y(await n.getBookFullTextIndex(H))}catch{Y(null)}finally{Ne(!1)}},[n]),se=x.useCallback(async(H,oe)=>{Le(!0);try{if(n.getLineageGraph){const ze=await n.getLineageGraph(H);ze&&he(ze)}const le=oe.version_graph;if(!le||!le.enabled){je||he(null),Se.current=null;return}const ae=oe.books??[],Q=[];for(const ze of ae)try{const ke=await n.getItem(ze);ke&&Q.push(ke)}catch{}Se.current={work:oe,books:Q};const K=a??le.default_collection??(le.core_books&&le.core_books.length>0?"core":"all"),Ue=K==="core"&&Array.isArray(le.core_books)&&le.core_books.length>0?"core":K??"all";he(It(oe,Q,Ue))}catch{he(null),Se.current=null}finally{Le(!1)}},[n]);x.useEffect(()=>{let H=!1;return(async()=>{P(!0),A(!1),W(null),M(null),E([]),Z(null),he(null),Se.current=null;try{const le=await n.getItem(t);if(H)return;if(!le){A(!0);return}const ae=le;let Q=null;if(n.getEntry&&(Q=await n.getEntry(t),H))return;Q||(Q={id:t,title:ae.title??ae.primary_name??t,type:ae.type??"book"}),m&&m(Q,ae),W(Q),M(ae),ae.type==="collection"?ee(t):ae.type==="work"?((ae.has_collated||n.getCollatedEditionIndex)&&B(t),(ae.version_graph||n.getLineageGraph)&&se(t,ae)):ae.type==="book"&&ae.has_full_text&&n.getBookFullTextIndex&&X(t)}catch{H||A(!0)}finally{H||P(!1)}})(),()=>{H=!0}},[t,n,m,ee,B,se,X]),x.useEffect(()=>{const H=Se.current;!H||!a||he(It(H.work,H.books,a))},[a]);const J=[];if(R){if(J.push({key:"basic",label:T.detailTab.basicInfo}),R.type==="collection"){D&&L.length===0&&J.push({key:"catalog:loading",label:`${T.detailTab.catalog}…`});for(const H of L)J.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${w(H.short_name)}${T.detailTab.catalogSuffix}`:T.detailTab.collectionCatalog})}R.type==="work"&&(G||re)&&J.push({key:"collated",label:re?`${T.detailTab.collatedEdition}…`:T.detailTab.collatedEdition}),R.type==="book"&&(U||ce)&&J.push({key:"fulltext",label:ce?`${T.detailTab.fullText}…`:T.detailTab.fullText}),R.type==="work"&&(je||Ie)&&J.push({key:"lineage",label:Ie?`${T.detailTab.lineage}…`:T.detailTab.lineage});for(const H of b)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(R)&&J.push({key:H.key,label:H.label});S&&J.push({key:"feedback",label:T.detailTab.feedback});for(const H of b)H.position==="after-feedback"&&H.shouldShow(R)&&J.push({key:H.key,label:H.label})}x.useEffect(()=>{if(i!=="emendated"||!R)return;o("basic");const H=setTimeout(()=>{var oe;(oe=document.getElementById("studies"))==null||oe.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,R,o]);const Ee=C&&R&&j?j({activeTab:i,activeJuan:O,entry:C,detail:R}):null,be=x.useMemo(()=>{var Q;if(!R)return null;const oe=(R.authors??[]).map(K=>`${K.dynasty?`〔${w(K.dynasty)}〕`:""}${w(K.name)}${K.role?` ${w(K.role)}`:""}`).join(" · ");let le=!1;try{le=q.extractStatus(R.id)==="draft"}catch{}if(R.type==="book"){const K=R;return{title:w(K.title),subtitle:K.edition?w(K.edition):oe||void 0,aside:[le?T.status.draft:"",oe&&K.edition?oe:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(R.type==="collection"){const K=R;return{title:w(K.title),subtitle:w(De(K,T.unit.juan))||void 0,aside:[(Q=K.publication_info)==null?void 0:Q.year,le?T.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:oe||void 0}}if(R.type==="entity"){const K=R,Ue=ke=>ke==null?"":ke<0?`前${-ke}`:String(ke),ze=K.birth_year!=null||K.death_year!=null?`${Ue(K.birth_year)||"?"}—${Ue(K.death_year)||"?"}`:"";return{title:w(K.primary_name||K.title),subtitle:[K.dynasty?`〔${w(K.dynasty)}〕`:"",ze].filter(Boolean).join(" ")||void 0,aside:le?T.status.draft:void 0,secondLine:void 0}}const ae=w(De(R,T.unit.juan));return{title:w(R.title),subtitle:[ae,oe].filter(Boolean).join(" · ")||void 0,aside:[R.subtype,le?T.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[R,w,T]),pe=()=>{var H;return R?R.type==="work"?e.jsx(So,{data:R,transport:n,onNavigate:g,renderLink:y,lineageAction:je&&je.nodes.length>0?e.jsxs("button",{type:"button",onClick:()=>o("lineage"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[T.detailTab.lineage," →"]}):null}):R.type==="book"?e.jsx(ko,{data:R,transport:n,onNavigate:g,renderLink:y}):R.type==="collection"?e.jsx(wo,{data:R,catalog:(H=L[0])==null?void 0:H.data,transport:n,onNavigate:g,renderLink:y,catalogAction:L.length>0?e.jsxs("button",{type:"button",onClick:()=>o(`catalog:${L[0].resource_id}`),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[T.detailTab.collectionCatalog," →"]}):null}):e.jsx(nn,{data:R,transport:n,onNavigate:g,renderLink:y,hideHeader:!0}):null},Ge=()=>{var oe,le,ae;if(!C||!R)return null;if(i==="basic"||i==="emendated")return pe();if(typeof i=="string"&&i.startsWith("catalog:")){const Q=(oe=L.find(K=>`catalog:${K.resource_id}`===i))==null?void 0:oe.data;return e.jsx(rn,{data:Q,onNavigate:g,renderLink:y})}if(i==="collated")return e.jsx(cn,{index:G||void 0,workId:t,transport:n,onNavigate:g,activeJuan:O,onJuanChange:ie});if(i==="fulltext")return e.jsx(Oi,{index:U||void 0,bookId:t,transport:n,activeChapter:O,onChapterChange:ie});if(i==="lineage"){if(!je)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:Ie?"加載中…":"暫無版本圖數據"});const Q=R.type==="work"?R:null;return e.jsx(zo,{graph:je,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:f,collection:a??((le=Q==null?void 0:Q.version_graph)==null?void 0:le.default_collection),onCollectionChange:d,collectionsAvailable:(ae=Q==null?void 0:Q.version_graph)==null?void 0:ae.collections,collectionCounts:(()=>{var ke,bn,yn,vn,jn,Sn,kn;if(!Q)return;const K={},Ue=((ke=Se.current)==null?void 0:ke.books)??[];K.all=(((bn=Q.books)==null?void 0:bn.length)??0)-(((vn=(yn=Q.version_graph)==null?void 0:yn.excluded_books)==null?void 0:vn.length)??0);const ze=(jn=Q.version_graph)==null?void 0:jn.collections;if(ze)for(const wn of Object.keys(ze))K[wn]=It(Q,Ue,wn).nodes.filter(_n=>_n.kind==="book"&&!_n.bridge).length;return K.core==null&&((kn=(Sn=Q.version_graph)==null?void 0:Sn.core_books)!=null&&kn.length)&&(K.core=Q.version_graph.core_books.length),K})()})}if(i==="feedback"&&S)return e.jsx(io,{resourceId:t,apiUrl:_});const H=b.find(Q=>Q.key===i);return H?H.render({detail:R,entry:C,transport:n,onNavigate:g}):null};if(F)return e.jsx(kt,{style:{minHeight:k,...z},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,oe)=>e.jsx("div",{style:{height:oe===1?40:16,width:H,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},oe))})});if($||!R||!C||!be)return e.jsx(kt,{style:{minHeight:k,...z},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const Eo=i==="basic"||i==="emendated",Mt=[{label:h??T.detailTab.backToIndex,onClick:u}];if(R.type==="book"&&R.work_id){const H=R.work_id;Mt.push({label:T.indexType.work,onClick:()=>g==null?void 0:g(H)})}return Mt.push({label:T.indexType[R.type]}),e.jsx("div",{className:v,children:e.jsxs(kt,{style:{minHeight:k,...z},children:[e.jsx(so,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(pn,{char:"籍"}),e.jsx(lo,{items:Mt})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(To,{}),S&&e.jsx("button",{type:"button",onClick:()=>o("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:T.detailTab.feedback}),Ee&&e.jsx(Ro,{...Ee})]})}),e.jsx(ao,{...be}),J.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:J.map(H=>e.jsx(Fe,{label:H.label,active:H.key===i||Eo&&H.key==="basic",onClick:()=>o(H.key)},H.key))}),e.jsx("div",{style:{marginTop:J.length>1?8:0},children:Ge()}),e.jsx(uo,{left:e.jsxs(e.Fragment,{children:[I,I?" · ":"",e.jsx(Sa,{id:R.id,label:T.label.id,copied:T.action.copied})]}),right:e.jsxs(e.Fragment,{children:[S&&e.jsx("button",{type:"button",onClick:()=>o("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:T.detailTab.submitVersion}),Ee&&e.jsx("a",{href:Ee.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:T.detailTab.dataLicense})]})})]})})};function Sa({id:t,label:n,copied:i}){const[o,s]=x.useState(!1);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsxs("span",{children:[n," ",t]}),e.jsx("button",{type:"button",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}).catch(()=>{})},title:o?i:void 0,style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:o?"✓":"⧉"})]})}exports.BidLink=q.BidLink;exports.BookIndexError=q.BookIndexError;exports.BookIndexManager=q.BookIndexManager;exports.BookIndexStorage=q.BookIndexStorage;exports.BundleStorage=q.BundleStorage;exports.ConfigError=q.ConfigError;exports.GithubStorage=q.GithubStorage;exports.IdGenerationError=q.IdGenerationError;exports.IdGenerator=q.IdGenerator;exports.LocalStorage=q.LocalStorage;exports.MigrationError=q.MigrationError;exports.StorageError=q.StorageError;exports.base36Decode=q.base36Decode;exports.base36Encode=q.base36Encode;exports.base58Decode=q.base58Decode;exports.buildId=q.buildId;exports.buildPromotionMap=q.buildPromotionMap;exports.cleanName=q.cleanName;exports.decodeId=q.decodeId;exports.decodeIdString=q.decodeIdString;exports.encodeId=q.encodeId;exports.extractIdFromUrl=q.extractIdFromUrl;exports.extractStatus=q.extractStatus;exports.extractType=q.extractType;exports.normalizeCatalog=q.normalizeCatalog;exports.parseId=q.parseId;exports.shardOf=q.shardOf;exports.smartDecode=q.smartDecode;exports.validateResource=q.validateResource;exports.Badge=Tt;exports.BidUrlProvider=Oo;exports.BookDetailLayout=ja;exports.BookFullText=Oi;exports.BookPage=ko;exports.Breadcrumb=lo;exports.Chip=Qe;exports.ChipWall=Wt;exports.CollatedEdition=cn;exports.CollectionCatalog=rn;exports.CollectionPage=wo;exports.CreateEntityDialog=Ji;exports.DETAIL_CSS=ro;exports.Dash=gt;exports.DataTable=$t;exports.DetailFooter=uo;exports.DetailHeader=ao;exports.EmendatedBySection=Wi;exports.EmptyNote=gn;exports.EntityDetail=nn;exports.EntityPickerDialog=Xi;exports.EntitySelector=Ki;exports.ExpandRow=po;exports.ExtLink=qt;exports.FactList=Lt;exports.FeedbackButton=kl;exports.FeedbackDialog=to;exports.FeedbackForm=no;exports.FeedbackList=dn;exports.FeedbackTab=io;exports.FilterChip=Fe;exports.FormInput=ue;exports.FormTextArea=$e;exports.GlyphBadge=pn;exports.HomePage=Yt;exports.IndexApp=Rs;exports.IndexBrowser=Ut;exports.IndexDetail=on;exports.IndexEditor=Zi;exports.IndexView=ul;exports.IntroGrid=Bt;exports.LocaleContext=mt;exports.LocaleProvider=Xo;exports.LocaleToggle=To;exports.ModeIndicator=Ii;exports.MoreButton=He;exports.PAGE_MAX_WIDTH=oo;exports.PageFrame=kt;exports.Quote=wt;exports.RelationPanel=Ui;exports.RepoSourceLink=Ro;exports.ResourceEditor=Gt;exports.ResourceGroup=Jt;exports.ResourceList=tn;exports.ResourceRow=At;exports.SearchInput=zi;exports.Section=ye;exports.SectionHead=xe;exports.SmartBidInput=St;exports.SourceEditor=Ni;exports.TableHead=xn;exports.TableRow=fn;exports.TextButton=un;exports.TopStrip=so;exports.VersionLineageGraph=Io;exports.VersionLineageList=Co;exports.VersionLineageView=zo;exports.VolumeChips=co;exports.WorkCatalog=Es;exports.WorkPage=So;exports.bucketResources=Ft;exports.buildCollectionTable=yo;exports.buildLineageGraph=It;exports.buildPageUrl=en;exports.buildVersionRow=ho;exports.buildVersionTable=bo;exports.computeVersionPartition=Ml;exports.deriveEditionType=jo;exports.deriveEra=mn;exports.deriveYear=go;exports.detailToEditor=eo;exports.editorToDetail=pl;exports.eraRank=ct;exports.formatTemplate=ht;exports.formatVolumeRange=hn;exports.getDisplayNameFromUrl=Pe;exports.getStartPage=Qt;exports.getTypeGroupKey=Xt;exports.groupRelatedWorks=mo;exports.measureText=De;exports.mergeVolumeResources=Zt;exports.normalizeEra=lt;exports.normalizeVolumeIndex=xt;exports.normalizeVolumes=Ci;exports.numberToChinese=vo;exports.parseChineseNumber=fo;exports.parseSourceString=Vi;exports.resourceHref=qe;exports.resourceNote=bt;exports.stringifySources=Gi;exports.useBidUrl=me;exports.useConvert=V;exports.useT=N;exports.validateLineageGraph=Ql;exports.volumeStats=Rt;
|
|
51
|
+
`;function Tt({children:t,style:n}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:ko}),e.jsx("div",{className:"bim-d-main",children:t})]})}function wo({breadcrumb:t,actions:n}){return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",alignItems:"center",justifyContent:"space-between",gap:"8px 16px",marginBottom:24,fontSize:12,color:"var(--bim-label-fg, #8b7a62)"},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:t}),n&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:16},children:n})]})}function vn({char:t,tone:n="accent"}){return e.jsx("span",{"aria-hidden":"true",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,flex:"none",fontSize:11,fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",background:n==="accent"?"var(--bim-accent, #9c3a2c)":"var(--bim-ink, #2a231c)",color:"var(--bim-page-bg, #fbf9f3)"},children:t})}function _o({items:t}){const n=me();return e.jsx(e.Fragment,{children:t.map((i,o)=>{const s=o===t.length-1,r=o>0&&e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${o}`),l=i.id?n(i.id):i.href,c=s||!i.onClick&&!l?e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:i.label},o):e.jsx("a",{href:l??"#",onClick:i.onClick?a=>{a.metaKey||a.ctrlKey||(a.preventDefault(),i.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:i.label},o);return e.jsxs(u.Fragment,{children:[r,c]},o)})})}function Co({title:t,subtitle:n,aside:i,secondLine:o}){return e.jsxs("header",{style:{borderBottom:"2px solid var(--bim-rule-strong, #2a231c)",paddingBottom:18},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"flex-end",justifyContent:"space-between",gap:"10px 24px"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 14px",minWidth:0},children:[e.jsx("h1",{className:"bim-d-h1",style:{margin:0,fontSize:42,fontWeight:700,letterSpacing:".06em",lineHeight:1.1,wordBreak:"break-word"},children:t}),n&&e.jsx("span",{style:{fontSize:15,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".06em"},children:n})]}),i&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".06em"},children:i})]}),o&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:"var(--bim-quiet-fg, #5b4f40)"},children:o})]})}function vt({children:t,facts:n}){return!t&&n?e.jsx("div",{style:{padding:"20px 0 26px",borderBottom:"1px solid var(--bim-rule, #e4dbc9)",marginBottom:40},children:n}):e.jsxs("div",{className:"bim-d-intro",children:[e.jsx("div",{style:{minWidth:0},children:t}),n]})}function jt({items:t,horizontal:n}){return t.length?e.jsx("div",{style:{borderLeft:"2px solid var(--bim-accent, #9c3a2c)",paddingLeft:16,display:n?"grid":"flex",gridTemplateColumns:n?"repeat(auto-fit, minmax(150px, max-content))":void 0,flexDirection:n?void 0:"column",gap:n?"14px 40px":10,fontSize:13},children:t.map((i,o)=>e.jsxs("div",{title:i.title,style:n?{display:"flex",flexDirection:"column",gap:3}:{display:"flex",justifyContent:"space-between",gap:10},children:[e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em",flex:"none"},children:i.label}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:i.value})]},o))}):null}function ue({glyph:t,tone:n,title:i,count:o,actions:s,id:r}){return e.jsxs("div",{id:r,style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"10px 16px",marginBottom:14,scrollMarginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(vn,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:i}),o!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:o})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Te({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function Ae({label:t,active:n,onClick:i,dashed:o}){return e.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${o&&!n?"dashed":"solid"} ${n?"var(--bim-accent, #9c3a2c)":"var(--bim-rule, #e0d6c0)"}`,background:n?"var(--bim-accent, #9c3a2c)":"transparent",color:n?"var(--bim-page-bg, #fbf9f3)":"var(--bim-meta-fg, #7b6a54)",fontSize:12,cursor:"pointer",letterSpacing:".04em",lineHeight:1.4},children:t})}function Mt({label:t,onClick:n}){return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:t})}function Me({label:t,onClick:n,inline:i}){return e.jsx("button",{type:"button",onClick:n,className:"bim-d-ui",style:{marginTop:i?0:12,width:i?void 0:"100%",padding:i?"4px 12px":9,background:"none",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",cursor:"pointer",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:i?void 0:".08em"},children:t})}function St({children:t,href:n,onClick:i,title:o}){const s={display:"inline-block",padding:"4px 10px",border:"1px solid var(--bim-rule, #e0d6c0)",fontSize:13,color:"var(--bim-body-fg, #3b3228)",lineHeight:1.5};return n||i?e.jsx("a",{href:n??"#",title:o,onClick:i?r=>{r.metaKey||r.ctrlKey||(r.preventDefault(),i())}:void 0,style:s,children:t}):e.jsx("span",{title:o,style:s,children:t})}function Ft({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function Io({volumes:t,unit:n="冊",max:i=60}){const[o,s]=u.useState(!1);if(!t.length)return null;const r=o?t:t.slice(0,i);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[r.map(l=>e.jsx("span",{style:{minWidth:30,textAlign:"center",padding:"2px 5px",border:"1px solid var(--bim-rule, #e0d6c0)",color:"var(--bim-meta-fg, #7b6a54)"},children:l},l)),!o&&t.length>i&&e.jsxs("button",{type:"button",onClick:()=>s(!0),style:{padding:"2px 8px",background:"none",cursor:"pointer",border:"1px dashed var(--bim-rule-dashed, #d6c9ae)",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:["+",t.length-i]}),e.jsx("span",{style:{padding:"2px 6px",color:"var(--bim-hint-fg, #b3a385)"},children:n})]})}function Ne({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function Pt({spec:t}){return e.jsxs("div",{className:"bim-d-thead bim-d-ui",style:{display:"grid",gridTemplateColumns:`${t.leadWidth}px 1fr ${t.metaWidth}px`,gap:12,padding:"7px 4px",borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",fontSize:11,color:"var(--bim-label-fg, #8b7a62)",letterSpacing:".1em"},children:[e.jsx("span",{}),e.jsx("span",{children:t.mainLabel}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(n=>n.width).join(" "),gap:12},children:t.columns.map(n=>e.jsx("span",{children:n.label},n.label))})]})}function Ht({no:t,main:n,meta:i,spec:o}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${o.leadWidth}px 1fr ${o.metaWidth}px`,gap:12},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-hint-fg, #c2b294)",textAlign:"right"},children:t}),e.jsx("span",{style:{minWidth:0},children:n}),e.jsx("span",{className:"bim-d-row-meta",style:{display:"grid",gridTemplateColumns:o.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Dt(t){return String(t+1).padStart(2,"0")}function Xe(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function zo({open:t,onToggle:n,main:i,action:o,children:s}){return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsxs("div",{className:"bim-d-expand-head",style:{display:"grid",gridTemplateColumns:"26px 1fr auto",gap:12,alignItems:"baseline",padding:"9px 4px"},children:[e.jsx("button",{type:"button",onClick:n,"aria-expanded":t,className:"bim-d-ui",style:{width:18,height:18,display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,cursor:"pointer",fontSize:12,lineHeight:1,border:`1px solid ${t?"var(--bim-accent, #9c3a2c)":"var(--bim-rule-dashed, #d6c9ae)"}`,background:t?"var(--bim-accent, #9c3a2c)":"transparent",color:t?"var(--bim-page-bg, #fbf9f3)":"var(--bim-accent, #9c3a2c)"},children:t?"-":"+"}),e.jsx("span",{style:{fontSize:14,minWidth:0},children:i}),o]}),t&&s&&e.jsx("div",{style:{padding:"2px 4px 14px 38px",borderLeft:"2px solid var(--bim-rule-accent-soft, #e0d3b6)",marginLeft:12},children:s})]})}function Rt({label:t,children:n}){return e.jsxs("div",{style:{marginBottom:10},children:[t&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,fontWeight:600,letterSpacing:".1em",color:"var(--bim-label-fg, #a3937b)",marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"},children:n})]})}function en({title:t,tag:n,children:i}){return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:7,borderBottom:"1px solid var(--bim-rule-strong, #2a231c)",marginBottom:2},children:[e.jsx("span",{style:{fontSize:14.5,letterSpacing:".08em"},children:t}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:n})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function To({name:t,note:n,href:i,extra:o}){const s=e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontSize:14,minWidth:0},children:t}),e.jsx("span",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)",flex:"none"},children:i?"↗":""}),n&&e.jsx("span",{className:"bim-d-ui",style:{gridColumn:"1 / -1",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:n})]}),r={display:"grid",gridTemplateColumns:"1fr auto",gap:"4px 12px",padding:"9px 4px",borderBottom:"1px solid var(--bim-rule, #eae2d0)",color:"var(--bim-body-fg, #3b3228)",alignItems:"baseline"};return e.jsxs(e.Fragment,{children:[i?e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:r,children:s}):e.jsx("div",{style:r,children:s}),o]})}function Ze({item:t,siblings:n,showVolumes:i=!0,fallbackNote:o}){const{convert:s}=D(),[r,l]=u.useState(!1),c=rn(t),a=i&&!!c&&c.expected>0,d=(t.url?gt(t.url):void 0)||s(t.name),p=n?Kl(t,n):"",f=p?`${d}(${p})`:d;return e.jsx(To,{name:f,note:hn(t)||o,href:Bt(t),extra:a?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>l(g=>!g),className:"bim-d-ui",style:{alignSelf:"flex-start",padding:"2px 0",marginTop:4,background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--bim-meta-fg, #7b6a54)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)"},children:r?"收起分冊":`展開 ${c.expected} 冊`}),r&&e.jsx(Ro,{item:t})]}):void 0})}function Ro({item:t}){return e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,padding:"6px 0 10px",fontSize:11},children:(t.volumes||[]).map((n,i)=>{const o=n.status==="missing";return n.url&&!o?e.jsx("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",style:{padding:"1px 5px",border:"1px solid var(--bim-rule, #e0d6c0)"},children:n.volume},i):e.jsx("span",{style:{padding:"1px 5px",color:o?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:o?"line-through":void 0},children:n.volume},i)})})}function jn({label:t,items:n}){const{convert:i}=D();return n.length?e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".08em"},children:t}),n.map((o,s)=>e.jsx(St,{children:i(o)},s))]}):null}function Eo({rows:t}){const n=t.filter(i=>i.items.length>0);return n.length?e.jsx("div",{style:{marginTop:16,display:"flex",flexDirection:"column",gap:8},children:n.map(i=>e.jsx(jn,{label:i.label,items:i.items},i.label))}):null}function ht(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Bo({left:t,right:n}){return e.jsxs("footer",{className:"bim-d-ui",style:{marginTop:52,paddingTop:14,borderTop:"1px solid var(--bim-rule, #e4dbc9)",display:"flex",flexWrap:"wrap",justifyContent:"space-between",gap:"8px 16px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[e.jsx("span",{children:t}),n&&e.jsx("span",{style:{display:"flex",gap:16},children:n})]})}function Qe({children:t,action:n}){return e.jsxs("div",{className:"bim-d-ui",style:{padding:"18px 4px",fontSize:12.5,color:"var(--bim-label-fg, #a3937b)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",display:"flex",flexWrap:"wrap",alignItems:"center",gap:12},children:[e.jsx("span",{children:t}),n]})}function we({id:t,label:n,onNavigate:i,renderLink:o,style:s,dense:r}){const l=me();return o?e.jsx(e.Fragment,{children:o(t,typeof n=="string"?n:void 0,{dense:r})}):e.jsx("a",{href:l(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function tn({href:t,children:n}){return e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:[n," ",e.jsx("span",{className:"bim-d-ui",style:{fontSize:11},children:"↗"})]})}const Je={versions:12,catalogs:8,chips:12},Lo={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Wo=({data:t,transport:n,onNavigate:i,renderLink:o,lineageAction:s})=>{var b,R,E,A,M,P,$,F,Q,W,U,ne;const r=O(),{convert:l}=D(),c=u.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[a,d]=u.useState(new Map),[p,f]=u.useState(!1),[g,x]=u.useState(""),[h,v]=u.useState(!1),[m,j]=u.useState("default"),y=p||!!g||h||m==="year",k=u.useMemo(()=>y?c:c.slice(0,Je.versions),[c,y]);u.useEffect(()=>{if(!n||k.length===0)return;const B=k.filter(Y=>!a.has(Y));if(B.length===0)return;let V=!1;return Promise.all(B.map(Y=>n.getItem(Y).then(ie=>{const G=ie??{};return[Y,{id:Y,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[Y,{id:Y}]))).then(Y=>{V||d(ie=>{const G=new Map(ie);for(const[K,de]of Y)G.set(K,de);return G})}),()=>{V=!0}},[n,k,a]);const _=u.useMemo(()=>c.map(B=>a.get(B)??{id:B}),[c,a]),w=u.useMemo(()=>go(_,t.version_graph,{era:g,scanOnly:h,sort:m}),[_,t.version_graph,g,h,m]),z=p?w.rows:w.rows.slice(0,Je.versions),S=u.useMemo(()=>At(t.resources,t.resource_groups),[t.resources,t.resource_groups]),I=u.useMemo(()=>xo((t.related_works||[]).map(B=>({id:B.id,title:B.title,relation:B.relation}))),[t.related_works]),T=u.useMemo(()=>{var ie,G,K,de;const B=[],V=(G=(ie=t.authors)==null?void 0:ie[0])==null?void 0:G.dynasty;V&&B.push({label:"成書",value:l(V)});const Y=Oe(t,r.unit.juan);if(Y){const he=(K=t.juan_count)==null?void 0:K.description;B.push({label:"卷帙",value:l(Y),title:he?l(he):void 0})}if(y||c.length<=Je.versions){const he=w.allRows.map(pe=>pe.year).filter(pe=>pe!=null);if(he.length>0){const pe=Math.min(...he),le=w.allRows.find(ve=>ve.year===pe);le!=null&&le.era.era&&B.push({label:"最早存世刻本",value:`${le.era.era}${le.era.reign?" "+le.era.reign:""}`,title:le.era.source==="edition"?"據版本題名推斷":void 0})}}return(de=t.indexed_by)!=null&&de.length&&B.push({label:"著錄",value:`${t.indexed_by.length} ${r.unit.bu}`}),B},[t,l,r,w.allRows,y,c.length]),C=c.length===0&&S.buckets.length===0&&S.mirrors.length===0&&!((b=t.indexed_by)!=null&&b.length)&&!((R=t.emendated_by)!=null&&R.length)&&I.length===0&&!((E=t.description)!=null&&E.text);return e.jsxs(e.Fragment,{children:[e.jsxs(vt,{facts:T.length?e.jsx(jt,{items:T}):void 0,children:[((A=t.description)==null?void 0:A.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Le,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(M=t.description.sources)!=null&&M.length?e.jsx("div",{className:"bim-d-ui",style:{marginTop:8,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:t.description.sources.map(B=>l(B)).join(" · ")}):null]}),(P=t.appendix)==null?void 0:P.map((B,V)=>e.jsxs("details",{style:{marginTop:12},children:[e.jsx("summary",{className:"bim-d-ui",style:{cursor:"pointer",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #e0d6c0)",display:"inline-block"},children:l(B.title)}),e.jsx(Le,{text:B.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},V)),e.jsx(Eo,{rows:[{label:r.section.aliases,items:ht(t.additional_titles)},{label:r.section.attachedTexts,items:ht(t.attached_texts)},{label:r.section.appendix,items:(t.additional_works||[]).map(B=>B.book_title+(B.n_juan!=null?` ${B.n_juan}${r.unit.juan}`:""))}]})]}),c.length>0&&e.jsxs(Te,{children:[e.jsx(ue,{glyph:"版",title:r.section.relatedVersions,count:w.rows.length===w.allRows.length?`${w.allRows.length} 種`:`${w.allRows.length} 種 · 當前 ${w.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(Ae,{label:"僅看有影印",active:h,dashed:!0,onClick:()=>{v(B=>!B),f(!1)}}),e.jsx(Mt,{label:m==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>j(B=>B==="default"?"year":"default")})]})}),w.allRows.length>=6&&w.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(Ae,{label:r.catalog.all,active:!g,onClick:()=>{x(""),f(!1)}}),w.eras.map(B=>e.jsx(Ae,{label:B,active:g===B,onClick:()=>{x(B),f(!1)}},B))]}),e.jsxs(Ne,{children:[e.jsx(Pt,{spec:Lo}),z.map((B,V)=>e.jsx(na,{row:B,no:V,onNavigate:i,renderLink:o},B.id)),z.length===0&&e.jsx(Qe,{children:g||h?"當前篩選下沒有版本":"暫無版本著錄"})]}),w.rows.length>z.length&&e.jsx(Me,{label:`展開其餘 ${w.rows.length-z.length} 種版本`,onClick:()=>f(!0)}),w.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(S.buckets.length>0||S.mirrors.length>0)&&e.jsxs(Te,{children:[e.jsx(ue,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[S.mirrors.map(B=>e.jsx(en,{title:l(B.label),tag:B.description?l(B.description):void 0,children:B.items.map((V,Y)=>e.jsx(Ze,{item:V,siblings:B.items},`${V.id||V.url||V.name}-${Y}`))},B.key)),S.buckets.map(B=>e.jsx(en,{title:ea[B.key],tag:ta[B.key],children:B.items.map((V,Y)=>e.jsx(Ze,{item:V,siblings:B.items},`${V.id||V.url||V.name}-${Y}`))},B.key))]})]}),($=t.indexed_by)!=null&&$.length||(F=t.emendated_by)!=null&&F.length?e.jsxs("div",{className:(Q=t.emendated_by)!=null&&Q.length?"bim-d-pair":void 0,style:(W=t.emendated_by)!=null&&W.length?void 0:{marginBottom:48},children:[(U=t.indexed_by)!=null&&U.length?e.jsx(ui,{id:"catalogs",glyph:"目",title:r.section.indexed,items:t.indexed_by,unit:r.unit.bu,cap:Je.catalogs,showMeta:!0,t:r,convert:l,onNavigate:i,renderLink:o}):null,(ne=t.emendated_by)!=null&&ne.length?e.jsx(ui,{id:"studies",glyph:"考",title:r.section.emendated,items:t.emendated_by,unit:r.unit.bu,cap:Je.catalogs,t:r,convert:l,onNavigate:i,renderLink:o}):null]}):null,I.map(B=>e.jsx(ia,{glyph:B.key==="derivative"?"續":"叢",title:r.section[B.labelKey]??r.section.relatedWorks,items:B.items,convert:l,onNavigate:i,renderLink:o},B.key)),C&&e.jsxs(Te,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:r.section.relatedVersions}),e.jsx(Ne,{children:e.jsx(Qe,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},ea={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},ta={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function na({row:t,no:n,onNavigate:i,renderLink:o}){const{convert:s}=D(),r=[t.era.era,t.era.reign].filter(Boolean).join(" · "),l=t.era.source==="edition";return e.jsx(Ht,{no:Dt(n),spec:Lo,main:e.jsx(we,{id:t.id,label:s(t.name),onNavigate:i,renderLink:o,dense:!0,style:{fontWeight:t.important?600:400}}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)",letterSpacing:".04em"},title:l?"據版本題名推斷":void 0,children:r||e.jsx(Xe,{})}),e.jsx(pi,{items:t.images,convert:s}),e.jsx(pi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function pi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(Xe,{});if(t.length===1){const l=t[0],c=(l.url?gt(l.url):void 0)||n(l.name),a=Bt(l);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:a?e.jsx(tn,{href:a,children:c}):c})}const o=t[0],s=(o.url?gt(o.url):void 0)||n(o.name),r=Bt(o);return e.jsxs("span",{style:{minWidth:0},children:[r?e.jsx(tn,{href:r,children:s}):s,e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:4,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:["+",t.length-1]})]})}function ui({id:t,glyph:n,title:i,items:o,unit:s,cap:r,showMeta:l,t:c,convert:a,onNavigate:d,renderLink:p}){const[f,g]=u.useState({}),[x,h]=u.useState(!1),v=o.length>0&&o.every((y,k)=>f[k]),m=u.useCallback(()=>{g(v?{}:Object.fromEntries(o.map((y,k)=>[k,!0])))},[v,o]),j=x?o:o.slice(0,r);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(ue,{glyph:n,tone:"ink",title:i,count:`${o.length} ${s}`,actions:e.jsx(Mt,{label:v?"收起全部":"+ 展開提要",onClick:m})}),e.jsx(Ne,{children:j.map((y,k)=>{const _=y;return e.jsxs(zo,{open:!!f[k],onToggle:()=>g(w=>({...w,[k]:!w[k]})),main:e.jsxs(e.Fragment,{children:[_.source_bid?e.jsx(we,{id:_.source_bid,label:a(_.source),onNavigate:d,renderLink:p,dense:!0}):a(_.source),l&&_.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(_.section)})]}),action:_.source_bid?e.jsx(we,{id:_.source_bid,label:c.action.view,onNavigate:d,renderLink:p,dense:!0,style:{fontFamily:"var(--bim-font-ui, system-ui, sans-serif)",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"}}):void 0,children:[l&&(_.title_info||_.author_info||_.edition)&&e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:"4px 16px",marginBottom:8,fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:[_.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",a(_.title_info)]}),_.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",a(_.author_info)]}),_.edition&&e.jsxs("span",{children:[c.label.edition," ",a(_.edition)]})]}),_.summary&&e.jsx(Rt,{children:a(_.summary)}),_.comment&&e.jsx(Rt,{label:c.section.comment,children:a(_.comment)}),_.additional_comment&&e.jsx(Rt,{label:c.section.additionalComment,children:a(_.additional_comment)}),l&&_.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:_.page})]},k)})}),o.length>j.length&&e.jsx(Me,{label:`展開其餘 ${o.length-j.length} ${s}`,onClick:()=>h(!0)})]})}function ia({glyph:t,title:n,items:i,convert:o,onNavigate:s,renderLink:r}){const[l,c]=u.useState(!1),a=l?i:i.slice(0,Je.chips);return e.jsxs(Te,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Ft,{children:[a.map(d=>e.jsx(St,{children:e.jsx(we,{id:d.id,label:o(d.title),onNavigate:s,renderLink:r,dense:!0,style:{color:"inherit"}})},d.id)),i.length>a.length&&e.jsx(Me,{inline:!0,label:`更多 ${i.length-a.length} 種`,onClick:()=>c(!0)})]})]})}const oa=8,$o=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var k,_,w,z;const s=O(),{convert:r}=D(),[l,c]=u.useState(null),[a,d]=u.useState(new Map),[p,f]=u.useState([]),[g,x]=u.useState(!1);u.useEffect(()=>{if(!n||!t.work_id){c(null);return}let S=!1;return n.getItem(t.work_id).then(I=>{!S&&I&&I.type==="work"&&c(I)}).catch(()=>{}),()=>{S=!0}},[n,t.work_id]),u.useEffect(()=>{const S=t.contained_in||[];if(!n||S.length===0){d(new Map);return}let I=!1;return Promise.all(S.map(T=>{const C=typeof T=="string"?T:T.id;return n.getItem(C).then(b=>[C,b]).catch(()=>[C,null])})).then(T=>{if(I)return;const C=new Map;for(const[b,R]of T)R&&C.set(b,R);d(C)}),()=>{I=!0}},[n,t.contained_in]);const h=u.useMemo(()=>{const S=new Set([...(l==null?void 0:l.books)||[],...t.related_books||[]]);return S.delete(t.id),[...S]},[l==null?void 0:l.books,t.related_books,t.id]);u.useEffect(()=>{if(!n||h.length===0){f([]);return}const S=g?h:h.slice(0,oa);let I=!1;return Promise.all(S.map(T=>n.getItem(T).then(C=>({id:T,title:C==null?void 0:C.title,edition:C==null?void 0:C.edition})).catch(()=>({id:T})))).then(T=>{I||f(T)}),()=>{I=!0}},[n,h,g]);const v=u.useMemo(()=>At(t.resources,t.resource_groups),[t.resources,t.resource_groups]),m=u.useMemo(()=>{var E,A,M;const S=[],I=mn(t),T=jo(t);T&&S.push({label:"版本類型",value:T,title:(E=t.lineage)!=null&&E.category?void 0:"據版本題名推斷"}),(I.era||I.reign)&&S.push({label:"刊寫年代",value:[I.era,I.reign].filter(Boolean).join(" "),title:I.source==="edition"?"據版本題名推斷":void 0});const C=(t.contained_in||[]).flatMap(P=>typeof P=="string"?[]:ft(P.volume_index));C.length&&(S.push({label:"冊數",value:`${C.length} ${s.unit.volume}`}),S.push({label:"冊次",value:`第 ${yn(C,s.unit.volume)} ${s.unit.volume}`}));const b=Oe(t,s.unit.juan);b&&S.push({label:"卷帙",value:r(b)});const R=(t.resources||[]).filter(P=>(P.types||(P.type?[P.type]:[])).includes("physical"));return R.length?S.push({label:"存藏",value:R.slice(0,2).map(P=>r(P.name)).join("、")+(R.length>2?` 等 ${R.length} 處`:"")}):(A=t.current_location)!=null&&A.name&&S.push({label:"存藏",value:r(t.current_location.name)}),(M=t.page_count)!=null&&M.description&&S.push({label:s.label.pageCount,value:t.page_count.description}),S},[t,r,s]),j=!!((k=t.description)!=null&&k.text),y=(t.contained_in||[]).some(S=>typeof S!="string"&&ft(S.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(vt,{facts:m.length?e.jsx(jt,{items:m,horizontal:!j}):void 0,children:j?e.jsx(Le,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),(t.contained_in||[]).length>0&&e.jsxs(Te,{children:[e.jsx(ue,{glyph:"收",title:s.section.containedIn}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",borderBottom:"1px solid var(--bim-rule, #eae2d0)",padding:"14px 4px",display:"flex",flexDirection:"column",gap:12},children:(t.contained_in||[]).map((S,I)=>{var E,A;const T=typeof S=="string"?S:S.id,C=typeof S=="string"?[]:ft(S.volume_index),b=a.get(T),R=((E=b==null?void 0:b.books)==null?void 0:E.length)||((A=b==null?void 0:b.contained_works)==null?void 0:A.length)||0;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",justifyContent:"space-between",gap:"8px 16px",marginBottom:12},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(we,{id:T,label:b?r(b.title):T,onNavigate:i,renderLink:o})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[R>0&&`全 ${R} ${s.unit.bu}`,R>0&&C.length>0&&" · ",C.length>0&&`本書佔 ${C.length} ${s.unit.volume}`]})]}),C.length>0&&e.jsx(Io,{volumes:C,unit:s.unit.volume})]},`${T}-${I}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[l&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"作",tone:"ink",title:s.section.belongsToWork}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)",padding:"12px 4px 0"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"6px 12px",marginBottom:10},children:[e.jsx("span",{style:{fontSize:16},children:e.jsx(we,{id:l.id,label:r(l.title),onNavigate:i,renderLink:o})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[r(Oe(l,s.unit.juan)),(_=l.authors)==null?void 0:_.map(S=>{const I=ho(S.role);return`${S.dynasty?`〔${r(S.dynasty)}〕`:""}${r(S.name)}${I?" "+r(I):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((w=l.description)==null?void 0:w.text)&&e.jsx(Le,{text:l.description.text,style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)",textAlign:"justify"}}),e.jsx("div",{style:{marginTop:14},children:e.jsx(jn,{label:s.section.aliases,items:[...ht(t.additional_titles),...ht(t.attached_texts)]})})]})]}),(v.buckets.length>0||v.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsxs("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[v.mirrors.map(S=>e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{className:"bim-d-ui",style:{padding:"8px 4px 4px",fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r(S.label)}),S.items.map((I,T)=>e.jsx(Ze,{item:I,showVolumes:!y},`${I.id||I.url||I.name}-${T}`))]},S.key)),v.buckets.flatMap(S=>S.items).map((S,I)=>e.jsx(Ze,{item:S,showVolumes:!y},`${S.id||S.url||S.name}-${I}`))]})]})]}),(z=t.location_history)!=null&&z.length?e.jsxs(Te,{children:[e.jsx(ue,{glyph:"藏",tone:"ink",title:s.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((S,I)=>e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px 12px",padding:"9px 4px",fontSize:14,borderBottom:"1px solid var(--bim-rule, #eae2d0)"},children:[e.jsx("span",{children:r(S.name)}),S.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r(S.description)})]},I))})]}):null,h.length>0&&e.jsxs(Te,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"版",tone:"ink",title:s.relation.siblingVersions,count:`${h.length} 種`,actions:l?e.jsx(we,{id:l.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:o,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Ft,{children:[p.map(S=>e.jsx(St,{children:e.jsx(we,{id:S.id,label:r(S.edition||S.title||S.id),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},S.id)),h.length>p.length&&e.jsx(Me,{inline:!0,label:`更多 ${h.length-p.length} 種`,onClick:()=>x(!0)})]})]})]})},xi={titles:16,works:16},Ao=({data:t,catalog:n,onNavigate:i,renderLink:o,catalogAction:s})=>{var T,C;const r=O(),{convert:l}=D(),[c,a]=u.useState(""),[d,p]=u.useState(!1),[f,g]=u.useState(!1),x=u.useMemo(()=>yo(t,n),[t,n]),h=u.useMemo(()=>c?x.rows.filter(b=>b.section===c):x.rows,[x.rows,c]),v=d?h:h.slice(0,xi.titles),m=u.useMemo(()=>At(t.resources,t.resource_groups),[t.resources,t.resource_groups]),j=t.contained_works||[],y=new Set(x.rows.map(b=>b.id).filter(Boolean)),k=j.length>0&&!j.every(b=>y.has(b.id)),_=(()=>{const b=x.rows.map(R=>R.edition).filter(Boolean);return b.length>1&&new Set(b).size===1})(),w=f?j:j.slice(0,xi.works),z=x.sections.length>0,S=u.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...z?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[z]),I=u.useMemo(()=>{var A,M,P,$;const b=[];t.subtype&&b.push({label:r.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(A=t.publication_info)!=null&&A.details&&b.push({label:"刊印",value:l(t.publication_info.details)}),(M=t.publication_info)!=null&&M.year&&b.push({label:"年代",value:t.publication_info.year});const R=((P=t.books)==null?void 0:P.length)||j.length,E=Oe(t,r.unit.juan);return(R||E)&&b.push({label:"種數 / 卷數",value:[R?`${R} ${r.unit.bu}`:"",l(E)].filter(Boolean).join(" · "),title:($=t.juan_count)!=null&&$.description?l(t.juan_count.description):void 0}),x.totalVolumes&&b.push({label:"全帙冊數",value:`${x.totalVolumes} ${r.unit.volume}`}),b},[t,j.length,x.totalVolumes,l,r]);return e.jsxs(e.Fragment,{children:[e.jsxs(vt,{facts:I.length?e.jsx(jt,{items:I}):void 0,children:[((T=t.description)==null?void 0:T.text)&&e.jsx(Le,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(C=t.history)!=null&&C.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((b,R)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",l(b)]},R))}):null]}),x.rows.length>0&&e.jsxs(Te,{children:[e.jsx(ue,{glyph:"目",title:r.section.containedBooks,count:h.length===x.rows.length?`${r.catalog.contains} ${x.rows.length} ${r.unit.items}`:`${x.rows.length} ${r.unit.items} · 當前 ${h.length} ${r.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,z&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:r.catalog.all,active:!c,onClick:()=>{a(""),p(!1)}}),x.sections.map(b=>e.jsx(Ae,{label:b,active:c===b,onClick:()=>{a(b),p(!1)}},b))]})]})}),e.jsxs(Ne,{children:[e.jsx(Pt,{spec:S}),v.map((b,R)=>{var E;return e.jsx(Ht,{no:Dt(R),spec:S,main:e.jsxs(e.Fragment,{children:[b.id?e.jsx(we,{id:b.id,label:l(b.title),onNavigate:i,renderLink:o,dense:!0}):e.jsx("span",{children:l(b.title)}),(E=b.subItems)!=null&&E.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",b.subItems.map(A=>l(A)).join("、"),")"]}):null,b.edition&&!_&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(b.edition)})]}),meta:e.jsxs(e.Fragment,{children:[z&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:b.section?b.section.endsWith("部")?b.section:`${b.section}部`:e.jsx(Xe,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:b.volumes.length>0?`第 ${yn(b.volumes,r.unit.volume)} ${r.unit.volume}`:b.expected!=null?`${b.found??0}/${b.expected} ${r.unit.volume}`:e.jsx(Xe,{})})]})},`${b.id??b.title}-${R}`)}),v.length===0&&e.jsx(Qe,{children:r.catalog.noMatch})]}),h.length>v.length&&e.jsx(Me,{label:`展開其餘 ${h.length-v.length} ${r.unit.items}子目`,onClick:()=>p(!0)})]}),(m.buckets.length>0||k)&&e.jsxs("div",{className:"bim-d-pair bim-d-pair-wide",children:[(m.buckets.length>0||m.mirrors.length>0)&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"源",tone:"ink",title:"影印與全文"}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:[...m.mirrors.flatMap(b=>b.items),...m.buckets.flatMap(b=>b.items)].map((b,R)=>e.jsx(Ze,{item:b,fallbackNote:b.details?l(b.details):void 0},`${b.id||b.url||b.name}-${R}`))})]}),k&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:r.section.containedWorks,count:`${j.length} 種`}),e.jsxs(Ft,{children:[w.map(b=>e.jsx(St,{children:e.jsx(we,{id:b.id,label:l(b.title),onNavigate:i,renderLink:o,dense:!0,style:{color:"inherit"}})},b.id)),j.length>w.length&&e.jsx(Me,{inline:!0,label:`更多 ${j.length-w.length} 種`,onClick:()=>g(!0)})]})]})]})]})},ra=16,fi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},Kt=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function gi(t){if(!t)return Kt.length;const n=Kt.indexOf(t);return n===-1?Kt.length:n}const Mo=({data:t,transport:n,onNavigate:i,renderLink:o})=>{var S,I,T;const s=O(),{convert:r}=D(),[l,c]=u.useState("全部"),[a,d]=u.useState(!1),[p,f]=u.useState("default"),[g,x]=u.useState(new Map),h=u.useMemo(()=>(t.works||[]).map(b=>{const R=g.get(b.work_id);return{id:b.work_id,title:(R==null?void 0:R.title)??b.work_id,role:b.role||"",cls:bn(b.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,g]),v=u.useMemo(()=>bo((t.works||[]).map(C=>C.role)),[t.works]),m=u.useMemo(()=>{const C=l==="全部"?h:h.filter(b=>b.cls===l);return p==="versions"?[...C].sort((b,R)=>(R.versionCount??-1)-(b.versionCount??-1)):C},[h,l,p]),j=a?m:m.slice(0,ra),y=u.useMemo(()=>j.filter(C=>!g.has(C.id)).map(C=>C.id),[j,g]);u.useEffect(()=>{if(!n||y.length===0)return;let C=!1;return Promise.all(y.map(b=>n.getItem(b).then(R=>{var M,P;const E=R??{},A=(((M=E.books)==null?void 0:M.length)??0)+(((P=E.collections)==null?void 0:P.length)??0);return[b,{id:b,title:E.title,versionCount:A,loaded:!0}]}).catch(()=>[b,{id:b,loaded:!0}]))).then(b=>{C||x(R=>{const E=new Map(R);for(const[A,M]of b)E.set(A,M);return E})}),()=>{C=!0}},[n,y]);const k=u.useMemo(()=>{const C=new Map;for(const b of t.alt_names||[]){const R=b.type||s.section.aliases;C.has(R)||C.set(R,[]),C.get(R).push(b.name)}return[...C.entries()].sort((b,R)=>gi(b[0])-gi(R[0])).map(([b,R])=>({label:b,names:R}))},[t.alt_names,s]),_=u.useMemo(()=>{const C=[];t.dynasty&&C.push({label:"時代",value:r(t.dynasty)});const b=E=>E==null?"":E<0?`前${-E}`:String(E);(t.birth_year!=null||t.death_year!=null)&&C.push({label:"生卒",value:`${b(t.birth_year)||"?"}—${b(t.death_year)||"?"}`});const R=(t.works||[]).length;return R&&C.push({label:"著作數",value:`${R} 種`}),C},[t,r]),w=(S=t.external_ids)==null?void 0:S.cbdb_id,z=!!((I=t.description)!=null&&I.text);return e.jsxs(e.Fragment,{children:[e.jsx(vt,{facts:_.length?e.jsx(jt,{items:_}):void 0,children:(k.length>0||z)&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[k.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:k.map(C=>e.jsxs("span",{style:{display:"flex",alignItems:"baseline",gap:8,minWidth:0},children:[e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)",letterSpacing:".1em",flex:"none"},children:r(C.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:C.names.map(b=>r(b)).join(" · ")})]},C.label))}),z&&e.jsx(Le,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),h.length===0&&e.jsxs(Te,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks}),e.jsx(Ne,{children:e.jsx(Qe,{children:"尚未著錄該人物的關聯作品。"})})]}),h.length>0&&e.jsxs(Te,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks,count:m.length===h.length?`${h.length} 種`:`${h.length} 種 · 當前 ${m.length} 種`,actions:e.jsx(Mt,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{f(C=>(C==="default"&&d(!0),C==="default"?"versions":"default"))}})}),v.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:v.map(C=>e.jsx(Ae,{label:`${C.label} ${C.count}`,active:l===C.cls,onClick:()=>{c(C.cls),d(!1)}},C.cls))}),e.jsxs(Ne,{children:[e.jsx(Pt,{spec:fi}),j.map((C,b)=>e.jsx(Ht,{no:Dt(b),spec:fi,main:e.jsx(we,{id:C.id,label:r(C.title),onNavigate:i,renderLink:o,dense:!0}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:C.role?r(C.role):e.jsx(Xe,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:C.loaded?C.versionCount?`${C.versionCount} 種版本`:e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},C.id)),j.length===0&&e.jsx(Qe,{children:"該職任下的著作尚未著錄。"})]}),m.length>j.length&&e.jsx(Me,{label:`展開其餘 ${m.length-j.length} 條著作`,onClick:()=>d(!0)}),w!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",w,((T=t.external_ids)==null?void 0:T.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function sa(t){var n;return{id:t.id,kind:"hypothetical",label:t.label,year:t.year??((n=t.year_range)==null?void 0:n[0]),year_range:t.year_range,year_uncertain:t.year_uncertain,group:t.group,note:t.note,description:t.description}}function la(t,n){if(!t.lineage)return null;const i=t.lineage;return{id:t.id,kind:"book",label:t.title,year:i.year,year_text:i.year_text,year_uncertain:i.year_uncertain,category:i.category,status:i.status,extant_juan:i.extant_juan,group:n[t.id],note:i.note}}function mi(t,n,i){return{id:`derive:${n.ref}->${t}:${i}`,source:n.ref,target:t,kind:"derive",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function aa(t,n,i){const[o,s]=[t,n.book_id].sort();return{id:`sibling:${o}-${s}:${i}`,source:o,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function ca(t,n){var d;if(n==="all")return null;const i=(d=t.collections)==null?void 0:d[n],o=Array.isArray(i==null?void 0:i.groups)&&i.groups.length>0,s=Array.isArray(i==null?void 0:i.book_ids)&&i.book_ids.length>0,r=o||s||!!(i!=null&&i.hypothetical_ids);if(!r&&n==="core"&&Array.isArray(t.core_books)&&t.core_books.length>0)return{books:new Set(t.core_books),hypos:t.core_hypotheticals?new Set(t.core_hypotheticals):null};if(!i||!r)return null;const l=o?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(l&&t.node_groups)for(const[p,f]of Object.entries(t.node_groups))l.has(f)&&c.add(p);let a=null;if(i.hypothetical_ids&&(a=new Set(i.hypothetical_ids)),l){a||(a=new Set);for(const p of t.hypothetical_nodes??[])p.group&&l.has(p.group)&&a.add(p.id)}return{books:c,hypos:a}}function Et(t,n,i){const o=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!o||!o.enabled)return s;const r=new Set(o.excluded_books??[]),l=o.node_groups??{},c=ca(o,i??o.default_collection??"all"),a=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,f=new Set,g=new Set;if(a){const _=new Map(n.map(C=>[C.id,C])),w=new Map((o.hypothetical_nodes??[]).map(C=>[C.id,C])),z=C=>{const b=_.get(C);if(b&&b.lineage)return(b.lineage.derived_from??[]).map(E=>E.ref);const R=w.get(C);return R?(R.derived_from??[]).map(E=>E.ref):[]},S=C=>w.has(C)?!p||p.has(C):!d||d.has(C),I=new Set,T=C=>{if(!I.has(C)){I.add(C);for(const b of z(C))r.has(b)||(S(b)||(w.has(b)?g.add(b):_.has(b)&&f.add(b)),T(b))}};for(const C of n)d&&d.has(C.id)&&!r.has(C.id)&&T(C.id);for(const C of o.hypothetical_nodes??[])p&&p.has(C.id)&&T(C.id)}const x=n.filter(_=>!r.has(_.id)).filter(_=>!d||d.has(_.id)||f.has(_.id)).map(_=>{const w=la(_,l);return w&&f.has(_.id)&&(w.bridge=!0),w}).filter(_=>_!==null),h=(o.hypothetical_nodes??[]).filter(_=>!p||p.has(_.id)||g.has(_.id)).map(_=>{const w=sa(_);return g.has(_.id)&&(w.bridge=!0),w}),v=[...x,...h],m=new Set(v.map(_=>_.id)),j=new Set,y=[],k=_=>{j.has(_.id)||!m.has(_.source)||!m.has(_.target)||(j.add(_.id),y.push(_))};for(const _ of n)r.has(_.id)||!_.lineage||d&&!d.has(_.id)&&!f.has(_.id)||((_.lineage.derived_from??[]).forEach((w,z)=>{k(mi(_.id,w,z))}),(_.lineage.related_to??[]).forEach((w,z)=>{k(aa(_.id,w,z))}));for(const _ of o.hypothetical_nodes??[])p&&!p.has(_.id)&&!g.has(_.id)||(_.derived_from??[]).forEach((w,z)=>{k(mi(_.id,w,z))});return{nodes:v,edges:y,groups:o.groups??[],title:o.title,description:o.description,layout:o.layout??"LR",excluded:Array.from(r)}}function Fo(t,n,i){const o=(t??(n!=null?String(n):"")).trim();return o?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(o)?o:`约 ${o}`:""}function da(t,n){const i=[],o=t.version_graph;if(!o)return i;const s=new Set(n.map(a=>a.id)),r=new Set((o.hypothetical_nodes??[]).map(a=>a.id)),l=new Set([...s,...r]),c=(a,d)=>{l.has(d.ref)||i.push(`${a}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!r.has(d.ref)&&i.push(`${a}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const a of n){if(!a.lineage)continue;const d=`Book ${a.id} (${a.title})`;(a.lineage.derived_from??[]).forEach(p=>c(d,p)),(a.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const a of o.hypothetical_nodes??[]){const d=`Hypothetical ${a.id} (${a.label})`;(a.derived_from??[]).forEach(p=>c(d,p))}return i}const Po=({graph:t,renderLink:n,className:i,style:o})=>{const{convert:s}=D();if(!t.nodes.length)return e.jsx("div",{style:{...wa,...o},className:i,children:"暂无版本图数据"});const r=new Map,l=new Map;for(const g of t.edges)if(g.kind==="derive"){const x=r.get(g.target)??[];x.push(g),r.set(g.target,x)}else for(const x of[g.source,g.target]){const h=l.get(x)??[];h.push(g),l.set(x,h)}const c=new Map(t.nodes.map(g=>[g.id,g])),a=new Map,d=[];for(const g of t.nodes)if(g.group){const x=a.get(g.group)??[];x.push(g),a.set(g.group,x)}else d.push(g);const p=(g,x)=>(g.year??9999)-(x.year??9999);a.forEach(g=>g.sort(p)),d.sort(p);const f=t.groups.filter(g=>a.has(g.id));return e.jsxs("div",{className:i,style:{...ua,...o},children:[t.title&&e.jsx("div",{style:xa,children:s(t.title)}),t.description&&e.jsx("div",{style:fa,children:s(t.description)}),f.map(g=>e.jsx(hi,{label:g.label,color:g.color,nodes:a.get(g.id),incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx(hi,{label:"其他",nodes:d,incomingMap:r,siblingMap:l,nodeMap:c,renderLink:n})]})},hi=({label:t,color:n,nodes:i,incomingMap:o,siblingMap:s,nodeMap:r,renderLink:l})=>{const{convert:c}=D();return e.jsxs("div",{style:ga,children:[e.jsx("div",{style:{...ma,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(a=>e.jsx(pa,{node:a,incoming:o.get(a.id)??[],siblings:s.get(a.id)??[],nodeMap:r,renderLink:l},a.id))]})},pa=({node:t,incoming:n,siblings:i,nodeMap:o,renderLink:s})=>{const r=t.kind==="hypothetical",l=t.bridge,{convert:c}=D();return e.jsxs("div",{style:{...ha,borderStyle:r||l?"dashed":"solid",opacity:l?.55:t.status==="lost"?.7:1,background:l?"var(--bim-bg-subtle, #fafafa)":void 0},title:l?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:ba,children:[e.jsx("span",{style:ya,children:r||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:va,children:Fo(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:ja,children:[t.category&&e.jsx(lt,{children:c(t.category)}),t.status==="lost"&&e.jsx(lt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(lt,{tone:"warn",children:"残本"}),r&&e.jsx(lt,{tone:"info",children:"假想祖本"}),l&&e.jsx(lt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Sa,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:ka,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:yi,children:[e.jsx("div",{style:vi,children:"来源:"}),n.map(a=>{const d=o.get(a.source);return e.jsxs("div",{style:ji(a.confidence),children:[e.jsx("span",{style:Si,children:c(a.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??a.source)}),a.confidence!=="consensus"&&a.confidence!=="certain"&&e.jsx(bi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:ki,children:["· ",c(a.evidence)]})]},a.id)})]}),i.length>0&&e.jsxs("div",{style:yi,children:[e.jsx("div",{style:vi,children:"关联:"}),i.map(a=>{const d=a.source===t.id?a.target:a.source,p=o.get(d);return e.jsxs("div",{style:ji(a.confidence),children:[e.jsx("span",{style:Si,children:c(a.relation)}),e.jsx("span",{children:(p==null?void 0:p.kind)==="book"&&s?s(p.id,c(p.label)):c((p==null?void 0:p.label)??d)}),e.jsx(bi,{level:a.confidence}),a.evidence&&e.jsxs("span",{style:ki,children:["· ",c(a.evidence)]})]},a.id)})]})]})},lt=({children:t,tone:n="default"})=>{const o={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:o.bg,color:o.fg,marginRight:"4px"},children:t})},bi=({level:t})=>{const i={certain:{label:"确定",color:"var(--bim-confidence-certain, #2e7d32)"},consensus:{label:"共识",color:"var(--bim-confidence-consensus, #1976d2)"},probable:{label:"推测",color:"var(--bim-confidence-probable, #ed6c02)"},disputed:{label:"有争议",color:"var(--bim-confidence-disputed, #c62828)"}}[t];return i?e.jsx("span",{style:{display:"inline-block",padding:"0 6px",fontSize:"10px",border:`1px solid ${i.color}`,color:i.color,borderRadius:"8px",marginLeft:"4px"},children:i.label}):null},ua={fontSize:"14px",color:"var(--bim-fg, #333)"},xa={fontSize:"16px",fontWeight:600,marginBottom:"8px"},fa={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},ga={marginBottom:"16px"},ma={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},ha={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},ba={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},ya={fontSize:"15px",fontWeight:600},va={fontSize:"12px",color:"var(--bim-muted, #777)"},ja={marginBottom:"6px"},Sa={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},ka={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},yi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},vi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},ji=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Si={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},ki={fontSize:"11px",color:"var(--bim-muted, #888)"},wa={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},Ho=({selectedNodeId:t,...n})=>{const[i,o]=u.useState("loading"),[s,r]=u.useState(null);return u.useEffect(()=>{let l=!1;return _a().then(c=>{l||(c?(r(c),o("ready")):o("missing"))}),()=>{l=!0}},[]),i==="loading"?e.jsx("div",{style:wi,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:wi,children:[e.jsxs("div",{children:["图组件未安装。请安装 ",e.jsx("code",{children:"@xyflow/react"})," 与 ",e.jsx("code",{children:"@dagrejs/dagre"}),"。"]}),e.jsxs("div",{style:{fontSize:"12px",marginTop:"4px"},children:["或使用 ",e.jsx("code",{children:"VersionLineageList"})," 列表视图。"]})]}):e.jsx(Ca,{modules:s,selectedNodeId:t,...n})};async function _a(){try{const[t,n]=await Promise.all([import("@xyflow/react"),import("@dagrejs/dagre")]);let i=!1;try{await import("@xyflow/react/dist/style.css"),i=!0}catch{i=!1}return{ReactFlow:t.ReactFlow,Background:t.Background,Controls:t.Controls,Handle:t.Handle,Position:t.Position,BaseEdge:t.BaseEdge,EdgeLabelRenderer:t.EdgeLabelRenderer,getSmoothStepPath:t.getSmoothStepPath,dagre:n,cssLoaded:i}}catch{return null}}const Ca=({graph:t,renderLink:n,height:i=600,className:o,style:s,selectedNodeId:r,modules:l})=>{const{ReactFlow:c,Background:a,Controls:d,Handle:p,Position:f,BaseEdge:g,EdgeLabelRenderer:x,getSmoothStepPath:h,dagre:v}=l,m=u.useMemo(()=>({lineage:z=>{var P,$,F,Q;const S=((P=z.data)==null?void 0:P.stepPosition)??.85,[I,T,C]=h({sourceX:z.sourceX,sourceY:z.sourceY,sourcePosition:z.sourcePosition,targetX:z.targetX,targetY:z.targetY,targetPosition:z.targetPosition,stepPosition:S,borderRadius:5}),b=!!(($=z.data)!=null&&$.isSibling),R=b?T:z.targetX-18,E=b?C:z.targetY-12,A=(F=z.data)==null?void 0:F.labelStyle,M=(Q=z.data)==null?void 0:Q.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:z.id,path:I,style:z.style,markerStart:z.markerStart,markerEnd:z.markerEnd}),z.label&&e.jsx(x,{children:e.jsx("div",{style:{position:"absolute",transform:`translate(-50%, -50%) translate(${R}px,${E}px)`,pointerEvents:"none",padding:"2px 6px",borderRadius:4,fontSize:11,fontWeight:500,whiteSpace:"nowrap",background:"var(--bim-bg, #fff)",border:"0.5px solid var(--bim-widget-border, #ddd)",...M,...A},children:z.label})})]})}}),[g,x,h]),j=u.useMemo(()=>({version:z=>{const S=z.data,I=S.kind==="hypothetical",T=S.status==="lost",C=S.isSelected,b=S.bridge,R=S.borderColor??"var(--bim-muted, #888)",E=b||I?"dashed":"solid",A=b?.5:T?.6:1;return e.jsxs("div",{style:{background:b?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${E} ${C?"var(--bim-primary, #0078d4)":R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:A,boxShadow:C?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":I||b?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:b?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(p,{type:"target",position:f.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:I||!S.renderLink?S.label:S.renderLink(S.bookId,S.label)}),S.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:S.description}),S.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:Fo(S.yearText,void 0,S.uncertain)}),T&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(p,{type:"source",position:f.Right,style:{visibility:"hidden"}})]})}}),[p,f]),{convert:y}=D(),{rfNodes:k,rfEdges:_}=u.useMemo(()=>Ia(t,v,n,r,y),[t,v,n,r,y]);return e.jsx("div",{style:{width:"100%",height:i,...s},className:o,children:e.jsxs(c,{nodes:k,edges:_,nodeTypes:j,edgeTypes:m,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(a,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function Ia(t,n,i,o,s=r=>r??""){const c=t.layout==="LR"||!t.layout,a=new n.graphlib.Graph;a.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),a.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(j=>[j.id,j.color??"var(--bim-muted, #888)"]));for(const j of t.nodes)a.setNode(j.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const j of t.edges)j.kind==="derive"&&(p.has(j.relation)||a.setEdge(j.source,j.target));n.layout(a);const f=t.nodes.map(j=>{const y=a.node(j.id),k=o&&j.id===o,_={kind:j.kind,label:s(j.label),bookId:j.kind==="book"?j.id:void 0,yearText:s(j.year_text??Ta(j)),uncertain:j.year_uncertain,category:j.category,status:j.status,borderColor:j.group?d.get(j.group):void 0,renderLink:i,isSelected:k,description:s(j.description),bridge:j.bridge};return{id:j.id,type:"version",position:{x:y.x-160/2,y:y.y-90/2},data:_,draggable:!1,selected:k}}),g=.78,x=.06,h=new Map;for(const j of t.edges)j.kind==="derive"&&(h.has(j.source)||h.set(j.source,[]),h.get(j.source).push(j));const v=new Map;for(const[j,y]of h){if(y.length<=1)continue;const k=[...y].sort((w,z)=>{var T,C;const S=((T=a.node(w.target))==null?void 0:T.y)??0,I=((C=a.node(z.target))==null?void 0:C.y)??0;return S-I}),_=k.length;k.forEach((w,z)=>{const S=(z-(_-1)/2)*x;v.set(w.id,g+S)})}const m=t.edges.map(j=>za(j,v.get(j.id),s));return{rfNodes:f,rfEdges:m}}function za(t,n,i=o=>o??""){const o=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",r=Ra(t.confidence),l={type:"arrowclosed",color:r,width:14,height:14};return{id:t.id,source:t.source,target:t.target,type:"lineage",label:i(t.relation),data:{labelStyle:{color:"var(--bim-fg, #444)"},isSibling:s,stepPosition:n},style:{stroke:r,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":o?"6 4":void 0,opacity:o?.75:1},animated:!1,markerEnd:l,markerStart:s?l:void 0,zIndex:1e3}}function Ta(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function Ra(t){switch(t){case"certain":return"var(--bim-confidence-certain, #2e7d32)";case"consensus":return"var(--bim-lineage-edge-consensus, #555)";case"probable":return"var(--bim-confidence-probable, #ed6c02)";case"disputed":return"var(--bim-confidence-disputed, #c62828)";default:return"var(--bim-muted, #888)"}}const wi={padding:"40px 20px",textAlign:"center",color:"var(--bim-muted, #888)",fontSize:"13px",border:"1px dashed var(--bim-widget-border, #ddd)",borderRadius:8,background:"var(--bim-bg, #fafafa)"},Do=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:o=600,selectedNodeId:s,onModeChange:r,collection:l,onCollectionChange:c,collectionsAvailable:a,collectionCounts:d,className:p,style:f})=>{var y;const[g,x]=u.useState(n),h=k=>{x(k),r==null||r(k)},v=(()=>{if(!a)return[];const k=Object.entries(a);return k.length===0||a.all?k:[...k,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),m=!!(c&&v.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const j=l?(y=a==null?void 0:a[l])==null?void 0:y.description:void 0;return e.jsxs("div",{className:p,style:f,children:[e.jsxs("div",{style:Ea,children:[e.jsx("button",{onClick:()=>h("list"),style:Jt(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>h("graph"),style:Jt(g==="graph"),children:"关系图"}),m&&e.jsxs("div",{style:{marginLeft:"auto",marginRight:80,display:"flex",gap:4,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginRight:4},children:"集合:"}),v.map(([k,_])=>{const w=d==null?void 0:d[k];return e.jsxs("button",{onClick:()=>c==null?void 0:c(k),style:Jt(l===k),title:_.description,children:[_.label,w!=null?` ${w}`:""]},k)})]})]}),m&&j&&e.jsx("div",{style:{fontSize:12,color:"var(--bim-muted, #888)",marginBottom:8,padding:"4px 8px",background:"var(--bim-bg-subtle, #fafafa)",borderRadius:4},children:j}),g==="list"?e.jsx(Po,{graph:t,renderLink:i}):e.jsx(Ho,{graph:t,renderLink:i,height:o,selectedNodeId:s})]})},Ea={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},Jt=t=>({padding:"4px 12px",fontSize:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:4,background:t?"var(--bim-primary, #0078d4)":"transparent",color:t?"var(--bim-primary-fg, #fff)":"var(--bim-fg, #333)",cursor:"pointer"}),Oo=({style:t})=>{const n=u.useContext(bt);if(!n)return null;const{locale:i,setLocale:o}=n,s=i==="zh-Hant",r=()=>o(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:r,title:s?"切换为简体":"切換為繁體",style:{display:"inline-flex",alignItems:"center",gap:"2px",padding:"4px 10px",fontSize:"13px",fontWeight:500,lineHeight:1,border:"1px solid var(--bim-border, #ddd)",borderRadius:"4px",background:"var(--bim-bg, #fff)",color:"var(--bim-fg, #333)",cursor:"pointer",userSelect:"none",...t},children:[e.jsx("span",{style:{color:s?"var(--bim-primary, #0078d4)":void 0,fontWeight:s?700:400},children:"繁"}),e.jsx("span",{style:{opacity:.3},children:"/"}),e.jsx("span",{style:{color:s?void 0:"var(--bim-primary, #0078d4)",fontWeight:s?400:700},children:"简"})]})},No=({href:t,label:n="在 GitHub 查看本条目源文件",size:i=16,className:o,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:r=>{r.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:r=>{r.currentTarget.style.color="var(--bim-desc-fg, #717171)"},children:e.jsx("svg",{width:i,height:i,viewBox:"0 0 16 16",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"})})}),Ba=({id:t,transport:n,activeTab:i,onTabChange:o,activeJuan:s,onJuanChange:r,lineageMode:l="list",onLineageModeChange:c,lineageCollection:a,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:f,onNavigate:g,onBack:x,backLabel:h,renderLink:v,enrichDetail:m,getSourceLink:j,extraTabs:y=[],showFeedbackTab:k=!0,feedbackApiUrl:_,height:w,footerExtra:z,className:S,style:I})=>{const T=O(),{convert:C}=D(),[b,R]=u.useState(null),[E,A]=u.useState(null),[M,P]=u.useState(!0),[$,F]=u.useState(!1),[Q,W]=u.useState([]),[U,ne]=u.useState(!1),[B,V]=u.useState(null),[Y,ie]=u.useState(!1),[G,K]=u.useState(null),[de,he]=u.useState(!1),[pe,le]=u.useState(null),[ve,Fe]=u.useState(!1),_e=u.useRef(null),[Ge,tt]=u.useState(null),N=s!==void 0?s:Ge,oe=u.useCallback(H=>{r?r(H):tt(H)},[r]),te=u.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ne(!0);try{if(n.getCollectionCatalogs)W(await n.getCollectionCatalogs(H)||[]);else if(n.getCollectionCatalog){const re=await n.getCollectionCatalog(H);W(re?[{resource_id:"",data:re}]:[])}}catch{W([])}finally{ne(!1)}},[n]),L=u.useCallback(async H=>{if(!n.getCollatedEditionIndex){V(null);return}ie(!0);try{V(await n.getCollatedEditionIndex(H))}catch{V(null)}finally{ie(!1)}},[n]),Z=u.useCallback(async H=>{if(!n.getBookFullTextIndex){K(null);return}he(!0);try{K(await n.getBookFullTextIndex(H))}catch{K(null)}finally{he(!1)}},[n]),se=u.useCallback(async(H,re)=>{Fe(!0);try{if(n.getLineageGraph){const Ee=await n.getLineageGraph(H);Ee&&le(Ee)}const ae=re.version_graph;if(!ae||!ae.enabled){pe||le(null),_e.current=null;return}const ce=re.books??[],ee=[];for(const Ee of ce)try{const Ce=await n.getItem(Ee);Ce&&ee.push(Ce)}catch{}_e.current={work:re,books:ee};const q=a??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Re=q==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":q??"all";le(Et(re,ee,Re))}catch{le(null),_e.current=null}finally{Fe(!1)}},[n]);u.useEffect(()=>{let H=!1;return(async()=>{P(!0),F(!1),R(null),A(null),W([]),V(null),le(null),_e.current=null;try{const ae=await n.getItem(t);if(H)return;if(!ae){F(!0);return}const ce=ae;let ee=null;if(n.getEntry&&(ee=await n.getEntry(t),H))return;ee||(ee={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),m&&m(ee,ce),R(ee),A(ce),ce.type==="collection"?te(t):ce.type==="work"?((ce.has_collated||n.getCollatedEditionIndex)&&L(t),(ce.version_graph||n.getLineageGraph)&&se(t,ce)):ce.type==="book"&&ce.has_full_text&&n.getBookFullTextIndex&&Z(t)}catch{H||F(!0)}finally{H||P(!1)}})(),()=>{H=!0}},[t,n,m,te,L,se,Z]),u.useEffect(()=>{const H=_e.current;!H||!a||le(Et(H.work,H.books,a))},[a]);const J=[];if(E){if(J.push({key:"basic",label:T.detailTab.basicInfo}),E.type==="collection"){U&&Q.length===0&&J.push({key:"catalog:loading",label:`${T.detailTab.catalog}…`});for(const H of Q)J.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${C(H.short_name)}${T.detailTab.catalogSuffix}`:T.detailTab.collectionCatalog})}E.type==="work"&&(B||Y)&&J.push({key:"collated",label:Y?`${T.detailTab.collatedEdition}…`:T.detailTab.collatedEdition}),E.type==="book"&&(G||de)&&J.push({key:"fulltext",label:de?`${T.detailTab.fullText}…`:T.detailTab.fullText}),E.type==="work"&&(pe||ve)&&J.push({key:"lineage",label:ve?`${T.detailTab.lineage}…`:T.detailTab.lineage});for(const H of y)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&J.push({key:H.key,label:H.label});k&&i==="feedback"&&J.push({key:"feedback",label:T.detailTab.feedback});for(const H of y)H.position==="after-feedback"&&H.shouldShow(E)&&J.push({key:H.key,label:H.label})}u.useEffect(()=>{if(i!=="emendated"||!E)return;o("basic");const H=setTimeout(()=>{var re;(re=document.getElementById("studies"))==null||re.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,E,o]);const $e=b&&E&&j?j({activeTab:i,activeJuan:N,entry:b,detail:E}):null,je=u.useMemo(()=>{var ee;if(!E)return null;const re=(E.authors??[]).map(q=>{const Re=ho(q.role);return`${q.dynasty?`〔${C(q.dynasty)}〕`:""}${C(q.name)}${Re?` ${C(Re)}`:""}`}).join(" · ");let ae=!1;try{ae=X.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const q=E;return{title:C(q.title),subtitle:q.edition?C(q.edition):re||void 0,aside:[ae?T.status.draft:"",re&&q.edition?re:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const q=E;return{title:C(q.title),subtitle:C(Oe(q,T.unit.juan))||void 0,aside:[(ee=q.publication_info)==null?void 0:ee.year,ae?T.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:re||void 0}}if(E.type==="entity"){const q=E,Re=Ce=>Ce==null?"":Ce<0?`前${-Ce}`:String(Ce),Ee=q.birth_year!=null||q.death_year!=null?`${Re(q.birth_year)||"?"}—${Re(q.death_year)||"?"}`:"";return{title:C(q.primary_name||q.title),subtitle:[q.dynasty?`〔${C(q.dynasty)}〕`:"",Ee].filter(Boolean).join(" ")||void 0,aside:ae?T.status.draft:void 0,secondLine:void 0}}const ce=C(Oe(E,T.unit.juan));return{title:C(E.title),subtitle:[ce,re].filter(Boolean).join(" · ")||void 0,aside:[E.subtype,ae?T.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,C,T]),fe=()=>{var H;return E?E.type==="work"?e.jsx(Wo,{data:E,transport:n,onNavigate:g,renderLink:v,lineageAction:pe&&pe.nodes.length>0?e.jsxs("button",{type:"button",onClick:()=>o("lineage"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[T.detailTab.lineage," →"]}):null}):E.type==="book"?e.jsx($o,{data:E,transport:n,onNavigate:g,renderLink:v}):E.type==="collection"?e.jsx(Ao,{data:E,catalog:(H=Q[0])==null?void 0:H.data,transport:n,onNavigate:g,renderLink:v,catalogAction:Q.length>0?e.jsxs("button",{type:"button",onClick:()=>o(`catalog:${Q[0].resource_id}`),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[T.detailTab.collectionCatalog," →"]}):null}):e.jsx(Mo,{data:E,transport:n,onNavigate:g,renderLink:v}):null},Ue=()=>{var re,ae,ce;if(!b||!E)return null;if(i==="basic"||i==="emendated")return fe();if(typeof i=="string"&&i.startsWith("catalog:")){const ee=(re=Q.find(q=>`catalog:${q.resource_id}`===i))==null?void 0:re.data;return e.jsx(dn,{data:ee,onNavigate:g,renderLink:v})}if(i==="collated")return e.jsx(fn,{index:B||void 0,workId:t,transport:n,onNavigate:g,activeJuan:N,onJuanChange:oe});if(i==="fulltext")return e.jsx(Yi,{index:G||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:oe});if(i==="lineage"){if(!pe)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:ve?"加載中…":"暫無版本圖數據"});const ee=E.type==="work"?E:null;return e.jsx(Do,{graph:pe,renderLink:v,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:l,onModeChange:c,selectedNodeId:f,collection:a??((ae=ee==null?void 0:ee.version_graph)==null?void 0:ae.default_collection),onCollectionChange:d,collectionsAvailable:(ce=ee==null?void 0:ee.version_graph)==null?void 0:ce.collections,collectionCounts:(()=>{var Ce,Sn,kn,wn,_n,Cn,In;if(!ee)return;const q={},Re=((Ce=_e.current)==null?void 0:Ce.books)??[];q.all=(((Sn=ee.books)==null?void 0:Sn.length)??0)-(((wn=(kn=ee.version_graph)==null?void 0:kn.excluded_books)==null?void 0:wn.length)??0);const Ee=(_n=ee.version_graph)==null?void 0:_n.collections;if(Ee)for(const zn of Object.keys(Ee))q[zn]=Et(ee,Re,zn).nodes.filter(Tn=>Tn.kind==="book"&&!Tn.bridge).length;return q.core==null&&((In=(Cn=ee.version_graph)==null?void 0:Cn.core_books)!=null&&In.length)&&(q.core=ee.version_graph.core_books.length),q})()})}if(i==="feedback"&&k)return e.jsx(ao,{resourceId:t,apiUrl:_});const H=y.find(ee=>ee.key===i);return H?H.render({detail:E,entry:b,transport:n,onNavigate:g}):null};if(M)return e.jsx(Tt,{style:{minHeight:w,...I},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12,paddingTop:48},children:[180,320,160].map((H,re)=>e.jsx("div",{style:{height:re===1?40:16,width:H,opacity:.35,background:"var(--bim-rule, #e0d6c0)"}},re))})});if($||!E||!b||!je)return e.jsx(Tt,{style:{minHeight:w,...I},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const Vo=i==="basic"||i==="emendated",Ot=[{label:h??T.detailTab.backToIndex,onClick:x}];if(E.type==="book"&&E.work_id){const H=E.work_id;Ot.push({label:T.indexType.work,id:H,onClick:()=>g==null?void 0:g(H)})}return Ot.push({label:T.indexType[E.type]}),e.jsx("div",{className:S,children:e.jsxs(Tt,{style:{minHeight:w,...I},children:[e.jsx(wo,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(vn,{char:"籍"}),e.jsx(_o,{items:Ot})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(Oo,{}),k&&e.jsx("button",{type:"button",onClick:()=>o("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:T.detailTab.feedback}),$e&&e.jsx(No,{...$e})]})}),e.jsx(Co,{...je}),J.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:J.map(H=>e.jsx(Ae,{label:H.label,active:H.key===i||Vo&&H.key==="basic",onClick:()=>o(H.key)},H.key))}),e.jsx("div",{style:{marginTop:J.length>1?8:0},children:Ue()}),e.jsx(Bo,{left:e.jsxs(e.Fragment,{children:[z,z?" · ":"",e.jsx(La,{id:E.id,label:T.label.id,copied:T.action.copied})]}),right:e.jsxs(e.Fragment,{children:[k&&e.jsx("button",{type:"button",onClick:()=>o("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:T.detailTab.submitVersion}),$e&&e.jsx("a",{href:$e.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:T.detailTab.dataLicense})]})})]})})};function La({id:t,label:n,copied:i}){const[o,s]=u.useState(!1);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsxs("span",{children:[n," ",t]}),e.jsx("button",{type:"button",onClick:()=>{var r;(r=navigator.clipboard)==null||r.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}).catch(()=>{})},title:o?i:void 0,style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:o?"✓":"⧉"})]})}exports.BidLink=X.BidLink;exports.BookIndexError=X.BookIndexError;exports.BookIndexManager=X.BookIndexManager;exports.BookIndexStorage=X.BookIndexStorage;exports.BundleStorage=X.BundleStorage;exports.ConfigError=X.ConfigError;exports.GithubStorage=X.GithubStorage;exports.IdGenerationError=X.IdGenerationError;exports.IdGenerator=X.IdGenerator;exports.LocalStorage=X.LocalStorage;exports.MigrationError=X.MigrationError;exports.StorageError=X.StorageError;exports.base36Decode=X.base36Decode;exports.base36Encode=X.base36Encode;exports.base58Decode=X.base58Decode;exports.buildId=X.buildId;exports.buildPromotionMap=X.buildPromotionMap;exports.cleanName=X.cleanName;exports.decodeId=X.decodeId;exports.decodeIdString=X.decodeIdString;exports.encodeId=X.encodeId;exports.extractIdFromUrl=X.extractIdFromUrl;exports.extractStatus=X.extractStatus;exports.extractType=X.extractType;exports.normalizeCatalog=X.normalizeCatalog;exports.parseId=X.parseId;exports.shardOf=X.shardOf;exports.smartDecode=X.smartDecode;exports.validateResource=X.validateResource;exports.Badge=Wt;exports.BidUrlProvider=tr;exports.BookDetailLayout=Ba;exports.BookFullText=Yi;exports.BookPage=$o;exports.Breadcrumb=_o;exports.Chip=St;exports.ChipWall=Ft;exports.CollatedEdition=fn;exports.CollectionCatalog=dn;exports.CollectionPage=Ao;exports.CreateEntityDialog=eo;exports.DETAIL_CSS=ko;exports.Dash=Xe;exports.DataTable=Ne;exports.DetailFooter=Bo;exports.DetailHeader=Co;exports.EmendatedBySection=Pi;exports.EmptyNote=Qe;exports.EntityDetail=Li;exports.EntityPage=Mo;exports.EntityPickerDialog=no;exports.EntitySelector=Qi;exports.ExpandRow=zo;exports.ExtLink=tn;exports.FactList=jt;exports.FeedbackButton=Al;exports.FeedbackDialog=so;exports.FeedbackForm=lo;exports.FeedbackList=gn;exports.FeedbackTab=ao;exports.FilterChip=Ae;exports.FormInput=ge;exports.FormTextArea=He;exports.GlyphBadge=vn;exports.HomePage=Zt;exports.IndexApp=Ns;exports.IndexBrowser=Xt;exports.IndexDetail=cn;exports.IndexEditor=io;exports.IndexView=_l;exports.IntroGrid=vt;exports.LocaleContext=bt;exports.LocaleProvider=dr;exports.LocaleToggle=Oo;exports.ModeIndicator=Ei;exports.MoreButton=Me;exports.PAGE_MAX_WIDTH=So;exports.PageFrame=Tt;exports.Quote=Rt;exports.ROLE_CLASS_ORDER=mo;exports.RelationPanel=Xi;exports.RepoSourceLink=No;exports.ResourceEditor=qt;exports.ResourceGroup=en;exports.ResourceLine=Ze;exports.ResourceList=an;exports.ResourceRow=To;exports.SearchInput=Bi;exports.Section=Se;exports.SectionHead=ue;exports.SmartBidInput=Ct;exports.SourceEditor=Ki;exports.TableHead=Pt;exports.TableRow=Ht;exports.TagRow=jn;exports.TagRows=Eo;exports.TextButton=Mt;exports.TopStrip=wo;exports.VersionLineageGraph=Ho;exports.VersionLineageList=Po;exports.VersionLineageView=Do;exports.VolumeChips=Io;exports.VolumeLinks=Ro;exports.WorkCatalog=Vs;exports.WorkPage=Wo;exports.bucketResources=At;exports.buildCollectionTable=yo;exports.buildLineageGraph=Et;exports.buildPageUrl=ln;exports.buildVersionRow=fo;exports.buildVersionTable=go;exports.computeVersionPartition=ql;exports.deriveEditionType=jo;exports.deriveEra=mn;exports.deriveYear=uo;exports.detailToEditor=ro;exports.editorToDetail=wl;exports.eraRank=dt;exports.flattenTitles=ht;exports.formatTemplate=yt;exports.formatVolumeRange=yn;exports.getDisplayNameFromUrl=gt;exports.getStartPage=sn;exports.getTypeGroupKey=nn;exports.groupRelatedWorks=xo;exports.measureText=Oe;exports.mergeVolumeResources=on;exports.normalizeEra=at;exports.normalizeRole=bn;exports.normalizeVolumeIndex=ft;exports.normalizeVolumes=Ri;exports.numberToChinese=vo;exports.parseChineseNumber=po;exports.parseSourceString=Ji;exports.resourceHref=Bt;exports.resourceNote=hn;exports.roleFacets=bo;exports.rowNo=Dt;exports.stringifySources=qi;exports.useBidUrl=me;exports.useConvert=D;exports.useT=O;exports.validateLineageGraph=da;exports.volumeStats=rn;
|