book-index-ui 0.9.2 → 0.9.4
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 +3 -3
- package/dist/index.js +1206 -1174
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ao=Object.create;var Un=Object.defineProperty;var co=Object.getOwnPropertyDescriptor;var po=Object.getOwnPropertyNames;var uo=Object.getPrototypeOf,xo=Object.prototype.hasOwnProperty;var fo=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of po(n))!xo.call(t,s)&&s!==i&&Un(t,s,{get:()=>n[s],enumerable:!(r=co(n,s))||r.enumerable});return t};var dt=(t,n,i)=>(i=t!=null?ao(uo(t)):{},fo(n||!t||!t.__esModule?Un(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("./storage-entry-VGdfSKGX.cjs"),e=require("react/jsx-runtime"),f=require("react"),go=require("react-markdown"),mo=require("remark-gfm"),ho=require("react-dom"),bo=t=>`/book-index?id=${t}`,Vi=f.createContext(bo);function yo({buildUrl:t,children:n}){const i=f.useMemo(()=>t,[t]);return e.jsx(Vi.Provider,{value:i,children:n})}function be(){return f.useContext(Vi)}function Ke(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function vo(t,n){return Ke(t).includes(n)}const Gi={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},jo={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},So={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},_t=f.createContext(null),Yi={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:"收入叢編",collectedIn:"收入叢編",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)",publicationYearLabel:"出版年 (Publication 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:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},ko={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:"收入丛编",collectedIn:"收入丛编",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)",publicationYearLabel:"出版年 (Publication 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:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},wo={"zh-Hant":Yi,"zh-Hans":ko},Ui="bim-locale";function _o(){try{const t=localStorage.getItem(Ui);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function Co(t){try{localStorage.setItem(Ui,t)}catch{}}const Io="zh-Hans",To=({locale:t,onLocaleChange:n,children:i})=>{const[r,s]=f.useState(t??Io),o=t??r;f.useEffect(()=>{if(t)return;const p=_o();p&&p!==r&&s(p)},[]);const[a,c]=f.useState(null);f.useEffect(()=>{o==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const x=p.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>p=>p)}):c(null)},[o]);const l=f.useCallback(p=>{s(p),Co(p),n==null||n(p)},[n]),d=f.useMemo(()=>({locale:o,setLocale:l,messages:wo[o],converter:a}),[o,l,a]);return e.jsx(_t.Provider,{value:d,children:i})};function D(){const t=f.useContext(_t);return(t==null?void 0:t.messages)??Yi}const zo=2e3;function P(){const t=f.useContext(_t),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const o=f.useCallback(a=>{if(!a)return"";if(!i)return a;const c=r.current.get(a);if(c!==void 0)return c;const l=i(a);if(r.current.size>=zo){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,l),l},[i]);return f.useMemo(()=>({convert:o,locale:n,isSimplified:n==="zh-Hans"}),[o,n])}function Ct(t,n){return t.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Ro(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 r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Eo(){return{id:"",name:"",url:"",type:"text",details:""}}const cn=({items:t,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const o=D(),[a,c]=f.useState(null),l=[{value:"text",label:o.resourceTypeShort.text},{value:"image",label:o.resourceTypeShort.image},{value:"text+image",label:o.resourceTypeShort.textImage},{value:"physical",label:o.resourceTypeShort.physical}],d=[{value:"catalog",label:o.rootType.catalog},{value:"search",label:o.rootType.search}],p=m=>{if(!s)return!0;const j=Ke(m);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=t.map((m,j)=>({item:m,originalIndex:j})).filter(({item:m})=>p(m)),g=()=>{const m=Eo();s&&(m.type=s),n([...t,m]),c(t.length)},u=m=>{n(t.filter((j,w)=>w!==m)),c(null)},b=(m,j,w)=>{const k=[...t];if(k[m]={...k[m],[j]:w},j==="url"&&!k[m].id){const C=Ro(w);C&&(k[m].id=C)}n(k)},y=(m,j,w)=>{const C={...t[m].metadata||{}};w?C[j]=w:delete C[j],b(m,"metadata",Object.keys(C).length>0?C:void 0)},h=(m,j)=>{const w=j.trim()?j.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;b(m,"structure",w)},S=(m,j,w)=>{const C=t[m].coverage||{level:1,ranges:""};j==="level"?C.level=parseInt(w)||1:C.ranges=w,b(m,"coverage",C.ranges?C:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:j})=>{var w,k,C;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(a===j?null:j),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===j?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Bo(m.type??"text"),color:"#fff"},children:(()=>{var _,z;const T=Ke(m);return T.length===0?m.type??"text":T.length===1?((_=l.find(I=>I.value===T[0]))==null?void 0:_.label)??T[0]:T.includes("text")&&T.includes("image")?((z=l.find(I=>I.value==="text+image"))==null?void 0:z.label)??"text+image":T.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${o.editor.resourcePlaceholder} ${j+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:T=>T.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&m.url&&Lo(j,r==null?void 0:r[j],i,o),e.jsx("button",{onClick:T=>{T.stopPropagation(),u(j)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisResource,children:"✕"})]}),a===j&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[vo(m,"image")&&m.url&&Wo(m,o),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.type}),e.jsx("select",{value:m.type,onChange:T=>b(j,"type",T.target.value),style:{...Re,flex:1},children:l.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]}),e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:T=>b(j,"root_type",T.target.value),style:{...Re,flex:1},children:d.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:T=>b(j,"id",T.target.value),placeholder:o.editor.idAutoExtract,style:{...Re,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:T=>b(j,"name",T.target.value),placeholder:o.editor.resourceName,style:{...Re,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:T=>b(j,"url",T.target.value),placeholder:o.editor.resourceUrl,style:Re}),e.jsx("input",{type:"text",value:((w=m.structure)==null?void 0:w.join("、"))||"",onChange:T=>h(j,T.target.value),placeholder:o.editor.structurePlaceholder,style:Re}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=m.coverage)==null?void 0:k.level)??"",onChange:T=>S(j,"level",T.target.value),placeholder:"1",style:{...Re,width:"60px"}})]}),e.jsxs("label",{style:{...pt,flex:1},children:[e.jsx("span",{style:ut,children:o.label.coverageRange}),e.jsx("input",{type:"text",value:((C=m.coverage)==null?void 0:C.ranges)||"",onChange:T=>S(j,"ranges",T.target.value),placeholder:o.editor.coverageRangePlaceholder,style:{...Re,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:T=>b(j,"details",T.target.value),placeholder:o.editor.detailsPlaceholder,style:{...Re,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:o.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(o.metadata).map(([T,_])=>{var z;return e.jsxs("label",{style:{...pt,gap:"4px"},children:[e.jsx("span",{style:{...ut,minWidth:"56px"},children:_}),e.jsx("input",{type:"text",value:((z=m.metadata)==null?void 0:z[T])||"",onChange:I=>y(j,T,I.target.value),placeholder:_,style:{...Re,flex:1}})]},T)})})]})]})]})]},j)}),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:o.action.addResource})]})]})};function Bo(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 Lo(t,n,i,r){const s=(n==null?void 0:n.status)==="downloading",o=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||i(t,"")},disabled:s,style:{background:"transparent",border:"none",color:o?"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:o?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:o?"✓":s?"⏳":"⬇"})}function Wo(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:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const Re={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},pt={display:"flex",alignItems:"center",gap:"6px"},ut={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},$o={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function St(t){try{return $o[new URL(t).hostname]}catch{return}}const Kn={text:0,image:1,physical:2};function bn(t){return t.length===0?"physical":[...t].sort((n,i)=>(Kn[n]??99)-(Kn[i]??99)).join("+")}function yn(t){var a;const n=c=>{const l=c.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const d=c.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let c=0;c<t.length;c++){const l=t[c];if(l.volumes&&l.volumes.length>0)continue;const d=n(l.name);if(!d)continue;const[p,x]=d,g=`${p}|${bn(Ke(l))}`;i.has(g)||i.set(g,{base:{...l,name:p,url:"",volumes:[]},volumes:[],indices:[]});const u=i.get(g);u.volumes.push({volume:x,url:l.url||void 0,status:"found"}),u.indices.push(c)}const r=[],s=new Set;for(const c of i.values())if(!(c.volumes.length<2)){c.volumes.sort((l,d)=>l.volume-d.volume),c.base.volumes=c.volumes,c.base.expected_volumes=c.volumes.length,c.base.url||(c.base.url=((a=c.volumes.find(l=>l.url))==null?void 0:a.url)??""),r.push(c.base);for(const l of c.indices)s.add(l)}const o=[...r];for(let c=0;c<t.length;c++)s.has(c)||o.push(t[c]);return o}function Ki(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 Ji(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Ki(n)}))}function vn(t){const n=Ji(t);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:t.expected_volumes??i+r}}function jn(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 Sn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const r=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Pt(t){if(!t.url)return;const n=jn(t.metadata);return n?Sn(t.url,n):t.url}const Jn={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 Ao(t){return t.includes("text")&&t.includes("image")?Jn["text+image"]:Jn[t[0]||"physical"]}const kn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const o=D(),{convert:a}=P(),c=f.useMemo(()=>yn(t||[]),[t]),{mirrorGroups:l,ungroupedItems:d}=f.useMemo(()=>{const h=new Map,S=[];for(const m of c){const j=m.group;j?(h.has(j)||h.set(j,[]),h.get(j).push(m)):S.push(m)}for(const m of h.values())m.sort((j,w)=>{const k=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return k(j)-k(w)});return{mirrorGroups:h,ungroupedItems:S}},[c]),p={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical},x=h=>p[h]?p[h]:h.split("+").map(S=>p[S]||S).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((h,S)=>e.jsx(Qt,{item:h},h.id||S))});const g=(h,S)=>{const m=i==null?void 0:i[h],j=(m==null?void 0:m.label)||h,w=m==null?void 0:m.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(j)}),w&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:a(w)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((k,C)=>e.jsx(Qt,{item:k,onNavigate:r,renderLink:s},k.id||C))})]},`group-${h}`)},u=new Map;for(const h of d){const S=bn(Ke(h));u.has(S)||u.set(S,[]),u.get(S).push(h)}const b=["text","image","text+image","physical"],y=[...b.filter(h=>u.has(h)),...[...u.keys()].filter(h=>!b.includes(h)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...l.entries()].map(([h,S])=>g(h,S)),y.map(h=>{const S=u.get(h),m=Ao(h.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:m,whiteSpace:"nowrap",flexShrink:0},children:x(h)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((j,w)=>e.jsx(Qt,{item:j,onNavigate:r,renderLink:s},j.id||w))})]},h)})]})},Fo={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)"}},Qt=({item:t})=>{const n=D(),{convert:i}=P(),[r,s]=f.useState(!1),o=f.useMemo(()=>(t.url?St(t.url):void 0)||i(t.name),[t.url,t.name,i]),a=f.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||Ki(b)})),[t.volumes]),c=a&&a.length>0,l=c?new Set(a.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(a.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,p=t.expected_volumes??(c?l+d:0),x=t.color_mode?{...Fo[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:o}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l,"/",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 b=jn(t.metadata);return b?Sn(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const y=b.status==="missing";return b.url&&!y?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:b.volume},b.volume)})})]})},qi=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:o,onSelectFolder:a})=>{const c=D(),l=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",x=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"},b=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"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,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:a,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,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:o,title:x||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:r,title:l?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:a,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!l&&x&&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:x})]})]})},Nt="bim-search-history",qn=10,Xn=8;function bt(){try{const t=localStorage.getItem(Nt);return t?JSON.parse(t):[]}catch{return[]}}function Mo(t){try{const n=bt().filter(i=>i!==t);n.unshift(t),n.length>qn&&(n.length=qn),localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Po(t){try{const n=bt().filter(i=>i!==t);localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Ho(){try{localStorage.removeItem(Nt)}catch{}}const Xi=({transport:t,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:o})=>{const a=D(),c=o??a.search.placeholder,l={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,p]=f.useState(!1),[x,g]=f.useState([]),[u,b]=f.useState(-1),[y,h]=f.useState(bt),S=f.useRef(null),m=f.useRef(null),j=f.useRef(null),w=f.useRef(!1);f.useEffect(()=>{b(-1);const v=n.trim();if(!v){g(y.map(M=>({type:"history",text:M})));return}if(!t.searchAll){g([]);return}let R=!1;const E=setTimeout(()=>{t.searchAll(v,Xn).then(M=>{if(R)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];g($.slice(0,Xn).map(O=>({type:"entry",text:O.title||O.id,entry:O})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,y,t]),f.useEffect(()=>{const v=R=>{j.current&&!j.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),f.useEffect(()=>{const v=R=>{var E,M;if(R.key==="/"&&document.activeElement!==S.current){const $=(E=document.activeElement)==null?void 0:E.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;R.preventDefault(),(M=S.current)==null||M.focus()}};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const k=f.useCallback(v=>{v.trim()&&(Mo(v.trim()),h(bt())),r(v),p(!1)},[r]),C=f.useCallback(v=>{v.type==="history"?(i(v.text),k(v.text)):v.entry&&(s?(s(v.entry),p(!1)):(i(v.text),k(v.text)))},[i,k,s]),T=f.useCallback(v=>{if(!d||x.length===0){v.key==="Enter"&&k(n);return}switch(v.key){case"ArrowDown":v.preventDefault(),b(R=>(R+1)%x.length);break;case"ArrowUp":v.preventDefault(),b(R=>(R-1+x.length)%x.length);break;case"Enter":v.preventDefault(),u>=0&&u<x.length?C(x[u]):k(n);break;case"Escape":v.preventDefault(),p(!1);break}},[d,x,u,n,k,C]),_=f.useCallback((v,R)=>{R.stopPropagation(),Po(v),h(bt()),g(E=>E.filter(M=>!(M.type==="history"&&M.text===v)))},[]),z=f.useCallback(v=>{v.stopPropagation(),Ho(),h([]),g([])},[]);f.useEffect(()=>{if(u>=0&&m.current){const v=m.current.children;v[u]&&v[u].scrollIntoView({block:"nearest"})}},[u]);const I=!n.trim()&&y.length>0;return e.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:c,value:n,onChange:v=>{i(v.target.value),p(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{p(!0)},onKeyDown:T,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:z,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((v,R)=>e.jsxs("div",{onClick:()=>C(v),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:R===u?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:v.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.text}),v.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[l[v.entry.type],v.entry.edition&&` · ${v.entry.edition}`,v.entry.author&&` · ${v.entry.author}`]}),v.type==="history"&&e.jsx("button",{onClick:E=>_(v.text,E),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${v.type}-${v.text}-${R}`))]})]})},kt="bim-recent-ids",Zn="bim-recent-entries",Qn=50,en=5,Oo=50,Do=200;function yt(){try{const t=localStorage.getItem(kt);if(t)return JSON.parse(t);const n=localStorage.getItem(Zn);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(kt,JSON.stringify(i)),localStorage.removeItem(Zn),i}return[]}catch{return[]}}function No(t){try{const n=yt().filter(i=>i!==t);n.unshift(t),n.length>Qn&&(n.length=Qn),localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Vo(t){try{const n=yt().filter(i=>i!==t);localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Go(){try{localStorage.removeItem(kt)}catch{}}const Yo={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},dn=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:o,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l,hideModeIndicator:d,resultVariant:p="compact",renderEntry:x,initialQuery:g,onQueryChange:u,headerRight:b})=>{const y=D(),h=[{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"}],[S,m]=f.useState(g??""),[j,w]=f.useState(null),[k,C]=f.useState(null),[T,_]=f.useState(!1),[z,I]=f.useState(null),[v,R]=f.useState(""),[E,M]=f.useState(!g),[$,O]=f.useState(yt),[A,F]=f.useState([]),[J,W]=f.useState(!1),[Y,ie]=f.useState(!1),[K,L]=f.useState(null),[U,q]=f.useState(null),V=f.useRef(void 0),G=f.useRef(!1),de=f.useCallback(async(N,oe)=>{if(!N.trim()){M(!0),w(null),C(null);return}M(!1),_(!0),R("");try{if(t.searchAll){const ne=await t.searchAll(N,oe??en);w(ne)}else{const ne=["work","book","collection","entity"],B=await Promise.all(ne.map(ee=>t.search(N,ee,{page:1,pageSize:oe??en})));w({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(ne){R(ne instanceof Error?ne.message:String(ne)),w(null)}finally{_(!1)}},[t]);f.useEffect(()=>{let N=!1;const oe=()=>{var X,Pe;const ne=["work","book","collection","entity"],B=Promise.all(ne.map(ve=>t.loadEntries(ve,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((X=t.getResourceCounts)==null?void 0:X.call(t).catch(()=>null))??Promise.resolve(null),le=((Pe=t.getSubtypeStats)==null?void 0:Pe.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([B,ee,le]).then(([ve,ge,Qe])=>{N||(L({works:ve[0].total,books:ve[1].total,collections:ve[2].total,entities:ve[3].total,hasText:ge==null?void 0:ge.hasText,hasImage:ge==null?void 0:ge.hasImage}),Qe&&q(Qe))})};return t.getCounts?t.getCounts().then(ne=>{var B,ee;N||(L({works:ne.works,books:ne.books,collections:ne.collections,entities:ne.entities,hasText:(B=ne.resourceCounts)==null?void 0:B.hasText,hasImage:(ee=ne.resourceCounts)==null?void 0:ee.hasImage}),ne.subtypeStats&&q(ne.subtypeStats))}).catch(()=>{N||oe()}):oe(),()=>{N=!0}},[t]),f.useEffect(()=>{G.current||!(g!=null&&g.trim())||(G.current=!0,de(g))},[g,de]);const Se=f.useCallback(N=>{if(m(N),!N.trim()){u==null||u(N),M(!0),w(null),C(null);return}V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{C(null),u==null||u(N),de(N)},Do)},[de,u]),me=f.useCallback(N=>{V.current&&clearTimeout(V.current),u==null||u(N),de(N)},[de,u]),se=f.useCallback(N=>{C(N),de(S,Oo)},[S,de]);f.useEffect(()=>{if(!$.length){F([]);return}let N=!1;return W(!0),Promise.all($.slice(0,10).map(async oe=>{var ne,B,ee;try{if(t.getEntry){const X=await t.getEntry(oe);if(X)return X}const le=await t.getItem(oe);if(le){const X=le.authors;return{id:oe,title:le.title||oe,type:le.type||"work",author:(ne=X==null?void 0:X[0])==null?void 0:ne.name,dynasty:(B=X==null?void 0:X[0])==null?void 0:B.dynasty,role:(ee=X==null?void 0:X[0])==null?void 0:ee.role,edition:le.edition||void 0}}}catch{}return{id:oe,title:oe,type:"work",notFound:!0}})).then(oe=>{N||(F(oe),W(!1))}),()=>{N=!0}},[$,t]);const ye=N=>{I(N.id),No(N.id),O(yt()),r==null||r(N)},Ie=N=>{Vo(N),O(yt())},Te=()=>{Go(),O([])},Ze=N=>h.find(oe=>oe.type===N),ct=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:y.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&e.jsx(qi,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:o,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Xi,{transport:t,value:S,onChange:Se,onSearch:me,onEntrySelect:ye}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:y.action.newEntry})]}),K&&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:U?e.jsxs(e.Fragment,{children:[(U.book??0)>0&&e.jsxs(e.Fragment,{children:["書 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.book.toLocaleString()})," 部 ,",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()})," 本"]}),U.article?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"文章 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.article.toLocaleString()})," 篇"]}):null,U.poem?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"詩詞 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:U.poem.toLocaleString()})," 首"]}):null,e.jsx("span",{style:{margin:"0 6px"},children:"·"}),"叢編 ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()}),K.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.entities.toLocaleString()})]})]})}),K.hasImage!=null&&K.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.searching}):v?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:v})]}):E?e.jsx("div",{style:{flex:1},children:J?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):A.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:Te,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:A.slice(0,Y?10:3).map(N=>N.notFound?e.jsx(Ko,{id:N.id,onRemove:Ie,t:y},N.id):e.jsx(ei,{entry:N,selected:z===N.id,onClick:ye,getConfig:Ze,onRemove:Ie},N.id))}),!Y&&A.length>3&&e.jsx("button",{onClick:()=>ie(!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})]})}):ct?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:N,icon:oe,name:ne,key:B})=>{const ee=j[B]??[],le=Yo[B],X=j[le]??0;if(ee.length===0)return null;const ve=!(k===N)&&X>en;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," ",ne,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[X," ",y.unit.items]})]}),ve&&e.jsx("button",{onClick:()=>se(N),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:ee.map(ge=>{if(x)return e.jsx(f.Fragment,{children:x(ge)},ge.id);const Qe=p==="card"?Uo:ei;return e.jsx(Qe,{entry:ge,selected:z===ge.id,onClick:ye,getConfig:Ze,query:S},ge.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:Ct(y.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},Uo=({entry:t,selected:n,onClick:i,getConfig:r,query:s})=>{const o=D(),{convert:a}=P(),c=a(t.title||t.primary_name||t.id),l=t.measure_info?a(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${o.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,x="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, ${x} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${x} 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, ${x} 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:x},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}),l&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs("span",{children:["〔",a(t.era),"〕"]}),t.edition&&e.jsx("span",{children:a(t.edition)})]}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[o.search.alias,":",a(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:[r(t.type).icon," ",r(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",o.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:["🖼️ ",o.misc.imageResource]})]})]})]})},ei=({entry:t,selected:n,onClick:i,getConfig:r,query:s,onRemove:o})=>{const a=D(),{convert:c}=P(),l=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&l.length?l.find(p=>{const x=typeof p=="string"?p:p==null?void 0:p.book_title;return x==null?void 0:x.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:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:a.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:a.misc.imageResource,children:"🖼️"})]}),(t.era||t.edition)&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs(e.Fragment,{children:["〔",c(t.era),"〕"]}),t.edition&&c(t.edition)]}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[a.search.alias,":",c(d)]})]}),o?e.jsx("button",{onClick:p=>{p.stopPropagation(),o(t.id)},title:a.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},Ko=({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 Jo(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 qo({data:t}){const{convert:n}=P(),{dynasty:i,birth_year:r,death_year:s}=t,o=[];return i&&o.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?o.push(`${r}—${s}`):r!==void 0?o.push(`${r}—?`):s!==void 0&&o.push(`?—${s}`),o.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:o.join(" ")})}function Xo({alt_names:t}){const{convert:n}=P(),i=new Map;for(const o of t){const a=o.type||"別名";i.has(a)||i.set(a,[]),i.get(a).push(o.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((o,a)=>{const c=r.indexOf(o),l=r.indexOf(a);return c===-1&&l===-1?0:c===-1?1:l===-1?-1:c-l});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(o=>{const a=i.get(o);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:o}),e.jsx("span",{children:a.map((c,l)=>e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},l))})]},o)})})}function Zo({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 Qo({works:t,transport:n,onNavigate:i,renderLink:r}){const s=D(),{convert:o}=P(),a=be(),[c,l]=f.useState(new Map);f.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 j=await n.getEntriesByIds(u);let w=!0;for(let k=0;k<u.length;k++){const C=j[k];C!=null&&C.title?y.set(u[k],C.title):C!=null&&C.primary_name?y.set(u[k],C.primary_name):w=!1}if(w)return y}catch{}const h=[...u],S=8,m=new Array(S).fill(0).map(async()=>{for(;h.length;){const j=h.shift();if(!j)break;if(!y.has(j))try{if(n.getEntry){const C=await n.getEntry(j);if(C!=null&&C.title){y.set(j,C.title);continue}}const w=await n.getItem(j),k=w&&(w.title||w.primary_name)||j;y.set(j,k)}catch{y.set(j,j)}}});return await Promise.all(m),y})().then(y=>{g||l(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const u=g.role||"";d.has(u)||d.set(u,[]),d.get(u).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((g,u)=>{const b=p.indexOf(g),y=p.indexOf(u);return b===-1&&y===-1?g.localeCompare(u):b===-1?1:y===-1?-1:b-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.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:[o(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((b,y)=>{const h=o(c.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,h)},y):i?e.jsx("li",{children:e.jsx("a",{href:a(b.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),i(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:h})},y):e.jsx("li",{children:h},y)})})]},g)})]})}const Zi=({data:t,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:o})=>{var x;const a=D(),{convert:c}=P();let l=!1;try{l=Q.extractStatus(t.id)==="draft"}catch{}const d=Jo(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!o&&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(qo,{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:a.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),l&&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:a.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(Xo,{alt_names:t.alt_names}),e.jsx(Zo,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(t.description.text)}),t.works&&t.works.length>0&&e.jsx(Qo,{works:t.works,transport:n,onNavigate:i,renderLink:r})]})},Qi={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})},es={...Qi,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Fe=({text:t,plainStrong:n,style:i,className:r})=>{const{convert:s}=P(),o=n?es:Qi;return e.jsx("div",{className:r,style:i,children:e.jsx(go,{remarkPlugins:[mo],components:o,children:s(t)})})},ts=["〇","一","二","三","四","五","六","七","八","九"],ti=["","十","百","千"];function er(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const a=parseInt(n[o]),c=i-1-o;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&o===0?r+=ti[c]:r+=ts[a]+ti[c])}return r}function tr(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 ns={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 is({type:t}){const n=D();return e.jsx("span",{style:tr(ns[t]),children:n.indexType[t]})}function rs({isDraft:t}){const n=D(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:tr(i),children:t?n.status.draft:n.status.official})}function os({id:t}){const n=D(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"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:o=>o.currentTarget.style.opacity="1",onMouseLeave:o=>o.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function je({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 Ee({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 nr({authors:t,type:n,onNavigate:i,renderLink:r}){const{convert:s}=P();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,a)=>{const c=s(o.name),l=o.entity_id?e.jsx(we,{id:o.entity_id,label:c,onNavigate:i,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(o.dynasty),"〕"]}),l,o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(o.role)]})]},a)})})}function we({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.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:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function ss({id:t,title:n,edition:i,type:r,isDraft:s,authors:o,volumeText:a,meta:c,headerExtra:l,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}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),l&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:l})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(is,{type:r}),e.jsx(rs,{isDraft:s}),e.jsx(os,{id:t})]}),((o==null?void 0:o.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[o&&o.length>0&&e.jsx(nr,{authors:o,type:r,onNavigate:d,renderLink:p}),c]})]})}function ir({items:t,label:n,showMeta:i,onNavigate:r,renderLink:s}){const o=D(),{convert:a}=P();if(!t.length)return null;const[c,l]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,p)=>{const x=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>l(x?null: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:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(d.source)}),!x&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(we,{id:d.source_bid,label:o.action.view,onNavigate:r,renderLink:s})})]}),x&&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(Ee,{label:o.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(Ee,{label:o.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(Ee,{label:o.label.edition,children:a(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},p)})})]})}function ls({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function rr({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.emendated,onNavigate:n,renderLink:i})}function or({label:t,items:n}){const{convert:i}=P();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const o=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:i(o)},s)})})]}):null}function as({items:t}){const n=D();return e.jsx(or,{label:n.section.aliases,items:t})}function cs({items:t}){const n=D();return e.jsx(or,{label:n.section.attachedTexts,items:t})}function ds({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",i(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function ps({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function us({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(r)]},s))})]}):null}function ni({title:t,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:o}=P(),[a,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let l=!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=>{l||c(d)}),()=>{l=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(l=>({id:l}))).map(l=>{const d=l.edition?`${o(l.title)||l.id}(${o(l.edition)})`:o(l.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(we,{id:l.id,label:d,onNavigate:r,renderLink:s})},l.id)})})]}):null}function tn({book:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=P(),[o,a]=f.useState(!1),c=t.resources&&t.resources.length>0,l=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!o?"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(we,{id:t.id,label:l,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:o?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:o?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!o&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(kn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function xs({ids:t,workData:n,transport:i,onNavigate:r,renderLink:s,footer:o}){const a=D(),{convert:c}=P(),[l,d]=f.useState([]);if(f.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(y=>({id:y})));return}let b=!1;return Promise.all(t.map(y=>i.getItem(y).then(h=>({id:y,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:y})))).then(y=>{b||d(y)}),()=>{b=!0}},[t,i]),!t.length)return null;const p=l.length?l:t.map(b=>({id:b})),x=new Map(p.map(b=>[b.id,b])),g=n==null?void 0:n.version_graph,u=fs(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),o,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(b=>{const y=x.get(b);return y?e.jsx(tn,{book:y,onNavigate:r,renderLink:s},b):null})}),u.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(y=>{const h=x.get(y);return h?e.jsx(tn,{book:h,onNavigate:r,renderLink:s},y):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(b=>e.jsx(tn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function fs(t,n){var h,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,a=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const j=n.node_groups[m];return j!=null&&c.has(j)},p=[],x=new Map,g=[];for(const m of t)if(!((S=n.excluded_books)!=null&&S.includes(m)))if(d(m))p.push(m);else{const j=n.node_groups[m];j?(x.has(j)||x.set(j,[]),x.get(j).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,j)=>m+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,j])=>{const w=b.get(m);return{id:m,label:(w==null?void 0:w.label)??m,description:w==null?void 0:w.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}function gs({workData:t,onNavigate:n,renderLink:i}){var a,c,l,d;const r=D(),{convert:s}=P(),o=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:o?"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(we,{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:[er(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(nr,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),o&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((l=t.description)==null?void 0:l.text)&&e.jsx(Fe,{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(Ee,{label:r.label.parentWork,children:e.jsx(we,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function ms({items:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=P();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(o=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:r.indexType.collection}),e.jsx(we,{id:o.id,label:s(o.title)||o.id,onNavigate:n,renderLink:i}),o.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ct(r.catalog.volume,{n:o.volume_index})})]},o.id))}):null}const wn=({data:t,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:o,relatedBooksFooter:a,className:c,style:l})=>{var R,E,M,$,O,A,F,J;const d=D(),{convert:p}=P(),[x,g]=f.useState(null),[u,b]=f.useState(!1),[y,h]=f.useState(null),[S,m]=f.useState(null),[j,w]=f.useState([]),k=t||x;if(f.useEffect(()=>{if(t||!n||!i)return;let W=!1;return b(!0),h(null),i.getItem(n).then(Y=>{W||(Y?g(Y):h(d.misc.notFoundEntry))}).catch(Y=>{W||h(Y instanceof Error?Y.message:d.misc.loadFailed)}).finally(()=>{W||b(!1)}),()=>{W=!0}},[t,n,i]),f.useEffect(()=>{if(!k||!i){m(null),w([]);return}let W=!1;const Y=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(Y?i.getItem(Y).then(ie=>{!W&&ie&&ie.type==="work"&&m(ie)}).catch(()=>{}):m(null),k.type==="book"){const ie=k;ie.contained_in&&ie.contained_in.length>0?Promise.all(ie.contained_in.map(K=>{const L=typeof K=="string"?K:K.id,U=typeof K=="string"?void 0:K.volume_index;return i.getItem(L).then(q=>({id:L,title:q&&q.title||L,volume_index:U})).catch(()=>({id:L,title:L,volume_index:U}))})).then(K=>{W||w(K)}):w([])}else w([]);return()=>{W=!0}},[k,i]),u)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((W,Y)=>e.jsx("div",{style:{height:Y===1?"32px":"16px",width:`${W}px`,background:"var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",opacity:.4}},Y))})});if(y)return e.jsx("div",{className:c,style:{...l,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y});if(!k)return null;if(k.type==="entity")return e.jsx("div",{className:c,style:l,children:e.jsx(Zi,{data:k,transport:i,onNavigate:r,renderLink:s,headerExtra:o})});const C=k.type==="book"?k:null,T=k.type==="collection"?k:null,_=k.type==="work"?k:null;let z=!1;try{z=Q.extractStatus(k.id)==="draft"}catch{}let I="";k.measure_info?I=p(k.measure_info):(R=k.juan_count)!=null&&R.number?I=er(k.juan_count.number)+d.unit.juan:(E=k.juan_count)!=null&&E.description&&(I=p(k.juan_count.description));const v=[];return(M=k.publication_info)!=null&&M.year&&v.push(e.jsx(Ee,{label:d.label.year,children:k.publication_info.year},"year")),($=k.current_location)!=null&&$.name&&v.push(e.jsx(Ee,{label:d.label.currentLocation,children:p(k.current_location.name)},"loc")),(O=k.page_count)!=null&&O.description&&v.push(e.jsx(Ee,{label:d.label.pageCount,children:k.page_count.description},"page")),C!=null&&C.edition&&v.push(e.jsx(Ee,{label:d.label.edition,children:p(C.edition)},"ver")),_!=null&&_.parent_work&&v.push(e.jsx(Ee,{label:d.label.parentWork,children:e.jsx(we,{id:_.parent_work.id,label:p(_.parent_work.title),onNavigate:r,renderLink:s})},"pw")),_!=null&&_.parent_works&&_.parent_works.length>0&&!_.parent_work&&v.push(e.jsx(Ee,{label:d.label.parentWork,children:_.parent_works.map((W,Y)=>e.jsxs("span",{children:[Y>0&&"、",e.jsx(we,{id:W,onNavigate:r,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(ss,{id:k.id,title:p(k.title),edition:k.edition?p(k.edition):void 0,type:k.type,isDraft:z,authors:k.authors,volumeText:I,meta:v,headerExtra:o,onNavigate:r,renderLink:s}),((A=k.description)==null?void 0:A.text)&&e.jsx(Fe,{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((W,Y)=>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(Fe,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},Y))}),j.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.containedIn}),e.jsx(ms,{items:j,onNavigate:r,renderLink:s})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.belongsToWork}),e.jsx(gs,{workData:S,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&e.jsx(ds,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&e.jsx(as,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&e.jsx(cs,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&e.jsx(ls,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&e.jsx(rr,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.resources}),e.jsx(kn,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&e.jsx(ps,{items:C.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&e.jsx(us,{items:T.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&e.jsx(ni,{title:d.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.books)&&T.books.length>0&&e.jsx(ni,{title:d.section.containedBooks,ids:T.books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.contained_works)&&T.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(je,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",T.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:T.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(we,{id:W.id,label:p(W.title),onNavigate:r,renderLink:s})},W.id))})]}),(((F=_==null?void 0:_.books)==null?void 0:F.length)||0)+(((J=_==null?void 0:_.collections)==null?void 0:J.length)||0)>0&&e.jsx(xs,{ids:[...(_==null?void 0:_.books)||[],...(_==null?void 0:_.collections)||[]],workData:_,transport:i,onNavigate:r,renderLink:s,footer:a}),(_==null?void 0:_.related_works)&&_.related_works.length>0&&(()=>{const W=[],Y=_.related_works.filter(V=>V.relation==="part_of"),ie=_.related_works.filter(V=>V.relation==="has_part"),K=_.related_works.filter(V=>V.relation==="has_adaptation"),L=_.related_works.filter(V=>V.relation==="text_carried_by"),U=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),q=_.related_works.filter(V=>!V.relation||!U.has(V.relation));return Y.length>0&&W.push({label:d.section.belongsToWork,items:Y}),ie.length>0&&W.push({label:d.section.containedWorks,items:ie}),K.length>0&&W.push({label:d.section.adaptations,items:K}),L.length>0&&W.push({label:d.section.derivativeWorks,items:L}),q.length>0&&W.push({label:d.section.relatedWorks,items:q}),W.map(V=>e.jsxs("div",{children:[e.jsxs(je,{children:[V.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",V.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:V.items.map(G=>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(we,{id:G.id,label:p(G.title),onNavigate:r,renderLink:s})},G.id))})]},V.label))})()]})};function hs({data:t}){const n=D(),{convert:i}=P(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,o=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]}),o!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",o,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function bs({sections:t,activeSection:n,onSelect:i}){const r=D();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:ii(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:ii(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 ii(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 ys({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.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:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function vs(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],r=t[t.length-1];return r-i+1===t.length?`${i}–${r}`:t.length<=3?t.join(", "):`${i}–${r} (${t.length}${n})`}function ri({book:t,onNavigate:n,renderLink:i,showVolumes:r}){const s=D(),{convert:o}=P(),a=t.book_id||t.work_id,c=r&&t.volumes.length>0?vs(t.volumes,s.unit.volume):null,l=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[o(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=>o(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:o(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:l?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(ys,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const _n=({data:t,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:o,style:a})=>{const c=D(),[l,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[b,y]=f.useState(null),[h,S]=f.useState(""),m=t||l;f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let T=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(_=>{T||(_?d(_):u(c.catalog.notFound))}).catch(_=>{T||u(_ instanceof Error?_.message:c.catalog.loadFailed)}).finally(()=>{T||x(!1)}),()=>{T=!0}},[t,n,i,c]);const j=(m==null?void 0:m.sections)&&m.sections.length>0,w=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const T=m.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(T).size<T.length},[m]),k=f.useMemo(()=>{if(!m)return[];let T=m.books;if(b&&(T=T.filter(_=>_.section===b)),h.trim()){const _=h.trim().toLowerCase();T=T.filter(z=>z.title.toLowerCase().includes(_)||z.sub_items&&z.sub_items.some(I=>I.toLowerCase().includes(_))||z.edition&&z.edition.toLowerCase().includes(_))}return T},[m,b,h]),C=f.useMemo(()=>{if(!w)return null;const T=[],_=new Map;for(const I of k){if(!I.volumes||I.volumes.length===0)continue;const v=I.volumes[0];_.has(v)||_.set(v,[]),_.get(v).push(I)}const z=[..._.keys()].sort((I,v)=>I-v);for(const I of z)T.push({volume:I,books:_.get(I)});return T},[k,w]);return p?e.jsx("div",{className:o,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:o,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:o,style:a,children:[e.jsx(hs,{data:m}),j&&e.jsx(bs,{sections:m.sections,activeSection:b,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:h,onChange:T=>S(T.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:[C?C.map((T,_)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Ct(c.catalog.volume,{n:T.volume})}),T.books.map((z,I)=>e.jsx(ri,{book:z,onNavigate:r,renderLink:s,showVolumes:z.volumes.length>1},`${T.volume}-${I}`))]},`${T.volume}-${_}`)):k.map((T,_)=>e.jsx(ri,{book:T,onNavigate:r,renderLink:s,showVolumes:!0},_)),k.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Xe=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+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)})},fe=6,Bt=7,js=({content:t,children:n,placement:i="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:o})=>{const[a,c]=f.useState(!1),[l,d]=f.useState(null),p=f.useRef(null),x=f.useRef(null),g=f.useRef(null),u=f.useCallback(()=>{const h=x.current,S=g.current;if(!h||!S)return;const m=h.getBoundingClientRect(),j=S.getBoundingClientRect(),w=window.innerHeight,k=document.documentElement.clientWidth;let C=i;i==="top"&&m.top-j.height-Bt<8&&(C="bottom"),i==="bottom"&&m.bottom+j.height+Bt>w-8&&(C="top");const T=C==="top"?m.top-j.height-Bt:m.bottom+Bt;let _=m.left+m.width/2-j.width/2;_=Math.max(8,Math.min(_,k-j.width-8)),d({left:_,top:T,placement:C})},[i]),b=f.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),r)},[r]),y=f.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!a)return;const h=requestAnimationFrame(u);return()=>cancelAnimationFrame(h)},[a,u]),f.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:b,onMouseLeave:y,onFocus:b,onBlur:y,style:{display:"inline-block",...o},children:n}),a&&ho.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(l==null?void 0:l.left)??-9999,top:(l==null?void 0:l.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:l?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-fe,width:0,height:0,...l.placement==="top"?{bottom:-fe,borderTop:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}:{top:-fe,borderBottom:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...l.placement==="top"?{bottom:-5,borderTop:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}:{top:-5,borderBottom:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}}})]})]}),document.body)]})},sr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],Ss={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function pe(t){return Ss[t]??t}const nt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],it={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌: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,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},lr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Vt(t){const n=t.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function ks(t){return t>=1950?"":t>=1912?"民國":t>=1645?"清":t>=1368?"明":t>=1279?"元":t>=960?"宋":t>=907?"五代":t>=618?"唐":t>=581?"隋":t>=420?"南北朝":t>=265?"晉":t>=220?"三國":t>=-202?"漢":""}const ws=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,oi={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function Cn(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(oi))if(n.startsWith(s))return oi[s];const i=pe(n);if(Ge[i]!=null)return i;const r=Ae(n);if(r&&n.length<=r.length+1)return pe(r)}function Ve(t,n){if(n){const i=lr[`${n}|${t}`];if(i!=null)return i}return it[t]}const _s=1911;function Cs(t){const n=it[t];if(n==null)return;const i=Be[t];let r;for(const[s,o]of Object.entries(it))Be[s]===i&&o>n&&(r==null||o<r)&&(r=o);return r!=null?r-1:void 0}const Is={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Ht(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,i=0,r=!1;for(const o of t){const a=Is[o];if(a===void 0)return;r=!0,o==="十"?i=(i||1)*10:o==="廿"||o==="卅"?(n+=a,i=0):i>=10?(n+=i+a,i=0):i=i*10+a}const s=n+i;return r&&s>0?s:void 0}function Ae(t){for(const n of sr)if(t.startsWith(n))return n}const Be={};{const t=(n,i)=>{for(const r of i)Be[r]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ye(t,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(it))if(t.includes(r)&&!(i&&Be[r]&&Be[r]!==i&&lr[`${i}|${r}`]==null))return r}function It(t){var a,c,l;const n={era:"",reign:"",source:"none"},i=t.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(a=t.lineage)==null?void 0:a.year_text;if(r){const d=Ae(r)??"";return{era:pe(d),reign:Ye(r,d)??"",source:"lineage"}}const s=(c=t.publication_info)==null?void 0:c.year;if(s){const d=Vt(s);if(d)return{era:ks(d.from),reign:"",source:"publication"};const p=Ae(s)??Cn(s)??((l=nt.find(u=>u.pattern.test(s)))==null?void 0:l.era)??"",x=Ye(s,p)??"",g=p||(x?Be[x]??"":"");if(g||x)return{era:pe(g),reign:x,source:"publication"}}const o=t.edition||t.title||"";if(o){const d=Ae(o);if(d)return{era:pe(d),reign:Ye(o,d)??"",source:"edition"};const p=nt.find(x=>x.pattern.test(o));if(p)return{era:pe(p.era),reign:Ye(o,p.era)??p.reign??"",source:"edition"}}return n}function Gt(t){var r,s,o,a,c,l,d,p,x;if(((r=t.dating)==null?void 0:r.year)!=null)return t.dating.year;if(typeof((s=t.lineage)==null?void 0:s.year)=="number")return t.lineage.year;const n=(o=t.publication_info)==null?void 0:o.year;if(n){const g=Vt(n);if(g)return g.from}const i=[(a=t.lineage)==null?void 0:a.year_text,(c=t.publication_info)==null?void 0:c.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const g of i){const u=((l=t.publication_info)==null?void 0:l.year)||((d=t.lineage)==null?void 0:d.year_text);if(u&&g!==u&&(Ae(u)||Cn(u)))break;const b=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const j=parseInt(b[1],10);if(j>=100&&j<=2100)return j}const y=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(y){const j=Ae(g);if(!j||pe(j)==="民國"){const k=Ht(y[1]);if(k!=null&&k>=1&&k<=120)return _s+k}}const h=Ae(g)??((p=nt.find(j=>j.pattern.test(g)))==null?void 0:p.era),S=h?pe(h):void 0,m=Ye(g,S)??(Ae(g)||(x=nt.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(m){const j=Ve(m,S);if(j==null)continue;const w=g.indexOf(m),k=w>=0?g.slice(w+m.length):"",C=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),T=C?Ht(C[1]):void 0;return j+(T?T-1:0)}}}function In(t){var a,c,l,d,p,x;const n=(a=t.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(c=t.lineage)==null?void 0:c.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(l=t.lineage)==null?void 0:l.year_text;if(r){const g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const u=pn[pe(g[1])],b=Ge[pe(g[2])];if(u!=null&&b!=null)return{from:Math.min(u,b)-20,to:Math.max(u,b)+40}}}const s=(d=t.publication_info)==null?void 0:d.year;if(s){const g=Vt(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const u=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(u){const b=pn[pe(u[1])],y=Ge[pe(u[2])];if(b!=null&&y!=null)return{from:Math.min(b,y)-20,to:Math.max(b,y)+40}}}const o=[(p=t.publication_info)==null?void 0:p.year,t.edition,t.title].filter(Boolean);for(const g of o){if(!/[間间]/.test(g))continue;const u=Ae(g)??Cn(g)??((x=nt.find(h=>h.pattern.test(g)))==null?void 0:x.era),b=u?pe(u):void 0,y=[];for(const h of Object.keys(it))g.includes(h)&&(b&&Be[h]&&Be[h]!==b||Ve(h,b)!=null&&y.push(h));if(y.length===0){const h=g.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const S of[h[1],h[2]])for(const m of Object.keys(it))if(Be[m]===b&&!(m[0]!==S&&m[m.length-1]!==S)&&Ve(m,b)!=null){y.push(m);break}}}if(y.length>0){const h=y.map(w=>Ve(w,b)).filter(w=>w!=null),S=Math.min(...h),m=y.reduce((w,k)=>Ve(w,b)>=Ve(k,b)?w:k),j=Cs(m)??nn(b??"")??Math.max(...h);return{from:S,to:j>S?j:nn(b??Be[m]??"")??S}}if(b&&Ge[b]!=null)return{from:Ge[b],to:nn(b)??Ge[b]}}}const Ge={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Ts=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],zs=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,si=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function li(t,n){for(const i of sr){const r=t.indexOf(i);if(r<0)continue;if(i.length===1){const l=t[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(l)&&!Ye(t.slice(r),pe(i)))continue}const s=pe(i);if(s===n)continue;const o=t.slice(r),a=Ye(o,s)??"";let c;if(a){const l=Ve(a,s);if(l!=null){const p=o.slice(o.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=p?Ht(p[1]):void 0;c=l+(x?x-1:0)}}return{era:s,reign:a,year:c}}for(const i of nt)if(i.pattern.test(t))return{era:pe(i.era),reign:i.reign??""}}function Rs(t){var S,m,j,w,k;const n=It(t),i=((S=t.publication_info)==null?void 0:S.year)??"",r=i?Vt(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=t.edition||t.title||"",o=/[間间]/.test(s),a=((m=t.lineage)==null?void 0:m.year_text)??"",c=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),l=n.source==="publication"&&ws.test(i),d=n.source==="publication"&&/[間间]/.test(i),p=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;o||c||l||d?x=void 0:p?x=parseInt(p[2],10):x=Gt(t);const g=x==null?In(t):void 0;let u;n.source==="publication"&&(l||si.test(i))?u="uncertain":n.source==="lineage"||n.source==="publication"?u="attested":si.test(s)||!n.reign&&x==null?u="uncertain":u="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=t.lineage)==null?void 0:j.year_text)??((w=t.lineage)==null?void 0:w.year)??""}」`:`出版著錄「${((k=t.publication_info)==null?void 0:k.year)??""}」`,y={era:n.era,reign:n.reign,year:x,yearRange:g,certainty:u,source:n.source==="edition"?"edition":"catalog",basis:b};if(p){const C=a.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==y.era&&(y.laterRepair={era:C[1]})}if(!y.laterRepair&&zs.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(y.laterRepair={era:C[1]})}const h=Ts.find(C=>C.re.test(s));if(h){const C=s.search(h.re),T=s.slice(C),_=li(T,n.era)??li(s,n.era);_&&(y.basedOn={era:_.era,reign:_.reign,year:_.year,relation:h.relation})}return y}const pn={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function nn(t){return pn[t]}function ar(t){const n=Gt(t);if(n!=null)return n;const i=In(t);if(i)return i.from;const r=It(t).era;return r?Ge[r]:void 0}const ai=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function un(t){const n=ai.indexOf(t);return n===-1?ai.length:n}function cr(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const o=s.relation;o==="part_of"?n.belongsTo.push(s):o==="collected_in"?n.collected.push(s):o==="has_part"||o==="contains_text_of"?n.contains.push(s):o==="text_carried_by"||o==="studied_by"||o==="derived_from"||o==="followed_by"||o==="has_adaptation"?n.derivative.push(s):o==="studies"||o==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,o)=>{n[s].length&&i.push({key:s,labelKey:o,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function Yt(t,n){const i=yn(t||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((p,x)=>{const g=u=>u.group_role==="origin"?0:u.group_role==="mirror"?1:2;return g(p)-g(x)});const o={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=Ke(d),x=p.includes("text"),g=p.includes("image");x&&g?o.textImage.push(d):x?o.text.push(d):g?o.image.push(d):o.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>o[d].length>0).map(d=>({key:d,items:o[d]})),l=[...r.entries()].map(([d,p])=>{var x,g;return{key:d,label:((x=n==null?void 0:n[d])==null?void 0:x.label)||d,description:(g=n==null?void 0:n[d])==null?void 0:g.description,items:p}});return{buckets:c,mirrors:l,total:i.length}}function Tn(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 r=vn(t);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Es(t,n){if(Tn(t)||n.filter(r=>r.name===t.name).length<2)return"";try{const r=new URL(t.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const o=r.pathname.split("/").filter(Boolean).pop();if(o)return decodeURIComponent(o)}catch{}return""}function dr(t,n){var o,a;const i=t.resources||[],r=[],s=[];for(const c of i){const l=Ke(c);l.includes("image")&&r.push(c),l.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:It(t),year:Gt(t),sortYear:ar(t),images:r,holders:s,locationName:(o=t.current_location)==null?void 0:o.name,important:Bs(t.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[t.id],hasImage:r.length>0}}function Bs(t,n){var c,l;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(c=n.collections)==null?void 0:c[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(t))return!0;const o=(r==null?void 0:r.groups)??[],a=(l=n.node_groups)==null?void 0:l[t];return!!a&&o.includes(a)}function pr(t,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(l=>!r.has(l.id)).map(l=>dr(l,n));let o=s;i.era&&(o=o.filter(l=>l.era.era===i.era)),i.scanOnly&&(o=o.filter(l=>l.hasImage)),i.sort==="year"?o=o.map((l,d)=>({r:l,i:d})).sort((l,d)=>{const p=l.r.sortYear,x=d.r.sortYear;return p!=null&&x!=null?p-x||l.i-d.i:p!=null?-1:x!=null?1:l.i-d.i}).map(l=>l.r):o=o.map((l,d)=>({r:l,i:d})).sort((l,d)=>{const p=x=>(x.important?0:1)*2+(x.hasImage?0:1);return p(l.r)-p(d.r)||l.i-d.i}).map(l=>l.r);const c=[...new Set(s.map(l=>l.era.era).filter(Boolean))].sort((l,d)=>un(l)-un(d));return{rows:o,allRows:s,eras:c,hasInferredEra:s.some(l=>l.era.source==="edition")}}function Ls(t,n){var h,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,a=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const j=n.node_groups[m];return j!=null&&c.has(j)},p=[],x=new Map,g=[];for(const m of t)if(!((S=n.excluded_books)!=null&&S.includes(m)))if(d(m))p.push(m);else{const j=n.node_groups[m];j?(x.has(j)||x.set(j,[]),x.get(j).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,j)=>m+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,j])=>{const w=b.get(m);return{id:m,label:(w==null?void 0:w.label)??m,description:w==null?void 0:w.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}const ur=["撰","編","注","校","譯","繪","其他"],Ws=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function zn(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of Ws)if(r.test(n))return i;return"其他"}function Rn(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function xr(t){const n=new Map;for(const r of t){const s=zn(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const r of ur){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function fr(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),o=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:o,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(o=>({id:o.id,title:o.title,volumes:vt(o.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var o,a;return{id:s,title:((o=i==null?void 0:i.get(s))==null?void 0:o.title)||s,edition:(a=i==null?void 0:i.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function vt(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,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,o)=>i+o)}return t.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function En(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((o,a)=>o-a),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const $s=["〇","一","二","三","四","五","六","七","八","九"],ci=["","十","百","千"];function gr(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const a=parseInt(n[o]),c=i-1-o;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&o===0?r+=ci[c]:r+=$s[a]+ci[c])}return r}function As(t){return t==null?"":typeof t=="string"?t:t.title??""}function Je(t,n="卷"){var r,s;const i=t;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?gr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function mr(t){var r;if((r=t.lineage)!=null&&r.category)return t.lineage.category;const n=t.edition||t.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,o]of i)if(s.test(n))return o;return""}const mt=1e3,rn=208,Fs="(max-width: 719px)",hr=`
|
|
1
|
+
"use strict";var po=Object.create;var Kn=Object.defineProperty;var uo=Object.getOwnPropertyDescriptor;var xo=Object.getOwnPropertyNames;var fo=Object.getPrototypeOf,go=Object.prototype.hasOwnProperty;var mo=(t,n,i,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of xo(n))!go.call(t,s)&&s!==i&&Kn(t,s,{get:()=>n[s],enumerable:!(r=uo(n,s))||r.enumerable});return t};var dt=(t,n,i)=>(i=t!=null?po(fo(t)):{},mo(n||!t||!t.__esModule?Kn(i,"default",{value:t,enumerable:!0}):i,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("./storage-entry-VGdfSKGX.cjs"),e=require("react/jsx-runtime"),f=require("react"),ho=require("react-markdown"),bo=require("remark-gfm"),yo=require("react-dom"),vo=t=>`/book-index?id=${t}`,Vi=f.createContext(vo);function jo({buildUrl:t,children:n}){const i=f.useMemo(()=>t,[t]);return e.jsx(Vi.Provider,{value:i,children:n})}function be(){return f.useContext(Vi)}function Ke(t){return t.types&&t.types.length>0?t.types:t.type?t.type==="text+image"?["text","image"]:[t.type]:[]}function So(t,n){return Ke(t).includes(n)}const Gi={published:"出版",fine:"精校",rough:"粗校",ocr:"機器識別"},ko={published:"達到出版、學術研究標準,錯誤率在萬分之一以內",fine:"通讀無障礙,錯誤率在百分之一以內",rough:"保證文意基本正確,錯誤率在百分之三以內",ocr:"保持大意和結構,錯誤率在百分之十以內"},wo={published:"#1b5e20",fine:"#2e7d32",rough:"#1565c0",ocr:"#e65100"},_t=f.createContext(null),Ui={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:"收入叢編",collectedIn:"收入叢編",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)",publicationYearLabel:"出版年 (Publication 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:"條"},workSubtype:{book:"書",article:"篇",poem:"詩",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暫無資源信息",hasTranslation:"有",noTranslation:"無",structure:"層級",coverage:"覆蓋",notFoundEntry:"未找到該條目",loadFailed:"加載失敗",textResource:"文字資源",imageResource:"圖片資源"}},_o={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:"收入丛编",collectedIn:"收入丛编",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)",publicationYearLabel:"出版年 (Publication 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:"条"},workSubtype:{book:"书",article:"篇",poem:"诗",chapter:"篇章"},colorMode:{bw:"黑白",color:"彩色"},misc:{noResources:"暂无资源信息",hasTranslation:"有",noTranslation:"无",structure:"层级",coverage:"覆盖",notFoundEntry:"未找到该条目",loadFailed:"加载失败",textResource:"文字资源",imageResource:"图片资源"}},Co={"zh-Hant":Ui,"zh-Hans":_o},Yi="bim-locale";function Io(){try{const t=localStorage.getItem(Yi);if(t==="zh-Hant"||t==="zh-Hans")return t}catch{}}function To(t){try{localStorage.setItem(Yi,t)}catch{}}const zo="zh-Hans",Ro=({locale:t,onLocaleChange:n,children:i})=>{const[r,s]=f.useState(t??zo),o=t??r;f.useEffect(()=>{if(t)return;const p=Io();p&&p!==r&&s(p)},[]);const[a,c]=f.useState(null);f.useEffect(()=>{o==="zh-Hans"?import("opencc-js/t2cn").then(p=>{const x=p.Converter({from:"tw",to:"cn"});c(()=>x)}).catch(()=>{c(()=>p=>p)}):c(null)},[o]);const l=f.useCallback(p=>{s(p),To(p),n==null||n(p)},[n]),d=f.useMemo(()=>({locale:o,setLocale:l,messages:Co[o],converter:a}),[o,l,a]);return e.jsx(_t.Provider,{value:d,children:i})};function D(){const t=f.useContext(_t);return(t==null?void 0:t.messages)??Ui}const Eo=2e3;function P(){const t=f.useContext(_t),n=(t==null?void 0:t.locale)??"zh-Hant",i=(t==null?void 0:t.converter)??null,r=f.useRef(new Map),s=f.useRef(n);s.current!==n&&(r.current.clear(),s.current=n);const o=f.useCallback(a=>{if(!a)return"";if(!i)return a;const c=r.current.get(a);if(c!==void 0)return c;const l=i(a);if(r.current.size>=Eo){const d=r.current.keys().next().value;d!==void 0&&r.current.delete(d)}return r.current.set(a,l),l},[i]);return f.useMemo(()=>({convert:o,locale:n,isSimplified:n==="zh-Hans"}),[o,n])}function Ct(t,n){return t.replace(/\{(\w+)\}/g,(i,r)=>String(n[r]??""))}function Bo(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 r=n.split(".");return r.length>=2?r[r.length-2]:n}catch{return""}}function Lo(){return{id:"",name:"",url:"",type:"text",details:""}}const dn=({items:t,onChange:n,onDownload:i,downloadStatuses:r,filterType:s})=>{const o=D(),[a,c]=f.useState(null),l=[{value:"text",label:o.resourceTypeShort.text},{value:"image",label:o.resourceTypeShort.image},{value:"text+image",label:o.resourceTypeShort.textImage},{value:"physical",label:o.resourceTypeShort.physical}],d=[{value:"catalog",label:o.rootType.catalog},{value:"search",label:o.rootType.search}],p=m=>{if(!s)return!0;const j=Ke(m);return s==="text"?j.includes("text"):s==="image"?j.includes("image")||j.includes("physical"):s==="physical"?j.includes("physical"):j.includes(s)},x=t.map((m,j)=>({item:m,originalIndex:j})).filter(({item:m})=>p(m)),g=()=>{const m=Lo();s&&(m.type=s),n([...t,m]),c(t.length)},u=m=>{n(t.filter((j,w)=>w!==m)),c(null)},b=(m,j,w)=>{const k=[...t];if(k[m]={...k[m],[j]:w},j==="url"&&!k[m].id){const C=Bo(w);C&&(k[m].id=C)}n(k)},y=(m,j,w)=>{const C={...t[m].metadata||{}};w?C[j]=w:delete C[j],b(m,"metadata",Object.keys(C).length>0?C:void 0)},h=(m,j)=>{const w=j.trim()?j.split(/[,,、]/).map(k=>k.trim()).filter(Boolean):void 0;b(m,"structure",w)},S=(m,j,w)=>{const C=t[m].coverage||{level:1,ranges:""};j==="level"?C.level=parseInt(w)||1:C.ranges=w,b(m,"coverage",C.ranges?C:void 0)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[x.map(({item:m,originalIndex:j})=>{var w,k,C;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>c(a===j?null:j),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:a===j?"▼":"▶"}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"3px",background:Wo(m.type??"text"),color:"#fff"},children:(()=>{var _,z;const T=Ke(m);return T.length===0?m.type??"text":T.length===1?((_=l.find(I=>I.value===T[0]))==null?void 0:_.label)??T[0]:T.includes("text")&&T.includes("image")?((z=l.find(I=>I.value==="text+image"))==null?void 0:z.label)??"text+image":T.join("+")})()}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children:m.name||`${o.editor.resourcePlaceholder} ${j+1}`}),m.id&&e.jsx("span",{style:{fontSize:"11px",opacity:.5},children:m.id}),m.url&&e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",onClick:T=>T.stopPropagation(),style:{fontSize:"12px",opacity:.7},children:"🔗"}),i&&m.url&&$o(j,r==null?void 0:r[j],i,o),e.jsx("button",{onClick:T=>{T.stopPropagation(),u(j)},style:{background:"transparent",border:"none",color:"var(--bim-danger, #f44336)",cursor:"pointer",padding:"2px 6px",fontSize:"14px"},title:o.editor.deleteThisResource,children:"✕"})]}),a===j&&e.jsxs("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[So(m,"image")&&m.url&&Ao(m,o),e.jsxs("div",{style:{display:"grid",gap:"8px"},children:[e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.type}),e.jsx("select",{value:m.type,onChange:T=>b(j,"type",T.target.value),style:{...Re,flex:1},children:l.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]}),e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.rootType}),e.jsx("select",{value:m.root_type||"catalog",onChange:T=>b(j,"root_type",T.target.value),style:{...Re,flex:1},children:d.map(T=>e.jsx("option",{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("input",{type:"text",value:m.id,onChange:T=>b(j,"id",T.target.value),placeholder:o.editor.idAutoExtract,style:{...Re,width:"140px",flexShrink:0}}),e.jsx("input",{type:"text",value:m.name,onChange:T=>b(j,"name",T.target.value),placeholder:o.editor.resourceName,style:{...Re,flex:1}})]}),e.jsx("input",{type:"text",value:m.url,onChange:T=>b(j,"url",T.target.value),placeholder:o.editor.resourceUrl,style:Re}),e.jsx("input",{type:"text",value:((w=m.structure)==null?void 0:w.join("、"))||"",onChange:T=>h(j,T.target.value),placeholder:o.editor.structurePlaceholder,style:Re}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("label",{style:pt,children:[e.jsx("span",{style:ut,children:o.label.coverageLevel}),e.jsx("input",{type:"number",min:1,value:((k=m.coverage)==null?void 0:k.level)??"",onChange:T=>S(j,"level",T.target.value),placeholder:"1",style:{...Re,width:"60px"}})]}),e.jsxs("label",{style:{...pt,flex:1},children:[e.jsx("span",{style:ut,children:o.label.coverageRange}),e.jsx("input",{type:"text",value:((C=m.coverage)==null?void 0:C.ranges)||"",onChange:T=>S(j,"ranges",T.target.value),placeholder:o.editor.coverageRangePlaceholder,style:{...Re,flex:1}})]})]}),e.jsx("textarea",{value:m.details||"",onChange:T=>b(j,"details",T.target.value),placeholder:o.editor.detailsPlaceholder,style:{...Re,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:o.label.metadata}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(o.metadata).map(([T,_])=>{var z;return e.jsxs("label",{style:{...pt,gap:"4px"},children:[e.jsx("span",{style:{...ut,minWidth:"56px"},children:_}),e.jsx("input",{type:"text",value:((z=m.metadata)==null?void 0:z[T])||"",onChange:I=>y(j,T,I.target.value),placeholder:_,style:{...Re,flex:1}})]},T)})})]})]})]})]},j)}),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:o.action.addResource})]})]})};function Wo(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 $o(t,n,i,r){const s=(n==null?void 0:n.status)==="downloading",o=(n==null?void 0:n.status)==="completed";return e.jsx("button",{onClick:a=>{a.stopPropagation(),s||i(t,"")},disabled:s,style:{background:"transparent",border:"none",color:o?"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:o?r.download.completed:s?`${r.download.downloading} ${(n==null?void 0:n.progress)||0}%`:r.download.downloadThis,children:o?"✓":s?"⏳":"⬇"})}function Ao(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:r=>{r.target.style.display="none"}})}):e.jsx("div",{style:{padding:"12px",background:"var(--bim-overlay-bg, #00000010)",borderRadius:"4px",fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:n.editor.imageResourceLink})})}const Re={width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box"},pt={display:"flex",alignItems:"center",gap:"6px"},ut={fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},Fo={"commons.wikimedia.org":"維基共享","zh.wikisource.org":"維基文庫","taiwanebook.ncl.edu.tw":"臺灣華文電子書庫","ctext.org":"中國哲學書電子化計劃","www.shidianguji.com":"識典古籍","shidianguji.com":"識典古籍","archive.org":"Internet Archive"};function St(t){try{return Fo[new URL(t).hostname]}catch{return}}const Jn={text:0,image:1,physical:2};function yn(t){return t.length===0?"physical":[...t].sort((n,i)=>(Jn[n]??99)-(Jn[i]??99)).join("+")}function vn(t){var a;const n=c=>{const l=c.match(/^(.+?)·第(\d+)[冊册]$/);if(l)return[l[1],parseInt(l[2])];const d=c.match(/^(.+?)[·(](\d+)[)]?$/);return d?[d[1],parseInt(d[2])]:null},i=new Map;for(let c=0;c<t.length;c++){const l=t[c];if(l.volumes&&l.volumes.length>0)continue;const d=n(l.name);if(!d)continue;const[p,x]=d,g=`${p}|${yn(Ke(l))}`;i.has(g)||i.set(g,{base:{...l,name:p,url:"",volumes:[]},volumes:[],indices:[]});const u=i.get(g);u.volumes.push({volume:x,url:l.url||void 0,status:"found"}),u.indices.push(c)}const r=[],s=new Set;for(const c of i.values())if(!(c.volumes.length<2)){c.volumes.sort((l,d)=>l.volume-d.volume),c.base.volumes=c.volumes,c.base.expected_volumes=c.volumes.length,c.base.url||(c.base.url=((a=c.volumes.find(l=>l.url))==null?void 0:a.url)??""),r.push(c.base);for(const l of c.indices)s.add(l)}const o=[...r];for(let c=0;c<t.length;c++)s.has(c)||o.push(t[c]);return o}function Ki(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 Ji(t){return!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(n=>({...n,url:n.url||Ki(n)}))}function jn(t){const n=Ji(t);if(!n)return null;const i=new Set(n.filter(s=>s.status!=="missing").map(s=>s.volume)).size,r=new Set(n.filter(s=>s.status==="missing").map(s=>s.volume)).size;return{found:i,missing:r,expected:t.expected_volumes??i+r}}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 kn(t,n){try{if(new URL(t).hostname.includes("wikimedia.org")){const r=t.match(/\/wiki\/File:(.+?)(?:#|$)/);if(r)return`https://commons.wikimedia.org/w/index.php?title=File%3A${encodeURIComponent(decodeURIComponent(r[1]))}&page=${n}`;const s=new URL(t);return s.searchParams.set("page",String(n)),s.toString()}return t}catch{return t}}function Pt(t){if(!t.url)return;const n=Sn(t.metadata);return n?kn(t.url,n):t.url}const qn={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 Mo(t){return t.includes("text")&&t.includes("image")?qn["text+image"]:qn[t[0]||"physical"]}const wn=({items:t,groupByType:n=!0,resourceGroups:i,onNavigate:r,renderLink:s})=>{const o=D(),{convert:a}=P(),c=f.useMemo(()=>vn(t||[]),[t]),{mirrorGroups:l,ungroupedItems:d}=f.useMemo(()=>{const h=new Map,S=[];for(const m of c){const j=m.group;j?(h.has(j)||h.set(j,[]),h.get(j).push(m)):S.push(m)}for(const m of h.values())m.sort((j,w)=>{const k=C=>C.group_role==="origin"?0:C.group_role==="mirror"?1:2;return k(j)-k(w)});return{mirrorGroups:h,ungroupedItems:S}},[c]),p={text:o.resourceType.text,image:o.resourceType.image,"text+image":o.resourceType.textImage,physical:o.resourceType.physical},x=h=>p[h]?p[h]:h.split("+").map(S=>p[S]||S).join("+");if(!c||c.length===0)return e.jsx("div",{style:{padding:"16px",color:"var(--bim-desc-fg, #717171)",fontSize:"13px",textAlign:"center"},children:o.misc.noResources});if(!n)return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((h,S)=>e.jsx(Qt,{item:h},h.id||S))});const g=(h,S)=>{const m=i==null?void 0:i[h],j=(m==null?void 0:m.label)||h,w=m==null?void 0:m.description;return e.jsxs("div",{style:{padding:"10px 12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",background:"var(--bim-input-bg, #fafafa)",display:"flex",flexDirection:"column",gap:"8px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(j)}),w&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.5},children:a(w)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((k,C)=>e.jsx(Qt,{item:k,onNavigate:r,renderLink:s},k.id||C))})]},`group-${h}`)},u=new Map;for(const h of d){const S=yn(Ke(h));u.has(S)||u.set(S,[]),u.get(S).push(h)}const b=["text","image","text+image","physical"],y=[...b.filter(h=>u.has(h)),...[...u.keys()].filter(h=>!b.includes(h)).sort()];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:[[...l.entries()].map(([h,S])=>g(h,S)),y.map(h=>{const S=u.get(h),m=Mo(h.split("+"));return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:m,whiteSpace:"nowrap",flexShrink:0},children:x(h)}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:S.map((j,w)=>e.jsx(Qt,{item:j,onNavigate:r,renderLink:s},j.id||w))})]},h)})]})},Po={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)"}},Qt=({item:t})=>{const n=D(),{convert:i}=P(),[r,s]=f.useState(!1),o=f.useMemo(()=>(t.url?St(t.url):void 0)||i(t.name),[t.url,t.name,i]),a=f.useMemo(()=>!Array.isArray(t.volumes)||t.volumes.length===0?null:t.volumes.map(b=>({...b,url:b.url||Ki(b)})),[t.volumes]),c=a&&a.length>0,l=c?new Set(a.filter(b=>b.status!=="missing").map(b=>b.volume)).size:0,d=c?new Set(a.filter(b=>b.status==="missing").map(b=>b.volume)).size:0,p=t.expected_volumes??(c?l+d:0),x=t.color_mode?{...Po[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:o}),x&&e.jsx("span",{style:{padding:"0 5px",borderRadius:"3px",fontSize:"10px",fontWeight:500,background:x.bg,color:x.fg},children:x.label}),g&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:g}),c&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:[l,"/",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 b=Sn(t.metadata);return b?kn(t.url,b):t.url})(),target:"_blank",rel:"noopener noreferrer",style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none",whiteSpace:"nowrap"},children:n.action.visit}),c&&e.jsx("button",{onClick:()=>s(!r),style:{padding:"0 6px",fontSize:"11px",border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",lineHeight:1.4},children:r?"▲":"▼"})]}),c&&r&&e.jsx("div",{style:{padding:"6px 10px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"5px",display:"flex",flexWrap:"wrap",gap:"4px",maxWidth:"360px"},children:a.map(b=>{const y=b.status==="missing";return b.url&&!y?e.jsx("a",{href:b.url,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",borderRadius:"3px",border:"1px solid var(--bim-widget-border, #e0e0e0)",color:"var(--bim-link-fg, #0066cc)",textDecoration:"none"},children:b.volume},b.volume):e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"11px",color:y?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",textDecoration:y?"line-through":"none",opacity:y?.6:1},children:b.volume},b.volume)})})]})},qi=({indexSource:t,syncConfig:n,variant:i="index-browser",onSwitchMode:r,onToggleDraft:s,onConfigurePath:o,onSelectFolder:a})=>{const c=D(),l=t==="local",d=(n==null?void 0:n.isDraft)??!0,p=(n==null?void 0:n.repoPath)||"",x=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"},b=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"?l?e.jsxs("div",{style:{display:"flex",gap:"4px",alignItems:"center"},children:[b,e.jsxs("div",{onClick:r,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:a,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]})]}):e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsxs("div",{onClick:r,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:o,title:x||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:r,title:l?c.mode.switchToGithub:c.mode.switchToLocal,style:g,...u,children:[e.jsx("span",{children:l?"📁":"🌐"}),e.jsx("span",{children:l?c.mode.localMode:c.mode.githubSync}),e.jsx("span",{style:{opacity:.6},children:"⇄"})]}),l&&e.jsxs("div",{onClick:a,title:p||c.mode.selectFolder,style:{...g,paddingLeft:"8px",paddingRight:"8px",minWidth:p?"100px":"auto",justifyContent:"space-between"},...u,children:[e.jsx("span",{children:"📂"}),x&&e.jsx("span",{style:{fontSize:"11px",opacity:.9},children:x})]}),!l&&x&&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:x})]})]})},Nt="bim-search-history",Xn=10,Zn=8;function bt(){try{const t=localStorage.getItem(Nt);return t?JSON.parse(t):[]}catch{return[]}}function Ho(t){try{const n=bt().filter(i=>i!==t);n.unshift(t),n.length>Xn&&(n.length=Xn),localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Oo(t){try{const n=bt().filter(i=>i!==t);localStorage.setItem(Nt,JSON.stringify(n))}catch{}}function Do(){try{localStorage.removeItem(Nt)}catch{}}const Xi=({transport:t,value:n,onChange:i,onSearch:r,onEntrySelect:s,placeholder:o})=>{const a=D(),c=o??a.search.placeholder,l={work:a.indexType.work,book:a.indexType.book,collection:a.indexType.collection,entity:a.indexType.entity},[d,p]=f.useState(!1),[x,g]=f.useState([]),[u,b]=f.useState(-1),[y,h]=f.useState(bt),S=f.useRef(null),m=f.useRef(null),j=f.useRef(null),w=f.useRef(!1);f.useEffect(()=>{b(-1);const v=n.trim();if(!v){g(y.map(M=>({type:"history",text:M})));return}if(!t.searchAll){g([]);return}let R=!1;const E=setTimeout(()=>{t.searchAll(v,Zn).then(M=>{if(R)return;const $=[...M.works,...M.books,...M.collections,...M.entities??[]];g($.slice(0,Zn).map(O=>({type:"entry",text:O.title||O.id,entry:O})))}).catch(()=>{R||g([])})},80);return()=>{R=!0,clearTimeout(E)}},[n,y,t]),f.useEffect(()=>{const v=R=>{j.current&&!j.current.contains(R.target)&&p(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),f.useEffect(()=>{const v=R=>{var E,M;if(R.key==="/"&&document.activeElement!==S.current){const $=(E=document.activeElement)==null?void 0:E.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return;R.preventDefault(),(M=S.current)==null||M.focus()}};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const k=f.useCallback(v=>{v.trim()&&(Ho(v.trim()),h(bt())),r(v),p(!1)},[r]),C=f.useCallback(v=>{v.type==="history"?(i(v.text),k(v.text)):v.entry&&(s?(s(v.entry),p(!1)):(i(v.text),k(v.text)))},[i,k,s]),T=f.useCallback(v=>{if(!d||x.length===0){v.key==="Enter"&&k(n);return}switch(v.key){case"ArrowDown":v.preventDefault(),b(R=>(R+1)%x.length);break;case"ArrowUp":v.preventDefault(),b(R=>(R-1+x.length)%x.length);break;case"Enter":v.preventDefault(),u>=0&&u<x.length?C(x[u]):k(n);break;case"Escape":v.preventDefault(),p(!1);break}},[d,x,u,n,k,C]),_=f.useCallback((v,R)=>{R.stopPropagation(),Oo(v),h(bt()),g(E=>E.filter(M=>!(M.type==="history"&&M.text===v)))},[]),z=f.useCallback(v=>{v.stopPropagation(),Do(),h([]),g([])},[]);f.useEffect(()=>{if(u>=0&&m.current){const v=m.current.children;v[u]&&v[u].scrollIntoView({block:"nearest"})}},[u]);const I=!n.trim()&&y.length>0;return e.jsxs("div",{ref:j,style:{position:"relative",flex:1},children:[e.jsx("input",{ref:S,type:"text",placeholder:c,value:n,onChange:v=>{i(v.target.value),p(!0)},onCompositionStart:()=>{w.current=!0},onCompositionEnd:()=>{w.current=!1},onFocus:()=>{p(!0)},onKeyDown:T,style:{width:"100%",padding:"8px 12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"6px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"14px",boxSizing:"border-box"}}),d&&x.length>0&&e.jsxs("div",{ref:m,style:{position:"absolute",top:"100%",left:0,right:0,marginTop:"4px",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",boxShadow:"0 4px 12px rgba(0,0,0,0.1)",zIndex:100,maxHeight:"320px",overflow:"auto"},children:[I&&e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("span",{children:a.search.history}),e.jsx("button",{onClick:z,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"11px",padding:"0 4px"},children:a.search.clearAll})]}),x.map((v,R)=>e.jsxs("div",{onClick:()=>C(v),style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",cursor:"pointer",fontSize:"13px",color:"var(--bim-fg, #333)",background:R===u?"var(--bim-list-active-bg, #e8f0fe)":"transparent"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.5,width:"16px",textAlign:"center"},children:v.type==="history"?"🕐":"🔍"}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:v.text}),v.entry&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",flexShrink:0},children:[l[v.entry.type],v.entry.edition&&` · ${v.entry.edition}`,v.entry.author&&` · ${v.entry.author}`]}),v.type==="history"&&e.jsx("button",{onClick:E=>_(v.text,E),style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"12px",padding:"0 2px",lineHeight:1},title:a.action.remove,children:"×"})]},`${v.type}-${v.text}-${R}`))]})]})},kt="bim-recent-ids",Qn="bim-recent-entries",ei=50,en=5,No=50,Vo=200;function yt(){try{const t=localStorage.getItem(kt);if(t)return JSON.parse(t);const n=localStorage.getItem(Qn);if(n){const i=JSON.parse(n).map(r=>r.id);return localStorage.setItem(kt,JSON.stringify(i)),localStorage.removeItem(Qn),i}return[]}catch{return[]}}function Go(t){try{const n=yt().filter(i=>i!==t);n.unshift(t),n.length>ei&&(n.length=ei),localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Uo(t){try{const n=yt().filter(i=>i!==t);localStorage.setItem(kt,JSON.stringify(n))}catch{}}function Yo(){try{localStorage.removeItem(kt)}catch{}}const Ko={works:"totalWorks",books:"totalBooks",collections:"totalCollections",entities:"totalEntities"},pn=({transport:t,indexSource:n="local",syncConfig:i,onEntryClick:r,onNewEntry:s,onSwitchMode:o,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l,hideModeIndicator:d,resultVariant:p="compact",renderEntry:x,initialQuery:g,onQueryChange:u,headerRight:b})=>{const y=D(),h=[{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"}],[S,m]=f.useState(g??""),[j,w]=f.useState(null),[k,C]=f.useState(null),[T,_]=f.useState(!1),[z,I]=f.useState(null),[v,R]=f.useState(""),[E,M]=f.useState(!g),[$,O]=f.useState(yt),[A,F]=f.useState([]),[J,W]=f.useState(!1),[U,ie]=f.useState(!1),[K,L]=f.useState(null),[Y,q]=f.useState(null),V=f.useRef(void 0),G=f.useRef(!1),de=f.useCallback(async(N,oe)=>{if(!N.trim()){M(!0),w(null),C(null);return}M(!1),_(!0),R("");try{if(t.searchAll){const ne=await t.searchAll(N,oe??en);w(ne)}else{const ne=["work","book","collection","entity"],B=await Promise.all(ne.map(ee=>t.search(N,ee,{page:1,pageSize:oe??en})));w({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(ne){R(ne instanceof Error?ne.message:String(ne)),w(null)}finally{_(!1)}},[t]);f.useEffect(()=>{let N=!1;const oe=()=>{var X,He;const ne=["work","book","collection","entity"],B=Promise.all(ne.map(ve=>t.loadEntries(ve,{page:1,pageSize:1}).catch(()=>({total:0})))),ee=((X=t.getResourceCounts)==null?void 0:X.call(t).catch(()=>null))??Promise.resolve(null),le=((He=t.getSubtypeStats)==null?void 0:He.call(t).catch(()=>null))??Promise.resolve(null);Promise.all([B,ee,le]).then(([ve,ge,Qe])=>{N||(L({works:ve[0].total,books:ve[1].total,collections:ve[2].total,entities:ve[3].total,hasText:ge==null?void 0:ge.hasText,hasImage:ge==null?void 0:ge.hasImage}),Qe&&q(Qe))})};return t.getCounts?t.getCounts().then(ne=>{var B,ee;N||(L({works:ne.works,books:ne.books,collections:ne.collections,entities:ne.entities,hasText:(B=ne.resourceCounts)==null?void 0:B.hasText,hasImage:(ee=ne.resourceCounts)==null?void 0:ee.hasImage}),ne.subtypeStats&&q(ne.subtypeStats))}).catch(()=>{N||oe()}):oe(),()=>{N=!0}},[t]),f.useEffect(()=>{G.current||!(g!=null&&g.trim())||(G.current=!0,de(g))},[g,de]);const Se=f.useCallback(N=>{if(m(N),!N.trim()){u==null||u(N),M(!0),w(null),C(null);return}V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{C(null),u==null||u(N),de(N)},Vo)},[de,u]),me=f.useCallback(N=>{V.current&&clearTimeout(V.current),u==null||u(N),de(N)},[de,u]),se=f.useCallback(N=>{C(N),de(S,No)},[S,de]);f.useEffect(()=>{if(!$.length){F([]);return}let N=!1;return W(!0),Promise.all($.slice(0,10).map(async oe=>{var ne,B,ee;try{if(t.getEntry){const X=await t.getEntry(oe);if(X)return X}const le=await t.getItem(oe);if(le){const X=le.authors;return{id:oe,title:le.title||oe,type:le.type||"work",author:(ne=X==null?void 0:X[0])==null?void 0:ne.name,dynasty:(B=X==null?void 0:X[0])==null?void 0:B.dynasty,role:(ee=X==null?void 0:X[0])==null?void 0:ee.role,edition:le.edition||void 0}}}catch{}return{id:oe,title:oe,type:"work",notFound:!0}})).then(oe=>{N||(F(oe),W(!1))}),()=>{N=!0}},[$,t]);const ye=N=>{I(N.id),Go(N.id),O(yt()),r==null||r(N)},Ie=N=>{Uo(N),O(yt())},Te=()=>{Yo(),O([])},Ze=N=>h.find(oe=>oe.type===N),ct=j&&(j.works.length>0||j.books.length>0||j.collections.length>0);return e.jsxs("div",{className:"bim-browser-container",children:[e.jsx("header",{style:{padding:"12px 20px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h1",{style:{margin:0,fontSize:"18px",color:"var(--bim-fg, #333)"},children:y.browser.title}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[b,!d&&e.jsx(qi,{variant:"index-browser",indexSource:n,syncConfig:i,onSwitchMode:o,onToggleDraft:a,onConfigurePath:c,onSelectFolder:l})]})]})}),e.jsxs("div",{style:{display:"flex",gap:"8px",padding:"12px 20px",alignItems:"center"},children:[e.jsx(Xi,{transport:t,value:S,onChange:Se,onSearch:me,onEntrySelect:ye}),s&&e.jsx("button",{onClick:()=>s("work"),style:{padding:"8px 14px",border:"1px solid var(--bim-primary, #0078d4)",borderRadius:"6px",background:"transparent",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px"},children:y.action.newEntry})]}),K&&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:K.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:K.collections.toLocaleString()})]}):e.jsxs(e.Fragment,{children:[y.indexType.work," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.works.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.book," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.books.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.collection," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.collections.toLocaleString()}),K.entities>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.indexType.entity," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.entities.toLocaleString()})]})]})}),K.hasImage!=null&&K.hasText!=null&&e.jsxs("span",{children:[y.resourceType.image," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasImage.toLocaleString()}),e.jsx("span",{style:{margin:"0 6px"},children:"·"}),y.resourceType.text," ",e.jsx("strong",{style:{color:"var(--bim-fg, #555)"},children:K.hasText.toLocaleString()})]})]}),e.jsx("div",{style:{padding:"0 20px 20px",flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.searching}):v?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:v})]}):E?e.jsx("div",{style:{flex:1},children:J?e.jsx("div",{style:{textAlign:"center",padding:"40px",color:"var(--bim-desc-fg, #717171)"},children:y.search.loading}):A.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:Te,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:A.slice(0,U?10:3).map(N=>N.notFound?e.jsx(qo,{id:N.id,onRemove:Ie,t:y},N.id):e.jsx(ti,{entry:N,selected:z===N.id,onClick:ye,getConfig:Ze,onRemove:Ie},N.id))}),!U&&A.length>3&&e.jsx("button",{onClick:()=>ie(!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})]})}):ct?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:h.map(({type:N,icon:oe,name:ne,key:B})=>{const ee=j[B]??[],le=Ko[B],X=j[le]??0;if(ee.length===0)return null;const ve=!(k===N)&&X>en;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," ",ne,e.jsxs("span",{style:{fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"6px"},children:[X," ",y.unit.items]})]}),ve&&e.jsx("button",{onClick:()=>se(N),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:ee.map(ge=>{if(x)return e.jsx(f.Fragment,{children:x(ge)},ge.id);const Qe=p==="card"?Jo:ti;return e.jsx(Qe,{entry:ge,selected:z===ge.id,onClick:ye,getConfig:Ze,query:S},ge.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:Ct(y.search.noResultsFor,{query:S})}),e.jsx("p",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:y.search.tryOther})]})})]})},Jo=({entry:t,selected:n,onClick:i,getConfig:r,query:s})=>{const o=D(),{convert:a}=P(),c=a(t.title||t.primary_name||t.id),l=t.measure_info?a(t.measure_info):t.juan_count!=null&&t.juan_count>0?`${t.juan_count}${o.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,x="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, ${x} 50%, var(--bim-widget-border, #e0e0e0))`,background:`linear-gradient(color-mix(in srgb, ${x} 14%, var(--bim-bg, #fff)), color-mix(in srgb, ${x} 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, ${x} 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:x},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}),l&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:l})]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)"},children:[t.dynasty&&e.jsxs("span",{children:["〔",a(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:a(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",a(t.role)]})]}),(t.era||t.edition)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs("span",{children:["〔",a(t.era),"〕"]}),t.edition&&e.jsx("span",{children:a(t.edition)})]}),p&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)"},children:[o.search.alias,":",a(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:[r(t.type).icon," ",r(t.type).name]}),t.has_text&&e.jsxs("span",{style:{fontSize:"11px",padding:"2px 8px",borderRadius:"999px",color:"var(--bim-desc-fg, #717171)",border:"1px solid var(--bim-widget-border, #e0e0e0)"},children:["📝 ",o.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:["🖼️ ",o.misc.imageResource]})]})]})]})},ti=({entry:t,selected:n,onClick:i,getConfig:r,query:s,onRemove:o})=>{const a=D(),{convert:c}=P(),l=[...t.additional_titles||[],...t.attached_texts||[]],d=s&&l.length?l.find(p=>{const x=typeof p=="string"?p:p==null?void 0:p.book_title;return x==null?void 0:x.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:r(t.type).icon}),e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #999)",lineHeight:1},children:r(t.type).name})]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #333)"},children:c(t.title||t.primary_name||t.id)}),e.jsxs("span",{style:{display:"flex",gap:"2px",fontSize:"12px",opacity:.7},children:[t.has_text&&e.jsx("span",{title:a.misc.textResource,children:"📝"}),t.has_image&&e.jsx("span",{title:a.misc.imageResource,children:"🖼️"})]}),(t.era||t.edition)&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.era&&e.jsxs(e.Fragment,{children:["〔",c(t.era),"〕"]}),t.edition&&c(t.edition)]}),t.measure_info?e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:c(t.measure_info)}):t.juan_count!=null&&t.juan_count>0?e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)"},children:[t.juan_count,a.unit.juan]}):null]}),(t.dynasty||t.author)&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[t.dynasty&&e.jsxs("span",{children:["〔",c(t.dynasty),"〕"]}),t.author&&e.jsx("span",{children:c(t.author)}),t.role&&t.role!=="author"&&e.jsxs("span",{children:[" ",c(t.role)]}),t.type==="entity"&&(t.birth_year!=null||t.death_year!=null)&&e.jsxs("span",{style:{marginLeft:t.dynasty?"4px":0},children:[t.birth_year??"?","—",t.death_year??"?"]})]}),d&&e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginTop:"2px"},children:[a.search.alias,":",c(d)]})]}),o?e.jsx("button",{onClick:p=>{p.stopPropagation(),o(t.id)},title:a.search.removeFromRecent,style:{border:"none",background:"transparent",color:"var(--bim-desc-fg, #999)",cursor:"pointer",fontSize:"14px",padding:"2px 4px",lineHeight:1,opacity:.5,marginTop:"2px"},children:"×"}):e.jsx("span",{style:{opacity:.4,marginTop:"2px"},children:"→"})]})},qo=({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 Xo(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 Zo({data:t}){const{convert:n}=P(),{dynasty:i,birth_year:r,death_year:s}=t,o=[];return i&&o.push(`〔${n(i)}〕`),r!==void 0&&s!==void 0?o.push(`${r}—${s}`):r!==void 0?o.push(`${r}—?`):s!==void 0&&o.push(`?—${s}`),o.length===0?null:e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-desc-fg, #717171)",marginLeft:"8px",fontWeight:"normal"},children:o.join(" ")})}function Qo({alt_names:t}){const{convert:n}=P(),i=new Map;for(const o of t){const a=o.type||"別名";i.has(a)||i.set(a,[]),i.get(a).push(o.name)}const r=["字","號","本名","諡號","賜號","常用名","別名","稱號","簡體","行第","小名","小字","俗姓","俗名","廟號","尊號","法號","道號","年號"],s=[...i.keys()].sort((o,a)=>{const c=r.indexOf(o),l=r.indexOf(a);return c===-1&&l===-1?0:c===-1?1:l===-1?-1:c-l});return e.jsx("div",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0 4px"},children:s.map(o=>{const a=i.get(o);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:o}),e.jsx("span",{children:a.map((c,l)=>e.jsxs("span",{children:[l>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),n(c)]},l))})]},o)})})}function es({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 ts({works:t,transport:n,onNavigate:i,renderLink:r}){const s=D(),{convert:o}=P(),a=be(),[c,l]=f.useState(new Map);f.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 j=await n.getEntriesByIds(u);let w=!0;for(let k=0;k<u.length;k++){const C=j[k];C!=null&&C.title?y.set(u[k],C.title):C!=null&&C.primary_name?y.set(u[k],C.primary_name):w=!1}if(w)return y}catch{}const h=[...u],S=8,m=new Array(S).fill(0).map(async()=>{for(;h.length;){const j=h.shift();if(!j)break;if(!y.has(j))try{if(n.getEntry){const C=await n.getEntry(j);if(C!=null&&C.title){y.set(j,C.title);continue}}const w=await n.getItem(j),k=w&&(w.title||w.primary_name)||j;y.set(j,k)}catch{y.set(j,j)}}});return await Promise.all(m),y})().then(y=>{g||l(y)}),()=>{g=!0}},[t,n]);const d=new Map;for(const g of t){const u=g.role||"";d.has(u)||d.set(u,[]),d.get(u).push(g)}const p=["撰","編","注","輯","集","校","評","譯","述","作",""],x=[...d.keys()].sort((g,u)=>{const b=p.indexOf(g),y=p.indexOf(u);return b===-1&&y===-1?g.localeCompare(u):b===-1?1:y===-1?-1:b-y});return e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsxs("h3",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)",margin:"0 0 8px",paddingBottom:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[s.label.relatedWorks," ",e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontWeight:"normal",fontSize:"12px"},children:["(",t.length,")"]})]}),x.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:[o(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((b,y)=>{const h=o(c.get(b.work_id)||b.work_id);return r?e.jsx("li",{children:r(b.work_id,h)},y):i?e.jsx("li",{children:e.jsx("a",{href:a(b.work_id),onClick:S=>{S.metaKey||S.ctrlKey||(S.preventDefault(),i(b.work_id))},style:{color:"var(--bim-link-fg, #0066cc)",textDecoration:"underline",cursor:"pointer"},children:h})},y):e.jsx("li",{children:h},y)})})]},g)})]})}const Zi=({data:t,transport:n,onNavigate:i,renderLink:r,headerExtra:s,hideHeader:o})=>{var x;const a=D(),{convert:c}=P();let l=!1;try{l=Q.extractStatus(t.id)==="draft"}catch{}const d=Xo(t),p=t.subtype==="people"?"人物":t.subtype==="place"?"地名":t.subtype==="dynasty"?"朝代":t.subtype==="anonymous"?"佚名":t.subtype==="collective"?"集体":t.subtype;return e.jsxs("div",{children:[!o&&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(Zo,{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:a.indexType.entity}),p&&t.subtype!=="people"&&e.jsx("span",{children:p}),l&&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:a.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(Qo,{alt_names:t.alt_names}),e.jsx(es,{data:t}),((x=t.description)==null?void 0:x.text)&&e.jsx("p",{style:{fontSize:"14px",color:"var(--bim-fg, #444)",lineHeight:1.9,margin:"8px 0",textAlign:"justify"},children:c(t.description.text)}),t.works&&t.works.length>0&&e.jsx(ts,{works:t.works,transport:n,onNavigate:i,renderLink:r})]})},Qi={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})},ns={...Qi,strong:({children:t})=>e.jsx(e.Fragment,{children:t})},Me=({text:t,plainStrong:n,style:i,className:r})=>{const{convert:s}=P(),o=n?ns:Qi;return e.jsx("div",{className:r,style:i,children:e.jsx(ho,{remarkPlugins:[bo],components:o,children:s(t)})})},is=["〇","一","二","三","四","五","六","七","八","九"],ni=["","十","百","千"];function er(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const a=parseInt(n[o]),c=i-1-o;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&o===0?r+=ni[c]:r+=is[a]+ni[c])}return r}function tr(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 rs={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 os({type:t}){const n=D();return e.jsx("span",{style:tr(rs[t]),children:n.indexType[t]})}function ss({isDraft:t}){const n=D(),i=t?"var(--bim-status-draft, #e67e22)":"var(--bim-status-official, #27ae60)";return e.jsx("span",{style:tr(i),children:t?n.status.draft:n.status.official})}function ls({id:t}){const n=D(),[i,r]=f.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{r(!0),setTimeout(()=>r(!1),1500)})};return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"1px 6px",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",background:"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:o=>o.currentTarget.style.opacity="1",onMouseLeave:o=>o.currentTarget.style.opacity=i?"1":"0.5",children:i?"✓":"⧉"})]})}function je({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 Ee({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 nr({authors:t,type:n,onNavigate:i,renderLink:r}){const{convert:s}=P();return e.jsx("span",{style:{fontSize:"14px",color:"var(--bim-fg, #333)",lineHeight:1.6},children:t.map((o,a)=>{const c=s(o.name),l=o.entity_id?e.jsx(we,{id:o.entity_id,label:c,onNavigate:i,renderLink:r}):e.jsx("span",{style:{fontWeight:500},children:c});return e.jsxs("span",{children:[a>0&&e.jsx("span",{style:{color:"var(--bim-desc-fg, #aaa)",margin:"0 4px"},children:"·"}),o.dynasty&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"12px"},children:["〔",s(o.dynasty),"〕"]}),l,o.role&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px",marginLeft:"2px"},children:[" ",s(o.role)]})]},a)})})}function we({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.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:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{children:n||t})}function as({id:t,title:n,edition:i,type:r,isDraft:s,authors:o,volumeText:a,meta:c,headerExtra:l,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}),a&&e.jsx("span",{style:{fontSize:"15px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"8px"},children:a})]}),l&&e.jsx("div",{style:{flexShrink:0,paddingTop:"2px"},children:l})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap",marginBottom:"4px"},children:[e.jsx(os,{type:r}),e.jsx(ss,{isDraft:s}),e.jsx(ls,{id:t})]}),((o==null?void 0:o.length)||c.length>0)&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"12px",marginTop:"6px"},children:[o&&o.length>0&&e.jsx(nr,{authors:o,type:r,onNavigate:d,renderLink:p}),c]})]})}function ir({items:t,label:n,showMeta:i,onNavigate:r,renderLink:s}){const o=D(),{convert:a}=P();if(!t.length)return null;const[c,l]=f.useState(null);return e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((d,p)=>{const x=c===p;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",transition:"box-shadow 0.15s",...x?{boxShadow:"0 1px 4px rgba(0,0,0,0.06)"}:{}},children:[e.jsxs("div",{onClick:()=>l(x?null: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:x?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsx("span",{style:{fontSize:"13px",fontWeight:600,color:"var(--bim-fg, #333)"},children:a(d.source)}),!x&&i&&d.title_info&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a(d.title_info)}),d.source_bid&&e.jsx("span",{onClick:g=>g.stopPropagation(),style:{fontSize:"11px",marginLeft:"auto",flexShrink:0},children:e.jsx(we,{id:d.source_bid,label:o.action.view,onNavigate:r,renderLink:s})})]}),x&&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(Ee,{label:o.label.titleInfo,children:a(d.title_info)}),d.author_info&&e.jsx(Ee,{label:o.label.authorInfo,children:a(d.author_info)}),d.edition&&e.jsx(Ee,{label:o.label.edition,children:a(d.edition)})]}),d.summary&&e.jsxs("div",{style:{marginTop:"6px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.summary}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(d.summary)})]}),d.comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.comment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.comment)})]}),d.additional_comment&&e.jsxs("div",{style:{marginTop:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:o.section.additionalComment}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(d.additional_comment)})]})]})]},p)})})]})}function cs({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.indexed,showMeta:!0,onNavigate:n,renderLink:i})}function rr({items:t,onNavigate:n,renderLink:i}){const r=D();return e.jsx(ir,{items:t,label:r.section.emendated,onNavigate:n,renderLink:i})}function or({label:t,items:n}){const{convert:i}=P();return n.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:t}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:n.map((r,s)=>{const o=typeof r=="string"?r:r.book_title;return e.jsx("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:i(o)},s)})})]}):null}function ds({items:t}){const n=D();return e.jsx(or,{label:n.section.aliases,items:t})}function ps({items:t}){const n=D();return e.jsx(or,{label:n.section.attachedTexts,items:t})}function us({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.appendix}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:t.map((r,s)=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"baseline",gap:"3px",padding:"3px 8px",fontSize:"13px",color:"var(--bim-fg, #333)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)"},children:["《",i(r.book_title),"》",r.n_juan!=null&&e.jsxs("span",{style:{color:"var(--bim-desc-fg, #999)",fontSize:"12px"},children:[r.n_juan,n.unit.juan]})]},s))})]}):null}function xs({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.locationHistory}),e.jsxs("div",{style:{position:"relative",paddingLeft:"18px"},children:[e.jsx("div",{style:{position:"absolute",left:"4px",top:"6px",bottom:"6px",width:"1px",background:"var(--bim-widget-border, #ddd)"}}),t.map((r,s)=>e.jsxs("div",{style:{position:"relative",marginBottom:"10px"},children:[e.jsx("div",{style:{position:"absolute",left:"-16px",top:"5px",width:"7px",height:"7px",borderRadius:"50%",background:"var(--bim-primary, #8e6f3e)",border:"1.5px solid var(--bim-input-bg, #fff)"}}),e.jsx("span",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:i(r.name)}),r.description&&e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:i(r.description)})]},s))]})]}):null}function fs({items:t}){const n=D(),{convert:i}=P();return t.length?e.jsxs(e.Fragment,{children:[e.jsx(je,{children:n.section.historyOverview}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map((r,s)=>e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.7,paddingLeft:"12px",position:"relative"},children:[e.jsx("span",{style:{position:"absolute",left:0,top:0,color:"var(--bim-desc-fg, #ccc)"},children:"·"}),i(r)]},s))})]}):null}function ii({title:t,ids:n,transport:i,onNavigate:r,renderLink:s}){const{convert:o}=P(),[a,c]=f.useState([]);return f.useEffect(()=>{if(!n.length){c([]);return}if(!i){c(n.map(d=>({id:d})));return}let l=!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=>{l||c(d)}),()=>{l=!0}},[n,i]),n.length?e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[t,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",n.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:(a.length?a:n.map(l=>({id:l}))).map(l=>{const d=l.edition?`${o(l.title)||l.id}(${o(l.edition)})`:o(l.title)||void 0;return e.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",transition:"border-color 0.15s"},children:e.jsx(we,{id:l.id,label:d,onNavigate:r,renderLink:s})},l.id)})})]}):null}function tn({book:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=P(),[o,a]=f.useState(!1),c=t.resources&&t.resources.length>0,l=t.edition?s(t.edition):s(t.title)||void 0;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{padding:"6px 12px",borderBottom:c&&!o?"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(we,{id:t.id,label:l,onNavigate:n,renderLink:i})}),c&&e.jsx("span",{onClick:()=>a(d=>!d),style:{cursor:"pointer",fontSize:"10px",color:"var(--bim-desc-fg, #999)",userSelect:"none",transition:"transform 0.15s",transform:o?"rotate(-90deg)":"rotate(0deg)",display:"inline-block"},title:o?r.action.expand:r.action.collapse,children:"▼"})]}),c&&!o&&e.jsx("div",{style:{padding:"10px 14px"},children:e.jsx(wn,{items:t.resources,resourceGroups:t.resource_groups,groupByType:!0,onNavigate:n,renderLink:i})})]})}function gs({ids:t,workData:n,transport:i,onNavigate:r,renderLink:s,footer:o}){const a=D(),{convert:c}=P(),[l,d]=f.useState([]);if(f.useEffect(()=>{if(!t.length){d([]);return}if(!i){d(t.map(y=>({id:y})));return}let b=!1;return Promise.all(t.map(y=>i.getItem(y).then(h=>({id:y,title:h?h.title:void 0,edition:h?h.edition:void 0,resources:h?h.resources:void 0,resource_groups:h?h.resource_groups:void 0})).catch(()=>({id:y})))).then(y=>{b||d(y)}),()=>{b=!0}},[t,i]),!t.length)return null;const p=l.length?l:t.map(b=>({id:b})),x=new Map(p.map(b=>[b.id,b])),g=n==null?void 0:n.version_graph,u=ms(t,g);return e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[a.section.relatedVersions,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",t.length,")"]})]}),o,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(b=>{const y=x.get(b);return y?e.jsx(tn,{book:y,onNavigate:r,renderLink:s},b):null})}),u.groupedIds.map(b=>e.jsxs("details",{style:{marginTop:12,border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:6,background:"var(--bim-bg-subtle, #fafafa)"},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"8px 14px",fontSize:14,fontWeight:600,color:"var(--bim-fg, #333)",userSelect:"none"},children:[c(b.label),e.jsxs("span",{style:{marginLeft:6,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:["(",b.ids.length,")"]}),b.description&&e.jsx("span",{style:{marginLeft:8,fontSize:12,color:"var(--bim-desc-fg, #888)",fontWeight:400},children:c(b.description)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",padding:"0 12px 12px"},children:b.ids.map(y=>{const h=x.get(y);return h?e.jsx(tn,{book:h,onNavigate:r,renderLink:s},y):null})})]},b.id))]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px",marginTop:"12px"},children:p.map(b=>e.jsx(tn,{book:b,onNavigate:r,renderLink:s},b.id))})]})}function ms(t,n){var h,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,a=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const j=n.node_groups[m];return j!=null&&c.has(j)},p=[],x=new Map,g=[];for(const m of t)if(!((S=n.excluded_books)!=null&&S.includes(m)))if(d(m))p.push(m);else{const j=n.node_groups[m];j?(x.has(j)||x.set(j,[]),x.get(j).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,j)=>m+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,j])=>{const w=b.get(m);return{id:m,label:(w==null?void 0:w.label)??m,description:w==null?void 0:w.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}function hs({workData:t,onNavigate:n,renderLink:i}){var a,c,l,d;const r=D(),{convert:s}=P(),o=!!((a=t.description)!=null&&a.text)||!!t.parent_work;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",overflow:"hidden",background:"var(--bim-input-bg, #fff)",marginTop:"4px"},children:[e.jsxs("div",{style:{padding:"6px 14px",borderBottom:o?"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(we,{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:[er(t.juan_count.number),r.unit.juan]}):null,t.authors&&t.authors.length>0&&e.jsx("span",{style:{fontSize:"13px"},children:e.jsx(nr,{authors:t.authors,type:"work",onNavigate:n,renderLink:i})})]}),o&&e.jsxs("div",{style:{padding:"8px 14px"},children:[((l=t.description)==null?void 0:l.text)&&e.jsx(Me,{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(Ee,{label:r.label.parentWork,children:e.jsx(we,{id:t.parent_work.id,label:s(t.parent_work.title),onNavigate:n,renderLink:i})})})]})]})}function bs({items:t,onNavigate:n,renderLink:i}){const r=D(),{convert:s}=P();return t.length?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginTop:"6px"},children:t.map(o=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:"4px",padding:"3px 10px",fontSize:"13px",border:"1px solid color-mix(in srgb, var(--bim-type-collection, #2471a3) 25%, transparent)",borderRadius:"4px",background:"color-mix(in srgb, var(--bim-type-collection, #2471a3) 3%, transparent)"},children:[e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-type-collection, #2471a3)"},children:r.indexType.collection}),e.jsx(we,{id:o.id,label:s(o.title)||o.id,onNavigate:n,renderLink:i}),o.volume_index!=null&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginLeft:"2px"},children:Ct(r.catalog.volume,{n:o.volume_index})})]},o.id))}):null}const _n=({data:t,id:n,transport:i,onNavigate:r,renderLink:s,headerExtra:o,relatedBooksFooter:a,className:c,style:l})=>{var R,E,M,$,O,A,F,J;const d=D(),{convert:p}=P(),[x,g]=f.useState(null),[u,b]=f.useState(!1),[y,h]=f.useState(null),[S,m]=f.useState(null),[j,w]=f.useState([]),k=t||x;if(f.useEffect(()=>{if(t||!n||!i)return;let W=!1;return b(!0),h(null),i.getItem(n).then(U=>{W||(U?g(U):h(d.misc.notFoundEntry))}).catch(U=>{W||h(U instanceof Error?U.message:d.misc.loadFailed)}).finally(()=>{W||b(!1)}),()=>{W=!0}},[t,n,i]),f.useEffect(()=>{if(!k||!i){m(null),w([]);return}let W=!1;const U=k.type==="book"||k.type==="collection"?k.work_id:void 0;if(U?i.getItem(U).then(ie=>{!W&&ie&&ie.type==="work"&&m(ie)}).catch(()=>{}):m(null),k.type==="book"){const ie=k;ie.contained_in&&ie.contained_in.length>0?Promise.all(ie.contained_in.map(K=>{const L=typeof K=="string"?K:K.id,Y=typeof K=="string"?void 0:K.volume_index;return i.getItem(L).then(q=>({id:L,title:q&&q.title||L,volume_index:Y})).catch(()=>({id:L,title:L,volume_index:Y}))})).then(K=>{W||w(K)}):w([])}else w([]);return()=>{W=!0}},[k,i]),u)return e.jsx("div",{className:c,style:{...l,padding:"24px"},children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[180,260,160].map((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(y)return e.jsx("div",{className:c,style:{...l,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:l,children:e.jsx(Zi,{data:k,transport:i,onNavigate:r,renderLink:s,headerExtra:o})});const C=k.type==="book"?k:null,T=k.type==="collection"?k:null,_=k.type==="work"?k:null;let z=!1;try{z=Q.extractStatus(k.id)==="draft"}catch{}let I="";k.measure_info?I=p(k.measure_info):(R=k.juan_count)!=null&&R.number?I=er(k.juan_count.number)+d.unit.juan:(E=k.juan_count)!=null&&E.description&&(I=p(k.juan_count.description));const v=[];return(M=k.publication_info)!=null&&M.year&&v.push(e.jsx(Ee,{label:d.label.year,children:k.publication_info.year},"year")),($=k.current_location)!=null&&$.name&&v.push(e.jsx(Ee,{label:d.label.currentLocation,children:p(k.current_location.name)},"loc")),(O=k.page_count)!=null&&O.description&&v.push(e.jsx(Ee,{label:d.label.pageCount,children:k.page_count.description},"page")),C!=null&&C.edition&&v.push(e.jsx(Ee,{label:d.label.edition,children:p(C.edition)},"ver")),_!=null&&_.parent_work&&v.push(e.jsx(Ee,{label:d.label.parentWork,children:e.jsx(we,{id:_.parent_work.id,label:p(_.parent_work.title),onNavigate:r,renderLink:s})},"pw")),_!=null&&_.parent_works&&_.parent_works.length>0&&!_.parent_work&&v.push(e.jsx(Ee,{label:d.label.parentWork,children:_.parent_works.map((W,U)=>e.jsxs("span",{children:[U>0&&"、",e.jsx(we,{id:W,onNavigate:r,renderLink:s})]},W))},"pws")),e.jsxs("div",{className:c,style:l,children:[e.jsx(as,{id:k.id,title:p(k.title),edition:k.edition?p(k.edition):void 0,type:k.type,isDraft:z,authors:k.authors,volumeText:I,meta:v,headerExtra:o,onNavigate:r,renderLink:s}),((A=k.description)==null?void 0:A.text)&&e.jsx(Me,{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((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(Me,{text:W.text,plainStrong:!0,style:{marginTop:8,fontSize:13,lineHeight:1.9,color:"var(--bim-fg, #444)"}})]},U))}),j.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.containedIn}),e.jsx(bs,{items:j,onNavigate:r,renderLink:s})]}),S&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.belongsToWork}),e.jsx(hs,{workData:S,onNavigate:r,renderLink:s})]}),k.additional_works&&k.additional_works.length>0&&e.jsx(us,{items:k.additional_works}),k.additional_titles&&k.additional_titles.length>0&&e.jsx(ds,{items:k.additional_titles}),k.attached_texts&&k.attached_texts.length>0&&e.jsx(ps,{items:k.attached_texts}),k.indexed_by&&k.indexed_by.length>0&&e.jsx(cs,{items:k.indexed_by,onNavigate:r,renderLink:s}),k.emendated_by&&k.emendated_by.length>0&&e.jsx(rr,{items:k.emendated_by,onNavigate:r,renderLink:s}),k.resources&&k.resources.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:d.section.resources}),e.jsx(wn,{items:k.resources,resourceGroups:k.resource_groups,groupByType:!0,onNavigate:r,renderLink:s})]}),(C==null?void 0:C.location_history)&&C.location_history.length>0&&e.jsx(xs,{items:C.location_history}),(T==null?void 0:T.history)&&T.history.length>0&&e.jsx(fs,{items:T.history}),(C==null?void 0:C.related_books)&&C.related_books.length>0&&e.jsx(ii,{title:d.section.relatedVersions,ids:C.related_books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.books)&&T.books.length>0&&e.jsx(ii,{title:d.section.containedBooks,ids:T.books,transport:i,onNavigate:r,renderLink:s}),(T==null?void 0:T.contained_works)&&T.contained_works.length>0&&e.jsxs("div",{children:[e.jsxs(je,{children:[d.section.containedWorks,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",T.contained_works.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:T.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(we,{id:W.id,label:p(W.title),onNavigate:r,renderLink:s})},W.id))})]}),(((F=_==null?void 0:_.books)==null?void 0:F.length)||0)+(((J=_==null?void 0:_.collections)==null?void 0:J.length)||0)>0&&e.jsx(gs,{ids:[...(_==null?void 0:_.books)||[],...(_==null?void 0:_.collections)||[]],workData:_,transport:i,onNavigate:r,renderLink:s,footer:a}),(_==null?void 0:_.related_works)&&_.related_works.length>0&&(()=>{const W=[],U=_.related_works.filter(V=>V.relation==="part_of"),ie=_.related_works.filter(V=>V.relation==="has_part"),K=_.related_works.filter(V=>V.relation==="has_adaptation"),L=_.related_works.filter(V=>V.relation==="text_carried_by"),Y=new Set(["part_of","has_part","has_adaptation","text_carried_by"]),q=_.related_works.filter(V=>!V.relation||!Y.has(V.relation));return U.length>0&&W.push({label:d.section.belongsToWork,items:U}),ie.length>0&&W.push({label:d.section.containedWorks,items:ie}),K.length>0&&W.push({label:d.section.adaptations,items:K}),L.length>0&&W.push({label:d.section.derivativeWorks,items:L}),q.length>0&&W.push({label:d.section.relatedWorks,items:q}),W.map(V=>e.jsxs("div",{children:[e.jsxs(je,{children:[V.label,e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400},children:["(",V.items.length,")"]})]}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:V.items.map(G=>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(we,{id:G.id,label:p(G.title),onNavigate:r,renderLink:s})},G.id))})]},V.label))})()]})};function ys({data:t}){const n=D(),{convert:i}=P(),{stats:r}=t,s=r.processed_volumes??r.total_found_volumes,o=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]}),o!=null&&e.jsxs("span",{children:[n.catalog.processed," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:s})," ",n.unit.volume," (",o,"%)"]}),e.jsxs("span",{children:[n.catalog.contains," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.total_books})," ",n.unit.bu]}),r.matched_works!=null&&r.matched_works>0&&e.jsxs("span",{children:[n.catalog.matched," ",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:r.matched_works})," ",n.unit.bu]}),r.unmatched_works!=null&&r.unmatched_works>0&&e.jsxs("span",{children:[n.catalog.unmatched," ",e.jsx("strong",{style:{color:"var(--bim-missing-fg, #e67e22)"},children:r.unmatched_works})," ",n.unit.bu]})]}),t.source&&e.jsxs("div",{style:{marginTop:"6px",fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[n.catalog.source," ",t.source]})]})}function vs({sections:t,activeSection:n,onSelect:i}){const r=D();return e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"16px"},children:[e.jsx("button",{onClick:()=>i(null),style:ri(n===null),children:r.catalog.all}),t.map(s=>e.jsxs("button",{onClick:()=>i(s.name),style:ri(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 ri(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 js({id:t,label:n,onNavigate:i,renderLink:r}){const s=be();return r?e.jsx(e.Fragment,{children:r(t,n)}):i?e.jsx("a",{href:s(t),onClick:o=>{o.metaKey||o.ctrlKey||(o.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:o=>o.currentTarget.style.borderBottomStyle="solid",onMouseLeave:o=>o.currentTarget.style.borderBottomStyle="dashed",children:n||t}):e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:n||t})}function Ss(t,n){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=t[0],r=t[t.length-1];return r-i+1===t.length?`${i}–${r}`:t.length<=3?t.join(", "):`${i}–${r} (${t.length}${n})`}function oi({book:t,onNavigate:n,renderLink:i,showVolumes:r}){const s=D(),{convert:o}=P(),a=t.book_id||t.work_id,c=r&&t.volumes.length>0?Ss(t.volumes,s.unit.volume):null,l=t.missing_volumes&&t.missing_volumes.length>0;return e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",padding:"6px 12px",borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",fontSize:"14px",lineHeight:1.8},children:[r&&e.jsx("span",{style:{flexShrink:0,minWidth:"48px",fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right"},children:c}),e.jsxs("span",{style:{flex:1,fontWeight:500,color:"var(--bim-fg, #1a1a1a)"},children:[o(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=>o(d)).join("、"),")"]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)",fontWeight:400,marginLeft:"8px"},children:o(t.edition)})]}),t.expected_volumes!=null&&e.jsxs("span",{style:{fontSize:"11px",color:l?"var(--bim-missing-fg, #e67e22)":"var(--bim-desc-fg, #999)",flexShrink:0},children:[t.found_volumes??0,"/",t.expected_volumes,s.unit.volume]}),a&&e.jsx(js,{id:a,label:t.book_id?s.indexType.book:s.indexType.work,onNavigate:n,renderLink:i}),!a&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #ccc)",flexShrink:0},children:s.catalog.unmatched_label})]})}const Cn=({data:t,collectionId:n,transport:i,onNavigate:r,renderLink:s,className:o,style:a})=>{const c=D(),[l,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[b,y]=f.useState(null),[h,S]=f.useState(""),m=t||l;f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollectionCatalog))return;let T=!1;return x(!0),u(null),i.getCollectionCatalog(n).then(_=>{T||(_?d(_):u(c.catalog.notFound))}).catch(_=>{T||u(_ instanceof Error?_.message:c.catalog.loadFailed)}).finally(()=>{T||x(!1)}),()=>{T=!0}},[t,n,i,c]);const j=(m==null?void 0:m.sections)&&m.sections.length>0,w=f.useMemo(()=>{if(!m)return!1;if(m.volume_index&&Object.keys(m.volume_index).length>0)return!0;const T=m.books.map(z=>z.volumes[0]).filter(z=>z!=null);return new Set(T).size<T.length},[m]),k=f.useMemo(()=>{if(!m)return[];let T=m.books;if(b&&(T=T.filter(_=>_.section===b)),h.trim()){const _=h.trim().toLowerCase();T=T.filter(z=>z.title.toLowerCase().includes(_)||z.sub_items&&z.sub_items.some(I=>I.toLowerCase().includes(_))||z.edition&&z.edition.toLowerCase().includes(_))}return T},[m,b,h]),C=f.useMemo(()=>{if(!w)return null;const T=[],_=new Map;for(const I of k){if(!I.volumes||I.volumes.length===0)continue;const v=I.volumes[0];_.has(v)||_.set(v,[]),_.get(v).push(I)}const z=[..._.keys()].sort((I,v)=>I-v);for(const I of z)T.push({volume:I,books:_.get(I)});return T},[k,w]);return p?e.jsx("div",{className:o,style:{...a,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:c.catalog.loading})}):g?e.jsx("div",{className:o,style:{...a,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g}):m?e.jsxs("div",{className:o,style:a,children:[e.jsx(ys,{data:m}),j&&e.jsx(vs,{sections:m.sections,activeSection:b,onSelect:y}),e.jsxs("div",{style:{marginBottom:"12px"},children:[e.jsx("input",{type:"text",placeholder:c.search.searchBookName,value:h,onChange:T=>S(T.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:[C?C.map((T,_)=>e.jsxs("div",{children:[e.jsx("div",{style:{padding:"4px 12px",background:"var(--bim-bg, #f8f8f8)",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",fontSize:"12px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",position:"sticky",top:0,zIndex:1},children:Ct(c.catalog.volume,{n:T.volume})}),T.books.map((z,I)=>e.jsx(oi,{book:z,onNavigate:r,renderLink:s,showVolumes:z.volumes.length>1},`${T.volume}-${I}`))]},`${T.volume}-${_}`)):k.map((T,_)=>e.jsx(oi,{book:T,onNavigate:r,renderLink:s,showVolumes:!0},_)),k.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:c.catalog.noMatch})]})]}):null},Xe=()=>{const[t,n]=f.useState(1);return f.useEffect(()=>{const i=setInterval(()=>n(r=>r>=3?1:r+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)})},fe=6,Bt=7,ks=({content:t,children:n,placement:i="top",delayMs:r=100,maxWidth:s=280,wrapperStyle:o})=>{const[a,c]=f.useState(!1),[l,d]=f.useState(null),p=f.useRef(null),x=f.useRef(null),g=f.useRef(null),u=f.useCallback(()=>{const h=x.current,S=g.current;if(!h||!S)return;const m=h.getBoundingClientRect(),j=S.getBoundingClientRect(),w=window.innerHeight,k=document.documentElement.clientWidth;let C=i;i==="top"&&m.top-j.height-Bt<8&&(C="bottom"),i==="bottom"&&m.bottom+j.height+Bt>w-8&&(C="top");const T=C==="top"?m.top-j.height-Bt:m.bottom+Bt;let _=m.left+m.width/2-j.width/2;_=Math.max(8,Math.min(_,k-j.width-8)),d({left:_,top:T,placement:C})},[i]),b=f.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>c(!0),r)},[r]),y=f.useCallback(()=>{p.current&&clearTimeout(p.current),c(!1),d(null)},[]);return f.useEffect(()=>{if(!a)return;const h=requestAnimationFrame(u);return()=>cancelAnimationFrame(h)},[a,u]),f.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),e.jsxs(e.Fragment,{children:[e.jsx("span",{ref:x,onMouseEnter:b,onMouseLeave:y,onFocus:b,onBlur:y,style:{display:"inline-block",...o},children:n}),a&&yo.createPortal(e.jsxs("div",{ref:g,role:"tooltip",style:{position:"fixed",left:(l==null?void 0:l.left)??-9999,top:(l==null?void 0:l.top)??-9999,maxWidth:s,padding:"6px 10px",fontSize:"12px",lineHeight:1.5,color:"var(--bim-fg, #333)",background:"var(--bim-input-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",boxShadow:"0 2px 8px rgba(0,0,0,0.08)",pointerEvents:"none",zIndex:9999,opacity:l?1:0,transition:"opacity 80ms ease-out",whiteSpace:"normal",wordBreak:"break-word"},children:[t,l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-fe,width:0,height:0,...l.placement==="top"?{bottom:-fe,borderTop:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}:{top:-fe,borderBottom:`${fe}px solid var(--bim-widget-border, #e0e0e0)`,borderLeft:`${fe}px solid transparent`,borderRight:`${fe}px solid transparent`}}}),e.jsx("span",{style:{position:"absolute",left:"50%",marginLeft:-5,width:0,height:0,...l.placement==="top"?{bottom:-5,borderTop:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}:{top:-5,borderBottom:`${fe-1}px solid var(--bim-input-bg, #fff)`,borderLeft:`${fe-1}px solid transparent`,borderRight:`${fe-1}px solid transparent`}}})]})]}),document.body)]})},sr=["西漢","東漢","三國","西晉","東晉","南北朝","南朝","北朝","隋","唐","五代","北宋","南宋","宋","遼","西夏","金","元","南明","明","清","民國","日本","朝鮮","高麗","越南","琉球","西汉","东汉","西晋","东晋","南北朝","南朝","北朝","辽","民国","朝鲜","高丽"],ws={北宋:"宋",南宋:"宋",西漢:"漢",東漢:"漢",西汉:"漢",东汉:"漢",西晉:"晉",東晉:"晉",西晋:"晉",东晋:"晉",南明:"明",民国:"民國",辽:"遼",朝鲜:"朝鮮",高丽:"高麗",南北朝:"南北朝",南朝:"南北朝",北朝:"南北朝"};function pe(t){return ws[t]??t}const nt=[{pattern:/欽定四庫全書薈要|摛藻堂/,era:"清",reign:"乾隆"},{pattern:/欽定四庫全書|四庫全書|文淵閣|文瀾閣|文溯閣|文津閣|文匯閣|文宗閣|文瀾閣/,era:"清",reign:"乾隆"},{pattern:/钦定四库全书|四库全书|文渊阁|文澜阁|文溯阁|文津阁/,era:"清",reign:"乾隆"},{pattern:/武英殿聚珍|聚珍版/,era:"清",reign:"乾隆"},{pattern:/武英殿/,era:"清"},{pattern:/百衲本|涵芬樓|涵芬楼|商務印書館|商务印书馆|中華書局|中华书局/,era:"民國"},{pattern:/汲古閣|汲古阁/,era:"明",reign:"崇禎"}],it={熹平:172,建安:196,黃初:220,正始:240,廣政:938,太康:280,永和:345,開皇:581,貞觀:627,開元:713,天寶:742,貞元:785,元和:806,開成:836,會昌: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,弘光:1645,隆武:1645,紹武:1646,永曆:1647,順治:1644,康熙:1662,雍正:1723,乾隆:1736,嘉慶:1796,道光:1821,咸豐:1851,同治:1862,光緒:1875,宣統:1909,慶長:1596,寬永:1624,正保:1644,慶安:1648,承應:1652,明曆:1655,萬治:1658,寬文:1661,延寶:1673,天和:1681,貞享:1684,元祿:1688,寶永:1704,享保:1716,元文:1736,寬保:1741,延享:1744,寬延:1748,寶曆:1751,明和:1764,安永:1772,天明:1781,寬政:1789,享和:1801,文化:1804,文政:1818,天保:1830,弘化:1844,嘉永:1848,安政:1854,萬延:1860,文久:1861,元治:1864,慶應:1865,明治:1868,大正:1912,昭和:1926,天正:1573,文祿:1592,永祿:1558,天文:1532},lr={"唐|元和":806,"日本|元和":1615,"明|正德":1506,"日本|正德":1711};function Vt(t){const n=t.match(/^\s*(\d{3,4})(?:\s*[-–—~至]\s*(\d{3,4}))?/);if(!n)return;const i=parseInt(n[1],10);if(i<100||i>2100)return;const r=n[2]?parseInt(n[2],10):void 0;return{from:i,to:r!=null&&r>=i&&r<=2100?r:void 0}}function _s(t){return t>=1950?"":t>=1912?"民國":t>=1645?"清":t>=1368?"明":t>=1279?"元":t>=960?"宋":t>=907?"五代":t>=618?"唐":t>=581?"隋":t>=420?"南北朝":t>=265?"晉":t>=220?"三國":t>=-202?"漢":""}const Cs=/末[宋元明清]初|[約约]|推定|推算|前後|前后|左右|[前中後后末]期/,si={曹魏:"三國",蜀漢:"三國",東吳:"三國",前蜀:"五代",後蜀:"五代"};function In(t){const n=t.trim().replace(/[代朝]$/,"");for(const s of Object.keys(si))if(n.startsWith(s))return si[s];const i=pe(n);if(Ge[i]!=null)return i;const r=Ae(n);if(r&&n.length<=r.length+1)return pe(r)}function Ve(t,n){if(n){const i=lr[`${n}|${t}`];if(i!=null)return i}return it[t]}const Is=1911;function Ts(t){const n=it[t];if(n==null)return;const i=Be[t];let r;for(const[s,o]of Object.entries(it))Be[s]===i&&o>n&&(r==null||o<r)&&(r=o);return r!=null?r-1:void 0}const zs={零:0,"〇":0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9,十:10,廿:20,卅:30,元:1};function Ht(t){if(!t)return;if(/^\d+$/.test(t))return parseInt(t,10);let n=0,i=0,r=!1;for(const o of t){const a=zs[o];if(a===void 0)return;r=!0,o==="十"?i=(i||1)*10:o==="廿"||o==="卅"?(n+=a,i=0):i>=10?(n+=i+a,i=0):i=i*10+a}const s=n+i;return r&&s>0?s:void 0}function Ae(t){for(const n of sr)if(t.startsWith(n))return n}const Be={};{const t=(n,i)=>{for(const r of i)Be[r]=n};t("東漢",["熹平","建安"]),t("三國",["黃初","正始"]),t("五代",["廣政"]),t("西晉",["太康"]),t("東晉",["永和"]),t("隋",["開皇"]),t("唐",["貞觀","開元","天寶","貞元","元和","開成","會昌","咸通"]),t("宋",["建隆","太平興國","咸平","天禧","慶曆","皇祐","嘉祐","治平","熙寧","元豐","元祐","紹聖","崇寧","大觀","政和","宣和","建炎","紹興","隆興","乾道","淳熙","紹熙","慶元","嘉泰","開禧","嘉定","寶慶","紹定","端平","嘉熙","淳祐","寶祐","開慶","景定","咸淳"]),t("金",["大定","明昌"]),t("元",["至元","大德","皇慶","延祐","泰定","天曆","至順","至正"]),t("明",["洪武","永樂","宣德","正統","景泰","天順","成化","弘治","正德","嘉靖","隆慶","萬曆","泰昌","天啟","崇禎","弘光","隆武","紹武","永曆"]),t("清",["順治","康熙","雍正","乾隆","嘉慶","道光","咸豐","同治","光緒","宣統"]),t("日本",["慶長","寬永","正保","慶安","承應","明曆","萬治","寬文","延寶","天和","貞享","元祿","寶永","享保","元文","寬保","延享","寬延","寶曆","明和","安永","天明","寬政","享和","文化","文政","天保","弘化","嘉永","安政","萬延","文久","元治","慶應","明治","大正","昭和","天正","文祿","永祿","天文"])}function Ue(t,n){const i=n==="北宋"||n==="南宋"?"宋":n;for(const r of Object.keys(it))if(t.includes(r)&&!(i&&Be[r]&&Be[r]!==i&&lr[`${i}|${r}`]==null))return r}function It(t){var a,c,l;const n={era:"",reign:"",source:"none"},i=t.dating;if(i!=null&&i.era||i!=null&&i.reign)return{era:i.era??"",reign:i.reign??"",source:i.certainty==="attested"?"catalog":"edition"};const r=(a=t.lineage)==null?void 0:a.year_text;if(r){const d=Ae(r)??"";return{era:pe(d),reign:Ue(r,d)??"",source:"lineage"}}const s=(c=t.publication_info)==null?void 0:c.year;if(s){const d=Vt(s);if(d)return{era:_s(d.from),reign:"",source:"publication"};const p=Ae(s)??In(s)??((l=nt.find(u=>u.pattern.test(s)))==null?void 0:l.era)??"",x=Ue(s,p)??"",g=p||(x?Be[x]??"":"");if(g||x)return{era:pe(g),reign:x,source:"publication"}}const o=t.edition||t.title||"";if(o){const d=Ae(o);if(d)return{era:pe(d),reign:Ue(o,d)??"",source:"edition"};const p=nt.find(x=>x.pattern.test(o));if(p)return{era:pe(p.era),reign:Ue(o,p.era)??p.reign??"",source:"edition"}}return n}function Gt(t){var r,s,o,a,c,l,d,p,x;if(((r=t.dating)==null?void 0:r.year)!=null)return t.dating.year;if(typeof((s=t.lineage)==null?void 0:s.year)=="number")return t.lineage.year;const n=(o=t.publication_info)==null?void 0:o.year;if(n){const g=Vt(n);if(g)return g.from}const i=[(a=t.lineage)==null?void 0:a.year_text,(c=t.publication_info)==null?void 0:c.year,t.edition,t.edition?void 0:t.title].filter(Boolean);for(const g of i){const u=((l=t.publication_info)==null?void 0:l.year)||((d=t.lineage)==null?void 0:d.year_text);if(u&&g!==u&&(Ae(u)||In(u)))break;const b=g.match(/(?:^|[^\d第卷冊册頁页])(\d{3,4})\s*年/)??g.match(/[((](\d{3,4})\s*(?:[-–—~至]\s*\d{3,4})?\s*年?[))]/);if(b){const j=parseInt(b[1],10);if(j>=100&&j<=2100)return j}const y=g.match(/民[國国]\s*([零〇一二三四五六七八九十廿卅百元\d]+)\s*年/);if(y){const j=Ae(g);if(!j||pe(j)==="民國"){const k=Ht(y[1]);if(k!=null&&k>=1&&k<=120)return Is+k}}const h=Ae(g)??((p=nt.find(j=>j.pattern.test(g)))==null?void 0:p.era),S=h?pe(h):void 0,m=Ue(g,S)??(Ae(g)||(x=nt.find(j=>j.pattern.test(g)))==null?void 0:x.reign);if(m){const j=Ve(m,S);if(j==null)continue;const w=g.indexOf(m),k=w>=0?g.slice(w+m.length):"",C=k.match(/^([零〇一二三四五六七八九十廿卅元]+)年/)??k.match(/^[甲乙丙丁戊己庚辛壬癸][子丑寅卯辰巳午未申酉戌亥]\s*[((]\s*([零〇一二三四五六七八九十廿卅元]+)\s*年?\s*[))]/),T=C?Ht(C[1]):void 0;return j+(T?T-1:0)}}}function Tn(t){var a,c,l,d,p,x;const n=(a=t.dating)==null?void 0:a.year_range;if(n&&n.length===2)return{from:n[0],to:n[1]};const i=(c=t.lineage)==null?void 0:c.year_range;if(i&&i.length===2)return{from:i[0],to:i[1]};const r=(l=t.lineage)==null?void 0:l.year_text;if(r){const g=r.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(g){const u=un[pe(g[1])],b=Ge[pe(g[2])];if(u!=null&&b!=null)return{from:Math.min(u,b)-20,to:Math.max(u,b)+40}}}const s=(d=t.publication_info)==null?void 0:d.year;if(s){const g=Vt(s);if((g==null?void 0:g.to)!=null)return{from:g.from,to:g.to};const u=s.match(/([宋元明清])\s*末\s*([宋元明清])\s*初/);if(u){const b=un[pe(u[1])],y=Ge[pe(u[2])];if(b!=null&&y!=null)return{from:Math.min(b,y)-20,to:Math.max(b,y)+40}}}const o=[(p=t.publication_info)==null?void 0:p.year,t.edition,t.title].filter(Boolean);for(const g of o){if(!/[間间]/.test(g))continue;const u=Ae(g)??In(g)??((x=nt.find(h=>h.pattern.test(g)))==null?void 0:x.era),b=u?pe(u):void 0,y=[];for(const h of Object.keys(it))g.includes(h)&&(b&&Be[h]&&Be[h]!==b||Ve(h,b)!=null&&y.push(h));if(y.length===0){const h=g.match(/([一-鿿])([一-鿿])[間间]/);if(h&&b){for(const S of[h[1],h[2]])for(const m of Object.keys(it))if(Be[m]===b&&!(m[0]!==S&&m[m.length-1]!==S)&&Ve(m,b)!=null){y.push(m);break}}}if(y.length>0){const h=y.map(w=>Ve(w,b)).filter(w=>w!=null),S=Math.min(...h),m=y.reduce((w,k)=>Ve(w,b)>=Ve(k,b)?w:k),j=Ts(m)??nn(b??"")??Math.max(...h);return{from:S,to:j>S?j:nn(b??Be[m]??"")??S}}if(b&&Ge[b]!=null)return{from:Ge[b],to:nn(b)??Ge[b]}}}const Ge={漢:-202,三國:220,晉:265,南北朝:420,隋:581,唐:618,五代:907,宋:960,遼:916,西夏:1038,金:1115,元:1271,明:1368,清:1644,民國:1912,日本:1600,朝鮮:1392,高麗:918,越南:1400,琉球:1400},Rs=[{re:/影印|景印|影鈔|影钞|景鈔|景钞/,relation:"影印"},{re:/翻刻|覆刻|覆刊|翻雕|重刊|重雕/,relation:"翻刻"},{re:/傳鈔|传钞|傳抄|传抄/,relation:"傳鈔"},{re:/配補|配补|百衲/,relation:"配補"},{re:/據.{0,12}本|据.{0,12}本/,relation:"據刊"}],Es=/修補|修补|遞修|递修|[明清元宋]修本|後代修|后代修/,li=/約|约|疑|傳為|传为|舊題|旧题|相傳|相传|待考|未詳|未详|\(疑\)|(疑)/;function ai(t,n){for(const i of sr){const r=t.indexOf(i);if(r<0)continue;if(i.length===1){const l=t[r+1]??"";if(!/[刻刊寫写鈔钞抄印本間间初末年時时代人臧藏]/.test(l)&&!Ue(t.slice(r),pe(i)))continue}const s=pe(i);if(s===n)continue;const o=t.slice(r),a=Ue(o,s)??"";let c;if(a){const l=Ve(a,s);if(l!=null){const p=o.slice(o.indexOf(a)+a.length).match(/^([零〇一二三四五六七八九十廿卅元]+)年/),x=p?Ht(p[1]):void 0;c=l+(x?x-1:0)}}return{era:s,reign:a,year:c}}for(const i of nt)if(i.pattern.test(t))return{era:pe(i.era),reign:i.reign??""}}function Bs(t){var S,m,j,w,k;const n=It(t),i=((S=t.publication_info)==null?void 0:S.year)??"",r=i?Vt(i):void 0;if(!n.era&&!n.reign&&!r)return;const s=t.edition||t.title||"",o=/[間间]/.test(s),a=((m=t.lineage)==null?void 0:m.year_text)??"",c=/末[宋元明清]初|[約约]|推定|前後|前后|左右/.test(a),l=n.source==="publication"&&Cs.test(i),d=n.source==="publication"&&/[間间]/.test(i),p=a.match(/([宋元明清])[^、,,]*?[((](\d{3,4})[))][^、,,]*?原刻/);let x;o||c||l||d?x=void 0:p?x=parseInt(p[2],10):x=Gt(t);const g=x==null?Tn(t):void 0;let u;n.source==="publication"&&(l||li.test(i))?u="uncertain":n.source==="lineage"||n.source==="publication"?u="attested":li.test(s)||!n.reign&&x==null?u="uncertain":u="inferred";const b=n.source==="edition"?`題名「${s}」`:n.source==="lineage"?`版本傳承著錄「${((j=t.lineage)==null?void 0:j.year_text)??((w=t.lineage)==null?void 0:w.year)??""}」`:`出版著錄「${((k=t.publication_info)==null?void 0:k.year)??""}」`,y={era:n.era,reign:n.reign,year:x,yearRange:g,certainty:u,source:n.source==="edition"?"edition":"catalog",basis:b};if(p){const C=a.match(/[、,,]\s*([宋元明清])/);C&&C[1]!==y.era&&(y.laterRepair={era:C[1]})}if(!y.laterRepair&&Es.test(s)){const C=s.match(/([宋元明清])\s*(?:初|末)?\s*(?:修補|修补|遞修|递修|修)/);C&&C[1]!==n.era&&(y.laterRepair={era:C[1]})}const h=Rs.find(C=>C.re.test(s));if(h){const C=s.search(h.re),T=s.slice(C),_=ai(T,n.era)??ai(s,n.era);_&&(y.basedOn={era:_.era,reign:_.reign,year:_.year,relation:h.relation})}return y}const un={漢:220,三國:280,晉:420,南北朝:589,隋:618,唐:907,五代:960,宋:1279,遼:1125,西夏:1227,金:1234,元:1368,明:1662,清:1911,民國:1975,日本:1912,朝鮮:1897,高麗:1392,越南:1945,琉球:1879};function nn(t){return un[t]}function ar(t){const n=Gt(t);if(n!=null)return n;const i=Tn(t);if(i)return i.from;const r=It(t).era;return r?Ge[r]:void 0}const ci=["漢","三國","晉","南北朝","隋","唐","五代","宋","遼","西夏","金","元","明","清","民國","日本","朝鮮","高麗","越南","琉球"];function xn(t){const n=ci.indexOf(t);return n===-1?ci.length:n}function cr(t){const n={belongsTo:[],collected:[],contains:[],derivative:[],studies:[],related:[]};for(const s of t){const o=s.relation;o==="part_of"?n.belongsTo.push(s):o==="collected_in"?n.collected.push(s):o==="has_part"||o==="contains_text_of"?n.contains.push(s):o==="text_carried_by"||o==="studied_by"||o==="derived_from"||o==="followed_by"||o==="has_adaptation"?n.derivative.push(s):o==="studies"||o==="preceded_by"?n.studies.push(s):n.related.push(s)}const i=[],r=(s,o)=>{n[s].length&&i.push({key:s,labelKey:o,items:n[s]})};return r("belongsTo","belongsToWork"),r("collected","collectedIn"),r("contains","containedWorks"),r("derivative","derivativeWorks"),r("studies","studies"),r("related","relatedWorks"),i}function Ut(t,n){const i=vn(t||[]),r=new Map,s=[];for(const d of i)d.group?(r.has(d.group)||r.set(d.group,[]),r.get(d.group).push(d)):s.push(d);for(const d of r.values())d.sort((p,x)=>{const g=u=>u.group_role==="origin"?0:u.group_role==="mirror"?1:2;return g(p)-g(x)});const o={text:[],image:[],textImage:[],physical:[]};for(const d of s){const p=Ke(d),x=p.includes("text"),g=p.includes("image");x&&g?o.textImage.push(d):x?o.text.push(d):g?o.image.push(d):o.physical.push(d)}const c=["text","image","textImage","physical"].filter(d=>o[d].length>0).map(d=>({key:d,items:o[d]})),l=[...r.entries()].map(([d,p])=>{var x,g;return{key:d,label:((x=n==null?void 0:n[d])==null?void 0:x.label)||d,description:(g=n==null?void 0:n[d])==null?void 0:g.description,items:p}});return{buckets:c,mirrors:l,total:i.length}}function zn(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 r=jn(t);return r&&r.expected>0&&n.push(r.missing>0?`${r.found} / ${r.expected} 冊 缺 ${r.missing}`:`${r.found} / ${r.expected} 冊`),i.version&&n.push(String(i.version)),n.join(" · ")}function Ls(t,n){if(zn(t)||n.filter(r=>r.name===t.name).length<2)return"";try{const r=new URL(t.url),s=r.searchParams.get("res")||r.searchParams.get("id");if(s)return s;const o=r.pathname.split("/").filter(Boolean).pop();if(o)return decodeURIComponent(o)}catch{}return""}function dr(t,n){var o,a;const i=t.resources||[],r=[],s=[];for(const c of i){const l=Ke(c);l.includes("image")&&r.push(c),l.includes("physical")&&s.push(c)}return{id:t.id,name:t.edition||t.title||t.id,era:It(t),year:Gt(t),sortYear:ar(t),images:r,holders:s,locationName:(o=t.current_location)==null?void 0:o.name,important:Ws(t.id,n),group:(a=n==null?void 0:n.node_groups)==null?void 0:a[t.id],hasImage:r.length>0}}function Ws(t,n){var c,l;if(!n)return!1;const i=n.default_collection;if(!i)return!1;const r=(c=n.collections)==null?void 0:c[i];if(((r==null?void 0:r.book_ids)??(i==="core"?n.core_books??[]:[])).includes(t))return!0;const o=(r==null?void 0:r.groups)??[],a=(l=n.node_groups)==null?void 0:l[t];return!!a&&o.includes(a)}function pr(t,n,i={}){const r=new Set((n==null?void 0:n.excluded_books)??[]),s=t.filter(l=>!r.has(l.id)).map(l=>dr(l,n));let o=s;i.era&&(o=o.filter(l=>l.era.era===i.era)),i.scanOnly&&(o=o.filter(l=>l.hasImage)),i.sort==="year"?o=o.map((l,d)=>({r:l,i:d})).sort((l,d)=>{const p=l.r.sortYear,x=d.r.sortYear;return p!=null&&x!=null?p-x||l.i-d.i:p!=null?-1:x!=null?1:l.i-d.i}).map(l=>l.r):o=o.map((l,d)=>({r:l,i:d})).sort((l,d)=>{const p=x=>(x.important?0:1)*2+(x.hasImage?0:1);return p(l.r)-p(d.r)||l.i-d.i}).map(l=>l.r);const c=[...new Set(s.map(l=>l.era.era).filter(Boolean))].sort((l,d)=>xn(l)-xn(d));return{rows:o,allRows:s,eras:c,hasInferredEra:s.some(l=>l.era.source==="edition")}}function $s(t,n){var h,S;if(!n||!n.default_collection||!n.node_groups)return{useGrouping:!1,coreIds:t,groupedIds:[]};const i=(h=n.collections)==null?void 0:h[n.default_collection],r=(i==null?void 0:i.groups)??[],s=(i==null?void 0:i.book_ids)??[],o=r.length>0||s.length>0,a=!o&&n.default_collection==="core"&&Array.isArray(n.core_books)?n.core_books:[];if(!o&&a.length===0)return{useGrouping:!1,coreIds:t,groupedIds:[]};const c=new Set(r),l=new Set([...s,...a]),d=m=>{if(l.has(m))return!0;const j=n.node_groups[m];return j!=null&&c.has(j)},p=[],x=new Map,g=[];for(const m of t)if(!((S=n.excluded_books)!=null&&S.includes(m)))if(d(m))p.push(m);else{const j=n.node_groups[m];j?(x.has(j)||x.set(j,[]),x.get(j).push(m)):g.push(m)}if(g.length+[...x.values()].reduce((m,j)=>m+j.length,0)<3)return{useGrouping:!1,coreIds:t,groupedIds:[]};const b=new Map((n.groups??[]).map(m=>[m.id,m])),y=[...x.entries()].map(([m,j])=>{const w=b.get(m);return{id:m,label:(w==null?void 0:w.label)??m,description:w==null?void 0:w.description,ids:j}});return g.length>0&&y.push({id:"__other__",label:"其他版本",description:void 0,ids:g}),{useGrouping:!0,coreIds:p,groupedIds:y}}const ur=["撰","編","注","校","譯","繪","其他"],As=[{cls:"譯",re:/譯|译/},{cls:"繪",re:/繪|绘|畫|画|圖|图|篆|摹/},{cls:"校",re:/^(?!.*[編编輯辑纂])(?=.*(校|訂|订|勘|審|审|考異)).*/},{cls:"注",re:/注|註|疏|箋|笺|解|釋|释|音|義疏|章句|評|评|批|論|论|答/},{cls:"編",re:/編|编|輯|辑|纂|集|選|选|錄|录|彙|汇|續|续|補|补|刪|删|修|次|定/},{cls:"撰",re:/撰|譔|作|著|述|製|制|書|书|記|记|傳|传|題|题|序|跋|讚|贊|赞|頌|颂/}];function Rn(t){if(!t||!t.trim())return"撰";const n=t.replace(/[\s-]/g,"");if(!n||n==="author")return"撰";for(const{cls:i,re:r}of As)if(r.test(n))return i;return"其他"}function En(t){if(!t)return"";const n=t.trim();return!n||!/[一-鿿]/.test(n)?"":n}function xr(t){const n=new Map;for(const r of t){const s=Rn(r);n.set(s,(n.get(s)??0)+1)}const i=[{cls:"全部",label:"全部",count:t.length}];for(const r of ur){const s=n.get(r);s&&i.push({cls:r,label:r,count:s})}return i.length>2?i:[]}function fr(t,n,i){if(n&&n.books&&n.books.length>0){const s=n.books.map(a=>({id:a.work_id||a.book_id||void 0,title:a.title,section:a.section,volumes:a.volumes||[],subItems:a.sub_items,edition:a.edition,found:a.found_volumes,expected:a.expected_volumes})),o=[...new Set(s.map(a=>a.section).filter(Boolean))];return{rows:s,source:"catalog",sections:o,totalVolumes:n.total_volumes}}return t.contained_works&&t.contained_works.length>0?{rows:t.contained_works.map(o=>({id:o.id,title:o.title,volumes:vt(o.volume_index)})),source:"works",sections:[]}:{rows:(t.books||[]).map(s=>{var o,a;return{id:s,title:((o=i==null?void 0:i.get(s))==null?void 0:o.title)||s,edition:(a=i==null?void 0:i.get(s))==null?void 0:a.edition,volumes:[]}}),source:"books",sections:[]}}function vt(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,r]=[parseInt(n[1]),parseInt(n[2])];return Array.from({length:Math.max(0,r-i+1)},(s,o)=>i+o)}return t.split(/[,、]/).map(i=>parseInt(i.trim())).filter(i=>!isNaN(i))}return[]}function Bn(t,n="冊"){if(t.length===0)return"";if(t.length===1)return`${t[0]}`;const i=[...t].sort((o,a)=>o-a),r=i[0],s=i[i.length-1];return s-r+1===i.length?`${r}–${s}`:i.length<=3?i.join(", "):`${r}–${s} (${i.length}${n})`}const Fs=["〇","一","二","三","四","五","六","七","八","九"],di=["","十","百","千"];function gr(t){if(t<=0)return"";if(t>=1e4)return String(t);const n=String(t),i=n.length;let r="",s=!1;for(let o=0;o<i;o++){const a=parseInt(n[o]),c=i-1-o;a===0?s=!0:(s&&r&&(r+="〇"),s=!1,a===1&&c===1&&o===0?r+=di[c]:r+=Fs[a]+di[c])}return r}function Ms(t){return t==null?"":typeof t=="string"?t:t.title??""}function Je(t,n="卷"){var r,s;const i=t;return i.measure_info?i.measure_info:(r=i.juan_count)!=null&&r.number?gr(i.juan_count.number)+n:(s=i.juan_count)!=null&&s.description?i.juan_count.description:""}function mr(t){var r;if((r=t.lineage)!=null&&r.category)return t.lineage.category;const n=t.edition||t.title||"",i=[[/活字|聚珍/,"活字本"],[/石印/,"石印本"],[/影印|景印/,"影印本"],[/寫本|写本|繕寫|缮写/,"寫本"],[/鈔本|抄本/,"抄本"],[/拓本/,"拓本"],[/批校|評本|评本|校本/,"校本"],[/刻本|刊本|梓行|開雕/,"刻本"],[/排印|鉛印|铅印/,"排印本"]];for(const[s,o]of i)if(s.test(n))return o;return""}const mt=1e3,rn=208,Ps="(max-width: 719px)",hr=`
|
|
2
2
|
.bim-d-page {
|
|
3
3
|
background: var(--bim-page-bg, #fbf9f3);
|
|
4
4
|
color: var(--bim-ink, #2a231c);
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
align-items: start; margin-bottom: 48px; }
|
|
76
76
|
.bim-d-pair-wide { grid-template-columns: 1fr 1.2fr; }
|
|
77
77
|
|
|
78
|
-
@media ${
|
|
78
|
+
@media ${Ps} {
|
|
79
79
|
.bim-d-intro { grid-template-columns: 1fr; gap: 20px; margin-bottom: 32px; }
|
|
80
80
|
.bim-d-pair, .bim-d-pair-wide { grid-template-columns: 1fr; gap: 40px; }
|
|
81
81
|
/* 表格:meta 列折到第二行,表头隐藏 */
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
padding-right: 0; padding-bottom: 12px;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
`;function $t({children:t,style:n,wide:i}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:hr}),e.jsx("div",{className:i?"bim-d-main bim-d-main-wide":"bim-d-main",children:t})]})}function br({aside:t,children:n}){return e.jsxs("div",{className:"bim-d-reader",children:[e.jsx("aside",{className:"bim-d-reader-aside bim-d-ui",children:t}),e.jsx("div",{className:"bim-d-reader-main",children:n})]})}function yr({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
|
|
97
|
-
`)||(n.push({start:i,end:o+1,inner:a}),i=o)}return n}function Oe(t,n=i=>i){if(!t)return"";if(t.indexOf("⟨")<0&&t.indexOf("<")<0)return n(t);const i=[];let r=0,s=0;for(const o of Ms(t))o.start>r&&i.push(e.jsx(f.Fragment,{children:n(t.slice(r,o.start))},s++)),i.push(e.jsx("span",{className:"bim-jiazhu",style:{fontSize:".78em",color:"var(--bim-meta-fg, #7b6a54)",lineHeight:1.55},children:n(o.inner)},s++)),r=o.end;return r<t.length&&i.push(e.jsx(f.Fragment,{children:n(t.slice(r))},s++)),i}function At({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 xn({title:t,tag:n,children:i}){const{convert:r}=P();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:r(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:r(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function wr({name:t,note:n,href:i,extra:r}){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})]}),o={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:o,children:s}):e.jsx("div",{style:o,children:s}),r]})}function ot({item:t,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=P(),[o,a]=f.useState(!1),c=vn(t),l=i&&!!c&&c.expected>0,d=(t.url?St(t.url):void 0)||s(t.name),p=n?Es(t,n):"",x=p?`${d}(${p})`:d;return e.jsx(wr,{name:x,note:Tn(t)||r,href:Pt(t),extra:l?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>a(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:o?"收起分冊":`展開 ${c.expected} 冊`}),o&&e.jsx(_r,{item:t})]}):void 0})}function _r({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 r=n.status==="missing";return n.url&&!r?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:r?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function Ln({label:t,items:n}){const{convert:i}=P();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((r,s)=>e.jsx(Rt,{children:i(r)},s))]}):null}function Cr({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(Ln,{label:i.label,items:i.items},i.label))}):null}function wt(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function Ir({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 st({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 _e({id:t,label:n,onNavigate:i,renderLink:r,style:s,dense:o}){const a=be();return r?e.jsx(e.Fragment,{children:r(t,typeof n=="string"?n:void 0,{dense:o})}):e.jsx("a",{href:a(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function fn({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 di={A:"fine",B:"rough",C:"rough",D:"ocr"};function Ps(t){return typeof t!="string"?null:t in Gi?t:t in di?di[t]:null}const Hs={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Os={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function xe(t){return typeof t!="string"?"":Hs[t]??Os[t]??t}const Ds=["〇","一","二","三","四","五","六","七","八","九"],pi=["","十","百","千"],Ns=["","萬","億"];function Tr(t){if(t===0)return"〇";if(t<0)return`負${Tr(-t)}`;const n=[];let i=t,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Vs(s,r>0)+Ns[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Vs(t,n){const i=[];let r=t;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let o=0;o<i.length;o++){const a=i[o],c=i.length-1-o;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&c===1&&o===0&&!n?s+=pi[c]:s+=Ds[a]+pi[c]}return s.replace(/〇$/,"")}let jt=null,Lt=null;const Ot=new Set;function Gs(){return jt?Promise.resolve():Lt||(Lt=import("opencc-js/t2cn").then(t=>{jt=t.Converter({from:"tw",to:"cn"}),Ot.forEach(n=>n())}).catch(()=>{jt=t=>t,Ot.forEach(t=>t())}),Lt)}function Me(){const[,t]=f.useState(0);return f.useEffect(()=>{if(jt)return;const n=()=>t(i=>i+1);return Ot.add(n),Gs(),()=>{Ot.delete(n)}},[]),jt??(n=>n)}function lt(t,n){return n(t).toLowerCase()}const Wn="var(--bim-highlight-bg, #fff59d)";function at(t,n,i){if(!n)return t;const r=lt(n,i);if(!r)return t;const s=lt(t,i);if(s.length!==t.length)return t;const o=[];let a=0,c=0;for(;a<t.length;){const l=s.indexOf(r,a);if(l===-1){o.push(t.slice(a));break}l>a&&o.push(t.slice(a,l)),o.push(e.jsx("mark",{style:{background:Wn,padding:0,color:"inherit"},children:t.slice(l,l+r.length)},c++)),a=l+r.length}return e.jsx(e.Fragment,{children:o})}function $n(t,n,i,r){if(!n)return!0;const s=lt(n,r);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(a=>typeof a=="string"&<(a,r).includes(s))}function Ys(t,n,i){return n?lt(t,i).includes(lt(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)"},Us={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Ks(t){const n=t.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function gn({file:t,isActive:n,onSelect:i,meta:r,matchState:s,vertical:o}){const a=s===0,c=s==="loading",l=typeof s=="number"&&s>0,d=r!=null&&r.vol_label?`${r.vol_label}冊`:null,p=d??Ks(t),x=!d&&!!(r!=null&&r.vol_label)&&!p.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{a||i(t)},disabled:a,style:{padding:o?"4px 8px":"3px 8px",textAlign:o?"left":"center",width:o?"100%":void 0,border:o?"1px solid transparent":n?"1px solid var(--bim-primary, #8e6f3e)":a?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderLeft:o?`2px solid ${n?"var(--bim-primary, #8e6f3e)":"transparent"}`:void 0,borderRadius:o?0:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":l?`${Wn}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":a?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:a?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:a?.5:1},children:[p,x&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function zr(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(r=>zr(r,n)))}function Rr(t){var r;const n=t.files.length,i=((r=t.children)==null?void 0:r.reduce((s,o)=>s+Rr(o),0))||0;return n+i}function Js(t,n){const i=[],r=a=>{var c;i.push(...a.files),(c=a.children)==null||c.forEach(r)};if(r(t),i.length===0)return;const s=i.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let o=0;for(const a of s)typeof a=="number"&&(o+=a);return o}function Er({group:t,activeFile:n,onSelect:i,depth:r=0,juanMeta:s,matchStates:o,vertical:a}){var y;const c=zr(t,n||""),l=Js(t,o),d=typeof l=="number"&&l>0,p=l===0,[x,g]=f.useState(c||d),u=Rr(t),b=!!((y=t.children)!=null&&y.length);if(f.useEffect(()=>{c&&g(!0)},[c]),f.useEffect(()=>{d&&g(!0)},[d]),t.files.length===1&&!b){const h=t.files[0],S=n===h,m=o[h],j=m===0,w=m==="loading",k=typeof m=="number"&&m>0;return e.jsxs("button",{onClick:()=>{j||i(h)},disabled:j,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:S?"1px solid var(--bim-primary, #8e6f3e)":j?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:S?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":k?`${Wn}40`:"transparent",color:S?"var(--bim-primary, #8e6f3e)":j?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:j?"not-allowed":"pointer",fontSize:"12px",fontWeight:S?600:400,lineHeight:1.4,opacity:j?.5:1},children:[t.label,k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:m}),w&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>g(!x),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:c?"var(--bim-primary, #8e6f3e)":p?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:p?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",u,")"]}),d&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",l]}),l==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:a?"column":"row",flexWrap:a?"nowrap":"wrap",gap:a?"1px":"4px",padding:a?`2px 0 2px ${8+r*10}px`:`4px 0 4px ${24+r*16}px`},children:t.files.map(h=>e.jsx(gn,{file:h,isActive:n===h,onSelect:i,meta:s==null?void 0:s[h],matchState:o[h],vertical:a},h))}),b&&t.children.map((h,S)=>e.jsx(Er,{group:h,activeFile:n,onSelect:i,depth:r+1,juanMeta:s,matchStates:o,vertical:a},S))]})]})}function qs({files:t,groups:n,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:a}){const c=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:a?0:"16px"},children:n.map((l,d)=>e.jsx(Er,{group:l,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:a},d))}):c.length===0?null:a?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1px"},children:c.map(l=>e.jsx(gn,{file:l,isActive:i===l,onSelect:r,meta:s==null?void 0:s[l],matchState:o[l],vertical:!0},l))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:c.map(l=>e.jsx(gn,{file:l,isActive:i===l,onSelect:r,meta:s==null?void 0:s[l],matchState:o[l]},l))})}function Xs({type:t}){const n=xe(t),i=An[n]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Zs({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),s=be(),o=Me(),a=y=>y?Oe(r(y),h=>i?at(h,i,o):h):"",[c,l]=f.useState(!1),d=!!t.summary,p=!!t.comment,x=!!t.additional_comment,g=!!(t.content&&t.content.length>60),u=d||p||x||g;f.useEffect(()=>{i&&l(!0)},[i]);const b=!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&&l(!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:["《",a(t.book_title),"》"]}):a(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Tr(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:a(t.author_info||t.author)})]}),!c&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:a(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"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:a(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.additional_comment)})]}),g&&!d&&!p&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)})]})]})}function Qs({section:t,highlightQuery:n=""}){const{convert:i}=P(),r=Me(),s=l=>l?Oe(i(l),d=>n?at(d,n,r):d):"",[o,a]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&a(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(Xs,{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:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${An[xe(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)})})]})}const el=100;function Br(t){return xe(t.type)!=="page_header"?!1:(t.content||"").length>=el}function tl({section:t,highlightQuery:n=""}){const{convert:i}=P(),r=Me();if(xe(t.type)==="page_header"&&!Br(t)||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
98
|
-
`)),o=n?at(
|
|
99
|
-
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:o.map((a,c)=>{if(a.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(a.slice(2))},c);if(a.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(a.slice(3))},c);if(a.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(a.slice(4))},c);if(!a.trim())return c>0&&!o[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const l=a.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},p):e.jsx(f.Fragment,{children:s(d)},p))},c)})})}function sl({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),s=be(),o=Me(),a=d=>d?Oe(r(d),p=>i?at(p,i,o):p):"",c=[];let l=null;for(const d of t){const p=xe(d.type);p==="page_header"&&!Br(d)||(p==="类"?(l&&c.push(l),l={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(l||(l={category:"",items:[]}),l.items.push(d)):(p==="序"||p==="结语")&&(l||(l={category:"",items:[]}),l.items.push(d),p==="结语"&&(c.push(l),l=null)))}return l&&c.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,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:[a(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:a(d.categoryContent)})]}),d.items.map((x,g)=>xe(x.type)==="序"||xe(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:a(x.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),u.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:a(x.title)})}):e.jsx("strong",{children:a(x.title)}),x.content&&a(x.content)]},g))]},p))})}function ll({juan:t,rawText:n,searchQuery:i,onNavigate:r}){const{convert:s}=P(),o=Me(),[a,c]=f.useState("catalog"),l=i.trim(),d=f.useMemo(()=>l?t.sections.filter(u=>$n(u,l,!1,o)):t.sections,[t.sections,l,o]),p=t.sections.filter(u=>xe(u.type)==="书").length,x=t.sections.filter(u=>xe(u.type)==="诗").length,g=l?d.filter(u=>xe(u.type)==="书"||xe(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("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${x>0?`${x} 首`:`${p} 部書`}`:x>0?`${x} 首`:p>0?`${p} 部书`:""}),e.jsx("div",{style:{display:"flex",gap:"2px"},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:a===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:a===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))})]}),a==="raw"&&(n?e.jsx(ol,{text:n,highlightQuery:l}):e.jsx(sl,{sections:t.sections,onNavigate:r,highlightQuery:l})),a==="catalog"&&d.map((u,b)=>{const y=xe(u.type);return y==="书"||y==="诗"||y==="考证"?e.jsx(Zs,{section:u,onNavigate:r,highlightQuery:l},b):y==="类"?e.jsx(Qs,{section:u,highlightQuery:l},b):e.jsx(tl,{section:u,highlightQuery:l},b)}),a==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function Lr(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 al(t){const n=Lr(t);return n.length>0?n[0]:null}function cl(t){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:o,activeRawText:a,query:c,isKaozhen:l}=t,d=Me(),p=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&o&&p.current.set(s,{juan:o,rawText:a})},[s,o,a]),f.useEffect(()=>{p.current.clear(),g({})},[n]);const u=f.useCallback((b,y)=>{let h=0;if(b.juan)for(const S of b.juan.sections)$n(S,y,l,d)&&h++;return h===0&&b.rawText&&Ys(b.rawText,y,d)&&(h=1),h},[l,d]);return f.useEffect(()=>{const b=c.trim();if(!b){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const h={},S=[];for(const C of r){const T=p.current.get(C);T?h[C]=u(T,b):(h[C]="loading",S.push(C))}g(h);const m=8;let j=0;const w=async()=>{var C;for(;j<S.length;){if(y)return;const T=j++,_=S[T];try{const[z,I]=await Promise.all([i.getCollatedJuan(n,_),((C=i.getCollatedJuanText)==null?void 0:C.call(i,n,_))??Promise.resolve(null)]),v={juan:z,rawText:I};if(p.current.set(_,v),y)return;g(R=>({...R,[_]:u(v,b)}))}catch{if(y)return;g(z=>({...z,[_]:0}))}}},k=Array.from({length:Math.min(m,S.length)},()=>w());return Promise.all(k),()=>{y=!0}},[c,n,i,r.join(","),u,d]),{matchStates:x}}const Fn=({index:t,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:o,className:a,style:c})=>{const[l,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[b,y]=f.useState(null),[h,S]=f.useState(null),[m,j]=f.useState(!1),[w,k]=f.useState(null),[C,T]=f.useState(""),_=f.useRef(new Map),z=f.useRef(0),I=s??b,v=f.useCallback(F=>{y(F),o==null||o(F)},[o]),R=t||l;f.useEffect(()=>{t&&(x(!1),u(null))},[t]),f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let F=!1;return x(!0),u(null),i.getCollatedEditionIndex(n).then(J=>{F||(J?d(J):u("未找到整理本数据"))}).catch(J=>{F||u(J instanceof Error?J.message:"加载失败")}).finally(()=>{F||x(!1)}),()=>{F=!0}},[t,n,i]),f.useEffect(()=>{if(R&&!I){const F=al(R);F&&v(F)}},[R,I,v]);const E=n||(R==null?void 0:R.work_id),M=f.useCallback(async F=>{var W;if(!E||!(i!=null&&i.getCollatedJuan))return;const J=++z.current;j(!0),S(null),k(null);try{const[Y,ie]=await Promise.all([i.getCollatedJuan(E,F),((W=i.getCollatedJuanText)==null?void 0:W.call(i,E,F))??Promise.resolve(null)]);if(J!==z.current)return;S(Y),k(ie)}catch{if(J!==z.current)return;S(null),k(null)}finally{J===z.current&&j(!1)}},[E,i]);f.useEffect(()=>{I&&M(I)},[I,M]);const $=F=>{v(F)};if(p)return e.jsx("div",{className:a,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!R)return null;const O=R.type==="kaozhen",A=Lr(R);return e.jsx(dl,{className:a,style:c,index:R,allFiles:A,isKaozhen:O,effectiveWorkId:E,transport:i,activeFile:I,handleSelectFile:$,juanData:h,juanRawText:w,juanLoading:m,searchQuery:C,setSearchQuery:T,onNavigate:r,workLabelCacheRef:_})},dl=({className:t,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:o,transport:a,activeFile:c,handleSelectFile:l,juanData:d,juanRawText:p,juanLoading:x,searchQuery:g,setSearchQuery:u,onNavigate:b,workLabelCacheRef:y})=>{const{matchStates:h}=cl({workId:o,transport:a,files:r,activeFile:c,activeJuan:d,activeRawText:p,query:g,isKaozhen:s}),S=e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:s?"搜索全部章节…":"搜索全部卷…",value:g,onChange:m=>u(m.target.value),style:{width:"100%",padding:"6px 9px",marginBottom:"12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"12.5px",boxSizing:"border-box"}}),e.jsx(qs,{files:r,groups:i.juan_groups,activeFile:c,onSelect:l,juanMeta:i.juan_metadata,matchStates:h,vertical:!0})]});return e.jsx("div",{className:t,style:n,children:e.jsxs(br,{aside:S,children:[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&&i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})]})}),i.text_quality&&(()=>{const m=Ps(i.text_quality.grade);return m?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(js,{content:jo[m],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:So[m],cursor:"help"},children:Gi[m]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),x?e.jsx(Xe,{}):d?s?e.jsx(rl,{juan:d,searchQuery:g,onNavigate:b,transport:a,workLabelCache:y}):e.jsx(ll,{juan:d,rawText:p,searchQuery:g,onNavigate:b}):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((m,j)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[j+1,". "]}),m.url?e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:m.title}):e.jsx("span",{children:m.title}),m.author&&e.jsxs("span",{children:[",",m.author]}),m.note&&e.jsxs("span",{children:["。",m.note]})]},j))]})]})})},pl={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"}},ul={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"}};function xl(t){try{const n=new Date(t),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}const Mn=({items:t,loading:n})=>{const i=be();return n?e.jsx(Xe,{}):t.length===0?e.jsx("div",{style:fl,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=pl[r.type],o=ul[r.status];return e.jsxs("div",{style:gl,children:[e.jsxs("div",{style:ml,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...ui,background:s.color},children:s.label}),e.jsx("span",{style:{...ui,background:o.color},children:o.label})]}),e.jsx("span",{style:hl,children:xl(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:bl,children:[r.resourceId&&e.jsx("a",{href:i(r.resourceId),style:xi,children:r.resourceId}),r.pageUrl&&!r.resourceId&&e.jsx("a",{href:r.pageUrl,style:xi,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")})]}),e.jsx("div",{style:yl,children:r.content}),r.reply&&e.jsxs("div",{style:vl,children:[e.jsx("div",{style:jl,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},fl={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},gl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},ml={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},ui={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},hl={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},bl={fontSize:"12px",marginBottom:"6px"},xi={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},yl={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},vl={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},jl={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},mn=({transport:t,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:o})=>{const a=D(),[c,l]=f.useState(null),[d,p]=f.useState([]),[x,g]=f.useState("recommend"),[u,b]=f.useState([]),[y,h]=f.useState(!1),S=r??x,m=$=>{g($),s==null||s($)},[j,w]=f.useState(!0),[k,C]=f.useState(null),[T,_]=f.useState(null),[z,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(O=>{$||l({works:O.works,books:O.books,collections:O.collections})}).catch(()=>{}),()=>{$=!0}},[t]),f.useEffect(()=>{let $=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const A=await t.getRecommended();if(A!=null&&A.groups)return A.groups.flatMap(F=>F.items.map(J=>({...J,group:F.name})))}catch{}return[]})().then(async A=>{if($)return;const F=A.filter(W=>W.id);if(F.length===0){w(!1);return}const J=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 Y=null;if(t.getEntry)Y=await t.getEntry(W.id);else{const ie=await t.getItem(W.id);ie&&(Y={id:W.id,title:ie.title||W.id,type:ie.type||"work"})}if(Y)return{...Y,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:Q.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(p(J.filter(W=>W!==null)),w(!1))}),()=>{$=!0}},[t,i]);const v=f.useRef(!1),R=f.useRef(!1),E=f.useRef(!1);f.useEffect(()=>{if(S!=="catalog"||v.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;v.current=!0;let O=!1;return $.call(t).then(A=>{O||C(A)}).catch(()=>{v.current=!1}),()=>{O=!0}},[t,S]),f.useEffect(()=>{if(S!=="collection"||R.current||!t.getCollectionProgress)return;R.current=!0;let $=!1;return t.getCollectionProgress().then(O=>{$||_(O)}).catch(()=>{R.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(S!=="site"||E.current||!t.getSiteProgress)return;E.current=!0;let $=!1;return t.getSiteProgress().then(O=>{$||I(O)}).catch(()=>{E.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(!o||S!=="feedback")return;let $=!1;return h(!0),fetch(o).then(O=>O.json()).then(O=>{!$&&O.success&&b(O.items||[])}).catch(()=>{}).finally(()=>{$||h(!1)}),()=>{$=!0}},[o,S]);const M=$=>{switch($){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(xt,{label:a.home.recommendTab,active:S==="recommend",onClick:()=>m("recommend")}),e.jsx(xt,{label:a.home.catalogTab,active:S==="catalog",onClick:()=>m("catalog")}),e.jsx(xt,{label:a.home.collectionTab,active:S==="collection",onClick:()=>m("collection")}),e.jsx(xt,{label:a.home.siteTab,active:S==="site",onClick:()=>m("site")}),o&&e.jsx(xt,{label:a.home.feedbackTab,active:S==="feedback",onClick:()=>m("feedback")})]}),S==="recommend"&&e.jsx(Sl,{recommended:d,loading:j,onNavigate:n,getIcon:M,t:a}),S==="catalog"&&e.jsx(fi,{progress:k,t:a,onNavigate:n}),S==="collection"&&e.jsx(fi,{progress:T,t:a,onNavigate:n}),S==="site"&&e.jsx(wl,{progress:z,t:a,totalWorks:(c==null?void 0:c.works)??0}),S==="feedback"&&o&&e.jsx(Mn,{items:u,loading:y})]})})},xt=({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}),Sl=({recommended:t,loading:n,onNavigate:i,getIcon:r,t:s})=>{const o=be();if(n)return e.jsx(Xe,{});if(t.length===0)return null;const a=new Map;for(const c of t){const l=c.group||s.home.recommendedBrowse;a.has(l)||a.set(l,[]),a.get(l).push(c)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([c,l])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:l.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:o(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.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:r(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),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))})},fi=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((c,l)=>c.priority-l.priority),s=["in_progress","done","todo"],o={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={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 l=r.filter(d=>d.status===c);return l.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[c]}}),o[c]," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(d=>e.jsx(kl,{item:d,t:n,statusColor:a[c],onNavigate:i},d.id))})]},c)})})},kl=({item:t,t:n,statusColor:i,onNavigate:r})=>{const s=be(),o=t.total>0?Math.round(t.imported/t.total*100):0,a=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,l=t.collection_id||t.work_id;return l&&r?e.jsx("a",{href:s(l),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(l))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:a})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ct(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:`${o}%`,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})]})},wl=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((l,d)=>l.priority-d.priority),s=r.filter(l=>l.imported>0),o=r.filter(l=>l.imported===0),a=s.reduce((l,d)=>Math.max(l,d.imported),0),c=i>0?Math.round(a/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:a.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(l=>e.jsx(gi,{item:l,t:n,totalWorks:i},l.id))})]}),o.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," (",o.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:o.map(l=>e.jsx(gi,{item:l,t:n,totalWorks:i},l.id))})]})]})},gi=({item:t,t:n,totalWorks:i})=>{const r=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} (${r}%)`: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:`${r}%`,borderRadius:"2px",background:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},mi="(max-width: 768px)";function _l(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(mi).matches);return f.useEffect(()=>{const i=window.matchMedia(mi),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),t}const Cl=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var O;const o=D(),{convert:a}=P(),c=_l(),[l,d]=f.useState(null),[p,x]=f.useState(null),[g,u]=f.useState(!1),[b,y]=f.useState("detail"),[h,S]=f.useState([]),[m,j]=f.useState(!1),[w,k]=f.useState(null),[C,T]=f.useState(!1),_=f.useCallback(async A=>{if(!t.getCollatedEditionIndex){k(null);return}T(!0);try{const F=await t.getCollatedEditionIndex(A);k(F)}catch{k(null)}finally{T(!1)}},[t]),z=f.useCallback(async A=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){S([]);return}j(!0);try{if(t.getCollectionCatalogs){const F=await t.getCollectionCatalogs(A);S(F||[])}else if(t.getCollectionCatalog){const F=await t.getCollectionCatalog(A);S(F?[{resource_id:"",data:F}]:[])}}catch{S([])}finally{j(!1)}},[t]),I=f.useCallback(async A=>{if(i){i(A);return}d(A),x(null),S([]),k(null),y("detail"),u(!0);try{const F=await t.getItem(A.id);F&&(x(F),F.type==="collection"?z(A.id):F.type==="work"&&F.has_collated&&_(A.id))}catch(F){console.error("加载详情失败:",F)}finally{u(!1)}},[t,i,z,_]),v=f.useCallback(async A=>{x(null),S([]),k(null),y("detail"),u(!0);try{const F=await t.getItem(A);F&&(x(F),d({id:A,title:F.title||A,type:F.type||"book"}),F.type==="collection"?z(A):F.type==="work"&&F.has_collated&&_(A))}catch(F){console.error("导航失败:",F)}finally{u(!1)}},[t,z,_]),R=(p==null?void 0:p.type)==="collection"&&(h.length>0||m)||(p==null?void 0:p.type)==="work"&&(w||C),E=c&&(g||p),M=f.useCallback(()=>{d(null),x(null),S([]),k(null),y("detail")},[]),$=e.jsx(e.Fragment,{children:g?e.jsx(Xe,{}):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:()=>y("detail"),style:Wt(b==="detail"),children:o.detailTab.basicInfo}),p.type==="collection"&&m&&h.length===0&&e.jsxs("button",{onClick:()=>{},style:Wt(!1),children:[o.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&h.map(A=>e.jsx("button",{onClick:()=>y(`catalog:${A.resource_id}`),style:Wt(b===`catalog:${A.resource_id}`),children:A.short_name?`${a(A.short_name)}${o.detailTab.catalogSuffix}`:o.detailTab.collectionCatalog},A.resource_id)),p.type==="work"&&(w||C)&&e.jsxs("button",{onClick:()=>y("collated"),style:Wt(b==="collated"),children:[o.detailTab.collatedEdition,C&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(wn,{data:p,transport:t,onNavigate:v}):b.startsWith("catalog:")?e.jsx(_n,{data:(O=h.find(A=>`catalog:${A.resource_id}`===b))==null?void 0:O.data,onNavigate:v}):b==="collated"?e.jsx(Fn,{index:w||void 0,workId:p.id,transport:t,onNavigate:v}):null})]}):e.jsx(mn,{transport:t,onNavigate:v,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children: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: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:["← ",o.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(dn,{transport:t,onEntryClick:I,hideModeIndicator:n}),!p&&e.jsx(mn,{transport:t,onNavigate:v,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(dn,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Wt(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Ne(t){return t.replace(/\.md$/,"")}const Wr=({index:t,bookId:n,transport:i,activeChapter:r,onChapterChange:s})=>{const[o,a]=f.useState(t??null),[c,l]=f.useState(null),d=r!==void 0?r:c,p=f.useCallback(S=>{s?s(S):l(S)},[s]),[x,g]=f.useState(null),[u,b]=f.useState(!1);f.useEffect(()=>{t&&a(t)},[t]),f.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let S=!1;return i.getBookFullTextIndex(n).then(m=>{S||a(m)}),()=>{S=!0}},[n,i,t]),f.useEffect(()=>{if(!o||o.chapters.length===0)return;const S=Ne(o.chapters[0].file);if(!d){p(S);return}const m=Ne(d);o.chapters.some(w=>Ne(w.file)===m)||p(S)},[o,d,p]);const y=f.useMemo(()=>{if(!o||!d)return null;const S=Ne(d);return o.chapters.find(m=>Ne(m.file)===S)??null},[o,d]);if(f.useEffect(()=>{if(!n||!y||!i.getBookFullTextChapter)return;let S=!1;return b(!0),g(null),i.getBookFullTextChapter(n,y.file).then(m=>{S||g(m)}).catch(()=>{S||g(null)}).finally(()=>{S||b(!1)}),()=>{S=!0}},[n,y,i]),!o)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"});if(o.chapters.length===0)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"});const h=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"0 8px 8px",fontSize:12.5,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:o.version_label}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.chapters.map(S=>{const m=Ne(S.file),j=m===Ne(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(m),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:j?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:j?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:j?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:S.title})},S.file)})})]});return e.jsx(br,{aside:h,children:e.jsxs("div",{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:o.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:o.source.name}),o.source.license&&e.jsxs(e.Fragment,{children:[" · ",o.source.license]})]})]}),u&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!u&&x&&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:x.replace(/^##\s+[^\n]+\n+/,"")}),!u&&!x&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})})},Il=({data:t,onNavigate:n,className:i,style:r})=>{var p;const s=D(),{convert:o}=P(),[a,c]=f.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[l,d]=f.useState(null);return e.jsxs("div",{className:i,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Tl,{division:x,expanded:a===x.name,onToggle:()=>c(a===x.name?null:x.name),expandedCat:l,onCatToggle:g=>d(l===g?null:g),onNavigate:n},x.name))})]})},Tl=({division:t,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:o})=>{const{convert:a}=P(),c=t.categories.reduce((l,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return l+(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:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(l=>{const d=`${t.name}/${l.name}`;return e.jsx(zl,{category:l,expanded:r===d,onToggle:()=>s(d),onNavigate:o},l.name)})})]})},zl=({category:t,expanded:n,onToggle:i,onNavigate:r})=>{var l,d,p,x;const{convert:s}=P(),o=((l=t.books)==null?void 0:l.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||o.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.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&&(o.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[o.length>0&&e.jsx(hi,{label:"著錄",books:o,onNavigate:r}),a.length>0&&e.jsx(hi,{label:"存目",books:a,onNavigate:r})]})]})},hi=({label:t,books:n,onNavigate:i})=>{const{convert:r}=P(),s=be(),[o,a]=f.useState(n.length<=20),c=o?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((l,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:l.work_id&&i?e.jsx("a",{href:s(l.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(l.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(l.title)}):r(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(l.author).slice(0,20)})]},d))}),!o&&e.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ke=({title:t,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const o=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&e.jsx("button",{onClick:i,style:El,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Rl,children:o.action.save})]})]}),s]})},Rl={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},El={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},he=({label:t,value:n,onChange:i,placeholder:r,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:o=>i(o.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),Ue=({value:t,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder: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"}})},Dt=({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 Bl(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ft=({value:t,onChange:n,label:i})=>{const[r,s]=f.useState(!1),o=f.useRef(null),a=Bl(t||"");return f.useEffect(()=>{r&&o.current&&o.current.focus()},[r]),!r&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,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:a.name}),e.jsx(Dt,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,children:i}),e.jsx("input",{ref:o,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"}})]})},bi={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Ll(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 Wl(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const $r=({items:t,onChange:n,onOpenEntityPicker:i})=>{const r=D(),[s,o]=f.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),o(t.length)},c=x=>{n(t.filter((g,u)=>u!==x)),s===x&&o(null)},l=(x,g,u)=>{const b=[...t];b[x]={...b[x],[g]:u},n(b)},d=(x,g)=>{const u=[...t];u[x]={...u[x],type:g,id:"",name:""},n(u),g==="bookID"&&i&&i(b=>{const y=[...t];y[x]={...y[x],id:b.id,name:b.title,type:"bookID"},n(y)})},p=x=>{i&&i(g=>{const u=[...t];u[x]={...u[x],id:g.id,name:g.title,type:"bookID"},n(u)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>o(s===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Ll(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Wl(x.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:r.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...yi,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...yi,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid 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:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>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:r.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:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:u=>l(g,"name",u.target.value),placeholder:r.editor.sourceNamePlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:u=>l(g,"id",u.target.value),placeholder:"https://...",style:et})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...$e,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:u=>l(g,"details",u.target.value),placeholder:r.editor.detailsPlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:u=>l(g,"position",u.target.value),placeholder:"如: 卷三, p.52",style:et})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:u=>l(g,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:u=>l(g,"processor_version",u.target.value),placeholder:"如: v0.1",style:et})]})]})]})]})})]},g)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},$e={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},et={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"},yi={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"},vi={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Ar(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 Fr(t){return!t||t.length===0?"":JSON.stringify(t)}const Mr=({entityType:t,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:o,belongsToCollection:a,childWorks:c,childCollections:l,containedBooks:d,siblingBooks:p,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:u,onCreateAndLink:b,onSaveRelations:y})=>{const h=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:h.section.relations})]}),y&&e.jsx("button",{onClick:y,style:$l,children:h.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:h.relation.belongsToWork,entity:o,onView:u,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ft,{direction:"up",title:h.relation.containedInCollection,entity:a,onView:u,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),o&&p&&p.length>0&&e.jsx(tt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${p.length})`,entities:p,onView:u,onAdd:()=>b("siblingBook","book",{workId:o.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:h.relation.parentWork,entity:r,onView:u,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),c&&c.length>0&&e.jsx(tt,{direction:"down",title:`${h.relation.childWorks} (${c.length})`,entities:c,onView:u,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),l&&l.length>0&&e.jsx(tt,{direction:"down",title:`${h.relation.collectionImpl} (${l.length})`,entities:l,onView:u,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(tt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:h.relation.correspondingWork,entity:o,onView:u,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ft,{direction:"up",title:h.relation.parentCollection,entity:s,onView:u,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(tt,{direction:"down",title:`${h.relation.childCollections} (${(l==null?void 0:l.length)??0})`,entities:l||[],onView:u,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(tt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},ft=({direction:t,title:n,entity:i,onView:r,onUnlink:s,onLink:o,onCreate:a,linkLabel:c,createLabel:l,notLinkedLabel:d,viewLabel:p,unlinkLabel:x})=>{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:Pr(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(ji,{onClick:()=>r(i),title:p,children:"👁️"}),e.jsx(ji,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(hn,{onClick:o,children:c}),e.jsx(hn,{onClick:a,primary:!0,children:l})]})]})},tt=({direction:t,title:n,entities:i,onView:r,onAdd:s,addLabel:o,noneLabel:a,expandMoreLabel:c})=>{const[l,d]=f.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=l?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:x}),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:()=>r(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:Pr(u.type)}),e.jsx("span",{children:u.title})]},u.id)),i.length>5&&!l&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",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:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(hn,{onClick:s,primary:!0,children:["+ ",o]})})]})},ji=({onClick:t,title:n,danger:i,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),hn=({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 Pr(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const $l={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"},Hr=({isOpen:t,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:o,searchResults:a,onSearch:c,isLoading:l,excludeId:d})=>{const[p,x]=f.useState(""),g=d?a.filter(h=>h.id!==d):a;f.useEffect(()=>{t&&(x(""),c(""))},[t]);const u=h=>{x(h),c(h)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Al,children:e.jsxs("div",{style:Fl,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:Ml,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:h=>u(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Pl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:l?e.jsx("div",{style:on,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(h=>e.jsxs("div",{onClick:()=>r(h),style:Hl,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):p?e.jsxs("div",{style:on,children:["未找到匹配的",b]}):e.jsxs("div",{style:on,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:o,style:Ol,children:["创建新",b,"并关联"]})]})]})})},Al={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Fl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",width:"500px",maxWidth:"calc(100vw - 32px)",maxHeight:"70vh",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"},Pl={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"},Hl={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},on={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"},Si={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Dl={work:"📜",book:"📖",collection:"📚",entity:"👤"},Or=({isOpen:t,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:o})=>{const[a,c]=f.useState(""),l=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,u;(g=l.current)==null||g.focus(),(u=l.current)==null||u.select()},100))},[t,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&a.trim()?p():g.key==="Escape"&&o()},p=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!t)return null;const x=()=>{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`创建新${Si[n]}`}};return e.jsx("div",{style:Nl,onClick:g=>{g.target===g.currentTarget&&o()},children:e.jsxs("div",{style:Vl,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:Dl[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:l,type:"text",value:a,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Si[n]}名称...`,style:Gl})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:o,style:Yl,children:"取消"}),e.jsx("button",{onClick:p,disabled:!a.trim(),style:{...Ul,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Nl={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},Vl={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)"},Gl={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"},Yl={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Ul={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Kl(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Dr(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Jl(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 Nr=({isOpen:t,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:o=!1,createButtonText:a,onSelect:c,onCancel:l,onCreate:d,onSearch:p})=>{const[x,g]=f.useState(""),[u,b]=f.useState([]),[y,h]=f.useState(!1),[S,m]=f.useState("recent");f.useEffect(()=>{t&&(g(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!x.trim()){b([]);return}const _=setTimeout(async()=>{h(!0);try{b(await p(x,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(_)},[x,i,p]);const j=f.useCallback(_=>{g(_.target.value),_.target.value.trim()&&m("search")},[]),w=f.useCallback(_=>s?_.filter(z=>z.id!==s):_,[s]);if(!t)return null;const k=n||(i==="all"?"选择实体":`选择${Dr(i)}`),C=w(r),T=w(u);return e.jsx("div",{style:Xl,children:e.jsxs("div",{style:Zl,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:l,style:Ql,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:ea}),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:"搜索中..."})]})}),C.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(ki,{active:S==="recent",onClick:()=>m("recent"),children:["最近使用 (",C.length,")"]}),e.jsxs(ki,{active:S==="search",onClick:()=>m("search"),children:["搜索结果 ",T.length>0&&`(${T.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&C.length>0?e.jsx(wi,{entities:C,onSelect:c}):x.trim()?y?e.jsx(sn,{message:"搜索中..."}):T.length>0?e.jsx(wi,{entities:T,onSelect:c}):e.jsx(sn,{message:"未找到匹配的结果"}):e.jsx(sn,{message:"输入关键词开始搜索"})}),o&&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:ta,children:a||"创建新实体"})]})]})})},ki=({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}),wi=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(ql,{entity:i,onClick:()=>n(i)},i.id))}),ql=({entity:t,onClick:n})=>{const[i,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background: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:Kl(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:Jl(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Dr(t.type)})]})},sn=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),Xl={position:"fixed",top:0,left:0,right:0,bottom:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},Zl={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)"},Ql={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},ea={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"},ta={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},na={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)"},ia={work:"📜",collection:"📚",book:"📖",entity:"👤"},Vr=({data:t,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:o,onDelete:a,onAskAI:c,renderSectionActions:l,onDownloadResource:d,downloadStatuses:p,relations:x,onRelationsChange:g})=>{var ne;const u=D(),[b,y]=f.useState(!1),[h,S]=f.useState("work"),[m,j]=f.useState(""),[w,k]=f.useState(""),[C,T]=f.useState([]),[_,z]=f.useState(!1),[I,v]=f.useState(!1),[R,E]=f.useState("work"),[M,$]=f.useState(""),[O,A]=f.useState(),[F,J]=f.useState(!1),[W,Y]=f.useState(null),[ie,K]=f.useState([]);f.useRef(null);const L=t.type,U=L==="work",q=L==="collection",V=L==="book",G=f.useCallback((B,ee)=>{n({...t,[B]:ee})},[t,n]),de=f.useCallback((B,ee)=>{j(B),S(ee),k(u.editor.selectToLink+u.indexType[ee]),T([]),y(!0)},[u]),Se=f.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,B)},[r,t.id]),me=f.useCallback(B=>{s==null||s(B.id,B.type)},[s]),se=f.useCallback((B,ee,le)=>{const X={...le,author:(le==null?void 0:le.author)||t.author,dynasty:le==null?void 0:le.dynasty};E(ee),$(B),A(X),v(!0)},[t.author]),ye=f.useCallback((B,ee)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,M,{type:R,title:B,inheritData:ee}),v(!1)},[r,t.id,M,R]),Ie=f.useCallback(B=>{if(!B.trim()){T([]);return}z(!0),r!=null&&r.searchEntities&&r.searchEntities(B,h).then(ee=>{T(ee),z(!1)}).catch(()=>{T([]),z(!1)})},[r,h]),Te=f.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,B.id),y(!1)},[r,t.id,m]),Ze=f.useCallback(()=>{i()},[i]),ct=f.useCallback(B=>{Y(()=>B),J(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(K).catch(()=>{})},[r]),N=f.useCallback((B,ee)=>r!=null&&r.searchEntities?r.searchEntities(B,ee==="all"?void 0:ee):Promise.resolve([]),[r]),oe=f.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),K(ee=>[B,...ee.filter(le=>le.id!==B.id)].slice(0,10)),W==null||W(B),J(!1),Y(null)},[r,W]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:ia[L]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Dt,{children:t.id}),e.jsx(Dt,{color:na[L],children:u.indexType[L]})]})}),e.jsx(ke,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:l==null?void 0:l("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ft,{label:U?u.editor.workTitle:q?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:B=>G("title",B)}),V&&e.jsx(Ft,{label:u.editor.belongsToWork,value:t.workName||"",onChange:B=>G("workName",B)}),e.jsx(he,{label:u.editor.authorLabel,value:t.author||"",onChange:B=>G("author",B)}),e.jsx(he,{label:u.editor.publicationYearLabel,value:t.publicationYear||"",onChange:B=>G("publicationYear",B)}),(V||q)&&e.jsx(Ft,{label:u.editor.containedIn,value:t.collection||"",onChange:B=>G("collection",B)}),(V||q)&&e.jsx(he,{label:u.editor.holderLabel,value:t.holder||"",onChange:B=>G("holder",B)}),(V||q)&&e.jsx(he,{label:V?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:B=>G("pages",B)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(he,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:B=>G("firstImage",B)})})]})}),e.jsx(ke,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Ue,{value:t.description||"",onChange:B=>G("description",B),placeholder:u.editor.descriptionPlaceholder})}),(((ne=t.additional_works)==null?void 0:ne.length)||0)>0&&e.jsx(ke,{title:u.section.additionalWorks,onSave:i,children:e.jsx(ra,{items:t.additional_works||[],onChange:B=>G("additional_works",B)})}),e.jsx(ke,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(oa,{items:t.indexed_by||[],onChange:B=>G("indexed_by",B)})}),e.jsx(ke,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(sa,{items:t.emendated_by||[],onChange:B=>G("emendated_by",B)})}),e.jsx(ke,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(cn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(ke,{title:u.section.imageResources,onSave:i,children:e.jsx(cn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(ke,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx($r,{items:Ar(t.sources||""),onChange:B=>G("sources",Fr(B)),onOpenEntityPicker:ct})}),(V||q)&&e.jsx(ke,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Ue,{value:t.provenance||"",onChange:B=>G("provenance",B),placeholder:u.editor.provenancePlaceholder})}),V&&e.jsx(ke,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Ue,{value:t.otherEditions||"",onChange:B=>G("otherEditions",B),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(Mr,{entityType:L,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:de,onUnlinkEntity:Se,onViewEntity:me,onCreateAndLink:se,onSaveRelations:Ze}),o&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children: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:a,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:u.editor.deleteEntity})]}),e.jsx(Hr,{isOpen:b,entityType:h,title:w,onSelect:Te,onCancel:()=>y(!1),onCreate:()=>{y(!1),se(m,h)},searchResults:C,onSearch:Ie,isLoading:_,excludeId:t.id}),e.jsx(Or,{isOpen:I,entityType:R,relationField:M,inheritData:O,onConfirm:ye,onCancel:()=>v(!1)}),e.jsx(Nr,{isOpen:F,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ie,excludeId:t.id,onSelect:oe,onCancel:()=>{J(!1),Y(null)},onSearch:N})]})};function ra({items:t,onChange:n}){const i=D(),r=(a,c,l)=>{const d=t.map((p,x)=>x===a?{...p,[c]:l}:p);n(d)},s=a=>n(t.filter((c,l)=>l!==a)),o=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(he,{label:i.editor.bookNameLabel,value:a.book_title,onChange:l=>r(c,"book_title",l)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(he,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:l=>r(c,"n_juan",l&&parseInt(l,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:o,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 Gr({items:t,onChange:n,showMeta:i,addLabel:r}){const s=D(),[o,a]=f.useState(null),c=(p,x,g)=>{const u=t.map((b,y)=>y===p?{...b,[x]:g||void 0}:b);n(u)},l=p=>{n(t.filter((x,g)=>g!==p)),o===p&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,x)=>{const g=o===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>a(g?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children: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(),l(x)},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(he,{label:s.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),e.jsx(he,{label:s.label.sourceBid,value:p.source_bid||"",onChange:u=>c(x,"source_bid",u)})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(he,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),e.jsx(he,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),e.jsx(he,{label:s.label.edition,value:p.edition||"",onChange:u=>c(x,"edition",u)})]}),e.jsx(Ue,{value:p.summary||"",onChange:u=>c(x,"summary",u),placeholder:s.editor.summaryPlaceholder}),e.jsx(Ue,{value:p.comment||"",onChange:u=>c(x,"comment",u),placeholder:s.editor.commentPlaceholder}),e.jsx(Ue,{value:p.additional_comment||"",onChange:u=>c(x,"additional_comment",u),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:r})]})}function oa({items:t,onChange:n}){const i=D();return e.jsx(Gr,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function sa({items:t,onChange:n}){const i=D();return e.jsx(Gr,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function Yr(t){var c,l,d,p,x,g,u;const n=((l=(c=t.authors)==null?void 0:c[0])==null?void 0:l.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",r=((p=t.current_location)==null?void 0:p.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",o=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,publicationYear:i,holder:r,pages:s,description:o,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const y=b.related_works.find(h=>h.relation==="part_of");y&&(a.parentWorkId=y.id,a.parentWorkName=y.title)}}if(t.type==="book"){const b=t;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(u=b.contained_in[0])==null?void 0:u.id)}return a}function la(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.publicationYear?{year:t.publicationYear}: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 aa=t=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:o,onChange:a,onSave:c,onDelete:l,onNavigate:d,renderLink:p,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:b,relations:y,onRelationsChange:h,headerExtra:S,className:m,style:j}=t;D();const[w,k]=f.useState(s),C=o?s:w;f.useEffect(()=>{s!==w&&k(s)},[s]);const T=f.useCallback(()=>{const M=C==="view"?"edit":"view";o?o(M):k(M)},[C,o]),[_,z]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(M=>{M&&z(M)})},[i,r]);const I=n||_,v=f.useMemo(()=>I?Yr(I):null,[I]),R=o||!n?e.jsx("button",{onClick:T,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:C==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:C==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:C==="view"?"切换到编辑模式":"切换到查看模式",children:C==="view"?"✏️ 编辑":"👁 查看"}):null,E=e.jsxs(e.Fragment,{children:[R,S]});return!I&&!v?e.jsx(Xe,{}):C==="view"?e.jsx(wn,{data:I,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:p,headerExtra:E,className:m,style:j}):v?e.jsxs("div",{className:m,style:j,children:[E&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:E}),e.jsx(Vr,{data:v,onChange:a||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!l,onDelete:l,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:b,relations:y,onRelationsChange:h})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},_i=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Ur=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,o]=f.useState(null),[a,c]=f.useState(""),[l,d]=f.useState(""),[p,x]=f.useState("idle"),[g,u]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{t&&(o(null),c(""),d(""),x("idle"),u(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=b.current)==null?void 0:m.focus()},100)},[s]),f.useEffect(()=>{if(p==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[p,n]),f.useEffect(()=>{if(!t)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const y=async()=>{if(!(!s||!a.trim())){x("submitting"),u("");try{await i({type:s,content:a.trim(),...l.trim()?{contact:l.trim()}:{}}),x("success")}catch(m){x("error"),u(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&a.trim()&&p!=="submitting",S=_i.find(m=>m.value===s);return e.jsx("div",{style:ca,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:da,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:pa,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:ua,"aria-label":"关闭",children:"✕"})]}),p==="success"?e.jsxs("div",{style:ha,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"16px"},children:_i.map(m=>e.jsxs("button",{onClick:()=>o(m.value),style:{...xa,...s===m.value?fa:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:b,value:a,onChange:m=>c(m.target.value),placeholder:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||p==="submitting",style:{...ga,opacity:s?1:.6}}),e.jsx("input",{type:"text",value:l,onChange:m=>d(m.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||p==="submitting","aria-label":"联系方式(选填)",style:ya}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),p==="error"&&e.jsx("div",{style:ba,children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:y,disabled:!h,style:{...ma,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交反馈"})})]})]})})},ca={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},da={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)"},pa={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},ua={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},xa={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"},fa={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ga={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"},ma={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ha={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},ba={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ya={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",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",fontFamily:"inherit"},va=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[r,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{...ja,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(Ur,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},ja={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"},Ci=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"}],Kr=({onSubmit:t})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[o,a]=f.useState(""),[c,l]=f.useState("idle"),[d,p]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var y;return(y=x.current)==null?void 0:y.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){l("submitting"),p("");try{await t({type:n,content:r.trim(),...o.trim()?{contact:o.trim()}:{}}),l("success"),s(""),a(""),i("bug")}catch(y){l("error"),p(y instanceof Error?y.message:"提交失败,请稍后重试")}}},u=n&&r.trim()&&c!=="submitting",b=Ci.find(y=>y.value===n);return c==="success"?e.jsx("div",{style:Ii,children:e.jsxs("div",{style:Ca,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Ia,children:"继续提交"})]})}):e.jsxs("div",{style:Ii,children:[e.jsx("div",{style:{display:"flex",gap:"8px",marginBottom:"12px"},children:Ci.map(y=>e.jsxs("button",{onClick:()=>i(y.value),style:{...Sa,...n===y.value?ka:{}},children:[e.jsx("span",{children:y.icon})," ",y.label]},y.value))}),e.jsx("textarea",{ref:x,value:r,onChange:y=>s(y.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:c==="submitting",style:{...wa}}),e.jsx("input",{type:"text",value:o,onChange:y=>a(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:c==="submitting","aria-label":"联系方式(选填)",style:za}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:g,disabled:!u,style:{..._a,opacity:u?1:.6,cursor:u?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交"})]}),c==="error"&&e.jsx("div",{style:Ta,children:d})]})},Ii={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Sa={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"},ka={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},wa={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"},_a={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ca={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Ia={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Ta={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},za={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",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",fontFamily:"inherit"};function Ti(t){return typeof t=="function"?t():t??"/api/feedback"}const Jr=({resourceId:t,apiUrl:n})=>{const[i,r]=f.useState([]),[s,o]=f.useState(!0),a=f.useCallback(async()=>{const l=Ti(n);o(!0);try{const p=await(await fetch(`${l}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&r(p.items)}catch{}finally{o(!1)}},[t,n]);f.useEffect(()=>{a()},[a]);const c=async l=>{const d=Ti(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...l,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!p.ok){const x=await p.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>a(),500)};return e.jsxs("div",{children:[e.jsx(Mn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(Kr,{onSubmit:c})})]})},ht={versions:12,catalogs:8,chips:12},qr={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Xr=({data:t,transport:n,onNavigate:i,renderLink:r,lineageAction:s,collatedSection:o})=>{var R,E,M,$,O,A,F,J,W,Y,ie,K;const a=D(),{convert:c}=P(),l=f.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[d,p]=f.useState(new Map),[x,g]=f.useState(!1),[u,b]=f.useState(""),[y,h]=f.useState(!1),[S,m]=f.useState("default"),j=x||!!u||y||S==="year",w=f.useMemo(()=>j?l:l.slice(0,ht.versions),[l,j]);f.useEffect(()=>{if(!n||w.length===0)return;const L=w.filter(q=>!d.has(q));if(L.length===0)return;let U=!1;return Promise.all(L.map(q=>n.getItem(q).then(V=>{const G=V??{};return[q,{id:q,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[q,{id:q}]))).then(q=>{U||p(V=>{const G=new Map(V);for(const[de,Se]of q)G.set(de,Se);return G})}),()=>{U=!0}},[n,w,d]);const k=f.useMemo(()=>l.map(L=>d.get(L)??{id:L}),[l,d]),C=f.useMemo(()=>pr(k,t.version_graph,{era:u,scanOnly:y,sort:S}),[k,t.version_graph,u,y,S]),T=x?C.rows:C.rows.slice(0,ht.versions),_=f.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),z=f.useMemo(()=>cr((t.related_works||[]).map(L=>({id:L.id,title:L.title,relation:L.relation}))),[t.related_works]),I=f.useMemo(()=>{var G,de,Se,me;const L=[],U=(de=(G=t.authors)==null?void 0:G[0])==null?void 0:de.dynasty;U&&L.push({label:"成書",value:c(U)});const q=Je(t,a.unit.juan);if(q){const se=(Se=t.juan_count)==null?void 0:Se.description;L.push({label:"卷帙",value:c(q),title:se?c(se):void 0})}const V=C.allRows.filter(se=>se.sortYear!=null);if(V.length>0){const se=V.reduce((ye,Ie)=>ye.sortYear<=Ie.sortYear?ye:Ie);se.era.era&&L.push({label:"最早存世刻本",value:`${se.era.era}${se.era.reign?" "+se.era.reign:""}`,title:se.era.source==="edition"?"據版本題名推斷":void 0})}return(me=t.indexed_by)!=null&&me.length&&L.push({label:"著錄",value:`${t.indexed_by.length} ${a.unit.bu}`}),L},[t,c,a,C.allRows,j,l.length]),v=!o&&l.length===0&&_.buckets.length===0&&_.mirrors.length===0&&!((R=t.indexed_by)!=null&&R.length)&&!((E=t.emendated_by)!=null&&E.length)&&z.length===0&&!((M=t.description)!=null&&M.text);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:I.length?e.jsx(zt,{items:I}):void 0,children:[(($=t.description)==null?void 0:$.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Fe,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(O=t.description.sources)!=null&&O.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=>c(As(L))).filter(Boolean).join(" · ")}):null]}),(A=t.appendix)==null?void 0:A.map((L,U)=>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:c(L.title)}),e.jsx(Fe,{text:L.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},U)),e.jsx(Cr,{rows:[{label:a.section.aliases,items:wt(t.additional_titles)},{label:a.section.attachedTexts,items:wt(t.attached_texts)},{label:a.section.appendix,items:(t.additional_works||[]).map(L=>L.book_title+(L.n_juan!=null?` ${L.n_juan}${a.unit.juan}`:""))}]})]}),o,l.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"版",title:a.section.relatedVersions,count:C.rows.length===C.allRows.length?`${C.allRows.length} 種`:`${C.allRows.length} 種 · 當前 ${C.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(He,{label:"僅看有影印",active:y,dashed:!0,onClick:()=>{h(L=>!L),g(!1)}}),e.jsx(Ut,{label:S==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>m(L=>L==="default"?"year":"default")})]})}),C.allRows.length>=6&&C.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(He,{label:a.catalog.all,active:!u,onClick:()=>{b(""),g(!1)}}),C.eras.map(L=>e.jsx(He,{label:L,active:u===L,onClick:()=>{b(L),g(!1)}},L))]}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:qr}),T.map((L,U)=>e.jsx(Ba,{row:L,no:U,onNavigate:i,renderLink:r},L.id)),T.length===0&&e.jsx(st,{children:u||y?"當前篩選下沒有版本":"暫無版本著錄"})]}),C.rows.length>T.length&&e.jsx(De,{label:`展開其餘 ${C.rows.length-T.length} 種版本`,onClick:()=>g(!0)}),C.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(_.buckets.length>0||_.mirrors.length>0)&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[_.mirrors.map(L=>e.jsx(xn,{title:c(L.label),tag:L.description?c(L.description):void 0,children:L.items.map((U,q)=>e.jsx(ot,{item:U,siblings:L.items},`${U.id||U.url||U.name}-${q}`))},L.key)),_.buckets.map(L=>e.jsx(xn,{title:Ra[L.key],tag:Ea[L.key],children:L.items.map((U,q)=>e.jsx(ot,{item:U,siblings:L.items},`${U.id||U.url||U.name}-${q}`))},L.key))]})]}),(F=t.indexed_by)!=null&&F.length||(J=t.emendated_by)!=null&&J.length?e.jsxs("div",{className:(W=t.emendated_by)!=null&&W.length?"bim-d-pair":void 0,style:(Y=t.emendated_by)!=null&&Y.length?void 0:{marginBottom:48},children:[(ie=t.indexed_by)!=null&&ie.length?e.jsx(Ri,{id:"catalogs",glyph:"目",title:a.section.indexed,items:t.indexed_by,unit:a.unit.bu,cap:ht.catalogs,showMeta:!0,t:a,convert:c,onNavigate:i,renderLink:r}):null,(K=t.emendated_by)!=null&&K.length?e.jsx(Ri,{id:"studies",glyph:"考",title:a.section.emendated,items:t.emendated_by,unit:a.unit.bu,cap:ht.catalogs,t:a,convert:c,onNavigate:i,renderLink:r}):null]}):null,z.map(L=>e.jsx(La,{glyph:L.key==="derivative"?"續":"叢",title:a.section[L.labelKey]??a.section.relatedWorks,items:L.items,convert:c,onNavigate:i,renderLink:r},L.key)),v&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:a.section.relatedVersions}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},Ra={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},Ea={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function Ba({row:t,no:n,onNavigate:i,renderLink:r}){const{convert:s}=P(),o=[t.era.era,t.era.reign].filter(Boolean).join(" · "),a=t.era.source==="edition";return e.jsx(qt,{no:Xt(n),spec:qr,main:e.jsx(_e,{id:t.id,label:s(t.name),onNavigate:i,renderLink:r,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:a?"據版本題名推斷":void 0,children:o||e.jsx(rt,{})}),e.jsx(zi,{items:t.images,convert:s}),e.jsx(zi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function zi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(rt,{});if(t.length===1){const a=t[0],c=(a.url?St(a.url):void 0)||n(a.name),l=Pt(a);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:l?e.jsx(fn,{href:l,children:c}):c})}const r=t[0],s=(r.url?St(r.url):void 0)||n(r.name),o=Pt(r);return e.jsxs("span",{style:{minWidth:0},children:[o?e.jsx(fn,{href:o,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 Ri({id:t,glyph:n,title:i,items:r,unit:s,cap:o,showMeta:a,t:c,convert:l,onNavigate:d,renderLink:p}){const[x,g]=f.useState({}),[u,b]=f.useState(!1),y=r.length>0&&r.every((m,j)=>x[j]),h=f.useCallback(()=>{g(y?{}:Object.fromEntries(r.map((m,j)=>[j,!0])))},[y,r]),S=u?r:r.slice(0,o);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(ue,{glyph:n,tone:"ink",title:i,count:`${r.length} ${s}`,actions:e.jsx(Ut,{label:y?"收起全部":"+ 展開提要",onClick:h})}),e.jsx(qe,{children:S.map((m,j)=>{const w=m;return e.jsxs(kr,{open:!!x[j],onToggle:()=>g(k=>({...k,[j]:!k[j]})),main:e.jsxs(e.Fragment,{children:[w.source_bid?e.jsx(_e,{id:w.source_bid,label:l(w.source),onNavigate:d,renderLink:p,dense:!0}):l(w.source),a&&w.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(w.section)})]}),action:w.source_bid?e.jsx(_e,{id:w.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:[a&&(w.title_info||w.author_info||w.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:[w.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",l(w.title_info)]}),w.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",l(w.author_info)]}),w.edition&&e.jsxs("span",{children:[c.label.edition," ",l(w.edition)]})]}),w.summary&&e.jsx(At,{children:Oe(l(w.summary))}),w.comment&&e.jsx(At,{label:c.section.comment,children:Oe(l(w.comment))}),w.additional_comment&&e.jsx(At,{label:c.section.additionalComment,children:Oe(l(w.additional_comment))}),a&&w.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:w.page})]},j)})}),r.length>S.length&&e.jsx(De,{label:`展開其餘 ${r.length-S.length} ${s}`,onClick:()=>b(!0)})]})}function La({glyph:t,title:n,items:i,convert:r,onNavigate:s,renderLink:o}){const[a,c]=f.useState(!1),l=a?i:i.slice(0,ht.chips);return e.jsxs(Ce,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Kt,{children:[l.map(d=>e.jsx(Rt,{children:e.jsx(_e,{id:d.id,label:r(d.title),onNavigate:s,renderLink:o,dense:!0,style:{color:"inherit"}})},d.id)),i.length>l.length&&e.jsx(De,{inline:!0,label:`更多 ${i.length-l.length} 種`,onClick:()=>c(!0)})]})]})}const Wa=8,Zr=({data:t,transport:n,onNavigate:i,renderLink:r,fullTextSection:s})=>{var w,k,C,T;const o=D(),{convert:a}=P(),[c,l]=f.useState(null),[d,p]=f.useState(new Map),[x,g]=f.useState([]),[u,b]=f.useState(!1);f.useEffect(()=>{if(!n||!t.work_id){l(null);return}let _=!1;return n.getItem(t.work_id).then(z=>{!_&&z&&z.type==="work"&&l(z)}).catch(()=>{}),()=>{_=!0}},[n,t.work_id]),f.useEffect(()=>{const _=t.contained_in||[];if(!n||_.length===0){p(new Map);return}let z=!1;return Promise.all(_.map(I=>{const v=typeof I=="string"?I:I.id;return n.getItem(v).then(R=>[v,R]).catch(()=>[v,null])})).then(I=>{if(z)return;const v=new Map;for(const[R,E]of I)E&&v.set(R,E);p(v)}),()=>{z=!0}},[n,t.contained_in]);const y=f.useMemo(()=>{const _=new Set([...(c==null?void 0:c.books)||[],...t.related_books||[]]);return _.delete(t.id),[..._]},[c==null?void 0:c.books,t.related_books,t.id]);f.useEffect(()=>{if(!n||y.length===0){g([]);return}const _=u?y:y.slice(0,Wa);let z=!1;return Promise.all(_.map(I=>n.getItem(I).then(v=>({id:I,title:v==null?void 0:v.title,edition:v==null?void 0:v.edition})).catch(()=>({id:I})))).then(I=>{z||g(I)}),()=>{z=!0}},[n,y,u]);const h=f.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=f.useMemo(()=>{var M,$,O;const _=[],z=It(t),I=mr(t);I&&_.push({label:"版本類型",value:I,title:(M=t.lineage)!=null&&M.category?void 0:"據版本題名推斷"}),(z.era||z.reign)&&_.push({label:"刊寫年代",value:[z.era,z.reign].filter(Boolean).join(" "),title:z.source==="edition"?"據版本題名推斷":void 0});const v=(t.contained_in||[]).flatMap(A=>typeof A=="string"?[]:vt(A.volume_index));v.length&&(_.push({label:"冊數",value:`${v.length} ${o.unit.volume}`}),_.push({label:"冊次",value:`第 ${En(v,o.unit.volume)} ${o.unit.volume}`}));const R=Je(t,o.unit.juan);R&&_.push({label:"卷帙",value:a(R)});const E=(t.resources||[]).filter(A=>(A.types||(A.type?[A.type]:[])).includes("physical"));return E.length?_.push({label:"存藏",value:E.slice(0,2).map(A=>a(A.name)).join("、")+(E.length>2?` 等 ${E.length} 處`:"")}):($=t.current_location)!=null&&$.name&&_.push({label:"存藏",value:a(t.current_location.name)}),(O=t.page_count)!=null&&O.description&&_.push({label:o.label.pageCount,value:t.page_count.description}),_},[t,a,o]),m=!!((w=t.description)!=null&&w.text),j=(t.contained_in||[]).some(_=>typeof _!="string"&&vt(_.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:S.length?e.jsx(zt,{items:S,horizontal:!m}):void 0,children:m?e.jsx(Fe,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),s,(t.contained_in||[]).length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"收",title:o.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((_,z)=>{var M,$;const I=typeof _=="string"?_:_.id,v=typeof _=="string"?[]:vt(_.volume_index),R=d.get(I),E=((M=R==null?void 0:R.books)==null?void 0:M.length)||(($=R==null?void 0:R.contained_works)==null?void 0:$.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(_e,{id:I,label:R?a(R.title):I,onNavigate:i,renderLink:r})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[E>0&&`全 ${E} ${o.unit.bu}`,E>0&&v.length>0&&" · ",v.length>0&&`本書佔 ${v.length} ${o.unit.volume}`]})]}),v.length>0&&e.jsx(Sr,{volumes:v,unit:o.unit.volume})]},`${I}-${z}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[c&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"作",tone:"ink",title:o.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(_e,{id:c.id,label:a(c.title),onNavigate:i,renderLink:r})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[a(Je(c,o.unit.juan)),(k=c.authors)==null?void 0:k.map(_=>{const z=Rn(_.role);return`${_.dynasty?`〔${a(_.dynasty)}〕`:""}${a(_.name)}${z?" "+a(z):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((C=c.description)==null?void 0:C.text)&&e.jsx(Fe,{text:c.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(Ln,{label:o.section.aliases,items:[...wt(t.additional_titles),...wt(t.attached_texts)]})})]})]}),(h.buckets.length>0||h.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:[h.mirrors.map(_=>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:a(_.label)}),_.items.map((z,I)=>e.jsx(ot,{item:z,showVolumes:!j},`${z.id||z.url||z.name}-${I}`))]},_.key)),h.buckets.flatMap(_=>_.items).map((_,z)=>e.jsx(ot,{item:_,showVolumes:!j},`${_.id||_.url||_.name}-${z}`))]})]})]}),(T=t.location_history)!=null&&T.length?e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"藏",tone:"ink",title:o.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((_,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:a(_.name)}),_.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:a(_.description)})]},z))})]}):null,y.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"版",tone:"ink",title:o.relation.siblingVersions,count:`${y.length} 種`,actions:c?e.jsx(_e,{id:c.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:r,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Kt,{children:[x.map(_=>e.jsx(Rt,{children:e.jsx(_e,{id:_.id,label:a(_.edition||_.title||_.id),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},_.id)),y.length>x.length&&e.jsx(De,{inline:!0,label:`更多 ${y.length-x.length} 種`,onClick:()=>b(!0)})]})]})]})},Ei={titles:16,works:16},Qr=({data:t,catalog:n,onNavigate:i,renderLink:r,catalogAction:s})=>{var z,I;const o=D(),{convert:a}=P(),[c,l]=f.useState(""),[d,p]=f.useState(!1),[x,g]=f.useState(!1),u=f.useMemo(()=>fr(t,n),[t,n]),b=f.useMemo(()=>c?u.rows.filter(v=>v.section===c):u.rows,[u.rows,c]),y=d?b:b.slice(0,Ei.titles),h=f.useMemo(()=>Yt(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=t.contained_works||[],m=new Set(u.rows.map(v=>v.id).filter(Boolean)),j=S.length>0&&!S.every(v=>m.has(v.id)),w=(()=>{const v=u.rows.map(R=>R.edition).filter(Boolean);return v.length>1&&new Set(v).size===1})(),k=x?S:S.slice(0,Ei.works),C=u.sections.length>0,T=f.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...C?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[C]),_=f.useMemo(()=>{var M,$,O,A;const v=[];t.subtype&&v.push({label:o.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(M=t.publication_info)!=null&&M.details&&v.push({label:"刊印",value:a(t.publication_info.details)}),($=t.publication_info)!=null&&$.year&&v.push({label:"年代",value:t.publication_info.year});const R=((O=t.books)==null?void 0:O.length)||S.length,E=Je(t,o.unit.juan);return(R||E)&&v.push({label:"種數 / 卷數",value:[R?`${R} ${o.unit.bu}`:"",a(E)].filter(Boolean).join(" · "),title:(A=t.juan_count)!=null&&A.description?a(t.juan_count.description):void 0}),u.totalVolumes&&v.push({label:"全帙冊數",value:`${u.totalVolumes} ${o.unit.volume}`}),v},[t,S.length,u.totalVolumes,a,o]);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:_.length?e.jsx(zt,{items:_}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Fe,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(I=t.history)!=null&&I.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((v,R)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",a(v)]},R))}):null]}),u.rows.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"目",title:o.section.containedBooks,count:b.length===u.rows.length?`${o.catalog.contains} ${u.rows.length} ${o.unit.items}`:`${u.rows.length} ${o.unit.items} · 當前 ${b.length} ${o.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,C&&e.jsxs(e.Fragment,{children:[e.jsx(He,{label:o.catalog.all,active:!c,onClick:()=>{l(""),p(!1)}}),u.sections.map(v=>e.jsx(He,{label:v,active:c===v,onClick:()=>{l(v),p(!1)}},v))]})]})}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:T}),y.map((v,R)=>{var E;return e.jsx(qt,{no:Xt(R),spec:T,main:e.jsxs(e.Fragment,{children:[v.id?e.jsx(_e,{id:v.id,label:a(v.title),onNavigate:i,renderLink:r,dense:!0}):e.jsx("span",{children:a(v.title)}),(E=v.subItems)!=null&&E.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",v.subItems.map(M=>a(M)).join("、"),")"]}):null,v.edition&&!w&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(v.edition)})]}),meta:e.jsxs(e.Fragment,{children:[C&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:v.section?v.section.endsWith("部")?v.section:`${v.section}部`:e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:v.volumes.length>0?`第 ${En(v.volumes,o.unit.volume)} ${o.unit.volume}`:v.expected!=null?`${v.found??0}/${v.expected} ${o.unit.volume}`:e.jsx(rt,{})})]})},`${v.id??v.title}-${R}`)}),y.length===0&&e.jsx(st,{children:o.catalog.noMatch})]}),b.length>y.length&&e.jsx(De,{label:`展開其餘 ${b.length-y.length} ${o.unit.items}子目`,onClick:()=>p(!0)})]}),(h.buckets.length>0||j)&&e.jsxs("div",{className:"bim-d-pair bim-d-pair-wide",children:[(h.buckets.length>0||h.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:[...h.mirrors.flatMap(v=>v.items),...h.buckets.flatMap(v=>v.items)].map((v,R)=>e.jsx(ot,{item:v,fallbackNote:v.details?a(v.details):void 0},`${v.id||v.url||v.name}-${R}`))})]}),j&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:o.section.containedWorks,count:`${S.length} 種`}),e.jsxs(Kt,{children:[k.map(v=>e.jsx(Rt,{children:e.jsx(_e,{id:v.id,label:a(v.title),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},v.id)),S.length>k.length&&e.jsx(De,{inline:!0,label:`更多 ${S.length-k.length} 種`,onClick:()=>g(!0)})]})]})]})]})},$a=16,Bi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},ln=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Li(t){if(!t)return ln.length;const n=ln.indexOf(t);return n===-1?ln.length:n}const eo=({data:t,transport:n,onNavigate:i,renderLink:r})=>{var T,_,z;const s=D(),{convert:o}=P(),[a,c]=f.useState("全部"),[l,d]=f.useState(!1),[p,x]=f.useState("default"),[g,u]=f.useState(new Map),b=f.useMemo(()=>(t.works||[]).map(v=>{const R=g.get(v.work_id);return{id:v.work_id,title:(R==null?void 0:R.title)??v.work_id,role:v.role||"",cls:zn(v.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,g]),y=f.useMemo(()=>xr((t.works||[]).map(I=>I.role)),[t.works]),h=f.useMemo(()=>{const I=a==="全部"?b:b.filter(v=>v.cls===a);return p==="versions"?[...I].sort((v,R)=>(R.versionCount??-1)-(v.versionCount??-1)):I},[b,a,p]),S=l?h:h.slice(0,$a),m=f.useMemo(()=>S.filter(I=>!g.has(I.id)).map(I=>I.id),[S,g]);f.useEffect(()=>{if(!n||m.length===0)return;let I=!1;return Promise.all(m.map(v=>n.getItem(v).then(R=>{var $,O;const E=R??{},M=((($=E.books)==null?void 0:$.length)??0)+(((O=E.collections)==null?void 0:O.length)??0);return[v,{id:v,title:E.title,versionCount:M,loaded:!0}]}).catch(()=>[v,{id:v,loaded:!0}]))).then(v=>{I||u(R=>{const E=new Map(R);for(const[M,$]of v)E.set(M,$);return E})}),()=>{I=!0}},[n,m]);const j=f.useMemo(()=>{const I=new Map;for(const v of t.alt_names||[]){const R=v.type||s.section.aliases;I.has(R)||I.set(R,[]),I.get(R).push(v.name)}return[...I.entries()].sort((v,R)=>Li(v[0])-Li(R[0])).map(([v,R])=>({label:v,names:R}))},[t.alt_names,s]),w=f.useMemo(()=>{const I=[];t.dynasty&&I.push({label:"時代",value:o(t.dynasty)});const v=E=>E==null?"":E<0?`前${-E}`:String(E);(t.birth_year!=null||t.death_year!=null)&&I.push({label:"生卒",value:`${v(t.birth_year)||"?"}—${v(t.death_year)||"?"}`});const R=(t.works||[]).length;return R&&I.push({label:"著作數",value:`${R} 種`}),I},[t,o]),k=(T=t.external_ids)==null?void 0:T.cbdb_id,C=!!((_=t.description)!=null&&_.text);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:w.length?e.jsx(zt,{items:w}):void 0,children:(j.length>0||C)&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[j.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:j.map(I=>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:o(I.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:I.names.map(v=>o(v)).join(" · ")})]},I.label))}),C&&e.jsx(Fe,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),b.length===0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該人物的關聯作品。"})})]}),b.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks,count:h.length===b.length?`${b.length} 種`:`${b.length} 種 · 當前 ${h.length} 種`,actions:e.jsx(Ut,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{x(I=>(I==="default"&&d(!0),I==="default"?"versions":"default"))}})}),y.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:y.map(I=>e.jsx(He,{label:`${I.label} ${I.count}`,active:a===I.cls,onClick:()=>{c(I.cls),d(!1)}},I.cls))}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:Bi}),S.map((I,v)=>e.jsx(qt,{no:Xt(v),spec:Bi,main:e.jsx(_e,{id:I.id,label:o(I.title),onNavigate:i,renderLink:r,dense:!0}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:I.role?o(I.role):e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:I.loaded?I.versionCount?`${I.versionCount} 種版本`:e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},I.id)),S.length===0&&e.jsx(st,{children:"該職任下的著作尚未著錄。"})]}),h.length>S.length&&e.jsx(De,{label:`展開其餘 ${h.length-S.length} 條著作`,onClick:()=>d(!0)}),k!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",k,((z=t.external_ids)==null?void 0:z.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function Aa(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 Fa(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 Wi(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 Ma(t,n,i){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Pa(t,n){var d;if(n==="all")return null;const i=(d=t.collections)==null?void 0:d[n],r=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,o=r||s||!!(i!=null&&i.hypothetical_ids);if(!o&&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||!o)return null;const a=r?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(a&&t.node_groups)for(const[p,x]of Object.entries(t.node_groups))a.has(x)&&c.add(p);let l=null;if(i.hypothetical_ids&&(l=new Set(i.hypothetical_ids)),a){l||(l=new Set);for(const p of t.hypothetical_nodes??[])p.group&&a.has(p.group)&&l.add(p.id)}return{books:c,hypos:l}}function Mt(t,n,i){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const o=new Set(r.excluded_books??[]),a=r.node_groups??{},c=Pa(r,i??r.default_collection??"all"),l=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,x=new Set,g=new Set;if(l){const w=new Map(n.map(I=>[I.id,I])),k=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),C=I=>{const v=w.get(I);if(v&&v.lineage)return(v.lineage.derived_from??[]).map(E=>E.ref);const R=k.get(I);return R?(R.derived_from??[]).map(E=>E.ref):[]},T=I=>k.has(I)?!p||p.has(I):!d||d.has(I),_=new Set,z=I=>{if(!_.has(I)){_.add(I);for(const v of C(I))o.has(v)||(T(v)||(k.has(v)?g.add(v):w.has(v)&&x.add(v)),z(v))}};for(const I of n)d&&d.has(I.id)&&!o.has(I.id)&&z(I.id);for(const I of r.hypothetical_nodes??[])p&&p.has(I.id)&&z(I.id)}const u=n.filter(w=>!o.has(w.id)).filter(w=>!d||d.has(w.id)||x.has(w.id)).map(w=>{const k=Fa(w,a);return k&&x.has(w.id)&&(k.bridge=!0),k}).filter(w=>w!==null),b=(r.hypothetical_nodes??[]).filter(w=>!p||p.has(w.id)||g.has(w.id)).map(w=>{const k=Aa(w);return g.has(w.id)&&(k.bridge=!0),k}),y=[...u,...b],h=new Set(y.map(w=>w.id)),S=new Set,m=[],j=w=>{S.has(w.id)||!h.has(w.source)||!h.has(w.target)||(S.add(w.id),m.push(w))};for(const w of n)o.has(w.id)||!w.lineage||d&&!d.has(w.id)&&!x.has(w.id)||((w.lineage.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))}),(w.lineage.related_to??[]).forEach((k,C)=>{j(Ma(w.id,k,C))}));for(const w of r.hypothetical_nodes??[])p&&!p.has(w.id)&&!g.has(w.id)||(w.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(o)}}function to(t,n,i){const r=(t??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Ha(t,n){const i=[],r=t.version_graph;if(!r)return i;const s=new Set(n.map(l=>l.id)),o=new Set((r.hypothetical_nodes??[]).map(l=>l.id)),a=new Set([...s,...o]),c=(l,d)=>{a.has(d.ref)||i.push(`${l}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${l}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!o.has(d.ref)&&i.push(`${l}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const l of n){if(!l.lineage)continue;const d=`Book ${l.id} (${l.title})`;(l.lineage.derived_from??[]).forEach(p=>c(d,p)),(l.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const l of r.hypothetical_nodes??[]){const d=`Hypothetical ${l.id} (${l.label})`;(l.derived_from??[]).forEach(p=>c(d,p))}return i}const no=({graph:t,renderLink:n,className:i,style:r})=>{const{convert:s}=P();if(!t.nodes.length)return e.jsx("div",{style:{...ec,...r},className:i,children:"暂无版本图数据"});const o=new Map,a=new Map;for(const g of t.edges)if(g.kind==="derive"){const u=o.get(g.target)??[];u.push(g),o.set(g.target,u)}else for(const u of[g.source,g.target]){const b=a.get(u)??[];b.push(g),a.set(u,b)}const c=new Map(t.nodes.map(g=>[g.id,g])),l=new Map,d=[];for(const g of t.nodes)if(g.group){const u=l.get(g.group)??[];u.push(g),l.set(g.group,u)}else d.push(g);const p=(g,u)=>(g.year??9999)-(u.year??9999);l.forEach(g=>g.sort(p)),d.sort(p);const x=t.groups.filter(g=>l.has(g.id));return e.jsxs("div",{className:i,style:{...Da,...r},children:[t.title&&e.jsx("div",{style:Na,children:s(t.title)}),t.description&&e.jsx("div",{style:Va,children:s(t.description)}),x.map(g=>e.jsx($i,{label:g.label,color:g.color,nodes:l.get(g.id),incomingMap:o,siblingMap:a,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx($i,{label:"其他",nodes:d,incomingMap:o,siblingMap:a,nodeMap:c,renderLink:n})]})},$i=({label:t,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:o,renderLink:a})=>{const{convert:c}=P();return e.jsxs("div",{style:Ga,children:[e.jsx("div",{style:{...Ya,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(l=>e.jsx(Oa,{node:l,incoming:r.get(l.id)??[],siblings:s.get(l.id)??[],nodeMap:o,renderLink:a},l.id))]})},Oa=({node:t,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const o=t.kind==="hypothetical",a=t.bridge,{convert:c}=P();return e.jsxs("div",{style:{...Ua,borderStyle:o||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?"var(--bim-bg-subtle, #fafafa)":void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Ka,children:[e.jsx("span",{style:Ja,children:o||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:qa,children:to(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:Xa,children:[t.category&&e.jsx(gt,{children:c(t.category)}),t.status==="lost"&&e.jsx(gt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(gt,{tone:"warn",children:"残本"}),o&&e.jsx(gt,{tone:"info",children:"假想祖本"}),a&&e.jsx(gt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:Za,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:Qa,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Fi,children:[e.jsx("div",{style:Mi,children:"来源:"}),n.map(l=>{const d=r.get(l.source);return e.jsxs("div",{style:Pi(l.confidence),children:[e.jsx("span",{style:Hi,children:c(l.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??l.source)}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Ai,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(l.evidence)]})]},l.id)})]}),i.length>0&&e.jsxs("div",{style:Fi,children:[e.jsx("div",{style:Mi,children:"关联:"}),i.map(l=>{const d=l.source===t.id?l.target:l.source,p=r.get(d);return e.jsxs("div",{style:Pi(l.confidence),children:[e.jsx("span",{style:Hi,children:c(l.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(Ai,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(l.evidence)]})]},l.id)})]})]})},gt=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Ai=({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},Da={fontSize:"14px",color:"var(--bim-fg, #333)"},Na={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Va={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Ga={marginBottom:"16px"},Ya={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Ua={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Ka={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Ja={fontSize:"15px",fontWeight:600},qa={fontSize:"12px",color:"var(--bim-muted, #777)"},Xa={marginBottom:"6px"},Za={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},Qa={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Fi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Mi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Pi=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Hi={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Oi={fontSize:"11px",color:"var(--bim-muted, #888)"},ec={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},io=({selectedNodeId:t,...n})=>{const[i,r]=f.useState("loading"),[s,o]=f.useState(null);return f.useEffect(()=>{let a=!1;return tc().then(c=>{a||(c?(o(c),r("ready")):r("missing"))}),()=>{a=!0}},[]),i==="loading"?e.jsx("div",{style:Di,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:Di,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(nc,{modules:s,selectedNodeId:t,...n})};async function tc(){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 nc=({graph:t,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:o,modules:a})=>{const{ReactFlow:c,Background:l,Controls:d,Handle:p,Position:x,BaseEdge:g,EdgeLabelRenderer:u,getSmoothStepPath:b,dagre:y}=a,h=f.useMemo(()=>({lineage:C=>{var O,A,F,J;const T=((O=C.data)==null?void 0:O.stepPosition)??.85,[_,z,I]=b({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:T,borderRadius:5}),v=!!((A=C.data)!=null&&A.isSibling),R=v?z:C.targetX-18,E=v?I:C.targetY-12,M=(F=C.data)==null?void 0:F.labelStyle,$=(J=C.data)==null?void 0:J.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:C.id,path:_,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&e.jsx(u,{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},children:C.label})})]})}}),[g,u,b]),S=f.useMemo(()=>({version:C=>{const T=C.data,_=T.kind==="hypothetical",z=T.status==="lost",I=T.isSelected,v=T.bridge,R=T.borderColor??"var(--bim-muted, #888)",E=v||_?"dashed":"solid",M=v?.5:z?.6:1;return e.jsxs("div",{style:{background:v?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${E} ${I?"var(--bim-primary, #0078d4)":R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":_||v?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:v?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(p,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:_||!T.renderLink?T.label:T.renderLink(T.bookId,T.label)}),T.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:T.description}),T.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:to(T.yearText,void 0,T.uncertain)}),z&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(p,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[p,x]),{convert:m}=P(),{rfNodes:j,rfEdges:w}=f.useMemo(()=>ic(t,y,n,o,m),[t,y,n,o,m]);return e.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:e.jsxs(c,{nodes:j,edges:w,nodeTypes:S,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(l,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function ic(t,n,i,r,s=o=>o??""){const c=t.layout==="LR"||!t.layout,l=new n.graphlib.Graph;l.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),l.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(S=>[S.id,S.color??"var(--bim-muted, #888)"]));for(const S of t.nodes)l.setNode(S.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const S of t.edges)S.kind==="derive"&&(p.has(S.relation)||l.setEdge(S.source,S.target));n.layout(l);const x=t.nodes.map(S=>{const m=l.node(S.id),j=r&&S.id===r,w={kind:S.kind,label:s(S.label),bookId:S.kind==="book"?S.id:void 0,yearText:s(S.year_text??oc(S)),uncertain:S.year_uncertain,category:S.category,status:S.status,borderColor:S.group?d.get(S.group):void 0,renderLink:i,isSelected:j,description:s(S.description),bridge:S.bridge};return{id:S.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:w,draggable:!1,selected:j}}),g=.78,u=.06,b=new Map;for(const S of t.edges)S.kind==="derive"&&(b.has(S.source)||b.set(S.source,[]),b.get(S.source).push(S));const y=new Map;for(const[S,m]of b){if(m.length<=1)continue;const j=[...m].sort((k,C)=>{var z,I;const T=((z=l.node(k.target))==null?void 0:z.y)??0,_=((I=l.node(C.target))==null?void 0:I.y)??0;return T-_}),w=j.length;j.forEach((k,C)=>{const T=(C-(w-1)/2)*u;y.set(k.id,g+T)})}const h=t.edges.map(S=>rc(S,y.get(S.id),s));return{rfNodes:x,rfEdges:h}}function rc(t,n,i=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",o=sc(t.confidence),a={type:"arrowclosed",color:o,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:o,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function oc(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function sc(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 Di={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)"},ro=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:o,collection:a,onCollectionChange:c,collectionsAvailable:l,collectionCounts:d,className:p,style:x})=>{var m;const[g,u]=f.useState(n),b=j=>{u(j),o==null||o(j)},y=(()=>{if(!l)return[];const j=Object.entries(l);return j.length===0||l.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const S=a?(m=l==null?void 0:l[a])==null?void 0:m.description:void 0;return e.jsxs("div",{className:p,style:x,children:[e.jsxs("div",{style:lc,children:[e.jsx("button",{onClick:()=>b("list"),style:an(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:an(g==="graph"),children:"关系图"}),h&&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(([j,w])=>{const k=d==null?void 0:d[j];return e.jsxs("button",{onClick:()=>c==null?void 0:c(j),style:an(a===j),title:w.description,children:[w.label,k!=null?` ${k}`:""]},j)})]})]}),h&&S&&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:S}),g==="list"?e.jsx(no,{graph:t,renderLink:i}):e.jsx(io,{graph:t,renderLink:i,height:r,selectedNodeId:s})]})},lc={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},an=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=f.useContext(_t);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",o=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:o,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:"简"})]})},so=({href:t,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:o=>{o.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:o=>{o.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"})})}),ac=({id:t,transport:n,activeTab:i,onTabChange:r,activeJuan:s,onJuanChange:o,lineageMode:a="list",onLineageModeChange:c,lineageCollection:l,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:x,onNavigate:g,onBack:u,backLabel:b,renderLink:y,enrichDetail:h,getSourceLink:S,extraTabs:m=[],showFeedbackTab:j=!0,feedbackApiUrl:w,height:k,footerExtra:C,className:T,style:_})=>{const z=D(),{convert:I}=P(),[v,R]=f.useState(null),[E,M]=f.useState(null),[$,O]=f.useState(!0),[A,F]=f.useState(!1),[J,W]=f.useState([]),[Y,ie]=f.useState(!1),[K,L]=f.useState(null),[U,q]=f.useState(!1),[V,G]=f.useState(null),[de,Se]=f.useState(!1),[me,se]=f.useState(null),[ye,Ie]=f.useState(!1),Te=f.useRef(null),[Ze,ct]=f.useState(null),N=s!==void 0?s:Ze,oe=f.useCallback(H=>{o?o(H):ct(H)},[o]),ne=f.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ie(!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{ie(!1)}},[n]),B=f.useCallback(async H=>{if(!n.getCollatedEditionIndex){L(null);return}q(!0);try{L(await n.getCollatedEditionIndex(H))}catch{L(null)}finally{q(!1)}},[n]),ee=f.useCallback(async H=>{if(!n.getBookFullTextIndex){G(null);return}Se(!0);try{G(await n.getBookFullTextIndex(H))}catch{G(null)}finally{Se(!1)}},[n]),le=f.useCallback(async(H,re)=>{Ie(!0);try{if(n.getLineageGraph){const We=await n.getLineageGraph(H);We&&se(We)}const ae=re.version_graph;if(!ae||!ae.enabled){me||se(null),Te.current=null;return}const ce=re.books??[],te=[];for(const We of ce)try{const ze=await n.getItem(We);ze&&te.push(ze)}catch{}Te.current={work:re,books:te};const Z=l??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Le=Z==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":Z??"all";se(Mt(re,te,Le))}catch{se(null),Te.current=null}finally{Ie(!1)}},[n]);f.useEffect(()=>{let H=!1;return(async()=>{O(!0),F(!1),R(null),M(null),W([]),L(null),se(null),Te.current=null;try{const ae=await n.getItem(t);if(H)return;if(!ae){F(!0);return}const ce=ae;let te=null;if(n.getEntry&&(te=await n.getEntry(t),H))return;te||(te={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),h&&h(te,ce),R(te),M(ce),ce.type==="collection"?ne(t):ce.type==="work"?((ce.has_collated||n.getCollatedEditionIndex)&&B(t),(ce.version_graph||n.getLineageGraph)&&le(t,ce)):ce.type==="book"&&ce.has_full_text&&n.getBookFullTextIndex&&ee(t)}catch{H||F(!0)}finally{H||O(!1)}})(),()=>{H=!0}},[t,n,h,ne,B,le,ee]),f.useEffect(()=>{const H=Te.current;!H||!l||se(Mt(H.work,H.books,l))},[l]);const X=[];if(E){if(X.push({key:"basic",label:z.detailTab.basicInfo}),E.type==="collection"){Y&&J.length===0&&X.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const H of J)X.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${I(H.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}E.type==="work"&&(K||U)&&i==="collated"&&X.push({key:"collated",label:U?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),E.type==="book"&&(V||de)&&i==="fulltext"&&X.push({key:"fulltext",label:de?`${z.detailTab.fullText}…`:z.detailTab.fullText}),E.type==="work"&&(me||ye)&&X.push({key:"lineage",label:ye?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const H of m)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&X.push({key:H.key,label:H.label});j&&i==="feedback"&&X.push({key:"feedback",label:z.detailTab.feedback});for(const H of m)H.position==="after-feedback"&&H.shouldShow(E)&&X.push({key:H.key,label:H.label})}f.useEffect(()=>{if(i!=="emendated"||!E)return;r("basic");const H=setTimeout(()=>{var re;(re=document.getElementById("studies"))==null||re.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,E,r]);const Pe=v&&E&&S?S({activeTab:i,activeJuan:N,entry:v,detail:E}):null,ve=f.useMemo(()=>{var te;if(!E)return null;const re=(E.authors??[]).map(Z=>{const Le=Rn(Z.role);return`${Z.dynasty?`〔${I(Z.dynasty)}〕`:""}${I(Z.name)}${Le?` ${I(Le)}`:""}`}).join(" · ");let ae=!1;try{ae=Q.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Z=E;return{title:I(Z.title),subtitle:Z.edition?I(Z.edition):re||void 0,aside:[ae?z.status.draft:"",re&&Z.edition?re:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Z=E;return{title:I(Z.title),subtitle:I(Je(Z,z.unit.juan))||void 0,aside:[(te=Z.publication_info)==null?void 0:te.year,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:re||void 0}}if(E.type==="entity"){const Z=E,Le=ze=>ze==null?"":ze<0?`前${-ze}`:String(ze),We=Z.birth_year!=null||Z.death_year!=null?`${Le(Z.birth_year)||"?"}—${Le(Z.death_year)||"?"}`:"";return{title:I(Z.primary_name||Z.title),subtitle:[Z.dynasty?`〔${I(Z.dynasty)}〕`:"",We].filter(Boolean).join(" ")||void 0,aside:ae?z.status.draft:void 0,secondLine:void 0}}const ce=I(Je(E,z.unit.juan));return{title:I(E.title),subtitle:[ce,re].filter(Boolean).join(" · ")||void 0,aside:[dc(z,E.subtype),ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,I,z]),ge=()=>{var H,re;return E?E.type==="work"?e.jsx(Xr,{data:E,transport:n,onNavigate:g,renderLink:y,collatedSection:K&&(((H=K.juan_files)==null?void 0:H.length)??0)>0?e.jsx(Ni,{title:E.title,measure:`${K.juan_files.length} ${I(z.unit.juan)}`,onOpen:()=>{oe(K.juan_files[0]),r("collated")}}):null,lineageAction:me&&me.nodes.length>0?e.jsxs("button",{type:"button",onClick:()=>r("lineage"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.lineage," →"]}):null}):E.type==="book"?e.jsx(Zr,{data:E,transport:n,onNavigate:g,renderLink:y,fullTextSection:V&&V.chapters.length>0?e.jsx(Ni,{title:E.title,measure:[`${V.total_chapters} ${I("章")}`,I(V.version_label)].filter(Boolean).join(" · "),onOpen:()=>{oe(null),r("fulltext")}}):null}):E.type==="collection"?e.jsx(Qr,{data:E,catalog:(re=J[0])==null?void 0:re.data,transport:n,onNavigate:g,renderLink:y,catalogAction:J.length>0?e.jsxs("button",{type:"button",onClick:()=>r(`catalog:${J[0].resource_id}`),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.collectionCatalog," →"]}):null}):e.jsx(eo,{data:E,transport:n,onNavigate:g,renderLink:y}):null},Qe=()=>{var re,ae,ce;if(!v||!E)return null;if(i==="basic"||i==="emendated")return ge();if(typeof i=="string"&&i.startsWith("catalog:")){const te=(re=J.find(Z=>`catalog:${Z.resource_id}`===i))==null?void 0:re.data;return e.jsx(_n,{data:te,onNavigate:g,renderLink:y})}if(i==="collated")return e.jsx(Fn,{index:K||void 0,workId:t,transport:n,onNavigate:g,activeJuan:N,onJuanChange:oe});if(i==="fulltext")return e.jsx(Wr,{index:V||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:oe});if(i==="lineage"){if(!me)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:ye?"加載中…":"暫無版本圖數據"});const te=E.type==="work"?E:null;return e.jsx(ro,{graph:me,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:c,selectedNodeId:x,collection:l??((ae=te==null?void 0:te.version_graph)==null?void 0:ae.default_collection),onCollectionChange:d,collectionsAvailable:(ce=te==null?void 0:te.version_graph)==null?void 0:ce.collections,collectionCounts:(()=>{var ze,Pn,Hn,On,Dn,Nn,Vn;if(!te)return;const Z={},Le=((ze=Te.current)==null?void 0:ze.books)??[];Z.all=(((Pn=te.books)==null?void 0:Pn.length)??0)-(((On=(Hn=te.version_graph)==null?void 0:Hn.excluded_books)==null?void 0:On.length)??0);const We=(Dn=te.version_graph)==null?void 0:Dn.collections;if(We)for(const Gn of Object.keys(We))Z[Gn]=Mt(te,Le,Gn).nodes.filter(Yn=>Yn.kind==="book"&&!Yn.bridge).length;return Z.core==null&&((Vn=(Nn=te.version_graph)==null?void 0:Nn.core_books)!=null&&Vn.length)&&(Z.core=te.version_graph.core_books.length),Z})()})}if(i==="feedback"&&j)return e.jsx(Jr,{resourceId:t,apiUrl:w});const H=m.find(te=>te.key===i);return H?H.render({detail:E,entry:v,transport:n,onNavigate:g}):null};if($)return e.jsx($t,{style:{minHeight:k,..._},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(A||!E||!v||!ve)return e.jsx($t,{style:{minHeight:k,..._},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const lo=i==="basic"||i==="emendated",Zt=[{label:b??z.detailTab.backToIndex,onClick:u}];if(E.type==="book"&&E.work_id){const H=E.work_id;Zt.push({label:z.indexType.work,id:H,onClick:()=>g==null?void 0:g(H)})}Zt.push({label:z.indexType[E.type]});const Et=i==="collated"||i==="fulltext";return e.jsx("div",{className:T,children:e.jsxs($t,{wide:Et,style:{minHeight:k,..._},children:[e.jsx(yr,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Bn,{char:"籍"}),e.jsx(vr,{items:Zt})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(oo,{}),j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.feedback}),Pe&&e.jsx(so,{...Pe})]})}),e.jsx(jr,{...ve,aside:Et?e.jsxs("button",{type:"button",onClick:()=>r("basic"),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:[I("作品信息")," →"]}):ve.aside}),!Et&&X.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:X.map(H=>e.jsx(He,{label:H.label,active:H.key===i||lo&&H.key==="basic",onClick:()=>r(H.key)},H.key))}),e.jsx("div",{style:{marginTop:!Et&&X.length>1?8:0},children:Qe()}),e.jsx(Ir,{left:e.jsxs(e.Fragment,{children:[C,C?" · ":"",e.jsx(cc,{id:E.id,label:z.label.id,copied:z.action.copied})]}),right:e.jsxs(e.Fragment,{children:[j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.submitVersion}),Pe&&e.jsx("a",{href:Pe.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function cc({id:t,label:n,copied:i}){const[r,s]=f.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 o;(o=navigator.clipboard)==null||o.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}).catch(()=>{})},title:r?i:void 0,style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:r?"✓":"⧉"})]})}function dc(t,n){return n?t.workSubtype[n]??n:""}function Ni({title:t,measure:n,onOpen:i}){const{convert:r}=P(),[s,o]=f.useState(!1),a=r(t?`進入《${t}》全文閲讀`:"進入全文閲讀"),c=[n,r("全文檢索"),r("原書對照")].filter(Boolean).join(" · ");return e.jsx(Ce,{style:{marginTop:-12,marginBottom:28},children:e.jsxs("div",{role:"button",tabIndex:0,onClick:i,onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),i())},onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,flexWrap:"wrap",padding:"14px 26px",cursor:"pointer",background:s?"var(--bim-band-bg-hover, #e6d5b4)":"var(--bim-band-bg, #f0e4cb)",borderLeft:"3px solid var(--bim-accent, #9c3a2c)",transition:"background .18s ease"},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontFamily:"var(--bim-font-body, system-ui, sans-serif)",fontSize:21,fontWeight:600,letterSpacing:".02em",lineHeight:1.3,color:"var(--bim-ink, #2a231c)"},children:a}),e.jsx("div",{className:"bim-d-ui",style:{marginTop:4,fontSize:12.5,letterSpacing:".06em",color:"var(--bim-meta-fg, #7b6a54)"},children:c})]}),e.jsxs("span",{className:"bim-d-ui","aria-hidden":!0,style:{flex:"none",padding:"11px 22px",fontSize:14,letterSpacing:".08em",background:s?"var(--bim-accent-deep, #6f2a20)":"var(--bim-accent, #9c3a2c)",color:"var(--bim-page-bg, #fbf9f3)",transition:"background .18s ease"},children:[r("開始閲讀")," →"]})]})})}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=Dt;exports.BidUrlProvider=yo;exports.BookDetailLayout=ac;exports.BookFullText=Wr;exports.BookPage=Zr;exports.Breadcrumb=vr;exports.Chip=Rt;exports.ChipWall=Kt;exports.CollatedEdition=Fn;exports.CollectionCatalog=_n;exports.CollectionPage=Qr;exports.CreateEntityDialog=Or;exports.DETAIL_CSS=hr;exports.Dash=rt;exports.DataTable=qe;exports.DetailFooter=Ir;exports.DetailHeader=jr;exports.EmendatedBySection=rr;exports.EmptyNote=st;exports.EntityDetail=Zi;exports.EntityPage=eo;exports.EntityPickerDialog=Nr;exports.EntitySelector=Hr;exports.ExpandRow=kr;exports.ExtLink=fn;exports.FactList=zt;exports.FeedbackButton=va;exports.FeedbackDialog=Ur;exports.FeedbackForm=Kr;exports.FeedbackList=Mn;exports.FeedbackTab=Jr;exports.FilterChip=He;exports.FormInput=he;exports.FormTextArea=Ue;exports.GlyphBadge=Bn;exports.HomePage=mn;exports.IndexApp=Cl;exports.IndexBrowser=dn;exports.IndexDetail=wn;exports.IndexEditor=Vr;exports.IndexView=aa;exports.IntroGrid=Tt;exports.LocaleContext=_t;exports.LocaleProvider=To;exports.LocaleToggle=oo;exports.ModeIndicator=qi;exports.MoreButton=De;exports.PAGE_MAX_WIDTH=mt;exports.PageFrame=$t;exports.Quote=At;exports.ROLE_CLASS_ORDER=ur;exports.RelationPanel=Mr;exports.RepoSourceLink=so;exports.ResourceEditor=cn;exports.ResourceGroup=xn;exports.ResourceLine=ot;exports.ResourceList=kn;exports.ResourceRow=wr;exports.SearchInput=Xi;exports.Section=ke;exports.SectionHead=ue;exports.SmartBidInput=Ft;exports.SourceEditor=$r;exports.TableHead=Jt;exports.TableRow=qt;exports.TagRow=Ln;exports.TagRows=Cr;exports.TextButton=Ut;exports.TopStrip=yr;exports.VersionLineageGraph=io;exports.VersionLineageList=no;exports.VersionLineageView=ro;exports.VolumeChips=Sr;exports.VolumeLinks=_r;exports.WorkCatalog=Il;exports.WorkPage=Xr;exports.bucketResources=Yt;exports.buildCollectionTable=fr;exports.buildLineageGraph=Mt;exports.buildPageUrl=Sn;exports.buildVersionRow=dr;exports.buildVersionTable=pr;exports.computeVersionPartition=Ls;exports.deriveDating=Rs;exports.deriveEditionType=mr;exports.deriveEra=It;exports.deriveYear=Gt;exports.deriveYearRange=In;exports.detailToEditor=Yr;exports.displayAuthorRole=Rn;exports.editorToDetail=la;exports.eraRank=un;exports.flattenTitles=wt;exports.formatTemplate=Ct;exports.formatVolumeRange=En;exports.getDisplayNameFromUrl=St;exports.getStartPage=jn;exports.getTypeGroupKey=bn;exports.groupRelatedWorks=cr;exports.measureText=Je;exports.mergeVolumeResources=yn;exports.normalizeEra=pe;exports.normalizeRole=zn;exports.normalizeVolumeIndex=vt;exports.normalizeVolumes=Ji;exports.numberToChinese=gr;exports.parseChineseNumber=Ht;exports.parseSourceString=Ar;exports.resourceHref=Pt;exports.resourceNote=Tn;exports.roleFacets=xr;exports.rowNo=Xt;exports.sortYear=ar;exports.stringifySources=Fr;exports.useBidUrl=be;exports.useConvert=P;exports.useT=D;exports.validateLineageGraph=Ha;exports.volumeStats=vn;
|
|
96
|
+
`;function $t({children:t,style:n,wide:i}){return e.jsxs("div",{className:"bim-d-page",style:n,children:[e.jsx("style",{children:hr}),e.jsx("div",{className:i?"bim-d-main bim-d-main-wide":"bim-d-main",children:t})]})}function br({aside:t,children:n}){return e.jsxs("div",{className:"bim-d-reader",children:[e.jsx("aside",{className:"bim-d-reader-aside bim-d-ui",children:t}),e.jsx("div",{className:"bim-d-reader-main",children:n})]})}function yr({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 Ln({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 vr({items:t}){const n=be();return e.jsx(e.Fragment,{children:t.map((i,r)=>{const s=r===t.length-1,o=r>0&&e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"/"},`s${r}`),a=i.id?n(i.id):i.href,c=s||!i.onClick&&!a?e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:i.label},r):e.jsx("a",{href:a??"#",onClick:i.onClick?l=>{l.metaKey||l.ctrlKey||(l.preventDefault(),i.onClick())}:void 0,style:{color:"var(--bim-meta-fg, #7b6a54)"},children:i.label},r);return e.jsxs(f.Fragment,{children:[o,c]},r)})})}function jr({title:t,subtitle:n,aside:i,secondLine:r}){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})]}),r&&e.jsx("div",{style:{marginTop:12,fontSize:13.5,color:"var(--bim-quiet-fg, #5b4f40)"},children:r})]})}function Tt({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 zt({items:t,horizontal:n}){const{convert:i}=P();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((r,s)=>e.jsxs("div",{title:r.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(r.label)}),e.jsx("span",{style:{color:"var(--bim-body-fg, #3b3228)",textAlign:n?"left":"right",minWidth:0},children:r.value})]},s))}):null}function ue({glyph:t,tone:n,title:i,count:r,actions:s,id:o}){const{convert:a}=P();return e.jsxs("div",{id:o,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(Ln,{char:t,tone:n}),e.jsx("h2",{style:{margin:0,fontSize:19,fontWeight:600,letterSpacing:".1em"},children:a(i)}),r!=null&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:r})]}),s&&e.jsx("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:14,fontSize:12},children:s})]})}function Ce({children:t,style:n}){return e.jsx("section",{style:{marginBottom:48,...n},children:t})}function Oe({label:t,active:n,onClick:i,dashed:r}){const{convert:s}=P();return e.jsx("button",{type:"button",onClick:i,"aria-pressed":n,className:"bim-d-ui",style:{padding:"5px 13px",border:`1px ${r&&!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:s(t)})}function Yt({label:t,onClick:n}){const{convert:i}=P();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:i(t)})}function De({label:t,onClick:n,inline:i}){const{convert:r}=P();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:r(t)})}function Rt({children:t,href:n,onClick:i,title:r}){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:r,onClick:i?o=>{o.metaKey||o.ctrlKey||(o.preventDefault(),i())}:void 0,style:s,children:t}):e.jsx("span",{title:r,style:s,children:t})}function Kt({children:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t})}function Sr({volumes:t,unit:n="冊",max:i=60}){const[r,s]=f.useState(!1);if(!t.length)return null;const o=r?t:t.slice(0,i);return e.jsxs("div",{className:"bim-d-ui",style:{display:"flex",flexWrap:"wrap",gap:4,fontSize:11.5},children:[o.map(a=>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:a},a)),!r&&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 qe({children:t}){return e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t})}function Jt({spec:t}){const{convert:n}=P();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:n(t.mainLabel)}),e.jsx("span",{style:{display:"grid",gridTemplateColumns:t.columns.map(i=>i.width).join(" "),gap:12},children:t.columns.map(i=>e.jsx("span",{children:n(i.label)},i.label))})]})}function qt({no:t,main:n,meta:i,spec:r}){return e.jsxs("div",{className:"bim-d-row",style:{gridTemplateColumns:`${r.leadWidth}px 1fr ${r.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:r.columns.map(s=>s.width).join(" "),gap:12,alignItems:"center",fontSize:12},children:i})]})}function Xt(t){return String(t+1).padStart(2,"0")}function rt(){return e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"—"})}function kr({open:t,onToggle:n,main:i,action:r,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}),r]}),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 wr(t){const n=[];for(let i=0;i<t.length;i++){const r=t[i];let s;if(r==="⟨")s="⟩";else if(r==="<"){const c=t[i+1];if(c===void 0||/[A-Za-z/!?>\s]/.test(c))continue;s=">"}else continue;const o=t.indexOf(s,i+1);if(o<0)continue;const a=t.slice(i+1,o);a.includes(`
|
|
97
|
+
`)||(n.push({start:i,end:o+1,inner:a}),i=o)}return n}function _r(t,n){if(t.length<=n)return t;let i=n;for(const r of wr(t)){if(r.start>=i)break;if(r.end>i){i=r.start>0?r.start:r.end;break}}return t.slice(0,i)}function Fe(t,n=i=>i){if(!t)return"";if(t.indexOf("⟨")<0&&t.indexOf("<")<0)return n(t);const i=[];let r=0,s=0;for(const o of wr(t))o.start>r&&i.push(e.jsx(f.Fragment,{children:n(t.slice(r,o.start))},s++)),i.push(e.jsx("span",{className:"bim-jiazhu",style:{fontSize:".78em",color:"var(--bim-meta-fg, #7b6a54)",lineHeight:1.55},children:n(o.inner)},s++)),r=o.end;return r<t.length&&i.push(e.jsx(f.Fragment,{children:n(t.slice(r))},s++)),i}function At({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 fn({title:t,tag:n,children:i}){const{convert:r}=P();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:r(t)}),n&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:10.5,color:"var(--bim-accent, #9c3a2c)",letterSpacing:".06em"},children:r(n)})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:i})]})}function Cr({name:t,note:n,href:i,extra:r}){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})]}),o={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:o,children:s}):e.jsx("div",{style:o,children:s}),r]})}function ot({item:t,siblings:n,showVolumes:i=!0,fallbackNote:r}){const{convert:s}=P(),[o,a]=f.useState(!1),c=jn(t),l=i&&!!c&&c.expected>0,d=(t.url?St(t.url):void 0)||s(t.name),p=n?Ls(t,n):"",x=p?`${d}(${p})`:d;return e.jsx(Cr,{name:x,note:zn(t)||r,href:Pt(t),extra:l?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>a(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:o?"收起分冊":`展開 ${c.expected} 冊`}),o&&e.jsx(Ir,{item:t})]}):void 0})}function Ir({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 r=n.status==="missing";return n.url&&!r?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:r?"var(--bim-missing-fg, #e67e22)":"var(--bim-hint-fg, #b3a385)",textDecoration:r?"line-through":void 0},children:n.volume},i)})})}function Wn({label:t,items:n}){const{convert:i}=P();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((r,s)=>e.jsx(Rt,{children:i(r)},s))]}):null}function Tr({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(Wn,{label:i.label,items:i.items},i.label))}):null}function wt(t){return(t||[]).map(n=>typeof n=="string"?n:n==null?void 0:n.book_title).filter(n=>!!n)}function zr({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 st({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 _e({id:t,label:n,onNavigate:i,renderLink:r,style:s,dense:o}){const a=be();return r?e.jsx(e.Fragment,{children:r(t,typeof n=="string"?n:void 0,{dense:o})}):e.jsx("a",{href:a(t),onClick:i?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),i(t))}:void 0,style:s,children:n??t})}function gn({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 pi={A:"fine",B:"rough",C:"rough",D:"ocr"};function Hs(t){return typeof t!="string"?null:t in Gi?t:t in pi?pi[t]:null}const Os={書:"书",類:"类",結語:"结语",結语:"结语",考證:"考证",詩:"诗"},Ds={book:"书",poem:"诗",category:"类",preface:"序",verification:"考证",prose:"书",reconstruction:"书",comment:"注释"};function xe(t){return typeof t!="string"?"":Os[t]??Ds[t]??t}const Ns=["〇","一","二","三","四","五","六","七","八","九"],ui=["","十","百","千"],Vs=["","萬","億"];function Rr(t){if(t===0)return"〇";if(t<0)return`負${Rr(-t)}`;const n=[];let i=t,r=0;for(;i>0;){const s=i%1e4;s>0?n.unshift(Gs(s,r>0)+Vs[r]):n.length>0&&n.unshift("〇"),i=Math.floor(i/1e4),r++}return n.join("").replace(/〇+/g,"〇").replace(/〇$/,"")}function Gs(t,n){const i=[];let r=t;for(;r>0;)i.unshift(r%10),r=Math.floor(r/10);let s="";for(let o=0;o<i.length;o++){const a=i[o],c=i.length-1-o;a===0?s&&!s.endsWith("〇")&&(s+="〇"):a===1&&c===1&&o===0&&!n?s+=ui[c]:s+=Ns[a]+ui[c]}return s.replace(/〇$/,"")}let jt=null,Lt=null;const Ot=new Set;function Us(){return jt?Promise.resolve():Lt||(Lt=import("opencc-js/t2cn").then(t=>{jt=t.Converter({from:"tw",to:"cn"}),Ot.forEach(n=>n())}).catch(()=>{jt=t=>t,Ot.forEach(t=>t())}),Lt)}function Pe(){const[,t]=f.useState(0);return f.useEffect(()=>{if(jt)return;const n=()=>t(i=>i+1);return Ot.add(n),Us(),()=>{Ot.delete(n)}},[]),jt??(n=>n)}function lt(t,n){return n(t).toLowerCase()}const $n="var(--bim-highlight-bg, #fff59d)";function at(t,n,i){if(!n)return t;const r=lt(n,i);if(!r)return t;const s=lt(t,i);if(s.length!==t.length)return t;const o=[];let a=0,c=0;for(;a<t.length;){const l=s.indexOf(r,a);if(l===-1){o.push(t.slice(a));break}l>a&&o.push(t.slice(a,l)),o.push(e.jsx("mark",{style:{background:$n,padding:0,color:"inherit"},children:t.slice(l,l+r.length)},c++)),a=l+r.length}return e.jsx(e.Fragment,{children:o})}function An(t,n,i,r){if(!n)return!0;const s=lt(n,r);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(a=>typeof a=="string"&<(a,r).includes(s))}function Ys(t,n,i){return n?lt(t,i).includes(lt(n,i)):!0}const Fn={类:"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)"},Ks={考证:"var(--bim-section-kaozhen, #5d6d7e)"};function Js(t){const n=t.replace(".json","").replace(/[/\\]/g,"");return n==="fulu"?"附錄":n.startsWith("juanshou")?`卷首${n.replace("juanshou","")}`:n.startsWith("juan")?`卷${n.replace("juan","").replace(/^0+/,"")}`:n}function mn({file:t,isActive:n,onSelect:i,meta:r,matchState:s,vertical:o}){const a=s===0,c=s==="loading",l=typeof s=="number"&&s>0,d=r!=null&&r.vol_label?`${r.vol_label}冊`:null,p=d??Js(t),x=!d&&!!(r!=null&&r.vol_label)&&!p.includes(r.vol_label);return e.jsxs("button",{onClick:()=>{a||i(t)},disabled:a,style:{padding:o?"4px 8px":"3px 8px",textAlign:o?"left":"center",width:o?"100%":void 0,border:o?"1px solid transparent":n?"1px solid var(--bim-primary, #8e6f3e)":a?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderLeft:o?`2px solid ${n?"var(--bim-primary, #8e6f3e)":"transparent"}`:void 0,borderRadius:o?0:"3px",background:n?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":l?`${$n}40`:"transparent",color:n?"var(--bim-primary, #8e6f3e)":a?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:a?"not-allowed":"pointer",fontSize:"12px",fontWeight:n?600:400,lineHeight:1.4,opacity:a?.5:1},children:[p,x&&e.jsxs("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",r.vol_label,"冊)"]}),l&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:s}),c&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}function Er(t,n){var i;return t.files.includes(n)?!0:!!((i=t.children)!=null&&i.some(r=>Er(r,n)))}function Br(t){var r;const n=t.files.length,i=((r=t.children)==null?void 0:r.reduce((s,o)=>s+Br(o),0))||0;return n+i}function qs(t,n){const i=[],r=a=>{var c;i.push(...a.files),(c=a.children)==null||c.forEach(r)};if(r(t),i.length===0)return;const s=i.map(a=>n[a]);if(s.every(a=>a===void 0))return;if(s.some(a=>a==="loading"))return"loading";let o=0;for(const a of s)typeof a=="number"&&(o+=a);return o}function Lr({group:t,activeFile:n,onSelect:i,depth:r=0,juanMeta:s,matchStates:o,vertical:a}){var y;const c=Er(t,n||""),l=qs(t,o),d=typeof l=="number"&&l>0,p=l===0,[x,g]=f.useState(c||d),u=Br(t),b=!!((y=t.children)!=null&&y.length);if(f.useEffect(()=>{c&&g(!0)},[c]),f.useEffect(()=>{d&&g(!0)},[d]),t.files.length===1&&!b){const h=t.files[0],S=n===h,m=o[h],j=m===0,w=m==="loading",k=typeof m=="number"&&m>0;return e.jsxs("button",{onClick:()=>{j||i(h)},disabled:j,style:{display:"inline-block",padding:"3px 8px",margin:"2px 0",marginLeft:`${8+r*16}px`,border:S?"1px solid var(--bim-primary, #8e6f3e)":j?"1px dashed var(--bim-widget-border, #e0e0e0)":"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"3px",background:S?"color-mix(in srgb, var(--bim-primary, #8e6f3e) 10%, transparent)":k?`${$n}40`:"transparent",color:S?"var(--bim-primary, #8e6f3e)":j?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",cursor:j?"not-allowed":"pointer",fontSize:"12px",fontWeight:S?600:400,lineHeight:1.4,opacity:j?.5:1},children:[t.label,k&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:m}),w&&e.jsx("span",{style:{marginLeft:"5px",fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]})}return e.jsxs("div",{style:{marginBottom:r===0?"4px":"2px"},children:[e.jsxs("div",{onClick:()=>g(!x),style:{display:"flex",alignItems:"center",gap:"6px",padding:r===0?"4px 8px":"2px 8px",paddingLeft:`${8+r*16}px`,cursor:"pointer",userSelect:"none",fontSize:r===0?"13px":"12px",fontWeight:r===0?600:500,color:c?"var(--bim-primary, #8e6f3e)":p?"var(--bim-desc-fg, #bbb)":"var(--bim-fg, #333)",opacity:p?.6:1},children:[e.jsx("span",{style:{fontSize:"9px",transition:"transform 0.15s",transform:x?"rotate(90deg)":"none",display:"inline-block"},children:"▶"}),e.jsx("span",{children:t.label}),e.jsxs("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #999)"},children:["(",u,")"]}),d&&e.jsxs("span",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-matchstate-fg, #b78900)"},children:["匹配 ",l]}),l==="loading"&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:"…"})]}),x&&e.jsxs(e.Fragment,{children:[t.files.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:a?"column":"row",flexWrap:a?"nowrap":"wrap",gap:a?"1px":"4px",padding:a?`2px 0 2px ${8+r*10}px`:`4px 0 4px ${24+r*16}px`},children:t.files.map(h=>e.jsx(mn,{file:h,isActive:n===h,onSelect:i,meta:s==null?void 0:s[h],matchState:o[h],vertical:a},h))}),b&&t.children.map((h,S)=>e.jsx(Lr,{group:h,activeFile:n,onSelect:i,depth:r+1,juanMeta:s,matchStates:o,vertical:a},S))]})]})}function Xs({files:t,groups:n,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:a}){const c=t||[];return n&&n.length>0?e.jsx("div",{style:{marginBottom:a?0:"16px"},children:n.map((l,d)=>e.jsx(Lr,{group:l,activeFile:i,onSelect:r,juanMeta:s,matchStates:o,vertical:a},d))}):c.length===0?null:a?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"1px"},children:c.map(l=>e.jsx(mn,{file:l,isActive:i===l,onSelect:r,meta:s==null?void 0:s[l],matchState:o[l],vertical:!0},l))}):e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"4px",marginBottom:"16px",maxHeight:"120px",overflow:"auto",padding:"4px 0"},children:c.map(l=>e.jsx(mn,{file:l,isActive:i===l,onSelect:r,meta:s==null?void 0:s[l],matchState:o[l]},l))})}function Zs({type:t}){const n=xe(t),i=Fn[n]||"var(--bim-desc-fg, #717171)";return e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:i,border:`1px solid ${i}40`,borderRadius:"2px",background:`${i}08`,flexShrink:0},children:n})}function Qs({section:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),s=be(),o=Pe(),a=y=>y?Fe(r(y),h=>i?at(h,i,o):h):"",[c,l]=f.useState(!1),d=!!t.summary,p=!!t.comment,x=!!t.additional_comment,g=!!(t.content&&t.content.length>60),u=d||p||x||g;f.useEffect(()=>{i&&l(!0)},[i]);const b=!c&&g?_r(t.content.replace(/\n/g," "),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&&l(!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:["《",a(t.book_title),"》"]}):a(t.title),t.n_juan!=null&&e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"6px"},children:[Rr(t.n_juan),"卷"]}),(t.author_info||t.author)&&e.jsx("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #999)",marginLeft:"8px"},children:a(t.author_info||t.author)})]}),!c&&b&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginTop:"2px"},children:a(b)})]}),t.edition&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:a(t.edition)}),t.tag&&e.jsx("span",{style:{fontSize:"11px",color:"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:a(t.author_info)}),t.summary&&e.jsxs("div",{style:{marginBottom:"8px",padding:"10px 14px",borderLeft:"3px solid var(--bim-primary, #8e6f3e)",background:"color-mix(in srgb, var(--bim-primary, #8e6f3e) 4%, transparent)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"提要"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify"},children:a(t.summary)})]}),t.comment&&e.jsxs("div",{style:{marginBottom:"8px",padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #aaa)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"按語"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.comment)})]}),t.additional_comment&&e.jsxs("div",{style:{padding:"8px 14px",borderLeft:"3px solid var(--bim-desc-fg, #ccc)",borderRadius:"0 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"11px",fontWeight:600,color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",letterSpacing:"1px"},children:"附按"}),e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #555)",lineHeight:1.8,margin:0,fontStyle:"italic"},children:a(t.additional_comment)})]}),g&&!d&&!p&&!x&&e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:1.9,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:a(t.content)})]})]})}function el({section:t,highlightQuery:n=""}){const{convert:i}=P(),r=Pe(),s=l=>l?Fe(i(l),d=>n?at(d,n,r):d):"",[o,a]=f.useState(!1),c=!!t.content;return e.jsxs("div",{style:{padding:"12px 0 6px"},children:[e.jsxs("div",{onClick:()=>c&&a(!o),style:{display:"flex",alignItems:"center",gap:"8px",cursor:c?"pointer":"default",userSelect:"none"},children:[e.jsx(Zs,{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:o?"rotate(90deg)":"none",display:"inline-block"},children:"▶"})]}),o&&c&&e.jsx("div",{style:{marginTop:"8px",padding:"10px 14px",borderLeft:`3px solid color-mix(in srgb, ${Fn[xe(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)})})]})}const tl=100;function Wr(t){return xe(t.type)!=="page_header"?!1:(t.content||"").length>=tl}function nl({section:t,highlightQuery:n=""}){const{convert:i}=P(),r=Pe();if(xe(t.type)==="page_header"&&!Wr(t)||!t.content&&!t.title)return null;const s=i((t.content||t.title||"").replace(/\n{2,}/g,`
|
|
98
|
+
`)),o=Fe(s,d=>n?at(d,n,r):d),a=xe(t.type),c=Fn[a]||"var(--bim-desc-fg, #717171)",l=a==="序"||a==="结语"||a==="注释";return e.jsxs("div",{style:{padding:l?"10px 12px":"6px 0",margin:l?"8px 0":void 0,fontSize:"13px",color:"var(--bim-desc-fg, #555)",lineHeight:1.8,whiteSpace:"pre-line",borderLeft:l?`3px solid ${c}40`:void 0,background:l?"var(--bim-bg, #fafafa)":void 0,borderRadius:l?"0 4px 4px 0":void 0,position:"relative"},children:[l&&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:a}),o]})}function il(t,n,i){const[r,s]=f.useState({});return f.useEffect(()=>{var d;if(!n||t.length===0)return;let o=!1;const a=t.filter(p=>{var x;return!((x=i==null?void 0:i.current)!=null&&x.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),a.length===0)return;const l=async p=>{var x;try{if(n.getEntry){const h=await n.getEntry(p);if(h)return{title:h.title,author:h.author}}const g=await n.getItem(p);if(!g)return null;const u=g.title||p,b=g.authors,y=(x=b==null?void 0:b[0])==null?void 0:x.name;return{title:u,author:y}}catch{return null}};return Promise.all(a.map(async p=>{var g;const x=await l(p);return(g=i==null?void 0:i.current)==null||g.set(p,x),[p,x]})).then(p=>{o||s(x=>{const g={...x};for(const[u,b]of p)g[u]=b;return g})}),()=>{o=!0}},[t.join(","),n]),r}function rl({section:t,onNavigate:n,transport:i,workLabelCache:r,highlightQuery:s=""}){const{convert:o}=P(),a=be(),c=Pe(),l=m=>m?Fe(o(m),j=>s?at(j,s,c):j):"",[d,p]=f.useState(!1);f.useEffect(()=>{s&&p(!0)},[s]);const x=xe(t.type),g=Ks[x]||"var(--bim-desc-fg, #717171)",u=!!t.content,b=t.work_ids||[],y=b.length>1,h=il(y?b:[],i,r),S=u&&!d&&t.content.length>80?_r(t.content,80)+"……":null;return e.jsxs("div",{style:{borderBottom:"1px solid var(--bim-widget-border, #f0f0f0)",padding:"10px 0"},children:[e.jsxs("div",{onClick:()=>u&&p(!d),style:{display:"flex",alignItems:"flex-start",gap:"8px",cursor:u?"pointer":"default",userSelect:"none"},children:[u&&e.jsx("span",{style:{fontSize:"9px",color:"var(--bim-desc-fg, #aaa)",marginTop:"5px",transition:"transform 0.15s",transform:d?"rotate(90deg)":"none",display:"inline-block",flexShrink:0},children:"▶"}),e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--bim-fg, #1a1a1a)",lineHeight:1.6},children:t.header_line?l(t.header_line):l(t.title)}),!d&&S&&e.jsx("p",{style:{margin:"4px 0 0",fontSize:"12px",color:"var(--bim-desc-fg, #aaa)",lineHeight:1.7},children:l(S)})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[b.length===1&&n&&e.jsx("a",{href:a(b[0]),onClick:m=>{m.metaKey||m.ctrlKey||(m.preventDefault(),m.stopPropagation(),n(b[0]))},style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",flexShrink:0},title:"查看作品",children:"→作品"}),y&&e.jsxs("span",{style:{fontSize:"11px",color:"var(--bim-link-fg, #0066cc)",flexShrink:0},children:[b.length,"部作品"]}),e.jsx("span",{style:{display:"inline-block",padding:"1px 5px",fontSize:"10px",fontWeight:500,color:g,border:`1px solid ${g}40`,borderRadius:"2px",background:`${g}08`},children:x})]})]}),y&&n&&e.jsx("div",{style:{margin:"6px 0 0 17px",display:"flex",flexWrap:"wrap",gap:"4px 12px"},children:b.map(m=>{const j=h[m],w=j?`${o(j.title)}${j.author?`(${o(j.author)})`:""}`:m.slice(0,8)+"…";return e.jsxs("a",{href:a(m),onClick:k=>{k.metaKey||k.ctrlKey||(k.preventDefault(),k.stopPropagation(),n(m))},style:{fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",textDecoration:"none",lineHeight:1.8},title:m,children:["→",w]},m)})}),d&&u&&e.jsxs("div",{style:{marginTop:"10px",padding:"12px 16px",borderLeft:`3px solid ${g}40`,borderRadius:"0 4px 4px 0",background:"var(--bim-bg, #fafafa)"},children:[e.jsx("p",{style:{fontSize:"13px",color:"var(--bim-fg, #333)",lineHeight:2,margin:0,textAlign:"justify",whiteSpace:"pre-line"},children:l(t.content)}),t.comment&&e.jsx("div",{style:{marginTop:"10px",paddingTop:"8px",borderTop:"1px solid var(--bim-widget-border, #eee)",fontSize:"12px",color:"var(--bim-desc-fg, #717171)",lineHeight:1.8,fontStyle:"italic"},children:l(t.comment)})]})]})}function ol({juan:t,searchQuery:n,onNavigate:i,transport:r,workLabelCache:s}){const{convert:o}=P(),a=Pe(),c=n.trim(),l=f.useMemo(()=>c?t.sections.filter(x=>An(x,c,!0,a)):t.sections,[t.sections,c,a]),d=t.sections.filter(x=>xe(x.type)==="考证").length,p=l.filter(x=>xe(x.type)==="考证").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"12px",marginBottom:"4px"},children:[e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:0},children:o(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:l.map((x,g)=>e.jsx(rl,{section:x,onNavigate:i,transport:r,workLabelCache:s,highlightQuery:c},g))}),l.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function sl({text:t,highlightQuery:n=""}){const{convert:i}=P(),r=Pe(),s=a=>Fe(i(a),c=>n?at(c,n,r):c),o=t.split(`
|
|
99
|
+
`);return e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:o.map((a,c)=>{if(a.startsWith("# "))return e.jsx("h2",{style:{fontSize:"17px",fontWeight:700,margin:"16px 0 8px"},children:s(a.slice(2))},c);if(a.startsWith("## "))return e.jsx("h3",{style:{fontSize:"16px",fontWeight:600,margin:"14px 0 6px"},children:s(a.slice(3))},c);if(a.startsWith("### "))return e.jsx("h4",{style:{fontSize:"15px",fontWeight:600,margin:"12px 0 4px"},children:s(a.slice(4))},c);if(!a.trim())return c>0&&!o[c-1].trim()?null:e.jsx("div",{style:{height:"0.5em"}},c);const l=a.split(/(\*\*[^*]+\*\*)/g);return e.jsx("p",{style:{margin:"6px 0",textIndent:"2em",whiteSpace:"pre-wrap"},children:l.map((d,p)=>d.startsWith("**")&&d.endsWith("**")?e.jsx("strong",{children:s(d.slice(2,-2))},p):e.jsx(f.Fragment,{children:s(d)},p))},c)})})}function ll({sections:t,onNavigate:n,highlightQuery:i=""}){const{convert:r}=P(),s=be(),o=Pe(),a=d=>d?Fe(r(d),p=>i?at(p,i,o):p):"",c=[];let l=null;for(const d of t){const p=xe(d.type);p==="page_header"&&!Wr(d)||(p==="类"?(l&&c.push(l),l={category:d.title,categoryContent:d.content||void 0,items:[]}):p==="书"||p==="诗"||p==="考证"||p==="注释"?(l||(l={category:"",items:[]}),l.items.push(d)):(p==="序"||p==="结语")&&(l||(l={category:"",items:[]}),l.items.push(d),p==="结语"&&(c.push(l),l=null)))}return l&&c.push(l),e.jsx("div",{style:{fontSize:"15px",lineHeight:2.2,color:"var(--bim-fg, #333)",textAlign:"justify"},children:c.map((d,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:[a(d.category),d.categoryContent&&e.jsx("span",{style:{fontWeight:400,fontSize:"14px",marginLeft:"8px",color:"var(--bim-desc-fg, #717171)"},children:a(d.categoryContent)})]}),d.items.map((x,g)=>xe(x.type)==="序"||xe(x.type)==="结语"?e.jsx("p",{style:{margin:"12px 0",textIndent:"2em"},children:a(x.content||"")},g):e.jsxs("p",{style:{margin:"8px 0",textIndent:"2em",whiteSpace:"pre-line"},children:[n&&x.work_id?e.jsx("a",{href:s(x.work_id),onClick:u=>{u.metaKey||u.ctrlKey||(u.preventDefault(),u.stopPropagation(),n(x.work_id))},style:{color:"var(--bim-fg, #333)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"3px",cursor:"pointer"},title:r(x.title),children:e.jsx("strong",{children:a(x.title)})}):e.jsx("strong",{children:a(x.title)}),x.content&&a(x.content)]},g))]},p))})}function al({juan:t,rawText:n,searchQuery:i,onNavigate:r}){const{convert:s}=P(),o=Pe(),[a,c]=f.useState("catalog"),l=i.trim(),d=f.useMemo(()=>l?t.sections.filter(u=>An(u,l,!1,o)):t.sections,[t.sections,l,o]),p=t.sections.filter(u=>xe(u.type)==="书").length,x=t.sections.filter(u=>xe(u.type)==="诗").length,g=l?d.filter(u=>xe(u.type)==="书"||xe(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("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",marginLeft:"auto"},children:g!=null?`${g} / ${x>0?`${x} 首`:`${p} 部書`}`:x>0?`${x} 首`:p>0?`${p} 部书`:""}),e.jsx("div",{style:{display:"flex",gap:"2px"},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:a===u?"var(--bim-primary, #8e6f3e)":"var(--bim-input-bg, #fff)",color:a===u?"#fff":"var(--bim-desc-fg, #999)",cursor:"pointer"},children:u==="catalog"?"目錄":"原文"},u))})]}),a==="raw"&&(n?e.jsx(sl,{text:n,highlightQuery:l}):e.jsx(ll,{sections:t.sections,onNavigate:r,highlightQuery:l})),a==="catalog"&&d.map((u,b)=>{const y=xe(u.type);return y==="书"||y==="诗"||y==="考证"?e.jsx(Qs,{section:u,onNavigate:r,highlightQuery:l},b):y==="类"?e.jsx(el,{section:u,highlightQuery:l},b):e.jsx(nl,{section:u,highlightQuery:l},b)}),a==="catalog"&&d.length===0&&e.jsx("div",{style:{padding:"32px",textAlign:"center",color:"var(--bim-desc-fg, #999)",fontSize:"13px"},children:"无匹配结果"})]})}function $r(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 cl(t){const n=$r(t);return n.length>0?n[0]:null}function dl(t){const{workId:n,transport:i,files:r,activeFile:s,activeJuan:o,activeRawText:a,query:c,isKaozhen:l}=t,d=Pe(),p=f.useRef(new Map),[x,g]=f.useState({});f.useEffect(()=>{s&&o&&p.current.set(s,{juan:o,rawText:a})},[s,o,a]),f.useEffect(()=>{p.current.clear(),g({})},[n]);const u=f.useCallback((b,y)=>{let h=0;if(b.juan)for(const S of b.juan.sections)An(S,y,l,d)&&h++;return h===0&&b.rawText&&Ys(b.rawText,y,d)&&(h=1),h},[l,d]);return f.useEffect(()=>{const b=c.trim();if(!b){g({});return}if(!n||!(i!=null&&i.getCollatedJuan)||r.length===0)return;let y=!1;const h={},S=[];for(const C of r){const T=p.current.get(C);T?h[C]=u(T,b):(h[C]="loading",S.push(C))}g(h);const m=8;let j=0;const w=async()=>{var C;for(;j<S.length;){if(y)return;const T=j++,_=S[T];try{const[z,I]=await Promise.all([i.getCollatedJuan(n,_),((C=i.getCollatedJuanText)==null?void 0:C.call(i,n,_))??Promise.resolve(null)]),v={juan:z,rawText:I};if(p.current.set(_,v),y)return;g(R=>({...R,[_]:u(v,b)}))}catch{if(y)return;g(z=>({...z,[_]:0}))}}},k=Array.from({length:Math.min(m,S.length)},()=>w());return Promise.all(k),()=>{y=!0}},[c,n,i,r.join(","),u,d]),{matchStates:x}}const Mn=({index:t,workId:n,transport:i,onNavigate:r,activeJuan:s,onJuanChange:o,className:a,style:c})=>{const[l,d]=f.useState(null),[p,x]=f.useState(!1),[g,u]=f.useState(null),[b,y]=f.useState(null),[h,S]=f.useState(null),[m,j]=f.useState(!1),[w,k]=f.useState(null),[C,T]=f.useState(""),_=f.useRef(new Map),z=f.useRef(0),I=s??b,v=f.useCallback(F=>{y(F),o==null||o(F)},[o]),R=t||l;f.useEffect(()=>{t&&(x(!1),u(null))},[t]),f.useEffect(()=>{if(t||!n||!(i!=null&&i.getCollatedEditionIndex))return;let F=!1;return x(!0),u(null),i.getCollatedEditionIndex(n).then(J=>{F||(J?d(J):u("未找到整理本数据"))}).catch(J=>{F||u(J instanceof Error?J.message:"加载失败")}).finally(()=>{F||x(!1)}),()=>{F=!0}},[t,n,i]),f.useEffect(()=>{if(R&&!I){const F=cl(R);F&&v(F)}},[R,I,v]);const E=n||(R==null?void 0:R.work_id),M=f.useCallback(async F=>{var W;if(!E||!(i!=null&&i.getCollatedJuan))return;const J=++z.current;j(!0),S(null),k(null);try{const[U,ie]=await Promise.all([i.getCollatedJuan(E,F),((W=i.getCollatedJuanText)==null?void 0:W.call(i,E,F))??Promise.resolve(null)]);if(J!==z.current)return;S(U),k(ie)}catch{if(J!==z.current)return;S(null),k(null)}finally{J===z.current&&j(!1)}},[E,i]);f.useEffect(()=>{I&&M(I)},[I,M]);const $=F=>{v(F)};if(p)return e.jsx("div",{className:a,style:{...c,padding:"24px"},children:e.jsx("div",{style:{color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:"加载整理本..."})});if(g)return e.jsx("div",{className:a,style:{...c,padding:"24px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:g});if(!R)return null;const O=R.type==="kaozhen",A=$r(R);return e.jsx(pl,{className:a,style:c,index:R,allFiles:A,isKaozhen:O,effectiveWorkId:E,transport:i,activeFile:I,handleSelectFile:$,juanData:h,juanRawText:w,juanLoading:m,searchQuery:C,setSearchQuery:T,onNavigate:r,workLabelCacheRef:_})},pl=({className:t,style:n,index:i,allFiles:r,isKaozhen:s,effectiveWorkId:o,transport:a,activeFile:c,handleSelectFile:l,juanData:d,juanRawText:p,juanLoading:x,searchQuery:g,setSearchQuery:u,onNavigate:b,workLabelCacheRef:y})=>{const{matchStates:h}=dl({workId:o,transport:a,files:r,activeFile:c,activeJuan:d,activeRawText:p,query:g,isKaozhen:s}),S=e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:s?"搜索全部章节…":"搜索全部卷…",value:g,onChange:m=>u(m.target.value),style:{width:"100%",padding:"6px 9px",marginBottom:"12px",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",fontSize:"12.5px",boxSizing:"border-box"}}),e.jsx(Xs,{files:r,groups:i.juan_groups,activeFile:c,onSelect:l,juanMeta:i.juan_metadata,matchStates:h,vertical:!0})]});return e.jsx("div",{className:t,style:n,children:e.jsxs(br,{aside:S,children:[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&&i.target_source&&e.jsxs("span",{children:["考證對象:",e.jsx("strong",{style:{color:"var(--bim-fg, #333)"},children:i.target_source})]})}),i.text_quality&&(()=>{const m=Hs(i.text_quality.grade);return m?e.jsxs("div",{style:{fontSize:"12px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"文本質量:"}),e.jsx(ks,{content:ko[m],children:e.jsx("span",{style:{display:"inline-block",padding:"2px 8px",lineHeight:"16px",textAlign:"center",borderRadius:"3px",fontWeight:600,fontSize:"12px",color:"#fff",background:wo[m],cursor:"help"},children:Gi[m]})}),i.text_quality.source_note&&e.jsxs("span",{style:{marginLeft:"4px"},children:["— ",i.text_quality.source_note]})]}):null})()]}),x?e.jsx(Xe,{}):d?s?e.jsx(ol,{juan:d,searchQuery:g,onNavigate:b,transport:a,workLabelCache:y}):e.jsx(al,{juan:d,rawText:p,searchQuery:g,onNavigate:b}):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((m,j)=>e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",lineHeight:1.8,paddingLeft:"12px"},children:[e.jsxs("span",{children:[j+1,". "]}),m.url?e.jsx("a",{href:m.url,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-desc-fg, #999)",textDecoration:"underline",textDecorationColor:"var(--bim-widget-border, #ddd)",textUnderlineOffset:"2px"},children:m.title}):e.jsx("span",{children:m.title}),m.author&&e.jsxs("span",{children:[",",m.author]}),m.note&&e.jsxs("span",{children:["。",m.note]})]},j))]})]})})},ul={bug:{label:"错误反馈",color:"var(--bim-danger, #f44336)"},resource:{label:"资源建议",color:"var(--bim-primary, #0078d4)"},suggestion:{label:"功能建议",color:"var(--bim-primary, #0078d4)"},other:{label:"其他",color:"var(--bim-desc-fg, #999)"}},xl={label:"其他",color:"var(--bim-desc-fg, #999)"},fl={pending:{label:"待处理",color:"var(--bim-warning, #ff9800)"},in_progress:{label:"处理中",color:"var(--bim-primary, #0078d4)"},resolved:{label:"已处理",color:"var(--bim-success, #4caf50)"},wontfix:{label:"不采纳",color:"var(--bim-desc-fg, #999)"},duplicate:{label:"重复",color:"var(--bim-desc-fg, #999)"}},gl={label:"待处理",color:"var(--bim-warning, #ff9800)"};function ml(t){try{const n=new Date(t),i=r=>String(r).padStart(2,"0");return`${n.getFullYear()}-${i(n.getMonth()+1)}-${i(n.getDate())} ${i(n.getHours())}:${i(n.getMinutes())}`}catch{return t}}function hl(t,n){if(!t)return!1;try{const i=new URL(t,n);if(i.protocol!=="http:"&&i.protocol!=="https:")return!1;const r=new URL(n);return i.hostname===r.hostname}catch{return!1}}const Pn=({items:t,loading:n})=>{const i=be();return n?e.jsx(Xe,{}):t.length===0?e.jsx("div",{style:bl,children:"暂无反馈"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:t.map(r=>{const s=ul[r.type]||xl,o=fl[r.status]||gl,a=typeof window<"u"&&hl(r.pageUrl,window.location.href);return e.jsxs("div",{style:yl,children:[e.jsxs("div",{style:vl,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{...xi,background:s.color},children:s.label}),e.jsx("span",{style:{...xi,background:o.color},children:o.label})]}),e.jsx("span",{style:jl,children:ml(r.createdAt)})]}),(r.resourceId||r.pageUrl)&&e.jsxs("div",{style:Sl,children:[r.resourceId&&e.jsx("a",{href:i(r.resourceId),style:on,children:r.resourceId}),r.pageUrl&&!r.resourceId&&(a?e.jsx("a",{href:r.pageUrl,style:on,children:r.pageUrl.replace(/^https?:\/\/[^/]+/,"")}):e.jsx("span",{style:on,children:r.pageUrl}))]}),e.jsx("div",{style:kl,children:r.content}),r.reply&&e.jsxs("div",{style:wl,children:[e.jsx("div",{style:_l,children:"回复"}),e.jsx("div",{children:r.reply})]})]},r.id)})})},bl={textAlign:"center",padding:"40px 0",color:"var(--bim-desc-fg, #999)",fontSize:"14px"},yl={background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",padding:"16px"},vl={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"10px",flexWrap:"wrap",gap:"8px"},xi={fontSize:"12px",color:"#fff",padding:"2px 8px",borderRadius:"4px",fontWeight:500},jl={fontSize:"12px",color:"var(--bim-desc-fg, #999)"},Sl={fontSize:"12px",marginBottom:"6px"},on={color:"var(--bim-primary, #0078d4)",textDecoration:"none",borderBottom:"1px dashed var(--bim-primary, #0078d4)"},kl={fontSize:"14px",lineHeight:"1.6",color:"var(--bim-fg, #333)",whiteSpace:"pre-wrap"},wl={marginTop:"12px",padding:"10px 12px",background:"var(--bim-input-bg, #f5f5f5)",borderRadius:"6px",fontSize:"13px",lineHeight:"1.6",color:"var(--bim-fg, #333)"},_l={fontSize:"12px",fontWeight:600,marginBottom:"4px",color:"var(--bim-primary, #0078d4)"},hn=({transport:t,onNavigate:n,recommendedIds:i,activeTab:r,onTabChange:s,feedbackApiUrl:o})=>{const a=D(),[c,l]=f.useState(null),[d,p]=f.useState([]),[x,g]=f.useState("recommend"),[u,b]=f.useState([]),[y,h]=f.useState(!1),S=r??x,m=$=>{g($),s==null||s($)},[j,w]=f.useState(!0),[k,C]=f.useState(null),[T,_]=f.useState(null),[z,I]=f.useState(null);f.useEffect(()=>{let $=!1;if(t.getCounts)return t.getCounts().then(O=>{$||l({works:O.works,books:O.books,collections:O.collections})}).catch(()=>{}),()=>{$=!0}},[t]),f.useEffect(()=>{let $=!1;return(async()=>{if(i)return i;if(t.getRecommended)try{const A=await t.getRecommended();if(A!=null&&A.groups)return A.groups.flatMap(F=>F.items.map(J=>({...J,group:F.name})))}catch{}return[]})().then(async A=>{if($)return;const F=A.filter(W=>W.id);if(F.length===0){w(!1);return}const J=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 ie=await t.getItem(W.id);ie&&(U={id:W.id,title:ie.title||W.id,type:ie.type||"work"})}if(U)return{...U,group:W.group,fallbackDescription:W.description}}catch{}return{id:W.id,title:W.title,type:Q.extractType(W.id),group:W.group,fallbackDescription:W.description}}));$||(p(J.filter(W=>W!==null)),w(!1))}),()=>{$=!0}},[t,i]);const v=f.useRef(!1),R=f.useRef(!1),E=f.useRef(!1);f.useEffect(()=>{if(S!=="catalog"||v.current)return;const $=t.getCatalogProgress??t.getResourceProgress;if(!$)return;v.current=!0;let O=!1;return $.call(t).then(A=>{O||C(A)}).catch(()=>{v.current=!1}),()=>{O=!0}},[t,S]),f.useEffect(()=>{if(S!=="collection"||R.current||!t.getCollectionProgress)return;R.current=!0;let $=!1;return t.getCollectionProgress().then(O=>{$||_(O)}).catch(()=>{R.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(S!=="site"||E.current||!t.getSiteProgress)return;E.current=!0;let $=!1;return t.getSiteProgress().then(O=>{$||I(O)}).catch(()=>{E.current=!1}),()=>{$=!0}},[t,S]),f.useEffect(()=>{if(!o||S!=="feedback")return;let $=!1;return h(!0),fetch(o).then(O=>O.json()).then(O=>{!$&&O.success&&b(O.items||[])}).catch(()=>{}).finally(()=>{$||h(!1)}),()=>{$=!0}},[o,S]);const M=$=>{switch($){case"work":return"✍️";case"book":return"📖";case"collection":return"📚";case"entity":return"👤";default:return""}};return e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",height:"100%",padding:"20px",color:"var(--bim-fg, #333)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:"600px",marginBottom:"24px"},children:[e.jsxs("div",{style:{display:"flex",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",marginBottom:"16px"},children:[e.jsx(xt,{label:a.home.recommendTab,active:S==="recommend",onClick:()=>m("recommend")}),e.jsx(xt,{label:a.home.catalogTab,active:S==="catalog",onClick:()=>m("catalog")}),e.jsx(xt,{label:a.home.collectionTab,active:S==="collection",onClick:()=>m("collection")}),e.jsx(xt,{label:a.home.siteTab,active:S==="site",onClick:()=>m("site")}),o&&e.jsx(xt,{label:a.home.feedbackTab,active:S==="feedback",onClick:()=>m("feedback")})]}),S==="recommend"&&e.jsx(Cl,{recommended:d,loading:j,onNavigate:n,getIcon:M,t:a}),S==="catalog"&&e.jsx(fi,{progress:k,t:a,onNavigate:n}),S==="collection"&&e.jsx(fi,{progress:T,t:a,onNavigate:n}),S==="site"&&e.jsx(Tl,{progress:z,t:a,totalWorks:(c==null?void 0:c.works)??0}),S==="feedback"&&o&&e.jsx(Pn,{items:u,loading:y})]})})},xt=({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}),Cl=({recommended:t,loading:n,onNavigate:i,getIcon:r,t:s})=>{const o=be();if(n)return e.jsx(Xe,{});if(t.length===0)return null;const a=new Map;for(const c of t){const l=c.group||s.home.recommendedBrowse;a.has(l)||a.set(l,[]),a.get(l).push(c)}return e.jsx(e.Fragment,{children:Array.from(a.entries()).map(([c,l])=>e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsx("div",{style:{fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:c}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(260px, 1fr))",gap:"8px"},children:l.map(d=>{const p=d.dynasty||d.author?`${d.dynasty?`〔${d.dynasty}〕`:""}${d.author||""}`:d.fallbackDescription;return e.jsxs("a",{href:o(d.id),onClick:x=>{x.metaKey||x.ctrlKey||(x.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:r(d.type)}),e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[d.title,d.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,color:"var(--bim-desc-fg, #717171)",marginLeft:"4px"},children:d.edition})]}),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))})},fi=({progress:t,t:n,onNavigate:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((c,l)=>c.priority-l.priority),s=["in_progress","done","todo"],o={in_progress:n.home.statusInProgress,done:n.home.statusDone,todo:n.home.statusTodo},a={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 l=r.filter(d=>d.status===c);return l.length===0?null:e.jsxs("div",{style:{marginBottom:"20px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"13px",fontWeight:500,color:"var(--bim-desc-fg, #717171)",marginBottom:"8px"},children:[e.jsx("span",{style:{display:"inline-block",width:"8px",height:"8px",borderRadius:"50%",background:a[c]}}),o[c]," (",l.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:l.map(d=>e.jsx(Il,{item:d,t:n,statusColor:a[c],onNavigate:i},d.id))})]},c)})})},Il=({item:t,t:n,statusColor:i,onNavigate:r})=>{const s=be(),o=t.total>0?Math.round(t.imported/t.total*100):0,a=t.type==="catalog"?n.home.typeCatalog:n.home.typeCollection;return e.jsxs("div",{style:{padding:"12px 16px",borderRadius:"8px",border:"1px solid var(--bim-widget-border, #e0e0e0)",background:"var(--bim-input-bg, #fff)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"6px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0},children:[e.jsx("span",{style:{fontSize:"14px",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(()=>{const c=t.edition?`${t.name}·${t.edition}`:t.name,l=t.collection_id||t.work_id;return l&&r?e.jsx("a",{href:s(l),onClick:d=>{d.metaKey||d.ctrlKey||(d.preventDefault(),r(l))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},onMouseEnter:d=>d.currentTarget.style.borderBottomStyle="solid",onMouseLeave:d=>d.currentTarget.style.borderBottomStyle="dashed",children:c}):t.url?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:c}):c})()}),e.jsx("span",{style:{fontSize:"11px",padding:"1px 6px",borderRadius:"4px",background:"var(--bim-widget-border, #e0e0e0)",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap"},children:t.collection_id?n.indexType.collection:t.work_id?n.indexType.work:a})]}),e.jsx("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",whiteSpace:"nowrap",marginLeft:"8px"},children:t.total>0?Ct(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:`${o}%`,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})]})},Tl=({progress:t,t:n,totalWorks:i})=>{if(!t)return e.jsx(Xe,{});const r=[...t.resources].sort((l,d)=>l.priority-d.priority),s=r.filter(l=>l.imported>0),o=r.filter(l=>l.imported===0),a=s.reduce((l,d)=>Math.max(l,d.imported),0),c=i>0?Math.round(a/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:a.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(l=>e.jsx(gi,{item:l,t:n,totalWorks:i},l.id))})]}),o.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," (",o.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:o.map(l=>e.jsx(gi,{item:l,t:n,totalWorks:i},l.id))})]})]})},gi=({item:t,t:n,totalWorks:i})=>{const r=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} (${r}%)`: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:`${r}%`,borderRadius:"2px",background:"var(--bim-progress-done, #10b981)",transition:"width 0.3s ease"}})}),t.description&&e.jsx("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",marginTop:"4px"},children:t.description})]})},mi="(max-width: 768px)";function zl(){const[t,n]=f.useState(()=>typeof window>"u"?!1:window.matchMedia(mi).matches);return f.useEffect(()=>{const i=window.matchMedia(mi),r=s=>n(s.matches);return i.addEventListener("change",r),()=>i.removeEventListener("change",r)},[]),t}const Rl=({transport:t,hideModeIndicator:n=!0,onEntryClick:i,recommendedIds:r,headerRight:s})=>{var O;const o=D(),{convert:a}=P(),c=zl(),[l,d]=f.useState(null),[p,x]=f.useState(null),[g,u]=f.useState(!1),[b,y]=f.useState("detail"),[h,S]=f.useState([]),[m,j]=f.useState(!1),[w,k]=f.useState(null),[C,T]=f.useState(!1),_=f.useCallback(async A=>{if(!t.getCollatedEditionIndex){k(null);return}T(!0);try{const F=await t.getCollatedEditionIndex(A);k(F)}catch{k(null)}finally{T(!1)}},[t]),z=f.useCallback(async A=>{if(!t.getCollectionCatalogs&&!t.getCollectionCatalog){S([]);return}j(!0);try{if(t.getCollectionCatalogs){const F=await t.getCollectionCatalogs(A);S(F||[])}else if(t.getCollectionCatalog){const F=await t.getCollectionCatalog(A);S(F?[{resource_id:"",data:F}]:[])}}catch{S([])}finally{j(!1)}},[t]),I=f.useCallback(async A=>{if(i){i(A);return}d(A),x(null),S([]),k(null),y("detail"),u(!0);try{const F=await t.getItem(A.id);F&&(x(F),F.type==="collection"?z(A.id):F.type==="work"&&F.has_collated&&_(A.id))}catch(F){console.error("加载详情失败:",F)}finally{u(!1)}},[t,i,z,_]),v=f.useCallback(async A=>{x(null),S([]),k(null),y("detail"),u(!0);try{const F=await t.getItem(A);F&&(x(F),d({id:A,title:F.title||A,type:F.type||"book"}),F.type==="collection"?z(A):F.type==="work"&&F.has_collated&&_(A))}catch(F){console.error("导航失败:",F)}finally{u(!1)}},[t,z,_]),R=(p==null?void 0:p.type)==="collection"&&(h.length>0||m)||(p==null?void 0:p.type)==="work"&&(w||C),E=c&&(g||p),M=f.useCallback(()=>{d(null),x(null),S([]),k(null),y("detail")},[]),$=e.jsx(e.Fragment,{children:g?e.jsx(Xe,{}):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:()=>y("detail"),style:Wt(b==="detail"),children:o.detailTab.basicInfo}),p.type==="collection"&&m&&h.length===0&&e.jsxs("button",{onClick:()=>{},style:Wt(!1),children:[o.detailTab.catalog,e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]}),p.type==="collection"&&h.map(A=>e.jsx("button",{onClick:()=>y(`catalog:${A.resource_id}`),style:Wt(b===`catalog:${A.resource_id}`),children:A.short_name?`${a(A.short_name)}${o.detailTab.catalogSuffix}`:o.detailTab.collectionCatalog},A.resource_id)),p.type==="work"&&(w||C)&&e.jsxs("button",{onClick:()=>y("collated"),style:Wt(b==="collated"),children:[o.detailTab.collatedEdition,C&&e.jsx("span",{style:{marginLeft:"4px",fontSize:"11px",opacity:.6},children:"..."})]})]}),s&&e.jsx("div",{style:{marginLeft:"auto",flexShrink:0,padding:"4px 0"},children:s})]}),e.jsx("div",{style:{padding:c?"16px 12px":"32px 48px",maxWidth:"900px",flex:1,overflow:"auto"},children:b==="detail"?e.jsx(_n,{data:p,transport:t,onNavigate:v}):b.startsWith("catalog:")?e.jsx(Cn,{data:(O=h.find(A=>`catalog:${A.resource_id}`===b))==null?void 0:O.data,onNavigate:v}):b==="collated"?e.jsx(Mn,{index:w||void 0,workId:p.id,transport:t,onNavigate:v}):null})]}):e.jsx(hn,{transport:t,onNavigate:v,recommendedIds:r})});return c?e.jsx("div",{style:{display:"flex",flexDirection:"column",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children: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: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:["← ",o.detailTab.basicInfo]})}),e.jsx("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column"},children:$})]}):e.jsxs("div",{style:{flex:1,overflow:"auto"},children:[e.jsx(pn,{transport:t,onEntryClick:I,hideModeIndicator:n}),!p&&e.jsx(hn,{transport:t,onNavigate:v,recommendedIds:r})]})}):e.jsxs("div",{style:{display:"flex",height:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif',background:"var(--bim-bg, #f5f5f5)",color:"var(--bim-fg, #333)"},children:[e.jsx("div",{style:{width:"420px",flexShrink:0,borderRight:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",flexDirection:"column",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(pn,{transport:t,onEntryClick:I,hideModeIndicator:n})})}),e.jsx("div",{style:{flex:1,overflow:"auto",background:"var(--bim-bg, #f5f5f5)",display:"flex",flexDirection:"column"},children:$})]})};function Wt(t){return{padding:"10px 16px",border:"none",borderBottom:t?"2px solid var(--bim-primary, #0078d4)":"2px solid transparent",background:"transparent",color:t?"var(--bim-primary, #0078d4)":"var(--bim-desc-fg, #717171)",cursor:"pointer",fontSize:"13px",fontWeight:t?600:400}}function Ne(t){return t.replace(/\.md$/,"")}const Ar=({index:t,bookId:n,transport:i,activeChapter:r,onChapterChange:s})=>{const[o,a]=f.useState(t??null),[c,l]=f.useState(null),d=r!==void 0?r:c,p=f.useCallback(S=>{s?s(S):l(S)},[s]),[x,g]=f.useState(null),[u,b]=f.useState(!1);f.useEffect(()=>{t&&a(t)},[t]),f.useEffect(()=>{if(t||!n||!i.getBookFullTextIndex)return;let S=!1;return i.getBookFullTextIndex(n).then(m=>{S||a(m)}),()=>{S=!0}},[n,i,t]),f.useEffect(()=>{if(!o||o.chapters.length===0)return;const S=Ne(o.chapters[0].file);if(!d){p(S);return}const m=Ne(d);o.chapters.some(w=>Ne(w.file)===m)||p(S)},[o,d,p]);const y=f.useMemo(()=>{if(!o||!d)return null;const S=Ne(d);return o.chapters.find(m=>Ne(m.file)===S)??null},[o,d]);if(f.useEffect(()=>{if(!n||!y||!i.getBookFullTextChapter)return;let S=!1;return b(!0),g(null),i.getBookFullTextChapter(n,y.file).then(m=>{S||g(m)}).catch(()=>{S||g(null)}).finally(()=>{S||b(!1)}),()=>{S=!0}},[n,y,i]),!o)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"加载全文目录…"});if(o.chapters.length===0)return e.jsx("div",{style:{padding:24,color:"var(--bim-desc-fg, #999)"},children:"全文目录为空"});const h=e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{padding:"0 8px 8px",fontSize:12.5,color:"var(--bim-desc-fg, #888)",borderBottom:"1px solid var(--bim-border, #e5e5e5)",marginBottom:8},children:o.version_label}),e.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.chapters.map(S=>{const m=Ne(S.file),j=m===Ne(d??"");return e.jsx("li",{children:e.jsx("button",{onClick:()=>p(m),style:{display:"block",width:"100%",textAlign:"left",padding:"6px 12px",background:j?"var(--bim-primary-bg, #fdf4f4)":"transparent",border:"none",borderLeft:j?"3px solid var(--bim-primary, #8B0000)":"3px solid transparent",color:j?"var(--bim-primary, #8B0000)":"var(--bim-fg, #2c2c2c)",cursor:"pointer",fontSize:14,lineHeight:1.5},children:S.title})},S.file)})})]});return e.jsx(br,{aside:h,children:e.jsxs("div",{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:o.source.url,target:"_blank",rel:"noreferrer",style:{color:"var(--bim-primary, #8B0000)"},children:o.source.name}),o.source.license&&e.jsxs(e.Fragment,{children:[" · ",o.source.license]})]})]}),u&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"加载中…"}),!u&&x&&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:x.replace(/^##\s+[^\n]+\n+/,"")}),!u&&!x&&e.jsx("div",{style:{color:"var(--bim-desc-fg, #999)"},children:"无法加载章节内容"})]})})},El=({data:t,onNavigate:n,className:i,style:r})=>{var p;const s=D(),{convert:o}=P(),[a,c]=f.useState(((p=t.divisions[0])==null?void 0:p.name)??null),[l,d]=f.useState(null);return e.jsxs("div",{className:i,style:r,children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h2",{style:{fontSize:"18px",fontWeight:600,color:"var(--bim-fg, #1a1a1a)",margin:"0 0 8px"},children:o(t.title)}),t.stats&&e.jsxs("div",{style:{fontSize:"13px",color:"var(--bim-desc-fg, #717171)",display:"flex",gap:"16px"},children:[t.total_volumes!=null&&e.jsxs("span",{children:[s.catalog.totalVolumes," ",e.jsx("strong",{children:t.total_volumes})," ",s.unit.juan]}),t.stats.zhulu!=null&&e.jsxs("span",{children:["著錄 ",e.jsx("strong",{children:t.stats.zhulu})," ",s.unit.bu]}),t.stats.cunmu!=null&&e.jsxs("span",{children:["存目 ",e.jsx("strong",{children:t.stats.cunmu})," ",s.unit.bu]}),t.stats.categories!=null&&e.jsxs("span",{children:[t.stats.categories," 類"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.divisions.map(x=>e.jsx(Bl,{division:x,expanded:a===x.name,onToggle:()=>c(a===x.name?null:x.name),expandedCat:l,onCatToggle:g=>d(l===g?null:g),onNavigate:n},x.name))})]})},Bl=({division:t,expanded:n,onToggle:i,expandedCat:r,onCatToggle:s,onNavigate:o})=>{const{convert:a}=P(),c=t.categories.reduce((l,d)=>{const p=d.stats||{zhulu:0,cunmu:0};return l+(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:a(t.name)}),e.jsxs("span",{style:{fontSize:"12px",fontWeight:400,color:"var(--bim-desc-fg, #717171)"},children:[t.categories.length," 類 · ",c," 部",e.jsx("span",{style:{marginLeft:"8px"},children:n?"▲":"▼"})]})]}),n&&e.jsx("div",{style:{padding:"4px 0"},children:t.categories.map(l=>{const d=`${t.name}/${l.name}`;return e.jsx(Ll,{category:l,expanded:r===d,onToggle:()=>s(d),onNavigate:o},l.name)})})]})},Ll=({category:t,expanded:n,onToggle:i,onNavigate:r})=>{var l,d,p,x;const{convert:s}=P(),o=((l=t.books)==null?void 0:l.zhulu)||[],a=((d=t.books)==null?void 0:d.cunmu)||[],c=(((p=t.stats)==null?void 0:p.zhulu)||o.length)+(((x=t.stats)==null?void 0:x.cunmu)||a.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&&(o.length>0||a.length>0)&&e.jsxs("div",{style:{padding:"4px 14px 8px 42px"},children:[o.length>0&&e.jsx(hi,{label:"著錄",books:o,onNavigate:r}),a.length>0&&e.jsx(hi,{label:"存目",books:a,onNavigate:r})]})]})},hi=({label:t,books:n,onNavigate:i})=>{const{convert:r}=P(),s=be(),[o,a]=f.useState(n.length<=20),c=o?n:n.slice(0,10);return e.jsxs("div",{style:{marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)",marginBottom:"4px",fontWeight:500},children:[t," (",n.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:c.map((l,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"8px",fontSize:"13px",lineHeight:1.6},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--bim-fg, #333)"},children:l.work_id&&i?e.jsx("a",{href:s(l.work_id),onClick:p=>{p.metaKey||p.ctrlKey||(p.preventDefault(),i(l.work_id))},style:{color:"inherit",textDecoration:"none",borderBottom:"1px dashed var(--bim-link-fg, #0066cc)"},children:r(l.title)}):r(l.title)}),l.volumes&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #999)"},children:r(l.volumes)}),l.author&&e.jsx("span",{style:{fontSize:"11px",color:"var(--bim-desc-fg, #aaa)"},children:r(l.author).slice(0,20)})]},d))}),!o&&e.jsxs("button",{onClick:()=>a(!0),style:{marginTop:"4px",padding:"2px 12px",fontSize:"11px",color:"var(--bim-primary, #0078d4)",background:"transparent",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",cursor:"pointer"},children:["展開全部 ",n.length," 條"]})]})},ke=({title:t,onSave:n,onAskAI:i,extraButtons:r,children:s})=>{const o=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"12px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:600,color:"var(--bim-fg, #333)"},children:t}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[r,i&&e.jsx("button",{onClick:i,style:$l,children:"AI"}),n&&e.jsx("button",{onClick:n,style:Wl,children:o.action.save})]})]}),s]})},Wl={padding:"4px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},$l={padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},he=({label:t,value:n,onChange:i,placeholder:r,disabled:s})=>e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:{display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},children:t}),e.jsx("input",{type:"text",value:n,onChange:o=>i(o.target.value),placeholder:r,disabled:s,style:{width:"100%",padding:"6px 8px",background:"var(--bim-input-bg, #fff)",color:"var(--bim-input-fg, #333)",border:"1px solid var(--bim-input-border, #ccc)",borderRadius:"2px",fontSize:"13px",boxSizing:"border-box",outline:"none"}})]}),Ye=({value:t,onChange:n,placeholder:i})=>{const r=f.useRef(null);return f.useEffect(()=>{r.current&&(r.current.style.height="auto",r.current.style.height=`${r.current.scrollHeight}px`)},[t]),e.jsx("textarea",{ref:r,value:t||"",onChange:s=>n(s.target.value),placeholder: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"}})},Dt=({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 Al(t){const n=t.match(/^\[(.+?)\]\(bid:(.+?)\)$/);return n?{name:n[1],id:n[2]}:null}const Ft=({value:t,onChange:n,label:i})=>{const[r,s]=f.useState(!1),o=f.useRef(null),a=Al(t||"");return f.useEffect(()=>{r&&o.current&&o.current.focus()},[r]),!r&&a?e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,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:a.name}),e.jsx(Dt,{children:a.id})]})]}):e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("label",{style:bi,children:i}),e.jsx("input",{ref:o,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"}})]})},bi={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500};function Fl(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 Ml(t){switch(t){case"url":return"URL";case"bookID":return"Book ID";default:return"未选择"}}const Fr=({items:t,onChange:n,onOpenEntityPicker:i})=>{const r=D(),[s,o]=f.useState(null),a=()=>{n([...t,{id:"",name:"",type:"",details:"",position:"",version:"",processor_version:""}]),o(t.length)},c=x=>{n(t.filter((g,u)=>u!==x)),s===x&&o(null)},l=(x,g,u)=>{const b=[...t];b[x]={...b[x],[g]:u},n(b)},d=(x,g)=>{const u=[...t];u[x]={...u[x],type:g,id:"",name:""},n(u),g==="bookID"&&i&&i(b=>{const y=[...t];y[x]={...y[x],id:b.id,name:b.title,type:"bookID"},n(y)})},p=x=>{i&&i(g=>{const u=[...t];u[x]={...u[x],id:g.id,name:g.title,type:"bookID"},n(u)})};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((x,g)=>e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"var(--bim-input-bg, #fff)",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"8px 12px",cursor:"pointer",gap:"8px"},onClick:()=>o(s===g?null:g),children:[e.jsx("span",{style:{opacity:.6,fontSize:"12px"},children:s===g?"▼":"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500,color:"var(--bim-fg, #333)"},children:x.name||`${r.editor.sourcePlaceholder} ${g+1}`}),x.type&&e.jsx("span",{style:{fontSize:"11px",padding:"2px 8px",background:Fl(x.type),color:"white",borderRadius:"3px",fontWeight:500},children:Ml(x.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:r.editor.deleteThisSource,children:"✕"})]}),s===g&&e.jsx("div",{style:{padding:"12px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[!x.type&&e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.editor.selectSourceType}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsxs("button",{onClick:()=>d(g,"bookID"),style:{...yi,borderColor:"var(--bim-source-bookid, #4caf50)",color:"var(--bim-source-bookid, #4caf50)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"📚"}),e.jsx("span",{children:"Book ID"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.fromExistingBook})]}),e.jsxs("button",{onClick:()=>d(g,"url"),style:{...yi,borderColor:"var(--bim-source-url, #2196f3)",color:"var(--bim-source-url, #2196f3)"},children:[e.jsx("span",{style:{fontSize:"18px"},children:"🔗"}),e.jsx("span",{children:"URL"}),e.jsx("span",{style:{fontSize:"11px",opacity:.7},children:r.editor.enterUrl})]})]})]}),x.type==="bookID"&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.action.selectBookOrWork}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),x.id&&x.name?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",background:"var(--bim-bg, #fff)",border:"1px solid 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:x.name}),e.jsx("code",{style:{fontSize:"11px",background:"var(--bim-primary-soft, rgba(0,120,212,0.15))",padding:"2px 6px",borderRadius:"3px"},children:x.id})]}),e.jsx("button",{onClick:()=>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:r.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:r.action.clickToSelectBookOrWork})]})]})}),x.type==="url"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("label",{style:$e,children:r.label.sourceName}),e.jsx("button",{onClick:()=>{const u=[...t];u[g]={...u[g],type:"",id:"",name:""},n(u)},style:vi,children:r.action.changeType})]}),e.jsx("input",{type:"text",value:x.name,onChange:u=>l(g,"name",u.target.value),placeholder:r.editor.sourceNamePlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.urlAddress}),e.jsx("input",{type:"text",value:x.id,onChange:u=>l(g,"id",u.target.value),placeholder:"https://...",style:et})]})]}),x.type&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{borderTop:"1px dashed var(--bim-widget-border, #e0e0e0)",paddingTop:"12px",marginTop:"4px"},children:e.jsx("label",{style:{...$e,opacity:.7},children:r.label.optionalInfo})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.detailsOptional}),e.jsx("input",{type:"text",value:x.details,onChange:u=>l(g,"details",u.target.value),placeholder:r.editor.detailsPlaceholder,style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.positionOptional}),e.jsx("input",{type:"text",value:x.position,onChange:u=>l(g,"position",u.target.value),placeholder:"如: 卷三, p.52",style:et})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.dataVersionOptional}),e.jsx("input",{type:"text",value:x.version,onChange:u=>l(g,"version",u.target.value),placeholder:"如: v1.0, 2024-01",style:et})]}),e.jsxs("div",{children:[e.jsx("label",{style:$e,children:r.label.processorVersionOptional}),e.jsx("input",{type:"text",value:x.processor_version,onChange:u=>l(g,"processor_version",u.target.value),placeholder:"如: v0.1",style:et})]})]})]})]})})]},g)),e.jsxs("button",{onClick:a,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"8px 16px",border:"1px dashed var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer",fontSize:"13px",opacity:.8},children:[e.jsx("span",{children:"+"}),e.jsx("span",{children:r.action.addSource})]})]})},$e={display:"block",fontSize:"11px",color:"var(--bim-desc-fg, #717171)",marginBottom:"4px",fontWeight:500},et={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"},yi={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"},vi={background:"transparent",border:"none",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer",fontSize:"11px",padding:0};function Mr(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 Pr(t){return!t||t.length===0?"":JSON.stringify(t)}const Hr=({entityType:t,entityId:n,entityTitle:i,parentWork:r,parentCollection:s,belongsToWork:o,belongsToCollection:a,childWorks:c,childCollections:l,containedBooks:d,siblingBooks:p,onLinkEntity:x,onUnlinkEntity:g,onViewEntity:u,onCreateAndLink:b,onSaveRelations:y})=>{const h=D();return e.jsxs("div",{style:{background:"var(--bim-bg, #fff)",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",padding:"16px",marginBottom:"12px"},children:[e.jsxs("div",{style:{fontSize:"14px",fontWeight:600,marginBottom:"16px",paddingBottom:"8px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:h.section.relations})]}),y&&e.jsx("button",{onClick:y,style:Pl,children:h.action.save})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[t==="book"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:h.relation.belongsToWork,entity:o,onView:u,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ft,{direction:"up",title:h.relation.containedInCollection,entity:a,onView:u,onUnlink:()=>g("collectionId"),onLink:()=>x("collectionId","collection"),onCreate:()=>b("collectionId","collection",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),o&&p&&p.length>0&&e.jsx(tt,{direction:"horizontal",title:`${h.relation.siblingVersions} (${p.length})`,entities:p,onView:u,onAdd:()=>b("siblingBook","book",{workId:o.id}),addLabel:h.relation.addVersionForWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="work"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:h.relation.parentWork,entity:r,onView:u,onUnlink:()=>g("parentWorkId"),onLink:()=>x("parentWorkId","work"),onCreate:()=>b("parentWorkId","work"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),c&&c.length>0&&e.jsx(tt,{direction:"down",title:`${h.relation.childWorks} (${c.length})`,entities:c,onView:u,onAdd:()=>b("childWork","work",{parentWorkId:n}),addLabel:h.action.addSubWork,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),l&&l.length>0&&e.jsx(tt,{direction:"down",title:`${h.relation.collectionImpl} (${l.length})`,entities:l,onView:u,onAdd:()=>b("childCollection","collection",{workId:n}),addLabel:h.action.addCollectionImpl,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(tt,{direction:"down",title:`${h.relation.allVersions} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>b("childBook","book",{workId:n}),addLabel:h.action.addVersion,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]}),t==="collection"&&e.jsxs(e.Fragment,{children:[e.jsx(ft,{direction:"up",title:h.relation.correspondingWork,entity:o,onView:u,onUnlink:()=>g("workId"),onLink:()=>x("workId","work"),onCreate:()=>b("workId","work",{title:i}),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(ft,{direction:"up",title:h.relation.parentCollection,entity:s,onView:u,onUnlink:()=>g("parentCollectionId"),onLink:()=>x("parentCollectionId","collection"),onCreate:()=>b("parentCollectionId","collection"),linkLabel:h.action.linkExisting,createLabel:h.action.createAndLink,notLinkedLabel:h.relation.notLinked,viewLabel:h.action.viewEntity,unlinkLabel:h.action.unlink}),e.jsx(tt,{direction:"down",title:`${h.relation.childCollections} (${(l==null?void 0:l.length)??0})`,entities:l||[],onView:u,onAdd:()=>b("childCollection","collection",{parentCollectionId:n}),addLabel:h.action.addSubCollection,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore}),e.jsx(tt,{direction:"down",title:`${h.relation.containedBooks} (${(d==null?void 0:d.length)??0})`,entities:d||[],onView:u,onAdd:()=>b("childBook","book",{collectionId:n}),addLabel:h.action.addBook,noneLabel:h.relation.none,expandMoreLabel:h.action.expandMore})]})]})]})},ft=({direction:t,title:n,entity:i,onView:r,onUnlink:s,onLink:o,onCreate:a,linkLabel:c,createLabel:l,notLinkedLabel:d,viewLabel:p,unlinkLabel:x})=>{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:Or(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(ji,{onClick:()=>r(i),title:p,children:"👁️"}),e.jsx(ji,{onClick:s,title:x,danger:!0,children:"✕"})]})]}):e.jsx("div",{style:{padding:"8px",background:"var(--bim-bg, #fff)",borderRadius:"4px",color:"var(--bim-desc-fg, #717171)",fontSize:"12px",textAlign:"center"},children:d}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"8px"},children:[e.jsx(bn,{onClick:o,children:c}),e.jsx(bn,{onClick:a,primary:!0,children:l})]})]})},tt=({direction:t,title:n,entities:i,onView:r,onAdd:s,addLabel:o,noneLabel:a,expandMoreLabel:c})=>{const[l,d]=f.useState(!1),p=t==="up"?"var(--bim-relation-up, #2196f3)":t==="down"?"var(--bim-relation-down, #4caf50)":"var(--bim-relation-flat, #ff9800)",x=t==="up"?"⬆️":t==="down"?"⬇️":"↔️",g=l?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:x}),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:()=>r(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:Or(u.type)}),e.jsx("span",{children:u.title})]},u.id)),i.length>5&&!l&&e.jsxs("div",{onClick:()=>d(!0),style:{padding:"4px 8px",textAlign:"center",fontSize:"12px",color:"var(--bim-link-fg, #0066cc)",cursor:"pointer"},children:[c," (",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:a}),e.jsx("div",{style:{marginTop:"8px"},children:e.jsxs(bn,{onClick:s,primary:!0,children:["+ ",o]})})]})},ji=({onClick:t,title:n,danger:i,children:r})=>e.jsx("button",{onClick:s=>{s.stopPropagation(),t()},title:n,style:{background:"transparent",border:"none",cursor:"pointer",padding:"2px 6px",fontSize:"12px",color:i?"var(--bim-danger, #f44336)":"inherit",opacity:.7},children:r}),bn=({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 Or(t){switch(t){case"work":return"📜";case"book":return"📖";case"collection":return"📚"}}const Pl={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"},Dr=({isOpen:t,entityType:n,title:i,onSelect:r,onCancel:s,onCreate:o,searchResults:a,onSearch:c,isLoading:l,excludeId:d})=>{const[p,x]=f.useState(""),g=d?a.filter(h=>h.id!==d):a;f.useEffect(()=>{t&&(x(""),c(""))},[t]);const u=h=>{x(h),c(h)};if(!t)return null;const b=n==="work"?"作品":n==="book"?"书籍":"丛编",y=n==="work"?"📜":n==="book"?"📖":"📚";return e.jsx("div",{style:Hl,children:e.jsxs("div",{style:Ol,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:Dl,children:"✕"})]}),e.jsx("div",{style:{padding:"12px 16px"},children:e.jsx("input",{type:"text",value:p,onChange:h=>u(h.target.value),placeholder:`搜索${b}名称或 ID...`,autoFocus:!0,style:Nl})}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"0 16px"},children:l?e.jsx("div",{style:sn,children:"搜索中..."}):g.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:g.map(h=>e.jsxs("div",{onClick:()=>r(h),style:Vl,children:[e.jsx("span",{style:{fontSize:"16px"},children:y}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{fontWeight:500},children:[h.title,h.edition&&e.jsx("span",{style:{fontSize:"11px",fontWeight:400,opacity:.6,marginLeft:"4px"},children:h.edition})]}),e.jsxs("div",{style:{fontSize:"11px",opacity:.7},children:[h.id,h.author&&` · ${h.author}`,h.dynasty&&` · ${h.dynasty}`]})]})]},h.id))}):p?e.jsxs("div",{style:sn,children:["未找到匹配的",b]}):e.jsxs("div",{style:sn,children:["输入关键词搜索",b]})}),e.jsxs("div",{style:{padding:"12px 16px",borderTop:"1px solid var(--bim-widget-border, #e0e0e0)",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"12px",opacity:.7},children:"找不到?"}),e.jsxs("button",{onClick:o,style:Gl,children:["创建新",b,"并关联"]})]})]})})},Hl={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},Ol={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)"},Dl={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"},Vl={display:"flex",alignItems:"center",gap:"10px",padding:"10px 12px",borderRadius:"4px",cursor:"pointer",background:"var(--bim-primary-soft, rgba(0,120,212,0.05))"},sn={padding:"20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)"},Gl={padding:"6px 12px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},Si={work:"作品",book:"书籍",collection:"丛编",entity:"人物"},Ul={work:"📜",book:"📖",collection:"📚",entity:"👤"},Nr=({isOpen:t,entityType:n,relationField:i,inheritData:r,onConfirm:s,onCancel:o})=>{const[a,c]=f.useState(""),l=f.useRef(null);f.useEffect(()=>{t&&(c((r==null?void 0:r.title)||""),setTimeout(()=>{var g,u;(g=l.current)==null||g.focus(),(u=l.current)==null||u.select()},100))},[t,r==null?void 0:r.title]);const d=g=>{g.key==="Enter"&&a.trim()?p():g.key==="Escape"&&o()},p=()=>{a.trim()&&s(a.trim(),{...r,title:a.trim()})};if(!t)return null;const x=()=>{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`创建新${Si[n]}`}};return e.jsx("div",{style:Yl,onClick:g=>{g.target===g.currentTarget&&o()},children:e.jsxs("div",{style:Kl,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:Ul[n]}),e.jsx("span",{children:x()})]}),e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsxs("label",{style:{display:"block",fontSize:"13px",marginBottom:"6px",color:"var(--bim-fg, #333)"},children:[n==="work"?"作品名":n==="collection"?"丛编名":"书名",e.jsx("span",{style:{color:"var(--bim-danger, #f44336)",marginLeft:"4px"},children:"*"})]}),e.jsx("input",{ref:l,type:"text",value:a,onChange:g=>c(g.target.value),onKeyDown:d,placeholder:`请输入${Si[n]}名称...`,style:Jl})]}),((r==null?void 0:r.author)||(r==null?void 0:r.dynasty))&&e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #717171)",background:"var(--bim-input-bg, #fff)",padding:"8px 12px",borderRadius:"4px",marginBottom:"16px"},children:[e.jsx("div",{style:{marginBottom:"4px",fontWeight:500},children:"将继承以下信息:"}),(r==null?void 0:r.author)&&e.jsxs("div",{children:["作者: ",r.author]}),(r==null?void 0:r.dynasty)&&e.jsxs("div",{children:["朝代/年份: ",r.dynasty]})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px"},children:[e.jsx("button",{onClick:o,style:ql,children:"取消"}),e.jsx("button",{onClick:p,disabled:!a.trim(),style:{...Xl,opacity:a.trim()?1:.6,cursor:a.trim()?"pointer":"not-allowed"},children:"创建"})]})]})})},Yl={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},Kl={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)"},Jl={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"},ql={padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"4px",background:"transparent",color:"var(--bim-fg, #333)",cursor:"pointer"},Xl={padding:"8px 16px",fontSize:"13px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)"};function Zl(t){switch(t){case"work":return"📜";case"collection":return"📚";case"book":return"📖";default:return"📄"}}function Vr(t){switch(t){case"work":return"作品";case"collection":return"丛编";case"book":return"书籍";default:return"实体"}}function Ql(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 Gr=({isOpen:t,title:n,filterType:i="all",recentEntities:r=[],excludeId:s,showCreateButton:o=!1,createButtonText:a,onSelect:c,onCancel:l,onCreate:d,onSearch:p})=>{const[x,g]=f.useState(""),[u,b]=f.useState([]),[y,h]=f.useState(!1),[S,m]=f.useState("recent");f.useEffect(()=>{t&&(g(""),b([]),m(r.length>0?"recent":"search"))},[t,r.length]),f.useEffect(()=>{if(!x.trim()){b([]);return}const _=setTimeout(async()=>{h(!0);try{b(await p(x,i))}catch{b([])}finally{h(!1)}},300);return()=>clearTimeout(_)},[x,i,p]);const j=f.useCallback(_=>{g(_.target.value),_.target.value.trim()&&m("search")},[]),w=f.useCallback(_=>s?_.filter(z=>z.id!==s):_,[s]);if(!t)return null;const k=n||(i==="all"?"选择实体":`选择${Vr(i)}`),C=w(r),T=w(u);return e.jsx("div",{style:ta,children:e.jsxs("div",{style:na,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:l,style:ia,children:"✕"})]}),e.jsx("div",{style:{padding:"16px 20px 12px"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",value:x,onChange:j,placeholder:"输入名称或 ID 搜索...",autoFocus:!0,style:ra}),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:"搜索中..."})]})}),C.length>0&&e.jsxs("div",{style:{display:"flex",padding:"0 20px",gap:"4px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)"},children:[e.jsxs(ki,{active:S==="recent",onClick:()=>m("recent"),children:["最近使用 (",C.length,")"]}),e.jsxs(ki,{active:S==="search",onClick:()=>m("search"),children:["搜索结果 ",T.length>0&&`(${T.length})`]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"12px 20px",minHeight:"200px",maxHeight:"400px"},children:S==="recent"&&C.length>0?e.jsx(wi,{entities:C,onSelect:c}):x.trim()?y?e.jsx(ln,{message:"搜索中..."}):T.length>0?e.jsx(wi,{entities:T,onSelect:c}):e.jsx(ln,{message:"未找到匹配的结果"}):e.jsx(ln,{message:"输入关键词开始搜索"})}),o&&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:oa,children:a||"创建新实体"})]})]})})},ki=({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}),wi=({entities:t,onSelect:n})=>e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:t.map(i=>e.jsx(ea,{entity:i,onClick:()=>n(i)},i.id))}),ea=({entity:t,onClick:n})=>{const[i,r]=f.useState(!1);return e.jsxs("div",{onClick:n,onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),style:{display:"flex",alignItems:"center",gap:"12px",padding:"10px 14px",borderRadius:"6px",cursor:"pointer",background: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:Zl(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:Ql(t.type),color:"white",borderRadius:"4px",fontWeight:500,flexShrink:0},children:Vr(t.type)})]})},ln=({message:t})=>e.jsx("div",{style:{padding:"40px 20px",textAlign:"center",color:"var(--bim-desc-fg, #717171)",fontSize:"13px"},children:t}),ta={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},na={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)"},ia={background:"transparent",border:"none",fontSize:"18px",cursor:"pointer",opacity:.7,color:"inherit",padding:"4px 8px"},ra={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"},oa={padding:"6px 14px",fontSize:"12px",border:"none",borderRadius:"4px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",cursor:"pointer"},sa={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)"},la={work:"📜",collection:"📚",book:"📖",entity:"👤"},Ur=({data:t,onChange:n,onSave:i,transport:r,onNavigate:s,showDelete:o,onDelete:a,onAskAI:c,renderSectionActions:l,onDownloadResource:d,downloadStatuses:p,relations:x,onRelationsChange:g})=>{var ne;const u=D(),[b,y]=f.useState(!1),[h,S]=f.useState("work"),[m,j]=f.useState(""),[w,k]=f.useState(""),[C,T]=f.useState([]),[_,z]=f.useState(!1),[I,v]=f.useState(!1),[R,E]=f.useState("work"),[M,$]=f.useState(""),[O,A]=f.useState(),[F,J]=f.useState(!1),[W,U]=f.useState(null),[ie,K]=f.useState([]);f.useRef(null);const L=t.type,Y=L==="work",q=L==="collection",V=L==="book",G=f.useCallback((B,ee)=>{n({...t,[B]:ee})},[t,n]),de=f.useCallback((B,ee)=>{j(B),S(ee),k(u.editor.selectToLink+u.indexType[ee]),T([]),y(!0)},[u]),Se=f.useCallback(B=>{r!=null&&r.unlinkEntity&&r.unlinkEntity(t.id,B)},[r,t.id]),me=f.useCallback(B=>{s==null||s(B.id,B.type)},[s]),se=f.useCallback((B,ee,le)=>{const X={...le,author:(le==null?void 0:le.author)||t.author,dynasty:le==null?void 0:le.dynasty};E(ee),$(B),A(X),v(!0)},[t.author]),ye=f.useCallback((B,ee)=>{r!=null&&r.createAndLink&&r.createAndLink(t.id,M,{type:R,title:B,inheritData:ee}),v(!1)},[r,t.id,M,R]),Ie=f.useCallback(B=>{if(!B.trim()){T([]);return}z(!0),r!=null&&r.searchEntities&&r.searchEntities(B,h).then(ee=>{T(ee),z(!1)}).catch(()=>{T([]),z(!1)})},[r,h]),Te=f.useCallback(B=>{r!=null&&r.linkEntity&&r.linkEntity(t.id,m,B.id),y(!1)},[r,t.id,m]),Ze=f.useCallback(()=>{i()},[i]),ct=f.useCallback(B=>{U(()=>B),J(!0),r!=null&&r.getRecentEntities&&r.getRecentEntities().then(K).catch(()=>{})},[r]),N=f.useCallback((B,ee)=>r!=null&&r.searchEntities?r.searchEntities(B,ee==="all"?void 0:ee):Promise.resolve([]),[r]),oe=f.useCallback(B=>{r!=null&&r.addRecentEntity&&r.addRecentEntity(B),K(ee=>[B,...ee.filter(le=>le.id!==B.id)].slice(0,10)),W==null||W(B),J(!1),U(null)},[r,W]);return e.jsxs("div",{style:{padding:"16px",maxWidth:"900px",margin:"0 auto"},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"24px",borderBottom:"1px solid var(--bim-widget-border, #e0e0e0)",paddingBottom:"16px"},children:e.jsxs("h1",{style:{fontSize:"20px",fontWeight:600,margin:0,display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{children:la[L]}),e.jsx("span",{children:t.title||u.editor.untitled}),e.jsx(Dt,{children:t.id}),e.jsx(Dt,{color:sa[L],children:u.indexType[L]})]})}),e.jsx(ke,{title:u.section.basicInfo,onSave:i,onAskAI:c?()=>c("基本信息"):void 0,extraButtons:l==null?void 0:l("基本信息"),children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"12px"},children:[e.jsx(Ft,{label:Y?u.editor.workTitle:q?u.editor.collectionTitle:u.editor.bookTitle,value:t.title,onChange:B=>G("title",B)}),V&&e.jsx(Ft,{label:u.editor.belongsToWork,value:t.workName||"",onChange:B=>G("workName",B)}),e.jsx(he,{label:u.editor.authorLabel,value:t.author||"",onChange:B=>G("author",B)}),e.jsx(he,{label:u.editor.publicationYearLabel,value:t.publicationYear||"",onChange:B=>G("publicationYear",B)}),(V||q)&&e.jsx(Ft,{label:u.editor.containedIn,value:t.collection||"",onChange:B=>G("collection",B)}),(V||q)&&e.jsx(he,{label:u.editor.holderLabel,value:t.holder||"",onChange:B=>G("holder",B)}),(V||q)&&e.jsx(he,{label:V?u.editor.pageLabel:u.editor.volumeLabel,value:t.pages||"",onChange:B=>G("pages",B)}),e.jsx("div",{style:{gridColumn:"1 / -1"},children:e.jsx(he,{label:u.editor.firstImageLabel,value:t.firstImage||"",onChange:B=>G("firstImage",B)})})]})}),e.jsx(ke,{title:u.section.description,onSave:i,onAskAI:c?()=>c("介绍"):void 0,children:e.jsx(Ye,{value:t.description||"",onChange:B=>G("description",B),placeholder:u.editor.descriptionPlaceholder})}),(((ne=t.additional_works)==null?void 0:ne.length)||0)>0&&e.jsx(ke,{title:u.section.additionalWorks,onSave:i,children:e.jsx(aa,{items:t.additional_works||[],onChange:B=>G("additional_works",B)})}),e.jsx(ke,{title:u.section.indexedBy,onSave:i,onAskAI:c?()=>c("收录于"):void 0,children:e.jsx(ca,{items:t.indexed_by||[],onChange:B=>G("indexed_by",B)})}),e.jsx(ke,{title:u.section.emendatedBy,onSave:i,onAskAI:c?()=>c("考证"):void 0,children:e.jsx(da,{items:t.emendated_by||[],onChange:B=>G("emendated_by",B)})}),e.jsx(ke,{title:u.section.textResources,onSave:i,onAskAI:c?()=>c("资源"):void 0,children:e.jsx(dn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"text"})}),e.jsx(ke,{title:u.section.imageResources,onSave:i,children:e.jsx(dn,{items:t.resources||[],onChange:B=>G("resources",B),onDownload:d,downloadStatuses:p,filterType:"image"})}),e.jsx(ke,{title:u.section.sources,onSave:i,onAskAI:c?()=>c("资料来源"):void 0,children:e.jsx(Fr,{items:Mr(t.sources||""),onChange:B=>G("sources",Pr(B)),onOpenEntityPicker:ct})}),(V||q)&&e.jsx(ke,{title:u.section.provenance,onSave:i,onAskAI:c?()=>c("收藏历史"):void 0,children:e.jsx(Ye,{value:t.provenance||"",onChange:B=>G("provenance",B),placeholder:u.editor.provenancePlaceholder})}),V&&e.jsx(ke,{title:u.section.otherEditions,onSave:i,onAskAI:c?()=>c("其他版本"):void 0,children:e.jsx(Ye,{value:t.otherEditions||"",onChange:B=>G("otherEditions",B),placeholder:u.editor.otherEditionsPlaceholder})}),e.jsx(Hr,{entityType:L,entityId:t.id,entityTitle:t.title,parentWork:x==null?void 0:x.parentWork,parentCollection:x==null?void 0:x.parentCollection,belongsToWork:x==null?void 0:x.belongsToWork,belongsToCollection:x==null?void 0:x.belongsToCollection,childWorks:x==null?void 0:x.childWorks,childCollections:x==null?void 0:x.childCollections,containedBooks:x==null?void 0:x.containedBooks,siblingBooks:x==null?void 0:x.siblingBooks,onLinkEntity:de,onUnlinkEntity:Se,onViewEntity:me,onCreateAndLink:se,onSaveRelations:Ze}),o&&a&&e.jsxs("div",{style:{marginTop:"40px",padding:"16px",border:"1px solid rgba(244,67,54,0.13)",background:"rgba(244,67,54,0.03)",borderRadius:"4px"},children:[e.jsx("div",{style:{color:"var(--bim-danger, #f44336)",fontWeight:600,marginBottom:"8px"},children: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:a,style:{padding:"8px 16px",fontSize:"13px",border:"1px solid var(--bim-danger, #f44336)",borderRadius:"4px",background:"transparent",color:"var(--bim-danger, #f44336)",cursor:"pointer"},children:u.editor.deleteEntity})]}),e.jsx(Dr,{isOpen:b,entityType:h,title:w,onSelect:Te,onCancel:()=>y(!1),onCreate:()=>{y(!1),se(m,h)},searchResults:C,onSearch:Ie,isLoading:_,excludeId:t.id}),e.jsx(Nr,{isOpen:I,entityType:R,relationField:M,inheritData:O,onConfirm:ye,onCancel:()=>v(!1)}),e.jsx(Gr,{isOpen:F,title:u.action.selectBookOrWork,filterType:"all",recentEntities:ie,excludeId:t.id,onSelect:oe,onCancel:()=>{J(!1),U(null)},onSearch:N})]})};function aa({items:t,onChange:n}){const i=D(),r=(a,c,l)=>{const d=t.map((p,x)=>x===a?{...p,[c]:l}:p);n(d)},s=a=>n(t.filter((c,l)=>l!==a)),o=()=>n([...t,{book_title:""}]);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((a,c)=>e.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[e.jsx(he,{label:i.editor.bookNameLabel,value:a.book_title,onChange:l=>r(c,"book_title",l)}),e.jsx("div",{style:{width:"100px"},children:e.jsx(he,{label:i.label.juanCount,value:a.n_juan!=null?String(a.n_juan):"",onChange:l=>r(c,"n_juan",l&&parseInt(l,10)||void 0)})}),e.jsx("button",{onClick:()=>s(c),style:{padding:"4px 8px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #ddd)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-muted, #999)",marginTop:"18px"},children:"✕"})]},c)),e.jsx("button",{onClick:o,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 Yr({items:t,onChange:n,showMeta:i,addLabel:r}){const s=D(),[o,a]=f.useState(null),c=(p,x,g)=>{const u=t.map((b,y)=>y===p?{...b,[x]:g||void 0}:b);n(u)},l=p=>{n(t.filter((x,g)=>g!==p)),o===p&&a(null)},d=()=>{n([...t,{source:""}]),a(t.length)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[t.map((p,x)=>{const g=o===x;return e.jsxs("div",{style:{border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",background:g?"color-mix(in srgb, var(--bim-primary, #0078d4) 5%, transparent)":"transparent",cursor:"pointer"},onClick:()=>a(g?null:x),children:[e.jsx("span",{style:{fontSize:"10px",color:"var(--bim-desc-fg, #717171)",transition:"transform 0.2s",transform:g?"rotate(90deg)":"none"},children:"▶"}),e.jsx("span",{style:{flex:1,fontSize:"13px",fontWeight:500},children: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(),l(x)},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(he,{label:s.label.sourceName,value:p.source,onChange:u=>c(x,"source",u)}),e.jsx(he,{label:s.label.sourceBid,value:p.source_bid||"",onChange:u=>c(x,"source_bid",u)})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsx(he,{label:s.label.titleInfo,value:p.title_info||"",onChange:u=>c(x,"title_info",u)}),e.jsx(he,{label:s.label.authorInfo,value:p.author_info||"",onChange:u=>c(x,"author_info",u)})]}),e.jsx(he,{label:s.label.edition,value:p.edition||"",onChange:u=>c(x,"edition",u)})]}),e.jsx(Ye,{value:p.summary||"",onChange:u=>c(x,"summary",u),placeholder:s.editor.summaryPlaceholder}),e.jsx(Ye,{value:p.comment||"",onChange:u=>c(x,"comment",u),placeholder:s.editor.commentPlaceholder}),e.jsx(Ye,{value:p.additional_comment||"",onChange:u=>c(x,"additional_comment",u),placeholder:s.editor.additionalCommentPlaceholder})]})]},x)}),e.jsx("button",{onClick:d,style:{padding:"6px 12px",fontSize:"12px",border:"1px dashed var(--bim-input-border, #ccc)",borderRadius:"4px",background:"transparent",cursor:"pointer",color:"var(--bim-desc-fg, #666)",alignSelf:"flex-start"},children:r})]})}function ca({items:t,onChange:n}){const i=D();return e.jsx(Yr,{items:t,onChange:n,showMeta:!0,addLabel:i.action.addIndexedBy})}function da({items:t,onChange:n}){const i=D();return e.jsx(Yr,{items:t,onChange:n,addLabel:i.action.addEmendatedBy})}function Kr(t){var c,l,d,p,x,g,u;const n=((l=(c=t.authors)==null?void 0:c[0])==null?void 0:l.name)||"",i=((d=t.publication_info)==null?void 0:d.year)||"",r=((p=t.current_location)==null?void 0:p.name)||"",s=(x=t.page_count)!=null&&x.number?String(t.page_count.number):((g=t.page_count)==null?void 0:g.description)||"",o=typeof t.description=="object"&&t.description!==null&&t.description.text||"",a={id:t.id,title:t.title,type:t.type,author:n,publicationYear:i,holder:r,pages:s,description:o,resources:t.resources,additional_works:t.additional_works,indexed_by:t.indexed_by,emendated_by:t.emendated_by};if(t.type==="work"){const b=t;if(Array.isArray(b.related_works)){const y=b.related_works.find(h=>h.relation==="part_of");y&&(a.parentWorkId=y.id,a.parentWorkName=y.title)}}if(t.type==="book"){const b=t;a.workId=b.work_id,Array.isArray(b.contained_in)&&b.contained_in.length>0&&(a.collectionId=(u=b.contained_in[0])==null?void 0:u.id)}return a}function pa(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.publicationYear?{year:t.publicationYear}: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 ua=t=>{const{data:n,id:i,transport:r,mode:s="view",onModeChange:o,onChange:a,onSave:c,onDelete:l,onNavigate:d,renderLink:p,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:b,relations:y,onRelationsChange:h,headerExtra:S,className:m,style:j}=t;D();const[w,k]=f.useState(s),C=o?s:w;f.useEffect(()=>{s!==w&&k(s)},[s]);const T=f.useCallback(()=>{const M=C==="view"?"edit":"view";o?o(M):k(M)},[C,o]),[_,z]=f.useState(null);f.useEffect(()=>{i&&r&&r.getItem(i).then(M=>{M&&z(M)})},[i,r]);const I=n||_,v=f.useMemo(()=>I?Kr(I):null,[I]),R=o||!n?e.jsx("button",{onClick:T,style:{padding:"4px 12px",fontSize:"12px",border:"1px solid var(--bim-widget-border, #d0d0d0)",borderRadius:"4px",background:C==="edit"?"var(--bim-accent-bg, #1976d2)":"transparent",color:C==="edit"?"#fff":"var(--bim-fg, #333)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px"},title:C==="view"?"切换到编辑模式":"切换到查看模式",children:C==="view"?"✏️ 编辑":"👁 查看"}):null,E=e.jsxs(e.Fragment,{children:[R,S]});return!I&&!v?e.jsx(Xe,{}):C==="view"?e.jsx(_n,{data:I,transport:r,onNavigate:d?M=>d(M):void 0,renderLink:p,headerExtra:E,className:m,style:j}):v?e.jsxs("div",{className:m,style:j,children:[E&&e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",padding:"8px 0",gap:"8px"},children:E}),e.jsx(Ur,{data:v,onChange:a||(()=>{}),onSave:c||(()=>{}),transport:r,onNavigate:d,showDelete:!!l,onDelete:l,onAskAI:x,renderSectionActions:g,onDownloadResource:u,downloadStatuses:b,relations:y,onRelationsChange:h})]}):e.jsx("div",{style:{padding:"24px",textAlign:"center",color:"var(--bim-muted, #999)"},children:"无数据"})},_i=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],Jr=({isOpen:t,onClose:n,onSubmit:i,feedbackListUrl:r})=>{const[s,o]=f.useState(null),[a,c]=f.useState(""),[l,d]=f.useState(""),[p,x]=f.useState("idle"),[g,u]=f.useState(""),b=f.useRef(null);f.useEffect(()=>{t&&(o(null),c(""),d(""),x("idle"),u(""))},[t]),f.useEffect(()=>{s&&setTimeout(()=>{var m;return(m=b.current)==null?void 0:m.focus()},100)},[s]),f.useEffect(()=>{if(p==="success"){const m=setTimeout(n,2e3);return()=>clearTimeout(m)}},[p,n]),f.useEffect(()=>{if(!t)return;const m=j=>{j.key==="Escape"&&n()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,n]);const y=async()=>{if(!(!s||!a.trim())){x("submitting"),u("");try{await i({type:s,content:a.trim(),...l.trim()?{contact:l.trim()}:{}}),x("success")}catch(m){x("error"),u(m instanceof Error?m.message:"提交失败,请稍后重试")}}};if(!t)return null;const h=s&&a.trim()&&p!=="submitting",S=_i.find(m=>m.value===s);return e.jsx("div",{style:xa,onClick:m=>{m.target===m.currentTarget&&n()},children:e.jsxs("div",{style:fa,onClick:m=>m.stopPropagation(),children:[e.jsxs("div",{style:ga,children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600},children:"反馈"}),e.jsx("button",{onClick:n,style:ma,"aria-label":"关闭",children:"✕"})]}),p==="success"?e.jsxs("div",{style:ja,children:[e.jsx("span",{style:{fontSize:"32px"},children:"✓"}),e.jsx("div",{style:{fontSize:"15px",fontWeight:500},children:"感谢您的反馈!"}),r&&e.jsx("a",{href:r,style:{fontSize:"13px",color:"var(--bim-primary, #2563eb)",marginTop:"8px"},children:"查看反馈列表 →"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"16px"},children:_i.map(m=>e.jsxs("button",{onClick:()=>o(m.value),style:{...ha,...s===m.value?ba:{}},children:[e.jsx("span",{children:m.icon})," ",m.label]},m.value))}),e.jsx("textarea",{ref:b,value:a,onChange:m=>c(m.target.value),placeholder:(S==null?void 0:S.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:!s||p==="submitting",style:{...ya,opacity:s?1:.6}}),e.jsx("input",{type:"text",value:l,onChange:m=>d(m.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:!s||p==="submitting","aria-label":"联系方式(选填)",style:ka}),e.jsxs("div",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)",textAlign:"right",marginBottom:"12px"},children:[a.length," / 2000"]}),p==="error"&&e.jsx("div",{style:Sa,children:g}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsx("button",{onClick:y,disabled:!h,style:{...va,opacity:h?1:.6,cursor:h?"pointer":"not-allowed"},children:p==="submitting"?"提交中...":"提交反馈"})})]})]})})},xa={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},fa={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)"},ga={display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"16px"},ma={background:"none",border:"none",fontSize:"16px",cursor:"pointer",color:"var(--bim-desc-fg, #999)",padding:"4px 8px",borderRadius:"4px"},ha={flex:"1 1 calc(50% - 4px)",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"},ba={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},ya={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"},va={padding:"8px 24px",fontSize:"14px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},ja={display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",padding:"32px 0",color:"var(--bim-success, #4caf50)"},Sa={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginBottom:"12px"},ka={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",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",fontFamily:"inherit"},wa=({onSubmit:t,position:n={bottom:24,right:24},feedbackListUrl:i})=>{const[r,s]=f.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>s(!0),style:{..._a,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(Jr,{isOpen:r,onClose:()=>s(!1),onSubmit:t,feedbackListUrl:i})]})},_a={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"},Ci=[{value:"bug",label:"反馈错误",icon:"🐛",placeholder:"请描述您发现的错误,包括页面位置和具体内容"},{value:"resource",label:"添加资源",icon:"📚",placeholder:"请提供完整资源链接和简要版本说明"},{value:"suggestion",label:"功能建议",icon:"💡",placeholder:"您希望网站增加或改进什么?"},{value:"contact",label:"想参与",icon:"🤝",placeholder:"想参与整理、校对或合作?简单介绍一下您自己,并留下联系方式(此类留言不公开)"}],qr=({onSubmit:t})=>{const[n,i]=f.useState("bug"),[r,s]=f.useState(""),[o,a]=f.useState(""),[c,l]=f.useState("idle"),[d,p]=f.useState(""),x=f.useRef(null);f.useEffect(()=>{n&&setTimeout(()=>{var y;return(y=x.current)==null?void 0:y.focus()},100)},[n]);const g=async()=>{if(!(!n||!r.trim())){l("submitting"),p("");try{await t({type:n,content:r.trim(),...o.trim()?{contact:o.trim()}:{}}),l("success"),s(""),a(""),i("bug")}catch(y){l("error"),p(y instanceof Error?y.message:"提交失败,请稍后重试")}}},u=n&&r.trim()&&c!=="submitting",b=Ci.find(y=>y.value===n);return c==="success"?e.jsx("div",{style:Ii,children:e.jsxs("div",{style:Ra,children:[e.jsx("span",{children:"✓ 感谢您的反馈!"}),e.jsx("button",{onClick:()=>l("idle"),style:Ea,children:"继续提交"})]})}):e.jsxs("div",{style:Ii,children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px",marginBottom:"12px"},children:Ci.map(y=>e.jsxs("button",{onClick:()=>i(y.value),style:{...Ca,...n===y.value?Ia:{}},children:[e.jsx("span",{children:y.icon})," ",y.label]},y.value))}),e.jsx("textarea",{ref:x,value:r,onChange:y=>s(y.target.value),placeholder:(b==null?void 0:b.placeholder)||"请先选择反馈类型",maxLength:2e3,disabled:c==="submitting",style:{...Ta}}),e.jsx("input",{type:"text",value:o,onChange:y=>a(y.target.value),placeholder:"邮箱(选填,仅站方可见,方便我们回复您)",maxLength:200,disabled:c==="submitting","aria-label":"联系方式(选填)",style:La}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px"},children:[e.jsxs("span",{style:{fontSize:"12px",color:"var(--bim-desc-fg, #999)"},children:[r.length," / 2000"]}),e.jsx("button",{onClick:g,disabled:!u,style:{...za,opacity:u?1:.6,cursor:u?"pointer":"not-allowed"},children:c==="submitting"?"提交中...":"提交"})]}),c==="error"&&e.jsx("div",{style:Ba,children:d})]})},Ii={padding:"16px",border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"8px",background:"var(--bim-input-bg, #fff)"},Ca={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"},Ia={borderColor:"var(--bim-primary, #0078d4)",background:"var(--bim-list-active-bg, #e8f0fe)",color:"var(--bim-primary, #0078d4)",fontWeight:500},Ta={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"},za={padding:"6px 20px",fontSize:"13px",border:"none",borderRadius:"6px",background:"var(--bim-primary, #0078d4)",color:"var(--bim-primary-fg, #fff)",fontWeight:500},Ra={display:"flex",alignItems:"center",gap:"12px",color:"var(--bim-success, #4caf50)",fontSize:"14px"},Ea={background:"none",border:"none",color:"var(--bim-primary, #0078d4)",cursor:"pointer",fontSize:"13px",textDecoration:"underline"},Ba={fontSize:"13px",color:"var(--bim-danger, #f44336)",padding:"8px 12px",background:"rgba(244,67,54,0.08)",borderRadius:"4px",marginTop:"8px"},La={width:"100%",marginTop:"8px",padding:"8px 12px",fontSize:"13px",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",fontFamily:"inherit"};function Ti(t){return typeof t=="function"?t():t??"/api/feedback"}const Xr=({resourceId:t,apiUrl:n})=>{const[i,r]=f.useState([]),[s,o]=f.useState(!0),a=f.useCallback(async()=>{const l=Ti(n);o(!0);try{const p=await(await fetch(`${l}?resourceId=${encodeURIComponent(t)}`)).json();p.success&&r(p.items)}catch{}finally{o(!1)}},[t,n]);f.useEffect(()=>{a()},[a]);const c=async l=>{const d=Ti(n),p=await fetch(d,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...l,pageUrl:typeof window<"u"?window.location.href:"",resourceId:t})});if(!p.ok){const x=await p.json().catch(()=>null);throw new Error((x==null?void 0:x.error)||"提交失败")}setTimeout(()=>a(),500)};return e.jsxs("div",{children:[e.jsx(Pn,{items:i,loading:s}),e.jsx("div",{style:{marginTop:"24px"},children:e.jsx(qr,{onSubmit:c})})]})},ht={versions:12,catalogs:8,chips:12},Zr={leadWidth:22,metaWidth:424,mainLabel:"版本名稱",columns:[{label:"刊刻年代",width:"118px"},{label:"影印圖源",width:"156px"},{label:"收藏機構",width:"138px"}]},Qr=({data:t,transport:n,onNavigate:i,renderLink:r,lineageAction:s,collatedSection:o})=>{var R,E,M,$,O,A,F,J,W,U,ie,K;const a=D(),{convert:c}=P(),l=f.useMemo(()=>[...t.books||[],...t.collections||[]],[t.books,t.collections]),[d,p]=f.useState(new Map),[x,g]=f.useState(!1),[u,b]=f.useState(""),[y,h]=f.useState(!1),[S,m]=f.useState("default"),j=x||!!u||y||S==="year",w=f.useMemo(()=>j?l:l.slice(0,ht.versions),[l,j]);f.useEffect(()=>{if(!n||w.length===0)return;const L=w.filter(q=>!d.has(q));if(L.length===0)return;let Y=!1;return Promise.all(L.map(q=>n.getItem(q).then(V=>{const G=V??{};return[q,{id:q,title:G.title,edition:G.edition,resources:G.resources,publication_info:G.publication_info,current_location:G.current_location,lineage:G.lineage}]}).catch(()=>[q,{id:q}]))).then(q=>{Y||p(V=>{const G=new Map(V);for(const[de,Se]of q)G.set(de,Se);return G})}),()=>{Y=!0}},[n,w,d]);const k=f.useMemo(()=>l.map(L=>d.get(L)??{id:L}),[l,d]),C=f.useMemo(()=>pr(k,t.version_graph,{era:u,scanOnly:y,sort:S}),[k,t.version_graph,u,y,S]),T=x?C.rows:C.rows.slice(0,ht.versions),_=f.useMemo(()=>Ut(t.resources,t.resource_groups),[t.resources,t.resource_groups]),z=f.useMemo(()=>cr((t.related_works||[]).map(L=>({id:L.id,title:L.title,relation:L.relation}))),[t.related_works]),I=f.useMemo(()=>{var G,de,Se,me;const L=[],Y=(de=(G=t.authors)==null?void 0:G[0])==null?void 0:de.dynasty;Y&&L.push({label:"成書",value:c(Y)});const q=Je(t,a.unit.juan);if(q){const se=(Se=t.juan_count)==null?void 0:Se.description;L.push({label:"卷帙",value:c(q),title:se?c(se):void 0})}const V=C.allRows.filter(se=>se.sortYear!=null);if(V.length>0){const se=V.reduce((ye,Ie)=>ye.sortYear<=Ie.sortYear?ye:Ie);se.era.era&&L.push({label:"最早存世刻本",value:`${se.era.era}${se.era.reign?" "+se.era.reign:""}`,title:se.era.source==="edition"?"據版本題名推斷":void 0})}return(me=t.indexed_by)!=null&&me.length&&L.push({label:"著錄",value:`${t.indexed_by.length} ${a.unit.bu}`}),L},[t,c,a,C.allRows,j,l.length]),v=!o&&l.length===0&&_.buckets.length===0&&_.mirrors.length===0&&!((R=t.indexed_by)!=null&&R.length)&&!((E=t.emendated_by)!=null&&E.length)&&z.length===0&&!((M=t.description)!=null&&M.text);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:I.length?e.jsx(zt,{items:I}):void 0,children:[(($=t.description)==null?void 0:$.text)&&e.jsxs(e.Fragment,{children:[e.jsx(Me,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(O=t.description.sources)!=null&&O.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=>c(Ms(L))).filter(Boolean).join(" · ")}):null]}),(A=t.appendix)==null?void 0:A.map((L,Y)=>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:c(L.title)}),e.jsx(Me,{text:L.text,plainStrong:!0,style:{marginTop:10,fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"}})]},Y)),e.jsx(Tr,{rows:[{label:a.section.aliases,items:wt(t.additional_titles)},{label:a.section.attachedTexts,items:wt(t.attached_texts)},{label:a.section.appendix,items:(t.additional_works||[]).map(L=>L.book_title+(L.n_juan!=null?` ${L.n_juan}${a.unit.juan}`:""))}]})]}),o,l.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"版",title:a.section.relatedVersions,count:C.rows.length===C.allRows.length?`${C.allRows.length} 種`:`${C.allRows.length} 種 · 當前 ${C.rows.length} 種`,actions:e.jsxs(e.Fragment,{children:[s,e.jsx(Oe,{label:"僅看有影印",active:y,dashed:!0,onClick:()=>{h(L=>!L),g(!1)}}),e.jsx(Yt,{label:S==="default"?"排序:預設順序":"排序:年代先後",onClick:()=>m(L=>L==="default"?"year":"default")})]})}),C.allRows.length>=6&&C.eras.length>=2&&e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:[e.jsx(Oe,{label:a.catalog.all,active:!u,onClick:()=>{b(""),g(!1)}}),C.eras.map(L=>e.jsx(Oe,{label:L,active:u===L,onClick:()=>{b(L),g(!1)}},L))]}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:Zr}),T.map((L,Y)=>e.jsx(Aa,{row:L,no:Y,onNavigate:i,renderLink:r},L.id)),T.length===0&&e.jsx(st,{children:u||y?"當前篩選下沒有版本":"暫無版本著錄"})]}),C.rows.length>T.length&&e.jsx(De,{label:`展開其餘 ${C.rows.length-T.length} 種版本`,onClick:()=>g(!0)}),C.hasInferredEra&&e.jsx("div",{className:"bim-d-ui",style:{marginTop:10,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:"部分刊刻年代據版本題名推斷,非著錄原文"})]}),(_.buckets.length>0||_.mirrors.length>0)&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"源",title:"在線數字資源"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(210px, 1fr))",gap:26},children:[_.mirrors.map(L=>e.jsx(fn,{title:c(L.label),tag:L.description?c(L.description):void 0,children:L.items.map((Y,q)=>e.jsx(ot,{item:Y,siblings:L.items},`${Y.id||Y.url||Y.name}-${q}`))},L.key)),_.buckets.map(L=>e.jsx(fn,{title:Wa[L.key],tag:$a[L.key],children:L.items.map((Y,q)=>e.jsx(ot,{item:Y,siblings:L.items},`${Y.id||Y.url||Y.name}-${q}`))},L.key))]})]}),(F=t.indexed_by)!=null&&F.length||(J=t.emendated_by)!=null&&J.length?e.jsxs("div",{className:(W=t.emendated_by)!=null&&W.length?"bim-d-pair":void 0,style:(U=t.emendated_by)!=null&&U.length?void 0:{marginBottom:48},children:[(ie=t.indexed_by)!=null&&ie.length?e.jsx(Ri,{id:"catalogs",glyph:"目",title:a.section.indexed,items:t.indexed_by,unit:a.unit.bu,cap:ht.catalogs,showMeta:!0,t:a,convert:c,onNavigate:i,renderLink:r}):null,(K=t.emendated_by)!=null&&K.length?e.jsx(Ri,{id:"studies",glyph:"考",title:a.section.emendated,items:t.emendated_by,unit:a.unit.bu,cap:ht.catalogs,t:a,convert:c,onNavigate:i,renderLink:r}):null]}):null,z.map(L=>e.jsx(Fa,{glyph:L.key==="derivative"?"續":"叢",title:a.section[L.labelKey]??a.section.relatedWorks,items:L.items,convert:c,onNavigate:i,renderLink:r},L.key)),v&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:a.section.relatedVersions}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該作品的版本、資源與書目收錄。"})})]})]})},Wa={text:"文字全文庫",image:"影印資源",textImage:"圖文對照",physical:"館藏"},$a={text:"純文本",image:"原卷掃描",textImage:"圖文對照",physical:"實體"};function Aa({row:t,no:n,onNavigate:i,renderLink:r}){const{convert:s}=P(),o=[t.era.era,t.era.reign].filter(Boolean).join(" · "),a=t.era.source==="edition";return e.jsx(qt,{no:Xt(n),spec:Zr,main:e.jsx(_e,{id:t.id,label:s(t.name),onNavigate:i,renderLink:r,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:a?"據版本題名推斷":void 0,children:o||e.jsx(rt,{})}),e.jsx(zi,{items:t.images,convert:s}),e.jsx(zi,{items:t.holders,convert:s,fallback:t.locationName})]})})}function zi({items:t,convert:n,fallback:i}){if(t.length===0)return i?e.jsx("span",{style:{minWidth:0},children:n(i)}):e.jsx(rt,{});if(t.length===1){const a=t[0],c=(a.url?St(a.url):void 0)||n(a.name),l=Pt(a);return e.jsx("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},children:l?e.jsx(gn,{href:l,children:c}):c})}const r=t[0],s=(r.url?St(r.url):void 0)||n(r.name),o=Pt(r);return e.jsxs("span",{style:{minWidth:0},children:[o?e.jsx(gn,{href:o,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 Ri({id:t,glyph:n,title:i,items:r,unit:s,cap:o,showMeta:a,t:c,convert:l,onNavigate:d,renderLink:p}){const[x,g]=f.useState({}),[u,b]=f.useState(!1),y=r.length>0&&r.every((m,j)=>x[j]),h=f.useCallback(()=>{g(y?{}:Object.fromEntries(r.map((m,j)=>[j,!0])))},[y,r]),S=u?r:r.slice(0,o);return e.jsxs("section",{id:t,style:{scrollMarginTop:16},children:[e.jsx(ue,{glyph:n,tone:"ink",title:i,count:`${r.length} ${s}`,actions:e.jsx(Yt,{label:y?"收起全部":"+ 展開提要",onClick:h})}),e.jsx(qe,{children:S.map((m,j)=>{const w=m;return e.jsxs(kr,{open:!!x[j],onToggle:()=>g(k=>({...k,[j]:!k[j]})),main:e.jsxs(e.Fragment,{children:[w.source_bid?e.jsx(_e,{id:w.source_bid,label:l(w.source),onNavigate:d,renderLink:p,dense:!0}):l(w.source),a&&w.section&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:l(w.section)})]}),action:w.source_bid?e.jsx(_e,{id:w.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:[a&&(w.title_info||w.author_info||w.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:[w.title_info&&e.jsxs("span",{children:[c.label.titleInfo," ",l(w.title_info)]}),w.author_info&&e.jsxs("span",{children:[c.label.authorInfo," ",l(w.author_info)]}),w.edition&&e.jsxs("span",{children:[c.label.edition," ",l(w.edition)]})]}),w.summary&&e.jsx(At,{children:Fe(l(w.summary))}),w.comment&&e.jsx(At,{label:c.section.comment,children:Fe(l(w.comment))}),w.additional_comment&&e.jsx(At,{label:c.section.additionalComment,children:Fe(l(w.additional_comment))}),a&&w.page&&e.jsx("div",{className:"bim-d-ui",style:{fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:w.page})]},j)})}),r.length>S.length&&e.jsx(De,{label:`展開其餘 ${r.length-S.length} ${s}`,onClick:()=>b(!0)})]})}function Fa({glyph:t,title:n,items:i,convert:r,onNavigate:s,renderLink:o}){const[a,c]=f.useState(!1),l=a?i:i.slice(0,ht.chips);return e.jsxs(Ce,{style:{marginBottom:44},children:[e.jsx(ue,{glyph:t,tone:"ink",title:n,count:`${i.length} 種`}),e.jsxs(Kt,{children:[l.map(d=>e.jsx(Rt,{children:e.jsx(_e,{id:d.id,label:r(d.title),onNavigate:s,renderLink:o,dense:!0,style:{color:"inherit"}})},d.id)),i.length>l.length&&e.jsx(De,{inline:!0,label:`更多 ${i.length-l.length} 種`,onClick:()=>c(!0)})]})]})}const Ma=8,eo=({data:t,transport:n,onNavigate:i,renderLink:r,fullTextSection:s})=>{var w,k,C,T;const o=D(),{convert:a}=P(),[c,l]=f.useState(null),[d,p]=f.useState(new Map),[x,g]=f.useState([]),[u,b]=f.useState(!1);f.useEffect(()=>{if(!n||!t.work_id){l(null);return}let _=!1;return n.getItem(t.work_id).then(z=>{!_&&z&&z.type==="work"&&l(z)}).catch(()=>{}),()=>{_=!0}},[n,t.work_id]),f.useEffect(()=>{const _=t.contained_in||[];if(!n||_.length===0){p(new Map);return}let z=!1;return Promise.all(_.map(I=>{const v=typeof I=="string"?I:I.id;return n.getItem(v).then(R=>[v,R]).catch(()=>[v,null])})).then(I=>{if(z)return;const v=new Map;for(const[R,E]of I)E&&v.set(R,E);p(v)}),()=>{z=!0}},[n,t.contained_in]);const y=f.useMemo(()=>{const _=new Set([...(c==null?void 0:c.books)||[],...t.related_books||[]]);return _.delete(t.id),[..._]},[c==null?void 0:c.books,t.related_books,t.id]);f.useEffect(()=>{if(!n||y.length===0){g([]);return}const _=u?y:y.slice(0,Ma);let z=!1;return Promise.all(_.map(I=>n.getItem(I).then(v=>({id:I,title:v==null?void 0:v.title,edition:v==null?void 0:v.edition})).catch(()=>({id:I})))).then(I=>{z||g(I)}),()=>{z=!0}},[n,y,u]);const h=f.useMemo(()=>Ut(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=f.useMemo(()=>{var M,$,O;const _=[],z=It(t),I=mr(t);I&&_.push({label:"版本類型",value:I,title:(M=t.lineage)!=null&&M.category?void 0:"據版本題名推斷"}),(z.era||z.reign)&&_.push({label:"刊寫年代",value:[z.era,z.reign].filter(Boolean).join(" "),title:z.source==="edition"?"據版本題名推斷":void 0});const v=(t.contained_in||[]).flatMap(A=>typeof A=="string"?[]:vt(A.volume_index));v.length&&(_.push({label:"冊數",value:`${v.length} ${o.unit.volume}`}),_.push({label:"冊次",value:`第 ${Bn(v,o.unit.volume)} ${o.unit.volume}`}));const R=Je(t,o.unit.juan);R&&_.push({label:"卷帙",value:a(R)});const E=(t.resources||[]).filter(A=>(A.types||(A.type?[A.type]:[])).includes("physical"));return E.length?_.push({label:"存藏",value:E.slice(0,2).map(A=>a(A.name)).join("、")+(E.length>2?` 等 ${E.length} 處`:"")}):($=t.current_location)!=null&&$.name&&_.push({label:"存藏",value:a(t.current_location.name)}),(O=t.page_count)!=null&&O.description&&_.push({label:o.label.pageCount,value:t.page_count.description}),_},[t,a,o]),m=!!((w=t.description)!=null&&w.text),j=(t.contained_in||[]).some(_=>typeof _!="string"&&vt(_.volume_index).length>0);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:S.length?e.jsx(zt,{items:S,horizontal:!m}):void 0,children:m?e.jsx(Me,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}):void 0}),s,(t.contained_in||[]).length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"收",title:o.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((_,z)=>{var M,$;const I=typeof _=="string"?_:_.id,v=typeof _=="string"?[]:vt(_.volume_index),R=d.get(I),E=((M=R==null?void 0:R.books)==null?void 0:M.length)||(($=R==null?void 0:R.contained_works)==null?void 0:$.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(_e,{id:I,label:R?a(R.title):I,onNavigate:i,renderLink:r})}),e.jsxs("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:[E>0&&`全 ${E} ${o.unit.bu}`,E>0&&v.length>0&&" · ",v.length>0&&`本書佔 ${v.length} ${o.unit.volume}`]})]}),v.length>0&&e.jsx(Sr,{volumes:v,unit:o.unit.volume})]},`${I}-${z}`)})})]}),e.jsxs("div",{className:"bim-d-pair",children:[c&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"作",tone:"ink",title:o.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(_e,{id:c.id,label:a(c.title),onNavigate:i,renderLink:r})}),e.jsx("span",{style:{fontSize:12.5,color:"var(--bim-meta-fg, #7b6a54)"},children:[a(Je(c,o.unit.juan)),(k=c.authors)==null?void 0:k.map(_=>{const z=En(_.role);return`${_.dynasty?`〔${a(_.dynasty)}〕`:""}${a(_.name)}${z?" "+a(z):""}`}).join(" · ")].filter(Boolean).join(" · ")})]}),((C=c.description)==null?void 0:C.text)&&e.jsx(Me,{text:c.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(Wn,{label:o.section.aliases,items:[...wt(t.additional_titles),...wt(t.attached_texts)]})})]})]}),(h.buckets.length>0||h.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:[h.mirrors.map(_=>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:a(_.label)}),_.items.map((z,I)=>e.jsx(ot,{item:z,showVolumes:!j},`${z.id||z.url||z.name}-${I}`))]},_.key)),h.buckets.flatMap(_=>_.items).map((_,z)=>e.jsx(ot,{item:_,showVolumes:!j},`${_.id||_.url||_.name}-${z}`))]})]})]}),(T=t.location_history)!=null&&T.length?e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"藏",tone:"ink",title:o.section.locationHistory}),e.jsx("div",{style:{borderTop:"1px solid var(--bim-rule-strong, #2a231c)"},children:t.location_history.map((_,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:a(_.name)}),_.description&&e.jsx("span",{className:"bim-d-ui",style:{fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:a(_.description)})]},z))})]}):null,y.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"版",tone:"ink",title:o.relation.siblingVersions,count:`${y.length} 種`,actions:c?e.jsx(_e,{id:c.id,label:"在作品頁查看全部 →",onNavigate:i,renderLink:r,style:{color:"var(--bim-meta-fg, #7b6a54)",fontSize:11.5}}):void 0}),e.jsxs(Kt,{children:[x.map(_=>e.jsx(Rt,{children:e.jsx(_e,{id:_.id,label:a(_.edition||_.title||_.id),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},_.id)),y.length>x.length&&e.jsx(De,{inline:!0,label:`更多 ${y.length-x.length} 種`,onClick:()=>b(!0)})]})]})]})},Ei={titles:16,works:16},to=({data:t,catalog:n,onNavigate:i,renderLink:r,catalogAction:s})=>{var z,I;const o=D(),{convert:a}=P(),[c,l]=f.useState(""),[d,p]=f.useState(!1),[x,g]=f.useState(!1),u=f.useMemo(()=>fr(t,n),[t,n]),b=f.useMemo(()=>c?u.rows.filter(v=>v.section===c):u.rows,[u.rows,c]),y=d?b:b.slice(0,Ei.titles),h=f.useMemo(()=>Ut(t.resources,t.resource_groups),[t.resources,t.resource_groups]),S=t.contained_works||[],m=new Set(u.rows.map(v=>v.id).filter(Boolean)),j=S.length>0&&!S.every(v=>m.has(v.id)),w=(()=>{const v=u.rows.map(R=>R.edition).filter(Boolean);return v.length>1&&new Set(v).size===1})(),k=x?S:S.slice(0,Ei.works),C=u.sections.length>0,T=f.useMemo(()=>({leadWidth:26,metaWidth:300,mainLabel:"書名",columns:[...C?[{label:"部類",width:"64px"}]:[],{label:"全帙冊次",width:"1fr"}]}),[C]),_=f.useMemo(()=>{var M,$,O,A;const v=[];t.subtype&&v.push({label:o.label.type,value:t.subtype==="work_collection"?"叢編 · 作品集":"叢編"}),(M=t.publication_info)!=null&&M.details&&v.push({label:"刊印",value:a(t.publication_info.details)}),($=t.publication_info)!=null&&$.year&&v.push({label:"年代",value:t.publication_info.year});const R=((O=t.books)==null?void 0:O.length)||S.length,E=Je(t,o.unit.juan);return(R||E)&&v.push({label:"種數 / 卷數",value:[R?`${R} ${o.unit.bu}`:"",a(E)].filter(Boolean).join(" · "),title:(A=t.juan_count)!=null&&A.description?a(t.juan_count.description):void 0}),u.totalVolumes&&v.push({label:"全帙冊數",value:`${u.totalVolumes} ${o.unit.volume}`}),v},[t,S.length,u.totalVolumes,a,o]);return e.jsxs(e.Fragment,{children:[e.jsxs(Tt,{facts:_.length?e.jsx(zt,{items:_}):void 0,children:[((z=t.description)==null?void 0:z.text)&&e.jsx(Me,{text:t.description.text,style:{fontSize:15,lineHeight:2.05,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}}),(I=t.history)!=null&&I.length?e.jsx("div",{style:{marginTop:14},children:t.history.map((v,R)=>e.jsxs("div",{style:{fontSize:13.5,lineHeight:2,color:"var(--bim-quiet-fg, #5b4f40)"},children:["· ",a(v)]},R))}):null]}),u.rows.length>0&&e.jsxs(Ce,{children:[e.jsx(ue,{glyph:"目",title:o.section.containedBooks,count:b.length===u.rows.length?`${o.catalog.contains} ${u.rows.length} ${o.unit.items}`:`${u.rows.length} ${o.unit.items} · 當前 ${b.length} ${o.unit.items}`,actions:e.jsxs(e.Fragment,{children:[s,C&&e.jsxs(e.Fragment,{children:[e.jsx(Oe,{label:o.catalog.all,active:!c,onClick:()=>{l(""),p(!1)}}),u.sections.map(v=>e.jsx(Oe,{label:v,active:c===v,onClick:()=>{l(v),p(!1)}},v))]})]})}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:T}),y.map((v,R)=>{var E;return e.jsx(qt,{no:Xt(R),spec:T,main:e.jsxs(e.Fragment,{children:[v.id?e.jsx(_e,{id:v.id,label:a(v.title),onNavigate:i,renderLink:r,dense:!0}):e.jsx("span",{children:a(v.title)}),(E=v.subItems)!=null&&E.length?e.jsxs("span",{className:"bim-d-ui",style:{marginLeft:6,fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:["(",v.subItems.map(M=>a(M)).join("、"),")"]}):null,v.edition&&!w&&e.jsx("span",{className:"bim-d-ui",style:{marginLeft:8,fontSize:11,color:"var(--bim-hint-fg, #b3a385)"},children:a(v.edition)})]}),meta:e.jsxs(e.Fragment,{children:[C&&e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:v.section?v.section.endsWith("部")?v.section:`${v.section}部`:e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:v.volumes.length>0?`第 ${Bn(v.volumes,o.unit.volume)} ${o.unit.volume}`:v.expected!=null?`${v.found??0}/${v.expected} ${o.unit.volume}`:e.jsx(rt,{})})]})},`${v.id??v.title}-${R}`)}),y.length===0&&e.jsx(st,{children:o.catalog.noMatch})]}),b.length>y.length&&e.jsx(De,{label:`展開其餘 ${b.length-y.length} ${o.unit.items}子目`,onClick:()=>p(!0)})]}),(h.buckets.length>0||j)&&e.jsxs("div",{className:"bim-d-pair bim-d-pair-wide",children:[(h.buckets.length>0||h.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:[...h.mirrors.flatMap(v=>v.items),...h.buckets.flatMap(v=>v.items)].map((v,R)=>e.jsx(ot,{item:v,fallbackNote:v.details?a(v.details):void 0},`${v.id||v.url||v.name}-${R}`))})]}),j&&e.jsxs("section",{children:[e.jsx(ue,{glyph:"叢",tone:"ink",title:o.section.containedWorks,count:`${S.length} 種`}),e.jsxs(Kt,{children:[k.map(v=>e.jsx(Rt,{children:e.jsx(_e,{id:v.id,label:a(v.title),onNavigate:i,renderLink:r,dense:!0,style:{color:"inherit"}})},v.id)),S.length>k.length&&e.jsx(De,{inline:!0,label:`更多 ${S.length-k.length} 種`,onClick:()=>g(!0)})]})]})]})]})},Pa=16,Bi={leadWidth:26,metaWidth:300,mainLabel:"作品名稱",columns:[{label:"職任",width:"72px"},{label:"存世版本",width:"1fr"}]},an=["本名","字","號","号","諡號","谥号","尊號","尊号","廟號","庙号","法號","法号","道號","道号","年號","年号","常用名","別名","别名","小名","小字","行第","俗姓","俗名","稱號","称号","賜號","赐号","簡體","简体"];function Li(t){if(!t)return an.length;const n=an.indexOf(t);return n===-1?an.length:n}const no=({data:t,transport:n,onNavigate:i,renderLink:r})=>{var T,_,z;const s=D(),{convert:o}=P(),[a,c]=f.useState("全部"),[l,d]=f.useState(!1),[p,x]=f.useState("default"),[g,u]=f.useState(new Map),b=f.useMemo(()=>(t.works||[]).map(v=>{const R=g.get(v.work_id);return{id:v.work_id,title:(R==null?void 0:R.title)??v.work_id,role:v.role||"",cls:Rn(v.role),versionCount:R==null?void 0:R.versionCount,loaded:!!(R!=null&&R.loaded)}}),[t.works,g]),y=f.useMemo(()=>xr((t.works||[]).map(I=>I.role)),[t.works]),h=f.useMemo(()=>{const I=a==="全部"?b:b.filter(v=>v.cls===a);return p==="versions"?[...I].sort((v,R)=>(R.versionCount??-1)-(v.versionCount??-1)):I},[b,a,p]),S=l?h:h.slice(0,Pa),m=f.useMemo(()=>S.filter(I=>!g.has(I.id)).map(I=>I.id),[S,g]);f.useEffect(()=>{if(!n||m.length===0)return;let I=!1;return Promise.all(m.map(v=>n.getItem(v).then(R=>{var $,O;const E=R??{},M=((($=E.books)==null?void 0:$.length)??0)+(((O=E.collections)==null?void 0:O.length)??0);return[v,{id:v,title:E.title,versionCount:M,loaded:!0}]}).catch(()=>[v,{id:v,loaded:!0}]))).then(v=>{I||u(R=>{const E=new Map(R);for(const[M,$]of v)E.set(M,$);return E})}),()=>{I=!0}},[n,m]);const j=f.useMemo(()=>{const I=new Map;for(const v of t.alt_names||[]){const R=v.type||s.section.aliases;I.has(R)||I.set(R,[]),I.get(R).push(v.name)}return[...I.entries()].sort((v,R)=>Li(v[0])-Li(R[0])).map(([v,R])=>({label:v,names:R}))},[t.alt_names,s]),w=f.useMemo(()=>{const I=[];t.dynasty&&I.push({label:"時代",value:o(t.dynasty)});const v=E=>E==null?"":E<0?`前${-E}`:String(E);(t.birth_year!=null||t.death_year!=null)&&I.push({label:"生卒",value:`${v(t.birth_year)||"?"}—${v(t.death_year)||"?"}`});const R=(t.works||[]).length;return R&&I.push({label:"著作數",value:`${R} 種`}),I},[t,o]),k=(T=t.external_ids)==null?void 0:T.cbdb_id,C=!!((_=t.description)!=null&&_.text);return e.jsxs(e.Fragment,{children:[e.jsx(Tt,{facts:w.length?e.jsx(zt,{items:w}):void 0,children:(j.length>0||C)&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[j.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"8px 26px",fontSize:14},children:j.map(I=>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:o(I.label)}),e.jsx("span",{style:{color:"var(--bim-ink, #2a231c)"},children:I.names.map(v=>o(v)).join(" · ")})]},I.label))}),C&&e.jsx(Me,{text:t.description.text,style:{fontSize:14,lineHeight:2,color:"var(--bim-body-fg, #3b3228)",textAlign:"justify"}})]})}),b.length===0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks}),e.jsx(qe,{children:e.jsx(st,{children:"尚未著錄該人物的關聯作品。"})})]}),b.length>0&&e.jsxs(Ce,{style:{marginBottom:0},children:[e.jsx(ue,{glyph:"著",title:s.label.relatedWorks,count:h.length===b.length?`${b.length} 種`:`${b.length} 種 · 當前 ${h.length} 種`,actions:e.jsx(Yt,{label:p==="default"?"排序:著錄順序":"排序:版本數量",onClick:()=>{x(I=>(I==="default"&&d(!0),I==="default"?"versions":"default"))}})}),y.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:14},children:y.map(I=>e.jsx(Oe,{label:`${I.label} ${I.count}`,active:a===I.cls,onClick:()=>{c(I.cls),d(!1)}},I.cls))}),e.jsxs(qe,{children:[e.jsx(Jt,{spec:Bi}),S.map((I,v)=>e.jsx(qt,{no:Xt(v),spec:Bi,main:e.jsx(_e,{id:I.id,label:o(I.title),onNavigate:i,renderLink:r,dense:!0}),meta:e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{color:"var(--bim-meta-fg, #7b6a54)"},children:I.role?o(I.role):e.jsx(rt,{})}),e.jsx("span",{className:"bim-d-ui",style:{color:"var(--bim-label-fg, #a3937b)"},children:I.loaded?I.versionCount?`${I.versionCount} 種版本`:e.jsx("span",{style:{color:"var(--bim-hint-fg, #cbbda0)"},children:"未著錄版本"}):""})]})},I.id)),S.length===0&&e.jsx(st,{children:"該職任下的著作尚未著錄。"})]}),h.length>S.length&&e.jsx(De,{label:`展開其餘 ${h.length-S.length} 條著作`,onClick:()=>d(!0)}),k!=null&&e.jsxs("div",{className:"bim-d-ui",style:{marginTop:14,fontSize:11.5,color:"var(--bim-label-fg, #a3937b)"},children:["人物編號 CBDB ",k,((z=t.external_ids)==null?void 0:z.cbdb_match)==="auto"&&e.jsxs("span",{title:"由姓名、朝代与著作重合度自动匹配,未经人工复核",children:[" ","· 自動匹配"]})]})]})]})};function Ha(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 Oa(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 Wi(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 Da(t,n,i){const[r,s]=[t,n.book_id].sort();return{id:`sibling:${r}-${s}:${i}`,source:r,target:s,kind:"sibling",relation:n.relation,confidence:n.confidence,evidence:n.evidence,note:n.note}}function Na(t,n){var d;if(n==="all")return null;const i=(d=t.collections)==null?void 0:d[n],r=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,o=r||s||!!(i!=null&&i.hypothetical_ids);if(!o&&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||!o)return null;const a=r?new Set(i.groups):null,c=new Set(i.book_ids??[]);if(a&&t.node_groups)for(const[p,x]of Object.entries(t.node_groups))a.has(x)&&c.add(p);let l=null;if(i.hypothetical_ids&&(l=new Set(i.hypothetical_ids)),a){l||(l=new Set);for(const p of t.hypothetical_nodes??[])p.group&&a.has(p.group)&&l.add(p.id)}return{books:c,hypos:l}}function Mt(t,n,i){const r=t.version_graph,s={nodes:[],edges:[],groups:[],layout:"LR",excluded:[]};if(!r||!r.enabled)return s;const o=new Set(r.excluded_books??[]),a=r.node_groups??{},c=Na(r,i??r.default_collection??"all"),l=c!==null,d=(c==null?void 0:c.books)??null,p=(c==null?void 0:c.hypos)??null,x=new Set,g=new Set;if(l){const w=new Map(n.map(I=>[I.id,I])),k=new Map((r.hypothetical_nodes??[]).map(I=>[I.id,I])),C=I=>{const v=w.get(I);if(v&&v.lineage)return(v.lineage.derived_from??[]).map(E=>E.ref);const R=k.get(I);return R?(R.derived_from??[]).map(E=>E.ref):[]},T=I=>k.has(I)?!p||p.has(I):!d||d.has(I),_=new Set,z=I=>{if(!_.has(I)){_.add(I);for(const v of C(I))o.has(v)||(T(v)||(k.has(v)?g.add(v):w.has(v)&&x.add(v)),z(v))}};for(const I of n)d&&d.has(I.id)&&!o.has(I.id)&&z(I.id);for(const I of r.hypothetical_nodes??[])p&&p.has(I.id)&&z(I.id)}const u=n.filter(w=>!o.has(w.id)).filter(w=>!d||d.has(w.id)||x.has(w.id)).map(w=>{const k=Oa(w,a);return k&&x.has(w.id)&&(k.bridge=!0),k}).filter(w=>w!==null),b=(r.hypothetical_nodes??[]).filter(w=>!p||p.has(w.id)||g.has(w.id)).map(w=>{const k=Ha(w);return g.has(w.id)&&(k.bridge=!0),k}),y=[...u,...b],h=new Set(y.map(w=>w.id)),S=new Set,m=[],j=w=>{S.has(w.id)||!h.has(w.source)||!h.has(w.target)||(S.add(w.id),m.push(w))};for(const w of n)o.has(w.id)||!w.lineage||d&&!d.has(w.id)&&!x.has(w.id)||((w.lineage.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))}),(w.lineage.related_to??[]).forEach((k,C)=>{j(Da(w.id,k,C))}));for(const w of r.hypothetical_nodes??[])p&&!p.has(w.id)&&!g.has(w.id)||(w.derived_from??[]).forEach((k,C)=>{j(Wi(w.id,k,C))});return{nodes:y,edges:m,groups:r.groups??[],title:r.title,description:r.description,layout:r.layout??"LR",excluded:Array.from(o)}}function io(t,n,i){const r=(t??(n!=null?String(n):"")).trim();return r?!i||/约|約|推定|大约|大約|学界估计|學界估計|不確|不确|前后|前後|疑/.test(r)?r:`约 ${r}`:""}function Va(t,n){const i=[],r=t.version_graph;if(!r)return i;const s=new Set(n.map(l=>l.id)),o=new Set((r.hypothetical_nodes??[]).map(l=>l.id)),a=new Set([...s,...o]),c=(l,d)=>{a.has(d.ref)||i.push(`${l}: derived_from.ref "${d.ref}" 未在 books 或 hypothetical_nodes 中找到`),d.ref_type==="book"&&!s.has(d.ref)&&i.push(`${l}: derived_from.ref "${d.ref}" 标记为 book 但不在 books 列表中`),d.ref_type==="hypothetical"&&!o.has(d.ref)&&i.push(`${l}: derived_from.ref "${d.ref}" 标记为 hypothetical 但不在 hypothetical_nodes 中`)};for(const l of n){if(!l.lineage)continue;const d=`Book ${l.id} (${l.title})`;(l.lineage.derived_from??[]).forEach(p=>c(d,p)),(l.lineage.related_to??[]).forEach(p=>{s.has(p.book_id)||i.push(`${d}: related_to.book_id "${p.book_id}" 不在 books 列表中`)})}for(const l of r.hypothetical_nodes??[]){const d=`Hypothetical ${l.id} (${l.label})`;(l.derived_from??[]).forEach(p=>c(d,p))}return i}const ro=({graph:t,renderLink:n,className:i,style:r})=>{const{convert:s}=P();if(!t.nodes.length)return e.jsx("div",{style:{...rc,...r},className:i,children:"暂无版本图数据"});const o=new Map,a=new Map;for(const g of t.edges)if(g.kind==="derive"){const u=o.get(g.target)??[];u.push(g),o.set(g.target,u)}else for(const u of[g.source,g.target]){const b=a.get(u)??[];b.push(g),a.set(u,b)}const c=new Map(t.nodes.map(g=>[g.id,g])),l=new Map,d=[];for(const g of t.nodes)if(g.group){const u=l.get(g.group)??[];u.push(g),l.set(g.group,u)}else d.push(g);const p=(g,u)=>(g.year??9999)-(u.year??9999);l.forEach(g=>g.sort(p)),d.sort(p);const x=t.groups.filter(g=>l.has(g.id));return e.jsxs("div",{className:i,style:{...Ua,...r},children:[t.title&&e.jsx("div",{style:Ya,children:s(t.title)}),t.description&&e.jsx("div",{style:Ka,children:s(t.description)}),x.map(g=>e.jsx($i,{label:g.label,color:g.color,nodes:l.get(g.id),incomingMap:o,siblingMap:a,nodeMap:c,renderLink:n},g.id)),d.length>0&&e.jsx($i,{label:"其他",nodes:d,incomingMap:o,siblingMap:a,nodeMap:c,renderLink:n})]})},$i=({label:t,color:n,nodes:i,incomingMap:r,siblingMap:s,nodeMap:o,renderLink:a})=>{const{convert:c}=P();return e.jsxs("div",{style:Ja,children:[e.jsx("div",{style:{...qa,borderLeftColor:n??"var(--bim-widget-border, #ddd)"},children:c(t)}),i.map(l=>e.jsx(Ga,{node:l,incoming:r.get(l.id)??[],siblings:s.get(l.id)??[],nodeMap:o,renderLink:a},l.id))]})},Ga=({node:t,incoming:n,siblings:i,nodeMap:r,renderLink:s})=>{const o=t.kind==="hypothetical",a=t.bridge,{convert:c}=P();return e.jsxs("div",{style:{...Xa,borderStyle:o||a?"dashed":"solid",opacity:a?.55:t.status==="lost"?.7:1,background:a?"var(--bim-bg-subtle, #fafafa)":void 0},title:a?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsxs("div",{style:Za,children:[e.jsx("span",{style:Qa,children:o||!s?c(t.label):s(t.id,c(t.label))}),(t.year_text||t.year!=null)&&e.jsx("span",{style:ec,children:io(c(t.year_text),t.year,t.year_uncertain)})]}),e.jsxs("div",{style:tc,children:[t.category&&e.jsx(gt,{children:c(t.category)}),t.status==="lost"&&e.jsx(gt,{tone:"warn",children:"已佚"}),t.status==="fragment"&&e.jsx(gt,{tone:"warn",children:"残本"}),o&&e.jsx(gt,{tone:"info",children:"假想祖本"}),a&&e.jsx(gt,{tone:"info",children:"桥接"})]}),t.extant_juan&&e.jsxs("div",{style:nc,children:["现存:",c(t.extant_juan)]}),t.note&&e.jsx("div",{style:ic,children:c(t.note)}),n.length>0&&e.jsxs("div",{style:Fi,children:[e.jsx("div",{style:Mi,children:"来源:"}),n.map(l=>{const d=r.get(l.source);return e.jsxs("div",{style:Pi(l.confidence),children:[e.jsx("span",{style:Hi,children:c(l.relation)}),e.jsx("span",{children:(d==null?void 0:d.kind)==="book"&&s?s(d.id,c(d.label)):c((d==null?void 0:d.label)??l.source)}),l.confidence!=="consensus"&&l.confidence!=="certain"&&e.jsx(Ai,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(l.evidence)]})]},l.id)})]}),i.length>0&&e.jsxs("div",{style:Fi,children:[e.jsx("div",{style:Mi,children:"关联:"}),i.map(l=>{const d=l.source===t.id?l.target:l.source,p=r.get(d);return e.jsxs("div",{style:Pi(l.confidence),children:[e.jsx("span",{style:Hi,children:c(l.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(Ai,{level:l.confidence}),l.evidence&&e.jsxs("span",{style:Oi,children:["· ",c(l.evidence)]})]},l.id)})]})]})},gt=({children:t,tone:n="default"})=>{const r={default:{bg:"var(--bim-tag-bg, #f0f0f0)",fg:"var(--bim-fg, #555)"},warn:{bg:"var(--bim-warn-bg, #fff3cd)",fg:"var(--bim-warn-fg, #856404)"},info:{bg:"var(--bim-info-bg, #e7f3ff)",fg:"var(--bim-info-fg, #0c5380)"}}[n];return e.jsx("span",{style:{display:"inline-block",padding:"1px 8px",fontSize:"11px",borderRadius:"10px",background:r.bg,color:r.fg,marginRight:"4px"},children:t})},Ai=({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)"},Ya={fontSize:"16px",fontWeight:600,marginBottom:"8px"},Ka={fontSize:"13px",color:"var(--bim-muted, #666)",marginBottom:"16px",lineHeight:1.6},Ja={marginBottom:"16px"},qa={fontSize:"13px",fontWeight:600,padding:"4px 12px",borderLeft:"4px solid",marginBottom:"8px",color:"var(--bim-fg, #333)"},Xa={border:"1px solid var(--bim-widget-border, #e0e0e0)",borderRadius:"6px",padding:"10px 12px",marginBottom:"8px",background:"var(--bim-bg, #fff)"},Za={display:"flex",justifyContent:"space-between",alignItems:"baseline",marginBottom:"4px"},Qa={fontSize:"15px",fontWeight:600},ec={fontSize:"12px",color:"var(--bim-muted, #777)"},tc={marginBottom:"6px"},nc={fontSize:"12px",color:"var(--bim-muted, #666)",margin:"2px 0"},ic={fontSize:"12px",color:"var(--bim-muted, #888)",fontStyle:"italic",margin:"4px 0"},Fi={marginTop:"6px",paddingTop:"6px",borderTop:"1px dashed var(--bim-widget-border, #e8e8e8)"},Mi={fontSize:"11px",color:"var(--bim-muted, #888)",marginBottom:"2px"},Pi=t=>({fontSize:"12px",margin:"2px 0",opacity:t==="probable"||t==="disputed"?.85:1}),Hi={display:"inline-block",padding:"0 6px",fontSize:"11px",background:"var(--bim-tag-bg, #f0f0f0)",color:"var(--bim-fg, #555)",borderRadius:"3px",marginRight:"6px"},Oi={fontSize:"11px",color:"var(--bim-muted, #888)"},rc={padding:"20px",textAlign:"center",color:"var(--bim-muted, #999)",fontSize:"13px"},oo=({selectedNodeId:t,...n})=>{const[i,r]=f.useState("loading"),[s,o]=f.useState(null);return f.useEffect(()=>{let a=!1;return oc().then(c=>{a||(c?(o(c),r("ready")):r("missing"))}),()=>{a=!0}},[]),i==="loading"?e.jsx("div",{style:Di,children:"加载图组件中…"}):i==="missing"||!s?e.jsxs("div",{style:Di,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(sc,{modules:s,selectedNodeId:t,...n})};async function oc(){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 sc=({graph:t,renderLink:n,height:i=600,className:r,style:s,selectedNodeId:o,modules:a})=>{const{ReactFlow:c,Background:l,Controls:d,Handle:p,Position:x,BaseEdge:g,EdgeLabelRenderer:u,getSmoothStepPath:b,dagre:y}=a,h=f.useMemo(()=>({lineage:C=>{var O,A,F,J;const T=((O=C.data)==null?void 0:O.stepPosition)??.85,[_,z,I]=b({sourceX:C.sourceX,sourceY:C.sourceY,sourcePosition:C.sourcePosition,targetX:C.targetX,targetY:C.targetY,targetPosition:C.targetPosition,stepPosition:T,borderRadius:5}),v=!!((A=C.data)!=null&&A.isSibling),R=v?z:C.targetX-18,E=v?I:C.targetY-12,M=(F=C.data)==null?void 0:F.labelStyle,$=(J=C.data)==null?void 0:J.labelBgStyle;return e.jsxs(e.Fragment,{children:[e.jsx(g,{id:C.id,path:_,style:C.style,markerStart:C.markerStart,markerEnd:C.markerEnd}),C.label&&e.jsx(u,{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},children:C.label})})]})}}),[g,u,b]),S=f.useMemo(()=>({version:C=>{const T=C.data,_=T.kind==="hypothetical",z=T.status==="lost",I=T.isSelected,v=T.bridge,R=T.borderColor??"var(--bim-muted, #888)",E=v||_?"dashed":"solid",M=v?.5:z?.6:1;return e.jsxs("div",{style:{background:v?"var(--bim-bg-subtle, #fafafa)":"var(--bim-bg, #fff)",border:`2px ${E} ${I?"var(--bim-primary, #0078d4)":R}`,borderRadius:8,padding:"6px 10px",minWidth:120,maxWidth:160,wordWrap:"break-word",wordBreak:"break-word",opacity:M,boxShadow:I?"0 0 0 3px rgba(0, 120, 212, 0.2), 0 2px 8px rgba(0, 120, 212, 0.3)":_||v?"none":"0 1px 3px rgba(0,0,0,0.1)"},title:v?"桥接节点:本身不在核心集,为保持派生链完整而显示":void 0,children:[e.jsx(p,{type:"target",position:x.Left,style:{visibility:"hidden"}}),e.jsx("div",{style:{fontSize:12,fontWeight:600,marginBottom:1,lineHeight:1.3},children:_||!T.renderLink?T.label:T.renderLink(T.bookId,T.label)}),T.description&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.25,marginTop:1},children:T.description}),T.yearText&&e.jsx("div",{style:{fontSize:10,color:"var(--bim-muted, #777)",lineHeight:1.2},children:io(T.yearText,void 0,T.uncertain)}),z&&e.jsx("div",{style:{fontSize:9,color:"var(--bim-lost-fg, #c62828)",marginTop:1},children:"已佚"}),e.jsx(p,{type:"source",position:x.Right,style:{visibility:"hidden"}})]})}}),[p,x]),{convert:m}=P(),{rfNodes:j,rfEdges:w}=f.useMemo(()=>lc(t,y,n,o,m),[t,y,n,o,m]);return e.jsx("div",{style:{width:"100%",height:i,...s},className:r,children:e.jsxs(c,{nodes:j,edges:w,nodeTypes:S,edgeTypes:h,fitView:!0,fitViewOptions:{padding:.15},proOptions:{hideAttribution:!0},nodesDraggable:!1,nodesConnectable:!1,edgesFocusable:!1,minZoom:.2,maxZoom:1.8,children:[e.jsx(l,{gap:16}),e.jsx(d,{showInteractive:!1})]})})};function lc(t,n,i,r,s=o=>o??""){const c=t.layout==="LR"||!t.layout,l=new n.graphlib.Graph;l.setGraph({rankdir:c?"LR":"TB",ranksep:160,nodesep:40,edgesep:16,marginx:20,marginy:20}),l.setDefaultEdgeLabel(()=>({}));const d=new Map(t.groups.map(S=>[S.id,S.color??"var(--bim-muted, #888)"]));for(const S of t.nodes)l.setNode(S.id,{width:160,height:90});const p=new Set(["配补","形式仿照","综合","兄弟本","同源","互校"]);for(const S of t.edges)S.kind==="derive"&&(p.has(S.relation)||l.setEdge(S.source,S.target));n.layout(l);const x=t.nodes.map(S=>{const m=l.node(S.id),j=r&&S.id===r,w={kind:S.kind,label:s(S.label),bookId:S.kind==="book"?S.id:void 0,yearText:s(S.year_text??cc(S)),uncertain:S.year_uncertain,category:S.category,status:S.status,borderColor:S.group?d.get(S.group):void 0,renderLink:i,isSelected:j,description:s(S.description),bridge:S.bridge};return{id:S.id,type:"version",position:{x:m.x-160/2,y:m.y-90/2},data:w,draggable:!1,selected:j}}),g=.78,u=.06,b=new Map;for(const S of t.edges)S.kind==="derive"&&(b.has(S.source)||b.set(S.source,[]),b.get(S.source).push(S));const y=new Map;for(const[S,m]of b){if(m.length<=1)continue;const j=[...m].sort((k,C)=>{var z,I;const T=((z=l.node(k.target))==null?void 0:z.y)??0,_=((I=l.node(C.target))==null?void 0:I.y)??0;return T-_}),w=j.length;j.forEach((k,C)=>{const T=(C-(w-1)/2)*u;y.set(k.id,g+T)})}const h=t.edges.map(S=>ac(S,y.get(S.id),s));return{rfNodes:x,rfEdges:h}}function ac(t,n,i=r=>r??""){const r=t.confidence==="probable"||t.confidence==="disputed",s=t.kind==="sibling",o=dc(t.confidence),a={type:"arrowclosed",color:o,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:o,strokeWidth:s?1:1.5,strokeDasharray:s?"4 3":r?"6 4":void 0,opacity:r?.75:1},animated:!1,markerEnd:a,markerStart:s?a:void 0,zIndex:1e3}}function cc(t){if(t.year_range)return`~${t.year_range[0]}–${t.year_range[1]}`;if(typeof t.year=="number")return String(t.year)}function dc(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 Di={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)"},so=({graph:t,defaultMode:n="list",renderLink:i,graphHeight:r=600,selectedNodeId:s,onModeChange:o,collection:a,onCollectionChange:c,collectionsAvailable:l,collectionCounts:d,className:p,style:x})=>{var m;const[g,u]=f.useState(n),b=j=>{u(j),o==null||o(j)},y=(()=>{if(!l)return[];const j=Object.entries(l);return j.length===0||l.all?j:[...j,["all",{label:"全部",description:"显示该作品所有版本(含桥接节点)"}]]})(),h=!!(c&&y.length>0);if(!t.nodes.length)return e.jsx("div",{style:{padding:24,color:"var(--bim-muted, #999)",textAlign:"center"},children:"暂无版本传承数据"});const S=a?(m=l==null?void 0:l[a])==null?void 0:m.description:void 0;return e.jsxs("div",{className:p,style:x,children:[e.jsxs("div",{style:pc,children:[e.jsx("button",{onClick:()=>b("list"),style:cn(g==="list"),children:"列表"}),e.jsx("button",{onClick:()=>b("graph"),style:cn(g==="graph"),children:"关系图"}),h&&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(([j,w])=>{const k=d==null?void 0:d[j];return e.jsxs("button",{onClick:()=>c==null?void 0:c(j),style:cn(a===j),title:w.description,children:[w.label,k!=null?` ${k}`:""]},j)})]})]}),h&&S&&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:S}),g==="list"?e.jsx(ro,{graph:t,renderLink:i}):e.jsx(oo,{graph:t,renderLink:i,height:r,selectedNodeId:s})]})},pc={display:"flex",gap:4,marginBottom:12,position:"relative",zIndex:20,flexWrap:"wrap"},cn=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"}),lo=({style:t})=>{const n=f.useContext(_t);if(!n)return null;const{locale:i,setLocale:r}=n,s=i==="zh-Hant",o=()=>r(s?"zh-Hans":"zh-Hant");return e.jsxs("button",{type:"button",onClick:o,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:"简"})]})},ao=({href:t,label:n="在 GitHub 查看本条目源文件",size:i=16,className:r,style:s})=>e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",title:n,"aria-label":n,className:r,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:i+8,height:i+8,borderRadius:4,color:"var(--bim-desc-fg, #717171)",textDecoration:"none",transition:"color 120ms, background 120ms",...s},onMouseEnter:o=>{o.currentTarget.style.color="var(--bim-fg, #1a1a1a)"},onMouseLeave:o=>{o.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"})})}),uc=({id:t,transport:n,activeTab:i,onTabChange:r,activeJuan:s,onJuanChange:o,lineageMode:a="list",onLineageModeChange:c,lineageCollection:l,onLineageCollectionChange:d,initialPage:p=1,selectedLineageNodeId:x,onNavigate:g,onBack:u,backLabel:b,renderLink:y,enrichDetail:h,getSourceLink:S,extraTabs:m=[],showFeedbackTab:j=!0,feedbackApiUrl:w,height:k,footerExtra:C,className:T,style:_})=>{const z=D(),{convert:I}=P(),[v,R]=f.useState(null),[E,M]=f.useState(null),[$,O]=f.useState(!0),[A,F]=f.useState(!1),[J,W]=f.useState([]),[U,ie]=f.useState(!1),[K,L]=f.useState(null),[Y,q]=f.useState(!1),[V,G]=f.useState(null),[de,Se]=f.useState(!1),[me,se]=f.useState(null),[ye,Ie]=f.useState(!1),Te=f.useRef(null),[Ze,ct]=f.useState(null),N=s!==void 0?s:Ze,oe=f.useCallback(H=>{o?o(H):ct(H)},[o]),ne=f.useCallback(async H=>{if(!n.getCollectionCatalogs&&!n.getCollectionCatalog){W([]);return}ie(!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{ie(!1)}},[n]),B=f.useCallback(async H=>{if(!n.getCollatedEditionIndex){L(null);return}q(!0);try{L(await n.getCollatedEditionIndex(H))}catch{L(null)}finally{q(!1)}},[n]),ee=f.useCallback(async H=>{if(!n.getBookFullTextIndex){G(null);return}Se(!0);try{G(await n.getBookFullTextIndex(H))}catch{G(null)}finally{Se(!1)}},[n]),le=f.useCallback(async(H,re)=>{Ie(!0);try{if(n.getLineageGraph){const We=await n.getLineageGraph(H);We&&se(We)}const ae=re.version_graph;if(!ae||!ae.enabled){me||se(null),Te.current=null;return}const ce=re.books??[],te=[];for(const We of ce)try{const ze=await n.getItem(We);ze&&te.push(ze)}catch{}Te.current={work:re,books:te};const Z=l??ae.default_collection??(ae.core_books&&ae.core_books.length>0?"core":"all"),Le=Z==="core"&&Array.isArray(ae.core_books)&&ae.core_books.length>0?"core":Z??"all";se(Mt(re,te,Le))}catch{se(null),Te.current=null}finally{Ie(!1)}},[n]);f.useEffect(()=>{let H=!1;return(async()=>{O(!0),F(!1),R(null),M(null),W([]),L(null),se(null),Te.current=null;try{const ae=await n.getItem(t);if(H)return;if(!ae){F(!0);return}const ce=ae;let te=null;if(n.getEntry&&(te=await n.getEntry(t),H))return;te||(te={id:t,title:ce.title??ce.primary_name??t,type:ce.type??"book"}),h&&h(te,ce),R(te),M(ce),ce.type==="collection"?ne(t):ce.type==="work"?((ce.has_collated||n.getCollatedEditionIndex)&&B(t),(ce.version_graph||n.getLineageGraph)&&le(t,ce)):ce.type==="book"&&ce.has_full_text&&n.getBookFullTextIndex&&ee(t)}catch{H||F(!0)}finally{H||O(!1)}})(),()=>{H=!0}},[t,n,h,ne,B,le,ee]),f.useEffect(()=>{const H=Te.current;!H||!l||se(Mt(H.work,H.books,l))},[l]);const X=[];if(E){if(X.push({key:"basic",label:z.detailTab.basicInfo}),E.type==="collection"){U&&J.length===0&&X.push({key:"catalog:loading",label:`${z.detailTab.catalog}…`});for(const H of J)X.push({key:`catalog:${H.resource_id}`,label:H.short_name?`${I(H.short_name)}${z.detailTab.catalogSuffix}`:z.detailTab.collectionCatalog})}E.type==="work"&&(K||Y)&&i==="collated"&&X.push({key:"collated",label:Y?`${z.detailTab.collatedEdition}…`:z.detailTab.collatedEdition}),E.type==="book"&&(V||de)&&i==="fulltext"&&X.push({key:"fulltext",label:de?`${z.detailTab.fullText}…`:z.detailTab.fullText}),E.type==="work"&&(me||ye)&&X.push({key:"lineage",label:ye?`${z.detailTab.lineage}…`:z.detailTab.lineage});for(const H of m)(H.position??"before-feedback")==="before-feedback"&&H.shouldShow(E)&&X.push({key:H.key,label:H.label});j&&i==="feedback"&&X.push({key:"feedback",label:z.detailTab.feedback});for(const H of m)H.position==="after-feedback"&&H.shouldShow(E)&&X.push({key:H.key,label:H.label})}f.useEffect(()=>{if(i!=="emendated"||!E)return;r("basic");const H=setTimeout(()=>{var re;(re=document.getElementById("studies"))==null||re.scrollIntoView({behavior:"smooth",block:"start"})},100);return()=>clearTimeout(H)},[i,E,r]);const He=v&&E&&S?S({activeTab:i,activeJuan:N,entry:v,detail:E}):null,ve=f.useMemo(()=>{var te;if(!E)return null;const re=(E.authors??[]).map(Z=>{const Le=En(Z.role);return`${Z.dynasty?`〔${I(Z.dynasty)}〕`:""}${I(Z.name)}${Le?` ${I(Le)}`:""}`}).join(" · ");let ae=!1;try{ae=Q.extractStatus(E.id)==="draft"}catch{}if(E.type==="book"){const Z=E;return{title:I(Z.title),subtitle:Z.edition?I(Z.edition):re||void 0,aside:[ae?z.status.draft:"",re&&Z.edition?re:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}}if(E.type==="collection"){const Z=E;return{title:I(Z.title),subtitle:I(Je(Z,z.unit.juan))||void 0,aside:[(te=Z.publication_info)==null?void 0:te.year,ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:re||void 0}}if(E.type==="entity"){const Z=E,Le=ze=>ze==null?"":ze<0?`前${-ze}`:String(ze),We=Z.birth_year!=null||Z.death_year!=null?`${Le(Z.birth_year)||"?"}—${Le(Z.death_year)||"?"}`:"";return{title:I(Z.primary_name||Z.title),subtitle:[Z.dynasty?`〔${I(Z.dynasty)}〕`:"",We].filter(Boolean).join(" ")||void 0,aside:ae?z.status.draft:void 0,secondLine:void 0}}const ce=I(Je(E,z.unit.juan));return{title:I(E.title),subtitle:[ce,re].filter(Boolean).join(" · ")||void 0,aside:[fc(z,E.subtype),ae?z.status.draft:""].filter(Boolean).join(" · ")||void 0,secondLine:void 0}},[E,I,z]),ge=()=>{var H,re;return E?E.type==="work"?e.jsx(Qr,{data:E,transport:n,onNavigate:g,renderLink:y,collatedSection:K&&(((H=K.juan_files)==null?void 0:H.length)??0)>0?e.jsx(Ni,{title:E.title,measure:`${K.juan_files.length} ${I(z.unit.juan)}`,onOpen:()=>{oe(K.juan_files[0]),r("collated")}}):null,lineageAction:me&&me.nodes.length>0?e.jsxs("button",{type:"button",onClick:()=>r("lineage"),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.lineage," →"]}):null}):E.type==="book"?e.jsx(eo,{data:E,transport:n,onNavigate:g,renderLink:y,fullTextSection:V&&V.chapters.length>0?e.jsx(Ni,{title:E.title,measure:[`${V.total_chapters} ${I("章")}`,I(V.version_label)].filter(Boolean).join(" · "),onOpen:()=>{oe(null),r("fulltext")}}):null}):E.type==="collection"?e.jsx(to,{data:E,catalog:(re=J[0])==null?void 0:re.data,transport:n,onNavigate:g,renderLink:y,catalogAction:J.length>0?e.jsxs("button",{type:"button",onClick:()=>r(`catalog:${J[0].resource_id}`),className:"bim-d-ui",style:{background:"none",border:"none",padding:"2px 0",cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-accent, #9c3a2c)",borderBottom:"1px solid var(--bim-rule, #d6c9ae)"},children:[z.detailTab.collectionCatalog," →"]}):null}):e.jsx(no,{data:E,transport:n,onNavigate:g,renderLink:y}):null},Qe=()=>{var re,ae,ce;if(!v||!E)return null;if(i==="basic"||i==="emendated")return ge();if(typeof i=="string"&&i.startsWith("catalog:")){const te=(re=J.find(Z=>`catalog:${Z.resource_id}`===i))==null?void 0:re.data;return e.jsx(Cn,{data:te,onNavigate:g,renderLink:y})}if(i==="collated")return e.jsx(Mn,{index:K||void 0,workId:t,transport:n,onNavigate:g,activeJuan:N,onJuanChange:oe});if(i==="fulltext")return e.jsx(Ar,{index:V||void 0,bookId:t,transport:n,activeChapter:N,onChapterChange:oe});if(i==="lineage"){if(!me)return e.jsx("div",{style:{color:"var(--bim-label-fg, #a3937b)",padding:"24px 0"},children:ye?"加載中…":"暫無版本圖數據"});const te=E.type==="work"?E:null;return e.jsx(so,{graph:me,renderLink:y,graphHeight:Math.max(500,(typeof window<"u"?window.innerHeight:800)-250),defaultMode:a,onModeChange:c,selectedNodeId:x,collection:l??((ae=te==null?void 0:te.version_graph)==null?void 0:ae.default_collection),onCollectionChange:d,collectionsAvailable:(ce=te==null?void 0:te.version_graph)==null?void 0:ce.collections,collectionCounts:(()=>{var ze,Hn,On,Dn,Nn,Vn,Gn;if(!te)return;const Z={},Le=((ze=Te.current)==null?void 0:ze.books)??[];Z.all=(((Hn=te.books)==null?void 0:Hn.length)??0)-(((Dn=(On=te.version_graph)==null?void 0:On.excluded_books)==null?void 0:Dn.length)??0);const We=(Nn=te.version_graph)==null?void 0:Nn.collections;if(We)for(const Un of Object.keys(We))Z[Un]=Mt(te,Le,Un).nodes.filter(Yn=>Yn.kind==="book"&&!Yn.bridge).length;return Z.core==null&&((Gn=(Vn=te.version_graph)==null?void 0:Vn.core_books)!=null&&Gn.length)&&(Z.core=te.version_graph.core_books.length),Z})()})}if(i==="feedback"&&j)return e.jsx(Xr,{resourceId:t,apiUrl:w});const H=m.find(te=>te.key===i);return H?H.render({detail:E,entry:v,transport:n,onNavigate:g}):null};if($)return e.jsx($t,{style:{minHeight:k,..._},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(A||!E||!v||!ve)return e.jsx($t,{style:{minHeight:k,..._},children:e.jsx("div",{style:{padding:"64px 0",textAlign:"center",color:"var(--bim-label-fg, #a3937b)",fontSize:14},children:"找不到該條目,可能已被刪除或 ID 不正確"})});const co=i==="basic"||i==="emendated",Zt=[{label:b??z.detailTab.backToIndex,onClick:u}];if(E.type==="book"&&E.work_id){const H=E.work_id;Zt.push({label:z.indexType.work,id:H,onClick:()=>g==null?void 0:g(H)})}Zt.push({label:z.indexType[E.type]});const Et=i==="collated"||i==="fulltext";return e.jsx("div",{className:T,children:e.jsxs($t,{wide:Et,style:{minHeight:k,..._},children:[e.jsx(yr,{breadcrumb:e.jsxs(e.Fragment,{children:[e.jsx(Ln,{char:"籍"}),e.jsx(vr,{items:Zt})]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(lo,{}),j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),className:"bim-d-ui",style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.feedback}),He&&e.jsx(ao,{...He})]})}),e.jsx(jr,{...ve,aside:Et?e.jsxs("button",{type:"button",onClick:()=>r("basic"),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:[I("作品信息")," →"]}):ve.aside}),!Et&&X.length>1&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,margin:"14px 0 0",paddingBottom:2},children:X.map(H=>e.jsx(Oe,{label:H.label,active:H.key===i||co&&H.key==="basic",onClick:()=>r(H.key)},H.key))}),e.jsx("div",{style:{marginTop:!Et&&X.length>1?8:0},children:Qe()}),e.jsx(zr,{left:e.jsxs(e.Fragment,{children:[C,C?" · ":"",e.jsx(xc,{id:E.id,label:z.label.id,copied:z.action.copied})]}),right:e.jsxs(e.Fragment,{children:[j&&e.jsx("button",{type:"button",onClick:()=>r("feedback"),style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.submitVersion}),He&&e.jsx("a",{href:He.href,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--bim-meta-fg, #7b6a54)"},children:z.detailTab.dataLicense})]})})]})})};function xc({id:t,label:n,copied:i}){const[r,s]=f.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 o;(o=navigator.clipboard)==null||o.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),1500)}).catch(()=>{})},title:r?i:void 0,style:{background:"none",border:"none",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:11.5,color:"var(--bim-hint-fg, #b3a385)"},children:r?"✓":"⧉"})]})}function fc(t,n){return n?t.workSubtype[n]??n:""}function Ni({title:t,measure:n,onOpen:i}){const{convert:r}=P(),[s,o]=f.useState(!1),a=r(t?`進入《${t}》全文閲讀`:"進入全文閲讀"),c=[n,r("全文檢索"),r("原書對照")].filter(Boolean).join(" · ");return e.jsx(Ce,{style:{marginTop:-12,marginBottom:28},children:e.jsxs("div",{role:"button",tabIndex:0,onClick:i,onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),i())},onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:24,flexWrap:"wrap",padding:"14px 26px",cursor:"pointer",background:s?"var(--bim-band-bg-hover, #e6d5b4)":"var(--bim-band-bg, #f0e4cb)",borderLeft:"3px solid var(--bim-accent, #9c3a2c)",transition:"background .18s ease"},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontFamily:"var(--bim-font-body, system-ui, sans-serif)",fontSize:21,fontWeight:600,letterSpacing:".02em",lineHeight:1.3,color:"var(--bim-ink, #2a231c)"},children:a}),e.jsx("div",{className:"bim-d-ui",style:{marginTop:4,fontSize:12.5,letterSpacing:".06em",color:"var(--bim-meta-fg, #7b6a54)"},children:c})]}),e.jsxs("span",{className:"bim-d-ui","aria-hidden":!0,style:{flex:"none",padding:"11px 22px",fontSize:14,letterSpacing:".08em",background:s?"var(--bim-accent-deep, #6f2a20)":"var(--bim-accent, #9c3a2c)",color:"var(--bim-page-bg, #fbf9f3)",transition:"background .18s ease"},children:[r("開始閲讀")," →"]})]})})}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=Dt;exports.BidUrlProvider=jo;exports.BookDetailLayout=uc;exports.BookFullText=Ar;exports.BookPage=eo;exports.Breadcrumb=vr;exports.Chip=Rt;exports.ChipWall=Kt;exports.CollatedEdition=Mn;exports.CollectionCatalog=Cn;exports.CollectionPage=to;exports.CreateEntityDialog=Nr;exports.DETAIL_CSS=hr;exports.Dash=rt;exports.DataTable=qe;exports.DetailFooter=zr;exports.DetailHeader=jr;exports.EmendatedBySection=rr;exports.EmptyNote=st;exports.EntityDetail=Zi;exports.EntityPage=no;exports.EntityPickerDialog=Gr;exports.EntitySelector=Dr;exports.ExpandRow=kr;exports.ExtLink=gn;exports.FactList=zt;exports.FeedbackButton=wa;exports.FeedbackDialog=Jr;exports.FeedbackForm=qr;exports.FeedbackList=Pn;exports.FeedbackTab=Xr;exports.FilterChip=Oe;exports.FormInput=he;exports.FormTextArea=Ye;exports.GlyphBadge=Ln;exports.HomePage=hn;exports.IndexApp=Rl;exports.IndexBrowser=pn;exports.IndexDetail=_n;exports.IndexEditor=Ur;exports.IndexView=ua;exports.IntroGrid=Tt;exports.LocaleContext=_t;exports.LocaleProvider=Ro;exports.LocaleToggle=lo;exports.ModeIndicator=qi;exports.MoreButton=De;exports.PAGE_MAX_WIDTH=mt;exports.PageFrame=$t;exports.Quote=At;exports.ROLE_CLASS_ORDER=ur;exports.RelationPanel=Hr;exports.RepoSourceLink=ao;exports.ResourceEditor=dn;exports.ResourceGroup=fn;exports.ResourceLine=ot;exports.ResourceList=wn;exports.ResourceRow=Cr;exports.SearchInput=Xi;exports.Section=ke;exports.SectionHead=ue;exports.SmartBidInput=Ft;exports.SourceEditor=Fr;exports.TableHead=Jt;exports.TableRow=qt;exports.TagRow=Wn;exports.TagRows=Tr;exports.TextButton=Yt;exports.TopStrip=yr;exports.VersionLineageGraph=oo;exports.VersionLineageList=ro;exports.VersionLineageView=so;exports.VolumeChips=Sr;exports.VolumeLinks=Ir;exports.WorkCatalog=El;exports.WorkPage=Qr;exports.bucketResources=Ut;exports.buildCollectionTable=fr;exports.buildLineageGraph=Mt;exports.buildPageUrl=kn;exports.buildVersionRow=dr;exports.buildVersionTable=pr;exports.computeVersionPartition=$s;exports.deriveDating=Bs;exports.deriveEditionType=mr;exports.deriveEra=It;exports.deriveYear=Gt;exports.deriveYearRange=Tn;exports.detailToEditor=Kr;exports.displayAuthorRole=En;exports.editorToDetail=pa;exports.eraRank=xn;exports.flattenTitles=wt;exports.formatTemplate=Ct;exports.formatVolumeRange=Bn;exports.getDisplayNameFromUrl=St;exports.getStartPage=Sn;exports.getTypeGroupKey=yn;exports.groupRelatedWorks=cr;exports.measureText=Je;exports.mergeVolumeResources=vn;exports.normalizeEra=pe;exports.normalizeRole=Rn;exports.normalizeVolumeIndex=vt;exports.normalizeVolumes=Ji;exports.numberToChinese=gr;exports.parseChineseNumber=Ht;exports.parseSourceString=Mr;exports.resourceHref=Pt;exports.resourceNote=zn;exports.roleFacets=xr;exports.rowNo=Xt;exports.sortYear=ar;exports.stringifySources=Pr;exports.useBidUrl=be;exports.useConvert=P;exports.useT=D;exports.validateLineageGraph=Va;exports.volumeStats=jn;
|